def unparse_cr_split(sdfg, wcr_ast): """ Parses various types of WCR functions, returning a 2-tuple of body (in C++), and a list of arguments. """ if isinstance(wcr_ast, ast.Lambda): # Convert the lambda expression into a function that we can parse funcdef = LambdaToFunction().visit(wcr_ast) return unparse_cr_split(sdfg, funcdef) elif isinstance(wcr_ast, ast.FunctionDef): # Process data structure initializers sinit = StructInitializer(sdfg) body = [sinit.visit(stmt) for stmt in wcr_ast.body] # Construct a C++ lambda function out of a function args = [n.arg for n in wcr_ast.args.args] return cppunparse.cppunparse(body, expr_semicolon=False), args elif isinstance(wcr_ast, ast.Module): return unparse_cr_split(sdfg, wcr_ast.body[0].value) elif isinstance(wcr_ast, str): return unparse_cr_split(sdfg, LambdaProperty.from_string(wcr_ast)) else: raise NotImplementedError("INVALID TYPE OF WCR: " + type(wcr_ast).__name__)
def simple(data, subset_str, veclen=1, wcr_str=None, wcr_identity=None, other_subset_str=None, wcr_conflict=True, num_accesses=None, debuginfo=None): """ Constructs a Memlet from string-based expressions. @param data: The data object or name to access. B{Note:} this parameter will soon be deprecated. @type data: Either a string of the data descriptor name or an AccessNode. @param subset_str: The subset of `data` that is going to be accessed in string format. Example: '0:N'. @param veclen: The length of a single unit of access to the data (used for vectorization optimizations). @param wcr_str: A lambda function (as a string) specifying how write-conflicts are resolved. The syntax of the lambda function receives two elements: `current` value and `new` value, and returns the value after resolution. For example, summation is `'lambda cur, new: cur + new'`. @param wcr_identity: Identity value used for the first write conflict. B{Note:} this parameter will soon be deprecated. @param other_subset_str: The reindexing of `subset` on the other connected data (as a string). @param wcr_conflict: If False, forces non-locked conflict resolution when generating code. The default is to let the code generator infer this information from the SDFG. @param num_accesses: The number of times that the moved data will be subsequently accessed. If `dace.types.DYNAMIC` (-1), designates that the number of accesses is unknown at compile time. @param debuginfo: Source-code information (e.g., line, file) used for debugging. """ subset = SubsetProperty.from_string(subset_str) if num_accesses is not None: na = num_accesses else: na = subset.num_elements() if wcr_str is not None: wcr = LambdaProperty.from_string(wcr_str) else: wcr = None if other_subset_str is not None: other_subset = SubsetProperty.from_string(other_subset_str) else: other_subset = None # If it is an access node or another memlet if hasattr(data, 'data'): data = data.data return Memlet(data, na, subset, veclen, wcr=wcr, wcr_identity=wcr_identity, other_subset=other_subset, wcr_conflict=wcr_conflict, debuginfo=debuginfo)
def simple(data, subset_str, wcr_str=None, other_subset_str=None, wcr_conflict=True, num_accesses=None, debuginfo=None, dynamic=False): """ DEPRECATED: Constructs a Memlet from string-based expressions. :param data: The data object or name to access. :type data: Either a string of the data descriptor name or an AccessNode. :param subset_str: The subset of `data` that is going to be accessed in string format. Example: '0:N'. :param wcr_str: A lambda function (as a string) specifying how write-conflicts are resolved. The syntax of the lambda function receives two elements: `current` value and `new` value, and returns the value after resolution. For example, summation is `'lambda cur, new: cur + new'`. :param other_subset_str: The reindexing of `subset` on the other connected data (as a string). :param wcr_conflict: If False, forces non-locked conflict resolution when generating code. The default is to let the code generator infer this information from the SDFG. :param num_accesses: The number of times that the moved data will be subsequently accessed. If -1, designates that the number of accesses is unknown at compile time. :param debuginfo: Source-code information (e.g., line, file) used for debugging. :param dynamic: If True, the number of elements moved in this memlet is defined dynamically at runtime. """ # warnings.warn( # 'This function is deprecated, please use the Memlet ' # 'constructor instead', DeprecationWarning) result = Memlet() if isinstance(subset_str, subsets.Subset): result.subset = subset_str else: result.subset = SubsetProperty.from_string(subset_str) result.dynamic = dynamic if num_accesses is not None: if num_accesses == -1: result.dynamic = True result.volume = 0 else: result.volume = num_accesses else: result.volume = result._subset.num_elements() if wcr_str is not None: if isinstance(wcr_str, ast.AST): result.wcr = wcr_str else: result.wcr = LambdaProperty.from_string(wcr_str) if other_subset_str is not None: if isinstance(other_subset_str, subsets.Subset): result.other_subset = other_subset_str else: result.other_subset = SubsetProperty.from_string( other_subset_str) else: result.other_subset = None # If it is an access node or another memlet if hasattr(data, 'data'): result.data = data.data else: result.data = data result.wcr_nonatomic = not wcr_conflict return result