Skip to content

Commit

Permalink
run CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Apr 15, 2024
1 parent 23b2524 commit 2a8208f
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/PerformanceCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.BENCHMARK_KEY }}
PR_NUMBER: ${{ github.event.number }}
run: julia --threads=auto --project=./benchmark/CI-scripts ./benchmark/CI-scripts/runtests.jl ${{ github.event.pull_request.base.ref }}
run: julia --threads=auto --project=./benchmark/CI-scripts ./benchmark/CI-scripts/runtests.jl
2 changes: 1 addition & 1 deletion benchmark/CI-scripts/run_benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# TTFX
t1 = @timed using Groebner
using AbstractAlgebra

R, (x, y) = polynomial_ring(QQ, ["x", "y"], internal_ordering=:degrevlex)
sys = [x^2 + y, x * y^2]
Expand Down Expand Up @@ -31,7 +32,6 @@ push!(suite, (problem_name="groebner, allocs qq", result=[a1]))
push!(suite, (problem_name="groebner, allocs zp", result=[a2]))

# Runtime
using AbstractAlgebra
import Primes
import Nemo

Expand Down
116 changes: 30 additions & 86 deletions benchmark/CI-scripts/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ function runbench()
)
end

# Adapted from https://github.com/MakieOrg/Makie.jl/blob/v0.21.0/metrics/ttfp/run-benchmark.jl.
# License is MIT.
function best_unit(m)
if m < 1e3
return 1, "ns"
elseif m < 1e6
return 1e3, "μs"
elseif m < 1e9
return 1e6, "ms"
else
return 1e9, "s"
end
end

# Compare results
function compare()
results_master = nothing
Expand Down Expand Up @@ -72,94 +86,35 @@ function compare()
x -> parse(Float64, String(strip(x, ['[', ']', ' ', '\t']))),
split(times_nightly, ",")
)
label_master = "$(mean(times_master)) ± $(std(time_master))"
label_nightly = "$(mean(times_nightly)) ± $(std(times_nightly))"
indicator =
if (1 + MAX_ACCEPTABLE_RELATIVE_DEVIATION) * mean(times_master) <
mean(times_nightly)
fail = true
2, "**slower**❌"
elseif mean(times_master) >
(1 + MAX_ACCEPTABLE_RELATIVE_DEVIATION) * mean(times_nightly)
1, "**faster**✅"
else
0, "insignificant"
end
f, unit = best_unit(maximum(times_master) - minimum(times_master))
m1 = round(mean(times_master) / f, digits=2)
d1 = round(std(time_master) / f, digits=2)
label_master = "$m1 ± $d1 $unit"
m2 = round(mean(times_nightly) / f, digits=2)
d2 = round(std(times_nightly) / f, digits=2)
label_master = "$m2 ± $d2 $unit"
indicator = if (1 + MAX_ACCEPTABLE_RELATIVE_DEVIATION) * m1 < m2
fail = true
2, "**slower**❌"
elseif m1 > (1 + MAX_ACCEPTABLE_RELATIVE_DEVIATION) * m2
1, "**faster**✅"
else
0, "insignificant"
end
table[i, 1] = problem_name
table[i, 2] = label_master
table[i, 3] = label_nightly
table[i, 4] = indicator[2]
# delta = time_nightly - time_master
# if abs(delta) / time_master > MAX_ACCEPTABLE_RELATIVE_DEVIATION
# if abs(delta) > IGNORE_SMALL_ABSOLUTE_DEVIATION
# if delta > 0
# printstyled("Regression\n", color=:red)
# else
# printstyled("Improvement\n", color=:green)
# end
# @test delta / time_master < MAX_ACCEPTABLE_RELATIVE_DEVIATION
# else
# printstyled("Insignificant\n")
# @test true
# end
# else
# printstyled("Insignificant\n")
# @test true
# end
end
fail, table
end

# Adapted from https://github.com/MakieOrg/Makie.jl/blob/v0.21.0/metrics/ttfp/run-benchmark.jl.
# License is MIT.
function github_context()
owner = "sumiya11"
return (
owner=owner,
repo=GitHub.Repo("$(owner)/Groebner.jl"),
auth=GitHub.authenticate(ENV["GITHUB_TOKEN"])
)
end

function best_unit(m)
if m < 1e3
return 1, "ns"
elseif m < 1e6
return 1e3, "μs"
elseif m < 1e9
return 1e6, "ms"
else
return 1e9, "s"
end
end

function make_or_edit_comment(ctx, pr, benchmarks)
prev_comments, _ = GitHub.comments(ctx.repo, pr; auth=ctx.auth)
idx = findfirst(c -> c.user.login == "MakieBot", prev_comments)
if isnothing(idx)
comment = update_comment(COMMENT_TEMPLATE, package_name, benchmarks)
println(comment)
GitHub.create_comment(ctx.repo, pr; auth=ctx.auth, params=Dict("body" => comment))
else
old_comment = prev_comments[idx].body
comment = update_comment(old_comment, package_name, benchmarks)
println(comment)
GitHub.edit_comment(
ctx.repo,
prev_comments[idx],
:pr;
auth=ctx.auth,
params=Dict("body" => comment)
)
end
end

