1

We can do printf in kernels now, but is it possible to use the

sprintf(buffer, format, arg, ... )

function?

I'm doing CUDA-accelerated OBJ file writing, and I need to convert floats into ASCII strings for writing.

Edit: CUDA is not doing the actual writing of course =) Just generating the obj char buffers from a list of floats.

paleonix
  • 2,293
  • 1
  • 13
  • 29
randyrand
  • 433
  • 1
  • 4
  • 9
  • 2
    CUDA is not likely to accelerate the actual process of writing files. In any event, there is no `sprintf` -- you would have to implement your own if you wanted to do it from a CUDA kernel. Older cuda toolkits (e.g. CUDA 6.5 and before) included a "simplePrintf" sample code that might be useful. – Robert Crovella Apr 27 '16 at 01:20
  • I'm also pretty certain that most of the string translation work associated with printf is done on the host after a kernel is completed – talonmies Apr 27 '16 at 06:43
  • 1
    1. Does this answer your question? [CUDA: sprintf like function for \_\_device\_\_ code](https://stackoverflow.com/questions/34122798/cuda-sprintf-like-function-for-device-code) 2. The GPU is probably not the place to produce the characters you intend to output. – einpoklum Oct 20 '21 at 16:49

1 Answers1

1

Besides the va_list, the code from Georges Menie should help you get started. Also, for simple argument list, simplePrintf exposed a few as @RobertCrovella mentioned. C++11 features of recent CUDA distributions might also help.

However, parallelisation of this task on the GPU and maintaining consistency in object list indices and consistent string formatting (floatting point especially) might be your biggest issue.

Florent DUGUET
  • 2,786
  • 16
  • 28
  • Thank you. As for your second point, I'm lucky I'm only writing triangle lists. The 'faces' are just > f 1 2 3 > f 4 5 6 > f 7 8 9 – randyrand Apr 27 '16 at 18:49
  • My thinking is, since I have a fast ~500MB per second SSD, the bottle neck will likely be the CPU converting their of floats to the 'v x.xxxx y.yyyy z.zzzz' format for writing - given that 500MB per second is 62,500,000 float conversions a second. The GPU should be able to easily handle this task of converting a float list to a 'v x.xxxx y.yyyy z.zzzz' char buffer. That said, it will likely nearly saturate the SDD write speed either way. – randyrand Apr 27 '16 at 18:58
  • I added a piece of code to the appropriate question on how to access disk directly from GPU. I believe this might help: http://stackoverflow.com/a/36899573/6218300 . This applies to your use-case as your bottleneck is string formatting, and CPU would be solely responsible for paging management. – Florent DUGUET Apr 27 '16 at 19:51
  • That's an interesting idea. Thanks. – randyrand Apr 27 '16 at 19:59