Skip to content

Commit b35286f

Browse files
committed
initial support for cl_khr_unified_svm
1 parent f21e764 commit b35286f

File tree

6 files changed

+407
-11
lines changed

6 files changed

+407
-11
lines changed

intercept/src/cli_ext.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,94 @@ cl_int CL_API_CALL clGetKernelSuggestedLocalWorkSizeKHR(
975975
#define CL_QUEUE_THROTTLE_MED_KHR (1<<1)
976976
#define CL_QUEUE_THROTTLE_LOW_KHR (1<<2)
977977

978+
///////////////////////////////////////////////////////////////////////////////
979+
// cl_khr_unified_svm
980+
981+
// Note: This implements the proposed extension version 0.2.0.
982+
983+
#define CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR 0x0909
984+
985+
#define CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR 0x1077
986+
987+
typedef cl_bitfield cl_svm_capabilities_khr;
988+
989+
#define CL_SVM_CAPABILITY_SINGLE_ADDRESS_SPACE_KHR (1 << 0)
990+
#define CL_SVM_CAPABILITY_SYSTEM_ALLOCATED_KHR (1 << 1)
991+
#define CL_SVM_CAPABILITY_DEVICE_OWNED_KHR (1 << 2)
992+
#define CL_SVM_CAPABILITY_DEVICE_UNASSOCIATED_KHR (1 << 3)
993+
#define CL_SVM_CAPABILITY_CONTEXT_ACCESS_KHR (1 << 4)
994+
#define CL_SVM_CAPABILITY_HOST_OWNED_KHR (1 << 5)
995+
#define CL_SVM_CAPABILITY_HOST_READ_KHR (1 << 6)
996+
#define CL_SVM_CAPABILITY_HOST_WRITE_KHR (1 << 7)
997+
#define CL_SVM_CAPABILITY_HOST_MAP_KHR (1 << 8)
998+
#define CL_SVM_CAPABILITY_DEVICE_READ_KHR (1 << 9)
999+
#define CL_SVM_CAPABILITY_DEVICE_WRITE_KHR (1 << 10)
1000+
#define CL_SVM_CAPABILITY_DEVICE_ATOMIC_ACCESS_KHR (1 << 11)
1001+
#define CL_SVM_CAPABILITY_CONCURRENT_ACCESS_KHR (1 << 12)
1002+
#define CL_SVM_CAPABILITY_CONCURRENT_ATOMIC_ACCESS_KHR (1 << 13)
1003+
#define CL_SVM_CAPABILITY_INDIRECT_ACCESS_KHR (1 << 14)
1004+
1005+
typedef cl_properties cl_svm_alloc_properties_khr;
1006+
typedef cl_bitfield cl_svm_alloc_access_flags_khr;
1007+
typedef cl_properties cl_svm_free_properties_khr;
1008+
typedef cl_bitfield cl_svm_free_flags_khr;
1009+
typedef cl_uint cl_svm_pointer_info_khr;
1010+
1011+
#define CL_SVM_ALLOC_ASSOCIATED_DEVICE_HANDLE_KHR 0x2078
1012+
#define CL_SVM_ALLOC_ACCESS_FLAGS_KHR 0x2079
1013+
#define CL_SVM_ALLOC_ALIGNMENT_KHR 0x207A
1014+
1015+
#define CL_SVM_ALLOC_ACCESS_HOST_NOREAD_KHR (1 << 0)
1016+
#define CL_SVM_ALLOC_ACCESS_HOST_NOWRITE_KHR (1 << 1)
1017+
#define CL_SVM_ALLOC_ACCESS_DEVICE_NOREAD_KHR (1 << 8)
1018+
#define CL_SVM_ALLOC_ACCESS_DEVICE_NOWRITE_KHR (1 << 9)
1019+
1020+
#define CL_SVM_FREE_BLOCKING_KHR (1 << 0)
1021+
1022+
#define CL_SVM_INFO_TYPE_INDEX_KHR 0x2088
1023+
#define CL_SVM_INFO_CAPABILITIES_KHR 0x2089
1024+
#define CL_SVM_INFO_PROPERTIES_KHR 0x208A
1025+
#define CL_SVM_INFO_ACCESS_FLAGS_KHR 0x208B
1026+
#define CL_SVM_INFO_BASE_PTR_KHR 0x419B
1027+
#define CL_SVM_INFO_SIZE_KHR 0x419C
1028+
#define CL_SVM_INFO_ASSOCIATED_DEVICE_HANDLE_KHR 0x419D
1029+
1030+
#define CL_KERNEL_EXEC_INFO_SVM_INDIRECT_ACCESS_KHR 0x11BB
1031+
1032+
extern CL_API_ENTRY
1033+
void* CL_API_CALL clSVMAllocWithPropertiesKHR(
1034+
cl_context context,
1035+
const cl_svm_alloc_properties_khr* properties,
1036+
cl_uint svm_type_index,
1037+
size_t size,
1038+
cl_int* errcode_ret);
1039+
1040+
extern CL_API_ENTRY
1041+
cl_int CL_API_CALL clSVMFreeWithPropertiesKHR(
1042+
cl_context context,
1043+
const cl_svm_free_properties_khr* properties,
1044+
cl_svm_free_flags_khr flags,
1045+
void* ptr);
1046+
1047+
extern CL_API_ENTRY
1048+
cl_int CL_API_CALL clGetSVMPointerInfoKHR(
1049+
cl_context context,
1050+
cl_device_id device,
1051+
const void* ptr,
1052+
cl_svm_pointer_info_khr param_name,
1053+
size_t param_value_size,
1054+
void* param_value,
1055+
size_t* param_value_size_ret);
1056+
1057+
extern CL_API_ENTRY
1058+
cl_int CL_API_CALL clGetSVMSuggestedTypeIndexKHR(
1059+
cl_context context,
1060+
cl_svm_capabilities_khr required_capabilities,
1061+
cl_svm_capabilities_khr desired_capabilities,
1062+
const cl_svm_alloc_properties_khr* properties,
1063+
size_t size,
1064+
cl_uint* suggested_svm_type_index);
1065+
9781066
///////////////////////////////////////////////////////////////////////////////
9791067
// cl_ext_atomic_counters
9801068

intercept/src/dispatch.cpp

Lines changed: 185 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5378,10 +5378,8 @@ CL_API_ENTRY void* CL_API_CALL CLIRN(clGetExtensionFunctionAddress)(
53785378

53795379
return retVal;
53805380
}
5381-
else
5382-
{
5383-
return NULL;
5384-
}
5381+
5382+
return NULL;
53855383
}
53865384

