l2NormGPU function
Computes the L2 norm (Euclidean length) of a vector. Squares each element of the vector, sums them together, and takes the square root of the result.
The operations are appended to tape for execution.
The operations are appended to tape for execution.
Implementation
GPUTensor<Scalar> l2NormGPU(GPUTensor<Vector> v, CommandBuffer tape) {
GPUTensor<Vector> squared = powGPU<Vector>(v, 2.0, tape);
GPUTensor<Scalar> sumOfSquares = sumGPU(squared, tape);
GPUTensor<Scalar> out = sqrtGPU<Scalar>(sumOfSquares, tape);
out.subMap["squared"] = squared;
out.subMap["sumOfSquares"] = sumOfSquares;
return out;
}