Documentation
¶
Overview ¶
Package curand provides lazy-loaded bindings for NVIDIA cuRAND.
cuRAND provides host-side pseudorandom and quasi-random number generation.
Create a Generator with CreateGenerator or CreateGeneratorHost, then configure and use it to generate values.
A generator from CreateGenerator writes to device memory, given as a driver.DevicePtr. One from CreateGeneratorHost writes to host memory: call the Host form of each generate method, such as Generator.GenerateUniformHost, which fills a slice.
Generator and Distribution Lifecycle ¶
- CreateGenerator: Create new random number generator.
- CreateGeneratorHost: Create new host CPU random number generator.
- CreatePoissonDistribution: Construct the histogram array for a Poisson distribution.
- DiscreteDistribution.Close: Destroy the histogram array for a discrete distribution (e.g. Poisson).
- Generator.Close: Destroy an existing generator.
Random Number Generation ¶
- Generator.Generate: Generate 32-bit pseudo or quasirandom numbers.
- Generator.GenerateBinomial.
- Generator.GenerateBinomialHost.
- Generator.GenerateHost.
- Generator.GenerateLogNormal: Generate log-normally distributed floats.
- Generator.GenerateLogNormalDouble: Generate log-normally distributed doubles.
- Generator.GenerateLogNormalDoubleHost.
- Generator.GenerateLogNormalHost.
- Generator.GenerateLongLong: Generate 64-bit quasirandom numbers.
- Generator.GenerateLongLongHost.
- Generator.GenerateNormal: Generate normally distributed doubles.
- Generator.GenerateNormalDouble: Generate normally distributed doubles.
- Generator.GenerateNormalDoubleHost.
- Generator.GenerateNormalHost.
- Generator.GeneratePoisson: Generate Poisson-distributed unsigned ints.
- Generator.GeneratePoissonHost.
- Generator.GenerateSeeds: Setup starting states.
- Generator.GenerateUniform: Generate uniformly distributed floats.
- Generator.GenerateUniformDouble: Generate uniformly distributed doubles.
- Generator.GenerateUniformDoubleHost.
- Generator.GenerateUniformHost.
Quasi-Random Parameters ¶
- GetDirectionVectors32: Get direction vectors for 32-bit quasirandom number generation.
- GetDirectionVectors64: Get direction vectors for 64-bit quasirandom number generation.
- GetScrambleConstants32: Get scramble constants for 32-bit scrambled Sobol' .
- GetScrambleConstants64: Get scramble constants for 64-bit scrambled Sobol' .
Library Queries ¶
- GetProperty: Return the value of the curand property.
- GetVersion: Return the version number of the library.
Generator Configuration ¶
- Generator.SetOffset: Set the absolute offset of the pseudo or quasirandom number generator.
- Generator.SetOrdering: Set the ordering of results of the pseudo or quasirandom number generator.
- Generator.SetPseudoRandomGeneratorSeed: Set the seed value of the pseudo-random number generator.
- Generator.SetQuasiRandomGeneratorDimensions: Set the number of dimensions.
- Generator.SetStream: Set the current stream for CURAND kernel launches.
Example ¶
Example generates uniform random numbers on the host with a cuRAND host generator, writing directly into Go memory — no GPU required. A fixed seed gives the same values on every run. It returns early when the cuRAND library is not available. It has no Output comment, so it is compiled but not run: a host without cuRAND prints an error instead.
package main
import (
"fmt"
"github.com/tmc/lib/nvidia/curand"
)
func main() {
gen, err := curand.CreateGeneratorHost(curand.CURAND_RNG_PseudoDefault)
if err != nil {
fmt.Println("cuRAND unavailable:", err)
return
}
defer gen.Close()
if err := gen.SetPseudoRandomGeneratorSeed(42); err != nil {
fmt.Println("seed:", err)
return
}
out := make([]float32, 4)
if err := gen.GenerateUniformHost(out); err != nil {
fmt.Println("generate:", err)
return
}
fmt.Println(out)
}
Output:
Index ¶
- Constants
- func Close() error
- func GetProperty(type_ LibraryPropertyType) (int32, error)
- func GetScrambleConstants32() (*uint32, error)
- func GetScrambleConstants64() (*uint64, error)
- func GetVersion() (int32, error)
- func Has(symbol string) bool
- func HasCreateGenerator() bool
- func HasCreateGeneratorHost() bool
- func HasCreatePoissonDistribution() bool
- func HasDestroyDistribution() bool
- func HasDestroyGenerator() bool
- func HasGenerate() bool
- func HasGenerateBinomial() bool
- func HasGenerateLogNormal() bool
- func HasGenerateLogNormalDouble() bool
- func HasGenerateLongLong() bool
- func HasGenerateNormal() bool
- func HasGenerateNormalDouble() bool
- func HasGeneratePoisson() bool
- func HasGenerateSeeds() bool
- func HasGenerateUniform() bool
- func HasGenerateUniformDouble() bool
- func HasGetDirectionVectors32() bool
- func HasGetDirectionVectors64() bool
- func HasGetProperty() bool
- func HasGetScrambleConstants32() bool
- func HasGetScrambleConstants64() bool
- func HasGetVersion() bool
- func HasSetGeneratorOffset() bool
- func HasSetGeneratorOrdering() bool
- func HasSetPseudoRandomGeneratorSeed() bool
- func HasSetQuasiRandomGeneratorDimensions() bool
- func HasSetStream() bool
- func Load(path string) error
- func Loaded() bool
- func Path() string
- type BindFailure
- type CallError
- type DirectionVectorSet
- type DirectionVectors32
- type DirectionVectors64
- type DiscreteDistribution
- type Distributionm2shiftT
- type DistributionshiftT
- type Generator
- func (g *Generator) Close() error
- func (g Generator) Generate(outputPtr driver.DevicePtr, num uint) error
- func (g Generator) GenerateBinomial(outputPtr driver.DevicePtr, num uint, n uint32, p float64) error
- func (g Generator) GenerateBinomialHost(output []uint32, n uint32, p float64) error
- func (g Generator) GenerateHost(output []uint32) error
- func (g Generator) GenerateLogNormal(outputPtr driver.DevicePtr, n uint, mean float32, stddev float32) error
- func (g Generator) GenerateLogNormalDouble(outputPtr driver.DevicePtr, n uint, mean float64, stddev float64) error
- func (g Generator) GenerateLogNormalDoubleHost(output []float64, mean float64, stddev float64) error
- func (g Generator) GenerateLogNormalHost(output []float32, mean float32, stddev float32) error
- func (g Generator) GenerateLongLong(outputPtr driver.DevicePtr, num uint) error
- func (g Generator) GenerateLongLongHost(output []uint64) error
- func (g Generator) GenerateNormal(outputPtr driver.DevicePtr, n uint, mean float32, stddev float32) error
- func (g Generator) GenerateNormalDouble(outputPtr driver.DevicePtr, n uint, mean float64, stddev float64) error
- func (g Generator) GenerateNormalDoubleHost(output []float64, mean float64, stddev float64) error
- func (g Generator) GenerateNormalHost(output []float32, mean float32, stddev float32) error
- func (g Generator) GeneratePoisson(outputPtr driver.DevicePtr, n uint, lambda float64) error
- func (g Generator) GeneratePoissonHost(output []uint32, lambda float64) error
- func (g Generator) GenerateSeeds() error
- func (g Generator) GenerateUniform(outputPtr driver.DevicePtr, num uint) error
- func (g Generator) GenerateUniformDouble(outputPtr driver.DevicePtr, num uint) error
- func (g Generator) GenerateUniformDoubleHost(output []float64) error
- func (g Generator) GenerateUniformHost(output []float32) error
- func (g Generator) SetOffset(offset uint64) error
- func (g Generator) SetOrdering(order Ordering) error
- func (g Generator) SetPseudoRandomGeneratorSeed(seed uint64) error
- func (g Generator) SetQuasiRandomGeneratorDimensions(numDimensions uint32) error
- func (g Generator) SetStream(stream driver.Stream) error
- type Histogramm2T
- type LibraryAttempt
- type LibraryConflictError
- type LibraryError
- type LibraryPropertyType
- type MethodT
- type Ordering
- type Result
- type RngType
- type SymbolError
- type VersionMismatchError
Examples ¶
Constants ¶
const ( // Version is CURAND_VERSION. This is the version of the headers the bindings were generated from, not of the library loaded at run time. [GetVersion] reports that. Version = 10405 // VerBuild is CURAND_VER_BUILD. This is the version of the headers the bindings were generated from, not of the library loaded at run time. [GetVersion] reports that. VerBuild = 25 // VerMajor is CURAND_VER_MAJOR. This is the version of the headers the bindings were generated from, not of the library loaded at run time. [GetVersion] reports that. VerMajor = 10 // VerMinor is CURAND_VER_MINOR. This is the version of the headers the bindings were generated from, not of the library loaded at run time. [GetVersion] reports that. VerMinor = 4 // VerPatch is CURAND_VER_PATCH. This is the version of the headers the bindings were generated from, not of the library loaded at run time. [GetVersion] reports that. VerPatch = 5 )
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_ LibraryPropertyType) (int32, error)
GetProperty returns the value of the curand property.
Return the number for the property described by type of the dynamically linked CURAND library.
- type_: CUDA library property
- value: integer value for the requested property
Wraps curandGetProperty.
func GetScrambleConstants32 ¶
GetScrambleConstants32 gets scramble constants for 32-bit scrambled Sobol' .
Get a pointer to an array of scramble constants that can be used for quasirandom number generation. The resulting pointer will reference an array of unsinged ints in host memory.
The array contains constants for many dimensions. Each dimension has a single unsigned int constant.
- constants: Address of pointer in which to return scramble constants
Wraps curandGetScrambleConstants32.
func GetScrambleConstants64 ¶
GetScrambleConstants64 gets scramble constants for 64-bit scrambled Sobol' .
Get a pointer to an array of scramble constants that can be used for quasirandom number generation. The resulting pointer will reference an array of unsinged long longs in host memory.
The array contains constants for many dimensions. Each dimension has a single unsigned long long constant.
- constants: Address of pointer in which to return scramble constants
Wraps curandGetScrambleConstants64.
func GetVersion ¶
GetVersion returns the version number of the library.
Return the version number of the dynamically linked CURAND library. The format is the same as CUDART_VERSION from the CUDA Runtime. The only supported configuration is CURAND version equal to CUDA Runtime version.
- version: CURAND library version
Wraps curandGetVersion.
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 HasCreateGenerator ¶
func HasCreateGenerator() bool
HasCreateGenerator reports whether curandCreateGenerator resolved in the loaded library.
func HasCreateGeneratorHost ¶
func HasCreateGeneratorHost() bool
HasCreateGeneratorHost reports whether curandCreateGeneratorHost resolved in the loaded library.
func HasCreatePoissonDistribution ¶
func HasCreatePoissonDistribution() bool
HasCreatePoissonDistribution reports whether curandCreatePoissonDistribution resolved in the loaded library.
func HasDestroyDistribution ¶
func HasDestroyDistribution() bool
HasDestroyDistribution reports whether curandDestroyDistribution resolved in the loaded library.
func HasDestroyGenerator ¶
func HasDestroyGenerator() bool
HasDestroyGenerator reports whether curandDestroyGenerator resolved in the loaded library.
func HasGenerate ¶
func HasGenerate() bool
HasGenerate reports whether curandGenerate resolved in the loaded library.
func HasGenerateBinomial ¶
func HasGenerateBinomial() bool
HasGenerateBinomial reports whether curandGenerateBinomial resolved in the loaded library.
func HasGenerateLogNormal ¶
func HasGenerateLogNormal() bool
HasGenerateLogNormal reports whether curandGenerateLogNormal resolved in the loaded library.
func HasGenerateLogNormalDouble ¶
func HasGenerateLogNormalDouble() bool
HasGenerateLogNormalDouble reports whether curandGenerateLogNormalDouble resolved in the loaded library.
func HasGenerateLongLong ¶
func HasGenerateLongLong() bool
HasGenerateLongLong reports whether curandGenerateLongLong resolved in the loaded library.
func HasGenerateNormal ¶
func HasGenerateNormal() bool
HasGenerateNormal reports whether curandGenerateNormal resolved in the loaded library.
func HasGenerateNormalDouble ¶
func HasGenerateNormalDouble() bool
HasGenerateNormalDouble reports whether curandGenerateNormalDouble resolved in the loaded library.
func HasGeneratePoisson ¶
func HasGeneratePoisson() bool
HasGeneratePoisson reports whether curandGeneratePoisson resolved in the loaded library.
func HasGenerateSeeds ¶
func HasGenerateSeeds() bool
HasGenerateSeeds reports whether curandGenerateSeeds resolved in the loaded library.
func HasGenerateUniform ¶
func HasGenerateUniform() bool
HasGenerateUniform reports whether curandGenerateUniform resolved in the loaded library.
func HasGenerateUniformDouble ¶
func HasGenerateUniformDouble() bool
HasGenerateUniformDouble reports whether curandGenerateUniformDouble resolved in the loaded library.
func HasGetDirectionVectors32 ¶
func HasGetDirectionVectors32() bool
HasGetDirectionVectors32 reports whether curandGetDirectionVectors32 resolved in the loaded library.
func HasGetDirectionVectors64 ¶
func HasGetDirectionVectors64() bool
HasGetDirectionVectors64 reports whether curandGetDirectionVectors64 resolved in the loaded library.
func HasGetProperty ¶
func HasGetProperty() bool
HasGetProperty reports whether curandGetProperty resolved in the loaded library.
func HasGetScrambleConstants32 ¶
func HasGetScrambleConstants32() bool
HasGetScrambleConstants32 reports whether curandGetScrambleConstants32 resolved in the loaded library.
func HasGetScrambleConstants64 ¶
func HasGetScrambleConstants64() bool
HasGetScrambleConstants64 reports whether curandGetScrambleConstants64 resolved in the loaded library.
func HasGetVersion ¶
func HasGetVersion() bool
HasGetVersion reports whether curandGetVersion resolved in the loaded library.
func HasSetGeneratorOffset ¶
func HasSetGeneratorOffset() bool
HasSetGeneratorOffset reports whether curandSetGeneratorOffset resolved in the loaded library.
func HasSetGeneratorOrdering ¶
func HasSetGeneratorOrdering() bool
HasSetGeneratorOrdering reports whether curandSetGeneratorOrdering resolved in the loaded library.
func HasSetPseudoRandomGeneratorSeed ¶
func HasSetPseudoRandomGeneratorSeed() bool
HasSetPseudoRandomGeneratorSeed reports whether curandSetPseudoRandomGeneratorSeed resolved in the loaded library.
func HasSetQuasiRandomGeneratorDimensions ¶
func HasSetQuasiRandomGeneratorDimensions() bool
HasSetQuasiRandomGeneratorDimensions reports whether curandSetQuasiRandomGeneratorDimensions resolved in the loaded library.
func HasSetStream ¶
func HasSetStream() bool
HasSetStream reports whether curandSetStream 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 DirectionVectorSet ¶
type DirectionVectorSet int32
DirectionVectorSet represents curandDirectionVectorSet_t.
const ( CURAND_DirectionVectors32Joekuo6 DirectionVectorSet = 101 // Specific set of 32-bit direction vectors generated from polynomials recommended by S. Joe and F. Y. Kuo, for up to 20,000 dimensions CURAND_ScrambledDirectionVectors32Joekuo6 DirectionVectorSet = 102 // Specific set of 32-bit direction vectors generated from polynomials recommended by S. Joe and F. Y. Kuo, for up to 20,000 dimensions, and scrambled CURAND_DirectionVectors64Joekuo6 DirectionVectorSet = 103 // Specific set of 64-bit direction vectors generated from polynomials recommended by S. Joe and F. Y. Kuo, for up to 20,000 dimensions CURAND_ScrambledDirectionVectors64Joekuo6 DirectionVectorSet = 104 // Specific set of 64-bit direction vectors generated from polynomials recommended by S. Joe and F. Y. Kuo, for up to 20,000 dimensions, and scrambled )
func (DirectionVectorSet) String ¶
func (e DirectionVectorSet) String() string
String returns the constant name, or a numeric representation for unknown values.
type DirectionVectors32 ¶
type DirectionVectors32 [32]uint32
DirectionVectors32 holds one 32-bit Sobol direction-vector set.
func GetDirectionVectors32 ¶
func GetDirectionVectors32(set DirectionVectorSet) (*DirectionVectors32, error)
GetDirectionVectors32 gets direction vectors for 32-bit quasirandom number generation.
Get a pointer to an array of direction vectors that can be used for quasirandom number generation. The resulting pointer will reference an array of direction vectors in host memory.
The array contains vectors for many dimensions. Each dimension has 32 vectors. Each individual vector is an unsigned int.
Legal values for set are:
- CURAND_DirectionVectors32Joekuo6 (20,000 dimensions)
- CURAND_ScrambledDirectionVectors32Joekuo6 (20,000 dimensions)
Parameters:
- vectors: Address of pointer in which to return direction vectors
- set: Which set of direction vectors to use
Wraps curandGetDirectionVectors32.
type DirectionVectors64 ¶
type DirectionVectors64 [64]uint64
DirectionVectors64 holds one 64-bit Sobol direction-vector set.
func GetDirectionVectors64 ¶
func GetDirectionVectors64(set DirectionVectorSet) (*DirectionVectors64, error)
GetDirectionVectors64 gets direction vectors for 64-bit quasirandom number generation.
Get a pointer to an array of direction vectors that can be used for quasirandom number generation. The resulting pointer will reference an array of direction vectors in host memory.
The array contains vectors for many dimensions. Each dimension has 64 vectors. Each individual vector is an unsigned long long.
Legal values for set are:
- CURAND_DirectionVectors64Joekuo6 (20,000 dimensions)
- CURAND_ScrambledDirectionVectors64Joekuo6 (20,000 dimensions)
Parameters:
- vectors: Address of pointer in which to return direction vectors
- set: Which set of direction vectors to use
Wraps curandGetDirectionVectors64.
type DiscreteDistribution ¶
type DiscreteDistribution uintptr
DiscreteDistribution is an opaque handle for curandDiscreteDistribution_t.
func CreatePoissonDistribution ¶
func CreatePoissonDistribution(lambda float64) (DiscreteDistribution, error)
CreatePoissonDistribution Construct the histogram array for a Poisson distribution.
Construct the histogram array for the Poisson distribution with lambda lambda. For lambda greater than 2000, an approximation with a normal distribution is used.
- lambda: lambda for the Poisson distribution
- discreteDistribution: pointer to the histogram in device memory
Wraps curandCreatePoissonDistribution.
func (*DiscreteDistribution) Close ¶
func (d *DiscreteDistribution) Close() error
Close destroys the histogram array for a discrete distribution (e.g. Poisson).
Destroy the histogram array for a discrete distribution created by CreatePoissonDistribution.
If d is zero, Close returns nil. Otherwise Close sets d to zero when the call succeeds and leaves it unchanged when it fails. Only d is zeroed: a copy of it still refers to the released object.
Wraps curandDestroyDistribution.
type Distributionm2shiftT ¶
type Distributionm2shiftT uintptr
Distributionm2shiftT is an opaque handle for curandDistributionM2Shift_t.
type DistributionshiftT ¶
type DistributionshiftT uintptr
DistributionshiftT is an opaque handle for curandDistributionShift_t.
type Generator ¶
type Generator uintptr
Generator is an opaque handle for curandGenerator_t.
func CreateGenerator ¶
CreateGenerator creates new random number generator.
Creates a new random number generator of type rngType and returns it.
Legal values for rngType are:
- CURAND_RNG_PseudoDefault
- CURAND_RNG_PseudoXorwow
- CURAND_RNG_PseudoMrg32k3a
- CURAND_RNG_PseudoMtgp32
- CURAND_RNG_PseudoMt19937
- CURAND_RNG_PseudoPhilox43210
- CURAND_RNG_QuasiDefault
- CURAND_RNG_QuasiSobol32
- CURAND_RNG_QuasiScrambledSobol32
- CURAND_RNG_QuasiSobol64
- CURAND_RNG_QuasiScrambledSobol64
When rngType is CURAND_RNG_PseudoDefault, the type chosen is CURAND_RNG_PseudoXorwow. When rngType is CURAND_RNG_QuasiDefault, the type chosen is CURAND_RNG_QuasiSobol32.
The default values for rngType = CURAND_RNG_PseudoXorwow are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_PseudoMrg32k3a are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_PseudoMtgp32 are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_PseudoMt19937 are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
* The default values for rngType = CURAND_RNG_PseudoPhilox43210 are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_QuasiSobol32 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
The default values for rngType = CURAND_RNG_QuasiSobol64 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
The default values for rngType = CURAND_RNG_QUASI_SCRAMBBLED_SOBOL32 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
The default values for rngType = CURAND_RNG_QuasiScrambledSobol64 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
Parameters:
- generator: Pointer to generator
- rngType: Type of generator to create
Wraps curandCreateGenerator.
func CreateGeneratorHost ¶
CreateGeneratorHost creates new host CPU random number generator.
Creates a new host CPU random number generator of type rngType and returns it.
Legal values for rngType are:
- CURAND_RNG_PseudoDefault
- CURAND_RNG_PseudoXorwow
- CURAND_RNG_PseudoMrg32k3a
- CURAND_RNG_PseudoMtgp32
- CURAND_RNG_PseudoMt19937
- CURAND_RNG_PseudoPhilox43210
- CURAND_RNG_QuasiDefault
- CURAND_RNG_QuasiSobol32
- CURAND_RNG_QuasiScrambledSobol32
- CURAND_RNG_QuasiSobol64
- CURAND_RNG_QuasiScrambledSobol64
When rngType is CURAND_RNG_PseudoDefault, the type chosen is CURAND_RNG_PseudoXorwow. When rngType is CURAND_RNG_QuasiDefault, the type chosen is CURAND_RNG_QuasiSobol32.
The default values for rngType = CURAND_RNG_PseudoXorwow are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_PseudoMrg32k3a are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_PseudoMtgp32 are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_PseudoMt19937 are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
* The default values for rngType = CURAND_RNG_PseudoPhilox43210 are:
- seed = 0
- offset = 0
- ordering = CURAND_ORDERING_PseudoDefault
The default values for rngType = CURAND_RNG_QuasiSobol32 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
The default values for rngType = CURAND_RNG_QuasiSobol64 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
The default values for rngType = CURAND_RNG_QuasiScrambledSobol32 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
The default values for rngType = CURAND_RNG_QuasiScrambledSobol64 are:
- dimensions = 1
- offset = 0
- ordering = CURAND_ORDERING_QuasiDefault
Parameters:
- generator: Pointer to generator
- rngType: Type of generator to create
Wraps curandCreateGeneratorHost.
func (*Generator) Close ¶
Close destroys an existing generator.
Destroy an existing generator and free all memory associated with its state.
If g is zero, Close returns nil. Otherwise Close sets g to zero when the call succeeds and leaves it unchanged when it fails. Only g is zeroed: a copy of it still refers to the released object.
Wraps curandDestroyGenerator.
func (Generator) Generate ¶
Generate generates 32-bit pseudo or quasirandom numbers.
Use generator to generate num 32-bit results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 32-bit values with every bit random.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- num: Number of random 32-bit values to generate
Wraps curandGenerate.
func (Generator) GenerateBinomial ¶
func (g Generator) GenerateBinomial(outputPtr driver.DevicePtr, num uint, n uint32, p float64) error
GenerateBinomial wraps curandGenerateBinomial.
func (Generator) GenerateBinomialHost ¶
GenerateBinomialHost is GenerateBinomial for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateHost ¶
GenerateHost is Generate for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateLogNormal ¶
func (g Generator) GenerateLogNormal(outputPtr driver.DevicePtr, n uint, mean float32, stddev float32) error
GenerateLogNormal generates log-normally distributed floats.
Use generator to generate n float results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 32-bit floating point values with log-normal distribution based on an associated normal distribution with mean mean and standard deviation stddev.
Normally distributed results are generated from pseudorandom generators with a Box-Muller transform, and so require n to be even. Quasirandom generators use an inverse cumulative distribution function to preserve dimensionality. The normally distributed results are transformed into log-normal distribution.
There may be slight numerical differences between results generated on the GPU with generators created with CreateGenerator and results calculated on the CPU with generators created with CreateGeneratorHost. These differences arise because of differences in results for transcendental functions. In addition, future versions of CURAND may use newer versions of the CUDA math library, so different versions of CURAND may give slightly different numerical values.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- n: Number of floats to generate
- mean: Mean of associated normal distribution
- stddev: Standard deviation of associated normal distribution
Wraps curandGenerateLogNormal.
func (Generator) GenerateLogNormalDouble ¶
func (g Generator) GenerateLogNormalDouble(outputPtr driver.DevicePtr, n uint, mean float64, stddev float64) error
GenerateLogNormalDouble generates log-normally distributed doubles.
Use generator to generate n double results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 64-bit floating point values with log-normal distribution based on an associated normal distribution with mean mean and standard deviation stddev.
Normally distributed results are generated from pseudorandom generators with a Box-Muller transform, and so require n to be even. Quasirandom generators use an inverse cumulative distribution function to preserve dimensionality. The normally distributed results are transformed into log-normal distribution.
There may be slight numerical differences between results generated on the GPU with generators created with CreateGenerator and results calculated on the CPU with generators created with CreateGeneratorHost. These differences arise because of differences in results for transcendental functions. In addition, future versions of CURAND may use newer versions of the CUDA math library, so different versions of CURAND may give slightly different numerical values.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- n: Number of doubles to generate
- mean: Mean of normal distribution
- stddev: Standard deviation of normal distribution
Wraps curandGenerateLogNormalDouble.
func (Generator) GenerateLogNormalDoubleHost ¶
func (g Generator) GenerateLogNormalDoubleHost(output []float64, mean float64, stddev float64) error
GenerateLogNormalDoubleHost is GenerateLogNormalDouble for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateLogNormalHost ¶
GenerateLogNormalHost is GenerateLogNormal for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateLongLong ¶
GenerateLongLong generates 64-bit quasirandom numbers.
Use generator to generate num 64-bit results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 64-bit values with every bit random.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- num: Number of random 64-bit values to generate
Wraps curandGenerateLongLong.
func (Generator) GenerateLongLongHost ¶
GenerateLongLongHost is GenerateLongLong for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateNormal ¶
func (g Generator) GenerateNormal(outputPtr driver.DevicePtr, n uint, mean float32, stddev float32) error
GenerateNormal generates normally distributed doubles.
Use generator to generate n float results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 32-bit floating point values with mean mean and standard deviation stddev.
Normally distributed results are generated from pseudorandom generators with a Box-Muller transform, and so require n to be even. Quasirandom generators use an inverse cumulative distribution function to preserve dimensionality.
There may be slight numerical differences between results generated on the GPU with generators created with CreateGenerator and results calculated on the CPU with generators created with CreateGeneratorHost. These differences arise because of differences in results for transcendental functions. In addition, future versions of CURAND may use newer versions of the CUDA math library, so different versions of CURAND may give slightly different numerical values.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- n: Number of floats to generate
- mean: Mean of normal distribution
- stddev: Standard deviation of normal distribution
Wraps curandGenerateNormal.
func (Generator) GenerateNormalDouble ¶
func (g Generator) GenerateNormalDouble(outputPtr driver.DevicePtr, n uint, mean float64, stddev float64) error
GenerateNormalDouble generates normally distributed doubles.
Use generator to generate n double results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 64-bit floating point values with mean mean and standard deviation stddev.
Normally distributed results are generated from pseudorandom generators with a Box-Muller transform, and so require n to be even. Quasirandom generators use an inverse cumulative distribution function to preserve dimensionality.
There may be slight numerical differences between results generated on the GPU with generators created with CreateGenerator and results calculated on the CPU with generators created with CreateGeneratorHost. These differences arise because of differences in results for transcendental functions. In addition, future versions of CURAND may use newer versions of the CUDA math library, so different versions of CURAND may give slightly different numerical values.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- n: Number of doubles to generate
- mean: Mean of normal distribution
- stddev: Standard deviation of normal distribution
Wraps curandGenerateNormalDouble.
func (Generator) GenerateNormalDoubleHost ¶
GenerateNormalDoubleHost is GenerateNormalDouble for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateNormalHost ¶
GenerateNormalHost is GenerateNormal for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GeneratePoisson ¶
GeneratePoisson generates Poisson-distributed unsigned ints.
Use generator to generate n unsigned int results into device memory at outputPtr. The device memory must have been previously allocated and must be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 32-bit unsigned int point values with Poisson distribution, with lambda lambda.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- n: Number of unsigned ints to generate
- lambda: lambda for the Poisson distribution
Wraps curandGeneratePoisson.
func (Generator) GeneratePoissonHost ¶
GeneratePoissonHost is GeneratePoisson for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateSeeds ¶
GenerateSeeds Setup starting states.
Generate the starting state of the generator. This function is automatically called by generation functions such as Generator.Generate and Generator.GenerateUniform. It can be called manually for performance testing reasons to separate timings for starting state generation and random number generation.
Wraps curandGenerateSeeds.
func (Generator) GenerateUniform ¶
GenerateUniform generates uniformly distributed floats.
Use generator to generate num float results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 32-bit floating point values between 0.0f and 1.0f, excluding 0.0f and including 1.0f.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- num: Number of floats to generate
Wraps curandGenerateUniform.
func (Generator) GenerateUniformDouble ¶
GenerateUniformDouble generates uniformly distributed doubles.
Use generator to generate num double results into the device memory at outputPtr. The device memory must have been previously allocated and be large enough to hold all the results. Launches are done with the stream set using Generator.SetStream, or the null stream if no stream has been set.
Results are 64-bit double precision floating point values between 0.0 and 1.0, excluding 0.0 and including 1.0.
- outputPtr: Pointer to device memory to store CUDA-generated results, or Pointer to host memory to store CPU-generated results
- num: Number of doubles to generate
Wraps curandGenerateUniformDouble.
func (Generator) GenerateUniformDoubleHost ¶
GenerateUniformDoubleHost is GenerateUniformDouble for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) GenerateUniformHost ¶
GenerateUniformHost is GenerateUniform for host memory. It fills all of output, len(output) values, for a handle whose results are in host memory.
func (Generator) SetOffset ¶
SetOffset sets the absolute offset of the pseudo or quasirandom number generator.
All values of offset are valid. The offset position is absolute, not relative to the current position in the sequence.
- offset: Absolute offset position
Wraps curandSetGeneratorOffset.
func (Generator) SetOrdering ¶
SetOrdering sets the ordering of results of the pseudo or quasirandom number generator.
Legal values of order for pseudorandom generators are:
- CURAND_ORDERING_PseudoDefault
- CURAND_ORDERING_PseudoBest
- CURAND_ORDERING_PseudoSeeded
- CURAND_ORDERING_PseudoLegacy
Legal values of order for quasirandom generators are:
Parameters:
- order: Ordering of results
Wraps curandSetGeneratorOrdering.
func (Generator) SetPseudoRandomGeneratorSeed ¶
SetPseudoRandomGeneratorSeed sets the seed value of the pseudo-random number generator.
Set the seed value of the pseudorandom number generator. All values of seed are valid. Different seeds will produce different sequences. Different seeds will often not be statistically correlated with each other, but some pairs of seed values may generate sequences which are statistically correlated.
- seed: Seed value
Wraps curandSetPseudoRandomGeneratorSeed.
func (Generator) SetQuasiRandomGeneratorDimensions ¶
SetQuasiRandomGeneratorDimensions sets the number of dimensions.
Set the number of dimensions to be generated by the quasirandom number generator.
Legal values for numDimensions are 1 to 20000.
- numDimensions: Number of dimensions
Wraps curandSetQuasiRandomGeneratorDimensions.
type Histogramm2T ¶
type Histogramm2T uintptr
Histogramm2T is an opaque handle for curandHistogramM2_t.
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 libcurand could not be opened. Attempts lists every name tried in order. Path is set when an explicit path, from Load or CURAND_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 LibraryPropertyType ¶
type LibraryPropertyType int32
LibraryPropertyType identifies a CUDA library property.
const ( MajorVersion LibraryPropertyType = 0 MinorVersion LibraryPropertyType = 1 PatchLevel LibraryPropertyType = 2 )
LibraryPropertyType constants.
type MethodT ¶
type MethodT int32
MethodT represents curandMethod_t.
const ( ChooseBest MethodT = 0 // choose best depends on args Itr MethodT = 1 Knuth MethodT = 2 Hitr MethodT = 3 M1 MethodT = 4 M2 MethodT = 5 BinarySearch MethodT = 6 DiscreteGauss MethodT = 7 Rejection MethodT = 8 DeviceApi MethodT = 9 FastRejection MethodT = 10 N3RD MethodT = 11 Definition MethodT = 12 Poisson MethodT = 13 )
type Ordering ¶
type Ordering int32
Ordering represents curandOrdering_t.
const ( CURAND_ORDERING_PseudoBest Ordering = 100 // Best ordering for pseudorandom results CURAND_ORDERING_PseudoDefault Ordering = 101 // Specific default thread sequence for pseudorandom results, same as [CURAND_ORDERING_PseudoBest] CURAND_ORDERING_PseudoSeeded Ordering = 102 // Specific seeding pattern for fast lower quality pseudorandom results CURAND_ORDERING_PseudoLegacy Ordering = 103 // Specific legacy sequence for pseudorandom results, guaranteed to remain the same for all cuRAND release CURAND_ORDERING_PseudoDynamic Ordering = 104 // Specific ordering adjusted to the device it is being executed on, provides the best performance CURAND_ORDERING_QuasiDefault Ordering = 201 // Specific n-dimensional ordering for quasirandom results )
type Result ¶
type Result int32
Result represents a curand API error code (curandStatus_t).
const ( Success Result = 0 // No errors ErrVersionMismatch Result = 100 // Header file and linked library version do not match ErrNotInitialized Result = 101 // Generator not initialized ErrAllocationFailed Result = 102 // Memory allocation failed ErrTypeError Result = 103 // Generator is wrong type ErrOutOfRange Result = 104 // Argument out of range ErrLengthNotMultiple Result = 105 // Length requested is not a multple of dimension ErrDoublePrecisionRequired Result = 106 // GPU does not have double precision required by MRG32k3a ErrLaunchFailure Result = 201 // Kernel launch failure ErrPreexistingFailure Result = 202 // Preexisting failure on library entry ErrInitializationFailed Result = 203 // Initialization of CUDA failed ErrArchMismatch Result = 204 // Architecture mismatch, GPU does not support requested feature ErrInternalError Result = 999 // Internal library error )
curand error codes from curand.h.
type RngType ¶
type RngType int32
RngType represents curandRngType_t.
const ( CURAND_RNG_Test RngType = 0 CURAND_RNG_PseudoDefault RngType = 100 // Default pseudorandom generator CURAND_RNG_PseudoXorwow RngType = 101 // XORWOW pseudorandom generator CURAND_RNG_PseudoMrg32k3a RngType = 121 // MRG32k3a pseudorandom generator CURAND_RNG_PseudoMtgp32 RngType = 141 // Mersenne Twister MTGP32 pseudorandom generator CURAND_RNG_PseudoMt19937 RngType = 142 // Mersenne Twister MT19937 pseudorandom generator CURAND_RNG_PseudoPhilox43210 RngType = 161 // PHILOX-4x32-10 pseudorandom generator CURAND_RNG_QuasiDefault RngType = 200 // Default quasirandom generator CURAND_RNG_QuasiSobol32 RngType = 201 // Sobol32 quasirandom generator CURAND_RNG_QuasiScrambledSobol32 RngType = 202 // Scrambled Sobol32 quasirandom generator CURAND_RNG_QuasiSobol64 RngType = 203 // Sobol64 quasirandom generator CURAND_RNG_QuasiScrambledSobol64 RngType = 204 // Scrambled Sobol64 quasirandom generator )
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 VersionMismatchError ¶
type VersionMismatchError struct {
Path string // the library that was opened
Want int // major version these bindings were generated for
Got int // major version the library reports
Raw int // the version value the library reported, undecoded
}
VersionMismatchError reports that the shared library that opened is not from the version train curand was generated for. dlsym matches on name alone, so a library from a neighbouring train opens and resolves nearly every symbol; asking it its own version is what tells the two apart.
func (*VersionMismatchError) Error ¶
func (e *VersionMismatchError) Error() string
Error reports which library was opened and the two majors that disagree.
A decoder is only a decoder for the version schemes it was measured against, and a library from a train that predates the scheme can report a value it does not decode. Naming a major of 0 in that case would attribute to the library a claim it never made, so the raw value is reported instead.