Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/torch7.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonid Vlasenkov <leo.vlasenkov@gmail.com>2017-06-21 23:25:12 +0300
committerSoumith Chintala <soumith@gmail.com>2017-07-10 17:29:26 +0300
commit01bcef96bd8d3b77004ca9b6f2718e8f223e8600 (patch)
treec3e2c41f5321b595053d60b474d5a7bbba008992
parent11321f7bf65573849be90650bb376f05dfd79c60 (diff)
Fix sdot_ bug for runtime F2C symbol conflicts by using cblas where available
-rw-r--r--lib/TH/THGeneral.h.in1
-rw-r--r--lib/TH/cmake/FindBLAS.cmake16
-rw-r--r--lib/TH/generic/THBlas.c11
3 files changed, 28 insertions, 0 deletions
diff --git a/lib/TH/THGeneral.h.in b/lib/TH/THGeneral.h.in
index 88a3934..0e1cb5d 100644
--- a/lib/TH/THGeneral.h.in
+++ b/lib/TH/THGeneral.h.in
@@ -14,6 +14,7 @@
#cmakedefine USE_BLAS
#cmakedefine USE_LAPACK
#cmakedefine BLAS_F2C
+#cmakedefine BLAS_USE_CBLAS_DOT
#ifdef __cplusplus
# define TH_EXTERNC extern "C"
diff --git a/lib/TH/cmake/FindBLAS.cmake b/lib/TH/cmake/FindBLAS.cmake
index 2188fc7..a62cfad 100644
--- a/lib/TH/cmake/FindBLAS.cmake
+++ b/lib/TH/cmake/FindBLAS.cmake
@@ -274,6 +274,22 @@ int main() {
ELSE (BLAS_F2C_DOUBLE_WORKS AND NOT BLAS_F2C_FLOAT_WORKS)
SET(BLAS_F2C FALSE)
ENDIF (BLAS_F2C_DOUBLE_WORKS AND NOT BLAS_F2C_FLOAT_WORKS)
+ CHECK_C_SOURCE_RUNS("
+#include <stdlib.h>
+#include <stdio.h>
+float x[4] = { 1, 2, 3, 4 };
+float y[4] = { .1, .01, .001, .0001 };
+extern float cblas_sdot();
+int main() {
+ int i;
+ double r = cblas_sdot(4, x, 1, y, 1);
+ exit((float)r != (float).1234);
+}" BLAS_USE_CBLAS_DOT )
+ IF (BLAS_USE_CBLAS_DOT)
+ SET(BLAS_USE_CBLAS_DOT TRUE)
+ ELSE (BLAS_USE_CBLAS_DOT)
+ SET(BLAS_USE_CBLAS_DOT FALSE)
+ ENDIF (BLAS_USE_CBLAS_DOT)
ENDIF(BLAS_LIBRARIES)
# epilogue
diff --git a/lib/TH/generic/THBlas.c b/lib/TH/generic/THBlas.c
index b04931f..bcd2a65 100644
--- a/lib/TH/generic/THBlas.c
+++ b/lib/TH/generic/THBlas.c
@@ -18,7 +18,18 @@ TH_EXTERNC void scopy_(int *n, float *x, int *incx, float *y, int *incy);
TH_EXTERNC void daxpy_(int *n, double *a, double *x, int *incx, double *y, int *incy);
TH_EXTERNC void saxpy_(int *n, float *a, float *x, int *incx, float *y, int *incy);
TH_EXTERNC double ddot_(int *n, double *x, int *incx, double *y, int *incy);
+#ifdef BLAS_USE_CBLAS_DOT
+TH_EXTERNC float cblas_sdot(const int n, const float *x, const int incx, const float *y, const int incy);
+#ifndef THBlas_C_sdot_
+#define THBlas_C_sdot_
+inline ffloat sdot_(const int *n, const float *x, const int *incx, const float *y, const int *incy)
+{
+ return cblas_sdot(*n, x, *incx, y, *incy);
+}
+#endif
+#else
TH_EXTERNC ffloat sdot_(int *n, float *x, int *incx, float *y, int *incy);
+#endif
TH_EXTERNC void dgemv_(char *trans, int *m, int *n, double *alpha, double *a, int *lda, double *x, int *incx, double *beta, double *y, int *incy);
TH_EXTERNC void sgemv_(char *trans, int *m, int *n, float *alpha, float *a, int *lda, float *x, int *incx, float *beta, float *y, int *incy);
TH_EXTERNC void dger_(int *m, int *n, double *alpha, double *x, int *incx, double *y, int *incy, double *a, int *lda);