Hey there, I am trying to pass an array of LightData (LightData*) to my Launch Parameters. My host code initializes an std::vector<LightData> lightData with the corresponding information for each light, and then I pass it to my launch parameters by assigning launchParams.lights = lightData.data(). However, my device code keeps crashing because of an illegal memory access within this LightData array. Before I make the call to OptiXLaunch, I make sure to update the space allocated for the launch parameters on my device by freeing the device_ptr, then reallocating space of size sizeof(launchParams). Could this be because my pipeline’s module is set up by passing the pipelineLaunchParamsVariableName, and at that point it just sees a LightData* in my launch parameter struct, not knowing how many elements the array will contain? What is the correct way to do this?
However, my device code keeps crashing because of an illegal memory access within this LightData array.
The launchParams.lights must be a pointer to GPU device memory. You cannot just assign the host side array pointer to that. That is not visible by the GPU.
Instead you need two more steps: Allocate the device memory with a CUDA runtime or driver API call to get a CUdeviceptr to a sufficiently large memory block.
Then you need to copy your lightData array data from host to device with a CUDA memcpy call.