Skip to content

Commit

Permalink
Move to cdotc instead of zdotc to avoid Windows x64 confusion
Browse files Browse the repository at this point in the history
Our new `LBT_FORCE_RETSTYLE => ARGUMENT` doesn't work so well when it's
already `ARGUMENT` on Windows x64.
  • Loading branch information
staticfloat committed Jun 12, 2024
1 parent c006cad commit 98cab58
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
15 changes: 15 additions & 0 deletions test/cdotc_test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include ../../src/Make.inc

all: $(prefix)/cdotc_test$(EXE)

$(prefix):
@mkdir -p $@

$(prefix)/cdotc_test$(EXE): cdotc_test.c | $(prefix)
@$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS)

clean:
@rm -f $(prefix)/cdotc_test$(EXE)

run: $(prefix)/cdotc_test$(EXE)
@$(prefix)/cdotc_test$(EXE)
12 changes: 6 additions & 6 deletions test/zdotc_test/zdotc_test.c → test/cdotc_test/cdotc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ typedef int64_t blasint;
typedef int32_t blasint;
#endif

extern void MANGLE(cblas_zdotc_sub)(blasint, double complex *, blasint, double complex *, blasint, double complex *);
extern double complex MANGLE(zdotc_)(blasint *, double complex *, blasint *, double complex *, blasint *);
extern void MANGLE(cblas_cdotc_sub)(blasint, float complex *, blasint, float complex *, blasint, float complex *);
extern float complex MANGLE(cdotc_)(blasint *, float complex *, blasint *, float complex *, blasint *);

