|
| 1 | +using Libdl, Test |
| 2 | + |
| 3 | +# Taken from AppleAccelerate.jl to avoid a dependency on it |
| 4 | +const libacc = "/System/Library/Frameworks/Accelerate.framework/Accelerate" |
| 5 | +const libacc_info_plist = "/System/Library/Frameworks/Accelerate.framework/Versions/Current/Resources/Info.plist" |
| 6 | + |
| 7 | +function get_macos_version(normalize=true) |
| 8 | + @static if !Sys.isapple() |
| 9 | + return nothing |
| 10 | + end |
| 11 | + |
| 12 | + plist_lines = split(String(read("/System/Library/CoreServices/SystemVersion.plist")), "\n") |
| 13 | + vers_idx = findfirst(l -> occursin("ProductVersion", l), plist_lines) |
| 14 | + if vers_idx === nothing |
| 15 | + return nothing |
| 16 | + end |
| 17 | + |
| 18 | + m = match(r">([\d\.]+)<", plist_lines[vers_idx+1]) |
| 19 | + if m === nothing |
| 20 | + return nothing |
| 21 | + end |
| 22 | + |
| 23 | + ver = VersionNumber(only(m.captures)) |
| 24 | + if normalize && ver.major == 16 |
| 25 | + return VersionNumber(26, ver.minor, ver.patch) |
| 26 | + end |
| 27 | + return ver |
| 28 | +end |
| 29 | + |
| 30 | + |
| 31 | +# Load the Accelerate library |
| 32 | +libacc_handle = dlopen(libacc) |
| 33 | +@testset "Accelerate ILP64 loading" begin |
| 34 | + # ILP64 requires macOS 13.3+ |
| 35 | + if get_macos_version() >= v"13.3" |
| 36 | + # Load the ILP64 interface |
| 37 | + lbt_forward(lbt_handle, libacc; clear=true, suffix_hint="\x1a\$NEWLAPACK\$ILP64") |
| 38 | + |
| 39 | + # Test that we have only one library loaded |
| 40 | + config = lbt_get_config(lbt_handle) |
| 41 | + libs = unpack_loaded_libraries(config) |
| 42 | + @test length(libs) == 1 |
| 43 | + |
| 44 | + # Test that it's Accelerate and it's correctly identified |
| 45 | + @test libs[1].libname == libacc |
| 46 | + @test libs[1].interface == LBT_INTERFACE_ILP64 |
| 47 | + |
| 48 | + # Test that `dgemm` forwards to `dgemm_` within the Accelerate library |
| 49 | + acc_dgemm = dlsym(libacc_handle, "dgemm\$NEWLAPACK\$ILP64") |
| 50 | + @test lbt_get_forward(lbt_handle, "dgemm_", LBT_INTERFACE_ILP64) == acc_dgemm |
| 51 | + end |
| 52 | +end |
| 53 | + |
| 54 | +@testset "Accelerate LP64 loading" begin |
| 55 | + # New LAPACK interface requires macOS 13.3+ |
| 56 | + if get_macos_version() >= v"13.3" |
| 57 | + # Load the LP64 interface |
| 58 | + lbt_forward(lbt_handle, libacc; clear=true, suffix_hint="\x1a\$NEWLAPACK") |
| 59 | + |
| 60 | + # Test that we have only one library loaded |
| 61 | + config = lbt_get_config(lbt_handle) |
| 62 | + libs = unpack_loaded_libraries(config) |
| 63 | + @test length(libs) == 1 |
| 64 | + |
| 65 | + # Test that it's Accelerate and it's correctly identified |
| 66 | + @test libs[1].libname == libacc |
| 67 | + @test libs[1].interface == LBT_INTERFACE_LP64 |
| 68 | + |
| 69 | + # Test that `dgemm` forwards to `dgemm_` within the Accelerate library |
| 70 | + acc_dgemm = dlsym(libacc_handle, "dgemm\$NEWLAPACK") |
| 71 | + @test lbt_get_forward(lbt_handle, "dgemm_", LBT_INTERFACE_LP64) == acc_dgemm |
| 72 | + end |
| 73 | +end |
| 74 | + |
| 75 | +@testset "Accelerate threading" begin |
| 76 | + # This threading API will only work on v15 and above |
| 77 | + if get_macos_version() >= v"15" |
| 78 | + lbt_forward(lbt_handle, libacc; clear=true) |
| 79 | + |
| 80 | + # Set to single-threaded |
| 81 | + lbt_set_num_threads(lbt_handle, 1) |
| 82 | + @test lbt_get_num_threads(lbt_handle) == 1 |
| 83 | + |
| 84 | + # Set to multi-threaded |
| 85 | + # Accelerate doesn't actually let us say how many threads, so we must test for greater than |
| 86 | + lbt_set_num_threads(lbt_handle, 2) |
| 87 | + @test lbt_get_num_threads(lbt_handle) > 1 |
| 88 | + |
| 89 | + # Set back to single-threaded |
| 90 | + lbt_set_num_threads(lbt_handle, 1) |
| 91 | + @test lbt_get_num_threads(lbt_handle) == 1 |
| 92 | + end |
| 93 | +end |
0 commit comments