aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--redist/dclapack.h2
-rw-r--r--redist/test_dcl.c110
3 files changed, 57 insertions, 61 deletions
diff --git a/Makefile b/Makefile
index dfcb9f4..ceb452a 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,7 @@ all : lib data_recorder test calibrate calibrate_client simple_pose_test
CC?=gcc
CFLAGS:=-Iinclude/libsurvive -fPIC -g -O0 -Iredist -flto -DUSE_DOUBLE -std=gnu99 -rdynamic -llapacke -lcblas -lm
+CFLAGS_RELEASE:=-Iinclude/libsurvive -fPIC -msse2 -ftree-vectorize -O3 -Iredist -flto -DUSE_DOUBLE -std=gnu99 -rdynamic -llapacke -lcblas -lm
#LDFLAGS:=-L/usr/local/lib -lpthread -lusb-1.0 -lz -lm -flto -g
LDFLAGS:=-L/usr/local/lib -lpthread -lz -lm -flto -g
@@ -88,7 +89,10 @@ static_calibrate : calibrate.c redist/os_generic.c $(DRAWFUNCTIONS) $(LIBSURVIVE
sed -i 's/#/\/\/#/g' ./redist/dclhelpers_debuggable.c
-test_dcl: ./redist/test_dcl.c ./redist/dclhelpers_debuggable.c ./redist/dclhelpers.h ./redist/dclapack.h
+test_dcl: ./redist/test_dcl.c ./redist/dclhelpers.c ./redist/dclhelpers.h ./redist/dclapack.h redist/os_generic.c
+ $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS_RELEASE) -DFLT=double
+
+test_dcl_debug: ./redist/test_dcl.c ./redist/dclhelpers_debuggable.c ./redist/dclhelpers.h ./redist/dclapack.h redist/os_generic.c
$(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) -DFLT=double -fsanitize=address -fsanitize=undefined
test_minimal_cv: ./src/epnp/test_minimal_cv.c ./lib/libsurvive.so
diff --git a/redist/dclapack.h b/redist/dclapack.h
index d4634ac..e43a4f9 100644
--- a/redist/dclapack.h
+++ b/redist/dclapack.h
@@ -27,7 +27,7 @@
printf(#A "\n"); \
for (int _i = 0; _i < (m); _i++) { \
for (int _j = 0; _j < (n); _j++) { \
- printf("%4.3f\t", _(A, _i, _j)); \
+ printf("%4.3f ", _(A, _i, _j)); \
} \
printf("\n"); \
} \
diff --git a/redist/test_dcl.c b/redist/test_dcl.c
index 5435a3c..68a6129 100644
--- a/redist/test_dcl.c
+++ b/redist/test_dcl.c
@@ -1,13 +1,60 @@
//gcc -msse2 -O3 -ftree-vectorize test_dcl.c dclhelpers.c os_generic.c -DFLT=double -lpthread -lcblas && valgrind ./a.out
-
#include "dclhelpers.h"
+#include "os_generic.h"
#include <assert.h>
+#include <cblas.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
-#include "os_generic.h"
-#include <cblas.h>
+#include <stdlib.h>
+
+void compareToCblas() {
+ FLT em1[12][20];
+ FLT em2[20][20];
+ FLT emo[2][20][20] = {};
+ int x, y;
+
+ for (y = 0; y < 12; y++)
+ for (x = 0; x < 20; x++)
+ em1[y][x] = (rand() % 1000) / 1000.0;
+
+ for (y = 0; y < 20; y++)
+ for (x = 0; x < 20; x++)
+ em2[y][x] = (rand() % 1000) / 1000.0;
+
+ int m = 12;
+ int n = 20;
+ int k = 20;
+
+ dclPrint(DMS(em1), 12, 20);
+ dclPrint(DMS(em2), 20, 12);
+
+ double times[2];
+ for (int z = 0; z < 2; z++) {
+ double start = OGGetAbsoluteTime();
+ for (int i = 0; i < 100000; i++) {
+ dclZero(DMS(emo[z]), 20, 20);
+
+ if (z == 0) {
+ dcldgemm(0, 0, m, n, k, 1.0, DMS(em1), DMS(em2), .1, DMS(emo[z]));
+ } else {
+ cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, k, 1.0, DMS(em1), DMS(em2), .1,
+ DMS(emo[z]));
+ }
+ /*void cblas_dgemm(CBLAS_LAYOUT layout, CBLAS_TRANSPOSE TransA,
+ CBLAS_TRANSPOSE TransB, const int M, const int N,
+ const int K, const double alpha, const double *A,
+ const int lda, const double *B, const int ldb,
+ const double beta, double *C, const int ldc);*/
+ }
+
+ printf("%s Elapsed: %f\n", z ? "CBlas" : "dcl", times[z] = OGGetAbsoluteTime() - start);
+ }
+ printf("%fx difference\n", times[0] / times[1]);
+ dclPrint(emo[0][0], 12, 20, 12);
+ dclPrint(emo[1][0], 12, 20, 12);
+}
int main()
{
@@ -65,61 +112,6 @@ int main()
}
}
-
-#if 1
-
- //Currently failing test...
- {
-// FLT em1[3][4];
-// FLT em2[4][2];
-// FLT emo[4][2];
-
- FLT em1[12][20];
- FLT em2[20][20];
- FLT emo[20][20];
- int x, y;
-
- for( y = 0; y < 12; y++ )
- for( x = 0; x < 20; x++ )
- em1[y][x] = (rand()%1000)/1000.0;
-
- for( y = 0; y < 20; y++ )
- for( x = 0; x < 20; x++ )
- em2[y][x] = (rand()%1000)/1000.0;
-
- for( y = 0; y < 20; y++ )
- for( x = 0; x < 20; x++ )
- emo[y][x] = 0;
-
- int m = 12;
- int n = 20;
- int k = 12;
-
- dclPrint( DMS(em1), 12, 20 );
- dclPrint( DMS(em2), 20, 12 );
-
- int i;
-
- double start = OGGetAbsoluteTime();
- for( i = 0; i < 10000; i++ )
- {
- dclZero( DMS(emo), 20, 20 );
-
- dcldgemm( 0, 0, m, n, k, 1.0, DMS(em1), DMS(em2), .1, DMS(emo) );
- //cblas_dgemm( CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, 1.0, DMS(em1), DMS(em2), .1, DMS(emo) );
-
-/*void cblas_dgemm(CBLAS_LAYOUT layout, CBLAS_TRANSPOSE TransA,
- CBLAS_TRANSPOSE TransB, const int M, const int N,
- const int K, const double alpha, const double *A,
- const int lda, const double *B, const int ldb,
- const double beta, double *C, const int ldc);*/
-
- }
- printf( "Elapsed: %f\n", OGGetAbsoluteTime()-start );
-
- dclPrint( emo[0], 12, 20, 12 );
- }
-#endif
-
+ compareToCblas();
}