Send rtPrintf to standard error stream

Is there a way to direct the output of rtPrintf to the standard error stream (or to any stream other than standard out, for that matter) in OptiX?

I’m working with an application that pipes its standard output stream to a file to be read by another program, so I’d prefer not to write debugging statements to the same stream.

I know this isn’t the answer you’re looking for, but is there a reason you can’t use a regular buffer and output that to cerr?

Specifically, instead of using rtPrintf, store it in an rtBuffer at position launch_index (or something). Then after the trace just copy the buffer back to host and output that to cerr. It’s what I’ve done in the past.

Currently there is no way to do this. It’s a good suggestion though. In the meantime maybe you could prefix all your rtPrintfs with some known prefix and you could split the stream manually.

I agree with both but this is probably the easiest solution right now.

Thanks for the input. I will use a separate output buffer for now.

Prefixing is not as easy as it sounds because the output from the program ends up interleaved with the output from rtPrintf. The prefix might end up separated from the rest of the string by output from elsewhere in the program, even if generated by a single call to rtPrintf.

In the long run, the option to choose an output stream would be nice to have.

This sounds like it could be a bug. Can you explain the interleaving in a little more detail? Is it multiple rtPrintfs that get interleaved? Or rtPrintfs with printf/cout on the host side? Is the app multi-threaded?

Here’s a sample output (truncated):

Called rtPrintf from ray generation program at launch index (288,4)
Called rtPrintf from ray generation program at launch index (289,4)
Called rtPrintf from ray generation program at launch index (290,4)
...
Called rtPrintf from ray generation program at launch index (18,7)
Called rtPrintf from ray generation program at launch index (19,7)
Called rtPrintf from ray generation program at launch index (20,5)
Called rtPrintf from ¡¢¢€¡¡¡ ŸŸžžžœ›™˜——–•”“’‘ŽŒ†€óæáÍÊÈÇÅöòòóó÷õôôõõ÷÷÷ùø÷ööõõôóóóòóóŸŸžžžœ›™˜——–•”“’‘ŽŒ†€óæáÍÊÈÇÅöòòóó÷õôôõõ÷÷÷ùø÷ööõõôóóóòóóóòòñðÐÑÒÓÔÔØÛÝàâãæèëîòóôõ÷úþ€‚ƒ…ˆ‰‹ŒŒŽŽ‘‘“”•–—™šš››œœžžŸ¡¡	
...
[ This is binary image data sent to standard out by the application ]
...
àààáááâââããã䞆ŸŠ °¡€   ŸŸžžœœœ›š˜——–••“’‘Ž‹…òæàÍÊÈÇÅõñ
Þëêéèçåäáàßáãåçéëíêéèçæå倀xƒ„„xœxˆ—x¾„€ˆ„	ƒƒxƒƒ‚‚x‡€§„–€…Ô‚ray generation program at launch index (21,5)
Called rtPrintf from ray generation program at launch index (22,5)
Called rtPrintf from ray generation program at launch index (23,5)
Called rtPrintf from ray generation program at launch index (20,7)
...
Called rtPrintf from ray generation program at launch index (506,2)
Called rtPrintf from ray generation program at launch index (507,2)

The application is single threaded, and none of the binary data is printed until after rtContextLaunch2D returns. There is only a single call to rtPrintf in the code.

Does it help to call std::cout.flush() or fflush( stdout ) before the application prints?

Calling fflush( stdout ) before rtContextLaunch2D() does cause previously printed statements to appear before the text from rtPrintf.

However, calling fflush( stdout ) after rtContextLaunch2D() does not prevent rtPrintf statements from being interleaved with subsequently printed statements as shown above.

What platform is this on? Is it possible for you to send us a repro? If so, send email to Optix-Help@nvidia.com and we will arrange a way for you to send it to us.