/// <summary> /// A simple 1D kernel. Simple kernels also support other dimensions via Index2 and Index3. /// Note that the first argument of a kernel method is always the current index. All other parameters /// are optional. Furthermore, kernels can only receive structures as arguments; reference types are /// not supported. /// /// Memory buffers are accessed via ArrayViews (<see cref="ArrayView{T}"/>, <see cref="ArrayView{T, TIndex}"/>). /// These views encapsulate all memory accesses and hide the underlying native pointer operations. /// Similar to ArrayViews, a VariableView (<see cref="VariableView{T}"/>) points to a single variable in memory. /// In other words, a VariableView is a special ArrayView with a length of 1. /// </summary> /// <param name="index">The current thread index.</param> /// <param name="dataView">The view pointing to our memory buffer.</param> /// <param name="constant">A uniform constant.</param> static void MyKernel( ILGPU.Index index, // The global thread index (1D in this case) ArrayView <int> dataView, // A view to a chunk of memory (1D in this case) int constant) // A sample uniform constant { dataView[index] = index + constant; }
private int runILGPUTest(int items, TimeSpan duration, Accelerator acc, bool copyBack) { int count = 0; var init = acc.CreateInitializer <Vector2>(); using (var buffer1 = acc.Allocate <Vector2>(items)) { init(acc.DefaultStream, buffer1, Vector2.One); using (var buffer2 = acc.Allocate <Vector2>(items)) { init(acc.DefaultStream, buffer2, Vector2.One); var run = acc.LoadAutoGroupedStreamKernel <ILGPU.Index, ArrayView <Vector2>, ArrayView <Vector2> >(ilgpu_test); ILGPU.Index idx = new ILGPU.Index(items); Stopwatch sb = new Stopwatch(); sb.Start(); while (sb.Elapsed < duration) { run(idx, buffer1, buffer2); acc.Synchronize(); count++; if (copyBack) { buffer1.GetAsArray(); } count++; } } } return(count); }
private static void UpdateXKernel( ILGPU.Index index, ArrayView2D <float> xImage, ArrayView <Pixel> pixel) { if (pixel[0].AbsDiff > 0) { xImage[pixel[0].X, pixel[0].Y] += pixel[0].Sign * pixel[0].AbsDiff; } }
public void Init() { var init = Acc.CreateInitializer <Vector2>(); buffer1 = Acc.Allocate <Vector2>(Items); init(Acc.DefaultStream, buffer1, Vector2.One); buffer2 = Acc.Allocate <Vector2>(Items); init(Acc.DefaultStream, buffer2, Vector2.One); run = Acc.LoadAutoGroupedStreamKernel <ILGPU.Index, ArrayView <Vector2>, ArrayView <Vector2> >(ilgpu_test); idx = new ILGPU.Index(Items); }
private static void ilgpu_test(ILGPU.Index idx, ArrayView <Vector2> value1, ArrayView <Vector2> value2) { value1[idx] = value1[idx] + value2[idx]; }