[Beignet] [PATCH 4/6 OpenCL-1.2] Add the printfSet into the kernel Class and add misc helper functions
junyan.he at inbox.com
junyan.he at inbox.com
Tue Jun 3 23:03:36 PDT 2014
From: Junyan He <junyan.he at linux.intel.com>
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
backend/src/backend/program.cpp | 51 +++++++++++++++++++++++++++++++++++++++--
backend/src/backend/program.h | 20 ++++++++++++++++
backend/src/backend/program.hpp | 26 +++++++++++++++++++++
backend/src/ir/function.cpp | 1 +
backend/src/ir/function.hpp | 4 ++++
5 files changed, 100 insertions(+), 2 deletions(-)
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 121e237..bde0b24 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"
@@ -78,12 +79,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 {
@@ -135,6 +137,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));
}
@@ -983,6 +986,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;
@@ -1049,6 +1086,11 @@ 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_compiler = NULL;
GBE_EXPORT_SYMBOL gbe_set_image_base_index_cb *gbe_set_image_base_index_interp = 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
@@ -1087,6 +1129,11 @@ namespace gbe
gbe_kernel_get_image_data = gbe::kernelGetImageData;
gbe_get_image_base_index = gbe::getImageBaseIndex;
gbe_set_image_base_index_compiler = 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 7297ea8..b4b3aaf 100644
--- a/backend/src/backend/program.h
+++ b/backend/src/backend/program.h
@@ -115,6 +115,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 6bb1529..fb5a0de 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
};
diff --git a/backend/src/ir/function.cpp b/backend/src/ir/function.cpp
index b0df412..a46108e 100644
--- a/backend/src/ir/function.cpp
+++ b/backend/src/ir/function.cpp
@@ -48,6 +48,7 @@ namespace ir {
initProfile(*this);
samplerSet = GBE_NEW(SamplerSet);
imageSet = GBE_NEW(ImageSet);
+ printfSet = GBE_NEW(PrintfSet);
}
Function::~Function(void) {
diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
index 266e652..63bb6ea 100644
--- a/backend/src/ir/function.hpp
+++ b/backend/src/ir/function.hpp
@@ -29,6 +29,7 @@
#include "ir/instruction.hpp"
#include "ir/profile.hpp"
#include "ir/sampler.hpp"
+#include "ir/printf.hpp"
#include "ir/image.hpp"
#include "sys/vector.hpp"
#include "sys/set.hpp"
@@ -329,6 +330,8 @@ namespace ir {
SamplerSet* getSamplerSet(void) const {return samplerSet; }
/*! Get image set in this function */
ImageSet* getImageSet(void) const {return imageSet; }
+ /*! Get printf set in this function */
+ PrintfSet* getPrintfSet(void) const {return printfSet; }
/*! Set required work group size. */
void setCompileWorkGroupSize(size_t x, size_t y, size_t z) { compileWgSize[0] = x; compileWgSize[1] = y; compileWgSize[2] = z; }
/*! Get required work group size. */
@@ -360,6 +363,7 @@ namespace ir {
uint32_t stackSize; //!< stack size for private memory.
SamplerSet *samplerSet; //!< samplers used in this function.
ImageSet* imageSet; //!< Image set in this function's arguments..
+ PrintfSet *printfSet; //!< printfSet store the printf info.
size_t compileWgSize[3]; //!< required work group size specified by
// __attribute__((reqd_work_group_size(X, Y, Z))).
GBE_CLASS(Function); //!< Use custom allocator
--
1.8.3.2
More information about the Beignet
mailing list