cusolvermp

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cusolvermp

Go bindings for NVIDIA cuSOLVERMp, the distributed dense linear algebra library. Generated by codegen/cmd/gen-cusolvermp from the pinned cusolverMp.h of the 0.9.1 redistributable; the provenance and digests are in that command's headers/README.md.

FFI is purego. There is no cgo in this package.

Status

Implemented, physically unverified. Nothing here has run against a GPU, a NCCL communicator or more than one rank. What has been verified is the ABI, against a CPU-only fixture compiled from the same header: argument order, by-value widths, out-parameters, the error type, and the loader's behavior when the library or a symbol is absent. See TestNativeFixture in the generator.

Validating it physically needs a multi-rank, multi-GPU job: one process per GPU, at least two NVIDIA GPUs, a driver for the CUDA 12 build, libcusolverMp.so.0 with libnccl.so.2 and libcuda.so.1, and a launcher that gives every rank the same NCCL unique ID. physical_test.go is that consumer test. It skips with the exact list of what it needs, and once opted in it fails rather than skips.

Scope

Bound: handle lifecycle, the NCCL-backed process grid, matrix descriptors, the grid allocator and buffer registration, NUMROC, the workspace queries, the LU factorize-and-solve pair, and the process-wide logger.

Not bound: the QR family, the least-squares solver, the symmetric and generalized eigensolvers, the SVD, the polar decomposition and the Newton-Schulz iteration. They are declared by the header and left out until the common path has run on real hardware.

cusolverMpSetMathMode and cusolverMpGetMathMode are declared by the 0.9.1 header but are not exported by the 0.9.1 library. They are bound anyway, so a build that does export them works and one that does not returns *SymbolError. Use HasSetMathMode to tell the two apart.

Loader

This package opens libcusolverMp.so.0 itself and shares no loader state with cusolver, nccl or cublasmp. Loading is lazy: importing the package opens nothing. Load takes an explicit path, CUSOLVERMP_LIB_PATH names one, CODEGEN_SKIP_BINDINGS disables loading entirely, and Has and the generated HasXxx predicates report which symbols resolved. Every entry point returns a structured error when the library or its symbol is unavailable. None panics.

It borrows types from cusolver (Result, Stream, DataType, Operation, MathMode) and from nccl (Comm), so a caller does not learn a second error or handle vocabulary. It does not load either library.

Ownership

Documented in full in the package doc, under five headings. In short:

  • Rank and device mapping. A handle belongs to one rank, one device and one stream for its whole life. It is not portable and not safe for concurrent use.
  • Local layouts. Matrices are 2D block-cyclic; each rank holds one block. NUMROC gives the local extents, and the leading dimension has to be at least the local row count. A smaller one is a silent memory error.
  • Collective ordering. Every call taking a Grid or MatrixDescriptor is collective. All ranks must reach it, with matching arguments, in the same order. Returning early on a local error leaves the others waiting.
  • Workspace lifetime. The two *BufferSize queries return a device size and a host size specific to the arguments they were asked about. The caller owns both buffers, keeps them alive until the stream has completed, and does not share one between operations in flight.
  • Coordinated cleanup. Synchronize, then destroy descriptors, grid, handle, and only then the communicator and the buffers. Every rank does the same.

DevicePtr and HostPtr are uintptr, never unsafe.Pointer: nothing in this package claims to the garbage collector that a device address, or a host buffer the library reads after the call returns, is a live Go pointer. They are distinct types so the compiler refuses to swap them.

A nil error from Getrf or Getrs means the work was enqueued. dInfo is a single int in device memory and is what says whether it succeeded; read it back after synchronizing the stream.

Early access

MatrixScatterH2D and MatrixGatherD2H are marked in NVIDIA's header as shipped for early access and not part of the official release. They are bound because the physical test needs them to get a matrix in and an answer out.

Documentation

Overview

Package cusolvermp provides Go bindings for NVIDIA cuSOLVERMp, the distributed dense linear algebra library, libcusolverMp.

Status codes, streams, data types and matrix operations use the types in github.com/tmc/lib/nvidia/cusolver; communicators use github.com/tmc/lib/nvidia/nccl. This package opens and probes libcusolverMp on its own and shares no loader state with either of them.

Scope

Handle lifecycle, process grids, matrix descriptors, workspace queries and the LU factorize-and-solve path (Getrf and Getrs) are bound. The QR family, the least-squares solver, the symmetric and generalized eigensolvers, the SVD, the polar decomposition and the Newton-Schulz iteration are declared by the header but deliberately not bound here.

Rank and device mapping

Every rank calls Create with the device ordinal it owns, and that binding is fixed for the life of the handle. A handle is not portable between ranks, is not safe for concurrent use, and must be destroyed by the rank that created it. CreateDeviceGrid takes an already-initialized NCCL communicator whose rank count equals numRowDevices*numColDevices; the mapping argument decides whether a communicator rank becomes a grid row or a grid column first. Ranks that disagree about the grid shape or the mapping do not fail locally, they diverge.

Local layouts

A distributed matrix is 2D block-cyclic. Each rank stores only its own local block and describes the global matrix with CreateMatrixDesc. NUMROC computes how many rows or columns a given process coordinate owns, which is what the local leading dimension has to accommodate; passing a leading dimension smaller than the local row count is a silent memory error, not a status code. Matrix indices IA and JA are one-based, following ScaLAPACK.

MatrixScatterH2D and MatrixGatherD2H move a matrix between one rank's host buffer and the distributed blocks. NVIDIA's header marks both as shipped for early access and not part of the official release.

Collective ordering

Every call that takes a Grid or a MatrixDescriptor is collective over the communicator behind that grid. All ranks must reach the same call, with matching arguments, in the same order. A rank that returns early on a local error, or that skips a call because a local check failed, leaves the remaining ranks waiting. Handle an error by propagating it to every rank and tearing down together.

Workspace lifetime

GetrfBufferSize and GetrsBufferSize return a device size and a host size. The caller allocates both, keeps them alive until the stream has completed the operation, and does not share one workspace between two operations in flight. The sizes depend on the arguments they were queried with: re-query whenever the matrix, the descriptors, or the compute type change.

Coordinated cleanup

Synchronize the stream, then destroy in reverse order of creation: matrix descriptors, then the grid, then the handle, and only then the communicator and the device buffers. Every rank performs the same teardown. Destroying a grid while a descriptor still refers to it, or freeing device memory the library is still reading, is undefined behavior that this package cannot detect.

Memory

DevicePtr and HostPtr are plain addresses. They are not Go pointers, they do not keep an allocation alive, and the garbage collector cannot see through them. Do not pass the address of Go memory: these calls are asynchronous on the stream and the library reads the buffers after the call returns.

Malloc and Free are the grid's own allocator, which registers the block for collective transfer as it allocates. BufferRegister and BufferDeregister do the registration alone, for memory the caller allocated elsewhere; the caller keeps ownership and must deregister before freeing.

The index below covers the wrappers generated from the header's declarations. The memory, layout and factorization entry points listed above are written by hand, next to the ownership rule each one carries, and do not appear in it.

See the cuSOLVERMp documentation for the block-cyclic layout rules and the supported precision combinations.

Lifecycle

Logging

Other

Example

Example shows the shape of one rank's work in a distributed LU solve: build the handle for the device this rank owns, wrap the already-initialized NCCL communicator in a process grid, describe the local block of each distributed matrix, size the workspaces, factorize, and solve.

Every call below is collective over the grid. All ranks must reach every one of them, in this order, with matching global arguments; a rank that returns early leaves the others waiting. The addresses are device addresses supplied by the caller, which this package will not allocate, free or trace.

This example is not executed. It needs libcusolverMp, an NVIDIA GPU per rank, and a launcher that starts one rank per GPU with a shared NCCL communicator.

// comm is an initialized nccl.Comm with nprow*npcol ranks; stream is the
// CUDA stream this rank drives. Both are caller-owned and must outlive
// everything created below.
var (
	comm         = exampleComm()
	stream       = exampleStream()
	device int32 = 0 // the ordinal this rank owns
	nprow  int32 = 2
	npcol  int32 = 2
)

handle, err := cusolvermp.NewHandle(device, stream)
if err != nil {
	fmt.Println("cuSOLVERMp unavailable:", err)
	return
}
defer handle.Close()

grid, err := handle.CreateDeviceGrid(comm, nprow, npcol, cusolvermp.GridMappingRowMajor)
if err != nil {
	fmt.Println("grid:", err)
	return
}
defer grid.Close()

// The global system is n-by-n with nrhs right-hand sides, blocked mb-by-nb
// and distributed over the grid. Each rank holds only its own block.
const (
	n, nrhs int64 = 4096, 1
	mb, nb  int64 = 256, 256
)
myrow, mycol := exampleCoords(nprow, npcol)

// NUMROC gives this rank's local extents, which is what the leading
// dimension has to accommodate. A smaller lld is a silent memory error.
localRowsA, err := cusolvermp.NUMROC(n, mb, myrow, 0, uint32(nprow))
if err != nil {
	fmt.Println("numroc:", err)
	return
}
localColsA, err := cusolvermp.NUMROC(n, nb, mycol, 0, uint32(npcol))
if err != nil {
	fmt.Println("numroc:", err)
	return
}

descA, err := grid.CreateMatrixDesc(cusolvermp.R64F, n, n, mb, nb, 0, 0, localRowsA)
if err != nil {
	fmt.Println("descriptor:", err)
	return
}
defer descA.Close()
descB, err := grid.CreateMatrixDesc(cusolvermp.R64F, n, nrhs, mb, nb, 0, 0, localRowsA)
if err != nil {
	fmt.Println("descriptor:", err)
	return
}
defer descB.Close()

// The grid's allocator hands back device addresses that are already
// registered for collective transfer. They are freed explicitly: nothing
// here is traced by the garbage collector.
dA, err := grid.Malloc(uint(localRowsA * localColsA * 8))
if err != nil {
	fmt.Println("allocate:", err)
	return
}
defer grid.Free(dA)
dB, err := grid.Malloc(uint(localRowsA * 8))
if err != nil {
	fmt.Println("allocate:", err)
	return
}
defer grid.Free(dB)
dIpiv, err := grid.Malloc(uint(localRowsA * 8))
if err != nil {
	fmt.Println("allocate:", err)
	return
}
defer grid.Free(dIpiv)
dInfo, err := grid.Malloc(4)
if err != nil {
	fmt.Println("allocate:", err)
	return
}
defer grid.Free(dInfo)

// Workspace sizes are specific to these arguments and must be re-queried
// whenever any of them change.
deviceBytes, hostBytes, err := cusolvermp.GetrfBufferSize(handle, n, n, dA, 1, 1, descA, dIpiv, cusolvermp.R64F)
if err != nil {
	fmt.Println("workspace:", err)
	return
}
dWork, err := grid.Malloc(deviceBytes)
if err != nil {
	fmt.Println("allocate:", err)
	return
}
defer grid.Free(dWork)
hWork := exampleHostBuffer(hostBytes)

