transposeGPU function
GPUTensor<Matrix>
transposeGPU(
- GPUTensor<
Matrix> a, - CommandBuffer tape, {
- GPUTensor<
Matrix> ? outTensor,
Appends a command for switching rows and columns to tape.
Implementation
GPUTensor<Matrix> transposeGPU(GPUTensor<Matrix> a, CommandBuffer tape,
{GPUTensor<Matrix>? outTensor}) {
int M = a.shape[0];
int N = a.shape[1];
GPUTensor<Matrix> out = outTensor ?? GPUTensor<Matrix>.empty(<int>[N, M]);
GPUTensor<Matrix> tmpGrad = GPUTensor<Matrix>.empty(<int>[M, N]);
out.subMap["tmpGrad"] = tmpGrad;
tape.putInt(OP_TRANSPOSE);
tape.putString(a.id);
tape.putString(out.id);
out.creator = GPUNode(
[a],
(CommandBuffer bTape) {
bTape.putInt(OP_TRANSPOSE);
bTape.putString(out.gradId);
bTape.putString(tmpGrad.id);
bTape.putInt(OP_ADD_INTO);
bTape.putString(tmpGrad.id);
bTape.putString(a.gradId);
},
opName: 'transposeGPU',
extraParams: {'tmpGrad': tmpGrad},
cost: 0,
);
return out;
}