Skip to content

Commit c27e704

Browse files
author
Diptorup Deb
authored
Merge pull request #1132 from IntelPython/main
Merge into GOLD
2 parents d7afd57 + 1d09550 commit c27e704

File tree

26 files changed

+428
-181
lines changed

26 files changed

+428
-181
lines changed

.github/workflows/conda-package.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
python: ['3.8', '3.9', '3.10']
29+
python: ['3.9', '3.10', '3.11']
3030
os: [ubuntu-latest, windows-latest]
3131

3232
runs-on: ${{ matrix.os }}
@@ -93,7 +93,7 @@ jobs:
9393
strategy:
9494
fail-fast: false
9595
matrix:
96-
python: ['3.8', '3.9', '3.10']
96+
python: ['3.9', '3.10', '3.11']
9797
os: [ubuntu-20.04, ubuntu-latest, windows-latest]
9898
experimental: [false]
9999

@@ -157,8 +157,9 @@ jobs:
157157
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
158158
159159
# We want to make sure that all dependecies install automatically.
160+
# intel::intel-opencl-rt is needed for set-intel-ocl-icd-registry.ps1
160161
- name: Install builded package
161-
run: mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} opencl_rt pytest -c ${{ env.CHANNEL_PATH }}
162+
run: mamba install ${{ env.PACKAGE_NAME }}=${{ env.PACKAGE_VERSION }} intel::intel-opencl-rt pytest -c ${{ env.CHANNEL_PATH }}
162163

163164
- name: Setup OpenCL CPU device
164165
if: runner.os == 'Windows'
@@ -199,7 +200,7 @@ jobs:
199200

200201
strategy:
201202
matrix:
202-
python: ['3.8', '3.9', '3.10']
203+
python: ['3.9', '3.10', '3.11']
203204
os: [ubuntu-latest, windows-latest]
204205

