Skip to content
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

experiment with numba/cffi/cython? #363

Open
AndrewAnnex opened this issue Apr 14, 2020 · 9 comments
Open

experiment with numba/cffi/cython? #363

AndrewAnnex opened this issue Apr 14, 2020 · 9 comments

Comments

@AndrewAnnex
Copy link
Owner

can numba/cffi be used to accelerate vectorized functions in spiceypy?
https://numba.pydata.org/numba-doc/0.15.1/interface_c.html
experiment!

@AndrewAnnex
Copy link
Owner Author

requires c_char support in numba numba/numba#3207

@AndrewAnnex AndrewAnnex changed the title experiment with numba/cffi? experiment with numba/cffi/cython? May 21, 2020
@AndrewAnnex
Copy link
Owner Author

I wonder if something clever using numpy dtype str_ and numba can be done, could I just pass c_void_p to cspice ctypes calls and rely on the ctypeslib in numpy to help?

@AndrewAnnex
Copy link
Owner Author

so after some experimentation cython is appearing as a viable option as I have locally prototyped a cython extension linked to the same shared library as spiceypy and they are able to share the same kernel pool. with cython I can also just make the subset of vectorized functions I need and slowly convert the codebase, in particular everything in support types to cython.

However, it seems like numba should still be viable, so I want to go back and figure out where I got stuck and get past that point. But I am slightly blocked by numba not supporting python 3.9 yet (or is being actively worked on now numba/numba#6345)

@gaowutong
Copy link

Or is there away to use spiceypy functions inside the numba-accelerated function?

@AndrewAnnex
Copy link
Owner Author

I found out a few months ago that there are a few features of ctypes that are not supported by numba and I although I could get numba to use spiceypy it was slower than using pure python. I could still be using numba incorrectly, but for now I will rule out numba unless I can be shown a working proof of concept.

As for cython, I now have a working proof on concept for accelerating spiceypy with it. With a quick benchmark I see about a 2x speedup and as far as I can tell at the moment SPICE remains the bottleneck rather than the python/cython code itself. There are some issues to resolve with linking and reliable compilation across conda-forge/pypi that I want to fix before I post a wip branch

@gaowutong
Copy link

Thanks for the reply, looking forward to your work!

@medley56
Copy link
Contributor

medley56 commented Mar 2, 2022

@AndrewAnnex In your prototype, are you building the .so from CSPICE source using Cython and setuptools.Extension or are you using the existing setup script to build spice.so and somehow telling Cython that the shared object already exists (after installation)? I don't know of a way to do the latter, so I'm thinking that this change would also mean changes to setup.py and get_spice.py.

@AndrewAnnex
Copy link
Owner Author

AndrewAnnex commented Mar 2, 2022 via email

@jessemapel
Copy link
Contributor

You want the FetchContent function in cmake. It allows you to download stuff like git repos and release tarballs and then hook into any cmake files located in them. CSPICE unfortunately doesn't come with a cmake configuration, but it's fairly easy to make one and then have it export a target that can be included in other projects.

If you're not going to be doing CMAKE build configuration for CSPICE and just use the makefiles, then you can use ExternalProject_Add which will download at build time instead of configuration time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants