Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
/docs/build/
.vscode
.perftest_logs
.perftests
.perftests

._*
.DS_Store
.ipynb_checkpoints/
core
experiments/
.claude
268 changes: 268 additions & 0 deletions AGENT.md

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d"
CountFlops = "1db9610d-79e1-487a-8d40-77f3295c7593"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Hwloc = "0e44f5e4-bd66-52a0-8798-143a42290a1d"
Expand All @@ -28,13 +29,18 @@ ThreadPinningCore = "6f48bc29-05ce-4cc8-baad-4adcba581a18"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"

[weakdeps]
LIKWID = "bf22376a-e803-4184-b2ed-56326e3bff83"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"

[extensions]
PerfTest_LIKWIDExt = "LIKWID"
PerfTest_MPIExt = "MPI"
PerfTest_CUDAExt = "CUDA"
PerfTest_AMDGPUExt = "AMDGPU"

[compat]
julia = "1, 1.11"
BandwidthBenchmark = "0.2.0"
BenchmarkTools = "1"
Configurations = "0"
Expand All @@ -50,3 +56,4 @@ PrecompileTools = "1.2"
Suppressor = "0"
ThreadPinningCore = "0.4"
UnicodePlots = "3"
julia = "1, 1.11"
32 changes: 22 additions & 10 deletions docs/src/configuration_params.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

This document describes all configuration parameters available. Parameters are organized by section, they are specified in TOML format.

Every transformation starts from the default values below, overridden by the `perftest_config.toml` file in the working directory. If the file does not exist it is created with the default values. The file does not need to define every parameter: missing sections or parameters keep their default value, and a parameter with an incorrect type is reported as an error and keeps its default value as well. A section or parameter that does not exist (e.g. a misspelled one) is reported as an error, naming it along with the existing sections, or the existing parameters of its section, and is ignored while the rest of the file applies. A file that cannot be parsed is reported as an error and left untouched, and the default configuration is used instead.

The configuration is used when a recipe is transformed, and the generated suite keeps the configuration it was generated with: when it executes, wherever and however that happens, it uses those same values. The only exception is the `[bencher]` section, see below. Values that depend on the machine are fixed at generation as well, but the ones that describe it relatively (e.g. a thread arrangement like `:numa`, or a buffer size of `0`) are resolved on the machine that executes the suite. A `@perftest_config` macro applies from its place in the recipe onwards. In an included recipe (see `recursive`) it applies only to the part of the suite generated from that recipe, the including recipe gets its own configuration back after it.

The argument of `@perftest_config` must be a string literal, as it is read when the recipe is transformed (a variable or any other expression is reported as a parse error). Its content is checked against the parameters below: invalid TOML, a section or parameter that does not exist (naming the existing ones, as for the file), a parameter with an incorrect type (naming the expected and the given type) and a parameter that is used before the recipe is read (`[MPI]` `enabled`) are reported as parse errors, so the suite is not generated. The rest of its parameters still apply during the transform, so the errors of the rest of the recipe are reported as well.

The `@perftest_config` string may interpolate values inside TOML strings, e.g. `dedicated_reference_file = 'ref_$(gethostname()).JLD2'`. Those keys take their value when the generated suite executes, during the transform they keep their previous value while the rest of the keys are applied as usual. An interpolated value is therefore always a string, so interpolation can only set parameters that take a `String` (e.g. not `verbose = '$(level)'`), otherwise it is reported as a parse error. Interpolation anywhere else (as a whole value, in a key or in a table name) is reported as a parse error as well.

The parameters given with the `config` keyword argument of `runperftests` or `PerfTest.transform` take priority over the file, and are checked one by one: one with an incorrect type is reported as an error and ignored, the rest apply. A section or parameter that does not exist is reported as an error as well, naming the existing ones as for the file, and ignored. The same type check happens when a generated suite executes, in case it was generated by a version of PerfTest with different parameters.

---

## `[general]`
Expand All @@ -10,15 +20,15 @@ General settings that control the overall behavior of the package.

| Parameter | Type | Default | Description |
|---|---|---|---|
| `autoflops` | `Bool` | `true` | Whether the autoflop counter is enabled and accessible during testing. |
| `numas` | `String \| Integer \| Float64` | `"single"` | Amount of NUMAS to use when pinning threads. |
| `threads_per_numa` | `String \| Integer \| Float64` | `"single"` | Amount of threads to pin per NUMA. |
| `save_results` | `Bool` | `true` | Whether to record the results of executing the performance suite. |
| `logs_enabled` | `Bool` | `true` | Enable or disable the log subsystem. If false, this will prevent PerfTest from creating a log folder and log files.|
| `save_folder` | `String` | `".perftests"` | Folder where performance suite results shall be stored. |
| `autoflops` | `Bool` | `false` | Deprecated: automatic flop counting is outdated and not supported (the `:autoflop` primitive is always 0). While it is true, a `@roofline` without `actual_flops` is reported as a parse error: give the flop count of the target to `@roofline` with `actual_flops` instead. Setting the key alone is not an error. A formula or a `@regression` metric that uses `:autoflop` is reported as a parse error regardless of this key. |
| `numas` | `String \| Integer \| Float64` | `"single"` | Amount of NUMA domains whose threads the suite uses, along with `threads_per_numa`. Together they are the thread setting of the suite, which `runperftests` launches it with: it sets the number of threads of the process that executes the suite (`--threads`), it does not pin them. A string names a whole arrangement and is given in both keys: `"single"` (1 thread), `"numa"` (every thread of 1 NUMA domain) or `"all"` (every thread of every NUMA domain). Otherwise both are numbers, each one an integer n ≥ 1 or a float in (0, 1], the ratio of the available ones (e.g. `numas = 1` and `threads_per_numa = 0.5` is half of the threads of 1 NUMA domain). Anything else, e.g. two different names or a name along with a number, is reported as an error, naming the reason and where each key comes from: a parse error if a `@perftest_config` sets one of them. The arrangement is resolved on the machine that executes the suite. A suite has a single thread setting: each key takes its value from the last `@perftest_config` that sets it, even when it is in an included recipe, and a `@perftest_threads` in the recipe takes priority over both. |
| `threads_per_numa` | `String \| Integer \| Float64` | `"single"` | Amount of threads to use per NUMA domain, see `numas`. |
| `save_results` | `Bool` | `true` | Whether to record the results of executing the performance suite. If false, an execution writes neither the result file (see `save_folder`) nor the `[regression]` `dedicated_reference_file`, the existing ones are still used as regression reference. |
| `logs_enabled` | `Bool` | `true` | Enable or disable the log subsystem. If false, nothing is logged from where it is set (neither kept in memory nor printed by `verbose`), and no log folder nor log file is written: the transform saves its logs (see `verbose`) only if it is true in the configuration in force at the end of the recipe. The generated suite writes no log file. |
| `save_folder` | `String` | `".perftests"` | Folder where performance suite results shall be stored, the suite creates it when it saves its results. |
| `max_saved_results` | `Int` | `20` | Maximum amount of performance test suite execution results to be saved in the result file for each suite. |
| `plotting` | `Bool` | `true` | Whether to have plots in the test output of methodologies that support it. |
| `verbose` | `Int` | `0` | Whether to output the collected logs in the standard output. |
| `verbose` | `Int` | `0` | Whether to output the collected logs in the standard output. From 2 on, the logs of the transform are saved in the `.perftest_logs` folder, as decided by the value in force at the end of the recipe (e.g. a `@perftest_config` of the recipe that sets it). |
| `recursive` | `Bool` | `true` | If enabled, whenever a file is included inside a recipe that is being transformed, it will be transformed as well. |
| `safe_formulas` | `Bool` | `false` | Deprecated. |
| `suppress_output` | `Bool` | `true` | Whether to hide the output of the test targets. If false the output of each execution will be shown, which will be probably a long output. |
Expand All @@ -33,7 +43,7 @@ Settings for regression testing.
|---|---|---|---|
| `enabled` | `Bool` | `true` | Whether to use regression testing in this suite. |
| `dedicated_reference_file` | `String` | `""` | If not an empty string, a succesful suite execution will be saved into this file, as well as in the (result file see `[general] save_folder`). The last saved execution will be used as reference for regression testing. If empty the package will look at the result file instead, and find the latest sucessful execution as reference. |
| `default_threshold` | `Number` | `1.1` | The default threshold of the `@regression` macro if no threshold is specified. |
| `default_threshold` | `Number` | `1.1` | The threshold of a `@regression` that gives none, and of the regression every top level testset gets. A metric with `low_is_bad = false` (e.g. a time, the default regression) takes this value, its ratio new/reference must stay below it. A metric with `low_is_bad = true` (the default of `@regression`, e.g. a throughput) takes 2 − this value, its ratio must stay above it: 1.1 tolerates a time up to 10% higher and a throughput up to 10% lower (0.9). A value of 2 or more leaves no threshold for a metric with `low_is_bad = true`, such a `@regression` is reported as a parse error, give it an explicit threshold. |
| `use_bencher` | `Bool` | `false` | Whether to enable Bencher to upload results to an online CI/CD performance benchmark platform. THIS FEATURE IS EXPERIMENTAL and likely unstable. |

---
Expand Down Expand Up @@ -76,7 +86,7 @@ Settings for benchmarking the underlying machine.

| Parameter | Type | Default | Description |
|---|---|---|---|
| `memory_bandwidth_test_buffer_size` | `Int` | `0` | If 0 a buffer size for bandwith benchmarks is used so its at least 4 times bigger than the biggest cache level of the machine. If non-zero this value is used to set the buffer size instead. |
| `memory_bandwidth_test_buffer_size` | `Int` | `0` | If 0 a buffer size for bandwith benchmarks is used so its at least 4 times bigger than the biggest cache level of the machine that executes the suite. If non-zero this value is used to set the buffer size instead. |

---

Expand All @@ -86,7 +96,7 @@ Settings for MPI-based execution.

| Parameter | Type | Default | Description |
|---|---|---|---|
| `enabled` | `Bool` | `false` | Whether to enable the MPI aware performance suite generation, this will mainly make sure tests are measured in all ranks but evaluated on the main rank only, and that machine benchmarks take into account all ranks.|
| `enabled` | `Bool` | `false` | Whether to enable the MPI aware performance suite generation, this will mainly make sure tests are measured in all ranks but evaluated on the main rank only, and that machine benchmarks take into account all ranks. The MPI mode is decided before the recipe is read, so it can only be set in the `perftest_config.toml` file or with the `config` argument of `runperftests` or `PerfTest.transform`, a `@perftest_config` that sets it is reported as a parse error.|
| `mode` | `String` | `"reduce"` | This has no function as of now, but it will be used in future versions of perftest. |

---
Expand All @@ -95,6 +105,8 @@ Settings for MPI-based execution.

Settings for [Bencher](https://bencher.dev) integration. This feature is experimental, and likely prone to bugs.

Unlike the rest of the configuration, this section is read when the suite executes, from the `perftest_config.toml` file of the working directory (the default values are used if there is none), so the credentials are never written into a generated suite. A `@perftest_config` in the recipe that sets these keys takes priority over the file, but its values are written into the suite: interpolate secrets to keep them out of it, e.g. `api_key = '$(ENV["BENCHER_API_KEY"])'`.

| Parameter | Type | Default | Description |
|---|---|---|---|
| `api_key` | `String` | `""` | The Bencher platform key to use to connect to bencher. |
Expand Down
1 change: 1 addition & 0 deletions docs/src/limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ There are a couple of things to keep into consideration when using the package:

1. GPU testing is technically supported, but it requires more effort from the developer to set up since the automatic measurements apart from time elapsed do not apply to GPUs (as of now).
2. The automatic flop counting feature works exclusively for Julia native functions, it can not measure the flops in C calls given the limitations of the subjacent package [CountFlops.jl]
3. LIKWID and GPU (CUDA/AMDGPU) energy/power measurements are repeated to match the actual number of samples `BenchmarkTools` took for the same test (median-aggregated, with the spread preserved as a standard-error-of-the-mean interval when `showvar=true` and at least 30 samples were taken — see `@regression`/`@perfcompare`'s `showvar` argument), so their cost scales with whatever `samples=`/`seconds=`/`evals=` the test uses — tune those explicitly on tests using these extensions if you don't want extension sampling to inherit `BenchmarkTools`' adaptive defaults.


## Features to be expected in the next versions:
Expand Down
6 changes: 3 additions & 3 deletions docs/src/usage.MD
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ using ExampleModule : innerProduct, Test, PerfTest # Importing the target and
@testset "Roofline Test" begin
a,b = rand(1e6),rand(1e6)

@roofline actual_flops=:autoflop target_ratio=0.5
:autoflop / (2 * 8 * 1e6)
@roofline actual_flops=2e6 target_ratio=0.5 begin
2e6 / (2 * 8 * 1e6)
end

@perftest innerProduct(a, b)
Expand All @@ -27,7 +27,7 @@ end
The following things can be appreciated in this example:
1. This is a combined functional and performance unit test suite (there is both @test and @perftest present)
2. The target of the perftest is the innerProduct function
3. The performance test methodology is a roofline model, the developer expects innerProduct to perform at least at 50% of the maximum flop performance set by the roofline. The operational intensity is defined on the main block of the macro. :autoflop is a symbol that enables the use of an automatic flop count feature.
3. The performance test methodology is a roofline model, the developer expects innerProduct to perform at least at 50% of the maximum flop performance set by the roofline. The operational intensity is defined on the main block of the macro, and `actual_flops` gives the flop count of the target (2 flops per element of the vectors), from which the attained flops are computed. Automatic flop counting (`:autoflop`) is outdated and not supported, so the flop count is always given explicitly.

## How to use, a first PerfTest.jl recipe

Expand Down
121 changes: 121 additions & 0 deletions examples/example-kkt-cholesky-regression/KktCholesky.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
module KktCholesky

using LinearAlgebra
using Random

export build_kkt_system, cholesky_factor_fast!, cholesky_factor_regressed!,
forward_substitution!, back_substitution!, solve_kkt, relative_residual

# Synthetic SPD "condensed KKT" system K = AᵀA + σI, b -- representative of
# the normal-equations/Newton system solved every iteration of a QP/SOCP
# interior-point method (Clarabel.jl, OSQP, ECOS, ...). A is m×n with m<n,
# so AᵀA alone is only positive semi-definite (rank ≤ m); σI shifts every
# eigenvalue by σ>0, making K strictly positive definite regardless of rank.
function build_kkt_system(n::Int, m::Int; seed::Int=1, sigma::Float64=1e-2)
rng = MersenneTwister(seed)
A = randn(rng, m, n)
K = Matrix(Symmetric(A' * A))
@inbounds for i in 1:n
K[i, i] += sigma
end
b = randn(rng, n)
return K, b
end

# Unblocked right-looking Cholesky (K = L*Lᵀ), "kji" loop order: for each
# pivot k, the trailing-submatrix rank-1 update loops columns j (outer) then
# rows i (inner), so the innermost loop walks straight down a column of L --
# contiguous in Julia's column-major storage. This is the textbook loop
# order for column-major languages (Julia, Fortran, MATLAB, R).
function cholesky_factor_fast!(L::Matrix{Float64}, K::Matrix{Float64})
n = size(K, 1)
copyto!(L, K)
@inbounds for k in 1:n
L[k, k] = sqrt(L[k, k])
invLkk = 1.0 / L[k, k]
for i in (k+1):n
L[i, k] *= invLkk
end
for j in (k+1):n
ljk = L[j, k]
@simd for i in j:n
L[i, j] -= L[i, k] * ljk
end
end
end
@inbounds for j in 1:n, i in 1:(j-1)
L[i, j] = 0.0
end
return L
end

# THE REGRESSION. Same algorithm, same operations, same floating-point
# results as `cholesky_factor_fast!` (bit-for-bit identical L, see README) --
# only the trailing-submatrix loop nest is transposed to "kij" order: rows i
# outer, columns j inner. `L[i, j]` for fixed i is now walked across a *row*,
# i.e. striding n elements through memory instead of 1. This is the kind of
# one-line-diff bug that shows up when porting/refactoring from a row-major
# reference (C, NumPy) without adjusting loop order for Julia's layout: no
# functional test can ever catch it (@simd is still there, the answer is
# still exactly right), only a performance-regression suite can.
function cholesky_factor_regressed!(L::Matrix{Float64}, K::Matrix{Float64})
n = size(K, 1)
copyto!(L, K)
@inbounds for k in 1:n
L[k, k] = sqrt(L[k, k])
invLkk = 1.0 / L[k, k]
for i in (k+1):n
L[i, k] *= invLkk
end
for i in (k+1):n
lik = L[i, k]
@simd for j in (k+1):i
L[i, j] -= lik * L[j, k]
end
end
end
@inbounds for j in 1:n, i in 1:(j-1)
L[i, j] = 0.0
end
return L
end

function forward_substitution!(z::Vector{Float64}, L::Matrix{Float64}, b::Vector{Float64})
n = length(b)
@inbounds for i in 1:n
s = b[i]
@simd for k in 1:(i-1)
s -= L[i, k] * z[k]
end
z[i] = s / L[i, i]
end
return z
end

# Solves Lᵀx = z; Lᵀ[i, k] = L[k, i].
function back_substitution!(x::Vector{Float64}, L::Matrix{Float64}, z::Vector{Float64})
n = length(z)
@inbounds for i in n:-1:1
s = z[i]
@simd for k in (i+1):n
s -= L[k, i] * x[k]
end
x[i] = s / L[i, i]
end
return x
end

function solve_kkt(K::Matrix{Float64}, b::Vector{Float64}, fast::Bool=true)
n = size(K, 1)
L = Matrix{Float64}(undef, n, n)
fast ? cholesky_factor_fast!(L, K) : cholesky_factor_regressed!(L, K)
z = Vector{Float64}(undef, n)
x = Vector{Float64}(undef, n)
forward_substitution!(z, L, b)
back_substitution!(x, L, z)
return x
end

relative_residual(K, b, x) = norm(K * x - b) / norm(b)

end # module
Loading
Loading