53875385
///////////////////////////////////////////////////////////////////////////////
@@ -5434,10 +5432,8 @@ CL_API_ENTRY void* CL_API_CALL CLIRN(clGetExtensionFunctionAddressForPlatform)(
54345432

54355433
return retVal;
54365434
}
5437-
else
5438-
{
5439-
return NULL;
5440-
}
5435+
5436+
return NULL;
54415437
}
54425438

54435439
///////////////////////////////////////////////////////////////////////////////
@@ -8913,6 +8909,185 @@ CL_API_ENTRY cl_int CL_API_CALL clGetKernelSuggestedLocalWorkSizeKHR(
89138909
NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_COMMAND_QUEUE);
89148910
}
89158911

8912+
///////////////////////////////////////////////////////////////////////////////
8913+
//
8914+
// cl_khr_unified_svm
8915+
CL_API_ENTRY void* CL_API_CALL clSVMAllocWithPropertiesKHR(
8916+
cl_context context,
8917+
const cl_svm_alloc_properties_khr* properties,
8918+
cl_uint svm_type_index,
8919+
size_t size,
8920+
cl_int* errcode_ret)
8921+
{
8922+
CLIntercept* pIntercept = GetIntercept();
8923+
8924+
if( pIntercept )
8925+
{
8926+
const auto& dispatchX = pIntercept->dispatchX(context);
8927+
if( dispatchX.clSVMAllocWithPropertiesKHR )
8928+
{
8929+
GET_ENQUEUE_COUNTER();
8930+
8931+
std::string propsStr;
8932+
if( pIntercept->config().CallLogging )
8933+
{
8934+
pIntercept->getSVMAllocPropertiesString(
8935+
properties,
8936+
propsStr );
8937+
}
8938+
CALL_LOGGING_ENTER( "context = %p, properties = [ %s ], svm_type_index = %u, size = %zu",
8939+
context,
8940+
propsStr.c_str(),
8941+
svm_type_index,
8942+
size );
8943+
CHECK_ERROR_INIT( errcode_ret );
8944+
HOST_PERFORMANCE_TIMING_START();
8945+
8946+
void* retVal = dispatchX.clSVMAllocWithPropertiesKHR(
8947+
context,
8948+
properties,
8949+
svm_type_index,
8950+
size,
8951+
errcode_ret );
8952+
8953+
HOST_PERFORMANCE_TIMING_END();
8954+
ADD_SVM_ALLOCATION( retVal, size ); // TODO: Should this be SVM or USM?
8955+
CHECK_ERROR( errcode_ret[0] );
8956+
ADD_POINTER_ALLOCATION( retVal );
8957+
CALL_LOGGING_EXIT( errcode_ret[0], "returned %p", retVal );
8958+
8959+
return retVal;
8960+
}
8961+
}
8962+
8963+
NULL_FUNCTION_POINTER_SET_ERROR_RETURN_NULL(errcode_ret, CL_INVALID_CONTEXT);
8964+
}
8965+
8966+
///////////////////////////////////////////////////////////////////////////////
8967+
//
8968+
// cl_khr_unified_svm
8969+
CL_API_ENTRY cl_int CL_API_CALL clSVMFreeWithPropertiesKHR(
8970+
cl_context context,
8971+
const cl_svm_free_properties_khr* properties,
8972+
cl_svm_free_flags_khr flags,
8973+
void* ptr)
8974+
{
8975+
CLIntercept* pIntercept = GetIntercept();
8976+
8977+
if( pIntercept )
8978+
{
8979+
const auto& dispatchX = pIntercept->dispatchX(context);
8980+
if( dispatchX.clSVMFreeWithPropertiesKHR )
8981+
{
8982+
GET_ENQUEUE_COUNTER();
8983+
CALL_LOGGING_ENTER( "context = %p, ptr = %p",
8984+
context,
8985+
ptr );
8986+
HOST_PERFORMANCE_TIMING_START();
8987+
8988+
cl_int retVal = dispatchX.clSVMFreeWithPropertiesKHR(
8989+
context,
8990+
properties,
8991+
flags,
8992+
ptr );
8993+
8994+
HOST_PERFORMANCE_TIMING_END();
8995+
REMOVE_SVM_ALLOCATION( ptr ); // TODO: Should this be SVM or USM?
8996+
CHECK_ERROR( retVal );
8997+
ADD_POINTER_FREE( ptr );
8998+
CALL_LOGGING_EXIT( retVal );
8999+
9000+
return retVal;
9001+
}
9002+
}
9003+
9004+
NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_CONTEXT);
9005+
}
9006+
9007+
///////////////////////////////////////////////////////////////////////////////
9008+
//
9009+
// cl_khr_unified_svm
9010+
CL_API_ENTRY cl_int CL_API_CALL clGetSVMPointerInfoKHR(
9011+
cl_context context,
9012+
cl_device_id device,
9013+
const void* ptr,
9014+
cl_svm_pointer_info_khr param_name,
9015+
size_t param_value_size,
9016+
void* param_value,
9017+
size_t* param_value_size_ret)
9018+
{
9019+
CLIntercept* pIntercept = GetIntercept();
9020+
9021+
if( pIntercept )
9022+
{
9023+
const auto& dispatchX = pIntercept->dispatchX(context);
9024+
if( dispatchX.clGetSVMPointerInfoKHR )
9025+
{
9026+
GET_ENQUEUE_COUNTER();
9027+
CALL_LOGGING_ENTER();
9028+
HOST_PERFORMANCE_TIMING_START();
9029+
9030+
cl_int retVal = dispatchX.clGetSVMPointerInfoKHR(
9031+
context,
9032+
device,
9033+
ptr,
9034+
param_name,
9035+
param_value_size,
9036+
param_value,
9037+
param_value_size_ret );
9038+
9039+
HOST_PERFORMANCE_TIMING_END();
9040+
CHECK_ERROR( retVal );
9041+
CALL_LOGGING_EXIT( retVal );
9042+
9043+
return retVal;
9044+
}
9045+
}
9046+
9047+
NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_CONTEXT);
9048+
}
9049+
9050+
///////////////////////////////////////////////////////////////////////////////
9051+
//
9052+
// cl_khr_unified_svm
9053+
CL_API_ENTRY cl_int CL_API_CALL clGetSVMSuggestedTypeIndexKHR(
9054+
cl_context context,
9055+
cl_svm_capabilities_khr required_capabilities,
9056+
cl_svm_capabilities_khr desired_capabilities,
9057+
const cl_svm_alloc_properties_khr* properties,
9058+
size_t size,
9059+
cl_uint* suggested_svm_type_index)
9060+
{
9061+
CLIntercept* pIntercept = GetIntercept();
9062+
9063+
if( pIntercept )
9064+
{
9065+
const auto& dispatchX = pIntercept->dispatchX(context);
9066+
if( dispatchX.clGetSVMSuggestedTypeIndexKHR )
9067+
{
9068+
GET_ENQUEUE_COUNTER();
9069+
CALL_LOGGING_ENTER();
9070+
HOST_PERFORMANCE_TIMING_START();
9071+
9072+
cl_int retVal = dispatchX.clGetSVMSuggestedTypeIndexKHR(
9073+
context,
9074+
required_capabilities,
9075+
desired_capabilities,
9076+
properties,
9077+
size,
9078+
suggested_svm_type_index );
9079+
9080+
HOST_PERFORMANCE_TIMING_END();
9081+
CHECK_ERROR( retVal );
9082+
CALL_LOGGING_EXIT( retVal );
9083+
9084+
return retVal;
9085+
}
9086+
}
9087+
9088+
NULL_FUNCTION_POINTER_RETURN_ERROR(CL_INVALID_CONTEXT);
9089+
}
9090+
89169091
///////////////////////////////////////////////////////////////////////////////
89179092
//
89189093
// cl_ext_image_requirements_info
@@ -9750,7 +9925,7 @@ CL_API_ENTRY void* CL_API_CALL clHostMemAllocINTEL(
97509925
}
97519926
}
97529927

