Commit 97c41c9b authored by Joseph Noir's avatar Joseph Noir

added pfn_notify callback to print error messages

removed build log from program, since it is printed by the callback
parent b2ff851b
...@@ -93,12 +93,20 @@ void opencl_metainfo::initialize() ...@@ -93,12 +93,20 @@ void opencl_metainfo::initialize()
throw runtime_error(oss.str()); throw runtime_error(oss.str());
} }
auto pfn_notify = [](const char *errinfo,
const void *,
size_t,
void *) {
CPPA_LOG_ERROR("\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(),
nullptr, pfn_notify,
nullptr, nullptr,
&err)); &err));
if (err != CL_SUCCESS) { if (err != CL_SUCCESS) {
......
...@@ -70,77 +70,21 @@ program program::create(const char* kernel_source, uint32_t device_id) { ...@@ -70,77 +70,21 @@ program program::create(const char* kernel_source, uint32_t device_id) {
&kernel_source, &kernel_source,
&kernel_source_length, &kernel_source_length,
&err)); &err));
if (err != CL_SUCCESS) { if (err != CL_SUCCESS) {
throw runtime_error("clCreateProgramWithSource: " throw runtime_error("clCreateProgramWithSource: "
+ get_opencl_error(err)); + get_opencl_error(err));
} }
auto program_build_info = [&](size_t vs, void* v, size_t* vsr) {
return clGetProgramBuildInfo(pptr.get(),
devices[device_id].m_device.get(),
CL_PROGRAM_BUILD_LOG,
vs,
v,
vsr);
};
// 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, nullptr, nullptr, nullptr); err = clBuildProgram(pptr.get(), 1, &dev_tmp, nullptr, 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);
size_t ret_size; // the build log will be printed by the
auto bi_err = program_build_info(0, nullptr, &ret_size); // pfn_notify (see opencl_metainfo.cpp)
if (bi_err == CL_SUCCESS) {
vector<char> build_log(ret_size);
bi_err = program_build_info(ret_size, build_log.data(), nullptr);
if (bi_err == CL_SUCCESS) {
if (ret_size <= 1) {
oss << " (no build log available)";
}
else {
build_log[ret_size - 1] = '\0';
cerr << build_log.data() << endl;
}
}
else { // program_build_info failed to get log
oss << " (with CL_PROGRAM_BUILD_LOG to get log)";
}
}
else { // program_build_info failed to get size of the log
oss << " (with CL_PROGRAM_BUILD_LOG to get size)";
}
CPPA_LOGM_ERROR(detail::demangle<program>().c_str(), oss.str());
throw runtime_error(oss.str()); throw runtime_error(oss.str());
} }
# ifdef CPPA_DEBUG_MODE
else {
const char* where = "CL_PROGRAM_BUILD_LOG:get size";
size_t ret_size;
err = program_build_info(0, nullptr, &ret_size);
if (err == CL_SUCCESS) {
where = "CL_PROGRAM_BUILD_LOG:get log";
vector<char> build_log(ret_size+1);
err = program_build_info(ret_size, build_log.data(), nullptr);
if (err == CL_SUCCESS) {
if (ret_size > 1) {
CPPA_LOGM_ERROR(detail::demangle<program>().c_str(),
"clBuildProgram: error");
build_log[ret_size - 1] = '\0';
cerr << "clBuildProgram build log:\n"
<< build_log.data() << endl;
}
}
}
if (err != CL_SUCCESS) {
CPPA_LOGM_ERROR(detail::demangle<program>().c_str(),
"clGetProgramBuildInfo (" << where << "): "
<< get_opencl_error(err));
}
}
# endif
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