From 476d1165ea8cf70f9f661ff50acd187ef9ffd64a Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Fri, 24 Aug 2012 19:22:11 -0400 Subject: [PATCH] Rename ScalarArg -> ValueArg. --- MEMO | 7 +++---- doc/reference.rst | 2 +- loopy/__init__.py | 4 ++-- loopy/codegen/__init__.py | 4 ++-- loopy/compiled.py | 12 ++++++------ loopy/kernel.py | 16 ++++++++++++---- loopy/preprocess.py | 4 ++-- proto-tests/test_fem_assembly.py | 2 +- proto-tests/test_sem.py | 12 ++++++------ proto-tests/test_sem_reagan.py | 2 +- proto-tests/test_sem_tim.py | 12 ++++++------ proto-tests/test_tim.py | 6 +++--- test/test_linalg.py | 12 ++++++------ test/test_loopy.py | 14 +++++++------- test/test_nbody.py | 2 +- 15 files changed, 59 insertions(+), 52 deletions(-) diff --git a/MEMO b/MEMO index 694b49a92..aeeb733a0 100644 --- a/MEMO +++ b/MEMO @@ -53,16 +53,12 @@ To-do - Add dependencies after the fact -- Fix all tests - - Scalar insn priority - If finding a maximum proves troublesome, move parameters into the domain - : (as in, Matlab full-slice) in prefetches -- ScalarArg is a bad name - Future ideas ^^^^^^^^^^^^ @@ -115,6 +111,9 @@ Future ideas Dealt with ^^^^^^^^^^ +- ScalarArg is a bad name + -> renamed to ValueArg + - What to do about constants in codegen? (...f suffix, complex types) -> dealt with by type contexts diff --git a/doc/reference.rst b/doc/reference.rst index 6915549f6..69b1b0fe2 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -117,7 +117,7 @@ Creating Kernels Arguments ^^^^^^^^^ -.. autoclass:: ScalarArg +.. autoclass:: ValueArg :members: :undoc-members: diff --git a/loopy/__init__.py b/loopy/__init__.py index eb89d6570..43c13f8f6 100644 --- a/loopy/__init__.py +++ b/loopy/__init__.py @@ -19,7 +19,7 @@ class LoopyAdvisory(UserWarning): # {{{ imported user interface -from loopy.kernel import ScalarArg, GlobalArg, ArrayArg, ConstantArg, ImageArg +from loopy.kernel import ValueArg, ScalarArg, GlobalArg, ArrayArg, ConstantArg, ImageArg from loopy.kernel import (AutoFitLocalIndexTag, get_dot_dependency_graph, LoopKernel, Instruction, @@ -35,7 +35,7 @@ from loopy.codegen import generate_code from loopy.compiled import CompiledKernel, drive_timing_run, auto_test_vs_ref from loopy.check import check_kernels -__all__ = ["ScalarArg", "GlobalArg", "ArrayArg", "ConstantArg", "ImageArg", +__all__ = ["ValueArg", "ScalarArg", "GlobalArg", "ArrayArg", "ConstantArg", "ImageArg", "LoopKernel", "Instruction", "default_function_mangler", "single_arg_function_mangler", diff --git a/loopy/codegen/__init__.py b/loopy/codegen/__init__.py index e653feb93..e25f0af36 100644 --- a/loopy/codegen/__init__.py +++ b/loopy/codegen/__init__.py @@ -228,7 +228,7 @@ def generate_code(kernel, with_annotation=False, has_image = False - from loopy.kernel import GlobalArg, ConstantArg, ImageArg, ScalarArg + from loopy.kernel import GlobalArg, ConstantArg, ImageArg, ValueArg args = [] for arg in kernel.args: @@ -250,7 +250,7 @@ def generate_code(kernel, with_annotation=False, arg_decl = CLImage(arg.dimensions, mode, arg.name) has_image = True - elif isinstance(arg, ScalarArg): + elif isinstance(arg, ValueArg): arg_decl = Const(POD(arg.dtype, arg.name)) else: raise ValueError("argument type not understood: '%s'" % type(arg)) diff --git a/loopy/compiled.py b/loopy/compiled.py index 8cf223f47..44497d97d 100644 --- a/loopy/compiled.py +++ b/loopy/compiled.py @@ -108,11 +108,11 @@ class CompiledKernel: print "[Loopy] ----------------------------------------------------" raise - from loopy.kernel import ScalarArg + from loopy.kernel import ValueArg arg_types = [] for arg in kernel.args: - if isinstance(arg, ScalarArg): + if isinstance(arg, ValueArg): arg_types.append(arg.dtype) else: arg_types.append(None) @@ -307,7 +307,7 @@ def fill_rand(ary): def make_ref_args(kernel, queue, parameters, fill_value): - from loopy.kernel import ScalarArg, GlobalArg, ImageArg + from loopy.kernel import ValueArg, GlobalArg, ImageArg from pymbolic import evaluate @@ -316,7 +316,7 @@ def make_ref_args(kernel, queue, parameters, output_arrays = [] for arg in kernel.args: - if isinstance(arg, ScalarArg): + if isinstance(arg, ValueArg): arg_value = parameters[arg.name] try: @@ -373,14 +373,14 @@ def make_ref_args(kernel, queue, parameters, def make_args(queue, kernel, ref_input_arrays, parameters, fill_value): - from loopy.kernel import ScalarArg, GlobalArg, ImageArg + from loopy.kernel import ValueArg, GlobalArg, ImageArg from pymbolic import evaluate result = [] output_arrays = [] for arg in kernel.args: - if isinstance(arg, ScalarArg): + if isinstance(arg, ValueArg): arg_value = parameters[arg.name] try: diff --git a/loopy/kernel.py b/loopy/kernel.py index f7b2f1590..a6d8095bb 100644 --- a/loopy/kernel.py +++ b/loopy/kernel.py @@ -211,14 +211,22 @@ class ImageArg(object): return "<ImageArg '%s' of type %s>" % (self.name, self.dtype) -class ScalarArg(object): +class ValueArg(object): def __init__(self, name, dtype, approximately=None): self.name = name self.dtype = np.dtype(dtype) self.approximately = approximately def __repr__(self): - return "<ScalarArg '%s' of type %s>" % (self.name, self.dtype) + return "<ValueArg '%s' of type %s>" % (self.name, self.dtype) + +class ScalarArg(ValueArg): + def __init__(self, name, dtype, approximately=None): + from warnings import warn + warn("ScalarArg is a deprecated name of ValueArg", + DeprecationWarning, stacklevel=2) + + ValueArg.__init__(self, name, dtype, approximately) # }}} @@ -854,7 +862,7 @@ class LoopKernel(Record): domains = [domains] ctx = isl.Context() - scalar_arg_names = set(arg.name for arg in args if isinstance(arg, ScalarArg)) + scalar_arg_names = set(arg.name for arg in args if isinstance(arg, ValueArg)) var_names = ( set(temporary_variables) | set(insn.get_assignee_var_name() @@ -1310,7 +1318,7 @@ class LoopKernel(Record): from pytools import flatten loop_arg_names = list(flatten(dom.get_var_names(dim_type.param) for dom in self.domains)) - return [arg.name for arg in self.args if isinstance(arg, ScalarArg) + return [arg.name for arg in self.args if isinstance(arg, ValueArg) if arg.name in loop_arg_names] @memoize_method diff --git a/loopy/preprocess.py b/loopy/preprocess.py index 8492e9f9b..71a936924 100644 --- a/loopy/preprocess.py +++ b/loopy/preprocess.py @@ -492,12 +492,12 @@ def limit_boostability(kernel): # {{{ rank inames by stride def get_auto_axis_iname_ranking_by_stride(kernel, insn): - from loopy.kernel import ImageArg, ScalarArg + from loopy.kernel import ImageArg, ValueArg approximate_arg_values = dict( (arg.name, arg.approximately) for arg in kernel.args - if isinstance(arg, ScalarArg)) + if isinstance(arg, ValueArg)) # {{{ find all array accesses in insn diff --git a/proto-tests/test_fem_assembly.py b/proto-tests/test_fem_assembly.py index 7d71d76c7..c3823d504 100644 --- a/proto-tests/test_fem_assembly.py +++ b/proto-tests/test_fem_assembly.py @@ -40,7 +40,7 @@ def test_laplacian_stiffness(ctx_factory): lp.GlobalArg("jacDet", dtype, shape=(Nc_sym, Nq), order=order), lp.ConstantArg("w", dtype, shape=(Nq,), order=order), lp.GlobalArg("A", dtype, shape=(Nc_sym, Nb, Nb), order=order), - lp.ScalarArg("Nc", np.int32, approximately=1000), + lp.ValueArg("Nc", np.int32, approximately=1000), ], name="lapquad", assumptions="Nc>=1") diff --git a/proto-tests/test_sem.py b/proto-tests/test_sem.py index 6ee04953d..888ecdd2b 100644 --- a/proto-tests/test_sem.py +++ b/proto-tests/test_sem.py @@ -56,7 +56,7 @@ def test_laplacian(ctx_factory): lp.GlobalArg("lap", dtype, shape=field_shape, order=order), lp.GlobalArg("G", dtype, shape=(6,)+field_shape, order=order), lp.GlobalArg("D", dtype, shape=(n, n), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap", assumptions="K>=1") @@ -144,7 +144,7 @@ def test_laplacian_lmem(ctx_factory): lp.GlobalArg("lap", dtype, shape=field_shape, order=order), lp.GlobalArg("G", dtype, shape=(6,)+field_shape, order=order), lp.GlobalArg("D", dtype, shape=(n, n), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap", assumptions="K>=1") @@ -219,7 +219,7 @@ def test_laplacian_lmem_ilp(ctx_factory): lp.GlobalArg("lap", dtype, shape=field_shape, order=order), lp.GlobalArg("G", dtype, shape=(6,)+field_shape, order=order), lp.GlobalArg("D", dtype, shape=(n, n), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap", assumptions="K>=1") @@ -321,7 +321,7 @@ def test_advect(ctx_factory): lp.GlobalArg("Nw", dtype, shape=field_shape, order=order), lp.GlobalArg("G", dtype, shape=(9,)+field_shape, order=order), lp.GlobalArg("D", dtype, shape=(N, N), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="sem_advect", assumptions="K>=1") @@ -441,7 +441,7 @@ def test_advect_dealias(ctx_factory): lp.GlobalArg("D", dtype, shape=(M,M), order=order), lp.GlobalArg("I", dtype, shape=(M, N), order=order), lp.GlobalArg("V", dtype, shape=(N, M), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="sem_advect", assumptions="K>=1") @@ -505,7 +505,7 @@ def test_interp_diff(ctx_factory): lp.GlobalArg("I", dtype, shape=(M, N), order=order), lp.GlobalArg("V", dtype, shape=(N, M), order=order), lp.GlobalArg("Pu", dtype, shape=field_shape, order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="sem_lap_precon", assumptions="K>=1") diff --git a/proto-tests/test_sem_reagan.py b/proto-tests/test_sem_reagan.py index c147c20b9..f625c3b04 100644 --- a/proto-tests/test_sem_reagan.py +++ b/proto-tests/test_sem_reagan.py @@ -45,7 +45,7 @@ def test_tim2d(ctx_factory): # lp.ConstantArrayArg("D", dtype, shape=(n, n), order=order), lp.ArrayArg("D", dtype, shape=(n, n), order=order), # lp.ImageArg("D", dtype, shape=(n, n)), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap2D", assumptions="K>=1") diff --git a/proto-tests/test_sem_tim.py b/proto-tests/test_sem_tim.py index 8d1c03e7c..04d6aeed4 100644 --- a/proto-tests/test_sem_tim.py +++ b/proto-tests/test_sem_tim.py @@ -56,7 +56,7 @@ def test_laplacian(ctx_factory): lp.ArrayArg("lap", dtype, shape=field_shape, order=order), lp.ArrayArg("G", dtype, shape=(6,)+field_shape, order=order), lp.ArrayArg("D", dtype, shape=(n, n), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap", assumptions="K>=1") @@ -142,7 +142,7 @@ def test_laplacian_lmem(ctx_factory): lp.ArrayArg("lap", dtype, shape=field_shape, order=order), lp.ArrayArg("G", dtype, shape=(6,)+field_shape, order=order), lp.ArrayArg("D", dtype, shape=(n, n), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap", assumptions="K>=1") @@ -230,7 +230,7 @@ def test_laplacian_lmem_ilp(ctx_factory): lp.ArrayArg("lap", dtype, shape=field_shape, order=order), lp.ArrayArg("G", dtype, shape=(6,)+field_shape, order=order), lp.ArrayArg("D", dtype, shape=(n, n), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap", assumptions="K>=1") @@ -332,7 +332,7 @@ def test_advect(ctx_factory): lp.ArrayArg("Nw", dtype, shape=field_shape, order=order), lp.ArrayArg("G", dtype, shape=(9,)+field_shape, order=order), lp.ArrayArg("D", dtype, shape=(N, N), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="sem_advect", assumptions="K>=1") @@ -452,7 +452,7 @@ def test_advect_dealias(ctx_factory): lp.ArrayArg("D", dtype, shape=(M,M), order=order), lp.ArrayArg("I", dtype, shape=(M, N), order=order), lp.ArrayArg("V", dtype, shape=(N, M), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="sem_advect", assumptions="K>=1") @@ -516,7 +516,7 @@ def test_interp_diff(ctx_factory): lp.ArrayArg("I", dtype, shape=(M, N), order=order), lp.ArrayArg("V", dtype, shape=(N, M), order=order), lp.ArrayArg("Pu", dtype, shape=field_shape, order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="sem_lap_precon", assumptions="K>=1") diff --git a/proto-tests/test_tim.py b/proto-tests/test_tim.py index f5a8545d8..84523146d 100644 --- a/proto-tests/test_tim.py +++ b/proto-tests/test_tim.py @@ -42,7 +42,7 @@ def test_tim2d(ctx_factory): # lp.ConstantArrayArg("D", dtype, shape=(n, n), order=order), lp.ArrayArg("D", dtype, shape=(n, n), order=order), # lp.ImageArg("D", dtype, shape=(n, n)), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap2D", assumptions="K>=1") @@ -104,7 +104,7 @@ def test_red2d(ctx_factory): lp.ArrayArg("lap", dtype, shape=field_shape, order=order), lp.ArrayArg("G", dtype, shape=(3,)+field_shape, order=order), lp.ArrayArg("D", dtype, shape=(n, n), order=order), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap2D", assumptions="K>=1") @@ -172,7 +172,7 @@ def test_tim3d(ctx_factory): # lp.ConstantArrayArg("D", dtype, shape=(n, n), order=order), lp.ArrayArg("D", dtype, shape=(n, n), order=order), # lp.ImageArg("D", dtype, shape=(n, n)), - lp.ScalarArg("K", np.int32, approximately=1000), + lp.ValueArg("K", np.int32, approximately=1000), ], name="semlap3D", assumptions="K>=1") diff --git a/test/test_linalg.py b/test/test_linalg.py index d4db1941b..74bd1c501 100644 --- a/test/test_linalg.py +++ b/test/test_linalg.py @@ -110,12 +110,12 @@ def test_axpy(ctx_factory): "z[i] = a*x[i]+b*y[i]" ], [ - lp.ScalarArg("a", dtype), + lp.ValueArg("a", dtype), lp.GlobalArg("x", dtype, shape="n,"), - lp.ScalarArg("b", dtype), + lp.ValueArg("b", dtype), lp.GlobalArg("y", dtype, shape="n,"), lp.GlobalArg("z", dtype, shape="n,"), - lp.ScalarArg("n", np.int32, approximately=n), + lp.ValueArg("n", np.int32, approximately=n), ], name="axpy", assumptions="n>=1") @@ -246,7 +246,7 @@ def test_variable_size_matrix_mul(ctx_factory): lp.GlobalArg("a", dtype, shape=(n, n), order=order), lp.GlobalArg("b", dtype, shape=(n, n), order=order), lp.GlobalArg("c", dtype, shape=(n, n), order=order), - lp.ScalarArg("n", np.int32, approximately=n), + lp.ValueArg("n", np.int32, approximately=n), ], name="matmul", assumptions="n >= 16") @@ -297,7 +297,7 @@ def test_rank_one(ctx_factory): lp.GlobalArg("a", dtype, shape=(n,), order=order), lp.GlobalArg("b", dtype, shape=(n,), order=order), lp.GlobalArg("c", dtype, shape=(n, n), order=order), - lp.ScalarArg("n", np.int32, approximately=n), + lp.ValueArg("n", np.int32, approximately=n), ], name="rank_one", assumptions="n >= 16") @@ -652,7 +652,7 @@ def test_fancy_matrix_mul(ctx_factory): lp.GlobalArg("a", dtype, shape="(n, n)", order=order), lp.GlobalArg("b", dtype, shape="(n, n)", order=order), lp.GlobalArg("c", dtype, shape="(n, n)", order=order), - lp.ScalarArg("n", np.int32, approximately=1000), + lp.ValueArg("n", np.int32, approximately=1000), ], name="fancy_matmul", assumptions="n>=1") knl = lp.split_dimension(knl, "i", 16, outer_tag="g.0", inner_tag="l.1") diff --git a/test/test_loopy.py b/test/test_loopy.py index e4644bcf1..0639bbfec 100644 --- a/test/test_loopy.py +++ b/test/test_loopy.py @@ -254,7 +254,7 @@ def test_fuzz_code_generator(ctx_factory): [lp.Instruction(None, "value", expr)], [lp.GlobalArg("value", np.complex128, shape=())] + [ - lp.ScalarArg(name, get_dtype(val)) + lp.ValueArg(name, get_dtype(val)) for name, val in var_values.iteritems() ]) ck = lp.CompiledKernel(ctx, knl) @@ -322,7 +322,7 @@ def test_nested_dependent_reduction(ctx_factory): "a[i] = sum(j, j)", ], [ - lp.ScalarArg("n", np.int32), + lp.ValueArg("n", np.int32), lp.GlobalArg("a", dtype, ("n",)), lp.GlobalArg("l", np.int32, ("n",)), ]) @@ -361,7 +361,7 @@ def test_dependent_loop_bounds(ctx_factory): lp.GlobalArg("a_values", dtype), lp.GlobalArg("x", dtype), lp.GlobalArg("ax", dtype), - lp.ScalarArg("n", np.int32), + lp.ValueArg("n", np.int32), ], assumptions="n>=1 and row_len>=1") @@ -393,7 +393,7 @@ def test_dependent_loop_bounds_2(ctx_factory): lp.GlobalArg("a_values", dtype), lp.GlobalArg("x", dtype), lp.GlobalArg("ax", dtype), - lp.ScalarArg("n", np.int32), + lp.ValueArg("n", np.int32), ], assumptions="n>=1 and row_len>=1") @@ -429,7 +429,7 @@ def test_dependent_loop_bounds_3(ctx_factory): [ lp.GlobalArg("a_row_lengths", np.int32), lp.GlobalArg("a", dtype, shape=("n,n"), order="C"), - lp.ScalarArg("n", np.int32), + lp.ValueArg("n", np.int32), ]) assert knl.parents_per_domain()[1] == 0 @@ -469,7 +469,7 @@ def test_independent_multi_domain(ctx_factory): [ lp.GlobalArg("a", dtype, shape=("n"), order="C"), lp.GlobalArg("b", dtype, shape=("n"), order="C"), - lp.ScalarArg("n", np.int32), + lp.ValueArg("n", np.int32), ]) @@ -507,7 +507,7 @@ def test_bare_data_dependency(ctx_factory): ], [ lp.GlobalArg("a", dtype, shape=("n"), order="C"), - lp.ScalarArg("n", np.int32), + lp.ValueArg("n", np.int32), ]) cknl = lp.CompiledKernel(ctx, knl) diff --git a/test/test_nbody.py b/test/test_nbody.py index d3a38cc71..aa9812527 100644 --- a/test/test_nbody.py +++ b/test/test_nbody.py @@ -23,7 +23,7 @@ def test_nbody(ctx_factory): [ lp.GlobalArg("x", dtype, shape="N,3", order="C"), lp.GlobalArg("pot", dtype, shape="N", order="C"), - lp.ScalarArg("N", np.int32), + lp.ValueArg("N", np.int32), ], name="nbody", assumptions="N>=1") -- GitLab