aboutsummaryrefslogtreecommitdiff
path: root/src/core/events.h
blob: ceb4fc1906f9eaf9d9175d5b2ba292244119cac8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
/*
 * Copyright (c) 2011, Denis Steckelmacher <steckdenis@yahoo.fr>
 * Copyright (c) 2012-2014, Texas Instruments Incorporated - http://www.ti.com/
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the copyright holder nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * \file events.h
 * \brief All the event-related classes
 */

#ifndef __EVENTS_H__
#define __EVENTS_H__

#include "commandqueue.h"
#include <core/config.h>

#include <vector>

namespace Coal
{

class MemObject;
class Image2D;
class Kernel;
class DeviceKernel;
class DeviceInterface;

/**
 * \brief Buffer-related event
 */
class BufferEvent : public Event
{
    public:
        BufferEvent(CommandQueue *parent,
                    MemObject *buffer,
                    cl_uint num_events_in_wait_list,
                    const Event **event_wait_list,
                    cl_int *errcode_ret);
        virtual ~BufferEvent();

        MemObject *buffer() const; /*!< \brief Buffer on which to operate */

        /**
         * \brief Check that a buffer is correctly aligned for a device
         * 
         * OpenCL supports sub-buffers of buffers (\c Coal::SubBuffer). They
         * have to be aligned on a certain device-dependent boundary.
         * 
         * This function checks that \p buffer is correctly aligned for
         * \p device. If \p buffer is not a \c Coal::SubBuffer, this function
         * returns true.
         * 
         * \return true if the buffer is aligned or not a \c Coal::SubBuffer
         */
        static bool isSubBufferAligned(const MemObject *buffer,
                                       const DeviceInterface *device);

    private:
        MemObject *p_buffer;
};

/**
 * \brief Reading or writing to a buffer
 */
class ReadWriteBufferEvent : public BufferEvent
{
    public:
        ReadWriteBufferEvent(CommandQueue *parent,
                             MemObject *buffer,
                             size_t offset,
                             size_t cb,
                             void *ptr,
                             cl_uint num_events_in_wait_list,
                             const Event **event_wait_list,
                             cl_int *errcode_ret);

        size_t offset() const; /*!< \brief Offset in the buffer of the operation, in bytes */
        size_t cb() const;     /*!< \brief Number of bytes to read or write */
        void *ptr() const;     /*!< \brief Pointer in host memory at which to put the data */

    private:
        size_t p_offset, p_cb;
        void *p_ptr;
};

/**
 * \brief Reading a buffer
 */
class ReadBufferEvent : public ReadWriteBufferEvent
{
    public:
        ReadBufferEvent(CommandQueue *parent,
                        MemObject *buffer,
                        size_t offset,
                        size_t cb,
                        void *ptr,
                        cl_uint num_events_in_wait_list,
                        const Event **event_wait_list,
                        cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::ReadBuffer one */
};

/**
 * \brief Writing a buffer
 */
class WriteBufferEvent : public ReadWriteBufferEvent
{
    public:
        WriteBufferEvent(CommandQueue *parent,
                         MemObject *buffer,
                         size_t offset,
                         size_t cb,
                         void *ptr,
                         cl_uint num_events_in_wait_list,
                         const Event **event_wait_list,
                         cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::WriteBuffer one */
};

/**
 * \brief Mapping a buffer
 */
class MapBufferEvent : public BufferEvent
{
    public:
        MapBufferEvent(CommandQueue *parent,
                       MemObject *buffer,
                       size_t offset,
                       size_t cb,
                       cl_map_flags map_flags,
                       cl_uint num_events_in_wait_list,
                       const Event **event_wait_list,
                       cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::MapBuffer one */

        size_t offset() const;      /*!< \brief Offset in the buffer at which the mapping begins, in bytes */
        size_t cb() const;          /*!< \brief Number of bytes to map */
        cl_map_flags flags() const; /*!< \brief Flags of the mapping */
        void *ptr() const;          /*!< \brief Pointer at which the data has been mapped */

        /**
         * \brief Set the memory location at which the data has been mapped
         * 
         * This function is called by the device when it has successfully mapped
         * the buffer. It must be called inside 
         * \c Coal::DeviceInterface::initEventDeviceData().
         * 
         * \param ptr the address at which the buffer has been mapped
         */
        void setPtr(void *ptr);

    private:
        size_t p_offset, p_cb;
        cl_map_flags p_map_flags;
        void *p_ptr;
};

/**
 * \brief Mapping an image
 */
class MapImageEvent : public BufferEvent
{
    public:
        MapImageEvent(CommandQueue *parent,
                      Image2D *image,
                      cl_map_flags map_flags,
                      const size_t origin[3],
                      const size_t region[3],
                      cl_uint num_events_in_wait_list,
                      const Event **event_wait_list,
                      cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::MapImage one */

        /**
         * \brief Origin of the mapping, in pixels, for the given dimension
         * \param index dimension for which the origin is retrieved
         * \return origin of the mapping for the given dimension
         */
        size_t origin(unsigned int index) const;

        /**
         * \brief Region of the mapping, in pixels, for the given dimension
         * \param index dimension for which the region is retrieved
         * \return region of the mapping for the given dimension
         */
        size_t region(unsigned int index) const;
        cl_map_flags flags() const; /*!< \brief Flags of the mapping */

        void *ptr() const;          /*!< \brief Pointer at which the data is mapped */
        size_t row_pitch() const;   /*!< \brief Row pitch of the mapped data */
        size_t slice_pitch() const; /*!< \brief Slice pitch of the mapped data */

        /**
         * \brief Set the memory location at which the image is mapped
         * 
         * This function must be called by
         * \c Coal::DeviceInterface::initEventDeviceData(). Row and slice pitches
         * must also be set by this function by calling \c setRowPitch() and
         * \c setSlicePitch().
         * 
         * \param ptr pointer at which the data is available
         */
        void setPtr(void *ptr);
        void setRowPitch(size_t row_pitch);     /*!< \brief Set row pitch */
        void setSlicePitch(size_t slice_pitch); /*!< \brief Set slice pitch */

    private:
        cl_map_flags p_map_flags;
        size_t p_origin[3], p_region[3];
        void *p_ptr;
        size_t p_slice_pitch, p_row_pitch;
};

/**
 * \brief Unmapping a memory object
 */
class UnmapBufferEvent : public BufferEvent
{
    public:
        UnmapBufferEvent(CommandQueue *parent,
                         MemObject *buffer,
                         void *mapped_addr,
                         cl_uint num_events_in_wait_list,
                         const Event **event_wait_list,
                         cl_int *errcode_ret);

