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

Runtime Initialization, Finalization, and EntryPoint Handling Workstream Definition #18

Merged
merged 9 commits into from
May 25, 2022
5 changes: 5 additions & 0 deletions profile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ discussed:
definition](https://github.com/qir-alliance/.github/blob/main/workstreams/Base_Profile_Workstream.md),
[GitHub issue](https://github.com/qir-alliance/.github/issues/15)]

- Runtime initialization, finalization, and entry-Point marking and runtime
amccaskey marked this conversation as resolved.
Show resolved Hide resolved
parameter input <br/> [[workstream
definition](https://github.com/amccaskey/.github/blob/main/workstreams/Runtime_Init_Finalize_EntryPoint_Workstream.md),
[GitHub issue](https://github.com/qir-alliance/.github/issues/16)]

### Steering Committee

Steering members include Microsoft, Oak Ridge National Laboratory, Quantinuum,
Expand Down
102 changes: 102 additions & 0 deletions workstreams/Runtime_Init_Finalize_EntryPoint_Workstream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Workstream: Runtime Initialization, Finalization, and Entry-Point Handling

## Motivation & Benefits

QIR implementation libraries provided at link time may need to rely on library
start-up and finalization routines in order to properly configure and tear-down
an underlying simulation and / or remote job submission infrastructure. QIR for
native code-generation or as an exchange format with control systems may also
require some notion of start-up, initialization, and tear-down.

Runtime initialization raises the question of how QIR lowering strategies
should specify entry point functions and corresponding input data provided
at runtime. For runtime library linking, the notion of input `argc` and
`argv` can be a valuable asset to designing dynamic and flexible QIR
runtimes. For QIR as a format for backend submission, the specification
needs to carefully define what an entrypoint function is and how packaged
runtime arguments (command line or otherwise) can be injected into the
entrypoint at executable start-up.

## Requirements

The specification should define runtime initialization as a set of overloaded
functions with a prescribed function name. The functions differ by argument
structure, can take the usual `(int, int8_t**)`, no arguments to indicate
default initialization, or any other pertinent structure this proposed
workstream decides on.

The specification should define a finalization function declaration that
takes no arguments and is responsible for freeing all leveraged classical
and quantum resources at program exit.

For the case of runtime library linking, initialization and finalization may
also be required of quantum functions that are invoked from host code. Library
implementors may require the declaration of fine-grained function
initialization and finalization routines that QIR generators may insert at
the beginning of and end of these quantum function calls invoked from host
call-sites. The utility of this type of function-level functionality in the
support of near-term remote job submission and flushing internal quantum
instruction queues, as well as general callbacks for library runtime
event systems.

This workstream will define how QIR generators should mark a function as
EntryPoint. QIR generators can mark exactly one function as `EntryPoint`
via an LLVM attribute. The function can be described with any valid function
name. If there aren't any functions marked as `EntryPoint` then a `main`
function must be present to enable execution. For custom `EntryPoint`
functions an appropriate LLVM Pass must be applied to introduce a `__start`
or `__main` function that calls the original entry point function.

Use cases may exist whereby QIR code is generated with a custom EntryPoint and
needs to be executed with custom command line arguments that should serve as
input to that EntryPoint function. The specification needs to define some
specified way to map custom command line arguments of a general type to the
input arguments of the function, as well as the introduction of a `main`
function for the underlying C runtime to pick up for execution.

## Dependencies & Related Projects

A related workstream is to specify a base profile of the full specification.
This work should ensure that future base profile work is also compliant with
amccaskey marked this conversation as resolved.
Show resolved Hide resolved
entrypoint definitions and runtime input, finalization, and parameterization.

## Deliverable(s) & Expected Outcome

The expected outcome of this workstream is an update to the existing QIR
specification documentation that defines specific function declarations
for program-level initialization and finalization, function-level
initialization and finalization for quantum functions invoked from host
call sites, and entry-point marker metadata and runtime parameter input.

## Future Work (Out of Scope)

This work will not define specific initialization or finalization tasks
that a QIR implementation library should perform.

## Working Group & Getting Involved

Working group participants: TBD <br/>
Working group chair: Alex McCaskey

If you would like to contribute to the workstream, please contact
[[email protected]](mailto:[email protected]).

## Schedule

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

## Status & Discussions

Current status: Workstream to be approved by steering committee
amccaskey marked this conversation as resolved.
Show resolved Hide resolved

The work and status will be tracked in the form of a [GitHub
amccaskey marked this conversation as resolved.
Show resolved Hide resolved
issue](https://github.com/qir-alliance/qir-spec/issues) on the [specification
repository](https://github.com/qir-alliance/qir-spec). We encourage comments,
inputs, and discussions on that issue.

The GitHub issue with be tagged appropriately after approval by the steering
amccaskey marked this conversation as resolved.
Show resolved Hide resolved
committee.

## Open Questions
dan1pal marked this conversation as resolved.
Show resolved Hide resolved