Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mapping_types.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 #include "tc/external/isl.h"
19 
20 namespace tc {
21 
22 struct Block;
23 struct Grid;
24 
25 namespace polyhedral {
26 namespace mapping {
27 
28 struct BlockId;
29 struct ThreadId;
30 
31 struct MappingId : public isl::id {
32  protected:
33  MappingId(isl::id i, unsigned char l) : isl::id(i), dim(l) {}
34 
35  public:
36  MappingId(const MappingId& id) : isl::id(id), dim(id.dim) {}
37 
38  inline bool isBlockId();
39  inline BlockId* asBlockId();
40 
41  inline bool isThreadId();
42  inline ThreadId* asThreadId();
43 
44  // For indexing into positional arrays
45  // TODO: this should go away but this probably requires tinkering with
46  // mapping_options.h::Grid/Block.
47  // Also, generally can't have fully static types and dynamic behavior
48  // like is used in mapped_scop.cc, so pick your poison:
49  // API bloat/templates or dynamic checks
50  const unsigned char dim;
51 
52  // Placeholder value to use in absence of mapping size.
53  static constexpr size_t unmapped = 1;
54 
55  struct Hash {
56  size_t operator()(const MappingId& id) const {
57  return isl::IslIdIslHash().operator()(id);
58  }
59  };
60 };
61 
62 // Note: do not add members to ThreadId or slicing will ensue.
63 // We use containers of MappingId. This makes sense because of isl::id
64 // semantics and the fact that a MappingId **isa** isl::id.
65 struct BlockId : public MappingId {
66  public:
67  inline BlockId(isl::id id, unsigned char l) : MappingId(id, l) {}
68  static inline BlockId makeId(size_t dim);
69  template <unsigned char Dim>
70  static BlockId makeId(isl::id id);
71 
72  static constexpr unsigned char kMaxDim = 3;
73 
74  static inline BlockId x();
75  static inline BlockId y();
76  static inline BlockId z();
77  /*
78  * Returns the size of the mapping or Mapping::unmapped if not mapped.
79  * This uses traditional internal assumptions that x<=>0, x<=>0, y<=>1, z<=>2.
80  */
81  size_t mappingSize(const tc::Grid& grid) const;
82 
83  struct Hash {
84  size_t operator()(const BlockId& id) const {
85  return isl::IslIdIslHash().operator()(id);
86  }
87  };
88 };
89 
90 // Note: do not add members to ThreadId or slicing will ensue.
91 // We use containers of MappingId. This makes sense because of isl::id
92 // semantics and the fact that a MappingId **isa** isl::id.
93 struct ThreadId : public MappingId {
94  public:
95  inline ThreadId(isl::id id, unsigned char l) : MappingId(id, l) {}
96  static inline ThreadId makeId(size_t dim);
97  template <unsigned char Dim>
98  static ThreadId makeId(isl::id id);
99 
100  static constexpr unsigned char kMaxDim = 3;
101 
102  static inline ThreadId x();
103  static inline ThreadId y();
104  static inline ThreadId z();
105  /*
106  * Returns the size of the mapping or Mapping::unmapped if not mapped.
107  * This uses traditional internal assumptions that x<=>0, y<=>1, z<=>2.
108  */
109  size_t mappingSize(const tc::Block& block) const;
110 
111  struct Hash {
112  size_t operator()(const ThreadId& id) const {
113  return isl::IslIdIslHash().operator()(id);
114  }
115  };
116 };
117 
118 #define USING_MAPPING_SHORT_NAMES(BX, BY, BZ, TX, TY, TZ) \
119  using namespace tc::polyhedral::mapping; \
120  auto BX = BlockId::x(); \
121  (void)BX; \
122  auto BY = BlockId::y(); \
123  (void)BY; \
124  auto BZ = BlockId::z(); \
125  (void)BZ; \
126  auto TX = ThreadId::x(); \
127  (void)TX; \
128  auto TY = ThreadId::y(); \
129  (void)TY; \
130  auto TZ = ThreadId::z(); \
131  (void)TZ;
132 } // namespace mapping
133 } // namespace polyhedral
134 } // namespace tc
135 
Specializing CudaDim to differentiate between Block and Grid sizes.
Definition: mapping_options.h:208
Specializing CudaDim to differentiate between Block and Grid sizes.
Definition: mapping_options.h:196
Definition: islpp.h:260