Lazily load nvmath subpackages and bindings wrappers - #69
Draft
juenglin wants to merge 1 commit into
Draft
Conversation
…ibrary wrapper and host API into the process.
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.
Summary
Importing any
nvmath.bindingsCython submodule (for example CuPy'sfrom nvmath.bindings.cycurand cimport ...) previously executednvmath/__init__.py, which importedfft/linalg/sparse/tensorand every library wrapper, including optional*Mpand NVSHMEM modules. That mapped ~130 extra.sofiles (~350 MB RSS) into the process and slowed Python object construction process-wide (visible oncupy.empty_likeand even onbytearray(256)).This PR loads those subpackages and wrappers on first access (PEP 562).
import nvmath.bindings.cycurandnow maps cycurand and its own deps only. Public names,__all__, and "optional modules areNonewhen unavailable" are unchanged. Native-library preload for host APIs still runs whennvmath.fft/linalg/sparse/tensorare actually imported.Test plan
pytest tests/nvmath_tests/test_bindings_init.pypytest tests/nvmath_tests/linalg/generic/matmul/test_qualifier.pypytest tests/nvmath_tests/linalg/test_layout.pypytest tests/nvmath_tests/ndbuffer/test_no_cupy.pyimport nvmath.bindings.cycurand— 130 → 7 extra.so, 347 MB → 8.6 MB RSS