Skip to content

Commit 6cff8be

Browse files
committed
cleanup
1 parent 03a7526 commit 6cff8be

File tree

8 files changed

+53
-186
lines changed

8 files changed

+53
-186
lines changed

Core/interface/SonicClientBase.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ class SonicClientBase {
2828
}
2929

3030
void finish(std::exception_ptr eptr = std::exception_ptr{}) {
31-
/*unsigned int clientTime = 0;
3231
if(setTime_){
3332
auto t1 = std::chrono::high_resolution_clock::now();
34-
clientTime = (unsigned int)std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0_).count();
35-
}*/
33+
edm::LogInfo(debugName_) << "Client time: " << std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0_).count();
34+
}
3635
holder_.doneWaiting(eptr);
3736
}
3837

Core/interface/SonicEDProducer.h

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
#include "FWCore/Framework/interface/EventSetup.h"
88
#include "FWCore/Concurrency/interface/WaitingTaskWithArenaHolder.h"
99
#include "FWCore/MessageLogger/interface/MessageLogger.h"
10-
#include <sstream>
10+
1111
#include <string>
1212
#include <chrono>
13-
#include <fstream>
1413

1514
//this is a stream producer because client operations are not multithread-safe in general
1615
//it is designed such that the user never has to interact with the client or the acquire() callback directly
@@ -21,40 +20,17 @@ class SonicEDProducer : public edm::stream::EDProducer<edm::ExternalWork, Capabi
2120
typedef typename Client::Input Input;
2221
typedef typename Client::Output Output;
2322
//constructor
24-
SonicEDProducer(edm::ParameterSet const& cfg) : client_(cfg.getParameter<edm::ParameterSet>("Client")) {
25-
sumLoadTime = 0;
26-
numLoadTime = 0;
27-
}
28-
23+
SonicEDProducer(edm::ParameterSet const& cfg) : client_(cfg.getParameter<edm::ParameterSet>("Client")) {}
2924
//destructor
30-
~SonicEDProducer() {
31-
/*
32-
std::stringstream msg;
33-
msg << "Produced by SonicEDProducer" << std::endl;
34-
if (numLoadTime == 0) {
35-
msg << "numLoadTime was 0." << std::endl;
36-
}
37-
else {
38-
msg << "Load time: " << float(sumLoadTime) / numLoadTime << std::endl;
39-
}
40-
41-
writeData(&msg);
42-
43-
std::ofstream file("./data/producer-data.dat");
44-
file << msg.str();
45-
file.close();*/
46-
}
25+
virtual ~SonicEDProducer() {}
4726

4827
//derived classes use a dedicated acquire() interface that incorporates client_.input()
4928
//(no need to interact with callback holder)
5029
void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, edm::WaitingTaskWithArenaHolder holder) override final {
5130
auto t0 = std::chrono::high_resolution_clock::now();
5231
acquire(iEvent, iSetup, client_.input());
5332
auto t1 = std::chrono::high_resolution_clock::now();
54-
if(!debugName_.empty()) {
55-
sumLoadTime += (unsigned int)std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
56-
numLoadTime++;
57-
}
33+
if(!debugName_.empty()) edm::LogInfo(debugName_) << "Load time: " << std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count();
5834
client_.predict(holder);
5935
}
6036
virtual void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) = 0;
@@ -74,11 +50,6 @@ class SonicEDProducer : public edm::stream::EDProducer<edm::ExternalWork, Capabi
7450
//members
7551
Client client_;
7652
std::string debugName_;
77-
78-
private:
79-
virtual void writeData(std::stringstream* msg) {}
80-
unsigned int sumLoadTime;
81-
unsigned int numLoadTime;
8253
};
8354

8455
#endif

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ For this branch, please use the following script to set up the work area:
66
```
77
wget https://raw.githubusercontent.com/hls-fpga-machine-learning/SonicCMS/master/setup.sh
88
chmod +x setup.sh
9-
./setup.sh -f jeffkrupa -j 4 -p TensorRT
9+
./setup.sh
1010
cd CMSSW_10_6_6/src
1111
cmsenv
1212
```

