18#include "cuda_runtime.h"
36 size_t sampleIndex = *sampleIterator;
39 buffer[bufferIndex] =
static_cast<float>(
inputTensor[0](sampleIndex, j));
45 size_t sampleIndex = *sampleIterator;
49 buffer[bufferIndex] =
static_cast<float>(
inputTensor[sampleIndex](j, k));
66 size_t sampleIndex = *sampleIterator;
67 for (
size_t j = 0; j <
n; j++) {
69 buffer[bufferIndex] =
static_cast<float>(
outputMatrix(sampleIndex, j));
83 buffer[i] =
static_cast<float>(
weightMatrix(*sampleIterator, 0));
97 size_t sampleIndex = *sampleIterator;
98 Event *
event = std::get<0>(
fData)[sampleIndex];
101 buffer[bufferIndex] =
event->GetValue(j);
108 size_t sampleIndex = *sampleIterator;
109 Event *
event = std::get<0>(
fData)[sampleIndex];
114 buffer[bufferIndex] =
event->GetValue(j *
fBatchWidth + k);
122 Error(
"TTensorDataLoader",
"Inconsistency between batch depth and batch size");
136 size_t sampleIndex = *sampleIterator++;
137 Event *
event = std::get<0>(
fData)[sampleIndex];
138 for (
size_t j = 0; j <
n; j++) {
142 if (event->GetNTargets() == 0) {
145 buffer[bufferIndex] = (info.
IsSignal(event)) ? 1.0 : 0.0;
148 buffer[bufferIndex] = 0.0;
149 if (j == event->GetClass()) {
150 buffer[bufferIndex] = 1.0;
154 buffer[bufferIndex] =
static_cast<Float_t>(
event->GetTarget(j));
166 size_t sampleIndex = *sampleIterator++;
167 Event *
event = std::get<0>(
fData)[sampleIndex];
168 buffer[i] =
event->GetWeight();
181 size_t sampleIndex = *sampleIterator;
184 buffer[bufferIndex] =
static_cast<double>(
inputTensor[0](sampleIndex, j));
190 size_t sampleIndex = *sampleIterator;
194 buffer[bufferIndex] =
static_cast<double>(
inputTensor[sampleIndex](j, k));
211 size_t sampleIndex = *sampleIterator;
212 for (
size_t j = 0; j <
n; j++) {
240 size_t sampleIndex = *sampleIterator;
241 Event *
event = std::get<0>(
fData)[sampleIndex];
244 buffer[bufferIndex] =
event->GetValue(j);
251 size_t sampleIndex = *sampleIterator;
252 Event *
event = std::get<0>(
fData)[sampleIndex];
257 buffer[bufferIndex] =
event->GetValue(j *
fBatchWidth + k);
264 Error(
"TTensorDataLoader",
"Inconsistency between batch depth and batch size");
280 size_t sampleIndex = *sampleIterator++;
281 Event *
event = std::get<0>(
fData)[sampleIndex];
282 for (
size_t j = 0; j <
n; j++) {
286 if (event->GetNTargets() == 0) {
289 buffer[bufferIndex] = (info.
IsSignal(event)) ? 1.0 : 0.0;
292 buffer[bufferIndex] = 0.0;
293 if (j == event->GetClass()) {
294 buffer[bufferIndex] = 1.0;
298 buffer[bufferIndex] =
static_cast<Double_t>(
event->GetTarget(j));
310 size_t sampleIndex = *sampleIterator++;
311 Event *
event = std::get<0>(
fData)[sampleIndex];
312 buffer[i] =
event->GetWeight();
322 DeviceBufferTuple DeviceBuffers = CopyTensorBatches();
324 std::vector<size_t> outputShape {fBatchSize, 1, fNOutputFeatures, 1};
325 std::vector<size_t> wheightShape {fBatchSize, 1, 1, 1};
326 std::vector<TCudaTensor<float> > inputTensor(1, TCudaTensor<float>(std::get<0>(DeviceBuffers),
327 this->GetTensorDim(), fInputShape));
328 TCudaTensor<float> outputMatrix(std::get<1>(DeviceBuffers), this->GetTensorDim(), outputShape);
329 TCudaTensor<float> weightMatrix(std::get<2>(DeviceBuffers), this->GetTensorDim(), wheightShape);
332 return TTensorBatch<TCudnn<float> >(inputTensor, outputMatrix, weightMatrix);
340 DeviceBufferTuple DeviceBuffers = CopyTensorBatches();
342 std::vector<size_t> outputShape {fBatchSize, 1, fNOutputFeatures, 1};
343 std::vector<size_t> wheightShape {fBatchSize, 1, 1, 1};
344 std::vector<TCudaTensor<double> > inputTensor(1,
TCudaTensor<double>(std::get<0>(DeviceBuffers),
345 this->GetTensorDim(), fInputShape));
346 TCudaTensor<double> outputMatrix(std::get<1>(DeviceBuffers), this->GetTensorDim(), outputShape);
347 TCudaTensor<double> weightMatrix(std::get<2>(DeviceBuffers), this->GetTensorDim(), wheightShape);
358 DeviceBufferTuple DeviceBuffers = CopyTensorBatches();
360 std::vector<size_t> outputShape {fBatchSize, 1, fNOutputFeatures, 1};
361 std::vector<size_t> wheightShape {fBatchSize, 1, 1, 1};
362 std::vector<TCudaTensor<float> > inputTensor(1,
TCudaTensor<float>(std::get<0>(DeviceBuffers),
363 this->GetTensorDim(), fInputShape));
364 TCudaTensor<float> outputMatrix(std::get<1>(DeviceBuffers), this->GetTensorDim(), outputShape);
365 TCudaTensor<float> weightMatrix(std::get<2>(DeviceBuffers), this->GetTensorDim(), wheightShape);
376 DeviceBufferTuple DeviceBuffers = CopyTensorBatches();
378 std::vector<size_t> outputShape {fBatchSize, 1, fNOutputFeatures, 1};
379 std::vector<size_t> wheightShape {fBatchSize, 1, 1, 1};
380 std::vector<TCudaTensor<double> > inputTensor(1,
TCudaTensor<double>(std::get<0>(DeviceBuffers),
381 this->GetTensorDim(), fInputShape));
382 TCudaTensor<double> outputMatrix(std::get<1>(DeviceBuffers), fNOutputFeatures + 2, outputShape);
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
TMatrixT< AReal > weightMatrix
The matrix used to keep the batch weights.
TTensorDataLoader(const AData &data, size_t nSamples, size_t batchDepth, size_t batchHeight, size_t batchWidth, size_t nOutputFeatures, std::vector< size_t > inputShape, size_t nStreams=1)
Constructor.
size_t fBatchHeight
The number od rows in each matrix.
const AData & fData
The data that should be loaded in the batches.
std::vector< TMatrixT< AReal > > inputTensor
The 3D tensor used to keep the input data.
void CopyTensorInput(std::vector< TMatrixT< AReal > > &tensor, IndexIterator_t sampleIterator)
Copy input tensor into the given host buffer.
TMatrixT< AReal > outputMatrix
The matrix used to keep the output.
size_t fBatchDepth
The number of matrices in the tensor.
size_t fBatchWidth
The number of columns in each matrix.
void CopyTensorWeights(TMatrixT< AReal > &matrix, IndexIterator_t sampleIterator)
Copy weight matrix into the given host buffer.
void CopyTensorOutput(TMatrixT< AReal > &matrix, IndexIterator_t sampleIterator)
Copy output matrix into the given host buffer.
Class that contains all the data information.
Bool_t IsSignal(const Event *ev) const
typename std::vector< size_t >::iterator IndexIterator_t
create variable transformations