Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 13 additions & 8 deletions third_party/nvfuser/csrc/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,17 +994,22 @@ class CudaKernelGenerator : private OptOutConstDispatch {
code_ << " = ";
}

code_ << top->getTernaryOpType() << "(" << gen(top->in1()) << ", ";

// Make sure the two operands of where has the same
// type. Note that compiling "where(0.0f, 0.0)" fails because of
// the overloading ambiguity.
// Don't use a runtime device function for where as the second and
// third aguments should not be evaluated unless picked by the
// condition. If a device function is implemnted as pass-by-value,
// both arguments would be evaluated. Could be worked around by
// pass-by-reference, but it's just simpler to use the C++ ? operator.
if (top->getTernaryOpType() == TernaryOpType::Where) {
code_ << gen(top->in1()) << " ? ";
// Make sure the two operands of where has the same
// type. Note that compiling "where(0.0f, 0.0)" fails because of
// the overloading ambiguity.
auto cast = scalarCast(top->in2(), top->in3());
code_ << (top->in2()->isScalar() ? cast : "") << gen(top->in2()) << ", "
<< (top->in3()->isScalar() ? cast : "") << gen(top->in3()) << ")";
code_ << (top->in2()->isScalar() ? cast : "") << gen(top->in2()) << " : "
<< (top->in3()->isScalar() ? cast : "") << gen(top->in3());
} else {
code_ << gen(top->in2()) << ", " << gen(top->in3()) << ")";
code_ << top->getTernaryOpType() << "(" << gen(top->in1()) << ", "
<< gen(top->in2()) << ", " << gen(top->in3()) << ")";
}

if (!print_inline_) {
Expand Down
46 changes: 0 additions & 46 deletions third_party/nvfuser/runtime/helpers.cu
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,6 @@ __device__ float threshold(float x, double t, double v) {
return x <= t ? v : x;
}

__device__ std::complex<double> where(
bool c,
std::complex<double> a,
std::complex<double> b) {
return c ? a : b;
}

__device__ std::complex<float> where(
bool c,
std::complex<float> a,
std::complex<float> b) {
return c ? a : b;
}

__device__ int threshold(int x, int64_t t, int64_t v) {
return x <= t ? v : x;
}
Expand All @@ -297,38 +283,6 @@ __device__ int64_t threshold(int64_t x, int64_t t, int64_t v) {
return x <= t ? v : x;
}

__device__ double where(bool c, double a, double b) {
return c ? a : b;
}

__device__ float where(bool c, float a, float b) {
return c ? a : b;
}

__device__ __half where(bool c, __half a, __half b) {
return c ? a : b;
}

__device__ __bfloat where(bool c, __bfloat a, __bfloat b) {
return c ? a : b;
}

__device__ int64_t where(bool c, int64_t a, int64_t b) {
return c ? a : b;
}

__device__ int where(bool c, int a, int b) {
return c ? a : b;
}

__device__ int64_t where(bool c, int64_t a, int b) {
return c ? a : b;
}

__device__ int64_t where(bool c, int a, int64_t b) {
return c ? a : b;
}

__device__ constexpr int64_t remainder(int64_t a, int64_t b) {
auto mod = a % b;
if ((mod != 0) && ((b < 0) != (mod < 0)))
Expand Down