hello,
im trying to develop a simple test program. theres loop in which I run one opencl kernel (kernel_1) and another kernel - kernel_2 (or group of kernels) is running in background using pthreads ( saying in background i mean to execute kernel_2 clEnqueueNDRangeKernel less frequent than kernel_1).
unfortunatelly there are errors cl_out_of resources thrown on both kernels when calling clEnqueueNDRangeKernel and clEnqueueReadBuffer.
is there a solution to use pthread and opencl (or tbb+opencl) together without problems ?
full source at:
code - http://pastebin.com/sGz0tkEt
kernel - http://pastebin.com/jQQ4FXE2
most important part below:
[codebox]
pthread_mutex_t region_mutex = PTHREAD_MUTEX_INITIALIZER;
int main(int argc, char *argv) {
void *moj(void*);
pthread_t moj_thread;
prepare_CL();
pthread_create(&moj_thread,NULL,moj,NULL);
for(int i=0; i < 100; i++) {
ciErr1 = clEnqueueNDRangeKernel(cqCommandQue, kernel_fold2, 1, NULL, &worksize1D_global, &worksize1D_local, 0, NULL, &ee);
if (ciErr1 != CL_SUCCESS) {printf("Error in clEnqueueNDRangeKernel !!!\n\n");}
clFinish(cqCommandQue);
}
read_CL();
for(int j=0;j<size;j++) {
cout << "thread: " << data_fold_out[j] << " main: " << data_fold_out2[j] << endl;
}
}
void moj(void) {
pthread_mutex_lock(®ion_mutex);
ciErr1 = clEnqueueNDRangeKernel(cqCommandQue, kernel_fold, 1, NULL, &worksize1D_global, &worksize1D_local, 0, NULL, NULL);
if (ciErr1 != CL_SUCCESS) {printf("Error in clEnqueueNDRangeKernel thread!!!\n\n"); pthread_exit(NULL);}
clFinish(cqCommandQue);
pthread_mutex_unlock(®ion_mutex);
pthread_exit(NULL);
}
[/codebox]