-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Matrix Multiplication #291
Comments
unfortunately this is not that surprising - if the model is dominated by a matrix multiplication, then the version that uses a linear algebra library will be much faster. Supporting this properly has been on the back burner for a long time (#38, #134, #213 - these mostly concern multinomial distributions but the syntactic issue in #134 is shared and is the primary blocker). The actual calling convention is not that bad, though it does mean that models need to have a working copy of gfortran to compile which is quite annoying in practice, particularly for people on macs |
I'm glad you agree. For my use-case, I can circumvent this by being a little more clever about this. But to stick to this issue, and since you know this stuff already:
But if I just think about BLAS (whatever that is). First, it says:
So on my Windows machine it is
Then apparently /* DGEMM - perform one of the matrix-matrix operations */
/* C := alpha*op( A )*op( B ) + beta*C */
BLAS_extern void
F77_NAME(dgemm)(const char *transa, const char *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
FCLEN FCLEN); Finally, I've asked ChatGPT about this and it suggested this code for invoking this:
I don't know where these I've googled and BLAS should be supported on Mac. Details
|
Okay, I've also found this snippet here that might be helpful: And of course this: https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Linear-algebra |
Thanks - that part is straightforward and we do it elsewhere (for example https://github.com/mrc-ide/eigen1/blob/master/src/util.c#L16-L17) - the pain comes when users have not correctly installed the fortran parts of the toolchain - and on macs that changes every couple of years as apple and R-core change how things get installed. The blocker on this is the odin syntax, and that's been unresolved for about 5 years so I doubt we will get to it soon! |
Good. I won't comment on the syntax just yet.. Especially since I don't know anything about parsers. I guess the problem is that right now the line order doesn't matter, but for the three-step definition it would need to? In any case, thanks for indulging this conversation. I guess, for my personal understanding, on Windows we have Rblas.dll, and I had hoped it was possible to just link to that, and not need a Fortran compiler. On Windows however, we have Rtools, and most likely it also contains Fortran compiler.. So I don't really have experience with this. I would have guessed |
Windows tends to be fine because R core controls the whole toolchain. On mac, at linking, you get issues if libgfortran is not found Line order won't matter for this either - the intention is to support
at the moment |
Benchmarking an R+deSolve code against the equivalent odin code yielded a surprising result:
I suspect the culprit is the lack of matrix multiplication in
odin
(or maybe I don't know how to invoke it).In the
deSolve
part:However, in the
odin
part I do:Here I've omitted the parts I don't think are necessary.
Unfortunately, R's C-facilities have a weird way of doing matrix multiplication, so it might not be supported yet.
I'll work on a minimal testcase to check if this is indeed the problem.
Under details, I have more complete excerpts of my code:
Details
Benchmarking:
The text was updated successfully, but these errors were encountered: