sav
sav

Reputation: 2152

Cant get my graphics card device in opencl

I am trying to write a simple opencl program and I'm not able to get my Graphics card it seems.

#include "stdafx.h"
#include <stdio.h>
#include "CL/cl.h"

#define DATA_SIZE 10

const char *KernelSource = 
"__kernel void hello(__global float * input, __global float *output)\n"\
"{\n"\
" size_t id = get_global_id(0);\n"\
" output[id] = input[id] * input[id]; \n"\
"}\n"\
"\n";
int main()
{
    cl_context context;
    cl_context_properties properties[3];
    cl_kernel kernel;
    cl_command_queue command_queue;
    cl_program program;
    cl_int err;
    cl_uint num_of_platforms=0;
    cl_platform_id platform_id;
    cl_platform_id * platform_ids;
    cl_device_id device_id;
    cl_uint num_of_devices=0;
    cl_mem input, output;
    size_t global;

    float inputData[DATA_SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    float results[DATA_SIZE] = {0};

    int i;

    if (clGetPlatformIDs(1, &platform_id, &num_of_platforms) != CL_SUCCESS)
    {
        printf("Unable to get platform_id\n");
        return 1;
    }

    if (clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, &num_of_devices) != CL_SUCCESS)
    {
        printf("Unable to get device_id\n");
        return 1;
    }

    return 0;
}

The program prints Unable to get device_id

When I put in a break point and inspect num_of_platforms. It seems that I have 3 platforms.

I have an intel CPU and an NVIDIA GPU (quadro K4000)

However, it says I have 0 devices of type CL_DEVICE_TYPE_GPU

I can see in my device manager I have my GPU visible

K4000

I think this might be related to another problem I'm having using cloo on the same PC.

It also appears that the only listed opencl device is my CPU

ClooCPU

The Opencl version supported by my CPU (1.2) is actuall later than the GPU (1.1).

I'm not sure about how to go about debugging this any further ...

Upvotes: 1

Views: 2407

Answers (1)

DarkZeros
DarkZeros

Reputation: 8410

You are trying to get GPU device from the first platform. How do you know it has to be on the first platform? You should try all the platforms.

if (clGetPlatformIDs(0, NULL, &num_of_platforms) != CL_SUCCESS)
{
    printf("Unable to get platform_id\n");
    return 1;
}
cl_platform_id *platform_ids = new cl_platform_id[num_of_platforms];
if (clGetPlatformIDs(num_of_platforms, &platform_ids, NULL) != CL_SUCCESS)
{
    printf("Unable to get platform_id\n");
    return 1;
}
bool found = false;
for(int i=0; i<num_of_platforms; i++)
    if(clGetDeviceIDs(&platform_id[i], CL_DEVICE_TYPE_GPU, 1, &device_id, &num_of_devices) == CL_SUCCESS){
         found = true;
         break;
    }
if(!found){
    printf("Unable to get device_id\n");
    return 1;
}

Upvotes: 6

Related Questions