Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL][CUDA] Implement sycl_ext_oneapi_peer_access extension #8303

Merged
merged 89 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
5d788c6
[SYCL][CUDA] Decouple CUDA contexts from PI contexts
npmiller Feb 1, 2023
8685475
[SYCL][CUDA] Move deprecation warning to class
npmiller Feb 3, 2023
de16f88
Initial P2P impl.
Feb 6, 2023
b5f9481
added ext_oneapi_disable_peer_access and ext_oneapi_can_access_peer.
JackAKirk Feb 8, 2023
64ecf25
Introduced pi_peer_attr.
Feb 10, 2023
15d4bf6
Format.
Feb 10, 2023
a35294f
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk Feb 10, 2023
df55a69
Format.
JackAKirk Mar 3, 2023
ddca3c3
Format.
JackAKirk Mar 3, 2023
c3a2009
Format.
JackAKirk Mar 3, 2023
f0f448d
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk Mar 3, 2023
1855367
Corrected hip pi die function.
JackAKirk Mar 3, 2023
644c880
Added esimd p2p pi functions.
JackAKirk Mar 6, 2023
e5b421e
fix mistake in last commit.
JackAKirk Mar 6, 2023
6f45d53
corrected pi function names.
JackAKirk Mar 6, 2023
1849619
format.
JackAKirk Mar 6, 2023
aa7a7eb
Update sycl/plugins/cuda/pi_cuda.cpp
JackAKirk Mar 7, 2023
3380230
Update sycl/plugins/level_zero/pi_level_zero.cpp
JackAKirk Mar 7, 2023
5f6360c
Early exit in ext_oneapi_can_access_peer
JackAKirk Mar 7, 2023
e33a578
Switched piextCanAccessPeer to more general piextPeerAccessGetInfo.
JackAKirk Mar 10, 2023
32d714a
format.
JackAKirk Mar 10, 2023
7d12cd7
Added unittest, fixed hip pi names.
JackAKirk Mar 17, 2023
4cf5999
Format.
JackAKirk Mar 17, 2023
63f23e5
Add missing abi symbols to test.
JackAKirk Mar 17, 2023
aaec286
Update l0 abi test.
JackAKirk Mar 17, 2023
76245f2
Corrected die error messages.
JackAKirk Mar 20, 2023
55a9b6a
cleanup test.
JackAKirk Mar 20, 2023
80dfb3a
Add global var check that pi is reached.
JackAKirk Mar 20, 2023
76f6772
Format.
JackAKirk Mar 20, 2023
85949f7
Fix copy/paste error.
JackAKirk Mar 21, 2023
65aa452
trying to scope up meaningful error mech.
JackAKirk May 9, 2023
ea7e855
added some comments.
JackAKirk May 9, 2023
eae9b12
working impl throwing exceptions in all backends.
JackAKirk May 16, 2023
c825b9c
remove comments.
JackAKirk May 16, 2023
ae358bb
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk May 16, 2023
ce81826
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk May 16, 2023
72aca2e
format.
JackAKirk May 16, 2023
c2579aa
fixes for recent sycl branch changes.
JackAKirk May 16, 2023
0c87405
Format.
JackAKirk May 16, 2023
dfcb01c
Added P2P USM tests.
JackAKirk May 16, 2023
b84da4d
Update sycl/source/device.cpp
JackAKirk May 16, 2023
9e5408b
Address review comments.
JackAKirk May 16, 2023
57c5747
Just use Plugin::call.
JackAKirk May 16, 2023
029c1fe
Remove trace checks CI doesn't support.
JackAKirk May 17, 2023
8d41240
Added comments, updating namings.
JackAKirk May 17, 2023
b86954d
Added windows symbols.
JackAKirk May 17, 2023
a6f7602
Refactor common code.
JackAKirk May 17, 2023
cc5eb63
Format.
JackAKirk May 17, 2023
716bf30
Some final corrections.
JackAKirk May 18, 2023
484cf25
Format.
JackAKirk May 18, 2023
333b7d6
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk May 22, 2023
308f45a
Correct version comment order.
JackAKirk May 22, 2023
8b8cbc8
Merge branch 'sycl' into P2P-primary-ctxt
May 31, 2023
b2b6fcb
Removed broken error message.
May 31, 2023
2bea80b
Addressed review comments.
May 31, 2023
04b8610
Format.
May 31, 2023
d0b138c
Try UR invalid value error.
Jun 1, 2023
3e488c4
Stated return type of queries in comment.
Jun 6, 2023
c1905c6
Merge branch 'sycl' into P2P-primary-ctxt
Jun 22, 2023
19d2a7d
Integrate UR usm-p2p interfaces.
Jun 23, 2023
f2a2026
Attempt to fix getLastError.
Jun 23, 2023
37aecb1
Switch to UR_CHECK_ERROR usage.
JackAKirk Jun 26, 2023
e80ff9b
Format.
JackAKirk Jun 26, 2023
8956f50
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk Jun 26, 2023
b987dba
RT:: -> sycl::detail::pi::
JackAKirk Jun 26, 2023
6724a40
u_int32_t -> uint32_t
JackAKirk Jun 26, 2023
69a6506
Removed unnecessary includes.
JackAKirk Jun 26, 2023
11ca2a6
Merge branch 'sycl' into P2P-primary-ctxt
Jul 3, 2023
8b9c2ab
PI_ERROR_UNKNOWN -> return PI_ERROR_INVALID_VALUE
Jul 3, 2023
0a09023
Merge branch 'sycl' into P2P-primary-ctxt
Jul 4, 2023
f1eb0f0
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk Jul 4, 2023
40e93d0
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk Jul 4, 2023
e5e967f
Conflict fix.
JackAKirk Jul 4, 2023
92e1420
Merge branch 'sycl' into P2P-primary-ctxt
JackAKirk Jul 4, 2023
f0993b9
Reverted pi2ur.hpp due to problem diff.
JackAKirk Jul 5, 2023
28028ac
same as last commit.
JackAKirk Jul 5, 2023
6ed3213
Added back peer functions to pi2ur.
JackAKirk Jul 5, 2023
512d2a8
Removed unnecessary usm_p2p.hpp headers.
JackAKirk Jul 5, 2023
1e088a1
Removed level_zero pi::die impl.
JackAKirk Jul 5, 2023
80dd26a
Format.
JackAKirk Jul 5, 2023
9dc099c
Added missing inline and urPrint.
JackAKirk Jul 6, 2023
b191914
Format.
JackAKirk Jul 6, 2023
5d83aeb
Format.
JackAKirk Jul 6, 2023
c389980
Moved p2p ext doc to supported.
JackAKirk Jul 7, 2023
8bd6b60
Added Backend support status, updated status.
Jul 7, 2023
5e7d821
Updated sycl 2020 revision version.
Jul 7, 2023
ab3ac25
Switch to Greg's suggested wording.
Jul 7, 2023
47acd23
Use code font for function name.
Jul 7, 2023
4ab6215
Merge branch 'sycl' into P2P-primary-ctxt
Jul 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the following changes to the API specification:

  • Update the "Status" section using the wording in the template.

  • Add a section "Backend support status" noting that this extension is supported only for the CUDA backend. I'd suggest wording like:

