IntelPython / dpctl

Python SYCL bindings and SYCL-based Python Array API library
https://intelpython.github.io/dpctl/
Apache License 2.0
97 stars 29 forks source link

How to convert CUDA-Python to SYCL using dpctl? #1635

Open AryanKarumuri opened 3 months ago

AryanKarumuri commented 3 months ago

Hi team,

Would you kindly provide guidance on transitioning CUDA-Python code to SYCL? Specifically, I am interested in converting the code available here to SYCL utilizing dpctl. And also, is there any tool available for auto-migration of CUDA-Python sample to SYCL? (like SYCLOMATIC tool)

Additionally, could you please furnish any documentation detailing the mapping process, if available?

Thank you in advance for your assistance.

oleksandr-pavlyk commented 3 months ago

An example of dispatching kernels written in OpenCL language can be found in the dpctl's test suite: https://github.com/IntelPython/dpctl/blob/master/dpctl/tests/test_sycl_kernel_submit.py#L44-L94

It leverages dpctl.program.create_program_from_source functions to compile OCL source, and submits kernel extracted from the program it using dpctl.SyclQueue.submit method.

That said, numba_dpex enables writing kernels in Python, not unlike numba.cuda. Please refer to https://intelpython.github.io/numba-dpex/latest/user_guide/kernel_programming/index.html for examples.

DPCTL comes with DPCTLSyclInterface library, which provides C-API to DPC++ runtime classes. Please refer https://github.com/IntelPython/dpctl/blob/master/libsyclinterface/tests/test_sycl_queue_submit.cpp for examples of kernel submission from C.

There is no automated tool like available to aid in transition from CUDA-Python to SYCL. However, Syclomatic could be used to convert CUDA program to SYCL, and Python extension can be created leveraging dpctl to invoke SYCL functions in the translated code from Python.

Examples of writing Python extensions using C++ that leverage SYCL can be found in https://github.com/IntelPython/dpctl/tree/master/examples/pybind11, but also in https://github.com/IntelPython/sample-data-parallel-extensions/

Please refer to https://dl.acm.org/doi/abs/10.1145/3529538.3529990 for more details.