        Type type() const;     /*!< \brief Say the event is a \c Coal::Event::UnmapBuffer one */

        void *mapping() const; /*!< \brief Mapped address to unmap */

    private:
        void *p_mapping;
};

/**
 * \brief Copying between two buffers
 */
class CopyBufferEvent : public BufferEvent
{
    public:
        CopyBufferEvent(CommandQueue *parent,
                        MemObject *source,
                        MemObject *destination,
                        size_t src_offset,
                        size_t dst_offset,
                        size_t cb,
                        cl_uint num_events_in_wait_list,
                        const Event **event_wait_list,
                        cl_int *errcode_ret);
        ~CopyBufferEvent();

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::CopyBuffer one */

        MemObject *source() const;      /*!< \brief Source buffer, equivalent to \c Coal::BufferEvent::buffer() */
        MemObject *destination() const; /*!< \brief Destination buffer */
        size_t src_offset() const;      /*!< \brief Offset in the source buffer, in bytes */
        size_t dst_offset() const;      /*!< \brief Offset in the destination buffer, in bytes */
        size_t cb() const;              /*!< \brief Number of bytes to copy */

    private:
        MemObject *p_destination;
        size_t p_src_offset, p_dst_offset, p_cb;
};

/**
 * \brief Fill a buffer with a pattern
 */
class FillBufferEvent : public BufferEvent
{
    public:
        FillBufferEvent(CommandQueue *parent,
                        MemObject *buffer,
                        const void *       pattern,
                        size_t             pattern_size,
                        size_t             offset,
                        size_t             size,
                        cl_uint num_events_in_wait_list,
                        const Event **event_wait_list,
                        cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::FillBuffer one */

        const void * pattern() const;   /*!< \brief Pattern with which to fill buffer */
        size_t pattern_size() const;    /*!< \brief Size of pattern, in bytes */
        size_t offset() const;          /*!< \brief Location in buffer to start filling */
        size_t size() const;            /*!< \brief Size of region in buffer being filled.  */

    private:
        const void *    p_pattern;
        size_t          p_pattern_size, p_offset, p_size;
};

/**
 * \brief Events related to rectangular (or cubic) memory regions
 * 
 * This event is the base for all the *BufferRect events, and the Image ones.
 */
class ReadWriteCopyBufferRectEvent : public BufferEvent
{
    public:
        ReadWriteCopyBufferRectEvent(CommandQueue *parent,
                                     MemObject *source,
                                     const size_t src_origin[3],
                                     const size_t dst_origin[3],
                                     const size_t region[3],
                                     size_t src_row_pitch,
                                     size_t src_slice_pitch,
                                     size_t dst_row_pitch,
                                     size_t dst_slice_pitch,
                                     unsigned int bytes_per_element,
                                     cl_uint num_events_in_wait_list,
                                     const Event **event_wait_list,
                                     cl_int *errcode_ret);

