This commit is contained in:
2026-04-14 14:17:16 -04:00
parent caf347e8f5
commit 3afe18f188
41 changed files with 123 additions and 100 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,55 +0,0 @@
#ifndef __AMSCU_RANDOM_HPP__
#define __AMSCU_RANDOM_HPP__
namespace amscuda
{
// Random Number Gerneators
// faster floating point hash function used in fractal generators
__device__ __host__ float fhash1d_su(float x);
__device__ __host__ float fhash3d_su(float x, float y, float z);
__device__ __host__ float fhash4d_su(float x, float y, float z, float w);
//////////////////////////////////////////////////
// Deterministic Pseudorandom int32_t Generator //
//////////////////////////////////////////////////
//Next seed in simple 32 bit integer deterministic psuedo-rand generator
__host__ __device__ void dpr32_nextseed(int32_t *rseed_inout);
//Simple 32 bit integer deterministic pseudo-random generator
// *not* for cryptography
// Frequency of generated floats should be uniform [0,1)
__host__ __device__ float dpr32_randf(int32_t *rseed_inout);
//box muller standard normal pseudorandom variable
__host__ __device__ float dpr32_randnf(int32_t *rseed_inout);
//////////////////////////////////////////////////
// Deterministic Pseudorandom int64_t Generator //
//////////////////////////////////////////////////
//operates without side-effects on explicit seed for threaded use
//deterministic pseudorandom number generator - takes seed and returns next seed
__host__ __device__ void dpr64_nextseed(int64_t *seedinout);
//deterministic pseudorandom number generator - takes seed and returns next seed
//returns uniformly distributed double
__host__ __device__ double dpr64_randd(int64_t *seedinout);
__host__ __device__ float dpr64_randf(int64_t *seedinout);
void test_dprg64();
void test_dprg32();
}; //end namespace amscuda
#endif

View File

@ -39,8 +39,6 @@ namespace amscuda
//random device buffer functions //random device buffer functions
void dbuff_rand_dpr32(float *devbuffer, int N, int32_t *rseedinout, int nblocks, int nthreads); // void dbuff_rand_dpr32(float *devbuffer, int N, int32_t *rseedinout, int nblocks, int nthreads); //
void dbuff_rand_dpr32n(float *devbuffer, int N, int32_t *rseedinout, int nblocks, int nthreads); // void dbuff_rand_dpr32n(float *devbuffer, int N, int32_t *rseedinout, int nblocks, int nthreads); //
void dbuff_rand_dpr64(float *devbuffer, int N, int64_t *rseedinout, int nblocks, int nthreads); // void dbuff_rand_dpr64(float *devbuffer, int N, int64_t *rseedinout, int nblocks, int nthreads); //
//Elementwise device-buffer vector binary operation //Elementwise device-buffer vector binary operation

View File

@ -50,7 +50,6 @@ namespace amscuda
#include <amsculib3/amscuarray.hpp> #include <amsculib3/amscuarray.hpp>
#include <amsculib3/amscuda_binarrrw.hpp> #include <amsculib3/amscuda_binarrrw.hpp>
#include <amsculib3/amscu_random.hpp>
#include <amsculib3/random/amscurandom.cuh> #include <amsculib3/random/amscurandom.cuh>

View File

@ -11,7 +11,12 @@ namespace fhash
{ {
//Floating point hash functions //Floating point hash functions
// legacy fast floating point hash function used in fractal generators
__device__ __host__ float fhash1d_su(float x);
__device__ __host__ float fhash3d_su(float x, float y, float z);
__device__ __host__ float fhash4d_su(float x, float y, float z, float w);
}; };

View File

@ -11,7 +11,38 @@ namespace lcg
{ {
//Legacy linear congruential generators //Legacy linear congruential generators
//////////////////////////////////////////////////
// Deterministic Pseudorandom int32_t Generator //
//////////////////////////////////////////////////
//Next seed in simple 32 bit integer deterministic psuedo-rand generator
__host__ __device__ void dpr32_nextseed(int32_t *rseed_inout);
//Simple 32 bit integer deterministic pseudo-random generator
// *not* for cryptography
// Frequency of generated floats should be uniform [0,1)
__host__ __device__ float dpr32_randf(int32_t *rseed_inout);
//box muller standard normal pseudorandom variable
__host__ __device__ float dpr32_randnf(int32_t *rseed_inout);
//////////////////////////////////////////////////
// Deterministic Pseudorandom int64_t Generator //
//////////////////////////////////////////////////
//operates without side-effects on explicit seed for threaded use
//deterministic pseudorandom number generator - takes seed and returns next seed
__host__ __device__ void dpr64_nextseed(int64_t *seedinout);
//deterministic pseudorandom number generator - takes seed and returns next seed
//returns uniformly distributed double
__host__ __device__ double dpr64_randd(int64_t *seedinout);
__host__ __device__ float dpr64_randf(int64_t *seedinout);
void test_dprg64();
void test_dprg32();
}; };
}; };

View File

@ -48,6 +48,10 @@ __host__ int dbuff_randn(double *hbuffer, int64_t size, randstate_t *state = NUL
__host__ int dbuff_randint(int *hbuffer, int64_t size, int low, int high, randstate_t *state = NULL); __host__ int dbuff_randint(int *hbuffer, int64_t size, int low, int high, randstate_t *state = NULL);
//Tests
__host__ void amscurand_tests1(); //test basic random functions
}; };
}; };

View File

