In the past we have been using `DataType` in PrimExpr.dtype field to
check type information for PrimExpr while still having BaseExpr.ty for
richer type information. DataType is also used both in runtime and
compiler. This PR streamlines the boundary:
- PrimExpr.ty now carries PrimType that replaces original use of
`DataType`
- Runtime use will now favor DLPack DLDataType, removing one layer of
indirection.
- Constants attributes where values are usually runtime values, will use
`DLDataType`
- DataType will be phased out after this PR
We also brings up helper functions in PrimType, but also limits them to
a more concise set so the functions do not grow with the data type codes
in DLPack.
This is a major refactor that changes the IR primitive. It helps to
bring possible future benefits:
- Unified type mechanism through Expr.ty
- Possibility of carry future Type nodes
Migration Guide:
- Use `PrimType` when code reasons about compiler expression types,
tensor element compiler types, or constructs a `PrimExpr`/compiler type.
- Use existing source types such as `expr.ty()`, `ExprOp.expr_ty()`, or
TE tensor element `dtype` where possible instead of rebuilding a type
from dtype text.
- Use raw `DLDataType` for runtime constants, ABI paths, dtype-valued
attrs, and storage/runtime helper logic.
- Prefer direct `PrimType` equality, `MatchesCode(...)`,
`MatchesElementType(...)`, and `WithCode(...)` over local wrappers or
string dtype checks.
Performance:
Using Object type instead of DLDataType would indeed bring some
performance impact to the IR. We have done the following performance
optimizations:
- Make sure most of the outputs reuse one of the PrimType from inputs
- Cache a thread local PrimType based on input so we don't repeatly
realloc
We did benchmarks show that rewrite simplify operation stays within
+-10% overhead of original one. Which merits the refactor given the
benefit the unfication brings
## Background
This PR continues the FFI migration work. It focuses on two cleanup
themes:
## Theme 1: Drop ffi indirection aliases from TVM headers
Many TVM headers contained `using` re-export aliases like:
```cpp
using String = ffi::String;
using Array = ffi::Array;
using Map = ffi::Map;
// etc.
```
These aliases were introduced as a transitional shim. Now that the
codebase has stabilized,
they create confusion about which namespace owns each type. This commit
removes these aliases
and rewrites all call sites to use `ffi::` names directly.
Files changed: ~103 files across `include/` and `src/`.
## Theme 2: Switch icheck-only callers from `runtime/logging.h` to
`ffi/error.h`
64 files were `#include <tvm/runtime/logging.h>` solely to use
`TVM_FFI_ICHECK` and/or
`TVM_FFI_THROW`. Those macros are now directly declared in
`<tvm/ffi/error.h>`, so the
heavier logging header is not needed for that purpose.
These files now include `<tvm/ffi/error.h>` instead, keeping the
dependency chain leaner.
Files that also use `LOG(...)` / `VLOG(...)` / `DLOG(...)` logging
macros retain the
`runtime/logging.h` include unchanged.
Files changed: ~120 files across `include/` and `src/`.
## Testing
- `tests/python/all-platform-minimal-test/`: 16 passed, 126 skipped
- `tests/python/tirx-base/`: 251 passed, 23 skipped
- pre-commit (clang-format, cpplint): all passed
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.
* cleanup relay c++
* [REFACTOR] Phase out relay c++ components
This PR phases out the relay C++ components and
simplifies the overall codegen runtime logic.
---------
Co-authored-by: Siyuan Feng <hzfengsy@sjtu.edu.cn>
Skip checking stride if shape is 1 in IsContiguous
Skip stride check if shape[k] is 1, where the dimension is contiguous
regardless of the value of stride.
For example, PyTorch will normalize stride to 1 if shape is 1.