        size_t src_origin(unsigned int index) const; /*!< \brief Source origin for the \p index dimension */
        size_t dst_origin(unsigned int index) const; /*!< \brief Destination origin for the \p index dimension */
        size_t region(unsigned int index) const;     /*!< \brief Region to copy for the \p index dimension */
        size_t src_row_pitch() const;                /*!< \brief Source row pitch */
        size_t src_slice_pitch() const;              /*!< \brief Source slice pitch */
        size_t dst_row_pitch() const;                /*!< \brief Destination row pitch */
        size_t dst_slice_pitch() const;              /*!< \brief Destination slice pitch */
        MemObject *source() const;                   /*!< \brief Source of the copy, for readability. Calls \c Coal::BufferEvent::buffer(). */

    protected:
        size_t p_src_origin[3], p_dst_origin[3], p_region[3];
        size_t p_src_row_pitch, p_src_slice_pitch;
        size_t p_dst_row_pitch, p_dst_slice_pitch;
};

/**
 * \brief Copying between two buffers
 */
class CopyBufferRectEvent : public ReadWriteCopyBufferRectEvent
{
    public:
        CopyBufferRectEvent(CommandQueue *parent,
                            MemObject *source,
                            MemObject *destination,
                            const size_t src_origin[3],
                            const size_t dst_origin[3],
                            const size_t region[3],
                            size_t src_row_pitch,
                            size_t src_slice_pitch,
                            size_t dst_row_pitch,
                            size_t dst_slice_pitch,
                            unsigned int bytes_per_element,
                            cl_uint num_events_in_wait_list,
                            const Event **event_wait_list,
                            cl_int *errcode_ret);

        virtual Type type() const;      /*!< \brief Say the event is a \c Coal::Event::CopyBufferRect one */
        MemObject *destination() const; /*!< \brief Destination buffer */

    private:
        MemObject *p_destination;
};

/**
 * \brief Reading or writing to a buffer
 */
class ReadWriteBufferRectEvent : public ReadWriteCopyBufferRectEvent
{
    public:
        ReadWriteBufferRectEvent(CommandQueue *parent,
                                 MemObject *buffer,
                                 const size_t buffer_origin[3],
                                 const size_t host_origin[3],
                                 const size_t region[3],
                                 size_t buffer_row_pitch,
                                 size_t buffer_slice_pitch,
                                 size_t host_row_pitch,
                                 size_t host_slice_pitch,
                                 void *ptr,
                                 unsigned int bytes_per_element,
                                 cl_uint num_events_in_wait_list,
                                 const Event **event_wait_list,
                                 cl_int *errcode_ret);

        void *ptr() const; /*!< \brief Pointer in host memory in which to put the data */

    private:
        void *p_ptr;
};

/**
 * \brief Reading a buffer
 */
class ReadBufferRectEvent : public ReadWriteBufferRectEvent
{
    public:
        ReadBufferRectEvent(CommandQueue *parent,
                            MemObject *buffer,
                            const size_t buffer_origin[3],
                            const size_t host_origin[3],
                            const size_t region[3],
                            size_t buffer_row_pitch,
                            size_t buffer_slice_pitch,
                            size_t host_row_pitch,
                            size_t host_slice_pitch,
                            void *ptr,
                            cl_uint num_events_in_wait_list,
                            const Event **event_wait_list,
                            cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::ReadBufferRect one */
};

/**
 * \brief Writing a buffer
 */
class WriteBufferRectEvent : public ReadWriteBufferRectEvent
{
    public:
        WriteBufferRectEvent(CommandQueue *parent,
                             MemObject *buffer,
                             const size_t buffer_origin[3],
                             const size_t host_origin[3],
                             const size_t region[3],
                             size_t buffer_row_pitch,
                             size_t buffer_slice_pitch,
                             size_t host_row_pitch,
                             size_t host_slice_pitch,
                             void *ptr,
                             cl_uint num_events_in_wait_list,
                             const Event **event_wait_list,
                             cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::WriteBufferRect one */
};

/**
 * \brief Reading or writing images
 * 
 * This class only converts some of the arguments given to its constructor
 * to the one of \c Coal::ReadWriteBufferRectEvent. For example, the source row
 * and slice pitches are read from the \c Coal::Image2D object.
 */
class ReadWriteImageEvent : public ReadWriteBufferRectEvent
{
    public:
        ReadWriteImageEvent(CommandQueue *parent,
                            Image2D *image,
                            const size_t origin[3],
                            const size_t region[3],
                            size_t row_pitch,
                            size_t slice_pitch,
                            void *ptr,
                            cl_uint num_events_in_wait_list,
                            const Event **event_wait_list,
                            cl_int *errcode_ret);
};

/**
 * \brief Reading an image
 */
class ReadImageEvent : public ReadWriteImageEvent
{
    public:
        ReadImageEvent(CommandQueue *parent,
                       Image2D *image,
                       const size_t origin[3],
                       const size_t region[3],
                       size_t row_pitch,
                       size_t slice_pitch,
                       void *ptr,
                       cl_uint num_events_in_wait_list,
                       const Event **event_wait_list,
                       cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::ReadImage one */
};

/**
 * \brief Writing to an image
 */
class WriteImageEvent : public ReadWriteImageEvent
{
    public:
        WriteImageEvent(CommandQueue *parent,
                        Image2D *image,
                        const size_t origin[3],
                        const size_t region[3],
                        size_t row_pitch,
                        size_t slice_pitch,
                        void *ptr,
                        cl_uint num_events_in_wait_list,
                        const Event **event_wait_list,
                        cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::WriteImage one */
};

/**
 * \brief Copying between two images
 */
class CopyImageEvent : public CopyBufferRectEvent
{
    public:
        CopyImageEvent(CommandQueue *parent,
                       Image2D *source,
                       Image2D *destination,
                       const size_t src_origin[3],
                       const size_t dst_origin[3],
                       const size_t region[3],
                       cl_uint num_events_in_wait_list,
                       const Event **event_wait_list,
                       cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::CopyImage one */
};

/**
 * \brief Copying an image to a buffer
 */
class CopyImageToBufferEvent : public CopyBufferRectEvent
{
    public:
        CopyImageToBufferEvent(CommandQueue *parent,
                               Image2D *source,
                               MemObject *destination,
                               const size_t src_origin[3],
                               const size_t region[3],
                               size_t dst_offset,
                               cl_uint num_events_in_wait_list,
                               const Event **event_wait_list,
                               cl_int *errcode_ret);

        size_t offset() const; /*!< \brief Offset in the buffer at which writing the image */
        Type type() const;     /*!< \brief Say the event is a \c Coal::Event::CopyImageToBuffer one */

    private:
        size_t p_offset;
};

/**
 * \brief Copying a buffer to an image
 */
class CopyBufferToImageEvent : public CopyBufferRectEvent
{
    public:
        CopyBufferToImageEvent(CommandQueue *parent,
                               MemObject *source,
                               Image2D *destination,
                               size_t src_offset,
                               const size_t dst_origin[3],
                               const size_t region[3],
                               cl_uint num_events_in_wait_list,
                               const Event **event_wait_list,
                               cl_int *errcode_ret);

        size_t offset() const; /*!< \brief Offset in the buffer at which the copy starts */
        Type type() const;     /*!< \brief Say the event is a \c Coal::Event::CopyBufferToImage one */

    private:
        size_t p_offset;
};

/**
 * \brief Executing a native function as a kernel
 * 
 * This event builds an argument list to give to the native function. It needs
 * for example to replace all occurence of a \c Coal::MemObject by a pointer
 * to data the host CPU can actually access, using 
 * \c Coal::DeviceBuffer::nativeGlobalPointer().
 */
class NativeKernelEvent : public Event
{
    public:
        NativeKernelEvent(CommandQueue *parent,
                          void (*user_func)(void *),
                          void *args,
                          size_t cb_args,
                          cl_uint num_mem_objects,
                          const MemObject **mem_list,
                          const void **args_mem_loc,
                          cl_uint num_events_in_wait_list,
                          const Event **event_wait_list,
                          cl_int *errcode_ret);
        ~NativeKernelEvent();

        Type type() const;      /*!< \brief Say the event is a \c Coal::Event::NativeKernel one */

        void *function() const; /*!< \brief Host function to call */
        void *args() const;     /*!< \brief Args to give to the host function */

    private:
        void *p_user_func;
        void *p_args;
};

/**
 * \brief Executing a compiled kernel
 */
class KernelEvent : public Event
{
    public:
        KernelEvent(CommandQueue *parent,
                    Kernel *kernel,
                    cl_uint work_dim,
                    const size_t *global_work_offset,
                    const size_t *global_work_size,
                    const size_t *local_work_size,
                    cl_uint num_events_in_wait_list,
                    const Event **event_wait_list,
                    cl_int *errcode_ret);
        ~KernelEvent();

