From c59137b59269a2c93f8c5cf34e079378b4334e93 Mon Sep 17 00:00:00 2001
From: Russel Arbore <russel.jma@gmail.com>
Date: Thu, 20 Feb 2025 20:24:47 -0600
Subject: [PATCH] Emit infinity in GPU backend

---
 hercules_cg/src/gpu.rs                  | 16 +++++++++++-----
 juno_samples/edge_detection/src/gpu.sch |  3 ---
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/hercules_cg/src/gpu.rs b/hercules_cg/src/gpu.rs
index 73dcf528..6dc5d53e 100644
--- a/hercules_cg/src/gpu.rs
+++ b/hercules_cg/src/gpu.rs
@@ -1797,7 +1797,7 @@ extern \"C\" {} {}(",
             Constant::Integer64(val) => write!(w, "{}{} = {}ll;\n", tabs, name, val)?,
             Constant::UnsignedInteger64(val) => write!(w, "{}{} = {}ull;\n", tabs, name, val)?,
             Constant::Float32(val) => {
-                write!(w, "{}{} = {}f;\n", tabs, name, format_float(**val as f64))?
+                write!(w, "{}{} = {};\n", tabs, name, format_float(**val as f64))?
             }
             Constant::Float64(val) => write!(w, "{}{} = {};\n", tabs, name, format_float(**val))?,
             // All three following collections involve align then allocate from the
@@ -2223,9 +2223,15 @@ fn convert_type(ty: &Type, make_pointer: bool) -> String {
 }
 
 fn format_float(val: f64) -> String {
-    let mut s = val.to_string();
-    if !s.contains('.') && !s.contains('e') && !s.contains('E') {
-        s.push_str(".0");
+    if val == f64::INFINITY {
+        "INFINITY".to_string()
+    } else if val == f64::NEG_INFINITY {
+        "-INFINITY".to_string()
+    } else {
+        let mut s = val.to_string();
+        if !s.contains('.') && !s.contains('e') && !s.contains('E') {
+            s.push_str(".0");
+        }
+        s
     }
-    s
 }
diff --git a/juno_samples/edge_detection/src/gpu.sch b/juno_samples/edge_detection/src/gpu.sch
index 2a8960ee..ed414084 100644
--- a/juno_samples/edge_detection/src/gpu.sch
+++ b/juno_samples/edge_detection/src/gpu.sch
@@ -67,12 +67,9 @@ let out = fork-split(max_gradient);
 fork-tile[32, 0, false, true](out._4_max_gradient.fj1);
 let out = fork-split(max_gradient);
 simpl!(max_gradient);
-xdot[true](max_gradient);
 clean-monoid-reduces(max_gradient);
-xdot[true](max_gradient);
 fork-fission-bufferize[out._4_max_gradient.fj0, out._4_max_gradient.fj1](max_gradient);
 simpl!(max_gradient);
-xdot[true](max_gradient);
 
 no-memset(reject_zero_crossings@res);
 fixpoint {
-- 
GitLab