summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2014-06-10 12:53:04 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-06-11 11:04:06 +0800
commit64f2ad234111a6f16293955c1943bf0474d84006 (patch)
treedaf5ba11054ac058ca768e20820ef4296626b034 /backend
parent42cdacda1b5217c593d23621775651a7143a353c (diff)
Add the printfSet into the kernel Class and add misc helper functions
Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'backend')
-rw-r--r--backend/src/backend/program.cpp51
-rw-r--r--backend/src/backend/program.h20
-rw-r--r--backend/src/backend/program.hpp26
3 files changed, 95 insertions, 2 deletions
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 6e507619..e64e624f 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -30,6 +30,7 @@
#include "ir/liveness.hpp"
#include "ir/value.hpp"
#include "ir/unit.hpp"
+#include "ir/printf.hpp"
#include "llvm/llvm_to_gen.hpp"
#include "llvm/Config/config.h"
#include "llvm/Support/Threading.h"
@@ -80,12 +81,13 @@
namespace gbe {
Kernel::Kernel(const std::string &name) :
- name(name), args(NULL), argNum(0), curbeSize(0), stackSize(0), useSLM(false), slmSize(0), ctx(NULL), samplerSet(NULL), imageSet(NULL)
- {}
+ name(name), args(NULL), argNum(0), curbeSize(0), stackSize(0), useSLM(false),
+ slmSize(0), ctx(NULL), samplerSet(NULL), imageSet(NULL), printfSet(NULL) {}
Kernel::~Kernel(void) {
if(ctx) GBE_DELETE(ctx);
if(samplerSet) GBE_DELETE(samplerSet);
if(imageSet) GBE_DELETE(imageSet);
+ if(printfSet) GBE_DELETE(printfSet);
GBE_SAFE_DELETE_ARRAY(args);
}
int32_t Kernel::getCurbeOffset(gbe_curbe_type type, uint32_t subType) const {
@@ -148,6 +150,7 @@ namespace gbe {
Kernel *kernel = this->compileKernel(unit, name, !OCL_STRICT_CONFORMANCE);
kernel->setSamplerSet(pair.second->getSamplerSet());
kernel->setImageSet(pair.second->getImageSet());
+ kernel->setPrintfSet(pair.second->getPrintfSet());
kernel->setCompileWorkGroupSize(pair.second->getCompileWorkGroupSize());
kernels.insert(std::make_pair(name, kernel));
}
@@ -992,6 +995,40 @@ namespace gbe {
kernel->getSamplerData(samplers);
}
+ static uint32_t kernelGetPrintfNum(void * printf_info) {
+ if (printf_info == NULL) return 0;
+ const ir::PrintfSet *ps = (ir::PrintfSet *)printf_info;
+ return ps->getPrintfNum();
+ }
+
+ static void* kernelDupPrintfSet(gbe_kernel gbeKernel) {
+ if (gbeKernel == NULL) return NULL;
+ const gbe::Kernel *kernel = (const gbe::Kernel*) gbeKernel;
+ return kernel->dupPrintfSet();
+ }
+
+ static void kernelReleasePrintfSet(void * printf_info) {
+ if (printf_info == NULL) return;
+ ir::PrintfSet *ps = (ir::PrintfSet *)printf_info;
+ delete ps;
+ }
+
+ static uint32_t kernelGetPrintfSizeOfSize(void * printf_info) {
+ if (printf_info == NULL) return 0;
+ const ir::PrintfSet *ps = (ir::PrintfSet *)printf_info;
+ return ps->getPrintfSizeOfSize();
+ }
+
+ static void kernelOutputPrintf(void * printf_info, void* index_addr,
+ void* buf_addr, size_t global_wk_sz0,
+ size_t global_wk_sz1, size_t global_wk_sz2)
+ {
+ if (printf_info == NULL) return;
+ ir::PrintfSet *ps = (ir::PrintfSet *)printf_info;
+ ps->outputPrintf(index_addr, buf_addr, global_wk_sz0,
+ global_wk_sz1, global_wk_sz2);
+ }
+
static void kernelGetCompileWorkGroupSize(gbe_kernel gbeKernel, size_t wg_size[3]) {
if (gbeKernel == NULL) return;
const gbe::Kernel *kernel = (const gbe::Kernel*) gbeKernel;
@@ -1057,6 +1094,11 @@ GBE_EXPORT_SYMBOL gbe_kernel_get_image_size_cb *gbe_kernel_get_image_size = NULL
GBE_EXPORT_SYMBOL gbe_kernel_get_image_data_cb *gbe_kernel_get_image_data = NULL;
GBE_EXPORT_SYMBOL gbe_set_image_base_index_cb *gbe_set_image_base_index = NULL;
GBE_EXPORT_SYMBOL gbe_get_image_base_index_cb *gbe_get_image_base_index = NULL;
+GBE_EXPORT_SYMBOL gbe_get_printf_num_cb *gbe_get_printf_num = NULL;
+GBE_EXPORT_SYMBOL gbe_dup_printfset_cb *gbe_dup_printfset = NULL;
+GBE_EXPORT_SYMBOL gbe_release_printf_info_cb *gbe_release_printf_info = NULL;
+GBE_EXPORT_SYMBOL gbe_get_printf_sizeof_size_cb *gbe_get_printf_sizeof_size = NULL;
+GBE_EXPORT_SYMBOL gbe_output_printf_cb *gbe_output_printf = NULL;
#ifdef GBE_COMPILER_AVAILABLE
namespace gbe
@@ -1095,6 +1137,11 @@ namespace gbe
gbe_kernel_get_image_data = gbe::kernelGetImageData;
gbe_get_image_base_index = gbe::getImageBaseIndex;
gbe_set_image_base_index = gbe::setImageBaseIndex;
+ gbe_get_printf_num = gbe::kernelGetPrintfNum;
+ gbe_dup_printfset = gbe::kernelDupPrintfSet;
+ gbe_get_printf_sizeof_size = gbe::kernelGetPrintfSizeOfSize;
+ gbe_release_printf_info = gbe::kernelReleasePrintfSet;
+ gbe_output_printf = gbe::kernelOutputPrintf;
genSetupCallBacks();
llvm::llvm_start_multithreaded();
}
diff --git a/backend/src/backend/program.h b/backend/src/backend/program.h
index ad018e8e..65378c4a 100644
--- a/backend/src/backend/program.h
+++ b/backend/src/backend/program.h
@@ -114,6 +114,26 @@ extern gbe_kernel_get_image_size_cb *gbe_kernel_get_image_size;
typedef void (gbe_kernel_get_image_data_cb)(gbe_kernel gbeKernel, ImageInfo *images);
extern gbe_kernel_get_image_data_cb *gbe_kernel_get_image_data;
+/*! Get the printf number */
+typedef uint32_t (gbe_get_printf_num_cb)(void* printf_info);
+extern gbe_get_printf_num_cb *gbe_get_printf_num;
+
+/*! Release the printfset */
+typedef void (gbe_release_printf_info_cb)(void* printf_info);
+extern gbe_release_printf_info_cb *gbe_release_printf_info;
+
+/*! Dup the printf set */
+typedef void* (gbe_dup_printfset_cb)(gbe_kernel gbeKernel);
+extern gbe_dup_printfset_cb *gbe_dup_printfset;
+
+/*! Get the printf buffer const offset */
+typedef uint32_t (gbe_get_printf_sizeof_size_cb)(void* printf_info);
+extern gbe_get_printf_sizeof_size_cb *gbe_get_printf_sizeof_size;
+
+typedef void (gbe_output_printf_cb) (void* printf_info, void* index_addr, void* buf_addr,
+ size_t global_wk_sz0, size_t global_wk_sz1, size_t global_wk_sz2);
+extern gbe_output_printf_cb* gbe_output_printf;
+
/*! Create a new program from the given source code (zero terminated string) */
typedef gbe_program (gbe_program_new_from_source_cb)(uint32_t deviceID,
const char *source,
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index 1235d511..4afdb157 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -30,6 +30,7 @@
#include "ir/constant.hpp"
#include "ir/unit.hpp"
#include "ir/function.hpp"
+#include "ir/printf.hpp"
#include "ir/sampler.hpp"
#include "sys/hash_map.hpp"
#include "sys/vector.hpp"
@@ -134,6 +135,30 @@ namespace gbe {
void setImageSet(ir::ImageSet * from) {
imageSet = from;
}
+ /*! Set printf set. */
+ void setPrintfSet(ir::PrintfSet * from) {
+ printfSet = from;
+ }
+ /* ! Return the offset in the sizeof(xxx). */
+ uint32_t getPrintfSizeOfSize(void) const {
+ return printfSet ? printfSet->getPrintfSizeOfSize() : 0;
+ }
+ uint32_t getPrintfNum() const {
+ return printfSet ? printfSet->getPrintfNum() : 0;
+ }
+
+ void * dupPrintfSet() const {
+ void* ptr = printfSet ? (void *)(new ir::PrintfSet(*printfSet)) : NULL;
+ return ptr;
+ }
+
+ void outputPrintf(void* index_addr, void* buf_addr, size_t global_wk_sz0,
+ size_t global_wk_sz1, size_t global_wk_sz2) {
+ if(printfSet)
+ printfSet->outputPrintf(index_addr, buf_addr, global_wk_sz0,
+ global_wk_sz1, global_wk_sz2);
+ }
+
/*! Set compile work group size */
void setCompileWorkGroupSize(const size_t wg_sz[3]) {
compileWgSize[0] = wg_sz[0];
@@ -196,6 +221,7 @@ namespace gbe {
Context *ctx; //!< Save context after compiler to alloc constant buffer curbe
ir::SamplerSet *samplerSet;//!< Copy from the corresponding function.
ir::ImageSet *imageSet; //!< Copy from the corresponding function.
+ ir::PrintfSet *printfSet; //!< Copy from the corresponding function.
size_t compileWgSize[3]; //!< required work group size by kernel attribute.
GBE_CLASS(Kernel); //!< Use custom allocators
};