Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include "cuda.h"
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. __global__ void fp_test(int a, int b, float c)
  6. {
  7. int val_gpu = ceilf( (a+b) * c / (1.0f+c) );
  8. printf("gpu: %dn", val_gpu);
  9. }
  10.  
  11. int main()
  12. {
  13. int a = 5;
  14. int b = 4;
  15. float c = 0.8;
  16.  
  17. fp_test<<<1,1>>>(a, b, c);
  18. cudaDeviceSynchronize();
  19.  
  20. int val_cpu = ceilf( (a+b) * c / (1.0+c) );
  21. printf("cpu: %dn", val_cpu);
  22. }
  23.  
  24. $ nvcc -arch=sm_20 gpu_fp_test.cu -o gpu_fp_test
  25. $ gpu_fp_test
  26. gpu: 5
  27. cpu: 4
  28.  
  29. int val_gpu = ceilf( (a+b) * c / (1.0+c) );
  30. ^
  31. remove f from constant
  32.  
  33. int val_cpu = ceilf( (a+b) * c / (1.0f+c) );
  34. ^
  35. add f to constant
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement