Skip to content

Commit 944a531

Browse files
committed
Merge remote-tracking branch 'numba/main' into cuda-caching-2-rebase
2 parents 7db1c4e + 158b117 commit 944a531

69 files changed

Lines changed: 2092 additions & 343 deletions

Some content is hidden

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

‎.flake8‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ exclude =
150150
numba/tests/test_numberctor.py
151151
numba/tests/test_globals.py
152152
numba/tests/test_typingerror.py
153-
numba/tests/test_object_mode.py
154153
numba/tests/test_copy_propagate.py
155154
numba/tests/test_ctypes.py
156155
numba/tests/test_typeof.py

‎.github/ISSUE_TEMPLATE/first_rc_checklist.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ labels: task
1717
* [ ] Merge change log changes.
1818
- [ ] "PR with changelog entries".
1919
* [ ] Create X.Y release branch.
20-
* [ ] Pin llvmlite to `>=0.A.0rc1,<0.A+1.0`.
21-
* [ ] Pin NumPy if needed
22-
* [ ] Pin tbb if needed
23-
* [ ] Annotated tag X.Y.Zrc1 on release branch.
20+
* [ ] Dependency version pinning on release branch
21+
* [ ] Pin llvmlite to `>=0.A.0rc1,<0.A+1.0`.
22+
* [ ] Pin NumPy if needed
23+
* [ ] Pin TBB if needed
24+
* [ ] Annotated tag X.Y.Zrc1 on release branch (no `v` prefix).
2425
* [ ] Build and upload conda packages on buildfarm (check "upload").
25-
* [ ] Build wheels (`$PYTHON_VERSIONS`) on the buildfarm.
26+
* [ ] Build wheels and sdist on the buildfarm (check "upload").
2627
* [ ] Verify packages uploaded to Anaconda Cloud and move to `numba/label/main`.
27-
* [ ] Build sdist locally using `python setup.py sdist --owner=ci --group=numba` with umask `0022`.
2828
* [ ] Upload wheels and sdist to PyPI (upload from `ci_artifacts`).
2929
* [ ] Verify wheels for all platforms arrived on PyPi.
3030
* [ ] Initialize and verify ReadTheDocs build.
31-
* [ ] Clean up `ci_artifacts`.
3231
* [ ] Send RC announcement email / post announcement to discourse group.
3332
* [ ] Post link to Twitter.
3433

3534
### Post Release:
3635

36+
* [ ] Clean up `ci_artifacts` by moving files to sub-directories
3737
* [ ] Tag X.Y+1.0dev0 to start new development cycle on `main`.
3838
* [ ] Update llvmlite dependency spec to match next version via PR to `main`.
3939
* [ ] Update release checklist template with any additional bullet points that

‎.github/ISSUE_TEMPLATE/sub_rc_checklist.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ labels: task
1818
* [ ] Build and upload conda packages on buildfarm (check `upload`).
1919
* [ ] Verify packages uploaded to Anaconda Cloud and move to
2020
`numba/label/main`.
21-
* [ ] Build wheels (`$PYTHON_VERSIONS`) on the buildfarm.
22-
* [ ] Build sdist locally using `python setup.py sdist --owner=ci --group=numba` with umask `0022`.
21+
* [ ] Build wheels and sdist on the buildfarm (check "upload").
2322
* [ ] Upload wheels and sdist to PyPI (upload from `ci_artifacts`).
2423
* [ ] Verify wheels for all platforms arrived on PyPi.
2524
* [ ] Verify ReadTheDocs build.
@@ -29,8 +28,10 @@ labels: task
2928

3029
### Post release
3130

31+
* [ ] Snapshot Build Farm config
3232
* [ ] Clean up `ci_artifacts` by moving files to subdirectories
33-
* [ ] Update release checklist template.
33+
* [ ] Update release checklist template with any additional bullet points that
34+
may have arisen during the release.
3435
* [ ] Ping Anaconda Distro team to trigger a build for `defaults` (FINAL ONLY).
3536
* [ ] Create a release on Github at https://github.com/numba/numba/releases (FINAL ONLY).
3637
* [ ] Close milestone (and then close this release issue).

