Skip to content

Commit 85eb21e

Browse files
committed
Add dpstrf_ test
This isolates a known LAPACK failure on the new Accelerate; use it to track the issue as Apple hopefully fixes it.
1 parent b6b0456 commit 85eb21e

File tree

3 files changed

+88
-14
lines changed

3 files changed

+88
-14
lines changed

test/dpstrf_test/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
include ../../src/Make.inc
2+
3+
all: $(prefix)/dpstrf_test$(EXE)
4+
5+
$(prefix):
6+
@mkdir -p $@
7+
8+
$(prefix)/dpstrf_test$(EXE): dpstrf_test.c | $(prefix)
9+
@$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS)
10+
11+
clean:
12+
@rm -f $(prefix)/dpstrf_test$(EXE)
13+
14+
run: $(prefix)/dpstrf_test$(EXE)
15+
@$(prefix)/dpstrf_test$(EXE)

test/dpstrf_test/dpstrf_test.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
4+
#ifdef ILP64
5+
#define MANGLE(x) x##64_
6+
typedef int64_t blasint;
7+
#else
8+
#define MANGLE(x) x
9+
typedef int32_t blasint;
10+
#endif
11+
12+
extern blasint MANGLE(dpstrf_)(char *, blasint *, double *, blasint *, blasint *, blasint *, double *, double*, blasint *);
13+
14+
#define N 4
15+
int main()
16+
{
17+
blasint pivot[N];
18+
blasint info;
19+
double A[N][N];
20+
double work[2*N];
21+
blasint order = N;
22+
blasint rank = 0;
23+
blasint lda = N;
24+
blasint stride = 1;
25+
double tol = 0.0;
26+
27+
28+
// Initialize `A` with known values (transposed into FORTRAN ordering)
29+
A[0][0] = 3.4291134; A[1][0] = -0.61112815; A[2][0] = 0.8155207; A[3][0] = -0.9183448;
30+
A[0][1] = -0.61112815; A[1][1] = 3.1250076; A[2][1] = -0.44400603; A[3][1] = 0.97749346;
31+
A[0][2] = 0.8155207; A[1][2] = -0.44400603; A[2][2] = 0.5413656; A[3][2] = 0.53000593;
32+
A[0][3] = -0.9183448; A[1][3] = 0.97749346; A[2][3] = 0.53000593; A[3][3] = 5.108155;
33+
34+
// find solution using LAPACK routine dpstrf, all the arguments have to
35+
// be pointers and you have to add an underscore to the routine name
36+
37+
// parameters in the order as they appear in the function call
38+
// order of matrix A, number of right hand sides (b), matrix A,
39+
// leading dimension of A, array that records pivoting,
40+
// result vector b on entry, x on exit, leading dimension of b
41+
// return value
42+
MANGLE(dpstrf_)("U", &order, &A[0][0], &lda, &pivot[0], &rank, &tol, &work[0], &info);
43+
if (info != 0) {
44+
printf("ERROR: info == %ld!\n", info);
45+
return 1;
46+
}
47+
48+
// Print out diagonal of A
49+
printf("diag(A):");
50+
for (blasint j=0; j<N; j++) {
51+
printf(" %8.4f", A[j][j]);
52+
}
53+
printf("\n");
54+
return 0;
55+
}

