This commit is contained in:
Mario Hüttel 2018-04-23 09:09:14 +02:00
parent d59e3d4ee2
commit 016cd00613
3 changed files with 54 additions and 44 deletions

View File

@ -9,7 +9,7 @@ message(STATUS "OpenCL includes: ${OPENCL_INCLUDE_DIRS}")
message(STATUS "OpenCL CXX includes: ${OPENCL_HAS_CPP_BINDINGS}") message(STATUS "OpenCL CXX includes: ${OPENCL_HAS_CPP_BINDINGS}")
message(STATUS "OpenCL libraries: ${OPENCL_LIBRARIES}") 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}) target_link_libraries(${PROJECT_NAME} ${OPENCL_LIBRARIES})
include_directories(${PROJECT_NAME} ${OPENCL_INCLUDE_DIR}) include_directories(${PROJECT_NAME} ${OPENCL_INCLUDE_DIR})

53
main.c Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <CL/cl.h>
#include <stdlib.h>
#include <stdint.h>
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;
}

View File

@ -1,43 +0,0 @@
#include <iostream>
#include <vector>
#include <CL/cl.h>
int main()
{
cl_int error;
cl_uint platformIdCount = 0;
clGetPlatformIDs (0, nullptr, &platformIdCount);
std::vector<cl_platform_id> 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<cl_device_id> deviceIds (deviceIdCount);
clGetDeviceIDs (platformIds [0], CL_DEVICE_TYPE_ALL, deviceIdCount,
deviceIds.data (), nullptr);
const cl_context_properties contextProperties [] =
{
CL_CONTEXT_PLATFORM,
reinterpret_cast<cl_context_properties> (platformIds [0]),
0, 0
};
cl_context context = clCreateContext (
contextProperties, deviceIdCount,
deviceIds.data (), nullptr,
nullptr, &error);
return 0;
}