This project is read-only.

Copy to device a struct with arrays inside

Mar 13 at 5:15 PM
Hi. I have a struct:
    public struct TriangleGP
    {
        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 3)]
        public double[] XDoubles; //3 points
        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 3)]
        public double[] YDoubles; //3 points
        [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 3)]
        public double[] ZDoubles; //3 points
    }
and I'm going to copy this into GPU:
TriangleGP[] temp_ts = FillTriangles(aTriangleList);

                        CudafyModule km = CudafyModule.TryDeserialize();
                        if (km == null || !km.TryVerifyChecksums())
                        {
                            km = CudafyTranslator.Cudafy(typeof(PointGPU), typeof(TriangleGP));
                            km.Serialize();
                        }
                        GPGPU gpu = CudafyHost.CreateDevice(CudafyModes.Target, CudafyModes.DeviceId);
                        gpu.LoadModule(km);
                        TriangleGP[] dev_triangles = gpu.Allocate<TriangleGP>();
                        gpu.CopyToDevice(temp_ts, dev_triangles); 
                        gpu.Launch().Polygonise(..., dev_triangles)
                        gpu.CopyFromDevice<TriangleGP>(dev_triangles, out resultTri);
                        gpu.FreeAll();
but I have a System.ArgumentException in mscorlib in line gpu.CopyToDevice(temp_ts, dev_triangles); it says about objects has data that are non-primitives
Is the problem in my wrong using cudafy? Did I write this right?
Mar 14 at 7:11 AM
The issue was decided with:
[Cudafy]
    public unsafe struct TriangleGP
    {
        public fixed double XDoubles[3]; //3 points
        public fixed double YDoubles[3]; //3 points
        public fixed double ZDoubles[3]; //3 points
    }
Marked as answer by twojay on 3/13/2017 at 11:11 PM