Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 3d55faa

Browse files
Separate out MappingId
This changeset separates cuda-specific typed mapping ids on the path towards supporting multiple backends.
1 parent 0444be0 commit 3d55faa

File tree

5 files changed

+110
-59
lines changed

5 files changed

+110
-59
lines changed

include/tc/core/polyhedral/cuda/cuda_mapping_types-inl.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,6 @@
1818
namespace tc {
1919
namespace polyhedral {
2020
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-
4221
ThreadId ThreadId::makeId(size_t dim) {
4322
CHECK(dim < 3);
4423
if (dim == 0) {

include/tc/core/polyhedral/cuda/cuda_mapping_types.h

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,12 @@
1717

1818
#include "tc/external/isl.h"
1919

20-
namespace tc {
21-
22-
struct Block;
23-
struct Grid;
20+
#include "tc/core/polyhedral/mapping_types.h"
2421

22+
namespace tc {
2523
namespace polyhedral {
2624
namespace mapping {
2725

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-
6226
// Note: do not add members to ThreadId or slicing will ensue.
6327
// We use containers of MappingId. This makes sense because of isl::id
6428
// semantics and the fact that a MappingId **isa** isl::id.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright (c) 2017-present, Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
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+
bool isBlockId();
39+
BlockId* asBlockId();
40+
41+
bool isThreadId();
42+
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+
} // namespace mapping
62+
} // namespace polyhedral
63+
} // namespace tc

src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_library(
1616

1717
polyhedral/codegen.cc
1818
polyhedral/mapped_scop.cc
19+
polyhedral/mapping_types.cc
1920
polyhedral/memory_promotion.cc
2021
polyhedral/memory_promotion_heuristic.cc
2122
polyhedral/reduction_matcher.cc

src/core/polyhedral/mapping_types.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2017-present, Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "tc/core/polyhedral/mapping_types.h"
17+
#include "tc/core/polyhedral/cuda/cuda_mapping_types.h"
18+
19+
namespace tc {
20+
namespace polyhedral {
21+
namespace mapping {
22+
bool MappingId::isBlockId() {
23+
return *this == BlockId::x() or *this == BlockId::y() or
24+
*this == BlockId::z();
25+
}
26+
BlockId* MappingId::asBlockId() {
27+
if (!isBlockId()) {
28+
return nullptr;
29+
}
30+
return static_cast<BlockId*>(this);
31+
}
32+
bool MappingId::isThreadId() {
33+
return *this == ThreadId::x() or *this == ThreadId::y() or
34+
*this == ThreadId::z();
35+
}
36+
ThreadId* MappingId::asThreadId() {
37+
if (!isThreadId()) {
38+
return nullptr;
39+
}
40+
return static_cast<ThreadId*>(this);
41+
}
42+
} // namespace mapping
43+
} // namespace polyhedral
44+
} // namespace tc

0 commit comments

Comments
 (0)