Skip to content
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

Memory resource / view #2

Open
wants to merge 360 commits into
base: cuda_memory_resource
Choose a base branch
from

Conversation

mzient
Copy link

@mzient mzient commented Apr 25, 2021

This is a copy of PR PR #158 in libcudacxx

This work builds on [NVIDIA#105] ((NVIDIA#105)

The resource is defined in terms of memory kind.
resource_view (a glorifieid pointer with elaborate conversion logic) is defined in terms of the properties of the memory allocated. This allows, for example, to define a function that expects a resource_view<memory_access::host> to take memory_resource and memory_resource, even though these types are not related.

Summary (from #105 ):
cuda::memory_kind (namespace)
Groups kinds of memory allocated
Possible values: device, managed, pinned, host
cuda::memory_resource<memory_kind, context>
Synchronous (de)allocation of storage of the specified memory_kind
cuda::stream_ordered_memory_resource<memory_kind>
Asynchronous, stream-ordered (de)allocation of storage of the specified memory_kind
The semantics of stream ordered memory allocation are as defined here
stream_ordered_memory_resource inherits from memory_resource and provides a default implementation of allocate/deallocate by allocating on the default stream and synchronizing.
cuda::stream_view
A non-owning wrapper for cudaStream_t
cuda::cuda_error
Exception thrown on CUDA runtime API errors
throw_on_cuda_error utility for checking result of CUDA runtime API calls

New (wrt #105 ):
cuda::basic_resource_view<resource_pointer, properties...> a pointer-like object that can be used in place of memory_resource and pameterized in terms of memory properties instead of memory kind.
cuda::memory_resource_base, cuda::stream_ordered_memory_resource_base - base classes with common interface for all memory resources regardless of their memory kind. The bases are private so that the user can't blindly declare a function parameter as cuda::memory_resource_base and unsafely pass a resource of any kind there. Instead, resource_view should be used.
resource_view, stream_ordererd_resource_view - template aliases for basic_resource_view, with pointers the base resource types substituted for the resource_pointer. These types are befriended with (stream_ordered_)memory_resource and therefore the access to the private base class is allowed. There's no way to obtain the base pointer except for calling operator-> which is intended for exposing the resource interface.

TODO: Add tests for resource_view

@mzient mzient force-pushed the memres_view branch 2 times, most recently from 5e19b23 to 319db3e Compare June 7, 2021 17:27
wmaxey and others added 27 commits August 3, 2021 19:25
Refactor <atomic> and move implementation to libcxx
…stexpr

Add `inline` and `constexpr` qualifiers to `__cxx_atomic_is_lock_free`
Fix `cuda::atomic<Integral>`'s `fetch_max/fetch_min` extension
Add a path for nvc++ host side atomics in __config
jrhemstad and others added 24 commits October 27, 2021 10:33
- add (basic_)resource_view template
- add private base classes for memory resources
- make memory kind a tag type
- rename unified memory to managed
- fix tests for exceptions
- adjust __cuda_util for no-exceptions builds

TODO: add tests for views.

Signed-off-by: Michał Zientkiewicz <[email protected]>
properly propagated to the resource view via operator->.

Signed-off-by: Michał Zientkiewicz <[email protected]>
* Fix typos.
* Move base interfaces to namespace detail.
* Add resource_view comparison.
* Add a view_resource with default property (is_kind).

Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
* Remove superfluous override
* Make __do_as_kind final

Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Add operator bool in resource view.
Disallow construction of resource_view from integer (0).
Add context to as_kind.

Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Signed-off-by: Michał Zientkiewicz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants