@@ -71,6 +71,8 @@ struct dpctl_capi
7171 PyTypeObject * PyMemoryUSMSharedType_ ;
7272 PyTypeObject * PyMemoryUSMHostType_ ;
7373 PyTypeObject * PyUSMArrayType_ ;
74+ PyTypeObject * PySyclProgramType_ ;
75+ PyTypeObject * PySyclKernelType_ ;
7476
7577 DPCTLSyclDeviceRef (* SyclDevice_GetDeviceRef_ )(PySyclDeviceObject * );
7678 PySyclDeviceObject * (* SyclDevice_Make_ )(DPCTLSyclDeviceRef );
@@ -94,6 +96,13 @@ struct dpctl_capi
9496 DPCTLSyclQueueRef ,
9597 PyObject * );
9698
99+ // program
100+ DPCTLSyclKernelRef (* SyclKernel_GetKernelRef_ )(PySyclKernelObject * );
101+ PySyclKernelObject * (* SyclKernel_Make_ )(DPCTLSyclKernelRef );
102+
103+ DPCTLSyclKernelBundleRef (* SyclProgram_GetKernelBundleRef_ )(PySyclProgramObject * );
104+ PySyclProgramObject * (* SyclProgram_Make_ )(DPCTLSyclKernelBundleRef );
105+
97106 // tensor
98107 char * (* UsmNDArray_GetData_ )(PyUSMArrayObject * );
99108 int (* UsmNDArray_GetNDim_ )(PyUSMArrayObject * );
@@ -131,6 +140,14 @@ struct dpctl_capi
131140 {
132141 return PyObject_TypeCheck (obj , PySyclQueueType_ ) != 0 ;
133142 }
143+ bool PySyclKernel_Check_ (PyObject * obj ) const
144+ {
145+ return PyObject_TypeCheck (obj , PySyclKernelType_ ) != 0 ;
146+ }
147+ bool PySyclProgram_Check_ (PyObject * obj ) const
148+ {
149+ return PyObject_TypeCheck (obj , PySyclProgramType_ ) != 0 ;
150+ }
134151
135152 ~dpctl_capi (){};
136153
@@ -174,6 +191,8 @@ struct dpctl_capi
174191 std ::shared_ptr < py ::object > default_usm_memory ;
175192 std ::shared_ptr < py ::object > default_usm_ndarray ;
176193 std ::shared_ptr < py ::object > as_usm_memory ;
194+ std ::shared_ptr < py ::object > default_sycl_kernel ;
195+ std ::shared_ptr < py ::object > default_sycl_program ;
177196
178197 dpctl_capi ()
179198 : default_sycl_queue {}, default_usm_memory {}, default_usm_ndarray {},
@@ -201,6 +220,8 @@ struct dpctl_capi
201220 this -> PyMemoryUSMSharedType_ = & PyMemoryUSMSharedType ;
202221 this -> PyMemoryUSMHostType_ = & PyMemoryUSMHostType ;
203222 this -> PyUSMArrayType_ = & PyUSMArrayType ;
223+ this -> PySyclProgramType_ = & PySyclProgramType ;
224+ this -> PySyclKernelType_ = & PySyclKernelType ;
204225
205226 // SyclDevice API
206227 this -> SyclDevice_GetDeviceRef_ = SyclDevice_GetDeviceRef ;
@@ -225,6 +246,10 @@ struct dpctl_capi
225246 this -> Memory_GetNumBytes_ = Memory_GetNumBytes ;
226247 this -> Memory_Make_ = Memory_Make ;
227248
249+ // dpctl.program API
250+ this -> SyclKernel_Make_ = SyclKernel_Make ;
251+ this -> SyclProgram_Make_ = SyclProgram_Make ;
252+
228253 // dpctl.tensor.usm_ndarray API
229254 this -> UsmNDArray_GetData_ = UsmNDArray_GetData ;
230255 this -> UsmNDArray_GetNDim_ = UsmNDArray_GetNDim ;
@@ -506,6 +531,76 @@ template <> struct type_caster<sycl::event>
506531
507532 DPCTL_TYPE_CASTER (sycl ::event , _ ("dpctl.SyclEvent" ));
508533};
534+
535+ /* This type caster associates ``sycl::kernel`` C++ class with
536+ * :class:`dpctl.program.SyclKernel` for the purposes of generation of
537+ * Python bindings by pybind11.
538+ */
539+ template < > struct type_caster < sycl ::kernel >
540+ {
541+ public :
542+ bool load (handle src , bool )
543+ {
544+ PyObject * source = src .ptr ();
545+ auto & api = ::dpctl ::detail ::dpctl_capi ::get ();
546+ if (api .PySyclKernel_Check_ (source )) {
547+ DPCTLSyclKernelRef KRef = api .SyclKernel_GetKernelRef_ (
548+ reinterpret_cast < PySyclKernelObject * > (source ));
549+ value = std ::make_unique < sycl ::kernel > (
550+ * (reinterpret_cast < sycl ::kernel * > (KRef )));
551+ return true;
552+ }
553+ else {
554+ throw py ::type_error (
555+ "Input is of unexpected type, expected dpctl.program.SyclKernel" );
556+ }
557+ }
558+
559+ static handle cast (sycl ::kernel src , return_value_policy , handle )
560+ {
561+ auto & api = ::dpctl ::detail ::dpctl_capi ::get ();
562+ auto tmp =
563+ api .SyclKernel_Make_ (reinterpret_cast < DPCTLSyclKernelRef > (& src ));
564+ return handle (reinterpret_cast < PyObject * > (tmp ));
565+ }
566+
567+ DPCTL_TYPE_CASTER (sycl ::kernel , _ ("dpctl.program.SyclKernel" ));
568+ };
569+
570+ /* This type caster associates ``sycl::kernel_bundle<sycl::bundle_state::executable>`` C++ class with
571+ * :class:`dpctl.program.SyclProgram` for the purposes of generation of
572+ * Python bindings by pybind11.
573+ */
574+ template < > struct type_caster < sycl ::kernel_bundle < sycl ::bundle_state ::executable >>
575+ {
576+ public :
577+ bool load (handle src , bool )
578+ {
579+ PyObject * source = src .ptr ();
580+ auto & api = ::dpctl ::detail ::dpctl_capi ::get ();
581+ if (api .PySyclProgram_Check_ (source )) {
582+ DPCTLSyclKernelBundleRef KBRef = api .SyclProgram_GetKernelBundleRef_ (
583+ reinterpret_cast < PySyclProgramObject * > (source ));
584+ value = std ::make_unique < sycl ::kernel_bundle < sycl ::bundle_state ::executable >>(
585+ * (reinterpret_cast < sycl ::kernel_bundle < sycl ::bundle_state ::executable > * > (KBRef )));
586+ return true;
587+ }
588+ else {
589+ throw py ::type_error (
590+ "Input is of unexpected type, expected dpctl.SyclEvent" );
591+ }
592+ }
593+
594+ static handle cast (sycl ::kernel_bundle < sycl ::bundle_state ::executable > src , return_value_policy , handle )
595+ {
596+ auto & api = ::dpctl ::detail ::dpctl_capi ::get ();
597+ auto tmp =
598+ api .SyclProgram_Make_ (reinterpret_cast < DPCTLSyclKernelBundleRef > (& src ));
599+ return handle (reinterpret_cast < PyObject * > (tmp ));
600+ }
601+
602+ DPCTL_TYPE_CASTER (sycl ::kernel_bundle < sycl ::bundle_state ::executable > , _ ("dpctl.program.SyclProgram" ));
603+ };
509604} // namespace detail
510605} // namespace pybind11
511606
0 commit comments