‎azure-pipelines.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ jobs:
5252
TEST_START_INDEX: 4
5353
py38_np119_tbb:
5454
PYTHON: '3.8'
55-
NUMPY: '1.19'
55+
NUMPY: '1.19.2=*_0'
5656
CONDA_ENV: azure_ci
5757
TEST_THREADING: 'tbb'
5858
TEST_START_INDEX: 5
5959
py38_np119_omp:
6060
PYTHON: '3.8'
61-
NUMPY: '1.19'
61+
NUMPY: '1.19.2=*_0'
6262
CONDA_ENV: azure_ci
6363
TEST_THREADING: omp
6464
TEST_START_INDEX: 6
6565
py38_np119_workqueue:
6666
PYTHON: '3.8'
67-
NUMPY: '1.19'
67+
NUMPY: '1.19.2=*_0'
6868
CONDA_ENV: azure_ci
6969
TEST_THREADING: workqueue
7070
TEST_START_INDEX: 7
@@ -93,7 +93,7 @@ jobs:
9393
TEST_START_INDEX: 11
9494
py39_np119:
9595
PYTHON: '3.9'
96-
NUMPY: '1.19'
96+
NUMPY: '1.19.2=*_0'
9797
CONDA_ENV: azure_ci
9898
TEST_START_INDEX: 12
9999
py39_np120_typeguard:

‎buildscripts/condarecipe.local/meta.yaml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ requirements:
4444
- tbb-devel >=2021,<2021.6 # [not (armv6l or armv7l or aarch64 or linux32 or ppc64le)]
4545
run:
4646
- python >=3.7
47-
- numpy >=1.18
47+
# NumPy 1.22.0, 1.22.1, 1.22.2 are all broken for ufuncs, see #7756
48+
- numpy >=1.18, !=1.22.0, !=1.22.1, !=1.22.2
4849
- setuptools
4950
- importlib_metadata # [py<39]
5051
# On channel https://anaconda.org/numba/
@@ -60,14 +61,12 @@ requirements:
6061
# Exclude 0.3.20 too
6162
# https://github.com/numba/numba/issues/8096
6263
- libopenblas >=0.3.18, !=0.3.20 # [arm64]
63-
# CUDA 9.2 or later is required for CUDA support
64-
- cudatoolkit >=9.2
64+
# CUDA 10.2 or later is required for CUDA support
65+
- cudatoolkit >=10.2
6566
# scipy 1.0 or later
6667
- scipy >=1.0
6768
# CUDA Python 11.6 or later
6869
- cuda-python >=11.6
69-
# NumPy 1.22.0, 1.22.1, 1.22.2 are all broken for ufuncs, see #7756
70-
- numpy !=1.22.0, !=1.22.1, !=1.22.2
7170

7271
test:
7372
requires:

‎docs/source/cuda-reference/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ CUDA Python Reference
55

