1

How can you have a struct full of arrays in cudafy?

This appears a somewhat trivial issue, but I could not find an easy implementation of it on the net.

Some links suggest it cannot be done, see for example: Passing an array within a structure in CUDAfy

While others suggest it can be done through a somewhat lengthy helper function, see for example http://cudafy.codeplex.com/discussions/283527

I am looking to pass a single struct into my Cudafy kernel, where for example the struct looks like...

    [Cudafy]
    public struct myStructTwo
    {
        public float[] value_x;
        public float[] value_y;
        public float[] value_z;
    }


    public struct myStructTwo
    {
        public IntPtr value_x;
        public IntPtr value_y;
        public IntPtr value_z;
    }
Community
  • 1
  • 1
rithm10
  • 63
  • 4

1 Answers1

4

The question has been addressed in a Codeplex answer. It looks to be possible using a fixed size e.g.

[Cudafy]
public struct myStructTwo
{
    public float value_x[size];
}

I will let this question remain open in case further responses are received.

rithm10
  • 63
  • 4
  • structs need to have a fixed total size. this is what allows them to be handled by eg. arrays as values and not pointers. i guess you could use a list, since the struct just stores a pointer to the list – Rasmus Damgaard Nielsen Jul 08 '16 at 13:53
  • @RasmusDamgaardNielsen surely the question here is trying to determine whether a struct with an array can be passed to the GPU, so a pointer to a list wouldn't work? – mcmillab Oct 11 '17 at 01:40