test/runtests.jl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,20 @@ function run_test((test_name, test_expected_outputs, expect_success), libblas_na
8888
end
8989

9090
# our tests, written in C, defined in subdirectories in `test/`
91-
dgemm = ("dgemm_test", ("||C||^2 is: 24.3384",), true)
92-
dgemmt = ("dgemmt_test", ("||C||^2 is: 23.2952",), true)
93-
sgesv = ("sgesv_test", ("||b||^2 is: 3.0000",), true)
94-
sgesv_failure = ("sgesv_test", ("Error: no BLAS/LAPACK library loaded!",), false)
95-
sdot = ("sdot_test", ("C is: 1.9900",), true)
91+
dgemm = ("dgemm_test", ("||C||^2 is: 24.3384",), true)
92+
dgemmt = ("dgemmt_test", ("||C||^2 is: 23.2952",), true)
93+
dpstrf = ("dpstrf_test", ("diag(A): 2.2601 1.8067 1.6970 0.4121",), true)
94+
sgesv = ("sgesv_test", ("||b||^2 is: 3.0000",), true)
95+
sgesv_failure = ("sgesv_test", ("Error: no BLAS/LAPACK library loaded!",), false)
96+
sdot = ("sdot_test", ("C is: 1.9900",), true)
9697
zdotc = ("zdotc_test", (
9798
"C (cblas) is: ( 1.4700, 3.8300)",
9899
"C (fortran) is: ( 1.4700, 3.8300)",
99100
), true)
100101

101102
# Helper function to run all the tests with the given arguments
102-
function run_all_tests(args...; tests = [dgemm, dgemmt, sgesv, sdot, zdotc])
103+
# Does not include `dgemmt` because that's MKL-only
104+
function run_all_tests(args...; tests = [dgemm, dpstrf, sgesv, sdot, zdotc])
103105
for test in tests
104106
run_test(test, args...)
105107
end
@@ -112,13 +114,13 @@ if Sys.WORD_SIZE == 64
112114
end
113115
openblas_jll_libname = splitext(basename(OpenBLAS_jll.libopenblas_path)[4:end])[1]
114116
@testset "Vanilla OpenBLAS_jll ($(openblas_interface))" begin
115-
run_all_tests(openblas_jll_libname, OpenBLAS_jll.LIBPATH_list, openblas_interface, "", tests=[dgemm, sgesv, sdot, zdotc])
117+
run_all_tests(openblas_jll_libname, OpenBLAS_jll.LIBPATH_list, openblas_interface, "")
116118
end
117119

118120
# Build version that links against vanilla OpenBLAS32
119121
@testset "Vanilla OpenBLAS32_jll (LP64)" begin
120122
# Reverse OpenBLAS32_jll's LIBPATH_list so that we get the right openblas.so
121-
run_all_tests("openblas", reverse(OpenBLAS32_jll.LIBPATH_list), :LP64, "", tests=[dgemm, sgesv, sdot, zdotc])
123+
run_all_tests("openblas", reverse(OpenBLAS32_jll.LIBPATH_list), :LP64, "")
122124
end
123125

124126
# Next, build a version that links against `libblastrampoline`, and tell
@@ -128,28 +130,28 @@ lbt_dir = joinpath(lbt_dir, binlib)
128130

129131
@testset "LBT -> OpenBLAS_jll ($(openblas_interface))" begin
130132
libdirs = unique(vcat(lbt_dir, OpenBLAS_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
131-
run_all_tests(blastrampoline_link_name(), libdirs, openblas_interface, OpenBLAS_jll.libopenblas_path, tests=[dgemm, sgesv, sdot, zdotc])
133+
run_all_tests(blastrampoline_link_name(), libdirs, openblas_interface, OpenBLAS_jll.libopenblas_path)
132134
end
133135

134136
# And again, but this time with OpenBLAS32_jll
135137
@testset "LBT -> OpenBLAS32_jll (LP64)" begin
136138
libdirs = unique(vcat(lbt_dir, OpenBLAS32_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
137-
run_all_tests(blastrampoline_link_name(), libdirs, :LP64, OpenBLAS32_jll.libopenblas_path, tests=[dgemm, sgesv, sdot, zdotc])
139+
run_all_tests(blastrampoline_link_name(), libdirs, :LP64, OpenBLAS32_jll.libopenblas_path)
138140
end
139141

140142
# Test against MKL_jll using `libmkl_rt`, which is :LP64 by default
141143
if MKL_jll.is_available()
142144
@testset "LBT -> MKL_jll (LP64)" begin
143145
libdirs = unique(vcat(lbt_dir, MKL_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
144-
run_all_tests(blastrampoline_link_name(), libdirs, :LP64, MKL_jll.libmkl_rt_path)
146+
run_all_tests(blastrampoline_link_name(), libdirs, :LP64, MKL_jll.libmkl_rt_path; tests = [dgemm, dgemmt, dpstrf, sgesv, sdot, zdotc])
145147
end
146148

147149
# Test that we can set MKL's interface via an environment variable to select ILP64, and LBT detects it properly
148150
if Sys.WORD_SIZE == 64
149151
@testset "LBT -> MKL_jll (ILP64, via env)" begin
150152
withenv("MKL_INTERFACE_LAYER" => "ILP64") do
151153
libdirs = unique(vcat(lbt_dir, MKL_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
152-
run_all_tests(blastrampoline_link_name(), libdirs, :ILP64, MKL_jll.libmkl_rt_path)
154+
run_all_tests(blastrampoline_link_name(), libdirs, :ILP64, MKL_jll.libmkl_rt_path; tests = [dgemm, dgemmt, dpstrf, sgesv, sdot, zdotc])
153155
end
154156
end
155157
end
@@ -168,7 +170,7 @@ if dlopen_e(veclib_blas_path) != C_NULL
168170
# With LAPACK as well, run all tests except `dgemmt`
169171
veclib_lapack_path = "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/libLAPACK.dylib"
170172
@testset "LBT -> vecLib/libLAPACK" begin
171-
run_all_tests(blastrampoline_link_name(), [lbt_dir], :LP64, string(veclib_blas_path, ";", veclib_lapack_path), tests=[dgemm, sgesv, sdot, zdotc])
173+
run_all_tests(blastrampoline_link_name(), [lbt_dir], :LP64, string(veclib_blas_path, ";", veclib_lapack_path))
172174
end
173175

174176
veclib_lapack_handle = dlopen(veclib_lapack_path)
@@ -180,7 +182,9 @@ if dlopen_e(veclib_blas_path) != C_NULL
180182

181183
@testset "LBT -> vecLib/libLAPACK (ILP64)" begin
182184
veclib_lapack_path_ilp64 = "$(veclib_lapack_path)!\x1a\$NEWLAPACK\$ILP64"
183-
run_all_tests(blastrampoline_link_name(), [lbt_dir], :ILP64, veclib_lapack_path_ilp64; tests=[dgemm, sgesv, sdot, zdotc])
185+
@warn("dpstrf test broken on new LAPACK in Accelerate")
186+
dpstrf_broken = (dpstrf[1], "diag(A): 2.2601 1.7140 0.6206 1.1878", true)
187+
run_all_tests(blastrampoline_link_name(), [lbt_dir], :ILP64, veclib_lapack_path_ilp64; tests=[dgemm, dpstrf_broken, sgesv, sdot, zdotc])
184188
end
185189
end
186190
end

0 commit comments

Comments
 (0)