18#ifndef TMVA_DNN_DATALOADER
19#define TMVA_DNN_DATALOADER
40 std::tuple<const std::vector<Event *> &,
const DataSetInfo &>;
53template <
typename AArchitecture>
58 using Matrix_t =
typename AArchitecture::Matrix_t;
79template<
typename Data_t,
typename AArchitecture>
class TDataLoader;
89template<
typename Data_t,
typename AArchitecture>
127template<
typename Data_t,
typename AArchitecture>
154 size_t nInputFeatures,
size_t nOutputFeatures,
size_t nStreams = 1);
191template <
typename AArchitecture>
193 : fInputMatrix(inputMatrix), fOutputMatrix(outputMatrix), fWeightMatrix(weightMatrix)
201template<
typename Data_t,
typename AArchitecture>
203 const Data_t &
data,
size_t nSamples,
size_t batchSize,
204 size_t nInputFeatures,
size_t nOutputFeatures,
size_t nStreams)
205 : fData(
data), fNSamples(nSamples), fBatchSize(batchSize),
206 fNInputFeatures(nInputFeatures), fNOutputFeatures(nOutputFeatures),
207 fBatchIndex(0), fNStreams(nStreams), fDeviceBuffers(), fHostBuffers(),
227template<
typename Data_t,
typename AArchitecture>
230 fBatchIndex %= (fNSamples / fBatchSize);
233 size_t inputMatrixSize = fBatchSize * fNInputFeatures;
234 size_t outputMatrixSize = fBatchSize * fNOutputFeatures;
235 size_t weightMatrixSize = fBatchSize;
237 size_t streamIndex = fBatchIndex % fNStreams;
241 HostBuffer_t inputHostBuffer = hostBuffer.GetSubBuffer(0, inputMatrixSize);
242 HostBuffer_t outputHostBuffer = hostBuffer.GetSubBuffer(inputMatrixSize,
244 HostBuffer_t weightHostBuffer = hostBuffer.GetSubBuffer(inputMatrixSize + outputMatrixSize, weightMatrixSize);
246 DeviceBuffer_t inputDeviceBuffer = deviceBuffer.GetSubBuffer(0, inputMatrixSize);
247 DeviceBuffer_t outputDeviceBuffer = deviceBuffer.GetSubBuffer(inputMatrixSize,
249 DeviceBuffer_t weightDeviceBuffer = deviceBuffer.GetSubBuffer(inputMatrixSize + outputMatrixSize, weightMatrixSize);
251 size_t sampleIndex = fBatchIndex * fBatchSize;
252 IndexIterator_t sampleIndexIterator = fSampleIndices.begin() + sampleIndex;
254 CopyInput(inputHostBuffer, sampleIndexIterator, fBatchSize);
255 CopyOutput(outputHostBuffer, sampleIndexIterator, fBatchSize);
256 CopyWeights(weightHostBuffer, sampleIndexIterator, fBatchSize);
258 deviceBuffer.CopyFrom(hostBuffer);
259 Matrix_t inputMatrix(inputDeviceBuffer, fBatchSize, fNInputFeatures);
260 Matrix_t outputMatrix(outputDeviceBuffer, fBatchSize, fNOutputFeatures);
261 Matrix_t weightMatrix(weightDeviceBuffer, fBatchSize, fNOutputFeatures);
268template<
typename Data_t,
typename AArchitecture>
271 std::shuffle(fSampleIndices.begin(), fSampleIndices.end(), std::default_random_engine{});
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
TDataLoader< Data_t, AArchitecture > & fDataLoader
TBatch< AArchitecture > operator*()
bool operator!=(const TBatchIterator &other)
TBatchIterator(TDataLoader< Data_t, AArchitecture > &dataLoader, size_t index=0)
TBatchIterator operator++()
TBatch(const TBatch &)=default
TBatch(Matrix_t &, Matrix_t &, Matrix_t &)
Matrix_t & GetInput()
Return the matrix representing the input data.
Matrix_t & GetOutput()
Return the matrix representing the output data.
TBatch & operator=(const TBatch &)=default
Matrix_t & GetWeights()
Return the matrix holding the event weights.
TBatch(TBatch &&)=default
TBatch & operator=(TBatch &&)=default
typename AArchitecture::Matrix_t Matrix_t
TDataLoader(TDataLoader &&)=default
void CopyInput(HostBuffer_t &buffer, IndexIterator_t begin, size_t batchSize)
Copy input matrix into the given host buffer.
std::vector< size_t > fSampleIndices
Ordering of the samples in the epoch.
std::vector< HostBuffer_t > fHostBuffers
TBatch< AArchitecture > GetBatch()
Return the next batch from the training set.
typename AArchitecture::DeviceBuffer_t DeviceBuffer_t
void CopyOutput(HostBuffer_t &buffer, IndexIterator_t begin, size_t batchSize)
Copy output matrix into the given host buffer.
TDataLoader & operator=(TDataLoader &&)=default
std::vector< DeviceBuffer_t > fDeviceBuffers
TDataLoader & operator=(const TDataLoader &)=default
typename AArchitecture::Matrix_t Matrix_t
size_t fNStreams
Number of buffer pairs.
TDataLoader(const Data_t &data, size_t nSamples, size_t batchSize, size_t nInputFeatures, size_t nOutputFeatures, size_t nStreams=1)
typename AArchitecture::HostBuffer_t HostBuffer_t
void Shuffle()
Shuffle the order of the samples in the batch.
void CopyWeights(HostBuffer_t &buffer, IndexIterator_t begin, size_t batchSize)
Copy weight matrix into the given host buffer.
TDataLoader(const TDataLoader &)=default
Class that contains all the data information.
typename std::vector< size_t >::iterator IndexIterator_t
std::tuple< const std::vector< Event * > &, const DataSetInfo & > TMVAInput_t
std::tuple< const TMatrixT< Double_t > &, const TMatrixT< Double_t > &, const TMatrixT< Double_t > & > MatrixInput_t
create variable transformations