Skip to content

Commit 8e526b4

Browse files
authored
Feature/device selectors (#274)
* Device selector support - Expose wrapper functions for standard SYCL device_selector classes and the ONEAPI::filter_selector class in C API. - Add the C API functions and types to Python API. - Redesign the SyclDevice class to allow construction from a filter selector string. - Make test cases related to device selection parameterized in both C API and Python. - Handle exceptions in C API for info::device functions. Fixes an issue with crashing tests in Python. - Update changelog. - Update documentation's rst file.
1 parent 6babd3f commit 8e526b4

13 files changed

+1241
-189
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Documentation improvements
1111
- Cmake improvements and Coverage for C API, Cython and Python
12-
- Add support for Level Zero
12+
- Added support for Level Zero devices and queues
13+
- Added support for SYCL standard device_selector classes
14+
- SyclDevice instances can now be constructed using filter selector strings
1315
- Code of conduct
1416

1517
### Fixed

docs/dpCtl_api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Classes
1515

1616
.. autoclass:: dpctl.SyclDevice
1717
:members:
18+
:inherited-members:
1819
:undoc-members:
1920

2021
.. autoclass:: dpctl.SyclEvent

dpctl-capi/CMakeLists.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,17 @@ else()
6161
message(FATAL_ERROR "Unsupported system.")
6262
endif()
6363

64-
add_library(
65-
DPCTLSyclInterface
66-
SHARED
67-
source/dpctl_sycl_context_interface.cpp
68-
source/dpctl_sycl_device_interface.cpp
69-
source/dpctl_sycl_event_interface.cpp
70-
source/dpctl_sycl_kernel_interface.cpp
71-
source/dpctl_sycl_platform_interface.cpp
72-
source/dpctl_sycl_program_interface.cpp
73-
source/dpctl_sycl_queue_interface.cpp
74-
source/dpctl_sycl_queue_manager.cpp
75-
source/dpctl_sycl_usm_interface.cpp
76-
source/dpctl_utils.cpp
77-
helper/source/dpctl_utils_helper.cpp
64+
file(GLOB_RECURSE sources
65+
${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp
66+
)
67+
file(GLOB_RECURSE helper_sources
68+
${CMAKE_CURRENT_SOURCE_DIR}/helper/source/*.cpp
69+
)
70+
71+
add_library(DPCTLSyclInterface
72+
SHARED
73+
${sources}
74+
${helper_sources}
7875
)
7976

8077
target_include_directories(DPCTLSyclInterface
@@ -83,6 +80,7 @@ target_include_directories(DPCTLSyclInterface
8380
${CMAKE_SOURCE_DIR}/helper/include/
8481
${DPCPP_SYCL_INCLUDE_DIR}
8582
)
83+
8684
target_link_libraries(DPCTLSyclInterface
8785
PRIVATE ${DPCPP_SYCL_LIBRARY}
8886
PRIVATE ${DPCPP_OPENCL_LIBRARY}

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,39 @@
3636

3737
DPCTL_C_EXTERN_C_BEGIN
3838

39+
/*!
40+
* @brief Returns a copy of the DPCTLSyclDeviceRef object.
41+
*
42+
* @param DRef DPCTLSyclDeviceRef object to be copied.
43+
* @return A new DPCTLSyclDeviceRef created by copying the passed in
44+
* DPCTLSyclDeviceRef object.
45+
*/
46+
DPCTL_API
47+
__dpctl_give DPCTLSyclDeviceRef
48+
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef);
49+
50+
/*!
51+
* @brief Returns a new DPCTLSyclDeviceRef opaque object wrapping a SYCL device
52+
* instance as a host device.
53+
*
54+
* @return An opaque pointer to the host SYCL device.
55+
*/
56+
DPCTL_API
57+
__dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Create();
58+
59+
/*!
60+
* @brief Returns a new DPCTLSyclDeviceRef opaque object created using the
61+
* provided device_selector.
62+
*
63+
* @param DSRef An opaque pointer to a SYCL device_selector.
64+
* @return Returns an opaque pointer to a SYCL device created using the
65+
* device_selector, if the requested device could not be created a
66+
* nullptr is returned.
67+
*/
68+
DPCTL_API
69+
__dpctl_give DPCTLSyclDeviceRef DPCTLDevice_CreateFromSelector(
70+
__dpctl_keep const DPCTLSyclDeviceSelectorRef DSRef);
71+
3972
/*!
4073
* @brief Prints out some of the info::deivice attributes for the device.
4174
*
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//=== dpctl_sycl_device_selector_interface.h - device_selector C API -*-C++-*-//
2+
//
3+
// Data Parallel Control (dpCtl)
4+
//
5+
// Copyright 2020-2021 Intel Corporation
6+
//
7+
// Licensed under the Apache License, Version 2.0 (the "License");
8+
// you may not use this file except in compliance with the License.
9+
// You may obtain a copy of the License at
10+
//
11+
// http://www.apache.org/licenses/LICENSE-2.0
12+
//
13+
// Unless required by applicable law or agreed to in writing, software
14+
// distributed under the License is distributed on an "AS IS" BASIS,
15+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
// See the License for the specific language governing permissions and
17+
// limitations under the License.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
///
21+
/// \file
22+
/// This header declares C contructors for the various SYCL device_selector
23+
/// classes.
24+
///
25+
//===----------------------------------------------------------------------===//
26+
27+
#pragma once
28+
29+
#include "Support/DllExport.h"
30+
#include "Support/ExternC.h"
31+
#include "Support/MemOwnershipAttrs.h"
32+
#include "dpctl_sycl_types.h"
33+
34+
DPCTL_C_EXTERN_C_BEGIN
35+
36+
/**
37+
* \defgroup DeviceSelectors C API for SYCL Device Selectors
38+
*/
39+
40+
/*!
41+
* @brief Returns an opaque wrapper for sycl::accelerator_selector object.
42+
*
43+
* @return An opaque pointer to a sycl::accelerator_selector object.
44+
* @ingroup DeviceSelectors
45+
*/
46+
DPCTL_API
47+
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLAcceleratorSelector_Create();
48+
49+
/*!
50+
* @brief Returns an opaque wrapper for sycl::default_selector object.
51+
*
52+
* @return An opaque pointer to a sycl::default_selector object.
53+
*/
54+
DPCTL_API
55+
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLDefaultSelector_Create();
56+
57+
/*!
58+
* @brief Returns an opaque wrapper for sycl::cpu_selector object.
59+
*
60+
* @return An opaque pointer to a sycl::cpu_selector object.
61+
* @ingroup DeviceSelectors
62+
*/
63+
DPCTL_API
64+
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLCPUSelector_Create();
65+
66+
/*!
67+
* @brief Returns an opaque wrapper for sycl::ONEAPI::filter_selector object
68+
* based on the passed in filter string.
69+
*
70+
* @param filter_str A C string providing a filter based on which to
71+
* create a device_selector.
72+
* @return An opaque pointer to a sycl::ONEAPI::filter_selector object.
73+
* @ingroup DeviceSelectors
74+
*/
75+
DPCTL_API
76+
__dpctl_give DPCTLSyclDeviceSelectorRef
77+
DPCTLFilterSelector_Create(__dpctl_keep const char *filter_str);
78+
79+
/*!
80+
* @brief Returns an opaque wrapper for sycl::gpu_selector object.
81+
*
82+
* @return An opaque pointer to a sycl::gpu_selector object.
83+
* @ingroup DeviceSelectors
84+
*/
85+
DPCTL_API
86+
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLGPUSelector_Create();
87+
88+
/*!
89+
* @brief Returns an opaque wrapper for sycl::host_selector object.
90+
*
91+
* @return An opaque pointer to a sycl::host_selector object.
92+
* @ingroup DeviceSelectors
93+
*/
94+
DPCTL_API
95+
__dpctl_give DPCTLSyclDeviceSelectorRef DPCTLHostSelector_Create();
96+
97+
/*!
98+
* @brief Deletes the DPCTLSyclDeviceSelectorRef after casting it to a
99+
* sycl::device_selector.
100+
*
101+
* @param DSRef An opaque DPCTLSyclDeviceSelectorRef pointer that would be
102+
* freed.
103+
* @ingroup DeviceSelectors
104+
*/
105+
DPCTL_API
106+
void DPCTLDeviceSelector_Delete(__dpctl_take DPCTLSyclDeviceSelectorRef DSRef);
107+
108+
DPCTL_C_EXTERN_C_END

dpctl-capi/include/dpctl_sycl_types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ typedef struct DPCTLOpaqueSyclContext *DPCTLSyclContextRef;
4141
*/
4242
typedef struct DPCTLOpaqueSyclDevice *DPCTLSyclDeviceRef;
4343

44+
/*!
45+
* @brief Opaque pointer to a sycl::device_selector
46+
*
47+
*/
48+
typedef struct DPCTLOpaqueSyclDeviceSelector *DPCTLSyclDeviceSelectorRef;
49+
4450
/*!
4551
* @brief Opaque pointer to a sycl::event
4652
*

0 commit comments

Comments
 (0)