|
|
Example:
int main()
{
/* ------------------------------------
Call the hello( ) kernel function
------------------------------------ */
hello<<< 1, 4 >>>( ); // Asynchronous !!!
printf("I am the CPU: Hello World ! \n");
return 0;
}
|
Effect:
|
cudaDeviceSynchronize();
This call will forces the CPU to wait until all preceeding
command/function calls on the GPU have completed
|
#include <stdio.h>
#include <unistd.h>
__global__ void hello( )
{
printf("Hello World !\n");
}
int main()
{
hello<<< 1, 4 >>>( );
printf("I am the CPU: Hello World ! \n");
// Try moving the "printf" statement
// after cudaDeviceSynchronize()
cudaDeviceSynchronize();
return 0;
}
|
/home/cs355001/demo/CUDA/1-intro/hello-sync
Output:
I am the CPU: Hello World !
Hello World !
Hello World !
Hello World !
Hello World !
|