Commit ae3395da authored by Marian Triebe's avatar Marian Triebe

Print OpenCL error log on all systems

This patch removes the "pfn notify" callbacks for printing build errors,
because it is not supported on all platforms.
parent 8ee40cc1
...@@ -39,11 +39,8 @@ const std::vector<device_info> opencl_metainfo::get_devices() const { ...@@ -39,11 +39,8 @@ const std::vector<device_info> opencl_metainfo::get_devices() const {
return m_devices; return m_devices;
} }
void opencl_metainfo::initialize() void opencl_metainfo::initialize() {
{
cl_int err{0}; cl_int err{0};
// get number of available platforms // get number of available platforms
cl_uint number_of_platforms; cl_uint number_of_platforms;
err = clGetPlatformIDs(0, nullptr, &number_of_platforms); err = clGetPlatformIDs(0, nullptr, &number_of_platforms);
...@@ -54,8 +51,6 @@ void opencl_metainfo::initialize() ...@@ -54,8 +51,6 @@ void opencl_metainfo::initialize()
CPPA_LOGMF(CPPA_ERROR, oss.str()); CPPA_LOGMF(CPPA_ERROR, oss.str());
throw logic_error(oss.str()); throw logic_error(oss.str());
} }
// get platform ids // get platform ids
vector<cl_platform_id> ids(number_of_platforms); vector<cl_platform_id> ids(number_of_platforms);
err = clGetPlatformIDs(ids.size(), ids.data(), nullptr); err = clGetPlatformIDs(ids.size(), ids.data(), nullptr);
...@@ -66,8 +61,6 @@ void opencl_metainfo::initialize() ...@@ -66,8 +61,6 @@ void opencl_metainfo::initialize()
CPPA_LOGMF(CPPA_ERROR, oss.str()); CPPA_LOGMF(CPPA_ERROR, oss.str());
throw logic_error(oss.str()); throw logic_error(oss.str());
} }
// find gpu devices on our platform // find gpu devices on our platform
int pid{0}; int pid{0};
cl_uint num_devices{0}; cl_uint num_devices{0};
...@@ -93,23 +86,11 @@ void opencl_metainfo::initialize() ...@@ -93,23 +86,11 @@ void opencl_metainfo::initialize()
CPPA_LOGMF(CPPA_ERROR, oss.str()); CPPA_LOGMF(CPPA_ERROR, oss.str());
throw runtime_error(oss.str()); throw runtime_error(oss.str());
} }
auto pfn_notify = [](const char *errinfo,
const void *,
size_t,
void *) {
CPPA_LOGC_ERROR("cppa::opencl::opencl_metainfo",
"initialize",
"\n##### Error message via pfn_notify #####\n" +
string(errinfo) +
"\n########################################");
};
// create a context // create a context
m_context.adopt(clCreateContext(0, m_context.adopt(clCreateContext(0,
devices.size(), devices.size(),
devices.data(), devices.data(),
pfn_notify, nullptr,
nullptr, nullptr,
&err)); &err));
if (err != CL_SUCCESS) { if (err != CL_SUCCESS) {
...@@ -118,8 +99,7 @@ void opencl_metainfo::initialize() ...@@ -118,8 +99,7 @@ void opencl_metainfo::initialize()
CPPA_LOGMF(CPPA_ERROR, oss.str()); CPPA_LOGMF(CPPA_ERROR, oss.str());
throw runtime_error(oss.str()); throw runtime_error(oss.str());
} }
// create command queues
for (auto& d : devices) { for (auto& d : devices) {
CPPA_LOG_TRACE("Creating command queue for device(s)."); CPPA_LOG_TRACE("Creating command queue for device(s).");
device_ptr device; device_ptr device;
...@@ -193,7 +173,6 @@ void opencl_metainfo::initialize() ...@@ -193,7 +173,6 @@ void opencl_metainfo::initialize()
m_devices.push_back(move(dev_info)); m_devices.push_back(move(dev_info));
} }
} }
if (m_devices.empty()) { if (m_devices.empty()) {
ostringstream oss; ostringstream oss;
oss << "Could not create a command queue for " oss << "Could not create a command queue for "
...@@ -218,4 +197,3 @@ opencl_metainfo* get_opencl_metainfo() { ...@@ -218,4 +197,3 @@ opencl_metainfo* get_opencl_metainfo() {
} // namespace opencl } // namespace opencl
} // namespace cppa } // namespace cppa
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include "cppa/config.hpp"
#include "cppa/singletons.hpp" #include "cppa/singletons.hpp"
#include "cppa/opencl/program.hpp" #include "cppa/opencl/program.hpp"
#include "cppa/opencl/opencl_metainfo.hpp" #include "cppa/opencl/opencl_metainfo.hpp"
...@@ -42,7 +43,6 @@ using namespace std; ...@@ -42,7 +43,6 @@ using namespace std;
namespace cppa { namespace cppa {
namespace opencl { namespace opencl {
program::program(context_ptr context, command_queue_ptr queue, program_ptr program) program::program(context_ptr context, command_queue_ptr queue, program_ptr program)
: m_context(move(context)), m_program(move(program)), m_queue(move(queue)) { } : m_context(move(context)), m_program(move(program)), m_queue(move(queue)) { }
...@@ -50,8 +50,6 @@ program program::create(const char* kernel_source, const char* options, uint32_t ...@@ -50,8 +50,6 @@ program program::create(const char* kernel_source, const char* options, uint32_t
auto metainfo = get_opencl_metainfo(); auto metainfo = get_opencl_metainfo();
auto devices = metainfo->get_devices(); auto devices = metainfo->get_devices();
auto context = metainfo->m_context; auto context = metainfo->m_context;
if (devices.size() <= device_id) { if (devices.size() <= device_id) {
ostringstream oss; ostringstream oss;
oss << "Device id " << device_id oss << "Device id " << device_id
...@@ -60,9 +58,7 @@ program program::create(const char* kernel_source, const char* options, uint32_t ...@@ -60,9 +58,7 @@ program program::create(const char* kernel_source, const char* options, uint32_t
CPPA_LOGM_ERROR(detail::demangle<program>().c_str(), oss.str()); CPPA_LOGM_ERROR(detail::demangle<program>().c_str(), oss.str());
throw runtime_error(oss.str()); throw runtime_error(oss.str());
} }
cl_int err{0}; cl_int err{0};
// create program object from kernel source // create program object from kernel source
size_t kernel_source_length = strlen(kernel_source); size_t kernel_source_length = strlen(kernel_source);
program_ptr pptr; program_ptr pptr;
...@@ -75,15 +71,37 @@ program program::create(const char* kernel_source, const char* options, uint32_t ...@@ -75,15 +71,37 @@ program program::create(const char* kernel_source, const char* options, uint32_t
throw runtime_error("clCreateProgramWithSource: " throw runtime_error("clCreateProgramWithSource: "
+ get_opencl_error(err)); + get_opencl_error(err));
} }
// build programm from program object // build programm from program object
auto dev_tmp = devices[device_id].m_device.get(); auto dev_tmp = devices[device_id].m_device.get();
err = clBuildProgram(pptr.get(), 1, &dev_tmp, options, nullptr, nullptr); err = clBuildProgram(pptr.get(), 1, &dev_tmp, options, nullptr, nullptr);
if (err != CL_SUCCESS) { if (err != CL_SUCCESS) {
ostringstream oss; ostringstream oss;
oss << "clBuildProgram: " << get_opencl_error(err); oss << "clBuildProgram: " << get_opencl_error(err);
// the build log will be printed by the // get the build log
// pfn_notify (see opencl_metainfo.cpp) if (err == CL_BUILD_PROGRAM_FAILURE) {
size_t buildlog_buffer_size = 0;
// get the log length
clGetProgramBuildInfo(pptr.get(),
dev_tmp,
CL_PROGRAM_BUILD_LOG,
sizeof(buildlog_buffer_size),
nullptr,
&buildlog_buffer_size);
vector<char> buffer(buildlog_buffer_size);
// fill the buffer with buildlog informations
clGetProgramBuildInfo(pptr.get(),
dev_tmp,
CL_PROGRAM_BUILD_LOG,
sizeof(buffer[0]) * buildlog_buffer_size,
buffer.data(),
nullptr);
// make sure string is null terminated
buffer.push_back('\0');
cerr << "OpenCL build error log: "
<< endl
<< buffer.data()
<< endl;
}
throw runtime_error(oss.str()); throw runtime_error(oss.str());
} }
return {context, devices[device_id].m_cmd_queue, pptr}; return {context, devices[device_id].m_cmd_queue, pptr};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment