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>
13 
14 namespace sycl {
15 inline namespace _V1 {
16 
17 template <>
19 get_native<backend::ext_oneapi_hip, device>(const device &Obj) {
20  if (Obj.get_backend() != backend::ext_oneapi_hip) {
21  throw exception(errc::backend_mismatch, "Backends mismatch");
22  }
23  // HIP uses a 32-bit int instead of an opaque pointer like other backends,
24  // so we need a specialization with static_cast instead of reinterpret_cast.
26  Obj.getNative());
27 }
28 
29 template <>
30 inline device make_device<backend::ext_oneapi_hip>(
33  for (auto &dev : devs) {
34  if (dev.get_backend() == backend::ext_oneapi_hip &&
35  BackendObject == get_native<backend::ext_oneapi_hip>(dev)) {
36  return dev;
37  }
38  }
39  // The ext_oneapi_hip platform(s) adds all n available devices where n
40  // is returned from call to `hipGetDeviceCount`.
41  // Hence if this code is reached then the requested device ordinal must
42  // not be visible to the driver.
44  "Native device has an invalid ordinal.");
45 }
46 
47 } // namespace _V1
48 } // 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:53
backend get_backend() const noexcept
Returns the backend associated with this device.
Definition: device.cpp:203
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:65
typename backend_traits< Backend >::template input_type< SyclType > backend_input_t
Definition: backend.hpp:83
Definition: access.hpp:18