You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2023/10/29 22:25:51 UTC

(tvm) 01/02: [MERGE] Merge main into unity 2023-10-29

This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch unity-staging
in repository https://gitbox.apache.org/repos/asf/tvm.git

commit 3184a80492a64dcae31cce54073924e4fd9a8a5d
Merge: 6408cc414f 7eedea53fc
Author: tqchen <ti...@gmail.com>
AuthorDate: Sun Oct 29 18:12:03 2023 -0400

    [MERGE] Merge main into unity 2023-10-29

 CMakeLists.txt                                     |   2 +-
 apps/cpp_clml/scripts/clml_codegen.py              |   2 +-
 apps/microtvm/poetry.lock                          |  30 ++--
 ci/jenkins/docker-images.ini                       |   2 +-
 conda/recipe/meta.yaml                             |   2 +-
 docker/Dockerfile.ci_adreno                        |   8 +-
 docker/install/ubuntu2204_install_llvm.sh          |  22 ++-
 .../ubuntu_download_arm_compute_lib_binaries.sh    |   2 +-
 docker/install/ubuntu_install_cmsis.sh             |  20 +--
 docker/python/bootstrap-requirements.txt           |   5 +-
 include/tvm/runtime/c_runtime_api.h                |  50 ++++++-
 python/tvm/_ffi/libinfo.py                         |   2 +-
 .../tvm/relay/backend/contrib/ethosu/legalize.py   |  99 ++++++++++++-
 .../relay/backend/contrib/ethosu/op/identity.py    |  18 ++-
 .../relay/backend/contrib/ethosu/te/identity.py    |   8 +-
 .../relay/backend/contrib/ethosu/tir/identity.py   |   2 +-
 python/tvm/relay/frontend/keras.py                 |   6 +-
 python/tvm/relay/frontend/mxnet.py                 |   7 +-
 python/tvm/relay/frontend/pytorch.py               | 124 +++++++++++++++++
 python/tvm/relay/frontend/tflite.py                |   2 -
 python/tvm/relay/op/contrib/ethosu.py              |  43 ++++++
 python/tvm/relay/qnn/__init__.py                   |   3 +-
 python/tvm/script/parser/core/parser.py            |   1 -
 python/tvm/target/codegen.py                       |  42 ++++++
 python/tvm/testing/utils.py                        |  89 ++++--------
 python/tvm/tir/op.py                               |   9 +-
 python/tvm/tir/schedule/schedule.py                |   2 +-
 python/tvm/tir/tensor_intrin/cuda.py               |  46 +++----
 .../arm_cpu/mprofile/dsp/micro_kernel/avg_pool.py  |   8 +-
 .../topi/arm_cpu/mprofile/dsp/micro_kernel/gemm.py |  87 +++++++++---
 .../arm_cpu/mprofile/dsp/micro_kernel/max_pool.py  |  13 +-
 .../arm_cpu/mprofile/dsp/micro_kernel/tensordot.py |   7 +-
 .../backend/contrib/cmsisnn/tir_to_runtime.cc      |  28 ++--
 .../contrib/example_target_hooks/tir_to_runtime.cc |  26 +++-
 src/relay/backend/contrib/uma/tir_to_runtime.cc    |  34 +++--
 src/relay/op/contrib/ethosu/identity.cc            |   3 +-
 src/relay/op/contrib/ethosu/op_attrs.h             |   8 ++
 src/runtime/c_runtime_api.cc                       |  14 +-
 src/script/printer/tir/expr.cc                     |  25 ++++
 src/target/llvm/codegen_amdgpu.cc                  |  11 +-
 src/target/llvm/codegen_hexagon.cc                 |   5 +-
 src/target/llvm/codegen_llvm.cc                    |  18 +++
 src/target/llvm/codegen_nvptx.cc                   |   5 +-
 src/target/llvm/llvm_instance.cc                   |  62 ++++++++-
 src/target/llvm/llvm_instance.h                    |   8 ++
 src/target/llvm/llvm_module.cc                     |  39 +++++-
 src/target/opt/build_cuda_on.cc                    |  18 ++-
 src/target/source/codegen_aocl.cc                  |  19 ++-
 src/target/source/codegen_c.cc                     | 153 ++++++++++++++-------
 src/target/source/codegen_c.h                      |  59 +++++++-
 src/target/source/codegen_c_host.cc                |  93 ++++++-------
 src/target/source/codegen_c_host.h                 |   3 +-
 src/target/source/codegen_cuda.cc                  |   4 +-
 src/target/source/codegen_cuda.h                   |   2 +-
 src/target/source/codegen_metal.cc                 |  89 ++++++------
 src/target/source/codegen_metal.h                  |   3 +-
 src/target/source/codegen_opencl.cc                |  24 ++--
 src/target/source/codegen_vhls.cc                  |  34 +++--
 src/target/source/codegen_webgpu.cc                |  19 ++-
 src/target/source/source_module.cc                 |   6 +-
 src/tir/op/op.cc                                   |  26 ++++
 tests/python/contrib/test_amx.py                   |  13 +-
 .../cascader/test_ethosu_identity_matcher.py       |   1 +
 tests/python/contrib/test_ethosu/test_codegen.py   |  25 ++++
 tests/python/contrib/test_ethosu/test_legalize.py  | 117 ++++++++++++++++
 tests/python/contrib/test_gemm_acc32_vnni.py       |   4 +-
 .../test_hexagon/test_qnn_op_integration.py        |  38 ++---
 .../test_hexagon/test_relay_simplify_qnn_concat.py |  10 +-
 tests/python/frontend/pytorch/test_forward.py      |  26 ++++
 tests/python/frontend/tflite/test_forward.py       |  17 ++-
 tests/python/integration/test_auto_tensorize.py    |  12 +-
 .../relay/aot/test_crt_forward_declarations.py     |   6 +-
 tests/python/relay/qnn/test_clip_legalization.py   |   2 +-
 .../python/relay/qnn/test_qnn_channel_stripping.py |  16 +--
 tests/python/relay/test_op_level1.py               |   4 +-
 tests/python/relay/test_op_level10.py              |   4 +-
 tests/python/relay/test_op_level2.py               |   4 +-
 tests/python/relay/test_op_qnn_add.py              |  14 +-
 tests/python/relay/test_op_qnn_batch_matmul.py     |   4 +-
 tests/python/relay/test_op_qnn_concatenate.py      |  10 +-
 tests/python/relay/test_op_qnn_conv2_transpose.py  |   4 +-
 tests/python/relay/test_op_qnn_conv2d.py           |   4 +-
 tests/python/relay/test_op_qnn_dense.py            |   4 +-
 tests/python/relay/test_op_qnn_dequantize.py       |   4 +-
 tests/python/relay/test_op_qnn_leaky_relu.py       |   2 +-
 tests/python/relay/test_op_qnn_mul.py              |  10 +-
 tests/python/relay/test_op_qnn_quantize.py         |   4 +-
 tests/python/relay/test_op_qnn_requantize.py       |   8 +-
 .../relay/test_op_qnn_simulated_dequantize.py      |   4 +-
 .../python/relay/test_op_qnn_simulated_quantize.py |   4 +-
 tests/python/relay/test_op_qnn_subtract.py         |   2 +-
 .../python/relay/test_op_qnn_unary_elementwise.py  |  32 ++---
 tests/python/relay/test_pass_qnn_legalize.py       |  18 +--
 tests/python/target/test_llvm_features_info.py     |   6 +
 .../topi/python/test_topi_conv2d_tensordot_opts.py |  28 +++-
 tests/python/topi/python/test_topi_qnn.py          |   4 +-
 .../unittest/test_meta_schedule_cpu_dot_product.py |   8 +-
 .../python/unittest/test_target_codegen_c_host.py  |  48 +++++--
 tests/python/unittest/test_tir_ops.py              |   7 +
 .../test_tir_transform_inject_ptx_async_copy.py    |   1 +
 .../python/unittest/test_tvmscript_printer_tir.py  |   7 +
 tests/scripts/ci.py                                |   2 +-
 tests/scripts/task_config_build_adreno.sh          |   1 +
 version.py                                         |   2 +-
 web/package.json                                   |   2 +-
 105 files changed, 1576 insertions(+), 568 deletions(-)

