numerics in Lisp #41
Replies: 16 comments 21 replies
-
I've been working on an interface to Eigen, if that helps.
…On Wed, Aug 24, 2022 at 7:40 PM Jerry Vinokurov ***@***.***> wrote:
It seems like achieving the aims of this project will require some kind of
reasonably efficient numerical tools. My day job is working in
numpy/pandas/dask, so I'm pretty familiar with that universe of tools, but
I don't know what people use these days in Lisp, if anything. I took a
brief look around a while back and I came up with:
- GSLL - bindings to the GNU scientific library
- MAGICL - linear algebra package that wraps BLAS
I'm sure there are others I don't know about, but it's hard to find out
what they might be. I saw on the CL subreddit some months back that Marco
Heisig had done some work on autovectorizing Lisp code that was very
promising from a performance standpoint but I'm not sure what the maturity
of that project is (and I think it was only for SBCL).
Maybe we don't need to reinvent the numpy wheel (haha) to make this
specific project work, but I think it would be cool if there was something
that was as ergonomic in CL as numpy is in Python and offered comparable
performance. It would certainly help in the implementation of various
geometrical algorithms. Would love to hear what others think about this.
—
Reply to this email directly, view it on GitHub
<#41>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABGMMJFAZTHA2FIRDQYOG3V226JDANCNFSM57RHDUMA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I see three areas in which numerics can be helpful.
|
Beta Was this translation helpful? Give feedback.
-
The text Fast Floating-Point Pro cessing in Common Lisp by Fateman, Broughan, Willcock and Rettig discusses how to efficiently program numerics in Lisp and illustrates declarations as well as macros that can make the declarations less tedious. |
Beta Was this translation helpful? Give feedback.
-
This was also brought to my attention if we want to go the FFI route: https://github.com/digikar99/bmas |
Beta Was this translation helpful? Give feedback.
-
Also things like this https://github.com/takagi/avm , i think there's an cl-opencl out there. And for simple advantage of simd in sbcl https://github.com/marcoheisig/Loopus |
Beta Was this translation helpful? Give feedback.
-
I have been advised that for our needs SIMD is more appropriate than CUDA. https://www.reddit.com/r/GraphicsProgramming/comments/x1rwoo/how_widespread_is_cuda_availability/? My preference is still a purely CL option, but we could go with an FFI lib if we have to. |
Beta Was this translation helpful? Give feedback.
-
The eigen interface which I am using basically does what I want it to do,
but could be extended fairly easily. It currently needs some work as the
original author did not provide finalizations on matrices.
…On Tue, Aug 30, 2022 at 6:48 PM Kaveh Kardan ***@***.***> wrote:
@awolven <https://github.com/awolven> Eigen came up in a discussion. How
far along are you on your interface?
—
Reply to this email directly, view it on GitHub
<#41 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABGMMOIDDHTRACRMVCHCXDV32MT3ANCNFSM57RHDUMA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Nice example: https://gist.github.com/digikar99/13ed3868993ca8c71c91b50c8022a64d |
Beta Was this translation helpful? Give feedback.
-
https://www.codeproject.com/Articles/874396/Crunching-Numbers-with-AVX-and-AVX |
Beta Was this translation helpful? Give feedback.
-
I think the choice of tools depends on what the use cases are and what you want to prioritize. If the team wants to learn SIMD, then one could certainly go the sb-simd way, possibly extending it to other platforms (arm64, M1, etc). But if getting things to work ASAP and reasnably-portably is a priority, I think an FFI would be better, largely because C and fortran libraries seem to have been battling the issue of cross-compiler and cross-platform portability-with-performance for decades, and so not using them seems like we are discarding their efforts; and then if it does turn out that it actually hampers extensibility, then perhaps one could do some slight refactoring to take sb-simd into account wherever appropriate. For the FFI route, if you are working with at least moderately sized vectors and matrices (more than 100 or 1000 elements), magicl seems like a fine choice in terms of performance as well as stability. I am not exactly sure what its status is on other implementations, but I also don't think they are going terribly beyond the ANSI standard. BLAS is also an industry standard that shouldn't be a wrong choice. In fact, for smaller arrays, one could try putting static-dispatch to recompile magicl appropriately. And wherever magicl happens to be incomplete, one could add more functionality to it; their teams seems fairly comfortable with PRs and requests. I also don't think ANSI CL is sufficient for a good number crunching library that is performant for small arrays as well as large, unless you invent a whole DSL itself (I'm looking at coalton!). In effect, cross-implementation portability gets thrown out of the window, unless the implementation decides to at least support CFFI and CLTL2 (and perhaps CLOSER-MOP as well). Even if you do have CFFI, writing reasonably maintable/modular code requires dispatching on specialized array types. Here, generic functions do not suffice (and I haven't found any good way to use CLOSER-MOP - or even SB-PCL - to achieve the same results on SBCL). Writing a small layer of abstraction for dispatching on types using only lambda-lists with all arguments as required and positions (rather than optional, keyword, and rest) takes less than 300 LOC. But when you put in the code for parsing optional, keyword, and rest, code blows up pretty quickly - and this was the main goal of polymorphic-functions. However that only gets you runtime dispatch. To get compile-time dispatch in order to be performant on small arrays, you need CLTL2, through something like cl-environments and cl-form-types. Without them, I don't think I'd recommend Common Lisp as the "ultimate" language for number crunching. (With them though, I think its potential goes beyond julia, if only we had more people writing lisp :/.) |
Beta Was this translation helpful? Give feedback.
-
I'm thinking we need our numerics to do the following:
Case (1) would benefit from vectorization and concurrency on our part. The others would do their own such things under the hood I imagine. So it appears to me that most of our needs involve data transfer to the outside (C/C++) world. Which makes me wonder if my preference to keep everything in CL is misguided. Should we store our vector and math data structures as C arrays or structs with simple CL interfaces? |
Beta Was this translation helpful? Give feedback.
-
I am not sure if it would fit, but I have been experimenting with and using Coalton and it offers a bunch of things CL is missing in terms of building tools that work with numbers. |
Beta Was this translation helpful? Give feedback.
-
perhaps all this is a bit premature. Shouldn't we be looking at a framework wherein these possibilities exist? So coming up with a protocol for what needs to be done. e.g. object->vertex-array, assemble-object-for-display, submit-objet-for-display, translate-object-for-client :gl/:vulkan, etc... |
Beta Was this translation helpful? Give feedback.
-
I'm in favor of taking small steps. Based on the timings that were done for packing points, looks like the Origin package is a good one to switch to for our vector and matrix code. Once that is done we can test packing our geometry into vertex arrays by replacing the functions in Then we can do more tests and see how best to vectorize/optimize the code. |
Beta Was this translation helpful? Give feedback.
-
So I've got the basics done over here https://github.com/JMC-design/kons-9/tree/point-origin |
Beta Was this translation helpful? Give feedback.
-
all demos run. |
Beta Was this translation helpful? Give feedback.
-
It seems like achieving the aims of this project will require some kind of reasonably efficient numerical tools. My day job is working in numpy/pandas/dask, so I'm pretty familiar with that universe of tools, but I don't know what people use these days in Lisp, if anything. I took a brief look around a while back and I came up with:
I'm sure there are others I don't know about, but it's hard to find out what they might be. I saw on the CL subreddit some months back that Marco Heisig had done some work on autovectorizing Lisp code that was very promising from a performance standpoint but I'm not sure what the maturity of that project is (and I think it was only for SBCL).
Maybe we don't need to reinvent the numpy wheel (haha) to make this specific project work, but I think it would be cool if there was something that was as ergonomic in CL as numpy is in Python and offered comparable performance. It would certainly help in the implementation of various geometrical algorithms. Would love to hear what others think about this.
Beta Was this translation helpful? Give feedback.
All reactions