Skip to content

Commit

Permalink
Synchronise with CMSSW_11_1_0_patch2
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Jul 12, 2020
2 parents 6c6f82e + 2a223ba commit 3c4a74f
Show file tree
Hide file tree
Showing 449 changed files with 46,075 additions and 706 deletions.
8 changes: 8 additions & 0 deletions CUDADataFormats/BeamSpot/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<use name="rootcore"/>
<use name="CUDADataFormats/Common"/>
<use name="DataFormats/Common"/>
<use name="HeterogeneousCore/CUDAUtilities"/>

<export>
<lib name="1"/>
</export>
32 changes: 32 additions & 0 deletions CUDADataFormats/BeamSpot/interface/BeamSpotCUDA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef CUDADataFormats_BeamSpot_interface_BeamSpotCUDA_h
#define CUDADataFormats_BeamSpot_interface_BeamSpotCUDA_h

#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"

#include <cuda_runtime.h>

class BeamSpotCUDA {
public:
// alignas(128) doesn't really make sense as there is only one
// beamspot per event?
struct Data {
float x, y, z; // position
// TODO: add covariance matrix

float sigmaZ;
float beamWidthX, beamWidthY;
float dxdz, dydz;
float emittanceX, emittanceY;
float betaStar;
};

BeamSpotCUDA() = default;
BeamSpotCUDA(Data const* data_h, cudaStream_t stream);

Data const* data() const { return data_d_.get(); }

private:
cms::cuda::device::unique_ptr<Data> data_d_;
};

#endif
9 changes: 9 additions & 0 deletions CUDADataFormats/BeamSpot/src/BeamSpotCUDA.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "CUDADataFormats/BeamSpot/interface/BeamSpotCUDA.h"

#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"

BeamSpotCUDA::BeamSpotCUDA(Data const* data_h, cudaStream_t stream) {
data_d_ = cms::cuda::make_device_unique<Data>(stream);
cudaCheck(cudaMemcpyAsync(data_d_.get(), data_h, sizeof(Data), cudaMemcpyHostToDevice, stream));
}
8 changes: 8 additions & 0 deletions CUDADataFormats/BeamSpot/src/classes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef CUDADataFormats_BeamSpot_classes_h
#define CUDADataFormats_BeamSpot_classes_h

#include "CUDADataFormats/Common/interface/Product.h"
#include "CUDADataFormats/BeamSpot/interface/BeamSpotCUDA.h"
#include "DataFormats/Common/interface/Wrapper.h"

#endif
4 changes: 4 additions & 0 deletions CUDADataFormats/BeamSpot/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<lcgdict>
<class name="cms::cuda::Product<BeamSpotCUDA>" persistent="false"/>
<class name="edm::Wrapper<cms::cuda::Product<BeamSpotCUDA>>" persistent="false"/>
</lcgdict>
6 changes: 6 additions & 0 deletions CUDADataFormats/CaloCommon/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<use name="CUDADataFormats/Common" />
<use name="HeterogeneousCore/CUDAUtilities"/>

<export>
<lib name="1"/>
</export>
68 changes: 68 additions & 0 deletions CUDADataFormats/CaloCommon/interface/Common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef CUDADataFormats_CaloCommon_interface_Common_h
#define CUDADataFormats_CaloCommon_interface_Common_h

#include <vector>

#include "HeterogeneousCore/CUDAUtilities/interface/HostAllocator.h"
#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"

namespace calo {
namespace common {

// FIXME: not able to get enums to work with genreflex
namespace tags {

struct Vec {};
struct Ptr {};
struct DevPtr {};

} // namespace tags

template <typename tag>
struct AddSize {};

template <>
struct AddSize<tags::Ptr> {
uint32_t size;
};

template <>
struct AddSize<tags::DevPtr> {
uint32_t size;
};

struct ViewStoragePolicy {
using TagType = tags::Ptr;

template <typename T>
struct StorageSelector {
using type = T*;
};
};

struct DevStoragePolicy {
using TagType = tags::DevPtr;

template <typename T>
struct StorageSelector {
using type = cms::cuda::device::unique_ptr<T[]>;
};
};

template <template <typename> typename Allocator = std::allocator>
struct VecStoragePolicy {
using TagType = tags::Vec;

template <typename T>
struct StorageSelector {
using type = std::vector<T, Allocator<T>>;
};
};

template <typename T>
using CUDAHostAllocatorAlias = cms::cuda::HostAllocator<T>;

} // namespace common
} // namespace calo

#endif // CUDADataFormats_CaloCommon_interface_Common_h
2 changes: 2 additions & 0 deletions CUDADataFormats/CaloCommon/src/classes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "DataFormats/Common/interface/Wrapper.h"
#include "CUDADataFormats/CaloCommon/interface/Common.h"
8 changes: 8 additions & 0 deletions CUDADataFormats/CaloCommon/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<lcgdict>
<enum name="calo::common::tags::Ptr"/>
<enum name="calo::common::tags::Vec"/>
<enum name="calo::common::tags::DevPtr"/>
<class name="calo::common::AddSize<calo::common::tags::Ptr>"/>
<class name="calo::common::AddSize<calo::common::tags::Vec>"/>
<class name="calo::common::AddSize<calo::common::tags::DevPtr>"/>
</lcgdict>
12 changes: 12 additions & 0 deletions CUDADataFormats/Common/interface/ArrayShadow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef CUDADataFormatsCommonArrayShadow_H
#define CUDADataFormatsCommonArrayShadow_H
#include <array>

template <typename A>
struct ArrayShadow {
using T = typename A::value_type;
constexpr static auto size() { return std::tuple_size<A>::value; }
T data[std::tuple_size<A>::value];
};

#endif
189 changes: 189 additions & 0 deletions CUDADataFormats/Common/interface/HeterogeneousSoA.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
#ifndef CUDADataFormatsCommonHeterogeneousSoA_H
#define CUDADataFormatsCommonHeterogeneousSoA_H

#include <cassert>

#include "HeterogeneousCore/CUDAUtilities/interface/copyAsync.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"
#include "HeterogeneousCore/CUDAUtilities/interface/host_unique_ptr.h"

// a heterogeneous unique pointer...
template <typename T>
class HeterogeneousSoA {
public:
using Product = T;

HeterogeneousSoA() = default; // make root happy
~HeterogeneousSoA() = default;
HeterogeneousSoA(HeterogeneousSoA &&) = default;
HeterogeneousSoA &operator=(HeterogeneousSoA &&) = default;

explicit HeterogeneousSoA(cms::cuda::device::unique_ptr<T> &&p) : dm_ptr(std::move(p)) {}
explicit HeterogeneousSoA(cms::cuda::host::unique_ptr<T> &&p) : hm_ptr(std::move(p)) {}
explicit HeterogeneousSoA(std::unique_ptr<T> &&p) : std_ptr(std::move(p)) {}

auto const *get() const { return dm_ptr ? dm_ptr.get() : (hm_ptr ? hm_ptr.get() : std_ptr.get()); }

auto const &operator*() const { return *get(); }

auto const *operator-> () const { return get(); }

auto *get() { return dm_ptr ? dm_ptr.get() : (hm_ptr ? hm_ptr.get() : std_ptr.get()); }

auto &operator*() { return *get(); }

auto *operator-> () { return get(); }

// in reality valid only for GPU version...
cms::cuda::host::unique_ptr<T> toHostAsync(cudaStream_t stream) const {
assert(dm_ptr);
auto ret = cms::cuda::make_host_unique<T>(stream);
cudaCheck(cudaMemcpyAsync(ret.get(), dm_ptr.get(), sizeof(T), cudaMemcpyDefault, stream));
return ret;
}

private:
// a union wan't do it, a variant will not be more efficienct
cms::cuda::device::unique_ptr<T> dm_ptr; //!
cms::cuda::host::unique_ptr<T> hm_ptr; //!
std::unique_ptr<T> std_ptr; //!
};

namespace cms {
namespace cudacompat {

struct GPUTraits {
template <typename T>
using unique_ptr = cms::cuda::device::unique_ptr<T>;

template <typename T>
static auto make_unique(cudaStream_t stream) {
return cms::cuda::make_device_unique<T>(stream);
}

template <typename T>
static auto make_unique(size_t size, cudaStream_t stream) {
return cms::cuda::make_device_unique<T>(size, stream);
}

template <typename T>
static auto make_host_unique(cudaStream_t stream) {
return cms::cuda::make_host_unique<T>(stream);
}

template <typename T>
static auto make_device_unique(cudaStream_t stream) {
return cms::cuda::make_device_unique<T>(stream);
}

template <typename T>
static auto make_device_unique(size_t size, cudaStream_t stream) {
return cms::cuda::make_device_unique<T>(size, stream);
}
};

struct HostTraits {
template <typename T>
using unique_ptr = cms::cuda::host::unique_ptr<T>;

template <typename T>
static auto make_unique(cudaStream_t stream) {
return cms::cuda::make_host_unique<T>(stream);
}

template <typename T>
static auto make_host_unique(cudaStream_t stream) {
return cms::cuda::make_host_unique<T>(stream);
}

template <typename T>
static auto make_device_unique(cudaStream_t stream) {
return cms::cuda::make_device_unique<T>(stream);
}

template <typename T>
static auto make_device_unique(size_t size, cudaStream_t stream) {
return cms::cuda::make_device_unique<T>(size, stream);
}
};

struct CPUTraits {
template <typename T>
using unique_ptr = std::unique_ptr<T>;

template <typename T>
static auto make_unique(cudaStream_t) {
return std::make_unique<T>();
}

template <typename T>
static auto make_unique(size_t size, cudaStream_t) {
return std::make_unique<T>(size);
}

template <typename T>
static auto make_host_unique(cudaStream_t) {
return std::make_unique<T>();
}

template <typename T>
static auto make_device_unique(cudaStream_t) {
return std::make_unique<T>();
}

template <typename T>
static auto make_device_unique(size_t size, cudaStream_t) {
return std::make_unique<T>(size);
}
};

} // namespace cudacompat
} // namespace cms

// a heterogeneous unique pointer (of a different sort) ...
template <typename T, typename Traits>
class HeterogeneousSoAImpl {
public:
template <typename V>
using unique_ptr = typename Traits::template unique_ptr<V>;

HeterogeneousSoAImpl() = default; // make root happy
~HeterogeneousSoAImpl() = default;
HeterogeneousSoAImpl(HeterogeneousSoAImpl &&) = default;
HeterogeneousSoAImpl &operator=(HeterogeneousSoAImpl &&) = default;

explicit HeterogeneousSoAImpl(unique_ptr<T> &&p) : m_ptr(std::move(p)) {}
explicit HeterogeneousSoAImpl(cudaStream_t stream);

T const *get() const { return m_ptr.get(); }

T *get() { return m_ptr.get(); }

cms::cuda::host::unique_ptr<T> toHostAsync(cudaStream_t stream) const;

private:
unique_ptr<T> m_ptr; //!
};

template <typename T, typename Traits>
HeterogeneousSoAImpl<T, Traits>::HeterogeneousSoAImpl(cudaStream_t stream) {
m_ptr = Traits::template make_unique<T>(stream);
}

// in reality valid only for GPU version...
template <typename T, typename Traits>
cms::cuda::host::unique_ptr<T> HeterogeneousSoAImpl<T, Traits>::toHostAsync(cudaStream_t stream) const {
auto ret = cms::cuda::make_host_unique<T>(stream);
cudaCheck(cudaMemcpyAsync(ret.get(), get(), sizeof(T), cudaMemcpyDefault, stream));
return ret;
}

template <typename T>
using HeterogeneousSoAGPU = HeterogeneousSoAImpl<T, cms::cudacompat::GPUTraits>;
template <typename T>
using HeterogeneousSoACPU = HeterogeneousSoAImpl<T, cms::cudacompat::CPUTraits>;
template <typename T>
using HeterogeneousSoAHost = HeterogeneousSoAImpl<T, cms::cudacompat::HostTraits>;

#endif
29 changes: 29 additions & 0 deletions CUDADataFormats/Common/interface/HostProduct.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef CUDADataFormatsCommonHostProduct_H
#define CUDADataFormatsCommonHostProduct_H

#include "HeterogeneousCore/CUDAUtilities/interface/host_unique_ptr.h"

// a heterogeneous unique pointer...
template <typename T>
class HostProduct {
public:
HostProduct() = default; // make root happy
~HostProduct() = default;
HostProduct(HostProduct&&) = default;
HostProduct& operator=(HostProduct&&) = default;

explicit HostProduct(cms::cuda::host::unique_ptr<T>&& p) : hm_ptr(std::move(p)) {}
explicit HostProduct(std::unique_ptr<T>&& p) : std_ptr(std::move(p)) {}

auto const* get() const { return hm_ptr ? hm_ptr.get() : std_ptr.get(); }

auto const& operator*() const { return *get(); }

auto const* operator-> () const { return get(); }

private:
cms::cuda::host::unique_ptr<T> hm_ptr; //!
std::unique_ptr<T> std_ptr; //!
};

#endif
8 changes: 8 additions & 0 deletions CUDADataFormats/EcalDigi/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<use name="CUDADataFormats/Common"/>
<use name="CUDADataFormats/CaloCommon"/>
<use name="DataFormats/Common"/>
<use name="HeterogeneousCore/CUDAUtilities"/>

<export>
<lib name="1"/>
</export>
Loading

0 comments on commit 3c4a74f

Please sign in to comment.