Last active
August 30, 2022 23:42
-
-
Save ShangjinTang/a1c9322c1fbfdbbaf9669aa85ef402ce to your computer and use it in GitHub Desktop.
CUDA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include "cuda.h" | |
__global__ | |
void loop_on_device() | |
{ | |
printf("Device(GPU) iteration number %d\n", blockIdx.x * blockDim.x + threadIdx.x); | |
} | |
void loop_on_host(int length) | |
{ | |
for (int i = 0; i < length; ++i) { | |
printf("Host(CPU) iteration number %d\n", i); | |
} | |
} | |
int main() | |
{ | |
int block_size = 3; | |
int kernel_size = 4; | |
loop_on_device<<<block_size, kernel_size>>>(); | |
int n = block_size * kernel_size; | |
loop_on_host(n); | |
cudaDeviceSynchronize(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment