You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1000 B

3 years ago
  1. // Patric Zhao: patric.zhao@intel.com
  2. #include <CL/sycl.hpp>
  3. #include <iostream>
  4. using namespace sycl;
  5. constexpr int N = 10;
  6. int main() {
  7. queue my_gpu_queue( gpu_selector{} );
  8. std::cout << "Selected GPU device: " <<
  9. my_gpu_queue.get_device().get_info<info::device::name>() << "\n";
  10. int *host_mem = malloc_host<int>(N, my_gpu_queue);
  11. int *device_mem = malloc_device<int>(N, my_gpu_queue);
  12. // Init CPU data
  13. for(int i = 0; i < N; i++) {
  14. host_mem[i] = i;
  15. }
  16. // Copy from host(CPU) to device(GPU)
  17. my_gpu_queue.memcpy(device_mem, host_mem, N * sizeof(int)).wait();
  18. // do some works on GPU
  19. // ......
  20. //
  21. // Copy back from GPU to CPU
  22. my_gpu_queue.memcpy(host_mem, device_mem, N * sizeof(int)).wait();
  23. printf("\nData Result\n");
  24. for(int i = 0; i < N; i++) {
  25. printf("%d, ", host_mem[i]);
  26. }
  27. printf("\nTask Done!\n");
  28. return 0;
  29. }