-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Squash all Patatrack developments on top of CMSSW_11_3_0_pre5 #27983
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<use name="cuda"/> | ||
<use name="rootcore"/> | ||
<use name="CUDADataFormats/Common"/> | ||
<use name="DataFormats/Common"/> | ||
<use name="HeterogeneousCore/CUDAUtilities"/> | ||
<use name="eigen"/> | ||
<export> | ||
<lib name="1"/> | ||
</export> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef CUDADataFormats_Track_PixelTrackHeterogeneous_h | ||
#define CUDADataFormats_Track_PixelTrackHeterogeneous_h | ||
|
||
#include "CUDADataFormats/Common/interface/HeterogeneousSoA.h" | ||
#include "CUDADataFormats/Track/interface/TrackSoAHeterogeneousT.h" | ||
|
||
using PixelTrackHeterogeneous = HeterogeneousSoA<pixelTrack::TrackSoA>; | ||
|
||
#endif // #ifndef CUDADataFormats_Track_PixelTrackHeterogeneous_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#ifndef CUDADataFormats_Track_TrackHeterogeneousT_H | ||
#define CUDADataFormats_Track_TrackHeterogeneousT_H | ||
|
||
#include "CUDADataFormats/Track/interface/TrajectoryStateSoAT.h" | ||
#include "HeterogeneousCore/CUDAUtilities/interface/HistoContainer.h" | ||
|
||
#include "CUDADataFormats/Common/interface/HeterogeneousSoA.h" | ||
|
||
namespace pixelTrack { | ||
enum class Quality : uint8_t { bad = 0, dup, loose, strict, tight, highPurity }; | ||
} | ||
|
||
template <int32_t S> | ||
class TrackSoAHeterogeneousT { | ||
public: | ||
static constexpr int32_t stride() { return S; } | ||
|
||
using Quality = pixelTrack::Quality; | ||
using hindex_type = uint32_t; | ||
using HitContainer = cms::cuda::OneToManyAssoc<hindex_type, S, 5 * S>; | ||
|
||
// Always check quality is at least loose! | ||
// CUDA does not support enums in __lgc ... | ||
private: | ||
eigenSoA::ScalarSoA<uint8_t, S> quality_; | ||
|
||
public: | ||
constexpr Quality quality(int32_t i) const { return (Quality)(quality_(i)); } | ||
constexpr Quality &quality(int32_t i) { return (Quality &)(quality_(i)); } | ||
constexpr Quality const *qualityData() const { return (Quality const *)(quality_.data()); } | ||
constexpr Quality *qualityData() { return (Quality *)(quality_.data()); } | ||
|
||
// this is chi2/ndof as not necessarely all hits are used in the fit | ||
eigenSoA::ScalarSoA<float, S> chi2; | ||
|
||
constexpr int nHits(int i) const { return detIndices.size(i); } | ||
|
||
// State at the Beam spot | ||
// phi,tip,1/pt,cotan(theta),zip | ||
TrajectoryStateSoAT<S> stateAtBS; | ||
eigenSoA::ScalarSoA<float, S> eta; | ||
eigenSoA::ScalarSoA<float, S> pt; | ||
constexpr float charge(int32_t i) const { return std::copysign(1.f, stateAtBS.state(i)(2)); } | ||
constexpr float phi(int32_t i) const { return stateAtBS.state(i)(0); } | ||
constexpr float tip(int32_t i) const { return stateAtBS.state(i)(1); } | ||
constexpr float zip(int32_t i) const { return stateAtBS.state(i)(4); } | ||
|
||
// state at the detector of the outermost hit | ||
// representation to be decided... | ||
// not yet filled on GPU | ||
// TrajectoryStateSoA<S> stateAtOuterDet; | ||
|
||
HitContainer hitIndices; | ||
HitContainer detIndices; | ||
}; | ||
|
||
namespace pixelTrack { | ||
|
||
#ifdef GPU_SMALL_EVENTS | ||
// kept for testing and debugging | ||
constexpr uint32_t maxNumber() { return 2 * 1024; } | ||
#else | ||
// tested on MC events with 55-75 pileup events | ||
constexpr uint32_t maxNumber() { return 32 * 1024; } | ||
#endif | ||
|
||
using TrackSoA = TrackSoAHeterogeneousT<maxNumber()>; | ||
using TrajectoryState = TrajectoryStateSoAT<maxNumber()>; | ||
using HitContainer = TrackSoA::HitContainer; | ||
|
||
} // namespace pixelTrack | ||
|
||
#endif // CUDADataFormats_Track_TrackHeterogeneousT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef CUDADataFormats_Track_TrajectoryStateSOAT_H | ||
#define CUDADataFormats_Track_TrajectoryStateSOAT_H | ||
|
||
#include <Eigen/Dense> | ||
#include "HeterogeneousCore/CUDAUtilities/interface/eigenSoA.h" | ||
|
||
template <int32_t S> | ||
struct TrajectoryStateSoAT { | ||
using Vector5f = Eigen::Matrix<float, 5, 1>; | ||
using Vector15f = Eigen::Matrix<float, 15, 1>; | ||
|
||
using Vector5d = Eigen::Matrix<double, 5, 1>; | ||
using Matrix5d = Eigen::Matrix<double, 5, 5>; | ||
|
||
static constexpr int32_t stride() { return S; } | ||
|
||
eigenSoA::MatrixSoA<Vector5f, S> state; | ||
eigenSoA::MatrixSoA<Vector15f, S> covariance; | ||
|
||
template <typename V3, typename M3, typename V2, typename M2> | ||
__host__ __device__ inline void copyFromCircle( | ||
V3 const& cp, M3 const& ccov, V2 const& lp, M2 const& lcov, float b, int32_t i) { | ||
state(i) << cp.template cast<float>(), lp.template cast<float>(); | ||
state(i)(2) *= b; | ||
auto cov = covariance(i); | ||
cov(0) = ccov(0, 0); | ||
cov(1) = ccov(0, 1); | ||
cov(2) = b * float(ccov(0, 2)); | ||
cov(4) = cov(3) = 0; | ||
cov(5) = ccov(1, 1); | ||
cov(6) = b * float(ccov(1, 2)); | ||
cov(8) = cov(7) = 0; | ||
cov(9) = b * b * float(ccov(2, 2)); | ||
cov(11) = cov(10) = 0; | ||
cov(12) = lcov(0, 0); | ||
cov(13) = lcov(0, 1); | ||
cov(14) = lcov(1, 1); | ||
} | ||
|
||
template <typename V5, typename M5> | ||
__host__ __device__ inline void copyFromDense(V5 const& v, M5 const& cov, int32_t i) { | ||
state(i) = v.template cast<float>(); | ||
for (int j = 0, ind = 0; j < 5; ++j) | ||
for (auto k = j; k < 5; ++k) | ||
covariance(i)(ind++) = cov(j, k); | ||
} | ||
|
||
template <typename V5, typename M5> | ||
__host__ __device__ inline void copyToDense(V5& v, M5& cov, int32_t i) const { | ||
v = state(i).template cast<typename V5::Scalar>(); | ||
for (int j = 0, ind = 0; j < 5; ++j) { | ||
cov(j, j) = covariance(i)(ind++); | ||
for (auto k = j + 1; k < 5; ++k) | ||
cov(k, j) = cov(j, k) = covariance(i)(ind++); | ||
} | ||
} | ||
}; | ||
|
||
#endif // CUDADataFormats_Track_TrajectoryStateSOAT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef CUDADataFormats_Track_src_classes_h | ||
#define CUDADataFormats_Track_src_classes_h | ||
|
||
#include "CUDADataFormats/Common/interface/Product.h" | ||
#include "CUDADataFormats/Common/interface/HostProduct.h" | ||
#include "CUDADataFormats/Track/interface/TrackSoAHeterogeneousT.h" | ||
#include "DataFormats/Common/interface/Wrapper.h" | ||
|
||
#endif // CUDADataFormats_Track_src_classes_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<lcgdict> | ||
<class name="cms::cuda::Product<HeterogeneousSoA<pixelTrack::TrackSoA>>" persistent="false"/> | ||
<class name="edm::Wrapper<cms::cuda::Product<HeterogeneousSoA<pixelTrack::TrackSoA>>>" persistent="false"/> | ||
<class name="HeterogeneousSoA<pixelTrack::TrackSoA>" persistent="false"/> | ||
<class name="edm::Wrapper<HeterogeneousSoA<pixelTrack::TrackSoA>>" persistent="false"/> | ||
</lcgdict> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<use name="HeterogeneousCore/CUDAUtilities"/> | ||
|
||
<bin file="TrajectoryStateSOA_t.cpp" name="cpuTrajectoryStateSOA_t"> | ||
<use name="eigen"/> | ||
<flags CXXFLAGS="-g -DGPU_DEBUG"/> | ||
</bin> | ||
|
||
<bin file="TrajectoryStateSOA_t.cu" name="gpuTrajectoryStateSOA_t"> | ||
<use name="eigen"/> | ||
<flags CUDA_FLAGS="-g -DGPU_DEBUG"/> | ||
<flags CXXFLAGS="-g -DGPU_DEBUG"/> | ||
</bin> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "TrajectoryStateSOA_t.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "TrajectoryStateSOA_t.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include "CUDADataFormats/Track/interface/TrajectoryStateSoAT.h" | ||
|
||
using Vector5d = Eigen::Matrix<double, 5, 1>; | ||
using Matrix5d = Eigen::Matrix<double, 5, 5>; | ||
|
||
__host__ __device__ Matrix5d loadCov(Vector5d const& e) { | ||
Matrix5d cov; | ||
for (int i = 0; i < 5; ++i) | ||
cov(i, i) = e(i) * e(i); | ||
for (int i = 0; i < 5; ++i) { | ||
for (int j = 0; j < i; ++j) { | ||
double v = 0.3 * std::sqrt(cov(i, i) * cov(j, j)); // this makes the matrix pos defined | ||
cov(i, j) = (i + j) % 2 ? -0.4 * v : 0.1 * v; | ||
cov(j, i) = cov(i, j); | ||
} | ||
} | ||
return cov; | ||
} | ||
|
||
using TS = TrajectoryStateSoAT<128>; | ||
|
||
__global__ void testTSSoA(TS* pts, int n) { | ||
assert(n <= 128); | ||
|
||
Vector5d par0; | ||
par0 << 0.2, 0.1, 3.5, 0.8, 0.1; | ||
Vector5d e0; | ||
e0 << 0.01, 0.01, 0.035, -0.03, -0.01; | ||
auto cov0 = loadCov(e0); | ||
|
||
TS& ts = *pts; | ||
|
||
int first = threadIdx.x + blockIdx.x * blockDim.x; | ||
|
||
for (int i = first; i < n; i += blockDim.x * gridDim.x) { | ||
ts.copyFromDense(par0, cov0, i); | ||
Vector5d par1; | ||
Matrix5d cov1; | ||
ts.copyToDense(par1, cov1, i); | ||
Vector5d delV = par1 - par0; | ||
Matrix5d delM = cov1 - cov0; | ||
for (int j = 0; j < 5; ++j) { | ||
assert(std::abs(delV(j)) < 1.e-5); | ||
for (auto k = j; k < 5; ++k) { | ||
assert(cov0(k, j) == cov0(j, k)); | ||
assert(cov1(k, j) == cov1(j, k)); | ||
assert(std::abs(delM(k, j)) < 1.e-5); | ||
} | ||
} | ||
} | ||
} | ||
|
||
#ifdef __CUDACC__ | ||
#include "HeterogeneousCore/CUDAUtilities/interface/requireDevices.h" | ||
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h" | ||
#endif | ||
|
||
int main() { | ||
#ifdef __CUDACC__ | ||
cms::cudatest::requireDevices(); | ||
#endif | ||
|
||
TS ts; | ||
|
||
#ifdef __CUDACC__ | ||
TS* ts_d; | ||
cudaCheck(cudaMalloc(&ts_d, sizeof(TS))); | ||
testTSSoA<<<1, 64>>>(ts_d, 128); | ||
cudaCheck(cudaGetLastError()); | ||
cudaCheck(cudaMemcpy(&ts, ts_d, sizeof(TS), cudaMemcpyDefault)); | ||
cudaCheck(cudaDeviceSynchronize()); | ||
#else | ||
testTSSoA(&ts, 128); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<use name="cuda"/> | ||
<use name="rootcore"/> | ||
<use name="CUDADataFormats/Common"/> | ||
<use name="DataFormats/Common"/> | ||
<use name="HeterogeneousCore/CUDAUtilities"/> | ||
<use name="eigen"/> | ||
<export> | ||
<lib name="1"/> | ||
</export> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef CUDADataFormatsVertexZVertexHeterogeneous_H | ||
#define CUDADataFormatsVertexZVertexHeterogeneous_H | ||
|
||
#include "CUDADataFormats/Vertex/interface/ZVertexSoA.h" | ||
#include "CUDADataFormats/Common/interface/HeterogeneousSoA.h" | ||
#include "CUDADataFormats/Track/interface/PixelTrackHeterogeneous.h" | ||
|
||
using ZVertexHeterogeneous = HeterogeneousSoA<ZVertexSoA>; | ||
#ifndef __CUDACC__ | ||
#include "CUDADataFormats/Common/interface/Product.h" | ||
using ZVertexCUDAProduct = cms::cuda::Product<ZVertexHeterogeneous>; | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef CUDADataFormatsVertexZVertexSoA_H | ||
#define CUDADataFormatsVertexZVertexSoA_H | ||
|
||
#include <cstdint> | ||
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCompat.h" | ||
|
||
// SOA for vertices | ||
// These vertices are clusterized and fitted only along the beam line (z) | ||
// to obtain their global coordinate the beam spot position shall be added (eventually correcting for the beam angle as well) | ||
struct ZVertexSoA { | ||
static constexpr uint32_t MAXTRACKS = 32 * 1024; | ||
static constexpr uint32_t MAXVTX = 1024; | ||
|
||
int16_t idv[MAXTRACKS]; // vertex index for each associated (original) track (-1 == not associate) | ||
float zv[MAXVTX]; // output z-posistion of found vertices | ||
float wv[MAXVTX]; // output weight (1/error^2) on the above | ||
float chi2[MAXVTX]; // vertices chi2 | ||
float ptv2[MAXVTX]; // vertices pt^2 | ||
int32_t ndof[MAXTRACKS]; // vertices number of dof (reused as workspace for the number of nearest neighbours FIXME) | ||
uint16_t sortInd[MAXVTX]; // sorted index (by pt2) ascending | ||
uint32_t nvFinal; // the number of vertices | ||
|
||
__host__ __device__ void init() { nvFinal = 0; } | ||
}; | ||
|
||
#endif // CUDADataFormatsVertexZVertexSoA.H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef CUDADataFormats__src_classes_h | ||
#define CUDADataFormats__src_classes_h | ||
|
||
#include "CUDADataFormats/Vertex/interface/ZVertexHeterogeneous.h" | ||
#include "CUDADataFormats/Common/interface/Product.h" | ||
#include "DataFormats/Common/interface/Wrapper.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<lcgdict> | ||
<class name="cms::cuda::Product<ZVertexHeterogeneous>" persistent="false"/> | ||
<class name="edm::Wrapper<ZVertexCUDAProduct>" persistent="false"/> | ||
<class name="ZVertexHeterogeneous" persistent="false"/> | ||
<class name="edm::Wrapper<ZVertexHeterogeneous>" persistent="false"/> | ||
</lcgdict> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fwyzard , can you please add cuda-gcc-support protection [a] for cuda released build products
[a]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I'm getting to the point where I will simply stop caring about the integration in CMSSW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the build system should figure out by itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a good point @VinInn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smuzaffar , on architectures / compiler versions that do not support CUDA, like GCC 9, can we simply not build the CUDA externals, and automatically disable everything that depends on it ?
@makortel if we actually do this, would it be a reason to split the CUDA code into seprate libraries and plugins ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, yes.
If we use Alpaka or similar, we may end up with
.cc
files that need to be compiled by NVCC (or with.cu
files that include.cc
files).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the framework perspective not really (not sure if the split would make the life easier for the build system, ok libraries could make sense anyway). As outlined in #28576 (comment), if we want a portable configuration, the framework needs to be able to construct all EDModules and ESProducers for all the platforms the configuration supports. I.e. the CUDA EDProducers need to exist even when we can't build CUDA, implying that the pieces of code depending on CUDA needs to be protected with
#ifdef
s.(not my favorite solution, but this is where we are today)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but then the build system should be otherwise aware (either by explicit rules in the
BuildFile.xml
, or by built-in logic) whether to build for the CUDA backend or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what is worth, I really don't like this approach.
At this point, I think that the requirement to have unique hashes for the configuration is doing more harm to the process than (any ?) good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I replied in #28576 (comment).
We can certainly discuss this subject in a Core Software meeting (today or later).