rocm.bindings.cyrccl

rocm.bindings.cyrccl#

2026-09-24

30 min read time

Applies to Linux and Windows

Advanced Micro Devices, Inc.

Cython declarations for the C-level interface. Use cimport rocm.bindings.cyrccl from your Cython code to access these declarations directly.

See also

The high-level Python API is documented at rocm.bindings.rccl.

# MIT License
#
# Copyright (c) 2021-2026 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


# This file has been autogenerated, do not modify.

from libc.stdint cimport *
ctypedef bint _Bool # bool is not a reserved keyword in C, _Bool is
from rocm.bindings.cyhip cimport hipStream_t
cdef extern from "rccl/rccl.h":

    cdef int NCCL_MAJOR

    cdef int NCCL_MINOR

    cdef int NCCL_PATCH

    cdef char * NCCL_SUFFIX

    cdef int NCCL_VERSION_CODE

    cdef int RCCL_BFLOAT16

    cdef int RCCL_GATHER_SCATTER

    cdef int RCCL_ALLTOALLV

    cdef int NCCL_UNIQUE_ID_BYTES

    cdef struct ncclComm:
        pass

    ctypedef ncclComm * ncclComm_t

    cdef struct ncclWindow_vidmem:
        pass

    ctypedef ncclWindow_vidmem * ncclWindow_t

    ctypedef struct ncclUniqueId:
        char internal[128]

    ctypedef enum ncclResult_t:
        ncclSuccess
        ncclUnhandledCudaError
        ncclSystemError
        ncclInternalError
        ncclInvalidArgument
        ncclInvalidUsage
        ncclRemoteError
        ncclInProgress
        ncclTimeout
        ncclNumResults

    cdef struct ncclConfig_v22800:
        size_t size
        unsigned int magic
        unsigned int version
        int blocking
        int cgaClusterSize
        int minCTAs
        int maxCTAs
        const char * netName
        int splitShare
        int trafficClass
        const char * commName
        int collnetEnable
        int CTAPolicy
        int shrinkShare
        int nvlsCTAs
        int nChannelsPerNetPeer
        int nvlinkCentricSched
        int graphUsageMode
        int numRmaCtx
        int maxP2pPeers

    ctypedef ncclConfig_v22800 ncclConfig_t

    cdef struct ncclSimInfo_v22200:
        size_t size
        unsigned int magic
        unsigned int version
        float estimatedTime

    ctypedef ncclSimInfo_v22200 ncclSimInfo_t


cdef ncclResult_t ncclMemAlloc(void ** ptr,size_t size) except? ncclInternalError nogil



cdef ncclResult_t ncclMemFree(void * ptr) except? ncclInternalError nogil


# @brief      Return the RCCL_VERSION_CODE of RCCL in the supplied integer.
# @details    This integer is coded with the MAJOR, MINOR and PATCH level of RCCL.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[out] version       Pointer to where version will be stored
cdef ncclResult_t ncclGetVersion(int * version) except? ncclInternalError nogil


# @brief      Generates an ID for ncclCommInitRank.
# @details    Generates an ID to be used in ncclCommInitRank.
#             ncclGetUniqueId should be called once by a single rank and the
#             ID should be distributed to all ranks in the communicator before
#             using it as a parameter for ncclCommInitRank.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[out] uniqueId      Pointer to where uniqueId will be stored
cdef ncclResult_t ncclGetUniqueId(ncclUniqueId * uniqueId) except? ncclInternalError nogil


# @brief      Create a new communicator with config.
# @details    Create a new communicator (multi thread/process version) with a configuration
#             set by users. See @ref rccl_config_type for more details.
#             Each rank is associated to a CUDA device, which has to be set before calling
#             ncclCommInitRank.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[out] comm          Pointer to created communicator
# @param[in]  nranks        Total number of ranks participating in this communicator
# @param[in]  commId        UniqueId required for initialization
# @param[in]  rank          Current rank to create communicator for. [0 to nranks-1]
# @param[in]  config        Pointer to communicator configuration
cdef ncclResult_t ncclCommInitRankConfig(ncclComm_t * comm,int nranks,ncclUniqueId commId,int rank,ncclConfig_v22800 * config) except? ncclInternalError nogil


