From 4e49b75c478e1d2eba42b7f401ade67ae0c897df Mon Sep 17 00:00:00 2001 From: Edgar Gabriel Date: Fri, 12 Jan 2024 13:12:47 -0800 Subject: [PATCH] opal/accelerator: allow 0 size copies it looks like zero size messages with valid buffer pointers can occur for send-to-self operations and with persistent request. The current accelerator components return however an error for size 0 making those tests fail in our testsuite. This commit allows size 0 messages, and returns immediatly. Signed-off-by: Edgar Gabriel (cherry picked from commit 9965f6c518956cd88be18de6633b28e2bbaf0ea4) --- opal/mca/accelerator/cuda/accelerator_cuda.c | 10 ++++++++-- opal/mca/accelerator/rocm/accelerator_rocm_module.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/opal/mca/accelerator/cuda/accelerator_cuda.c b/opal/mca/accelerator/cuda/accelerator_cuda.c index 49d181a0b00..116f0713cd4 100644 --- a/opal/mca/accelerator/cuda/accelerator_cuda.c +++ b/opal/mca/accelerator/cuda/accelerator_cuda.c @@ -364,9 +364,12 @@ static int accelerator_cuda_memcpy_async(int dest_dev_id, int src_dev_id, void * return delayed_init; } - if (NULL == stream || NULL == dest || NULL == src || size <= 0) { + if (NULL == stream || NULL == dest || NULL == src || size < 0) { return OPAL_ERR_BAD_PARAM; } + if (0 == size) { + return OPAL_SUCCESS; + } result = cuMemcpyAsync((CUdeviceptr) dest, (CUdeviceptr) src, size, *(CUstream *)stream->stream); if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) { @@ -387,9 +390,12 @@ static int accelerator_cuda_memcpy(int dest_dev_id, int src_dev_id, void *dest, return delayed_init; } - if (NULL == dest || NULL == src || size <= 0) { + if (NULL == dest || NULL == src || size < 0) { return OPAL_ERR_BAD_PARAM; } + if (0 == size) { + return OPAL_SUCCESS; + } /* Async copy then synchronize is the default behavior as some applications * cannot utilize synchronous copies. In addition, host memory does not need diff --git a/opal/mca/accelerator/rocm/accelerator_rocm_module.c b/opal/mca/accelerator/rocm/accelerator_rocm_module.c index d5640db2100..a769e929c15 100644 --- a/opal/mca/accelerator/rocm/accelerator_rocm_module.c +++ b/opal/mca/accelerator/rocm/accelerator_rocm_module.c @@ -254,9 +254,12 @@ static int mca_accelerator_rocm_memcpy_async(int dest_dev_id, int src_dev_id, vo opal_accelerator_transfer_type_t type) { if (NULL == stream || NULL == src || - NULL == dest || size <= 0) { + NULL == dest || size < 0) { return OPAL_ERR_BAD_PARAM; } + if (0 == size) { + return OPAL_SUCCESS; + } hipError_t err = hipMemcpyAsync(dest, src, size, hipMemcpyDefault, *((hipStream_t *)stream->stream)); @@ -275,9 +278,12 @@ static int mca_accelerator_rocm_memcpy(int dest_dev_id, int src_dev_id, void *de { hipError_t err; - if (NULL == src || NULL == dest || size <=0) { + if (NULL == src || NULL == dest || size < 0) { return OPAL_ERR_BAD_PARAM; } + if (0 == size) { + return OPAL_SUCCESS; + } if (type == MCA_ACCELERATOR_TRANSFER_DTOH && size <= opal_accelerator_rocm_memcpyD2H_limit) { memcpy(dest, src, size);