-
Notifications
You must be signed in to change notification settings - Fork 5
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
Require allocated type to have only a trivial constructor for make_device_unique and make_host_unique #204
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ class CUDAService { | |
template <typename T> | ||
typename cudaserviceimpl::make_device_unique_selector<T>::non_array | ||
make_device_unique(cuda::stream_t<>& stream) { | ||
static_assert(std::is_trivially_constructible<T>::value, "Allocating with non-trivial constructor on the device memory is not supported"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to fail the instantiation using Pro: the templates can be used with SFINAE. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably not woken up enough, but what would be the benefit of SFINAE be with these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, no, I don't think there is any advantage... |
||
int dev = getCurrentDevice(); | ||
void *mem = allocate_device(dev, sizeof(T), stream); | ||
return typename cudaserviceimpl::make_device_unique_selector<T>::non_array(reinterpret_cast<T *>(mem), | ||
|
@@ -83,8 +84,9 @@ class CUDAService { | |
template <typename T> | ||
typename cudaserviceimpl::make_device_unique_selector<T>::unbounded_array | ||
make_device_unique(size_t n, cuda::stream_t<>& stream) { | ||
int dev = getCurrentDevice(); | ||
using element_type = typename std::remove_extent<T>::type; | ||
static_assert(std::is_trivially_constructible<element_type>::value, "Allocating with non-trivial constructor on the device memory is not supported"); | ||
int dev = getCurrentDevice(); | ||
void *mem = allocate_device(dev, n*sizeof(element_type), stream); | ||
return typename cudaserviceimpl::make_device_unique_selector<T>::unbounded_array(reinterpret_cast<element_type *>(mem), | ||
[this, dev](void *ptr) { | ||
|
@@ -100,6 +102,7 @@ class CUDAService { | |
template <typename T> | ||
typename cudaserviceimpl::make_host_unique_selector<T>::non_array | ||
make_host_unique(cuda::stream_t<>& stream) { | ||
static_assert(std::is_trivially_constructible<T>::value, "Allocating with non-trivial constructor on the pinned host memory is not supported"); | ||
void *mem = allocate_host(sizeof(T), stream); | ||
return typename cudaserviceimpl::make_host_unique_selector<T>::non_array(reinterpret_cast<T *>(mem), | ||
[this](void *ptr) { | ||
|
@@ -111,6 +114,7 @@ class CUDAService { | |
typename cudaserviceimpl::make_host_unique_selector<T>::unbounded_array | ||
make_host_unique(size_t n, cuda::stream_t<>& stream) { | ||
using element_type = typename std::remove_extent<T>::type; | ||
static_assert(std::is_trivially_constructible<element_type>::value, "Allocating with non-trivial constructor on the pinned host memory is not supported"); | ||
void *mem = allocate_host(n*sizeof(element_type), stream); | ||
return typename cudaserviceimpl::make_host_unique_selector<T>::unbounded_array(reinterpret_cast<element_type *>(mem), | ||
[this](void *ptr) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you remove the
nullptr
initialisation ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because those lead to constructor being non-trivial (since it would do some initialization).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course sorry (trivial really means it does nothing...).