LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
lbann::sample_list< sample_name_t > Class Template Reference

#include <sample_list.hpp>

Inheritance diagram for lbann::sample_list< sample_name_t >:
[legend]
Collaboration diagram for lbann::sample_list< sample_name_t >:
[legend]

Public Types

using name_t = sample_name_t
 
using sample_file_id_t = std::size_t
 The type for the index assigned to each sample file. More...
 
using sample_t = std::template pair< sample_file_id_t, sample_name_t >
 
using samples_t = std::template vector< sample_t >
 Type for the list of samples. More...
 
using sample_idx_t = typename samples_t::size_type
 Type for the index into the sample list. More...
 
using sample_map_t = std::unordered_map< sample_name_t, sample_idx_t >
 Type for the map from sample name to the sample list index. More...
 
using file_id_stats_v_t = std::vector< std::string >
 Mapping of the file index to the filename. More...
 

Public Member Functions

 sample_list ()
 
virtual ~sample_list ()
 
 sample_list (const sample_list &rhs)
 
sample_listoperator= (const sample_list &rhs)
 
sample_listcopy (const sample_list &rhs)
 
void copy_members (const sample_list &rhs)
 
void load (std::istream &istrm, size_t stride=1, size_t offset=0)
 
void load (const std::string &samplelist_file, const lbann_comm &comm, bool interleave)
 
void load (std::istream &istrm, const lbann_comm &comm, bool interleave)
 
void load (const sample_list_header &header, std::istream &istrm, const lbann_comm &comm, bool interleave)
 
void load_from_string (const std::string &samplelist, const lbann_comm &comm, bool interleave)
 Restore a sample list from a serialized string. More...
 
virtual size_t size () const
 Tells how many samples in the list. More...
 
virtual size_t get_num_files () const
 Tells how many sample files are there. More...
 
bool empty () const
 Tells if the internal list is empty. More...
 
template<class Archive >
void serialize (Archive &ar)
 Serialize to and from an archive using the cereal library. More...
 
virtual bool to_string (std::string &sstr) const
 Serialize sample list. More...
 
void write (const std::string filename) const
 Write the sample list. More...
 
const samples_tget_list () const
 Allow read-only access to the internal list data. More...
 
const sample_list_headerget_header () const
 Allow the read-only access to the list header. More...
 
const sample_toperator[] (size_t idx) const
 Allow read-only access to the metadata of the idx-th sample in the list. More...
 
virtual const std::string & get_samples_filename (sample_file_id_t id) const
 
const std::string & get_samples_dirname () const
 
const std::string & get_label_filename () const
 
void all_gather_archive (const std::string &archive, std::vector< std::string > &gathered_archive, lbann_comm &comm)
 
void all_gather_archive_new (const std::string &archive, std::vector< std::string > &gathered_archive, lbann_comm &comm)
 
template<typename T >
size_t all_gather_field (T data, std::vector< T > &gathered_data, lbann_comm &comm)
 
virtual void all_gather_packed_lists (lbann_comm &comm)
 
void keep_sample_order (bool keep)
 Set to maintain the original sample order as listed in the file. More...
 
void set_sample_list_name (const std::string &n)
 
void set_data_file_check ()
 Set to check the existence of data file in the list. More...
 
void unset_data_file_check ()
 Set not to check the existence of data file in the list. More...
 
void build_sample_map_from_name_to_index ()
 Build map from sample names to indices for sample list. More...
 
void clear_sample_map_from_name_to_index ()
 Clear the map from sample names to indices. More...
 
sample_idx_t get_sample_index (const sample_name_t &sn)
 Return the index of the sample with the specified name. More...
 

Protected Member Functions

std::string read_header_line (std::istream &ifs, const std::string &listname, const std::string &info)
 
void read_header (std::istream &istrm)
 Reads the header of a sample list. More...
 
virtual void read_sample_list (std::istream &istrm, size_t stride=1, size_t offset=0)
 
virtual void assign_samples_name ()
 
size_t get_samples_per_file (std::istream &istrm, size_t stride=1, size_t offset=0)
 Reads a sample list and populates the internal list. More...
 
void write_header (std::string &sstr, size_t num_files) const
 Add the header info to the given string. More...
 
virtual void get_num_samples (size_t &total, size_t &included, size_t &excluded) const
 Get the number of total/included/excluded samples. More...
 
virtual void set_samples_filename (sample_file_id_t id, const std::string &filename)
 
virtual void reorder ()
 Reorder the sample list to its initial order. More...
 
template<>
void assign_samples_name ()
 
template<>
void assign_samples_name ()
 

Protected Attributes

sample_list_header m_header
 header info of sample list More...
 
size_t m_stride
 The stride used in loading sample list file. More...
 
bool m_keep_order
 maintain the original sample order as listed in the file More...
 
bool m_check_data_file
 Whether to check the existence of data file. More...
 
samples_t m_sample_list
 List of all samples with a file identifier and sample name for each sample. More...
 
sample_map_t m_map_name_to_idx
 Map from sample name to the corresponding index into the sample list. More...
 

Private Attributes

file_id_stats_v_t m_file_id_stats_map
 Maps sample's file id to file names, file descriptors, and use counts. More...
 

Detailed Description

template<typename sample_name_t>
class lbann::sample_list< sample_name_t >

Definition at line 93 of file sample_list.hpp.

Member Typedef Documentation

◆ file_id_stats_v_t

template<typename sample_name_t>
using lbann::sample_list< sample_name_t >::file_id_stats_v_t = std::vector<std::string>

Mapping of the file index to the filename.

Definition at line 109 of file sample_list.hpp.

◆ name_t

template<typename sample_name_t>
using lbann::sample_list< sample_name_t >::name_t = sample_name_t

Definition at line 96 of file sample_list.hpp.

◆ sample_file_id_t

template<typename sample_name_t>
using lbann::sample_list< sample_name_t >::sample_file_id_t = std::size_t

The type for the index assigned to each sample file.

Definition at line 98 of file sample_list.hpp.

◆ sample_idx_t

template<typename sample_name_t>
using lbann::sample_list< sample_name_t >::sample_idx_t = typename samples_t::size_type

Type for the index into the sample list.

Definition at line 105 of file sample_list.hpp.

◆ sample_map_t

template<typename sample_name_t>
using lbann::sample_list< sample_name_t >::sample_map_t = std::unordered_map<sample_name_t, sample_idx_t>

Type for the map from sample name to the sample list index.

Definition at line 107 of file sample_list.hpp.

◆ sample_t

template<typename sample_name_t>
using lbann::sample_list< sample_name_t >::sample_t = std::template pair<sample_file_id_t, sample_name_t>

To describe a sample as the id of the file to which it belongs. Each file contains only one sample.

Definition at line 101 of file sample_list.hpp.

◆ samples_t

template<typename sample_name_t>
using lbann::sample_list< sample_name_t >::samples_t = std::template vector<sample_t>

Type for the list of samples.

Definition at line 103 of file sample_list.hpp.

Constructor & Destructor Documentation

◆ sample_list() [1/2]

template<typename sample_name_t >
lbann::sample_list< sample_name_t >::sample_list ( )

Definition at line 293 of file sample_list_impl.hpp.

◆ ~sample_list()

template<typename sample_name_t >
lbann::sample_list< sample_name_t >::~sample_list ( )
virtual

Definition at line 298 of file sample_list_impl.hpp.

◆ sample_list() [2/2]

template<typename sample_name_t >
lbann::sample_list< sample_name_t >::sample_list ( const sample_list< sample_name_t > &  rhs)

Definition at line 302 of file sample_list_impl.hpp.

Member Function Documentation

◆ all_gather_archive()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::all_gather_archive ( const std::string &  archive,
std::vector< std::string > &  gathered_archive,
lbann_comm comm 
)
inline

Definition at line 560 of file sample_list_impl.hpp.

◆ all_gather_archive_new()

template<typename sample_name_t>
void lbann::sample_list< sample_name_t >::all_gather_archive_new ( const std::string &  archive,
std::vector< std::string > &  gathered_archive,
lbann_comm comm 
)

◆ all_gather_field()

template<typename sample_name_t >
template<typename T >
size_t lbann::sample_list< sample_name_t >::all_gather_field ( data,
std::vector< T > &  gathered_data,
lbann_comm comm 
)
inline

Definition at line 642 of file sample_list_impl.hpp.

◆ all_gather_packed_lists()

◆ assign_samples_name() [1/3]

◆ assign_samples_name() [2/3]

template<>
void lbann::sample_list< size_t >::assign_samples_name ( )
inlineprotected

Definition at line 901 of file sample_list_impl.hpp.

◆ assign_samples_name() [3/3]

template<>
void lbann::sample_list< std::string >::assign_samples_name ( )
inlineprotected

Definition at line 910 of file sample_list_impl.hpp.

◆ build_sample_map_from_name_to_index()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::build_sample_map_from_name_to_index ( )
inline

Build map from sample names to indices for sample list.

Definition at line 1025 of file sample_list_impl.hpp.

◆ clear_sample_map_from_name_to_index()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::clear_sample_map_from_name_to_index ( )
inline

Clear the map from sample names to indices.

Definition at line 1034 of file sample_list_impl.hpp.

◆ copy()

template<typename sample_name_t >
sample_list< sample_name_t > & lbann::sample_list< sample_name_t >::copy ( const sample_list< sample_name_t > &  rhs)
inline

Definition at line 323 of file sample_list_impl.hpp.

◆ copy_members()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::copy_members ( const sample_list< sample_name_t > &  rhs)
inline

Keep track of existing filenames

Definition at line 336 of file sample_list_impl.hpp.

Here is the caller graph for this function:

◆ empty()

template<typename sample_name_t >
bool lbann::sample_list< sample_name_t >::empty ( ) const
inline

Tells if the internal list is empty.

Definition at line 421 of file sample_list_impl.hpp.

◆ get_header()

template<typename sample_name_t >
const sample_list_header & lbann::sample_list< sample_name_t >::get_header ( ) const
inline

Allow the read-only access to the list header.

Definition at line 813 of file sample_list_impl.hpp.

◆ get_label_filename()

template<typename sample_name_t >
const std::string & lbann::sample_list< sample_name_t >::get_label_filename ( ) const
inline

Definition at line 840 of file sample_list_impl.hpp.

Here is the caller graph for this function:

◆ get_list()

template<typename sample_name_t >
const sample_list< sample_name_t >::samples_t & lbann::sample_list< sample_name_t >::get_list ( ) const
inline

Allow read-only access to the internal list data.

Definition at line 807 of file sample_list_impl.hpp.

◆ get_num_files()

◆ get_num_samples()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::get_num_samples ( size_t &  total,
size_t &  included,
size_t &  excluded 
) const
inlineprotectedvirtual

◆ get_sample_index()

template<typename sample_name_t>
sample_list< sample_name_t >::sample_idx_t lbann::sample_list< sample_name_t >::get_sample_index ( const sample_name_t &  sn)
inline

Return the index of the sample with the specified name.

Definition at line 1045 of file sample_list_impl.hpp.

◆ get_samples_dirname()

template<typename sample_name_t >
const std::string & lbann::sample_list< sample_name_t >::get_samples_dirname ( ) const
inline

Definition at line 834 of file sample_list_impl.hpp.

◆ get_samples_filename()

◆ get_samples_per_file()

template<typename sample_name_t >
size_t lbann::sample_list< sample_name_t >::get_samples_per_file ( std::istream &  istrm,
size_t  stride = 1,
size_t  offset = 0 
)
inlineprotected

Reads a sample list and populates the internal list.

Definition at line 547 of file sample_list_impl.hpp.

◆ keep_sample_order()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::keep_sample_order ( bool  keep)
inline

Set to maintain the original sample order as listed in the file.

Definition at line 1056 of file sample_list_impl.hpp.

◆ load() [1/4]

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::load ( std::istream &  istrm,
size_t  stride = 1,
size_t  offset = 0 
)
inline

Load a sample list file using the given stride and offset on the sample sequence

Definition at line 349 of file sample_list_impl.hpp.

◆ load() [2/4]

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::load ( const std::string &  samplelist_file,
const lbann_comm comm,
bool  interleave 
)
inline

Load a sample list file using the stride as the number of processes per trainer and the offset as the current rank within the trainer if interleaving option is on.

Definition at line 358 of file sample_list_impl.hpp.

◆ load() [3/4]

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::load ( std::istream &  istrm,
const lbann_comm comm,
bool  interleave 
)
inline

Definition at line 371 of file sample_list_impl.hpp.

◆ load() [4/4]

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::load ( const sample_list_header header,
std::istream &  istrm,
const lbann_comm comm,
bool  interleave 
)
inline

Load sample list using the given header instead of reading it from the input stream

Definition at line 381 of file sample_list_impl.hpp.

◆ load_from_string()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::load_from_string ( const std::string &  samplelist,
const lbann_comm comm,
bool  interleave 
)
inline

Restore a sample list from a serialized string.

Definition at line 396 of file sample_list_impl.hpp.

◆ operator=()

template<typename sample_name_t >
sample_list< sample_name_t > & lbann::sample_list< sample_name_t >::operator= ( const sample_list< sample_name_t > &  rhs)
inline

Definition at line 309 of file sample_list_impl.hpp.

◆ operator[]()

template<typename sample_name_t >
const sample_list< sample_name_t >::sample_t & lbann::sample_list< sample_name_t >::operator[] ( size_t  idx) const
inline

Allow read-only access to the metadata of the idx-th sample in the list.

Definition at line 820 of file sample_list_impl.hpp.

◆ read_header()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::read_header ( std::istream &  istrm)
inlineprotected

Reads the header of a sample list.

Definition at line 454 of file sample_list_impl.hpp.

◆ read_header_line()

template<typename sample_name_t >
std::string lbann::sample_list< sample_name_t >::read_header_line ( std::istream &  ifs,
const std::string &  listname,
const std::string &  info 
)
inlineprotected

Reads a header line from the sample list given as a stream, and use the info string for error message

Definition at line 428 of file sample_list_impl.hpp.

◆ read_sample_list()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::read_sample_list ( std::istream &  istrm,
size_t  stride = 1,
size_t  offset = 0 
)
inlineprotectedvirtual

◆ reorder()

◆ serialize()

template<typename sample_name_t >
template<class Archive >
void lbann::sample_list< sample_name_t >::serialize ( Archive &  ar)

Serialize to and from an archive using the cereal library.

Definition at line 675 of file sample_list_impl.hpp.

◆ set_data_file_check()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::set_data_file_check ( )
inline

Set to check the existence of data file in the list.

Definition at line 1069 of file sample_list_impl.hpp.

◆ set_sample_list_name()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::set_sample_list_name ( const std::string &  n)
inline

Manually set the sample list name, which can be used for stream-based sources

Definition at line 1063 of file sample_list_impl.hpp.

Here is the caller graph for this function:

◆ set_samples_filename()

◆ size()

template<typename sample_name_t >
size_t lbann::sample_list< sample_name_t >::size ( ) const
inlinevirtual

◆ to_string()

◆ unset_data_file_check()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::unset_data_file_check ( )
inline

Set not to check the existence of data file in the list.

Definition at line 1075 of file sample_list_impl.hpp.

◆ write()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::write ( const std::string  filename) const
inline

Write the sample list.

Definition at line 779 of file sample_list_impl.hpp.

◆ write_header()

template<typename sample_name_t >
void lbann::sample_list< sample_name_t >::write_header ( std::string &  sstr,
size_t  num_files 
) const
inlineprotected

Add the header info to the given string.

Definition at line 684 of file sample_list_impl.hpp.

Member Data Documentation

◆ m_check_data_file

template<typename sample_name_t>
bool lbann::sample_list< sample_name_t >::m_check_data_file
protected

Whether to check the existence of data file.

Definition at line 257 of file sample_list.hpp.

◆ m_file_id_stats_map

template<typename sample_name_t>
file_id_stats_v_t lbann::sample_list< sample_name_t >::m_file_id_stats_map
private

Maps sample's file id to file names, file descriptors, and use counts.

Definition at line 267 of file sample_list.hpp.

◆ m_header

template<typename sample_name_t>
sample_list_header lbann::sample_list< sample_name_t >::m_header
protected

header info of sample list

Definition at line 248 of file sample_list.hpp.

◆ m_keep_order

template<typename sample_name_t>
bool lbann::sample_list< sample_name_t >::m_keep_order
protected

maintain the original sample order as listed in the file

Definition at line 254 of file sample_list.hpp.

◆ m_map_name_to_idx

template<typename sample_name_t>
sample_map_t lbann::sample_list< sample_name_t >::m_map_name_to_idx
protected

Map from sample name to the corresponding index into the sample list.

Definition at line 263 of file sample_list.hpp.

◆ m_sample_list

template<typename sample_name_t>
samples_t lbann::sample_list< sample_name_t >::m_sample_list
protected

List of all samples with a file identifier and sample name for each sample.

Definition at line 260 of file sample_list.hpp.

◆ m_stride

template<typename sample_name_t>
size_t lbann::sample_list< sample_name_t >::m_stride
protected

The stride used in loading sample list file.

Definition at line 251 of file sample_list.hpp.


The documentation for this class was generated from the following files: