Skip to content

[GenVectorX] Prototype SYCL support for 2,3,4-dim vector classes #18461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .github/workflows/root-ci-config/buildconfig/fedora41.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ builtin_zstd=ON
builtin_zlib=ON
builtin_vdt=On
ccache=On
experimental_adaptivecpp=ON
experimental_genvectorx=ON
2 changes: 2 additions & 0 deletions .github/workflows/root-ci-config/buildconfig/fedora42.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
builtin_zlib=ON
builtin_zstd=ON
ccache=ON
experimental_adaptivecpp=ON
experimental_genvectorx=ON
vdt=OFF
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ CMAKE_BUILD_TYPE=RelWithDebInfo
pythia8=OFF
cuda=ON
ccache=ON
experimental_adaptivecpp=ON
experimental_genvectorx=ON
tmva=ON
tmva-cpu=ON
tmva-gpu=ON
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/root-ci-config/buildconfig/ubuntu2404.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ccache=ON
experimental_adaptivecpp=ON
experimental_genvectorx=ON
pythia8=OFF
tmva-sofie=ON
2 changes: 2 additions & 0 deletions .github/workflows/root-ci-config/buildconfig/ubuntu2504.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
experimental_adaptivecpp=ON
experimental_genvectorx=ON
ccache=ON
pythia8=OFF
2 changes: 2 additions & 0 deletions cmake/modules/RootBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ ROOT_BUILD_OPTION(davix ON "Enable support for Davix (HTTP/WebDAV access)")
ROOT_BUILD_OPTION(dcache OFF "Enable support for dCache (requires libdcap from DESY)")
ROOT_BUILD_OPTION(dev OFF "Enable recommended developer compilation flags, reduce exposed includes")
ROOT_BUILD_OPTION(distcc OFF "Enable distcc usage for speeding up builds (ccache is called first if enabled)")
ROOT_BUILD_OPTION(experimental_adaptivecpp OFF "Build AdaptiveCPP for SYCL support")
ROOT_BUILD_OPTION(experimental_genvectorx OFF "Build GenvectorX (requires SYCL support)")
ROOT_BUILD_OPTION(fcgi OFF "Enable FastCGI support in HTTP server")
ROOT_BUILD_OPTION(fftw3 OFF "Enable support for FFTW3 [GPL]")
ROOT_BUILD_OPTION(fitsio ON "Enable support for reading FITS images")
Expand Down
35 changes: 35 additions & 0 deletions cmake/modules/SearchInstalledSoftware.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,41 @@ if (vecgeom)
endif()
endif()

if(experimental_adaptivecpp)
# Building adaptivecpp requires an internet connection, if we're not side-loading the source directory
if(NOT DEFINED ADAPTIVECPP_SOURCE_DIR)
ROOT_CHECK_CONNECTION_AND_DISABLE_OPTION("experimental_adaptivecpp")
endif()
include(SetupAdaptiveCpp)
set(HIPSYCL_NO_FIBERS ON)
set(WITH_OPENCL_BACKEND OFF)
set(WITH_LEVEL_ZERO_BACKEND OFF)

find_package(AdaptiveCpp)
if (AdaptiveCpp_FOUND)
set(sycl ON)
set(SYCL_COMPILER_FLAGS "-ffast-math ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_BUILD_TYPE_UPPER}}")
message(STATUS "SYCL compiler flags: ${SYCL_COMPILER_FLAGS}")
separate_arguments(SYCL_COMPILER_FLAGS NATIVE_COMMAND ${SYCL_COMPILER_FLAGS})
function(add_sycl_to_root_target)
CMAKE_PARSE_ARGUMENTS(ARG "" "TARGET" "SOURCES" "COMPILE_DEFINITIONS" ${ARGN})
add_dependencies(${ARG_TARGET} acpp-rt)
add_sycl_to_target(TARGET ${ARG_TARGET} SOURCES ${ARG_SOURCES})
target_link_libraries(${ARG_TARGET} INTERFACE AdaptiveCpp::acpp-rt)
target_compile_options(${ARG_TARGET} PUBLIC ${SYCL_COMPILER_FLAGS})
target_compile_definitions(${ARG_TARGET} PUBLIC ${ARG_COMPILE_DEFINITIONS})
endfunction()
message(STATUS "AdaptiveCpp sycl enabled")
else()
if(fail-on-missing)
message(FATAL_ERROR "AdaptiveCpp library not found")
else()
message(STATUS "AdaptiveCpp library not found")
set(sycl OFF CACHE BOOL "Disabled because no SYCL implementation is not found" FORCE)
endif()
endif()
endif()

#---Check for protobuf-------------------------------------------------------------------

if(tmva-sofie)
Expand Down
116 changes: 116 additions & 0 deletions cmake/modules/SetupAdaptiveCpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
message(STATUS "Building AdaptiveCpp for SYCL support.")

include(FetchContent)

if(NOT DEFINED ADAPTIVE_CPP_SOURCE_DIR)
FetchContent_Declare(
AdaptiveCpp
GIT_REPOSITORY https://github.com/root-project/AdaptiveCpp.git
Copy link
Member

@vgvassilev vgvassilev Jul 11, 2025

Choose a reason for hiding this comment

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

I am a bit confused. If that PR is merged does it mean that ROOT will be fetching ROOT?

Replying to self: AdaptiveCpp seems some runtime that we need. Any clue what would it take to depend on llvm only and what would it take to move the minimal set of infrastructure we need of AdaptiveCpp in llvm?

Copy link
Contributor

Choose a reason for hiding this comment

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

Root will be fetching AdaptiveCpp at configure time if -Dexperimental_adaptivecpp is enabled. AdaptiveCpp upstream uses dynamic LLVM (we need a few patches to get it building statically, so a separate fork. This can potentially be up-streamed)

GIT_TAG ROOT-acpp-v25.02.0-20250615-01)
FetchContent_GetProperties(AdaptiveCpp)
if(NOT AdaptiveCpp_POPULATED)
FetchContent_Populate(AdaptiveCpp)
endif()
set(ADAPTIVE_CPP_SOURCE_DIR ${adaptivecpp_SOURCE_DIR})
message(STATUS "Fetched AdaptiveCpp source to: ${ADAPTIVE_CPP_SOURCE_DIR}")
else()
message(
STATUS "ADAPTIVE_CPP_SOURCE_DIR already defined: ${ADAPTIVE_CPP_SOURCE_DIR}"
)
endif()

set(LLVM_BINARY_DIR ${CMAKE_BINARY_DIR}/interpreter/llvm-project/llvm)
set(CLANG_EXECUTABLE_PATH ${LLVM_BINARY_DIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX})

set(ACPP_CLANG
${CLANG_EXECUTABLE_PATH}
CACHE STRING "Clang compiler executable used for compilation." FORCE)

set(ADAPTIVE_CPP_BINARY_DIR ${CMAKE_BINARY_DIR})
message(STATUS "AdaptiveCpp will be built in: ${ADAPTIVE_CPP_BINARY_DIR}")

set(ADAPTIVECPP_INSTALL_CMAKE_DIR
lib/cmake/AdaptiveCpp
CACHE PATH "Install path for CMake config files")

# Set relative paths for install root in the following variables so that
# configure_package_config_file will generate paths relative whatever is the
# future install root
set(ADAPTIVECPP_INSTALL_COMPILER_DIR bin)
set(ACPP_CONFIG_FILE_INSTALL_DIR etc/AdaptiveCpp)
set(ADAPTIVECPP_INSTALL_LAUNCHER_DIR ${ADAPTIVECPP_INSTALL_CMAKE_DIR})
set(ADAPTIVECPP_INSTALL_LAUNCHER_RULE_DIR ${ADAPTIVECPP_INSTALL_CMAKE_DIR})

install(FILES ${ADAPTIVE_CPP_BINARY_DIR}/lib/libacpp-rt.so DESTINATION lib)
install(DIRECTORY ${ADAPTIVE_CPP_BINARY_DIR}/lib/hipSYCL/bitcode/
DESTINATION lib/hipSYCL/bitcode)
install(DIRECTORY ${ADAPTIVE_CPP_BINARY_DIR}/include/AdaptiveCpp/
DESTINATION include/AdaptiveCpp)

file(
COPY ${ADAPTIVE_CPP_SOURCE_DIR}/cmake/syclcc-launcher
DESTINATION ${ADAPTIVE_CPP_BINARY_DIR}/${ADAPTIVECPP_INSTALL_LAUNCHER_DIR})
file(
COPY ${ADAPTIVE_CPP_SOURCE_DIR}/cmake/syclcc-launch.rule.in
DESTINATION ${ADAPTIVE_CPP_BINARY_DIR}/${ADAPTIVECPP_INSTALL_LAUNCHER_RULE_DIR})

list(APPEND CMAKE_PREFIX_PATH ${ADAPTIVE_CPP_BINARY_DIR}/${ADAPTIVECPP_INSTALL_CMAKE_DIR})
message(STATUS "Added ${ADAPTIVE_CPP_BINARY_DIR}/${ADAPTIVECPP_INSTALL_CMAKE_DIR} to CMAKE_PREFIX_PATH.")

install(PROGRAMS ${ADAPTIVE_CPP_BINARY_DIR}/bin/acpp
DESTINATION ${ADAPTIVECPP_INSTALL_COMPILER_DIR})
install(FILES ${ADAPTIVE_CPP_SOURCE_DIR}/cmake/syclcc-launcher
DESTINATION ${ADAPTIVECPP_INSTALL_LAUNCHER_DIR})
install(FILES ${ADAPTIVE_CPP_SOURCE_DIR}/cmake/syclcc-launch.rule.in
DESTINATION ${ADAPTIVECPP_INSTALL_LAUNCHER_RULE_DIR})

file(GLOB CLANG_EXECUTABLES "${LLVM_BINARY_DIR}/bin/clang*")
install(PROGRAMS ${CLANG_EXECUTABLES}
DESTINATION ${ADAPTIVECPP_INSTALL_COMPILER_DIR})

file(GLOB CONFIG_FILES "${ADAPTIVE_CPP_BINARY_DIR}/etc/AdaptiveCpp/*")
install(FILES ${CONFIG_FILES} DESTINATION ${ACPP_CONFIG_FILE_INSTALL_DIR})

# Create imported target AdaptiveCpp::acpp-common
add_library(AdaptiveCpp::acpp-common STATIC IMPORTED)

set_target_properties(AdaptiveCpp::acpp-common PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ADAPTIVE_CPP_BINARY_DIR}/include;${ADAPTIVE_CPP_BINARY_DIR}/include/AdaptiveCpp"
INTERFACE_LINK_LIBRARIES "-Wl,-Bsymbolic-functions;\$<LINK_ONLY:dl>"
)

# Create imported target AdaptiveCpp::acpp-rt
add_library(AdaptiveCpp::acpp-rt SHARED IMPORTED)

set_target_properties(AdaptiveCpp::acpp-rt PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ADAPTIVE_CPP_BINARY_DIR}/include;${ADAPTIVE_CPP_BINARY_DIR}/include/AdaptiveCpp"
INTERFACE_LINK_LIBRARIES "AdaptiveCpp::acpp-common"
)

