gdrcopy

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: 12 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.

Documentation

Overview

Package gdrcopy provides Go bindings for GDRCopy's libgdrapi, NVIDIA's user-space interface to the gdrdrv kernel module for mapping GPU memory into a process's address space.

Pin device memory with Handle.PinBuffer, map it with Handle.Map, and move bytes with MemHandle.CopyToMapping and MemHandle.CopyFromMapping.

Release order

gdrapi.h requires releases in the reverse of the order they were taken: unmap before unpin, unpin before close. Unpinning a mapped handle leaves the process holding an mmap of an aperture the driver has released, which the library does not detect. This package tracks what it created and returns ErrMapped rather than making the call, so the order is enforced for handles obtained through it. Handle.Close is the one relaxation: gdr_close unpins whatever is left, so pinned-but-unmapped handles need no unpinning first, but a live mapping still refuses the close.

Alignment and offsets

The kernel module pins whole GPU pages. It aligns the address down to GPUPageSize and rounds the length up, so a pinning generally begins below the address that was pinned and a mapping begins at that lower address. Handle.Map returns the base of the mapping, not the address of the caller's data: read Info.Va from Handle.GetInfoV2 and use Info.Offset to find where the data starts inside it.

Mappings are not memory

The address Handle.Map returns is an mmap of a device aperture. Do not build a Go slice on it and do not load or store through it directly. MemHandle.CopyToMapping and MemHandle.CopyFromMapping run the per-architecture copy paths libgdrapi implements for these mappings and issue the fences they require. Neither orders the copy against GPU work already launched.

Errors

gdrcopy has no status enum. Its calls return POSIX error numbers, which this package reports as *Error wrapping a syscall.Errno, so errors.Is works against the errno directly. When libgdrapi is absent, or is older than a symbol being called, every entry point returns an error (*LibraryError or *SymbolError) rather than panicking or reporting a success it did not have.

Requirements

Linux, libgdrapi.so.2 on the loader path (or named by GDRCOPY_LIB_PATH), and either the gdrdrv kernel module or a CUDA driver whose device supports dma-buf mmap. Open reports ErrOpen when it has neither.

These bindings were generated from the gdrapi.h of the release linked below, which cmd/gen-gdrcopy vendors and pins.

Example

Example shows the whole lifecycle: open, pin, map, copy, and then release in the reverse order, which is what gdrapi.h requires.

devicePtr is a CUDA device address, from cuMemAlloc or an equivalent. The kernel module pins whole GPU pages, so the mapping generally starts below that address and the data is at an offset inside it; Info reports where.

package main

import (
	"fmt"
	"log"

	"github.com/tmc/lib/nvidia/gdrcopy"
)

func main() {
	const (
		devicePtr = uintptr(0) // a CUDA device address
		size      = uintptr(64 * 1024)
	)

	g, err := gdrcopy.Open()
	if err != nil {
		log.Fatal(err)
	}
	defer g.Close()

	mh, err := g.PinBuffer(devicePtr, size, 0, 0)
	if err != nil {
		log.Fatal(err)
	}
	defer g.UnpinBuffer(mh)

	va, err := g.Map(mh, size)
	if err != nil {
		log.Fatal(err)
	}
	defer g.Unmap(mh, va, size)

	// The mapping begins at the GPU-page-aligned base of the pinning, which is
	// at or below devicePtr. Info says where, and Offset does the arithmetic.
	info, err := g.GetInfoV2(mh)
	if err != nil {
		log.Fatal(err)
	}
	off, ok := info.Offset(devicePtr)
	if !ok {
		log.Fatalf("%#x is not inside the pinning at %#x", devicePtr, info.Va)
	}

	// Write through the copy helpers, never by storing into the mapping: the
	// address is an mmap of a device aperture, and these run the copy paths
	// libgdrapi implements for it.
	payload := []byte("hello from the host")
	if err := mh.CopyToMapping(va+gdrcopy.MappedPtr(off), payload); err != nil {
		log.Fatal(err)
	}

	readback := make([]byte, len(payload))
	if err := mh.CopyFromMapping(readback, va+gdrcopy.MappedPtr(off)); err != nil {
		log.Fatal(err)
	}
	fmt.Printf("mapping type %v, %d bytes at offset %#x\n", info.MappingType, info.MappedSize, off)
}

