Skip to content

Commit

Permalink
try agian
Browse files Browse the repository at this point in the history
  • Loading branch information
Dale-Black committed Jan 22, 2025
1 parent 5c54eff commit 0af683b
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions benchmarks/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using ImageMorphology: distance_transform, feature_transform
using KernelAbstractions
using Random, Statistics
import InteractiveUtils
using JSON

const BENCHMARK_GROUP = get(ENV, "BENCHMARK_GROUP", "CPU")

Expand Down Expand Up @@ -133,95 +134,92 @@ function setup_benchmarks(suite::BenchmarkGroup, backend::String, num_cpu_thread
end
elseif backend == "Metal"
@info "Running Metal benchmarks"
memory_info = Dict{String, Float64}()
for n in sizes_2D
f = Float32.(rand([0, 1], n, n))
f_gpu = MtlArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["2D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["2D"]["Size_$n"]["Memory"], "GPU")
suite["2D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["2D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["2D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

for n in sizes_3D
f = Float32.(rand([0, 1], n, n, n))
f_gpu = MtlArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["3D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["3D"]["Size_$n"]["Memory"], "GPU")
suite["3D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["3D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["3D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

# Store memory info in a file with a different name to avoid conflicts
open(joinpath(@__DIR__, "results", "$(backend)_memory_info.json"), "w") do io
JSON.print(io, memory_info)
end
elseif backend == "CUDA"
@info "Running CUDA benchmarks"
memory_info = Dict{String, Float64}()
for n in sizes_2D
f = Float32.(rand([0, 1], n, n))
f_gpu = CUDA.CuArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["2D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["2D"]["Size_$n"]["Memory"], "GPU")
suite["2D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["2D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["2D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

for n in sizes_3D
f = Float32.(rand([0, 1], n, n, n))
f_gpu = CUDA.CuArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["3D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["3D"]["Size_$n"]["Memory"], "GPU")
suite["3D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["3D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["3D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

open(joinpath(@__DIR__, "results", "$(backend)_memory_info.json"), "w") do io
JSON.print(io, memory_info)
end
elseif backend == "AMDGPU"
@info "Running AMDGPU benchmarks"
memory_info = Dict{String, Float64}()
for n in sizes_2D
f = Float32.(rand([0, 1], n, n))
f_gpu = ROCArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["2D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["2D"]["Size_$n"]["Memory"], "GPU")
suite["2D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["2D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["2D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

for n in sizes_3D
f = Float32.(rand([0, 1], n, n, n))
f_gpu = ROCArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["3D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["3D"]["Size_$n"]["Memory"], "GPU")
suite["3D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["3D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["3D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

open(joinpath(@__DIR__, "results", "$(backend)_memory_info.json"), "w") do io
JSON.print(io, memory_info)
end
elseif backend == "oneAPI"
@info "Running oneAPI benchmarks"
memory_info = Dict{String, Float64}()
for n in sizes_2D
f = Float32.(rand([0, 1], n, n))
f_gpu = oneArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["2D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["2D"]["Size_$n"]["Memory"], "GPU")
suite["2D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["2D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["2D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

for n in sizes_3D
f = Float32.(rand([0, 1], n, n, n))
f_gpu = oneArray(f)
benchmark_result = benchmark_with_memory(() -> transform(boolean_indicator(f_gpu)), backend)
suite["3D"]["Size_$n"]["Felzenszwalb"]["GPU"][backend] = benchmark_result.benchmark
if !haskey(suite["3D"]["Size_$n"]["Memory"], "GPU")
suite["3D"]["Size_$n"]["Memory"]["GPU"] = BenchmarkGroup()
end
suite["3D"]["Size_$n"]["Memory"]["GPU"][backend] = benchmark_result.peak_memory_mb
memory_info["3D_Size_$(n)"] = benchmark_result.peak_memory_mb
end

open(joinpath(@__DIR__, "results", "$(backend)_memory_info.json"), "w") do io
JSON.print(io, memory_info)
end
else
@error "Unknown backend: $backend"
Expand Down

0 comments on commit 0af683b

Please sign in to comment.