Skip to content

Commit f4f80a5

Browse files
authored
Dppl queue manager (#22)
Refactored API to expose a minimal sycl::queue interface. * Uses a clean C-API * The DPPL stack to keep track of activated sycl::queue objects is not thread local * The code has more documentation and comments.
1 parent bf7572f commit f4f80a5

19 files changed

+1376
-528
lines changed

backends/CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,10 @@ set(OpenCL_LIBRARY "${DPCPP_ROOT}/lib/libOpenCL.so")
9393
message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")
9494
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
9595

96-
# Todo : Add build rules for unit tests
97-
98-
# Todo : Add build rules for doxygen
99-
10096
add_library(
10197
DPPLSyclInterface
10298
SHARED
103-
source/dppl_sycl_interface.cpp
99+
source/dppl_sycl_queue_interface.cpp
104100
)
105101

106102
# Install DPPLOpenCLInterface
@@ -174,3 +170,15 @@ file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/*.h*")
174170
foreach(HEADER ${HEADERS})
175171
install(FILES "${HEADER}" DESTINATION include)
176172
endforeach()
173+
174+
# Install all headers in include/Support
175+
file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/Support/*.h*")
176+
foreach(HEADER ${HEADERS})
177+
install(FILES "${HEADER}" DESTINATION include/Support)
178+
endforeach()
179+
180+
# Enable to build the PyDPPL backend test cases
181+
add_subdirectory(tests)
182+
183+
# Todo : Add build rules for doxygen
184+
# maybe refer https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/

backends/dbg_build.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set +xe
3+
rm -rf build
4+
mkdir build
5+
pushd build
6+
7+
INSTALL_PREFIX=`pwd`/../install
8+
export ONEAPI_ROOT=/opt/intel/oneapi
9+
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
10+
PYTHON_INC=`python -c "import distutils.sysconfig; \
11+
print(distutils.sysconfig.get_python_inc())"`
12+
NUMPY_INC=`python -c "import numpy; print(numpy.get_include())"`
13+
14+
cmake \
15+
-DCMAKE_BUILD_TYPE=Debug \
16+
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \
17+
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
18+
-DDPCPP_ROOT=${DPCPP_ROOT} \
19+
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \
20+
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \
21+
-DPYTHON_INCLUDE_DIR=${PYTHON_INC} \
22+
-DNUMPY_INCLUDE_DIR=${NUMPY_INC} \
23+
-DGTEST_INCLUDE_DIR=${CONDA_PREFIX}/include/ \
24+
-DGTEST_LIB_DIR=${CONDA_PREFIX}/lib \
25+
..
26+
27+
make V=1 -n -j 4
28+
make check
29+
make install
30+
31+
32+
popd
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===----- Support/CBindingWrapping.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 file declares the wrapping macros for the DPPL C interface.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#pragma once
27+
28+
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
29+
inline ty *unwrap(ref P) { \
30+
return reinterpret_cast<ty*>(P); \
31+
} \
32+
\
33+
inline ref wrap(const ty *P) { \
34+
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
35+
}
36+
37+
#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
38+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
39+
\
40+
template<typename T> \
41+
inline T *unwrap(ref P) { \
42+
T *Q = (T*)unwrap(P); \
43+
assert(Q && "Invalid cast!"); \
44+
return Q; \
45+
}

backends/include/Support/DllExport.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===---------- Support/DllExport.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 file defines a "__declspec(dllexport)" wrapper for windows.
23+
///
24+
//===----------------------------------------------------------------------===//
25+
26+
#pragma once
27+
28+
#ifdef _WIN32
29+
# ifdef DPPLSyclInterface_EXPORTS
30+
# define DPPL_API __declspec(dllexport)
31+
# else
32+
# define DPPL_API __declspec(dllimport)
33+
# endif
34+
#else
35+
# define DPPL_API
36+
#endif
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===------- dppl_error_codes.hpp - DPPL-SYCL interface ---*- C++ -*-------===//
1+
//===------------ Support/ExternC.h - DPPL-SYCL interface ---*--- C ---*---===//
22
//
33
// Python Data Parallel Processing Library (PyDPPL)
44
//
@@ -19,20 +19,16 @@
1919
//===----------------------------------------------------------------------===//
2020
///
2121
/// \file
22-
/// This file contains the error codes that are returned by DPPL functions.
22+
/// This file defines an extern "C" wrapper.
2323
///
2424
//===----------------------------------------------------------------------===//
25-
#pragma once
26-
27-
#include <cstdint>
2825

29-
namespace dppl
30-
{
31-
32-
enum : int64_t
33-
{
34-
DPPL_FAILURE = -1,
35-
DPPL_SUCCESS
36-
};
26+
#pragma once
3727

38-
}
28+
#ifdef __cplusplus
29+
#define DPPL_C_EXTERN_C_BEGIN extern "C" {
30+
#define DPPL_C_EXTERN_C_END }
31+
#else
32+
#define DPPL_C_EXTERN_C_BEGIN
33+
#define DPPL_C_EXTERN_C_END
34+
#endif
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//===----- dppl_mem_ownership_attrs.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 file defines a group of macros that serve as attributes indicating the
23+
/// type of ownership of a pointer. The macros are modeled after similar
24+
/// attributes defines in Integer Set Library (isl) and serve the purpose of
25+
/// helping a programmer understand the semantics of a DPPL function.
26+
///
27+
//===----------------------------------------------------------------------===//
28+
#pragma once
29+
30+
/**
31+
* @defgroup MEM_MGMT_ATTR_MACROS Memory management attributes.
32+
*
33+
* @{
34+
*/
35+
36+
/*!
37+
* @def __dppl_give
38+
* @brief The __dppl_give attribute indicates that a new object is returned and
39+
* the caller now owns the object.
40+
*
41+
* The __dppl_give attribute informs a user that the function is allocating a
42+
* new object and returning it to the user. The user now owns the object and to
43+
* free the object, he/she should make sure to use it exactly once as a value
44+
* for a __dppl_take argument. However, the user is free to use the object as
45+
* he/she likes as a value to __dppl_keep arguments.
46+
*
47+
*/
48+
#ifndef __dppl_give
49+
#define __dppl_give
50+
#endif
51+
/*!
52+
* @def __dppl_take
53+
* @brief The __dppl_take attribute indicates that the function "takes" over the
54+
* ownership of the object and the user must not use the object as an argument
55+
* to another function.
56+
*
57+
* The __dppl_take attribute mens that the function destroys it before the
58+
* function returns, and the caller must not use the object again in any other
59+
* function. If the pointer annotated with __dppl_take is NULL then it is
60+
* treated as an error, since it may prevent the normal behavior of the
61+
* function.
62+
*
63+
*/
64+
#ifndef __dppl_take
65+
#define __dppl_take
66+
#endif
67+
/*!
68+
* @def __dppl_keep
69+
* @brief The __dppl_keep attribute indicates that the function only uses the
70+
* object and does not destroy it before returning.
71+
*
72+
*/
73+
#ifndef __dppl_keep
74+
#define __dppl_keep
75+
#endif
76+
/*!
77+
* @def __dppl_null
78+
* @brief The __dppl_null attribute indicates that a NULL value is returned.
79+
*
80+
*/
81+
#ifndef __dppl_null
82+
#define __dppl_null
83+
#endif
84+
85+
/** @} */

backends/include/dppl_data_types.h

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//===---------- dppl_data_types.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 file was copied over from the LLVM-C (include/llvm-c/DataTypes.h).
23+
/// This file contains definitions to figure out the size of _HOST_ data types.
24+
/// This file is important because different host OS's define different macros,
25+
/// which makes portability tough. This file exports the following
26+
/// definitions:
27+
///
28+
/// [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types
29+
/// [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values.
30+
///
31+
/// No library is required when using these functions.
32+
///
33+
//===----------------------------------------------------------------------===//
34+
35+
#pragma once
36+
37+
#include <inttypes.h>
38+
#include <stdint.h>
39+
40+
#ifndef _MSC_VER
41+
42+
#if !defined(UINT32_MAX)
43+
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
44+
"__STDC_LIMIT_MACROS before #including llvm-c/DataTypes.h"
45+
#endif
46+
47+
#if !defined(UINT32_C)
48+
# error "The standard header <cstdint> is not C++11 compliant. Must #define "\
49+
"__STDC_CONSTANT_MACROS before #including llvm-c/DataTypes.h"
50+
#endif
51+
52+
/* Note that <inttypes.h> includes <stdint.h>, if this is a C99 system. */
53+
#include <sys/types.h>
54+
55+
#ifdef _AIX
56+
// GCC is strict about defining large constants: they must have LL modifier.
57+
#undef INT64_MAX
58+
#undef INT64_MIN
59+
#endif
60+
61+
#else /* _MSC_VER */
62+
#ifdef __cplusplus
63+
#include <cstddef>
64+
#include <cstdlib>
65+
#else
66+
#include <stddef.h>
67+
#include <stdlib.h>
68+
#endif
69+
#include <sys/types.h>
70+
71+
#if defined(_WIN64)
72+
typedef signed __int64 ssize_t;
73+
#else
74+
typedef signed int ssize_t;
75+
#endif /* _WIN64 */
76+
77+
#endif /* _MSC_VER */
78+
79+
/* Set defaults for constants which we cannot find. */
80+
#if !defined(INT64_MAX)
81+
# define INT64_MAX 9223372036854775807LL
82+
#endif
83+
#if !defined(INT64_MIN)
84+
# define INT64_MIN ((-INT64_MAX)-1)
85+
#endif
86+
#if !defined(UINT64_MAX)
87+
# define UINT64_MAX 0xffffffffffffffffULL
88+
#endif
89+
90+
#ifndef HUGE_VALF
91+
#define HUGE_VALF (float)HUGE_VAL
92+
#endif

0 commit comments

Comments
 (0)