[Beignet] [PATCH] Add clGetKernelSubGroupInfoKHR to _cl_icd_dispatch table

Rebecca N. Palmer rebecca_palmer at zoho.com
Mon Oct 10 23:07:24 UTC 2016


> This patch causes a warning:
> /home/yr /beignet/src/cl_khr_icd.c:187:3: warning: initialization from incompatible pointer type
>    clGetKernelSubGroupInfoKHR,
>
> /home/yr/maintain/beignet/src/cl_khr_icd.c:187:3: warning: (near initialization for ‘cl_khr_icd_dispatch.clUnknown136’)

I see that as well, but it does work (with both old and new ocl-icd).

> clGetKernelSubGroupInfoKHR is available from OpenCL2.0, also need OpenCL version check in beignet?
>
> BTW: ocl-icd 2.2.8's OCL_ICD_IDENTIFIED_FUNCTIONS is 128, is it a typo?

#ifdef CL_VERSION_* checks in current Beignet always give 1.2, the 
version of Beignet's copy of CL/cl.h, but what we actually care about 
here is the version ocl-icd (the ICD loader) was built with: the #if 
(OCL_ICD_IDENTIFIED_FUNCTIONS > 110) is an "OpenCL >=2.0" check for 
that.  (I got the idea from pocl, 
https://anonscm.debian.org/cgit/collab-maint/pocl.git/tree/lib/CL/clGetPlatformIDs.c)

This matters because the ICD loader has a table of function names 
(function_description), while the ICD has a table of function addresses 
(_cl_icd_dispatch) **but no way to tell the loader how long this table 
is**, and the ICD loader's clGetExtensionFunctionForPlatform does 
"search the name table for the requested name, if found return that slot 
in the address table (even if that's NULL or off-the-end garbage), if 
not found in the name table ask the ICD's 
clGetExtensionFunctionForPlatform":
https://www.khronos.org/registry/cl/sdk/2.1/docs/man/xhtml/clGetExtensionFunctionAddressForPlatform.html
https://forge.imag.fr/plugins/scmgit/cgi-bin/gitweb.cgi?p=ocl-icd/ocl-icd.git;a=blob;f=icd_generator.rb;h=d299dbd252ac4b25e62d2e44c0c40dcd179ca3f6;hb=HEAD#l576

Hence, functions that are in the ICD loader's name table but not the 
ICD's address table are impossible to use via ICD, and trying to do so 
may even crash.

The reverse, i.e. having functions in the address table but not the name 
table, is harmless as long as you don't overflow the table's total 
length (now OCL_ICD_IDENTIFIED_FUNCTIONS+50 but was +20 pre-2.0, 
https://forge.imag.fr/plugins/scmgit/cgi-bin/gitweb.cgi?p=ocl-icd/ocl-icd.git;a=blob;f=icd_generator.rb;h=d299dbd252ac4b25e62d2e44c0c40dcd179ca3f6;hb=HEAD#l72); 
hence my use of one #if (OCL_ICD_IDENTIFIED_FUNCTIONS > 110) for the 
whole OpenCL 2.0 block, rather than separate ones for 2.0-core 
(positions 123-135, not currently implemented in Beignet, 
OCL_ICD_IDENTIFIED_FUNCTIONS>110) and clGetKernelSubGroupInfoKHR 
(position 136, >120).



More information about the Beignet mailing list