-
Notifications
You must be signed in to change notification settings - Fork 4
/
clcontextwrapper.cpp
780 lines (644 loc) · 21.8 KB
/
clcontextwrapper.cpp
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
#include "clcontextwrapper.h"
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#if __APPLE__
#include <OpenCL/cl.h>
#include <OpenCL/cl_ext.h>
#include <OpenCL/gcl.h>
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#include <OpenGL/CGLContext.h>
#include <OpenGL/CGLCurrent.h>
#endif
#if !defined(SAG_COM) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
#include <CL/opencl.h>
#include <CL/cl_ext.h>
#include <CL/cl_gl_ext.h>
#include <Windows.h>
#include <gl/GL.h>
typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)(
const cl_context_properties *properties,
cl_gl_context_info param_name,
size_t param_value_size,
void *param_value,
size_t *param_value_size_ret);
#define clGetGLContextInfoKHR clGetGLContextInfoKHR_proc
static clGetGLContextInfoKHR_fn clGetGLContextInfoKHR;
#endif
#include <timer.h>
static std::string getError(cl_int error);
static inline void logError(const std::string & error, const std::string & errorDetail );
struct KernelInfo
{
cl_kernel kernel;
size_t workGroupSize;
unsigned long localMemSize;
};
struct CLContextWrapperPrivate
{
cl_context context;
cl_command_queue commandQueue;
cl_device_id deviceId;
cl_program computeProgram;
size_t maxWorkGroupSize;
std::unordered_map<std::string, KernelInfo> kernels;
std::unordered_set<cl_mem> buffers;
bool setKernelArg(cl_kernel kernel, KernelArg arg, int index)
{
cl_uint uindex = static_cast<cl_uint>(index);
int err = clSetKernelArg(kernel, uindex, arg.byteSize, arg.data);
if(err)
{
logError("Error: Failed to set kernel arg!", getError(err));
return false;
}
return true;
}
};
static std::string getError(cl_int error)
{
switch (error)
{
case CL_SUCCESS:
return "Success";
case CL_INVALID_CONTEXT:
return "Invalid Context";
case CL_INVALID_VALUE:
return "Invalid Value";
case CL_INVALID_BUFFER_SIZE:
return "Invalid Buffer Size";
case CL_INVALID_HOST_PTR:
return "Invalid Host Pointer";
case CL_MEM_OBJECT_ALLOCATION_FAILURE:
return "Failure to allocate memory for object";
case CL_OUT_OF_RESOURCES:
return "Out of resources";
case CL_OUT_OF_HOST_MEMORY:
return "Out of host memory";
case CL_INVALID_PROGRAM_EXECUTABLE:
return "Invalid Program Executable";
case CL_INVALID_COMMAND_QUEUE:
return "Invalid Command Queue";
case CL_INVALID_KERNEL:
return "Invalid Kernel";
case CL_INVALID_KERNEL_ARGS:
return "Invalid Kernel Arguments";
case CL_INVALID_WORK_DIMENSION:
return "Invalid Work Dimension";
case CL_INVALID_PLATFORM:
return "Invalid Platform";
case CL_DEVICE_NOT_FOUND:
return "Device not found";
case CL_INVALID_DEVICE_TYPE:
return "Invalid Device type";
case CL_INVALID_WORK_GROUP_SIZE:
return "Invalid work group size";
case CL_INVALID_WORK_ITEM_SIZE:
return "Invalid work item size";
case CL_INVALID_GLOBAL_OFFSET:
return "Invalid Global Offset";
case CL_INVALID_EVENT_WAIT_LIST:
return "Invalid Event Wait List";
case CL_INVALID_GLOBAL_WORK_SIZE:
return "Invalid Global Work Size";
case CL_INVALID_GL_OBJECT:
return "Invalid OpenGL Object";
case CL_INVALID_MEM_OBJECT:
return "Invalid Mem Object. (Invalid Buffer)";
case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
return "Invalid Image Format Descriptor";
case CL_INVALID_ARG_SIZE:
return "Invalid Arg Size";
case CL_BUILD_PROGRAM_FAILURE:
return "Build program Failure";
case CL_INVALID_KERNEL_NAME:
return "Invalid Kernel Name";
case CL_INVALID_ARG_VALUE:
return "Invalid Argument Value";
case CL_INVALID_ARG_INDEX:
return "Invalid Argument Index";
default:
{
std::stringstream ss;
ss << "Erro number : " << std::to_string(error);
return ss.str();
}
}
}
static inline cl_mem_flags getMemFlags(BufferType type)
{
switch (type) {
case BufferType::READ_ONLY:
return CL_MEM_READ_ONLY;
break;
case BufferType::WRITE_ONLY:
return CL_MEM_WRITE_ONLY;
break;
case BufferType::READ_AND_WRITE:
return CL_MEM_READ_WRITE;
break;
default:
return CL_MEM_READ_WRITE;
break;
}
}
static inline void logError(const std::string & error, const std::string & errorDetail = "")
{
std::cout << error << std::endl;
std::cout << errorDetail << std::endl;
}
CLContextWrapper::CLContextWrapper() : _hasCreatedContext(false), _deviceType(DeviceType::NONE)
{
_this = new CLContextWrapperPrivate;
}
CLContextWrapper::~CLContextWrapper()
{
for(auto it : _this->kernels)
{
clReleaseKernel(it.second.kernel);
}
for(auto mem : _this->buffers)
{
clReleaseMemObject(mem);
}
if(_this->commandQueue)
{
clReleaseCommandQueue(_this->commandQueue);
}
if(_this->context)
{
clReleaseContext(_this->context);
}
delete _this;
}
bool CLContextWrapper::createContext(DeviceType deviceType)
{
// Check if has already created a context
if(_hasCreatedContext)
{
return false;
}
cl_int err = CL_SUCCESS;
// Get Platform
cl_uint numPlatforms = 0;
err = clGetPlatformIDs(0, nullptr, &numPlatforms);
if(numPlatforms == 0)
{
return false;
}
// Get the first found platform
cl_platform_id platform;
err = clGetPlatformIDs(1, &platform, nullptr);
if(err)
{
logError("Error: Failed get platorm id" , getError(err));
return false;
}
// Get Device Info
cl_device_type computeDeviceType = deviceType == DeviceType::GPU_DEVICE ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU; // for now, only these two types
cl_device_id computeDeviceId;
err = clGetDeviceIDs(platform, computeDeviceType, 1, &computeDeviceId, NULL);
if (err != CL_SUCCESS)
{
logError("Error: Failed to locate a compute device!" , getError(err));
return false;
}
size_t returnedSize = 0;
size_t maxWorkGroupSize = 0;
err = clGetDeviceInfo(computeDeviceId, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &maxWorkGroupSize, &returnedSize);
if (err != CL_SUCCESS)
{
logError("Error: Failed to retrieve device info!", getError(err));
return false;
}
cl_char vendorName[1024] = {0};
cl_char deviceName[1024] = {0};
err = clGetDeviceInfo(computeDeviceId, CL_DEVICE_VENDOR, sizeof(vendorName), vendorName, &returnedSize);
err|= clGetDeviceInfo(computeDeviceId, CL_DEVICE_NAME, sizeof(deviceName), deviceName, &returnedSize);
if (err != CL_SUCCESS)
{
logError("Error: Failed to retrieve device info!", getError(err));
return false;
}
std::cout << "Connecting to " << vendorName << " - " << deviceName << "..." << std::endl;
// Create Context
cl_context context = clCreateContext(0, 1, &computeDeviceId, NULL, NULL, &err);
if (!_this->context || err)
{
logError("Error: Failed to create a compute ComputeContext!", getError(err));
return false;
}
// Create Command Queue
cl_command_queue commandQueue = clCreateCommandQueue(context, computeDeviceId, 0, &err);
if (!_this->commandQueue)
{
logError("Error: Failed to create a command ComputeCommands!", getError(err));
return false;
}
_this->deviceId = computeDeviceId;
_this->context = context;
_this->commandQueue = commandQueue;
_this->maxWorkGroupSize = maxWorkGroupSize;
std::cout << "Successfully created OpenCL context " << std::endl;
_hasCreatedContext = true;
_deviceType = deviceType;
return true;
}
#if __APPLE__
bool CLContextWrapper::createContextWithOpengl()
{
cl_platform_id platform;
cl_int err = clGetPlatformIDs(1, &platform, nullptr);
if(err)
{
logError("Error: Failed get platorm id" , getError(err));
return false;
}
// Get Device Info
cl_device_id computeDeviceId;
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &computeDeviceId, NULL);
if (err != CL_SUCCESS)
{
logError("Error: Failed to locate a compute device!" , getError(err));
return false;
}
CGLContextObj kCGLContext = CGLGetCurrentContext();
CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
// Create CL context properties, add handle & share-group enum
cl_context_properties properties[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup, 0
};
// Create a context with device in the CGL share group
cl_context context = clCreateContext(properties, 0, &computeDeviceId, nullptr, 0, &err);
size_t returnedSize = 0;
size_t maxWorkGroupSize = 0;
err = clGetDeviceInfo(computeDeviceId, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &maxWorkGroupSize, &returnedSize);
if (err != CL_SUCCESS)
{
logError("Error: Failed to retrieve device info!", getError(err));
return false;
}
if(err)
{
logError("Error creating OpenCL shared with with shared Opengl", getError(err));
return false;
}
// Create Command Queue
auto commandQueue = clCreateCommandQueue(context, computeDeviceId, 0, &err);
if (!commandQueue)
{
logError("Error: Failed to create a command ComputeCommands with shared Opengl!", getError(err));
return false;
}
_this->context = context;
_this->deviceId = computeDeviceId;
_this->commandQueue = commandQueue;
_this->maxWorkGroupSize = maxWorkGroupSize;
_hasCreatedContext = true;
_deviceType = DeviceType::GPU_DEVICE;
return true;
}
#else
bool CLContextWrapper::createContextWithOpengl()
{
cl_platform_id platform;
cl_int err = clGetPlatformIDs(1, &platform, nullptr);
if(err)
{
logError("Error: Failed get platorm id" , getError(err));
return false;
}
// Create CL context properties, add handle & share-group enum
auto glContext = wglGetCurrentContext();
auto glDc = wglGetCurrentDC();
cl_context_properties properties[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties) glContext,
CL_WGL_HDC_KHR, (cl_context_properties) glDc,
CL_CONTEXT_PLATFORM,(cl_context_properties) platform,
0
};
// Get Device Info
// The easy way
cl_device_id computeDeviceId;
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &computeDeviceId, NULL);
if (err)
{
// The "hard" way
if (!clGetGLContextInfoKHR)
{
clGetGLContextInfoKHR = (clGetGLContextInfoKHR_fn)
clGetExtensionFunctionAddressForPlatform(platform, "clGetGLContextInfoKHR");
if (!clGetGLContextInfoKHR)
{
logError("Error: Failed to locate a compute device!" , "Failed to query proc address for clGetGLContextInfoKHR");
return false;
}
// Get the first
err = clGetGLContextInfoKHR(properties, CL_DEVICES_FOR_GL_CONTEXT_KHR, sizeof(cl_device_id), &computeDeviceId, nullptr);
if(!computeDeviceId)
{
logError("Error: Failed to locate a compute device!" , getError(err));
}
}
}
// Create a context with device in the CGL share group
cl_context context = clCreateContext(properties, 1, &computeDeviceId, nullptr, 0, &err);
size_t returnedSize = 0;
size_t maxWorkGroupSize = 0;
err = clGetDeviceInfo(computeDeviceId, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &maxWorkGroupSize, &returnedSize);
if (err != CL_SUCCESS)
{
logError("Error: Failed to retrieve device info!", getError(err));
return false;
}
if(err)
{
logError("Error creating OpenCL shared with with shared Opengl", getError(err));
return false;
}
// Create Command Queue
auto commandQueue = clCreateCommandQueue(context, computeDeviceId, 0, &err);
if (!commandQueue)
{
logError("Error: Failed to create a command ComputeCommands with shared Opengl!", getError(err));
return false;
}
_this->deviceId = computeDeviceId;
_this->context = context;
_this->commandQueue = commandQueue;
_this->maxWorkGroupSize = maxWorkGroupSize;
_hasCreatedContext = true;
_deviceType = DeviceType::GPU_DEVICE;
return true;
return false;
}
#endif
bool CLContextWrapper::hasCreatedContext() const
{
return _hasCreatedContext;
}
DeviceType CLContextWrapper::getContextDeviceType() const
{
return _deviceType;
}
size_t CLContextWrapper::getMaxWorkGroupSize() const
{
return _this->maxWorkGroupSize;
}
bool CLContextWrapper::createProgramFromSource(const std::string & source)
{
cl_int err = 0;
// Create program
const char * sourcePtr = source.c_str();
_this->computeProgram = clCreateProgramWithSource(_this->context, 1, &sourcePtr, nullptr, &err);
if (!_this->computeProgram || err != CL_SUCCESS)
{
std::cout << "___________Begin Source___________________" << std::endl;
std::cout << source << std::endl;
std::cout << "___________End Source___________________" << std::endl;
std::cout << "Error: Failed to create compute program! " << std::endl;
return false;
}
// Build the program executable
const cl_device_id const_device_id = _this->deviceId;
err = clBuildProgram(_this->computeProgram, 1,&const_device_id, NULL, NULL, NULL);
size_t length = 0;
clGetProgramBuildInfo(_this->computeProgram, _this->deviceId, CL_PROGRAM_BUILD_LOG, 0, nullptr, &length);
if(length > 1)
{
char * buildLog = new char[length];
clGetProgramBuildInfo(_this->computeProgram, _this->deviceId, CL_PROGRAM_BUILD_LOG, length*sizeof(char), buildLog, nullptr);
std::cout << buildLog << std::endl;
delete [] buildLog;
}
if (err != CL_SUCCESS)
{
std::cout << getError(err) << std::endl;
return false;
}
std::cout << "Succesfully created program" << std::endl;
return true;
}
KernelId CLContextWrapper::prepareKernel(const std::string & kernelName)
{
cl_int err;
// Create Kernel
cl_kernel newKernel = clCreateKernel(_this->computeProgram, kernelName.c_str(), &err);
if (!newKernel || err != CL_SUCCESS)
{
std::cout << "Error: Failed to create compute kernel!" << std::endl;
std::cout << getError(err) << std::endl;
return newKernel;
}
// Get workgroup size
size_t wgSize;
err = clGetKernelWorkGroupInfo(newKernel, _this->deviceId, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &wgSize, NULL);
if(err)
{
std::cout << "Error: Failed to get kernel work group size" << std::endl;
std::cout << getError(err) << std::endl;
return newKernel;
}
unsigned long lmemSize;
err = clGetKernelWorkGroupInfo(newKernel, _this->deviceId, CL_KERNEL_LOCAL_MEM_SIZE, sizeof(size_t), &lmemSize, NULL);
if(err)
{
std::cout << "Error: Failed to get kernel local memory size" << std::endl;
std::cout << getError(err) << std::endl;
return newKernel;
}
KernelInfo info;
info.kernel = newKernel;
info.workGroupSize = wgSize;
info.localMemSize = lmemSize;
_this->kernels[kernelName] = info;
std::cout << "Succesfully prepared kernel '" << kernelName << "'" << std::endl;
std::cout << "Work group size :" << wgSize << std::endl;
std::cout << "Local Memory size :" << lmemSize << std::endl;
return newKernel;
}
size_t CLContextWrapper::getWorkGroupSizeForKernel(const std::string & kernelName) const
{
auto it =_this->kernels.find(kernelName);
if(it != _this->kernels.end())
{
return it->second.workGroupSize;
}
return 0;
}
bool CLContextWrapper::dispatchKernel(const std::string& kernelName, NDRange range)
{
return dispatchKernel(kernelName, range, std::vector<KernelArg>());
}
bool CLContextWrapper::dispatchKernel(const std::string& kernelName, NDRange range,const std::vector<KernelArg>& args)
{
cl_int err = 0;
// TODO: check if global size and local size are evenly
auto it =_this->kernels.find(kernelName);
if(it == _this->kernels.end())
{
std::cout << "Error: Failed to find kernel to dispatch" << std::endl;
return false;
}
cl_kernel kernel = it->second.kernel;
if(!args.empty())
{
bool allOk = true;
for(decltype(args.size()) i = 0; i < args.size() ; i++)
{
bool ok =_this->setKernelArg(kernel, args[i], static_cast<int>(i));
if(!ok)
{
std::cout << "Failed to setup arg for index " << i << std::endl;
}
allOk &= ok;
}
if(!allOk)
{
return false;
}
}
err = clEnqueueNDRangeKernel(_this->commandQueue,
kernel,
range.workDim,
range.globalOffset,
range.globalSize,
range.localSize,
0, nullptr, nullptr );
if(err)
{
logError("Error: Failed to dispatch kernel", getError(err));
return false;
}
// std::cout << "Successfully dispatched kernel \"" << kernelName <<"\"" << std::endl;
return true;
}
bool CLContextWrapper::setKernelArg(const std::string & kernelName, KernelArg arg, int index)
{
auto it = _this->kernels.find(kernelName);
if(it == _this->kernels.end())
{
std::cout << "Kernel not found! " << std::endl;
return false;
}
return _this->setKernelArg(it->second.kernel, arg, index);
}
void CLContextWrapper::finish()
{
clFinish(_this->commandQueue);
}
BufferId CLContextWrapper::createBuffer(size_t bytesSize, void * hostData, BufferType type)
{
cl_int err;
cl_mem_flags flags = getMemFlags(type);
if(hostData)
{
flags |= CL_MEM_COPY_HOST_PTR;
}
cl_mem buffer = clCreateBuffer(_this->context, flags, bytesSize, hostData, &err);
if(!buffer)
{
std::cout << "Error: Failed to allocate buffer" << std::endl;
std::cout << getError(err) << std::endl;
return 0;
}
_this->buffers.insert(buffer);
return buffer;
}
bool CLContextWrapper::uploadToBuffer(BufferId id, size_t bytesSize, void * data, size_t offset, const bool blocking)
{
cl_int err = 0;
auto it = _this->buffers.find(static_cast<cl_mem>(id));
if(it == _this->buffers.end())
{
std::cout << "Error: Buffer Id not created" << std::endl;
return false;
}
err = clEnqueueWriteBuffer(_this->commandQueue,
static_cast<cl_mem>(id),
blocking ? CL_TRUE : CL_FALSE,
offset,
bytesSize,
data,
0, NULL, NULL);
if(err)
{
std::cout << "Error: Failed to upload data to buffer" << std::endl;
std::cout << getError(err) << std::endl;
return false;
}
return true;
}
bool CLContextWrapper::dowloadFromBuffer(BufferId id, size_t bytesSize, void * data, size_t offset , const bool blocking)
{
cl_int err = 0;
auto it = _this->buffers.find(static_cast<cl_mem>(id));
if(it == _this->buffers.end())
{
std::cout << "Error: Buffer Id not created" << std::endl;
return false;
}
err = clEnqueueReadBuffer(_this->commandQueue,
static_cast<cl_mem>(id),
blocking ? CL_TRUE : CL_FALSE,
offset,
bytesSize,
data,
0, NULL, NULL);
if(err)
{
std::cout << "Error: Failed to download data from buffer" << std::endl;
std::cout << getError(err) << std::endl;
return false;
}
return true;
}
BufferId CLContextWrapper::shareGLTexture(const GLTextureId textureId, BufferType type)
{
auto flags = getMemFlags(type);
cl_int err = 0;
cl_mem mem = clCreateFromGLTexture(_this->context, flags, GL_TEXTURE_2D, 0, textureId, &err);
if(err || !mem)
{
logError("Error: Failed to share texture with Opengl.", getError(err));
return 0;
}
_this->buffers.insert(mem);
return mem;
}
void CLContextWrapper::executeSafeAndSyncronized(BufferId * textureToLock, unsigned int count, std::function<void()> exec)
{
clEnqueueAcquireGLObjects(_this->commandQueue, count, reinterpret_cast<cl_mem*>(textureToLock), 0, nullptr, nullptr);
exec();
clEnqueueReleaseGLObjects(_this->commandQueue, count, reinterpret_cast<cl_mem*>(textureToLock), 0, nullptr, nullptr);
clFinish(_this->commandQueue);
}
std::vector<std::string> CLContextWrapper::listAvailablePlatforms()
{
cl_int err = 0;
cl_uint numPlatforms = 0;
err = clGetPlatformIDs(0, nullptr, &numPlatforms);
if(numPlatforms ==0)
{
return std::vector<std::string>();
}
std::vector<std::string> platformList;
for(cl_uint i =0; i < numPlatforms ; i++)
{
cl_platform_id* platforms = new cl_platform_id[numPlatforms];
err = clGetPlatformIDs(numPlatforms, platforms, nullptr);
for (unsigned i = 0; i < numPlatforms; ++i)
{
char platformName[100];
err = clGetPlatformInfo(platforms[i],
CL_PLATFORM_VENDOR,
sizeof(platformName),
platformName,
nullptr);
platformList.push_back(platformName);
}
}
return platformList;
}