Пример #1
0
 public static void Test(GThread thread, DerivedClass[] instance, float[] result)
 {
     result[0] = instance[1].Sum();
     result[1] = instance[1].SumDimension0();
     result[2] = instance[1].SumBase();
     result[3] = instance[1].MemberClassInstance.Test();
 }
Пример #2
0
        public static void Example1(GPGPU gpu)
        {
            // Create instance and copy this to the GPU.
            // Includes a base class and another class as a member. 
            DerivedClass[] array = new DerivedClass[2];
            DerivedClass instance = new DerivedClass();
            instance.PopulateMembers();
            instance.MemberClassInstance = new MemberClass();
            instance.MemberClassInstance.Field = 5;
            instance.MemberClassInstance.MemberClassArray = new float[] { 3, 4, 5 };
            DerivedClass instance2 = new DerivedClass();
            instance2.PopulateMembers();
            instance2.MemberClassInstance = new MemberClass();
            instance2.MemberClassInstance.Field = 6;
            instance2.MemberClassInstance.MemberClassArray = new float[] { 6, 7, 8 };
            array[0] = instance;
            array[1] = instance2;
            DeviceClassHelper.CreateDeviceObject(gpu, array);
            // could also use 
            // var dev_array = DeviceClassHelper.CreateDeviceObject(gpu, array);
            // Note that this also copies reference type members to the GPU.

            // Create a result array and copy to the GPU:
            float[] result = new float[5];
            var dev_result = DeviceClassHelper.CreateDeviceObject(gpu, result);

            var dev_array = DeviceClassHelper.TryGetDeviceObjectFromHostObject(gpu, array);

            gpu.Launch(1, 1).Test(dev_array, dev_result);

            DeviceClassHelper.UpdateFromDevice(gpu, result);

            bool pass = (result[0] == 18.9f && result[1] == 8.8f && result[2] == 10f && result[3] == 36f);
            Console.WriteLine(pass ? "Pass" : "Fail");
        }