From 4c59fd732808b593cc600709fc27cfb636215ec4 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Sat, 8 Jun 2013 13:43:55 -0400 Subject: [PATCH] PEP8 clrandom --- pyopencl/clrandom.py | 71 ++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/pyopencl/clrandom.py b/pyopencl/clrandom.py index 04d3a59a..04ebe99e 100644 --- a/pyopencl/clrandom.py +++ b/pyopencl/clrandom.py @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ + # {{{ documentation __doc__ = u""" @@ -33,7 +34,8 @@ available in any piece of code compiled through PyOpenCL by:: #include <pyopencl-ranluxcl.cl> -See the `source <https://github.com/inducer/pyopencl/blob/master/src/cl/pyopencl-ranluxcl.cl>`_ +See the `source +<https://github.com/inducer/pyopencl/blob/master/src/cl/pyopencl-ranluxcl.cl>`_ for some documentation if you're planning on using RANLUXCL directly. The RANLUX generator is described in the following two articles. If you use the @@ -58,11 +60,6 @@ from pytools import memoize_method import numpy as np - - - - - class RanluxGenerator(object): """ .. versionadded:: 2011.2 @@ -73,9 +70,10 @@ class RanluxGenerator(object): .. attribute:: nskip - nskip is an integer which can (optionally) be defined in the kernel code - as RANLUXCL_NSKIP. If this is done the generator will be faster for luxury setting - 0 and 1, or when the p-value is manually set to a multiple of 24. + nskip is an integer which can (optionally) be defined in the kernel + code as RANLUXCL_NSKIP. If this is done the generator will be faster + for luxury setting 0 and 1, or when the p-value is manually set to a + multiple of 24. """ def __init__(self, queue, num_work_items=None, @@ -83,19 +81,21 @@ class RanluxGenerator(object): use_legacy_init=False, max_work_items=None): """ :param queue: :class:`pyopencl.CommandQueue`, only used for initialization - :param luxury: the "luxury value" of the generator, and should be 0-4, where 0 is fastest - and 4 produces the best numbers. It can also be >=24, in which case it directly - sets the p-value of RANLUXCL. - :param num_work_items: is the number of generators to initialize, usually corresponding - to the number of work-items in the NDRange RANLUXCL will be used with. - May be `None`, in which case a default value is used. - :param max_work_items: should reflect the maximum number of work-items that will be used - on any parallel instance of RANLUXCL. So for instance if we are launching 5120 - work-items on GPU1 and 10240 work-items on GPU2, GPU1's RANLUXCLTab would be - generated by calling ranluxcl_intialization with numWorkitems = 5120 while - GPU2's RANLUXCLTab would use numWorkitems = 10240. However maxWorkitems must - be at least 10240 for both GPU1 and GPU2, and it must be set to the same value - for both. (may be `None`) + :param luxury: the "luxury value" of the generator, and should be 0-4, + where 0 is fastest and 4 produces the best numbers. It can also be + >=24, in which case it directly sets the p-value of RANLUXCL. + :param num_work_items: is the number of generators to initialize, + usually corresponding to the number of work-items in the NDRange + RANLUXCL will be used with. May be `None`, in which case a default + value is used. + :param max_work_items: should reflect the maximum number of work-items + that will be used on any parallel instance of RANLUXCL. So for + instance if we are launching 5120 work-items on GPU1 and 10240 + work-items on GPU2, GPU1's RANLUXCLTab would be generated by + calling ranluxcl_intialization with numWorkitems = 5120 while + GPU2's RANLUXCLTab would use numWorkitems = 10240. However + maxWorkitems must be at least 10240 for both GPU1 and GPU2, and it + must be set to the same value for both. (may be `None`) .. versionchanged:: 2013.1 Added default value for `num_work_items`. @@ -112,7 +112,7 @@ class RanluxGenerator(object): if seed is None: from time import time - seed = int(time()*1e6) % 2<<30 + seed = int(time()*1e6) % 2 << 30 self.context = queue.context self.luxury = luxury @@ -130,7 +130,8 @@ class RanluxGenerator(object): #include <pyopencl-ranluxcl.cl> - kernel void init_ranlux(unsigned seeds, global ranluxcl_state_t *ranluxcltab) + kernel void init_ranlux(unsigned seeds, + global ranluxcl_state_t *ranluxcltab) { if (get_global_id(0) < %(num_work_items)d) ranluxcl_initialization(seeds, ranluxcltab); @@ -180,7 +181,8 @@ class RanluxGenerator(object): lines.append("#define RANLUXCL_USE_LEGACY_INITIALIZATION") if self.max_work_items: - lines.append("#define RANLUXCL_MAXWORKITEMS %d" % self.max_work_items) + lines.append( + "#define RANLUXCL_MAXWORKITEMS %d" % self.max_work_items) return "\n".join(lines) @@ -215,8 +217,7 @@ class RanluxGenerator(object): c_type = "int" rng_expr = ("(shift " "+ convert_int4(scale * gen) " - "+ convert_int4((scale / (1<<24)) * gen))" - ) + "+ convert_int4((scale / (1<<24)) * gen))") else: raise TypeError("unsupported RNG data type '%s'" % dtype) @@ -248,7 +249,9 @@ class RanluxGenerator(object): unsigned long idx = get_global_id(0)*4; while (idx + 4 < out_size) { - vstore4(GET_RANDOM_NUM(RANLUX_FUNC(&ranluxclstate)), idx >> 2, output); + vstore4( + GET_RANDOM_NUM(RANLUX_FUNC(&ranluxclstate)), + idx >> 2, output); idx += 4*NUM_WORKITEMS; } @@ -355,11 +358,8 @@ class RanluxGenerator(object): efficiency. """ - self.get_sync_kernel()(queue, (self.num_work_items,), self.wg_size, self.state.data) - - - - + self.get_sync_kernel()(queue, (self.num_work_items,), + self.wg_size, self.state.data) @first_arg_dependent_memoize @@ -369,8 +369,6 @@ def _get_generator(queue, luxury=None): return gen - - def fill_rand(result, queue=None, luxury=4, a=0, b=1): """Fill *result* with random values of `dtype` in the range [0,1). """ @@ -380,8 +378,6 @@ def fill_rand(result, queue=None, luxury=4, a=0, b=1): gen.fill_uniform(result, a=a, b=b) - - def rand(queue, shape, dtype, luxury=None, a=0, b=1): """Return an array of `shape` filled with random values of `dtype` in the range [a,b). @@ -394,5 +390,4 @@ def rand(queue, shape, dtype, luxury=None, a=0, b=1): return result - # vim: filetype=pyopencl:foldmethod=marker -- GitLab