Skip to content

Commit c2f7099

Browse files
committed
Merge branch 'main' into jcoplin-quic/clip
2 parents 25d89df + ed9a992 commit c2f7099

File tree

30 files changed

+378
-169
lines changed

30 files changed

+378
-169
lines changed

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/cpp_rpc/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ void ParseCmdArgs(int argc, char* argv[], struct RpcServerArgs& args) {
201201
args.port = stoi(port);
202202
}
203203

204-
const string port_end = GetCmdOption(argc, argv, "--port_end=");
204+
const string port_end = GetCmdOption(argc, argv, "--port-end=");
205205
if (!port_end.empty()) {
206206
if (!IsNumber(port_end) || stoi(port_end) > 65535) {
207-
LOG(WARNING) << "Wrong port_end number.";
207+
LOG(WARNING) << "Wrong port-end number.";
208208
LOG(INFO) << kUsage;
209209
exit(1);
210210
}
@@ -226,7 +226,7 @@ void ParseCmdArgs(int argc, char* argv[], struct RpcServerArgs& args) {
226226
args.key = key;
227227
}
228228

229-
const string custom_addr = GetCmdOption(argc, argv, "--custom_addr=");
229+
const string custom_addr = GetCmdOption(argc, argv, "--custom-addr=");
230230
if (!custom_addr.empty()) {
231231
if (!ValidateIP(custom_addr)) {
232232
LOG(WARNING) << "Wrong custom address format.";

apps/microtvm/reference-vm/base-box-tool.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"docker/install/ubuntu_install_core.sh",
5858
"docker/install/ubuntu_install_python.sh",
5959
"docker/utils/apt-install-and-clear.sh",
60+
"docker/install/ubuntu1804_install_llvm.sh",
6061
]
6162

6263
EXTRA_SCRIPTS = {
@@ -360,6 +361,9 @@ def do_build_release_test_vm(
360361
found_box_line = False
361362
with open(release_test_vagrantfile, "w") as f:
362363
for line in lines:
364+
# Skip setting version
365+
if "config.vm.box_version" in line:
366+
continue
363367
m = VM_BOX_RE.match(line)
364368
if not m:
365369
f.write(line)

apps/microtvm/reference-vm/base_box_setup_common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ rm -f ~/ubuntu_install_python.sh
5353
sudo apt-install-and-clear -y python3-venv
5454

5555
# TVM deps
56-
# TODO(mehrdadh): replace with ubuntu_install_llvm.sh
57-
sudo apt-install-and-clear -y llvm
56+
sudo ~/ubuntu1804_install_llvm.sh
57+
rm -rf ~/ubuntu1804_install_llvm.sh
5858

5959
# ONNX deps
6060
sudo apt-install-and-clear -y protobuf-compiler libprotoc-dev

apps/microtvm/reference-vm/rebuild-tvm.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ BUILD_DIR="build-microtvm-${platform}"
4444
if [ ! -e "${BUILD_DIR}" ]; then
4545
mkdir "${BUILD_DIR}"
4646
fi
47-
cp cmake/config.cmake "${BUILD_DIR}"
47+
48+
./tests/scripts/task_config_build_qemu.sh "${BUILD_DIR}"
4849
cd "${BUILD_DIR}"
49-
sed -i 's/USE_MICRO OFF/USE_MICRO ON/' config.cmake
50-
sed -i 's/USE_GRAPH_EXECUTOR_DEBUG OFF/USE_GRAPH_EXECUTOR_DEBUG ON/' config.cmake
51-
sed -i 's/USE_LLVM OFF/USE_LLVM ON/' config.cmake
5250
cmake ..
5351
rm -rf standalone_crt host_standalone_crt # remove stale generated files
5452
make -j${num_cores}

gallery/how_to/work_with_microtvm/micro_train.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,20 @@
165165
import urllib.request
166166

167167
# Download datasets
168+
os.makedirs(f"{FOLDER}/downloads")
168169
os.makedirs(f"{FOLDER}/images")
169170
urllib.request.urlretrieve(
170-
"http://ai.stanford.edu/~jkrause/car196/cars_train.tgz", f"{FOLDER}/images/target.tgz"
171+
"https://data.deepai.org/stanfordcars.zip", f"{FOLDER}/downloads/target.zip"
171172
)
172173
urllib.request.urlretrieve(
173-
"http://images.cocodataset.org/zips/val2017.zip", f"{FOLDER}/images/random.zip"
174+
"http://images.cocodataset.org/zips/val2017.zip", f"{FOLDER}/downloads/random.zip"
174175
)
175176

176177
# Extract them and rename their folders
177-
shutil.unpack_archive(f"{FOLDER}/images/target.tgz", f"{FOLDER}/images")
178-
shutil.unpack_archive(f"{FOLDER}/images/random.zip", f"{FOLDER}/images")
179-
shutil.move(f"{FOLDER}/images/cars_train", f"{FOLDER}/images/target")
180-
shutil.move(f"{FOLDER}/images/val2017", f"{FOLDER}/images/random")
178+
shutil.unpack_archive(f"{FOLDER}/downloads/target.zip", f"{FOLDER}/downloads")
179+
shutil.unpack_archive(f"{FOLDER}/downloads/random.zip", f"{FOLDER}/downloads")
180+
shutil.move(f"{FOLDER}/downloads/cars_train/cars_train", f"{FOLDER}/images/target")
181+
shutil.move(f"{FOLDER}/downloads/val2017", f"{FOLDER}/images/random")
181182

182183
######################################################################
183184
# Loading the Data

include/tvm/relay/attrs/nn.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ struct Conv2DAttrs : public tvm::AttrsNode<Conv2DAttrs> {
124124
tvm::String data_layout;
125125
tvm::String kernel_layout;
126126
tvm::String out_layout;
127-
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
127+
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
128+
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
128129
DataType out_dtype;
129130

130131
TVM_DECLARE_ATTRS(Conv2DAttrs, "relay.attrs.Conv2DAttrs") {
@@ -217,7 +218,8 @@ struct Conv2DWinogradAttrs : public tvm::AttrsNode<Conv2DWinogradAttrs> {
217218
tvm::String data_layout;
218219
tvm::String kernel_layout;
219220
tvm::String out_layout;
220-
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
221+
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
222+
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
221223
DataType out_dtype;
222224

223225
TVM_DECLARE_ATTRS(Conv2DWinogradAttrs, "relay.attrs.Conv2DWinogradAttrs") {
@@ -308,7 +310,8 @@ struct Conv3DAttrs : public tvm::AttrsNode<Conv3DAttrs> {
308310
tvm::String data_layout;
309311
tvm::String kernel_layout;
310312
tvm::String out_layout;
311-
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
313+
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
314+
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
312315
DataType out_dtype;
313316

314317
TVM_DECLARE_ATTRS(Conv3DAttrs, "relay.attrs.Conv3DAttrs") {
@@ -1049,7 +1052,8 @@ struct MatmulAttrs : public tvm::AttrsNode<MatmulAttrs> {
10491052
DataType out_dtype;
10501053
bool transpose_a;
10511054
bool transpose_b;
1052-
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
1055+
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
1056+
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
10531057

10541058
TVM_DECLARE_ATTRS(MatmulAttrs, "relay.attrs.MatmulAttrs") {
10551059
TVM_ATTR_FIELD(units).describe("Number of hidden units of the dense transformation.");
@@ -1072,7 +1076,8 @@ struct MatmulAttrs : public tvm::AttrsNode<MatmulAttrs> {
10721076
/*! \brief Attributes for dense operator */
10731077
struct DenseAttrs : public tvm::AttrsNode<DenseAttrs> {
10741078
IndexExpr units;
1075-
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
1079+
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
1080+
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
10761081
DataType out_dtype;
10771082

10781083
TVM_DECLARE_ATTRS(DenseAttrs, "relay.attrs.DenseAttrs") {
@@ -1109,7 +1114,8 @@ struct BatchMatmulAttrs : public tvm::AttrsNode<BatchMatmulAttrs> {
11091114
DataType out_dtype;
11101115
bool transpose_a;
11111116
bool transpose_b;
1112-
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
1117+
tvm::String auto_scheduler_rewritten_layout; // The layout after auto-scheduler's layout rewrite
1118+
Array<PrimExpr> meta_schedule_original_shape; // The original shape of the weights
11131119

11141120
TVM_DECLARE_ATTRS(BatchMatmulAttrs, "relay.attrs.BatchMatmulAttrs") {
11151121
// use 0 bits to indicate none.

include/tvm/relay/attrs/transform.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <tvm/ir/attrs.h>
2828
#include <tvm/relay/base.h>
2929
#include <tvm/relay/expr.h>
30+
#include <tvm/tir/index_map.h>
3031

3132
#include <string>
3233

@@ -429,6 +430,22 @@ struct AutoSchedulerLayoutTransformAttrs
429430
}
430431
};
431432

433+
/*! \brief Attributes for MetaScheduleLayoutTransform operator */
434+
struct MetaScheduleLayoutTransformAttrs : public tvm::AttrsNode<MetaScheduleLayoutTransformAttrs> {
435+
tir::IndexMap index_map;
436+
437+
TVM_DECLARE_ATTRS(MetaScheduleLayoutTransformAttrs,
438+
"relay.attrs.MetaScheduleLayoutTransformAttrs") {
439+
TVM_ATTR_FIELD(index_map).describe(
440+
"The order of the extents, for example, "
441+
"let extents = [2, 3, 4], reorder = [0, 2, 1], and the shape of buffer A is (4, 6)"
442+
"then A[i, j] will be first rewritten to "
443+
"A[(6 * i + j) / 12, (6 * i + j) / 4 % 3 , (6 * i + j) % 4] according to the `extents`,"
444+
"and then reordered to A[(6 * i + j) / 12, (6 * i + j) % 4 , (6 * i + j) / 4 % 3]"
445+
"according to `reorder`");
446+
}
447+
};
448+
432449
/*! \brief Attributes for ShapeOf operator */
433450
struct ShapeOfAttrs : public tvm::AttrsNode<ShapeOfAttrs> {
434451
DataType dtype;

include/tvm/tir/index_map.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,19 @@ class IndexMapNode : public Object {
135135
v->Visit("final_indices", &final_indices);
136136
}
137137

138-
static constexpr const char* _type_key = "tir.IndexMap";
138+
bool SEqualReduce(const IndexMapNode* other, SEqualReducer equal) const {
139+
return equal.DefEqual(initial_indices, other->initial_indices) &&
140+
equal(final_indices, other->final_indices);
141+
}
139142

143+
void SHashReduce(SHashReducer hash_reduce) const {
144+
hash_reduce.DefHash(initial_indices);
145+
hash_reduce(final_indices);
146+
}
147+
148+
static constexpr const char* _type_key = "tir.IndexMap";
149+
static constexpr const bool _type_has_method_sequal_reduce = true;
150+
static constexpr const bool _type_has_method_shash_reduce = true;
140151
TVM_DECLARE_FINAL_OBJECT_INFO(IndexMapNode, Object);
141152
};
142153

include/tvm/topi/transform.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <tvm/te/operation.h>
2828
#include <tvm/tir/data_layout.h>
29+
#include <tvm/tir/index_map.h>
2930
#include <tvm/topi/broadcast.h>
3031
#include <tvm/topi/detail/broadcast.h>
3132
#include <tvm/topi/detail/constant_utils.h>
@@ -1693,6 +1694,59 @@ inline Tensor auto_scheduler_layout_transform(const Tensor& src, const String& s
16931694
name, tag);
16941695
}
16951696

1697+
/*!
1698+
* \brief Transform the meta-schedule generated layout according to TIR's IndexMap
1699+
* \param src the source input.
1700+
* \param index_map The TIR IndexMap
1701+
* \param name output tensor name.
1702+
* \param tag output tensor tag.
1703+
* \return A tensor. The layout transformation method
1704+
* \note Example:
1705+
*
1706+
* For the indexing pattern below:
1707+
*
1708+
* for i in range(32):
1709+
* for j in range(64):
1710+
* load A[
1711+
* i / 16 * 4 + j / 16,
1712+
* i % 16 * 16 + j % 16,
1713+
* ]
1714+
*
1715+
* The corresponding indexing pattern in TIR is:
1716+
*
1717+
* A[i, j] => A'[i / 4, j / 16, i % 4, j % 16]
1718+
*
1719+
* which converts the pattern to:
1720+
*
1721+
* for i in range(32):
1722+
* for j in range(64):
1723+
* load A'[
1724+
* i / 16 + j / 64,
1725+
* i % 16,
1726+
* j % 64 / 16,
1727+
* j % 16,
1728+
* ]
1729+
*
1730+
* In this case, the transformation pattern is:
1731+
* A'[a, b, c, d] = A[a * 4 + c, b * 16 + d]
1732+
*/
1733+
inline Tensor meta_schedule_layout_transform(const Tensor& src, const tir::IndexMap& index_map,
1734+
const String name = "T_meta_schedule_layout_trans",
1735+
const String tag = kInjective) {
1736+
Array<Range> iter_domain;
1737+
iter_domain.reserve(src->shape.size());
1738+
for (const PrimExpr& e : src->shape) {
1739+
iter_domain.push_back(Range::FromMinExtent(make_zero(e->dtype), e));
1740+
}
1741+
Array<PrimExpr> post_transform_shape = index_map->MapShape(src->shape);
1742+
return compute(
1743+
post_transform_shape,
1744+
[src, inv = index_map.Inverse(iter_domain)](const Array<Var>& indices) -> PrimExpr {
1745+
return src(inv->MapIndices(Array<PrimExpr>{indices.begin(), indices.end()}));
1746+
},
1747+
name, tag);
1748+
}
1749+
16961750
/*!
16971751
* \brief Get the shape of input tensor.
16981752
* \param src the input tensor.

0 commit comments

Comments
 (0)