-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CODEGEN][OPENCL] Fix compile error about ternary expression. #2821
Conversation
@@ -208,6 +208,16 @@ void CodeGenOpenCL::VisitExpr_(const Broadcast* op, std::ostream& os) { // NOL | |||
os << "))"; | |||
} | |||
|
|||
void CodeGenOpenCL::VisitExpr_(const Call *op, std::ostream& os) { // NOLINT(*) | |||
if (op->is_intrinsic(intrinsic::tvm_if_then_else)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment on why explicit cast is needed here.
Likely you also need to add support for select
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a regression test case as per https://docs.tvm.ai/contribute/code_review.html#ensure-test-coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added for both tvm::if_then_else and Select
src/codegen/codegen_opencl.cc
Outdated
@@ -208,6 +208,16 @@ void CodeGenOpenCL::VisitExpr_(const Broadcast* op, std::ostream& os) { // NOL | |||
os << "))"; | |||
} | |||
|
|||
void CodeGenOpenCL::VisitExpr_(const Call *op, std::ostream& os) { // NOLINT(*) | |||
if (op->is_intrinsic(intrinsic::tvm_if_then_else)) { | |||
if (op->args[2].type() == UInt(8)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my environment, the problem also happens with char, short, and ushort. It looks safe to add a cast for any types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works with float/int, that's why most people didn't run into this problem. Casting for any types is good for me.
7300eba
to
580b065
Compare
Code like this can't be built with NV OpenCL, and it needs an explicit type converison for ternary expression if return type is uchar. uchar i = 0, j = 0; uchar t = max((uchar)j, ((i > 0) ? (uchar)1 : (uchar)0));
@tqchen I think your comment has been addressed. Can you confirm it and update your review status if appropriate? |
Thanks @lixiaoquan @tqchen, this is now merged. |
…#2821) Code like this can't be built with NV OpenCL, and it needs an explicit type converison for ternary expression if return type is uchar. uchar i = 0, j = 0; uchar t = max((uchar)j, ((i > 0) ? (uchar)1 : (uchar)0));
…#2821) Code like this can't be built with NV OpenCL, and it needs an explicit type converison for ternary expression if return type is uchar. uchar i = 0, j = 0; uchar t = max((uchar)j, ((i > 0) ? (uchar)1 : (uchar)0));
Code like this can't be built with NV OpenCL, and it needs an explicit type
converison for ternary expression if return type is uchar.
It is for #2787