-
Notifications
You must be signed in to change notification settings - Fork 0
Description
We need provide an API for differentiated CBLAS routines.
One approach is to differentiate through the CBLAS routines themselves using Tapenade in a multi-language setting.
The other approach is to to simply create a thin C layer that calls the fortran code.
For example in cblas_dgemm.c we have a call
F77_dgemm(F77_TA, F77_TB, &F77_N, &F77_M, &F77_K, &alpha, B,
&F77_ldb, A, &F77_lda, &beta, C, &F77_ldc);
Where 77_TA, F77_TB are character arrays of length 1.
This call gets preprocessed to:
dgemm_(&TA, &TB, &F77_N, &F77_M, &F77_K, &alpha, B, &F77_ldb, A, &F77_lda, &beta, C, &F77_ldc, 1, 1).
It is notable that there are two additional arguments (1, 1) appended to the end of the original argument list. Fortran compilers (like gfortran) pass string length as a hidden parameter at the end. CBLAS uses 1 for single-character strings. TA and TB are char, so length is 1.
The issue however is that Tapenade does not expect to see these explicit hidden parameters and the differentiation fails. Removing these argument artificially allows the differentiation to succeed.