|
| 1 | +//===-- dpctl_device_selection.h - Device selector class declar. --*-C++-*- =// |
| 2 | +// |
| 3 | +// |
| 4 | +// Data Parallel Control (dpctl) |
| 5 | +// |
| 6 | +// Copyright 2020-2022 Intel Corporation |
| 7 | +// |
| 8 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | +// you may not use this file except in compliance with the License. |
| 10 | +// You may obtain a copy of the License at |
| 11 | +// |
| 12 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +// |
| 14 | +// Unless required by applicable law or agreed to in writing, software |
| 15 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +// See the License for the specific language governing permissions and |
| 18 | +// limitations under the License. |
| 19 | +// |
| 20 | +//===----------------------------------------------------------------------===// |
| 21 | +/// |
| 22 | +/// \file |
| 23 | +/// This file declares classes for device selection. |
| 24 | +/// |
| 25 | +//===----------------------------------------------------------------------===// |
| 26 | + |
| 27 | +#pragma once |
| 28 | + |
| 29 | +#include "Config/dpctl_config.h" |
| 30 | +#include "Support/DllExport.h" |
| 31 | +#include <CL/sycl.hpp> |
| 32 | + |
| 33 | +namespace dpctl |
| 34 | +{ |
| 35 | +namespace syclinterface |
| 36 | +{ |
| 37 | + |
| 38 | +#if __SYCL_COMPILER_VERSION >= __SYCL_COMPILER_2023_SWITCHOVER |
| 39 | + |
| 40 | +class DPCTL_API dpctl_device_selector |
| 41 | +{ |
| 42 | +public: |
| 43 | + virtual ~dpctl_device_selector() = default; |
| 44 | + static constexpr int REJECT_DEVICE = -1; |
| 45 | + virtual int operator()(const sycl::device &) const; |
| 46 | +}; |
| 47 | + |
| 48 | +class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector |
| 49 | +{ |
| 50 | +public: |
| 51 | + dpctl_accelerator_selector() = default; |
| 52 | + int operator()(const sycl::device &d) const override; |
| 53 | +}; |
| 54 | + |
| 55 | +class DPCTL_API dpctl_default_selector : public dpctl_device_selector |
| 56 | +{ |
| 57 | +public: |
| 58 | + dpctl_default_selector() = default; |
| 59 | + int operator()(const sycl::device &d) const override; |
| 60 | +}; |
| 61 | + |
| 62 | +class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector |
| 63 | +{ |
| 64 | +public: |
| 65 | + dpctl_gpu_selector() = default; |
| 66 | + int operator()(const sycl::device &d) const override; |
| 67 | +}; |
| 68 | + |
| 69 | +class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector |
| 70 | +{ |
| 71 | +public: |
| 72 | + dpctl_cpu_selector() = default; |
| 73 | + int operator()(const sycl::device &d) const override; |
| 74 | +}; |
| 75 | + |
| 76 | +class DPCTL_API dpctl_filter_selector : public dpctl_device_selector |
| 77 | +{ |
| 78 | +public: |
| 79 | + dpctl_filter_selector(const std::string &fs) : _impl(fs) {} |
| 80 | + int operator()(const sycl::device &d) const override; |
| 81 | + |
| 82 | +private: |
| 83 | + sycl::ext::oneapi::filter_selector _impl; |
| 84 | +}; |
| 85 | + |
| 86 | +class DPCTL_API dpctl_host_selector : public dpctl_device_selector |
| 87 | +{ |
| 88 | +public: |
| 89 | + dpctl_host_selector() = default; |
| 90 | + int operator()(const sycl::device &) const override; |
| 91 | +}; |
| 92 | + |
| 93 | +#else |
| 94 | + |
| 95 | +class DPCTL_API dpctl_device_selector : public sycl::device_selector |
| 96 | +{ |
| 97 | +public: |
| 98 | + virtual ~dpctl_device_selector() = default; |
| 99 | + |
| 100 | + virtual int operator()(const sycl::device &device) const = 0; |
| 101 | +}; |
| 102 | + |
| 103 | +class DPCTL_API dpctl_accelerator_selector : public dpctl_device_selector |
| 104 | +{ |
| 105 | +public: |
| 106 | + dpctl_accelerator_selector() : _impl(){}; |
| 107 | + int operator()(const sycl::device &d) const override; |
| 108 | + |
| 109 | +private: |
| 110 | + sycl::accelerator_selector _impl; |
| 111 | +}; |
| 112 | + |
| 113 | +class DPCTL_API dpctl_default_selector : public dpctl_device_selector |
| 114 | +{ |
| 115 | +public: |
| 116 | + dpctl_default_selector() : _impl(){}; |
| 117 | + int operator()(const sycl::device &d) const override; |
| 118 | + |
| 119 | +private: |
| 120 | + sycl::default_selector _impl; |
| 121 | +}; |
| 122 | + |
| 123 | +class DPCTL_API dpctl_gpu_selector : public dpctl_device_selector |
| 124 | +{ |
| 125 | +public: |
| 126 | + dpctl_gpu_selector() : _impl(){}; |
| 127 | + int operator()(const sycl::device &d) const override; |
| 128 | + |
| 129 | +private: |
| 130 | + sycl::gpu_selector _impl; |
| 131 | +}; |
| 132 | + |
| 133 | +class DPCTL_API dpctl_cpu_selector : public dpctl_device_selector |
| 134 | +{ |
| 135 | +public: |
| 136 | + dpctl_cpu_selector() : _impl(){}; |
| 137 | + int operator()(const sycl::device &d) const override; |
| 138 | + |
| 139 | +private: |
| 140 | + sycl::cpu_selector _impl; |
| 141 | +}; |
| 142 | + |
| 143 | +class DPCTL_API dpctl_filter_selector : public dpctl_device_selector |
| 144 | +{ |
| 145 | +public: |
| 146 | + dpctl_filter_selector(const std::string &fs) : _impl(fs) {} |
| 147 | + |
| 148 | + int operator()(const sycl::device &d) const override; |
| 149 | + |
| 150 | +private: |
| 151 | + sycl::ext::oneapi::filter_selector _impl; |
| 152 | +}; |
| 153 | + |
| 154 | +class DPCTL_API dpctl_host_selector : public dpctl_device_selector |
| 155 | +{ |
| 156 | +public: |
| 157 | + dpctl_host_selector() : _impl(){}; |
| 158 | + int operator()(const sycl::device &d) const override; |
| 159 | + |
| 160 | +private: |
| 161 | + sycl::host_selector _impl; |
| 162 | +}; |
| 163 | + |
| 164 | +#endif |
| 165 | + |
| 166 | +} // namespace syclinterface |
| 167 | +} // namespace dpctl |
0 commit comments