Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Jan 7, 2024
1 parent eae1c6d commit 1a9ad22
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "0.6.0"
[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
Bumper = "8ce10254-0962-460f-a3d8-1f77fea1446e"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand All @@ -16,6 +17,7 @@ PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[compat]
Expand Down
53 changes: 53 additions & 0 deletions experimental/bumper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using BenchmarkTools, Bumper

function work0(polys; use_custom_allocator=false)
if use_custom_allocator
custom_allocator = Bumper.SlabBuffer()
@no_escape custom_allocator begin
work1(polys, custom_allocator)
end
else
work1(polys)
end
end

# Very important work
function work1(polys, custom_allocator=nothing)
res = 0
for poly in polys
new_poly = work2(poly, custom_allocator)
res += sum(new_poly)
end
res
end

function work2(poly::Vector{T}, ::Nothing) where {T}
new_poly = Vector{T}(undef, length(poly))
work3!(new_poly)
end

function work2(poly::Vector{T}, custom_allocator) where {T}
new_poly = Bumper.alloc!(custom_allocator, T, length(poly))
work3!(new_poly)
end

function work3!(poly::AbstractVector{T}) where {T}
poly[1] = one(T)
for i in 2:length(poly)
poly[i] = convert(T, i)^3 - poly[i - 1]
end
poly
end

###

m, n = 100, 10_000
polys = [rand(UInt32, rand(1:m)) for _ in 1:n];

@btime work0(polys, use_custom_allocator=false)
# 956.800 μs (10001 allocations: 2.55 MiB)
# 0x000000064889383b

@btime work0(polys, use_custom_allocator=true)
# 1.326 ms (5 allocations: 272 bytes)
# 0x000000064889383b
6 changes: 5 additions & 1 deletion src/Groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ import AbstractAlgebra: base_ring, elem_type

import Atomix

import Base: *
import Base.Threads
import Base.Threads: nthreads, threadid
import Base.MultiplicativeInverses: UnsignedMultiplicativeInverse

import Base: *

# Custom allocators
import Bumper

import Combinatorics

using ExprTools
Expand Down

0 comments on commit 1a9ad22

Please sign in to comment.