[Beignet] [PATCH 2/7] add helper functions in gbe::Program

Homer Hsing homer.xing at intel.com
Wed May 1 18:00:27 PDT 2013


Version 3.
for get global constant related information

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 backend/src/backend/program.cpp | 20 +++++++++++++++++++-
 backend/src/backend/program.h   | 10 ++++++++++
 backend/src/backend/program.hpp |  8 ++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 0882e5a..38cc236 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -63,9 +63,10 @@ namespace gbe {
     return it->offset; // we found it!
   }
 
-  Program::Program(void) {}
+  Program::Program(void) : constantSet(NULL) {}
   Program::~Program(void) {
     for (auto &kernel : kernels) GBE_DELETE(kernel.second);
+    if (constantSet) delete constantSet;
   }
 
   BVAR(OCL_OUTPUT_GEN_IR, false);
@@ -81,6 +82,7 @@ namespace gbe {
   }
 
   bool Program::buildFromUnit(const ir::Unit &unit, std::string &error) {
+    constantSet = new ir::ConstantSet(unit.getConstantSet());
     const auto &set = unit.getFunctionSet();
     const uint32_t kernelNum = set.size();
     if (OCL_OUTPUT_GEN_IR) std::cout << unit;
@@ -146,6 +148,18 @@ namespace gbe {
     return p;
   }
 
+  static size_t programGetGlobalConstantSize(gbe_program gbeProgram) {
+    if (gbeProgram == NULL) return 0;
+    const gbe::Program *program = (const gbe::Program*) gbeProgram;
+    return program->getGlobalConstantSize();
+  }
+
+  static void programGetGlobalConstantData(gbe_program gbeProgram, char *mem) {
+    if (gbeProgram == NULL) return;
+    const gbe::Program *program = (const gbe::Program*) gbeProgram;
+    program->getGlobalConstantData(mem);
+  }
+
   static uint32_t programGetKernelNum(gbe_program gbeProgram) {
     if (gbeProgram == NULL) return 0;
     const gbe::Program *program = (const gbe::Program*) gbeProgram;
@@ -244,6 +258,8 @@ namespace gbe {
 GBE_EXPORT_SYMBOL gbe_program_new_from_source_cb *gbe_program_new_from_source = NULL;
 GBE_EXPORT_SYMBOL gbe_program_new_from_binary_cb *gbe_program_new_from_binary = NULL;
 GBE_EXPORT_SYMBOL gbe_program_new_from_llvm_cb *gbe_program_new_from_llvm = NULL;
+GBE_EXPORT_SYMBOL gbe_program_get_global_constant_size_cb *gbe_program_get_global_constant_size = NULL;
+GBE_EXPORT_SYMBOL gbe_program_get_global_constant_data_cb *gbe_program_get_global_constant_data = NULL;
 GBE_EXPORT_SYMBOL gbe_program_delete_cb *gbe_program_delete = NULL;
 GBE_EXPORT_SYMBOL gbe_program_get_kernel_num_cb *gbe_program_get_kernel_num = NULL;
 GBE_EXPORT_SYMBOL gbe_program_get_kernel_by_name_cb *gbe_program_get_kernel_by_name = NULL;
@@ -269,6 +285,8 @@ namespace gbe
   {
     CallBackInitializer(void) {
       gbe_program_new_from_source = gbe::programNewFromSource;
+      gbe_program_get_global_constant_size = gbe::programGetGlobalConstantSize;
+      gbe_program_get_global_constant_data = gbe::programGetGlobalConstantData;
       gbe_program_delete = gbe::programDelete;
       gbe_program_get_kernel_num = gbe::programGetKernelNum;
       gbe_program_get_kernel_by_name = gbe::programGetKernelByName;
diff --git a/backend/src/backend/program.h b/backend/src/backend/program.h
index 4273a77..575196a 100644
--- a/backend/src/backend/program.h
+++ b/backend/src/backend/program.h
@@ -69,6 +69,8 @@ enum gbe_curbe_type {
   GBE_CURBE_GROUP_NUM_X,
   GBE_CURBE_GROUP_NUM_Y,
   GBE_CURBE_GROUP_NUM_Z,
+  GBE_CURBE_GLOBAL_CONSTANT_OFFSET,
+  GBE_CURBE_GLOBAL_CONSTANT_DATA,
   GBE_CURBE_IMAGE_WIDTH,
   GBE_CURBE_IMAGE_HEIGHT,
   GBE_CURBE_IMAGE_DEPTH,
@@ -104,6 +106,14 @@ typedef gbe_program (gbe_program_new_from_llvm_cb)(const char *fileName,
                                                    size_t *err_size);
 extern gbe_program_new_from_llvm_cb *gbe_program_new_from_llvm;
 
+/*! Get the size of global constants */
+typedef size_t (gbe_program_get_global_constant_size_cb)(gbe_program gbeProgram);
+extern gbe_program_get_global_constant_size_cb *gbe_program_get_global_constant_size;
+
+/*! Get the content of global constants */
+typedef void (gbe_program_get_global_constant_data_cb)(gbe_program gbeProgram, char *mem);
+extern gbe_program_get_global_constant_data_cb *gbe_program_get_global_constant_data;
+
 /*! Destroy and deallocate the given program */
 typedef void (gbe_program_delete_cb)(gbe_program);
 extern gbe_program_delete_cb *gbe_program_delete;
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index e7584d9..e754899 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -27,6 +27,8 @@
 
 #include "backend/program.h"
 #include "backend/context.hpp"
+#include "ir/constant.hpp"
+#include "ir/unit.hpp"
 #include "sys/hash_map.hpp"
 #include "sys/vector.hpp"
 #include <string>
@@ -157,11 +159,17 @@ namespace gbe {
     bool buildFromLLVMFile(const char *fileName, std::string &error);
     /*! Buils a program from a OCL string */
     bool buildFromSource(const char *source, std::string &error);
+    /*! Get size of the global constant arrays */
+    size_t getGlobalConstantSize(void) const { return constantSet->getDataSize(); }
+    /*! Get the content of global constant arrays */
+    void getGlobalConstantData(char *mem) const { constantSet->getData(mem); }
   protected:
     /*! Compile a kernel */
     virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name) = 0;
     /*! Kernels sorted by their name */
     hash_map<std::string, Kernel*> kernels;
+    /*! Global (constants) outside any kernel */
+    ir::ConstantSet *constantSet;
     /*! Use custom allocators */
     GBE_CLASS(Program);
   };
-- 
1.8.1.2



More information about the Beignet mailing list