Closed RobbinMarcus closed 7 years ago
I posted an answer on StackOverflow, but the short answer is, that this will be tough to get running automatically.
I had the same troubles with some of the structures of the CUDA API. To manipulate the layout, you'd use the StructLayout
options. But still, in some rare cases, I also had to use the explicit layout to get things to work.
I was wondering if there is a general accepted solution to create a memory layout that works in C++ CUDA and in C# / ManagedCuda. I'm having trouble with the alignment of structures that contain float4 values. Since the float4 is aligned to 16 bytes in CUDA/C++, the structures usually add padding when there are members smaller than 16 bytes. This padding is not added when Marshalled from C#, thus the sizes of the structs do not match.
You can get more information from this StackOverflow description.
I also made a small project that shows the problem: https://github.com/RobbinMarcus/ManagedCudaCustomStruct