grain.autograd

A module for a variable used as a node in autograd computation graph

TODO: - support shape ops

Members

Aliases

DeviceStorage
alias DeviceStorage(T) = CuArray!T
Undocumented in source.
ElementType
alias ElementType(V : Variable!(Elem, dim, Storage), Elem, size_t dim, alias Storage) = Elem

an alias of element type (e.g., float, double and int) of variable

HostStorage
alias HostStorage(T) = T[]

CPU storage (i.e., GC dynamic array)

isDevice
alias isDevice = isDeviceMemory
Undocumented in source.

Functions

gradSlice
auto gradSlice(V v)
iterVariables
void iterVariables(C* chain, string prefix)

kind of std.algorithm.each for iterating variables inside a chain

length
auto length(V v)

total number of elements in variable

refIterVariables
void refIterVariables(C chain, string prefix)

kind of std.algorithm.each for iterating variables inside a chain

to
auto to(T[] src)

CUDA -> CPU memory conversion

to
auto to(Src src)

CPU -> CUDA memory conversion

to
Variable!(T, dim, Dst) to(Variable!(T, dim, Src) src)

copy variable into the other device (e.g., CPU -> CUDA or CUDA -> CPU)

uninit
auto uninit(Variable!(T, dim, HostStorage) v)

create new variable with uninitialized array and the same shape/strides to v on CPU

uninit
auto uninit(Variable!(T, dim, DeviceStorage) v)

create new variable with uninitialized array and the same shape/strides to v on CUDA

uninitVariable
auto uninitVariable(uint[dim] shape, bool requiresGrad)

create new variable with uninitialized array of shape on CPU/CUDA

variable
auto variable(Sl sl, bool requiresGrad)

a helper function to create variable object from slice

variable
auto variable(T x)
auto variable(A a, bool requiresGrad)

a helper function to create variable object from CPU/CUDA array

zero_
auto zero_(T[] s)

fill CPU array with zero

zeros
auto zeros(size_t n)

create new CPU array filled with zero

Structs

BackProp
struct BackProp

stores information for backpropagation

UntypedVariable
struct UntypedVariable

type-erased variable used in BackProp object

Variable
struct Variable(T, size_t dim, alias Storage = HostStorage, SliceKind kind = Contiguous)

A variable has autograd ability with mir.ndslice.Slice like data

Variables

DimensionCount
enum size_t DimensionCount(V : Variable!(Elem, dim, Storage), Elem, size_t dim, alias Storage);

a function to get the number of dimensions of variable

isHost
enum bool isHost(V : Variable!(Elem, dim, Storage), Elem, size_t dim, alias Storage);

a trait to identify variable stored in CPU memory

isVariable
enum bool isVariable(T);

a trait to identify variable object

Meta