fna
June 23, 2010, 10:16pm
#1
Instead of having my threads write to the console window, is there a way to have them write to file?
I normally use:
FILE * FP;
fp=freopen("c:\Text.txt", "w" ,stdout);
And that directs all my printfs to file while on the host, but any printf call I make while in a kernel just gets lost; it doesn’t get output to the console or to the file.
I couldn’t find anything in the programming guide or the reference guide…
Any ideas?
Thanks!
(GTX 480, SDK 3.1, XPx64)
No I/O of any kind is possible in a kernel which runs on a device (as opposed to emulation mode).
Get with the times, real device-side printf exists in 3.1. :)
There’s currently no way to redirect the output, though.
fna
June 23, 2010, 10:32pm
#4
Thanks guys. Yep, It’s new with the 3.1.
From the Program Guide (3.1beta)
B.13 Formatted Output
Formatted output is only supported by devices of compute capability 2.0.
int printf(const char *format[, arg, …]);
prints formatted output from a kernel to a host-side output stream.
The in-kernel printf() function behaves in a similar way to the standard C-library
printf() function, and the user is referred to manual pages for a
complete description of printf() behavior. In essence, the string passed in as
format is output to a stream on the host, with substitutions made from the
argument list wherever a format specifier is encountered. Supported format
specifiers are listed below.
The printf() command is executed as any other device-side function: per-thread,
and in the context of the calling thread. From a multi-threaded kernel, this means
that a straightforward call to printf() will be executed by every thread, using that
the host stream, once for each thread which encountered the printf().
It is up to the programmer to limit the output to a single thread if only a single
output string is desired (see Section B.13.4 for an illustrative example).
Guess I’ll wait for 3.2 for the redirect ability :D
Mea Cupla. Trying to finish my habilitation monograph at the moment and not coding much beyond python for making figures. Haven’t even looked at the 3.1 beta, beyond installing it at the same time I got my Fermi hardware (half of which is still in the box)…
I haven’t used 3.1’s printf, but with the cuPrintf library its pretty simple to use an stream different to stdout AFAIK…
wumpus
June 28, 2010, 1:31pm
#7
Stone age debugging goes GPU, oh no :)