diff --cc src/target/source/codegen_webgpu.cc
index 1702699ac2,6a6712a4ce..f0b0a0840e
--- a/src/target/source/codegen_webgpu.cc
+++ b/src/target/source/codegen_webgpu.cc
@@@ -118,45 -62,13 +124,45 @@@ void CodeGenWebGPU::InitFuncState(cons
  
  CodeGenWebGPU::CodeGenWebGPU(Target target) : target_(target) {}
  
 -void CodeGenWebGPU::PrintFunctionSignature(const String& function_name, const PrimFunc& func,
 -                                           std::ostream& os) {
 +runtime::FunctionInfo CodeGenWebGPU::AddFunction(const PrimFunc& f, bool skip_readonly_decl) {
 +  // clear previous generated state.
 +  this->InitFuncState(f);
 +  // reserve keywords
 +  name_supply_->ReserveName("var");
 +  name_supply_->ReserveName("let");
 +  name_supply_->ReserveName("const");
 +
 +  // skip the first underscore, so SSA variable starts from
 +  name_supply_->FreshName("v_");
 +  // Setup the thread group info.
 +  ICHECK_EQ(name_supply_->FreshName("threadIdx"), "threadIdx");
 +  ICHECK_EQ(name_supply_->FreshName("blockIdx"), "blockIdx");
 +  ICHECK_EQ(name_supply_->FreshName("gridDim"), "gridDim");
 +
 +  // add to alloc buffer type.
 +  auto global_symbol = f->GetAttr<String>(tvm::attr::kGlobalSymbol);
 +  ICHECK(global_symbol.defined())
 +      << "CodeGenWebGPU: Expect PrimFunc to have the global_symbol attribute";
 +
 +  header_stream << "//----------------------------------------\n"
 +                << "// Function: " << global_symbol.value() << "\n"
 +                << "//----------------------------------------\n";
 +  runtime::FunctionInfo func_info;
 +  func_info.name = global_symbol.value();
 +
 +  WebGPUWorkGroupInfo info = WebGPUWorkgroupInfoCollector::Collect(f->body);
 +
    std::vector<Var> pod_args;
    int num_buffer = 0;
 +
 +  // add param_access modes info to launch params
 +  std::ostringstream os_param_access;
 +  os_param_access << "paramWriteAccess:[";
    // setup buffer argumemts
-   for (Var arg : f->params) {
+   for (Var arg : func->params) {
      DataType t = arg.dtype();
 +    func_info.arg_types.push_back(t);
 +
      if (t.is_handle()) {
        auto* ptr = arg->type_annotation.as<PointerTypeNode>();
        ICHECK(ptr) << "All handles passed to the CodeGenWebGPU must have a type_annotation as a "
@@@ -686,31 -515,34 +692,36 @@@ class WebGPUSourceModuleNode final : pu
  runtime::Module BuildWebGPU(IRModule mod, Target target) {
    mod = tir::transform::PointerValueTypeRewrite()(std::move(mod));
    bool output_ssa = false;
 +  bool skip_readonly_decl = false;
 +  std::unordered_map<std::string, std::string> smap;
 +  std::unordered_map<std::string, runtime::FunctionInfo> fmap;
  
 -  Map<GlobalVar, PrimFunc> functions;
 -  for (auto [gvar, base_func] : mod->functions) {
 -    ICHECK(base_func->IsInstance<PrimFuncNode>()) << "CodeGenWebGPU: Can only take PrimFunc";
 -    auto prim_func = Downcast<PrimFunc>(base_func);
 -    auto calling_conv = prim_func->GetAttr<Integer>(tvm::attr::kCallingConv);
 +  // narrow all i64 to i32
 +  mod = tir::transform::ForceNarrowIndexToInt32()(std::move(mod));
 +
 +  for (auto kv : mod->functions) {
 +    CodeGenWebGPU cg(target);
 +    ICHECK(kv.second->IsInstance<PrimFuncNode>()) << "CodeGenWebGPU: Can only take PrimFunc";
 +    auto f = Downcast<PrimFunc>(kv.second);
 +    auto calling_conv = f->GetAttr<Integer>(tvm::attr::kCallingConv);
      ICHECK(calling_conv == CallingConv::kDeviceKernelLaunch)
          << "CodeGenWebGPU: expect calling_conv equals CallingConv::kDeviceKernelLaunch";
-     auto global_symbol = f->GetAttr<String>(tvm::attr::kGlobalSymbol);
+     auto global_symbol = prim_func->GetAttr<String>(tvm::attr::kGlobalSymbol);
      ICHECK(global_symbol.defined())
          << "CodeGenWebGPU: Expect PrimFunc to have the global_symbol attribute";
-     std::string f_name = global_symbol.value();
+     functions.Set(gvar, prim_func);
+   }
+ 
+   std::unordered_map<std::string, std::string> smap;
+   for (auto [gvar, prim_func] : functions) {
+     CodeGenWebGPU cg(target);
      cg.Init(output_ssa);
 -
 -    for (auto [other_gvar, other_prim_func] : functions) {
 -      cg.DeclareFunction(other_gvar, other_prim_func);
 -    }
 -    cg.AddFunction(gvar, prim_func);
 -
 +    fmap[f_name] = cg.AddFunction(f, skip_readonly_decl);
      std::string code = cg.Finish();
-     smap[f_name] = code;
+     smap[cg.GetFunctionName(gvar)] = code;
    }
 -  auto n = make_object<WebGPUSourceModuleNode>(smap, ExtractFuncInfo(mod));
 +
 +  auto n = make_object<WebGPUSourceModuleNode>(smap, fmap);
    return runtime::Module(n);
  }
  
diff --cc web/package.json
index dbbb04d82d,ac80622fd7..23855700e3
--- a/web/package.json
+++ b/web/package.json
@@@ -2,19 -2,14 +2,19 @@@
    "name": "tvmjs",
    "displayName": "TVM Wasm JS runtime",
    "license": "Apache-2.0",
-   "version": "0.14.0-dev0",
+   "version": "0.15.0-dev0",
 +  "files": [
 +    "lib"
 +  ],
 +  "main": "lib/index.js",
 +  "types": "lib/index.d.ts",
    "scripts": {
      "prepwasm": "make && python3 tests/python/prepare_test_libs.py",
 -    "build": "tsc -b && make rmtypedep",
 +    "build": "rollup -c",
      "lint": "eslint -c .eslintrc.json .",
 -    "typedoc": "typedoc .",
 +    "typedoc": "typedoc src/index.ts --plugin typedoc-plugin-missing-exports",
      "test": "jest",
 -    "bundle": "npm run build && rollup -c rollup.config.js",
 +    "bundle": "npm run build && cp lib/index.js dist/index.js && cp lib/index.js dist/tvmjs.bundle.js",
      "example": "npm run bundle && node apps/node/example.js",
      "example:wasi": "npm run bundle && node --experimental-wasi-unstable-preview1 --experimental-wasm-bigint apps/node/wasi_example.js",
      "rpc": "npm run bundle && node --experimental-wasi-unstable-preview1  --experimental-wasm-bigint apps/node/wasi_rpc_server.js"