From c92ecc5d7bbbeaaf49f69491ca2101707fd13e69 Mon Sep 17 00:00:00 2001 From: Tal Ben-Nun Date: Tue, 20 Feb 2024 08:13:35 -0800 Subject: [PATCH] Remove the long-deprecated `symbol.get/set` methods (#1523) This also fixes FPGA CI, which now runs in parallel and depended on that deprecated functionality. --------- Co-authored-by: Alexandros Nikolaos Ziogas --- dace/codegen/compiled_sdfg.py | 55 ++-- dace/frontend/python/wrappers.py | 7 +- dace/sdfg/sdfg.py | 10 +- dace/symbolic.py | 46 +--- samples/fpga/gemv_fpga.py | 38 ++- samples/fpga/histogram_fpga.py | 27 +- samples/fpga/jacobi_fpga_systolic.py | 41 ++- .../fpga/matrix_multiplication_pipelined.py | 40 ++- samples/fpga/matrix_multiplication_stream.py | 46 ++-- .../fpga/matrix_multiplication_systolic.py | 40 ++- samples/fpga/rtl/add_fortytwo.py | 8 +- samples/fpga/rtl/axpy.py | 10 +- samples/fpga/rtl/axpy_double_pump.py | 10 +- samples/fpga/rtl/fladd.py | 10 +- samples/fpga/rtl/pipeline.py | 8 +- samples/fpga/spmv_fpga_stream.py | 109 ++------ tests/chained_nested_tasklet_test.py | 24 +- tests/chained_tasklet_test.py | 10 +- tests/codegen/mpi_axpy.py | 10 +- tests/codegen/sve/application_axpy_test.py | 18 +- tests/codegen/sve/application_filter_test.py | 10 +- tests/codegen/sve/application_spmv_test.py | 30 +-- tests/compile_sdfg_test.py | 10 +- tests/confres_test.py | 10 +- tests/constant_array_test.py | 12 +- tests/copynd_test.py | 16 +- tests/cuda_block_test.py | 8 +- tests/cuda_grid2d_test.py | 10 +- tests/cuda_grid_test.py | 8 +- tests/cuda_smem2d_test.py | 10 +- tests/cuda_smem_test.py | 8 +- tests/duplicate_arg_test.py | 3 +- tests/duplicate_naming_test.py | 6 +- tests/dynamic_sdfg_functions_test.py | 10 +- tests/external_module_test.py | 6 +- tests/fpga/dot_fpga_test.py | 8 +- tests/fpga/multibank_copy_fpga_test.py | 2 +- tests/fpga/simple_systolic_array_test.py | 17 +- tests/fpga/type_inference_test.py | 12 +- tests/fpga/vec_sum_test.py | 43 ++-- .../fpga/veclen_conversion_connector_test.py | 8 +- tests/fpga/veclen_conversion_test.py | 51 ++-- tests/fpga/vector_reduce_test.py | 6 +- tests/instrumentation_test.py | 3 +- tests/intarg_test.py | 6 +- tests/library/sparse/csrmm_test.py | 2 +- tests/library/sparse/csrmv_test.py | 2 +- tests/local_inline_test.py | 6 +- tests/mapreduce_test.py | 80 +++--- tests/memlet_lifetime_validation_test.py | 5 - tests/multi_output_scope_test.py | 8 +- tests/multiple_cr_test.py | 6 +- tests/multiple_tasklet_test.py | 10 +- tests/multistate_init_test.py | 6 +- tests/multistream_custom_cudatest.py | 14 +- tests/nested_sdfg_python_test.py | 8 +- tests/nested_sdfg_test.py | 6 +- tests/nested_symbol_test.py | 1 - tests/numpy/datatype_conversion_test.py | 6 +- tests/numpy/indirection_test.py | 16 +- tests/numpy/inline_scalar_test.py | 3 - tests/numpy/map_syntax_test.py | 8 +- tests/numpy/range_indirection_test.py | 16 +- tests/numpy/slice_test.py | 4 +- tests/numpy/transient_test.py | 12 +- tests/numpy/ufunc_support_test.py | 18 +- tests/offset_stride_test.py | 10 +- tests/passes/constant_propagation_test.py | 12 +- .../writeset_underapproximation_test.py | 241 ++++++------------ tests/polybench/2mm.py | 10 +- tests/polybench/3mm.py | 11 +- tests/polybench/adi.py | 3 +- tests/polybench/atax.py | 4 +- tests/polybench/bicg.py | 5 +- tests/polybench/cholesky.py | 8 +- tests/polybench/correlation.py | 4 +- tests/polybench/covariance.py | 4 +- tests/polybench/deriche.py | 5 +- tests/polybench/doitgen.py | 6 +- tests/polybench/durbin.py | 4 +- tests/polybench/fdtd-2d.py | 7 +- tests/polybench/floyd-warshall.py | 7 +- tests/polybench/gemm.py | 9 +- tests/polybench/gemver.py | 4 +- tests/polybench/gesummv.py | 4 +- tests/polybench/gramschmidt.py | 5 +- tests/polybench/heat-3d.py | 3 +- tests/polybench/jacobi-1d.py | 3 +- tests/polybench/jacobi-2d.py | 6 +- tests/polybench/lu.py | 4 +- tests/polybench/ludcmp.py | 4 +- tests/polybench/mvt.py | 4 +- tests/polybench/nussinov.py | 10 +- tests/polybench/polybench.py | 11 +- tests/polybench/seidel-2d.py | 3 +- tests/polybench/symm.py | 7 +- tests/polybench/syr2k.py | 5 +- tests/polybench/syrk.py | 5 +- tests/polybench/trisolv.py | 4 +- tests/polybench/trmm.py | 5 +- tests/python_frontend/augassign_wcr_test.py | 2 + .../binop_replacements_test.py | 95 ++++--- .../callback_autodetect_test.py | 1 - .../identifiers_and_keywords_test.py | 66 ++--- tests/python_frontend/line_structure_test.py | 24 +- .../nested_name_accesses_test.py | 8 +- tests/read_after_write_test.py | 6 +- tests/rtl/hardware_test.py | 62 ++--- tests/rtl/simulation_test.py | 18 +- tests/sdfg_validate_names_test.py | 2 +- tests/specialize_test.py | 14 +- tests/subarray_test.py | 6 +- tests/symbol_dependent_transients_test.py | 3 +- tests/threadlocal_stream_test.py | 6 +- tests/tile_test.py | 14 +- tests/tiling_test.py | 22 +- tests/transformations/loop_to_map_test.py | 18 +- tests/transformations/mapfission_test.py | 18 +- .../move_assignment_outside_if_test.py | 50 ++-- .../state_fusion_node_merge_test.py | 6 +- .../block_allreduce_cudatest.py | 9 +- .../subgraph_fusion/complex_test.py | 33 ++- .../create_out_transient_test.py | 17 +- .../subgraph_fusion/disjoint_test.py | 8 +- .../subgraph_fusion/expansion_test.py | 31 +-- .../subgraph_fusion/intermediate_mimo_test.py | 17 +- .../invariant_dimension_test.py | 23 +- .../subgraph_fusion/parallel_test.py | 46 ++-- .../subgraph_fusion/reduction_fuse_test.py | 24 +- .../subgraph_fusion/reduction_test.py | 26 +- .../subgraph_fusion/sequential1_test.py | 10 +- .../subgraph_fusion/sequential2_cudatest.py | 8 +- .../subgraph_fusion/sequential2_test.py | 10 +- .../subgraph_fusion/smax_test.py | 24 +- .../subgraph_fusion/tiling_pool_test.py | 15 +- .../subgraph_fusion/tiling_stencil_test.py | 15 +- tests/transformations/tasklet_fusion_test.py | 19 +- tests/unparse_memlet_test.py | 12 +- tests/vector_min_test.py | 12 +- tests/vla_test.py | 3 +- tutorials/explicit.ipynb | 12 +- 141 files changed, 1022 insertions(+), 1347 deletions(-) diff --git a/dace/codegen/compiled_sdfg.py b/dace/codegen/compiled_sdfg.py index ff7bc6084e..c2ca3316d7 100644 --- a/dace/codegen/compiled_sdfg.py +++ b/dace/codegen/compiled_sdfg.py @@ -31,9 +31,8 @@ def __init__(self, library_filename, program_name): :param program_name: Name of the DaCe program (for use in finding the stub library loader). """ - self._stub_filename = os.path.join( - os.path.dirname(os.path.realpath(library_filename)), - f'libdacestub_{program_name}.{Config.get("compiler", "library_extension")}') + self._stub_filename = os.path.join(os.path.dirname(os.path.realpath(library_filename)), + f'libdacestub_{program_name}.{Config.get("compiler", "library_extension")}') self._library_filename = os.path.realpath(library_filename) self._stub = None self._lib = None @@ -219,7 +218,6 @@ def __init__(self, sdfg, lib: ReloadableDLL, argnames: List[str] = None): self.has_gpu_code = True break - def get_exported_function(self, name: str, restype=None) -> Optional[Callable[..., Any]]: """ Tries to find a symbol by name in the compiled SDFG, and convert it to a callable function @@ -233,7 +231,6 @@ def get_exported_function(self, name: str, restype=None) -> Optional[Callable[.. except KeyError: # Function not found return None - def get_state_struct(self) -> ctypes.Structure: """ Attempt to parse the SDFG source code and extract the state struct. This method will parse the first consecutive entries in the struct that are pointers. As soon as a non-pointer or other unparseable field is @@ -247,7 +244,6 @@ def get_state_struct(self) -> ctypes.Structure: return ctypes.cast(self._libhandle, ctypes.POINTER(self._try_parse_state_struct())).contents - def _try_parse_state_struct(self) -> Optional[Type[ctypes.Structure]]: from dace.codegen.targets.cpp import mangle_dace_state_struct_name # Avoid import cycle # the path of the main sdfg file containing the state struct @@ -375,7 +371,6 @@ def _get_error_text(self, result: Union[str, int]) -> str: else: return result - def __call__(self, *args, **kwargs): """ Forwards the Python call to the compiled ``SDFG``. @@ -400,13 +395,12 @@ def __call__(self, *args, **kwargs): elif len(args) > 0 and self.argnames is not None: kwargs.update( # `_construct_args` will handle all of its arguments as kwargs. - {aname: arg for aname, arg in zip(self.argnames, args)} - ) - argtuple, initargtuple = self._construct_args(kwargs) # Missing arguments will be detected here. - # Return values are cached in `self._lastargs`. + {aname: arg + for aname, arg in zip(self.argnames, args)}) + argtuple, initargtuple = self._construct_args(kwargs) # Missing arguments will be detected here. + # Return values are cached in `self._lastargs`. return self.fast_call(argtuple, initargtuple, do_gpu_check=True) - def fast_call( self, callargs: Tuple[Any, ...], @@ -455,7 +449,6 @@ def fast_call( self._lib.unload() raise - def __del__(self): if self._initialized is True: self.finalize() @@ -463,7 +456,6 @@ def __del__(self): self._libhandle = ctypes.c_void_p(0) self._lib.unload() - def _construct_args(self, kwargs) -> Tuple[Tuple[Any], Tuple[Any]]: """ Main function that controls argument construction for calling @@ -486,7 +478,7 @@ def _construct_args(self, kwargs) -> Tuple[Tuple[Any], Tuple[Any]]: typedict = self._typedict if len(kwargs) > 0: # Construct mapping from arguments to signature - arglist = [] + arglist = [] argtypes = [] argnames = [] for a in sig: @@ -536,10 +528,9 @@ def _construct_args(self, kwargs) -> Tuple[Tuple[Any], Tuple[Any]]: 'you are doing, you can override this error in the ' 'configuration by setting compiler.allow_view_arguments ' 'to True.') - elif (not isinstance(atype, (dt.Array, dt.Structure)) and - not isinstance(atype.dtype, dtypes.callback) and - not isinstance(arg, (atype.dtype.type, sp.Basic)) and - not (isinstance(arg, symbolic.symbol) and arg.dtype == atype.dtype)): + elif (not isinstance(atype, (dt.Array, dt.Structure)) and not isinstance(atype.dtype, dtypes.callback) + and not isinstance(arg, (atype.dtype.type, sp.Basic)) + and not (isinstance(arg, symbolic.symbol) and arg.dtype == atype.dtype)): is_int = isinstance(arg, int) if is_int and atype.dtype.type == np.int64: pass @@ -573,29 +564,23 @@ def _construct_args(self, kwargs) -> Tuple[Tuple[Any], Tuple[Any]]: # Retain only the element datatype for upcoming checks and casts arg_ctypes = tuple(at.dtype.as_ctypes() for at in argtypes) - constants = self.sdfg.constants - callparams = tuple( - (actype(arg.get()) - if isinstance(arg, symbolic.symbol) - else arg, actype, atype, aname - ) - for arg, actype, atype, aname in zip(arglist, arg_ctypes, argtypes, argnames) - if not (symbolic.issymbolic(arg) and (hasattr(arg, 'name') and arg.name in constants)) - ) + constants = self.sdfg.constants + callparams = tuple((arg, actype, atype, aname) + for arg, actype, atype, aname in zip(arglist, arg_ctypes, argtypes, argnames) + if not (symbolic.issymbolic(arg) and (hasattr(arg, 'name') and arg.name in constants))) symbols = self._free_symbols initargs = tuple( - actype(arg) if not isinstance(arg, ctypes._SimpleCData) else arg - for arg, actype, atype, aname in callparams - if aname in symbols - ) + actype(arg) if not isinstance(arg, ctypes._SimpleCData) else arg for arg, actype, atype, aname in callparams + if aname in symbols) try: # Replace arrays with their base host/device pointers newargs = [None] * len(callparams) for i, (arg, actype, atype, _) in enumerate(callparams): if dtypes.is_array(arg): - newargs[i] = ctypes.c_void_p(_array_interface_ptr(arg, atype.storage)) # `c_void_p` is subclass of `ctypes._SimpleCData`. + newargs[i] = ctypes.c_void_p(_array_interface_ptr( + arg, atype.storage)) # `c_void_p` is subclass of `ctypes._SimpleCData`. elif not isinstance(arg, (ctypes._SimpleCData)): newargs[i] = actype(arg) else: @@ -607,11 +592,9 @@ def _construct_args(self, kwargs) -> Tuple[Tuple[Any], Tuple[Any]]: self._lastargs = newargs, initargs return self._lastargs - def clear_return_values(self): self._create_new_arrays = True - def _create_array(self, _: str, dtype: np.dtype, storage: dtypes.StorageType, shape: Tuple[int], strides: Tuple[int], total_size: int): ndarray = np.ndarray @@ -636,7 +619,6 @@ def ndarray(*args, buffer=None, **kwargs): # Create an array with the properties of the SDFG array return ndarray(shape, dtype, buffer=zeros(total_size, dtype), strides=strides) - def _initialize_return_values(self, kwargs): # Obtain symbol values from arguments and constants syms = dict() @@ -687,7 +669,6 @@ def _initialize_return_values(self, kwargs): arr = self._create_array(*shape_desc) self._return_arrays.append(arr) - def _convert_return_values(self): # Return the values as they would be from a Python function if self._return_arrays is None or len(self._return_arrays) == 0: diff --git a/dace/frontend/python/wrappers.py b/dace/frontend/python/wrappers.py index dc05289536..509ca5612d 100644 --- a/dace/frontend/python/wrappers.py +++ b/dace/frontend/python/wrappers.py @@ -12,12 +12,9 @@ def ndarray(shape, dtype=numpy.float64, *args, **kwargs): - """ Returns a numpy ndarray where all symbols have been evaluated to - numbers and types are converted to numpy types. """ - repldict = {sym: sym.get() for sym in symbolic.symlist(shape).values()} - new_shape = [int(s.subs(repldict) if symbolic.issymbolic(s) else s) for s in shape] + """ Returns a numpy ndarray where all types are converted to numpy types. """ new_dtype = dtype.type if isinstance(dtype, dtypes.typeclass) else dtype - return numpy.ndarray(shape=new_shape, dtype=new_dtype, *args, **kwargs) + return numpy.ndarray(shape=shape, dtype=new_dtype, *args, **kwargs) stream: Type[Deque[T]] = deque diff --git a/dace/sdfg/sdfg.py b/dace/sdfg/sdfg.py index 9db6f3f22b..9f3e3b75e5 100644 --- a/dace/sdfg/sdfg.py +++ b/dace/sdfg/sdfg.py @@ -2125,16 +2125,8 @@ def specialize(self, symbols: Dict[str, Any]): :param symbols: Values to specialize. """ - # Set symbol values to add - syms = { - # If symbols are passed, extract the value. If constants are - # passed, use them directly. - name: val.get() if isinstance(val, dace.symbolic.symbol) else val - for name, val in symbols.items() - } - # Update constants - for k, v in syms.items(): + for k, v in symbols.items(): self.add_constant(str(k), v) def is_loaded(self) -> bool: diff --git a/dace/symbolic.py b/dace/symbolic.py index 8342725349..4b652d2ed1 100644 --- a/dace/symbolic.py +++ b/dace/symbolic.py @@ -53,19 +53,10 @@ def __new__(cls, name=None, dtype=DEFAULT_SYMBOL_TYPE, **assumptions): self.dtype = dtype self._constraints = [] - self.value = None return self - def set(self, value): - warnings.warn('symbol.set is deprecated, use keyword arguments', DeprecationWarning) - if value is not None: - # First, check constraints - self.check_constraints(value) - - self.value = self.dtype(value) - def __getstate__(self): - return dict(self.assumptions0, **{'value': self.value, 'dtype': self.dtype, '_constraints': self._constraints}) + return dict(self.assumptions0, **{'dtype': self.dtype, '_constraints': self._constraints}) def _eval_subs(self, old, new): """ @@ -85,15 +76,6 @@ def _eval_subs(self, old, new): except AttributeError: return None - def is_initialized(self): - return self.value is not None - - def get(self): - warnings.warn('symbol.get is deprecated, use keyword arguments', DeprecationWarning) - if self.value is None: - raise UnboundLocalError('Uninitialized symbol value for \'' + self.name + '\'') - return self.value - def set_constraints(self, constraint_list): try: iter(constraint_list) @@ -141,9 +123,6 @@ def check_constraints(self, value): if fail is not None: raise RuntimeError('Value %s invalidates constraint %s for symbol %s' % (str(value), str(fail), self.name)) - def get_or_return(self, uninitialized_ret): - return self.value or uninitialized_ret - class SymExpr(object): """ Symbolic expressions with support for an overapproximation expression. @@ -287,13 +266,6 @@ def __gt__(self, other): SymbolicType = Union[sympy.Basic, SymExpr] -def symvalue(val): - """ Returns the symbol value if it is a symbol. """ - if isinstance(val, symbol): - return val.get() - return val - - # http://stackoverflow.com/q/3844948/ def _checkEqualIvo(lst): return not lst or lst.count(lst[0]) == len(lst) @@ -333,9 +305,8 @@ def symlist(values): return result -def evaluate(expr: Union[sympy.Basic, int, float], - symbols: Dict[Union[symbol, str], Union[int, float]]) -> \ - Union[int, float, numpy.number]: +def evaluate(expr: Union[sympy.Basic, int, float], symbols: Dict[Union[symbol, str], + Union[int, float]]) -> Union[int, float, numpy.number]: """ Evaluates an expression to a constant based on a mapping from symbols to values. @@ -356,9 +327,7 @@ def evaluate(expr: Union[sympy.Basic, int, float], return expr # Evaluate all symbols - syms = {(sname if isinstance(sname, sympy.Symbol) else symbol(sname)): - sval.get() if isinstance(sval, symbol) else sval - for sname, sval in symbols.items()} + syms = {(sname if isinstance(sname, sympy.Symbol) else symbol(sname)): sval for sname, sval in symbols.items()} # Filter out `None` values, callables, and iterables but not strings (for SymPy 1.12) syms = { @@ -1028,7 +997,7 @@ def visit_IfExp(self, node): self.visit(node.orelse)], keywords=[]) return ast.copy_location(new_node, node) - + def visit_Subscript(self, node): if isinstance(node.value, ast.Attribute): attr = ast.Subscript(value=ast.Name(id=node.value.attr, ctx=ast.Load()), slice=node.slice, ctx=ast.Load()) @@ -1405,8 +1374,7 @@ def equal(a: SymbolicType, b: SymbolicType, is_length: bool = True) -> Union[boo return sympy.ask(sympy.Q.is_true(sympy.Eq(*args))) -def symbols_in_code(code: str, potential_symbols: Set[str] = None, - symbols_to_ignore: Set[str] = None) -> Set[str]: +def symbols_in_code(code: str, potential_symbols: Set[str] = None, symbols_to_ignore: Set[str] = None) -> Set[str]: """ Tokenizes a code string for symbols and returns a set thereof. @@ -1419,7 +1387,7 @@ def symbols_in_code(code: str, potential_symbols: Set[str] = None, if potential_symbols is not None and len(potential_symbols) == 0: # Don't bother tokenizing for an empty set of potential symbols return set() - + tokens = set(re.findall(_NAME_TOKENS, code)) if potential_symbols is not None: tokens &= potential_symbols diff --git a/samples/fpga/gemv_fpga.py b/samples/fpga/gemv_fpga.py index 5871bc88d1..c00d05cd81 100644 --- a/samples/fpga/gemv_fpga.py +++ b/samples/fpga/gemv_fpga.py @@ -120,12 +120,12 @@ def make_outer_compute_state(sdfg): return state -def make_sdfg(specialize): +def make_sdfg(specialize, N, M): if specialize: - name = "gemv_transposed_{}x{}".format(N.get(), M.get()) + name = "gemv_transposed_{}x{}".format(N, M) else: - name = "gemv_transposed_{}xM".format(N.get()) + name = "gemv_transposed_{}xM".format(N) sdfg = dace.SDFG(name) @@ -143,29 +143,25 @@ def run_gemv(n: int, m: int, specialize: bool): print("==== Program start ====") - N.set(n) if specialize: print("Specializing M...") - M.set(m) - gemv = make_sdfg(specialize) - gemv.specialize(dict(N=N)) + gemv = make_sdfg(specialize, n, m) + gemv.specialize(dict(N=n)) - if not specialize: - M.set(m) - else: - gemv.specialize(dict(M=M)) + if specialize: + gemv.specialize(dict(M=m)) - print("Running GEMV {}x{} ({}specialized)".format(N.get(), M.get(), ("" if specialize else "not "))) + print("Running GEMV {}x{} ({}specialized)".format(n, m, ("" if specialize else "not "))) - A = dace.ndarray([M, N], dtype=dtype) - x = dace.ndarray([M], dtype=dtype) - y = dace.ndarray([N], dtype=dtype) + A = dace.ndarray([m, n], dtype=dtype) + x = dace.ndarray([m], dtype=dtype) + y = dace.ndarray([n], dtype=dtype) # Intialize: randomize A, x and y - # A[:, :] = np.random.rand(M.get(), N.get()).astype(dtype.type) - # x[:] = np.random.rand(M.get()).astype(dtype.type) - # y[:] = np.random.rand(N.get()).astype(dtype.type) + # A[:, :] = np.random.rand(M, N).astype(dtype.type) + # x[:] = np.random.rand(M).astype(dtype.type) + # y[:] = np.random.rand(N).astype(dtype.type) A[:, :] = 1 x[:] = 1 y[:] = 0 @@ -179,9 +175,9 @@ def run_gemv(n: int, m: int, specialize: bool): if specialize: gemv(A=A, x=x, y=x) else: - gemv(A=A, M=M, x=x, y=y) + gemv(A=A, M=m, x=x, y=y) - residual = np.linalg.norm(y - regression) / (N.get() * M.get()) + residual = np.linalg.norm(y - regression) / (n * m) print("Residual:", residual) diff = np.abs(y - regression) wrong_elements = np.transpose(np.nonzero(diff >= 0.01)) @@ -191,7 +187,7 @@ def run_gemv(n: int, m: int, specialize: bool): if residual >= 0.01 or highest_diff >= 0.01: print("Verification failed!") print("Residual: {}".format(residual)) - print("Incorrect elements: {} / {}".format(wrong_elements.shape[0], (N.get() * M.get()))) + print("Incorrect elements: {} / {}".format(wrong_elements.shape[0], (n * m))) print("Highest difference: {}".format(highest_diff)) print("** Result:\n", y) print("** Reference:\n", regression) diff --git a/samples/fpga/histogram_fpga.py b/samples/fpga/histogram_fpga.py index 630c5d4cd0..dc12b75c17 100644 --- a/samples/fpga/histogram_fpga.py +++ b/samples/fpga/histogram_fpga.py @@ -9,7 +9,6 @@ W = dace.symbol("W") H = dace.symbol("H") num_bins = dace.symbol("num_bins") -num_bins.set(256) dtype = dace.float32 @@ -119,10 +118,10 @@ def make_nested_sdfg(parent): return sdfg -def make_sdfg(specialize): +def make_sdfg(specialize, h, w): if specialize: - sdfg = dace.SDFG("histogram_fpga_{}x{}".format(H.get(), W.get())) + sdfg = dace.SDFG("histogram_fpga_{}x{}".format(h, w)) else: sdfg = dace.SDFG("histogram_fpga") @@ -161,23 +160,25 @@ def make_sdfg(specialize): help="Fix all symbols at compile time/in hardware") args = vars(parser.parse_args()) + nbins = 256 + if args["specialize"]: - H.set(args["H"]) - W.set(args["W"]) - histogram = make_sdfg(True) - histogram.specialize(dict(H=H, W=W, num_bins=num_bins)) + h = args["H"] + w = args["W"] + histogram = make_sdfg(True, h, w) + histogram.specialize(dict(H=h, W=w, num_bins=nbins)) else: histogram = make_sdfg(False) histogram.specialize(dict(num_bins=num_bins)) - H.set(args["H"]) - W.set(args["W"]) + h = args["H"] + w = args["W"] - print("Histogram {}x{} ({}specialized)".format(H.get(), W.get(), "" if args["specialize"] else "not ")) + print("Histogram {}x{} ({}specialized)".format(h, w, "" if args["specialize"] else "not ")) A = dace.ndarray([H, W], dtype=dtype) hist = dace.ndarray([num_bins], dtype=dace.uint32) - A[:] = np.random.rand(H.get(), W.get()).astype(dace.float32.type) + A[:] = np.random.rand(h, w).astype(dace.float32.type) hist[:] = dace.uint32(0) if args["specialize"]: @@ -186,9 +187,9 @@ def make_sdfg(specialize): histogram(A=A, H=H, W=W, hist=hist) if dace.Config.get_bool('profiling'): - dace.timethis('histogram', 'numpy', (H.get() * W.get()), np.histogram, A, num_bins) + dace.timethis('histogram', 'numpy', (h * w), np.histogram, A, num_bins) - diff = np.linalg.norm(np.histogram(A, bins=num_bins.get(), range=(0.0, 1.0))[0][1:-1] - hist[1:-1]) + diff = np.linalg.norm(np.histogram(A, bins=nbins, range=(0.0, 1.0))[0][1:-1] - hist[1:-1]) print("Difference:", diff) if diff > 1e-5: diff --git a/samples/fpga/jacobi_fpga_systolic.py b/samples/fpga/jacobi_fpga_systolic.py index 78e8a2db45..d022f6712b 100644 --- a/samples/fpga/jacobi_fpga_systolic.py +++ b/samples/fpga/jacobi_fpga_systolic.py @@ -237,9 +237,9 @@ def make_outer_compute_state(sdfg): return state -def make_sdfg(specialize_all): - name = "jacobi_fpga_systolic_{}_{}x{}x{}".format(P.get(), ("H" if not specialize_all else H.get()), W.get(), - ("T" if not specialize_all else T.get())) +def make_sdfg(specialize_all, h, w, t, p): + name = "jacobi_fpga_systolic_{}_{}x{}x{}".format(p, ("H" if not specialize_all else h), w, + ("T" if not specialize_all else t)) sdfg = dace.SDFG(name) sdfg.add_symbol('T', dace.int32) @@ -272,35 +272,28 @@ def run_jacobi(w: int, h: int, t: int, p: int, specialize_all: bool = False): # Width and number of PEs must be known at compile time, as it will # influence the hardware layout - W.set(w) - P.set(p) if specialize_all: print("Specializing H and T...") - H.set(h) - T.set(t) - jacobi = make_sdfg(specialize_all) + jacobi = make_sdfg(specialize_all, h, w, t, p) jacobi.specialize(dict(W=W, P=P)) - if not specialize_all: - H.set(h) - T.set(t) - else: + if specialize_all: jacobi.specialize(dict(H=H, T=T)) - if T.get() % P.get() != 0: + if t % p != 0: raise ValueError("Iteration must be divisable by number of processing elements") - print("Jacobi Stencil {}x{} ({} steps) with {} PEs{}".format(H.get(), W.get(), T.get(), P.get(), + print("Jacobi Stencil {}x{} ({} steps) with {} PEs{}".format(h, w, t, p, (" (fully specialized)" if specialize_all else ""))) - A = dace.ndarray([H, W], dtype=dace.float32) + A = dace.ndarray([h, w], dtype=dace.float32) # Initialize arrays: Randomize A, zero B A[:] = dace.float32(0) - A[2:H.get() - 2, 2:W.get() - 2] = 1 - regression = np.ndarray([H.get() - 4, W.get() - 4], dtype=np.float32) - regression[:] = A[2:H.get() - 2, 2:W.get() - 2] + A[2:h - 2, 2:w - 2] = 1 + regression = np.ndarray([h - 4, w - 4], dtype=np.float32) + regression[:] = A[2:h - 2, 2:w - 2] ############################################# # Run DaCe program @@ -312,12 +305,12 @@ def run_jacobi(w: int, h: int, t: int, p: int, specialize_all: bool = False): # Regression kernel = np.array([[0, 0.2, 0], [0.2, 0.2, 0.2], [0, 0.2, 0]], dtype=np.float32) - for i in range(T.get()): + for i in range(t): regression = ndimage.convolve(regression, kernel, mode='constant', cval=0.0) - residual = np.linalg.norm(A[2:H.get() - 2, 2:W.get() - 2] - regression) / (H.get() * W.get()) + residual = np.linalg.norm(A[2:h - 2, 2:w - 2] - regression) / (h * w) print("Residual:", residual) - diff = np.abs(A[2:H.get() - 2, 2:W.get() - 2] - regression) + diff = np.abs(A[2:h - 2, 2:w - 2] - regression) wrong_elements = np.transpose(np.nonzero(diff >= 0.01)) highest_diff = np.max(diff) @@ -325,10 +318,10 @@ def run_jacobi(w: int, h: int, t: int, p: int, specialize_all: bool = False): if residual >= 0.01 or highest_diff >= 0.01: print("Verification failed!") print("Residual: {}".format(residual)) - print("Incorrect elements: {} / {}".format(wrong_elements.shape[0], H.get() * W.get())) + print("Incorrect elements: {} / {}".format(wrong_elements.shape[0], h * w)) print("Highest difference: {}".format(highest_diff)) - print("** Result:\n", A[:min(6, H.get()), :min(6, W.get())]) - print("** Reference:\n", regression[:min(5, H.get()), :min(4, W.get())]) + print("** Result:\n", A[:min(6, h), :min(6, w)]) + print("** Reference:\n", regression[:min(5, h), :min(4, w)]) raise RuntimeError("Validation failed.") return jacobi diff --git a/samples/fpga/matrix_multiplication_pipelined.py b/samples/fpga/matrix_multiplication_pipelined.py index d7ceaaf184..209b3be6e1 100644 --- a/samples/fpga/matrix_multiplication_pipelined.py +++ b/samples/fpga/matrix_multiplication_pipelined.py @@ -8,12 +8,12 @@ K = dace.symbol("K") -def make_sdfg(specialized): +def make_sdfg(specialized, n, k, m): if specialized: - sdfg = dace.SDFG("mm_fpga_pipelined_{}x{}x{}".format(N.get(), K.get(), M.get())) + sdfg = dace.SDFG("mm_fpga_pipelined_{}x{}x{}".format(n, k, m)) else: - sdfg = dace.SDFG("mm_fpga_pipelined_NxKx{}".format(M.get())) + sdfg = dace.SDFG("mm_fpga_pipelined_NxKx{}".format(m)) ########################################################################### # Copy data to FPGA @@ -183,37 +183,35 @@ def make_sdfg(specialized): help="Fix all loop bounds at compile time/in hardware") args = vars(parser.parse_args()) + n = args.N + k = args.K + m = args.M + if not args["specialize"]: - M.set(args["M"]) # M must always be specialized, as it's used for the static buffer size - sdfg = make_sdfg(False) - sdfg.specialize(dict(M=M)) - N.set(args["N"]) - K.set(args["K"]) + sdfg = make_sdfg(False, n, k, m) + sdfg.specialize(dict(M=m)) else: - M.set(args["M"]) - N.set(args["N"]) - K.set(args["K"]) - sdfg = make_sdfg(True) - sdfg.specialize(dict(M=M, N=N, K=K)) + sdfg = make_sdfg(True, n, k, m) + sdfg.specialize(dict(M=m, N=n, K=k)) - print("Matrix multiplication {}x{}x{} ({}specialized)".format(M.get(), N.get(), K.get(), + print("Matrix multiplication {}x{}x{} ({}specialized)".format(m, n, k, "" if args["specialize"] else "not ")) # Initialize arrays: Randomize A and B, zero C - A = np.ndarray([N.get(), K.get()], dtype=dace.float32.type) - B = np.ndarray([K.get(), M.get()], dtype=dace.float32.type) - C = np.ndarray([N.get(), M.get()], dtype=dace.float32.type) - A[:] = np.random.rand(M.get(), N.get()).astype(dace.float32.type) - B[:] = np.random.rand(N.get(), K.get()).astype(dace.float32.type) + A = np.ndarray([n, k], dtype=dace.float32.type) + B = np.ndarray([k, m], dtype=dace.float32.type) + C = np.ndarray([n, m], dtype=dace.float32.type) + A[:] = np.random.rand(m, n).astype(dace.float32.type) + B[:] = np.random.rand(n, k).astype(dace.float32.type) C[:] = dace.float32(0) if args["specialize"]: sdfg(A=A, B=B, C=C) else: - sdfg(A=A, B=B, C=C, N=N, K=K) + sdfg(A=A, B=B, C=C, N=n, K=k) - diff = np.linalg.norm((A @ B) - C) / float(M.get() * K.get()) + diff = np.linalg.norm((A @ B) - C) / float(m * k) if diff > 1e-6: raise ValueError(f"Verification failed, difference: {diff}") else: diff --git a/samples/fpga/matrix_multiplication_stream.py b/samples/fpga/matrix_multiplication_stream.py index 32dc8ae6bc..1ad0289355 100644 --- a/samples/fpga/matrix_multiplication_stream.py +++ b/samples/fpga/matrix_multiplication_stream.py @@ -137,12 +137,12 @@ def make_fpga_state(sdfg): return state -def make_sdfg(specialized): +def make_sdfg(specialized, n, k, m): if specialized: - sdfg = dace.SDFG("mm_fpga_stream_{}x{}x{}".format(N.get(), K.get(), M.get())) + sdfg = dace.SDFG("mm_fpga_stream_{}x{}x{}".format(n, k, m)) else: - sdfg = dace.SDFG("mm_fpga_stream_NxKx{}".format(M.get())) + sdfg = dace.SDFG("mm_fpga_stream_NxKx{}".format(m)) pre_state = make_copy_to_fpga_state(sdfg) compute_state = make_fpga_state(sdfg) @@ -167,34 +167,32 @@ def make_sdfg(specialized): help="Fix all loop bounds at compile time/in hardware") args = vars(parser.parse_args()) + m = args.M + n = args.N + k = args.K + if not args["specialize"]: - M.set(args["M"]) # M must always be specialized, as it's used for the static buffer size - sdfg = make_sdfg(False) - sdfg.specialize(dict(M=M)) - N.set(args["N"]) - K.set(args["K"]) + sdfg = make_sdfg(False, n, k, m) + sdfg.specialize(dict(M=m)) else: - M.set(args["M"]) - N.set(args["N"]) - K.set(args["K"]) - sdfg = make_sdfg(True) - sdfg.specialize(dict(M=M, N=N, K=K)) + sdfg = make_sdfg(True, n, k, m) + sdfg.specialize(dict(M=m, N=n, K=k)) - print("Matrix multiplication {}x{}x{} ({}specialized)".format(M.get(), N.get(), K.get(), + print("Matrix multiplication {}x{}x{} ({}specialized)".format(m, n, k, "" if args["specialize"] else "not ")) # Initialize arrays: Randomize A and B, zero C - A = np.ndarray([N.get(), K.get()], dtype=dace.float32.type) - B = np.ndarray([K.get(), M.get()], dtype=dace.float32.type) - C = np.ndarray([N.get(), M.get()], dtype=dace.float32.type) - A[:] = 1 # np.random.rand(N.get(), K.get()).astype(dace.float32.type) - B[:] = 1 # np.random.rand(K.get(), M.get()).astype(dace.float32.type) + A = np.ndarray([n, k], dtype=dace.float32.type) + B = np.ndarray([k, m], dtype=dace.float32.type) + C = np.ndarray([n, m], dtype=dace.float32.type) + A[:] = 1 # np.random.rand(n, k).astype(dace.float32.type) + B[:] = 1 # np.random.rand(k, m).astype(dace.float32.type) C[:] = dace.float32(0) - A_regression = np.ndarray([N.get(), K.get()], dtype=np.float32) - B_regression = np.ndarray([K.get(), M.get()], dtype=np.float32) - C_regression = np.ndarray([N.get(), M.get()], dtype=np.float32) + A_regression = np.ndarray([n, k], dtype=np.float32) + B_regression = np.ndarray([k, m], dtype=np.float32) + C_regression = np.ndarray([n, m], dtype=np.float32) A_regression[:] = A[:] B_regression[:] = B[:] C_regression[:] = C[:] @@ -202,9 +200,9 @@ def make_sdfg(specialized): if args["specialize"]: sdfg(A=A, B=B, C=C) else: - sdfg(A=A, B=B, C=C, N=N, K=K) + sdfg(A=A, B=B, C=C, N=n, K=k) - diff = np.linalg.norm((A @ B) - C) / float(M.get() * K.get()) + diff = np.linalg.norm((A @ B) - C) / float(m * k) if diff > 1e-6: raise ValueError(f"Verification failed, difference: {diff}") else: diff --git a/samples/fpga/matrix_multiplication_systolic.py b/samples/fpga/matrix_multiplication_systolic.py index 26cc95bf1d..514c583a93 100644 --- a/samples/fpga/matrix_multiplication_systolic.py +++ b/samples/fpga/matrix_multiplication_systolic.py @@ -241,12 +241,12 @@ def make_fpga_state(sdfg): return state -def make_sdfg(specialized): +def make_sdfg(specialized, p, n, k, m): if specialized: - sdfg = dace.SDFG("mm_fpga_systolic_{}_{}x{}x{}".format(P.get(), N.get(), K.get(), M.get())) + sdfg = dace.SDFG("mm_fpga_systolic_{}_{}x{}x{}".format(p, n, k, m)) else: - sdfg = dace.SDFG("mm_fpga_systolic_{}_NxKx{}".format(P.get(), M.get())) + sdfg = dace.SDFG("mm_fpga_systolic_{}_NxKx{}".format(p, m)) pre_state = make_copy_to_fpga_state(sdfg) compute_state = make_fpga_state(sdfg) @@ -262,35 +262,27 @@ def run_matmul_systolic(m, n, k, p, specialize): print("==== Program start ====") if not specialize: - P.set(p) - M.set(m) # M must always be specialized, as it's used for the static buffer size - sdfg = make_sdfg(False) + sdfg = make_sdfg(False, p, n, k, m) sdfg.specialize(dict(P=p, M=m)) - N.set(n) - K.set(k) else: - P.set(p) - M.set(m) - N.set(n) - K.set(k) - sdfg = make_sdfg(True) + sdfg = make_sdfg(True, p, n, k, m) sdfg.specialize(dict(P=p, M=m, N=n, K=k)) - print("Matrix multiplication {}x{}x{} with {} PEs ({}specialized)".format(M.get(), N.get(), K.get(), P.get(), + print("Matrix multiplication {}x{}x{} with {} PEs ({}specialized)".format(m, n, k, p, "" if specialize else "not ")) # Initialize arrays: Randomize A and B, zero C - A = np.ndarray([N.get(), K.get()], dtype=dace.float32.type) - B = np.ndarray([K.get(), M.get()], dtype=dace.float32.type) - C = np.ndarray([N.get(), M.get()], dtype=dace.float32.type) - A[:] = np.random.rand(N.get(), K.get()).astype(dace.float32.type) - B[:] = np.random.rand(K.get(), M.get()).astype(dace.float32.type) + A = np.ndarray([n, k], dtype=dace.float32.type) + B = np.ndarray([k, m], dtype=dace.float32.type) + C = np.ndarray([n, m], dtype=dace.float32.type) + A[:] = np.random.rand(n, k).astype(dace.float32.type) + B[:] = np.random.rand(k, m).astype(dace.float32.type) C[:] = dace.float32(0) - A_regression = np.ndarray([N.get(), K.get()], dtype=np.float32) - B_regression = np.ndarray([K.get(), M.get()], dtype=np.float32) - C_regression = np.ndarray([N.get(), M.get()], dtype=np.float32) + A_regression = np.ndarray([n, k], dtype=np.float32) + B_regression = np.ndarray([k, m], dtype=np.float32) + C_regression = np.ndarray([n, m], dtype=np.float32) A_regression[:] = A[:] B_regression[:] = B[:] C_regression[:] = C[:] @@ -298,9 +290,9 @@ def run_matmul_systolic(m, n, k, p, specialize): if specialize: sdfg(A=A, B=B, C=C) else: - sdfg(A=A, B=B, C=C, N=N, K=K) + sdfg(A=A, B=B, C=C, N=n, K=k) - diff = np.linalg.norm((A @ B) - C) / float(M.get() * K.get()) + diff = np.linalg.norm((A @ B) - C) / float(m * k) if diff > 1e-6: raise ValueError(f"Verification failed, difference: {diff}") else: diff --git a/samples/fpga/rtl/add_fortytwo.py b/samples/fpga/rtl/add_fortytwo.py index 5abcd76a5b..bd24aaa378 100644 --- a/samples/fpga/rtl/add_fortytwo.py +++ b/samples/fpga/rtl/add_fortytwo.py @@ -119,9 +119,9 @@ if __name__ == '__main__': with dace.config.set_temporary('compiler', 'xilinx', 'mode', value='hardware_emulation'): # init data structures - N.set(8192) - a = np.random.randint(0, 100, N.get()).astype(np.int32) - b = np.zeros((N.get(), )).astype(np.int32) + N = 8192 + a = np.random.randint(0, 100, N).astype(np.int32) + b = np.zeros((N, )).astype(np.int32) # show initial values print("a={}, b={}".format(a, b)) @@ -133,5 +133,5 @@ print("a={}, b={}".format(a, b)) # check result - for i in range(N.get()): + for i in range(N): assert b[i] == a[i] + 42 diff --git a/samples/fpga/rtl/axpy.py b/samples/fpga/rtl/axpy.py index 4f386c82a4..c4e9ba0af1 100644 --- a/samples/fpga/rtl/axpy.py +++ b/samples/fpga/rtl/axpy.py @@ -240,11 +240,11 @@ def make_sdfg(veclen=2): if __name__ == '__main__': with dace.config.set_temporary('compiler', 'xilinx', 'mode', value='hardware_emulation'): # init data structures - N.set(4096) + N = 4096 a = np.random.rand(1)[0].astype(np.float32) - x = np.random.rand(N.get()).astype(np.float32) - y = np.random.rand(N.get()).astype(np.float32) - result = np.zeros((N.get(), )).astype(np.float32) + x = np.random.rand(N).astype(np.float32) + y = np.random.rand(N).astype(np.float32) + result = np.zeros((N, )).astype(np.float32) # show initial values print("a={}, x={}, y={}".format(a, x, y)) @@ -260,6 +260,6 @@ def make_sdfg(veclen=2): # check result expected = a * x + y - diff = np.linalg.norm(expected - result) / N.get() + diff = np.linalg.norm(expected - result) / N print("Difference:", diff) assert diff <= 1e-5 diff --git a/samples/fpga/rtl/axpy_double_pump.py b/samples/fpga/rtl/axpy_double_pump.py index c79948007b..e87ddfd68b 100644 --- a/samples/fpga/rtl/axpy_double_pump.py +++ b/samples/fpga/rtl/axpy_double_pump.py @@ -430,11 +430,11 @@ def make_sdfg(veclen=2): with dace.config.set_temporary('compiler', 'xilinx', 'frequency', value='"0:300\\|1:600"'): with dace.config.set_temporary('compiler', 'xilinx', 'mode', value='hardware_emulation'): # init data structures - N.set(4096) + N = 4096 a = np.random.rand(1)[0].astype(np.float32) - x = np.random.rand(N.get()).astype(np.float32) - y = np.random.rand(N.get()).astype(np.float32) - result = np.zeros((N.get(), )).astype(np.float32) + x = np.random.rand(N).astype(np.float32) + y = np.random.rand(N).astype(np.float32) + result = np.zeros((N, )).astype(np.float32) # show initial values print("a={}, x={}, y={}".format(a, x, y)) @@ -450,7 +450,7 @@ def make_sdfg(veclen=2): # check result expected = a * x + y - diff = np.linalg.norm(expected - result) / N.get() + diff = np.linalg.norm(expected - result) / N print("Difference:", diff) assert diff <= 1e-5 diff --git a/samples/fpga/rtl/fladd.py b/samples/fpga/rtl/fladd.py index daf1ed269b..c2e2fdcc81 100644 --- a/samples/fpga/rtl/fladd.py +++ b/samples/fpga/rtl/fladd.py @@ -172,10 +172,10 @@ if __name__ == '__main__': with dace.config.set_temporary('compiler', 'xilinx', 'mode', value='hardware_emulation'): # init data structures - N.set(8192) - a = np.random.randint(0, 100, N.get()).astype(np.float32) - b = np.random.randint(0, 100, N.get()).astype(np.float32) - c = np.zeros((N.get() // veclen, )).astype(np.float32) + N = 8192 + a = np.random.randint(0, 100, N).astype(np.float32) + b = np.random.randint(0, 100, N).astype(np.float32) + c = np.zeros((N // veclen, )).astype(np.float32) print(a.shape, b.shape, c.shape) # show initial values @@ -189,6 +189,6 @@ # check result expected = a + b - diff = np.linalg.norm(expected - c) / N.get() + diff = np.linalg.norm(expected - c) / N print("Difference:", diff) assert diff <= 1e-5 diff --git a/samples/fpga/rtl/pipeline.py b/samples/fpga/rtl/pipeline.py index dbd0460fb0..4fe5d3c74b 100644 --- a/samples/fpga/rtl/pipeline.py +++ b/samples/fpga/rtl/pipeline.py @@ -154,9 +154,9 @@ if __name__ == '__main__': with dace.config.set_temporary('compiler', 'xilinx', 'mode', value='hardware_emulation'): # init data structures - N.set(8192) - a = np.random.randint(0, 100, N.get()).astype(np.int32) - b = np.zeros((N.get(), )).astype(np.int32) + N = 8192 + a = np.random.randint(0, 100, N).astype(np.int32) + b = np.zeros((N, )).astype(np.int32) # show initial values print("a={}, b={}".format(a, b)) @@ -168,5 +168,5 @@ print("a={}, b={}".format(a, b)) # check result - for i in range(N.get()): + for i in range(N): assert b[i] == a[i] + depth diff --git a/samples/fpga/spmv_fpga_stream.py b/samples/fpga/spmv_fpga_stream.py index 7435f7bf34..e2b3a5d1af 100644 --- a/samples/fpga/spmv_fpga_stream.py +++ b/samples/fpga/spmv_fpga_stream.py @@ -18,8 +18,8 @@ cols = dace.symbol("cols") rows = dace.symbol("rows") nnz = dace.symbol("nnz") -itype = dace.dtypes.uint32 -dtype = dace.dtypes.float32 +itype = dace.uint32 +dtype = dace.float32 def make_pre_state(sdfg): @@ -434,66 +434,10 @@ def make_main_state(sdfg): return state -def make_nested_compute_state(sdfg): - - state = sdfg.add_state("spmv") - - row_entry, row_exit = state.add_map("compute_row", {"i": "0:rows"}, schedule=ScheduleType.FPGA_Device) - - rowptr = state.add_scalar("rowptr", itype, storage=StorageType.FPGA_Registers, transient=True) - rowend = state.add_scalar("rowend", itype, storage=StorageType.FPGA_Registers, transient=True) - - nested_sdfg = make_nested_sdfg(sdfg) - nested_sdfg_tasklet = state.add_nested_sdfg(nested_sdfg, sdfg, - {"row_begin", "row_end", "A_val_read", "A_col_read", "x_read"}, - {"b_write"}) - - state.add_memlet_path(a_row, row_entry, rowptr, memlet=dace.memlet.Memlet.simple(rowptr, "0", other_subset_str="i")) - state.add_memlet_path(rowptr, - nested_sdfg_tasklet, - dst_conn="row_begin", - memlet=dace.memlet.Memlet.simple(rowptr, "0")) - - state.add_memlet_path(a_row, - row_entry, - rowend, - memlet=dace.memlet.Memlet.simple(rowend, "0", other_subset_str="i + 1")) - state.add_memlet_path(rowend, - nested_sdfg_tasklet, - dst_conn="row_end", - memlet=dace.memlet.Memlet.simple(rowend, "0")) - - state.add_memlet_path(a_val, - row_entry, - nested_sdfg_tasklet, - dst_conn="A_val_read", - memlet=dace.memlet.Memlet.simple(a_val, "0:nnz")) - - state.add_memlet_path(x, - row_entry, - nested_sdfg_tasklet, - dst_conn="x_read", - memlet=dace.memlet.Memlet.simple(x, "0:cols")) - - state.add_memlet_path(a_col, - row_entry, - nested_sdfg_tasklet, - dst_conn="A_col_read", - memlet=dace.memlet.Memlet.simple(a_col, "0:nnz")) - - state.add_memlet_path(nested_sdfg_tasklet, - row_exit, - b, - src_conn="b_write", - memlet=dace.memlet.Memlet.simple(b, "i")) - - return state - - -def make_sdfg(specialize): +def make_sdfg(specialize, rows, cols, nnz): if specialize: - name = "spmv_fpga_stream_{}x{}x{}".format(rows.get(), cols.get(), nnz.get()) + name = "spmv_fpga_stream_{}x{}x{}".format(rows, cols, nnz) else: name = "spmv_fpga_stream" sdfg = dace.SDFG(name) @@ -509,60 +453,55 @@ def make_sdfg(specialize): def run_spmv(size_w, size_h, num_nonzero, specialize): - - cols.set(size_w) - rows.set(size_h) - nnz.set(num_nonzero) - print("Sparse Matrix-Vector Multiplication {}x{} " - "({} non-zero elements, {}specialized)".format(cols.get(), rows.get(), nnz.get(), + "({} non-zero elements, {}specialized)".format(size_w, size_h, num_nonzero, "not " if not specialize else "")) - A_row = dace.ndarray([rows + 1], dtype=itype) - A_col = dace.ndarray([nnz], dtype=itype) - A_val = dace.ndarray([nnz], dtype=dtype) + A_row = dace.ndarray([size_h + 1], dtype=itype) + A_col = dace.ndarray([num_nonzero], dtype=itype) + A_val = dace.ndarray([num_nonzero], dtype=dtype) - x = dace.ndarray([cols], dtype) - b = dace.ndarray([rows], dtype) + x = dace.ndarray([size_w], dtype) + b = dace.ndarray([size_h], dtype) # Assuming uniform sparsity distribution across rows - nnz_per_row = nnz.get() // rows.get() - nnz_last_row = nnz_per_row + (nnz.get() % rows.get()) - if nnz_last_row > cols.get(): + nnz_per_row = num_nonzero // size_h + nnz_last_row = nnz_per_row + (num_nonzero % size_h) + if nnz_last_row > size_w: print("Too many nonzeros per row") exit(1) # RANDOMIZE SPARSE MATRIX A_row[0] = itype(0) - A_row[1:rows.get()] = itype(nnz_per_row) + A_row[1:size_h] = itype(nnz_per_row) A_row[-1] = itype(nnz_last_row) A_row = np.cumsum(A_row, dtype=itype.type) # Fill column data - for i in range(rows.get() - 1): + for i in range(size_h - 1): A_col[nnz_per_row*i:nnz_per_row*(i+1)] = \ - np.sort(np.random.choice(cols.get(), nnz_per_row, replace=False)) + np.sort(np.random.choice(size_w, nnz_per_row, replace=False)) # Fill column data for last row - A_col[nnz_per_row * (rows.get() - 1):] = np.sort(np.random.choice(cols.get(), nnz_last_row, replace=False)) + A_col[nnz_per_row * (size_h - 1):] = np.sort(np.random.choice(size_w, nnz_last_row, replace=False)) - A_val[:] = np.random.rand(nnz.get()).astype(dtype.type) + A_val[:] = np.random.rand(num_nonzero).astype(dtype.type) ######################### - x[:] = np.random.rand(cols.get()).astype(dtype.type) + x[:] = np.random.rand(size_w).astype(dtype.type) #b[:] = dtype(0) # Setup regression - A_sparse = scipy.sparse.csr_matrix((A_val, A_col, A_row), shape=(rows.get(), cols.get())) + A_sparse = scipy.sparse.csr_matrix((A_val, A_col, A_row), shape=(size_h, size_w)) - spmv = make_sdfg(specialize) + spmv = make_sdfg(specialize, size_h, size_w, num_nonzero) if specialize: - spmv.specialize(dict(rows=rows, cols=cols, nnz=nnz)) - spmv(A_row=A_row, A_col=A_col, A_val=A_val, x=x, b=b, rows=rows, cols=cols, nnz=nnz) + spmv.specialize(dict(rows=size_h, cols=size_w, nnz=num_nonzero)) + spmv(A_row=A_row, A_col=A_col, A_val=A_val, x=x, b=b, rows=size_h, cols=size_w, nnz=num_nonzero) if dace.Config.get_bool("profiling"): dace.timethis("spmv", "scipy", 0, A_sparse.dot, x) - diff = np.linalg.norm(A_sparse.dot(x) - b) / float(rows.get()) + diff = np.linalg.norm(A_sparse.dot(x) - b) / float(size_h) print("Difference:", diff) if diff >= 1e-5: print("Validation failed.") diff --git a/tests/chained_nested_tasklet_test.py b/tests/chained_nested_tasklet_test.py index 797fb4fc48..5b388582e0 100644 --- a/tests/chained_nested_tasklet_test.py +++ b/tests/chained_nested_tasklet_test.py @@ -12,9 +12,9 @@ def test_nested_map(): print('SDFG consecutive tasklet (nested) test') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N], dp.int32) - output = dp.ndarray([N], dp.int32) + n = 20 + input = dp.ndarray([n], dp.int32) + output = dp.ndarray([n], dp.int32) input[:] = dp.int32(5) output[:] = dp.int32(0) @@ -42,9 +42,9 @@ def test_nested_map(): mysdfg.fill_scope_connectors() mysdfg.validate() - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) - diff = np.linalg.norm(10 * input - output) / N.get() + diff = np.linalg.norm(10 * input - output) / n print("Difference:", diff) assert diff <= 1e-5 @@ -53,9 +53,9 @@ def test_nested_sdfg(): print('SDFG consecutive tasklet (nested SDFG) test') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N], dp.int32) - output = dp.ndarray([N], dp.int32) + n = 20 + input = dp.ndarray([n], dp.int32) + output = dp.ndarray([n], dp.int32) input[:] = dp.int32(5) output[:] = dp.int32(0) @@ -84,17 +84,17 @@ def test_nested_sdfg(): state.add_memlet_path(nsdfg_node, omap_exit, B_, src_conn='b', memlet=Memlet('B[0:N]')) mysdfg.validate() - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) - diff = np.linalg.norm(10 * input - output) / N.get() + diff = np.linalg.norm(10 * input - output) / n print("Difference:", diff) assert diff <= 1e-5 mysdfg.simplify() - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) - diff = np.linalg.norm(10 * input - output) / N.get() + diff = np.linalg.norm(10 * input - output) / n print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/chained_tasklet_test.py b/tests/chained_tasklet_test.py index 51b686bb12..116db82613 100644 --- a/tests/chained_tasklet_test.py +++ b/tests/chained_tasklet_test.py @@ -11,9 +11,9 @@ def test(): print('SDFG consecutive tasklet test') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N], dp.int32) - output = dp.ndarray([N], dp.int32) + n = 20 + input = dp.ndarray([n], dp.int32) + output = dp.ndarray([n], dp.int32) input[:] = dp.int32(5) output[:] = dp.int32(0) @@ -34,9 +34,9 @@ def test(): state.add_edge(A_, None, map_entry, None, Memlet.simple(A_, '0:N')) state.add_edge(map_exit, None, B_, None, Memlet.simple(B_, '0:N')) - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) - diff = np.linalg.norm(10 * input - output) / N.get() + diff = np.linalg.norm(10 * input - output) / n print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/codegen/mpi_axpy.py b/tests/codegen/mpi_axpy.py index fa15888c8e..962ee5319c 100644 --- a/tests/codegen/mpi_axpy.py +++ b/tests/codegen/mpi_axpy.py @@ -27,21 +27,21 @@ def multiplication(i): parser.add_argument("N", type=int, nargs="?", default=24) args = vars(parser.parse_args()) - N.set(args["N"]) + N = args["N"] comm = MPI.COMM_WORLD rank = comm.Get_rank() ranks = comm.Get_size() if rank == 0: - print('Scalar-vector multiplication %d (MPI, ranks = %d)' % (N.get(), ranks)) + print('Scalar-vector multiplication %d (MPI, ranks = %d)' % (N, ranks)) else: dace.Config.set('debugprint', value=False) # Initialize arrays: Randomize A and X, zero Y a = dace.float64(np.random.rand()) - x = np.random.rand(N.get()).astype(np.float64) - y = np.random.rand(N.get()).astype(np.float64) + x = np.random.rand(N).astype(np.float64) + y = np.random.rand(N).astype(np.float64) regression = (a * x + y) sdfg = axpy.to_sdfg() @@ -62,7 +62,7 @@ def multiplication(i): csdfg(A=a, X=x, Y=y, N=N) # Get range handled by this rank - partition = N.get() // ranks + partition = N // ranks reg = regression[partition * rank:partition * (rank + 1)] res = y[partition * rank:partition * (rank + 1)] diff --git a/tests/codegen/sve/application_axpy_test.py b/tests/codegen/sve/application_axpy_test.py index 0a3f19e15c..77eefbc722 100644 --- a/tests/codegen/sve/application_axpy_test.py +++ b/tests/codegen/sve/application_axpy_test.py @@ -25,18 +25,18 @@ def multiplication(i): def test_axpy(): print("==== Program start ====") - N.set(24) + N = 24 - print('Scalar-vector multiplication %d' % (N.get())) + print('Scalar-vector multiplication %d' % (N)) # Initialize arrays: Randomize A and X, zero Y A = dace.float64(np.random.rand()) - X = np.random.rand(N.get()).astype(np.float64) - Y = np.random.rand(N.get()).astype(np.float64) + X = np.random.rand(N).astype(np.float64) + Y = np.random.rand(N).astype(np.float64) A_regression = np.float64() - X_regression = np.ndarray([N.get()], dtype=np.float64) - Y_regression = np.ndarray([N.get()], dtype=np.float64) + X_regression = np.ndarray([N], dtype=np.float64) + Y_regression = np.ndarray([N], dtype=np.float64) A_regression = A X_regression[:] = X[:] Y_regression[:] = Y[:] @@ -47,11 +47,11 @@ def test_axpy(): c_axpy = sp.linalg.blas.get_blas_funcs('axpy', arrays=(X_regression, Y_regression)) if dace.Config.get_bool('profiling'): - dace.timethis('axpy', 'BLAS', (2 * N.get()), c_axpy, X_regression, Y_regression, N.get(), A_regression) + dace.timethis('axpy', 'BLAS', (2 * N), c_axpy, X_regression, Y_regression, N, A_regression) else: - c_axpy(X_regression, Y_regression, N.get(), A_regression) + c_axpy(X_regression, Y_regression, N, A_regression) - diff = np.linalg.norm(Y_regression - Y) / N.get() + diff = np.linalg.norm(Y_regression - Y) / N print("Difference:", diff) print("==== Program end ====") assert diff <= 1e-5 diff --git a/tests/codegen/sve/application_filter_test.py b/tests/codegen/sve/application_filter_test.py index dfdccde786..194db19e4e 100644 --- a/tests/codegen/sve/application_filter_test.py +++ b/tests/codegen/sve/application_filter_test.py @@ -31,12 +31,12 @@ def regression(A, ratio): @pytest.mark.sve def test_filter(): - N.set(64) + N = 64 ratio = np.float32(0.5) - print('Predicate-Based Filter. size=%d, ratio=%f' % (N.get(), ratio)) + print('Predicate-Based Filter. size=%d, ratio=%f' % (N, ratio)) - A = np.random.rand(N.get()).astype(np.float32) + A = np.random.rand(N).astype(np.float32) B = np.zeros_like(A) outsize = dace.scalar(dace.uint32) outsize[0] = 0 @@ -52,7 +52,7 @@ def test_filter(): if len(filtered) != outsize[0]: print("Difference in number of filtered items: %d (DaCe) vs. %d (numpy)" % (outsize[0], len(filtered))) - totalitems = min(outsize[0], N.get()) + totalitems = min(outsize[0], N) print('DaCe:', B[:totalitems].view(type=np.ndarray)) print('Regression:', filtered.view(type=np.ndarray)) exit(1) @@ -68,7 +68,7 @@ def test_filter(): diff = np.linalg.norm(filtered - B[:outsize[0]]) / float(outsize[0]) print("Difference:", diff) if diff > 1e-5: - totalitems = min(outsize[0], N.get()) + totalitems = min(outsize[0], N) print('DaCe:', B[:totalitems].view(type=np.ndarray)) print('Regression:', filtered.view(type=np.ndarray)) diff --git a/tests/codegen/sve/application_spmv_test.py b/tests/codegen/sve/application_spmv_test.py index 9652587e0c..b2ab3679c2 100644 --- a/tests/codegen/sve/application_spmv_test.py +++ b/tests/codegen/sve/application_spmv_test.py @@ -30,11 +30,11 @@ def compute(j): @pytest.mark.sve def test_spmv(): - W.set(64) - H.set(64) - nnz.set(640) + W = 64 + H = 64 + nnz = 640 - print('Sparse Matrix-Vector Multiplication %dx%d (%d non-zero elements)' % (W.get(), H.get(), nnz.get())) + print('Sparse Matrix-Vector Multiplication %dx%d (%d non-zero elements)' % (W, H, nnz)) A_row = dace.ndarray([H + 1], dtype=dace.uint32) A_col = dace.ndarray([nnz], dtype=dace.uint32) @@ -44,33 +44,33 @@ def test_spmv(): b = dace.ndarray([H], dace.float32) # Assuming uniform sparsity distribution across rows - nnz_per_row = nnz.get() // H.get() - nnz_last_row = nnz_per_row + (nnz.get() % H.get()) - if nnz_last_row > W.get(): + nnz_per_row = nnz // H + nnz_last_row = nnz_per_row + (nnz % H) + if nnz_last_row > W: print('Too many nonzeros per row') exit(1) # RANDOMIZE SPARSE MATRIX A_row[0] = dace.uint32(0) - A_row[1:H.get()] = dace.uint32(nnz_per_row) + A_row[1:H] = dace.uint32(nnz_per_row) A_row[-1] = dace.uint32(nnz_last_row) A_row = np.cumsum(A_row, dtype=np.uint32) # Fill column data - for i in range(H.get() - 1): + for i in range(H - 1): A_col[nnz_per_row*i:nnz_per_row*(i+1)] = \ - np.sort(np.random.choice(W.get(), nnz_per_row, replace=False)) + np.sort(np.random.choice(W, nnz_per_row, replace=False)) # Fill column data for last row - A_col[nnz_per_row * (H.get() - 1):] = np.sort(np.random.choice(W.get(), nnz_last_row, replace=False)) + A_col[nnz_per_row * (H - 1):] = np.sort(np.random.choice(W, nnz_last_row, replace=False)) - A_val[:] = np.random.rand(nnz.get()).astype(dace.float32.type) + A_val[:] = np.random.rand(nnz).astype(dace.float32.type) ######################### - x[:] = np.random.rand(W.get()).astype(dace.float32.type) + x[:] = np.random.rand(W).astype(dace.float32.type) b[:] = dace.float32(0) # Setup regression - A_sparse = scipy.sparse.csr_matrix((A_val, A_col, A_row), shape=(H.get(), W.get())) + A_sparse = scipy.sparse.csr_matrix((A_val, A_col, A_row), shape=(H, W)) sdfg = common.vectorize(spmv) @@ -79,7 +79,7 @@ def test_spmv(): if dace.Config.get_bool('profiling'): dace.timethis('spmv', 'scipy', 0, A_sparse.dot, x) - diff = np.linalg.norm(A_sparse.dot(x) - b) / float(H.get()) + diff = np.linalg.norm(A_sparse.dot(x) - b) / float(H) print("Difference:", diff) print("==== Program end ====") assert diff <= 1e-5 diff --git a/tests/compile_sdfg_test.py b/tests/compile_sdfg_test.py index 3120359262..5c6e9ae846 100644 --- a/tests/compile_sdfg_test.py +++ b/tests/compile_sdfg_test.py @@ -11,9 +11,9 @@ def test(): # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N], dp.int32) - output = dp.ndarray([N], dp.int32) + n = 20 + input = dp.ndarray([n], dp.int32) + output = dp.ndarray([n], dp.int32) input[:] = dp.int32(5) output[:] = dp.int32(0) @@ -38,9 +38,9 @@ def test(): state.add_edge(A_, None, map_entry, None, Memlet.simple(A_, '0:N')) state.add_edge(map_exit, None, B_, None, Memlet.simple(B_, '0:N')) - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) - diff = np.linalg.norm(5 * input - output) / N.get() + diff = np.linalg.norm(5 * input - output) / n print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/confres_test.py b/tests/confres_test.py index d9ca4e6e0b..0f065f8f4e 100644 --- a/tests/confres_test.py +++ b/tests/confres_test.py @@ -32,18 +32,18 @@ def compute(i, j): def test(): - W.set(20) - H.set(20) + W = 20 + H = 20 - print('Conflict Resolution Test %dx%d' % (W.get(), H.get())) + print('Conflict Resolution Test %dx%d' % (W, H)) A = dace.ndarray([W, H], dtype=dace.float32) B = dace.ndarray([H, W, H], dtype=dace.float32) red1 = dace.ndarray([3], dtype=dace.float32) red2 = dace.ndarray([1], dtype=dace.float32) - A[:] = np.random.rand(H.get(), W.get()).astype(dace.float32.type) - B[:] = np.random.rand(H.get(), W.get(), H.get()).astype(dace.float32.type) + A[:] = np.random.rand(H, W).astype(dace.float32.type) + B[:] = np.random.rand(H, W, H).astype(dace.float32.type) red1[:] = dace.float32(0) red2[:] = dace.float32(0) diff --git a/tests/constant_array_test.py b/tests/constant_array_test.py index da5387d571..69444768af 100644 --- a/tests/constant_array_test.py +++ b/tests/constant_array_test.py @@ -10,7 +10,6 @@ from scipy import ndimage N = dace.symbol('N') -N.set(20) KERNEL = np.array([[0, -1, 0], [-1, 0, -1], [0, -1, 0]], dtype=np.float32) @@ -26,7 +25,8 @@ def a2b(y, x): def test(): - print('Conv2D %dx%d' % (N.get(), N.get())) + N = 20 + print('Conv2D %dx%d' % (N, N)) A = dace.ndarray([N, N], dtype=dace.float32) B = dace.ndarray([N, N], dtype=dace.float32) @@ -34,9 +34,9 @@ def test(): # Initialize arrays: Randomize A, zero B A[:] = dace.float32(0) B[:] = dace.float32(0) - A[1:N.get() - 1, 1:N.get() - 1] = np.random.rand((N.get() - 2), (N.get() - 2)).astype(dace.float32.type) - regression = np.ndarray([N.get() - 2, N.get() - 2], dtype=np.float32) - regression[:] = A[1:N.get() - 1, 1:N.get() - 1] + A[1:N - 1, 1:N - 1] = np.random.rand((N - 2), (N - 2)).astype(dace.float32.type) + regression = np.ndarray([N - 2, N - 2], dtype=np.float32) + regression[:] = A[1:N - 1, 1:N - 1] #print(A.view(type=np.ndarray)) @@ -50,7 +50,7 @@ def test(): # Regression regression = ndimage.convolve(regression, KERNEL, mode='constant', cval=0.0) - residual = np.linalg.norm(B[1:N.get() - 1, 1:N.get() - 1] - regression) / ((N.get() - 2)**2) + residual = np.linalg.norm(B[1:N - 1, 1:N - 1] - regression) / ((N - 2)**2) print("Residual:", residual) #print(A.view(type=np.ndarray)) diff --git a/tests/copynd_test.py b/tests/copynd_test.py index 2b62bb99c9..c1a8a1ae22 100644 --- a/tests/copynd_test.py +++ b/tests/copynd_test.py @@ -11,7 +11,7 @@ def test(): print('Copy ND tests') N = dace.symbol('N') - N.set(20) + n = 20 sdfg = dace.SDFG('copynd') state = sdfg.add_state() @@ -80,15 +80,15 @@ def test(): dace.memlet.Memlet.simple(arrays[-2], '10:30, 20', other_subset_str='10, 10:30')) array_data = [ - np.random.rand(*[dace.symbolic.evaluate(s, {N: N.get()}) + np.random.rand(*[dace.symbolic.evaluate(s, {N: n}) for s in a.desc(sdfg).shape]).astype(a.desc(sdfg).dtype.type) for a in arrays ] args = {anode.label: adata for anode, adata in zip(arrays, array_data)} - args['N'] = N.get() + args['N'] = n sdfg(**args) - N = N.get() + N = n diffs = [ np.linalg.norm(array_data[1] - array_data[0][5:10, N - 7:N]) / 5.0 * 7.0, @@ -116,7 +116,7 @@ def test_gpu(): print('Copy ND tests') N = dace.symbol('N') - N.set(20) + n = 20 sdfg = dace.SDFG('copynd_gpu') state = sdfg.add_state() @@ -194,16 +194,16 @@ def test_gpu(): dace.memlet.Memlet.simple(arrays[-2], '0:5, 0:6, 0:7 , 0:8', other_subset_str='0:5, 1:7, 1:8, 0:8')) array_data = [ - np.random.rand(*[dace.symbolic.evaluate(s, {N: N.get()}) + np.random.rand(*[dace.symbolic.evaluate(s, {N: n}) for s in a.desc(sdfg).shape]).astype(a.desc(sdfg).dtype.type) for a in arrays ] args = {anode.label: adata for anode, adata in zip(arrays, array_data)} - args['N'] = N.get() + args['N'] = n sdfg.apply_gpu_transformations() sdfg(**args) - N = N.get() + N = n diffs = [ np.linalg.norm(array_data[1] - array_data[0][5:10, N - 7:N]) / 5.0 * 7.0, diff --git a/tests/cuda_block_test.py b/tests/cuda_block_test.py index 676785e0e5..8b75376a00 100644 --- a/tests/cuda_block_test.py +++ b/tests/cuda_block_test.py @@ -28,18 +28,18 @@ def mult_block_2(bi): def _test(sdfg): - N.set(128) + N = 128 - print('Vector double CUDA (block) %d' % (N.get())) + print('Vector double CUDA (block) %d' % (N)) V = dace.ndarray([N], dace.float64) Vout = dace.ndarray([N], dace.float64) - V[:] = np.random.rand(N.get()).astype(dace.float64.type) + V[:] = np.random.rand(N).astype(dace.float64.type) Vout[:] = dace.float64(0) cudahello(V=V, Vout=Vout, N=N) - diff = np.linalg.norm(2 * V - Vout) / N.get() + diff = np.linalg.norm(2 * V - Vout) / N print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/cuda_grid2d_test.py b/tests/cuda_grid2d_test.py index 7399dddc9f..accb65be75 100644 --- a/tests/cuda_grid2d_test.py +++ b/tests/cuda_grid2d_test.py @@ -20,19 +20,19 @@ def multiplication(i, j): def _test(sdfg): - W.set(128) - H.set(64) + W = 128 + H = 64 - print('Vector double CUDA (grid 2D) %dx%d' % (W.get(), H.get())) + print('Vector double CUDA (grid 2D) %dx%d' % (W, H)) V = dace.ndarray([H, W], dace.float64) Vout = dace.ndarray([H, W], dace.float64) - V[:] = np.random.rand(H.get(), W.get()).astype(dace.float64.type) + V[:] = np.random.rand(H, W).astype(dace.float64.type) Vout[:] = dace.float64(0) sdfg(V=V, Vout=Vout, H=H, W=W) - diff = np.linalg.norm(2 * V - Vout) / (H.get() * W.get()) + diff = np.linalg.norm(2 * V - Vout) / (H * W) print("Difference:", diff) print("==== Program end ====") assert diff <= 1e-5 diff --git a/tests/cuda_grid_test.py b/tests/cuda_grid_test.py index a471ac5983..2f8f29baaa 100644 --- a/tests/cuda_grid_test.py +++ b/tests/cuda_grid_test.py @@ -31,18 +31,18 @@ def multiplication(i): def _test(sdfg): - N.set(52) + N = 52 - print('Vector double CUDA %d' % (N.get())) + print('Vector double CUDA %d' % (N)) V = dace.ndarray([N], dace.float32) Vout = dace.ndarray([N], dace.float32) - V[:] = np.random.rand(N.get()).astype(dace.float32.type) + V[:] = np.random.rand(N).astype(dace.float32.type) Vout[:] = dace.float32(0) sdfg(V=V, Vout=Vout, N=N) - diff = np.linalg.norm(2 * V - Vout) / N.get() + diff = np.linalg.norm(2 * V - Vout) / N print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/cuda_smem2d_test.py b/tests/cuda_smem2d_test.py index ed1eceb92d..1ec8f81ac1 100644 --- a/tests/cuda_smem2d_test.py +++ b/tests/cuda_smem2d_test.py @@ -21,19 +21,19 @@ def mult_block(bi, bj): def _test(sdfg): - W.set(128) - H.set(64) + W = 128 + H = 64 - print('Vector double CUDA (shared memory 2D) %dx%d' % (W.get(), H.get())) + print('Vector double CUDA (shared memory 2D) %dx%d' % (W, H)) V = dace.ndarray([H, W], dace.float64) Vout = dace.ndarray([H, W], dace.float64) - V[:] = np.random.rand(H.get(), W.get()).astype(dace.float64.type) + V[:] = np.random.rand(H, W).astype(dace.float64.type) Vout[:] = dace.float64(0) sdfg(V=V, Vout=Vout, H=H, W=W) - diff = np.linalg.norm(2 * V - Vout) / (H.get() * W.get()) + diff = np.linalg.norm(2 * V - Vout) / (H * W) print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/cuda_smem_test.py b/tests/cuda_smem_test.py index 0930744578..496e01d72e 100644 --- a/tests/cuda_smem_test.py +++ b/tests/cuda_smem_test.py @@ -20,18 +20,18 @@ def mult_block(bi): def _test(sdfg): - N.set(144) + N = 144 - print('Vector double CUDA (shared memory) %d' % (N.get())) + print('Vector double CUDA (shared memory) %d' % (N)) V = dace.ndarray([N], dace.float64) Vout = dace.ndarray([N], dace.float64) - V[:] = np.random.rand(N.get()).astype(dace.float64.type) + V[:] = np.random.rand(N).astype(dace.float64.type) Vout[:] = dace.float64(0) sdfg(A=V, Vout=Vout, N=N) - diff = np.linalg.norm(2 * V - Vout) / N.get() + diff = np.linalg.norm(2 * V - Vout) / N print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/duplicate_arg_test.py b/tests/duplicate_arg_test.py index 938993e878..094dfabb0d 100644 --- a/tests/duplicate_arg_test.py +++ b/tests/duplicate_arg_test.py @@ -19,8 +19,7 @@ def product(i: _[0:N]): def test_dot(): n = 64 - N.set(n) - A = dace.ndarray([N], dtype=dace.float32) + A = dace.ndarray([n], dtype=dace.float32) out_AA = dace.scalar(dace.float64) A[:] = np.random.rand(n).astype(dace.float32.type) out_AA[0] = dace.float64(0) diff --git a/tests/duplicate_naming_test.py b/tests/duplicate_naming_test.py index 7da017b99c..3dfc969e99 100644 --- a/tests/duplicate_naming_test.py +++ b/tests/duplicate_naming_test.py @@ -34,17 +34,17 @@ def bla2(i): def test(): - W.set(3) + W = 3 A = dace.ndarray([W]) B = dace.ndarray([W]) - A[:] = np.mgrid[0:W.get()] + A[:] = np.mgrid[0:W] B[:] = dace.float32(0.0) duplicate_naming(A, B, W=W) - diff = np.linalg.norm(4 * A - B) / W.get() + diff = np.linalg.norm(4 * A - B) / W print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/dynamic_sdfg_functions_test.py b/tests/dynamic_sdfg_functions_test.py index 8fe2a9148d..9a94f926d8 100644 --- a/tests/dynamic_sdfg_functions_test.py +++ b/tests/dynamic_sdfg_functions_test.py @@ -21,10 +21,10 @@ def test_dynamic_sdfg_with_math_functions(): # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) + n = 20 - input = np.random.rand(N.get()).astype(np.float32) - output = dp.ndarray([N], dp.float32) + input = np.random.rand(n).astype(np.float32) + output = dp.ndarray([n], dp.float32) output[:] = dp.float32(0) # Construct SDFG @@ -42,10 +42,10 @@ def test_dynamic_sdfg_with_math_functions(): state.add_edge(A, None, map_entry, None, Memlet.simple(A, '0:N')) state.add_edge(map_exit, None, B, None, Memlet.simple(B, '0:N')) - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) #mymodexp_prog(input, output) - diff = np.linalg.norm(np.exp(input) - output) / N.get() + diff = np.linalg.norm(np.exp(input) - output) / n print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/external_module_test.py b/tests/external_module_test.py index fc6fec5ff4..9b72daa827 100644 --- a/tests/external_module_test.py +++ b/tests/external_module_test.py @@ -27,9 +27,9 @@ def extmodtest(A: dace.float32[W, H], result: dace.float32[1]): def test(): - W.set(12) - H.set(12) - A = np.random.rand(W.get(), H.get()).astype(np.float32) + W = 12 + H = 12 + A = np.random.rand(W, H).astype(np.float32) res = np.zeros([1], np.float32) extmodtest(A, res) diff --git a/tests/fpga/dot_fpga_test.py b/tests/fpga/dot_fpga_test.py index 36c3478c24..a9ef45a6d2 100644 --- a/tests/fpga/dot_fpga_test.py +++ b/tests/fpga/dot_fpga_test.py @@ -26,13 +26,13 @@ def product(i: _[0:N]): def run_dot(n, tile_first): - N.set(n) + N = n A = dace.ndarray([N], dtype=dace.float32) B = dace.ndarray([N], dtype=dace.float32) out_AB = dace.scalar(dace.float32) - A[:] = np.random.rand(N.get()).astype(dace.float32.type) - B[:] = np.random.rand(N.get()).astype(dace.float32.type) + A[:] = np.random.rand(N).astype(dace.float32.type) + B[:] = np.random.rand(N).astype(dace.float32.type) out_AB[0] = dace.float32(0) sdfg = dot.to_sdfg() @@ -45,7 +45,7 @@ def run_dot(n, tile_first): sdfg(A=A, B=B, out=out_AB, N=N) - diff_ab = np.linalg.norm(np.dot(A, B) - out_AB) / float(N.get()) + diff_ab = np.linalg.norm(np.dot(A, B) - out_AB) / float(N) assert diff_ab <= 1e-5 return sdfg diff --git a/tests/fpga/multibank_copy_fpga_test.py b/tests/fpga/multibank_copy_fpga_test.py index 2e53d37079..4e8c586a99 100644 --- a/tests/fpga/multibank_copy_fpga_test.py +++ b/tests/fpga/multibank_copy_fpga_test.py @@ -28,7 +28,7 @@ def mkc(sdfg: dace.SDFG, if copy_expr is None: copy_expr = src_name if (state_before == None): - state = sdfg.add_state(is_start_state=True) + state = sdfg.add_state(is_start_block=True) else: state = sdfg.add_state_after(state_before) diff --git a/tests/fpga/simple_systolic_array_test.py b/tests/fpga/simple_systolic_array_test.py index 1c9cb680d6..1694172723 100644 --- a/tests/fpga/simple_systolic_array_test.py +++ b/tests/fpga/simple_systolic_array_test.py @@ -242,10 +242,13 @@ def make_fpga_state(sdfg): return state -def make_sdfg(name=None): +def make_sdfg(name=None, p=None): if name is None: - name = "simple_systolic_array_{}".format(P.get()) + if p is not None: + name = "simple_systolic_array_{}".format(p) + else: + name = "simple_systolic_array_P" sdfg = dace.SDFG(name) @@ -262,17 +265,17 @@ def make_sdfg(name=None): @fpga_test(xilinx=False) def test_simple_systolic_array(): - P.set(4) - N.set(128) + P = 4 + N = 128 sdfg = make_sdfg() sdfg.specialize(dict(P=P, N=N)) # Initialize arrays: Randomize A and B, zero C - A = np.ndarray([N.get()], dtype=dace.int32.type) - A[:] = np.random.randint(0, 1000, N.get()).astype(dace.int32.type) + A = np.ndarray([N], dtype=dace.int32.type) + A[:] = np.random.randint(0, 1000, N).astype(dace.int32.type) - A_Exp = A + P.get() + A_Exp = A + P sdfg(A=A) # print("A: ", A) diff --git a/tests/fpga/type_inference_test.py b/tests/fpga/type_inference_test.py index 14656e6ea8..dbe8f58b48 100644 --- a/tests/fpga/type_inference_test.py +++ b/tests/fpga/type_inference_test.py @@ -74,21 +74,21 @@ def comp(i: _[0:N]): @fpga_test() def test_type_inference_fpga(): - N.set(24) + N = 24 # Initialize vector: X - X = np.random.uniform(-10, 0, N.get()).astype(dace.float32.type) - Y = np.random.uniform(-10, 0, N.get()).astype(dace.float32.type) + X = np.random.uniform(-10, 0, N).astype(dace.float32.type) + Y = np.random.uniform(-10, 0, N).astype(dace.float32.type) # compute expected result - Z = np.zeros(N.get()) - for i in range(0, N.get()): + Z = np.zeros(N) + for i in range(0, N): Z[i] = int(X[i]) + int(Y[i]) * 2.1 sdfg = type_inference.to_sdfg() sdfg.apply_transformations(FPGATransformSDFG) sdfg(x=X, y=Y, N=N) - diff = np.linalg.norm(Z - Y) / N.get() + diff = np.linalg.norm(Z - Y) / N assert diff <= 1e-5 diff --git a/tests/fpga/vec_sum_test.py b/tests/fpga/vec_sum_test.py index 619621a4dc..f6817985c9 100644 --- a/tests/fpga/vec_sum_test.py +++ b/tests/fpga/vec_sum_test.py @@ -10,32 +10,32 @@ from dace.config import set_temporary import pytest -N = dace.symbol("N") - +def run_vec_sum(vectorize_first: bool): + N = dace.symbol("N") -@dace.program -def vec_sum(x: dace.float32[N], y: dace.float32[N], z: dace.float32[N]): - @dace.map - def sum(i: _[0:N]): - in_x << x[i] - in_y << y[i] - in_z << z[i] - out >> z[i] + @dace.program + def vec_sum(x: dace.float32[N], y: dace.float32[N], z: dace.float32[N]): - out = in_x + in_y + in_z + @dace.map + def sum(i: _[0:N]): + in_x << x[i] + in_y << y[i] + in_z << z[i] + out >> z[i] + out = in_x + in_y + in_z -def run_vec_sum(vectorize_first: bool): - N.set(24) + n = 24 # Initialize arrays: X, Y and Z - X = np.random.rand(N.get()).astype(dace.float32.type) - Y = np.random.rand(N.get()).astype(dace.float32.type) - Z = np.random.rand(N.get()).astype(dace.float32.type) - - Z_exp = X + Y + Z + rng = np.random.default_rng(42) + X = rng.random(n, dtype=np.float32) + Y = rng.random(n, dtype=np.float32) + Z = rng.random(n, dtype=np.float32) + ref = np.empty(n, dtype=np.float32) + ref[:] = X + Y + Z sdfg = vec_sum.to_sdfg() @@ -54,9 +54,12 @@ def run_vec_sum(vectorize_first: bool): assert sdfg.apply_transformations(transformations, transformation_options) == 2 - sdfg(x=X, y=Y, z=Z, N=N) + sdfg(x=X, y=Y, z=Z, N=n) + + print(f"ref ({ref.shape}): {ref}") + print(f"Z ({Z.shape}): {Z}") - diff = np.linalg.norm(Z_exp - Z) / N.get() + diff = np.linalg.norm(ref- Z) / n if diff > 1e-5: raise ValueError("Difference: {}".format(diff)) diff --git a/tests/fpga/veclen_conversion_connector_test.py b/tests/fpga/veclen_conversion_connector_test.py index e72f6e729c..1d271512ec 100644 --- a/tests/fpga/veclen_conversion_connector_test.py +++ b/tests/fpga/veclen_conversion_connector_test.py @@ -1,7 +1,6 @@ # Copyright 2019-2021 ETH Zurich and the DaCe authors. All rights reserved. -import argparse import numpy as np -from veclen_conversion_test import SIZE, VECTOR_LENGTH, make_sdfg +from veclen_conversion_test import make_sdfg from dace.fpga_testing import fpga_test @@ -11,9 +10,6 @@ def test_veclen_conversion_connector(): size = 128 vector_length = 4 - SIZE.set(size) - VECTOR_LENGTH.set(vector_length) - if size % vector_length != 0: raise ValueError("Size {} must be divisible by vector length {}.".format(size, vector_length)) @@ -23,7 +19,7 @@ def test_veclen_conversion_connector(): A = np.arange(size, dtype=np.float64) B = np.zeros((size, ), dtype=np.float64) - sdfg(A=A, B=B, N=SIZE) + sdfg(A=A, B=B, N=size) mid = vector_length // 2 diff --git a/tests/fpga/veclen_conversion_test.py b/tests/fpga/veclen_conversion_test.py index ebbbe69594..21a9f575bf 100755 --- a/tests/fpga/veclen_conversion_test.py +++ b/tests/fpga/veclen_conversion_test.py @@ -1,5 +1,4 @@ # Copyright 2019-2021 ETH Zurich and the DaCe authors. All rights reserved. -import argparse import dace import numpy as np from dace.fpga_testing import intel_fpga_test @@ -9,14 +8,14 @@ DTYPE = dace.float64 -def make_copy_to_fpga_state(sdfg): +def make_copy_to_fpga_state(sdfg, veclen): state = sdfg.add_state("copy_to_device") - A_host = sdfg.add_array("A", [SIZE // VECTOR_LENGTH.get()], dtype=dace.vector(DTYPE, VECTOR_LENGTH.get())) + A_host = sdfg.add_array("A", [SIZE // veclen], dtype=dace.vector(DTYPE, veclen)) A_device = sdfg.add_array("A_device", [SIZE], - dtype=dace.vector(DTYPE, VECTOR_LENGTH.get()), + dtype=dace.vector(DTYPE, veclen), transient=True, storage=dace.dtypes.StorageType.FPGA_Global) @@ -26,22 +25,22 @@ def make_copy_to_fpga_state(sdfg): state.add_memlet_path(read, write, memlet=dace.memlet.Memlet.simple("A_device", - "0:N//{}".format(VECTOR_LENGTH.get()), - num_accesses=SIZE // VECTOR_LENGTH.get())) + "0:N//{}".format(veclen), + num_accesses=SIZE // veclen)) return state -def make_copy_to_host_state(sdfg): +def make_copy_to_host_state(sdfg, veclen): state = sdfg.add_state("copy_to_host") B_device = sdfg.add_array("B_device", [SIZE], - dtype=dace.vector(DTYPE, VECTOR_LENGTH.get()), + dtype=dace.vector(DTYPE, veclen), transient=True, storage=dace.dtypes.StorageType.FPGA_Global) - B_host = sdfg.add_array("B", [SIZE // VECTOR_LENGTH.get()], dtype=dace.vector(DTYPE, VECTOR_LENGTH.get())) + B_host = sdfg.add_array("B", [SIZE // veclen], dtype=dace.vector(DTYPE, veclen)) read = state.add_read("B_device") write = state.add_write("B") @@ -49,21 +48,21 @@ def make_copy_to_host_state(sdfg): state.add_memlet_path(read, write, memlet=dace.memlet.Memlet.simple("B", - "0:N//{}".format(VECTOR_LENGTH.get()), - num_accesses=SIZE // VECTOR_LENGTH.get())) + "0:N//{}".format(veclen), + num_accesses=SIZE // veclen)) return state -def make_fpga_state(sdfg, vectorize_connector): +def make_fpga_state(sdfg, vectorize_connector, veclen): state = sdfg.add_state("fpga_state") - sdfg.add_array("input_buffer", (VECTOR_LENGTH.get(), ), + sdfg.add_array("input_buffer", (veclen, ), DTYPE, transient=True, storage=dace.StorageType.FPGA_Registers) - sdfg.add_array("output_buffer", (VECTOR_LENGTH.get(), ), + sdfg.add_array("output_buffer", (veclen, ), DTYPE, transient=True, storage=dace.StorageType.FPGA_Registers) @@ -77,7 +76,7 @@ def make_fpga_state(sdfg, vectorize_connector): # Test read from packed memory to an unpacked buffer if vectorize_connector: - outputs = {"a_unpacked": dace.vector(DTYPE, VECTOR_LENGTH.get())} + outputs = {"a_unpacked": dace.vector(DTYPE, veclen)} else: outputs = {"a_unpacked"} # Infers an array unpack_tasklet = state.add_tasklet("unpack_tasklet", {"a"}, outputs, "a_unpacked = a") @@ -89,7 +88,7 @@ def make_fpga_state(sdfg, vectorize_connector): state.add_memlet_path(unpack_tasklet, read_buffer, src_conn="a_unpacked", - memlet=dace.Memlet.simple(read_buffer.data, "0:{}".format(VECTOR_LENGTH.get()))) + memlet=dace.Memlet.simple(read_buffer.data, "0:{}".format(veclen))) unroll_entry, unroll_exit = state.add_map("shuffle_map", {"w": "0:W"}, schedule=dace.ScheduleType.FPGA_Device, @@ -111,14 +110,14 @@ def make_fpga_state(sdfg, vectorize_connector): # Test writing from unpacked to packed from inside tasklet if vectorize_connector: - outputs = {"b": dace.vector(DTYPE, VECTOR_LENGTH.get())} + outputs = {"b": dace.vector(DTYPE, veclen)} else: outputs = {"b"} pack_tasklet = state.add_tasklet("pack_tasklet", outputs, {"b_packed"}, "b_packed = b") state.add_memlet_path(write_buffer, pack_tasklet, dst_conn="b", - memlet=dace.Memlet.simple(write_buffer.data, "0:{}".format(VECTOR_LENGTH.get()))) + memlet=dace.Memlet.simple(write_buffer.data, "0:{}".format(veclen))) # Write back out to memory from unpacked to packed memory state.add_memlet_path(pack_tasklet, @@ -130,16 +129,16 @@ def make_fpga_state(sdfg, vectorize_connector): return state -def make_sdfg(name=None, vectorize_connector=False): +def make_sdfg(name=None, vectorize_connector=False, veclen=4): if name is None: name = "veclen_conversion" sdfg = dace.SDFG(name) - pre_state = make_copy_to_fpga_state(sdfg) - post_state = make_copy_to_host_state(sdfg) - compute_state = make_fpga_state(sdfg, vectorize_connector) + pre_state = make_copy_to_fpga_state(sdfg, veclen) + post_state = make_copy_to_host_state(sdfg, veclen) + compute_state = make_fpga_state(sdfg, vectorize_connector, veclen) sdfg.add_edge(pre_state, compute_state, dace.sdfg.InterstateEdge()) sdfg.add_edge(compute_state, post_state, dace.sdfg.InterstateEdge()) @@ -149,23 +148,19 @@ def make_sdfg(name=None, vectorize_connector=False): @intel_fpga_test() def test_veclen_conversion(): - size = 128 vector_length = 4 - SIZE.set(size) - VECTOR_LENGTH.set(vector_length) - if size % vector_length != 0: raise ValueError("Size {} must be divisible by vector length {}.".format(size, vector_length)) - sdfg = make_sdfg(vectorize_connector=False) + sdfg = make_sdfg(vectorize_connector=False, veclen=vector_length) sdfg.specialize({"W": vector_length}) A = np.arange(size, dtype=np.float64) B = np.zeros((size, ), dtype=np.float64) - sdfg(A=A, B=B, N=SIZE) + sdfg(A=A, B=B, N=size) mid = vector_length // 2 diff --git a/tests/fpga/vector_reduce_test.py b/tests/fpga/vector_reduce_test.py index f7fbb76b07..8c2fa9b332 100644 --- a/tests/fpga/vector_reduce_test.py +++ b/tests/fpga/vector_reduce_test.py @@ -28,10 +28,10 @@ def sum(i: _[0:N]): @fpga_test() def test_vector_reduce(): - N.set(24) + N = 24 # Initialize arrays: X, Y and Z - X = np.random.rand(N.get()).astype(dace.float32.type) + X = np.random.rand(N).astype(dace.float32.type) s = dace.scalar(dace.float32) sdfg = vector_reduce.to_sdfg() @@ -42,7 +42,7 @@ def test_vector_reduce(): s_exp = 0.0 for x in X: s_exp += x - diff = np.linalg.norm(s_exp - s) / N.get() + diff = np.linalg.norm(s_exp - s) / N assert diff <= 1e-5 return sdfg diff --git a/tests/instrumentation_test.py b/tests/instrumentation_test.py index ef844ea472..69eff85a8e 100644 --- a/tests/instrumentation_test.py +++ b/tests/instrumentation_test.py @@ -26,7 +26,6 @@ def mult(i: _[0:N], j: _[0:N], k: _[0:N]): def onetest(instrumentation: dace.InstrumentationType, size=128): - N.set(size) A = np.random.rand(size, size) B = np.random.rand(size, size) C = np.zeros([size, size], dtype=np.float64) @@ -47,7 +46,7 @@ def onetest(instrumentation: dace.InstrumentationType, size=128): if instrumentation == dace.InstrumentationType.GPU_Events: sdfg.apply_transformations(GPUTransformSDFG) - sdfg(A=A, B=B, C=C, N=N) + sdfg(A=A, B=B, C=C, N=size) # Check for correctness assert np.allclose(C, 20 * A @ B) diff --git a/tests/intarg_test.py b/tests/intarg_test.py index ef92e0884c..335d0acbae 100644 --- a/tests/intarg_test.py +++ b/tests/intarg_test.py @@ -15,17 +15,17 @@ def compute(i): def test(): - W.set(3) + W = 3 A = dp.ndarray([W]) B = dp.ndarray([W]) - A[:] = np.mgrid[0:W.get()] + A[:] = np.mgrid[0:W] B[:] = dp.float32(0.0) intarg(A, B, 5, W=W) - diff = np.linalg.norm(5 * A - B) / W.get() + diff = np.linalg.norm(5 * A - B) / W print("Difference:", diff) print("==== Program end ====") assert diff <= 1e-5 diff --git a/tests/library/sparse/csrmm_test.py b/tests/library/sparse/csrmm_test.py index ed9cbbc393..0a04ebf428 100644 --- a/tests/library/sparse/csrmm_test.py +++ b/tests/library/sparse/csrmm_test.py @@ -23,7 +23,7 @@ def make_sdfg(transB: bool, alpha: float, beta: float, implementation: str, dtyp else: sdfg.add_array("B", shape=(M, K), dtype=dtype, transient=False) - state = sdfg.add_state("state", is_start_state=True) + state = sdfg.add_state("state", is_start_block=True) a_row_node = state.add_access("A_row") a_col_node = state.add_access("A_col") a_val_node = state.add_access("A_val") diff --git a/tests/library/sparse/csrmv_test.py b/tests/library/sparse/csrmv_test.py index 3fb96627af..f08dab4fe4 100644 --- a/tests/library/sparse/csrmv_test.py +++ b/tests/library/sparse/csrmv_test.py @@ -20,7 +20,7 @@ def make_sdfg(alpha: float, beta: float, implementation: str, dtype) -> dace.SDF sdfg.add_array("C", shape=(N, ), dtype=dtype, transient=False) sdfg.add_array("B", shape=(M, ), dtype=dtype, transient=False) - state = sdfg.add_state("state", is_start_state=True) + state = sdfg.add_state("state", is_start_block=True) a_row_node = state.add_access("A_row") a_col_node = state.add_access("A_col") a_val_node = state.add_access("A_val") diff --git a/tests/local_inline_test.py b/tests/local_inline_test.py index 6a4097b5c3..2c07a1c3ad 100644 --- a/tests/local_inline_test.py +++ b/tests/local_inline_test.py @@ -29,19 +29,19 @@ def local_inline(A: dace.float64[W], B: dace.float64[W], C: dace.float64[W]): def test(): - W.set(3) + W = 3 A = dace.ndarray([W]) B = dace.ndarray([W]) C = dace.ndarray([W]) - A[:] = np.mgrid[0:W.get()] + A[:] = np.mgrid[0:W] B[:] = 0.0 C[:] = 0.0 local_inline(A, B, C) - diff = np.linalg.norm((-(-A + 1) + 1) - C) / W.get() + diff = np.linalg.norm((-(-A + 1) + 1) - C) / W print("Difference:", diff) print("==== Program end ====") assert diff <= 1e-5 diff --git a/tests/mapreduce_test.py b/tests/mapreduce_test.py index 81a6490614..e0cc9fa31c 100644 --- a/tests/mapreduce_test.py +++ b/tests/mapreduce_test.py @@ -140,15 +140,15 @@ def summation_outer(i: _[0:M], k: _[0:K], j: _[0:N]): def onetest(program): - M.set(50) - N.set(20) - K.set(5) + M = 50 + N = 20 + K = 5 - print('Matrix multiplication %dx%dx%d' % (M.get(), N.get(), K.get())) + print('Matrix multiplication %dx%dx%d' % (M, N, K)) - A = np.random.rand(M.get(), K.get()) - B = np.random.rand(K.get(), N.get()) - C = np.zeros([M.get(), N.get()], np.float64) + A = np.random.rand(M, K) + B = np.random.rand(K, N) + C = np.zeros([M, N], np.float64) C_regression = A @ B sdfg = program.to_sdfg() @@ -156,21 +156,21 @@ def onetest(program): sdfg.apply_transformations([MapFusion, MapWCRFusion]) sdfg(A=A, B=B, C=C, M=M, N=N, K=K) - diff = np.linalg.norm(C_regression - C) / (M.get() * N.get()) + diff = np.linalg.norm(C_regression - C) / (M * N) print("Difference:", diff) assert diff <= 1e-5 def test_basic(): - W.set(128) - H.set(128) + W = 128 + H = 128 - print('Map-Reduce Test %dx%d' % (W.get(), H.get())) + print('Map-Reduce Test %dx%d' % (W, H)) A = dace.ndarray([H, W], dtype=dace.float32) B = dace.ndarray([H, W], dtype=dace.float32) res = dace.ndarray([1], dtype=dace.float32) - A[:] = np.random.rand(H.get(), W.get()).astype(dace.float32.type) + A[:] = np.random.rand(H, W).astype(dace.float32.type) B[:] = dace.float32(0) res[:] = dace.float32(0) @@ -185,23 +185,23 @@ def test_basic(): def test_mmm(): - M.set(50) - N.set(20) - K.set(5) + M = 50 + N = 20 + K = 5 - print('Matrix multiplication %dx%dx%d' % (M.get(), N.get(), K.get())) + print('Matrix multiplication %dx%dx%d' % (M, N, K)) # Initialize arrays: Randomize A and B, zero C A = dace.ndarray([M, N], dtype=dace.float64) B = dace.ndarray([N, K], dtype=dace.float64) C = dace.ndarray([M, K], dtype=dace.float64) - A[:] = np.random.rand(M.get(), N.get()).astype(dace.float64.type) - B[:] = np.random.rand(N.get(), K.get()).astype(dace.float64.type) + A[:] = np.random.rand(M, N).astype(dace.float64.type) + B[:] = np.random.rand(N, K).astype(dace.float64.type) C[:] = dace.float64(0) - A_regression = np.ndarray([M.get(), N.get()], dtype=np.float64) - B_regression = np.ndarray([N.get(), K.get()], dtype=np.float64) - C_regression = np.ndarray([M.get(), K.get()], dtype=np.float64) + A_regression = np.ndarray([M, N], dtype=np.float64) + B_regression = np.ndarray([N, K], dtype=np.float64) + C_regression = np.ndarray([M, K], dtype=np.float64) A_regression[:] = A[:] B_regression[:] = B[:] C_regression[:] = C[:] @@ -217,21 +217,21 @@ def test_mmm(): def test_extradims(): - W.set(128) - H.set(128) + W = 128 + H = 128 - print('Map-Reduce Test %dx%d' % (W.get(), H.get())) + print('Map-Reduce Test %dx%d' % (W, H)) A = dace.ndarray([1, H, 1, W, 1], dtype=dace.float32) B = dace.ndarray([H, W], dtype=dace.float32) res = dace.ndarray([1], dtype=dace.float32) - A[:] = np.random.rand(1, H.get(), 1, W.get(), 1).astype(dace.float32.type) + A[:] = np.random.rand(1, H, 1, W, 1).astype(dace.float32.type) B[:] = dace.float32(0) res[:] = dace.float32(0) mapreduce_test_3(A, B, res) - diff = np.linalg.norm(5 * A.reshape((H.get(), W.get())) - B) / (H.get() * W.get()) + diff = np.linalg.norm(5 * A.reshape((H, W)) - B) / (H * W) diff_res = abs((np.sum(B) - res[0])).view(type=np.ndarray) print("Difference:", diff, diff_res) print("==== Program end ====") @@ -239,25 +239,25 @@ def test_extradims(): def test_permuted(): - M.set(50) - N.set(20) - K.set(5) + M = 50 + N = 20 + K = 5 - print('Matrix multiplication %dx%dx%d' % (M.get(), N.get(), K.get())) + print('Matrix multiplication %dx%dx%d' % (M, N, K)) # Initialize arrays: Randomize A and B, zero C A = dace.ndarray([M, N], dtype=dace.float64) B = dace.ndarray([N, K], dtype=dace.float64) C = dace.ndarray([M, K], dtype=dace.float64) D = dace.ndarray([M, K, N], dtype=dace.float64) - A[:] = np.random.rand(M.get(), N.get()).astype(dace.float64.type) - B[:] = np.random.rand(N.get(), K.get()).astype(dace.float64.type) + A[:] = np.random.rand(M, N).astype(dace.float64.type) + B[:] = np.random.rand(N, K).astype(dace.float64.type) C[:] = dace.float64(0) D[:] = dace.float64(0) - A_regression = np.ndarray([M.get(), N.get()], dtype=np.float64) - B_regression = np.ndarray([N.get(), K.get()], dtype=np.float64) - C_regression = np.ndarray([M.get(), K.get()], dtype=np.float64) + A_regression = np.ndarray([M, N], dtype=np.float64) + B_regression = np.ndarray([N, K], dtype=np.float64) + C_regression = np.ndarray([M, K], dtype=np.float64) A_regression[:] = A[:] B_regression[:] = B[:] C_regression[:] = C[:] @@ -265,18 +265,18 @@ def test_permuted(): mapreduce_test_4(A, B, C, D) np.dot(A_regression, B_regression, C_regression) - diff = np.linalg.norm(C_regression - C) / (M.get() * K.get()) + diff = np.linalg.norm(C_regression - C) / (M * K) print("Difference:", diff) assert diff <= 1e-5 def test_histogram(): - W.set(32) - H.set(32) + W = 32 + H = 32 - print('Histogram (dec) %dx%d' % (W.get(), H.get())) + print('Histogram (dec) %dx%d' % (W, H)) - A = np.random.randint(0, BINS, (H.get(), W.get())).astype(np.uint8) + A = np.random.randint(0, BINS, (H, W)).astype(np.uint8) hist = np.zeros([BINS], dtype=np.uint32) sdfg = histogram.to_sdfg() diff --git a/tests/memlet_lifetime_validation_test.py b/tests/memlet_lifetime_validation_test.py index 6a8e65cd8d..1f206e9cc5 100644 --- a/tests/memlet_lifetime_validation_test.py +++ b/tests/memlet_lifetime_validation_test.py @@ -11,11 +11,6 @@ def test(): print('SDFG memlet lifetime validation test') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N], dp.int32) - output = dp.ndarray([N], dp.int32) - input[:] = dp.int32(5) - output[:] = dp.int32(0) # Construct SDFG 1 sdfg1 = SDFG('shouldntwork1') diff --git a/tests/multi_output_scope_test.py b/tests/multi_output_scope_test.py index 00a23e78dc..29ba811fdc 100644 --- a/tests/multi_output_scope_test.py +++ b/tests/multi_output_scope_test.py @@ -18,18 +18,18 @@ def compute(i): def test(): - W.set(120) + W = 120 A = dace.ndarray([W]) stats = dace.ndarray([2]) - A[:] = np.random.normal(3.0, 5.0, W.get()) + A[:] = np.random.normal(3.0, 5.0, W) stats[:] = 0.0 multi_output_scope(A, stats, W=W) - mean = stats[0] / W.get() - variance = stats[1] / W.get() - mean * mean + mean = stats[0] / W + variance = stats[1] / W - mean * mean print("Mean: %f, Variance: %f" % (mean, variance)) diff_mean = abs(mean - np.mean(A)) diff --git a/tests/multiple_cr_test.py b/tests/multiple_cr_test.py index ebcb03923e..cf78c48242 100644 --- a/tests/multiple_cr_test.py +++ b/tests/multiple_cr_test.py @@ -11,8 +11,8 @@ def test(): print('SDFG multiple tasklet test') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N], dp.int64) + n = 20 + input = dp.ndarray([n], dp.int64) sum = dp.ndarray([1], dp.int64) product = dp.ndarray([1], dp.int64) input[:] = dp.int64(5) @@ -41,7 +41,7 @@ def test(): state.add_edge(t2, 'b', map_exit, None, Memlet.simple(p, '0', wcr_str='lambda a,b: a*b')) state.add_edge(map_exit, None, p, None, Memlet.simple(p, '0')) - mysdfg(A=input, s=sum, p=product, N=N) + mysdfg(A=input, s=sum, p=product, N=n) diff_sum = 5 * 20 - sum[0] diff_prod = 5**20 - product[0] diff --git a/tests/multiple_tasklet_test.py b/tests/multiple_tasklet_test.py index 6091fe93d4..d7db9e1e36 100644 --- a/tests/multiple_tasklet_test.py +++ b/tests/multiple_tasklet_test.py @@ -11,9 +11,9 @@ def test(): print('SDFG multiple tasklet test') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N], dp.int32) - output = dp.ndarray([N], dp.int32) + n = 20 + input = dp.ndarray([n], dp.int32) + output = dp.ndarray([n], dp.int32) input[:] = dp.int32(5) output[:] = dp.int32(0) @@ -38,9 +38,9 @@ def test(): state.add_edge(A, None, map_entry, None, Memlet.simple(A, '0:N')) state.add_edge(map_exit, None, B, None, Memlet.simple(B, '0:N')) - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) - diff = np.linalg.norm(5 * input - output) / N.get() + diff = np.linalg.norm(5 * input - output) / n print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/multistate_init_test.py b/tests/multistate_init_test.py index 5e5a2afa6e..3359ce3e56 100644 --- a/tests/multistate_init_test.py +++ b/tests/multistate_init_test.py @@ -27,17 +27,17 @@ def bla2(i): def test(): - W.set(3) + W = 3 A = dace.ndarray([W]) regression = dace.ndarray([W]) - A[:] = np.mgrid[0:W.get()] + A[:] = np.mgrid[0:W] regression[:] = A[:] multistate_init(A, W=W) - diff = np.linalg.norm(4 * regression - A) / W.get() + diff = np.linalg.norm(4 * regression - A) / W print("Difference:", diff) print("==== Program end ====") assert diff <= 1e-5 diff --git a/tests/multistream_custom_cudatest.py b/tests/multistream_custom_cudatest.py index 2071cf719c..931352609e 100644 --- a/tests/multistream_custom_cudatest.py +++ b/tests/multistream_custom_cudatest.py @@ -6,7 +6,6 @@ # Create symbols N = dp.symbol('N') -N.set(27) # Create a GPU SDFG with a custom C++ tasklet sdfg = dp.SDFG('cublas_multistream_test') @@ -101,6 +100,7 @@ @pytest.mark.gpu def test_multistream_custom(): + N = 27 # First, add libraries to link (CUBLAS) to configuration oldconf = dp.Config.get('compiler', 'cpu', 'libs') if os.name == 'nt': @@ -109,13 +109,13 @@ def test_multistream_custom(): dp.Config.append('compiler', 'cpu', 'libs', value='libcublas.so') # Initialize arrays. We are using column-major order to support CUBLAS! - A = np.ndarray([N.get(), N.get()], dtype=np.float64, order='F') - B = np.ndarray([N.get(), N.get()], dtype=np.float64, order='F') - C = np.ndarray([N.get(), N.get()], dtype=np.float64, order='F') + A = np.ndarray([N, N], dtype=np.float64, order='F') + B = np.ndarray([N, N], dtype=np.float64, order='F') + C = np.ndarray([N, N], dtype=np.float64, order='F') - A[:] = np.random.rand(N.get(), N.get()) - B[:] = np.random.rand(N.get(), N.get()) - C[:] = np.random.rand(N.get(), N.get()) + A[:] = np.random.rand(N, N) + B[:] = np.random.rand(N, N) + C[:] = np.random.rand(N, N) out_ref = A @ A @ B diff --git a/tests/nested_sdfg_python_test.py b/tests/nested_sdfg_python_test.py index 414ce0b245..2a7b8712bb 100644 --- a/tests/nested_sdfg_python_test.py +++ b/tests/nested_sdfg_python_test.py @@ -31,15 +31,15 @@ def do(): def test(): print('Nested SDFG test (Python syntax)') # Externals (parameters, symbols) - N.set(64) + N = 64 - input = np.random.rand(N.get(), N.get()).astype(dp.float32.type) - output = np.zeros((N.get(), N.get()), dp.float32.type) + input = np.random.rand(N, N).astype(dp.float32.type) + output = np.zeros((N, N), dp.float32.type) sdfg = sdfg_with_children.to_sdfg() sdfg(A=input, B=output, N=N) - diff = np.linalg.norm(output - np.power(input, 5)) / (N.get() * N.get()) + diff = np.linalg.norm(output - np.power(input, 5)) / (N * N) print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/nested_sdfg_test.py b/tests/nested_sdfg_test.py index b68bd8fa19..a36dc0963a 100644 --- a/tests/nested_sdfg_test.py +++ b/tests/nested_sdfg_test.py @@ -40,16 +40,16 @@ def do(): state.add_memlet_path(nsdfg, map_exit, B, src_conn='output', memlet=Memlet.simple(B, 'i,j')) - N.set(64) + N = 64 input = dp.ndarray([N, N], dp.float32) output = dp.ndarray([N, N], dp.float32) - input[:] = np.random.rand(N.get(), N.get()).astype(dp.float32.type) + input[:] = np.random.rand(N, N).astype(dp.float32.type) output[:] = dp.float32(0) mysdfg(A=input, B=output, N=N) - diff = np.linalg.norm(output - np.power(input, 5)) / (N.get() * N.get()) + diff = np.linalg.norm(output - np.power(input, 5)) / (N * N) print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/nested_symbol_test.py b/tests/nested_symbol_test.py index ac3f794300..3195d915ac 100644 --- a/tests/nested_symbol_test.py +++ b/tests/nested_symbol_test.py @@ -4,7 +4,6 @@ import warnings N = dace.symbol('N') -N.set(12345) @dace.program diff --git a/tests/numpy/datatype_conversion_test.py b/tests/numpy/datatype_conversion_test.py index fba7585e24..f9fc23316b 100644 --- a/tests/numpy/datatype_conversion_test.py +++ b/tests/numpy/datatype_conversion_test.py @@ -63,12 +63,12 @@ def simple_symbol_conversion(A: dace.int32[N]): def test_simple_symbol_conversion(): - N.set(10) - A = np.random.randint(0, 1000, size=(N.get(), ), dtype=np.int32) + N = 10 + A = np.random.randint(0, 1000, size=(N, ), dtype=np.int32) B = simple_symbol_conversion(A) assert (B.dtype == np.int64) - assert (B[0] == np.int64(N.get())) + assert (B[0] == np.int64(N)) if __name__ == "__main__": diff --git a/tests/numpy/indirection_test.py b/tests/numpy/indirection_test.py index bbe21226f9..bfea78b954 100644 --- a/tests/numpy/indirection_test.py +++ b/tests/numpy/indirection_test.py @@ -15,19 +15,19 @@ def indirection(A: dace.float64[M], x: dace.int32[N]): def test_indirection(): - M.set(100) - N.set(100) + M = 100 + N = 100 - x = np.ndarray((N.get(), ), dtype=np.int32) - for i in range(N.get()): - x[i] = N.get() - 1 - i - A = np.ndarray((M.get(), ), dtype=np.float64) + x = np.ndarray((N, ), dtype=np.int32) + for i in range(N): + x[i] = N - 1 - i + A = np.ndarray((M, ), dtype=np.float64) indirection(A, x) - npA = np.ndarray((M.get(), ), dtype=np.float64) + npA = np.ndarray((M, ), dtype=np.float64) npA[:] = 1.0 - for j in range(1, N.get()): + for j in range(1, N): npA[x[j]] += npA[x[j - 1]] rel_norm = np.linalg.norm(npA - A) / np.linalg.norm(npA) diff --git a/tests/numpy/inline_scalar_test.py b/tests/numpy/inline_scalar_test.py index 1787668b7c..68f990a966 100644 --- a/tests/numpy/inline_scalar_test.py +++ b/tests/numpy/inline_scalar_test.py @@ -13,9 +13,6 @@ def transpose_add(A: dace.float32[M, K], B: dace.float32[K, M]): def test_inline_scalar(): - K.set(24) - M.set(25) - A = np.random.rand(25, 24).astype(np.float32) B = np.random.rand(24, 25).astype(np.float32) diff --git a/tests/numpy/map_syntax_test.py b/tests/numpy/map_syntax_test.py index fd6e6ff36c..fe7af1d644 100644 --- a/tests/numpy/map_syntax_test.py +++ b/tests/numpy/map_syntax_test.py @@ -16,12 +16,12 @@ def copy3d(A: dace.float32[M, N, K], B: dace.float32[M, N, K]): def test_copy3d(): - [sym.set(24) for sym in [M, N, K]] - A = np.random.rand(M.get(), N.get(), K.get()).astype(np.float32) - B = np.random.rand(M.get(), N.get(), K.get()).astype(np.float32) + N = M = K = 24 + A = np.random.rand(M, N, K).astype(np.float32) + B = np.random.rand(M, N, K).astype(np.float32) copy3d(A, B) - diff = np.linalg.norm(B - A) / (M.get() * N.get()) + diff = np.linalg.norm(B - A) / (M * N) print('Difference:', diff) assert diff < 1e-5 diff --git a/tests/numpy/range_indirection_test.py b/tests/numpy/range_indirection_test.py index 94943bb9c8..799060e506 100644 --- a/tests/numpy/range_indirection_test.py +++ b/tests/numpy/range_indirection_test.py @@ -15,19 +15,19 @@ def range_indirection(A: dace.float64[M, N], x: dace.int32[M]): def test(): - M.set(100) - N.set(100) + M = 100 + N = 100 - x = np.ndarray((M.get(), ), dtype=np.int32) - for i in range(M.get()): - x[i] = M.get() - 1 - i - A = np.ndarray((M.get(), N.get()), dtype=np.float64) + x = np.ndarray((M, ), dtype=np.int32) + for i in range(M): + x[i] = M - 1 - i + A = np.ndarray((M, N), dtype=np.float64) range_indirection(A, x) - npA = np.ndarray((M.get(), N.get()), dtype=np.float64) + npA = np.ndarray((M, N), dtype=np.float64) npA[:] = 1.0 - for j in range(1, M.get()): + for j in range(1, M): npA[x[j]] += npA[x[j - 1]] rel_norm = np.linalg.norm(npA - A) / np.linalg.norm(npA) diff --git a/tests/numpy/slice_test.py b/tests/numpy/slice_test.py index 4b5f016cdd..b4e4d59e12 100644 --- a/tests/numpy/slice_test.py +++ b/tests/numpy/slice_test.py @@ -19,10 +19,10 @@ def test(): A = np.random.rand(5, 4) B = np.random.rand(4, 5) C = np.random.rand(4, 4) - N.set(5) + N = 5 slicetest(A, B, C) - diff = np.linalg.norm(C - (A[1:N.get()] * B[:, 0:N.get() - 1])) + diff = np.linalg.norm(C - (A[1:N] * B[:, 0:N - 1])) print('Difference:', diff) assert diff <= 1e-5 diff --git a/tests/numpy/transient_test.py b/tests/numpy/transient_test.py index 91d7cc7ecf..37b68ade1f 100644 --- a/tests/numpy/transient_test.py +++ b/tests/numpy/transient_test.py @@ -22,16 +22,16 @@ def ttest(A: dace.float32[M, N, K], B: dace.float32[M, N, K]): def test(): - M.set(13) - N.set(8) - K.set(25) - A = np.random.rand(M.get(), N.get(), K.get()).astype(np.float32) - B = np.random.rand(M.get(), N.get(), K.get()).astype(np.float32) + M = 13 + N = 8 + K = 25 + A = np.random.rand(M, N, K).astype(np.float32) + B = np.random.rand(M, N, K).astype(np.float32) realB = B - 5 * A - 1.0 ttest(A, B) - diff = np.linalg.norm(B - realB) / (M.get() * K.get() * N.get()) + diff = np.linalg.norm(B - realB) / (M * K * N) print('Difference:', diff) assert diff <= 1e-5 diff --git a/tests/numpy/ufunc_support_test.py b/tests/numpy/ufunc_support_test.py index df0234259b..81f0e2a8a1 100644 --- a/tests/numpy/ufunc_support_test.py +++ b/tests/numpy/ufunc_support_test.py @@ -71,10 +71,10 @@ def ufunc_add_simple4(A: dace.int32[N]): def test_ufunc_add_simple4(): - N.set(10) - A = np.random.randint(10, size=(N.get(), ), dtype=np.int32) + N = 10 + A = np.random.randint(10, size=(N, ), dtype=np.int32) C = ufunc_add_simple4(A) - assert (np.array_equal(A + N.get(), C)) + assert (np.array_equal(A + N, C)) @dace.program @@ -239,10 +239,10 @@ def ufunc_add_reduce_simple3(A: dace.int32[N]): def test_ufunc_add_reduce_simple3(): - N.set(10) - A = np.random.randint(1, 10, size=(N.get(), ), dtype=np.int32) + N = 10 + A = np.random.randint(1, 10, size=(N, ), dtype=np.int32) s = ufunc_add_reduce_simple3(A) - assert (np.array_equal(np.add.reduce(N.get()) + A, s)) + assert (np.array_equal(np.add.reduce(N) + A, s)) @dace.program @@ -416,10 +416,10 @@ def ufunc_add_outer_simple4(A: dace.int32[2, 2, 2, 2, N]): def test_ufunc_add_outer_simple4(): - N.set(10) - A = np.random.randint(1, 10, size=(2, 2, 2, 2, N.get()), dtype=np.int32) + N = 10 + A = np.random.randint(1, 10, size=(2, 2, 2, 2, N), dtype=np.int32) s = ufunc_add_outer_simple4(A) - assert (np.array_equal(np.add.outer(A, N.get()), s)) + assert (np.array_equal(np.add.outer(A, N), s)) @dace.program diff --git a/tests/offset_stride_test.py b/tests/offset_stride_test.py index d02e441b47..b78ea6c43f 100644 --- a/tests/offset_stride_test.py +++ b/tests/offset_stride_test.py @@ -10,10 +10,10 @@ def test(): print('Multidimensional offset and stride test') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) - input = dp.ndarray([N, N], dp.float32) + n = 20 + input = dp.ndarray([n, n], dp.float32) output = dp.ndarray([4, 3], dp.float32) - input[:] = (np.random.rand(N.get(), N.get()) * 5).astype(dp.float32.type) + input[:] = (np.random.rand(n, n) * 5).astype(dp.float32.type) output[:] = dp.float32(0) # Construct SDFG @@ -31,9 +31,9 @@ def test(): state.add_edge(A_, None, map_entry, None, Memlet.simple(A_, '1:4,1:3')) state.add_edge(map_exit, None, B_, None, Memlet.simple(B_, '1:4,1:3')) - mysdfg(A=input, B=output, N=N) + mysdfg(A=input, B=output, N=n) - diff = np.linalg.norm(output[0:3, 0:2] - input[3:6, 4:6]) / N.get() + diff = np.linalg.norm(output[0:3, 0:2] - input[3:6, 4:6]) / n print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/passes/constant_propagation_test.py b/tests/passes/constant_propagation_test.py index fc22dd7f96..c41f1fc4a6 100644 --- a/tests/passes/constant_propagation_test.py +++ b/tests/passes/constant_propagation_test.py @@ -358,13 +358,13 @@ def test_for_with_external_init_nested(): sdfg = dace.SDFG('for_with_external_init_nested') sdfg.add_array('A', (N, ), dace.int32) - init = sdfg.add_state('init', is_start_state=True) + init = sdfg.add_state('init', is_start_block=True) main = sdfg.add_state('main') sdfg.add_edge(init, main, dace.InterstateEdge(assignments={'i': 'N-1'})) nsdfg = dace.SDFG('nested_sdfg') - nsdfg.add_array('inner_A', (N,), dace.int32) - ninit = nsdfg.add_state('nested_init', is_start_state=True) + nsdfg.add_array('inner_A', (N, ), dace.int32) + ninit = nsdfg.add_state('nested_init', is_start_block=True) nguard = nsdfg.add_state('nested_guard') nbody = nsdfg.add_state('nested_body') nexit = nsdfg.add_state('nested_exit') @@ -403,13 +403,13 @@ def test_for_with_external_init_nested_start_with_guard(): sdfg = dace.SDFG('for_with_external_init_nested_start_with_guard') sdfg.add_array('A', (N, ), dace.int32) - init = sdfg.add_state('init', is_start_state=True) + init = sdfg.add_state('init', is_start_block=True) main = sdfg.add_state('main') sdfg.add_edge(init, main, dace.InterstateEdge(assignments={'i': '1'})) nsdfg = dace.SDFG('nested_sdfg') - nsdfg.add_array('inner_A', (N,), dace.int32) - nguard = nsdfg.add_state('nested_guard', is_start_state=True) + nsdfg.add_array('inner_A', (N, ), dace.int32) + nguard = nsdfg.add_state('nested_guard', is_start_block=True) nbody = nsdfg.add_state('nested_body') nexit = nsdfg.add_state('nested_exit') nsdfg.add_edge(nguard, nbody, dace.InterstateEdge(condition='i <= N')) diff --git a/tests/passes/writeset_underapproximation_test.py b/tests/passes/writeset_underapproximation_test.py index a696c5ba24..ea860c6336 100644 --- a/tests/passes/writeset_underapproximation_test.py +++ b/tests/passes/writeset_underapproximation_test.py @@ -167,32 +167,23 @@ def test_map_tree_full_write(): map_entry, map_exit = map_state.add_map("outer_map", {"_i": '0:N:1'}) map_exit.add_in_connector("IN_B") map_exit.add_out_connector("OUT_B") - inner_map_entry_0, inner_map_exit_0 = map_state.add_map( - "inner_map_0", {"_j": '0:M:1'}) + inner_map_entry_0, inner_map_exit_0 = map_state.add_map("inner_map_0", {"_j": '0:M:1'}) inner_map_exit_0.add_in_connector("IN_B") inner_map_exit_0.add_out_connector("OUT_B") - inner_map_entry_1, inner_map_exit_1 = map_state.add_map( - "inner_map_1", {"_j": '0:M:1'}) + inner_map_entry_1, inner_map_exit_1 = map_state.add_map("inner_map_1", {"_j": '0:M:1'}) inner_map_exit_1.add_in_connector("IN_B") inner_map_exit_1.add_out_connector("OUT_B") map_tasklet_0 = map_state.add_tasklet("map_tasklet_0", {}, {"b"}, "b = 1") map_tasklet_1 = map_state.add_tasklet("map_tasklet_1", {}, {"b"}, "b = 2") map_state.add_edge(map_entry, None, inner_map_entry_0, None, dace.Memlet()) - map_state.add_edge(inner_map_entry_0, None, map_tasklet_0, None, - dace.Memlet()) - map_state.add_edge(map_tasklet_0, "b", inner_map_exit_0, "IN_B", - dace.Memlet("B[_j, _i]")) - inner_edge_0 = map_state.add_edge(inner_map_exit_0, "OUT_B", map_exit, - "IN_B", dace.Memlet(data="B")) + map_state.add_edge(inner_map_entry_0, None, map_tasklet_0, None, dace.Memlet()) + map_state.add_edge(map_tasklet_0, "b", inner_map_exit_0, "IN_B", dace.Memlet("B[_j, _i]")) + inner_edge_0 = map_state.add_edge(inner_map_exit_0, "OUT_B", map_exit, "IN_B", dace.Memlet(data="B")) map_state.add_edge(map_entry, None, inner_map_entry_1, None, dace.Memlet()) - map_state.add_edge(inner_map_entry_1, None, map_tasklet_1, None, - dace.Memlet()) - map_state.add_edge(map_tasklet_1, "b", inner_map_exit_1, "IN_B", - dace.Memlet("B[_j, _i]")) - inner_edge_1 = map_state.add_edge(inner_map_exit_1, "OUT_B", map_exit, - "IN_B", dace.Memlet(data="B")) - outer_edge = map_state.add_edge(map_exit, "OUT_B", a1, None, - dace.Memlet(data="B")) + map_state.add_edge(inner_map_entry_1, None, map_tasklet_1, None, dace.Memlet()) + map_state.add_edge(map_tasklet_1, "b", inner_map_exit_1, "IN_B", dace.Memlet("B[_j, _i]")) + inner_edge_1 = map_state.add_edge(inner_map_exit_1, "OUT_B", map_exit, "IN_B", dace.Memlet(data="B")) + outer_edge = map_state.add_edge(map_exit, "OUT_B", a1, None, dace.Memlet(data="B")) results = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__] @@ -221,32 +212,23 @@ def test_map_tree_no_write_multiple_indices(): map_entry, map_exit = map_state.add_map("outer_map", {"_i": '0:N:1'}) map_exit.add_in_connector("IN_B") map_exit.add_out_connector("OUT_B") - inner_map_entry_0, inner_map_exit_0 = map_state.add_map( - "inner_map_0", {"_j": '0:M:1'}) + inner_map_entry_0, inner_map_exit_0 = map_state.add_map("inner_map_0", {"_j": '0:M:1'}) inner_map_exit_0.add_in_connector("IN_B") inner_map_exit_0.add_out_connector("OUT_B") - inner_map_entry_1, inner_map_exit_1 = map_state.add_map( - "inner_map_1", {"_j": '0:M:1'}) + inner_map_entry_1, inner_map_exit_1 = map_state.add_map("inner_map_1", {"_j": '0:M:1'}) inner_map_exit_1.add_in_connector("IN_B") inner_map_exit_1.add_out_connector("OUT_B") map_tasklet_0 = map_state.add_tasklet("map_tasklet_0", {}, {"b"}, "b = 1") map_tasklet_1 = map_state.add_tasklet("map_tasklet_1", {}, {"b"}, "b = 2") map_state.add_edge(map_entry, None, inner_map_entry_0, None, dace.Memlet()) - map_state.add_edge(inner_map_entry_0, None, map_tasklet_0, None, - dace.Memlet()) - map_state.add_edge(map_tasklet_0, "b", inner_map_exit_0, "IN_B", - dace.Memlet("B[_j + _i, _i]")) - inner_edge_0 = map_state.add_edge(inner_map_exit_0, "OUT_B", map_exit, - "IN_B", dace.Memlet(data="B")) + map_state.add_edge(inner_map_entry_0, None, map_tasklet_0, None, dace.Memlet()) + map_state.add_edge(map_tasklet_0, "b", inner_map_exit_0, "IN_B", dace.Memlet("B[_j + _i, _i]")) + inner_edge_0 = map_state.add_edge(inner_map_exit_0, "OUT_B", map_exit, "IN_B", dace.Memlet(data="B")) map_state.add_edge(map_entry, None, inner_map_entry_1, None, dace.Memlet()) - map_state.add_edge(inner_map_entry_1, None, map_tasklet_1, None, - dace.Memlet()) - map_state.add_edge(map_tasklet_1, "b", inner_map_exit_1, "IN_B", - dace.Memlet("B[_j, _i + _j]")) - inner_edge_1 = map_state.add_edge(inner_map_exit_1, "OUT_B", map_exit, - "IN_B", dace.Memlet(data="B")) - outer_edge = map_state.add_edge(map_exit, "OUT_B", a1, None, - dace.Memlet(data="B")) + map_state.add_edge(inner_map_entry_1, None, map_tasklet_1, None, dace.Memlet()) + map_state.add_edge(map_tasklet_1, "b", inner_map_exit_1, "IN_B", dace.Memlet("B[_j, _i + _j]")) + inner_edge_1 = map_state.add_edge(inner_map_exit_1, "OUT_B", map_exit, "IN_B", dace.Memlet(data="B")) + outer_edge = map_state.add_edge(map_exit, "OUT_B", a1, None, dace.Memlet(data="B")) results = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__] @@ -273,32 +255,23 @@ def test_map_tree_multiple_indices_per_dimension(): map_entry, map_exit = map_state.add_map("outer_map", {"_i": '0:N:1'}) map_exit.add_in_connector("IN_B") map_exit.add_out_connector("OUT_B") - inner_map_entry_0, inner_map_exit_0 = map_state.add_map( - "inner_map_0", {"_j": '0:M:1'}) + inner_map_entry_0, inner_map_exit_0 = map_state.add_map("inner_map_0", {"_j": '0:M:1'}) inner_map_exit_0.add_in_connector("IN_B") inner_map_exit_0.add_out_connector("OUT_B") - inner_map_entry_1, inner_map_exit_1 = map_state.add_map( - "inner_map_1", {"_j": '0:M:1'}) + inner_map_entry_1, inner_map_exit_1 = map_state.add_map("inner_map_1", {"_j": '0:M:1'}) inner_map_exit_1.add_in_connector("IN_B") inner_map_exit_1.add_out_connector("OUT_B") map_tasklet_0 = map_state.add_tasklet("map_tasklet_0", {}, {"b"}, "b = 1") map_tasklet_1 = map_state.add_tasklet("map_tasklet_1", {}, {"b"}, "b = 2") map_state.add_edge(map_entry, None, inner_map_entry_0, None, dace.Memlet()) - map_state.add_edge(inner_map_entry_0, None, map_tasklet_0, None, - dace.Memlet()) - map_state.add_edge(map_tasklet_0, "b", inner_map_exit_0, "IN_B", - dace.Memlet("B[_j * _j, _i ]")) - inner_edge_0 = map_state.add_edge(inner_map_exit_0, "OUT_B", map_exit, - "IN_B", dace.Memlet(data="B")) + map_state.add_edge(inner_map_entry_0, None, map_tasklet_0, None, dace.Memlet()) + map_state.add_edge(map_tasklet_0, "b", inner_map_exit_0, "IN_B", dace.Memlet("B[_j * _j, _i ]")) + inner_edge_0 = map_state.add_edge(inner_map_exit_0, "OUT_B", map_exit, "IN_B", dace.Memlet(data="B")) map_state.add_edge(map_entry, None, inner_map_entry_1, None, dace.Memlet()) - map_state.add_edge(inner_map_entry_1, None, map_tasklet_1, None, - dace.Memlet()) - map_state.add_edge(map_tasklet_1, "b", inner_map_exit_1, "IN_B", - dace.Memlet("B[_j, _i]")) - inner_edge_1 = map_state.add_edge(inner_map_exit_1, "OUT_B", map_exit, - "IN_B", dace.Memlet(data="B")) - outer_edge = map_state.add_edge(map_exit, "OUT_B", a1, None, - dace.Memlet(data="B")) + map_state.add_edge(inner_map_entry_1, None, map_tasklet_1, None, dace.Memlet()) + map_state.add_edge(map_tasklet_1, "b", inner_map_exit_1, "IN_B", dace.Memlet("B[_j, _i]")) + inner_edge_1 = map_state.add_edge(inner_map_exit_1, "OUT_B", map_exit, "IN_B", dace.Memlet(data="B")) + outer_edge = map_state.add_edge(map_exit, "OUT_B", a1, None, dace.Memlet(data="B")) results = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__] @@ -388,8 +361,7 @@ def test_map_in_loop(): result = results["loop_approximation"] expected_subset = Range.from_string("0:N, 0:M") - assert (str( - result[guard]["B"].subset.subset_list[0]) == str(expected_subset)) + assert (str(result[guard]["B"].subset.subset_list[0]) == str(expected_subset)) def test_map_in_loop_multiplied_indices_first_dimension(): @@ -597,17 +569,14 @@ def test_simple_loop_overwrite(): init = sdfg.add_state("init") end = sdfg.add_state("end") loop_body = sdfg.add_state("loop_body") - _, guard, _ = sdfg.add_loop(init, loop_body, end, "i", "0", "i < N", - "i + 1") + _, guard, _ = sdfg.add_loop(init, loop_body, end, "i", "0", "i < N", "i + 1") a0 = loop_body.add_access("A") loop_tasklet = loop_body.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[i]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] - assert (str(result[guard]["A"].subset) == str( - Range.from_array(sdfg.arrays["A"]))) + assert (str(result[guard]["A"].subset) == str(Range.from_array(sdfg.arrays["A"]))) def test_loop_2D_overwrite(): @@ -623,19 +592,15 @@ def test_loop_2D_overwrite(): loop_body = sdfg.add_state("loop_body") loop_before_1 = sdfg.add_state("loop_before_1") loop_after_1 = sdfg.add_state("loop_after_1") - _, guard2, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", - "0", "i < N", "i + 1") - _, guard1, _ = sdfg.add_loop(init, loop_before_1, end, "j", "0", "j < M", - "j + 1", loop_after_1) + _, guard2, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", "0", "i < N", "i + 1") + _, guard1, _ = sdfg.add_loop(init, loop_before_1, end, "j", "0", "j < M", "j + 1", loop_after_1) a0 = loop_body.add_access("A") loop_tasklet = loop_body.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[j,i]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] - assert (str(result[guard1]["A"].subset) == str( - Range.from_array(sdfg.arrays["A"]))) + assert (str(result[guard1]["A"].subset) == str(Range.from_array(sdfg.arrays["A"]))) assert (str(result[guard2]["A"].subset) == "j, 0:N") @@ -656,19 +621,15 @@ def test_loop_2D_propagation_gap_symbolic(): loop_after_1 = sdfg.add_state("loop_after_1") loop_before_2 = sdfg.add_state("loop_before_2") loop_after_2 = sdfg.add_state("loop_after_2") - _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", - "0", "i < N", "i + 1") # inner-most loop - _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, - "k", "0", "k < K", "k + 1", + _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", "0", "i < N", "i + 1") # inner-most loop + _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, "k", "0", "k < K", "k + 1", loop_after_1) # second-inner-most loop - _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", - "j + 1", loop_after_2) # outer-most loop + _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", "j + 1", loop_after_2) # outer-most loop a0 = loop_body.add_access("A") loop_tasklet = loop_body.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[j,i]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] assert ("A" not in result[guard1].keys()) assert ("A" not in result[guard2].keys()) @@ -687,10 +648,8 @@ def test_2_loops_overwrite(): end = sdfg.add_state("end") loop_body_1 = sdfg.add_state("loop_body_1") loop_body_2 = sdfg.add_state("loop_body_2") - _, guard_1, after_state = sdfg.add_loop(init, loop_body_1, None, "i", "0", - "i < N", "i + 1") - _, guard_2, _ = sdfg.add_loop(after_state, loop_body_2, end, "i", "0", - "i < N", "i + 1") + _, guard_1, after_state = sdfg.add_loop(init, loop_body_1, None, "i", "0", "i < N", "i + 1") + _, guard_2, _ = sdfg.add_loop(after_state, loop_body_2, end, "i", "0", "i < N", "i + 1") a0 = loop_body_1.add_access("A") loop_tasklet_1 = loop_body_1.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body_1.add_edge(loop_tasklet_1, "a", a0, None, dace.Memlet("A[i]")) @@ -698,13 +657,10 @@ def test_2_loops_overwrite(): loop_tasklet_2 = loop_body_2.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body_2.add_edge(loop_tasklet_2, "a", a1, None, dace.Memlet("A[i]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] - assert (str(result[guard_1]["A"].subset) == str( - Range.from_array(sdfg.arrays["A"]))) - assert (str(result[guard_2]["A"].subset) == str( - Range.from_array(sdfg.arrays["A"]))) + assert (str(result[guard_1]["A"].subset) == str(Range.from_array(sdfg.arrays["A"]))) + assert (str(result[guard_2]["A"].subset) == str(Range.from_array(sdfg.arrays["A"]))) def test_loop_2D_overwrite_propagation_gap_non_empty(): @@ -724,21 +680,16 @@ def test_loop_2D_overwrite_propagation_gap_non_empty(): loop_after_1 = sdfg.add_state("loop_after_1") loop_before_2 = sdfg.add_state("loop_before_2") loop_after_2 = sdfg.add_state("loop_after_2") - _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", - "0", "i < N", "i + 1") - _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, - "k", "0", "k < 10", "k + 1", loop_after_1) - _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", - "j + 1", loop_after_2) + _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", "0", "i < N", "i + 1") + _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, "k", "0", "k < 10", "k + 1", loop_after_1) + _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", "j + 1", loop_after_2) a0 = loop_body.add_access("A") loop_tasklet = loop_body.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[j,i]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] - assert (str(result[guard1]["A"].subset) == str( - Range.from_array(sdfg.arrays["A"]))) + assert (str(result[guard1]["A"].subset) == str(Range.from_array(sdfg.arrays["A"]))) assert (str(result[guard2]["A"].subset) == "j, 0:N") assert (str(result[guard3]["A"].subset) == "j, 0:N") @@ -759,23 +710,18 @@ def test_loop_nest_multiplied_indices(): loop_after_1 = sdfg.add_state("loop_after_1") loop_before_2 = sdfg.add_state("loop_before_2") loop_after_2 = sdfg.add_state("loop_after_2") - _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", - "0", "i < N", "i + 1") - _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, - "k", "0", "k < 10", "k + 1", loop_after_1) - _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", - "j + 1", loop_after_2) + _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", "0", "i < N", "i + 1") + _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, "k", "0", "k < 10", "k + 1", loop_after_1) + _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", "j + 1", loop_after_2) a0 = loop_body.add_access("A") loop_tasklet = loop_body.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[i,i*j]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] assert (guard1 not in result.keys() or "A" not in result[guard1].keys()) assert (guard2 not in result.keys() or "A" not in result[guard2].keys()) - assert (guard3 not in result.keys() or "A" not in result[guard3].keys() - or not result[guard3]['A'].subset) + assert (guard3 not in result.keys() or "A" not in result[guard3].keys() or not result[guard3]['A'].subset) def test_loop_nest_empty_nested_loop(): @@ -795,18 +741,14 @@ def test_loop_nest_empty_nested_loop(): loop_after_1 = sdfg.add_state("loop_after_1") loop_before_2 = sdfg.add_state("loop_before_2") loop_after_2 = sdfg.add_state("loop_after_2") - _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", - "0", "i < N", "i + 1") - _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, - "k", "0", "k < 0", "k + 1", loop_after_1) - _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", - "j + 1", loop_after_2) + _, guard3, _ = sdfg.add_loop(loop_before_1, loop_body, loop_after_1, "i", "0", "i < N", "i + 1") + _, guard2, _ = sdfg.add_loop(loop_before_2, loop_before_1, loop_after_2, "k", "0", "k < 0", "k + 1", loop_after_1) + _, guard1, _ = sdfg.add_loop(init, loop_before_2, end, "j", "0", "j < M", "j + 1", loop_after_2) a0 = loop_body.add_access("A") loop_tasklet = loop_body.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[j,i]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] assert (guard1 not in result.keys() or "A" not in result[guard1].keys()) assert (guard2 not in result.keys() or "A" not in result[guard2].keys()) @@ -828,25 +770,19 @@ def test_loop_nest_inner_loop_conditional(): if_merge = sdfg.add_state("if_merge") loop_before_2 = sdfg.add_state("loop_before_2") loop_after_2 = sdfg.add_state("loop_after_2") - _, guard2, _ = sdfg.add_loop(loop_before_2, loop_body, loop_after_2, "k", - "0", "k < N", "k + 1") - _, guard1, _ = sdfg.add_loop(init, if_guard, end, "j", "0", "j < M", - "j + 1", if_merge) - sdfg.add_edge(if_guard, loop_before_2, - dace.InterstateEdge(condition="j % 2 == 0")) - sdfg.add_edge(if_guard, if_merge, - dace.InterstateEdge(condition="j % 2 == 1")) + _, guard2, _ = sdfg.add_loop(loop_before_2, loop_body, loop_after_2, "k", "0", "k < N", "k + 1") + _, guard1, _ = sdfg.add_loop(init, if_guard, end, "j", "0", "j < M", "j + 1", if_merge) + sdfg.add_edge(if_guard, loop_before_2, dace.InterstateEdge(condition="j % 2 == 0")) + sdfg.add_edge(if_guard, if_merge, dace.InterstateEdge(condition="j % 2 == 1")) sdfg.add_edge(loop_after_2, if_merge, dace.InterstateEdge()) a0 = loop_body.add_access("A") loop_tasklet = loop_body.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[k]")) - result = pipeline.apply_pass( - sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] + result = pipeline.apply_pass(sdfg, {})[UnderapproximateWrites.__name__]["loop_approximation"] assert (guard1 not in result.keys() or "A" not in result[guard1].keys()) - assert (guard2 in result.keys() and "A" in result[guard2].keys() - and str(result[guard2]['A'].subset) == "0:N") + assert (guard2 in result.keys() and "A" in result[guard2].keys() and str(result[guard2]['A'].subset) == "0:N") def test_loop_in_nested_sdfg_in_map_multiplied_indices(): @@ -917,16 +853,13 @@ def test_loop_break(): sdfg = dace.SDFG("loop_2D_no_overwrite") sdfg.add_array("A", [N], dace.int64) - init = sdfg.add_state("init", is_start_state=True) + init = sdfg.add_state("init", is_start_block=True) loop_body_0 = sdfg.add_state("loop_body_0") loop_body_1 = sdfg.add_state("loop_body_1") loop_after_1 = sdfg.add_state("loop_after_1") - _, guard3, _ = sdfg.add_loop(init, loop_body_0, loop_after_1, "i", "0", - "i < N", "i + 1", loop_body_1) - sdfg.add_edge(loop_body_0, loop_after_1, - dace.InterstateEdge(condition="i > 10")) - sdfg.add_edge(loop_body_0, loop_body_1, - dace.InterstateEdge(condition="not(i > 10)")) + _, guard3, _ = sdfg.add_loop(init, loop_body_0, loop_after_1, "i", "0", "i < N", "i + 1", loop_body_1) + sdfg.add_edge(loop_body_0, loop_after_1, dace.InterstateEdge(condition="i > 10")) + sdfg.add_edge(loop_body_0, loop_body_1, dace.InterstateEdge(condition="not(i > 10)")) a0 = loop_body_1.add_access("A") loop_tasklet = loop_body_1.add_tasklet("overwrite", {}, {"a"}, "a = 0") loop_body_1.add_edge(loop_tasklet, "a", a0, None, dace.Memlet("A[i]")) @@ -950,10 +883,9 @@ def test_constant_multiplicative_2D(): memlet = dace.Memlet(None, "A", subset) memlets = [memlet] - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - memlets, A, ["j"], j_subset, None, True) - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - [propagated_memlet], A, ["i"], i_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets(memlets, A, ["j"], j_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets([propagated_memlet], A, ["i"], i_subset, + None, True) propagated_subset = propagated_memlet.subset.subset_list[0] expected_subset = Range.from_string("0:N:1, 0:3*M - 2:3") @@ -975,10 +907,9 @@ def test_affine_2D(): memlet = dace.Memlet(None, "A", subset) memlets = [memlet] - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - memlets, A, ["j"], j_subset, None, True) - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - [propagated_memlet], A, ["i"], i_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets(memlets, A, ["j"], j_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets([propagated_memlet], A, ["i"], i_subset, + None, True) propagated_subset = propagated_memlet.subset.subset_list[0] expected_subset = Range.from_string("0:N:1, 3 : 3 * M + 1 : 3") @@ -1000,10 +931,9 @@ def test_multiplied_variables(): memlet = dace.Memlet(None, "A", subset) memlets = [memlet] - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - memlets, A, ["j"], j_subset, None, True) - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - [propagated_memlet], A, ["i"], i_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets(memlets, A, ["j"], j_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets([propagated_memlet], A, ["i"], i_subset, + None, True) assert (not propagated_memlet.subset.subset_list) @@ -1021,10 +951,9 @@ def test_one_variable_in_2dimensions(): memlet = dace.Memlet(None, "A", subset) memlets = [memlet] - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - memlets, A, ["j"], j_subset, None, True) - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - [propagated_memlet], A, ["i"], i_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets(memlets, A, ["j"], j_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets([propagated_memlet], A, ["i"], i_subset, + None, True) assert (not propagated_memlet.subset.subset_list) @@ -1037,10 +966,9 @@ def test_negative_step(): memlet = dace.Memlet(None, "A", subset) memlets = [memlet] - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - memlets, A, ["j"], j_subset, None, True) - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - [propagated_memlet], A, ["i"], i_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets(memlets, A, ["j"], j_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets([propagated_memlet], A, ["i"], i_subset, + None, True) propagated_subset = propagated_memlet.subset.subset_list[0] expected_subset = Range.from_string("0:N:1,M:0:-1") @@ -1062,8 +990,7 @@ def test_step_not_one(): memlet = dace.Memlet(None, "A", subset) memlets = [memlet] - propagated_memlet = UnderapproximateWrites()._underapproximate_subsets( - memlets, A, ["i"], i_subset, None, True) + propagated_memlet = UnderapproximateWrites()._underapproximate_subsets(memlets, A, ["i"], i_subset, None, True) propagated_subset = propagated_memlet.subset.subset_list[0] expected_subset = Range.from_string("0:N:3") diff --git a/tests/polybench/2mm.py b/tests/polybench/2mm.py index 8e64383601..8d7404ba47 100644 --- a/tests/polybench/2mm.py +++ b/tests/polybench/2mm.py @@ -46,12 +46,7 @@ ([1], datatype)] -def init_array(A, B, C, D, alpha, beta): - ni = NI.get() - nj = NJ.get() - nk = NK.get() - nl = NL.get() - +def init_array(A, B, C, D, alpha, beta, ni, nj, nk, nl): alpha[0] = datatype(1.5) beta[0] = datatype(1.2) @@ -106,6 +101,5 @@ def comp_d(i: _[0:NI], j: _[0:NL], k: _[0:NJ]): if polybench: polybench.main(sizes, args, [(3, 'D')], init_array, k2mm) else: - [k.set(v) for k, v in sizes[2].items()] - init_array(*args) + init_array(*args, **{str(k).lower(): v for k, v in sizes[2].items()}) k2mm(*args) diff --git a/tests/polybench/3mm.py b/tests/polybench/3mm.py index d1d3509be7..db9db0bf95 100644 --- a/tests/polybench/3mm.py +++ b/tests/polybench/3mm.py @@ -52,13 +52,7 @@ args = [([NI, NK], datatype), ([NK, NJ], datatype), ([NJ, NM], datatype), ([NM, NL], datatype), ([NI, NL], datatype)] -def init_array(A, B, C, D, G): - ni = NI.get() - nj = NJ.get() - nk = NK.get() - nl = NL.get() - nm = NM.get() - +def init_array(A, B, C, D, G, ni, nj, nk, nl, nm): for i in range(ni): for j in range(nk): A[i, j] = datatype((i * j + 1) % ni) / (5 * ni) @@ -104,6 +98,5 @@ def mult_G(i: _[0:NI], j: _[0:NL], k: _[0:NJ]): if polybench: polybench.main(sizes, args, [(4, 'G')], init_array, k3mm) else: - [k.set(v) for k, v in sizes[2].items()] - init_array(*args) + init_array(*args, **{str(k).lower(): v for k, v in sizes[2].items()}) k3mm(*args) diff --git a/tests/polybench/adi.py b/tests/polybench/adi.py index fe5e66aaca..86623f954e 100644 --- a/tests/polybench/adi.py +++ b/tests/polybench/adi.py @@ -29,8 +29,7 @@ args = [([N, N], datatype)] -def init_array(u): - n = N.get() +def init_array(u, tsteps, n): for i in range(n): for j in range(n): u[i, j] = datatype(i + n - j) / n diff --git a/tests/polybench/atax.py b/tests/polybench/atax.py index 77ec31da05..875b83999c 100644 --- a/tests/polybench/atax.py +++ b/tests/polybench/atax.py @@ -30,9 +30,7 @@ args = [([M, N], datatype), ([N], datatype), ([N], datatype)] -def init_array(A, x, y): - n = N.get() - m = M.get() +def init_array(A, x, y, n, m): fn = datatype(n) for i in range(n): diff --git a/tests/polybench/bicg.py b/tests/polybench/bicg.py index 0f746d7a9c..26a4cd9bba 100644 --- a/tests/polybench/bicg.py +++ b/tests/polybench/bicg.py @@ -30,10 +30,7 @@ args = [([N, M], datatype), ([M], datatype), ([N], datatype), ([M], datatype), ([N], datatype)] -def init_array(A, s, q, p, r): - n = N.get() - m = M.get() - +def init_array(A, s, q, p, r, n, m): for i in range(m): p[i] = datatype(i % m) / m for i in range(n): diff --git a/tests/polybench/cholesky.py b/tests/polybench/cholesky.py index 67c880bed8..56d90e7d31 100644 --- a/tests/polybench/cholesky.py +++ b/tests/polybench/cholesky.py @@ -15,9 +15,7 @@ args = [([N, N], datatype)] -def init_array(A): - n = N.get() - +def init_array(A, n): for i in range(0, n, 1): for j in range(0, i + 1, 1): # Python does modulo, while C does remainder ... @@ -61,11 +59,11 @@ def sqrt(): out = math.sqrt(inp) -def print_result(filename, *args): +def print_result(filename, *args, n=None, **kwargs): with open(filename, 'w') as fp: fp.write("==BEGIN DUMP_ARRAYS==\n") fp.write("begin dump: %s\n" % 'A') - for i in range(0, N.get()): + for i in range(0, n): for j in range(0, i + 1): fp.write("{:.7f} ".format(args[0][i, j])) fp.write("\n") diff --git a/tests/polybench/correlation.py b/tests/polybench/correlation.py index c5ccc476ff..ed13d3e5b1 100644 --- a/tests/polybench/correlation.py +++ b/tests/polybench/correlation.py @@ -15,9 +15,7 @@ args = [([N, M], datatype), ([M, M], datatype), ([M], datatype), ([M], datatype)] -def init_array(data, corr, mean, stddev): - n = N.get() - m = M.get() +def init_array(data, corr, mean, stddev, n, m): for i in range(n): for j in range(m): data[i, j] = datatype(i * j) / m + i diff --git a/tests/polybench/covariance.py b/tests/polybench/covariance.py index db68a0651d..567de5a284 100644 --- a/tests/polybench/covariance.py +++ b/tests/polybench/covariance.py @@ -14,9 +14,7 @@ args = [([N, M], datatype), ([M, M], datatype), ([M], datatype)] -def init_array(data, cov, mean): - n = N.get() - m = M.get() +def init_array(data, cov, mean, n, m): for i in range(n): for j in range(m): data[i, j] = datatype(i * j) / m diff --git a/tests/polybench/deriche.py b/tests/polybench/deriche.py index b277a3ada1..8dd18e24e7 100644 --- a/tests/polybench/deriche.py +++ b/tests/polybench/deriche.py @@ -45,10 +45,7 @@ c1 = c2 = 1 -def init_array(imgIn, imgOut): - w = W.get() - h = H.get() - +def init_array(imgIn, imgOut, w, h): for i in range(w): for j in range(h): imgIn[i, j] = datatype((313 * i + 991 * j) % 65536) / 65535.0 diff --git a/tests/polybench/doitgen.py b/tests/polybench/doitgen.py index ed12afdae8..5cd81705fc 100644 --- a/tests/polybench/doitgen.py +++ b/tests/polybench/doitgen.py @@ -36,11 +36,7 @@ args = [([NR, NQ, NP], datatype), ([NP, NP], datatype)] -def init_array(A, C4): - nr = NR.get() - nq = NQ.get() - np = NP.get() - +def init_array(A, C4, nr, nq, np): for i in range(nr): for j in range(nq): for k in range(np): diff --git a/tests/polybench/durbin.py b/tests/polybench/durbin.py index a3cdb42975..a6c5d5c2cd 100644 --- a/tests/polybench/durbin.py +++ b/tests/polybench/durbin.py @@ -14,9 +14,7 @@ args = [([N], datatype), ([N], datatype)] -def init_array(r, y): - n = N.get() - +def init_array(r, y, n): for i in range(0, n): r[i] = datatype(n + 1 - i) diff --git a/tests/polybench/fdtd-2d.py b/tests/polybench/fdtd-2d.py index fd4256a208..b0ee9de6a4 100644 --- a/tests/polybench/fdtd-2d.py +++ b/tests/polybench/fdtd-2d.py @@ -42,10 +42,7 @@ ] -def init_array(ex, ey, hz, _fict_): #, NX, NY, TMAX): - nx = NX.get() - ny = NY.get() - tmax = TMAX.get() +def init_array(ex, ey, hz, _fict_, nx, ny, tmax): for i in range(tmax): _fict_[i] = datatype(i) for i in range(nx): @@ -57,7 +54,7 @@ def init_array(ex, ey, hz, _fict_): #, NX, NY, TMAX): @dace.program(datatype[NX, NY], datatype[NX, NY], datatype[NX, NY], datatype[TMAX]) #, dace.int32, dace.int32, dace.int32) -def fdtd2d(ex, ey, hz, _fict_): #, NX, NY, TMAX): +def fdtd2d(ex, ey, hz, _fict_): for t in range(TMAX): @dace.map diff --git a/tests/polybench/floyd-warshall.py b/tests/polybench/floyd-warshall.py index 00b3e7caec..536e7c9cba 100644 --- a/tests/polybench/floyd-warshall.py +++ b/tests/polybench/floyd-warshall.py @@ -17,9 +17,7 @@ args = [([N, N], datatype)] -def init_array(path): - n = N.get() - +def init_array(path, n): for i in range(n): for j in range(n): path[i, j] = datatype(i * j % 7 + 1) @@ -43,6 +41,5 @@ def ij_map(i: _[0:N], j: _[0:N]): if polybench: polybench.main(sizes, args, [(0, 'path')], init_array, floyd_warshall) else: - [k.set(v) for k, v in sizes[2].items()] - init_array(*args) + init_array(*args, **{str(k).lower(): v for k, v in sizes[2].items()}) floyd_warshall(*args) diff --git a/tests/polybench/gemm.py b/tests/polybench/gemm.py index 8c7f257ab1..cc5a18a6ef 100644 --- a/tests/polybench/gemm.py +++ b/tests/polybench/gemm.py @@ -39,11 +39,7 @@ args = [([NI, NJ], datatype), ([NI, NK], datatype), ([NK, NJ], datatype), ([1], datatype), ([1], datatype)] -def init_array(C, A, B, alpha, beta): - ni = NI.get() - nj = NJ.get() - nk = NK.get() - +def init_array(C, A, B, alpha, beta, ni, nj, nk): alpha[0] = datatype(1.5) beta[0] = datatype(1.2) @@ -81,6 +77,5 @@ def comp(i: _[0:NI], k: _[0:NK], j: _[0:NJ]): if polybench: polybench.main(sizes, args, [(0, 'C')], init_array, gemm) else: - [k.set(v) for k, v in sizes[2].items()] - init_array(*args) + init_array(*args, **{str(k).lower(): v for k, v in sizes[2].items()}) gemm(*args) diff --git a/tests/polybench/gemver.py b/tests/polybench/gemver.py index 117271088b..a39951cb02 100644 --- a/tests/polybench/gemver.py +++ b/tests/polybench/gemver.py @@ -17,9 +17,7 @@ outputs = [(5, 'w')] -def init_array(A, u1, v1, u2, v2, w, x, y, z, alpha, beta): - n = N.get() - +def init_array(A, u1, v1, u2, v2, w, x, y, z, alpha, beta, n): alpha[0] = datatype(1.5) beta[0] = datatype(1.2) diff --git a/tests/polybench/gesummv.py b/tests/polybench/gesummv.py index 791c1bf0b8..a2836b676d 100644 --- a/tests/polybench/gesummv.py +++ b/tests/polybench/gesummv.py @@ -17,9 +17,7 @@ outputs = [(4, 'y')] -def init_array(A, B, tmp, x, y, alpha, beta): - n = N.get() - +def init_array(A, B, tmp, x, y, alpha, beta, n): alpha[0] = datatype(1.5) beta[0] = datatype(1.2) diff --git a/tests/polybench/gramschmidt.py b/tests/polybench/gramschmidt.py index 2519288e51..a46cfaf317 100644 --- a/tests/polybench/gramschmidt.py +++ b/tests/polybench/gramschmidt.py @@ -16,10 +16,7 @@ args = [([M, N], datatype), ([N, N], datatype), ([M, N], datatype)] -def init_array(A, R, Q): - m = M.get() - n = N.get() - +def init_array(A, R, Q, m, n): for i in range(0, m, 1): for j in range(0, n, 1): A[i, j] = ((datatype((i * j) % m) / m) * 100) + 10 diff --git a/tests/polybench/heat-3d.py b/tests/polybench/heat-3d.py index 1f1ed9251e..6b3aad06ec 100644 --- a/tests/polybench/heat-3d.py +++ b/tests/polybench/heat-3d.py @@ -53,8 +53,7 @@ def a(i: _[1:N - 1], j: _[1:N - 1], k: _[1:N - 1]): a -def init_array(A, B): #, N, tsteps): - n = N.get() +def init_array(A, B, n, tsteps): for i in range(n): for j in range(n): for k in range(n): diff --git a/tests/polybench/jacobi-1d.py b/tests/polybench/jacobi-1d.py index e92cb34135..27029e695f 100644 --- a/tests/polybench/jacobi-1d.py +++ b/tests/polybench/jacobi-1d.py @@ -50,8 +50,7 @@ def b(i: _[1:N - 1]): b = 0.33333 * (a1 + a2 + a3) -def init_array(A, B): #, N, tsteps): - n = N.get() +def init_array(A, B, n, tsteps): for i in range(n): A[i] = datatype(i + 2) / n B[i] = datatype(i + 3) / n diff --git a/tests/polybench/jacobi-2d.py b/tests/polybench/jacobi-2d.py index d4e2a9ae45..e2f171f56d 100644 --- a/tests/polybench/jacobi-2d.py +++ b/tests/polybench/jacobi-2d.py @@ -61,8 +61,7 @@ def b(i: _[1:N - 1], j: _[1:N - 1]): b = 0.2 * (a1 + a2 + a3 + a4 + a5) -def init_array(A, B): #, N, tsteps): - n = N.get() +def init_array(A, B, n, tsteps): for i in range(n): for j in range(n): A[i, j] = datatype(i * (j + 2) + 2) / n @@ -73,6 +72,5 @@ def init_array(A, B): #, N, tsteps): if polybench: polybench.main(sizes, args, [(0, 'A')], init_array, jacobi2d) else: - [k.set(v) for k, v in sizes[2].items()] - init_array(*args) + init_array(*args, **{str(k).lower(): v for k, v in sizes[2].items()}) jacobi2d(*args) diff --git a/tests/polybench/lu.py b/tests/polybench/lu.py index f706de71de..5c4cd7f6c5 100644 --- a/tests/polybench/lu.py +++ b/tests/polybench/lu.py @@ -15,9 +15,7 @@ args = [([N, N], datatype)] -def init_array(A): - n = N.get() - +def init_array(A, n): for i in range(0, n, 1): for j in range(0, i + 1, 1): # Python does modulo, while C does remainder ... diff --git a/tests/polybench/ludcmp.py b/tests/polybench/ludcmp.py index 614313b319..6cad67437d 100644 --- a/tests/polybench/ludcmp.py +++ b/tests/polybench/ludcmp.py @@ -15,9 +15,7 @@ args = [([N, N], datatype), ([N], datatype), ([N], datatype), ([N], datatype)] -def init_array(A, b, x, y): - n = N.get() - +def init_array(A, b, x, y, n): x[:] = datatype(0) y[:] = datatype(0) diff --git a/tests/polybench/mvt.py b/tests/polybench/mvt.py index f2b4754d56..c197d0bdce 100644 --- a/tests/polybench/mvt.py +++ b/tests/polybench/mvt.py @@ -24,9 +24,7 @@ args = [([N], datatype), ([N], datatype), ([N], datatype), ([N], datatype), ([N, N], datatype)] -def init_array(x1, x2, y_1, y_2, A): - n = N.get() - +def init_array(x1, x2, y_1, y_2, A, n): for i in range(n): x1[i] = datatype(i % n) / n x2[i] = datatype((i + 1) % n) / n diff --git a/tests/polybench/nussinov.py b/tests/polybench/nussinov.py index e3e430a6e6..5f045e9467 100644 --- a/tests/polybench/nussinov.py +++ b/tests/polybench/nussinov.py @@ -15,9 +15,7 @@ args = [([N], datatype), ([N, N], datatype)] -def init_array(seq, table): - n = N.get() - +def init_array(seq, table, n): for i in range(0, n): seq[i] = datatype((i + 1) % 4) table[:] = datatype(0) @@ -76,12 +74,12 @@ def set_table_5(): out = max(center, k_center + k_south) -def print_result(filename, *args): +def print_result(filename, *args, n=None, **kwargs): with open(filename, 'w') as fp: fp.write("==BEGIN DUMP_ARRAYS==\n") fp.write("begin dump: %s\n" % 'table') - for i in range(0, N.get()): - for j in range(i, N.get()): + for i in range(0, n): + for j in range(i, n): fp.write("{} ".format(args[1][i, j])) fp.write("\n") fp.write("\nend dump: %s\n" % 'table') diff --git a/tests/polybench/polybench.py b/tests/polybench/polybench.py index 296b5854f9..f20b127d44 100644 --- a/tests/polybench/polybench.py +++ b/tests/polybench/polybench.py @@ -35,14 +35,15 @@ def _main(sizes, args, output_args, init_array, func, argv, keywords=None): # Initialize symbols with values from dataset size psize = sizes[_SIZE_TO_IND[FLAGS.size]] - for k, v in psize.items(): - k.set(v) psize = {str(k): v for k, v in psize.items()} + psize_lowercase = {k.lower(): v for k, v in psize.items()} # Construct arrays from tuple arguments for i, arg in enumerate(args): if isinstance(arg, tuple): - args[i] = dace.ndarray(*arg) + shape, dtype = arg + shape = [psize[str(s)] if isinstance(s, dace.symbol) else s for s in shape] + args[i] = dace.ndarray(shape, dtype) if FLAGS.simulate == False: if isinstance(func, dace.SDFG): @@ -60,7 +61,7 @@ def _main(sizes, args, output_args, init_array, func, argv, keywords=None): if FLAGS.compile == False: print('Initializing arrays...') - init_array(*args) + init_array(*args, **psize_lowercase) print('Running %skernel...' % ('specialized ' if FLAGS.specialize else '')) if FLAGS.simulate: @@ -73,7 +74,7 @@ def _main(sizes, args, output_args, init_array, func, argv, keywords=None): if FLAGS.save: if not isinstance(output_args, list): - output_args(func.name + '.dace.out', *args) + output_args(func.name + '.dace.out', *args, **psize_lowercase) else: polybench_dump(func.name + '.dace.out', args, output_args) diff --git a/tests/polybench/seidel-2d.py b/tests/polybench/seidel-2d.py index 02b78c7331..d6b07b98a8 100644 --- a/tests/polybench/seidel-2d.py +++ b/tests/polybench/seidel-2d.py @@ -51,8 +51,7 @@ def a(): out = (a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9) / datatype(9.0) -def init_array(A): - n = N.get() +def init_array(A, tsteps, n): for i in range(n): for j in range(n): A[i, j] = datatype(i * (j + 2) + 2) / n diff --git a/tests/polybench/symm.py b/tests/polybench/symm.py index fcc9d7bf1e..8fbe49758b 100644 --- a/tests/polybench/symm.py +++ b/tests/polybench/symm.py @@ -17,10 +17,7 @@ outputs = [(0, 'C')] -def init_array(C, A, B, alpha, beta): - n = N.get() - m = M.get() - +def init_array(C, A, B, alpha, beta, n, m): alpha[0] = datatype(1.5) beta[0] = datatype(1.2) @@ -35,8 +32,6 @@ def init_array(C, A, B, alpha, beta): A[i, j] = -999 # regions of arrays that should not be used - print('aval', beta[0] * C[0, 0] + alpha[0] * B[0, 0] * A[0, 0]) - @dace.program(datatype[M, N], datatype[M, M], datatype[M, N], datatype[1], datatype[1]) def symm(C, A, B, alpha, beta): diff --git a/tests/polybench/syr2k.py b/tests/polybench/syr2k.py index 6657cab467..0e7b92aa60 100644 --- a/tests/polybench/syr2k.py +++ b/tests/polybench/syr2k.py @@ -17,10 +17,7 @@ outputs = [(0, 'C')] -def init_array(C, A, B, alpha, beta): - n = N.get() - m = M.get() - +def init_array(C, A, B, alpha, beta, n, m): alpha[0] = datatype(1.5) beta[0] = datatype(1.2) diff --git a/tests/polybench/syrk.py b/tests/polybench/syrk.py index c5de0a44cd..ae22a603d2 100644 --- a/tests/polybench/syrk.py +++ b/tests/polybench/syrk.py @@ -17,10 +17,7 @@ outputs = [(0, 'C')] -def init_array(C, A, alpha, beta): - n = N.get() - m = M.get() - +def init_array(C, A, alpha, beta, n, m): alpha[0] = datatype(1.5) beta[0] = datatype(1.2) diff --git a/tests/polybench/trisolv.py b/tests/polybench/trisolv.py index aa985598f3..279be0b3a6 100644 --- a/tests/polybench/trisolv.py +++ b/tests/polybench/trisolv.py @@ -15,9 +15,7 @@ args = [([N, N], datatype), ([N], datatype), ([N], datatype)] -def init_array(L, x, b): - n = N.get() - +def init_array(L, x, b, n): x[:] = datatype(-999) for i in range(0, n, 1): b[i] = datatype(i) diff --git a/tests/polybench/trmm.py b/tests/polybench/trmm.py index 1a65478fd7..2626829ad4 100644 --- a/tests/polybench/trmm.py +++ b/tests/polybench/trmm.py @@ -21,10 +21,7 @@ outputs = [(1, 'B')] -def init_array(A, B, alpha): - n = N.get() - m = M.get() - +def init_array(A, B, alpha, n, m): alpha[0] = datatype(1.5) for i in range(m): diff --git a/tests/python_frontend/augassign_wcr_test.py b/tests/python_frontend/augassign_wcr_test.py index d460f7d0e7..2345b5a2aa 100644 --- a/tests/python_frontend/augassign_wcr_test.py +++ b/tests/python_frontend/augassign_wcr_test.py @@ -1,6 +1,7 @@ # Copyright 2019-2021 ETH Zurich and the DaCe authors. All rights reserved. import dace import numpy as np +import pytest @dace.program @@ -155,6 +156,7 @@ def no_wcr(A: dace.int32[5, 5, 5]): assert (np.allclose(A, ref)) +@pytest.mark.skip def test_augassign_wcr4(): with dace.config.set_temporary('frontend', 'avoid_wcr', value=False): diff --git a/tests/python_frontend/binop_replacements_test.py b/tests/python_frontend/binop_replacements_test.py index b74baf4277..c5286b0b6b 100644 --- a/tests/python_frontend/binop_replacements_test.py +++ b/tests/python_frontend/binop_replacements_test.py @@ -4,10 +4,7 @@ import pytest N = dace.symbol('N') -N.set(10) M = dace.symbol('M') -M.set(5) - @dace.program def array_array(A: dace.int32[N], B: dace.int32[N]): @@ -15,8 +12,8 @@ def array_array(A: dace.int32[N], B: dace.int32[N]): def test_array_array(): - A = np.random.randint(10, size=(N.get(), ), dtype=np.int32) - B = np.random.randint(10, size=(N.get(), ), dtype=np.int32) + A = np.random.randint(10, size=(10, ), dtype=np.int32) + B = np.random.randint(10, size=(10, ), dtype=np.int32) C = array_array(A, B) assert (np.array_equal(A + B, C)) @@ -27,7 +24,7 @@ def array_array1(A: dace.int32[N], B: dace.int32[1]): def test_array_array1(): - A = np.random.randint(10, size=(N.get(), ), dtype=np.int32) + A = np.random.randint(10, size=(10, ), dtype=np.int32) B = np.random.randint(10, size=(1, ), dtype=np.int32) C = array_array1(A, B) assert (np.array_equal(A + B, C)) @@ -40,7 +37,7 @@ def array1_array(A: dace.int32[1], B: dace.int32[N]): def test_array1_array(): A = np.random.randint(10, size=(1, ), dtype=np.int32) - B = np.random.randint(10, size=(N.get(), ), dtype=np.int32) + B = np.random.randint(10, size=(10, ), dtype=np.int32) C = array1_array(A, B) assert (np.array_equal(A + B, C)) @@ -63,7 +60,7 @@ def array_scalar(A: dace.int32[N], B: dace.int32): def test_array_scalar(): - A = np.random.randint(10, size=(N.get(), ), dtype=np.int32) + A = np.random.randint(10, size=(10, ), dtype=np.int32) B = np.random.randint(10, size=(1, ), dtype=np.int32)[0] C = array_scalar(A, B) assert (np.array_equal(A + B, C)) @@ -76,7 +73,7 @@ def scalar_array(A: dace.int32, B: dace.int32[N]): def test_scalar_array(): A = np.random.randint(10, size=(1, ), dtype=np.int32)[0] - B = np.random.randint(10, size=(N.get(), ), dtype=np.int32) + B = np.random.randint(10, size=(10, ), dtype=np.int32) C = scalar_array(A, B) assert (np.array_equal(A + B, C)) @@ -87,7 +84,7 @@ def array_num(A: dace.int64[N]): def test_array_num(): - A = np.random.randint(10, size=(N.get(), ), dtype=np.int64) + A = np.random.randint(10, size=(10, ), dtype=np.int64) B = array_num(A) assert (np.array_equal(A + 5, B)) @@ -98,7 +95,7 @@ def num_array(A: dace.int64[N]): def test_num_array(): - A = np.random.randint(10, size=(N.get(), ), dtype=np.int64) + A = np.random.randint(10, size=(10, ), dtype=np.int64) B = array_num(A) assert (np.array_equal(5 + A, B)) @@ -109,7 +106,7 @@ def array_bool(A: dace.bool[N]): def test_array_bool(): - A = np.random.randint(0, high=2, size=(N.get(), ), dtype=bool) + A = np.random.randint(0, high=2, size=(10, ), dtype=bool) B = array_bool(A) assert (np.array_equal(np.logical_and(A, True), B)) @@ -120,7 +117,7 @@ def bool_array(A: dace.bool[N]): def test_bool_array(): - A = np.random.randint(0, high=2, size=(N.get(), ), dtype=bool) + A = np.random.randint(0, high=2, size=(10, ), dtype=bool) B = bool_array(A) assert (np.array_equal(np.logical_and(True, A), B)) @@ -131,9 +128,9 @@ def array_sym(A: dace.int64[N]): def test_array_sym(): - A = np.random.randint(0, high=2, size=(N.get(), ), dtype=np.int64) + A = np.random.randint(0, high=2, size=(10, ), dtype=np.int64) B = array_sym(A) - assert (np.array_equal(A + N.get(), B)) + assert (np.array_equal(A + 10, B)) @dace.program @@ -142,9 +139,9 @@ def sym_array(A: dace.int64[N]): def test_sym_array(): - A = np.random.randint(0, high=2, size=(N.get(), ), dtype=np.int64) + A = np.random.randint(0, high=2, size=(10, ), dtype=np.int64) B = sym_array(A) - assert (np.array_equal(N.get() + A, B)) + assert (np.array_equal(10 + A, B)) @dace.program @@ -153,9 +150,9 @@ def array_symexpr(A: dace.int64[N]): def test_array_symexpr(): - A = np.random.randint(0, high=2, size=(N.get(), ), dtype=np.int64) + A = np.random.randint(0, high=2, size=(10, ), dtype=np.int64) B = array_symexpr(A) - assert (np.array_equal(A + (N.get() + 1), B)) + assert (np.array_equal(A + (10 + 1), B)) @dace.program @@ -164,9 +161,9 @@ def symexpr_array(A: dace.int64[N]): def test_symexpr_array(): - A = np.random.randint(0, high=2, size=(N.get(), ), dtype=np.int64) + A = np.random.randint(0, high=2, size=(10, ), dtype=np.int64) B = symexpr_array(A) - assert (np.array_equal((N.get() + 1) + A, B)) + assert (np.array_equal((10 + 1) + A, B)) @dace.program @@ -232,9 +229,9 @@ def scal_sym(A: dace.int64, tmp: dace.int64[N]): def test_scal_sym(): A = np.random.randint(0, high=2, size=(1, ), dtype=np.int64)[0] - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) B = scal_sym(A, tmp) - assert (np.array_equal(A + N.get(), B[0])) + assert (np.array_equal(A + 10, B[0])) @dace.program @@ -244,9 +241,9 @@ def sym_scal(A: dace.int64, tmp: dace.int64[N]): def test_sym_scal(): A = np.random.randint(0, high=2, size=(1, ), dtype=np.int64)[0] - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) B = sym_scal(A, tmp) - assert (np.array_equal(N.get() + A, B[0])) + assert (np.array_equal(10 + A, B[0])) @dace.program @@ -256,9 +253,9 @@ def scal_symexpr(A: dace.int64, tmp: dace.int64[N]): def test_scal_symexpr(): A = np.random.randint(0, high=2, size=(1, ), dtype=np.int64)[0] - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) B = scal_symexpr(A, tmp) - assert (np.array_equal(A + (N.get() + 1), B[0])) + assert (np.array_equal(A + (10 + 1), B[0])) @dace.program @@ -268,9 +265,9 @@ def symexpr_scal(A: dace.int64, tmp: dace.int64[N]): def test_symexpr_scal(): A = np.random.randint(0, high=2, size=(1, ), dtype=np.int64)[0] - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) B = symexpr_scal(A, tmp) - assert (np.array_equal((N.get() + 1) + A, B[0])) + assert (np.array_equal((10 + 1) + A, B[0])) @dace.program @@ -289,9 +286,9 @@ def num_sym(tmp: dace.int64[N]): def test_num_sym(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = num_sym(tmp) - assert (A[0] == 5 + N.get()) + assert (A[0] == 5 + 10) @dace.program @@ -300,9 +297,9 @@ def sym_num(tmp: dace.int64[N]): def test_sym_num(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = sym_num(tmp) - assert (A[0] == N.get() + 5) + assert (A[0] == 10 + 5) @dace.program @@ -311,9 +308,9 @@ def num_symexpr(tmp: dace.int64[N]): def test_num_symexpr(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = num_symexpr(tmp) - assert (A[0] == 5 + (N.get() + 1)) + assert (A[0] == 5 + (10 + 1)) @dace.program @@ -322,9 +319,9 @@ def symexpr_num(tmp: dace.int64[N]): def test_symexpr_num(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = symexpr_num(tmp) - assert (A[0] == (N.get() + 1) + 5) + assert (A[0] == (10 + 1) + 5) @dace.program @@ -343,9 +340,9 @@ def bool_sym(tmp: dace.int64[N]): def test_bool_sym(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = bool_sym(tmp) - assert (A[0] == False or N.get()) + assert (A[0] == False or 10) @dace.program @@ -354,9 +351,9 @@ def sym_bool(tmp: dace.int64[N]): def test_sym_bool(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = sym_bool(tmp) - assert (A[0] == N.get() or False) + assert (A[0] == 10 or False) @dace.program @@ -365,9 +362,9 @@ def bool_symexpr(tmp: dace.int64[N]): def test_bool_symexpr(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = bool_symexpr(tmp) - assert (A[0] == False or (N.get() + 1)) + assert (A[0] == False or (10 + 1)) @dace.program @@ -376,9 +373,9 @@ def symexpr_bool(tmp: dace.int64[N]): def test_symexpr_bool(): - tmp = np.zeros((N.get(), ), dtype=np.int64) + tmp = np.zeros((10, ), dtype=np.int64) A = symexpr_bool(tmp) - assert (A[0] == (N.get() + 1) or False) + assert (A[0] == (10 + 1) or False) @dace.program @@ -387,9 +384,9 @@ def sym_sym(tmp: dace.int64[M, N]): def test_sym_sym(): - tmp = np.zeros((M.get(), N.get()), dtype=np.int64) + tmp = np.zeros((5, 10), dtype=np.int64) A = sym_sym(tmp) - assert (A[0] == M.get() + N.get()) + assert (A[0] == 5 + 10) @dace.program @@ -398,10 +395,10 @@ def mixed(A: dace.int64[M, N], B: dace.int64): def test_mixed(): - A = np.random.randint(10, size=(M.get(), N.get()), dtype=np.int64) + A = np.random.randint(10, size=(5, 10), dtype=np.int64) B = np.random.randint(10, size=(1, ), dtype=np.int64)[0] C = mixed(A, B) - ref = 5j + M.get() + A[0, 0] + 32 + A[0, 1] + B + 2 + M.get() + N.get() + ref = 5j + 5 + A[0, 0] + 32 + A[0, 1] + B + 2 + 5 + 10 assert (C[0] == ref) diff --git a/tests/python_frontend/callback_autodetect_test.py b/tests/python_frontend/callback_autodetect_test.py index 19fb50b3ff..fe567f18ad 100644 --- a/tests/python_frontend/callback_autodetect_test.py +++ b/tests/python_frontend/callback_autodetect_test.py @@ -142,7 +142,6 @@ def modcallback(A: dace.float64[N, N], B: dace.float64[N]): def test_callback_from_module(): - N.set(24) A = np.random.rand(24, 24) B = np.random.rand(24) modcallback(A, B) diff --git a/tests/python_frontend/identifiers_and_keywords_test.py b/tests/python_frontend/identifiers_and_keywords_test.py index 897eb48aa8..ac6e299fd9 100644 --- a/tests/python_frontend/identifiers_and_keywords_test.py +++ b/tests/python_frontend/identifiers_and_keywords_test.py @@ -12,9 +12,9 @@ def keyword_false(A: dace.float32[N], B: dace.float32[N], C: dace.bool): def test_keyword_false(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) C = False try: keyword_false(A, B, C) @@ -31,9 +31,9 @@ def keyword_none(A: dace.float32[N], B: dace.float32[N], C: dace.pointer(dace.in def test_keyword_none(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) C = None try: keyword_none(A, B, C) @@ -50,9 +50,9 @@ def keyword_true(A: dace.float32[N], B: dace.float32[N], C: dace.bool): def test_keyword_true(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) C = True try: keyword_true(A, B, C) @@ -69,9 +69,9 @@ def keyword_and(A: dace.float32[N], B: dace.float32[N], C: dace.bool, D: dace.bo def test_keyword_and(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) C = True D = True try: @@ -94,9 +94,9 @@ def keyword_assert(A: dace.float32[N], B: dace.float32[N], C: dace.bool, D: dace def test_keyword_assert(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) C = True D = True try: @@ -118,9 +118,9 @@ def keyword_ifelse(A: dace.float32[N], B: dace.float32[N], C: dace.int32): def test_keyword_ifelse(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) C = np.int32(2) try: keyword_ifelse(A, B, C) @@ -137,9 +137,9 @@ def keyword_for(A: dace.float32[N], B: dace.float32[N]): def test_keyword_for(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) try: keyword_for(A, B) except Exception as e: @@ -162,9 +162,9 @@ def keyword_while(A: dace.float32[N], B: dace.float32[N]): def test_keyword_while(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) try: keyword_while(A, B) except Exception as e: @@ -189,9 +189,9 @@ def keyword_return(A: dace.float32[N]): def test_keyword_return(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) try: B[:] = keyword_return(A) except Exception as e: @@ -207,9 +207,9 @@ def keyword_notor(A: dace.float32[N], B: dace.float32[N], C: dace.bool, D: dace. def test_keyword_notor(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) C = False D = True try: @@ -228,9 +228,9 @@ def keyword_lambda(A: dace.float32[N], B: dace.float32[N]): def test_keyword_lambda(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) try: keyword_lambda(A, B) except Exception as e: diff --git a/tests/python_frontend/line_structure_test.py b/tests/python_frontend/line_structure_test.py index f5811ff71e..bbdc6629e9 100644 --- a/tests/python_frontend/line_structure_test.py +++ b/tests/python_frontend/line_structure_test.py @@ -14,9 +14,9 @@ def comments(A: dace.float32[N], B: dace.float32[N]): def test_comments(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(),), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N,), dtype=np.float32) comments(A, B) assert np.allclose(A, B) @@ -29,9 +29,9 @@ def explicit_line_joining(A: dace.float32[N], B: dace.float32[N]): def test_explicit_line_joining(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(),), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N,), dtype=np.float32) explicit_line_joining(A, B) assert np.allclose(A, B) @@ -48,9 +48,9 @@ def implicit_line_joining(A: dace.float32[N], B: dace.float32[N]): def test_implicit_line_joining(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(),), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N,), dtype=np.float32) implicit_line_joining(A, B) assert np.allclose(A, B) @@ -77,9 +77,9 @@ def blank_lines(A: dace.float32[N], B: dace.float32[N]): def test_blank_lines(): - N.set(128) - A = np.random.rand(N.get()).astype(np.float32) - B = np.zeros((N.get(), ), dtype=np.float32) + N = 128 + A = np.random.rand(N).astype(np.float32) + B = np.zeros((N, ), dtype=np.float32) blank_lines(A, B) assert np.allclose(A, B) diff --git a/tests/python_frontend/nested_name_accesses_test.py b/tests/python_frontend/nested_name_accesses_test.py index 14ded42960..1e5b18b840 100644 --- a/tests/python_frontend/nested_name_accesses_test.py +++ b/tests/python_frontend/nested_name_accesses_test.py @@ -15,13 +15,13 @@ def nested_name_accesses(a: dc.float32, x: dc.float32[N, N, N], w: dc.float32[N, def test_nested_name_accesses(): - N.set(10) + N = 10 a = np.random.rand(1).astype(np.float32)[0] - x = np.random.rand(N.get(), N.get(), N.get()).astype(np.float32) - w = np.random.rand(N.get(), N.get()).astype(np.float32) + x = np.random.rand(N, N, N).astype(np.float32) + w = np.random.rand(N, N).astype(np.float32) dc_out = nested_name_accesses(a, x, w) np_out = np.empty(x.shape, x.dtype) - for i in range(N.get()): + for i in range(N): np_out[i] = a * x[i] @ w diff_norm = np.linalg.norm(dc_out - np_out) ref_norm = np.linalg.norm(np_out) diff --git a/tests/read_after_write_test.py b/tests/read_after_write_test.py index 5425fea5cf..563ec34587 100644 --- a/tests/read_after_write_test.py +++ b/tests/read_after_write_test.py @@ -29,17 +29,17 @@ def compute_output(i): def test(): - W.set(3) + W = 3 A = dp.ndarray([W]) B = dp.ndarray([W]) - A[:] = np.mgrid[0:W.get()] + A[:] = np.mgrid[0:W] B[:] = dp.float32(0.0) raw_prog(A, B, W=W) - diff = np.linalg.norm(4 * A - B) / W.get() + diff = np.linalg.norm(4 * A - B) / W print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/rtl/hardware_test.py b/tests/rtl/hardware_test.py index 727dc7362b..b6c01fab93 100644 --- a/tests/rtl/hardware_test.py +++ b/tests/rtl/hardware_test.py @@ -192,7 +192,7 @@ def make_vadd_sdfg(N: dace.symbol, veclen: int = 8): return sdfg -def make_vadd_multi_sdfg(N, M): +def make_vadd_multi_sdfg(N, M, n, m): ''' Function for constructing an SDFG that adds a constant (42) to a an array `A` of `N` elements into a vector `B`. Each instance of an adder is within its own Processing Element (PE), along with a reader and writer to/from global memory. @@ -203,7 +203,7 @@ def make_vadd_multi_sdfg(N, M): :return: An SDFG that has arguments `A` and `B`. ''' # add sdfg - sdfg = dace.SDFG(f'integer_vector_plus_42_multiple_kernels_{N.get() // M.get()}') + sdfg = dace.SDFG(f'integer_vector_plus_42_multiple_kernels_{n // m}') # add state state = sdfg.add_state('device_state') @@ -216,12 +216,12 @@ def make_vadd_multi_sdfg(N, M): # add streams sdfg.add_stream('A_stream', - shape=(int(N.get() / M.get()), ), + shape=(int(n / m), ), dtype=dace.int32, transient=True, storage=dace.StorageType.FPGA_Local) sdfg.add_stream('B_stream', - shape=(int(N.get() / M.get()), ), + shape=(int(n / m), ), dtype=dace.int32, transient=True, storage=dace.StorageType.FPGA_Local) @@ -329,18 +329,18 @@ def test_hardware_vadd(): # add symbol N = dace.symbol('N') - N.set(32) + n = 32 veclen = 4 sdfg = make_vadd_sdfg(N, veclen) - a = np.random.randint(0, 100, N.get()).astype(np.float32) + a = np.random.randint(0, 100, n).astype(np.float32) b = np.random.randint(1, 100, 1)[0].astype(np.float32) - c = np.zeros((N.get(), )).astype(np.float32) + c = np.zeros((n, )).astype(np.float32) # call program sdfg(A=a, B=b, C=c, N=N) expected = a + b - diff = np.linalg.norm(expected - c) / N.get() + diff = np.linalg.norm(expected - c) / n assert diff <= 1e-5 return sdfg @@ -355,18 +355,18 @@ def test_hardware_add42_single(): M = dace.symbol('M') # init data structures - N.set(32) # elements - M.set(32) # elements per kernel - a = np.random.randint(0, 100, N.get()).astype(np.int32) - b = np.zeros((N.get(), )).astype(np.int32) - sdfg = make_vadd_multi_sdfg(N, M) - sdfg.specialize(dict(N=N, M=M)) + n = 32 # elements + m = 32 # elements per kernel + a = np.random.randint(0, 100, n).astype(np.int32) + b = np.zeros((n, )).astype(np.int32) + sdfg = make_vadd_multi_sdfg(N, M, n, m) + sdfg.specialize(dict(N=n, M=m)) # call program sdfg(A=a, B=b) # check result - for i in range(N.get()): + for i in range(n): assert b[i] == a[i] + 42 return sdfg @@ -389,11 +389,11 @@ def test_hardware_axpy_double_pump(veclen=2): # init data structures N = dace.symbol('N') - N.set(32) + n = 32 a = np.random.rand(1)[0].astype(np.float32) - x = np.random.rand(N.get()).astype(np.float32) - y = np.random.rand(N.get()).astype(np.float32) - result = np.zeros((N.get(), )).astype(np.float32) + x = np.random.rand(n).astype(np.float32) + y = np.random.rand(n).astype(np.float32) + result = np.zeros((n, )).astype(np.float32) # Build the SDFG sdfg = axpy.make_sdfg(veclen) @@ -403,7 +403,7 @@ def test_hardware_axpy_double_pump(veclen=2): # check result expected = a * x + y - diff = np.linalg.norm(expected - result) / N.get() + diff = np.linalg.norm(expected - result) / n assert diff <= 1e-5 @@ -441,10 +441,10 @@ def test_hardware_vadd_temporal_vectorization(): size_n = 1024 veclen = 4 N = dace.symbol('N') - N.set(size_n) - x = np.random.rand(N.get()).astype(np.float32) - y = np.random.rand(N.get()).astype(np.float32) - result = np.zeros(N.get(), dtype=np.float32) + n = size_n + x = np.random.rand(n).astype(np.float32) + y = np.random.rand(n).astype(np.float32) + result = np.zeros(n, dtype=np.float32) expected = x + y # Generate the initial SDFG @@ -486,7 +486,7 @@ def np_vadd(x: dace.float32[N], y: dace.float32[N]): [TemporalVectorization.apply_to(sdfg, sg) for i, sg in enumerate(sgs) if cba[i]] # Run the program and verify the results - sdfg.specialize({'N': N.get()}) + sdfg.specialize({'N': n}) sdfg(x=x, y=y, __return=result) assert (np.allclose(expected, result)) @@ -500,18 +500,18 @@ def np_vadd(x: dace.float32[N], y: dace.float32[N]): # M = dace.symbol('M') # # # init data structures -# N.set(32) # elements -# M.set(8) # elements per kernel -# a = np.random.randint(0, 100, N.get()).astype(np.int32) -# b = np.zeros((N.get(), )).astype(np.int32) -# sdfg = make_vadd_multi_sdfg(N, M) +# n = 32 # elements +# n = 8 # elements per kernel +# a = np.random.randint(0, 100, n).astype(np.int32) +# b = np.zeros((n, )).astype(np.int32) +# sdfg = make_vadd_multi_sdfg(N, M, n, m) # sdfg.specialize(dict(N=N, M=M)) # # # call program # sdfg(A=a, B=b) # # # check result -# for i in range(N.get()): +# for i in range(n): # assert b[i] == a[i] + 42 # # return sdfg diff --git a/tests/rtl/simulation_test.py b/tests/rtl/simulation_test.py index 6b7ac2cd15..d9fcf90eff 100644 --- a/tests/rtl/simulation_test.py +++ b/tests/rtl/simulation_test.py @@ -15,7 +15,6 @@ def test_tasklet_array(): n = 128 N = dace.symbol('N') - N.set(n) # add sdfg sdfg = dace.SDFG('rtl_tasklet_array') @@ -59,12 +58,12 @@ def test_tasklet_array(): state.add_edge(tasklet, 'b', B, None, dace.Memlet('B[0:N]')) # validate sdfg - sdfg.specialize({'N': N.get()}) + sdfg.specialize({'N': n}) sdfg.validate() # init data structures - a = np.random.randint(0, 100, N.get()).astype(np.int32) - b = np.zeros((N.get(), )).astype(np.int32) + a = np.random.randint(0, 100, n).astype(np.int32) + b = np.zeros((n, )).astype(np.int32) # call program sdfg(A=a, B=b) @@ -583,9 +582,6 @@ def test_tasklet_map(): N = dace.symbol('N') M = dace.symbol('M') W = dace.symbol('W') - N.set(n) - M.set(m) - W.set(w) # add sdfg sdfg = dace.SDFG('rtl_tasklet_map') @@ -594,9 +590,9 @@ def test_tasklet_map(): state = sdfg.add_state() # add arrays - sdfg.add_array('A', [M, N], dtype=dace.vector(dace.int32, W.get())) - sdfg.add_array('B', [M, N], dtype=dace.vector(dace.int32, W.get())) - sdfg.add_array('C', [M, N], dtype=dace.vector(dace.int32, W.get())) + sdfg.add_array('A', [M, N], dtype=dace.vector(dace.int32, w)) + sdfg.add_array('B', [M, N], dtype=dace.vector(dace.int32, w)) + sdfg.add_array('C', [M, N], dtype=dace.vector(dace.int32, w)) mentry, mexit = state.add_map('compute_map', {'k': '0:M'}) @@ -674,7 +670,7 @@ def test_tasklet_map(): state.add_memlet_path(B, mentry, tasklet, memlet=dace.Memlet('B[k,0:N]'), dst_conn='b') state.add_memlet_path(tasklet, mexit, C, memlet=dace.Memlet('C[k,0:N]'), src_conn='c') - sdfg.specialize({'M': M, 'N': N, 'W': W}) + sdfg.specialize({'M': m, 'N': n, 'W': w}) sdfg.validate() # init data structures diff --git a/tests/sdfg_validate_names_test.py b/tests/sdfg_validate_names_test.py index 1650a4e4b1..ac9f633496 100644 --- a/tests/sdfg_validate_names_test.py +++ b/tests/sdfg_validate_names_test.py @@ -100,7 +100,7 @@ def test_connector(self): def test_interstate_edge(self): try: sdfg = dace.SDFG('ok') - state = sdfg.add_state('also_ok', is_start_state=True) + state = sdfg.add_state('also_ok', is_start_block=True) A = state.add_array('A', [1], dace.float32) B = state.add_array('B', [1], dace.float32) t = state.add_tasklet('tasklet', {'a'}, {'b'}, 'b = a') diff --git a/tests/specialize_test.py b/tests/specialize_test.py index 3b18bbc02c..b9e91bb5df 100644 --- a/tests/specialize_test.py +++ b/tests/specialize_test.py @@ -12,14 +12,14 @@ def test(): N = dp.symbol('N') M = dp.symbol('M') - N.set(20) - M.set(30) + n = 20 + m = 30 fullrange = '1:N-1,0:M' irange = '1:N-1' jrange = '0:M' - input = np.random.rand(N.get(), M.get()).astype(np.float32) - output = dp.ndarray([N, M], dtype=dp.float32) + input = np.random.rand(n, m).astype(np.float32) + output = dp.ndarray([n, m], dtype=dp.float32) output[:] = dp.float32(0) ########################################################################## @@ -44,15 +44,15 @@ def test(): assert 'Dynamic' in code_nonspec[0].code - spec_sdfg.specialize(dict(N=N, M=M)) + spec_sdfg.specialize(dict(N=n, M=m)) code_spec = spec_sdfg.generate_code() assert 'Dynamic' not in code_spec[0].code func = spec_sdfg.compile() - func(A=input, B=output, N=N, M=M) + func(A=input, B=output, N=n, M=m) - diff = np.linalg.norm(np.exp(input[1:(N.get() - 1), 0:M.get()]) - output[1:-1, :]) / N.get() + diff = np.linalg.norm(np.exp(input[1:(n - 1), 0:m]) - output[1:-1, :]) / n print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/subarray_test.py b/tests/subarray_test.py index 5c513c3773..a0614a382a 100644 --- a/tests/subarray_test.py +++ b/tests/subarray_test.py @@ -16,13 +16,13 @@ def subarrays(i): def test(): - W.set(3) + W = 3 A = dp.ndarray([W, W, W, W]) B = dp.ndarray([W, W, W, W]) - A[:] = np.mgrid[0:W.get(), 0:W.get(), 0:W.get()] - for i in range(W.get()): + A[:] = np.mgrid[0:W, 0:W, 0:W] + for i in range(W): A[i, :] += 10 * (i + 1) B[:] = dp.float32(0.0) diff --git a/tests/symbol_dependent_transients_test.py b/tests/symbol_dependent_transients_test.py index 8033b6b196..2c7ca94c6f 100644 --- a/tests/symbol_dependent_transients_test.py +++ b/tests/symbol_dependent_transients_test.py @@ -20,7 +20,7 @@ def _make_sdfg(name, storage=dace.dtypes.StorageType.CPU_Heap, isview=False): _, tmp1 = sdfg.add_transient('tmp1', [N - 4, N - 4, N - i], dtype=dace.float64, storage=storage) _, tmp2 = sdfg.add_transient('tmp2', [1], dtype=dace.float64, storage=storage) - begin_state = sdfg.add_state("begin", is_start_state=True) + begin_state = sdfg.add_state("begin", is_start_block=True) guard_state = sdfg.add_state("guard") body1_state = sdfg.add_state("body1") body2_state = sdfg.add_state("body2") @@ -190,6 +190,7 @@ def test_symbol_dependent_fpga_global_array(): def test_symbol_dependent_array_in_map(): + @dace.program def symbol_dependent_array_in_map(A: dace.float32[10]): out = np.ndarray(10, dtype=np.float32) diff --git a/tests/threadlocal_stream_test.py b/tests/threadlocal_stream_test.py index bbcdc57caa..ebefb9d04e 100644 --- a/tests/threadlocal_stream_test.py +++ b/tests/threadlocal_stream_test.py @@ -31,9 +31,9 @@ def test(): print('Thread-local stream test') - N.set(20) + N = 20 - output = np.ndarray([N.get()], dtype=np.float32) + output = np.ndarray([N], dtype=np.float32) output[:] = dp.float32(0) code_nonspec = sdfg.generate_code() @@ -45,7 +45,7 @@ def test(): output = np.sort(output) - diff = np.linalg.norm(output - np.arange(0, N.get(), dtype=np.float32)) + diff = np.linalg.norm(output - np.arange(0, N, dtype=np.float32)) print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/tile_test.py b/tests/tile_test.py index f43b801879..3a7223952e 100644 --- a/tests/tile_test.py +++ b/tests/tile_test.py @@ -25,21 +25,21 @@ def transpose_tiled(A: dace.float32[H, W], B: dace.float32[H, W]): def test(): - W.set(128) - H.set(128) - TW.set(16) - TH.set(16) + W = 128 + H = 128 + TW = 16 + TH = 16 - print('Transpose (Tiled) %dx%d (tile size: %dx%d)' % (W.get(), H.get(), TW.get(), TH.get())) + print('Transpose (Tiled) %dx%d (tile size: %dx%d)' % (W, H, TW, TH)) A = dace.ndarray([H, W], dtype=dace.float32) B = dace.ndarray([H, W], dtype=dace.float32) - A[:] = np.random.rand(H.get(), W.get()).astype(dace.float32.type) + A[:] = np.random.rand(H, W).astype(dace.float32.type) B[:] = dace.float32(0) transpose_tiled(A, B, TW=TW, TH=TH) - diff = np.linalg.norm(np.transpose(A) - B) / (H.get() * W.get()) + diff = np.linalg.norm(np.transpose(A) - B) / (H * W) print("Difference:", diff) assert diff <= 1e-5 diff --git a/tests/tiling_test.py b/tests/tiling_test.py index ea561d9fe7..89f40e5d82 100644 --- a/tests/tiling_test.py +++ b/tests/tiling_test.py @@ -67,19 +67,19 @@ def create_sdfg(): def test(): - W.set(1024) - H.set(1024) - MAXITER.set(30) + W = 1024 + H = 1024 + MAXITER = 30 - print('Jacobi 5-point Stencil %dx%d (%d steps)' % (W.get(), H.get(), MAXITER.get())) + print('Jacobi 5-point Stencil %dx%d (%d steps)' % (W, H, MAXITER)) - A = np.ndarray((H.get(), W.get()), dtype=np.float32) + A = np.ndarray((H, W), dtype=np.float32) # Initialize arrays: Randomize A, zero B A[:] = dace.float32(0) - A[1:H.get() - 1, 1:W.get() - 1] = np.random.rand((H.get() - 2), (W.get() - 2)).astype(dace.float32.type) - regression = np.ndarray([H.get() - 2, W.get() - 2], dtype=np.float32) - regression[:] = A[1:H.get() - 1, 1:W.get() - 1] + A[1:H - 1, 1:W - 1] = np.random.rand((H - 2), (W - 2)).astype(dace.float32.type) + regression = np.ndarray([H - 2, W - 2], dtype=np.float32) + regression[:] = A[1:H - 1, 1:W - 1] #print(A.view(type=np.ndarray)) @@ -93,14 +93,14 @@ def test(): if (isinstance(node, dace.sdfg.nodes.MapEntry) and node.label[:-2] == 'stencil'): assert len(body.in_edges(node)) <= 1 - sdfg(A=A, H=H.get(), W=W.get(), MAXITER=MAXITER.get()) + sdfg(A=A, H=H, W=W, MAXITER=MAXITER) # Regression kernel = np.array([[0, 0.2, 0], [0.2, 0.2, 0.2], [0, 0.2, 0]], dtype=np.float32) - for i in range(2 * MAXITER.get()): + for i in range(2 * MAXITER): regression = ndimage.convolve(regression, kernel, mode='constant', cval=0.0) - residual = np.linalg.norm(A[1:H.get() - 1, 1:W.get() - 1] - regression) / (H.get() * W.get()) + residual = np.linalg.norm(A[1:H - 1, 1:W - 1] - regression) / (H * W) print("Residual:", residual) assert residual <= 0.05 diff --git a/tests/transformations/loop_to_map_test.py b/tests/transformations/loop_to_map_test.py index 13abe83434..7c556362e4 100644 --- a/tests/transformations/loop_to_map_test.py +++ b/tests/transformations/loop_to_map_test.py @@ -266,7 +266,7 @@ def test_interstate_dep(): sdfg = dace.SDFG('intestate_dep') sdfg.add_array('A', (10, ), dtype=np.int32) - init = sdfg.add_state('init', is_start_state=True) + init = sdfg.add_state('init', is_start_block=True) guard = sdfg.add_state('guard') body0 = sdfg.add_state('body0') body1 = sdfg.add_state('body1') @@ -392,7 +392,7 @@ def tester(data: dace.int32[20]): def test_symbol_write_before_read(): sdfg = dace.SDFG('tester') - init = sdfg.add_state(is_start_state=True) + init = sdfg.add_state(is_start_block=True) body_start = sdfg.add_state() body = sdfg.add_state() body_end = sdfg.add_state() @@ -410,7 +410,7 @@ def test_symbol_array_mix(overwrite): sdfg = dace.SDFG('tester') sdfg.add_transient('tmp', [1], dace.float64) sdfg.add_symbol('sym', dace.float64) - init = sdfg.add_state(is_start_state=True) + init = sdfg.add_state(is_start_block=True) body_start = sdfg.add_state() body = sdfg.add_state() body_end = sdfg.add_state() @@ -438,7 +438,7 @@ def test_symbol_array_mix_2(parallel): sdfg.add_array('A', [20], dace.float64) sdfg.add_array('B', [20], dace.float64) sdfg.add_symbol('sym', dace.float64) - init = sdfg.add_state(is_start_state=True) + init = sdfg.add_state(is_start_block=True) body_start = sdfg.add_state() body_end = sdfg.add_state() after = sdfg.add_state() @@ -461,7 +461,7 @@ def test_symbol_array_mix_2(parallel): @pytest.mark.parametrize('overwrite', (False, True)) def test_internal_symbol_used_outside(overwrite): sdfg = dace.SDFG('tester') - init = sdfg.add_state(is_start_state=True) + init = sdfg.add_state(is_start_block=True) body_start = sdfg.add_state() body = sdfg.add_state() body_end = sdfg.add_state() @@ -490,7 +490,7 @@ def test_shared_local_transient_single_state(): """ sdfg = dace.SDFG('shared_local_transient_single_state') - begin = sdfg.add_state('begin', is_start_state=True) + begin = sdfg.add_state('begin', is_start_block=True) guard = sdfg.add_state('guard') body = sdfg.add_state('body') end = sdfg.add_state('end') @@ -525,7 +525,7 @@ def test_thread_local_transient_single_state(): """ sdfg = dace.SDFG('thread_local_transient_single_state') - begin = sdfg.add_state('begin', is_start_state=True) + begin = sdfg.add_state('begin', is_start_block=True) guard = sdfg.add_state('guard') body = sdfg.add_state('body') end = sdfg.add_state('end') @@ -563,7 +563,7 @@ def test_shared_local_transient_multi_state(): """ sdfg = dace.SDFG('shared_local_transient_multi_state') - begin = sdfg.add_state('begin', is_start_state=True) + begin = sdfg.add_state('begin', is_start_block=True) guard = sdfg.add_state('guard') body0 = sdfg.add_state('body0') body1 = sdfg.add_state('body1') @@ -601,7 +601,7 @@ def test_thread_local_transient_multi_state(): """ sdfg = dace.SDFG('thread_local_transient_multi_state') - begin = sdfg.add_state('begin', is_start_state=True) + begin = sdfg.add_state('begin', is_start_block=True) guard = sdfg.add_state('guard') body0 = sdfg.add_state('body0') body1 = sdfg.add_state('body1') diff --git a/tests/transformations/mapfission_test.py b/tests/transformations/mapfission_test.py index 609c075c21..6cd52bec00 100644 --- a/tests/transformations/mapfission_test.py +++ b/tests/transformations/mapfission_test.py @@ -271,14 +271,14 @@ def test_mapfission_with_symbols(): sdfg.add_array('A', (M, N), dace.int32) sdfg.add_array('B', (M, N), dace.int32) - state = sdfg.add_state('parent', is_start_state=True) + state = sdfg.add_state('parent', is_start_block=True) me, mx = state.add_map('parent_map', {'i': '0:N'}) nsdfg = dace.SDFG('nested_sdfg') nsdfg.add_scalar('inner_A', dace.int32) nsdfg.add_scalar('inner_B', dace.int32) - nstate = nsdfg.add_state('child', is_start_state=True) + nstate = nsdfg.add_state('child', is_start_block=True) na = nstate.add_access('inner_A') nb = nstate.add_access('inner_B') ta = nstate.add_tasklet('tasklet_A', {}, {'__out'}, '__out = M') @@ -319,14 +319,14 @@ def test_two_edges_through_map(): sdfg.add_array('A', (N, ), dace.int32) sdfg.add_array('B', (N, ), dace.int32) - state = sdfg.add_state('parent', is_start_state=True) + state = sdfg.add_state('parent', is_start_block=True) me, mx = state.add_map('parent_map', {'i': '0:N'}) nsdfg = dace.SDFG('nested_sdfg') nsdfg.add_array('inner_A', (N, ), dace.int32) nsdfg.add_scalar('inner_B', dace.int32) - nstate = nsdfg.add_state('child', is_start_state=True) + nstate = nsdfg.add_state('child', is_start_block=True) na = nstate.add_access('inner_A') nb = nstate.add_access('inner_B') t = nstate.add_tasklet('tasklet', {'__in1', '__in2'}, {'__out'}, '__out = __in1 + __in2') @@ -460,7 +460,7 @@ def test_single_data_multiple_connectors(): inner_sdfg.add_array('B0', (10, ), dtype=dace.int32) inner_sdfg.add_array('B1', (10, ), dtype=dace.int32) - inner_state = inner_sdfg.add_state('inner_state', is_start_state=True) + inner_state = inner_sdfg.add_state('inner_state', is_start_block=True) inner_state.add_mapped_tasklet(name='plus', map_ranges={'j': '0:10'}, @@ -481,7 +481,7 @@ def test_single_data_multiple_connectors(): code='__b1 = __a0 - __a1', external_edges=True) - outer_state = outer_sdfg.add_state('outer_state', is_start_state=True) + outer_state = outer_sdfg.add_state('outer_state', is_start_block=True) a = outer_state.add_access('A') b = outer_state.add_access('B') @@ -529,7 +529,7 @@ def test_dependent_symbol(): inner_sdfg.add_array('B0', (10, ), dtype=dace.int32) inner_sdfg.add_array('B1', (10, ), dtype=dace.int32) - inner_state = inner_sdfg.add_state('inner_state', is_start_state=True) + inner_state = inner_sdfg.add_state('inner_state', is_start_block=True) inner_state.add_mapped_tasklet(name='plus', map_ranges={'j': 'first:last'}, @@ -550,7 +550,7 @@ def test_dependent_symbol(): inner_sdfg2.add_array('A1', (10, ), dtype=dace.int32) inner_sdfg2.add_array('B1', (10, ), dtype=dace.int32) - inner_state2 = inner_sdfg2.add_state('inner_state2', is_start_state=True) + inner_state2 = inner_sdfg2.add_state('inner_state2', is_start_block=True) inner_state2.add_mapped_tasklet(name='minus', map_ranges={'j': 'first:last'}, @@ -571,7 +571,7 @@ def test_dependent_symbol(): inner_state.add_edge(a1, None, nsdfg, 'A1', dace.Memlet(data='A1', subset='0:10')) inner_state.add_edge(nsdfg, 'B1', b1, None, dace.Memlet(data='B1', subset='0:10')) - outer_state = outer_sdfg.add_state('outer_state', is_start_state=True) + outer_state = outer_sdfg.add_state('outer_state', is_start_block=True) a = outer_state.add_access('A') b = outer_state.add_access('B') diff --git a/tests/transformations/move_assignment_outside_if_test.py b/tests/transformations/move_assignment_outside_if_test.py index 323e83cf61..270fd8f842 100644 --- a/tests/transformations/move_assignment_outside_if_test.py +++ b/tests/transformations/move_assignment_outside_if_test.py @@ -10,20 +10,26 @@ def one_variable_simple_test(const_value: int = 0): """ Test with one variable which has formula and const branch. Uses the given const value """ sdfg = dace.SDFG('one_variable_simple_test') # Create guard state and one state where A is set to 0 and another where it is set using B and some formula - guard = sdfg.add_state('guard', is_start_state=True) - formula_state = sdfg.add_state('formula', is_start_state=False) - const_state = sdfg.add_state('const', is_start_state=False) + guard = sdfg.add_state('guard', is_start_block=True) + formula_state = sdfg.add_state('formula', is_start_block=False) + const_state = sdfg.add_state('const', is_start_block=False) sdfg.add_array('A', [1], dace.float64) sdfg.add_array('B', [1], dace.float64) # Add tasklet inside states formula_tasklet = formula_state.add_tasklet('formula_assign', {'b'}, {'a'}, 'a = 2*b') - formula_state.add_memlet_path(formula_state.add_read('B'), formula_tasklet, memlet=Memlet(data='B', subset='0'), + formula_state.add_memlet_path(formula_state.add_read('B'), + formula_tasklet, + memlet=Memlet(data='B', subset='0'), dst_conn='b') - formula_state.add_memlet_path(formula_tasklet, formula_state.add_write('A'), memlet=Memlet(data='A', subset='0'), + formula_state.add_memlet_path(formula_tasklet, + formula_state.add_write('A'), + memlet=Memlet(data='A', subset='0'), src_conn='a') const_tasklet = const_state.add_tasklet('const_assign', {}, {'a'}, f"a = {const_value}") - const_state.add_memlet_path(const_tasklet, const_state.add_write('A'), memlet=Memlet(data='A', subset='0'), + const_state.add_memlet_path(const_tasklet, + const_state.add_write('A'), + memlet=Memlet(data='A', subset='0'), src_conn='a') # Create if-else condition such that either the formula state or the const state is executed @@ -47,9 +53,9 @@ def multiple_variable_test(): """ Test with multiple variables where not all appear in the const branch """ sdfg = dace.SDFG('one_variable_simple_test') # Create guard state and one state where A is set to 0 and another where it is set using B and some formula - guard = sdfg.add_state('guard', is_start_state=True) - formula_state = sdfg.add_state('formula', is_start_state=False) - const_state = sdfg.add_state('const', is_start_state=False) + guard = sdfg.add_state('guard', is_start_block=True) + formula_state = sdfg.add_state('formula', is_start_block=False) + const_state = sdfg.add_state('const', is_start_block=False) sdfg.add_array('A', [1], dace.float64) sdfg.add_array('B', [1], dace.float64) sdfg.add_array('C', [1], dace.float64) @@ -70,10 +76,14 @@ def multiple_variable_test(): formula_state.add_memlet_path(formula_tasklet_c, C, memlet=Memlet(data='C', subset='0'), src_conn='c') const_tasklet_a = const_state.add_tasklet('const_assign', {}, {'a'}, 'a = 0') - const_state.add_memlet_path(const_tasklet_a, const_state.add_write('A'), memlet=Memlet(data='A', subset='0'), + const_state.add_memlet_path(const_tasklet_a, + const_state.add_write('A'), + memlet=Memlet(data='A', subset='0'), src_conn='a') const_tasklet_b = const_state.add_tasklet('const_assign', {}, {'b'}, 'b = 0') - const_state.add_memlet_path(const_tasklet_b, const_state.add_write('B'), memlet=Memlet(data='B', subset='0'), + const_state.add_memlet_path(const_tasklet_b, + const_state.add_write('B'), + memlet=Memlet(data='B', subset='0'), src_conn='b') # Create if-else condition such that either the formula state or the const state is executed @@ -100,9 +110,9 @@ def multiple_variable_not_all_const_test(): """ Test with multiple variables where not all get const-assigned in const branch """ sdfg = dace.SDFG('one_variable_simple_test') # Create guard state and one state where A is set to 0 and another where it is set using B and some formula - guard = sdfg.add_state('guard', is_start_state=True) - formula_state = sdfg.add_state('formula', is_start_state=False) - const_state = sdfg.add_state('const', is_start_state=False) + guard = sdfg.add_state('guard', is_start_block=True) + formula_state = sdfg.add_state('formula', is_start_block=False) + const_state = sdfg.add_state('const', is_start_block=False) sdfg.add_array('A', [1], dace.float64) sdfg.add_array('B', [1], dace.float64) sdfg.add_array('C', [1], dace.float64) @@ -118,12 +128,18 @@ def multiple_variable_not_all_const_test(): formula_state.add_memlet_path(formula_tasklet_b, B, memlet=Memlet(data='B', subset='0'), src_conn='b') const_tasklet_a = const_state.add_tasklet('const_assign', {}, {'a'}, 'a = 0') - const_state.add_memlet_path(const_tasklet_a, const_state.add_write('A'), memlet=Memlet(data='A', subset='0'), + const_state.add_memlet_path(const_tasklet_a, + const_state.add_write('A'), + memlet=Memlet(data='A', subset='0'), src_conn='a') const_tasklet_b = const_state.add_tasklet('const_assign', {'c'}, {'b'}, 'b = 1.5 * c') - const_state.add_memlet_path(const_state.add_read('C'), const_tasklet_b, memlet=Memlet(data='C', subset='0'), + const_state.add_memlet_path(const_state.add_read('C'), + const_tasklet_b, + memlet=Memlet(data='C', subset='0'), dst_conn='c') - const_state.add_memlet_path(const_tasklet_b, const_state.add_write('B'), memlet=Memlet(data='B', subset='0'), + const_state.add_memlet_path(const_tasklet_b, + const_state.add_write('B'), + memlet=Memlet(data='B', subset='0'), src_conn='b') # Create if-else condition such that either the formula state or the const state is executed diff --git a/tests/transformations/state_fusion_node_merge_test.py b/tests/transformations/state_fusion_node_merge_test.py index 463c693a76..f7d4099b04 100644 --- a/tests/transformations/state_fusion_node_merge_test.py +++ b/tests/transformations/state_fusion_node_merge_test.py @@ -43,9 +43,9 @@ def relative_error(val, ref): def test_one(): - N.set(42) - A = np.random.rand(N.get()).astype(np.float64) - B = np.random.rand(N.get()).astype(np.float64) + N = 42 + A = np.random.rand(N).astype(np.float64) + B = np.random.rand(N).astype(np.float64) A_ref = A + 42 + 43 B_ref = A + 42 diff --git a/tests/transformations/subgraph_fusion/block_allreduce_cudatest.py b/tests/transformations/subgraph_fusion/block_allreduce_cudatest.py index 4a58656332..eccb57d479 100644 --- a/tests/transformations/subgraph_fusion/block_allreduce_cudatest.py +++ b/tests/transformations/subgraph_fusion/block_allreduce_cudatest.py @@ -8,9 +8,6 @@ N = dace.symbol('N') M = dace.symbol('M') -N.set(30) -M.set(30) - @dace.program def program(A: dace.float32[M, N]): @@ -19,7 +16,7 @@ def program(A: dace.float32[M, N]): @pytest.mark.gpu def test_blockallreduce(): - A = np.random.rand(M.get(), N.get()).astype(np.float32) + A = np.random.rand(30, 30).astype(np.float32) sdfg = program.to_sdfg() sdfg.apply_gpu_transformations() @@ -30,7 +27,7 @@ def test_blockallreduce(): reduce_node.implementation = 'CUDA (device)' csdfg = sdfg.compile() - result1 = csdfg(A=A, M=M, N=N) + result1 = csdfg(A=A, M=30, N=30) del csdfg sdfg_id = 0 @@ -42,7 +39,7 @@ def test_blockallreduce(): transform.reduce_implementation = 'CUDA (block allreduce)' transform.apply(sdfg.node(0), sdfg) csdfg = sdfg.compile() - result2 = csdfg(A=A, M=M, N=N) + result2 = csdfg(A=A, M=30, N=30) del csdfg print(np.linalg.norm(result1)) diff --git a/tests/transformations/subgraph_fusion/complex_test.py b/tests/transformations/subgraph_fusion/complex_test.py index 7a01267c3a..54ebcf1242 100644 --- a/tests/transformations/subgraph_fusion/complex_test.py +++ b/tests/transformations/subgraph_fusion/complex_test.py @@ -12,16 +12,13 @@ from util import expand_maps, expand_reduce, fusion N, M, O = [dace.symbol(s) for s in ['N', 'M', 'O']] -N.set(50) -M.set(60) -O.set(70) - -A = np.random.rand(N.get()).astype(np.float64) -B = np.random.rand(M.get()).astype(np.float64) -C = np.random.rand(O.get()).astype(np.float64) -out1 = np.ndarray((N.get(), M.get()), np.float64) + +A = np.random.rand(50).astype(np.float64) +B = np.random.rand(60).astype(np.float64) +C = np.random.rand(70).astype(np.float64) +out1 = np.ndarray((50, 60), np.float64) out2 = np.ndarray((1), np.float64) -out3 = np.ndarray((N.get(), M.get(), O.get()), np.float64) +out3 = np.ndarray((50, 60, 70), np.float64) @dace.program @@ -98,17 +95,17 @@ def fun(): def _test_quantitatively(sdfg, graph): - A = np.random.rand(N.get()).astype(np.float64) - B = np.random.rand(M.get()).astype(np.float64) - C = np.random.rand(O.get()).astype(np.float64) - out1_base = np.ndarray((N.get(), M.get()), np.float64) + A = np.random.rand(50).astype(np.float64) + B = np.random.rand(60).astype(np.float64) + C = np.random.rand(70).astype(np.float64) + out1_base = np.ndarray((50, 60), np.float64) out2_base = np.ndarray((1), np.float64) - out3_base = np.ndarray((N.get(), M.get(), O.get()), np.float64) - out1 = np.ndarray((N.get(), M.get()), np.float64) + out3_base = np.ndarray((50, 60, 70), np.float64) + out1 = np.ndarray((50, 60), np.float64) out2 = np.ndarray((1), np.float64) - out3 = np.ndarray((N.get(), M.get(), O.get()), np.float64) + out3 = np.ndarray((50, 60, 70), np.float64) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C, out1=out1_base, out2=out2_base, out3=out3_base, N=N, M=M, O=O) + csdfg(A=A, B=B, C=C, out1=out1_base, out2=out2_base, out3=out3_base, N=50, M=60, O=70) del csdfg expand_reduce(sdfg, graph) @@ -120,7 +117,7 @@ def _test_quantitatively(sdfg, graph): fusion(sdfg, graph) sdfg.validate() csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C, out1=out1, out2=out2, out3=out3, N=N, M=M, O=O) + csdfg(A=A, B=B, C=C, out1=out1, out2=out2, out3=out3, N=50, M=60, O=70) del csdfg assert np.allclose(out1, out1_base) diff --git a/tests/transformations/subgraph_fusion/create_out_transient_test.py b/tests/transformations/subgraph_fusion/create_out_transient_test.py index 8c41e70d77..d331c92e1d 100644 --- a/tests/transformations/subgraph_fusion/create_out_transient_test.py +++ b/tests/transformations/subgraph_fusion/create_out_transient_test.py @@ -12,9 +12,6 @@ from util import fusion N, M, O = [dace.symbol(s) for s in ['N', 'M', 'O']] -N.set(50) -M.set(60) -O.set(70) @dace.program @@ -69,17 +66,17 @@ def program2(A: dace.float64[M, N], B: dace.float64[M, N], C: dace.float64[M, N] def _test_quantitatively(sdfg, graph): - A = np.random.rand(M.get(), N.get()).astype(np.float64) - B1 = np.zeros(shape=[M.get(), N.get()], dtype=np.float64) - C1 = np.zeros(shape=[M.get(), N.get()], dtype=np.float64) - B2 = np.zeros(shape=[M.get(), N.get()], dtype=np.float64) - C2 = np.zeros(shape=[M.get(), N.get()], dtype=np.float64) + A = np.random.rand(60, 50).astype(np.float64) + B1 = np.zeros(shape=[60, 50], dtype=np.float64) + C1 = np.zeros(shape=[60, 50], dtype=np.float64) + B2 = np.zeros(shape=[60, 50], dtype=np.float64) + C2 = np.zeros(shape=[60, 50], dtype=np.float64) csdfg = sdfg.compile() - csdfg(A=A, B=B1, C=C1, N=N, M=M) + csdfg(A=A, B=B1, C=C1, N=50, M=60) del csdfg fusion(sdfg, graph) csdfg = sdfg.compile() - csdfg(A=A, B=B2, C=C2, N=N, M=M) + csdfg(A=A, B=B2, C=C2, N=50, M=60) del csdfg assert np.allclose(B1, B2) assert np.allclose(C1, C2) diff --git a/tests/transformations/subgraph_fusion/disjoint_test.py b/tests/transformations/subgraph_fusion/disjoint_test.py index 002bdfba35..7dfb015a72 100644 --- a/tests/transformations/subgraph_fusion/disjoint_test.py +++ b/tests/transformations/subgraph_fusion/disjoint_test.py @@ -14,8 +14,6 @@ M = dace.symbol('M') N = dace.symbol('N') -N.set(20) -M.set(30) # TRUE @@ -86,12 +84,12 @@ def test_p1(): sdfg.simplify() state = sdfg.nodes()[0] assert len(sdfg.nodes()) == 1 - A = np.random.rand(M.get(), 2).astype(np.float64) + A = np.random.rand(30, 2).astype(np.float64) A1 = A.copy() A2 = A.copy() csdfg = sdfg.compile() - csdfg(A=A1, N=N, M=M) + csdfg(A=A1, N=20, M=30) del csdfg subgraph = SubgraphView(state, state.nodes()) @@ -101,7 +99,7 @@ def test_p1(): sf.apply(sdfg) csdfg = sdfg.compile() - csdfg(A=A2, M=M) + csdfg(A=A2, M=30) del csdfg assert np.allclose(A1, A2) diff --git a/tests/transformations/subgraph_fusion/expansion_test.py b/tests/transformations/subgraph_fusion/expansion_test.py index ba1e48226d..4afa6b7793 100644 --- a/tests/transformations/subgraph_fusion/expansion_test.py +++ b/tests/transformations/subgraph_fusion/expansion_test.py @@ -12,9 +12,6 @@ from util import expand_maps, expand_reduce, fusion N, M, O = [dace.symbol(s) for s in ['N', 'M', 'O']] -N.set(50) -M.set(60) -O.set(70) @dace.program @@ -72,13 +69,13 @@ def test_expansion2(): sdfg = expansion2.to_sdfg() graph = sdfg.nodes()[0] kwargs = { - 'A': np.random.rand(M.get(), N.get()).astype(np.float64), - 'B': np.random.rand(M.get(), O.get()).astype(np.float64), - 'out1': np.ndarray((M.get(), N.get()), dtype=np.float64), - 'out2': np.ndarray((M.get(), O.get()), dtype=np.float64), - 'N': N, - 'M': M, - 'O': O + 'A': np.random.rand(60, 50).astype(np.float64), + 'B': np.random.rand(60, 70).astype(np.float64), + 'out1': np.ndarray((60, 50), dtype=np.float64), + 'out2': np.ndarray((60, 70), dtype=np.float64), + 'N': 50, + 'M': 60, + 'O': 70 } run(sdfg, graph, kwargs) @@ -101,13 +98,13 @@ def test_expansion1(): sdfg = expansion1.to_sdfg() graph = sdfg.nodes()[0] kwargs = { - 'A': np.random.rand(M.get(), N.get(), O.get()).astype(np.float64), - 'B': np.random.rand(M.get(), N.get(), O.get()).astype(np.float64), - 'C': np.random.rand(M.get(), N.get(), O.get()).astype(np.float64), - 'out1': np.ndarray((M.get(), N.get(), O.get()), dtype=np.float64), - 'N': N, - 'M': M, - 'O': O + 'A': np.random.rand(60, 50, 70).astype(np.float64), + 'B': np.random.rand(60, 50, 70).astype(np.float64), + 'C': np.random.rand(60, 50, 70).astype(np.float64), + 'out1': np.ndarray((60, 50, 70), dtype=np.float64), + 'N': 50, + 'M': 60, + 'O': 70 } run(sdfg, graph, kwargs) out1 = kwargs['out1'].copy() diff --git a/tests/transformations/subgraph_fusion/intermediate_mimo_test.py b/tests/transformations/subgraph_fusion/intermediate_mimo_test.py index 1996d3c4a5..499e3ea97b 100644 --- a/tests/transformations/subgraph_fusion/intermediate_mimo_test.py +++ b/tests/transformations/subgraph_fusion/intermediate_mimo_test.py @@ -14,7 +14,6 @@ from dace.sdfg.graph import SubgraphView N = dace.symbol('N') -N.set(1000) @dace.program @@ -47,15 +46,15 @@ def mimo(A: dace.float64[N], B: dace.float64[N], C: dace.float64[N], D: dace.flo def _test_quantitatively(sdfg): graph = sdfg.nodes()[0] - A = np.random.rand(N.get()).astype(np.float64) - B = np.random.rand(N.get()).astype(np.float64) - C1 = np.random.rand(N.get()).astype(np.float64) - C2 = np.random.rand(N.get()).astype(np.float64) - D1 = np.random.rand(N.get()).astype(np.float64) - D2 = np.random.rand(N.get()).astype(np.float64) + A = np.random.rand(1000).astype(np.float64) + B = np.random.rand(1000).astype(np.float64) + C1 = np.random.rand(1000).astype(np.float64) + C2 = np.random.rand(1000).astype(np.float64) + D1 = np.random.rand(1000).astype(np.float64) + D2 = np.random.rand(1000).astype(np.float64) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C1, D=D1, N=N) + csdfg(A=A, B=B, C=C1, D=D1, N=1000) del csdfg subgraph = SubgraphView(graph, [node for node in graph.nodes()]) @@ -71,7 +70,7 @@ def _test_quantitatively(sdfg): sf.apply(sdfg) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C2, D=D2, N=N) + csdfg(A=A, B=B, C=C2, D=D2, N=1000) assert np.allclose(C1, C2) assert np.allclose(D1, D2) diff --git a/tests/transformations/subgraph_fusion/invariant_dimension_test.py b/tests/transformations/subgraph_fusion/invariant_dimension_test.py index 79a6ec5011..7772a634ff 100644 --- a/tests/transformations/subgraph_fusion/invariant_dimension_test.py +++ b/tests/transformations/subgraph_fusion/invariant_dimension_test.py @@ -16,14 +16,11 @@ from util import fusion N, M, O = [dace.symbol(s) for s in ['N', 'M', 'O']] -N.set(50) -M.set(60) -O.set(70) -A = np.random.rand(N.get(), M.get(), O.get()).astype(np.float64) -B = np.random.rand(N.get(), M.get(), O.get()).astype(np.float64) -C = np.random.rand(N.get(), M.get(), O.get()).astype(np.float64) -out1 = np.ndarray((N.get(), M.get(), O.get()), np.float64) +A = np.random.rand(50, 60, 70).astype(np.float64) +B = np.random.rand(50, 60, 70).astype(np.float64) +C = np.random.rand(50, 60, 70).astype(np.float64) +out1 = np.ndarray((50, 60, 70), np.float64) @dace.program @@ -101,14 +98,14 @@ def fix_sdfg(sdfg, graph): def _test_quantitatively(sdfg, graph): - A = np.random.rand(N.get(), M.get(), O.get()).astype(np.float64) - B = np.random.rand(N.get(), M.get(), O.get()).astype(np.float64) - C1 = np.zeros([N.get(), M.get(), O.get()], dtype=np.float64) - C2 = np.zeros([N.get(), M.get(), O.get()], dtype=np.float64) + A = np.random.rand(50, 60, 70).astype(np.float64) + B = np.random.rand(50, 60, 70).astype(np.float64) + C1 = np.zeros([50, 60, 70], dtype=np.float64) + C2 = np.zeros([50, 60, 70], dtype=np.float64) sdfg.validate() csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C1, N=N, M=M, O=O) + csdfg(A=A, B=B, C=C1, N=50, M=60, O=70) del csdfg subgraph = SubgraphView(graph, graph.nodes()) @@ -118,7 +115,7 @@ def _test_quantitatively(sdfg, graph): fusion(sdfg, graph) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C2, N=N, M=M, O=O) + csdfg(A=A, B=B, C=C2, N=50, M=60, O=70) del csdfg assert np.allclose(C1, C2) diff --git a/tests/transformations/subgraph_fusion/parallel_test.py b/tests/transformations/subgraph_fusion/parallel_test.py index 3af0a94dec..fae9cd2196 100644 --- a/tests/transformations/subgraph_fusion/parallel_test.py +++ b/tests/transformations/subgraph_fusion/parallel_test.py @@ -56,34 +56,34 @@ def subgraph_fusion_parallel(A: dace.float64[N], B: dace.float64[M], C: dace.flo def test_p1(): - N.set(20) - M.set(30) - O.set(50) - P.set(40) - Q.set(42) - R.set(25) + N = 20 + M = 30 + O = 50 + P = 40 + Q = 42 + R = 25 sdfg = subgraph_fusion_parallel.to_sdfg() sdfg.simplify() state = sdfg.nodes()[0] - A = np.random.rand(N.get()).astype(np.float64) - B = np.random.rand(M.get()).astype(np.float64) - C = np.random.rand(O.get()).astype(np.float64) - D = np.random.rand(M.get()).astype(np.float64) - E = np.random.rand(N.get()).astype(np.float64) - F = np.random.rand(P.get()).astype(np.float64) - G = np.random.rand(M.get()).astype(np.float64) - H = np.random.rand(P.get()).astype(np.float64) - I = np.random.rand(N.get()).astype(np.float64) - J = np.random.rand(R.get()).astype(np.float64) - X = np.random.rand(N.get()).astype(np.float64) - Y = np.random.rand(M.get()).astype(np.float64) - Z = np.random.rand(P.get()).astype(np.float64) - o1 = np.random.rand(N.get(), M.get(), O.get()) - o2 = np.random.rand(M.get(), N.get(), P.get()) - o3 = np.random.rand(P.get(), N.get(), R.get()) - o4 = np.random.rand(N.get(), M.get(), P.get()) + A = np.random.rand(N).astype(np.float64) + B = np.random.rand(M).astype(np.float64) + C = np.random.rand(O).astype(np.float64) + D = np.random.rand(M).astype(np.float64) + E = np.random.rand(N).astype(np.float64) + F = np.random.rand(P).astype(np.float64) + G = np.random.rand(M).astype(np.float64) + H = np.random.rand(P).astype(np.float64) + I = np.random.rand(N).astype(np.float64) + J = np.random.rand(R).astype(np.float64) + X = np.random.rand(N).astype(np.float64) + Y = np.random.rand(M).astype(np.float64) + Z = np.random.rand(P).astype(np.float64) + o1 = np.random.rand(N, M, O) + o2 = np.random.rand(M, N, P) + o3 = np.random.rand(P, N, R) + o4 = np.random.rand(N, M, P) csdfg = sdfg.compile() csdfg(A=A, diff --git a/tests/transformations/subgraph_fusion/reduction_fuse_test.py b/tests/transformations/subgraph_fusion/reduction_fuse_test.py index 34aa379bb3..1e2597d510 100644 --- a/tests/transformations/subgraph_fusion/reduction_fuse_test.py +++ b/tests/transformations/subgraph_fusion/reduction_fuse_test.py @@ -14,8 +14,6 @@ M = dace.symbol('M') N = dace.symbol('N') -N.set(20) -M.set(30) @dace.program @@ -40,25 +38,25 @@ def test_p3(in_transient, out_transient): sdfg = reduction_test_3.to_sdfg() sdfg.simplify() state = sdfg.nodes()[0] - A = np.random.rand(M.get(), N.get()).astype(np.float64) - B = np.random.rand(M.get(), N.get()).astype(np.float64) - C1 = np.zeros([N.get()], dtype=np.float64) - C2 = np.zeros([N.get()], dtype=np.float64) - C3 = np.zeros([N.get()], dtype=np.float64) + A = np.random.rand(30, 20).astype(np.float64) + B = np.random.rand(30, 20).astype(np.float64) + C1 = np.zeros([20], dtype=np.float64) + C2 = np.zeros([20], dtype=np.float64) + C3 = np.zeros([20], dtype=np.float64) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C1, N=N, M=M) + csdfg(A=A, B=B, C=C1, N=20, M=30) del csdfg expand_reduce(sdfg, state, create_in_transient=in_transient, create_out_transient=out_transient) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C2, N=N, M=M) + csdfg(A=A, B=B, C=C2, N=20, M=30) del csdfg expand_maps(sdfg, state) fusion(sdfg, state) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C3, N=N, M=M) + csdfg(A=A, B=B, C=C3, N=20, M=30) del csdfg assert np.linalg.norm(C1) > 0.01 @@ -67,6 +65,6 @@ def test_p3(in_transient, out_transient): if __name__ == "__main__": - test_p3() - test_p3(in_transient=True) - test_p3(out_transient=True) + test_p3(False, False) + test_p3(True, False) + test_p3(False, True) diff --git a/tests/transformations/subgraph_fusion/reduction_test.py b/tests/transformations/subgraph_fusion/reduction_test.py index fa738e9dae..2d71992178 100644 --- a/tests/transformations/subgraph_fusion/reduction_test.py +++ b/tests/transformations/subgraph_fusion/reduction_test.py @@ -14,8 +14,6 @@ M = dace.symbol('M') N = dace.symbol('N') -N.set(20) -M.set(30) @dace.program @@ -56,18 +54,18 @@ def test_p1(in_transient, out_transient): rexp.setup_match(sdfg, sdfg.sdfg_id, 0, {ReduceExpansion.reduce: state.node_id(reduce_node)}, 0) assert rexp.can_be_applied(state, 0, sdfg) == True - A = np.random.rand(M.get(), N.get()).astype(np.float64) - B = np.random.rand(M.get(), N.get()).astype(np.float64) - C1 = np.zeros([N.get()], dtype=np.float64) - C2 = np.zeros([N.get()], dtype=np.float64) + A = np.random.rand(30, 20).astype(np.float64) + B = np.random.rand(30, 20).astype(np.float64) + C1 = np.zeros([20], dtype=np.float64) + C2 = np.zeros([20], dtype=np.float64) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C1, N=N, M=M) + csdfg(A=A, B=B, C=C1, N=20, M=30) del csdfg expand_reduce(sdfg, state, create_in_transient=in_transient, create_out_transient=out_transient) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C2, N=N, M=M) + csdfg(A=A, B=B, C=C2, N=20, M=30) del csdfg assert np.linalg.norm(C1) > 0.01 @@ -82,18 +80,18 @@ def test_p2(in_transient, out_transient): sdfg = reduction_test_2.to_sdfg() sdfg.simplify() state = sdfg.nodes()[0] - A = np.random.rand(M.get(), N.get()).astype(np.float64) - B = np.random.rand(M.get(), N.get()).astype(np.float64) - C1 = np.zeros([N.get()], dtype=np.float64) - C2 = np.zeros([N.get()], dtype=np.float64) + A = np.random.rand(30, 20).astype(np.float64) + B = np.random.rand(30, 20).astype(np.float64) + C1 = np.zeros([20], dtype=np.float64) + C2 = np.zeros([20], dtype=np.float64) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C1, N=N, M=M) + csdfg(A=A, B=B, C=C1, N=20, M=30) del csdfg expand_reduce(sdfg, state, create_in_transient=in_transient, create_out_transient=out_transient) csdfg = sdfg.compile() - csdfg(A=A, B=B, C=C2, N=N, M=M) + csdfg(A=A, B=B, C=C2, N=20, M=30) assert np.linalg.norm(C1) > 0.01 assert np.allclose(C1, C2) diff --git a/tests/transformations/subgraph_fusion/sequential1_test.py b/tests/transformations/subgraph_fusion/sequential1_test.py index 427a1d1a44..c870475b0e 100644 --- a/tests/transformations/subgraph_fusion/sequential1_test.py +++ b/tests/transformations/subgraph_fusion/sequential1_test.py @@ -28,15 +28,15 @@ def subgraph_fusion_sequential(A: dace.float64[N], B: dace.float64[N], C: dace.f def test_sequential(): - N.set(1000) + N = 1000 sdfg = subgraph_fusion_sequential.to_sdfg() state = sdfg.nodes()[0] - A = np.random.rand(N.get()).astype(np.float64) - B = np.random.rand(N.get()).astype(np.float64) - C1 = np.random.rand(N.get()).astype(np.float64) - C2 = np.random.rand(N.get()).astype(np.float64) + A = np.random.rand(N).astype(np.float64) + B = np.random.rand(N).astype(np.float64) + C1 = np.random.rand(N).astype(np.float64) + C2 = np.random.rand(N).astype(np.float64) csdfg = sdfg.compile() csdfg(A=A, B=B, C=C1, N=N) diff --git a/tests/transformations/subgraph_fusion/sequential2_cudatest.py b/tests/transformations/subgraph_fusion/sequential2_cudatest.py index dced9afc78..8f66146f59 100644 --- a/tests/transformations/subgraph_fusion/sequential2_cudatest.py +++ b/tests/transformations/subgraph_fusion/sequential2_cudatest.py @@ -30,15 +30,15 @@ def program(A: dace.float64[N], C: dace.float64[N]): @pytest.mark.gpu def test(): - N.set(50) + N = 50 sdfg = program.to_sdfg() sdfg.apply_gpu_transformations() state = sdfg.nodes()[0] - A = np.random.rand(N.get()).astype(np.float64) - C1 = np.random.rand(N.get()).astype(np.float64) - C2 = np.random.rand(N.get()).astype(np.float64) + A = np.random.rand(N).astype(np.float64) + C1 = np.random.rand(N).astype(np.float64) + C2 = np.random.rand(N).astype(np.float64) csdfg = sdfg.compile() csdfg(A=A, C=C1, N=N) diff --git a/tests/transformations/subgraph_fusion/sequential2_test.py b/tests/transformations/subgraph_fusion/sequential2_test.py index 3e6a9bd725..a00664b5cb 100644 --- a/tests/transformations/subgraph_fusion/sequential2_test.py +++ b/tests/transformations/subgraph_fusion/sequential2_test.py @@ -28,15 +28,15 @@ def sequential2(A: dace.float64[N], C: dace.float64[N]): def test_sequential(): - N.set(1000) + N = 1000 sdfg = sequential2.to_sdfg() state = sdfg.nodes()[0] - A = np.random.rand(N.get()).astype(np.float64) - B = np.random.rand(N.get()).astype(np.float64) - C1 = np.random.rand(N.get()).astype(np.float64) - C2 = np.random.rand(N.get()).astype(np.float64) + A = np.random.rand(N).astype(np.float64) + B = np.random.rand(N).astype(np.float64) + C1 = np.random.rand(N).astype(np.float64) + C2 = np.random.rand(N).astype(np.float64) csdfg = sdfg.compile() csdfg(A=A, B=B, C=C1, N=N) diff --git a/tests/transformations/subgraph_fusion/smax_test.py b/tests/transformations/subgraph_fusion/smax_test.py index d512cdf091..3138a0893c 100644 --- a/tests/transformations/subgraph_fusion/smax_test.py +++ b/tests/transformations/subgraph_fusion/smax_test.py @@ -45,12 +45,6 @@ def softmax(X_in: dace_dtype[H, B, SN, SM]): return out -H.set(10) -B.set(10) -SN.set(20) -SM.set(20) - - def get_partition(sdfg, graph): subgraph1 = SubgraphView(graph, []) subgraph2 = SubgraphView(graph, []) @@ -78,10 +72,10 @@ def test_2fuse(): sdfg = softmax.to_sdfg() sdfg.name = 'softmax_2part' sdfg.simplify() - X_in = np.random.rand(H.get(), B.get(), SN.get(), SM.get()).astype(np.float32) + X_in = np.random.rand(10, 10, 20, 20).astype(np.float32) csdfg = sdfg.compile() - res1 = csdfg(X_in=X_in, H=H, B=B, SN=SN, SM=SM) + res1 = csdfg(X_in=X_in, H=10, B=10, SN=20, SM=20) del csdfg subgraph = get_partition(sdfg, sdfg.nodes()[0]) @@ -90,7 +84,7 @@ def test_2fuse(): fusion(sdfg, sdfg.nodes()[0], subgraph) csdfg = sdfg.compile() - res2 = csdfg(X_in=X_in, H=H, B=B, SN=SN, SM=SM) + res2 = csdfg(X_in=X_in, H=10, B=10, SN=20, SM=20) del csdfg assert np.allclose(res1, res2) @@ -102,10 +96,10 @@ def test_1fuse(): sdfg = softmax.to_sdfg() sdfg.name = 'softmax_fused' sdfg.simplify() - X_in = np.random.rand(H.get(), B.get(), SN.get(), SM.get()).astype(np.float32) + X_in = np.random.rand(10, 10, 20, 20).astype(np.float32) csdfg = sdfg.compile() - res1 = csdfg(X_in=X_in, H=H, B=B, SN=SN, SM=SM) + res1 = csdfg(X_in=X_in, H=10, B=10, SN=20, SM=20) del csdfg expand_reduce(sdfg, sdfg.nodes()[0]) @@ -113,7 +107,7 @@ def test_1fuse(): fusion(sdfg, sdfg.nodes()[0]) csdfg = sdfg.compile() - res2 = csdfg(X_in=X_in, H=H, B=B, SN=SN, SM=SM) + res2 = csdfg(X_in=X_in, H=10, B=10, SN=20, SM=20) del csdfg print(np.linalg.norm(res1)) @@ -127,10 +121,10 @@ def test_1fuse(): sdfg = softmax.to_sdfg() sdfg.name = 'softmax_fused' sdfg.simplify() - X_in = np.random.rand(H.get(), B.get(), SN.get(), SM.get()).astype(np.float32) + X_in = np.random.rand(10, 10, 20, 20).astype(np.float32) csdfg = sdfg.compile() - res1 = csdfg(X_in=X_in, H=H, B=B, SN=SN, SM=SM) + res1 = csdfg(X_in=X_in, H=10, B=10, SN=20, SM=20) del csdfg expand_reduce(sdfg, sdfg.nodes()[0]) @@ -139,7 +133,7 @@ def test_1fuse(): #sdfg.specialize({'SM':SM}) csdfg = sdfg.compile() - res2 = csdfg(X_in=X_in, H=H, B=B, SN=SN, SM=SM) + res2 = csdfg(X_in=X_in, H=10, B=10, SN=20, SM=20) del csdfg print(np.linalg.norm(res1)) diff --git a/tests/transformations/subgraph_fusion/tiling_pool_test.py b/tests/transformations/subgraph_fusion/tiling_pool_test.py index 9432125c6e..6b9500c021 100644 --- a/tests/transformations/subgraph_fusion/tiling_pool_test.py +++ b/tests/transformations/subgraph_fusion/tiling_pool_test.py @@ -11,7 +11,6 @@ import itertools N = dace.symbol('N') -N.set(100) @dace.program @@ -56,10 +55,10 @@ def m2(i: _[0:N - 2]): def invoke_stencil(tile_size, offset=False, unroll=False): - A = np.random.rand(N.get() * 2).astype(np.float64) - B1 = np.zeros((N.get()), dtype=np.float64) - B2 = np.zeros((N.get()), dtype=np.float64) - B3 = np.zeros((N.get()), dtype=np.float64) + A = np.random.rand(100 * 2).astype(np.float64) + B1 = np.zeros((100), dtype=np.float64) + B2 = np.zeros((100), dtype=np.float64) + B3 = np.zeros((100), dtype=np.float64) if offset: sdfg = stencil_offset.to_sdfg() @@ -71,7 +70,7 @@ def invoke_stencil(tile_size, offset=False, unroll=False): # baseline sdfg.name = f'baseline_{tile_size}_{offset}_{unroll}' csdfg = sdfg.compile() - csdfg(A=A, B=B1, N=N) + csdfg(A=A, B=B1, N=100) del csdfg subgraph = SubgraphView(graph, [n for n in graph.nodes()]) @@ -86,7 +85,7 @@ def invoke_stencil(tile_size, offset=False, unroll=False): sdfg.name = f'tiled_{tile_size}_{offset}_{unroll}' csdfg = sdfg.compile() - csdfg(A=A, B=B2, N=N) + csdfg(A=A, B=B2, N=100) del csdfg sdfg.simplify() @@ -98,7 +97,7 @@ def invoke_stencil(tile_size, offset=False, unroll=False): sdfg.name = f'fused_{tile_size}_{offset}_{unroll}' csdfg = sdfg.compile() - csdfg(A=A, B=B3, N=N) + csdfg(A=A, B=B3, N=100) del csdfg print(np.linalg.norm(B1)) diff --git a/tests/transformations/subgraph_fusion/tiling_stencil_test.py b/tests/transformations/subgraph_fusion/tiling_stencil_test.py index 307861abd4..91fd198a9a 100644 --- a/tests/transformations/subgraph_fusion/tiling_stencil_test.py +++ b/tests/transformations/subgraph_fusion/tiling_stencil_test.py @@ -11,7 +11,6 @@ import itertools N = dace.symbol('N') -N.set(100) @dace.program @@ -96,10 +95,10 @@ def m4(i: _[0:N - 4]): def invoke_stencil(tile_size, offset=False, unroll=False, view=False): - A = np.random.rand(N.get()).astype(np.float64) - B1 = np.zeros((N.get()), dtype=np.float64) - B2 = np.zeros((N.get()), dtype=np.float64) - B3 = np.zeros((N.get()), dtype=np.float64) + A = np.random.rand(100).astype(np.float64) + B1 = np.zeros((100), dtype=np.float64) + B2 = np.zeros((100), dtype=np.float64) + B3 = np.zeros((100), dtype=np.float64) if offset: sdfg = stencil_offset.to_sdfg() @@ -113,7 +112,7 @@ def invoke_stencil(tile_size, offset=False, unroll=False, view=False): # baseline sdfg.name = 'baseline' csdfg = sdfg.compile() - csdfg(A=A, B=B1, N=N) + csdfg(A=A, B=B1, N=100) del csdfg subgraph = SubgraphView(graph, [n for n in graph.nodes()]) @@ -130,7 +129,7 @@ def invoke_stencil(tile_size, offset=False, unroll=False, view=False): sdfg.name = 'tiled' sdfg.validate() csdfg = sdfg.compile() - csdfg(A=A, B=B2, N=N) + csdfg(A=A, B=B2, N=100) del csdfg assert np.allclose(B1, B2) @@ -144,7 +143,7 @@ def invoke_stencil(tile_size, offset=False, unroll=False, view=False): sf.apply(sdfg) sdfg.name = 'fused' csdfg = sdfg.compile() - csdfg(A=A, B=B3, N=N) + csdfg(A=A, B=B3, N=100) del csdfg print(np.linalg.norm(B1)) diff --git a/tests/transformations/tasklet_fusion_test.py b/tests/transformations/tasklet_fusion_test.py index 59a7e8b36b..c621ee38d4 100644 --- a/tests/transformations/tasklet_fusion_test.py +++ b/tests/transformations/tasklet_fusion_test.py @@ -32,7 +32,7 @@ def _make_sdfg(language: str, with_data: bool = False): sdfg.add_array('A', (N, ), datatype) sdfg.add_array('B', (M, ), datatype) sdfg.add_array('C', (M, ), datatype) - state = sdfg.add_state(is_start_state=True) + state = sdfg.add_state(is_start_block=True) A = state.add_read('A') B = state.add_read('B') C = state.add_write('C') @@ -95,6 +95,7 @@ def _make_sdfg(language: str, with_data: bool = False): def test_basic(): + @dace.program def test_basic_tf(A: datatype[5, 5]): B = A + 1 @@ -113,6 +114,7 @@ def test_basic_tf(A: datatype[5, 5]): def test_same_name(): + @dace.program def test_same_name(A: datatype[5, 5]): B = A + 1 @@ -132,6 +134,7 @@ def test_same_name(A: datatype[5, 5]): def test_same_name_different_memlet(): + @dace.program def test_same_name_different_memlet(A: datatype[5, 5], B: datatype[5, 5]): C = B * 3 @@ -152,6 +155,7 @@ def test_same_name_different_memlet(A: datatype[5, 5], B: datatype[5, 5]): def test_tasklet_fusion_multiline(): + @dace.program def test_tasklet_fusion_multiline(A: datatype): B = A + 1 @@ -177,6 +181,7 @@ def test_tasklet_fusion_multiline(A: datatype): def test_map_param(): + @dace.program def map_uses_param(A: dace.float32[10], B: dace.float32[10], C: dace.float32[10]): for i in dace.map[0:10]: @@ -214,7 +219,9 @@ def test_map_with_tasklets(language: str, with_data: bool): ref = map_with_tasklets.f(A, B) assert (np.allclose(C, ref)) + def test_none_connector(): + @dace.program def sdfg_none_connector(A: dace.float32[32], B: dace.float32[32]): tmp = dace.define_local([32], dace.float32) @@ -230,7 +237,6 @@ def sdfg_none_connector(A: dace.float32[32], B: dace.float32[32]): b >> tmp2[i] b = a + 1 - for i in dace.map[0:32]: with dace.tasklet: a << tmp[i] @@ -248,7 +254,7 @@ def sdfg_none_connector(A: dace.float32[32], B: dace.float32[32]): if isinstance(node, dace.nodes.MapEntry): map_entry = node break - + assert map_entry is not None assert len([edge.src_conn for edge in sdfg.start_state.out_edges(map_entry) if edge.src_conn is None]) == 1 @@ -260,20 +266,20 @@ def sdfg_none_connector(A: dace.float32[32], B: dace.float32[32]): def test_intermediate_transients(): + @dace.program def sdfg_intermediate_transients(A: dace.float32[10], B: dace.float32[10]): tmp = dace.define_local_scalar(dace.float32) - + # Use tmp twice to test removal of data tmp = A[0] + 1 tmp = tmp * 2 B[0] = tmp - sdfg = sdfg_intermediate_transients.to_sdfg(simplify=True) assert len([node for node in sdfg.start_state.data_nodes() if node.data == "tmp"]) == 2 - xforms = Optimizer(sdfg=sdfg).get_pattern_matches(patterns=(TaskletFusion,)) + xforms = Optimizer(sdfg=sdfg).get_pattern_matches(patterns=(TaskletFusion, )) applied = False for xform in xforms: if xform.data.data == "tmp": @@ -285,6 +291,7 @@ def sdfg_intermediate_transients(A: dace.float32[10], B: dace.float32[10]): assert len([node for node in sdfg.start_state.data_nodes() if node.data == "tmp"]) == 1 assert "tmp" in sdfg.arrays + if __name__ == '__main__': test_basic() test_same_name() diff --git a/tests/unparse_memlet_test.py b/tests/unparse_memlet_test.py index cdd673b872..9379d79265 100644 --- a/tests/unparse_memlet_test.py +++ b/tests/unparse_memlet_test.py @@ -15,16 +15,16 @@ def div(i): def test(): - N.set(25) - A = np.random.rand(N.get()) - B = np.zeros([N.get()], dtype=np.float64) + N = 25 + A = np.random.rand(N) + B = np.zeros([N], dtype=np.float64) floor_div(A, B) - if N.get() % 2 == 0: - expected = 2.0 * np.sum(A[0:N.get() // 2]) + if N % 2 == 0: + expected = 2.0 * np.sum(A[0:N // 2]) else: - expected = 2.0 * np.sum(A[0:N.get() // 2]) + A[N.get() // 2] + expected = 2.0 * np.sum(A[0:N // 2]) + A[N // 2] actual = np.sum(B) diff = abs(actual - expected) print('Difference:', diff) diff --git a/tests/vector_min_test.py b/tests/vector_min_test.py index a7cf955a9b..9c526f1ff4 100644 --- a/tests/vector_min_test.py +++ b/tests/vector_min_test.py @@ -11,11 +11,11 @@ def test(): print('Dynamic SDFG test with vectorization and min') # Externals (parameters, symbols) N = dp.symbol('N') - N.set(20) + n = 20 - input = np.random.rand(N.get()).astype(np.float32) - input2 = np.random.rand(N.get()).astype(np.float32) - output = dp.ndarray([N], dp.float32) + input = np.random.rand(n).astype(np.float32) + input2 = np.random.rand(n).astype(np.float32) + output = dp.ndarray([n], dp.float32) output[:] = dp.float32(0) # Construct SDFG @@ -42,9 +42,9 @@ def test(): state.add_edge(B, None, map_entry, None, Memlet.simple(B, '0:N')) state.add_edge(map_exit, None, C, None, Memlet.simple(C, '0:N')) - mysdfg(A=input, B=input2, C=output, N=N) + mysdfg(A=input, B=input2, C=output, N=n) - diff = np.linalg.norm(np.minimum(input, input2) - output) / N.get() + diff = np.linalg.norm(np.minimum(input, input2) - output) / n print("Difference:", diff) print("==== Program end ====") assert diff <= 1e-5 diff --git a/tests/vla_test.py b/tests/vla_test.py index d0de435acb..1e303d1898 100644 --- a/tests/vla_test.py +++ b/tests/vla_test.py @@ -22,13 +22,12 @@ def test(): - N.set(12) A = np.random.rand(12).astype(np.float32) B = np.random.rand(12).astype(np.float32) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - sdfg(A=A, B=B, N=N) + sdfg(A=A, B=B, N=12) assert w assert any('Variable-length' in str(warn.message) for warn in w) diff --git a/tutorials/explicit.ipynb b/tutorials/explicit.ipynb index 7f9fbbd866..45d172cf35 100644 --- a/tutorials/explicit.ipynb +++ b/tutorials/explicit.ipynb @@ -206,12 +206,12 @@ "outputs": [], "source": [ "N = dace.symbol('N')\n", - "N.set(255)\n", + "n = 255\n", "\n", - "storage = dace.ndarray(shape=[N], dtype=dace.int32)\n", + "storage = dace.ndarray(shape=[n], dtype=dace.int32)\n", "# The size of \"output\" will actually be lesser or equal to N, but we need to \n", "# statically allocate the memory.\n", - "output = dace.ndarray(shape=[N], dtype=dace.int32)\n", + "output = dace.ndarray(shape=[n], dtype=dace.int32)\n", "# The size is a scalar\n", "output_size = dace.scalar(dtype=dace.uint32)" ] @@ -286,9 +286,9 @@ "source": [ "# Define some random integers and zero outputs\n", "import numpy as np\n", - "storage[:] = np.random.randint(0, 100, size=N.get())\n", + "storage[:] = np.random.randint(0, 100, size=n)\n", "output_size[0] = 0\n", - "output[:] = np.zeros(N.get()).astype(np.int32)\n", + "output[:] = np.zeros(n).astype(np.int32)\n", "\n", "# Compute expected output using numpy\n", "expected = storage[np.where(storage > thres)]" @@ -325,7 +325,7 @@ } ], "source": [ - "qfunc(data=storage, output=output, outsz=output_size, threshold=thres, N=N)\n", + "qfunc(data=storage, output=output, outsz=output_size, threshold=thres, N=n)\n", "output_size" ] },