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

[FFI] Add SharedLibrary class to track the usage of dynamic library #63

Merged
merged 1 commit into from Jan 7, 2023

Conversation

yaoyaoding
Copy link
Member

The ctypes.CDLL class does not provide a way to unload the loaded library. When a library is loaded, it will never
be unloaded until the program exits. However, when we tune an operator, we need to generate hundreds of kernels, and
each kernel will be compiled into a shared library. If we do not unload the shared library, we would load tens of
thousands of shared libraries, which will trigger memory error like:

cannot apply additional memory protection after relocation

To solve this problem, we need to unload the shared library after we use it. Thus, whenever we need to load a shared
library, we should use this module instead of the ctypes.CDLL class. The SharedLibrary class will keep track of the
loaded libraries, and unload them when no one references them.

The current implementation only supports *nix systems. Will add support for Windows when we plan to support Windows
in the project-level.

@yaoyaoding yaoyaoding merged commit d4dd236 into hidet-org:main Jan 7, 2023
@yaoyaoding yaoyaoding deleted the share-lib branch January 7, 2023 06:59
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

Successfully merging this pull request may close these issues.

None yet

1 participant