Skip to content

Commit 6e84867

Browse files
committed
Test Apple Accelerate loading and threading
1 parent ec3ec3a commit 6e84867

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

test/accelerate.jl

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
# Only test this on Apple
31+
@static if Sys.isapple()
32+
@testset "Accelerate ILP64 loading" begin
33+
# ILP64 requires macOS 13.3+
34+
if get_macos_version() >= v"13.3"
35+
# Load the ILP64 interface
36+
lbt_forward(lbt_handle, libacc; clear=true, suffix_hint="\x1a\$NEWLAPACK\$ILP64")
37+
38+
# Test that we have only one library loaded
39+
config = lbt_get_config(lbt_handle)
40+
libs = unpack_loaded_libraries(config)
41+
@test length(libs) == 1
42+
43+
# Test that it's Accelerate and it's correctly identified
44+
@test libs[1].libname == libacc
45+
@test libs[1].interface == LBT_INTERFACE_ILP64
46+
47+
# Test that `dgemm` forwards to `dgemm_` within the Accelerate library
48+
acc_dgemm = dlsym(libacc, Symbol("dgemm\$NEWLAPACK\$ILP64"))
49+
@test lbt_get_forward(lbt_handle, "dgemm_", LBT_INTERFACE_ILP64) == acc_dgemm
50+
end
51+
end
52+
53+
@testset "Accelerate LP64 loading" begin
54+
# New LAPACK interface requires macOS 13.3+
55+
if get_macos_version() >= v"13.3"
56+
# Load the LP64 interface
57+
lbt_forward(lbt_handle, libacc; clear=true, suffix_hint="\x1a\$NEWLAPACK")
58+
59+
# Test that we have only one library loaded
60+
config = lbt_get_config(lbt_handle)
61+
libs = unpack_loaded_libraries(config)
62+
@test length(libs) == 1
63+
64+
# Test that it's Accelerate and it's correctly identified
65+
@test libs[1].libname == libacc
66+
@test libs[1].interface == LBT_INTERFACE_LP64
67+
68+
# Test that `dgemm` forwards to `dgemm_` within the Accelerate library
69+
acc_dgemm = dlsym(libacc, Symbol("dgemm\$NEWLAPACK"))
70+
@test lbt_get_forward(lbt_handle, "dgemm_", LBT_INTERFACE_LP64) == acc_dgemm
71+
end
72+
end
73+
74+
@testset "Accelerate threading" begin
75+
# This threading API will only work on v15 and above
76+
if get_macos_version() >= v"15"
77+
lbt_forward(lbt_handle, libacc; clear=true)
78+
79+
# Set to single-threaded
80+
lbt_set_num_threads(1)
81+
@test lbt_get_num_threads == 1
82+
83+
# Set to multi-threaded
84+
# Accelerate doesn't actually let us say how many threads, so we must test for greater than
85+
lbt_set_num_threads(2)
86+
@test lbt_get_num_threads() > 1
87+
88+
# Set back to single-threaded
89+
lbt_set_num_threads(1)
90+
@test lbt_get_num_threads() == 1
91+
end
92+
end
93+
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,6 @@ end
255255

256256
# Run our "direct" tests within Julia
257257
include("direct.jl")
258+
259+
# Run some AppleAccelerate tests
260+
include("accelerate.jl")

0 commit comments

Comments
 (0)