Skip to content

Commit 6e6fab1

Browse files
authored
add code to clGetMemAllocInfoINTEL in USMChecking if it is NULL (#130)
It's possible that an application will never get an extension function pointer for clGetMemAllocInfoINTEL, in which case there will not be an entry in the dispatch table for it and it will be NULL for USMChecking. So, add checks for a NULL function pointer, and attempt to get the extension function pointer if it it is NULL.
1 parent 60e83d9 commit 6e6fab1

File tree

1 file changed

+60
-7
lines changed

1 file changed

+60
-7
lines changed

intercept/src/intercept.cpp

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6071,14 +6071,66 @@ void CLIntercept::checkKernelArgUSMPointer(
60716071
{
60726072
std::lock_guard<std::mutex> lock(m_Mutex);
60736073

6074-
if( arg == NULL )
6074+
cl_int errorCode = CL_SUCCESS;
6075+
6076+
// If we don't have a function pointer for clGetMemAllocINFO, try to
6077+
// get one. It's possible that the function pointer exists but
6078+
// the application hasn't queried for it yet, in which case it won't
6079+
// be installed into the dispatch table.
6080+
if( dispatch().clGetMemAllocInfoINTEL == NULL )
6081+
{
6082+
cl_program program = NULL;
6083+
if( errorCode == CL_SUCCESS )
6084+
{
6085+
errorCode = dispatch().clGetKernelInfo(
6086+
kernel,
6087+
CL_KERNEL_PROGRAM,
6088+
sizeof(program),
6089+
&program,
6090+
NULL );
6091+
}
6092+
6093+
cl_uint numDevices = 0;
6094+
cl_device_id* deviceList = NULL;
6095+
if( errorCode == CL_SUCCESS )
6096+
{
6097+
errorCode = allocateAndGetProgramDeviceList(
6098+
program,
6099+
numDevices,
6100+
deviceList );
6101+
}
6102+
6103+
cl_platform_id platform = NULL;
6104+
if( errorCode == CL_SUCCESS && numDevices > 0 )
6105+
{
6106+
errorCode = dispatch().clGetDeviceInfo(
6107+
deviceList[0],
6108+
CL_DEVICE_PLATFORM,
6109+
sizeof(platform),
6110+
&platform,
6111+
NULL );
6112+
}
6113+
6114+
if( errorCode == CL_SUCCESS )
6115+
{
6116+
getExtensionFunctionAddress(
6117+
platform,
6118+
"clGetMemAllocInfoINTEL" );
6119+
}
6120+
6121+
delete [] deviceList;
6122+
}
6123+
6124+
if( dispatch().clGetMemAllocInfoINTEL == NULL )
6125+
{
6126+
logf( "function pointer for clGetMemAllocInfoINTEL is NULL\n" );
6127+
}
6128+
else if( arg == NULL )
60756129
{
60766130
logf( "mem pointer %p is NULL\n", arg );
60776131
}
60786132
else
60796133
{
6080-
cl_int errorCode = CL_SUCCESS;
6081-
60826134
cl_context context = NULL;
60836135
if( errorCode == CL_SUCCESS )
60846136
{
@@ -6090,10 +6142,11 @@ void CLIntercept::checkKernelArgUSMPointer(
60906142
NULL );
60916143
}
60926144

6093-
cl_unified_shared_memory_type_intel memType = CL_MEM_TYPE_UNKNOWN_INTEL;
6094-
cl_device_id associatedDevice = NULL;
60956145
if( errorCode == CL_SUCCESS )
60966146
{
6147+
cl_unified_shared_memory_type_intel memType = CL_MEM_TYPE_UNKNOWN_INTEL;
6148+
cl_device_id associatedDevice = NULL;
6149+
60976150
dispatch().clGetMemAllocInfoINTEL(
60986151
context,
60996152
arg,
@@ -6135,7 +6188,7 @@ void CLIntercept::checkKernelArgUSMPointer(
61356188
else
61366189
{
61376190
CLI_ASSERT( 0 );
6138-
logf( "mem pointer %p is a DEVICE pointer but has no associated device?\n",
6191+
logf( "mem pointer %p is a DEVICE pointer without an associated device???\n",
61396192
arg );
61406193
}
61416194
}
@@ -6167,7 +6220,7 @@ void CLIntercept::checkKernelArgUSMPointer(
61676220
else if( memType == CL_MEM_TYPE_UNKNOWN_INTEL )
61686221
{
61696222
// This could be a system shared USM pointer, or this could be an error.
6170-
// Check the devices associatd with this kernel to see if any support
6223+
// Check the devices associated with this kernel to see if any support
61716224
// system shared USM allocations.
61726225
cl_program program = NULL;
61736226
if( errorCode == CL_SUCCESS )

0 commit comments

Comments
 (0)