-
Notifications
You must be signed in to change notification settings - Fork 19
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
Low-level Blas interface #28
Comments
This is NICE (eg I like what you're doing with saying symm==hymm in the real case). l think I will be interested in this. Though i'll need to mull it for a day or so first (and think about the design implications etc). The design is so the maintainer runs the make file before pushing to hackage? a strong design constraint for hblas i want to adhere to is "zeroconfig". Can this approach be extended to cover lapack? If so, what would be the challenges of that? |
(if i don't follow up in a day or so, please ping me, but this is NICE) |
i'm open to moving to having a tool that generates the ffi stuff on the maintainer side, that maybe makes some presumptions about the normal target so that the typical config is zero config, but has some hooks/ flags to do installer side config when appropriate. @maxpow4h did a prelim foray into that which i've cached in the ffi-utils folder , but i'm not currently using. what are some example BLAS configs that see wide use that use a CBLAS_INDEX thats not a 32bit int? |
Code generatorThe
For the user, these generated files would already be pre-packaged. The user does need to have The sticky details
Leaving the integer size problems aside, there's also the issue that Blas implementations often come in different names and flavors. Of the top of my head, there's: ACML, ATLAS, cuBLAS, Intel MKL, OpenBLAS, ... and of course the official reference implementation of BLAS by Netlib. It may take a lot of effort to accommodate to all of them and deal with their quirks, if any. I'm not really sure how I plan to deal with this part yet. I would certainly prefer to streamline the process as much as possible for the user! LapackI've not really looked into Lapack yet so that may take a while. It would also be a separate project. |
still mulling this on a few angles, but heres some naive (and possibly controversial!) thoughts:
|
|
for exposing the "closedness", one approach would be adding somthing like class Blas a where
elementType :: p a-> ElementType a
data ElementType a where
EFloat :: ElementType Float
EDouble :: ElementType Double
-- etc cool, sounds like we're converging on agreeing |
I figured there'd be a way to make them closed (saw a few on StackOverflow), but all of them are sort of a hack and I feel there's no need to go through all this trouble just to stop the user from shooting themselves with a nerf gun :P |
wasn't meant for safety! was thinking more so about how theres certain Double Precision routines that can be accelerated by a Single Precision estimate first! (easy way to make the closedness of the API obvious too ) |
anyways, no hurry :) this week i'm trying to finish up the alpha release engineering for my Numerical package |
to clarify, i'm suggesting adding something like |
Right, but why go through all this effort to make them closed? |
good point :) |
Think I'm mostly done with it for the time being. The docs have a lot of room for improvement, but functionality-wise I'm not sure if there's anything else I plan on adding to it. I tried to implement an automated Haskell script to help with the linking process (find where libraries are and set the right flags), and it ended up taking far more effort that I anticipated because I had to learn a lot of the internal details of Cabal. The flags themselves are also quite complex: the Intel MKL alone has like 5-8 flags that vary depending on the architecture, operating system, parallelization, etc. For the time being, I'm deferring the linking part to the user (i.e. blas-hs does not link to Blas directly). What I might do in the near term is to add a table of the linking flags for some common Blas implementations on typical systems, add some explanation of how linking works, and link to the appropriate documentation if users need more info etc so that the user can do it themselves. For really simple cases (such as OpenBlas, Netlib Blas) it's probably fine to implement Cabal flags for them too. If you have any suggestions, please let me know! |
oh wow, good job! this is very very nice! I'll take a look soon, but this is quite nice. (a bit buried ) I'm happy to help you work on the cabal setup.hs foo in a few weeks time permitting |
Here's a complete low-level Blas FFI that contains everything defined in the official Blas standard. It's a 1-to-1 map to the C interface, using
Ptr
,IO
, etc, but with ordinary Haskell types (Int
,Float
, etc). It contains both safe and unsafe foreign calls.For better or worse, it makes use of c2hs, which saves some effort with the marshaling of data types. The generated Haskell code is not portable partly because c2hs doesn't handle
size_t
properly, but also because the underlying Blas implementation is free to choose a different type forCBLAS_INDEX
(most implementations do usesize_t
though).Would you be interested in this? It could save you some of the more tedious work.
The text was updated successfully, but these errors were encountered: