/// <summary> /// Computes the required number of temp-storage elements for a radix sort /// operation and the given data length. /// </summary> /// <typeparam name="T">The underlying type of the sort operation.</typeparam> /// <typeparam name="TRadixSortOperation"> /// The type of the radix-sort operation. /// </typeparam> /// <param name="accelerator">The accelerator.</param> /// <param name="dataLength">The number of data elements to sort.</param> /// <returns> /// The required number of temp-storage elements in 32 bit ints. /// </returns> public static Index1 ComputeRadixSortTempStorageSize <T, TRadixSortOperation>( this Accelerator accelerator, Index1 dataLength) where T : unmanaged where TRadixSortOperation : struct, IRadixSortOperation <T> { Index1 tempScanMemory = accelerator.ComputeScanTempStorageSize <T>(dataLength); int numGroups; if (accelerator.AcceleratorType == AcceleratorType.CPU) { numGroups = accelerator.MaxNumThreads; } else { var(gridDim, _) = accelerator.ComputeGridStrideLoopExtent( dataLength, out int numIterationsPerGroup); numGroups = gridDim * numIterationsPerGroup; } int numIntTElements = Interop.ComputeRelativeSizeOf <int, T>(dataLength); const int unrollFactor = 4; return(numGroups * unrollFactor * 2 + numIntTElements + tempScanMemory); }
private ArrayView <int> AllocateTempScanView <T>(ArrayView <T> input) where T : unmanaged { var tempSize = Accelerator.ComputeScanTempStorageSize <T>(input.Length); return(bufferCache.Allocate <int>(tempSize)); }
private ArrayView <int> AllocateTempScanView <T>(ArrayView <T> input) where T : unmanaged { var tempSize = Accelerator.ComputeScanTempStorageSize <T>(input.Length); IndexTypeExtensions.AssertIntIndexRange(tempSize); return(bufferCache.Allocate <int>(tempSize.ToIntIndex())); }
private ArrayView <T> AllocateTempScanView <T>(ArrayView <T> input) where T : struct { var tempSize = Accelerator.ComputeScanTempStorageSize(input.Length); if (tempSize < 1) { throw new ArgumentOutOfRangeException(nameof(input)); } return(bufferCache.Allocate <T>(tempSize)); }