diff options
Diffstat (limited to 'src/random.h')
| -rw-r--r-- | src/random.h | 48 | 
1 files changed, 42 insertions, 6 deletions
diff --git a/src/random.h b/src/random.h index 74329da..b084c19 100644 --- a/src/random.h +++ b/src/random.h @@ -5,18 +5,54 @@  #include "physical_constants.h" -__device__ float uniform(curandState *rng, float a=0.0, float b=1.0) +__device__ float uniform(curandState *s, const float &low, const float &high)  { -	return a + curand_uniform(rng)*(b-a); +	return low + curand_uniform(s)*(high-low);  } -__device__ float3 uniform_sphere(curandState *rng) +__device__ float3 uniform_sphere(curandState *s)  { -	float theta = uniform(rng, 0, 2*PI); -	float u = uniform(rng, -1, 1); -	float c = sqrtf(1-u*u); +	float theta = uniform(s, 0.0f, 2*PI); +	float u = uniform(s, -1.0f, 1.0f); +	float c = sqrtf(1.0f-u*u);  	return make_float3(c*cosf(theta), c*sinf(theta), u);  } +extern "C" +{ + +__global__ void init_rng(int nthreads, curandState *s, unsigned long long seed, unsigned long long offset) +{ +	int id = blockIdx.x*blockDim.x + threadIdx.x; + +	if (id >= nthreads) +		return; + +	curand_init(seed, id, offset, &s[id]); +} + +__global__ void fill_uniform(int nthreads, curandState *s, float *a, float low, float high) +{ +	int id = blockIdx.x*blockDim.x + threadIdx.x; + +	if (id >= nthreads) +		return; + +	a[id] = uniform(&s[id], low, high); + +} + +__global__ void fill_uniform_sphere(int nthreads, curandState *s, float3 *a) +{ +	int id = blockIdx.x*blockDim.x + threadIdx.x; + +	if (id >= nthreads) +		return; + +	a[id] = uniform_sphere(&s[id]); +} + +} // extern "c" +  #endif  | 
