예제 #1
0
        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);
                                        }
            }
        }
예제 #2
0
        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));
                        }
            }
        }