[Beignet] [PATCH 2/7] Add the get gen version callback function
junyan.he at inbox.com
junyan.he at inbox.com
Tue Apr 15 17:55:27 PDT 2014
From: Junyan He <junyan.he at linux.intel.com>
Add a get gen version callback. We will get
the gen version when init. The version info
will be passed to create the according gen_context
and gen_encoder.
Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
backend/src/backend/gen_program.cpp | 7 ++++---
backend/src/backend/gen_program.hpp | 2 +-
backend/src/backend/program.cpp | 11 ++++++-----
backend/src/backend/program.h | 4 +++-
backend/src/backend/program.hpp | 6 +++---
backend/src/gbe_bin_generater.cpp | 3 ++-
src/cl_api.c | 1 +
src/cl_driver.h | 4 ++++
src/cl_driver_defs.c | 1 +
src/cl_program.c | 7 +++++--
src/cl_program.h | 1 +
src/intel/intel_driver.c | 22 +++++++++++++++++++++-
src/intel/intel_gpgpu.c | 2 +-
src/intel/intel_gpgpu.h | 2 +-
14 files changed, 54 insertions(+), 19 deletions(-)
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 22f4aa1..21fe636 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -85,7 +85,7 @@ namespace gbe {
{8,true},
};
- Kernel *GenProgram::compileKernel(const ir::Unit &unit, const std::string &name) {
+ Kernel *GenProgram::compileKernel(const ir::Unit &unit, const std::string &name, int gen_ver) {
// Be careful when the simdWidth is forced by the programmer. We can see it
// when the function already provides the simd width we need to use (i.e.
@@ -152,13 +152,14 @@ namespace gbe {
size_t stringSize,
char *err,
size_t *errSize,
- int optLevel)
+ int optLevel,
+ int gen_ver)
{
using namespace gbe;
GenProgram *program = GBE_NEW_NO_ARG(GenProgram);
std::string error;
// Try to compile the program
- if (program->buildFromLLVMFile(fileName, error, optLevel) == false) {
+ if (program->buildFromLLVMFile(fileName, error, optLevel, gen_ver) == false) {
if (err != NULL && errSize != NULL && stringSize > 0u) {
const size_t msgSize = std::min(error.size(), stringSize-1u);
std::memcpy(err, error.c_str(), msgSize);
diff --git a/backend/src/backend/gen_program.hpp b/backend/src/backend/gen_program.hpp
index f78e324..194b2e5 100644
--- a/backend/src/backend/gen_program.hpp
+++ b/backend/src/backend/gen_program.hpp
@@ -62,7 +62,7 @@ namespace gbe
/*! Destroy the program */
virtual ~GenProgram(void);
/*! Implements base class */
- virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name);
+ virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name, int gen_ver);
/*! Allocate an empty kernel. */
virtual Kernel *allocateKernel(const std::string &name) {
return GBE_NEW(GenKernel, name);
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 5fddd64..c86a94d 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -102,7 +102,7 @@ namespace gbe {
BVAR(OCL_OUTPUT_GEN_IR, false);
- bool Program::buildFromLLVMFile(const char *fileName, std::string &error, int optLevel) {
+ bool Program::buildFromLLVMFile(const char *fileName, std::string &error, int optLevel, int gen_ver) {
ir::Unit *unit = new ir::Unit();
if (llvmToGen(*unit, fileName, optLevel) == false) {
error = std::string(fileName) + " not found";
@@ -116,12 +116,12 @@ namespace gbe {
llvmToGen(*unit, fileName, 0); //suppose file exists and llvmToGen will not return false.
}
assert(unit->getValid());
- this->buildFromUnit(*unit, error);
+ this->buildFromUnit(*unit, error, gen_ver);
delete unit;
return true;
}
- bool Program::buildFromUnit(const ir::Unit &unit, std::string &error) {
+ bool Program::buildFromUnit(const ir::Unit &unit, std::string &error, int gen_ver) {
constantSet = new ir::ConstantSet(unit.getConstantSet());
const auto &set = unit.getFunctionSet();
const uint32_t kernelNum = set.size();
@@ -129,7 +129,7 @@ namespace gbe {
if (kernelNum == 0) return true;
for (const auto &pair : set) {
const std::string &name = pair.first;
- Kernel *kernel = this->compileKernel(unit, name);
+ Kernel *kernel = this->compileKernel(unit, name, gen_ver);
kernel->setSamplerSet(pair.second->getSamplerSet());
kernel->setImageSet(pair.second->getImageSet());
kernel->setCompileWorkGroupSize(pair.second->getCompileWorkGroupSize());
@@ -692,6 +692,7 @@ namespace gbe {
static gbe_program programNewFromSource(const char *source,
size_t stringSize,
const char *options,
+ int gen_ver,
char *err,
size_t *errSize)
{
@@ -829,7 +830,7 @@ namespace gbe {
clangErrSize = *errSize;
}
p = gbe_program_new_from_llvm(llName.c_str(), stringSize,
- err, errSize, optLevel);
+ err, errSize, optLevel, gen_ver);
if (err != NULL)
*errSize += clangErrSize;
gbe_mutex.unlock();
diff --git a/backend/src/backend/program.h b/backend/src/backend/program.h
index 5f308ad..7e8efaa 100644
--- a/backend/src/backend/program.h
+++ b/backend/src/backend/program.h
@@ -116,6 +116,7 @@ extern gbe_kernel_get_image_data_cb *gbe_kernel_get_image_data;
typedef gbe_program (gbe_program_new_from_source_cb)(const char *source,
size_t stringSize,
const char *options,
+ int gen_ver,
char *err,
size_t *err_size);
extern gbe_program_new_from_source_cb *gbe_program_new_from_source;
@@ -133,7 +134,8 @@ typedef gbe_program (gbe_program_new_from_llvm_cb)(const char *fileName,
size_t string_size,
char *err,
size_t *err_size,
- int optLevel);
+ int optLevel,
+ int gen_ver);
extern gbe_program_new_from_llvm_cb *gbe_program_new_from_llvm;
/*! Get the size of global constants */
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index e6fc411..7a191ce 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -229,9 +229,9 @@ namespace gbe {
return kernel;
}
/*! Build a program from a ir::Unit */
- bool buildFromUnit(const ir::Unit &unit, std::string &error);
+ bool buildFromUnit(const ir::Unit &unit, std::string &error, int gen_ver);
/*! Buils a program from a LLVM source code */
- bool buildFromLLVMFile(const char *fileName, std::string &error, int optLevel);
+ bool buildFromLLVMFile(const char *fileName, std::string &error, int optLevel, int gen_ver);
/*! Buils a program from a OCL string */
bool buildFromSource(const char *source, std::string &error);
/*! Get size of the global constant arrays */
@@ -261,7 +261,7 @@ namespace gbe {
protected:
/*! Compile a kernel */
- virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name) = 0;
+ virtual Kernel *compileKernel(const ir::Unit &unit, const std::string &name, int gen_ver) = 0;
/*! Allocate an empty kernel. */
virtual Kernel *allocateKernel(const std::string &name) = 0;
/*! Kernels sorted by their name */
diff --git a/backend/src/gbe_bin_generater.cpp b/backend/src/gbe_bin_generater.cpp
index f813775..9c4f74f 100644
--- a/backend/src/gbe_bin_generater.cpp
+++ b/backend/src/gbe_bin_generater.cpp
@@ -190,9 +190,10 @@ void program_build_instance::serialize_program(void) throw(int)
}
+// TODO: need to build for gen7 and gen75 each here.
void program_build_instance::build_program(void) throw(int)
{
- gbe_program opaque = gbe_program_new_from_source(code, 0, build_opt.c_str(), NULL, NULL);
+ gbe_program opaque = gbe_program_new_from_source(code, 0, build_opt.c_str(), 70, NULL, NULL);
if (!opaque)
throw FILE_BUILD_FAILED;
diff --git a/src/cl_api.c b/src/cl_api.c
index 9638994..2c74fdf 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -2770,6 +2770,7 @@ clCreateProgramWithLLVMIntel(cl_context context,
num_devices,
devices,
filename,
+ cl_gen_version(),
errcode_ret);
}
diff --git a/src/cl_driver.h b/src/cl_driver.h
index 9dc2330..d294afa 100644
--- a/src/cl_driver.h
+++ b/src/cl_driver.h
@@ -34,6 +34,10 @@
* to minimize the code specific for the HW and for the simulator
**************************************************************************/
/* Create a new driver */
+typedef int (cl_gen_version_cb)(void);
+extern cl_gen_version_cb *cl_gen_version;
+
+/* Create a new driver */
typedef cl_driver (cl_driver_new_cb)(cl_context_prop);
extern cl_driver_new_cb *cl_driver_new;
diff --git a/src/cl_driver_defs.c b/src/cl_driver_defs.c
index 95a1a03..f2c1778 100644
--- a/src/cl_driver_defs.c
+++ b/src/cl_driver_defs.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
/* Driver */
+LOCAL cl_gen_version_cb *cl_gen_version = NULL;
LOCAL cl_driver_new_cb *cl_driver_new = NULL;
LOCAL cl_driver_delete_cb *cl_driver_delete = NULL;
LOCAL cl_driver_get_bufmgr_cb *cl_driver_get_bufmgr = NULL;
diff --git a/src/cl_program.c b/src/cl_program.c
index 10eecee..43532c1 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -213,6 +213,7 @@ cl_program_create_from_llvm(cl_context ctx,
cl_uint num_devices,
const cl_device_id *devices,
const char *file_name,
+ int gen_ver,
cl_int *errcode_ret)
{
cl_program program = NULL;
@@ -225,7 +226,8 @@ cl_program_create_from_llvm(cl_context ctx,
INVALID_VALUE_IF (file_name == NULL);
program = cl_program_new(ctx);
- program->opaque = gbe_program_new_from_llvm(file_name, program->build_log_max_sz, program->build_log, &program->build_log_sz, 1);
+ program->opaque = gbe_program_new_from_llvm(file_name, program->build_log_max_sz, program->build_log,
+ &program->build_log_sz, 1, gen_ver);
if (UNLIKELY(program->opaque == NULL)) {
err = CL_INVALID_PROGRAM;
goto error;
@@ -326,7 +328,8 @@ cl_program_build(cl_program p, const char *options)
}
if (p->source_type == FROM_SOURCE) {
- p->opaque = gbe_program_new_from_source(p->source, p->build_log_max_sz, options, p->build_log, &p->build_log_sz);
+ p->opaque = gbe_program_new_from_source(p->source, p->build_log_max_sz, options,
+ cl_gen_version(), p->build_log, &p->build_log_sz);
if (UNLIKELY(p->opaque == NULL)) {
if (p->build_log_sz > 0 && strstr(p->build_log, "error: error reading 'options'"))
err = CL_INVALID_BUILD_OPTIONS;
diff --git a/src/cl_program.h b/src/cl_program.h
index a6d75da..3720eae 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -98,6 +98,7 @@ cl_program_create_from_llvm(cl_context context,
cl_uint num_devices,
const cl_device_id * devices,
const char * fileName,
+ int gen_ver,
cl_int * errcode_ret);
/* Build the program as specified by OCL */
diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c
index 5e474de..40d0bf2 100644
--- a/src/intel/intel_driver.c
+++ b/src/intel/intel_driver.c
@@ -75,6 +75,7 @@
#include "cl_driver.h"
#include "cl_device_id.h"
#include "cl_platform_id.h"
+#include "cl_device_data.h"
#define SET_BLOCKED_SIGSET(DRIVER) do { \
sigset_t bl_mask; \
@@ -652,9 +653,28 @@ static int intel_buffer_set_tiling(cl_buffer bo,
return ret;
}
+static int gen_version = 0;
+
+static int intel_get_gen_version(void)
+{
+ return gen_version;
+}
+
LOCAL void
intel_setup_callbacks(void)
{
+ const int device_id = intel_get_device_id();
+
+ if (IS_HASWELL(device_id))
+ gen_version = 75;
+ else if (IS_IVYBRIDGE(device_id))
+ gen_version = 70;
+ else {
+ printf("We can just support IVB and HAS now\n");
+ exit(-1);
+ }
+
+ cl_gen_version = (cl_gen_version_cb *) intel_get_gen_version;
cl_driver_new = (cl_driver_new_cb *) cl_intel_driver_new;
cl_driver_delete = (cl_driver_delete_cb *) cl_intel_driver_delete;
cl_driver_get_ver = (cl_driver_get_ver_cb *) intel_driver_get_ver;
@@ -683,5 +703,5 @@ intel_setup_callbacks(void)
cl_buffer_subdata = (cl_buffer_subdata_cb *) drm_intel_bo_subdata;
cl_buffer_wait_rendering = (cl_buffer_wait_rendering_cb *) drm_intel_bo_wait_rendering;
cl_buffer_get_fd = (cl_buffer_get_fd_cb *) drm_intel_bo_gem_export_to_prime;
- intel_set_gpgpu_callbacks();
+ intel_set_gpgpu_callbacks(device_id);
}
diff --git a/src/intel/intel_gpgpu.c b/src/intel/intel_gpgpu.c
index e95b050..4cb9e0b 100644
--- a/src/intel/intel_gpgpu.c
+++ b/src/intel/intel_gpgpu.c
@@ -1066,7 +1066,7 @@ intel_gpgpu_event_get_exec_timestamp(intel_event_t *event,
}
LOCAL void
-intel_set_gpgpu_callbacks(void)
+intel_set_gpgpu_callbacks(int device_id)
{
cl_gpgpu_new = (cl_gpgpu_new_cb *) intel_gpgpu_new;
cl_gpgpu_delete = (cl_gpgpu_delete_cb *) intel_gpgpu_delete;
diff --git a/src/intel/intel_gpgpu.h b/src/intel/intel_gpgpu.h
index 9918b35..d593ac7 100644
--- a/src/intel/intel_gpgpu.h
+++ b/src/intel/intel_gpgpu.h
@@ -28,7 +28,7 @@
#include <stdint.h>
/* Set the gpgpu related call backs */
-extern void intel_set_gpgpu_callbacks(void);
+extern void intel_set_gpgpu_callbacks(int device_id);
#endif /* __INTEL_GPGPU_H__ */
--
1.7.9.5
More information about the Beignet
mailing list