-
Notifications
You must be signed in to change notification settings - Fork 188
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
[FEA]: provide a type erased owning resource wrapper #1426
Comments
@harrism Would love to get your input here |
Can you provide a sketch of what using |
Regarding the mentioned two use cases A way to store the memory resource used per device (shamelessly stolen from rmm) using namespace cuda::mr;
inline auto& get_map()
{
static std::map<cuda_device_id::value_type, any_resource_with<device_accessible>> device_id_to_resource;
return device_id_to_resource;
}
async_resource_ref<device_accessible> get_per_device_resource(cuda_device_id device_id)
{
std::lock_guard<std::mutex> lock{detail::map_lock()};
auto& map = detail::get_map();
// If a resource was never set for `id`, set to the initial resource
auto const found = map.find(device_id.value());
return (found == map.end()) ? (map[device_id.value()] = detail::initial_resource())
: found->second;
} A test framework for different memory resources again stolen from rmm using MRFactoryFunc = std::function<std::shared_ptr<any_resource_with<device_accessible>>()>; A container that actually stores a memory resource class my_container {
private:
any_resource_with<...> mr_;
void* __ptr;
....
}; |
In general any RAII type memory functionality kind of wants to actually store the used memory resource and not rely on |
Specifically, you mean storing an owning reference to the resource? Because otherwise, you could simply store a |
Yeah this is explicitly about owning a resource |
Would What would it look like to construct an |
I'm not familiar with this convention. Can you provide references? Why don't C++ smart pointers ( |
Final question: would it be better to try this out in RMM first to work out the kinks before canonizing it in CCCL? After all the use cases are in RMM... |
The convention is that |
Regarding the question about unique_ptr, that should be doable, but what we also want is something that lives on the stack and not the heap |
Can you add this point (and a reason why) to the issue description? |
|
Yep, I think that's what Michael said already. :) Just asking for it to be all documented in the issue description. |
We will need this implemented in order to move forward with removing RMM's MR base classes. |
Couple more questions.
So:
To me, it seems like for consistency |
…2266) * Implement `any_resource` an owning wrapper around any resource Addresses #1426 * Continue development of @miscco's `any_resource` * address review feedback * [pre-commit.ci] auto code formatting * mark all deallocation functions as `noexcept` * fix some test failures * more tests and bug fixes * fix more build breaks * attempt to fix the cudax docs build * exclude more symbols from the cudax docs * more portability fixes and doxygen tweaks * once more with feeling * getting pretty close now * fix broken test * deduplicate `basic_any_resource` constructors to satisfy doxygen * [pre-commit.ci] auto code formatting * don't use `if constexpr` when compiling as c++14 * more fixes for doxygen and c++14 * back out a questionable addition of `noexcept` * molify msvc * accommodate integer size differences on msvc * eliminate shadow warning treated as error * handle duplicate properties without triggering compiler warnings * [pre-commit.ci] auto code formatting --------- Co-authored-by: Michael Schellenberger Costa <[email protected]>
…VIDIA#2266) * Implement `any_resource` an owning wrapper around any resource Addresses NVIDIA#1426 * Continue development of @miscco's `any_resource` * address review feedback * [pre-commit.ci] auto code formatting * mark all deallocation functions as `noexcept` * fix some test failures * more tests and bug fixes * fix more build breaks * attempt to fix the cudax docs build * exclude more symbols from the cudax docs * more portability fixes and doxygen tweaks * once more with feeling * getting pretty close now * fix broken test * deduplicate `basic_any_resource` constructors to satisfy doxygen * [pre-commit.ci] auto code formatting * don't use `if constexpr` when compiling as c++14 * more fixes for doxygen and c++14 * back out a questionable addition of `noexcept` * molify msvc * accommodate integer size differences on msvc * eliminate shadow warning treated as error * handle duplicate properties without triggering compiler warnings * [pre-commit.ci] auto code formatting --------- Co-authored-by: Michael Schellenberger Costa <[email protected]>
…`cudax::any_resource` (#2293) * Implement `any_resource` an owning wrapper around any resource Addresses #1426 * Continue development of @miscco's `any_resource` * address review feedback * [pre-commit.ci] auto code formatting * mark all deallocation functions as `noexcept` * fix some test failures * more tests and bug fixes * fix more build breaks * attempt to fix the cudax docs build * exclude more symbols from the cudax docs * more portability fixes and doxygen tweaks * once more with feeling * getting pretty close now * fix broken test * deduplicate `basic_any_resource` constructors to satisfy doxygen * [pre-commit.ci] auto code formatting * don't use `if constexpr` when compiling as c++14 * more fixes for doxygen and c++14 * back out a questionable addition of `noexcept` * molify msvc * accommodate integer size differences on msvc * eliminate shadow warning treated as error * handle duplicate properties without triggering compiler warnings * change `uninitialized_buffer` to own its memory resource using `any_resource` * Use fully qualified name * Drop `__host__ __device__` from uninitialized_buffer * Revert "Drop `__host__ __device__` from uninitialized_buffer" This reverts commit 5115b08. * Just do the cursed thing * Add missing include * Adopt the doc string --------- Co-authored-by: Michael Schellenberger Costa <[email protected]> Co-authored-by: anon <users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…VIDIA#2266) * Implement `any_resource` an owning wrapper around any resource Addresses NVIDIA#1426 * Continue development of @miscco's `any_resource` * address review feedback * [pre-commit.ci] auto code formatting * mark all deallocation functions as `noexcept` * fix some test failures * more tests and bug fixes * fix more build breaks * attempt to fix the cudax docs build * exclude more symbols from the cudax docs * more portability fixes and doxygen tweaks * once more with feeling * getting pretty close now * fix broken test * deduplicate `basic_any_resource` constructors to satisfy doxygen * [pre-commit.ci] auto code formatting * don't use `if constexpr` when compiling as c++14 * more fixes for doxygen and c++14 * back out a questionable addition of `noexcept` * molify msvc * accommodate integer size differences on msvc * eliminate shadow warning treated as error * handle duplicate properties without triggering compiler warnings * [pre-commit.ci] auto code formatting --------- Co-authored-by: Michael Schellenberger Costa <[email protected]>
…`cudax::any_resource` (NVIDIA#2293) * Implement `any_resource` an owning wrapper around any resource Addresses NVIDIA#1426 * Continue development of @miscco's `any_resource` * address review feedback * [pre-commit.ci] auto code formatting * mark all deallocation functions as `noexcept` * fix some test failures * more tests and bug fixes * fix more build breaks * attempt to fix the cudax docs build * exclude more symbols from the cudax docs * more portability fixes and doxygen tweaks * once more with feeling * getting pretty close now * fix broken test * deduplicate `basic_any_resource` constructors to satisfy doxygen * [pre-commit.ci] auto code formatting * don't use `if constexpr` when compiling as c++14 * more fixes for doxygen and c++14 * back out a questionable addition of `noexcept` * molify msvc * accommodate integer size differences on msvc * eliminate shadow warning treated as error * handle duplicate properties without triggering compiler warnings * change `uninitialized_buffer` to own its memory resource using `any_resource` * Use fully qualified name * Drop `__host__ __device__` from uninitialized_buffer * Revert "Drop `__host__ __device__` from uninitialized_buffer" This reverts commit 5115b08. * Just do the cursed thing * Add missing include * Adopt the doc string --------- Co-authored-by: Michael Schellenberger Costa <[email protected]> Co-authored-by: anon <users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Is this a duplicate?
Area
libcu++
Is your feature request related to a problem? Please describe.
libcu++ currently provides the
{async_}resource_ref
wrapper that provides type erased access to an existing memory resource.However, often we want to also store a type erased memory resource to then pass around through a
{async_}resource_ref
Describe the solution you'd like
Following convention, I would propose to name it
any_resource
. Obvious use cases are testing frameworks which usually test APIs against a host of different resources and also certain resource adaptors that want to adopt a memory resource.Finally this would also allow it to create something similar to
rmm:{get,set}_current_device_resource
.Just throwing ideas around I believe it would be sufficient to only store few methods in an external vtable
destroy
we need to redirect to the correct destructor during destruction ofany_resource
to_resource_ref
we need to have a static method that creates a{async_}resource_ref
with the right member functions. We can use this throughoperator->
oroperator*
Describe alternatives you've considered
Just using a
std::any
does not work, because we need a good way to actually create a{async_}resource_ref
from the stored type erased resource.Additional context
No response
The text was updated successfully, but these errors were encountered: