Advertisement
Guest User

Untitled

a guest
Oct 20th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. $ cat t263.cu
  2. #include <stdio.h>
  3.  
  4. #define cudaCheckErrors(msg) \
  5. do { \
  6. cudaError_t __err = cudaGetLastError(); \
  7. if (__err != cudaSuccess) { \
  8. fprintf(stderr, "Fatal error: %s (%s at %s:%d)\n", \
  9. msg, cudaGetErrorString(__err), \
  10. __FILE__, __LINE__); \
  11. fprintf(stderr, "*** FAILED - ABORTING\n"); \
  12. exit(1); \
  13. } \
  14. } while (0)
  15.  
  16. int main(){
  17. int capacity = 1048576;
  18. float* data_t = 0;
  19. float* data = 0;
  20.  
  21. size_t msize = sizeof(float) * capacity;
  22. cudaHostAlloc((void**)&data_t, msize, cudaHostAllocPortable);
  23. cudaCheckErrors("cudaHostAlloc 1 fail");
  24. cudaHostAlloc((void**)&data, msize, cudaHostAllocPortable);
  25. cudaCheckErrors("cudaHostAlloc 2 fail");
  26. cudaMemcpy(data_t, data, msize, cudaMemcpyDefault);
  27. cudaCheckErrors("cudaMemcpy fail");
  28. printf("success\n");
  29. return 0;
  30. }
  31. $ nvcc -arch=sm_20 -o t263 t263.cu
  32. $ ./t263
  33. success
  34. $ uname -a
  35. Linux cluster1 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:14 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
  36. $ nvcc --version
  37. nvcc: NVIDIA (R) Cuda compiler driver
  38. Copyright (c) 2005-2012 NVIDIA Corporation
  39. Built on Fri_Sep_21_17:28:58_PDT_2012
  40. Cuda compilation tools, release 5.0, V0.2.1221
  41. $
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement