Commit 74b12ebd authored by Uldis Locans's avatar Uldis Locans

release old OpenCL kernel before creating a new one

parent 6d14df5b
......@@ -716,6 +716,11 @@ int OpenCLBase::ocl_copyData(cl_mem src_ptr, cl_mem dst_ptr, size_t size) {
*/
int OpenCLBase::ocl_createKernel(const char* kernel_name) {
cl_int ierr;
//release the old kernel
if (m_kernel != NULL)
clReleaseKernel(m_kernel);
//create a new kernel
m_kernel = clCreateKernel(m_program, kernel_name, &ierr);
if (ierr != CL_SUCCESS) {
DEBUG_MSG("Error creating kernel, OpenCL error: " << ierr);
......@@ -743,25 +748,31 @@ int OpenCLBase::ocl_setKernelArg(int idx, size_t size, const void *arg_value) {
optional: work_group_size - can specify how work items are divided in work groups,
if left NULL OpenCL implementation handles this part.
*/
int OpenCLBase::ocl_executeKernel(cl_uint ndim, const size_t *work_items, const size_t *work_group_size) {
cl_int ierr;
int OpenCLBase::ocl_executeKernel(cl_uint ndim, const size_t *work_items,
const size_t *work_group_size)
{
cl_int ierr;
cl_event tmp_event;
if (m_last_event == NULL) {
ierr = clEnqueueNDRangeKernel(m_command_queue, m_kernel, ndim, NULL, work_items, work_group_size,
0, NULL, &tmp_event);
ierr = clEnqueueNDRangeKernel(m_command_queue, m_kernel, ndim, NULL,
work_items, work_group_size,
0, NULL, &tmp_event);
} else {
ierr = clEnqueueNDRangeKernel(m_command_queue, m_kernel, ndim, NULL, work_items, work_group_size,
1, &m_last_event, &tmp_event);
ierr = clEnqueueNDRangeKernel(m_command_queue, m_kernel, ndim, NULL,
work_items, work_group_size,
1, &m_last_event, &tmp_event);
}
clFlush(m_command_queue);
if (ierr != CL_SUCCESS)
DEBUG_MSG("Error executing kernel, OpenCL error: " << ierr
<< " work items: " << *work_items << ", "
<< " work group: " << *work_group_size);
m_last_event = tmp_event;
m_events.push_back(m_last_event);
clReleaseEvent(tmp_event);
//m_last_event = tmp_event;
//m_events.push_back(m_last_event);
return ierr;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment