codehaus


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ctypes struct alignment specification


I am working on a CUDA python API using ctypes. Within CUDA there are vector type structs defined (float2, float3, float4, int2, int3, int4, ...), all of which have an alignment specification (example of how this is specified https://stackoverflow.com/questions/12778949/cuda-memory-alignment/12779757) . I want to include these structs in the Python api but as far as I can tell, ctypes does not have a way to specify a structure's alignment in the same fashion (the #pragma pack(n) alignment feature that ctypes does support does not do the same thing). If the alignment specification is omitted on the Python side, the structure's alignment can be mismatched between the host (CPU) and device (GPU) causing segfaults/etc. . Is this something that could be added to ctypes or is it not feasible/possible?