Sto cercando di utilizzare l'OpenCL C++ API wrapper per il seguente programma:OpenCL 1.2 C++ wrapper - undefined reference to clReleaseDevice
#define __CL_ENABLE_EXCEPTIONS
#include <CL/cl.hpp>
#include <cstdio>
#include <cstdlib>
#include <iostream>
const char helloStr [] = "__kernel void "
"hello(void) "
"{ "
" "
"} ";
int
main(void)
{
cl_int err = CL_SUCCESS;
try {
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (platforms.size() == 0) {
std::cout << "Platform size 0\n";
return -1;
}
cl_context_properties properties[] =
{ CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
cl::Context context(CL_DEVICE_TYPE_CPU, properties);
std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
cl::Program::Sources source(1,
std::make_pair(helloStr,strlen(helloStr)));
cl::Program program_ = cl::Program(context, source);
program_.build(devices);
cl::Kernel kernel(program_, "hello", &err);
cl::Event event;
cl::CommandQueue queue(context, devices[0], 0, &err);
queue.enqueueNDRangeKernel(
kernel,
cl::NullRange,
cl::NDRange(4,4),
cl::NullRange,
NULL,
&event);
event.wait();
}
catch (cl::Error err) {
std::cerr
<< "ERROR: "
<< err.what()
<< "("
<< err.err()
<< ")"
<< std::endl;
}
return EXIT_SUCCESS;
}
io uso lo stesso file del kernel da quel post sul blog, in ogni modo che non è il problema dato che non riesco a superare la compilazione.
Sto compilando il programma con il seguente comando:
g++ example.cpp -o example -l OpenCL
e ottengo il seguente messaggio di errore: roba
/tmp/ccbUf7dB.o: In function `cl::detail::ReferenceHandler<_cl_device_id*>::release(_cl_device_id*)':
example.cpp:(.text._ZN2cl6detail16ReferenceHandlerIP13_cl_device_idE7releaseES3_[_ZN2cl6detail16ReferenceHandlerIP13_cl_device_idE7releaseES3_]+0x14): undefined reference to `clReleaseDevice'
collect2: error: ld returned 1 exit status
ho letto su clReleaseDevice non funziona per dispositivi legacy (vedere ad esempio this question), ma la mia scheda grafica è piuttosto recente (NVidia GTX 660 Ti, supporta OpenCL 1.2). Dove posso andare da lì?
L'ho eseguito su Ubuntu 13.04 x64 con nvidia-opencl-dev e opencl-headers installati dai repository di ubuntu.
Prova ad aggiungere '-DCL_USE_DEPRECATED_OPENCL_1_1_APIS' al tuo makefile. – Thomas
Non cambia nulla. Ho sfogliato il file CL/cl.hpp e il codice in bundle con questa definizione non sembra essere correlato a questa chiamata di funzione. – levesque
Cosa succede se metti '#define CL_USE_DEPRECATED_OPENCL_1_1_APIS; #include "CL/cl.h"; #undef CL_VERSION_1_2; #define __CL_ENABLE_EXCEPTIONS; #include "cl-1.2.hpp" 'Funziona? L'ho provato su Amazon AWS nvidia, con ubuntu 14.04, e sembra funzionare bene? –