# @brief      Creates a new communicator (multi thread/process version).
# @details    Rank must be between 0 and nranks-1 and unique within a communicator clique.
#             Each rank is associated to a CUDA device, which has to be set before calling
#             ncclCommInitRank.  ncclCommInitRank implicitly syncronizes with other ranks,
#             so it must be called by different threads/processes or use ncclGroupStart/ncclGroupEnd.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[out] comm          Pointer to created communicator
# @param[in]  nranks        Total number of ranks participating in this communicator
# @param[in]  commId        UniqueId required for initialization
# @param[in]  rank          Current rank to create communicator for
cdef ncclResult_t ncclCommInitRank(ncclComm_t * comm,int nranks,ncclUniqueId commId,int rank) except? ncclInternalError nogil


# @brief      Creates a clique of communicators (single process version).
# @details    This is a convenience function to create a single-process communicator clique.
#             Returns an array of ndev newly initialized communicators in comm.
#             comm should be pre-allocated with size at least ndev*sizeof(ncclComm_t).
#             If devlist is NULL, the first ndev HIP devices are used.
#             Order of devlist defines user-order of processors within the communicator.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[out] comm          Pointer to array of created communicators
# @param[in]  ndev          Total number of ranks participating in this communicator
# @param[in]  devlist       Array of GPU device indices to create for
cdef ncclResult_t ncclCommInitAll(ncclComm_t * comm,int ndev,const int * devlist) except? ncclInternalError nogil


# @brief      Finalize a communicator.
# @details    ncclCommFinalize flushes all issued communications
#             and marks communicator state as ncclInProgress. The state will change to ncclSuccess
#             when the communicator is globally quiescent and related resources are freed; then,
#             calling ncclCommDestroy can locally free the rest of the resources (e.g. communicator
#             itself) without blocking.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to finalize
cdef ncclResult_t ncclCommFinalize(ncclComm_t comm) except? ncclInternalError nogil


# @brief      Frees local resources associated with communicator object.
# @details    Destroy all local resources associated with the passed in communicator object
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to destroy
cdef ncclResult_t ncclCommDestroy(ncclComm_t comm) except? ncclInternalError nogil


# @brief      Abort any in-progress calls and destroy the communicator object.
# @details    Frees resources associated with communicator object and aborts any operations
#             that might still be running on the device.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to abort and destroy
cdef ncclResult_t ncclCommAbort(ncclComm_t comm) except? ncclInternalError nogil


# @brief      Revoke a communicator without destroying it.
# @details    Aborts in-flight collectives by raising the comm's abort flag,
#             stops the proxy service, and rejects subsequently enqueued
#             collectives with ncclInvalidUsage. The abort flag is cleared
#             once the asynchronous revoke job completes, so the communicator
#             remains valid as a parent for ncclCommSplit / ncclCommShrink /
#             ncclCommGrow, and may be torn down via ncclCommDestroy /
#             ncclCommAbort.
#             Because in-flight collectives are aborted (not drained), revoke
#             can recover from peers that have failed mid-collective; output
#             buffers of an aborted collective contain undefined data.
#             ncclCommFinalize on a revoked communicator is invalid and returns
#             ncclInvalidUsage.
#             Pass NCCL_REVOKE_DEFAULT for revokeFlags; other values are rejected
#             with ncclInvalidArgument.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to revoke
# @param[in]  revokeFlags   Reserved; must be NCCL_REVOKE_DEFAULT
cdef ncclResult_t ncclCommRevoke(ncclComm_t comm,int revokeFlags) except? ncclInternalError nogil


