diff --git a/CMakeLists.txt b/CMakeLists.txt index c2c316b..5260c9e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,12 +53,6 @@ if(POLICY CMP0053) cmake_policy(SET CMP0053 OLD) endif(POLICY CMP0053) - -include(CMakeCommon/FindOpenCL.cmake) -IF(NOT OpenCL_FOUND) - MESSAGE( STATUS "OpenCL is not there, will build without MTAPI OpenCL Plugin." ) -ENDIF() - # give the user the possibility, to append compiler flags set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CMAKE_CXX_FLAGS}") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CMAKE_C_FLAGS}") @@ -88,6 +82,7 @@ option(USE_EXCEPTIONS "Specify whether exceptions should be activated in C++" ON option(INSTALL_DOCS "Specify whether Doxygen docs should be installed" ON) option(WARNINGS_ARE_ERRORS "Specify whether warnings should be treated as errors" OFF) option(USE_AUTOMATIC_INITIALIZATION "Specify whether the MTAPI C++ interface, algorithms and dataflow should automatically intialize the MTAPI node if no explicit initialization is present" ON) +option(BUILD_OPENCL_PLUGIN "Specify whether the MTAPI OpenCL plugin should be built" OFF) ## LOCAL INSTALLATION OF SUBPROJECT BINARIES # @@ -146,7 +141,7 @@ set(EXPECTED_EMBB_TEST_EXECUTABLES "embb_algorithms_cpp_test" ) # if opencl is there, we also expect the mtapi opencl test to be generated -if(OpenCL_FOUND) +if(BUILD_OPENCL_PLUGIN STREQUAL ON) list(APPEND EXPECTED_EMBB_TEST_EXECUTABLES "embb_mtapi_opencl_c_test") endif() @@ -182,7 +177,7 @@ add_subdirectory(base_c) add_subdirectory(base_cpp) add_subdirectory(mtapi_c) add_subdirectory(mtapi_network_c) -if(OpenCL_FOUND) +if(BUILD_OPENCL_PLUGIN STREQUAL ON) add_subdirectory(mtapi_opencl_c) endif() add_subdirectory(tasks_cpp) diff --git a/doc/examples/CMakeLists.txt b/doc/examples/CMakeLists.txt index d68a8a3..fe33f32 100644 --- a/doc/examples/CMakeLists.txt +++ b/doc/examples/CMakeLists.txt @@ -21,7 +21,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../dataflow_cpp/include ) -if(OpenCL_FOUND) +if(BUILD_OPENCL_PLUGIN STREQUAL ON) # used in source code, to include opencl code add_definitions(-DEMBB_WITH_OPENCL) # add opencl includes diff --git a/mtapi_opencl_c/src/embb_mtapi_opencl.c b/mtapi_opencl_c/src/embb_mtapi_opencl.c index a4b7e19..a92cd14 100644 --- a/mtapi_opencl_c/src/embb_mtapi_opencl.c +++ b/mtapi_opencl_c/src/embb_mtapi_opencl.c @@ -259,7 +259,11 @@ void mtapi_opencl_plugin_initialize( embb_mtapi_opencl_plugin_t * plugin = &embb_mtapi_opencl_plugin; err = embb_mtapi_opencl_link_at_runtime(); - if (err != 0) { + if (err <= 0) { + // OpenCL not available, or wrong version + local_status = MTAPI_ERR_FUNC_NOT_IMPLEMENTED; + } else { + // all good, go ahead err = clGetPlatformIDs(1, &plugin->platform_id, NULL); if (CL_SUCCESS == err) { err = clGetDeviceIDs(plugin->platform_id, CL_DEVICE_TYPE_DEFAULT, diff --git a/mtapi_opencl_c/src/embb_mtapi_opencl_runtimelinker.c b/mtapi_opencl_c/src/embb_mtapi_opencl_runtimelinker.c index 9396a5b..e96f9d9 100644 --- a/mtapi_opencl_c/src/embb_mtapi_opencl_runtimelinker.c +++ b/mtapi_opencl_c/src/embb_mtapi_opencl_runtimelinker.c @@ -263,7 +263,7 @@ int embb_mtapi_opencl_link_at_runtime() { void * opencl_dll_handle = dlopen("libOpenCL.so", RTLD_LAZY); #endif if (opencl_dll_handle == 0) - return 0; + return -1; #ifdef EMBB_PLATFORM_COMPILER_MSVC #pragma warning(push) diff --git a/mtapi_opencl_c/test/embb_mtapi_opencl_test_linker.cc b/mtapi_opencl_c/test/embb_mtapi_opencl_test_linker.cc index 83a81e7..246c3a4 100644 --- a/mtapi_opencl_c/test/embb_mtapi_opencl_test_linker.cc +++ b/mtapi_opencl_c/test/embb_mtapi_opencl_test_linker.cc @@ -34,5 +34,7 @@ LinkerTest::LinkerTest() { } void LinkerTest::TestBasic() { - PT_EXPECT(embb_mtapi_opencl_link_at_runtime() != 0); + int result = embb_mtapi_opencl_link_at_runtime(); + bool success = result != 0; + PT_EXPECT(success); } diff --git a/mtapi_opencl_c/test/embb_mtapi_opencl_test_task.cc b/mtapi_opencl_c/test/embb_mtapi_opencl_test_task.cc index 61ddd31..0a922da 100644 --- a/mtapi_opencl_c/test/embb_mtapi_opencl_test_task.cc +++ b/mtapi_opencl_c/test/embb_mtapi_opencl_test_task.cc @@ -75,6 +75,10 @@ void TaskTest::TestBasic() { } mtapi_opencl_plugin_initialize(&status); + if (status == MTAPI_ERR_FUNC_NOT_IMPLEMENTED) { + // OpenCL unavailable + return; + } MTAPI_CHECK_STATUS(status); mtapi_initialize(