Skip to content

Commit e35093b

Browse files
authored
Merge pull request #193 from PokhodenkoSA/update-gold-2021-to-0.4.0
Update gold/2021 to 0.4.0
2 parents 824837d + 38b6742 commit e35093b

File tree

75 files changed

+5815
-3305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+5815
-3305
lines changed

.git-blame-ignore-revs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
2+
3+
# Migrate code style to Black
4+
41ccd65e2e659aa0add0e5ab59f1a46e32cc4c46

.github/workflows/black.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# This is a workflow to format Python code with black formatter
2+
3+
name: black
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
branches: [master]
10+
pull_request:
11+
branches: [master]
12+
13+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
14+
jobs:
15+
# This workflow contains a single job called "black"
16+
black:
17+
# The type of runner that the job will run on
18+
runs-on: ubuntu-latest
19+
20+
# Steps represent a sequence of tasks that will be executed as part of the job
21+
steps:
22+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
23+
- uses: actions/checkout@v2
24+
# Set up a Python environment for use in actions
25+
- uses: actions/setup-python@v2
26+
27+
# Run black code formatter
28+
- uses: psf/black@stable

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [Unreleased]
5+
6+
## [0.4.0] - 2020-11-04
7+
### Added
8+
- Device descriptors "max_compute_units", "max_work_item_dimensions", "max_work_item_sizes", "max_work_group_size", "max_num_sub_groups" and "aspects" for int64 atomics inside dpctl C API and inside the dpctl.SyclDevice class.
9+
- MemoryUSM* classes moved to `dpctl.memory` module, added support for aligned allocation, added support for `prefetch` and `mem_advise` (sychronous) methods, implemented `copy_to_host`, `copy_from_host` and `copy_from_device` methods, pickling support, and zero-copy interoperability with Python objects which implement `__sycl_usm_array_inerface__` protocol.
10+
- Helper scripts to generate API documentation for both C API and Python.
11+
12+
### Fixed
13+
- Compiler warnings when building libDPPLSyclInterface and the Cython extensions.
14+
15+
### Removed
16+
- The Legacy OpenCL interface.
17+
18+
## [0.3.8] - 2020-10-08
19+
20+
### Changed
21+
- How the initial active queue is populated inside DPPLQueueMgr.
22+
- dpctl.SyclQueueManager only reports the number of non-host platform.
23+
- dpctl.SyclQueueManager now raises an exception if DPCTL C API returns a nullptr instead of a valid Sycl queue.
24+
25+
### Fixed
26+
- Several crashes in cases where an OpenCL or Level Zero platform is not available.
27+
- Fix failing platform test case. (#116)
28+
- Properly skip tests when no OpenCL devices are available.
29+
- Add skip tests to test_sycl_usm.py
30+
- Fix Gtests configuration.
31+
32+
## [0.3.7] - 2020-10-08
33+
34+
### Fixed
35+
- A crash on Windows due a Level Zero driver problem. Each device was getting enumerated twice. To handle the issue, we added a temporary fix to use only first device for each device type and backend (#118).
36+
437
## [0.3.6] - 2020-10-06
538
### Added
639
- Changelog was added for dpctl.

CONTRIBUTING.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
Coming soon
1+
# Python code style
2+
3+
## black
4+
5+
We use [black](https://black.readthedocs.io/en/stable/) code formatter.
6+
7+
- Revision: `20.8b1` or branch `stable`.
8+
- See configuration in `pyproject.toml`.
9+
10+
Run before each commit: `black .`

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
2+
13
What?
24
====
3-
A lightweight Python package exposing a subset of OpenCL and SYCL
4-
functionalities.
5+
A lightweight Python package exposing a subset of SYCL functionalities.
56

67
Requirements
78
============

backends/CMakeLists.txt

Lines changed: 23 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
22
project("dpCtl - A lightweight SYCL wrapper for Python")
33

44
# The function checks is DPCPP_ROOT is valid and points to a dpcpp installation
@@ -13,7 +13,7 @@ function (check_for_dpcpp)
1313
set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp")
1414
set (dpcpp_arg "--version")
1515
elseif(UNIX)
16-
set (dpcpp_cmd "dpcpp")
16+
set (dpcpp_cmd "${DPCPP_ROOT}/bin/dpcpp")
1717
set (dpcpp_arg "--version")
1818
else()
1919
message(FATAL_ERROR "Unsupported system.")
@@ -38,28 +38,8 @@ function (check_for_dpcpp)
3838
endif()
3939
endfunction()
4040

41-
function (check_for_numpy_inc)
42-
string(COMPARE EQUAL "${NUMPY_INCLUDE_DIR}" "" no_numpy_inc)
43-
if(${no_dpcpp_root})
44-
message(FATAL_ERROR "Set the NUMPY_INCLUDE_DIR argument providing the \
45-
path to NumPy Headers.")
46-
else()
47-
message(STATUS "NUMPY_INCLUDE_DIR: ${NUMPY_INCLUDE_DIR}")
48-
endif()
49-
50-
string(COMPARE EQUAL "${PYTHON_INCLUDE_DIR}" "" no_python_inc)
51-
if(${no_dpcpp_root})
52-
message(FATAL_ERROR "Set the PYTHON_INCLUDE_DIR argument providing the \
53-
path to Python Headers.")
54-
else()
55-
message(STATUS "PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}")
56-
endif()
57-
endfunction()
58-
5941
# Check for dpcpp in the specified DPCPP_ROOT
6042
check_for_dpcpp()
61-
# Check if the locations of Numpy and Python headers were provided
62-
check_for_numpy_inc()
6343

6444
if(WIN32)
6545
set(CMAKE_CXX_COMPILER:PATH "${DPCPP_ROOT}/bin/dpcpp")
@@ -68,31 +48,22 @@ if(WIN32)
6848
message(STATUS "Resetting CXX compiler to: " ${CMAKE_CXX_COMPILER})
6949
message(STATUS "Resetting C compiler to: " ${CMAKE_C_COMPILER})
7050
message(STATUS "Resetting Linker to: " ${CMAKE_LINK})
71-
72-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
73-
-Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations \
74-
-fdiagnostics-color=auto -O3 \
75-
")
76-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qstd=c++17")
77-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
51+
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations")
52+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
53+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Qstd=c++17")
54+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
55+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -Qstd=c++17")
7856
elseif(UNIX)
79-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
80-
-Wall -Wextra -Winit-self -Wuninitialized -Wmissing-declarations \
81-
-fdiagnostics-color=auto -O3 \
82-
")
83-
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -ggdb3 -DDEBUG ")
84-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fsycl")
57+
set(SDL_FLAGS "-fstack-protector -fstack-protector-all -fpic -fPIC -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -fno-strict-overflow -fno-delete-null-pointer-checks")
58+
set(WARNING_FLAGS "-Wall -Wextra -Winit-self -Wunused-function -Wuninitialized -Wmissing-declarations -fdiagnostics-color=auto")
59+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS}")
60+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${SDL_FLAGS} -std=c++17 -fsycl")
61+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG")
62+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${WARNING_FLAGS} -ggdb3 -DDEBUG -std=c++17 -fsycl")
8563
else()
8664
message(FATAL_ERROR "Unsupported system.")
8765
endif()
8866

89-
90-
set(OpenCL_INCLUDE_DIR "${DPCPP_ROOT}/include/sycl")
91-
set(OpenCL_LIBRARY "${DPCPP_ROOT}/lib/libOpenCL.so")
92-
93-
message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")
94-
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
95-
9667
add_library(
9768
DPPLSyclInterface
9869
SHARED
@@ -108,32 +79,11 @@ add_library(
10879
source/dppl_utils.cpp
10980
)
11081

111-
# Install DPPLOpenCLInterface
112-
add_library(
113-
DPPLOpenCLInterface
114-
SHARED
115-
source/dppl_opencl_interface.c
116-
)
117-
11882
# Install DPPLSyclInterface
11983
target_include_directories(
12084
DPPLSyclInterface
12185
PRIVATE
12286
${CMAKE_SOURCE_DIR}/include/
123-
${PYTHON_INCLUDE_DIR}
124-
${NUMPY_INCLUDE_DIR}
125-
)
126-
127-
target_include_directories(
128-
DPPLOpenCLInterface
129-
PRIVATE
130-
${CMAKE_SOURCE_DIR}/include/
131-
)
132-
133-
target_include_directories(
134-
DPPLOpenCLInterface
135-
PUBLIC
136-
${OpenCL_INCLUDE_DIR}
13787
)
13888

13989
if(WIN32)
@@ -152,10 +102,6 @@ if(WIN32)
152102
PRIVATE ${DPCPP_ROOT}/lib/sycl.lib
153103
PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib
154104
)
155-
target_link_libraries(
156-
DPPLOpenCLInterface
157-
PRIVATE ${DPCPP_ROOT}/lib/OpenCL.lib
158-
)
159105
endif()
160106

161107
install(
@@ -165,14 +111,6 @@ install(
165111
"${CMAKE_INSTALL_PREFIX}/lib/"
166112
)
167113

168-
install(
169-
TARGETS
170-
DPPLOpenCLInterface
171-
LIBRARY
172-
DESTINATION
173-
"${CMAKE_INSTALL_PREFIX}/lib/"
174-
)
175-
176114
# Install all headers
177115
file(GLOB HEADERS "${CMAKE_SOURCE_DIR}/include/*.h*")
178116
foreach(HEADER ${HEADERS})
@@ -185,8 +123,17 @@ foreach(HEADER ${HEADERS})
185123
install(FILES "${HEADER}" DESTINATION include/Support)
186124
endforeach()
187125

126+
option(
127+
BUILD_CAPI_TESTS
128+
"Build dpctl C API google tests"
129+
OFF
130+
)
131+
188132
# Enable to build the dpCtl backend test cases
189-
add_subdirectory(tests)
133+
if(BUILD_CAPI_TESTS)
134+
add_subdirectory(tests)
135+
endif()
136+
190137

191138
# Todo : Add build rules for doxygen
192139
# maybe refer https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/

backends/dbg_build.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ INSTALL_PREFIX=`pwd`/../install
88
rm -rf ${INSTALL_PREFIX}
99
export ONEAPI_ROOT=/opt/intel/oneapi
1010
DPCPP_ROOT=${ONEAPI_ROOT}/compiler/latest/linux
11-
PYTHON_INC=`python -c "import distutils.sysconfig; \
12-
print(distutils.sysconfig.get_python_inc())"`
13-
NUMPY_INC=`python -c "import numpy; print(numpy.get_include())"`
1411

1512
cmake \
1613
-DCMAKE_BUILD_TYPE=Debug \
@@ -19,12 +16,14 @@ cmake \
1916
-DDPCPP_ROOT=${DPCPP_ROOT} \
2017
-DCMAKE_C_COMPILER:PATH=${DPCPP_ROOT}/bin/clang \
2118
-DCMAKE_CXX_COMPILER:PATH=${DPCPP_ROOT}/bin/dpcpp \
22-
-DPYTHON_INCLUDE_DIR=${PYTHON_INC} \
23-
-DNUMPY_INCLUDE_DIR=${NUMPY_INC} \
24-
-DGTEST_INCLUDE_DIR=${CONDA_PREFIX}/include/ \
25-
-DGTEST_LIB_DIR=${CONDA_PREFIX}/lib \
19+
-DBUILD_CAPI_TESTS=ON \
2620
..
2721

2822
make V=1 -n -j 4 && make check && make install
2923

24+
# For more verbose tests use:
25+
# cd tests
26+
# ctest -V --progress --output-on-failure -j 4
27+
# cd ..
28+
3029
popd

backends/include/Support/CBindingWrapping.h

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,34 @@
2323
///
2424
//===----------------------------------------------------------------------===//
2525

26-
#pragma once
26+
#pragma once
2727

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-
}
28+
/*!
29+
@brief Creates two convenience functions to reinterpret_cast an opaque
30+
pointer to a pointer to a Sycl type and vice-versa.
31+
*/
32+
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
33+
__attribute__((unused)) inline ty *unwrap(ref P) \
34+
{ \
35+
return reinterpret_cast<ty*>(P); \
36+
} \
37+
\
38+
__attribute__((unused)) inline ref wrap(const ty *P) \
39+
{ \
40+
return reinterpret_cast<ref>(const_cast<ty*>(P)); \
41+
}
3642

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-
}
43+
/*!
44+
@brief Add an overloaded unwrap to assert that a pointer can be legally
45+
cast. @see DEFINE_SIMPLE_CONVERSION_FUNCTIONS()
46+
*/
47+
#define DEFINE_STDCXX_CONVERSION_FUNCTIONS(ty, ref) \
48+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \
49+
\
50+
template<typename T> \
51+
__attribute__((unused)) inline T *unwrap(ref P) \
52+
{ \
53+
T *Q = (T*)unwrap(P); \
54+
assert(Q && "Invalid cast!"); \
55+
return Q; \
56+
}

backends/include/dppl_data_types.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,30 @@ typedef signed int ssize_t;
7676

7777
#endif /* _MSC_VER */
7878

79-
/* Set defaults for constants which we cannot find. */
79+
/*!
80+
@brief Represents tha largest possible value of a 64 bit signed integer.
81+
*/
8082
#if !defined(INT64_MAX)
8183
# define INT64_MAX 9223372036854775807LL
8284
#endif
85+
86+
/*!
87+
@brief Represents tha smallest possible value of a 64 bit signed integer.
88+
*/
8389
#if !defined(INT64_MIN)
8490
# define INT64_MIN ((-INT64_MAX)-1)
8591
#endif
92+
93+
/*!
94+
@brief Represents tha largest possible value of a 64bit unsigned integer.
95+
*/
8696
#if !defined(UINT64_MAX)
8797
# define UINT64_MAX 0xffffffffffffffffULL
8898
#endif
8999

100+
/*!
101+
@brief Represents a positive expression of type float.
102+
*/
90103
#ifndef HUGE_VALF
91104
#define HUGE_VALF (float)HUGE_VAL
92105
#endif

0 commit comments

Comments
 (0)