205206
runs-on: ${{ matrix.os }}

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
oneapi_version:
2323
default: '2023.1.0.46401'
2424
python_versions:
25-
default: '["3.8", "3.9", "3.10", "3.11"]'
25+
default: '["3.9", "3.10", "3.11"]'
2626
buildkit_version:
2727
default: '0.11.6'
2828

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.21.3] - 2023-09-21
8+
9+
### Fixed
10+
* Mangled kernel name generation (#1112)
11+
12+
### Added
13+
* Python 3.11 support (#1123)
14+
* Security policy (#1117)
15+
* scikit-build to build native extensions (#1107, #1127)
16+
17+
### Changed
18+
* The data model used by the DpnpNdArray type for kernel functions(#1118)
19+
20+
### Removed
21+
* Support for Python 3.8 (#1113)
22+
723
## [0.21.2] - 2023-08-07
824

925
### Fixed
10-
* Bugs (#1068, #774) in atomic addition caused due to imporper floating point atomic emulation. (#1103)
26+
* Bugs (#1068, #774) in atomic addition caused due to improper floating point atomic emulation. (#1103)
1127

1228
### Changed
1329
* Updated documentation and user guides (#1097, #879)

CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#[=======================================================================[.rst:
2+
numba_dpex
3+
-----------
4+
5+
A cmake file to compile the ``_dpexrt_python`` Python C extension for
6+
``numba_dpex``. You can build this component locally in-place by invoking these
7+
commands:
8+
9+
.. code-block:: cmake
10+
~$ cmake .
11+
~$ cmake --build . --verbose
12+
13+
Once compiled, the _dpexrt_python library will be in ``numba_dpex/core/runtime``
14+
folder.
15+
16+
This ``CMakeLists.txt`` file will be used by ``setup.py``.
17+
#]=======================================================================]
18+
19+
cmake_minimum_required(VERSION 3.21...3.27 FATAL_ERROR)
20+
21+
message(STATUS "NUMBA_DPEX_VERSION=" "${NUMBA_DPEX_VERSION}")
22+
23+
project(numba-dpex
24+
DESCRIPTION "An extension for Numba to add data-parallel offload capability"
25+
VERSION ${NUMBA_DPEX_VERSION}
26+
)
27+
28+
if(IS_INSTALL)
29+
install(DIRECTORY numba_dpex
30+
DESTINATION ${CMAKE_INSTALL_PREFIX}
31+
FILES_MATCHING PATTERN "*.py")
32+
endif()
33+
34+
add_subdirectory(numba_dpex)

MANIFEST.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
include MANIFEST.in
22
include README.md setup.py LICENSE
33

4-
recursive-include numba_dpex *.cl
5-
recursive-include numba_dpex *.spir
6-
74
include versioneer.py
85
include numba_dpex/_version.py
96

SECURITY.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Security Policy
2+
3+
## Report a Vulnerability
4+
5+
Please report security issues or vulnerabilities to the [Intel® Security Center].
6+
7+
For more information on how Intel® works to resolve security issues, see
8+
[Vulnerability Handling Guidelines].
9+
10+
[Intel® Security Center]:https://www.intel.com/content/www/us/en/security-center/default.html
11+
12+
[Vulnerability Handling Guidelines]:https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html

build-environment.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

conda-recipe/meta.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ requirements:
1717
host:
1818
- python
1919
- setuptools >=63.*
20-
- numba 0.57*
20+
- scikit-build >=0.15*
21+
- cmake >=3.26*
22+
- numba >=0.57*
2123
- dpctl >=0.14*
2224
- dpnp >=0.11*
2325
- dpcpp-llvm-spirv

docs/source/getting_started.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Building from source
3737
--------------------
3838

3939
``numba-dpex`` can be built from source using either ``conda-build`` or
40-
``setuptools``.
40+
``setuptools`` (with ``scikit-build`` backend).
4141

4242
Steps to build using ``conda-build``:
4343

@@ -70,7 +70,7 @@ first step.
7070
7171
# Create a conda environment that hass needed dependencies installed
7272
conda create -n numba-dpex-env \
73-
dpctl dpnp numba dpcpp-llvm-spirv llvmdev pytest \
73+
scikit-build cmake dpctl dpnp numba dpcpp-llvm-spirv llvmdev pytest \
7474
-c intel -c conda-forge
7575
# Activate the environment
7676
conda activate numba-dpex-env

environment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ dependencies:
1616
- mkl >=2021.3.0 # for dpnp
1717
- dpcpp-llvm-spirv
1818
- packaging
19+
- scikit-build >=0.15*
20+
- cmake >=3.26*
1921
- pytest
2022
- pip
2123
- pip:

environment/coverage.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ dependencies:
2020
- pytest-cov
2121
- pytest-xdist
2222
- pexpect
23+
- scikit-build>=0.15*
24+
- cmake>=3.26*

environment/docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ dependencies:
1111
- gxx_linux-64
1212
- dpcpp_linux-64
1313
- numba=0.57
14+
- scikit-build>=0.15*
15+
- cmake>=3.26*
1416
- dpctl
1517
- dpnp
1618
- dpcpp-llvm-spirv

numba_dpex/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
if(IS_INSTALL)
2+
install(DIRECTORY core
3+
DESTINATION numba_dpex
4+
FILES_MATCHING PATTERN "*.py")
5+
endif()
6+
7+
add_subdirectory(core/runtime)
8+
9+
if(IS_INSTALL)
10+
install(DIRECTORY dpctl_iface
11+
DESTINATION numba_dpex
12+
FILES_MATCHING PATTERN "*.py")
13+
endif()
14+
15+
if(IS_INSTALL)
16+
install(DIRECTORY dpnp_iface
17+
DESTINATION numba_dpex
18+
FILES_MATCHING PATTERN "*.py")
19+
endif()
20+
21+
if(IS_INSTALL)
22+
install(DIRECTORY examples
23+
DESTINATION numba_dpex)
24+
endif()
25+
26+
if(IS_INSTALL)
27+
install(DIRECTORY numba_patches
28+
DESTINATION numba_dpex
29+
FILES_MATCHING PATTERN "*.py")
30+
endif()
31+
32+
if(IS_INSTALL)
33+
install(DIRECTORY ocl
34+
DESTINATION numba_dpex
35+
FILES_MATCHING PATTERN "*.py")
36+
endif()
37+
38+
if(IS_INSTALL)
39+
install(DIRECTORY tests
40+
DESTINATION numba_dpex
41+
FILES_MATCHING PATTERN "*.py")
42+
endif()
43+
44+
if(IS_INSTALL)
45+
install(DIRECTORY utils
46+
DESTINATION numba_dpex
47+
FILES_MATCHING PATTERN "*.py")
48+
endif()

numba_dpex/core/codegen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def _optimize_final_module(self):
3535
pmb.opt_level = config.OPT
3636

3737
pmb.disable_unit_at_a_time = False
38+
pmb.inlining_threshold = 2
3839
pmb.disable_unroll_loops = True
3940
pmb.loop_vectorize = False
4041
pmb.slp_vectorize = False

numba_dpex/core/datamodel/models.py

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ def __init__(self, dmm, fe_type):
5757
]
5858
super(USMArrayModel, self).__init__(dmm, fe_type, members)
5959

60+
@property
61+
def flattened_field_count(self):
62+
"""Return the number of fields in an instance of a USMArrayModel."""
63+
flattened_member_count = 0
64+
members = self._members
65+
for member in members:
66+
if isinstance(member, types.UniTuple):
67+
flattened_member_count += member.count
68+
elif isinstance(
69+
member,
70+
(
71+
types.scalars.Integer,
72+
types.misc.PyObject,
73+
types.misc.RawPointer,
74+
types.misc.CPointer,
75+
types.misc.MemInfoPointer,
76+
),
77+
):
78+
flattened_member_count += 1
79+
else:
80+
raise UnreachableError
81+
82+
return flattened_member_count
83+
6084

6185
class DpnpNdArrayModel(StructModel):
6286
"""Data model for the DpnpNdArray type.
@@ -138,35 +162,54 @@ def __init__(self, dmm, fe_type):
138162
super(SyclQueueModel, self).__init__(dmm, fe_type, members)
139163

140164

141-
def _init_data_model_manager():
165+
def _init_data_model_manager() -> datamodel.DataModelManager:
166+
"""Initializes a DpexKernelTarget-specific data model manager.
167+
168+
SPIRV kernel functions for certain types of devices require an explicit
169+
address space qualifier for pointers. For OpenCL HD Graphics
170+
devices, defining a kernel function (spir_kernel calling convention) with
171+
pointer arguments that have no address space qualifier causes a run time
172+
crash. For this reason, numba-dpex defines two separate data
173+
models: USMArrayModel and DpnpNdArrayModel. When a dpnp.ndarray object is
174+
passed as an argument to a ``numba_dpex.kernel`` decorated function it uses
175+
the USMArrayModel and when passed to a ``numba_dpex.dpjit`` decorated
176+
function it uses the DpnpNdArrayModel. The difference is due to the fact
177+
that inside a ``dpjit`` decorated function a dpnp.ndarray object can be
178+
passed to any other regular function.
179+
180+
Returns:
181+
DataModelManager: A numba-dpex DpexKernelTarget-specific data model
182+
manager
183+
"""
142184
dmm = datamodel.default_manager.copy()
143185
dmm.register(types.CPointer, GenericPointerModel)
144186
dmm.register(Array, USMArrayModel)
187+
188+
# Register the USMNdArray type to USMArrayModel in numba_dpex's data model
189+
# manager. The dpex_data_model_manager is used by the DpexKernelTarget
190+
dmm.register(USMNdArray, USMArrayModel)
191+
192+
# Register the DpnpNdArray type to USMArrayModel in numba_dpex's data model
193+
# manager. The dpex_data_model_manager is used by the DpexKernelTarget
194+
dmm.register(DpnpNdArray, USMArrayModel)
195+
196+
# Register the DpctlSyclQueue type to SyclQueueModel in numba_dpex's data
197+
# model manager. The dpex_data_model_manager is used by the DpexKernelTarget
198+
dmm.register(DpctlSyclQueue, SyclQueueModel)
199+
145200
return dmm
146201

147202

148203
dpex_data_model_manager = _init_data_model_manager()
149204

150-
# XXX A kernel function has the spir_kernel ABI and requires pointers to have an
151-
# address space attribute. For this reason, the UsmNdArray type uses dpex's
152-
# ArrayModel where the pointers are address space casted to have a SYCL-specific
153-
# address space value. The DpnpNdArray type can be used inside djit functions
154-
# as host function calls arguments, such as dpnp library calls. The DpnpNdArray
155-
# needs to use Numba's array model as its data model. Thus, from a Numba typing
156-
# perspective dpnp.ndarrays cannot be directly passed to a kernel. To get
157-
# around the limitation, the DpexKernelTypingContext does not resolve the type
158-
# of dpnp.array args to a kernel as DpnpNdArray type objects, but uses the
159-
# ``to_usm_ndarray`` utility function to convert them into a UsmNdArray type
160-
# object.
161-
162-
# Register the USMNdArray type with the dpex ArrayModel
205+
206+
# Register the USMNdArray type to USMArrayModel in numba's default data model
207+
# manager
163208
register_model(USMNdArray)(USMArrayModel)
164-
dpex_data_model_manager.register(USMNdArray, USMArrayModel)
165209

166-
# Register the DpnpNdArray type with the Numba ArrayModel
210+
# Register the DpnpNdArray type to DpnpNdArrayModel in numba's default data
211+
# model manager
167212
register_model(DpnpNdArray)(DpnpNdArrayModel)
168-
dpex_data_model_manager.register(DpnpNdArray, DpnpNdArrayModel)
169213

170214
# Register the DpctlSyclQueue type
171215
register_model(DpctlSyclQueue)(SyclQueueModel)
172-
dpex_data_model_manager.register(DpctlSyclQueue, SyclQueueModel)

numba_dpex/core/kernel_interface/spirv_kernel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def compile(
136136
kernel = cres.target_context.prepare_ocl_kernel(
137137
func, cres.signature.args
138138
)
139+
cres.library._optimize_final_module()
139140
self._llvm_module = kernel.module.__str__()
140141
self._module_name = kernel.name
141142

numba_dpex/core/parfors/kernel_builder.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,6 @@ def _compile_kernel_parfor(
7070
func_ir, kernel_name
7171
)
7272

73-
# A cast from DpnpNdArray type to USMNdArray is needed for all arguments of
74-
# DpnpNdArray type. Although, DpnpNdArray derives from USMNdArray the two
75-
# types use different data models. USMNdArray uses the
76-
# numba_dpex.core.datamodel.models.ArrayModel data model that defines all
77-
# CPointer type members in the GLOBAL address space. The DpnpNdArray uses
78-
# Numba's default ArrayModel that does not define pointers in any specific
79-
# address space. For OpenCL HD Graphics devices, defining a kernel function
80-
# (spir_kernel calling convention) with pointer arguments that have no
81-
# address space qualifier causes a run time crash. By casting the argument
82-
# type for parfor arguments from DpnpNdArray type to the USMNdArray type the
83-
# generated kernel always has an address space qualifier, avoiding the issue
84-
# on OpenCL HD graphics devices.
85-
86-
for i, argty in enumerate(argtypes):
87-
if isinstance(argty, DpnpNdArray):
88-
new_argty = USMNdArray(
89-
ndim=argty.ndim,
90-
layout=argty.layout,
91-
dtype=argty.dtype,
92-
usm_type=argty.usm_type,
93-
queue=argty.queue,
94-
)
95-
argtypes[i] = new_argty
96-
9773
# compile the kernel
9874
kernel.compile(
9975
args=argtypes,

0 commit comments

Comments
 (0)