Why do I need to include <stdio.h> to use CUDA's printf()?

einpoklum

I want to printf() something in my CUDA kernel. [The Programming Guide suggests][1] I do this like so:

#include <stdio.h>

__global__ void helloCUDA(float f)
{
    printf("Hello thread %d, f=%f\n", threadIdx.x, f);
}

But this is simply including the standard C library's stdio.h. Why would that be necessary? CUDA's printf() doesn't have the same behavior of stdio's printf(); and I certainly don't need most of everything else that's in there.

talonmies

It's an implementation detail you don't need to know about which stems from limitations in the CUDA syntax (basically it is illegal to define different __device__ and __host__ versions of the same function).

The standard library prototype is used as a proxy in device code during compilation, and when compiling for a supported architecture, some sneaky template overloading is used to insert the device implementation into the device code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why do I need to include <stdio.h> to use CUDA's printf()?

From Dev

Why use .gitignore? And why do I need to not include certain files?

From Dev

Why do both "std::printf" and "printf" compile when using <cstdio> rather than <stdio.h> in C++?

From Dev

How do I get CUDA's printf to print to an arbitrary stream?

From Dev

How do I get CUDA's printf to print to an arbitrary stream?

From Dev

What does '#include <stdio.h>' really do in a C program

From Dev

Why do i need to use minitest/autorun?

From Dev

Why do I need depthBuffer to use RenderTexture?

From Dev

Why do i need NOT use the namespace?

From Dev

Why do I need to use locks with semaphore

From Dev

Why do i need NOT use the namespace?

From Dev

Why do I need to use chroot

From Dev

Why do I need to #include <typeinfo> when using the typeid operator?

From Dev

Why do I need to include .o files when compiling?

From Dev

Why do I need to include .o files when compiling?

From Dev

Why do I need to include EOF in my loop condition?

From Dev

Why do we use `#include "stdafx.h"` instead of `#include <stdafx.h>`?

From Dev

why do I need to patch linux kernel to use pandaboard's spi?

From Dev

How do I detect if stdio.h is included?

From Dev

a.h is included in b.h and I include b.h in my source file, do I need to include a.h in my source file as well?

From Dev

Why do I need to declare the type of a function everywhere I use it?

From Dev

Why do I need to redefine a String if I use the method replace?

From Java

Why do projects use the -I include switch given the dangers?

From Dev

Is it correct to drop #include <stdio.h> in C?

From Dev

Why when I write with Rcpp I do not need to include some libraries which I should include writing in plain C++?

From Dev

Why do I need to use type** to point to type*?

From Dev

Why do I need to use angular.copy in my factory?

From Java

Why do I need to copy an array to use a method on it?

From Dev

jQuery / JavaScript, why do I need to wrap variables in $() to use them?

Related Related

  1. 1

    Why do I need to include <stdio.h> to use CUDA's printf()?

  2. 2

    Why use .gitignore? And why do I need to not include certain files?

  3. 3

    Why do both "std::printf" and "printf" compile when using <cstdio> rather than <stdio.h> in C++?

  4. 4

    How do I get CUDA's printf to print to an arbitrary stream?

  5. 5

    How do I get CUDA's printf to print to an arbitrary stream?

  6. 6

    What does '#include <stdio.h>' really do in a C program

  7. 7

    Why do i need to use minitest/autorun?

  8. 8

    Why do I need depthBuffer to use RenderTexture?

  9. 9

    Why do i need NOT use the namespace?

  10. 10

    Why do I need to use locks with semaphore

  11. 11

    Why do i need NOT use the namespace?

  12. 12

    Why do I need to use chroot

  13. 13

    Why do I need to #include <typeinfo> when using the typeid operator?

  14. 14

    Why do I need to include .o files when compiling?

  15. 15

    Why do I need to include .o files when compiling?

  16. 16

    Why do I need to include EOF in my loop condition?

  17. 17

    Why do we use `#include "stdafx.h"` instead of `#include <stdafx.h>`?

  18. 18

    why do I need to patch linux kernel to use pandaboard's spi?

  19. 19

    How do I detect if stdio.h is included?

  20. 20

    a.h is included in b.h and I include b.h in my source file, do I need to include a.h in my source file as well?

  21. 21

    Why do I need to declare the type of a function everywhere I use it?

  22. 22

    Why do I need to redefine a String if I use the method replace?

  23. 23

    Why do projects use the -I include switch given the dangers?

  24. 24

    Is it correct to drop #include <stdio.h> in C?

  25. 25

    Why when I write with Rcpp I do not need to include some libraries which I should include writing in plain C++?

  26. 26

    Why do I need to use type** to point to type*?

  27. 27

    Why do I need to use angular.copy in my factory?

  28. 28

    Why do I need to copy an array to use a method on it?

  29. 29

    jQuery / JavaScript, why do I need to wrap variables in $() to use them?

HotTag

Archive