Skip to content

Commit

Permalink
Fix sdot_ bug for runtime F2C symbol conflicts by using cblas where a…
Browse files Browse the repository at this point in the history
…vailable
  • Loading branch information
vlasenkov authored and soumith committed Jul 10, 2017
1 parent 11321f7 commit 01bcef9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/TH/THGeneral.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions lib/TH/cmake/FindBLAS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/TH/generic/THBlas.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 01bcef9

Please sign in to comment.