Skip to content

Commit 81c0e46

Browse files
authored
fix for possible bug obtaining the accelerator refcount (#200)
1 parent 25557bb commit 81c0e46

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

intercept/src/dispatch.cpp

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8139,17 +8139,9 @@ CL_API_ENTRY cl_int CL_API_CALL clRetainAcceleratorINTEL(
81398139
{
81408140
GET_ENQUEUE_COUNTER();
81418141

8142-
cl_uint ref_count = 0;
8143-
if( pIntercept->config().CallLogging )
8144-
{
8145-
ref_count = 0;
8146-
dispatchX.clGetAcceleratorInfoINTEL(
8147-
accelerator,
8148-
CL_ACCELERATOR_REFERENCE_COUNT_INTEL,
8149-
sizeof( ref_count ),
8150-
&ref_count,
8151-
NULL );
8152-
}
8142+
cl_uint ref_count =
8143+
pIntercept->config().CallLogging ?
8144+
pIntercept->getRefCount( accelerator ) : 0;
81538145
CALL_LOGGING_ENTER( "[ ref count = %d ] accelerator = %p",
81548146
ref_count,
81558147
accelerator );
@@ -8160,16 +8152,9 @@ CL_API_ENTRY cl_int CL_API_CALL clRetainAcceleratorINTEL(
81608152

81618153
CPU_PERFORMANCE_TIMING_END();
81628154
CHECK_ERROR( retVal );
8163-
if( pIntercept->config().CallLogging )
8164-
{
8165-
ref_count = 0;
8166-
dispatchX.clGetAcceleratorInfoINTEL(
8167-
accelerator,
8168-
CL_ACCELERATOR_REFERENCE_COUNT_INTEL,
8169-
sizeof( ref_count ),
8170-
&ref_count,
8171-
NULL );
8172-
}
8155+
ref_count =
8156+
pIntercept->config().CallLogging ?
8157+
pIntercept->getRefCount( accelerator ) : 0;
81738158
CALL_LOGGING_EXIT( retVal, "[ ref count = %d ]", ref_count );
81748159

81758160
return retVal;
@@ -8196,17 +8181,9 @@ CL_API_ENTRY cl_int CL_API_CALL clReleaseAcceleratorINTEL(
81968181

81978182
pIntercept->checkRemoveAcceleratorInfo( accelerator );
81988183

8199-
cl_uint ref_count = 0;
8200-
if( pIntercept->config().CallLogging )
8201-
{
8202-
ref_count = 0;
8203-
dispatchX.clGetAcceleratorInfoINTEL(
8204-
accelerator,
8205-
CL_ACCELERATOR_REFERENCE_COUNT_INTEL,
8206-
sizeof( ref_count ),
8207-
&ref_count,
8208-
NULL );
8209-
}
8184+
cl_uint ref_count =
8185+
pIntercept->config().CallLogging ?
8186+
pIntercept->getRefCount( accelerator ) : 0;
82108187
CALL_LOGGING_ENTER( "[ ref count = %d ] accelerator = %p",
82118188
ref_count,
82128189
accelerator );

intercept/src/intercept.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ class CLIntercept
665665
cl_platform_id getPlatform( cl_kernel kernel ) const;
666666
cl_platform_id getPlatform( cl_mem memobj ) const;
667667

668+
cl_uint getRefCount( cl_accelerator_intel accelerator );
668669
cl_uint getRefCount( cl_command_queue queue ) const;
669670
cl_uint getRefCount( cl_context conest ) const;
670671
cl_uint getRefCount( cl_device_id device ) const;
@@ -1071,7 +1072,7 @@ class CLIntercept
10711072
typedef std::map< const cl_context, SBuiltinKernelOverrides* > CBuiltinKernelOverridesMap;
10721073
CBuiltinKernelOverridesMap m_BuiltinKernelOverridesMap;
10731074

1074-
typedef std::map< const cl_accelerator_intel, cl_platform_id> CAcceleratorInfoMap;
1075+
typedef std::map< const cl_accelerator_intel, cl_platform_id > CAcceleratorInfoMap;
10751076
CAcceleratorInfoMap m_AcceleratorInfoMap;
10761077

10771078
struct Config
@@ -1326,6 +1327,30 @@ inline cl_platform_id CLIntercept::getPlatform( cl_mem memobj ) const
13261327

13271328
///////////////////////////////////////////////////////////////////////////////
13281329
//
1330+
inline cl_uint CLIntercept::getRefCount( cl_accelerator_intel accelerator )
1331+
{
1332+
auto platform = this->getPlatform(accelerator);
1333+
auto dispatchX = this->dispatchX(platform);
1334+
if( dispatchX.clGetAcceleratorInfoINTEL == NULL )
1335+
{
1336+
getExtensionFunctionAddress(
1337+
platform,
1338+
"clGetAcceleratorInfoINTEL" );
1339+
}
1340+
1341+
cl_uint refCount = 0;
1342+
if( dispatchX.clGetAcceleratorInfoINTEL )
1343+
{
1344+
dispatchX.clGetAcceleratorInfoINTEL(
1345+
accelerator,
1346+
CL_ACCELERATOR_REFERENCE_COUNT_INTEL,
1347+
sizeof(refCount),
1348+
&refCount,
1349+
NULL );
1350+
}
1351+
return refCount;
1352+
}
1353+
13291354
inline cl_uint CLIntercept::getRefCount( cl_command_queue queue ) const
13301355
{
13311356
cl_uint refCount = 0;

0 commit comments

Comments
 (0)