document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <cuda.h>
  2. #include <stdio.h>
  3.  
  4. __global__ void helloWorld(char* str){
  5.   int idx = blockIdx.x * blockDim.x + threadIdx.x;
  6.   str[idx] += idx;
  7. }
  8.  
  9. int main(int argc, char** argv){
  10.   char str[] = "Hello World";
  11.   for(int i = 0; i < 12; i++){
  12.     str[i] -= i;
  13.   }
  14.  
  15.   char *d_str;
  16.   size_t size = sizeof(str);
  17.   cudaMalloc((void**)&d_str, size);
  18.   cudaMemcpy(d_str, str, size, cudaMemcpyHostToDevice);
  19.  
  20.   dim3 dimGrid(2);
  21.   dim3 dimBlock(6);
  22.  
  23.   helloWorld<<< dimGrid, dimBlock >>>(d_str);
  24.   cudaMemcpy(str, d_str, size, cudaMemcpyDeviceToHost);
  25.   cudaFree(d_str);
  26.  
  27.   printf("%s\\n", str);
  28.  
  29.   return 0;
  30. }
');