Example #1
0
    def _parse_memlet_from_str(self, expr: str):
        """
        Parses a memlet and fills in either the src_subset,dst_subset fields
        or the _data,_subset fields.
        :param expr: A string expression of the this memlet, given as an ease
                of use API. Must follow one of the following forms:
                1. ``ARRAY``,
                2. ``ARRAY[SUBSET]``,
                3. ``ARRAY[SUBSET] -> OTHER_SUBSET``.
                Note that modes 2 and 3 are deprecated and will leave 
                the memlet uninitialized until inserted into an SDFG.
        """
        expr = expr.strip()
        if '->' not in expr:  # Options 1 and 2
            self.data, self.subset = self._parse_from_subexpr(expr)
            return

        # Option 3
        src_expr, dst_expr = expr.split('->')
        src_expr = src_expr.strip()
        dst_expr = dst_expr.strip()
        if '[' not in src_expr and not dtypes.validate_name(src_expr):
            raise SyntaxError('Expression without data name not yet allowed')

        self.data, self.subset = self._parse_from_subexpr(src_expr)
        self.other_subset = SubsetProperty.from_string(dst_expr)
Example #2
0
    def _parse_from_subexpr(self, expr: str):
        if expr[-1] != ']':  # No subset given, try to use whole array
            if not dtypes.validate_name(expr):
                raise SyntaxError('Invalid memlet syntax "%s"' % expr)
            return expr, None

        # array[subset] syntax
        arrname, subset_str = expr[:-1].split('[')
        if not dtypes.validate_name(arrname):
            raise SyntaxError('Invalid array name "%s" in memlet' % arrname)
        return arrname, SubsetProperty.from_string(subset_str)
Example #3
0
    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)
Example #4
0
    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