0
votes

I want to run OpenCL application under Windows 10 using my GTX970 graphics card. But the following code doesn't work =(

#define __CL_ENABLE_EXCEPTIONS
#include <CL/cl.hpp>
#include <CL/cl.h>

#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip>

int main() {
    std::vector<cl::Platform> platforms;
    std::vector<cl::Device> devices;

    try
    {
        cl::Platform::get(&platforms);

        std::cout << platforms.size() << std::endl;

        for (cl_uint i = 0; i < platforms.size(); ++i)
        {
            platforms[i].getDevices(CL_DEVICE_TYPE_GPU, &devices);
        }

        std::cout << devices.size() << std::endl;

    }
    catch (cl::Error e) {
        std::cout << std::endl << e.what() << " : " << e.err() << std::endl;
    }

    return 0;
}

It gives me error code -1. I am using Visual Studio 2015 Community Edition to launch it with installed NVIDIA CUDA SDK v8.0 and configured paths, so compiler and linker knows about SDK.

Can someone please explain what's wrong with this snippet?

Thanks in advance!

EDIT: Can someone also explain me, why when i try to debug this code it falls when getting platform id, however, when i do not debug this code it prints that i have 2 platforms(my GPU card and integerated GPU)

1
Nvidia only supports OpenCL 1.1. I would strongly suggest getting an AMD card, or at least writing some OpenCL 2.0 and running it using either AMD's or Intel's (or both) CPU implementation. Also: be sure to look at the OpenCL examples included in the Nvidia SDK, often even simple initialization needs trickery. Final note: the C++ API was deprecated, so it's not a great idea to be using it. What the real problem is you're experiencing, no idea, so this is meant as a (long) comment. - rubenvb
Wow, but gpu caps viewer gives me info that my graphics card supports OpenCL 1.2. Does that matter? - EdZhavoronkov
@Ed might be 1.2, but all the good stuff (the stuff that makes OpenCL competitive with CUDA) is in 2.0. - rubenvb

1 Answers

0
votes

Probably your iGPU is Intel(I assume you did a combo of gtx970 + intel cpu for gaming) which also has some experimental opencl 2.1 platform support that could give error for an opencl 1.2 app at device picking or platform picking(I had a similar problem).

You should check returned error codes from opencl api commands. Those give better info about what happened.

For example, my system has two platforms for Intel, one being experimental 2.1 only for cpu and one being normal 1.2 for both gpu and cpu.

To check that, query platform version and check its parameter-returned 7th and 9th char values against 1 and 2 for 1.2 or 2 and 0 for 2.0. This should elliminate experimental 2.1 which gives 2 at 7th char and "1" at 9th char (where indexing starts at 0 ofcourse)

https://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clGetPlatformInfo.html

CL_PLATFORM_VERSION

Check for both numpad number keycodes and left hand side numbers keycodes.

Nvidia must have 1.2 support already.

If I'm right, you may query for cpu devices and have 2 from Intel and 1 from Nvidia(if it has any) in return.