21

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?

PEC
  • 593
  • 1
  • 5
  • 16

1 Answers1

44

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>
jprice
  • 9,755
  • 1
  • 28
  • 32
  • 4
    You don't *have* to use the function. You will get the warning, because we won't be adding new features to functions like that in the future, but it is perfectly valid to use and will continue to be supported in runtimes for the foreseeable future. Rather than telling VC++ to ignore deprecation warnings, you can safely disable them in the OpenCL headers directly using the CL_USE_DEPRECATED_OPENCL_1_0_APIS (1_1, 1_2...) flags. – Lee Feb 13 '15 at 17:19
  • @Lee Thanks, I had forgotten about those handy macros. I've updated my answer accordingly. – jprice Feb 13 '15 at 17:36