-
Notifications
You must be signed in to change notification settings - Fork 1
/
cl.hpp
12934 lines (11701 loc) · 292 KB
/
cl.hpp
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
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2008-2015 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE 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
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
******************************************************************************/
/*! \file
*
* \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and
* OpenCL 1.2 (rev 15)
* \author Benedict R. Gaster, Laurent Morichetti and Lee Howes
*
* Additions and fixes from:
* Brian Cole, March 3rd 2010 and April 2012
* Matt Gruenke, April 2012.
* Bruce Merry, February 2013.
* Tom Deakin and Simon McIntosh-Smith, July 2013
*
* \version 1.2.8
* \date October 2015
*
* Optional extension support
*
* cl
* cl_ext_device_fission
* #define USE_CL_DEVICE_FISSION
*/
/*! \mainpage
* \section intro Introduction
* For many large applications C++ is the language of choice and so it seems
* reasonable to define C++ bindings for OpenCL.
*
*
* The interface is contained with a single C++ header file \em cl.hpp and all
* definitions are contained within the namespace \em cl. There is no additional
* requirement to include \em cl.h and to use either the C++ or original C
* bindings it is enough to simply include \em cl.hpp.
*
* The bindings themselves are lightweight and correspond closely to the
* underlying C API. Using the C++ bindings introduces no additional execution
* overhead.
*
* For detail documentation on the bindings see:
*
* The OpenCL C++ Wrapper API 1.2 (revision 09)
* http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf
*
* \section example Example
*
* The following example shows a general use case for the C++
* bindings, including support for the optional exception feature and
* also the supplied vector and string classes, see following sections for
* decriptions of these features.
*
* \code
* #define __CL_ENABLE_EXCEPTIONS
*
* #if defined(__APPLE__) || defined(__MACOSX)
* #include <OpenCL/cl.hpp>
* #else
* #include <CL/cl.hpp>
* #endif
* #include <cstdio>
* #include <cstdlib>
* #include <iostream>
*
* const char * helloStr = "__kernel void "
* "hello(void) "
* "{ "
* " "
* "} ";
*
* int
* main(void)
* {
* cl_int err = CL_SUCCESS;
* try {
*
* std::vector<cl::Platform> platforms;
* cl::Platform::get(&platforms);
* if (platforms.size() == 0) {
* std::cout << "Platform size 0\n";
* return -1;
* }
*
* cl_context_properties properties[] =
* { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
* cl::Context context(CL_DEVICE_TYPE_CPU, properties);
*
* std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
*
* cl::Program::Sources source(1,
* std::make_pair(helloStr,strlen(helloStr)));
* cl::Program program_ = cl::Program(context, source);
* program_.build(devices);
*
* cl::Kernel kernel(program_, "hello", &err);
*
* cl::Event event;
* cl::CommandQueue queue(context, devices[0], 0, &err);
* queue.enqueueNDRangeKernel(
* kernel,
* cl::NullRange,
* cl::NDRange(4,4),
* cl::NullRange,
* NULL,
* &event);
*
* event.wait();
* }
* catch (cl::Error err) {
* std::cerr
* << "ERROR: "
* << err.what()
* << "("
* << err.err()
* << ")"
* << std::endl;
* }
*
* return EXIT_SUCCESS;
* }
*
* \endcode
*
*/
#ifndef CL_HPP_
#define CL_HPP_
#ifdef _WIN32
#include <malloc.h>
#if defined(USE_DX_INTEROP)
#include <CL/cl_d3d10.h>
#include <CL/cl_dx9_media_sharing.h>
#endif
#endif // _WIN32
#if defined(_MSC_VER)
#include <intrin.h>
#endif // _MSC_VER
//
#if defined(USE_CL_DEVICE_FISSION)
#include <CL/cl_ext.h>
#endif
#if defined(__APPLE__) || defined(__MACOSX)
#include <OpenCL/opencl.h>
#else
#include <CL/opencl.h>
#endif // !__APPLE__
#if (_MSC_VER >= 1700) || (__cplusplus >= 201103L)
#define CL_HPP_RVALUE_REFERENCES_SUPPORTED
#define CL_HPP_CPP11_ATOMICS_SUPPORTED
#include <atomic>
#endif
#if (__cplusplus >= 201103L)
#define CL_HPP_NOEXCEPT noexcept
#else
#define CL_HPP_NOEXCEPT
#endif
// To avoid accidentally taking ownership of core OpenCL types
// such as cl_kernel constructors are made explicit
// under OpenCL 1.2
#if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
#define __CL_EXPLICIT_CONSTRUCTORS explicit
#else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
#define __CL_EXPLICIT_CONSTRUCTORS
#endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
// Define deprecated prefixes and suffixes to ensure compilation
// in case they are not pre-defined
#if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
#define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
#if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
#define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
#endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
#if !defined(CL_CALLBACK)
#define CL_CALLBACK
#endif //CL_CALLBACK
#include <utility>
#include <limits>
#include <iterator>
#if defined(__CL_ENABLE_EXCEPTIONS)
#include <exception>
#endif // #if defined(__CL_ENABLE_EXCEPTIONS)
#if !defined(__NO_STD_VECTOR)
#include <vector>
#endif
#if !defined(__NO_STD_STRING)
#include <string>
#endif
#if defined(__ANDROID__) || defined(linux) || defined(__APPLE__) || defined(__MACOSX)
#include <alloca.h>
#endif // linux
#include <cstring>
/*! \namespace cl
*
* \brief The OpenCL C++ bindings are defined within this namespace.
*
*/
namespace cl {
class Memory;
/**
* Deprecated APIs for 1.2
*/
#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
#define __INIT_CL_EXT_FCN_PTR(name) \
if(!pfn_##name) { \
pfn_##name = (PFN_##name) \
clGetExtensionFunctionAddress(#name); \
if(!pfn_##name) { \
} \
}
#endif // #if defined(CL_VERSION_1_1)
#if defined(CL_VERSION_1_2)
#define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \
if(!pfn_##name) { \
pfn_##name = (PFN_##name) \
clGetExtensionFunctionAddressForPlatform(platform, #name); \
if(!pfn_##name) { \
} \
}
#endif // #if defined(CL_VERSION_1_1)
class Program;
class Device;
class Context;
class CommandQueue;
class Memory;
class Buffer;
#if defined(__CL_ENABLE_EXCEPTIONS)
/*! \brief Exception class
*
* This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined.
*/
class Error : public std::exception
{
private:
cl_int err_;
const char * errStr_;
public:
/*! \brief Create a new CL error exception for a given error code
* and corresponding message.
*
* \param err error code value.
*
* \param errStr a descriptive string that must remain in scope until
* handling of the exception has concluded. If set, it
* will be returned by what().
*/
Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
{}
~Error() throw() {}
/*! \brief Get error string associated with exception
*
* \return A memory pointer to the error message string.
*/
virtual const char * what() const throw ()
{
if (errStr_ == NULL) {
return "empty";
}
else {
return errStr_;
}
}
/*! \brief Get error code associated with exception
*
* \return The error code.
*/
cl_int err(void) const { return err_; }
};
#define __ERR_STR(x) #x
#else
#define __ERR_STR(x) NULL
#endif // __CL_ENABLE_EXCEPTIONS
namespace detail
{
#if defined(__CL_ENABLE_EXCEPTIONS)
static inline cl_int errHandler (
cl_int err,
const char * errStr = NULL)
{
if (err != CL_SUCCESS) {
throw Error(err, errStr);
}
return err;
}
#else
static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
{
(void) errStr; // suppress unused variable warning
return err;
}
#endif // __CL_ENABLE_EXCEPTIONS
}
//! \cond DOXYGEN_DETAIL
#if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
#define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo)
#define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
#define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
#define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
#define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
#define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
#define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
#define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
#define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
#define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
#define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
#if defined(CL_VERSION_1_2)
#define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo)
#endif // #if defined(CL_VERSION_1_2)
#define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
#define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
#define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
#define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
#define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext)
#define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
#define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
#define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
#define __COPY_ERR __ERR_STR(cl::copy)
#define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
#define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
#define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
#define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
#if defined(CL_VERSION_1_2)
#define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage)
#define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture)
#define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions)
#endif // #if defined(CL_VERSION_1_2)
#define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
#define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
#define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
#define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
#define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
#define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
#define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
#define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
#define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
#define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
#if defined(CL_VERSION_1_2)
#define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels)
#endif // #if defined(CL_VERSION_1_2)
#define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
#if defined(CL_VERSION_1_2)
#define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram)
#define __LINK_PROGRAM_ERR __ERR_STR(clLinkProgram)
#endif // #if defined(CL_VERSION_1_2)
#define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
#define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
#define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
#define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
#define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
#define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
#define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
#define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
#define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
#define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer)
#define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
#define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
#define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
#define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage)
#define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
#define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
#define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
#define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
#define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
#define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
#define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
#define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
#if defined(CL_VERSION_1_2)
#define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects)
#endif // #if defined(CL_VERSION_1_2)
#define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
#define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
#define __RETAIN_ERR __ERR_STR(Retain Object)
#define __RELEASE_ERR __ERR_STR(Release Object)
#define __FLUSH_ERR __ERR_STR(clFlush)
#define __FINISH_ERR __ERR_STR(clFinish)
#define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error)
/**
* CL 1.2 version that uses device fission.
*/
#if defined(CL_VERSION_1_2)
#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices)
#else
#define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
#endif // #if defined(CL_VERSION_1_2)
/**
* Deprecated APIs for 1.2
*/
#if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
#define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
#define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
#define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
#define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
#define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D)
#define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D)
#define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
#define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
#endif // #if defined(CL_VERSION_1_1)
#endif // __CL_USER_OVERRIDE_ERROR_STRINGS
//! \endcond
/**
* CL 1.2 marker and barrier commands
*/
#if defined(CL_VERSION_1_2)
#define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList)
#define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList)
#endif // #if defined(CL_VERSION_1_2)
#if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
typedef std::string STRING_CLASS;
#elif !defined(__USE_DEV_STRING)
/*! \class string
* \brief Simple string class, that provides a limited subset of std::string
* functionality but avoids many of the issues that come with that class.
* \note Deprecated. Please use std::string as default or
* re-define the string class to match the std::string
* interface by defining STRING_CLASS
*/
class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
{
private:
::size_t size_;
char * str_;
public:
//! \brief Constructs an empty string, allocating no memory.
string(void) : size_(0), str_(NULL)
{
}
/*! \brief Constructs a string populated from an arbitrary value of
* specified size.
*
* An extra '\0' is added, in case none was contained in str.
*
* \param str the initial value of the string instance. Note that '\0'
* characters receive no special treatment. If NULL,
* the string is left empty, with a size of 0.
*
* \param size the number of characters to copy from str.
*/
string(const char * str, ::size_t size) :
size_(size),
str_(NULL)
{
if( size > 0 ) {
str_ = new char[size_+1];
if (str_ != NULL) {
memcpy(str_, str, size_ * sizeof(char));
str_[size_] = '\0';
}
else {
size_ = 0;
}
}
}
/*! \brief Constructs a string populated from a null-terminated value.
*
* \param str the null-terminated initial value of the string instance.
* If NULL, the string is left empty, with a size of 0.
*/
string(const char * str) :
size_(0),
str_(NULL)
{
if( str ) {
size_= ::strlen(str);
}
if( size_ > 0 ) {
str_ = new char[size_ + 1];
if (str_ != NULL) {
memcpy(str_, str, (size_ + 1) * sizeof(char));
}
}
}
void resize( ::size_t n )
{
if( size_ == n ) {
return;
}
if (n == 0) {
if( str_ ) {
delete [] str_;
}
str_ = NULL;
size_ = 0;
}
else {
char *newString = new char[n + 1];
::size_t copySize = n;
if( size_ < n ) {
copySize = size_;
}
size_ = n;
if(str_) {
memcpy(newString, str_, (copySize + 1) * sizeof(char));
}
if( copySize < size_ ) {
memset(newString + copySize, 0, size_ - copySize);
}
newString[size_] = '\0';
delete [] str_;
str_ = newString;
}
}
const char& operator[] ( ::size_t pos ) const
{
return str_[pos];
}
char& operator[] ( ::size_t pos )
{
return str_[pos];
}
/*! \brief Copies the value of another string to this one.
*
* \param rhs the string to copy.
*
* \returns a reference to the modified instance.
*/
string& operator=(const string& rhs)
{
if (this == &rhs) {
return *this;
}
if( str_ != NULL ) {
delete [] str_;
str_ = NULL;
size_ = 0;
}
if (rhs.size_ == 0 || rhs.str_ == NULL) {
str_ = NULL;
size_ = 0;
}
else {
str_ = new char[rhs.size_ + 1];
size_ = rhs.size_;
if (str_ != NULL) {
memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
}
else {
size_ = 0;
}
}
return *this;
}
/*! \brief Constructs a string by copying the value of another instance.
*
* \param rhs the string to copy.
*/
string(const string& rhs) :
size_(0),
str_(NULL)
{
*this = rhs;
}
//! \brief Destructor - frees memory used to hold the current value.
~string()
{
delete[] str_;
str_ = NULL;
}
//! \brief Queries the length of the string, excluding any added '\0's.
::size_t size(void) const { return size_; }
//! \brief Queries the length of the string, excluding any added '\0's.
::size_t length(void) const { return size(); }
/*! \brief Returns a pointer to the private copy held by this instance,
* or "" if empty/unset.
*/
const char * c_str(void) const { return (str_) ? str_ : "";}
};
typedef cl::string STRING_CLASS;
#endif // #elif !defined(__USE_DEV_STRING)
#if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
#define VECTOR_CLASS std::vector
#elif !defined(__USE_DEV_VECTOR)
#define VECTOR_CLASS cl::vector
#if !defined(__MAX_DEFAULT_VECTOR_SIZE)
#define __MAX_DEFAULT_VECTOR_SIZE 10
#endif
/*! \class vector
* \brief Fixed sized vector implementation that mirroring
*
* \note Deprecated. Please use std::vector as default or
* re-define the vector class to match the std::vector
* interface by defining VECTOR_CLASS
* \note Not recommended for use with custom objects as
* current implementation will construct N elements
*
* std::vector functionality.
* \brief Fixed sized vector compatible with std::vector.
*
* \note
* This differs from std::vector<> not just in memory allocation,
* but also in terms of when members are constructed, destroyed,
* and assigned instead of being copy constructed.
*
* \param T type of element contained in the vector.
*
* \param N maximum size of the vector.
*/
template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector
{
private:
T data_[N];
unsigned int size_;
public:
//! \brief Constructs an empty vector with no memory allocated.
vector() :
size_(static_cast<unsigned int>(0))
{}
//! \brief Deallocates the vector's memory and destroys all of its elements.
~vector()
{
clear();
}
//! \brief Returns the number of elements currently contained.
unsigned int size(void) const
{
return size_;
}
/*! \brief Empties the vector of all elements.
* \note
* This does not deallocate memory but will invoke destructors
* on contained elements.
*/
void clear()
{
while(!empty()) {
pop_back();
}
}
/*! \brief Appends an element after the last valid element.
* Calling this on a vector that has reached capacity will throw an
* exception if exceptions are enabled.
*/
void push_back (const T& x)
{
if (size() < N) {
new (&data_[size_]) T(x);
size_++;
} else {
detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
}
}
/*! \brief Removes the last valid element from the vector.
* Calling this on an empty vector will throw an exception
* if exceptions are enabled.
*/
void pop_back(void)
{
if (size_ != 0) {
--size_;
data_[size_].~T();
} else {
detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
}
}
/*! \brief Constructs with a value copied from another.
*
* \param vec the vector to copy.
*/
vector(const vector<T, N>& vec) :
size_(vec.size_)
{
if (size_ != 0) {
assign(vec.begin(), vec.end());
}
}
/*! \brief Constructs with a specified number of initial elements.
*
* \param size number of initial elements.
*
* \param val value of initial elements.
*/
vector(unsigned int size, const T& val = T()) :
size_(0)
{
for (unsigned int i = 0; i < size; i++) {
push_back(val);
}
}
/*! \brief Overwrites the current content with that copied from another
* instance.
*
* \param rhs vector to copy.
*
* \returns a reference to this.
*/
vector<T, N>& operator=(const vector<T, N>& rhs)
{
if (this == &rhs) {
return *this;
}
if (rhs.size_ != 0) {
assign(rhs.begin(), rhs.end());
} else {
clear();
}
return *this;
}
/*! \brief Tests equality against another instance.
*
* \param vec the vector against which to compare.
*/
bool operator==(vector<T,N> &vec)
{
if (size() != vec.size()) {
return false;
}
for( unsigned int i = 0; i < size(); ++i ) {
if( operator[](i) != vec[i] ) {
return false;
}
}
return true;
}
//! \brief Conversion operator to T*.
operator T* () { return data_; }
//! \brief Conversion operator to const T*.
operator const T* () const { return data_; }
//! \brief Tests whether this instance has any elements.
bool empty (void) const
{
return size_==0;
}
//! \brief Returns the maximum number of elements this instance can hold.
unsigned int max_size (void) const
{
return N;
}
//! \brief Returns the maximum number of elements this instance can hold.
unsigned int capacity () const
{
return N;
}
//! \brief Resizes the vector to the given size
void resize(unsigned int newSize, T fill = T())
{
if (newSize > N)
{
detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
}
else
{
while (size_ < newSize)
{
new (&data_[size_]) T(fill);
size_++;
}
while (size_ > newSize)
{
--size_;
data_[size_].~T();
}
}
}
/*! \brief Returns a reference to a given element.
*
* \param index which element to access. *
* \note
* The caller is responsible for ensuring index is >= 0 and < size().
*/
T& operator[](int index)
{
return data_[index];
}
/*! \brief Returns a const reference to a given element.
*
* \param index which element to access.
*
* \note
* The caller is responsible for ensuring index is >= 0 and < size().
*/
const T& operator[](int index) const
{
return data_[index];
}
/*! \brief Assigns elements of the vector based on a source iterator range.
*
* \param start Beginning iterator of source range
* \param end Enditerator of source range
*
* \note
* Will throw an exception if exceptions are enabled and size exceeded.
*/
template<class I>
void assign(I start, I end)
{
clear();
while(start != end) {
push_back(*start);
start++;
}
}
/*! \class iterator
* \brief Const iterator class for vectors
*/
class iterator
{
private:
const vector<T,N> *vec_;
int index_;
/**
* Internal iterator constructor to capture reference
* to the vector it iterates over rather than taking
* the vector by copy.
*/
iterator (const vector<T,N> &vec, int index) :
vec_(&vec)
{
if( !vec.empty() ) {
index_ = index;
} else {
index_ = -1;
}
}
public:
iterator(void) :
index_(-1),
vec_(NULL)
{
}
iterator(const iterator& rhs) :
vec_(rhs.vec_),
index_(rhs.index_)
{
}
~iterator(void) {}
static iterator begin(const cl::vector<T,N> &vec)
{
iterator i(vec, 0);
return i;
}
static iterator end(const cl::vector<T,N> &vec)
{
iterator i(vec, vec.size());
return i;
}
bool operator==(iterator i)
{
return ((vec_ == i.vec_) &&
(index_ == i.index_));
}
bool operator!=(iterator i)
{
return (!(*this==i));
}
iterator& operator++()
{
++index_;
return *this;
}
iterator operator++(int)
{
iterator retVal(*this);
++index_;
return retVal;
}
iterator& operator--()
{
--index_;
return *this;
}
iterator operator--(int)
{
iterator retVal(*this);
--index_;
return retVal;
}
const T& operator *() const
{
return (*vec_)[index_];
}
};
iterator begin(void)
{