Skip to content

Commit

Permalink
Merge pull request #12229 from edgargabriel/topic/accelerator-size-0-fix
Browse files Browse the repository at this point in the history
opal/accelerator: allow 0 size copies
  • Loading branch information
edgargabriel authored Jan 16, 2024
2 parents 5fa32f7 + 9965f6c commit 6256b00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
10 changes: 8 additions & 2 deletions opal/mca/accelerator/cuda/accelerator_cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,12 @@ static int accelerator_cuda_memcpy_async(int dest_dev_id, int src_dev_id, void *
}

if ((MCA_ACCELERATOR_STREAM_DEFAULT != stream && NULL == stream) ||
NULL == dest || NULL == src || size <= 0) {
NULL == dest || NULL == src || size < 0) {
return OPAL_ERR_BAD_PARAM;
}
if (0 == size) {
return OPAL_SUCCESS;
}

result = cuMemcpyAsync((CUdeviceptr) dest, (CUdeviceptr) src, size, GET_STREAM(stream));
if (OPAL_UNLIKELY(CUDA_SUCCESS != result)) {
Expand All @@ -422,9 +425,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
Expand Down
10 changes: 8 additions & 2 deletions opal/mca/accelerator/rocm/accelerator_rocm_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,12 @@ static int mca_accelerator_rocm_memcpy_async(int dest_dev_id, int src_dev_id, vo
{
if ((MCA_ACCELERATOR_STREAM_DEFAULT != stream &&
(NULL == stream || NULL == stream->stream)) ||
NULL == src || NULL == dest || size <= 0) {
NULL == src || NULL == dest || size < 0) {
return OPAL_ERR_BAD_PARAM;
}
if (0 == size) {
return OPAL_SUCCESS;
}

hipError_t err = hipMemcpyAsync(dest, src, size, hipMemcpyDefault,
GET_STREAM(stream));
Expand All @@ -324,9 +327,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);
Expand Down
12 changes: 9 additions & 3 deletions opal/mca/accelerator/ze/accelerator_ze_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ static int mca_accelerator_ze_memcpy_async(int dest_dev_id, int src_dev_id, void
opal_accelerator_ze_stream_t *ze_stream = NULL;

if (NULL == stream || NULL == src ||
NULL == dest || size <= 0) {
NULL == dest || size < 0) {
return OPAL_ERR_BAD_PARAM;
}
if (0 == size) {
return OPAL_SUCCESS;
}

ze_stream = (opal_accelerator_ze_stream_t *)stream->stream;
ze_stream = (opal_accelerator_ze_stream_t *)stream->stream;
assert(NULL != ze_stream);

zret = zeCommandListAppendMemoryCopy(ze_stream->hCommandList,
Expand Down Expand Up @@ -435,9 +438,12 @@ static int mca_accelerator_ze_memcpy(int dest_dev_id, int src_dev_id, void *dest

opal_accelerator_ze_stream_t *ze_stream = NULL;

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 (MCA_ACCELERATOR_NO_DEVICE_ID == src_dev_id) {
dev_id = 0;
Expand Down

0 comments on commit 6256b00

Please sign in to comment.