Repository navigation
Add kernel bundle states, kernel ids and SYCL library loading - #2440
Open
ndgrigorian wants to merge 10 commits into
Open
ndgrigorian wants to merge 10 commits into
ndgrigorian wants to merge 10 commits into
Conversation
Wrap sycl::kernel_bundle in input, object and executable states, kernel_id and device images, with get_kernel_bundle, compile, link, build and join in the C API and dpctl.compiler. DPCTLKernel_GetNumArgs no longer terminates for kernels without a number of arguments.
SyclKernel device-specific queries become methods with an optional device, and DPCTLKernel_Get* take a nullable device (breaking). get_kernel_bundle accepts a device image selector, and dpctl4pybind11.hpp casts input and object bundles and kernel ids, used by the new use_kernel_bundle example.
Load a shared library with SYCL device code, e.g. built for CUDA or HIP, and return the ids of the kernels it registered, for get_kernel_bundle. Exposed as dpctl.compiler.load_kernel_library and DPCTLKernelId_LoadLibrary.
The IL memoryview was typed as strided but passed to the C API as a contiguous pointer and length. Declare it as const unsigned char[::1] so non-contiguous buffers are rejected.
The destructor called dlclose/FreeLibrary even when the library failed to open.
DPCTLKernelBundle_GetKernel, DPCTLKernelBundle_HasKernel and DPCTLKernelBundle_CreateFromOCLSource could let SYCL exceptions escape an extern "C" function, which terminates the process. Report them through error_handler and return the function's failure value.
get_native and make_kernel_bundle/make_kernel retain the OpenCL context, program and kernel, so the references obtained by dpctl were leaked. Release them with a scoped guard, and release the kernels created by _HasKernel_ocl_impl.
The module and kernels were created with ownership::keep and never destroyed. Use ownership::transfer, destroy them if interop fails, and destroy the kernel created by _HasKernel_ze_impl.
Append the clBuildProgram or zeModuleCreate build log to the error reported through error_handler.
ndgrigorian
requested review from
antonwolfy and
vlad-perevezentsev
as code owners
December 3, 2026 09:06
|
View rendered docs @ https://intelpython.github.io/dpctl/pulls/2440/index.html |
A Debug build defines _DEBUG, which makes Windows pyconfig.h enable Py_DEBUG and reference symbols missing from the release python lib.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes expanding
dpctl.compilerto include kernel bundles in theinput,objectandexecutablestates,get_kernel_bundleandhas_kernel_bundle,compile,link,buildandjoin, theSyclKernelIdandSyclDeviceImageclasses,get_kernel_ids,is_compatible, and newSyclKernelBundlequeries (state,backend,sycl_context,get_devices,is_empty,get_kernel_ids,has_kernel,get_kernel,get_device_images, specialization constant queries)It also adds
dpctl.compiler.load_kernel_library, which loads a shared library with SYCL device code, e.g. compiled for CUDA or HIP devices, and returns the ids of its kernels for use withget_kernel_bundle, anddpctl4pybind11.hpptype casters forsycl::kernel_bundle<sycl::bundle_state::input>,sycl::kernel_bundle<sycl::bundle_state::object>andsycl::kernel_id, with a newexamples/pybind11/use_kernel_bundleexample that sets a SYCL specialization constant on a kernel bundle obtained in PythonThis includes a breaking change for
dpctl.compiler.SyclKernel: the device-specific queries become methods taking an optionaldevice, which defaults to the first device of the kernel bundle, and the matchingDPCTLKernel_Get*C-API functions take a nullableDPCTLSyclDeviceRef. These queries now return 0 instead of terminating the process when the SYCL runtime throwsThe PR also fixes a number of bugs in the existing kernel bundle C API:
DPCTLKernelBundle_GetKernel,DPCTLKernelBundle_HasKernelandDPCTLKernelBundle_CreateFromOCLSourcelet SYCL exceptions escape anextern "C"function, terminating the processget_nativeandmake_kernel_bundle/make_kernelwere leakedownership::keepand never destroyedDynamicLibHelperno longer closes a NULL handle when a library fails to opencreate_kernel_bundle_from_spirvrejects non-contiguous buffers which were passed to the C API as contiguous