public class JCurand extends Object
Modifier and Type | Method and Description |
---|---|
static int |
curandCreateGenerator(curandGenerator generator,
int rng_type)
Create new random number generator.
|
static int |
curandCreateGeneratorHost(curandGenerator generator,
int rng_type)
Create new host CPU random number generator.
|
static int |
curandCreatePoissonDistribution(double lambda,
curandDiscreteDistribution discrete_distribution)
Construct the histogram array for a Poisson distribution.
|
static int |
curandDestroyDistribution(curandDiscreteDistribution discrete_distribution)
Destroy the histogram array for a discrete distribution (e.g.
|
static int |
curandDestroyGenerator(curandGenerator generator)
Destroy an existing generator.
|
static int |
curandGenerate(curandGenerator generator,
Pointer outputPtr,
long num)
Generate 32-bit pseudo or quasirandom numbers.
|
static int |
curandGenerateLogNormal(curandGenerator generator,
Pointer outputPtr,
long n,
float mean,
float stddev)
Generate log-normally distributed floats.
|
static int |
curandGenerateLogNormalDouble(curandGenerator generator,
Pointer outputPtr,
long n,
double mean,
double stddev)
Generate log-normally distributed doubles.
|
static int |
curandGenerateLongLong(curandGenerator generator,
Pointer outputPtr,
long num)
Generate 64-bit quasirandom numbers.
|
static int |
curandGenerateNormal(curandGenerator generator,
Pointer outputPtr,
long n,
float mean,
float stddev)
Generate normally distributed floats.
|
static int |
curandGenerateNormalDouble(curandGenerator generator,
Pointer outputPtr,
long n,
double mean,
double stddev)
Generate normally distributed doubles.
|
static int |
curandGeneratePoisson(curandGenerator generator,
Pointer outputPtr,
long n,
double lambda)
Generate Poisson-distributed unsigned ints.
|
static int |
curandGenerateSeeds(curandGenerator generator)
Setup starting states.
|
static int |
curandGenerateUniform(curandGenerator generator,
Pointer outputPtr,
long num)
Generate uniformly distributed floats.
|
static int |
curandGenerateUniformDouble(curandGenerator generator,
Pointer outputPtr,
long num)
Generate uniformly distributed doubles.
|
static int |
curandGetDirectionVectors32(int[][][] vectors,
int set)
Get direction vectors for 32-bit quasirandom number generation.
|
static int |
curandGetDirectionVectors64(long[][][] vectors,
int set)
Get direction vectors for 64-bit quasirandom number generation.
|
static int |
curandGetProperty(int type,
int[] value)
Obtains the value of the specified property.
|
static int |
curandGetScrambleConstants32(int[][] constants)
Get scramble constants for 32-bit scrambled Sobol' .
|
static int |
curandGetScrambleConstants64(long[][] constants)
Get scramble constants for 64-bit scrambled Sobol' .
|
static int |
curandGetVersion(int[] version)
Return the version number of the library.
|
static int |
curandSetGeneratorOffset(curandGenerator generator,
long offset)
Set the absolute offset of the pseudo or quasirandom number generator.
|
static int |
curandSetGeneratorOrdering(curandGenerator generator,
int order)
Set the ordering of results of the pseudo or quasirandom number generator.
|
static int |
curandSetPseudoRandomGeneratorSeed(curandGenerator generator,
long seed)
Set the seed value of the pseudo-random number generator.
|
static int |
curandSetQuasiRandomGeneratorDimensions(curandGenerator generator,
int num_dimensions)
Set the number of dimensions.
|
static int |
curandSetStream(curandGenerator generator,
cudaStream_t stream)
Set the current stream for CURAND kernel launches.
|
static void |
initialize()
Initializes the native library.
|
static void |
setExceptionsEnabled(boolean enabled)
Enables or disables exceptions.
|
static void |
setLogLevel(LogLevel logLevel)
Set the specified log level for the JCurand library.
|
public static void initialize()
public static void setLogLevel(LogLevel logLevel)
logLevel
- The log level to use.public static void setExceptionsEnabled(boolean enabled)
curandStatus
from the native methods.
If exceptions are enabled, a CudaException with a detailed error
message will be thrown if a method is about to set a result code
that is not curandStatus.CURAND_STATUS_SUCCESSenabled
- Whether exceptions are enabledpublic static int curandCreateGenerator(curandGenerator generator, int rng_type)
Create new random number generator. Creates a new random number generator of type rng_type and returns it in *generator. Legal values for rng_type are: - CURAND_RNG_PSEUDO_DEFAULT - CURAND_RNG_PSEUDO_XORWOW - CURAND_RNG_PSEUDO_MRG32K3A - CURAND_RNG_PSEUDO_MTGP32 - CURAND_RNG_PSEUDO_MT19937 - CURAND_RNG_PSEUDO_PHILOX4_32_10 - CURAND_RNG_QUASI_DEFAULT - CURAND_RNG_QUASI_SOBOL32 - CURAND_RNG_QUASI_SCRAMBLED_SOBOL32 - CURAND_RNG_QUASI_SOBOL64 - CURAND_RNG_QUASI_SCRAMBLED_SOBOL64 When rng_type is CURAND_RNG_PSEUDO_DEFAULT, the type chosen is CURAND_RNG_PSEUDO_XORWOW. When rng_type is CURAND_RNG_QUASI_DEFAULT, the type chosen is CURAND_RNG_QUASI_SOBOL32. The default values for rng_type = CURAND_RNG_PSEUDO_XORWOW are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_PSEUDO_MRG32K3A are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_PSEUDO_MTGP32 are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for \p rng_type = CURAND_RNG_PSEUDO_MT19937 are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_PSEUDO_PHILOX4_32_10 are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SOBOL32 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SOBOL64 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SCRAMBBLED_SOBOL32 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SCRAMBLED_SOBOL64 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT
generator
- - Pointer to generatorrng_type
- - Type of generator to createpublic static int curandCreateGeneratorHost(curandGenerator generator, int rng_type)
Create new host CPU random number generator. Creates a new host CPU random number generator of type rng_type and returns it in *generator. Legal values for rng_type are: - CURAND_RNG_PSEUDO_DEFAULT - CURAND_RNG_PSEUDO_XORWOW - CURAND_RNG_PSEUDO_MRG32K3A - CURAND_RNG_PSEUDO_MTGP32 - CURAND_RNG_PSEUDO_MT19937 - CURAND_RNG_PSEUDO_PHILOX4_32_10 - CURAND_RNG_QUASI_DEFAULT - CURAND_RNG_QUASI_SOBOL32 When rng_type is CURAND_RNG_PSEUDO_DEFAULT, the type chosen is CURAND_RNG_PSEUDO_XORWOW. When rng_type is CURAND_RNG_QUASI_DEFAULT, the type chosen is CURAND_RNG_QUASI_SOBOL32. The default values for rng_type = CURAND_RNG_PSEUDO_XORWOW are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_PSEUDO_MRG32K3A are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_PSEUDO_MTGP32 are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for \p rng_type = CURAND_RNG_PSEUDO_MT19937 are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_PSEUDO_PHILOX4_32_10 are: - seed = 0 - offset = 0 - ordering = CURAND_ORDERING_PSEUDO_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SOBOL32 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SOBOL64 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SCRAMBLED_SOBOL32 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT The default values for rng_type = CURAND_RNG_QUASI_SCRAMBLED_SOBOL64 are: - dimensions = 1 - offset = 0 - ordering = CURAND_ORDERING_QUASI_DEFAULT
generator
- - Pointer to generatorrng_type
- - Type of generator to createpublic static int curandDestroyGenerator(curandGenerator generator)
Destroy an existing generator. Destroy an existing generator and free all memory associated with its state.
generator
- - Generator to destroypublic static int curandGetVersion(int[] version)
Return the version number of the library. Return in *version 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 versionpublic static int curandGetProperty(int type, int[] value)
type
- The libraryPropertyType
value
- The valuepublic static int curandSetStream(curandGenerator generator, cudaStream_t stream)
Set the current stream for CURAND kernel launches. Set the current stream for CURAND kernel launches. All library functions will use this stream until set again.
generator
- - Generator to modifystream
- - Stream to use or ::NULL for null streampublic static int curandSetPseudoRandomGeneratorSeed(curandGenerator generator, long seed)
Set 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.
generator
- - Generator to modifyseed
- - Seed valuepublic static int curandSetGeneratorOffset(curandGenerator generator, long offset)
Set the absolute offset of the pseudo or quasirandom number generator. Set 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.
generator
- - Generator to modifyoffset
- - Absolute offset positionpublic static int curandSetGeneratorOrdering(curandGenerator generator, int order)
Set the ordering of results of the pseudo or quasirandom number generator. Set the ordering of results of the pseudo or quasirandom number generator. Legal values of order for pseudorandom generators are: - CURAND_ORDERING_PSEUDO_DEFAULT - CURAND_ORDERING_PSEUDO_BEST - CURAND_ORDERING_PSEUDO_SEEDED Legal values of order for quasirandom generators are: - CURAND_ORDERING_QUASI_DEFAULT
generator
- - Generator to modifyorder
- - Ordering of resultspublic static int curandSetQuasiRandomGeneratorDimensions(curandGenerator generator, int num_dimensions)
Set the number of dimensions. Set the number of dimensions to be generated by the quasirandom number generator. Legal values for num_dimensions are 1 to 20000.
generator
- - Generator to modifynum_dimensions
- - Number of dimensionspublic static int curandGenerate(curandGenerator generator, Pointer outputPtr, long num)
Generate 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 ::curandSetStream(), or the null stream if no stream has been set. Results are 32-bit values with every bit random.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsnum
- - Number of random 32-bit values to generatepublic static int curandGenerateLongLong(curandGenerator generator, Pointer outputPtr, long num)
Generate 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 ::curandSetStream(), or the null stream if no stream has been set. Results are 64-bit values with every bit random.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsnum
- - Number of random 64-bit values to generatepublic static int curandGenerateUniform(curandGenerator generator, Pointer outputPtr, long num)
Generate 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 ::curandSetStream(), 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.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsnum
- - Number of floats to generatepublic static int curandGenerateUniformDouble(curandGenerator generator, Pointer outputPtr, long num)
Generate 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 ::curandSetStream(), 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.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsnum
- - Number of doubles to generatepublic static int curandGenerateNormal(curandGenerator generator, Pointer outputPtr, long n, float mean, float stddev)
Generate normally 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 ::curandSetStream(), 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 num 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 ::curandCreateGenerator() and results calculated on the CPU with generators created with ::curandCreateGeneratorHost(). 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.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsn
- - Number of floats to generatemean
- - Mean of normal distributionstddev
- - Standard deviation of normal distributionpublic static int curandGenerateNormalDouble(curandGenerator generator, Pointer outputPtr, long n, double mean, double stddev)
Generate normally 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 ::curandSetStream(), 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 num 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 ::curandCreateGenerator() and results calculated on the CPU with generators created with ::curandCreateGeneratorHost(). 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.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsn
- - Number of doubles to generatemean
- - Mean of normal distributionstddev
- - Standard deviation of normal distributionpublic static int curandGenerateLogNormal(curandGenerator generator, Pointer outputPtr, long n, float mean, float stddev)
Generate log-normally 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 ::curandSetStream(), 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 num 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 ::curandCreateGenerator() and results calculated on the CPU with generators created with ::curandCreateGeneratorHost(). 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.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsn
- - Number of floats to generatemean
- - Mean of associated normal distributionstddev
- - Standard deviation of associated normal distributionpublic static int curandGenerateLogNormalDouble(curandGenerator generator, Pointer outputPtr, long n, double mean, double stddev)
Generate log-normally 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 ::curandSetStream(), 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 num 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 ::curandCreateGenerator() and results calculated on the CPU with generators created with ::curandCreateGeneratorHost(). 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.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsn
- - Number of doubles to generatemean
- - Mean of normal distributionstddev
- - Standard deviation of normal distributionpublic static int curandCreatePoissonDistribution(double lambda, curandDiscreteDistribution discrete_distribution)
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 distributiondiscrete_distribution
- - pointer to the histogram in device memorypublic static int curandDestroyDistribution(curandDiscreteDistribution discrete_distribution)
Destroy the histogram array for a discrete distribution (e.g. Poisson). Destroy the histogram array for a discrete distribution created by curandCreatePoissonDistribution.
discrete_distribution
- - pointer to device memory where the histogram is storedpublic static int curandGeneratePoisson(curandGenerator generator, Pointer outputPtr, long n, double lambda)
Generate 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 ::curandSetStream(), or the null stream if no stream has been set. Results are 32-bit unsigned int point values with Poisson distribution, with lambda lambda.
generator
- - Generator to useoutputPtr
- - Pointer to device memory to store CUDA-generated results, or
Pointer to host memory to store CPU-generated resultsn
- - Number of unsigned ints to generatelambda
- - lambda for the Poisson distributionpublic static int curandGenerateSeeds(curandGenerator generator)
Setup starting states. Generate the starting state of the generator. This function is automatically called by generation functions such as ::curandGenerate() and ::curandGenerateUniform(). It can be called manually for performance testing reasons to separate timings for starting state generation and random number generation.
generator
- - Generator to updatepublic static int curandGetDirectionVectors32(int[][][] vectors, int set)
Get 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_DIRECTION_VECTORS_32_JOEKUO6 (20,000 dimensions) - CURAND_SCRAMBLED_DIRECTION_VECTORS_32_JOEKUO6 (20,000 dimensions)
vectors
- - Address of pointer in which to return direction vectorsset
- - Which set of direction vectors to usepublic static int curandGetScrambleConstants32(int[][] constants)
Get 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 constantspublic static int curandGetDirectionVectors64(long[][][] vectors, int set)
Get 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_DIRECTION_VECTORS_64_JOEKUO6 (20,000 dimensions) - CURAND_SCRAMBLED_DIRECTION_VECTORS_64_JOEKUO6 (20,000 dimensions)
vectors
- - Address of pointer in which to return direction vectorsset
- - Which set of direction vectors to usepublic static int curandGetScrambleConstants64(long[][] constants)
Get 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 constantsCopyright © 2018. All rights reserved.