From db01df115b41adeff9d00422d466e0d7fdb770fa Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Mon, 25 May 2015 14:01:15 +0200 Subject: [PATCH 1/5] Repaired an exception-printing bug --- src/cltune.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cltune.cc b/src/cltune.cc index 053f90b..9a1d0e5 100644 --- a/src/cltune.cc +++ b/src/cltune.cc @@ -164,7 +164,9 @@ template void Tuner::AddArgumentInput(const std::vector &source) { auto device_buffer = Buffer(pimpl->context(), CL_MEM_READ_ONLY, source.size()*sizeof(T)); auto status = device_buffer.WriteBuffer(pimpl->queue(), source.size()*sizeof(T), source); - if (status != CL_SUCCESS) { throw std::runtime_error("Write buffer error: " + status); } + if (status != CL_SUCCESS) { + throw std::runtime_error("Write buffer error: " + std::to_string(status)); + } auto argument = TunerImpl::MemArgument{pimpl->argument_counter_++, source.size(), pimpl->GetType(), device_buffer}; pimpl->arguments_input_.push_back(argument); From 435065b9bea98f662c3207ff410826bfb33e12aa Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Mon, 25 May 2015 14:05:56 +0200 Subject: [PATCH 2/5] Improved printing of errors in case of kernel failure --- src/tuner_impl.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tuner_impl.cc b/src/tuner_impl.cc index 6b18297..3b8b100 100644 --- a/src/tuner_impl.cc +++ b/src/tuner_impl.cc @@ -190,14 +190,14 @@ void TunerImpl::Tune() { // Stores the parameters and the timing-result tuning_result.configuration = permutation; tuning_results_.push_back(tuning_result); - if (!tuning_result.status) { - PrintResult(stdout, tuning_result, kMessageWarning); - } if (tuning_result.time == std::numeric_limits::max()) { tuning_result.time = 0.0; PrintResult(stdout, tuning_result, kMessageFailure); tuning_result.time = std::numeric_limits::max(); } + else if (!tuning_result.status) { + PrintResult(stdout, tuning_result, kMessageWarning); + } } // Prints a log of the searching process. This is disabled per default, but can be enabled From 11844f5ab2cd9eaef1e93c2a954bed89ad70a118 Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Mon, 25 May 2015 14:09:02 +0200 Subject: [PATCH 3/5] Updated the OpenCL C++ API with explicit, const and new functions --- include/internal/clpp11.h | 61 ++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/include/internal/clpp11.h b/include/internal/clpp11.h index dffe112..636afa4 100644 --- a/include/internal/clpp11.h +++ b/include/internal/clpp11.h @@ -53,10 +53,10 @@ class Object { protected: // Error handling - [[noreturn]] void Error(const std::string &message) { + [[noreturn]] void Error(const std::string &message) const { throw std::runtime_error("Internal OpenCL error: "+message); } - [[noreturn]] void Error(const cl_int status) { + [[noreturn]] void Error(const cl_int status) const { throw std::runtime_error("Internal OpenCL error with status: "+std::to_string(status)); } }; @@ -75,10 +75,10 @@ class Event: public Object { public: // Constructor based on the plain C data-type - Event(const cl_event event): event_(event) { } + explicit Event(const cl_event event): event_(event) { } // New event - Event() {} + Event(): event_() {} // Public functions size_t GetProfilingStart() const { @@ -113,10 +113,10 @@ class Platform: public Object { public: // Constructor based on the plain C data-type - Platform(const cl_platform_id platform): platform_(platform) { } + explicit Platform(const cl_platform_id platform): platform_(platform) { } // Initialize the platform. Note that this constructor can throw exceptions! - Platform(const size_t platform_id) { + explicit Platform(const size_t platform_id) { auto num_platforms = cl_uint{0}; auto status = clGetPlatformIDs(0, nullptr, &num_platforms); if (status != CL_SUCCESS) { Error(status); } @@ -142,10 +142,10 @@ class Device: public Object { public: // Constructor based on the plain C data-type - Device(const cl_device_id device): device_(device) { } + explicit Device(const cl_device_id device): device_(device) { } // Initialize the device. Note that this constructor can throw exceptions! - Device(const Platform &platform, const cl_device_type type, const size_t device_id) { + explicit Device(const Platform &platform, const cl_device_type type, const size_t device_id) { auto num_devices = cl_uint{0}; auto status = clGetDeviceIDs(platform(), type, 0, nullptr, &num_devices); if (status != CL_SUCCESS) { Error(status); } @@ -159,6 +159,8 @@ class Device: public Object { // Public functions std::string Version() const { return GetInfoString(CL_DEVICE_VERSION); } + cl_device_type Type() const { return GetInfo(CL_DEVICE_TYPE); } + std::string Vendor() const { return GetInfoString(CL_DEVICE_VENDOR); } std::string Name() const { return GetInfoString(CL_DEVICE_NAME); } std::string Extensions() const { return GetInfoString(CL_DEVICE_EXTENSIONS); } size_t MaxWorkGroupSize() const { return GetInfo(CL_DEVICE_MAX_WORK_GROUP_SIZE); } @@ -225,12 +227,12 @@ class Context: public ObjectWithState { public: // Constructor based on the plain C data-type - Context(const cl_context context): context_(context) { + explicit Context(const cl_context context): context_(context) { clRetainContext(context_); } // Memory management - Context(const Device &device) { + explicit Context(const Device &device) { auto status = CL_SUCCESS; const cl_device_id dev = device(); context_ = clCreateContext(nullptr, 1, &dev, nullptr, nullptr, &status); @@ -267,7 +269,7 @@ class Program: public ObjectWithState { // Note that there is no constructor based on the plain C data-type because of extra state // Memory management - Program(const Context &context, const std::string &source): + explicit Program(const Context &context, const std::string &source): length_(source.length()) { std::copy(source.begin(), source.end(), back_inserter(source_)); source_ptr_ = source_.data(); @@ -289,6 +291,16 @@ class Program: public ObjectWithState { swap(*this, other); return *this; } + /* + TODO: Implement move construction/assignment? + Program(Program &&other) { + clRetainProgram(program_); + swap(*this, other); + } + Program& operator=(Program &&other) { + swap(*this, other); + return *this; + }*/ friend void swap(Program &first, Program &second) { std::swap(first.length_, second.length_); std::swap(first.source_, second.source_); @@ -326,12 +338,12 @@ class Kernel: public ObjectWithState { public: // Constructor based on the plain C data-type - Kernel(const cl_kernel kernel): kernel_(kernel) { + explicit Kernel(const cl_kernel kernel): kernel_(kernel) { clRetainKernel(kernel_); } // Memory management - Kernel(const Program &program, const std::string &name) { + explicit Kernel(const Program &program, const std::string &name) { auto status = CL_SUCCESS; kernel_ = clCreateKernel(program(), name.c_str(), &status); if (status != CL_SUCCESS) { Error(status); } @@ -352,11 +364,11 @@ class Kernel: public ObjectWithState { } // Public functions - template - cl_int SetArgument(const cl_uint index, const T value) { + template // Note: doesn't work with T=Buffer + cl_int SetArgument(const cl_uint index, const T &value) { return clSetKernelArg(kernel_, index, sizeof(T), &value); } - size_t LocalMemUsage(const Device &device) { + size_t LocalMemUsage(const Device &device) const { auto bytes = size_t{0}; clGetKernelWorkGroupInfo(kernel_, device(), CL_KERNEL_LOCAL_MEM_SIZE, 0, nullptr, &bytes); auto result = size_t{0}; @@ -378,12 +390,12 @@ class CommandQueue: public ObjectWithState { public: // Constructor based on the plain C data-type - CommandQueue(const cl_command_queue queue): queue_(queue) { + explicit CommandQueue(const cl_command_queue queue): queue_(queue) { clRetainCommandQueue(queue_); } // Memory management - CommandQueue(const Context &context, const Device &device) { + explicit CommandQueue(const Context &context, const Device &device) { auto status = CL_SUCCESS; queue_ = clCreateCommandQueue(context(), device(), CL_QUEUE_PROFILING_ENABLE, &status); if (status != CL_SUCCESS) { Error(status); } @@ -441,12 +453,12 @@ class Buffer: public ObjectWithState { public: // Constructor based on the plain C data-type - Buffer(const cl_mem buffer): buffer_(buffer) { + explicit Buffer(const cl_mem buffer): buffer_(buffer) { clRetainMemObject(buffer_); } // Memory management - Buffer(const Context &context, const cl_mem_flags flags, const size_t bytes) { + explicit Buffer(const Context &context, const cl_mem_flags flags, const size_t bytes) { auto status = CL_SUCCESS; buffer_ = clCreateBuffer(context(), flags, bytes, nullptr, &status); if (status != CL_SUCCESS) { Error(status); } @@ -483,6 +495,15 @@ class Buffer: public ObjectWithState { cl_int WriteBuffer(const CommandQueue &queue, const size_t bytes, const std::vector &host) { return WriteBuffer(queue, bytes, &host[0]); } + size_t GetSize() const { + auto bytes = size_t{0}; + auto status = clGetMemObjectInfo(buffer_, CL_MEM_SIZE, 0, nullptr, &bytes); + if (status != CL_SUCCESS) { Error(status); } + auto result = size_t{0}; + status = clGetMemObjectInfo(buffer_, CL_MEM_SIZE, bytes, &result, nullptr); + if (status != CL_SUCCESS) { Error(status); } + return result; + } // Accessors to the private data-member cl_mem operator()() const { return buffer_; } From bc8b21c0cd0104548d24f06be8525bfd5422f8d5 Mon Sep 17 00:00:00 2001 From: CNugteren Date: Mon, 25 May 2015 14:14:16 +0200 Subject: [PATCH 4/5] Updated to version 1.6.2 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b53314f..805a6bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ cmake_minimum_required(VERSION 2.8) project("cltune" CXX) set(cltune_VERSION_MAJOR 1) set(cltune_VERSION_MINOR 6) -set(cltune_VERSION_PATCH 1) +set(cltune_VERSION_PATCH 2) # Options option(SAMPLES "Enable compilation of sample programs" ON) From 4cc9dbd911562f6455f0a150b2ea0296a0672b20 Mon Sep 17 00:00:00 2001 From: CNugteren Date: Mon, 25 May 2015 14:15:00 +0200 Subject: [PATCH 5/5] Updated to version 1.6.2 --- CHANGELOG | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index fb55234..e95cb19 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,9 @@ +Version 1.6.2 +- Fixed another exception-related bug +- Further improved reporting of failed runs +- Updated C++11 OpenCL API + Version 1.6.1 - Fixed a couple of issues related to exceptions - Improved reporting of failed runs