Skip to content

Commit

Permalink
Fixes #517 typed_set() was wrongfully accepting types of size 8 (an…
Browse files Browse the repository at this point in the history
…d not setting the values)
  • Loading branch information
eyalroz committed Jun 7, 2023
1 parent fb75600 commit e175454
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/cuda/api/multi_wrapper_impls/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,16 +546,14 @@ inline void typed_set(T* start, const T& value, size_t num_elements)
{
context::current::detail_::scoped_existence_ensurer_t ensure_some_context{};
static_assert(::std::is_trivially_copyable<T>::value, "Non-trivially-copyable types cannot be used for setting memory");
static_assert(
sizeof(T) == 1 or sizeof(T) == 2 or
sizeof(T) == 4 or sizeof(T) == 8,
"Unsupported type size - only sizes 1, 2 and 4 are supported");
static_assert(sizeof(T) == 1 or sizeof(T) == 2 or sizeof(T) == 4,
"Unsupported type size - only sizes 1, 2 and 4 are supported");
// TODO: Consider checking for alignment when compiling without NDEBUG
status_t result {CUDA_SUCCESS};
switch(sizeof(T)) {
case 1: result = cuMemsetD8 (address(start), reinterpret_cast<const ::std::uint8_t& >(value), num_elements); break;
case 2: result = cuMemsetD16(address(start), reinterpret_cast<const ::std::uint16_t&>(value), num_elements); break;
case 4: result = cuMemsetD32(address(start), reinterpret_cast<const ::std::uint32_t&>(value), num_elements); break;
case 1: result = cuMemsetD8 (address(start), reinterpret_cast<const ::std::uint8_t& >(value), num_elements); break;
case 2: result = cuMemsetD16(address(start), reinterpret_cast<const ::std::uint16_t&>(value), num_elements); break;
case 4: result = cuMemsetD32(address(start), reinterpret_cast<const ::std::uint32_t&>(value), num_elements); break;
}
throw_if_error_lazy(result, "Setting global device memory bytes");
}
Expand Down

0 comments on commit e175454

Please sign in to comment.