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