@@ -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) {
0 commit comments