DPC++ Runtime
Runtime libraries for oneAPI DPC++
device_filter.hpp
Go to the documentation of this file.
1 //==---------- device_filter.hpp - SYCL device filter descriptor -----------==//
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_types.hpp>
12 #include <sycl/detail/defines.hpp>
13 #include <sycl/info/info_desc.hpp>
14 
15 #include <optional>
16 #include <ostream>
17 #include <string>
18 
19 namespace sycl {
20 inline namespace _V1 {
21 namespace detail {
22 
23 // ---------------------------------------
24 // ONEAPI_DEVICE_SELECTOR support
25 
26 template <typename T>
27 std::ostream &operator<<(std::ostream &os, std::optional<T> const &opt) {
28  return opt ? os << opt.value() : os << "not set ";
29 }
30 
31 // the ONEAPI_DEVICE_SELECTOR string gets broken down into these targets
32 // will will match devices. If the target is negative, such as !opencl:*
33 // then matching devices will not be made available to the user.
34 struct ods_target {
35 public:
36  std::optional<backend> Backend;
37  std::optional<info::device_type> DeviceType;
38 
39  bool HasDeviceWildCard = false;
40  std::optional<int> DeviceNum;
41 
42  bool HasSubDeviceWildCard = false;
43  std::optional<unsigned> SubDeviceNum;
44 
45  bool HasSubSubDeviceWildCard = false; // two levels of sub-devices.
46  std::optional<unsigned> SubSubDeviceNum;
47 
48  bool IsNegativeTarget = false; // used to represent negative filters.
49  // used in filter selector to keep count of the number of devices with
50  // the same Backend and DeviceType.
51  int MatchesSeen = 0;
52 
53  ods_target(backend be) { Backend = be; };
55  friend std::ostream &operator<<(std::ostream &Out, const ods_target &Target);
56 };
57 
59  std::vector<ods_target> TargetList;
60 
61 public:
63  ods_target_list(const std::string &FilterString);
64  std::vector<ods_target> &get() { return TargetList; }
65  bool containsHost();
66  bool backendCompatible(backend Backend);
67 };
68 
69 std::ostream &operator<<(std::ostream &Out, const ods_target &Target);
70 std::vector<ods_target> Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envStr);
71 
72 } // namespace detail
73 } // namespace _V1
74 } // namespace sycl
bool backendCompatible(backend Backend)
std::vector< ods_target > & get()
std::ostream & operator<<(std::ostream &os, std::optional< T > const &opt)
std::vector< ods_target > Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envStr)
Definition: access.hpp:18
std::optional< backend > Backend
std::optional< int > DeviceNum
std::optional< unsigned > SubDeviceNum
std::optional< info::device_type > DeviceType
std::optional< unsigned > SubSubDeviceNum
friend std::ostream & operator<<(std::ostream &Out, const ods_target &Target)