Xiangyu-Hu / SPHinXsys

SPHinXsys provides C++ APIs for engineering simulation and optimization. It aims at complex systems driven by fluid, structure, multi-body dynamics and beyond. The multi-physics library is based on a unique and unified computational framework by which strong coupling has been achieved for all involved physics.
https://www.sphinxsys.org/
Apache License 2.0
259 stars 197 forks source link

[SYCL] Use Eigen classes within SYCL kernels #503

Closed nR3D closed 3 months ago

nR3D commented 3 months ago

So far SYCL vector types (sycl::vec) have been used as a replacement for Eigen matrices and arrays, since the latter are directly supported for SYCL kernel execution. This led to the introduction of a parallel set of data types (e.g. DeviceVecd instead of Vecd) that could be used within SYCL kernels. However, Eigen provides many algebraic methods that SYCL vectors lack, additionally the support for two different vector types would mean a less maintainable codebase. Ideally, using Eigen for both CPU and GPU execution is the option to pursue (as long as the performance gap w.r.t. SYCL vectors is not excessive). The following changes enable an initial support for Eigen data types within SYCL kernels, however many aspect are still to be considered, so I will keep this pull request as a draft for the moment being:

https://gitlab.com/libeigen/eigen/-/issues/2763 This is a recently-opened discussion with additional resources and insights on SYCL support by Eigen.

Xiangyu-Hu commented 3 months ago

@nR3D we can check the macro in eigen for using https://gitlab.com/libeigen/eigen/-/blob/master/Eigen/Core#L111

Xiangyu-Hu commented 3 months ago

@nR3D another place for sycl is https://eigen.tuxfamily.org/dox-devel/Macros_8h_source.html and https://gitlab.com/libeigen/eigen/-/blob/master/Eigen/src/Core/util/Macros.h#L851

nR3D commented 3 months ago

I have solved the issue in the 3d case, it turned out to be a problem with the allocation size of the neighborhood list, which was too small. As discussed in previous PRs, the solution would be to define a method that determines the maximum number of particles contained withing the kernel's smoothing radius, or by removing the usage of a neighborhood list all together.

At this point all the issues with Eigen seem to have been solved, so I will remove the draft status from the PR.

Xiangyu-Hu commented 3 months ago

@nR3D Great to hear it.