-
Notifications
You must be signed in to change notification settings - Fork 901
coll/accelerator add support for more functions #13006
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
Merged
edgargabriel
merged 3 commits into
open-mpi:main
from
edgargabriel:topic/coll-accelerator-new-funcs
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c) 2014-2017 The University of Tennessee and The University | ||
* of Tennessee Research Foundation. All rights | ||
* reserved. | ||
* Copyright (c) 2014-2015 NVIDIA Corporation. All rights reserved. | ||
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved. | ||
* Copyright (c) 2024 Triad National Security, LLC. All rights reserved. | ||
* Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights reserved. | ||
* $COPYRIGHT$ | ||
* | ||
* Additional copyrights may follow | ||
* | ||
* $HEADER$ | ||
*/ | ||
|
||
#include "ompi_config.h" | ||
#include "coll_accelerator.h" | ||
|
||
#include <stdio.h> | ||
|
||
#include "ompi/op/op.h" | ||
#include "opal/datatype/opal_convertor.h" | ||
|
||
/* | ||
* Function: - allgather for device buffers through temp CPU buffer | ||
* Accepts: - same as MPI_Allgather() | ||
* Returns: - MPI_SUCCESS or error code | ||
*/ | ||
int | ||
mca_coll_accelerator_allgather(const void *sbuf, size_t scount, | ||
struct ompi_datatype_t *sdtype, | ||
void *rbuf, size_t rcount, | ||
struct ompi_datatype_t *rdtype, | ||
struct ompi_communicator_t *comm, | ||
mca_coll_base_module_t *module) | ||
{ | ||
mca_coll_accelerator_module_t *s = (mca_coll_accelerator_module_t*) module; | ||
ptrdiff_t sgap, rgap; | ||
char *rbuf1 = NULL, *sbuf1 = NULL, *rbuf2 = NULL; | ||
int sbuf_dev, rbuf_dev; | ||
size_t sbufsize, rbufsize; | ||
int rc; | ||
int comm_size = ompi_comm_size(comm); | ||
|
||
sbufsize = opal_datatype_span(&sdtype->super, scount, &sgap); | ||
rc = mca_coll_accelerator_check_buf((void *)sbuf, &sbuf_dev); | ||
if (rc < 0) { | ||
return rc; | ||
} | ||
if ((MPI_IN_PLACE != sbuf) && (rc > 0) && | ||
(sbufsize <= (size_t)mca_coll_accelerator_allgather_thresh)) { | ||
sbuf1 = (char*)malloc(sbufsize); | ||
if (NULL == sbuf1) { | ||
return OMPI_ERR_OUT_OF_RESOURCE; | ||
} | ||
mca_coll_accelerator_memcpy(sbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, sbuf, sbuf_dev, | ||
sbufsize, MCA_ACCELERATOR_TRANSFER_DTOH); | ||
sbuf = sbuf1 - sgap; | ||
} | ||
|
||
rbufsize = opal_datatype_span(&rdtype->super, rcount, &rgap); | ||
rc = mca_coll_accelerator_check_buf(rbuf, &rbuf_dev); | ||
if (rc < 0) { | ||
goto exit; | ||
} | ||
/* Using sbufsize here on purpose to ensure symmetric decision for handling of GPU vs | ||
CPU buffers. The two buffer sizes are expected to be the same for pre-defined datatypes, | ||
but could vary due to layout issues/gaps for derived datatypes */ | ||
if ((rc > 0) && (sbufsize <= (size_t)mca_coll_accelerator_allgather_thresh)) { | ||
rbuf1 = (char*)malloc(rbufsize * comm_size); | ||
if (NULL == rbuf1) { | ||
rc = OMPI_ERR_OUT_OF_RESOURCE; | ||
goto exit; | ||
} | ||
mca_coll_accelerator_memcpy(rbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, rbuf, rbuf_dev, | ||
bosilca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rbufsize * comm_size, MCA_ACCELERATOR_TRANSFER_DTOH); | ||
rbuf2 = rbuf; /* save original buffer */ | ||
rbuf = rbuf1 - rgap; | ||
} | ||
rc = s->c_coll.coll_allgather(sbuf, scount, sdtype, rbuf, rcount, rdtype, | ||
comm, s->c_coll.coll_allgather_module); | ||
if (rc < 0) { | ||
goto exit; | ||
} | ||
|
||
if (NULL != rbuf1) { | ||
mca_coll_accelerator_memcpy(rbuf2, rbuf_dev, rbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, rbufsize * comm_size, | ||
MCA_ACCELERATOR_TRANSFER_HTOD); | ||
} | ||
|
||
exit: | ||
if (NULL != sbuf1) { | ||
free(sbuf1); | ||
} | ||
if (NULL != rbuf1) { | ||
free(rbuf1); | ||
} | ||
|
||
return rc; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2014-2017 The University of Tennessee and The University | ||
* of Tennessee Research Foundation. All rights | ||
* reserved. | ||
* Copyright (c) 2014-2015 NVIDIA Corporation. All rights reserved. | ||
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved. | ||
* Copyright (c) 2024 Triad National Security, LLC. All rights reserved. | ||
* Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights reserved. | ||
* $COPYRIGHT$ | ||
* | ||
* Additional copyrights may follow | ||
* | ||
* $HEADER$ | ||
*/ | ||
|
||
#include "ompi_config.h" | ||
#include "coll_accelerator.h" | ||
|
||
#include <stdio.h> | ||
|
||
#include "ompi/op/op.h" | ||
#include "opal/datatype/opal_convertor.h" | ||
|
||
/* | ||
* Function: - alltoall for device buffers using temp. CPU buffer | ||
* Accepts: - same as MPI_Alltoall() | ||
* Returns: - MPI_SUCCESS or error code | ||
*/ | ||
int | ||
mca_coll_accelerator_alltoall(const void *sbuf, size_t scount, | ||
struct ompi_datatype_t *sdtype, | ||
void *rbuf, size_t rcount, | ||
struct ompi_datatype_t *rdtype, | ||
struct ompi_communicator_t *comm, | ||
mca_coll_base_module_t *module) | ||
{ | ||
mca_coll_accelerator_module_t *s = (mca_coll_accelerator_module_t*) module; | ||
ptrdiff_t sgap, rgap; | ||
char *rbuf1 = NULL, *sbuf1 = NULL, *rbuf2 = NULL; | ||
int sbuf_dev, rbuf_dev; | ||
size_t sbufsize, rbufsize; | ||
int rc; | ||
int comm_size = ompi_comm_size(comm); | ||
|
||
sbufsize = opal_datatype_span(&sdtype->super, scount, &sgap); | ||
rc = mca_coll_accelerator_check_buf((void *)sbuf, &sbuf_dev); | ||
if (rc < 0) { | ||
return rc; | ||
} | ||
if ((MPI_IN_PLACE != sbuf) && (rc > 0) && | ||
(sbufsize <= (size_t)mca_coll_accelerator_alltoall_thresh)) { | ||
sbuf1 = (char*)malloc(sbufsize * comm_size); | ||
if (NULL == sbuf1) { | ||
return OMPI_ERR_OUT_OF_RESOURCE; | ||
} | ||
mca_coll_accelerator_memcpy(sbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, sbuf, sbuf_dev, | ||
bosilca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sbufsize * comm_size, MCA_ACCELERATOR_TRANSFER_DTOH); | ||
sbuf = sbuf1 - sgap; | ||
} | ||
|
||
rbufsize = opal_datatype_span(&rdtype->super, rcount, &rgap); | ||
rc = mca_coll_accelerator_check_buf(rbuf, &rbuf_dev); | ||
if (rc < 0) { | ||
goto exit; | ||
} | ||
/* Using sbufsize here on purpose to ensure symmetric decision for handling of GPU vs | ||
CPU buffers. The two buffer sizes are expected to be the same for pre-defined datatypes, | ||
but could vary due to layout issues/gaps for derived datatypes */ | ||
bosilca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ((rc > 0) && (sbufsize <= (size_t)mca_coll_accelerator_alltoall_thresh)) { | ||
rbuf1 = (char*)malloc(rbufsize * comm_size); | ||
devreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (NULL == rbuf1) { | ||
rc = OMPI_ERR_OUT_OF_RESOURCE; | ||
goto exit; | ||
} | ||
mca_coll_accelerator_memcpy(rbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, rbuf, rbuf_dev, | ||
devreal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
rbufsize * comm_size, MCA_ACCELERATOR_TRANSFER_DTOH); | ||
rbuf2 = rbuf; /* save away original buffer */ | ||
rbuf = rbuf1 - rgap; | ||
} | ||
rc = s->c_coll.coll_alltoall(sbuf, scount, sdtype, rbuf, rcount, rdtype, | ||
comm, s->c_coll.coll_alltoall_module); | ||
if (rc < 0) { | ||
goto exit;; | ||
edgargabriel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
if (NULL != rbuf1) { | ||
mca_coll_accelerator_memcpy(rbuf2, rbuf_dev, rbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, | ||
rbufsize * comm_size, MCA_ACCELERATOR_TRANSFER_HTOD); | ||
} | ||
|
||
exit: | ||
if (NULL != sbuf1) { | ||
free(sbuf1); | ||
} | ||
if (NULL != rbuf1) { | ||
free(rbuf1); | ||
} | ||
|
||
return rc; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved. | ||
* Copyright (c) 2004-2023 The University of Tennessee and The University | ||
* of Tennessee Research Foundation. All rights | ||
* reserved. | ||
* Copyright (c) 2014-2015 NVIDIA Corporation. All rights reserved. | ||
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved. | ||
* Copyright (c) 2024 Triad National Security, LLC. All rights reserved. | ||
* Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights reserved. | ||
* $COPYRIGHT$ | ||
* | ||
* Additional copyrights may follow | ||
* | ||
* $HEADER$ | ||
*/ | ||
|
||
#include "ompi_config.h" | ||
#include "coll_accelerator.h" | ||
|
||
#include <stdio.h> | ||
|
||
#include "ompi/op/op.h" | ||
#include "opal/datatype/opal_convertor.h" | ||
|
||
/* | ||
* | ||
* Function: - Bcast for device buffers through temp CPU buffer. | ||
* Accepts: - same as MPI_Bcast() | ||
* Returns: - MPI_SUCCESS or error code | ||
*/ | ||
int | ||
mca_coll_accelerator_bcast(void *orig_buf, size_t count, | ||
struct ompi_datatype_t *datatype, | ||
int root, | ||
struct ompi_communicator_t *comm, | ||
mca_coll_base_module_t *module) | ||
{ | ||
mca_coll_accelerator_module_t *s = (mca_coll_accelerator_module_t*) module; | ||
ptrdiff_t gap; | ||
char *buf1 = NULL; | ||
char *sbuf = (char*) orig_buf; | ||
int buf_dev; | ||
size_t bufsize; | ||
int rc; | ||
|
||
bufsize = opal_datatype_span(&datatype->super, count, &gap); | ||
|
||
rc = mca_coll_accelerator_check_buf((void *)orig_buf, &buf_dev); | ||
if (rc < 0) { | ||
return rc; | ||
} | ||
if ((rc > 0) && (bufsize <= (size_t)mca_coll_accelerator_bcast_thresh)) { | ||
buf1 = (char*)malloc(bufsize); | ||
if (NULL == buf1) { | ||
return OMPI_ERR_OUT_OF_RESOURCE; | ||
} | ||
mca_coll_accelerator_memcpy(buf1, MCA_ACCELERATOR_NO_DEVICE_ID, orig_buf, buf_dev, bufsize, | ||
MCA_ACCELERATOR_TRANSFER_DTOH); | ||
sbuf = buf1 - gap; | ||
} | ||
|
||
rc = s->c_coll.coll_bcast((void *) sbuf, count, datatype, root, comm, | ||
s->c_coll.coll_bcast_module); | ||
if (rc < 0) { | ||
goto exit; | ||
} | ||
if (NULL != buf1) { | ||
mca_coll_accelerator_memcpy((void*)orig_buf, buf_dev, buf1, MCA_ACCELERATOR_NO_DEVICE_ID, bufsize, | ||
MCA_ACCELERATOR_TRANSFER_HTOD); | ||
} | ||
|
||
exit: | ||
if (NULL != buf1) { | ||
free(buf1); | ||
} | ||
|
||
return rc; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.