6 Commits

Author SHA1 Message Date
Tianqi Chen 1e1920bcbd [REFACTOR][IR] Unify PrimExpr type mechanism to PrimType instead of DataType (#19875)
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
2026-06-24 21:31:47 -04:00
Tianqi Chen 561ead9512 [REFACTOR][FFI] Cleanup ffi indirections in tvm headers + switch logging.h to ffi/error.h where only ICHECK/THROW are used (#19483)
## 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
2026-05-01 07:56:52 +08:00
Tianqi Chen f533d0b3c1 [REFACTOR] Migrate CHECK macros to tvm-ffi ones (#18803) 2026-02-21 09:00:44 -05:00
Tianqi Chen 3c36ce2ec6 [FFI][REFACTOR][ABI] Rename NDArray to Tensor (#18275)
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.
2025-09-06 14:33:59 -07:00
Tianqi Chen a531d170b9 [REFACTOR] Phase out relay c++ components (#17660)
* 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>
2025-02-17 22:21:37 +08:00
Lite Ye 0b4836739c Skip stride check if shape is 1 in IsContiguous (#13121)
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.
2022-10-19 09:15:52 +09:00