Skip to content

Commit c8ba5ee

Browse files
authored
Merge pull request #2206 from IntelPython/feature/sycl-source-compilation
Support SYCL source compilation
2 parents c74de01 + 4de6d72 commit c8ba5ee

15 files changed

Lines changed: 1447 additions & 40 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
* `dpctl.SyclQueue.copy` and `dpctl.SyclQueue.copy_async` methods [gh-2273](https://github.com/IntelPython/dpctl/pull/2273)
1111
* Added a number of `sycl::device` info queries to `dpctl.SyclDevice` [gh-2324](https://github.com/IntelPython/dpctl/pull/2324)
1212
* Added `sycl::info::context` queries `sycl_platform`, `atomic_memory_order_capabilities`, `atomic_fence_order_capabilities`, `atomic_memory_scope_capabilities`, and `atomic_fence_scope_capabilities` to `dpctl.SyclContext` [gh-2354](https://github.com/IntelPython/dpctl/pull/2354)
13+
* Added `create_kernel_bundle_from_sycl_source`, `is_sycl_source_compilation_available`, and `dpctl.SyclDevice.can_compile` for supporting the creation of `dpctl.SyclKernelBundle`s from SYCL source strings via DPC++ extension, as well as corresponding C-API functions to support it [gh-2206](https://github.com/IntelPython/dpctl/pull/2206)
1314

1415
### Changed
1516
* Bump minimum NumPy version to 1.26 [gh-2192](https://github.com/IntelPython/dpctl/pull/2192)

docs/doc_sources/api_reference/dpctl/program.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
=======================
55

66
:py:mod:`dpctl.program` provides a way to create a SYCL kernel
7-
from either an OpenCL* program source code represented as a string
8-
or a SPIR-V binary file.
7+
from an OpenCL* program source code represented as a string, SYCL
8+
source code represented as a string, or a SPIR-V binary file.
99

1010
It implements creation of interoperability
1111
``sycl::kernel_bundle<sycl::bundle_state_executable>`` (a collection of kernels),
@@ -22,8 +22,10 @@ execution via :py:meth:`dpctl.SyclQueue.submit`.
2222

2323
create_kernel_bundle_from_source
2424
create_kernel_bundle_from_spirv
25+
create_kernel_bundle_from_sycl_source
2526
create_program_from_source
2627
create_program_from_spirv
28+
is_sycl_source_compilation_available
2729

2830
.. autosummary::
2931
:toctree: generated

dpctl/_backend.pxd

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
328328
_peer_access PT)
329329
cdef void DPCTLDevice_EnablePeerAccess(const DPCTLSyclDeviceRef DRef,
330330
const DPCTLSyclDeviceRef PDRef)
331-
332331
cdef void DPCTLDevice_DisablePeerAccess(const DPCTLSyclDeviceRef DRef,
333332
const DPCTLSyclDeviceRef PDRef)
334333
cdef uint32_t DPCTLDevice_GetVendorId(const DPCTLSyclDeviceRef DRef)
@@ -371,6 +370,10 @@ cdef extern from "syclinterface/dpctl_sycl_device_interface.h":
371370
const DPCTLSyclDeviceRef DRef, size_t *res_len)
372371
cdef int *DPCTLDevice_GetPartitionAffinityDomains(
373372
const DPCTLSyclDeviceRef DRef, size_t *res_len)
373+
cdef bool DPCTLDevice_CanCompileSPIRV(const DPCTLSyclDeviceRef DRef)
374+
cdef bool DPCTLDevice_CanCompileOpenCL(const DPCTLSyclDeviceRef DRef)
375+
cdef bool DPCTLDevice_CanCompileSYCL(const DPCTLSyclDeviceRef DRef)
376+
374377

375378
cdef extern from "syclinterface/dpctl_sycl_device_manager.h":
376379
cdef DPCTLDeviceVectorRef DPCTLDeviceVector_CreateFromArray(
@@ -553,6 +556,53 @@ cdef extern from "syclinterface/dpctl_sycl_kernel_bundle_interface.h":
553556
cdef DPCTLSyclKernelBundleRef DPCTLKernelBundle_Copy(
554557
const DPCTLSyclKernelBundleRef KBRef)
555558

559+
cdef struct DPCTLBuildOptionList
560+
cdef struct DPCTLKernelNameList
561+
cdef struct DPCTLVirtualHeaderList
562+
cdef struct DPCTLKernelBuildLog
563+
ctypedef DPCTLBuildOptionList* DPCTLBuildOptionListRef
564+
ctypedef DPCTLKernelNameList* DPCTLKernelNameListRef
565+
ctypedef DPCTLVirtualHeaderList* DPCTLVirtualHeaderListRef
566+
ctypedef DPCTLKernelBuildLog* DPCTLKernelBuildLogRef
567+
568+
cdef DPCTLBuildOptionListRef DPCTLBuildOptionList_Create()
569+
cdef void DPCTLBuildOptionList_Delete(DPCTLBuildOptionListRef Ref)
570+
cdef void DPCTLBuildOptionList_Append(DPCTLBuildOptionListRef Ref,
571+
const char *Option)
572+
573+
cdef DPCTLKernelNameListRef DPCTLKernelNameList_Create()
574+
cdef void DPCTLKernelNameList_Delete(DPCTLKernelNameListRef Ref)
575+
cdef void DPCTLKernelNameList_Append(DPCTLKernelNameListRef Ref,
576+
const char *Option)
577+
578+
cdef DPCTLVirtualHeaderListRef DPCTLVirtualHeaderList_Create()
579+
cdef void DPCTLVirtualHeaderList_Delete(DPCTLVirtualHeaderListRef Ref)
580+
cdef void DPCTLVirtualHeaderList_Append(DPCTLVirtualHeaderListRef Ref,
581+
const char *Name,
582+
const char *Content)
583+
584+
cdef DPCTLKernelBuildLogRef DPCTLKernelBuildLog_Create()
585+
cdef void DPCTLKernelBuildLog_Delete(DPCTLKernelBuildLogRef Ref)
586+
cdef const char *DPCTLKernelBuildLog_Get(DPCTLKernelBuildLogRef)
587+
588+
cdef bool DPCTLKernelBundle_CreateFromSYCLSource_Available()
589+
590+
cdef DPCTLSyclKernelBundleRef DPCTLKernelBundle_CreateFromSYCLSource(
591+
const DPCTLSyclContextRef Ctx,
592+
const DPCTLSyclDeviceRef Dev,
593+
const char *Source,
594+
DPCTLVirtualHeaderListRef Headers,
595+
DPCTLKernelNameListRef Names,
596+
DPCTLBuildOptionListRef BuildOptions,
597+
DPCTLKernelBuildLogRef BuildLog)
598+
599+
cdef DPCTLSyclKernelRef DPCTLKernelBundle_GetSyclKernel(
600+
DPCTLSyclKernelBundleRef KBRef,
601+
const char *KernelName)
602+
603+
cdef bool DPCTLKernelBundle_HasSyclKernel(DPCTLSyclKernelBundleRef KBRef,
604+
const char *KernelName)
605+
556606

557607
cdef extern from "syclinterface/dpctl_sycl_queue_interface.h":
558608
ctypedef struct _md_local_accessor "MDLocalAccessor":

dpctl/_sycl_device.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ cdef public api class SyclDevice(_SyclDevice) [
6161
cdef int get_overall_ordinal(self)
6262
cdef int get_backend_ordinal(self)
6363
cdef int get_backend_and_device_type_ordinal(self)
64+
cpdef bint can_compile(self, str language)

dpctl/_sycl_device.pyx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ from ._backend cimport ( # noqa: E211
2727
DPCTLDefaultSelector_Create,
2828
DPCTLDevice_AreEq,
2929
DPCTLDevice_CanAccessPeer,
30+
DPCTLDevice_CanCompileOpenCL,
31+
DPCTLDevice_CanCompileSPIRV,
32+
DPCTLDevice_CanCompileSYCL,
3033
DPCTLDevice_Copy,
3134
DPCTLDevice_CreateFromSelector,
3235
DPCTLDevice_CreateSubDevicesByAffinity,
@@ -2854,6 +2857,34 @@ cdef class SyclDevice(_SyclDevice):
28542857
raise ValueError("device could not be found")
28552858
return dev_id
28562859

2860+
cpdef bint can_compile(self, str language):
2861+
"""
2862+
Check whether it is possible to create an executable kernel_bundle
2863+
for this device from the given source language.
2864+
2865+
Parameters:
2866+
language
2867+
Input language. Possible values are "spirv" or "spv" for
2868+
SPIR-V binary files, "opencl" or "ocl" for OpenCL C device code
2869+
and "sycl" for SYCL device code.
2870+
2871+
Returns:
2872+
bool:
2873+
True if compilation is supported, False otherwise.
2874+
2875+
Raises:
2876+
ValueError:
2877+
If an unknown source language is used.
2878+
"""
2879+
if language == "spirv" or language == "spv":
2880+
return DPCTLDevice_CanCompileSPIRV(self._device_ref)
2881+
if language == "opencl" or language == "ocl":
2882+
return DPCTLDevice_CanCompileOpenCL(self._device_ref)
2883+
if language == "sycl":
2884+
return DPCTLDevice_CanCompileSYCL(self._device_ref)
2885+
2886+
raise ValueError(f"Unknown source language {language}")
2887+
28572888

28582889
cdef api DPCTLSyclDeviceRef SyclDevice_GetDeviceRef(SyclDevice dev):
28592890
"""

dpctl/_sycl_queue.pxd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ cdef public api class SyclQueue (_SyclQueue) [
6868
cdef int _populate_range(self, size_t Range[3], list gS, size_t nGS)
6969

7070
@staticmethod
71-
cdef SyclQueue _create(DPCTLSyclQueueRef qref)
71+
cdef SyclQueue _create(DPCTLSyclQueueRef qref)
7272

7373
@staticmethod
74-
cdef SyclQueue _create_from_context_and_device(
74+
cdef SyclQueue _create_from_context_and_device(
7575
SyclContext ctx, SyclDevice dev, int props=*
7676
)
7777
cdef cpp_bool equals(self, SyclQueue q)
7878
cpdef SyclContext get_sycl_context(self)
7979
cpdef SyclDevice get_sycl_device(self)
80-
cdef DPCTLSyclQueueRef get_queue_ref(self)
80+
cdef DPCTLSyclQueueRef get_queue_ref(self)
8181
cpdef SyclEvent _submit_keep_args_alive(
8282
self,
8383
object args,

dpctl/program/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@
2929
SyclKernelBundleCompilationError,
3030
create_kernel_bundle_from_source,
3131
create_kernel_bundle_from_spirv,
32+
create_kernel_bundle_from_sycl_source,
3233
create_program_from_source,
3334
create_program_from_spirv,
35+
is_sycl_source_compilation_available,
3436
)
3537

3638
__all__ = [
3739
"create_kernel_bundle_from_source",
3840
"create_kernel_bundle_from_spirv",
3941
"create_program_from_source",
4042
"create_program_from_spirv",
43+
"create_kernel_bundle_from_sycl_source",
44+
"is_sycl_source_compilation_available",
4145
"SyclKernel",
4246
"SyclKernelBundle",
4347
"SyclKernelBundleCompilationError",

dpctl/program/_program.pxd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ cdef api class SyclKernelBundle [
5252
binary file.
5353
"""
5454
cdef DPCTLSyclKernelBundleRef _kernel_bundle_ref
55+
cdef bint _is_sycl_source
5556

5657
@staticmethod
57-
cdef SyclKernelBundle _create (DPCTLSyclKernelBundleRef kbref)
58-
cdef DPCTLSyclKernelBundleRef get_kernel_bundle_ref (self)
58+
cdef SyclKernelBundle _create (DPCTLSyclKernelBundleRef kbref,
59+
bint _is_sycl_source)
60+
cdef DPCTLSyclKernelBundleRef get_kernel_bundle_ref (self)
5961
cpdef SyclKernel get_sycl_kernel(self, str kernel_name)
6062

6163

@@ -72,3 +74,7 @@ cpdef create_program_from_source (SyclQueue q, unicode source, unicode copts=*)
7274
cpdef create_program_from_spirv (
7375
SyclQueue q, const unsigned char[:] IL, unicode copts=*
7476
)
77+
cpdef create_kernel_bundle_from_sycl_source(SyclQueue q, unicode source,
78+
list headers=*,
79+
list registered_names=*,
80+
list copts=*)

0 commit comments

Comments
 (0)