# @brief      Create one or more communicators from an existing one.
# @details    Creates one or more communicators from an existing one.
#             Ranks with the same color will end up in the same communicator.
#             Within the new communicator, key will be used to order ranks.
#             NCCL_SPLIT_NOCOLOR as color will indicate the rank will not be part of any group
#             and will therefore return a NULL communicator.
#             If config is NULL, the new communicator will inherit the original communicator's configuration
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Original communicator object for this rank
# @param[in]  color         Color to assign this rank
# @param[in]  key           Key used to order ranks within the same new communicator
# @param[out] newcomm       Pointer to new communicator
# @param[in]  config        Config file for new communicator. May be NULL to inherit from comm
cdef ncclResult_t ncclCommSplit(ncclComm_t comm,int color,int key,ncclComm_t * newcomm,ncclConfig_v22800 * config) except? ncclInternalError nogil


# @brief      Shrink existing communicator.
# @details    Ranks in excludeRanksList will be removed form the existing communicator.
#             Within the new communicator, ranks will be re-ordered to fill the gap of removed ones.
#             If config is NULL, the new communicator will inherit the original communicator's configuration.
#             The flag enables NCCL to adapt to various states of the parent communicator, see NCCL_SHRINK flags.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm                  Original communicator object for this rank
# @param[in]  excludeRanksList      List of ranks to be exluded
# @param[in]  excludeRanksCount     Number of ranks to be excluded
# @param[out] newcomm               Pointer to new communicator
# @param[in]  config                Config file for new communicator. May be NULL to inherit from comm
# @param[in]  shrinkFlags           Flag to adapt to various states of the parent communicator (see NCCL_SHRINK flags)
cdef ncclResult_t ncclCommShrink(ncclComm_t comm,int * excludeRanksList,int excludeRanksCount,ncclComm_t * newcomm,ncclConfig_v22800 * config,int shrinkFlags) except? ncclInternalError nogil


# @brief      Generate a per-communicator unique ID for growing a communicator.
# @details    Generates a unique ID on an existing communicator. The ID must be
#             distributed to the ranks joining through ncclCommGrow.
#             Constraints:
#             - A new ID cannot be generated while a previous ID is unconsumed.
#             - Each ID can only be used once (no reuse after consumption).
#             - The grow operation must complete before calling this again.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Existing communicator that coordinates the grow
# @param[out] uniqueId      Pointer to the generated unique ID
cdef ncclResult_t ncclCommGetUniqueId(ncclComm_t comm,ncclUniqueId * uniqueId) except? ncclInternalError nogil


# @brief      Grow a communicator by adding new ranks.
# @details    Creates a larger communicator from an existing one plus newly
#             joining ranks. The unique ID obtained from ncclCommGetUniqueId
#             must be distributed to the new ranks. Parameter usage:
#             - Existing non-root ranks: comm set, uniqueId = NULL, rank = -1
#             - Existing root rank: comm set, uniqueId = &id, rank = -1
#             - New ranks: comm = NULL, uniqueId = &id, rank = assigned
#             The unique ID is consumed upon a successful grow and cannot be reused.
#             If config is NULL, the new communicator inherits the original
#             communicator's configuration.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Existing communicator, or NULL for newly joining ranks
# @param[in]  nRanks        Total number of ranks in the new communicator
# @param[in]  uniqueId      Unique ID from ncclCommGetUniqueId; NULL on existing non-root ranks
# @param[in]  rank          Rank in the new communicator for joining ranks; -1 for existing ranks
# @param[out] newcomm       Pointer to the new communicator
# @param[in]  config        Config for the new communicator. May be NULL to inherit from comm
cdef ncclResult_t ncclCommGrow(ncclComm_t comm,int nRanks,const ncclUniqueId * uniqueId,int rank,ncclComm_t * newcomm,ncclConfig_v22800 * config) except? ncclInternalError nogil


# @brief      Creates a new communicator (multi thread/process version), similar to ncclCommInitRankConfig.
#  @details    Allows to use more than one ncclUniqueId (up to one per rank),
#              indicated by nId, to accelerate the init operation.
#              The number of ncclUniqueIds and their order must be the same for every rank.
#  @return     Result code. See @ref rccl_result_code for more details.
# 
#  @param[out] newcomm       Pointer to new communicator
#  @param[in]  nranks        Total number of ranks participating in this communicator
#  @param[in]  myrank        Current rank
#  @param[in]  nId           Number of unique IDs
#  @param[in]  commIds       List of unique IDs
#  @param[in]  config        Config file for new communicator. May be NULL to inherit from comm
cdef ncclResult_t ncclCommInitRankScalable(ncclComm_t * newcomm,int nranks,int myrank,int nId,ncclUniqueId * commIds,ncclConfig_v22800 * config) except? ncclInternalError nogil