// Matrix indices are one-based, following ScaLAPACK.
if err := cusolvermp.Getrf(handle, n, n, dA, 1, 1, descA, dIpiv, cusolvermp.R64F, dWork, deviceBytes, hWork, hostBytes, dInfo); err != nil {
	fmt.Println("getrf:", err)
	return
}
if err := cusolvermp.Getrs(handle, cusolvermp.OpN, n, nrhs, dA, 1, 1, descA, dIpiv, dB, 1, 1, descB, cusolvermp.R64F, dWork, deviceBytes, hWork, hostBytes, dInfo); err != nil {
	fmt.Println("getrs:", err)
	return
}

// Both calls only enqueued work. Synchronize the stream, then read dInfo
// back from the device: a nil error above does not mean the factorization
// succeeded. The solution overwrites dB in place.
exampleSynchronize(stream)
if info := exampleReadInfo(dInfo); info != 0 {
	fmt.Println("factorization reported", info)
	return
}
fmt.Println("solved")

Index

Examples

Constants

View Source
const (
	R32F cusolver.DataType = 0
	R64F cusolver.DataType = 1
	C32F cusolver.DataType = 4
	C64F cusolver.DataType = 5
)

Element types the LU path accepts, as cudaDataType values. The compute type passed to Getrf and Getrs is independent of the matrix element type; see the cuSOLVERMp documentation for the combinations the library supports.

View Source
const (
	OpN cusolver.Operation = 0
	OpT cusolver.Operation = 1
	OpC cusolver.Operation = 2
)

Transpose modes, as cublasOperation_t values. OpT and OpC differ only for a complex matrix, where OpC is the conjugate transpose.

Variables

This section is empty.

Functions

func BufferDeregister

func BufferDeregister(grid Grid, ptr DevicePtr) error

BufferDeregister wraps cusolverMpBufferDeregister. It withdraws a registration made by BufferRegister. It does not free the memory.

func BufferRegister

func BufferRegister(grid Grid, ptr DevicePtr, size uint) error

BufferRegister wraps cusolverMpBufferRegister. It registers size bytes of caller-allocated device memory at ptr with grid, so that the library may use it as the source or destination of a collective transfer.

The caller keeps ownership. The registration must be withdrawn with BufferDeregister before the memory is released, and the memory must stay mapped at the same address for the whole registration.

func Close

func Close() error

Close unloads the library and clears all bound function pointers.

The function pointers are package-level state, so Close must not be called concurrently with any other call into this package: doing so is a use-after-free. It is intended for test teardown, not for reclaiming a live library.

func Destroy

func Destroy(handle Handle) error

Destroy releases a handle created by NewHandle

Synchronize the handle's stream first: work already enqueued still refers to the handle. Destroy the grids and matrix descriptors built on this handle before destroying it, and destroy the NCCL communicator only afterwards. Every rank performs the same teardown.

Wraps cusolverMpDestroy.

func DestroyGrid

func DestroyGrid(grid Grid) error

DestroyGrid releases a grid created by Handle.CreateDeviceGrid

Destroy every matrix descriptor built on the grid first, and free or deregister every buffer the grid allocated or registered. Destroying a grid that a live descriptor still refers to is undefined behavior that this package cannot detect. The call is collective.

Wraps cusolverMpDestroyGrid.

func DestroyMatrixDesc

func DestroyMatrixDesc(desc MatrixDescriptor) error

DestroyMatrixDesc releases a descriptor created by Grid.CreateMatrixDesc

Synchronize the stream first: an enqueued operation still refers to the descriptor. Destroying the descriptor does not free the matrix memory.

Wraps cusolverMpDestroyMatrixDesc.

func Free

func Free(grid Grid, ptr DevicePtr) error

Free wraps cusolverMpFree. It releases an allocation obtained from Malloc on the same grid. Freeing memory the library is still reading, which includes memory an enqueued operation has not finished with, is undefined behavior that this package cannot detect: synchronize the stream first.

func GetMathMode

func GetMathMode(handle Handle) (cusolver.MathMode, error)

GetMathMode returns the arithmetic mode set by Handle.SetMathMode

Not exported by the library shipped with 0.9.1; see Handle.SetMathMode.

Wraps cusolverMpGetMathMode.

func GetStream

func GetStream(handle Handle) (driver.Stream, error)

GetStream returns the stream operations on handle are enqueued on

Wraps cusolverMpGetStream.

func GetVersion

func GetVersion(handle Handle) (int32, error)

GetVersion returns the version of the loaded library

The value is major*10000 + minor*100 + patch, so 0.9.1 reports 901. This package was generated against the 0.9.1 header; a library that reports a different version may not export every symbol bound here.

Wraps cusolverMpGetVersion.

func Getrf

func Getrf(handle Handle, m, n int64, dA DevicePtr, ia, ja int64, descA MatrixDescriptor, dIpiv DevicePtr, computeType cusolver.DataType, dWork DevicePtr, deviceBytes uint, hWork HostPtr, hostBytes uint, dInfo DevicePtr) error

Getrf wraps cusolverMpGetrf. It computes the LU factorization of the m-by-n submatrix of the distributed matrix described by descA, starting at the one-based global element (ia, ja), in place.

The call is collective over the grid behind descA: every rank must reach it with matching m, n, ia, ja, descriptors and compute type, and in the same order relative to other collective calls. A rank that skips the call on a local error leaves the others waiting.

dIpiv addresses the local part of the distributed pivot array, at least NUMROC(m, mb, myrow, rsrc, nprow) int64 entries; pass zero to request the unpivoted factorization, which is not backward stable for a general matrix.

dWork and hWork are the workspaces whose sizes GetrfBufferSize returned for these same arguments; deviceBytes and hostBytes must be those sizes. Both buffers, dA, dIpiv and dInfo are caller-owned addresses that must stay valid and unshared until the stream has completed the operation.

dInfo is a single int in device memory. A zero return from Getrf means the work was enqueued, not that the factorization succeeded: read dInfo back after synchronizing the stream. A positive value is the one-based index of a zero pivot; a negative value reports an invalid argument.

func GetrfBufferSize

func GetrfBufferSize(handle Handle, m, n int64, dA DevicePtr, ia, ja int64, descA MatrixDescriptor, dIpiv DevicePtr, computeType cusolver.DataType) (deviceBytes, hostBytes uint, err error)

GetrfBufferSize wraps cusolverMpGetrf_bufferSize. It reports how many bytes of device workspace and how many bytes of host workspace a Getrf call with exactly these arguments will need.

The two sizes depend on the matrix, the descriptor and the compute type, so they must be re-queried whenever any of those change; a workspace sized for one call is not valid for another. The call is collective over the grid behind descA, and the sizes it returns are the ones this rank must supply.

dA and dIpiv are inspected but not modified. dIpiv may be zero, which asks for the unpivoted factorization.

func Getrs

func Getrs(handle Handle, trans cusolver.Operation, n, nrhs int64, dA DevicePtr, ia, ja int64, descA MatrixDescriptor, dIpiv, dB DevicePtr, ib, jb int64, descB MatrixDescriptor, computeType cusolver.DataType, dWork DevicePtr, deviceBytes uint, hWork HostPtr, hostBytes uint, dInfo DevicePtr) error

Getrs wraps cusolverMpGetrs. It solves op(A) * X = B in place in B, where A is the n-by-n factorization Getrf left in the submatrix of descA at the one-based global element (ia, ja), dIpiv is the pivot array that same Getrf call produced, and B is the n-by-nrhs submatrix of descB at (ib, jb).

The call is collective over the grid behind descA and descB, with the same matching and ordering requirements as Getrf. Passing a pivot array from a different factorization, or a descriptor whose grid differs from descA's, is not diagnosed.

dWork and hWork are the workspaces whose sizes GetrsBufferSize returned for these same arguments. Every address here is caller-owned and must stay valid until the stream has completed the operation.

dInfo is a single int in device memory, read back after synchronizing the stream; see Getrf.

func GetrsBufferSize

func GetrsBufferSize(handle Handle, trans cusolver.Operation, n, nrhs int64, dA DevicePtr, ia, ja int64, descA MatrixDescriptor, dIpiv, dB DevicePtr, ib, jb int64, descB MatrixDescriptor, computeType cusolver.DataType) (deviceBytes, hostBytes uint, err error)

GetrsBufferSize wraps cusolverMpGetrs_bufferSize. It reports how many bytes of device workspace and how many bytes of host workspace a Getrs call with exactly these arguments will need. The sizes are specific to these arguments; see GetrfBufferSize.

func Has

func Has(symbol string) bool

Has reports whether the named C symbol resolved in the loaded library, loading it first if necessary. It returns false if the library failed to load. Use it to gate on capabilities before calling into them.

func HasBufferDeregister

func HasBufferDeregister() bool

HasBufferDeregister reports whether cusolverMpBufferDeregister resolved in the loaded library.

func HasBufferRegister

func HasBufferRegister() bool

HasBufferRegister reports whether cusolverMpBufferRegister resolved in the loaded library.

func HasCreate

func HasCreate() bool

HasCreate reports whether cusolverMpCreate resolved in the loaded library.

func HasCreateDeviceGrid

func HasCreateDeviceGrid() bool

HasCreateDeviceGrid reports whether cusolverMpCreateDeviceGrid resolved in the loaded library.

func HasCreateMatrixDesc

func HasCreateMatrixDesc() bool

HasCreateMatrixDesc reports whether cusolverMpCreateMatrixDesc resolved in the loaded library.

func HasDestroy

func HasDestroy() bool

HasDestroy reports whether cusolverMpDestroy resolved in the loaded library.

func HasDestroyGrid

func HasDestroyGrid() bool

HasDestroyGrid reports whether cusolverMpDestroyGrid resolved in the loaded library.

func HasDestroyMatrixDesc

func HasDestroyMatrixDesc() bool

HasDestroyMatrixDesc reports whether cusolverMpDestroyMatrixDesc resolved in the loaded library.

func HasFree

func HasFree() bool

HasFree reports whether cusolverMpFree resolved in the loaded library.

func HasGetMathMode

func HasGetMathMode() bool

HasGetMathMode reports whether cusolverMpGetMathMode resolved in the loaded library.

func HasGetStream

func HasGetStream() bool

HasGetStream reports whether cusolverMpGetStream resolved in the loaded library.

func HasGetVersion

func HasGetVersion() bool

HasGetVersion reports whether cusolverMpGetVersion resolved in the loaded library.

func HasGetrf

func HasGetrf() bool

HasGetrf reports whether cusolverMpGetrf resolved in the loaded library.

func HasGetrfBufferSize

func HasGetrfBufferSize() bool

HasGetrfBufferSize reports whether cusolverMpGetrf_bufferSize resolved in the loaded library.

