From 0f1ef5a1549e861424a97d1283173492af0b42cc Mon Sep 17 00:00:00 2001 From: Billy Moses Date: Thu, 21 May 2026 16:35:55 -0500 Subject: [PATCH] Add sparam --- src/llvm/attributes.jl | 4 ++++ test/sparam.jl | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/sparam.jl diff --git a/src/llvm/attributes.jl b/src/llvm/attributes.jl index 29e87aba17..eb96fb163f 100644 --- a/src/llvm/attributes.jl +++ b/src/llvm/attributes.jl @@ -1,4 +1,6 @@ const nofreefns = Set{String}(( + "jl_f__compute_sparams", + "ijl_f__compute_sparams", "jl_genericmemory_copyto", "jl_get_binding_value_seqcst", "ijl_get_binding_value_seqcst", @@ -215,6 +217,8 @@ const nofreefns = Set{String}(( )) const inactivefns = Set{String}(( + "jl_f__compute_sparams", + "ijl_f__compute_sparams", # The binding lookup is asserted as inactive [e.g. globals are considered constant wrt differentiation] # If and when this changes, we need to change that here diff --git a/test/sparam.jl b/test/sparam.jl new file mode 100644 index 0000000000..b129c90c36 --- /dev/null +++ b/test/sparam.jl @@ -0,0 +1,17 @@ +using Enzyme, Test + +dual_type(c::NTuple{N, Float64}) where {N} = Val{N} + +function loss(x::Vector{Float64}) + t = ntuple(_ -> 0.0, length(x)) # NTuple{_A, Float64} where _A — non-inferable N + return sum(x) + (dual_type(t) === Val{2} ? 0.0 : 1.0) +end + +@testset "broadcast" begin + res = Enzyme.gradient( + Enzyme.set_runtime_activity(Enzyme.Reverse), + Enzyme.Const(loss), + [1.0, 2.0] + )[1] + @test res ≈ [1.0, 1.0] +end \ No newline at end of file