Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mapping_types-inl.h
Go to the documentation of this file.
1 
16 #pragma once
17 
18 namespace tc {
19 namespace polyhedral {
20 namespace mapping {
21 bool MappingId::isBlockId() {
22  return *this == BlockId::x() or *this == BlockId::y() or
23  *this == BlockId::z();
24 }
25 BlockId* MappingId::asBlockId() {
26  if (!isBlockId()) {
27  return nullptr;
28  }
29  return static_cast<BlockId*>(this);
30 }
31 bool MappingId::isThreadId() {
32  return *this == ThreadId::x() or *this == ThreadId::y() or
33  *this == ThreadId::z();
34 }
35 ThreadId* MappingId::asThreadId() {
36  if (!isThreadId()) {
37  return nullptr;
38  }
39  return static_cast<ThreadId*>(this);
40 }
41 
42 ThreadId ThreadId::makeId(size_t dim) {
43  CHECK(dim < 3);
44  if (dim == 0) {
45  return ThreadId::x();
46  }
47  if (dim == 1) {
48  return ThreadId::y();
49  }
50  return ThreadId::z();
51 }
52 template <unsigned char Dim>
53 ThreadId ThreadId::makeId(isl::id id) {
54  static_assert(Dim < kMaxDim, "Incorrect Dim >= kMaxDim");
55  return ThreadId(id, Dim);
56 }
57 ThreadId ThreadId::x() {
58  static thread_local isl::id x(
59  isl::with_exceptions::globalIslCtx(), std::string("t0"));
60  return makeId<0>(x);
61 }
62 ThreadId ThreadId::y() {
63  static thread_local isl::id y(
64  isl::with_exceptions::globalIslCtx(), std::string("t1"));
65  return makeId<1>(y);
66 }
67 ThreadId ThreadId::z() {
68  static thread_local isl::id z(
69  isl::with_exceptions::globalIslCtx(), std::string("t2"));
70  return makeId<2>(z);
71 }
72 
73 BlockId BlockId::makeId(size_t dim) {
74  CHECK(dim < 3);
75  if (dim == 0) {
76  return BlockId::x();
77  }
78  if (dim == 1) {
79  return BlockId::y();
80  }
81  return BlockId::z();
82 }
83 template <unsigned char Dim>
84 BlockId BlockId::makeId(isl::id id) {
85  static_assert(Dim < kMaxDim, "Incorrect Dim >= kMaxDim");
86  return BlockId(id, Dim);
87 }
88 BlockId BlockId::x() {
89  static thread_local isl::id x(
90  isl::with_exceptions::globalIslCtx(), std::string("b0"));
91  return makeId<0>(x);
92 }
93 BlockId BlockId::y() {
94  static thread_local isl::id y(
95  isl::with_exceptions::globalIslCtx(), std::string("b1"));
96  return makeId<1>(y);
97 }
98 BlockId BlockId::z() {
99  static thread_local isl::id z(
100  isl::with_exceptions::globalIslCtx(), std::string("b2"));
101  return makeId<2>(z);
102 }
103 } // namespace mapping
104 } // namespace polyhedral
105 } // namespace tc