From: Jianzhong Xu Date: Fri, 13 Feb 2015 17:52:40 +0000 (-0500) Subject: Added linalg examples. X-Git-Tag: 0.0.1.0~5 X-Git-Url: https://git.ti.com/gitweb?p=dense-linear-algebra-libraries%2Flinalg.git;a=commitdiff_plain;h=0ed9be8ce6173f944b1fdccfc51d7a2609e1a814 Added linalg examples. --- diff --git a/Makefile b/Makefile index 5276198..2a56b29 100644 --- a/Makefile +++ b/Makefile @@ -41,5 +41,4 @@ install: install -m 755 -d ${DESTDIR}/usr/share/ti/examples/linalg cp $(LINALG_BLISACC_DIR)/lib/libcblas_armplusdsp.a ${DESTDIR}/usr/lib cp $(LINALG_BLIS_DIR)/install/arm/lib/libblis-*-cortex-a15.a ${DESTDIR}/usr/lib/libblis.a - - \ No newline at end of file + cp ./examples ${DESTDIR}/usr/share/ti/examples/linalg diff --git a/build/tar_files_list.txt b/build/tar_files_list.txt index 3325a81..1c8bc42 100644 --- a/build/tar_files_list.txt +++ b/build/tar_files_list.txt @@ -1,6 +1,7 @@ make.inc Makefile debian +examples blis/build blis/CHANGELOG blis/config diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..7152704 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,28 @@ +.SILENT: + +MFS = $(wildcard */Makefile) +DIRS = $(patsubst %/Makefile,%,$(MFS)) + +all: + for dir in $(DIRS); do \ + echo "=============== " $$dir " =================" ; \ + $(MAKE) -C $$dir; \ + done + +test: + for dir in $(DIRS); do \ + echo "=============== " $$dir " =================" ; \ + $(MAKE) -C $$dir test; \ + done + +cross: + for dir in $(DIRS); do \ + echo "=============== " $$dir " =================" ; \ + $(MAKE) -C $$dir cross; \ + done + +clean: + for dir in $(DIRS); do \ + $(MAKE) -C $$dir clean; \ + done + diff --git a/examples/make.inc b/examples/make.inc new file mode 100644 index 0000000..0125a07 --- /dev/null +++ b/examples/make.inc @@ -0,0 +1,24 @@ + + +CC = gcc +CFLAGS = -g -O2 -I/usr/include + +BLAS_LIB_DIR = /usr/lib/ +BLASLIB = $(BLAS_LIB_DIR)libcblas_armplusdsp.a $(BLAS_LIB_DIR)libblis.a -lOpenCL -locl_util -lstdc++ -lrt -lm -lgomp + + +%.o: %.c + @$(CC) -c $(CFLAGS) $< + @echo Compiling $< + +$(EXE): + +cross: $(EXE) + +clean:: + @rm -f $(EXE) *.o *.obj *.out *.asm *.if *.opt *.bc *.objc *.map *.bin *.dsp_h + +test: clean $(EXE) + @echo Running $(EXE) + @./$(EXE) >> /dev/null + @if [ $$? -ne 0 ] ; then echo "FAILED !!!" ; fi diff --git a/examples/matmpy/Makefile b/examples/matmpy/Makefile new file mode 100644 index 0000000..46f74fb --- /dev/null +++ b/examples/matmpy/Makefile @@ -0,0 +1,8 @@ + +EXE = matmpy + +include ../make.inc + +$(EXE): main.o + $(CC) $(CFLAGS) main.o $(BLASLIB) -o $@ + diff --git a/examples/matmpy/main.c b/examples/matmpy/main.c new file mode 100644 index 0000000..4298c08 --- /dev/null +++ b/examples/matmpy/main.c @@ -0,0 +1,102 @@ +#include +#include +#include +#include + +#include "cblas.h" + +/* Number of elements in matrix to display */ + +/* For profiling */ +#define tick() clock_gettime(CLOCK_MONOTONIC, &t0); +#define tock() (clock_gettime(CLOCK_MONOTONIC, &t1), \ + t1.tv_sec - t0.tv_sec + (t1.tv_nsec - t0.tv_nsec) / 1e9) +#define fout stdout + + +double *A, *B, *C; +int m, n, k; +double alpha, beta; +struct timespec t0, t1; +double secs = 0.0; + +static void report_flops(double secs, int m, int n, int k, int N) +{ + fprintf(fout,"Total time for %d tests: %8.6fs, %5.3f Mflops\n", + N, secs, (float)N*m*n*(2*k-1) / (secs * 1e6)); +} + +double matrix_mult(void) { + int i,j; + for (i = 0; i < (m*k); i++) { + A[i] = (double)rand()/RAND_MAX; + } + + for (i = 0; i < (k*n); i++) { + B[i] = (double)rand()/RAND_MAX; + } + + for (i = 0; i < (m*n); i++) { + C[i] = 0.0; + } + + tick(); + cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha, A, k, B, n, beta, C, n); + secs += tock(); + + /* We do a simplistic checksum across a subset of the result matrix */ + double checksum = 0.0; + for (i=0; i C(%ix%i)\n", m, k, k, n, m, n); + + printf("Warming caches (by doing a single matrix-multiply)..\n"); + checksum = matrix_mult(); + + /* reset secs, so we can now begin the real timing */ + secs = 0; + + printf("Now doing %d tests after warming caches\n", numtests); + for (t=0; t