DPC++ Runtime
Runtime libraries for oneAPI DPC++
hip.hpp
Go to the documentation of this file.
1 //==--------- hip.hpp - SYCL HIP backend -----------------------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 #include <sycl/backend.hpp>
12 
13 namespace sycl {
14 inline namespace _V1 {
15 
16 template <>
18 get_native<backend::ext_oneapi_hip, device>(const device &Obj) {
19  // TODO swap with SYCL 2020 exception when in ABI-break window
20  if (Obj.get_backend() != backend::ext_oneapi_hip) {
21  throw sycl::runtime_error(errc::backend_mismatch, "Backends mismatch",
22  PI_ERROR_INVALID_OPERATION);
23  }
24  // HIP uses a 32-bit int instead of an opaque pointer like other backends,
25  // so we need a specialization with static_cast instead of reinterpret_cast.
27  Obj.getNative());
28 }
29 
30 template <>
31 inline device make_device<backend::ext_oneapi_hip>(
34  for (auto &dev : devs) {
35  if (dev.get_backend() == backend::ext_oneapi_hip &&
36  BackendObject == get_native<backend::ext_oneapi_hip>(dev)) {
37  return dev;
38  }
39  }
40  // The ext_oneapi_hip platform(s) adds all n available devices where n
41  // is returned from call to `hipGetDeviceCount`.
42  // Hence if this code is reached then the requested device ordinal must
43  // not be visible to the driver.
45  "Native device has an invalid ordinal.");
46 }
47 
48 } // namespace _V1
49 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
static std::vector< device > get_devices(info::device_type deviceType=info::device_type::all)
Query available SYCL devices.
Definition: device.cpp:51
backend get_backend() const noexcept
Returns the backend associated with this device.
Definition: device.cpp:215
typename backend_traits< Backend >::template return_type< SyclType > backend_return_t
Definition: backend.hpp:87
std::error_code make_error_code(sycl::errc E) noexcept
Constructs an error code using e and sycl_category()
Definition: exception.cpp:87
typename backend_traits< Backend >::template input_type< SyclType > backend_input_t
Definition: backend.hpp:83
Definition: access.hpp:18