Reputation: 29
I've been trying to learn OpenCl but every time i put this command my code breaks, Here is a simple code that i have isolated the error: clGetPlatformIDs couse the fallowing error:
Unhandled exception at 0x778d15ee in OpenCl-OpenGl.exe: 0xC0000005: Access violation.
then the program gives the option "Break" or "continue"
#pragma comment(lib, "OpenCL.lib")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CL/cl.h>
int main() {
cl_platform_id platform;
cl_int err;
err = clGetPlatformIDs(1, &platform, NULL);
return 0;
}
Upvotes: 1
Views: 2355
Reputation: 141
It may have the following reasons:
you have multiple OpenCL.dll on your system and by choice (or some VS setting, environment path) the executable is loading an old version. Check in the VS module window (Debug > Window > Modules) that the correct OpenCL.dll (C:\Windows\SysWow64 or C:\Windows\System32) is loaded.
Although the 3rd parameter in clGetPatformIDs is optional, I know that some older Intel OpenCL vendor libraries (intelopencl32.dll or intelopencl64.dll) do not check this and may try to write into that nullptr. I suggest to try to add a 3rd parameter that receives the platform count.
If both don't seem to solve the problem, post a stack dump from Visual Studio when/where the crash happens. Also, check the debug output window to see if it's a read or a write access violation. All windows can be found under menu Debug > Windows > Output. You also find Stack and Modules there.
Edit: I just made a test with the latest OpenCL.dll version and only provided an array with 1 entry, like you did. Still, the OpenCL.dll wrote into 3 elements meaning it wrote outside the allowed array boundary. Coincidentally, I have 3 platforms.
When you provide a single variable of type cl_platform_id this behavior will damage the stack and in this short program most likely damage the return address of clGetPlatformIds, hence your crash. I have to investigate this further. Try to use an cl_platform_id platforms[8] array meanwhile. It looks like a bug in my OpenCl.dll, version 2.01
Try this code:
cl_uint PlatformCount = 0;
cl_platform_id Platforms[8] = { 0 };
cl_int Status = clGetPlatformIDs(sizeof(Platforms) / sizeof(Platforms[0]), Platforms, &PlatformCount);
if (Status != CL_SUCCESS || PlatformCount == 0)
error(...)
Upvotes: 1