Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
70d80cc
[Unity] Relax VM (#13878)
YuchenJin Feb 1, 2023
25e6174
[Unity] Relax expressions and types (#13901)
YuchenJin Feb 2, 2023
51cf110
[Unity][IR] First-class StructInfo (#13907)
YuchenJin Feb 3, 2023
40c4310
[Unity][CI] Unity specific jenkins setup (do not upstream to main) (#…
tqchen Feb 3, 2023
e68ef58
[Unity] Basic StructInfo Analysis and Expr construction (#13916)
YuchenJin Feb 5, 2023
aa59d86
[Unity] Relax BlockBuilder and ExprMutator (#13926)
YuchenJin Feb 7, 2023
540ba28
[Unity] Relax TVMScript Parser. (#13932)
Feb 8, 2023
334fd8b
[Unity] Relax TVMScript Printer (#13944)
junrushao Feb 10, 2023
574084d
[Unity] Relax VM codegen (#13954)
YuchenJin Feb 11, 2023
518a7bd
[Unity] Relax VM shape lowering pass (#13956)
YuchenJin Feb 11, 2023
b3d913a
[Unity] e2e Relax minimum build flow (#13961)
YuchenJin Feb 11, 2023
caad7cd
[Unity][TVMScript] Use explicit `R.shape` in TVMScript (#13979)
Feb 14, 2023
903628f
[Unity] Relax op: index (#13987)
MasterJH5574 Feb 14, 2023
0319939
[Unity] Relax op: datatype (#13986)
MasterJH5574 Feb 14, 2023
11e5e1d
[Unity] Relax op: set (#13990)
MasterJH5574 Feb 14, 2023
1280422
[Unity] Relax op: image (#13994)
MasterJH5574 Feb 14, 2023
64f2817
[Unity] Relax op: arithmetic, comparison (#13983)
MasterJH5574 Feb 14, 2023
be4373a
[Unity] Relax op: statistical (#13991)
MasterJH5574 Feb 14, 2023
fa3cfbd
[Unity] Relax op: neural networks (#13993)
MasterJH5574 Feb 14, 2023
45e6d0b
[Unity] Relax op: creation (#13984)
MasterJH5574 Feb 14, 2023
206762f
[Unity] Relax op: linear algebra (#13988)
MasterJH5574 Feb 14, 2023
088afc5
[Unity] Relax op: search (#13992)
MasterJH5574 Feb 14, 2023
4430d26
[Unity] Relax op: manipulation (#13989)
MasterJH5574 Feb 14, 2023
471ff84
[Unity] NestedMsg Support utility (#13995)
tqchen Feb 14, 2023
604754a
[Unity][Pass] Operator Fusion Passes (#14001)
Feb 15, 2023
50f616c
[Unity][Pass] LambdaLift pass (#14012)
yongwww Feb 16, 2023
0a0166e
[Unity][VM] Supporting "compiled" exec mode. (#14015)
tqchen Feb 17, 2023
660a1f3
[Unity][Pass] BindParams pass, FoldConstant pass (#14016)
sunggg Feb 17, 2023
30a5669
[Unity][Pass][TuningAPI] Introduce TuningAPI and MetaSchedule pass (#…
sunggg Feb 17, 2023
b792751
[Unity] Relay -> Relax translator (#14026)
YuchenJin Feb 17, 2023
554e609
[Unity][Pass] Normalize Pass (#14031)
LeshengJin Feb 18, 2023
477d011
[Unity][BlockBuilder] CallTE convert PrimValue args (#14028)
MasterJH5574 Feb 18, 2023
f61c330
[Unity][Pass] Wellformed Analysis (#14032)
LeshengJin Feb 18, 2023
4df587a
[Unity][TVMScript] Move tir/relax import in script out of __init__.py…
MasterJH5574 Feb 18, 2023
d2b8ea3
[Unity][Pass] Operator legalization (#14029)
MasterJH5574 Feb 18, 2023
e0c6ca0
[Unity][Op] Add ShapeExpr Tests for Reshape Op (#14035)
Ubospica Feb 18, 2023
e15f59b
[Unity] Initial PyTorch Frontend (#14037)
MasterJH5574 Feb 18, 2023
e8ebd68
[Unity][Pass] Block-level static memory planning (#14038)
MasterJH5574 Feb 18, 2023
2e1d851
[Unity] Disallow inline prim_func in relax IR (#14040)
yongwww Feb 18, 2023
60d3796
[Unity] Update tests to adapt to latest TVMScript syntax (#14039)
MasterJH5574 Feb 18, 2023
7d70af3
[Unity] Relax dataflow pattern language (matching) (#14041)
ganler Feb 18, 2023
44b05d6
[Unity] Statement rewriter for DataflowBlock (#14043)
ganler Feb 19, 2023
7a71e53
[Unity][Pass] FuseOps FuseTIR fixes (#14044)
MasterJH5574 Feb 19, 2023
e7cc287
[Unity][TVMScript] Overload `__neg__` for relax expr (#14045)
SiriusNEO Feb 19, 2023
5239022
[Unity][VM] Add per-op profiling support (#14053)
masahi Feb 20, 2023
38178a3
[Unity][BYOC] Add pattern-based partitioning pass (#14054)
masahi Feb 20, 2023
a7e936f
[Unity] Relax op: collapse sum (#14059)
SiriusNEO Feb 21, 2023
7ce0a51
[Unity][Fix][Pass] Fix FuseOps for lack graph edges (#14058)
MasterJH5574 Feb 21, 2023
34d5944
[Unity][Pass] Remove Unused Function (#14061)
sunggg Feb 21, 2023
2c5ccfa
[Unity][BYOC] Add pass to merge composite functions to offload large …
masahi Feb 21, 2023
7f5f816
[Unity][Frontend] Annotate number of non-static input of FX function …
vinx13 Feb 21, 2023
73fe88d
[Unity][Transform] Add LiftTransformParams pass (#14069)
vinx13 Feb 21, 2023
b137d22
[Unity][BYOC][Pass] RunCodegen and TensorRT (#14078)
sunggg Feb 22, 2023
38f920d
[Unity][Pass] Canonicalize Bindings (#14079)
YuchenJin Feb 22, 2023
2a51dca
[Unity] Add testcases for `expr_args_converter` (#14080)
Feb 22, 2023
026217d
[Unity][BYOC] Add CUTLASS backend (#14081)
masahi Feb 22, 2023
4365d1e
[Unity][BYOC] Add DNNL backend (#14082)
masahi Feb 22, 2023
2409be1
[Unity][Op] `log_softmax` and `cross_entropy_with_logits` (#14083)
SiriusNEO Feb 22, 2023
9caab4d
[Unity][Analysis] TIR pattern kind analysis for multi-buffer write bl…
MasterJH5574 Feb 22, 2023
872c9f2
[Unity][Fix][Pass] FoldConstant with DCE in dataflow block (#14087)
MasterJH5574 Feb 22, 2023
6b87e35
[Unity] Refactor Relax Build JIT UX (#14088)
tqchen Feb 22, 2023
3959707
[Unity][Relax] Set Shape Function to Be Host Function (#14090)
zxybazh Feb 22, 2023
79fe0a2
[Unity] Fix typo in the comment (#14096)
vinx13 Feb 22, 2023
779c54d
[Unity] Lower `shape_of` to a builtin (#14093)
YuchenJin Feb 22, 2023
3173f28
[Unity] Relax Recursive function (#14092)
yongwww Feb 23, 2023
62a4c73
[Unity][Layout] Add layout transformation analysis for PrimFunc (#14066)
psrivas2 Feb 23, 2023
1bf8b63
[Unity] Remove attributes of relax.print, assert and unique (#14101)
yongwww Feb 23, 2023
30d204b
[Unity][BYOC]Add relax backend pattern registry (#14106)
yelite Feb 24, 2023
a1f8d72
[Unity] Update tests again to adapt to latest TVMScript syntax (#14115)
Ubospica Feb 24, 2023
6a9caf4
[Unity][Fix] Fix bug in MergeCompositeFunctions (#14117)
Ubospica Feb 24, 2023
3515f95
[Unity][BlockBuilder] Add `name_hint` argument for `emit` and `emit_o…
SiriusNEO Feb 25, 2023
c1f3044
[Unity][WEB] Relax vm on web runtime (#14131)
tqchen Feb 25, 2023
aaa457d
[Unity] Add Global info (#14132)
jinhongyii Feb 26, 2023
837dd6c
[Unity][BYOC] Add transposed matmul support to Relax CUTLASS BYOC (#1…
yelite Feb 27, 2023
a4b1ec0
[Unity][TVMScript] emit_te sugar (#14123)
yongwww Feb 27, 2023
be170bb
[Unity][BYOC] Assign group to unused bindings and ignroe PrimFunc (#1…
vinx13 Feb 27, 2023
77f4c71
[Unity] Add callback to FuseOpsByPattern to check match result is acc…
vinx13 Feb 27, 2023
1b6d104
[Unity][Legalize] Fix Scalar Constant Legalization (#14127)
zxybazh Feb 28, 2023
788c12f
[Unity][Pass] Enhance constant folding to fold relax ops by evaluatin…
psrivas2 Feb 28, 2023
f17a728
[Unity][Debugging] AST printer (#14152)
slyubomirsky Mar 1, 2023
c78e68b
[Unity][Pass] Support Symbolic Shape Deduction during BindParam (#14154)
Mar 1, 2023
ab5aaa0
[Unity][Analysis] Checking function return struct info in well-formed…
Mar 1, 2023
89cff05
[Unity][BYOC] Use Relax legalize + CPU build for reference in tests (…
masahi Mar 1, 2023
2ca340a
[Unity] Add bind_constants option to FuseOpsByPattern (#14151)
vinx13 Mar 1, 2023
4fe3a6d
[Unity][Analysis] Analysis for detecting recursion in Relax (#14149)
slyubomirsky Mar 1, 2023
2de852f
[Unity][BYOC] Add batch matmul support to Relax CUTLASS BYOC (#14166)
yelite Mar 2, 2023
8de0ff7
[Unity][Op] Full support of Relax op `power` (#14171)
SiriusNEO Mar 2, 2023
9797924
[Unity][Analysis] Restore Python bindings for var analyses (#14180)
slyubomirsky Mar 4, 2023
30dc236
[Unity][OP] Add an operator for fused multi head attention (#14150)
cyx-6 Mar 4, 2023
279317d
[Unity][WEBGPU] Codegen improvements and WebRuntime (#14187)
tqchen Mar 4, 2023
3f66edc
[Unity][Transform] LiftTransformParams handling multiple functions (#…
MasterJH5574 Mar 4, 2023
283a3db
[Unity][Op] Group normalization (#14194)
MasterJH5574 Mar 4, 2023
c25659d
[Unity][Op] Argmax and argmin (#14195)
MasterJH5574 Mar 5, 2023
2f114d2
[Unity][Op] Legalize `round`, `floor`, `ceil`, `sign` (#14198)
MasterJH5574 Mar 5, 2023
0129235
[Unity][Frontend] FX translator supporting more ops (#14196)
MasterJH5574 Mar 5, 2023
a115d03
[Unity][Frontend] FX translator returning weights with `keep_params_a…
MasterJH5574 Mar 5, 2023
27b6fa7
[Unity][Fix] FX translating dtype (#14201)
MasterJH5574 Mar 5, 2023
6ab0abc
[Unity][TIR][Pass] ForceNarrowIndexToInt32 (#14203)
MasterJH5574 Mar 6, 2023
3f4417c
[Unity][Frontend] FX translator support torch.baddbmm (#14202)
MasterJH5574 Mar 6, 2023
2d562f8
[Unity] Introduce Default GPU Schedule Pass (#14182)
zxybazh Mar 6, 2023
97dc05e
[Unity][Frontend] Attach imported model weights, deprecate ImporterOu…
MasterJH5574 Mar 6, 2023
033fc0e
[Unity][Frontend] FX translator supports unwrapping unit return tuple…
MasterJH5574 Mar 6, 2023
9f9cf29
[Unity][WEB] Improve webgpu codegen options to skip readonly (#14213)
tqchen Mar 6, 2023
8f2153c
[Unity][Frontend] from_fx keeps parameters in order (#14214)
MasterJH5574 Mar 6, 2023
3084874
[Unity][BYOC] Add dynamic shape support to CUTLASS matmul (#14216)
yelite Mar 7, 2023
73b03da
[Unity][Transform] Memory plan across the IRModule (#14220)
MasterJH5574 Mar 7, 2023
780a579
[Unity][WEB] Simplify WebGPU Codegen per spec (#14225)
tqchen Mar 7, 2023
3345aed
[Unity] ensure memory.alloc_tensor/storage roundtrippable (#14226)
yongwww Mar 7, 2023
30a9403
[Unity] Improve implementation of FuseOps (#14229)
tqchen Mar 8, 2023
9bc1ecc
[Unity][Transform] SimplifyNormInference (#14221)
SiriusNEO Mar 8, 2023
a6b37b8
[Unity][Bugfix] Do not include `PrimFunc`s in the dependency graph wh…
slyubomirsky Mar 8, 2023
3e03ca5
[Unity][TVMScript] Enable Context-Aware Parsing (#14234)
Mar 8, 2023
cea0161
[Unity][TVMScript] Fix prim_func lost issue in relax.emit_te (#14189)
yongwww Mar 8, 2023
14a7de5
[Unity][WEB] Update text prompts for syntactical correctness (#14237)
MasterJH5574 Mar 8, 2023
663c821
[Unity][WEB] Improve ndarray cache (#14236)
tqchen Mar 8, 2023
c7c4dee
[Unity][Op][Tweak] Improve `StructInfo` inference for `shape_of` (#14…
slyubomirsky Mar 9, 2023
633c900
[Unity][Op] Add repeat, tile, conv2d_transpose, avg_pool2d (#14238)
Ubospica Mar 9, 2023
07f7fc0
[Unity] Allow user defined func attrs in emit_te (#14255)
psrivas2 Mar 9, 2023
04d6d15
[Unity][BYOC] Add conv2d and residual block patterns for Relax cutlas…
yelite Mar 9, 2023
df9d084
[Unity][Frontend] Import `tanh` and fix `layer_norm` (#14247)
SiriusNEO Mar 10, 2023
71c23b7
[Unity] Consider target context for Relay to Relax conversion (#14269)
ibsidorenko Mar 10, 2023
70386ec
[Unity] Introduce call_dps_packed (#14183)
yongwww Mar 10, 2023
c676d13
[Unity][ci] Use CPU-SMALL instances (#14256)
driazati Mar 11, 2023
121e1e7
[TVMScript][Unity] Improve PyLint Compatibility (#14276)
Mar 12, 2023
6be5c19
[Unity] Mark tests that need python3.8 compact.
tqchen Mar 13, 2023
68827fa
[Unity] Fix StructInfo Infer for `vm.alloc_tensor` (#14283)
Mar 13, 2023
e3f9755
[Unity][Op] Cumsum (#14297)
SiriusNEO Mar 14, 2023
67e183c
[Unity][DEBUG] Add Instrument (#14302)
tqchen Mar 15, 2023
f96e09a
[Unity][Pass] Add a pass to alter the TIR implementation of an operat…
psrivas2 Mar 15, 2023
a46fd90
[Unity][Op] Enable special dimension value 0 in reshape (#14311)
Mar 16, 2023
e0c4456
[Unity][Web] WebGPU explicit max buffer size (#14321)
MasterJH5574 Mar 16, 2023
4bfbd3a
[Unity] Support pattern-based rewriting (#14312)
masahi Mar 16, 2023
2f1642f
[Unity][BYOC] Support matmul + residual block fusion in CUTLASS BYOC …
masahi Mar 16, 2023
778b343
[Unity][BYOC] Improve expressiveness of the pattern check function in…
yelite Mar 17, 2023
7c5a570
[Unity][Transform] Enhance RewriteDataflowReshape transform (#14265)
spectrometerHBH Mar 18, 2023
b10e2a2
[Unity][Contrib] Introduce several features of cutlass profiler (#14275)
spectrometerHBH Mar 18, 2023
f67657f
[Unity][TOPI] fp16 LayerNorm & GroupNorm (#14264)
spectrometerHBH Mar 19, 2023
5cd30b0
[Unity][Transform] Automatic Layout Conversion (#14257)
spectrometerHBH Mar 19, 2023
59746ea
[Unity][Transform] Simple Dead Code Elimination (#14262)
spectrometerHBH Mar 19, 2023
371c3a2
[Unity][Transform] Automatic Mixed Precision (#14242)
spectrometerHBH Mar 19, 2023
6919830
[Unity][Lint] Fix cpplint casting (#14333)
ganler Mar 19, 2023
5229827
[Unity][Transform] DefaultSchedule pass (#14266)
spectrometerHBH Mar 19, 2023
375a292
[Unity][Op] Fix Strided Slice Shape Inference (#14324)
zxybazh Mar 20, 2023
920f98d
[Unity][Pass] Reuse prior infra to implement more complete DCE (#14334)
ganler Mar 20, 2023
f4a451d
[Unity] Remove Python interface of RemoveUnusedFunction (#14336)
MasterJH5574 Mar 20, 2023
050562b
[Unity][BYOC] Update testcases to follow recent changes (#14339)
sunggg Mar 20, 2023
7534531
[Unity][Frontend] FX exp and strided_slice fix (#14338)
MasterJH5574 Mar 20, 2023
021ce24
[Unity] Support model kwargs in dynamo_capture_subgraph (#14349)
jinhongyii Mar 21, 2023
fe34a55
[Unity][BYOC] Check leaked intermediate variables in cutlass patterns…
yelite Mar 21, 2023
9ae5895
[Unity][Transform] AMP out_dtype=float16 testcases (#14358)
spectrometerHBH Mar 21, 2023
cd48ba9
[Unity][Fix] Fix block memory plan to handle bool (#14357)
psrivas2 Mar 21, 2023
57b9070
[Unity][Transform] Introduce data-dependent operation of reshape and …
sunggg Mar 21, 2023
27f0ad3
[Unity][Transform] Fix AMP tests (#14360)
spectrometerHBH Mar 21, 2023
20cc2ff
[Unity] Add support to append relay op attrs in translator (#14356)
quic-sanirudh Mar 21, 2023
79492b8
[Unity][WEB] Support async pipeline creation (#14362)
tqchen Mar 22, 2023
7974e0f
[Unity][Pass] Fix FuseOps error if there is no output of a given grou…
Mar 22, 2023
b5cdcec
[Unity][Fix] Infer Layout must support negative axes (#14365)
psrivas2 Mar 22, 2023
eb7b020
[Unity] Add More Ops For FX Translator (#14348)
jinhongyii Mar 22, 2023
14f7b5a
[Unity][TVMScript] Update GlobalVar `checked_type_` when `emit_te` (#…
Mar 22, 2023
a0b28c4
[Unity][Fix] Allow scalar layout initialization (#14370)
psrivas2 Mar 22, 2023
9253f0f
[Unity] Also include output dtype in simt MathInstruction (#14372)
areusch Mar 22, 2023
8d8ced7
[Unity][VM] Add CUDA graph vm builtins (#14371)
vinx13 Mar 22, 2023
983b569
[Unity] Add missing #include <array> (#14383)
Mar 23, 2023
d6efe9f
[Unity][Transform] SplitCallTIRByPattern and CUTLASS backend (#14274)
spectrometerHBH Mar 24, 2023
f7f45dc
[Unity] Support simple dynamic-shape-aware fusion (#14396)
Mar 24, 2023
34b32cd
[Unity][Op] Add stop_lift_params (#14368)
jinhongyii Mar 25, 2023
6eb12ff
[Unity][TVMScript] Fix Shape Var occurrence in Tensor annotation (#14…
Ubospica Mar 26, 2023
ae3cf5f
[Unity][Transform] Common Subexpression Elimination (#14361)
slyubomirsky Mar 27, 2023
6818799
[Unity][QNN][Hexagon]Support Relax Constants in the QNN TOPI operatio…
farshidsp Mar 27, 2023
a8205ed
[Unity][Op] Conv1d (#14388)
LeshengJin Mar 27, 2023
906f690
[Unity] Fix getting shapes for cutlass BYOC kernels (#14411)
vinx13 Mar 28, 2023
5426085
[Unity][Op] Expose scale in `R.nn.attention` and add its legalize op …
cyx-6 Mar 28, 2023
7f44914
[Unity][Hexagon] Enable Relax VM for Hexagon (#14415)
ibsidorenko Mar 28, 2023
94b9bbc
[Unity][Fix] Copy over module attrs in FuseTIR (#14418)
psrivas2 Mar 29, 2023
4d29a7c
[Unity] Handle extern func calls in static memory planning (#14419)
vinx13 Mar 29, 2023
e424eea
[Unity] Include constant shapes in the profiler result (#14428)
vinx13 Mar 29, 2023
b1346b9
[Unity][Fix] Annotate TIR op pattern could have no stores. (#14420)
psrivas2 Mar 29, 2023
beb25a7
[Unity] Minor updates to DataFlowBlockRewrite (#14431)
masahi Mar 30, 2023
22c363a
[Unity] Remove non-deterministic behavior from graph pattern matching…
masahi Mar 30, 2023
61f7edc
[Unity][Graph matching] Automatically add `used-by` constraints for `…
masahi Mar 30, 2023
ad4bfbc
[Unity][Op][Docs] Update comment for `call_tir_dyn` (#14441)
slyubomirsky Mar 31, 2023
0a4ce4d
[Unity][Graph matching] Clean up undo stack for parent and child node…
masahi Mar 31, 2023
52f6e63
[Unity] Pattern-based rewriting for dataflow block (#14446)
masahi Apr 1, 2023
5c8b7af
[Unity] Fix lint during for upstream black
tqchen Apr 1, 2023
1527bfb
[TVMScript][Bugfix] Tuple on the RHS of AssignDoc (#14452)
junrushao Apr 2, 2023
97ab25c
[Unity][BYOC] Faster cutlass codegen (#14465)
psrivas2 Apr 3, 2023
db01567
[Unity][Op] introduce `shape_to_tensor` op (#14447)
sunggg Apr 3, 2023
d2f35eb
use sinfo from Call instead of callee func in Runcodegen
masahi Apr 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion 3rdparty/cutlass
Submodule cutlass updated 25 files
+1 −1 docs/annotated.html
+1 −1 docs/default__mma__core__simt_8h_source.html
+1 −1 docs/hierarchy.html
+1 −1 docs/namespacecutlass_1_1transform.html
+1 −1 docs/pitch__linear__thread__map_8h.html
+1 −1 docs/pitch__linear__thread__map_8h_source.html
+1 −1 docs/structcutlass_1_1transform_1_1TransposePitchLinearThreadMap2DThreadTile.html
+46 −7 examples/41_fused_multi_head_attention/debug_utils.h
+6 −6 examples/41_fused_multi_head_attention/default_fmha_grouped.h
+0 −0 examples/41_fused_multi_head_attention/epilogue/epilogue_pipelined.h
+0 −0 examples/41_fused_multi_head_attention/epilogue/epilogue_rescale_output.h
+0 −0 examples/41_fused_multi_head_attention/epilogue/epilogue_thread_apply_logsumexp.h
+132 −11 examples/41_fused_multi_head_attention/fmha_grouped.h
+7 −2 examples/41_fused_multi_head_attention/fused_multihead_attention_fixed_seqlen.cu
+2 −0 examples/41_fused_multi_head_attention/gemm/find_default_mma.h
+17 −152 examples/41_fused_multi_head_attention/gemm/mma_accum_lambda_iterator.h
+263 −23 examples/41_fused_multi_head_attention/gemm/mma_from_smem.h
+437 −52 examples/41_fused_multi_head_attention/kernel_forward.h
+88 −0 examples/41_fused_multi_head_attention/transform/tile_smem_loader.h
+1 −1 include/cutlass/gemm/device/base_grouped.h
+52 −126 include/cutlass/gemm/kernel/gemm_universal_streamk.h
+2 −9 include/cutlass/gemm/threadblock/threadblock_swizzle_streamk.h
+1 −1 include/cutlass/transform/pitch_linear_thread_map.h
+1 −1 test/unit/common/cutlass_unit_test.h
+36 −16 tools/library/scripts/generator.py
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ tvm_file_glob(GLOB_RECURSE COMPILER_SRCS
src/driver/*.cc
src/support/*.cc
src/script/*.cc
src/relax/ir/*.cc
src/relax/op/*.cc
src/relax/analysis/*.cc
src/relax/transform/*.cc
src/relax/backend/vm/*.cc
src/relax/backend/task_extraction.cc
src/relax/backend/pattern_registry.cc
src/relax/utils.cc
)

tvm_file_glob(GLOB CODEGEN_SRCS
Expand Down Expand Up @@ -335,6 +343,7 @@ tvm_file_glob(GLOB RUNTIME_SRCS
src/runtime/*.cc
src/runtime/vm/*.cc
src/runtime/minrpc/*.cc
src/runtime/relax_vm/*.cc
)

if(BUILD_FOR_HEXAGON)
Expand Down
253 changes: 253 additions & 0 deletions apps/relax_examples/e2e_auto_tir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import datetime
import os
import csv
import json
import argparse
import logging
from typing import Dict
import numpy as np # type: ignore

import tvm
from tvm import relay, relax, runtime, transform
from tvm.ir.module import IRModule
from tvm import meta_schedule as ms
from tvm.meta_schedule.testing.relay_workload import get_network
from tvm.meta_schedule.testing.custom_builder_runner import run_module_via_rpc
from tvm.relax.testing import relay_translator
from tvm.target.target import Target


def _parse_args():
args = argparse.ArgumentParser()
args.add_argument(
"--workload",
type=str,
required=True,
)
args.add_argument(
"--input-shape",
type=str,
required=True,
)
args.add_argument(
"--target",
type=str,
required=True,
)
args.add_argument(
"--num-trials",
type=int,
required=True,
)
args.add_argument(
"--rpc-host",
type=str,
default=None,
)
args.add_argument(
"--rpc-port",
type=int,
default=None,
)
args.add_argument(
"--rpc-key",
type=str,
default=None,
)
args.add_argument(
"--work-dir",
type=str,
required=True,
)
args.add_argument(
"--cache-dir",
type=str,
default=None,
)
args.add_argument(
"--rpc-timeout-sec",
type=int,
default=180,
)
args.add_argument("--num-measurement-repeats", type=int, default=5)
args.add_argument("--num-measurements", type=int, default=10)
args.add_argument("--results-file", type=str, required=False, default=None)
parsed = args.parse_args()
parsed.target = tvm.target.Target(parsed.target)
parsed.input_shape = json.loads(parsed.input_shape)
if parsed.target.attrs.get("mtriple", None) == "aarch64-linux-gnu":
parsed.alloc_repeat = 3
else:
parsed.alloc_repeat = 1
if parsed.rpc_host and parsed.rpc_port and parsed.rpc_key:
parsed.rpc_config = ms.runner.RPCConfig(
tracker_host=parsed.rpc_host,
tracker_port=parsed.rpc_port,
tracker_key=parsed.rpc_key,
session_timeout_sec=parsed.rpc_timeout_sec,
)
parsed.workers = parsed.rpc_config.count_num_servers(allow_missing=False)
else:
# check all rpc configs are None
assert (
(parsed.rpc_host is None) and (parsed.rpc_port is None) and (parsed.rpc_key is None)
), "Please set all 'rpc_host', 'rpc_port' and 'rpc_key' to use PRC server"
parsed.rpc_config = None
parsed.workers = 1
return parsed


logging.basicConfig()
logging.getLogger("tvm.meta_schedule").setLevel(logging.DEBUG)
ARGS = _parse_args()


def apply_opt_before_tuning(
relay_mod: IRModule, params: Dict[str, runtime.NDArray], target: Target
):
with transform.PassContext(opt_level=3):
main_func = relay_mod["main"]
bind_main_func = relay.build_module.bind_params_by_name(main_func, params)
relay_mod = IRModule.from_expr(bind_main_func)
relay_mod = relay.transform.SimplifyInference()(relay_mod)
relay_mod = relay.transform.FoldConstant()(relay_mod)
relay_mod = relay.transform.FoldScaleAxis()(relay_mod)
relay_mod = relay.transform.CanonicalizeOps()(relay_mod)
relay_mod = relay.transform.AlterOpLayout()(relay_mod)
relay_mod = relay.transform.FoldConstant()(relay_mod)

relax_mod = relay_translator.from_relay(relay_mod["main"], target=target)
relax_mod = relax.transform.AnnotateTIROpPattern()(relax_mod)
relax_mod = relax.transform.FuseOps()(relax_mod)
relax_mod = relax.transform.FuseTIR()(relax_mod)
return relax_mod


def f_measurement(
rt_mod: runtime.Module, device: runtime.ndarray.Device, input_data: Dict[str, runtime.NDArray]
):
vm = relax.VirtualMachine(rt_mod, device=device)
vm.save_function("main", "measure_func", **input_data, include_return=False)
evaluator = vm.time_evaluator(
func_name="measure_func",
dev=device,
repeat=ARGS.num_measurement_repeats,
number=ARGS.num_measurements,
min_repeat_ms=500,
)
return evaluator()


def get_runner():
runner_config = {
"evaluator_config": ms.runner.EvaluatorConfig(
number=3,
repeat=1,
min_repeat_ms=100,
enable_cpu_cache_flush=False,
),
"alloc_repeat": ARGS.alloc_repeat,
}
if ARGS.rpc_config:
runner = ms.runner.RPCRunner(
rpc_config=ARGS.rpc_config, max_workers=ARGS.workers, **runner_config
)
else:
runner = ms.runner.LocalRunner(**runner_config)

return runner


def main():
relay_mod, params, (input_name, input_shape, input_dtype) = get_network(
ARGS.workload,
ARGS.input_shape,
cache_dir=ARGS.cache_dir,
)
input_info = {input_name: input_shape}
input_data = {}
for input_name, input_shape in input_info.items():
print(f" input_name: {input_name}")
print(f" input_shape: {input_shape}")
print(f" input_dtype: {input_dtype}")

# translate the ResNet model from Relay to Relax
relax_mod = apply_opt_before_tuning(relay_mod, params, target=ARGS.target)
assert isinstance(relax_mod, tvm.IRModule)

db = ms.relax_integration.tune_relax(
mod=relax_mod,
target=ARGS.target,
params=params,
num_trials_per_iter=64,
max_trials_per_task=ARGS.num_trials,
max_trials_global=ARGS.num_trials,
runner=get_runner(),
work_dir=ARGS.work_dir,
)
executable = ms.relax_integration.compile_relax(
db,
mod=relax_mod,
target=ARGS.target,
params=params,
)

for input_name, input_shape in input_info.items():
if input_dtype.startswith("float"):
input_data[input_name] = np.random.uniform(size=input_shape).astype(input_dtype)
else:
input_data[input_name] = np.random.randint(
low=0, high=10000, size=input_shape, dtype=input_dtype
)

# for documentation purposes
start_time = datetime.datetime.now()

if ARGS.rpc_config:
result = run_module_via_rpc(
rpc_config=ARGS.rpc_config,
lib=executable.mod,
dev_type=ARGS.target.kind.name,
args=input_data,
continuation=f_measurement,
)
else:
dev = tvm.device(ARGS.target.kind.name)
result = f_measurement(executable.mod, dev, input_data)

print(result)

if not ARGS.results_file:
return

out_path = os.path.abspath(os.path.expanduser(ARGS.results_file))
with open(out_path, "w") as out_file:
writer = csv.writer(out_file)
# write experiment parameters at the top as a record
writer.writerow(["start", str(start_time)])
writer.writerow(["workload", ARGS.workload])
writer.writerow(["input_shape", ARGS.input_shape])
writer.writerow(["target", ARGS.target])
writer.writerow(["num_measurement_repeats", ARGS.num_measurement_repeats])
for res in result.results:
writer.writerow([str(res)])


if __name__ == "__main__":
main()
57 changes: 57 additions & 0 deletions apps/relax_examples/mlp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# Example code on creating, compiling, and running an MLP model in relax


import tvm
from tvm import relax, tir, topi
import numpy as np


def build_mlp(data, weight):
bb = relax.BlockBuilder()

with bb.function("mlp", [data, weight]):
gv0 = bb.emit_te(tvm.contrib.cblas.matmul, data, weight, transa=False, transb=False)
gv1 = bb.emit_te(topi.nn.relu, gv0)
bb.emit_func_output(gv1)

mod = bb.get()
return mod


if __name__ == "__main__":
# symbolic dimensions
n, m = tir.Var("n", "int64"), tir.Var("m", "int64")
# create data and weight variables
data = relax.Var("data", relax.TensorStructInfo([n, m], "float32"))
weight = relax.Var("weight", relax.TensorStructInfo([m, n], "float32"))

# construct a mlp model
mod = build_mlp(data, weight)

# build and create vm executor
target = tvm.target.Target("llvm", host="llvm")
ex = relax.build(mod, target)
vm = relax.VirtualMachine(ex, tvm.cpu())

# run the mlp model on relax vm
data = tvm.nd.array(np.random.rand(16, 32).astype(np.float32))
weight = tvm.nd.array(np.random.rand(32, 16).astype(np.float32))
res = vm["mlp"](data, weight)
print(res)
Loading