# @brief      Returns a string for each result code.
# @details    Returns a human-readable string describing the given result code.
# @return     String containing description of result code.
# 
# @param[in]  result        Result code to get description for
cdef const char * ncclGetErrorString(ncclResult_t result) noexcept nogil


# Returns a human-readable message of the last error that occurred.
cdef const char * ncclGetLastError(ncclComm_t comm) noexcept nogil


# Reload environment variables that determine logging.
cdef void ncclResetDebugInit() noexcept nogil


# @brief      Checks whether the comm has encountered any asynchronous errors
# @details    Query whether the provided communicator has encountered any asynchronous errors
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to query
# @param[out] asyncError    Pointer to where result code will be stored
cdef ncclResult_t ncclCommGetAsyncError(ncclComm_t comm,ncclResult_t * asyncError) except? ncclInternalError nogil


# @brief      Gets the number of ranks in the communicator clique.
# @details    Returns the number of ranks in the communicator clique (as set during initialization)
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to query
# @param[out] count         Pointer to where number of ranks will be stored
cdef ncclResult_t ncclCommCount(const ncclComm_t comm,int * count) except? ncclInternalError nogil


# @brief      Get the ROCm device index associated with a communicator
# @details    Returns the ROCm device number associated with the provided communicator.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to query
# @param[out] device        Pointer to where the associated ROCm device index will be stored
cdef ncclResult_t ncclCommCuDevice(const ncclComm_t comm,int * device) except? ncclInternalError nogil


# @brief      Get the rank associated with a communicator
# @details    Returns the user-ordered "rank" associated with the provided communicator.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to query
# @param[out] rank          Pointer to where the associated rank will be stored
cdef ncclResult_t ncclCommUserRank(const ncclComm_t comm,int * rank) except? ncclInternalError nogil


# Register CUDA buffer for zero-copy operation
cdef ncclResult_t ncclCommRegister(const ncclComm_t comm,void * buff,size_t size,void ** handle) except? ncclInternalError nogil


# Deregister CUDA buffer
cdef ncclResult_t ncclCommDeregister(const ncclComm_t comm,void * handle) except? ncclInternalError nogil


# @brief      Suspend communicator operations to free resources.
# @details    Releases the resources selected by @p flags. The communicator
#             cannot be used until @ref ncclCommResume is called.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to suspend
# @param[in]  flags         Bitmask of NCCL_SUSPEND_* flags (e.g. @ref NCCL_SUSPEND_MEM)
cdef ncclResult_t ncclCommSuspend(ncclComm_t comm,int flags) except? ncclInternalError nogil


# @brief      Resume a previously suspended communicator.
# @details    Reacquires every resource that was released by the matching
#             @ref ncclCommSuspend call.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to resume
cdef ncclResult_t ncclCommResume(ncclComm_t comm) except? ncclInternalError nogil


cdef extern from "rccl/rccl.h":

    ctypedef enum ncclCommMemStat_t:
        ncclStatGpuMemSuspend
        ncclStatGpuMemSuspended
        ncclStatGpuMemPersist
        ncclStatGpuMemTotal

# @brief      Query communicator memory statistics.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  comm          Communicator to query
# @param[in]  stat          One of @ref ncclCommMemStat_t values
# @param[out] value         Pointer to receive the memory statistic value
cdef ncclResult_t ncclCommMemStats(ncclComm_t comm,ncclCommMemStat_t stat,uint64_t * value) except? ncclInternalError nogil


# Register memory window
cdef ncclResult_t ncclCommWindowRegister(ncclComm_t comm,void * buff,size_t size,ncclWindow_t * win,int winFlags) except? ncclInternalError nogil


# Deregister symmetric memory
cdef ncclResult_t ncclCommWindowDeregister(ncclComm_t comm,ncclWindow_t win) except? ncclInternalError nogil


