Reputation: 51
If I want to format this code into OpenCL what should I consider when doing so? Like what buffers should I be using? And if I want to know how much data the kernel use doing this, how am I able to calculate it?
int A[100000]
int B[100000]
for(int i=1; i<100000 -1); i++) {
B[i] = A[i-1] + A[i+1] - 2*A[i]
}
All help is appreciated
Upvotes: 1
Views: 155
Reputation: 673
You need two buffers for A and B. For example:
cl_int error = CL_SUCCESS;
cl_mem A_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(int)*100000, A, &error);
cl_mem B_buffer = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, sizeof(int)*100000, B, &error);
If you want each kernel to work with only one element of B, then your global work size would equal 99999.
Your kernel might look somehow like this (in case one thread works with one value, you might not need such parallelism, it's just an example):
kernel void your_kernel(global int* A, global int* B) {
int i = get_global_id(0);
B[i] = A[i-1] + A[i+1] - 2*A[i];
}
Upvotes: 2