Closed Thanh-Binh closed 7 years ago
My guess is we have different OpenCL versions because I'm using the archlinux "nvidia-opencl" package for my GTX 1070, which doesn't include cl2.hpp. In compute-system.h try changing "#include <CL/cl.hpp>" to "#include <CL/cl2.hpp>". I think that should work.
I changed to use cl2.hpp but have compatibility error at the line calling "source"...,
Can you paste the error? I'd like to help you get it working if I can.
thanks. Here is my error:
./source/compute/compute-program.cpp: In member function ‘bool ComputeProgram::loadFromSourceFile(ComputeSystem&, const string&)’:
./source/compute/compute-program.cpp:24:99: error: no matching function for call to ‘std::vector<std::__cxx11::basic_string
I took a look at how Ogma wrote their ComputeProgram.cpp. Try this:
In compute-program.cpp, replace lines 20-26
std::string sourceCode(
std::istreambuf_iterator<char>(sourceFile),
(std::istreambuf_iterator<char>()));
cl::Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length() + 1));
_program = cl::Program(cs.getContext(), source);
with this:
std::string kernel = "";
while (!fromFile.eof() && fromFile.good()) {
std::string line;
std::getline(fromFile, line);
kernel += line + "\n";
}
_program = cl::Program(cs.getContext(), kernel);
I think this should solve the issue. Regardless, I will look into upgrading my compute-system and compute-program code to support cl2.hpp. Thanks for bringing this to my attention! I hope this fix works.
I did like too too, by learning from OgmaNeo... but got too many errors like: Please note that i have to insert -std=c++11 into CFLAGS too...
/usr/include/CL/cl2.hpp:6276: undefined reference to clBuildProgram' compute-program.o: In function
int cl::Program::getBuildInfo<std::cxx11::basic_string<char, std::char_traitsclGetProgramBuildInfo' compute-program.o: In function
int cl::Program::getInfo<std::vector<cl::Device, std::allocator
Does this work?
_program.build(std::vector<cl::Device>(1, cs.getDevice()))
If not I will try to get it working. Hopefully I can get to it over the next few days.
No. the same errors ...unfortunately!
Darn... ok, I'll work on it. Sorry for the inconvenience!
Thanks for your support ...
I modified my compute code to run cl2.hpp. Please let me know if it works on your machine!
No it does not help.
I have to include CFLAGS -std=c++11, even though I got many errors:
g++ -I./source/ -std=c++11 -c -g ./demos/ball/ball.cpp
g++ -I./source/ -std=c++11 -c -g ./source/cortex/stimulae.cpp
g++ -I./source/ -std=c++11 -c -g ./source/cortex/forest.cpp
g++ -I./source/ -std=c++11 -c -g ./source/cortex/area.cpp
g++ -std=c++11 -c -g ./source/compute/compute-system.cpp
g++ -std=c++11 -c -g ./source/compute/compute-program.cpp
g++ -lOpenCL -lGL -lsfml-system -lsfml-window -lsfml-graphics ball.o stimulae.o forest.o area.o compute-system.o compute-program.o -o execute.exe
ball.o: In function main': /home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:25: undefined reference to
sf::RenderWindow::RenderWindow()'
/home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:26: undefined reference to sf::String::String(char const*, std::locale const&)' /home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:26: undefined reference to
sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:26: undefined reference to sf::Window::create(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)' /home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:117: undefined reference to
sf::Window::pollEvent(sf::Event&)'
/home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:238: undefined reference to sf::Color::Black' /home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:238: undefined reference to
sf::RenderTarget::clear(sf::Color const&)'
/home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:239: undefined reference to sf::RenderStates::Default' /home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:239: undefined reference to
sf::RenderTarget::draw(sf::Drawable const&, sf::RenderStates const&)'
/home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:240: undefined reference to sf::Window::display()' /home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:25: undefined reference to
sf::RenderWindow::~RenderWindow()'
/home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:25: undefined reference to sf::RenderWindow::~RenderWindow()' ball.o: In function
cl::detail::ReferenceHandler<_cl_device_id>::release(_cl_device_id)':
/usr/include/CL/cl2.hpp:1438: undefined reference to clReleaseDevice' ball.o: In function
cl::detail::ReferenceHandler<_cl_context>::release(_cl_context)':
/usr/include/CL/cl2.hpp:1473: undefined reference to clReleaseContext' ball.o: In function
cl::detail::ReferenceHandler<_cl_command_queue>::release(_cl_command_queue)':
/usr/include/CL/cl2.hpp:1482: undefined reference to clReleaseCommandQueue' ball.o: In function
cl::detail::ReferenceHandler<_cl_mem>::retain(_cl_mem)':
/usr/include/CL/cl2.hpp:1489: undefined reference to clRetainMemObject' ball.o: In function
cl::detail::ReferenceHandler<_cl_mem>::release(_cl_mem)':
/usr/include/CL/cl2.hpp:1491: undefined reference to clReleaseMemObject' ball.o: In function
cl::detail::ReferenceHandler<_cl_program>::release(_cl_program)':
/usr/include/CL/cl2.hpp:1509: undefined reference to clReleaseProgram' ball.o: In function
cl::detail::ReferenceHandler<_cl_kernel>::release(_cl_kernel)':
/usr/include/CL/cl2.hpp:1518: undefined reference to clReleaseKernel' ball.o: In function
Render2D::Render2D(unsigned int, unsigned int)':
/home/binh/nupic/simple-cortex/./source/utils/render2d.h:17: undefined reference to sf::Color::Color()' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:17: undefined reference to
sf::Image::Image()'
/home/binh/nupic/simple-cortex/./source/utils/render2d.h:17: undefined reference to sf::Texture::Texture()' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:17: undefined reference to
sf::Sprite::Sprite()'
/home/binh/nupic/simple-cortex/./source/utils/render2d.h:23: undefined reference to sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:23: undefined reference to
sf::Image::create(unsigned int, unsigned int, sf::Color const&)'
/home/binh/nupic/simple-cortex/./source/utils/render2d.h:17: undefined reference to sf::Texture::~Texture()' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:17: undefined reference to
sf::Image::~Image()'
ball.o: In function Render2D::setPosition(unsigned int, unsigned int)': /home/binh/nupic/simple-cortex/./source/utils/render2d.h:73: undefined reference to
sf::Transformable::setPosition(float, float)'
ball.o: In function Render2D::setScale(float)': /home/binh/nupic/simple-cortex/./source/utils/render2d.h:78: undefined reference to
sf::Transformable::setScale(sf::Vector2sf::Transformable::Transformable(sf::Transformable const&)': /usr/include/SFML/Graphics/Transformable.hpp:41: undefined reference to
vtable for sf::Transformable'
ball.o: In function sf::Sprite::Sprite(sf::Sprite const&)': /usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference to
vtable for sf::Sprite'
/usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference to vtable for sf::Sprite' ball.o: In function
Render2D::getSprite()':
/home/binh/nupic/simple-cortex/./source/utils/render2d.h:93: undefined reference to sf::Image::setPixel(unsigned int, unsigned int, sf::Color const&)' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:97: undefined reference to
sf::Texture::loadFromImage(sf::Image const&, sf::Rectsf::Sprite::setTexture(sf::Texture const&, bool)' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:99: undefined reference to
sf::Texture::getSize() const'
/home/binh/nupic/simple-cortex/./source/utils/render2d.h:99: undefined reference to sf::Texture::getSize() const' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:99: undefined reference to
sf::Transformable::setOrigin(sf::Vector2Render2D::~Render2D()': /home/binh/nupic/simple-cortex/./source/utils/render2d.h:13: undefined reference to
sf::Texture::~Texture()'
/home/binh/nupic/simple-cortex/./source/utils/render2d.h:13: undefined reference to sf::Image::~Image()' ball.o: In function
sf::Sprite::~Sprite()':
/usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference to vtable for sf::Sprite' /usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference to
vtable for sf::Sprite'
/usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference to sf::Transformable::~Transformable()' stimulae.o: In function
cl::detail::ReferenceHandler<_cl_context>::retain(_cl_context)':
/usr/include/CL/cl2.hpp:1471: undefined reference to clRetainContext' stimulae.o: In function
cl::detail::ReferenceHandler<_cl_command_queue>::retain(_cl_command_queue)':
/usr/include/CL/cl2.hpp:1480: undefined reference to clRetainCommandQueue' stimulae.o: In function
cl::detail::ReferenceHandler<_cl_event>::release(_cl_event)':
/usr/include/CL/cl2.hpp:1527: undefined reference to clReleaseEvent' stimulae.o: In function
cl::Buffer::Buffer(cl::Context const&, unsigned long, unsigned long, void, int)':
/usr/include/CL/cl2.hpp:3620: undefined reference to clCreateBuffer' stimulae.o: In function
cl::CommandQueue::enqueueReadBuffer(cl::Buffer const&, unsigned int, unsigned long, unsigned long, void, std::vector<cl::Event, std::allocatorclEnqueueReadBuffer' stimulae.o: In function
cl::CommandQueue::enqueueWriteBuffer(cl::Buffer const&, unsigned int, unsigned long, unsigned long, void const, std::vector<cl::Event, std::allocatorclEnqueueWriteBuffer' stimulae.o: In function
int cl::CommandQueue::enqueueFillBufferclEnqueueFillBuffer' forest.o: In function
int cl::CommandQueue::enqueueFillBufferclEnqueueFillBuffer' area.o: In function
cl::detail::ReferenceHandler<_cl_program>::retain(_cl_program)':
/usr/include/CL/cl2.hpp:1507: undefined reference to clRetainProgram' area.o: In function
cl::Kernel::Kernel(cl::Program const&, char const, int)':
/usr/include/CL/cl2.hpp:6544: undefined reference to clCreateKernel' area.o: In function
cl::CommandQueue::enqueueNDRangeKernel(cl::Kernel const&, cl::NDRange const&, cl::NDRange const&, cl::NDRange const&, std::vector<cl::Event, std::allocatorclEnqueueNDRangeKernel' area.o: In function
cl::CommandQueue::finish() const':
/usr/include/CL/cl2.hpp:8067: undefined reference to clFinish' area.o: In function
std::enable_if<!std::is_pointerclSetKernelArg' area.o: In function
std::enable_if<!std::is_pointerclSetKernelArg' area.o: In function
std::enable_if<!std::is_pointerclSetKernelArg' compute-system.o: In function
cl::detail::ReferenceHandler<_cl_device_id>::retain(_cl_device_id)':
/usr/include/CL/cl2.hpp:1427: undefined reference to clRetainDevice' compute-system.o: In function
cl::Platform::getInfo(unsigned int, std::cxx11::basic_string<char, std::char_traitsclGetPlatformInfo' compute-system.o: In function
cl::Platform::getDevices(unsigned long, std::vector<cl::Device, std::allocatorclGetDeviceIDs' /usr/include/CL/cl2.hpp:2302: undefined reference to
clGetDeviceIDs'
compute-system.o: In function cl::Platform::get(std::vector<cl::Platform, std::allocator<cl::Platform> >*)': /usr/include/CL/cl2.hpp:2425: undefined reference to
clGetPlatformIDs'
/usr/include/CL/cl2.hpp:2431: undefined reference to clGetPlatformIDs' compute-system.o: In function
cl::Context::Context(cl::Device const&, long, void ()(char const, void const, unsigned long, void), void, int)':
/usr/include/CL/cl2.hpp:2639: undefined reference to clCreateContext' compute-system.o: In function
cl::CommandQueue::CommandQueue(cl::Context const&, cl::Device const&, unsigned long, int)':
/usr/include/CL/cl2.hpp:6841: undefined reference to clCreateCommandQueue' compute-system.o: In function
int cl::Device::getInfo<std::clGetDeviceInfo' compute-program.o: In function
cl::Program::Program(cl::Context const&, std::clCreateProgramWithSource' /usr/include/CL/cl2.hpp:5992: undefined reference to
clBuildProgram'
compute-program.o: In function `cl::Program::build(std::vector<cl::Device, std::allocatorclBuildProgram' compute-program.o: In function
int cl::Program::getBuildInfo<std::cxx11::basic_string<char, std::char_traitsclGetProgramBuildInfo' compute-program.o: In function
int cl::Program::getInfo<std::vector<cl::Device, std::allocator
It looks like it has something to do with the library linker. You mentioned you got Ogmaneo working? If so then you should have all the right libraries. Maybe in LDFLAGS before all the library names include "-L /usr/lib/", or wherever your OpenCL and SFML libraries are stored.
LDFLAGS= -L<Directory where the library resides> -l<library name>
I did so, but have the same errors. I have no idea! Which gcc version do you use?
Haha, oh the joys of computers...
my gcc version is 7.1.1
We use gcc 5
Aha, I found a solution .... In Makefile, please put LDLIBS at the end. i.e. $(CXX) $(OBJS_E) -o $(EXECUTE) $(LDLIBS)
I tried to test in ubuntu 16.04 lts, but have compiling error due to header file cl/ cl.hpp is not found. Normally, we use cl2.hpp like Ogma, but your code is not compatible...