Skip to content

Commit 605495e

Browse files
amontoisonstaticfloat
authored andcommitted
Add dgemmt_folder
1 parent 5a6a9b0 commit 605495e

File tree

3 files changed

+98
-7
lines changed

3 files changed

+98
-7
lines changed

test/dgemmt_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)/dgemmt_test$(EXE)
4+
5+
$(prefix):
6+
@mkdir -p $@
7+
8+
$(prefix)/dgemmt_test$(EXE): dgemmt_test.c | $(prefix)
9+
@$(CC) -o $@ $(CFLAGS) $^ $(LDFLAGS)
10+
11+
clean:
12+
@rm -f $(prefix)/dgemmt_test$(EXE)
13+
14+
run: $(prefix)/dgemmt_test$(EXE)
15+
@$(prefix)/dgemmt_test$(EXE)

test/dgemmt_test/dgemmt_test.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
#define MATRIX_IDX(n, i, j) j*n + i
13+
#define MATRIX_ELEMENT(A, m, n, i, j) A[ MATRIX_IDX(m, i, j) ]
14+
extern void MANGLE(dgemmt_)(char *, char *, char *, blasint *, blasint *, double *, double *, blasint *, double *, blasint *, double *, double *, blasint *);
15+
16+
void init_matrix(double* A, int m, int n) {
17+
double element = 1.0;
18+
for (int j = 0; j < n; j++) {
19+
for (int i = 0; i < m; i++) {
20+
MATRIX_ELEMENT(A, m, n, i, j) = element;
21+
element *= 0.9;
22+
}
23+
}
24+
}
25+
26+
float frobnorm2(const double * A, int m, int n) {
27+
float norm = 0.0f;
28+
for (int i = 0; i < m; i++) {
29+
for (int j = 0; j < n; j++) {
30+
float elem = MATRIX_ELEMENT(A, m, n, i, j);
31+
norm += elem*elem;
32+
}
33+
}
34+
return norm;
35+
}
36+
37+
void print_matrix(const double* A, int m, int n) {
38+
for (int i = 0; i < m; i++) {
39+
for (int j = 0; j < n; j++) {
40+
printf("%8.4f", MATRIX_ELEMENT(A, m, n, i, j));
41+
}
42+
printf("\n");
43+
}
44+
}
45+
46+
int main(int argc, char** argv) {
47+
blasint n = 4;
48+
blasint k = 5;
49+
50+
double A[n * k];
51+
double B[k * n];
52+
double C[n * n];
53+
54+
init_matrix(A, n, k);
55+
init_matrix(B, k, n);
56+
57+
printf("Matrix A (%d x %d) is:\n", (int)n, (int)k);
58+
print_matrix(A, n, k);
59+
60+
printf("\nMatrix B (%d x %d) is:\n", (int)k, (int)n);
61+
print_matrix(B, k, n);
62+
63+
double alpha = 1.0, beta=0.0;
64+
char uploL = 'L';
65+
char uploU = 'U';
66+
char no = 'N';
67+
MANGLE(dgemmt_)(&uploL, &no, &no, &n, &k, &alpha, A, &n, B, &k, &beta, C, &n);
68+
MANGLE(dgemmt_)(&uploU, &no, &no, &n, &k, &alpha, A, &n, B, &k, &beta, C, &n);
69+
70+
printf("\nMatrix C (%d x %d) = AB is:\n", (int)n, (int)n);
71+
print_matrix(C, n, n);
72+
printf("\n||C||^2 is: %8.4f\n", frobnorm2(C, n, n));
73+
74+
return 0;
75+
}

test/runtests.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ end
8282

8383
# our tests, written in C, defined in subdirectories in `test/`
8484
dgemm = ("dgemm_test", ("||C||^2 is: 24.3384",), true)
85+
dgemmt = ("dgemmt_test", ("||C||^2 is: 24.3384",), true)
8586
sgesv = ("sgesv_test", ("||b||^2 is: 3.0000",), true)
8687
sgesv_failure = ("sgesv_test", ("Error: no BLAS/LAPACK library loaded!",), false)
8788
sdot = ("sdot_test", ("C is: 1.9900",), true)
@@ -91,7 +92,7 @@ zdotc = ("zdotc_test", (
9192
), true)
9293