@ -26,7 +26,7 @@ __global__ void dbuff_rand_dpr32_kf(float *devbuffer, int N, int32_t *seeds)
lseed = seeds[I0]; lseed = seeds[I0];
for(I=I0;I<N;I=I+Is) for(I=I0;I<N;I=I+Is)
{ {
f = dpr32_randf(&lseed); f = amscuda::random::lcg::dpr32_randf(&lseed);
devbuffer[I] = f; devbuffer[I] = f;
} }
@ -53,7 +53,7 @@ void dbuff_rand_dpr32(float *devbuffer, int N, int32_t *rseedinout, int nblocks
for(I=0;I<nblocks*nthreads;I++) for(I=0;I<nblocks*nthreads;I++)
{ {
lseed = lseed + I + 1; lseed = lseed + I + 1;
dpr32_nextseed(&lseed); amscuda::random::lcg::dpr32_nextseed(&lseed);
seeds[I] = lseed; seeds[I] = lseed;
} }
@ -86,7 +86,7 @@ __global__ void dbuff_rand_dpr32n_kf(float *devbuffer, int N, int32_t *seeds)
lseed = seeds[I0]; lseed = seeds[I0];
for(I=I0;I<N;I=I+Is) for(I=I0;I<N;I=I+Is)
{ {
f = dpr32_randnf(&lseed); f = amscuda::random::lcg::dpr32_randnf(&lseed);
devbuffer[I] = f; devbuffer[I] = f;
} }
@ -113,7 +113,7 @@ void dbuff_rand_dpr32n(float *devbuffer, int N, int32_t *rseedinout, int nblock
for(I=0;I<nblocks*nthreads;I++) for(I=0;I<nblocks*nthreads;I++)
{ {
lseed = lseed + I + 1; lseed = lseed + I + 1;
dpr32_nextseed(&lseed); amscuda::random::lcg::dpr32_nextseed(&lseed);
seeds[I] = lseed; seeds[I] = lseed;
} }

View File

@ -0,0 +1,51 @@
#include <amsculib3/amsculib3.hpp>
namespace amscuda
{
namespace random
{
namespace fhash
{
__device__ __host__ float fhash1d_su(float x)
{
float ret;
ret = x*(x>0.0f) + -x*(x<0.0f); //sign without conditionals?
ret = fmodf(ret,10000.0f); //restrain domain
ret = fmodf(ret*(ret+3678.453f)+7890.453f,10000.0f);
ret = fmodf(ret*(ret+8927.2134f),10000.0f);
ret = fmodf(ret*(ret+3656.234f),10000.0f);
//ret = fmodf(ret*(ret+892.2134f),1000.0f);
//ret = fmodf(ret,1000.0f);
ret = ret/10000.0f;
return ret;
}
__device__ __host__ float fhash3d_su(float x, float y=0.0f, float z=0.0f)
{
float ret = 0.0f;
ret = fhash1d_su(z);
ret = fhash1d_su(1000.0f*ret*ret + y);
ret = fhash1d_su(1000.0f*ret*ret + x);
return ret;
}
__device__ __host__ float fhash4d_su(float x, float y=0.0f, float z=0.0f, float w=0.0f)
{
float ret = 0.0f;
ret = fhash1d_su(w);
ret = fhash1d_su(1000.0f*ret*ret + z);
ret = fhash1d_su(1000.0f*ret*ret + y);
ret = fhash1d_su(1000.0f*ret*ret + x);
return ret;
}
};
};
}; //end namespaces

View File

@ -2,44 +2,10 @@
namespace amscuda namespace amscuda
{ {
namespace random
__device__ __host__ float fhash1d_su(float x)
{ {
float ret; namespace lcg
ret = x*(x>0.0f) + -x*(x<0.0f); //sign without conditionals?
ret = fmodf(ret,10000.0f); //restrain domain
ret = fmodf(ret*(ret+3678.453f)+7890.453f,10000.0f);
ret = fmodf(ret*(ret+8927.2134f),10000.0f);
ret = fmodf(ret*(ret+3656.234f),10000.0f);
//ret = fmodf(ret*(ret+892.2134f),1000.0f);
//ret = fmodf(ret,1000.0f);
ret = ret/10000.0f;
return ret;
}
__device__ __host__ float fhash3d_su(float x, float y=0.0f, float z=0.0f)
{ {
float ret = 0.0f;
ret = fhash1d_su(z);
ret = fhash1d_su(1000.0f*ret*ret + y);
ret = fhash1d_su(1000.0f*ret*ret + x);
return ret;
}
__device__ __host__ float fhash4d_su(float x, float y=0.0f, float z=0.0f, float w=0.0f)
{
float ret = 0.0f;
ret = fhash1d_su(w);
ret = fhash1d_su(1000.0f*ret*ret + z);
ret = fhash1d_su(1000.0f*ret*ret + y);
ret = fhash1d_su(1000.0f*ret*ret + x);
return ret;
}
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Deterministic Pseudorandom int32_t Generator // // Deterministic Pseudorandom int32_t Generator //
@ -218,5 +184,6 @@ void test_dprg32()
// return; // return;
} }
};
}; //namespace amscuda };
}; //end namespaces

View File

@ -0,0 +1,21 @@
#include <amsculib3/amsculib3.hpp>
namespace amscuda
{
namespace random
{
__host__ void amscurand_tests1()
{
using namespace random;
printf("Random number generator basic function test:\n");
rand_seed(0);
return;
}
}; //end namespaces
};

View File

@ -23,5 +23,7 @@ int main(int argc, char* argv[])
//test_amscurarray1(); //test_amscurarray1();
random::amscurand_tests1();
return 0; return 0;
} }