Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencl function found deprecated by Visual Studio

I am getting started with opencl in VS using this tutorial:

https://opencl.codeplex.com/wikipage?title=OpenCL%20Tutorials%20-%201

I am having trouble with setting up the host program. This is the code so far:

const char* clewErrorString(cl_int error) {
    //stuff
}

int main(int argc, char **argv) {


    cl_int errcode_ret;
    cl_uint num_entries;


    // Platform

    cl_platform_id platforms;
    cl_uint num_platforms;
    num_entries = 1;

    cout << "Getting platform id..." << endl;
    errcode_ret = clGetPlatformIDs(num_entries, &platforms, &num_platforms);
    if (errcode_ret != CL_SUCCESS) {
        cout << "Error getting platform id: " << clewErrorString(errcode_ret) << endl;
        exit(errcode_ret);
    }
    cout << "Success!" << endl;


    // Device

    cl_device_type device_type = CL_DEVICE_TYPE_GPU;
    num_entries = 1;
    cl_device_id devices;
    cl_uint num_devices;

    cout << "Getting device id..." << endl;
    errcode_ret = clGetDeviceIDs(platforms, device_type, num_entries, &devices, &num_devices);
    if (errcode_ret != CL_SUCCESS) {
        cout << "Error getting device id: " << clewErrorString(errcode_ret) << endl;
        exit(errcode_ret);
    }
    cout << "Success!" << endl;


    // Context

    cl_context context;

    cout << "Creating context..." << endl;
    context = clCreateContext(0, num_devices, &devices, NULL, NULL, &errcode_ret);
    if (errcode_ret < 0) {
        cout << "Error creating context: " << clewErrorString(errcode_ret) << endl;
        exit(errcode_ret);
    }
    cout << "Success!" << endl;


    // Command-queue

    cl_command_queue queue;

    cout << "Creating command queue..." << endl;
    queue = clCreateCommandQueue(context, devices, 0, &errcode_ret);
    if (errcode_ret != CL_SUCCESS) {
        cout << "Error creating command queue: " << clewErrorString(errcode_ret) << endl;
        exit(errcode_ret);
    }
    cout << "Success!" << endl;


    return 0;
}

This doesn't compile, though: I get an error C4996: 'clCreateCommandQueue': was declared deprecated when i try to compile. I don't understand the whole setup process as of yet, so I don't know if I have messed up something or not. According to chronos, the function doesn't seem to be deprecated though: https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clCreateCommandQueue.html

If I remove the command queue part, the rest runs without problems. How can I make this work?

like image 318
PEC Avatar asked Feb 13 '15 13:02

PEC


1 Answers

The clCreateCommandQueue function was deprecated as of OpenCL 2.0, and replaced with clCreateCommandQueueWithProperties. If you are only targeting devices that support OpenCL 2.0 (some recent Intel and AMD processors at the time of writing), you can safely use this new function.

If you need your code to run on devices that don't yet support OpenCL 2.0, you can continue using the deprecated clCreateCommandQueue function by using the preprocessor macros that the OpenCL headers provide, e.g:

#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>
like image 197
jprice Avatar answered Oct 19 '22 03:10

jprice