简体   繁体   中英

Running OpenCL under Windows 10

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM