Buffer element size mismatch?


I am working on a spectral ray tracing program as a part of my diploma thesis. Implementation is made (obvoiusly) using OptiX. However, I have encountered an error I just cannot resolve. It is element size mismatch in buffer vs ptx file, exactly: “Buffer ‘material_buffer’ element size(1008) does not match ptx(1004).”. I have no idea where those 4 bytes can vanish and even after few weeks I found no cause nor solution. Does anybody have an idea why it might happen?

Thanks for any tips.

EDIT: I forgot to mention I am using VS2010 and OptiX 3.0.1

CUDA has some alignment restrictions for the built-in vector types. They should be listed in a table inside the CUDA Programming Guide. Make sure your structure elements are padded correctly. Maybe try to make the structure size 16 bytes aligned (1008 is, 1004 isn’t).

Thanks for reply. Problem is, real size of my structure is the mentioned 1008 bytes. Only the generated PTX files “lose 4 bytes” somewhere. I have even tried padding to 1024 bytes, yet 4 bytes were missing again in PTX. This is my definition:

struct MaterialData
  string name_;       // Material name
  eBRDF brdf_type_;   // Type of BRDF of material
  float color_[81];   // Material color
  float n_data_[81];  // Material index of refraction
  float k_data_[81];  // Material extinction coefficient

First I thought it might be the eBRDF enum messing it up, since it’s size is 4 bytes. I tried placing an integer instead with no effect. My second thought is the string, but changing it to, let’s say, char4, would require quite large refactor of my actual code. Which might be necessary it seems.

Is that a C++ std::string? Yes, that seems like a bad idea. I have no experience how that would translate to PTX, never used. Material definitions don’t normally contain strings on the GPU side.
(You could easily identify a specific MaterialData with a unique integer ID and resolve that to a name with a map or vector elsewhere inside the application.)
When removing the name for the Buffer element description just as an experiment, do you get the remaining 976 bytes then?

Yes, it was C++ std::string. I removed it, used vector of strings instead and problem is gone. Now to change rest of code to make it working again :) If I might suggest, add a note about using strings in CUDA. I have not found it in the progamming guide, unless I have missed it, which is also possible. Anyway, thanks a lot for help, now I can get moving again :)