From 016cd00613682afbe849e70fa41e37c306d44a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Mon, 23 Apr 2018 09:09:14 +0200 Subject: [PATCH] fix #1 --- CMakeLists.txt | 2 +- main.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 43 ---------------------------------------- 3 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 main.c delete mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c2032e..7b80ecc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ message(STATUS "OpenCL includes: ${OPENCL_INCLUDE_DIRS}") message(STATUS "OpenCL CXX includes: ${OPENCL_HAS_CPP_BINDINGS}") message(STATUS "OpenCL libraries: ${OPENCL_LIBRARIES}") -add_executable(${PROJECT_NAME} "main.cpp") +add_executable(${PROJECT_NAME} "main.c") target_link_libraries(${PROJECT_NAME} ${OPENCL_LIBRARIES}) include_directories(${PROJECT_NAME} ${OPENCL_INCLUDE_DIR}) diff --git a/main.c b/main.c new file mode 100644 index 0000000..f02d7b7 --- /dev/null +++ b/main.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +int main() +{ + + cl_int error; + cl_platform_id *platform_ids = NULL; + cl_device_id *device_ids = NULL; + cl_uint platform_id_count = 0; + cl_uint device_id_count = 0; + cl_context_properties context_properties[4]; + cl_context context; + + clGetPlatformIDs (0, NULL, &platform_id_count); + if (platform_id_count == 0) + return -1; + + platform_ids = (cl_platform_id*) malloc(platform_id_count * + sizeof(cl_platform_id)); + if (platform_ids == NULL) + return -1; + + clGetPlatformIDs (platform_id_count, platform_ids, NULL); + + printf("Platforms available: %u\n", (unsigned int)platform_id_count); + + + clGetDeviceIDs (platform_ids[0], CL_DEVICE_TYPE_ALL, 0, NULL, + &device_id_count); + printf("Device in Platform 0 count: %u\n", (unsigned int)device_id_count); + + if (device_id_count == 0) + return -1; + + device_ids = (cl_device_id*) malloc(sizeof(cl_device_id)*device_id_count); + + clGetDeviceIDs (platform_ids[0], CL_DEVICE_TYPE_ALL, device_id_count, + device_ids, NULL); + + context_properties[0] = CL_CONTEXT_PLATFORM; + context_properties[1] = (cl_context_properties)platform_ids[0]; + context_properties[2] = context_properties[3] = 0; + + + context = clCreateContext (context_properties, device_id_count, + device_ids, NULL, + NULL, &error); + + return 0; +} diff --git a/main.cpp b/main.cpp deleted file mode 100644 index c8a12f3..0000000 --- a/main.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -int main() -{ - - - cl_int error; - - cl_uint platformIdCount = 0; - clGetPlatformIDs (0, nullptr, &platformIdCount); - - std::vector platformIds (platformIdCount); - clGetPlatformIDs (platformIdCount, platformIds.data(), nullptr); - - std::cout << "Platform count: " << platformIdCount << std::endl; - - cl_uint deviceIdCount = 0; - clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_ALL, 0, nullptr, - &deviceIdCount); - std::cout << "Device in Platform 0 count: " << deviceIdCount << std::endl; - - std::vector deviceIds (deviceIdCount); - clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_ALL, deviceIdCount, - deviceIds.data (), nullptr); - - - const cl_context_properties contextProperties [] = - { - CL_CONTEXT_PLATFORM, - reinterpret_cast (platformIds [0]), - 0, 0 - }; - - cl_context context = clCreateContext ( - contextProperties, deviceIdCount, - deviceIds.data (), nullptr, - nullptr, &error); - - - return 0; -}