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 
14 
15 #include <iostream>
16 #include <string>
17 
19 namespace sycl {
20 namespace detail {
21 
22 struct device_filter {
23  backend Backend = backend::all;
25  int DeviceNum = 0;
26  bool HasBackend = false;
27  bool HasDeviceType = false;
28  bool HasDeviceNum = false;
29  int MatchesSeen = 0;
30 
32  device_filter(const std::string &FilterString);
33  friend std::ostream &operator<<(std::ostream &Out,
34  const device_filter &Filter);
35 };
36 
38  std::vector<device_filter> FilterList;
39 
40 public:
42  device_filter_list(const std::string &FilterString);
44  void addFilter(device_filter &Filter);
45  std::vector<device_filter> &get() { return FilterList; }
46  bool backendCompatible(backend Backend);
47  bool deviceTypeCompatible(info::device_type DeviceType);
48  bool deviceNumberCompatible(int DeviceNum);
49  bool containsHost();
50  friend std::ostream &operator<<(std::ostream &Out,
51  const device_filter_list &List);
52 };
53 
54 inline std::ostream &operator<<(std::ostream &Out,
55  const device_filter &Filter) {
56  Out << Filter.Backend << ":";
57  if (Filter.DeviceType == info::device_type::host) {
58  Out << "host";
59  } else if (Filter.DeviceType == info::device_type::cpu) {
60  Out << "cpu";
61  } else if (Filter.DeviceType == info::device_type::gpu) {
62  Out << "gpu";
63  } else if (Filter.DeviceType == info::device_type::accelerator) {
64  Out << "accelerator";
65  } else if (Filter.DeviceType == info::device_type::all) {
66  Out << "*";
67  } else {
68  Out << "unknown";
69  }
70  if (Filter.HasDeviceNum) {
71  Out << ":" << Filter.DeviceNum;
72  }
73  return Out;
74 }
75 
76 inline std::ostream &operator<<(std::ostream &Out,
77  const device_filter_list &List) {
78  for (const device_filter &Filter : List.FilterList) {
79  Out << Filter;
80  Out << ",";
81  }
82  return Out;
83 }
84 
85 } // namespace detail
86 } // namespace sycl
87 } // __SYCL_INLINE_NAMESPACE(cl)
cl::sycl::backend
backend
Definition: backend_types.hpp:21
cl::sycl::detail::device_filter::HasDeviceNum
bool HasDeviceNum
Definition: device_filter.hpp:28
cl::sycl::detail::device_filter
Definition: device_filter.hpp:22
cl::sycl::detail::device_filter_list::get
std::vector< device_filter > & get()
Definition: device_filter.hpp:45
cl::sycl::info::device_type
device_type
Definition: info_desc.hpp:180
sycl
Definition: invoke_simd.hpp:68
cl::sycl::detail::operator<<
std::ostream & operator<<(std::ostream &Out, const device_filter_list &List)
Definition: device_filter.hpp:76
cl::sycl::detail::device_filter::DeviceType
info::device_type DeviceType
Definition: device_filter.hpp:24
cl::sycl::detail::device_filter::device_filter
device_filter()
Definition: device_filter.hpp:31
cl::sycl::detail::device_filter::DeviceNum
int DeviceNum
Definition: device_filter.hpp:25
cl::sycl::detail::device_filter_list
Definition: device_filter.hpp:37
defines.hpp
cl
We provide new interfaces for matrix muliply in this patch:
Definition: access.hpp:13
backend_types.hpp
cl::sycl::detail::device_filter_list::device_filter_list
device_filter_list()
Definition: device_filter.hpp:41
cl::sycl::all
detail::enable_if_t< detail::is_sigeninteger< T >::value, int > all(T x) __NOEXC
Definition: builtins.hpp:1297
info_desc.hpp
cl::sycl::detail::device_filter::Backend
backend Backend
Definition: device_filter.hpp:23
__SYCL_INLINE_NAMESPACE
#define __SYCL_INLINE_NAMESPACE(X)
Definition: defines_elementary.hpp:12