Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions docs/doc_sources/api_reference/dpctl/program.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ execution via :py:meth:`dpctl.SyclQueue.submit`.
:toctree: generated
:nosignatures:

create_kernel_bundle_from_source
create_kernel_bundle_from_spirv
create_program_from_source
create_program_from_spirv

.. autosummary::
:toctree: generated
:nosignatures:

SyclProgram
SyclKernelBundle
SyclKernel

.. autosummary::
:toctree: generated
:nosignatures:

SyclProgramCompilationError
SyclKernelBundleCompilationError
12 changes: 6 additions & 6 deletions docs/doc_sources/api_reference/dpctl_capi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ Exported typedefs

.. c:struct:: PySyclKernelType

.. c:struct:: PySyclProgramObject
.. c:struct:: PySyclKernelBundleObject

.. c:struct:: PySyclProgramType
.. c:struct:: PySyclKernelBundleType

To check whether a particular Python object is an instance of :py:class:`dpctl.SyclQueue`:

Expand Down Expand Up @@ -176,19 +176,19 @@ API for :c:struct:`PySyclKernelObject`
the caller remains responsible for freeing ``KRef`` as appropriate.


API for :c:struct:`PySyclProgramObject`
API for :c:struct:`PySyclKernelBundleObject`
---------------------------------------

.. c:function:: DPCTLSyclKernelBundleRef SyclProgram_GetKernelBundleRef(struct PySyclProgramObject *prog)
.. c:function:: DPCTLSyclKernelBundleRef SyclKernelBundle_GetKernelBundleRef(struct PySyclKernelBundleObject *prog)

:param prog: Input object
:returns: borrowed instance of :c:struct:`DPCTLSyclKernelBundleRef` corresponding
to ``sycl::kernel_bundle<sycl::bundle_state::executable>``

.. c:function:: struct PySyclProgramObject * SyclProgram_Make(DPCTLSyclKernelBundleRef KBRef)
.. c:function:: struct PySyclKernelBundleObject * SyclKernelBundle_Make(DPCTLSyclKernelBundleRef KBRef)

:param KBRef: instance of :c:struct:`DPCTLSyclKernelBundleRef`
:returns: new Python object of type :c:struct:`PySyclProgramType`
:returns: new Python object of type :c:struct:`PySyclKernelBundleType`

Note that function does not change the ownership of the ``KBRef`` instance and
the caller remains responsible for freeing ``KBRef`` as appropriate.
1 change: 1 addition & 0 deletions docs/doc_sources/known_words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ SyclQueue
SyclContext
SyclEvent
SyclKernel
SyclKernelBundle
SyclProgram
SyclPlatform
dtype
Expand Down
41 changes: 22 additions & 19 deletions dpctl/apis/include/dpctl4pybind11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class dpctl_capi
PyTypeObject *PyMemoryUSMDeviceType_;
PyTypeObject *PyMemoryUSMSharedType_;
PyTypeObject *PyMemoryUSMHostType_;
PyTypeObject *PySyclProgramType_;
PyTypeObject *PySyclKernelBundleType_;
PyTypeObject *PySyclKernelType_;

DPCTLSyclDeviceRef (*SyclDevice_GetDeviceRef_)(PySyclDeviceObject *);
Expand Down Expand Up @@ -89,9 +89,10 @@ class dpctl_capi
DPCTLSyclKernelRef (*SyclKernel_GetKernelRef_)(PySyclKernelObject *);
PySyclKernelObject *(*SyclKernel_Make_)(DPCTLSyclKernelRef, const char *);

DPCTLSyclKernelBundleRef (*SyclProgram_GetKernelBundleRef_)(
PySyclProgramObject *);
PySyclProgramObject *(*SyclProgram_Make_)(DPCTLSyclKernelBundleRef);
DPCTLSyclKernelBundleRef (*SyclKernelBundle_GetKernelBundleRef_)(
PySyclKernelBundleObject *);
PySyclKernelBundleObject *(*SyclKernelBundle_Make_)(
DPCTLSyclKernelBundleRef);