func HasGetrs

func HasGetrs() bool

HasGetrs reports whether cusolverMpGetrs resolved in the loaded library.

func HasGetrsBufferSize

func HasGetrsBufferSize() bool

HasGetrsBufferSize reports whether cusolverMpGetrs_bufferSize resolved in the loaded library.

func HasLoggerForceDisable

func HasLoggerForceDisable() bool

HasLoggerForceDisable reports whether cusolverMpLoggerForceDisable resolved in the loaded library.

func HasLoggerOpenFile

func HasLoggerOpenFile() bool

HasLoggerOpenFile reports whether cusolverMpLoggerOpenFile resolved in the loaded library.

func HasLoggerSetLevel

func HasLoggerSetLevel() bool

HasLoggerSetLevel reports whether cusolverMpLoggerSetLevel resolved in the loaded library.

func HasLoggerSetMask

func HasLoggerSetMask() bool

HasLoggerSetMask reports whether cusolverMpLoggerSetMask resolved in the loaded library.

func HasMalloc

func HasMalloc() bool

HasMalloc reports whether cusolverMpMalloc resolved in the loaded library.

func HasMatrixGatherD2H

func HasMatrixGatherD2H() bool

HasMatrixGatherD2H reports whether cusolverMpMatrixGatherD2H resolved in the loaded library.

func HasMatrixScatterH2D

func HasMatrixScatterH2D() bool

HasMatrixScatterH2D reports whether cusolverMpMatrixScatterH2D resolved in the loaded library.

func HasNUMROC

func HasNUMROC() bool

HasNUMROC reports whether cusolverMpNUMROC resolved in the loaded library.

func HasSetMathMode

func HasSetMathMode() bool

HasSetMathMode reports whether cusolverMpSetMathMode resolved in the loaded library.

func HasSetStream

func HasSetStream() bool

HasSetStream reports whether cusolverMpSetStream resolved in the loaded library.

func Load

func Load(path string) error

Load opens the shared library from path, or from the default search list when path is empty, and binds all symbols. Callers that need to direct loading should call Load before any other function; otherwise the first call loads from the default search list.

Load is idempotent: calling it again with the same path, or with an empty path, returns nil. Calling it with a different path after a successful load returns *LibraryConflictError rather than replacing the library. After a failed load, Load retries.

func Loaded

func Loaded() bool

Loaded reports whether the library is currently loaded. It does not trigger a load.

func LoggerForceDisable

func LoggerForceDisable() error

LoggerForceDisable turns the library's logging off for the rest of the process

It cannot be turned back on.

Wraps cusolverMpLoggerForceDisable.

func LoggerOpenFile

func LoggerOpenFile(logFile string) error

LoggerOpenFile sends the library's log to a file

Process-wide, not per handle. Every rank writing to one path on a shared filesystem interleaves its output with the others.

  • logFile: path to open; copied by the library

Wraps cusolverMpLoggerOpenFile.

func LoggerSetLevel

func LoggerSetLevel(level int32) error

LoggerSetLevel sets the library's log verbosity

Process-wide, not per handle.

Wraps cusolverMpLoggerSetLevel.

func LoggerSetMask

func LoggerSetMask(mask int32) error

LoggerSetMask selects which log categories the library emits

Process-wide, not per handle.

Wraps cusolverMpLoggerSetMask.

func MatrixGatherD2H

func MatrixGatherD2H(handle Handle, m, n int64, dA DevicePtr, ia, ja int64, descA MatrixDescriptor, root int32, hDst HostPtr, hLdDst int64) error

MatrixGatherD2H wraps cusolverMpMatrixGatherD2H. It collects the m-by-n submatrix of the distributed matrix described by descA, starting at the one-based global element (ia, ja), into the host buffer hDst on rank root, in column-major order with leading dimension hLdDst.

The call is collective, with the same matching requirements as MatrixScatterH2D. hDst is written on root only; dA is read on every rank.

NVIDIA's header marks this routine as shipped for early access and not part of the official release. Treat it as available only in the pinned version this package was generated against.

func MatrixScatterH2D

func MatrixScatterH2D(handle Handle, m, n int64, dA DevicePtr, ia, ja int64, descA MatrixDescriptor, root int32, hSrc HostPtr, hLdSrc int64) error

MatrixScatterH2D wraps cusolverMpMatrixScatterH2D. It distributes an m-by-n host matrix held on rank root, in column-major order with leading dimension hLdSrc, into the local blocks dA described by descA, starting at the one-based global element (ia, ja).

The call is collective: every rank in the grid behind descA must reach it with matching m, n, ia, ja and root. hSrc is read on root only; dA is written on every rank. Both are caller-owned addresses that must stay valid until the stream has completed the transfer.

NVIDIA's header marks this routine as shipped for early access and not part of the official release. Treat it as available only in the pinned version this package was generated against.

func NUMROC

func NUMROC(n, nb int64, iproc, isrcproc, nprocs uint32) (int64, error)

NUMROC wraps cusolverMpNUMROC. It reports how many rows or columns of an n-element dimension, distributed in blocks of nb over nprocs processes starting at process isrcproc, are owned by process iproc.

It is the local-layout query: the local array of a distributed matrix needs NUMROC(M, MB, myrow, RSRC, nprow) rows and NUMROC(N, NB, mycol, CSRC, npcol) columns, and the leading dimension passed to CreateMatrixDesc must be at least the row count. This is a pure function of its arguments and performs no communication, but it lives in the library, so it reports an error if the library or the symbol is unavailable.

Example

ExampleNUMROC shows how a rank's grid coordinates and its local block extents follow from the grid shape. The arithmetic is ScaLAPACK's, and it is what the leading dimension passed to CreateMatrixDesc has to accommodate.

This part needs no library: it is the same formula NUMROC evaluates.

package main

import (
	"fmt"
)

func main() {
	const (
		n, nb        int64  = 1000, 64
		nprow, npcol uint32 = 2, 3
	)
	// A rank's coordinates in a row-major grid.
	for rank := uint32(0); rank < nprow*npcol; rank++ {
		myrow, mycol := rank/npcol, rank%npcol
		rows := numroc(n, nb, myrow, 0, nprow)
		cols := numroc(n, nb, mycol, 0, npcol)
		fmt.Printf("rank %d at (%d,%d) holds %dx%d\n", rank, myrow, mycol, rows, cols)
	}
}

// numroc is the ScaLAPACK formula cusolverMpNUMROC evaluates, repeated here so
// the example runs without the library.
func numroc(n, nb int64, iproc, isrcproc, nprocs uint32) int64 {
	mydist := int64((nprocs + iproc - isrcproc) % nprocs)
	nblocks := n / nb
	nroc := (nblocks / int64(nprocs)) * nb
	extra := nblocks % int64(nprocs)
	switch {
	case mydist < extra:
		nroc += nb
	case mydist == extra:
		nroc += n % nb
	}
	return nroc
}
Output:
rank 0 at (0,0) holds 512x360
rank 1 at (0,1) holds 512x320
rank 2 at (0,2) holds 512x320
rank 3 at (1,0) holds 488x360
rank 4 at (1,1) holds 488x320
rank 5 at (1,2) holds 488x320

func Path

func Path() string

Path returns the path or name the loaded library was opened from, or the empty string if no library is loaded.

func SetMathMode

func SetMathMode(handle Handle, mode cusolver.MathMode) error

SetMathMode selects the arithmetic the library may use

The library shipped with 0.9.1 declares this entry point but does not export it, so this wrapper returns *SymbolError there. Use HasSetMathMode to test for it rather than treating the error as a failure of the call.

Wraps cusolverMpSetMathMode.

func SetStream

func SetStream(handle Handle, stream driver.Stream) error

SetStream redirects subsequent operations on handle to stream

Operations already enqueued stay on the previous stream. Changing the stream does not order the two: if later work depends on earlier work, the caller supplies that ordering. Every rank must make the same sequence of collective calls whichever stream they run on.

  • stream: caller-owned stream, which must outlive the handle's use of it

Wraps cusolverMpSetStream.

Types

type BindFailure

type BindFailure struct {
	Symbol string
	Err    error
}

BindFailure names a symbol the loaded library exports but that could not be bound, and why.

func BindFailures

func BindFailures() []BindFailure

BindFailures returns the symbols the loaded library exports that could not be bound, sorted by symbol name, or nil if every exported symbol bound. Calling one of these reports *SymbolError with the same Err.

A load that reports no error can still leave symbols unbound: the library is fine and the signatures are not representable here. Call this after Load to find that out at once rather than one call site at a time. It does not trigger a load, and returns nil if none has happened.

type CallError

type CallError = cusolver.CallError

CallError reports that a cuSOLVERMp call returned a failure status. It is cuSOLVER's, so errors.As matches it whichever package made the call.

type DevicePtr

type DevicePtr uintptr

DevicePtr is an address in GPU memory. It is not a Go pointer, is not visible to the garbage collector, and does not keep an allocation alive. The caller must keep the allocation valid until every operation reading or writing it has completed on the stream.

func Malloc

func Malloc(grid Grid, size uint) (DevicePtr, error)

Malloc wraps cusolverMpMalloc. It allocates size bytes of device memory on the calling rank's device and registers the allocation with grid, which is what lets the library move the block between ranks.

The returned address is owned by the caller and must be released with Free on the same grid, after the stream has completed every operation that reads or writes it. It is not a Go pointer: nothing keeps it alive and nothing frees it automatically.

type Grid

type Grid uintptr

Grid is an opaque handle for cusolverMpGrid_t.

func CreateDeviceGrid

func CreateDeviceGrid(handle Handle, comm nccl.Comm, numRowDevices int32, numColDevices int32, mapping GridMapping) (Grid, error)

CreateDeviceGrid describes the process grid the distributed matrices are laid out over

The call is collective: every rank of comm must create the grid with the same numRowDevices, numColDevices and mapping. Ranks that disagree do not fail locally, they diverge, and the first collective operation on the grid hangs or produces wrong results.

The grid borrows comm. It does not take ownership: the caller keeps the communicator alive until every grid built on it has been destroyed with Grid.Close, and destroys the communicator afterwards.

  • comm: initialized NCCL communicator whose rank count is numRowDevices*numColDevices; borrowed, not owned
  • numRowDevices: number of process rows
  • numColDevices: number of process columns
  • mapping: whether a communicator rank advances along a grid row or a grid column first

Wraps cusolverMpCreateDeviceGrid.

func (Grid) BufferDeregister

func (g Grid) BufferDeregister(ptr DevicePtr) error

BufferDeregister withdraws a registration made with Grid.BufferRegister. See BufferDeregister.

func (Grid) BufferRegister

func (g Grid) BufferRegister(ptr DevicePtr, size uint) error

BufferRegister registers caller-owned device memory with g. See BufferRegister.

func (*Grid) Close

func (g *Grid) Close() error

Close releases a grid created by Handle.CreateDeviceGrid

