Skip to content

Commit

Permalink
Fixes #660: unique_span::operator= correction
Browse files Browse the repository at this point in the history
* The operator now properly returns `*this`.
* No longer assigning to `size()` and `data()`, but rather to `*this`-as-a-span.
* Added an explicit instantiation of a unique_span to the example program we compile with different versions of the C++ standard.
  • Loading branch information
eyalroz committed Jul 15, 2024
1 parent 86fefd5 commit f18303f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/other/new_cpp_standard/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ cuda::device::id_t get_current_device_id()
return device.id();
}

void unique_spans()
{
cuda::memory::host::unique_span<float> data1(nullptr, 0);
cuda::memory::host::unique_span<float> data2(nullptr, 0);

data1 = std::move(data2);
}

int main()
{
auto count = cuda::device::count();
Expand All @@ -38,5 +46,6 @@ int main()
auto nvtx_color_yellow = cuda::profiling::color_t::from_hex(0x0FFFF00);
(void) nvtx_color_yellow;
#endif

std::cout << "SUCCESS\n";
}
4 changes: 2 additions & 2 deletions src/cuda/api/detail/unique_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class unique_span : public ::cuda::span<T> {
if (data() != nullptr) {
deleter_type{}(data());
}
data() = released.data();
size() = released.size();
static_cast<span_type&>(*this) = released;
return *this;
}

/// No plain dereferencing - as there is no guarantee that any object has been
Expand Down

0 comments on commit f18303f

Please sign in to comment.