forked from poliastro/poliastro
-
Notifications
You must be signed in to change notification settings - Fork 1
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
[WIP] jit/core redesign #7
Open
s-m-e
wants to merge
347
commits into
main
Choose a base branch
from
jit_redesign
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…redesign_solveivp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
This PR serves as foundation for both orbit and state arrays. It focusses on functionalities provided by the
core
module and their invocation. All relevantcore
functions are designed to work equally on CPUs and GPUs as either universal functions or generalized universal functions. As a "side-effect", all relevantcore
functions allow parallel operation with full broadcasting semantics.Summary
All dependencies of
Orbit
and state classes towardscore
are refactored as follows:numba.vectorize
andnumba.guvectorize
serve as the only interface between regular uncompiled Python code andcore
numba.vectorize
andnumba.guvectorize
only call functions decorated bynumba.jit
/numba.cuda.jit
numba.jit
/numba.cuda.jit
can only call each other.numba.vectorize
,numba.guvectorize
andnumba.jit
/numba.cuda.jit
:math
module, but notnumpy
- except for certain details like enforcing floating point precisionThe above mentioned "hierarchy" of decorators is imposed by CUDA-compatibility. While functions decorated by
numba.jit
(targetscpu
andparallel
) can be called from uncompiled Python code, functions decorated bynumba.cuda.jit
(targetcuda
) are considered "device functions" and can not be called by uncompiled Python code directly. They are supposed to be called by CUDA-kernels (or other device functions) only (slightly simplifying the actual situation as implemented bynumba
). If the target is set tocuda
, functions decorated bynumba.vectorize
andnumba.guvectorize
become CUDA kernels.Eliminating
numpy
as a dependency serves two purposes. While it also contributes to CUDA-compatiblity, it additionally makes the code significantly faster on CPUs.New decorators are introduced, wrapping
numba.jit
,numba.cuda.jit
,numba.vectorize
andnumba.guvectorize
, centralizing compiler options and target switching (cpu
,parallel
orcuda
) as well as simplifying typing:-
vjit
: Wrapsnumba.vectorize
. Functions decorated by it carry the suffix_vf
.-
gjit
: Wrapsnumba.guvectorize
. Functions decorated by it carry the suffix_gf
.-
hjit
: Wrapsnumba.jit
ornumba.cuda.jit
, depending on compiler target. Functions decorated by it carry the suffix_hf
.-
djit
: Variation ofhjit
with fixed function signature for user-provided functions used byCowell
All mentioned wrappers are found in
core.jit
.As a result of name suffixes, a number of
core
module functions have been renamed making the package intentionally backwards-incompatible. Functions not yet using the new infrastructure can be recognized based on lack of suffix.core
functions dynamically generating (and compiling) other functions carry_hb
,_vb
and_gb
suffixes.Math
The former
_math
module has become a first-class citizen ascore.math
, fully compiled by the above mentioned infrastructure.All compiled code now enforces a single floating point precision level, which can be configured by users. The default is FP64 / double precision. For simplicity, the type shortcut is
f
. Additional infrastructure can be found incore.math.ieee754
.core.math
contains a number of replacements fornumpy
operations, mostly found incore.math.linalg
. All of those functions do not allocate memory and are free of side-effects including a lack of changes to their parameters. 3D vectors are expressed as tuples (type shortcutV
, replacingTuple([f,f,f])
). Matrices are expressed as tuples of tuples (type shortcutM
, replacingTuple([V,V,V])
).core.math
also replaces (some) requiredscipy
functions:- scipy.interpolate.interp1d is replaced by
core.math.interpolate.interp_hb
. It custom-compiles 1D linear interpolators, embedding data statically into the compiled functions.- scipy.integrate.solve_ivp, scipy.integrate.DOP853 and scipy.optimize.brentq are replaced by
core.math.ivp
.Style
core
modules now explicitly export APIs via__all__
.Settings
This PR introduces a new
settings
module. It currently serves to control compiler options, e.g. the compiler target (cpu
,parallel
andcuda
). Settings can be switched by either setting environment variables or importing thesettings
module before any other (sub-) module is imported.Logging
This PR introduces basic logging functionality. Logger name equals package name. The logger can also be imported from the new
debug
module. At the moment, it only logs compiler status messages and issues.Blocking
numba
issues for CUDA-compatibilitymath.nextafter
:nextafter
(via bothmath
andnumpy
) missing for CUDA numba/numba#9435guvectorize
: Allow multiple outputs forguvectorize
on CUDA target numba/numba#8303__name__
attribute for 'CUDAUFuncDispatcher': 'CUDAUFuncDispatcher' object has no attribute '__name__' numba/numba#8272Non-blocking
numba
issues for CUDA-compatibility with workaround presentnumba.cuda.jit
numba/numba#7870Non-blocking
numba
issues unrelated to CUDA with workaround present() -> (n)
in output argument: @guvectorize not accepting new size variable (i.e. () -> (n)) in output argument numba/numba#2797TODO
core.math.ivp
📚 Documentation preview 📚: https://hapsira--7.org.readthedocs.build/en/7/