def __setstate__(self, val): super(InstructionBase, self).__setstate__(val) from loopy.tools import intern_frozenset_of_ids if self.id is not None: self.id = intern(self.id) self.depends_on = intern_frozenset_of_ids(self.depends_on) self.groups = intern_frozenset_of_ids(self.groups) self.conflicts_with_groups = (intern_frozenset_of_ids( self.conflicts_with_groups)) self.within_inames = (intern_frozenset_of_ids(self.within_inames))
def __setstate__(self, val): super(InstructionBase, self).__setstate__(val) from loopy.tools import intern_frozenset_of_ids if self.id is not None: # pylint:disable=access-member-before-definition self.id = intern(self.id) self.depends_on = intern_frozenset_of_ids(self.depends_on) self.groups = intern_frozenset_of_ids(self.groups) self.conflicts_with_groups = ( intern_frozenset_of_ids(self.conflicts_with_groups)) self.within_inames = ( intern_frozenset_of_ids(self.within_inames))
def __setstate__(self, val): super().__setstate__(val) from loopy.tools import intern_frozenset_of_ids if self.id is not None: # pylint:disable=access-member-before-definition self.id = intern(self.id) self.depends_on = intern_frozenset_of_ids(self.depends_on) self.groups = intern_frozenset_of_ids(self.groups) self.conflicts_with_groups = ( intern_frozenset_of_ids(self.conflicts_with_groups)) self.within_inames = ( intern_frozenset_of_ids(self.within_inames))
def __setstate__(self, val): super(InstructionBase, self).__setstate__(val) from loopy.tools import intern_frozenset_of_ids self.id = intern(self.id) self.insn_deps = intern_frozenset_of_ids(self.insn_deps) self.groups = intern_frozenset_of_ids(self.groups) self.conflicts_with_groups = ( intern_frozenset_of_ids(self.conflicts_with_groups)) self.forced_iname_deps = ( intern_frozenset_of_ids(self.forced_iname_deps)) self.predicates = ( intern_frozenset_of_ids(self.predicates))
def all_params(self): all_inames = self.all_inames() result = set() for dom in self.domains: result.update(set(dom.get_var_names(dim_type.param)) - all_inames) from loopy.tools import intern_frozenset_of_ids return intern_frozenset_of_ids(result)
def outer_params(self, domains=None): if domains is None: domains = self.domains all_inames = set() all_params = set() for dom in domains: all_inames.update(dom.get_var_names(dim_type.set)) all_params.update(dom.get_var_names(dim_type.param)) from loopy.tools import intern_frozenset_of_ids return intern_frozenset_of_ids(all_params-all_inames)
def outer_params(self, domains=None): if domains is None: domains = self.domains all_inames = set() all_params = set() for dom in domains: all_inames.update(dom.get_var_names(dim_type.set)) all_params.update(dom.get_var_names(dim_type.param)) from loopy.tools import intern_frozenset_of_ids return intern_frozenset_of_ids(all_params - all_inames)
def parse_insn(insn): """ :return: a tuple ``(insn, inames_to_dup)``, where insn is a :class:`Assignment` or a :class:`SubstitutionRule` and *inames_to_dup* is None or a list of tuples `(old, new)`. """ insn_match = INSN_RE.match(insn) subst_match = SUBST_RE.match(insn) if insn_match is not None and subst_match is not None: raise RuntimeError("instruction parse error: %s" % insn) if insn_match is not None: groups = insn_match.groupdict() elif subst_match is not None: groups = subst_match.groupdict() else: raise RuntimeError("instruction parse error at '%s'" % insn) from loopy.symbolic import parse try: lhs = parse(groups["lhs"]) except: print("While parsing left hand side '%s', " "the following error occurred:" % groups["lhs"]) raise try: rhs = parse(groups["rhs"]) except: print("While parsing right hand side '%s', " "the following error occurred:" % groups["rhs"]) raise if insn_match is not None: insn_deps = None insn_deps_is_final = False insn_groups = None conflicts_with_groups = None insn_id = None inames_to_dup = [] priority = 0 forced_iname_deps_is_final = False forced_iname_deps = frozenset() predicates = frozenset() tags = () if groups["options"] is not None: for option in groups["options"].split(","): option = option.strip() if not option: raise RuntimeError("empty option supplied") equal_idx = option.find("=") if equal_idx == -1: opt_key = option opt_value = None else: opt_key = option[:equal_idx].strip() opt_value = option[equal_idx+1:].strip() if opt_key == "id": insn_id = intern(opt_value) elif opt_key == "id_prefix": insn_id = UniqueName(opt_value) elif opt_key == "priority": priority = int(opt_value) elif opt_key == "dup": for value in opt_value.split(":"): arrow_idx = value.find("->") if arrow_idx >= 0: inames_to_dup.append( (value[:arrow_idx], value[arrow_idx+2:])) else: inames_to_dup.append((value, None)) elif opt_key == "dep": if opt_value.startswith("*"): insn_deps_is_final = True opt_value = (opt_value[1:]).strip() insn_deps = frozenset( intern(dep.strip()) for dep in opt_value.split(":") if dep.strip()) elif opt_key == "groups": insn_groups = frozenset( intern(grp.strip()) for grp in opt_value.split(":") if grp.strip()) elif opt_key == "conflicts": conflicts_with_groups = frozenset( intern(grp.strip()) for grp in opt_value.split(":") if grp.strip()) elif opt_key == "inames": if opt_value.startswith("+"): forced_iname_deps_is_final = False opt_value = (opt_value[1:]).strip() else: forced_iname_deps_is_final = True forced_iname_deps = intern_frozenset_of_ids(opt_value.split(":")) elif opt_key == "if": predicates = intern_frozenset_of_ids(opt_value.split(":")) elif opt_key == "tags": tags = tuple( tag.strip() for tag in opt_value.split(":") if tag.strip()) else: raise ValueError("unrecognized instruction option '%s'" % opt_key) if groups["temp_var_type"] is not None: if groups["temp_var_type"]: temp_var_type = np.dtype(groups["temp_var_type"]) else: import loopy as lp temp_var_type = lp.auto else: temp_var_type = None from pymbolic.primitives import Variable, Subscript if not isinstance(lhs, (Variable, Subscript)): raise RuntimeError("left hand side of assignment '%s' must " "be variable or subscript" % lhs) return Assignment( id=( intern(insn_id) if isinstance(insn_id, str) else insn_id), insn_deps=insn_deps, insn_deps_is_final=insn_deps_is_final, groups=insn_groups, conflicts_with_groups=conflicts_with_groups, forced_iname_deps_is_final=forced_iname_deps_is_final, forced_iname_deps=forced_iname_deps, assignee=lhs, expression=rhs, temp_var_type=temp_var_type, priority=priority, predicates=predicates, tags=tags), inames_to_dup elif subst_match is not None: from pymbolic.primitives import Variable, Call if isinstance(lhs, Variable): subst_name = lhs.name arg_names = [] elif isinstance(lhs, Call): if not isinstance(lhs.function, Variable): raise RuntimeError("Invalid substitution rule left-hand side") subst_name = lhs.function.name arg_names = [] for i, arg in enumerate(lhs.parameters): if not isinstance(arg, Variable): raise RuntimeError("Invalid substitution rule " "left-hand side: %s--arg number %d " "is not a variable" % (lhs, i)) arg_names.append(arg.name) else: raise RuntimeError("Invalid substitution rule left-hand side") return SubstitutionRule( name=subst_name, arguments=tuple(arg_names), expression=rhs), []