Skip to content

Fix comparisons with Rationals - #707

Merged
maleadt merged 1 commit into
mainfrom
tb/int128
Oct 18, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/int128

Conversation

@maleadt

@maleadt maleadt commented Oct 16, 2026

Copy link
Copy Markdown
Member

Base compares Rationals with each other, with integers and with floats by multiplying out their denominators with widemul. With 64-bit rationals (or any float, whose decompose returns Ints) that computes Int128 products, which SPIR-V doesn't support. This stacks GPUToolbox's new int128_overrides table (JuliaGPU/GPUToolbox.jl#30) regardless of fp64 support, and requires GPUToolbox 3.4. Same fix as JuliaGPU/Metal.jl#550.

Tested on an Iris Xe: the new tests fail without the change (13 errors) and pass with it.

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic main) to apply these changes.

Click here to view the suggested changes.
diff --git a/src/compiler/compilation.jl b/src/compiler/compilation.jl
index 2bfff9c..5c56740 100644
--- a/src/compiler/compilation.jl
+++ b/src/compiler/compilation.jl
@@ -42,8 +42,10 @@ function GPUCompiler.method_tables(job::oneAPICompilerJob)
         (method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.int128_overrides)
     else
         # keep single-precision math that Base computes in Float64 out of double precision
-        (method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.float64_overrides,
-         GPUToolbox.Overlays.int128_overrides)
+        (
+            method_table, SPIRVIntrinsics.method_table, GPUToolbox.Overlays.float64_overrides,
+            GPUToolbox.Overlays.int128_overrides,
+        )
     end
 end
 
diff --git a/test/device/intrinsics.jl b/test/device/intrinsics.jl
index ce37747..eeab908 100644
--- a/test/device/intrinsics.jl
+++ b/test/device/intrinsics.jl
@@ -54,9 +54,9 @@ end
         xs = Float32[0, -1, 1.4, 1.5, 1.6, Inf, NaN]
         @test Array(map(x -> x < r, oneArray(xs))) == (xs .< r)
 
-        qs = [1//3, -5//7, 3//2, typemax(Int)//2, 2^40//3, -typemax(Int)//(2^40 + 1)]
+        qs = [1 // 3, -5 // 7, 3 // 2, typemax(Int) // 2, 2^40 // 3, -typemax(Int) // (2^40 + 1)]
         ns = [0, -1, 2, 2^35, typemax(Int), typemin(Int)]
-        fs = Float32[0.3, -0.7, 1.5, 2f0^62, 3.6f11, -Inf]
+        fs = Float32[0.3, -0.7, 1.5, 2.0f0^62, 3.6f11, -Inf]
         for op in (<, <=, cmp)
             @test Array(op.(oneArray(qs), oneArray(fs))) == op.(qs, fs)
             @test Array(op.(oneArray(fs), oneArray(qs))) == op.(fs, qs)

SPIR-V doesn't support 128-bit integers, which Base uses to compare `Rational`s by
multiplying out their denominators. Stack GPUToolbox's `int128_overrides`, which
compute these products as pairs of 64-bit words.
@maleadt

maleadt commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

CI failure is a bug in NEO. Claude has a fix.

@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.05%. Comparing base (8460d3f) to head (aa6f3a3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #707      +/-   ##
==========================================
- Coverage   83.70%   83.05%   -0.66%     
==========================================
  Files          52       51       -1     
  Lines        4376     4254     -122     
==========================================
- Hits         3663     3533     -130     
- Misses        713      721       +8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit adfc2bd into main Oct 18, 2026
5 checks passed
@maleadt
maleadt deleted the tb/int128 branch October 18, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant