-
Notifications
You must be signed in to change notification settings - Fork 59
Lower ion to rtio #2204
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
Open
rniczh
wants to merge
71
commits into
main
Choose a base branch
from
rniczh/lower-ion-to-rtio
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Lower ion to rtio #2204
Changes from 53 commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
46c39de
RTIO dialect is added to Catalyst
rniczh fd2dea4
Merge branch 'main' into rniczh/add-rtio-dialect
rniczh f127e6a
reformatting
rniczh eb19fa3
pulse should use f64 for duration
rniczh e5b170f
Update mlir/include/RTIO/IR/RTIODialect.td
rniczh 6c9e90d
Update mlir/include/RTIO/IR/RTIODialect.td
rniczh a502944
Update mlir/include/RTIO/IR/RTIODialect.td
rniczh 94927c3
Update mlir/include/RTIO/IR/RTIODialect.td
rniczh e9b1e84
Update mlir/include/RTIO/IR/RTIOOps.td
rniczh 1452e7b
Update mlir/include/RTIO/IR/RTIODialect.td
rniczh 38242f5
Update mlir/include/RTIO/IR/RTIOOps.td
rniczh 6c00116
add empty op
rniczh 48ecf52
Merge branch 'rniczh/add-rtio-dialect' of github.com:PennyLaneAI/cata…
rniczh ef5c3a6
fix formatting
rniczh c819333
update td
rniczh a26864c
Add pass to lower ion dialect to rtio dialect
rniczh c0e7234
update
rniczh f1ad990
add missing include
rniczh 4cf83fe
update
rniczh 27a4b98
add missing lib
rniczh 4b3408f
Merge branch 'rniczh/add-rtio-dialect' of github.com:PennyLaneAI/cata…
rniczh 29ffc70
remove redundant include
rniczh fcd540d
update
rniczh 82bb3aa
remove other redundant functions
rniczh 4a7430a
update pass
rniczh a349b1c
remove redundant code
rniczh cc814da
update linkage
rniczh 5681bb3
add rtio.config
rniczh f326bf2
drop timeline IR
rniczh 0e6b14f
remove unrelated thing
rniczh c0da830
Merge branch 'main' into rniczh/add-rtio-dialect
rniczh bd1c4c4
update channel ID underlying number
rniczh 8e58bbe
Merge branch 'rniczh/add-rtio-dialect' of github.com:PennyLaneAI/cata…
rniczh 6d57469
add bracket for if
rniczh cf5874e
fix
rniczh c4a3afa
add assert for oob
rniczh 5e136eb
update comment
rniczh 9fd57fc
merge from upstream
rniczh b623d0d
supports importing json to rtio.config
rniczh b127e9e
update changelog
rniczh 1ce02ba
add deviceDB option
rniczh a379528
add missing comma
rniczh 4f851ef
add missing include
rniczh 2ff88f9
Update mlir/lib/RTIO/IR/RTIODialect.cpp
rniczh 2486c74
Update mlir/include/RTIO/IR/RTIOOps.td
rniczh e6d0c7c
Add filecheck line
rniczh d8588ad
Merge branch 'main' into rniczh/add-rtio-dialect
rniczh 49b2c0b
merge from upstream
rniczh 3937ecf
revert
rniczh 5559870
merge
rniczh e92d58e
Add changelog
rniczh 7ed6c04
Merge branch 'rniczh/add-rtio-dialect' of github.com:PennyLaneAI/cata…
rniczh f77a12b
update changelog
rniczh ff777d3
merge from upstream
rniczh d0eba30
udpate
rniczh 9837334
update
rniczh 6314072
add test
rniczh 528e0bb
remove comment
rniczh 99a85c5
remove comment
rniczh 7e7ee45
update changelog
rniczh 2040912
Add scf.if and scf.for test
rniczh 737425c
Merge branch 'main' into rniczh/lower-ion-to-rtio
mehrdad2m e19c29c
change variable name
rniczh c368eff
only support walkresult as return type
rniczh aa46203
fix
rniczh 81db109
exit gracefully
rniczh 436beaa
move ionInfo to separate file
rniczh 820ec19
move json utils to separate files
rniczh 8c210ca
refactor
rniczh 4385130
reformat
rniczh 2fa61f6
clean unused ops
rniczh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| add_subdirectory(IR) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| add_mlir_dialect(RTIOOps rtio) | ||
| add_mlir_doc(RTIODialect RTIODialect RTIO/ -gen-dialect-doc) | ||
| add_mlir_doc(RTIOOps RTIOOps RTIO/ -gen-op-doc) | ||
|
|
||
| set(LLVM_TARGET_DEFINITIONS RTIOOps.td) | ||
| mlir_tablegen(RTIOAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=rtio) | ||
| mlir_tablegen(RTIOAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=rtio) | ||
| add_public_tablegen_target(MLIRRTIOAttributesIncGen) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright 2025 Xanadu Quantum Technologies Inc. | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
|
|
||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "mlir/Bytecode/BytecodeOpInterface.h" | ||
| #include "mlir/IR/Dialect.h" | ||
| #include "mlir/IR/OpDefinition.h" | ||
|
|
||
| #include "RTIO/IR/RTIOOpsDialect.h.inc" | ||
|
|
||
| #define GET_TYPEDEF_CLASSES | ||
| #include "RTIO/IR/RTIOOpsTypes.h.inc" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| // Copyright 2025 Xanadu Quantum Technologies Inc. | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
|
|
||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef RTIO_DIALECT | ||
| #define RTIO_DIALECT | ||
|
|
||
| include "mlir/IR/OpBase.td" | ||
| include "mlir/IR/DialectBase.td" | ||
| include "mlir/IR/AttrTypeBase.td" | ||
| include "mlir/IR/BuiltinTypeInterfaces.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // RTIO Dialect Definition | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def RTIO_Dialect : Dialect { | ||
| let summary = "Real-Time I/O dialect for FPGA quantum control"; | ||
| let description = [{ | ||
| The RTIO dialect provides operations for precise timing control | ||
| and hardware signal generation on FPGAs for quantum computing. | ||
|
|
||
| It provides declarative operations with explicit event dependencies for hardware control. | ||
| }]; | ||
|
|
||
| let name = "rtio"; | ||
| let cppNamespace = "::catalyst::rtio"; | ||
| let useDefaultTypePrinterParser = 1; | ||
| let useDefaultAttributePrinterParser = 1; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // RTIO dialect types. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class RTIO_Type<string name, string typeMnemonic, list<Trait> traits = []> | ||
| : TypeDef<RTIO_Dialect, name, traits> { | ||
| let mnemonic = typeMnemonic; | ||
| } | ||
|
|
||
| // Channel type with variadic parameters | ||
| def RTIOChannelType : RTIO_Type<"Channel", "channel"> { | ||
| let summary = "A hardware I/O channel with logical and physical identification"; | ||
| let description = [{ | ||
| Represents a virtual hardware channel for RTIO operations | ||
|
|
||
| Syntax: | ||
| ``` | ||
| !rtio.channel<KIND, ?> // Dynamic: kind only | ||
| !rtio.channel<KIND, N> // Static: kind + channel ID | ||
| !rtio.channel<KIND, [QUALIFIERS], ?> // Dynamic: with qualifiers | ||
| !rtio.channel<KIND, [QUALIFIERS], N> // Static: with qualifiers + channel ID | ||
| ``` | ||
|
|
||
| Examples: | ||
| ```mlir | ||
|
|
||
| // Simple DDS, channel ID TBD (to be resolved during channel resolution) | ||
| !rtio.channel<"dds", ?> | ||
|
|
||
| // DDS channel with qualifiers: | ||
| // Qualifiers distinguish different logical channels of the same kind. | ||
| // Example: ion 0, transition 0 -> will be distinguished from other transitions of | ||
| // the same ion. The mapping of the logical channel to the hardware channel will | ||
| // be resolved during the lowering pass from given dialect to RTIO dialect. | ||
| // User need to specifiy the mapping logic. | ||
| !rtio.channel<"dds", [0, "transition_0"], ?> | ||
|
|
||
| // DDS on hardware channel 0 | ||
| !rtio.channel<"dds", 0> | ||
|
|
||
| // === Channel Resolution During Compilation === | ||
|
|
||
| // Before channel resolution: Dynamic channels | ||
| !rtio.channel<"dds", [0], ?> | ||
|
|
||
| // After channel resolution: Resolved to hardware channel 1 | ||
| !rtio.channel<"dds", [0], 1> | ||
|
|
||
| // Note: The qualifiers are used to provide additional information to the channel type. | ||
| // And they will be used to distinguish different channels with the same kind. | ||
| ``` | ||
| }]; | ||
|
|
||
| let parameters = (ins | ||
| StringRefParameter<"channel kind">:$kind, | ||
| OptionalParameter<"mlir::ArrayAttr">:$qualifiers, | ||
| OptionalParameter<"mlir::IntegerAttr">:$channelId | ||
| ); | ||
|
|
||
| let assemblyFormat = [{ | ||
| `<` custom<ChannelTypeBody>($kind, $qualifiers, $channelId) `>` | ||
| }]; | ||
|
|
||
| let extraClassDeclaration = [{ | ||
| bool hasQualifiers() const { | ||
| return getQualifiers() && !getQualifiers().empty(); | ||
| } | ||
|
|
||
| size_t getNumQualifiers() const { | ||
| return getQualifiers() ? getQualifiers().size() : 0; | ||
| } | ||
|
|
||
| mlir::Attribute getQualifier(size_t index) const { | ||
| assert(getQualifiers() && "qualifiers are not present"); | ||
| assert(index < getQualifiers().size() && "index out of bounds"); | ||
| return getQualifiers()[index]; | ||
| } | ||
|
|
||
| bool isStatic() const { | ||
| auto channelId = getChannelId(); | ||
| if (!channelId) { | ||
| return false; | ||
| } | ||
| return channelId.getInt() != mlir::ShapedType::kDynamic; | ||
| } | ||
|
|
||
| bool isDynamic() const { | ||
| return !isStatic(); | ||
| } | ||
| }]; | ||
| } | ||
|
|
||
| // Event handle type | ||
| def RTIOEventType : RTIO_Type<"Event", "event"> { | ||
| let summary = "A handle to a pending RTIO event"; | ||
| let description = [{ | ||
| Represents a handle to a pending RTIO event (e.g., pulse, sync). | ||
|
|
||
| Example: | ||
| ```mlir | ||
| %event0 = rtio.pulse %ch0 duration(%dur) frequency(%freq) phase(%phase) : !rtio.event | ||
| %event1 = rtio.pulse %ch1 duration(%dur) frequency(%freq) phase(%phase) : !rtio.event | ||
| %sync = rtio.sync %event0, %event1 : !rtio.event | ||
| ``` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // RTIO Operation Base | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class RTIO_Op<string mnemonic, list<Trait> traits = []> : | ||
| Op<RTIO_Dialect, mnemonic, traits>; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // RTIO Attributes | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class RTIO_Attr<string name, string attrMnemonic, list<Trait> traits = []> | ||
| : AttrDef<RTIO_Dialect, name, traits> { | ||
| let mnemonic = attrMnemonic; | ||
| } | ||
|
|
||
| def RTIOConfigAttr : RTIO_Attr<"Config", "config"> { | ||
| let summary = "A dictionary attribute for RTIO configuration"; | ||
| let description = [{ | ||
| A configuration attribute that wraps a DictionaryAttr for RTIO-specific metadata. | ||
| Can be used as a module-level attribute. | ||
|
|
||
| Example: | ||
| ```mlir | ||
| module @my_module attributes { | ||
| rtio.config = #rtio.config<{ | ||
| config1 = 1 : i32, | ||
| config2 = "test", | ||
| }> | ||
| } { | ||
| // ... | ||
| } | ||
| ``` | ||
| }]; | ||
|
|
||
| let parameters = (ins | ||
| "mlir::DictionaryAttr":$dict | ||
| ); | ||
|
|
||
| let assemblyFormat = "`<` $dict `>`"; | ||
|
|
||
| let extraClassDeclaration = [{ | ||
| /// The canonical attribute name for module-level config. | ||
| static llvm::StringRef getModuleAttrName() { | ||
| return "rtio.config"; | ||
| } | ||
|
|
||
| /// Return the value for the given key, or null if not found. | ||
| mlir::Attribute get(llvm::StringRef key) const { | ||
| return getDict().get(key); | ||
| } | ||
| mlir::Attribute get(mlir::StringAttr key) const { | ||
| return getDict().get(key); | ||
| } | ||
|
|
||
| /// Return whether the config contains the given key. | ||
| bool contains(llvm::StringRef key) const { | ||
| return getDict().contains(key); | ||
| } | ||
| bool contains(mlir::StringAttr key) const { | ||
| return getDict().contains(key); | ||
| } | ||
|
|
||
| /// Return the specified named attribute if present. | ||
| std::optional<mlir::NamedAttribute> getNamed(llvm::StringRef key) const { | ||
| return getDict().getNamed(key); | ||
| } | ||
| std::optional<mlir::NamedAttribute> getNamed(mlir::StringAttr key) const { | ||
| return getDict().getNamed(key); | ||
| } | ||
|
|
||
| /// Support range iteration (delegates to DictionaryAttr). | ||
| using iterator = mlir::DictionaryAttr::iterator; | ||
| iterator begin() const { return getDict().begin(); } | ||
| iterator end() const { return getDict().end(); } | ||
| bool empty() const { return getDict().empty(); } | ||
| size_t size() const { return getDict().size(); } | ||
| }]; | ||
| } | ||
|
|
||
| #endif // RTIO_DIALECT | ||
|
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.