Commit Graph

3466 Commits

Author SHA1 Message Date
An Wang c5bd181c3d [FQ2I] Add abs to FQ2I (#10922)
* add abs to fq2i

* lint

* special case for fq2i

* np iinfo
2022-04-08 20:17:11 -07:00
Matthew Barrett 81d72e3d63 [CUDNN] Add cuDNN as a Relay partitioning target (BYOC) (#10871)
* [CUDNN] Add cuDNN as a Relay partitioning target (BYOC)

This adds infrastructure to support offloading of Relay
patterns to cuDNN. In this initial commit, only softmax
is supported.

* Refactor common TE BYOC code into separate file

* Add test guard
2022-04-09 04:23:15 +09:00
Masahiro Masuda fc0473885f [TIR] VNNI and ARM dot product intrinsic for tensorization (#10925) 2022-04-07 18:34:38 -07:00
Yuanjing Shi 19784c8c83 [TVMScript] Fixing T.buffer with typed positional arguments other than int32 (#10892)
* workaround for T.buffer with typed positional arguments

* address comments

* fix linting
2022-04-07 16:55:14 -07:00
Krzysztof Parzyszek 46675996e5 [Hexagon] Register basic strategies and schedules for common operators (#10919)
These are just placeholders to enable building full models.
2022-04-07 16:24:06 -07:00
Junru Shao 5f1f8f3421 [MetaSchedule][Refactor] Clarify Integration Logic (#10927) 2022-04-08 06:17:41 +09:00
Michalis Papadimitriou 6b4d351e9b [TRT] Minor fixes on TRT python interface (#10917)
Co-authored-by: Michalis Papapdimitriou <mpapapdimitriou@octoml.ai>
2022-04-07 21:00:03 +09:00
driazati 6cbb0f6718 [build] Update libinfo and add lint rule (#10774)
* [build] Update libinfo and add lint rule

This updates `tvm.support.libinfo()` to be in-line with the current tvm options. It also adds a lint rule to ensure these stay matched up in the future as well as a script to print out the options in more detail. This should add in communication when debugging (i.e. tell someone to run `python -c 'import tvm; tvm.support.describe()` to learn everything you need about their envrionment)

* Fix pylint

Co-authored-by: driazati <driazati@users.noreply.github.com>
2022-04-06 10:58:50 -07:00
driazati 96f701fd66 [ci] Don't diff Python files when checking formatting (#10895) 2022-04-06 09:25:22 +01:00
An Wang bf9308a8d6 [ONNX] Add imports for Gelu, BiasGelu (#10898)
As title. Adds imports for Gelu, BiasGelu from the com.microsoft onnx op domain.
2022-04-05 20:00:24 -07:00
Masahiro Masuda 3266ab1b4a [MetaSchedule] Add utility API to ease using manual schedules (#10876)
As discussed in https://github.com/apache/tvm/pull/10856#discussion_r840324560, add a utility under `meta_schedule/testing/utils.py` to clean up the database boilerplate. Also using `DummyDatabase` instead of `JsonDatabase` for further clean up, as suggested by @junrushao1994 .
2022-04-05 15:27:00 -07:00
Sevin F. Varoglu 5ec061f976 [QNN] Add per-channel quantization to add/subtract/multiply (#10718)
* Add per-channel quantization to QNN add/subtract/multiply

* Add feedback

* Add feedback - round 2

* Fix for arm test

* Add params to the test

* Try again

* Try int

* Move lhs_axis and rhs_axis

* Add as an attribute

* Add quotes
2022-04-05 09:53:14 -07:00
Jinkun Lin 41cfd3d92d [TIR] Fix int32 vs int64 mismatch in For construct. (#10595)
* Respect dtype in Scalarize.

* Add unittest.

* Fix lint.

* Promote dtype of IntImm to match loop_var in For.

* Fix dtype mismatches.

* Lint

* Lint.

* jostle ci

* Match dtype in hybrid parser.
2022-04-05 15:08:36 +09:00
Tristan Konolige a6e620937b [RUNTIME] Api to get number of runtime threads (#10896)
* [RUNTIME] Api to get number of runtime threads

Add `tvm::runtime::threading::NumThreads` and `tvm.runtime.num_threads`
as a way to get the number of threads in use by the TVM runtime.

* check if equal to hardware threads or hardware threads/2
2022-04-05 11:24:37 +09:00
Michalis Papadimitriou 98580a2a0b [BYOC][TRT] Add DFPattern support for TRT backend (#10759)
This PR adds DFPattern support for the TRT backend without removing the existing predicate registry.

Adds and extends the following:

In tensorrt.py: Add a pattern_table for all the supported ops and consumes the pre-existing op_registry checks
Adds an additional pass as unmerge_composites.cc. This is required for the TRT backend as it expects a single primitive 
function to work with, while the MergeComposite and PartitionGraph will produce a single function for each Composite 
pattern.

Adds test_inline_composites.py which tests the newly introduced pass.
Both the pattern-based and predicate-based pass sequences produce syntactically equivalent IRModules.
This is to ensure backwards compatibility."
2022-04-05 00:42:59 +01:00
heliqi 6d8cb6072b Optimize the implmentation of scale (#10884) 2022-04-04 09:38:17 +09:00
Junru Shao 6f0017a9bf [MetaSchedule][BugFix] Fix broken integration tests (#10885) 2022-04-02 09:05:01 -05:00
Gustavo Romero f745f06f04 [TVMC] tune: Use proper caps for AutoTVM and AutoScheduler (#10864)
Use proper caps in help messages when mentioning AutoTVM and
AutoScheduler tuners.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
2022-04-01 11:40:23 -05:00
Gustavo Romero 9a34ca81f4 Fix typo in comment about kill() (#10863)
Fix typo in comment about kill method in PopenWorker class used to kill
child processes created by the worker.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
2022-04-01 11:39:36 -05:00
Tristan Konolige adcf199294 [PROFILING] Various fixes for profile_function (#10850)
Check that the function to be profiled is actually defined.

Check that the MetricCollector used actually can time the region
requested.

Default to using the module's entry_name instead of "main".
2022-03-31 17:13:28 -07:00
Masahiro Masuda 912993ff39 [ARM] Fix int8 NCHWc compute and alter layout (#10839)
This PR fixes a bug in TE ARM int8 compute for NCHWc conv2d, introduced in https://github.com/apache/tvm/pull/10310. The compute itself, not the schedule, is broken for the following reasons:

* We are using `n_elems = 8` in https://github.com/apache/tvm/blob/e9091d6c68d5d70c28881e5c75bfe72e385c1f4d/python/tvm/topi/arm_cpu/conv2d_alter_op.py#L350. Thus, the innermost axis of the transformed kernel has extent 8: https://github.com/apache/tvm/blob/e9091d6c68d5d70c28881e5c75bfe72e385c1f4d/python/tvm/topi/arm_cpu/conv2d_alter_op.py#L375
* In the TE compute, we iterate over the innermost axis `ic_s_inner` of the kernel at https://github.com/apache/tvm/blob/f6f252f0abc8f621a96506739f9534083d1fe213/python/tvm/topi/nn/conv2d.py#L577. `ic_s_inner` has extent `n_elems` according to https://github.com/apache/tvm/blob/f6f252f0abc8f621a96506739f9534083d1fe213/python/tvm/topi/nn/conv2d.py#L566. `n_elems` is 4 by default according to https://github.com/apache/tvm/blob/f6f252f0abc8f621a96506739f9534083d1fe213/python/tvm/topi/nn/conv2d.py#L478
* The ARM code that calls this compute does not explicitly pass `n_elems`, according to https://github.com/apache/tvm/blob/e9091d6c68d5d70c28881e5c75bfe72e385c1f4d/python/tvm/topi/arm_cpu/conv2d_int8.py#L106-L108
* Thus, even though the innermost axis of the kernel has extent 8, the TE compute only loops over `n_elems = 4` of the input channel dimension. 

Initially, I tried to keep `n_elems = 8` in alter layout and fix the intrinsic definition. But `n_elems = 8` breaks tensorization pattern matching, since now the compute is doing 4x8 innermost loop but this intrinsic is supposed to do 4x4 dot product, see https://github.com/apache/tvm/blob/7896108fc41663a1fecbb52345194a93278e9e28/python/tvm/topi/arm_cpu/tensor_intrin.py#L467-L479. Setting `num_int8_elements = 8` there does fix the tensorize pattern matching, but the result was still incorrect.

Rather than fixing the intrin implementation in https://github.com/apache/tvm/blob/7896108fc41663a1fecbb52345194a93278e9e28/python/tvm/topi/arm_cpu/tensor_intrin.py#L492 to adapt for 4x8 dot product, I settled on setting `n_elems = 4` in alter layout. It turned out this change is enough to get the correct output. Moreover, `n_elems = 8` is simply wrong for the dot product path in https://github.com/apache/tvm/blob/7896108fc41663a1fecbb52345194a93278e9e28/python/tvm/topi/arm_cpu/conv2d_int8.py#L154-L155 which computes 4x4 dot product in one instruction. 

@tkonolige I suggest doing perf benchmark again, since the numbers in https://github.com/apache/tvm/pull/10310 are invalid.

cc @mbrookhart @Mousius  @junrushao1994 @vinx13
2022-03-31 17:11:32 -07:00
Margaret Qian 8775a805d1 [TVMC] Support compiling and running with VM (#10722)
* introduce vm compile path

* support vm in tvmc

* cleanup + lint

* add profiler + simplify vm case in tvmcpackage

* address comments + parametrize tests

Co-authored-by: Margaret Qian <mqian@octoml.ai>
2022-03-31 09:30:09 -07:00
Xiyou Zhou 5629f8a69e [MetaSchedule] Add Gradient Based Task Scheduler (#10366)
Co-authored-by: Junru Shao <junrushao1994@gmail.com>
2022-03-31 22:58:07 +08:00
Ivy Zhang 5814fdd7d6 prune dnnl subgraph, and add related test case. (#10835) 2022-03-30 23:42:24 -07:00
Matthew Barrett 5cacecc0c0 [CUBLAS] Add support for nn.dense and nn.batch_matmul (#10826)
* [CUBLAS] Add support for nn.dense and nn.batch_matmul

This commit includes a fix for cublas.batch_matmul
when mixed precision is being used.

* Specify args in dense
2022-03-31 13:46:31 +09:00
Krzysztof Parzyszek 6af3f36184 [Hexagon] Pass extra parameters to link_params via Map (#10830)
There is no way to pass kwargs dictionary from C++ code, so the previous
way never worked. Use TVM's Map instead, and pass the target architecture
version to the linker to use libraries specific to the architecture.
2022-03-31 13:45:15 +09:00
Xiyou Zhou 72c761c807 [MetaSchedule] Fine-Grained Rewrite Unbound Block (#10823)
In this PR we introduced more fine-grained loop spliting and reordering for Rewrite-Unbound-Block post processor based on given cuda target's attribute (`max_threads_per_block`). After this PR the performance of non-reductional kernels could improve by ~20%. Regression tests are also added.
2022-03-30 17:02:27 -07:00
Masahiro Masuda 642fc57c5e [Metaschedule] Add demonstration of selectively tuning relay ops with TIR schedules (#10793)
This demonstrates how to selectively extract and tune tasks from a whole relay mod, and apply the tuned schedule during the final `relay.build(...)`. 

This flow is entirely different from existing tests in `test_meta_schedule_tune_relay.py` where ALL ops are extracted and auto-scheduled by MS. My test extracts only int8 `dense` op, applies a manual TIR schedule on it, and leaves int8 `batch_matmul` to be scheduled by TE. 

This also serves as an example of autotvm style manual template + tensorization. The manual TIR schedule is equivalent to TE VNNI `dense` schedule in https://github.com/apache/tvm/blob/ce335c3a74185df6cc1152e53c60695d8a418d8e/python/tvm/topi/x86/dense.py#L366-L375
2022-03-30 13:30:44 -07:00
driazati de93d81ddf [skip ci][hotfix] Fix broken lint (#10827)
Co-authored-by: driazati <driazati@users.noreply.github.com>
2022-03-31 04:31:41 +09:00
Thomas Viehmann 6d42264fac bump PyTorch version to 1.11 (#10794)
* bump PyTorch version to 1.11

* disable some caffe2 ci

* Fix sub conversion in PyTorch frontend

* use fuse_modules_qat if available, fallback to fuse_modules for older PyTorch

* Re-Run CI
2022-03-31 04:11:36 +09:00
Matthew Barrett b2a0e1d274 [CUBLAS] Add cuBLAS as a Relay partitioning target (BYOC) (#10820)
* [CUBLAS] Add cuBLAS as a Relay partitioning target (BYOC)

This PR adds a partitioning pass for cuBLAS so that
supported Relay patterns can be offloaded to cuBLAS.

This initial commit only adds offloading support
for nn.matmul.

Although cuBLAS is already enabled in TVM by using
strategy selection in TE, by exposing it explicitly
as a Relay partitioning target we can more precisely
describe how to execute a model in Relay. This is
desirable particularly in the Collage effort to
improve multi-backend graph partitioning.

* Refactor to remove boilerplate
2022-03-30 12:24:18 -06:00
Elen Kalda d0c7c78c56 [microNPU] Tweak a layout transform matrix (#10763)
* [microNPU] Fix layout transform matrix

One of the layout transforms currently causes the cascader to stripe
across B16 axis (which is not allowed), so change that and deal with
the implications to the get_valid_block_configs.

Change-Id: I04199f9f35fcc31618581567483cfb80d3b5aad2

* Reduce the duplication of layout transfrom matrices

* Change the nhcwb16_to_nhwc matrix for binary and unary elementwise
  such that it matches the other NPU ops
* Reduce the number of places where the same layout transform matrices are
  defined

* Add documentation to the layout transform matrices
2022-03-30 08:33:25 +01:00
anilmartha ba8698f0a6 [CI] Fix Vitis-AI tests when USE_VITIS_AI flag set to OFF (#10802)
* Register relay.ext.vitis_ai.available function

* Fix vitis-ai tests when running with USE_VITIS_AI OFF

* Replace skip_test with pytest skipif

* Add a function to see if vitis_ai is available

* Use requires_vitis_ai function for running tests
2022-03-29 19:46:12 +01:00
Junru Shao ce28068da8 [MetaSchedule] Support grouping in the cost model (#10811) 2022-03-29 19:05:56 +08:00
Junru Shao c2488ac863 [MetaSchedule] Extract task weights during task extraction (#10810)
* [MetaSchedule] Extract task weights on task extraction

* Update test_meta_schedule_integration.py
2022-03-29 18:58:55 +09:00
Masahiro Masuda 7896108fc4 [ARM] Fix NCHWc int8 dot product schedule lowering (#10773)
* [ARM] Fix NCHWc int8 dot product schedule lowering

* fix arm task extraction test not running

* skip test on i386
2022-03-28 10:41:03 -07:00
Colin Y. Li f88e43f18a [PyTorch] Fix neg indexing issue for aten::flatten (#10796) 2022-03-28 14:27:49 +09:00
mawnja 2cc0451c28 added surpport for arg type of numeric float16 and testcase, fixed the (#10797)
cierror
2022-03-28 06:14:09 +09:00
Ruihang Lai 8813d0a2bd [TVMScript] Parser int64 support (#10789)
## Context

When dealing with end-to-end models, we note that some tensors may have large shapes. Thus, when designing graph-level IR, we sometimes use `int64` instead of `int32` for the shape. Below is an dense GeMM example which has `int64` input tensor shape:

```python
@tvm.script.ir_module
class Module:
    @T.prim_func
    def main(rxplaceholder: T.Buffer[(1, 512), "float32"], rxplaceholder_1: T.Buffer[(T.int64(1000), T.int64(512)), "float32"], T_matmul_NT: T.Buffer[(1, T.int64(1000)), "float32"]) -> None:
        # function attr dict
        T.func_attr({"global_symbol": "dense", "tir.noalias": True, "op_pattern": 3})
        # body
        # with T.block("root")
        for i0_0, i1_0, i0_1, i1_1, i2_0, i0_2, i1_2, i2_1, i0_3, i1_3 in T.grid(1, 4, 1, 25, 8, 1, 10, 64, 1, 1):
            with T.block("T_matmul_NT"):
                i = T.axis.spatial(1, 0)
                j = T.axis.spatial(T.int64(1000), i1_0 * T.int64(250) + i1_1 * T.int64(10) + i1_2)
                k = T.axis.reduce(512, i2_0 * 64 + i2_1)
                T.reads(T_matmul_NT[i, j], rxplaceholder[i, k], rxplaceholder_1[j, k])
                T.writes(T_matmul_NT[i, j])
                T.block_attr({"layout_free_placeholders":[rxplaceholder_1], "meta_schedule.tiling_structure":"SSRSRS"})
                with T.init():
                    T_matmul_NT[i, j] = T.float32(0)
                T_matmul_NT[i, j] = T_matmul_NT[i, j] + rxplaceholder[i, k] * rxplaceholder_1[j, k]
```

## Problem

Though our TVMScript printer can easily print `int64` constants, the parser had poor support for `int64`. So this PR introduces some parser support for `int64`, basically about the data type of loop variables, block iterators and block read/write regions.

Besides the parser, most of the TIR schedule primitives didn't take `int64` into account in their implementations. These schedule primitives will be fixed and updated in recent future, in followup PRs.
2022-03-25 15:09:24 -07:00
Christian Convey e956eb3375 [TVMC] Fix wrong terminology in tvmc source (#10320)
Renames variable from `runtime` with `executor` to better
reflect current terminology and reduce confusion.
2022-03-26 05:51:35 +09:00
Jiawei Liu 31a4267a19 [ONNX] fix reduce crash on scalar inputs (#10780)
* fix reduce crash on scalar inputs

* fix uncovered cases.

* fix on different opset to pass ci
2022-03-26 04:51:11 +09:00
Luke Hutton 079eb4e992 [microNPU] Add a pass to move allocate nodes to the outer scope (#10725)
* [microNPU] Add a pass to move allocate nodes to the outer scope

Adds a pass called `HoistAllocates` to move allocate nodes to the top
of the body of the main function. In doing so, it opens the door to
other optimizations that need to swap the ordering of external calls.

Pass illustration:
(before)
```
allocate {
    extern_call {
        allocate {
            extern_call {

            }
        }
    }
}
```

(after)
```
allocate {
    allocate {
        extern_call
        extern_call
    }
}
```

Change-Id: Ibcfc3c75b15deebb5c6645a4923a6ddf683b37c4

* address comments

* uses prim func pass, rather than module pass.
* adds error message informing user to run this pass with LowerToTIR()
  pass for now.

Change-Id: I57757b9dc5bff0208034a974a341c09cce0294bc

* Support allocates when not followed by a sequence statement

With a test to back this case up.

Change-Id: I670809f5ee53b583a15d9b783852dda3089756e9

* Add new directory tir/contrib/ethosu to cmake build

Change-Id: I3e9f24adfe992ace4e03238a18a8378b03257e1a
2022-03-25 18:23:17 +00:00
Wuwei Lin 937a14f07f [TIR][Analysis] Add SuggestIndexMap for layout rewriting (#10732)
This PR added an analysis function `SuggestIndexMap` to analyze buffer access pattern and suggest index map for layout transformations.

Co-authored-by: Siyuan Feng <Hzfengsy@sjtu.edu.cn>
Co-authored-by: Bohan Hou <32121147+spectrometerHBH@users.noreply.github.com>
Co-authored-by: Hongyi Jin <3231950289@qq.com>
Co-authored-by: Ruihang Lai <lairuihangdongdong@qq.com>
Co-authored-by: Junru Shao <junrushao1994@gmail.com>
Co-authored-by: Xiyou Zhou <xiyou@octoml.ai>
2022-03-25 11:19:46 -07:00
Eric Lunderberg f16286e399 [Hexagon] Improved ergonomics of HexagonLauncher in unit tests. (#10581)
* [Hexagon] Improved ergonomics of HexagonLauncher in unit tests.

The goal of this commit is to reduce/eliminate common code required
through unit tests that interact with Hexagon hardware.

- New testing fixtures in `tests/python/contrib/test_hexagon`.  A test
  running on hexagon hardware should only need to use the
  `hexagon_session` fixture.

  - `rpc_server_port`: Iterates through port numbers, selecting an
    unused port for each unit test.  Avoids needing to explicitly
    specify unique ports for each unit test.

  - `tvm_tracker`: Starts a tracker on use, exits after test.  Avoids
    needing to manually start a tracker prior to running the unit
    test.

  - `hexagon_launcher`: Starts a `HexagonLauncher` server on use,
    stops server after test.  Avoids needing to call `start_server()`
    and `stop_server()` in each test.

  - `hexagon_session`: Starts a hexagon session using
    `hexagon_laucnehr.start_session()`, exits after test.

- Added `Session.upload` function, which delegates to
  `HexagonLauncher.upload`.  Avoids needing to interact with both the
  launcher and the session.

- Allowed `tvm.IRModule` as argument passed to `Session.load_module`,
  which will automatically save/upload the module, then load it.
  Avoids needing to handle save/upload of temporary files in each unit
  test.

* Added default port for tracker if not already set.

* Pass through None from hexagon_launcher to hexagon_session.

* Updated launcher to use external tracker if specified.

* Avoid setting up the local tracker unless required.

* Declare previous_port as global, instead of list.

* Corrected type hints.

* Docstring updates
2022-03-25 09:29:04 -07:00
Christopher Sidebottom 532b2b4a62 Check for toolchain when marking reference system tests (#10659)
This mimics the behaviour of aot_test_utils.py to ensure the tests don't start running when the toolchain isn't available.
2022-03-25 14:12:13 +00:00
Junru Shao 774c28576b [TIR][MetaSchedule] Estimate TIR FLOPs (#10782) 2022-03-25 09:57:16 -04:00
Luke Hutton 2cb769560b [microNPU] Remove identity operations between non-compute operations (#10411)
Builds upon the work in #10254 to remove identity operations sandwiched
between two non-compute operations (reshape/strided slice - concatenate
is handled differently), under certain conditions. Specifically, an
identity operation is not removed when the dimensionality between the
two non-compute operations is reduced, due to non-congruent values
being accessed incorrectly. For example,

```
strided_slice(dims=4) -> identity -> reshape(dims=4)
```
becomes...
```
strided_slice -> reshape
```
but,
```
strided_slice(dims=4) -> identity -> reshape(dims=2)
```
remains as...
```
strided_slice -> identity -> reshape
```

Change-Id: Ie28ba384fcb3230d6f4651c0c19e2b9526ebcc42
2022-03-25 07:05:45 +00:00
Gustavo Romero b56f9e5796 [TVMC] compile: Check if FILE exists (#10608)
Currently when a non-existing FILE is passed to 'tvmc compile' it throws
a traceback because a FileNotFoundError exception is not handled. Since
there is no need for such abrupt exit, and the trace can also confuse
users, this commit fixes it by checking if FILE indeed exists, informing
the user about the non-existing FILE before exiting.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
2022-03-25 13:15:22 +09:00
Masahiro Masuda e9091d6c68 [ARM] Support NCHWc alter layout in the fallback mode (#10724)
* [ARM] Support NCHWc alter layout in the fallback mode

* remove fallback path

* add test

* fixed int32_lanes and add channel check

* fixed schedule dispatch bug

* add workaround fallback path for NHWC im2col based GEMM schedule

* int32_lanes=4 by default

* typo

* update test
2022-03-25 13:14:08 +09:00
Junru Shao 8ebdf6ee21 [MetaSchedule] Misc update for e2e workloads (#10776) 2022-03-25 10:29:06 +08:00