Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opal/accelerator: allow 0 size copies #12229

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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