9394
# Helper function to run all the tests with the given arguments
94-
function run_all_tests(args...; tests = [dgemm, sgesv, sdot, zdotc])
95+
function run_all_tests(args...; tests = [dgemm, dgemmt, sgesv, sdot, zdotc])
9596
for test in tests
9697
run_test(test, args...)
9798
end
@@ -104,13 +105,13 @@ if Sys.WORD_SIZE == 64
104105
end
105106
openblas_jll_libname = splitext(basename(OpenBLAS_jll.libopenblas_path)[4:end])[1]
106107
@testset "Vanilla OpenBLAS_jll ($(openblas_interface))" begin
107-
run_all_tests(openblas_jll_libname, OpenBLAS_jll.LIBPATH_list, openblas_interface, "")
108+
run_all_tests(openblas_jll_libname, OpenBLAS_jll.LIBPATH_list, openblas_interface, "", tests=[dgemm, sgesv, sdot, zdotc])
108109
end
109110

110111
# Build version that links against vanilla OpenBLAS32
111112
@testset "Vanilla OpenBLAS32_jll (LP64)" begin
112113
# Reverse OpenBLAS32_jll's LIBPATH_list so that we get the right openblas.so
113-
run_all_tests("openblas", reverse(OpenBLAS32_jll.LIBPATH_list), :LP64, "")
114+
run_all_tests("openblas", reverse(OpenBLAS32_jll.LIBPATH_list), :LP64, "", tests=[dgemm, sgesv, sdot, zdotc])
114115
end
115116

116117
# Next, build a version that links against `libblastrampoline`, and tell
@@ -120,13 +121,13 @@ lbt_dir = joinpath(lbt_dir, binlib)
120121

121122
@testset "LBT -> OpenBLAS_jll ($(openblas_interface))" begin
122123
libdirs = unique(vcat(lbt_dir, OpenBLAS_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
123-
run_all_tests("blastrampoline", libdirs, openblas_interface, OpenBLAS_jll.libopenblas_path)
124+
run_all_tests("blastrampoline", libdirs, openblas_interface, OpenBLAS_jll.libopenblas_path, tests=[dgemm, sgesv, sdot, zdotc])
124125
end
125126

126127
# And again, but this time with OpenBLAS32_jll
127128
@testset "LBT -> OpenBLAS32_jll (LP64)" begin
128129
libdirs = unique(vcat(lbt_dir, OpenBLAS32_jll.LIBPATH_list..., CompilerSupportLibraries_jll.LIBPATH_list...))
129-
run_all_tests("blastrampoline", libdirs, :LP64, OpenBLAS32_jll.libopenblas_path)
130+
run_all_tests("blastrampoline", libdirs, :LP64, OpenBLAS32_jll.libopenblas_path, tests=[dgemm, sgesv, sdot, zdotc])
130131
end
131132

132133
# Test against MKL_jll using `libmkl_rt`, which is :LP64 by default
@@ -157,10 +158,10 @@ if dlopen_e(veclib_blas_path) != C_NULL
157158
run_all_tests("blastrampoline", [lbt_dir], :LP64, veclib_blas_path; tests=[dgemm, sdot, zdotc])
158159
end
159160

160-
# With LAPACK as well, run all tests
161+
# With LAPACK as well, run all tests except `dgemmt`
161162
veclib_lapack_path = "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/libLAPACK.dylib"
162163
@testset "LBT -> vecLib/libLAPACK" begin
163-
run_all_tests("blastrampoline", [lbt_dir], :LP64, string(veclib_blas_path, ";", veclib_lapack_path))
164+
run_all_tests("blastrampoline", [lbt_dir], :LP64, string(veclib_blas_path, ";", veclib_lapack_path), tests=[dgemm, sgesv, sdot, zdotc])
164165
end
165166
end
166167

0 commit comments

Comments
 (0)