1 #ifndef VIENNACL_OCL_ENQUEUE_HPP_
2 #define VIENNACL_OCL_ENQUEUE_HPP_
26 #include <OpenCL/cl.h>
39 namespace device_specific
41 class custom_operation;
49 template<
typename KernelType>
52 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_KERNEL)
57 if (k.local_work_size(1) == 0)
59 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_KERNEL)
60 std::cout <<
"ViennaCL: Starting 1D-kernel '" << k.name() <<
"'..." << std::endl;
61 std::cout <<
"ViennaCL: Global work size: '" << k.global_work_size() <<
"'..." << std::endl;
62 std::cout <<
"ViennaCL: Local work size: '" << k.local_work_size() <<
"'..." << std::endl;
69 if (tmp_global == 1 && tmp_local == 1)
70 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_KERNEL)
71 err = clEnqueueTask(queue.
handle().
get(), k.handle().get(), 0, NULL, &event);
73 err = clEnqueueTask(queue.
handle().
get(), k.handle().get(), 0, NULL, NULL);
76 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_KERNEL)
77 err = clEnqueueNDRangeKernel(queue.
handle().
get(), k.handle().get(), 1, NULL, &tmp_global, &tmp_local, 0, NULL, &event);
79 err = clEnqueueNDRangeKernel(queue.
handle().
get(), k.handle().get(), 1, NULL, &tmp_global, &tmp_local, 0, NULL, NULL);
82 if (err != CL_SUCCESS)
84 std::cerr <<
"ViennaCL: FATAL ERROR: Kernel start failed for '" << k.name() <<
"'." << std::endl;
85 std::cerr <<
"ViennaCL: Smaller work sizes could not solve the problem. " << std::endl;
91 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_KERNEL)
92 std::cout <<
"ViennaCL: Starting 2D/3D-kernel '" << k.name() <<
"'..." << std::endl;
93 std::cout <<
"ViennaCL: Global work size: '" << k.global_work_size(0) <<
", " << k.global_work_size(1) <<
", " << k.global_work_size(2) <<
"'..." << std::endl;
94 std::cout <<
"ViennaCL: Local work size: '" << k.local_work_size(0) <<
", " << k.local_work_size(1) <<
", " << k.local_work_size(2) <<
"'..." << std::endl;
98 tmp_global[0] = k.global_work_size(0);
99 tmp_global[1] = k.global_work_size(1);
100 tmp_global[2] = k.global_work_size(2);
103 tmp_local[0] = k.local_work_size(0);
104 tmp_local[1] = k.local_work_size(1);
105 tmp_local[2] = k.local_work_size(2);
107 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_KERNEL)
108 cl_int err = clEnqueueNDRangeKernel(queue.
handle().
get(), k.handle().get(), (tmp_global[2] == 0) ? 2 : 3, NULL, tmp_global, tmp_local, 0, NULL, &event);
110 cl_int err = clEnqueueNDRangeKernel(queue.
handle().
get(), k.handle().get(), (tmp_global[2] == 0) ? 2 : 3, NULL, tmp_global, tmp_local, 0, NULL, NULL);
112 if (err != CL_SUCCESS)
115 std::cerr <<
"ViennaCL: FATAL ERROR: Kernel start failed for '" << k.name() <<
"'." << std::endl;
120 #if defined(VIENNACL_DEBUG_ALL) || defined(VIENNACL_DEBUG_KERNEL)
122 cl_int execution_status;
123 clGetEventInfo(event, CL_EVENT_COMMAND_EXECUTION_STATUS,
sizeof(cl_int), &execution_status, NULL);
124 std::cout <<
"ViennaCL: Kernel " << k.name() <<
" finished with status " << execution_status <<
"!" << std::endl;
130 template<
typename KernelType>
133 enqueue(k, k.context().get_queue());
141 inline void enqueue(viennacl::device_specific::custom_operation & op)
void finish() const
Waits until all kernels in the queue have finished their execution.
viennacl::ocl::context & current_context()
Convenience function for returning the current context.
A class representing a command queue.
viennacl::ocl::handle< cl_command_queue > const & handle() const
Implementations of command queue representations.
#define VIENNACL_ERR_CHECK(err)
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
const OCL_TYPE & get() const
viennacl::ocl::command_queue & get_queue()
Convenience function for getting the default queue for the currently active device in the active cont...
void enqueue_custom_op(viennacl::device_specific::custom_operation &op, viennacl::ocl::command_queue const &queue)
Represents an OpenCL context within ViennaCL.
Implementations of the OpenCL backend, where all contexts are stored in.
void enqueue(KernelType &k, viennacl::ocl::command_queue const &queue)
Enqueues a kernel in the provided queue.
Representation of an OpenCL kernel in ViennaCL.