compute icon indicating copy to clipboard operation
compute copied to clipboard

Random numbers generation

Open orralus opened this issue 6 years ago • 10 comments

I try to generate vector of random number multiple times and it seems to generate the same vector

for example

... auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); compute::default_random_engine engine(queue,seed); compute::uniform_real_distribution GPUdistribution(0.0, 1.0); for (int t=0; t<T;t++) { ... GPUdistribution.generate(vec2.begin(), vec2.end(),engine,queue); ... }

Is it necessary to destroy and regenerate engine with new seed at each iteration to get proper results? Thanks

orralus avatar Apr 29 '18 14:04 orralus

Can you try using boost::compute::threefry_engine instead of default_random_engine?

jszuppe avatar Apr 29 '18 15:04 jszuppe

Same as in https://github.com/boostorg/compute/issues/745

GPUdistribution.generate(vec2.begin(), vec2.end(), engine ,queue); does not compile

orralus avatar Apr 29 '18 15:04 orralus

Which version of boost are you using?

Ulfgard avatar Apr 29 '18 16:04 Ulfgard

1.61

orralus avatar Apr 30 '18 05:04 orralus

Can you try the newest boost? I think this got fixed in #747

Ulfgard avatar Apr 30 '18 07:04 Ulfgard

Upgraded to 1.67 and problem is persistent

orralus avatar May 07 '18 08:05 orralus

Apparently the threefry.hpp here is not the same as the one which comes with 1.67

orralus avatar May 08 '18 11:05 orralus

That's possible. I don't know when @kylelutz merged those changes into master.

jszuppe avatar May 08 '18 12:05 jszuppe

I think it settles the randomness issue but apparently it fills the device memory from some reason after several iterations.

"terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injectorboost::compute::opencl_error >' what(): Memory Object Allocation Failure"

does threefry allocate memory somewhere? I think it is because it builds new kernels and program in every generation (in the private function load_program).

orralus avatar May 09 '18 11:05 orralus

all program generation is cached and the cache size is limited (i think 32 or 64 programs). load_program is also called only in the constructor.

Ulfgard avatar May 09 '18 11:05 Ulfgard