This extension is currently implemented in DPC++ for all devices and backends, however, only the CUDA backend allows peer to peer memory access. Other backends report false from the ext_oneapi_can_access_peer query.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I've made these changes now.

Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ https://github.com/intel/llvm/issues

== Dependencies

This extension is written against the SYCL 2020 revision 6 specification. All
This extension is written against the SYCL 2020 revision 7 specification. All
references below to the "core SYCL specification" or to section numbers in the
SYCL specification refer to that revision.

== Status

This is a proposed extension specification, intended to gather community
feedback. Interfaces defined in this specification may not be implemented yet
or may be in a preliminary state. The specification itself may also change in
incompatible ways before it is finalized. *Shipping software products should
not rely on APIs defined in this specification.*
This extension is implemented and fully supported by DPC++.

== Backend support status

This extension is currently implemented in DPC++ for all GPU devices and
backends, however, only the CUDA backend allows peer to peer memory access.
Other backends report false from the `ext_oneapi_can_access_peer` query.

== Overview

Expand Down
5 changes: 4 additions & 1 deletion sycl/include/sycl/detail/pi.def
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ _PI_API(piPluginGetLastError)

_PI_API(piTearDown)


_PI_API(piextUSMEnqueueFill2D)
_PI_API(piextUSMEnqueueMemset2D)
_PI_API(piextUSMEnqueueMemcpy2D)
Expand All @@ -158,6 +157,10 @@ _PI_API(piextEnqueueDeviceGlobalVariableRead)

