Types and Constants

Type wrappers, predefined value constants, and type aliases that appear in public method signatures.

Data type

NcclDataType

class nccl.core.NcclDataType(*values)

Bases: IntEnum

NCCL data type, mirroring ncclDataType_t.

Used as the dtype of buffer specs and as the datatype argument of NCCL collective operations. Supports conversion to/from NumPy dtypes via from_numpy_dtype() and numpy_dtype.

INT8 = 0
CHAR = 0
UINT8 = 1
INT32 = 2
INT = 2
UINT32 = 3
INT64 = 4
UINT64 = 5
FLOAT16 = 6
HALF = 6
FLOAT32 = 7
FLOAT = 7
FLOAT64 = 8
DOUBLE = 8
BFLOAT16 = 9
FLOAT8E4M3 = 10
FLOAT8E5M2 = 11
classmethod from_numpy_dtype(dtype: numpy.dtype) NcclDataType

Maps a NumPy dtype to its NCCL equivalent.

Parameters:

dtype – A NumPy dtype. Mapped first by name (for ml-dtypes like bfloat16, float8_e4m3fn, float8_e5m2) and then by (kind, itemsize) for standard types.

Returns:

Corresponding NcclDataType member.

Raises:

NcclInvalid – If the dtype has no NCCL equivalent.

property itemsize: int

Size in bytes of a single element of this data type.

property numpy_dtype: numpy.dtype

Equivalent NumPy dtype.

Returns:

NumPy dtype corresponding to this NCCL data type. For BFLOAT16 and the float8 variants, ml-dtypes must be installed.

Raises:

NcclInvalid – If ml-dtypes is required but not installed.

Predefined data type constants

Module-level NcclDataType instances for use as the dtype argument of buffer specs.

Constant

Maps to

nccl.core.INT8

NcclDataType.INT8

nccl.core.CHAR

NcclDataType.CHAR

nccl.core.UINT8

NcclDataType.UINT8

nccl.core.INT32

NcclDataType.INT32

nccl.core.INT

NcclDataType.INT

nccl.core.UINT32

NcclDataType.UINT32

nccl.core.INT64

NcclDataType.INT64

nccl.core.UINT64

NcclDataType.UINT64

nccl.core.FLOAT16

NcclDataType.FLOAT16

nccl.core.HALF

NcclDataType.HALF

nccl.core.FLOAT32

NcclDataType.FLOAT32

nccl.core.FLOAT

NcclDataType.FLOAT

nccl.core.FLOAT64

NcclDataType.FLOAT64

nccl.core.DOUBLE

NcclDataType.DOUBLE

nccl.core.BFLOAT16

NcclDataType.BFLOAT16

nccl.core.FLOAT8E4M3

NcclDataType.FLOAT8E4M3

nccl.core.FLOAT8E5M2

NcclDataType.FLOAT8E5M2

Reduction operator

NcclRedOp

class nccl.core.NcclRedOp(*values)

Bases: IntEnum

NCCL reduction operator, mirroring ncclRedOp_t.

Used as the op argument of reduction collectives (Communicator.allreduce(), Communicator.reduce(), Communicator.reduce_scatter()).

SUM = 0
PROD = 1
MAX = 2
MIN = 3
AVG = 4

Predefined reduction operators

Module-level NcclRedOp instances for use as the op argument of reduction collectives. User-defined operators are created via Communicator.create_pre_mul_sum().

Constant

Maps to

nccl.core.SUM

NcclRedOp.SUM

nccl.core.PROD

NcclRedOp.PROD

nccl.core.MAX

NcclRedOp.MAX

nccl.core.MIN

NcclRedOp.MIN

nccl.core.AVG

NcclRedOp.AVG

Team

NCCLTeam

class nccl.core.NCCLTeam(n_ranks: int, rank: int, stride: int)

Bases: LowppSpec

A NCCL team: (n_ranks, rank, stride) view over a communicator.

Produced by team_world, team_lsa, and team_rail.

n_ranks: int
rank: int
stride: int

Type aliases

Aliases naming the argument types accepted by public methods. Each expands to a union of concrete types, so a value of any member type is accepted.

nccl.core.NcclBufferSpec

Represent a union type

E.g. for int | str

nccl.core.NcclScalarSpec

Represent a union type

E.g. for int | str

nccl.core.NcclDeviceSpec

Represent a union type

E.g. for int | str

nccl.core.NcclStreamSpec

Represent a union type

E.g. for int | str

Exceptions

NcclInvalid

Python-side validation exception, raised when a public API receives a malformed argument before it reaches NCCL itself.

exception nccl.core.NcclInvalid(msg)

Bases: Exception

Raised when an argument provided to an NCCL4Py API is invalid.

Used for argument validation errors that the Python layer detects before forwarding the call to NCCL (e.g. unsupported dtype, mismatched buffer counts, wrong device). Errors raised by NCCL itself are reported as NCCLError from the bindings layer.