public static void ConvolutionBackwardData(DNNConvolutionBwdDataAlgo algo, Cpu.ConvolutionDesc2d cd, CudaStorage workspace, Tensor w, Tensor dy, Tensor dx) { using (var dnn = CudaHelpers.TSContextForTensor(w).DNNForTensor(w)) { var convDesc = GetConvDescriptor(cd, w.ElementType); using (var workspacePtr = new CudaDeviceVariable <byte>(workspace.DevicePtrAtElement(0), false, workspace.ByteLength)) using (var wPtr = GetDeviceVar(w)) using (var dxPtr = GetDeviceVar(dx)) using (var dyPtr = GetDeviceVar(dy)) using (var wDesc = GetFilterDescriptor(w)) using (var dxDesc = GetDescriptor(dx)) using (var dyDesc = GetDescriptor(dy)) { dnn.Value.ConvolutionBackwardData(1, wDesc, wPtr, dyDesc, dyPtr, convDesc, 0, (cudnnConvolutionBwdDataAlgo)algo, workspacePtr, dxDesc, dxPtr); } } }
public static void ConvForward(DNNConvolutionFwdAlgo algo, Cpu.ConvolutionDesc2d cd, CudaStorage workspace, Tensor x, Tensor w, Tensor y) { using (var dnn = CudaHelpers.TSContextForTensor(x).DNNForTensor(x)) { var convDesc = GetConvDescriptor(cd, x.ElementType); using (var workspacePtr = new CudaDeviceVariable <byte>(workspace.DevicePtrAtElement(0), false, workspace.ByteLength)) using (var xPtr = GetDeviceVar(x)) using (var wPtr = GetDeviceVar(w)) using (var yPtr = GetDeviceVar(y)) using (var xDesc = GetDescriptor(x)) using (var wDesc = GetFilterDescriptor(w)) using (var yDesc = GetDescriptor(y)) { dnn.Value.ConvolutionForward(1, xDesc, xPtr, wDesc, wPtr, convDesc, (cudnnConvolutionFwdAlgo)algo, workspacePtr, 0, yDesc, yPtr); } } }
private static ConvolutionDescriptor GetConvDescriptor(Cpu.ConvolutionDesc2d cd, DType elementType) { var convDesc = new ConvolutionDescriptor(); convDesc.SetConvolution2dDescriptor(cd.padH, cd.padW, cd.dH, cd.dW, 1, 1, cudnnConvolutionMode.CrossCorrelation, GetDataType(elementType)); return(convDesc); }
public static void ConvolutionBackwardBias(Cpu.ConvolutionDesc2d cd, Tensor dy, Tensor db) { using (var dnn = CudaHelpers.TSContextForTensor(dy).DNNForTensor(dy)) { using (var dyPtr = GetDeviceVar(dy)) using (var dbPtr = GetDeviceVar(db)) using (var dyDesc = GetDescriptor(dy)) using (var dbDesc = GetDescriptor(db)) { dnn.Value.ConvolutionBackwardBias(1, dyDesc, dyPtr, 0, dbDesc, dbPtr); } } }
public static long GetConvolutionBackwardDataWorkspaceSize(IAllocator allocator, DNNConvolutionBwdDataAlgo algo, Cpu.ConvolutionDesc2d cd, TensorShape w, TensorShape dy, TensorShape dx) { if (!(allocator is CudaAllocator)) { throw new InvalidOperationException("allocator must be a CUDA allocator"); } var cudaAllocator = (CudaAllocator)allocator; using (var dnn = cudaAllocator.Context.DNNForDevice(cudaAllocator.DeviceId)) { var convDesc = GetConvDescriptor(cd, w.ElementType); using (var wDesc = GetFilterDescriptor(w)) using (var dyDesc = GetDescriptor(dy)) using (var dxDesc = GetDescriptor(dx)) { return(dnn.Value.GetConvolutionBackwardDataWorkspaceSize( wDesc, dyDesc, convDesc, dxDesc, (cudnnConvolutionBwdDataAlgo)algo)); } } }
/// <summary> /// Convolutions the backward filter. /// </summary> /// <param name="algo">The algo.</param> /// <param name="cd">The cd.</param> /// <param name="workspace">The workspace.</param> /// <param name="x">The x.</param> /// <param name="dy">The dy.</param> /// <param name="dw">The dw.</param> public static void ConvolutionBackwardFilter(DNNConvolutionBwdFilterAlgo algo, Cpu.ConvolutionDesc2d cd, CudaStorage workspace, NDArray x, NDArray dy, NDArray dw) { using (var dnn = CudaHelpers.TSContextForTensor(x).DNNForTensor(x)) { var convDesc = GetConvDescriptor(cd, x.ElementType); using (var workspacePtr = new CudaDeviceVariable <byte>(workspace.DevicePtrAtElement(0), false, workspace.ByteLength)) using (var xPtr = GetDeviceVar(x)) using (var dyPtr = GetDeviceVar(dy)) using (var dwPtr = GetDeviceVar(dw)) using (var xDesc = GetDescriptor(x)) using (var dyDesc = GetDescriptor(dy)) using (var dwDesc = GetFilterDescriptor(dw)) { dnn.Value.ConvolutionBackwardFilter(1, xDesc, xPtr, dyDesc, dyPtr, convDesc, (cudnnConvolutionBwdFilterAlgo)algo, workspacePtr, 0, dwDesc, dwPtr); } } }