|
| 1 | +/* |
| 2 | + * Copyright (c) 2014-2017 The University of Tennessee and The University |
| 3 | + * of Tennessee Research Foundation. All rights |
| 4 | + * reserved. |
| 5 | + * Copyright (c) 2014-2015 NVIDIA Corporation. All rights reserved. |
| 6 | + * Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved. |
| 7 | + * Copyright (c) 2024 Triad National Security, LLC. All rights reserved. |
| 8 | + * Copyright (c) 2024 Advanced Micro Devices, Inc. All Rights reserved. |
| 9 | + * $COPYRIGHT$ |
| 10 | + * |
| 11 | + * Additional copyrights may follow |
| 12 | + * |
| 13 | + * $HEADER$ |
| 14 | + */ |
| 15 | + |
| 16 | +#include "ompi_config.h" |
| 17 | +#include "coll_accelerator.h" |
| 18 | + |
| 19 | +#include <stdio.h> |
| 20 | + |
| 21 | +#include "ompi/op/op.h" |
| 22 | +#include "opal/datatype/opal_convertor.h" |
| 23 | + |
| 24 | +/* |
| 25 | + * Function: - alltoall for device buffers using temp. CPU buffer |
| 26 | + * Accepts: - same as MPI_Alltoall() |
| 27 | + * Returns: - MPI_SUCCESS or error code |
| 28 | + */ |
| 29 | +int |
| 30 | +mca_coll_accelerator_alltoall(const void *sbuf, size_t scount, |
| 31 | + struct ompi_datatype_t *sdtype, |
| 32 | + void *rbuf, size_t rcount, |
| 33 | + struct ompi_datatype_t *rdtype, |
| 34 | + struct ompi_communicator_t *comm, |
| 35 | + mca_coll_base_module_t *module) |
| 36 | +{ |
| 37 | + mca_coll_accelerator_module_t *s = (mca_coll_accelerator_module_t*) module; |
| 38 | + ptrdiff_t sgap, rgap; |
| 39 | + char *rbuf1 = NULL, *sbuf1 = NULL, *rbuf2 = NULL; |
| 40 | + int sbuf_dev, rbuf_dev; |
| 41 | + size_t sbufsize, rbufsize; |
| 42 | + int rc; |
| 43 | + int comm_size = ompi_comm_size(comm); |
| 44 | + |
| 45 | + sbufsize = opal_datatype_span(&sdtype->super, scount, &sgap); |
| 46 | + rc = mca_coll_accelerator_check_buf((void *)sbuf, &sbuf_dev); |
| 47 | + if (rc < 0) { |
| 48 | + return rc; |
| 49 | + } |
| 50 | + if ((MPI_IN_PLACE != sbuf) && (rc > 0) && |
| 51 | + (sbufsize <= (size_t)mca_coll_accelerator_alltoall_thresh)) { |
| 52 | + sbuf1 = (char*)malloc(sbufsize * comm_size); |
| 53 | + if (NULL == sbuf1) { |
| 54 | + return OMPI_ERR_OUT_OF_RESOURCE; |
| 55 | + } |
| 56 | + mca_coll_accelerator_memcpy(sbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, sbuf, sbuf_dev, |
| 57 | + sbufsize * comm_size, MCA_ACCELERATOR_TRANSFER_DTOH); |
| 58 | + sbuf = sbuf1 - sgap; |
| 59 | + } |
| 60 | + |
| 61 | + rbufsize = opal_datatype_span(&rdtype->super, rcount, &rgap); |
| 62 | + rc = mca_coll_accelerator_check_buf(rbuf, &rbuf_dev); |
| 63 | + if (rc < 0) { |
| 64 | + goto exit; |
| 65 | + } |
| 66 | + /* Using sbufsize here on purpose to ensure symmetric decision for handling of GPU vs |
| 67 | + CPU buffers. The two buffer sizes are expected to be the same for pre-defined datatypes, |
| 68 | + but could vary due to layout issues/gaps for derived datatypes */ |
| 69 | + if ((rc > 0) && (sbufsize <= (size_t)mca_coll_accelerator_alltoall_thresh)) { |
| 70 | + rbuf1 = (char*)malloc(rbufsize * comm_size); |
| 71 | + if (NULL == rbuf1) { |
| 72 | + rc = OMPI_ERR_OUT_OF_RESOURCE; |
| 73 | + goto exit; |
| 74 | + } |
| 75 | + mca_coll_accelerator_memcpy(rbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, rbuf, rbuf_dev, |
| 76 | + rbufsize * comm_size, MCA_ACCELERATOR_TRANSFER_DTOH); |
| 77 | + rbuf2 = rbuf; /* save away original buffer */ |
| 78 | + rbuf = rbuf1 - rgap; |
| 79 | + } |
| 80 | + rc = s->c_coll.coll_alltoall(sbuf, scount, sdtype, rbuf, rcount, rdtype, |
| 81 | + comm, s->c_coll.coll_alltoall_module); |
| 82 | + if (rc < 0) { |
| 83 | + goto exit;; |
| 84 | + } |
| 85 | + if (NULL != rbuf1) { |
| 86 | + mca_coll_accelerator_memcpy(rbuf2, rbuf_dev, rbuf1, MCA_ACCELERATOR_NO_DEVICE_ID, |
| 87 | + rbufsize * comm_size, MCA_ACCELERATOR_TRANSFER_HTOD); |
| 88 | + } |
| 89 | + |
| 90 | + exit: |
| 91 | + if (NULL != sbuf1) { |
| 92 | + free(sbuf1); |
| 93 | + } |
| 94 | + if (NULL != rbuf1) { |
| 95 | + free(rbuf1); |
| 96 | + } |
| 97 | + |
| 98 | + return rc; |
| 99 | +} |
0 commit comments