gemini-code-assist[bot] commented on code in PR #19908:
URL: https://github.com/apache/tvm/pull/19908#discussion_r3490449383
##########
src/relax/op/tensor/create.cc:
##########
@@ -179,8 +179,7 @@ Type InferTypeOnesLikeZerosLike(const Call& call, const
BlockBuilder& ctx) {
/* relax.ones & relax.ones_like */
Expr ones(Expr shape, DLDataType dtype) {
- TVM_FFI_ICHECK((dtype != DLDataType{kDLOpaqueHandle, 0, 0}))
- << "Ones op expects the input dtype not to be void";
+ TVM_FFI_ICHECK(!PrimType(dtype).IsVoid()) << "Ones op expects the input
dtype not to be void";
Review Comment:

Constructing a `PrimType` AST node via `PrimType(dtype)` allocates a
`PrimTypeNode` on the heap (using `make_object`), which introduces unnecessary
overhead just to check if the data type is void. Using
`DataType(dtype).is_void()` is a stack-only operation that compiles down to a
simple inline comparison, avoiding any heap allocation or reference counting
overhead.
```suggestion
TVM_FFI_ICHECK(!DataType(dtype).is_void()) << "Ones op expects the input
dtype not to be void";
```
##########
src/relax/op/tensor/create.cc:
##########
@@ -217,8 +216,7 @@ TVM_REGISTER_OP("relax.ones_like")
/* relax.zeros & relax.zeros_like */
Expr zeros(Expr shape, DLDataType dtype) {
- TVM_FFI_ICHECK((dtype != DLDataType{kDLOpaqueHandle, 0, 0}))
- << "Zeros op expects the input dtype not to be void";
+ TVM_FFI_ICHECK(!PrimType(dtype).IsVoid()) << "Zeros op expects the input
dtype not to be void";
Review Comment:

Constructing a `PrimType` AST node via `PrimType(dtype)` allocates a
`PrimTypeNode` on the heap (using `make_object`), which introduces unnecessary
overhead just to check if the data type is void. Using
`DataType(dtype).is_void()` is a stack-only operation that compiles down to a
simple inline comparison, avoiding any heap allocation or reference counting
overhead.
```suggestion
TVM_FFI_ICHECK(!DataType(dtype).is_void()) << "Zeros op expects the input
dtype not to be void";
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]