TensorRT/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
Remote mode:
22
```
33
cd python
4-
cmsRun HcalTest_mc_cfg.py maxEvents=25 port=<port> address=<server address> batchsize=16000 modelname=facile maxEvents=10
4+
cmsRun HcalTest_mc_cfg.py maxEvents=25 port=<port> address=<server_ip> batchsize=16000 modelname=facile maxEvents=10
55
```
66

77
All the different client options can be tested with an additional argument:
88
`mode=Async` (default), `mode=Sync`, `mode=PseudoAsync`.
99

1010
Other available servers:
1111
* `prp-gpu-1.t2.ucsd.edu`
12-
13-
## Timing
14-
Some timing data will be recorded in `SonicCMS/TensorRT/python/data`. The most interesting timing data is stored in `client-data.dat`. Some parts of `TRTClient.cc` have commented-out lines of code which could collect timing data, but since we have not yet needed that data, it is not saved to the file. This could be easily remedied.
15-
16-

TensorRT/plugins/HcalPhase1Reconstructor_FACILE.cc

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ class HcalPhase1Reconstructor_FACILE : public SonicEDProducer<Client>
132132
fTokChanInfo(this->template consumes<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>> >(fChanInfoName)),
133133
fTokDigis(this->template consumes<QIE11DigiCollection>(fDigiName))
134134
{
135-
136-
137135
this->template produces<HBHERecHitCollection>();
138136
this->setDebugName("HcalPhase1Reconstructor_FACILE");
139137
}
@@ -151,61 +149,54 @@ class HcalPhase1Reconstructor_FACILE : public SonicEDProducer<Client>
151149

152150
tmp->clear();
153151

154-
processData<QIE11DataFrame>(*digis, *conditions, iInput, ninput);
155-
152+
processData<QIE11DataFrame>(*digis, *conditions, iInput, ninput);
156153
}
157154

158155
template<class DFrame, class Collection>
159156
void processData(const Collection& coll,
160-
const HcalDbService& cond,
161-
Input& iInput,
162-
auto ninput)
157+
const HcalDbService& cond,
158+
Input& iInput,
159+
auto ninput)
163160
{
164-
165161
const bool skipDroppedChannels = false;
166162

167163
unsigned int ib = 0;
168164
for (typename Collection::const_iterator it = coll.begin(); it != coll.end(); it++){
169-
170-
171-
172165
unsigned int ib = std::distance(coll.begin(),it);
173166

174-
const DFrame& frame(*it);
175-
const HcalDetId cell(frame.id());
167+
const DFrame& frame(*it);
168+
const HcalDetId cell(frame.id());
176169

177-
const HcalSubdetector subdet = cell.subdet();
178-
if (!(subdet == HcalSubdetector::HcalBarrel ||
179-
subdet == HcalSubdetector::HcalEndcap ||
180-
subdet == HcalSubdetector::HcalOuter))
181-
continue;
170+
const HcalSubdetector subdet = cell.subdet();
171+
if (!(subdet == HcalSubdetector::HcalBarrel ||
172+
subdet == HcalSubdetector::HcalEndcap ||
173+
subdet == HcalSubdetector::HcalOuter))
174+
continue;
182175

183176
const HcalCalibrations& calib = cond.getHcalCalibrations(cell);
184-
const HcalQIECoder* channelCoder = cond.getHcalCoder(cell);
185-
const HcalQIEShape* shape = cond.getHcalShape(channelCoder);
186-
const HcalCoderDb coder(*channelCoder, *shape);
177+
const HcalQIECoder* channelCoder = cond.getHcalCoder(cell);
178+
const HcalQIEShape* shape = cond.getHcalShape(channelCoder);
179+
const HcalCoderDb coder(*channelCoder, *shape);
187180

188181
CaloSamples cs;
189-
coder.adc2fC(frame, cs);
190-
182+
coder.adc2fC(frame, cs);
191183

192184
const int nRead = cs.size();
193-
const int maxTS = std::min(nRead, static_cast<int>(HBHEChannelInfo::MAXSAMPLES));
185+
const int maxTS = std::min(nRead, static_cast<int>(HBHEChannelInfo::MAXSAMPLES));
194186

195187
const int soi = 3;
196188
const int nCycles = 8;
197-
const RawChargeFromSample<DFrame> rcfs(sipmQTSShift_, sipmQNTStoSum_,
198-
cond, cell, cs, soi, frame, maxTS);
199-
189+
const RawChargeFromSample<DFrame> rcfs(sipmQTSShift_, sipmQNTStoSum_,
190+
cond, cell, cs, soi, frame, maxTS);
200191

201192
iInput[ib*ninput + 0] = (float)cell.iphi();
202193
for (int inputTS = 0; inputTS < nCycles; ++inputTS){
203194
auto s(frame[inputTS]);
204195
const uint8_t adc = s.adc();
205196
const int capid = s.capid();
206-
const double gain = calib.respcorrgain(capid);
197+
const double gain = calib.respcorrgain(capid);
207198
iInput[ib*ninput + 1] = (float)gain;
208-
const double rawCharge = rcfs.getRawCharge(cs[inputTS], calib.pedestal(capid));
199+
const double rawCharge = rcfs.getRawCharge(cs[inputTS], calib.pedestal(capid));
209200
iInput[ib*ninput+inputTS+2] = ((float)rawCharge);
210201
}
211202
for(unsigned int d = 1; d < 8; d++){
@@ -222,9 +213,7 @@ class HcalPhase1Reconstructor_FACILE : public SonicEDProducer<Client>
222213
}
223214
}
224215
void produce(edm::Event& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) override {
225-
226-
227-
std::unique_ptr<HBHERecHitCollection> out;
216+
std::unique_ptr<HBHERecHitCollection> out;
228217
out = std::make_unique<HBHERecHitCollection>();
229218

230219
unsigned int ib = 0;
@@ -241,55 +230,24 @@ class HcalPhase1Reconstructor_FACILE : public SonicEDProducer<Client>
241230
~HcalPhase1Reconstructor_FACILE() override {}
242231

243232
private:
244-
245-
246-
247233
int sipmQTSShift_;
248234
int sipmQNTStoSum_;
249235
unsigned topN_;
250-
edm::InputTag fDigiName;
251-
edm::InputTag fRHName;
252-
edm::InputTag fChanInfoName;
253-
edm::EDGetTokenT<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> fTokRH;
254-
edm::EDGetTokenT<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>>> fTokChanInfo;
255-
edm::EDGetTokenT<QIE11DigiCollection> fTokDigis;
256-
257-
std::vector<HBHERecHit> tmprh;
236+
edm::InputTag fDigiName;
237+
edm::InputTag fRHName;
238+
edm::InputTag fChanInfoName;
239+
edm::EDGetTokenT<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> fTokRH;
240+
edm::EDGetTokenT<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>>> fTokChanInfo;
241+
edm::EDGetTokenT<QIE11DigiCollection> fTokDigis;
242+
243+
std::vector<HBHERecHit> tmprh;
258244
std::vector<HBHERecHit> *tmp = &tmprh;
259245

260246
float depth, ieta, iphi;
261247

262248
using SonicEDProducer<Client>::client_;
263-
template<unsigned int B, unsigned int I>
264-
unsigned short f_to_ui(float f) {
265-
bool isPos = f > 0.;
266-
short tmpIs = int(fabs(f));
267-
unsigned short tmpI = tmpIs;
268-
if (not isPos) {
269-
unsigned short comp = ((unsigned short)((1<<(sizeof(unsigned short)*4-I+1))-1)<<I);
270-
tmpI = -tmpIs;
271-
tmpI = tmpI-comp;
272-
}
273-
float tmpF = fabs(f) - float(tmpIs);
274-
unsigned short fracs = tmpF*float(1<<(B-I));
275-
unsigned short val = (tmpI << (B-I)) + fracs;
276-
return val;
277-
}
278-
template<unsigned int B, unsigned int I>
279-
float ui_to_f(const unsigned short ui) {
280-
unsigned short i = ui >> (B-I);
281-
unsigned short mask = (1 << (B-I))-1;
282-
unsigned short dec = ui & mask;
283-
float lDec = float(dec)/float(1 << (B-I));
284-
return float(i)+lDec;
285-
}
286-
uint32_t merge(unsigned short iA,unsigned short iB) {
287-
uint32_t result = (uint32_t) iA << 16 | iB;
288-
return result;
289-
}
290249
};
291250

292-
293251
typedef HcalPhase1Reconstructor_FACILE<TRTClientSync> HcalPhase1Reconstructor_FACILESync;
294252
typedef HcalPhase1Reconstructor_FACILE<TRTClientAsync> HcalPhase1Reconstructor_FACILEAsync;
295253
typedef HcalPhase1Reconstructor_FACILE<TRTClientPseudoAsync> HcalPhase1Reconstructor_FACILEPseudoAsync;

TensorRT/plugins/HcalProducer.cc

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -45,58 +45,36 @@ class HcalProducer : public SonicEDProducer<Client>
4545
fTokRH(this->template consumes<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>> >(fRHName)),
4646
fTokChanInfo(this->template consumes<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>> >(fChanInfoName))
4747
{
48-
49-
5048
this->template produces<HBHERecHitCollection>();
5149
//for debugging
5250
this->setDebugName("HcalProducer");
5351
}
5452
void acquire(edm::Event const& iEvent, edm::EventSetup const& iSetup, Input& iInput) override {
55-
56-
5753
//load RecHit and ChannelInfo collections from hbheprereco
58-
edm::Handle<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> hRecHitHCAL;
59-
iEvent.getByToken(fTokRH,hRecHitHCAL);
60-
edm::Handle<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>>> hChannelInfo;
61-
iEvent.getByToken(fTokChanInfo, hChannelInfo);
54+
edm::Handle<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> hRecHitHCAL;
55+
iEvent.getByToken(fTokRH,hRecHitHCAL);
56+
edm::Handle<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>>> hChannelInfo;
57+
iEvent.getByToken(fTokChanInfo, hChannelInfo);
6258

6359
auto ninput = client_.ninput();
6460
auto batchSize = client_.batchSize();
65-
//auto batchSize = std::distance(hRecHitHCAL->begin(), hRecHitHCAL->end());
6661
iInput = Input(ninput*batchSize, 0.f);
67-
/*for(unsigned ib = 0; ib < batchSize; ib++) {
68-
for(unsigned i0 = 0; i0 < ninput; i0++) {
69-
iInput[ib*ninput+0] = 1; //
70-
iInput[ib*ninput+1] = 1; //
71-
iInput[ib*ninput+2] = 1; //
72-
iInput[ib*ninput+3] = int(rand() % 30)-15; //
73-
iInput[ib*ninput+4] = int(rand() % 36)-36; //
74-
iInput[ib*ninput+5] = 1;
75-
for(unsigned i1 = 6; i1 < ninput; i1++) iInput[ib*ninput+i1] = float(rand() % 1000)*0.1;
76-
}
77-
}*/
78-
//batchSize == # of RHs in evt
79-
//auto batchSize = std::distance(hRecHitHCAL->begin(), hRecHitHCAL->end());
80-
std::cout << "# of RHs: " << std::distance(hRecHitHCAL->begin(), hRecHitHCAL->end()) << std::endl;
8162

8263
//fill inputs
8364
unsigned int ib = 0;
84-
for(HBHERecHitCollection::const_iterator itRH = hRecHitHCAL->begin(); itRH != hRecHitHCAL->end(); itRH++) {
65+
for(HBHERecHitCollection::const_iterator itRH = hRecHitHCAL->begin(); itRH != hRecHitHCAL->end(); itRH++) {
8566

8667
depth = (float)itRH->id().depth();
8768
ieta = (float)itRH->id().ieta();
8869
iphi = (float)itRH->id().iphi();
8970

90-
//std::cout << sizeof(depth) << std::endl;
9171
iInput[ib*ninput+0] = ieta;
9272
iInput[ib*ninput+1] = iphi;
9373

94-
95-
96-
for (HBHEChannelInfoCollection::const_iterator iter = hChannelInfo->begin(); iter != hChannelInfo->end(); iter++) {
97-
const HBHEChannelInfo& pChannel(*iter);
98-
const HcalDetId pDetId = pChannel.id();
99-
if(pDetId != itRH->id()) continue;
74+
for (HBHEChannelInfoCollection::const_iterator iter = hChannelInfo->begin(); iter != hChannelInfo->end(); iter++) {
75+
const HBHEChannelInfo& pChannel(*iter);
76+
const HcalDetId pDetId = pChannel.id();
77+
if(pDetId != itRH->id()) continue;
10078
iInput[ib*ninput+2] = pChannel.tsGain(0);
10179
for (unsigned int iTS=0; iTS<8; ++iTS) {
10280
iInput[ib*ninput+iTS+3] = (float)pChannel.tsRawCharge(iTS);
@@ -107,22 +85,17 @@ class HcalProducer : public SonicEDProducer<Client>
10785
if(depth == (float)d) { iInput[ib*ninput + d + 10] = 1.; }
10886
else { iInput[ib*ninput + d + 10] = 0.; }
10987
}
110-
ib++;
111-
112-
88+
ib++;
11389
}
11490
}
11591
void produce(edm::Event& iEvent, edm::EventSetup const& iSetup, Output const& iOutput) override {
116-
117-
118-
edm::Handle<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> hRecHitHCAL_client;
119-
iEvent.getByToken(fTokRH,hRecHitHCAL_client);
92+
edm::Handle<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> hRecHitHCAL_client;
93+
iEvent.getByToken(fTokRH,hRecHitHCAL_client);
12094

12195
std::unique_ptr<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> out;
12296
out = std::make_unique<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>>();
12397
for(HBHERecHitCollection::const_iterator itRH = hRecHitHCAL_client->begin(); itRH != hRecHitHCAL_client->end(); itRH++){
12498
out->push_back(*itRH);
125-
12699
}
127100

128101
//check the results
@@ -141,14 +114,11 @@ class HcalProducer : public SonicEDProducer<Client>
141114
}
142115

143116
private:
144-
145-
// edm::EDGetTokenT<QIE11DigiCollection> tok_qie11_;
146-
147117
unsigned topN_;
148-
edm::InputTag fRHName;
149-
edm::InputTag fChanInfoName;
150-
edm::EDGetTokenT<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> fTokRH;
151-
edm::EDGetTokenT<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>>> fTokChanInfo;
118+
edm::InputTag fRHName;
119+
edm::InputTag fChanInfoName;
120+
edm::EDGetTokenT<edm::SortedCollection<HBHERecHit,edm::StrictWeakOrdering<HBHERecHit>>> fTokRH;
121+
edm::EDGetTokenT<edm::SortedCollection<HBHEChannelInfo,edm::StrictWeakOrdering<HBHEChannelInfo>>> fTokChanInfo;
152122

153123
float depth, ieta, iphi;
154124

@@ -175,7 +145,6 @@ class HcalProducer : public SonicEDProducer<Client>
175145
edm::LogInfo("HcalProducer") << msg.str();
176146
}
177147
}
178-
179148
};
180149

181150
typedef HcalProducer<TRTClientSync> HcalProducerSync;

0 commit comments

Comments
 (0)