Backends/SiaNet.Backend.TensorSharp/Cuda/DeviceCode/ReduceDimIndexKernels.cs
/// <summary>
/// Reduces the index outer dim.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="resultValues">The result values.</param>
/// <param name="resultIndices">The result indices.</param>
/// <param name="src">The source.</param>
/// <param name="dimension">The dimension.</param>
/// <param name="init">The initialize.</param>
/// <param name="baseKernelName">Name of the base kernel.</param>
Reduces the index outer dim.
Reduces the index outer dim .
private void ReduceIndexOuterDim(TSCudaContext context, NDArray resultValues, NDArray resultIndices, NDArray src, int dimension, Tuple<float, float> init, string baseKernelName)
        {
            var cudaContext = context.CudaContextForTensor(src);
            var ndim = src.DimensionCount;
            long num_orows = 1;
            for (int dim = 0; dim < dimension; dim++)
            {
                num_orows *= src.Shape[dim];
            }
            var row_size = src.Shape[dimension];
            long num_irows = 1;
            for (int dim = dimension + 1; dim < ndim; dim++)
            {
                num_irows *= src.Shape[dim];
            }
            var threads = new dim3((uint)Math.Min(512, num_irows));
            var maxGridDim = 1024;
            var grid = new dim3((uint)Math.Min(maxGridDim, num_orows), (uint)Math.Min(maxGridDim, ApplyUtils.CeilDiv(num_irows, threads.x)));
            var resultValPtr = CudaHelpers.GetBufferStart(resultValues);
            var resultIdxPtr = CudaHelpers.GetBufferStart(resultIndices);
            var srcPtr = CudaHelpers.GetBufferStart(src);
            var kernelName = "outer_index_" + baseKernelName;
            Invoke(context, cudaContext, kernelName, grid, threads, 0, CUstream.NullStream, resultValPtr, resultIdxPtr, srcPtr, num_orows, num_irows, row_size, init.Item1, init.Item2);
        }
private void ReduceIndexOuterDim ( TSCudaContext context , NDArray resultValues , NDArray resultIndices , NDArray src , int dimension , Tuple < float , float > init , string baseKernelName ) { var cudaContext = context . CudaContextForTensor ( src ) ; var ndim = src . DimensionCount ; long num_orows = 1 ; for ( int dim = 0 ; dim < dimension ; dim ++ ) { num_orows *= src . Shape [ dim ] ; } var row_size = src . Shape [ dimension ] ; long num_irows = 1 ; for ( int dim = dimension + 1 ; dim < ndim ; dim ++ ) { num_irows *= src . Shape [ dim ] ; } var threads = new dim3 ( ( uint ) Math . Min ( 512 , num_irows ) ) ; var maxGridDim = 1024 ; var grid = new dim3 ( ( uint ) Math . Min ( maxGridDim , num_orows ) , ( uint ) Math . Min ( maxGridDim , ApplyUtils . CeilDiv ( num_irows , threads . x ) ) ) ; var resultValPtr = CudaHelpers . GetBufferStart ( resultValues ) ; var resultIdxPtr = CudaHelpers . GetBufferStart ( resultIndices ) ; var srcPtr = CudaHelpers . GetBufferStart ( src ) ; var kernelName = " " + baseKernelName ; Invoke ( context , cudaContext , kernelName , grid , threads , 0 , CUstream . NullStream , resultValPtr , resultIdxPtr , srcPtr , num_orows , num_irows , row_size , init . Item1 , init . Item2 ) ; }
Reduces the index outer dim.
Reduces the index outer dim .
context
TSCudaContext
None
resultValues
NDArray
The result values.
The result values .
resultIndices
NDArray
The result indices.
The result indices .
src
NDArray
None
dimension
int
None
init
Tuple<float, float>
None
baseKernelName
string
Name of the base kernel.
Name of the base kernel .