From 001aba2276fd7000a39d6343c0ed443ed9d09dc0 Mon Sep 17 00:00:00 2001 From: Benjamin Segovia Date: Tue, 3 Apr 2012 17:39:46 +0000 Subject: [PATCH] Adapted properly the driver to the new gen compiler interface --- src/cl_kernel.c | 18 +++++++++--------- src/cl_kernel.h | 21 +++++++++++---------- src/cl_program.c | 18 +++++++++--------- src/cl_program.h | 25 +++++++++++++------------ 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/cl_kernel.c b/src/cl_kernel.c index 876cefb..8fbb2e8 100644 --- a/src/cl_kernel.c +++ b/src/cl_kernel.c @@ -25,7 +25,7 @@ #include "cl_alloc.h" #include "cl_utils.h" #include "CL/cl.h" -#include "gen/program.h" +#include "gen/gbe_program.h" #include #include @@ -74,7 +74,7 @@ LOCAL const char* cl_kernel_get_name(const cl_kernel k) { if (UNLIKELY(k == NULL)) return NULL; - return GenKernelGetName(k->gen_kernel); + return gbe_kernel_get_name(k->opaque); } LOCAL void @@ -95,23 +95,23 @@ LOCAL uint32_t cl_kernel_get_simd_width(const cl_kernel k) { assert(k != NULL); - return GenKernelGetSIMDWidth(k->gen_kernel); + return gbe_kernel_get_simd_width(k->opaque); } LOCAL void -cl_kernel_setup(cl_kernel k, const struct GenKernel *gen_kernel) +cl_kernel_setup(cl_kernel k, gbe_kernel opaque) { cl_context ctx = k->program->ctx; cl_buffer_mgr bufmgr = cl_context_get_bufmgr(ctx); /* Allocate the gen code here */ - const uint32_t code_sz = GenKernelGetCodeSize(gen_kernel); - const char *code = GenKernelGetCode(gen_kernel); + const uint32_t code_sz = gbe_kernel_get_code_size(opaque); + const char *code = gbe_kernel_get_code(opaque); k->bo = cl_buffer_alloc(bufmgr, "CL kernel", code_sz, 64u); /* Upload the code */ cl_buffer_subdata(k->bo, 0, code_sz, code); - k->gen_kernel = gen_kernel; + k->opaque = opaque; } LOCAL cl_kernel @@ -124,7 +124,7 @@ cl_kernel_dup(const cl_kernel from) TRY_ALLOC_NO_ERR (to, CALLOC(struct _cl_kernel)); to->bo = from->bo; to->const_bo = from->const_bo; - to->gen_kernel = from->gen_kernel; + to->opaque = from->opaque; to->ref_n = 1; to->magic = CL_MAGIC_KERNEL_HEADER; to->program = from->program; @@ -159,7 +159,7 @@ cl_kernel_work_group_sz(cl_kernel ker, cl_uint i; for (i = 0; i < wk_dim; ++i) { - const uint32_t required_sz = GenKernelGetRequiredWorkGroupSize(ker->gen_kernel, i); + const uint32_t required_sz = gbe_kernel_get_required_work_group_size(ker->opaque, i); if (required_sz != 0 && required_sz != local_wk_sz[i]) { err = CL_INVALID_WORK_ITEM_SIZE; goto error; diff --git a/src/cl_kernel.h b/src/cl_kernel.h index 8518364..27b602d 100644 --- a/src/cl_kernel.h +++ b/src/cl_kernel.h @@ -23,23 +23,24 @@ #include "cl_defs.h" #include "cl_internals.h" #include "cl_driver.h" +#include "gen/gbe_program.h" #include "CL/cl.h" #include #include /* This is the kernel as it is interfaced by the compiler */ -struct GenKernel; +struct _gbe_kernel; /*! One OCL function */ struct _cl_kernel { - uint64_t magic; /* To identify it as a kernel */ - volatile int ref_n; /* We reference count this object */ - cl_buffer bo; /* The code itself */ - cl_buffer const_bo; /* Buffer for all __constants values in the OCL program */ - cl_program program; /* Owns this structure (and pointers) */ - const struct GenKernel *gen_kernel; /* (Opaque) compiler structure for the OCL kernel */ - uint8_t ref_its_program; /* True only for the user kernel (created by clCreateKernel) */ + uint64_t magic; /* To identify it as a kernel */ + volatile int ref_n; /* We reference count this object */ + cl_buffer bo; /* The code itself */ + cl_buffer const_bo; /* Buffer for all __constants values in the OCL program */ + cl_program program; /* Owns this structure (and pointers) */ + gbe_kernel opaque; /* (Opaque) compiler structure for the OCL kernel */ + uint8_t ref_its_program; /* True only for the user kernel (created by clCreateKernel) */ }; /* Allocate an empty kernel */ @@ -48,8 +49,8 @@ extern cl_kernel cl_kernel_new(const cl_program); /* Destroy and deallocate an empty kernel */ extern void cl_kernel_delete(cl_kernel); -/* Setup the kernel with the given Gen Kernel */ -extern void cl_kernel_setup(cl_kernel k, const struct GenKernel *gen_kernel); +/* Setup the kernel with the given GBE Kernel */ +extern void cl_kernel_setup(cl_kernel k, gbe_kernel opaque); /* Get the kernel name */ extern const char *cl_kernel_get_name(const cl_kernel k); diff --git a/src/cl_program.c b/src/cl_program.c index 5d15706..fc6b73a 100644 --- a/src/cl_program.c +++ b/src/cl_program.c @@ -25,7 +25,7 @@ #include "cl_utils.h" #include "CL/cl.h" #include "CL/cl_intel.h" -#include "gen/program.h" +#include "gen/gbe_program.h" #include #include @@ -65,7 +65,7 @@ cl_program_delete(cl_program p) cl_context_delete(p->ctx); /* Free the program as allocated by the compiler */ - if (p->gen_program) GenProgramDelete(p->gen_program); + if (p->opaque) gbe_program_delete(p->opaque); p->magic = CL_MAGIC_DEAD_HEADER; /* For safety */ cl_free(p); @@ -105,17 +105,17 @@ cl_program_load_gen_program(cl_program p) cl_int err = CL_SUCCESS; uint32_t i; - assert(p->gen_program != NULL); - p->ker_n = GenProgramGetKernelNum(p->gen_program); + assert(p->opaque != NULL); + p->ker_n = gbe_program_get_kernel_num(p->opaque); /* Allocate the kernel array */ TRY_ALLOC (p->ker, CALLOC_ARRAY(cl_kernel, p->ker_n)); for (i = 0; i < p->ker_n; ++i) { - const GenKernel *gen_kernel = GenProgramGetKernel(p->gen_program, i); - assert(gen_kernel != NULL); + const gbe_kernel opaque = gbe_program_get_kernel(p->opaque, i); + assert(opaque != NULL); TRY_ALLOC (p->ker[i], cl_kernel_new(p)); - cl_kernel_setup(p->ker[i], gen_kernel); + cl_kernel_setup(p->ker[i], opaque); } error: @@ -189,8 +189,8 @@ cl_program_create_from_llvm(cl_context ctx, program = cl_program_new(ctx); - program->gen_program = GenProgramNewFromLLVM(file_name, 0, NULL, NULL); - if (program->gen_program == NULL) { + program->opaque = gbe_program_new_from_llvm(file_name, 0, NULL, NULL); + if (program->opaque == NULL) { err = CL_INVALID_PROGRAM; goto error; } diff --git a/src/cl_program.h b/src/cl_program.h index 612ed96..74f0997 100644 --- a/src/cl_program.h +++ b/src/cl_program.h @@ -21,27 +21,28 @@ #define __CL_PROGRAM_H__ #include "cl_internals.h" +#include "gen/gbe_program.h" #include "CL/cl.h" #include #include // This is the structure ouput by the compiler -struct GenProgram; +struct _gbe_program; /* This maps an OCL file containing some kernels */ struct _cl_program { - uint64_t magic; /* To identify it as a program */ - volatile int ref_n; /* We reference count this object */ - struct GenProgram *gen_program; /* Program as ouput by the compiler */ - cl_kernel *ker; /* All kernels included by the OCL file */ - cl_program prev, next; /* We chain the programs together */ - cl_context ctx; /* Its parent context */ - char *bin; /* The program copied verbatim */ - size_t bin_sz; /* Its size in memory */ - uint32_t ker_n; /* Number of declared kernels */ - uint32_t from_source:1; /* Built from binary or source? */ - uint32_t is_built:1; /* Did we call clBuildProgram on it? */ + uint64_t magic; /* To identify it as a program */ + volatile int ref_n; /* We reference count this object */ + gbe_program opaque; /* (Opaque) program as ouput by the compiler */ + cl_kernel *ker; /* All kernels included by the OCL file */ + cl_program prev, next; /* We chain the programs together */ + cl_context ctx; /* Its parent context */ + char *bin; /* The program copied verbatim */ + size_t bin_sz; /* Its size in memory */ + uint32_t ker_n; /* Number of declared kernels */ + uint32_t from_source:1; /* Built from binary or source? */ + uint32_t is_built:1; /* Did we call clBuildProgram on it? */ }; /* Create a empty program */ -- 2.7.4