-
Notifications
You must be signed in to change notification settings - Fork 792
[SYCL][Docs] Add sycl_ext_oneapi_inter_process_communication #20018
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
Open
steffenlarsen
wants to merge
40
commits into
intel:sycl
Choose a base branch
from
steffenlarsen:ext_oneapi_inter_process_communication
base: sycl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
eec1fe5
[SYCL][Docs] Add sycl_ext_oneapi_inter_process_communication
steffenlarsen e4aefbf
Set ptracer permission in test
steffenlarsen 7c85049
Document known issues
steffenlarsen 6debadb
Disable on Windows L0
steffenlarsen d3b6c56
Add tracker
steffenlarsen 29cbc37
Open handle directly from data
steffenlarsen baa805f
Adjust for UR changes
steffenlarsen 7170da9
Address source-check issues
steffenlarsen ce89cfe
Address more source checks
steffenlarsen 49ce33d
Add missing symbols
steffenlarsen c3f139b
Remove known issue
steffenlarsen d1ba0de
Add put explicit internal release arg
steffenlarsen 4070634
Adjust sycl impl
steffenlarsen 5d5dc0f
Merge remote-tracking branch 'intel/sycl' into ext_oneapi_inter_proce…
steffenlarsen db03d7b
Remove unused param
steffenlarsen 0075694
Add missing Windows symbol
steffenlarsen 7a332b9
Add missing newline
steffenlarsen ce651ce
Merge remote-tracking branch 'intel/sycl' into ext_oneapi_inter_proce…
steffenlarsen acf286f
Change IPC API (SYCL)
steffenlarsen fa44def
Change IPC API (UR)
steffenlarsen 7873e13
Fix formatting
steffenlarsen 2001baa
Fix failures
steffenlarsen 3555827
Merge remote-tracking branch 'intel/sycl' into ext_oneapi_inter_proce…
steffenlarsen 68ea80e
Address feedback
steffenlarsen d1d9a1a
Fix unittest
steffenlarsen 01e3a65
Switch to std::byte
steffenlarsen 3bf5099
Fix include
steffenlarsen ebdc9e3
Fix tests
steffenlarsen 02e9613
Fix stylistic issues
steffenlarsen eeb0a8a
Make device lookup when failing
steffenlarsen 0103ab4
Merge remote-tracking branch 'intel/sycl' into ext_oneapi_inter_proce…
steffenlarsen 0f3b66f
Fix typo and add shortcut
steffenlarsen 31aa6a3
Address code comments
steffenlarsen 33d34a9
Address spec comments
steffenlarsen a1a7945
Clarify put result
steffenlarsen 3bc26d0
Add note about matching open and close
steffenlarsen 6cb2cf3
Add note about validity of opened ptrs after put
steffenlarsen 7883b93
Clarify last comment a little more
steffenlarsen 4410d55
Address newest comments
steffenlarsen 63315d9
Make arguments const and make work-around
steffenlarsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
248 changes: 248 additions & 0 deletions
248
...oc/extensions/experimental/sycl_ext_oneapi_inter_process_communication.asciidoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
= sycl_ext_oneapi_inter_process_communication | ||
|
||
:source-highlighter: coderay | ||
:coderay-linenums-mode: table | ||
|
||
// This section needs to be after the document title. | ||
:doctype: book | ||
:toc2: | ||
:toc: left | ||
:encoding: utf-8 | ||
:lang: en | ||
:dpcpp: pass:[DPC++] | ||
:endnote: —{nbsp}end{nbsp}note | ||
|
||
// Set the default source code type in this document to C++, | ||
// for syntax highlighting purposes. This is needed because | ||
// docbook uses c++ and html5 uses cpp. | ||
:language: {basebackend@docbook:c++:cpp} | ||
|
||
|
||
== Notice | ||
|
||
[%hardbreaks] | ||
Copyright (C) 2025 Intel Corporation. All rights reserved. | ||
|
||
Khronos(R) is a registered trademark and SYCL(TM) and SPIR(TM) are trademarks | ||
of The Khronos Group Inc. OpenCL(TM) is a trademark of Apple Inc. used by | ||
permission by Khronos. | ||
|
||
|
||
== Contact | ||
|
||
To report problems with this extension, please open a new issue at: | ||
|
||
https://github.com/intel/llvm/issues | ||
|
||
|
||
== Dependencies | ||
|
||
This extension is written against the SYCL 2020 revision 10 specification. All | ||
references below to the "core SYCL specification" or to section numbers in the | ||
SYCL specification refer to that revision. | ||
|
||
|
||
== Status | ||
|
||
This is an experimental extension specification, intended to provide early | ||
access to features and gather community feedback. Interfaces defined in this | ||
specification are implemented in {dpcpp}, but they are not finalized and may | ||
change incompatibly in future versions of {dpcpp} without prior notice. | ||
*Shipping software products should not rely on APIs defined in this | ||
specification.* | ||
|
||
|
||
== Backend support status | ||
|
||
The APIs in this extension may be used only on a device that has | ||
`aspect::ext_oneapi_ipc_memory`. The application must check that the device has | ||
this aspect before submitting a kernel using any of the APIs in this | ||
extension. If the application fails to do this, the implementation throws | ||
a synchronous exception with the `errc::kernel_not_supported` error code | ||
when the kernel is submitted to the queue. | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
|
||
== Overview | ||
|
||
This extension adds the ability for SYCL programs to share device USM memory | ||
allocations between processes. This is done by the allocating process creating | ||
a new `ipc_memory` object and transferring the "handle data" to the other | ||
processes. The other processes can use the handle data to recreate the | ||
`ipc_memory` object and get a pointer to the corresponding device USM memory. | ||
|
||
|
||
== Specification | ||
|
||
=== Feature test macro | ||
|
||
This extension provides a feature-test macro as described in the core SYCL | ||
specification. An implementation supporting this extension must predefine the | ||
macro `SYCL_EXT_ONEAPI_IPC` to one of the values defined in the table | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
below. Applications can test for the existence of this macro to determine if | ||
the implementation supports this feature, or applications can test the macro's | ||
value to determine which of the extension's features the implementation | ||
supports. | ||
|
||
_And follow the text with a table like this *unless the extension is | ||
"experimental"*. Note that your table may have more than one row if it | ||
has multiple versions._ | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
[%header,cols="1,5"] | ||
|=== | ||
|Value | ||
|Description | ||
|
||
|1 | ||
|The APIs of this experimental extension are not versioned, so the | ||
feature-test macro always has this value. | ||
|=== | ||
|
||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
=== Inter-process communicable memory | ||
|
||
|
||
This extension adds the new `ipc_memory` class. This new class adheres to the | ||
common reference semantics described in | ||
https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html#sec:reference-semantics[Section 4.5.2.] | ||
in the SYCL 2020 specification. | ||
|
||
``` | ||
namespace sycl::ext::oneapi::experimental { | ||
using ipc_memory_handle_data_t = span<char, sycl::dynamic_extent>; | ||
|
||
class ipc_memory { | ||
public: | ||
ipc_memory(void *ptr, sycl::context &ctx); | ||
|
||
void put(); | ||
|
||
static void *open(ipc_memory_handle_data_t ipc_memory_handle_data, | ||
const sycl::context &ctx, const sycl::device &dev); | ||
static void close(void *ptr, const sycl::context &ctx); | ||
|
||
ipc_memory_handle_data_t get_handle_data() const; | ||
|
||
void *get_ptr() const; | ||
}; | ||
|
||
} | ||
``` | ||
|
||
|==== | ||
a| | ||
[frame=all,grid=none] | ||
!==== | ||
a! | ||
[source] | ||
---- | ||
ipc_memory(void *ptr, const sycl::context &ctx) | ||
---- | ||
!==== | ||
|
||
_Effects:_ Constructs an IPC memory object in `ctx` from a pointer `ptr` to | ||
device USM memory. | ||
If `ptr` is not pointing to device USM memory, the behaviors of this constructor | ||
and any resulting objects are undefined. | ||
|
||
!==== | ||
a! | ||
[source] | ||
---- | ||
void put() | ||
---- | ||
!==== | ||
|
||
_Effects:_ Instructs the underlying IPC memory resources to be returned to | ||
the backend. This is not required to be called before the `ipc_memory` object | ||
dies. Freeing the device USM memory used when constructing this instance of | ||
`ipc_memory` will return the underlying IPC memory resources. | ||
Calling this function after `sycl::free()` has been called on the device USM | ||
memory used when constructing this instance of `ipc_memory` will result in | ||
undefined behavior. | ||
|
||
_Throws:_ A `sycl::exception` with `errc::invalid` if `ipc_memory::put()` has | ||
previously been called on this instance of `ipc_memory`. | ||
|
||
!==== | ||
a! | ||
[source] | ||
---- | ||
static void *open(ipc_memory_handle_data_t ipc_memory_handle_data, | ||
const sycl::context &ctx, const sycl::device &dev) | ||
---- | ||
!==== | ||
|
||
_Effects:_ Returns a pointer to the same device USM memory as the device USM | ||
memory associated with the `ipc_memory` object that the handle data originated | ||
from. | ||
The `ipc_memory` object that the handle data originated from is allowed to be | ||
from another process on the host system. | ||
If the `ipc_memory` object that the handle data originated from has been | ||
destroyed, the behaviors of this constructor and any resulting objects are | ||
undefined. | ||
If the device USM memory the original `ipc_memory` object was created with was | ||
not originally allocated on `dev`, the behaviors of this function is undefined. | ||
|
||
!==== | ||
a! | ||
[source] | ||
---- | ||
static void close(void *ptr, const sycl::context &ctx) | ||
---- | ||
!==== | ||
|
||
_Effects:_ Closes a device USM pointer previously returned by a call to | ||
`ipc_memory::open()`. | ||
|
||
!==== | ||
a! | ||
[source] | ||
---- | ||
ipc_memory_handle_data_t get_handle_data() const | ||
---- | ||
!==== | ||
|
||
_Returns:_ The handle data of the `ipc_memory` object. | ||
Utilizing the handle data returned by this API after the `ipc_memory` object has | ||
been destroyed results in undefined behavior. | ||
|
||
_Throws:_ A `sycl::exception` with `errc::invalid` if `ipc_memory::put()` has | ||
previously been called on this instance of `ipc_memory`. | ||
|
||
!==== | ||
a! | ||
[source] | ||
---- | ||
void *get_ptr() const | ||
---- | ||
!==== | ||
|
||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_Returns:_ A pointer to device USM memory corresponding to the pointer used to | ||
construct the original `ipc_memory` object. | ||
Accessing the pointer returned by this API after the `ipc_memory` object has | ||
been destroyed results in undefined behavior. | ||
|
||
|==== | ||
|
||
|
||
== Issues | ||
|
||
=== Level Zero file descriptor duplication dependency | ||
|
||
The IPC memory APIs in Level Zero on Linux currently requires the ability to | ||
duplicate file descriptors between processes. For security this is not allowed | ||
by default on Linux-based systems, so in order for the IPC memory APIs to work | ||
with Level Zero on Linux the user must either call `prctl(PR_SET_PTRACER, ...)` | ||
in the IPC handle owner process or enable the functionality globally using | ||
|
||
```bash | ||
sudo bash -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope" | ||
``` | ||
|
||
See also https://github.com/oneapi-src/unified-memory-framework/tree/main?tab=readme-ov-file#level-zero-memory-provider. | ||
|
||
|
||
=== Level Zero IPC memory Windows support | ||
|
||
The new IPC memory APIs are not currently supported on the Level Zero backend on | ||
Windows systems. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//==------- ipc_memory.hpp --- SYCL inter-process communicable memory ------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include <sycl/detail/defines_elementary.hpp> | ||
#include <sycl/detail/export.hpp> | ||
#include <sycl/detail/owner_less_base.hpp> | ||
#include <sycl/sycl_span.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
|
||
class context; | ||
class device; | ||
|
||
namespace detail { | ||
class ipc_memory_impl; | ||
} | ||
|
||
namespace ext::oneapi::experimental { | ||
using ipc_memory_handle_data_t = span<char, sycl::dynamic_extent>; | ||
|
||
class __SYCL_EXPORT ipc_memory | ||
: public sycl::detail::OwnerLessBase<ipc_memory> { | ||
public: | ||
ipc_memory(void *Ptr, const sycl::context &Ctx); | ||
|
||
void put(); | ||
|
||
static void *open(ipc_memory_handle_data_t IPCMemoryHandleData, | ||
const sycl::context &Ctx, const sycl::device &Dev); | ||
static void close(void *Ptr, const sycl::context &Ctx); | ||
|
||
ipc_memory_handle_data_t get_handle_data() const; | ||
|
||
void *get_ptr() const; | ||
|
||
private: | ||
ipc_memory(std::shared_ptr<sycl::detail::ipc_memory_impl> IPCMemImpl) | ||
: impl{IPCMemImpl} {} | ||
|
||
std::shared_ptr<sycl::detail::ipc_memory_impl> impl; | ||
|
||
template <class Obj> | ||
friend const decltype(Obj::impl) & | ||
sycl::detail::getSyclObjImpl(const Obj &SyclObject); | ||
|
||
template <class T> | ||
friend T sycl::detail::createSyclObjFromImpl( | ||
std::add_rvalue_reference_t<decltype(T::impl)> ImplObj); | ||
template <class T> | ||
friend T sycl::detail::createSyclObjFromImpl( | ||
std::add_lvalue_reference_t<const decltype(T::impl)> ImplObj); | ||
}; | ||
} // namespace ext::oneapi::experimental | ||
} // namespace _V1 | ||
} // namespace sycl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.