I would like to get some helps from experts.
My code executes cuda kernels repeatedly and each kernel draws random numbers. Depending on an internal condition, some draw a random number once and the others twice. Is this problematic?
Below are simplified version of my kernels.
The two kernels “do_it1” and “do_it2” are mathematically equivalent.
But, it am afraid that results from the two kernels are quite different.
“do_it2” looks silly. But, should it be forbidden?
========== codes below ==========
(1) Setting up a random number generator
global void setup(curandState *state, unsigned long long seed)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
curand_init(seed, id, 0, &state[id]);
}
(2) Working kernels
global void do_it2(curandState *state)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
curandState localState = state[id];
if( curand_uniform(&localState) > 0.5 ) {
if( curand_uniform(&localState) > 0.5) {
do_something() ;
}
}
state[id] = localState;
}
global void do_it1(curandState *state)
{
int id = threadIdx.x + blockIdx.x * blockDim.x;
curandState localState = state[id];
if( curand_uniform(&localState) > 1.- 0.5 * 0.5 ) {
do_something() ;
}
state[id] = localState;
}
(3) main
int main()
{
setup<<<64, 64>>>(states, 1234);
for(i = 0; i < 100; i++) {
do_it1<<<64, 64>>>(states);
// or do_it2<<<64, 64>>>(states);
}
}