-
Notifications
You must be signed in to change notification settings - Fork 769
[AsyncAlloc][SYCL][CUDA][Exp] Initial device side implementation for the sycl_ext_oneapi_async_memory_alloc extension #16900
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
45 commits
Select commit
Hold shift + click to select a range
8ac949b
[AsyncAlloc][SYCL][CUDA][Exp] Initial device side implementation for the
Seanst98 13cea8d
Address feedback. Replace UR USMPoolSetThresholdExp with USMPoolSetIn…
Seanst98 553247f
Merge branch 'sycl' into sean/async-alloc
Seanst98 b261147
Address feedback
Seanst98 5646474
Merge branch 'sycl' into sean/async-alloc
Seanst98 c308b22
Merge branch 'sycl' into sean/async-alloc
Seanst98 3d83097
Merge branch 'sycl' into sean/async-alloc
Seanst98 e332e79
Address feedback
Seanst98 51db796
Merge branch 'sycl' into sean/async-alloc
Seanst98 9f32b79
Merge branch 'sycl' into sean/async-alloc
Seanst98 c9411b9
Address feedback:
Seanst98 9018de4
Merge branch 'sycl' into sean/async-alloc
Seanst98 aa8599d
Add symbols dump
Seanst98 aefd4a2
Merge branch 'sycl' into sean/async-alloc
Seanst98 7d3155d
Fix self-contained-check
Seanst98 73772c4
Merge branch 'sycl' into sean/async-alloc
Seanst98 6b7152c
Add EOF lines
Seanst98 8e9ea97
Minor style changes
Seanst98 8fcaa39
Merge branch 'sycl' into sean/async-alloc
Seanst98 8d90123
Warning fixup
Seanst98 3e3cda5
Address feedback
Seanst98 d7f1c82
Remove some redundant includes
Seanst98 0ddd2d1
Fix missing constructor default
Seanst98 c452e5a
Add missing include
Seanst98 5757d13
Test broken build
Seanst98 4d48509
Test broken build
Seanst98 00de9a4
Add includes to see if that fixes build
Seanst98 ac392af
Move memory_pool.cpp to source top level
Seanst98 8a0d4c3
Undo broken changes
Seanst98 3780680
Bring back changes. Failure likely CI related
Seanst98 d40690c
Merge branch 'sycl' into sean/async-alloc
Seanst98 b4da32b
Modify createSyclObjFromImpl to follow new style
Seanst98 a78d3a4
Address changes to spec. Add tests
Seanst98 cbfc355
Merge branch 'sycl' into sean/async-alloc
Seanst98 f511bd5
Remove erroneous message about a non-error
Seanst98 1af1e7e
Update API to spec changes
Seanst98 363bbc4
Merge branch 'sycl' into sean/async-alloc
Seanst98 83adbe8
Merge branch 'sycl' into sean/async-alloc
Seanst98 da17dd1
Add const to memory_pool and remove watermark queries/resetters
Seanst98 2ba3fd9
Merge branch 'sycl' into sean/async-alloc
Seanst98 9bc5dc9
Update symbols
Seanst98 e48d88a
Merge branch 'sycl' into sean/async-alloc
Seanst98 2b81311
Merge branch 'sycl' into sean/async-alloc
Seanst98 22e6311
Merge branch 'sycl' into sean/async-alloc
Seanst98 285f593
Merge branch 'sycl' into sean/async-alloc
npmiller 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
95 changes: 95 additions & 0 deletions
95
sycl/include/sycl/ext/oneapi/experimental/async_alloc/async_alloc.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,95 @@ | ||
//==----------- async_alloc.hpp --- SYCL asynchronous allocation -----------==// | ||
// | ||
// 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/common.hpp> // for code_location | ||
#include <sycl/handler.hpp> // for handler | ||
#include <sycl/queue.hpp> // for queue | ||
#include <sycl/usm/usm_enums.hpp> // for usm::alloc | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace ext::oneapi::experimental { | ||
|
||
// Forward declare memory_pool. | ||
class memory_pool; | ||
|
||
/** | ||
* @brief Asynchronousy allocate memory from a default pool. | ||
* | ||
* @param q The queue with which to enqueue the asynchronous allocation. | ||
* @param kind The kind of memory pool allocation - device, host, shared, etc. | ||
* @param size The size in bytes to allocate. | ||
* | ||
* @return Generic pointer to allocated USM memory. | ||
*/ | ||
__SYCL_EXPORT void *async_malloc(const sycl::queue &q, sycl::usm::alloc kind, | ||
AerialMantis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
size_t size, | ||
const sycl::detail::code_location &CodeLoc = | ||
sycl::detail::code_location::current()); | ||
|
||
/** | ||
* @brief Asynchronously allocate memory from a default pool. | ||
* | ||
* @param h The handler with which to enqueue the asynchronous allocation. | ||
* @param kind The kind of memory pool allocation - device, host, shared, etc. | ||
* @param size The size in bytes to allocate. | ||
* | ||
* @return Generic pointer to allocated USM memory. | ||
*/ | ||
__SYCL_EXPORT void *async_malloc(sycl::handler &h, sycl::usm::alloc kind, | ||
size_t size); | ||
|
||
/** | ||
* @brief Asynchronously allocate memory from a specified pool. | ||
* | ||
* @param q The queue with which to enqueue the asynchronous allocation. | ||
* @param size The size in bytes to allocate. | ||
* @param pool The pool with which to allocate from. | ||
* | ||
* @return Generic pointer to allocated USM memory. | ||
*/ | ||
__SYCL_EXPORT void * | ||
async_malloc_from_pool(const sycl::queue &q, size_t size, | ||
const memory_pool &pool, | ||
const sycl::detail::code_location &CodeLoc = | ||
sycl::detail::code_location::current()); | ||
|
||
/** | ||
* @brief Asynchronously allocate memory from a specified pool. | ||
* | ||
* @param h The handler with which to enqueue the asynchronous allocation. | ||
* @param size The size in bytes to allocate. | ||
* @param pool The pool with which to allocate from. | ||
* | ||
* @return Generic pointer to allocated USM memory. | ||
*/ | ||
__SYCL_EXPORT void *async_malloc_from_pool(sycl::handler &h, size_t size, | ||
const memory_pool &pool); | ||
|
||
/** | ||
* @brief Asynchronously free memory. | ||
* | ||
* @param q The queue with which to enqueue the asynchronous free. | ||
* @param ptr The generic pointer to be freed. | ||
*/ | ||
__SYCL_EXPORT void async_free(const sycl::queue &q, void *ptr, | ||
const sycl::detail::code_location &CodeLoc = | ||
sycl::detail::code_location::current()); | ||
|
||
/** | ||
* @brief Asynchronously free memory. | ||
* | ||
* @param h The handler with which to enqueue the asynchronous free. | ||
* @param ptr The generic pointer to be freed. | ||
*/ | ||
__SYCL_EXPORT void async_free(sycl::handler &h, void *ptr); | ||
|
||
} // namespace ext::oneapi::experimental | ||
} // namespace _V1 | ||
} // namespace sycl |
122 changes: 122 additions & 0 deletions
122
sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool.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,122 @@ | ||
//==----------- memory_pool.hpp --- SYCL asynchronous allocation -----------==// | ||
// | ||
// 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/context.hpp> // for context | ||
#include <sycl/device.hpp> // for device | ||
#include <sycl/ext/oneapi/experimental/async_alloc/memory_pool_properties.hpp> | ||
#include <sycl/queue.hpp> // for queue | ||
#include <sycl/usm/usm_enums.hpp> // for usm::alloc | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace ext::oneapi::experimental { | ||
|
||
// Forward declare memory_pool_impl. | ||
namespace detail { | ||
class memory_pool_impl; | ||
} // namespace detail | ||
|
||
/// Memory pool | ||
class __SYCL_EXPORT memory_pool { | ||
|
||
public: | ||
// NOT SUPPORTED: Host side pools unsupported. | ||
memory_pool(const sycl::context &, sycl::usm::alloc kind, | ||
const property_list & = {}) { | ||
if (kind == sycl::usm::alloc::device || kind == sycl::usm::alloc::shared) | ||
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid), | ||
"Device and shared allocation kinds are disallowed " | ||
"without specifying a device!"); | ||
if (kind == sycl::usm::alloc::unknown) | ||
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid), | ||
"Unknown allocation kinds are disallowed!"); | ||
|
||
throw sycl::exception( | ||
sycl::make_error_code(sycl::errc::feature_not_supported), | ||
"Host allocated pools are unsupported!"); | ||
} | ||
|
||
memory_pool(const sycl::context &ctx, const sycl::device &dev, | ||
sycl::usm::alloc kind, const property_list &props = {}); | ||
|
||
memory_pool(const sycl::queue &q, sycl::usm::alloc kind, | ||
const property_list &props = {}) | ||
: memory_pool(q.get_context(), q.get_device(), kind, props) {} | ||
|
||
// NOT SUPPORTED: Creating a pool from an existing allocation is unsupported. | ||
memory_pool(const sycl::context &, void *, size_t, | ||
const property_list & = {}) { | ||
throw sycl::exception( | ||
sycl::make_error_code(sycl::errc::feature_not_supported), | ||
"Creating a pool from an existing allocation is unsupported!"); | ||
} | ||
|
||
~memory_pool() = default; | ||
|
||
// Copy constructible/assignable, move constructible/assignable. | ||
memory_pool(const memory_pool &) = default; | ||
memory_pool(memory_pool &&) = default; | ||
memory_pool &operator=(const memory_pool &) = default; | ||
memory_pool &operator=(memory_pool &&) = default; | ||
|
||
// Equality comparison. | ||
bool operator==(const memory_pool &rhs) const { return impl == rhs.impl; } | ||
bool operator!=(const memory_pool &rhs) const { return !(*this == rhs); } | ||
|
||
// Impl handles getters and setters. | ||
sycl::context get_context() const; | ||
sycl::device get_device() const; | ||
sycl::usm::alloc get_alloc_kind() const; | ||
size_t get_threshold() const; | ||
size_t get_reserved_size_current() const; | ||
size_t get_used_size_current() const; | ||
|
||
void increase_threshold_to(size_t newThreshold); | ||
|
||
// Property getters. | ||
template <typename PropertyT> bool has_property() const noexcept { | ||
return getPropList().template has_property<PropertyT>(); | ||
} | ||
template <typename PropertyT> PropertyT get_property() const { | ||
return getPropList().template get_property<PropertyT>(); | ||
} | ||
|
||
protected: | ||
std::shared_ptr<detail::memory_pool_impl> impl; | ||
|
||
memory_pool(std::shared_ptr<detail::memory_pool_impl> Impl) : 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); | ||
|
||
const property_list &getPropList() const; | ||
}; | ||
|
||
} // namespace ext::oneapi::experimental | ||
} // namespace _V1 | ||
} // namespace sycl | ||
|
||
namespace std { | ||
template <> struct hash<sycl::ext::oneapi::experimental::memory_pool> { | ||
size_t operator()( | ||
const sycl::ext::oneapi::experimental::memory_pool &mem_pool) const { | ||
return hash<std::shared_ptr< | ||
sycl::ext::oneapi::experimental::detail::memory_pool_impl>>()( | ||
sycl::detail::getSyclObjImpl(mem_pool)); | ||
} | ||
}; | ||
} // namespace std |
80 changes: 80 additions & 0 deletions
80
sycl/include/sycl/ext/oneapi/experimental/async_alloc/memory_pool_properties.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,80 @@ | ||
//==------ memory_pool_properties.hpp --- SYCL asynchronous allocation -----==// | ||
// | ||
// 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 <cstddef> | ||
#include <sycl/properties/property_traits.hpp> | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace ext::oneapi::experimental { | ||
|
||
// Forward declare memory_pool. | ||
class memory_pool; | ||
|
||
namespace property::memory_pool { | ||
|
||
// Property that determines the initial threshold of a memory pool. | ||
struct initial_threshold : public sycl::detail::PropertyWithData< | ||
sycl::detail::MemPoolInitialThreshold> { | ||
initial_threshold(size_t initialThreshold) | ||
: initialThreshold(initialThreshold) {}; | ||
size_t get_initial_threshold() { return initialThreshold; } | ||
|
||
private: | ||
size_t initialThreshold; | ||
}; | ||
|
||
// Property that determines the maximum size of a memory pool. | ||
struct maximum_size | ||
: public sycl::detail::PropertyWithData<sycl::detail::MemPoolMaximumSize> { | ||
maximum_size(size_t maxSize) : maxSize(maxSize) {}; | ||
size_t get_maximum_size() { return maxSize; } | ||
|
||
private: | ||
size_t maxSize; | ||
}; | ||
|
||
// Property that provides a performance hint that all allocations from this pool | ||
// will only be read from within SYCL kernel functions. | ||
struct read_only | ||
: public sycl::detail::DataLessProperty<sycl::detail::MemPoolReadOnly> { | ||
read_only() = default; | ||
}; | ||
|
||
// Property that initial allocations to a pool (not subsequent allocations | ||
// from prior frees) are iniitialised to zero. | ||
struct zero_init | ||
: public sycl::detail::DataLessProperty<sycl::detail::MemPoolZeroInit> { | ||
zero_init() = default; | ||
}; | ||
} // namespace property::memory_pool | ||
} // namespace ext::oneapi::experimental | ||
|
||
template <> | ||
struct is_property< | ||
sycl::ext::oneapi::experimental::property::memory_pool::initial_threshold> | ||
: std::true_type {}; | ||
|
||
template <> | ||
struct is_property< | ||
sycl::ext::oneapi::experimental::property::memory_pool::maximum_size> | ||
: std::true_type {}; | ||
|
||
template <> | ||
struct is_property< | ||
sycl::ext::oneapi::experimental::property::memory_pool::read_only> | ||
: std::true_type {}; | ||
|
||
template <> | ||
struct is_property< | ||
sycl::ext::oneapi::experimental::property::memory_pool::zero_init> | ||
: std::true_type {}; | ||
|
||
} // namespace _V1 | ||
} // namespace sycl |
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.