Accelerator
Defines
-
strong_inline
-
DO_PRAGMA_(x)
-
DO_PRAGMA(x)
-
thread_num(a)
-
thread_max(a)
-
set_threads(a)
-
in_thread_parallel_region(a)
-
thread_for(i, num, ...)
-
thread_for3d(i1, n1, i2, n2, i3, n3, ...)
-
thread_for2d(i1, n1, i2, n2, ...)
-
accelerator
-
accelerator_inline
-
accelerator_barrier(dummy)
-
accelerator_for3dNB(iter1, num1, iter2, num2, iter3, num3, block2, ...)
-
accelerator_for3d(iter1, num1, iter2, num2, iter3, num3, block2, ...)
-
accelerator_for2dNB(iter1, num1, iter2, num2, block2, ...)
-
accelerator_for2d(iter1, num1, iter2, num2, block2, ...)
-
accelerator_forNB(iter1, num1, ...)
-
accelerator_for(iter, num, ...)
-
accelerator_for3d_shm(iter1, num1, iter2, num2, iter3, num3, block2, shm_size, ...)
-
accelerator_for2dNB_shm(iter1, num1, iter2, num2, block2, shm_size, ...)
-
accelerator_for2d_shm(iter1, num1, iter2, num2, block2, shm_size, ...)
-
accelerator_forNB_shm(iter1, num1, shm_size, ...)
-
accelerator_for_shm(iter, num, shm_size, ...)
-
autoView(ViewName, ObjName, mode)
-
doHost(a, ...)
-
doHost2(a, b, ...)
-
doHost3(a, b, c, ...)
Functions
-
void acceleratorInit(void)
-
void acceleratorReport()
-
inline void acceleratorCopyToDevice(void *to, void const *from, size_t bytes)
-
inline void acceleratorCopyFromDevice(void *to, void const *from, size_t bytes)
-
inline void acceleratorCopyDeviceToDevice(void *to, void const *from, size_t bytes)
-
inline void acceleratorCopyDeviceToDeviceAsynch(void *to, void const *from, size_t bytes)
-
inline void acceleratorCopySynchronize(void)
-
inline void acceleratorMemSet(void *base, int value, size_t bytes)
-
inline void *acceleratorAllocHost(size_t bytes)
-
inline void *acceleratorAllocDevice(size_t bytes)
-
inline void acceleratorFreeHost(void *ptr)
-
inline void acceleratorFreeDevice(void *ptr)
-
inline void profileStart()
-
inline void profileStop()
-
inline void labelRegionBegin(char const *label)
-
inline void labelRegionEnd()
-
template<typename ViewType>
struct viewDeallocator
ActivationFuncs
-
template<typename FloatType>
class ReLU
-
template<typename FloatType>
class noActivation
-
template<typename FloatType>
class GeLU
Comms
Functions
-
Communicators &communicators()
-
void initializeComms(int argc, char **argv)
-
inline int UniqueID()
-
template<typename FloatType>
inline MPI_Datatype getMPIdataType()
-
template<typename FloatType>
inline void commsReduce(FloatType *data, size_t data_len, const MPI_Comm &comm)
-
template<typename FloatType>
inline void commsBroadcast(FloatType *data, size_t data_len, int from_rank, const MPI_Comm &comm)
-
class Communicators
Public Functions
-
Communicators(int argc, char **argv)
-
~Communicators()
-
inline int worldRank() const
-
inline int worldNrank() const
-
inline int nodeRank() const
-
inline int nodeNrank() const
-
inline int ddpRank() const
-
inline int ddpNrank() const
-
inline int pipelineRank() const
-
inline int pipelineNrank() const
-
inline bool isPipelineLeader() const
-
inline MPI_Comm &pipelineCommunicator()
-
inline MPI_Comm &ddpCommunicator()
-
void enableNodePipelining()
-
void enableColorPipelining(int rank_color)
-
void enableGlobalPipelining()
-
void disableParallelism()
-
void enableDDPnoPipelining()
-
void reportSetup()
Private Functions
-
void setupDDPcommunicator()
-
void freeCommunicators()
-
void enableDDPnoPipeliningInternal()
Private Members
-
MPI_Comm pipeline_comm
-
MPI_Comm ddp_comm
-
int world_rank
-
int world_nrank
-
int node_rank
-
int node_nrank
-
int pipeline_rank
-
int pipeline_nrank
-
bool is_pipeline_leader
-
int ddp_rank
-
int ddp_nrank
Private Static Functions
-
static void createCommJustThisRank(int world_rank, MPI_Comm &comm)
-
Communicators(int argc, char **argv)
Components
DDP
DynamicModel
Functions
-
template<typename FloatType, typename InputType, typename LayerOutputType>
class LayerWrapperInternalBase Public Functions
-
virtual LayerOutputType value(const InputType &x) = 0
-
virtual int deriv(Vector<FloatType> &cost_deriv, int off, LayerOutputType &&above_deriv, InputType *input_above_deriv_return = nullptr) const = 0
-
virtual int nparams() const = 0
-
virtual size_t FLOPS(int value_or_deriv) const = 0
-
virtual void resizeInputBuffer(size_t to) = 0
-
inline virtual ~LayerWrapperInternalBase()
-
virtual LayerOutputType value(const InputType &x) = 0
-
template<typename Store, typename std::enable_if<ISSTORAGE(Store), int>::type = 0>
class LayerWrapperInternal : public LayerWrapperInternalBase<Store::type::FloatType, Store::type::InputType, LAYEROUTPUTTYPE(Store::type)> -
Public Functions
- typedef LAYEROUTPUTTYPE (typename Store::type) LayerOutputType
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, LayerOutputType &&above_deriv, InputType *input_above_deriv_return = nullptr) const override
-
inline virtual int nparams() const override
-
inline virtual size_t FLOPS(int value_or_deriv) const
-
inline virtual void resizeInputBuffer(size_t to) override
-
template<typename _FloatType, typename _InputType, typename _LayerOutputType>
class LayerWrapper Public Types
-
typedef _FloatType FloatType
-
typedef _InputType InputType
-
typedef _LayerOutputType LayerOutputType
Public Functions
-
LayerWrapper(LayerWrapper &&r) = default
-
LayerWrapper &operator=(LayerWrapper &&r) = default
-
template<typename Store, typename std::enable_if<ISSTORAGE(Store), int>::type = 0>
inline LayerWrapper(Store &&layer)
-
inline LayerOutputType value(const InputType &x)
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, LayerOutputType &&above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
std::unique_ptr<LayerWrapperInternalBase<FloatType, InputType, LayerOutputType>> layer
-
typedef _FloatType FloatType
Embeddings
HPCortex
Init
Functions
-
void initialize(int argc, char **argv)
InstanceStorage
-
struct StorageTag
-
template<typename T>
struct LeafStore -
Public Functions
-
template<typename T>
struct LeafRef -
Public Functions
-
template<typename T>
struct deduceStorage
Layers
Linalg
Functions
-
template<typename FloatType>
void thinMulMatMatTranspose_p(FloatType *out_p, const Matrix<FloatType> &a, const Matrix<FloatType> &b, FLOPScounter *flops = nullptr)
-
template<typename FloatType>
Matrix<FloatType> thinMulMatMatTranspose(const Matrix<FloatType> &a, const Matrix<FloatType> &b, FLOPScounter *flops = nullptr)
-
template<typename FloatType>
Matrix<FloatType> mulMatTransposeThinMat(const Matrix<FloatType> &a, const Matrix<FloatType> &b, FLOPScounter *flops = nullptr)
-
template<typename FloatType>
Matrix<FloatType> computeThinMatOuterProd(const Matrix<FloatType> &above_deriv, const Matrix<FloatType> &activation_deriv, FLOPScounter *flops = nullptr)
-
template<typename FloatType>
Matrix<FloatType> axpyMatThinMat(const Matrix<FloatType> &a, const Matrix<FloatType> &b, const Vector<FloatType> &c, FLOPScounter *flops = nullptr)
-
template<typename FloatType>
Tensor<FloatType, 3> batch3tensorContract(const Tensor<FloatType, 3> &A, const Tensor<FloatType, 3> &B, int contract_dimA, int contract_dimB, FloatType nrm = 1.0, FLOPScounter *flops = nullptr)
-
template<typename FloatType, int Dim>
Tensor<FloatType, Dim> matrixBatchTensorAxpy(const Matrix<FloatType> &A, const Tensor<FloatType, Dim> &X, const Vector<FloatType> &Y, const int contract_dim, FLOPScounter *flops = nullptr)
-
template<typename FloatType, int Dim>
void batchTensorContractToMatrix_p(FloatType *out_p, const Tensor<FloatType, Dim> &A, const Tensor<FloatType, Dim> &B, const int preserve_dim, FLOPScounter *flops = nullptr)
LossFunctions
Defines
-
CWRP
Functions
-
template<typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto mse_cost(U &&u) -> CWRP
-
template<typename Store, typename CostFunc>
class CostFuncWrapper Public Types
Public Functions
-
inline FloatType loss(const InputType &x, const ComparisonType &y)
-
inline PredictionType predict(const InputType &x)
-
template<typename _PredictionType = PredictionType, typename _InputType = InputType, int TensDimIn = _InputType::Dimension, int TensDimOut = _PredictionType::Dimension, typename std::enable_if<std::is_same<_PredictionType, Tensor<FloatType, TensDimOut>>::value && std::is_same<_InputType, Tensor<FloatType, TensDimIn>>::value && std::is_same<_PredictionType, ComparisonType>::value, int>::type = 0>
inline Tensor<FloatType, TensDimOut - 1> predict(const Tensor<FloatType, TensDimIn - 1> &x, int batch_size)
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline FloatType loss(const InputType &x, const ComparisonType &y)
-
template<typename OutputType>
class MSEcostFunc
-
template<typename FloatType, int Dim>
class MSEcostFunc<Tensor<FloatType, Dim>> Public Types
Public Static Functions
-
static FloatType loss(const ComparisonType &y, const PredictionType &ypred)
-
static PredictionType layer_deriv(const ComparisonType &y, const PredictionType &ypred)
-
static FloatType loss(const ComparisonType &y, const PredictionType &ypred)
ManagedArray
-
template<typename FloatType>
class ManagedArray Public Functions
-
inline ManagedArray()
-
inline ManagedArray(size_t size, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
-
inline ManagedArray(size_t size, FloatType init, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
-
inline ManagedArray(ManagedArray &&r)
-
inline ManagedArray(const ManagedArray &r)
-
inline ManagedArray &operator=(ManagedArray &&r)
-
inline ManagedArray &operator=(const ManagedArray &r)
-
inline size_t size() const
-
inline ~ManagedArray()
-
inline void fill(FloatType init, MemoryManager::Pool assign_pool = MemoryManager::Pool::DevicePool)
-
inline void lock() const
-
inline void unlock() const
-
class View
Subclassed by Tensor< _FloatType, Dim >::View
Public Functions
- inline accelerator_inline size_t size () const
- inline accelerator_inline FloatType * data ()
- inline accelerator_inline FloatType const * data () const
- inline accelerator_inline FloatType & operator[] (const size_t i)
- inline accelerator_inline FloatType operator[] (const size_t i) const
-
inline View(ViewMode mode, MemoryManager::HandleIterator handle, size_t _size)
-
inline View(ViewMode mode, const ManagedArray &parent)
-
inline void free()
-
inline ManagedArray()
MemoryManager
Enums
Functions
-
inline std::string memPoolManagerReport(bool detailed = false)
-
class MemoryManager
Public Types
Public Functions
-
inline MemoryManager()
-
inline MemoryManager(size_t max_size_device, size_t max_size_host)
-
~MemoryManager()
-
inline void setVerbose(bool to)
-
void enableIOlogging()
-
inline void setDiskRoot(const std::string &to)
-
inline const std::string &getDiskRoot() const
-
inline void enableDeletionOfLocalDiskDataOnRestore(bool val = true)
-
size_t getDiskCachedBytes() const
-
size_t getDiskUsedBytes() const
-
std::string report(bool detailed = false) const
-
void evictToDisk(HandleIterator h)
-
HandleIterator allocate(size_t bytes, Pool pool = DevicePool)
-
void *openView(ViewMode mode, HandleIterator h)
-
void closeView(HandleIterator h)
-
void free(HandleIterator h)
-
inline size_t nOpenHandles() const
-
inline void lock(HandleIterator h)
-
inline void unlock(HandleIterator h)
Public Static Functions
-
static inline MemoryManager &globalPool()
Protected Functions
-
EntryIterator allocEntry(size_t bytes, Pool pool)
-
void sanityCheck()
-
void moveEntryToFreePool(EntryIterator it, Pool pool)
-
void freeEntry(EntryIterator it, Pool pool)
-
EntryIterator getEntry(size_t bytes, Pool pool)
-
EntryIterator evictEntry(EntryIterator entry, bool free_it, Pool pool)
Protected Attributes
-
bool verbose
-
std::ofstream *io_logger
-
std::list<HandleIterator> device_queued_prefetches
-
std::list<HandleIterator> host_queued_prefetches
-
size_t device_allocated
-
size_t host_allocated
-
size_t device_pool_max_size
-
size_t host_pool_max_size
-
size_t local_disk_allocated
-
size_t device_allocated_HWM
-
size_t host_allocated_HWM
-
size_t local_disk_allocated_HWM
-
std::string disk_root
-
bool delete_local_diskdata_on_restore
Protected Static Functions
-
static void summarizePoolStatus(std::ostream &os, const std::string &descr, const std::map<size_t, std::list<Entry>, std::greater<size_t>> &pool_stat)
-
static void summarizePoolStatus(std::ostream &os, const std::string &descr, const std::map<size_t, int, std::greater<size_t>> &pool_stat)
-
struct Entry
-
inline MemoryManager()
Optimizers
Functions
-
template<typename DataLoader, typename ModelType, typename Optimizer>
std::vector<typename ModelType::FloatType> train(ModelType &model, const DataLoader &data, Optimizer &optimizer, int nepoch, int batch_size, bool suppress_logging = false)
-
template<typename FloatType>
struct noScheduler Public Functions
-
template<typename FloatType, typename LRscheduler = noScheduler<FloatType>>
class GradientDescentOptimizer Public Functions
-
inline GradientDescentOptimizer(const LRscheduler &sched)
-
template<typename L = LRscheduler, typename std::enable_if<std::is_same<L, noScheduler<FloatType>>::value, int>::type = 0>
inline GradientDescentOptimizer(FloatType lr)
-
inline void epochStart(int epoch, bool verbose = true)
-
inline GradientDescentOptimizer(const LRscheduler &sched)
-
template<typename FloatType>
struct AdamParams Public Functions
-
template<typename FloatType, typename LRscheduler = noScheduler<FloatType>>
class AdamOptimizer Public Functions
-
inline AdamOptimizer(const AdamParams<FloatType> &ap, const LRscheduler &sched)
-
inline AdamOptimizer(const LRscheduler &sched)
-
template<typename L = LRscheduler, typename std::enable_if<std::is_same<L, noScheduler<FloatType>>::value, int>::type = 0>
inline AdamOptimizer(const AdamParams<FloatType> &ap, FloatType lr)
-
template<typename L = LRscheduler, typename std::enable_if<std::is_same<L, noScheduler<FloatType>>::value, int>::type = 0>
inline AdamOptimizer(FloatType lr)
-
inline void epochStart(int epoch, bool verbose = true)
Private Functions
-
inline void reset()
-
inline AdamOptimizer(const AdamParams<FloatType> &ap, const LRscheduler &sched)
-
template<typename FloatType>
class DecayScheduler Public Functions
-
template<typename FloatType, int DimX, int DimY>
struct XYpair
Padding
-
template<typename FloatType>
class NoPadding Public Functions
Public Static Functions
-
static inline int layerOutputLength(int input_size, int kernel_size, int stride)
-
static inline int layerOutputLength(int input_size, int kernel_size, int stride)
Performance
Pipelining
Defines
-
CWRP
Functions
-
template<typename PipelineBlockType>
auto pipeline_mse_cost(PipelineBlockType &u) -> CWRP
-
template<typename InputType, typename OutputType, typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto pipeline_block(U &&u, int const *block_output_dims, int const *block_input_dims) -> PipelineBlock<DDST(u), InputType, OutputType>
-
template<typename PipelineBlockType, typename CostFunc>
class BatchPipelineCostFuncWrapper Public Types
-
typedef PipelineBlockType::FloatType FloatType
-
typedef PipelineBlockType::InputType InputType
-
typedef PipelineBlockType::OutputType OutputType
-
typedef PipelineBlockType::BlockInputType BlockInputType
Public Functions
- typedef LAYEROUTPUTTYPE (PipelineBlockType) BlockOutputType
-
inline BatchPipelineCostFuncWrapper(PipelineBlockType &block, int call_batch_size, const CostFunc &cost = CostFunc())
-
inline FloatType loss(const InputType &x, const OutputType &y)
-
inline int nparams() const
-
typedef PipelineBlockType::FloatType FloatType
-
template<typename PipelineBlockType, typename CostFunc>
class PipelineCostFuncWrapper Public Functions
-
inline PipelineCostFuncWrapper(PipelineBlockType &block, const CostFunc &cost = CostFunc())
-
inline std::pair<FloatType, bool> loss(const OutputType &x, const OutputType &y)
-
inline int nparams()
-
inline int valueLag() const
-
inline int derivLag() const
Private Types
-
typedef PipelineBlockType::FloatType FloatType
-
typedef PipelineBlockType::InputType InputType
-
typedef PipelineBlockType::OutputType OutputType
-
typedef PipelineBlockType::BlockInputType BlockInputType
Private Functions
- typedef LAYEROUTPUTTYPE (PipelineBlockType) BlockOutputType
Private Members
-
PipelineBlockType &block
-
RingBuffer<OutputType> yval_buf_v
-
size_t calls
-
OutputType ypred
-
OutputType yval
-
int nparam
-
int value_lag
-
int deriv_lag
-
int rank
-
inline PipelineCostFuncWrapper(PipelineBlockType &block, const CostFunc &cost = CostFunc())
-
struct LockControlWrapper
Subclassed by LockControlWrapperTensor< FloatType, Dim >
-
template<typename FloatType, int Dim>
struct LockControlWrapperTensor : public LockControlWrapper
-
class PipelineCommunicator
Subclassed by PipelineBlock< BlockStore, InputType_, OutputType_ >
Public Functions
-
inline PipelineCommunicator()
-
inline int pipelineDepth() const
-
inline void waitAll(const std::vector<CommsRequest> &reqs)
-
template<typename T, typename U>
inline void passLeft(std::vector<CommsRequest> &reqs, T const *send_bulk, T const *send_last, U *recv_first, U *recv_bulk) const
-
template<typename T, typename U>
inline void passRight(std::vector<CommsRequest> &reqs, T const *send_first, T const *send_bulk, U *recv_bulk, U *recv_last) const
-
template<typename T>
inline void passLeftLastToFirst(std::vector<CommsRequest> &reqs, T const *send_last, T *recv_first)
Public Static Functions
-
template<typename T>
static inline CommsRequest send(const T &mat, int to)
-
template<typename T>
static inline CommsRequest recv(T &mat, int from)
-
inline PipelineCommunicator()
-
template<typename BlockStore, typename InputType_, typename OutputType_>
class PipelineBlock : public PipelineCommunicator Public Types
-
typedef BlockStore::type::FloatType FloatType
-
typedef BlockStore::type::InputType BlockInputType
-
typedef InputType_ InputType
-
typedef OutputType_ OutputType
Public Functions
- typedef LAYEROUTPUTTYPE (typename BlockStore::type) BlockOutputType
-
inline PipelineBlock(BlockStore &&_block, int const *block_output_dims_, int const *block_input_dims_)
-
PipelineBlock(const PipelineBlock &r) = delete
-
PipelineBlock(PipelineBlock &&r) = default
-
inline int nparams() const
-
inline int valueLag() const
-
inline int derivLag() const
-
inline OutputType value(const InputType &in)
-
inline void deriv(Vector<FloatType> &cost_deriv, OutputType &&above_deriv)
Private Functions
-
template<typename OutType, typename B, typename std::enable_if<!std::is_same<typename std::decay<B>::type, OutType>::value, int>::type = 0>
inline OutType get_as(B &&v)
-
template<typename OutType, typename B, typename std::enable_if<std::is_same<typename std::decay<B>::type, OutType>::value, int>::type = 0>
inline OutType get_as(B &&v)
-
typedef BlockStore::type::FloatType FloatType
Random
Typedefs
-
typedef std::mt19937 GlobalRNGtype
Functions
-
GlobalRNGtype &globalRNG()
-
inline void reseedGlobalRNG(size_t seed)
-
template<typename FloatType, int Dim, typename Dist, typename RNG>
void random(Tensor<FloatType, Dim> &m, Dist &dist, RNG &rng)
-
template<typename FloatType, int Dim, typename RNG>
void uniformRandom(Tensor<FloatType, Dim> &m, RNG &rng, FloatType min = FloatType(-1.0), FloatType max = FloatType(1.0))
-
template<typename FloatType, int Dim>
inline void uniformRandom(Tensor<FloatType, Dim> &m, FloatType min = FloatType(-1.0), FloatType max = FloatType(1.0))
-
template<typename FloatType, typename RNG>
void glorotUniformRandom(Matrix<FloatType> &m, RNG &rng, FloatType gain = FloatType(1.0))
-
template<typename FloatType>
inline void glorotUniformRandom(Matrix<FloatType> &m, FloatType gain = FloatType(1.0))
Variables
-
constexpr size_t default_seed = 1234
RingBuffer
Serialization
Functions
-
std::string toString(const Endianness e)
-
Endianness endianness()
-
uint8_t BitReverseTable256(size_t i)
-
class BinaryWriter
Public Functions
-
BinaryWriter(const std::string &filename, const Endianness end = Endianness::System)
-
template<typename Model, typename std::enable_if<ISLEAF(Model), int>::type = 0>
void write(const Model &model)
-
template<typename Store, typename CostFunc>
void write(const CostFuncWrapper<Store, CostFunc> &model)
-
inline void close()
-
BinaryWriter(const std::string &filename, const Endianness end = Endianness::System)
-
class BinaryReader
Tensors
Typedefs
Functions
- template<size_t Dim> accelerator_inline size_t tensorSize (int const *dims)
Compute the linear size of a tensor of dimension “Dim” and the provided dimensions.
- Parameters:
dims – The tensor dimension (array of size Dim)
- template<size_t Dim> accelerator_inline size_t tensorOffset (int const *coord, int const *dims)
Compute the linear (pointer) offset of a specific coordate within a tensor of dimension “Dim” and the provided dimensions.
- Parameters:
coor – The coordinate (array of size Dim)
dims – The tensor dimension (array of size Dim)
- template<size_t Dim> accelerator_inline void tensorOffsetUnmap (int *coord, int const *dims, size_t offset)
Compute the coordinate associated with a specific linear (pointer) offset for a tensor of dimension “Dim” and the provided dimensions.
- Parameters:
coord – [out] The tensor coordinate (array of size Dim)
dims – [in] The tensor dimension (array of size Dim)
offset – [in] The input linear offset
- template<int Dim> accelerator_inline size_t tensorDimensionStride (int iter_dim, int const *size)
Compute the stride for iterating over a specific dimension for a tensor of dimension “Dim” with the provided dimensions.
- Parameters:
iter_dim – The dimension that will be iterated over
size – The tensor dimension (array of size Dim)
- template<int Dim> accelerator_inline size_t tensorDimensionBase (int iter_dim, int const *other_coord, int const *size)
Compute the linear (pointer) offset for the base element for iterating over a specific dimension of a tensor of dimension “Dim”.
- Parameters:
iter_dim – The dimension that will be iterated over
other_coor – The coordinates for the other dimensions (array of size Dim-1)
size – The tensor dimension (array of size Dim)
- template<int Dim> accelerator_inline size_t batchTensorDimensionBaseLin (int iter_dim, int batch_idx, size_t other_dim_lin, int const *size)
Compute the linear (pointer) offset for the base element for iterating over a specific dimension for a batch-tensor (last dim is the batch dimension) of dimension “Dim”.
- Parameters:
iter_dim – The dimension that will be iterated over
batch_idx – The batch index (coordinate in last dimension)
other_dim_lin – The coordinates in dimensions apart from iter_dim and Dim-1 expressed as a lexicographic linear index in descending order, e.g. z + size_z * (y + size_y * x)
size – The tensor dimension (array of size Dim)
-
template<typename FloatType>
void pokeColumn(Matrix<FloatType> &into, int col, const Vector<FloatType> &data) Insert a vector as particular column of a matrix, i.e. into(:,col) = data(:)
- Parameters:
The – target matrix
col – The column index
data – The input column
-
template<typename FloatType>
void pokeRow(Matrix<FloatType> &into, int row, const Vector<FloatType> &data) Insert a vector as particular row of a matrix, i.e. into(row,:) = data(:)
- Parameters:
The – target matrix
row – The row index
data – The input row
-
template<typename FloatType>
Vector<FloatType> peekColumn(const Matrix<FloatType> &m, int col) Retrieve a specific column of a matrix m, i.e. return m(:,col)
- Parameters:
m – The matrix
col – The column index
-
template<typename FloatType>
Matrix<FloatType> peekColumns(const Matrix<FloatType> &m, int col_start, int col_end) Retrieve multiple consecutive columns of a matrix m, i.e. return m(:,col_start:col_end+1)
- Parameters:
m – The matrix
col_start – The first column index
col_end – The last column index
-
template<typename FloatType>
void pokeColumns(Matrix<FloatType> &into, int col_start, int col_end, const Matrix<FloatType> &cols) Insert multiple consecutive columns of a matrix m, i.e. into(:,col_start:col_end+1) = cols(:,:)
- Parameters:
into – The matrix in which to insert the columns
col_start – The first column index
col_end – The last column index
cols – The matrix containing the columns (cols = col_end-col_start+1)
-
template<typename FloatType>
std::ostream &operator<<(std::ostream &os, const Vector<FloatType> &v) Output a vector to a stream.
-
template<typename FloatType>
std::ostream &operator<<(std::ostream &os, const Matrix<FloatType> &v) Output a matrix to a stream.
-
template<typename FloatType>
Vector<FloatType> operator*(const Matrix<FloatType> &A, const Vector<FloatType> &x) Perform the matrix-vector product of A and x.
-
template<typename FloatType, int Dim>
Tensor<FloatType, Dim> &operator+=(Tensor<FloatType, Dim> &a, const Tensor<FloatType, Dim> &b) Addition-assignment operator for tensors.
-
template<typename FloatType, int Dim>
Tensor<FloatType, Dim> operator+(const Tensor<FloatType, Dim> &a, const Tensor<FloatType, Dim> &b) Addition operator for tensors.
-
template<typename FloatType, int Dim>
Tensor<FloatType, Dim> &operator-=(Tensor<FloatType, Dim> &a, const Tensor<FloatType, Dim> &b) Subtraction-assignment operator for tensors.
-
template<typename FloatType, int Dim>
Tensor<FloatType, Dim> operator-(const Tensor<FloatType, Dim> &a, const Tensor<FloatType, Dim> &b) Subtraction operator for tensors.
-
template<typename FloatType, int Dim>
Tensor<FloatType, Dim> &operator*=(Tensor<FloatType, Dim> &a, FloatType eps) Scalar multiplication-assignment operator for tensors.
-
template<typename FloatType, int Dim>
Tensor<FloatType, Dim> operator*(FloatType eps, const Tensor<FloatType, Dim> &b) Scalar left-multiplication operator for tensors.
-
template<typename FloatType, int Dim>
inline Tensor<FloatType, Dim> operator*(const Tensor<FloatType, Dim> &b, FloatType eps) Scalar right-multiplication operator for tensors.
-
template<int Dim, typename FloatType>
Vector<FloatType> flatten(const Tensor<FloatType, Dim> &t) “Flatten” a tensor into a vector. The output mapping is lexicographic in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
-
template<int Dim, typename FloatType>
FloatType *flatten(FloatType *host_ptr, const Tensor<FloatType, Dim> &in) “Flatten” a tensor into a pre-allocated host array and return the pointer to the element of the array one past the flattened tensor.
- Parameters:
host_ptr – The host array destination. The output mapping is lexicographic in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
in – The input tensor
- Returns:
A pointer to the element of the array one past the flattened tensor. note, the copy is performed on the host side
-
template<int Dim, typename FloatType>
void unflatten(Tensor<FloatType, Dim> &out, const Vector<FloatType> &t) “Unflatten” vector into tensor
- Parameters:
out – The output tensor. Its dimensions should be set correctly prior to calling this function
t – The input vector. The input mapping is lexicographic in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
-
template<int Dim, typename FloatType>
FloatType const *unflatten(Tensor<FloatType, Dim> &out, FloatType const *host_ptr) “Unflatten” a tensor from a pre-allocated host array and return the pointer to the element of the array one past the flattened tensor.
- Parameters:
out – The output tensor. Its dimensions should be set correctly prior to calling this function
host_ptr – The input array pointer. The input mapping is lexicographic in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
- Returns:
A pointer to the element of the array one past the flattened tensor. note, the copy is performed on the host side
-
template<int Dim1, int Dim2, typename FloatType>
Vector<FloatType> flatten2(const Tensor<FloatType, Dim1> &t1, const Tensor<FloatType, Dim2> &t2) Flatten two tensors into a single contiguous array.
- Parameters:
t1 – The first tensor
t2 – The second tensor
- Returns:
An output vector of length t1.data_len() + t2.data_len(), where the elements within the sub-arrays are obtained from their corresponding tensor via a lexicographic mapping in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
-
template<int Dim1, int Dim2, typename FloatType>
void unflatten2(Tensor<FloatType, Dim1> &t1, Tensor<FloatType, Dim2> &t2, const Vector<FloatType> &v) Unflatten two tensors from a single contiguous array.
The output tensor dimensions should be set appropriately prior to calling this function
- Parameters:
t1 – [out] The first tensor
t2 – [out] The first tensor
v – [in] An input vector of length t1.data_len() + t2.data_len(), where the elements within the sub-arrays map to their corresponding tensor coordinates via a lexicographic mapping in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
-
template<int Dim, typename FloatType>
Vector<FloatType> flattenNsameDim(Tensor<FloatType, Dim> const *const *tens, int N) Flatten N tensors of the same dimension into a single contiguous array.
- Parameters:
tens – An array of pointers to input tensors
N – The number of tensors
- Returns:
An output vector of length \sum_i tens[i].data_len(), where the elements within the sub-arrays are obtained from their corresponding tensor via a lexicographic mapping in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
-
template<int Dim, typename FloatType>
void unflattenNsameDim(Tensor<FloatType, Dim> *const *tens, int N, const Vector<FloatType> &v) Unflatten N tensors of the same dimension from a single contiguous array.
- Parameters:
tens – The output tensor array. The tensor dimensions should be set appropriately prior to calling this function.
N – The number of tensors
v – The input vector. This must have length \sum_i tens[i].data_len(), where the elements within the sub-arrays map to their corresponding tensor coordinates via a lexicographic mapping in descending order, e.g. (x,y,z) -> z + sizez*(y + sizey*x)
-
template<int Dim, typename FloatType>
Tensor<FloatType, Dim> batchTensorConcatenate(Tensor<FloatType, Dim> const *const *in, int Ntens, int concat_dim) Concatenate (stack) Ntens tensors along a dimension concat_dim < Dim-1 (last dim is assumed to be the batch index).
Dimensions other than concat_dim must all have the same size.
- Parameters:
in – The input tensor array
Ntens – The number of tensors
concat_dim – The dimension along which the concatenation is performed
-
template<int Dim, typename FloatType>
void batchTensorSplit(Tensor<FloatType, Dim> *const *out, int Ntens, const Tensor<FloatType, Dim> &in, int split_dim) Split a tensor along a dimension split_dim < Dim-1 (last dim is the batch index) into multiple tensors.
Dimensions other than split_dim must all have the same size.
- Parameters:
out – The output tensors. These should be pre-initialized to the appropriate sizes.
Ntens – The number of output tensors
in – The input tensor
split_dim – The dimension along which to split
-
template<typename _FloatType, int Dim>
struct Tensor - #include <Tensors.hpp>
A class for tensors of arbitrary dimension and floating point type.
Public Types
Values:
-
enumerator Dimension
-
enumerator Dimension
-
typedef _FloatType FloatType
The floating point type
-
typedef const int *Dims
Array type for tensor dimensions
-
typedef const int *Coord
Array type for tensor coordinates
Public Functions
-
inline Tensor()
Default constructor for a zero-size tensor.
-
inline Tensor(Dims dims, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a tensor with the provided dimensions with the initial memory allocation in the provided pool.
- Parameters:
dims – The tensor dimensions
alloc_pool – The memory pool for the initial allocatio (default: device)
-
inline Tensor(Dims dims, FloatType init, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a tensor with the provided dimensions uniformly initialized with the provided value with the initial memory allocation in the provided pool.
- Parameters:
dims – The tensor dimensions
init – The initial value for all elements
alloc_pool – The memory pool for the initial allocatio (default: device)
-
inline Tensor(Dims dims, const std::vector<FloatType> &init_vals)
Construct a tensor with the provided dimensions initialized from the provided array. The initial memory allocation will be in the host pool.
- Parameters:
dims – The tensor dimensions
init_vals – The initial values with lexicographic mapping in descending order, e.g. z + size_z * (y + size_y * x)
-
inline Tensor(Dims dims, FloatType const *init_vals)
Construct a tensor with the provided dimensions initialized from the provided array. The initial memory allocation will be in the host pool.
- Parameters:
dims – The tensor dimensions
init_vals – The initial values with lexicographic mapping in descending order, e.g. z + size_z * (y + size_y * x)
-
inline _1D_TENSOR_ONLY Tensor(int len, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 1D tensor (vector) with the provided length with the initial memory allocation in the provided pool.
- Parameters:
len – The vector length
alloc_pool – The memory pool for the initial allocatio (default: device)
-
inline _1D_TENSOR_ONLY Tensor(int len, FloatType init, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 1D tensor (vector) with the provided length uniformly initialized with the provided value with the initial memory allocation in the provided pool.
- Parameters:
len – The vector length
init – The initial value for all elements
alloc_pool – The memory pool for the initial allocatio (default: device)
-
inline _1D_TENSOR_ONLY Tensor(const std::vector<FloatType> &init_vals)
Construct a 1D tensor (vector) initialized from the provided array. The initial memory allocation will be in the host pool.
- Parameters:
init_vals – The initial values
-
inline _2D_TENSOR_ONLY Tensor(int size0, int size1, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 2D tensor (matrix) with the provided dimensions with the initial memory allocation in the provided pool.
- Parameters:
size0 – The size of the 1st dimension (number of rows)
size1 – The size of the 2nd dimension (number of columns)
alloc_pool – The memory pool for the initial allocatio (default: device)
-
inline _2D_TENSOR_ONLY Tensor(int size0, int size1, FloatType init, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 2D tensor (matrix) with the provided dimensions, uniformly initialized with the provided value with the initial memory allocation in the provided pool.
- Parameters:
size0 – The size of the 1st dimension (number of rows)
size1 – The size of the 2nd dimension (number of columns)
init – The initial value for all elements
alloc_pool – The memory pool for the initial allocation (default: device)
-
inline _2D_TENSOR_ONLY Tensor(int size0, int size1, const std::vector<FloatType> &init_vals)
Construct a 2D tensor (matrix) with the provided dimensions, initialized from the provided array. The initial memory allocation will be in the host pool.
- Parameters:
size0 – The size of the 1st dimension (number of rows)
size1 – The size of the 2nd dimension (number of columns)
init_vals – The initial values with lexicographic mapping y + size1*x for coord (x,y)
-
inline _3D_TENSOR_ONLY Tensor(int size0, int size1, int size2, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 3D tensor with the provided dimensions with the initial memory allocation in the provided pool.
- Parameters:
size0 – The size of the 1st dimension
size1 – The size of the 2nd dimension
size2 – The size of the 3rd dimension
alloc_pool – The memory pool for the initial allocatio (default: device)
-
inline _3D_TENSOR_ONLY Tensor(int size0, int size1, int size2, FloatType init, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 3D tensor with the provided dimensions, uniformly initialized with the provided value with the initial memory allocation in the provided pool.
- Parameters:
size0 – The size of the 1st dimension
size1 – The size of the 2nd dimension
size2 – The size of the 3rd dimension
init – The initial value for all elements
alloc_pool – The memory pool for the initial allocation (default: device)
-
inline _3D_TENSOR_ONLY Tensor(int size0, int size1, int size2, const std::vector<FloatType> &init_vals)
Construct a 3D tensor with the provided dimensions, initialized from the provided array. The initial memory allocation will be in the host pool.
- Parameters:
size0 – The size of the 1st dimension
size1 – The size of the 2nd dimension
size2 – The size of the 3rd dimension
init_vals – The initial values with lexicographic mapping z + size2*(y + size1*x) for coord (x,y,z)
-
inline _4D_TENSOR_ONLY Tensor(int size0, int size1, int size2, int size3, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 4D tensor with the provided dimensions with the initial memory allocation in the provided pool.
- Parameters:
size0 – The size of the 1st dimension
size1 – The size of the 2nd dimension
size2 – The size of the 3rd dimension
size3 – The size of the 4th dimension
alloc_pool – The memory pool for the initial allocatio (default: device)
-
inline _4D_TENSOR_ONLY Tensor(int size0, int size1, int size2, int size3, FloatType init, MemoryManager::Pool alloc_pool = MemoryManager::Pool::DevicePool)
Construct a 4D tensor with the provided dimensions, uniformly initialized with the provided value with the initial memory allocation in the provided pool.
- Parameters:
size0 – The size of the 1st dimension
size1 – The size of the 2nd dimension
size2 – The size of the 3rd dimension
size3 – The size of the 4th dimension
init – The initial value for all elements
alloc_pool – The memory pool for the initial allocation (default: device)
-
inline _4D_TENSOR_ONLY Tensor(int size0, int size1, int size2, int size3, const std::vector<FloatType> &init_vals)
Construct a 4D tensor with the provided dimensions, initialized from the provided array. The initial memory allocation will be in the host pool.
- Parameters:
size0 – The size of the 1st dimension
size1 – The size of the 2nd dimension
size2 – The size of the 3rd dimension
size3 – The size of the 4th dimension
init_vals – The initial values with lexicographic mapping t + size3*(z + size2*(y + size1*x) ) for coord (x,y,z,t)
-
inline int const *sizeArray() const
Return the tensor dimensions as an array pointer.
-
inline int size(int i) const
Return the tensor size along a specific dimension.
- Parameters:
i – The dimension
-
inline std::string sizeArrayString() const
Return the tensor dimensions as a string.
-
inline size_t data_len() const
Return the linear dimension (flattened size) of the tensor, or equivalently, the total number of elements.
-
inline View view(ViewMode mode) const
Return a view to this tensor opened with a specific view mode.
-
inline void lock() const
“Lock” the memory region associated with this object such that it cannot be auto-evicted to free space in a memory pool. A possible use case is to ensure a memory region remains valid while performing an asynchronouse background copy
-
inline void unlock() const
“Unlock the memory region, allowing it to be evicted. This is the default state.
-
Tensor sliceLastDimension(int idx_start, int idx_end) const
Return a tensor where the last dimension contains the slice between idx_start and idx_end (inclusive). E.g., for a 3D tensor T, return T(:,:,idx_start:idx_end+1)
-
void pokeLastDimension(const Tensor<FloatType, Dim - 1> &ins, const int idx)
Insert a tensor of Dim-1 such that (*this)(i,j,k,…, idx) = ins(i,j,k,…). E.g., for a 3D tensor T and 2D input I, set T[:,:,idx] = I[:,:].
- Parameters:
ins – The Dim-1 dimensional tensor to insert
idx – The index in the last dimension on which to insert the tensor
Public Static Functions
-
static inline constexpr int dimension()
Return the tensor dimension.
Private Members
-
ManagedArray<FloatType> vals
Memory-contiguous container for tensor data
-
class View : private ManagedArray<FloatType>::View
- #include <Tensors.hpp>
The tensor View accessor class
Public Functions
-
inline View(ViewMode mode, const Tensor<FloatType, Dim> &parent)
Construct a view with a specific view mode and parent object.
- Parameters:
mode – The view mode
parent – The parent object
-
inline void free()
Free the view. This must be called explicitly once the view is no longer needed.
- inline accelerator_inline FloatType & operator() (const Coord coord)
Access the tensor at the provided coordinate.
- inline accelerator_inline FloatType operator() (const Coord coord) const
Access the tensor at the provided coordinate.
- inline _1D_TENSOR_ONLY accelerator_inline FloatType & operator() (int i)
Access the 1D tensor at the index (i)
- inline _1D_TENSOR_ONLY accelerator_inline FloatType operator() (int i) const
Access the 1D tensor at the index (i)
- inline _2D_TENSOR_ONLY accelerator_inline FloatType & operator() (int i, int j)
Access the 2D tensor at the coordinate (i,j)
- inline _2D_TENSOR_ONLY accelerator_inline FloatType operator() (int i, int j) const
Access the 2D tensor at the coordinate (i,j)
- inline _3D_TENSOR_ONLY accelerator_inline FloatType & operator() (int i, int j, int k)
Access the 3D tensor at the coordinate (i,j,k)
- inline _3D_TENSOR_ONLY accelerator_inline FloatType operator() (int i, int j, int k) const
Access the 3D tensor at the coordinate (i,j,k)
- inline _4D_TENSOR_ONLY accelerator_inline FloatType & operator() (int i, int j, int k, int l)
Access the 4D tensor at the coordinate (i,j,k,l)
- inline _4D_TENSOR_ONLY accelerator_inline FloatType operator() (int i, int j, int k, int l) const
Access the 4D tensor at the coordinate (i,j,k,l)
- inline accelerator_inline FloatType const * data () const
Return a pointer to the underlying array.
- inline accelerator_inline FloatType * data ()
Return a pointer to the underlying array.
- inline accelerator_inline size_t data_len () const
Return the linear dimension (flattened size) of the tensor, or equivalently, the total number of elements.
- inline accelerator_inline size_t size (int i) const
Return the tensor size along a specific dimension.
- Parameters:
i – The dimension
- inline accelerator_inline int const * sizeArray () const
Return the tensor dimensions as an array pointer.
- inline accelerator_inline FloatType & compact3 (int i, int j, int k)
Access a tensor element at a coordinate expressed such that the first Dim-2 dimensions are expressed lexicographically.
- Parameters:
i – The first Dim-2 dimensions expressed lexicographically in descending order (e.g. z+sizez*(y+sizey*x))
j – The index of dimension Dim-2
k – The index of dimension Dim-1
- inline accelerator_inline FloatType compact3 (int i, int j, int k) const
Access a tensor element at a coordinate expressed such that the first Dim-2 dimensions are expressed lexicographically.
- Parameters:
i – The first Dim-2 dimensions expressed lexicographically in descending order (e.g. z+sizez*(y+sizey*x))
j – The index of dimension Dim-2
k – The index of dimension Dim-1
Private Types
-
typedef ManagedArray<FloatType>::View Base
-
inline View(ViewMode mode, const Tensor<FloatType, Dim> &parent)
Testing
Functions
-
template<typename FloatType>
bool near(FloatType a, FloatType b, FloatType rel_tol, FloatType *reldiff_p = nullptr)
-
template<typename FloatType>
bool near(const Vector<FloatType> &a, const Vector<FloatType> &b, FloatType rel_tol, bool verbose = false)
-
template<typename FloatType>
bool near(const Matrix<FloatType> &a, const Matrix<FloatType> &b, FloatType rel_tol, bool verbose = false)
-
template<typename FloatType>
bool abs_near(FloatType a, FloatType b, FloatType abs_tol, FloatType *absdiff_p = nullptr)
-
template<typename FloatType>
bool abs_near(const Matrix<FloatType> &a, const Matrix<FloatType> &b, FloatType abs_tol, bool verbose = false)
-
template<typename FloatType, int Dim>
bool abs_near(const Tensor<FloatType, Dim> &a, const Tensor<FloatType, Dim> &b, FloatType abs_tol, bool verbose = false)
-
template<typename FloatType, int Dim>
bool equal(const Tensor<FloatType, Dim> &a, const Tensor<FloatType, Dim> &b, bool verbose = false)
-
template<typename Op, typename PreOp>
void benchmark(double &mean, double &std, int nrpt, int nwarmup, const Op &op, const PreOp &preop)
-
template<typename TensType>
TensType::FloatType testCost(const Vector<typename TensType::FloatType> &c, const TensType &v)
-
template<typename ModelType>
void testDeriv(ModelType &model, int const *in_sizes, int const *out_sizes, typename ModelType::FloatType delta = typename ModelType::FloatType(1e-4))
-
template<typename ComponentWrapper>
void testComponentDeriv(ComponentWrapper &cpt, typename ComponentWrapper::FloatType delta = typename ComponentWrapper::FloatType(1e-4), bool _2nd_order = false)
Timing
Batch3tensorPairContractComponent
-
template<typename _FloatType>
class Batch3tensorPairContractComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
inline Batch3tensorPairContractComponent(int contract_dim_A, int contract_dim_B, FloatType nrm = 1.0)
-
Batch3tensorPairContractComponent(const Batch3tensorPairContractComponent &r) = delete
-
Batch3tensorPairContractComponent(Batch3tensorPairContractComponent &&r) = default
-
inline void deriv(Tensor<FloatType, 3> &&_dcost_by_dC, Tensor<FloatType, 3> &dcost_by_dA, Tensor<FloatType, 3> &dcost_by_dB) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
int contract_dim_A
-
int contract_dim_B
-
mutable FLOPScounter value_FLOPS
-
mutable FLOPScounter deriv_FLOPS
-
mutable RingBuffer<Tensor<FloatType, 3>> A_buf
-
mutable RingBuffer<Tensor<FloatType, 3>> B_buf
-
typedef _FloatType FloatType
BatchedMatrixRowSoftMaxComponent
-
template<typename _FloatType>
class BatchedMatrixRowSoftMaxComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
BatchedMatrixRowSoftMaxComponent(const BatchedMatrixRowSoftMaxComponent &r) = delete
-
BatchedMatrixRowSoftMaxComponent(BatchedMatrixRowSoftMaxComponent &&r) = default
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
mutable RingBuffer<Tensor<FloatType, 3>> out_buf
-
mutable FLOPScounter value_FLOPS
-
mutable FLOPScounter deriv_FLOPS
-
bool use_mask
-
typedef _FloatType FloatType
BatchTensorConcatenateComponent
-
template<typename _FloatType, int TensDim>
class BatchTensorConcatenateComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
inline BatchTensorConcatenateComponent(int concat_dim, int Ntens)
-
BatchTensorConcatenateComponent(const BatchTensorConcatenateComponent &r) = delete
-
BatchTensorConcatenateComponent(BatchTensorConcatenateComponent &&r) = default
-
inline void deriv(Tensor<FloatType, TensDim> &&_dcost_by_dOut, Tensor<FloatType, TensDim> *const *dcost_by_dIn) const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
typedef _FloatType FloatType
BatchTensorDimensionSliceComponent
-
template<typename _FloatType, int TensDim>
class BatchTensorDimensionSliceComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
inline BatchTensorDimensionSliceComponent(int slice_dim, int slice_idx)
-
BatchTensorDimensionSliceComponent(const BatchTensorDimensionSliceComponent &r) = delete
-
BatchTensorDimensionSliceComponent(BatchTensorDimensionSliceComponent &&r) = default
-
void deriv(Tensor<FloatType, TensDim - 1> &&dcost_by_dOut, Tensor<FloatType, TensDim> &dcost_by_dIn) const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
typedef _FloatType FloatType
BatchTensorDNNcomponent
-
template<typename _FloatType, int TensDim, typename ActivationFunc>
class BatchTensorDNNcomponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
inline BatchTensorDNNcomponent(const Matrix<FloatType> &weights, const Vector<FloatType> &bias, int contract_dim, const ActivationFunc &activation)
-
inline BatchTensorDNNcomponent(const Matrix<FloatType> &_weights, int contract_dim, const ActivationFunc &activation)
-
BatchTensorDNNcomponent(const BatchTensorDNNcomponent &r) = delete
-
BatchTensorDNNcomponent(BatchTensorDNNcomponent &&r) = default
-
void deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, TensDim> &&dCost_by_dOut, Tensor<FloatType, TensDim> &dCost_by_dIn) const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
int batch_size
-
int contract_dim
-
bool use_bias
-
size_t other_size
-
size_t stride
-
mutable FLOPScounter value_FLOPS
-
mutable FLOPScounter deriv_FLOPS
-
bool setup
-
ActivationFunc activation_func
-
mutable RingBuffer<Tensor<FloatType, TensDim>> in_buf
-
mutable RingBuffer<Tensor<FloatType, TensDim>> activation_deriv_buf
-
typedef _FloatType FloatType
MatrixTensorContractComponent
-
template<typename _FloatType, int TensDim>
class MatrixTensorContractComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
MatrixTensorContractComponent(const MatrixTensorContractComponent &r) = delete
-
MatrixTensorContractComponent(MatrixTensorContractComponent &&r) = default
-
void deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, TensDim> &&dCost_by_dOut, Tensor<FloatType, TensDim> &dCost_by_dIn) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
typedef _FloatType FloatType
MultiHeadAttentionComponent
-
template<typename _FloatType>
class MultiHeadAttentionComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
MultiHeadAttentionComponent(int Nheads, Matrix<FloatType> const *const *W_Q, Matrix<FloatType> const *const *W_K, Matrix<FloatType> const *const *W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
-
MultiHeadAttentionComponent(int Nheads, const std::vector<Matrix<FloatType>> &W_Q, const std::vector<Matrix<FloatType>> &W_K, const std::vector<Matrix<FloatType>> &W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
-
MultiHeadAttentionComponent(const MultiHeadAttentionComponent &r) = delete
-
MultiHeadAttentionComponent(MultiHeadAttentionComponent &&r) = default
-
TensorType value(const TensorType &Q, const TensorType &K, const TensorType &V)
-
void deriv(Vector<FloatType> &cost_deriv, int off, TensorType &&dCost_by_dOut, TensorType &dCost_by_dQ, TensorType &dCost_by_dK, TensorType &dCost_by_dV) const
-
inline int nparams() const
-
size_t FLOPS(int value_or_deriv) const
-
void resizeInputBuffer(size_t to)
Private Members
-
int C
-
int E
-
int B
-
int Nparams_layer
-
bool setup
-
std::vector<std::unique_ptr<ScaledDotProductAttentionHeadComponent<FloatType>>> heads
-
BatchTensorConcatenateComponent<FloatType, 3> concatY
-
MatrixTensorContractComponent<FloatType, 3> multW_O
-
typedef _FloatType FloatType
NormComponent
-
template<typename _FloatType, int TensDim>
class NormComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
NormComponent(const NormComponent &r) = delete
-
NormComponent(NormComponent &&r) = default
-
void deriv(Tensor<FloatType, TensDim> &&dcost_by_dOut, Tensor<FloatType, TensDim> &dcost_by_dIn) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
typedef _FloatType FloatType
ScaleComponent
-
template<typename _FloatType, int TensDim>
class ScaleComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
inline ScaleComponent(int scale_dim, int dimension_size, bool use_affine, bool use_bias, const Vector<FloatType> &affine_init, const Vector<FloatType> &bias_init)
-
ScaleComponent(const ScaleComponent &r) = delete
-
ScaleComponent(ScaleComponent &&r) = default
-
void deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, TensDim> &&dcost_by_dOut, Tensor<FloatType, TensDim> &dcost_by_dIn) const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
inline void resizeInputBuffer(size_t to)
-
typedef _FloatType FloatType
ScaledDotProductAttentionComponent
-
template<typename _FloatType>
class ScaledDotProductAttentionComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
inline ScaledDotProductAttentionComponent(int d_k, int d_v, int use_mask = false)
-
ScaledDotProductAttentionComponent(const ScaledDotProductAttentionComponent &r) = delete
-
ScaledDotProductAttentionComponent(ScaledDotProductAttentionComponent &&r) = default
-
Tensor<FloatType, 3> value(const Tensor<FloatType, 3> &Q, const Tensor<FloatType, 3> &K, Tensor<FloatType, 3> &V)
-
void deriv(Tensor<FloatType, 3> &&dCost_by_dOut, Tensor<FloatType, 3> &dCost_by_dQ, Tensor<FloatType, 3> &dCost_by_dK, Tensor<FloatType, 3> &dCost_by_dV) const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
int C
-
int B
-
int d_k
-
int d_v
-
bool setup
-
Batch3tensorPairContractComponent<FloatType> mulQKtoGetS
-
BatchedMatrixRowSoftMaxComponent<FloatType> softmaxS_to_SS
-
Batch3tensorPairContractComponent<FloatType> mulSSVtoGetOut
-
typedef _FloatType FloatType
ScaledDotProductAttentionHeadComponent
-
template<typename _FloatType>
class ScaledDotProductAttentionHeadComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
inline ScaledDotProductAttentionHeadComponent(const Matrix<FloatType> &W_Q, const Matrix<FloatType> &W_K, const Matrix<FloatType> &W_V, bool use_mask = false)
-
ScaledDotProductAttentionHeadComponent(const ScaledDotProductAttentionHeadComponent &r) = delete
-
ScaledDotProductAttentionHeadComponent(ScaledDotProductAttentionHeadComponent &&r) = default
-
Tensor<FloatType, 3> value(const Tensor<FloatType, 3> &Q, const Tensor<FloatType, 3> &K, const Tensor<FloatType, 3> &V)
-
void deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, 3> &&dCost_by_dOut, Tensor<FloatType, 3> &dCost_by_dQ, Tensor<FloatType, 3> &dCost_by_dK, Tensor<FloatType, 3> &dCost_by_dV) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
Private Types
-
typedef MatrixTensorContractComponent<FloatType, 3> MatTensMulCptType
Private Members
-
int C
-
int B
-
int E
-
int d_k
-
int d_v
-
bool setup
-
MatTensMulCptType multWQ
-
MatTensMulCptType multWK
-
MatTensMulCptType multWV
-
ScaledDotProductAttentionComponent<FloatType> attention
-
typedef _FloatType FloatType
SoftMaxComponent
-
template<typename _FloatType, int TensDim>
class SoftMaxComponent Public Types
-
typedef _FloatType FloatType
Public Functions
-
SoftMaxComponent(const SoftMaxComponent &r) = delete
-
SoftMaxComponent(SoftMaxComponent &&r) = default
-
void deriv(Tensor<FloatType, TensDim> &&dcost_by_dOut, Tensor<FloatType, TensDim> &dcost_by_dIn) const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
int softmax_dim
-
mutable FLOPScounter value_FLOPS
-
mutable FLOPScounter deriv_FLOPS
-
mutable RingBuffer<Tensor<FloatType, TensDim>> out_buf
-
typedef _FloatType FloatType
BatchTensorDNNlayer
Functions
-
template<int TensDim, typename U, typename ActivationFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto batch_tensor_dnn_layer(const Matrix<FLOATTYPE(U)> &weights, const Vector<FLOATTYPE(U)> &bias, int contract_dim, const ActivationFunc &activation, U &&u) -> LAYER_TYPE
-
template<int TensDim, typename U, typename ActivationFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto batch_tensor_dnn_layer(const Matrix<FLOATTYPE(U)> &weights, int contract_dim, const ActivationFunc &activation, U &&u) -> LAYER_TYPE
-
template<int TensDim, typename U, typename ActivationFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto batch_tensor_dnn_layer(int contract_dim, int fan_out, int fan_in, const ActivationFunc &activation, U &&u) -> LAYER_TYPE
-
template<int TensDim, typename U, typename ActivationFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto batch_tensor_unbiased_dnn_layer(int contract_dim, int fan_out, int fan_in, const ActivationFunc &activation, U &&u) -> LAYER_TYPE
-
template<typename U, typename ActivationFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto dnn_layer(const Matrix<FLOATTYPE(U)> &weights, const Vector<FLOATTYPE(U)> &bias, const ActivationFunc &activation, U &&u)
-
template<typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto dnn_layer(const Matrix<FLOATTYPE(U)> &weights, const Vector<FLOATTYPE(U)> &bias, U &&u)
-
template<typename U, typename ActivationFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto dnn_layer(int fan_out, int fan_in, const ActivationFunc &activation, U &&u)
-
template<typename _FloatType, int TensDim, typename _InputType, typename Store, typename ActivationFunc>
class BatchTensorDNNlayer -
Public Functions
-
inline BatchTensorDNNlayer(Store &&leaf, const Matrix<FloatType> &weights, const Vector<FloatType> &bias, int contract_dim, const ActivationFunc &activation)
-
inline BatchTensorDNNlayer(Store &&leaf, const Matrix<FloatType> &weights, int contract_dim, const ActivationFunc &activation)
-
BatchTensorDNNlayer(const BatchTensorDNNlayer &r) = delete
-
BatchTensorDNNlayer(BatchTensorDNNlayer &&r) = default
-
int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, TensDim> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline int nparams() const
-
inline void resizeInputBuffer(size_t to)
-
inline BatchTensorDNNlayer(Store &&leaf, const Matrix<FloatType> &weights, const Vector<FloatType> &bias, int contract_dim, const ActivationFunc &activation)
ConvolutionLayer1D
Functions
-
template<typename U, typename ActivationFunc, typename PaddingFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto conv1d_layer(const Tensor<FLOATTYPE(U), 3> &filter, const ActivationFunc &activation_func, const PaddingFunc &padding_func, int stride, U &&u) -> ConvolutionLayer1D<FLOATTYPE(U), INPUTTYPE(U), DDST(u), ActivationFunc, PaddingFunc>
-
template<typename U, typename ActivationFunc, typename PaddingFunc, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto conv1d_layer(const Tensor<FLOATTYPE(U), 3> &filter, const ActivationFunc &activation_func, const PaddingFunc &padding_func, U &&u) -> ConvolutionLayer1D<FLOATTYPE(U), INPUTTYPE(U), DDST(u), ActivationFunc, PaddingFunc>
-
template<typename _FloatType, typename _InputType, typename Store, typename ActivationFunc, typename PaddingFunc>
class ConvolutionLayer1D -
Public Functions
- typedef LAYEROUTPUTTYPE (typename Store::type) LayerInputTensorType
-
inline ConvolutionLayer1D(Store &&leaf, const Tensor<FloatType, 3> &_filter, const ActivationFunc &activation_func, const PaddingFunc &padding_func, int stride = 1)
-
ConvolutionLayer1D(const ConvolutionLayer1D &r) = delete
-
ConvolutionLayer1D(ConvolutionLayer1D &&r) = default
-
int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, 3> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
int _input_tens_size[LayerInputTensorType::dimension()]
-
ActivationFunc activation_func
-
PaddingFunc padding_func
-
int depth
-
int channels
-
int kernel_size
-
int stride
-
bool init
-
int padded_data_len
-
int batch_size
-
mutable FLOPScounter value_FLOPS
-
mutable FLOPScounter deriv_FLOPS
-
mutable RingBuffer<Tensor<FloatType, 3>> leaf_buf
-
mutable RingBuffer<Tensor<FloatType, 3>> activation_deriv_buf
EmbedPositionsSinusoidalLayer
Functions
-
template<typename _FloatType, typename _InputType, typename Store>
class EmbedPositionsSinusoidalLayer -
Public Functions
-
EmbedPositionsSinusoidalLayer(const EmbedPositionsSinusoidalLayer &r) = delete
-
EmbedPositionsSinusoidalLayer(EmbedPositionsSinusoidalLayer &&r) = default
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, 3> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
EmbedPositionsSinusoidalLayer(const EmbedPositionsSinusoidalLayer &r) = delete
FlattenLayer
Functions
-
template<typename _FloatType, typename _InputType, typename Store>
class FlattenLayer -
Public Functions
- typedef LAYEROUTPUTTYPE (typename Store::type) LayerInputTensorType
-
FlattenLayer(const FlattenLayer &r) = delete
-
FlattenLayer(FlattenLayer &&r) = default
-
int deriv(Vector<FloatType> &cost_deriv, int off, Matrix<FloatType> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
InputLayer
Functions
-
template<typename _FloatType, typename _InputType = Matrix<_FloatType>>
class InputLayer -
Public Functions
-
inline InputLayer()
-
inline InputLayer(InputLayer &&r) = default
-
inline InputLayer(const InputLayer &r) = delete
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, InputType &&above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
inline InputLayer()
LayerCommon
-
struct LeafTag
MatrixTensorContractLayer
Defines
-
LAYER_TYPE
Functions
-
template<typename _FloatType, int TensDim, typename _InputType, typename Store>
class MatrixTensorContractLayer -
Public Functions
-
MatrixTensorContractLayer(const MatrixTensorContractLayer &r) = delete
-
MatrixTensorContractLayer(MatrixTensorContractLayer &&r) = default
-
int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, TensDim> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
MatrixTensorContractLayer(const MatrixTensorContractLayer &r) = delete
MultiHeadCrossAttentionLayer
Functions
-
TEMPL auto multihead_cross_attention_layer(int Nheads, Matrix<FLOATTYPE(ChainKV)> const *const *W_Q, Matrix<FLOATTYPE(ChainKV)> const *const *W_K, Matrix<FLOATTYPE(ChainKV)> const *const *W_V, const Matrix<FLOATTYPE(ChainKV)> &W_O, bool use_mask, ChainKV &&chain_KV, ChainQ &&chain_Q) -> LAYER_TYPE
-
TEMPL auto multihead_cross_attention_layer(int Nheads, Matrix<FLOATTYPE(ChainKV)> const *const *W_Q, Matrix<FLOATTYPE(ChainKV)> const *const *W_K, Matrix<FLOATTYPE(ChainKV)> const *const *W_V, const Matrix<FLOATTYPE(ChainKV)> &W_O, ChainKV &&chain_KV, ChainQ &&chain_Q) -> LAYER_TYPE
-
TEMPL auto multihead_cross_attention_layer(int Nheads, const std::vector<Matrix<FLOATTYPE(ChainKV)>> &W_Q, const std::vector<Matrix<FLOATTYPE(ChainKV)>> &W_K, const std::vector<Matrix<FLOATTYPE(ChainKV)>> &W_V, const Matrix<FLOATTYPE(ChainKV)> &W_O, bool use_mask, ChainKV &&chain_KV, ChainQ &&chain_Q) -> LAYER_TYPE
-
TEMPL auto multihead_cross_attention_layer(int Nheads, const std::vector<Matrix<FLOATTYPE(ChainKV)>> &W_Q, const std::vector<Matrix<FLOATTYPE(ChainKV)>> &W_K, const std::vector<Matrix<FLOATTYPE(ChainKV)>> &W_V, const Matrix<FLOATTYPE(ChainKV)> &W_O, ChainKV &&chain_KV, ChainQ &&chain_Q) -> LAYER_TYPE
-
TEMPL auto multihead_cross_attention_layer(int Nheads, int E, bool use_mask, ChainKV &&chain_KV, ChainQ &&chain_Q) -> LAYER_TYPE
-
TEMPL auto multihead_cross_attention_layer(int Nheads, int E, ChainKV &&chain_KV, ChainQ &&chain_Q)
-
template<typename _FloatType, typename _InputType, typename StoreKV, typename StoreQ>
class MultiHeadCrossAttentionLayer -
Public Functions
-
inline MultiHeadCrossAttentionLayer(StoreKV &&leaf_KV, StoreQ &&leaf_Q, int Nheads, Matrix<FloatType> const *const *W_Q, Matrix<FloatType> const *const *W_K, Matrix<FloatType> const *const *W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
-
inline MultiHeadCrossAttentionLayer(StoreKV &&leaf_KV, StoreQ &&leaf_Q, int Nheads, const std::vector<Matrix<FloatType>> &W_Q, const std::vector<Matrix<FloatType>> &W_K, const std::vector<Matrix<FloatType>> &W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
-
MultiHeadCrossAttentionLayer(const MultiHeadCrossAttentionLayer &r) = delete
-
MultiHeadCrossAttentionLayer(MultiHeadCrossAttentionLayer &&r) = default
-
inline TensorType value(const InputType &x)
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, TensorType &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
inline MultiHeadCrossAttentionLayer(StoreKV &&leaf_KV, StoreQ &&leaf_Q, int Nheads, Matrix<FloatType> const *const *W_Q, Matrix<FloatType> const *const *W_K, Matrix<FloatType> const *const *W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
MultiHeadSelfAttentionLayer
Defines
-
LAYER_TYPE
Functions
-
template<typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto multihead_self_attention_layer(int Nheads, Matrix<FLOATTYPE(U)> const *const *W_Q, Matrix<FLOATTYPE(U)> const *const *W_K, Matrix<FLOATTYPE(U)> const *const *W_V, const Matrix<FLOATTYPE(U)> &W_O, bool use_mask, U &&u) -> LAYER_TYPE
-
template<typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto multihead_self_attention_layer(int Nheads, Matrix<FLOATTYPE(U)> const *const *W_Q, Matrix<FLOATTYPE(U)> const *const *W_K, Matrix<FLOATTYPE(U)> const *const *W_V, const Matrix<FLOATTYPE(U)> &W_O, U &&u) -> LAYER_TYPE
-
template<typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto multihead_self_attention_layer(int Nheads, const std::vector<Matrix<FLOATTYPE(U)>> &W_Q, const std::vector<Matrix<FLOATTYPE(U)>> &W_K, const std::vector<Matrix<FLOATTYPE(U)>> &W_V, const Matrix<FLOATTYPE(U)> &W_O, bool use_mask, U &&u) -> LAYER_TYPE
-
template<typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto multihead_self_attention_layer(int Nheads, const std::vector<Matrix<FLOATTYPE(U)>> &W_Q, const std::vector<Matrix<FLOATTYPE(U)>> &W_K, const std::vector<Matrix<FLOATTYPE(U)>> &W_V, const Matrix<FLOATTYPE(U)> &W_O, U &&u) -> LAYER_TYPE
-
template<typename _FloatType, typename _InputType, typename Store>
class MultiHeadSelfAttentionLayer -
Public Functions
-
MultiHeadSelfAttentionLayer(Store &&leaf, int Nheads, Matrix<FloatType> const *const *W_Q, Matrix<FloatType> const *const *W_K, Matrix<FloatType> const *const *W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
-
MultiHeadSelfAttentionLayer(Store &&leaf, int Nheads, const std::vector<Matrix<FloatType>> &W_Q, const std::vector<Matrix<FloatType>> &W_K, const std::vector<Matrix<FloatType>> &W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
-
MultiHeadSelfAttentionLayer(const MultiHeadSelfAttentionLayer &r) = delete
-
MultiHeadSelfAttentionLayer(MultiHeadSelfAttentionLayer &&r) = default
-
int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, 3> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
void resizeInputBuffer(size_t to)
-
MultiHeadSelfAttentionLayer(Store &&leaf, int Nheads, Matrix<FloatType> const *const *W_Q, Matrix<FloatType> const *const *W_K, Matrix<FloatType> const *const *W_V, const Matrix<FloatType> &W_O, bool use_mask = false)
NormLayer
Defines
-
LAYER_TYPE
Functions
- template<int TensDim, typename U, typename std::enable_if< ISLEAF(U), int >::type = 0> auto norm_layer (int norm_dim, int norm_dim_size, bool use_affine, bool use_bias, const Vector< FLOATTYPE(U)> &affine_init, const Vector< FLOATTYPE(U)> &bias_init, FLOATTYPE(U) epsilon, U &&u) -> LAYER_TYPE
-
template<int TensDim, typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto norm_layer(int norm_dim, int norm_dim_size, bool use_affine, bool use_bias, const Vector<FLOATTYPE(U)> &affine_init, const Vector<FLOATTYPE(U)> &bias_init, U &&u) -> LAYER_TYPE
- template<int TensDim, typename U, typename std::enable_if< ISLEAF(U), int >::type = 0> auto norm_layer (int norm_dim, int norm_dim_size, bool use_affine, bool use_bias, FLOATTYPE(U) epsilon, U &&u) -> LAYER_TYPE
-
template<typename _FloatType, int TensDim, typename _InputType, typename Store>
class NormLayer -
Public Functions
-
inline NormLayer(Store &&leaf, int norm_dim, int norm_dim_size, bool use_affine, bool use_bias, const Vector<FloatType> &affine_init, const Vector<FloatType> &bias_init, FloatType epsilon)
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, TensDim> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
inline NormLayer(Store &&leaf, int norm_dim, int norm_dim_size, bool use_affine, bool use_bias, const Vector<FloatType> &affine_init, const Vector<FloatType> &bias_init, FloatType epsilon)
PairJoinLayer
Functions
-
template<typename _FloatType, typename _InputType, typename Store1, typename Store2>
class PairJoinLayer Public Types
-
typedef _FloatType FloatType
-
typedef _InputType InputType
-
typedef std::pair<LayerInputType1, LayerInputType2> LayerOutputType
Public Functions
- typedef LAYERTYPEOUTPUTTYPE (StoredType1) LayerInputType1
- typedef LAYERTYPEOUTPUTTYPE (StoredType2) LayerInputType2
-
PairJoinLayer(const PairJoinLayer &r) = delete
-
PairJoinLayer(PairJoinLayer &&r) = default
-
inline LayerOutputType value(const InputType &x)
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, LayerOutputType &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
typedef _FloatType FloatType
PairSplitLayer
Functions
-
template<typename _FloatType, typename _InputType, typename Store>
class PairSplitLayerLeader Public Types
-
typedef _FloatType FloatType
-
typedef _InputType InputType
-
typedef LayerInputType::first_type LayerOutputType1
-
typedef LayerInputType::second_type LayerOutputType2
Public Functions
- typedef LAYERTYPEOUTPUTTYPE (StoredType) LayerInputType
-
inline void cinc(int &i)
-
inline LayerOutputType1 first(const InputType &x)
-
inline LayerOutputType2 second(const InputType &x)
-
inline int deriv_complete(Vector<FloatType> &cost_deriv, int off, InputType *input_above_deriv_return)
-
inline int deriv_first(Vector<FloatType> &cost_deriv, int off, LayerOutputType1 &&_above_deriv, InputType *input_above_deriv_return)
-
inline int deriv_second(Vector<FloatType> &cost_deriv, int off, LayerOutputType2 &&_above_deriv, InputType *input_above_deriv_return)
-
typedef _FloatType FloatType
-
template<typename _FloatType, typename _InputType, typename Store>
class PairSplitLayer1 Public Types
-
typedef LayerInputType::first_type LayerOutputType
-
typedef _FloatType FloatType
-
typedef _InputType InputType
Public Functions
- typedef LAYERTYPEOUTPUTTYPE (StoredType) LayerInputType
-
inline PairSplitLayer1(PairSplitLayerLeader<FloatType, InputType, Store> *leader)
-
PairSplitLayer1(const PairSplitLayer1 &r) = delete
-
inline PairSplitLayer1(PairSplitLayer1 &&r)
-
inline ~PairSplitLayer1()
-
inline LayerOutputType value(const InputType &x)
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, LayerOutputType &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
PairSplitLayerLeader<FloatType, InputType, Store> *leader
-
typedef LayerInputType::first_type LayerOutputType
-
template<typename _FloatType, typename _InputType, typename Store>
class PairSplitLayer2 Public Types
-
typedef LayerInputType::second_type LayerOutputType
-
typedef _FloatType FloatType
-
typedef _InputType InputType
Public Functions
- typedef LAYERTYPEOUTPUTTYPE (StoredType) LayerInputType
-
inline PairSplitLayer2(PairSplitLayerLeader<FloatType, InputType, Store> *leader)
-
PairSplitLayer2(const PairSplitLayer2 &r) = delete
-
PairSplitLayer2(PairSplitLayer2 &&r) = default
-
inline LayerOutputType value(const InputType &x)
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, LayerOutputType &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
Private Members
-
PairSplitLayerLeader<FloatType, InputType, Store> *leader
-
typedef LayerInputType::second_type LayerOutputType
ReplicateLayer
Functions
-
template<typename _FloatType, typename _InputType, typename Store>
class ReplicateLayerLeader
-
template<typename _FloatType, typename _InputType, typename Store>
class ReplicateLayer -
Public Functions
- typedef LAYERTYPEOUTPUTTYPE (StoredType) LayerInputOutputType
-
inline ReplicateLayer(ReplicateLayerLeader<FloatType, InputType, Store> *leader, int instance, int N)
-
ReplicateLayer(const ReplicateLayer &r) = delete
-
inline ReplicateLayer(ReplicateLayer &&r)
-
inline ~ReplicateLayer()
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, LayerInputOutputType &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
ScaledDotProductSelfAttentionLayer
Defines
-
LAYER_TYPE
Functions
-
template<typename _FloatType, typename _InputType, typename Store>
class ScaledDotProductSelfAttentionLayer -
Public Functions
-
inline ScaledDotProductSelfAttentionLayer(Store &&leaf, const Matrix<FloatType> &W_Q, const Matrix<FloatType> &W_K, const Matrix<FloatType> &W_V, bool use_mask = false)
-
ScaledDotProductSelfAttentionLayer(const ScaledDotProductSelfAttentionLayer &r) = delete
-
ScaledDotProductSelfAttentionLayer(ScaledDotProductSelfAttentionLayer &&r) = default
-
int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, 3> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
inline ScaledDotProductSelfAttentionLayer(Store &&leaf, const Matrix<FloatType> &W_Q, const Matrix<FloatType> &W_K, const Matrix<FloatType> &W_V, bool use_mask = false)
SkipConnection
Defines
-
LAYER_TYPE
Functions
-
template<typename _FloatType, typename _InputType, typename ChainInternal, typename ChainBelow>
class SkipConnection Public Types
-
typedef _FloatType FloatType
-
typedef _InputType InputType
-
typedef ChainBelow::type ChainBelowInternalType
Public Functions
- typedef LAYERTYPEOUTPUTTYPE (ChainBelowInternalType) LayerInputOutputType
-
inline SkipConnection(ChainInternal &&leaf_internal, ChainBelow &&leaf_below)
-
SkipConnection(const SkipConnection &r) = delete
-
SkipConnection(SkipConnection &&r) = default
-
int deriv(Vector<FloatType> &cost_deriv, int off, LayerInputOutputType &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
typedef _FloatType FloatType
SoftMaxLayer
Defines
-
LAYER_TYPE
Functions
- template<int TensDim, typename U, typename std::enable_if< ISLEAF(U), int >::type = 0> auto softmax_layer (int softmax_dim, FLOATTYPE(U) beta, U &&u) -> LAYER_TYPE
-
template<typename _FloatType, int TensDim, typename _InputType, typename Store>
class SoftMaxLayer -
Public Functions
-
inline SoftMaxLayer(SoftMaxLayer &&r) = default
-
inline SoftMaxLayer(const SoftMaxLayer &r) = delete
-
int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, TensDim> &&above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
-
inline SoftMaxLayer(SoftMaxLayer &&r) = default
SumJoinLayer
Functions
-
template<typename _FloatType, typename _InputType, typename Store1, typename Store2>
class SumJoinLayer Public Types
-
typedef _FloatType FloatType
-
typedef _InputType InputType
-
typedef LayerInputType1 LayerInputOutputType
Public Functions
-
SumJoinLayer(const SumJoinLayer &r) = delete
-
SumJoinLayer(SumJoinLayer &&r) = default
-
inline LayerInputOutputType value(const InputType &x)
-
inline int deriv(Vector<FloatType> &cost_deriv, int off, LayerInputOutputType &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)
Private Functions
- typedef LAYERTYPEOUTPUTTYPE (StoredType1) LayerInputType1
- typedef LAYERTYPEOUTPUTTYPE (StoredType2) LayerInputType2
-
typedef _FloatType FloatType
TransformerEncoderDecoderBlock
Functions
-
template<typename Below, typename ActivationFunc>
auto transformer_decoder_block(int E, int nheads, int d_act, const ActivationFunc &activation, Below &&below)
-
template<typename Below, typename ActivationFunc>
auto transformer_encoder_block(int E, int nheads, int d_act, const ActivationFunc &activation, Below &&below)
-
template<typename EncoderInput, typename DecoderInput, typename ActivationFunc>
auto transformer_cross_decoder_block(int E, int nheads, int d_act, const ActivationFunc &activation, EncoderInput &&encoder_in, DecoderInput &&decoder_in)
UnflattenLayer
Functions
-
template<int OutDimension, typename U, typename std::enable_if<ISLEAF(U), int>::type = 0>
auto unflatten_layer(int const *output_tens_dim, U &&u) -> UnflattenLayer<FLOATTYPE(U), OutDimension, INPUTTYPE(U), DDST(u)>
-
template<typename _FloatType, int OutDimension, typename _InputType, typename Store>
class UnflattenLayer -
Public Functions
- typedef LAYEROUTPUTTYPE (typename Store::type) LayerInputTensorType
-
UnflattenLayer(const UnflattenLayer &r) = delete
-
UnflattenLayer(UnflattenLayer &&r) = default
-
Tensor<FloatType, OutDimension> value(const InputType &x)
-
int deriv(Vector<FloatType> &cost_deriv, int off, Tensor<FloatType, OutDimension> &&_above_deriv, InputType *input_above_deriv_return = nullptr) const
-
inline int nparams() const
-
inline size_t FLOPS(int value_or_deriv) const
-
inline void resizeInputBuffer(size_t to)