You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/06/23 15:44:11 UTC

[PR] [REFACTOR][IR] Use PrimType for compiler dtypes [tvm]

tqchen opened a new pull request, #19875:
URL: https://github.com/apache/tvm/pull/19875

   This PR removes the old runtime `DataType` wrapper as the compiler-facing dtype abstraction and routes dtype usage by boundary:
   
   - compiler/type constructs use `PrimType` for expression and tensor element type reasoning
   - runtime, ABI, and dtype-valued attrs use raw `DLDataType`
   - `PrimType` stays minimal but useful: documented factories/matchers, value equality/hash, final/non-null type, and cached common constructors
   - TIRX, TE, TOPI, Relax, codegen, Python bindings, and tests are updated to follow the boundary
   
   The branch is intentionally stacked on #19874 (`2bdedc93aa`) so CI has the needed base fix.
   
   Validation:
   
   - `pre-commit run --files $(cat /tmp/tvm_task199_final_changed_files.txt)` passed over 420 changed files
   - `git diff --check` passed
   - final grep found no `PrimType::IsPredicate`, `.IsBool(`, `.IsInt(`, `.IsUInt(`, removed `type.cc` helper names, or `runtime/data_type.h` references in checked paths
   - LLVM-enabled `ninja -C build -j$(nproc)` completed and linked `lib/libtvm_compiler.so`
   - focused Python pytest passed: `77 passed, 4 skipped, 1 warning` over TIRX ops/intrinsics, Relax qdq/manipulate legalizers, and contrib sort
   - direct TOPI smoke passed for touched math/scatter paths
   - reduced benchmark matrix was rerun from the final branch state; results are recorded in the task report
   
   Benchmark summary (ns/op, old DataType -> current PrimType):
   
   - IntImm int32 immediate: 9.78 -> 13.06
   - IntImm int64 immediate: 10.10 -> 12.97
   - a+b int32 immediate: 23.35 -> 42.90
   - a+b float32 immediate: 23.22 -> 41.54
   - canonical split-fuse simplify: 3892.61 -> 4608.44
   - rewrite split-fuse simplify: 22536.85 -> 29550.93
   - rewrite bool-vector simplify: 1090.19 -> 1453.94
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][IR] Unify PrimExpr type mechanism to PrimType instead of DataType [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #19875:
URL: https://github.com/apache/tvm/pull/19875


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][IR] Use PrimType for compiler dtypes [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #19875:
URL: https://github.com/apache/tvm/pull/19875#issuecomment-4781695997

   /gemini Please run another review pass on latest head 4b0c660668. Since the last pass, I fixed CI compile failures in CBLAS/CUBLAS/HIPBLAS/MKL/DNNL/CUDNN/random and CUDA runtime paths after DataType helper removal: contrib backends now use direct raw DLDataType equality instead of TypeMatch/TypeEqual/runtime namespace helpers, and CUDA tensor-map runtime code uses raw DLDataType fields. Local validation: changed-file pre-commit passed, LLVM-enabled ninja build passed, and syntax-only checks passed for the reported disabled-backend sources with local CUDA/CUDNN/CBLAS/DNNL headers.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][IR] Use PrimType for compiler dtypes [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19875:
URL: https://github.com/apache/tvm/pull/19875#discussion_r3461058247


##########
src/relax/op/memory/view.cc:
##########
@@ -167,16 +167,15 @@ Type InferTypeView(const Call& call, const BlockBuilder& ctx) {
     output_ndim = data_ty->ndim;
   }
 
-  DataType output_dtype = view_dtype.value_or(data_ty->dtype);
+  DLDataType output_raw_dtype = view_dtype.value_or(data_ty->dtype->dtype);
+  PrimType output_dtype(output_raw_dtype);
 
-  // Helper function, returns the number of bytes per vectorized
-  // element.  Cannot use `DataType::bytes`, as it returns the
-  // number of bytes per scalar element.
-  auto get_size_bytes = [](const DataType& dtype) -> ffi::Optional<IntImm> {
-    if (dtype.is_void()) {
+  // Helper function returns the number of bytes per vectorized element.
+  auto get_size_bytes = [](DLDataType dtype) -> ffi::Optional<IntImm> {
+    if ((((dtype).code == kDLOpaqueHandle) && ((dtype).bits == 0) && ((dtype).lanes == 0))) {
       return std::nullopt;
     } else {
-      auto size_bits = dtype.bits() * dtype.lanes();
+      auto size_bits = ((dtype).bits) * static_cast<int16_t>((dtype).lanes);
       return IntImm::Int64((size_bits + 7) / 8);
     }
   };

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   We should use the `PrimType` wrapper to safely retrieve the lanes and bits, and handle scalable vectors by returning `std::nullopt` since their size cannot be determined at compile time.
   
   ```c
     auto get_size_bytes = [](DLDataType dtype) -> ffi::Optional<IntImm> {\n    PrimType prim_type(dtype);\n    if (prim_type.IsVoid() || prim_type.IsScalableVector()) {\n      return std::nullopt;\n    } else {\n      auto size_bits = prim_type.bits() * prim_type.lanes();\n      return IntImm::Int64((size_bits + 7) / 8);\n    }\n  };
   ```



##########
src/relax/transform/lower_alloc_tensor.cc:
##########
@@ -72,7 +72,8 @@ class Mutator : public ExprMutator {
       }();
 
       PrimExpr nbytes = [&]() -> PrimExpr {
-        PrimExpr nbytes = IntImm::Int64(dtype->value.bytes());
+        PrimExpr nbytes = IntImm::Int64(
+            ((((dtype->value).bits * static_cast<int16_t>((dtype->value).lanes)) + 7) / 8));
         for (const auto& dim : shape) {
           nbytes *= dim;
         }

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   When calculating `nbytes` for the tensor allocation, using raw `static_cast<int16_t>((dtype->value).lanes)` directly bypasses the safety checks in `PrimType`. If the tensor has a scalable vector dtype, this will silently produce a negative or overflowed size at compile time.\n\nWe should use the `PrimType` wrapper to safely retrieve the lanes and bits, and explicitly check that it is not a scalable vector.
   
   ```c
         PrimExpr nbytes = [&]() -> PrimExpr {\n        PrimType prim_type(dtype->value);\n        TVM_FFI_ICHECK(!prim_type.IsScalableVector())\n            << "Cannot allocate tensor with scalable vector dtype at compile time.";\n        PrimExpr nbytes = IntImm::Int64((prim_type.bits() * prim_type.lanes() + 7) / 8);\n        for (const auto& dim : shape) {\n          nbytes *= dim;\n        }
   ```



##########
src/relax/transform/utils.h:
##########
@@ -319,39 +319,39 @@ class FunctionCopier : public SymbolicVarRenewMutator {
  * \return A Constant.
  */
 template <typename T>
-inline Constant MakeConstantScalar(T value, DataType dtype) {
+inline Constant MakeConstantScalar(T value, DLDataType dtype) {
   runtime::Tensor arr = runtime::Tensor::Empty({}, dtype, {kDLCPU, 0});
-  if (dtype == DataType::Float(32)) {
+  if (dtype == DLDataType{kDLFloat, 32, 1}) {
     *static_cast<float*>(arr->data) = static_cast<float>(value);
-  } else if (dtype == DataType::Float(64)) {
+  } else if (dtype == DLDataType{kDLFloat, 64, 1}) {
     *static_cast<double*>(arr->data) = static_cast<double>(value);
-  } else if (dtype == DataType::Int(32)) {
+  } else if (dtype == DLDataType{kDLInt, 32, 1}) {
     *static_cast<int32_t*>(arr->data) = static_cast<int32_t>(value);
-  } else if (dtype == DataType::Int(64)) {
+  } else if (dtype == DLDataType{kDLInt, 64, 1}) {
     *static_cast<int64_t*>(arr->data) = static_cast<int64_t>(value);
-  } else if (dtype == DataType::Bool()) {
+  } else if (dtype == DLDataType{kDLBool, 1, 1}) {

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   In TVM, `kDLBool` is standardly represented with 8 bits (not 1 bit). Comparing `dtype` against `DLDataType{kDLBool, 1, 1}` will fail to match standard boolean constants, causing them to fall through or fail.\n\nWe should change the bit width check to `8` to match the standard boolean representation.
   
   ```c
     } else if (dtype == DLDataType{kDLBool, 8, 1}) {
   ```



##########
src/s_tir/analysis/verify_gpu_code.cc:
##########
@@ -202,38 +204,50 @@ class GPUCodeVerifier : public StmtExprVisitor {
   void CheckBufferIndicesVectorizable(const ffi::Array<PrimExpr> indices) {
     for (const auto index : indices) {
       if (const auto* ramp = index.as<RampNode>()) {
-        if (!is_one(ramp->stride) &&
-            static_cast<size_t>(ramp->dtype.lanes() * ramp->dtype.bytes()) > max_vector_bytes_) {
+        PrimType ramp_ty = ramp->ty();
+        DLDataType ramp_dtype = ramp_ty->dtype;
+        if (!is_one(ramp->stride) && ramp_ty.IsFixedLengthVector() &&
+            static_cast<size_t>(static_cast<int16_t>((ramp_dtype).lanes) *
+                                (((ramp_dtype).bits + 7) / 8)) > max_vector_bytes_) {
           std::stringstream s;
-          s << "Number of lanes (" << ramp->dtype.lanes() << ") times number of bytes ("
-            << ramp->dtype.bytes() << ") for dtype " << ramp->dtype
-            << " is greater than the maximum number of vector bytes (" << max_vector_bytes_ << ")";
+          s << "Number of lanes (" << static_cast<int16_t>((ramp_dtype).lanes)
+            << ") times number of bytes (" << (((ramp_dtype).bits + 7) / 8) << ") for dtype "
+            << ramp_dtype << " is greater than the maximum number of vector bytes ("
+            << max_vector_bytes_ << ")";
           errors_.push_back(s.str());
         }
       }
     }
   }
 
   void VisitExpr_(const CastNode* op) {
-    if (op->dtype.is_vector()) {
-      if (static_cast<size_t>(op->dtype.lanes() * op->dtype.bytes()) > max_vector_bytes_) {
+    PrimType op_ty = op->ty();
+    DLDataType op_dtype = op_ty->dtype;
+    if (op_ty.IsFixedLengthVector()) {
+      if (static_cast<size_t>(static_cast<int16_t>((op_dtype).lanes) *
+                              (((op_dtype).bits + 7) / 8)) > max_vector_bytes_) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can simplify this by using `op_ty.lanes()` and `op_ty.bits()` directly instead of unpacking to `DLDataType` and performing manual bit/lane arithmetic.
   
   ```c
       PrimType op_ty = op->ty();\n    if (op_ty.IsFixedLengthVector()) {\n      if (static_cast<size_t>(op_ty.lanes() * ((op_ty.bits() + 7) / 8)) > max_vector_bytes_) {
   ```



##########
src/s_tir/analysis/verify_gpu_code.cc:
##########
@@ -76,20 +76,22 @@ class GPUCodeVerifier : public StmtExprVisitor {
         break;
       }
     }
+    DLDataType dtype = op->buffer->dtype->dtype;
     if (storage_scope.rank == runtime::StorageRank::kLocal) {
-      local_memory_per_block_ +=
-          static_cast<size_t>(const_size) * op->buffer->dtype.bytes() * op->buffer->dtype.lanes();
+      local_memory_per_block_ += static_cast<size_t>(const_size) * (((dtype).bits + 7) / 8) *
+                                 static_cast<int16_t>((dtype).lanes);
     } else if (storage_scope.rank == runtime::StorageRank::kShared) {
-      shared_memory_per_block_ +=
-          static_cast<size_t>(const_size) * op->buffer->dtype.bytes() * op->buffer->dtype.lanes();
+      shared_memory_per_block_ += static_cast<size_t>(const_size) * (((dtype).bits + 7) / 8) *
+                                  static_cast<int16_t>((dtype).lanes);
     }
-    if (op->buffer->dtype.is_vector()) {
-      if (static_cast<size_t>(op->buffer->dtype.lanes() * op->buffer->dtype.bytes()) >
+    if ((static_cast<int16_t>((dtype).lanes) > 1)) {
+      if (static_cast<size_t>(static_cast<int16_t>((dtype).lanes) * (((dtype).bits + 7) / 8)) >

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Since `op->buffer->dtype` is already a `PrimType`, we can use its member functions `bits()` and `lanes()` directly instead of unpacking it to `DLDataType` and performing manual bit/lane arithmetic. This is safer and more readable.
   
   ```c
       PrimType dtype = op->buffer->dtype;\n    if (storage_scope.rank == runtime::StorageRank::kLocal) {\n      local_memory_per_block_ += static_cast<size_t>(const_size) * ((dtype.bits() + 7) / 8) *\n                                 dtype.lanes();\n    } else if (storage_scope.rank == runtime::StorageRank::kShared) {\n      shared_memory_per_block_ += static_cast<size_t>(const_size) * ((dtype.bits() + 7) / 8) *\n                                  dtype.lanes();\n    }\n    if (dtype.IsFixedLengthVector()) {\n      if (static_cast<size_t>(dtype.lanes() * ((dtype.bits() + 7) / 8)) >
   ```



##########
src/relax/transform/static_plan_block_memory.cc:
##########
@@ -135,10 +135,10 @@ class StorageTokenNode : public ffi::Object {
  */
 class StorageToken : public ffi::ObjectRef {
  public:
-  explicit StorageToken(ffi::Array<PrimExpr> shape, DataType dtype, std::string storage_scope,
+  explicit StorageToken(ffi::Array<PrimExpr> shape, DLDataType dtype, std::string storage_scope,
                         ffi::Optional<VDevice> vdevice = std::nullopt) {
     // Compute the tensor size from the shape.
-    int64_t const_coeff = dtype.bytes() * dtype.lanes();
+    int64_t const_coeff = ((((dtype).bits * static_cast<int16_t>((dtype).lanes)) + 7) / 8);

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   We should use the `PrimType` wrapper to safely retrieve the lanes and bits, and explicitly check that it is not a scalable vector to prevent negative/overflowed size calculations.
   
   ```c
     explicit StorageToken(ffi::Array<PrimExpr> shape, DLDataType dtype, std::string storage_scope,\n                        ffi::Optional<VDevice> vdevice = std::nullopt) {\n    // Compute the tensor size from the shape.\n    PrimType prim_type(dtype);\n    TVM_FFI_ICHECK(!prim_type.IsScalableVector())\n        << "Cannot allocate storage for scalable vector dtype at compile time.";\n    int64_t const_coeff = (prim_type.bits() * prim_type.lanes() + 7) / 8;
   ```



##########
src/s_tir/analysis/verify_gpu_code.cc:
##########
@@ -202,38 +204,50 @@ class GPUCodeVerifier : public StmtExprVisitor {
   void CheckBufferIndicesVectorizable(const ffi::Array<PrimExpr> indices) {
     for (const auto index : indices) {
       if (const auto* ramp = index.as<RampNode>()) {
-        if (!is_one(ramp->stride) &&
-            static_cast<size_t>(ramp->dtype.lanes() * ramp->dtype.bytes()) > max_vector_bytes_) {
+        PrimType ramp_ty = ramp->ty();
+        DLDataType ramp_dtype = ramp_ty->dtype;
+        if (!is_one(ramp->stride) && ramp_ty.IsFixedLengthVector() &&

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can simplify this by using `ramp_ty.lanes()` and `ramp_ty.bits()` directly instead of unpacking to `DLDataType` and performing manual bit/lane arithmetic.
   
   ```c
           PrimType ramp_ty = ramp->ty();\n        if (!is_one(ramp->stride) && ramp_ty.IsFixedLengthVector() &&\n            static_cast<size_t>(ramp_ty.lanes() * ((ramp_ty.bits() + 7) / 8)) > max_vector_bytes_) {
   ```



##########
src/s_tir/analysis/verify_gpu_code.cc:
##########
@@ -202,38 +204,50 @@ class GPUCodeVerifier : public StmtExprVisitor {
   void CheckBufferIndicesVectorizable(const ffi::Array<PrimExpr> indices) {
     for (const auto index : indices) {
       if (const auto* ramp = index.as<RampNode>()) {
-        if (!is_one(ramp->stride) &&
-            static_cast<size_t>(ramp->dtype.lanes() * ramp->dtype.bytes()) > max_vector_bytes_) {
+        PrimType ramp_ty = ramp->ty();
+        DLDataType ramp_dtype = ramp_ty->dtype;
+        if (!is_one(ramp->stride) && ramp_ty.IsFixedLengthVector() &&
+            static_cast<size_t>(static_cast<int16_t>((ramp_dtype).lanes) *
+                                (((ramp_dtype).bits + 7) / 8)) > max_vector_bytes_) {
           std::stringstream s;
-          s << "Number of lanes (" << ramp->dtype.lanes() << ") times number of bytes ("
-            << ramp->dtype.bytes() << ") for dtype " << ramp->dtype
-            << " is greater than the maximum number of vector bytes (" << max_vector_bytes_ << ")";
+          s << "Number of lanes (" << static_cast<int16_t>((ramp_dtype).lanes)
+            << ") times number of bytes (" << (((ramp_dtype).bits + 7) / 8) << ") for dtype "
+            << ramp_dtype << " is greater than the maximum number of vector bytes ("
+            << max_vector_bytes_ << ")";
           errors_.push_back(s.str());
         }
       }
     }
   }
 
   void VisitExpr_(const CastNode* op) {
-    if (op->dtype.is_vector()) {
-      if (static_cast<size_t>(op->dtype.lanes() * op->dtype.bytes()) > max_vector_bytes_) {
+    PrimType op_ty = op->ty();
+    DLDataType op_dtype = op_ty->dtype;
+    if (op_ty.IsFixedLengthVector()) {
+      if (static_cast<size_t>(static_cast<int16_t>((op_dtype).lanes) *
+                              (((op_dtype).bits + 7) / 8)) > max_vector_bytes_) {
         std::stringstream s;
-        s << "Number of lanes (" << op->dtype.lanes() << ") times number of bytes ("
-          << op->dtype.bytes() << ") for dtype " << op->dtype
-          << " is greater than the maximum number of vector bytes (" << max_vector_bytes_ << ")";
+        s << "Number of lanes (" << static_cast<int16_t>((op_dtype).lanes)
+          << ") times number of bytes (" << (((op_dtype).bits + 7) / 8) << ") for dtype "
+          << op_dtype << " is greater than the maximum number of vector bytes ("
+          << max_vector_bytes_ << ")";
         errors_.push_back(s.str());
       }
     }
     ExprVisitor::VisitExpr_(op);
   }
 
   void VisitExpr_(const BufferLoadNode* op) {
-    if (op->dtype.is_vector()) {
-      if (static_cast<size_t>(op->dtype.lanes() * op->dtype.bytes()) > max_vector_bytes_) {
+    PrimType op_ty = op->ty();
+    DLDataType op_dtype = op_ty->dtype;
+    if (op_ty.IsFixedLengthVector()) {
+      if (static_cast<size_t>(static_cast<int16_t>((op_dtype).lanes) *
+                              (((op_dtype).bits + 7) / 8)) > max_vector_bytes_) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can simplify this by using `op_ty.lanes()` and `op_ty.bits()` directly instead of unpacking to `DLDataType` and performing manual bit/lane arithmetic.
   
   ```c
       PrimType op_ty = op->ty();\n    if (op_ty.IsFixedLengthVector()) {\n      if (static_cast<size_t>(op_ty.lanes() * ((op_ty.bits() + 7) / 8)) > max_vector_bytes_) {
   ```



##########
src/s_tir/analysis/verify_gpu_code.cc:
##########
@@ -242,13 +256,16 @@ class GPUCodeVerifier : public StmtExprVisitor {
   }
 
   void VisitStmt_(const BufferStoreNode* op) {
-    if (op->value->dtype.is_vector()) {
-      if (static_cast<size_t>(op->value->dtype.lanes() * op->value->dtype.bytes()) >
-          max_vector_bytes_) {
+    PrimType value_ty = op->value.ty();
+    DLDataType value_dtype = value_ty->dtype;
+    if (value_ty.IsFixedLengthVector()) {
+      if (static_cast<size_t>(static_cast<int16_t>((value_dtype).lanes) *
+                              (((value_dtype).bits + 7) / 8)) > max_vector_bytes_) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can simplify this by using `value_ty.lanes()` and `value_ty.bits()` directly instead of unpacking to `DLDataType` and performing manual bit/lane arithmetic.
   
   ```c
       PrimType value_ty = op->value.ty();\n    if (value_ty.IsFixedLengthVector()) {\n      if (static_cast<size_t>(value_ty.lanes() * ((value_ty.bits() + 7) / 8)) > max_vector_bytes_) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][IR] Use PrimType for compiler dtypes [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19875:
URL: https://github.com/apache/tvm/pull/19875#discussion_r3461546596


##########
src/backend/hexagon/codegen/llvm/codegen_hexagon.cc:
##########
@@ -66,6 +66,11 @@
 namespace tvm {
 namespace codegen {
 
+TVM_FFI_INLINE int GetVectorBytes(const PrimType& dtype) {
+  TVM_FFI_ICHECK(dtype.IsFixedLengthVector() || dtype.IsScalar());
+  return dtype.bits() * dtype.lanes() / 8;
+}

Review Comment:
   ![critical](https://www.gstatic.com/codereviewagent/critical.svg)
   
   In `GetVectorBytes`, using `dtype.bits() * dtype.lanes() / 8` can return `0` for sub-byte types (such as 4-bit integers or booleans). This will lead to a division-by-zero error in `VectorLookupLoad` where `native_vector_bytes / GetVectorBytes(buffer_type)` is calculated. Using `(dtype.bits() * dtype.lanes() + 7) / 8` safely computes the byte size and prevents this potential compiler crash.
   
   ```c
   TVM_FFI_INLINE int GetVectorBytes(const PrimType& dtype) {
     TVM_FFI_ICHECK(dtype.IsFixedLengthVector() || dtype.IsScalar());
     return (dtype.bits() * dtype.lanes() + 7) / 8;
   }
   ```



##########
python/tvm/ir/expr.py:
##########
@@ -43,7 +43,10 @@ class PrimExpr(BaseExpr):
     optimizations and integer analysis.
     """
 
-    dtype: str
+    @property
+    def dtype(self):
+        """Return the runtime dtype represented by this expression's PrimType."""
+        return self.ty.dtype

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The `dtype` property on `PrimExpr` is implemented as `return self.ty.dtype`. However, `self.ty` can be `None` or a `PointerType` (which does not have a `dtype` attribute). This will raise an `AttributeError` when accessing `.dtype` on handle variables or un-typed expressions. Adding safety checks to handle `None` and `PointerType` (returning `"handle"` for pointers) ensures backward compatibility and robustness.
   
   ```suggestion
       @property
       def dtype(self):
           """Return the runtime dtype represented by this expression's PrimType."""
           if self.ty is None:
               return None
           if hasattr(self.ty, "dtype"):
               return self.ty.dtype
           return "handle"
   ```



##########
include/tvm/topi/detail/broadcast.h:
##########
@@ -56,15 +58,15 @@ inline BroadcastHelper BroadcastShape(const tvm::ffi::Array<tvm::PrimExpr>& shap
   tvm::PrimExpr one(1);
   int i;
 
-  auto cast_if_needed = [](DataType to_type, PrimExpr expr) {
-    return to_type != expr.dtype() ? cast(to_type, expr) : expr;
+  auto cast_if_needed = [](PrimType to_type, PrimExpr expr) {
+    return to_type->dtype == expr.ty()->dtype ? expr : cast(to_type, expr);
   };

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Since `PrimType` has `operator==` defined, the check `to_type->dtype == expr.ty()->dtype` can be simplified to `to_type == expr.ty()`.
   
   ```suggestion
     auto cast_if_needed = [](PrimType to_type, PrimExpr expr) {
       return to_type == expr.ty() ? expr : cast(to_type, expr);
     };
   ```



##########
include/tvm/topi/detail/broadcast.h:
##########
@@ -42,10 +42,12 @@ struct BroadcastHelper {
   std::deque<tvm::tirx::Var> vars2;
 };
 
-static inline DataType CommonType(DataType type1, DataType type2) {
-  TVM_FFI_ICHECK(type1.is_scalar() && type2.is_scalar());
+static inline PrimType CommonType(const PrimType& type1, const PrimType& type2) {
+  TVM_FFI_ICHECK(!type1.IsScalableVector() && !type2.IsScalableVector());
+  TVM_FFI_ICHECK_EQ(type1.lanes(), 1);
+  TVM_FFI_ICHECK_EQ(type2.lanes(), 1);

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The checks to ensure `type1` and `type2` are scalar can be simplified and made more robust by using the newly introduced `IsScalar()` helper method on `PrimType`.
   
   ```suggestion
     TVM_FFI_ICHECK(type1.IsScalar() && type2.IsScalar());
   ```



##########
src/arith/const_fold.h:
##########
@@ -72,18 +72,29 @@ inline ffi::Optional<PrimExpr> TryConstFold(PrimExpr a);
  * \param type The type to represent index.
  * \return the checked result.
  */
-inline bool IsIndexType(const DataType& type) {
-  return type.is_int() && !type.is_scalable_or_fixed_length_vector() &&
-         (type.bits() == 32 || type.bits() == 64);
+inline bool IsIndexType(DLDataType type) {
+  return type.code == static_cast<uint8_t>(DLDataTypeCode::kDLInt) &&
+         (type.bits == 32 || type.bits == 64) && type.lanes == 1;
+}
+
+inline bool IsIndexTypedExpr(const PrimExprNode* expr) {
+  TVM_FFI_DCHECK(expr != nullptr);
+  TVM_FFI_DCHECK(expr->BaseExprNode::ty.defined());
+  const auto* prim_ty = expr->BaseExprNode::ty.as<PrimTypeNode>();
+  TVM_FFI_DCHECK(prim_ty != nullptr);
+  return IsIndexType(prim_ty->dtype);

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The manual checks on `expr->BaseExprNode::ty` are redundant because `PrimExprNode::ty()` already implements these checks and returns `PrimType`. We can simplify this to a single call to `expr->ty()`.
   
   ```suggestion
     return IsIndexType(expr->ty()->dtype);
   ```



##########
src/s_tir/transform/bound_checker.cc:
##########
@@ -175,7 +177,9 @@ class BoundChecker : public StmtExprMutator {
   }
 
   bool IsValidScalar(const PrimExpr& expr) const {
-    return expr.defined() && expr.dtype().is_scalar();
+    if (!expr.defined()) return false;

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The check `!ty.IsFixedLengthVector() && !ty.IsScalableVector()` can be simplified using the `IsScalar()` helper method on `PrimType`.
   
   ```c
       return expr.defined() && expr.ty().IsScalar();
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][IR] Use PrimType for compiler dtypes [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #19875:
URL: https://github.com/apache/tvm/pull/19875#issuecomment-4781545387

   /gemini Please run another review pass on latest head b8c7505222. Since the last pass, I applied the Gemini MatchesCode cleanups, fixed the Python PrimType-to-runtime-dtype boundary in Relax gradient constants and TE NumPy test uses, reran full LLVM build plus focused Relax/TE/TIRX validation, and resolved the previous review threads that are addressed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][IR] Use PrimType for compiler dtypes [tvm]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19875:
URL: https://github.com/apache/tvm/pull/19875#discussion_r3461433341


##########
src/relax/op/nn/nn.cc:
##########
@@ -186,10 +188,14 @@ Type InferTypeSoftmax(const Call& call, const BlockBuilder& ctx) {
   if (data_ty->IsUnknownNdim()) {
     return data_ty;
   }
-  if (!data_ty->IsUnknownDtype() && !data_ty->dtype.is_float() && !data_ty->dtype.is_bfloat()) {
-    TVM_FFI_VISIT_THROW(TypeError, call) << "Softmax requires the input tensor to have float "
-                                            "dtype. However, the given input dtype is "
-                                         << data_ty->dtype;
+  if (!data_ty->IsUnknownDtype()) {
+    PrimType data_dtype = data_ty->dtype;
+    // Softmax only requires a floating element kind; lane encoding is irrelevant to the check.
+    if (data_dtype.code() != kDLFloat && data_dtype.code() != kDLBfloat) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLFloat` and `kDLBfloat`.
   
   ```suggestion
       if (!data_dtype.MatchesCode(kDLFloat, kDLBfloat)) {
   ```



##########
src/relax/op/nn/nn.cc:
##########
@@ -380,10 +386,14 @@ bool NormCheckDtypeAndShape(const Call& call, const BlockBuilder& ctx,
     axes_non_neg = NormalizeAxes(call, ctx, data_ty->ndim, axes);
   }
   int n_axis = axes.size();
-  if (!data_ty->IsUnknownDtype() && (!data_ty->dtype.is_float() && !data_ty->dtype.is_bfloat())) {
-    TVM_FFI_VISIT_THROW(TypeError, call)
-        << op << " requires the input data to have float dtype. However, the given data dtype is "
-        << data_ty->dtype;
+  if (!data_ty->IsUnknownDtype()) {
+    PrimType data_dtype = data_ty->dtype;
+    // Norm ops only require a floating element kind; lane encoding is irrelevant to the check.
+    if (data_dtype.code() != kDLFloat && data_dtype.code() != kDLBfloat) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLFloat` and `kDLBfloat`.
   
   ```suggestion
       if (!data_dtype.MatchesCode(kDLFloat, kDLBfloat)) {
   ```



##########
src/relax/op/tensor/index.cc:
##########
@@ -84,11 +84,15 @@ Type InferTypeTake(const Call& call, const BlockBuilder& ctx) {
 
   if (indices_ty->IsUnknownDtype()) {
     LOG(WARNING) << "Data type of indices has not been specified. Assume it has an integer type.";
-  } else if (!(indices_ty->dtype.is_int() || indices_ty->dtype.is_uint())) {
-    TVM_FFI_VISIT_THROW(TypeError, call)
-        << "Take op requires the input indices to have integer dtype. However, the "
-           "given indices dtype is "
-        << indices_ty->dtype;
+  } else {
+    PrimType indices_dtype = indices_ty->dtype;
+    if (!indices_dtype.MatchesCode(DLDataTypeCode::kDLInt) &&
+        !indices_dtype.MatchesCode(DLDataTypeCode::kDLUInt)) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Instead of calling `MatchesCode` twice separately for `kDLInt` and `kDLUInt`, you can simplify this check by passing both codes to a single `MatchesCode` call. `MatchesCode` is a variadic template designed exactly for this purpose.
   
   ```c
       if (!indices_dtype.MatchesCode(DLDataTypeCode::kDLInt, DLDataTypeCode::kDLUInt)) {
   ```



##########
src/relax/op/nn/nn.cc:
##########
@@ -122,7 +122,9 @@ Type InferTypePRelu(const Call& call, const BlockBuilder& ctx) {
   if (data_ty->IsUnknownNdim()) {
     return data_ty;
   }
-  if (!data_ty->IsUnknownDtype() && !data_ty->dtype.is_float()) {
+  PrimType data_dtype = data_ty->dtype;
+  // PRelu preserves the old float-kind check; vector lanes are irrelevant to this check.
+  if (!data_ty->IsUnknownDtype() && data_dtype.code() != DLDataTypeCode::kDLFloat) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLFloat`.
   
   ```suggestion
     if (!data_ty->IsUnknownDtype() && !data_dtype.MatchesCode(DLDataTypeCode::kDLFloat)) {
   ```



##########
src/relax/op/distributed/nn.cc:
##########
@@ -33,7 +33,9 @@ Type InferDistTypeSoftmax(const Call& call, const BlockBuilder& ctx) {
   if (input_tensor_ty->IsUnknownNdim()) {
     TVM_FFI_VISIT_THROW(ValueError, call) << "Input of distributed operator must have known ndim";
   }
-  if (!input_tensor_ty->IsUnknownDtype() && !input_tensor_ty->dtype.is_float()) {
+  PrimType input_dtype = input_tensor_ty->dtype;
+  // Softmax validation preserves the old float-kind check; lanes do not affect this policy.
+  if (!input_tensor_ty->IsUnknownDtype() && input_dtype.code() != DLDataTypeCode::kDLFloat) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLFloat`.
   
   ```suggestion
     if (!input_tensor_ty->IsUnknownDtype() && !input_dtype.MatchesCode(DLDataTypeCode::kDLFloat)) {
   ```



##########
src/relax/op/distributed/unary.h:
##########
@@ -40,15 +40,22 @@ Type InferDistTypeUnary(const Call& call, const BlockBuilder& ctx, FType f_compu
   distributed::DTensorType input_dtensor_ty = input_dtensor_tys[0];
   TensorType input_tensor_ty = input_dtensor_ty->tensor_ty;
 
+  PrimType input_dtype = input_tensor_ty->dtype;
+  // Unary op validation preserves the old float-kind check; lanes do not affect this policy.
   if (require_float_dtype && !input_tensor_ty->IsUnknownDtype() &&
-      !input_tensor_ty->dtype.is_float()) {
+      input_dtype.code() != DLDataTypeCode::kDLFloat) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLFloat`.
   
   ```suggestion
     if (require_float_dtype && !input_tensor_ty->IsUnknownDtype() &&
         !input_dtype.MatchesCode(DLDataTypeCode::kDLFloat)) {
   ```



##########
src/arith/const_fold.h:
##########
@@ -72,18 +72,29 @@ inline ffi::Optional<PrimExpr> TryConstFold(PrimExpr a);
  * \param type The type to represent index.
  * \return the checked result.
  */
-inline bool IsIndexType(const DataType& type) {
-  return type.is_int() && !type.is_scalable_or_fixed_length_vector() &&
-         (type.bits() == 32 || type.bits() == 64);
+inline bool IsIndexType(DLDataType type) {
+  return type.code == static_cast<uint8_t>(DLDataTypeCode::kDLInt) &&
+         (type.bits == 32 || type.bits == 64) && type.lanes == 1;
+}
+
+inline bool IsIndexTypedExpr(const PrimExprNode* expr) {
+  TVM_FFI_DCHECK(expr != nullptr);
+  TVM_FFI_DCHECK(expr->BaseExprNode::ty.defined());
+  const auto* prim_ty = expr->BaseExprNode::ty.as<PrimTypeNode>();
+  TVM_FFI_DCHECK(prim_ty != nullptr);
+  return IsIndexType(prim_ty->dtype);
+}
+
+inline bool IsIndexTypedExpr(const PrimExpr& expr) {
+  return IsIndexTypedExpr(static_cast<const PrimExprNode*>(expr.get()));
 }
 
 /*! \brief Helper to get const folding result repr in int64. */
-inline int64_t GetFoldResultInt64Repr(int64_t x, const DataType& dtype) {
+inline int64_t GetFoldResultInt64Repr(int64_t x, const PrimType& dtype) {
   if (dtype.bits() < 64) {
     x &= (1LL << dtype.bits()) - 1;
   }
-  if (dtype.is_int()) {
-    // get sign extended value of integer with specified bits
+  if (dtype.code() == DLDataTypeCode::kDLInt) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLInt`.
   
   ```suggestion
     if (dtype.MatchesCode(DLDataTypeCode::kDLInt)) {
   ```



##########
src/arith/transitive_comparison_analyzer.cc:
##########
@@ -615,7 +615,8 @@ CompareResult TransitiveComparisonAnalyzer::Impl::TryCompare(const PrimExpr& lhs
                                                              const PrimExpr& rhs_expr,
                                                              bool propagate_inequalities) const {
   // Currently only supports integer checks
-  if (!lhs_expr.dtype().is_int() || !rhs_expr.dtype().is_int()) {
+  if (lhs_expr.ty().code() != DLDataTypeCode::kDLInt ||
+      rhs_expr.ty().code() != DLDataTypeCode::kDLInt) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLInt`.
   
   ```suggestion
     if (!lhs_expr.ty().MatchesCode(DLDataTypeCode::kDLInt) ||
         !rhs_expr.ty().MatchesCode(DLDataTypeCode::kDLInt)) {
   ```



##########
src/relax/op/tensor/search.cc:
##########
@@ -119,13 +118,15 @@ Type InferTypeWhere(const Call& call, const BlockBuilder& ctx) {
     }
   }
 
-  if (!cond_ty->dtype.is_bool()) {
+  PrimType cond_dtype = cond_ty->dtype;
+  // Where condition validation only checks the boolean element kind; lanes are irrelevant here.
+  if (cond_dtype.code() != DLDataTypeCode::kDLBool) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLBool`.
   
   ```suggestion
     if (!cond_dtype.MatchesCode(DLDataTypeCode::kDLBool)) {
   ```



##########
src/relax/transform/gradient.cc:
##########
@@ -707,7 +707,8 @@ class GradientMutator : private ExprMutator {
 
   static bool IsFloatTensorType(const Type& ty) {
     auto* tensor_ty = ty.as<TensorTypeNode>();
-    return tensor_ty && tensor_ty->dtype.is_float();
+    // Gradient eligibility preserves the old float-kind check; lanes do not affect this policy.
+    return tensor_ty && tensor_ty->dtype.code() == DLDataTypeCode::kDLFloat;

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLFloat`.
   
   ```suggestion
       return tensor_ty && tensor_ty->dtype.MatchesCode(DLDataTypeCode::kDLFloat);
   ```



##########
src/arith/int_set.cc:
##########
@@ -72,8 +72,10 @@ TVM_FFI_STATIC_INIT_BLOCK() {
 IntervalSet Intersect(AnalyzerObj* analyzer, IntervalSet a, IntervalSet b) {
   PrimExpr max_value = min(a->max_value, b->max_value);
   PrimExpr min_value = max(a->min_value, b->min_value);
-  if ((max_value.dtype().is_int() || max_value.dtype().is_uint()) &&
-      (min_value.dtype().is_int() || min_value.dtype().is_uint()) &&
+  PrimType max_ty = max_value.ty();
+  PrimType min_ty = min_value.ty();
+  if ((max_ty.code() == DLDataTypeCode::kDLInt || max_ty.code() == DLDataTypeCode::kDLUInt) &&
+      (min_ty.code() == DLDataTypeCode::kDLInt || min_ty.code() == DLDataTypeCode::kDLUInt) &&

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLInt` and `kDLUInt`.
   
   ```suggestion
     if (max_ty.MatchesCode(DLDataTypeCode::kDLInt, DLDataTypeCode::kDLUInt) &&
         min_ty.MatchesCode(DLDataTypeCode::kDLInt, DLDataTypeCode::kDLUInt) &&
   ```



##########
src/arith/int_set.cc:
##########
@@ -569,18 +572,19 @@ class IntervalSetEvaluator : public ExprFunctor<IntervalSet(const PrimExpr&)> {
     // short cut for the int set.
     if (value_set->min_value.same_as(value_set->max_value)) {
       if (value_set->IsEmpty()) return value_set;
-      return IntervalSet::SinglePoint(cast(op->dtype, value_set->min_value));
+      return IntervalSet::SinglePoint(cast(op->ty(), value_set->min_value));
     }
     PrimExpr min_value =
-        value_set->HasLowerBound() ? cast(op->dtype, value_set->min_value) : neg_inf();
+        value_set->HasLowerBound() ? cast(op->ty(), value_set->min_value) : neg_inf();
     PrimExpr max_value =
-        value_set->HasUpperBound() ? cast(op->dtype, value_set->max_value) : pos_inf();
+        value_set->HasUpperBound() ? cast(op->ty(), value_set->max_value) : pos_inf();
     return IntervalSet(min_value, max_value);
   }
 
   IntervalSet VisitExpr_(const BufferLoadNode* op) final {
-    if (!(op->dtype.is_int() || op->dtype.is_uint())) {
-      DLOG(WARNING) << "cannot evaluate set BufferLoad which loads from a " << op->dtype
+    PrimType op_ty = op->ty();
+    if (!(op_ty.code() == DLDataTypeCode::kDLInt || op_ty.code() == DLDataTypeCode::kDLUInt)) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLInt` and `kDLUInt`.
   
   ```suggestion
       if (!op_ty.MatchesCode(DLDataTypeCode::kDLInt, DLDataTypeCode::kDLUInt)) {
   ```



##########
src/arith/int_constraints.cc:
##########
@@ -74,7 +74,9 @@ ffi::Array<PrimExpr> AsConditions(const ffi::Array<Var>& variables,
 
 IntGroupBounds::IntGroupBounds(PrimExpr coef, ffi::Array<PrimExpr> lower,
                                ffi::Array<PrimExpr> equal, ffi::Array<PrimExpr> upper) {
-  TVM_FFI_ICHECK(coef.dtype().is_int() || coef.dtype().is_uint())
+  PrimType coef_ty = coef.ty();
+  TVM_FFI_ICHECK(coef_ty.code() == DLDataTypeCode::kDLInt ||
+                 coef_ty.code() == DLDataTypeCode::kDLUInt)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLInt` and `kDLUInt`.
   
   ```c
     TVM_FFI_ICHECK(coef_ty.MatchesCode(DLDataTypeCode::kDLInt, DLDataTypeCode::kDLUInt))
   ```



##########
src/arith/bound_deducer.cc:
##########
@@ -96,7 +96,8 @@ class BoundDeducer : public ExprFunctor<void(const PrimExpr&)> {
   void VisitExprDefault_(const ffi::Object* op) final { success_ = false; }
 
   SignType GetSignType(const PrimExpr& e) {
-    if (e.dtype().is_uint()) {
+    PrimType e_ty = e.ty();
+    if (e_ty.code() == DLDataTypeCode::kDLUInt) {

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLUInt`.
   
   ```suggestion
       if (e_ty.MatchesCode(DLDataTypeCode::kDLUInt)) {
   ```



##########
src/arith/int_constraints.cc:
##########
@@ -232,7 +234,9 @@ IntConstraints::IntConstraints(ffi::Array<Var> variables, ffi::Map<Var, Range> r
   }
   TVM_FFI_ICHECK(relations.defined());
   for (const auto& var : variables) {
-    TVM_FFI_ICHECK(var.dtype().is_int() || var.dtype().is_uint())
+    PrimType var_ty = var.ty();
+    TVM_FFI_ICHECK(var_ty.code() == DLDataTypeCode::kDLInt ||
+                   var_ty.code() == DLDataTypeCode::kDLUInt)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can use the more idiomatic `MatchesCode` helper on `PrimType` instead of directly comparing `code()` against `kDLInt` and `kDLUInt`.
   
   ```c
       TVM_FFI_ICHECK(var_ty.MatchesCode(DLDataTypeCode::kDLInt, DLDataTypeCode::kDLUInt))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org


Re: [PR] [REFACTOR][IR] Use PrimType for compiler dtypes [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #19875:
URL: https://github.com/apache/tvm/pull/19875#issuecomment-4781405297

   /gemini Please run another code review pass on the latest head b20481204d. The branch has been rebased onto upstream main and includes follow-up fixes for the prior review comments: PVar optional storage CI warning, Relax scalable-vector byte-size checks, bool8 dtype comparison, and GPU verifier vector-byte PrimType usage.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org