Guest User

main.cpp

a guest
Nov 29th, 2013
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "cuda_runtime.h"
  2. #include "device_launch_parameters.h"
  3.  
  4. #include <iostream>
  5.  
  6. #include "Vector.h"
  7.  
  8. using namespace std;
  9.  
  10. extern "C" void CALL_KERNEL(Vector& dev_a, Vector& dev_b, Vector& dev_result);
  11.  
  12. int main()
  13. {
  14. Vector a(5, 4, 3);
  15. Vector b(1, 1, 1);
  16. Vector c;
  17.  
  18. Vector* dev_a;
  19. Vector* dev_b;
  20. Vector* dev_c;
  21.  
  22. cudaMalloc((void**)&dev_a, sizeof(Vector));
  23. cudaMalloc((void**)&dev_b, sizeof(Vector));
  24. cudaMalloc((void**)&dev_c, sizeof(Vector));
  25.  
  26. cudaMemcpy(dev_a, (void*)&a, sizeof(Vector), cudaMemcpyHostToDevice);
  27. cudaMemcpy(dev_a, (void*)&b, sizeof(Vector), cudaMemcpyHostToDevice);
  28. cudaMemcpy(dev_a, (void*)&c, sizeof(Vector), cudaMemcpyHostToDevice);
  29.  
  30. CALL_KERNEL(*dev_a, *dev_b, *dev_c);
  31.  
  32. cudaMemcpy((void*)&c, dev_c, sizeof(Vector), cudaMemcpyDeviceToHost);
  33.  
  34. cudaFree(dev_a);
  35. cudaFree(dev_b);
  36. cudaFree(dev_c);
  37.  
  38. cout << c.x << endl;
  39. }
RAW Paste Data