I'm trying to load an external OpenCL kernel and the clCreateKernel
returns an error code: -46 CL_INVALID_KERNEL_NAME
. The file structure is the following:
.
├── CMakeLists.txt
└── src
├── cl.hpp
├── GameOfLife.cpp
└── kernels
└── programs.cl
This is my first CMake project, thus I'm not sure the following CMake is correct:
cmake_minimum_required(VERSION 3.5)
project(gpgpu_gameoflife)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lOpenCL")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/src/kernels)
# source: http://igorbarbosa.com/articles/how-to-use-opengl-freeglut-and-cmake/
#########################################################
# FIND GLUT
#########################################################
find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})
add_definitions(${GLUT_DEFINITIONS})
if(NOT GLUT_FOUND)
message(ERROR " GLUT not found!")
endif(NOT GLUT_FOUND)
#########################################################
# FIND OPENGL
#########################################################
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)
set(SOURCE_FILES
src/GameOfLife.cpp
src/kernels/programs.cl
)
add_executable(gpgpu_gameoflife ${SOURCE_FILES})
target_link_libraries(gpgpu_gameoflife ${OPENGL_LIBRARIES} ${GLUT_LIBRARY})
For the following function call I get an empty string as a result, thus I think the kernel file is not available to be read (the kernel itself is not empty).
std::string sourceCode = fileToString("kernels/programs.cl");
...
std::string fileToString(const std::string &path) {
std::ifstream file(path, std::ios::in | std::ios::binary);
if (file) {
std::ostringstream contents;
contents << file.rdbuf();
file.close();
return (contents.str());
}
return "";
}
Could you please tell me how to create an OpenCL application using CMake that loads an external kernel? Or is this not a good practice?
Thank you!