From 68a0ca0c84bf4e5037124290735290130e5100b1 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Thu, 6 Jun 2024 12:46:08 +0200
Subject: [PATCH] KfCore: moving SIMD header from CaCore

---
 algo/CMakeLists.txt                           |  6 ++++-
 algo/ca/core/CMakeLists.txt                   | 10 ++++-----
 algo/ca/core/utils/CaSimd.h                   | 11 ++++++++--
 algo/kf/core/CMakeLists.txt                   |  6 ++++-
 algo/kf/core/utils/KfSimd.h                   | 14 ++++++++++++
 .../core/utils/KfSimdPseudo.h}                |  6 ++---
 .../CaSimdVc.h => kf/core/utils/KfSimdVc.h}   | 22 +++++++++----------
 reco/littrack/parallel/CMakeLists.txt         |  3 ++-
 8 files changed, 54 insertions(+), 24 deletions(-)
 create mode 100644 algo/kf/core/utils/KfSimd.h
 rename algo/{ca/core/utils/CaSimdPseudo.h => kf/core/utils/KfSimdPseudo.h} (98%)
 rename algo/{ca/core/utils/CaSimdVc.h => kf/core/utils/KfSimdVc.h} (61%)

diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt
index 1f3952888c..b177933cbb 100644
--- a/algo/CMakeLists.txt
+++ b/algo/CMakeLists.txt
@@ -185,8 +185,11 @@ target_include_directories(Algo
          ${CMAKE_CURRENT_SOURCE_DIR}/unpack
          ${CMAKE_CURRENT_SOURCE_DIR}/detectors
          ${CMAKE_CURRENT_SOURCE_DIR}/qa
-         ${CMAKE_CURRENT_SOURCE_DIR}/ca
          ${CMAKE_CURRENT_SOURCE_DIR}/qa/unpack
+         ${CMAKE_CURRENT_SOURCE_DIR}/kf
+         ${CMAKE_CURRENT_SOURCE_DIR}/kf/core
+         ${CMAKE_CURRENT_SOURCE_DIR}/kf/core/utils
+         ${CMAKE_CURRENT_SOURCE_DIR}/ca
          ${CMAKE_CURRENT_SOURCE_DIR}/ca/qa
          ${CMAKE_CURRENT_SOURCE_DIR}/ca/core/data
          ${CMAKE_CURRENT_SOURCE_DIR}
@@ -195,6 +198,7 @@ target_include_directories(Algo
 
 target_link_libraries(Algo
   PUBLIC    OnlineData
+            KfCore
             CaCore
             ROOT::GenVector
             GSL
diff --git a/algo/ca/core/CMakeLists.txt b/algo/ca/core/CMakeLists.txt
index b255a4bfdb..b80a507590 100644
--- a/algo/ca/core/CMakeLists.txt
+++ b/algo/ca/core/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SRCS
 
 SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-O3")
 
+
 If(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   ADD_DEFINITIONS(-Wall -Wextra -Wsign-promo -Wctor-dtor-privacy -Wreorder -Wno-deprecated -Wno-parentheses) # -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast : wait for other parts of cbmroot\root.
 Else()
@@ -51,19 +52,19 @@ EndIf()
 
 add_library(CaCore SHARED ${SRCS})
 
+list(APPEND HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/utils/CaSimd.h)
+
 target_include_directories(CaCore
   PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/data
          ${CMAKE_CURRENT_SOURCE_DIR}/utils
          ${CMAKE_CURRENT_SOURCE_DIR}/pars
          ${CMAKE_CURRENT_SOURCE_DIR}/qa
          ${CMAKE_CURRENT_SOURCE_DIR}/tracking
-         ${CMAKE_CURRENT_SOURCE_DIR}
 )
 
 target_compile_definitions(CaCore PUBLIC NO_ROOT)
 target_link_libraries(CaCore
-                      KfCore
-                      Vc::Vc                      
+              PUBLIC  KfCore
                       Boost::serialization
                       OnlineDataLog          # needed for the logger
                       external::fles_logging # needed for the logger
@@ -74,6 +75,7 @@ target_link_libraries(CaCore
 install(TARGETS CaCore DESTINATION lib)
 install(DIRECTORY utils TYPE INCLUDE FILES_MATCHING PATTERN "*.h")
 install(DIRECTORY data TYPE INCLUDE FILES_MATCHING PATTERN "*.h")
+install(DIRECTORY tracking TYPE INCLUDE FILES_MATCHING PATTERN "*.h")
 install(DIRECTORY pars TYPE INCLUDE FILES_MATCHING PATTERN "*.h")
 
 install(
@@ -113,8 +115,6 @@ install(
     utils/CaMonitorData.h
     utils/CaObjectInitController.h
     utils/CaSimd.h
-    utils/CaSimdVc.h
-    utils/CaSimdPseudo.h
     utils/CaTimer.h
     utils/CaVector.h
     utils/CaUtils.h
diff --git a/algo/ca/core/utils/CaSimd.h b/algo/ca/core/utils/CaSimd.h
index 06f4017fdc..99ac74afe1 100644
--- a/algo/ca/core/utils/CaSimd.h
+++ b/algo/ca/core/utils/CaSimd.h
@@ -4,5 +4,12 @@
 
 #pragma once  // include this header only once per compilation unit
 
-#include "CaSimdVc.h"
-//#include "CaSimdPseudo.h"
+#include "KfSimd.h"
+
+namespace cbm::algo::ca
+{
+  // Backward compatebility to ca::fvec etc.
+  using fvec  = kf::fvec;
+  using fscal = kf::fscal;
+  using fmask = kf::fmask;
+}  // namespace cbm::algo::ca
diff --git a/algo/kf/core/CMakeLists.txt b/algo/kf/core/CMakeLists.txt
index f89e9015c6..18c994e8fe 100644
--- a/algo/kf/core/CMakeLists.txt
+++ b/algo/kf/core/CMakeLists.txt
@@ -14,6 +14,7 @@ set(SRCS
 
 SET_SOURCE_FILES_PROPERTIES(${SRCS} PROPERTIES COMPILE_FLAGS "-O3")
 
+
 If(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
   ADD_DEFINITIONS(-Wall -Wextra -Wsign-promo -Wctor-dtor-privacy -Wreorder -Wno-deprecated -Wno-parentheses) # -Weffc++ -Wnon-virtual-dtor -Woverloaded-virtual -Wold-style-cast : wait for other parts of cbmroot\root.
 Else()
@@ -22,6 +23,8 @@ EndIf()
 
 add_library(KfCore SHARED ${SRCS})
 
+list(APPEND HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/utils/KfSimd.h)
+
 target_include_directories(KfCore
   PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/data
          ${CMAKE_CURRENT_SOURCE_DIR}/pars
@@ -32,7 +35,7 @@ target_include_directories(KfCore
 target_compile_definitions(KfCore PUBLIC NO_ROOT)
 
 target_link_libraries(KfCore
-                      Vc::Vc                      
+              PUBLIC  Vc::Vc                      
                       Boost::serialization
                       OnlineDataLog          # needed for the logger
                       external::fles_logging # needed for the logger
@@ -54,6 +57,7 @@ install(
     pars/KfParameters.h 
     pars/KfSetup.h
     utils/KfVector.h
+    utils/KfSimd.h
   DESTINATION
     include/
 )
diff --git a/algo/kf/core/utils/KfSimd.h b/algo/kf/core/utils/KfSimd.h
new file mode 100644
index 0000000000..1804fc7e8b
--- /dev/null
+++ b/algo/kf/core/utils/KfSimd.h
@@ -0,0 +1,14 @@
+/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
+   SPDX-License-Identifier: GPL-3.0-only
+   Authors: Sergei Zharko [committer] */
+
+/// \file   KfSimd.h
+/// \brief  Implementation selection for the SIMD utilities (VS or pseudo)
+/// \since  30.03.2024
+/// \author Sergey Gorbunov <se.gorbunov@gsi.de>
+/// \author Sergei Zharko <s.zharko@gsi.de>
+
+#pragma once  // include this header only once per compilation unit
+
+#include "KfSimdVc.h"
+//#include "KfSimdPseudo.h"
diff --git a/algo/ca/core/utils/CaSimdPseudo.h b/algo/kf/core/utils/KfSimdPseudo.h
similarity index 98%
rename from algo/ca/core/utils/CaSimdPseudo.h
rename to algo/kf/core/utils/KfSimdPseudo.h
index 557b3da268..e6783ab61d 100644
--- a/algo/ca/core/utils/CaSimdPseudo.h
+++ b/algo/kf/core/utils/KfSimdPseudo.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 2010 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
+/* Copyright (C) 2010-2024 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
    SPDX-License-Identifier: GPL-3.0-only
    Authors: Igor Kulakov [committer] */
 
@@ -10,7 +10,7 @@
 #include <iomanip>
 #include <iostream>
 
-namespace cbm::algo::ca
+namespace cbm::algo::kf
 {
 
   typedef float fscal;
@@ -278,4 +278,4 @@ namespace cbm::algo::ca
 
 #define _fvecalignment __attribute__((aligned(fvec::size() * sizeof(fscal))))
 
-}  // namespace cbm::algo::ca
+}  // namespace cbm::algo::kf
diff --git a/algo/ca/core/utils/CaSimdVc.h b/algo/kf/core/utils/KfSimdVc.h
similarity index 61%
rename from algo/ca/core/utils/CaSimdVc.h
rename to algo/kf/core/utils/KfSimdVc.h
index a254dc65b7..6162119184 100644
--- a/algo/ca/core/utils/CaSimdVc.h
+++ b/algo/kf/core/utils/KfSimdVc.h
@@ -1,6 +1,6 @@
-/* Copyright (C) 2010-2014 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
+/* Copyright (C) 2010-2024 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
    SPDX-License-Identifier: GPL-3.0-only
-   Authors: Igor Kulakov [committer], Maksym Zyzak */
+   Authors: Igor Kulakov [committer], Maksym Zyzak, Sergei Zharko */
 
 #pragma once  // include this header only once per compilation unit
 
@@ -10,7 +10,7 @@
 
 #include <Vc/Vc>
 
-namespace cbm::algo::ca
+namespace cbm::algo::kf
 {
   typedef Vc::float_v fvec;
   //typedef Vc::double_v fvec;
@@ -21,33 +21,33 @@ namespace cbm::algo::ca
   typedef fvec::MaskType fmask;
 
 #define _fvecalignment __attribute__((aligned(Vc::VectorAlignment)))
-}  // namespace cbm::algo::ca
+}  // namespace cbm::algo::kf
 
 /// \brief Serializer for SIMD vectors
 namespace boost::serialization
 {
   template<class Archive>
-  void save(Archive& ar, const cbm::algo::ca::fvec& vect, unsigned int)
+  void save(Archive& ar, const cbm::algo::kf::fvec& vect, unsigned int)
   {
-    std::array<cbm::algo::ca::fscal, cbm::algo::ca::fvec::size()> buffer;
-    for (size_t i = 0; i < cbm::algo::ca::fvec::size(); ++i) {
+    std::array<cbm::algo::kf::fscal, cbm::algo::kf::fvec::size()> buffer;
+    for (size_t i = 0; i < cbm::algo::kf::fvec::size(); ++i) {
       buffer[i] = vect[i];
     }
     ar << buffer;
   }
 
   template<class Archive>
-  void load(Archive& ar, cbm::algo::ca::fvec& vect, unsigned int)
+  void load(Archive& ar, cbm::algo::kf::fvec& vect, unsigned int)
   {
-    std::array<cbm::algo::ca::fscal, cbm::algo::ca::fvec::size()> buffer;
+    std::array<cbm::algo::kf::fscal, cbm::algo::kf::fvec::size()> buffer;
     ar >> buffer;
-    for (size_t i = 0; i < cbm::algo::ca::fvec::size(); ++i) {
+    for (size_t i = 0; i < cbm::algo::kf::fvec::size(); ++i) {
       vect[i] = buffer[i];
     }
   }
 
   template<class Archive>
-  void serialize(Archive& ar, cbm::algo::ca::fvec& vect, const unsigned int version)
+  void serialize(Archive& ar, cbm::algo::kf::fvec& vect, const unsigned int version)
   {
     split_free(ar, vect, version);
   }
diff --git a/reco/littrack/parallel/CMakeLists.txt b/reco/littrack/parallel/CMakeLists.txt
index 48d06d4bc1..0ea8149dc1 100644
--- a/reco/littrack/parallel/CMakeLists.txt
+++ b/reco/littrack/parallel/CMakeLists.txt
@@ -2,7 +2,8 @@
 
 set(INCLUDE_DIRECTORIES
   ${CMAKE_CURRENT_SOURCE_DIR}
-  ${CBMROOT_SOURCE_DIR}/algo/ca/core/utils
+  ${CBMROOT_SOURCE_DIR}/algo/kf/core/utils # For SIMD (TODO: Should be re-worked)
+  ${CBMROOT_SOURCE_DIR}/algo/ca/core/utils # For SIMD (TODO: Should be re-worked)
   )
 
 
-- 
GitLab