Backends/SiaNet.Backend.TensorSharp/Cuda/DeviceCode/SpatialMaxPoolKernels.cs
/// <summary>
/// Spatials the maximum pooling forward.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="output">The output.</param>
/// <param name="indices">The indices.</param>
/// <param name="cd">The cd.</param>
/// <param name="ceilMode">if set to <c>true</c> [ceil mode].</param>
Spatials the maximum pooling forward.
Spatials the maximum pooling forward .
public void SpatialMaxPoolingForward(NDArray input, NDArray output, NDArray indices, ConvolutionDesc2d cd, bool ceilMode)
        {
            var context = CudaHelpers.TSContextForTensor(input);
            var cudaContext = context.CudaContextForTensor(input);
            var iwidth = input.Shape[3];
            var iheight = input.Shape[2];
            var nInputPlane = input.Shape[1];
            var batchSize = input.Shape[0];
            long owidth;
            long oheight;
            if (ceilMode)
            {
                oheight = (long)(Math.Ceiling((float)(iheight - cd.kH + 2 * cd.padH) / cd.dH)) + 1;
                owidth = (long)(Math.Ceiling((float)(iwidth - cd.kW + 2 * cd.padW) / cd.dW)) + 1;
            }
            else
            {
                oheight = (long)(Math.Floor((float)(iheight - cd.kH + 2 * cd.padH) / cd.dH)) + 1;
                owidth = (long)(Math.Floor((float)(iwidth - cd.kW + 2 * cd.padW) / cd.dW)) + 1;
            }
            if (cd.padW != 0 || cd.padH != 0)
            {
                if ((oheight - 1) * cd.dH >= iheight + cd.padH)
                    --oheight;
                if ((owidth - 1) * cd.dW >= iwidth + cd.padW)
                    --owidth;
            }
            using (var inputContig = Ops.AsContiguous(input))
            {
                var inputPtr = CudaHelpers.GetBufferStart(inputContig);
                var outputPtr = CudaHelpers.GetBufferStart(output);
                var indicesPtr = CudaHelpers.GetBufferStart(indices);
                var count = (int)output.ElementCount();
                Invoke(context, cudaContext, "MaxPoolForward", new dim3(NNThreads.NumBlocks(count)), new dim3(NNThreads.NumThreads), 0, CUstream.NullStream,
                    count, inputPtr, batchSize, nInputPlane, iheight, iwidth, oheight, owidth,
                    cd.kH, cd.kW, cd.dH, cd.dW, cd.padH, cd.padW, outputPtr, indicesPtr);
            }
        }
public void SpatialMaxPoolingForward ( NDArray input , NDArray output , NDArray indices , ConvolutionDesc2d cd , bool ceilMode ) { var context = CudaHelpers . TSContextForTensor ( input ) ; var cudaContext = context . CudaContextForTensor ( input ) ; var iwidth = input . Shape [ 3 ] ; var iheight = input . Shape [ 2 ] ; var nInputPlane = input . Shape [ 1 ] ; var batchSize = input . Shape [ 0 ] ; long owidth ; long oheight ; if ( ceilMode ) { oheight = ( long ) ( Math . Ceiling ( ( float ) ( iheight - cd . kH + 2 * cd . padH ) / cd . dH ) ) + 1 ; owidth = ( long ) ( Math . Ceiling ( ( float ) ( iwidth - cd . kW + 2 * cd . padW ) / cd . dW ) ) + 1 ; } else { oheight = ( long ) ( Math . Floor ( ( float ) ( iheight - cd . kH + 2 * cd . padH ) / cd . dH ) ) + 1 ; owidth = ( long ) ( Math . Floor ( ( float ) ( iwidth - cd . kW + 2 * cd . padW ) / cd . dW ) ) + 1 ; } if ( cd . padW != 0 || cd . padH != 0 ) { if ( ( oheight - 1 ) * cd . dH >= iheight + cd . padH ) -- oheight ; if ( ( owidth - 1 ) * cd . dW >= iwidth + cd . padW ) -- owidth ; } using ( var inputContig = Ops . AsContiguous ( input ) ) { var inputPtr = CudaHelpers . GetBufferStart ( inputContig ) ; var outputPtr = CudaHelpers . GetBufferStart ( output ) ; var indicesPtr = CudaHelpers . GetBufferStart ( indices ) ; var count = ( int ) output . ElementCount ( ) ; Invoke ( context , cudaContext , " " , new dim3 ( NNThreads . NumBlocks ( count ) ) , new dim3 ( NNThreads . NumThreads ) , 0 , CUstream . NullStream , count , inputPtr , batchSize , nInputPlane , iheight , iwidth , oheight , owidth , cd . kH , cd . kW , cd . dH , cd . dW , cd . padH , cd . padW , outputPtr , indicesPtr ) ; } }
Spatials the maximum pooling forward.
Spatials the maximum pooling forward .
// ensure that the last pooling starts inside the image
input
NDArray
None
output
NDArray
None
indices
NDArray
None
cd
ConvolutionDesc2d
None
ceilMode
bool
if set to true
if set to true