xpu: support py_limited_api with SyclExtension

Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
This commit is contained in:
Dmitry Rogozhkin 2025-01-27 23:17:44 +00:00
parent 1df103e823
commit 05193ab582

View file

@ -1329,6 +1329,15 @@ def SyclExtension(name, sources, *args, **kwargs):
All arguments are forwarded to the :class:`setuptools.Extension`
constructor.
.. note::
The PyTorch python API (as provided in libtorch_python) cannot be built
with the flag ``py_limited_api=True``. When this flag is passed, it is
the user's responsibility in their library to not use APIs from
libtorch_python (in particular pytorch/python bindings) and to only use
APIs from libtorch (aten objects, operators and the dispatcher). For
example, to give access to custom ops from python, the library should
register the ops through the dispatcher.
Example:
>>> # xdoctest: +SKIP
>>> # xdoctest: +REQUIRES(env:TORCH_DOCTEST_CPP_EXT)
@ -1367,7 +1376,9 @@ def SyclExtension(name, sources, *args, **kwargs):
libraries.append("c10_xpu")
libraries.append("torch")
libraries.append("torch_cpu")
libraries.append("torch_python")
if not kwargs.get('py_limited_api', False):
# torch_python uses more than the python limited api
libraries.append("torch_python")
libraries.append("torch_xpu")
kwargs["libraries"] = libraries