Skip to content
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

[BugFix][CUDA] Increase FloatImm precision when printing 64 bit values in CUDA codegen #17530

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/target/source/codegen_cuda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1381,26 +1381,38 @@ inline void PrintConst(const FloatImmNode* op, std::ostream& os, CodeGenCUDA* p)
}
// Type code is kFloat
switch (op->dtype.bits()) {
case 64:
case 32: {
case 64: {
std::ostringstream temp;
if (std::isinf(op->value)) {
if (op->value < 0) {
temp << "-";
}
temp << ((op->dtype.bits() == 32) ? "CUDART_INF_F" : "CUDART_INF");
temp << "CUDART_INF";
p->need_math_constants_h_ = true;
} else if (std::isnan(op->value)) {
temp << ((op->dtype.bits() == 32) ? "CUDART_NAN_F" : "CUDART_NAN");
temp << "CUDART_NAN";
p->need_math_constants_h_ = true;
} else {
temp << std::scientific << op->value;
if (op->dtype.bits() == 32) temp << 'f';
temp << std::fixed << std::setprecision(15) << op->value;
}
p->MarkConst(temp.str());
os << temp.str();
break;
}
case 32: {
std::ostringstream temp;
if (std::isinf(op->value)) {
if (op->value < 0) {
temp << "-";
}
temp << "CUDART_INF_F";
p->need_math_constants_h_ = true;
} else if (std::isnan(op->value)) {
temp << "CUDART_NAN_F";
p->need_math_constants_h_ = true;
} else {
temp << std::scientific << op->value << 'f';
}
case 16: {
os << "__float2half_rn" << '(';
FloatImm const_f32 = FloatImm(DataType::Float(32), op->value);
Expand Down
Loading