Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1314,3 +1314,14 @@ this section verbatim). Each entry is one bullet starting with `- `.
serialization, hiding the original conversion error. An opaque-pointer
CPU fixture can protect the address-hook contract; it does not replace
native backend validation.

119. **Choose GPU test scalar types from the selected device's capability.**
A backend can expose both Float64-capable and incapable devices. A
Float32 array with a `0.0` scan initializer widens to Float64, so a test
can fail before reaching its intended value assertion. Query the actual
device inside the task's GPU scope. Level Zero's module capability bits
belong to `module_properties(device).flags`; `fp64flags` instead holds
arithmetic properties, so applying a module mask there can pass by
coincidence. Test those fields with different values. Keep the Float64 case on capable hardware and run the same
behavioral assertion with a supported initializer elsewhere; a vendor-wide
skip loses coverage on devices that support it.
23 changes: 22 additions & 1 deletion test/gpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ end
end
end

@everywhere begin
gpu_accumulate_init(properties, mask) = (properties.flags & mask) == mask ? 0.0 : 0f0
function gpu_accumulate_init(name::Symbol)
if name == :oneAPI
# This runs in the selected GPU scope, so query that task's device.
properties = oneAPI.oneL0.module_properties(oneAPI.device())
return gpu_accumulate_init(properties, oneAPI.oneL0.ZE_DEVICE_MODULE_FLAG_FP64)
end
return 0.0
end
end

@testset "GPU accumulate init capability" begin
# Module support flags and floating-point arithmetic flags are distinct.
@test gpu_accumulate_init((flags=UInt32(0), fp64flags=UInt32(2)), UInt32(2)) === 0f0
@test gpu_accumulate_init((flags=UInt32(1), fp64flags=UInt32(0x7f)), UInt32(2)) === 0f0
@test gpu_accumulate_init((flags=UInt32(2), fp64flags=UInt32(0)), UInt32(2)) === 0.0
@test gpu_accumulate_init((flags=UInt32(3), fp64flags=UInt32(0)), UInt32(2)) === 0.0
end

@testset "DArray accumulate ($name)" for (name, scope) in GPU_SCOPES
Dagger.with_options(; scope) do
DA = rand(Blocks(4, 4), Float32, 16, 16)
Expand All @@ -111,7 +131,8 @@ end
@test collect(accumulate(+, DA; dims=2, init=1f0)) ≈ accumulate(+, A; dims=2, init=1f0)
# Metal has no Float64
if name != :Metal
@test collect(accumulate(+, DA; dims=1, init=0.0)) ≈ accumulate(+, A; dims=1, init=0.0)
init = fetch(Dagger.@spawn gpu_accumulate_init(name))
@test collect(accumulate(+, DA; dims=1, init)) ≈ accumulate(+, A; dims=1, init)
end
DV = rand(Blocks(4), Float32, 16)
@test collect(cumsum(DV)) ≈ cumsum(collect(DV))
Expand Down
Loading