bool PySyclDevice_Check_(PyObject *obj) const
{
Expand All @@ -113,9 +114,9 @@ class dpctl_capi
{
return PyObject_TypeCheck(obj, PySyclKernelType_) != 0;
}
bool PySyclProgram_Check_(PyObject *obj) const
bool PySyclKernelBundle_Check_(PyObject *obj) const
{
return PyObject_TypeCheck(obj, PySyclProgramType_) != 0;
return PyObject_TypeCheck(obj, PySyclKernelBundleType_) != 0;
}

~dpctl_capi()
Expand Down Expand Up @@ -165,7 +166,7 @@ class dpctl_capi
Py_SyclQueueType_(nullptr), PySyclQueueType_(nullptr),
Py_MemoryType_(nullptr), PyMemoryUSMDeviceType_(nullptr),
PyMemoryUSMSharedType_(nullptr), PyMemoryUSMHostType_(nullptr),
PySyclProgramType_(nullptr), PySyclKernelType_(nullptr),
PySyclKernelBundleType_(nullptr), PySyclKernelType_(nullptr),
SyclDevice_GetDeviceRef_(nullptr), SyclDevice_Make_(nullptr),
SyclContext_GetContextRef_(nullptr), SyclContext_Make_(nullptr),
SyclEvent_GetEventRef_(nullptr), SyclEvent_Make_(nullptr),
Expand All @@ -174,8 +175,9 @@ class dpctl_capi
Memory_GetContextRef_(nullptr), Memory_GetQueueRef_(nullptr),
Memory_GetNumBytes_(nullptr), Memory_Make_(nullptr),
SyclKernel_GetKernelRef_(nullptr), SyclKernel_Make_(nullptr),
SyclProgram_GetKernelBundleRef_(nullptr), SyclProgram_Make_(nullptr),
default_sycl_queue_{}, default_usm_memory_{}, as_usm_memory_{}
SyclKernelBundle_GetKernelBundleRef_(nullptr),
SyclKernelBundle_Make_(nullptr), default_sycl_queue_{},
default_usm_memory_{}, as_usm_memory_{}

{
// Import Cython-generated C-API for dpctl
Expand All @@ -198,7 +200,7 @@ class dpctl_capi
this->PyMemoryUSMDeviceType_ = &PyMemoryUSMDeviceType;
this->PyMemoryUSMSharedType_ = &PyMemoryUSMSharedType;
this->PyMemoryUSMHostType_ = &PyMemoryUSMHostType;
this->PySyclProgramType_ = &PySyclProgramType;
this->PySyclKernelBundleType_ = &PySyclKernelBundleType;
this->PySyclKernelType_ = &PySyclKernelType;

// SyclDevice API
Expand Down Expand Up @@ -228,8 +230,9 @@ class dpctl_capi
// dpctl.program API
this->SyclKernel_GetKernelRef_ = SyclKernel_GetKernelRef;
this->SyclKernel_Make_ = SyclKernel_Make;
this->SyclProgram_GetKernelBundleRef_ = SyclProgram_GetKernelBundleRef;
this->SyclProgram_Make_ = SyclProgram_Make;
this->SyclKernelBundle_GetKernelBundleRef_ =
SyclKernelBundle_GetKernelBundleRef;
this->SyclKernelBundle_Make_ = SyclKernelBundle_Make;

// create shared pointers to python objects used in type-casters
// for dpctl::memory::usm_memory
Expand Down Expand Up @@ -484,7 +487,7 @@ template <> struct type_caster<sycl::kernel>

/* This type caster associates
* ``sycl::kernel_bundle<sycl::bundle_state::executable>`` C++ class with
* :class:`dpctl.program.SyclProgram` for the purposes of generation of
* :class:`dpctl.program.SyclKernelBundle` for the purposes of generation of
* Python bindings by pybind11.
*/
template <>
Expand All @@ -495,10 +498,10 @@ struct type_caster<sycl::kernel_bundle<sycl::bundle_state::executable>>
{
PyObject *source = src.ptr();
auto const &api = ::dpctl::detail::dpctl_capi::get();
if (api.PySyclProgram_Check_(source)) {
if (api.PySyclKernelBundle_Check_(source)) {
DPCTLSyclKernelBundleRef KBRef =
api.SyclProgram_GetKernelBundleRef_(
reinterpret_cast<PySyclProgramObject *>(source));
api.SyclKernelBundle_GetKernelBundleRef_(
reinterpret_cast<PySyclKernelBundleObject *>(source));
value = std::make_unique<
sycl::kernel_bundle<sycl::bundle_state::executable>>(
*(reinterpret_cast<
Expand All @@ -508,7 +511,7 @@ struct type_caster<sycl::kernel_bundle<sycl::bundle_state::executable>>
}
else {
throw py::type_error("Input is of unexpected type, expected "
"dpctl.program.SyclProgram");
"dpctl.program.SyclKernelBundle");
}
}

Expand All @@ -517,13 +520,13 @@ struct type_caster<sycl::kernel_bundle<sycl::bundle_state::executable>>
handle)
{
auto const &api = ::dpctl::detail::dpctl_capi::get();
auto tmp = api.SyclProgram_Make_(
auto tmp = api.SyclKernelBundle_Make_(
reinterpret_cast<DPCTLSyclKernelBundleRef>(&src));
return handle(reinterpret_cast<PyObject *>(tmp));
}

DPCTL_TYPE_CASTER(sycl::kernel_bundle<sycl::bundle_state::executable>,
_("dpctl.program.SyclProgram"));
_("dpctl.program.SyclKernelBundle"));
};

/* This type caster associates
Expand Down
25 changes: 22 additions & 3 deletions dpctl/program/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,35 @@

from ._program import (
SyclKernel,
SyclProgram,
SyclProgramCompilationError,
SyclKernelBundle,
SyclKernelBundleCompilationError,
create_kernel_bundle_from_source,
create_kernel_bundle_from_spirv,
create_program_from_source,
create_program_from_spirv,
)

__all__ = [
"create_kernel_bundle_from_source",
"create_kernel_bundle_from_spirv",
"create_program_from_source",
"create_program_from_spirv",
"SyclKernel",
"SyclKernelBundle",
"SyclKernelBundleCompilationError",
"SyclProgram",
"SyclProgramCompilationError",
]


def __getattr__(name):
if name == "SyclProgram":
from warnings import warn

warn(
"dpctl.program.SyclProgram is deprecated and will be removed in a "
"future release. Use dpctl.program.SyclKernelBundle instead.",
DeprecationWarning,
stacklevel=2,
)
return SyclKernelBundle
raise AttributeError(f"module {__name__} has no attribute {name}")
26 changes: 18 additions & 8 deletions dpctl/program/_program.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,32 @@ cdef api class SyclKernel [object PySyclKernelObject, type PySyclKernelType]:
cdef SyclKernel _create (DPCTLSyclKernelRef kref, str name)


cdef api class SyclProgram [object PySyclProgramObject, type PySyclProgramType]:
cdef api class SyclKernelBundle [
object PySyclKernelBundleObject, type PySyclKernelBundleType
]:
"""
Wraps a sycl::kernel_bundle<sycl::bundle_state::executable> object created
by using SYCL interoperability layer for OpenCL and Level-Zero backends.
SyclProgram exposes the C API from dpctl_sycl_kernel_bundle_interface.h.
A SyclProgram can be created from either a source string or a SPIR-V
SyclKernelBundle exposes the C API from
dpctl_sycl_kernel_bundle_interface.h.
A SyclKernelBundle can be created from either a source string or a SPIR-V
binary file.
"""
cdef DPCTLSyclKernelBundleRef _program_ref
cdef DPCTLSyclKernelBundleRef _kernel_bundle_ref

@staticmethod
cdef SyclProgram _create (DPCTLSyclKernelBundleRef pref)
cdef DPCTLSyclKernelBundleRef get_program_ref (self)
cdef SyclKernelBundle _create (DPCTLSyclKernelBundleRef kbref)
cdef DPCTLSyclKernelBundleRef get_kernel_bundle_ref (self)
cpdef SyclKernel get_sycl_kernel(self, str kernel_name)


cpdef create_kernel_bundle_from_source (
SyclQueue q, unicode source, unicode copts=*
)
cpdef create_kernel_bundle_from_spirv (
SyclQueue q, const unsigned char[:] IL, unicode copts=*
)
cpdef create_program_from_source (SyclQueue q, unicode source, unicode copts=*)
cpdef create_program_from_spirv (SyclQueue q, const unsigned char[:] IL,
unicode copts=*)
cpdef create_program_from_spirv (
SyclQueue q, const unsigned char[:] IL, unicode copts=*
)
Loading
Loading