예제 #1
0
        public void Backward(CudnnActivationMode mode, CudnnTensorDescriptor srcTensor, double[] srcData, CudnnTensorDescriptor srcDiffTensor, double[] srcDiffData,
                             CudnnTensorDescriptor destTensor, double[] destData, CudnnTensorDescriptor destDiffTensor, double[] destDiffData)
        {
            Contract.Requires(srcTensor != null);
            Contract.Requires(srcData != null);
            Contract.Requires(destTensor != null);
            Contract.Requires(destData != null);
            Contract.Requires(srcDiffTensor != null);
            Contract.Requires(srcDiffData != null);
            Contract.Requires(destDiffTensor != null);
            Contract.Requires(destDiffData != null);

            ThrowIfNotInitialized();
            CheckIfCompatible(CudnnType.Double, srcTensor, srcDiffTensor, destTensor, destDiffTensor);

            using (var srcDataGpu = new CudaDeviceVariable <double>(srcData.Length))
                using (var srcDiffDataGpu = new CudaDeviceVariable <double>(srcDiffData.Length))
                    using (var destDataGpu = new CudaDeviceVariable <double>(destData.Length))
                        using (var destDiffDataGpu = new CudaDeviceVariable <double>(destDiffData.Length))
                        {
                            srcDataGpu.CopyToDevice(srcData);
                            srcDiffDataGpu.CopyToDevice(srcDiffData);
                            destDataGpu.CopyToDevice(destData);

                            Invoke(() => CudnnNativeMethods.cudnnActivationBackward(handle, mode,
                                                                                    srcTensor.Handle, srcDataGpu.DevicePointer, srcDiffTensor.Handle, srcDiffDataGpu.DevicePointer,
                                                                                    destTensor.Handle, destDataGpu.DevicePointer, destDiffTensor.Handle, destDiffDataGpu.DevicePointer));
                            destDiffDataGpu.CopyToHost(destDiffData);
                        }
        }
예제 #2
0
        public void Backward(CudnnActivationMode mode, CudnnTensorDescriptor srcTensor, CudaDeviceVariable <double> srcData, CudnnTensorDescriptor srcDiffTensor, CudaDeviceVariable <double> srcDiffData,
                             CudnnTensorDescriptor destTensor, CudaDeviceVariable <double> destData, CudnnTensorDescriptor destDiffTensor, CudaDeviceVariable <double> destDiffData)
        {
            Contract.Requires(srcTensor != null);
            Contract.Requires(srcData != null);
            Contract.Requires(destTensor != null);
            Contract.Requires(destData != null);
            Contract.Requires(srcDiffTensor != null);
            Contract.Requires(srcDiffData != null);
            Contract.Requires(destDiffTensor != null);
            Contract.Requires(destDiffData != null);

            ThrowIfNotInitialized();
            CheckIfCompatible(CudnnType.Double, srcTensor, srcDiffTensor, destTensor, destDiffTensor);

            Invoke(() => CudnnNativeMethods.cudnnActivationBackward(handle, mode,
                                                                    srcTensor.Handle, srcData.DevicePointer, srcDiffTensor.Handle, srcDiffData.DevicePointer,
                                                                    destTensor.Handle, destData.DevicePointer, destDiffTensor.Handle, destDiffData.DevicePointer));
        }