Esempio n. 1
0
        /// <summary>
        /// Poolings the backward.
        /// </summary>
        /// <param name="desc">The desc.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="dx">The dx.</param>
        /// <param name="dy">The dy.</param>
        public static void PoolingBackward(DNNPoolingDesc desc, NDArray x, NDArray y, NDArray dx, NDArray dy)
        {
            using (var dnn = CudaHelpers.TSContextForTensor(x).DNNForTensor(x))
            {
                var poolingDesc = new PoolingDescriptor();
                poolingDesc.SetPoolingNdDescriptor((cudnnPoolingMode)desc.Mode, cudnnNanPropagation.PropagateNan, desc.WindowDims.Length,
                                                   desc.WindowDims, desc.Padding, desc.Strides);

                using (var xPtr = GetDeviceVar(x))
                    using (var yPtr = GetDeviceVar(y))
                        using (var dxPtr = GetDeviceVar(dx))
                            using (var dyPtr = GetDeviceVar(dy))
                                using (var xDesc = GetDescriptor(x))
                                    using (var yDesc = GetDescriptor(y))
                                        using (var dxDesc = GetDescriptor(dx))
                                            using (var dyDesc = GetDescriptor(dy))
                                            {
                                                // Note: ManagedCUDA argument names may be slightly misleading (src refers to 'y' here, and dest to 'x')
                                                dnn.Value.PoolingBackward(poolingDesc, 1,
                                                                          yDesc, yPtr,
                                                                          dyDesc, dyPtr,
                                                                          xDesc, xPtr,
                                                                          0,
                                                                          dxDesc, dxPtr);
                                            }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Poolings the forward.
        /// </summary>
        /// <param name="desc">The desc.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        public static void PoolingForward(DNNPoolingDesc desc, NDArray x, NDArray y)
        {
            using (var dnn = CudaHelpers.TSContextForTensor(x).DNNForTensor(x))
            {
                var poolingDesc = new PoolingDescriptor();
                poolingDesc.SetPoolingNdDescriptor((cudnnPoolingMode)desc.Mode, cudnnNanPropagation.PropagateNan, desc.WindowDims.Length,
                                                   desc.WindowDims, desc.Padding, desc.Strides);

                using (var xPtr = GetDeviceVar(x))
                    using (var yPtr = GetDeviceVar(y))
                        using (var xDesc = GetDescriptor(x))
                            using (var yDesc = GetDescriptor(y))
                            {
                                dnn.Value.PoolingForward(poolingDesc, 1,
                                                         xDesc, xPtr,
                                                         0,
                                                         yDesc, yPtr);
                            }
            }
        }