Clover Git
OpenCL 1.1 software implementation

api_enqueue.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Denis Steckelmacher <steckdenis@yahoo.fr>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *     * Redistributions of source code must retain the above copyright
00008  *       notice, this list of conditions and the following disclaimer.
00009  *     * Redistributions in binary form must reproduce the above copyright
00010  *       notice, this list of conditions and the following disclaimer in the
00011  *       documentation and/or other materials provided with the distribution.
00012  *     * Neither the name of the copyright holder nor the
00013  *       names of its contributors may be used to endorse or promote products
00014  *       derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00020  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  */
00027 
00033 #include <CL/cl.h>
00034 
00035 #include <core/events.h>
00036 #include <core/memobject.h>
00037 
00038 #include <cstdlib>
00039 
00040 static inline cl_int queueEvent(Coal::CommandQueue *queue,
00041                                 Coal::Event *command,
00042                                 cl_event *event,
00043                                 cl_bool blocking)
00044 {
00045     cl_int rs;
00046 
00047     rs = queue->queueEvent(command);
00048 
00049     if (rs != CL_SUCCESS)
00050     {
00051         delete command;
00052         return rs;
00053     }
00054 
00055     if (event)
00056     {
00057         *event = (cl_event)command;
00058         command->reference();
00059     }
00060 
00061     if (blocking)
00062     {
00063         rs = clWaitForEvents(1, (cl_event *)&command);
00064 
00065         if (rs != CL_SUCCESS)
00066         {
00067             delete command;
00068             return rs;
00069         }
00070     }
00071 
00072     return CL_SUCCESS;
00073 }
00074 
00075 // Enqueued Commands APIs
00076 cl_int
00077 clEnqueueReadBuffer(cl_command_queue    command_queue,
00078                     cl_mem              buffer,
00079                     cl_bool             blocking_read,
00080                     size_t              offset,
00081                     size_t              cb,
00082                     void *              ptr,
00083                     cl_uint             num_events_in_wait_list,
00084                     const cl_event *    event_wait_list,
00085                     cl_event *          event)
00086 {
00087     cl_int rs = CL_SUCCESS;
00088 
00089     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00090         return CL_INVALID_COMMAND_QUEUE;
00091 
00092     Coal::ReadBufferEvent *command = new Coal::ReadBufferEvent(
00093         (Coal::CommandQueue *)command_queue,
00094         (Coal::MemObject *)buffer,
00095         offset, cb, ptr,
00096         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00097     );
00098 
00099     if (rs != CL_SUCCESS)
00100     {
00101         delete command;
00102         return rs;
00103     }
00104 
00105     return queueEvent(command_queue, command, event, blocking_read);
00106 }
00107 
00108 cl_int
00109 clEnqueueWriteBuffer(cl_command_queue   command_queue,
00110                      cl_mem             buffer,
00111                      cl_bool            blocking_write,
00112                      size_t             offset,
00113                      size_t             cb,
00114                      const void *       ptr,
00115                      cl_uint            num_events_in_wait_list,
00116                      const cl_event *   event_wait_list,
00117                      cl_event *         event)
00118 {
00119     cl_int rs = CL_SUCCESS;
00120 
00121     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00122         return CL_INVALID_COMMAND_QUEUE;
00123 
00124     Coal::WriteBufferEvent *command = new Coal::WriteBufferEvent(
00125         (Coal::CommandQueue *)command_queue,
00126         (Coal::MemObject *)buffer,
00127         offset, cb, (void *)ptr,
00128         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00129     );
00130 
00131     if (rs != CL_SUCCESS)
00132     {
00133         delete command;
00134         return rs;
00135     }
00136 
00137     return queueEvent(command_queue, command, event, blocking_write);
00138 }
00139 
00140 cl_int
00141 clEnqueueReadBufferRect(cl_command_queue    command_queue,
00142                         cl_mem              buffer,
00143                         cl_bool             blocking_read,
00144                         const size_t *      buffer_origin,
00145                         const size_t *      host_origin,
00146                         const size_t *      region,
00147                         size_t              buffer_row_pitch,
00148                         size_t              buffer_slice_pitch,
00149                         size_t              host_row_pitch,
00150                         size_t              host_slice_pitch,
00151                         void *              ptr,
00152                         cl_uint             num_events_in_wait_list,
00153                         const cl_event *    event_wait_list,
00154                         cl_event *          event)
00155 {
00156     cl_int rs = CL_SUCCESS;
00157 
00158     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00159         return CL_INVALID_COMMAND_QUEUE;
00160 
00161     Coal::ReadBufferRectEvent *command = new Coal::ReadBufferRectEvent(
00162         (Coal::CommandQueue *)command_queue,
00163         (Coal::MemObject *)buffer,
00164         buffer_origin, host_origin, region, buffer_row_pitch, buffer_slice_pitch,
00165         host_row_pitch, host_slice_pitch, ptr,
00166         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00167     );
00168 
00169     if (rs != CL_SUCCESS)
00170     {
00171         delete command;
00172         return rs;
00173     }
00174 
00175     return queueEvent(command_queue, command, event, blocking_read);
00176 }
00177 
00178 cl_int
00179 clEnqueueWriteBufferRect(cl_command_queue    command_queue,
00180                         cl_mem              buffer,
00181                         cl_bool             blocking_write,
00182                         const size_t *      buffer_origin,
00183                         const size_t *      host_origin,
00184                         const size_t *      region,
00185                         size_t              buffer_row_pitch,
00186                         size_t              buffer_slice_pitch,
00187                         size_t              host_row_pitch,
00188                         size_t              host_slice_pitch,
00189                         const void *        ptr,
00190                         cl_uint             num_events_in_wait_list,
00191                         const cl_event *    event_wait_list,
00192                         cl_event *          event)
00193 {
00194     cl_int rs = CL_SUCCESS;
00195 
00196     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00197         return CL_INVALID_COMMAND_QUEUE;
00198 
00199     Coal::WriteBufferRectEvent *command = new Coal::WriteBufferRectEvent(
00200         (Coal::CommandQueue *)command_queue,
00201         (Coal::MemObject *)buffer,
00202         buffer_origin, host_origin, region, buffer_row_pitch, buffer_slice_pitch,
00203         host_row_pitch, host_slice_pitch, (void *)ptr,
00204         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00205     );
00206 
00207     if (rs != CL_SUCCESS)
00208     {
00209         delete command;
00210         return rs;
00211     }
00212 
00213     return queueEvent(command_queue, command, event, blocking_write);
00214 }
00215 
00216 cl_int
00217 clEnqueueCopyBufferRect(cl_command_queue    command_queue,
00218                         cl_mem              src_buffer,
00219                         cl_mem              dst_buffer,
00220                         const size_t *      src_origin,
00221                         const size_t *      dst_origin,
00222                         const size_t *      region,
00223                         size_t              src_row_pitch,
00224                         size_t              src_slice_pitch,
00225                         size_t              dst_row_pitch,
00226                         size_t              dst_slice_pitch,
00227                         cl_uint             num_events_in_wait_list,
00228                         const cl_event *    event_wait_list,
00229                         cl_event *          event)
00230 {
00231     cl_int rs = CL_SUCCESS;
00232 
00233     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00234         return CL_INVALID_COMMAND_QUEUE;
00235 
00236     Coal::CopyBufferRectEvent *command = new Coal::CopyBufferRectEvent(
00237         (Coal::CommandQueue *)command_queue,
00238         (Coal::MemObject *)src_buffer,
00239         (Coal::MemObject *)dst_buffer,
00240         src_origin, dst_origin, region, src_row_pitch, src_slice_pitch,
00241         dst_row_pitch, dst_slice_pitch, 1,
00242         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00243     );
00244 
00245     if (rs != CL_SUCCESS)
00246     {
00247         delete command;
00248         return rs;
00249     }
00250 
00251     return queueEvent(command_queue, command, event, false);
00252 }
00253 
00254 cl_int
00255 clEnqueueCopyBuffer(cl_command_queue    command_queue,
00256                     cl_mem              src_buffer,
00257                     cl_mem              dst_buffer,
00258                     size_t              src_offset,
00259                     size_t              dst_offset,
00260                     size_t              cb,
00261                     cl_uint             num_events_in_wait_list,
00262                     const cl_event *    event_wait_list,
00263                     cl_event *          event)
00264 {
00265     cl_int rs = CL_SUCCESS;
00266 
00267     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00268         return CL_INVALID_COMMAND_QUEUE;
00269 
00270     Coal::CopyBufferEvent *command = new Coal::CopyBufferEvent(
00271         (Coal::CommandQueue *)command_queue,
00272         (Coal::MemObject *)src_buffer,
00273         (Coal::MemObject *)dst_buffer,
00274         src_offset, dst_offset, cb,
00275         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00276     );
00277 
00278     if (rs != CL_SUCCESS)
00279     {
00280         delete command;
00281         return rs;
00282     }
00283 
00284     return queueEvent(command_queue, command, event, false);
00285 }
00286 
00287 cl_int
00288 clEnqueueReadImage(cl_command_queue     command_queue,
00289                    cl_mem               image,
00290                    cl_bool              blocking_read,
00291                    const size_t *       origin,
00292                    const size_t *       region,
00293                    size_t               row_pitch,
00294                    size_t               slice_pitch,
00295                    void *               ptr,
00296                    cl_uint              num_events_in_wait_list,
00297                    const cl_event *     event_wait_list,
00298                    cl_event *           event)
00299 {
00300     cl_int rs = CL_SUCCESS;
00301 
00302     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00303         return CL_INVALID_COMMAND_QUEUE;
00304 
00305     if (!image || (image->type() != Coal::MemObject::Image2D &&
00306         image->type() != Coal::MemObject::Image3D))
00307         return CL_INVALID_MEM_OBJECT;
00308 
00309     Coal::ReadImageEvent *command = new Coal::ReadImageEvent(
00310         (Coal::CommandQueue *)command_queue,
00311         (Coal::Image2D *)image,
00312         origin, region, row_pitch, slice_pitch, (void *)ptr,
00313         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00314     );
00315 
00316     if (rs != CL_SUCCESS)
00317     {
00318         delete command;
00319         return rs;
00320     }
00321 
00322     return queueEvent(command_queue, command, event, blocking_read);
00323 }
00324 
00325 cl_int
00326 clEnqueueWriteImage(cl_command_queue    command_queue,
00327                     cl_mem              image,
00328                     cl_bool             blocking_write,
00329                     const size_t *      origin,
00330                     const size_t *      region,
00331                     size_t              row_pitch,
00332                     size_t              slice_pitch,
00333                     const void *        ptr,
00334                     cl_uint             num_events_in_wait_list,
00335                     const cl_event *    event_wait_list,
00336                     cl_event *          event)
00337 {
00338     cl_int rs = CL_SUCCESS;
00339 
00340     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00341         return CL_INVALID_COMMAND_QUEUE;
00342 
00343     Coal::WriteImageEvent *command = new Coal::WriteImageEvent(
00344         (Coal::CommandQueue *)command_queue,
00345         (Coal::Image2D *)image,
00346         origin, region, row_pitch, slice_pitch, (void *)ptr,
00347         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00348     );
00349 
00350     if (rs != CL_SUCCESS)
00351     {
00352         delete command;
00353         return rs;
00354     }
00355 
00356     return queueEvent(command_queue, command, event, blocking_write);
00357 }
00358 
00359 cl_int
00360 clEnqueueCopyImage(cl_command_queue     command_queue,
00361                    cl_mem               src_image,
00362                    cl_mem               dst_image,
00363                    const size_t *       src_origin,
00364                    const size_t *       dst_origin,
00365                    const size_t *       region,
00366                    cl_uint              num_events_in_wait_list,
00367                    const cl_event *     event_wait_list,
00368                    cl_event *           event)
00369 {
00370     cl_int rs = CL_SUCCESS;
00371 
00372     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00373         return CL_INVALID_COMMAND_QUEUE;
00374 
00375     Coal::CopyImageEvent *command = new Coal::CopyImageEvent(
00376         (Coal::CommandQueue *)command_queue,
00377         (Coal::Image2D *)src_image, (Coal::Image2D *)dst_image,
00378         src_origin, dst_origin, region,
00379         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00380     );
00381 
00382     if (rs != CL_SUCCESS)
00383     {
00384         delete command;
00385         return rs;
00386     }
00387 
00388     return queueEvent(command_queue, command, event, false);
00389 }
00390 
00391 cl_int
00392 clEnqueueCopyImageToBuffer(cl_command_queue command_queue,
00393                            cl_mem           src_image,
00394                            cl_mem           dst_buffer,
00395                            const size_t *   src_origin,
00396                            const size_t *   region,
00397                            size_t           dst_offset,
00398                            cl_uint          num_events_in_wait_list,
00399                            const cl_event * event_wait_list,
00400                            cl_event *       event)
00401 {
00402     cl_int rs = CL_SUCCESS;
00403 
00404     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00405         return CL_INVALID_COMMAND_QUEUE;
00406 
00407     Coal::CopyImageToBufferEvent *command = new Coal::CopyImageToBufferEvent(
00408         (Coal::CommandQueue *)command_queue,
00409         (Coal::Image2D *)src_image, (Coal::MemObject *)dst_buffer,
00410         src_origin, region, dst_offset,
00411         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00412     );
00413 
00414     if (rs != CL_SUCCESS)
00415     {
00416         delete command;
00417         return rs;
00418     }
00419 
00420     return queueEvent(command_queue, command, event, false);
00421 }
00422 
00423 cl_int
00424 clEnqueueCopyBufferToImage(cl_command_queue command_queue,
00425                            cl_mem           src_buffer,
00426                            cl_mem           dst_image,
00427                            size_t           src_offset,
00428                            const size_t *   dst_origin,
00429                            const size_t *   region,
00430                            cl_uint          num_events_in_wait_list,
00431                            const cl_event * event_wait_list,
00432                            cl_event *       event)
00433 {
00434     cl_int rs = CL_SUCCESS;
00435 
00436     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00437         return CL_INVALID_COMMAND_QUEUE;
00438 
00439     Coal::CopyBufferToImageEvent *command = new Coal::CopyBufferToImageEvent(
00440         (Coal::CommandQueue *)command_queue,
00441         (Coal::MemObject *)src_buffer, (Coal::Image2D *)dst_image,
00442         src_offset, dst_origin, region,
00443         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00444     );
00445 
00446     if (rs != CL_SUCCESS)
00447     {
00448         delete command;
00449         return rs;
00450     }
00451 
00452     return queueEvent(command_queue, command, event, false);
00453 }
00454 
00455 void *
00456 clEnqueueMapBuffer(cl_command_queue command_queue,
00457                    cl_mem           buffer,
00458                    cl_bool          blocking_map,
00459                    cl_map_flags     map_flags,
00460                    size_t           offset,
00461                    size_t           cb,
00462                    cl_uint          num_events_in_wait_list,
00463                    const cl_event * event_wait_list,
00464                    cl_event *       event,
00465                    cl_int *         errcode_ret)
00466 {
00467     cl_int dummy_errcode;
00468 
00469     if (!errcode_ret)
00470         errcode_ret = &dummy_errcode;
00471 
00472     *errcode_ret = CL_SUCCESS;
00473 
00474     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00475     {
00476         *errcode_ret = CL_INVALID_COMMAND_QUEUE;
00477         return 0;
00478     }
00479 
00480     Coal::MapBufferEvent *command = new Coal::MapBufferEvent(
00481         (Coal::CommandQueue *)command_queue,
00482         (Coal::MemObject *)buffer,
00483         offset, cb, map_flags,
00484         num_events_in_wait_list, (const Coal::Event **)event_wait_list, errcode_ret
00485     );
00486 
00487     if (*errcode_ret != CL_SUCCESS)
00488     {
00489         delete command;
00490         return 0;
00491     }
00492 
00493     // We need command to be valid after queueEvent, so don't let the command
00494     // queue handle it like a fire-and-forget event. Fixes a crash when event
00495     // is NULL : the event gets deleted by clReleaseEvent called from
00496     // CPUDevice's worker() and we then try to read it in command->ptr();
00497     command->reference();
00498 
00499     *errcode_ret = queueEvent(command_queue, command, event, blocking_map);
00500 
00501     if (*errcode_ret != CL_SUCCESS)
00502         return 0;
00503     else
00504     {
00505         void *rs = command->ptr();
00506 
00507         clReleaseEvent((cl_event)command);
00508 
00509         return rs;
00510     }
00511 }
00512 
00513 void *
00514 clEnqueueMapImage(cl_command_queue  command_queue,
00515                   cl_mem            image,
00516                   cl_bool           blocking_map,
00517                   cl_map_flags      map_flags,
00518                   const size_t *    origin,
00519                   const size_t *    region,
00520                   size_t *          image_row_pitch,
00521                   size_t *          image_slice_pitch,
00522                   cl_uint           num_events_in_wait_list,
00523                   const cl_event *  event_wait_list,
00524                   cl_event *        event,
00525                   cl_int *          errcode_ret)
00526 {
00527     cl_int rs;
00528 
00529     if (!errcode_ret)
00530         errcode_ret = &rs;
00531 
00532     *errcode_ret = CL_SUCCESS;
00533 
00534     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00535     {
00536         *errcode_ret = CL_INVALID_COMMAND_QUEUE;
00537         return 0;
00538     }
00539 
00540     Coal::MapImageEvent *command = new Coal::MapImageEvent(
00541         (Coal::CommandQueue *)command_queue,
00542         (Coal::Image2D *)image,
00543         map_flags, origin, region,
00544         num_events_in_wait_list, (const Coal::Event **)event_wait_list, errcode_ret
00545     );
00546 
00547     if (*errcode_ret != CL_SUCCESS)
00548     {
00549         delete command;
00550         return 0;
00551     }
00552 
00553     if (!image_row_pitch ||
00554         (image->type() == Coal::MemObject::Image3D && !image_slice_pitch))
00555     {
00556         *errcode_ret = CL_INVALID_VALUE;
00557         delete command;
00558         return 0;
00559     }
00560 
00561     command->reference(); // See clEnqueueMapImage for explanation.
00562     *errcode_ret = queueEvent(command_queue, command, event, blocking_map);
00563 
00564     if (*errcode_ret != CL_SUCCESS)
00565     {
00566         delete command;
00567         return 0;
00568     }
00569     else
00570     {
00571         *image_row_pitch = command->row_pitch();
00572 
00573         if (image_slice_pitch)
00574             *image_slice_pitch = command->slice_pitch();
00575 
00576         void *rs = command->ptr();
00577 
00578         clReleaseEvent((cl_event)command);
00579 
00580         return rs;
00581     }
00582 }
00583 
00584 cl_int
00585 clEnqueueUnmapMemObject(cl_command_queue command_queue,
00586                         cl_mem           memobj,
00587                         void *           mapped_ptr,
00588                         cl_uint          num_events_in_wait_list,
00589                         const cl_event *  event_wait_list,
00590                         cl_event *        event)
00591 {
00592     cl_int rs = CL_SUCCESS;
00593 
00594     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00595     {
00596         return CL_INVALID_COMMAND_QUEUE;
00597     }
00598 
00599     Coal::UnmapBufferEvent *command = new Coal::UnmapBufferEvent(
00600         (Coal::CommandQueue *)command_queue,
00601         (Coal::MemObject *)memobj,
00602         mapped_ptr,
00603         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00604     );
00605 
00606     if (rs != CL_SUCCESS)
00607     {
00608         delete command;
00609         return rs;
00610     }
00611 
00612     return queueEvent(command_queue, command, event, false);
00613 }
00614 
00615 cl_int
00616 clEnqueueNDRangeKernel(cl_command_queue command_queue,
00617                        cl_kernel        kernel,
00618                        cl_uint          work_dim,
00619                        const size_t *   global_work_offset,
00620                        const size_t *   global_work_size,
00621                        const size_t *   local_work_size,
00622                        cl_uint          num_events_in_wait_list,
00623                        const cl_event * event_wait_list,
00624                        cl_event *       event)
00625 {
00626     cl_int rs = CL_SUCCESS;
00627 
00628     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00629     {
00630         return CL_INVALID_COMMAND_QUEUE;
00631     }
00632 
00633     Coal::KernelEvent *command = new Coal::KernelEvent(
00634         (Coal::CommandQueue *)command_queue,
00635         (Coal::Kernel *)kernel,
00636         work_dim, global_work_offset, global_work_size, local_work_size,
00637         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00638     );
00639 
00640     if (rs != CL_SUCCESS)
00641     {
00642         delete command;
00643         return rs;
00644     }
00645 
00646     return queueEvent(command_queue, command, event, false);
00647 }
00648 
00649 cl_int
00650 clEnqueueTask(cl_command_queue  command_queue,
00651               cl_kernel         kernel,
00652               cl_uint           num_events_in_wait_list,
00653               const cl_event *  event_wait_list,
00654               cl_event *        event)
00655 {
00656     cl_int rs = CL_SUCCESS;
00657 
00658     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00659     {
00660         return CL_INVALID_COMMAND_QUEUE;
00661     }
00662 
00663     Coal::TaskEvent *command = new Coal::TaskEvent(
00664         (Coal::CommandQueue *)command_queue,
00665         (Coal::Kernel *)kernel,
00666         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00667     );
00668 
00669     if (rs != CL_SUCCESS)
00670     {
00671         delete command;
00672         return rs;
00673     }
00674 
00675     return queueEvent(command_queue, command, event, false);
00676 }
00677 
00678 cl_int
00679 clEnqueueNativeKernel(cl_command_queue  command_queue,
00680                       void (*user_func)(void *),
00681                       void *            args,
00682                       size_t            cb_args,
00683                       cl_uint           num_mem_objects,
00684                       const cl_mem *    mem_list,
00685                       const void **     args_mem_loc,
00686                       cl_uint           num_events_in_wait_list,
00687                       const cl_event *  event_wait_list,
00688                       cl_event *        event)
00689 {
00690     cl_int rs = CL_SUCCESS;
00691 
00692     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00693         return CL_INVALID_COMMAND_QUEUE;
00694 
00695     Coal::NativeKernelEvent *command = new Coal::NativeKernelEvent(
00696         (Coal::CommandQueue *)command_queue,
00697         user_func, args, cb_args, num_mem_objects,
00698         (const Coal::MemObject **)mem_list, args_mem_loc,
00699         num_events_in_wait_list, (const Coal::Event **)event_wait_list, &rs
00700     );
00701 
00702     if (rs != CL_SUCCESS)
00703     {
00704         delete command;
00705         return rs;
00706     }
00707 
00708     return queueEvent(command_queue, command, event, false);
00709 }
00710 
00711 cl_int
00712 clEnqueueMarker(cl_command_queue    command_queue,
00713                 cl_event *          event)
00714 {
00715     cl_int rs = CL_SUCCESS;
00716 
00717     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00718         return CL_INVALID_COMMAND_QUEUE;
00719 
00720     if (!event)
00721         return CL_INVALID_VALUE;
00722 
00723     // Get the events in command_queue
00724     unsigned int count;
00725     Coal::Event **events = command_queue->events(count);
00726 
00727     Coal::MarkerEvent *command = new Coal::MarkerEvent(
00728         (Coal::CommandQueue *)command_queue,
00729         count, (const Coal::Event **)events, &rs);
00730 
00731     if (rs != CL_SUCCESS)
00732     {
00733         delete command;
00734         return rs;
00735     }
00736 
00737     // Free events, they were memcpyed by Coal::Event
00738     for (unsigned int i=0; i<count; ++i)
00739     {
00740         events[i]->dereference();
00741     }
00742 
00743     std::free(events);
00744 
00745     return queueEvent(command_queue, command, event, false);
00746 }
00747 
00748 cl_int
00749 clEnqueueWaitForEvents(cl_command_queue command_queue,
00750                        cl_uint          num_events,
00751                        const cl_event * event_list)
00752 {
00753     cl_int rs = CL_SUCCESS;
00754 
00755     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00756         return CL_INVALID_COMMAND_QUEUE;
00757 
00758     Coal::WaitForEventsEvent *command = new Coal::WaitForEventsEvent(
00759         (Coal::CommandQueue *)command_queue,
00760         num_events, (const Coal::Event **)event_list, &rs);
00761 
00762     if (rs != CL_SUCCESS)
00763     {
00764         delete command;
00765         return rs;
00766     }
00767 
00768     return queueEvent(command_queue, command, 0, false);
00769 }
00770 
00771 cl_int
00772 clEnqueueBarrier(cl_command_queue command_queue)
00773 {
00774     cl_int rs = CL_SUCCESS;
00775 
00776     if (!command_queue->isA(Coal::Object::T_CommandQueue))
00777         return CL_INVALID_COMMAND_QUEUE;
00778 
00779     Coal::BarrierEvent *command = new Coal::BarrierEvent(
00780         (Coal::CommandQueue *)command_queue, &rs);
00781 
00782     if (rs != CL_SUCCESS)
00783     {
00784         delete command;
00785         return rs;
00786     }
00787 
00788     return queueEvent(command_queue, command, 0, false);
00789 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines