-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathdpctl_sycl_device_selector_interface.cpp
More file actions
116 lines (105 loc) · 3.61 KB
/
Copy pathdpctl_sycl_device_selector_interface.cpp
File metadata and controls
116 lines (105 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//=== dpctl_sycl_device_selector_interface.cpp - device_selector C API ===//
//
// Data Parallel Control (dpctl)
//
// Copyright 2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Implements constructors for SYCL's device selector classes.
///
//===----------------------------------------------------------------------===//
#include "dpctl_sycl_device_selector_interface.h"
#include "Config/dpctl_config.h"
#include "dpctl_device_selection.hpp"
#include "dpctl_error_handlers.h"
#include "dpctl_sycl_type_casters.hpp"
#include <sycl/sycl.hpp> /* SYCL headers */
using namespace sycl;
namespace
{
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
"The compiler does not meet minimum version requirement");
using namespace dpctl::syclinterface;
} // end of anonymous namespace
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create()
{
try {
auto Selector = new dpctl_accelerator_selector();
return wrap<dpctl_device_selector>(Selector);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create()
{
try {
auto Selector = new dpctl_default_selector();
return wrap<dpctl_device_selector>(Selector);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create()
{
try {
auto Selector = new dpctl_cpu_selector();
return wrap<dpctl_device_selector>(Selector);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclDeviceSelectorRef
DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str)
{
using filter_selector_t = dpctl_filter_selector;
try {
auto Selector = new filter_selector_t(filter_str);
return wrap<dpctl_device_selector>(Selector);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
}
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create()
{
try {
auto Selector = new dpctl_gpu_selector();
return wrap<dpctl_device_selector>(Selector);
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
return nullptr;
}
}
int DPCTLDeviceSelector_Score(__dpctl_keep DPCTLSyclDeviceSelectorRef DSRef,
__dpctl_keep DPCTLSyclDeviceRef DRef)
{
static constexpr int REJECT_DEVICE_SCORE = -1;
if (DSRef && DRef) {
auto dev = *(unwrap<device>(DRef));
return (*unwrap<dpctl_device_selector>(DSRef))(dev);
}
else
return REJECT_DEVICE_SCORE;
}
void DPCTLDeviceSelector_Delete(__dpctl_take DPCTLSyclDeviceSelectorRef DSRef)
{
auto Selector = unwrap<dpctl_device_selector>(DSRef);
delete Selector;
}