Repository navigation
perf(cuda): compile every kernel once (wheel 93.1 -> 42.4 MB) - #105
Merged
Merged
Conversation
Kernels launched or defined in headers were compiled into every TU that included them. Each family is now instantiated once in its kernels.cu and launched through a table of its order specializations (launch/by_order.cuh). cu12 core 157.3 -> 70.8 MB, cu13 189.9 -> 85.8 MB, wheel 93.1 -> 42.4 MB. Machine code of every kernel on every arch is byte-identical to 0.3.3.
Merged
This file contains hidden or 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
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.
Why
The 0.3.3 wheel is 93.1 MB, 7 MB under PyPI's 100 MB per-file limit. In its cu12 core, 65.4 of the 111.8 MB of SASS were duplicate copies of the same kernels:
LAUNCH_*macro) is instantiated, for five stencil orders × every arch of the fat binary, in every translation unit that includes the header, whether that unit calls it or not. That means an equation'sforward.cuandbackward.cu, and every equation sharing a kernel family (Elastic/DASMu/ViscoElastic,Elastic3D/DASMu3D,Acoustic/ViscoAcoustic). Each 2-D elastic kernel had six copies.static __global__kernel defined in a header is compiled into every unit that includes it, referenced or not.What
cuda/launch/by_order.cuh: a table of a kernel template's five stencil-order specializations (2/4/6/8/-1).kernels.cudefines its tables; it is the only translation unit that names the specializations.kernels.cuhlaunch through the table, so call sites are unchanged.kernel<N><<<>>>.extern template: nvcc 12.9 warns that extern__global__templates stop being supported in whole-program mode once-static-global-template-stubdefaults to true (#20279), and nvcc 13 requires a named specialization to be defined in the unit that names it (#20280).kernels.cu, behind a declaration in the header: air-clear, the 3-D carrier capture, LSRTMcompute_v2_lambda, the VRZ utt correction and kappa kernels, and the TTI-2nd rho correction.visco_acoustic2d'svisco_opslaunchers move to a newspectral_ops.cu.nullptrs explicitly.*_ADJOINT/BUILD_VRZ_ADJOINT_FIELDS*, elastic3d*_ADJOINT) are left as they were: a table would instantiate kernels the core never contained.docs/dev/cuda_drivers.mdstates the convention.docs/dev/release_cores.mdare updated.Sizes (manylinux_2_28 images, the same arch lists as 0.3.3):
Tested
test/backend_gradient_matrix.py --backends eager/gpu c-cuda --scale cuda-suite, 29 cases): the 0.3.3 core's log and this core's are identical line for line, apart from timestamps.gradient_cases.pykeeps failing on purpose.🤖 Generated with Claude Code