-
-
Notifications
You must be signed in to change notification settings - Fork 72
Add MKL preference management to autotune system #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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 | ||||
|
||||
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 | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||
# Check if MKL algorithm is best for this category | ||||
if contains(algorithm, "MKL") | ||||
mkl_is_best_somewhere = true | ||||
@info "MKL algorithm ($algorithm) is best for $eltype at size $size_range" | ||||
end | ||||
end | ||||
end | ||||
|
||||
|
@@ -118,6 +126,16 @@ function set_algorithm_preferences(categories::Dict{String, String}) | |||
end | ||||
end | ||||
|
||||
# Set MKL preference based on whether it was best for any category | ||||
# If MKL wasn't best anywhere, disable it to avoid loading unnecessary dependencies | ||||
Preferences.set_preferences!(LinearSolve, "LoadMKL_JLL" => mkl_is_best_somewhere; force = true) | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||
if mkl_is_best_somewhere | ||||
@info "MKL was best in at least one category - setting LoadMKL_JLL preference to true" | ||||
else | ||||
@info "MKL was not best in any category - setting LoadMKL_JLL preference to false to avoid loading unnecessary dependencies" | ||||
end | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||
# Set a timestamp for when these preferences were created | ||||
Preferences.set_preferences!(LinearSolve, "autotune_timestamp" => string(Dates.now()); force = true) | ||||
|
||||
|
@@ -178,6 +196,10 @@ function clear_algorithm_preferences() | |||
Preferences.delete_preferences!(LinearSolve, "autotune_timestamp"; force = true) | ||||
end | ||||
|
||||
# Clear MKL preference | ||||
Preferences.delete_preferences!(LinearSolve, "LoadMKL_JLL"; force = true) | ||||
@info "Cleared MKL preference" | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||
@info "Preferences cleared from LinearSolve.jl." | ||||
end | ||||
|
||||
|
@@ -214,6 +236,12 @@ function show_current_preferences() | |||
end | ||||
end | ||||
|
||||
# Show MKL preference | ||||
mkl_pref = Preferences.load_preference(LinearSolve, "LoadMKL_JLL", nothing) | ||||
if mkl_pref !== nothing | ||||
println("\nMKL Usage: $(mkl_pref ? "Enabled" : "Disabled")") | ||||
end | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||
timestamp = Preferences.load_preference(LinearSolve, "autotune_timestamp", "unknown") | ||||
println("\nLast updated: $timestamp") | ||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using LinearSolveAutotune | ||
using LinearSolve | ||
using Test | ||
|
||
@testset "MKL Preference Management" begin | ||
# Test that MKL preference is set before loading LinearSolve | ||
# This has already happened in LinearSolveAutotune.jl module initialization | ||
|
||
# Create some mock categories to test preference setting | ||
categories_with_mkl = Dict{String, String}( | ||
"Float64_tiny (5-20)" => "MKLLUFactorization", | ||
"Float64_small (20-100)" => "RFLUFactorization", | ||
"Float64_medium (100-300)" => "MKLLUFactorization", | ||
"Float32_tiny (5-20)" => "LUFactorization" | ||
) | ||
|
||
categories_without_mkl = Dict{String, String}( | ||
"Float64_tiny (5-20)" => "RFLUFactorization", | ||
"Float64_small (20-100)" => "RFLUFactorization", | ||
"Float64_medium (100-300)" => "LUFactorization", | ||
"Float32_tiny (5-20)" => "SimpleLUFactorization" | ||
) | ||
|
||
# Test setting preferences with MKL as best | ||
@info "Testing preference setting with MKL as best algorithm..." | ||
LinearSolveAutotune.set_algorithm_preferences(categories_with_mkl) | ||
|
||
# The MKL preference should be set to true | ||
# Note: We can't directly test the preference value without restarting Julia | ||
# but we can verify the function runs without error | ||
|
||
@info "Testing preference setting without MKL as best algorithm..." | ||
LinearSolveAutotune.set_algorithm_preferences(categories_without_mkl) | ||
|
||
# Clear preferences | ||
@info "Testing preference clearing..." | ||
LinearSolveAutotune.clear_algorithm_preferences() | ||
|
||
# Show current preferences | ||
@info "Testing preference display..." | ||
LinearSolveAutotune.show_current_preferences() | ||
|
||
@test true # If we got here without errors, the test passes | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[JuliaFormatter] reported by reviewdog 🐶