364364 @test_throws DomainError loggamma (6 , - 3.2 )
365365end
366366
367+ # Run `f(args...)` twice and return only the result of the second call, so that
368+ # one-time costs of the first execution of a freshly compiled callsite are not
369+ # measured. On Julia >= 1.13 OpenLibm is a `Libdl.LazyLibrary`, so resolving the
370+ # target of a `ccall` into it allocates 16 bytes on that callsite's first
371+ # execution. Warming up with a separate call does not help, because the binding
372+ # is cached per callsite and not per callee.
373+ run_twice (f, args... ) = (f (args... ); f (args... ))
374+
367375@testset " GPU compatibility ($FT )" for FT in (Float64, Float32, Float16)
368376 # Note: This test is a proxy for GPU compatibility by checking that the functions
369377 # are type stable and do not allocate memory. It does not launch any GPU kernels.
@@ -378,38 +386,38 @@ end
378386 # `@allocated` checks for allocations for specific code paths
379387 # # a >= 1
380388 # ## gamma_inc_temme_1: simplified Temme expansion
381- @test iszero ((FT -> @allocated (gamma_inc (FT (30.0 ), FT (29.99999 ), 0 )))( FT))
389+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (30.0 ), FT (29.99999 ), 0 )), FT))
382390 # ## gamma_inc_minimax: minimax approximation
383- @test iszero ((FT -> @allocated (gamma_inc (FT (100.0 ), FT (80.0 ), 0 )))( FT))
391+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (100.0 ), FT (80.0 ), 0 )), FT))
384392 # ## gamma_inc_temme: Temme expansion
385- @test iszero ((FT -> @allocated (gamma_inc (FT (100.0 ), FT (80.0 ), 1 )))( FT))
393+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (100.0 ), FT (80.0 ), 1 )), FT))
386394 # ## gamma_inc_cf: Continued fraction
387- @test iszero ((FT -> @allocated (gamma_inc (FT (1.7 ), FT (2.5 ))))( FT))
395+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (1.7 ), FT (2.5 ))), FT))
388396 # ## gamma_inc_taylor: Taylor series
389- @test iszero ((FT -> @allocated (gamma_inc (FT (11.1 ), FT (0.001 ))))( FT))
397+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (11.1 ), FT (0.001 ))), FT))
390398 # ## gamma_inc_asym: Asymptotic expansion
391- @test iszero ((FT -> @allocated (gamma_inc (FT (10.0 ), FT (35.0 ))))( FT))
399+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (10.0 ), FT (35.0 ))), FT))
392400 # ## gamma_inc_fsum: Finite sums
393- @test iszero ((FT -> @allocated (gamma_inc (FT (24.0 ), FT (25 ))))( FT))
401+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (24.0 ), FT (25 ))), FT))
394402 # # a==0.5
395403 # ## erfc
396- @test iszero ((FT -> @allocated (gamma_inc (FT (0.5 ), FT (0.5 ))))( FT))
404+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (0.5 ), FT (0.5 ))), FT))
397405 # # x < 1.1
398406 # ## gamma_inc_taylor_x
399- @test iszero ((FT -> @allocated (gamma_inc (FT (0.9 ), FT (0.8 ))))( FT))
407+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (0.9 ), FT (0.8 ))), FT))
400408 # # else
401409 # ## gamma_inc_cf
402- @test iszero ((FT -> @allocated (gamma_inc (FT (0.7 ), FT (2.5 ))))( FT))
410+ @test iszero (run_twice (FT -> @allocated (gamma_inc (FT (0.7 ), FT (2.5 ))), FT))
403411 end
404412
405413 @testset " gamma_inc_inv allocations" begin
406414 # `@allocated` checks for allocations for specific code paths
407415 # # x0 approximation paths
408416 # ## gamma_inc_inv_psmall
409- @test iszero ((FT -> @allocated (gamma_inc_inv (FT (1.0 ), FT (0.01 ), FT (0.99 ))))( FT))
417+ @test iszero (run_twice (FT -> @allocated (gamma_inc_inv (FT (1.0 ), FT (0.01 ), FT (0.99 ))), FT))
410418 # ## gamma_inc_inv_qsmall
411- @test iszero ((FT -> @allocated (gamma_inc_inv (FT (5.0 ), FT (0.99 ), FT (0.01 ))))( FT))
419+ @test iszero (run_twice (FT -> @allocated (gamma_inc_inv (FT (5.0 ), FT (0.99 ), FT (0.01 ))), FT))
412420 # ## gamma_inc_inv_alarge
413- @test iszero ((FT -> @allocated (gamma_inc_inv (FT (50.0 ), FT (0.3 ), FT (0.7 ))))( FT))
421+ @test iszero (run_twice (FT -> @allocated (gamma_inc_inv (FT (50.0 ), FT (0.3 ), FT (0.7 ))), FT))
414422 end
415423end
0 commit comments