Skip to content

Commit 006da93

Browse files
committed
Test Apple Accelerate loading and threading
1 parent ec3ec3a commit 006da93

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-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+
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

test/runtests.jl

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

256256
# Run our "direct" tests within Julia
257257
include("direct.jl")
258+
259+
# Run some Apple Accelerate tests, but only on Apple
260+
@static if Sys.isapple()
261+
include("accelerate.jl")
262+
end

0 commit comments

Comments
 (0)