Clover Git
OpenCL 1.1 software implementation
|
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 #ifndef __EVENTS_H__ 00034 #define __EVENTS_H__ 00035 00036 #include "commandqueue.h" 00037 #include <core/config.h> 00038 00039 #include <vector> 00040 00041 namespace Coal 00042 { 00043 00044 class MemObject; 00045 class Image2D; 00046 class Kernel; 00047 class DeviceKernel; 00048 class DeviceInterface; 00049 00053 class BufferEvent : public Event 00054 { 00055 public: 00056 BufferEvent(CommandQueue *parent, 00057 MemObject *buffer, 00058 cl_uint num_events_in_wait_list, 00059 const Event **event_wait_list, 00060 cl_int *errcode_ret); 00061 00062 MemObject *buffer() const; 00076 static bool isSubBufferAligned(const MemObject *buffer, 00077 const DeviceInterface *device); 00078 00079 private: 00080 MemObject *p_buffer; 00081 }; 00082 00086 class ReadWriteBufferEvent : public BufferEvent 00087 { 00088 public: 00089 ReadWriteBufferEvent(CommandQueue *parent, 00090 MemObject *buffer, 00091 size_t offset, 00092 size_t cb, 00093 void *ptr, 00094 cl_uint num_events_in_wait_list, 00095 const Event **event_wait_list, 00096 cl_int *errcode_ret); 00097 00098 size_t offset() const; 00099 size_t cb() const; 00100 void *ptr() const; 00102 private: 00103 size_t p_offset, p_cb; 00104 void *p_ptr; 00105 }; 00106 00110 class ReadBufferEvent : public ReadWriteBufferEvent 00111 { 00112 public: 00113 ReadBufferEvent(CommandQueue *parent, 00114 MemObject *buffer, 00115 size_t offset, 00116 size_t cb, 00117 void *ptr, 00118 cl_uint num_events_in_wait_list, 00119 const Event **event_wait_list, 00120 cl_int *errcode_ret); 00121 00122 Type type() const; 00123 }; 00124 00128 class WriteBufferEvent : public ReadWriteBufferEvent 00129 { 00130 public: 00131 WriteBufferEvent(CommandQueue *parent, 00132 MemObject *buffer, 00133 size_t offset, 00134 size_t cb, 00135 void *ptr, 00136 cl_uint num_events_in_wait_list, 00137 const Event **event_wait_list, 00138 cl_int *errcode_ret); 00139 00140 Type type() const; 00141 }; 00142 00146 class MapBufferEvent : public BufferEvent 00147 { 00148 public: 00149 MapBufferEvent(CommandQueue *parent, 00150 MemObject *buffer, 00151 size_t offset, 00152 size_t cb, 00153 cl_map_flags map_flags, 00154 cl_uint num_events_in_wait_list, 00155 const Event **event_wait_list, 00156 cl_int *errcode_ret); 00157 00158 Type type() const; 00160 size_t offset() const; 00161 size_t cb() const; 00162 cl_map_flags flags() const; 00163 void *ptr() const; 00174 void setPtr(void *ptr); 00175 00176 private: 00177 size_t p_offset, p_cb; 00178 cl_map_flags p_map_flags; 00179 void *p_ptr; 00180 }; 00181 00185 class MapImageEvent : public BufferEvent 00186 { 00187 public: 00188 MapImageEvent(CommandQueue *parent, 00189 Image2D *image, 00190 cl_map_flags map_flags, 00191 const size_t origin[3], 00192 const size_t region[3], 00193 cl_uint num_events_in_wait_list, 00194 const Event **event_wait_list, 00195 cl_int *errcode_ret); 00196 00197 Type type() const; 00204 size_t origin(unsigned int index) const; 00205 00211 size_t region(unsigned int index) const; 00212 cl_map_flags flags() const; 00214 void *ptr() const; 00215 size_t row_pitch() const; 00216 size_t slice_pitch() const; 00228 void setPtr(void *ptr); 00229 void setRowPitch(size_t row_pitch); 00230 void setSlicePitch(size_t slice_pitch); 00232 private: 00233 cl_map_flags p_map_flags; 00234 size_t p_origin[3], p_region[3]; 00235 void *p_ptr; 00236 size_t p_slice_pitch, p_row_pitch; 00237 }; 00238 00242 class UnmapBufferEvent : public BufferEvent 00243 { 00244 public: 00245 UnmapBufferEvent(CommandQueue *parent, 00246 MemObject *buffer, 00247 void *mapped_addr, 00248 cl_uint num_events_in_wait_list, 00249 const Event **event_wait_list, 00250 cl_int *errcode_ret); 00251 00252 Type type() const; 00254 void *mapping() const; 00256 private: 00257 void *p_mapping; 00258 }; 00259 00263 class CopyBufferEvent : public BufferEvent 00264 { 00265 public: 00266 CopyBufferEvent(CommandQueue *parent, 00267 MemObject *source, 00268 MemObject *destination, 00269 size_t src_offset, 00270 size_t dst_offset, 00271 size_t cb, 00272 cl_uint num_events_in_wait_list, 00273 const Event **event_wait_list, 00274 cl_int *errcode_ret); 00275 00276 Type type() const; 00278 MemObject *source() const; 00279 MemObject *destination() const; 00280 size_t src_offset() const; 00281 size_t dst_offset() const; 00282 size_t cb() const; 00284 private: 00285 MemObject *p_destination; 00286 size_t p_src_offset, p_dst_offset, p_cb; 00287 }; 00288 00294 class ReadWriteCopyBufferRectEvent : public BufferEvent 00295 { 00296 public: 00297 ReadWriteCopyBufferRectEvent(CommandQueue *parent, 00298 MemObject *source, 00299 const size_t src_origin[3], 00300 const size_t dst_origin[3], 00301 const size_t region[3], 00302 size_t src_row_pitch, 00303 size_t src_slice_pitch, 00304 size_t dst_row_pitch, 00305 size_t dst_slice_pitch, 00306 unsigned int bytes_per_element, 00307 cl_uint num_events_in_wait_list, 00308 const Event **event_wait_list, 00309 cl_int *errcode_ret); 00310 00311 size_t src_origin(unsigned int index) const; 00312 size_t dst_origin(unsigned int index) const; 00313 size_t region(unsigned int index) const; 00314 size_t src_row_pitch() const; 00315 size_t src_slice_pitch() const; 00316 size_t dst_row_pitch() const; 00317 size_t dst_slice_pitch() const; 00318 MemObject *source() const; 00320 protected: 00321 size_t p_src_origin[3], p_dst_origin[3], p_region[3]; 00322 size_t p_src_row_pitch, p_src_slice_pitch; 00323 size_t p_dst_row_pitch, p_dst_slice_pitch; 00324 }; 00325 00329 class CopyBufferRectEvent : public ReadWriteCopyBufferRectEvent 00330 { 00331 public: 00332 CopyBufferRectEvent(CommandQueue *parent, 00333 MemObject *source, 00334 MemObject *destination, 00335 const size_t src_origin[3], 00336 const size_t dst_origin[3], 00337 const size_t region[3], 00338 size_t src_row_pitch, 00339 size_t src_slice_pitch, 00340 size_t dst_row_pitch, 00341 size_t dst_slice_pitch, 00342 unsigned int bytes_per_element, 00343 cl_uint num_events_in_wait_list, 00344 const Event **event_wait_list, 00345 cl_int *errcode_ret); 00346 00347 virtual Type type() const; 00348 MemObject *destination() const; 00350 private: 00351 MemObject *p_destination; 00352 }; 00353 00357 class ReadWriteBufferRectEvent : public ReadWriteCopyBufferRectEvent 00358 { 00359 public: 00360 ReadWriteBufferRectEvent(CommandQueue *parent, 00361 MemObject *buffer, 00362 const size_t buffer_origin[3], 00363 const size_t host_origin[3], 00364 const size_t region[3], 00365 size_t buffer_row_pitch, 00366 size_t buffer_slice_pitch, 00367 size_t host_row_pitch, 00368 size_t host_slice_pitch, 00369 void *ptr, 00370 unsigned int bytes_per_element, 00371 cl_uint num_events_in_wait_list, 00372 const Event **event_wait_list, 00373 cl_int *errcode_ret); 00374 00375 void *ptr() const; 00377 private: 00378 void *p_ptr; 00379 }; 00380 00384 class ReadBufferRectEvent : public ReadWriteBufferRectEvent 00385 { 00386 public: 00387 ReadBufferRectEvent(CommandQueue *parent, 00388 MemObject *buffer, 00389 const size_t buffer_origin[3], 00390 const size_t host_origin[3], 00391 const size_t region[3], 00392 size_t buffer_row_pitch, 00393 size_t buffer_slice_pitch, 00394 size_t host_row_pitch, 00395 size_t host_slice_pitch, 00396 void *ptr, 00397 cl_uint num_events_in_wait_list, 00398 const Event **event_wait_list, 00399 cl_int *errcode_ret); 00400 00401 Type type() const; 00402 }; 00403 00407 class WriteBufferRectEvent : public ReadWriteBufferRectEvent 00408 { 00409 public: 00410 WriteBufferRectEvent(CommandQueue *parent, 00411 MemObject *buffer, 00412 const size_t buffer_origin[3], 00413 const size_t host_origin[3], 00414 const size_t region[3], 00415 size_t buffer_row_pitch, 00416 size_t buffer_slice_pitch, 00417 size_t host_row_pitch, 00418 size_t host_slice_pitch, 00419 void *ptr, 00420 cl_uint num_events_in_wait_list, 00421 const Event **event_wait_list, 00422 cl_int *errcode_ret); 00423 00424 Type type() const; 00425 }; 00426 00434 class ReadWriteImageEvent : public ReadWriteBufferRectEvent 00435 { 00436 public: 00437 ReadWriteImageEvent(CommandQueue *parent, 00438 Image2D *image, 00439 const size_t origin[3], 00440 const size_t region[3], 00441 size_t row_pitch, 00442 size_t slice_pitch, 00443 void *ptr, 00444 cl_uint num_events_in_wait_list, 00445 const Event **event_wait_list, 00446 cl_int *errcode_ret); 00447 }; 00448 00452 class ReadImageEvent : public ReadWriteImageEvent 00453 { 00454 public: 00455 ReadImageEvent(CommandQueue *parent, 00456 Image2D *image, 00457 const size_t origin[3], 00458 const size_t region[3], 00459 size_t row_pitch, 00460 size_t slice_pitch, 00461 void *ptr, 00462 cl_uint num_events_in_wait_list, 00463 const Event **event_wait_list, 00464 cl_int *errcode_ret); 00465 00466 Type type() const; 00467 }; 00468 00472 class WriteImageEvent : public ReadWriteImageEvent 00473 { 00474 public: 00475 WriteImageEvent(CommandQueue *parent, 00476 Image2D *image, 00477 const size_t origin[3], 00478 const size_t region[3], 00479 size_t row_pitch, 00480 size_t slice_pitch, 00481 void *ptr, 00482 cl_uint num_events_in_wait_list, 00483 const Event **event_wait_list, 00484 cl_int *errcode_ret); 00485 00486 Type type() const; 00487 }; 00488 00492 class CopyImageEvent : public CopyBufferRectEvent 00493 { 00494 public: 00495 CopyImageEvent(CommandQueue *parent, 00496 Image2D *source, 00497 Image2D *destination, 00498 const size_t src_origin[3], 00499 const size_t dst_origin[3], 00500 const size_t region[3], 00501 cl_uint num_events_in_wait_list, 00502 const Event **event_wait_list, 00503 cl_int *errcode_ret); 00504 00505 Type type() const; 00506 }; 00507 00511 class CopyImageToBufferEvent : public CopyBufferRectEvent 00512 { 00513 public: 00514 CopyImageToBufferEvent(CommandQueue *parent, 00515 Image2D *source, 00516 MemObject *destination, 00517 const size_t src_origin[3], 00518 const size_t region[3], 00519 size_t dst_offset, 00520 cl_uint num_events_in_wait_list, 00521 const Event **event_wait_list, 00522 cl_int *errcode_ret); 00523 00524 size_t offset() const; 00525 Type type() const; 00527 private: 00528 size_t p_offset; 00529 }; 00530 00534 class CopyBufferToImageEvent : public CopyBufferRectEvent 00535 { 00536 public: 00537 CopyBufferToImageEvent(CommandQueue *parent, 00538 MemObject *source, 00539 Image2D *destination, 00540 size_t src_offset, 00541 const size_t dst_origin[3], 00542 const size_t region[3], 00543 cl_uint num_events_in_wait_list, 00544 const Event **event_wait_list, 00545 cl_int *errcode_ret); 00546 00547 size_t offset() const; 00548 Type type() const; 00550 private: 00551 size_t p_offset; 00552 }; 00553 00562 class NativeKernelEvent : public Event 00563 { 00564 public: 00565 NativeKernelEvent(CommandQueue *parent, 00566 void (*user_func)(void *), 00567 void *args, 00568 size_t cb_args, 00569 cl_uint num_mem_objects, 00570 const MemObject **mem_list, 00571 const void **args_mem_loc, 00572 cl_uint num_events_in_wait_list, 00573 const Event **event_wait_list, 00574 cl_int *errcode_ret); 00575 ~NativeKernelEvent(); 00576 00577 Type type() const; 00579 void *function() const; 00580 void *args() const; 00582 private: 00583 void *p_user_func; 00584 void *p_args; 00585 }; 00586 00590 class KernelEvent : public Event 00591 { 00592 public: 00593 KernelEvent(CommandQueue *parent, 00594 Kernel *kernel, 00595 cl_uint work_dim, 00596 const size_t *global_work_offset, 00597 const size_t *global_work_size, 00598 const size_t *local_work_size, 00599 cl_uint num_events_in_wait_list, 00600 const Event **event_wait_list, 00601 cl_int *errcode_ret); 00602 ~KernelEvent(); 00603 00604 cl_uint work_dim() const; 00605 size_t global_work_offset(cl_uint dim) const; 00606 size_t global_work_size(cl_uint dim) const; 00607 size_t local_work_size(cl_uint dim) const; 00608 Kernel *kernel() const; 00609 DeviceKernel *deviceKernel() const; 00611 virtual Type type() const; 00613 private: 00614 cl_uint p_work_dim; 00615 size_t p_global_work_offset[MAX_WORK_DIMS], 00616 p_global_work_size[MAX_WORK_DIMS], 00617 p_local_work_size[MAX_WORK_DIMS], 00618 p_max_work_item_sizes[MAX_WORK_DIMS]; 00619 Kernel *p_kernel; 00620 DeviceKernel *p_dev_kernel; 00621 }; 00622 00635 class TaskEvent : public KernelEvent 00636 { 00637 public: 00638 TaskEvent(CommandQueue *parent, 00639 Kernel *kernel, 00640 cl_uint num_events_in_wait_list, 00641 const Event **event_wait_list, 00642 cl_int *errcode_ret); 00643 00644 Type type() const; 00645 }; 00646 00661 class UserEvent : public Event 00662 { 00663 public: 00664 UserEvent(Context *context, cl_int *errcode_ret); 00665 00666 Type type() const; 00667 Context *context() const; 00668 void flushQueues(); 00677 void addDependentCommandQueue(CommandQueue *queue); 00678 00679 private: 00680 Context *p_context; 00681 std::vector<CommandQueue *> p_dependent_queues; 00682 }; 00683 00687 class BarrierEvent : public Event 00688 { 00689 public: 00690 BarrierEvent(CommandQueue *parent, 00691 cl_int *errcode_ret); 00692 00693 Type type() const; 00694 }; 00695 00699 class WaitForEventsEvent : public Event 00700 { 00701 public: 00702 WaitForEventsEvent(CommandQueue *parent, 00703 cl_uint num_events_in_wait_list, 00704 const Event **event_wait_list, 00705 cl_int *errcode_ret); 00706 00707 virtual Type type() const; 00708 }; 00709 00713 class MarkerEvent : public WaitForEventsEvent 00714 { 00715 public: 00716 MarkerEvent(CommandQueue *parent, 00717 cl_uint num_events_in_wait_list, 00718 const Event **event_wait_list, 00719 cl_int *errcode_ret); 00720 00721 Type type() const; 00722 }; 00723 00724 } 00725 00726 #endif