Will printf inside a kernel work on other language/compilers ? Possible replacement ?


I think the real “HelloWorld” for cuda would be:

global kernel()


printf(“Hello World !\n”);


However according to the manual, the formatting of printf depends on the host compiler/operating system.

So I now wonder if this printf will work on for example another compiler/language like Delphi ?!?

If not then a replacement could be designed for CUDA Driver API which would work something like this:

printf would be replaced with

OutputString( “Hello World !\n” );

Plus perhaps any other version of this function that you can conceive that might have parameter support as well, perhaps by a list of memory which can contain integers or floats or even more strings.

And then every data structure would have the following fieldS:


OutputStringParameterType (enum)   osp_float / osp_integer / osp_ansi_character / osp_double

OutputStringParameterSize (int)            4 /           4 /                  1 /          8

OutputStringParameterCount(int)            1 /           1 /           Variable /          1


TOutputStringParameterTypeEnum =







struct TOutputStringParameterStructure


  TOutputStringParameterTypeEnum mType;

  int mSize;

  int mCount;


usage example:

TOutputStringParameterStructure mParameter[10];

// or

TOutputStringParameterStructure *mParameter;

mParameter[0].mType = osp_float; 

  mParameter[0].mSize = 4;

  mParameter[0].mCount = 1;

Count could also be used as an array size.

This parameter structure would be proceeded by:

OutputStringParameterArray // array of OutputStringParameterStructurePointers

OutputStringParameterArraySize // size of array

So such an advanced function (variable) would look like:

OutputString( ParaMainString, the rest );

or to prevent this weird inconsistencies it would instead directly go to the data structure:

OutputString( OutputStringParameterArray *ParameterArray, OutputStringParameterArraySize ParameterArraySize );

This is not how the kernel user would use it…

The kernel user would simply write:

printf(“whatever”, whatever);

The cuda compiler would then convert this call to a call to OutputString function variable above.

Other languages can now call the following functions to set the output string function variable/callback.

SetOutputStringVariable( @OutputStringFunctionVariable );

Then the host user can simply implement OutputStringFunction himself and provide a variable/callback towards it.

Then the host user can simply use the language’s/compiler’s string printing functions to do the rest ! ;) =D

(This posting was writing by listening to music lol, which might or might not have affected this posting LOL ;) :) I think it’s ok ;) :))

(Ok I think this is enough… this should give you some idea of what I’m looking for ;) :))