diff --git a/intercept/src/cli_ext.h b/intercept/src/cli_ext.h index 0b69a9a7..9e21a7f5 100644 --- a/intercept/src/cli_ext.h +++ b/intercept/src/cli_ext.h @@ -984,6 +984,92 @@ cl_int CL_API_CALL clGetKernelSuggestedLocalWorkSizeKHR( #define CL_QUEUE_THROTTLE_MED_KHR (1<<1) #define CL_QUEUE_THROTTLE_LOW_KHR (1<<2) +/////////////////////////////////////////////////////////////////////////////// +// cl_khr_unified_svm + +// Note: This implements the proposed extension version 0.9.0. + +#define CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR 0x0909 + +#define CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR 0x1077 + +typedef cl_bitfield cl_svm_capabilities_khr; + +#define CL_SVM_CAPABILITY_SINGLE_ADDRESS_SPACE_KHR (1 << 0) +#define CL_SVM_CAPABILITY_SYSTEM_ALLOCATED_KHR (1 << 1) +#define CL_SVM_CAPABILITY_DEVICE_OWNED_KHR (1 << 2) +#define CL_SVM_CAPABILITY_DEVICE_UNASSOCIATED_KHR (1 << 3) +#define CL_SVM_CAPABILITY_CONTEXT_ACCESS_KHR (1 << 4) +#define CL_SVM_CAPABILITY_HOST_OWNED_KHR (1 << 5) +#define CL_SVM_CAPABILITY_HOST_READ_KHR (1 << 6) +#define CL_SVM_CAPABILITY_HOST_WRITE_KHR (1 << 7) +#define CL_SVM_CAPABILITY_HOST_MAP_KHR (1 << 8) +#define CL_SVM_CAPABILITY_DEVICE_READ_KHR (1 << 9) +#define CL_SVM_CAPABILITY_DEVICE_WRITE_KHR (1 << 10) +#define CL_SVM_CAPABILITY_DEVICE_ATOMIC_ACCESS_KHR (1 << 11) +#define CL_SVM_CAPABILITY_CONCURRENT_ACCESS_KHR (1 << 12) +#define CL_SVM_CAPABILITY_CONCURRENT_ATOMIC_ACCESS_KHR (1 << 13) +#define CL_SVM_CAPABILITY_INDIRECT_ACCESS_KHR (1 << 14) + +typedef cl_properties cl_svm_alloc_properties_khr; +typedef cl_bitfield cl_svm_alloc_access_flags_khr; +typedef cl_properties cl_svm_free_properties_khr; +typedef cl_bitfield cl_svm_free_flags_khr; +typedef cl_uint cl_svm_pointer_info_khr; + +#define CL_SVM_ALLOC_ASSOCIATED_DEVICE_HANDLE_KHR 0x2078 +#define CL_SVM_ALLOC_ACCESS_FLAGS_KHR 0x2079 +#define CL_SVM_ALLOC_ALIGNMENT_KHR 0x207A + +#define CL_SVM_ALLOC_ACCESS_HOST_NOREAD_KHR (1 << 0) +#define CL_SVM_ALLOC_ACCESS_HOST_NOWRITE_KHR (1 << 1) +#define CL_SVM_ALLOC_ACCESS_DEVICE_NOREAD_KHR (1 << 8) +#define CL_SVM_ALLOC_ACCESS_DEVICE_NOWRITE_KHR (1 << 9) + +#define CL_SVM_INFO_TYPE_INDEX_KHR 0x2088 +#define CL_SVM_INFO_CAPABILITIES_KHR 0x2089 +#define CL_SVM_INFO_PROPERTIES_KHR 0x208A +#define CL_SVM_INFO_ACCESS_FLAGS_KHR 0x208B +#define CL_SVM_INFO_BASE_PTR_KHR 0x419B +#define CL_SVM_INFO_SIZE_KHR 0x419C +#define CL_SVM_INFO_ASSOCIATED_DEVICE_HANDLE_KHR 0x419D + +#define CL_KERNEL_EXEC_INFO_SVM_INDIRECT_ACCESS_KHR 0x11BB + +extern CL_API_ENTRY +void* CL_API_CALL clSVMAllocWithPropertiesKHR( + cl_context context, + const cl_svm_alloc_properties_khr* properties, + cl_uint svm_type_index, + size_t size, + cl_int* errcode_ret); + +extern CL_API_ENTRY +cl_int CL_API_CALL clSVMFreeWithPropertiesKHR( + cl_context context, + const cl_svm_free_properties_khr* properties, + cl_svm_free_flags_khr flags, + void* ptr); + +extern CL_API_ENTRY +cl_int CL_API_CALL clGetSVMPointerInfoKHR( + cl_context context, + cl_device_id device, + const void* ptr, + cl_svm_pointer_info_khr param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + +extern CL_API_ENTRY +cl_int CL_API_CALL clGetSVMSuggestedTypeIndexKHR( + cl_context context, + cl_svm_capabilities_khr required_capabilities, + cl_svm_capabilities_khr desired_capabilities, + const cl_svm_alloc_properties_khr* properties, + size_t size, + cl_uint* suggested_svm_type_index); + /////////////////////////////////////////////////////////////////////////////// // cl_ext_atomic_counters diff --git a/intercept/src/dispatch.cpp b/intercept/src/dispatch.cpp index cd2c97e4..fa59fcb1 100644 --- a/intercept/src/dispatch.cpp +++ b/intercept/src/dispatch.cpp @@ -57,7 +57,8 @@ CL_API_ENTRY cl_int CL_API_CALL CLIRN(clGetPlatformIDs)( if( pIntercept && pIntercept->dispatch().clGetPlatformIDs ) { - LOG_CLINFO(); + CACHE_PLATFORM_INFO(); + LOG_CL_INFO(); GET_ENQUEUE_COUNTER(); CALL_LOGGING_ENTER(); @@ -5382,10 +5383,8 @@ CL_API_ENTRY void* CL_API_CALL CLIRN(clGetExtensionFunctionAddress)( return retVal; } - else - { - return NULL; - } + + return NULL; } /////////////////////////////////////////////////////////////////////////////// @@ -5438,10 +5437,8 @@ CL_API_ENTRY void* CL_API_CALL CLIRN(clGetExtensionFunctionAddressForPlatform)( return retVal; } - else - { - return NULL; - } + + return NULL; } /////////////////////////////////////////////////////////////////////////////// @@ -6448,8 +6445,10 @@ CL_API_ENTRY cl_int CL_API_CALL CLIRN(clEnqueueSVMFree) ( HOST_PERFORMANCE_TIMING_END(); DEVICE_PERFORMANCE_TIMING_END( command_queue, event ); + // TODO: REMOVE_SVM_ALLOCATIONS? CHECK_ERROR( retVal ); ADD_OBJECT_ALLOCATION( event ? event[0] : NULL ); + ADD_POINTER_FREES( pfn_free_func, num_svm_pointers, svm_pointers ); CALL_LOGGING_EXIT_EVENT( retVal, event ); ADD_EVENT( event ? event[0] : NULL ); } @@ -8969,6 +8968,207 @@ CL_API_ENTRY cl_int CL_API_CALL clSetKernelArgDevicePointerEXT( NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_KERNEL); } +/////////////////////////////////////////////////////////////////////////////// +// +// cl_khr_unified_svm +CL_API_ENTRY void* CL_API_CALL clSVMAllocWithPropertiesKHR( + cl_context context, + const cl_svm_alloc_properties_khr* properties, + cl_uint svm_type_index, + size_t size, + cl_int* errcode_ret) +{ + CLIntercept* pIntercept = GetIntercept(); + + if( pIntercept ) + { + const auto& dispatchX = pIntercept->dispatchX(context); + if( dispatchX.clSVMAllocWithPropertiesKHR ) + { + GET_ENQUEUE_COUNTER(); + + std::string propsStr; + std::string typeStr; + if( pIntercept->config().CallLogging ) + { + pIntercept->getSVMAllocPropertiesString( + properties, + propsStr ); + pIntercept->getSVMTypeIndexCapabilitiesString( + context, + svm_type_index, + typeStr ); + } + CALL_LOGGING_ENTER( "context = %p, properties = [ %s ], svm_type_index = %s (%u), size = %zu", + context, + propsStr.c_str(), + typeStr.c_str(), + svm_type_index, + size ); + CHECK_ERROR_INIT( errcode_ret ); + HOST_PERFORMANCE_TIMING_START(); + + void* retVal = dispatchX.clSVMAllocWithPropertiesKHR( + context, + properties, + svm_type_index, + size, + errcode_ret ); + + HOST_PERFORMANCE_TIMING_END(); + ADD_SVM_ALLOCATION( retVal, size ); // TODO: Should this be SVM or USM? + CHECK_ERROR( errcode_ret[0] ); + ADD_POINTER_ALLOCATION( retVal ); + CALL_LOGGING_EXIT( errcode_ret[0], "returned %p", retVal ); + + return retVal; + } + } + + NULL_FUNCTION_POINTER_SET_ERROR_RETURN_NULL(errcode_ret, CL_INVALID_CONTEXT); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// cl_khr_unified_svm +CL_API_ENTRY cl_int CL_API_CALL clSVMFreeWithPropertiesKHR( + cl_context context, + const cl_svm_free_properties_khr* properties, + cl_svm_free_flags_khr flags, + void* ptr) +{ + CLIntercept* pIntercept = GetIntercept(); + + if( pIntercept ) + { + const auto& dispatchX = pIntercept->dispatchX(context); + if( dispatchX.clSVMFreeWithPropertiesKHR ) + { + GET_ENQUEUE_COUNTER(); + CALL_LOGGING_ENTER( "context = %p, ptr = %p", + context, + ptr ); + HOST_PERFORMANCE_TIMING_START(); + + cl_int retVal = dispatchX.clSVMFreeWithPropertiesKHR( + context, + properties, + flags, + ptr ); + + HOST_PERFORMANCE_TIMING_END(); + REMOVE_SVM_ALLOCATION( ptr ); // TODO: Should this be SVM or USM? + CHECK_ERROR( retVal ); + ADD_POINTER_FREE( ptr ); + CALL_LOGGING_EXIT( retVal ); + + return retVal; + } + } + + NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_CONTEXT); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// cl_khr_unified_svm +CL_API_ENTRY cl_int CL_API_CALL clGetSVMPointerInfoKHR( + cl_context context, + cl_device_id device, + const void* ptr, + cl_svm_pointer_info_khr param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret) +{ + CLIntercept* pIntercept = GetIntercept(); + + if( pIntercept ) + { + const auto& dispatchX = pIntercept->dispatchX(context); + if( dispatchX.clGetSVMPointerInfoKHR ) + { + GET_ENQUEUE_COUNTER(); + CALL_LOGGING_ENTER( "context = %p, ptr = %p, param_name = %s (%08X)", + context, + ptr, + pIntercept->enumName().name( param_name ).c_str(), + param_name ); + HOST_PERFORMANCE_TIMING_START(); + + cl_int retVal = dispatchX.clGetSVMPointerInfoKHR( + context, + device, + ptr, + param_name, + param_value_size, + param_value, + param_value_size_ret ); + + HOST_PERFORMANCE_TIMING_END(); + CHECK_ERROR( retVal ); + CALL_LOGGING_EXIT( retVal ); + + return retVal; + } + } + + NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_CONTEXT); +} + +/////////////////////////////////////////////////////////////////////////////// +// +// cl_khr_unified_svm +CL_API_ENTRY cl_int CL_API_CALL clGetSVMSuggestedTypeIndexKHR( + cl_context context, + cl_svm_capabilities_khr required_capabilities, + cl_svm_capabilities_khr desired_capabilities, + const cl_svm_alloc_properties_khr* properties, + size_t size, + cl_uint* suggested_svm_type_index) +{ + CLIntercept* pIntercept = GetIntercept(); + + if( pIntercept ) + { + const auto& dispatchX = pIntercept->dispatchX(context); + if( dispatchX.clGetSVMSuggestedTypeIndexKHR ) + { + GET_ENQUEUE_COUNTER(); + std::string propsStr; + if( pIntercept->config().CallLogging ) + { + pIntercept->getSVMAllocPropertiesString( + properties, + propsStr ); + } + CALL_LOGGING_ENTER( "context = %p, required_capabilities = %llX, desired_capabilities = %llX, properties = [ %s ], size = %zu", + context, + required_capabilities, + desired_capabilities, + propsStr.c_str(), + size ); + HOST_PERFORMANCE_TIMING_START(); + + cl_int retVal = dispatchX.clGetSVMSuggestedTypeIndexKHR( + context, + required_capabilities, + desired_capabilities, + properties, + size, + suggested_svm_type_index ); + + HOST_PERFORMANCE_TIMING_END(); + CHECK_ERROR( retVal ); + CALL_LOGGING_EXIT( retVal ); + + return retVal; + } + } + + NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_CONTEXT); +} + /////////////////////////////////////////////////////////////////////////////// // // cl_ext_image_requirements_info @@ -9806,7 +10006,7 @@ CL_API_ENTRY void* CL_API_CALL clHostMemAllocINTEL( } } - return NULL; + NULL_FUNCTION_POINTER_SET_ERROR_RETURN_NULL(errcode_ret, CL_INVALID_CONTEXT); } /////////////////////////////////////////////////////////////////////////////// @@ -9883,7 +10083,7 @@ CL_API_ENTRY void* CL_API_CALL clDeviceMemAllocINTEL( } } - return NULL; + NULL_FUNCTION_POINTER_SET_ERROR_RETURN_NULL(errcode_ret, CL_INVALID_CONTEXT); } /////////////////////////////////////////////////////////////////////////////// diff --git a/intercept/src/dispatch.h b/intercept/src/dispatch.h index 35f63616..40c808d5 100644 --- a/intercept/src/dispatch.h +++ b/intercept/src/dispatch.h @@ -487,6 +487,40 @@ struct CLdispatchX const size_t* global_work_size, size_t* suggested_local_work_size); + // cl_khr_unified_svm + void* (CL_API_CALL *clSVMAllocWithPropertiesKHR) ( + cl_context context, + const cl_svm_alloc_properties_khr* properties, + cl_uint svm_type_index, + size_t size, + cl_int* errcode_ret); + + // cl_khr_unified_svm + cl_int (CL_API_CALL *clSVMFreeWithPropertiesKHR) ( + cl_context context, + const cl_svm_free_properties_khr* properties, + cl_svm_free_flags_khr flags, + void* ptr); + + // cl_khr_unified_svm + cl_int (CL_API_CALL *clGetSVMPointerInfoKHR) ( + cl_context context, + cl_device_id device, + const void* ptr, + cl_svm_pointer_info_khr param_name, + size_t param_value_size, + void* param_value, + size_t* param_value_size_ret); + + // cl_khr_unified_svm + cl_int (CL_API_CALL *clGetSVMSuggestedTypeIndexKHR) ( + cl_context context, + cl_svm_capabilities_khr required_capabilities, + cl_svm_capabilities_khr desired_capabilities, + const cl_svm_alloc_properties_khr* properties, + size_t size, + cl_uint* suggested_svm_type_index); + // cl_ext_buffer_device_address cl_int (CL_API_CALL *clSetKernelArgDevicePointerEXT) ( cl_kernel kernel, diff --git a/intercept/src/enummap.cpp b/intercept/src/enummap.cpp index 09f9167a..80ecacce 100644 --- a/intercept/src/enummap.cpp +++ b/intercept/src/enummap.cpp @@ -883,9 +883,28 @@ CEnumNameMap::CEnumNameMap() ADD_ENUM_NAME( m_cl_int, CL_DEVICE_TERMINATE_CAPABILITY_KHR ); ADD_ENUM_NAME( m_cl_int, CL_CONTEXT_TERMINATE_KHR ); - // cl_khr_throttle_hints extension + // cl_khr_throttle_hints ADD_ENUM_NAME( m_cl_int, CL_QUEUE_THROTTLE_KHR ); + // cl_khr_unified_svm + ADD_ENUM_NAME( m_cl_int, CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR ); + + ADD_ENUM_NAME( m_cl_int, CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR ); + + ADD_ENUM_NAME( m_cl_int, CL_SVM_ALLOC_ASSOCIATED_DEVICE_HANDLE_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_ALLOC_ACCESS_FLAGS_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_ALLOC_ALIGNMENT_KHR ); + + ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_TYPE_INDEX_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_CAPABILITIES_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_PROPERTIES_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_ACCESS_FLAGS_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_BASE_PTR_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_SIZE_KHR ); + ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_ASSOCIATED_DEVICE_HANDLE_KHR ); + + ADD_ENUM_NAME( m_cl_int, CL_KERNEL_EXEC_INFO_SVM_INDIRECT_ACCESS_KHR ); + // cl_ext_atomic_counters ADD_ENUM_NAME( m_cl_int, CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT ); diff --git a/intercept/src/intercept.cpp b/intercept/src/intercept.cpp index d5737cc6..50bab880 100644 --- a/intercept/src/intercept.cpp +++ b/intercept/src/intercept.cpp @@ -1272,6 +1272,67 @@ void CLIntercept::callLoggingExit( va_end( args ); } +/////////////////////////////////////////////////////////////////////////////// +// +void CLIntercept::cachePlatformInfo() +{ + std::lock_guard lock(m_Mutex); + + if( m_PlatformInfoMap.empty() ) + { + cl_uint numPlatforms = 0; + dispatch().clGetPlatformIDs( + 0, + NULL, + &numPlatforms ); + if( numPlatforms ) + { + std::vector platforms( numPlatforms ); + dispatch().clGetPlatformIDs( + numPlatforms, + platforms.data(), + NULL ); + for( cl_uint i = 0; i < numPlatforms; i++ ) + { + cl_platform_id platform = platforms[i]; + SPlatformInfo& platformInfo = m_PlatformInfoMap[platform]; + + char* platformName = NULL; + + allocateAndGetPlatformInfoString( + platform, + CL_PLATFORM_NAME, + platformName ); + if( platformName ) + { + platformInfo.Name = platformName; + } + + size_t sz = 0; + dispatch().clGetPlatformInfo( + platform, + CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR, + 0, + NULL, + &sz ); + if( sz ) + { + const size_t numPlatformCaps = sz / sizeof(cl_svm_capabilities_khr); + platformInfo.SVMCapabilities.resize( numPlatformCaps ); + dispatch().clGetPlatformInfo( + platform, + CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR, + sz, + platformInfo.SVMCapabilities.data(), + NULL ); + } + + delete [] platformName; + } + } + } +} + /////////////////////////////////////////////////////////////////////////////// // void CLIntercept::cacheDeviceInfo( @@ -1949,26 +2010,9 @@ void CLIntercept::getPlatformInfoString( { str = ""; - cl_int errorCode = CL_SUCCESS; - - char* platformName = NULL; - - errorCode |= allocateAndGetPlatformInfoString( - platform, - CL_PLATFORM_NAME, - platformName ); - - if( errorCode != CL_SUCCESS ) + if( platform && m_PlatformInfoMap.find(platform) != m_PlatformInfoMap.end() ) { - CLI_ASSERT( 0 ); - str += "ERROR"; - } - else - { - if( platformName ) - { - str += platformName; - } + str += m_PlatformInfoMap.at(platform).Name; { char s[256]; CLI_SPRINTF( s, 256, " (%p)", @@ -1976,9 +2020,10 @@ void CLIntercept::getPlatformInfoString( str += s; } } - - delete [] platformName; - platformName = NULL; + else + { + str += "ERROR"; + } } /////////////////////////////////////////////////////////////////////////////// @@ -2521,6 +2566,123 @@ void CLIntercept::getMemPropertiesString( } } +/////////////////////////////////////////////////////////////////////////////// +// +void CLIntercept::getSVMAllocPropertiesString( + const cl_svm_alloc_properties_khr* properties, + std::string& str ) const +{ + str = ""; + + if( properties ) + { + char s[256]; + + while( properties[0] != 0 ) + { + cl_int property = (cl_int)properties[0]; + str += enumName().name( property ) + " = "; + + switch( property ) + { + case CL_SVM_ALLOC_ASSOCIATED_DEVICE_HANDLE_KHR: + { + auto pDevice = (const cl_device_id*)( properties + 1 ); + std::string deviceInfo; + getDeviceInfoString( + 1, + pDevice, + deviceInfo ); + str += deviceInfo; + properties += 2; + } + break; + case CL_SVM_ALLOC_ACCESS_FLAGS_KHR: + { + auto pAccessFlags = (const cl_svm_alloc_access_flags_khr*)( properties + 1); + CLI_SPRINTF( s, 256, "0x%" PRIx64, pAccessFlags[0] ); + str += s; + properties += 2; + } + break; + case CL_SVM_ALLOC_ALIGNMENT_KHR: + { + auto pAlignment = (const size_t*)( properties + 1); + CLI_SPRINTF( s, 256, "%zu", pAlignment[0] ); + str += s; + properties += 2; + } + break; + default: + { + CLI_SPRINTF( s, 256, "", (cl_uint)property ); + str += s; + // Advance by two properties. This may not be correct, + // but it's the best we can do when the property is + // unknown. + properties += 2; + } + break; + } + + if( properties[0] != 0 ) + { + str += ", "; + } + } + } + else + { + str = "NULL"; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// +void CLIntercept::getSVMTypeIndexCapabilitiesString( + cl_context context, + cl_uint typeIndex, + std::string& str ) const +{ + str = ""; + + cl_platform_id platform = getPlatform(context); + if( platform && m_PlatformInfoMap.find(platform) != m_PlatformInfoMap.end() ) + { + const SPlatformInfo& platformInfo = m_PlatformInfoMap.at(platform); + if( typeIndex >= platformInfo.SVMCapabilities.size() ) + { + str += "out of range!"; + } + else + { + cl_svm_capabilities_khr caps = platformInfo.SVMCapabilities[typeIndex]; + + auto appendToStr = [&str](const char* text) + { + if( !str.empty() ) str += "|"; + str += text; + }; + + if( caps & CL_SVM_CAPABILITY_SINGLE_ADDRESS_SPACE_KHR ) appendToStr("SAS"); + if( caps & CL_SVM_CAPABILITY_SYSTEM_ALLOCATED_KHR ) appendToStr("SA"); + if( caps & CL_SVM_CAPABILITY_DEVICE_OWNED_KHR ) appendToStr("DO"); + if( caps & CL_SVM_CAPABILITY_DEVICE_UNASSOCIATED_KHR ) appendToStr("DU"); + if( caps & CL_SVM_CAPABILITY_CONTEXT_ACCESS_KHR ) appendToStr("CTX"); + if( caps & CL_SVM_CAPABILITY_HOST_OWNED_KHR ) appendToStr("HO"); + if( caps & CL_SVM_CAPABILITY_HOST_READ_KHR ) appendToStr("HR"); + if( caps & CL_SVM_CAPABILITY_HOST_WRITE_KHR ) appendToStr("HW"); + if( caps & CL_SVM_CAPABILITY_HOST_MAP_KHR ) appendToStr("HM"); + if( caps & CL_SVM_CAPABILITY_DEVICE_READ_KHR ) appendToStr("DR"); + if( caps & CL_SVM_CAPABILITY_DEVICE_WRITE_KHR ) appendToStr("DW"); + if( caps & CL_SVM_CAPABILITY_DEVICE_ATOMIC_ACCESS_KHR ) appendToStr("DAA"); + if( caps & CL_SVM_CAPABILITY_CONCURRENT_ACCESS_KHR ) appendToStr("CA"); + if( caps & CL_SVM_CAPABILITY_CONCURRENT_ATOMIC_ACCESS_KHR ) appendToStr("CAA"); + if( caps & CL_SVM_CAPABILITY_INDIRECT_ACCESS_KHR ) appendToStr("IA"); + } + } +} + /////////////////////////////////////////////////////////////////////////////// // void CLIntercept::getSemaphorePropertiesString( @@ -13535,6 +13697,12 @@ void* CLIntercept::getExtensionFunctionAddress( // cl_khr_suggested_local_work_size CHECK_RETURN_EXTENSION_FUNCTION( clGetKernelSuggestedLocalWorkSizeKHR ); + // cl_khr_unified_svm + CHECK_RETURN_EXTENSION_FUNCTION( clSVMAllocWithPropertiesKHR ); + CHECK_RETURN_EXTENSION_FUNCTION( clSVMFreeWithPropertiesKHR ); + CHECK_RETURN_EXTENSION_FUNCTION( clGetSVMPointerInfoKHR ); + CHECK_RETURN_EXTENSION_FUNCTION( clGetSVMSuggestedTypeIndexKHR ); + // cl_ext_buffer_device_address CHECK_RETURN_EXTENSION_FUNCTION( clSetKernelArgDevicePointerEXT ); diff --git a/intercept/src/intercept.h b/intercept/src/intercept.h index 20094b0f..3bef1b97 100644 --- a/intercept/src/intercept.h +++ b/intercept/src/intercept.h @@ -93,8 +93,10 @@ class CLIntercept const char* formatStr, ... ); + void cachePlatformInfo(); void cacheDeviceInfo( cl_device_id device ); + void getDeviceIndexString( cl_device_id device, std::string& str ); @@ -168,6 +170,13 @@ class CLIntercept void getMemPropertiesString( const cl_mem_properties* properties, std::string& str ) const; + void getSVMAllocPropertiesString( + const cl_svm_alloc_properties_khr* properties, + std::string& str ) const; + void getSVMTypeIndexCapabilitiesString( + cl_context context, + cl_uint type_index, + std::string& str ) const; void getSemaphorePropertiesString( const cl_semaphore_properties_khr* properties, std::string& str ) const; @@ -1134,8 +1143,18 @@ class CLIntercept typedef std::unordered_map< std::string, SHostTimingStats > CHostTimingStatsMap; CHostTimingStatsMap m_HostTimingStatsMap; - // These structures define a mapping between a device ID handle and - // properties of a device, for easier querying. + // These structures define a mapping between a platform or device ID handle and + // properties of a platform or device, for easier querying. + + struct SPlatformInfo + { + std::string Name; + + std::vector SVMCapabilities; + }; + + typedef std::map< cl_platform_id, SPlatformInfo > CPlatformInfoMap; + CPlatformInfoMap m_PlatformInfoMap; struct SDeviceInfo { @@ -2048,9 +2067,22 @@ inline CObjectTracker& CLIntercept::objectTracker() pIntercept->objectTracker().AddPointerFree(_ptr); \ } +#define ADD_POINTER_FREES( free_callback, numSvmPointers, svmPointers ) \ + if( pIntercept->config().LeakChecking && \ + ( free_callback == nullptr ) ) \ + { \ + for( cl_uint i = 0; i < numSvmPointers; i++ ) \ + { \ + pIntercept->objectTracker().AddPointerFree(svmPointers[i]); \ + } \ + } + /////////////////////////////////////////////////////////////////////////////// // -#define LOG_CLINFO() \ +#define CACHE_PLATFORM_INFO() \ + pIntercept->cachePlatformInfo(); \ + +#define LOG_CL_INFO() \ if( pIntercept->config().CLInfoLogging ) \ { \ pIntercept->logCLInfo(); \