Repository navigation
Use GPUToolbox's shared throw overrides - #1217
Conversation
Julia 1.10 formats the message of the error that `Rational` throws for a typemin denominator, which fails to compile for the device, breaking all `Rational` arithmetic with a negative denominator in kernels. GPUToolbox's `throw_overrides` throw these errors with a constant message instead.
GPUToolbox's shared overrides throw through `Overlays.device_throw`, with a constant exception type and message. Implement it with `@gputhrow`, so that these exceptions report their type like AMDGPU's own quirks, instead of as an unknown exception.
Benchmark resultsCompared with 74cf40077, the merge base. Times are the minimum time of every benchmark. A change is unusual when it exceeds both three times the benchmark's typical change between consecutive runs on the default branch and a minimum per category (performance 3%, latency 5%, applications 3%, other 3%). A benchmark that starts or stops allocating is listed however few the allocations. A single run can still be a fluke, so rerun before drawing conclusions.
All benchmarks
|
rocSOLVER's gesvdj diagonalizes A'A with a Jacobi eigensolver and takes U and S from a QR of AV, so singular values below sqrt(eps)*σ₁ are lost while info = 0 and the residual is below tolerance: a Float64 svd, cond or rank could silently be accurate to 1e-8 only. gesvd matches LAPACK down to the eps*σ₁ floor. Make QRAlgorithm() the default of svd, svd!, svdvals and svdvals! (and the target of DivideAndConquer()), as CUDA.jl does; JacobiAlgorithm() stays available as the documented fast path (3-9x faster on MI250X and MI300A) for well-conditioned matrices. Upstream: ROCm/rocm-libraries#12868 (gesvdj accuracy), #15788 (cgesvd singular vectors of a rank-deficient ComplexF32 matrix, worked around in the test).
GPUToolbox v3.6.0 (JuliaGPU/GPUToolbox.jl#43, #44) adds
Overlays.throw_overrides, a method table that overrides Base's throw helpers that format their message at run time. On Julia 1.10,Rationalarithmetic reaches such a helper (Base.__throw_rational_argerror_typemin) whenever a denominator can be negative, so any kernel doingRationalmultiplication, addition or negation fails to compile with anInvalidIRError. Julia 1.11 has the same problem withBase.__throw_rational_numerator_typemin, and on 1.12 and later the table is empty.This PR:
throw_overridesunder AMDGPU's method table throughGPUCompiler.method_tables;GPUToolbox.Overlays.device_throw, the hook that the shared overrides throw through, with@gputhrow. Their exceptions are then reported by type (e.g.ArgumentError) like AMDGPU's own quirks, instead of asUnknown exception;test/device/exceptions.jl. They check thatRationalarithmetic, negation and construction compile and give correct results, that a typemin denominator or numerator reports the same exception type as on the host, and thatdevice_throwreports its exception type.Tested on gfx1036 (RDNA2):
test/device/exceptions.jlonmain: on Julia 1.10.12 theRationalkernel fails with anInvalidIRError, and on 1.13.2device_throwis reported asUnknown exception. With this PR it passes on both.device,core,kernelabstractions_testsandkernelinterface_testswith--jobs=4: all pass on 1.10.12 (13297 passed, 14 broken) and 1.13.2 (13319 passed, 14 broken).Requires GPUToolbox v3.6.0 to be registered (JuliaRegistries/General#175594).