Skip to content

SIMD backends for math functions - #3

Merged
tpadioleau merged 44 commits into
mainfrom
simd-backends
Apr 7, 2026
Merged

SIMD backends for math functions#3
tpadioleau merged 44 commits into
mainfrom
simd-backends

Conversation

@tretre91

@tretre91 tretre91 commented Apr 17, 2025

Copy link
Copy Markdown
Member

This PR adds Kokkos SIMD compatible wrappers for simd math libraries. A user can use this as a cmake project, and include CEXA_SIMD_Backends.hpp in their program, or directly include CEXA_SIMD_{SLEEF,SVML,AOCLLIBM}.hpp.

Currently, only sleef and svml are supported in the CMake, I will add aocl libm later as the support for vectorized functions is not complete at the moment (users can still use the standalone header)

I also added a basic accuracy test to ensure that the functions give a reasonable (<=4ulp) difference from the exact value

@tretre91 tretre91 self-assigned this Apr 17, 2025

@PaulGannay PaulGannay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are some of the file name in all caps (CEXA_SIMD_AOCLLIBM.hpp, ...)?

Comment on lines +55 to +58
#define CEXA_IMPL_SIMD_AOCL_AVX2_UNARY_FUNCTION(func) \
CEXA_IMPL_SIMD_AOCL_AVX2_S4_UNARY_FUNCTION(func) \
CEXA_IMPL_SIMD_AOCL_AVX2_S8_UNARY_FUNCTION(func) \
CEXA_IMPL_SIMD_AOCL_AVX2_D4_UNARY_FUNCTION(func)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why unary macro are defined as 3 separate macro merged in a fourth one while the binary macro are all defined in a single macro?

@tretre91 tretre91 Mar 31, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because AOCL LibM doesn't support every function for every vector type, CEXA_IMPL_SIMD_AOCL_AVX2_UNARY_FUNCTION is used when the function is implemented for fp32x8, fp32x4 and fp64x4, otherwise I use one or more of the three separate macros, for example cbrt is only defined for fp32x4, so I use CEXA_IMPL_SIMD_AOCL_AVX2_S4_UNARY_FUNCTION(cbrt).

We only use the binary macro for pow which is supported on all vector types, which is why there is a single macro for binary functions.

Comment thread simd-backends/src/CEXA_SIMD_AOCLLIBM.hpp Outdated
Comment on lines +9 to +10
#cmakedefine CEXA_SIMD_ENABLE_SLEEF
#cmakedefine CEXA_SIMD_ENABLE_SVML

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't AOCL-libm also be in this file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't figured out yet how to link AOCL cleanly through CMake, the libm examples rely on a user provided variable with the path to an aocl-libm install instead of doing a find_package or using pkg-config, they mention .deb/.rpm packages which don't seem to exist so I cannot look at this either to see if they export CMake files which could be used with a find_package

Comment thread simd-backends/test/accuracy.cpp Outdated
Comment thread simd-backends/test/accuracy.cpp Outdated
Comment thread simd-backends/test/accuracy.cpp Outdated
Comment thread simd-backends/test/accuracy.cpp Outdated
Comment on lines +10 to +22
option(
CEXA_SIMD_ENABLE_SLEEF
"Use the sleef library to implement the simd math functions"
OFF
)
option(CEXA_SIMD_ENABLE_SVML "Use the svml to implement the simd math functions" OFF)
option(CEXA_SIMD_ENABLE_TESTS "Enable accuracy tests" OFF)
option(CEXA_SIMD_ENABLE_INSTALL "Enable installation of the library" ON)

if(CEXA_SIMD_ENABLE_SLEEF AND CEXA_SIMD_ENABLE_SVML)
message(FATAL_ERROR "Only one backend can be enabled at a time")
endif()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No AOCL-libm?

Comment thread simd-backends/CMakeLists.txt Outdated
@tretre91

tretre91 commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

How do we make sure that the new implementation of these simd math functions get selected over the generic ones in Kokkos ?

I can try to setup a CI job running the Kokkos simd perf tests with and without the sleef backend and compare the results, assuming that running inside a github runner doesn't introduce too much noise

@tretre91

tretre91 commented Apr 1, 2026

Copy link
Copy Markdown
Member Author

No particular reason except for the convenience of not having to remember which letters are lowercase in "AOCLLibM". I can change it if needed

I would prefer it to be small cap only, but I have no particular rational, I'll let you decide.

By "small cap only" do you mean something like cexa_simd_sleef or CEXA_SIMD_sleef ?

Comment thread simd-backends/README.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other headers CEXA_SIMD_SVML, CEXA_SIMD_AOCLLIBM ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I didn't notice that sleef was duplicated. For AOCLLIBM, I don't support it through CMake yet, they don't seem to export files to enable find_package, so I will probably have to implement a FindAOCLLIBM file myself.

Comment thread simd-backends/src/CMakeLists.txt Outdated
Comment thread simd-backends/src/CMakeLists.txt Outdated
Comment thread simd-backends/src/CEXA_SIMD_SVML.hpp
Comment thread simd-backends/README.md Outdated
Comment thread simd-backends/README.md Outdated
@tretre91

tretre91 commented Apr 3, 2026

Copy link
Copy Markdown
Member Author

Removed the AOCL Libm header for now, I will add it back in another PR once I figure out how to include it with CMake

@tpadioleau tpadioleau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me

@tpadioleau
tpadioleau merged commit 2cf6968 into main Apr 7, 2026
3 checks passed
@tretre91
tretre91 deleted the simd-backends branch May 7, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants