[python] Use separate context for kernel builder#3940
Closed
lmondada wants to merge 1 commit intoNVIDIA:mainfrom
Closed
[python] Use separate context for kernel builder#3940lmondada wants to merge 1 commit intoNVIDIA:mainfrom
lmondada wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
4c97fda to
21e2e30
Compare
Signed-off-by: Luca Mondada <luca@mondada.net>
|
CUDA Quantum Docs Bot: A preview of the documentation can be found here. |
Collaborator
Author
|
We'll have to discuss a plan to fix this. For now I've disabled using the kernel builder with kernels that have deferred compilation. |
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.
This PR fixes the following crash
Error:
RuntimeError: the operation has been invalidatedThe reason for this is that kernel2 was getting compiled using
compile_to_mlirinpython/cudaq/kernel/ast_bridge.py. This callscontext._clear_live_operations()at the end of the function. However, the context is global, thus it also clears the context for the kernel builder. This invalidates the insertion point stored in the builder, hence any further modifications of the kernel builder fails.This PR proposes to use a separate context for the kernel builder. When a kernel builder gets invoked and needs to be jitted, we then output the module as string and reload it into the global context. This will come at some performance cost, but only affects kernels defined using the builder and only at the first invocation (as the compiled MLIR module is cached).