From af6a9eedd118b0e3d7f1a2098c10ff90b27b5d0e Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Sat, 11 May 2019 20:39:00 +0200 Subject: [PATCH] Added a function to set the OpenCL kernel standard, either 1.1 or 1.2 --- src/clpp11.hpp | 1 - src/routine.cpp | 1 + src/utilities/compile.cpp | 1 + src/utilities/utilities.cpp | 13 +++++++++++++ src/utilities/utilities.hpp | 4 ++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/clpp11.hpp b/src/clpp11.hpp index 786f7dbb..aeb14989 100644 --- a/src/clpp11.hpp +++ b/src/clpp11.hpp @@ -485,7 +485,6 @@ class Program { // Compiles the device program and checks whether or not there are any warnings/errors void Build(const Device &device, std::vector &options) { - options.push_back("-cl-std=CL1.1"); auto options_string = std::accumulate(options.begin(), options.end(), std::string{" "}); const cl_device_id dev = device(); CheckError(clBuildProgram(program_, 1, &dev, options_string.c_str(), nullptr, nullptr)); diff --git a/src/routine.cpp b/src/routine.cpp index 2df6d563..ed1b58ee 100644 --- a/src/routine.cpp +++ b/src/routine.cpp @@ -97,6 +97,7 @@ void Routine::InitProgram(std::initializer_list source) { &has_binary); if (has_binary) { program_ = std::make_shared(device_, context_, binary); + SetOpenCLKernelStandard(device_, options); program_->Build(device_, options); ProgramCache::Instance().Store(ProgramKey{ context_(), device_(), precision_, routine_info }, std::shared_ptr{program_}); diff --git a/src/utilities/compile.cpp b/src/utilities/compile.cpp index 00cb90cb..aeb7a3e2 100644 --- a/src/utilities/compile.cpp +++ b/src/utilities/compile.cpp @@ -111,6 +111,7 @@ std::shared_ptr CompileFromSource( // Compiles the kernel auto program = std::make_shared(context, kernel_string); try { + SetOpenCLKernelStandard(device, options); program->Build(device, options); } catch (const CLCudaAPIBuildError &e) { if (program->StatusIsCompilationWarningOrError(e.status()) && !silent) { diff --git a/src/utilities/utilities.cpp b/src/utilities/utilities.cpp index a0e89c98..29161e74 100644 --- a/src/utilities/utilities.cpp +++ b/src/utilities/utilities.cpp @@ -498,6 +498,19 @@ std::string GetDeviceName(const Device& device) { // ================================================================================================= +void SetOpenCLKernelStandard(const Device &device, std::vector &options) { + // Inclusion of one of the following extensions needs OpenCL 1.2 kernels + if (device.HasExtension(kKhronosIntelSubgroups)) { + options.push_back("-cl-std=CL1.2"); + } + // Otherwise we fall-back to the default CLBlast OpenCL 1.1 + else { + options.push_back("-cl-std=CL1.1"); + } +} + +// ================================================================================================= + // Solve Bezout's identity // a * p + b * q = r = GCD(a, b) void EuclidGCD(int a, int b, int &p, int &q, int &r) { diff --git a/src/utilities/utilities.hpp b/src/utilities/utilities.hpp index 23486d35..b66df118 100644 --- a/src/utilities/utilities.hpp +++ b/src/utilities/utilities.hpp @@ -375,6 +375,10 @@ std::string GetDeviceName(const Device& device); // ================================================================================================= +void SetOpenCLKernelStandard(const Device &device, std::vector &options); + +// ================================================================================================= + // Solve Bezout's identity // a * p + b * q = r = GCD(a, b) void EuclidGCD(int a, int b, int &p, int &q, int &r);