Question

I wanted to know if it was possible to write a text file of variables calculated in my program Cuda / Optix. That's variables are in my .cu files and therefore can not be written by the CPU.

No correct solution

OTHER TIPS

As far as I know, it's not possible to perform file I/O from a CUDA kernel. You would need to use cudaMemcpy and copy the data back to host memory, and from there you can write the values to a file.

I have no experience with Optix, but as far as I know, there is no way to write to a file from CUDA. You should download your values to the host in order to store them to a file.

You can use cudaMemcpy( dstPointer, srdPointer, size, cudaMemcpyDeviceToHost); to copy data from the device (GPU) to the host (CPU). See: NVIDIA CUDA Library: cudaMemcpy Be aware that your dstPointer has to be the large enought to store the data!

As the previous answers suggest, it's not possible to write data to a file through CUDA kernels. If your code involves multiple loops, you might be thinking how slow your program would be to transfer and write data on each loop; if so, you should make your data transfer after a given number of loops. In other words, write the file in chunks of multiple loops, not on every single loop.

in optix, you can transfer all your data back to host using buffer, once it is downloaded back to HOST memory you can easily convert the data in csv or txt format

I do not know a way to open a file descriptor and write to it directly from the device; however, I have used rtPrintf1 in OptiX to redirect the output of a program to a file. rtPrintf will allow you to print the contents of variables, etc, and if you prefix your prints with a keyword, you can grep for specific items easily. This strategy is a good way to debug early stage OptiX code and even trace what it is doing to some degree.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top