Ejemplo n.º 1
0
 public static void Test2(GThread thread, ArrayView arrayView1, ArrayView arrayView2, float[] result)
 {
     result[0] = arrayView1.GetElement(5);
     arrayView1.SetElement(106, 7f); // set element to 7 to verify that underlying array is same
     result[1] = arrayView2.GetElement(6); // check this is 7
 }
Ejemplo n.º 2
0
        public static void Example2(GPGPU gpu)
        {
            ArrayView view1 = new ArrayView();
            ArrayView view2 = new ArrayView();
            float[] data = Enumerable.Range(0, 1000).Select(t => (float)t).ToArray();
            // Two views of the array, simply applying an offset to the array; could slice instead for example.
            view1.CreateView(data, 100);
            view2.CreateView(data, 200);

            for (int i = 0; i < 1000; ++i) data[i] = data[i] * 10f;
            // Should copy the 'large' array to the device only once; this is referenced by each ArrayView instance.
            var dev_view1 = DeviceClassHelper.CreateDeviceObject(gpu, view1); 
            var dev_view2 = DeviceClassHelper.CreateDeviceObject(gpu, view2);

            var dev_result = gpu.Allocate<float>(5);
            var hostResult = new float[5];

            gpu.Launch(1, 1).Test2(dev_view1, dev_view2, dev_result);
            gpu.CopyFromDevice(dev_result, hostResult);

            bool pass = (hostResult[0] == 1050f && hostResult[1] == 7f);
            Console.WriteLine(pass ? "Pass" : "Fail");
        }