|
OpenNN
Open-source neural networks library
|
Owns the host-side and (optional) device-side buffers for one mini-batch of dataset samples. More...
#include <batch.h>
Public Member Functions | |
| Batch (const Index samples_number=0, const Dataset *dataset=nullptr) | |
| Constructs a batch sized for a given dataset. | |
| void | set (const Index samples_number=0, const Dataset *dataset=nullptr) |
| (Re)allocates buffers for a given batch size and dataset. | |
| void | fill (const vector< Index > &sample_indices, const vector< Index > &input_feature_indices, const vector< Index > &decoder_feature_indices, const vector< Index > &target_feature_indices, bool augment=false) |
| Fills the host-side buffers from the bound dataset. | |
| const vector< TensorView > & | get_inputs () const |
| Returns the input TensorViews for the active device. | |
| const TensorView & | get_targets () const |
| Returns the target TensorView for the active device. | |
| Index | get_samples_number () const |
| Number of samples currently held in the batch. | |
| void | print () const |
| Prints a human-readable summary of the batch buffers to stdout. | |
| bool | is_empty () const |
| Whether the batch holds zero samples. | |
| void | copy_device_async (const Index sample_count, cudaStream_t stream) |
Asynchronously copies the host buffers to the device on stream. | |
Public Attributes | |
| Index | samples_number = 0 |
| Number of samples currently held in the batch. | |
| const Dataset * | dataset = nullptr |
| Dataset whose shapes determined the batch buffer sizes; not owned. | |
| Buffer | input |
| Owning storage for the input tensor (host or device). | |
| Shape | input_shape |
| Shape of input (per-sample dimensions). | |
| Buffer | decoder |
| Owning storage for the decoder tensor (encoder-decoder models). | |
| Shape | decoder_shape |
| Shape of decoder. | |
| Buffer | target |
| Owning storage for the target tensor. | |
| Shape | target_shape |
| Shape of target. | |
| int | input_contiguous = -1 |
| Stride hint passed to Dataset::fill_inputs(); -1 to ignore. | |
| int | decoder_contiguous = -1 |
| Stride hint passed to Dataset::fill_inputs() for the decoder; -1 to ignore. | |
| int | target_contiguous = -1 |
| Stride hint passed to Dataset::fill_targets(); -1 to ignore. | |
| vector< TensorView > | input_views_host_cache |
| Host-side input TensorViews (one per input feature group). | |
| TensorView | target_view_host_cache |
| Host-side target TensorView. | |
| vector< TensorView > | input_views_cache |
| Device-side input TensorViews; populated only on CUDA mode. | |
| TensorView | target_view_cache |
| Device-side target TensorView; populated only on CUDA mode. | |
| Index | num_input_features = 0 |
| Total number of input features across all input feature groups. | |
| Index | num_decoder_features = 0 |
| Total number of decoder features. | |
| Index | num_target_features = 0 |
| Total number of target features. | |
| float * | inputs_host = nullptr |
| Pinned host pointer used to stage inputs into the device buffer. | |
| float * | decoder_host = nullptr |
| Pinned host pointer used to stage decoder inputs into the device buffer. | |
| float * | targets_host = nullptr |
| Pinned host pointer used to stage targets into the device buffer. | |
| Index | inputs_host_allocated_size = 0 |
| Allocation capacity of inputs_host, in floats. | |
| Index | decoder_host_allocated_size = 0 |
| Allocation capacity of decoder_host, in floats. | |
| Index | targets_host_allocated_size = 0 |
| Allocation capacity of targets_host, in floats. | |
| Buffer | inputs_fp32_staging {Device::CUDA} |
| Device-resident FP32 staging buffer used during mixed-precision uploads. | |
Owns the host-side and (optional) device-side buffers for one mini-batch of dataset samples.
The Batch is filled once per training step from a Dataset using fill(). Its TensorViews (target_view, input_views) are then handed to the NeuralNetwork's forward / backward passes. On CUDA-enabled builds the batch maintains parallel host and device buffers; copy_device_async() uploads the host data on a user-supplied CUDA stream so it can overlap with compute.
| opennn::Batch::Batch | ( | const Index | samples_number = 0, |
| const Dataset * | dataset = nullptr ) |
Constructs a batch sized for a given dataset.
| samples_number | Number of samples per batch. |
| dataset | Dataset whose shapes determine the batch buffer sizes. |
| void opennn::Batch::copy_device_async | ( | const Index | sample_count, |
| cudaStream_t | stream ) |
Asynchronously copies the host buffers to the device on stream.
| sample_count | Number of samples to copy from the host buffer. |
| stream | CUDA stream used for the asynchronous copy. |
| void opennn::Batch::fill | ( | const vector< Index > & | sample_indices, |
| const vector< Index > & | input_feature_indices, | ||
| const vector< Index > & | decoder_feature_indices, | ||
| const vector< Index > & | target_feature_indices, | ||
| bool | augment = false ) |
Fills the host-side buffers from the bound dataset.
| sample_indices | Indices of samples copied into this batch. |
| input_feature_indices | Dataset columns used as inputs. |
| decoder_feature_indices | Dataset columns used as decoder inputs (empty when the model has no decoder). |
| target_feature_indices | Dataset columns used as targets. |
| augment | True to apply Dataset::augment_inputs() to the input buffer. |
|
inline |
Returns the input TensorViews for the active device.
| Index opennn::Batch::get_samples_number | ( | ) | const |
Number of samples currently held in the batch.
|
inline |
Returns the target TensorView for the active device.
| bool opennn::Batch::is_empty | ( | ) | const |
Whether the batch holds zero samples.
| void opennn::Batch::print | ( | ) | const |
Prints a human-readable summary of the batch buffers to stdout.
| void opennn::Batch::set | ( | const Index | samples_number = 0, |
| const Dataset * | dataset = nullptr ) |
(Re)allocates buffers for a given batch size and dataset.
| samples_number | Number of samples per batch. |
| dataset | Dataset whose shapes determine the batch buffer sizes. |
| const Dataset* opennn::Batch::dataset = nullptr |
Dataset whose shapes determined the batch buffer sizes; not owned.
| Buffer opennn::Batch::decoder |
Owning storage for the decoder tensor (encoder-decoder models).
| int opennn::Batch::decoder_contiguous = -1 |
Stride hint passed to Dataset::fill_inputs() for the decoder; -1 to ignore.
| float* opennn::Batch::decoder_host = nullptr |
Pinned host pointer used to stage decoder inputs into the device buffer.
| Index opennn::Batch::decoder_host_allocated_size = 0 |
Allocation capacity of decoder_host, in floats.
| Buffer opennn::Batch::input |
Owning storage for the input tensor (host or device).
| int opennn::Batch::input_contiguous = -1 |
Stride hint passed to Dataset::fill_inputs(); -1 to ignore.
| vector<TensorView> opennn::Batch::input_views_cache |
Device-side input TensorViews; populated only on CUDA mode.
| vector<TensorView> opennn::Batch::input_views_host_cache |
Host-side input TensorViews (one per input feature group).
| Buffer opennn::Batch::inputs_fp32_staging {Device::CUDA} |
Device-resident FP32 staging buffer used during mixed-precision uploads.
| float* opennn::Batch::inputs_host = nullptr |
Pinned host pointer used to stage inputs into the device buffer.
| Index opennn::Batch::inputs_host_allocated_size = 0 |
Allocation capacity of inputs_host, in floats.
| Index opennn::Batch::num_decoder_features = 0 |
Total number of decoder features.
| Index opennn::Batch::num_input_features = 0 |
Total number of input features across all input feature groups.
| Index opennn::Batch::num_target_features = 0 |
Total number of target features.
| Index opennn::Batch::samples_number = 0 |
Number of samples currently held in the batch.
| Buffer opennn::Batch::target |
Owning storage for the target tensor.
| int opennn::Batch::target_contiguous = -1 |
Stride hint passed to Dataset::fill_targets(); -1 to ignore.
| TensorView opennn::Batch::target_view_cache |
Device-side target TensorView; populated only on CUDA mode.
| TensorView opennn::Batch::target_view_host_cache |
Host-side target TensorView.
| float* opennn::Batch::targets_host = nullptr |
Pinned host pointer used to stage targets into the device buffer.
| Index opennn::Batch::targets_host_allocated_size = 0 |
Allocation capacity of targets_host, in floats.