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
4 changes: 2 additions & 2 deletions test/big.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function allocation_test(
A = MA.copy_if_mutable(a)
@test A === short(A, b)
@test g == A
alloc_test_le(() -> short(A, b), n)
alloc_test_le(() -> short_to(c, a, b), n)
alloc_test(() -> short(A, b), n)
alloc_test(() -> short_to(c, a, b), n)
@test g == MA.buffered_operate!(nothing, op, MA.copy_if_mutable(a), b)
@test g == MA.buffered_operate_to!(nothing, c, op, a, b)
buffer = MA.buffer_for(op, typeof(a), typeof(b))
Expand Down
2 changes: 1 addition & 1 deletion test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
@test y == 5
# FIXME This should not allocate but I couldn't figure out where these
# allocations come from.
n = (VERSION >= v"1.11" ? 42 : 30) * sizeof(Int)
n = 6 * @allocated(BigInt(1))
alloc_test(() -> MA.broadcast!!(+, a, b), n)
alloc_test(() -> MA.broadcast!!(+, a, c), 0)
end
Expand Down
11 changes: 6 additions & 5 deletions test/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ function dispatch_tests(::Type{T}) where {T}
c = one(T)
x = convert.(T, [1, 2, 3])
# Need to allocate 1 BigInt for the result and one for the buffer
alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), 2BIGINT_ALLOC)
alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), 2BIGINT_ALLOC)
nalloc = 3 * @allocated(BigInt(1))
alloc_test(() -> MA.fused_map_reduce(MA.add_mul, x, x), nalloc)
alloc_test(() -> MA.fused_map_reduce(MA.add_dot, x, x), nalloc)
if T <: MA.AbstractMutable
alloc_test(() -> x'x, 2BIGINT_ALLOC)
alloc_test(() -> transpose(x) * x, 2BIGINT_ALLOC)
alloc_test(() -> LinearAlgebra.dot(x, x), 2BIGINT_ALLOC)
alloc_test(() -> x'x, nalloc)
alloc_test(() -> transpose(x) * x, nalloc)
alloc_test(() -> LinearAlgebra.dot(x, x), nalloc)
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ end
)
alloc_test(() -> MA.mutability(y, MA.add_mul, y, A, x), 0)
end

BIGINT_ALLOC = 2 * sizeof(Int) + @allocated(BigInt(1))
alloc_test(() -> MA.add_mul!!(y, A, x), BIGINT_ALLOC)
alloc_test(
() -> MA.operate_fallback!!(MA.IsMutable(), MA.add_mul, y, A, x),
Expand Down Expand Up @@ -277,7 +277,7 @@ end
)
alloc_test(() -> MA.mutability(C, MA.add_mul, C, A, B), 0)
end

BIGINT_ALLOC = 2 * sizeof(Int) + @allocated(BigInt(1))
alloc_test(() -> MA.add_mul!!(C, A, B), BIGINT_ALLOC)
alloc_test(() -> MA.operate!!(MA.add_mul, C, A, B), BIGINT_ALLOC)
alloc_test(() -> MA.operate!(MA.add_mul, C, A, B), BIGINT_ALLOC)
Expand Down Expand Up @@ -473,8 +473,8 @@ function test_sparse_vector_sum(::Type{T}) where {T}
y = copy(x)
z = copy(y)
# FIXME not sure what is allocating
alloc_test_le(() -> MA.operate!(+, y, z), 200)
alloc_test_le(() -> MA.operate!(-, y, z), 200)
alloc_test(() -> MA.operate!(+, y, z), 200)
alloc_test(() -> MA.operate!(-, y, z), 200)
alloc_test(() -> MA.operate_to!(x, +, y, z), 0)
alloc_test(() -> MA.operate_to!(x, -, y, z), 0)
alloc_test(() -> MA.operate_to!(x, +, y), 0)
Expand Down
8 changes: 3 additions & 5 deletions test/rewrite_generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,18 @@ function test_allocations_rewrite_unary_minus()
MA.@rewrite(-sum(x[i] for i in 1:N), move_factors_into_sums = false)
MA.@rewrite(sum(a * x[i] for i in 1:N), move_factors_into_sums = false)
sum(-x[i] for i in 1:N)
total = @allocated sum(-x[i] for i in 1:N)
# actual
value = @allocated(
MA.@rewrite(sum(-x[i] for i in 1:N), move_factors_into_sums = false),
)
@test value < total
@test value < @allocated sum(-x[i] for i in 1:N)
value = @allocated(
MA.@rewrite(-sum(x[i] for i in 1:N), move_factors_into_sums = false),
)
@test value < total
@test value < @allocated -sum(x[i] for i in 1:N)
value = @allocated(
MA.@rewrite(sum(a * x[i] for i in 1:N), move_factors_into_sums = false),
)
@test value < total
@test value < @allocated sum(a * x[i] for i in 1:N)
return
end

Expand Down
20 changes: 4 additions & 16 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@

include("dummy.jl")

# Allocating size for allocating a `BigInt`. Half size on 32-bit.
const BIGINT_ALLOC = @static if VERSION >= v"1.12-beta1"
Sys.WORD_SIZE == 64 ? 72 : 36
elseif VERSION >= v"1.11"
Sys.WORD_SIZE == 64 ? 56 : 28
else
Sys.WORD_SIZE == 64 ? 48 : 24
end

function alloc_test(f, n)
f() # compile
@test n == @allocated f()
end

function alloc_test_le(f, n)
function alloc_test(f::F, expected_upper_bound::Integer) where {F<:Function}
f() # compile
@test n >= @allocated f()
measured_allocations = @allocated f()
@test measured_allocations <= expected_upper_bound
return
end
Loading