From 028d33e09426be27bf7e0358cc204f4b4644ba82 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 18 Jan 2018 18:47:18 -0600 Subject: [PATCH 1/2] Use vstore4 to do a vector copy. --- pyopencl/clrandom.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index ba0d61b3..decab716 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -287,10 +287,7 @@ class RanluxGenerator(object): while (idx + 4 < out_size) { output_vec_t ran = GET_RANDOM_NUM(RANLUX_FUNC(&ranluxclstate)); - output[idx] = ran.x; - output[idx + 1] = ran.y; - output[idx + 2] = ran.z; - output[idx + 3] = ran.w; + vstore4(ran, 0, &output[idx]); idx += 4*NUM_WORKITEMS; } @@ -598,10 +595,7 @@ class Random123GeneratorBase(object): while (idx + 4 < out_size) { output_vec_t ran = GET_RANDOM_NUM(gen_bits(&k, &c)); - output[idx] = ran.x; - output[idx + 1] = ran.y; - output[idx + 2] = ran.z; - output[idx + 3] = ran.w; + vstore4(ran, 0, &output[idx]); idx += 4*get_global_size(0); } -- GitLab From 403ee3072a1a6534b3a75bc3553baeb5f2e326c9 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Thu, 18 Jan 2018 18:48:58 -0600 Subject: [PATCH 2/2] Use a function instead of a wrapper class to create a RanluxGenerator. --- test/test_clrandom.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/test/test_clrandom.py b/test/test_clrandom.py index 2be2e46f..2846e24c 100644 --- a/test/test_clrandom.py +++ b/test/test_clrandom.py @@ -40,21 +40,13 @@ else: faulthandler.enable() -class RanluxGeneratorShim(object): - - def __init__(self, cl_ctx): - self.queue = cl.CommandQueue(cl_ctx) - self.gen = clrandom.RanluxGenerator(self.queue) - - def uniform(self, *args, **kwargs): - return self.gen.uniform(*args, **kwargs) - - def normal(self, *args, **kwargs): - return self.gen.normal(*args, **kwargs) +def make_ranlux_generator(cl_ctx): + queue = cl.CommandQueue(cl_ctx) + return clrandom.RanluxGenerator(queue) @pytest.mark.parametrize("rng_class", [ - RanluxGeneratorShim, + make_ranlux_generator, clrandom.PhiloxGenerator, clrandom.ThreefryGenerator]) @pytest.mark.parametrize("dtype", [ -- GitLab