[Beignet] [PATCH 4/6] Add the printfSet into the kernel Class and add misc helper functions

Zhigang Gong zhigang.gong at linux.intel.com
Tue Jun 10 17:44:05 PDT 2014


This patch LGTM. Thanks.

On Tue, Jun 10, 2014 at 12:53:04PM +0800, junyan.he at inbox.com wrote:
> 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 +++++++++++++++++++++
>  3 files changed, 95 insertions(+), 2 deletions(-)
> 
> diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
> index 949aeb4..9f8d6ed 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;
> @@ -1048,6 +1085,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
> @@ -1086,6 +1128,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 7876db4..333ee28 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 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
>    };
> -- 
> 1.8.3.2
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list