[Beignet] [PATCH 13/21 V3] Add profiling info APIs to runtime.

junyan.he at inbox.com junyan.he at inbox.com
Mon Nov 16 15:40:15 PST 2015


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     |   26 +++++++++++++++++++++++++-
 backend/src/backend/program.h       |   11 +++++++++++
 backend/src/backend/program.hpp     |   22 ++++++++++++++++++++++
 backend/src/gbe_bin_interpreter.cpp |    4 ++++
 src/cl_gbe_loader.cpp               |   15 +++++++++++++++
 src/cl_gbe_loader.h                 |    3 +++
 6 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index d50320c..08b33da 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -88,12 +88,14 @@ 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), printfSet(NULL) {}
+        slmSize(0), ctx(NULL), samplerSet(NULL), imageSet(NULL), printfSet(NULL),
+        profilingInfo(NULL) {}
   Kernel::~Kernel(void) {
     if(ctx) GBE_DELETE(ctx);
     if(samplerSet) GBE_DELETE(samplerSet);
     if(imageSet) GBE_DELETE(imageSet);
     if(printfSet) GBE_DELETE(printfSet);
+    if(profilingInfo) GBE_DELETE(profilingInfo);
     GBE_SAFE_DELETE_ARRAY(args);
   }
   int32_t Kernel::getCurbeOffset(gbe_curbe_type type, uint32_t subType) const {
@@ -159,6 +161,7 @@ namespace gbe {
     for (const auto &pair : set) {
       const std::string &name = pair.first;
       Kernel *kernel = this->compileKernel(unit, name, !OCL_STRICT_CONFORMANCE, OCL_PROFILING_LOG);
+      kernel->setProfilingInfo(new ir::ProfilingInfo(*unit.getProfilingInfo()));
       kernel->setSamplerSet(pair.second->getSamplerSet());
       kernel->setImageSet(pair.second->getImageSet());
       kernel->setPrintfSet(pair.second->getPrintfSet());
@@ -1125,6 +1128,21 @@ namespace gbe {
     kernel->getSamplerData(samplers);
   }
 
+  static void* kernelDupProfiling(gbe_kernel gbeKernel) {
+    if (gbeKernel == NULL) return NULL;
+    const gbe::Kernel *kernel = (const gbe::Kernel*) gbeKernel;
+    return kernel->dupProfilingInfo();
+  }
+  static uint32_t kernelGetProfilingBTI(gbe_kernel gbeKernel) {
+    if (gbeKernel == NULL) return 0;
+    const gbe::Kernel *kernel = (const gbe::Kernel*) gbeKernel;
+    return kernel->getProfilingBTI();
+  }
+  static void kernelOutputProfiling(void *profiling_info, void* buf) {
+    if (profiling_info == NULL) return;
+    ir::ProfilingInfo *pi = (ir::ProfilingInfo *)profiling_info;
+    return pi->outputProfilingInfo(buf);
+  }
   static uint32_t kernelGetPrintfNum(void * printf_info) {
     if (printf_info == NULL) return 0;
     const ir::PrintfSet *ps = (ir::PrintfSet *)printf_info;
@@ -1247,6 +1265,9 @@ GBE_EXPORT_SYMBOL gbe_kernel_get_sampler_data_cb *gbe_kernel_get_sampler_data =
 GBE_EXPORT_SYMBOL gbe_kernel_get_compile_wg_size_cb *gbe_kernel_get_compile_wg_size = NULL;
 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_output_profiling_cb *gbe_output_profiling = NULL;
+GBE_EXPORT_SYMBOL gbe_dup_profiling_cb *gbe_dup_profiling = NULL;
+GBE_EXPORT_SYMBOL gbe_get_profiling_bti_cb *gbe_get_profiling_bti = 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_get_printf_buf_bti_cb *gbe_get_printf_buf_bti = NULL;
@@ -1296,7 +1317,10 @@ namespace gbe
       gbe_kernel_get_compile_wg_size = gbe::kernelGetCompileWorkGroupSize;
       gbe_kernel_get_image_size = gbe::kernelGetImageSize;
       gbe_kernel_get_image_data = gbe::kernelGetImageData;
+      gbe_get_profiling_bti = gbe::kernelGetProfilingBTI;
       gbe_get_printf_num = gbe::kernelGetPrintfNum;
+      gbe_dup_profiling = gbe::kernelDupProfiling;
+      gbe_output_profiling = gbe::kernelOutputProfiling;
       gbe_get_printf_buf_bti = gbe::kernelGetPrintfBufBTI;
       gbe_get_printf_indexbuf_bti = gbe::kernelGetPrintfIndexBufBTI;
       gbe_dup_printfset = gbe::kernelDupPrintfSet;
diff --git a/backend/src/backend/program.h b/backend/src/backend/program.h
index 14752ad..f948a6b 100644
--- a/backend/src/backend/program.h
+++ b/backend/src/backend/program.h
@@ -138,6 +138,17 @@ 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 whether we are in the code profiling mode */
+typedef void (gbe_output_profiling_cb)(void* profiling_info, void* buf);
+extern gbe_output_profiling_cb *gbe_output_profiling;
+
+/*! Get the profiling bti */
+typedef uint32_t (gbe_get_profiling_bti_cb)(gbe_kernel gbeKernel);
+extern gbe_get_profiling_bti_cb *gbe_get_profiling_bti;
+
+typedef void* (gbe_dup_profiling_cb)(gbe_kernel gbeKernel);
+extern gbe_dup_profiling_cb *gbe_dup_profiling;
+
 /*! 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;
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index d5c6442..59e4ba1 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -128,6 +128,17 @@ namespace gbe {
     void setImageSet(ir::ImageSet * from) {
       imageSet = from;
     }
+    /*! Set profiling info. */
+    void setProfilingInfo(ir::ProfilingInfo * from) {
+      profilingInfo = from;
+    }
+    void * dupProfilingInfo() const {
+      void* ptr = profilingInfo ? (void *)(new ir::ProfilingInfo(*profilingInfo)) : NULL;
+      return ptr;
+    }
+    uint32_t getProfilingBTI(void) const {
+      return profilingInfo ? profilingInfo->getBTI() : 0;
+    }
     /*! Set printf set. */
     void setPrintfSet(ir::PrintfSet * from) {
       printfSet = from;
@@ -161,6 +172,16 @@ namespace gbe {
                                 global_wk_sz1, global_wk_sz2, output_sz);
     }
 
+    uint32_t getProfilingBufBTI() const {
+      GBE_ASSERT(profilingInfo);
+      return profilingInfo->getBTI();
+    }
+
+    void outputProfilingInfo(void* buf) {
+      if(profilingInfo)
+        profilingInfo->outputProfilingInfo(buf);
+    }
+
     ir::FunctionArgument::InfoFromLLVM* getArgInfo(uint32_t id) const { return &args[id].info; }
 
     /*! Set compile work group size */
@@ -231,6 +252,7 @@ namespace gbe {
     ir::SamplerSet *samplerSet;//!< Copy from the corresponding function.
     ir::ImageSet *imageSet;    //!< Copy from the corresponding function.
     ir::PrintfSet *printfSet;  //!< Copy from the corresponding function.
+    ir::ProfilingInfo *profilingInfo;  //!< Copy from the corresponding function.
     size_t compileWgSize[3];   //!< required work group size by kernel attribute.
     std::string functionAttributes; //!< function attribute qualifiers combined.
     GBE_CLASS(Kernel);         //!< Use custom allocators
diff --git a/backend/src/gbe_bin_interpreter.cpp b/backend/src/gbe_bin_interpreter.cpp
index 4594a0a..4756842 100644
--- a/backend/src/gbe_bin_interpreter.cpp
+++ b/backend/src/gbe_bin_interpreter.cpp
@@ -22,6 +22,7 @@
 #include "sys/platform.cpp"
 #include "ir/constant.cpp"
 #include "ir/printf.cpp"
+#include "ir/profiling.cpp"
 
 #pragma GCC diagnostic ignored "-Wunused-function"
 #pragma GCC diagnostic ignored "-Wunused-variable"
@@ -64,6 +65,9 @@ struct BinInterpCallBackInitializer
     gbe_kernel_get_sampler_data = gbe::kernelGetSamplerData;
     gbe_kernel_get_image_data = gbe::kernelGetImageData;
     gbe_kernel_get_arg_info = gbe::kernelGetArgInfo;
+    gbe_get_profiling_bti = gbe::kernelGetProfilingBTI;
+    gbe_dup_profiling = gbe::kernelDupProfiling;
+    gbe_output_profiling = gbe::kernelOutputProfiling;
     gbe_get_printf_num = gbe::kernelGetPrintfNum;
     gbe_get_printf_buf_bti = gbe::kernelGetPrintfBufBTI;
     gbe_get_printf_indexbuf_bti = gbe::kernelGetPrintfIndexBufBTI;
diff --git a/src/cl_gbe_loader.cpp b/src/cl_gbe_loader.cpp
index e832a53..0ec6c96 100644
--- a/src/cl_gbe_loader.cpp
+++ b/src/cl_gbe_loader.cpp
@@ -64,6 +64,9 @@ gbe_kernel_get_sampler_data_cb *interp_kernel_get_sampler_data = NULL;
 gbe_kernel_get_compile_wg_size_cb *interp_kernel_get_compile_wg_size = NULL;
 gbe_kernel_get_image_size_cb *interp_kernel_get_image_size = NULL;
 gbe_kernel_get_image_data_cb *interp_kernel_get_image_data = NULL;
+gbe_output_profiling_cb* interp_output_profiling = NULL;
+gbe_get_profiling_bti_cb* interp_get_profiling_bti = NULL;
+gbe_dup_profiling_cb* interp_dup_profiling = NULL;
 gbe_get_printf_num_cb* interp_get_printf_num = NULL;
 gbe_get_printf_buf_bti_cb* interp_get_printf_buf_bti = NULL;
 gbe_get_printf_indexbuf_bti_cb* interp_get_printf_indexbuf_bti = NULL;
@@ -213,6 +216,18 @@ struct GbeLoaderInitializer
     if (interp_kernel_get_image_data == NULL)
       return false;
 
+    interp_output_profiling = *(gbe_output_profiling_cb**)dlsym(dlhInterp, "gbe_output_profiling");
+    if (interp_output_profiling == NULL)
+      return false;
+
+    interp_get_profiling_bti = *(gbe_get_profiling_bti_cb**)dlsym(dlhInterp, "gbe_get_profiling_bti");
+    if (interp_get_profiling_bti == NULL)
+      return false;
+
+    interp_dup_profiling = *(gbe_dup_profiling_cb**)dlsym(dlhInterp, "gbe_dup_profiling");
+    if (interp_dup_profiling == NULL)
+      return false;
+
     interp_get_printf_num = *(gbe_get_printf_num_cb**)dlsym(dlhInterp, "gbe_get_printf_num");
     if (interp_get_printf_num == NULL)
       return false;
diff --git a/src/cl_gbe_loader.h b/src/cl_gbe_loader.h
index de91c85..d72854c 100644
--- a/src/cl_gbe_loader.h
+++ b/src/cl_gbe_loader.h
@@ -64,6 +64,9 @@ extern gbe_kernel_get_sampler_data_cb *interp_kernel_get_sampler_data;
 extern gbe_kernel_get_compile_wg_size_cb *interp_kernel_get_compile_wg_size;
 extern gbe_kernel_get_image_size_cb *interp_kernel_get_image_size;
 extern gbe_kernel_get_image_data_cb *interp_kernel_get_image_data;
+extern gbe_output_profiling_cb* interp_output_profiling;
+extern gbe_get_profiling_bti_cb* interp_get_profiling_bti;
+extern gbe_dup_profiling_cb* interp_dup_profiling;
 extern gbe_get_printf_num_cb* interp_get_printf_num;
 extern gbe_get_printf_buf_bti_cb* interp_get_printf_buf_bti;
 extern gbe_get_printf_indexbuf_bti_cb* interp_get_printf_indexbuf_bti;
-- 
1.7.9.5





More information about the Beignet mailing list