Skip to content

Commit

Permalink
try saving mem benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale-Black committed Jan 22, 2025
1 parent dc3eb7f commit 300ddcf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 62 deletions.
84 changes: 24 additions & 60 deletions benchmarks/aggregate.jl
Original file line number Diff line number Diff line change
@@ -1,71 +1,35 @@
using BenchmarkTools

const GPU_BACKENDS = ["AMDGPU", "CUDA", "Metal", "oneAPI"]
const NUM_CPU_THREADS = [1, 2, 4, 8]
using JSON

const RESULTS = BenchmarkGroup()
const MEMORY_RESULTS = Dict{String, Dict{String, Float64}}()

# Aggregate CPU results
for n in NUM_CPU_THREADS
filename = string("CPUbenchmarks", n, "threads.json")
filepath = joinpath(@__DIR__, "results", filename)
if ispath(filepath)
nthreads_results = BenchmarkTools.load(filepath)[1]
for benchmark in keys(nthreads_results)
if !haskey(RESULTS, benchmark)
RESULTS[benchmark] = BenchmarkGroup()
end
for size in keys(nthreads_results[benchmark])
if !haskey(RESULTS[benchmark], size)
RESULTS[benchmark][size] = BenchmarkGroup()
end
for algorithm in keys(nthreads_results[benchmark][size])
if !haskey(RESULTS[benchmark][size], algorithm)
RESULTS[benchmark][size][algorithm] = BenchmarkGroup()
end
if !haskey(RESULTS[benchmark][size][algorithm], "CPU")
RESULTS[benchmark][size][algorithm]["CPU"] = BenchmarkGroup()
end
RESULTS[benchmark][size][algorithm]["CPU"][string(n, " thread(s)")] =
nthreads_results[benchmark][size][algorithm]["CPU"][string(n, " thread(s)")]
end
end
end
else
@warn "No CPU benchmark file found at path: $(filepath)"
# Load CPU benchmarks
for threads in [1, 4]
filename = joinpath(@__DIR__, "results", string("CPUbenchmarks", threads, "threads.json"))
if isfile(filename)
RESULTS["CPU_$(threads)thread"] = BenchmarkTools.load(filename)[1]
end
end

# Aggregate GPU results
for backend in GPU_BACKENDS
filename = string(backend, "benchmarks.json")
filepath = joinpath(@__DIR__, "results", filename)
if ispath(filepath)
backend_results = BenchmarkTools.load(filepath)[1]
for benchmark in keys(backend_results)
if !haskey(RESULTS, benchmark)
RESULTS[benchmark] = BenchmarkGroup()
end
for size in keys(backend_results[benchmark])
if !haskey(RESULTS[benchmark], size)
RESULTS[benchmark][size] = BenchmarkGroup()
end
for algorithm in keys(backend_results[benchmark][size])
if !haskey(RESULTS[benchmark][size], algorithm)
RESULTS[benchmark][size][algorithm] = BenchmarkGroup()
end
if !haskey(RESULTS[benchmark][size][algorithm], "GPU")
RESULTS[benchmark][size][algorithm]["GPU"] = BenchmarkGroup()
end
RESULTS[benchmark][size][algorithm]["GPU"][backend] =
backend_results[benchmark][size][algorithm]["GPU"][backend]
end
end
end
else
@warn "No GPU benchmark file found at path: $(filepath)"
# Load GPU benchmarks and memory info
for backend in ["Metal", "CUDA", "AMDGPU", "oneAPI"]
# Load timing benchmarks
filename = joinpath(@__DIR__, "results", "$(backend)benchmarks.json")
if isfile(filename)
RESULTS[backend] = BenchmarkTools.load(filename)[1]
end

# Load memory info
memory_filename = joinpath(@__DIR__, "results", "$(backend)_memory_info.json")
if isfile(memory_filename)
MEMORY_RESULTS[backend] = JSON.parsefile(memory_filename)
end
end

# Save combined results
mkpath(joinpath(@__DIR__, "results"))
BenchmarkTools.save(joinpath(@__DIR__, "results", "combinedbenchmarks.json"), RESULTS)
BenchmarkTools.save(joinpath(@__DIR__, "results", "combinedbenchmarks.json"), RESULTS)
open(joinpath(@__DIR__, "results", "combined_memory_info.json"), "w") do io
JSON.print(io, MEMORY_RESULTS)
end
11 changes: 9 additions & 2 deletions benchmarks/runbenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using DistanceTransforms
using Suppressor
using BenchmarkTools
using Random
# using JSON
using JSON

const SUITE = BenchmarkGroup()
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 5 # Reduce this from 120 seconds
Expand All @@ -20,9 +20,16 @@ results = BenchmarkTools.run(SUITE; verbose=true)
filepath = joinpath(@__DIR__, "results")
mkpath(filepath)

# Save timing benchmarks
filename = BENCHMARK_GROUP == "CPU" ?
string("CPUbenchmarks", BENCHMARK_CPU_THREADS, "threads.json") :
string(BENCHMARK_GROUP, "benchmarks.json")

BenchmarkTools.save(joinpath(filepath, filename), median(results))
@info "Saved results to $(joinpath(filepath, filename))"
@info "Saved results to $(joinpath(filepath, filename))"

# Ensure memory info file is also uploaded
if BENCHMARK_GROUP != "CPU"
memory_filename = "$(BENCHMARK_GROUP)_memory_info.json"
@info "Memory info saved to $(joinpath(filepath, memory_filename))"
end

0 comments on commit 300ddcf

Please sign in to comment.