Backends/SiaNet.Backend.TensorSharp/Cuda/DeviceCode/ReduceDimIndexKernels.cs
/// <summary>
/// Reduces the index innermost 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="init">The initialize.</param>
/// <param name="baseKernelName">Name of the base kernel.</param>
Reduces the index innermost dim.
Reduces the index innermost dim .
private void ReduceIndexInnermostDim(TSCudaContext context, NDArray resultValues, NDArray resultIndices, NDArray src, Tuple<float, float> init, string baseKernelName)
        {
            var cudaContext = context.CudaContextForTensor(src);
            var ndim = src.DimensionCount;
            long num_rows = 1;
            for (int dim = 0; dim < ndim - 1; dim++)
            {
                num_rows *= src.Shape[dim];
            }
            var row_size = src.Shape[ndim - 1];
            var threads = new dim3(16, 32);
            var grid = new dim3((uint)Math.Min(1024, ApplyUtils.CeilDiv(num_rows, threads.y)));
            var resultValPtr = CudaHelpers.GetBufferStart(resultValues);
            var resultIdxPtr = CudaHelpers.GetBufferStart(resultIndices);
            var srcPtr = CudaHelpers.GetBufferStart(src);
            var kernelName = "inner_index_" + baseKernelName;
            Invoke(context, cudaContext, kernelName, grid, threads, 0, CUstream.NullStream, resultValPtr, resultIdxPtr, srcPtr, num_rows, row_size, init.Item1, init.Item2);
        }
private void ReduceIndexInnermostDim ( TSCudaContext context , NDArray resultValues , NDArray resultIndices , NDArray src , Tuple < float , float > init , string baseKernelName ) { var cudaContext = context . CudaContextForTensor ( src ) ; var ndim = src . DimensionCount ; long num_rows = 1 ; for ( int dim = 0 ; dim < ndim - 1 ; dim ++ ) { num_rows *= src . Shape [ dim ] ; } var row_size = src . Shape [ ndim - 1 ] ; var threads = new dim3 ( 16 , 32 ) ; var grid = new dim3 ( ( uint ) Math . Min ( 1024 , ApplyUtils . CeilDiv ( num_rows , threads . y ) ) ) ; 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_rows , row_size , init . Item1 , init . Item2 ) ; }
Reduces the index innermost dim.
Reduces the index innermost dim .
context
TSCudaContext
None
resultValues
NDArray
The result values.
The result values .
resultIndices
NDArray
The result indices.
The result indices .
src
NDArray
None
init
Tuple<float, float>
None
baseKernelName
string
Name of the base kernel.
Name of the base kernel .