Documentation
¶
Overview ¶
Package nvshmem binds the host-callable API of the NVSHMEM library, libnvshmem_host.so.3, using purego. NVSHMEM gives the processing elements (PEs) of a multi-GPU job a symmetric heap: an allocation that every PE makes at the same time and can address on every other PE.
Host and device ¶
NVSHMEM is two APIs that share one set of headers. Only one of them is here.
The device API is what most NVSHMEM code is written against: nvshmem_put, nvshmem_get, nvshmem_wait_until, the block- and warp-scoped collectives, the tile API. Those are __device__ functions. They are compiled into your CUDA kernels from libnvshmem_device.a and they execute on the GPU. There is no symbol for a program to call and no way for purego, cgo, or any other FFI mechanism to reach them: a function that runs on the device is not an entry point on the host. Device-side NVSHMEM code belongs in a .cu file compiled by nvcc against libnvshmem_device.a. Load the resulting cubin with the CUDA driver API, register it with CUModuleInit or CULibraryInit so NVSHMEM can patch its device state into the module, and launch it yourself.
The host API is what this package binds: everything libnvshmem_host.so.3 exports with C linkage. That is more than the name "host API" suggests. Alongside the setup and query calls, the host library exports host-callable remote memory access (PutMem, GetMem), signal operations, barriers, and collectives, both blocking and stream-ordered. A Go program can move data between PEs without writing a kernel at all.
What is deliberately not bound ¶
Three groups of declarations in the public headers are unreachable and are therefore absent from this package rather than present and broken.
nvshmem_init, nvshmem_init_thread, nvshmem_finalize and nvshmemx_init_attr are static inline functions in the headers. They call nvshmemi_init_thread and nvshmemi_finalize, which libnvshmem_host.so.3 compiles as C++ with local binding: the names are absent from its dynamic symbol table, so dlsym cannot find them under any spelling. Use InitWithUniqueID or InitWithMPIComm, which call the exported nvshmemx_hostlib_init_attr, and Finalize, which calls the exported nvshmemx_hostlib_finalize.
nvshmemx_collective_launch and nvshmemx_collective_launch_query_gridsize are unreachable for the same reason, and this one costs real functionality. A kernel that uses device-side NVSHMEM collectives or synchronization must be launched collectively, and from Go it cannot be. A kernel that only issues non-blocking device-side RMA can be launched normally, with the CUDA driver API, after CUModuleInit. If your kernel needs a collective launch, launch it from a C++ program, not this package.
The typed API - nvshmem_int_put, nvshmem_float_sum_reduce and roughly 1300 more - is host-exported and reachable, but is not bound. The byte-granular PutMem and GetMem cover the same ground for data movement. The typed reductions do not have a byte-granular equivalent; if you need one, bind it.
Bootstrap ¶
NVSHMEM cannot initialize alone. Before the symmetric heap exists, the PEs have to agree on how many of them there are and how to reach each other, and NVSHMEM delegates that to a bootstrap plugin it dlopens at init.
InitWithUniqueID uses nvshmem_bootstrap_uid.so.3, which links nothing outside libc and libstdc++ and needs no launcher. It is the path a Go program can drive end to end: one PE calls NewUniqueID, distributes the result to the others by whatever means you already have, and every PE calls InitWithUniqueID with its own rank, the total rank count, and that same ID. Distributing the ID is your job. NVSHMEM does not do it, and this package does not either.
InitWithMPIComm uses nvshmem_bootstrap_mpi.so.3, which links libmpi.so.40 - the Open MPI ABI. It takes an MPI communicator as an opaque pointer, so the process must already be an MPI rank under mpirun, and the MPI library in the process has to be the one the plugin was built against. Handle values are not portable across MPI implementations.
The remaining plugins NVSHMEM ships - PMI, PMI2, PMIx, and OpenSHMEM - are selected by environment and launcher, not by an argument to this package.
Every PE must select its CUDA device before initializing. NVSHMEM binds the symmetric heap to the current context's device.
Ownership ¶
Symmetric-heap addresses are device addresses and are spelled uintptr, not unsafe.Pointer, so that Go memory cannot be passed where a remote GPU will dereference it. Malloc, Calloc and Align return an address that is valid on every PE at the same offset and that only Free releases. Every PE must make the same allocation calls in the same order: these are collective, and a PE that skips one desynchronizes the heap for the whole job.
An address the caller passes to a stream-ordered or non-blocking operation must stay allocated until the operation completes - QuietOnStream or a CUDA stream synchronize for the former, Quiet for the latter. Returning from the call is not completion.
Host buffers registered with BufferRegister stay registered, and must stay mapped, until BufferUnregister. Pin any Go allocation for the whole interval; the library keeps the address.
Finalize tears down the symmetric heap and the transports. Every address Malloc returned is invalid afterwards, on every PE.
Availability ¶
The library is opened on first use, or by an explicit Load. Import does not open it. Each wrapper checks its own symbol, so a package built against 3.7.2 still runs against an older library: a call whose symbol is absent returns a *SymbolError rather than panicking. Has reports availability in advance. Set NVSHMEM_LIB_PATH, or pass a path to Load, to choose the library.
Generated by gen-nvshmem from the pinned NVSHMEM 3.7.2 public headers.
Symmetric heap ¶
- Align.
- Calloc.
- Free.
- Malloc.
- Ptr.
- BufferRegister.
- BufferRegisterSymmetric.
- BufferRegisterSymmetricAt.
- BufferUnregister.
- BufferUnregisterAll.
- BufferUnregisterSymmetric.
- MulticastPtr.
Collectives ¶
- AllToAllMem.
- BroadcastMem.
- FCollectMem.
- AllToAllMemOnStream.
- BroadcastMemOnStream.
- FCollectMemOnStream.
Synchronization ¶
- Barrier.
- BarrierAll.
- Fence.
- Quiet.
- SyncAll.
- BarrierAllOnStream.
- BarrierOnStream.
- Flush.
- FlushOnStream.
- QuietOnStream.
- SyncAllOnStream.
Remote memory access ¶
- GetMem.
- GetMemNBI.
- PutMem.
- PutMemNBI.
- SignalFetch.
- GetMemNBIOnStream.
- GetMemOnStream.
- PutMemNBIOnStream.
- PutMemOnStream.
- PutMemSignalNBIOnStream.
- PutMemSignalOnStream.
- SignalOpOnStream.
- SignalWaitUntilOnStream.
Library lifecycle ¶
PE and version queries ¶
Teams ¶
- TeamDestroy.
- TeamGetConfig.
- TeamMyPE.
- TeamNPEs.
- TeamSplit2D.
- TeamSplitStrided.
- TeamSync.
- TeamTranslatePE.
- TeamGetUniqueID.
- TeamInit.
- TeamSyncOnStream.
Device code registration ¶
Bootstrap ¶
Example (UniqueIDBootstrap) ¶
Every PE in a job calls the same sequence: agree on a unique ID, initialize with it, allocate symmetrically, and finalize. Distributing the ID from PE 0 to the others is the caller's job; NVSHMEM does not do it. Here it stands in as the distribute function.
This example does not run: it needs a multi-PE job with the library present.
package main
import (
"log"
"github.com/tmc/lib/nvidia/nvshmem"
)
func main() {
var distribute func(nvshmem.UniqueID) nvshmem.UniqueID
// Every PE learns its rank and the job size from the launcher.
pe, npes := 0, 2
var id nvshmem.UniqueID
if pe == 0 {
var err error
if id, err = nvshmem.NewUniqueID(); err != nil {
log.Fatal(err)
}
}
id = distribute(id)
if err := nvshmem.InitWithUniqueID(pe, npes, &id); err != nil {
log.Fatal(err)
}
defer nvshmem.Finalize()
// The allocation is collective: every PE makes it, at the same size, in
// the same order, and the address is valid on all of them.
buf, err := nvshmem.Malloc(4096)
if err != nil {
log.Fatal(err)
}
defer nvshmem.Free(buf)
nvshmem.BarrierAll()
me, err := nvshmem.MyPE()
if err != nil {
log.Fatal(err)
}
if me == 0 {
nvshmem.PutMem(buf, buf, 4096, 1)
nvshmem.Quiet()
}
nvshmem.BarrierAll()
}
Output:
Index ¶
- Constants
- func Align(alignment uint, size uint) (uintptr, error)
- func AllToAllMem(team Team, dest uintptr, src uintptr, nelems uint) error
- func AllToAllMemOnStream(team Team, dest uintptr, src uintptr, nelem uint, stream driver.Stream) error
- func Barrier(team Team) error
- func BarrierAll() error
- func BarrierAllOnStream(stream driver.Stream) error
- func BarrierOnStream(team Team, stream driver.Stream) error
- func BroadcastMem(team Team, dest uintptr, src uintptr, nelems uint, pERoot int32) error
- func BroadcastMemOnStream(team Team, dest uintptr, src uintptr, nelem uint, pERoot int32, ...) error
- func BufferRegister(addr uintptr, length uint) error
- func BufferRegisterSymmetric(bufPtr uintptr, size uint, flags int32) (uintptr, error)
- func BufferRegisterSymmetricAt(bufPtr uintptr, size uint, preferredAddr uintptr, flags int32) (uintptr, error)
- func BufferUnregister(addr uintptr) error
- func BufferUnregisterAll() error
- func BufferUnregisterSymmetric(mmapPtr uintptr, size uint) error
- func CULibraryFinalize(library driver.Library) error
- func CULibraryInit(library driver.Library) error
- func CUModuleFinalize(module driver.Module) error
- func CUModuleInit(module driver.Module) error
- func Calloc(count uint, size uint) (uintptr, error)
- func Close() error
- func FCollectMem(team Team, dest uintptr, src uintptr, nelems uint) error
- func FCollectMemOnStream(team Team, dest uintptr, src uintptr, nelem uint, stream driver.Stream) error
- func Fence() error
- func Finalize() error
- func Flush() error
- func FlushOnStream(cstrm driver.Stream) error
- func Free(ptr uintptr) error
- func GetMem(dest uintptr, source uintptr, bytes uint, pe int32) error
- func GetMemNBI(dest uintptr, source uintptr, bytes uint, pe int32) error
- func GetMemNBIOnStream(dest uintptr, source uintptr, bytes uint, pe int32, cstrm driver.Stream) error
- func GetMemOnStream(dest uintptr, source uintptr, bytes uint, pe int32, cstrm driver.Stream) error
- func GlobalExit(status int32) error
- func Has(symbol string) bool
- func HasAlign() bool
- func HasAllToAllMem() bool
- func HasAllToAllMemOnStream() bool
- func HasBarrier() bool
- func HasBarrierAll() bool
- func HasBarrierAllOnStream() bool
- func HasBarrierOnStream() bool
- func HasBroadcastMem() bool
- func HasBroadcastMemOnStream() bool
- func HasBufferRegister() bool
- func HasBufferRegisterSymmetric() bool
- func HasBufferRegisterSymmetricAt() bool
- func HasBufferUnregister() bool
- func HasBufferUnregisterAll() bool
- func HasBufferUnregisterSymmetric() bool
- func HasCULibraryFinalize() bool
- func HasCULibraryInit() bool
- func HasCUModuleFinalize() bool
- func HasCUModuleInit() bool
- func HasCalloc() bool
- func HasFCollectMem() bool
- func HasFCollectMemOnStream() bool
- func HasFence() bool
- func HasFlush() bool
- func HasFlushOnStream() bool
- func HasFree() bool
- func HasGetMem() bool
- func HasGetMemNBI() bool
- func HasGetMemNBIOnStream() bool
- func HasGetMemOnStream() bool
- func HasGetUniqueID() bool
- func HasGlobalExit() bool
- func HasHostlibFinalize() bool
- func HasHostlibInitAttr() bool
- func HasInfoGetNameRaw() bool
- func HasInfoGetVersionRaw() bool
- func HasMalloc() bool
- func HasMulticastPtr() bool
- func HasMyPE() bool
- func HasNPEs() bool
- func HasPtr() bool
- func HasPutMem() bool
- func HasPutMemNBI() bool
- func HasPutMemNBIOnStream() bool
- func HasPutMemOnStream() bool
- func HasPutMemSignalNBIOnStream() bool
- func HasPutMemSignalOnStream() bool
- func HasQueryInitStatus() bool
- func HasQueryThreadRaw() bool
- func HasQuiet() bool
- func HasQuietOnStream() bool
- func HasSetAttrMPICommArgs() bool
- func HasSetAttrUniqueIDArgs() bool
- func HasSignalFetch() bool
- func HasSignalOpOnStream() bool
- func HasSignalWaitUntilOnStream() bool
- func HasSyncAll() bool
- func HasSyncAllOnStream() bool
- func HasTeamDestroy() bool
- func HasTeamGetConfig() bool
- func HasTeamGetUniqueID() bool
- func HasTeamInit() bool
- func HasTeamMyPE() bool
- func HasTeamNPEs() bool
- func HasTeamSplit2D() bool
- func HasTeamSplitStrided() bool
- func HasTeamSync() bool
- func HasTeamSyncOnStream() bool
- func HasTeamTranslatePE() bool
- func HasVendorGetVersionInfoRaw() bool
- func HostlibInit(flags InitFlags, attr *InitAttr) error
- func InfoGetVersion() (major, minor int, err error)
- func InitWithMPIComm(comm unsafe.Pointer) error
- func InitWithUniqueID(pe, npes int, id *UniqueID) error
- func Initialized() bool
- func Load(path string) error
- func Loaded() bool
- func Malloc(size uint) (uintptr, error)
- func MulticastPtr(team Team, ptr uintptr) (uintptr, error)
- func MyPE() (int32, error)
- func NPEs() (int32, error)
- func Name() (string, error)
- func Path() string
- func Ptr(ptr uintptr, pe int32) (uintptr, error)
- func PutMem(dest uintptr, source uintptr, bytes uint, pe int32) error
- func PutMemNBI(dest uintptr, source uintptr, bytes uint, pe int32) error
- func PutMemNBIOnStream(dest uintptr, source uintptr, bytes uint, pe int32, cstrm driver.Stream) error
- func PutMemOnStream(dest uintptr, source uintptr, bytes uint, pe int32, cstrm driver.Stream) error
- func PutMemSignalNBIOnStream(dest uintptr, source uintptr, bytes uint, sigAddr uintptr, signal uint64, ...) error
- func PutMemSignalOnStream(dest uintptr, source uintptr, bytes uint, sigAddr uintptr, signal uint64, ...) error
- func Quiet() error
- func QuietOnStream(cstrm driver.Stream) error
- func SetAttrMPICommArgs(mpiComm unsafe.Pointer, nvshmemAttr *InitAttr) error
- func SetAttrUniqueIDArgs(myrank int32, nranks int32, uniqueid *UniqueID, attr *InitAttr) error
- func SignalFetch(sigAddr uintptr) (uint64, error)
- func SignalOpOnStream(sigAddr uintptr, signal uint64, sigOp SignalOp, pe int32, cstrm driver.Stream) error
- func SignalWaitUntilOnStream(sigAddr uintptr, cmp CmpType, cmpValue uint64, cstream driver.Stream) error
- func Symbols() []string
- func SyncAll() error
- func SyncAllOnStream(stream driver.Stream) error
- func TeamDestroy(team Team) error
- func TeamGetConfig(team Team, config *TeamConfig) error
- func TeamGetUniqueID() (uint64, error)
- func TeamInit(team *Team, config *TeamConfig, configMask int, npes int32, peIdxInTeam int32) error
- func TeamMyPE(team Team) (int32, error)
- func TeamNPEs(team Team) (int32, error)
- func TeamSplit2D(parentTeam Team, xrange int32, xaxisConfig *TeamConfig, xaxisMask int, ...) error
- func TeamSync(team Team) error
- func TeamSyncOnStream(team Team, stream driver.Stream) error
- func TeamTranslatePE(srcTeam Team, srcPe int32, destTeam Team) (int32, error)
- func VendorVersion() (major, minor, patch int, err error)
- type BindFailure
- type CallError
- type CmpType
- type InitArgs
- type InitArgsV2
- type InitAttr
- type InitAttrV2
- type InitFlags
- type InitStatus
- type LibraryAttempt
- type LibraryConflictError
- type LibraryError
- type SignalOp
- type Status
- type SymbolError
- type Team
- type TeamConfig
- type TeamConfigV2
- type ThreadSupport
- type UniqueID
- type UniqueIDArgs
- type UniqueIDArgsV1
- type UniqueIDV1
Examples ¶
Constants ¶
const MaxNameLen = 256
MaxNameLen is NVSHMEM_MAX_NAME_LEN, the buffer size nvshmem_info_get_name writes into.
Variables ¶
This section is empty.
Functions ¶
func AllToAllMem ¶
AllToAllMem wraps nvshmem_alltoallmem.
func AllToAllMemOnStream ¶
func AllToAllMemOnStream(team Team, dest uintptr, src uintptr, nelem uint, stream driver.Stream) error
AllToAllMemOnStream wraps nvshmemx_alltoallmem_on_stream.
func BarrierAll ¶
func BarrierAll() error
BarrierAll wraps nvshmem_barrier_all. The error reports an unavailable library or symbol.
func BarrierAllOnStream ¶
BarrierAllOnStream wraps nvshmemx_barrier_all_on_stream. The error reports an unavailable library or symbol.
func BarrierOnStream ¶
BarrierOnStream wraps nvshmemx_barrier_on_stream.
func BroadcastMem ¶
BroadcastMem wraps nvshmem_broadcastmem.
func BroadcastMemOnStream ¶
func BroadcastMemOnStream(team Team, dest uintptr, src uintptr, nelem uint, pERoot int32, stream driver.Stream) error
BroadcastMemOnStream wraps nvshmemx_broadcastmem_on_stream.
func BufferRegister ¶
BufferRegister wraps nvshmemx_buffer_register.
func BufferRegisterSymmetric ¶
BufferRegisterSymmetric wraps nvshmemx_buffer_register_symmetric. The error reports an unavailable library or symbol.
func BufferRegisterSymmetricAt ¶
func BufferRegisterSymmetricAt(bufPtr uintptr, size uint, preferredAddr uintptr, flags int32) (uintptr, error)
BufferRegisterSymmetricAt wraps nvshmemx_buffer_register_symmetric_at_preferred_address. The error reports an unavailable library or symbol.
func BufferUnregister ¶
BufferUnregister wraps nvshmemx_buffer_unregister.
func BufferUnregisterAll ¶
func BufferUnregisterAll() error
BufferUnregisterAll wraps nvshmemx_buffer_unregister_all. The error reports an unavailable library or symbol.
func BufferUnregisterSymmetric ¶
BufferUnregisterSymmetric wraps nvshmemx_buffer_unregister_symmetric.
func CULibraryFinalize ¶
CULibraryFinalize wraps nvshmemx_culibrary_finalize.
func CULibraryInit ¶
CULibraryInit wraps nvshmemx_culibrary_init.
func CUModuleFinalize ¶
CUModuleFinalize wraps nvshmemx_cumodule_finalize.
func CUModuleInit ¶
CUModuleInit wraps nvshmemx_cumodule_init.
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 FCollectMem ¶
FCollectMem wraps nvshmem_fcollectmem.
func FCollectMemOnStream ¶
func FCollectMemOnStream(team Team, dest uintptr, src uintptr, nelem uint, stream driver.Stream) error
FCollectMemOnStream wraps nvshmemx_fcollectmem_on_stream.
func Fence ¶
func Fence() error
Fence wraps nvshmem_fence. The error reports an unavailable library or symbol.
func Finalize ¶
func Finalize() error
Finalize shuts NVSHMEM down. It is collective: every PE calls it.
Every address Malloc, Calloc or Align returned becomes invalid, on every PE. Complete or abandon all outstanding work first - a stream-ordered operation still in flight is reading memory this call frees.
Finalize calls the exported nvshmemx_hostlib_finalize. The header's nvshmem_finalize is a static inline over a symbol that is not exported and so is not reachable from Go.
func Flush ¶
func Flush() error
Flush wraps nvshmemx_flush. The error reports an unavailable library or symbol.
func FlushOnStream ¶
FlushOnStream wraps nvshmemx_flush_on_stream. The error reports an unavailable library or symbol.
func GetMemNBI ¶
GetMemNBI wraps nvshmem_getmem_nbi. The error reports an unavailable library or symbol.
func GetMemNBIOnStream ¶
func GetMemNBIOnStream(dest uintptr, source uintptr, bytes uint, pe int32, cstrm driver.Stream) error
GetMemNBIOnStream wraps nvshmemx_getmem_nbi_on_stream. The error reports an unavailable library or symbol.
func GetMemOnStream ¶
GetMemOnStream wraps nvshmemx_getmem_on_stream. The error reports an unavailable library or symbol.
func GlobalExit ¶
GlobalExit wraps nvshmem_global_exit. The error reports an unavailable library or symbol.
func Has ¶
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 HasAlign ¶
func HasAlign() bool
HasAlign reports whether nvshmem_align resolved in the loaded library.
func HasAllToAllMem ¶
func HasAllToAllMem() bool
HasAllToAllMem reports whether nvshmem_alltoallmem resolved in the loaded library.
func HasAllToAllMemOnStream ¶
func HasAllToAllMemOnStream() bool
HasAllToAllMemOnStream reports whether nvshmemx_alltoallmem_on_stream resolved in the loaded library.
func HasBarrier ¶
func HasBarrier() bool
HasBarrier reports whether nvshmem_barrier resolved in the loaded library.
func HasBarrierAll ¶
func HasBarrierAll() bool
HasBarrierAll reports whether nvshmem_barrier_all resolved in the loaded library.
func HasBarrierAllOnStream ¶
func HasBarrierAllOnStream() bool
HasBarrierAllOnStream reports whether nvshmemx_barrier_all_on_stream resolved in the loaded library.
func HasBarrierOnStream ¶
func HasBarrierOnStream() bool
HasBarrierOnStream reports whether nvshmemx_barrier_on_stream resolved in the loaded library.
func HasBroadcastMem ¶
func HasBroadcastMem() bool
HasBroadcastMem reports whether nvshmem_broadcastmem resolved in the loaded library.
func HasBroadcastMemOnStream ¶
func HasBroadcastMemOnStream() bool
HasBroadcastMemOnStream reports whether nvshmemx_broadcastmem_on_stream resolved in the loaded library.
func HasBufferRegister ¶
func HasBufferRegister() bool
HasBufferRegister reports whether nvshmemx_buffer_register resolved in the loaded library.
func HasBufferRegisterSymmetric ¶
func HasBufferRegisterSymmetric() bool
HasBufferRegisterSymmetric reports whether nvshmemx_buffer_register_symmetric resolved in the loaded library.
func HasBufferRegisterSymmetricAt ¶
func HasBufferRegisterSymmetricAt() bool
HasBufferRegisterSymmetricAt reports whether nvshmemx_buffer_register_symmetric_at_preferred_address resolved in the loaded library.
func HasBufferUnregister ¶
func HasBufferUnregister() bool
HasBufferUnregister reports whether nvshmemx_buffer_unregister resolved in the loaded library.
func HasBufferUnregisterAll ¶
func HasBufferUnregisterAll() bool
HasBufferUnregisterAll reports whether nvshmemx_buffer_unregister_all resolved in the loaded library.
func HasBufferUnregisterSymmetric ¶
func HasBufferUnregisterSymmetric() bool
HasBufferUnregisterSymmetric reports whether nvshmemx_buffer_unregister_symmetric resolved in the loaded library.
func HasCULibraryFinalize ¶
func HasCULibraryFinalize() bool
HasCULibraryFinalize reports whether nvshmemx_culibrary_finalize resolved in the loaded library.
func HasCULibraryInit ¶
func HasCULibraryInit() bool
HasCULibraryInit reports whether nvshmemx_culibrary_init resolved in the loaded library.
func HasCUModuleFinalize ¶
func HasCUModuleFinalize() bool
HasCUModuleFinalize reports whether nvshmemx_cumodule_finalize resolved in the loaded library.
func HasCUModuleInit ¶
func HasCUModuleInit() bool
HasCUModuleInit reports whether nvshmemx_cumodule_init resolved in the loaded library.
func HasCalloc ¶
func HasCalloc() bool
HasCalloc reports whether nvshmem_calloc resolved in the loaded library.
func HasFCollectMem ¶
func HasFCollectMem() bool
HasFCollectMem reports whether nvshmem_fcollectmem resolved in the loaded library.
func HasFCollectMemOnStream ¶
func HasFCollectMemOnStream() bool
HasFCollectMemOnStream reports whether nvshmemx_fcollectmem_on_stream resolved in the loaded library.
func HasFence ¶
func HasFence() bool
HasFence reports whether nvshmem_fence resolved in the loaded library.
func HasFlush ¶
func HasFlush() bool
HasFlush reports whether nvshmemx_flush resolved in the loaded library.
func HasFlushOnStream ¶
func HasFlushOnStream() bool
HasFlushOnStream reports whether nvshmemx_flush_on_stream resolved in the loaded library.
func HasFree ¶
func HasFree() bool
HasFree reports whether nvshmem_free resolved in the loaded library.
func HasGetMem ¶
func HasGetMem() bool
HasGetMem reports whether nvshmem_getmem resolved in the loaded library.
func HasGetMemNBI ¶
func HasGetMemNBI() bool
HasGetMemNBI reports whether nvshmem_getmem_nbi resolved in the loaded library.
func HasGetMemNBIOnStream ¶
func HasGetMemNBIOnStream() bool
HasGetMemNBIOnStream reports whether nvshmemx_getmem_nbi_on_stream resolved in the loaded library.
func HasGetMemOnStream ¶
func HasGetMemOnStream() bool
HasGetMemOnStream reports whether nvshmemx_getmem_on_stream resolved in the loaded library.
func HasGetUniqueID ¶
func HasGetUniqueID() bool
HasGetUniqueID reports whether nvshmemx_get_uniqueid resolved in the loaded library.
func HasGlobalExit ¶
func HasGlobalExit() bool
HasGlobalExit reports whether nvshmem_global_exit resolved in the loaded library.
func HasHostlibFinalize ¶
func HasHostlibFinalize() bool
HasHostlibFinalize reports whether nvshmemx_hostlib_finalize resolved in the loaded library.
func HasHostlibInitAttr ¶
func HasHostlibInitAttr() bool
HasHostlibInitAttr reports whether nvshmemx_hostlib_init_attr resolved in the loaded library.
func HasInfoGetNameRaw ¶
func HasInfoGetNameRaw() bool
HasInfoGetNameRaw reports whether nvshmem_info_get_name resolved in the loaded library.
func HasInfoGetVersionRaw ¶
func HasInfoGetVersionRaw() bool
HasInfoGetVersionRaw reports whether nvshmem_info_get_version resolved in the loaded library.
func HasMalloc ¶
func HasMalloc() bool
HasMalloc reports whether nvshmem_malloc resolved in the loaded library.
func HasMulticastPtr ¶
func HasMulticastPtr() bool
HasMulticastPtr reports whether nvshmemx_mc_ptr resolved in the loaded library.
func HasMyPE ¶
func HasMyPE() bool
HasMyPE reports whether nvshmem_my_pe resolved in the loaded library.
func HasNPEs ¶
func HasNPEs() bool
HasNPEs reports whether nvshmem_n_pes resolved in the loaded library.
func HasPutMem ¶
func HasPutMem() bool
HasPutMem reports whether nvshmem_putmem resolved in the loaded library.
func HasPutMemNBI ¶
func HasPutMemNBI() bool
HasPutMemNBI reports whether nvshmem_putmem_nbi resolved in the loaded library.
func HasPutMemNBIOnStream ¶
func HasPutMemNBIOnStream() bool
HasPutMemNBIOnStream reports whether nvshmemx_putmem_nbi_on_stream resolved in the loaded library.
func HasPutMemOnStream ¶
func HasPutMemOnStream() bool
HasPutMemOnStream reports whether nvshmemx_putmem_on_stream resolved in the loaded library.
func HasPutMemSignalNBIOnStream ¶
func HasPutMemSignalNBIOnStream() bool
HasPutMemSignalNBIOnStream reports whether nvshmemx_putmem_signal_nbi_on_stream resolved in the loaded library.
func HasPutMemSignalOnStream ¶
func HasPutMemSignalOnStream() bool
HasPutMemSignalOnStream reports whether nvshmemx_putmem_signal_on_stream resolved in the loaded library.
func HasQueryInitStatus ¶
func HasQueryInitStatus() bool
HasQueryInitStatus reports whether nvshmemx_init_status resolved in the loaded library.
func HasQueryThreadRaw ¶
func HasQueryThreadRaw() bool
HasQueryThreadRaw reports whether nvshmem_query_thread resolved in the loaded library.
func HasQuiet ¶
func HasQuiet() bool
HasQuiet reports whether nvshmem_quiet resolved in the loaded library.
func HasQuietOnStream ¶
func HasQuietOnStream() bool
HasQuietOnStream reports whether nvshmemx_quiet_on_stream resolved in the loaded library.
func HasSetAttrMPICommArgs ¶
func HasSetAttrMPICommArgs() bool
HasSetAttrMPICommArgs reports whether nvshmemx_set_attr_mpi_comm_args resolved in the loaded library.
func HasSetAttrUniqueIDArgs ¶
func HasSetAttrUniqueIDArgs() bool
HasSetAttrUniqueIDArgs reports whether nvshmemx_set_attr_uniqueid_args resolved in the loaded library.
func HasSignalFetch ¶
func HasSignalFetch() bool
HasSignalFetch reports whether nvshmem_signal_fetch resolved in the loaded library.
func HasSignalOpOnStream ¶
func HasSignalOpOnStream() bool
HasSignalOpOnStream reports whether nvshmemx_signal_op_on_stream resolved in the loaded library.
func HasSignalWaitUntilOnStream ¶
func HasSignalWaitUntilOnStream() bool
HasSignalWaitUntilOnStream reports whether nvshmemx_signal_wait_until_on_stream resolved in the loaded library.
func HasSyncAll ¶
func HasSyncAll() bool
HasSyncAll reports whether nvshmem_sync_all resolved in the loaded library.
func HasSyncAllOnStream ¶
func HasSyncAllOnStream() bool
HasSyncAllOnStream reports whether nvshmemx_sync_all_on_stream resolved in the loaded library.
func HasTeamDestroy ¶
func HasTeamDestroy() bool
HasTeamDestroy reports whether nvshmem_team_destroy resolved in the loaded library.
func HasTeamGetConfig ¶
func HasTeamGetConfig() bool
HasTeamGetConfig reports whether nvshmem_team_get_config resolved in the loaded library.
func HasTeamGetUniqueID ¶
func HasTeamGetUniqueID() bool
HasTeamGetUniqueID reports whether nvshmemx_team_get_uniqueid resolved in the loaded library.
func HasTeamInit ¶
func HasTeamInit() bool
HasTeamInit reports whether nvshmemx_team_init resolved in the loaded library.
func HasTeamMyPE ¶
func HasTeamMyPE() bool
HasTeamMyPE reports whether nvshmem_team_my_pe resolved in the loaded library.
func HasTeamNPEs ¶
func HasTeamNPEs() bool
HasTeamNPEs reports whether nvshmem_team_n_pes resolved in the loaded library.
func HasTeamSplit2D ¶
func HasTeamSplit2D() bool
HasTeamSplit2D reports whether nvshmem_team_split_2d resolved in the loaded library.
func HasTeamSplitStrided ¶
func HasTeamSplitStrided() bool
HasTeamSplitStrided reports whether nvshmem_team_split_strided resolved in the loaded library.
func HasTeamSync ¶
func HasTeamSync() bool
HasTeamSync reports whether nvshmem_team_sync resolved in the loaded library.
func HasTeamSyncOnStream ¶
func HasTeamSyncOnStream() bool
HasTeamSyncOnStream reports whether nvshmemx_team_sync_on_stream resolved in the loaded library.
func HasTeamTranslatePE ¶
func HasTeamTranslatePE() bool
HasTeamTranslatePE reports whether nvshmem_team_translate_pe resolved in the loaded library.
func HasVendorGetVersionInfoRaw ¶
func HasVendorGetVersionInfoRaw() bool
HasVendorGetVersionInfoRaw reports whether nvshmemx_vendor_get_version_info resolved in the loaded library.
func HostlibInit ¶
HostlibInit calls nvshmemx_hostlib_init_attr directly, for a bootstrap the named constructors do not cover - the PMI, PMI2, PMIx and OpenSHMEM plugins, which NVSHMEM selects from the environment and the launcher.
attr must be initialized by NewInitAttr and then filled in; a zero InitAttr has no version stamp and the library rejects it. Most callers want InitWithUniqueID or InitWithMPIComm.
func InfoGetVersion ¶
InfoGetVersion returns the OpenSHMEM specification version NVSHMEM implements. It is not the NVSHMEM release version; see VendorVersion.
func InitWithMPIComm ¶
InitWithMPIComm initializes NVSHMEM using the MPI bootstrap, with comm as the MPI communicator spanning the PEs.
comm is the address of an MPI_Comm as the process's own MPI library spells it, passed opaquely. The process must already be an MPI rank, and the MPI library loaded into it must be the one nvshmem_bootstrap_mpi.so.3 was built against - it links libmpi.so.40, the Open MPI ABI. Communicator values are not portable between MPI implementations, so handing this a handle from a different implementation is undefined, not an error.
The library reads through comm during the call. Keep whatever it points at alive and unmoved for the duration.
func InitWithUniqueID ¶
InitWithUniqueID initializes NVSHMEM using the unique-ID bootstrap.
Every PE calls it, with the same id and the same npes, and with its own pe in [0, npes). The call is collective and blocks until every PE has arrived; a PE that never calls it hangs the rest.
This is the only bootstrap a standalone Go program can drive: the plugin it uses, nvshmem_bootstrap_uid.so.3, links nothing outside libc and libstdc++ and needs no launcher. Getting the id to every PE is the caller's problem; see NewUniqueID.
The calling thread must already have a current CUDA context on the device this PE will use. NVSHMEM binds the symmetric heap to that device.
The library keeps no reference to id after the call returns.
func Initialized ¶
func Initialized() bool
Initialized reports whether this PE has completed initialization, by checking InitStatus against StatusIsInitialized. It reports false if the library cannot be loaded.
func Load ¶
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 MulticastPtr ¶
MulticastPtr wraps nvshmemx_mc_ptr. The error reports an unavailable library or symbol.
func Name ¶
Name returns the vendor name string, "NVSHMEM".
The C function writes into a caller-supplied buffer with no length argument and no bound other than the header's NVSHMEM_MAX_NAME_LEN, so the buffer here is that size and the result is truncated at the first NUL.
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 PutMemNBI ¶
PutMemNBI wraps nvshmem_putmem_nbi. The error reports an unavailable library or symbol.
func PutMemNBIOnStream ¶
func PutMemNBIOnStream(dest uintptr, source uintptr, bytes uint, pe int32, cstrm driver.Stream) error
PutMemNBIOnStream wraps nvshmemx_putmem_nbi_on_stream. The error reports an unavailable library or symbol.
func PutMemOnStream ¶
PutMemOnStream wraps nvshmemx_putmem_on_stream. The error reports an unavailable library or symbol.
func PutMemSignalNBIOnStream ¶
func PutMemSignalNBIOnStream(dest uintptr, source uintptr, bytes uint, sigAddr uintptr, signal uint64, sigOp SignalOp, pe int32, cstrm driver.Stream) error
PutMemSignalNBIOnStream wraps nvshmemx_putmem_signal_nbi_on_stream. The error reports an unavailable library or symbol.
func PutMemSignalOnStream ¶
func PutMemSignalOnStream(dest uintptr, source uintptr, bytes uint, sigAddr uintptr, signal uint64, sigOp SignalOp, pe int32, cstrm driver.Stream) error
PutMemSignalOnStream wraps nvshmemx_putmem_signal_on_stream. The error reports an unavailable library or symbol.
func Quiet ¶
func Quiet() error
Quiet wraps nvshmem_quiet. The error reports an unavailable library or symbol.
func QuietOnStream ¶
QuietOnStream wraps nvshmemx_quiet_on_stream. The error reports an unavailable library or symbol.
func SetAttrMPICommArgs ¶
SetAttrMPICommArgs wraps nvshmemx_set_attr_mpi_comm_args.
func SetAttrUniqueIDArgs ¶
SetAttrUniqueIDArgs wraps nvshmemx_set_attr_uniqueid_args.
func SignalFetch ¶
SignalFetch wraps nvshmem_signal_fetch. The error reports an unavailable library or symbol.
func SignalOpOnStream ¶
func SignalOpOnStream(sigAddr uintptr, signal uint64, sigOp SignalOp, pe int32, cstrm driver.Stream) error
SignalOpOnStream wraps nvshmemx_signal_op_on_stream. The error reports an unavailable library or symbol.
func SignalWaitUntilOnStream ¶
func SignalWaitUntilOnStream(sigAddr uintptr, cmp CmpType, cmpValue uint64, cstream driver.Stream) error
SignalWaitUntilOnStream wraps nvshmemx_signal_wait_until_on_stream. The error reports an unavailable library or symbol.
func Symbols ¶
func Symbols() []string
Symbols returns the C symbols this package binds, in API order.
The list is what the package looks for in the library, not what it found. Use Has to ask whether one resolved: a library older than the pinned headers can be missing any of them, and the wrapper for a missing symbol returns a *SymbolError.
Example ¶
Symbols lists the C entry points the package binds. It is the package's own account of its surface and needs neither the library nor a GPU.
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/nvshmem"
)
func main() {
syms := nvshmem.Symbols()
fmt.Println(len(syms) > 0, syms[0])
}
Output: true nvshmemx_hostlib_init_attr
func SyncAll ¶
func SyncAll() error
SyncAll wraps nvshmem_sync_all. The error reports an unavailable library or symbol.
func SyncAllOnStream ¶
SyncAllOnStream wraps nvshmemx_sync_all_on_stream. The error reports an unavailable library or symbol.
func TeamDestroy ¶
TeamDestroy wraps nvshmem_team_destroy. The error reports an unavailable library or symbol.
func TeamGetConfig ¶
func TeamGetConfig(team Team, config *TeamConfig) error
TeamGetConfig wraps nvshmem_team_get_config. The error reports an unavailable library or symbol.
func TeamGetUniqueID ¶
TeamGetUniqueID wraps nvshmemx_team_get_uniqueid.
func TeamMyPE ¶
TeamMyPE wraps nvshmem_team_my_pe. The error reports an unavailable library or symbol.
func TeamNPEs ¶
TeamNPEs wraps nvshmem_team_n_pes. The error reports an unavailable library or symbol.
func TeamSplit2D ¶
func TeamSplit2D(parentTeam Team, xrange int32, xaxisConfig *TeamConfig, xaxisMask int, xaxisTeam *Team, yaxisConfig *TeamConfig, yaxisMask int, yaxisTeam *Team) error
TeamSplit2D wraps nvshmem_team_split_2d.
func TeamSyncOnStream ¶
TeamSyncOnStream wraps nvshmemx_team_sync_on_stream.
func TeamTranslatePE ¶
TeamTranslatePE wraps nvshmem_team_translate_pe. The error reports an unavailable library or symbol.
func VendorVersion ¶
VendorVersion returns the NVSHMEM release version.
Types ¶
type BindFailure ¶
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 ¶
CallError reports that a library call returned a failure status.
Unwrap returns Result, so errors.Is(err, c) matches a Status constant c and errors.As(err, &s) with s a Status recovers the code.
type InitArgs ¶
type InitArgs struct {
Version int32
UIDArgs UniqueIDArgs
CUDADeviceID int32
Content [92]byte
}
InitArgs represents nvshmemx_init_args_v2.
type InitAttr ¶
InitAttr represents nvshmemx_init_attr_v2.
func NewInitAttr ¶
func NewInitAttr() InitAttr
NewInitAttr returns an init attribute stamped with the descriptor version the library expects, matching the C NVSHMEMX_INIT_ATTR_INITIALIZER.
A zero InitAttr is not usable: the library reads the version fields to decide how to interpret the rest. Pass the result to SetAttrUniqueIDArgs or SetAttrMPICommArgs before HostlibInit, or use InitWithUniqueID or InitWithMPIComm, which do this for you.
type InitStatus ¶
type InitStatus int32
InitStatus represents nvshmemx_init_status_t.
const ( StatusNotInitialized InitStatus = 0 StatusIsBootstrapped InitStatus = 1 StatusIsInitialized InitStatus = 2 StatusLimitedMpg InitStatus = 3 StatusFullMpg InitStatus = 4 StatusInvalid InitStatus = 2147483647 )
func QueryInitStatus ¶
func QueryInitStatus() (InitStatus, error)
QueryInitStatus wraps nvshmemx_init_status. The error reports an unavailable library or symbol.
func (InitStatus) String ¶
func (e InitStatus) String() string
String returns the constant name, or a numeric representation for unknown values.
type LibraryAttempt ¶
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 libnvshmem_host could not be opened. Attempts lists every name tried in order. Path is set when an explicit path, from Load or NVSHMEM_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 Status ¶
type Status int32
Status is the completion status of an NVSHMEM call.
The C API returns it as a plain int. Success is zero and every other value is a failure. The named constants are the nvshmemx_status enumerators of the pinned headers; NVSHMEM does not promise that a status is one of them, so treat an unnamed value as a failure rather than as impossible.
Status implements error, and every wrapper that returns error returns either nil or a non-zero Status.
const ( // Success reports that the call completed. Success Status = 0 // ErrorInvalidValue reports an argument NVSHMEM rejected. ErrorInvalidValue Status = 1 // ErrorOutOfMemory reports exhausted symmetric heap or host memory. ErrorOutOfMemory Status = 2 // ErrorNotSupported reports an operation this build or this hardware // does not implement. ErrorNotSupported Status = 3 // ErrorSymmetry reports that the PEs did not make the same collective // call with matching arguments. ErrorSymmetry Status = 4 // ErrorGPUNotSelected reports that no CUDA device was current when // NVSHMEM needed one. Select a device before initializing. ErrorGPUNotSelected Status = 5 // ErrorCollectiveLaunchFailed reports a failed collective kernel launch. // This package cannot launch one; see the package documentation. ErrorCollectiveLaunchFailed Status = 6 // ErrorInternal reports a failure NVSHMEM did not classify. ErrorInternal Status = 7 )
NVSHMEM status codes, from enum nvshmemx_status.
type SymbolError ¶
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.
type Team ¶
type Team int32
Team identifies a set of PEs that take part in a collective together.
It is nvshmem_team_t: an int32 index into the library's team table, not a pointer and not something a caller owns. TeamWorld is every PE in the job and is also the zero value. Derive a team with TeamSplitStrided or TeamSplit2D and release it with TeamDestroy; the predefined teams below are not released.
const ( // TeamInvalid is the zero-ish sentinel for no team. It is not the Go zero // value of [Team]: that is [TeamWorld]. TeamInvalid Team = -1 // TeamWorld is every PE in the job. TeamWorld Team = 0 TeamShared Team = 1 // TeamNode is the PEs on this node. TeamNode Team = 2 // TeamSameMyPENode is the PEs with the same node-local index. TeamSameMyPENode Team = 3 TeamMCShared Team = 6 )
Predefined teams, from enum nvshmem_team_id_t. A team is an index into the library's team table, not a pointer, so these are ordinary values and none of them is destroyed by TeamDestroy.
func TeamSplitStrided ¶
func TeamSplitStrided(parentTeam Team, pEStart int32, pEStride int32, pESize int32, config *TeamConfig, configMask int) (Team, error)
TeamSplitStrided wraps nvshmem_team_split_strided.
type TeamConfig ¶
TeamConfig represents nvshmem_team_config_v2.
func NewTeamConfig ¶
func NewTeamConfig() TeamConfig
NewTeamConfig returns a team configuration stamped with its descriptor version. Set NumContexts and pass the corresponding mask bit to TeamSplitStrided or TeamSplit2D; a zero mask leaves every field at the library's default.
type ThreadSupport ¶
type ThreadSupport int32
ThreadSupport represents nvshmemx_thread_support_t.
const ( ThreadSingle ThreadSupport = 0 ThreadFunneled ThreadSupport = 1 ThreadSerialized ThreadSupport = 2 ThreadMultiple ThreadSupport = 3 ThreadTypeSentinel ThreadSupport = 2147483647 )
func QueryThread ¶
func QueryThread() (ThreadSupport, error)
QueryThread returns the thread support level NVSHMEM is providing.
func (ThreadSupport) String ¶
func (e ThreadSupport) String() string
String returns the constant name, or a numeric representation for unknown values.
type UniqueID ¶
UniqueID represents nvshmemx_uniqueid_v1.
func NewUniqueID ¶
NewUniqueID asks the library for a bootstrap unique ID.
Exactly one PE calls it. That PE must then distribute the returned ID to every other PE by some means of its own - a socket, a file, an existing launcher - before any PE calls InitWithUniqueID. NVSHMEM does not distribute it and neither does this package.
The ID is a value, not a handle: it owns nothing and needs no release.
func NewUniqueIDValue ¶
func NewUniqueIDValue() UniqueID
NewUniqueIDValue returns a zeroed unique ID stamped with its descriptor version, matching the C NVSHMEMX_UNIQUEID_INITIALIZER.
It carries no bootstrap information. Only NewUniqueID, which calls the library, produces an ID that PEs can rendezvous on.
type UniqueIDArgs ¶
UniqueIDArgs represents nvshmemx_uniqueid_args_v1.
type UniqueIDArgsV1 ¶
type UniqueIDArgsV1 = UniqueIDArgs
UniqueIDArgsV1 is an alias for UniqueIDArgs.