From 976a5a66d7c82649c08e65f37cec2ac045c89139 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 6 Sep 2023 16:58:23 +0200 Subject: [PATCH 1/6] draft for Opaque Pointer workstream --- workstreams/Opaque_Pointers_Workstream.md | 98 +++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 workstreams/Opaque_Pointers_Workstream.md diff --git a/workstreams/Opaque_Pointers_Workstream.md b/workstreams/Opaque_Pointers_Workstream.md new file mode 100644 index 0000000..89f8665 --- /dev/null +++ b/workstreams/Opaque_Pointers_Workstream.md @@ -0,0 +1,98 @@ +# Workstream: Opaque Pointer Support + +## Motivation & Benefits + +Support for typed pointers in LLVM is being removed. More information about the +motivation for this change can be found in LLVM forums. For example, the LLVM +documentation on [opaque pointers](https://llvm.org/docs/OpaquePointers.html) as +well as [this +presentation](https://llvm.org/devmtg/2022-04-03/slides/keynote.Opaque.Pointers.Are.Coming.pdf) +give a brief overview. + +The QIR specification currently makes use of typed pointers to represent qubit +values and result values. While in LLVM 15, support for these types can still be +enabled, an update to LLVM 16 requires us to change this representation. + +The goal of this workstream is hence to update the QIR specification to support +newer versions of LLVM, and to document what LLVM versions can be used to +support each version of the QIR specification. + +## Requirements + +Generally, LLVM maintains very good [backwards +compatibility](https://llvm.org/docs/DeveloperPolicy.html#ir-backwards-compatibility); +according to the LLVM 18 docs, it is possible to load even bitcode generate by +an LLVM version as early as 3.0. However, it is not possible in general to +generate bitcode that can be loaded with an older version of LLVM than the one +used to emit it. This means that while *QIR consumers*, i.e. backend providers, +can update to the latest LLVM version without sacrificing support for prior QIR +versions, whereas *QIR producers*, i.e. language frontends, cannot use LLVM +versions that are newer than the one required by the versions of the QIR +specification they support. This can pose challenges for maintaining a +state-of-the art frontend. + +As part of this workstream, we hence specifically propose to update the required +LLVM version for the next version of the QIR specification to LLVM 16. + +## Dependencies & Related Projects + +There are no related projects within the QIR Alliance at this time. However, +there are a number of threads in the LLVM community by projects with similar +needs. In particular, the considerations discussed in [this +thread](https://discourse.llvm.org/t/rfc-better-support-for-typed-pointers-in-an-opaque-pointer-world/63339) +and the follow up +[here](https://discourse.llvm.org/t/rfc-adding-opaque-types-to-llvm-ir/65326) +also apply to the QIR ecosystem. + +See also the section on [Open Questions](#open-questions) regarding possible +alternatives to consider. + +A related topic to consider when discussing options for this workstream is +whether the new representation would also allow to support qudits in the future. + +## Deliverable(s) & Expected Outcome + +The expected outcome of the workstream is a pull request to update the 0.1 +version of the QIR specification with the necessary changes to be able to emit +the full QIR and all its profile using LLVM 16. + +## Future Work (Out of Scope) + +Migration plan for shared components? + +## Working Group & Getting Involved + +Members:
+Chair: + +If you would like to contribute to the workstream, please contact \. + +## Schedule + +Launch date:
+Estimated end date:
+Meeting schedule and/or channel(s) of communication: + +## Status & Discussions + +The work and status is tracked in the form of a GitHub issue \. +
+We encourage comments, inputs, and discussions on that issue. + +The GitHub issue is labeled as `Approved` after approval by the steering +committee. + +## Open Questions + +As part of the workstream, we could re-examine the use of address spaces to +distinguish memory on the QPU itself (i.e. qubits) from memory located on an +adjacent classical processor. See also [this +thread](https://discourse.llvm.org/t/casting-between-address-spaces-and-address-space-semantics/10920/16) +that contains a discussion about the nature and use of different address spaces. + +There may be options to consider for representing quantum specific data types, +and merely migrating from typed to opaque pointers may not be the best option. +E.g. the working group should consider if it is desirable at all to work with +pointers, especially since the QIR specification prohibits dereferencing of +resources that are located on the QPU. From ae75eb819ee0ac69a6cdeed31965ec075ac54421 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 15 Nov 2023 19:47:01 +0100 Subject: [PATCH 2/6] Update Opaque_Pointers_Workstream.md --- workstreams/Opaque_Pointers_Workstream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workstreams/Opaque_Pointers_Workstream.md b/workstreams/Opaque_Pointers_Workstream.md index 89f8665..ee17582 100644 --- a/workstreams/Opaque_Pointers_Workstream.md +++ b/workstreams/Opaque_Pointers_Workstream.md @@ -32,7 +32,7 @@ specification they support. This can pose challenges for maintaining a state-of-the art frontend. As part of this workstream, we hence specifically propose to update the required -LLVM version for the next version of the QIR specification to LLVM 16. +LLVM version for the next version of the QIR specification to LLVM 17. ## Dependencies & Related Projects From 33c39d4fce2a8f0b605ac4414361ab35e1c51bc8 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 15 Nov 2023 19:54:34 +0100 Subject: [PATCH 3/6] Update Opaque_Pointers_Workstream.md --- workstreams/Opaque_Pointers_Workstream.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/workstreams/Opaque_Pointers_Workstream.md b/workstreams/Opaque_Pointers_Workstream.md index ee17582..4332dd0 100644 --- a/workstreams/Opaque_Pointers_Workstream.md +++ b/workstreams/Opaque_Pointers_Workstream.md @@ -54,11 +54,18 @@ whether the new representation would also allow to support qudits in the future. The expected outcome of the workstream is a pull request to update the 0.1 version of the QIR specification with the necessary changes to be able to emit -the full QIR and all its profile using LLVM 16. +the full QIR and all its profile using LLVM 17. +Additionally, the working group should outline a migration plan/recommendation +for front- and backend implementers to migrate from supporting the current 0.1 version +of the spec to the new version supporting LLVM 17. This migration plan could for +example involve the creation of helper scripts and tools that would convert a +0.1 compliant representation to the new representation and vice versa. ## Future Work (Out of Scope) -Migration plan for shared components? +We look for a recommendation by the working group whether +adding support for qudits and non-binary measurement results should +be discussed and fleshed out by this workstream, or deferred to a separate one. ## Working Group & Getting Involved From 86d0115f5a39d37d58ec68697b3163161887a941 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 15 Nov 2023 19:55:06 +0100 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Eric Schweitz Co-authored-by: Kalan <22137047+kalzoo@users.noreply.github.com> --- workstreams/Opaque_Pointers_Workstream.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/workstreams/Opaque_Pointers_Workstream.md b/workstreams/Opaque_Pointers_Workstream.md index 4332dd0..ef09829 100644 --- a/workstreams/Opaque_Pointers_Workstream.md +++ b/workstreams/Opaque_Pointers_Workstream.md @@ -2,7 +2,7 @@ ## Motivation & Benefits -Support for typed pointers in LLVM is being removed. More information about the +Support for typed pointers in LLVM has been removed. More information about the motivation for this change can be found in LLVM forums. For example, the LLVM documentation on [opaque pointers](https://llvm.org/docs/OpaquePointers.html) as well as [this @@ -21,15 +21,15 @@ support each version of the QIR specification. Generally, LLVM maintains very good [backwards compatibility](https://llvm.org/docs/DeveloperPolicy.html#ir-backwards-compatibility); -according to the LLVM 18 docs, it is possible to load even bitcode generate by +according to the LLVM 18 docs, it is possible to load even bitcode generated by an LLVM version as early as 3.0. However, it is not possible in general to generate bitcode that can be loaded with an older version of LLVM than the one used to emit it. This means that while *QIR consumers*, i.e. backend providers, can update to the latest LLVM version without sacrificing support for prior QIR -versions, whereas *QIR producers*, i.e. language frontends, cannot use LLVM +versions, *QIR producers*, i.e. language frontends, cannot use LLVM versions that are newer than the one required by the versions of the QIR specification they support. This can pose challenges for maintaining a -state-of-the art frontend. +state-of-the-art front end. As part of this workstream, we hence specifically propose to update the required LLVM version for the next version of the QIR specification to LLVM 17. From 93877a41e45ca3b503a9314d4f9a795ea4300241 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 15 Nov 2023 19:58:32 +0100 Subject: [PATCH 5/6] Update Opaque_Pointers_Workstream.md --- workstreams/Opaque_Pointers_Workstream.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workstreams/Opaque_Pointers_Workstream.md b/workstreams/Opaque_Pointers_Workstream.md index ef09829..f99c0ea 100644 --- a/workstreams/Opaque_Pointers_Workstream.md +++ b/workstreams/Opaque_Pointers_Workstream.md @@ -10,8 +10,8 @@ presentation](https://llvm.org/devmtg/2022-04-03/slides/keynote.Opaque.Pointers. give a brief overview. The QIR specification currently makes use of typed pointers to represent qubit -values and result values. While in LLVM 15, support for these types can still be -enabled, an update to LLVM 16 requires us to change this representation. +values and result values. While in LLVM 16, support for these types can still be +enabled, an update to LLVM 17 requires us to change this representation. The goal of this workstream is hence to update the QIR specification to support newer versions of LLVM, and to document what LLVM versions can be used to From de26dcaed46ab09fdff313dd106ee98eb336f261 Mon Sep 17 00:00:00 2001 From: Bettina Heim Date: Wed, 15 Nov 2023 19:59:03 +0100 Subject: [PATCH 6/6] Update Opaque_Pointers_Workstream.md --- workstreams/Opaque_Pointers_Workstream.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/workstreams/Opaque_Pointers_Workstream.md b/workstreams/Opaque_Pointers_Workstream.md index f99c0ea..5a09b01 100644 --- a/workstreams/Opaque_Pointers_Workstream.md +++ b/workstreams/Opaque_Pointers_Workstream.md @@ -54,7 +54,7 @@ whether the new representation would also allow to support qudits in the future. The expected outcome of the workstream is a pull request to update the 0.1 version of the QIR specification with the necessary changes to be able to emit -the full QIR and all its profile using LLVM 17. +the full QIR and all its profiles using LLVM 17. Additionally, the working group should outline a migration plan/recommendation for front- and backend implementers to migrate from supporting the current 0.1 version of the spec to the new version supporting LLVM 17. This migration plan could for