GpuDiff¶
Import: import system.gpu;
This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation. Shader-only declarations can be used only inside shader entry points and helpers reached from them; using them elsewhere is a compile error.
GpuDiff¶
Automatic differentiation of @differentiable helpers inside shaders. Pass the helper itself as f, followed by one GpuDiffPair per parameter; the name's number is the helper's parameter count (forward and backward for one parameter). forward returns the result and its derivative along the pairs' derivatives. backward takes the pairs by ref, plus the derivative of whatever the result feeds into (1 to differentiate the result itself), and stores each parameter's gradient in its pair's derivative. Parameters marked @no_diff take plain values instead of pairs.
forward¶
Forward-mode derivative of a one-parameter helper.
forward2¶
Forward-mode derivative of a two-parameter helper.
public static extern fun forward2<A, B, R>(
f: fun(A, B): R,
a: GpuDiffPair<A>,
b: GpuDiffPair<B>
): GpuDiffPair<R>
forward3¶
Forward-mode derivative of a three-parameter helper.
public static extern fun forward3<A, B, C, R>(
f: fun(A, B, C): R,
a: GpuDiffPair<A>,
b: GpuDiffPair<B>,
c: GpuDiffPair<C>
): GpuDiffPair<R>
backward¶
Reverse-mode gradient of a one-parameter helper.
backward2¶
Reverse-mode gradient of a two-parameter helper.
public static extern fun backward2<A, B, R>(
f: fun(A, B): R,
ref a: GpuDiffPair<A>,
ref b: GpuDiffPair<B>,
d_output: R
): void
backward3¶
Reverse-mode gradient of a three-parameter helper.