Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <CL/cl.h>
- #include <stdio.h>
- #include <assert.h>
- #include <unistd.h>
- int main( int argc, const char* argv[] ){
- cl_int err;
- unsigned int i;
- // Get all platform IDs
- cl_uint nr_of_platforms;
- err = clGetPlatformIDs(0, NULL, &nr_of_platforms);
- assert(err == CL_SUCCESS);
- fprintf(stderr,"EC: %i\n",err);
- if (nr_of_platforms == 0) {
- fprintf(stderr, "No OpenCL platforms found.\n");
- return;
- }
- cl_platform_id platforms[nr_of_platforms];
- err = clGetPlatformIDs(nr_of_platforms, platforms, NULL);
- fprintf(stderr,"EC: %i\n",err);
- assert(err == CL_SUCCESS);
- // Now select platform and device. We simply pick the first device that is of the requested type.
- cl_platform_id platform = NULL;
- cl_device_id device = NULL;
- for (i=0; i<nr_of_platforms; ++i) {
- cl_uint nr_of_devices;
- err = clGetDeviceIDs(
- platforms[i], (1 ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU),
- 0, NULL, &nr_of_devices);
- fprintf(stderr,"EC: %i\n",err);
- if (!err && nr_of_devices > 0) {
- platform = platforms[i];
- err = clGetDeviceIDs(platform, 1 ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1, &device, NULL);
- fprintf(stderr,"EC: %i\n",err);
- assert(err == CL_SUCCESS);
- break;
- }
- }
- // Check if we selected a device
- if (device == NULL) {
- fprintf(stderr, "No suitable OpenCL device found.\n");
- return;
- }
- cl_context context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
- fprintf(stderr,"EC: %i\n",err);
- assert(err == CL_SUCCESS);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement