Skip to content

Commit 5f30259

Browse files
Force enable MKL during benchmarking to ensure availability
- Set LoadMKL_JLL=true before loading LinearSolve in autotune module - This ensures MKL algorithms are available for benchmarking - Track the original preference to inform user of temporary change - Final preference is still set based on benchmark results - Added documentation explaining this behavior
1 parent 80d7313 commit 5f30259

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/LinearSolveAutotune/src/LinearSolveAutotune.jl

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
module LinearSolveAutotune
22

3-
# Note: MKL preference should be set before loading LinearSolve for optimal performance
4-
# The autotune system will write the appropriate preference based on benchmark results
3+
# Ensure MKL is available for benchmarking by setting the preference before loading LinearSolve
54
using Preferences
65
using MKL_jll
6+
7+
# Set MKL preference to true for benchmarking if MKL is available
8+
# We need to use UUID instead of the module since LinearSolve isn't loaded yet
9+
const LINEARSOLVE_UUID = Base.UUID("7ed4a6bd-45f5-4d41-b270-4a48e9bafcae")
10+
if MKL_jll.is_available()
11+
# Force load MKL for benchmarking to ensure we can test MKL algorithms
12+
# The autotune results will determine the final preference setting
13+
current_pref = Preferences.load_preference(LINEARSOLVE_UUID, "LoadMKL_JLL", nothing)
14+
if current_pref !== true
15+
Preferences.set_preferences!(LINEARSOLVE_UUID, "LoadMKL_JLL" => true; force = true)
16+
@info "Temporarily setting LoadMKL_JLL=true for benchmarking (was $(current_pref))"
17+
end
18+
end
19+
720
using LinearSolve
821
using BenchmarkTools
922
using DataFrames
@@ -145,6 +158,12 @@ Run a comprehensive benchmark of all available LU factorization methods and opti
145158
- Set Preferences for optimal algorithm selection
146159
- Support both CPU and GPU algorithms based on hardware detection
147160
- Test algorithm compatibility with different element types
161+
- Automatically manage MKL loading preference based on performance results
162+
163+
!!! note "MKL Preference Management"
164+
During benchmarking, MKL is temporarily enabled (if available) to test MKL algorithms.
165+
After benchmarking, the LoadMKL_JLL preference is set based on whether MKL algorithms
166+
performed best in any category. This optimizes startup time and memory usage.
148167
149168
# Arguments
150169

lib/LinearSolveAutotune/src/preferences.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ function set_algorithm_preferences(categories::Dict{String, String})
128128

129129
# Set MKL preference based on whether it was best for any category
130130
# If MKL wasn't best anywhere, disable it to avoid loading unnecessary dependencies
131+
# Note: During benchmarking, MKL is temporarily enabled to test MKL algorithms
132+
# This final preference setting determines whether MKL loads in normal usage
131133
Preferences.set_preferences!(LinearSolve, "LoadMKL_JLL" => mkl_is_best_somewhere; force = true)
132134

133135
if mkl_is_best_somewhere

0 commit comments

Comments
 (0)