From 07ca3e2431a98b7a7e76c69c6b8c720b2baefd89 Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Mon, 2 Oct 2023 18:06:42 +0200 Subject: [PATCH] CA: CaCore: new serializer for CaSimdVc and CaSimdPseudo --- algo/ca/core/CMakeLists.txt | 12 ++--- algo/ca/core/simd/CaSimdVc.h | 25 ---------- algo/ca/core/{simd => utils}/CaSimd.h | 0 algo/ca/core/{simd => utils}/CaSimdPseudo.h | 11 +++++ algo/ca/core/utils/CaSimdVc.h | 55 +++++++++++++++++++++ reco/L1/CMakeLists.txt | 1 - reco/L1/L1Algo/L1BaseStationInfo.h | 1 + reco/L1/L1Algo/L1Field.h | 4 +- reco/L1/L1Algo/L1InitManager.h | 1 + reco/L1/L1Algo/L1Material.h | 3 +- reco/L1/L1Algo/L1SimdSerializer.h | 48 ------------------ reco/L1/L1Algo/L1Station.h | 7 +-- reco/L1/L1Algo/L1UMeasurementInfo.h | 2 +- reco/L1/L1Algo/L1XYMeasurementInfo.h | 2 +- reco/L1/catools/CaToolsMCTrack.h | 2 +- reco/littrack/parallel/CMakeLists.txt | 2 +- 16 files changed, 83 insertions(+), 93 deletions(-) delete mode 100644 algo/ca/core/simd/CaSimdVc.h rename algo/ca/core/{simd => utils}/CaSimd.h (100%) rename algo/ca/core/{simd => utils}/CaSimdPseudo.h (97%) create mode 100644 algo/ca/core/utils/CaSimdVc.h delete mode 100644 reco/L1/L1Algo/L1SimdSerializer.h diff --git a/algo/ca/core/CMakeLists.txt b/algo/ca/core/CMakeLists.txt index cee9a629f9..c65a8e0584 100644 --- a/algo/ca/core/CMakeLists.txt +++ b/algo/ca/core/CMakeLists.txt @@ -1,6 +1,6 @@ set(INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/simd + ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/pars ${CMAKE_CURRENT_SOURCE_DIR}/data ) @@ -13,7 +13,7 @@ add_library(CaCore SHARED ${SRCS}) target_include_directories(CaCore PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/data - ${CMAKE_CURRENT_SOURCE_DIR}/simd + ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/pars ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -25,7 +25,7 @@ target_link_libraries(CaCore ) install(TARGETS CaCore DESTINATION lib) -install(DIRECTORY simd TYPE INCLUDE FILES_MATCHING PATTERN "*.h") +install(DIRECTORY utils TYPE INCLUDE FILES_MATCHING PATTERN "*.h") install(DIRECTORY data TYPE INCLUDE FILES_MATCHING PATTERN "*.h") install(DIRECTORY pars TYPE INCLUDE FILES_MATCHING PATTERN "*.h") @@ -33,9 +33,9 @@ install( FILES data/CaTrack.h pars/CaConstants.h - simd/CaSimd.h - simd/CaSimdVc.h - simd/CaSimdPseudo.h + utils/CaSimd.h + utils/CaSimdVc.h + utils/CaSimdPseudo.h DESTINATION include/ ) diff --git a/algo/ca/core/simd/CaSimdVc.h b/algo/ca/core/simd/CaSimdVc.h deleted file mode 100644 index f807e12d02..0000000000 --- a/algo/ca/core/simd/CaSimdVc.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (C) 2010-2014 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt - SPDX-License-Identifier: GPL-3.0-only - Authors: Igor Kulakov [committer], Maksym Zyzak */ - -#ifndef Ca_CaSimdVc_H -#define Ca_CaSimdVc_H - -#include "Vc/Vc" - -namespace cbm::algo::ca -{ - - typedef Vc::float_v fvec; - //typedef Vc::double_v fvec; - //typedef Vc::Vector<float, Vc::VectorAbi::Scalar> fvec; - //typedef Vc::SimdArray<float, 4> fvec; - - typedef fvec::EntryType fscal; - typedef fvec::MaskType fmask; - -#define _fvecalignment __attribute__((aligned(Vc::VectorAlignment))) - -} // namespace cbm::algo::ca - -#endif diff --git a/algo/ca/core/simd/CaSimd.h b/algo/ca/core/utils/CaSimd.h similarity index 100% rename from algo/ca/core/simd/CaSimd.h rename to algo/ca/core/utils/CaSimd.h diff --git a/algo/ca/core/simd/CaSimdPseudo.h b/algo/ca/core/utils/CaSimdPseudo.h similarity index 97% rename from algo/ca/core/simd/CaSimdPseudo.h rename to algo/ca/core/utils/CaSimdPseudo.h index 3e876001ee..74f64da5af 100644 --- a/algo/ca/core/simd/CaSimdPseudo.h +++ b/algo/ca/core/utils/CaSimdPseudo.h @@ -7,6 +7,7 @@ #include <iomanip> #include <iostream> +#include <boost/serialization/access.hpp> #include <cmath> @@ -138,6 +139,16 @@ namespace cbm::algo::ca } } + /// Serialization block + friend class boost::serialization::access; + template<class Archive> + void serialize(Archive& ar, const unsigned int) + { + for (size_t i = 0; i < size(); ++i) { + ar& v[i]; + } + } + static fvec One() { return fvec(1.); } static fvec Zero() { return fvec(0.); } diff --git a/algo/ca/core/utils/CaSimdVc.h b/algo/ca/core/utils/CaSimdVc.h new file mode 100644 index 0000000000..668622c655 --- /dev/null +++ b/algo/ca/core/utils/CaSimdVc.h @@ -0,0 +1,55 @@ +/* Copyright (C) 2010-2014 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt + SPDX-License-Identifier: GPL-3.0-only + Authors: Igor Kulakov [committer], Maksym Zyzak */ + +#ifndef Ca_CaSimdVc_H +#define Ca_CaSimdVc_H + +#include "Vc/Vc" +#include <boost/serialization/access.hpp> +#include <boost/serialization/array.hpp> +#include <boost/serialization/split_free.hpp> + +namespace cbm::algo::ca +{ + typedef Vc::float_v fvec; + //typedef Vc::double_v fvec; + //typedef Vc::Vector<float, Vc::VectorAbi::Scalar> fvec; + //typedef Vc::SimdArray<float, 4> fvec; + + typedef fvec::EntryType fscal; + typedef fvec::MaskType fmask; + +#define _fvecalignment __attribute__((aligned(Vc::VectorAlignment))) +} // namespace cbm::algo::ca + +/// \brief Serializer for SIMD vectors +namespace boost::serialization +{ + template<class Archive> + void save(Archive& ar, const cbm::algo::ca::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) { buffer[i] = vect[i]; } + ar << buffer; + } + + template<class Archive> + void load(Archive& ar, cbm::algo::ca::fvec& vect, unsigned int) + { + std::array<cbm::algo::ca::fscal, cbm::algo::ca::fvec::size()> buffer; + ar >> buffer; + for (size_t i = 0; i < cbm::algo::ca::fvec::size(); ++i) { + vect[i] = buffer[i]; + } + } + + template<class Archive> + void serialize(Archive& ar, cbm::algo::ca::fvec& vect, const unsigned int version) + { + split_free(ar, vect, version); + } +} + + +#endif diff --git a/reco/L1/CMakeLists.txt b/reco/L1/CMakeLists.txt index c91ad51763..d30f029ba0 100644 --- a/reco/L1/CMakeLists.txt +++ b/reco/L1/CMakeLists.txt @@ -213,7 +213,6 @@ install(FILES CbmL1Counters.h L1Algo/L1ObjectInitController.h #L1Algo/L1Constants.h L1Algo/L1Utils.h - L1Algo/L1SimdSerializer.h L1Algo/L1TrackPar.h utils/CbmCaIdealHitProducer.h utils/CbmCaIdealHitProducerDet.h diff --git a/reco/L1/L1Algo/L1BaseStationInfo.h b/reco/L1/L1Algo/L1BaseStationInfo.h index a23cbb5e7a..cba776b6b4 100644 --- a/reco/L1/L1Algo/L1BaseStationInfo.h +++ b/reco/L1/L1Algo/L1BaseStationInfo.h @@ -18,6 +18,7 @@ // L1 Core #include "L1ObjectInitController.h" #include "L1Station.h" +#include "L1Material.h" // C++ std #include <bitset> #include <functional> diff --git a/reco/L1/L1Algo/L1Field.h b/reco/L1/L1Algo/L1Field.h index 353933a021..dc66cb30a6 100644 --- a/reco/L1/L1Algo/L1Field.h +++ b/reco/L1/L1Algo/L1Field.h @@ -8,8 +8,8 @@ #include <string> #include "CaConstants.h" -#include "L1Def.h" -#include "L1SimdSerializer.h" +#include "CaSimd.h" +#include <boost/serialization/access.hpp> class L1TrackPar; diff --git a/reco/L1/L1Algo/L1InitManager.h b/reco/L1/L1Algo/L1InitManager.h index 6322a03ddb..1a0f5e9fa2 100644 --- a/reco/L1/L1Algo/L1InitManager.h +++ b/reco/L1/L1Algo/L1InitManager.h @@ -26,6 +26,7 @@ #include "L1Parameters.h" #include "L1Utils.h" #include "L1Vector.h" +#include "CaSimd.h" class L1ConfigRW; class L1Algo; diff --git a/reco/L1/L1Algo/L1Material.h b/reco/L1/L1Algo/L1Material.h index 5c3ef784bb..d060c37790 100644 --- a/reco/L1/L1Algo/L1Material.h +++ b/reco/L1/L1Algo/L1Material.h @@ -13,8 +13,7 @@ #include <vector> #include "CaConstants.h" -#include "L1Def.h" -#include "L1SimdSerializer.h" +#include "CaSimd.h" using namespace cbm::algo::ca; diff --git a/reco/L1/L1Algo/L1SimdSerializer.h b/reco/L1/L1Algo/L1SimdSerializer.h deleted file mode 100644 index 79505b8125..0000000000 --- a/reco/L1/L1Algo/L1SimdSerializer.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt - SPDX-License-Identifier: GPL-3.0-only - Authors: Sergey Gorbunov, Sergei Zharko [committer] */ - -/// \file L1SimdSerializer.h -/// \brief External serialization for SIMD vector -/// \since 02.09.2022 -/// \author S.Zharko <s.zharko@gsi.de> - -#ifndef L1SimdSerializer_h -#define L1SimdSerializer_h 1 - -#include <boost/serialization/access.hpp> -#include <boost/serialization/split_free.hpp> - -#include "CaSimd.h" -/// This header defines functionality for saving and loading SIMDized vectors. At the moment, only the first element of -/// the vector can be saved, and the loaded vector will be horizontally equal. -/// -namespace boost -{ - namespace serialization - { - template<class Archive> - void save(Archive& ar, const cbm::algo::ca::fvec& vect, unsigned int) - { - ar << vect[0]; - } - - template<class Archive> - void load(Archive& ar, cbm::algo::ca::fvec& vect, unsigned int) - { - cbm::algo::ca::fscal buffer; - ar >> buffer; - for (size_t i = 0; i < cbm::algo::ca::fvec::size(); ++i) { - vect[i] = buffer; - } - } - - template<class Archive> - void serialize(Archive& ar, cbm::algo::ca::fvec& vect, const unsigned int version) - { - split_free(ar, vect, version); - } - } // namespace serialization -} // namespace boost - -#endif // L1SimdSerializer_h diff --git a/reco/L1/L1Algo/L1Station.h b/reco/L1/L1Algo/L1Station.h index b5b04cb559..62389f9d51 100644 --- a/reco/L1/L1Algo/L1Station.h +++ b/reco/L1/L1Algo/L1Station.h @@ -10,11 +10,8 @@ #include "CaConstants.h" #include "L1Field.h" -#include "L1Material.h" -#include "L1SimdSerializer.h" -#include "L1UMeasurementInfo.h" +#include "CaSimd.h" #include "L1Utils.h" -#include "L1XYMeasurementInfo.h" /// Structure L1Station /// Contains a set of geometry parameters for a particular station @@ -24,7 +21,7 @@ public: // TODO: SZh 12.05.2022: Rewrite type into L1DetectorID, change detector indexing scheme // TODO: SZh 12.05.2022: Provide getters to stations - int type = cbm::algo::ca::constants::undef::Int; + int type = cbm::algo::ca::constants::undef::Int; // ? Detector type? int timeInfo = cbm::algo::ca::constants::undef::Int; ///< flag: if time information can be used int fieldStatus = cbm::algo::ca::constants::undef::Int; ///< flag: 1 - station is INSIDE the field, 0 - station is OUTSIDE the field diff --git a/reco/L1/L1Algo/L1UMeasurementInfo.h b/reco/L1/L1Algo/L1UMeasurementInfo.h index 7390e4af74..0a42c8e794 100644 --- a/reco/L1/L1Algo/L1UMeasurementInfo.h +++ b/reco/L1/L1Algo/L1UMeasurementInfo.h @@ -8,8 +8,8 @@ #include <string> #include "CaConstants.h" +#include "CaSimd.h" #include "L1Def.h" -#include "L1SimdSerializer.h" #include "L1Utils.h" class L1UMeasurementInfo { diff --git a/reco/L1/L1Algo/L1XYMeasurementInfo.h b/reco/L1/L1Algo/L1XYMeasurementInfo.h index 6580a59ae0..34781242d2 100644 --- a/reco/L1/L1Algo/L1XYMeasurementInfo.h +++ b/reco/L1/L1Algo/L1XYMeasurementInfo.h @@ -8,8 +8,8 @@ #include <string> #include "CaConstants.h" +#include "CaSimd.h" #include "L1Def.h" -#include "L1SimdSerializer.h" using namespace cbm::algo::ca; diff --git a/reco/L1/catools/CaToolsMCTrack.h b/reco/L1/catools/CaToolsMCTrack.h index 6b55029a0e..1b50bb7f1b 100644 --- a/reco/L1/catools/CaToolsMCTrack.h +++ b/reco/L1/catools/CaToolsMCTrack.h @@ -154,7 +154,7 @@ namespace ca::tools int GetPdgCode() const { return fPdgCode; } /// Gets azimuthal angle [rad] - double GetPhi() const { return TMath::ATan2(-fMom[1], -fMom[0]); } + double GetPhi() const { return std::atan2(fMom[1], fMom[0]); } /// Gets a reference to associated point indexes const auto& GetPointIndexes() const { return fvPointIndexes; } diff --git a/reco/littrack/parallel/CMakeLists.txt b/reco/littrack/parallel/CMakeLists.txt index 4acecba75e..48d06d4bc1 100644 --- a/reco/littrack/parallel/CMakeLists.txt +++ b/reco/littrack/parallel/CMakeLists.txt @@ -2,7 +2,7 @@ set(INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} - ${CBMROOT_SOURCE_DIR}/algo/ca/core/simd + ${CBMROOT_SOURCE_DIR}/algo/ca/core/utils ) -- GitLab