Skip to content

Commit ab3a9e1

Browse files
vlasenkovsoumith
authored andcommitted
Fix sdot_ bug for runtime F2C symbol conflicts by using cblas where available
1 parent 56df97c commit ab3a9e1

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

THGeneral.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#cmakedefine USE_BLAS
1515
#cmakedefine USE_LAPACK
1616
#cmakedefine BLAS_F2C
17+
#cmakedefine BLAS_USE_CBLAS_DOT
1718

1819
#ifdef __cplusplus
1920
# define TH_EXTERNC extern "C"

cmake/FindBLAS.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,22 @@ int main() {
274274
ELSE (BLAS_F2C_DOUBLE_WORKS AND NOT BLAS_F2C_FLOAT_WORKS)
275275
SET(BLAS_F2C FALSE)
276276
ENDIF (BLAS_F2C_DOUBLE_WORKS AND NOT BLAS_F2C_FLOAT_WORKS)
277+
CHECK_C_SOURCE_RUNS("
278+
#include <stdlib.h>
279+
#include <stdio.h>
280+
float x[4] = { 1, 2, 3, 4 };
281+
float y[4] = { .1, .01, .001, .0001 };
282+
extern float cblas_sdot();
283+
int main() {
284+
int i;
285+
double r = cblas_sdot(4, x, 1, y, 1);
286+
exit((float)r != (float).1234);
287+
}" BLAS_USE_CBLAS_DOT )
288+
IF (BLAS_USE_CBLAS_DOT)
289+
SET(BLAS_USE_CBLAS_DOT TRUE)
290+
ELSE (BLAS_USE_CBLAS_DOT)
291+
SET(BLAS_USE_CBLAS_DOT FALSE)
292+
ENDIF (BLAS_USE_CBLAS_DOT)
277293
ENDIF(BLAS_LIBRARIES)
278294

279295
# epilogue

generic/THBlas.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ TH_EXTERNC void scopy_(int *n, float *x, int *incx, float *y, int *incy);
1818
TH_EXTERNC void daxpy_(int *n, double *a, double *x, int *incx, double *y, int *incy);
1919
TH_EXTERNC void saxpy_(int *n, float *a, float *x, int *incx, float *y, int *incy);
2020
TH_EXTERNC double ddot_(int *n, double *x, int *incx, double *y, int *incy);
21+
#ifdef BLAS_USE_CBLAS_DOT
22+
TH_EXTERNC float cblas_sdot(const int n, const float *x, const int incx, const float *y, const int incy);
23+
#ifndef THBlas_C_sdot_
24+
#define THBlas_C_sdot_
25+
inline ffloat sdot_(const int *n, const float *x, const int *incx, const float *y, const int *incy)
26+
{
27+
return cblas_sdot(*n, x, *incx, y, *incy);
28+
}
29+
#endif
30+
#else
2131
TH_EXTERNC ffloat sdot_(int *n, float *x, int *incx, float *y, int *incy);
32+
#endif
2233
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);
2334
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);
2435
TH_EXTERNC void dger_(int *m, int *n, double *alpha, double *x, int *incx, double *y, int *incy, double *a, int *lda);

0 commit comments

Comments
 (0)