Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ACEsuit committed May 31, 2024
1 parent c26c36d commit 4a63c70
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 50 deletions.
41 changes: 0 additions & 41 deletions src/WithAlloc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ function _bumper_alloc(allocinfo::NTuple{N, <: Tuple}) where {N}
end


macro withalloc1(ex)
fncall = esc(ex.args[1])
args = esc.(ex.args[2:end])
quote
let
allocinfo = whatalloc($fncall, $(args...), )
storobj = Bumper.alloc!(Bumper.default_buffer(), allocinfo... )
$(fncall)(storobj, $(args...), )
end
end
end

macro withalloc(ex)
fncall = esc(ex.args[1])
args = esc.(ex.args[2:end])
Expand All @@ -39,33 +27,4 @@ macro withalloc(ex)
end


# Teemu's original draft, slightly edited
# macro withalloc(ex)
# # Create symbols based on imput
# out_obj = Symbol( "out_" * String(ex.args[2]) )
# out_obj_info = Symbol( "out_" * String(ex.args[2]) * "_info" )

# # Create expressions
# # out_obj_info = whatalloc(somecalculation!, x1, x2, ...)
# l1 = Expr(:call, :(=), out_obj_info, Expr(:call, :whatalloc, ex.args...) )


# # A = @alloc(out_obj_info.A...)
# # la = Expr(:(=), :A, Expr(:macrocall, Symbol("@alloc"), Symbol("# empty #"), Expr(:..., Expr(:., out_obj_info, :(:A))) ) )

# # B = @alloc(out_obj_info.B...)
# # lb = Expr(:(=), :B, Expr(:macrocall, Symbol("@alloc"), Symbol("# empty #"), Expr(:..., Expr(:., out_obj_info, :(:B))) ) )

# # out_obj = (A = @alloc(out_obj_info.A...), B = @alloc(out_obj_info.B...) )
# l2 = Expr(:(=), out_obj, Expr(:tuple, la, lb) )
# l3 = Expr(:call, out_obj, ex.args... )

# # Create the final expression
# q = quote
# $l1
# $l2
# $l3
# end
# end

end
31 changes: 31 additions & 0 deletions test/_backup.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Teemu's original draft, slightly edited
# we keep this around since it gives a hint how the interface can be
# extended to support named tuples.
#
# macro withalloc(ex)
# # Create symbols based on imput
# out_obj = Symbol( "out_" * String(ex.args[2]) )
# out_obj_info = Symbol( "out_" * String(ex.args[2]) * "_info" )

# # Create expressions
# # out_obj_info = whatalloc(somecalculation!, x1, x2, ...)
# l1 = Expr(:call, :(=), out_obj_info, Expr(:call, :whatalloc, ex.args...) )


# # A = @alloc(out_obj_info.A...)
# # la = Expr(:(=), :A, Expr(:macrocall, Symbol("@alloc"), Symbol("# empty #"), Expr(:..., Expr(:., out_obj_info, :(:A))) ) )

# # B = @alloc(out_obj_info.B...)
# # lb = Expr(:(=), :B, Expr(:macrocall, Symbol("@alloc"), Symbol("# empty #"), Expr(:..., Expr(:., out_obj_info, :(:B))) ) )

# # out_obj = (A = @alloc(out_obj_info.A...), B = @alloc(out_obj_info.B...) )
# l2 = Expr(:(=), out_obj, Expr(:tuple, la, lb) )
# l3 = Expr(:call, out_obj, ex.args... )

# # Create the final expression
# q = quote
# $l1
# $l2
# $l3
# end
# end
14 changes: 5 additions & 9 deletions test/test1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,21 @@ end
@test s2 s1

@no_escape begin
A3 = WithAlloc.@withalloc1 mymul!(B, C)
A3 = WithAlloc.@withalloc mymul!(B, C)

@show A3 A1
s3 = sum(A3)
end
@test s3 s1

@no_escape begin
A4 = WithAlloc.@withalloc mymul!(B, C)

@show A4 A1
s4 = sum(A4)
end
@test s4 s1

##

B = randn(5,10)
C = randn(10, 3)
D = randn(10, 5)
A1 = B * C
A2 = B * D
s = sum(A1) + sum(A2)

function mymul2!(A1, A2, B, C, D)
mul!(A1, B, C)
Expand All @@ -68,5 +61,8 @@ end

@show A1 A1b
@show A2 A2b
sb = sum(A1b) + sum(A2b)
end

@test sb s

0 comments on commit 4a63c70

Please sign in to comment.