Struct is undefined

Feb 27 at 12:02 PM
Edited Feb 27 at 1:23 PM
I have two structs (PointGPU and TriangleGPU) used in cudafying method Polygonise. It's objects passed to the method as parameters. I tried to use principles like in CudafyByExample project but I don't understand what is wrong.
[Cudafy]
public struct TriangleGPU
{
    public PointGPU[] p;
}

[Cudafy]
public struct PointGPU
{
    public double x;
    public double y;
    public double z;

    public PointGPU(double x, double y, double z)
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }
}

class MarchingCubesOnGPU
{
    public const int vertCount = 12;

    // GPU
    CudafyModule km = CudafyTranslator.Cudafy();
    GPGPU gpu = CudafyHost.GetDevice();

    private static PointGPU[] pointsGpu = new PointGPU[8];
    private static int[] valsGpu = new int[8];
    private static double[] isolevelGpu = new double[1];
    private static TriangleGPU[] trianglesGpu;
    ...

    public void Execute()
    {
        gpu.LoadModule(km);

        TriangleGPU[] tris;

        PointGPU[] dev_points = gpu.CopyToDevice(pointsGpu);
        int[] dev_values = gpu.CopyToDevice(valsGpu);
        double[] dev_iso = gpu.Allocate<double>();
        TriangleGPU[] dev_triangles = gpu.CopyToDevice(trianglesGpu);
        int[] dev_edgeTable = gpu.Allocate<int>();
        int[,] dev_triangleTable = gpu.Allocate(TriTableStatic);
        PointGPU[] dev_vertList = gpu.Allocate<PointGPU>();

        gpu.CopyToDevice(isolevelGpu, dev_iso);
        gpu.CopyToDevice(EdgeTableStatic, dev_edgeTable);
        gpu.CopyToDevice(TriTableStatic, dev_triangleTable);

        gpu.Launch().PolygoniseOnGpu(dev_iso, dev_edgeTable, dev_triangleTable, dev_points, dev_values, dev_triangles, dev_vertList);

        for (int k = 0; k < dev_triangles.Length; k++)
        {
            gpu.CopyFromDevice(dev_triangles, out trianglesGpu[k]);
        }
        ...

        gpu.FreeAll();
    }

    [Cudafy]
    public static void PolygoniseOnGpu(double[] iso, int[] edgeT, int[,] triT, PointGPU[] p, int[] v, TriangleGPU[] tri, PointGPU[] dev_vert)
    {
        int cubeindex = 0;
        for (int i = 0; i < 8; ++i)
        {
            if (valsGpu[i] < iso[0])
                cubeindex |= 1 << i;
        }

        if (EdgeTableStatic[cubeindex] == 0)
            return;

        // Find the vertices where the surface intersects the cube 
        for (int id = 1, count = 0; id < 2048; id *= 2, count++)
        {
            if ((edgeT[cubeindex] & id) > 0)
                dev_vert[count] = VertexInterpolation(iso[0], p[count], p[count + 1], v[count], v[count + 1]);
        }
        ...
   }

    [Cudafy]
    public static PointGPU VertexInterpolation(double isolevel, PointGPU p1, PointGPU p2, double valP1, double valP2)
    {
        PointGPU p = new PointGPU();
        ...
    }
}

CudafySourceTemp.cu is
// DICOMViewer.GPU.MarchingCubesOnGPU
extern "C" __global__  void PolygoniseOnGpu( double* iso, int isoLen0,  int* edgeT, int edgeTLen0,  int* triT, int triTLen0, int triTLen1,  PointGPU* p, int pLen0,  int* v, int vLen0,  TriangleGPU* tri, int triLen0,  PointGPU* dev_vert, int dev_vertLen0);
// DICOMViewer.GPU.MarchingCubesOnGPU
__device__  PointGPU VertexInterpolation(double isolevel, PointGPU p1, PointGPU p2, double valP1, double valP2);

// DICOMViewer.GPU.MarchingCubesOnGPU
extern "C" __global__  void PolygoniseOnGpu( double* iso, int isoLen0,  int* edgeT, int edgeTLen0,  int* triT, int triTLen0, int triTLen1,  PointGPU* p, int pLen0,  int* v, int vLen0,  TriangleGPU* tri, int triLen0,  PointGPU* dev_vert, int dev_vertLen0)
{
    int num = 0;
    for (int i = 0; i < 8 ; i++)
    {
        bool flag = (double)valsGpu[(i)] < iso[(0)];
        if (flag)
        {
            num |= 1 << (i & 31);
        }
    }
        ...
}
Errors are:
.../bin/Debug/CUDAFYSOURCETEMP.cu(3): error: identifier "PointGPU" is undefined (where PointGPU* p as a parameter of Polygonise)
.../bin/Debug/CUDAFYSOURCETEMP.cu(3): error: identifier "TriangleGPU" is undefined (where TriangleGPU* tri as a parameter of Polygonise)
.../bin/Debug/CUDAFYSOURCETEMP.cu(13): error: identifier "valsGpu" is undefined (in (double)valsGpu[(i)])
Coordinator
Mar 6 at 2:04 PM
You may need to explicitly pass the type of the structs to the Cudafy method. Please note however that an array inside a struct must be of a fixed size which also necessitates use of "unsafe" - please refer to the C# code.
Marked as answer by twojay on 3/19/2017 at 11:20 PM