43 virtual
void Free(
float* ptr) noexcept = 0;
45 virtual
void Zero(
float* ptr,
size_t numFloats) noexcept = 0;
48 virtual
void Copy(
float* dst, const
float* src,
size_t numFloats) noexcept = 0;
51 virtual
void CopyFromHost(
float* deviceDst, const
float* hostSrc,
size_t numFloats) noexcept = 0;
54 virtual
void CopyToHost(
float* hostDst, const
float* deviceSrc,
size_t numFloats) noexcept = 0;
62 uint32_t seed) noexcept = 0;
71 uint32_t seed) noexcept = 0;
94 virtual
void MatMul(
bool transA,
bool transB,
int M,
int N,
int K,
float alpha, const
float* A,
95 int lda, const
float* B,
int ldb,
float beta,
float* C,
int ldc) noexcept = 0;
104 virtual
void SumRows(
float* dst, const
float* src,
size_t batchSize,
size_t width) noexcept = 0;
109 virtual
void Scale(
float* buf,
size_t n,
float alpha) noexcept = 0;
111 virtual
void AxpyInto(
float* y, const
float* x,
size_t n,
float alpha) noexcept = 0;
116 size_t width) noexcept = 0;
124 size_t n) noexcept = 0;
132 bool activated) noexcept = 0;
136 size_t n) noexcept = 0;
149 const
float* deriv, const
float* e,
size_t n,
float ir,
150 float beta) noexcept = 0;
155 virtual
void FusedStateUpdate(
float* z, const
float* feedback, const
float* deriv, const
float* e,
156 size_t n,
float ir) noexcept = 0;
161 size_t n) noexcept = 0;
164 virtual
void ComputeError(
float* e, const
float* z, const
float* mu,
size_t n) noexcept = 0;
185 size_t batchSize,
size_t nextSize,
186 float* rowEnergies) noexcept = 0;
192 size_t batchSize,
size_t nextSize) noexcept = 0;
213 const
float* bias,
float* mu,
int batchSize,
int size,
214 int nextSize) noexcept = 0;
226 virtual
void Im2Col(const
float* input,
int channels,
int height,
int width,
int kernelH,
227 int kernelW,
int strideH,
int strideW,
int padH,
int padW,
228 float* columns) noexcept = 0;
237 virtual
void Col2Im(const
float* columns,
int channels,
int height,
int width,
int kernelH,
238 int kernelW,
int strideH,
int strideW,
int padH,
int padW,
239 float* outputImage) noexcept = 0;
254 size_t cols) noexcept = 0;
274 virtual
void AdamStep(
float* param, const
float* grad,
float* m,
float* v,
size_t n, const
int* t,
275 const
float* lr,
float beta1 = 0.9f,
float beta2 = 0.999f,
276 float eps = 1e-8f) noexcept = 0;
279 virtual
void AdamWStep(
float* param, const
float* grad,
float* m,
float* v,
size_t n,
280 const
int* t, const
float* lr,
float weightDecay,
float beta1 = 0.9f,
281 float beta2 = 0.999f,
float eps = 1e-8f) noexcept = 0;
287 virtual
void MultiplyInto(
float* dst, const
float* a, const
float* b,
size_t n) noexcept = 0;
289 virtual
void Fill(
float* buf,
size_t n,
float value) noexcept = 0;
298 size_t spatialSize) noexcept = 0;
Defines the activation functions of a predictive coding model.
Device-agnostic compute backend interface: every numerical primitive a layer/network needs,...
Definition IComputeBackend.h:14
virtual void RepackForBatchedGemm(float *dst, const float *src, size_t batchSize, size_t rows, size_t cols) noexcept=0
Repacks a [batchSize, rows, cols] tensor (batch-major) into [rows, batchSize, cols] (row-major,...
virtual void Copy(float *dst, const float *src, size_t numFloats) noexcept=0
Copies numFloats floats from src to dst, both on this backend's own device.
virtual void CopyFromHost(float *deviceDst, const float *hostSrc, size_t numFloats) noexcept=0
Copies numFloats floats from a host buffer into a device buffer (a plain memcpy on CPUBackend).
virtual void SumRows(float *dst, const float *src, size_t batchSize, size_t width) noexcept=0
dst[j] = sum over b in [0,batchSize) of src[b*width + j], for all j in [0,width). Replaces a batchSiz...
virtual float ComputeSoftmaxCrossEntropyErrorAndEnergy(float *e, const float *z, const float *mu, size_t batchSize, size_t nextSize, float *rowEnergies) noexcept=0
Softmax cross-entropy variant of ComputeErrorAndEnergy, for the terminal layer only....
virtual void AdamStep(float *param, const float *grad, float *m, float *v, size_t n, const int *t, const float *lr, float beta1=0.9f, float beta2=0.999f, float eps=1e-8f) noexcept=0
Adam update for n parameters in place.
virtual void AdamWStep(float *param, const float *grad, float *m, float *v, size_t n, const int *t, const float *lr, float weightDecay, float beta1=0.9f, float beta2=0.999f, float eps=1e-8f) noexcept=0
Same as AdamStep(), plus decoupled weight decay (AdamW): param -= lr * weightDecay * param,...
virtual void PrepareForBatchSize(size_t batchSize) noexcept=0
Must be called once, before Compile()'s first BeginGraphCapture(), for any backend that needs to prep...
virtual void Activation(ActivationType type, float *buf, size_t n) noexcept=0
Applies type to buf in place.
virtual float ComputeErrorAndEnergy(float *e, const float *z, const float *mu, size_t n) noexcept=0
Computes e = z - mu, then returns 0.5 * sum(e^2) – the Gaussian error/energy used by every layer exce...
virtual void RandomizeNormal(float *buf, size_t n, float mean, float stddev, uint32_t seed) noexcept=0
Fills n floats with samples from a normal distribution.
virtual ~IComputeBackend()=default
virtual void ReplayGraph() noexcept=0
Launches a graph previously captured and instantiated by BeginGraphCapture()/EndGraphCapture()....
virtual void ActivationDerivative(ActivationType type, float *buf, size_t n, bool activated) noexcept=0
Applies type's derivative to buf in place.
virtual void AddBiasPerChannel(float *buf, const float *bias, size_t channels, size_t spatialSize) noexcept=0
Convolutional bias-add: buf[c*spatialSize + s] += bias[c] for all c in [0,channels),...
virtual void CopyToHost(float *hostDst, const float *deviceSrc, size_t numFloats) noexcept=0
Copies numFloats floats from a device buffer into a host buffer (a plain memcpy on CPUBackend).
virtual void MultiplyInto(float *dst, const float *a, const float *b, size_t n) noexcept=0
dst[i] = a[i] * b[i] for all i in [0, n) – elementwise product.
virtual void ActivationInto(ActivationType type, float *dst, const float *src, size_t n) noexcept=0
Two-buffer variant of Activation(): reads src, writes into dst.
virtual bool TryFusedForwardPass(ActivationType actType, const float *zF, const float *W, const float *bias, float *mu, int batchSize, int size, int nextSize) noexcept=0
Attempts a fused forward pass (GEMM + bias + activation in one kernel, via CUTLASS on GPU) for RELU o...
virtual void FusedStateUpdateMomentum(float *z, float *v, const float *feedback, const float *deriv, const float *e, size_t n, float ir, float beta) noexcept=0
Same as FusedStateUpdate, but with momentum: the update direction (feedback*deriv - e) is EMA-smoothe...
virtual void IncrementCounter(int *counter) noexcept=0
Atomically increments *counter by 1. Device-resident so it can be read/updated by the same kernel/gra...
virtual void ComputeError(float *e, const float *z, const float *mu, size_t n) noexcept=0
Same as ComputeErrorAndEnergy(), without computing (or returning) the energy – for callers that only ...
virtual void AxpyInto(float *y, const float *x, size_t n, float alpha) noexcept=0
y[i] += alpha * x[i] for all i in [0, n) – the standard AXPY.
virtual void FusedStateUpdate(float *z, const float *feedback, const float *deriv, const float *e, size_t n, float ir) noexcept=0
One settling step's state update, fused into a single call: z += ir * ((feedback * deriv) - e) Non-mo...
virtual void BeginGraphCapture() noexcept=0
Starts recording subsequent backend calls into a replayable graph, instead of executing them immediat...
virtual void ComputeSoftmaxCrossEntropyError(float *e, const float *z, const float *mu, size_t batchSize, size_t nextSize) noexcept=0
Same as ComputeSoftmaxCrossEntropyErrorAndEnergy(), without computing (or requiring rowEnergies for) ...
virtual void Scale(float *buf, size_t n, float alpha) noexcept=0
buf[i] *= alpha for all i in [0, n).
virtual void Zero(float *ptr, size_t numFloats) noexcept=0
Zero-fills numFloats floats starting at ptr.
virtual void Fill(float *buf, size_t n, float value) noexcept=0
buf[i] = value for all i in [0, n).
virtual void Im2Col(const float *input, int channels, int height, int width, int kernelH, int kernelW, int strideH, int strideW, int padH, int padW, float *columns) noexcept=0
Rearranges a single (channels, height, width) input image into a (channels*kH*kW, outH*outW) column m...
virtual DeviceType GetDeviceType() const noexcept=0
Which device this backend instance runs on.
virtual void Free(float *ptr) noexcept=0
Frees a buffer previously returned by Allocate(). No-op on nullptr.
virtual void RandomizeUniform(float *buf, size_t n, float min, float max, uint32_t seed) noexcept=0
Fills n floats with samples from a uniform distribution over [min, max).
virtual void MatMul(bool transA, bool transB, int M, int N, int K, float alpha, const float *A, int lda, const float *B, int ldb, float beta, float *C, int ldc) noexcept=0
C = alpha * op(A) * op(B) + beta * C, the standard BLAS SGEMM convention (op(X) = X^T if the matching...
virtual void AddBiasBroadcast(float *buf, const float *bias, size_t batchSize, size_t width) noexcept=0
buf[row*width + col] += bias[col] for every row in [0,batchSize) and col in [0,width) – broadcasts a ...
virtual void Col2Im(const float *columns, int channels, int height, int width, int kernelH, int kernelW, int strideH, int strideW, int padH, int padW, float *outputImage) noexcept=0
The adjoint of Im2Col(): scatters a (channels*kH*kW, outH*outW) column-gradient buffer back into a (c...
virtual void ActivationDerivativeInto(ActivationType type, float *dst, const float *src, size_t n) noexcept=0
Two-buffer variant of ActivationDerivative(): reads src (the pre-activation value),...
virtual bool EndGraphCapture() noexcept=0
Ends capture and instantiates the captured graph.
virtual float * Allocate(size_t numFloats)=0
Allocates numFloats floats on this backend's device.
This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing...
Definition Backend.cpp:10
ActivationType
Identifies an activation function or its derivative, for dispatch tables and layer/backend APIs that ...
Definition ActivationType.h:25
DeviceType
Which physical device a Tensor/IComputeBackend pair runs on.
Definition DeviceType.h:8