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

Add __quantum__rt__device_init(int8_t *, int8_t *, int8_t *) #396

Merged
merged 8 commits into from Dec 8, 2023

Conversation

maliasadi
Copy link
Member

@maliasadi maliasadi commented Dec 6, 2023

We currently lower the device name, kwargs, and library with 3 __quantum__rt__device(key, spec) calls. The runtime initializes the targeted device after getting the device name and kwargs at the third call:

__quantum__rt__device("rtd_name", "lightning.qubit");
__quantum__rt__device("rtd_kwargs", "{...}");
__quantum__rt__device("rtd_lib", "rtd_lightning.so"); <--- init device

This PR reduces the number of these device calls into 1 single __quantum__rt__device_init("rtd_lib", "rtd_name", "rtd_kwargs") call and deprecates the __quantum__rt__device instruction. The runtime is able to initialize the device without necessarily storing partial device info or implying any specific order to define these specifications in the IR and the runtime. This PR is related to #381 and will help better scope the lifetime of device instances. We also add __quantum__rt__device_release() to release the initialized device by request (this'll be used in the async support).

@maliasadi maliasadi added runtime Pull requests that update the runtime compiler Pull requests that update the compiler frontend Pull requests that update the frontend labels Dec 6, 2023
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (88bd0e2) 99.48% compared to head (a6efe74) 99.49%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #396   +/-   ##
=======================================
  Coverage   99.48%   99.49%           
=======================================
  Files          42       42           
  Lines        7053     7134   +81     
  Branches      477      477           
=======================================
+ Hits         7017     7098   +81     
  Misses         20       20           
  Partials       16       16           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maliasadi maliasadi requested a review from dime10 December 6, 2023 23:21
@josh146
Copy link
Member

josh146 commented Dec 7, 2023

@maliasadi what is the context behind this change?

@maliasadi
Copy link
Member Author

@maliasadi what is the context behind this change?

@josh146 First, it removes 2 instructions calls from the generated LLVM IR with hardcoding the device triple (name, library, kwargs) from the frontend to the backend in one single rt__device_init call instead of 3 rt__device calls.

// Before this change, (calls should be in some order: name->kwargs->lib)
__quantum__rt__device("rtd_name", "LightningQubit");
__quantum__rt__device("rtd_kwargs", "{...}");
__quantum__rt__device("rtd_lib", "rtd_lightning.so"); <--- init device
// Now,
__quantum__rt__device_init("rtd_lightning.so", LightningQubit", "{...}");

Second, it lets runtime to initialize device instances without keeping record of any partial information about that device. Before this change, the runtime had to store partial information about name and kwargs of the device before initializing it. But now, the runtime is able to initialize the device without necessarily storing partial device info or implying any specific order to define these specifications in the IR and the runtime. This PR is related to #381 and will help better scope the lifetime of device instances.

@josh146
Copy link
Member

josh146 commented Dec 7, 2023

thanks :)

Copy link
Collaborator

@dime10 dime10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, I think it just needs a changelog :)

frontend/catalyst/jax_primitives.py Outdated Show resolved Hide resolved
mlir/lib/Quantum/Transforms/ConversionPatterns.cpp Outdated Show resolved Hide resolved
mlir/lib/Quantum/Transforms/ConversionPatterns.cpp Outdated Show resolved Hide resolved
maliasadi and others added 3 commits December 7, 2023 16:54
Co-authored-by: David Ittah <dime10@users.noreply.github.com>
@maliasadi maliasadi merged commit 75e3133 into main Dec 8, 2023
21 checks passed
@maliasadi maliasadi deleted the maa/fix-rt-device-signature branch December 8, 2023 20:13
@maliasadi maliasadi restored the maa/fix-rt-device-signature branch December 19, 2023 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Pull requests that update the compiler frontend Pull requests that update the frontend runtime Pull requests that update the runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants