Skip to content

Commit

Permalink
x and y position calculation in kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Alves committed Jan 21, 2021
1 parent 4773a0a commit 22e19fb
Show file tree
Hide file tree
Showing 61 changed files with 2,383 additions and 966 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
macs -nw 2 ---
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 120
Expand Down
8 changes: 8 additions & 0 deletions CUDADataFormats/HGCal/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<use name="FWCore/Utilities"/>
<use name="Geometry/HGCalGeometry"/>
<use name="HeterogeneousCore/CUDACore"/>
<use name="cuda"/>

<export>
<lib name="1"/>
</export>
73 changes: 36 additions & 37 deletions CUDADataFormats/HGCal/interface/HGCConditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
class HeterogeneousHGCSiliconDetId {
public:
constexpr HeterogeneousHGCSiliconDetId(uint32_t id): id_(id) {}
constexpr uint32_t type() { return (id_ >> kHGCalTypeOffset) & kHGCalTypeMask; }
constexpr int32_t zside() { return (((id_ >> kHGCalZsideOffset) & kHGCalZsideMask) ? -1 : 1); }
constexpr uint32_t layer() { return (id_ >> kHGCalLayerOffset) & kHGCalLayerMask; }
constexpr uint32_t type() { return (id_ >> kHGCalTypeOffset) & kHGCalTypeMask; }
constexpr int32_t zside() { return (((id_ >> kHGCalZsideOffset) & kHGCalZsideMask) ? -1 : 1); }
constexpr uint32_t layer() { return (id_ >> kHGCalLayerOffset) & kHGCalLayerMask; }
constexpr int32_t waferUAbs() { return (id_ >> kHGCalWaferUOffset) & kHGCalWaferUMask; }
constexpr int32_t waferVAbs() { return (id_ >> kHGCalWaferVOffset) & kHGCalWaferVMask; }
constexpr int32_t waferU() { return (((id_ >> kHGCalWaferUSignOffset) & kHGCalWaferUSignMask) ? -waferUAbs() : waferUAbs()); }
constexpr int32_t waferV() { return (((id_ >> kHGCalWaferVSignOffset) & kHGCalWaferVSignMask) ? -waferVAbs() : waferVAbs()); }
constexpr int32_t waferX() { return (-2 * waferU() + waferV()); }
constexpr int32_t waferY() { return (2 * waferV()); }
constexpr int32_t cellU() { return (id_ >> kHGCalCellUOffset) & kHGCalCellUMask; }
constexpr int32_t cellV() { return (id_ >> kHGCalCellVOffset) & kHGCalCellVMask; }
constexpr int32_t cellX() { int N = (type() == HGCalFine) ? HGCalFineN : HGCalCoarseN; return (3 * (cellV() - N) + 2); }
constexpr int32_t cellY() { int N = (type() == HGCalFine) ? HGCalFineN : HGCalCoarseN; return (2 * cellU() - (N + cellV())); }

constexpr int32_t waferU() { return (((id_ >> kHGCalWaferUSignOffset) & kHGCalWaferUSignMask) ? -waferUAbs() : waferUAbs()); }
constexpr int32_t waferV() { return (((id_ >> kHGCalWaferVSignOffset) & kHGCalWaferVSignMask) ? -waferVAbs() : waferVAbs()); }
constexpr int32_t waferX() { return (-2 * waferU() + waferV()); }
constexpr int32_t waferY() { return (2 * waferV()); }
constexpr uint32_t cellU() { return (id_ >> kHGCalCellUOffset) & kHGCalCellUMask; }
constexpr uint32_t cellV() { return (id_ >> kHGCalCellVOffset) & kHGCalCellVMask; }
constexpr uint32_t nCells() { return (type() == HGCalFine) ? HGCalFineN : HGCalCoarseN; }
constexpr int32_t cellX() { const uint32_t N = nCells(); return (3 * (cellV() - N) + 2); }
constexpr int32_t cellY() { const uint32_t N = nCells(); return (2 * cellU() - (N + cellV())); }

private:
uint32_t id_;
enum waferType { HGCalFine = 0, HGCalCoarseThin = 1, HGCalCoarseThick = 2 };
Expand Down Expand Up @@ -116,20 +117,6 @@ namespace hgcal_conditions {
} //namespace parameters

namespace positions {
//stores the positions taken from the detid's in the CPU
struct HGCalPositions {
std::vector<float> x;
std::vector<float> y;
std::vector<float> z;
};

//stores the positions taken from the detid's in the GPU
//it is the same for all three subdetectors
struct HeterogeneousHGCalPositions {
float* x;
float* y;
float* z;
};

enum class HeterogeneousHGCalPositionsType {Float, Int32_t, Uint32_t};

Expand All @@ -140,27 +127,34 @@ namespace hgcal_conditions {
HeterogeneousHGCalPositionsType::Uint32_t };

struct HGCalPositionsMapping {
std::vector<float> z_per_layer;
std::vector<int32_t> numberCellsHexagon;
std::vector<uint32_t> detid;
//variables required for calculating the positions (x,y) from the detid in the GPU
float waferSize;
float sensorSeparation;
//variables required for the mapping of detid -> cell in the geometry
int firstLayer;
int lastLayer;
int waferMax;
int waferMin;
int32_t firstLayer;
int32_t lastLayer;
int32_t waferMax;
int32_t waferMin;
};

struct HeterogeneousHGCalPositionsMapping {
//the x, y and z positions will not be filled in the CPU
float* x;
float* y;
float* z;
float* z_per_layer;
int32_t *numberCellsHexagon;
uint32_t *detid;
//variables required for calculating the positions (x,y) from the detid in the GPU
float waferSize;
float sensorSeparation;
//variables required for the mapping of detid -> cell in the geometry
int firstLayer;
int lastLayer;
int waferMax;
int waferMin;
int32_t firstLayer;
int32_t lastLayer;
int32_t waferMax;
int32_t waferMin;
};

} //namespace positions
Expand All @@ -170,13 +164,18 @@ namespace hgcal_conditions {
};
struct HeterogeneousHEFConditionsESProduct {
parameters::HeterogeneousHGCalHEFParameters params;
positions::HeterogeneousHGCalPositionsMapping posmap;
size_t nelems_posmap;
//positions::HeterogeneousHGCalPositionsMapping posmap;
//size_t nelems_posmap;
};
struct HeterogeneousHEBConditionsESProduct {
parameters::HeterogeneousHGCalHEBParameters params;
};

struct HeterogeneousHEFCellPositionsConditionsESProduct {
positions::HeterogeneousHGCalPositionsMapping posmap;
size_t nelems_posmap;
};

} //namespace conditions

#endif //CUDADataFormats_HGCal_HGCConditions_h
95 changes: 0 additions & 95 deletions CUDADataFormats/HGCal/interface/HGCConstant.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
//maximum sizes for SoA's arrays holding configuration data ("constants")
namespace maxsizes_constants {
//EE
constexpr size_t ee_fCPerMIP = 6; //number of elements pointed by hgcEE_fCPerMIP_
constexpr size_t ee_cce = 6; //number of elements posize_ted by hgcEE_cce_
constexpr size_t ee_noise_fC = 6; //number of elements posize_ted by hgcEE_noise_fC_
constexpr size_t ee_rcorr = 6; //number of elements posize_ted by rcorr_
constexpr size_t ee_weights = 53; //number of elements posize_ted by weights_
constexpr size_t ee_fCPerMIP = 3; //number of elements pointed by hgcEE_fCPerMIP_
constexpr size_t ee_cce = 3; //number of elements pointed by hgcEE_cce_
constexpr size_t ee_noise_fC = 3; //number of elements pointed by hgcEE_noise_fC_
constexpr size_t ee_rcorr = 3; //number of elements pointed by rcorr_
constexpr size_t ee_weights = 51; //number of elements posize_ted by weights_
//HEF
constexpr size_t hef_fCPerMIP = 6; //number of elements pointed by hgcEE_fCPerMIP_
constexpr size_t hef_cce = 6; //number of elements posize_ted by hgcEE_cce_
constexpr size_t hef_noise_fC = 6; //number of elements posize_ted by hgcEE_noise_fC_
constexpr size_t hef_rcorr = 6; //number of elements posize_ted by rcorr_
constexpr size_t hef_weights = 53; //number of elements posize_ted by weights_
constexpr size_t hef_fCPerMIP = 3; //number of elements pointed by hgcEE_fCPerMIP_
constexpr size_t hef_cce = 3; //number of elements pointed by hgcEE_cce_
constexpr size_t hef_noise_fC = 3; //number of elements pointed by hgcEE_noise_fC_
constexpr size_t hef_rcorr = 3; //number of elements pointed by rcorr_
constexpr size_t hef_weights = 51; //number of elements pointed by weights_
//HEB
constexpr size_t heb_weights = 53; //number of elements posize_ted by weights_
constexpr size_t heb_weights = 51; //number of elements pointed by weights_
}

class HGCConstantVectorData {
Expand Down Expand Up @@ -60,6 +60,7 @@ class HGChefUncalibratedRecHitConstantData {
float xmax_; //used for computing the time resolution error
float aterm_; //used for computing the time resolution error
float cterm_; //used for computing the time resolution error
uint32_t layerOffset_; //layer offset relative to layer#1 of the EE subsetector
};

class HGChebUncalibratedRecHitConstantData {
Expand All @@ -69,6 +70,7 @@ class HGChebUncalibratedRecHitConstantData {
double keV2DIGI_; //energy to femto coloumb conversion: 1000 eV/3.62 (eV per e) / 6.24150934e3 (e per fC)
double uncalib2GeV_; //sets the ADC; obtained by dividing 1e-6 by hgcHEB_keV2DIGI_
double noise_MIP_; //noise
uint32_t layerOffset_; //layer offset relative to layer#1 of the EE subsetector
};

#endif
1 change: 1 addition & 0 deletions CondFormats/DataRecord/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<use name="FWCore/Framework"/>
<use name="FWCore/Utilities"/>
<use name="Geometry/Records"/>
<export>
<lib name="1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef CondFormats_DataRecord_HeterogeneousHGCalHEFCellPositionsConditionsRecord_h
#define CondFormats_DataRecord_HeterogeneousHGCalHEFCellPositionsConditionsRecord_h

#include "FWCore/Framework/interface/DependentRecordImplementation.h"
//#include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
#include "Geometry/Records/interface/IdealGeometryRecord.h"
#include "FWCore/Utilities/interface/mplVector.h"

class HeterogeneousHGCalHEFCellPositionsConditionsRecord
: public edm::eventsetup::DependentRecordImplementation<HeterogeneousHGCalHEFCellPositionsConditionsRecord, edm::mpl::Vector<IdealGeometryRecord>> {};

#endif //CondFormats_DataRecord_HeterogeneousHGCalHEFCellPositionsConditionsRecord_h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "CondFormats/DataRecord/interface/HeterogeneousHGCalHEFCellPositionsConditionsRecord.h"
#include "FWCore/Framework/interface/eventsetuprecord_registration_macro.h"

EVENTSETUP_RECORD_REG(HeterogeneousHGCalHEFCellPositionsConditionsRecord);
8 changes: 8 additions & 0 deletions CondFormats/HGCalObjects/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<use name="FWCore/Utilities"/>
<use name="FWCore/MessageLogger"/>
<use name="HeterogeneousCore/CUDACore"/>
<use name="CUDADataFormats/HGCal"/>
<use name="Geometry/HGCalCommonData"/>
<export>
<lib name="1"/>
</export>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#ifndef CondFormats_HGCalObjects_HeterogeneousHGCalHEFConditions_h
#define CondFormats_HGCalObjects_HeterogeneousHGCalHEFConditions_h

#include <numeric> //accumulate
#include <typeinfo>

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "HeterogeneousCore/CUDACore/interface/ESProduct.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
#include "CUDADataFormats/HGCal/interface/HGCConditions.h"
#include "Geometry/HGCalCommonData/interface/HGCalDDDConstants.h"
#include "Geometry/HGCalCommonData/interface/HGCalParameters.h"

namespace cpar = hgcal_conditions::parameters;
namespace cpos = hgcal_conditions::positions;

// Declare the wrapper ESProduct. The corresponding ESProducer should
// produce objects of this type.
class HeterogeneousHGCalHEFCellPositionsConditions {
public:
// Constructor takes the standard CPU ESProduct, and transforms the
// necessary data to array(s) in pinned host memory
HeterogeneousHGCalHEFCellPositionsConditions(cpos::HGCalPositionsMapping*);

// Deallocates all pinned host memory
~HeterogeneousHGCalHEFCellPositionsConditions();

// Function to return the actual payload on the memory of the current device
hgcal_conditions::HeterogeneousHEFCellPositionsConditionsESProduct const *getHeterogeneousConditionsESProductAsync(cudaStream_t stream) const;

private:
// Holds the data in pinned CPU memory
// Contrary to its non-heterogeneous counterpart (constructor argument) it is *not* a pointer (so to avoid an extra allocation)
cpos::HeterogeneousHGCalPositionsMapping posmap_;
size_t nelems_posmap_;

std::vector<size_t> sizes_pos_;
size_t chunk_pos_;
const size_t number_position_arrays = 2; //x and y; required due to the assymetry between cpos::HeterogeneousHGCalPositionsMapping and cpos::HGCalPositionsMapping

std::vector<size_t> calculate_memory_bytes_pos_(cpos::HGCalPositionsMapping*);
size_t allocate_memory_pos_(const std::vector<size_t>&);
void transfer_data_to_heterogeneous_pointers_pos_(const std::vector<size_t>&, cpos::HGCalPositionsMapping*);
void transfer_data_to_heterogeneous_vars_pos_(const cpos::HGCalPositionsMapping*);

/*methods for managing SoA's pointers*/
//float
float*& select_pointer_f_(cpos::HeterogeneousHGCalPositionsMapping*, const unsigned int&) const;
std::vector<float>& select_pointer_f_(cpos::HGCalPositionsMapping*, const unsigned int&);
//int32_t
int32_t*& select_pointer_i_(cpos::HeterogeneousHGCalPositionsMapping*, const unsigned int&) const;
std::vector<int32_t>& select_pointer_i_(cpos::HGCalPositionsMapping*, const unsigned int&);
//uint32_t
uint32_t*& select_pointer_u_(cpos::HeterogeneousHGCalPositionsMapping*, const unsigned int&) const;
std::vector<uint32_t>& select_pointer_u_(cpos::HGCalPositionsMapping*, const unsigned int&);

// Helper struct to hold all information that has to be allocated and
// deallocated per device
struct GPUData {
// Destructor should free all member pointers
~GPUData();
// internal pointers are on device, struct itself is on CPU
hgcal_conditions::HeterogeneousHEFCellPositionsConditionsESProduct *host = nullptr;
// internal pounters and struct are on device
hgcal_conditions::HeterogeneousHEFCellPositionsConditionsESProduct *device = nullptr;
};

// Helper that takes care of complexity of transferring the data to
// multiple devices
cms::cuda::ESProduct<GPUData> gpuData_;
};

#endif //CondFormats_HGCalObjects_HeterogeneousHGCalHEFConditions_h
Loading

0 comments on commit 22e19fb

Please sign in to comment.