Skip to content
This repository was archived by the owner on Feb 16, 2019. It is now read-only.

Commit 4c8a6c0

Browse files
Chaitanya Sri Krishna LollaChaitanya Sri Krishna Lolla
authored andcommitted
Workaround for Intel Port: Updated the code with opencl version.
1 parent 87ad275 commit 4c8a6c0

File tree

5 files changed

+80
-17
lines changed

5 files changed

+80
-17
lines changed

openvx/ago/ago_drama_alloc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ static int agoOptimizeDramaAllocGpuResources(AgoGraph * graph)
8484
// create command queue: for now use device#0 -- TBD: this needs to be changed in future
8585
cl_int err = -1;
8686
graph->opencl_device = context->opencl_device_list[0];
87+
#if defined(CL_VERSION_2_0)
8788
graph->opencl_cmdq = clCreateCommandQueueWithProperties(context->opencl_context, graph->opencl_device, NULL, &err);
89+
#else
90+
graph->opencl_cmdq = clCreateCommandQueue(context->opencl_context, graph->opencl_device, 0, &err);
91+
#endif
8892
if (err) {
8993
agoAddLogEntry(&graph->ref, VX_FAILURE, "ERROR: clCreateCommandQueueWithProperties(%p,%p,0,*) => %d\n", context->opencl_context, graph->opencl_device, err);
9094
return -1;

openvx/ago/ago_internal.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,13 @@ THE SOFTWARE.
144144
#define DATA_OPENCL_ARRAY_OFFSET 16 // first 16 bytes of array buffer will be used for numitems
145145
// opencl configuration flags
146146
#define CONFIG_OPENCL_USE_1_2 0x0001 // use OpenCL 1.2
147+
#if defined(CL_VERSION_2_0)
147148
#define CONFIG_OPENCL_SVM_MASK 0x00F0 // OpenCL SVM flags mask
148149
#define CONFIG_OPENCL_SVM_ENABLE 0x0010 // use OpenCL SVM
149150
#define CONFIG_OPENCL_SVM_AS_FGS 0x0020 // use OpenCL SVM as fine grain system
150151
#define CONFIG_OPENCL_SVM_AS_CLMEM 0x0040 // use OpenCL SVM as cl_mem
151152
#endif
153+
#endif
152154
// opencl image fixed byte offset
153155
#define OPENCL_IMAGE_FIXED_OFFSET 256
154156

@@ -393,9 +395,11 @@ struct AgoData {
393395
#if ENABLE_OPENCL
394396
cl_mem opencl_buffer;
395397
cl_mem opencl_buffer_allocated;
396-
#endif
398+
#if defined(CL_VERSION_2_0)
397399
vx_uint8 * opencl_svm_buffer;
398400
vx_uint8 * opencl_svm_buffer_allocated;
401+
#endif
402+
#endif
399403
vx_uint32 opencl_buffer_offset;
400404
vx_bool isVirtual;
401405
vx_bool isDelayed;
@@ -669,7 +673,9 @@ struct AgoContext {
669673
cl_command_queue opencl_cmdq;
670674
vx_uint32 opencl_config_flags;
671675
char opencl_extensions[1024];
676+
#if defined(CL_VERSION_2_0)
672677
cl_device_svm_capabilities opencl_svmcaps;
678+
#endif
673679
cl_uint opencl_num_devices;
674680
cl_device_id opencl_device_list[16];
675681
char opencl_build_options[256];

openvx/ago/ago_util.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ int agoGetDataFromDescription(AgoContext * acontext, AgoGraph * agraph, AgoData
15021502
}
15031503
else if (data->u.scalar.type == VX_TYPE_FLOAT16) {
15041504
data->u.scalar.itemsize = sizeof(vx_uint16);
1505-
if (sscanf(s, "%g", &data->u.scalar.u.u) == 1)
1505+
if (sscanf(s, "%d", &data->u.scalar.u.u) == 1)
15061506
data->isInitialized = vx_true_e;
15071507
}
15081508
else if (data->u.scalar.type == VX_TYPE_BOOL) {
@@ -2907,8 +2907,11 @@ AgoData::AgoData()
29072907
buffer{ nullptr }, buffer_allocated{ nullptr }, reserved{ nullptr }, reserved_allocated{ nullptr }, buffer_sync_flags{ 0 },
29082908
#if ENABLE_OPENCL
29092909
opencl_buffer{ nullptr }, opencl_buffer_allocated{ nullptr },
2910+
#if defined(CL_VERSION_2_0)
2911+
opencl_svm_buffer{ nullptr }, opencl_svm_buffer_allocated{ nullptr },
29102912
#endif
2911-
opencl_svm_buffer{ nullptr }, opencl_svm_buffer_allocated{ nullptr }, opencl_buffer_offset{ 0 },
2913+
#endif
2914+
opencl_buffer_offset{ 0 },
29122915
isVirtual{ vx_false_e }, isDelayed{ vx_false_e }, isNotFullyConfigured{ vx_false_e }, isInitialized{ vx_false_e }, siblingIndex{ 0 },
29132916
numChildren{ 0 }, children{ nullptr }, parent{ nullptr }, inputUsageCount{ 0 }, outputUsageCount{ 0 }, inoutUsageCount{ 0 },
29142917
nextMapId{ 0 }, hierarchical_level{ 0 }, hierarchical_life_start{ 0 }, hierarchical_life_end{ 0 }, ownerOfUserBufferOpenCL{ nullptr }
@@ -3069,7 +3072,10 @@ AgoContext::AgoContext()
30693072
num_active_modules{ 0 }, num_active_references{ 0 }, callback_log{ nullptr }, callback_reentrant{ vx_false_e },
30703073
thread_config{ CONFIG_THREAD_DEFAULT }, importing_module_index_plus1{ 0 }, graph_garbage_data{ nullptr }, graph_garbage_node{ nullptr }, graph_garbage_list{ nullptr }
30713074
#if ENABLE_OPENCL
3072-
, opencl_context_imported{ false }, opencl_context{ nullptr }, opencl_cmdq{ nullptr }, opencl_config_flags{ 0 }, opencl_svmcaps{ 0 }, opencl_num_devices{ 0 }, isAmdMediaOpsSupported{ true }
3075+
#if defined(CL_VERSION_2_0)
3076+
, opencl_svmcaps{ 0 }
3077+
#endif
3078+
, opencl_context_imported{ false }, opencl_context{ nullptr }, opencl_cmdq{ nullptr }, opencl_config_flags{ 0 }, opencl_num_devices{ 0 }, isAmdMediaOpsSupported{ true }
30733079
#endif
30743080
{
30753081
memset(&kernelList, 0, sizeof(kernelList));

openvx/ago/ago_util_opencl.cpp

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ int agoGpuOclReleaseData(AgoData * data)
115115
clReleaseMemObject(data->opencl_buffer_allocated);
116116
data->opencl_buffer_allocated = NULL;
117117
}
118+
#if defined(CL_VERSION_2_0)
118119
if (data->opencl_svm_buffer_allocated) {
119120
if (data->ref.context->opencl_config_flags & CONFIG_OPENCL_SVM_AS_FGS) {
120121
agoReleaseMemory(data->opencl_svm_buffer_allocated);
@@ -124,8 +125,9 @@ int agoGpuOclReleaseData(AgoData * data)
124125
}
125126
data->opencl_svm_buffer_allocated = NULL;
126127
}
127-
data->opencl_buffer = NULL;
128128
data->opencl_svm_buffer = NULL;
129+
#endif
130+
data->opencl_buffer = NULL;
129131
data->opencl_buffer_offset = 0;
130132
return 0;
131133
}
@@ -151,17 +153,26 @@ int agoGpuOclCreateContext(AgoContext * context, cl_context opencl_context)
151153
agoAddLogEntry(NULL, VX_FAILURE, "ERROR: clGetPlatformIDs(%d,*,0) => %d (failed)\n", num_platforms, status);
152154
return -1;
153155
}
154-
cl_platform_id platform_id = platform_list[0];
155-
for (int i = 0; i < (int)num_platforms; i++) {
156-
char vendor[128] = { 0 };
157-
if ((status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_VENDOR, sizeof(vendor), vendor, NULL)) != CL_SUCCESS) {
158-
agoAddLogEntry(NULL, VX_FAILURE, "ERROR: clGetPlatformInfo([%d],...) => %d (failed)\n", i, status);
159-
return -1;
156+
cl_platform_id platform_id = nullptr;
157+
char opencl_platform_override[64] = "";
158+
if (agoGetEnvironmentVariable("AGO_OPENCL_PLATFORM", opencl_platform_override, sizeof(opencl_platform_override))) {
159+
cl_uint index = (cl_uint)atoi(opencl_platform_override);
160+
if (index < num_platforms) {
161+
platform_id = platform_list[index];
160162
}
161-
if (!strcmp(vendor, "Advanced Micro Devices, Inc.")) {
162-
platform_id = platform_list[i];
163-
context->isVendorAmd = true;
164-
break;
163+
}
164+
if (!platform_id) {
165+
platform_id = platform_list[0];
166+
for (int i = 0; i < (int)num_platforms; i++) {
167+
char vendor[128] = { 0 };
168+
if ((status = clGetPlatformInfo(platform_list[i], CL_PLATFORM_VENDOR, sizeof(vendor), vendor, NULL)) != CL_SUCCESS) {
169+
agoAddLogEntry(NULL, VX_FAILURE, "ERROR: clGetPlatformInfo([%d],...) => %d (failed)\n", i, status);
170+
return -1;
171+
}
172+
if (!strcmp(vendor, "Advanced Micro Devices, Inc.")) {
173+
platform_id = platform_list[i];
174+
break;
175+
}
165176
}
166177
}
167178
delete [] platform_list;
@@ -221,19 +232,25 @@ int agoGpuOclCreateContext(AgoContext * context, cl_context opencl_context)
221232
return -1;
222233
}
223234
context->isAmdMediaOpsSupported = strstr(extensions, "cl_amd_media_ops") ? true : false;
235+
#if defined(CL_VERSION_2_0)
224236
agoAddLogEntry(&context->ref, VX_SUCCESS, "OK: OpenVX using GPU device#%d (%s) [%s] [SvmCaps " VX_FMT_SIZE " %d]\n", device_id, deviceName, deviceVersion, context->opencl_svmcaps, context->opencl_config_flags);
237+
#else
238+
agoAddLogEntry(&context->ref, VX_SUCCESS, "OK: OpenVX using GPU device#%d (%s) [%s] [%d]\n", device_id, deviceName, deviceVersion, context->opencl_config_flags);
239+
#endif
225240
memset(context->opencl_extensions, 0, sizeof(context->opencl_extensions));
226241
status = clGetDeviceInfo(context->opencl_device_list[device_id], CL_DEVICE_EXTENSIONS, sizeof(context->opencl_extensions), context->opencl_extensions, NULL);
227242
if (status) {
228243
agoAddLogEntry(&context->ref, VX_FAILURE, "ERROR: clGetDeviceInfo(%p,CL_DEVICE_EXTENSIONS) => %d\n", context->opencl_device_list[device_id], status);
229244
return -1;
230245
}
246+
#if defined(CL_VERSION_2_0)
231247
context->opencl_svmcaps = 0;
232248
status = clGetDeviceInfo(context->opencl_device_list[device_id], CL_DEVICE_SVM_CAPABILITIES, sizeof(context->opencl_svmcaps), &context->opencl_svmcaps, NULL);
233249
if (status) {
234250
agoAddLogEntry(&context->ref, VX_FAILURE, "ERROR: clGetDeviceInfo(%p,CL_DEVICE_SVM_CAPABILITIES) => %d\n", context->opencl_device_list[device_id], status);
235251
return -1;
236252
}
253+
#endif
237254
// get default OpenCL build options
238255
strcpy(context->opencl_build_options, (context->opencl_config_flags & CONFIG_OPENCL_USE_1_2) ? "-cl-std=CL1.2" : "-cl-std=CL2.0");
239256
// override build options with environment variable
@@ -246,6 +263,7 @@ int agoGpuOclCreateContext(AgoContext * context, cl_context opencl_context)
246263
}
247264

248265
// decide SVM features
266+
#if defined(CL_VERSION_2_0)
249267
if (context->opencl_svmcaps & (CL_DEVICE_SVM_FINE_GRAIN_BUFFER | CL_DEVICE_SVM_FINE_GRAIN_SYSTEM)) {
250268
context->opencl_config_flags &= ~CONFIG_OPENCL_SVM_MASK;
251269
if (context->attr_affinity.device_info & AGO_TARGET_AFFINITY_GPU_INFO_SVM_MASK) {
@@ -272,8 +290,13 @@ int agoGpuOclCreateContext(AgoContext * context, cl_context opencl_context)
272290
}
273291
}
274292
}
293+
#endif
275294
// create command queue for buffer sync
295+
#if defined(CL_VERSION_2_0)
276296
context->opencl_cmdq = clCreateCommandQueueWithProperties(context->opencl_context, context->opencl_device_list[device_id], NULL, &status);
297+
#else
298+
context->opencl_cmdq = clCreateCommandQueue(context->opencl_context, context->opencl_device_list[device_id], 0, &status);
299+
#endif
277300
if (status) {
278301
agoAddLogEntry(&context->ref, VX_FAILURE, "ERROR: clCreateCommandQueueWithProperties(%p,%p,0,*) => %d\n", context->opencl_context, context->opencl_device_list[device_id], status);
279302
return -1;
@@ -294,6 +317,7 @@ int agoGpuOclAllocBuffer(AgoData * data)
294317
AgoData * dataMaster = data->u.img.roiMasterImage ? data->u.img.roiMasterImage : data; // to handle image ROI
295318
if (!dataMaster->opencl_buffer && !dataMaster->u.img.enableUserBufferOpenCL && !(dataMaster->import_type == VX_MEMORY_TYPE_OPENCL)) {
296319
cl_int err = CL_SUCCESS;
320+
#if defined(CL_VERSION_2_0)
297321
if (!dataMaster->buffer && !dataMaster->u.img.isUniform) {
298322
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_ENABLE) {
299323
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_AS_FGS) {
@@ -322,7 +346,9 @@ int agoGpuOclAllocBuffer(AgoData * data)
322346
dataMaster->opencl_buffer = dataMaster->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, dataMaster->size + dataMaster->opencl_buffer_offset, dataMaster->opencl_svm_buffer_allocated, &err);
323347
}
324348
}
325-
else {
349+
else
350+
#endif
351+
{
326352
// allocate normal opencl_buffer
327353
dataMaster->opencl_buffer = dataMaster->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE, dataMaster->size + dataMaster->opencl_buffer_offset, NULL, &err);
328354
}
@@ -349,13 +375,16 @@ int agoGpuOclAllocBuffer(AgoData * data)
349375
if (data != dataMaster) {
350376
// special handling for image ROI
351377
data->opencl_buffer = dataMaster->opencl_buffer;
378+
#if defined(CL_VERSION_2_0)
352379
data->opencl_svm_buffer = dataMaster->opencl_svm_buffer;
380+
#endif
353381
}
354382
}
355383
else if (data->ref.type == VX_TYPE_ARRAY || data->ref.type == AGO_TYPE_CANNY_STACK) {
356384
if (!data->opencl_buffer) {
357385
data->opencl_buffer_offset = DATA_OPENCL_ARRAY_OFFSET; // first few bytes reserved for numitems/stacktop
358386
cl_int err = CL_SUCCESS;
387+
#if defined(CL_VERSION_2_0)
359388
if (!data->buffer) {
360389
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_ENABLE) {
361390
if (context->opencl_config_flags & CONFIG_OPENCL_SVM_AS_FGS) {
@@ -387,7 +416,9 @@ int agoGpuOclAllocBuffer(AgoData * data)
387416
data->opencl_buffer = data->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, data->size + data->opencl_buffer_offset, data->opencl_svm_buffer_allocated, &err);
388417
}
389418
}
390-
else {
419+
else
420+
#endif
421+
{
391422
// normal opencl_buffer allocation
392423
data->opencl_buffer = data->opencl_buffer_allocated = clCreateBuffer(context->opencl_context, CL_MEM_READ_WRITE, data->size + data->opencl_buffer_offset, NULL, &err);
393424
if (data->opencl_buffer) {
@@ -468,7 +499,9 @@ int agoGpuOclAllocBuffer(AgoData * data)
468499
if (data != dataMaster) {
469500
// special handling for tensor ROI
470501
data->opencl_buffer = dataMaster->opencl_buffer;
502+
#if defined(CL_VERSION_2_0)
471503
data->opencl_svm_buffer = dataMaster->opencl_svm_buffer;
504+
#endif
472505
data->opencl_buffer_offset = (vx_uint32)data->u.tensor.offset;
473506
}
474507
}
@@ -571,13 +604,15 @@ int agoGpuOclDataSetBufferAsKernelArg(AgoData * data, cl_kernel opencl_kernel, v
571604
return -1;
572605
}
573606
}
607+
#if defined(CL_VERSION_2_0)
574608
else if (data->opencl_svm_buffer) {
575609
cl_int err = clSetKernelArgSVMPointer(opencl_kernel, (cl_uint)kernelArgIndex, data->opencl_svm_buffer);
576610
if (err) {
577611
agoAddLogEntry(&data->ref, VX_FAILURE, "ERROR: clSetKernelArgSVMPointer(supernode,%d,*,buffer) failed(%d) for group#%d\n", (cl_uint)kernelArgIndex, err, group);
578612
return -1;
579613
}
580614
}
615+
#endif
581616
else if (data->import_type != VX_MEMORY_TYPE_OPENCL && !(data->ref.type == VX_TYPE_IMAGE && data->u.img.enableUserBufferOpenCL)) {
582617
agoAddLogEntry(&data->ref, VX_FAILURE, "ERROR: agoGpuOclDataSetBufferAsKernelArg(supernode,%d) OpenCL buffer not allocated for group#%d\n", (cl_uint)kernelArgIndex, group);
583618
return -1;
@@ -1115,7 +1150,11 @@ static int agoGpuOclDataOutputAtomicSync(AgoGraph * graph, AgoData * data)
11151150
// update number of items
11161151
cl_int err = CL_SUCCESS;
11171152
int64_t stime = agoGetClockCounter();
1153+
#if defined(CL_VERSION_2_0)
11181154
vx_uint32 * pNumItems = (vx_uint32 *)data->opencl_svm_buffer;
1155+
#else
1156+
vx_uint32 * pNumItems = nullptr;
1157+
#endif
11191158
if (data->opencl_buffer) {
11201159
pNumItems = (vx_uint32 *)clEnqueueMapBuffer(opencl_cmdq, data->opencl_buffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, sizeof(vx_uint32), 0, NULL, NULL, &err);
11211160
if (err) {
@@ -1144,7 +1183,11 @@ static int agoGpuOclDataOutputAtomicSync(AgoGraph * graph, AgoData * data)
11441183
// update number of items and reset it for next use
11451184
int64_t stime = agoGetClockCounter();
11461185
cl_int err = CL_SUCCESS;
1186+
#if defined(CL_VERSION_2_0)
11471187
vx_uint8 * stack = data->opencl_svm_buffer;
1188+
#else
1189+
vx_uint8 * stack = nullptr;
1190+
#endif
11481191
if (data->opencl_buffer) {
11491192
stack = (vx_uint8 *)clEnqueueMapBuffer(opencl_cmdq, data->opencl_buffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, sizeof(vx_uint32), 0, NULL, NULL, &err);
11501193
if (err) {

openvx/api/vx_api.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,11 @@ VX_API_ENTRY vx_status VX_API_CALL vxQueryImage(vx_image image_, vx_enum attribu
10201020
*(cl_mem *)ptr = image->opencl_buffer;
10211021
}
10221022
else {
1023+
#if defined(CL_VERSION_2_0)
10231024
*(vx_uint8 **)ptr = image->opencl_svm_buffer;
1025+
#else
1026+
*(vx_uint8 **)ptr = NULL;
1027+
#endif
10241028
}
10251029
status = VX_SUCCESS;
10261030
}

0 commit comments

Comments
 (0)