_PI_API(piPluginGetBackendOption)

_PI_API(piextEnablePeerAccess)
_PI_API(piextDisablePeerAccess)
_PI_API(piextPeerAccessGetInfo)

// command-buffer Extension
_PI_API(piextCommandBufferCreate)
_PI_API(piextCommandBufferRetain)
Expand Down
22 changes: 21 additions & 1 deletion sycl/include/sycl/detail/pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@
// 14.33 Added new parameter (memory object properties) to
// piextKernelSetArgMemObj
// 14.34 Added command-buffer extension methods
// 14.35 Added piextEnablePeerAccess, piextDisablePeerAccess,
// piextPeerAccessGetInfo, and pi_peer_attr enum.

#define _PI_H_VERSION_MAJOR 14
#define _PI_H_VERSION_MINOR 34
#define _PI_H_VERSION_MINOR 35

#define _PI_STRING_HELPER(a) #a
#define _PI_CONCAT(a, b) _PI_STRING_HELPER(a.b)
Expand Down Expand Up @@ -1030,7 +1032,17 @@ using pi_image_desc = _pi_image_desc;

typedef enum { PI_MEM_CONTEXT = 0x1106, PI_MEM_SIZE = 0x1102 } _pi_mem_info;

typedef enum {
PI_PEER_ACCESS_SUPPORTED =
0x0, ///< returns a uint32_t: 1 if P2P Access is supported
///< otherwise P2P Access is not supported.
PI_PEER_ATOMICS_SUPPORTED =
0x1 ///< returns a uint32_t: 1 if Atomic operations are supported over the
///< P2P link, otherwise such operations are not supported.
} _pi_peer_attr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to define the returned value (and type) for these queries, is it pi_bool aka uint32_t?

Copy link
Contributor Author

@JackAKirk JackAKirk May 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the definition of cuDeviceGetP2PAttribute here : https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__PEER__ACCESS.html#group__CUDA__PEER__ACCESS_1g4c55c60508f8eba4546b51f2ee545393
This function is used to get the query result. Although currently we only support queries which can be represented as booleans there is e.g. CU_DEVICE_P2P_ATTRIBUTE_PERFORMANCE_RANK which returns a relative integer value. This is why the return type is integer and not bool for future proofing.

L0 backend should decide whether it also will require such attributes at some point, and then whether SYCL (and in turn UR) will want to support them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with it being integer, but ask this to be documented (comments in pi.h)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I forgot the to document the return type. I will do this now. Note that this is a comment so won't affect the test status of this PR that is all green (everything passing.)


using pi_mem_info = _pi_mem_info;
using pi_peer_attr = _pi_peer_attr;

//
// Following section contains SYCL RT Plugin Interface (PI) functions.
Expand Down Expand Up @@ -1088,6 +1100,14 @@ __SYCL_EXPORT pi_result piDevicesGet(pi_platform platform,
pi_uint32 num_entries, pi_device *devices,
pi_uint32 *num_devices);

__SYCL_EXPORT pi_result piextEnablePeerAccess(pi_device command_device,
pi_device peer_device);
__SYCL_EXPORT pi_result piextDisablePeerAccess(pi_device command_device,
pi_device peer_device);
__SYCL_EXPORT pi_result piextPeerAccessGetInfo(
pi_device command_device, pi_device peer_device, pi_peer_attr attr,
size_t param_value_size, void *param_value, size_t *param_value_size_ret);

steffenlarsen marked this conversation as resolved.
Show resolved Hide resolved
/// Returns requested info for provided native device
/// Return PI_DEVICE_INFO_EXTENSION_DEVICELIB_ASSERT for
/// PI_DEVICE_INFO_EXTENSIONS query when the device supports native asserts
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/detail/pi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ using PiKernelCacheConfig = ::pi_kernel_cache_config;
using PiExtSyncPoint = ::pi_ext_sync_point;
using PiExtCommandBuffer = ::pi_ext_command_buffer;
using PiExtCommandBufferDesc = ::pi_ext_command_buffer_desc;
using PiPeerAttr = ::pi_peer_attr;

__SYCL_EXPORT void contextSetExtendedDeleter(const sycl::context &constext,
pi_context_extended_deleter func,
Expand Down
13 changes: 13 additions & 0 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ enum class aspect;
namespace ext::oneapi {
// Forward declaration
class filter_selector;

enum class peer_access {
access_supported = 0x0,
atomics_supported = 0x1,
};

} // namespace ext::oneapi

/// The SYCL device class encapsulates a single SYCL device on which kernels
Expand Down Expand Up @@ -90,6 +96,13 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {

device &operator=(device &&rhs) = default;

void ext_oneapi_enable_peer_access(const device &peer);
void ext_oneapi_disable_peer_access(const device &peer);
bool
ext_oneapi_can_access_peer(const device &peer,
ext::oneapi::peer_access value =
ext::oneapi::peer_access::access_supported);

/// Get instance of device
///
/// \return a valid cl_device_id instance in accordance with the requirements
Expand Down
1 change: 1 addition & 0 deletions sycl/plugins/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ add_sycl_plugin(cuda
"../unified_runtime/ur/adapters/cuda/usm.cpp"
"../unified_runtime/ur/adapters/cuda/command_buffer.hpp"
"../unified_runtime/ur/adapters/cuda/command_buffer.cpp"
"../unified_runtime/ur/adapters/cuda/usm_p2p.cpp"
# ---
"${sycl_inc_dir}/sycl/detail/pi.h"
"${sycl_inc_dir}/sycl/detail/pi.hpp"
Expand Down
5 changes: 4 additions & 1 deletion sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
_PI_CL(piextCommandBufferMemBufferCopyRect,
pi2ur::piextCommandBufferMemBufferCopyRect)
_PI_CL(piextEnqueueCommandBuffer, pi2ur::piextEnqueueCommandBuffer)

// Peer to Peer
_PI_CL(piextEnablePeerAccess, pi2ur::piextEnablePeerAccess)
_PI_CL(piextDisablePeerAccess, pi2ur::piextDisablePeerAccess)
_PI_CL(piextPeerAccessGetInfo, pi2ur::piextPeerAccessGetInfo)
#undef _PI_CL

return PI_SUCCESS;
Expand Down
37 changes: 37 additions & 0 deletions sycl/plugins/esimd_emulator/pi_esimd_emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,43 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
return PI_SUCCESS;
}

pi_result piextEnablePeerAccess(pi_device command_device,
pi_device peer_device) {

std::ignore = command_device;
std::ignore = peer_device;

setErrorMessage("piextEnablePeerAccess not "
"implemented in esimd_emulator backend",
PI_ERROR_PLUGIN_SPECIFIC_ERROR);
return PI_ERROR_PLUGIN_SPECIFIC_ERROR;
}

pi_result piextDisablePeerAccess(pi_device command_device,
pi_device peer_device) {

std::ignore = command_device;
std::ignore = peer_device;

setErrorMessage("piextDisablePeerAccess not "
"implemented in esimd_emulator backend",
PI_ERROR_PLUGIN_SPECIFIC_ERROR);
return PI_ERROR_PLUGIN_SPECIFIC_ERROR;
}

pi_result piextPeerAccessGetInfo(pi_device command_device,
pi_device peer_device, pi_peer_attr attr,
size_t ParamValueSize, void *ParamValue,
size_t *ParamValueSizeRet) {
std::ignore = command_device;
std::ignore = peer_device;
std::ignore = attr;

ReturnHelper ReturnValue(ParamValueSize, ParamValue, ParamValueSizeRet);
// Zero return value indicates that all of the queries currently return false.
return ReturnValue(pi_int32{0});
}

#ifdef _WIN32
#define __SYCL_PLUGIN_DLL_NAME "pi_esimd_emulator.dll"
#include "../common_win_pi_trace/common_win_pi_trace.hpp"
Expand Down
41 changes: 41 additions & 0 deletions sycl/plugins/hip/pi_hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5857,6 +5857,42 @@ pi_result hip_piGetDeviceAndHostTimer(pi_device Device, uint64_t *DeviceTime,
return PI_SUCCESS;
}

pi_result hip_piextEnablePeerAccess(pi_device command_device,
pi_device peer_device) {

std::ignore = command_device;
std::ignore = peer_device;

setErrorMessage("piextEnablePeerAccess not "
"implemented in hip backend",
PI_ERROR_PLUGIN_SPECIFIC_ERROR);
return PI_ERROR_PLUGIN_SPECIFIC_ERROR;
}

pi_result hip_piextDisablePeerAccess(pi_device command_device,
pi_device peer_device) {

std::ignore = command_device;
std::ignore = peer_device;

setErrorMessage("piextDisablePeerAccess not "
"implemented in hip backend",
PI_ERROR_PLUGIN_SPECIFIC_ERROR);
return PI_ERROR_PLUGIN_SPECIFIC_ERROR;
}

pi_result hip_piextPeerAccessGetInfo(pi_device command_device,
pi_device peer_device, pi_peer_attr attr,
size_t param_value_size, void *param_value,
size_t *param_value_size_ret) {
std::ignore = command_device;
std::ignore = peer_device;
std::ignore = attr;
// Zero return value indicates that all of the queries currently return false.
return getInfo(param_value_size, param_value, param_value_size_ret,
pi_int32{0});
}

const char SupportedVersion[] = _PI_HIP_PLUGIN_VERSION_STRING;

pi_result piPluginInit(pi_plugin *PluginInit) {
Expand Down Expand Up @@ -6028,6 +6064,11 @@ pi_result piPluginInit(pi_plugin *PluginInit) {
_PI_CL(piGetDeviceAndHostTimer, hip_piGetDeviceAndHostTimer)
_PI_CL(piPluginGetBackendOption, hip_piPluginGetBackendOption)

// Peer to Peer
_PI_CL(piextEnablePeerAccess, hip_piextEnablePeerAccess)
_PI_CL(piextDisablePeerAccess, hip_piextDisablePeerAccess)
_PI_CL(piextPeerAccessGetInfo, hip_piextPeerAccessGetInfo)

#undef _PI_CL

return PI_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions sycl/plugins/level_zero/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ add_sycl_plugin(level_zero
"../unified_runtime/ur/adapters/level_zero/queue.cpp"
"../unified_runtime/ur/adapters/level_zero/sampler.cpp"
"../unified_runtime/ur/adapters/level_zero/usm.cpp"
"../unified_runtime/ur/adapters/level_zero/usm_p2p.cpp"
# Following are the PI Level-Zero Plugin only codes.
"pi_level_zero.cpp"
"pi_level_zero.hpp"
Expand Down
22 changes: 22 additions & 0 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,28 @@ pi_result piGetDeviceAndHostTimer(pi_device Device, uint64_t *DeviceTime,
return pi2ur::piGetDeviceAndHostTimer(Device, DeviceTime, HostTime);
}

pi_result piextEnablePeerAccess(pi_device command_device,
jandres742 marked this conversation as resolved.
Show resolved Hide resolved
pi_device peer_device) {

return pi2ur::piextEnablePeerAccess(command_device, peer_device);
}

pi_result piextDisablePeerAccess(pi_device command_device,
pi_device peer_device) {

return pi2ur::piextDisablePeerAccess(command_device, peer_device);
}

pi_result piextPeerAccessGetInfo(pi_device command_device,
jandres742 marked this conversation as resolved.
Show resolved Hide resolved
pi_device peer_device, pi_peer_attr attr,
size_t ParamValueSize, void *ParamValue,
size_t *ParamValueSizeRet) {

return pi2ur::piextPeerAccessGetInfo(command_device, peer_device, attr,
ParamValueSize, ParamValue,
ParamValueSizeRet);
}

#ifdef _WIN32
#define __SYCL_PLUGIN_DLL_NAME "pi_level_zero.dll"
#include "../common_win_pi_trace/common_win_pi_trace.hpp"
Expand Down
2 changes: 2 additions & 0 deletions sycl/plugins/unified_runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ add_sycl_library("ur_adapter_level_zero" SHARED
"ur/adapters/level_zero/queue.cpp"
"ur/adapters/level_zero/sampler.cpp"
"ur/adapters/level_zero/usm.cpp"
"ur/adapters/level_zero/usm_p2p.cpp"
INCLUDE_DIRS
${sycl_inc_dir}
LIBRARIES
Expand Down Expand Up @@ -158,6 +159,7 @@ if ("cuda" IN_LIST SYCL_ENABLE_PLUGINS)
"ur/adapters/cuda/usm.cpp"
"ur/adapters/cuda/command_buffer.hpp"
"ur/adapters/cuda/command_buffer.cpp"
"ur/adapters/cuda/usm_p2p.cpp"
INCLUDE_DIRS
${sycl_inc_dir}
LIBRARIES
Expand Down
55 changes: 55 additions & 0 deletions sycl/plugins/unified_runtime/pi2ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4322,4 +4322,59 @@ inline pi_result piextEnqueueCommandBuffer(pi_ext_command_buffer CommandBuffer,
// Command-buffer extension
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// usm-p2p

inline pi_result piextEnablePeerAccess(pi_device command_device,
pi_device peer_device) {
auto commandDevice = reinterpret_cast<ur_device_handle_t>(command_device);
auto peerDevice = reinterpret_cast<ur_device_handle_t>(peer_device);

HANDLE_ERRORS(urUsmP2PEnablePeerAccessExp(commandDevice, peerDevice));

return PI_SUCCESS;
}

inline pi_result piextDisablePeerAccess(pi_device command_device,
pi_device peer_device) {
auto commandDevice = reinterpret_cast<ur_device_handle_t>(command_device);
auto peerDevice = reinterpret_cast<ur_device_handle_t>(peer_device);

HANDLE_ERRORS(urUsmP2PDisablePeerAccessExp(commandDevice, peerDevice));

return PI_SUCCESS;
}

inline pi_result
piextPeerAccessGetInfo(pi_device command_device, pi_device peer_device,
pi_peer_attr attr, size_t param_value_size,
void *param_value, size_t *param_value_size_ret) {
auto commandDevice = reinterpret_cast<ur_device_handle_t>(command_device);
auto peerDevice = reinterpret_cast<ur_device_handle_t>(peer_device);

ur_exp_peer_info_t propName;
switch (attr) {
case PI_PEER_ACCESS_SUPPORTED: {
propName = UR_EXP_PEER_INFO_UR_PEER_ACCESS_SUPPORTED;
break;
}
case PI_PEER_ATOMICS_SUPPORTED: {
propName = UR_EXP_PEER_INFO_UR_PEER_ATOMICS_SUPPORTED;
break;
}
default: {
return PI_ERROR_INVALID_VALUE;
}
}

HANDLE_ERRORS(urUsmP2PPeerAccessGetInfoExp(
commandDevice, peerDevice, propName, param_value_size, param_value,
param_value_size_ret));

return PI_SUCCESS;
}

// usm-p2p
///////////////////////////////////////////////////////////////////////////////

} // namespace pi2ur
25 changes: 25 additions & 0 deletions sycl/plugins/unified_runtime/pi_unified_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,26 @@ __SYCL_EXPORT pi_result piPluginGetBackendOption(pi_platform platform,
backend_option);
}

__SYCL_EXPORT pi_result piextEnablePeerAccess(pi_device command_device,
pi_device peer_device) {

return pi2ur::piextEnablePeerAccess(command_device, peer_device);
}

__SYCL_EXPORT pi_result piextDisablePeerAccess(pi_device command_device,
pi_device peer_device) {

return pi2ur::piextDisablePeerAccess(command_device, peer_device);
}

__SYCL_EXPORT pi_result piextPeerAccessGetInfo(
pi_device command_device, pi_device peer_device, pi_peer_attr attr,
size_t ParamValueSize, void *ParamValue, size_t *ParamValueSizeRet) {
return pi2ur::piextPeerAccessGetInfo(command_device, peer_device, attr,
ParamValueSize, ParamValue,
ParamValueSizeRet);
}

// This interface is not in Unified Runtime currently
__SYCL_EXPORT pi_result piTearDown(void *PluginParameter) {
return pi2ur::piTearDown(PluginParameter);
Expand Down Expand Up @@ -1251,6 +1271,11 @@ __SYCL_EXPORT pi_result piPluginInit(pi_plugin *PluginInit) {
_PI_API(piSamplerRetain)
_PI_API(piSamplerRelease)

// Peer to Peer
_PI_API(piextEnablePeerAccess)
_PI_API(piextDisablePeerAccess)
_PI_API(piextPeerAccessGetInfo)

_PI_API(piextPluginGetOpaqueData)
_PI_API(piTearDown)

Expand Down
Loading