#define N 2
int main()
{
double complex A[N], B[N];
float complex A[N], B[N];

// Initialize `A` with known values (transposed into FORTRAN ordering)
A[0] = 3.1 + 1.4*I;
Expand All @@ -30,13 +30,13 @@ int main()
blasint len = N;
blasint inca = 1;
blasint incb = 1;
complex double C;
MANGLE(cblas_zdotc_sub)(len, &A[0], inca, &B[0], incb, &C);
complex float C;
MANGLE(cblas_cdotc_sub)(len, &A[0], inca, &B[0], incb, &C);

// Print out C
printf("C (cblas) is: (%8.4f, %8.4f)\n", creal(C), cimag(C));

// Do the same thing, but with the FORTRAN interface
C = MANGLE(zdotc_)(&len, &A[0], &inca, &B[0], &incb);
C = MANGLE(cdotc_)(&len, &A[0], &inca, &B[0], &incb);
printf("C (fortran) is: (%8.4f, %8.4f)\n", creal(C), cimag(C));
}
22 changes: 13 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ dpstrf = ("dpstrf_test", ("diag(A): 2.2601 1.8067 1.6970 0.4121",
sgesv = ("sgesv_test", ("||b||^2 is: 3.0000",), true)
sgesv_failure = ("sgesv_test", ("Error: no BLAS/LAPACK library loaded!",), false)
sdot = ("sdot_test", ("C is: 1.9900",), true)
zdotc = ("zdotc_test", (
cdotc = ("cdotc_test", (
"C (cblas) is: ( 1.4700, 3.8300)",
"C (fortran) is: ( 1.4700, 3.8300)",
), true)

# Helper function to run all the tests with the given arguments
# Does not include `dgemmt` because that's MKL-only
function run_all_tests(args...; tests = [dgemm, dpstrf, sgesv, sdot, zdotc])
function run_all_tests(args...; tests = [dgemm, dpstrf, sgesv, sdot, cdotc])
for test in tests
run_test(test, args...)
end
Expand Down Expand Up @@ -133,10 +133,14 @@ lbt_dir = joinpath(lbt_dir, binlib)
run_all_tests(blastrampoline_link_name(), libdirs, openblas_interface, OpenBLAS_jll.libopenblas_path)

# Test that setting bad `LBT_FORCE_*` values actually breaks things
# This can be somewhat unpredictable (segfaulting sometimes, returning zero other times)
# so it's hard to test on CI, so we comment it out for now.
#=
withenv("LBT_FORCE_RETSTYLE" => "ARGUMENT") do
zdotc_fail = ("zdotc_test", [], false)
run_test(zdotc_fail, blastrampoline_link_name(), libdirs, openblas_interface, OpenBLAS_jll.libopenblas_path)
cdotc_fail = ("cdotc_test", cdotc[2], false)
run_test(cdotc_fail, blastrampoline_link_name(), libdirs, openblas_interface, OpenBLAS_jll.libopenblas_path)
end
=#
end

# And again, but this time with OpenBLAS32_jll
Expand All @@ -156,15 +160,15 @@ end
if MKL_jll.is_available()
@testset "LBT -> MKL_jll (LP64)" begin
libdirs = unique(vcat(lbt_dir, MKL_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
run_all_tests(blastrampoline_link_name(), libdirs, :LP64, MKL_jll.libmkl_rt_path; tests = [dgemm, dgemmt, dpstrf, sgesv, sdot, zdotc])
run_all_tests(blastrampoline_link_name(), libdirs, :LP64, MKL_jll.libmkl_rt_path; tests = [dgemm, dgemmt, dpstrf, sgesv, sdot, cdotc])
end

# Test that we can set MKL's interface via an environment variable to select ILP64, and LBT detects it properly
if Sys.WORD_SIZE == 64
@testset "LBT -> MKL_jll (ILP64, via env)" begin
withenv("MKL_INTERFACE_LAYER" => "ILP64") do
libdirs = unique(vcat(lbt_dir, MKL_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
run_all_tests(blastrampoline_link_name(), libdirs, :ILP64, MKL_jll.libmkl_rt_path; tests = [dgemm, dgemmt, dpstrf, sgesv, sdot, zdotc])
run_all_tests(blastrampoline_link_name(), libdirs, :ILP64, MKL_jll.libmkl_rt_path; tests = [dgemm, dgemmt, dpstrf, sgesv, sdot, cdotc])
end
end
end
Expand All @@ -177,7 +181,7 @@ veclib_blas_path = "/System/Library/Frameworks/Accelerate.framework/Versions/A/F
if dlopen_e(veclib_blas_path) != C_NULL
# Test that we can run BLAS-only tests without LAPACK loaded (`sgesv` test requires LAPACK symbols)
@testset "LBT -> vecLib/libBLAS" begin
run_all_tests(blastrampoline_link_name(), [lbt_dir], :LP64, veclib_blas_path; tests=[dgemm, sdot, zdotc])
run_all_tests(blastrampoline_link_name(), [lbt_dir], :LP64, veclib_blas_path; tests=[dgemm, sdot, cdotc])
end

# With LAPACK as well, run all tests except `dgemmt`
Expand All @@ -190,14 +194,14 @@ if dlopen_e(veclib_blas_path) != C_NULL
if dlsym_e(veclib_lapack_handle, "dpotrf\$NEWLAPACK\$ILP64") != C_NULL
@testset "LBT -> vecLib/libBLAS (ILP64)" begin
veclib_blas_path_ilp64 = "$(veclib_blas_path)!\x1a\$NEWLAPACK\$ILP64"
run_all_tests(blastrampoline_link_name(), [lbt_dir], :ILP64, veclib_blas_path_ilp64; tests=[dgemm, sdot, zdotc])
run_all_tests(blastrampoline_link_name(), [lbt_dir], :ILP64, veclib_blas_path_ilp64; tests=[dgemm, sdot, cdotc])
end

@testset "LBT -> vecLib/libLAPACK (ILP64)" begin
veclib_lapack_path_ilp64 = "$(veclib_lapack_path)!\x1a\$NEWLAPACK\$ILP64"
@warn("dpstrf test broken on new LAPACK in Accelerate")
dpstrf_broken = (dpstrf[1], "diag(A): 2.2601 1.7140 0.6206 1.1878", true)
run_all_tests(blastrampoline_link_name(), [lbt_dir], :ILP64, veclib_lapack_path_ilp64; tests=[dgemm, dpstrf_broken, sgesv, sdot, zdotc])
run_all_tests(blastrampoline_link_name(), [lbt_dir], :ILP64, veclib_lapack_path_ilp64; tests=[dgemm, dpstrf_broken, sgesv, sdot, cdotc])
end
end
end
Expand Down
15 changes: 0 additions & 15 deletions test/zdotc_test/Makefile

This file was deleted.

0 comments on commit 98cab58

Please sign in to comment.