Skip to content

Commit 2c86ef6

Browse files
Merge pull request #960 from IntelPython/header-for-DPCTLSyclInterface-type-casters
Header for dpctl sycl interface type casters
2 parents bab5d10 + e28769a commit 2c86ef6

33 files changed

+830
-453
lines changed

libsyclinterface/helper/source/dpctl_utils_helper.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//===----------------------------------------------------------------------===//
2525

2626
#include "dpctl_utils_helper.h"
27+
#include "Config/dpctl_config.h"
2728
#include <sstream>
2829
#include <string>
2930

@@ -48,9 +49,11 @@ std::string DPCTL_DeviceTypeToStr(info::device_type devTy)
4849
case info::device_type::custom:
4950
ss << "custom";
5051
break;
52+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
5153
case info::device_type::host:
5254
ss << "host";
5355
break;
56+
#endif
5457
default:
5558
ss << "unknown";
5659
}
@@ -90,8 +93,10 @@ backend DPCTL_DPCTLBackendTypeToSyclBackend(DPCTLSyclBackendType BeTy)
9093
switch (BeTy) {
9194
case DPCTLSyclBackendType::DPCTL_CUDA:
9295
return backend::ext_oneapi_cuda;
96+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
9397
case DPCTLSyclBackendType::DPCTL_HOST:
9498
return backend::host;
99+
#endif
95100
case DPCTLSyclBackendType::DPCTL_LEVEL_ZERO:
96101
return backend::ext_oneapi_level_zero;
97102
case DPCTLSyclBackendType::DPCTL_OPENCL:
@@ -108,8 +113,10 @@ DPCTLSyclBackendType DPCTL_SyclBackendToDPCTLBackendType(backend B)
108113
switch (B) {
109114
case backend::ext_oneapi_cuda:
110115
return DPCTLSyclBackendType::DPCTL_CUDA;
116+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
111117
case backend::host:
112118
return DPCTLSyclBackendType::DPCTL_HOST;
119+
#endif
113120
case backend::ext_oneapi_level_zero:
114121
return DPCTLSyclBackendType::DPCTL_LEVEL_ZERO;
115122
case backend::opencl:
@@ -170,9 +177,11 @@ std::string DPCTL_AspectToStr(aspect aspectTy)
170177
{
171178
std::stringstream ss;
172179
switch (aspectTy) {
180+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
173181
case aspect::host:
174182
ss << "host";
175183
break;
184+
#endif
176185
case aspect::cpu:
177186
ss << "cpu";
178187
break;
@@ -242,12 +251,14 @@ std::string DPCTL_AspectToStr(aspect aspectTy)
242251
aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
243252
{
244253
aspect aspectTy;
245-
if (aspectTyStr == "host") {
246-
aspectTy = aspect::host;
247-
}
248-
else if (aspectTyStr == "cpu") {
254+
if (aspectTyStr == "cpu") {
249255
aspectTy = aspect::cpu;
250256
}
257+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
258+
else if (aspectTyStr == "host") {
259+
aspectTy = aspect::host;
260+
}
261+
#endif
251262
else if (aspectTyStr == "gpu") {
252263
aspectTy = aspect::gpu;
253264
}
@@ -312,8 +323,10 @@ aspect DPCTL_StrToAspectType(const std::string &aspectTyStr)
312323
aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
313324
{
314325
switch (AspectTy) {
326+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
315327
case DPCTLSyclAspectType::host:
316328
return aspect::host;
329+
#endif
317330
case DPCTLSyclAspectType::cpu:
318331
return aspect::cpu;
319332
case DPCTLSyclAspectType::gpu:
@@ -360,8 +373,10 @@ aspect DPCTL_DPCTLAspectTypeToSyclAspect(DPCTLSyclAspectType AspectTy)
360373
DPCTLSyclAspectType DPCTL_SyclAspectToDPCTLAspectType(aspect Aspect)
361374
{
362375
switch (Aspect) {
376+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
363377
case aspect::host:
364378
return DPCTLSyclAspectType::host;
379+
#endif
365380
case aspect::cpu:
366381
return DPCTLSyclAspectType::cpu;
367382
case aspect::gpu:
@@ -487,9 +502,11 @@ std::string DPCTL_GetDeviceFilterString(const device &Device)
487502
case backend::opencl:
488503
ss << "opencl";
489504
break;
505+
#if __SYCL_COMPILER_VERSION < __SYCL_COMPILER_2023_SWITCHOVER
490506
case backend::host:
491507
ss << "host";
492508
break;
509+
#endif
493510
default:
494511
ss << "unknown";
495512
};

libsyclinterface/include/Config/dpctl_config.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
#cmakedefine DPCTL_ENABLE_L0_PROGRAM_CREATION \
3030
@DPCTL_ENABLE_L0_PROGRAM_CREATION@
3131

32+
/* Version of SYCL DPC++ 2023 compiler at which transition to SYCL 2020 occurs */
33+
#define __SYCL_COMPILER_2023_SWITCHOVER 20221020L
34+
35+
/* Version of SYCL DPC++ compiler at which info::max_work_item_size was
36+
made templated */
37+
#define __SYCL_COMPILER_MAX_WORK_ITEM_SIZE_THRESHOLD 20220805L
38+
3239
/* The DPCPP version used to build dpctl */
3340
#define DPCTL_DPCPP_VERSION "@IntelSycl_VERSION@"
3441

libsyclinterface/include/Support/CBindingWrapping.h

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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

libsyclinterface/include/dpctl_sycl_device_selector_interface.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,31 +65,31 @@ DPCTL_API
6565
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create(void);
6666

6767
/*!
68-
* @brief Returns an opaque wrapper for sycl::ONEAPI::filter_selector object
69-
* based on the passed in filter string.
68+
* @brief Returns an opaque wrapper for sycl::ext::oneapi::filter_selector
69+
* object based on the passed in filter string.
7070
*
7171
* @param filter_str A C string providing a filter based on which to
72-
* create a device_selector.
73-
* @return An opaque pointer to a sycl::ONEAPI::filter_selector object.
72+
* create a device selector.
73+
* @return An opaque pointer to a sycl::ext::oneapi::filter_selector object.
7474
* @ingroup DeviceSelectors
7575
*/
7676
DPCTL_API
7777
__dpctl_give DPCTLSyclDeviceSelectorRef
7878
DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str);
7979

8080
/*!
81-
* @brief Returns an opaque wrapper for sycl::gpu_selector object.
81+
* @brief Returns an opaque wrapper for dpctl_gpu_selector object.
8282
*
83-
* @return An opaque pointer to a sycl::gpu_selector object.
83+
* @return An opaque pointer to a dpctl_gpu_selector object.
8484
* @ingroup DeviceSelectors
8585
*/
8686
DPCTL_API
8787
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create(void);
8888

8989
/*!
90-
* @brief Returns an opaque wrapper for sycl::host_selector object.
90+
* @brief Returns an opaque wrapper for dpctl_host_selector object.
9191
*
92-
* @return An opaque pointer to a sycl::host_selector object.
92+
* @return An opaque pointer to a dpctl_host_selector object.
9393
* @ingroup DeviceSelectors
9494
*/
9595
DPCTL_API

libsyclinterface/include/dpctl_sycl_platform_interface.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ __dpctl_give DPCTLSyclPlatformRef DPCTLPlatform_Create(void);
6363

6464
/*!
6565
* @brief Creates a new DPCTLSyclPlatformRef for a SYCL platform constructed
66-
* using the device_selector wrapped by DPCTLSyclDeviceSelectorRef.
66+
* using the dpctl_device_selector wrapped by DPCTLSyclDeviceSelectorRef.
6767
*
68-
* @param DSRef An opaque pointer to a SYCL device_selector object.
68+
* @param DSRef An opaque pointer to a SYCL dpctl_device_selector
69+
* object.
6970
* @return A new DPCTLSyclPlatformRef pointer wrapping a SYCL platform object.
7071
* @ingroup PlatformInterface
7172
*/

0 commit comments

Comments
 (0)