Skip to content

Conversation

ChrisRackauckas
Copy link
Member

Summary

  • Implements intelligent MKL preference management in LinearSolveAutotune
  • Analyzes benchmark results to determine if MKL algorithms perform best
  • Automatically sets LoadMKL_JLL preference based on performance

Details

This PR adds MKL preference management to the autotune system:

  1. Performance Analysis: During benchmarking, the system tracks whether MKL algorithms (like MKLLUFactorization) are best for any size/element type category
  2. Smart Preference Setting:
    • If MKL is best in at least one category → sets LoadMKL_JLL to true
    • If MKL is never best → sets LoadMKL_JLL to false to avoid loading unnecessary dependencies
  3. Preference Management:
    • Added MKL preference display in
    • Included MKL preference clearing in

Benefits

  • Reduced startup time: When MKL is not beneficial, it won't be loaded
  • Lower memory usage: Unnecessary MKL dependencies are avoided
  • Automatic optimization: Users get the best configuration without manual tuning

Testing

Added test file to verify:

  • MKL preference is correctly set when MKL algorithms are best
  • MKL preference is disabled when MKL algorithms are not best
  • Preference clearing works correctly

- Analyze if MKL algorithms (MKLLUFactorization) perform best in any category
- Write LoadMKL_JLL preference based on benchmark results
- Set to false if MKL is never best to avoid loading unnecessary dependencies
- Set to true if MKL wins in any category to ensure availability
- Add MKL preference display in show_current_preferences
- Include MKL preference clearing in clear_algorithm_preferences

This optimization reduces startup time and memory usage when MKL is not beneficial for the user's workload.
@@ -23,13 +23,21 @@ function set_algorithm_preferences(categories::Dict{String, String})

# Extract benchmarked results by element type and size
benchmarked = Dict{String, Dict{String, String}}()
mkl_is_best_somewhere = false # Track if MKL wins any category

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

for (key, algorithm) in categories
if contains(key, "_")
eltype, size_range = split(key, "_", limit=2)
if !haskey(benchmarked, eltype)
benchmarked[eltype] = Dict{String, String}()
end
benchmarked[eltype][size_range] = algorithm

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

- 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
# Note: During benchmarking, MKL is temporarily enabled to test MKL algorithms
# This final preference setting determines whether MKL loads in normal usage
Preferences.set_preferences!(LinearSolve, "LoadMKL_JLL" => mkl_is_best_somewhere; force = true)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

else
@info "MKL was not best in any category - setting LoadMKL_JLL preference to false to avoid loading unnecessary dependencies"
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

# Clear MKL preference
Preferences.delete_preferences!(LinearSolve, "LoadMKL_JLL"; force = true)
@info "Cleared MKL preference"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

if mkl_pref !== nothing
println("\nMKL Usage: $(mkl_pref ? "Enabled" : "Disabled")")
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

@ChrisRackauckas ChrisRackauckas merged commit e7d01ed into main Aug 10, 2025
102 of 119 checks passed
@ChrisRackauckas ChrisRackauckas deleted the mkl-preference-management branch August 10, 2025 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant