1
Vote

Passinf structure to kernel

description

Hi everyone,

I am new in Cudafy and the question therefore might be a dummy one. However I cannot get over it.
I am trying to pass a structure of 4 ints to kernel and after running the code I get the following error message: Compilation error: 1:53:29: error: must use 'struct' tag to refer to type
I follow the examples but it is 1:1 as in examples. If I write the code using simple ints everything works fine

the structure:
    [Cudafy]
    [StructLayout(LayoutKind.Sequential)]
    public struct gpuLineSegment
    {
        public float A_x;
        public float A_y;
        public float B_x;
        public float B_y;
    }
the initialization code

CudafyModes.Target = eGPUType.OpenCL;
        CudafyModes.DeviceId = 0;
        CudafyTranslator.Language = CudafyModes.Target == eGPUType.OpenCL ? eLanguage.OpenCL : eLanguage.Cuda;
        gpu = CudafyHost.GetDevice(CudafyModes.Target, _selected_device);
        km = CudafyModule.TryDeserialize();
        if (km == null || !km.TryVerifyChecksums())
        {
            km = CudafyTranslator.Cudafy(typeof(ObstPoint), typeof(gpuPiont), typeof(gpuRectangle), typeof(gpuLineSegment), typeof(RRT_GPU_1));
            km.TrySerialize();
        }
        gpu.LoadModule(km);
and the kernel that draws a simple segment of line in image (rgb)
    [Cudafy]
    private static void GPU_DrawLine(gpuLineSegment s, byte[] rgb, int W, int H)
    {

        int dx;
        int dy;
            dx = (int)(s.B_x - s.A_x);
            dy = (int)(s.B_y - s.A_y);
            for (int x = (int)s.A_x; x < (int)s.B_x; x++)
            {
                int y = (int)(s.A_y + dy * (x - (int)s.A_x) / dx);
                int offset = x + y * W;
                rgb[offset * 4] = 255;
                rgb[offset * 4 + 1] = 0;
                rgb[offset * 4 + 2] = 0;
                rgb[offset * 4 + 3] = 0;
            }
        }

comments

agrisnikitenko wrote Mar 27, 2016 at 12:40 PM

Solved by passing gpuLineSegment[] s with length 1 instead of gpuLineSegment s.
Newbie's problem. :-)