-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Genarate the same random ndarray when size of random ndarray is changed #165
Comments
I show another example since the example code in #165 (comment) is resolved by modification for #166.
|
I tried to reuse the first element of The result of code in #165 (comment) is as follows.
$ git diff
diff --git a/clpy/random/generator.py b/clpy/random/generator.py
index 5430281..c6e40fa 100644
--- a/clpy/random/generator.py
+++ b/clpy/random/generator.py
@@ -176,9 +176,13 @@ class RandomState(object):
if (not isinstance(self.seed_array, clpy.ndarray)
or self.seed_array.size < array_size):
+ if (not isinstance(self.seed_array, clpy.ndarray)):
+ initial_seed = self.seed_value
+ else:
+ initial_seed = self.seed_array[0]
self.seed_array = clpy.empty(size, "uint")
tmp_seed_array = clpy.empty(size, "uint")
- tmp_seed_array.fill(self.seed_value)
+ tmp_seed_array.fill(initial_seed)
RandomState._init_kernel(tmp_seed_array, self.seed_array)
# not to use similar number for the first generation
RandomState._lcg_kernel(self.seed_array, out) |
How about adding influctuation to generate rand number (e.g. time) when rand() called? |
@LWisteria From the performance point of view, it takes much longer time only the first time the program pass through It can be reproduced every time and it happens on both of the Primary Machine and the Secondary Machine.
import clpy
import time
base = 100000
#initial call
beg = time.time()
clpy.random.rand(base)
end = time.time()
print("time = {:.5f} msec".format(end - beg))
for i in range(20):
beg = time.time()
clpy.random.rand(base + 1 + i)
end = time.time()
print("time = {:.5f} msec".format(end - beg))
$ python new_random4.py
time = 0.12433 msec
time = 0.04277 msec
time = 0.00138 msec
time = 0.00150 msec
time = 0.00104 msec
time = 0.00101 msec
time = 0.00093 msec
time = 0.00089 msec
time = 0.00088 msec
time = 0.00088 msec
time = 0.00089 msec
time = 0.00089 msec
time = 0.00089 msec
time = 0.00090 msec
time = 0.00090 msec
time = 0.00088 msec
time = 0.00089 msec
time = 0.00094 msec
time = 0.00063 msec
time = 0.00115 msec
time = 0.00064 msec |
I think this is not problem on random generator. It happenes the first time to execute every cupy/clpy kernel because it needs to initialize something in the runtime lib. Anyway, doesn't that comment refer to my comment?
I mean, this issue (not performance, it was already solved on #162 ) could be solved if you pass time value to kernel argument and add it and each thread's seeds. |
I'm sorry I misread your comments.
To get and use |
The reason is to use the same seed
self.seed_value
when the size of random number array is changed.https://github.com/fixstars/clpy/blob/clpy/clpy/random/generator.py#L178
The text was updated successfully, but these errors were encountered: