Skip to content

Commit 7c5d2a1

Browse files
committed
initial extension loader support for cl_khr_unified_svm
1 parent a4f024d commit 7c5d2a1

File tree

4 files changed

+145
-10
lines changed

4 files changed

+145
-10
lines changed

scripts/call_all.c.mako

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ defaultValueForType = {
6868
'cl_mem_object_type' : 'CL_MEM_OBJECT_IMAGE2D',
6969
'cl_mipmap_filter_mode_img' : 'CL_MIPMAP_FILTER_ANY_IMG',
7070
'cl_semaphore_info_khr' : 'CL_SEMAPHORE_CONTEXT_KHR',
71+
'cl_svm_capabilities_khr' : 'CL_SVM_TYPE_MACRO_COARSE_GRAIN_BUFFER_KHR',
72+
'cl_svm_free_flags_khr' : 'CL_SVM_FREE_BLOCKING_KHR',
7173
'cl_svm_mem_flags_arm' : 'CL_MEM_SVM_FINE_GRAIN_BUFFER_ARM',
74+
'cl_svm_pointer_info_khr' : 'CL_SVM_INFO_TYPE_INDEX_KHR',
7275
'cl_va_api_device_source_intel' : 'CL_VA_API_DISPLAY_INTEL',
7376
'cl_va_api_device_set_intel' : 'CL_ALL_DEVICES_FOR_VA_API_INTEL',
7477
# Integral Types

scripts/openclext.cpp.mako

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ def getCParameterStrings(params):
181181

182182
#include <vector>
183183

184-
static inline cl_platform_id _get_platform(cl_platform_id platform)
185-
{
186-
return platform;
187-
}
188-
189184
static inline cl_platform_id _get_platform(cl_device_id device)
190185
{
191186
if (device == nullptr) return nullptr;

src/openclext.cpp

Lines changed: 135 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@
6464

6565
#include <vector>
6666

67-
static inline cl_platform_id _get_platform(cl_platform_id platform)
68-
{
69-
return platform;
70-
}
71-
7267
static inline cl_platform_id _get_platform(cl_device_id device)
7368
{
7469
if (device == nullptr) return nullptr;
@@ -756,6 +751,42 @@ typedef cl_int (CL_API_CALL* clTerminateContextKHR_clextfn)(
756751
#pragma message("Define for cl_khr_terminate_context was not found! Please update your headers.")
757752
#endif // defined(cl_khr_terminate_context)
758753

754+
#if defined(cl_khr_unified_svm)
755+
756+
typedef void* (CL_API_CALL* clSVMAllocWithPropertiesKHR_clextfn)(
757+
cl_context context,
758+
const cl_svm_alloc_properties_khr* properties,
759+
cl_uint svm_type_index,
760+
size_t size,
761+
cl_int* errcode_ret);
762+
763+
typedef cl_int (CL_API_CALL* clSVMFreeWithPropertiesKHR_clextfn)(
764+
cl_context context,
765+
const cl_svm_free_properties_khr* properties,
766+
cl_svm_free_flags_khr flags,
767+
void* ptr);
768+
769+
typedef cl_int (CL_API_CALL* clGetSVMPointerInfoKHR_clextfn)(
770+
cl_context context,
771+
cl_device_id device,
772+
const void* ptr,
773+
cl_svm_pointer_info_khr param_name,
774+
size_t param_value_size,
775+
void* param_value,
776+
size_t* param_value_size_ret);
777+
778+
typedef cl_int (CL_API_CALL* clGetSVMSuggestedTypeIndexKHR_clextfn)(
779+
cl_context context,
780+
cl_svm_capabilities_khr required_capabilities,
781+
cl_svm_capabilities_khr desired_capabilities,
782+
const cl_svm_alloc_properties_khr* properties,
783+
size_t size,
784+
cl_uint* suggested_svm_type_index);
785+
786+
#else
787+
#pragma message("Define for cl_khr_unified_svm was not found! Please update your headers.")
788+
#endif // defined(cl_khr_unified_svm)
789+
759790
#if defined(cl_ext_device_fission)
760791

761792
typedef cl_int (CL_API_CALL* clReleaseDeviceEXT_clextfn)(
@@ -1445,6 +1476,13 @@ struct openclext_dispatch_table {
14451476
clTerminateContextKHR_clextfn clTerminateContextKHR;
14461477
#endif // defined(cl_khr_terminate_context)
14471478

1479+
#if defined(cl_khr_unified_svm)
1480+
clSVMAllocWithPropertiesKHR_clextfn clSVMAllocWithPropertiesKHR;
1481+
clSVMFreeWithPropertiesKHR_clextfn clSVMFreeWithPropertiesKHR;
1482+
clGetSVMPointerInfoKHR_clextfn clGetSVMPointerInfoKHR;
1483+
clGetSVMSuggestedTypeIndexKHR_clextfn clGetSVMSuggestedTypeIndexKHR;
1484+
#endif // defined(cl_khr_unified_svm)
1485+
14481486
#if defined(cl_ext_device_fission)
14491487
clReleaseDeviceEXT_clextfn clReleaseDeviceEXT;
14501488
clRetainDeviceEXT_clextfn clRetainDeviceEXT;
@@ -1721,6 +1759,13 @@ static void _init(cl_platform_id platform, openclext_dispatch_table* dispatch_pt
17211759
CLEXT_GET_EXTENSION(clTerminateContextKHR);
17221760
#endif // defined(cl_khr_terminate_context)
17231761

1762+
#if defined(cl_khr_unified_svm)
1763+
CLEXT_GET_EXTENSION(clSVMAllocWithPropertiesKHR);
1764+
CLEXT_GET_EXTENSION(clSVMFreeWithPropertiesKHR);
1765+
CLEXT_GET_EXTENSION(clGetSVMPointerInfoKHR);
1766+
CLEXT_GET_EXTENSION(clGetSVMSuggestedTypeIndexKHR);
1767+
#endif // defined(cl_khr_unified_svm)
1768+
17241769
#if defined(cl_ext_device_fission)
17251770
CLEXT_GET_EXTENSION(clReleaseDeviceEXT);
17261771
CLEXT_GET_EXTENSION(clRetainDeviceEXT);
@@ -3414,6 +3459,91 @@ cl_int CL_API_CALL clTerminateContextKHR(
34143459

34153460
#endif // defined(cl_khr_terminate_context)
34163461

3462+
#if defined(cl_khr_unified_svm)
3463+
3464+
void* CL_API_CALL clSVMAllocWithPropertiesKHR(
3465+
cl_context context,
3466+
const cl_svm_alloc_properties_khr* properties,
3467+
cl_uint svm_type_index,
3468+
size_t size,
3469+
cl_int* errcode_ret)
3470+
{
3471+
struct openclext_dispatch_table* dispatch_ptr = _get_dispatch(context);
3472+
if (dispatch_ptr == nullptr || dispatch_ptr->clSVMAllocWithPropertiesKHR == nullptr) {
3473+
if (errcode_ret) *errcode_ret = CL_INVALID_OPERATION;
3474+
return nullptr;
3475+
}
3476+
return dispatch_ptr->clSVMAllocWithPropertiesKHR(
3477+
context,
3478+
properties,
3479+
svm_type_index,
3480+
size,
3481+
errcode_ret);
3482+
}
3483+
3484+
cl_int CL_API_CALL clSVMFreeWithPropertiesKHR(
3485+
cl_context context,
3486+
const cl_svm_free_properties_khr* properties,
3487+
cl_svm_free_flags_khr flags,
3488+
void* ptr)
3489+
{
3490+
struct openclext_dispatch_table* dispatch_ptr = _get_dispatch(context);
3491+
if (dispatch_ptr == nullptr || dispatch_ptr->clSVMFreeWithPropertiesKHR == nullptr) {
3492+
return CL_INVALID_OPERATION;
3493+
}
3494+
return dispatch_ptr->clSVMFreeWithPropertiesKHR(
3495+
context,
3496+
properties,
3497+
flags,
3498+
ptr);
3499+
}
3500+
3501+
cl_int CL_API_CALL clGetSVMPointerInfoKHR(
3502+
cl_context context,
3503+
cl_device_id device,
3504+
const void* ptr,
3505+
cl_svm_pointer_info_khr param_name,
3506+
size_t param_value_size,
3507+
void* param_value,
3508+
size_t* param_value_size_ret)
3509+
{
3510+
struct openclext_dispatch_table* dispatch_ptr = _get_dispatch(context);
3511+
if (dispatch_ptr == nullptr || dispatch_ptr->clGetSVMPointerInfoKHR == nullptr) {
3512+
return CL_INVALID_OPERATION;
3513+
}
3514+
return dispatch_ptr->clGetSVMPointerInfoKHR(
3515+
context,
3516+
device,
3517+
ptr,
3518+
param_name,
3519+
param_value_size,
3520+
param_value,
3521+
param_value_size_ret);
3522+
}
3523+
3524+
cl_int CL_API_CALL clGetSVMSuggestedTypeIndexKHR(
3525+
cl_context context,
3526+
cl_svm_capabilities_khr required_capabilities,
3527+
cl_svm_capabilities_khr desired_capabilities,
3528+
const cl_svm_alloc_properties_khr* properties,
3529+
size_t size,
3530+
cl_uint* suggested_svm_type_index)
3531+
{
3532+
struct openclext_dispatch_table* dispatch_ptr = _get_dispatch(context);
3533+
if (dispatch_ptr == nullptr || dispatch_ptr->clGetSVMSuggestedTypeIndexKHR == nullptr) {
3534+
return CL_INVALID_OPERATION;
3535+
}
3536+
return dispatch_ptr->clGetSVMSuggestedTypeIndexKHR(
3537+
context,
3538+
required_capabilities,
3539+
desired_capabilities,
3540+
properties,
3541+
size,
3542+
suggested_svm_type_index);
3543+
}
3544+
3545+
#endif // defined(cl_khr_unified_svm)
3546+
34173547
#if defined(cl_ext_device_fission)
34183548

34193549
cl_int CL_API_CALL clReleaseDeviceEXT(

tests/call_all.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ void call_all(void)
161161
clTerminateContextKHR(NULL);
162162
#endif // cl_khr_terminate_context
163163

164+
#ifdef cl_khr_unified_svm
165+
clSVMAllocWithPropertiesKHR(NULL, NULL, 0, 0, NULL);
166+
clSVMFreeWithPropertiesKHR(NULL, NULL, CL_SVM_FREE_BLOCKING_KHR, NULL);
167+
clGetSVMPointerInfoKHR(NULL, NULL, NULL, CL_SVM_INFO_TYPE_INDEX_KHR, 0, NULL, NULL);
168+
clGetSVMSuggestedTypeIndexKHR(NULL, CL_SVM_TYPE_MACRO_COARSE_GRAIN_BUFFER_KHR, CL_SVM_TYPE_MACRO_COARSE_GRAIN_BUFFER_KHR, NULL, 0, NULL);
169+
#endif // cl_khr_unified_svm
170+
164171
#ifdef cl_ext_device_fission
165172
clReleaseDeviceEXT(NULL);
166173
clRetainDeviceEXT(NULL);

0 commit comments

Comments
 (0)