Index

Examples

Constants

View Source
const (
	GPUPageShift = 16
	GPUPageSize  = uintptr(1) << GPUPageShift
	GPUPageMask  = ^(GPUPageSize - 1)
)

GPUPageShift, GPUPageSize and GPUPageMask are the GPU page granularity the kernel module pins at, from GPU_PAGE_SHIFT in gdrapi.h. PinBuffer aligns the address it is given down to this boundary and rounds the length up, so a pinning generally begins below the address requested. GetInfoV2 reports where it actually begins.

View Source
const (
	HeaderVersionMajor = 2
	HeaderVersionMinor = 6
)

HeaderVersionMajor and HeaderVersionMinor are GDR_API_MAJOR_VERSION and GDR_API_MINOR_VERSION from the header these bindings were generated from. They describe the header, not the library that ends up loaded: RuntimeGetVersion asks the library itself.

View Source
const (
	MinimumDriverVersionMajor = 2
	MinimumDriverVersionMinor = 0
)

MinimumDriverVersionMajor and MinimumDriverVersionMinor are the oldest gdrdrv the pinned header supports, from MINIMUM_GDRDRV_VERSION. DriverGetVersion reports what is loaded.

Variables

View Source
var (
	ErrHandle    = errors.New("gdrcopy: zero Handle")
	ErrMemHandle = errors.New("gdrcopy: zero MemHandle")
)

ErrHandle and ErrMemHandle report a call on a zero handle. libgdrapi dereferences both a gdr_t and a gdr_mh_t without checking them, so a zero value would reach C as a null dereference. These are returned instead.

View Source
var ErrCopyRange = errors.New("gdrcopy: copy range is outside the mapping")

ErrCopyRange reports a copy whose range falls outside the mapping.

View Source
var ErrMapped = errors.New("gdrcopy: mapping is still mapped; call Unmap first")

ErrMapped reports an unpin or a close while a mapping this package created is still live. gdrapi.h requires gdr_unmap before gdr_unpin_buffer: unpinning first leaves the process holding an mmap of an aperture the driver has released.

View Source
var ErrNotMapped = errors.New("gdrcopy: handle is not mapped")

ErrNotMapped reports an unmap or a copy on a handle this package has no live mapping for.

View Source
var ErrOpen = errors.New("gdrcopy: gdr_open failed: gdrdrv is not loaded and no visible device supports dma-buf mmap")

ErrOpen reports that gdr_open returned NULL.

gdr_open reports no error code. It needs either the gdrdrv kernel module loaded, or a CUDA driver whose device supports dma-buf mmap, and says neither which was missing nor why. Set GDRCOPY_ENABLE_LOGGING in the environment to make libgdrapi write its own diagnosis to stderr.

View Source
var ErrUnmapRange = errors.New("gdrcopy: Unmap address or size does not match the Map that created the mapping")

ErrUnmapRange reports an Unmap whose address or length differs from the Map that created the mapping. gdr_unmap rounds the length up to a host page and calls munmap on the result, so a wrong length unmaps memory the caller never mapped.

Functions

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 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 HasClose

func HasClose() bool

HasClose reports whether gdr_close resolved in the loaded library.

func HasCopyFromMapping

func HasCopyFromMapping() bool

HasCopyFromMapping reports whether gdr_copy_from_mapping resolved in the loaded library.

func HasCopyToMapping

func HasCopyToMapping() bool

HasCopyToMapping reports whether gdr_copy_to_mapping resolved in the loaded library.

func HasDriverGetVersion

func HasDriverGetVersion() bool

HasDriverGetVersion reports whether gdr_driver_get_version resolved in the loaded library.

func HasGetAttribute

func HasGetAttribute() bool

HasGetAttribute reports whether gdr_get_attribute resolved in the loaded library.

func HasGetCallbackFlag

func HasGetCallbackFlag() bool

HasGetCallbackFlag reports whether gdr_get_callback_flag resolved in the loaded library.

func HasGetInfoV2

func HasGetInfoV2() bool

HasGetInfoV2 reports whether gdr_get_info_v2 resolved in the loaded library.

func HasGetMappingTypeString

func HasGetMappingTypeString() bool

HasGetMappingTypeString reports whether gdr_get_mapping_type_string resolved in the loaded library.

func HasMap

func HasMap() bool

HasMap reports whether gdr_map resolved in the loaded library.

func HasMapV1

func HasMapV1() bool

HasMapV1 reports whether gdr_map resolved in the loaded library.

func HasMapV2

func HasMapV2() bool

HasMapV2 reports whether gdr_map_v2 resolved in the loaded library.

func HasOpen

func HasOpen() bool

HasOpen reports whether gdr_open resolved in the loaded library.

func HasPinBuffer

func HasPinBuffer() bool

HasPinBuffer reports whether gdr_pin_buffer resolved in the loaded library.

func HasPinBufferV1

func HasPinBufferV1() bool

HasPinBufferV1 reports whether gdr_pin_buffer resolved in the loaded library.

func HasPinBufferV2

func HasPinBufferV2() bool

HasPinBufferV2 reports whether gdr_pin_buffer_v2 resolved in the loaded library.

func HasRuntimeGetVersion

func HasRuntimeGetVersion() bool

HasRuntimeGetVersion reports whether gdr_runtime_get_version resolved in the loaded library.

func HasUnmap

func HasUnmap() bool

HasUnmap reports whether gdr_unmap resolved in the loaded library.

func HasUnpinBuffer

func HasUnpinBuffer() bool

HasUnpinBuffer reports whether gdr_unpin_buffer 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 MappingTypeString

func MappingTypeString(t MappingType) (string, error)

MappingTypeString returns libgdrapi's own name for t. The library answers with a pointer to one of its static strings, which this copies.

MappingType.String, generated from the header, gives the Go constant name and needs no library. Use it unless the library's spelling is what is wanted.

gdr_get_mapping_type_string was added in gdrcopy 2.5. Against an older libgdrapi this returns *SymbolError.

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 RuntimeGetVersion

func RuntimeGetVersion() (major, minor int32, err error)

RuntimeGetVersion reports the version of the loaded libgdrapi, which is not necessarily the version of the header these bindings were generated from. See HeaderVersionMajor and HeaderVersionMinor for that.

Types

type Attr

type Attr int32

Attr represents gdr_attr_t.

const (
	AttrUsePersistentMapping    Attr = 1 // Query whether gdrdrv uses persistent mapping
	AttrSupportPinFlagForcePcie Attr = 2 // Return non-zero if both gdrdrv and the GPU driver
	AttrUsingDmaBufMmap         Attr = 3 // Return non-zero if gdrcopy is using dma-buf mmap backend.
)

func (Attr) String

func (e Attr) String() string

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

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 Error

type Error struct {
	// Op is the C entry point that failed, spelled as the library spells it.
	Op string
	// Err is the number the library returned.
	Err syscall.Errno
}

Error reports a libgdrapi call that failed.

gdrcopy has no status enum: its calls return POSIX error numbers directly, so errors.Is against a syscall.Errno works.

if errors.Is(err, syscall.EINVAL) { ... }

One exception is worth knowing about. Under the dma-buf backend, which libgdrapi selects when gdrdrv is absent, a failing pin can return a CUDA driver result code rather than an errno. Err then holds that number and its message is meaningless; compare against the numeric value in that case.

func (*Error) Error

func (e *Error) Error() string

Error describes the failing call and its error number.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying error number.

type Handle

type Handle uintptr

Handle is an opaque handle for gdr_t.

func Open

func Open() (Handle, error)

Open opens libgdrapi's state object, connecting to the gdrdrv kernel module or, when gdrdrv is absent, to the CUDA driver's dma-buf mmap backend. Set GDRCOPY_USE_DMABUF_MMAP=1 in the environment to force the second.

Close releases it. Close frees the state object inside the library, so a Handle used after Close, or closed twice, is a use-after-free. This package cannot detect that: the handle is an address the library hands back, and nothing in Go distinguishes a live one from a freed one.

func (Handle) Close

func (g Handle) Close() error

Close releases the library state object.

Every mapping made through this package must be released with Unmap first: Close returns ErrMapped and does nothing while any remains. Pinned buffers need not be unpinned first, because gdr_close unpins whatever is left, and this package then forgets them.

func (Handle) DriverGetVersion

func (g Handle) DriverGetVersion() (major, minor int32, err error)

DriverGetVersion reports the version of the loaded gdrdrv kernel module. MinimumDriverVersionMajor and MinimumDriverVersionMinor are the oldest the pinned header supports.

Under the dma-buf backend there is no kernel module and the underlying ioctl fails.

func (Handle) GetAttribute

func (g Handle) GetAttribute(attr Attr) (int32, error)

GetAttribute reports a system-wide property of the GDRCopy installation. Per-handle properties come from GetInfoV2 instead.

gdr_get_attribute was added in gdrcopy 2.5. Against an older libgdrapi this returns *SymbolError.

Example

ExampleHandle_GetAttribute shows how to ask whether the running gdrdrv and GPU driver support forcing a PCIe BAR1 mapping before asking for one.

package main

import (
	"fmt"
	"log"

	"github.com/tmc/lib/nvidia/gdrcopy"
)

func main() {
	g, err := gdrcopy.Open()
	if err != nil {
		log.Fatal(err)
	}
	defer g.Close()

	supported, err := g.GetAttribute(gdrcopy.AttrSupportPinFlagForcePcie)
	if err != nil {
		// Older libgdrapi has no gdr_get_attribute at all.
		log.Fatal(err)
	}
	flags := gdrcopy.PinFlagDefault
	if supported != 0 {
		flags = gdrcopy.PinFlagForcePcie
	}
	fmt.Println(flags)
}

func (Handle) GetCallbackFlag

func (g Handle) GetCallbackFlag(mh MemHandle) (bool, error)

GetCallbackFlag reports whether the GPU driver has run the invalidation callback for this pinning, which it does when the device memory is freed, by cuMemFree or process teardown, before UnpinBuffer. Once it has, the mapping no longer refers to the caller's buffer and reading through it is meaningless.

Under the dma-buf backend there is no such callback and this always reports false.

func (Handle) GetInfoV2

func (g Handle) GetInfoV2(mh MemHandle) (Info, error)

GetInfoV2 reports where the driver pinned the buffer and how it is mapped.

There is no GetInfo, and that is deliberate. gdrapi.h defines gdr_get_info as a macro expanding to gdr_get_info_v2, but libgdrapi still exports a symbol spelled gdr_get_info: the obsolete v1 entry point, which writes a struct eight bytes shorter with no mapping type. Binding that name and handing it an Info would leave MappingType unwritten and report success.

gdr_get_info_v2 was added in gdrcopy 2.4. Against an older libgdrapi this returns *SymbolError.

func (Handle) Map

func (g Handle) Map(mh MemHandle, size uintptr) (MappedPtr, error)

Map creates a user-space mapping of the pinned buffer and returns its base address.

The address is an mmap of a device aperture, not Go memory. Do not build a Go slice on it and do not load or store through it directly: neither the store width nor the ordering a Go access produces is what such a mapping requires. Use CopyToMapping and CopyFromMapping, which run libgdrapi's per-architecture uncached copy paths and issue the fences those paths need.

size is remembered and must be passed back to Unmap unchanged. gdr_unmap rounds it up to a host page and calls munmap on the result, so a different size unmaps a different range.

The mapping begins at the GPU-page-aligned base of the pinning. Add MappedPtr(addr - info.Va), where info comes from GetInfoV2, to reach the data that was pinned.

func (Handle) MapV1

func (g Handle) MapV1(mh MemHandle, size uintptr) (MappedPtr, error)

MapV1 is the explicit version 1 name for Map.

func (Handle) MapV2

func (g Handle) MapV2(mh MemHandle, size uintptr, flags MapFlags) (MappedPtr, error)