Destroy every matrix descriptor built on the grid first, and free or deregister every buffer the grid allocated or registered. Destroying a grid that a live descriptor still refers to is undefined behavior that this package cannot detect. The call is collective.

If g is zero, Close returns nil. Otherwise Close sets g to zero when the call succeeds and leaves it unchanged when it fails. Only g is zeroed: a copy of it still refers to the released object.

Wraps cusolverMpDestroyGrid.

func (Grid) CreateMatrixDesc

func (g Grid) CreateMatrixDesc(dataType cusolver.DataType, mA int64, nA int64, mBA int64, nBA int64, rSRCA uint32, cSRCA uint32, lLDA int64) (MatrixDescriptor, error)

CreateMatrixDesc describes a 2D block-cyclic distributed matrix over a grid

The descriptor covers the whole global matrix; each rank stores only its own local block. The local block on the rank at grid coordinate (myrow, mycol) has NUMROC(m, mb, myrow, rsrc, nprow) rows and NUMROC(n, nb, mycol, csrc, npcol) columns, in column-major order. See NUMROC.

lld is the leading dimension of that local block and must be at least its local row count. A smaller value is a silent out-of-bounds access, not a status code.

The descriptor borrows grid and does not own the matrix memory. The caller keeps both alive until the descriptor is destroyed with MatrixDescriptor.Close. The call is collective and every rank must pass identical global arguments.

  • dataType: element type of the matrix
  • mA: global row count
  • nA: global column count
  • mBA: row blocking factor
  • nBA: column blocking factor
  • rSRCA: grid row that owns the first block row
  • cSRCA: grid column that owns the first block column
  • lLDA: leading dimension of this rank's local block, at least its local row count

Wraps cusolverMpCreateMatrixDesc.

func (Grid) Free

func (g Grid) Free(ptr DevicePtr) error

Free releases memory allocated by Grid.Malloc. See Free.

func (Grid) Malloc

func (g Grid) Malloc(size uint) (DevicePtr, error)

Malloc allocates device memory registered with g. See Malloc.

type GridMapping

type GridMapping int32

GridMapping represents cusolverMpGridMapping_t.

const (
	GridMappingRowMajor GridMapping = 1
	GridMappingColMajor GridMapping = 0
)

func (GridMapping) String

func (e GridMapping) String() string

String returns the constant name, or a numeric representation for unknown values.

type Handle

type Handle uintptr

Handle is an opaque handle for cusolverMpHandle_t.

func Create

func Create(deviceId int32, stream driver.Stream) (Handle, error)

Create creates a cuSOLVERMp handle bound to one device and one stream

Each rank creates its own handle for the device it owns, and that binding is fixed for the life of the handle. A handle is not portable between ranks or devices, is not safe for concurrent use, and must be destroyed with Handle.Close by the rank that created it.

The handle does not own the stream. The caller keeps the stream valid until the handle is destroyed.

  • deviceId: ordinal of the device this rank owns
  • stream: stream every subsequent operation on this handle is enqueued on; caller-owned

Wraps cusolverMpCreate.

func NewHandle

func NewHandle(deviceId int32, stream driver.Stream) (Handle, error)

NewHandle creates a cuSOLVERMp handle bound to one device and one stream

Each rank creates its own handle for the device it owns, and that binding is fixed for the life of the handle. A handle is not portable between ranks or devices, is not safe for concurrent use, and must be destroyed with Handle.Close by the rank that created it.

The handle does not own the stream. The caller keeps the stream valid until the handle is destroyed.

  • deviceId: ordinal of the device this rank owns
  • stream: stream every subsequent operation on this handle is enqueued on; caller-owned

Wraps cusolverMpCreate.

func (*Handle) Close

func (h *Handle) Close() error

Close releases a handle created by NewHandle

Synchronize the handle's stream first: work already enqueued still refers to the handle. Destroy the grids and matrix descriptors built on this handle before destroying it, and destroy the NCCL communicator only afterwards. Every rank performs the same teardown.

If h is zero, Close returns nil. Otherwise Close sets h to zero when the call succeeds and leaves it unchanged when it fails. Only h is zeroed: a copy of it still refers to the released object.

Wraps cusolverMpDestroy.

func (Handle) CreateDeviceGrid

func (h Handle) CreateDeviceGrid(comm nccl.Comm, numRowDevices int32, numColDevices int32, mapping GridMapping) (Grid, error)

CreateDeviceGrid describes the process grid the distributed matrices are laid out over

The call is collective: every rank of comm must create the grid with the same numRowDevices, numColDevices and mapping. Ranks that disagree do not fail locally, they diverge, and the first collective operation on the grid hangs or produces wrong results.

The grid borrows comm. It does not take ownership: the caller keeps the communicator alive until every grid built on it has been destroyed with Grid.Close, and destroys the communicator afterwards.

  • comm: initialized NCCL communicator whose rank count is numRowDevices*numColDevices; borrowed, not owned
  • numRowDevices: number of process rows
  • numColDevices: number of process columns
  • mapping: whether a communicator rank advances along a grid row or a grid column first

Wraps cusolverMpCreateDeviceGrid.

func (Handle) MathMode

func (h Handle) MathMode() (cusolver.MathMode, error)

MathMode returns the arithmetic mode set by Handle.SetMathMode

Not exported by the library shipped with 0.9.1; see Handle.SetMathMode.

Wraps cusolverMpGetMathMode.

func (Handle) SetMathMode

func (h Handle) SetMathMode(mode cusolver.MathMode) error

SetMathMode selects the arithmetic the library may use

The library shipped with 0.9.1 declares this entry point but does not export it, so this wrapper returns *SymbolError there. Use HasSetMathMode to test for it rather than treating the error as a failure of the call.

Wraps cusolverMpSetMathMode.

func (Handle) SetStream

func (h Handle) SetStream(stream driver.Stream) error

SetStream redirects subsequent operations on handle to stream

Operations already enqueued stay on the previous stream. Changing the stream does not order the two: if later work depends on earlier work, the caller supplies that ordering. Every rank must make the same sequence of collective calls whichever stream they run on.

  • stream: caller-owned stream, which must outlive the handle's use of it

Wraps cusolverMpSetStream.

func (Handle) Stream

func (h Handle) Stream() (driver.Stream, error)

Stream returns the stream operations on handle are enqueued on

Wraps cusolverMpGetStream.

func (Handle) Version

func (h Handle) Version() (int32, error)

Version returns the version of the loaded library

The value is major*10000 + minor*100 + patch, so 0.9.1 reports 901. This package was generated against the 0.9.1 header; a library that reports a different version may not export every symbol bound here.

Wraps cusolverMpGetVersion.

type HostPtr

type HostPtr uintptr

HostPtr is an address in host memory that the library reads or writes after the call that received it has returned, because the call only enqueues work on the stream. It is not a Go pointer and does not keep an allocation alive. Do not pass the address of Go memory.

type LibraryAttempt

type LibraryAttempt struct {
	Name string // path or soname passed to dlopen
	Err  error
}

LibraryAttempt records one failed attempt to open the shared library.

type LibraryConflictError

type LibraryConflictError struct {
	Loaded    string
	Requested string

	// Implicit reports that the loaded library was opened lazily and no
	// successful Load has since acknowledged it. A
	// caller that sees this called some
	// other function first, and that call took the default search list.
	Implicit bool
}

LibraryConflictError reports a Load call naming a different library than the one already loaded. Only one library is loaded per process.

func (*LibraryConflictError) Error

func (e *LibraryConflictError) Error() string

Error reports the conflicting library paths, and whether the library that is already loaded got there without a Load call.

type LibraryError

type LibraryError struct {
	Library  string
	Env      string
	Path     string
	Attempts []LibraryAttempt
	Hint     string
}

LibraryError reports that libcusolverMp could not be opened. Attempts lists every name tried in order. Path is set when an explicit path, from Load or CUSOLVERMP_LIB_PATH, was requested and failed. Hint reports pkg-config discovery results and query failures, when discovery ran.

func (*LibraryError) Error

func (e *LibraryError) Error() string

Error describes the library load attempts and their errors.

func (*LibraryError) Unwrap

func (e *LibraryError) Unwrap() []error

Unwrap returns the error from each attempt.

type MatrixDescriptor

type MatrixDescriptor uintptr

MatrixDescriptor is an opaque handle for cusolverMpMatrixDescriptor_t.

func CreateMatrixDesc

func CreateMatrixDesc(grid Grid, dataType cusolver.DataType, mA int64, nA int64, mBA int64, nBA int64, rSRCA uint32, cSRCA uint32, lLDA int64) (MatrixDescriptor, error)

CreateMatrixDesc describes a 2D block-cyclic distributed matrix over a grid

The descriptor covers the whole global matrix; each rank stores only its own local block. The local block on the rank at grid coordinate (myrow, mycol) has NUMROC(m, mb, myrow, rsrc, nprow) rows and NUMROC(n, nb, mycol, csrc, npcol) columns, in column-major order. See NUMROC.

lld is the leading dimension of that local block and must be at least its local row count. A smaller value is a silent out-of-bounds access, not a status code.

The descriptor borrows grid and does not own the matrix memory. The caller keeps both alive until the descriptor is destroyed with MatrixDescriptor.Close. The call is collective and every rank must pass identical global arguments.

  • dataType: element type of the matrix
  • mA: global row count
  • nA: global column count
  • mBA: row blocking factor
  • nBA: column blocking factor
  • rSRCA: grid row that owns the first block row
  • cSRCA: grid column that owns the first block column
  • lLDA: leading dimension of this rank's local block, at least its local row count

Wraps cusolverMpCreateMatrixDesc.

func (*MatrixDescriptor) Close

func (m *MatrixDescriptor) Close() error

Close releases a descriptor created by Grid.CreateMatrixDesc

Synchronize the stream first: an enqueued operation still refers to the descriptor. Destroying the descriptor does not free the matrix memory.

If m is zero, Close returns nil. Otherwise Close sets m to zero when the call succeeds and leaves it unchanged when it fails. Only m is zeroed: a copy of it still refers to the released object.

Wraps cusolverMpDestroyMatrixDesc.

type Result

type Result = cusolver.Result

Result is the cuSOLVER status code, which cuSOLVERMp returns unchanged.

type SymbolError

type SymbolError struct {
	Symbol string
	Err    error
}

SymbolError reports that a symbol is not callable.

Err distinguishes the two ways that happens. A nil Err means the loaded library does not export the symbol, which is what an installation older than the symbol looks like. A non-nil Err means the library does export it and the binding itself failed; the library is not at fault.

func (*SymbolError) Error

func (e *SymbolError) Error() string

Error reports the uncallable library symbol and, when the symbol was present but could not be bound, why.

func (*SymbolError) Unwrap

func (e *SymbolError) Unwrap() error

Unwrap returns the reason the symbol could not be bound, or nil when the loaded library does not export it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL