Skip to content

Commit b7d82d6

Browse files
authored
Fix allocation tests for Julia v1.12.5 (#349)
1 parent 304285e commit b7d82d6

6 files changed

Lines changed: 20 additions & 33 deletions

File tree

test/big.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function allocation_test(
2626
A = MA.copy_if_mutable(a)
2727
@test A === short(A, b)
2828
@test g == A
29-
alloc_test_le(() -> short(A, b), n)
30-
alloc_test_le(() -> short_to(c, a, b), n)
29+
alloc_test(() -> short(A, b), n)
30+
alloc_test(() -> short_to(c, a, b), n)
3131
@test g == MA.buffered_operate!(nothing, op, MA.copy_if_mutable(a), b)
3232
@test g == MA.buffered_operate_to!(nothing, c, op, a, b)
3333
buffer = MA.buffer_for(op, typeof(a), typeof(b))

test/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131
@test y == 5
3232
# FIXME This should not allocate but I couldn't figure out where these
3333
# allocations come from.
34-
n = (VERSION >= v"1.11" ? 42 : 30) * sizeof(Int)
34+
n = 6 * @allocated(BigInt(1))
3535
alloc_test(() -> MA.broadcast!!(+, a, b), n)
3636
alloc_test(() -> MA.broadcast!!(+, a, c), 0)
3737
end

test/dispatch.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ function dispatch_tests(::Type{T}) where {T}
1515
c = one(T)
1616
x = convert.(T, [1, 2, 3])
1717
# Need to allocate 1 BigInt for the result and one for the buffer
18-
alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), 2BIGINT_ALLOC)
19-
alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), 2BIGINT_ALLOC)
18+
nalloc = 3 * @allocated(BigInt(1))
19+
alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), nalloc)
20+
alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), nalloc)
2021
if T <: MA.AbstractMutable
21-
alloc_test(() -> x'x, 2BIGINT_ALLOC)
22-
alloc_test(() -> transpose(x) * x, 2BIGINT_ALLOC)
23-
alloc_test(() -> LinearAlgebra.dot(x, x), 2BIGINT_ALLOC)
22+
alloc_test(() -> x'x, nalloc)
23+
alloc_test(() -> transpose(x) * x, nalloc)
24+
alloc_test(() -> LinearAlgebra.dot(x, x), nalloc)
2425
end
2526
end
2627

test/matmul.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ end
204204
)
205205
alloc_test(() -> MA.mutability(y, MA.add_mul, y, A, x), 0)
206206
end
207-
207+
BIGINT_ALLOC = 2 * sizeof(Int) + @allocated(BigInt(1))
208208
alloc_test(() -> MA.add_mul!!(y, A, x), BIGINT_ALLOC)
209209
alloc_test(
210210
() -> MA.operate_fallback!!(MA.IsMutable(), MA.add_mul, y, A, x),
@@ -277,7 +277,7 @@ end
277277
)
278278
alloc_test(() -> MA.mutability(C, MA.add_mul, C, A, B), 0)
279279
end
280-
280+
BIGINT_ALLOC = 2 * sizeof(Int) + @allocated(BigInt(1))
281281
alloc_test(() -> MA.add_mul!!(C, A, B), BIGINT_ALLOC)
282282
alloc_test(() -> MA.operate!!(MA.add_mul, C, A, B), BIGINT_ALLOC)
283283
alloc_test(() -> MA.operate!(MA.add_mul, C, A, B), BIGINT_ALLOC)
@@ -473,8 +473,8 @@ function test_sparse_vector_sum(::Type{T}) where {T}
473473
y = copy(x)
474474
z = copy(y)
475475
# FIXME not sure what is allocating
476-
alloc_test_le(() -> MA.operate!(+, y, z), 200)
477-
alloc_test_le(() -> MA.operate!(-, y, z), 200)
476+
alloc_test(() -> MA.operate!(+, y, z), 200)
477+
alloc_test(() -> MA.operate!(-, y, z), 200)
478478
alloc_test(() -> MA.operate_to!(x, +, y, z), 0)
479479
alloc_test(() -> MA.operate_to!(x, -, y, z), 0)
480480
alloc_test(() -> MA.operate_to!(x, +, y), 0)

test/rewrite_generic.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,20 +480,18 @@ function test_allocations_rewrite_unary_minus()
480480
MA.@rewrite(-sum(x[i] for i in 1:N), move_factors_into_sums = false)
481481
MA.@rewrite(sum(a * x[i] for i in 1:N), move_factors_into_sums = false)
482482
sum(-x[i] for i in 1:N)
483-
total = @allocated sum(-x[i] for i in 1:N)
484-
# actual
485483
value = @allocated(
486484
MA.@rewrite(sum(-x[i] for i in 1:N), move_factors_into_sums = false),
487485
)
488-
@test value < total
486+
@test value < @allocated sum(-x[i] for i in 1:N)
489487
value = @allocated(
490488
MA.@rewrite(-sum(x[i] for i in 1:N), move_factors_into_sums = false),
491489
)
492-
@test value < total
490+
@test value < @allocated -sum(x[i] for i in 1:N)
493491
value = @allocated(
494492
MA.@rewrite(sum(a * x[i] for i in 1:N), move_factors_into_sums = false),
495493
)
496-
@test value < total
494+
@test value < @allocated sum(a * x[i] for i in 1:N)
497495
return
498496
end
499497

test/utilities.jl

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,9 @@
66

77
include("dummy.jl")
88

9-
# Allocating size for allocating a `BigInt`. Half size on 32-bit.
10-
const BIGINT_ALLOC = @static if VERSION >= v"1.12-beta1"
11-
Sys.WORD_SIZE == 64 ? 72 : 36
12-
elseif VERSION >= v"1.11"
13-
Sys.WORD_SIZE == 64 ? 56 : 28
14-
else
15-
Sys.WORD_SIZE == 64 ? 48 : 24
16-
end
17-
18-
function alloc_test(f, n)
19-
f() # compile
20-
@test n == @allocated f()
21-
end
22-
23-
function alloc_test_le(f, n)
9+
function alloc_test(f::F, expected_upper_bound::Integer) where {F<:Function}
2410
f() # compile
25-
@test n >= @allocated f()
11+
measured_allocations = @allocated f()
12+
@test measured_allocations <= expected_upper_bound
13+
return
2614
end

0 commit comments

Comments
 (0)