66
host.rst
77
kernel.rst
8+
types.rst
89
memory.rst
910
libdevice.rst
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
CUDA-Specific Types
2+
====================
3+
4+
.. note::
5+
6+
This page is about types specific to CUDA targets. Many other types are also
7+
available in the CUDA target - see :ref:`cuda-built-in-types`.
8+
9+
Vector Types
10+
~~~~~~~~~~~~
11+
12+
`CUDA Vector Types <https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#built-in-vector-types>`_
13+
are usable in kernels. There are two important distinctions from vector types in CUDA C/C++:
14+
15+
First, the recommended names for vector types in Numba CUDA is formatted as ``<base_type>x<N>``,
16+
where ``base_type`` is the base type of the vector, and ``N`` is the number of elements in the vector.
17+
Examples include ``int64x3``, ``uint16x4``, ``float32x4``, etc. For new Numba CUDA kernels,
18+
this is the recommended way to instantiate vector types.
19+
20+
For convenience, users adapting existing kernels from CUDA C/C++ to Python may use
21+
aliases consistent with the C/C++ namings. For example, ``float3`` aliases ``float32x3``,
22+
``long3`` aliases ``int32x3`` or ``int64x3`` (depending on the platform), etc.
23+
24+
Second, unlike CUDA C/C++ where factory functions are used, vector types are constructed directly
25+
with their constructor. For example, to construct a ``float32x3``:
26+
27+
.. code-block:: python3
28+
29+
from numba.cuda import float32x3
30+
31+
# In kernel
32+
f3 = float32x3(0.0, -1.0, 1.0)
33+
34+
Additionally, vector types can be constructed from a combination of vector and
35+
primitive types, as long as the total number of components matches the result
36+
vector type. For example, all of the following constructions are valid:
37+
38+
.. code-block:: python3
39+
40+
zero = uint32(0)
41+
u2 = uint32x2(1, 2)
42+
# Construct a 3-component vector with primitive type and a 2-component vector
43+
u3 = uint32x3(zero, u2)
44+
# Construct a 4-component vector with 2 2-component vectors
45+
u4 = uint32x4(u2, u2)
46+
47+
The 1st, 2nd, 3rd and 4th component of the vector type can be accessed through fields
48+
``x``, ``y``, ``z``, and ``w`` respectively. The components are immutable after
49+
construction in the present version of Numba; it is expected that support for
50+
mutating vector components will be added in a future release.
51+
52+
.. code-block:: python3
53+
54+
v1 = float32x2(1.0, 1.0)
55+
v2 = float32x2(1.0, -1.0)
56+
dotprod = v1.x * v2.x + v1.y * v2.y

‎docs/source/cuda/cudapysupported.rst‎

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ The following Python constructs are not supported:
3333
* Comprehensions (either list, dict, set or generator comprehensions)
3434
* Generator (any ``yield`` statements)
3535

36-
The ``raise`` statement is supported.
36+
The ``raise`` and ``assert`` statements are supported, with the following
37+
constraints:
3738

38-
The ``assert`` statement is supported, but only has an effect when
39-
``debug=True`` is passed to the :func:`numba.cuda.jit` decorator. This is
40-
similar to the behavior of the ``assert`` keyword in CUDA C/C++, which is
41-
ignored unless compiling with device debug turned on.
39+
- They can only be used in kernels, not in device functions.
40+
- They only have an effect when ``debug=True`` is passed to the
41+
:func:`@cuda.jit <numba.cuda.jit>` decorator. This is similar to the behavior
42+
of the ``assert`` keyword in CUDA C/C++, which is ignored unless compiling
43+
with device debug turned on.
4244

4345

4446
Printing of strings, integers, and floats is supported, but printing is an
@@ -54,6 +56,56 @@ This is due to a general limitation in CUDA printing, as outlined in the
5456
<https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#limitations>`_
5557
in the CUDA C++ Programming Guide.
5658

59+
60+
Recursion
61+
---------
62+
63+
Self-recursive device functions are supported, with the constraint that
64+
recursive calls must have the same argument types as the initial call to
65+
the function. For example, the following form of recursion is supported:
66+
67+
.. code:: python
68+
69+
@cuda.jit("int64(int64)", device=True)
70+
def fib(n):
71+
if n < 2:
72+
return n
73+
return fib(n - 1) + fib(n - 2)
74+
75+
(the ``fib`` function always has an ``int64`` argument), whereas the following
76+
is unsupported:
77+
78+
.. code:: python
79+
80+
# Called with x := int64, y := float64
81+
@cuda.jit
82+
def type_change_self(x, y):
83+
if x > 1 and y > 0:
84+
return x + type_change_self(x - y, y)
85+
else:
86+
return y
87+
88+
The outer call to ``type_change_self`` provides ``(int64, float64)`` arguments,
89+
but the inner call uses ``(float64, float64)`` arguments (because ``x - y`` /
90+
``int64 - float64`` results in a ``float64`` type). Therefore, this function is
91+
unsupported.
92+
93+
Mutual recursion between functions (e.g. where a function ``func1()`` calls
94+
``func2()`` which again calls ``func1()``) is unsupported.
95+
96+
.. note::
97+
98+
The call stack in CUDA is typically quite limited in size, so it is easier
99+
to overflow it with recursive calls on CUDA devices than it is on CPUs.
100+
101+
Stack overflow will result in an Unspecified Launch Failure (ULF) during
102+
kernel execution. In order to identify whether a ULF is due to stack
103+
overflow, programs can be run under `Compute Sanitizer
104+
<https://docs.nvidia.com/compute-sanitizer/ComputeSanitizer/index.html>`_,
105+
which explicitly states when stack overflow has occurred.
106+
107+
.. _cuda-built-in-types:
108+
57109
Built-in types
58110
===============
59111

