-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir] Make the print function in CRunnerUtil platform agnostic #86767
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
Conversation
@llvm/pr-subscribers-mlir Author: Kai Sasaki (Lewuathe) ChangesThe platform running on Apple Silicon does not seem to support the negative nan. It causes the test failure where we explicitly specify the negative nan bit pattern and check the output printed by the CRunnerUtil function. We can make the print function in the utility platform agnostic by using the standard library functions (e.g., I have added two test cases that would fail in the Apple Silicon platform without print function changes.
See: https://discourse.llvm.org/t/test-failure-of-sparse-sign-test-in-apple-silicon/77876/3 Full diff: https://github.com/llvm/llvm-project/pull/86767.diff 2 Files Affected:
diff --git a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
index 48e4b8cd88b58e..41c619566b55df 100644
--- a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
+++ b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
@@ -51,8 +51,20 @@ void stdSort(uint64_t n, V *p) {
// details of our vectors. Also useful for direct LLVM IR output.
extern "C" void printI64(int64_t i) { fprintf(stdout, "%" PRId64, i); }
extern "C" void printU64(uint64_t u) { fprintf(stdout, "%" PRIu64, u); }
-extern "C" void printF32(float f) { fprintf(stdout, "%g", f); }
-extern "C" void printF64(double d) { fprintf(stdout, "%lg", d); }
+extern "C" void printF32(float f) {
+ if (std::isnan(f) && std::signbit(f)) {
+ fprintf(stdout, "-nan");
+ } else {
+ fprintf(stdout, "%g", f);
+ }
+}
+extern "C" void printF64(double d) {
+ if (std::isnan(d) && std::signbit(d)) {
+ fprintf(stdout, "-nan");
+ } else {
+ fprintf(stdout, "%lg", d);
+ }
+}
extern "C" void printString(char const *s) { fputs(s, stdout); }
extern "C" void printOpen() { fputs("( ", stdout); }
extern "C" void printClose() { fputs(" )", stdout); }
diff --git a/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir b/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
index e2229a392bbf76..340ef30bf59c29 100644
--- a/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
+++ b/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
@@ -190,6 +190,12 @@ func.func @func_powff64(%a : f64, %b : f64) {
return
}
+func.func @func_powff32(%a : f32, %b : f32) {
+ %r = math.powf %a, %b : f32
+ vector.print %r : f32
+ return
+}
+
func.func @powf() {
// CHECK-NEXT: 16
%a = arith.constant 4.0 : f64
@@ -230,7 +236,17 @@ func.func @powf() {
%j = arith.constant 29385.0 : f64
%j_p = arith.constant 23598.0 : f64
call @func_powff64(%j, %j_p) : (f64, f64) -> ()
- return
+
+ // CHECK-NEXT: -nan
+ %k = arith.constant 1.0 : f64
+ %k_p = arith.constant 0xfff0000001000000 : f64
+ call @func_powff64(%k, %k_p) : (f64, f64) -> ()
+
+ // CHECK-NEXT: -nan
+ %l = arith.constant 1.0 : f32
+ %l_p = arith.constant 0xffffffff : f32
+ call @func_powff32(%l, %l_p) : (f32, f32) -> ()
+ return
}
// -------------------------------------------------------------------------- //
|
@llvm/pr-subscribers-mlir-execution-engine Author: Kai Sasaki (Lewuathe) ChangesThe platform running on Apple Silicon does not seem to support the negative nan. It causes the test failure where we explicitly specify the negative nan bit pattern and check the output printed by the CRunnerUtil function. We can make the print function in the utility platform agnostic by using the standard library functions (e.g., I have added two test cases that would fail in the Apple Silicon platform without print function changes.
See: https://discourse.llvm.org/t/test-failure-of-sparse-sign-test-in-apple-silicon/77876/3 Full diff: https://github.com/llvm/llvm-project/pull/86767.diff 2 Files Affected:
diff --git a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
index 48e4b8cd88b58e..41c619566b55df 100644
--- a/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
+++ b/mlir/lib/ExecutionEngine/CRunnerUtils.cpp
@@ -51,8 +51,20 @@ void stdSort(uint64_t n, V *p) {
// details of our vectors. Also useful for direct LLVM IR output.
extern "C" void printI64(int64_t i) { fprintf(stdout, "%" PRId64, i); }
extern "C" void printU64(uint64_t u) { fprintf(stdout, "%" PRIu64, u); }
-extern "C" void printF32(float f) { fprintf(stdout, "%g", f); }
-extern "C" void printF64(double d) { fprintf(stdout, "%lg", d); }
+extern "C" void printF32(float f) {
+ if (std::isnan(f) && std::signbit(f)) {
+ fprintf(stdout, "-nan");
+ } else {
+ fprintf(stdout, "%g", f);
+ }
+}
+extern "C" void printF64(double d) {
+ if (std::isnan(d) && std::signbit(d)) {
+ fprintf(stdout, "-nan");
+ } else {
+ fprintf(stdout, "%lg", d);
+ }
+}
extern "C" void printString(char const *s) { fputs(s, stdout); }
extern "C" void printOpen() { fputs("( ", stdout); }
extern "C" void printClose() { fputs(" )", stdout); }
diff --git a/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir b/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
index e2229a392bbf76..340ef30bf59c29 100644
--- a/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
+++ b/mlir/test/mlir-cpu-runner/test-expand-math-approx.mlir
@@ -190,6 +190,12 @@ func.func @func_powff64(%a : f64, %b : f64) {
return
}
+func.func @func_powff32(%a : f32, %b : f32) {
+ %r = math.powf %a, %b : f32
+ vector.print %r : f32
+ return
+}
+
func.func @powf() {
// CHECK-NEXT: 16
%a = arith.constant 4.0 : f64
@@ -230,7 +236,17 @@ func.func @powf() {
%j = arith.constant 29385.0 : f64
%j_p = arith.constant 23598.0 : f64
call @func_powff64(%j, %j_p) : (f64, f64) -> ()
- return
+
+ // CHECK-NEXT: -nan
+ %k = arith.constant 1.0 : f64
+ %k_p = arith.constant 0xfff0000001000000 : f64
+ call @func_powff64(%k, %k_p) : (f64, f64) -> ()
+
+ // CHECK-NEXT: -nan
+ %l = arith.constant 1.0 : f32
+ %l_p = arith.constant 0xffffffff : f32
+ call @func_powff32(%l, %l_p) : (f32, f32) -> ()
+ return
}
// -------------------------------------------------------------------------- //
|
The platform running on Apple Silicon does not seem to support the negative nan. It causes the test failure where we explicitly specify the negative nan bit pattern and check the output printed by the CRunnerUtil function.
We can make the print function in the utility platform agnostic by using the standard library functions (i.e.
std::isnan
andstd::signbit
) so that we can run the test across platforms that do not support the negative bit pattern.I have added two test cases that would fail in the Apple Silicon platform without print function changes.
See: https://discourse.llvm.org/t/test-failure-of-sparse-sign-test-in-apple-silicon/77876/3