9753-
return NULL;
9928+
NULL_FUNCTION_POINTER_SET_ERROR_RETURN_NULL(errcode_ret, CL_INVALID_CONTEXT);
97549929
}
97559930

97569931
///////////////////////////////////////////////////////////////////////////////
@@ -9827,7 +10002,7 @@ CL_API_ENTRY void* CL_API_CALL clDeviceMemAllocINTEL(
982710002
}
982810003
}
982910004

9830-
return NULL;
10005+
NULL_FUNCTION_POINTER_SET_ERROR_RETURN_NULL(errcode_ret, CL_INVALID_CONTEXT);
983110006
}
983210007

983310008
///////////////////////////////////////////////////////////////////////////////

intercept/src/dispatch.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,40 @@ struct CLdispatchX
487487
const size_t* global_work_size,
488488
size_t* suggested_local_work_size);
489489

490+
// cl_khr_unified_svm
491+
void* (CL_API_CALL *clSVMAllocWithPropertiesKHR) (
492+
cl_context context,
493+
const cl_svm_alloc_properties_khr* properties,
494+
cl_uint svm_type_index,
495+
size_t size,
496+
cl_int* errcode_ret);
497+
498+
// cl_khr_unified_svm
499+
cl_int (CL_API_CALL *clSVMFreeWithPropertiesKHR) (
500+
cl_context context,
501+
const cl_svm_free_properties_khr* properties,
502+
cl_svm_free_flags_khr flags,
503+
void* ptr);
504+
505+
// cl_khr_unified_svm
506+
cl_int (CL_API_CALL *clGetSVMPointerInfoKHR) (
507+
cl_context context,
508+
cl_device_id device,
509+
const void* ptr,
510+
cl_svm_pointer_info_khr param_name,
511+
size_t param_value_size,
512+
void* param_value,
513+
size_t* param_value_size_ret);
514+
515+
// cl_khr_unified_svm
516+
cl_int (CL_API_CALL *clGetSVMSuggestedTypeIndexKHR) (
517+
cl_context context,
518+
cl_svm_capabilities_khr required_capabilities,
519+
cl_svm_capabilities_khr desired_capabilities,
520+
const cl_svm_alloc_properties_khr* properties,
521+
size_t size,
522+
cl_uint* suggested_svm_type_index);
523+
490524
// cl_ext_image_requirements_info
491525
cl_int (CL_API_CALL *clGetImageRequirementsInfoEXT) (
492526
cl_context context,

intercept/src/enummap.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,28 @@ CEnumNameMap::CEnumNameMap()
876876
ADD_ENUM_NAME( m_cl_int, CL_DEVICE_TERMINATE_CAPABILITY_KHR );
877877
ADD_ENUM_NAME( m_cl_int, CL_CONTEXT_TERMINATE_KHR );
878878

879-
// cl_khr_throttle_hints extension
879+
// cl_khr_throttle_hints
880880
ADD_ENUM_NAME( m_cl_int, CL_QUEUE_THROTTLE_KHR );
881881

882+
// cl_khr_unified_svm
883+
ADD_ENUM_NAME( m_cl_int, CL_PLATFORM_SVM_TYPE_CAPABILITIES_KHR );
884+
885+
ADD_ENUM_NAME( m_cl_int, CL_DEVICE_SVM_TYPE_CAPABILITIES_KHR );
886+
887+
ADD_ENUM_NAME( m_cl_int, CL_SVM_ALLOC_ASSOCIATED_DEVICE_HANDLE_KHR );
888+
ADD_ENUM_NAME( m_cl_int, CL_SVM_ALLOC_ACCESS_FLAGS_KHR );
889+
ADD_ENUM_NAME( m_cl_int, CL_SVM_ALLOC_ALIGNMENT_KHR );
890+
891+
ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_TYPE_INDEX_KHR );
892+
ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_CAPABILITIES_KHR );
893+
ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_PROPERTIES_KHR );
894+
ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_ACCESS_FLAGS_KHR );
895+
ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_BASE_PTR_KHR );
896+
ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_SIZE_KHR );
897+
ADD_ENUM_NAME( m_cl_int, CL_SVM_INFO_ASSOCIATED_DEVICE_HANDLE_KHR );
898+
899+
ADD_ENUM_NAME( m_cl_int, CL_KERNEL_EXEC_INFO_SVM_INDIRECT_ACCESS_KHR );
900+
882901
// cl_ext_atomic_counters
883902
ADD_ENUM_NAME( m_cl_int, CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT );
884903

0 commit comments

Comments
 (0)