public void GroupedIndex2EntryPoint(int length) { var end = (int)Math.Sqrt(Accelerator.MaxNumThreadsPerGroup); for (int i = 1; i <= end; i <<= 1) { var stride = new Index2(i, i); var extent = new KernelConfig( new Index2(length, length), stride); using var buffer = Accelerator.Allocate <int>(extent.Size); buffer.MemSetToZero(Accelerator.DefaultStream); Execute(extent, buffer.View, stride, extent.GridDim.XY); var expected = new int[extent.Size]; for (int j = 0; j < length * length; ++j) { var gridIdx = Index2.ReconstructIndex(j, extent.GridDim.XY); for (int k = 0; k < i * i; ++k) { var groupIdx = Index2.ReconstructIndex(k, extent.GroupDim.XY); var idx = (gridIdx * stride + groupIdx).ComputeLinearIndex(extent.GridDim.XY); expected[idx] = idx; } } Verify(buffer, expected); } }
5, 6_000)] // Make sure linearIndices > int.MaxValue work. public void ReconstructIndex2( long linearIndex, int dimX, int dimY, int expectedX, int expectedY) { var index = Index2.ReconstructIndex(linearIndex, new Index2(dimX, dimY)); Assert.Equal(expectedX, index.X); Assert.Equal(expectedY, index.Y); }
public static void PerformShading(Index index, ArrayView <Rgba32> image, Rgba32 frameColor, int radius, Size size) { int circleCentreX = size.Width / 2; int circleCentreY = size.Height / 2; var point = Index2.ReconstructIndex(index.X, new Index2(size.Width, size.Height)); if (((point.X - circleCentreX) * (point.X - circleCentreX) + (point.Y - circleCentreY) * (point.Y - circleCentreY)) > radius * radius) { image[(point.Y * size.Width) + point.X] = frameColor; } }
private static Index2 Reconstruct2DIndex(Index2 totalDim, int linearIndex) => totalDim.ReconstructIndex(linearIndex);