VM_AI
VM_AI

Reputation: 1132

OpenCL EXC_BAD_ACCESS (code=1, address=0xc00)

I have created a basic OpenCL code that should do matrix multiplication. I am unsure what mistake I may have committed, but I am getting this error:

Thread 1: EXC_BAD_ACCESS (code=1, address=0xc00)

After a bit of research it appears the error is actually thrown when a program is trying to access a memory location, which is either already released or points to a location that is not expected to. However I do not understand where this could be the case in my code which makes a call to clCreateProgramWithSource.

FYI, I simply tried changing the third parameter to NULL at which case it actually works, but fails when correct string value that corresponds to kernel string is passed.

(I use Xcode 9.2)

Could someone please shed some light on this.

Thanks in advance.

Upvotes: 0

Views: 153

Answers (1)

Andrew Savonichev
Andrew Savonichev

Reputation: 699

In the code you have mentioned:

string sourceCode = readFile("/Users/rajkumar/Documents/OpenCL/Kernels/matmul.cl");

// Create a program from the kernel source
size_t len = (size_t)sourceCode.length();
size_t * len_ptr = &(len);
cl_program program = clCreateProgramWithSource(opencl->context,
                                               1,(const char**)&sourceCode,
                                               NULL,&clStatus);

You cannot cast std::string* to a const char**. You should call sourceCode.c_str(), then store it to a temporary variable of type const char*, and pass a pointer to this variable into clCreateProgramWithSource().

Upvotes: 2

Related Questions