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

Opaque Pointer workstream definition #42

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions workstreams/Opaque_Pointers_Workstream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Workstream: Opaque Pointer Support

## Motivation & Benefits

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
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 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
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 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, *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 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.

## 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 profiles using LLVM 17.
Additionally, the working group should outline a migration plan/recommendation

Check warning on line 58 in workstreams/Opaque_Pointers_Workstream.md

View workflow job for this annotation

GitHub Actions / Check spelling, linting and links

Trailing spaces [Expected: 0 or 2; Actual: 1]
for front- and backend implementers to migrate from supporting the current 0.1 version

Check warning on line 59 in workstreams/Opaque_Pointers_Workstream.md

View workflow job for this annotation

GitHub Actions / Check spelling, linting and links

Trailing spaces [Expected: 0 or 2; Actual: 1]

Check warning on line 59 in workstreams/Opaque_Pointers_Workstream.md

View workflow job for this annotation

GitHub Actions / Check spelling, linting and links

Line length [Expected: 80; Actual: 87]
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

Check warning on line 61 in workstreams/Opaque_Pointers_Workstream.md

View workflow job for this annotation

GitHub Actions / Check spelling, linting and links

Trailing spaces [Expected: 0 or 2; Actual: 1]
0.1 compliant representation to the new representation and vice versa.

## Future Work (Out of Scope)

We look for a recommendation by the working group whether

Check warning on line 66 in workstreams/Opaque_Pointers_Workstream.md

View workflow job for this annotation

GitHub Actions / Check spelling, linting and links

Trailing spaces [Expected: 0 or 2; Actual: 1]
adding support for qudits and non-binary measurement results should

Check warning on line 67 in workstreams/Opaque_Pointers_Workstream.md

View workflow job for this annotation

GitHub Actions / Check spelling, linting and links

Trailing spaces [Expected: 0 or 2; Actual: 1]
be discussed and fleshed out by this workstream, or deferred to a separate one.

## Working Group & Getting Involved

Members: <br/>
Chair:

If you would like to contribute to the workstream, please contact \<insert
contact\>.

## Schedule

Launch date: <br/>
Estimated end date: <br/>
Meeting schedule and/or channel(s) of communication:

## Status & Discussions

The work and status is tracked in the form of a GitHub issue \<insert link\>.
<br/>
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.
Loading