Skip to content

Commit 5d6838b

Browse files
CUDA: static assert to prevent misuse of memcpy_1 (ggml-org#17198)
1 parent 92bb442 commit 5d6838b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ggml/src/ggml-cuda/common.cuh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@ static __device__ __forceinline__ void ggml_cuda_mad(half2 & acc, const half2 v,
586586
// If dst and src point at different address spaces then they are guaranteed to not be aliased.
587587
template <int nbytes, int alignment = 0>
588588
static __device__ __forceinline__ void ggml_cuda_memcpy_1(void * __restrict__ dst, const void * __restrict__ src) {
589+
static_assert(
590+
nbytes <= ggml_cuda_get_max_cpy_bytes() || alignment == 0,
591+
"You are misusing the alignment parameter for ggml_cuda_memcpy_1. "
592+
"The intent is for the parameter is only as a workaround if either one of the pointers is not properly aligned. "
593+
"If you use it to do more bytes per copy than ggml_cuda_max_cpy_bytes() the reads and writes may not be coalesced. "
594+
"Call ggml_cuda_memcpy_1 in a loop instead.");
589595
if constexpr (alignment != 0) {
590596
static_assert(nbytes % alignment == 0, "bad alignment");
591597
}

0 commit comments

Comments
 (0)