Skip to content

Commit

Permalink
Drop memory::managed::region_t in favor of using just `memory::regi…
Browse files Browse the repository at this point in the history
…on_t`.
  • Loading branch information
eyalroz committed Feb 24, 2024
1 parent 882df66 commit 8f55efb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
34 changes: 11 additions & 23 deletions src/cuda/api/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1648,17 +1648,15 @@ inline void zero(T* ptr)
*/
namespace managed {

struct const_region_t;

namespace detail_ {

using advice_t = CUmem_advise;

template <typename T>
inline T get_scalar_range_attribute(managed::const_region_t region, range_attribute_t attribute);
inline T get_scalar_range_attribute(const_region_t region, range_attribute_t attribute);

inline void advise(managed::const_region_t region, advice_t advice, cuda::device::id_t device_id);
// inline void advise(managed::const_region_t region, advice_t attribute);
inline void advise(const_region_t region, advice_t advice, cuda::device::id_t device_id);
// inline void advise(const_region_t region, advice_t attribute);

template <typename T>
struct base_region_t : public memory::detail_::base_region_t<T> {
Expand Down Expand Up @@ -1689,26 +1687,16 @@ struct base_region_t : public memory::detail_::base_region_t<T> {

} // namespace detail_

struct region_t : public detail_::base_region_t<void> {
using base_region_t<void>::base_region_t;
operator memory::region_t() { return memory::region_t{ start(), size() }; }
};

struct const_region_t : public detail_::base_region_t<void const> {
using base_region_t<void const>::base_region_t;
const_region_t(const region_t& r) : detail_::base_region_t<void const>(r.start(), r.size()) {}
};

void advise_expected_access_by(managed::const_region_t region, device_t& device);
void advise_no_access_expected_by(managed::const_region_t region, device_t& device);
void advise_expected_access_by(const_region_t region, device_t& device);
void advise_no_access_expected_by(const_region_t region, device_t& device);

template <typename Allocator = ::std::allocator<cuda::device_t> >
typename ::std::vector<device_t, Allocator> accessors(managed::const_region_t region, const Allocator& allocator = Allocator() );
typename ::std::vector<device_t, Allocator> accessors(const_region_t region, const Allocator& allocator = Allocator() );

namespace detail_ {

template <typename T>
inline T get_scalar_range_attribute(managed::const_region_t region, range_attribute_t attribute)
inline T get_scalar_range_attribute(const_region_t region, range_attribute_t attribute)
{
uint32_t attribute_value { 0 };
auto result = cuMemRangeGetAttribute(
Expand All @@ -1720,14 +1708,14 @@ inline T get_scalar_range_attribute(managed::const_region_t region, range_attrib

// CUDA's range "advice" is simply a way to set the attributes of a range; unfortunately that's
// not called cuMemRangeSetAttribute, and uses a different enum.
inline void advise(managed::const_region_t region, advice_t advice, cuda::device::id_t device_id)
inline void advise(const_region_t region, advice_t advice, cuda::device::id_t device_id)
{
auto result = cuMemAdvise(device::address(region.start()), region.size(), advice, device_id);
throw_if_error_lazy(result, "Setting an attribute for a managed memory range at "
+ cuda::detail_::ptr_as_hex(region.start()));
}

// inline void set_range_attribute(managed::const_region_t region, range_attribute_t attribute, cuda::device::handle_t device_id)
// inline void set_range_attribute(const_region_t region, range_attribute_t attribute, cuda::device::handle_t device_id)

inline advice_t as_advice(range_attribute_t attribute, bool set)
{
Expand All @@ -1744,13 +1732,13 @@ inline advice_t as_advice(range_attribute_t attribute, bool set)
}
}

inline void set_range_attribute(managed::const_region_t region, range_attribute_t settable_attribute, cuda::device::id_t device_id)
inline void set_range_attribute(const_region_t region, range_attribute_t settable_attribute, cuda::device::id_t device_id)
{
static constexpr const bool set { true };
advise(region, as_advice(settable_attribute, set), device_id);
}

inline void unset_range_attribute(managed::const_region_t region, range_attribute_t settable_attribute)
inline void unset_range_attribute(const_region_t region, range_attribute_t settable_attribute)
{
static constexpr const bool unset { false };
static constexpr const cuda::device::id_t dummy_device_id { 0 };
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/api/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class stream_t {
* you must pass whatever @ref cuda::memory::managed::allocate() returned.
*/
void attach_managed_region(
memory::managed::region_t region,
memory::region_t region,
memory::managed::attachment_t attachment = memory::managed::attachment_t::single_stream) const
{
attach_managed_region(region.start(), attachment);
Expand Down

0 comments on commit 8f55efb

Please sign in to comment.