Skip to content

Commit 1032cd2

Browse files
authored
Merge pull request #478 from inducer/map-domain-transformation-v2
Map domain transformation v2
2 parents 73098bb + 19a3802 commit 1032cd2

File tree

4 files changed

+893
-2
lines changed

4 files changed

+893
-2
lines changed

loopy/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
affine_map_inames, find_unused_axis_tag,
7777
make_reduction_inames_unique,
7878
has_schedulable_iname_nesting, get_iname_duplication_options,
79-
add_inames_to_insn, add_inames_for_unused_hw_axes)
79+
add_inames_to_insn, add_inames_for_unused_hw_axes, map_domain)
8080

8181
from loopy.transform.instruction import (
8282
find_instructions, map_instructions,
@@ -202,7 +202,7 @@
202202
"affine_map_inames", "find_unused_axis_tag",
203203
"make_reduction_inames_unique",
204204
"has_schedulable_iname_nesting", "get_iname_duplication_options",
205-
"add_inames_to_insn", "add_inames_for_unused_hw_axes",
205+
"add_inames_to_insn", "add_inames_for_unused_hw_axes", "map_domain",
206206

207207
"add_prefetch", "change_arg_to_image",
208208
"tag_array_axes", "tag_data_axes",

loopy/isl_helpers.py

+83
Original file line numberDiff line numberDiff line change
@@ -767,4 +767,87 @@ def subst_into_pwaff(new_space, pwaff, subst_dict):
767767

768768
# }}}
769769

770+
771+
# {{{ add_and_name_dims
772+
773+
def add_and_name_dims(isl_obj, dt, names):
774+
"""Append dimensions of the specified dimension type to the provided ISL
775+
object, and set their names.
776+
777+
:arg isl_obj: An :class:`islpy.Set` or :class:`islpy.Map` to which
778+
new dimensions will be added.
779+
780+
:arg dt: An :class:`islpy.dim_type`, i.e., an :class:`int`, specifying the
781+
dimension type for the new dimensions.
782+
783+
:arg names: An iterable of :class:`str` values specifying the names of the
784+
new dimensions to be added.
785+
786+
:returns: An object of the same type as *isl_obj* with the new dimensions
787+
added and named.
788+
789+
"""
790+
791+
new_idx_start = isl_obj.dim(dt)
792+
isl_obj = isl_obj.add_dims(dt, len(names))
793+
for i, name in enumerate(names):
794+
isl_obj = isl_obj.set_dim_name(dt, new_idx_start+i, name)
795+
return isl_obj
796+
797+
# }}}
798+
799+
800+
# {{{ add_eq_constraint_from_names
801+
802+
def add_eq_constraint_from_names(isl_obj, var1, var2):
803+
"""Add constraint *var1* = *var2* to an ISL object.
804+
805+
:arg isl_obj: An :class:`islpy.Set` or :class:`islpy.Map` to which
806+
a new constraint will be added.
807+
808+
:arg var1: A :class:`str` specifying the name of the first variable
809+
involved in constraint *var1* = *var2*.
810+
811+
:arg var2: A :class:`str` specifying the name of the second variable
812+
involved in constraint *var1* = *var2*.
813+
814+
:returns: An object of the same type as *isl_obj* with the constraint
815+
*var1* = *var2*.
816+
817+
"""
818+
return isl_obj.add_constraint(
819+
isl.Constraint.eq_from_names(
820+
isl_obj.space,
821+
{1: 0, var1: 1, var2: -1}))
822+
823+
# }}}
824+
825+
826+
# {{{ find_and_rename_dim
827+
828+
def find_and_rename_dim(isl_obj, dt, old_name, new_name):
829+
"""Rename a dimension in an ISL object.
830+
831+
:arg isl_obj: An :class:`islpy.Set` or :class:`islpy.Map` containing the
832+
dimension to be renamed.
833+
834+
:arg dt: An :class:`islpy.dim_type` (i.e., :class:`int`) specifying the
835+
dimension type containing the dimension to be renamed.
836+
837+
:arg old_name: A :class:`str` specifying the name of the dimension to be
838+
renamed.
839+
840+
:arg new_name: A :class:`str` specifying the new name of the dimension to
841+
be renamed.
842+
843+
:returns: An object of the same type as *isl_obj* with the dimension
844+
*old_name* renamed to *new_name*.
845+
846+
"""
847+
return isl_obj.set_dim_name(
848+
dt, isl_obj.find_dim_by_name(dt, old_name), new_name)
849+
850+
# }}}
851+
852+
770853
# vim: foldmethod=marker

0 commit comments

Comments
 (0)