This class describes the possible set of representations (i.e. TensorRepr) that may be used to represent a tensor. This set is determined by the implementation of the operator that the tensor participates in as well as the texture extents of the GPU.
| 863 | |
| 864 | |
| 865 | class TensorRepSet: |
| 866 | """ |
| 867 | This class describes the possible set of representations (i.e. TensorRepr) that may |
| 868 | be used to represent a tensor. This set is determined by the implementation of the |
| 869 | operator that the tensor participates in as well as the texture extents of the GPU. |
| 870 | """ |
| 871 | |
| 872 | def __init__( |
| 873 | self, |
| 874 | buffer_memory_layouts: Set[VkMemoryLayout], |
| 875 | texture_memory_layouts: Set[VkMemoryLayout], |
| 876 | ): |
| 877 | self.valid_buffer_layouts = buffer_memory_layouts |
| 878 | self.valid_texture_layouts = texture_memory_layouts |
| 879 | |
| 880 | def __str__(self) -> str: |
| 881 | buffer_layouts = ", ".join(layout.name for layout in self.valid_buffer_layouts) |
| 882 | texture_layouts = ", ".join( |
| 883 | layout.name for layout in self.valid_texture_layouts |
| 884 | ) |
| 885 | return f"TensorRepSet(Buffer Layouts: [{buffer_layouts}], Texture Layouts: [{texture_layouts}])" |
| 886 | |
| 887 | def __eq__(self, other: object) -> bool: |
| 888 | if not isinstance(other, TensorRepSet): |
| 889 | return NotImplemented |
| 890 | return ( |
| 891 | self.valid_buffer_layouts == other.valid_buffer_layouts |
| 892 | and self.valid_texture_layouts == other.valid_texture_layouts |
| 893 | ) |
| 894 | |
| 895 | def __ne__(self, other: object) -> bool: |
| 896 | return not self.__eq__(other) |
| 897 | |
| 898 | def copy(self) -> "TensorRepSet": |
| 899 | return TensorRepSet( |
| 900 | set(self.valid_buffer_layouts), set(self.valid_texture_layouts) |
| 901 | ) |
| 902 | |
| 903 | def is_empty(self) -> bool: |
| 904 | """ |
| 905 | A TensorRepSet is "empty" if there are no valid representations of the tensor. |
| 906 | """ |
| 907 | return ( |
| 908 | len(self.valid_buffer_layouts) == 0 and len(self.valid_texture_layouts) == 0 |
| 909 | ) |
| 910 | |
| 911 | def make_intersect(self, other: "TensorRepSet") -> "TensorRepSet": |
| 912 | """ |
| 913 | Merge this TensorRepr with another TensorRepr, returning a new TensorRepr |
| 914 | with the intersection of the two. |
| 915 | """ |
| 916 | return TensorRepSet( |
| 917 | self.valid_buffer_layouts & other.valid_buffer_layouts, |
| 918 | self.valid_texture_layouts & other.valid_texture_layouts, |
| 919 | ) |
| 920 | |
| 921 | def make_union(self, other: "TensorRepSet") -> "TensorRepSet": |
| 922 | """ |
no outgoing calls