You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add safe Python-extension module C API headers (#15762)
* Add safe Python-extension module C API headers
With the vtables now compiled into the `_accelerate` object and stored
in suitable `PyCapsule`s, the last step to exposing the complete ability
to compile Python extension modules is providing header-file support for
actually using the result. This support is modelled on NumPy.
We generate alternate versions of the function declarations as part of
the `pyext` build script, which are loaded (instead of the standard
function prototypes) when the `QISKIT_PYTHON_EXTENSION` macro is set
prior to the inclusion of `qiskit.h`. These declarations are all
pre-processor macros that resolve to compile-time constant offset
lookups into the vtables stored in the `PyCapsule`s, except we cache the
internal pointer of each `PyCapsule` into a compilation-unit-local
`static`. If we didn't have this cache, _all_ function calls would have
Python-API overhead and require an attached Python thread state (holding
the GIL).
The cache population is done by a new header-only function `qk_import`
defined in (the non-stub version of) `funcs_py.h`, which then must be
called _before_ any C API function. This will almost invariably be done
inside the `PyInit_*` module-initialisation function of the extension.
The cache mechanism introduced in this commit is local to a single
translation unit. It is possible to extend this to allow sharing it
between different translation units, but since this necessarily requires
exposing a non-`static` symbol out of a library, we will have to take
care to do it with a mechanism that allows the user to override the
names used.
* Remove `dbg!` call from build script
* Remove unneeded `pyo3-build-config` dependence
* Fix typos
Co-authored-by: Max Rossmannek <21973473+mrossinek@users.noreply.github.com>
Co-authored-by: Jake Lishman <jake@binhbar.com>
---------
Co-authored-by: Max Rossmannek <21973473+mrossinek@users.noreply.github.com>
0 commit comments