Skip to content

Commit

Permalink
Fixes #429: Passing array_t objects by const-reference to all copy …
Browse files Browse the repository at this point in the history
…functions.

* Also, a comment tweak
  • Loading branch information
eyalroz committed Oct 14, 2022
1 parent f17a8f9 commit c802e6d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cuda/api/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ status_t multidim_copy(context::handle_t context_handle, copy_parameters_t<NumDi
return multidim_copy(::std::integral_constant<dimensionality_t, NumDimensions>{}, params);
}

} // namespace detail
} // namespace detail_

/**
* Synchronously copies data from a CUDA array into non-array memory.
Expand Down Expand Up @@ -829,7 +829,7 @@ void copy(T *destination, const array_t<T, NumDimensions>& source)
}

template <typename T, dimensionality_t NumDimensions>
void copy(array_t<T, NumDimensions> destination, array_t<T, NumDimensions> source)
void copy(const array_t<T, NumDimensions>& destination, const array_t<T, NumDimensions>& source)
{
detail_::copy_parameters_t<NumDimensions> params{};
auto dims = source.dimensions();
Expand All @@ -845,7 +845,6 @@ void copy(array_t<T, NumDimensions> destination, array_t<T, NumDimensions> sourc
throw_if_error_lazy(status, "Copying from a CUDA array into a regular memory region");
}


template <typename T, dimensionality_t NumDimensions>
void copy(region_t destination, const array_t<T, NumDimensions>& source)
{
Expand All @@ -855,6 +854,15 @@ void copy(region_t destination, const array_t<T, NumDimensions>& source)
copy(destination.start(), source);
}

template <typename T, dimensionality_t NumDimensions>
void copy(const array_t<T, NumDimensions>& destination, const_region_t & source)
{
if (destination.size_bytes() < source.size()) {
throw ::std::logic_error("Attempt to copy into an array from a source region larger than the array's size");
}
copy(destination, source.start());
}

/**
* Synchronously copies a single (typed) value between two memory locations.
*
Expand Down

0 comments on commit c802e6d

Please sign in to comment.