MapV2 creates a user-space mapping and asks for a particular mapping type.

MapFlagDefault lets the kernel module choose, which is what Map does. The other flags request a write-combining, cached, or device mapping, and fail with syscall.EINVAL when the loaded gdrdrv cannot provide the one asked for. Info.MappingType reports what was actually established.

gdr_map_v2 was added in gdrcopy 2.5. Against an older libgdrapi this returns *SymbolError; Map is exported by every 2.x release.

func (Handle) PinBuffer

func (g Handle) PinBuffer(addr, size uintptr, p2pToken uint64, vaSpace uint32) (MemHandle, error)

PinBuffer pins size bytes of GPU memory at addr, a CUDA device address from cuMemAlloc or an equivalent, and returns a handle to the pinning.

The kernel module aligns the pinning down to GPUPageSize and rounds the length up, so the pinned region generally starts below addr. GetInfoV2 reports where it starts: the offset of the caller's data inside the mapping is addr - Info.Va, and Map returns the base of the mapping, not the address of that data.

p2pToken and vaSpace are the peer-to-peer token arguments NVIDIA deprecated. Pass zero for both. libgdrapi ignores them unless the loaded gdrdrv predates its v2 pin ioctl, and PinBufferV2 drops them.

Release with UnpinBuffer, after Unmap if the handle was mapped.

func (Handle) PinBufferV1

func (g Handle) PinBufferV1(addr, size uintptr, p2pToken uint64, vaSpace uint32) (MemHandle, error)

PinBufferV1 is the explicit version 1 name for PinBuffer.

func (Handle) PinBufferV2

func (g Handle) PinBufferV2(addr, size uintptr, flags PinFlags) (MemHandle, error)

PinBufferV2 pins size bytes of GPU memory at addr with an explicit flag. It aligns the pinning exactly as PinBuffer does.

PinFlagForcePcie asks for a GPU BAR1 mapping, which is supported only on certain coherent platforms, needs persistent mappings enabled, and needs both a GPU driver of release 570 or newer and a gdrdrv new enough to carry the flag. It fails with syscall.EINVAL otherwise. GetAttribute with AttrSupportPinFlagForcePcie reports whether the loaded pair supports it, though the header notes the pin itself can still fail on an unsupported platform.

gdr_pin_buffer_v2 was added in gdrcopy 2.5. Against an older libgdrapi this returns *SymbolError; PinBuffer is exported by every 2.x release.

func (Handle) Unmap

func (g Handle) Unmap(mh MemHandle, va MappedPtr, size uintptr) error

Unmap releases the user-space mapping.

va and size must be exactly what Map returned and was given. Unmap returns ErrUnmapRange without calling the library otherwise, because gdr_unmap passes the rounded-up length straight to munmap and would unmap a range the caller does not own.

func (Handle) UnpinBuffer

func (g Handle) UnpinBuffer(mh MemHandle) error

UnpinBuffer releases the pinning.

Any mapping of mh must be released with Unmap first, as gdrapi.h requires. UnpinBuffer returns ErrMapped and does nothing while a mapping this package created is still live.

type Info

type Info struct {
	// Va is the base of the pinned region, aligned down to GPUPageSize.
	// It is generally below the address passed to PinBuffer; the data that
	// was pinned begins at addr - Va bytes into the mapping.
	Va uint64

	// MappedSize is the length of the pinned region, rounded up from the
	// length passed to PinBuffer.
	MappedSize uint64

	// PageSize is the GPU page size the region was pinned at.
	PageSize uint32

	// TmCycles and CyclesPerMs are deprecated. gdrapi.h says they will be
	// removed in a future release; they are mirrored so the struct matches
	// the C layout, not because they are useful.
	TmCycles    uint64
	CyclesPerMs uint32

	// MappingType is the kind of mapping the kernel module established,
	// which is not necessarily the kind MapV2 asked for.
	MappingType MappingType
	// contains filtered or unexported fields
}

Info reports where the kernel module pinned a buffer and how it is mapped. It is the Go mirror of gdr_info_v2_t and is written by GetInfoV2.

The layout below was measured with a C compiler on:

  • x86_64-unknown-linux-gnu
  • aarch64-unknown-linux-gnu
  • powerpc64le-unknown-linux-gnu

The targets agreed; abi_test.go checks that the Go compiler lays this struct out the same way, and generation fails if a future header makes them disagree, because one Go struct could not then describe all of them.

func (Info) Mapped

func (i Info) Mapped() bool

Mapped reports whether the pinned region currently has a user-space mapping.

func (Info) Offset

func (i Info) Offset(addr uintptr) (uintptr, bool)

Offset returns the offset of addr within the mapping of this pinning, which is addr - Va. PinBuffer aligns the pinning down to a GPU page, so a mapping generally begins below the address that was pinned and the caller's data starts at this offset into it.

It reports false if addr lies outside the pinned region.

func (Info) WCMapping

func (i Info) WCMapping() bool

WCMapping reports whether the mapping is write-combining. It is the older, coarser form of MappingType, which distinguishes cached and device mappings as well.

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 libgdrapi could not be opened. Attempts lists every name tried in order. Path is set when an explicit path, from Load or GDRCOPY_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 MapFlags

type MapFlags int32

MapFlags represents gdr_map_flags_t.

const (
	MapFlagDefault          MapFlags = 0
	MapFlagReqWcMapping     MapFlags = 1
	MapFlagReqCacheMapping  MapFlags = 2
	MapFlagReqDeviceMapping MapFlags = 3
)

func (MapFlags) String

func (e MapFlags) String() string

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

type MappedPtr

type MappedPtr uintptr

MappedPtr is a CPU address in a mapping returned by Map or MapV2. It remains valid until Unmap. Use the copy methods to access it so that libgdrapi applies the required store widths and memory fences. The zero value does not identify a mapping.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/gdrcopy"
)

func main() {
	var p gdrcopy.MappedPtr
	fmt.Println(p == 0)
}
Output:
true

type MappingType

type MappingType int32

MappingType represents gdr_mapping_type_t.

const (
	MappingTypeNone    MappingType = 0
	MappingTypeWc      MappingType = 1
	MappingTypeCaching MappingType = 2
	MappingTypeDevice  MappingType = 3
)

func (MappingType) String

func (e MappingType) String() string

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

type MemHandle

type MemHandle uint64

MemHandle identifies one pinned GPU buffer. It is gdr_mh_t, which gdrapi.h declares as a struct wrapping a single unsigned long.

The C struct is one integer word wide, and every ABI gdrcopy builds for (System V x86-64, AAPCS64, ELFv2 ppc64le) passes such a struct in one general-purpose register, exactly as it passes the bare word, so MemHandle is a scalar here rather than a Go struct. TestMemHandleABI checks the width against what a C compiler measured, and generation fails outright if gdr_mh_t ever grows a second member.

The value is the address of an allocation inside libgdrapi. It means something only to the Handle that produced it, and libgdrapi frees and reuses the allocation after UnpinBuffer.

func (MemHandle) CopyFromMapping

func (mh MemHandle) CopyFromMapping(dst []byte, mapDPtr MappedPtr) error

CopyFromMapping copies len(dst) bytes into dst from the mapping at mapDPtr, which must lie inside the mapping Map returned for mh. The same ordering caveats as CopyToMapping apply.

func (MemHandle) CopyToMapping

func (mh MemHandle) CopyToMapping(mapDPtr MappedPtr, src []byte) error

CopyToMapping copies src into the mapping at mapDPtr, which must lie inside the mapping Map returned for mh.

The copy is synchronous and borrows src only for its duration. It runs libgdrapi's uncached store path and the fence that path requires, which is why a plain Go store into the mapping is not a substitute.

The library does not order this copy against GPU work already launched, and does not promise that a partly completed copy is invisible to it. See the GPUDirect RDMA sync behavior notes for what is and is not guaranteed.

type PinFlags

type PinFlags int32

PinFlags represents gdr_pin_flags_t.

const (
	PinFlagDefault   PinFlags = 0
	PinFlagForcePcie PinFlags = 1
)

func (PinFlags) String

func (e PinFlags) String() string

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

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