-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1039 from gridap/benchmarks
Benchmarks
- Loading branch information
Showing
13 changed files
with
273 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Benchmarks | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
target: | ||
description: 'Target branch' | ||
required: true | ||
type: string | ||
base: | ||
description: 'Base branch' | ||
required: true | ||
default: 'master' | ||
type: string | ||
|
||
jobs: | ||
benchmark: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
version: | ||
- '1.10' | ||
arch: | ||
- x64 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: julia-actions/setup-julia@v2 | ||
with: | ||
version: ${{ matrix.version }} | ||
arch: ${{ matrix.arch }} | ||
- uses: actions/cache@v4 | ||
env: | ||
cache-name: cache-artifacts | ||
with: | ||
path: ~/.julia/artifacts | ||
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} | ||
restore-keys: | | ||
${{ runner.os }}-test-${{ env.cache-name }}- | ||
${{ runner.os }}-test- | ||
${{ runner.os }}- | ||
- uses: julia-actions/julia-buildpkg@v1 | ||
- name: Install Gridap in main environment | ||
run: julia -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' | ||
- name: Install dependencies | ||
run: julia --project=benchmark/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' | ||
- name: Run benchmarks | ||
run: julia --project=benchmark/ --color=yes benchmark/run_benchmarks.jl | ||
env: | ||
BM_BASE: ${{ github.event.inputs.base }} | ||
BM_TARGET: ${{ github.event.inputs.target }} | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: benchmarks | ||
path: benchmark/benchmark_results.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[deps] | ||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" | ||
Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e" | ||
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Benchmarking Suite | ||
|
||
The following benchmarking suite uses `PkgBenchmark.jl` and `BenchmarkTools.jl` to compare the performance of different branches of Gridap. | ||
|
||
## Running the benchmarks | ||
|
||
### Running as CI job | ||
|
||
The benchmarks are setup as a manual Github Actions workflow in `.github/workflows/benchmark.yml`. To run the workflow, you will need administrator access to the Gridap repository, then follow instructions [here](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/manually-running-a-workflow). | ||
|
||
The workflow will has two inputs: `target` and `base`, which are the branches/tags/commits you want to compare. The workflow will run the benchmarks on the `target` branch and compare them with the `base` branch (`master` by default). | ||
|
||
You can also run the workflow using Github CLI and the following command: | ||
|
||
```bash | ||
gh workflow run benchmark.yml -f target=your_target_branch -f base=your_base_branch | ||
``` | ||
|
||
### Running Locally | ||
|
||
To run the benchmarks locally, you can have a look at the [documentation for `PkgBenchmark.jl`](https://juliaci.github.io/PkgBenchmark.jl/stable/run_benchmarks/). | ||
|
||
Alternatively, you can run the CI script locally from a local copy of the repository. From the Gridap root directory, run the following commands: | ||
|
||
```bash | ||
# Instantiate Gridap and Gridap/benchmark | ||
julia -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' | ||
julia --project=benchmark/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' | ||
# Run the benchmarks | ||
export BM_TARGET = "your target branch" | ||
export BM_BASE = "your reference branch" | ||
julia --project=benchmark/ --color=yes benchmark/run_benchmarks.jl | ||
``` | ||
|
||
where `BM_TARGET` and `BM_BASE` are the branches/tags/commits you want to compare. | ||
|
||
## Adding a new benchmark | ||
|
||
To add a new benchmark suite `xyx`, create a new file `bm/bm_xyx.jl` that with the following structure: | ||
|
||
```julia | ||
module bm_xyx | ||
|
||
using PkgBenchmark, BenchmarkTools | ||
|
||
const SUITE = BenchmarkGroup() | ||
|
||
[... Add your benchmarks here ...] | ||
|
||
end # module | ||
``` | ||
|
||
Then, add the following line to the `benchmarks.jl` file: | ||
|
||
```julia | ||
@include_bm "bm_xyz" | ||
``` | ||
|
||
This should automatically include the new benchmarks into the global benchmarking suite. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using BenchmarkTools | ||
using PkgBenchmark | ||
using Gridap | ||
|
||
macro include_bm(SUITE,name) | ||
quote | ||
include("bm/$($name).jl") | ||
SUITE["$($name)"] = $(Symbol(name)).SUITE | ||
end | ||
end | ||
|
||
const SUITE = BenchmarkGroup() | ||
|
||
@include_bm SUITE "bm_assembly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module bm_assembly | ||
|
||
using PkgBenchmark, BenchmarkTools | ||
using Gridap | ||
using Gridap.Geometry | ||
|
||
mass(u,v,dΩ) = ∫(u⋅v)dΩ | ||
laplacian(u,v,dΩ) = ∫(∇(u)⊙∇(v))dΩ | ||
graddiv(u,v,dΩ) = ∫((∇⋅u)⋅(∇⋅v))dΩ | ||
|
||
function driver( | ||
Ω :: Triangulation, | ||
reffe :: Tuple, | ||
qdegree :: Integer, | ||
biform :: Function | ||
) | ||
model = get_background_model(Ω) | ||
dΩ = Measure(Ω,qdegree) | ||
V = TestFESpace(model, reffe) | ||
a(u,v) = biform(u,v,dΩ) | ||
A = assemble_matrix(a, V, V) | ||
end | ||
|
||
const SUITE = BenchmarkGroup() | ||
|
||
for (D,n) in [(2,10),(3,6)] | ||
domain = Tuple([repeat([0,1], D)...]) | ||
partition = Tuple(fill(n, D)) | ||
model = UnstructuredDiscreteModel(CartesianDiscreteModel(domain, partition)) | ||
trian_cases = [ | ||
("bulk",Triangulation(model)), | ||
("view",Triangulation(model,collect(1:div(n^D,2)))), # About half of the cells | ||
] | ||
for (trian_name, trian) in trian_cases | ||
for order in [1,2,3] | ||
basis_cases = [ | ||
("lagrangian",lagrangian,Float64,order), | ||
("vector_lagragian",lagrangian,VectorValue{D,Float64},order), | ||
("raviart_thomas",raviart_thomas,Float64,order-1), | ||
] | ||
for (basis_name,basis,T,degree) in basis_cases | ||
biform_cases = [ | ||
("mass",mass,2*order), | ||
("laplacian",laplacian,2*(order-1)), | ||
("graddiv",graddiv,2*(order-1)), | ||
] | ||
for (biform_name,biform,qdegree) in biform_cases | ||
reffe = ReferenceFE(basis, T, degree) | ||
name = "assembly_$(D)D_$(trian_name)_$(basis_name)_$(biform_name)_$(order)" | ||
SUITE[name] = @benchmarkable driver( | ||
$(trian),$(reffe),$(qdegree),$(biform) | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Pkg | ||
|
||
Pkg.activate(@__DIR__) | ||
Pkg.develop(PackageSpec(path = dirname(@__DIR__))) | ||
Pkg.instantiate() | ||
|
||
using Gridap | ||
using PkgBenchmark | ||
|
||
config_kwargs = (; | ||
juliacmd = `julia -O3`, | ||
) | ||
|
||
if haskey(ENV,"BM_TARGET") # Provided by CI workflow | ||
target = BenchmarkConfig(;config_kwargs..., id = ENV["BM_TARGET"]) | ||
else # Default to the current commit | ||
target = BenchmarkConfig(;config_kwargs...) | ||
end | ||
|
||
if haskey(ENV,"BM_BASE") # Provided by CI workflow | ||
base = BenchmarkConfig(;config_kwargs..., id = ENV["BM_BASE"]) | ||
else # Default to master | ||
base = BenchmarkConfig(;config_kwargs..., id = "master") | ||
end | ||
|
||
results = judge(Gridap, target, base) | ||
outfile = normpath(@__DIR__,"benchmark_results.md") | ||
export_markdown(outfile,results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module AquaTests | ||
|
||
using Gridap | ||
using Aqua | ||
|
||
Aqua.test_all( | ||
Gridap, | ||
ambiguities = false, | ||
unbound_args = false | ||
) | ||
|
||
""" | ||
Comment: Ambiguities | ||
I think all ambiguities are either false positives or never used in practice... I've seen | ||
other packages set `ambiguities = false` as well, so I think it's fine to do so. | ||
""" | ||
|
||
""" | ||
Comment: Unbound Args | ||
We do have some unbound type warnings. However, these are calls which are never executed in | ||
the code. | ||
They mostly involve things like `f(a::T...) where T`, which trigger the warning | ||
in the case were the function `f` is called with no arguments. This can be fixed as described | ||
in https://juliatesting.github.io/Aqua.jl/stable/unbound_args/#test_unbound_args, but it is quite | ||
a pain to do so... | ||
I guess something to think about in the future. | ||
""" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters