-
Notifications
You must be signed in to change notification settings - Fork 840
[SYCL] Implement register_host_memory extension API #22390
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
907b966
[UR][L0] Add read-only flag to host memory registration
againull a34863f
Merge remote-tracking branch 'origin/sycl' into ur_read_only
againull f89d360
[SYCL] Implement register_host_memory extension API
againull a85904b
Merge remote-tracking branch 'origin/sycl' into sycl_rt_impl_reg_mem
againull 9cd5f52
Format
againull 7fc552d
Update td for aspect
againull 7429eea
Address review
againull a847b38
Merge remote-tracking branch 'origin/sycl' into reg_mem_sycl_rt
againull 58b0c76
Require v2
againull e14282c
Address review
againull c9bb13b
Fix
againull 5efacbd
Merge remote-tracking branch 'origin/sycl' into reg_mem_sycl_rt
againull 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
82 changes: 82 additions & 0 deletions
82
sycl/include/sycl/ext/oneapi/experimental/register_host_memory.hpp
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,82 @@ | ||
| //==--- register_host_memory.hpp - SYCL host memory registration extension -==// | ||
| // | ||
| // 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/export.hpp> // for __SYCL_EXPORT | ||
| #include <sycl/ext/oneapi/properties.hpp> | ||
|
|
||
| #include <cstddef> // for size_t | ||
| #include <cstdint> // for uint32_t | ||
| #include <type_traits> | ||
|
|
||
| namespace sycl { | ||
| inline namespace _V1 { | ||
| class context; | ||
|
|
||
| namespace ext::oneapi::experimental { | ||
|
|
||
| // Indicates that device code will only read from the registered range. Device | ||
| // writes to a range registered with this property are undefined behavior. | ||
| struct read_only_key : detail::compile_time_property_key< | ||
| detail::PropKind::RegisterHostMemoryReadOnly> { | ||
| using value_t = property_value<read_only_key>; | ||
| }; | ||
|
|
||
| inline constexpr read_only_key::value_t read_only; | ||
|
|
||
| namespace detail { | ||
| // Implementation-internal flags describing a host memory registration. They | ||
| // are translated to UR flags in the runtime library. | ||
| enum register_host_memory_flags : uint32_t { | ||
| register_host_memory_flag_read_only = 1u << 0, | ||
| }; | ||
|
|
||
| // Non-templated implementation entry points, defined in the SYCL runtime | ||
| // library. Flags is a bitwise OR of register_host_memory_flags values. | ||
| __SYCL_EXPORT void register_host_memory(void *Ptr, size_t NumBytes, | ||
| const context &Ctxt, uint32_t Flags); | ||
| __SYCL_EXPORT void unregister_host_memory(void *Ptr, const context &Ctxt); | ||
|
|
||
| // Lowers a compile-time property list to the runtime flags word. | ||
| template <typename Properties> uint32_t getRegisterHostMemoryFlags() { | ||
| uint32_t Flags = 0; | ||
| if constexpr (std::decay_t<Properties>::template has_property< | ||
| read_only_key>()) | ||
| Flags |= register_host_memory_flag_read_only; | ||
| return Flags; | ||
| } | ||
| } // namespace detail | ||
|
|
||
| /// Registers the existing host memory range \p ptr of \p numBytes bytes with | ||
| /// \p ctxt so that it behaves like a USM host allocation. See | ||
| /// sycl_ext_oneapi_register_host_memory for the full semantics. | ||
| /// | ||
| /// \p ptr and \p numBytes must both be aligned to the host page size, \p ptr | ||
| /// must not be null, \p numBytes must not be zero, and every device in \p ctxt | ||
| /// must have aspect::ext_oneapi_register_host_memory. | ||
| template <typename Properties = empty_properties_t> | ||
| std::enable_if_t<is_property_list_v<std::decay_t<Properties>>> | ||
| register_host_memory(void *ptr, size_t numBytes, const context &ctxt, | ||
| Properties props = {}) { | ||
| (void)props; | ||
| detail::register_host_memory( | ||
| ptr, numBytes, ctxt, detail::getRegisterHostMemoryFlags<Properties>()); | ||
| } | ||
|
|
||
| /// Unregisters a host memory range previously registered with | ||
| /// register_host_memory. \p ptr must be the exact base pointer that was passed | ||
| /// to register_host_memory with the same \p ctxt, and the registration must | ||
| /// still be in effect. This does not free or unmap the underlying host memory. | ||
| inline void unregister_host_memory(void *ptr, const context &ctxt) { | ||
| detail::unregister_host_memory(ptr, ctxt); | ||
| } | ||
|
|
||
| } // 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
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.