Backends/SiaNet.Backend.TensorSharp/Cuda/KernelOps/ReductionOp.cs
/// <summary>
/// Gets the contig reduce block.
/// </summary>
/// <param name="cudaContext">The cuda context.</param>
/// <param name="numSlices">The number slices.</param>
/// <param name="reductionSize">Size of the reduction.</param>
/// <returns>dim3.</returns>
Gets the contig reduce block.
Gets the contig reduce block .
private static dim3 GetContigReduceBlock(CudaContext cudaContext, long numSlices, long reductionSize)
        {
            int smCount = 15;
            int maxWarps = 4; 
            if (numSlices < smCount * 8)
            {
                maxWarps = 8;
                if (numSlices < smCount * 4)
                {
                    maxWarps = 16;
                    if (numSlices < smCount * 2)
                    {
                        maxWarps = 32;
                    }
                }
            }
            long warpsInReductionSize = ApplyUtils.CeilDiv(reductionSize, 32);
            int numWarps =
              warpsInReductionSize > (long)maxWarps ? maxWarps : (int)warpsInReductionSize;
            int targetSize = numWarps * 32;
            targetSize = Math.Min(targetSize, (int)cudaContext.GetDeviceInfo().MaxBlockDim.x);
            return new dim3(targetSize);
        }
private static dim3 GetContigReduceBlock ( CudaContext cudaContext , long numSlices , long reductionSize ) { int smCount = 15 ; int maxWarps = 4 ; if ( numSlices < smCount * 8 ) { maxWarps = 8 ; if ( numSlices < smCount * 4 ) { maxWarps = 16 ; if ( numSlices < smCount * 2 ) { maxWarps = 32 ; } } } long warpsInReductionSize = ApplyUtils . CeilDiv ( reductionSize , 32 ) ; int numWarps = warpsInReductionSize > ( long ) maxWarps ? maxWarps : ( int ) warpsInReductionSize ; int targetSize = numWarps * 32 ; targetSize = Math . Min ( targetSize , ( int ) cudaContext . GetDeviceInfo ( ) . MaxBlockDim . x ) ; return new dim3 ( targetSize ) ; }
Gets the contig reduce block.
Gets the contig reduce block .
// If the number of slices is low but the reduction dimension size // is high, then we should increase block size for greater parallelism. // Aim for at least 32 warps per SM (assume 15 SMs; don't bother // inquiring the real number for now). // better occupancy if many blocks are around // For numSlices > smCount * 8, there are > 32 warps active per SM. // Scale up block size based on the reduction dimension size
None
cudaContext
CudaContext
The cuda context.
The cuda context .
numSlices
long
The number slices.
The number slices .
reductionSize
long
Size of the reduction.
Size of the reduction .