Skip to content

Commit 9149483

Browse files
authored
Merge pull request #12241 from edgargabriel/pr/accelerator-size-0-fix-v5.0.x
opal/accelerator: allow 0 size copies - v5.0.x
2 parents a2dee36 + 4e49b75 commit 9149483

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

opal/mca/accelerator/cuda/accelerator_cuda.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,12 @@ static int accelerator_cuda_memcpy_async(int dest_dev_id, int src_dev_id, void *
364364
return delayed_init;
365365
}
366366

367-
if (NULL == stream || NULL == dest || NULL == src || size <= 0) {
367+
if (NULL == stream || NULL == dest || NULL == src || size < 0) {
368368
return OPAL_ERR_BAD_PARAM;
369369
}
370+
if (0 == size) {
371+
return OPAL_SUCCESS;
372+
}
370373

371374
result = cuMemcpyAsync((CUdeviceptr) dest, (CUdeviceptr) src, size, *(CUstream *)stream->stream);
372375
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,
387390
return delayed_init;
388391
}
389392

390-
if (NULL == dest || NULL == src || size <= 0) {
393+
if (NULL == dest || NULL == src || size < 0) {
391394
return OPAL_ERR_BAD_PARAM;
392395
}
396+
if (0 == size) {
397+
return OPAL_SUCCESS;
398+
}
393399

394400
/* Async copy then synchronize is the default behavior as some applications
395401
* cannot utilize synchronous copies. In addition, host memory does not need

opal/mca/accelerator/rocm/accelerator_rocm_module.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,12 @@ static int mca_accelerator_rocm_memcpy_async(int dest_dev_id, int src_dev_id, vo
254254
opal_accelerator_transfer_type_t type)
255255
{
256256
if (NULL == stream || NULL == src ||
257-
NULL == dest || size <= 0) {
257+
NULL == dest || size < 0) {
258258
return OPAL_ERR_BAD_PARAM;
259259
}
260+
if (0 == size) {
261+
return OPAL_SUCCESS;
262+
}
260263

261264
hipError_t err = hipMemcpyAsync(dest, src, size, hipMemcpyDefault,
262265
*((hipStream_t *)stream->stream));
@@ -275,9 +278,12 @@ static int mca_accelerator_rocm_memcpy(int dest_dev_id, int src_dev_id, void *de
275278
{
276279
hipError_t err;
277280

278-
if (NULL == src || NULL == dest || size <=0) {
281+
if (NULL == src || NULL == dest || size < 0) {
279282
return OPAL_ERR_BAD_PARAM;
280283
}
284+
if (0 == size) {
285+
return OPAL_SUCCESS;
286+
}
281287

282288
if (type == MCA_ACCELERATOR_TRANSFER_DTOH && size <= opal_accelerator_rocm_memcpyD2H_limit) {
283289
memcpy(dest, src, size);

0 commit comments

Comments
 (0)