public static void InitKernels() { if (cs_radixSort != null) { return; } cs_radixSort = Resources.Load <ComputeShader>("RadixSort"); kn_radixSortLocal = cs_radixSort.FindKernel("RadixSortLocal"); kn_globalShuffle = cs_radixSort.FindKernel("GlobalShuffle"); BlellochSumScan.InitKernels(); }
public RadixSort(int dataSize) { this._dataSize = dataSize; this._sortGridSize = MathUtil.CalculateGrids(_dataSize, Graphics.M_BLOCK_SZ); this._blockSumsSize = 4 * _sortGridSize; this._blellochSumScan = new BlellochSumScan(_blockSumsSize); this.cb_sortTemp = new ComputeBuffer(_dataSize, StrideSize.s_uint); this.cb_indexTemp = new ComputeBuffer(_dataSize, StrideSize.s_uint); this.cb_prefixSums = new ComputeBuffer(_dataSize, StrideSize.s_uint); this.cb_blockSums = new ComputeBuffer(_blockSumsSize, StrideSize.s_uint); this.cb_scanBlockSums = new ComputeBuffer(_blockSumsSize, StrideSize.s_uint); }
public void BlellochSumScanTest() { uint[] array = new uint[ARRAY_COUNT]; uint[] scannedArray = new uint[ARRAY_COUNT]; for (int i = 0; i < ARRAY_COUNT; i++) { array[i] = GenerateRandomUInt(); } ComputeBuffer cb_in = new ComputeBuffer(ARRAY_COUNT, StrideSize.s_uint); ComputeBuffer cb_out = new ComputeBuffer(ARRAY_COUNT, StrideSize.s_uint); ComputeShaderUtil.InitKernels(); BlellochSumScan.InitKernels(); cb_in.SetData(array); ComputeShaderUtil.ZeroOut(ref cb_out, ARRAY_COUNT); BlellochSumScan blellochSumScan = new BlellochSumScan(ARRAY_COUNT); blellochSumScan.Scan(ref cb_in, ref cb_out, ARRAY_COUNT); cb_out.GetData(scannedArray); // using serial exclusive sum scan method to make sure that the parallel method works uint sum = 0; for (int i = 0; i < ARRAY_COUNT; i++) { Assert.AreEqual(sum, scannedArray[i]); sum += array[i]; } cb_in.Dispose(); cb_out.Dispose(); blellochSumScan.Dispose(); }