        cl_uint work_dim() const;                     /*!< \brief Number of working dimensions */
        size_t global_work_offset(cl_uint dim) const; /*!< \brief Global work offset for the \p dim dimension */
        size_t global_work_size(cl_uint dim) const;   /*!< \brief Global work size for the \p dim dimension */
        size_t local_work_size(cl_uint dim) const;    /*!< \brief Number of work-items per work-group for the \p dim dimension */
        Kernel *kernel() const;                       /*!< \brief \c Coal::Kernel object to run */
        DeviceKernel *deviceKernel() const;           /*!< \brief \c Coal::DeviceKernel for the kernel and device of this event */

        virtual Type type() const;                    /*!< \brief Say the event is a \c Coal::Event::NDRangeKernel one */

    private:
        cl_uint p_work_dim;
        size_t p_global_work_offset[MAX_WORK_DIMS],
               p_global_work_size[MAX_WORK_DIMS],
               p_local_work_size[MAX_WORK_DIMS],
               p_max_work_item_sizes[MAX_WORK_DIMS];
        Kernel *p_kernel;
        DeviceKernel *p_dev_kernel;
};

/**
 * \brief Executing a task kernel
 * 
 * This event is simple a \c Coal::KernelEvent with:
 * 
 * - \c work_dim() set to 1
 * - \c global_work_offset() set to {0}
 * - \c global_work_size() set to {1}
 * - \c local_work_size() set to {1}
 * 
 * It's in fact a \c Coal::KernelEvent containing only one single work-item.
 */
class TaskEvent : public KernelEvent
{
    public:
        TaskEvent(CommandQueue *parent,
                  Kernel *kernel,
                  cl_uint num_events_in_wait_list,
                  const Event **event_wait_list,
                  cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::TaskKernel one */
};

/**
 * \brief User event
 * 
 * This event is a bit special as it is created by a call to 
 * \c clCreateUserEvent() and doesn't belong to an event queue. Thus, a mean had
 * to be found for all to work.
 * 
 * The solution is the \c addDependentCommandQueue() function, called every time
 * the user event is added to a command queue. When this event becomes completed,
 * \c flushQueues() is called to allow all the \c Coal::CommandQueue objects
 * containing this event to push more events on their device.
 * 
 * This way, command queues are not blocked by user events.
 */
class UserEvent : public Event
{
    public:
        UserEvent(Context *context, cl_int *errcode_ret);

        Type type() const;        /*!< \brief Say the event is a \c Coal::Event::User one */
        Context *context() const; /*!< \brief Context of this event */

    private:
        Context *p_context;
};

/**
 * \brief Barrier event
 */
class BarrierEvent : public Event
{
    public:
        BarrierEvent(CommandQueue *parent,
                     cl_uint num_events_in_wait_list,
                     const Event **event_wait_list,
                     cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::Barrier one */
};

/**
 * \brief Event waiting for others to complete before being completed
 */
class WaitForEventsEvent : public Event
{
    public:
        WaitForEventsEvent(CommandQueue *parent,
                           cl_uint num_events_in_wait_list,
                           const Event **event_wait_list,
                           cl_int *errcode_ret);

        virtual Type type() const; /*!< \brief Say the event is a \c Coal::Event::WaitForEvents one */
};

/**
 * \brief Marker event
 */
class MarkerEvent : public WaitForEventsEvent
{
    public:
        MarkerEvent(CommandQueue *parent,
                    cl_uint num_events_in_wait_list,
                    const Event **event_wait_list,
                    cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::Marker one */
};

class MigrateMemObjectsEvent: public Event
{
    public:
        MigrateMemObjectsEvent(CommandQueue *parent,
                               cl_uint                num_mem_objects,
                               const Coal::MemObject **mem_objects,
                               cl_mem_migration_flags flags,
                               cl_uint num_events_in_wait_list,
                               const Event **event_wait_list,
                               cl_int *errcode_ret);

        Type type() const; /*!< \brief Say the event is a \c Coal::Event::MigrateMemObjects one */

        cl_uint num_mem_objects() const;            /*!< \brief Number of MemObjects to migrate */
        const Coal::MemObject **mem_objects() const;/*!< \brief List of MemObjects to migrate */
        cl_mem_migration_flags flags() const;       /*!< \brief  Migrate flags */

    private:
        cl_uint  p_num_mem_objects;
        const Coal::MemObject **p_mem_objects;
        cl_mem_migration_flags p_flags;
};

}
#endif