gemini-code-assist[bot] commented on code in PR #19954:
URL: https://github.com/apache/tvm/pull/19954#discussion_r3525370997
##########
src/backend/opencl/codegen/codegen_opencl.cc:
##########
@@ -376,9 +377,10 @@ void CodeGenOpenCL::PrintRestrict(const Var& v,
std::ostream& os) {
}
}
-std::string CodeGenOpenCL::CastFromTo(std::string value, DLDataType from,
DLDataType target) {
+std::string CodeGenOpenCL::CastFromTo(std::string value, const PrimType& from,
+ const PrimType& target) {
if (from == target) return value;
- return CastTo(value, target);
+ return CastTo(value, target->dtype);
}
Review Comment:

Comparing `from == target` checks for pointer/reference equality of the
`PrimType` objects rather than structural equality of their underlying
`DLDataType`. If two different `PrimType` instances represent the same
`DLDataType` (e.g., `float32`), `from == target` will evaluate to `false`,
leading to redundant type casts (such as `convert_float(value)`) in the
generated OpenCL code.
Using `from->dtype == target->dtype` ensures that we correctly check for
type equality and avoid generating unnecessary casts.
```suggestion
std::string CodeGenOpenCL::CastFromTo(std::string value, const PrimType&
from,
const PrimType& target) {
if (from->dtype == target->dtype) return value;
return CastTo(value, target->dtype);
}
```
--
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]