JuliaGPU / oneAPI.jl

Julia support for the oneAPI programming toolkit.
https://juliagpu.org/oneapi/
Other
182 stars 22 forks source link

Add a generator of C interfaces #378

Closed amontoison closed 10 months ago

amontoison commented 12 months ago

@maleadt @pengtu @michel2323 I worked on a generator of C interfaces today. It takes as input a C++ header file and generate the C interfaces with a C header. You have an example with onemkl_lapack.cpp and one_lapack.h.

Even if it's not perfect, it will highly help to interface the libraries of oneAPI. Do we have a Julia artifact that contains all hxx / hpp such that I can test it a different library?

maleadt commented 12 months ago

Great stuff! I wondered if we could consider calling the C++ libraries directly (given that we only need to support a well-defined subset of types, maybe it's possible to do the ABI conversions ourselves and treat the entry-points as C functions), but a generator is pretty great as well.

Do we have a Julia artifact that contains all hxx / hpp such that I can test it a different library?

No, I attempted packaging the oneAPI Base Toolkit in Yggdrasil at some point, but the installer is really redistribution-unfriendly. This is also why we're using Conda right now, much to my dismay. Maybe it would be possible to create a simple oneAPI_Support_Headers JLL though, repackaging just the bits you need?

pengtu commented 12 months ago

@amontoison : This is very cool!

amontoison commented 11 months ago

@maleadt @pengtu @michel2323 @kballeda

I finalized the script generate_interfaces.jl. When we run julia --project generate_interfaces.jl, the files onemkl.h and onemkl.cpp are updated in the folder deps/src.

The script uses the headers of the new artifact oneAPI_Support_Headers_jll.jl, which means that we can easily update the C interfaces in the future.

Before that generate_interfaces.jl updates the two files, it generates the following files in the current folder:

At the end of the process, these files are concatenated with onemkl_prologue.{h,cpp} and onemkl_epilogue.{h,cpp} to form onemkl.cpp and onemkl.h.

In the current state, we have a C interface for almost all BLAS and LAPACK routines. For SPARSE MKL, I don't know how to interface the type matrix_handle_t. Can one of you take a look? It shouldn't be complicated.

If the sparse part works, we'll be able to use the sparse_gemv and sparse_gemm routines to solve sparse linear systems with Krylov.jl, and if possible, test this on Aurora. :rocket:

kballeda commented 11 months ago

@amontoison we are looking into enabling sparse primitives - sparse_gemv and sparse_gemm.

pengtu commented 10 months ago

@maleadt : Could you merge this PR to the oneAPI.jl repo or need additional reviews/tests?

maleadt commented 10 months ago

Thanks @amontoison!

maleadt commented 9 months ago

@amontoison I didn't realize you didn't use Clang.jl to parse the headers. Doing this string-based seems really fragile; did you consider using Clang.jl?

amontoison commented 9 months ago

@maleadt Using Clang.jl is the best solution but I don't know how we can parse *.hxx herders with it to generate Julia interfaces.