Skip to content

Commit f5643ef

Browse files
committed
Fixes #713 + minor unique_region tweaks:
* The `reset()` method now passes a pointer, rather than a region, to the deleter * Now using `get_deleter()` in the destructor as well * Comment corrections and deletions * Added an instantiation of `unique_region` to the `new_cpp_standard` example program Thanks goes to GitHub user @ralwing for catching the bug and proposing the fix.
1 parent bb5d252 commit f5643ef

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

examples/other/new_cpp_standard/main.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ cuda::device::id_t get_current_device_id()
2626

2727
void unique_spans()
2828
{
29-
cuda::unique_span<float> data1(nullptr, 0, cuda::detail_::default_span_deleter<float>);
30-
cuda::unique_span<float> data2(nullptr, 0, cuda::detail_::default_span_deleter<float>);
29+
auto device = cuda::device::current::get();
30+
auto us1 = cuda::make_unique_span<float>(10);
31+
auto us2 = cuda::unique_span<float>(nullptr, 0, cuda::detail_::default_span_deleter<float>);
32+
auto us3 = cuda::unique_span<float>(nullptr, 0, cuda::detail_::default_span_deleter<float>);
33+
us2 = std::move(us3);
34+
}
3135

32-
data1 = std::move(data2);
36+
void unique_regions()
37+
{
38+
auto device = cuda::device::current::get();
39+
auto ur1 = cuda::memory::device::make_unique_region(device, 10);
40+
auto ur2 = cuda::memory::device::make_unique_region(device, 10);
41+
using std::swap;
42+
swap(ur1, ur2);
3343
}
3444

3545
int main()

src/cuda/api/unique_region.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class unique_region : public region_t {
6060

6161
// Note: No constructor which also takes a deleter. We do not hold a deleter
6262
// member - unlike unique_ptr's. If we wanted a general-purpose unique region
63-
// that's not just GPU allcoation-oriented, we might have had one of those.
63+
// that's not just GPU allocation-oriented, we might have had one of those.
6464

6565
/// Move constructor.
6666
unique_region(unique_region&& other) noexcept : unique_region(other.release()) { }
@@ -74,7 +74,7 @@ class unique_region : public region_t {
7474
~unique_region() noexcept
7575
{
7676
if (data() != nullptr) {
77-
deleter_type{}(data());
77+
get_deleter()(data());
7878
}
7979
static_cast<region_t&>(*this) = region_t{ nullptr, 0 };
8080
}
@@ -89,8 +89,6 @@ class unique_region : public region_t {
8989
return *this;
9090
}
9191

92-
// No "assignment from anoterh type", a s
93-
9492
/// Reset the %unique_region to empty, invoking the deleter if necessary.
9593
unique_region&
9694
operator=(::std::nullptr_t) noexcept
@@ -111,7 +109,7 @@ class unique_region : public region_t {
111109

112110
/// Return a deleter of the fixed type (it can't be a reference -
113111
/// we don't keep a deleter object)
114-
deleter_type get_deleter() const noexcept { return Deleter{}; }
112+
deleter_type get_deleter() const noexcept { return deleter_type{}; }
115113

116114
/// Return @c true if the stored pointer is not null.
117115
explicit operator bool() const noexcept { return data() != nullptr; }
@@ -138,7 +136,7 @@ class unique_region : public region_t {
138136
{
139137
::std::swap<region_t>(*this, region);
140138
if (region.start() != nullptr) {
141-
get_deleter()(region);
139+
get_deleter()(region.data());
142140
}
143141
}
144142

0 commit comments

Comments
 (0)