Commit Graph

3454 Commits

Author SHA1 Message Date
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
Colin Y. Li 73ec86047c [PyTorch] Add aten::square operator (#10766) 2022-03-25 06:26:25 +09:00
Jiawei Liu 4974b51b0b Onnx squeeze enabled with auto axis handling. (#10742)
* fix squeeze when axis is absent

* lint

* tidy code

* fix argument
2022-03-25 06:02:09 +09:00
Eric Lunderberg ef35acbb96 [NDArray] Update runtime.TVMArrayAllocWithScope to use ShapeTuple (#10728)
`runtime.TVMArrayAllocWithScope` predates the introduction of
ShapeTuple, and its use simplifies the `tvm.nd.empty` function.  The
two modified locations are the only occurrences of the string
"TVMArrayAllocWithScope" in the repository, so no other call sites
should need to be updated.
2022-03-24 13:07:40 -07:00
Eric Lunderberg d9a5f9ec7e [NDArray] Expose NDArray::CreateView to python (#10712)
Modifying the array view is needed for Hexagon targets, in order to
first call `tvm.nd.array` with the physical dimensions, then update the
shape to contain the logical dimensions.
2022-03-24 13:06:11 -07:00
Brunno Goldstein 1c013bcbbd ONNX Opset 14 Support - HardSwish (#10735)
* ONNX Opset 14 - HardSwish

Added hardswish support to TVM CI and fixed unit test.

- Add class HardSwish and added its reference to convert_map in onnx.py;
- Removed test_hardswish entry from test_forward.py;

* ONNX Opset 14 Support - HardSwish

Fixing onnx.py format.

* jostle ci
2022-03-24 13:02:33 -07:00
Wuwei Lin 38fea15004 [TIR][Schedule] Change BufferIndexType enum in python side to string (#10737)
This is a follow-up of #10538 to use string instead of enum in python side.
2022-03-24 12:56:12 -07:00
Masahiro Masuda f368295638 [ONNX] Make freeze_param = True and run DynamicToStatic by default (#10750)
* [ONNX] make freeze_params=True and run DynamicToStatic by default

* remove convert_to_static in onnx test

* fixed qlinearconv conversion for freeze_params=True

* fixed assert msg placement
2022-03-24 15:14:17 +09:00
Tristan Konolige 93969dbebc [FIX,AUTOTVM] Fix printing of measure results (#10647)
* [FIX,AUTOTVM] Fix printing of measure results

The check for if the error_no was valid was wrong.

* switch logic
2022-03-23 21:23:08 -07:00
Masahiro Masuda 177d529f0e [TVMScript] Enable assignment statement without type annotation (#10736)
* Add test

* workaround mypy

* replace assert with condition
2022-03-24 12:06:53 +08:00
Hua Jiang 4a85dcd706 [Runtime][PipelineExecutor] Getting the asynchronous output (#10723)
This patch create a new GlobalRuntime to check whether the output data
ready and poll global output of pipeline, it also removed the sequence
pipeline execution logic as the asynchronous logic already done.
2022-03-24 09:54:27 +09:00
AleksKnezevic 375566b6e2 Fix default pytorch divide behaviour (#10727)
Co-authored-by: Aleks Knezevic <aknezevic@tenstorrent.com>
2022-03-24 08:46:07 +09:00
Leandro Nunes 4c6b0770b5 [Keras] Adjust Keras frontend for Keras 2.6 support (#10733)
Add support for the Keras frontend to be tested and used with
both Keras 2.4 and 2.6, as we plan for migration.

Co-Authored-By: Luke Hutton <Luke.Hutton@arm.com>

Co-authored-by: Luke Hutton <Luke.Hutton@arm.com>
2022-03-23 14:50:18 -07:00