function post(fail, table)
header = """
## Running times benchmark
Note, that these numbers may fluctuate on the CI servers, so take them with a grain of salt.
"""
io = IOBuffer()
println(io, header)
Expand All @@ -171,17 +126,6 @@ function post(fail, table)
pretty_table(io, table)
comment_str = String(take!(io))
println(comment_str)

# Post to github
ctx = github_context()
pr_to_comment = get(ENV, "PR_NUMBER", nothing)
if !isnothing(pr_to_comment)
pr = GitHub.pull_request(ctx.repo, pr_to_comment)
make_or_edit_comment(ctx, pr, table)
else
@info "Not commenting, no PR found"
println(update_comment(COMMENT_TEMPLATE, table))
end
end

function main()
Expand Down
39 changes: 21 additions & 18 deletions benchmark/scripts/pairset/pairset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ using LinuxPerf, JLD2, BenchmarkTools
function clear_data()
for (root, dirs, files) in walkdir((@__DIR__))
for file in files
if endswith((@__DIR__)*"/"*file, "jld2")
rm((@__DIR__)*"/"*file)
if endswith((@__DIR__) * "/" * file, "jld2")
rm((@__DIR__) * "/" * file)
end
end
break
end
end
end

function load_data()
Expand All @@ -17,11 +17,11 @@ function load_data()
@info "" files
for file in files
!endswith(file, "jld2") && continue
a = load((@__DIR__)*"/"*file)
a = load((@__DIR__) * "/" * file)
push!(data, a)
end
break
end
end
data
end

Expand All @@ -31,7 +31,8 @@ function describe_data(data)
println("-------------------------------------------------------------------------")
res = []
for (j, x) in enumerate(data)
ht, update_ht, basis, pairset, i = x["ht"], x["update_ht"], x["basis"], x["pairset"], x["i"]
ht, update_ht, basis, pairset, i =
x["ht"], x["update_ht"], x["basis"], x["pairset"], x["i"]
# println("$j\t$(basis.nfilled)\t\t$(pairset.load)\t\t$(update_ht.load)/$(update_ht.size)")
push!(res, [basis.nfilled, pairset.load, update_ht.load, update_ht.size, i])
end
Expand All @@ -55,7 +56,8 @@ clear_data()
_data = deepcopy(data);
@time begin
for x in data
ht, update_ht, basis, pairset, i = x["ht"], x["update_ht"], x["basis"], x["pairset"], x["i"]
ht, update_ht, basis, pairset, i =
x["ht"], x["update_ht"], x["basis"], x["pairset"], x["i"]
Groebner.pairset_update!(pairset, basis, ht, update_ht, i)
end
end
Expand All @@ -67,7 +69,8 @@ end
_data = deepcopy(data);
@pstats "(cpu-cycles,task-clock),(instructions,branch-instructions,branch-misses), (L1-dcache-load-misses, L1-dcache-loads, cache-misses, cache-references)" begin
for x in _data
ht, update_ht, basis, pairset, i = x["ht"], x["update_ht"], x["basis"], x["pairset"], x["i"]
ht, update_ht, basis, pairset, i =
x["ht"], x["update_ht"], x["basis"], x["pairset"], x["i"]
Groebner.pairset_update!(pairset, basis, ht, update_ht, i)
end
end
Expand All @@ -83,28 +86,28 @@ function gather_pairs(x::Vector{T}, pairs) where {T}
s
end

n, m = 1000, 1000*1000
n, m = 1000, 1000 * 1000
x = rand(UInt64, n)

pairs_i8 = [(rand(1:n), rand(1:n)) for i in 1:m]
pairs_i4 = [(Int32.(rand(1:n)), Int32.(rand(1:n))) for i in 1:m]
pairs_i2 = [(Int16.(rand(1:n)), Int16.(rand(1:n))) for i in 1:m]

@code_llvm debuginfo=:none gather_pairs(x, pairs_i8)
@code_native debuginfo=:none gather_pairs(x, pairs_i8)
@btime gather_pairs($x, pairs_i8) setup=begin
@code_llvm debuginfo = :none gather_pairs(x, pairs_i8)
@code_native debuginfo = :none gather_pairs(x, pairs_i8)
@btime gather_pairs($x, pairs_i8) setup = begin
pairs_i8 = [(Int64.(rand(1:n)), Int64.(rand(1:n))) for i in 1:m]
end

