コード例 #1
0
        public void Test_processStructure()
        {
            PrimitiveStruct[] x = new PrimitiveStruct[N];
            PrimitiveStruct[] y = new PrimitiveStruct[N];
            int size            = Marshal.SizeOf(x[0]);

            for (int i = 0; i < N; i++)
            {
                x[i].Value1  = i;
                x[i].Message = "hello " + i.ToString();
            }
            IntPtr x_ptr = _gpu.HostAllocate <PrimitiveStruct>(N);
            IntPtr y_ptr = _gpu.HostAllocate <PrimitiveStruct>(N);

            PrimitiveStruct[] dev_x = _gpu.Allocate <PrimitiveStruct>(N);
            PrimitiveStruct[] dev_y = _gpu.Allocate <PrimitiveStruct>(N);
            //x_ptr.Write(x);

            //_gpu.CopyToDeviceAsync(x_ptr, 0, dev_x, 0, N);
            _gpu.CopyToDevice(x, 0, dev_x, 0, N);
            _gpu.Launch(1, N, "ProcessStructure", dev_x, dev_y);
            //_gpu.CopyFromDeviceAsync(dev_y, 0, y_ptr, 0, N);
            _gpu.CopyFromDevice(dev_y, 0, y, 0, N);

            _gpu.SynchronizeStream();

            //y_ptr.Read(y);
            _gpu.HostFreeAll();
            _gpu.FreeAll();
            for (int i = 0; i < N; i++)
            {
                Assert.AreEqual(x[i].Value1, y[i].Value1);
                //Assert.AreEqual(x[i].myvalues, y[i].myvalues);
                //Console.WriteLine(y[i].Message);
                Assert.AreEqual(x[i].Message, y[i].Message);
            }
        }
コード例 #2
0
 public static void ProcessStructure(GThread thread, PrimitiveStruct[] x, PrimitiveStruct[] y)
 {
     int idx = thread.threadIdx.x;
     y[idx].Value1 = x[idx].Value1;
     y[idx].Value2 = x[idx].Value2;
     y[idx].Value3 = x[idx].Value3;
     y[idx].Value4 = x[idx].Value4;
     fixed (char* xptr = x[idx]._messageChars)
     {
         fixed (char* yptr = y[idx]._messageChars)
         {
             char* px = xptr;
             char* py = yptr;
             for (int i = 0; i < 16; i++)
             {
                 *py = *px;
                 px++;
                 py++;
             }
         }
     }
 }
コード例 #3
0
        public void Test_processStructure()
        {

            PrimitiveStruct[] x = new PrimitiveStruct[N];
            PrimitiveStruct[] y = new PrimitiveStruct[N];
            int size = Marshal.SizeOf(x[0]);
            for (int i = 0; i < N; i++)
            {
                x[i].Value1 = i;
                x[i].Message = "hello " + i.ToString();
            }
            IntPtr x_ptr = _gpu.HostAllocate<PrimitiveStruct>(N);
            IntPtr y_ptr = _gpu.HostAllocate<PrimitiveStruct>(N);
            PrimitiveStruct[] dev_x = _gpu.Allocate<PrimitiveStruct>(N);
            PrimitiveStruct[] dev_y = _gpu.Allocate<PrimitiveStruct>(N);
            //x_ptr.Write(x);

            //_gpu.CopyToDeviceAsync(x_ptr, 0, dev_x, 0, N);
            _gpu.CopyToDevice(x, 0, dev_x, 0, N);
            _gpu.Launch(1, N, "ProcessStructure", dev_x, dev_y);
            //_gpu.CopyFromDeviceAsync(dev_y, 0, y_ptr, 0, N);
            _gpu.CopyFromDevice(dev_y, 0, y, 0, N);

            _gpu.SynchronizeStream();

            //y_ptr.Read(y);
            _gpu.HostFreeAll();
            _gpu.FreeAll();
            for (int i = 0; i < N; i++)
            {
                Assert.AreEqual(x[i].Value1, y[i].Value1);
                //Assert.AreEqual(x[i].myvalues, y[i].myvalues);
                //Console.WriteLine(y[i].Message);
                Assert.AreEqual(x[i].Message, y[i].Message);
            }
        }