summaryrefslogtreecommitdiff
path: root/tests/util/piglit-util-cl.h
blob: ebe1a1e361e583227a932a4ff2bb82ada03faa57 (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
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
/*
 * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#pragma once
#ifndef PIGLIT_UTIL_CL_H
#define PIGLIT_UTIL_CL_H

#include "piglit-util.h"
#include "piglit-util-cl-enum.h"


/* Define with which version of OpenCL Piglit was compiled */

#if defined(CL_VERSION_2_0)
#  define PIGLIT_CL_VERSION 20
#elif defined(CL_VERSION_1_2)
#  define PIGLIT_CL_VERSION 12
#elif defined(CL_VERSION_1_1)
#  define PIGLIT_CL_VERSION 11
#else
#  define PIGLIT_CL_VERSION 10
#endif


#ifdef __cplusplus
extern "C" {
#endif

#define DIRECT_CONVERT(to, from) \
static inline from convert_##to(from in) \
{ \
	return (to)in; \
}

DIRECT_CONVERT(cl_char, int64_t);
DIRECT_CONVERT(cl_uchar, uint64_t);
DIRECT_CONVERT(cl_short, int64_t);
DIRECT_CONVERT(cl_ushort, uint64_t);
DIRECT_CONVERT(cl_int, int64_t);
DIRECT_CONVERT(cl_uint, uint64_t);
DIRECT_CONVERT(cl_long, int64_t);
DIRECT_CONVERT(cl_ulong, uint64_t);
DIRECT_CONVERT(cl_float, double);
DIRECT_CONVERT(cl_double, double);

cl_half convert_cl_half(double in);


/* Runtime independent */

/**
 * \brief Probe integer \c value if it compares equal to \c expect with
 *        tolerance \c tolerance.
 */
bool piglit_cl_probe_integer(int64_t value, int64_t expect, uint64_t tolerance);

/**
 * \brief Probe unsigned integer \c value if it compares equal to \c expect with
 *        tolerance \c tolerance.
 */
bool piglit_cl_probe_uinteger(uint64_t value,
                              uint64_t expect,
                              uint64_t tolerance);

/**
 * \brief Probe half-floating-point \c value if it compares equal to \c expect with
 *        tolerance \c ulp.
 */
bool piglit_cl_probe_half(cl_half value, cl_half expect, uint32_t ulp);

/**
 * \brief Probe floating-point \c value if it compares equal to \c expect with
 *        tolerance \c ulp.
 */
bool piglit_cl_probe_floating(float value, float expect, uint32_t ulp);

/**
 * \brief Probe double \c value if it compares equal to \c expect with
 *        tolerance \c ulp.
 */
bool piglit_cl_probe_double(double value, double expect, uint64_t ulp);

/**
 * \brief Check for unexpected GL error and report it.
 *
 * If \c error is other than \c expected_error, then print a diagnostic.
 *
 * If you expect no error, then set \code expected_error = CL_SUCCESS \endcode.
 *
 * Returns true if \c error and \c expected_error are the same,
 * else it returns false.
 */
bool piglit_cl_check_error(cl_int error, cl_int expected_error);

/**
 * \brief Check for unexpected GL error and possibly terminate the test.
 *
 * If \c error is other than \c expected_error, then print a diagnostic
 * and terminate the test with the given \c result.
 *
 * If you expect no error, then set \code expected_error = CL_SUCCESS \endcode.
 */
void piglit_cl_expect_error(cl_int error,
                            cl_int expected_error,
                            enum piglit_result result);

/* Runtime dependent */

/* Info functions */

/**
 * \brief Get version of OpenCL API for \c platform.
 *
 * Returned version is multiplied by 10 to make it an integer. For
 * example, if the CL version is 1.1, the returned value is 11.
 */
int piglit_cl_get_platform_version(cl_platform_id platform);

/**
 * \brief Check for required OpenCL version and possibly terminate the test.
 *
 * \c required_version_times_10 must be an OpenCL version multiplied by 10.
 * For example, if the required CL version is 1.1, then the
 * \c required_version_times_10 should be 11.
 */
void piglit_cl_require_platform_version(cl_platform_id platform,
                                        int required_version_times_10);

/**
 * \brief Get version of OpenCL API for \c device.
 *
 * Returned version is multiplied by 10 to make it an integer. For
 * example, if the CL version is 1.1, the returned value is 11.
 */
int piglit_cl_get_device_version(cl_device_id platform);

/**
 * \brief Check for required OpenCL version and possibly terminate the test.
 *
 * \c required_version_times_10 must be an OpenCL version multiplied by 10.
 * For example, if the required CL version is 1.1, then the
 * \c required_version_times_10 should be 11.
 */
void piglit_cl_require_device_version(cl_device_id device,
                                      int required_version_times_10);

/**
 * \brief Get version of OpenCL C for \c device.
 *
 * Returned version is multiplied by 10 to make it an integer. For
 * example, if the CL C version is 1.1, the returned value is 11.
 */
int piglit_cl_get_device_cl_c_version(cl_device_id device);

/**
 * \brief Check for required OpenCL C version and possibly terminate the test.
 *
 * \c required_version_times_10 must be an OpenCL C version multiplied by 10.
 * For example, if the required CL C version is 1.1, then the
 * \c required_version_times_10 should be 11.
 */
void piglit_cl_require_device_cl_c_version(cl_device_id device,
                                           int required_version_times_10);

/**
 * \brief Get platform information.
 *
 * \warning Returned data must be freed by the caller.
 *
 * \note
 * Although the returned types of all params are of type char all through
 * the last version of OpenCL (1.2 as of time of writing), the return type
 * of this function is void* for future compatibility.
 */
void* piglit_cl_get_platform_info(cl_platform_id platform,
                                  cl_platform_info param);

/**
 * \brief Get device information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_device_info(cl_device_id device, cl_device_info param);

/**
 * \brief Get context information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_context_info(cl_context context, cl_context_info param);

/**
 * \brief Get command queue information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_command_queue_info(cl_command_queue command_queue,
                                       cl_command_queue_info param);

/**
 * \brief Get memory object information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_mem_object_info(cl_mem mem_obj, cl_mem_info param);

/**
 * \brief Get image information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_image_info(cl_mem image, cl_image_info param);

/**
 * \brief Get sampler information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_sampler_info(cl_sampler sampler, cl_sampler_info param);

/**
 * \brief Get program information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_program_info(cl_program program, cl_program_info param);

/**
 * \brief Get program build information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_program_build_info(cl_program program,
                                       cl_device_id device,
                                       cl_program_build_info param);

/**
 * \brief Get kernel information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_kernel_info(cl_kernel kernel, cl_mem_info param);

/**
 * \brief Get kernel work group information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_kernel_work_group_info(cl_kernel kernel,
                                           cl_device_id device,
                                           cl_mem_info param);

/**
 * \brief Get event information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_event_info(cl_event event, cl_event_info param);

/**
 * \brief Get profiling information.
 *
 * \warning Returned data must be freed by the caller.
 */
void* piglit_cl_get_event_profiling_info(cl_event event,
                                         cl_profiling_info param);

/* Extensions */

/**
 * \brief Check if platform extension is supported
 *
 * \pre name is not null
 */
bool piglit_cl_is_platform_extension_supported(cl_platform_id platform,
                                               const char *name);

/**
 * \brief Check for required OpenCL platform extension and possibly
 * terminate the test.
 */
void piglit_cl_require_platform_extension(cl_platform_id platform,
                                          const char *name);

/**
 * \brief Check for not required OpenCL platform extension and possibly
 * terminate the test.
 */
void piglit_cl_require_not_platform_extension(cl_platform_id platform,
                                              const char *name);

/**
 * \brief Check if device extension is supported
 *
 * \pre name is not null
 */
bool piglit_cl_is_device_extension_supported(cl_device_id device,
                                             const char *name);

/**
 * \brief Check for required OpenCL device extension and possibly
 * terminate the test.
 */
void piglit_cl_require_device_extension(cl_device_id device, const char *name);

/**
 * \brief Check for not required OpenCL device extension and possibly
 * terminate the test.
 */
void piglit_cl_require_not_device_extension(cl_device_id device,
                                            const char *name);

/* Helper functions */

/**
 * \brief Get all available platforms.
 *
 * \warning Caller must free the allocated platform array.
 *
 * @param platform_ids  Address to store a pointer to platform ids list.
 * @return              Number of stored platform ids.
 */
unsigned int piglit_cl_get_platform_ids(cl_platform_id** platform_ids);

/**
 * \brief Get all available devices on platform \c platform_id.
 *
 * \warning Caller must free the allocated device array.
 *
 * @param platform_id   Platform from which to get platforms.
 * @param device_type   A bitfield to filter device types.
 * @param device_ids    Address to store a pointer to device ids list.
 * @return              Number of stored device ids.
 */
unsigned int piglit_cl_get_device_ids(cl_platform_id platform_id,
                                      cl_device_type device_type,
                                      cl_device_id** device_ids);

/**
 * \brief Helper context.
 *
 * Helper context struct for easier OpenCL context manipulation.
 */
struct _piglit_cl_context {
	cl_platform_id platform_id; /**< Platform used to create context. */
	cl_context cl_ctx; /**< OpenCL context. */

	unsigned int num_devices; /**< Number of members in \c device_ids and \c
	                               command_queues */

	cl_device_id* device_ids; /**< Device ids available in the context. */
	cl_command_queue* command_queues; /**< Command queues available in the
	                                       context.  Each command queue is
	                                       assigned to device id in \c
	                                       device_ids with the same index. */
};
typedef struct _piglit_cl_context* piglit_cl_context;

/**
 * \brief Create \c piglit_cl_context
 *
 * Create a helper context from platform id \c platform_id and
 * device ids \c device_ids.
 *
 * @param context      Context struct to fill.
 * @param platform_id  Platform from which to create context.
 * @param device_ids   Device ids to add to context.
 * @param num_devices  Number of members in \c device_ids.
 * @return             Return \c true on success.
 */
piglit_cl_context
piglit_cl_create_context(cl_platform_id platform_id,
                         const cl_device_id device_ids[],
                         unsigned int num_devices);

/**
 * \brief Release \c piglit_cl_context
 *
 * Free memory used by \c context and release the generated context
 * and memory queues.
 *
 * @param context  Context to release.
 */
void
piglit_cl_release_context(piglit_cl_context context);

/**
 * \brief Create and build a program with source.
 *
 * Create and build a program with source for all devices in
 * \c piglit_cl_context.
 *
 * @param context      Context on which to create and build program.
 * @param count        Number of strings in \c strings.
 * @param string       Array of pointers to NULL-terminated source strings.
 * @param options      NULL-terminated string that describes build options.
 * @return             Built program or NULL on fail.
 */
cl_program
piglit_cl_build_program_with_source(piglit_cl_context context,
                                    cl_uint count,
                                    char** strings,
                                    const char* options);

/**
 * \brief Create and try to build a program with invalid source.
 *
 * Create and try to build a program with invalid source for all devices
 * in \c piglit_cl_context.
 *
 * @param context      Context on which to create and build program.
 * @param count        Number of strings in \c strings.
 * @param string       Array of pointers to NULL-terminated source strings.
 * @param options      NULL-terminated string that describes build options.
 * @return             Unsuccessfully built program or NULL on fail.
 */
cl_program
piglit_cl_fail_build_program_with_source(piglit_cl_context context,
                                         cl_uint count,
                                         char** strings,
                                         const char* options);

/**
 * \brief Create and build a program with binary.
 *
 * Create and build aprogram with binary for all devices in
 * \c piglit_cl_context.
 *
 * @param context      Context on which to create and build program.
 * @param lenghts      Lenghts of binaries in \c binaries.
 * @param binaries     Array of pointers to binaries.
 * @param options      NULL-terminated string that describes build options.
 * @return             Built program or NULL on fail.
 */
cl_program
piglit_cl_build_program_with_binary(piglit_cl_context context,
                                    size_t* lenghts,
                                    unsigned char** binaries,
                                    const char* options);

/**
 * \brief Create and try to build a program with invalid binary.
 *
 * Create and try to build a program with invalid binary for all devices
 * in \c piglit_cl_context.
 *
 * @param context      Context on which to create and build program.
 * @param lenghts      Lenghts of binaries in \c binaries.
 * @param binaries     Array of pointers to binaries.
 * @param options      NULL-terminated string that describes build options.
 * @return             Unsuccessfully built program or NULL on fail.
 */
cl_program
piglit_cl_fail_build_program_with_binary(piglit_cl_context context,
                                         size_t* lenghts,
                                         unsigned char** binaries,
                                         const char* options);

/**
 * \brief Create a buffer.
 *
 * @param context      Context on which to create buffer.
 * @param flags        Memory flags.
 * @param size         Size of created buffer.
 * @return             Created buffer or NULL on fail.
 */
cl_mem
piglit_cl_create_buffer(piglit_cl_context context,
                        cl_mem_flags flags,
                        size_t size);

/**
 * \brief Blocking write to a buffer.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param buffer         Memory buffer to write to.
 * @param offset         Offset in buffer.
 * @param cb             Size of data in bytes.
 * @param ptr            Pointer to data to be written to buffer.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_write_buffer(cl_command_queue command_queue,
                       cl_mem buffer,
                       size_t offset,
                       size_t cb,
                       const void *ptr);

/**
 * \brief Blocking write to a whole buffer.
 *
 * \warning \c ptr must point to memory space which is equal or larger
 * in size than \c buffer.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param buffer         Memory buffer to write to.
 * @param ptr            Pointer to data to be written to buffer.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_write_whole_buffer(cl_command_queue command_queue,
                             cl_mem buffer,
                             const void *ptr);

/**
 * \brief Blocking read from a buffer.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param buffer         Memory buffer to read from.
 * @param offset         Offset in buffer.
 * @param cb             Size of data in bytes.
 * @param ptr            Pointer to data to be written from buffer.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_read_buffer(cl_command_queue command_queue,
                      cl_mem buffer,
                      size_t offset,
                      size_t cb,
                      void *ptr);

/**
 * \brief Blocking read from a whole buffer.
 *
 * \warning \c ptr must point to memory space which is equal or larger
 * in size than \c buffer.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param buffer         Memory buffer to read from.
 * @param ptr            Pointer to data to be written from buffer.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_read_whole_buffer(cl_command_queue command_queue,
                            cl_mem buffer,
                            void *ptr);
#ifdef CL_VERSION_1_2
typedef cl_image_desc piglit_image_desc;
#else
/** Taken from OpenCL 1.2 specs 5.3.1.2 */
typedef struct {
	cl_mem_object_type image_type;
	size_t             image_width;
	size_t             image_height;
	size_t             image_depth;
	size_t             image_array_size;
	size_t             image_row_pitch;
	size_t             image_slice_pitch;
	cl_uint            num_mip_levels;
	cl_uint            num_samples;
	cl_mem             buffer;
} piglit_image_desc;
#endif

/**
 * \brief Get context image support.
 *
 * @param context      Context on which to create image.
 * @return             True if there is one device with image support.
 */
bool
piglit_cl_get_context_image_support(const piglit_cl_context context);

/**
 * \brief Get device image support.
 *
 * @param device       Context on which to create image.
 * @return             True if there the device has image support.
 */
bool
piglit_cl_get_device_image_support(cl_device_id device);


/**
 * \brief Create an image.
 *
 * @param context      Context on which to create image.
 * @param flags        Memory flags.
 * @param format       Image format.
 * @param desc         Image descriptor.
 * @return             Created image or NULL on fail.
 */
cl_mem
piglit_cl_create_image(piglit_cl_context context,
                       cl_mem_flags flags,
                       const cl_image_format *format,
                       const piglit_image_desc *desc);

/**
 * \brief Blocking write to an image.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param image          Image to write to.
 * @param origin         (x, y, z) offset in pixels.
 * @param region         (width, height, depht) size in pixels.
 * @param ptr            Pointer to data to be written to image.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_write_image(cl_command_queue command_queue,
                      cl_mem image,
                      const size_t *origin,
                      const size_t *region,
                      const void *ptr);

/**
 * \brief Blocking write to the entire area of an image.
 *
 * \warning \c ptr must point to memory space which is equal or larger
 * in size than \c image.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param image          Image to write to.
 * @param ptr            Pointer to data to be written to image.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_write_whole_image(cl_command_queue command_queue,
                            cl_mem image,
                            const void *ptr);

/**
 * \brief Blocking read from an image.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param image          Image to read from.
 * @param origin         (x, y, z) offset in pixels.
 * @param region         (width, height, depht) size in pixels.
 * @param ptr            Pointer to data read from image.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_read_image(cl_command_queue command_queue,
                     cl_mem image,
                     const size_t *origin,
                     const size_t *region,
                     void *ptr);

/**
 * \brief Blocking read of the full contents of an image.
 *
 * \warning \c ptr must point to memory space which is equal or larger
 * in size than \c image.
 *
 * @param command_queue  Command queue to enqueue operation on.
 * @param image          Image to read from.
 * @param ptr            Pointer to data read from image.
 * @return               \c true on succes, \c false otherwise.
 */
bool
piglit_cl_read_whole_image(cl_command_queue command_queue,
                           cl_mem image,
                           void *ptr);

/**
 * \brief Create a sampler.
 *
 * @param context            Context on which to create image.
 * @param normalized_coords  Use normalized coords if true.
 * @param addressing_mode    Addressing mode.
 * @param filter_mode        Filter mode.
 * @return                   Created sampler or NULL on fail.
 */
cl_sampler
piglit_cl_create_sampler(piglit_cl_context context,
                         cl_bool normalized_coords,
                         cl_addressing_mode addressing_mode,
                         cl_filter_mode filter_mode);

/**
 * \brief Create a kernel.
 *
 * @param context      Program on which to create a kernel.
 * @param kernel_name  Kernel name.
 * @return             Created kernel or NULL on fail.
 */
cl_kernel
piglit_cl_create_kernel(cl_program program, const char* kernel_name);

/**
 * \brief Set kernel argument.
 *
 * @param kernel       Kernel for which to set an argument.
 * @param arg_index    Argument index.
 * @param size         Size of argument.
 * @param arg_value    Pointer to argument value.
 * @return             \c true on succes, \c false otherwise.
 */
bool
piglit_cl_set_kernel_arg(cl_kernel kernel,
                         cl_uint arg_index,
                         size_t size,
                         const void* arg_value);

/**
 * \brief Set kernel buffer argument.
 *
 * @param kernel       Kernel for which to set an buffer argument.
 * @param arg_index    Argument index.
 * @param buffer       Buffer to be set as argument.
 * @return             \c true on succes, \c false otherwise.
 */
bool
piglit_cl_set_kernel_buffer_arg(cl_kernel kernel,
                                cl_uint arg_index,
                                cl_mem *buffer);

/**
 * \brief Enqueue ND-range kernel.
 *
 * @param command_queue     Command queue to enqueue operation on.
 * @param kernel            Kernel to be enqueued.
 * @param work_dim          Work dimensions.
 * @param global_offset     Global offset.
 * @param global_work_size  Global work sizes.
 * @param local_work_size   Local work sizes.
 * @return                  \c true on succes, \c false otherwise.
 */
bool
piglit_cl_enqueue_ND_range_kernel(cl_command_queue command_queue,
                                  cl_kernel kernel,
                                  cl_uint work_dim,
                                  const size_t* global_offset,
                                  const size_t* global_work_size,
                                  const size_t* local_work_size);

/**
 * \brief Enqueue ND-range kernel and wait it to complete.
 *
 * @param command_queue     Command queue to enqueue operation on.
 * @param kernel            Kernel to be enqueued.
 * @param work_dim          Work dimensions.
 * @param global_offset     Global offset.
 * @param global_work_size  Global work sizes.
 * @param local_work_size   Local work sizes.
 * @return                  \c true on succes, \c false otherwise.
 */
bool
piglit_cl_execute_ND_range_kernel(cl_command_queue command_queue,
                                  cl_kernel kernel,
                                  cl_uint work_dim,
                                  const size_t* global_offset,
                                  const size_t* global_work_size,
                                  const size_t* local_work_size);

/**
 * \brief Enqueue kernel task.
 *
 * @param command_queue     Command queue to enqueue operation on.
 * @param kernel            Kernel to be enqueued.
 * @return                  \c true on succes, \c false otherwise.
 */
bool
piglit_cl_enqueue_task(cl_command_queue command_queue, cl_kernel kernel);

/**
 * \brief Enqueue kernel task and wait it to complete.
 *
 * @param command_queue     Command queue to enqueue operation on.
 * @param kernel            Kernel to be enqueued.
 * @return                  \c true on succes, \c false otherwise.
 */
bool
piglit_cl_execute_task(cl_command_queue command_queue, cl_kernel kernel);

#ifdef __cplusplus
} /* end extern "C" */
#endif

#endif //PIGLIT_UTIL_CL_H