author | Jianzhong Xu <a0869574@ti.com> | |
Fri, 13 Feb 2015 17:55:30 +0000 (12:55 -0500) | ||
committer | Jianzhong Xu <a0869574@ti.com> | |
Fri, 13 Feb 2015 17:55:30 +0000 (12:55 -0500) |
Makefile | patch | blob | history | |
build/tar_files_list.txt | patch | blob | history | |
examples/Makefile | [new file with mode: 0644] | patch | blob |
examples/make.inc | [new file with mode: 0644] | patch | blob |
examples/matmpy/Makefile | [new file with mode: 0644] | patch | blob |
examples/matmpy/main.c | [new file with mode: 0644] | patch | blob |
diff --git a/Makefile b/Makefile
index 76503d78ec1bbd6ccbf3b77469d97894621a221f..363c44d4ccef0a821035545c131a450500b730ea 100644 (file)
--- a/Makefile
+++ b/Makefile
cp $(LINALG_CBLAS_DIR)/include/cblas.h ${DESTDIR}/usr/include
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
index 8cb3afdcd32f150e9cc58d691e8f0b5d8715cd56..588088c19a632493efd978f6b5fe1688f3e823be 100644 (file)
--- a/build/tar_files_list.txt
+++ b/build/tar_files_list.txt
make.inc
Makefile
debian
+examples
blis/build
blis/CHANGELOG
blis/config
diff --git a/examples/Makefile b/examples/Makefile
--- /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
--- /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
--- /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
--- /dev/null
+++ b/examples/matmpy/main.c
@@ -0,0 +1,102 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+
+#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<m; i++)
+ for (j=0; j<n; j++)
+ checksum += C[j+i*n];
+ return checksum;
+}
+
+int main()
+{
+ int t;
+ double checksum;
+ int numtests = 10;
+
+ /* configuration */
+ m = k = n = 1000;
+ alpha = 0.7;
+ beta = 1.3;
+
+ /* allocate the matrices */
+ A = (double *)malloc( m*k*sizeof( double ) );
+ B = (double *)malloc( k*n*sizeof( double ) );
+ C = (double *)malloc( m*n*sizeof( double ) );
+ if (A == NULL || B == NULL || C == NULL) {
+ printf( "\nERROR: Can't allocate memory for matrices. Aborting... \n\n");
+ free(A);
+ free(B);
+ free(C);
+ return 1;
+ }
+
+ srand(123456789);
+
+ printf ("A(%ix%i) X B(%ix%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<numtests; t++)
+ checksum += matrix_mult();
+ report_flops(secs, m, n, k, numtests);
+
+ printf("Result CHECKSUM: %16.4f\n", checksum);
+
+ free(A);
+ free(B);
+ free(C);
+
+ return 0;
+}
+
+