# Get the user pointer from the window
cdef ncclResult_t ncclWinGetUserPtr(ncclComm_t comm,ncclWindow_t win,void ** outUserPtr) except? ncclInternalError nogil


cdef extern from "rccl/rccl.h":

    ctypedef enum ncclRedOp_dummy_t:
        ncclNumOps_dummy

    ctypedef enum ncclRedOp_t:
        ncclSum
        ncclProd
        ncclMax
        ncclMin
        ncclAvg
        ncclNumOps
        ncclMaxRedOp

    ctypedef enum ncclDataType_t:
        ncclInt8
        ncclChar
        ncclUint8
        ncclInt32
        ncclInt
        ncclUint32
        ncclInt64
        ncclUint64
        ncclFloat16
        ncclHalf
        ncclFloat32
        ncclFloat
        ncclFloat64
        ncclDouble
        ncclBfloat16
        ncclFloat8e4m3
        ncclFloat8e5m2
        ncclNumTypes

    ctypedef enum ncclScalarResidence_t:
        ncclScalarDevice
        ncclScalarHostImmediate

# @brief      Create a custom pre-multiplier reduction operator
# @details    Creates a new reduction operator which pre-multiplies input values by a given
#             scalar locally before reducing them with peer values via summation. For use
#             only with collectives launched against *comm* and *datatype*. The
#              residence* argument indicates how/when the memory pointed to by *scalar*
#             will be dereferenced. Upon return, the newly created operator's handle
#             is stored in *op*.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[out] op            Pointer to where newly created custom reduction operator is to be stored
# @param[in]  scalar        Pointer to scalar value.
# @param[in]  datatype      Scalar value datatype
# @param[in]  residence     Memory type of the scalar value
# @param[in]  comm          Communicator to associate with this custom reduction operator
cdef ncclResult_t ncclRedOpCreatePreMulSum(ncclRedOp_t * op,void * scalar,ncclDataType_t datatype,ncclScalarResidence_t residence,ncclComm_t comm) except? ncclInternalError nogil


# @brief      Destroy custom reduction operator
# @details    Destroys the reduction operator *op*. The operator must have been created by
#             ncclRedOpCreatePreMul with the matching communicator *comm*. An operator may be
#             destroyed as soon as the last RCCL function which is given that operator returns.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  op            Custom reduction operator is to be destroyed
# @param[in]  comm          Communicator associated with this reduction operator
cdef ncclResult_t ncclRedOpDestroy(ncclRedOp_t op,ncclComm_t comm) except? ncclInternalError nogil


# @brief      Reduce
# @details    Reduces data arrays of length *count* in *sendbuff* into *recvbuff* using *op*
#             operation.
#              recvbuff* may be NULL on all calls except for root device.
#              root* is the rank (not the HIP device) where data will reside after the
#              operation is complete.
#             In-place operation will happen if sendbuff == recvbuff.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Local device data buffer to be reduced
# @param[in,out] recvbuff      Data buffer where result is stored (only for *root* rank).  May be null for other ranks.
# @param[in]  count         Number of elements in every send buffer
# @param[in]  datatype      Data buffer element datatype
# @param[in]  op            Reduction operator type
# @param[in]  root          Rank where result data array will be stored
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclReduce(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,ncclRedOp_t op,int root,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      (Deprecated) Broadcast (in-place)
# @details    Copies *count* values from *root* to all other devices.
#             root is the rank (not the CUDA device) where data resides before the
#             operation is started.
#             This operation is implicitly in-place.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in,out]  buff      Input array on *root* to be copied to other ranks.  Output array for all ranks.
# @param[in]  count         Number of elements in data buffer
# @param[in]  datatype      Data buffer element datatype
# @param[in]  root          Rank owning buffer to be copied to others
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclBcast(void * buff,size_t count,ncclDataType_t datatype,int root,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      Broadcast
# @details    Copies *count* values from *sendbuff* on *root* to *recvbuff* on all devices.
#              root* is the rank (not the HIP device) where data resides before the operation is started.
#              sendbuff* may be NULL on ranks other than *root*.
#             In-place operation will happen if *sendbuff* == *recvbuff*.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to copy (if *root*).  May be NULL for other ranks
# @param[in,out] recvbuff   Data array to store received array
# @param[in]  count         Number of elements in data buffer
# @param[in]  datatype      Data buffer element datatype
# @param[in]  root          Rank of broadcast root
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclBroadcast(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,int root,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      All-Reduce
# @details    Reduces data arrays of length *count* in *sendbuff* using *op* operation, and
#             leaves identical copies of result on each *recvbuff*.
#             In-place operation will happen if sendbuff == recvbuff.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Input data array to reduce
# @param[in,out] recvbuff      Data array to store reduced result array
# @param[in]  count         Number of elements in data buffer
# @param[in]  datatype      Data buffer element datatype
# @param[in]  op            Reduction operator
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclAllReduce(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,ncclRedOp_t op,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      All-Reduce-with-Bias
# @details    Reduces data arrays of length *count* in *sendbuff* using *op* operation, and
#             leaves identical copies of result on each *recvbuff*.
#             In-place operation will happen if sendbuff == recvbuff.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Input data array to reduce
# @param[in,out] recvbuff      Data array to store reduced result array
# @param[in]  count         Number of elements in data buffer
# @param[in]  datatype      Data buffer element datatype
# @param[in]  op            Reduction operator
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
# @param[in]  acc           Bias data array to reduce
cdef ncclResult_t ncclAllReduceWithBias(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,ncclRedOp_t op,ncclComm_t comm,hipStream_t stream,const void * acc) except? ncclInternalError nogil


# @brief      Reduce-Scatter
# @details    Reduces data in *sendbuff* using *op* operation and leaves reduced result
#             scattered over the devices so that *recvbuff* on rank i will contain the i-th
#             block of the result.
#             Assumes sendcount is equal to nranks*recvcount, which means that *sendbuff*
#             should have a size of at least nranks*recvcount elements.
#             In-place operations will happen if recvbuff == sendbuff + rank * recvcount.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Input data array to reduce
# @param[in,out] recvbuff      Data array to store reduced result subarray
# @param[in]  recvcount     Number of elements each rank receives
# @param[in]  datatype      Data buffer element datatype
# @param[in]  op            Reduction operator
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclReduceScatter(const void * sendbuff,void * recvbuff,size_t recvcount,ncclDataType_t datatype,ncclRedOp_t op,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      All-Gather
# @details    Each device gathers *sendcount* values from other GPUs into *recvbuff*,
#             receiving data from rank i at offset i*sendcount.
#             Assumes recvcount is equal to nranks*sendcount, which means that recvbuff
#             should have a size of at least nranks*sendcount elements.
#             In-place operations will happen if sendbuff == recvbuff + rank * sendcount.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Input data array to send
# @param[in,out] recvbuff      Data array to store the gathered result
# @param[in]  sendcount     Number of elements each rank sends
# @param[in]  datatype      Data buffer element datatype
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclAllGather(const void * sendbuff,void * recvbuff,size_t sendcount,ncclDataType_t datatype,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      All-to-All
# @details    Each device sends count values to all other devices and receives count values
#             from all other devices. Data to send to destination rank j is taken from
#             sendbuff+j*count and data received from source rank i is placed at
#             recvbuff+i*count.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to send (contains blocks for each other rank)
# @param[in,out] recvbuff      Data array to receive (contains blocks from each other rank)
# @param[in]  count         Number of elements to send between each pair of ranks
# @param[in]  datatype      Data buffer element datatype
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclAlltoAll(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      All-To-Allv
# @details    Device (i) sends sendcounts[j] of data from offset sdispls[j]
#             to device (j). At the same time, device (i) receives recvcounts[j] of data
#             from device (j) to be placed at rdispls[j].
#             sendcounts, sdispls, recvcounts and rdispls are all measured in the units
#             of datatype, not bytes.
#             In-place operation will happen if sendbuff == recvbuff.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to send (contains blocks for each other rank)
# @param[in]  sendcounts    Array containing number of elements to send to each participating rank
# @param[in]  sdispls       Array of offsets into *sendbuff* for each participating rank
# @param[in,out] recvbuff      Data array to receive (contains blocks from each other rank)
# @param[in]  recvcounts    Array containing number of elements to receive from each participating rank
# @param[in]  rdispls       Array of offsets into *recvbuff* for each participating rank
# @param[in]  datatype      Data buffer element datatype
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclAlltoAllv(const void * sendbuff,const size_t * sendcounts,const size_t * sdispls,void * recvbuff,const size_t * recvcounts,const size_t * rdispls,ncclDataType_t datatype,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      Gather
# @details    Each rank sends count elements from sendbuff to the root rank.
#             On the root rank, data from rank i is placed at recvbuff + i*count.
#             On non-root ranks, recvbuff is not used.
#             root is the rank where data will be gathered.
# 
#             In-place operations will happen if sendbuff == recvbuff + root * count.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to send
# @param[in,out] recvbuff   Data array to recv
# @param[in]  count         Number of elements
# @param[in]  datatype      Data buffer element datatype
# @param[in]  root          Rank of gather root
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclGather(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,int root,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      Scatter
# @details    On the root rank, count elements from sendbuff+i*count are sent to rank i.
#             On non-root ranks, sendbuff is not used.
#             Each rank receives count elements into recvbuff.
#             root is the rank that will distribute the data.
# 
#             In-place operations will happen if recvbuff == sendbuff + root * count.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to send
# @param[in,out] recvbuff   Data array to recv
# @param[in]  count         Number of elements
# @param[in]  datatype      Data buffer element datatype
# @param[in]  root          Rank of scatter root
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclScatter(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,int root,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      All-To-All
# @details    Device (i) send (j)th block of data to device (j) and be placed as (i)th
#             block. Each block for sending/receiving has *count* elements, which means
#             that *recvbuff* and *sendbuff* should have a size of nranks*count elements.
#             In-place operation is NOT supported. It is the user's responsibility
#             to ensure that sendbuff and recvbuff are distinct.
# @deprecated ncclAllToAll is replaced with ncclAlltoAll and will be removed in the future.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to send (contains blocks for each other rank)
# @param[in,out] recvbuff      Data array to receive (contains blocks from each other rank)
# @param[in]  count         Number of elements to send between each pair of ranks
# @param[in]  datatype      Data buffer element datatype
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclAllToAll(const void * sendbuff,void * recvbuff,size_t count,ncclDataType_t datatype,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      All-To-Allv
# @details    Device (i) sends sendcounts[j] of data from offset sdispls[j]
#             to device (j). At the same time, device (i) receives recvcounts[j] of data
#             from device (j) to be placed at rdispls[j].
#             sendcounts, sdispls, recvcounts and rdispls are all measured in the units
#             of datatype, not bytes.
#             In-place operation will happen if sendbuff == recvbuff.
# @deprecated ncclAllToAllv is replaced with ncclAlltoAllv and will be removed in the future.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to send (contains blocks for each other rank)
# @param[in]  sendcounts    Array containing number of elements to send to each participating rank
# @param[in]  sdispls       Array of offsets into *sendbuff* for each participating rank
# @param[in,out] recvbuff      Data array to receive (contains blocks from each other rank)
# @param[in]  recvcounts    Array containing number of elements to receive from each participating rank
# @param[in]  rdispls       Array of offsets into *recvbuff* for each participating rank
# @param[in]  datatype      Data buffer element datatype
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclAllToAllv(const void * sendbuff,const size_t * sendcounts,const size_t * sdispls,void * recvbuff,const size_t * recvcounts,const size_t * rdispls,ncclDataType_t datatype,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      Send
# @details    Send data from *sendbuff* to rank *peer*.
#             Rank *peer* needs to call ncclRecv with the same *datatype* and the same *count*
#             as this rank.
#             This operation is blocking for the GPU. If multiple ncclSend and ncclRecv operations
#             need to progress concurrently to complete, they must be fused within a ncclGroupStart /
#             ncclGroupEnd section.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in]  sendbuff      Data array to send
# @param[in]  count         Number of elements to send
# @param[in]  datatype      Data buffer element datatype
# @param[in]  peer          Peer rank to send to
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclSend(const void * sendbuff,size_t count,ncclDataType_t datatype,int peer,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      Receive
# @details    Receive data from rank *peer* into *recvbuff*.
#             Rank *peer* needs to call ncclSend with the same datatype and the same count
#             as this rank.
#             This operation is blocking for the GPU. If multiple ncclSend and ncclRecv operations
#             need to progress concurrently to complete, they must be fused within a ncclGroupStart/
#             ncclGroupEnd section.
# @return     Result code. See @ref rccl_result_code for more details.
# 
# @param[in,out] recvbuff      Data array to receive
# @param[in]  count         Number of elements to receive
# @param[in]  datatype      Data buffer element datatype
# @param[in]  peer          Peer rank to send to
# @param[in]  comm          Communicator group object to execute on
# @param[in]  stream        HIP stream to execute collective on
cdef ncclResult_t ncclRecv(void * recvbuff,size_t count,ncclDataType_t datatype,int peer,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# 
# Put
# 
# One-sided communication operation that writes data from the local buffer to a
# remote peer's registered memory window without explicit participation from the
# target process.
cdef ncclResult_t ncclPutSignal(const void * localbuff,size_t count,ncclDataType_t datatype,int peer,ncclWindow_t peerWin,size_t peerWinOffset,int sigIdx,int ctx,unsigned int flags,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil



cdef ncclResult_t ncclSignal(int peer,int sigIdx,int ctx,unsigned int flags,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


cdef extern from "rccl/rccl.h":

    ctypedef struct ncclWaitSignalDesc_t:
        int opCnt
        int peer
        int sigIdx
        int ctx


cdef ncclResult_t ncclWaitSignal(int nDesc,ncclWaitSignalDesc_t * signalDescs,ncclComm_t comm,hipStream_t stream) except? ncclInternalError nogil


# @brief      Group Start
# @details    Start a group call. All calls to RCCL until ncclGroupEnd will be fused into
#             a single RCCL operation. Nothing will be started on the HIP stream until
#             ncclGroupEnd.
# @return     Result code. See @ref rccl_result_code for more details.
cdef ncclResult_t ncclGroupStart() except? ncclInternalError nogil


# @brief      Group End
# @details    End a group call. Start a fused RCCL operation consisting of all calls since
#             ncclGroupStart. Operations on the HIP stream depending on the RCCL operations
#             need to be called after ncclGroupEnd.
# @return     Result code. See @ref rccl_result_code for more details.
cdef ncclResult_t ncclGroupEnd() except? ncclInternalError nogil


# 
# Group Simulate End
# 
# Simulate a ncclGroupEnd() call and return NCCL's simulation info in a struct.
cdef ncclResult_t ncclGroupSimulateEnd(ncclSimInfo_v22200 * simInfo) except? ncclInternalError nogil


cdef extern from "rccl/rccl.h":

    cdef struct ncclParamHandle:
        pass

    ctypedef ncclParamHandle ncclParamHandle_t


cdef ncclResult_t ncclParamBind(ncclParamHandle ** out,const char * key) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetI8(ncclParamHandle * h,int8_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetI16(ncclParamHandle * h,int16_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetI32(ncclParamHandle * h,int32_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetI64(ncclParamHandle * h,int64_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetU8(ncclParamHandle * h,uint8_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetU16(ncclParamHandle * h,uint16_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetU32(ncclParamHandle * h,uint32_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetU64(ncclParamHandle * h,uint64_t * out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetStr(ncclParamHandle * h,const char ** out) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGet(ncclParamHandle * h,void * out,int maxLen,int * len) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetParameter(const char * key,const char ** value,int * valueLen) except? ncclInternalError nogil



cdef ncclResult_t ncclParamGetAllParameterKeys(const char *** table,int * tableLen) except? ncclInternalError nogil



cdef void ncclParamDumpAll() noexcept nogil


cdef bint __rccl_has_symbol(const char* name) noexcept nogil