Hello. I’m trying to create a OpenCL library from a collection of C source files with math. functions in it. The structure is as following:
- opencl_utils.h
- utility.h
- hashing.h
- hashing.c
- noise_gen.h
- noise_gen.c
I can compile and link everything up to hashing.c.
std::vector<Program> programs;
auto opencl_utils_h = compileProgram(readFile("src/main/cpp/opencl_utils.h"));
programs.push_back(opencl_utils_h);
auto utility_h = compileProgram(readFile("src/main/cpp/utility.h"),
{opencl_utils_h}, { "opencl_utils.h" });
programs.push_back(utility_h);
auto hashing_h = compileProgram(readFile("src/main/cpp/hashing.h"),
{ opencl_utils_h }, { "opencl_utils.h" });
programs.push_back(hashing_h);
auto hashing_c = compileProgram(readFile("src/main/cpp/hashing.c"),
{ opencl_utils_h, hashing_h }, { "opencl_utils.h", "hashing.h" });
programs.push_back(hashing_c);
Program hashing_lib;
try {
hashing_lib = linkProgram(programs, "-create-library");
logger->debug("Successfully linked {}", "hashing_lib");
libraries.push_back(hashing_lib);
} catch (const cl::Error &ex) {
logger->error("Link library {} error {}: {}", "hashing_lib", ex.err(), ex.what());
throw ex;
}
The hashing_lib
is then a successful linked program/library.
Now I try to link the noise_gen
library with the hashing_lib
.
programs.clear();
auto noise_gen_h = compileProgram(readFile("src/main/cpp/noise_gen.h"),
{ opencl_utils_h }, { "opencl_utils.h" });
programs.push_back(noise_gen_h);
auto noise_gen_c = compileProgram(readFile("src/main/cpp/noise_gen.c"),
{ noise_gen_h, opencl_utils_h, hashing_h, utility_h },
{ "noise_gen.h", "opencl_utils.h", "hashing.h", "utility.h", });
programs.push_back(noise_gen_c);
try {
Program noise_gen_lib = linkProgram(hashing_lib, noise_gen_c, "-create-library");
logger->debug("Successfully linked {}", "noise_gen_lib");
} catch (const cl::Error &ex) {
logger->error("Link library {} error {}: {}", "noise_gen_lib", ex.err(), ex.what());
cl_int buildErr = CL_SUCCESS;
auto buildInfo = noise_gen_c.getBuildInfo<CL_PROGRAM_BUILD_LOG>(&buildErr);
for (auto &pair : buildInfo) {
logger->error("Error link {} {}", "noise_gen_lib", std::string(pair.second));
}
throw ex;
}
This fails with error -17 CL_LINK_PROGRAM_FAILURE. Why? And how can I even get the CL_PROGRAM_BUILD_LOG
? The clLinkProgram
return a NULL program. Should I use the hashing_lib
or the noise_gen_c
program? Neither of them returns a log.
The source is here: https://github.com/devent/anl-opencl/blob/feature/Feature%234484/anlopencl/src/test/cpp/opencl_test.cpp#L127
The sources of the headers: https://github.com/devent/anl-opencl/tree/feature/Feature%234484/anlopencl/src/main/cpp
I’m using the C++ bindings for OpenCL but the functions calls are the same. The call is basically:
cl_program prog = ::clLinkProgram(
ctx(),
0,
NULL,
options, // "-create-library"
2,
programs, // hashing_lib, noise_gen_c
notifyFptr, // NULL
data, // NULL
&error_local);