//==============================================================
// Copyright © 2020 Intel Corporation
//
// SPDX-License-Identifier: MIT
// =============================================================

#include <CL/sycl.hpp>

using namespace sycl;
static const int N = 16;
int main() {
  // # define queue which has default device associated for offload
  queue q;
  std::cout << "Device: " << q.get_device().get_info<info::device::name>()
            << std::endl;

  // # Unified Shared Memory Allocation enables data access on host and device
  int *data = malloc_shared<int>(N, q);

  std::cout << "allocated shared memory" << std::endl;
  // # Initialization
  for (int i = 0; i < N; i++) {
    data[i] = i;
  }

  // # Offload parallel computation to device
  q.parallel_for(range<1>(N), [=](id<1> i) { data[i] *= 2; }).wait();

  // # Print Output
  for (int i = 0; i < N; i++)
    std::cout << data[i] << std::endl;

  free(data, q);
  return 0;
}
