Skip to content
86 changes: 86 additions & 0 deletions intercept/src/cli_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
222 changes: 211 additions & 11 deletions intercept/src/dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -5382,10 +5383,8 @@ CL_API_ENTRY void* CL_API_CALL CLIRN(clGetExtensionFunctionAddress)(

return retVal;
}
else
{
return NULL;
}

return NULL;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -5438,10 +5437,8 @@ CL_API_ENTRY void* CL_API_CALL CLIRN(clGetExtensionFunctionAddressForPlatform)(

return retVal;
}
else
{
return NULL;
}

return NULL;
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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);
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
Loading