Skip to content

Commit

Permalink
norm: fix complex abs( inf + inf*i ) in CUDA and HIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mgates3 committed Jul 7, 2024
1 parent 3e2934e commit d47e9d6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/cuda/device_util.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ inline float abs(cuFloatComplex x)
// CUDA has a good implementation.
return cuCabsf(x);
#else
// For HIP, use our implementation that scales per LAPACK.
// For HIP, use our implementation that scales per LAPACK lapy2.
float a = real( x );
float b = imag( x );
float z, w, t;
Expand All @@ -173,7 +173,7 @@ inline float abs(cuFloatComplex x)
b = fabsf(b);
w = max(a, b);
z = min(a, b);
if (z == 0) {
if (z == 0 || isinf( w )) {
t = w;
}
else {
Expand All @@ -194,7 +194,7 @@ inline double abs(cuDoubleComplex x)
// CUDA has a good implementation.
return cuCabs(x);
#else
// For HIP, use our implementation that scales per LAPACK.
// For HIP, use our implementation that scales per LAPACK lapy2.
double a = real( x );
double b = imag( x );
double z, w, t;
Expand All @@ -209,12 +209,12 @@ inline double abs(cuDoubleComplex x)
b = fabs(b);
w = max(a, b);
z = min(a, b);
if (z == 0) {
if (z == 0 || isinf( w )) {
t = w;
}
else {
t = z/w;
t = 1.0 + t*t;
t = 1 + t*t;
t = w * sqrt(t);
}
return t;
Expand Down
10 changes: 5 additions & 5 deletions src/hip/device_util.hip.hh
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ inline float abs(rocblas_float_complex x)
// CUDA has a good implementation.
return hipCabsf(x);
#else
// For HIP, use our implementation that scales per LAPACK.
// For HIP, use our implementation that scales per LAPACK lapy2.
float a = real( x );
float b = imag( x );
float z, w, t;
Expand All @@ -173,7 +173,7 @@ inline float abs(rocblas_float_complex x)
b = fabsf(b);
w = max(a, b);
z = min(a, b);
if (z == 0) {
if (z == 0 || isinf( w )) {
t = w;
}
else {
Expand All @@ -194,7 +194,7 @@ inline double abs(rocblas_double_complex x)
// CUDA has a good implementation.
return hipCabs(x);
#else
// For HIP, use our implementation that scales per LAPACK.
// For HIP, use our implementation that scales per LAPACK lapy2.
double a = real( x );
double b = imag( x );
double z, w, t;
Expand All @@ -209,12 +209,12 @@ inline double abs(rocblas_double_complex x)
b = fabs(b);
w = max(a, b);
z = min(a, b);
if (z == 0) {
if (z == 0 || isinf( w )) {
t = w;
}
else {
t = z/w;
t = 1.0 + t*t;
t = 1 + t*t;
t = w * sqrt(t);
}
return t;
Expand Down
2 changes: 1 addition & 1 deletion src/hip/device_util.hip.hh.dep
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a403f5b1c0195b503252fa643c722495 src/cuda/device_util.cuh
9aa8108d505dd3a8afee23324e45bb95 src/cuda/device_util.cuh

0 comments on commit d47e9d6

Please sign in to comment.