Documentation
¶
Overview ¶
Package custatevec provides lazy-loaded bindings for NVIDIA cuStateVec, the state-vector simulator shipped with cuQuantum.
The bound path is: create a Handle; optionally attach a workspace with Handle.SetWorkspace; allocate a device state vector of 2^nIndexBits complex elements and fill it with Handle.InitializeStateVector; apply gates with Handle.ApplyMatrix; and read the state back out with Handle.Abs2SumArray, Handle.MeasureOnZBasis or Handle.ComputeExpectation.
The declarations are generated from the custatevec.h shipped in cuQuantum 26.06.0.17 (CUSTATEVEC_VERSION 11400); cmd/gen-custatevec/headers/README.md records the source URL and header checksums. The library itself is opened on first use, by soname libcustatevec.so.1 or from CUSTATEVEC_LIB_PATH; nothing is loaded at import time.
Bit ordering ¶
Every bit position in this API is a state-vector index bit, numbered in little-endian order: bit 0 is the least significant bit of the state vector index, so amplitude sv[i] belongs to the computational basis state whose qubit b value is (i>>b)&1. Qubit 0 therefore selects adjacent pairs of amplitudes and qubit nIndexBits-1 splits the vector in half. A caller who numbers qubits from the other end sees plausible but wrong amplitudes, not an error: no call validates the intent behind a bit position. See BitOrdering for the constant that records this convention.
Complex representation ¶
A state vector is an array of Complex64 or Complex128, the Go spellings of CUDA's cuComplex (float2) and cuDoubleComplex (double2). These are structs of two floats, not Go's complex64 and complex128, whose memory layout the Go specification does not fix. cuDoubleComplex is declared __align__(16) in CUDA and Go cannot express a 16-byte struct alignment, so a Go []Complex128 has the right element size and stride but only 8-byte base alignment. Use AlignedComplex128 for a host buffer that matches the C alignment.
Data types ¶
The state vector, the gate or observable matrix and the arithmetic are typed separately, and the header accepts only three combinations:
- a C64F state vector with a C64F matrix and Compute64F
- a C32F state vector with a C64F matrix and Compute32F
- a C32F state vector with a C32F matrix and Compute32F
ComputeTF32 is declared by the header but is documented as not available. ComputeDefault selects Compute64F for a C64F state vector and Compute32F for a C32F one. An unsupported combination is reported by the library as ErrNotSupported, not rejected by this package.
Ownership ¶
The state vector, the extra workspace and the workspace attached to the handle are device memory this package neither allocates nor frees; pair it with a CUDA allocator such as github.com/tmc/lib/nvidia/driver. They must stay valid and unmodified until the work submitted on the handle's stream completes. The bit-position arrays (targets, controls, basisBits, bitOrdering, maskBitString, maskOrdering) and a host-resident gate matrix are host memory the library reads while the call runs; a Go allocation passed as one of them must be pinned with runtime.Pinner across the call. A Handle is not safe for concurrent use.
Distributed swaps use a Communicator, DistIndexBitSwapScheduler and SVSwapWorker. The communicator soname is nullable: nil selects already-linked MPI symbols. Keep worker state, events, semaphores and workspaces alive until transfers finish. Set extra workspace before worker parameters; transfer workspace must meet the reported minimum and power-of-two requirement. Synchronize before destroying workers and their dependencies. Distributed execution needs separate qualification. Sampler, accessor, batched operations and migrators remain unbound.
Observation ¶
- Handle.Abs2SumArray: sums the squared absolute values of state vector elements over a set of index bits.
- Handle.ComputeExpectation: computes the expectation value of an observable matrix.
- Handle.ComputeExpectationGetWorkspaceSize: returns the extra workspace size in bytes that a matching Handle.ComputeExpectation call needs.
- Handle.MeasureOnZBasis: measures a state vector on the Z basis and returns the parity of the measured bits.
Gate application ¶
- Handle.ApplyMatrix: applies a gate matrix to a state vector in place.
- Handle.ApplyMatrixGetWorkspaceSize: returns the extra workspace size in bytes that a matching Handle.ApplyMatrix call needs.
Library context ¶
- NewCommunicator: Create communicator.
- Communicator.Destroy: releases communicator.
- Create: creates a cuStateVec library handle bound to the current CUDA device.
- Handle.Close: releases a handle and the resources it owns.
- NewDistIndexBitSwapScheduler: Create distributed index bit swap scheduler.
- DistIndexBitSwapScheduler.Destroy: releases distributed index bit swap scheduler.
- DistIndexBitSwapScheduler.Parameters: Get parameters to be set to the state vector swap worker
- DistIndexBitSwapScheduler.SetIndexBitSwaps: Set index bit swaps to distributed index bit swap scheduler.
- GetProperty: reports one component of the linked library version.
- Handle.Stream: returns the CUDA stream bound to the handle.
- GetVersion: returns the linked library version, which the header encodes as major*10000 + minor*100 + patch.
- NewSVSwapWorker: Create state vector swap worker.
- NewSVSwapWorkerWithSemaphore: Create state vector swap worker with semaphore.
- SVSwapWorker.Destroy: releases the state vector swap worker.
- SVSwapWorker.Execute: Execute the data transfer.
- SVSwapWorker.SetExtraWorkspace: Set extra workspace.
- SVSwapWorker.SetParameters: Set state vector swap parameters.
- SVSwapWorker.SetSubSVsP2P: Set sub state vector pointers accessible via GPUDirect P2P with CUDA IPC events
- SVSwapWorker.SetSubSVsP2PWithSemaphores: Set sub state vector pointers accessible via GPUDirect P2P with semaphores
- SVSwapWorker.SetTransferWorkspace: Set transfer workspace.
- Handle.SetStream: binds the CUDA stream on which subsequent calls enqueue work.
Workspace ¶
- Handle.DefaultWorkspaceSize: returns the size in bytes of the workspace the handle allocated for itself.
- Handle.SetWorkspace: attaches caller-owned device memory as the handle's workspace.
State vector ¶
- Handle.InitializeStateVector: fills a device state vector with a standard initial state.
Example ¶
Example shows the index convention that decides whether a caller's amplitudes mean what they think they mean. It runs anywhere, because it makes no library call: the arithmetic below is what the bit ordering documented by this package amounts to.
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/custatevec"
)
func main() {
const nIndexBits = 3
fmt.Println(custatevec.BitOrdering)
for qubit := 0; qubit < nIndexBits; qubit++ {
// The basis state with only this qubit set.
index := 1 << qubit
fmt.Printf("qubit %d set -> state vector index %d\n", qubit, index)
}
// Reading a qubit's value back out of an index.
const index = 5
for qubit := 0; qubit < nIndexBits; qubit++ {
fmt.Printf("index %d has qubit %d = %d\n", index, qubit, (index>>qubit)&1)
}
}
Output: little-endian: index bit 0 is the least significant bit qubit 0 set -> state vector index 1 qubit 1 set -> state vector index 2 qubit 2 set -> state vector index 4 index 5 has qubit 0 = 1 index 5 has qubit 1 = 0 index 5 has qubit 2 = 1
Example (BellState) ¶
Example_bellState builds a two-qubit Bell state on a GPU and reads back the probability of each value of qubit 0.
It has no "Output" comment, so `go test` compiles it but never runs it: it needs an NVIDIA GPU, the CUDA driver and libcustatevec, none of which a test machine is assumed to have. It is written to be read as the shape of a correct call sequence, and to be run by hand on a machine that has them.
package main
import (
"fmt"
"math"
"runtime"
"unsafe"
"github.com/tmc/lib/nvidia/custatevec"
"github.com/tmc/lib/nvidia/driver"
)
func main() {
const nIndexBits = 2
const nAmplitudes = 1 << nIndexBits
// The CUDA context. cuStateVec operates on the current context's device.
// A context is current on an OS thread, so keep this goroutine on the
// thread that makes it current.
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if err := driver.Init(0); err != nil {
panic(err)
}
device, err := driver.DeviceGet(0)
if err != nil {
panic(err)
}
ctx, err := device.PrimaryCtxRetain()
if err != nil {
panic(err)
}
defer device.PrimaryCtxRelease()
if err := ctx.SetCurrent(); err != nil {
panic(err)
}
// The state vector is device memory this package neither allocates nor
// frees. Its size is 2^nIndexBits complex elements.
sv, err := driver.MemAllocBytes(nAmplitudes * uint(unsafe.Sizeof(custatevec.Complex128{})))
if err != nil {
panic(err)
}
defer sv.Free()
h, err := custatevec.Create()
if err != nil {
panic(err)
}
defer h.Close()
if err := h.InitializeStateVector(uintptr(sv), custatevec.C64F, nIndexBits,
custatevec.StateVectorTypeZero); err != nil {
panic(err)
}
// Gate matrices are host memory here, read by the library during the call,
// so they are pinned across it. The bit-position arrays are host memory
// too and are pinned for the same reason.
var pin runtime.Pinner
defer pin.Unpin()
invSqrt2 := 1 / math.Sqrt2
hadamard := custatevec.AlignedComplex128(4)
hadamard[0] = custatevec.MakeComplex128(complex(invSqrt2, 0))
hadamard[1] = custatevec.MakeComplex128(complex(invSqrt2, 0))
hadamard[2] = custatevec.MakeComplex128(complex(invSqrt2, 0))
hadamard[3] = custatevec.MakeComplex128(complex(-invSqrt2, 0))
pauliX := custatevec.AlignedComplex128(4)
pauliX[1] = custatevec.MakeComplex128(1)
pauliX[2] = custatevec.MakeComplex128(1)
pin.Pin(&hadamard[0])
pin.Pin(&pauliX[0])
qubit0 := []int32{0}
qubit1 := []int32{1}
pin.Pin(&qubit0[0])
pin.Pin(&qubit1[0])
// H on qubit 0.
if err := h.ApplyMatrix(uintptr(sv), custatevec.C64F, nIndexBits,
uintptr(unsafe.Pointer(&hadamard[0])), custatevec.C64F, custatevec.MatrixLayoutRow,
0, &qubit0[0], 1, nil, nil, 0, custatevec.Compute64F, 0, 0); err != nil {
panic(err)
}
// X on qubit 1, controlled by qubit 0.
if err := h.ApplyMatrix(uintptr(sv), custatevec.C64F, nIndexBits,
uintptr(unsafe.Pointer(&pauliX[0])), custatevec.C64F, custatevec.MatrixLayoutRow,
0, &qubit1[0], 1, &qubit0[0], nil, 1, custatevec.Compute64F, 0, 0); err != nil {
panic(err)
}
// The probability of each value of qubit 0. abs2sum is an address because
// the library accepts host or device memory there; this one is host memory
// the caller pinned.
probabilities := make([]float64, 2)
pin.Pin(&probabilities[0])
if err := h.Abs2SumArray(uintptr(sv), custatevec.C64F, nIndexBits,
uintptr(unsafe.Pointer(&probabilities[0])), &qubit0[0], 1, nil, nil, 0); err != nil {
panic(err)
}
fmt.Printf("P(qubit 0 = 0) = %.3f\nP(qubit 0 = 1) = %.3f\n", probabilities[0], probabilities[1])
}
Output:
Index ¶
- Constants
- func Close() error
- func GetProperty(type_ PropertyType) (int32, error)
- func GetVersion() (uint, error)
- func Has(symbol string) bool
- func HasAbs2SumArray() bool
- func HasApplyMatrix() bool
- func HasApplyMatrixGetWorkspaceSize() bool
- func HasCommunicatorCreate() bool
- func HasCommunicatorDestroy() bool
- func HasComputeExpectation() bool
- func HasComputeExpectationGetWorkspaceSize() bool
- func HasCreate() bool
- func HasDestroy() bool
- func HasDistIndexBitSwapSchedulerCreate() bool
- func HasDistIndexBitSwapSchedulerDestroy() bool
- func HasDistIndexBitSwapSchedulerGetParameters() bool
- func HasDistIndexBitSwapSchedulerSetIndexBitSwaps() bool
- func HasGetDefaultWorkspaceSize() bool
- func HasGetErrorName() bool
- func HasGetErrorString() bool
- func HasGetProperty() bool
- func HasGetStream() bool
- func HasGetVersion() bool
- func HasInitializeStateVector() bool
- func HasMeasureOnZBasis() bool
- func HasSVSwapWorkerCreate() bool
- func HasSVSwapWorkerCreateWithSemaphore() bool
- func HasSVSwapWorkerDestroy() bool
- func HasSVSwapWorkerExecute() bool
- func HasSVSwapWorkerSetExtraWorkspace() bool
- func HasSVSwapWorkerSetParameters() bool
- func HasSVSwapWorkerSetSubSVsP2P() bool
- func HasSVSwapWorkerSetSubSVsP2PWithSemaphores() bool
- func HasSVSwapWorkerSetTransferWorkspace() bool
- func HasSetStream() bool
- func HasSetWorkspace() bool
- func Load(path string) error
- func Loaded() bool
- func Path() string
- type BindFailure
- type CallError
- type CollapseOp
- type Communicator
- type CommunicatorType
- type Complex64
- type Complex128
- type ComputeType
- type DataTransferType
- type DataType
- type DistIndexBitSwapScheduler
- func (d DistIndexBitSwapScheduler) Destroy(handle Handle) error
- func (d DistIndexBitSwapScheduler) Parameters(handle Handle, swapBatchIndex int32, orgSubSVIndex int32, ...) error
- func (d DistIndexBitSwapScheduler) SetIndexBitSwaps(handle Handle, indexBitSwaps *Int2, nIndexBitSwaps uint32, ...) (uint32, error)
- type Handle
- func (h Handle) Abs2SumArray(sv uintptr, svDataType DataType, nIndexBits uint32, abs2sum uintptr, ...) error
- func (h Handle) ApplyMatrix(sv uintptr, svDataType DataType, nIndexBits uint32, matrix uintptr, ...) error
- func (h Handle) ApplyMatrixGetWorkspaceSize(svDataType DataType, nIndexBits uint32, matrix uintptr, ...) (uint, error)
- func (h *Handle) Close() error
- func (h Handle) ComputeExpectation(sv uintptr, svDataType DataType, nIndexBits uint32, ...) error
- func (h Handle) ComputeExpectationGetWorkspaceSize(svDataType DataType, nIndexBits uint32, matrix uintptr, ...) (uint, error)
- func (h Handle) DefaultWorkspaceSize() (uint, error)
- func (h Handle) InitializeStateVector(sv uintptr, svDataType DataType, nIndexBits uint32, svType StateVectorType) error
- func (h Handle) MeasureOnZBasis(sv uintptr, svDataType DataType, nIndexBits uint32, basisBits *int32, ...) (int32, error)
- func (h Handle) SetStream(streamId driver.Stream) error
- func (h Handle) SetWorkspace(workspace uintptr, workspaceSizeInBytes uint) error
- func (h Handle) Stream() (driver.Stream, error)
- type Index
- type Int2
- type LibraryAttempt
- type LibraryConflictError
- type LibraryError
- type MatrixLayout
- type PropertyType
- type Result
- type SVSwapParameters
- type SVSwapWorker
- func (s SVSwapWorker) Destroy(handle Handle) error
- func (s SVSwapWorker) Execute(handle Handle, begin Index, end Index) error
- func (s SVSwapWorker) SetExtraWorkspace(handle Handle, extraWorkspace uintptr, extraWorkspaceSizeInBytes uint) error
- func (s SVSwapWorker) SetParameters(handle Handle, parameters *SVSwapParameters, peer int32) error
- func (s SVSwapWorker) SetSubSVsP2P(handle Handle, dstSubSVsP2P *uintptr, dstSubSVIndicesP2P *int32, ...) error
- func (s SVSwapWorker) SetSubSVsP2PWithSemaphores(handle Handle, dstSubSVsP2P *uintptr, dstSubSVIndicesP2P *int32, ...) error
- func (s SVSwapWorker) SetTransferWorkspace(handle Handle, transferWorkspace uintptr, transferWorkspaceSizeInBytes uint) error
- type StateVectorType
- type SymbolError
Examples ¶
Constants ¶
const BitOrdering = "little-endian: index bit 0 is the least significant bit"
BitOrdering records the index-bit convention of this API, so that a caller can name it instead of assuming it. Bit positions passed to this package are state-vector index bits in little-endian order: bit 0 is the least significant bit of the index, and the amplitude at index i has qubit b in state (i>>b)&1.
Variables ¶
This section is empty.
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 GetProperty ¶
func GetProperty(type_ PropertyType) (int32, error)
GetProperty reports one component of the linked library version.
This function returns the version information of the cuStateVec library.
- type_: in requested property (`MAJOR_VERSION`, `MINOR_VERSION`, or `PATCH_LEVEL`)
- value: out value of the requested property
Wraps custatevecGetProperty.
func GetVersion ¶
GetVersion returns the linked library version, which the header encodes as major*10000 + minor*100 + patch.
This function returns the version information of the cuStateVec library.
Wraps custatevecGetVersion. 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 HasAbs2SumArray ¶
func HasAbs2SumArray() bool
HasAbs2SumArray reports whether custatevecAbs2SumArray resolved in the loaded library.
func HasApplyMatrix ¶
func HasApplyMatrix() bool
HasApplyMatrix reports whether custatevecApplyMatrix resolved in the loaded library.
func HasApplyMatrixGetWorkspaceSize ¶
func HasApplyMatrixGetWorkspaceSize() bool
HasApplyMatrixGetWorkspaceSize reports whether custatevecApplyMatrixGetWorkspaceSize resolved in the loaded library.
func HasCommunicatorCreate ¶
func HasCommunicatorCreate() bool
HasCommunicatorCreate reports whether custatevecCommunicatorCreate resolved in the loaded library.
func HasCommunicatorDestroy ¶
func HasCommunicatorDestroy() bool
HasCommunicatorDestroy reports whether custatevecCommunicatorDestroy resolved in the loaded library.
func HasComputeExpectation ¶
func HasComputeExpectation() bool
HasComputeExpectation reports whether custatevecComputeExpectation resolved in the loaded library.
func HasComputeExpectationGetWorkspaceSize ¶
func HasComputeExpectationGetWorkspaceSize() bool
HasComputeExpectationGetWorkspaceSize reports whether custatevecComputeExpectationGetWorkspaceSize resolved in the loaded library.
func HasCreate ¶
func HasCreate() bool
HasCreate reports whether custatevecCreate resolved in the loaded library.
func HasDestroy ¶
func HasDestroy() bool
HasDestroy reports whether custatevecDestroy resolved in the loaded library.
func HasDistIndexBitSwapSchedulerCreate ¶
func HasDistIndexBitSwapSchedulerCreate() bool
HasDistIndexBitSwapSchedulerCreate reports whether custatevecDistIndexBitSwapSchedulerCreate resolved in the loaded library.
func HasDistIndexBitSwapSchedulerDestroy ¶
func HasDistIndexBitSwapSchedulerDestroy() bool
HasDistIndexBitSwapSchedulerDestroy reports whether custatevecDistIndexBitSwapSchedulerDestroy resolved in the loaded library.
func HasDistIndexBitSwapSchedulerGetParameters ¶
func HasDistIndexBitSwapSchedulerGetParameters() bool
HasDistIndexBitSwapSchedulerGetParameters reports whether custatevecDistIndexBitSwapSchedulerGetParameters resolved in the loaded library.
func HasDistIndexBitSwapSchedulerSetIndexBitSwaps ¶
func HasDistIndexBitSwapSchedulerSetIndexBitSwaps() bool
HasDistIndexBitSwapSchedulerSetIndexBitSwaps reports whether custatevecDistIndexBitSwapSchedulerSetIndexBitSwaps resolved in the loaded library.
func HasGetDefaultWorkspaceSize ¶
func HasGetDefaultWorkspaceSize() bool
HasGetDefaultWorkspaceSize reports whether custatevecGetDefaultWorkspaceSize resolved in the loaded library.
func HasGetErrorName ¶
func HasGetErrorName() bool
HasGetErrorName reports whether custatevecGetErrorName resolved in the loaded library.
func HasGetErrorString ¶
func HasGetErrorString() bool
HasGetErrorString reports whether custatevecGetErrorString resolved in the loaded library.
func HasGetProperty ¶
func HasGetProperty() bool
HasGetProperty reports whether custatevecGetProperty resolved in the loaded library.
func HasGetStream ¶
func HasGetStream() bool
HasGetStream reports whether custatevecGetStream resolved in the loaded library.
func HasGetVersion ¶
func HasGetVersion() bool
HasGetVersion reports whether custatevecGetVersion resolved in the loaded library.
func HasInitializeStateVector ¶
func HasInitializeStateVector() bool
HasInitializeStateVector reports whether custatevecInitializeStateVector resolved in the loaded library.
func HasMeasureOnZBasis ¶
func HasMeasureOnZBasis() bool
HasMeasureOnZBasis reports whether custatevecMeasureOnZBasis resolved in the loaded library.
func HasSVSwapWorkerCreate ¶
func HasSVSwapWorkerCreate() bool
HasSVSwapWorkerCreate reports whether custatevecSVSwapWorkerCreate resolved in the loaded library.
func HasSVSwapWorkerCreateWithSemaphore ¶
func HasSVSwapWorkerCreateWithSemaphore() bool
HasSVSwapWorkerCreateWithSemaphore reports whether custatevecSVSwapWorkerCreateWithSemaphore resolved in the loaded library.
func HasSVSwapWorkerDestroy ¶
func HasSVSwapWorkerDestroy() bool
HasSVSwapWorkerDestroy reports whether custatevecSVSwapWorkerDestroy resolved in the loaded library.
func HasSVSwapWorkerExecute ¶
func HasSVSwapWorkerExecute() bool
HasSVSwapWorkerExecute reports whether custatevecSVSwapWorkerExecute resolved in the loaded library.
func HasSVSwapWorkerSetExtraWorkspace ¶
func HasSVSwapWorkerSetExtraWorkspace() bool
HasSVSwapWorkerSetExtraWorkspace reports whether custatevecSVSwapWorkerSetExtraWorkspace resolved in the loaded library.
func HasSVSwapWorkerSetParameters ¶
func HasSVSwapWorkerSetParameters() bool
HasSVSwapWorkerSetParameters reports whether custatevecSVSwapWorkerSetParameters resolved in the loaded library.
func HasSVSwapWorkerSetSubSVsP2P ¶
func HasSVSwapWorkerSetSubSVsP2P() bool
HasSVSwapWorkerSetSubSVsP2P reports whether custatevecSVSwapWorkerSetSubSVsP2P resolved in the loaded library.
func HasSVSwapWorkerSetSubSVsP2PWithSemaphores ¶
func HasSVSwapWorkerSetSubSVsP2PWithSemaphores() bool
HasSVSwapWorkerSetSubSVsP2PWithSemaphores reports whether custatevecSVSwapWorkerSetSubSVsP2PWithSemaphores resolved in the loaded library.
func HasSVSwapWorkerSetTransferWorkspace ¶
func HasSVSwapWorkerSetTransferWorkspace() bool
HasSVSwapWorkerSetTransferWorkspace reports whether custatevecSVSwapWorkerSetTransferWorkspace resolved in the loaded library.
func HasSetStream ¶
func HasSetStream() bool
HasSetStream reports whether custatevecSetStream resolved in the loaded library.
func HasSetWorkspace ¶
func HasSetWorkspace() bool
HasSetWorkspace reports whether custatevecSetWorkspace resolved in the loaded library.
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.
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 result.
Unwrap returns Result, so errors.Is(err, c) reports whether the call returned the Result constant c, and errors.As(err, &r) with r of type Result recovers the code.
type CollapseOp ¶
type CollapseOp int32
CollapseOp specifies whether a measurement collapses the state vector.
const ( CollapseNone CollapseOp = 0 // Do not collapse the statevector CollapseNormalizeAndZero CollapseOp = 1 // Collapse, normalize, and fill zeros in the statevector CollapseReset CollapseOp = 2 // Reserved for future use )
func (CollapseOp) String ¶
func (e CollapseOp) String() string
String returns the constant name, or a numeric representation for unknown values.
type Communicator ¶
type Communicator uintptr
Communicator is an opaque handle for custatevecCommunicatorDescriptor_t.
func NewCommunicator ¶
func NewCommunicator(handle Handle, communicatorType CommunicatorType, soname *byte) (Communicator, error)
NewCommunicator creates communicator.
- handle: in the handle to cuStateVec library
- communicator: out a pointer to the communicator
- communicatorType: in the communicator type
- soname: in the shared object name
Wraps custatevecCommunicatorCreate.
func (Communicator) Destroy ¶
func (c Communicator) Destroy(handle Handle) error
Destroy releases communicator.
- handle: in the handle to cuStateVec library
It is not named Close because it takes more than the handle.
Wraps custatevecCommunicatorDestroy.
type CommunicatorType ¶
type CommunicatorType int32
CommunicatorType specifies the communicator used in inter-process communications.
const ( CommunicatorTypeExternal CommunicatorType = 0 // An user-provided communicator will be used for inter-process communications. CommunicatorTypeOpenmpi CommunicatorType = 1 // Open MPI will be used for inter-process communications. CommunicatorTypeMpich CommunicatorType = 2 // MPICH will be used for inter-process communications. )
func (CommunicatorType) String ¶
func (e CommunicatorType) String() string
String returns the constant name, or a numeric representation for unknown values.
type Complex64 ¶
type Complex64 struct {
X float32 // real part
Y float32 // imaginary part
// contains filtered or unexported fields
}
Complex64 is one single-precision state-vector or matrix element. It is the Go spelling of CUDA's cuComplex, a float2 of the real part X and the imaginary part Y. It is not Go's complex64, whose memory layout the Go specification does not fix.
func MakeComplex64 ¶
MakeComplex64 converts a Go complex64 to the C element representation.
type Complex128 ¶
Complex128 is one double-precision state-vector or matrix element. It is the Go spelling of CUDA's cuDoubleComplex, a double2 of the real part X and the imaginary part Y. It is not Go's complex128, whose memory layout the Go specification does not fix.
CUDA declares double2 __align__(16) and Go cannot express a 16-byte struct alignment, so this type has size 16 and stride 16 but alignment 8. An array of them is laid out identically to a C array; only the base address may be less aligned. Use AlignedComplex128 for a host buffer whose base address must match the C alignment.
func AlignedComplex128 ¶
func AlignedComplex128(n int) []Complex128
AlignedComplex128 returns a Go-allocated slice of n elements whose first element is 16-byte aligned, matching the alignment CUDA declares for cuDoubleComplex. Use it for a host-resident gate matrix; the alignment of a plain make([]Complex128, n) is whatever the Go allocator happens to give, which is only guaranteed to be 8.
Over-allocating by one element does not work: the element size is already 16, so advancing by an element preserves the misalignment. The slice is carved out of a float64 backing array with 16 bytes of slack instead, and remains ordinary Go memory that the collector keeps alive through the returned interior pointer. Pin it with a runtime.Pinner across any call that receives its address.
func MakeComplex128 ¶
func MakeComplex128(v complex128) Complex128
MakeComplex128 converts a Go complex128 to the C element representation.
func (Complex128) Complex ¶
func (c Complex128) Complex() complex128
Complex returns c as a Go complex128.
type ComputeType ¶
type ComputeType int32
ComputeType specifies the minimal accuracy of the arithmetic a call uses.
Only three combinations of state vector, matrix and compute type are accepted; see the package documentation.
const ( ComputeDefault ComputeType = 0 // FP32(float) for Complex64, FP64(double) for Complex128 Compute32F ComputeType = 1 << 2 // FP32(float) Compute64F ComputeType = 1 << 4 // FP64(double) ComputeTF32 ComputeType = 1 << 12 // TF32(tensor-float-32) )
func (ComputeType) String ¶
func (e ComputeType) String() string
String returns the constant name, or a numeric representation for unknown values.
type DataTransferType ¶
type DataTransferType int32
DataTransferType specifies the data transfer direction in point-to-point communication.
const ( DataTransferTypeNone DataTransferType = 0 // Data transfer worker will not send or receive any data. DataTransferTypeSend DataTransferType = 1 // Data transfer worker will send data. DataTransferTypeRecv DataTransferType = 2 // Data transfer worker will receive data. DataTransferTypeSendRecv DataTransferType = DataTransferTypeSend | DataTransferTypeRecv )
func (DataTransferType) String ¶
func (e DataTransferType) String() string
String returns the constant name, or a numeric representation for unknown values.
type DataType ¶
type DataType int32
DataType identifies a CUDA data representation.
const ( // real as a half R16F DataType = 2 // complex as a pair of half numbers C16F DataType = 6 // real as a nv_bfloat16 R16BF DataType = 14 // complex as a pair of nv_bfloat16 numbers C16BF DataType = 15 // real as a float R32F DataType = 0 // complex as a pair of float numbers C32F DataType = 4 // real as a double R64F DataType = 1 // complex as a pair of double numbers C64F DataType = 5 // real as a signed 4-bit int R4I DataType = 16 // complex as a pair of signed 4-bit int numbers C4I DataType = 17 // real as a unsigned 4-bit int R4U DataType = 18 // complex as a pair of unsigned 4-bit int numbers C4U DataType = 19 // real as a signed 8-bit int R8I DataType = 3 // complex as a pair of signed 8-bit int numbers C8I DataType = 7 // real as a unsigned 8-bit int R8U DataType = 8 // complex as a pair of unsigned 8-bit int numbers C8U DataType = 9 // real as a signed 16-bit int R16I DataType = 20 // complex as a pair of signed 16-bit int numbers C16I DataType = 21 // real as a unsigned 16-bit int R16U DataType = 22 // complex as a pair of unsigned 16-bit int numbers C16U DataType = 23 // real as a signed 32-bit int R32I DataType = 10 // complex as a pair of signed 32-bit int numbers C32I DataType = 11 // real as a unsigned 32-bit int R32U DataType = 12 // complex as a pair of unsigned 32-bit int numbers C32U DataType = 13 // real as a signed 64-bit int R64I DataType = 24 // complex as a pair of signed 64-bit int numbers C64I DataType = 25 // real as a unsigned 64-bit int R64U DataType = 26 // complex as a pair of unsigned 64-bit int numbers C64U DataType = 27 // real as a nv_fp8_e4m3 R8F_E4M3 DataType = 28 // real as an unsigned nv_fp8_e4m3 R8F_UE4M3 DataType = R8F_E4M3 // real as a nv_fp8_e5m2 R8F_E5M2 DataType = 29 // real as an exponent-only unsigned nv_fp8_e8m0 R8F_UE8M0 DataType = 30 // real as a nv_fp6_e2m3 R6F_E2M3 DataType = 31 // real as a nv_fp6_e3m2 R6F_E3M2 DataType = 32 // real as a nv_fp4_e2m1 R4F_E2M1 DataType = 33 // real as an unsigned nv_fp8_ue5m3 R8FUe5m3 DataType = 34 )
DataType constants.
type DistIndexBitSwapScheduler ¶
type DistIndexBitSwapScheduler uintptr
DistIndexBitSwapScheduler is an opaque handle for custatevecDistIndexBitSwapSchedulerDescriptor_t.
func NewDistIndexBitSwapScheduler ¶
func NewDistIndexBitSwapScheduler(handle Handle, nGlobalIndexBits uint32, nLocalIndexBits uint32) (DistIndexBitSwapScheduler, error)
NewDistIndexBitSwapScheduler creates distributed index bit swap scheduler.
- handle: in the handle to cuStateVec library
- scheduler: out a pointer to a batch swap scheduler
- nGlobalIndexBits: in the number of global index bits
- nLocalIndexBits: in the number of local index bits
Wraps custatevecDistIndexBitSwapSchedulerCreate.
func (DistIndexBitSwapScheduler) Destroy ¶
func (d DistIndexBitSwapScheduler) Destroy(handle Handle) error
Destroy releases distributed index bit swap scheduler.
- handle: in the handle to cuStateVec library
It is not named Close because it takes more than the handle.
Wraps custatevecDistIndexBitSwapSchedulerDestroy.
func (DistIndexBitSwapScheduler) Parameters ¶
func (d DistIndexBitSwapScheduler) Parameters(handle Handle, swapBatchIndex int32, orgSubSVIndex int32, parameters *SVSwapParameters) error
Parameters gets parameters to be set to the state vector swap worker
- handle: in the handle to cuStateVec library
- swapBatchIndex: in swap batch index for state vector swap parameters
- orgSubSVIndex: in the index of the origin sub state vector to swap state vector segments
- parameters: out a pointer to data transfer parameters
Wraps custatevecDistIndexBitSwapSchedulerGetParameters.
func (DistIndexBitSwapScheduler) SetIndexBitSwaps ¶
func (d DistIndexBitSwapScheduler) SetIndexBitSwaps(handle Handle, indexBitSwaps *Int2, nIndexBitSwaps uint32, maskBitString *int32, maskOrdering *int32, maskLen uint32) (uint32, error)
SetIndexBitSwaps sets index bit swaps to distributed index bit swap scheduler.
- handle: in the handle to cuStateVec library
- indexBitSwaps: in pointer to a host array of index bit pairs being swapped
- nIndexBitSwaps: in the number of index bit swaps
- maskBitString: in pointer to a host array to mask output
- maskOrdering: in pointer to a host array to specify the ordering of maskBitString
- maskLen: in the length of mask
- nSwapBatches: out the number of batched data transfers
Wraps custatevecDistIndexBitSwapSchedulerSetIndexBitSwaps.
type Handle ¶
type Handle uintptr
Handle is an opaque handle for custatevecHandle_t.
func Create ¶
Create creates a cuStateVec library handle bound to the current CUDA device.
This function initializes the cuStateVec library and creates a handle on the cuStateVec context. It must be called prior to any other cuStateVec API functions. If the device has unsupported compute capability, this function could return ErrArchMismatch.
- handle: in the pointer to the handle to the cuStateVec context
Wraps custatevecCreate.
func (Handle) Abs2SumArray ¶
func (h Handle) Abs2SumArray(sv uintptr, svDataType DataType, nIndexBits uint32, abs2sum uintptr, bitOrdering *int32, bitOrderingLen uint32, maskBitString *int32, maskOrdering *int32, maskLen uint32) error
Abs2SumArray sums the squared absolute values of state vector elements over a set of index bits.
Calculate abs2sum array for a given set of index bits.
Calculates an array of sums of squared absolute values of state vector elements. The abs2sum array can be on host or device. The index bit ordering abs2sum array is specified by the bitOrdering and bitOrderingLen arguments. Unspecified bits are folded (summed up).
The maskBitString, maskOrdering and maskLen arguments set bit mask in the state vector index. The abs2sum array is calculated by using state vector elements whose indices match the mask bit string. If the maskLen argument is 0, null pointers can be specified to the maskBitString and maskOrdering arguments, and all state vector elements are used for calculation.
By definition, bit positions in bitOrdering and maskOrdering arguments should not overlap.
The empty bitOrdering can be specified to calculate the norm of state vector. In this case, 0 is passed to the bitOrderingLen argument and the bitOrdering argument can be a null pointer.
Note: Since the size of abs2sum array is proportional to 2^bitOrderingLen, the max length of bitOrdering depends on the amount of available memory and maskLen.
- sv: in state vector
- svDataType: in data type of state vector
- nIndexBits: in the number of index bits
- abs2sum: out pointer to a host or device array of sums of squared absolute values
- bitOrdering: in pointer to a host array of index bit ordering
- bitOrderingLen: in the length of bitOrdering
- maskBitString: in pointer to a host array for a bit string to specify mask
- maskOrdering: in pointer to a host array for the mask ordering
- maskLen: in the length of mask
Wraps custatevecAbs2SumArray.
func (Handle) ApplyMatrix ¶
func (h Handle) ApplyMatrix(sv uintptr, svDataType DataType, nIndexBits uint32, matrix uintptr, matrixDataType DataType, layout MatrixLayout, adjoint int32, targets *int32, nTargets uint32, controls *int32, controlBitValues *int32, nControls uint32, computeType ComputeType, extraWorkspace uintptr, extraWorkspaceSizeInBytes uint) error
ApplyMatrix applies a gate matrix to a state vector in place.
Apply gate matrix to a state vector. The state vector size is 2^nIndexBits.
The matrix argument is a host or device pointer of a 2-dimensional array for a square matrix. The size of matrix is (2^nTargets x 2^nTargets) and the value type is specified by the matrixDataType argument. The layout argument specifies the matrix layout which can be in either row-major or column-major order. The targets and controls arguments specify target and control bit positions in the state vector index.
The controlBitValues argument specifies bit values of control bits. The ordering of controlBitValues is specified by the controls argument. If a null pointer is specified to this argument, all control bit values are set to 1.
By definition, bit positions in targets and controls arguments should not overlap.
This function may return ErrInsufficientWorkspace for large nTargets. In such cases, the extraWorkspace and extraWorkspaceSizeInBytes arguments should be specified to provide extra workspace. The size of required extra workspace is obtained by calling Handle.ApplyMatrixGetWorkspaceSize. A null pointer can be passed to the extraWorkspace argument if no extra workspace is required. Also, if a device memory handler is set, the extraWorkspace can be set to null, and the extraWorkspaceSizeInBytes can be set to 0.
- sv: in,out state vector
- svDataType: in data type of the state vector
- nIndexBits: in the number of index bits of the state vector
- matrix: in host or device pointer to a square matrix
- matrixDataType: in data type of matrix
- layout: in enumerator specifying the memory layout of matrix
- adjoint: in apply adjoint of matrix
- targets: in pointer to a host array of target bits
- nTargets: in the number of target bits
- controls: in pointer to a host array of control bits
- controlBitValues: in pointer to a host array of control bit values
- nControls: in the number of control bits
- computeType: in computeType of matrix multiplication
- extraWorkspace: in extra workspace
- extraWorkspaceSizeInBytes: in extra workspace size
Wraps custatevecApplyMatrix.
func (Handle) ApplyMatrixGetWorkspaceSize ¶
func (h Handle) ApplyMatrixGetWorkspaceSize(svDataType DataType, nIndexBits uint32, matrix uintptr, matrixDataType DataType, layout MatrixLayout, adjoint int32, nTargets uint32, nControls uint32, computeType ComputeType) (uint, error)
ApplyMatrixGetWorkspaceSize returns the extra workspace size in bytes that a matching Handle.ApplyMatrix call needs.
This function gets the required workspace size for Handle.ApplyMatrix.
This function returns the required extra workspace size to execute Handle.ApplyMatrix. extraWorkspaceSizeInBytes will be set to 0 if no extra buffer is required for a given set of arguments.
- svDataType: in Data type of the state vector
- nIndexBits: in the number of index bits of the state vector
- matrix: in host or device pointer to a matrix
- matrixDataType: in data type of matrix
- layout: in enumerator specifying the memory layout of matrix
- adjoint: in apply adjoint of matrix
- nTargets: in the number of target bits
- nControls: in the number of control bits
- computeType: in computeType of matrix multiplication
- extraWorkspaceSizeInBytes: out workspace size
Wraps custatevecApplyMatrixGetWorkspaceSize.
func (*Handle) Close ¶
Close releases a handle and the resources it owns.
This function releases resources used by the cuStateVec library.
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 custatevecDestroy.
func (Handle) ComputeExpectation ¶
func (h Handle) ComputeExpectation(sv uintptr, svDataType DataType, nIndexBits uint32, expectationValue unsafe.Pointer, expectationDataType DataType, residualNorm *float64, matrix uintptr, matrixDataType DataType, layout MatrixLayout, basisBits *int32, nBasisBits uint32, computeType ComputeType, extraWorkspace uintptr, extraWorkspaceSizeInBytes uint) error
ComputeExpectation computes the expectation value of an observable matrix.
Compute expectation of matrix observable.
This function calculates expectation for a given matrix observable. The acceptable values for the expectationDataType argument are CUDA_R_64F and CUDA_C_64F.
The basisBits and nBasisBits arguments specify the basis to calculate expectation. For the computeType argument, the same combinations for Handle.ApplyMatrix are available.
This function may return ErrInsufficientWorkspace for large nBasisBits. In such cases, the extraWorkspace and extraWorkspaceSizeInBytes arguments should be specified to provide extra workspace. The size of required extra workspace is obtained by calling Handle.ComputeExpectationGetWorkspaceSize. A null pointer can be passed to the extraWorkspace argument if no extra workspace is required. Also, if a device memory handler is set, the extraWorkspace can be set to null, and the extraWorkspaceSizeInBytes can be set to 0.
Note: The residualNorm argument is not available in this version. If a matrix given by the matrix argument may not be a Hermitian matrix, please specify CUDA_C_64F to the expectationDataType argument and check the imaginary part of the calculated expectation value.
Note: For Blackwell architecture, the input state vector has to be 128-byte aligned. Otherwise, this function may return ErrInvalidValue.
- sv: in state vector
- svDataType: in data type of the state vector
- nIndexBits: in the number of index bits of the state vector
- expectationValue: out host pointer to a variable to store an expectation value
- expectationDataType: in data type of expect
- residualNorm: out result of matrix type test
- matrix: in observable as matrix
- matrixDataType: in data type of matrix
- layout: in matrix memory layout
- basisBits: in pointer to a host array of basis index bits
- nBasisBits: in the number of basis bits
- computeType: in computeType of matrix multiplication
- extraWorkspace: in pointer to an extra workspace
- extraWorkspaceSizeInBytes: in the size of extra workspace
Wraps custatevecComputeExpectation.
func (Handle) ComputeExpectationGetWorkspaceSize ¶
func (h Handle) ComputeExpectationGetWorkspaceSize(svDataType DataType, nIndexBits uint32, matrix uintptr, matrixDataType DataType, layout MatrixLayout, nBasisBits uint32, computeType ComputeType) (uint, error)
ComputeExpectationGetWorkspaceSize returns the extra workspace size in bytes that a matching Handle.ComputeExpectation call needs.
This function gets the required workspace size for Handle.ComputeExpectation.
This function returns the size of the extra workspace required to execute Handle.ComputeExpectation. extraWorkspaceSizeInBytes will be set to 0 if no extra buffer is required.
- svDataType: in Data type of the state vector
- nIndexBits: in the number of index bits of the state vector
- matrix: in host or device pointer to a matrix
- matrixDataType: in data type of matrix
- layout: in enumerator specifying the memory layout of matrix
- nBasisBits: in the number of target bits
- computeType: in computeType of matrix multiplication
- extraWorkspaceSizeInBytes: out size of the extra workspace
Wraps custatevecComputeExpectationGetWorkspaceSize.
func (Handle) DefaultWorkspaceSize ¶
DefaultWorkspaceSize returns the size in bytes of the workspace the handle allocated for itself.
This function returns the default workspace size defined by the cuStateVec library.
This function returns the default size used for the workspace.
- workspaceSizeInBytes: out default workspace size
Wraps custatevecGetDefaultWorkspaceSize.
func (Handle) InitializeStateVector ¶
func (h Handle) InitializeStateVector(sv uintptr, svDataType DataType, nIndexBits uint32, svType StateVectorType) error
InitializeStateVector fills a device state vector with a standard initial state.
Initialize the state vector to a certain form.
- sv: in,out state vector
- svDataType: in data type of state vector
- nIndexBits: in the number of index bits
- svType: in the target quantum state
Wraps custatevecInitializeStateVector.
func (Handle) MeasureOnZBasis ¶
func (h Handle) MeasureOnZBasis(sv uintptr, svDataType DataType, nIndexBits uint32, basisBits *int32, nBasisBits uint32, randnum float64, collapse CollapseOp) (int32, error)
MeasureOnZBasis measures a state vector on the Z basis and returns the parity of the measured bits.
Measurement on a given Z-product basis.
This function does measurement on a given Z product basis. The measurement result is the parity of the specified Z product basis. At least one basis bit should be specified, otherwise this function fails.
If CollapseNone is specified for the collapse argument, this function only returns the measurement result without collapsing the state vector. If CollapseNormalizeAndZero is specified, this function collapses the state vector as custatevecCollapseOnZBasis() does.
If a random number is not in [0, 1), this function returns ErrInvalidValue. At least one basis bit should be specified, otherwise this function returns ErrInvalidValue.
- sv: in,out state vector
- svDataType: in data type of state vector
- nIndexBits: in the number of index bits
- parity: out parity, 0 or 1
- basisBits: in pointer to a host array of Z basis bits
- nBasisBits: in the number of Z basis bits
- randnum: in random number, [0, 1)
- collapse: in Collapse operation
Wraps custatevecMeasureOnZBasis.
func (Handle) SetStream ¶
SetStream binds the CUDA stream on which subsequent calls enqueue work.
This function sets the stream to be used by the cuStateVec library to execute its routine.
- streamId: in the stream to be used by the library
Wraps custatevecSetStream.
func (Handle) SetWorkspace ¶
SetWorkspace attaches caller-owned device memory as the handle's workspace.
This function sets the workspace used by the cuStateVec library.
This function sets the workspace attached to the handle. The required size of the workspace is obtained by Handle.DefaultWorkspaceSize.
By setting a larger workspace, users are able to execute functions without allocating the extra workspace in some functions.
If a device memory handler is set, the workspace can be set to null and the workspace is allocated using the user-defined memory pool.
- workspace: in device pointer to workspace
- workspaceSizeInBytes: in workspace size
Wraps custatevecSetWorkspace.
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 libcustatevec could not be opened. Attempts lists every name tried in order. Path is set when an explicit path, from Load or CUSTATEVEC_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 MatrixLayout ¶
type MatrixLayout int32
MatrixLayout specifies the memory layout of a gate or observable matrix.
const ( MatrixLayoutCol MatrixLayout = 0 // Matrix stored in the column-major order MatrixLayoutRow MatrixLayout = 1 // Matrix stored in the row-major order )
func (MatrixLayout) String ¶
func (e MatrixLayout) String() string
String returns the constant name, or a numeric representation for unknown values.
type PropertyType ¶
type PropertyType int32
PropertyType selects a version component for GetProperty.
const ( MajorVersion PropertyType = 0 MinorVersion PropertyType = 1 PatchLevel PropertyType = 2 )
PropertyType constants.
type Result ¶
type Result int32
Result represents a custatevec API error code (custatevecStatus_t).
When the library is loaded, Result.Error returns rich messages from GetErrorName and GetErrorString. When the library is not loaded, it falls back to the numeric error code and Go-defined name.
const ( Success Result = 0 // The API call has finished successfully ErrNotInitialized Result = 1 // The library handle was not initialized ErrAllocFailed Result = 2 // Memory allocation in the library was failed ErrInvalidValue Result = 3 // Wrong parameter was passed. For example, a null pointer as input data, or an invalid enum value ErrArchMismatch Result = 4 // The device capabilities are not enough for the set of input parameters provided ErrExecutionFailed Result = 5 // Error during the execution of the device tasks ErrInternalError Result = 6 // Unknown error occurred in the library ErrNotSupported Result = 7 // API is not supported by the backend, or no CUDA-capable GPU devices found ErrInsufficientWorkspace Result = 8 // Workspace on device is too small to execute ErrSamplerNotPreprocessed Result = 9 // Sampler was called prior to preprocessing ErrNoDeviceAllocator Result = 10 // The device memory pool was not set ErrDeviceAllocatorError Result = 11 // Operation with the device memory pool failed ErrCommunicatorError Result = 12 // Inter-process communication or distributed operation failed ErrLoadingLibraryFailed Result = 13 // Dynamic loading of the shared library failed ErrInvalidConfiguration Result = 14 // Invalid configuration ErrAlreadyInitialized Result = 15 // Already initialized ErrInvalidWire Result = 16 // Invalid wire is specified ErrSystemError Result = 17 // System operation failed (e.g., file I/O, memory mapping, threading) ErrCudaError Result = 18 // CUDA runtime or driver API operation failed ErrNumericalError Result = 19 // Numerical error due to constraint violations or instability ErrResourcesNotAccessible Result = 20 // Resources are not accessible, call custatevecExStateVectorExposeResources() first ErrMaxValue Result = 21 )
custatevec error codes from custatevec.h.
type SVSwapParameters ¶
type SVSwapParameters struct {
SwapBatchIndex int32
OrgSubSVIndex int32
DstSubSVIndex int32
OrgSegmentMaskString [48]int32
DstSegmentMaskString [48]int32
SegmentMaskOrdering [48]int32
SegmentMaskLen uint32
NSegmentBits uint32
DataTransferType DataTransferType
TransferSize Index
}
SVSwapParameters holds necessary information to execute data transfers between a pair of devices.
type SVSwapWorker ¶
type SVSwapWorker uintptr
SVSwapWorker is an opaque handle for custatevecSVSwapWorkerDescriptor_t.
func NewSVSwapWorker ¶
func NewSVSwapWorker(handle Handle, communicator Communicator, orgSubSV uintptr, orgSubSVIndex int32, orgEvent driver.Event, svDataType DataType, stream driver.Stream) (SVSwapWorker, uint, uint, error)
NewSVSwapWorker creates state vector swap worker.
- handle: in the handle to cuStateVec library
- svSwapWorker: out state vector swap worker
- communicator: in a pointer to the MPI communicator
- orgSubSV: in a pointer to a sub state vector
- orgSubSVIndex: in the index of the sub state vector specified by the orgSubSV argument
- orgEvent: in the event for synchronization with the peer worker
- svDataType: in data type used by the state vector representation
- stream: in a stream that is used to locally execute kernels during data transfers
- extraWorkspaceSizeInBytes: out the size of the extra workspace needed
- minTransferWorkspaceSizeInBytes: out the minimum-required size of the transfer workspace
Wraps custatevecSVSwapWorkerCreate.
func NewSVSwapWorkerWithSemaphore ¶
func NewSVSwapWorkerWithSemaphore(handle Handle, communicator Communicator, orgSubSV uintptr, orgSubSVIndex int32, orgSemaphore uintptr, svDataType DataType, stream driver.Stream) (SVSwapWorker, uint, uint, error)
NewSVSwapWorkerWithSemaphore creates state vector swap worker with semaphore.
- handle: in the handle to cuStateVec library
- svSwapWorker: out state vector swap worker
- communicator: in a pointer to the MPI communicator
- orgSubSV: in a pointer to a sub state vector
- orgSubSVIndex: in the index of the sub state vector specified by the orgSubSV argument
- orgSemaphore: in a pointer to a device memory chunk that used for synchronization with the peer worker
- svDataType: in data type used by the state vector representation
- stream: in a stream that is used to locally execute kernels during data transfers
- extraWorkspaceSizeInBytes: out the size of the extra workspace needed
- minTransferWorkspaceSizeInBytes: out the minimum-required size of the transfer workspace
Wraps custatevecSVSwapWorkerCreateWithSemaphore.
func (SVSwapWorker) Destroy ¶
func (s SVSwapWorker) Destroy(handle Handle) error
Destroy releases the state vector swap worker.
- handle: in the handle to cuStateVec library
It is not named Close because it takes more than the handle.
Wraps custatevecSVSwapWorkerDestroy.
func (SVSwapWorker) Execute ¶
func (s SVSwapWorker) Execute(handle Handle, begin Index, end Index) error
Execute executes the data transfer.
- handle: in the handle to cuStateVec library
- begin: in the index to start transfer
- end: in the index to end transfer
Wraps custatevecSVSwapWorkerExecute.
func (SVSwapWorker) SetExtraWorkspace ¶
func (s SVSwapWorker) SetExtraWorkspace(handle Handle, extraWorkspace uintptr, extraWorkspaceSizeInBytes uint) error
SetExtraWorkspace sets extra workspace.
- handle: in the handle to cuStateVec library
- extraWorkspace: in pointer to the user-owned workspace
- extraWorkspaceSizeInBytes: in size of the user-provided workspace
Wraps custatevecSVSwapWorkerSetExtraWorkspace.
func (SVSwapWorker) SetParameters ¶
func (s SVSwapWorker) SetParameters(handle Handle, parameters *SVSwapParameters, peer int32) error
SetParameters sets state vector swap parameters.
- handle: in the handle to cuStateVec library
- parameters: in data transfer parameters
- peer: in the peer process identifier of the data transfer
Wraps custatevecSVSwapWorkerSetParameters.
func (SVSwapWorker) SetSubSVsP2P ¶
func (s SVSwapWorker) SetSubSVsP2P(handle Handle, dstSubSVsP2P *uintptr, dstSubSVIndicesP2P *int32, dstEvents *driver.Event, nDstSubSVsP2P uint32) error
SetSubSVsP2P sets sub state vector pointers accessible via GPUDirect P2P with CUDA IPC events
- handle: in the handle to cuStateVec library
- dstSubSVsP2P: in an array of pointers to sub state vectors that are accessed by GPUDirect P2P
- dstSubSVIndicesP2P: in the sub state vector indices of sub state vector pointers specified by the dstSubSVsP2P argument
- dstEvents: in events used to create peer workers
- nDstSubSVsP2P: in the number of sub state vector pointers specified by the dstSubSVsP2P argument
Wraps custatevecSVSwapWorkerSetSubSVsP2P.
func (SVSwapWorker) SetSubSVsP2PWithSemaphores ¶
func (s SVSwapWorker) SetSubSVsP2PWithSemaphores(handle Handle, dstSubSVsP2P *uintptr, dstSubSVIndicesP2P *int32, dstSemaphores *uintptr, nDstSubSVsP2P uint32) error
SetSubSVsP2PWithSemaphores sets sub state vector pointers accessible via GPUDirect P2P with semaphores
- handle: in the handle to cuStateVec library
- dstSubSVsP2P: in an array of pointers to sub state vectors that are accessed by GPUDirect P2P
- dstSubSVIndicesP2P: in the sub state vector indices of sub state vector pointers specified by the dstSubSVsP2P argument
- dstSemaphores: in semaphores used to create peer workers
- nDstSubSVsP2P: in the number of sub state vector pointers specified by the dstSubSVsP2P argument
Wraps custatevecSVSwapWorkerSetSubSVsP2PWithSemaphores.
func (SVSwapWorker) SetTransferWorkspace ¶
func (s SVSwapWorker) SetTransferWorkspace(handle Handle, transferWorkspace uintptr, transferWorkspaceSizeInBytes uint) error
SetTransferWorkspace sets transfer workspace.
- handle: in the handle to cuStateVec library
- transferWorkspace: in pointer to the user-owned workspace
- transferWorkspaceSizeInBytes: in size of the user-provided workspace
Wraps custatevecSVSwapWorkerSetTransferWorkspace.
type StateVectorType ¶
type StateVectorType int32
StateVectorType selects the state Handle.InitializeStateVector writes.
const ( StateVectorTypeZero StateVectorType = 0 // create a zero state, StateVectorTypeUniform StateVectorType = 1 // create an equal superposition of all computational basis, StateVectorTypeGhz StateVectorType = 2 // create a GHZ state, StateVectorTypeW StateVectorType = 3 // create a W state, )
func (StateVectorType) String ¶
func (e StateVectorType) String() string
String returns the constant name, or a numeric representation for unknown values.
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.