Skip to content

Commit 811855d

Browse files
Add DPPL C-API interfaces for Sycl device, context, platform and queue. (#30)
* Adds C and Cython API for portions of Sycl queue, device, context interfaces. - Separates out the queue manager from the sycl queue interface wrapper. - Added API to get context, device froma Sycl queue. - Added C-API wrappers for sycl device, queue, context interfaces exposing some of the API functionalities. More can be added as needed. - The dppl extension now defines extension types for sycl quque, device, context to mimic the C API. - Sycl queues are now returned to callers as a SyclQueue extension type rather than a Py_capsule. * Add missing DPPL_API. * Move platform specific functions into a separate file. * Create a single utility function to delete C strings. * Update backends/source/dppl_utils.cpp New line at EOF. Co-authored-by: Sergey Pokhodenko <pokhodenko.s.a@gmail.com>
1 parent 78aba38 commit 811855d

21 files changed

+1376
-613
lines changed

backends/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
9696
add_library(
9797
DPPLSyclInterface
9898
SHARED
99+
source/dppl_sycl_context_interface.cpp
100+
source/dppl_sycl_device_interface.cpp
101+
source/dppl_sycl_platform_interface.cpp
99102
source/dppl_sycl_queue_interface.cpp
103+
source/dppl_sycl_queue_manager.cpp
104+
source/dppl_utils.cpp
100105
)
101106

102107
# Install DPPLOpenCLInterface
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===--- dppl_sycl_context_interface.h - DPPL-SYCL interface --*--C++ --*--===//
2+
//
3+
// Python Data Parallel Processing Library (PyDPPL)
4+
//
5+
// Copyright 2020 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 a C API to SYCL's sycl::context interface.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#pragma once
27+
28+
#include "dppl_data_types.h"
29+
#include "dppl_sycl_types.h"
30+
#include "Support/DllExport.h"
31+
#include "Support/ExternC.h"
32+
#include "Support/MemOwnershipAttrs.h"
33+
#include <stdbool.h>
34+
35+
DPPL_C_EXTERN_C_BEGIN
36+
37+
/*!
38+
* @brief Returns true if this SYCL context is a host context.
39+
*
40+
* @param CtxtRef A opaque pointer to a sycl::context.
41+
* @return True if the SYCL context is a host context, else False.
42+
*/
43+
DPPL_API
44+
bool DPPLIsHostContext (__dppl_keep const DPPLSyclContextRef CtxtRef);
45+
46+
/*!
47+
* @brief Delete the pointer after casting it to sycl::context
48+
*
49+
* @param CtxtRef The DPPLSyclContextRef pointer to be deleted.
50+
*/
51+
DPPL_API
52+
void DPPLDeleteSyclContext (__dppl_take DPPLSyclContextRef CtxtRef);
53+
54+
DPPL_C_EXTERN_C_END
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//===--- dppl_sycl_device_interface.h - DPPL-SYCL interface ---*---C++ -*---===//
2+
//
3+
// Python Data Parallel Processing Library (PyDPPL)
4+
//
5+
// Copyright 2020 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 a C interface to sycl::device. Not all of the device
23+
/// API is exposed, only the bits needed in other places like context and queue
24+
/// interfaces.
25+
///
26+
//===----------------------------------------------------------------------===//
27+
28+
#pragma once
29+
30+
#include "dppl_data_types.h"
31+
#include "dppl_sycl_types.h"
32+
#include "Support/DllExport.h"
33+
#include "Support/ExternC.h"
34+
#include "Support/MemOwnershipAttrs.h"
35+
36+
DPPL_C_EXTERN_C_BEGIN
37+
38+
/*!
39+
* @brief Redefinition of Sycl's device_type so that we do not have to include
40+
* sycl.hpp here and in the Python bindings.
41+
*
42+
*/
43+
typedef enum
44+
{
45+
DPPL_CPU,
46+
DPPL_GPU,
47+
DPPL_ACCELERATOR,
48+
DPPL_CUSTOM,
49+
DPPL_AUTOMATIC,
50+
DPPL_HOST,
51+
DPPL_ALL
52+
} DPPLSyclDeviceType;
53+
54+
/*!
55+
* @brief Prints out some of the info::deivice attributes for the device.
56+
*
57+
* @param DRef A DPPLSyclDeviceRef pointer.
58+
*/
59+
DPPL_API
60+
void DPPLDumpDeviceInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
61+
62+
/*!
63+
* @brief Deletes a DPPLSyclDeviceRef pointer after casting to to sycl::device.
64+
*
65+
* @param DRef The DPPLSyclDeviceRef pointer to be freed.
66+
*/
67+
DPPL_API
68+
void DPPLDeleteSyclDevice (__dppl_take DPPLSyclDeviceRef DRef);
69+
70+
/*!
71+
* @brief Returns true if this SYCL device is an OpenCL device and the device
72+
* type is sycl::info::device_type::accelerator.
73+
*
74+
* @param DRef Opaque pointer to a sycl::device
75+
* @return True if the device type is an accelerator, else False.
76+
*/
77+
DPPL_API
78+
bool DPPLDeviceIsAccelerator (__dppl_keep const DPPLSyclDeviceRef DRef);
79+
80+
/*!
81+
* @brief Returns true if this SYCL device is an OpenCL device and the device
82+
* type is sycl::info::device_type::cpu.
83+
*
84+
* @param DRef Opaque pointer to a sycl::device
85+
* @return True if the device type is a cpu, else False.
86+
*/
87+
DPPL_API
88+
bool DPPLDeviceIsCPU (__dppl_keep const DPPLSyclDeviceRef DRef);
89+
90+
/*!
91+
* @brief Returns true if this SYCL device is an OpenCL device and the device
92+
* type is sycl::info::device_type::gpu.
93+
*
94+
* @param DRef Opaque pointer to a sycl::device
95+
* @return True if the device type is a gpu, else False.
96+
*/
97+
DPPL_API
98+
bool DPPLDeviceIsGPU (__dppl_keep const DPPLSyclDeviceRef DRef);
99+
100+
/*!
101+
* @brief Returns true if this SYCL device is a host device.
102+
*
103+
* @param DRef Opaque pointer to a sycl::device
104+
* @return True if the device is a host device, else False.
105+
*/
106+
DPPL_API
107+
bool DPPLDeviceIsHost (__dppl_keep const DPPLSyclDeviceRef DRef);
108+
109+
/*!
110+
* @brief Returns the OpenCL software driver version as a C string.
111+
*
112+
* @param DRef Opaque pointer to a sycl::device
113+
* @return A C string in the form major_number.minor.number that corresponds
114+
* to the OpenCL driver version if this is a OpenCL device.
115+
*/
116+
DPPL_API
117+
__dppl_give const char*
118+
DPPLGetDeviceDriverInfo (__dppl_keep const DPPLSyclDeviceRef DRef);
119+
120+
/*!
121+
* @brief Returns a C string for the device name.
122+
*
123+
* @param DRef Opaque pointer to a sycl::device
124+
* @return A C string containing the OpenCL device name.
125+
*/
126+
DPPL_API
127+
__dppl_give const char*
128+
DPPLGetDeviceName (__dppl_keep const DPPLSyclDeviceRef DRef);
129+
130+
/*!
131+
* @brief Returns a C string corresponding to the vendor name.
132+
*
133+
* @param DRef Opaque pointer to a sycl::device
134+
* @return A C string containing the OpenCL device vendor name.
135+
*/
136+
DPPL_API
137+
__dppl_give const char*
138+
DPPLGetDeviceVendorName (__dppl_keep const DPPLSyclDeviceRef DRef);
139+
140+
/*!
141+
* @brief Returns True if the device and the host share a unified memory
142+
* subsystem, else returns False.
143+
*
144+
* @param DRef Opaque pointer to a sycl::device
145+
* @return Boolean indicating if the device shares a unified memory subsystem
146+
* with the host.
147+
*/
148+
DPPL_API
149+
bool DPPLGetDeviceHostUnifiedMemory (__dppl_keep const DPPLSyclDeviceRef DRef);
150+
151+
DPPL_C_EXTERN_C_END
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//===--- dppl_sycl_platform_interface.h - DPPL-SYCL interface ---*--C++ -*-===//
2+
//
3+
// Python Data Parallel Processing Library (PyDPPL)
4+
//
5+
// Copyright 2020 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 a C interface to sycl::platform interface functions.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#pragma once
27+
28+
#include "dppl_data_types.h"
29+
#include "Support/DllExport.h"
30+
#include "Support/ExternC.h"
31+
32+
DPPL_C_EXTERN_C_BEGIN
33+
34+
/*!
35+
* @brief Get the number of sycl::platform available on the system.
36+
*
37+
* @return The number of available sycl::platforms.
38+
*/
39+
DPPL_API
40+
size_t DPPLPlatform_GetNumPlatforms ();
41+
42+
/*!
43+
* @brief Prints out some selected info about all sycl::platform on the system.
44+
*
45+
*/
46+
DPPL_API
47+
void DPPLPlatform_DumpInfo ();
48+
49+
DPPL_C_EXTERN_C_END

0 commit comments

Comments
 (0)