DPC++ Runtime
Runtime libraries for oneAPI DPC++
composite_device.cpp
Go to the documentation of this file.
1 //==---------- composite_device.cpp - SYCL Composite Device ----------------==//
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 
10 #include <sycl/platform.hpp>
11 
12 #include <unordered_set>
13 
14 namespace sycl {
15 inline namespace _V1 {
16 namespace ext::oneapi::experimental {
17 std::vector<device> get_composite_devices() {
18  // We use set to filter out duplicates, and unordered because we don't need it
19  // to be sorted, and unordered provides faster insertion.
20  std::unordered_set<device> Composites;
21  auto Devs = sycl::device::get_devices();
22  for (const auto &D : Devs) {
23  if (D.has(sycl::aspect::ext_oneapi_is_component)) {
24  auto Composite = D.get_info<info::device::composite_device>();
25  Composites.insert(Composite);
26  }
27  }
28  std::vector<device> Result;
29  std::copy_if(
30  Composites.begin(), Composites.end(), std::back_inserter(Result),
31  [&](const device &Composite) {
32  auto Components = Composite.get_info<info::device::component_devices>();
33  // Only return composite devices if all of its component
34  // devices are available.
35  return std::all_of(
36  Components.begin(), Components.end(), [&](const device &d) {
37  return std::find(Devs.begin(), Devs.end(), d) != Devs.end();
38  });
39  });
40  return Result;
41 }
42 } // namespace ext::oneapi::experimental
43 } // namespace _V1
44 } // namespace sycl
The SYCL device class encapsulates a single SYCL device on which kernels may be executed.
Definition: device.hpp:64
std::vector< device > get_composite_devices()
Definition: access.hpp:18