Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Device min/max on floats ignore NaNs, unlike Julia's min/max

Closed
#1,142 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
julia

Research direction

Start with the float Base.min/Base.max overrides in src/device/gcn/math.jl and compare their behavior with Julia’s NaN-propagating semantics. The issue identifies LLVM minimum/maximum lowering and older LLVM versions as constraints; investigate those paths and how atomics use the operations. Done means device min/max and the affected atomic behavior match Julia’s NaN semantics across the relevant LLVM versions.

Written by the indexing model from the issue text.

Description

On the device, Base.min and Base.max for Float16, Float32 and Float64 are overridden with __ocml_min_*/__ocml_max_* (src/device/gcn/math.jl), which ignore NaNs. Julia's min/max return NaN if either argument is NaN, so kernels compute something else than the same code on the host:

using AMDGPU
function k(out, x, y)
    out[1] = max(x[1], y[1])
    out[2] = min(x[1], y[1])
    return
end
out = ROCArray(zeros(Float32, 2))
@roc k(out, ROCArray([NaN32]), ROCArray([1f0]))
Array(out)                         # Float32[1.0, 1.0]
max(NaN32, 1f0), min(NaN32, 1f0)   # (NaN32, NaN32)

(AMDGPU.jl 2.8.0, Julia 1.13.1, gfx1036.)

This also leaks into atomics: Atomix.@atomic max(a[i], v) on Julia ≤ 1.13 is a compare-exchange loop around Base.max, so it ignores NaNs too, whereas on Julia 1.14 it becomes atomicrmw fmaximum, which propagates them. The result of the same kernel then depends on the Julia version.

CUDA.jl had a similar override and now lowers min/max to llvm.minimum/llvm.maximum. For AMDGPU, LLVM 19 and later expand those intrinsics on every subtarget (gfx12 and gfx950 have native instructions), so the external back-end and Julia 1.12+ could do the same. With the in-process LLVM of older Julia versions (15–18), they don't lower in general, so a fallback that keeps the semantics would be needed there.

Dominant language
Julia
Stars
348
Forks
81
Avg merge
2d 7h
Merged PRs (30d)
54

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaGPU/AMDGPU.jl

All issues in JuliaGPU/AMDGPU.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.