Skip to content

Commit f67949a

Browse files
author
Steffen Larsen
committed
[SYCL][PI] Splitting the converter function
Signed-off-by: Steffen Larsen <[email protected]>
1 parent a884b13 commit f67949a

20 files changed

+431
-223
lines changed

sycl/include/CL/sycl/detail/buffer_impl.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ class __SYCL_EXPORT buffer_impl final : public SYCLMemObjT {
4444
using typename BaseT::MemObjType;
4545

4646
public:
47-
static constexpr pi_handle_type PIHandleType = PI_NATIVE_HANDLE_MEM;
48-
4947
buffer_impl(size_t SizeInBytes, size_t RequiredAlign,
5048
const property_list &Props,
5149
unique_ptr_class<SYCLMemObjAllocator> Allocator)

sycl/include/CL/sycl/detail/pi.def

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,31 @@
1818
_PI_API(piPlatformsGet)
1919
_PI_API(piPlatformGetInfo)
2020
// Device
21-
_PI_API(piextDeviceConvert)
2221
_PI_API(piDevicesGet)
2322
_PI_API(piDeviceGetInfo)
2423
_PI_API(piDevicePartition)
2524
_PI_API(piDeviceRetain)
2625
_PI_API(piDeviceRelease)
2726
_PI_API(piextDeviceSelectBinary)
2827
_PI_API(piextGetDeviceFunctionPointer)
28+
_PI_API(piextDeviceGetNativeHandle)
29+
_PI_API(piextDeviceCreateWithNativeHandle)
2930
// Context
3031
_PI_API(piContextCreate)
3132
_PI_API(piContextGetInfo)
3233
_PI_API(piContextRetain)
3334
_PI_API(piContextRelease)
3435
_PI_API(piextContextSetExtendedDeleter)
36+
_PI_API(piextContextGetNativeHandle)
37+
_PI_API(piextContextCreateWithNativeHandle)
3538
// Queue
3639
_PI_API(piQueueCreate)
3740
_PI_API(piQueueGetInfo)
3841
_PI_API(piQueueFinish)
3942
_PI_API(piQueueRetain)
4043
_PI_API(piQueueRelease)
44+
_PI_API(piextQueueGetNativeHandle)
45+
_PI_API(piextQueueCreateWithNativeHandle)
4146
// Memory
4247
_PI_API(piMemBufferCreate)
4348
_PI_API(piMemImageCreate)
@@ -46,8 +51,9 @@ _PI_API(piMemImageGetInfo)
4651
_PI_API(piMemRetain)
4752
_PI_API(piMemRelease)
4853
_PI_API(piMemBufferPartition)
54+
_PI_API(piextMemGetNativeHandle)
55+
_PI_API(piextMemCreateWithNativeHandle)
4956
// Program
50-
_PI_API(piextProgramConvert)
5157
_PI_API(piProgramCreate)
5258
_PI_API(piclProgramCreateWithSource)
5359
_PI_API(piclProgramCreateWithBinary)
@@ -59,6 +65,8 @@ _PI_API(piProgramGetBuildInfo)
5965
_PI_API(piProgramRetain)
6066
_PI_API(piProgramRelease)
6167
_PI_API(piextProgramSetSpecializationConstant)
68+
_PI_API(piextProgramGetNativeHandle)
69+
_PI_API(piextProgramCreateWithNativeHandle)
6270
// Kernel
6371
_PI_API(piKernelCreate)
6472
_PI_API(piKernelSetArg)
@@ -78,6 +86,8 @@ _PI_API(piEventSetCallback)
7886
_PI_API(piEventSetStatus)
7987
_PI_API(piEventRetain)
8088
_PI_API(piEventRelease)
89+
_PI_API(piextEventGetNativeHandle)
90+
_PI_API(piextEventCreateWithNativeHandle)
8191
// Sampler
8292
_PI_API(piSamplerCreate)
8393
_PI_API(piSamplerGetInfo)
@@ -113,7 +123,4 @@ _PI_API(piextUSMGetMemAllocInfo)
113123

114124
_PI_API(piextKernelSetArgMemObj)
115125

116-
// Interop
117-
_PI_API(piGetNativeHandle)
118-
119126
#undef _PI_API

sycl/include/CL/sycl/detail/pi.h

Lines changed: 102 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ using pi_bool = pi_uint32;
6161
using pi_bitfield = pi_uint64;
6262
using pi_native_handle = uintptr_t;
6363

64-
enum pi_handle_type {
65-
PI_NATIVE_HANDLE_CONTEXT,
66-
PI_NATIVE_HANDLE_DEVICE,
67-
PI_NATIVE_HANDLE_QUEUE,
68-
PI_NATIVE_HANDLE_EVENT,
69-
PI_NATIVE_HANDLE_MEM,
70-
PI_NATIVE_HANDLE_PLATFORM
71-
};
72-
7364
//
7465
// NOTE: prefer to map 1:1 to OpenCL so that no translation is needed
7566
// for PI <-> OpenCL ways. The PI <-> to other BE translation is almost
@@ -772,19 +763,6 @@ pi_result piPlatformGetInfo(pi_platform platform, pi_platform_info param_name,
772763
size_t param_value_size, void *param_value,
773764
size_t *param_value_size_ret);
774765

775-
//
776-
// Device
777-
//
778-
///
779-
/// Create PI device from the given raw device handle (if the "device"
780-
/// points to null), or, vice versa, extract the raw device handle into
781-
/// the "handle" (if it was pointing to a null) from the given PI device.
782-
/// NOTE: The instance of the PI device created is retained.
783-
///
784-
pi_result piextDeviceConvert(
785-
pi_device *device, ///< [in,out] the pointer to PI device
786-
void **handle); ///< [in,out] the pointer to the raw device handle
787-
788766
pi_result piDevicesGet(pi_platform platform, pi_device_type device_type,
789767
pi_uint32 num_entries, pi_device *devices,
790768
pi_uint32 *num_devices);
@@ -802,6 +780,23 @@ pi_result piDevicePartition(pi_device device,
802780
pi_uint32 num_devices, pi_device *out_devices,
803781
pi_uint32 *out_num_devices);
804782

783+
/// Gets the native handle of a PI device object.
784+
///
785+
/// \param device is the PI device to get the native handle of.
786+
/// \param nativeHandle is the native handle of device.
787+
pi_result piextDeviceGetNativeHandle(pi_device device,
788+
pi_native_handle *nativeHandle);
789+
790+
/// Creates PI device object from a native handle.
791+
/// NOTE: If the created PI object shares reference count with the native object
792+
/// the reference count is increased by one. Otherwise the newly created
793+
/// PI object has a reference count of 1.
794+
///
795+
/// \param nativeHandle is the native handle to create PI device from.
796+
/// \param device is the PI device created from the native handle.
797+
pi_result piextDeviceCreateWithNativeHandle(pi_native_handle nativeHandle,
798+
pi_device *device);
799+
805800
/// Selects the most appropriate device binary based on runtime information
806801
/// and the IR characteristics.
807802
///
@@ -845,6 +840,23 @@ pi_result piextContextSetExtendedDeleter(pi_context context,
845840
pi_context_extended_deleter func,
846841
void *user_data);
847842

843+
/// Gets the native handle of a PI context object.
844+
///
845+
/// \param context is the PI context to get the native handle of.
846+
/// \param nativeHandle is the native handle of context.
847+
pi_result piextContextGetNativeHandle(pi_context context,
848+
pi_native_handle *nativeHandle);
849+
850+
/// Creates PI context object from a native handle.
851+
/// NOTE: If the created PI object shares reference count with the native object
852+
/// the reference count is increased by one. Otherwise the newly created
853+
/// PI object has a reference count of 1.
854+
///
855+
/// \param nativeHandle is the native handle to create PI context from.
856+
/// \param context is the PI context created from the native handle.
857+
pi_result piextContextCreateWithNativeHandle(pi_native_handle nativeHandle,
858+
pi_context *context);
859+
848860
//
849861
// Queue
850862
//
@@ -861,6 +873,23 @@ pi_result piQueueRelease(pi_queue command_queue);
861873

862874
pi_result piQueueFinish(pi_queue command_queue);
863875

876+
/// Gets the native handle of a PI queue object.
877+
///
878+
/// \param queue is the PI queue to get the native handle of.
879+
/// \param nativeHandle is the native handle of queue.
880+
pi_result piextQueueGetNativeHandle(pi_queue queue,
881+
pi_native_handle *nativeHandle);
882+
883+
/// Creates PI queue object from a native handle.
884+
/// NOTE: If the created PI object shares reference count with the native object
885+
/// the reference count is increased by one. Otherwise the newly created
886+
/// PI object has a reference count of 1.
887+
///
888+
/// \param nativeHandle is the native handle to create PI queue from.
889+
/// \param queue is the PI queue created from the native handle.
890+
pi_result piextQueueCreateWithNativeHandle(pi_native_handle nativeHandle,
891+
pi_queue *queue);
892+
864893
//
865894
// Memory
866895
//
@@ -888,19 +917,26 @@ pi_result piMemRelease(pi_mem mem);
888917
pi_result piMemBufferPartition(pi_mem buffer, pi_mem_flags flags,
889918
pi_buffer_create_type buffer_create_type,
890919
void *buffer_create_info, pi_mem *ret_mem);
920+
921+
/// Gets the native handle of a PI mem object.
922+
///
923+
/// \param mem is the PI mem to get the native handle of.
924+
/// \param nativeHandle is the native handle of mem.
925+
pi_result piextMemGetNativeHandle(pi_mem mem, pi_native_handle *nativeHandle);
926+
927+
/// Creates PI mem object from a native handle.
928+
/// NOTE: If the created PI object shares reference count with the native object
929+
/// the reference count is increased by one. Otherwise the newly created
930+
/// PI object has a reference count of 1.
931+
///
932+
/// \param nativeHandle is the native handle to create PI mem from.
933+
/// \param mem is the PI mem created from the native handle.
934+
pi_result piextMemCreateWithNativeHandle(pi_native_handle nativeHandle,
935+
pi_mem *mem);
936+
891937
//
892938
// Program
893939
//
894-
///
895-
/// Create PI program from the given raw program handle (if the "program"
896-
/// points to null), or, vice versa, extract the raw program handle into
897-
/// the "handle" (if it was pointing to a null) from the given PI program.
898-
/// NOTE: The instance of the PI program created is retained.
899-
///
900-
pi_result piextProgramConvert(
901-
pi_context context, ///< [in] the PI context of the program
902-
pi_program *program, ///< [in,out] the pointer to PI program
903-
void **handle); ///< [in,out] the pointer to the raw program handle
904940

905941
pi_result piProgramCreate(pi_context context, const void *il, size_t length,
906942
pi_program *res_program);
@@ -960,6 +996,23 @@ pi_result piextProgramSetSpecializationConstant(pi_program prog,
960996
size_t spec_size,
961997
const void *spec_value);
962998

999+
/// Gets the native handle of a PI program object.
1000+
///
1001+
/// \param program is the PI program to get the native handle of.
1002+
/// \param nativeHandle is the native handle of program.
1003+
pi_result piextProgramGetNativeHandle(pi_program program,
1004+
pi_native_handle *nativeHandle);
1005+
1006+
/// Creates PI program object from a native handle.
1007+
/// NOTE: If the created PI object shares reference count with the native object
1008+
/// the reference count is increased by one. Otherwise the newly created
1009+
/// PI object has a reference count of 1.
1010+
///
1011+
/// \param nativeHandle is the native handle to create PI program from.
1012+
/// \param program is the PI program created from the native handle.
1013+
pi_result piextProgramCreateWithNativeHandle(pi_native_handle nativeHandle,
1014+
pi_program *program);
1015+
9631016
//
9641017
// Kernel
9651018
//
@@ -1051,6 +1104,23 @@ pi_result piEventRetain(pi_event event);
10511104

10521105
pi_result piEventRelease(pi_event event);
10531106

1107+
/// Gets the native handle of a PI event object.
1108+
///
1109+
/// \param event is the PI event to get the native handle of.
1110+
/// \param nativeHandle is the native handle of event.
1111+
pi_result piextEventGetNativeHandle(pi_event event,
1112+
pi_native_handle *nativeHandle);
1113+
1114+
/// Creates PI event object from a native handle.
1115+
/// NOTE: If the created PI object shares reference count with the native object
1116+
/// the reference count is increased by one. Otherwise the newly created
1117+
/// PI object has a reference count of 1.
1118+
///
1119+
/// \param nativeHandle is the native handle to create PI event from.
1120+
/// \param event is the PI event created from the native handle.
1121+
pi_result piextEventCreateWithNativeHandle(pi_native_handle nativeHandle,
1122+
pi_event *event);
1123+
10541124
//
10551125
// Sampler
10561126
//
@@ -1356,14 +1426,6 @@ pi_result piextUSMGetMemAllocInfo(pi_context context, const void *ptr,
13561426
size_t param_value_size, void *param_value,
13571427
size_t *param_value_size_ret);
13581428

1359-
/// Gets the native handle of a SYCL object.
1360-
///
1361-
/// \param handleType is a representation of the native handle.
1362-
/// \param piObject is the PI object to get the native handle of.
1363-
/// \param nativeHandle is the native handle of piObject.
1364-
pi_result piGetNativeHandle(pi_handle_type handleType, void *piObject,
1365-
pi_native_handle *nativeHandle);
1366-
13671429
struct _pi_plugin {
13681430
// PI version supported by host passed to the plugin. The Plugin
13691431
// checks and writes the appropriate Function Pointers in

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ template <class To, class From> inline To cast(From value) {
311311

312312
// These conversions should use PI interop API.
313313
template <> inline pi::PiProgram cast(cl_program interop) {
314-
RT::assertion(false, "pi::cast -> use piextProgramConvert");
314+
RT::assertion(false, "pi::cast -> use piextProgramFromNative");
315315
return {};
316316
}
317317

318318
template <> inline pi::PiDevice cast(cl_device_id interop) {
319-
RT::assertion(false, "pi::cast -> use piextDeviceConvert");
319+
RT::assertion(false, "pi::cast -> use piextDeviceFromNative");
320320
return {};
321321
}
322322
} // namespace pi

0 commit comments

Comments
 (0)