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.

43 lines
1.0 KiB

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