boostorg / compute

A C++ GPU Computing Library for OpenCL
http://boostorg.github.io/compute/
Boost Software License 1.0
1.56k stars 332 forks source link

Random numbers generation #775

Open orralus opened 6 years ago

orralus commented 6 years ago

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

jszuppe commented 6 years ago

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

orralus commented 6 years ago

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

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

Ulfgard commented 6 years ago

Which version of boost are you using?

orralus commented 6 years ago

1.61

Ulfgard commented 6 years ago

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

orralus commented 6 years ago

Upgraded to 1.67 and problem is persistent

orralus commented 6 years ago

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

jszuppe commented 6 years ago

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

orralus commented 6 years ago

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_injector >' 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).

Ulfgard commented 6 years ago

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.