summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backend/src/backend/program.cpp17
-rwxr-xr-xbackend/src/ocl_stdlib.tmpl.h4
-rw-r--r--src/cl_program.c50
3 files changed, 66 insertions, 5 deletions
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 20471f94..40adc1d0 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -555,6 +555,7 @@ namespace gbe {
//Handle -cl-opt-disable in llvmToGen, skip here
const std::string unsupportedOptions("-cl-denorms-are-zero, -cl-strict-aliasing, -cl-opt-disable,"
"-cl-no-signed-zeros, -cl-fp32-correctly-rounded-divide-sqrt");
+ bool useDefaultCLCVersion = true;
while (end != std::string::npos) {
end = options.find(' ', start);
std::string str = options.substr(start, end - start);
@@ -564,9 +565,24 @@ namespace gbe {
if(str == "-cl-fast-relaxed-math") bFastMath = true;
if(unsupportedOptions.find(str) != std::string::npos)
continue;
+ if(str.find("-cl-std=") != std::string::npos) {
+ useDefaultCLCVersion = false;
+ if (str == "-cl-std=CL1.1")
+ args.push_back("-D__OPENCL_C_VERSION__=110");
+ else if (str == "-cl-std=CL1.2")
+ args.push_back("-D__OPENCL_C_VERSION__=120");
+ else {
+ if (err && stringSize > 0 && errSize)
+ *errSize = snprintf(err, stringSize, "Invalid build option: %s\n", str.c_str());
+ return false;
+ }
+ continue;
+ }
useless.push_back(str);
args.push_back(str.c_str());
}
+ if (useDefaultCLCVersion)
+ args.push_back("-D__OPENCL_C_VERSION__=120");
args.push_back("-mllvm");
args.push_back("-inline-threshold=200000");
#ifdef GEN7_SAMPLER_CLAMP_BORDER_WORKAROUND
@@ -759,7 +775,6 @@ namespace gbe {
"-cl-single-precision-constant",
// "-cl-denorms-are-zero",
"-cl-fast-relaxed-math",
- "-cl-std=",
};
const char * incompatible_defs[] = {
"GET_FLOAT_WORD",
diff --git a/backend/src/ocl_stdlib.tmpl.h b/backend/src/ocl_stdlib.tmpl.h
index 6f05dac3..1ee90fe6 100755
--- a/backend/src/ocl_stdlib.tmpl.h
+++ b/backend/src/ocl_stdlib.tmpl.h
@@ -124,9 +124,7 @@ typedef size_t __event_t;
#define __CL_VERSION_1_0__ 100
#define __CL_VERSION_1_1__ 110
#define __CL_VERSION_1_2__ 120
-#ifndef __OPENCL_C_VERSION
-#define __OPENCL_C_VERSION__ 120
-#endif
+
#define __ENDIAN_LITTLE__ 1
#define __IMAGE_SUPPORT__ 1
#define __kernel_exec(X, TYPE) __kernel __attribute__((work_group_size_hint(X,1,1))) \
diff --git a/src/cl_program.c b/src/cl_program.c
index a745c007..3ecc49ff 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -424,6 +424,43 @@ error:
goto exit;
}
+/* Before we do the real work, we need to check whether our platform
+ cl version can meet -cl-std= */
+static int check_cl_version_option(cl_program p, const char* options) {
+ const char* s = NULL;
+ int ver1 = 0;
+ int ver2 = 0;
+ char version_str[64];
+
+ if (options && (s = strstr(options, "-cl-std="))) {
+
+ if (s + strlen("-cl-std=CLX.X") > options + strlen(options)) {
+ return 0;
+ }
+
+ if (s[8] != 'C' || s[9] != 'L' || s[10] > '9' || s[10] < '0' || s[11] != '.'
+ || s[12] > '9' || s[12] < '0') {
+ return 0;
+ }
+
+ ver1 = (s[10] - '0') * 10 + (s[12] - '0');
+
+ if (cl_get_device_info(p->ctx->device, CL_DEVICE_OPENCL_C_VERSION, sizeof(version_str),
+ version_str, NULL) != CL_SUCCESS)
+ return 0;
+
+ assert(strstr(version_str, "OpenCL") && version_str[0] == 'O');
+ ver2 = (version_str[9] - '0') * 10 + (version_str[11] - '0');
+
+ if (ver2 < ver1)
+ return 0;
+
+ return 1;
+ }
+
+ return 1;
+}
+
LOCAL cl_int
cl_program_build(cl_program p, const char *options)
{
@@ -434,6 +471,9 @@ cl_program_build(cl_program p, const char *options)
if (p->ref_n > 1)
return CL_INVALID_OPERATION;
+ if (!check_cl_version_option(p, options))
+ return CL_BUILD_PROGRAM_FAILURE;
+
if (options) {
if(p->build_opts == NULL || strcmp(options, p->build_opts) != 0) {
if(p->build_opts) {
@@ -526,11 +566,16 @@ cl_program_link(cl_context context,
cl_int* errcode_ret)
{
cl_program p = NULL;
- cl_int err=CL_SUCCESS;
+ cl_int err = CL_SUCCESS;
cl_int i = 0;
int copyed = 0;
p = cl_program_new(context);
+ if (!check_cl_version_option(p, options)) {
+ err = CL_BUILD_PROGRAM_FAILURE;
+ goto error;
+ }
+
p->opaque = compiler_program_new_gen_program(context->device->vendor_id, NULL, NULL);
for(i = 0; i < num_input_programs; i++) {
@@ -588,6 +633,9 @@ cl_program_compile(cl_program p,
if (p->ref_n > 1)
return CL_INVALID_OPERATION;
+ if (!check_cl_version_option(p, options))
+ return CL_BUILD_PROGRAM_FAILURE;
+
if (options) {
if(p->build_opts == NULL || strcmp(options, p->build_opts) != 0) {
if(p->build_opts) {