Skip to content

Commit 9be377c

Browse files
authored
fix for MDAPI command queues (#165)
Don't cache a const reference to the dispatch table until after calling getExtensionFunctionAddress.
1 parent 5b2c079 commit 9be377c

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

intercept/mdapi/intercept_mdapi.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,28 @@ cl_command_queue CLIntercept::createMDAPICommandQueue(
147147
{
148148
cl_command_queue retVal = NULL;
149149

150-
// Note: This works fine for one device, but if there are two
151-
// devices then we will need a different mechanism to get a
152-
// device-specific function pointer.
153-
154150
cl_platform_id platform = getPlatform(device);
155-
auto dispatchX = this->dispatchX(platform);
156151

157-
if( dispatchX.clCreatePerfCountersCommandQueueINTEL == NULL )
152+
if( dispatchX(platform).clCreatePerfCountersCommandQueueINTEL == NULL )
158153
{
159154
getExtensionFunctionAddress(
160155
platform,
161156
"clCreatePerfCountersCommandQueueINTEL" );
162157
}
163158

164-
if( dispatchX.clCreatePerfCountersCommandQueueINTEL && m_pMDHelper )
165-
{
166-
std::lock_guard<std::mutex> lock(m_Mutex);
159+
std::lock_guard<std::mutex> lock(m_Mutex);
167160

161+
auto dispatchX = this->dispatchX(platform);
162+
if( dispatchX.clCreatePerfCountersCommandQueueINTEL == NULL )
163+
{
164+
log( "Couldn't get pointer to clCreatePerfCountersCommandQueueINTEL!\n" );
165+
}
166+
else if( m_pMDHelper == NULL )
167+
{
168+
log( "Metrics discovery is not initialized!\n" );
169+
}
170+
else
171+
{
168172
if( m_pMDHelper->ActivateMetricSet() )
169173
{
170174
cl_uint configuration = m_pMDHelper->GetMetricsConfiguration();

intercept/src/intercept.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4809,15 +4809,15 @@ void CLIntercept::addTimingEvent(
48094809
deviceInfo.Supports_cl_khr_subgroups )
48104810
{
48114811
cl_platform_id platform = getPlatform(device);
4812-
auto dispatchX = this->dispatchX(platform);
48134812

4814-
if( dispatchX.clGetKernelSubGroupInfoKHR == NULL )
4813+
if( dispatchX(platform).clGetKernelSubGroupInfoKHR == NULL )
48154814
{
48164815
getExtensionFunctionAddress(
48174816
platform,
48184817
"clGetKernelSubGroupInfoKHR" );
48194818
}
48204819

4820+
auto dispatchX = this->dispatchX(platform);
48214821
if( dispatchX.clGetKernelSubGroupInfoKHR )
48224822
{
48234823
dispatchX.clGetKernelSubGroupInfoKHR(
@@ -5260,15 +5260,15 @@ cl_command_queue CLIntercept::createCommandQueueWithProperties(
52605260
deviceInfo.Supports_cl_khr_create_command_queue )
52615261
{
52625262
cl_platform_id platform = getPlatform(device);
5263-
auto dispatchX = this->dispatchX(platform);
52645263

5265-
if( dispatchX.clCreateCommandQueueWithPropertiesKHR == NULL )
5264+
if( dispatchX(platform).clCreateCommandQueueWithPropertiesKHR == NULL )
52665265
{
52675266
getExtensionFunctionAddress(
52685267
platform,
52695268
"clCreateCommandQueueWithPropertiesKHR" );
52705269
}
52715270

5271+
auto dispatchX = this->dispatchX(platform);
52725272
if( dispatchX.clCreateCommandQueueWithPropertiesKHR )
52735273
{
52745274
retVal = dispatchX.clCreateCommandQueueWithPropertiesKHR(
@@ -6349,19 +6349,19 @@ void CLIntercept::checkKernelArgUSMPointer(
63496349
cl_int errorCode = CL_SUCCESS;
63506350

63516351
cl_platform_id platform = getPlatform(kernel);
6352-
auto dispatchX = this->dispatchX(platform);
63536352

63546353
// If we don't have a function pointer for clGetMemAllocINFO, try to
63556354
// get one. It's possible that the function pointer exists but
63566355
// the application hasn't queried for it yet, in which case it won't
63576356
// be installed into the dispatch table.
6358-
if( dispatchX.clGetMemAllocInfoINTEL == NULL )
6357+
if( dispatchX(platform).clGetMemAllocInfoINTEL == NULL )
63596358
{
63606359
getExtensionFunctionAddress(
63616360
platform,
63626361
"clGetMemAllocInfoINTEL" );
63636362
}
63646363

6364+
auto dispatchX = this->dispatchX(platform);
63656365
if( dispatchX.clGetMemAllocInfoINTEL == NULL )
63666366
{
63676367
logf( "function pointer for clGetMemAllocInfoINTEL is NULL\n" );

0 commit comments

Comments
 (0)