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 2025/09/06 15:51:40 UTC
(tvm) branch tensor updated (8f2fd19502 -> 96afa7de0e)
This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a change to branch tensor
in repository https://gitbox.apache.org/repos/asf/tvm.git
discard 8f2fd19502 [FFI][REFACTOR][ABI] Rename NDArray to Tensor
new 96afa7de0e [FFI][REFACTOR][ABI] Rename NDArray to Tensor
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (8f2fd19502)
\
N -- N -- N refs/heads/tensor (96afa7de0e)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
ffi/python/tvm_ffi/module.py | 1 +
python/tvm/runtime/params.py | 2 +-
python/tvm/script/ir_builder/tir/ir.py | 2 +-
src/runtime/vm/hexagon/builtin.cc | 3 +++
tests/python/tvmscript/test_tvmscript_ir_builder_tir.py | 4 ++--
5 files changed, 8 insertions(+), 4 deletions(-)
(tvm) 01/01: [FFI][REFACTOR][ABI] Rename NDArray to Tensor
Posted by tq...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch tensor
in repository https://gitbox.apache.org/repos/asf/tvm.git
commit 96afa7de0ebe64492c9e38ddf50d4173c6dbdba8
Author: tqchen <ti...@gmail.com>
AuthorDate: Sat Sep 6 08:00:07 2025 -0400
[FFI][REFACTOR][ABI] Rename NDArray to Tensor
This PR Updates the NDArray => Tensor.
Both tensor and ndarray are commonly used terms.
Because the term Tensor is getting more common in the context of ML,
we do the rename to stay more aligned with torch.Tensor and DLTensor.
---
apps/android_rpc/app/src/main/jni/tvm_runtime.h | 4 +-
apps/android_rpc/tests/android_rpc_test.py | 4 +-
apps/hexagon_launcher/launcher_core.h | 2 +-
apps/hexagon_launcher/launcher_hexagon.cc | 12 +-
apps/ios_rpc/tests/ios_rpc_test.py | 4 +-
docs/arch/index.rst | 6 +-
docs/deep_dive/tensor_ir/tutorials/tir_creation.py | 6 +-
.../tensor_ir/tutorials/tir_transformation.py | 6 +-
docs/get_started/tutorials/ir_module.py | 6 +-
docs/get_started/tutorials/quick_start.py | 14 +-
docs/how_to/tutorials/cross_compilation_and_rpc.py | 8 +-
docs/how_to/tutorials/customize_opt.py | 4 +-
docs/how_to/tutorials/e2e_opt_model.py | 4 +-
docs/how_to/tutorials/optimize_llm.py | 6 +-
docs/reference/api/python/index.rst | 1 -
docs/reference/api/python/runtime/ndarray.rst | 21 --
docs/reference/api/python/runtime/runtime.rst | 1 -
ffi/CMakeLists.txt | 4 +-
ffi/docs/.gitignore | 1 +
ffi/docs/Makefile | 6 +-
ffi/docs/concepts/abi_overview.md | 12 +-
ffi/docs/conf.py | 3 +
ffi/docs/get_started/quick_start.md | 2 +-
ffi/docs/guides/cpp_guide.md | 32 +--
ffi/docs/guides/python_guide.md | 8 +-
ffi/examples/quick_start/run_example.py | 4 +-
ffi/examples/quick_start/src/run_example.cc | 10 +-
ffi/include/tvm/ffi/c_api.h | 34 +--
ffi/include/tvm/ffi/container/shape.h | 2 +-
.../tvm/ffi/container/{ndarray.h => tensor.h} | 118 ++++----
ffi/include/tvm/ffi/extra/structural_equal.h | 9 +-
ffi/include/tvm/ffi/extra/structural_hash.h | 4 +-
ffi/include/tvm/ffi/object.h | 2 +-
ffi/include/tvm/ffi/type_traits.h | 8 +-
ffi/pyproject.toml | 2 +-
ffi/python/tvm_ffi/__init__.py | 8 +-
ffi/python/tvm_ffi/cython/base.pxi | 12 +-
ffi/python/tvm_ffi/cython/core.pyx | 2 +-
ffi/python/tvm_ffi/cython/function.pxi | 37 +--
.../tvm_ffi/cython/{ndarray.pxi => tensor.pxi} | 50 ++--
ffi/python/tvm_ffi/module.py | 25 +-
ffi/python/tvm_ffi/{ndarray.py => tensor.py} | 6 +-
ffi/src/ffi/extra/structural_equal.cc | 24 +-
ffi/src/ffi/extra/structural_hash.cc | 32 +--
ffi/src/ffi/{ndarray.cc => tensor.cc} | 32 +--
ffi/tests/cpp/test_example.cc | 20 +-
ffi/tests/cpp/{test_ndarray.cc => test_tensor.cc} | 52 ++--
ffi/tests/python/test_function.py | 22 +-
.../python/{test_ndarray.py => test_tensor.py} | 8 +-
include/tvm/ir/module.h | 8 +-
include/tvm/meta_schedule/builder.h | 6 +-
include/tvm/meta_schedule/database.h | 8 +-
include/tvm/meta_schedule/feature_extractor.h | 16 +-
include/tvm/node/structural_hash.h | 2 +-
include/tvm/relax/expr.h | 4 +-
include/tvm/runtime/disco/builtin.h | 34 +--
include/tvm/runtime/disco/session.h | 24 +-
include/tvm/runtime/memory/memory_manager.h | 24 +-
include/tvm/runtime/object.h | 4 +-
include/tvm/runtime/profiling.h | 14 +-
include/tvm/runtime/serializer.h | 2 +-
include/tvm/runtime/{ndarray.h => tensor.h} | 86 +++---
...rray_cache_support.h => tensor_cache_support.h} | 34 +--
include/tvm/script/ir_builder/tir/frame.h | 2 +-
include/tvm/script/ir_builder/tir/ir.h | 4 +-
include/tvm/tir/builtin.h | 2 +-
include/tvm/tir/function.h | 2 +-
include/tvm/tir/index_map.h | 8 +-
include/tvm/tir/stmt.h | 4 +-
include/tvm/tir/transform.h | 14 +-
include/tvm/topi/transform.h | 14 +-
jvm/README.md | 8 +-
.../src/main/java/org/apache/tvm/Function.java | 18 +-
jvm/core/src/main/java/org/apache/tvm/LibInfo.java | 4 +-
jvm/core/src/main/java/org/apache/tvm/TVMType.java | 2 +-
.../src/main/java/org/apache/tvm/TVMValue.java | 2 +-
.../org/apache/tvm/{NDArray.java => Tensor.java} | 56 ++--
.../tvm/{NDArrayBase.java => TensorBase.java} | 12 +-
.../src/main/java/org/apache/tvm/TypeIndex.java | 2 +-
.../src/test/java/org/apache/tvm/FunctionTest.java | 8 +-
.../src/test/java/org/apache/tvm/ModuleTest.java | 8 +-
.../src/test/java/org/apache/tvm/NDArrayTest.java | 80 ------
.../src/test/java/org/apache/tvm/TensorTest.java | 80 ++++++
jvm/native/src/main/native/jni_helper_func.h | 10 +-
.../src/main/native/org_apache_tvm_native_c_api.cc | 17 +-
python/tvm/__init__.py | 6 +-
python/tvm/contrib/cudnn.py | 2 +-
python/tvm/contrib/dlpack.py | 4 +-
python/tvm/contrib/hexagon/generate_take_op.py | 2 +-
python/tvm/contrib/hexagon/meta_schedule.py | 6 +-
python/tvm/contrib/hexagon/tools.py | 4 +-
python/tvm/contrib/miopen.py | 2 +-
python/tvm/contrib/msc/core/codegen/codegen.py | 2 +-
python/tvm/contrib/msc/core/frontend/translate.py | 18 +-
python/tvm/contrib/msc/core/runtime/hook.py | 8 +-
python/tvm/contrib/msc/core/runtime/runner.py | 56 ++--
.../contrib/msc/core/tools/distill/distiller.py | 10 +-
python/tvm/contrib/msc/core/tools/prune/pruner.py | 18 +-
python/tvm/contrib/msc/core/tools/tool.py | 24 +-
python/tvm/contrib/msc/core/transform/transform.py | 4 +-
python/tvm/contrib/msc/core/utils/info.py | 14 +-
.../msc/framework/tensorflow/codegen/codegen.py | 2 +-
.../msc/framework/tensorflow/frontend/translate.py | 2 +-
.../msc/framework/tensorflow/runtime/runner.py | 4 +-
.../msc/framework/tensorrt/codegen/codegen.py | 4 +-
.../msc/framework/tensorrt/frontend/translate.py | 4 +-
.../msc/framework/tensorrt/runtime/runner.py | 6 +-
.../framework/tensorrt/tools/quantize/quantizer.py | 8 +-
.../contrib/msc/framework/torch/codegen/codegen.py | 2 +-
.../msc/framework/torch/frontend/translate.py | 2 +-
.../contrib/msc/framework/torch/runtime/runner.py | 8 +-
.../contrib/msc/framework/tvm/codegen/codegen.py | 2 +-
.../contrib/msc/framework/tvm/runtime/runner.py | 8 +-
.../msc/framework/tvm/tools/quantize/method.py | 4 +-
.../msc/framework/tvm/tools/quantize/quantizer.py | 4 +-
.../msc/framework/tvm/tools/track/tracker.py | 4 +-
python/tvm/contrib/tflite_runtime.py | 4 +-
python/tvm/contrib/tvmjs.py | 30 +-
python/tvm/dlight/benchmark/bench.py | 6 +-
python/tvm/exec/disco_worker.py | 18 +-
python/tvm/exec/rpc_proxy.py | 2 +-
python/tvm/ir/base.py | 6 +-
python/tvm/meta_schedule/builder/builder.py | 10 +-
python/tvm/meta_schedule/builder/local_builder.py | 16 +-
python/tvm/meta_schedule/cost_model/mlp_model.py | 4 +-
python/tvm/meta_schedule/cost_model/xgb_model.py | 4 +-
python/tvm/meta_schedule/database/json_database.py | 4 +-
.../tvm/meta_schedule/database/memory_database.py | 4 +-
.../meta_schedule/database/schedule_fn_database.py | 4 +-
.../feature_extractor/feature_extractor.py | 10 +-
.../feature_extractor/random_feature_extractor.py | 4 +-
python/tvm/meta_schedule/relax_integration.py | 30 +-
python/tvm/meta_schedule/runner/utils.py | 6 +-
python/tvm/meta_schedule/testing/tune_utils.py | 6 +-
.../tvm/meta_schedule/testing/validate_database.py | 50 ++--
python/tvm/meta_schedule/tune.py | 4 +-
python/tvm/relax/base_py_module.py | 28 +-
python/tvm/relax/exec_builder.py | 4 +-
python/tvm/relax/expr.py | 24 +-
python/tvm/relax/frontend/common.py | 10 +-
python/tvm/relax/frontend/nn/core.py | 30 +-
python/tvm/relax/frontend/nn/modules.py | 2 +-
python/tvm/relax/frontend/nn/torch.py | 8 +-
python/tvm/relax/frontend/onnx/onnx_frontend.py | 4 +-
python/tvm/relax/frontend/torch/dynamo.py | 10 +-
python/tvm/relax/frontend/torch/fx_translator.py | 2 +-
python/tvm/relax/op/base.py | 14 +-
python/tvm/relax/op/memory/view.py | 2 +-
python/tvm/relax/op/set.py | 12 +-
python/tvm/relax/pipeline.py | 2 +-
python/tvm/relax/testing/lib_comparator.py | 8 +-
python/tvm/relax/testing/nn.py | 4 +-
python/tvm/relax/testing/vm.py | 12 +-
python/tvm/relax/training/optimizer.py | 16 +-
python/tvm/relax/training/trainer.py | 90 +++---
python/tvm/relax/transform/transform.py | 16 +-
python/tvm/rpc/client.py | 6 +-
python/tvm/rpc/testing.py | 6 +-
python/tvm/runtime/__init__.py | 6 +-
python/tvm/runtime/{ndarray.py => _tensor.py} | 46 ++--
python/tvm/runtime/disco/session.py | 62 ++---
python/tvm/runtime/executable.py | 2 +-
python/tvm/runtime/params.py | 20 +-
python/tvm/runtime/vm.py | 16 +-
.../tvm/script/ir_builder/relax/distributed/ir.py | 12 +-
python/tvm/script/ir_builder/relax/ir.py | 2 +-
python/tvm/script/ir_builder/tir/ir.py | 4 +-
python/tvm/target/detect_target.py | 2 +-
python/tvm/te/operation.py | 2 +-
python/tvm/testing/runner.py | 22 +-
python/tvm/testing/utils.py | 2 +-
python/tvm/tir/build.py | 3 +-
python/tvm/tir/function.py | 16 +-
python/tvm/tir/op.py | 6 +-
python/tvm/tir/stmt.py | 10 +-
python/tvm/tir/transform/transform.py | 18 +-
python/tvm/topi/sort.py | 4 +-
python/tvm/topi/transform.py | 4 +-
src/contrib/msc/core/ir/graph_builder.cc | 6 +-
src/contrib/msc/core/ir/graph_builder.h | 8 +-
.../msc/core/transform/bind_named_params.cc | 2 +-
src/contrib/msc/core/transform/rewrite_utils.cc | 2 +-
src/contrib/msc/core/utils.h | 2 +-
src/contrib/msc/framework/tensorflow/codegen.cc | 4 +-
src/meta_schedule/arg_info.cc | 2 +-
src/meta_schedule/builder/builder.cc | 4 +-
.../feature_extractor/feature_extractor.cc | 2 +-
.../feature_extractor/per_store_feature.cc | 20 +-
src/meta_schedule/module_equality.cc | 22 +-
src/meta_schedule/module_equality.h | 4 +-
src/node/structural_hash.cc | 6 +-
src/relax/backend/contrib/codegen_c/codegen_c.h | 12 +-
.../backend/contrib/codegen_json/codegen_json.h | 2 +-
src/relax/backend/vm/codegen_vm.cc | 10 +-
src/relax/ir/block_builder.cc | 4 +-
src/relax/ir/expr.cc | 4 +-
src/relax/op/memory/view.cc | 2 +-
src/relax/transform/bind_params.cc | 2 +-
src/relax/transform/fold_constant.cc | 16 +-
src/relax/transform/meta_schedule.cc | 8 +-
src/relax/transform/run_codegen.cc | 2 +-
src/relax/transform/utils.h | 2 +-
src/runtime/const_loader_module.cc | 54 ++--
src/runtime/const_loader_module.h | 6 +-
src/runtime/contrib/arm_compute_lib/acl_runtime.cc | 4 +-
src/runtime/contrib/bnns/bnns_json_runtime.cc | 6 +-
src/runtime/contrib/bnns/bnns_wrp.h | 16 +-
src/runtime/contrib/clml/clml_runtime.cc | 14 +-
src/runtime/contrib/clml/clml_runtime.h | 6 +-
src/runtime/contrib/coreml/coreml_runtime.h | 8 +-
src/runtime/contrib/coreml/coreml_runtime.mm | 15 +-
src/runtime/contrib/cublas/cublas_json_runtime.cc | 8 +-
src/runtime/contrib/cudnn/cudnn_json_runtime.cc | 4 +-
src/runtime/contrib/cutlass/fp16_group_gemm.cuh | 6 +-
.../contrib/cutlass/fp16_group_gemm_sm100.cu | 6 +-
.../contrib/cutlass/fp16_group_gemm_sm90.cu | 6 +-
src/runtime/contrib/cutlass/fp8_gemm.cu | 5 +-
src/runtime/contrib/cutlass/fp8_group_gemm_sm90.cu | 6 +-
.../contrib/cutlass/fp8_groupwise_scaled_gemm.cuh | 14 +-
.../fp8_groupwise_scaled_gemm_runner_sm100.cuh | 2 +-
.../fp8_groupwise_scaled_gemm_runner_sm90.cuh | 2 +-
.../cutlass/fp8_groupwise_scaled_gemm_sm100.cu | 14 +-
.../cutlass/fp8_groupwise_scaled_gemm_sm90.cu | 15 +-
.../fp8_groupwise_scaled_group_gemm_sm100.cu | 8 +-
src/runtime/contrib/cutlass/weight_preprocess.cc | 6 +-
src/runtime/contrib/dnnl/dnnl_json_runtime.cc | 4 +-
.../contrib/hipblas/hipblas_json_runtime.cc | 8 +-
src/runtime/contrib/json/json_runtime.h | 16 +-
src/runtime/contrib/mrvl/mrvl_hw_runtime.cc | 22 +-
src/runtime/contrib/mrvl/mrvl_runtime.cc | 2 +-
src/runtime/contrib/mrvl/mrvl_sw_runtime_lib.cc | 18 +-
src/runtime/contrib/msc/tensorrt_runtime.cc | 22 +-
src/runtime/contrib/mscclpp/allreduce.cu | 2 +-
src/runtime/contrib/nnapi/nnapi_runtime.cc | 6 +-
src/runtime/contrib/nvshmem/memory_allocator.cc | 6 +-
src/runtime/contrib/random/mt_random_engine.cc | 14 +-
src/runtime/contrib/tensorrt/tensorrt_builder.cc | 6 +-
src/runtime/contrib/tensorrt/tensorrt_builder.h | 2 +-
src/runtime/contrib/tensorrt/tensorrt_runtime.cc | 12 +-
src/runtime/contrib/tflite/tflite_runtime.cc | 4 +-
src/runtime/contrib/tflite/tflite_runtime.h | 14 +-
src/runtime/contrib/vllm/attention_kernels.cu | 2 +-
src/runtime/contrib/vllm/cache_alloc.cc | 18 +-
src/runtime/contrib/vllm/cache_kernels.cu | 29 +-
src/runtime/device_api.cc | 2 +-
src/runtime/disco/bcast_session.cc | 10 +-
src/runtime/disco/bcast_session.h | 8 +-
src/runtime/disco/builtin.cc | 30 +-
src/runtime/disco/disco_worker.cc | 20 +-
src/runtime/disco/distributed/socket_session.cc | 4 +-
src/runtime/disco/loader.cc | 66 ++---
src/runtime/disco/nccl/nccl.cc | 51 ++--
src/runtime/disco/protocol.h | 12 +-
src/runtime/file_utils.cc | 22 +-
src/runtime/file_utils.h | 10 +-
src/runtime/hexagon/hexagon_buffer.h | 2 +-
src/runtime/hexagon/hexagon_device_api.cc | 2 +-
src/runtime/hexagon/hexagon_vtcm_pool.h | 2 +-
src/runtime/memory/memory_manager.cc | 22 +-
src/runtime/meta_data.h | 2 +-
src/runtime/minrpc/rpc_reference.h | 14 +-
src/runtime/opencl/opencl_common.h | 6 +-
src/runtime/opencl/opencl_device_api.cc | 4 +-
src/runtime/profiling.cc | 14 +-
src/runtime/rpc/rpc_endpoint.h | 4 +-
src/runtime/rpc/rpc_local_session.cc | 12 +-
src/runtime/rpc/rpc_module.cc | 34 +--
src/runtime/rpc/rpc_session.h | 12 +-
src/runtime/{ndarray.cc => tensor.cc} | 68 +++--
src/runtime/vm/attn_backend.h | 190 +++++++------
src/runtime/vm/attn_utils.h | 303 ++++++++++-----------
src/runtime/vm/builtin.cc | 35 ++-
src/runtime/vm/executable.cc | 14 +-
src/runtime/vm/hexagon/builtin.cc | 9 +-
src/runtime/vm/kv_state.cc | 20 +-
src/runtime/vm/kv_state.h | 34 +--
src/runtime/vm/lm_support.cc | 53 ++--
src/runtime/vm/paged_kv_cache.cc | 238 ++++++++--------
src/runtime/vm/rnn_state.cc | 68 ++---
...ay_cache_support.cc => tensor_cache_support.cc} | 123 ++++-----
src/runtime/vm/vm.cc | 26 +-
src/script/ir_builder/tir/ir.cc | 4 +-
src/script/printer/relax/expr.cc | 2 +-
src/script/printer/tir/stmt.cc | 24 +-
src/support/scalars.cc | 18 +-
src/support/scalars.h | 16 +-
src/target/codegen.cc | 4 +-
src/target/llvm/codegen_llvm.cc | 2 +-
src/target/llvm/codegen_params.cc | 2 +-
src/target/llvm/codegen_params.h | 10 +-
src/target/source/codegen_c.cc | 2 +-
src/target/source/codegen_params.cc | 4 +-
src/target/source/codegen_params.h | 10 +-
src/target/source/codegen_source_base.h | 2 +-
src/target/source/source_module.cc | 2 +-
src/te/operation/create_primfunc.cc | 4 +-
src/te/operation/create_primfunc.h | 4 +-
src/tir/ir/index_map.cc | 8 +-
src/tir/ir/stmt.cc | 6 +-
src/tir/transforms/bind_params.cc | 10 +-
src/tir/transforms/extract_constants.cc | 6 +-
src/tir/transforms/ir_utils.h | 2 +-
src/tir/transforms/make_packed_api.cc | 8 +-
.../remove_weight_layout_rewrite_block.cc | 32 +--
src/topi/transform.cc | 10 +-
tests/cpp-runtime/opencl/opencl_nativeptr.cc | 6 +-
tests/cpp-runtime/opencl/texture_copy_test.cc | 38 +--
tests/cpp/ndarray_test.cc | 18 +-
tests/cpp/support/scalars_test.cc | 14 +-
.../test_minimal_target_codegen_llvm.py | 6 +-
.../test_runtime_ndarray.py | 10 +-
.../test_runtime_packed_func.py | 6 +-
tests/python/codegen/test_gpu_codegen_allreduce.py | 8 +-
tests/python/codegen/test_inject_ptx_ldg32.py | 4 +-
tests/python/codegen/test_target_codegen_blob.py | 4 +-
tests/python/codegen/test_target_codegen_bool.py | 6 +-
tests/python/codegen/test_target_codegen_c_host.py | 22 +-
.../codegen/test_target_codegen_cross_llvm.py | 6 +-
tests/python/codegen/test_target_codegen_cuda.py | 80 +++---
.../python/codegen/test_target_codegen_cuda_fp4.py | 6 +-
.../python/codegen/test_target_codegen_cuda_fp8.py | 48 ++--
tests/python/codegen/test_target_codegen_device.py | 10 +-
tests/python/codegen/test_target_codegen_extern.py | 12 +-
.../codegen/test_target_codegen_gpu_common.py | 4 +-
tests/python/codegen/test_target_codegen_llvm.py | 82 +++---
tests/python/codegen/test_target_codegen_metal.py | 22 +-
tests/python/codegen/test_target_codegen_opencl.py | 18 +-
tests/python/codegen/test_target_codegen_rocm.py | 16 +-
.../codegen/test_target_codegen_static_init.py | 4 +-
tests/python/codegen/test_target_codegen_vulkan.py | 46 ++--
tests/python/contrib/test_cblas.py | 30 +-
tests/python/contrib/test_coreml_runtime.py | 2 +-
tests/python/contrib/test_cutlass_gemm.py | 42 +--
tests/python/contrib/test_dlpack.py | 2 +-
tests/python/contrib/test_edgetpu_runtime.py | 2 +-
tests/python/contrib/test_hexagon/README_RPC.md | 12 +-
.../python/contrib/test_hexagon/infrastructure.py | 4 +-
tests/python/contrib/test_hexagon/pytest_util.py | 2 +-
.../test_hexagon/test_async_dma_pipeline.py | 6 +-
.../test_hexagon/test_benchmark_elemwise_add.py | 6 +-
.../contrib/test_hexagon/test_dma_builtin.py | 4 +-
.../contrib/test_hexagon/test_meta_schedule.py | 6 +-
.../contrib/test_hexagon/test_parallel_hvx.py | 6 +-
.../test_hexagon/test_parallel_hvx_load_vtcm.py | 18 +-
.../contrib/test_hexagon/test_parallel_scalar.py | 6 +-
.../test_relax_2d_buffer_allocation.py | 2 +-
.../contrib/test_hexagon/test_relax_integration.py | 8 +-
.../test_hexagon/test_software_pipeline_async.py | 6 +-
tests/python/contrib/test_hexagon/test_take.py | 2 +-
.../contrib/test_hexagon/test_thread_pool.py | 6 +-
.../contrib/test_hexagon/test_vtcm_bandwidth.py | 4 +-
tests/python/contrib/test_hipblas.py | 16 +-
tests/python/contrib/test_mps.py | 12 +-
tests/python/contrib/test_msc/test_plugin.py | 4 +-
.../contrib/test_msc/test_translate_relax.py | 2 +-
.../contrib/test_msc/test_translate_tensorrt.py | 4 +-
tests/python/contrib/test_random.py | 10 +-
tests/python/contrib/test_rocblas.py | 12 +-
tests/python/contrib/test_sort.py | 12 +-
tests/python/contrib/test_tflite_runtime.py | 4 +-
.../python/contrib/test_tir_triton_integration.py | 4 +-
tests/python/contrib/test_tvmjs.py | 4 +-
tests/python/disco/test_callback.py | 4 +-
tests/python/disco/test_ccl.py | 20 +-
tests/python/disco/test_loader.py | 23 +-
tests/python/disco/test_session.py | 8 +-
tests/python/driver/test_compile.py | 14 +-
tests/python/ir/test_datatype_nv_fp4.py | 2 +-
tests/python/ir/test_datatype_nv_fp8.py | 4 +-
tests/python/ir/test_ir_container.py | 6 +-
tests/python/ir/test_node_reflection.py | 12 +-
.../meta_schedule/test_meta_schedule_database.py | 4 +-
.../test_meta_schedule_feature_extractor.py | 4 +-
.../test_nnapi/test_from_exported_to_cuda.py | 4 +-
tests/python/nightly/test_nnapi/test_network.py | 2 +-
tests/python/nightly/test_nnapi/test_ops.py | 6 +-
tests/python/relax/backend/clml/utils.py | 2 +-
.../test_runtime_builtin_kv_cache_transfer.py | 14 +-
...est_runtime_builtin_kv_cache_transfer_kernel.py | 16 +-
.../relax/test_backend_dispatch_sort_scan.py | 2 +-
tests/python/relax/test_codegen_coreml.py | 42 +--
tests/python/relax/test_codegen_cublas.py | 2 +-
tests/python/relax/test_codegen_cudnn.py | 2 +-
tests/python/relax/test_codegen_cutlass.py | 20 +-
tests/python/relax/test_codegen_dnnl.py | 2 +-
tests/python/relax/test_codegen_hipblas.py | 2 +-
tests/python/relax/test_codegen_tensorrt.py | 2 +-
tests/python/relax/test_contrib_vllm.py | 16 +-
tests/python/relax/test_dataflow_inplace.py | 8 +-
tests/python/relax/test_dlpack_integration.py | 70 ++---
tests/python/relax/test_e2e_op_dynamic.py | 16 +-
tests/python/relax/test_frontend_common.py | 2 +-
tests/python/relax/test_frontend_dynamo.py | 2 +-
.../relax/test_frontend_from_exported_program.py | 8 +-
tests/python/relax/test_frontend_from_fx.py | 8 +-
tests/python/relax/test_frontend_nn_debug.py | 4 +-
.../python/relax/test_frontend_nn_extern_module.py | 8 +-
tests/python/relax/test_frontend_nn_op.py | 32 ++-
tests/python/relax/test_frontend_onnx.py | 4 +-
tests/python/relax/test_frontend_stablehlo.py | 6 +-
.../relax/test_meta_schedule_relax_integration.py | 6 +-
tests/python/relax/test_op_datatype.py | 6 +-
tests/python/relax/test_op_gradient_numeric.py | 8 +-
tests/python/relax/test_op_inspect.py | 20 +-
tests/python/relax/test_op_misc.py | 2 +-
tests/python/relax/test_op_take.py | 16 +-
tests/python/relax/test_op_view.py | 22 +-
tests/python/relax/test_pipeline.py | 8 +-
tests/python/relax/test_pytorch_integration.py | 2 +-
tests/python/relax/test_relax_operators.py | 69 ++---
tests/python/relax/test_runtime_builtin.py | 42 +--
...runtime_builtin_paged_attention_kv_cache_cpu.py | 12 +-
..._builtin_paged_attention_kv_cache_flashinfer.py | 14 +-
...ltin_paged_attention_kv_cache_mla_flashinfer.py | 26 +-
...ime_builtin_paged_attention_kv_cache_mla_tir.py | 26 +-
...runtime_builtin_paged_attention_kv_cache_tir.py | 14 +-
.../python/relax/test_runtime_builtin_rnn_state.py | 23 +-
.../relax/test_runtime_sampling_flashinfer.py | 4 +-
tests/python/relax/test_tir_call_source_kernel.py | 4 +-
.../relax/test_training_optimizer_numeric.py | 2 +-
tests/python/relax/test_transform_bind_params.py | 12 +-
tests/python/relax/test_transform_codegen_pass.py | 4 +-
tests/python/relax/test_transform_cse.py | 8 +-
.../python/relax/test_transform_few_shot_tuning.py | 4 +-
.../test_transform_fold_batch_norm_to_conv2d.py | 22 +-
tests/python/relax/test_transform_fold_constant.py | 8 +-
.../relax/test_transform_gradient_numeric.py | 12 +-
.../relax/test_transform_lazy_transform_params.py | 2 +-
.../relax/test_transform_to_mixed_precision.py | 6 +-
.../relax/test_vm_alloc_storage_with_scope.py | 2 +-
tests/python/relax/test_vm_build.py | 134 ++++-----
tests/python/relax/test_vm_builtin.py | 4 +-
tests/python/relax/test_vm_callback_function.py | 4 +-
tests/python/relax/test_vm_codegen_only.py | 28 +-
tests/python/relax/test_vm_cuda_graph.py | 6 +-
tests/python/relax/test_vm_execbuilder.py | 34 +--
tests/python/relax/test_vm_instrument.py | 4 +-
tests/python/relax/test_vm_multi_device.py | 20 +-
tests/python/relax/test_vm_profiler.py | 4 +-
.../python/runtime/test_evaluator_with_preproc.py | 6 +-
tests/python/runtime/test_executable.py | 40 +--
tests/python/runtime/test_runtime_container.py | 2 +-
tests/python/runtime/test_runtime_dlpack.py | 8 +-
tests/python/runtime/test_runtime_extension.py | 2 +-
tests/python/runtime/test_runtime_measure.py | 2 +-
tests/python/runtime/test_runtime_module_load.py | 22 +-
tests/python/runtime/test_runtime_nd_array.py | 56 ++--
tests/python/runtime/test_runtime_rpc.py | 32 +--
tests/python/runtime/test_runtime_trace.py | 44 +--
tests/python/target/test_arm_target.py | 12 +-
tests/python/te/test_te_create_primfunc.py | 8 +-
tests/python/tir-base/test_tir_imm_values.py | 2 +-
tests/python/tir-base/test_tir_index_map.py | 12 +-
tests/python/tir-base/test_tir_intrin.py | 28 +-
tests/python/tir-base/test_tir_ptx_cp_async.py | 12 +-
tests/python/tir-base/test_tir_ptx_ldmatrix.py | 4 +-
tests/python/tir-base/test_tir_ptx_mma.py | 102 +++----
tests/python/tir-base/test_tir_ptx_mma_sp.py | 16 +-
.../tir-base/test_tir_structural_equal_hash.py | 10 +-
.../python/tir-base/test_tir_te_extern_primfunc.py | 30 +-
.../test_tir_schedule_decompose_padding.py | 6 +-
.../test_tir_schedule_rolling_buffer.py | 6 +-
..._tir_schedule_tensorize_ldmatrix_mma_numeric.py | 6 +-
.../test_tir_schedule_tensorize_mfma_numeric.py | 6 +-
.../test_tir_transform_inject_ptx_async_copy.py | 14 +-
.../test_tir_transform_inject_software_pipeline.py | 6 +-
.../test_tir_transform_lower_intrin.py | 6 +-
.../test_tir_transform_lower_tvm_builtin.py | 2 +-
.../test_tir_transform_make_packed_api.py | 8 +-
.../tvmscript/test_tvmscript_ir_builder_tir.py | 4 +-
tests/python/tvmscript/test_tvmscript_ops.py | 14 +-
web/.gitignore | 2 +-
web/apps/browser/rpc_server.html | 16 +-
web/emcc/wasm_runtime.cc | 28 +-
web/src/artifact_cache.ts | 28 +-
web/src/ctypes.ts | 4 +-
web/src/index.ts | 6 +-
web/src/rpc_server.ts | 24 +-
web/src/runtime.ts | 198 +++++++-------
web/tests/node/test_packed_func.js | 2 +-
web/tests/node/{test_ndarray.js => test_tensor.js} | 0
web/tests/python/relax_rpc_test.py | 4 +-
web/tests/python/webgpu_rpc_test.py | 4 +-
483 files changed, 3675 insertions(+), 3654 deletions(-)
diff --git a/apps/android_rpc/app/src/main/jni/tvm_runtime.h b/apps/android_rpc/app/src/main/jni/tvm_runtime.h
index 94fc642289..b0cb033e88 100644
--- a/apps/android_rpc/app/src/main/jni/tvm_runtime.h
+++ b/apps/android_rpc/app/src/main/jni/tvm_runtime.h
@@ -43,8 +43,8 @@
#include "../ffi/src/ffi/extra/module.cc"
#include "../ffi/src/ffi/extra/testing.cc"
#include "../ffi/src/ffi/function.cc"
-#include "../ffi/src/ffi/ndarray.cc"
#include "../ffi/src/ffi/object.cc"
+#include "../ffi/src/ffi/tensor.cc"
#include "../ffi/src/ffi/traceback.cc"
#include "../src/runtime/cpu_device_api.cc"
#include "../src/runtime/device_api.cc"
@@ -52,7 +52,6 @@
#include "../src/runtime/logging.cc"
#include "../src/runtime/memory/memory_manager.cc"
#include "../src/runtime/minrpc/minrpc_logger.cc"
-#include "../src/runtime/ndarray.cc"
#include "../src/runtime/profiling.cc"
#include "../src/runtime/registry.cc"
#include "../src/runtime/rpc/rpc_channel.cc"
@@ -63,6 +62,7 @@
#include "../src/runtime/rpc/rpc_server_env.cc"
#include "../src/runtime/rpc/rpc_session.cc"
#include "../src/runtime/rpc/rpc_socket_impl.cc"
+#include "../src/runtime/tensor.cc"
#include "../src/runtime/thread_pool.cc"
#include "../src/runtime/threading_backend.cc"
#include "../src/runtime/workspace_pool.cc"
diff --git a/apps/android_rpc/tests/android_rpc_test.py b/apps/android_rpc/tests/android_rpc_test.py
index b9c6995729..b1548df3e1 100644
--- a/apps/android_rpc/tests/android_rpc_test.py
+++ b/apps/android_rpc/tests/android_rpc_test.py
@@ -72,8 +72,8 @@ def test_rpc_module():
dev = remote.cl(0)
remote.upload(path_dso_cl)
f1 = remote.load_module("dev_lib_cl.so")
- a = tvm.nd.array(a_np, dev)
- b = tvm.nd.array(np.zeros(1024, dtype=A.dtype), dev)
+ a = tvm.runtime.tensor(a_np, dev)
+ b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
time_f = f1.time_evaluator(f1.entry_name, dev, number=10)
cost = time_f(a, b).mean
print("%g secs/op\n" % cost)
diff --git a/apps/hexagon_launcher/launcher_core.h b/apps/hexagon_launcher/launcher_core.h
index 5e62774607..be5a4ee94d 100644
--- a/apps/hexagon_launcher/launcher_core.h
+++ b/apps/hexagon_launcher/launcher_core.h
@@ -25,7 +25,7 @@
#include <tvm/ffi/function.h>
#include <tvm/runtime/data_type.h>
#include <tvm/runtime/module.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <string>
#include <vector>
diff --git a/apps/hexagon_launcher/launcher_hexagon.cc b/apps/hexagon_launcher/launcher_hexagon.cc
index bd1df4aa62..64b795d8f4 100644
--- a/apps/hexagon_launcher/launcher_hexagon.cc
+++ b/apps/hexagon_launcher/launcher_hexagon.cc
@@ -137,7 +137,7 @@ AEEResult __QAIC_HEADER(launcher_rpc_set_input)(remote_handle64 handle, int inpu
};
DLManagedTensor managed{tensor, /*manager_ctx*/ nullptr, /*deleter*/ nullptr};
- auto input = tvm::runtime::NDArray::FromDLPack(&managed);
+ auto input = tvm::runtime::Tensor::FromDLPack(&managed);
tvm::ffi::Function set_input = get_module_func(TheModel->model_executor, "set_input");
set_input(input_idx, input);
@@ -172,17 +172,17 @@ AEEResult __QAIC_HEADER(launcher_rpc_get_output)(remote_handle64 handle, int out
}
tvm::ffi::Function get_output = get_module_func(TheModel->model_executor, "get_output");
- tvm::runtime::NDArray output = get_output(output_idx);
+ tvm::runtime::Tensor output = get_output(output_idx);
std::vector<int64_t> shape_vec{output->shape, output->shape + output->ndim};
- auto* container = new tvm::runtime::NDArray::Container(
- static_cast<void*>(output_value), shape_vec, output->dtype, Model::external());
+ auto* container = new tvm::runtime::Tensor::Container(static_cast<void*>(output_value), shape_vec,
+ output->dtype, Model::external());
container->SetDeleter([](tvm::Object* container) {
- delete static_cast<tvm::runtime::NDArray::Container*>(container);
+ delete static_cast<tvm::runtime::Tensor::Container*>(container);
});
- tvm::runtime::NDArray host_output(tvm::runtime::GetObjectPtr<tvm::runtime::Object>(container));
+ tvm::runtime::Tensor host_output(tvm::runtime::GetObjectPtr<tvm::runtime::Object>(container));
if (meta_size != 0) {
auto* meta = reinterpret_cast<tensor_meta*>(output_meta);
diff --git a/apps/ios_rpc/tests/ios_rpc_test.py b/apps/ios_rpc/tests/ios_rpc_test.py
index 0e563ee1b6..67b9cd22ae 100644
--- a/apps/ios_rpc/tests/ios_rpc_test.py
+++ b/apps/ios_rpc/tests/ios_rpc_test.py
@@ -72,8 +72,8 @@ def test_rpc_module(host, port, key, mode):
dev = remote.metal(0)
f1 = remote.load_module("dev_lib.dylib")
a_np = np.random.uniform(size=1024).astype(A.dtype)
- a = tvm.nd.array(a_np, dev)
- b = tvm.nd.array(np.zeros(1024, dtype=A.dtype), dev)
+ a = tvm.runtime.tensor(a_np, dev)
+ b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
time_f = f1.time_evaluator(f1.entry_name, dev, number=10)
cost = time_f(a, b).mean
print("Metal: %g secs/op" % cost)
diff --git a/docs/arch/index.rst b/docs/arch/index.rst
index 1acd38fb04..4985e91c0b 100644
--- a/docs/arch/index.rst
+++ b/docs/arch/index.rst
@@ -133,7 +133,7 @@ The main goal of TVM's runtime is to provide a minimal API for loading and execu
import tvm
# Example runtime execution program in python, with type annotated
mod: tvm.runtime.Module = tvm.runtime.load_module("compiled_artifact.so")
- arr: tvm.runtime.NDArray = tvm.nd.array([1, 2, 3], device=tvm.cuda(0))
+ arr: tvm.runtime.Tensor = tvm.runtime.tensor([1, 2, 3], device=tvm.cuda(0))
fun: tvm.runtime.PackedFunc = mod["addone"]
fun(arr)
print(arr.numpy())
@@ -142,7 +142,7 @@ The main goal of TVM's runtime is to provide a minimal API for loading and execu
:py:class:`tvm.runtime.Module` encapsulates the result of compilation. A runtime.Module contains a GetFunction method to obtain PackedFuncs by name.
:py:class:`tvm.runtime.PackedFunc` is a type-erased function interface for both the generated functions. A runtime.PackedFunc can take arguments and return values with the
-following types: POD types(int, float), string, runtime.PackedFunc, runtime.Module, runtime.NDArray, and other sub-classes of runtime.Object.
+following types: POD types(int, float), string, runtime.PackedFunc, runtime.Module, runtime.Tensor, and other sub-classes of runtime.Object.
:py:class:`tvm.runtime.Module` and :py:class:`tvm.runtime.PackedFunc` are powerful mechanisms to modularize the runtime. For example, to get the above `addone` function on CUDA, we can use LLVM to generate the host-side code to compute the launching parameters(e.g. size of the thread groups) and then call into another PackedFunc from a CUDAModule that is backed by the CUDA driver API. The same mechanism can be used for OpenCL kernels.
@@ -155,7 +155,7 @@ The above example only deals with a simple `addone` function. The code snippet b
factory: tvm.runtime.Module = tvm.runtime.load_module("resnet18.so")
# Create a stateful graph execution module for resnet18 on cuda(0)
gmod: tvm.runtime.Module = factory["resnet18"](tvm.cuda(0))
- data: tvm.runtime.NDArray = get_input_data()
+ data: tvm.runtime.Tensor = get_input_data()
# set input
gmod["set_input"](0, data)
# execute the model
diff --git a/docs/deep_dive/tensor_ir/tutorials/tir_creation.py b/docs/deep_dive/tensor_ir/tutorials/tir_creation.py
index 3d07f6227b..74b4406061 100644
--- a/docs/deep_dive/tensor_ir/tutorials/tir_creation.py
+++ b/docs/deep_dive/tensor_ir/tutorials/tir_creation.py
@@ -204,9 +204,9 @@ class DynamicShapeModule:
def evaluate_dynamic_shape(lib: tvm.runtime.Module, m: int, n: int, k: int):
- A = tvm.nd.array(np.random.uniform(size=(m, k)).astype("float32"))
- B = tvm.nd.array(np.random.uniform(size=(k, n)).astype("float32"))
- C = tvm.nd.array(np.zeros((m, n), dtype="float32"))
+ A = tvm.runtime.tensor(np.random.uniform(size=(m, k)).astype("float32"))
+ B = tvm.runtime.tensor(np.random.uniform(size=(k, n)).astype("float32"))
+ C = tvm.runtime.tensor(np.zeros((m, n), dtype="float32"))
lib(A, B, C)
return C.numpy()
diff --git a/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py b/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py
index 702b53011b..eb1b2eb020 100644
--- a/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py
+++ b/docs/deep_dive/tensor_ir/tutorials/tir_transformation.py
@@ -72,9 +72,9 @@ a_np = np.random.uniform(size=(128, 128)).astype("float32")
b_np = np.random.uniform(size=(128, 128)).astype("float32")
c_np = a_np @ b_np
-a_nd = tvm.nd.array(a_np)
-b_nd = tvm.nd.array(b_np)
-c_nd = tvm.nd.array(np.zeros((128, 128), dtype="float32"))
+a_nd = tvm.runtime.tensor(a_np)
+b_nd = tvm.runtime.tensor(b_np)
+c_nd = tvm.runtime.tensor(np.zeros((128, 128), dtype="float32"))
def evaluate(mod: tvm.IRModule):
diff --git a/docs/get_started/tutorials/ir_module.py b/docs/get_started/tutorials/ir_module.py
index c53d0ca5ef..8bb8fb77a4 100644
--- a/docs/get_started/tutorials/ir_module.py
+++ b/docs/get_started/tutorials/ir_module.py
@@ -237,7 +237,7 @@ dev = tvm.cpu()
vm = relax.VirtualMachine(exec, dev)
raw_data = np.random.rand(1, 784).astype("float32")
-data = tvm.nd.array(raw_data, dev)
+data = tvm.runtime.tensor(raw_data, dev)
cpu_out = vm["main"](data, *params_from_torch["main"]).numpy()
print(cpu_out)
@@ -267,8 +267,8 @@ exec = tvm.compile(gpu_mod, target="cuda")
dev = tvm.device("cuda", 0)
vm = relax.VirtualMachine(exec, dev)
# Need to allocate data and params on GPU device
-data = tvm.nd.array(raw_data, dev)
-gpu_params = [tvm.nd.array(p, dev) for p in params_from_torch["main"]]
+data = tvm.runtime.tensor(raw_data, dev)
+gpu_params = [tvm.runtime.tensor(p, dev) for p in params_from_torch["main"]]
gpu_out = vm["main"](data, *gpu_params).numpy()
print(gpu_out)
diff --git a/docs/get_started/tutorials/quick_start.py b/docs/get_started/tutorials/quick_start.py
index 1153108c96..0c2e087f53 100644
--- a/docs/get_started/tutorials/quick_start.py
+++ b/docs/get_started/tutorials/quick_start.py
@@ -141,9 +141,9 @@ ex = tvm.compile(mod, target)
device = tvm.cpu()
vm = relax.VirtualMachine(ex, device)
data = np.random.rand(1, 784).astype("float32")
-tvm_data = tvm.nd.array(data, device=device)
+tvm_data = tvm.runtime.tensor(data, device=device)
params = [np.random.rand(*param.shape).astype("float32") for _, param in param_spec]
-params = [tvm.nd.array(param, device=device) for param in params]
+params = [tvm.runtime.tensor(param, device=device) for param in params]
print(vm["forward"](tvm_data, *params).numpy())
################################################################################
@@ -158,14 +158,14 @@ print(vm["forward"](tvm_data, *params).numpy())
# prefill_logits = vm["prefill"](inputs, weight, kv_cache)
# decoded_logits = vm["decode"](inputs, weight, kv_cache)
#
-# - TVM runtime comes with native data structures, such as NDArray, can also have zero
+# - TVM runtime comes with native data structures, such as Tensor, can also have zero
# copy exchange with existing ecosystem (DLPack exchange with PyTorch)
#
# .. code-block:: Python
#
-# # Convert PyTorch tensor to TVM NDArray
+# # Convert PyTorch tensor to TVM Tensor
# x_tvm = tvm.nd.from_dlpack(x_torch.to_dlpack())
-# # Convert TVM NDArray to PyTorch tensor
+# # Convert TVM Tensor to PyTorch tensor
# x_torch = torch.from_dlpack(x_tvm.to_dlpack())
#
# - TVM runtime works in non-python environments, so it works on settings such as mobile
@@ -175,14 +175,14 @@ print(vm["forward"](tvm_data, *params).numpy())
# // C++ snippet
# runtime::Module vm = ex.GetFunction("load_executable")();
# vm.GetFunction("init")(...);
-# NDArray out = vm.GetFunction("prefill")(data, weight, kv_cache);
+# Tensor out = vm.GetFunction("prefill")(data, weight, kv_cache);
#
# .. code-block:: Java
#
# // Java snippet
# Module vm = ex.getFunction("load_executable").invoke();
# vm.getFunction("init").pushArg(...).invoke;
-# NDArray out = vm.getFunction("prefill").pushArg(data).pushArg(weight).pushArg(kv_cache).invoke();
+# Tensor out = vm.getFunction("prefill").pushArg(data).pushArg(weight).pushArg(kv_cache).invoke();
#
################################################################################
diff --git a/docs/how_to/tutorials/cross_compilation_and_rpc.py b/docs/how_to/tutorials/cross_compilation_and_rpc.py
index a6b7206b3e..b142eaa549 100644
--- a/docs/how_to/tutorials/cross_compilation_and_rpc.py
+++ b/docs/how_to/tutorials/cross_compilation_and_rpc.py
@@ -182,8 +182,8 @@ func = remote.load_module("lib.tar")
# create arrays on the remote device
dev = remote.cpu()
-a = tvm.nd.array(np.random.uniform(size=1024).astype(A.dtype), dev)
-b = tvm.nd.array(np.zeros(1024, dtype=A.dtype), dev)
+a = tvm.runtime.tensor(np.random.uniform(size=1024).astype(A.dtype), dev)
+b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
# the function will run on the remote device
func(a, b)
np.testing.assert_equal(b.numpy(), a.numpy() + 1)
@@ -249,8 +249,8 @@ def run_opencl():
# run
dev = remote.cl()
- a = tvm.nd.array(np.random.uniform(size=1024).astype(A.dtype), dev)
- b = tvm.nd.array(np.zeros(1024, dtype=A.dtype), dev)
+ a = tvm.runtime.tensor(np.random.uniform(size=1024).astype(A.dtype), dev)
+ b = tvm.runtime.tensor(np.zeros(1024, dtype=A.dtype), dev)
func(a, b)
np.testing.assert_equal(b.numpy(), a.numpy() + 1)
print("OpenCL test passed!")
diff --git a/docs/how_to/tutorials/customize_opt.py b/docs/how_to/tutorials/customize_opt.py
index d215654019..2e2747d61f 100644
--- a/docs/how_to/tutorials/customize_opt.py
+++ b/docs/how_to/tutorials/customize_opt.py
@@ -209,8 +209,8 @@ ex = tvm.compile(mod, target="cuda")
dev = tvm.device("cuda", 0)
vm = relax.VirtualMachine(ex, dev)
# Need to allocate data and params on GPU device
-data = tvm.nd.array(np.random.rand(*input_shape).astype("float32"), dev)
-gpu_params = [tvm.nd.array(np.random.rand(*p.shape).astype(p.dtype), dev) for _, p in params]
+data = tvm.runtime.tensor(np.random.rand(*input_shape).astype("float32"), dev)
+gpu_params = [tvm.runtime.tensor(np.random.rand(*p.shape).astype(p.dtype), dev) for _, p in params]
gpu_out = vm["forward"](data, *gpu_params).numpy()
print(gpu_out)
diff --git a/docs/how_to/tutorials/e2e_opt_model.py b/docs/how_to/tutorials/e2e_opt_model.py
index 88cc86bfa8..9f89e744a3 100644
--- a/docs/how_to/tutorials/e2e_opt_model.py
+++ b/docs/how_to/tutorials/e2e_opt_model.py
@@ -117,8 +117,8 @@ if not IS_IN_CI:
dev = tvm.device("cuda", 0)
vm = relax.VirtualMachine(ex, dev)
# Need to allocate data and params on GPU device
- gpu_data = tvm.nd.array(np.random.rand(1, 3, 224, 224).astype("float32"), dev)
- gpu_params = [tvm.nd.array(p, dev) for p in params["main"]]
+ gpu_data = tvm.runtime.tensor(np.random.rand(1, 3, 224, 224).astype("float32"), dev)
+ gpu_params = [tvm.runtime.tensor(p, dev) for p in params["main"]]
gpu_out = vm["main"](gpu_data, *gpu_params).numpy()
print(gpu_out.shape)
diff --git a/docs/how_to/tutorials/optimize_llm.py b/docs/how_to/tutorials/optimize_llm.py
index 8cc674920d..0e82b05559 100644
--- a/docs/how_to/tutorials/optimize_llm.py
+++ b/docs/how_to/tutorials/optimize_llm.py
@@ -489,7 +489,7 @@ if not IS_IN_CI:
# Convert params into ndarray
params = [
- tvm.nd.array(param_dict[k].astype("float16"), device=dev) for k in named_params.keys()
+ tvm.runtime.tensor(param_dict[k].astype("float16"), device=dev) for k in named_params.keys()
]
@@ -523,7 +523,7 @@ if not IS_IN_CI:
input_len = len(prompt)
# Load prompt tokens into TVM ndarray on the target device
- tokens = tvm.nd.array(np.array(prompt).astype("int32"), device=dev)
+ tokens = tvm.runtime.tensor(np.array(prompt).astype("int32"), device=dev)
######################################################################
# Create the KVCache
@@ -609,7 +609,7 @@ if not IS_IN_CI:
print("The generated token:")
while last_token != tokenizer.eos_token_id:
- tokens = tvm.nd.array(np.array([last_token]).astype("int32"), device=dev)
+ tokens = tvm.runtime.tensor(np.array([last_token]).astype("int32"), device=dev)
hidden_states = embed(tokens, params)
begin_forward_func(kv_cache, ShapeTuple([seq_id]), ShapeTuple([1]))
logits, kv_cache = vm["decode"](hidden_states, kv_cache, params)
diff --git a/docs/reference/api/python/index.rst b/docs/reference/api/python/index.rst
index a233c69a01..c63784781c 100644
--- a/docs/reference/api/python/index.rst
+++ b/docs/reference/api/python/index.rst
@@ -34,7 +34,6 @@ Python API
:caption: tvm.runtime
runtime/runtime
- runtime/ndarray
runtime/vm
runtime/disco
runtime/profiling
diff --git a/docs/reference/api/python/runtime/ndarray.rst b/docs/reference/api/python/runtime/ndarray.rst
deleted file mode 100644
index 8c794f04b1..0000000000
--- a/docs/reference/api/python/runtime/ndarray.rst
+++ /dev/null
@@ -1,21 +0,0 @@
-.. 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.
-
-tvm.runtime.ndarray
--------------------
-.. automodule:: tvm.runtime.ndarray
- :members:
diff --git a/docs/reference/api/python/runtime/runtime.rst b/docs/reference/api/python/runtime/runtime.rst
index 4dd9d96533..ae373080ae 100644
--- a/docs/reference/api/python/runtime/runtime.rst
+++ b/docs/reference/api/python/runtime/runtime.rst
@@ -19,4 +19,3 @@ tvm.runtime
-----------
.. automodule:: tvm.runtime
:members:
- :exclude-members: NDArray
diff --git a/ffi/CMakeLists.txt b/ffi/CMakeLists.txt
index 90f1f89cbb..94395d2343 100644
--- a/ffi/CMakeLists.txt
+++ b/ffi/CMakeLists.txt
@@ -57,7 +57,7 @@ set(tvm_ffi_objs_sources
"${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/object.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/error.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/function.cc"
- "${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/ndarray.cc"
+ "${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/tensor.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/dtype.cc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/ffi/container.cc"
)
@@ -189,7 +189,7 @@ if (TVM_FFI_BUILD_PYTHON_MODULE)
${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython/dtype.pxi
${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython/error.pxi
${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython/function.pxi
- ${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython/ndarray.pxi
+ ${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython/tensor.pxi
${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython/object.pxi
${CMAKE_CURRENT_SOURCE_DIR}/python/tvm_ffi/cython/string.pxi
)
diff --git a/ffi/docs/.gitignore b/ffi/docs/.gitignore
index e35d8850c9..0b4a3621d9 100644
--- a/ffi/docs/.gitignore
+++ b/ffi/docs/.gitignore
@@ -1 +1,2 @@
_build
+**/generated/*.rst
diff --git a/ffi/docs/Makefile b/ffi/docs/Makefile
index f589272b18..ff28cb0cbc 100644
--- a/ffi/docs/Makefile
+++ b/ffi/docs/Makefile
@@ -25,7 +25,7 @@ BUILDDIR = _build
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
-.PHONY: help Makefile livehtml
+.PHONY: help Makefile livehtml clean
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
@@ -34,3 +34,7 @@ help:
livehtml:
@sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+clean:
+ rm -rf $(BUILDDIR)
+ rm -rf reference/python/generated
diff --git a/ffi/docs/concepts/abi_overview.md b/ffi/docs/concepts/abi_overview.md
index 6d2fd10074..1182578964 100644
--- a/ffi/docs/concepts/abi_overview.md
+++ b/ffi/docs/concepts/abi_overview.md
@@ -219,17 +219,17 @@ typedef struct TVMFFIObject {
- `deleter` ensures that objects allocated from one language/runtime can be safely deleted in another.
The object format provides a unified way to manage object life-cycle and dynamic type casting
-for heap-allocated objects, including Shape, NDArray,
+for heap-allocated objects, including Shape, Tensor,
Function, Array, Map and other custom objects.
-### DLPack Compatible NDArray
+### DLPack Compatible Tensor
-We provide first-class support for DLPack raw unmanaged pointer support as well as a managed NDArray object that
-directly adopts the DLPack DLTensor layout. The overall layout of the NDArray object is as follows:
+We provide first-class support for DLPack raw unmanaged pointer support as well as a managed Tensor object that
+directly adopts the DLPack DLTensor layout. The overall layout of the Tensor object is as follows:
```c++
-struct NDArrayObj: public ffi::Object, public DLTensor {
+struct TensorObj: public ffi::Object, public DLTensor {
};
```
@@ -241,7 +241,7 @@ DLTensor* ReadDLTensorPtr(const TVMFFIAny *value) {
if (value->type_index == kTVMFFIDLTensorPtr) {
return static_cast<DLTensor*>(value->v_ptr);
}
- assert(value->type_index == kTVMFFINDArray);
+ assert(value->type_index == kTVMFFITensor);
return reinterpret_cast<DLTensor*>(
reinterpret_cast<char*>(value->v_obj) + sizeof(TVMFFIObject));
}
diff --git a/ffi/docs/conf.py b/ffi/docs/conf.py
index 317b58d3f6..b97ed78ef8 100644
--- a/ffi/docs/conf.py
+++ b/ffi/docs/conf.py
@@ -20,6 +20,9 @@ import sys
import tomli
+
+os.environ["TVM_FFI_BUILD_DOCS"] = "1"
+
# -- General configuration ------------------------------------------------
# Load version from pyproject.toml
diff --git a/ffi/docs/get_started/quick_start.md b/ffi/docs/get_started/quick_start.md
index 1f6b25ef6d..7eb3b97727 100644
--- a/ffi/docs/get_started/quick_start.md
+++ b/ffi/docs/get_started/quick_start.md
@@ -194,7 +194,7 @@ and can be loaded in other language environments, such as c++. The following cod
shows how to run the example exported function in C++.
```cpp
-#include <tvm/ffi/container/ndarray.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/extra/module.h>
void CallAddOne(DLTensor* x, DLTensor *y) {
diff --git a/ffi/docs/guides/cpp_guide.md b/ffi/docs/guides/cpp_guide.md
index 84b6fd8dc9..fdbd7f7d7b 100644
--- a/ffi/docs/guides/cpp_guide.md
+++ b/ffi/docs/guides/cpp_guide.md
@@ -342,18 +342,18 @@ Error type. Similarly, when we call a Python callback from C++, the error will b
into the right error kind and message.
-## NDArray
+## Tensor
For many use cases, we do not need to manage the nd-array/Tensor memory.
In such cases, `DLTensor*` can be used as the function arguments.
There can be cases for a managed container for multi-dimensional arrays.
-`ffi::NDArray` is a minimal container to provide such support.
+`ffi::Tensor` is a minimal container to provide such support.
Notably, specific logic of device allocations and array operations are non-goals
-of the FFI. Instead, we provide minimal generic API `ffi::NDArray::FromNDAlloc`
-to enable flexible customization of NDArray allocation.
+of the FFI. Instead, we provide minimal generic API `ffi::Tensor::FromNDAlloc`
+to enable flexible customization of Tensor allocation.
```cpp
-#include <tvm/ffi/container/ndarray.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/container/shape.h>
struct CPUNDAlloc {
@@ -363,19 +363,19 @@ struct CPUNDAlloc {
void FreeData(DLTensor* tensor) { free(tensor->data); }
};
-void ExampleNDArray() {
+void ExampleTensor() {
namespace ffi = tvm::ffi;
ffi::Shape shape = {1, 2, 3};
DLDataType dtype = {kDLFloat, 32, 1};
DLDevice device = {kDLCPU, 0};
- ffi::NDArray nd = ffi::NDArray::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
- // now nd is a managed ndarray
+ ffi::Tensor tensor = ffi::Tensor::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
+ // now tensor is a managed tensor
}
```
The above example shows how we define `CPUNDAlloc` that customizes `AllocData`
-and `FreeData` behavior. The CPUNDAlloc struct will be kept alive with the NDArray object.
-This pattern allows us to implement various NDArray allocations using the same API:
+and `FreeData` behavior. The CPUNDAlloc struct will be kept alive with the Tensor object.
+This pattern allows us to implement various Tensor allocations using the same API:
- For CUDA allocation, we can change malloc to cudaMalloc
- For memory-pool based allocation, we can update `CPUNDAlloc` to keep a strong reference to the pool,
@@ -387,27 +387,27 @@ of managed shapes and we provide quick conversions from standard vector types.
### DLPack Conversion
-We provide first-class DLPack support to the `ffi::NDArray` that enables efficient exchange
+We provide first-class DLPack support to the `ffi::Tensor` that enables efficient exchange
through the DLPack Protocol.
```cpp
-#include <tvm/ffi/container/ndarray.h>
+#include <tvm/ffi/container/tensor.h>
-void ExampleNDArrayDLPack() {
+void ExampleTensorDLPack() {
namespace ffi = tvm::ffi;
ffi::Shape shape = {1, 2, 3};
DLDataType dtype = {kDLFloat, 32, 1};
DLDevice device = {kDLCPU, 0};
- ffi::NDArray nd = ffi::NDArray::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
+ ffi::Tensor tensor = ffi::Tensor::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
// convert to DLManagedTensorVersioned
DLManagedTensorVersioned* dlpack = nd.ToDLPackVersioned();
// load back from DLManagedTensorVersioned
- ffi::NDArray nd2 = ffi::NDArray::FromDLPackVersioned(dlpack);
+ ffi::Tensor tensor2 = ffi::Tensor::FromDLPackVersioned(dlpack);
}
```
These APIs are also available through the C APIs
-`TVMFFINDArrayFromDLPackVersioned` and `TVMFFINDArrayToDLPackVersioned`.
+`TVMFFITensorFromDLPackVersioned` and `TVMFFITensorToDLPackVersioned`.
## String and Bytes
diff --git a/ffi/docs/guides/python_guide.md b/ffi/docs/guides/python_guide.md
index 2d588049ae..5ac7f318be 100644
--- a/ffi/docs/guides/python_guide.md
+++ b/ffi/docs/guides/python_guide.md
@@ -50,9 +50,9 @@ mod.add_one_cpu(x, y)
In this case, `tvm_ffi.load_module` will return a `tvm_ffi.Module` class that contains
the exported functions. You can access the functions by their names.
-## NDArray
+## Tensor
-`tvm_ffi` provides a managed DLPack-compatible NDArray.
+`tvm_ffi` provides a managed DLPack-compatible Tensor.
```python
import numpy as np
@@ -65,9 +65,9 @@ tvm_array = tvm_ffi.from_dlpack(np_data)
np_result = np.from_dlpack(tvm_array)
```
-In most cases, however, you do not have to explicitly create NDArrays.
+In most cases, however, you do not have to explicitly create Tensors.
The Python interface can take in `torch.Tensor` and `numpy.ndarray` objects
-and automatically convert them to `tvm_ffi.NDArray`.
+and automatically convert them to `tvm_ffi.Tensor`.
## Functions and Callbacks
diff --git a/ffi/examples/quick_start/run_example.py b/ffi/examples/quick_start/run_example.py
index cdd60916b9..456e58ce91 100644
--- a/ffi/examples/quick_start/run_example.py
+++ b/ffi/examples/quick_start/run_example.py
@@ -32,7 +32,7 @@ def run_add_one_cpu():
x = numpy.array([1, 2, 3, 4, 5], dtype=numpy.float32)
y = numpy.empty_like(x)
# tvm-ffi automatically handles DLPack compatible tensors
- # torch tensors can be viewed as ffi::NDArray or DLTensor*
+ # torch tensors can be viewed as ffi::Tensor or DLTensor*
# in the background
mod.add_one_cpu(x, y)
print("numpy.result after add_one(x, y)")
@@ -44,7 +44,7 @@ def run_add_one_cpu():
x = torch.tensor([1, 2, 3, 4, 5], dtype=torch.float32)
y = torch.empty_like(x)
# tvm-ffi automatically handles DLPack compatible tensors
- # torch tensors can be viewed as ffi::NDArray or DLTensor*
+ # torch tensors can be viewed as ffi::Tensor or DLTensor*
# in the background
mod.add_one_cpu(x, y)
print("torch.result after add_one(x, y)")
diff --git a/ffi/examples/quick_start/src/run_example.cc b/ffi/examples/quick_start/src/run_example.cc
index e9993b034f..90e61d170b 100644
--- a/ffi/examples/quick_start/src/run_example.cc
+++ b/ffi/examples/quick_start/src/run_example.cc
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-#include <tvm/ffi/container/ndarray.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/extra/module.h>
// This file shows how to load the same compiled module and interact with it in C++
@@ -27,16 +27,16 @@ struct CPUNDAlloc {
void FreeData(DLTensor* tensor) { free(tensor->data); }
};
-inline ffi::NDArray Empty(ffi::Shape shape, DLDataType dtype, DLDevice device) {
- return ffi::NDArray::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
+inline ffi::Tensor Empty(ffi::Shape shape, DLDataType dtype, DLDevice device) {
+ return ffi::Tensor::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
}
int main() {
// load the module
ffi::Module mod = ffi::Module::LoadFromFile("build/add_one_cpu.so");
- // create an NDArray, alternatively, one can directly pass in a DLTensor*
- ffi::NDArray x = Empty({5}, DLDataType({kDLFloat, 32, 1}), DLDevice({kDLCPU, 0}));
+ // create an Tensor, alternatively, one can directly pass in a DLTensor*
+ ffi::Tensor x = Empty({5}, DLDataType({kDLFloat, 32, 1}), DLDevice({kDLCPU, 0}));
for (int i = 0; i < 5; ++i) {
reinterpret_cast<float*>(x->data)[i] = static_cast<float>(i);
}
diff --git a/ffi/include/tvm/ffi/c_api.h b/ffi/include/tvm/ffi/c_api.h
index 4df2daffeb..2a694fc4ad 100644
--- a/ffi/include/tvm/ffi/c_api.h
+++ b/ffi/include/tvm/ffi/c_api.h
@@ -131,9 +131,9 @@ typedef enum {
*/
kTVMFFIShape = 69,
/*!
- * \brief NDArray object, layout = { TVMFFIObject, DLTensor, ... }
+ * \brief Tensor object, layout = { TVMFFIObject, DLTensor, ... }
*/
- kTVMFFINDArray = 70,
+ kTVMFFITensor = 70,
/*! \brief Array object. */
kTVMFFIArray = 71,
//----------------------------------------------------------------
@@ -497,15 +497,15 @@ TVM_FFI_DLL TVMFFIObjectHandle TVMFFIErrorCreate(const TVMFFIByteArray* kind,
// Section: DLPack support APIs
//------------------------------------------------------------
/*!
- * \brief Produce a managed NDArray from a DLPack tensor.
+ * \brief Produce a managed Tensor from a DLPack tensor.
* \param from The source DLPack tensor.
* \param require_alignment The minimum alignment required of the data + byte_offset.
* \param require_contiguous Boolean flag indicating if we need to check for contiguity.
- * \param out The output NDArray handle.
+ * \param out The output Tensor handle.
* \return 0 on success, nonzero on failure.
*/
-TVM_FFI_DLL int TVMFFINDArrayFromDLPack(DLManagedTensor* from, int32_t require_alignment,
- int32_t require_contiguous, TVMFFIObjectHandle* out);
+TVM_FFI_DLL int TVMFFITensorFromDLPack(DLManagedTensor* from, int32_t require_alignment,
+ int32_t require_contiguous, TVMFFIObjectHandle* out);
/*!
* \brief Produce a DLManagedTensor from the array that shares data memory with the array.
@@ -513,20 +513,20 @@ TVM_FFI_DLL int TVMFFINDArrayFromDLPack(DLManagedTensor* from, int32_t require_a
* \param out The DLManagedTensor handle.
* \return 0 on success, nonzero on failure.
*/
-TVM_FFI_DLL int TVMFFINDArrayToDLPack(TVMFFIObjectHandle from, DLManagedTensor** out);
+TVM_FFI_DLL int TVMFFITensorToDLPack(TVMFFIObjectHandle from, DLManagedTensor** out);
/*!
- * \brief Produce a managed NDArray from a DLPack tensor.
+ * \brief Produce a managed Tensor from a DLPack tensor.
* \param from The source DLPack tensor.
* \param require_alignment The minimum alignment required of the data + byte_offset.
* \param require_contiguous Boolean flag indicating if we need to check for contiguity.
- * \param out The output NDArray handle.
+ * \param out The output Tensor handle.
* \return 0 on success, nonzero on failure.
*/
-TVM_FFI_DLL int TVMFFINDArrayFromDLPackVersioned(DLManagedTensorVersioned* from,
- int32_t require_alignment,
- int32_t require_contiguous,
- TVMFFIObjectHandle* out);
+TVM_FFI_DLL int TVMFFITensorFromDLPackVersioned(DLManagedTensorVersioned* from,
+ int32_t require_alignment,
+ int32_t require_contiguous,
+ TVMFFIObjectHandle* out);
/*!
* \brief Produce a DLManagedTensor from the array that shares data memory with the array.
@@ -534,8 +534,8 @@ TVM_FFI_DLL int TVMFFINDArrayFromDLPackVersioned(DLManagedTensorVersioned* from,
* \param out The DLManagedTensor handle.
* \return 0 on success, nonzero on failure.
*/
-TVM_FFI_DLL int TVMFFINDArrayToDLPackVersioned(TVMFFIObjectHandle from,
- DLManagedTensorVersioned** out);
+TVM_FFI_DLL int TVMFFITensorToDLPackVersioned(TVMFFIObjectHandle from,
+ DLManagedTensorVersioned** out);
//---------------------------------------------------------------
// Section: dtype string support APIs.
@@ -1028,11 +1028,11 @@ inline TVMFFIShapeCell* TVMFFIShapeGetCellPtr(TVMFFIObjectHandle obj) {
}
/*!
- * \brief Get the DLTensor pointer from an NDArray object.
+ * \brief Get the DLTensor pointer from an Tensor object.
* \param obj The object handle.
* \return The DLTensor pointer.
*/
-inline DLTensor* TVMFFINDArrayGetDLTensorPtr(TVMFFIObjectHandle obj) {
+inline DLTensor* TVMFFITensorGetDLTensorPtr(TVMFFIObjectHandle obj) {
return reinterpret_cast<DLTensor*>(reinterpret_cast<char*>(obj) + sizeof(TVMFFIObject));
}
diff --git a/ffi/include/tvm/ffi/container/shape.h b/ffi/include/tvm/ffi/container/shape.h
index 6360fcd1e3..28f4961c99 100644
--- a/ffi/include/tvm/ffi/container/shape.h
+++ b/ffi/include/tvm/ffi/container/shape.h
@@ -19,7 +19,7 @@
/*!
* \file tvm/ffi/shape.h
- * \brief Container to store shape of an NDArray.
+ * \brief Container to store shape of an Tensor.
*/
#ifndef TVM_FFI_CONTAINER_SHAPE_H_
#define TVM_FFI_CONTAINER_SHAPE_H_
diff --git a/ffi/include/tvm/ffi/container/ndarray.h b/ffi/include/tvm/ffi/container/tensor.h
similarity index 73%
rename from ffi/include/tvm/ffi/container/ndarray.h
rename to ffi/include/tvm/ffi/container/tensor.h
index f65e386c06..93526e5c2a 100644
--- a/ffi/include/tvm/ffi/container/ndarray.h
+++ b/ffi/include/tvm/ffi/container/tensor.h
@@ -19,11 +19,11 @@
*/
/*!
- * \file tvm/ffi/ndarray.h
- * \brief Container to store an NDArray.
+ * \file tvm/ffi/tensor.h
+ * \brief Container to store an Tensor.
*/
-#ifndef TVM_FFI_CONTAINER_NDARRAY_H_
-#define TVM_FFI_CONTAINER_NDARRAY_H_
+#ifndef TVM_FFI_CONTAINER_TENSOR_H_
+#define TVM_FFI_CONTAINER_TENSOR_H_
#include <tvm/ffi/container/shape.h>
#include <tvm/ffi/dtype.h>
@@ -110,20 +110,20 @@ inline size_t GetDataSize(const DLTensor& arr) {
return GetDataSize(size, arr.dtype);
}
-/*! \brief An object representing an NDArray. */
-class NDArrayObj : public Object, public DLTensor {
+/*! \brief An object representing an Tensor. */
+class TensorObj : public Object, public DLTensor {
public:
- static constexpr const uint32_t _type_index = TypeIndex::kTVMFFINDArray;
- static constexpr const char* _type_key = StaticTypeKey::kTVMFFINDArray;
- TVM_FFI_DECLARE_STATIC_OBJECT_INFO(NDArrayObj, Object);
+ static constexpr const uint32_t _type_index = TypeIndex::kTVMFFITensor;
+ static constexpr const char* _type_key = StaticTypeKey::kTVMFFITensor;
+ TVM_FFI_DECLARE_STATIC_OBJECT_INFO(TensorObj, Object);
/*!
- * \brief Move NDArray to a DLPack managed tensor.
+ * \brief Move Tensor to a DLPack managed tensor.
* \return The converted DLPack managed tensor.
*/
DLManagedTensor* ToDLPack() const {
DLManagedTensor* ret = new DLManagedTensor();
- NDArrayObj* from = const_cast<NDArrayObj*>(this);
+ TensorObj* from = const_cast<TensorObj*>(this);
ret->dl_tensor = *static_cast<DLTensor*>(from);
ret->manager_ctx = from;
ret->deleter = DLManagedTensorDeleter;
@@ -132,12 +132,12 @@ class NDArrayObj : public Object, public DLTensor {
}
/*!
- * \brief Move NDArray to a DLPack managed tensor.
+ * \brief Move Tensor to a DLPack managed tensor.
* \return The converted DLPack managed tensor.
*/
DLManagedTensorVersioned* ToDLPackVersioned() const {
DLManagedTensorVersioned* ret = new DLManagedTensorVersioned();
- NDArrayObj* from = const_cast<NDArrayObj*>(this);
+ TensorObj* from = const_cast<TensorObj*>(this);
ret->version.major = DLPACK_MAJOR_VERSION;
ret->version.minor = DLPACK_MINOR_VERSION;
ret->dl_tensor = *static_cast<DLTensor*>(from);
@@ -149,37 +149,37 @@ class NDArrayObj : public Object, public DLTensor {
}
protected:
- // backs up the shape of the NDArray
+ // backs up the shape/strides
Optional<Shape> shape_data_;
Optional<Shape> stride_data_;
static void DLManagedTensorDeleter(DLManagedTensor* tensor) {
- NDArrayObj* obj = static_cast<NDArrayObj*>(tensor->manager_ctx);
+ TensorObj* obj = static_cast<TensorObj*>(tensor->manager_ctx);
details::ObjectUnsafe::DecRefObjectHandle(obj);
delete tensor;
}
static void DLManagedTensorVersionedDeleter(DLManagedTensorVersioned* tensor) {
- NDArrayObj* obj = static_cast<NDArrayObj*>(tensor->manager_ctx);
+ TensorObj* obj = static_cast<TensorObj*>(tensor->manager_ctx);
details::ObjectUnsafe::DecRefObjectHandle(obj);
delete tensor;
}
- friend class NDArray;
+ friend class Tensor;
};
namespace details {
/*!
- *\brief Helper class to create an NDArrayObj from an NDAllocator
+ *\brief Helper class to create an TensorObj from an NDAllocator
*
* The underlying allocator needs to be implemented by user.
*/
template <typename TNDAlloc>
-class NDArrayObjFromNDAlloc : public NDArrayObj {
+class TensorObjFromNDAlloc : public TensorObj {
public:
template <typename... ExtraArgs>
- NDArrayObjFromNDAlloc(TNDAlloc alloc, ffi::Shape shape, DLDataType dtype, DLDevice device,
- ExtraArgs&&... extra_args)
+ TensorObjFromNDAlloc(TNDAlloc alloc, ffi::Shape shape, DLDataType dtype, DLDevice device,
+ ExtraArgs&&... extra_args)
: alloc_(alloc) {
this->device = device;
this->ndim = static_cast<int>(shape.size());
@@ -193,7 +193,7 @@ class NDArrayObjFromNDAlloc : public NDArrayObj {
alloc_.AllocData(static_cast<DLTensor*>(this), std::forward<ExtraArgs>(extra_args)...);
}
- ~NDArrayObjFromNDAlloc() { alloc_.FreeData(static_cast<DLTensor*>(this)); }
+ ~TensorObjFromNDAlloc() { alloc_.FreeData(static_cast<DLTensor*>(this)); }
private:
TNDAlloc alloc_;
@@ -201,9 +201,9 @@ class NDArrayObjFromNDAlloc : public NDArrayObj {
/*! \brief helper class to import from DLPack legacy DLManagedTensor */
template <typename TDLPackManagedTensor>
-class NDArrayObjFromDLPack : public NDArrayObj {
+class TensorObjFromDLPack : public TensorObj {
public:
- explicit NDArrayObjFromDLPack(TDLPackManagedTensor* tensor) : tensor_(tensor) {
+ explicit TensorObjFromDLPack(TDLPackManagedTensor* tensor) : tensor_(tensor) {
*static_cast<DLTensor*>(this) = tensor_->dl_tensor;
if (tensor_->dl_tensor.strides == nullptr) {
Shape strides = Shape(details::MakeStridesFromShape(ndim, shape));
@@ -212,7 +212,7 @@ class NDArrayObjFromDLPack : public NDArrayObj {
}
}
- ~NDArrayObjFromDLPack() {
+ ~TensorObjFromDLPack() {
// run DLPack deleter if needed.
if (tensor_->deleter != nullptr) {
(*tensor_->deleter)(tensor_);
@@ -225,62 +225,62 @@ class NDArrayObjFromDLPack : public NDArrayObj {
} // namespace details
/*!
- * \brief Managed NDArray.
- * The array is backed by reference counted blocks.
+ * \brief Managed Tensor (n-dimensional array).
+ * The tensor is backed by reference counted blocks.
*
* \note This class can be subclassed to implement downstream customized
- * NDArray types that are backed by the same NDArrayObj storage type.
+ * Tensor types that are backed by the same TensorObj storage type.
*/
-class NDArray : public ObjectRef {
+class Tensor : public ObjectRef {
public:
/*!
- * \brief Get the shape of the NDArray.
- * \return The shape of the NDArray.
+ * \brief Get the shape of the Tensor.
+ * \return The shape of the Tensor.
*/
tvm::ffi::Shape shape() const {
- NDArrayObj* obj = get_mutable();
+ TensorObj* obj = get_mutable();
if (!obj->shape_data_.has_value()) {
obj->shape_data_ = tvm::ffi::Shape(obj->shape, obj->shape + obj->ndim);
}
return *(obj->shape_data_);
}
/*!
- * \brief Get the data type of the NDArray.
- * \return The data type of the NDArray.
+ * \brief Get the data type of the Tensor.
+ * \return The data type of the Tensor.
*/
DLDataType dtype() const { return (*this)->dtype; }
/*!
- * \brief Check if the NDArray is contiguous.
- * \return True if the NDArray is contiguous, false otherwise.
+ * \brief Check if the Tensor is contiguous.
+ * \return True if the Tensor is contiguous, false otherwise.
*/
bool IsContiguous() const { return tvm::ffi::IsContiguous(*get()); }
/*!
- * \brief Create a NDArray from a NDAllocator.
+ * \brief Create a Tensor from a NDAllocator.
* \param alloc The NDAllocator.
- * \param shape The shape of the NDArray.
- * \param dtype The data type of the NDArray.
- * \param device The device of the NDArray.
- * \return The created NDArray.
+ * \param shape The shape of the Tensor.
+ * \param dtype The data type of the Tensor.
+ * \param device The device of the Tensor.
+ * \return The created Tensor.
* \tparam TNDAlloc The type of the NDAllocator, impelments Alloc and Free.
* \tparam ExtraArgs Extra arguments to be passed to Alloc.
*/
template <typename TNDAlloc, typename... ExtraArgs>
- static NDArray FromNDAlloc(TNDAlloc alloc, ffi::Shape shape, DLDataType dtype, DLDevice device,
- ExtraArgs&&... extra_args) {
- return NDArray(make_object<details::NDArrayObjFromNDAlloc<TNDAlloc>>(
+ static Tensor FromNDAlloc(TNDAlloc alloc, ffi::Shape shape, DLDataType dtype, DLDevice device,
+ ExtraArgs&&... extra_args) {
+ return Tensor(make_object<details::TensorObjFromNDAlloc<TNDAlloc>>(
alloc, shape, dtype, device, std::forward<ExtraArgs>(extra_args)...));
}
/*!
- * \brief Create a NDArray from a DLPack managed tensor, pre v1.0 API.
+ * \brief Create a Tensor from a DLPack managed tensor, pre v1.0 API.
* \param tensor The input DLPack managed tensor.
* \param require_alignment The minimum alignment requored of the data + byte_offset.
* \param require_contiguous Boolean flag indicating if we need to check for contiguity.
* \note This function will not run any checks on flags.
- * \return The created NDArray.
+ * \return The created Tensor.
*/
- static NDArray FromDLPack(DLManagedTensor* tensor, size_t require_alignment = 0,
- bool require_contiguous = false) {
+ static Tensor FromDLPack(DLManagedTensor* tensor, size_t require_alignment = 0,
+ bool require_contiguous = false) {
if (require_alignment != 0 && !ffi::IsAligned(tensor->dl_tensor, require_alignment)) {
TVM_FFI_THROW(RuntimeError) << "FromDLPack: Data is not aligned to " << require_alignment
<< " bytes.";
@@ -288,18 +288,18 @@ class NDArray : public ObjectRef {
if (require_contiguous && !ffi::IsContiguous(tensor->dl_tensor)) {
TVM_FFI_THROW(RuntimeError) << "FromDLPack: Tensor is not contiguous.";
}
- return NDArray(make_object<details::NDArrayObjFromDLPack<DLManagedTensor>>(tensor));
+ return Tensor(make_object<details::TensorObjFromDLPack<DLManagedTensor>>(tensor));
}
/*!
- * \brief Create a NDArray from a DLPack managed tensor, post v1.0 API.
+ * \brief Create a Tensor from a DLPack managed tensor, post v1.0 API.
* \param tensor The input DLPack managed tensor.
* \param require_alignment The minimum alignment requored of the data + byte_offset.
* \param require_contiguous Boolean flag indicating if we need to check for contiguity.
- * \return The created NDArray.
+ * \return The created Tensor.
*/
- static NDArray FromDLPackVersioned(DLManagedTensorVersioned* tensor, size_t require_alignment = 0,
- bool require_contiguous = false) {
+ static Tensor FromDLPackVersioned(DLManagedTensorVersioned* tensor, size_t require_alignment = 0,
+ bool require_contiguous = false) {
if (require_alignment != 0 && !ffi::IsAligned(tensor->dl_tensor, require_alignment)) {
TVM_FFI_THROW(RuntimeError) << "FromDLPack: Data is not aligned to " << require_alignment
<< " bytes.";
@@ -310,32 +310,32 @@ class NDArray : public ObjectRef {
if (tensor->flags & DLPACK_FLAG_BITMASK_IS_SUBBYTE_TYPE_PADDED) {
TVM_FFI_THROW(RuntimeError) << "Subbyte type padded is not yet supported";
}
- return NDArray(make_object<details::NDArrayObjFromDLPack<DLManagedTensorVersioned>>(tensor));
+ return Tensor(make_object<details::TensorObjFromDLPack<DLManagedTensorVersioned>>(tensor));
}
/*!
- * \brief Convert the NDArray to a DLPack managed tensor.
+ * \brief Convert the Tensor to a DLPack managed tensor.
* \return The converted DLPack managed tensor.
*/
DLManagedTensor* ToDLPack() const { return get_mutable()->ToDLPack(); }
/*!
- * \brief Convert the NDArray to a DLPack managed tensor.
+ * \brief Convert the Tensor to a DLPack managed tensor.
* \return The converted DLPack managed tensor.
*/
DLManagedTensorVersioned* ToDLPackVersioned() const { return get_mutable()->ToDLPackVersioned(); }
- TVM_FFI_DEFINE_OBJECT_REF_METHODS(NDArray, ObjectRef, NDArrayObj);
+ TVM_FFI_DEFINE_OBJECT_REF_METHODS(Tensor, ObjectRef, TensorObj);
protected:
/*!
* \brief Get mutable internal container pointer.
* \return a mutable container pointer.
*/
- NDArrayObj* get_mutable() const { return const_cast<NDArrayObj*>(get()); }
+ TensorObj* get_mutable() const { return const_cast<TensorObj*>(get()); }
};
} // namespace ffi
} // namespace tvm
-#endif // TVM_FFI_CONTAINER_NDARRAY_H_
+#endif // TVM_FFI_CONTAINER_TENSOR_H_
diff --git a/ffi/include/tvm/ffi/extra/structural_equal.h b/ffi/include/tvm/ffi/extra/structural_equal.h
index 9727940297..8eb5da7f67 100644
--- a/ffi/include/tvm/ffi/extra/structural_equal.h
+++ b/ffi/include/tvm/ffi/extra/structural_equal.h
@@ -40,13 +40,13 @@ class StructuralEqual {
* \param lhs The left hand side Any object.
* \param rhs The right hand side Any object.
* \param map_free_vars Whether to map free variables.
- * \param skip_ndarray_content Whether to skip comparingn darray data content,
+ * \param skip_tensor_content Whether to skip comparingn darray data content,
* useful for cases where we don't care about parameters content
* \return True if the two Any values are structurally equal, false otherwise.
*/
TVM_FFI_EXTRA_CXX_API static bool Equal(const Any& lhs, const Any& rhs,
bool map_free_vars = false,
- bool skip_ndarray_content = false);
+ bool skip_tensor_content = false);
/**
* \brief Get the first mismatch AccessPath pair when running
* structural equal comparison between two Any values.
@@ -54,14 +54,13 @@ class StructuralEqual {
* \param lhs The left hand side Any object.
* \param rhs The right hand side Any object.
* \param map_free_vars Whether to map free variables.
- * \param skip_ndarray_content Whether to skip comparing ndarray data content,
+ * \param skip_tensor_content Whether to skip comparing tensor data content,
* useful for cases where we don't care about parameters content
* \return If comparison fails, return the first mismatch AccessPath pair,
* otherwise return std::nullopt.
*/
TVM_FFI_EXTRA_CXX_API static Optional<reflection::AccessPathPair> GetFirstMismatch(
- const Any& lhs, const Any& rhs, bool map_free_vars = false,
- bool skip_ndarray_content = false);
+ const Any& lhs, const Any& rhs, bool map_free_vars = false, bool skip_tensor_content = false);
/*
* \brief Compare two Any values for structural equality.
diff --git a/ffi/include/tvm/ffi/extra/structural_hash.h b/ffi/include/tvm/ffi/extra/structural_hash.h
index 9cb08a1c0f..1d7ba2613e 100644
--- a/ffi/include/tvm/ffi/extra/structural_hash.h
+++ b/ffi/include/tvm/ffi/extra/structural_hash.h
@@ -38,12 +38,12 @@ class StructuralHash {
* \brief Hash an Any value.
* \param value The Any value to hash.
* \param map_free_vars Whether to map free variables.
- * \param skip_ndarray_content Whether to skip comparingn darray data content,
+ * \param skip_tensor_content Whether to skip comparingn darray data content,
* useful for cases where we don't care about parameters content.
* \return The hash value.
*/
TVM_FFI_EXTRA_CXX_API static uint64_t Hash(const Any& value, bool map_free_vars = false,
- bool skip_ndarray_content = false);
+ bool skip_tensor_content = false);
/*!
* \brief Hash an Any value.
* \param value The Any value to hash.
diff --git a/ffi/include/tvm/ffi/object.h b/ffi/include/tvm/ffi/object.h
index cc5ee8d945..ab0e424551 100644
--- a/ffi/include/tvm/ffi/object.h
+++ b/ffi/include/tvm/ffi/object.h
@@ -57,7 +57,7 @@ struct StaticTypeKey {
static constexpr const char* kTVMFFIBytes = "ffi.Bytes";
static constexpr const char* kTVMFFIStr = "ffi.String";
static constexpr const char* kTVMFFIShape = "ffi.Shape";
- static constexpr const char* kTVMFFINDArray = "ffi.NDArray";
+ static constexpr const char* kTVMFFITensor = "ffi.Tensor";
static constexpr const char* kTVMFFIObject = "ffi.Object";
static constexpr const char* kTVMFFIFunction = "ffi.Function";
static constexpr const char* kTVMFFIArray = "ffi.Array";
diff --git a/ffi/include/tvm/ffi/type_traits.h b/ffi/include/tvm/ffi/type_traits.h
index 9cdb2b9338..b972f58359 100644
--- a/ffi/include/tvm/ffi/type_traits.h
+++ b/ffi/include/tvm/ffi/type_traits.h
@@ -463,15 +463,15 @@ struct TypeTraits<DLTensor*> : public TypeTraitsBase {
TVM_FFI_INLINE static void MoveToAny(DLTensor*, TVMFFIAny*) {
TVM_FFI_THROW(RuntimeError)
- << "DLTensor* cannot be held in Any as it does not retain ownership, use NDArray instead";
+ << "DLTensor* cannot be held in Any as it does not retain ownership, use Tensor instead";
}
TVM_FFI_INLINE static std::optional<DLTensor*> TryCastFromAnyView(const TVMFFIAny* src) {
if (src->type_index == TypeIndex::kTVMFFIDLTensorPtr) {
return static_cast<DLTensor*>(src->v_ptr);
- } else if (src->type_index == TypeIndex::kTVMFFINDArray) {
- // Conversion from NDArray pointer to DLTensor
- // based on the assumption that NDArray always follows the TVMFFIObject header
+ } else if (src->type_index == TypeIndex::kTVMFFITensor) {
+ // Conversion from Tensor pointer to DLTensor
+ // based on the assumption that Tensor always follows the TVMFFIObject header
static_assert(sizeof(TVMFFIObject) == 24);
return reinterpret_cast<DLTensor*>(reinterpret_cast<char*>(src->v_obj) +
sizeof(TVMFFIObject));
diff --git a/ffi/pyproject.toml b/ffi/pyproject.toml
index ab2a7f84df..430b47c33b 100644
--- a/ffi/pyproject.toml
+++ b/ffi/pyproject.toml
@@ -17,7 +17,7 @@
[project]
name = "apache-tvm-ffi"
-version = "0.1.0a7"
+version = "0.1.0a8"
description = "tvm ffi"
authors = [{ name = "TVM FFI team" }]
diff --git a/ffi/python/tvm_ffi/__init__.py b/ffi/python/tvm_ffi/__init__.py
index 7f702a7b09..807dc56a91 100644
--- a/ffi/python/tvm_ffi/__init__.py
+++ b/ffi/python/tvm_ffi/__init__.py
@@ -26,9 +26,9 @@ from .core import String, Bytes
from .core import Object, ObjectGeneric, Function
from .convert import convert
from .error import register_error
-from .ndarray import Device, device
-from .ndarray import cpu, cuda, rocm, opencl, metal, vpi, vulkan, ext_dev, hexagon, webgpu
-from .ndarray import from_dlpack, NDArray, Shape
+from .tensor import Device, device
+from .tensor import cpu, cuda, rocm, opencl, metal, vpi, vulkan, ext_dev, hexagon, webgpu
+from .tensor import from_dlpack, Tensor, Shape
from .container import Array, Map
from .module import Module, ModulePropertyMask, system_lib, load_module
from . import serialization
@@ -65,7 +65,7 @@ __all__ = [
"hexagon",
"webgpu",
"from_dlpack",
- "NDArray",
+ "Tensor",
"Shape",
"Array",
"Map",
diff --git a/ffi/python/tvm_ffi/cython/base.pxi b/ffi/python/tvm_ffi/cython/base.pxi
index 4acf5f0a17..f1cd77bc47 100644
--- a/ffi/python/tvm_ffi/cython/base.pxi
+++ b/ffi/python/tvm_ffi/cython/base.pxi
@@ -49,7 +49,7 @@ cdef extern from "tvm/ffi/c_api.h":
kTVMFFIError = 67
kTVMFFIFunction = 68
kTVMFFIShape = 69
- kTVMFFINDArray = 70
+ kTVMFFITensor = 70
kTVMFFIArray = 71
kTVMFFIMap = 72
kTVMFFIModule = 73
@@ -196,14 +196,14 @@ cdef extern from "tvm/ffi/c_api.h":
int TVMFFIDataTypeToString(const DLDataType* dtype, TVMFFIAny* out) nogil
const TVMFFIByteArray* TVMFFITraceback(
const char* filename, int lineno, const char* func, int cross_ffi_boundary) nogil;
- int TVMFFINDArrayFromDLPack(DLManagedTensor* src, int32_t require_alignment,
+ int TVMFFITensorFromDLPack(DLManagedTensor* src, int32_t require_alignment,
int32_t require_contiguous, TVMFFIObjectHandle* out) nogil
- int TVMFFINDArrayFromDLPackVersioned(DLManagedTensorVersioned* src,
+ int TVMFFITensorFromDLPackVersioned(DLManagedTensorVersioned* src,
int32_t require_alignment,
int32_t require_contiguous,
TVMFFIObjectHandle* out) nogil
- int TVMFFINDArrayToDLPack(TVMFFIObjectHandle src, DLManagedTensor** out) nogil
- int TVMFFINDArrayToDLPackVersioned(TVMFFIObjectHandle src,
+ int TVMFFITensorToDLPack(TVMFFIObjectHandle src, DLManagedTensor** out) nogil
+ int TVMFFITensorToDLPackVersioned(TVMFFIObjectHandle src,
DLManagedTensorVersioned** out) nogil
const TVMFFITypeInfo* TVMFFIGetTypeInfo(int32_t type_index) nogil
TVMFFIByteArray TVMFFISmallBytesGetContentByteArray(const TVMFFIAny* value) nogil
@@ -211,7 +211,7 @@ cdef extern from "tvm/ffi/c_api.h":
TVMFFIErrorCell* TVMFFIErrorGetCellPtr(TVMFFIObjectHandle obj) nogil
TVMFFIOpaqueObjectCell* TVMFFIOpaqueObjectGetCellPtr(TVMFFIObjectHandle obj) nogil
TVMFFIShapeCell* TVMFFIShapeGetCellPtr(TVMFFIObjectHandle obj) nogil
- DLTensor* TVMFFINDArrayGetDLTensorPtr(TVMFFIObjectHandle obj) nogil
+ DLTensor* TVMFFITensorGetDLTensorPtr(TVMFFIObjectHandle obj) nogil
DLDevice TVMFFIDLDeviceFromIntPair(int32_t device_type, int32_t device_id) nogil
cdef extern from "tvm/ffi/extra/c_env_api.h":
diff --git a/ffi/python/tvm_ffi/cython/core.pyx b/ffi/python/tvm_ffi/cython/core.pyx
index 010341187c..b24a83da7c 100644
--- a/ffi/python/tvm_ffi/cython/core.pyx
+++ b/ffi/python/tvm_ffi/cython/core.pyx
@@ -22,5 +22,5 @@ include "./device.pxi"
include "./object.pxi"
include "./error.pxi"
include "./string.pxi"
-include "./ndarray.pxi"
+include "./tensor.pxi"
include "./function.pxi"
diff --git a/ffi/python/tvm_ffi/cython/function.pxi b/ffi/python/tvm_ffi/cython/function.pxi
index fc273b5cee..ea10356077 100644
--- a/ffi/python/tvm_ffi/cython/function.pxi
+++ b/ffi/python/tvm_ffi/cython/function.pxi
@@ -15,12 +15,17 @@
# specific language governing permissions and limitations
# under the License.
import ctypes
+import os
from numbers import Real, Integral
-try:
- # optionally import torch and setup torch related utils
- import torch
-except ImportError:
+
+if os.environ.get("TVM_FFI_BUILD_DOCS", "0") == "0":
+ try:
+ # optionally import torch and setup torch related utils
+ import torch
+ except ImportError:
+ torch = None
+else:
torch = None
@@ -43,9 +48,9 @@ cdef inline object make_ret(TVMFFIAny result):
# TODO: Implement
cdef int32_t type_index
type_index = result.type_index
- if type_index == kTVMFFINDArray:
- # specially handle NDArray as it needs a special dltensor field
- return make_ndarray_from_any(result)
+ if type_index == kTVMFFITensor:
+ # specially handle Tensor as it needs a special dltensor field
+ return make_tensor_from_any(result)
elif type_index == kTVMFFIOpaquePyObject:
return make_ret_opaque_object(result)
elif type_index >= kTVMFFIStaticObjectBegin:
@@ -92,13 +97,13 @@ cdef inline int make_args(tuple py_args, TVMFFIAny* out, list temp_args,
out[i].v_int64 = 0
out[i].zero_padding = 0
- if isinstance(arg, NDArray):
+ if isinstance(arg, Tensor):
if (<Object>arg).chandle != NULL:
- out[i].type_index = kTVMFFINDArray
- out[i].v_ptr = (<NDArray>arg).chandle
+ out[i].type_index = kTVMFFITensor
+ out[i].v_ptr = (<Tensor>arg).chandle
else:
out[i].type_index = kTVMFFIDLTensorPtr
- out[i].v_ptr = (<NDArray>arg).cdltensor
+ out[i].v_ptr = (<Tensor>arg).cdltensor
elif isinstance(arg, Object):
out[i].type_index = TVMFFIObjectGetTypeIndex((<Object>arg).chandle)
out[i].v_ptr = (<Object>arg).chandle
@@ -106,9 +111,9 @@ cdef inline int make_args(tuple py_args, TVMFFIAny* out, list temp_args,
is_cuda = arg.is_cuda
arg = from_dlpack(torch.utils.dlpack.to_dlpack(arg),
required_alignment=__dlpack_auto_import_required_alignment__)
- out[i].type_index = kTVMFFINDArray
- out[i].v_ptr = (<NDArray>arg).chandle
- temp_dltensor = TVMFFINDArrayGetDLTensorPtr((<NDArray>arg).chandle)
+ out[i].type_index = kTVMFFITensor
+ out[i].v_ptr = (<Tensor>arg).chandle
+ temp_dltensor = TVMFFITensorGetDLTensorPtr((<Tensor>arg).chandle)
# record the stream and device for torch context
if is_cuda and ctx_dev_type != NULL and ctx_dev_type[0] == -1:
ctx_dev_type[0] = temp_dltensor.device.device_type
@@ -119,8 +124,8 @@ cdef inline int make_args(tuple py_args, TVMFFIAny* out, list temp_args,
temp_args.append(arg)
elif hasattr(arg, "__dlpack__"):
arg = from_dlpack(arg, required_alignment=__dlpack_auto_import_required_alignment__)
- out[i].type_index = kTVMFFINDArray
- out[i].v_ptr = (<NDArray>arg).chandle
+ out[i].type_index = kTVMFFITensor
+ out[i].v_ptr = (<Tensor>arg).chandle
temp_args.append(arg)
elif isinstance(arg, PyNativeObject) and arg.__tvm_ffi_object__ is not None:
arg = arg.__tvm_ffi_object__
diff --git a/ffi/python/tvm_ffi/cython/ndarray.pxi b/ffi/python/tvm_ffi/cython/tensor.pxi
similarity index 89%
rename from ffi/python/tvm_ffi/cython/ndarray.pxi
rename to ffi/python/tvm_ffi/cython/tensor.pxi
index 9dfe1222dc..5544359c9e 100644
--- a/ffi/python/tvm_ffi/cython/ndarray.pxi
+++ b/ffi/python/tvm_ffi/cython/tensor.pxi
@@ -17,12 +17,12 @@
__dlpack_version__ = (1, 1)
__dlpack_auto_import_required_alignment__ = 8
-_CLASS_NDARRAY = None
+_CLASS_TENSOR = None
-def _set_class_ndarray(cls):
- global _CLASS_NDARRAY
- _CLASS_NDARRAY = cls
+def _set_class_tensor(cls):
+ global _CLASS_TENSOR
+ _CLASS_TENSOR = cls
cdef const char* _c_str_dltensor = "dltensor"
@@ -55,7 +55,7 @@ cdef inline int _from_dlpack(
if pycapsule.PyCapsule_IsValid(dltensor, _c_str_dltensor):
ptr = <DLManagedTensor*>pycapsule.PyCapsule_GetPointer(dltensor, _c_str_dltensor)
with nogil:
- c_api_ret_code = TVMFFINDArrayFromDLPack(
+ c_api_ret_code = TVMFFITensorFromDLPack(
ptr, c_req_alignment, c_req_contiguous, out)
CHECK_CALL(c_api_ret_code)
# set name and destructor to be empty
@@ -77,7 +77,7 @@ cdef inline int _from_dlpack_versioned(
ptr = <DLManagedTensorVersioned*>pycapsule.PyCapsule_GetPointer(
dltensor, _c_str_dltensor_versioned)
with nogil:
- c_api_ret_code = TVMFFINDArrayFromDLPackVersioned(
+ c_api_ret_code = TVMFFITensorFromDLPackVersioned(
ptr, c_req_alignment, c_req_contiguous, out)
CHECK_CALL(c_api_ret_code)
# set name and destructor to be empty
@@ -89,7 +89,7 @@ cdef inline int _from_dlpack_versioned(
def from_dlpack(ext_tensor, *, required_alignment=8, required_contiguous=True):
"""
- Convert an external tensor to an NDArray.
+ Convert an external tensor to an Tensor.
Parameters
----------
@@ -147,7 +147,7 @@ def from_dlpack(ext_tensor, *, required_alignment=8, required_contiguous=True):
)
else:
raise TypeError("Expect from_dlpack to take either a compatible tensor or PyCapsule")
- return make_ndarray_from_chandle(chandle)
+ return make_tensor_from_chandle(chandle)
# helper class for shape handling
@@ -156,7 +156,7 @@ def _shape_obj_get_py_tuple(obj):
return tuple(shape.data[i] for i in range(shape.size))
-cdef class NDArray(Object):
+cdef class Tensor(Object):
"""N-dimensional array that is compatible with DLPack.
"""
cdef DLTensor* cdltensor
@@ -199,7 +199,7 @@ cdef class NDArray(Object):
cdef int c_api_ret_code
with nogil:
- c_api_ret_code = TVMFFINDArrayToDLPack(self.chandle, &dltensor)
+ c_api_ret_code = TVMFFITensorToDLPack(self.chandle, &dltensor)
CHECK_CALL(c_api_ret_code)
return pycapsule.PyCapsule_New(dltensor, _c_str_dltensor, <PyCapsule_Destructor>_c_dlpack_deleter)
@@ -208,7 +208,7 @@ cdef class NDArray(Object):
cdef int c_api_ret_code
with nogil:
- c_api_ret_code = TVMFFINDArrayToDLPackVersioned(self.chandle, &dltensor)
+ c_api_ret_code = TVMFFITensorToDLPackVersioned(self.chandle, &dltensor)
CHECK_CALL(c_api_ret_code)
return pycapsule.PyCapsule_New(
dltensor, _c_str_dltensor_versioned, <PyCapsule_Destructor>_c_dlpack_versioned_deleter)
@@ -266,27 +266,27 @@ cdef class NDArray(Object):
raise BufferError(f"Unsupported max_version {max_version}")
-_set_class_ndarray(NDArray)
-_register_object_by_index(kTVMFFINDArray, NDArray)
+_set_class_tensor(Tensor)
+_register_object_by_index(kTVMFFITensor, Tensor)
cdef inline object make_ret_dltensor(TVMFFIAny result):
cdef DLTensor* dltensor
dltensor = <DLTensor*>result.v_ptr
- ndarray = _CLASS_NDARRAY.__new__(_CLASS_NDARRAY)
- (<Object>ndarray).chandle = NULL
- (<NDArray>ndarray).cdltensor = dltensor
- return ndarray
+ tensor = _CLASS_TENSOR.__new__(_CLASS_TENSOR)
+ (<Object>tensor).chandle = NULL
+ (<Tensor>tensor).cdltensor = dltensor
+ return tensor
-cdef inline object make_ndarray_from_chandle(TVMFFIObjectHandle chandle):
+cdef inline object make_tensor_from_chandle(TVMFFIObjectHandle chandle):
# TODO: Implement
- cdef NDArray ndarray
- ndarray = _CLASS_NDARRAY.__new__(_CLASS_NDARRAY)
- (<Object>ndarray).chandle = chandle
- (<NDArray>ndarray).cdltensor = TVMFFINDArrayGetDLTensorPtr(chandle)
- return ndarray
+ cdef Tensor tensor
+ tensor = _CLASS_TENSOR.__new__(_CLASS_TENSOR)
+ (<Object>tensor).chandle = chandle
+ (<Tensor>tensor).cdltensor = TVMFFITensorGetDLTensorPtr(chandle)
+ return tensor
-cdef inline object make_ndarray_from_any(TVMFFIAny any):
- return make_ndarray_from_chandle(any.v_ptr)
+cdef inline object make_tensor_from_any(TVMFFIAny any):
+ return make_tensor_from_chandle(any.v_ptr)
diff --git a/ffi/python/tvm_ffi/module.py b/ffi/python/tvm_ffi/module.py
index c3c1d089c6..684018416e 100644
--- a/ffi/python/tvm_ffi/module.py
+++ b/ffi/python/tvm_ffi/module.py
@@ -38,25 +38,8 @@ class ModulePropertyMask(IntEnum):
class Module(core.Object):
"""Runtime Module."""
- def __new__(cls):
- instance = super(Module, cls).__new__(cls) # pylint: disable=no-value-for-parameter
- instance.entry_name = "main"
- instance._entry = None
- return instance
-
- @property
- def entry_func(self):
- """Get the entry function
-
- Returns
- -------
- f : tvm_ffi.Function
- The entry function if exist
- """
- if self._entry:
- return self._entry
- self._entry = self.get_function("main")
- return self._entry
+ # constant for entry function name
+ entry_name = "main"
@property
def kind(self):
@@ -142,10 +125,8 @@ class Module(core.Object):
return self.get_function(name)
def __call__(self, *args):
- if self._entry:
- return self._entry(*args)
# pylint: disable=not-callable
- return self.entry_func(*args)
+ return self.main(*args)
def inspect_source(self, fmt=""):
"""Get source code from module, if available.
diff --git a/ffi/python/tvm_ffi/ndarray.py b/ffi/python/tvm_ffi/tensor.py
similarity index 98%
rename from ffi/python/tvm_ffi/ndarray.py
rename to ffi/python/tvm_ffi/tensor.py
index d65b8fb361..97240c6a49 100644
--- a/ffi/python/tvm_ffi/ndarray.py
+++ b/ffi/python/tvm_ffi/tensor.py
@@ -14,11 +14,11 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-"""NDArray related objects and functions."""
+"""Tensor related objects and functions."""
from numbers import Integral
from . import core
-from .core import Device, NDArray, from_dlpack
+from .core import Device, Tensor, from_dlpack
from . import registry
from . import _ffi_api
@@ -240,7 +240,7 @@ def webgpu(dev_id=0):
__all__ = [
"from_dlpack",
- "NDArray",
+ "Tensor",
"device",
"cpu",
"cuda",
diff --git a/ffi/src/ffi/extra/structural_equal.cc b/ffi/src/ffi/extra/structural_equal.cc
index 171fa2f750..976ba4ecf4 100644
--- a/ffi/src/ffi/extra/structural_equal.cc
+++ b/ffi/src/ffi/extra/structural_equal.cc
@@ -23,8 +23,8 @@
*/
#include <tvm/ffi/container/array.h>
#include <tvm/ffi/container/map.h>
-#include <tvm/ffi/container/ndarray.h>
#include <tvm/ffi/container/shape.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/extra/structural_equal.h>
#include <tvm/ffi/reflection/accessor.h>
#include <tvm/ffi/string.h>
@@ -111,9 +111,9 @@ class StructEqualHandler {
return CompareShape(AnyUnsafe::MoveFromAnyAfterCheck<Shape>(std::move(lhs)),
AnyUnsafe::MoveFromAnyAfterCheck<Shape>(std::move(rhs)));
}
- case TypeIndex::kTVMFFINDArray: {
- return CompareNDArray(AnyUnsafe::MoveFromAnyAfterCheck<NDArray>(std::move(lhs)),
- AnyUnsafe::MoveFromAnyAfterCheck<NDArray>(std::move(rhs)));
+ case TypeIndex::kTVMFFITensor: {
+ return CompareTensor(AnyUnsafe::MoveFromAnyAfterCheck<Tensor>(std::move(lhs)),
+ AnyUnsafe::MoveFromAnyAfterCheck<Tensor>(std::move(rhs)));
}
default: {
return CompareObject(AnyUnsafe::MoveFromAnyAfterCheck<ObjectRef>(std::move(lhs)),
@@ -341,14 +341,14 @@ class StructEqualHandler {
return true;
}
- bool CompareNDArray(NDArray lhs, NDArray rhs) {
+ bool CompareTensor(Tensor lhs, Tensor rhs) {
if (lhs.same_as(rhs)) return true;
if (lhs->ndim != rhs->ndim) return false;
for (int i = 0; i < lhs->ndim; ++i) {
if (lhs->shape[i] != rhs->shape[i]) return false;
}
if (lhs->dtype != rhs->dtype) return false;
- if (!skip_ndarray_content_) {
+ if (!skip_tensor_content_) {
TVM_FFI_ICHECK_EQ(lhs->device.device_type, kDLCPU) << "can only compare CPU tensor";
TVM_FFI_ICHECK_EQ(rhs->device.device_type, kDLCPU) << "can only compare CPU tensor";
TVM_FFI_ICHECK(lhs.IsContiguous()) << "Can only compare contiguous tensor";
@@ -385,8 +385,8 @@ class StructEqualHandler {
}
// whether we map free variables that are not defined
bool map_free_vars_{false};
- // whether we compare ndarray data
- bool skip_ndarray_content_{false};
+ // whether we compare tensor data
+ bool skip_tensor_content_{false};
// the root lhs for result printing
std::vector<reflection::AccessStep>* mismatch_lhs_reverse_path_ = nullptr;
std::vector<reflection::AccessStep>* mismatch_rhs_reverse_path_ = nullptr;
@@ -399,20 +399,20 @@ class StructEqualHandler {
};
bool StructuralEqual::Equal(const Any& lhs, const Any& rhs, bool map_free_vars,
- bool skip_ndarray_content) {
+ bool skip_tensor_content) {
StructEqualHandler handler;
handler.map_free_vars_ = map_free_vars;
- handler.skip_ndarray_content_ = skip_ndarray_content;
+ handler.skip_tensor_content_ = skip_tensor_content;
return handler.CompareAny(lhs, rhs);
}
Optional<reflection::AccessPathPair> StructuralEqual::GetFirstMismatch(const Any& lhs,
const Any& rhs,
bool map_free_vars,
- bool skip_ndarray_content) {
+ bool skip_tensor_content) {
StructEqualHandler handler;
handler.map_free_vars_ = map_free_vars;
- handler.skip_ndarray_content_ = skip_ndarray_content;
+ handler.skip_tensor_content_ = skip_tensor_content;
std::vector<reflection::AccessStep> lhs_reverse_path;
std::vector<reflection::AccessStep> rhs_reverse_path;
handler.mismatch_lhs_reverse_path_ = &lhs_reverse_path;
diff --git a/ffi/src/ffi/extra/structural_hash.cc b/ffi/src/ffi/extra/structural_hash.cc
index 9f245c1d17..2eb9843fed 100644
--- a/ffi/src/ffi/extra/structural_hash.cc
+++ b/ffi/src/ffi/extra/structural_hash.cc
@@ -23,8 +23,8 @@
*/
#include <tvm/ffi/container/array.h>
#include <tvm/ffi/container/map.h>
-#include <tvm/ffi/container/ndarray.h>
#include <tvm/ffi/container/shape.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/extra/structural_hash.h>
#include <tvm/ffi/reflection/accessor.h>
#include <tvm/ffi/reflection/registry.h>
@@ -84,8 +84,8 @@ class StructuralHashHandler {
case TypeIndex::kTVMFFIShape: {
return HashShape(AnyUnsafe::MoveFromAnyAfterCheck<Shape>(std::move(src)));
}
- case TypeIndex::kTVMFFINDArray: {
- return HashNDArray(AnyUnsafe::MoveFromAnyAfterCheck<NDArray>(std::move(src)));
+ case TypeIndex::kTVMFFITensor: {
+ return HashTensor(AnyUnsafe::MoveFromAnyAfterCheck<Tensor>(std::move(src)));
}
default: {
return HashObject(AnyUnsafe::MoveFromAnyAfterCheck<ObjectRef>(std::move(src)));
@@ -267,29 +267,29 @@ class StructuralHashHandler {
return hash_value;
}
- uint64_t HashNDArray(NDArray ndarray) {
- uint64_t hash_value = details::StableHashCombine(ndarray->GetTypeKeyHash(), ndarray->ndim);
- for (int i = 0; i < ndarray->ndim; ++i) {
- hash_value = details::StableHashCombine(hash_value, ndarray->shape[i]);
+ uint64_t HashTensor(Tensor tensor) {
+ uint64_t hash_value = details::StableHashCombine(tensor->GetTypeKeyHash(), tensor->ndim);
+ for (int i = 0; i < tensor->ndim; ++i) {
+ hash_value = details::StableHashCombine(hash_value, tensor->shape[i]);
}
TVMFFIAny temp;
temp.v_uint64 = 0;
- temp.v_dtype = ndarray->dtype;
+ temp.v_dtype = tensor->dtype;
hash_value = details::StableHashCombine(hash_value, temp.v_int64);
- if (!skip_ndarray_content_) {
- TVM_FFI_ICHECK_EQ(ndarray->device.device_type, kDLCPU) << "can only hash CPU tensor";
- TVM_FFI_ICHECK(ndarray.IsContiguous()) << "Can only hash contiguous tensor";
- size_t data_size = GetDataSize(*(ndarray.operator->()));
+ if (!skip_tensor_content_) {
+ TVM_FFI_ICHECK_EQ(tensor->device.device_type, kDLCPU) << "can only hash CPU tensor";
+ TVM_FFI_ICHECK(tensor.IsContiguous()) << "Can only hash contiguous tensor";
+ size_t data_size = GetDataSize(*(tensor.operator->()));
uint64_t data_hash =
- details::StableHashBytes(static_cast<const char*>(ndarray->data), data_size);
+ details::StableHashBytes(static_cast<const char*>(tensor->data), data_size);
hash_value = details::StableHashCombine(hash_value, data_hash);
}
return hash_value;
}
bool map_free_vars_{false};
- bool skip_ndarray_content_{false};
+ bool skip_tensor_content_{false};
// free var counter.
uint32_t free_var_counter_{0};
// graph node counter.
@@ -300,10 +300,10 @@ class StructuralHashHandler {
std::unordered_map<ObjectRef, uint64_t, ObjectPtrHash, ObjectPtrEqual> hash_memo_;
};
-uint64_t StructuralHash::Hash(const Any& value, bool map_free_vars, bool skip_ndarray_content) {
+uint64_t StructuralHash::Hash(const Any& value, bool map_free_vars, bool skip_tensor_content) {
StructuralHashHandler handler;
handler.map_free_vars_ = map_free_vars;
- handler.skip_ndarray_content_ = skip_ndarray_content;
+ handler.skip_tensor_content_ = skip_tensor_content;
return handler.HashAny(value);
}
diff --git a/ffi/src/ffi/ndarray.cc b/ffi/src/ffi/tensor.cc
similarity index 71%
rename from ffi/src/ffi/ndarray.cc
rename to ffi/src/ffi/tensor.cc
index 41d4273b59..7b44e4586b 100644
--- a/ffi/src/ffi/ndarray.cc
+++ b/ffi/src/ffi/tensor.cc
@@ -17,11 +17,11 @@
* under the License.
*/
/*
- * \file src/ffi/ndarray.cc
- * \brief NDArray C API implementation
+ * \file src/ffi/tensor.cc
+ * \brief Tensor C API implementation
*/
#include <tvm/ffi/c_api.h>
-#include <tvm/ffi/container/ndarray.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
@@ -47,35 +47,35 @@ TVM_FFI_STATIC_INIT_BLOCK({
} // namespace ffi
} // namespace tvm
-int TVMFFINDArrayFromDLPack(DLManagedTensor* from, int32_t min_alignment,
- int32_t require_contiguous, TVMFFIObjectHandle* out) {
+int TVMFFITensorFromDLPack(DLManagedTensor* from, int32_t min_alignment, int32_t require_contiguous,
+ TVMFFIObjectHandle* out) {
TVM_FFI_SAFE_CALL_BEGIN();
- tvm::ffi::NDArray nd =
- tvm::ffi::NDArray::FromDLPack(from, static_cast<size_t>(min_alignment), require_contiguous);
- *out = tvm::ffi::details::ObjectUnsafe::MoveObjectRefToTVMFFIObjectPtr(std::move(nd));
+ tvm::ffi::Tensor tensor =
+ tvm::ffi::Tensor::FromDLPack(from, static_cast<size_t>(min_alignment), require_contiguous);
+ *out = tvm::ffi::details::ObjectUnsafe::MoveObjectRefToTVMFFIObjectPtr(std::move(tensor));
TVM_FFI_SAFE_CALL_END();
}
-int TVMFFINDArrayFromDLPackVersioned(DLManagedTensorVersioned* from, int32_t min_alignment,
- int32_t require_contiguous, TVMFFIObjectHandle* out) {
+int TVMFFITensorFromDLPackVersioned(DLManagedTensorVersioned* from, int32_t min_alignment,
+ int32_t require_contiguous, TVMFFIObjectHandle* out) {
TVM_FFI_SAFE_CALL_BEGIN();
- tvm::ffi::NDArray nd = tvm::ffi::NDArray::FromDLPackVersioned(
+ tvm::ffi::Tensor tensor = tvm::ffi::Tensor::FromDLPackVersioned(
from, static_cast<size_t>(min_alignment), require_contiguous);
- *out = tvm::ffi::details::ObjectUnsafe::MoveObjectRefToTVMFFIObjectPtr(std::move(nd));
+ *out = tvm::ffi::details::ObjectUnsafe::MoveObjectRefToTVMFFIObjectPtr(std::move(tensor));
TVM_FFI_SAFE_CALL_END();
}
-int TVMFFINDArrayToDLPack(TVMFFIObjectHandle from, DLManagedTensor** out) {
+int TVMFFITensorToDLPack(TVMFFIObjectHandle from, DLManagedTensor** out) {
TVM_FFI_SAFE_CALL_BEGIN();
- *out = tvm::ffi::details::ObjectUnsafe::RawObjectPtrFromUnowned<tvm::ffi::NDArrayObj>(
+ *out = tvm::ffi::details::ObjectUnsafe::RawObjectPtrFromUnowned<tvm::ffi::TensorObj>(
static_cast<TVMFFIObject*>(from))
->ToDLPack();
TVM_FFI_SAFE_CALL_END();
}
-int TVMFFINDArrayToDLPackVersioned(TVMFFIObjectHandle from, DLManagedTensorVersioned** out) {
+int TVMFFITensorToDLPackVersioned(TVMFFIObjectHandle from, DLManagedTensorVersioned** out) {
TVM_FFI_SAFE_CALL_BEGIN();
- *out = tvm::ffi::details::ObjectUnsafe::RawObjectPtrFromUnowned<tvm::ffi::NDArrayObj>(
+ *out = tvm::ffi::details::ObjectUnsafe::RawObjectPtrFromUnowned<tvm::ffi::TensorObj>(
static_cast<TVMFFIObject*>(from))
->ToDLPackVersioned();
TVM_FFI_SAFE_CALL_END();
diff --git a/ffi/tests/cpp/test_example.cc b/ffi/tests/cpp/test_example.cc
index 68e5298219..9808be68da 100644
--- a/ffi/tests/cpp/test_example.cc
+++ b/ffi/tests/cpp/test_example.cc
@@ -20,7 +20,7 @@
#include <tvm/ffi/any.h>
#include <tvm/ffi/container/array.h>
#include <tvm/ffi/container/map.h>
-#include <tvm/ffi/container/ndarray.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/container/tuple.h>
#include <tvm/ffi/container/variant.h>
#include <tvm/ffi/function.h>
@@ -127,29 +127,29 @@ struct CPUNDAlloc {
void FreeData(DLTensor* tensor) { free(tensor->data); }
};
-void ExampleNDArray() {
+void ExampleTensor() {
namespace ffi = tvm::ffi;
ffi::Shape shape = {1, 2, 3};
DLDataType dtype = {kDLFloat, 32, 1};
DLDevice device = {kDLCPU, 0};
- ffi::NDArray nd = ffi::NDArray::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
+ ffi::Tensor tensor = ffi::Tensor::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
}
-void ExampleNDArrayDLPack() {
+void ExampleTensorDLPack() {
namespace ffi = tvm::ffi;
ffi::Shape shape = {1, 2, 3};
DLDataType dtype = {kDLFloat, 32, 1};
DLDevice device = {kDLCPU, 0};
- ffi::NDArray nd = ffi::NDArray::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
+ ffi::Tensor tensor = ffi::Tensor::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
// convert to DLManagedTensorVersioned
- DLManagedTensorVersioned* dlpack = nd.ToDLPackVersioned();
+ DLManagedTensorVersioned* dlpack = tensor.ToDLPackVersioned();
// load back from DLManagedTensorVersioned
- ffi::NDArray nd2 = ffi::NDArray::FromDLPackVersioned(dlpack);
+ ffi::Tensor tensor2 = ffi::Tensor::FromDLPackVersioned(dlpack);
}
-TEST(Example, NDArray) {
- ExampleNDArray();
- ExampleNDArrayDLPack();
+TEST(Example, Tensor) {
+ ExampleTensor();
+ ExampleTensorDLPack();
}
void ExampleString() {
diff --git a/ffi/tests/cpp/test_ndarray.cc b/ffi/tests/cpp/test_tensor.cc
similarity index 70%
rename from ffi/tests/cpp/test_ndarray.cc
rename to ffi/tests/cpp/test_tensor.cc
index 0196bfc4fb..17a6427af3 100644
--- a/ffi/tests/cpp/test_ndarray.cc
+++ b/ffi/tests/cpp/test_tensor.cc
@@ -17,7 +17,7 @@
* under the License.
*/
#include <gtest/gtest.h>
-#include <tvm/ffi/container/ndarray.h>
+#include <tvm/ffi/container/tensor.h>
namespace {
@@ -28,12 +28,12 @@ struct CPUNDAlloc {
void FreeData(DLTensor* tensor) { free(tensor->data); }
};
-inline NDArray Empty(Shape shape, DLDataType dtype, DLDevice device) {
- return NDArray::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
+inline Tensor Empty(Shape shape, DLDataType dtype, DLDevice device) {
+ return Tensor::FromNDAlloc(CPUNDAlloc(), shape, dtype, device);
}
-TEST(NDArray, Basic) {
- NDArray nd = Empty(Shape({1, 2, 3}), DLDataType({kDLFloat, 32, 1}), DLDevice({kDLCPU, 0}));
+TEST(Tensor, Basic) {
+ Tensor nd = Empty(Shape({1, 2, 3}), DLDataType({kDLFloat, 32, 1}), DLDevice({kDLCPU, 0}));
Shape shape = nd.shape();
EXPECT_EQ(shape.size(), 3);
EXPECT_EQ(shape[0], 1);
@@ -45,7 +45,7 @@ TEST(NDArray, Basic) {
}
Any any0 = nd;
- NDArray nd2 = any0.as<NDArray>().value();
+ Tensor nd2 = any0.as<Tensor>().value();
EXPECT_EQ(nd2.shape(), shape);
EXPECT_EQ(nd2.dtype(), DLDataType({kDLFloat, 32, 1}));
for (int64_t i = 0; i < shape.Product(); ++i) {
@@ -56,9 +56,9 @@ TEST(NDArray, Basic) {
EXPECT_EQ(nd2.use_count(), 3);
}
-TEST(NDArray, DLPack) {
- NDArray nd = Empty({1, 2, 3}, DLDataType({kDLInt, 16, 1}), DLDevice({kDLCPU, 0}));
- DLManagedTensor* dlpack = nd.ToDLPack();
+TEST(Tensor, DLPack) {
+ Tensor tensor = Empty({1, 2, 3}, DLDataType({kDLInt, 16, 1}), DLDevice({kDLCPU, 0}));
+ DLManagedTensor* dlpack = tensor.ToDLPack();
EXPECT_EQ(dlpack->dl_tensor.ndim, 3);
EXPECT_EQ(dlpack->dl_tensor.shape[0], 1);
EXPECT_EQ(dlpack->dl_tensor.shape[1], 2);
@@ -72,22 +72,22 @@ TEST(NDArray, DLPack) {
EXPECT_EQ(dlpack->dl_tensor.strides[0], 6);
EXPECT_EQ(dlpack->dl_tensor.strides[1], 3);
EXPECT_EQ(dlpack->dl_tensor.strides[2], 1);
- EXPECT_EQ(nd.use_count(), 2);
+ EXPECT_EQ(tensor.use_count(), 2);
{
- NDArray nd2 = NDArray::FromDLPack(dlpack);
- EXPECT_EQ(nd2.use_count(), 1);
- EXPECT_EQ(nd2->data, nd->data);
- EXPECT_EQ(nd.use_count(), 2);
- EXPECT_EQ(nd2.use_count(), 1);
+ Tensor tensor2 = Tensor::FromDLPack(dlpack);
+ EXPECT_EQ(tensor2.use_count(), 1);
+ EXPECT_EQ(tensor2->data, tensor->data);
+ EXPECT_EQ(tensor.use_count(), 2);
+ EXPECT_EQ(tensor2.use_count(), 1);
}
- EXPECT_EQ(nd.use_count(), 1);
+ EXPECT_EQ(tensor.use_count(), 1);
}
-TEST(NDArray, DLPackVersioned) {
+TEST(Tensor, DLPackVersioned) {
DLDataType dtype = DLDataType({kDLFloat4_e2m1fn, 4, 1});
EXPECT_EQ(GetDataSize(2, dtype), 2 * 4 / 8);
- NDArray nd = Empty({2}, dtype, DLDevice({kDLCPU, 0}));
- DLManagedTensorVersioned* dlpack = nd.ToDLPackVersioned();
+ Tensor tensor = Empty({2}, dtype, DLDevice({kDLCPU, 0}));
+ DLManagedTensorVersioned* dlpack = tensor.ToDLPackVersioned();
EXPECT_EQ(dlpack->version.major, DLPACK_MAJOR_VERSION);
EXPECT_EQ(dlpack->version.minor, DLPACK_MINOR_VERSION);
EXPECT_EQ(dlpack->dl_tensor.ndim, 1);
@@ -100,14 +100,14 @@ TEST(NDArray, DLPackVersioned) {
EXPECT_EQ(dlpack->dl_tensor.byte_offset, 0);
EXPECT_EQ(dlpack->dl_tensor.strides[0], 1);
- EXPECT_EQ(nd.use_count(), 2);
+ EXPECT_EQ(tensor.use_count(), 2);
{
- NDArray nd2 = NDArray::FromDLPackVersioned(dlpack);
- EXPECT_EQ(nd2.use_count(), 1);
- EXPECT_EQ(nd2->data, nd->data);
- EXPECT_EQ(nd.use_count(), 2);
- EXPECT_EQ(nd2.use_count(), 1);
+ Tensor tensor2 = Tensor::FromDLPackVersioned(dlpack);
+ EXPECT_EQ(tensor2.use_count(), 1);
+ EXPECT_EQ(tensor2->data, tensor->data);
+ EXPECT_EQ(tensor.use_count(), 2);
+ EXPECT_EQ(tensor2.use_count(), 1);
}
- EXPECT_EQ(nd.use_count(), 1);
+ EXPECT_EQ(tensor.use_count(), 1);
}
} // namespace
diff --git a/ffi/tests/python/test_function.py b/ffi/tests/python/test_function.py
index 4b0db45b4b..0b45fe5583 100644
--- a/ffi/tests/python/test_function.py
+++ b/ffi/tests/python/test_function.py
@@ -74,21 +74,21 @@ def test_echo():
assert fadd1(1, 2) == 3
assert fadd1.same_as(fadd)
- def check_ndarray():
+ def check_tensor():
np_data = np.arange(10, dtype="int32")
if not hasattr(np_data, "__dlpack__"):
return
- # test NDArray
+ # test Tensor
x = tvm_ffi.from_dlpack(np_data)
- assert isinstance(x, tvm_ffi.NDArray)
- nd_result = fecho(x)
- assert isinstance(nd_result, tvm_ffi.NDArray)
- assert nd_result.shape == (10,)
- assert nd_result.dtype == tvm_ffi.dtype("int32")
- assert nd_result.device.device_type == tvm_ffi.Device.kDLCPU
- assert nd_result.device.device_id == 0
-
- check_ndarray()
+ assert isinstance(x, tvm_ffi.Tensor)
+ tensor_result = fecho(x)
+ assert isinstance(tensor_result, tvm_ffi.Tensor)
+ assert tensor_result.shape == (10,)
+ assert tensor_result.dtype == tvm_ffi.dtype("int32")
+ assert tensor_result.device.device_type == tvm_ffi.Device.kDLCPU
+ assert tensor_result.device.device_id == 0
+
+ check_tensor()
def test_return_raw_str_bytes():
diff --git a/ffi/tests/python/test_ndarray.py b/ffi/tests/python/test_tensor.py
similarity index 93%
rename from ffi/tests/python/test_ndarray.py
rename to ffi/tests/python/test_tensor.py
index f0ce0d193c..2e2a999400 100644
--- a/ffi/tests/python/test_ndarray.py
+++ b/ffi/tests/python/test_tensor.py
@@ -25,12 +25,12 @@ import tvm_ffi
import numpy as np
-def test_ndarray_attributes():
+def test_tensor_attributes():
data = np.zeros((10, 8, 4, 2), dtype="int16")
if not hasattr(data, "__dlpack__"):
return
x = tvm_ffi.from_dlpack(data)
- assert isinstance(x, tvm_ffi.NDArray)
+ assert isinstance(x, tvm_ffi.Tensor)
assert x.shape == (10, 8, 4, 2)
assert x.dtype == tvm_ffi.dtype("int16")
assert x.device.device_type == tvm_ffi.Device.kDLCPU
@@ -56,9 +56,9 @@ def test_shape_object():
@pytest.mark.skipif(torch is None, reason="Torch is not installed")
-def test_ndarray_auto_dlpack():
+def test_tensor_auto_dlpack():
def check(x, y):
- assert isinstance(y, tvm_ffi.NDArray)
+ assert isinstance(y, tvm_ffi.Tensor)
assert y.shape == (128,)
assert y.dtype == tvm_ffi.dtype("int64")
assert y.device.device_type == tvm_ffi.Device.kDLCPU
diff --git a/include/tvm/ir/module.h b/include/tvm/ir/module.h
index 6f7d6d2d13..f04a6cfe6d 100644
--- a/include/tvm/ir/module.h
+++ b/include/tvm/ir/module.h
@@ -314,11 +314,11 @@ namespace attr {
constexpr const char* kModuleName = "mod_name";
/*
- * \brief All the runtime::NDArrays extracted from PrimFunc tir::AllocateConst nodes. The
+ * \brief All the runtime::Tensors extracted from PrimFunc tir::AllocateConst nodes. The
* node will record the index into this array. See also kConstNameToConstant below, which is
* the analog for Realy Functions.
*
- * Type: Array<runtime::NDArray>
+ * Type: Array<runtime::Tensor>
*/
constexpr const char* kConstants = "constants";
@@ -360,12 +360,12 @@ constexpr const char* kExternalMods = "external_mods";
constexpr const char* kSystemLibPrefix = "system_lib_prefix";
/*!
- * \brief All the named runtime::NDArrays accumulated during compilation by external codegen.
+ * \brief All the named runtime::Tensors accumulated during compilation by external codegen.
* Generally the associated runtime::Module will indicate it requires bindings for these names,
* and during module initialization these bindings will be recovered from a ConstLoaderModule.
* See also kConstantsArray above, which is the analog for PrimFuncs.
*
- * Type: Map<String, runtime::NDArray>
+ * Type: Map<String, runtime::Tensor>
*/
constexpr const char* kConstNameToConstant = "const_name_to_constant";
diff --git a/include/tvm/meta_schedule/builder.h b/include/tvm/meta_schedule/builder.h
index 7e0be7de82..a5c3fe5f2c 100644
--- a/include/tvm/meta_schedule/builder.h
+++ b/include/tvm/meta_schedule/builder.h
@@ -26,8 +26,8 @@
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ffi/string.h>
#include <tvm/ir/module.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
+#include <tvm/runtime/tensor.h>
#include <tvm/target/target.h>
namespace tvm {
@@ -41,7 +41,7 @@ class BuilderInputNode : public runtime::Object {
/*! \brief The target to be built for. */
Target target;
/*! \brief Parameters for Relax build module. */
- Optional<Map<String, runtime::NDArray>> params;
+ Optional<Map<String, runtime::Tensor>> params;
static void RegisterReflection() {
namespace refl = tvm::ffi::reflection;
@@ -68,7 +68,7 @@ class BuilderInput : public runtime::ObjectRef {
* \param params Parameters for Relax build module.
*/
TVM_DLL explicit BuilderInput(IRModule mod, Target target,
- Optional<Map<String, runtime::NDArray>> params = std::nullopt);
+ Optional<Map<String, runtime::Tensor>> params = std::nullopt);
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(BuilderInput, runtime::ObjectRef, BuilderInputNode);
};
diff --git a/include/tvm/meta_schedule/database.h b/include/tvm/meta_schedule/database.h
index 29bc030c5b..6c631a9eca 100644
--- a/include/tvm/meta_schedule/database.h
+++ b/include/tvm/meta_schedule/database.h
@@ -192,10 +192,10 @@ class DatabaseNode : public runtime::Object {
* \param mod_eq_name A string to specify the module equality testing and hashing method.
* It must be one of the followings:
* - "structural": Use StructuralEqual/Hash
- * - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ * - "ignore-tensor": Same as "structural", but ignore tensor raw data during
* equality testing and hashing.
* - "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- * given module. The "ignore-ndarray" varint is used for the extracted blocks
+ * given module. The "ignore-tensor" varint is used for the extracted blocks
* or in case no anchor block is found.
* For the definition of the anchor block, see tvm/tir/analysis.h.
*/
@@ -291,10 +291,10 @@ class PyDatabaseNode : public DatabaseNode {
* \param mod_eq_name A string to specify the module equality testing and hashing method.
* It must be one of the followings:
* - "structural": Use StructuralEqual/Hash
- * - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ * - "ignore-tensor": Same as "structural", but ignore tensor raw data during
* equality testing and hashing.
* - "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- * given module. The "ignore-ndarray" varint is used for the extracted blocks
+ * given module. The "ignore-tensor" varint is used for the extracted blocks
* or in case no anchor block is found.
* For the definition of the anchor block, see tvm/tir/analysis.h.
*/
diff --git a/include/tvm/meta_schedule/feature_extractor.h b/include/tvm/meta_schedule/feature_extractor.h
index 88bf056ebb..88fcf9ac61 100644
--- a/include/tvm/meta_schedule/feature_extractor.h
+++ b/include/tvm/meta_schedule/feature_extractor.h
@@ -25,8 +25,8 @@
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ffi/string.h>
#include <tvm/meta_schedule/measure_candidate.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
+#include <tvm/runtime/tensor.h>
namespace tvm {
namespace meta_schedule {
@@ -47,10 +47,10 @@ class FeatureExtractorNode : public runtime::Object {
* \brief Extract features from the given measure candidate.
* \param context The tuning context for feature extraction.
* \param candidates The measure candidates to extract features from.
- * \return The feature ndarray extracted.
+ * \return The feature tensor extracted.
*/
- virtual Array<tvm::runtime::NDArray> ExtractFrom(const TuneContext& context,
- const Array<MeasureCandidate>& candidates) = 0;
+ virtual Array<tvm::runtime::Tensor> ExtractFrom(const TuneContext& context,
+ const Array<MeasureCandidate>& candidates) = 0;
static constexpr const char* _type_key = "meta_schedule.FeatureExtractor";
TVM_DECLARE_BASE_OBJECT_INFO(FeatureExtractorNode, Object);
@@ -63,9 +63,9 @@ class PyFeatureExtractorNode : public FeatureExtractorNode {
* \brief Extract features from the given measure candidate.
* \param context The tuning context for feature extraction.
* \param candidates The measure candidates to extract features from.
- * \return The feature ndarray extracted.
+ * \return The feature tensor extracted.
*/
- using FExtractFrom = ffi::TypedFunction<Array<tvm::runtime::NDArray>(
+ using FExtractFrom = ffi::TypedFunction<Array<tvm::runtime::Tensor>(
const TuneContext& context, const Array<MeasureCandidate>& candidates)>;
/*!
* \brief Get the feature extractor as string with name.
@@ -83,8 +83,8 @@ class PyFeatureExtractorNode : public FeatureExtractorNode {
// `f_as_string` is not registered
}
- Array<tvm::runtime::NDArray> ExtractFrom(const TuneContext& context,
- const Array<MeasureCandidate>& candidates) final;
+ Array<tvm::runtime::Tensor> ExtractFrom(const TuneContext& context,
+ const Array<MeasureCandidate>& candidates) final;
static constexpr const char* _type_key = "meta_schedule.PyFeatureExtractor";
TVM_DECLARE_FINAL_OBJECT_INFO(PyFeatureExtractorNode, FeatureExtractorNode);
diff --git a/include/tvm/node/structural_hash.h b/include/tvm/node/structural_hash.h
index 0aca92d0e2..2c0c54db41 100644
--- a/include/tvm/node/structural_hash.h
+++ b/include/tvm/node/structural_hash.h
@@ -25,7 +25,7 @@
#include <tvm/node/functor.h>
#include <tvm/runtime/data_type.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cmath>
#include <functional>
diff --git a/include/tvm/relax/expr.h b/include/tvm/relax/expr.h
index 22cda9e066..e7198fcf22 100644
--- a/include/tvm/relax/expr.h
+++ b/include/tvm/relax/expr.h
@@ -432,7 +432,7 @@ class DataflowVar : public Var {
class ConstantNode : public LeafExprNode {
public:
/*! \brief The data of the tensor */
- runtime::NDArray data;
+ runtime::Tensor data;
/*! \return The corresponding tensor type of the data */
TensorType tensor_type() const;
@@ -458,7 +458,7 @@ class Constant : public LeafExpr {
* If not specified, infer it from data.
* \param span The source span of the expression.
*/
- TVM_DLL explicit Constant(runtime::NDArray data,
+ TVM_DLL explicit Constant(runtime::Tensor data,
Optional<StructInfo> struct_info_annotation = std::nullopt,
Span span = Span());
diff --git a/include/tvm/runtime/disco/builtin.h b/include/tvm/runtime/disco/builtin.h
index bc0faf2413..acd4a214ff 100644
--- a/include/tvm/runtime/disco/builtin.h
+++ b/include/tvm/runtime/disco/builtin.h
@@ -21,7 +21,7 @@
#include <tvm/runtime/data_type.h>
#include <tvm/runtime/module.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <string>
@@ -64,13 +64,13 @@ inline std::string ReduceKind2String(ReduceKind kind) {
*/
TVM_DLL ffi::Module LoadVMModule(std::string path, Optional<Device> device);
/*!
- * \brief Create an uninitialized empty NDArray
- * \param shape The shape of the NDArray
- * \param dtype The dtype of the NDArray
- * \param device The device the NDArray is created on. If None, use the thread local default device
- * \return The NDArray created
+ * \brief Create an uninitialized empty Tensor
+ * \param shape The shape of the Tensor
+ * \param dtype The dtype of the Tensor
+ * \param device The device the Tensor is created on. If None, use the thread local default device
+ * \return The Tensor created
*/
-TVM_DLL NDArray DiscoEmptyNDArray(ffi::Shape shape, DataType dtype, Optional<Device> device);
+TVM_DLL Tensor DiscoEmptyTensor(ffi::Shape shape, DataType dtype, Optional<Device> device);
/*!
* \brief Perform an allreduce operation using the underlying communication library
* \param send The array send to perform allreduce on
@@ -78,21 +78,21 @@ TVM_DLL NDArray DiscoEmptyNDArray(ffi::Shape shape, DataType dtype, Optional<Dev
* \param in_group Whether the allreduce operation performs globally or in group as default.
* \param recv The array receives the outcome of allreduce
*/
-TVM_DLL void AllReduce(NDArray send, ReduceKind reduce_kind, bool in_group, NDArray recv);
+TVM_DLL void AllReduce(Tensor send, ReduceKind reduce_kind, bool in_group, Tensor recv);
/*!
* \brief Perform an allgather operation using the underlying communication library
* \param send The array send to perform allgather on
* \param in_group Whether the allgather operation performs globally or in group as default.
* \param recv The array receives the outcome of allgather
*/
-TVM_DLL void AllGather(NDArray send, bool in_group, NDArray recv);
+TVM_DLL void AllGather(Tensor send, bool in_group, Tensor recv);
/*!
* \brief Perform a broadcast operation from worker-0
* \param send The buffer to be broadcasted
* \param in_group Whether the broadcast operation performs globally or in group as default.
* \param recv The buffer receives the broadcasted array
*/
-TVM_DLL void BroadcastFromWorker0(NDArray send, bool in_group, NDArray recv);
+TVM_DLL void BroadcastFromWorker0(Tensor send, bool in_group, Tensor recv);
/*!
* \brief Perform a scatter operation from worker-0, chunking the given buffer into equal parts.
* \param send For worker-0, it must be provided, and otherwise, the buffer must be None.
@@ -100,7 +100,7 @@ TVM_DLL void BroadcastFromWorker0(NDArray send, bool in_group, NDArray recv);
* \param in_group Whether the scatter operation performs globally or in group as default.
* \param recv The receiving buffer, which must not be None.
*/
-TVM_DLL void ScatterFromWorker0(Optional<NDArray> send, bool in_group, NDArray recv);
+TVM_DLL void ScatterFromWorker0(Optional<Tensor> send, bool in_group, Tensor recv);
/*!
* \brief Perform a gather operation to worker-0.
* \param send The sending buffer, which must not be None.
@@ -108,36 +108,36 @@ TVM_DLL void ScatterFromWorker0(Optional<NDArray> send, bool in_group, NDArray r
* \param recv For worker-0, it must be provided, and otherwise, the buffer must be None. The
* receiving buffer will be divided into equal parts and receive from each worker accordingly.
*/
-TVM_DLL void GatherToWorker0(NDArray send, bool in_group, Optional<NDArray> recv);
+TVM_DLL void GatherToWorker0(Tensor send, bool in_group, Optional<Tensor> recv);
/*!
* \brief Receive a buffer from worker-0. No-op if the current worker is worker-0.
* \param buffer The buffer to be received
*/
-TVM_DLL void RecvFromWorker0(NDArray buffer);
+TVM_DLL void RecvFromWorker0(Tensor buffer);
/*!
* \brief Send a buffer to the corresponding worker in the next group.
* An error is thrown if the worker is already in the last group.
* \param buffer The sending buffer.
*/
-TVM_DLL void SendToNextGroup(NDArray buffer);
+TVM_DLL void SendToNextGroup(Tensor buffer);
/*!
* \brief Receive a buffer from the corresponding worker in the previous group.
* An error is thrown if the worker is already in the first group.
* \param buffer The receiving buffer.
*/
-TVM_DLL void RecvFromPrevGroup(NDArray buffer);
+TVM_DLL void RecvFromPrevGroup(Tensor buffer);
/*!
* \brief Send a buffer to the target receiver worker (globally across all groups).
* \param buffer The sending buffer.
* \param receiver_id The global receiver worker id.
*/
-TVM_DLL void SendToWorker(NDArray buffer, int receiver_id);
+TVM_DLL void SendToWorker(Tensor buffer, int receiver_id);
/*!
* \brief Receive a buffer from the target sender worker (globally across all groups).
* \param buffer The receiving buffer.
* \param sender_id The global sender worker id.
*/
-TVM_DLL void RecvFromWorker(NDArray buffer, int sender_id);
+TVM_DLL void RecvFromWorker(Tensor buffer, int sender_id);
/*! \brief Get the local worker id */
TVM_DLL int WorkerId();
/*!
diff --git a/include/tvm/runtime/disco/session.h b/include/tvm/runtime/disco/session.h
index 4fe0e72e79..72ac577d52 100644
--- a/include/tvm/runtime/disco/session.h
+++ b/include/tvm/runtime/disco/session.h
@@ -46,7 +46,7 @@
* It is assumed that the controler can synchronize with and access the registers of worker-0.
* The Disco session provides multiple APIs to interact specifically with the worker-0.
* To shared data with other workers, a common paradigm in Disco is to copy data from the
- * controler-side NDArray to the worker-0, and then copy it to other workers using primitives on
+ * controler-side Tensor to the worker-0, and then copy it to other workers using primitives on
* the data plane, for example, `broadcast` and `send`.
*
* **Control plane.** The controler broadcasts commands to all the workers as control signals.
@@ -74,8 +74,8 @@
#include <tvm/ffi/function.h>
#include <tvm/runtime/int_tuple.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
+#include <tvm/runtime/tensor.h>
#include <queue>
#include <string>
@@ -143,9 +143,9 @@ class DRefObj : public Object {
*/
inline ffi::Any DebugGetFromRemote(int worker_id);
/*!
- * \brief Copy from the NDArray provided to a remote worker.
+ * \brief Copy from the Tensor provided to a remote worker.
* \param worker_id The id of the worker to be copied to.
- * \param source The NDArray to be copied.
+ * \param source The Tensor to be copied.
*/
inline void DebugCopyFrom(int worker_id, ffi::AnyView source);
@@ -189,7 +189,7 @@ class SessionObj : public Object {
* - std::string;
* - DRef.
* Examples of unsupported types:
- * - NDArray, DLTensor;
+ * - Tensor, DLTensor;
* - TVM Objects, including ffi::Function, Module and String;
* \param func The function to be called.
* \param args The variadic arguments.
@@ -209,17 +209,17 @@ class SessionObj : public Object {
/*! \brief Get a global functions on workers. */
TVM_DLL virtual DRef GetGlobalFunc(const std::string& name) = 0;
/*!
- * \brief Copy an NDArray from worker-0 to the controler-side NDArray
+ * \brief Copy an Tensor from worker-0 to the controler-side Tensor
* \param host_array The array to be copied to worker-0
- * \param remote_array The NDArray on worker-0
+ * \param remote_array The Tensor on worker-0
*/
- TVM_DLL virtual void CopyFromWorker0(const NDArray& host_array, const DRef& remote_array) = 0;
+ TVM_DLL virtual void CopyFromWorker0(const Tensor& host_array, const DRef& remote_array) = 0;
/*!
- * \brief Copy the controler-side NDArray to worker-0
+ * \brief Copy the controler-side Tensor to worker-0
* \param host_array The array to be copied to worker-0
- * \param remote_array The NDArray on worker-0
+ * \param remote_array The Tensor on worker-0
*/
- TVM_DLL virtual void CopyToWorker0(const NDArray& host_array, const DRef& remote_array) = 0;
+ TVM_DLL virtual void CopyToWorker0(const Tensor& host_array, const DRef& remote_array) = 0;
/*!
* \brief Synchrnoize the controler with a worker, and it will wait until worker finishes
* executing this instruction.
@@ -319,7 +319,7 @@ class WorkerZeroData {
* \brief The host-side arrays to passed to worker-0 for special uses, for example,
* copy-to-worker0 and copy-from-worker0
*/
- std::queue<NDArray> host_arrays;
+ std::queue<Tensor> host_arrays;
/*! \brief The mutex that guards `host_arrays` */
std::mutex queue_mutex_;
};
diff --git a/include/tvm/runtime/memory/memory_manager.h b/include/tvm/runtime/memory/memory_manager.h
index f103c6f30a..a10bc6b36e 100644
--- a/include/tvm/runtime/memory/memory_manager.h
+++ b/include/tvm/runtime/memory/memory_manager.h
@@ -25,8 +25,8 @@
#define TVM_RUNTIME_MEMORY_MEMORY_MANAGER_H_
#include <tvm/runtime/base.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
+#include <tvm/runtime/tensor.h>
#include <functional>
#include <memory>
@@ -59,15 +59,15 @@ class Allocator {
public:
explicit Allocator(AllocatorType type) : type_(type) {}
virtual ~Allocator() = default;
- /*! \brief Allocate an empty NDArray using from the allocator.
- * \param shape The shape of the NDArray.
- * \param dtype The datatype of the NDArray.
+ /*! \brief Allocate an empty Tensor using from the allocator.
+ * \param shape The shape of the Tensor.
+ * \param dtype The datatype of the Tensor.
* \param dev The device where the array is allocated.
* \param mem_scope The device memory scope hint.
- * \return The empty NDArray.
+ * \return The empty Tensor.
*/
- TVM_DLL NDArray Empty(ffi::Shape shape, DLDataType dtype, Device dev,
- Optional<String> mem_scope = std::nullopt);
+ TVM_DLL Tensor Empty(ffi::Shape shape, DLDataType dtype, Device dev,
+ Optional<String> mem_scope = std::nullopt);
/*! \brief Return the allocator type. */
inline AllocatorType type() const { return type_; }
/*! \brief Allocate a buffer given a size, alignment and type.
@@ -163,12 +163,12 @@ class StorageObj : public Object {
/*! \brief The allocator where the storage buffer is allocated from. */
Allocator* allocator = nullptr;
- /*! \brief Allocate an NDArray from a given piece of storage. */
- TVM_DLL NDArray AllocNDArray(int64_t offset, ffi::Shape shape, DLDataType dtype);
+ /*! \brief Allocate an Tensor from a given piece of storage. */
+ TVM_DLL Tensor AllocTensor(int64_t offset, ffi::Shape shape, DLDataType dtype);
- /*! \brief Allocate an NDArray with memory scope from a given piece of storage. */
- TVM_DLL NDArray AllocNDArrayScoped(int64_t offset, ffi::Shape shape, DLDataType dtype,
- String scope = "global");
+ /*! \brief Allocate an Tensor with memory scope from a given piece of storage. */
+ TVM_DLL Tensor AllocTensorScoped(int64_t offset, ffi::Shape shape, DLDataType dtype,
+ String scope = "global");
~StorageObj() {
if (allocator) {
diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h
index 302b161b6f..9da9467e8f 100644
--- a/include/tvm/runtime/object.h
+++ b/include/tvm/runtime/object.h
@@ -52,8 +52,8 @@ enum TypeIndex : int32_t {
// Frontends can take benefit of these constants.
/*! \brief runtime::Module. */
kRuntimeModule = TVMFFITypeIndex::kTVMFFIModule,
- /*! \brief runtime::NDArray. */
- kRuntimeNDArray = TVMFFITypeIndex::kTVMFFINDArray,
+ /*! \brief runtime::Tensor. */
+ kRuntimeTensor = TVMFFITypeIndex::kTVMFFITensor,
/*! \brief runtime::Shape. */
kRuntimeShape = TVMFFITypeIndex::kTVMFFIShape,
// Extra builtin static index here
diff --git a/include/tvm/runtime/profiling.h b/include/tvm/runtime/profiling.h
index 9f25b6775c..88a22c9816 100644
--- a/include/tvm/runtime/profiling.h
+++ b/include/tvm/runtime/profiling.h
@@ -30,8 +30,8 @@
#include <tvm/runtime/base.h>
#include <tvm/runtime/device_api.h>
#include <tvm/runtime/module.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/object.h>
+#include <tvm/runtime/tensor.h>
#include <stack>
#include <string>
@@ -490,17 +490,17 @@ class RatioNode : public Object {
TVM_DECLARE_FINAL_OBJECT_INFO(RatioNode, Object);
};
-/*! \brief String representation of an array of NDArray shapes
- * \param shapes Array of NDArrays to get the shapes of.
+/*! \brief String representation of an array of Tensor shapes
+ * \param shapes Array of Tensors to get the shapes of.
* \return A textual representation of the shapes. For example: `float32[2], int64[1, 2]`.
*/
-String ShapeString(const std::vector<NDArray>& shapes);
-/*! \brief String representation of shape encoded as an NDArray
- * \param shape NDArray containing the shape.
+String ShapeString(const std::vector<Tensor>& shapes);
+/*! \brief String representation of shape encoded as an Tensor
+ * \param shape Tensor containing the shape.
* \param dtype The dtype of the shape.
* \return A textual representation of the shape. For example: `float32[2]`.
*/
-String ShapeString(NDArray shape, DLDataType dtype);
+String ShapeString(Tensor shape, DLDataType dtype);
/*! \brief String representation of a shape encoded as a vector
* \param shape Shape as a vector of integers.
* \param dtype The dtype of the shape.
diff --git a/include/tvm/runtime/serializer.h b/include/tvm/runtime/serializer.h
index 2cfd1de44d..c8e9d3c435 100644
--- a/include/tvm/runtime/serializer.h
+++ b/include/tvm/runtime/serializer.h
@@ -28,7 +28,7 @@
#include <dmlc/io.h>
#include <dmlc/serializer.h>
#include <tvm/runtime/base.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
namespace dmlc {
namespace serializer {
diff --git a/include/tvm/runtime/ndarray.h b/include/tvm/runtime/tensor.h
similarity index 78%
rename from include/tvm/runtime/ndarray.h
rename to include/tvm/runtime/tensor.h
index 9a295e491e..9536dd2005 100644
--- a/include/tvm/runtime/ndarray.h
+++ b/include/tvm/runtime/tensor.h
@@ -18,14 +18,14 @@
*/
/*!
- * \file tvm/runtime/ndarray.h
- * \brief A device-independent managed NDArray abstraction.
+ * \file tvm/runtime/tensor.h
+ * \brief A device-independent managed Tensor abstraction.
*/
-#ifndef TVM_RUNTIME_NDARRAY_H_
-#define TVM_RUNTIME_NDARRAY_H_
+#ifndef TVM_RUNTIME_TENSOR_H_
+#define TVM_RUNTIME_TENSOR_H_
-#include <tvm/ffi/container/ndarray.h>
#include <tvm/ffi/container/shape.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/optional.h>
#include <tvm/ffi/string.h>
#include <tvm/runtime/base.h>
@@ -47,31 +47,31 @@ using ffi::IsAligned;
using ffi::IsContiguous;
/*!
- * \brief Managed NDArray.
+ * \brief Managed Tensor.
* The array is backed by reference counted blocks.
*/
-class NDArray : public tvm::ffi::NDArray {
+class Tensor : public tvm::ffi::Tensor {
public:
- using Container = ffi::NDArrayObj;
- NDArray() = default;
+ using Container = ffi::TensorObj;
+ Tensor() = default;
/*!
* \brief constructor.
* \param data ObjectPtr to the data container.
*/
- explicit NDArray(ObjectPtr<Object> data) : tvm::ffi::NDArray(data) {}
- NDArray(ffi::NDArray&& other) : tvm::ffi::NDArray(std::move(other)) {} // NOLINT(*)
- NDArray(const ffi::NDArray& other) : tvm::ffi::NDArray(other) {} // NOLINT(*)
+ explicit Tensor(ObjectPtr<Object> data) : tvm::ffi::Tensor(data) {}
+ Tensor(ffi::Tensor&& other) : tvm::ffi::Tensor(std::move(other)) {} // NOLINT(*)
+ Tensor(const ffi::Tensor& other) : tvm::ffi::Tensor(other) {} // NOLINT(*)
ffi::Shape Shape() const { return this->shape(); }
runtime::DataType DataType() const { return runtime::DataType(this->dtype()); }
// DLPack handling
- static NDArray FromDLPack(DLManagedTensor* tensor) {
- return tvm::ffi::NDArray::FromDLPack(tensor, kAllocAlignment, true);
+ static Tensor FromDLPack(DLManagedTensor* tensor) {
+ return tvm::ffi::Tensor::FromDLPack(tensor, kAllocAlignment, true);
}
- static NDArray FromDLPackVersioned(DLManagedTensorVersioned* tensor) {
- return tvm::ffi::NDArray::FromDLPackVersioned(tensor, kAllocAlignment, true);
+ static Tensor FromDLPackVersioned(DLManagedTensorVersioned* tensor) {
+ return tvm::ffi::Tensor::FromDLPackVersioned(tensor, kAllocAlignment, true);
}
/*!
* \brief Copy data content from another array.
@@ -80,12 +80,12 @@ class NDArray : public tvm::ffi::NDArray {
* TVMSynchronize is necessary.
*/
inline void CopyFrom(const DLTensor* other);
- inline void CopyFrom(const NDArray& other);
+ inline void CopyFrom(const Tensor& other);
/*!
* \brief Copy data content from a byte buffer.
* \param data The source bytes to be copied from.
* \param nbytes The size of the buffer in bytes
- * Must be equal to the size of the NDArray.
+ * Must be equal to the size of the Tensor.
* \note The copy always triggers a TVMSynchronize.
*/
TVM_DLL void CopyFromBytes(const void* data, size_t nbytes);
@@ -96,12 +96,12 @@ class NDArray : public tvm::ffi::NDArray {
* TVMSynchronize is necessary.
*/
inline void CopyTo(DLTensor* other) const;
- inline void CopyTo(const NDArray& other) const;
+ inline void CopyTo(const Tensor& other) const;
/*!
* \brief Copy data content into another array.
* \param data The source bytes to be copied from.
* \param nbytes The size of the data buffer.
- * Must be equal to the size of the NDArray.
+ * Must be equal to the size of the Tensor.
* \note The copy always triggers a TVMSynchronize.
*/
TVM_DLL void CopyToBytes(void* data, size_t nbytes) const;
@@ -112,27 +112,27 @@ class NDArray : public tvm::ffi::NDArray {
* \return The array under another device.
* \note The copy always triggers a TVMSynchronize.
*/
- TVM_DLL NDArray CopyTo(const Device& dev, Optional<String> mem_scope = std::nullopt) const;
+ TVM_DLL Tensor CopyTo(const Device& dev, Optional<String> mem_scope = std::nullopt) const;
/*!
- * \brief Load NDArray from stream
+ * \brief Load Tensor from stream
* \param stream The input data stream
* \return Whether load is successful
*/
inline bool Load(dmlc::Stream* stream);
/*!
- * \brief Save NDArray to stream
+ * \brief Save Tensor to stream
* \param stream The output data stream
*/
inline void Save(dmlc::Stream* stream) const;
/*!
- * \brief Create a NDArray that shares the data memory with the current one.
+ * \brief Create a Tensor that shares the data memory with the current one.
*
* \param shape The shape of the new array.
*
* \param dtype The data type of the new array.
*
- * \param relative_byte_offset The offset of the output NDArray,
+ * \param relative_byte_offset The offset of the output Tensor,
* relative to the current byte offset.
*
* By default, the offset of the view is the same as the offset
@@ -145,18 +145,18 @@ class NDArray : public tvm::ffi::NDArray {
* outside the bounds of the current array, this function will
* raise an exception.
*/
- TVM_DLL NDArray CreateView(ffi::Shape shape, DLDataType dtype,
- uint64_t relative_byte_offset = 0) const;
+ TVM_DLL Tensor CreateView(ffi::Shape shape, DLDataType dtype,
+ uint64_t relative_byte_offset = 0) const;
/*!
- * \brief Create an empty NDArray.
+ * \brief Create an empty Tensor.
* \param shape The shape of the new array.
* \param dtype The data type of the new array.
* \param dev The device of the array.
* \param mem_scope The memory scope of the array.
* \return The created Array
*/
- TVM_DLL static NDArray Empty(ffi::Shape shape, DLDataType dtype, Device dev,
- Optional<String> mem_scope = std::nullopt);
+ TVM_DLL static Tensor Empty(ffi::Shape shape, DLDataType dtype, Device dev,
+ Optional<String> mem_scope = std::nullopt);
/*!
* \brief Function to copy data from one array to another.
* \param from The source array.
@@ -184,33 +184,33 @@ class NDArray : public tvm::ffi::NDArray {
*/
inline bool SaveDLTensor(dmlc::Stream* strm, const DLTensor* tensor);
-inline void NDArray::CopyFrom(const DLTensor* other) {
+inline void Tensor::CopyFrom(const DLTensor* other) {
ICHECK(data_ != nullptr);
CopyFromTo(other, get_mutable());
}
-inline void NDArray::CopyFrom(const NDArray& other) {
+inline void Tensor::CopyFrom(const Tensor& other) {
ICHECK(data_ != nullptr);
ICHECK(other.data_ != nullptr);
CopyFromTo(other.get_mutable(), get_mutable());
}
-inline void NDArray::CopyTo(DLTensor* other) const {
+inline void Tensor::CopyTo(DLTensor* other) const {
ICHECK(data_ != nullptr);
CopyFromTo(get_mutable(), other);
}
-inline void NDArray::CopyTo(const NDArray& other) const {
+inline void Tensor::CopyTo(const Tensor& other) const {
ICHECK(data_ != nullptr);
ICHECK(other.data_ != nullptr);
CopyFromTo(get_mutable(), other.get_mutable());
}
-/*! \brief Magic number for NDArray file */
-constexpr uint64_t kTVMNDArrayMagic = 0xDD5E40F096B4A13F;
+/*! \brief Magic number for Tensor file */
+constexpr uint64_t kTVMTensorMagic = 0xDD5E40F096B4A13F;
inline bool SaveDLTensor(dmlc::Stream* strm, const DLTensor* tensor) {
- uint64_t header = kTVMNDArrayMagic, reserved = 0;
+ uint64_t header = kTVMTensorMagic, reserved = 0;
strm->Write(header);
strm->Write(reserved);
// Always save data as CPU context
@@ -244,7 +244,7 @@ inline bool SaveDLTensor(dmlc::Stream* strm, const DLTensor* tensor) {
strm->Write(tensor->data, data_byte_size);
} else {
std::vector<uint8_t> bytes(data_byte_size);
- NDArray::CopyToBytes(const_cast<DLTensor*>(tensor), dmlc::BeginPtr(bytes), data_byte_size);
+ Tensor::CopyToBytes(const_cast<DLTensor*>(tensor), dmlc::BeginPtr(bytes), data_byte_size);
if (!DMLC_IO_NO_ENDIAN_SWAP) {
dmlc::ByteSwap(dmlc::BeginPtr(bytes), type_bytes, num_elems);
}
@@ -253,13 +253,13 @@ inline bool SaveDLTensor(dmlc::Stream* strm, const DLTensor* tensor) {
return true;
}
-inline void NDArray::Save(dmlc::Stream* strm) const { SaveDLTensor(strm, operator->()); }
+inline void Tensor::Save(dmlc::Stream* strm) const { SaveDLTensor(strm, operator->()); }
-inline bool NDArray::Load(dmlc::Stream* strm) {
+inline bool Tensor::Load(dmlc::Stream* strm) {
uint64_t header, reserved;
ICHECK(strm->Read(&header)) << "Invalid DLTensor file format";
ICHECK(strm->Read(&reserved)) << "Invalid DLTensor file format";
- ICHECK(header == kTVMNDArrayMagic) << "Invalid DLTensor file format";
+ ICHECK(header == kTVMTensorMagic) << "Invalid DLTensor file format";
Device dev;
int ndim;
DLDataType dtype;
@@ -271,7 +271,7 @@ inline bool NDArray::Load(dmlc::Stream* strm) {
if (ndim != 0) {
ICHECK(strm->ReadArray(&shape[0], ndim)) << "Invalid DLTensor file format";
}
- NDArray ret = NDArray::Empty(ffi::Shape(shape), dtype, dev);
+ Tensor ret = Tensor::Empty(ffi::Shape(shape), dtype, dev);
int64_t num_elems = 1;
int elem_bytes = (ret->dtype.bits + 7) / 8;
for (int i = 0; i < ret->ndim; ++i) {
@@ -328,4 +328,4 @@ struct equal_to<tvm::Device> {
};
} // namespace std
-#endif // TVM_RUNTIME_NDARRAY_H_
+#endif // TVM_RUNTIME_TENSOR_H_
diff --git a/include/tvm/runtime/vm/ndarray_cache_support.h b/include/tvm/runtime/vm/tensor_cache_support.h
similarity index 68%
rename from include/tvm/runtime/vm/ndarray_cache_support.h
rename to include/tvm/runtime/vm/tensor_cache_support.h
index 3ab08df043..d2112cc83f 100644
--- a/include/tvm/runtime/vm/ndarray_cache_support.h
+++ b/include/tvm/runtime/vm/tensor_cache_support.h
@@ -16,12 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
-#ifndef TVM_RUNTIME_VM_NDARRAY_CACHE_SUPPORT_H_
-#define TVM_RUNTIME_VM_NDARRAY_CACHE_SUPPORT_H_
+#ifndef TVM_RUNTIME_VM_TENSOR_CACHE_SUPPORT_H_
+#define TVM_RUNTIME_VM_TENSOR_CACHE_SUPPORT_H_
#include <tvm/ffi/container/array.h>
#include <tvm/ffi/function.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <string>
#include <unordered_map>
@@ -32,10 +32,10 @@ namespace runtime {
namespace vm {
/*!
- * \brief Metadata for NDArray cache, which by default, is named as "ndarray-cache.json".
+ * \brief Metadata for Tensor cache, which by default, is named as "tensor-cache.json".
*/
-struct NDArrayCacheMetadata {
- /*! \brief Each shard of NDArray cache, which by default, is named as "params_shard_x.bin". */
+struct TensorCacheMetadata {
+ /*! \brief Each shard of Tensor cache, which by default, is named as "params_shard_x.bin". */
struct FileRecord {
/*! \brief Metadata of each parameter */
struct ParamRecord {
@@ -46,8 +46,8 @@ struct NDArrayCacheMetadata {
* \param staging_buffer The buffer to be used to avoid extra OpenCL copies. Pass in a nullptr
* in other cases
*/
- TVM_DLL NDArray Load(Device device, const std::string* raw_data,
- Optional<NDArray>* staging_buffer = nullptr) const;
+ TVM_DLL Tensor Load(Device device, const std::string* raw_data,
+ Optional<Tensor>* staging_buffer = nullptr) const;
/*! \brief Name of the parameter */
std::string name;
@@ -64,10 +64,10 @@ struct NDArrayCacheMetadata {
};
/*! \brief Load a FileRecord into memory */
- TVM_DLL Array<NDArray> Load(Device device, //
- const std::string& path_prefix, //
- std::string* raw_data_buffer, //
- Optional<NDArray>* staging_buffer = nullptr) const;
+ TVM_DLL Array<Tensor> Load(Device device, //
+ const std::string& path_prefix, //
+ std::string* raw_data_buffer, //
+ Optional<Tensor>* staging_buffer = nullptr) const;
/*! \brief Relative path to the bin file */
std::string data_path;
@@ -78,19 +78,19 @@ struct NDArrayCacheMetadata {
/*! \brief The parameters in the file */
std::vector<ParamRecord> records;
};
- /*! \brief The files in the NDArray cache */
+ /*! \brief The files in the Tensor cache */
std::vector<FileRecord> records;
- /*! \brief The path to the `ndarray-cache.json` file */
+ /*! \brief The path to the `tensor-cache.json` file */
std::string path;
/*! \brief Load the metadata from a specific directory */
- TVM_DLL static NDArrayCacheMetadata Load(const std::string& path);
+ TVM_DLL static TensorCacheMetadata Load(const std::string& path);
/*! \brief Load the metadata from a given JSON string */
- static NDArrayCacheMetadata LoadFromStr(const std::string& json_str, const std::string& path);
+ static TensorCacheMetadata LoadFromStr(const std::string& json_str, const std::string& path);
};
} // namespace vm
} // namespace runtime
} // namespace tvm
-#endif // TVM_RUNTIME_VM_NDARRAY_CACHE_SUPPORT_H_
+#endif // TVM_RUNTIME_VM_TENSOR_CACHE_SUPPORT_H_
diff --git a/include/tvm/script/ir_builder/tir/frame.h b/include/tvm/script/ir_builder/tir/frame.h
index 1e205edc43..52173a8d8a 100644
--- a/include/tvm/script/ir_builder/tir/frame.h
+++ b/include/tvm/script/ir_builder/tir/frame.h
@@ -510,7 +510,7 @@ class AllocateConstFrameNode : public TIRFrameNode {
/*! \brief The extents of the allocate. */
Array<PrimExpr> extents;
/*! \brief The data associated with the constant. */
- tvm::runtime::NDArray data;
+ tvm::runtime::Tensor data;
/*! \brief The buffer var */
tvm::tir::Var buffer_var;
/*! \brief Additional annotations about the allocation. */
diff --git a/include/tvm/script/ir_builder/tir/ir.h b/include/tvm/script/ir_builder/tir/ir.h
index 30b5bb3382..6894bfa1fb 100644
--- a/include/tvm/script/ir_builder/tir/ir.h
+++ b/include/tvm/script/ir_builder/tir/ir.h
@@ -28,7 +28,7 @@ namespace script {
namespace ir_builder {
namespace tir {
-using tvm::runtime::NDArray;
+using tvm::runtime::Tensor;
using tvm::tir::Buffer;
using tvm::tir::Var;
@@ -323,7 +323,7 @@ AllocateFrame Allocate(Array<PrimExpr> extents, DataType dtype, String storage_s
* \param annotations Additional annotation hints.
* \return The created AllocateConstFrame.
*/
-AllocateConstFrame AllocateConst(NDArray data, DataType dtype, Array<PrimExpr> extents,
+AllocateConstFrame AllocateConst(Tensor data, DataType dtype, Array<PrimExpr> extents,
Optional<Map<String, Any>> annotations = std::nullopt);
/*!
diff --git a/include/tvm/tir/builtin.h b/include/tvm/tir/builtin.h
index d3573c925d..a48a8909c4 100644
--- a/include/tvm/tir/builtin.h
+++ b/include/tvm/tir/builtin.h
@@ -337,7 +337,7 @@ TVM_DLL const Op& tvm_stack_alloca();
TVM_DLL const Op& tvm_stack_make_shape();
/*!
- * \brief Allocate a NDArray(DLTensor) on stack, return the handle.
+ * \brief Allocate a Tensor(DLTensor) on stack, return the handle.
*
* Type tvm_stack_make_array(Expr data,
* Expr shape,
diff --git a/include/tvm/tir/function.h b/include/tvm/tir/function.h
index 6ea50e9ae0..21a97f986d 100644
--- a/include/tvm/tir/function.h
+++ b/include/tvm/tir/function.h
@@ -27,7 +27,7 @@
#include <tvm/ffi/container/map.h>
#include <tvm/ffi/container/variant.h>
#include <tvm/ir/function.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <tvm/tir/buffer.h>
#include <tvm/tir/expr.h>
#include <tvm/tir/stmt.h>
diff --git a/include/tvm/tir/index_map.h b/include/tvm/tir/index_map.h
index 518d7602f5..7c8c9c30c7 100644
--- a/include/tvm/tir/index_map.h
+++ b/include/tvm/tir/index_map.h
@@ -135,13 +135,13 @@ class IndexMapNode : public Object {
*/
Array<PrimExpr> MapShape(const Array<PrimExpr>& shape, arith::Analyzer* analyzer) const;
- /* \brief Map an NDArray according to this index map
+ /* \brief Map an Tensor according to this index map
*
- * \param arr_src The NDArray whose layout is transformed by this index map.
+ * \param arr_src The Tensor whose layout is transformed by this index map.
*
- * \returns The transformed NDArray.
+ * \returns The transformed Tensor.
*/
- runtime::NDArray MapNDArray(runtime::NDArray arr_src) const;
+ runtime::Tensor MapTensor(runtime::Tensor arr_src) const;
/*!
* \brief Convert to string representation in Python.
diff --git a/include/tvm/tir/stmt.h b/include/tvm/tir/stmt.h
index bbdb7c272e..b8c7ea594a 100644
--- a/include/tvm/tir/stmt.h
+++ b/include/tvm/tir/stmt.h
@@ -363,10 +363,10 @@ class AllocateConstNode : public StmtNode {
Var buffer_var;
/*! \brief The optional data associated to the constant.
*/
- Optional<runtime::NDArray> data;
+ Optional<runtime::Tensor> data;
/*!
* \brief If the PrimFunc containing the Stmt is added to IRModule, this is an optional index
- * to indicate the index within "constants" attribute, that is a Array<NDArray> of IRModule.
+ * to indicate the index within "constants" attribute, that is a Array<Tensor> of IRModule.
*/
Optional<Integer> irmod_storage_idx;
/*! \brief The type of the buffer. */
diff --git a/include/tvm/tir/transform.h b/include/tvm/tir/transform.h
index eb64d87f95..bd6a5d5372 100644
--- a/include/tvm/tir/transform.h
+++ b/include/tvm/tir/transform.h
@@ -676,7 +676,7 @@ TVM_DLL Pass UnifiedStaticMemoryPlanner();
*/
TVM_DLL Pass InjectSoftwarePipeline();
-TVM_DLL Pass BindParams(const Array<runtime::NDArray>& constants);
+TVM_DLL Pass BindParams(const Array<runtime::Tensor>& constants);
/*!
* \brief Pass to collect tir non-scalar constants into module's 'Constants' attribute.
@@ -729,17 +729,17 @@ TVM_DLL Pass InjectPTXLDG32(bool enable_ptx_ldg32 = true);
/*!
* \brief Remove the weight layout rewrite block
- * \param skip_ndarray_rewrite If True, exact rewrite of NDArray, according to the given index map,
- * will be skipped. Only the shape of the NDArray is transformed correctly, and the content of
+ * \param skip_tensor_rewrite If True, exact rewrite of Tensor, according to the given index map,
+ * will be skipped. Only the shape of the Tensor is transformed correctly, and the content of
* the destination array will be filled with random values.
*
- * When this pass is called many times during MetaSchedule tuning, the raw data of NDArray,
- * before and after rewrite, does not matter. Since NDArray layout rewrite, using IndexMap's
- * MapNDArray, is currently slow, skipping the exact rewrite is sometimes necessary.
+ * When this pass is called many times during MetaSchedule tuning, the raw data of Tensor,
+ * before and after rewrite, does not matter. Since Tensor layout rewrite, using IndexMap's
+ * MapTensor, is currently slow, skipping the exact rewrite is sometimes necessary.
*
* \return The pass.
*/
-TVM_DLL Pass RemoveWeightLayoutRewriteBlock(bool skip_ndarray_rewrite = false);
+TVM_DLL Pass RemoveWeightLayoutRewriteBlock(bool skip_tensor_rewrite = false);
/*!
* \brief Add the explicit local stage for the shared memory access on GPU.
diff --git a/include/tvm/topi/transform.h b/include/tvm/topi/transform.h
index df637f6f58..71b1bd3b8d 100644
--- a/include/tvm/topi/transform.h
+++ b/include/tvm/topi/transform.h
@@ -706,8 +706,8 @@ inline PrimExpr GetLength(PrimExpr begin, PrimExpr end, PrimExpr stride, PrimExp
*
* \return A Tensor whose op member is the dynamic_strided_slice operation
*/
-inline Tensor dynamic_strided_slice_with_axes(
- const Tensor& x, const Array<PrimExpr>& begin, const Array<PrimExpr>& end,
+inline te::Tensor dynamic_strided_slice_with_axes(
+ const te::Tensor& x, const Array<PrimExpr>& begin, const Array<PrimExpr>& end,
const Array<PrimExpr>& strides, const Array<Integer>& axes, bool assume_inbound = true,
std::string name = "T_dynamic_strided_slice_with_axes", std::string tag = kInjective) {
const size_t src_tensor_dim = x->shape.size();
@@ -1967,13 +1967,13 @@ inline Tensor shape(const Tensor& src, DataType dtype, const std::string name =
* \param tag output tensor tag.
* \return Tensor of input shape.
*/
-inline Tensor ndarray_size(const Tensor& src, const DataType& dtype,
- const std::string& name = "ndarray_size",
- const std::string& tag = kInjective) {
+inline te::Tensor tensor_size(const te::Tensor& src, const DataType& dtype,
+ const std::string& name = "tensor_size",
+ const std::string& tag = kInjective) {
int ndim = static_cast<int>(src->shape.size());
- Array<PrimExpr> out_ndarray_size = {};
+ Array<PrimExpr> out_tensor_size = {};
return compute(
- out_ndarray_size,
+ out_tensor_size,
[&](const Array<Var>& indices) {
PrimExpr ret = 1;
for (int i = 0; i < ndim; ++i) {
diff --git a/jvm/README.md b/jvm/README.md
index 71c737a4d0..355a17a7b2 100644
--- a/jvm/README.md
+++ b/jvm/README.md
@@ -19,7 +19,7 @@
This folder contains the Java interface for TVM runtime. It brings TVM runtime to Java virtual machine.
-- It enables you to construct NDArray from Java native array and vice versa.
+- It enables you to construct Tensor from Java native array and vice versa.
- You can register and convert Java native functions to TVM functions.
- It enables you to load shared libraries created by Python and C++.
- It provides a simple interface for RPC server and client.
@@ -95,7 +95,7 @@ The following code snippet demonstrate how to load generated shared library (add
```java
import org.apache.tvm.Module;
-import org.apache.tvm.NDArray;
+import org.apache.tvm.Tensor;
import org.apache.tvm.Device;
import java.io.File;
@@ -109,9 +109,9 @@ public class LoadAddFunc {
Device dev = Device.cpu();
long[] shape = new long[]{2};
- NDArray arr = NDArray.empty(shape, dev);
+ Tensor arr = Tensor.empty(shape, dev);
arr.copyFrom(new float[]{3f, 4f});
- NDArray res = NDArray.empty(shape, dev);
+ Tensor res = Tensor.empty(shape, dev);
fadd.entryFunc().pushArg(arr).pushArg(arr).pushArg(res).invoke();
System.out.println(Arrays.toString(res.asFloatArray()));
diff --git a/jvm/core/src/main/java/org/apache/tvm/Function.java b/jvm/core/src/main/java/org/apache/tvm/Function.java
index ee6b8e8cf5..29e105dee9 100644
--- a/jvm/core/src/main/java/org/apache/tvm/Function.java
+++ b/jvm/core/src/main/java/org/apache/tvm/Function.java
@@ -138,12 +138,12 @@ public class Function extends TVMObject {
/**
* Push argument to the function.
- * @param arg NDArray.
+ * @param arg Tensor.
* @return this
*/
- public Function pushArg(NDArrayBase arg) {
- if (arg instanceof NDArray) {
- Base._LIB.tvmFFIFunctionPushArgHandle(((NDArray) arg).handle, TypeIndex.kTVMFFINDArray);
+ public Function pushArg(TensorBase arg) {
+ if (arg instanceof Tensor) {
+ Base._LIB.tvmFFIFunctionPushArgHandle(((Tensor) arg).handle, TypeIndex.kTVMFFITensor);
} else {
Base._LIB.tvmFFIFunctionPushArgHandle(arg.dltensorHandle, TypeIndex.kTVMFFIDLTensorPtr);
}
@@ -192,7 +192,7 @@ public class Function extends TVMObject {
/**
* Invoke function with arguments.
- * @param args Can be Integer, Long, Float, Double, String, NDArray.
+ * @param args Can be Integer, Long, Float, Double, String, Tensor.
* @return the result.
*/
public TVMValue call(Object... args) {
@@ -203,10 +203,10 @@ public class Function extends TVMObject {
}
private static void pushArgToStack(Object arg) {
- if (arg instanceof NDArrayBase) {
- NDArrayBase nd = (NDArrayBase) arg;
- if (nd instanceof NDArray) {
- Base._LIB.tvmFFIFunctionPushArgHandle(((NDArray) nd).handle, TypeIndex.kTVMFFINDArray);
+ if (arg instanceof TensorBase) {
+ TensorBase nd = (TensorBase) arg;
+ if (nd instanceof Tensor) {
+ Base._LIB.tvmFFIFunctionPushArgHandle(((Tensor) nd).handle, TypeIndex.kTVMFFITensor);
} else {
Base._LIB.tvmFFIFunctionPushArgHandle(nd.dltensorHandle, TypeIndex.kTVMFFIDLTensorPtr);
}
diff --git a/jvm/core/src/main/java/org/apache/tvm/LibInfo.java b/jvm/core/src/main/java/org/apache/tvm/LibInfo.java
index f471883ca5..a1e15a873a 100644
--- a/jvm/core/src/main/java/org/apache/tvm/LibInfo.java
+++ b/jvm/core/src/main/java/org/apache/tvm/LibInfo.java
@@ -52,7 +52,7 @@ class LibInfo {
native int tvmFFIFunctionCreateFromCallback(Function.Callback function, Base.RefLong handle);
- // NDArray
+ // Tensor
native int tvmFFIDLTensorGetShape(long handle, List<Long> shape);
native int tvmFFIDLTensorCopyFromTo(long from, long to);
@@ -67,7 +67,7 @@ class LibInfo {
// Device
native int tvmSynchronize(int deviceType, int deviceId);
- native int tvmNDArrayEmpty(long[] shape, int dtypeCode, int dtypeBits,
+ native int tvmTensorEmpty(long[] shape, int dtypeCode, int dtypeBits,
int dtypeLanes, int deviceType, int deviceId,
Base.RefLong handle);
}
diff --git a/jvm/core/src/main/java/org/apache/tvm/TVMType.java b/jvm/core/src/main/java/org/apache/tvm/TVMType.java
index 1c2719eeca..658fdaedc1 100644
--- a/jvm/core/src/main/java/org/apache/tvm/TVMType.java
+++ b/jvm/core/src/main/java/org/apache/tvm/TVMType.java
@@ -31,7 +31,7 @@ public class TVMType {
/**
* TVMType constructor.
* @param typeStr type name, e.g., "float32", "float64", "uint8", etc.
- * @param lanes NDArray lanes.
+ * @param lanes Tensor lanes.
*/
public TVMType(String typeStr, int lanes) {
this.lanes = lanes;
diff --git a/jvm/core/src/main/java/org/apache/tvm/TVMValue.java b/jvm/core/src/main/java/org/apache/tvm/TVMValue.java
index 45aef808f4..532490a913 100644
--- a/jvm/core/src/main/java/org/apache/tvm/TVMValue.java
+++ b/jvm/core/src/main/java/org/apache/tvm/TVMValue.java
@@ -45,7 +45,7 @@ public class TVMValue {
throw new UnsupportedOperationException();
}
- public NDArrayBase asNDArray() {
+ public TensorBase asTensor() {
throw new UnsupportedOperationException();
}
diff --git a/jvm/core/src/main/java/org/apache/tvm/NDArray.java b/jvm/core/src/main/java/org/apache/tvm/Tensor.java
similarity index 90%
rename from jvm/core/src/main/java/org/apache/tvm/NDArray.java
rename to jvm/core/src/main/java/org/apache/tvm/Tensor.java
index 6b151d7bf9..7b44049f93 100644
--- a/jvm/core/src/main/java/org/apache/tvm/NDArray.java
+++ b/jvm/core/src/main/java/org/apache/tvm/Tensor.java
@@ -23,13 +23,13 @@ import java.util.ArrayList;
import java.util.List;
/**
- * Lightweight NDArray class of TVM runtime.
+ * Lightweight Tensor class of TVM runtime.
*/
-public class NDArray extends NDArrayBase {
+public class Tensor extends TensorBase {
private final TVMType dtype;
private final Device device;
- NDArray(long handle, boolean isView, TVMType dtype, Device dev) {
+ Tensor(long handle, boolean isView, TVMType dtype, Device dev) {
super(handle, isView);
this.dtype = dtype;
this.device = dev;
@@ -37,7 +37,7 @@ public class NDArray extends NDArrayBase {
/**
* Copy from a native array.
- * The NDArray type must by float64
+ * The Tensor type must by float64
* @param sourceArray the source data
*/
public void copyFrom(double[] sourceArray) {
@@ -54,7 +54,7 @@ public class NDArray extends NDArrayBase {
/**
* Copy from a native array.
- * The NDArray type must by float32
+ * The Tensor type must by float32
* @param sourceArray the source data
*/
public void copyFrom(float[] sourceArray) {
@@ -71,7 +71,7 @@ public class NDArray extends NDArrayBase {
/**
* Copy from a native array.
- * The NDArray type must by int64
+ * The Tensor type must by int64
* @param sourceArray the source data
*/
public void copyFrom(long[] sourceArray) {
@@ -88,7 +88,7 @@ public class NDArray extends NDArrayBase {
/**
* Copy from a native array.
- * The NDArray type must by float32
+ * The Tensor type must by float32
* @param sourceArray the source data
*/
public void copyFrom(int[] sourceArray) {
@@ -105,7 +105,7 @@ public class NDArray extends NDArrayBase {
/**
* Copy from a native array.
- * The NDArray type must by int16
+ * The Tensor type must by int16
* @param sourceArray the source data
*/
public void copyFrom(short[] sourceArray) {
@@ -122,7 +122,7 @@ public class NDArray extends NDArrayBase {
/**
* Copy from a native array.
- * The NDArray type must by int8
+ * The Tensor type must by int8
* @param sourceArray the source data
*/
public void copyFrom(byte[] sourceArray) {
@@ -135,7 +135,7 @@ public class NDArray extends NDArrayBase {
/**
* Copy from a native array.
- * The NDArray type must by uint16
+ * The Tensor type must by uint16
* @param sourceArray the source data
*/
public void copyFrom(char[] sourceArray) {
@@ -167,8 +167,8 @@ public class NDArray extends NDArrayBase {
}
/**
- * Get shape of current NDArray.
- * @return an array representing shape of current ndarray
+ * Get shape of current Tensor.
+ * @return an array representing shape of current tensor
*/
public long[] shape() {
List<Long> data = new ArrayList<Long>();
@@ -181,8 +181,8 @@ public class NDArray extends NDArrayBase {
}
/**
- * Get total size of current NDArray.
- * @return size of current NDArray.
+ * Get total size of current Tensor.
+ * @return size of current Tensor.
*/
public long size() {
long product = 1L;
@@ -195,7 +195,7 @@ public class NDArray extends NDArrayBase {
/**
* Return a copied flat java array of current array (row-major).
- * The NDArray dtype must be float64
+ * The Tensor dtype must be float64
* @return A copy of array content.
*/
public double[] asDoubleArray() {
@@ -213,7 +213,7 @@ public class NDArray extends NDArrayBase {
/**
* Return a copied flat java array of current array (row-major).
- * The NDArray dtype must be float32
+ * The Tensor dtype must be float32
* @return A copy of array content.
*/
public float[] asFloatArray() {
@@ -231,7 +231,7 @@ public class NDArray extends NDArrayBase {
/**
* Return a copied flat java array of current array (row-major).
- * The NDArray dtype must be int64
+ * The Tensor dtype must be int64
* @return A copy of array content.
*/
public long[] asLongArray() {
@@ -249,7 +249,7 @@ public class NDArray extends NDArrayBase {
/**
* Return a copied flat java array of current array (row-major).
- * The NDArray dtype must be int32
+ * The Tensor dtype must be int32
* @return A copy of array content.
*/
public int[] asIntArray() {
@@ -267,7 +267,7 @@ public class NDArray extends NDArrayBase {
/**
* Return a copied flat java array of current array (row-major).
- * The NDArray dtype must be int16
+ * The Tensor dtype must be int16
* @return A copy of array content.
*/
public short[] asShortArray() {
@@ -285,7 +285,7 @@ public class NDArray extends NDArrayBase {
/**
* Return a copied flat java array of current array (row-major).
- * The NDArray dtype must be uint16
+ * The Tensor dtype must be uint16
* @return A copy of array content.
*/
public char[] asCharArray() {
@@ -303,7 +303,7 @@ public class NDArray extends NDArrayBase {
/**
* Return a copied flat java array of current array (row-major).
- * The NDArray dtype must be int8
+ * The Tensor dtype must be int8
* @return A copy of array content.
*/
public byte[] asByteArray() {
@@ -319,7 +319,7 @@ public class NDArray extends NDArrayBase {
* @return A copy of array content.
*/
public byte[] internal() {
- NDArray tmp = NDArray.empty(shape(), dtype);
+ Tensor tmp = Tensor.empty(shape(), dtype);
copyTo(tmp);
int arrLength = dtype.numOfBytes * (int) size();
@@ -359,12 +359,12 @@ public class NDArray extends NDArrayBase {
* @param dev The device of the array.
* @return The array tvm supported.
*/
- public static NDArray empty(long[] shape, TVMType dtype, Device dev) {
+ public static Tensor empty(long[] shape, TVMType dtype, Device dev) {
Base.RefLong refHandle = new Base.RefLong();
- Base.checkCall(Base._LIB.tvmNDArrayEmpty(
+ Base.checkCall(Base._LIB.tvmTensorEmpty(
shape, dtype.typeCode, dtype.bits,
dtype.lanes, dev.deviceType, dev.deviceId, refHandle));
- return new NDArray(refHandle.value, false, dtype, dev);
+ return new Tensor(refHandle.value, false, dtype, dev);
}
/**
@@ -373,7 +373,7 @@ public class NDArray extends NDArrayBase {
* @param dtype The data type of the array.
* @return The array tvm supported.
*/
- public static NDArray empty(long[] shape, TVMType dtype) {
+ public static Tensor empty(long[] shape, TVMType dtype) {
return empty(shape, dtype, Device.cpu(0));
}
@@ -382,7 +382,7 @@ public class NDArray extends NDArrayBase {
* @param shape The shape of the array.
* @return The array tvm supported.
*/
- public static NDArray empty(long[] shape) {
+ public static Tensor empty(long[] shape) {
return empty(shape, new TVMType("float32", 1), Device.cpu(0));
}
@@ -392,7 +392,7 @@ public class NDArray extends NDArrayBase {
* @param dev The device of the array.
* @return The array tvm supported.
*/
- public static NDArray empty(long[] shape, Device dev) {
+ public static Tensor empty(long[] shape, Device dev) {
return empty(shape, new TVMType("float32", 1), dev);
}
diff --git a/jvm/core/src/main/java/org/apache/tvm/NDArrayBase.java b/jvm/core/src/main/java/org/apache/tvm/TensorBase.java
similarity index 86%
rename from jvm/core/src/main/java/org/apache/tvm/NDArrayBase.java
rename to jvm/core/src/main/java/org/apache/tvm/TensorBase.java
index 534dcb38d4..b150d65807 100644
--- a/jvm/core/src/main/java/org/apache/tvm/NDArrayBase.java
+++ b/jvm/core/src/main/java/org/apache/tvm/TensorBase.java
@@ -18,26 +18,26 @@
package org.apache.tvm;
/**
- * Base class of NDArray. To handle callback array.
+ * Base class of Tensor. To handle callback array.
* Only deep-copy supported.
*/
-public class NDArrayBase extends TVMValue {
+public class TensorBase extends TVMValue {
protected long handle;
public final boolean isView;
protected final long dltensorHandle;
- NDArrayBase(long handle, boolean isView) {
+ TensorBase(long handle, boolean isView) {
this.dltensorHandle = isView ? handle : handle + 8 * 2;
this.handle = isView ? 0 : handle;
this.isView = isView;
}
- @Override public NDArrayBase asNDArray() {
+ @Override public TensorBase asTensor() {
return this;
}
/**
- * Release the NDArray.
+ * Release the Tensor.
*/
public void release() {
if (this.handle != 0) {
@@ -56,7 +56,7 @@ public class NDArrayBase extends TVMValue {
* @param target The target array to be copied, must have same shape as this array.
* @return target
*/
- public NDArrayBase copyTo(NDArrayBase target) {
+ public TensorBase copyTo(TensorBase target) {
Base.checkCall(Base._LIB.tvmFFIDLTensorCopyFromTo(this.dltensorHandle, target.dltensorHandle));
return target;
}
diff --git a/jvm/core/src/main/java/org/apache/tvm/TypeIndex.java b/jvm/core/src/main/java/org/apache/tvm/TypeIndex.java
index 7689cc58ed..e29bae5182 100644
--- a/jvm/core/src/main/java/org/apache/tvm/TypeIndex.java
+++ b/jvm/core/src/main/java/org/apache/tvm/TypeIndex.java
@@ -37,7 +37,7 @@ public class TypeIndex {
public static final int kTVMFFIError = 67;
public static final int kTVMFFIFunction = 68;
public static final int kTVMFFIShape = 70;
- public static final int kTVMFFINDArray = 71;
+ public static final int kTVMFFITensor = 71;
public static final int kTVMFFIArray = 72;
public static final int kTVMFFIMap = 73;
public static final int kTVMFFIModule = 73;
diff --git a/jvm/core/src/test/java/org/apache/tvm/FunctionTest.java b/jvm/core/src/test/java/org/apache/tvm/FunctionTest.java
index c2a1f78fa4..56e9a21a2b 100644
--- a/jvm/core/src/test/java/org/apache/tvm/FunctionTest.java
+++ b/jvm/core/src/test/java/org/apache/tvm/FunctionTest.java
@@ -78,14 +78,14 @@ public class FunctionTest {
}
@Test
- public void test_sum_ndarray() {
+ public void test_sum_tensor() {
final long[] shape = new long[]{2, 1};
Function func = Function.convertFunc(new Function.Callback() {
@Override public Object invoke(TVMValue... args) {
double sum = 0.0;
for (TVMValue arg : args) {
- NDArray arr = NDArray.empty(shape, new TVMType("float32"));
- arg.asNDArray().copyTo(arr);
+ Tensor arr = Tensor.empty(shape, new TVMType("float32"));
+ arg.asTensor().copyTo(arr);
float[] nativeArr = arr.asFloatArray();
for (int i = 0; i < nativeArr.length; ++i) {
sum += nativeArr[i];
@@ -95,7 +95,7 @@ public class FunctionTest {
return sum;
}
});
- NDArray arr = NDArray.empty(shape, new TVMType("float32"));
+ Tensor arr = Tensor.empty(shape, new TVMType("float32"));
arr.copyFrom(new float[]{2f, 3f});
TVMValue res = func.pushArg(arr).pushArg(arr).invoke();
assertEquals(10.0, res.asDouble(), 1e-3);
diff --git a/jvm/core/src/test/java/org/apache/tvm/ModuleTest.java b/jvm/core/src/test/java/org/apache/tvm/ModuleTest.java
index 888cd18923..5c692eecc3 100644
--- a/jvm/core/src/test/java/org/apache/tvm/ModuleTest.java
+++ b/jvm/core/src/test/java/org/apache/tvm/ModuleTest.java
@@ -42,11 +42,11 @@ public class ModuleTest {
Device dev = new Device("cpu", 0);
long[] shape = new long[]{2};
- NDArray arr = NDArray.empty(shape, dev);
+ Tensor arr = Tensor.empty(shape, dev);
arr.copyFrom(new float[]{3f, 4f});
- NDArray res = NDArray.empty(shape, dev);
+ Tensor res = Tensor.empty(shape, dev);
fadd.entryFunc().pushArg(arr).pushArg(arr).pushArg(res).invoke();
assertArrayEquals(new float[]{6f, 8f}, res.asFloatArray(), 1e-3f);
@@ -74,7 +74,7 @@ public class ModuleTest {
final int dim = 100;
long[] shape = new long[]{dim};
- NDArray arr = NDArray.empty(shape, dev);
+ Tensor arr = Tensor.empty(shape, dev);
float[] data = new float[dim];
float[] dataX2 = new float[dim];
@@ -84,7 +84,7 @@ public class ModuleTest {
}
arr.copyFrom(data);
- NDArray res = NDArray.empty(shape, dev);
+ Tensor res = Tensor.empty(shape, dev);
fadd.entryFunc().pushArg(arr).pushArg(arr).pushArg(res).invoke();
assertArrayEquals(dataX2, res.asFloatArray(), 1e-3f);
diff --git a/jvm/core/src/test/java/org/apache/tvm/NDArrayTest.java b/jvm/core/src/test/java/org/apache/tvm/NDArrayTest.java
deleted file mode 100644
index c4c34360f7..0000000000
--- a/jvm/core/src/test/java/org/apache/tvm/NDArrayTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.tvm;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class NDArrayTest {
- @Test
- public void test_from_float32() {
- NDArray ndarray = NDArray.empty(new long[]{2, 2}, new TVMType("float32"));
- ndarray.copyFrom(new float[]{1, 2, 3, 4});
- assertArrayEquals(new float[]{1f, 2f, 3f, 4f}, ndarray.asFloatArray(), 1e-3f);
- ndarray.release();
- }
-
- @Test
- public void test_from_float64() {
- NDArray ndarray = NDArray.empty(new long[]{2, 2}, new TVMType("float64"));
- ndarray.copyFrom(new double[]{1, 2, 3, 4});
- assertArrayEquals(new double[]{1.0, 2.0, 3.0, 4.0}, ndarray.asDoubleArray(), 1e-3);
- ndarray.release();
- }
-
- @Test
- public void test_from_int8() {
- NDArray ndarray = NDArray.empty(new long[]{2, 2}, new TVMType("int8"));
- ndarray.copyFrom(new byte[]{1, 2, 3, 4});
- assertArrayEquals(new byte[]{1, 2, 3, 4}, ndarray.asByteArray());
- ndarray.release();
- }
-
- @Test
- public void test_from_int16() {
- NDArray ndarray = NDArray.empty(new long[]{2, 2}, new TVMType("int16"));
- ndarray.copyFrom(new short[]{1, 2, 3, 4});
- assertArrayEquals(new short[]{1, 2, 3, 4}, ndarray.asShortArray());
- ndarray.release();
- }
-
- @Test
- public void test_from_int32() {
- NDArray ndarray = NDArray.empty(new long[]{2, 2}, new TVMType("int32"));
- ndarray.copyFrom(new int[]{1, 2, 3, 4});
- assertArrayEquals(new int[]{1, 2, 3, 4}, ndarray.asIntArray());
- ndarray.release();
- }
-
- @Test
- public void test_from_int64() {
- NDArray ndarray = NDArray.empty(new long[]{2, 2}, new TVMType("int64"));
- ndarray.copyFrom(new long[]{1, 2, 3, 4});
- assertArrayEquals(new long[]{1, 2, 3, 4}, ndarray.asLongArray());
- ndarray.release();
- }
-
- @Test
- public void test_from_uint16() {
- NDArray ndarray = NDArray.empty(new long[]{2, 2}, new TVMType("uint16"));
- ndarray.copyFrom(new char[]{65535, 2, 3, 4});
- assertArrayEquals(new char[]{65535, 2, 3, 4}, ndarray.asCharArray());
- ndarray.release();
- }
-}
diff --git a/jvm/core/src/test/java/org/apache/tvm/TensorTest.java b/jvm/core/src/test/java/org/apache/tvm/TensorTest.java
new file mode 100644
index 0000000000..546bf661e4
--- /dev/null
+++ b/jvm/core/src/test/java/org/apache/tvm/TensorTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+package org.apache.tvm;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class TensorTest {
+ @Test
+ public void test_from_float32() {
+ Tensor tensor = Tensor.empty(new long[]{2, 2}, new TVMType("float32"));
+ tensor.copyFrom(new float[]{1, 2, 3, 4});
+ assertArrayEquals(new float[]{1f, 2f, 3f, 4f}, tensor.asFloatArray(), 1e-3f);
+ tensor.release();
+ }
+
+ @Test
+ public void test_from_float64() {
+ Tensor tensor = Tensor.empty(new long[]{2, 2}, new TVMType("float64"));
+ tensor.copyFrom(new double[]{1, 2, 3, 4});
+ assertArrayEquals(new double[]{1.0, 2.0, 3.0, 4.0}, tensor.asDoubleArray(), 1e-3);
+ tensor.release();
+ }
+
+ @Test
+ public void test_from_int8() {
+ Tensor tensor = Tensor.empty(new long[]{2, 2}, new TVMType("int8"));
+ tensor.copyFrom(new byte[]{1, 2, 3, 4});
+ assertArrayEquals(new byte[]{1, 2, 3, 4}, tensor.asByteArray());
+ tensor.release();
+ }
+
+ @Test
+ public void test_from_int16() {
+ Tensor tensor = Tensor.empty(new long[]{2, 2}, new TVMType("int16"));
+ tensor.copyFrom(new short[]{1, 2, 3, 4});
+ assertArrayEquals(new short[]{1, 2, 3, 4}, tensor.asShortArray());
+ tensor.release();
+ }
+
+ @Test
+ public void test_from_int32() {
+ Tensor tensor = Tensor.empty(new long[]{2, 2}, new TVMType("int32"));
+ tensor.copyFrom(new int[]{1, 2, 3, 4});
+ assertArrayEquals(new int[]{1, 2, 3, 4}, tensor.asIntArray());
+ tensor.release();
+ }
+
+ @Test
+ public void test_from_int64() {
+ Tensor tensor = Tensor.empty(new long[]{2, 2}, new TVMType("int64"));
+ tensor.copyFrom(new long[]{1, 2, 3, 4});
+ assertArrayEquals(new long[]{1, 2, 3, 4}, tensor.asLongArray());
+ tensor.release();
+ }
+
+ @Test
+ public void test_from_uint16() {
+ Tensor tensor = Tensor.empty(new long[]{2, 2}, new TVMType("uint16"));
+ tensor.copyFrom(new char[]{65535, 2, 3, 4});
+ assertArrayEquals(new char[]{65535, 2, 3, 4}, tensor.asCharArray());
+ tensor.release();
+ }
+}
diff --git a/jvm/native/src/main/native/jni_helper_func.h b/jvm/native/src/main/native/jni_helper_func.h
index 9b50fb6a49..659c6e4f29 100644
--- a/jvm/native/src/main/native/jni_helper_func.h
+++ b/jvm/native/src/main/native/jni_helper_func.h
@@ -151,8 +151,8 @@ jobject newFunction(JNIEnv* env, jlong value) {
return object;
}
-jobject newNDArray(JNIEnv* env, jlong handle, jboolean isview) {
- jclass cls = env->FindClass("org/apache/tvm/NDArrayBase");
+jobject newTensor(JNIEnv* env, jlong handle, jboolean isview) {
+ jclass cls = env->FindClass("org/apache/tvm/TensorBase");
jmethodID constructor = env->GetMethodID(cls, "<init>", "(JZ)V");
jobject object = env->NewObject(cls, constructor, handle, isview);
env->DeleteLocalRef(cls);
@@ -218,10 +218,10 @@ jobject tvmRetValueToJava(JNIEnv* env, TVMFFIAny value) {
return newFunction(env, reinterpret_cast<jlong>(value.v_obj));
}
case TypeIndex::kTVMFFIDLTensorPtr: {
- return newNDArray(env, reinterpret_cast<jlong>(value.v_ptr), true);
+ return newTensor(env, reinterpret_cast<jlong>(value.v_ptr), true);
}
- case TypeIndex::kTVMFFINDArray: {
- return newNDArray(env, reinterpret_cast<jlong>(value.v_obj), false);
+ case TypeIndex::kTVMFFITensor: {
+ return newTensor(env, reinterpret_cast<jlong>(value.v_obj), false);
}
case TypeIndex::kTVMFFISmallStr: {
TVMFFIByteArray arr = TVMFFISmallBytesGetContentByteArray(&value);
diff --git a/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc b/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc
index b512ec8775..e18d1171df 100644
--- a/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc
+++ b/jvm/native/src/main/native/org_apache_tvm_native_c_api.cc
@@ -26,8 +26,8 @@
#else
#include <dlfcn.h>
#include <tvm/ffi/c_api.h>
-#include <tvm/ffi/container/ndarray.h>
#include <tvm/ffi/container/shape.h>
+#include <tvm/ffi/container/tensor.h>
#include <tvm/ffi/function.h>
#endif
#include <cstring>
@@ -325,7 +325,7 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmFFIObjectFree(JNIEnv* env,
return TVMFFIObjectDecRef(reinterpret_cast<TVMFFIObjectHandle>(jhandle));
}
-// NDArray
+// Tensor
JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmFFIDLTensorGetShape(JNIEnv* env, jobject obj,
jlong jhandle,
@@ -356,7 +356,7 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmFFIDLTensorCopyFromTo(JNIE
jlong jfrom,
jlong jto) {
TVM_FFI_SAFE_CALL_BEGIN();
- static auto fcopy_from_to = tvm::ffi::Function::GetGlobalRequired("runtime.TVMArrayCopyFromTo");
+ static auto fcopy_from_to = tvm::ffi::Function::GetGlobalRequired("runtime.TVMTensorCopyFromTo");
fcopy_from_to(reinterpret_cast<DLTensor*>(jfrom), reinterpret_cast<DLTensor*>(jto));
TVM_FFI_SAFE_CALL_END();
}
@@ -370,7 +370,7 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmFFIDLTensorCopyFromJArray(
DLTensor* to = reinterpret_cast<DLTensor*>(jto);
size_t size = tvm::ffi::GetDataSize(*to);
static auto fcopy_from_bytes =
- tvm::ffi::Function::GetGlobalRequired("runtime.TVMArrayCopyFromBytes");
+ tvm::ffi::Function::GetGlobalRequired("runtime.TVMTensorCopyFromBytes");
fcopy_from_bytes(to, static_cast<void*>(pdata), size);
env->ReleaseByteArrayElements(jarr, pdata, 0);
TVM_FFI_SAFE_CALL_END();
@@ -384,7 +384,8 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmFFIDLTensorCopyToJArray(JN
DLTensor* from = reinterpret_cast<DLTensor*>(jfrom);
size_t size = tvm::ffi::GetDataSize(*from);
jbyte* pdata = env->GetByteArrayElements(jarr, NULL);
- static auto fcopy_to_bytes = tvm::ffi::Function::GetGlobalRequired("runtime.TVMArrayCopyToBytes");
+ static auto fcopy_to_bytes =
+ tvm::ffi::Function::GetGlobalRequired("runtime.TVMTensorCopyToBytes");
fcopy_to_bytes(from, static_cast<void*>(pdata), size);
env->ReleaseByteArrayElements(jarr, static_cast<jbyte*>(pdata),
0); // copy back to java array automatically
@@ -401,7 +402,7 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmSynchronize(JNIEnv* env, j
TVM_FFI_SAFE_CALL_END();
}
-JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmNDArrayEmpty(
+JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmTensorEmpty(
JNIEnv* env, jobject obj, jlongArray jshape, jint jdtypeCode, jint jdtypeBits, jint jdtypeLanes,
jint jdeviceType, jint jdeviceId, jobject jret) {
TVM_FFI_SAFE_CALL_BEGIN();
@@ -414,8 +415,8 @@ JNIEXPORT jint JNICALL Java_org_apache_tvm_LibInfo_tvmNDArrayEmpty(
dtype.lanes = static_cast<int16_t>(jdtypeLanes);
DLDevice device{static_cast<DLDeviceType>(jdeviceType), jdeviceId};
env->ReleaseLongArrayElements(jshape, shapeArray, 0);
- static auto fempty = tvm::ffi::Function::GetGlobalRequired("runtime.TVMArrayAllocWithScope");
- tvm::ffi::NDArray out = fempty(shape, dtype, device, nullptr).cast<tvm::ffi::NDArray>();
+ static auto fempty = tvm::ffi::Function::GetGlobalRequired("runtime.TVMTensorAllocWithScope");
+ tvm::ffi::Tensor out = fempty(shape, dtype, device, nullptr).cast<tvm::ffi::Tensor>();
void* handle = tvm::ffi::details::ObjectUnsafe::MoveObjectRefToTVMFFIObjectPtr(std::move(out));
setLongField(env, jret, reinterpret_cast<jlong>(handle));
TVM_FFI_SAFE_CALL_END();
diff --git a/python/tvm/__init__.py b/python/tvm/__init__.py
index 59d8e05666..c3c8c559c8 100644
--- a/python/tvm/__init__.py
+++ b/python/tvm/__init__.py
@@ -29,9 +29,9 @@ from .base import TVMError, __version__, _RUNTIME_ONLY
# top-level alias
# tvm.runtime
from .runtime.object import Object
-from .runtime.ndarray import device, cpu, cuda, opencl, vulkan, metal
-from .runtime.ndarray import vpi, rocm, ext_dev, hexagon
-from .runtime import ndarray as nd, DataType, DataTypeCode
+from .runtime._tensor import device, cpu, cuda, opencl, vulkan, metal
+from .runtime._tensor import vpi, rocm, ext_dev, hexagon
+from .runtime import DataType, DataTypeCode
# tvm.error
from . import error
diff --git a/python/tvm/contrib/cudnn.py b/python/tvm/contrib/cudnn.py
index 4d39dfd1c6..b69bc4f84e 100644
--- a/python/tvm/contrib/cudnn.py
+++ b/python/tvm/contrib/cudnn.py
@@ -123,7 +123,7 @@ def _get_np_int32_array_handle(arr):
Parameters
----------
- arr: numpy.NDArray
+ arr: numpy.Tensor
source numpy array
Returns
diff --git a/python/tvm/contrib/dlpack.py b/python/tvm/contrib/dlpack.py
index 75b37cef61..e6214ed3a2 100644
--- a/python/tvm/contrib/dlpack.py
+++ b/python/tvm/contrib/dlpack.py
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
"""Wrapping functions to bridge frameworks with DLPack support to TVM"""
-from tvm.runtime import ndarray
+import tvm.runtime
def convert_func(tvm_func, tensor_type, to_dlpack_func):
@@ -37,7 +37,7 @@ def convert_func(tvm_func, tensor_type, to_dlpack_func):
def _wrapper(*args):
args = tuple(
- ndarray.from_dlpack(to_dlpack_func(arg)) if isinstance(arg, tensor_type) else arg
+ tvm.runtime.from_dlpack(to_dlpack_func(arg)) if isinstance(arg, tensor_type) else arg
for arg in args
)
return tvm_func(*args)
diff --git a/python/tvm/contrib/hexagon/generate_take_op.py b/python/tvm/contrib/hexagon/generate_take_op.py
index b70eb451a1..080a7d6a19 100644
--- a/python/tvm/contrib/hexagon/generate_take_op.py
+++ b/python/tvm/contrib/hexagon/generate_take_op.py
@@ -84,7 +84,7 @@ class Tanh2TakeReplace(tvm.relax.PyExprMutator):
take_node = relax.call_tir(
take_func_gv,
relax.expr.Tuple(
- [call_node.args[1][0], relax.expr.Constant(tvm.nd.array(LUT))]
+ [call_node.args[1][0], relax.expr.Constant(tvm.runtime.tensor(LUT))]
),
call_node.struct_info,
)
diff --git a/python/tvm/contrib/hexagon/meta_schedule.py b/python/tvm/contrib/hexagon/meta_schedule.py
index 92298c011d..7c4ccdd5b2 100644
--- a/python/tvm/contrib/hexagon/meta_schedule.py
+++ b/python/tvm/contrib/hexagon/meta_schedule.py
@@ -21,7 +21,7 @@ from typing import Callable, Dict, List, Optional
import tvm
from tvm.ir.module import IRModule
-from tvm.runtime import Module, NDArray
+from tvm.runtime import Module, Tensor
from tvm.target import Target
from tvm.driver import build as tvm_build
from tvm.tir.transform import RemoveWeightLayoutRewriteBlock
@@ -140,10 +140,10 @@ def get_hexagon_local_builder(
return str(binary_path)
def default_build_with_context(
- mod: IRModule, target: Target, _params: Optional[Dict[str, NDArray]]
+ mod: IRModule, target: Target, _params: Optional[Dict[str, Tensor]]
) -> Module:
with pass_context:
- mod = RemoveWeightLayoutRewriteBlock(skip_ndarray_rewrite=True)(mod)
+ mod = RemoveWeightLayoutRewriteBlock(skip_tensor_rewrite=True)(mod)
return tvm_build(mod, target=target)
if pass_context is not None:
diff --git a/python/tvm/contrib/hexagon/tools.py b/python/tvm/contrib/hexagon/tools.py
index a26822bc5f..d84c18aaf7 100644
--- a/python/tvm/contrib/hexagon/tools.py
+++ b/python/tvm/contrib/hexagon/tools.py
@@ -336,7 +336,7 @@ def pack_imports(
"""
path_bin = os.path.join(workspace_dir, "imports.bin")
- pack_to_bin_f_name = "runtime.ModulePackImportsToNDArray"
+ pack_to_bin_f_name = "runtime.ModulePackImportsToTensor"
fpack_to_bin = tvm.get_global_func(pack_to_bin_f_name)
assert fpack_to_bin, f"Expecting {pack_to_bin_f_name} in registry"
@@ -438,7 +438,7 @@ def allocate_hexagon_array(
for dim_i, dim_f in zip(boundaries[:-1], boundaries[1:])
]
- arr = tvm.nd.empty(physical_shape, dtype=dtype, device=dev, mem_scope=mem_scope)
+ arr = tvm.runtime.empty(physical_shape, dtype=dtype, device=dev, mem_scope=mem_scope)
if data is not None:
arr.copyfrom(data.reshape(physical_shape))
diff --git a/python/tvm/contrib/miopen.py b/python/tvm/contrib/miopen.py
index 3aa885f545..6ec2cd78e4 100644
--- a/python/tvm/contrib/miopen.py
+++ b/python/tvm/contrib/miopen.py
@@ -29,7 +29,7 @@ def _get_np_int32_array_handle(arr):
Parameters
----------
- arr: numpy.NDArray
+ arr: numpy.Tensor
source numpy array
Returns
diff --git a/python/tvm/contrib/msc/core/codegen/codegen.py b/python/tvm/contrib/msc/core/codegen/codegen.py
index 96c9c23dfd..b2b97fc8b5 100644
--- a/python/tvm/contrib/msc/core/codegen/codegen.py
+++ b/python/tvm/contrib/msc/core/codegen/codegen.py
@@ -129,7 +129,7 @@ class CodeGen(object):
def to_relax(
graph: MSCGraph,
- weights: Optional[Dict[str, tvm.nd.array]] = None,
+ weights: Optional[Dict[str, tvm.runtime.Tensor]] = None,
codegen_config: Optional[Dict[str, str]] = None,
print_config: Optional[Dict[str, str]] = None,
build_folder: msc_utils.MSCDirectory = None,
diff --git a/python/tvm/contrib/msc/core/frontend/translate.py b/python/tvm/contrib/msc/core/frontend/translate.py
index 687d770c93..24825c99d4 100644
--- a/python/tvm/contrib/msc/core/frontend/translate.py
+++ b/python/tvm/contrib/msc/core/frontend/translate.py
@@ -67,13 +67,13 @@ def normalize_inputs(inputs: List[tuple]) -> List[tuple]:
def normalize_weights(
- t_weights: Dict[MSCTensor, tvm.nd.array], graph: MSCGraph
-) -> Dict[str, tvm.nd.array]:
+ t_weights: Dict[MSCTensor, tvm.runtime.Tensor], graph: MSCGraph
+) -> Dict[str, tvm.runtime.Tensor]:
"""Normalize the weghts.
Parameters
----------
- t_weights: dict of <MSCTensor, tvm.nd.array>
+ t_weights: dict of <MSCTensor, tvm.runtime.tensor>
The weights extracted from IRModule.
graph: tvm.contrib.msc.core.ir.MSCGraph
The translated graph.
@@ -88,7 +88,7 @@ def normalize_weights(
weight_t = graph.find_tensor(ref_t.name)
if weight_t.ndim == 1:
if ref_t.ndim != weight_t.ndim:
- return tvm.nd.array(data.numpy().reshape(weight_t.get_shape()))
+ return tvm.runtime.tensor(data.numpy().reshape(weight_t.get_shape()))
return data
if ref_t.layout and weight_t.layout:
ref_layout, weight_layout = ref_t.layout.name, weight_t.layout.name
@@ -97,7 +97,7 @@ def normalize_weights(
l in ref_layout for l in weight_layout
), "layout mismatch {} compare to {}".format(ref_t, weight_t)
permute = [ref_layout.index(l) for l in weight_layout]
- return tvm.nd.array(data.numpy().transpose(*permute))
+ return tvm.runtime.tensor(data.numpy().transpose(*permute))
return data
weights = {t.name: _to_data(t, d) for t, d in t_weights.items() if graph.has_tensor(t.name)}
@@ -111,11 +111,11 @@ def normalize_weights(
def from_relax(
mod: tvm.IRModule,
- params: Optional[Dict[str, tvm.nd.array]] = None,
+ params: Optional[Dict[str, tvm.runtime.Tensor]] = None,
trans_config: Optional[Dict[str, str]] = None,
build_config: Optional[Dict[str, str]] = None,
opt_config: Optional[Dict[str, str]] = None,
-) -> Tuple[MSCGraph, Dict[str, tvm.nd.array]]:
+) -> Tuple[MSCGraph, Dict[str, tvm.runtime.Tensor]]:
"""Change IRModule to MSCGraph.
Parameters
@@ -195,10 +195,10 @@ class BYOCChecker(PyExprVisitor):
def byoc_partition(
target: str,
mod: tvm.IRModule,
- params: Optional[Dict[str, tvm.nd.array]] = None,
+ params: Optional[Dict[str, tvm.runtime.Tensor]] = None,
trans_config: Optional[Dict[str, str]] = None,
build_config: Optional[Dict[str, str]] = None,
-) -> Tuple[tvm.IRModule, List[Tuple[MSCGraph, Dict[str, tvm.nd.array]]]]:
+) -> Tuple[tvm.IRModule, List[Tuple[MSCGraph, Dict[str, tvm.runtime.Tensor]]]]:
"""Partition module to target sub functions.
Parameters
diff --git a/python/tvm/contrib/msc/core/runtime/hook.py b/python/tvm/contrib/msc/core/runtime/hook.py
index e129d9771b..f87b2d3d06 100644
--- a/python/tvm/contrib/msc/core/runtime/hook.py
+++ b/python/tvm/contrib/msc/core/runtime/hook.py
@@ -136,9 +136,9 @@ class UpdateWeightsHook(RunnerHook):
self,
runner: object,
graphs: List[MSCGraph],
- weights: Dict[str, tvm.nd.array],
+ weights: Dict[str, tvm.runtime.Tensor],
weights_path: str,
- ) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Apply the default funcion
Parameters
@@ -147,7 +147,7 @@ class UpdateWeightsHook(RunnerHook):
The runner context.
graphs: list<MSCGraph>
The translated graphs
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The translated weights.
weights_path: str
The weights path.
@@ -156,7 +156,7 @@ class UpdateWeightsHook(RunnerHook):
-------
graphs: list<MSCGraph>
The updated graphs
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The updated weights.
"""
diff --git a/python/tvm/contrib/msc/core/runtime/runner.py b/python/tvm/contrib/msc/core/runtime/runner.py
index 074c7048c5..bd9cc01d76 100644
--- a/python/tvm/contrib/msc/core/runtime/runner.py
+++ b/python/tvm/contrib/msc/core/runtime/runner.py
@@ -340,7 +340,9 @@ class BaseRunner(object):
title = self.runner_mark("SAVE_CACHE")
self._logger.debug(msc_utils.msg_block(title, {"folder": cache_dir, "info": cache_info}))
- def translate(self, apply_hooks: bool = True) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ def translate(
+ self, apply_hooks: bool = True
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Translate IRModule to MSCgraphs
Parameters
@@ -352,7 +354,7 @@ class BaseRunner(object):
-------
graphs: list<MSCGraph>
The translated graphs
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The translated weights.
"""
@@ -366,7 +368,7 @@ class BaseRunner(object):
graphs, weights = self._apply_hook("after translate", hook, graphs, weights)
return graphs, weights
- def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Translate IRModule to MSCgraphs
Parameters
@@ -378,7 +380,7 @@ class BaseRunner(object):
-------
graphs: list<MSCGraph>
The translated graphs
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The translated weights.
"""
@@ -387,7 +389,7 @@ class BaseRunner(object):
def reset_tools(
self,
graphs: List[MSCGraph] = None,
- weights: List[Dict[str, tvm.nd.array]] = None,
+ weights: List[Dict[str, tvm.runtime.Tensor]] = None,
tools: List[BaseTool] = None,
cache_dir: msc_utils.MSCDirectory = None,
):
@@ -397,7 +399,7 @@ class BaseRunner(object):
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: list<dict<str, tvm.nd.array>>
+ weights: list<dict<str, tvm.runtime.tensor>>
The weights.
tools: list<BaseTool>
The tools.
@@ -408,7 +410,7 @@ class BaseRunner(object):
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: list<dict<str, tvm.nd.array>>
+ weights: list<dict<str, tvm.runtime.tensor>>
The weights.
"""
@@ -444,14 +446,16 @@ class BaseRunner(object):
model = self._apply_hook("after generate", hook, model)
return model
- def _generate_model(self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]) -> Any:
+ def _generate_model(
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Any:
"""Codegen the model according to framework
Parameters
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
@@ -763,7 +767,9 @@ class BaseRunner(object):
return self._model_info["outputs"]
- def get_weights(self, framework: str = None, device: str = None) -> Iterable[tvm.nd.array]:
+ def get_weights(
+ self, framework: str = None, device: str = None
+ ) -> Iterable[tvm.runtime.Tensor]:
"""Get the weights from graphs
Parameters
@@ -775,7 +781,7 @@ class BaseRunner(object):
Returns
-------
- weights: generator<tvm.nd.array>
+ weights: generator<tvm.runtime.tensor>
The generator of weight datas.
"""
@@ -787,23 +793,23 @@ class BaseRunner(object):
data = msc_utils.cast_array(data, framework, device)
yield data
- def get_runtime_params(self) -> Dict[str, tvm.nd.array]:
+ def get_runtime_params(self) -> Dict[str, tvm.runtime.Tensor]:
"""Get the runtime parameters
Returns
-------
- params: dict<str, tvm.nd.array>
+ params: dict<str, tvm.runtime.tensor>
The parameters from runtime.
"""
return self._get_runtime_params()
- def _get_runtime_params(self) -> Dict[str, tvm.nd.array]:
+ def _get_runtime_params(self) -> Dict[str, tvm.runtime.Tensor]:
"""Get the runtime parameters
Returns
-------
- params: dict<str, tvm.nd.array>
+ params: dict<str, tvm.runtime.tensor>
The parameters from runtime.
"""
@@ -1146,7 +1152,7 @@ class BaseRunner(object):
class ModelRunner(BaseRunner):
"""Model runner of MSC"""
- def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Translate IRModule to MSCgraphs
Parameters
@@ -1158,7 +1164,7 @@ class ModelRunner(BaseRunner):
-------
graphs: list<MSCGraph>
The translated graphs
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The translated weights.
"""
@@ -1210,14 +1216,16 @@ class ModelRunner(BaseRunner):
f_graph.write(self._graphs[0].to_json())
return {"main": main_info}
- def _generate_model(self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]) -> Any:
+ def _generate_model(
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Any:
"""Codegen the model according to framework
Parameters
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
@@ -1319,7 +1327,7 @@ class BYOCRunner(BaseRunner):
with open(visual_dir.relpath(self._byoc_graph.name + "_graph.json"), "w") as f_graph:
f_graph.write(self._byoc_graph.to_json())
- def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Translate IRModule to MSCgraphs
Parameters
@@ -1331,7 +1339,7 @@ class BYOCRunner(BaseRunner):
-------
graphs: list<MSCGraph>
The translated graphs
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The translated weights.
"""
@@ -1405,14 +1413,16 @@ class BYOCRunner(BaseRunner):
"byoc_mod": "byoc_module.json",
}
- def _generate_model(self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]) -> Any:
+ def _generate_model(
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Any:
"""Codegen the model according to framework
Parameters
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
diff --git a/python/tvm/contrib/msc/core/tools/distill/distiller.py b/python/tvm/contrib/msc/core/tools/distill/distiller.py
index 55b7947a6e..7812627ebc 100644
--- a/python/tvm/contrib/msc/core/tools/distill/distiller.py
+++ b/python/tvm/contrib/msc/core/tools/distill/distiller.py
@@ -48,22 +48,22 @@ class BaseDistiller(BaseTool):
return super().setup()
def _reset(
- self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]
- ) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Reset the tool
Parameters
----------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
"""
@@ -164,7 +164,7 @@ class BaseDistiller(BaseTool):
The distilled weights.
"""
- weights = {n: tvm.nd.array(msc_utils.cast_array(d)) for n, d in weights.items()}
+ weights = {n: tvm.runtime.tensor(msc_utils.cast_array(d)) for n, d in weights.items()}
weights_path = self._weights_folder.relpath("distill_{}.bin".format(self._current_iter))
with open(weights_path, "wb") as f_params:
f_params.write(tvm.runtime.save_param_dict(weights))
diff --git a/python/tvm/contrib/msc/core/tools/prune/pruner.py b/python/tvm/contrib/msc/core/tools/prune/pruner.py
index 38f855d0eb..95024e1abb 100644
--- a/python/tvm/contrib/msc/core/tools/prune/pruner.py
+++ b/python/tvm/contrib/msc/core/tools/prune/pruner.py
@@ -104,22 +104,22 @@ class BasePruner(WeightTool):
return super()._parse_strategys([_update_stages(s) for s in strategy_list])
def _reset(
- self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]
- ) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Reset the tool
Parameters
----------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
"""
@@ -315,22 +315,22 @@ class BasePruner(WeightTool):
self._plan[w_node.name]["out_indices"] = []
def prune_graphs(
- self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]
- ) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Reset the tool
Parameters
----------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
"""
@@ -375,7 +375,7 @@ class BasePruner(WeightTool):
if w_config["out_indices"]:
data = PruneMethod.prune_axis(data, out_axis, w_config["out_indices"])
pruned_tensors[w_name] = _prune_by_shape(weight, data.shape)
- pruned_weights[w_name] = tvm.nd.array(data)
+ pruned_weights[w_name] = tvm.runtime.tensor(data)
w_node.set_attr(
"pruned_shape",
",".join([str(i) for i in pruned_tensors[w_name].get_shape()]),
diff --git a/python/tvm/contrib/msc/core/tools/tool.py b/python/tvm/contrib/msc/core/tools/tool.py
index 06a16f2bbe..cb860729f7 100644
--- a/python/tvm/contrib/msc/core/tools/tool.py
+++ b/python/tvm/contrib/msc/core/tools/tool.py
@@ -372,16 +372,16 @@ class BaseTool(object):
def reset(
self,
graphs: List[MSCGraph],
- weights: Dict[str, tvm.nd.array],
+ weights: Dict[str, tvm.runtime.Tensor],
cache_dir: msc_utils.MSCDirectory = None,
- ) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Reset the tool with graphs and weights
Parameters
----------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
cache_dir: MSCDirectory
cache path for save/load info.
@@ -390,7 +390,7 @@ class BaseTool(object):
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
"""
@@ -411,22 +411,22 @@ class BaseTool(object):
return self._graphs, self._weights
def _reset(
- self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]
- ) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Reset the tool
Parameters
----------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
"""
@@ -1440,22 +1440,22 @@ class WeightTool(BaseTool):
return super().setup()
def _reset(
- self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]
- ) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Reset the tool
Parameters
----------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
"""
diff --git a/python/tvm/contrib/msc/core/transform/transform.py b/python/tvm/contrib/msc/core/transform/transform.py
index 47ea21266e..19f5b5a032 100644
--- a/python/tvm/contrib/msc/core/transform/transform.py
+++ b/python/tvm/contrib/msc/core/transform/transform.py
@@ -122,7 +122,7 @@ def SetBYOCAttrs(target, entry_name: str = "main") -> tvm.ir.transform.Pass:
def BindNamedParams(
func_name: str,
- params: Dict[str, tvm.runtime.NDArray],
+ params: Dict[str, tvm.runtime.Tensor],
) -> tvm.ir.transform.Pass:
"""Bind params of function of the module to constant tensors with span names.
@@ -130,7 +130,7 @@ def BindNamedParams(
----------
func_name: str
The function name to be bound
- params: dict<str, tvm.nd.array>
+ params: dict<str, tvm.runtime.tensor>
The map from parameter or parameter name to constant
tensors.
diff --git a/python/tvm/contrib/msc/core/utils/info.py b/python/tvm/contrib/msc/core/utils/info.py
index 189dd3ebbb..b4301beeb5 100644
--- a/python/tvm/contrib/msc/core/utils/info.py
+++ b/python/tvm/contrib/msc/core/utils/info.py
@@ -46,7 +46,7 @@ class MSCArray(object):
return MSCFramework.MSC, "list", "cpu"
if isinstance(data, np.ndarray):
return MSCFramework.MSC, "tensor", "cpu"
- if isinstance(data, tvm.runtime.NDArray):
+ if isinstance(data, tvm.runtime.Tensor):
device = tvm.runtime.Device.DEVICE_TYPE_TO_NAME[data.device.device_type]
if data.device.device_id:
device += ":{}".format(data.device.device_id)
@@ -71,7 +71,7 @@ class MSCArray(object):
def abstract(self) -> str:
"""Get abstract describe of the data"""
- data = self._to_ndarray()
+ data = self._to_tensor()
prefix = "[{},{}]".format(";".join([str(s) for s in data.shape]), data.dtype.name)
if data.size < 10:
return "{} {}".format(prefix, ",".join([str(i) for i in data.flatten()]))
@@ -79,7 +79,7 @@ class MSCArray(object):
prefix, data.max(), data.min(), data.sum() / data.size
)
- def _to_ndarray(self) -> np.ndarray:
+ def _to_tensor(self) -> np.ndarray:
"""Cast array like object to np.ndarray
Returns
@@ -120,7 +120,7 @@ class MSCArray(object):
if self._framework == MSCFramework.TORCH:
return self._meta_data.to(self.get_device(device))
if self._framework == MSCFramework.TVM:
- return tvm.nd.array(self._cast_data(), device=self.get_device(device))
+ return tvm.runtime.tensor(self._cast_data(), device=self.get_device(device))
return self._meta_data
def cast(self, framework: str, device: str = "cpu") -> Any:
@@ -144,13 +144,13 @@ class MSCArray(object):
return self._meta_data
if framework == self._framework:
return self._to_device(device)
- data = self._to_ndarray()
+ data = self._to_tensor()
if framework == MSCFramework.TORCH:
import torch # pylint: disable=import-outside-toplevel
return torch.from_numpy(data).to(self.get_device(device, framework))
if framework == MSCFramework.TVM:
- return tvm.nd.array(data, device=self.get_device(device, framework))
+ return tvm.runtime.tensor(data, device=self.get_device(device, framework))
return data
def get_device(self, device: str, framework: str = None) -> Any:
@@ -198,7 +198,7 @@ class MSCArray(object):
Whether the data is array like.
"""
- normal_types = (np.ndarray, tvm.runtime.NDArray, tvm.relax.Var)
+ normal_types = (np.ndarray, tvm.runtime.Tensor, tvm.relax.Var)
if isinstance(data, normal_types):
return True
if isinstance(data, (list, tuple)) and all(isinstance(d, (int, float)) for d in data):
diff --git a/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py b/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py
index f24150efcd..b9728b8f63 100644
--- a/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py
+++ b/python/tvm/contrib/msc/framework/tensorflow/codegen/codegen.py
@@ -28,7 +28,7 @@ from tvm.contrib.msc.framework.tensorflow import _ffi_api
def to_tensorflow(
graph: MSCGraph,
- weights: Optional[Dict[str, tvm.nd.array]] = None,
+ weights: Optional[Dict[str, tvm.runtime.Tensor]] = None,
codegen_config: Optional[Dict[str, str]] = None,
print_config: Optional[Dict[str, str]] = None,
build_folder: msc_utils.MSCDirectory = None,
diff --git a/python/tvm/contrib/msc/framework/tensorflow/frontend/translate.py b/python/tvm/contrib/msc/framework/tensorflow/frontend/translate.py
index 1accaba859..36e4e75491 100644
--- a/python/tvm/contrib/msc/framework/tensorflow/frontend/translate.py
+++ b/python/tvm/contrib/msc/framework/tensorflow/frontend/translate.py
@@ -34,7 +34,7 @@ def from_tensorflow(
build_config: Optional[Dict[str, str]] = None,
opt_config: Optional[Dict[str, str]] = None,
as_msc: bool = True,
-) -> Tuple[Union[MSCGraph, tvm.IRModule], Dict[str, tvm.nd.array]]:
+) -> Tuple[Union[MSCGraph, tvm.IRModule], Dict[str, tvm.runtime.Tensor]]:
"""Change tensorflow GraphDef to MSCGraph.
Parameters
diff --git a/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py b/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py
index 2297b3e825..eeee4635ab 100644
--- a/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/tensorflow/runtime/runner.py
@@ -88,7 +88,7 @@ class TensorflowRunner(ModelRunner):
super().destory()
def _generate_model(
- self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
) -> tf_v1.Graph:
"""Codegen the model according to framework
@@ -96,7 +96,7 @@ class TensorflowRunner(ModelRunner):
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
diff --git a/python/tvm/contrib/msc/framework/tensorrt/codegen/codegen.py b/python/tvm/contrib/msc/framework/tensorrt/codegen/codegen.py
index 4643d49c1e..a3cd722495 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/codegen/codegen.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/codegen/codegen.py
@@ -33,7 +33,7 @@ from .utils import write_weight
def to_sub_tensorrt(
graph: MSCGraph,
- weights: Dict[str, tvm.nd.array],
+ weights: Dict[str, tvm.runtime.Tensor],
codegen_config: Optional[Dict[str, str]] = None,
print_config: Optional[Dict[str, str]] = None,
build_folder: msc_utils.MSCDirectory = None,
@@ -145,7 +145,7 @@ def to_sub_tensorrt(
def to_tensorrt(
mod: tvm.IRModule,
graphs: List[MSCGraph],
- weights: Dict[str, tvm.nd.array],
+ weights: Dict[str, tvm.runtime.Tensor],
codegen_configs: Optional[Union[Dict[str, str], List[Dict[str, str]]]] = None,
print_configs: Optional[Union[Dict[str, str], List[Dict[str, str]]]] = None,
extra_options: Optional[Union[Dict[str, str], List[Dict[str, str]]]] = None,
diff --git a/python/tvm/contrib/msc/framework/tensorrt/frontend/translate.py b/python/tvm/contrib/msc/framework/tensorrt/frontend/translate.py
index 4a02b02728..59095aff45 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/frontend/translate.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/frontend/translate.py
@@ -60,10 +60,10 @@ def transform_for_tensorrt(
def partition_for_tensorrt(
mod: tvm.IRModule,
- params: Optional[Dict[str, tvm.nd.array]] = None,
+ params: Optional[Dict[str, tvm.runtime.Tensor]] = None,
trans_config: Optional[Dict[str, str]] = None,
build_config: Optional[Dict[str, str]] = None,
-) -> Tuple[tvm.IRModule, List[Tuple[MSCGraph, Dict[str, tvm.nd.array]]]]:
+) -> Tuple[tvm.IRModule, List[Tuple[MSCGraph, Dict[str, tvm.runtime.Tensor]]]]:
"""Partition module to tensorrt sub functions.
Parameters
diff --git a/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py b/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py
index 3dd392c7d8..43b9d096bd 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/runtime/runner.py
@@ -79,14 +79,16 @@ class TensorRTRunner(BYOCRunner):
assert quantizer.calibrated, "Failed to calibrate the tenosrrt quantizer"
return super().make_plan(tool_type, data_loader)
- def _generate_model(self, graphs: List[MSCGraph], weights: Dict[str, tvm.nd.array]) -> Any:
+ def _generate_model(
+ self, graphs: List[MSCGraph], weights: Dict[str, tvm.runtime.Tensor]
+ ) -> Any:
"""Codegen the model according to framework
Parameters
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: dict<str, tvm.nd.array>
+ weights: dict<str, tvm.runtime.tensor>
The weights.
Returns
diff --git a/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py b/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
index 88cc55a65e..259085454f 100644
--- a/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
+++ b/python/tvm/contrib/msc/framework/tensorrt/tools/quantize/quantizer.py
@@ -67,22 +67,22 @@ class TensorRTQuantizerFactory(object):
return super().setup()
def _reset(
- self, graphs: List[MSCGraph], weights: List[Dict[str, tvm.nd.array]]
- ) -> Tuple[List[MSCGraph], List[Dict[str, tvm.nd.array]]]:
+ self, graphs: List[MSCGraph], weights: List[Dict[str, tvm.runtime.Tensor]]
+ ) -> Tuple[List[MSCGraph], List[Dict[str, tvm.runtime.Tensor]]]:
"""Reset the tool
Parameters
----------
graphs: list<MSCgraph>
The msc graphs.
- weights: list<dict<str, tvm.nd.array>>
+ weights: list<dict<str, tvm.runtime.tensor>>
The weights
Returns
-------
graphs: list<MSCgraph>
The msc graphs.
- weights: list<dict<str, tvm.nd.array>>
+ weights: list<dict<str, tvm.runtime.tensor>>
The weights
"""
diff --git a/python/tvm/contrib/msc/framework/torch/codegen/codegen.py b/python/tvm/contrib/msc/framework/torch/codegen/codegen.py
index 5ca5de4006..cac575f9e2 100644
--- a/python/tvm/contrib/msc/framework/torch/codegen/codegen.py
+++ b/python/tvm/contrib/msc/framework/torch/codegen/codegen.py
@@ -28,7 +28,7 @@ from tvm.contrib.msc.framework.torch import _ffi_api
def to_torch(
graph: MSCGraph,
- weights: Optional[Dict[str, tvm.nd.array]] = None,
+ weights: Optional[Dict[str, tvm.runtime.Tensor]] = None,
codegen_config: Optional[Dict[str, str]] = None,
print_config: Optional[Dict[str, str]] = None,
build_folder: msc_utils.MSCDirectory = None,
diff --git a/python/tvm/contrib/msc/framework/torch/frontend/translate.py b/python/tvm/contrib/msc/framework/torch/frontend/translate.py
index b110513760..eb6e8b5e56 100644
--- a/python/tvm/contrib/msc/framework/torch/frontend/translate.py
+++ b/python/tvm/contrib/msc/framework/torch/frontend/translate.py
@@ -66,7 +66,7 @@ def from_torch(
build_config: Optional[Dict[str, str]] = None,
as_msc: bool = True,
custom_convert_map: dict = None,
-) -> Tuple[Union[MSCGraph, tvm.IRModule], Dict[str, tvm.nd.array]]:
+) -> Tuple[Union[MSCGraph, tvm.IRModule], Dict[str, tvm.runtime.Tensor]]:
"""Change torch nn.Module to MSCGraph.
Parameters
diff --git a/python/tvm/contrib/msc/framework/torch/runtime/runner.py b/python/tvm/contrib/msc/framework/torch/runtime/runner.py
index a4d37d08f5..de1356f08d 100644
--- a/python/tvm/contrib/msc/framework/torch/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/torch/runtime/runner.py
@@ -37,7 +37,7 @@ from tvm.contrib.msc.framework.torch import tools
class TorchRunner(ModelRunner):
"""Runner of Torch"""
- def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.nd.array]]:
+ def _translate(self, mod: tvm.IRModule) -> Tuple[List[MSCGraph], Dict[str, tvm.runtime.Tensor]]:
"""Translate IRModule to MSCgraphs
Parameters
@@ -49,7 +49,7 @@ class TorchRunner(ModelRunner):
-------
graph_list: list<MSCGraph>
The translated graphs
- weights_list: list<dict<str, tvm.nd.array>>
+ weights_list: list<dict<str, tvm.runtime.tensor>>
The translated weights
"""
graphs, weights = super()._translate(mod)
@@ -107,12 +107,12 @@ class TorchRunner(ModelRunner):
]
return runnable(*torch_inputs)
- def _get_runtime_params(self) -> Dict[str, tvm.nd.array]:
+ def _get_runtime_params(self) -> Dict[str, tvm.runtime.Tensor]:
"""Get the runtime parameters
Returns
-------
- params: dict<str, tvm.nd.array>
+ params: dict<str, tvm.runtime.tensor>
The parameters from runtime.
"""
diff --git a/python/tvm/contrib/msc/framework/tvm/codegen/codegen.py b/python/tvm/contrib/msc/framework/tvm/codegen/codegen.py
index 3c96446404..31c2cc619e 100644
--- a/python/tvm/contrib/msc/framework/tvm/codegen/codegen.py
+++ b/python/tvm/contrib/msc/framework/tvm/codegen/codegen.py
@@ -26,7 +26,7 @@ from tvm.contrib.msc.core import utils as msc_utils
def to_relax(
graph: MSCGraph,
- weights: Optional[Dict[str, tvm.nd.array]] = None,
+ weights: Optional[Dict[str, tvm.runtime.Tensor]] = None,
codegen_config: Optional[Dict[str, str]] = None,
print_config: Optional[Dict[str, str]] = None,
build_folder: msc_utils.MSCDirectory = None,
diff --git a/python/tvm/contrib/msc/framework/tvm/runtime/runner.py b/python/tvm/contrib/msc/framework/tvm/runtime/runner.py
index c6ae512a64..a27200d7b6 100644
--- a/python/tvm/contrib/msc/framework/tvm/runtime/runner.py
+++ b/python/tvm/contrib/msc/framework/tvm/runtime/runner.py
@@ -49,7 +49,7 @@ class WrapRunnable(object):
self._runnable = runnable
self._entry = entry
- def __call__(self, *inputs) -> List[tvm.nd.array]:
+ def __call__(self, *inputs) -> List[tvm.runtime.Tensor]:
execute_step("before_forward", *inputs)
output = self._runnable[self._entry](*inputs)
return execute_step("after_forward", output)
@@ -250,13 +250,13 @@ class TVMRunner(ModelRunner):
with tvm.transform.PassContext(opt_level=3):
relax_exec = tvm.compile(model, target)
runnable = tvm.relax.VirtualMachine(relax_exec, tvm.cuda())
- tvm_inputs = [tvm.nd.array(inputs[i], device=tvm.cuda()) for i in input_names]
+ tvm_inputs = [tvm.runtime.tensor(inputs[i], device=tvm.cuda()) for i in input_names]
else:
target = tvm.target.Target("llvm")
with tvm.transform.PassContext(opt_level=3):
relax_exec = tvm.compile(model, target)
runnable = tvm.relax.VirtualMachine(relax_exec, tvm.cpu())
- tvm_inputs = [tvm.nd.array(inputs[i]) for i in input_names]
+ tvm_inputs = [tvm.runtime.tensor(inputs[i]) for i in input_names]
def _run_once():
return runnable["main"](*tvm_inputs)
@@ -271,7 +271,7 @@ class TVMRunner(ModelRunner):
else:
outputs = _run_once()
avg_time = -1
- if isinstance(outputs, tvm.runtime.NDArray):
+ if isinstance(outputs, tvm.runtime.Tensor):
outputs = [outputs]
assert len(output_names) == len(outputs), "Outputs mismatch, {} with {}".format(
output_names, len(outputs)
diff --git a/python/tvm/contrib/msc/framework/tvm/tools/quantize/method.py b/python/tvm/contrib/msc/framework/tvm/tools/quantize/method.py
index d56193d9f7..cc9e7e8183 100644
--- a/python/tvm/contrib/msc/framework/tvm/tools/quantize/method.py
+++ b/python/tvm/contrib/msc/framework/tvm/tools/quantize/method.py
@@ -81,9 +81,9 @@ class TVMQuantizeMethod(QuantizeMethod):
scale_tensor = scale_tensor.astype(quantizer.find_tensor(name).dtype_name)
zero_point = np.zeros_like(scale_tensor).astype("int8")
scale_span = _ffi_api.SpanCreateWithAttr("name", name_prefix + "_scale")
- scale_tensor = tvm.relax.Constant(tvm.nd.array(scale_tensor), span=scale_span)
+ scale_tensor = tvm.relax.Constant(tvm.runtime.tensor(scale_tensor), span=scale_span)
zp_span = _ffi_api.SpanCreateWithAttr("name", name_prefix + "_zero_point")
- zero_point = tvm.relax.Constant(tvm.nd.array(zero_point), span=zp_span)
+ zero_point = tvm.relax.Constant(tvm.runtime.tensor(zero_point), span=zp_span)
quantizer._save_tensor_cache(name, consumer, "scale_tensor", scale_tensor)
quantizer._save_tensor_cache(name, consumer, "zero_point", zero_point)
return scale_tensor, zero_point
diff --git a/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py b/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py
index 173dc7c3d9..58fbd96c37 100644
--- a/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py
+++ b/python/tvm/contrib/msc/framework/tvm/tools/quantize/quantizer.py
@@ -85,8 +85,8 @@ class TVMQuantizerFactory(object):
return super()._execute_after_build(output + gather_tensors)
def _execute_after_forward(
- self, outputs: List[tvm.runtime.NDArray]
- ) -> Union[tvm.runtime.NDArray, List[tvm.runtime.NDArray]]:
+ self, outputs: List[tvm.runtime.Tensor]
+ ) -> Union[tvm.runtime.Tensor, List[tvm.runtime.Tensor]]:
"""Execute after model forward
Parameters
diff --git a/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py b/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py
index 2bb0de02be..39b8e4034b 100644
--- a/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py
+++ b/python/tvm/contrib/msc/framework/tvm/tools/track/tracker.py
@@ -83,8 +83,8 @@ class TVMTrackerFactory(object):
return super()._execute_after_build(output + track_tensors)
def _execute_after_forward(
- self, outputs: List[tvm.runtime.NDArray]
- ) -> Union[tvm.runtime.NDArray, List[tvm.runtime.NDArray]]:
+ self, outputs: List[tvm.runtime.Tensor]
+ ) -> Union[tvm.runtime.Tensor, List[tvm.runtime.Tensor]]:
"""Execute after model forward
Parameters
diff --git a/python/tvm/contrib/tflite_runtime.py b/python/tvm/contrib/tflite_runtime.py
index 81c43861c4..0769462146 100644
--- a/python/tvm/contrib/tflite_runtime.py
+++ b/python/tvm/contrib/tflite_runtime.py
@@ -86,7 +86,7 @@ class TFLiteModule(object):
value : the input value.
The input key
- params : dict of str to NDArray
+ params : dict of str to Tensor
Additonal arguments
"""
self._set_input(index, value)
@@ -96,7 +96,7 @@ class TFLiteModule(object):
Parameters
----------
- input_dict: dict of str to NDArray
+ input_dict: dict of str to Tensor
List of input values to be feed to
"""
self._invoke()
diff --git a/python/tvm/contrib/tvmjs.py b/python/tvm/contrib/tvmjs.py
index e24b88a3f8..a72eafd2bf 100644
--- a/python/tvm/contrib/tvmjs.py
+++ b/python/tvm/contrib/tvmjs.py
@@ -71,7 +71,7 @@ def _calculate_md5(filename):
return hash_md5.hexdigest()
-class NDArrayCacheShardingManager:
+class TensorCacheShardingManager:
"""Internal helper to shard ndarrays."""
def __init__(
@@ -198,10 +198,10 @@ class NDArrayCacheShardingManager:
return len(self.curr_data)
-def dump_ndarray_cache(
+def dump_tensor_cache(
params: Union[
- Mapping[str, Union[np.ndarray, tvm.runtime.NDArray]],
- Iterator[Tuple[str, Union[np.ndarray, tvm.runtime.NDArray]]],
+ Mapping[str, Union[np.ndarray, tvm.runtime.Tensor]],
+ Iterator[Tuple[str, Union[np.ndarray, tvm.runtime.Tensor]]],
],
cache_dir: str,
encode_format="f32-to-bf16",
@@ -210,13 +210,13 @@ def dump_ndarray_cache(
show_progress: bool = True,
update_if_exists: bool = False,
):
- """Dump parameters to NDArray cache.
+ """Dump parameters to Tensor cache.
Parameters
----------
params: Union[
- Mapping[str, Union[np.ndarray, tvm.runtime.NDArray]],
- Iterator[Tuple[str, Union[np.ndarray, tvm.runtime.NDArray]]],
+ Mapping[str, Union[np.ndarray, tvm.runtime.Tensor]],
+ Iterator[Tuple[str, Union[np.ndarray, tvm.runtime.Tensor]]],
]
The parameter dictionary or generator
@@ -257,7 +257,7 @@ def dump_ndarray_cache(
print("Start storing to cache %s" % cache_dir)
shard_cap_nbytes = shard_cap_mb * (1 << 20)
- nd_cache_json = os.path.join(cache_dir, "ndarray-cache.json")
+ nd_cache_json = os.path.join(cache_dir, "tensor-cache.json")
if update_if_exists and os.path.exists(nd_cache_json):
with open(nd_cache_json, "r") as infile:
old_data = json.load(infile)
@@ -265,7 +265,7 @@ def dump_ndarray_cache(
meta_data = old_data["metadata"]
records = old_data["records"]
- shard_manager = NDArrayCacheShardingManager(
+ shard_manager = TensorCacheShardingManager(
cache_dir, "params_shard", shard_cap_nbytes, initial_shard_records=records
)
@@ -277,7 +277,7 @@ def dump_ndarray_cache(
v = v.numpy()
# prefer to preserve original dtype, especially if the format was bfloat16
- dtype = origin_v.dtype if isinstance(origin_v, tvm.nd.NDArray) else v.dtype
+ dtype = origin_v.dtype if isinstance(origin_v, tvm.runtime.Tensor) else v.dtype
if dtype in DataType.NUMPY_DTYPE_TO_STR:
dtype = DataType.NUMPY_DTYPE_TO_STR[dtype]
@@ -325,15 +325,15 @@ def dump_ndarray_cache(
if item["dtype"] == "float32":
item["format"] = "raw"
item["dtype"] = "bfloat16"
- b16_nd_cache_json = os.path.join(cache_dir, "ndarray-cache-b16.json")
+ b16_nd_cache_json = os.path.join(cache_dir, "tensor-cache-b16.json")
# also dump a file that contains bf16
with open(b16_nd_cache_json, "w") as outfile:
json.dump({"metadata": meta_data, "records": records}, outfile, indent=4)
print("Also saved a bf16 record to %s" % b16_nd_cache_json)
-def load_ndarray_cache(cachepath: str, device: tvm.runtime.Device):
- """Load the ndarray cache from the directory or json.
+def load_tensor_cache(cachepath: str, device: tvm.runtime.Device):
+ """Load the tensor cache from the directory or json.
Parameters
@@ -345,7 +345,7 @@ def load_ndarray_cache(cachepath: str, device: tvm.runtime.Device):
The device we would like to load the data from.
"""
if not cachepath.endswith(".json"):
- cachepath = os.path.join(cachepath, "ndarray-cache.json")
+ cachepath = os.path.join(cachepath, "tensor-cache.json")
cachedir = os.path.dirname(cachepath)
json_info = json.loads(open(cachepath, "r").read())
@@ -366,7 +366,7 @@ def load_ndarray_cache(cachepath: str, device: tvm.runtime.Device):
offset = rec["byteOffset"]
nbytes = rec["nbytes"]
- arr = tvm.nd.empty(shape, dtype, device=device)
+ arr = tvm.runtime.empty(shape, dtype, device=device)
assert offset + nbytes <= len(raw_data)
buffer_source = raw_data[offset : offset + nbytes]
if dtype == "float8_e4m3fn":
diff --git a/python/tvm/dlight/benchmark/bench.py b/python/tvm/dlight/benchmark/bench.py
index 7ab50d4125..ea9f4299b2 100644
--- a/python/tvm/dlight/benchmark/bench.py
+++ b/python/tvm/dlight/benchmark/bench.py
@@ -106,7 +106,7 @@ def benchmark(
input_infos = populuate_input_shape(args, dym_var_sample)
# generate input tensors, including scalars
# scalars are appended to the end of the list due to parsing order
- input_tensors: List[Union[tvm.nd.NDArray, int]] = []
+ input_tensors: List[Union[tvm.runtime.Tensor, int]] = []
scalar_input_tensors: List[int] = []
for input_shape, input_dtype in input_infos:
if input_dtype == "scalar":
@@ -116,7 +116,7 @@ def benchmark(
else:
# normal case like [1, n, 128], generate random tensor
input_tensors.append(
- tvm.nd.array(generate_input_data(list(input_shape), input_dtype), device=dev)
+ tvm.runtime.tensor(generate_input_data(list(input_shape), input_dtype), device=dev)
)
# append scalar input tensors for rotary embedding
input_tensors.extend(scalar_input_tensors)
@@ -144,7 +144,7 @@ def benchmark(
_, profile_result = rpc_run(
rt_mod,
device_type=dev.DEVICE_TYPE_TO_NAME[dev.device_type],
- args=[w.numpy() if isinstance(w, tvm.nd.NDArray) else w for w in input_tensors],
+ args=[w.numpy() if isinstance(w, tvm.runtime.Tensor) else w for w in input_tensors],
rpc_config=rpc_config,
evaluator_config=evaluator_config,
)
diff --git a/python/tvm/exec/disco_worker.py b/python/tvm/exec/disco_worker.py
index fc22a50d9b..9c47627548 100644
--- a/python/tvm/exec/disco_worker.py
+++ b/python/tvm/exec/disco_worker.py
@@ -23,8 +23,8 @@ from typing import Callable
import tvm
from tvm_ffi import get_global_func, register_func
-from tvm.runtime import NDArray, ShapeTuple, String
-from tvm.runtime.ndarray import array
+from tvm.runtime import Tensor, ShapeTuple, String
+from tvm.runtime.tensor import tensor
@register_func("tests.disco.add_one", override=True)
@@ -37,9 +37,9 @@ def _add_one_float(x: float):
return x + 0.5
-@register_func("tests.disco.add_one_ndarray", override=True)
-def _add_one_ndarray(x: NDArray) -> NDArray:
- return array(x.numpy() + 1)
+@register_func("tests.disco.add_one_tensor", override=True)
+def _add_one_tensor(x: Tensor) -> Tensor:
+ return tensor(x.numpy() + 1)
@register_func("tests.disco.str", override=True)
@@ -60,7 +60,7 @@ def _shape_tuple_func(x: ShapeTuple):
@register_func("tests.disco.test_callback", override=True)
-def _make_callback(device: tvm.runtime.Device) -> Callable[[str, int], NDArray]:
+def _make_callback(device: tvm.runtime.Device) -> Callable[[str, int], Tensor]:
"""For use in tests/python/disco/test_callback.py
This function simulates a callback to be used for lazy parameter
@@ -75,7 +75,7 @@ def _make_callback(device: tvm.runtime.Device) -> Callable[[str, int], NDArray]:
Returns
-------
- fget_item: Callable[[str,int], NDArray]
+ fget_item: Callable[[str,int], Tensor]
A callback function that accepts a parameter's name and index,
and returns the specified parameter.
@@ -83,7 +83,7 @@ def _make_callback(device: tvm.runtime.Device) -> Callable[[str, int], NDArray]:
"""
import numpy as np # pylint: disable=import-outside-toplevel
- def fget_item(param_name: str, param_index: int) -> NDArray:
+ def fget_item(param_name: str, param_index: int) -> Tensor:
if param_index == 0:
assert param_name == "A"
arr = np.arange(16).reshape([4, 4]).astype("int32")
@@ -92,7 +92,7 @@ def _make_callback(device: tvm.runtime.Device) -> Callable[[str, int], NDArray]:
arr = np.arange(4).reshape([2, 2]).astype("float32")
else:
raise ValueError(f"Unexpected index {param_index}")
- return tvm.nd.array(arr, device=device)
+ return tvm.runtime.tensor(arr, device=device)
return fget_item
diff --git a/python/tvm/exec/rpc_proxy.py b/python/tvm/exec/rpc_proxy.py
index fd3ec55ba6..f8b4507f8e 100644
--- a/python/tvm/exec/rpc_proxy.py
+++ b/python/tvm/exec/rpc_proxy.py
@@ -40,7 +40,7 @@ def find_example_resource():
# recursively apend things in www, up to two levels
resource_bases = [
os.path.join(base_path, "web", "dist", "www"),
- os.path.join(base_path, "web", ".ndarray_cache"),
+ os.path.join(base_path, "web", ".tensor_cache"),
]
for base in resource_bases:
if not os.path.isdir(base):
diff --git a/python/tvm/ir/base.py b/python/tvm/ir/base.py
index 5e7996cf94..651ab39203 100644
--- a/python/tvm/ir/base.py
+++ b/python/tvm/ir/base.py
@@ -195,7 +195,7 @@ def structural_equal(lhs, rhs, map_free_vars=False):
return bool(_ffi_node_api.StructuralEqual(lhs, rhs, False, map_free_vars)) # type: ignore # pylint: disable=no-member
-def get_first_structural_mismatch(lhs, rhs, map_free_vars=False, skip_ndarray_content=False):
+def get_first_structural_mismatch(lhs, rhs, map_free_vars=False, skip_tensor_content=False):
"""Like structural_equal(), but returns the AccessPath pair of the first detected mismatch.
Parameters
@@ -210,7 +210,7 @@ def get_first_structural_mismatch(lhs, rhs, map_free_vars=False, skip_ndarray_co
Whether free variables (i.e. variables without a definition site) should be mapped
as equal to each other.
- skip_ndarray_content : bool
+ skip_tensor_content : bool
Whether to skip the content of ndarray.
Returns
@@ -221,7 +221,7 @@ def get_first_structural_mismatch(lhs, rhs, map_free_vars=False, skip_ndarray_co
"""
lhs = tvm.runtime.convert(lhs)
rhs = tvm.runtime.convert(rhs)
- return _ffi_node_api.GetFirstStructuralMismatch(lhs, rhs, map_free_vars, skip_ndarray_content) # type: ignore # pylint: disable=no-member
+ return _ffi_node_api.GetFirstStructuralMismatch(lhs, rhs, map_free_vars, skip_tensor_content) # type: ignore # pylint: disable=no-member
def assert_structural_equal(lhs, rhs, map_free_vars=False):
diff --git a/python/tvm/meta_schedule/builder/builder.py b/python/tvm/meta_schedule/builder/builder.py
index 3383ef55ad..3949378140 100644
--- a/python/tvm/meta_schedule/builder/builder.py
+++ b/python/tvm/meta_schedule/builder/builder.py
@@ -23,7 +23,7 @@ from typing_extensions import Literal
# isort: on
from tvm_ffi import register_object
from tvm.ir import IRModule
-from tvm.runtime import NDArray, Object
+from tvm.runtime import Tensor, Object
from tvm.target import Target
from .. import _ffi_api
@@ -39,19 +39,19 @@ class BuilderInput(Object):
The IRModule to be built.
target : Target
The target to be built for.
- params: Optional[Dict[str, NDArray]]
+ params: Optional[Dict[str, Tensor]]
The parameters for Relax build module
"""
mod: IRModule
target: Target
- params: Optional[Dict[str, NDArray]]
+ params: Optional[Dict[str, Tensor]]
def __init__(
self,
mod: IRModule,
target: Target,
- params: Optional[Dict[str, NDArray]] = None,
+ params: Optional[Dict[str, Tensor]] = None,
) -> None:
"""Constructor.
@@ -61,7 +61,7 @@ class BuilderInput(Object):
The IRModule to be built.
target : Target
The target to be built for.
- params: Optional[Dict[str, NDArray]]
+ params: Optional[Dict[str, Tensor]]
The parameters for Relax build module
"""
self.__init_handle_by_constructor__(
diff --git a/python/tvm/meta_schedule/builder/local_builder.py b/python/tvm/meta_schedule/builder/local_builder.py
index 297d6cb610..cda8d21838 100644
--- a/python/tvm/meta_schedule/builder/local_builder.py
+++ b/python/tvm/meta_schedule/builder/local_builder.py
@@ -21,7 +21,7 @@ from typing import Callable, Dict, List, Optional, Union
from tvm_ffi import register_func
from tvm.ir import IRModule
-from tvm.runtime import Module, NDArray, load_param_dict, save_param_dict
+from tvm.runtime import Module, Tensor, load_param_dict, save_param_dict
from tvm.target import Target
from ...contrib.popen_pool import MapResult, PopenPoolExecutor, StatusKind
@@ -33,18 +33,18 @@ logger = get_logger(__name__) # pylint: disable=invalid-name
T_BUILD = Callable[ # pylint: disable=invalid-name
- [IRModule, Target, Optional[Dict[str, NDArray]]], Module
+ [IRModule, Target, Optional[Dict[str, Tensor]]], Module
]
T_EXPORT = Callable[[Module], str] # pylint: disable=invalid-name
-def _serialize_params(params: Optional[Dict[str, NDArray]]) -> Optional[bytearray]:
+def _serialize_params(params: Optional[Dict[str, Tensor]]) -> Optional[bytearray]:
if params is None:
return None
return save_param_dict(params)
-def _deserialize_params(params: Optional[bytearray]) -> Optional[Dict[str, NDArray]]:
+def _deserialize_params(params: Optional[bytearray]) -> Optional[Dict[str, Tensor]]:
if params is None:
return None
return load_param_dict(params)
@@ -81,7 +81,7 @@ class LocalBuilder(PyBuilder):
def default_build(
mod: IRModule,
target: Target,
- params: Optional[Dict[str, NDArray]]
+ params: Optional[Dict[str, Tensor]]
) -> Module:
...
@@ -235,7 +235,7 @@ def _worker_func(
@register_func("meta_schedule.builder.default_build")
-def default_build(mod: IRModule, target: Target, _params: Optional[Dict[str, NDArray]]) -> Module:
+def default_build(mod: IRModule, target: Target, _params: Optional[Dict[str, Tensor]]) -> Module:
"""Default build function.
Parameters
@@ -244,7 +244,7 @@ def default_build(mod: IRModule, target: Target, _params: Optional[Dict[str, NDA
The IRModule to be built.
target : Target
The target to be built.
- _params : Optional[Dict[str, NDArray]]
+ _params : Optional[Dict[str, Tensor]]
The parameters to be used for the build. Must be None.
Returns
@@ -257,7 +257,7 @@ def default_build(mod: IRModule, target: Target, _params: Optional[Dict[str, NDA
from tvm.tir.transform import RemoveWeightLayoutRewriteBlock
# pylint: enable=import-outside-toplevel
- mod = RemoveWeightLayoutRewriteBlock(skip_ndarray_rewrite=True)(mod)
+ mod = RemoveWeightLayoutRewriteBlock(skip_tensor_rewrite=True)(mod)
return tvm_build(mod, target=target)
diff --git a/python/tvm/meta_schedule/cost_model/mlp_model.py b/python/tvm/meta_schedule/cost_model/mlp_model.py
index 9191eee6a6..ef846a6c7c 100644
--- a/python/tvm/meta_schedule/cost_model/mlp_model.py
+++ b/python/tvm/meta_schedule/cost_model/mlp_model.py
@@ -32,7 +32,7 @@ import torch # type: ignore
import tvm
from ...contrib.tar import tar, untar
-from ...runtime import NDArray
+from ...runtime import Tensor
from ...target import Target
from ..cost_model import PyCostModel
from ..database import JSONDatabase
@@ -441,7 +441,7 @@ def extract_features(
"""
extractor = extractor or PerStoreFeature(extract_workload=True)
- def _feature(feature: NDArray) -> np.ndarray:
+ def _feature(feature: Tensor) -> np.ndarray:
return feature.numpy().astype("float32")
def _mean_cost(res: RunnerResult) -> float:
diff --git a/python/tvm/meta_schedule/cost_model/xgb_model.py b/python/tvm/meta_schedule/cost_model/xgb_model.py
index 5806454cdd..a14dceef37 100644
--- a/python/tvm/meta_schedule/cost_model/xgb_model.py
+++ b/python/tvm/meta_schedule/cost_model/xgb_model.py
@@ -26,7 +26,7 @@ from typing_extensions import Literal
import numpy as np # type: ignore
from ...contrib.tar import tar, untar
-from ...runtime import NDArray
+from ...runtime import Tensor
from ..cost_model import PyCostModel
from ..feature_extractor import FeatureExtractor
from ..logging import get_logger
@@ -484,7 +484,7 @@ class XGBModel(PyCostModel):
group = self.data.get(new_group_hash, None)
# Step 2. Extract features
- def _feature(x: NDArray) -> np.ndarray:
+ def _feature(x: Tensor) -> np.ndarray:
return x.numpy().astype("float32")
def _mean_cost(x: RunnerResult) -> float:
diff --git a/python/tvm/meta_schedule/database/json_database.py b/python/tvm/meta_schedule/database/json_database.py
index cdf08c6e03..7c6f7459ca 100644
--- a/python/tvm/meta_schedule/database/json_database.py
+++ b/python/tvm/meta_schedule/database/json_database.py
@@ -38,10 +38,10 @@ class JSONDatabase(Database):
A string to specify the module equality testing and hashing method.
It must be one of the followings:
- "structural": Use StructuralEqual/Hash
- - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ - "ignore-tensor": Same as "structural", but ignore tensor raw data during
equality testing and hashing.
- "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- given module. The "ignore-ndarray" varint is used for the extracted
+ given module. The "ignore-tensor" varint is used for the extracted
blocks or in case no anchor block is found.
For the definition of the anchor block, see tir/analysis/analysis.py.
"""
diff --git a/python/tvm/meta_schedule/database/memory_database.py b/python/tvm/meta_schedule/database/memory_database.py
index 69b129ec21..1d6d412123 100644
--- a/python/tvm/meta_schedule/database/memory_database.py
+++ b/python/tvm/meta_schedule/database/memory_database.py
@@ -31,10 +31,10 @@ class MemoryDatabase(Database):
A string to specify the module equality testing and hashing method.
It must be one of the followings:
- "structural": Use StructuralEqual/Hash
- - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ - "ignore-tensor": Same as "structural", but ignore tensor raw data during
equality testing and hashing.
- "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- given module. The "ignore-ndarray" varint is used for the extracted
+ given module. The "ignore-tensor" varint is used for the extracted
blocks or in case no anchor block is found.
For the definition of the anchor block, see tir/analysis/analysis.py.
"""
diff --git a/python/tvm/meta_schedule/database/schedule_fn_database.py b/python/tvm/meta_schedule/database/schedule_fn_database.py
index 477c5664fd..74b2a6eb60 100644
--- a/python/tvm/meta_schedule/database/schedule_fn_database.py
+++ b/python/tvm/meta_schedule/database/schedule_fn_database.py
@@ -37,10 +37,10 @@ class ScheduleFnDatabase(Database):
A string to specify the module equality testing and hashing method.
It must be one of the followings:
- "structural": Use StructuralEqual/Hash
- - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ - "ignore-tensor": Same as "structural", but ignore tensor raw data during
equality testing and hashing.
- "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- given module. The "ignore-ndarray" varint is used for the extracted
+ given module. The "ignore-tensor" varint is used for the extracted
blocks or in case no anchor block is found.
For the definition of the anchor block, see tir/analysis/analysis.py.
"""
diff --git a/python/tvm/meta_schedule/feature_extractor/feature_extractor.py b/python/tvm/meta_schedule/feature_extractor/feature_extractor.py
index d4c68fcb93..b50a221429 100644
--- a/python/tvm/meta_schedule/feature_extractor/feature_extractor.py
+++ b/python/tvm/meta_schedule/feature_extractor/feature_extractor.py
@@ -24,7 +24,7 @@ from typing_extensions import Literal
from tvm_ffi import register_object
from tvm.runtime import Object
-from tvm.runtime.ndarray import NDArray
+from tvm.runtime._tensor import Tensor
from .. import _ffi_api
from ..search_strategy import MeasureCandidate
@@ -40,7 +40,7 @@ class FeatureExtractor(Object):
def extract_from(
self, context: TuneContext, candidates: List[MeasureCandidate]
- ) -> List[NDArray]:
+ ) -> List[Tensor]:
"""Extract features from the given measure candidate.
Parameters
@@ -52,7 +52,7 @@ class FeatureExtractor(Object):
Returns
-------
- features : List[NDArray]
+ features : List[Tensor]
The feature tvm ndarray extracted.
"""
result = _ffi_api.FeatureExtractorExtractFrom( # type: ignore # pylint: disable=no-member
@@ -108,7 +108,7 @@ class PyFeatureExtractor:
def extract_from(
self, context: TuneContext, candidates: List[MeasureCandidate]
- ) -> List[NDArray]:
+ ) -> List[Tensor]:
"""Extract features from the given measure candidate.
Parameters
@@ -120,7 +120,7 @@ class PyFeatureExtractor:
Returns
-------
- features : List[NDArray]
+ features : List[Tensor]
The feature tvm ndarray extracted.
"""
raise NotImplementedError
diff --git a/python/tvm/meta_schedule/feature_extractor/random_feature_extractor.py b/python/tvm/meta_schedule/feature_extractor/random_feature_extractor.py
index 18b84c364a..8e819468b8 100644
--- a/python/tvm/meta_schedule/feature_extractor/random_feature_extractor.py
+++ b/python/tvm/meta_schedule/feature_extractor/random_feature_extractor.py
@@ -18,7 +18,7 @@
from typing import List, Tuple, Union
import numpy as np # type: ignore
-from tvm.runtime.ndarray import NDArray, array
+from tvm.runtime._tensor import Tensor
from ..feature_extractor import PyFeatureExtractor
from ..search_strategy import MeasureCandidate
@@ -54,7 +54,7 @@ class RandomFeatureExtractor(PyFeatureExtractor):
def extract_from(
self, context: TuneContext, candidates: List[MeasureCandidate]
- ) -> List[NDArray]:
+ ) -> List[Tensor]:
np.random.set_state(self.random_state)
result = [
np.random.rand(np.random.randint(1, self.max_block_num + 1), self.feature_size)
diff --git a/python/tvm/meta_schedule/relax_integration.py b/python/tvm/meta_schedule/relax_integration.py
index 8d041b6caa..92e0e24a4c 100644
--- a/python/tvm/meta_schedule/relax_integration.py
+++ b/python/tvm/meta_schedule/relax_integration.py
@@ -26,7 +26,7 @@ from typing_extensions import Literal
from tvm_ffi import get_global_func, register_func
from tvm.ir import IRModule
from tvm.ir.transform import PassContext
-from tvm.runtime import NDArray
+from tvm.runtime import Tensor
from tvm.target import Target
from tvm.tir.expr import IntImm
@@ -56,7 +56,7 @@ _extract_task_func = get_global_func( # pylint: disable=invalid-name
def extract_tasks(
mod: Union[IRModule, "relax.Function"],
target: Target,
- params: Optional[Dict[str, NDArray]] = None,
+ params: Optional[Dict[str, Tensor]] = None,
module_equality: str = "structural",
) -> List[ExtractedTask]:
"""Extract tuning tasks from a relax program.
@@ -67,16 +67,16 @@ def extract_tasks(
The module or function to tune
target : tvm.target.Target
The compilation target
- params : Optional[Dict[str, tvm.runtime.NDArray]]
+ params : Optional[Dict[str, tvm.runtime.Tensor]]
The associated parameters of the program
module_equality : Optional[str]
A string to specify the module equality testing and hashing method.
It must be one of the followings:
- "structural": Use StructuralEqual/Hash
- - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ - "ignore-tensor": Same as "structural", but ignore tensor raw data during
equality testing and hashing.
- "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- given module. The "ignore-ndarray" varint is used for the extracted
+ given module. The "ignore-tensor" varint is used for the extracted
blocks or in case no anchor block is found.
For the definition of the anchor block, see tir/analysis/analysis.py.
@@ -159,7 +159,7 @@ def extracted_tasks_to_tune_contexts(
def tune_relax(
mod: Union[IRModule, "relax.Function"],
- params: Dict[str, NDArray],
+ params: Dict[str, Tensor],
target: Union[str, Target],
work_dir: str,
max_trials_global: int,
@@ -184,7 +184,7 @@ def tune_relax(
----------
mod : Union[IRModule, relax.Function]
The module or function to tune
- params : Optional[Dict[str, tvm.runtime.NDArray]]
+ params : Optional[Dict[str, tvm.runtime.Tensor]]
The associated parameters of the program
target : Union[Target, str]
The compilation target
@@ -221,10 +221,10 @@ def tune_relax(
A string to specify the module equality testing and hashing method.
It must be one of the followings:
- "structural": Use StructuralEqual/Hash
- - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ - "ignore-tensor": Same as "structural", but ignore tensor raw data during
equality testing and hashing.
- "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- given module. The "ignore-ndarray" variant is used for the extracted
+ given module. The "ignore-tensor" variant is used for the extracted
blocks or in case no anchor block is found.
For the definition of the anchor block, see tir/analysis/analysis.py.
@@ -272,7 +272,7 @@ def tune_relax(
@register_func("tvm.meta_schedule.tune_relax")
def _tune_relax(
mod: Union[IRModule, "relax.Function"],
- params: Dict[str, NDArray],
+ params: Dict[str, Tensor],
target: Union[str, Target],
work_dir: str,
max_trials_global: int,
@@ -297,7 +297,7 @@ def _tune_relax(
----------
mod : Union[IRModule, relax.Function]
The module or function to tune
- params : Optional[Dict[str, tvm.runtime.NDArray]]
+ params : Optional[Dict[str, tvm.runtime.Tensor]]
The associated parameters of the program
target : Union[Target, str]
The compilation target
@@ -334,10 +334,10 @@ def _tune_relax(
A string to specify the module equality testing and hashing method.
It must be one of the followings:
- "structural": Use StructuralEqual/Hash
- - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ - "ignore-tensor": Same as "structural", but ignore tensor raw data during
equality testing and hashing.
- "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- given module. The "ignore-ndarray" varint is used for the extracted
+ given module. The "ignore-tensor" varint is used for the extracted
blocks or in case no anchor block is found.
For the definition of the anchor block, see tir/analysis/analysis.py.
@@ -380,7 +380,7 @@ def compile_relax(
database: Database,
mod: IRModule,
target: Union[Target, str],
- params: Optional[Dict[str, NDArray]],
+ params: Optional[Dict[str, Tensor]],
enable_warning: bool = False,
) -> "relax.VMExecutable":
"""Compile a relax program with a MetaSchedule database.
@@ -393,7 +393,7 @@ def compile_relax(
The Relax program to be compiled
target : tvm.target.Target
The compilation target
- params : Optional[Dict[str, tvm.runtime.NDArray]]
+ params : Optional[Dict[str, tvm.runtime.Tensor]]
The associated parameters of the program
enable_warning : bool
A boolean value indicating if to print warnings for TIR functions not
diff --git a/python/tvm/meta_schedule/runner/utils.py b/python/tvm/meta_schedule/runner/utils.py
index ef0d4b5f98..ac3b23095a 100644
--- a/python/tvm/meta_schedule/runner/utils.py
+++ b/python/tvm/meta_schedule/runner/utils.py
@@ -18,7 +18,7 @@
import itertools
from typing import Any, Callable, Dict, List
-from ...runtime import Device, Module, ndarray
+from ...runtime import Device, Module, tensor
from .config import EvaluatorConfig
T_ARG_INFO_JSON_OBJ = List[Any] # pylint: disable=invalid-name
@@ -52,8 +52,8 @@ def alloc_argument_common(
The allocation args
"""
- def alloc_tensor(_, dtype, shape) -> ndarray.NDArray:
- arg = ndarray.empty(shape=shape, dtype=dtype, device=device)
+ def alloc_tensor(_, dtype, shape) -> tensor.Tensor:
+ arg = tensor.empty(shape=shape, dtype=dtype, device=device)
f_random_fill(arg)
return arg
diff --git a/python/tvm/meta_schedule/testing/tune_utils.py b/python/tvm/meta_schedule/testing/tune_utils.py
index 08618a289d..4b1155b2a2 100644
--- a/python/tvm/meta_schedule/testing/tune_utils.py
+++ b/python/tvm/meta_schedule/testing/tune_utils.py
@@ -19,7 +19,7 @@ from typing import Callable, Optional, List, Dict
import numpy as np # type: ignore
import tvm
-from tvm.runtime import NDArray
+from tvm.runtime import Tensor
def generate_input_data(
@@ -81,8 +81,8 @@ def create_calculator(backend: str) -> Callable:
def f_calculator(
rt_mod: tvm.runtime.Module,
dev: tvm.runtime.Device, # pylint: disable=unused-argument
- input_data: Dict[str, NDArray],
- ) -> List[NDArray]:
+ input_data: Dict[str, Tensor],
+ ) -> List[Tensor]:
"""Fetch the result of running the given runtime module.
Parameters
diff --git a/python/tvm/meta_schedule/testing/validate_database.py b/python/tvm/meta_schedule/testing/validate_database.py
index 4478792c5b..e356e6c753 100644
--- a/python/tvm/meta_schedule/testing/validate_database.py
+++ b/python/tvm/meta_schedule/testing/validate_database.py
@@ -205,22 +205,22 @@ def initializer() -> None:
@register_func("tvm.meta_schedule.testing.default_check_metric")
def default_check_metric( # pylint: disable=unused-variable,unreachable-code
- lhs: List[tvm.nd.NDArray], rhs: List[tvm.nd.NDArray]
+ lhs: List[tvm.runtime.Tensor], rhs: List[tvm.runtime.Tensor]
) -> bool:
"""Check if the outputs are equal
Parameters
----------
- lhs : List[tvm.nd.NDArray]
- The first list of NDArrays to compare.
+ lhs : List[tvm.runtime.Tensor]
+ The first list of Tensors to compare.
- rhs : List[tvm.nd.NDArray]
- The second list of NDArrays to compare.
+ rhs : List[tvm.runtime.Tensor]
+ The second list of Tensors to compare.
Returns
-------
is_equal : bool
- Whether the two lists of NDArrays are equal.
+ Whether the two lists of Tensors are equal.
"""
assert len(lhs) == len(rhs), "Different number of outputs from two modules"
for i in range(len(lhs)): # pylint: disable=consider-using-enumerate
@@ -232,7 +232,7 @@ def initializer() -> None:
@register_func("tvm.meta_schedule.testing.default_input_generator")
def default_input_generator( # pylint: disable=unused-variable
mod: IRModule,
-) -> List[tvm.nd.NDArray]:
+) -> List[tvm.runtime.Tensor]:
"""Default input generator function
Parameters
@@ -242,25 +242,27 @@ def default_input_generator( # pylint: disable=unused-variable
Returns
-------
- inputs : List[tvm.nd.NDArray]
+ inputs : List[tvm.runtime.Tensor]
The generated input data.
"""
args_info = ms.arg_info.TensorInfo.from_prim_func(mod["main"])
inputs = [
- tvm.nd.array(generate_input_data(input_shape=arg_info.shape, input_dtype=arg_info.dtype))
+ tvm.runtime.tensor(
+ generate_input_data(input_shape=arg_info.shape, input_dtype=arg_info.dtype)
+ )
for arg_info in args_info
]
return inputs
-def to_numpy(a: List[tvm.nd.NDArray]) -> List[np.ndarray]:
- """Convert a list of TVM NDArray to a list of numpy array
+def to_numpy(a: List[tvm.runtime.Tensor]) -> List[np.ndarray]:
+ """Convert a list of TVM Tensor to a list of numpy array
Parameters
----------
- a : List[tvm.nd.NDArray]
- The list of TVM NDArray to be converted
+ a : List[tvm.runtime.Tensor]
+ The list of TVM Tensor to be converted
Returns
-------
@@ -271,8 +273,8 @@ def to_numpy(a: List[tvm.nd.NDArray]) -> List[np.ndarray]:
return [x.numpy() for x in a]
-def to_tvm_ndarray(a: List[np.ndarray]) -> List[tvm.nd.NDArray]:
- """Convert a list of numpy array to a list of TVM NDArray
+def to_tvm_tensor(a: List[np.ndarray]) -> List[tvm.runtime.Tensor]:
+ """Convert a list of numpy array to a list of TVM Tensor
Parameters
----------
@@ -281,11 +283,11 @@ def to_tvm_ndarray(a: List[np.ndarray]) -> List[tvm.nd.NDArray]:
Returns
-------
- b : List[tvm.nd.NDArray]
- The list of TVM NDArray.
+ b : List[tvm.runtime.Tensor]
+ The list of TVM Tensor.
"""
- assert a is not None, "Empty result cannot be converted to TVM NDArray"
- return [tvm.nd.array(x) for x in a]
+ assert a is not None, "Empty result cannot be converted to TVM Tensor"
+ return [tvm.runtime.tensor(x) for x in a]
def is_failed_record(record: ms.database.TuningRecord) -> bool:
@@ -436,7 +438,9 @@ def make_alloc_arg_and_check(
args_list : List[T_ARGUMENT_LIST]
The list of argument lists.
"""
- return [[tvm.nd.array(arg, device=device) for arg in inputs] for _ in range(alloc_repeat)]
+ return [
+ [tvm.runtime.tensor(arg, device=device) for arg in inputs] for _ in range(alloc_repeat)
+ ]
def f_with_args_run_evaluator_common(
rt_mod: tvm.runtime.Module,
@@ -487,8 +491,8 @@ def make_alloc_arg_and_check(
# fetch comparison function
passed = check_and_run(
ARGS.check_metric_func,
- to_tvm_ndarray(original_res),
- to_tvm_ndarray(scheduled_res),
+ to_tvm_tensor(original_res),
+ to_tvm_tensor(scheduled_res),
)
print_result(
@@ -556,7 +560,7 @@ def local_build_and_run(
"""
# potential memory leak https://github.com/apache/tvm/issues/11096
lib = tvm.compile(mod, target=target)
- tvm_inputs = [tvm.nd.array(inp, device=device) for inp in inputs]
+ tvm_inputs = [tvm.runtime.tensor(inp, device=device) for inp in inputs]
device.sync()
func = lib.time_evaluator(lib.entry_name, dev=device, number=ARGS.number, repeat=ARGS.repeat)
benchmark_res = func(*tvm_inputs)
diff --git a/python/tvm/meta_schedule/tune.py b/python/tvm/meta_schedule/tune.py
index 78c05fed53..2cda77ba09 100644
--- a/python/tvm/meta_schedule/tune.py
+++ b/python/tvm/meta_schedule/tune.py
@@ -77,10 +77,10 @@ def tune_tasks(
It must be one of the followings:
- "structural": Use StructuralEqual/Hash
- - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during equality
+ - "ignore-tensor": Same as "structural", but ignore tensor raw data during equality
testing and hashing.
- "anchor-block": Apply equality testing and hashing on the anchor block extracted from
- a given module. The "ignore-ndarray" varint is used for the extracted blocks or in
+ a given module. The "ignore-tensor" varint is used for the extracted blocks or in
case no anchor block is found. For the definition of the anchor block, see
tir/analysis/analysis.py.
post_optimization : Optional[Bool]
diff --git a/python/tvm/relax/base_py_module.py b/python/tvm/relax/base_py_module.py
index f463a84fc6..2a654c334d 100644
--- a/python/tvm/relax/base_py_module.py
+++ b/python/tvm/relax/base_py_module.py
@@ -24,7 +24,7 @@ import numpy as np
import tvm
from tvm import relax, tir
from tvm.ir import IRModule
-from tvm.runtime import Device, NDArray, PackedFunc
+from tvm.runtime import Device, Tensor, PackedFunc
from tvm.target import Target
try:
@@ -38,7 +38,7 @@ class BasePyModule:
This class provides the infrastructure for:
1. JIT compilation of TIR and Relax functions.
- 2. DLPack-based conversion between PyTorch tensors and TVM NDArrays.
+ 2. DLPack-based conversion between PyTorch tensors and TVM Tensors.
3. Wrapping Relax functions for easy Python calling.
4. Cross-function calls between Python, TIR, and Relax functions.
@@ -208,7 +208,7 @@ class BasePyModule:
return result[0] if len(result) == 1 else result
def call_dps_packed(self, func_name: str, args, out_sinfo):
- """Call a packed function with PyTorch tensors, converting TVM NDArrays via DLPack."""
+ """Call a packed function with PyTorch tensors, converting TVM Tensors via DLPack."""
if hasattr(self, func_name) and callable(getattr(self, func_name)):
return getattr(self, func_name)(*args)
@@ -269,8 +269,8 @@ class BasePyModule:
def _convert_pytorch_to_tvm(
self, tensors: Union[Any, List[Any], Tuple[Any, ...]]
- ) -> Union[NDArray, List[NDArray]]:
- """Convert PyTorch tensors to TVM NDArrays using DLPack."""
+ ) -> Union[Tensor, List[Tensor]]:
+ """Convert PyTorch tensors to TVM Tensors using DLPack."""
# pylint: disable=import-outside-toplevel
import torch
@@ -278,12 +278,12 @@ class BasePyModule:
return [self._convert_single_pytorch_to_tvm(t) for t in tensors]
return self._convert_single_pytorch_to_tvm(tensors)
- def _convert_single_pytorch_to_tvm(self, tensor: Any) -> NDArray:
- """Convert a single PyTorch tensor to TVM NDArray with robust fallbacks."""
+ def _convert_single_pytorch_to_tvm(self, tensor: Any) -> Tensor:
+ """Convert a single PyTorch tensor to TVM Tensor with robust fallbacks."""
# pylint: disable=import-outside-toplevel
import torch
- if isinstance(tensor, NDArray):
+ if isinstance(tensor, Tensor):
return tensor
if isinstance(tensor, torch.Tensor):
# 1. Try modern `torch.to_dlpack` (preferred for PyTorch >= 1.7)
@@ -304,33 +304,33 @@ class BasePyModule:
)
# 3. If all DLPack methods fail, use numpy fallback
numpy_array = tensor.detach().cpu().numpy()
- return tvm.nd.array(numpy_array, device=self.device)
+ return tvm.runtime.tensor(numpy_array, device=self.device)
# For other types (like scalars, lists), convert to numpy first
try:
numpy_array = np.array(tensor, dtype=np.float32)
- return tvm.nd.array(numpy_array, device=self.device)
+ return tvm.runtime.tensor(numpy_array, device=self.device)
except (TypeError, ValueError) as error:
raise TypeError(
- f"Unsupported type for conversion to TVM NDArray: {type(tensor)}"
+ f"Unsupported type for conversion to TVM Tensor: {type(tensor)}"
) from error
def _convert_tvm_to_pytorch(
self, tvm_arrays: Union[Any, List[Any]]
) -> Union["torch.Tensor", List["torch.Tensor"]]:
- """Convert TVM NDArrays to PyTorch tensors using DLPack."""
+ """Convert TVM Tensors to PyTorch tensors using DLPack."""
if isinstance(tvm_arrays, (list, tuple)):
return [self._convert_single_tvm_to_pytorch(arr) for arr in tvm_arrays]
return self._convert_single_tvm_to_pytorch(tvm_arrays)
def _convert_single_tvm_to_pytorch(self, tvm_array: Any) -> "torch.Tensor":
- """Convert a single TVM NDArray to PyTorch tensor using DLPack."""
+ """Convert a single TVM Tensor to PyTorch tensor using DLPack."""
# pylint: disable=import-outside-toplevel
import torch
if isinstance(tvm_array, torch.Tensor):
return tvm_array
- if not isinstance(tvm_array, NDArray):
+ if not isinstance(tvm_array, Tensor):
return torch.tensor(tvm_array)
try:
dlpack = tvm_array.to_dlpack()
diff --git a/python/tvm/relax/exec_builder.py b/python/tvm/relax/exec_builder.py
index 43f9a2e693..50d6c0679e 100644
--- a/python/tvm/relax/exec_builder.py
+++ b/python/tvm/relax/exec_builder.py
@@ -106,7 +106,7 @@ class ExecBuilder(tvm_ffi.core.Object):
def emit_call(
self,
name: str,
- args: Optional[List[Union[tvm.nd.NDArray, tvm.DataType]]] = None,
+ args: Optional[List[Union[tvm.runtime.Tensor, tvm.DataType]]] = None,
dst: int = None,
) -> None:
"""emit a call instruction which calls a packed function."""
@@ -120,7 +120,7 @@ class ExecBuilder(tvm_ffi.core.Object):
shape_tuple = ShapeTuple(arg)
new_arg = self.convert_constant(shape_tuple)
args_.append(new_arg)
- elif isinstance(arg, (tvm.nd.NDArray, tvm.DataType, ShapeTuple)):
+ elif isinstance(arg, (tvm.runtime.Tensor, tvm.DataType, ShapeTuple)):
new_arg = self.convert_constant(arg)
args_.append(new_arg)
else:
diff --git a/python/tvm/relax/expr.py b/python/tvm/relax/expr.py
index 051e49f81c..2b78996f29 100644
--- a/python/tvm/relax/expr.py
+++ b/python/tvm/relax/expr.py
@@ -25,8 +25,8 @@ import tvm_ffi
import tvm.ir
import tvm.relax
from tvm import DataType
+import tvm.runtime
from tvm.runtime import Object
-from tvm.runtime import ndarray as _nd
from ..ir import BaseFunc, Node, Span
from ..runtime import Scriptable, String
@@ -713,7 +713,7 @@ class Constant(ExprWithOp):
Parameters
----------
- data: tvm.nd.NDArray
+ data: tvm.runtime.Tensor
The data of the constant tensor.
struct_info: Optional[StructInfo]
@@ -727,12 +727,12 @@ class Constant(ExprWithOp):
Scalar constants are represented by ndim-0 constant tensors.
"""
- data: tvm.nd.NDArray
+ data: tvm.runtime.Tensor
span: Optional[Span]
def __init__(
self,
- data: tvm.nd.NDArray,
+ data: tvm.runtime.Tensor,
struct_info: Optional[StructInfo] = None,
span: Optional[Span] = None,
) -> None:
@@ -1056,7 +1056,7 @@ class Function(BaseFunc, Scriptable):
self,
binding_map: Mapping[
Union[str, Var],
- Union[int, float, PrimExpr, tvm.runtime.NDArray, _np.ndarray, Expr],
+ Union[int, float, PrimExpr, tvm.runtime.Tensor, _np.ndarray, Expr],
],
) -> "Function":
"""Return a new function with updated symbolic variable
@@ -1065,7 +1065,7 @@ class Function(BaseFunc, Scriptable):
----------
binding_map: Mapping[
Union[str, Var],
- Union[int, float, PrimExpr, tvm.runtime.NDArray, _np.ndarray, Expr],
+ Union[int, float, PrimExpr, tvm.runtime.Tensor, _np.ndarray, Expr],
]
The mapping of values to be replaced.
@@ -1093,7 +1093,7 @@ class Function(BaseFunc, Scriptable):
# Relax uses int64 for symbolic variables, but the FFI
# converts python integers into int32.
return tvm.tir.const(value, "int64")
- elif isinstance(value, (_np.ndarray, tvm.nd.NDArray)):
+ elif isinstance(value, (_np.ndarray, tvm.runtime.Tensor)):
return tvm.relax.const(value)
else:
return value
@@ -1132,13 +1132,13 @@ def extern(name: str, struct_info: Optional[StructInfo] = None, span: Optional[S
def const(
- value: Union[bool, int, float, _np.ndarray, tvm.nd.NDArray], dtype: Optional[str] = None
+ value: Union[bool, int, float, _np.ndarray, tvm.runtime.Tensor], dtype: Optional[str] = None
) -> Constant:
"""Create a constant value.
Parameters
----------
- value: Union[bool, int, float, numpy.ndarray, tvm.nd.NDArray]
+ value: Union[bool, int, float, numpy.ndarray, tvm.runtime.Tensor]
The constant value.
dtype: Optional[str]
@@ -1168,10 +1168,10 @@ def const(
if isinstance(value, (_np.ndarray, _np.generic)):
if dtype is not None:
value = value.astype(dtype)
- value = _nd.array(value)
+ value = tvm.runtime.tensor(value)
- if not isinstance(value, _nd.NDArray):
- raise ValueError("value has to be scalar or NDArray")
+ if not isinstance(value, tvm.runtime.Tensor):
+ raise ValueError("value has to be scalar or Tensor")
return Constant(value)
diff --git a/python/tvm/relax/frontend/common.py b/python/tvm/relax/frontend/common.py
index ba2960c159..c1e9296ca3 100644
--- a/python/tvm/relax/frontend/common.py
+++ b/python/tvm/relax/frontend/common.py
@@ -23,7 +23,7 @@ import tvm
from tvm import topi
-def detach_params(mod: tvm.IRModule) -> Tuple[tvm.IRModule, Dict[str, List[tvm.nd.NDArray]]]:
+def detach_params(mod: tvm.IRModule) -> Tuple[tvm.IRModule, Dict[str, List[tvm.runtime.Tensor]]]:
"""Detach the attribute "params" in the functions of the input IRModule as
separate dictionary of params.
@@ -37,7 +37,7 @@ def detach_params(mod: tvm.IRModule) -> Tuple[tvm.IRModule, Dict[str, List[tvm.n
detached_mod : tvm.IRModule
The IRModule after the detachment.
- params_dict : Dict[str, List[tvm.nd.NDArray]]
+ params_dict : Dict[str, List[tvm.runtime.Tensor]]
The detached params. The dict keys corresponds to the names of the
functions in the input IRModule that have attribute "params".
"""
@@ -46,10 +46,8 @@ def detach_params(mod: tvm.IRModule) -> Tuple[tvm.IRModule, Dict[str, List[tvm.n
for gv, func in mod.functions_items():
if "params" in func.attrs:
params = list(func.attrs["params"])
- if not all([isinstance(param, tvm.nd.NDArray) for param in params]):
- raise ValueError(
- 'The value "params" attribute is expected to be a list of NDArray.'
- )
+ if not all([isinstance(param, tvm.runtime.Tensor) for param in params]):
+ raise ValueError('The value "params" attribute is expected to be a list of Tensor.')
params_dict[gv.name_hint] = params
detached_mod[gv] = func.without_attr("params")
else:
diff --git a/python/tvm/relax/frontend/nn/core.py b/python/tvm/relax/frontend/nn/core.py
index 068b2090db..b2904fe2a9 100644
--- a/python/tvm/relax/frontend/nn/core.py
+++ b/python/tvm/relax/frontend/nn/core.py
@@ -42,9 +42,9 @@ import numpy as np # type: ignore
from tvm import tir
from tvm.ir import IRModule
from tvm.ir.transform import Pass
-from tvm.runtime import Device, NDArray
+import tvm.runtime
+from tvm.runtime import Device
from tvm.runtime import device as as_device
-from tvm.runtime import ndarray
from tvm.runtime.vm import VirtualMachine
from tvm.target import Target
@@ -225,7 +225,7 @@ class Parameter(Tensor):
it is called a bound parameter, otherwise it is called an unbound parameter.
"""
- _data: Optional[NDArray]
+ _data: Optional[Tensor]
attrs: Dict[str, Any]
def __init__(
@@ -251,16 +251,16 @@ class Parameter(Tensor):
self.attrs = OrderedDict()
@property
- def data(self) -> Optional[NDArray]:
+ def data(self) -> Optional[Tensor]:
"""Returns the concrete value of the parameter if it is bound to a concrete value,
- otherwise returns None. The returned value is a tvm.runtime.NDArray."""
+ otherwise returns None. The returned value is a tvm.runtime.Tensor."""
return self._data
@data.setter
- def data(self, data: Union[None, NDArray, np.ndarray, "torch.Tensor"]) -> None:
+ def data(self, data: Union[None, tvm.runtime.Tensor, np.ndarray, "torch.Tensor"]) -> None:
"""Set the concrete value of the parameter. The data should be one of the following:
- None: unbind the parameter to concrete values
- - tvm.runtime.NDArray
+ - tvm.runtime.Tensor
- numpy.ndarray
- torch.Tensor and any other DLPack-compliant tensors
"""
@@ -268,10 +268,10 @@ class Parameter(Tensor):
self._data = data
return
# Try to do zero-copy if possible
- if isinstance(data, NDArray):
+ if isinstance(data, tvm.runtime.Tensor):
pass
elif isinstance(data, np.ndarray):
- data = ndarray.array(data)
+ data = tvm.runtime.tensor(data)
elif hasattr(data, "__dlpack__"):
data = _from_dlpack(data)
else:
@@ -526,7 +526,7 @@ class Module(SubroutineMixin):
),
device,
)
- params = _param_to_ndarray(params, device)
+ params = _param_to_tensor(params, device)
return spec, vm, params
device = as_device(device)
@@ -628,15 +628,15 @@ def _attribute_finder(root: Module, prefix: str, condition_yield: Callable[[Any]
)
-def _from_dlpack(tensor) -> NDArray:
+def _from_dlpack(tensor) -> tvm.runtime.Tensor:
try:
- return ndarray.from_dlpack(tensor)
+ return tvm.runtime.from_dlpack(tensor)
except RuntimeError:
pass
# special logic for PyTorch
device_type = tensor.device.type
device_id = tensor.device.index or 0
- return ndarray.array(
+ return tvm.runtime.tensor(
tensor.numpy(),
device=Device(
Device.DEVICE_NAME_TO_TYPE[device_type],
@@ -645,7 +645,9 @@ def _from_dlpack(tensor) -> NDArray:
)
-def _param_to_ndarray(params: List[Tuple[str, Parameter]], device: Device) -> List[NDArray]:
+def _param_to_tensor(
+ params: List[Tuple[str, Parameter]], device: Device
+) -> List[tvm.runtime.Tensor]:
results = []
missing = []
for name, param in params:
diff --git a/python/tvm/relax/frontend/nn/modules.py b/python/tvm/relax/frontend/nn/modules.py
index b61656a2e6..5ca5f72787 100644
--- a/python/tvm/relax/frontend/nn/modules.py
+++ b/python/tvm/relax/frontend/nn/modules.py
@@ -27,7 +27,7 @@ from .core import Effect, Module, ModuleList, Parameter, Tensor, get_default_dty
class IOEffect(Effect):
"""
- Modeling IO side effect, for example, printing the content of NDArrays on screen, inserting
+ Modeling IO side effect, for example, printing the content of Tensors on screen, inserting
debug breakpoints, etc.
"""
diff --git a/python/tvm/relax/frontend/nn/torch.py b/python/tvm/relax/frontend/nn/torch.py
index ae98868dae..4a85a14650 100644
--- a/python/tvm/relax/frontend/nn/torch.py
+++ b/python/tvm/relax/frontend/nn/torch.py
@@ -21,7 +21,7 @@ from typing import Any, Callable, List
import torch
from tvm.ir import Array
-from tvm.runtime import NDArray, ShapeTuple, ndarray
+from tvm.runtime import Tensor, ShapeTuple, ndarray
from tvm.runtime.vm import VirtualMachine
from . import core
@@ -34,14 +34,14 @@ class TorchModule: # pylint: disable=too-few-public-methods
spec: _spec.ModuleSpec
vm: VirtualMachine # pylint: disable=invalid-name
- params: List[NDArray]
+ params: List[Tensor]
effects: List[Any]
def __init__( # pylint: disable=invalid-name
self,
spec: _spec.ModuleSpec,
vm: VirtualMachine,
- params: List[NDArray],
+ params: List[Tensor],
):
try:
self.effects = vm["_initialize_effect"]()
@@ -87,7 +87,7 @@ class TorchModule: # pylint: disable=too-few-public-methods
def _tvm_to_torch(arg):
if isinstance(arg, (list, tuple, Array)):
return [_tvm_to_torch(i) for i in arg]
- if isinstance(arg, ndarray.NDArray):
+ if isinstance(arg, ndarray.Tensor):
return torch.utils.dlpack.from_dlpack(arg)
if isinstance(arg, ShapeTuple):
return list(arg)
diff --git a/python/tvm/relax/frontend/onnx/onnx_frontend.py b/python/tvm/relax/frontend/onnx/onnx_frontend.py
index 05e4534aca..5470c911d3 100644
--- a/python/tvm/relax/frontend/onnx/onnx_frontend.py
+++ b/python/tvm/relax/frontend/onnx/onnx_frontend.py
@@ -3830,9 +3830,9 @@ class ONNXGraphImporter:
name = value_proto
return name
- def _parse_array(self, tensor_proto: onnx.onnx_ml_pb2.TensorProto) -> tvm.nd.array:
+ def _parse_array(self, tensor_proto: onnx.onnx_ml_pb2.TensorProto) -> tvm.runtime.tensor:
np_array = get_numpy(tensor_proto).reshape(tuple(tensor_proto.dims))
- return tvm.nd.array(np_array)
+ return tvm.runtime.tensor(np_array)
def _parse_attr(self, attr_proto: onnx.onnx_ml_pb2.AttributeProto) -> Dict[str, Any]:
"""Convert a list of AttributeProto to a dict, with names as keys."""
diff --git a/python/tvm/relax/frontend/torch/dynamo.py b/python/tvm/relax/frontend/torch/dynamo.py
index c100194540..8837d96835 100644
--- a/python/tvm/relax/frontend/torch/dynamo.py
+++ b/python/tvm/relax/frontend/torch/dynamo.py
@@ -55,8 +55,8 @@ def relax_dynamo(pipeline: Optional[tvm.transform.Pass] = None):
assert isinstance(graph_module, torch.fx.GraphModule)
def to_torch_tensor(nd_tensor):
- """A helper function to transfer a NDArray to torch.tensor."""
- if isinstance(nd_tensor, tvm.nd.NDArray):
+ """A helper function to transfer a Tensor to torch.tensor."""
+ if isinstance(nd_tensor, tvm.runtime.Tensor):
return torch.from_numpy(nd_tensor.numpy())
elif isinstance(nd_tensor, tvm.ir.Array):
return tuple(to_torch_tensor(x) for x in nd_tensor)
@@ -64,12 +64,12 @@ def relax_dynamo(pipeline: Optional[tvm.transform.Pass] = None):
raise ValueError(f"Unsupported type {type(nd_tensor)}")
def to_tvm_tensor(torch_tensor):
- """A helper function to transfer a torch.tensor to NDArray."""
+ """A helper function to transfer a torch.tensor to Tensor."""
if not isinstance(torch_tensor, torch._subclasses.fake_tensor.FakeTensor):
- return tvm.nd.array(torch_tensor.numpy())
+ return tvm.runtime.tensor(torch_tensor.numpy())
# Fake Tensor
real_tensor = torch.randn(torch_tensor.shape, dtype=torch_tensor.dtype)
- return tvm.nd.array(real_tensor.numpy())
+ return tvm.runtime.tensor(real_tensor.numpy())
graph_module.graph.eliminate_dead_code()
diff --git a/python/tvm/relax/frontend/torch/fx_translator.py b/python/tvm/relax/frontend/torch/fx_translator.py
index 754129ffde..0d2e240be6 100644
--- a/python/tvm/relax/frontend/torch/fx_translator.py
+++ b/python/tvm/relax/frontend/torch/fx_translator.py
@@ -1042,7 +1042,7 @@ class TorchFXImporter(BaseFXGraphImporter):
dtype = self._convert_data_type(str(param.data.dtype))
inputs.append(relax.Var(name, relax.TensorStructInfo(shape, dtype)))
self.params[param] = inputs[-1]
- params.append(tvm.nd.array(param.data.cpu().numpy()))
+ params.append(tvm.runtime.tensor(param.data.cpu().numpy()))
else:
func_attrs = None
diff --git a/python/tvm/relax/op/base.py b/python/tvm/relax/op/base.py
index b0570344e5..4663e47020 100644
--- a/python/tvm/relax/op/base.py
+++ b/python/tvm/relax/op/base.py
@@ -414,7 +414,7 @@ def render_object(val: tvm.Object) -> str:
ret: str
A string representing the value, ideally human-readable
"""
- if isinstance(val, tvm.nd.NDArray):
+ if isinstance(val, tvm.runtime.Tensor):
return str(val)
if isinstance(val, tvm.ir.Array):
fields = ", ".join([render_object(val[i]) for i in range(len(val))])
@@ -423,16 +423,16 @@ def render_object(val: tvm.Object) -> str:
@tvm.register_func("relax.run.shape_to_tensor")
-def relax_shape_to_tensor(shape_tuple: tvm.runtime.ShapeTuple) -> tvm.nd.NDArray:
+def relax_shape_to_tensor(shape_tuple: tvm.runtime.ShapeTuple) -> tvm.runtime.Tensor:
"""
- Takes a ShapeTuple and convert it to NDArray.
+ Takes a ShapeTuple and convert it to Tensor.
Parameters
----------
shape_tuple: tvm.runtime.ShapeTuple
- Shape tuple that we want to convert to NDArray at runtime
+ Shape tuple that we want to convert to Tensor at runtime
"""
- return tvm.nd.array([int(v) for v in shape_tuple])
+ return tvm.runtime.tensor([int(v) for v in shape_tuple])
@tvm.register_func("relax.run.print")
@@ -514,7 +514,7 @@ def relax_assert_op(condition: tvm.Object, format_str: str, *format_args: tvm.Ob
if isinstance(condition, (bool, int)):
val = condition
- elif isinstance(condition, tvm.nd.NDArray):
+ elif isinstance(condition, tvm.runtime.Tensor):
# may happen if the original program had unknown shape or dtype for the tensor's type
dtype = condition.dtype
if dtype != "bool":
@@ -528,7 +528,7 @@ def relax_assert_op(condition: tvm.Object, format_str: str, *format_args: tvm.Ob
else:
# should be guaranteed by the type system
raise ValueError(
- f"The condition for relax assert must be a bool, int, or NDArray, "
+ f"The condition for relax assert must be a bool, int, or Tensor, "
f"but received a {type(condition)}."
)
diff --git a/python/tvm/relax/op/memory/view.py b/python/tvm/relax/op/memory/view.py
index 95adc78209..a7f6f91e18 100644
--- a/python/tvm/relax/op/memory/view.py
+++ b/python/tvm/relax/op/memory/view.py
@@ -70,7 +70,7 @@ def view(
relative_byte_offset: Optional[Expr]
- The offset of the output NDArray, relative to the byte offset
+ The offset of the output Tensor, relative to the byte offset
of `data`. If `None`, the offset of the view is the same as
the offset of `data`.
diff --git a/python/tvm/relax/op/set.py b/python/tvm/relax/op/set.py
index ed4b2e2ff9..4d0fd3dd42 100644
--- a/python/tvm/relax/op/set.py
+++ b/python/tvm/relax/op/set.py
@@ -86,13 +86,13 @@ def unique(
@tvm.register_func("relax.run.unique")
def numpy_unique(
- x: tvm.nd.array,
+ x: tvm.runtime.tensor,
sorted: int,
return_index: int,
return_inverse: int,
return_counts: int,
axis: Optional[int] = None,
-) -> tvm.nd.array:
+) -> tvm.runtime.tensor:
"""Returns the unique elements of the input tensor.
Uses numpy.unique to compute unique elements.
@@ -107,9 +107,9 @@ def numpy_unique(
output_sorted_numpy, indices = np.unique(x_numpy, return_index=True, axis=axis)
if sorted:
- return tvm.nd.array(output_sorted_numpy)
+ return tvm.runtime.tensor(output_sorted_numpy)
output_numpy = np.take(x_numpy, builtins.sorted(indices), axis=axis)
- return tvm.nd.array(output_numpy)
+ return tvm.runtime.tensor(output_numpy)
def nonzero(x: Expr) -> Expr:
@@ -144,6 +144,6 @@ def nonzero(x: Expr) -> Expr:
@tvm.register_func("relax.run.nonzero")
-def numpy_nonzero(x: tvm.nd.array) -> tvm.nd.array:
+def numpy_nonzero(x: tvm.runtime.tensor) -> tvm.runtime.tensor:
np_result = np.atleast_1d(x.numpy()).nonzero()
- return tvm.nd.array(np.stack(np_result, axis=0))
+ return tvm.runtime.tensor(np.stack(np_result, axis=0))
diff --git a/python/tvm/relax/pipeline.py b/python/tvm/relax/pipeline.py
index 37ef6156e4..a5850267a8 100644
--- a/python/tvm/relax/pipeline.py
+++ b/python/tvm/relax/pipeline.py
@@ -151,7 +151,7 @@ def static_shape_tuning_pipeline(
# the name should be f"{func_name}_transform_params"
params = vm["main_transform_params"](params["main"])
- input_data = tvm.nd.array(np.random.randn(1, 3, 224, 224).astype("float32"))
+ input_data = tvm.runtime.tensor(np.random.randn(1, 3, 224, 224).astype("float32"))
out = vm["main"](input_data, *params).numpy()
"""
diff --git a/python/tvm/relax/testing/lib_comparator.py b/python/tvm/relax/testing/lib_comparator.py
index b15698c8db..48930f0623 100644
--- a/python/tvm/relax/testing/lib_comparator.py
+++ b/python/tvm/relax/testing/lib_comparator.py
@@ -63,8 +63,8 @@ class LibCompareVMInstrument:
def compare(
self,
name: str,
- ref_args: Union[List[tvm.nd.NDArray], Tuple[tvm.nd.NDArray, ...]],
- new_args: Union[List[tvm.nd.NDArray], Tuple[tvm.nd.NDArray, ...]],
+ ref_args: Union[List[tvm.runtime.Tensor], Tuple[tvm.runtime.Tensor, ...]],
+ new_args: Union[List[tvm.runtime.Tensor], Tuple[tvm.runtime.Tensor, ...]],
ret_indices: Iterable[int],
):
"""Comparison function, can be overloaded.
@@ -103,7 +103,7 @@ class LibCompareVMInstrument:
return
if name.startswith("vm.builtin."):
return
- if any(not isinstance(x, tvm.nd.NDArray) for x in args):
+ if any(not isinstance(x, tvm.runtime.Tensor) for x in args):
return
try:
self.mod.get_function(name, query_imports=True)
@@ -120,7 +120,7 @@ class LibCompareVMInstrument:
ret_indices = (len(args) - 1,)
temp_args = []
for i, arg in enumerate(args):
- arr = tvm.nd.empty(arg.shape, arg.dtype, device=self.device)
+ arr = tvm.runtime.empty(arg.shape, arg.dtype, device=self.device)
# copy from cpu since we look at different device
if i not in ret_indices:
temp_cpu = arg.copyto(tvm.cpu())
diff --git a/python/tvm/relax/testing/nn.py b/python/tvm/relax/testing/nn.py
index 6e7e3d4d19..fb3564c6f1 100644
--- a/python/tvm/relax/testing/nn.py
+++ b/python/tvm/relax/testing/nn.py
@@ -281,7 +281,7 @@ def _unpack_params(value: object) -> List[relax.Var]:
return []
-def init_params(mod: tvm.IRModule) -> List[tvm.nd.array]:
+def init_params(mod: tvm.IRModule) -> List[tvm.runtime.Tensor]:
"""Utility function to initialize model's parameters."""
shape_dict = {v.name_hint: v.struct_info.shape for v in mod["main"].params}
params = []
@@ -295,7 +295,7 @@ def init_params(mod: tvm.IRModule) -> List[tvm.nd.array]:
shape.append(int(i))
else:
raise TypeError("cannot initialize for unknown-shape parameters.")
- params.append(tvm.nd.array(np.zeros(shape).astype(np.float32)))
+ params.append(tvm.runtime.tensor(np.zeros(shape).astype(np.float32)))
else:
raise TypeError("cannot initialize for unknown-shape parameters.")
return params
diff --git a/python/tvm/relax/testing/vm.py b/python/tvm/relax/testing/vm.py
index 37bcf870a5..737de13fc7 100644
--- a/python/tvm/relax/testing/vm.py
+++ b/python/tvm/relax/testing/vm.py
@@ -32,35 +32,35 @@ def move(src):
@tvm.register_func("test.vm.add")
def add(a, b):
ret = a.numpy() + b.numpy()
- return tvm.nd.array(ret)
+ return tvm.runtime.tensor(ret)
@tvm.register_func("test.vm.mul")
def mul(a, b):
ret = a.numpy() * b.numpy()
- return tvm.nd.array(ret)
+ return tvm.runtime.tensor(ret)
@tvm.register_func("test.vm.equal_zero")
def equal_zero(a):
ret = np.all((a.numpy() == 0))
- return tvm.nd.array(ret)
+ return tvm.runtime.tensor(ret)
@tvm.register_func("test.vm.subtract_one")
def subtract_one(a):
ret = np.subtract(a.numpy(), 1)
- return tvm.nd.array(ret)
+ return tvm.runtime.tensor(ret)
@tvm.register_func("test.vm.identity")
def identity_packed(a, b):
- b[:] = tvm.nd.array(a.numpy())
+ b[:] = tvm.runtime.tensor(a.numpy())
@tvm.register_func("test.vm.tile")
def tile_packed(a, b):
- b[:] = tvm.nd.array(np.tile(a.numpy(), (1, 2)))
+ b[:] = tvm.runtime.tensor(np.tile(a.numpy(), (1, 2)))
@tvm.register_func("test.vm.add_scalar")
diff --git a/python/tvm/relax/training/optimizer.py b/python/tvm/relax/training/optimizer.py
index d6f503de05..16a215f87d 100644
--- a/python/tvm/relax/training/optimizer.py
+++ b/python/tvm/relax/training/optimizer.py
@@ -291,7 +291,7 @@ class SGD(Optimizer):
self._set_params_and_dtype(params)
self.state = (
# num_steps = 0
- tvm.nd.array(np.zeros((), "int64")),
+ tvm.runtime.tensor(np.zeros((), "int64")),
)
return self
@@ -433,10 +433,10 @@ class MomentumSGD(Optimizer):
self._set_params_and_dtype(params)
self.state = (
# num_steps = 0
- tvm.nd.array(np.zeros((), "int64")),
+ tvm.runtime.tensor(np.zeros((), "int64")),
# v_{param} is initialized to all zeros
*(
- tvm.nd.array(np.zeros(_get_shape_as_int_list(p), p.struct_info.dtype))
+ tvm.runtime.tensor(np.zeros(_get_shape_as_int_list(p), p.struct_info.dtype))
for p in self.param_list
),
)
@@ -604,17 +604,17 @@ class Adam(Optimizer):
self._set_params_and_dtype(params)
self.state = (
# num_steps, beta_0_prod, beta_1_prod
- tvm.nd.array(np.zeros((), "int64")),
- tvm.nd.array(np.ones((), self.dtype)),
- tvm.nd.array(np.ones((), self.dtype)),
+ tvm.runtime.tensor(np.zeros((), "int64")),
+ tvm.runtime.tensor(np.ones((), self.dtype)),
+ tvm.runtime.tensor(np.ones((), self.dtype)),
# first_momentum
*(
- tvm.nd.array(np.zeros(_get_shape_as_int_list(p), p.struct_info.dtype))
+ tvm.runtime.tensor(np.zeros(_get_shape_as_int_list(p), p.struct_info.dtype))
for p in self.param_list
),
# second_momentum
*(
- tvm.nd.array(np.zeros(_get_shape_as_int_list(p), p.struct_info.dtype))
+ tvm.runtime.tensor(np.zeros(_get_shape_as_int_list(p), p.struct_info.dtype))
for p in self.param_list
),
)
diff --git a/python/tvm/relax/training/trainer.py b/python/tvm/relax/training/trainer.py
index fbf48fece9..aaaa14dd28 100644
--- a/python/tvm/relax/training/trainer.py
+++ b/python/tvm/relax/training/trainer.py
@@ -22,7 +22,7 @@ import numpy as np # type: ignore
import tvm
from tvm import relax, TVMError
from tvm.ir.module import IRModule
-from tvm.runtime.ndarray import NDArray
+from tvm.runtime._tensor import Tensor
class Trainer:
@@ -100,12 +100,12 @@ class Trainer:
)
]
- self._params: List[Optional[NDArray]] = [None] * self._param_num
+ self._params: List[Optional[Tensor]] = [None] * self._param_num
self._param_name_to_pos: Dict[str, int] = {
p.name_hint: i for i, p in enumerate(self._param_vars)
}
- self._states: List[Optional[NDArray]] = [None] * self._state_num
+ self._states: List[Optional[Tensor]] = [None] * self._state_num
self._state_name_to_pos: Dict[str, int] = {
s.name_hint: i for i, s in enumerate(self._state_vars)
}
@@ -129,7 +129,7 @@ class Trainer:
for p in self._param_vars:
shape, dtype = self._get_shape_list(p), p.struct_info.dtype
self._params.append(
- tvm.nd.array(
+ tvm.runtime.tensor(
(np.sqrt(6.0 / np.sum(shape)) * np.random.uniform(-1.0, 1.0, shape)).astype(
dtype
),
@@ -140,27 +140,27 @@ class Trainer:
def zero_init_params(self):
"""Zero initialize all parameters. Requires all parameters have static shapes."""
self._params = [
- tvm.nd.array(np.zeros(self._get_shape_list(p), p.struct_info.dtype), self.device)
+ tvm.runtime.tensor(np.zeros(self._get_shape_list(p), p.struct_info.dtype), self.device)
for p in self._param_vars
]
def zero_init_states(self):
"""Zero initialize all states. Requires all states have static shapes."""
self._states = [
- tvm.nd.array(np.zeros(self._get_shape_list(s), s.struct_info.dtype), self.device)
+ tvm.runtime.tensor(np.zeros(self._get_shape_list(s), s.struct_info.dtype), self.device)
for s in self._state_vars
]
def load_params(
self,
- params: Union[List[Union[np.ndarray, NDArray]], Dict[str, Union[np.ndarray, NDArray]]],
+ params: Union[List[Union[np.ndarray, Tensor]], Dict[str, Union[np.ndarray, Tensor]]],
):
- """Load parameters from a dict or a list. Will convert parameters into tvm.runtime.NDArray
+ """Load parameters from a dict or a list. Will convert parameters into tvm.runtime.Tensor
in self.device.
Parameters
----------
- params : List[Union[np.ndarray, NDArray]], Dict[str, Union[np.ndarray, NDArray]]
+ params : List[Union[np.ndarray, Tensor]], Dict[str, Union[np.ndarray, Tensor]]
The numerical value of the parameters.
If params is a list, its length should be param_num. The value of parameters at the
@@ -176,25 +176,25 @@ class Trainer:
f"The length of extern parameters is {len(params)}, which does not "
f"match the number of parameters {self._param_num}"
)
- self._params = [tvm.nd.array(v, self.device) for v in params]
+ self._params = [tvm.runtime.tensor(v, self.device) for v in params]
elif isinstance(params, dict):
for key, val in params.items():
if key not in self._param_name_to_pos:
raise ValueError(f"Parameter {key} is not found in the model")
- self._params[self._param_name_to_pos[key]] = tvm.nd.array(val, self.device)
+ self._params[self._param_name_to_pos[key]] = tvm.runtime.tensor(val, self.device)
else:
raise ValueError("The type of extern_params should be either list or dict")
def load_states(
self,
- states: Union[List[Union[np.ndarray, NDArray]], Dict[str, Union[np.ndarray, NDArray]]],
+ states: Union[List[Union[np.ndarray, Tensor]], Dict[str, Union[np.ndarray, Tensor]]],
):
- """Load model states from a dict or a list. Will convert states into tvm.runtime.NDArray
+ """Load model states from a dict or a list. Will convert states into tvm.runtime.Tensor
in self.device.
Parameters
----------
- states : List[Union[np.ndarray, NDArray]], Dict[str, Union[np.ndarray, NDArray]]
+ states : List[Union[np.ndarray, Tensor]], Dict[str, Union[np.ndarray, Tensor]]
The numerical value of the model states.
If states is a list, its length should be state_num. The value of states at the
@@ -210,31 +210,31 @@ class Trainer:
f"The length of extern states is {len(states)}, which does not match "
f"the number of model states {self._state_num}"
)
- self._states = [tvm.nd.array(v, self.device) for v in states]
+ self._states = [tvm.runtime.tensor(v, self.device) for v in states]
elif isinstance(states, dict):
for key, val in states.items():
if key not in self._param_name_to_pos:
raise ValueError(f"Parameter {key} is not found in the model")
- self._states[self._param_name_to_pos[key]] = tvm.nd.array(val, self.device)
+ self._states[self._param_name_to_pos[key]] = tvm.runtime.tensor(val, self.device)
else:
raise ValueError("The type of extern_states should be either list or dict")
- def export_params(self) -> Dict[str, NDArray]:
- """Export parameters to a dict (parameter name -> NDArray).
+ def export_params(self) -> Dict[str, Tensor]:
+ """Export parameters to a dict (parameter name -> Tensor).
Returns
-------
- exported_dict : Dict[str, NDArray]
+ exported_dict : Dict[str, Tensor]
The exported dictionary of parameters.
"""
return {key: self._params[pos] for key, pos in self._param_name_to_pos.items()}
- def export_states(self) -> Dict[str, NDArray]:
- """Export model states to a dict (parameter name -> NDArray).
+ def export_states(self) -> Dict[str, Tensor]:
+ """Export model states to a dict (parameter name -> Tensor).
Returns
-------
- exported_dict : Dict[str, NDArray]
+ exported_dict : Dict[str, Tensor]
The exported dictionary of model states.
"""
return {key: self._states[pos] for key, pos in self._state_name_to_pos.items()}
@@ -255,26 +255,28 @@ class Trainer:
"inference."
)
- def predict(self, *input_instances: Union[np.ndarray, NDArray]) -> NDArray:
+ def predict(self, *input_instances: Union[np.ndarray, Tensor]) -> Tensor:
"""Call the `backbone` function and return the prediction result of the backbone.
Parameters
----------
- *input_instances : Union[np.ndarray, NDArray]
+ *input_instances : Union[np.ndarray, Tensor]
The values corresponding to the input_instances part of the backbone function.
Parameters and model states are not needed to provide.
Returns
-------
- output : NDArray
+ output : Tensor
The result of the backbone function. If the backbone contains model states, the updated
states WILL NOT be returned.
"""
self._check_inited()
if len(input_instances) != self._input_num:
raise ValueError("The length of the input does not match the backbone")
- all_inputs: List[NDArray] = (
- [tvm.nd.array(i, self.device) for i in input_instances] + self._params + self._states
+ all_inputs: List[Tensor] = (
+ [tvm.runtime.tensor(i, self.device) for i in input_instances]
+ + self._params
+ + self._states
)
res = self.vm[self.BACKBONE_FUNC](*all_inputs)
@@ -287,9 +289,9 @@ class Trainer:
def update(
self,
- input_instances: Union[np.ndarray, NDArray, List[Union[np.ndarray, NDArray]]],
- targets: Union[np.ndarray, NDArray, List[Union[np.ndarray, NDArray]]],
- ) -> NDArray:
+ input_instances: Union[np.ndarray, Tensor, List[Union[np.ndarray, Tensor]]],
+ targets: Union[np.ndarray, Tensor, List[Union[np.ndarray, Tensor]]],
+ ) -> Tensor:
"""Update parameters and model states. It will calculate the gradients of parameters
and update them using the `optimizer` function.
@@ -298,21 +300,21 @@ class Trainer:
Parameters
----------
- input_instances : Union[np.ndarray, NDArray, List[Union[np.ndarray, NDArray]]]
+ input_instances : Union[np.ndarray, Tensor, List[Union[np.ndarray, Tensor]]]
The values corresponding to the input_instances part of the backbone function.
Parameters and model states are not needed to provide.
If there are more than one input instances, you can provide a list.
- targets : Union[np.ndarray, NDArray, List[Union[np.ndarray, NDArray]]]
+ targets : Union[np.ndarray, Tensor, List[Union[np.ndarray, Tensor]]]
The values corresponding to the targets part of the backbone function.
If there are more than one targets, you can provide a list.
Returns
-------
- loss : NDArray
- The loss stored in tvm.runtime.NDArray.
+ loss : Tensor
+ The loss stored in tvm.runtime.Tensor.
"""
self._check_inited()
@@ -325,11 +327,11 @@ class Trainer:
if len(input_instances) != self._input_num:
raise ValueError("The length of the input does not match the backbone")
- all_inputs: List[NDArray] = (
- [tvm.nd.array(i, self.device) for i in input_instances]
+ all_inputs: List[Tensor] = (
+ [tvm.runtime.tensor(i, self.device) for i in input_instances]
+ self._params
+ self._states
- + [tvm.nd.array(i, self.device) for i in targets]
+ + [tvm.runtime.tensor(i, self.device) for i in targets]
)
ret, grads = self.vm[self.ADJOINT_FUNC](*all_inputs)
@@ -348,21 +350,21 @@ class Trainer:
def profile_adjoint(
self,
- input_instances: List[Union[np.ndarray, NDArray]],
- targets: List[Union[np.ndarray, NDArray]],
+ input_instances: List[Union[np.ndarray, Tensor]],
+ targets: List[Union[np.ndarray, Tensor]],
) -> tvm.runtime.profiling.Report:
"""Profile the adjoint function. It requires the VM to be constructed with `profile=True`,
and runs `tvm.relax.VirtualMachine.profile()` internally.
Parameters
----------
- input_instances : Union[np.ndarray, NDArray, List[Union[np.ndarray, NDArray]]]
+ input_instances : Union[np.ndarray, Tensor, List[Union[np.ndarray, Tensor]]]
The values corresponding to the input_instances part of the backbone function.
Parameters and model states are not needed to provide.
If there are more than one input instances, you can provide a list.
- targets : Union[np.ndarray, NDArray, List[Union[np.ndarray, NDArray]]]
+ targets : Union[np.ndarray, Tensor, List[Union[np.ndarray, Tensor]]]
The values corresponding to the targets part of the backbone function.
If there are more than one targets, you can provide a list.
@@ -383,11 +385,11 @@ class Trainer:
if len(input_instances) != self._input_num:
raise ValueError("The length of the input does not match the backbone")
- all_inputs: List[NDArray] = (
- [tvm.nd.array(i) for i in input_instances]
+ all_inputs: List[Tensor] = (
+ [tvm.runtime.tensor(i) for i in input_instances]
+ self._params
+ self._states
- + [tvm.nd.array(i) for i in targets]
+ + [tvm.runtime.tensor(i) for i in targets]
)
all_inputs = [i.copyto(self.device) for i in all_inputs]
return self.vm.profile(self.ADJOINT_FUNC, *all_inputs)
diff --git a/python/tvm/relax/transform/transform.py b/python/tvm/relax/transform/transform.py
index bf813b3dd6..c945732a6d 100644
--- a/python/tvm/relax/transform/transform.py
+++ b/python/tvm/relax/transform/transform.py
@@ -28,7 +28,7 @@ import tvm.ir
from tvm.ir.container import Array
from tvm.relax import Expr, Var, StructInfo
from tvm.relax.dpl import DFPattern
-from tvm.runtime import NDArray, Object
+from tvm.runtime import Tensor, Object
from tvm.tir import IndexMap, PrimFunc
from . import _ffi_api
@@ -638,7 +638,7 @@ def AttachGlobalSymbol() -> tvm.ir.transform.Pass:
def BindParams(
func_name: str,
- params: Dict[Union[str, Var], Union[tvm.runtime.NDArray, np.ndarray]],
+ params: Dict[Union[str, Var], Union[tvm.runtime.Tensor, np.ndarray]],
) -> tvm.ir.transform.Pass:
"""Bind params of function of the module to constant tensors.
@@ -647,7 +647,7 @@ def BindParams(
func_name: str
The function name to be bound
- params: Dict[Union[str,relax.Var], Union[tvm.runtime.NDArray, np.ndarray]]
+ params: Dict[Union[str,relax.Var], Union[tvm.runtime.Tensor, np.ndarray]]
The map from parameter or parameter name to constant tensors.
Returns
@@ -657,9 +657,9 @@ def BindParams(
tvm_params = {}
for k, v in params.items():
if isinstance(v, np.ndarray):
- v = tvm.nd.array(v)
- assert isinstance(v, (tvm.runtime.NDArray, tvm.relax.Constant)), (
- f"param values are expected to be TVM.NDArray,"
+ v = tvm.runtime.tensor(v)
+ assert isinstance(v, (tvm.runtime.Tensor, tvm.relax.Constant)), (
+ f"param values are expected to be TVM.Tensor,"
f"numpy.ndarray or tvm.relax.Constant, but got {type(v)}"
)
tvm_params[k] = v
@@ -1223,7 +1223,7 @@ def MetaScheduleTuneTIR(
def MetaScheduleTuneIRMod(
- params: Dict[str, NDArray],
+ params: Dict[str, Tensor],
work_dir: str,
max_trials_global: int,
max_trials_per_task: Optional[int] = None,
@@ -1233,7 +1233,7 @@ def MetaScheduleTuneIRMod(
Parameters
----------
- params: Dict[str, NDArray]
+ params: Dict[str, Tensor]
model params
work_dir: str
work directory
diff --git a/python/tvm/rpc/client.py b/python/tvm/rpc/client.py
index 90267c0526..37bc6b3117 100644
--- a/python/tvm/rpc/client.py
+++ b/python/tvm/rpc/client.py
@@ -23,9 +23,9 @@ import struct
import time
import tvm_ffi
+import tvm.runtime
from tvm.base import TVMError
from tvm.contrib import utils
-from tvm.runtime import ndarray as nd
from tvm.runtime import Device
from . import _ffi_api, base, server
@@ -86,9 +86,9 @@ class RPCSession(object):
dev: Device
The corresponding encoded remote device.
"""
- dev = nd.device(dev_type, dev_id)
+ dev = tvm.runtime.device(dev_type, dev_id)
encode = (self._tbl_index + 1) * base.RPC_SESS_MASK
- dev = nd.device(dev.device_type + encode, dev.device_id)
+ dev = tvm.runtime.device(dev.device_type + encode, dev.device_id)
dev._rpc_sess = self
return dev
diff --git a/python/tvm/rpc/testing.py b/python/tvm/rpc/testing.py
index ba88c20484..d274854138 100644
--- a/python/tvm/rpc/testing.py
+++ b/python/tvm/rpc/testing.py
@@ -42,8 +42,8 @@ def _strcat(x, y):
return x + y
-@tvm.register_func("rpc.test.remote_array_func")
-def _remote_array_func(y):
+@tvm.register_func("rpc.test.remote_tensor_func")
+def _remote_tensor_func(y):
x = np.ones((3, 4))
np.testing.assert_equal(y.numpy(), x)
@@ -56,7 +56,7 @@ def _add_to_lhs(x):
@tvm.register_func("rpc.test.remote_return_nd")
def _my_module(name):
# Use closure to check the ref counter correctness
- nd = tvm.nd.array(np.zeros(10).astype("float32"))
+ nd = tvm.runtime.tensor(np.zeros(10).astype("float32"))
if name == "get_arr":
return lambda: nd
diff --git a/python/tvm/runtime/__init__.py b/python/tvm/runtime/__init__.py
index 5b7dea8367..57546dcff4 100644
--- a/python/tvm/runtime/__init__.py
+++ b/python/tvm/runtime/__init__.py
@@ -24,14 +24,14 @@ from .object import Object
from .script_printer import Scriptable
from .object_generic import ObjectGeneric
from .device import Device
-from .ndarray import NDArray
+from ._tensor import Tensor, tensor, empty
from .module import Module
from .profiling import Report
from .executable import Executable
# function exposures
-from .ndarray import device, cpu, cuda, opencl, vulkan, metal
-from .ndarray import vpi, rocm, ext_dev
+from ._tensor import device, cpu, cuda, opencl, vulkan, metal
+from ._tensor import vpi, rocm, ext_dev, from_dlpack
from .module import load_module, enabled, system_lib, load_static_library, num_threads
from .container import String, ShapeTuple
from .object_generic import const
diff --git a/python/tvm/runtime/ndarray.py b/python/tvm/runtime/_tensor.py
similarity index 90%
rename from python/tvm/runtime/ndarray.py
rename to python/tvm/runtime/_tensor.py
index 39ff8fb1bf..1d413272b2 100644
--- a/python/tvm/runtime/ndarray.py
+++ b/python/tvm/runtime/_tensor.py
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
# pylint: disable=invalid-name, unused-import, redefined-outer-name
-"""Runtime NDArray API"""
+"""Runtime Tensor API"""
import ctypes
import warnings
from typing import Optional
@@ -49,7 +49,7 @@ from . import _ffi_api
def from_dlpack(ext_tensor):
"""
- Convert an external tensor to an NDArray.
+ Convert an external tensor to an Tensor.
Parameters
----------
@@ -69,9 +69,9 @@ def from_dlpack(ext_tensor):
)
-@tvm_ffi.register_object("ffi.NDArray")
-class NDArray(tvm_ffi.core.NDArray):
- """Lightweight NDArray class of TVM runtime.
+@tvm_ffi.register_object("ffi.Tensor")
+class Tensor(tvm_ffi.core.Tensor):
+ """Lightweight Tensor class of TVM runtime.
Strictly this is only an Array Container (a buffer object)
No arthimetic operations are defined.
@@ -90,7 +90,7 @@ class NDArray(tvm_ffi.core.NDArray):
or in_slice.stop is not None
):
raise ValueError("Array only support set from numpy array")
- if isinstance(value, NDArray):
+ if isinstance(value, Tensor):
if not value.same_as(self):
value.copyto(self)
elif isinstance(value, (np.ndarray, np.generic)):
@@ -108,10 +108,10 @@ class NDArray(tvm_ffi.core.NDArray):
Returns
-------
- arr : NDArray
+ arr : Tensor
Reference to self.
"""
- if isinstance(source_array, NDArray):
+ if isinstance(source_array, Tensor):
source_array.copyto(self)
return self
@@ -132,7 +132,7 @@ class NDArray(tvm_ffi.core.NDArray):
if source_array.shape != shape:
raise ValueError(
- f"array shape do not match the shape of NDArray {source_array.shape} vs {shape}"
+ f"array shape do not match the shape of Tensor {source_array.shape} vs {shape}"
)
numpy_str_map = tvm_ffi.dtype.NUMPY_DTYPE_TO_STR
np_dtype_str = (
@@ -159,14 +159,14 @@ class NDArray(tvm_ffi.core.NDArray):
assert source_array.flags["C_CONTIGUOUS"]
data = source_array.ctypes.data_as(ctypes.c_void_p)
nbytes = source_array.size * source_array.dtype.itemsize
- _ffi_api.TVMArrayCopyFromBytes(self, data, nbytes)
+ _ffi_api.TVMTensorCopyFromBytes(self, data, nbytes)
return self
def __repr__(self):
# exception safety handling for chandle=None
if self.__chandle__() == 0:
return type(self).__name__ + "(chandle=None)"
- res = f"<tvm.nd.NDArray shape={self.shape}, {self.device}>\n"
+ res = f"<tvm.runtime.Tensor shape={self.shape}, {self.device}>\n"
res += self.numpy().__repr__()
return res
@@ -218,7 +218,7 @@ class NDArray(tvm_ffi.core.NDArray):
# TODO(kathy): revisit and get a mirrored function of ffi::GetDataSize
# in Python to replace line below
nbytes = np_arr.size if dtype == "bool" else (np_arr.size * old_dtype.bits + 7) // 8
- _ffi_api.TVMArrayCopyToBytes(self, data, nbytes)
+ _ffi_api.TVMTensorCopyToBytes(self, data, nbytes)
if old_dtype == "int4" or old_dtype.startswith("float4_e2m1fn"):
length = np_arr.size
@@ -238,13 +238,13 @@ class NDArray(tvm_ffi.core.NDArray):
Parameters
----------
- target : NDArray
+ target : Tensor
The target array to be copied, must have same shape as this array.
mem_scope : Optional[str]
The memory scope of the array.
"""
- if isinstance(target, NDArray):
+ if isinstance(target, Tensor):
return self._copyto(target)
if isinstance(target, tvm_ffi.core.Device):
res = empty(self.shape, self.dtype, target, mem_scope)
@@ -253,7 +253,7 @@ class NDArray(tvm_ffi.core.NDArray):
def _copyto(self, target_nd):
"""Internal function that implements copy to target ndarray."""
- _ffi_api.TVMArrayCopyFromTo(self, target_nd)
+ _ffi_api.TVMTensorCopyFromTo(self, target_nd)
return target_nd
def _create_view(self, shape, dtype: Optional[str] = None, relative_byte_offset: int = 0):
@@ -301,7 +301,7 @@ class NDArray(tvm_ffi.core.NDArray):
if dtype is None:
dtype = self.dtype
- return _ffi_api.TVMArrayCreateView(self, shape, dtype, relative_byte_offset)
+ return _ffi_api.TVMTensorCreateView(self, shape, dtype, relative_byte_offset)
def empty(shape, dtype="float32", device=None, mem_scope=None):
@@ -323,19 +323,19 @@ def empty(shape, dtype="float32", device=None, mem_scope=None):
Returns
-------
- arr : tvm.nd.NDArray
+ arr : tvm.runtime.Tensor
The array tvm supported.
"""
device = device or cpu()
if not isinstance(shape, tvm.runtime.ShapeTuple):
shape = tvm.runtime.ShapeTuple([int(dim) for dim in shape])
dtype = tvm_ffi.dtype(dtype)
- arr = _ffi_api.TVMArrayAllocWithScope(shape, dtype, device, mem_scope)
+ arr = _ffi_api.TVMTensorAllocWithScope(shape, dtype, device, mem_scope)
return arr
-def array(arr, device=None, mem_scope=None):
- """Create an array from source arr.
+def tensor(arr, device=None, mem_scope=None):
+ """Create an tensor from source arr.
Parameters
----------
@@ -350,15 +350,15 @@ def array(arr, device=None, mem_scope=None):
Returns
-------
- ret : NDArray
+ ret : Tensor
The created array
"""
device = device or cpu()
- if not isinstance(arr, (np.ndarray, NDArray)):
+ if not isinstance(arr, (np.ndarray, Tensor)):
arr = np.array(arr)
return empty(arr.shape, arr.dtype, device, mem_scope).copyfrom(arr)
# Register back to FFI
-tvm_ffi.core._set_class_ndarray(NDArray)
+tvm_ffi.core._set_class_tensor(Tensor)
diff --git a/python/tvm/runtime/disco/session.py b/python/tvm/runtime/disco/session.py
index 4e4d030a62..ed4ce06a37 100644
--- a/python/tvm/runtime/disco/session.py
+++ b/python/tvm/runtime/disco/session.py
@@ -28,8 +28,8 @@ import numpy as np
from tvm_ffi import get_global_func, register_func, register_object
from ..device import Device
from ..container import ShapeTuple
-from ..ndarray import NDArray
-from ..ndarray import array as _as_NDArray
+from .._tensor import Tensor
+from .._tensor import tensor as _as_Tensor
from ..object import Object
from . import _ffi_api, process_pool # pylint: disable=unused-import
@@ -58,20 +58,20 @@ class DRef(Object):
def debug_copy_from(
self,
worker_id: int,
- value: Union[np.ndarray, NDArray],
+ value: Union[np.ndarray, Tensor],
) -> None:
- """Copy an NDArray value to remote for debugging purposes.
+ """Copy an Tensor value to remote for debugging purposes.
Parameters
----------
worker_id : int
The id of the worker to be copied to.
- value : Union[numpy.ndarray, NDArray]
+ value : Union[numpy.ndarray, Tensor]
The value to be copied.
"""
- if not isinstance(value, NDArray):
- value = _as_NDArray(value)
+ if not isinstance(value, Tensor):
+ value = _as_Tensor(value)
return _ffi_api.DRefDebugCopyFrom(self, worker_id, value) # type: ignore # pylint: disable=no-member
@@ -122,18 +122,18 @@ class Session(Object):
worker0_only: bool = False,
in_group: bool = True,
) -> DRef:
- """Create an empty NDArray on all workers and attach them to a DRef.
+ """Create an empty Tensor on all workers and attach them to a DRef.
Parameters
----------
shape : tuple of int
- The shape of the NDArray.
+ The shape of the Tensor.
dtype : str
- The data type of the NDArray.
+ The data type of the Tensor.
device : Optional[Device] = None
- The device of the NDArray.
+ The device of the Tensor.
worker0_only: bool
If False (default), allocate an array on each worker. If
@@ -147,7 +147,7 @@ class Session(Object):
Returns
-------
array : DRef
- The created NDArray.
+ The created Tensor.
"""
func = self._get_cached_method("runtime.disco.empty")
@@ -217,7 +217,7 @@ class Session(Object):
Notes
-----
Examples of unsupported types:
- - NDArray, DLTensor,;
+ - Tensor, DLTensor,;
- TVM Objects, including PackedFunc, Module and String.
"""
return _ffi_api.SessionCallPacked(self, 0, 0, func, *args) # type: ignore # pylint: disable=no-member
@@ -246,29 +246,29 @@ class Session(Object):
executing all the existing instructions."""
return self._sync_worker(0)
- def copy_from_worker_0(self, host_array: NDArray, remote_array: DRef) -> None:
- """Copy an NDArray from worker-0 to the controller-side NDArray.
+ def copy_from_worker_0(self, host_array: Tensor, remote_array: DRef) -> None:
+ """Copy an Tensor from worker-0 to the controller-side Tensor.
Parameters
----------
host_array : numpy.ndarray
The array to be copied to worker-0.
- remote_array : NDArray
- The NDArray on worker-0.
+ remote_array : Tensor
+ The Tensor on worker-0.
"""
return _ffi_api.SessionCopyFromWorker0(self, host_array, remote_array) # type: ignore # pylint: disable=no-member
- def copy_to_worker_0(self, host_array: NDArray, remote_array: Optional[DRef] = None) -> DRef:
- """Copy the controller-side NDArray to worker-0.
+ def copy_to_worker_0(self, host_array: Tensor, remote_array: Optional[DRef] = None) -> DRef:
+ """Copy the controller-side Tensor to worker-0.
Parameters
----------
- host_array : NDArray
+ host_array : Tensor
The array to be copied to worker-0.
remote_array : Optiona[DRef]
- The destination NDArray on worker-0.
+ The destination Tensor on worker-0.
Returns
-------
@@ -329,7 +329,7 @@ class Session(Object):
def broadcast(
self,
- src: Union[np.ndarray, NDArray],
+ src: Union[np.ndarray, Tensor],
dst: Optional[DRef] = None,
in_group: bool = True,
) -> DRef:
@@ -337,7 +337,7 @@ class Session(Object):
Parameters
----------
- src: Union[np.ndarray, NDArray]
+ src: Union[np.ndarray, Tensor]
The array to be broadcasted.
dst: Optional[DRef]
@@ -356,8 +356,8 @@ class Session(Object):
`dst`. Otherwise, it is the newly allocated space.
"""
- if not isinstance(src, NDArray):
- src = _as_NDArray(src)
+ if not isinstance(src, Tensor):
+ src = _as_Tensor(src)
if dst is None:
dst = self.empty(src.shape, src.dtype)
@@ -372,7 +372,7 @@ class Session(Object):
Parameters
----------
- src: Union[np.ndarray, NDArray]
+ src: Union[np.ndarray, Tensor]
The array to be broadcasted.
dst: Optional[DRef]
@@ -387,7 +387,7 @@ class Session(Object):
def scatter(
self,
- src: Union[np.ndarray, NDArray],
+ src: Union[np.ndarray, Tensor],
dst: Optional[DRef] = None,
in_group: bool = True,
) -> DRef:
@@ -395,7 +395,7 @@ class Session(Object):
Parameters
----------
- src: Union[np.ndarray, NDArray]
+ src: Union[np.ndarray, Tensor]
The array to be scattered. The first dimension of this
array, `src.shape[0]`, must be equal to the number of
workers.
@@ -419,8 +419,8 @@ class Session(Object):
"""
assert src.shape[0] == self.num_workers
- if not isinstance(src, NDArray):
- src = _as_NDArray(src)
+ if not isinstance(src, Tensor):
+ src = _as_Tensor(src)
if dst is None:
dst = self.empty(src.shape[1:], src.dtype)
@@ -435,7 +435,7 @@ class Session(Object):
Parameters
----------
- src: Union[np.ndarray, NDArray]
+ src: Union[np.ndarray, Tensor]
The array to be scattered. The first dimension of this
array, `src.shape[0]`, must be equal to the number of
workers.
diff --git a/python/tvm/runtime/executable.py b/python/tvm/runtime/executable.py
index 47c46959be..a57c1b6231 100644
--- a/python/tvm/runtime/executable.py
+++ b/python/tvm/runtime/executable.py
@@ -39,7 +39,7 @@ class Executable:
def __call__(self, *args, **kwargs) -> Any:
"""Call the executable."""
- return self.jit().entry_func(*args, **kwargs)
+ return self.jit().main(*args, **kwargs)
def jit(
self,
diff --git a/python/tvm/runtime/params.py b/python/tvm/runtime/params.py
index af0b4a2617..f1ea7bda24 100644
--- a/python/tvm/runtime/params.py
+++ b/python/tvm/runtime/params.py
@@ -16,15 +16,15 @@
# under the License.
# pylint: disable=invalid-name
"""Helper utility to save and load parameter dicts."""
-from . import _ffi_api, ndarray, NDArray
+from . import _ffi_api, tensor, Tensor
-def _to_ndarray(params):
+def _to_tensor(params):
transformed = {}
for k, v in params.items():
- if not isinstance(v, NDArray):
- transformed[k] = ndarray.array(v)
+ if not isinstance(v, Tensor):
+ transformed[k] = tensor(v)
else:
transformed[k] = v
@@ -39,7 +39,7 @@ def save_param_dict(params):
Parameters
----------
- params : dict of str to NDArray
+ params : dict of str to Tensor
The parameter dictionary.
Returns
@@ -59,7 +59,7 @@ def save_param_dict(params):
# Pass in byte array to module to directly set parameters
tvm.runtime.load_param_dict(param_bytes)
"""
- return _ffi_api.SaveParams(_to_ndarray(params))
+ return _ffi_api.SaveParams(_to_tensor(params))
def save_param_dict_to_file(params, path):
@@ -67,13 +67,13 @@ def save_param_dict_to_file(params, path):
Parameters
----------
- params : dict of str to NDArray
+ params : dict of str to Tensor
The parameter dictionary.
path: str
The path to the parameter file.
"""
- return _ffi_api.SaveParamsToFile(_to_ndarray(params), path)
+ return _ffi_api.SaveParamsToFile(_to_tensor(params), path)
def load_param_dict(param_bytes):
@@ -86,7 +86,7 @@ def load_param_dict(param_bytes):
Returns
-------
- params : dict of str to NDArray
+ params : dict of str to Tensor
The parameter dictionary.
"""
if isinstance(param_bytes, (bytes, str)):
@@ -104,7 +104,7 @@ def load_param_dict_from_file(path):
Returns
-------
- params : dict of str to NDArray
+ params : dict of str to Tensor
The parameter dictionary.
"""
return _ffi_api.LoadParamsFromFile(path)
diff --git a/python/tvm/runtime/vm.py b/python/tvm/runtime/vm.py
index a955835573..72fb133788 100644
--- a/python/tvm/runtime/vm.py
+++ b/python/tvm/runtime/vm.py
@@ -134,7 +134,7 @@ class VirtualMachine(object):
closure : Object
The VMClosure Object.
- args : list[tvm.runtime.NDArray] or list[np.ndarray]
+ args : list[tvm.runtime.Tensor] or list[np.ndarray]
The arguments to the closure.
Returns
@@ -206,9 +206,9 @@ class VirtualMachine(object):
if isinstance(arg, Object):
cargs.append(arg)
elif isinstance(arg, np.ndarray):
- nd_arr = tvm.nd.array(arg, device=tvm.cpu(0))
+ nd_arr = tvm.runtime.tensor(arg, device=tvm.cpu(0))
cargs.append(nd_arr)
- elif isinstance(arg, tvm.runtime.NDArray):
+ elif isinstance(arg, tvm.runtime.Tensor):
cargs.append(arg)
elif isinstance(arg, (tuple, list)):
field_args: List[Any] = []
@@ -217,7 +217,7 @@ class VirtualMachine(object):
cargs.append(tuple(field_args))
elif isinstance(arg, (Number, bool)):
dtype = _gettype(arg)
- value = tvm.nd.array(np.array(arg, dtype=dtype), device=tvm.cpu(0))
+ value = tvm.runtime.tensor(np.array(arg, dtype=dtype), device=tvm.cpu(0))
cargs.append(value)
elif isinstance(arg, str):
cargs.append(arg)
@@ -252,7 +252,7 @@ class VirtualMachine(object):
def set_input(self, func_name: str, *args: Any, **kwargs: Any) -> None:
"""Set the inputs to a function.
- This interface works when using VM over RPC by internally converting NDArray in
+ This interface works when using VM over RPC by internally converting Tensor in
the arguments to DLTensor, which is supported in RPC where remote could only
have a minimal C runtime.
@@ -263,9 +263,9 @@ class VirtualMachine(object):
----------
func_name : str
The name of the function.
- args: List[tvm.runtime.NDArray] or List[np.ndarray]
+ args: List[tvm.runtime.Tensor] or List[np.ndarray]
The arguments to the function.
- kwargs: dict of str to tvm.runtime.NDArray or np.ndarray
+ kwargs: dict of str to tvm.runtime.Tensor or np.ndarray
Named arguments to the function.
"""
cargs: List[Any] = []
@@ -482,7 +482,7 @@ class VirtualMachine(object):
func_name : str
The name of the function.
- args: List of NDArray or other objects supported by PackedFunc.
+ args: List of Tensor or other objects supported by PackedFunc.
The arguments to the function.
Returns
diff --git a/python/tvm/script/ir_builder/relax/distributed/ir.py b/python/tvm/script/ir_builder/relax/distributed/ir.py
index 159ad5aea1..e097b64304 100644
--- a/python/tvm/script/ir_builder/relax/distributed/ir.py
+++ b/python/tvm/script/ir_builder/relax/distributed/ir.py
@@ -29,7 +29,7 @@ from tvm.relax.expr import Tuple as RxTuple
from tvm.relax.distributed import DTensorStructInfo
from tvm.relax.utils import args_converter
from tvm import base as _base
-from tvm.runtime import ndarray as _nd
+from tvm.runtime import _tensor
from tvm.relax.op.distributed import (
redistribute as _redistribute,
annotate_sharding as _annotate_sharding,
@@ -89,14 +89,14 @@ def call_tir(
def const(
- value: Union[bool, int, float, _np.ndarray, tvm.nd.NDArray],
+ value: Union[bool, int, float, _np.ndarray, tvm.runtime.Tensor],
struct_info: DTensorStructInfo,
) -> Constant:
"""Create a constant value.
Parameters
----------
- value: Union[bool, int, float, numpy.ndarray, tvm.nd.NDArray]
+ value: Union[bool, int, float, numpy.ndarray, tvm.runtime.Tensor]
The constant value.
dtype: Optional[str]
@@ -121,10 +121,10 @@ def const(
if isinstance(value, (_np.ndarray, _np.generic)):
if dtype is not None:
value = value.astype(dtype)
- value = _nd.array(value)
+ value = _tensor.array(value)
- if not isinstance(value, _nd.NDArray):
- raise ValueError("value has to be scalar or NDArray")
+ if not isinstance(value, _tensor.Tensor):
+ raise ValueError("value has to be scalar or Tensor")
return Constant(value, struct_info)
diff --git a/python/tvm/script/ir_builder/relax/ir.py b/python/tvm/script/ir_builder/relax/ir.py
index e61e563b70..f045508bfc 100644
--- a/python/tvm/script/ir_builder/relax/ir.py
+++ b/python/tvm/script/ir_builder/relax/ir.py
@@ -192,7 +192,7 @@ from tvm.relax.struct_info import StructInfo
from tvm.relax.utils import args_converter, gen_call_tir_inputs
from tvm.runtime import Object as tvm_Object
from tvm.runtime import ObjectGeneric
-from tvm.runtime.ndarray import (
+from tvm.runtime._tensor import (
cpu,
cuda,
device,
diff --git a/python/tvm/script/ir_builder/tir/ir.py b/python/tvm/script/ir_builder/tir/ir.py
index c6549ad104..ed41ac9bfb 100644
--- a/python/tvm/script/ir_builder/tir/ir.py
+++ b/python/tvm/script/ir_builder/tir/ir.py
@@ -32,7 +32,7 @@ import numpy as np # type: ignore
from tvm import ir, tir
from tvm.ir import Type
from tvm.ir.base import deprecated
-from tvm.runtime import String, convert, ndarray
+from tvm.runtime import String, convert, tensor
from tvm.target import Target
# pylint: disable=unused-import
@@ -1054,7 +1054,7 @@ def allocate_const(
np_data = np_data.reshape(extents)
return _ffi_api.AllocateConst( # type: ignore[attr-defined] # pylint: disable=no-member
- ndarray.array(np_data), dtype, extents, annotations
+ tensor(np_data), dtype, extents, annotations
)
diff --git a/python/tvm/target/detect_target.py b/python/tvm/target/detect_target.py
index 689825cbe1..1743e929ce 100644
--- a/python/tvm/target/detect_target.py
+++ b/python/tvm/target/detect_target.py
@@ -19,7 +19,7 @@ from typing import Union
from tvm_ffi import get_global_func
from ..runtime import Device
-from ..runtime.ndarray import device
+from ..runtime.tensor import device
from . import Target
diff --git a/python/tvm/te/operation.py b/python/tvm/te/operation.py
index c3634d3b0a..91d3e2b81c 100644
--- a/python/tvm/te/operation.py
+++ b/python/tvm/te/operation.py
@@ -452,7 +452,7 @@ def const(value, dtype="int32", span=None):
Parameters
----------
- value : Union[bool, int, float, numpy.ndarray, tvm.nd.NDArray]
+ value : Union[bool, int, float, numpy.ndarray, tvm.runtime.Tensor]
The constant value.
dtype : str
diff --git a/python/tvm/testing/runner.py b/python/tvm/testing/runner.py
index a4615f7a46..f2625b28f9 100644
--- a/python/tvm/testing/runner.py
+++ b/python/tvm/testing/runner.py
@@ -24,7 +24,7 @@ if TYPE_CHECKING:
import numpy as np
from tvm.meta_schedule.runner import EvaluatorConfig, RPCConfig
- from tvm.runtime import Device, Module, NDArray
+ from tvm.runtime import Device, Module, Tensor
# pylint: disable=import-outside-toplevel,protected-access
@@ -32,11 +32,11 @@ if TYPE_CHECKING:
def _args_to_device(args, device):
import numpy as np
- from tvm.runtime.ndarray import NDArray, empty
+ from tvm.runtime.tensor import Tensor, empty
uploaded_args = []
for arg in args:
- if isinstance(arg, (np.ndarray, NDArray)):
+ if isinstance(arg, (np.ndarray, Tensor)):
uploaded_args.append(empty(arg.shape, dtype=arg.dtype, device=device).copyfrom(arg))
elif isinstance(arg, (int, float)):
uploaded_args.append(arg)
@@ -46,11 +46,11 @@ def _args_to_device(args, device):
def _args_to_numpy(args):
- from tvm.runtime.ndarray import NDArray
+ from tvm.runtime.tensor import Tensor
downloaded_args = []
for arg in args:
- if isinstance(arg, NDArray):
+ if isinstance(arg, Tensor):
downloaded_args.append(arg.numpy())
else:
downloaded_args.append(arg)
@@ -80,7 +80,7 @@ def _normalize_export_func(export_func, output_format) -> Tuple[Callable, str]:
def local_run( # pylint: disable=too-many-arguments,too-many-locals
mod: "Module",
device_type: str,
- args: List[Union["np.ndarray", "NDArray", int, float]],
+ args: List[Union["np.ndarray", "Tensor", int, float]],
evaluator_config: Optional["EvaluatorConfig"] = None,
export_func: Union[Callable[["Module", str], None], Literal["tar", "ndk"]] = "tar",
output_format: Optional[str] = None,
@@ -93,7 +93,7 @@ def local_run( # pylint: disable=too-many-arguments,too-many-locals
The TVM module to run.
device_type : str
The device type to run the module on.
- args : List[Union[np.ndarray, NDArray, int, float]]
+ args : List[Union[np.ndarray, Tensor, int, float]]
The arguments to be fed to the module.
evaluator_config : Optional[EvaluatorConfig]
The evaluator configuration to use.
@@ -109,7 +109,7 @@ def local_run( # pylint: disable=too-many-arguments,too-many-locals
Returns
-------
- args : List[Union[np.ndarray, NDArray, int, float]]
+ args : List[Union[np.ndarray, Tensor, int, float]]
The results of running the module.
profile_result : tvm.runtime.BenchmarkResult
The profiling result of running the module.
@@ -152,7 +152,7 @@ def local_run( # pylint: disable=too-many-arguments,too-many-locals
def rpc_run( # pylint: disable=too-many-arguments,too-many-locals
mod: "Module",
device_type: str,
- args: List[Union["np.ndarray", "NDArray", int, float]],
+ args: List[Union["np.ndarray", "Tensor", int, float]],
evaluator_config: Optional["EvaluatorConfig"] = None,
rpc_config: Optional["RPCConfig"] = None,
export_func: Union[Callable[["Module", str], None], Literal["tar", "ndk"]] = "tar",
@@ -166,7 +166,7 @@ def rpc_run( # pylint: disable=too-many-arguments,too-many-locals
The TVM module to run.
device_type : str
The device type to run the module on.
- args : List[Union[np.ndarray, NDArray, int, float]]
+ args : List[Union[np.ndarray, Tensor, int, float]]
The arguments to be fed to the module.
evaluator_config : Optional[EvaluatorConfig]
The evaluator configuration to use.
@@ -189,7 +189,7 @@ def rpc_run( # pylint: disable=too-many-arguments,too-many-locals
Returns
-------
- args : List[Union[np.ndarray, NDArray, int, float]]
+ args : List[Union[np.ndarray, Tensor, int, float]]
The results of running the module.
profile_result : tvm.runtime.BenchmarkResult
The profiling result of running the module.
diff --git a/python/tvm/testing/utils.py b/python/tvm/testing/utils.py
index fcc452b6b4..da22cf7746 100644
--- a/python/tvm/testing/utils.py
+++ b/python/tvm/testing/utils.py
@@ -324,7 +324,7 @@ def check_bool_expr_is_true(bool_expr, vranges, cond=None):
return tvm.tir.stmt_functor.substitute(expr, vmap)
A = tvm.te.compute([r.extent.value for v, r in vranges.items()], _compute_body)
- args = [tvm.nd.empty(A.shape, A.dtype)]
+ args = [tvm.runtime.empty(A.shape, A.dtype)]
mod = tvm.compile(tvm.IRModule.from_expr(tvm.te.create_prim_func([A])))
mod(*args)
return args[0].numpy()
diff --git a/python/tvm/tir/build.py b/python/tvm/tir/build.py
index 98e549cc9c..beccb65b63 100644
--- a/python/tvm/tir/build.py
+++ b/python/tvm/tir/build.py
@@ -22,7 +22,6 @@ from typing import Dict, Optional, Tuple, Union
import tvm
from tvm import ir
from tvm.ir.module import IRModule
-from tvm.runtime import ndarray
from tvm.target import Target
from tvm.tir import PrimFunc
@@ -206,7 +205,7 @@ def build(
if target is not None:
if target.host is not None:
target_host = target.host
- elif ndarray.device(target.kind.name, 0).device_type == ndarray.cpu(0).device_type:
+ elif tvm.device(target.kind.name, 0).device_type == tvm.cpu(0).device_type:
target_host = target
target_host = Target.canon_target(target_host)
target_to_bind = target_to_bind.with_host(target_host)
diff --git a/python/tvm/tir/function.py b/python/tvm/tir/function.py
index 750a9118ab..5b365e124c 100644
--- a/python/tvm/tir/function.py
+++ b/python/tvm/tir/function.py
@@ -28,7 +28,7 @@ import tvm.runtime
from tvm.ir import BaseFunc, Range
from tvm.runtime import Object, Scriptable
-from ..runtime.ndarray import NDArray
+from ..runtime._tensor import Tensor
from . import _ffi_api
from .buffer import Buffer
from .expr import PrimExpr, Var
@@ -490,20 +490,20 @@ class IndexMap(Object):
"""
return _ffi_api.IndexMapMapShape(self, shape)
- def map_ndarray(self, arr_src: NDArray) -> NDArray:
- """Apply thie index map to transform the layout of the input NDArray
+ def map_tensor(self, arr_src: Tensor) -> Tensor:
+ """Apply thie index map to transform the layout of the input Tensor
Parameters
----------
- arr_src : runtime.NDArray
- The NDArray to be transformed
+ arr_src : runtime.Tensor
+ The Tensor to be transformed
Returns
-------
- arr_dst : runtime.NDArray
- The transformed NDArray
+ arr_dst : runtime.Tensor
+ The transformed Tensor
"""
- return _ffi_api.IndexMapMapNDArray(self, arr_src)
+ return _ffi_api.IndexMapMapTensor(self, arr_src)
def inverse(self, shape: List[Union[Range, PrimExpr]]) -> "IndexMap":
"""Return the inverse of the map
diff --git a/python/tvm/tir/op.py b/python/tvm/tir/op.py
index ffd9aeff88..d706a1a150 100644
--- a/python/tvm/tir/op.py
+++ b/python/tvm/tir/op.py
@@ -51,7 +51,7 @@ def call_packed_lowered(*args, span=None):
The argument is the corresponding POD type when Expr is presented.
When the argument is Buffer, the corresponding PackedFunc
will recieve an TVMArrayHandle whose content is valid during the callback period.
- If the PackedFunc is a python callback, then the corresponding argument is NDArray.
+ If the PackedFunc is a python callback, then the corresponding argument is Tensor.
Parameters
----------
@@ -108,7 +108,7 @@ def call_packed(*args, span=None):
When the argument is Buffer, the corresponding PackedFunc
will receive an TVMArrayHandle whose content is valid during the callback period.
- If the PackedFunc is a python callback, then the corresponding argument is NDArray.
+ If the PackedFunc is a python callback, then the corresponding argument is Tensor.
Parameters
----------
@@ -356,7 +356,7 @@ def tvm_stack_make_shape(*args):
def tvm_stack_make_array(data, shape, strides, ndim, arr_dtype, elem_offset):
- """Allocate a NDArray(DLTensor) on stack, return the handle
+ """Allocate a Tensor(DLTensor) on stack, return the handle
Parameters
----------
diff --git a/python/tvm/tir/stmt.py b/python/tvm/tir/stmt.py
index ed934183a5..bd90d52574 100644
--- a/python/tvm/tir/stmt.py
+++ b/python/tvm/tir/stmt.py
@@ -31,7 +31,7 @@ from typing import List, Mapping, Optional, Union
import tvm_ffi
from tvm.ir import PrimExpr, Range, Span
-from tvm.runtime import Object, Scriptable, const, NDArray
+from tvm.runtime import Object, Scriptable, const, Tensor
from . import _ffi_api
from .buffer import Buffer
@@ -368,8 +368,8 @@ class AllocateConst(Stmt):
extents : list of Expr
The extents of the allocate
- data_or_idx : Union[NDArray, int]
- If an NDArray, this is the const data associated with the
+ data_or_idx : Union[Tensor, int]
+ If an Tensor, this is the const data associated with the
constant. If an integer, this is the index into the
"constants" attribute of the `IRModule` that contains the
`AllocateConst`.
@@ -387,7 +387,7 @@ class AllocateConst(Stmt):
buffer_var: Var
dtype: str
extents: List[PrimExpr]
- data: Optional[NDArray]
+ data: Optional[Tensor]
irmod_storage_idx: Optional[int]
body: Stmt
annotations: Mapping[str, Object]
@@ -398,7 +398,7 @@ class AllocateConst(Stmt):
buffer_var: Var,
dtype: str,
extents: List[PrimExpr],
- data_or_idx: Union[NDArray, int],
+ data_or_idx: Union[Tensor, int],
body: Stmt,
annotations: Optional[Mapping[str, Object]] = None,
span: Optional[Span] = None,
diff --git a/python/tvm/tir/transform/transform.py b/python/tvm/tir/transform/transform.py
index 93a182ca3b..bf02529194 100644
--- a/python/tvm/tir/transform/transform.py
+++ b/python/tvm/tir/transform/transform.py
@@ -373,7 +373,7 @@ def MakePackedAPI():
For static shapes, the `BufferNode::shape`, `BufferNode::strides`,
and `BufferNode::elem_offset` member variables are used to
generate runtime checks on the corresponding member variables in
- the user-provided `DLTensor*` or `tvm.nd.array` argument. (e.g. A
+ the user-provided `DLTensor*` or `tvm.runtime.tensor` argument. (e.g. A
PrimFunc that accepts a buffer of shape `[16,32]` validates that
the `DLTensor::shape` array is `[16,32]`.)
@@ -1052,26 +1052,26 @@ def InjectPTXAsyncCopy():
return _ffi_api.InjectPTXAsyncCopy() # type: ignore
-def RemoveWeightLayoutRewriteBlock(skip_ndarray_rewrite=False):
+def RemoveWeightLayoutRewriteBlock(skip_tensor_rewrite=False):
"""Remove weight layout rewrite block before benchmarking during tuning stage.
Parameters
----------
- skip_ndarray_rewrite : bool
- If True, exact rewrite of NDArray, according to the given index map, will be skipped.
- Only the shape of the NDArray is transformed correctly, and the content of the destination
+ skip_tensor_rewrite : bool
+ If True, exact rewrite of Tensor, according to the given index map, will be skipped.
+ Only the shape of the Tensor is transformed correctly, and the content of the destination
array will be filled with random values.
- When this pass is called many times during MetaSchedule tuning, the raw data of NDArray,
- before and after rewrite, does not matter. Since NDArray layout rewrite, using IndexMap's
- MapNDArray, is currently slow, skipping the exact rewrite is sometimes necessary.
+ When this pass is called many times during MetaSchedule tuning, the raw data of Tensor,
+ before and after rewrite, does not matter. Since Tensor layout rewrite, using IndexMap's
+ MapTensor, is currently slow, skipping the exact rewrite is sometimes necessary.
Returns
-------
fpass : tvm.transform.Pass
The result pass
"""
- return _ffi_api.RemoveWeightLayoutRewriteBlock(skip_ndarray_rewrite) # type: ignore
+ return _ffi_api.RemoveWeightLayoutRewriteBlock(skip_tensor_rewrite) # type: ignore
def ManifestSharedMemoryLocalStage():
diff --git a/python/tvm/topi/sort.py b/python/tvm/topi/sort.py
index f75e5db4b9..1ee2964ae9 100644
--- a/python/tvm/topi/sort.py
+++ b/python/tvm/topi/sort.py
@@ -105,8 +105,8 @@ def argsort(data, valid_count=None, axis=-1, is_ascend=1, dtype="float32"):
s = topi.generic.schedule_argsort(out)
f = tvm.compile(s, [data, out], "llvm")
dev = tvm.cpu()
- tvm_data = tvm.nd.array(np_data, dev)
- tvm_out = tvm.nd.array(np.zeros(dshape, dtype=data.dtype), dev)
+ tvm_data = tvm.runtime.tensor(np_data, dev)
+ tvm_out = tvm.runtime.tensor(np.zeros(dshape, dtype=data.dtype), dev)
f(tvm_data, tvm_out)
"""
data_buf = tvm.tir.decl_buffer(data.shape, data.dtype, "data_buf", data_alignment=8)
diff --git a/python/tvm/topi/transform.py b/python/tvm/topi/transform.py
index 98cec99a09..db09aed05a 100644
--- a/python/tvm/topi/transform.py
+++ b/python/tvm/topi/transform.py
@@ -736,7 +736,7 @@ def sequence_mask(data, valid_length, mask_value=0, axis=0):
return cpp.sequence_mask(data, valid_length, mask_value, axis)
-def ndarray_size(array, dtype="int32"):
+def tensor_size(array, dtype="int32"):
"""Get the number of elements of input array
Parameters
@@ -752,7 +752,7 @@ def ndarray_size(array, dtype="int32"):
result : tvm.te.Tensor
The resulting tensor.
"""
- return cpp.ndarray_size(array, dtype)
+ return cpp.tensor_size(array, dtype)
def where(condition, x, y):
diff --git a/src/contrib/msc/core/ir/graph_builder.cc b/src/contrib/msc/core/ir/graph_builder.cc
index 7f84978105..00176fb2ca 100644
--- a/src/contrib/msc/core/ir/graph_builder.cc
+++ b/src/contrib/msc/core/ir/graph_builder.cc
@@ -34,7 +34,7 @@ namespace msc {
using namespace tvm::relax;
-const std::string GetScalarStr(const runtime::NDArray& data, int float_precision) {
+const std::string GetScalarStr(const runtime::Tensor& data, int float_precision) {
std::string scalar_str;
if (data->dtype.code == kDLFloat) {
const float val = ExprUtils::GetScalar<float>(data);
@@ -809,7 +809,7 @@ Array<Expr> GraphBuilder::GetPluginInputs(const Expr& expr) {
return Downcast<relax::Tuple>(call->args[1])->fields;
}
-Map<MSCTensor, NDArray> WeightsExtractor::GetWeights(const Function& func) {
+Map<MSCTensor, Tensor> WeightsExtractor::GetWeights(const Function& func) {
VisitExpr(func);
return weights_;
}
@@ -849,7 +849,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
return builder.Build(func);
})
.def("msc.core.GetRelaxWeights",
- [](const IRModule& module, const String& entry_name) -> Map<MSCTensor, NDArray> {
+ [](const IRModule& module, const String& entry_name) -> Map<MSCTensor, Tensor> {
const auto& func = Downcast<Function>(module->Lookup(entry_name));
return WeightsExtractor(module).GetWeights(func);
});
diff --git a/src/contrib/msc/core/ir/graph_builder.h b/src/contrib/msc/core/ir/graph_builder.h
index 401c452d95..79c4048304 100644
--- a/src/contrib/msc/core/ir/graph_builder.h
+++ b/src/contrib/msc/core/ir/graph_builder.h
@@ -28,7 +28,7 @@
#include <tvm/ffi/reflection/registry.h>
#include <tvm/relax/expr.h>
#include <tvm/relax/expr_functor.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <tvm/tir/data_layout.h>
#include <set>
@@ -50,7 +50,7 @@ namespace msc {
using namespace tvm::relax;
using Expr = tvm::RelaxExpr;
-using tvm::runtime::NDArray;
+using tvm::runtime::Tensor;
/*!
* \brief Config for building MSCGraph.
@@ -358,14 +358,14 @@ class WeightsExtractor : public ExprVisitor {
}
/*! \brief Visit the constant and save weights */
- Map<MSCTensor, NDArray> GetWeights(const Function& func);
+ Map<MSCTensor, Tensor> GetWeights(const Function& func);
void VisitExpr_(const ConstantNode* op) final;
void VisitExpr_(const CallNode* op) final;
private:
- Map<MSCTensor, NDArray> weights_;
+ Map<MSCTensor, Tensor> weights_;
Map<Expr, Function> local_funcs_;
IRModule ref_module_;
};
diff --git a/src/contrib/msc/core/transform/bind_named_params.cc b/src/contrib/msc/core/transform/bind_named_params.cc
index df534f4cfa..dec4616f5e 100644
--- a/src/contrib/msc/core/transform/bind_named_params.cc
+++ b/src/contrib/msc/core/transform/bind_named_params.cc
@@ -83,7 +83,7 @@ std::tuple<Map<Var, Expr>, Map<tir::Var, PrimExpr>> NormalizeNamedBindings(
auto normalize_value = [&](Var key, ffi::Any obj) -> relax::Expr {
if (auto opt = obj.as<relax::Expr>()) {
return opt.value();
- } else if (auto opt = obj.as<runtime::NDArray>()) {
+ } else if (auto opt = obj.as<runtime::Tensor>()) {
const auto& span = SpanUtils::CreateWithAttr(msc_attr::kName, key->name_hint());
return Constant(opt.value(), StructInfo(), span);
} else {
diff --git a/src/contrib/msc/core/transform/rewrite_utils.cc b/src/contrib/msc/core/transform/rewrite_utils.cc
index 9cbc7c1a8c..c88cad3e64 100644
--- a/src/contrib/msc/core/transform/rewrite_utils.cc
+++ b/src/contrib/msc/core/transform/rewrite_utils.cc
@@ -42,7 +42,7 @@ Var RewriteUtils::MakeCall(BlockBuilder builder, const String& name, Expr op, Ar
Expr RewriteUtils::MakeConstant(BlockBuilder builder, const String& name, double value,
const DataType& dtype, size_t ndim) {
- const auto& data = support::FloatImmToNDArray(FloatImm(dtype, value));
+ const auto& data = support::FloatImmToTensor(FloatImm(dtype, value));
Span span = SpanUtils::CreateWithAttr(msc_attr::kName, name);
const auto& constant = Constant(data, std::nullopt, span);
if (ndim == 0) {
diff --git a/src/contrib/msc/core/utils.h b/src/contrib/msc/core/utils.h
index aeb7f9eb88..19ad0020e5 100644
--- a/src/contrib/msc/core/utils.h
+++ b/src/contrib/msc/core/utils.h
@@ -325,7 +325,7 @@ class ExprUtils {
* \return The scalar value.
*/
template <typename T>
- TVM_DLL static const T GetScalar(const runtime::NDArray& array, size_t i = 0) {
+ TVM_DLL static const T GetScalar(const runtime::Tensor& array, size_t i = 0) {
if (array->dtype.code == kDLInt) {
if (array->dtype.bits == 8) {
return T(reinterpret_cast<int8_t*>(array->data)[i]);
diff --git a/src/contrib/msc/framework/tensorflow/codegen.cc b/src/contrib/msc/framework/tensorflow/codegen.cc
index 1a5bdfeacb..6a77440b72 100644
--- a/src/contrib/msc/framework/tensorflow/codegen.cc
+++ b/src/contrib/msc/framework/tensorflow/codegen.cc
@@ -40,7 +40,7 @@ void TensorflowCodeGen::CodeGenHelper() {
.func_arg("name", "str")
.func_arg("shape", "List[int]")
.func_arg("dtype", "str")
- .func_arg("weights", "Dict[str, tvm.nd.array]")
+ .func_arg("weights", "Dict[str, tvm.runtime.Tensor]")
.func_start()
.cond_if("name in weights")
.func_call("tf_v1.get_variable", "var")
@@ -63,7 +63,7 @@ void TensorflowCodeGen::CodeGenGraph() {
const auto& pair = graph()->FindProducerAndIdx(i);
stack_.func_arg(IdxOutputBase(pair.first, pair.second), "tf_v1.Tensor");
}
- stack_.func_arg("weights", "Dict[str, tvm.nd.array]").func_start();
+ stack_.func_arg("weights", "Dict[str, tvm.runtime.Tensor]").func_start();
// define weights
stack_.comment("Define the weights");
for (const auto& n : graph()->node_names) {
diff --git a/src/meta_schedule/arg_info.cc b/src/meta_schedule/arg_info.cc
index 9c2ba084ad..12c6e29eb2 100644
--- a/src/meta_schedule/arg_info.cc
+++ b/src/meta_schedule/arg_info.cc
@@ -105,7 +105,7 @@ Array<ArgInfo> ArgInfo::FromPrimFunc(const tir::PrimFunc& func) {
Array<ArgInfo> ArgInfo::FromEntryFunc(const IRModule& mod, bool remove_preproc) {
if (remove_preproc) {
IRModule new_mod =
- tir::transform::RemoveWeightLayoutRewriteBlock(/*skip_ndarray_rewrite*/ true)(mod);
+ tir::transform::RemoveWeightLayoutRewriteBlock(/*skip_tensor_rewrite*/ true)(mod);
return ArgInfo::FromPrimFunc(FindEntryFunc(new_mod));
}
return ArgInfo::FromPrimFunc(FindEntryFunc(mod));
diff --git a/src/meta_schedule/builder/builder.cc b/src/meta_schedule/builder/builder.cc
index 062e32e58e..5657a362ac 100644
--- a/src/meta_schedule/builder/builder.cc
+++ b/src/meta_schedule/builder/builder.cc
@@ -26,7 +26,7 @@ namespace meta_schedule {
/******** Constructors ********/
BuilderInput::BuilderInput(IRModule mod, Target target,
- Optional<Map<String, runtime::NDArray>> params) {
+ Optional<Map<String, runtime::Tensor>> params) {
ObjectPtr<BuilderInputNode> n = make_object<BuilderInputNode>();
n->mod = std::move(mod);
n->target = std::move(target);
@@ -59,7 +59,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
namespace refl = tvm::ffi::reflection;
refl::GlobalDef()
.def("meta_schedule.BuilderInput",
- [](IRModule mod, Target target, Optional<Map<String, runtime::NDArray>> params)
+ [](IRModule mod, Target target, Optional<Map<String, runtime::Tensor>> params)
-> BuilderInput { return BuilderInput(mod, target, params); })
.def("meta_schedule.BuilderResult",
[](Optional<String> artifact_path, Optional<String> error_msg) -> BuilderResult {
diff --git a/src/meta_schedule/feature_extractor/feature_extractor.cc b/src/meta_schedule/feature_extractor/feature_extractor.cc
index 1f0668a849..e2fa1fc176 100644
--- a/src/meta_schedule/feature_extractor/feature_extractor.cc
+++ b/src/meta_schedule/feature_extractor/feature_extractor.cc
@@ -23,7 +23,7 @@
namespace tvm {
namespace meta_schedule {
-Array<tvm::runtime::NDArray> PyFeatureExtractorNode::ExtractFrom(
+Array<tvm::runtime::Tensor> PyFeatureExtractorNode::ExtractFrom(
const TuneContext& context, const Array<MeasureCandidate>& candidates) {
ICHECK(f_extract_from != nullptr) << "PyFeatureExtractor's ExtractFrom method not implemented!";
return f_extract_from(context, candidates);
diff --git a/src/meta_schedule/feature_extractor/per_store_feature.cc b/src/meta_schedule/feature_extractor/per_store_feature.cc
index d99fe6cc78..7c9a809e71 100644
--- a/src/meta_schedule/feature_extractor/per_store_feature.cc
+++ b/src/meta_schedule/feature_extractor/per_store_feature.cc
@@ -216,18 +216,18 @@ int64_t GetVarStride(const std::vector<MultiIndex>& multi_indices, const IntVec&
}
/*!
- * \brief Converts a 2-dimensional STL vector to a TVM NDArray
+ * \brief Converts a 2-dimensional STL vector to a TVM Tensor
* \param src The source 2-dimensional STL vector
* \param second_dim_size The length of the second dimension. When the first dim of src is 0,
- * second_dim_size must be specified, and in such case the shape of the result NDArray is
+ * second_dim_size must be specified, and in such case the shape of the result Tensor is
* (0, second_dim_size).
- * \return The converted TVM NDArray
+ * \return The converted TVM Tensor
*/
-runtime::NDArray AsNDArray(const std::vector<std::vector<double>>& src, int second_dim_size = -1) {
+runtime::Tensor AsTensor(const std::vector<std::vector<double>>& src, int second_dim_size = -1) {
int n = src.size();
ICHECK(!src.empty() || second_dim_size != -1);
int m = src.empty() ? second_dim_size : src[0].size();
- runtime::NDArray tgt = runtime::NDArray::Empty(
+ runtime::Tensor tgt = runtime::Tensor::Empty(
/*shape=*/{n, m},
/*dtype=*/DLDataType{kDLFloat, 64, 1},
/*ctx=*/DLDevice{kDLCPU, 0});
@@ -308,7 +308,7 @@ Pass SimplifyForFeatureExtraction() {
*/
Sequential PassListForPerStoreFeature() {
return Sequential({
- tir::transform::RemoveWeightLayoutRewriteBlock(/*skip_ndarray_rewrite*/ true),
+ tir::transform::RemoveWeightLayoutRewriteBlock(/*skip_tensor_rewrite*/ true),
tir::transform::SimplifyForFeatureExtraction(),
tir::transform::LowerCrossThreadReduction(),
tir::transform::LowerInitBlock(),
@@ -1398,11 +1398,11 @@ class PerStoreFeatureNode : public FeatureExtractorNode {
}
}
- Array<runtime::NDArray> ExtractFrom(const TuneContext& tune_context,
- const Array<MeasureCandidate>& candidates) {
+ Array<runtime::Tensor> ExtractFrom(const TuneContext& tune_context,
+ const Array<MeasureCandidate>& candidates) {
auto& target_keys = tune_context->target.value()->keys;
bool is_gpu = std::find(target_keys.begin(), target_keys.end(), "gpu") != target_keys.end();
- std::vector<runtime::NDArray> results;
+ std::vector<runtime::Tensor> results;
results.resize(candidates.size());
std::unique_ptr<tir::group6::Feature> feature_group6 = nullptr;
if (extract_workload) {
@@ -1417,7 +1417,7 @@ class PerStoreFeatureNode : public FeatureExtractorNode {
feature_group6->Export(&feature);
}
}
- results[task_id] = tir::utils::AsNDArray(features, this->feature_vector_length);
+ results[task_id] = tir::utils::AsTensor(features, this->feature_vector_length);
};
support::parallel_for_dynamic(0, candidates.size(), tune_context->num_threads, f);
return results;
diff --git a/src/meta_schedule/module_equality.cc b/src/meta_schedule/module_equality.cc
index df8c45b5e6..c3b38cf341 100644
--- a/src/meta_schedule/module_equality.cc
+++ b/src/meta_schedule/module_equality.cc
@@ -37,20 +37,20 @@ class ModuleEqualityStructural : public ModuleEquality {
String GetName() const { return "structural"; }
};
-class ModuleEqualityIgnoreNDArray : public ModuleEquality {
+class ModuleEqualityIgnoreTensor : public ModuleEquality {
public:
size_t Hash(IRModule mod) const {
return tvm::ffi::StructuralHash::Hash(mod, /*map_free_vars=*/false,
- /*skip_ndarray_content=*/true);
+ /*skip_tensor_content=*/true);
}
bool Equal(IRModule lhs, IRModule rhs) const {
return tvm::ffi::StructuralEqual::Equal(lhs, rhs, /*map_free_vars=*/false,
- /*skip_ndarray_content=*/true);
+ /*skip_tensor_content=*/true);
}
- String GetName() const { return "ignore-ndarray"; }
+ String GetName() const { return "ignore-tensor"; }
};
-// The NDArray-ignoring variant of structural equal / hash is used for the module equality
+// The Tensor-ignoring variant of structural equal / hash is used for the module equality
// on the extracted anchor blocks.
class ModuleEqualityAnchorBlock : public ModuleEquality {
size_t Hash(IRModule mod) const {
@@ -58,9 +58,9 @@ class ModuleEqualityAnchorBlock : public ModuleEquality {
if (anchor_block) {
return ffi::StructuralHash::Hash(GetRef<tir::Block>(anchor_block),
/*map_free_vars=*/false,
- /*skip_ndarray_content=*/true);
+ /*skip_tensor_content=*/true);
}
- return ModuleEqualityIgnoreNDArray().Hash(mod);
+ return ModuleEqualityIgnoreTensor().Hash(mod);
}
bool Equal(IRModule lhs, IRModule rhs) const {
auto anchor_block_lhs = tir::FindAnchorBlock(lhs);
@@ -69,9 +69,9 @@ class ModuleEqualityAnchorBlock : public ModuleEquality {
return tvm::ffi::StructuralEqual::Equal(GetRef<tir::Block>(anchor_block_lhs),
GetRef<tir::Block>(anchor_block_rhs),
/*map_free_vars=*/false,
- /*skip_ndarray_content=*/true);
+ /*skip_tensor_content=*/true);
}
- return ModuleEqualityIgnoreNDArray().Equal(lhs, rhs);
+ return ModuleEqualityIgnoreTensor().Equal(lhs, rhs);
}
String GetName() const { return "anchor-block"; }
};
@@ -79,8 +79,8 @@ class ModuleEqualityAnchorBlock : public ModuleEquality {
std::unique_ptr<ModuleEquality> ModuleEquality::Create(const std::string& mod_eq_name) {
if (mod_eq_name == "structural") {
return std::make_unique<ModuleEqualityStructural>();
- } else if (mod_eq_name == "ignore-ndarray") {
- return std::make_unique<ModuleEqualityIgnoreNDArray>();
+ } else if (mod_eq_name == "ignore-tensor") {
+ return std::make_unique<ModuleEqualityIgnoreTensor>();
} else if (mod_eq_name == "anchor-block") {
return std::make_unique<ModuleEqualityAnchorBlock>();
}
diff --git a/src/meta_schedule/module_equality.h b/src/meta_schedule/module_equality.h
index 7aa3944a40..cd337c6d7e 100644
--- a/src/meta_schedule/module_equality.h
+++ b/src/meta_schedule/module_equality.h
@@ -41,10 +41,10 @@ class ModuleEquality {
* \param mod_eq_name A string to specify the module equality testing and hashing method.
* It must be one of the followings:
* - "structural": Use StructuralEqual/Hash
- * - "ignore-ndarray": Same as "structural", but ignore ndarray raw data during
+ * - "ignore-tensor": Same as "structural", but ignore tensor raw data during
* equality testing and hashing.
* - "anchor-block": Apply equality testing and hashing on the anchor block extracted from a
- * given module. The "ignore-ndarray" varint is used for the extracted blocks
+ * given module. The "ignore-tensor" varint is used for the extracted blocks
* or in case no anchor block is found.
* For the definition of the anchor block, see tvm/tir/analysis.h.
* \return An owning pointer to the created instance
diff --git a/src/node/structural_hash.cc b/src/node/structural_hash.cc
index 41a22e4d39..1810efa1bf 100644
--- a/src/node/structural_hash.cc
+++ b/src/node/structural_hash.cc
@@ -60,9 +60,9 @@ TVM_FFI_STATIC_INIT_BLOCK({
return rtmod;
});
- refl::TypeAttrDef<runtime::NDArray::Container>()
+ refl::TypeAttrDef<runtime::Tensor::Container>()
.def("__data_to_json__",
- [](const runtime::NDArray::Container* node) {
+ [](const runtime::Tensor::Container* node) {
std::string blob;
dmlc::MemoryStringStream mstrm(&blob);
support::Base64OutStream b64strm(&mstrm);
@@ -74,7 +74,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
dmlc::MemoryStringStream mstrm(const_cast<std::string*>(&blob));
support::Base64InStream b64strm(&mstrm);
b64strm.InitPosition();
- runtime::NDArray temp;
+ runtime::Tensor temp;
ICHECK(temp.Load(&b64strm));
return temp;
});
diff --git a/src/relax/backend/contrib/codegen_c/codegen_c.h b/src/relax/backend/contrib/codegen_c/codegen_c.h
index 7f04091fc1..611e63de89 100644
--- a/src/relax/backend/contrib/codegen_c/codegen_c.h
+++ b/src/relax/backend/contrib/codegen_c/codegen_c.h
@@ -115,7 +115,7 @@ class CodegenCBase {
*
* \code
*
- * Array<NDArray> foo_consts;
+ * Array<Tensor> foo_consts;
*
* // An example code for the generated C function.
* int foo_wrapper_(DLTensor* arg0,
@@ -129,7 +129,7 @@ class CodegenCBase {
*
* TVM_FFI_DLL_EXPORT_TYPED_FUNC(foo, foo_wrapper_);
*
- * int foo_init_wrapper_(Array<NDArray> arr) {
+ * int foo_init_wrapper_(Array<Tensor> arr) {
* foo_consts = arr;
* return 0;
* }
@@ -220,7 +220,7 @@ class CodegenCBase {
// codegen. Moreover, in microTVM we dont expect this part to be generated.
code_stream_ << "#ifdef __cplusplus\n";
code_stream_ << "int " << func_name
- << "_init_wrapper_(tvm::Array<tvm::runtime::NDArray> arr) {\n";
+ << "_init_wrapper_(tvm::Array<tvm::runtime::Tensor> arr) {\n";
EnterScope();
PrintIndents();
code_stream_ << func_name << "_consts = arr;\n";
@@ -369,7 +369,7 @@ class CodegenCBase {
}
/*!
- * \brief Creates a checker to check if the NDArray pool is initialized
+ * \brief Creates a checker to check if the Tensor pool is initialized
*
* \param symobl The Symbol of the current function
*
@@ -389,8 +389,8 @@ class CodegenCBase {
*
* \return The created declaration
*/
- std::string CreateNDArrayPool(const std::string& symbol) const {
- return "tvm::Array<tvm::runtime::NDArray> " + symbol + "_consts;";
+ std::string CreateTensorPool(const std::string& symbol) const {
+ return "tvm::Array<tvm::runtime::Tensor> " + symbol + "_consts;";
}
/*!
diff --git a/src/relax/backend/contrib/codegen_json/codegen_json.h b/src/relax/backend/contrib/codegen_json/codegen_json.h
index 3e0b6ea5e8..1ea03a63c0 100644
--- a/src/relax/backend/contrib/codegen_json/codegen_json.h
+++ b/src/relax/backend/contrib/codegen_json/codegen_json.h
@@ -174,7 +174,7 @@ class OpAttrExtractor {
this->Visit(field_info->name.data, &value);
break;
}
- case ffi::TypeIndex::kTVMFFINDArray: {
+ case ffi::TypeIndex::kTVMFFITensor: {
this->Visit(field_info->name.data, &field_value);
break;
}
diff --git a/src/relax/backend/vm/codegen_vm.cc b/src/relax/backend/vm/codegen_vm.cc
index 1f9e8c0378..c26c043e74 100644
--- a/src/relax/backend/vm/codegen_vm.cc
+++ b/src/relax/backend/vm/codegen_vm.cc
@@ -440,7 +440,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
* module(s).
* \return The created module.
*/
-void LinkModules(ObjectPtr<VMExecutable> exec, const Map<String, runtime::NDArray>& params,
+void LinkModules(ObjectPtr<VMExecutable> exec, const Map<String, runtime::Tensor>& params,
const tvm::ffi::Module& lib, const Array<ffi::Module>& ext_libs) {
// query if we need const loader for ext_modules
// Wrap all submodules in the initialization wrapper.
@@ -461,12 +461,12 @@ void LinkModules(ObjectPtr<VMExecutable> exec, const Map<String, runtime::NDArra
}
if (!const_vars_by_symbol.empty() || !params.empty()) {
// need runtime const information, run link const loader
- std::unordered_map<std::string, runtime::NDArray> const_var_ndarray;
+ std::unordered_map<std::string, runtime::Tensor> const_var_tensor;
for (const auto& [name, param] : params) {
- const_var_ndarray[name] = param;
+ const_var_tensor[name] = param;
}
ffi::Module const_loader_mod =
- runtime::ConstLoaderModuleCreate(const_var_ndarray, const_vars_by_symbol);
+ runtime::ConstLoaderModuleCreate(const_var_tensor, const_vars_by_symbol);
const_loader_mod->ImportModule(lib);
for (const auto& it : ext_libs) {
const_loader_mod->ImportModule(it);
@@ -485,7 +485,7 @@ void LinkModules(ObjectPtr<VMExecutable> exec, const Map<String, runtime::NDArra
* \brief Link the libraries together.
*/
ffi::Module VMLink(ExecBuilder builder, Target target, Optional<ffi::Module> lib,
- Array<ffi::Module> ext_libs, Map<String, runtime::NDArray> params) {
+ Array<ffi::Module> ext_libs, Map<String, runtime::Tensor> params) {
ObjectPtr<VMExecutable> executable = builder->Get();
if (!lib.defined()) {
lib = codegen::CSourceModuleCreate(";", "c", Array<String>{});
diff --git a/src/relax/ir/block_builder.cc b/src/relax/ir/block_builder.cc
index 3cf24d8a8c..1a725db904 100644
--- a/src/relax/ir/block_builder.cc
+++ b/src/relax/ir/block_builder.cc
@@ -427,12 +427,12 @@ class BlockBuilderImpl : public BlockBuilderNode {
return name_supply_->FreshName(prefix, /*add_prefix*/ false, /*add_underscore*/ false);
}
- /*! \brief A custom structural hashing that ignores NDArray raw data. */
+ /*! \brief A custom structural hashing that ignores Tensor raw data. */
class StructuralHashIgnoreNDarray {
public:
uint64_t operator()(const ObjectRef& key) const {
return ffi::StructuralHash::Hash(key, /*map_free_vars=*/false,
- /*skip_ndarray_content=*/true);
+ /*skip_tensor_content=*/true);
}
};
diff --git a/src/relax/ir/expr.cc b/src/relax/ir/expr.cc
index 8fbe05e891..844fd890e1 100644
--- a/src/relax/ir/expr.cc
+++ b/src/relax/ir/expr.cc
@@ -331,7 +331,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
});
});
-Constant::Constant(runtime::NDArray data, Optional<StructInfo> struct_info_annotation, Span span) {
+Constant::Constant(runtime::Tensor data, Optional<StructInfo> struct_info_annotation, Span span) {
ObjectPtr<ConstantNode> n = make_object<ConstantNode>();
n->data = std::move(data);
n->span = std::move(span);
@@ -356,7 +356,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
namespace refl = tvm::ffi::reflection;
refl::GlobalDef().def(
"relax.Constant",
- [](runtime::NDArray data, Optional<StructInfo> struct_info_annotation = std::nullopt,
+ [](runtime::Tensor data, Optional<StructInfo> struct_info_annotation = std::nullopt,
Span span = Span()) { return Constant(data, struct_info_annotation, span); });
});
diff --git a/src/relax/op/memory/view.cc b/src/relax/op/memory/view.cc
index 1af12b4751..87f6864824 100644
--- a/src/relax/op/memory/view.cc
+++ b/src/relax/op/memory/view.cc
@@ -346,7 +346,7 @@ Expr LowerBuiltinView(const BlockBuilder& bb, const Call& call) {
infer_sinfo_env_func = EnvFunc::Get("tvm.relax.struct_info.infer_view_sinfo");
auto runtime_view_sinfo = FuncStructInfo::OpaqueFunc(infer_sinfo_env_func, true);
- ExternFunc runtime_view_func("runtime.TVMArrayCreateView", runtime_view_sinfo);
+ ExternFunc runtime_view_func("runtime.TVMTensorCreateView", runtime_view_sinfo);
return Call(runtime_view_func, {data, shape, dtype, relative_byte_offset});
}
diff --git a/src/relax/transform/bind_params.cc b/src/relax/transform/bind_params.cc
index 13b138ecce..1940a7a24d 100644
--- a/src/relax/transform/bind_params.cc
+++ b/src/relax/transform/bind_params.cc
@@ -131,7 +131,7 @@ std::tuple<Map<Var, Expr>, Map<tir::Var, PrimExpr>> NormalizeBindings(
auto normalize_value = [&](ffi::Any obj) -> relax::Expr {
if (auto opt = obj.as<relax::Expr>()) {
return opt.value();
- } else if (auto opt = obj.as<runtime::NDArray>()) {
+ } else if (auto opt = obj.as<runtime::Tensor>()) {
return Constant(opt.value());
} else {
LOG(FATAL) << "Cannot coerce object of type " << obj.GetTypeKey() << " into relax expression";
diff --git a/src/relax/transform/fold_constant.cc b/src/relax/transform/fold_constant.cc
index 33e077d726..93b77387d5 100644
--- a/src/relax/transform/fold_constant.cc
+++ b/src/relax/transform/fold_constant.cc
@@ -73,8 +73,8 @@ class ConstantFolder : public ExprMutator {
* \brief Pattern match op to constant array arguments.
* \return The constant array arguments, or nullopt if match fails.
*/
- static Optional<Array<runtime::NDArray>> MatchConstArrayArgs(const Array<Expr>& args) {
- Array<runtime::NDArray> res;
+ static Optional<Array<runtime::Tensor>> MatchConstArrayArgs(const Array<Expr>& args) {
+ Array<runtime::Tensor> res;
for (auto arg : args) {
auto* ptr = arg.as<relax::ConstantNode>();
if (!ptr) return std::nullopt;
@@ -144,7 +144,7 @@ class ConstantFolder : public ExprMutator {
// Try constant evaluate the function call
// if failed return std::nullopt
- Optional<Expr> ConstEvaluateCallTIR(tir::PrimFunc tir_func, Array<runtime::NDArray> arr_args,
+ Optional<Expr> ConstEvaluateCallTIR(tir::PrimFunc tir_func, Array<runtime::Tensor> arr_args,
ffi::Shape shape, DataType ret_type) {
// obtain function from the cache.
Optional<ffi::Function> func = GetCachedBuild(tir_func);
@@ -154,11 +154,11 @@ class ConstantFolder : public ExprMutator {
std::vector<AnyView> packed_args(arr_args.size() + 1);
DLDevice cpu_dev = {DLDeviceType::kDLCPU, 0};
- runtime::NDArray ret_tensor = runtime::NDArray::Empty(shape, ret_type, cpu_dev);
+ runtime::Tensor ret_tensor = runtime::Tensor::Empty(shape, ret_type, cpu_dev);
// avoid set rvalue ref which get de-allocated later, store args in a vector
// where temp_args[i] are lvalue ref that is stable
- std::vector<runtime::NDArray> temp_args(arr_args.begin(), arr_args.end());
+ std::vector<runtime::Tensor> temp_args(arr_args.begin(), arr_args.end());
size_t arg_offset = 0;
for (; arg_offset < arr_args.size(); ++arg_offset) {
@@ -179,7 +179,7 @@ class ConstantFolder : public ExprMutator {
ICHECK_GE(call->args.size(), 2);
Optional<tir::PrimFunc> func = MatchPrimFunc(call->args[0]);
ICHECK(call->args[1].as<TupleNode>()) << "call_tir.args[1] must be Tuple";
- Optional<Array<runtime::NDArray>> arr_args =
+ Optional<Array<runtime::Tensor>> arr_args =
MatchConstArrayArgs(call->args[1].as<TupleNode>()->fields);
ICHECK_EQ(call->sinfo_args.size(), 1) << "call_tir should have exactly one sinfo arg";
Optional<ffi::Shape> shape = MatchConstShape(call->sinfo_args[0]);
@@ -268,7 +268,7 @@ class ConstantFolder : public ExprMutator {
Expr arg = post_call->args[0];
if (arg->IsInstance<ConstantNode>()) {
Constant constant = Downcast<Constant>(arg);
- runtime::NDArray ndarray = constant->data;
+ runtime::Tensor ndarray = constant->data;
ICHECK_EQ(ndarray->device.device_type, kDLCPU);
ICHECK(ffi::IsContiguous(*ndarray.get()));
ICHECK_EQ(ndarray->byte_offset, 0);
@@ -296,7 +296,7 @@ class ConstantFolder : public ExprMutator {
}
if (is_known) {
const auto func = tvm::ffi::Function::GetGlobalRequired("relax.run.shape_to_tensor");
- runtime::NDArray vals = func(arr).cast<runtime::NDArray>();
+ runtime::Tensor vals = func(arr).cast<runtime::Tensor>();
return Constant(vals);
}
}
diff --git a/src/relax/transform/meta_schedule.cc b/src/relax/transform/meta_schedule.cc
index acad7d1544..5bb8d2d3e3 100644
--- a/src/relax/transform/meta_schedule.cc
+++ b/src/relax/transform/meta_schedule.cc
@@ -37,7 +37,7 @@ class MetaScheduleTuner {
public:
explicit MetaScheduleTuner(Target target, String work_dir, Integer max_trials_global,
Integer max_trials_per_task, Optional<Array<String>> op_names,
- Map<String, runtime::NDArray> params = {})
+ Map<String, runtime::Tensor> params = {})
: target_(target),
work_dir_(work_dir),
max_trials_global_(max_trials_global),
@@ -68,7 +68,7 @@ class MetaScheduleTuner {
Integer max_trials_global_;
Integer max_trials_per_task_;
Optional<Array<String>> op_names_;
- Map<String, runtime::NDArray> params_;
+ Map<String, runtime::Tensor> params_;
tvm::ffi::Function normalize_mod_func_;
};
@@ -93,7 +93,7 @@ Pass MetaScheduleApplyDatabase(Optional<String> work_dir, bool enable_warning =
}
Map<GlobalVar, BaseFunc> result;
- auto mod_eq_structural = meta_schedule::ModuleEquality::Create("ignore-ndarray");
+ auto mod_eq_structural = meta_schedule::ModuleEquality::Create("ignore-tensor");
for (const auto& iter : mod->functions) {
GlobalVar gv = iter.first;
BaseFunc base_func = iter.second;
@@ -146,7 +146,7 @@ Pass MetaScheduleApplyDatabase(Optional<String> work_dir, bool enable_warning =
return CreateModulePass(pass_func, 0, "MetaScheduleApplyDatabase", {});
}
-Pass MetaScheduleTuneIRMod(Map<String, runtime::NDArray> params, String work_dir,
+Pass MetaScheduleTuneIRMod(Map<String, runtime::Tensor> params, String work_dir,
Integer max_trials_global,
Optional<Integer> max_trials_per_task = std::nullopt,
Optional<Array<String>> op_names = std::nullopt) {
diff --git a/src/relax/transform/run_codegen.cc b/src/relax/transform/run_codegen.cc
index 0cc0a070aa..af02225361 100644
--- a/src/relax/transform/run_codegen.cc
+++ b/src/relax/transform/run_codegen.cc
@@ -89,7 +89,7 @@ class CodeGenRunner : ExprMutator {
if (constant_names.size()) {
// Some backends (e.g. TensorRT) expect constants to be passed when they are instantiated
- Map<String, runtime::NDArray> constants;
+ Map<String, runtime::Tensor> constants;
for (const auto& [constant, name] : constant_names) {
ICHECK(!constants.count(name)) << "More than one constant with the name " << name;
constants.Set(name, constant->data);
diff --git a/src/relax/transform/utils.h b/src/relax/transform/utils.h
index 009d002607..e4fe449ed6 100644
--- a/src/relax/transform/utils.h
+++ b/src/relax/transform/utils.h
@@ -319,7 +319,7 @@ class FunctionCopier : public SymbolicVarRenewMutator {
*/
template <typename T>
inline Constant MakeConstantScalar(T value, DataType dtype) {
- runtime::NDArray arr = runtime::NDArray::Empty({}, dtype, {kDLCPU, 0});
+ runtime::Tensor arr = runtime::Tensor::Empty({}, dtype, {kDLCPU, 0});
if (dtype == DataType::Float(32)) {
*static_cast<float*>(arr->data) = static_cast<float>(value);
} else if (dtype == DataType::Float(64)) {
diff --git a/src/runtime/const_loader_module.cc b/src/runtime/const_loader_module.cc
index 2c02fb556c..6f07e10f62 100644
--- a/src/runtime/const_loader_module.cc
+++ b/src/runtime/const_loader_module.cc
@@ -19,7 +19,7 @@
/*!
* \file src/runtime/const_loader_module.cc
- * \brief A wrapper for initializing imported modules using constant NDArray. This
+ * \brief A wrapper for initializing imported modules using constant Tensor. This
* module is intended to be used by various runtime in the TVM stack, i.e.
* graph executor, relax VM, AOT runtime, and various user defined runtimes. It
* paves the way to separate the code and metedata, which makes compilation
@@ -34,7 +34,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/ffi/string.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstdint>
@@ -48,9 +48,9 @@ namespace runtime {
class ConstLoaderModuleObj : public ffi::ModuleObj {
public:
ConstLoaderModuleObj(
- const std::unordered_map<std::string, NDArray>& const_var_ndarray,
+ const std::unordered_map<std::string, Tensor>& const_var_tensor,
const std::unordered_map<std::string, std::vector<std::string>>& const_vars_by_symbol)
- : const_var_ndarray_(const_var_ndarray), const_vars_by_symbol_(const_vars_by_symbol) {
+ : const_var_tensor_(const_var_tensor), const_vars_by_symbol_(const_vars_by_symbol) {
VLOG(1) << "Creating ConstLoaderModule";
// Only the related submodules are cached to reduce the number of runtime
// symbol lookup for initialization. Otherwise, symbols/primitives in the
@@ -59,7 +59,7 @@ class ConstLoaderModuleObj : public ffi::ModuleObj {
for (const auto& var : kv.second) {
VLOG(1) << "ConstLoaderModuleNode has constant '" << var << "' for function '" << kv.first
<< "'";
- ICHECK_GT(const_var_ndarray_.count(var), 0)
+ ICHECK_GT(const_var_tensor_.count(var), 0)
<< "ConstLoaderModuleNode is missing entry for constant '" << var << "' for function '"
<< kv.first << "'";
}
@@ -78,10 +78,10 @@ class ConstLoaderModuleObj : public ffi::ModuleObj {
}
ObjectRef _self = ffi::GetRef<ObjectRef>(this);
- if (name == "get_const_var_ndarray") {
+ if (name == "get_const_var_tensor") {
return ffi::Function([_self, this](ffi::PackedArgs args, ffi::Any* rv) {
Map<String, ffi::Any> ret_map;
- for (const auto& kv : const_var_ndarray_) {
+ for (const auto& kv : const_var_tensor_) {
ret_map.Set(kv.first, kv.second);
}
*rv = ret_map;
@@ -107,17 +107,17 @@ class ConstLoaderModuleObj : public ffi::ModuleObj {
/*!
* \brief Get the list of constants that is required by the given module.
* \param symbol The symbol that is being queried.
- * \return The list of needed NDArray.
+ * \return The list of needed Tensor.
*/
- Array<NDArray> GetRequiredConstants(const std::string& symbol) {
- Array<NDArray> ret;
+ Array<Tensor> GetRequiredConstants(const std::string& symbol) {
+ Array<Tensor> ret;
ICHECK_GT(const_vars_by_symbol_.count(symbol), 0U)
<< "No constants known for function '" << symbol << "'";
std::vector<std::string> vars = const_vars_by_symbol_[symbol];
for (const auto& var : vars) {
- ICHECK_GT(const_var_ndarray_.count(var), 0U)
+ ICHECK_GT(const_var_tensor_.count(var), 0U)
<< "No such constant variable '" << var << "' for function '" << symbol << "'";
- ret.push_back(const_var_ndarray_[var]);
+ ret.push_back(const_var_tensor_[var]);
}
return ret;
}
@@ -157,20 +157,20 @@ class ConstLoaderModuleObj : public ffi::ModuleObj {
dmlc::Stream* stream = &ms;
std::vector<std::string> variables;
- std::vector<NDArray> const_var_ndarray;
- for (const auto& it : const_var_ndarray_) {
+ std::vector<Tensor> const_var_tensor;
+ for (const auto& it : const_var_tensor_) {
String var_name = it.first;
variables.push_back(var_name);
- const_var_ndarray.push_back(it.second);
+ const_var_tensor.push_back(it.second);
}
// Save all variables in the function.
stream->Write(variables);
// Save all constant data.
- uint64_t sz = static_cast<uint64_t>(const_var_ndarray.size());
+ uint64_t sz = static_cast<uint64_t>(const_var_tensor.size());
stream->Write(sz);
for (uint64_t i = 0; i < sz; i++) {
- const_var_ndarray[i].Save(stream);
+ const_var_tensor[i].Save(stream);
}
// Save the symbol to list of required constant variables mapping
@@ -202,17 +202,17 @@ class ConstLoaderModuleObj : public ffi::ModuleObj {
ICHECK_EQ(static_cast<size_t>(sz), variables.size())
<< "The number of variables and ndarray counts must match";
// Load the list of ndarray.
- std::vector<NDArray> arrays;
+ std::vector<Tensor> arrays;
for (uint64_t i = 0; i < sz; i++) {
- NDArray temp;
+ Tensor temp;
temp.Load(stream);
arrays.push_back(temp);
}
- std::unordered_map<std::string, NDArray> const_var_ndarray;
+ std::unordered_map<std::string, Tensor> const_var_tensor;
for (uint64_t i = 0; i < sz; i++) {
- ICHECK_EQ(const_var_ndarray.count(variables[i]), 0U);
- const_var_ndarray[variables[i]] = arrays[i];
+ ICHECK_EQ(const_var_tensor.count(variables[i]), 0U);
+ const_var_tensor[variables[i]] = arrays[i];
}
// Load the symbol to list of required constant variables mapping
@@ -232,7 +232,7 @@ class ConstLoaderModuleObj : public ffi::ModuleObj {
const_vars_by_symbol[symbols[i]] = const_vars[i];
}
- auto n = make_object<ConstLoaderModuleObj>(const_var_ndarray, const_vars_by_symbol);
+ auto n = make_object<ConstLoaderModuleObj>(const_var_tensor, const_vars_by_symbol);
return ffi::Module(n);
}
@@ -242,16 +242,16 @@ class ConstLoaderModuleObj : public ffi::ModuleObj {
* modules using execution engine.
*/
std::unordered_map<std::string, bool> initialized_;
- /*! \brief Variable name to NDArray mapping. */
- std::unordered_map<std::string, NDArray> const_var_ndarray_;
+ /*! \brief Variable name to Tensor mapping. */
+ std::unordered_map<std::string, Tensor> const_var_tensor_;
/*! \brief Symbol name to required constant variables mapping. */
std::unordered_map<std::string, std::vector<std::string>> const_vars_by_symbol_;
};
ffi::Module ConstLoaderModuleCreate(
- const std::unordered_map<std::string, NDArray>& const_var_ndarray,
+ const std::unordered_map<std::string, Tensor>& const_var_tensor,
const std::unordered_map<std::string, std::vector<std::string>>& const_vars_by_symbol) {
- auto n = make_object<ConstLoaderModuleObj>(const_var_ndarray, const_vars_by_symbol);
+ auto n = make_object<ConstLoaderModuleObj>(const_var_tensor, const_vars_by_symbol);
return ffi::Module(n);
}
diff --git a/src/runtime/const_loader_module.h b/src/runtime/const_loader_module.h
index c093818763..30bddc7b37 100644
--- a/src/runtime/const_loader_module.h
+++ b/src/runtime/const_loader_module.h
@@ -25,7 +25,7 @@
#ifndef TVM_RUNTIME_CONST_LOADER_MODULE_H_
#define TVM_RUNTIME_CONST_LOADER_MODULE_H_
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <string>
#include <unordered_map>
@@ -37,14 +37,14 @@ namespace runtime {
/*!
* \brief Create a ConstLoader module object.
*
- * \param const_var_ndarray Maps consts var name to NDArray containing data for the var.
+ * \param const_var_tensor Maps consts var name to Tensor containing data for the var.
* \param const_vars_by_symbol Maps the name of a module init function to a list of names of
* const vars whose data will be passed to that init function.
*
* \return The created ConstLoaderModule.
*/
ffi::Module ConstLoaderModuleCreate(
- const std::unordered_map<std::string, NDArray>& const_var_ndarray,
+ const std::unordered_map<std::string, Tensor>& const_var_tensor,
const std::unordered_map<std::string, std::vector<std::string>>& const_vars_by_symbol);
} // namespace runtime
diff --git a/src/runtime/contrib/arm_compute_lib/acl_runtime.cc b/src/runtime/contrib/arm_compute_lib/acl_runtime.cc
index 3de9e85a57..92e4bd06e2 100644
--- a/src/runtime/contrib/arm_compute_lib/acl_runtime.cc
+++ b/src/runtime/contrib/arm_compute_lib/acl_runtime.cc
@@ -24,7 +24,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include "../json/json_node.h"
#include "../json/json_runtime.h"
@@ -77,7 +77,7 @@ class ACLRuntime : public JSONRuntimeBase {
*
* \param consts The constant params from compiled model.
*/
- void Init(const Array<NDArray>& consts) override {
+ void Init(const Array<Tensor>& consts) override {
ICHECK_EQ(consts.size(), const_idx_.size())
<< "The number of input constants must match the number of required.";
SetupConstants(consts);
diff --git a/src/runtime/contrib/bnns/bnns_json_runtime.cc b/src/runtime/contrib/bnns/bnns_json_runtime.cc
index 9080eeb9bb..0386bde378 100644
--- a/src/runtime/contrib/bnns/bnns_json_runtime.cc
+++ b/src/runtime/contrib/bnns/bnns_json_runtime.cc
@@ -25,7 +25,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
#include <tvm/runtime/c_backend_api.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <string>
@@ -93,7 +93,7 @@ class BNNSJSONRuntime : public JSONRuntimeBase {
const char* kind() const override { return "bnns_json"; }
- void Init(const Array<NDArray>& consts) override {
+ void Init(const Array<Tensor>& consts) override {
ICHECK_EQ(consts.size(), const_idx_.size())
<< "The number of input constants must match the number of required.";
@@ -367,7 +367,7 @@ class BNNSJSONRuntime : public JSONRuntimeBase {
dst_view.get_bnns_view()};
// BNNS limitation: MatMul use reverse dims values. However strides are calculated correctly
- // based on BNNSNDArrayDescriptor::layout value.
+ // based on BNNSTensorDescriptor::layout value.
std::reverse(layerParameters.iA_desc.size, layerParameters.iA_desc.size + 3);
std::reverse(layerParameters.iB_desc.size, layerParameters.iB_desc.size + 3);
std::reverse(layerParameters.o_desc.size, layerParameters.o_desc.size + 3);
diff --git a/src/runtime/contrib/bnns/bnns_wrp.h b/src/runtime/contrib/bnns/bnns_wrp.h
index f395561a7f..1997e0a84d 100644
--- a/src/runtime/contrib/bnns/bnns_wrp.h
+++ b/src/runtime/contrib/bnns/bnns_wrp.h
@@ -62,7 +62,7 @@ class Tensor {
auto rank = shape.size();
ICHECK(rank < BNNS_MAX_TENSOR_DIMENSION);
- desc_ = {BNNSNDArrayFlags(0),
+ desc_ = {BNNSTensorFlags(0),
getPlainLayout(rank),
{}, // shape
{}, // strides
@@ -107,7 +107,7 @@ class Tensor {
is_external_data = true;
}
- const BNNSNDArrayDescriptor& get_desc() const { return desc_; }
+ const BNNSTensorDescriptor& get_desc() const { return desc_; }
static BNNSDataLayout getPlainLayout(size_t rank) {
ICHECK(rank <= BNNS_MAX_TENSOR_DIMENSION);
@@ -116,9 +116,9 @@ class Tensor {
static size_t getRank(BNNSDataLayout layout) { return (layout & 0xF0000) >> 16; }
- static size_t getRank(BNNSNDArrayDescriptor desc) { return getRank(desc.layout); }
+ static size_t getRank(BNNSTensorDescriptor desc) { return getRank(desc.layout); }
- static size_t getSize(BNNSNDArrayDescriptor desc) {
+ static size_t getSize(BNNSTensorDescriptor desc) {
auto rank = getRank(desc);
return std::accumulate(desc.size, desc.size + rank, 1, std::multiplies<int>());
}
@@ -127,13 +127,13 @@ class Tensor {
static size_t getElementSize(Dtype dtype) { return (dtype & 0xFFFF) / 8; }
/** return size of element in bytes */
- static size_t getElementSize(const BNNSNDArrayDescriptor& desc) {
+ static size_t getElementSize(const BNNSTensorDescriptor& desc) {
return getElementSize(desc.data_type);
}
private:
bool is_external_data = false;
- BNNSNDArrayDescriptor desc_;
+ BNNSTensorDescriptor desc_;
};
using TensorPtr = std::shared_ptr<Tensor>;
@@ -291,14 +291,14 @@ class TView {
operator bool() const { return origin_ != nullptr; }
/** Get BNNS descriptor for particular View. Batch and Party attributed are ignored. */
- const BNNSNDArrayDescriptor& get_bnns_view() const { return view_desc_; }
+ const BNNSTensorDescriptor& get_bnns_view() const { return view_desc_; }
private:
/** Original tensor object to view on */
TensorPtr origin_;
/** Batched view parameters */
- BNNSNDArrayDescriptor view_desc_ = {};
+ BNNSTensorDescriptor view_desc_ = {};
size_t batch_size_ = 1;
size_t batch_stride_ = 0;
diff --git a/src/runtime/contrib/clml/clml_runtime.cc b/src/runtime/contrib/clml/clml_runtime.cc
index 9d13e427b2..39e38aa872 100644
--- a/src/runtime/contrib/clml/clml_runtime.cc
+++ b/src/runtime/contrib/clml/clml_runtime.cc
@@ -201,7 +201,7 @@ class CLMLRuntime : public JSONRuntimeBase {
*
* \param consts The constant params from compiled model.
*/
- void Init(const Array<NDArray>& consts) override {
+ void Init(const Array<Tensor>& consts) override {
ICHECK_EQ(consts.size(), const_idx_.size())
<< "The number of input constants must match the number of required.";
SetupConstants(consts);
@@ -270,7 +270,7 @@ class CLMLRuntime : public JSONRuntimeBase {
"same by exporting CLML_DISABLE_RECORDABLE_QUEUE at runtime.";
}
cl_command_queue queue = CLML_QUEUE;
- Map<String, NDArray> dump_tensors;
+ Map<String, Tensor> dump_tensors;
std::ostringstream os;
dmlc::JSONWriter writer(&os);
writer.BeginObject();
@@ -293,7 +293,7 @@ class CLMLRuntime : public JSONRuntimeBase {
// Dump tensor to CPU
std::vector<int64_t> shape = node.GetOpShape()[0];
DLDataType tvm_dtype = node.GetOpDataType()[0];
- NDArray narr = NDArray::Empty(ffi::Shape(shape), tvm_dtype, {kDLCPU, 0});
+ Tensor narr = Tensor::Empty(ffi::Shape(shape), tvm_dtype, {kDLCPU, 0});
CopyDataFromCLMLTensor(clml_desc, narr.operator->()->data);
// Naming convention
@@ -466,8 +466,8 @@ class CLMLRuntime : public JSONRuntimeBase {
cl_channel_type cl_dtype = MakeCLDataType(tvm_dtype);
int dtype_size = cl_dtype == CL_FLOAT ? 4 : 2;
void* tmpptr = reinterpret_cast<void*>(malloc(isize * dtype_size));
- TVMArrayCopyToBytes(const_cast<DLTensor*>(data_entry_[eid]), const_cast<void*>(tmpptr),
- isize * dtype_size);
+ TVMTensorCopyToBytes(const_cast<DLTensor*>(data_entry_[eid]), const_cast<void*>(tmpptr),
+ isize * dtype_size);
CopyDataToCLMLTensor(layer_.inputs[nid], tmpptr);
free(tmpptr);
}
@@ -553,8 +553,8 @@ class CLMLRuntime : public JSONRuntimeBase {
void* tmpptr = reinterpret_cast<void*>(malloc(osize * dtype_size));
CopyDataFromCLMLTensor(layer_.outputs[0], tmpptr);
- TVMArrayCopyFromBytes(const_cast<DLTensor*>(data_entry_[eid]), const_cast<void*>(tmpptr),
- osize * dtype_size);
+ TVMTensorCopyFromBytes(const_cast<DLTensor*>(data_entry_[eid]), const_cast<void*>(tmpptr),
+ osize * dtype_size);
free(tmpptr);
}
}
diff --git a/src/runtime/contrib/clml/clml_runtime.h b/src/runtime/contrib/clml/clml_runtime.h
index 4431b63caf..716ea4665e 100644
--- a/src/runtime/contrib/clml/clml_runtime.h
+++ b/src/runtime/contrib/clml/clml_runtime.h
@@ -33,8 +33,8 @@
#include <CL/opencl.h>
#include <stdlib.h>
#include <tvm/ffi/function.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/profiling.h>
+#include <tvm/runtime/tensor.h>
#include <fstream>
#include <map>
@@ -253,11 +253,11 @@ struct CachedLayer {
std::map<cl_ml_op_qcom, std::pair<int, JSONGraphNode>> op_node_map;
/* The input tensor map */
std::map<int, std::shared_ptr<cl_ml_tensor_memory_desc_qcom>> inputs;
- /* A place holder Tensor representing TVM NDArray as CLML Tensor */
+ /* A place holder Tensor representing TVM Tensor as CLML Tensor */
std::map<int, std::shared_ptr<cl_ml_tensor_memory_desc_qcom>> in_placeholder;
/* The Output tensor map */
std::vector<std::shared_ptr<cl_ml_tensor_memory_desc_qcom>> outputs;
- /* A place holder Tensor representing TVM NDArray as CLML Tensor */
+ /* A place holder Tensor representing TVM Tensor as CLML Tensor */
std::vector<std::shared_ptr<cl_ml_tensor_memory_desc_qcom>> out_placeholder;
/* Tensor shape exception list while returning from CLML Subgraph */
std::map<int, std::vector<size_t>> out_shapes;
diff --git a/src/runtime/contrib/coreml/coreml_runtime.h b/src/runtime/contrib/coreml/coreml_runtime.h
index 257b624bbf..3f7db78bfc 100644
--- a/src/runtime/contrib/coreml/coreml_runtime.h
+++ b/src/runtime/contrib/coreml/coreml_runtime.h
@@ -31,7 +31,7 @@
#include <dlpack/dlpack.h>
#include <tvm/ffi/extra/module.h>
#include <tvm/ffi/function.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <memory>
#include <string>
@@ -67,12 +67,12 @@ class CoreMLModel {
*/
void SetInput(const std::string& key, DLTensor* data_in);
/*!
- * \brief Return NDArray for given output index.
+ * \brief Return Tensor for given output index.
* \param index The output index.
*
- * \return NDArray corresponding to given output node index.
+ * \return Tensor corresponding to given output node index.
*/
- NDArray GetOutput(int index) const;
+ Tensor GetOutput(int index) const;
/*!
* \brief Return the number of outputs
*
diff --git a/src/runtime/contrib/coreml/coreml_runtime.mm b/src/runtime/contrib/coreml/coreml_runtime.mm
index fb5faa8621..5926fb32d6 100644
--- a/src/runtime/contrib/coreml/coreml_runtime.mm
+++ b/src/runtime/contrib/coreml/coreml_runtime.mm
@@ -67,7 +67,7 @@ void CoreMLModel::SetInput(const std::string& key, DLTensor* data_in) {
[input_dict_ setObject:dest forKey:nsKey];
}
-NDArray CoreMLModel::GetOutput(int index) const {
+Tensor CoreMLModel::GetOutput(int index) const {
MLModelDescription* model_desc = model_.modelDescription;
NSString* metadata = [model_desc metadata][MLModelDescriptionKey];
NSData* data = [metadata dataUsingEncoding:NSUTF8StringEncoding];
@@ -103,7 +103,7 @@ NDArray CoreMLModel::GetOutput(int index) const {
.device_type = kDLCPU,
.device_id = 0,
};
- NDArray ret = NDArray::Empty(shape, dtype, cpu_dev);
+ Tensor ret = Tensor::Empty(shape, dtype, cpu_dev);
ret.CopyFromBytes(src.dataPointer, size);
return ret;
@@ -157,10 +157,9 @@ Optional<ffi::Function> CoreMLRuntime::GetFunction(const String& name) {
// Copy input tensors to corresponding data entries.
for (auto i = 0; i < args.size() - 1; ++i) {
- ICHECK(args[i].type_code() == kTVMDLTensorHandle ||
- args[i].type_code() == kTVMNDArrayHandle)
- << "Expect NDArray or DLTensor as inputs\n";
- if (args[i].type_code() == kTVMDLTensorHandle || args[i].type_code() == kTVMNDArrayHandle) {
+ ICHECK(args[i].type_code() == kTVMDLTensorHandle || args[i].type_code() == kTVMTensorHandle)
+ << "Expect Tensor or DLTensor as inputs\n";
+ if (args[i].type_code() == kTVMDLTensorHandle || args[i].type_code() == kTVMTensorHandle) {
model_->SetInput([input_names[i] UTF8String], args[i]);
} else {
LOG(FATAL) << "Not implemented";
@@ -171,12 +170,12 @@ Optional<ffi::Function> CoreMLRuntime::GetFunction(const String& name) {
model_->Invoke();
// TODO: Support multiple outputs.
- NDArray out = model_->GetOutput(0);
+ Tensor out = model_->GetOutput(0);
if (args[args.size() - 1].type_code() == kTVMDLTensorHandle) {
DLTensor* arg = args[args.size() - 1];
out.CopyTo(arg);
} else {
- NDArray arg = args[args.size() - 1];
+ Tensor arg = args[args.size() - 1];
out.CopyTo(arg);
}
*rv = out;
diff --git a/src/runtime/contrib/cublas/cublas_json_runtime.cc b/src/runtime/contrib/cublas/cublas_json_runtime.cc
index 0416391303..99eda5cc89 100644
--- a/src/runtime/contrib/cublas/cublas_json_runtime.cc
+++ b/src/runtime/contrib/cublas/cublas_json_runtime.cc
@@ -25,7 +25,7 @@
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <string>
@@ -49,7 +49,7 @@ class CublasJSONRuntime : public JSONRuntimeBase {
const Array<String> const_names)
: JSONRuntimeBase(symbol_name, graph_json, const_names) {}
- void Init(const Array<NDArray>& consts) override {}
+ void Init(const Array<Tensor>& consts) override {}
ffi::Optional<ffi::Function> GetFunction(const String& name) override {
// JSONRuntimeBase::SetInputOutputBuffers(...) is not thread safe. Since CublasJSONRuntime
@@ -76,8 +76,8 @@ class CublasJSONRuntime : public JSONRuntimeBase {
: EntryID(outputs_[i - input_var_eid_.size()]);
const DLTensor* arg;
- if (auto opt_nd = args[i].as<NDArray>()) {
- NDArray arr = opt_nd.value();
+ if (auto opt_nd = args[i].as<Tensor>()) {
+ Tensor arr = opt_nd.value();
arg = arr.operator->();
} else {
arg = args[i].cast<DLTensor*>();
diff --git a/src/runtime/contrib/cudnn/cudnn_json_runtime.cc b/src/runtime/contrib/cudnn/cudnn_json_runtime.cc
index 3888bca3df..1e17cf2ecf 100644
--- a/src/runtime/contrib/cudnn/cudnn_json_runtime.cc
+++ b/src/runtime/contrib/cudnn/cudnn_json_runtime.cc
@@ -25,7 +25,7 @@
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <string>
@@ -52,7 +52,7 @@ class cuDNNJSONRuntime : public JSONRuntimeBase {
const Array<String> const_names)
: JSONRuntimeBase(symbol_name, graph_json, const_names) {}
- void Init(const Array<NDArray>& consts) override {
+ void Init(const Array<Tensor>& consts) override {
op_execs_.resize(nodes_.size());
// get some config from the graph
for (size_t i = 0; i < nodes_.size(); ++i) {
diff --git a/src/runtime/contrib/cutlass/fp16_group_gemm.cuh b/src/runtime/contrib/cutlass/fp16_group_gemm.cuh
index cb26a0796d..ffc05893ca 100644
--- a/src/runtime/contrib/cutlass/fp16_group_gemm.cuh
+++ b/src/runtime/contrib/cutlass/fp16_group_gemm.cuh
@@ -21,7 +21,7 @@
#include <float.h>
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include "cutlass/bfloat16.h"
#include "cutlass/half.h"
@@ -33,8 +33,8 @@ template <int Arch, typename ElementA, typename ElementB, typename ElementC>
struct CutlassGroupGemm;
template <int Arch>
-void tvm_cutlass_group_gemm_impl(NDArray x, NDArray weight, NDArray indptr, NDArray workspace,
- NDArray out) {
+void tvm_cutlass_group_gemm_impl(Tensor x, Tensor weight, Tensor indptr, Tensor workspace,
+ Tensor out) {
// Workspace is used for storing device-side group gemm arguments and cutlass internal workspace.
// Recommened size is 4MB.
cudaStream_t stream =
diff --git a/src/runtime/contrib/cutlass/fp16_group_gemm_sm100.cu b/src/runtime/contrib/cutlass/fp16_group_gemm_sm100.cu
index 90802969c5..ef72c00080 100644
--- a/src/runtime/contrib/cutlass/fp16_group_gemm_sm100.cu
+++ b/src/runtime/contrib/cutlass/fp16_group_gemm_sm100.cu
@@ -21,8 +21,8 @@
#include <float.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/tensor.h>
#include "fp16_group_gemm.cuh"
#include "fp16_group_gemm_runner_sm100.cuh"
@@ -42,8 +42,8 @@ struct CutlassGroupGemm<100, ElementA, ElementB, ElementC> {
}
};
-void tvm_cutlass_group_gemm_sm100(NDArray x, NDArray weight, NDArray indptr, NDArray workspace,
- NDArray out) {
+void tvm_cutlass_group_gemm_sm100(Tensor x, Tensor weight, Tensor indptr, Tensor workspace,
+ Tensor out) {
tvm_cutlass_group_gemm_impl<100>(x, weight, indptr, workspace, out);
}
diff --git a/src/runtime/contrib/cutlass/fp16_group_gemm_sm90.cu b/src/runtime/contrib/cutlass/fp16_group_gemm_sm90.cu
index 0b240b85a4..508bc77f92 100644
--- a/src/runtime/contrib/cutlass/fp16_group_gemm_sm90.cu
+++ b/src/runtime/contrib/cutlass/fp16_group_gemm_sm90.cu
@@ -21,7 +21,7 @@
#include <float.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include "fp16_group_gemm.cuh"
#include "fp16_group_gemm_runner_sm90.cuh"
@@ -41,8 +41,8 @@ struct CutlassGroupGemm<90, ElementA, ElementB, ElementC> {
}
};
-void tvm_cutlass_group_gemm_sm90(NDArray x, NDArray weight, NDArray indptr, NDArray workspace,
- NDArray out) {
+void tvm_cutlass_group_gemm_sm90(Tensor x, Tensor weight, Tensor indptr, Tensor workspace,
+ Tensor out) {
tvm_cutlass_group_gemm_impl<90>(x, weight, indptr, workspace, out);
}
diff --git a/src/runtime/contrib/cutlass/fp8_gemm.cu b/src/runtime/contrib/cutlass/fp8_gemm.cu
index 5cabd0ca7a..2be8c09da2 100644
--- a/src/runtime/contrib/cutlass/fp8_gemm.cu
+++ b/src/runtime/contrib/cutlass/fp8_gemm.cu
@@ -22,7 +22,7 @@
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include "../cublas/cublas_utils.h"
#include "gemm_runner.cuh"
@@ -39,8 +39,7 @@ namespace tvm {
namespace runtime {
template <typename ElementA, typename ElementB, typename ElementC>
-void tvm_cutlass_fp8_gemm(NDArray x, NDArray weight, NDArray workspace, NDArray alpha,
- NDArray out) {
+void tvm_cutlass_fp8_gemm(Tensor x, Tensor weight, Tensor workspace, Tensor alpha, Tensor out) {
// Workspace is used for storing device-side gemm arguments and cutlass internal workspace.
// Recommened size is 4MB.
cudaStream_t stream =
diff --git a/src/runtime/contrib/cutlass/fp8_group_gemm_sm90.cu b/src/runtime/contrib/cutlass/fp8_group_gemm_sm90.cu
index 150485b868..48e68cb804 100644
--- a/src/runtime/contrib/cutlass/fp8_group_gemm_sm90.cu
+++ b/src/runtime/contrib/cutlass/fp8_group_gemm_sm90.cu
@@ -22,7 +22,7 @@
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include "fp16_group_gemm_runner_sm90.cuh"
@@ -42,8 +42,8 @@ namespace tvm {
namespace runtime {
template <typename ElementA, typename ElementB, typename ElementC>
-void tvm_cutlass_fp8_group_gemm(NDArray x, NDArray weight, NDArray indptr, NDArray workspace,
- NDArray alpha, NDArray out) {
+void tvm_cutlass_fp8_group_gemm(Tensor x, Tensor weight, Tensor indptr, Tensor workspace,
+ Tensor alpha, Tensor out) {
// Workspace is used for storing device-side group gemm arguments and cutlass internal workspace.
// Recommened size is 4MB.
cudaStream_t stream =
diff --git a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm.cuh b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm.cuh
index 0f688616d5..e03366a038 100644
--- a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm.cuh
+++ b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm.cuh
@@ -21,7 +21,7 @@
#include <float.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/extra/c_env_api.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include "cutlass/bfloat16.h"
#include "cutlass/half.h"
@@ -34,10 +34,10 @@ template <int Arch, typename TileShape, typename ClusterShape, typename ElementA
struct CutlassFP8GroupwiseGemm;
template <int Arch, typename TileShape, typename ClusterShape>
-void tvm_cutlass_fp8_groupwise_scaled_gemm_impl(NDArray a, NDArray b, NDArray scales_a,
- NDArray scales_b, NDArray workspace,
+void tvm_cutlass_fp8_groupwise_scaled_gemm_impl(Tensor a, Tensor b, Tensor scales_a,
+ Tensor scales_b, Tensor workspace,
int64_t block_size_0, int64_t block_size_1,
- NDArray out) {
+ Tensor out) {
// Workspace is used for storing device-side gemm arguments and cutlass internal workspace.
// Recommened size is 4MB.
cudaStream_t stream = static_cast<cudaStream_t>(TVMFFIEnvGetCurrentStream(kDLCUDA, a->device.device_id));
@@ -100,10 +100,10 @@ void tvm_cutlass_fp8_groupwise_scaled_gemm_impl(NDArray a, NDArray b, NDArray sc
}
template <int Arch, typename TileShape, typename ClusterShape>
-void tvm_cutlass_fp8_groupwise_scaled_bmm_impl(NDArray a, NDArray b, NDArray scales_a,
- NDArray scales_b, NDArray workspace,
+void tvm_cutlass_fp8_groupwise_scaled_bmm_impl(Tensor a, Tensor b, Tensor scales_a,
+ Tensor scales_b, Tensor workspace,
int64_t block_size_0, int64_t block_size_1,
- NDArray out) {
+ Tensor out) {
// Workspace is used for storing device-side gemm arguments and cutlass internal workspace.
// Recommened size is 4MB.
cudaStream_t stream = static_cast<cudaStream_t>(TVMFFIEnvGetCurrentStream(kDLCUDA, a->device.device_id));
diff --git a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm100.cuh b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm100.cuh
index 95fc578fd4..87cd8108f9 100644
--- a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm100.cuh
+++ b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm100.cuh
@@ -53,7 +53,7 @@
}
using namespace cute;
-using tvm::runtime::NDArray;
+using tvm::runtime::Tensor;
template <typename TileShape, typename ClusterShape, typename ElementD>
struct CutlassFP8ScaledGroupwiseGemmRunnerSM100 {
diff --git a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm90.cuh b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm90.cuh
index 5ec9ed0839..d5321d157c 100644
--- a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm90.cuh
+++ b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_runner_sm90.cuh
@@ -54,7 +54,7 @@
using namespace cute;
using ProblemShape = Shape<int, int, int, int>;
-using tvm::runtime::NDArray;
+using tvm::runtime::Tensor;
template <typename TileShape, typename ClusterShape, typename ElementD, typename SchedulerType,
int ScaleGranularityM = 1>
diff --git a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm100.cu b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm100.cu
index 7201604a7c..bd2d2aa04f 100644
--- a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm100.cu
+++ b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm100.cu
@@ -21,8 +21,8 @@
#include <float.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/tensor.h>
#include "../cublas/cublas_utils.h"
#include "fp8_groupwise_scaled_gemm.cuh"
@@ -47,20 +47,20 @@ struct CutlassFP8GroupwiseGemm<100, TileShape, ClusterShape, ElementA, ElementB,
}
};
-void tvm_cutlass_fp8_groupwise_scaled_gemm_sm100(NDArray a, NDArray b, NDArray scales_a,
- NDArray scales_b, NDArray workspace,
+void tvm_cutlass_fp8_groupwise_scaled_gemm_sm100(Tensor a, Tensor b, Tensor scales_a,
+ Tensor scales_b, Tensor workspace,
int64_t block_size_0, int64_t block_size_1,
- NDArray out) {
+ Tensor out) {
using TileShape = Shape<_128, _128, _128>;
using ClusterShape = Shape<_1, _1, _1>;
tvm_cutlass_fp8_groupwise_scaled_gemm_impl<100, TileShape, ClusterShape>(
a, b, scales_a, scales_b, workspace, block_size_0, block_size_1, out);
}
-void tvm_cutlass_fp8_groupwise_scaled_bmm_sm100(NDArray a, NDArray b, NDArray scales_a,
- NDArray scales_b, NDArray workspace,
+void tvm_cutlass_fp8_groupwise_scaled_bmm_sm100(Tensor a, Tensor b, Tensor scales_a,
+ Tensor scales_b, Tensor workspace,
int64_t block_size_0, int64_t block_size_1,
- NDArray out) {
+ Tensor out) {
using TileShape = Shape<_128, _128, _128>;
using ClusterShape = Shape<_1, _1, _1>;
tvm_cutlass_fp8_groupwise_scaled_bmm_impl<100, TileShape, ClusterShape>(
diff --git a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm90.cu b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm90.cu
index 8099d91419..dc067038c7 100644
--- a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm90.cu
+++ b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_gemm_sm90.cu
@@ -21,8 +21,8 @@
#include <float.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/tensor.h>
#include "../cublas/cublas_utils.h"
#include "fp8_groupwise_scaled_gemm.cuh"
@@ -47,20 +47,19 @@ struct CutlassFP8GroupwiseGemm<90, TileShape, ClusterShape, ElementA, ElementB,
}
};
-void tvm_cutlass_fp8_groupwise_scaled_gemm_sm90(NDArray a, NDArray b, NDArray scales_a,
- NDArray scales_b, NDArray workspace,
+void tvm_cutlass_fp8_groupwise_scaled_gemm_sm90(Tensor a, Tensor b, Tensor scales_a,
+ Tensor scales_b, Tensor workspace,
int64_t block_size_0, int64_t block_size_1,
- NDArray out) {
+ Tensor out) {
using TileShape = Shape<_128, _128, _128>;
using ClusterShape = Shape<_1, _1, _1>;
tvm_cutlass_fp8_groupwise_scaled_gemm_impl<90, TileShape, ClusterShape>(
a, b, scales_a, scales_b, workspace, block_size_0, block_size_1, out);
}
-void tvm_cutlass_fp8_groupwise_scaled_bmm_sm90(NDArray a, NDArray b, NDArray scales_a,
- NDArray scales_b, NDArray workspace,
- int64_t block_size_0, int64_t block_size_1,
- NDArray out) {
+void tvm_cutlass_fp8_groupwise_scaled_bmm_sm90(Tensor a, Tensor b, Tensor scales_a, Tensor scales_b,
+ Tensor workspace, int64_t block_size_0,
+ int64_t block_size_1, Tensor out) {
using TileShape = Shape<_128, _128, _128>;
using ClusterShape = Shape<_1, _1, _1>;
tvm_cutlass_fp8_groupwise_scaled_bmm_impl<90, TileShape, ClusterShape>(
diff --git a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_group_gemm_sm100.cu b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_group_gemm_sm100.cu
index b9be378a9a..420f93d4f2 100644
--- a/src/runtime/contrib/cutlass/fp8_groupwise_scaled_group_gemm_sm100.cu
+++ b/src/runtime/contrib/cutlass/fp8_groupwise_scaled_group_gemm_sm100.cu
@@ -22,8 +22,8 @@
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/packed_func.h>
+#include <tvm/runtime/tensor.h>
#include "fp8_groupwise_scaled_group_gemm_runner_sm100.cuh"
@@ -32,10 +32,10 @@
namespace tvm {
namespace runtime {
-void tvm_fp8_groupwise_scaled_group_gemm_sm100(NDArray a, NDArray b, NDArray scales_a,
- NDArray scales_b, NDArray indptr, NDArray workspace,
+void tvm_fp8_groupwise_scaled_group_gemm_sm100(Tensor a, Tensor b, Tensor scales_a, Tensor scales_b,
+ Tensor indptr, Tensor workspace,
int64_t block_size_0, int64_t block_size_1,
- NDArray out) {
+ Tensor out) {
// Workspace is used for storing device-side group gemm arguments and cutlass internal workspace.
// Recommended size is 4MB.
cudaStream_t stream =
diff --git a/src/runtime/contrib/cutlass/weight_preprocess.cc b/src/runtime/contrib/cutlass/weight_preprocess.cc
index c403039c58..32c30450cf 100644
--- a/src/runtime/contrib/cutlass/weight_preprocess.cc
+++ b/src/runtime/contrib/cutlass/weight_preprocess.cc
@@ -19,7 +19,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include "cutlass_kernels/cutlass_preprocessors.h"
@@ -37,7 +37,7 @@ namespace runtime {
// The preprocessing functions are defined in C++, so we need to copy the input weight to CPU.
TVM_FFI_STATIC_INIT_BLOCK({
namespace refl = tvm::ffi::reflection;
- refl::GlobalDef().def("cutlass.ft_preprocess_weight", [](NDArray packed_weight, int sm,
+ refl::GlobalDef().def("cutlass.ft_preprocess_weight", [](Tensor packed_weight, int sm,
bool is_int4) {
bool is_2d = packed_weight->ndim == 2;
int num_experts = is_2d ? 1 : packed_weight->shape[0];
@@ -54,7 +54,7 @@ TVM_FFI_STATIC_INIT_BLOCK({
}
fastertransformer::preprocess_weights(output_cpu.data(), input_cpu.data(), num_experts, rows,
cols, is_int4, sm);
- auto out = NDArray::Empty(packed_weight.Shape(), packed_weight->dtype, packed_weight->device);
+ auto out = Tensor::Empty(packed_weight.Shape(), packed_weight->dtype, packed_weight->device);
out.CopyFromBytes(output_cpu.data(), output_cpu.size());
return out;
});
diff --git a/src/runtime/contrib/dnnl/dnnl_json_runtime.cc b/src/runtime/contrib/dnnl/dnnl_json_runtime.cc
index 59b162e765..eccfb913d1 100644
--- a/src/runtime/contrib/dnnl/dnnl_json_runtime.cc
+++ b/src/runtime/contrib/dnnl/dnnl_json_runtime.cc
@@ -24,7 +24,7 @@
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <string>
@@ -60,7 +60,7 @@ class DNNLJSONRuntime : public JSONRuntimeBase {
const char* kind() const override { return "dnnl_json"; }
- void Init(const Array<NDArray>& consts) override {
+ void Init(const Array<Tensor>& consts) override {
ICHECK_EQ(consts.size(), const_idx_.size())
<< "The number of input constants must match the number of required.";
diff --git a/src/runtime/contrib/hipblas/hipblas_json_runtime.cc b/src/runtime/contrib/hipblas/hipblas_json_runtime.cc
index 08866fc108..046c1c14b3 100644
--- a/src/runtime/contrib/hipblas/hipblas_json_runtime.cc
+++ b/src/runtime/contrib/hipblas/hipblas_json_runtime.cc
@@ -25,7 +25,7 @@
#include <tvm/ffi/extra/c_env_api.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <string>
@@ -47,7 +47,7 @@ class HipblasJSONRuntime : public JSONRuntimeBase {
const Array<String> const_names)
: JSONRuntimeBase(symbol_name, graph_json, const_names) {}
- void Init(const Array<NDArray>& consts) override {}
+ void Init(const Array<Tensor>& consts) override {}
ffi::Optional<ffi::Function> GetFunction(const String& name) override {
// JSONRuntimeBase::SetInputOutputBuffers(...) is not thread safe. Since HipblasJSONRuntime
@@ -75,8 +75,8 @@ class HipblasJSONRuntime : public JSONRuntimeBase {
: EntryID(outputs_[i - input_var_eid_.size()]);
const DLTensor* arg;
- if (auto opt_nd = args[i].as<NDArray>()) {
- NDArray arr = opt_nd.value();
+ if (auto opt_nd = args[i].as<Tensor>()) {
+ Tensor arr = opt_nd.value();
arg = arr.operator->();
} else {
arg = args[i].cast<DLTensor*>();
diff --git a/src/runtime/contrib/json/json_runtime.h b/src/runtime/contrib/json/json_runtime.h
index d9e5af60f2..ea32f7f1f2 100644
--- a/src/runtime/contrib/json/json_runtime.h
+++ b/src/runtime/contrib/json/json_runtime.h
@@ -26,8 +26,8 @@
#define TVM_RUNTIME_CONTRIB_JSON_JSON_RUNTIME_H_
#include <tvm/ffi/extra/module.h>
-#include <tvm/runtime/ndarray.h>
#include <tvm/runtime/profiling.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <string>
@@ -63,7 +63,7 @@ class JSONRuntimeBase : public ffi::ModuleObj {
}
/*! \brief Initialize a specific json runtime. */
- virtual void Init(const Array<NDArray>& consts) = 0;
+ virtual void Init(const Array<Tensor>& consts) = 0;
/*! \brief Invoke the execution engine to inteprete a specific json runtime. */
virtual void Run() = 0;
@@ -141,7 +141,7 @@ class JSONRuntimeBase : public ffi::ModuleObj {
ICHECK_EQ(args.size(), 1U);
std::lock_guard<std::mutex> guard(this->initialize_mutex_);
if (!this->initialized_) {
- this->Init(args[0].cast<Array<NDArray>>());
+ this->Init(args[0].cast<Array<Tensor>>());
this->initialized_ = true;
}
*rv = 0;
@@ -212,14 +212,14 @@ class JSONRuntimeBase : public ffi::ModuleObj {
: EntryID(outputs_[i - input_var_eid_.size()]);
const DLTensor* arg;
- if (auto opt_nd = args[i].as<NDArray>()) {
- NDArray arr = opt_nd.value();
+ if (auto opt_nd = args[i].as<Tensor>()) {
+ Tensor arr = opt_nd.value();
arg = arr.operator->();
} else {
arg = args[i].cast<DLTensor*>();
}
- // Assign input/output the NDArray pointers to data entry so that we can directly
+ // Assign input/output the Tensor pointers to data entry so that we can directly
// read/write host buffers.
data_entry_[eid] = arg;
}
@@ -268,9 +268,9 @@ class JSONRuntimeBase : public ffi::ModuleObj {
* \brief Set up the constants/weights for inference by binding their DLTensor pointer to
* the corresponding data entry.
*
- * \param consts A list of constant NDArray to be used.
+ * \param consts A list of constant Tensor to be used.
*/
- void SetupConstants(const Array<NDArray>& consts) {
+ void SetupConstants(const Array<Tensor>& consts) {
for (size_t i = 0; i < consts.size(); ++i) {
data_entry_[EntryID(const_idx_[i], 0)] = consts[i].operator->();
}
diff --git a/src/runtime/contrib/mrvl/mrvl_hw_runtime.cc b/src/runtime/contrib/mrvl/mrvl_hw_runtime.cc
index bc1eb77ea1..f9769d7909 100644
--- a/src/runtime/contrib/mrvl/mrvl_hw_runtime.cc
+++ b/src/runtime/contrib/mrvl/mrvl_hw_runtime.cc
@@ -26,7 +26,7 @@
#include <tvm/ffi/extra/module.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <string>
@@ -309,8 +309,8 @@ class MarvellHardwareModuleNode : public ffi::ModuleObj {
i_d_buf_float = reinterpret_cast<float*>(i_d_buf);
for (int in = 0; in < num_inputs_; in++) {
- if (args[in].IsObjectRef<NDArray>()) {
- NDArray arr = args[in];
+ if (args[in].IsObjectRef<Tensor>()) {
+ Tensor arr = args[in];
tensor = arr.operator->();
} else {
tensor = args[in].operator DLTensor*();
@@ -345,8 +345,8 @@ class MarvellHardwareModuleNode : public ffi::ModuleObj {
int out = num_inputs_;
if (num_outputs_ == 1) {
- if (args[out].IsObjectRef<NDArray>()) {
- NDArray arr = args[out];
+ if (args[out].IsObjectRef<Tensor>()) {
+ Tensor arr = args[out];
outTensor = arr.operator->();
} else {
outTensor = args[out].operator DLTensor*();
@@ -361,8 +361,8 @@ class MarvellHardwareModuleNode : public ffi::ModuleObj {
for (out = num_inputs_; out < args.size(); out++) {
int out_tot_dim = 1;
- if (args[out].IsObjectRef<NDArray>()) {
- NDArray arr = args[out];
+ if (args[out].IsObjectRef<Tensor>()) {
+ Tensor arr = args[out];
outTensor = arr.operator->();
} else {
outTensor = args[out].operator DLTensor*();
@@ -382,8 +382,8 @@ class MarvellHardwareModuleNode : public ffi::ModuleObj {
const DLTensor* tensor[64];
for (int in = 0; in < num_inputs_; in++) {
- if (args[in].IsObjectRef<NDArray>()) {
- NDArray arr = args[in];
+ if (args[in].IsObjectRef<Tensor>()) {
+ Tensor arr = args[in];
tensor[in] = arr.operator->();
} else {
tensor[in] = args[in].operator DLTensor*();
@@ -398,8 +398,8 @@ class MarvellHardwareModuleNode : public ffi::ModuleObj {
int i = 0;
for (int out = num_inputs_; out < args.size(); out++) {
- if (args[out].IsObjectRef<NDArray>()) {
- NDArray arr = args[out];
+ if (args[out].IsObjectRef<Tensor>()) {
+ Tensor arr = args[out];
tensor[i] = arr.operator->();
} else {
tensor[i] = args[out].operator DLTensor*();
diff --git a/src/runtime/contrib/mrvl/mrvl_runtime.cc b/src/runtime/contrib/mrvl/mrvl_runtime.cc
index 974ca4a69a..af384035c9 100644
--- a/src/runtime/contrib/mrvl/mrvl_runtime.cc
+++ b/src/runtime/contrib/mrvl/mrvl_runtime.cc
@@ -27,7 +27,7 @@
#include <tvm/ffi/extra/module.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <cstddef>
#include <fstream>
diff --git a/src/runtime/contrib/mrvl/mrvl_sw_runtime_lib.cc b/src/runtime/contrib/mrvl/mrvl_sw_runtime_lib.cc
index c63bafcd00..8e68cf7e69 100644
--- a/src/runtime/contrib/mrvl/mrvl_sw_runtime_lib.cc
+++ b/src/runtime/contrib/mrvl/mrvl_sw_runtime_lib.cc
@@ -26,7 +26,7 @@
#include <assert.h>
#include <tvm/ffi/function.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <fstream>
#include <vector>
@@ -36,7 +36,7 @@
using namespace tvm::runtime;
template <typename T>
-static void NDArrayToFile(const tvm::runtime::NDArray& arr, std::ostream& os) {
+static void TensorToFile(const tvm::runtime::Tensor& arr, std::ostream& os) {
int ndim = arr->ndim;
int tot_dim = 1;
for (int i = 0; i < ndim; i++) {
@@ -70,8 +70,8 @@ static void ReadInputsAndGenerateInputBin(ffi::PackedArgs args, const std::strin
file_out << R"( "inputs": [)" << std::endl;
for (size_t i = 0; i < num_inputs; ++i) {
const DLTensor* tensor;
- if (args[i].IsObjectRef<NDArray>()) {
- NDArray arr = args[i];
+ if (args[i].IsObjectRef<Tensor>()) {
+ Tensor arr = args[i];
tensor = arr.operator->();
} else {
tensor = args[i].cast<DLTensor*>();
@@ -80,9 +80,9 @@ static void ReadInputsAndGenerateInputBin(ffi::PackedArgs args, const std::strin
for (int64_t i = 0; i < tensor->ndim; i++) {
shape.push_back(tensor->shape[i]);
}
- NDArray arr = NDArray::Empty(shape, tensor->dtype, tensor->device);
+ Tensor arr = Tensor::Empty(shape, tensor->dtype, tensor->device);
arr.CopyFrom(tensor);
- NDArrayToFile<float>(arr, file_out);
+ TensorToFile<float>(arr, file_out);
if (i != num_inputs - 1) {
file_out << std::endl << "\t," << std::endl;
}
@@ -108,8 +108,8 @@ static void ReadOutputsAndUpdateRuntime(ffi::PackedArgs args, size_t num_inputs,
const std::string& out_bin_prefix) {
for (int out = num_inputs; out < args.size(); out++) {
const DLTensor* outTensor;
- if (args[out].IsObjectRef<NDArray>()) {
- NDArray arr = args[out];
+ if (args[out].IsObjectRef<Tensor>()) {
+ Tensor arr = args[out];
outTensor = arr.operator->();
} else {
outTensor = args[out].operator DLTensor*();
@@ -118,7 +118,7 @@ static void ReadOutputsAndUpdateRuntime(ffi::PackedArgs args, size_t num_inputs,
for (int64_t i = 0; i < outTensor->ndim; i++) {
shape.push_back(outTensor->shape[i]);
}
- NDArray arr = NDArray::Empty(shape, outTensor->dtype, outTensor->device);
+ Tensor arr = Tensor::Empty(shape, outTensor->dtype, outTensor->device);
int ndim = arr->ndim;
int tot_dim = 1;
for (int i = 0; i < ndim; i++) {
diff --git a/src/runtime/contrib/msc/tensorrt_runtime.cc b/src/runtime/contrib/msc/tensorrt_runtime.cc
index 37ae9f2548..3a5f7c02de 100644
--- a/src/runtime/contrib/msc/tensorrt_runtime.cc
+++ b/src/runtime/contrib/msc/tensorrt_runtime.cc
@@ -25,7 +25,7 @@
#include <dmlc/parameter.h>
#include <tvm/ffi/function.h>
#include <tvm/ffi/reflection/registry.h>
-#include <tvm/runtime/ndarray.h>
+#include <tvm/runtime/tensor.h>
#include <fstream>
#include <memory>
@@ -87,7 +87,7 @@ class MSCTensorRTRuntime : public JSONRuntimeBase {
*
* \param consts The constant params from compiled model.
*/
- void Init(const Array<NDArray>& consts) override {
+ void Init(const Array<Tensor>& consts) override {
ICHECK_EQ(consts.size(), const_idx_.size())
... 13696 lines suppressed ...