@code_llvm debuginfo=:none gather_pairs(x, pairs_i4)
@code_native debuginfo=:none gather_pairs(x, pairs_i4)
@btime gather_pairs($x, pairs_i4) setup=begin
@code_llvm debuginfo = :none gather_pairs(x, pairs_i4)
@code_native debuginfo = :none gather_pairs(x, pairs_i4)
@btime gather_pairs($x, pairs_i4) setup = begin
pairs_i4 = [(Int32.(rand(1:n)), Int32.(rand(1:n))) for i in 1:m]
end

@code_llvm debuginfo=:none gather_pairs(x, pairs_i2)
@code_native debuginfo=:none gather_pairs(x, pairs_i2)
@btime gather_pairs($x, pairs_i2) setup=begin
@code_llvm debuginfo = :none gather_pairs(x, pairs_i2)
@code_native debuginfo = :none gather_pairs(x, pairs_i2)
@btime gather_pairs($x, pairs_i2) setup = begin
pairs_i2 = [(Int16.(rand(1:n)), Int16.(rand(1:n))) for i in 1:m]
end

Expand Down
10 changes: 5 additions & 5 deletions src/f4/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function sort_polys_by_lead_increasing!(

b_monoms = basis.monoms
h_monoms = hashtable.monoms
permutation = collect(1:basis.nfilled)
permutation = collect(1:(basis.nfilled))
cmps =
(x, y) -> monom_isless(
@inbounds(h_monoms[b_monoms[x][1]]),
Expand Down Expand Up @@ -94,7 +94,7 @@ function is_sorted_by_lead_increasing(
) where {Ord <: AbstractInternalOrdering}
b_monoms = basis.monoms
h_monoms = hashtable.monoms
permutation = collect(1:basis.nfilled)
permutation = collect(1:(basis.nfilled))
cmps =
(x, y) -> monom_isless(
@inbounds(h_monoms[b_monoms[x][1]]),
Expand All @@ -109,7 +109,7 @@ end
function sort_pairset_by_degree!(pairset::Pairset, from::Int, sz::Int)
pairs = pairset.pairs
degs = pairset.degrees
permutation = collect(from:from + sz - 1)
permutation = collect(from:(from + sz - 1))
sort_part!(permutation, 1, sz, by=i -> degs[i], scratch=pairset.scratch1)
# @inbounds pairs[from:(from + sz - 1)] = pairs[permutation]
# @inbounds degs[from:(from + sz - 1)] = degs[permutation]
Expand Down Expand Up @@ -244,7 +244,7 @@ end
function sort_matrix_upper_rows!(matrix::MacaulayMatrix)
#= smaller means pivot being more left =#
#= and density being smaller =#
permutation = collect(1:matrix.nrows_filled_upper)
permutation = collect(1:(matrix.nrows_filled_upper))
# TODO: use "let" here!
cmp =
(x, y) -> matrix_row_decreasing_cmp(
Expand All @@ -271,7 +271,7 @@ end
function sort_matrix_lower_rows!(matrix::MacaulayMatrix)
#= smaller means pivot being more right =#
#= and density being larger =#
permutation = collect(1:matrix.nrows_filled_lower)
permutation = collect(1:(matrix.nrows_filled_lower))
cmp =
(x, y) -> matrix_row_increasing_cmp(
@inbounds(matrix.lower_rows[x]),
Expand Down
2 changes: 1 addition & 1 deletion src/monomials/exponent_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ monom_max_vars(::Type{ExponentVector{T}}) where {T} = 2^32
monom_max_vars(p::ExponentVector{T}) where {T} = monom_max_vars(typeof(p))

monom_totaldeg(pv::ExponentVector) = @inbounds pv[1]
monom_entrytype(pv::ExponentVector{T}) where {T} = T
monom_entrytype(pv::ExponentVector{T}) where {T} = T

monom_copy(pv::ExponentVector) = Base.copy(pv)

Expand Down
2 changes: 1 addition & 1 deletion src/monomials/packed_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ for (op, n) in _defined_packed_tuples
monom_max_vars(::Type{$op{T, B}}) where {T, B} = $n * packed_elperchunk(T, B) - 1
monom_totaldeg(a::$op{T, B}) where {T, B} = a.a1 >> (8 * (sizeof(T) - sizeof(B)))
monom_copy(a::$op{T, B}) where {T, B} = a
monom_entrytype(a::$op{T, B}) where {T, B} = B
monom_entrytype(a::$op{T, B}) where {T, B} = B
end

@eval begin
Expand Down
2 changes: 1 addition & 1 deletion src/monomials/sparse_vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function monom_totaldeg(ev::SparseExponentVector{T}) where {T}
s
end

monom_entrytype(ev::SparseExponentVector{T, I, N}) where {T, I, N} = T
monom_entrytype(ev::SparseExponentVector{T, I, N}) where {T, I, N} = T

monom_copy(ev::SparseExponentVector{T, I, N}) where {T, I, N} =
SparseExponentVector{T, I, N}(Base.copy(ev.inds), Base.copy(ev.vals))
Expand Down

0 comments on commit 2a8208f

Please sign in to comment.