How is it possible to print to file on the device?

I’d like to fprintf or similar to file from the device instead of taking screenshots of printf writes fron the device. Is this possible?

printf in CUDA writes to stdout (once the kernel execution has completed).

The stdout stream can be redirected to a file or piped into other tools.

Please inform yourself about redirection of console output into files. It is a basic feature of every major command shell on Linux (or Unix) and Windows.

Also see this related stackOverflow topic: