|
32 | 32 | // done here, for efficiency and simplicity.
|
33 | 33 | //
|
34 | 34 | #include <CL/opencl.h>
|
| 35 | +#include <CL/cl_usm_ext.h> |
35 | 36 | #include <cstdint>
|
36 | 37 |
|
37 | 38 | #ifdef __cplusplus
|
@@ -639,6 +640,16 @@ pi_result piProgramRelease(pi_program program);
|
639 | 640 | //
|
640 | 641 | // Kernel
|
641 | 642 | //
|
| 643 | + |
| 644 | +typedef enum { |
| 645 | + /// indicates that the kernel might access data through USM ptrs |
| 646 | + PI_USM_INDIRECT_ACCESS, |
| 647 | + /// provides an explicit list of pointers that the kernel will access |
| 648 | + PI_USM_PTRS = CL_KERNEL_EXEC_INFO_USM_PTRS_INTEL |
| 649 | +} _pi_kernel_exec_info; |
| 650 | + |
| 651 | +typedef _pi_kernel_exec_info pi_kernel_exec_info; |
| 652 | + |
642 | 653 | pi_result piKernelCreate(
|
643 | 654 | pi_program program,
|
644 | 655 | const char * kernel_name,
|
@@ -679,6 +690,33 @@ pi_result piKernelRetain(pi_kernel kernel);
|
679 | 690 |
|
680 | 691 | pi_result piKernelRelease(pi_kernel kernel);
|
681 | 692 |
|
| 693 | +/// Sets up pointer arguments for CL kernels. An extra indirection |
| 694 | +/// is required due to CL argument conventions. |
| 695 | +/// |
| 696 | +/// @param kernel is the kernel to be launched |
| 697 | +/// @param arg_index is the index of the kernel argument |
| 698 | +/// @param arg_size is the size in bytes of the argument (ignored in CL) |
| 699 | +/// @param arg_value is the pointer argument |
| 700 | +pi_result piextKernelSetArgPointer( |
| 701 | + pi_kernel kernel, |
| 702 | + pi_uint32 arg_index, |
| 703 | + size_t arg_size, |
| 704 | + const void * arg_value); |
| 705 | + |
| 706 | +/// API to set attributes controlling kernel execution |
| 707 | +/// |
| 708 | +/// @param kernel is the pi kernel to execute |
| 709 | +/// @param param_name is a pi_kernel_exec_info value that specifies the info |
| 710 | +/// passed to the kernel |
| 711 | +/// @param param_value_size is the size of the value in bytes |
| 712 | +/// @param param_value is a pointer to the value to set for the kernel |
| 713 | +/// |
| 714 | +/// If param_name is PI_USM_INDIRECT_ACCESS, the value will be a ptr to |
| 715 | +/// the pi_bool value PI_TRUE |
| 716 | +/// If param_name is PI_USM_PTRS, the value will be an array of ptrs |
| 717 | +pi_result piKernelSetExecInfo(pi_kernel kernel, pi_kernel_exec_info value_name, |
| 718 | + size_t param_value_size, const void *param_value); |
| 719 | + |
682 | 720 | //
|
683 | 721 | // Events
|
684 | 722 | //
|
@@ -929,6 +967,204 @@ pi_result piEnqueueMemUnmap(
|
929 | 967 | const pi_event * event_wait_list,
|
930 | 968 | pi_event * event);
|
931 | 969 |
|
| 970 | +/// |
| 971 | +// USM |
| 972 | +/// |
| 973 | +typedef enum { |
| 974 | + PI_USM_HOST_SUPPORT = CL_DEVICE_HOST_MEM_CAPABILITIES_INTEL, |
| 975 | + PI_USM_DEVICE_SUPPORT = CL_DEVICE_DEVICE_MEM_CAPABILITIES_INTEL, |
| 976 | + PI_USM_SINGLE_SHARED_SUPPORT = CL_DEVICE_SINGLE_DEVICE_SHARED_MEM_CAPABILITIES_INTEL, |
| 977 | + PI_USM_CROSS_SHARED_SUPPORT = CL_DEVICE_CROSS_DEVICE_SHARED_MEM_CAPABILITIES_INTEL, |
| 978 | + PI_USM_SYSTEM_SHARED_SUPPORT = CL_DEVICE_SHARED_SYSTEM_MEM_CAPABILITIES_INTEL |
| 979 | +} _pi_usm_capability_query; |
| 980 | + |
| 981 | +typedef enum : pi_bitfield { |
| 982 | + PI_USM_ACCESS = CL_UNIFIED_SHARED_MEMORY_ACCESS_INTEL, |
| 983 | + PI_USM_ATOMIC_ACCESS = CL_UNIFIED_SHARED_MEMORY_ATOMIC_ACCESS_INTEL, |
| 984 | + PI_USM_CONCURRENT_ACCESS = CL_UNIFIED_SHARED_MEMORY_CONCURRENT_ACCESS_INTEL, |
| 985 | + PI_USM_CONCURRENT_ATOMIC_ACCESS = CL_UNIFIED_SHARED_MEMORY_CONCURRENT_ATOMIC_ACCESS_INTEL |
| 986 | +} _pi_usm_capabilities; |
| 987 | + |
| 988 | +typedef enum { |
| 989 | + PI_MEM_ALLOC_TYPE = CL_MEM_ALLOC_TYPE_INTEL, |
| 990 | + PI_MEM_ALLOC_BASE_PTR = CL_MEM_ALLOC_BASE_PTR_INTEL, |
| 991 | + PI_MEM_ALLOC_SIZE = CL_MEM_ALLOC_SIZE_INTEL, |
| 992 | + PI_MEM_ALLOC_DEVICE = CL_MEM_ALLOC_DEVICE_INTEL, |
| 993 | + PI_MEM_ALLOC_INFO_TBD0 = CL_MEM_ALLOC_INFO_TBD0_INTEL, |
| 994 | + PI_MEM_ALLOC_INFO_TBD1 = CL_MEM_ALLOC_INFO_TBD1_INTEL, |
| 995 | +} _pi_mem_info; |
| 996 | + |
| 997 | +typedef enum { |
| 998 | + PI_MEM_TYPE_UNKNOWN = CL_MEM_TYPE_UNKNOWN_INTEL, |
| 999 | + PI_MEM_TYPE_HOST = CL_MEM_TYPE_HOST_INTEL, |
| 1000 | + PI_MEM_TYPE_DEVICE = CL_MEM_TYPE_DEVICE_INTEL, |
| 1001 | + PI_MEM_TYPE_SHARED = CL_MEM_TYPE_SHARED_INTEL |
| 1002 | +} _pi_usm_type; |
| 1003 | + |
| 1004 | +typedef enum : pi_bitfield { |
| 1005 | + PI_MEM_ALLOC_FLAGS = CL_MEM_ALLOC_FLAGS_INTEL |
| 1006 | +} _pi_usm_mem_properties; |
| 1007 | + |
| 1008 | +typedef enum : pi_bitfield { |
| 1009 | + PI_USM_MIGRATION_TBD0 = (1 << 0) |
| 1010 | +} _pi_usm_migration_flags; |
| 1011 | + |
| 1012 | +typedef _pi_usm_capability_query pi_usm_capability_query; |
| 1013 | +typedef _pi_usm_capabilities pi_usm_capabilities; |
| 1014 | +typedef _pi_mem_info pi_mem_info; |
| 1015 | +typedef _pi_usm_type pi_usm_type; |
| 1016 | +typedef _pi_usm_mem_properties pi_usm_mem_properties; |
| 1017 | +typedef _pi_usm_migration_flags pi_usm_migration_flags; |
| 1018 | + |
| 1019 | +/// Allocates host memory accessible by the device. |
| 1020 | +/// |
| 1021 | +/// @param result_ptr contains the allocated memory |
| 1022 | +/// @param context is the pi_context |
| 1023 | +/// @param pi_usm_mem_properties are optional allocation properties |
| 1024 | +/// @param size_t is the size of the allocation |
| 1025 | +/// @param alignment is the desired alignment of the allocation |
| 1026 | +pi_result piextUSMHostAlloc( |
| 1027 | + void ** result_ptr, |
| 1028 | + pi_context context, |
| 1029 | + pi_usm_mem_properties * properties, |
| 1030 | + size_t size, |
| 1031 | + pi_uint32 alignment); |
| 1032 | + |
| 1033 | +/// Allocates device memory |
| 1034 | +/// |
| 1035 | +/// @param result_ptr contains the allocated memory |
| 1036 | +/// @param context is the pi_context |
| 1037 | +/// @param device is the device the memory will be allocated on |
| 1038 | +/// @param pi_usm_mem_properties are optional allocation properties |
| 1039 | +/// @param size_t is the size of the allocation |
| 1040 | +/// @param alignment is the desired alignment of the allocation |
| 1041 | +pi_result piextUSMDeviceAlloc( |
| 1042 | + void ** result_ptr, |
| 1043 | + pi_context context, |
| 1044 | + pi_device device, |
| 1045 | + pi_usm_mem_properties * properties, |
| 1046 | + size_t size, |
| 1047 | + pi_uint32 alignment); |
| 1048 | + |
| 1049 | +/// Allocates memory accessible on both host and device |
| 1050 | +/// |
| 1051 | +/// @param result_ptr contains the allocated memory |
| 1052 | +/// @param context is the pi_context |
| 1053 | +/// @param device is the device the memory will be allocated on |
| 1054 | +/// @param pi_usm_mem_properties are optional allocation properties |
| 1055 | +/// @param size_t is the size of the allocation |
| 1056 | +/// @param alignment is the desired alignment of the allocation |
| 1057 | +pi_result piextUSMSharedAlloc( |
| 1058 | + void ** result_ptr, |
| 1059 | + pi_context context, |
| 1060 | + pi_device device, |
| 1061 | + pi_usm_mem_properties * properties, |
| 1062 | + size_t size, |
| 1063 | + pi_uint32 alignment); |
| 1064 | + |
| 1065 | +/// Frees allocated USM memory |
| 1066 | +/// |
| 1067 | +/// @param context is the pi_context of the allocation |
| 1068 | +/// @param ptr is the memory to be freed |
| 1069 | +pi_result piextUSMFree( |
| 1070 | + pi_context context, |
| 1071 | + void * ptr); |
| 1072 | + |
| 1073 | +/// USM Memset API |
| 1074 | +/// |
| 1075 | +/// @param queue is the queue to submit to |
| 1076 | +/// @param ptr is the ptr to memset |
| 1077 | +/// @param value is value to set. It is interpreted as an 8-bit value and the upper |
| 1078 | +/// 24 bits are ignored |
| 1079 | +/// @param count is the size in bytes to memset |
| 1080 | +/// @param num_events_in_waitlist is the number of events to wait on |
| 1081 | +/// @param events_waitlist is an array of events to wait on |
| 1082 | +/// @param event is the event that represents this operation |
| 1083 | +pi_result piextUSMEnqueueMemset( |
| 1084 | + pi_queue queue, |
| 1085 | + void * ptr, |
| 1086 | + pi_int32 value, |
| 1087 | + size_t count, |
| 1088 | + pi_uint32 num_events_in_waitlist, |
| 1089 | + const pi_event * events_waitlist, |
| 1090 | + pi_event * event); |
| 1091 | + |
| 1092 | +/// USM Memcpy API |
| 1093 | +/// |
| 1094 | +/// @param queue is the queue to submit to |
| 1095 | +/// @param blocking is whether this operation should block the host |
| 1096 | +/// @param src_ptr is the data to be copied |
| 1097 | +/// @param dst_ptr is the location the data will be copied |
| 1098 | +/// @param size is number of bytes to copy |
| 1099 | +/// @param num_events_in_waitlist is the number of events to wait on |
| 1100 | +/// @param events_waitlist is an array of events to wait on |
| 1101 | +/// @param event is the event that represents this operation |
| 1102 | +pi_result piextUSMEnqueueMemcpy( |
| 1103 | + pi_queue queue, |
| 1104 | + pi_bool blocking, |
| 1105 | + void * dst_ptr, |
| 1106 | + const void * src_ptr, |
| 1107 | + size_t size, |
| 1108 | + pi_uint32 num_events_in_waitlist, |
| 1109 | + const pi_event * events_waitlist, |
| 1110 | + pi_event * event); |
| 1111 | + |
| 1112 | +/// Hint to migrate memory to the device |
| 1113 | +/// |
| 1114 | +/// @param queue is the queue to submit to |
| 1115 | +/// @param ptr points to the memory to migrate |
| 1116 | +/// @param size is the number of bytes to migrate |
| 1117 | +/// @param flags is a bitfield used to specify memory migration options |
| 1118 | +/// @param num_events_in_waitlist is the number of events to wait on |
| 1119 | +/// @param events_waitlist is an array of events to wait on |
| 1120 | +/// @param event is the event that represents this operation |
| 1121 | +pi_result piextUSMEnqueuePrefetch( |
| 1122 | + pi_queue queue, |
| 1123 | + const void * ptr, |
| 1124 | + size_t size, |
| 1125 | + pi_usm_migration_flags flags, |
| 1126 | + pi_uint32 num_events_in_waitlist, |
| 1127 | + const pi_event * events_waitlist, |
| 1128 | + pi_event * event); |
| 1129 | + |
| 1130 | +/// USM Memadvise API |
| 1131 | +/// |
| 1132 | +/// @param queue is the queue to submit to |
| 1133 | +/// @param ptr is the data to be advised |
| 1134 | +/// @param length is the size in bytes of the meory to advise |
| 1135 | +/// @param advice is device specific advice |
| 1136 | +/// @param event is the event that represents this operation |
| 1137 | +// USM memadvise API to govern behavior of automatic migration mechanisms |
| 1138 | +pi_result piextUSMEnqueueMemAdvise( |
| 1139 | + pi_queue queue, |
| 1140 | + const void * ptr, |
| 1141 | + size_t length, |
| 1142 | + int advice, |
| 1143 | + pi_event * event); |
| 1144 | + |
| 1145 | +/// API to query information about USM allocated pointers |
| 1146 | +/// Valid Queries: |
| 1147 | +/// PI_MEM_ALLOC_TYPE returns host/device/shared pi_host_usm value |
| 1148 | +/// PI_MEM_ALLOC_BASE_PTR returns the base ptr of an allocation if |
| 1149 | +/// the queried pointer fell inside an allocation. |
| 1150 | +/// Result must fit in void * |
| 1151 | +/// PI_MEM_ALLOC_SIZE returns how big the queried pointer's |
| 1152 | +/// allocation is in bytes. Result is a size_t. |
| 1153 | +/// PI_MEM_ALLOC_DEVICE returns the pi_device this was allocated against |
| 1154 | +/// |
| 1155 | +/// @param context is the pi_context |
| 1156 | +/// @param ptr is the pointer to query |
| 1157 | +/// @param param_name is the type of query to perform |
| 1158 | +/// @param param_value_size is the size of the result in bytes |
| 1159 | +/// @param param_value is the result |
| 1160 | +/// @param param_value_ret is how many bytes were written |
| 1161 | +pi_result piextUSMGetMemAllocInfo( |
| 1162 | + pi_context context, |
| 1163 | + const void * ptr, |
| 1164 | + pi_mem_info param_name, |
| 1165 | + size_t param_value_size, |
| 1166 | + void * param_value, |
| 1167 | + size_t * param_value_size_ret); |
932 | 1168 |
|
933 | 1169 | struct _pi_plugin {
|
934 | 1170 | // PI version supported by host passed to the plugin. The Plugin
|
|
0 commit comments