# Import target "AdaptiveCpp::acpp-common" for configuration "Release"
set_property(TARGET AdaptiveCpp::acpp-common APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(AdaptiveCpp::acpp-common PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX"
IMPORTED_LOCATION_RELEASE "${ADAPTIVE_CPP_BINARY_DIR}/lib/libacpp-common.a"
)

# Import target "AdaptiveCpp::acpp-rt" for configuration "Release"
set_property(TARGET AdaptiveCpp::acpp-rt APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(AdaptiveCpp::acpp-rt PROPERTIES
IMPORTED_LOCATION_RELEASE "${ADAPTIVE_CPP_BINARY_DIR}/lib/libacpp-rt.so"
IMPORTED_SONAME_RELEASE "libacpp-rt.so"
)

# Make a config file to make this usable as a CMake Package
# Start by adding the version in a CMake understandable way
include(CMakePackageConfigHelpers)

configure_package_config_file(
${ADAPTIVE_CPP_SOURCE_DIR}/cmake/adaptivecpp-config.cmake.in
${ADAPTIVE_CPP_BINARY_DIR}/lib/cmake/AdaptiveCpp/adaptivecpp-config.cmake
INSTALL_DESTINATION ${ADAPTIVECPP_INSTALL_CMAKE_DIR}
PATH_VARS
ADAPTIVECPP_INSTALL_COMPILER_DIR
ADAPTIVECPP_INSTALL_LAUNCHER_DIR
ADAPTIVECPP_INSTALL_LAUNCHER_RULE_DIR
)
7 changes: 7 additions & 0 deletions interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ if(builtin_llvm)

set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")

if(experimental_adaptivecpp)
# Register AdaptiveCpp as an external project
set(LLVM_EXTERNAL_PROJECTS "AdaptiveCpp" CACHE STRING "")
set(LLVM_EXTERNAL_ADAPTIVECPP_SOURCE_DIR "${ADAPTIVE_CPP_SOURCE_DIR}" CACHE STRING "")
set(LLVM_ADAPTIVECPP_LINK_INTO_TOOLS ON CACHE BOOL "") # To force-link the plugin into clang
endif()

# Always build LLVM with C++17. It is not necessary to compile with the same
# C++ standard as the rest of ROOT and sometimes it doesn't even work.
set(_cxx_standard ${CMAKE_CXX_STANDARD})
Expand Down
3 changes: 3 additions & 0 deletions math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ add_subdirectory(smatrix)
add_subdirectory(splot)
#add_subdirectory(mathcore/test EXCLUDE_FROM_ALL)
add_subdirectory(genvector)
if(sycl AND experimental_genvectorx)
add_subdirectory(experimental/genvectorx)
endif()
if(tmva)
add_subdirectory(genetic)
endif()
Expand Down
73 changes: 73 additions & 0 deletions math/experimental/genvectorx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

############################################################################
# CMakeLists.txt file for building ROOT math/genvector package
############################################################################

message(STATUS "Experimental GenVectorX")

ROOT_LINKER_LIBRARY(GenVectorSYCL
src/3DConversions.cxx
src/3DDistances.cxx
src/AxisAngle.cxx
src/AxisAngleXother.cxx
src/BitReproducible.cxx
src/Boost.cxx
src/BoostX.cxx
src/BoostY.cxx
src/BoostZ.cxx
src/EulerAngles.cxx
src/LorentzRotation.cxx
src/Quaternion.cxx
src/QuaternionXaxial.cxx
src/Rotation3D.cxx
src/Rotation3DxAxial.cxx
src/RotationZYX.cxx
src/VectorUtil.cxx
DEPENDENCIES
Core
MathCore
)

add_sycl_to_root_target(
TARGET
GenVectorSYCL
SOURCES
src/3DConversions.cxx
src/3DDistances.cxx
src/AxisAngle.cxx
src/AxisAngleXother.cxx
src/BitReproducible.cxx
src/Boost.cxx
src/BoostX.cxx
src/BoostY.cxx
src/BoostZ.cxx
src/EulerAngles.cxx
src/LorentzRotation.cxx
src/Quaternion.cxx
src/QuaternionXaxial.cxx
src/Rotation3D.cxx
src/Rotation3DxAxial.cxx
src/RotationZYX.cxx
src/VectorUtil.cxx
COMPILE_DEFINITIONS
ROOT_MATH_SYCL
)

set(ACPP_EXPORTS acpp-rt acpp-common)

foreach(target IN LISTS ACPP_EXPORTS)
install(TARGETS ${target} EXPORT ROOTExports)
endforeach()

target_link_libraries(GenVectorSYCL PUBLIC m stdc++)

target_compile_definitions(GenVectorSYCL PUBLIC ROOT_MATH_SYCL)

ROOT_ADD_TEST_SUBDIRECTORY(test)

ROOT_INSTALL_HEADERS()
14 changes: 14 additions & 0 deletions math/experimental/genvectorx/doc/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
\defgroup GenVectorX Physics Vectors
\ingroup Math
\brief Vector classes (2D, 3D and 4D / Lorentz vector) and their transformations to be used in SYCL or CUDA kernels for heterogeneous computing.

These classes represent vectors and their operations and transformations, such as rotations and Lorentz transformations, in two, three and four dimensions.
The 4D space-time is used for physics vectors representing relativistic particles in [Minkowski-space](https://en.wikipedia.org/wiki/Minkowski_space).
These vectors are different from Linear Algebra vectors or `std::vector` which describe generic N-dimensional vectors.

Hint: the most commonly used Lorentz vector class is ROOT::MathSYCL::PtEtaPhiMVector or ROOT::MathCUDA::PtEtaPhiMVector, respectively a typedef to ROOT::MathSYCL::LorentzVector < ROOT::MathSYCL::PtEtaPhiM4D < double > > and ROOT::MathCUDA::LorentzVector < ROOT::MathCUDA::PtEtaPhiM4D < double > >.


## Additional Documentation

A more detailed description of the GenVectorX package is available in this [document](https://arxiv.org/pdf/2312.02756).
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/AxisAngle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_AxisAngle
#define ROOT_MathX_AxisAngle

#include "MathX/GenVectorX/AxisAngle.h"

#endif
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/Boost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_Boost
#define ROOT_MathX_Boost

#include "MathX/GenVectorX/Boost.h"

#endif
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/BoostX.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_BoostX
#define ROOT_MathX_BoostX

#include "MathX/GenVectorX/BoostX.h"

#endif
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/BoostY.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_BoostY
#define ROOT_MathX_BoostY

#include "MathX/GenVectorX/BoostY.h"

#endif
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/BoostZ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_BoostZ
#define ROOT_MathX_BoostZ

#include "MathX/GenVectorX/BoostZ.h"

#endif
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/Cartesian2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_Cartesian2D
#define ROOT_MathX_Cartesian2D

#include "MathX/GenVectorX/Cartesian2D.h"

#endif
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/Cartesian3D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_Cartesian3D
#define ROOT_MathX_Cartesian3D

#include "MathX/GenVectorX/Cartesian3D.h"

#endif
9 changes: 9 additions & 0 deletions math/experimental/genvectorx/inc/MathX/Cylindrical3D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @(#)root/mathcore:$Id$
// Authors: W. Brown, M. Fischler, L. Moneta 2005

#ifndef ROOT_MathX_Cylindrical3D
#define ROOT_MathX_Cylindrical3D

#include "MathX/GenVectorX/Cylindrical3D.h"

#endif
Loading
Loading