ddigiorg / simple-cortex

A simple unsupervised on-line learning architecture
13 stars 5 forks source link

Compiling error #2

Closed Thanh-Binh closed 7 years ago

Thanh-Binh commented 7 years ago

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...

ddigiorg commented 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.

Thanh-Binh commented 7 years ago

I changed to use cl2.hpp but have compatibility error at the line calling "source"...,

ddigiorg commented 7 years ago

Can you paste the error? I'd like to help you get it working if I can.

Thanh-Binh commented 7 years ago

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, std::allocator<std::__cxx11::basic_string > >::vector(int, std::pair<const char*, long unsigned int>)’ Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length() + 1));

ddigiorg commented 7 years ago

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.

Thanh-Binh commented 7 years ago

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 functionint cl::Program::getBuildInfo<std::cxx11::basic_string<char, std::char_traits, std::allocator > >(cl::Device const&, unsigned int, std::cxx11::basic_string<char, std::char_traits, std::allocator >) const': /usr/include/CL/cl2.hpp:6327: undefined reference to clGetProgramBuildInfo' compute-program.o: In functionint cl::Program::getInfo<std::vector<cl::Device, std::allocator > >(unsigned int, std::vector<cl::Device, std::allocator >) const': /usr/include/CL/cl2.hpp:6305: undefined reference to `clGetProgramInfo'

ddigiorg commented 7 years ago

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.

Thanh-Binh commented 7 years ago

No. the same errors ...unfortunately!

ddigiorg commented 7 years ago

Darn... ok, I'll work on it. Sorry for the inconvenience!

Thanh-Binh commented 7 years ago

Thanks for your support ...

ddigiorg commented 7 years ago

I modified my compute code to run cl2.hpp. Please let me know if it works on your machine!

Thanh-Binh commented 7 years ago

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 tosf::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 tosf::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 tosf::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 tosf::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 tosf::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 tosf::RenderWindow::~RenderWindow()' /home/binh/nupic/simple-cortex/./demos/ball/ball.cpp:25: undefined reference to sf::RenderWindow::~RenderWindow()' ball.o: In functioncl::detail::ReferenceHandler<_cl_device_id>::release(_cl_device_id)': /usr/include/CL/cl2.hpp:1438: undefined reference to clReleaseDevice' ball.o: In functioncl::detail::ReferenceHandler<_cl_context>::release(_cl_context)': /usr/include/CL/cl2.hpp:1473: undefined reference to clReleaseContext' ball.o: In functioncl::detail::ReferenceHandler<_cl_command_queue>::release(_cl_command_queue)': /usr/include/CL/cl2.hpp:1482: undefined reference to clReleaseCommandQueue' ball.o: In functioncl::detail::ReferenceHandler<_cl_mem>::retain(_cl_mem)': /usr/include/CL/cl2.hpp:1489: undefined reference to clRetainMemObject' ball.o: In functioncl::detail::ReferenceHandler<_cl_mem>::release(_cl_mem)': /usr/include/CL/cl2.hpp:1491: undefined reference to clReleaseMemObject' ball.o: In functioncl::detail::ReferenceHandler<_cl_program>::release(_cl_program)': /usr/include/CL/cl2.hpp:1509: undefined reference to clReleaseProgram' ball.o: In functioncl::detail::ReferenceHandler<_cl_kernel>::release(_cl_kernel)': /usr/include/CL/cl2.hpp:1518: undefined reference to clReleaseKernel' ball.o: In functionRender2D::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 tosf::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 tosf::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 tosf::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 tosf::Image::~Image()' ball.o: In function Render2D::setPosition(unsigned int, unsigned int)': /home/binh/nupic/simple-cortex/./source/utils/render2d.h:73: undefined reference tosf::Transformable::setPosition(float, float)' ball.o: In function Render2D::setScale(float)': /home/binh/nupic/simple-cortex/./source/utils/render2d.h:78: undefined reference tosf::Transformable::setScale(sf::Vector2 const&)' ball.o: In function sf::Transformable::Transformable(sf::Transformable const&)': /usr/include/SFML/Graphics/Transformable.hpp:41: undefined reference tovtable for sf::Transformable' ball.o: In function sf::Sprite::Sprite(sf::Sprite const&)': /usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference tovtable for sf::Sprite' /usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference to vtable for sf::Sprite' ball.o: In functionRender2D::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 tosf::Texture::loadFromImage(sf::Image const&, sf::Rect const&)' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:98: undefined reference to sf::Sprite::setTexture(sf::Texture const&, bool)' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:99: undefined reference tosf::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 tosf::Transformable::setOrigin(sf::Vector2 const&)' ball.o: In function Render2D::~Render2D()': /home/binh/nupic/simple-cortex/./source/utils/render2d.h:13: undefined reference tosf::Texture::~Texture()' /home/binh/nupic/simple-cortex/./source/utils/render2d.h:13: undefined reference to sf::Image::~Image()' ball.o: In functionsf::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 tovtable for sf::Sprite' /usr/include/SFML/Graphics/Sprite.hpp:47: undefined reference to sf::Transformable::~Transformable()' stimulae.o: In functioncl::detail::ReferenceHandler<_cl_context>::retain(_cl_context)': /usr/include/CL/cl2.hpp:1471: undefined reference to clRetainContext' stimulae.o: In functioncl::detail::ReferenceHandler<_cl_command_queue>::retain(_cl_command_queue)': /usr/include/CL/cl2.hpp:1480: undefined reference to clRetainCommandQueue' stimulae.o: In functioncl::detail::ReferenceHandler<_cl_event>::release(_cl_event)': /usr/include/CL/cl2.hpp:1527: undefined reference to clReleaseEvent' stimulae.o: In functioncl::Buffer::Buffer(cl::Context const&, unsigned long, unsigned long, void, int)': /usr/include/CL/cl2.hpp:3620: undefined reference to clCreateBuffer' stimulae.o: In functioncl::CommandQueue::enqueueReadBuffer(cl::Buffer const&, unsigned int, unsigned long, unsigned long, void, std::vector<cl::Event, std::allocator > const, cl::Event) const': /usr/include/CL/cl2.hpp:6990: undefined reference to clEnqueueReadBuffer' stimulae.o: In functioncl::CommandQueue::enqueueWriteBuffer(cl::Buffer const&, unsigned int, unsigned long, unsigned long, void const, std::vector<cl::Event, std::allocator > const, cl::Event) const': /usr/include/CL/cl2.hpp:7015: undefined reference to clEnqueueWriteBuffer' stimulae.o: In functionint cl::CommandQueue::enqueueFillBuffer(cl::Buffer const&, unsigned char, unsigned long, unsigned long, std::vector<cl::Event, std::allocator > const, cl::Event) const': /usr/include/CL/cl2.hpp:7191: undefined reference to clEnqueueFillBuffer' forest.o: In functionint cl::CommandQueue::enqueueFillBuffer(cl::Buffer const&, unsigned int, unsigned long, unsigned long, std::vector<cl::Event, std::allocator > const, cl::Event) const': /usr/include/CL/cl2.hpp:7191: undefined reference to clEnqueueFillBuffer' area.o: In functioncl::detail::ReferenceHandler<_cl_program>::retain(_cl_program)': /usr/include/CL/cl2.hpp:1507: undefined reference to clRetainProgram' area.o: In functioncl::Kernel::Kernel(cl::Program const&, char const, int)': /usr/include/CL/cl2.hpp:6544: undefined reference to clCreateKernel' area.o: In functioncl::CommandQueue::enqueueNDRangeKernel(cl::Kernel const&, cl::NDRange const&, cl::NDRange const&, cl::NDRange const&, std::vector<cl::Event, std::allocator > const, cl::Event) const': /usr/include/CL/cl2.hpp:7820: undefined reference to clEnqueueNDRangeKernel' area.o: In functioncl::CommandQueue::finish() const': /usr/include/CL/cl2.hpp:8067: undefined reference to clFinish' area.o: In functionstd::enable_if<!std::is_pointer::value, int>::type cl::Kernel::setArg(unsigned int, cl::Buffer const&)': /usr/include/CL/cl2.hpp:5808: undefined reference to clSetKernelArg' area.o: In functionstd::enable_if<!std::is_pointer::value, int>::type cl::Kernel::setArg(unsigned int, unsigned int const&)': /usr/include/CL/cl2.hpp:5808: undefined reference to clSetKernelArg' area.o: In functionstd::enable_if<!std::is_pointer::value, int>::type cl::Kernel::setArg(unsigned int, unsigned char const&)': /usr/include/CL/cl2.hpp:5808: undefined reference to clSetKernelArg' compute-system.o: In functioncl::detail::ReferenceHandler<_cl_device_id>::retain(_cl_device_id)': /usr/include/CL/cl2.hpp:1427: undefined reference to clRetainDevice' compute-system.o: In functioncl::Platform::getInfo(unsigned int, std::cxx11::basic_string<char, std::char_traits, std::allocator >) const': /usr/include/CL/cl2.hpp:2265: undefined reference to clGetPlatformInfo' compute-system.o: In functioncl::Platform::getDevices(unsigned long, std::vector<cl::Device, std::allocator >) const': /usr/include/CL/cl2.hpp:2296: undefined reference to clGetDeviceIDs' /usr/include/CL/cl2.hpp:2302: undefined reference toclGetDeviceIDs' compute-system.o: In function cl::Platform::get(std::vector<cl::Platform, std::allocator<cl::Platform> >*)': /usr/include/CL/cl2.hpp:2425: undefined reference toclGetPlatformIDs' /usr/include/CL/cl2.hpp:2431: undefined reference to clGetPlatformIDs' compute-system.o: In functioncl::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 functioncl::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 functionint cl::Device::getInfo<std::cxx11::basic_string<char, std::char_traits, std::allocator > >(unsigned int, std::cxx11::basic_string<char, std::char_traits, std::allocator >*) const': /usr/include/CL/cl2.hpp:2026: undefined reference to clGetDeviceInfo' compute-program.o: In functioncl::Program::Program(cl::Context const&, std::cxx11::basic_string<char, std::char_traits, std::allocator > const&, bool, int)': /usr/include/CL/cl2.hpp:5986: undefined reference to clCreateProgramWithSource' /usr/include/CL/cl2.hpp:5992: undefined reference toclBuildProgram' compute-program.o: In function `cl::Program::build(std::vector<cl::Device, std::allocator > const&, char const, void ()(_cl_program, void), void) const': /usr/include/CL/cl2.hpp:6260: undefined reference to clBuildProgram' compute-program.o: In functionint cl::Program::getBuildInfo<std::cxx11::basic_string<char, std::char_traits, std::allocator > >(cl::Device const&, unsigned int, std::cxx11::basic_string<char, std::char_traits, std::allocator >) const': /usr/include/CL/cl2.hpp:6327: undefined reference to clGetProgramBuildInfo' compute-program.o: In functionint cl::Program::getInfo<std::vector<cl::Device, std::allocator > >(unsigned int, std::vector<cl::Device, std::allocator >) const': /usr/include/CL/cl2.hpp:6305: undefined reference to `clGetProgramInfo' collect2: error: ld returned 1 exit status Makefile:16: recipe for target 'execute.exe' failed

ddigiorg commented 7 years ago

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>
Thanh-Binh commented 7 years ago

I did so, but have the same errors. I have no idea! Which gcc version do you use?

ddigiorg commented 7 years ago

Haha, oh the joys of computers...

my gcc version is 7.1.1

Thanh-Binh commented 7 years ago

We use gcc 5

Thanh-Binh commented 7 years ago

Aha, I found a solution .... In Makefile, please put LDLIBS at the end. i.e. $(CXX) $(OBJS_E) -o $(EXECUTE) $(LDLIBS)