‎docs/source/cuda/memory.rst‎

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,20 @@ traditional dynamic memory management.
125125
This function must be called on the device (i.e. from a kernel or
126126
device function). *shape* is either an integer or a tuple of integers
127127
representing the array's dimensions and must be a simple constant
128-
expression. *type* is a :ref:`Numba type <numba-types>` of the elements
129-
needing to be stored in the array.
130-
131-
The returned array-like object can be read and written to like any normal
132-
device array (e.g. through indexing).
128+
expression. A "simple constant expression" includes, but is not limited to:
129+
130+
#. A literal (e.g. ``10``)
131+
#. A local variable whose right-hand side is a literal or a simple constant
132+
expression (e.g. ``shape``, where ``shape`` is defined earlier in the function
133+
as ``shape = 10``)
134+
#. A global variable that is defined in the jitted function's globals by the time
135+
of compilation (e.g. ``shape``, where ``shape`` is defined using any expression
136+
at global scope).
137+
138+
The definition must result in a Python ``int`` (i.e. not a NumPy scalar or other
139+
scalar / integer-like type). *type* is a :ref:`Numba type <numba-types>` of the
140+
elements needing to be stored in the array. The returned array-like object can be
141+
read and written to like any normal device array (e.g. through indexing).
133142

134143
A common pattern is to have each thread populate one element in the
135144
shared array and then wait for all threads to finish using :func:`.syncthreads`.
@@ -162,11 +171,22 @@ unlike traditional dynamic memory management.
162171

163172
Allocate a local array of the given *shape* and *type* on the device.
164173
*shape* is either an integer or a tuple of integers representing the array's
165-
dimensions and must be a simple constant expression. *type* is a :ref:`Numba
166-
type <numba-types>` of the elements needing to be stored in the array. The
167-
array is private to the current thread. An array-like object is returned
168-
which can be read and written to like any standard array (e.g. through
169-
indexing).
174+
dimensions and must be a simple constant expression. A "simple constant expression"
175+
includes, but is not limited to:
176+
177+
#. A literal (e.g. ``10``)
178+
#. A local variable whose right-hand side is a literal or a simple constant
179+
expression (e.g. ``shape``, where ``shape`` is defined earlier in the function
180+
as ``shape = 10``)
181+
#. A global variable that is defined in the jitted function's globals by the time
182+
of compilation (e.g. ``shape``, where ``shape`` is defined using any expression
183+
at global scope).
184+
185+
The definition must result in a Python ``int`` (i.e. not a NumPy scalar or other
186+
scalar / integer-like type). *type* is a :ref:`Numba type <numba-types>`
187+
of the elements needing to be stored in the array. The array is private to
188+
the current thread. An array-like object is returned which can be read and
189+
written to like any standard array (e.g. through indexing).
170190

171191
.. seealso:: The Local Memory section of `Device Memory Accesses
172192
<https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#device-memory-accesses>`_

‎numba/_random.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ rnd_seed_with_bytes(rnd_state_t *state, Py_buffer *buf)
141141
* constraints.
142142
*/
143143
for (i = 0; i < nkeys; i++, bytes += 4) {
144-
keys[i] = (bytes[3] << 24) + (bytes[2] << 16) +
145-
(bytes[1] << 8) + (bytes[0] << 0);
144+
keys[i] =
145+
((unsigned int)bytes[3] << 24) +
146+
((unsigned int)bytes[2] << 16) +
147+
((unsigned int)bytes[1] << 8) +
148+
((unsigned int)bytes[0] << 0);
146149
}
147150
PyBuffer_Release(buf);
148151
rnd_init_by_array(state, keys, nkeys);

0 commit comments

Comments
 (0)