-
Notifications
You must be signed in to change notification settings - Fork 98
[SYCLomaitc] Migrate 2 CUDA IPC code to level zero APIs. #2818
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,11 @@ struct ipc_mem_handle_ext_t { | |
| ze_ipc_mem_handle_t handle; | ||
| }; | ||
|
|
||
| struct ipc_event_pool_handle_ext_t { | ||
| pid_t pid; | ||
| ze_ipc_event_pool_handle_t handle; | ||
| }; | ||
|
|
||
| namespace detail { | ||
|
|
||
| #ifndef _SYS_pidfd_open | ||
|
|
@@ -33,7 +38,7 @@ namespace detail { | |
| #define _SYS_pidfd_getfd 438 // syscall number for pidfd_getfd | ||
| #endif | ||
|
|
||
| inline int get_fd_of_peer_process(ipc_mem_handle_ext_t ext_handle) { | ||
| template <class T> inline int get_fd_of_peer_process(T ext_handle) { | ||
| int pidfd = syscall(_SYS_pidfd_open, ext_handle.pid, | ||
| 0); // obtain a file descriptor that refers to a | ||
| // process(requires kernel 5.6+). | ||
|
|
@@ -43,6 +48,35 @@ inline int get_fd_of_peer_process(ipc_mem_handle_ext_t ext_handle) { | |
| 0); // obtain a duplicate of another process's file | ||
| // descriptor(requires kernel 5.6+). | ||
| } | ||
| constexpr ze_event_pool_desc_t default_event_pool_desc = { | ||
| .stype = ZE_STRUCTURE_TYPE_EVENT_POOL_DESC, | ||
| .pNext = nullptr, | ||
| .flags = ZE_EVENT_POOL_FLAG_IPC | ZE_EVENT_POOL_FLAG_HOST_VISIBLE, | ||
| .count = 1}; | ||
|
|
||
| constexpr ze_event_desc_t default_event_desc = { | ||
| .stype = ZE_STRUCTURE_TYPE_EVENT_DESC, .index = 0, .signal = 0, .wait = 0}; | ||
|
|
||
| ze_event_pool_handle_t create_event_in_pool(sycl::event *event) { | ||
| ze_event_pool_handle_t h_event_pool = {}; | ||
| auto context = dpct::get_current_device().get_context(); | ||
|
|
||
| if (h_event_pool == nullptr) { | ||
| ze_device_handle_t device = | ||
| sycl::get_native<sycl::backend::ext_oneapi_level_zero>( | ||
| (sycl::device)dpct::get_current_device()); | ||
| zeEventPoolCreate( | ||
| sycl::get_native<sycl::backend::ext_oneapi_level_zero>(context), | ||
| &default_event_pool_desc, 1, &device, &h_event_pool); | ||
| } | ||
|
|
||
| ze_event_handle_t ze_event = {}; | ||
| zeEventCreate(h_event_pool, &default_event_desc, &ze_event); | ||
| zeEventHostReset(ze_event); | ||
| *event = sycl::make_event<sycl::backend::ext_oneapi_level_zero>( | ||
| {ze_event, sycl::ext::oneapi::level_zero::ownership::keep}, context); | ||
| return h_event_pool; | ||
| } | ||
|
|
||
| } // namespace detail | ||
|
|
||
|
|
@@ -76,6 +110,36 @@ inline ze_result_t open_mem_ipc_handle(ipc_mem_handle_ext_t ext_handle, | |
| ext_handle.handle, 0u, pptr); | ||
| } | ||
|
|
||
| /// Gets an IPC event pool handle for the specified event handle that can be shared with another process. | ||
| /// \param [in] ext_handle IPC memory handle extension | ||
| /// \param [out] phipc Returned IPC event handle | ||
| ze_result_t get_event_pool_ipc_handle(sycl::event *event, | ||
| ipc_event_pool_handle_ext_t *phipc) { | ||
| phipc->pid = getpid(); | ||
| ze_event_pool_handle_t h_event_pool = detail::create_event_in_pool(event); | ||
| return zeEventPoolGetIpcHandle(h_event_pool, &phipc->handle); | ||
| } | ||
|
|
||
| ze_result_t open_event_pool_ipc_handle(sycl::event **event, | ||
| ipc_event_pool_handle_ext_t hipc) { | ||
| ze_context_handle_t ze_context = | ||
| sycl::get_native<sycl::backend::ext_oneapi_level_zero>( | ||
| dpct::get_current_device().get_context()); | ||
| int fd = detail::get_fd_of_peer_process(hipc); | ||
| if (fd < 0) | ||
| throw std::runtime_error("Cannot get file descriptor of peer process."); | ||
| *((int *)hipc.handle.data) = detail::get_fd_of_peer_process(hipc); | ||
|
||
| ze_event_handle_t ze_event = {}; | ||
| ze_event_pool_handle_t h_event_pool_t; | ||
| auto ret = zeEventPoolOpenIpcHandle(ze_context, hipc.handle, &h_event_pool_t); | ||
| zeEventCreate(h_event_pool_t, &detail::default_event_desc, &ze_event); | ||
| zeEventHostSignal(ze_event); | ||
| *event = | ||
| new sycl::event(sycl::make_event<sycl::backend::ext_oneapi_level_zero>( | ||
| {ze_event, sycl::ext::oneapi::level_zero::ownership::keep}, | ||
| dpct::get_current_device().get_context())); | ||
| return ret; | ||
| } | ||
| } // namespace experimental | ||
| } // namespace dpct | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The report message within this block uses 'cudaIpcMemHandle_t' instead of 'cudaIpcEventHandle_t', which may confuse users expecting the correct type name. Please update the string to 'cudaIpcEventHandle_t' to reflect the correct experimental feature.