cquda-continuumq 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cquda_continuumq-0.1.0/CHANGELOG.md +18 -0
- cquda_continuumq-0.1.0/LICENSE +21 -0
- cquda_continuumq-0.1.0/MANIFEST.in +3 -0
- cquda_continuumq-0.1.0/PKG-INFO +127 -0
- cquda_continuumq-0.1.0/README.md +98 -0
- cquda_continuumq-0.1.0/RELEASING.md +49 -0
- cquda_continuumq-0.1.0/pyproject.toml +51 -0
- cquda_continuumq-0.1.0/scripts/release.py +280 -0
- cquda_continuumq-0.1.0/setup.cfg +4 -0
- cquda_continuumq-0.1.0/src/cquda/__init__.py +3 -0
- cquda_continuumq-0.1.0/src/cquda_continuumq.egg-info/PKG-INFO +127 -0
- cquda_continuumq-0.1.0/src/cquda_continuumq.egg-info/SOURCES.txt +19 -0
- cquda_continuumq-0.1.0/src/cquda_continuumq.egg-info/dependency_links.txt +1 -0
- cquda_continuumq-0.1.0/src/cquda_continuumq.egg-info/entry_points.txt +3 -0
- cquda_continuumq-0.1.0/src/cquda_continuumq.egg-info/requires.txt +4 -0
- cquda_continuumq-0.1.0/src/cquda_continuumq.egg-info/top_level.txt +2 -0
- cquda_continuumq-0.1.0/src/tinykern/__init__.py +2621 -0
- cquda_continuumq-0.1.0/src/tinykern/__main__.py +66 -0
- cquda_continuumq-0.1.0/src/tinykern/fuzz.py +210 -0
- cquda_continuumq-0.1.0/tests/test_lib.py +130 -0
- cquda_continuumq-0.1.0/tests/test_packaging.py +73 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First public release.
|
|
6
|
+
|
|
7
|
+
- Kernel language: `@kernel`, 1D/2D/3D thread and block indices, `let`/`var`, masked `load`/`store`
|
|
8
|
+
(with a default value for masked-off loads), float4 `load4`/`store4`, atomics (`atomic_add`/`max`/`min`),
|
|
9
|
+
`if_`, `while_`, runtime `loop`, `shared` memory, `barrier`, warp shuffles and warp/block reductions,
|
|
10
|
+
math and bitwise ops.
|
|
11
|
+
- Optimiser: constant folding, algebraic simplification, CSE, `let` forwarding, dead-code elimination.
|
|
12
|
+
- CPU backend: the IR is compiled to NumPy source and run as lockstep SIMT, with bounds checking.
|
|
13
|
+
- PTX backend: PTX generation, plus an experimental GPU launcher through the CUDA driver API
|
|
14
|
+
(`DeviceArray`, JIT cache, CUDA-event timing).
|
|
15
|
+
- Ready-made kernels: `elementwise` (fused, float4 fast path), `reduce_sum/max/min`, `softmax`,
|
|
16
|
+
`layernorm`, `transpose`, `gemm`, `histogram`, `inclusive_scan`, `mandelbrot`, `autotune`.
|
|
17
|
+
- Command line: `python -m tinykern info | demo | fuzz`.
|
|
18
|
+
- `import cquda` is an alias for `import tinykern`.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CQUDA ContinuumQ contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cquda-continuumq
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Write CUDA-style kernels in Python: trace to an IR, run on NumPy (CPU SIMT emulation) or NVIDIA GPUs (PTX).
|
|
5
|
+
Author: Aliyev Islom/ContinuumQ
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://continuumq-aether.vercel.app/
|
|
8
|
+
Keywords: gpu,cuda,kernel,simt,ptx,numpy,compiler
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=1.21
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest; extra == "test"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# cquda-continuumq (tinykern)
|
|
31
|
+
|
|
32
|
+
Write CUDA-style kernels in Python. A kernel is written once as a Python function, traced into a small
|
|
33
|
+
IR, optimised, and executed by one of two backends:
|
|
34
|
+
|
|
35
|
+
| backend | what it does | needs |
|
|
36
|
+
|---------|-----------------------------------------------------------------------------|----------------------|
|
|
37
|
+
| CPU | the IR is compiled to NumPy source and run as lockstep SIMT on NumPy vectors | nothing but NumPy |
|
|
38
|
+
| GPU | PTX for NVIDIA GPUs through the CUDA driver API (**experimental**) | an NVIDIA driver |
|
|
39
|
+
|
|
40
|
+
The CPU backend is used whenever you pass NumPy arrays; the GPU backend is used when you pass `DeviceArray`s.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import numpy as np
|
|
44
|
+
from tinykern import kernel, Ptr, F32, I32, let, gid_x, load, store, cdiv
|
|
45
|
+
|
|
46
|
+
@kernel
|
|
47
|
+
def saxpy(x: Ptr, y: Ptr, out: Ptr, a: F32, n: I32):
|
|
48
|
+
i = let(gid_x())
|
|
49
|
+
store(out, i, a * load(x, i) + load(y, i), mask=i < n)
|
|
50
|
+
|
|
51
|
+
x = np.arange(10, dtype=np.float32)
|
|
52
|
+
out = np.zeros(10, np.float32)
|
|
53
|
+
saxpy(cdiv(10, 256), 256, x, x, out, 2.0, 10) # grid, block, then the arguments
|
|
54
|
+
assert np.allclose(out, 3 * x)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Install
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
pip install cquda-continuumq
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The distribution name is `cquda-continuumq`; you import it as `tinykern` or, equivalently, `cquda`.
|
|
64
|
+
Python 3.9+ and NumPy are required. No compiler and no GPU are needed.
|
|
65
|
+
|
|
66
|
+
## The kernel language
|
|
67
|
+
|
|
68
|
+
- Kernel arguments are annotated `Ptr` / `CPtr` (1-D contiguous `float32` array; `CPtr` is read-only),
|
|
69
|
+
`IPtr` / `CIPtr` (`int32` array), `F32` or `I32` (scalars).
|
|
70
|
+
- Thread and block indices: `tid_x/y/z`, `bid_x/y/z`, `bdim_x/y/z`, `gdim_x/y/z`, `gid_x/y/z`,
|
|
71
|
+
`tid_linear`, `lane_id`, `warp_id`. Grids and blocks may be an int or a tuple of up to three ints.
|
|
72
|
+
- Values: `let(expr)` / `var(init)` (mutable, use `v += x` or `v.set(x)`), `shared(n, dtype)` per-block
|
|
73
|
+
scratch memory.
|
|
74
|
+
- Memory: `load(ptr, idx, mask=..., other=...)`, `store(ptr, idx, value, mask=...)`, `load4` / `store4`
|
|
75
|
+
(float4), `atomic_add`, `atomic_max`, `atomic_min` (max/min on `int32`). `ptr[i]` and `ptr[i] = v` also work.
|
|
76
|
+
- Control flow: `with if_(cond):`, `with while_(cond):`, `for i in loop(a, b, step):` (runtime loops).
|
|
77
|
+
Plain Python `for`/`while` loops are unrolled at trace time. `barrier()` is `__syncthreads()`.
|
|
78
|
+
- Math: `+ - * / // % **`, comparisons, `& | ^ << >> ~`, `minimum`, `maximum`, `clamp`, `select`, `sqrt`,
|
|
79
|
+
`rsqrt`, `exp`, `exp2`, `log`, `log2`, `sin`, `cos`, `floor`, `ceil`, `trunc`, `rint`, `rcp`, `fabs`, `fma`,
|
|
80
|
+
`tanh`, `sigmoid`, `relu`, `gelu`, `i2f`, `f2i`.
|
|
81
|
+
- Warps: `shfl_xor/down/up/idx`, `warp_reduce`, `block_reduce`.
|
|
82
|
+
|
|
83
|
+
Python's `if`, `and`, `or` cannot be used on kernel values; use `with if_(...)` and `&` / `|` with
|
|
84
|
+
parenthesised comparisons. Kernel values are lazy expressions: use `let(...)` to snapshot a value that a
|
|
85
|
+
`var` will change later.
|
|
86
|
+
|
|
87
|
+
Inspect what is generated: `saxpy.dump()` (optimised IR), `saxpy.np_source()` (the NumPy code),
|
|
88
|
+
`saxpy.ptx()` (PTX text), `saxpy.stats()`.
|
|
89
|
+
|
|
90
|
+
## Ready-made kernels
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import tinykern as tk
|
|
94
|
+
tk.gemm(A, B, M, N, K) # row-major matrices, any size
|
|
95
|
+
tk.softmax(x, rows, cols) # row-wise
|
|
96
|
+
tk.layernorm(x, gamma, beta, rows, cols)
|
|
97
|
+
tk.transpose(a, rows, cols)
|
|
98
|
+
tk.reduce_sum(x); tk.reduce_max(x); tk.reduce_min(x)
|
|
99
|
+
tk.inclusive_scan(x); tk.histogram(ints, nbins)
|
|
100
|
+
tk.elementwise(lambda a, b: tk.relu(a * 2.0 - b), nin=2)(a, b) # fuse your own math into one kernel
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
They are written in the kernel language itself, so they double as examples. Float32 summation order differs
|
|
104
|
+
from NumPy's, so expect agreement to about 1e-4, not bit-for-bit. `tk.autotune(kernel, [(grid, block), ...], *args)`
|
|
105
|
+
times launch configurations and returns the fastest.
|
|
106
|
+
|
|
107
|
+
## Command line
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
python -m tinykern info # version and what hardware is available
|
|
111
|
+
python -m tinykern demo # run and verify the library kernels (add --ptx DIR to write PTX files)
|
|
112
|
+
python -m tinykern fuzz -n 25 # random kernels, compared with an independent NumPy evaluation
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Limitations
|
|
116
|
+
|
|
117
|
+
- The CPU backend emulates GPU threads with NumPy vectors. It is a correctness tool and a way to develop
|
|
118
|
+
kernels without a GPU, not a fast CPU compute engine.
|
|
119
|
+
- The GPU backend is experimental and untested in CI.
|
|
120
|
+
- Defining kernels from several threads at the same time is not supported (tracing uses global state).
|
|
121
|
+
- Arrays must be 1-D, contiguous `float32` (`int32` for `IPtr`). Blocks have at most 1024 threads and static
|
|
122
|
+
shared memory is limited to 48 KB per block. `histogram` supports up to 1024 bins.
|
|
123
|
+
|
|
124
|
+
## Trademarks and license
|
|
125
|
+
|
|
126
|
+
"CUDA" is a trademark of NVIDIA Corporation. This project is independent and is not affiliated with or
|
|
127
|
+
endorsed by NVIDIA. Released under the MIT License (see `LICENSE`).
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# cquda-continuumq (tinykern)
|
|
2
|
+
|
|
3
|
+
Write CUDA-style kernels in Python. A kernel is written once as a Python function, traced into a small
|
|
4
|
+
IR, optimised, and executed by one of two backends:
|
|
5
|
+
|
|
6
|
+
| backend | what it does | needs |
|
|
7
|
+
|---------|-----------------------------------------------------------------------------|----------------------|
|
|
8
|
+
| CPU | the IR is compiled to NumPy source and run as lockstep SIMT on NumPy vectors | nothing but NumPy |
|
|
9
|
+
| GPU | PTX for NVIDIA GPUs through the CUDA driver API (**experimental**) | an NVIDIA driver |
|
|
10
|
+
|
|
11
|
+
The CPU backend is used whenever you pass NumPy arrays; the GPU backend is used when you pass `DeviceArray`s.
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
import numpy as np
|
|
15
|
+
from tinykern import kernel, Ptr, F32, I32, let, gid_x, load, store, cdiv
|
|
16
|
+
|
|
17
|
+
@kernel
|
|
18
|
+
def saxpy(x: Ptr, y: Ptr, out: Ptr, a: F32, n: I32):
|
|
19
|
+
i = let(gid_x())
|
|
20
|
+
store(out, i, a * load(x, i) + load(y, i), mask=i < n)
|
|
21
|
+
|
|
22
|
+
x = np.arange(10, dtype=np.float32)
|
|
23
|
+
out = np.zeros(10, np.float32)
|
|
24
|
+
saxpy(cdiv(10, 256), 256, x, x, out, 2.0, 10) # grid, block, then the arguments
|
|
25
|
+
assert np.allclose(out, 3 * x)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
pip install cquda-continuumq
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The distribution name is `cquda-continuumq`; you import it as `tinykern` or, equivalently, `cquda`.
|
|
35
|
+
Python 3.9+ and NumPy are required. No compiler and no GPU are needed.
|
|
36
|
+
|
|
37
|
+
## The kernel language
|
|
38
|
+
|
|
39
|
+
- Kernel arguments are annotated `Ptr` / `CPtr` (1-D contiguous `float32` array; `CPtr` is read-only),
|
|
40
|
+
`IPtr` / `CIPtr` (`int32` array), `F32` or `I32` (scalars).
|
|
41
|
+
- Thread and block indices: `tid_x/y/z`, `bid_x/y/z`, `bdim_x/y/z`, `gdim_x/y/z`, `gid_x/y/z`,
|
|
42
|
+
`tid_linear`, `lane_id`, `warp_id`. Grids and blocks may be an int or a tuple of up to three ints.
|
|
43
|
+
- Values: `let(expr)` / `var(init)` (mutable, use `v += x` or `v.set(x)`), `shared(n, dtype)` per-block
|
|
44
|
+
scratch memory.
|
|
45
|
+
- Memory: `load(ptr, idx, mask=..., other=...)`, `store(ptr, idx, value, mask=...)`, `load4` / `store4`
|
|
46
|
+
(float4), `atomic_add`, `atomic_max`, `atomic_min` (max/min on `int32`). `ptr[i]` and `ptr[i] = v` also work.
|
|
47
|
+
- Control flow: `with if_(cond):`, `with while_(cond):`, `for i in loop(a, b, step):` (runtime loops).
|
|
48
|
+
Plain Python `for`/`while` loops are unrolled at trace time. `barrier()` is `__syncthreads()`.
|
|
49
|
+
- Math: `+ - * / // % **`, comparisons, `& | ^ << >> ~`, `minimum`, `maximum`, `clamp`, `select`, `sqrt`,
|
|
50
|
+
`rsqrt`, `exp`, `exp2`, `log`, `log2`, `sin`, `cos`, `floor`, `ceil`, `trunc`, `rint`, `rcp`, `fabs`, `fma`,
|
|
51
|
+
`tanh`, `sigmoid`, `relu`, `gelu`, `i2f`, `f2i`.
|
|
52
|
+
- Warps: `shfl_xor/down/up/idx`, `warp_reduce`, `block_reduce`.
|
|
53
|
+
|
|
54
|
+
Python's `if`, `and`, `or` cannot be used on kernel values; use `with if_(...)` and `&` / `|` with
|
|
55
|
+
parenthesised comparisons. Kernel values are lazy expressions: use `let(...)` to snapshot a value that a
|
|
56
|
+
`var` will change later.
|
|
57
|
+
|
|
58
|
+
Inspect what is generated: `saxpy.dump()` (optimised IR), `saxpy.np_source()` (the NumPy code),
|
|
59
|
+
`saxpy.ptx()` (PTX text), `saxpy.stats()`.
|
|
60
|
+
|
|
61
|
+
## Ready-made kernels
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import tinykern as tk
|
|
65
|
+
tk.gemm(A, B, M, N, K) # row-major matrices, any size
|
|
66
|
+
tk.softmax(x, rows, cols) # row-wise
|
|
67
|
+
tk.layernorm(x, gamma, beta, rows, cols)
|
|
68
|
+
tk.transpose(a, rows, cols)
|
|
69
|
+
tk.reduce_sum(x); tk.reduce_max(x); tk.reduce_min(x)
|
|
70
|
+
tk.inclusive_scan(x); tk.histogram(ints, nbins)
|
|
71
|
+
tk.elementwise(lambda a, b: tk.relu(a * 2.0 - b), nin=2)(a, b) # fuse your own math into one kernel
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
They are written in the kernel language itself, so they double as examples. Float32 summation order differs
|
|
75
|
+
from NumPy's, so expect agreement to about 1e-4, not bit-for-bit. `tk.autotune(kernel, [(grid, block), ...], *args)`
|
|
76
|
+
times launch configurations and returns the fastest.
|
|
77
|
+
|
|
78
|
+
## Command line
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
python -m tinykern info # version and what hardware is available
|
|
82
|
+
python -m tinykern demo # run and verify the library kernels (add --ptx DIR to write PTX files)
|
|
83
|
+
python -m tinykern fuzz -n 25 # random kernels, compared with an independent NumPy evaluation
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Limitations
|
|
87
|
+
|
|
88
|
+
- The CPU backend emulates GPU threads with NumPy vectors. It is a correctness tool and a way to develop
|
|
89
|
+
kernels without a GPU, not a fast CPU compute engine.
|
|
90
|
+
- The GPU backend is experimental and untested in CI.
|
|
91
|
+
- Defining kernels from several threads at the same time is not supported (tracing uses global state).
|
|
92
|
+
- Arrays must be 1-D, contiguous `float32` (`int32` for `IPtr`). Blocks have at most 1024 threads and static
|
|
93
|
+
shared memory is limited to 48 KB per block. `histogram` supports up to 1024 bins.
|
|
94
|
+
|
|
95
|
+
## Trademarks and license
|
|
96
|
+
|
|
97
|
+
"CUDA" is a trademark of NVIDIA Corporation. This project is independent and is not affiliated with or
|
|
98
|
+
endorsed by NVIDIA. Released under the MIT License (see `LICENSE`).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Releasing cquda-continuumq
|
|
2
|
+
|
|
3
|
+
All commands run from the project folder (the one containing `pyproject.toml`).
|
|
4
|
+
|
|
5
|
+
## One-time setup
|
|
6
|
+
|
|
7
|
+
1. Create accounts on https://pypi.org and https://test.pypi.org (they are separate) and enable 2FA.
|
|
8
|
+
2. Create an API token on each (Account settings -> API tokens). For the very first upload choose
|
|
9
|
+
scope "Entire account"; afterwards create a token limited to this project and delete the broad one.
|
|
10
|
+
3. Never put a token in a file or in git. `scripts/release.py` reads it from the `TWINE_PASSWORD`
|
|
11
|
+
environment variable or asks for it at a hidden prompt.
|
|
12
|
+
4. Edit `authors` in `pyproject.toml` if you want your own name on PyPI, and add a repository/issues link to `[project.urls]` when you have one.
|
|
13
|
+
|
|
14
|
+
## Every release
|
|
15
|
+
|
|
16
|
+
1. Change `__version__` in `src/tinykern/__init__.py` (the only place; `pyproject.toml` reads it).
|
|
17
|
+
2. Add a section for the version to `CHANGELOG.md`.
|
|
18
|
+
3. Dry run. Builds, runs `twine check`, installs the wheel into a fresh venv and tests it. Uploads nothing:
|
|
19
|
+
|
|
20
|
+
py scripts/release.py
|
|
21
|
+
|
|
22
|
+
On a machine without internet add `--offline-verify`.
|
|
23
|
+
4. Rehearse on TestPyPI:
|
|
24
|
+
|
|
25
|
+
py scripts/release.py --test-upload
|
|
26
|
+
|
|
27
|
+
5. Real upload (type `yes` when asked):
|
|
28
|
+
|
|
29
|
+
py scripts/release.py --upload
|
|
30
|
+
|
|
31
|
+
6. Tag the commit (`git tag v0.1.0 && git push --tags`) if you use git.
|
|
32
|
+
|
|
33
|
+
A version number can never be re-used on PyPI, even after deleting the release. If something is wrong,
|
|
34
|
+
bump the version and release again. A bad release can be "yanked" from the project's page on pypi.org.
|
|
35
|
+
|
|
36
|
+
## If the build complains about the license
|
|
37
|
+
|
|
38
|
+
`pyproject.toml` uses the modern SPDX form (`license = "MIT"` plus `license-files`), which needs
|
|
39
|
+
`setuptools>=77`. The isolated build downloads a new enough setuptools automatically. If you see an error
|
|
40
|
+
about `project.license` anyway:
|
|
41
|
+
|
|
42
|
+
- upgrade the build tools: `py -m pip install -U build setuptools twine`, or
|
|
43
|
+
- switch to the older form, replacing the two license lines in `pyproject.toml` with
|
|
44
|
+
`license = { file = "LICENSE" }` and the line `requires = ["setuptools>=61"]` in `[build-system]`.
|
|
45
|
+
(Old setuptools also wants the classifier `"License :: OSI Approved :: MIT License"`.)
|
|
46
|
+
|
|
47
|
+
## Trademark note
|
|
48
|
+
|
|
49
|
+
Keep the "independent, not affiliated with NVIDIA" wording in the README and docstrings.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "cquda-continuumq"
|
|
7
|
+
dynamic = ["version"] # read from src/tinykern/__init__.py (__version__)
|
|
8
|
+
description = "Write CUDA-style kernels in Python: trace to an IR, run on NumPy (CPU SIMT emulation) or NVIDIA GPUs (PTX)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Aliyev Islom/ContinuumQ" }]
|
|
14
|
+
keywords = ["gpu", "cuda", "kernel", "simt", "ptx", "numpy", "compiler"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.9",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Topic :: Scientific/Engineering",
|
|
28
|
+
"Topic :: Software Development :: Compilers",
|
|
29
|
+
]
|
|
30
|
+
dependencies = ["numpy>=1.21"]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
test = ["pytest"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://continuumq-aether.vercel.app/"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
tinykern = "tinykern.__main__:main"
|
|
40
|
+
cquda = "tinykern.__main__:main"
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.dynamic]
|
|
43
|
+
version = { attr = "tinykern.__version__" }
|
|
44
|
+
|
|
45
|
+
[tool.setuptools.packages.find]
|
|
46
|
+
where = ["src"]
|
|
47
|
+
include = ["tinykern*", "cquda*"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
51
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Release helper for cquda-continuumq.
|
|
4
|
+
|
|
5
|
+
py scripts/release.py # check, build, and test the built wheel in a fresh venv.
|
|
6
|
+
# Uploads NOTHING.
|
|
7
|
+
py scripts/release.py --test-upload # ... then upload to TestPyPI (https://test.pypi.org)
|
|
8
|
+
py scripts/release.py --upload # ... then upload to the real PyPI
|
|
9
|
+
|
|
10
|
+
Run it from the project folder (the one containing pyproject.toml).
|
|
11
|
+
|
|
12
|
+
Your API token is taken from the TWINE_PASSWORD environment variable, or typed at a hidden
|
|
13
|
+
prompt. It is passed to twine through the environment only: never printed, never written to disk.
|
|
14
|
+
Use a token created for this project (or "entire account" for the very first upload).
|
|
15
|
+
|
|
16
|
+
Options:
|
|
17
|
+
--yes do not ask for confirmation before uploading
|
|
18
|
+
--skip-verify skip the fresh-venv install test (faster; not recommended)
|
|
19
|
+
--offline-verify fresh venv re-uses already-installed numpy instead of downloading it
|
|
20
|
+
(for machines without internet; the real install path is not exercised)
|
|
21
|
+
"""
|
|
22
|
+
import argparse
|
|
23
|
+
import getpass
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import re
|
|
27
|
+
import shutil
|
|
28
|
+
import subprocess
|
|
29
|
+
import sys
|
|
30
|
+
import tempfile
|
|
31
|
+
import urllib.error
|
|
32
|
+
import urllib.request
|
|
33
|
+
|
|
34
|
+
ROOT = os.getcwd()
|
|
35
|
+
PLACEHOLDER_AUTHOR = "CQUDA ContinuumQ contributors"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def say(msg=""):
|
|
39
|
+
print(msg, flush=True)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def step(title):
|
|
43
|
+
say(f"\n== {title}")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def ok(msg):
|
|
47
|
+
say(f" OK {msg}")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def warn(msg):
|
|
51
|
+
say(f" WARN {msg}")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def die(msg, hint=None):
|
|
55
|
+
say(f" FAIL {msg}")
|
|
56
|
+
if hint:
|
|
57
|
+
say(f" {hint}")
|
|
58
|
+
sys.exit(1)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def run(cmd, **kw):
|
|
62
|
+
return subprocess.run(cmd, capture_output=True, text=True, **kw)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def tail(text, n=25):
|
|
66
|
+
return "\n".join(" | " + line for line in text.strip().splitlines()[-n:])
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# ------------------------------------------------------------------ project facts
|
|
70
|
+
def read_project():
|
|
71
|
+
pyproject = os.path.join(ROOT, "pyproject.toml")
|
|
72
|
+
if not os.path.exists(pyproject):
|
|
73
|
+
die("pyproject.toml not found", "run this script from the project folder")
|
|
74
|
+
text = open(pyproject, encoding="utf-8").read()
|
|
75
|
+
name = re.search(r'^name\s*=\s*"([^"]+)"', text, re.M)
|
|
76
|
+
init = os.path.join(ROOT, "src", "tinykern", "__init__.py")
|
|
77
|
+
version = re.search(r'^__version__\s*=\s*"([^"]+)"', open(init, encoding="utf-8").read(), re.M) \
|
|
78
|
+
if os.path.exists(init) else None
|
|
79
|
+
if not name or not version:
|
|
80
|
+
die("could not read the package name / __version__", "check pyproject.toml and src/tinykern/__init__.py")
|
|
81
|
+
return text, name.group(1), version.group(1)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def pypi_state(host, name, version):
|
|
85
|
+
"""('free'|'exists'|'unknown', version_already_uploaded)"""
|
|
86
|
+
url = f"https://{host}/pypi/{name}/json"
|
|
87
|
+
try:
|
|
88
|
+
with urllib.request.urlopen(url, timeout=20) as r:
|
|
89
|
+
data = json.load(r)
|
|
90
|
+
return "exists", version in data.get("releases", {})
|
|
91
|
+
except urllib.error.HTTPError as e:
|
|
92
|
+
return ("free", False) if e.code == 404 else ("unknown", False)
|
|
93
|
+
except Exception: # no network, DNS, proxy...
|
|
94
|
+
return "unknown", False
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# ------------------------------------------------------------------ steps
|
|
98
|
+
def check_metadata(pyproject_text, version):
|
|
99
|
+
step("1. Project metadata")
|
|
100
|
+
ok(f"version {version}")
|
|
101
|
+
if PLACEHOLDER_AUTHOR in pyproject_text:
|
|
102
|
+
warn(f'author is still "{PLACEHOLDER_AUTHOR}" - edit `authors` in pyproject.toml if you want your name on PyPI')
|
|
103
|
+
if "[project.urls]" not in re.sub(r"(?m)^#.*$", "", pyproject_text):
|
|
104
|
+
warn("no project URLs set (fine for a first release; add your repository link later)")
|
|
105
|
+
changelog = os.path.join(ROOT, "CHANGELOG.md")
|
|
106
|
+
if os.path.exists(changelog) and version not in open(changelog, encoding="utf-8").read():
|
|
107
|
+
warn(f"CHANGELOG.md does not mention {version}")
|
|
108
|
+
if not os.path.exists(os.path.join(ROOT, "LICENSE")):
|
|
109
|
+
die("LICENSE file is missing")
|
|
110
|
+
ok("LICENSE present")
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def check_name(host, name, version, label):
|
|
114
|
+
step(f"2. Is {name} {version} available on {label}?")
|
|
115
|
+
state, has_version = pypi_state(host, name, version)
|
|
116
|
+
if state == "free":
|
|
117
|
+
ok("name is free - you will create the project with this upload")
|
|
118
|
+
elif state == "exists" and has_version:
|
|
119
|
+
die(f"{name} {version} is already on {label}; a version can never be re-uploaded",
|
|
120
|
+
"bump the version in src/tinykern/__init__.py (and CHANGELOG.md), then run again")
|
|
121
|
+
elif state == "exists":
|
|
122
|
+
warn(f"the project {name} already exists on {label}. The upload only works if your token belongs to its owner.")
|
|
123
|
+
else:
|
|
124
|
+
warn(f"could not reach {host} to check (offline?). Continuing; the upload step will tell you if the name is taken.")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def ensure_tools():
|
|
128
|
+
step("3. Build tools")
|
|
129
|
+
missing = []
|
|
130
|
+
for mod in ("build", "twine"):
|
|
131
|
+
if run([sys.executable, "-c", f"import {mod}"]).returncode != 0:
|
|
132
|
+
missing.append(mod)
|
|
133
|
+
if missing:
|
|
134
|
+
say(f" installing: {', '.join(missing)}")
|
|
135
|
+
r = run([sys.executable, "-m", "pip", "install", "-U", *missing])
|
|
136
|
+
if r.returncode != 0:
|
|
137
|
+
die("could not install " + " and ".join(missing), "run: py -m pip install -U build twine\n" + tail(r.stdout + r.stderr))
|
|
138
|
+
ok("build and twine available")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def build():
|
|
142
|
+
step("4. Build wheel and source distribution")
|
|
143
|
+
for d in ("dist", "build"):
|
|
144
|
+
shutil.rmtree(os.path.join(ROOT, d), ignore_errors=True)
|
|
145
|
+
for egg in [p for p in os.listdir(os.path.join(ROOT, "src")) if p.endswith(".egg-info")] if os.path.isdir(os.path.join(ROOT, "src")) else []:
|
|
146
|
+
shutil.rmtree(os.path.join(ROOT, "src", egg), ignore_errors=True)
|
|
147
|
+
r = run([sys.executable, "-m", "build"], cwd=ROOT)
|
|
148
|
+
if r.returncode != 0:
|
|
149
|
+
out = r.stdout + r.stderr
|
|
150
|
+
hint = None
|
|
151
|
+
if "license" in out.lower():
|
|
152
|
+
hint = ("the error mentions the license field: see RELEASING.md, section 'If the build complains about the license'")
|
|
153
|
+
die("build failed", hint)
|
|
154
|
+
files = sorted(os.listdir(os.path.join(ROOT, "dist")))
|
|
155
|
+
if not any(f.endswith(".whl") for f in files) or not any(f.endswith(".tar.gz") for f in files):
|
|
156
|
+
die("build did not produce both a wheel and an sdist", ", ".join(files))
|
|
157
|
+
for f in files:
|
|
158
|
+
ok(f"{f} ({os.path.getsize(os.path.join(ROOT, 'dist', f)) // 1024} KiB)")
|
|
159
|
+
return [os.path.join(ROOT, "dist", f) for f in files]
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def twine_check(files):
|
|
163
|
+
step("5. twine check (README renders on PyPI, metadata valid)")
|
|
164
|
+
r = run([sys.executable, "-m", "twine", "check", *files])
|
|
165
|
+
if r.returncode != 0:
|
|
166
|
+
die("twine check failed", None if not (r.stdout + r.stderr) else "\n" + tail(r.stdout + r.stderr))
|
|
167
|
+
ok("metadata and description are valid")
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def verify_in_fresh_venv(files, offline):
|
|
171
|
+
step("6. Install the built wheel into a brand-new virtual environment and run it")
|
|
172
|
+
wheel = next(f for f in files if f.endswith(".whl"))
|
|
173
|
+
tmp = tempfile.mkdtemp(prefix="cquda_verify_")
|
|
174
|
+
try:
|
|
175
|
+
venv_dir = os.path.join(tmp, "venv")
|
|
176
|
+
args = [sys.executable, "-m", "venv", venv_dir] + (["--system-site-packages"] if offline else [])
|
|
177
|
+
if run(args).returncode != 0:
|
|
178
|
+
die("could not create a virtual environment")
|
|
179
|
+
py = os.path.join(venv_dir, "Scripts" if os.name == "nt" else "bin", "python" + (".exe" if os.name == "nt" else ""))
|
|
180
|
+
pip = [py, "-m", "pip", "install", "--disable-pip-version-check"]
|
|
181
|
+
r = run(pip + (["--no-deps", "--no-index"] if offline else []) + [wheel])
|
|
182
|
+
if r.returncode != 0:
|
|
183
|
+
die("pip could not install the built wheel", "\n" + tail(r.stdout + r.stderr))
|
|
184
|
+
ok("wheel installs" + (" (offline mode: numpy taken from this Python)" if offline else " with its dependencies from PyPI"))
|
|
185
|
+
env = dict(os.environ)
|
|
186
|
+
env.pop("PYTHONPATH", None)
|
|
187
|
+
checks = [
|
|
188
|
+
("import + version", [py, "-c", "import tinykern, cquda; assert cquda is tinykern; print(tinykern.__version__)"]),
|
|
189
|
+
("cquda info", [py, "-m", "tinykern", "info"]),
|
|
190
|
+
("demo kernels (saxpy, gemm, reductions, ...)", [py, "-m", "tinykern", "demo"]),
|
|
191
|
+
("kernel library", [py, "-c", "import numpy as np, tinykern as tk; a=np.eye(3,dtype=np.float32).reshape(-1); assert np.allclose(tk.gemm(a,a,3,3,3),a); assert np.allclose(tk.softmax(np.zeros(4,np.float32),1,4),0.25)"]),
|
|
192
|
+
("backend self-check (fuzz 15 random kernels)", [py, "-m", "tinykern", "fuzz", "-n", "15"]),
|
|
193
|
+
]
|
|
194
|
+
for label, cmd in checks:
|
|
195
|
+
r = run(cmd, cwd=tmp, env=env) # run from an unrelated folder: only the installed copy is visible
|
|
196
|
+
if r.returncode != 0:
|
|
197
|
+
die(f"{label} failed in the clean environment", "\n" + tail(r.stdout + r.stderr))
|
|
198
|
+
ok(label)
|
|
199
|
+
src_copy = run([py, "-c", "import tinykern; print(tinykern.__file__)"], cwd=tmp, env=env).stdout.strip()
|
|
200
|
+
if os.path.abspath(ROOT) in os.path.abspath(src_copy):
|
|
201
|
+
die("the clean environment imported the source tree, not the installed wheel", src_copy)
|
|
202
|
+
ok("tests ran against the installed wheel, not the source tree")
|
|
203
|
+
finally:
|
|
204
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def upload(files, test, assume_yes, name, version):
|
|
208
|
+
host_label = "TestPyPI" if test else "PyPI"
|
|
209
|
+
step(f"7. Upload to {host_label}")
|
|
210
|
+
say(f" About to upload {name} {version} ({len(files)} files) to {host_label}.")
|
|
211
|
+
if not test:
|
|
212
|
+
say(" This is the REAL PyPI. A version number can never be re-used, even if you delete the release.")
|
|
213
|
+
if not assume_yes and input(" Type 'yes' to continue: ").strip().lower() != "yes":
|
|
214
|
+
say(" Cancelled. Nothing was uploaded.")
|
|
215
|
+
return False
|
|
216
|
+
token = os.environ.get("TWINE_PASSWORD") or getpass.getpass(" Paste your API token (input hidden): ").strip()
|
|
217
|
+
if not token.startswith("pypi-"):
|
|
218
|
+
die("that does not look like a PyPI API token (they start with 'pypi-')")
|
|
219
|
+
env = dict(os.environ, TWINE_USERNAME="__token__", TWINE_PASSWORD=token)
|
|
220
|
+
cmd = [sys.executable, "-m", "twine", "upload", "--non-interactive"]
|
|
221
|
+
if test:
|
|
222
|
+
cmd += ["--repository-url", "https://test.pypi.org/legacy/"]
|
|
223
|
+
r = run(cmd + files, env=env)
|
|
224
|
+
out = (r.stdout + r.stderr).replace(token, "<token hidden>")
|
|
225
|
+
if r.returncode != 0:
|
|
226
|
+
hint = None
|
|
227
|
+
low = out.lower()
|
|
228
|
+
if "403" in low or "invalid or non-existent authentication" in low:
|
|
229
|
+
hint = "403: the token is wrong, belongs to another account, or is scoped to a different project"
|
|
230
|
+
elif "already exists" in low or "filename has already been used" in low:
|
|
231
|
+
hint = "that version is already uploaded - bump the version number"
|
|
232
|
+
elif "isn't allowed to upload" in low or "name is too similar" in low or "not allowed" in low:
|
|
233
|
+
hint = "PyPI refused the project name (taken or too similar to an existing one)"
|
|
234
|
+
die("upload failed", (hint + "\n" if hint else "") + tail(out))
|
|
235
|
+
ok("uploaded")
|
|
236
|
+
base = "https://test.pypi.org" if test else "https://pypi.org"
|
|
237
|
+
say(f"\n Page: {base}/project/{name}/")
|
|
238
|
+
if test:
|
|
239
|
+
say(f" Install: pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ {name}")
|
|
240
|
+
else:
|
|
241
|
+
say(f" Install: pip install {name} (can take a minute to appear)")
|
|
242
|
+
return True
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def main():
|
|
246
|
+
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
247
|
+
ap.add_argument("--upload", action="store_true", help="upload to the real PyPI after all checks pass")
|
|
248
|
+
ap.add_argument("--test-upload", action="store_true", help="upload to TestPyPI after all checks pass")
|
|
249
|
+
ap.add_argument("--yes", action="store_true", help="do not ask for confirmation before uploading")
|
|
250
|
+
ap.add_argument("--skip-verify", action="store_true", help="skip the fresh-venv install test")
|
|
251
|
+
ap.add_argument("--offline-verify", action="store_true", help="fresh venv re-uses installed numpy (no downloads)")
|
|
252
|
+
args = ap.parse_args()
|
|
253
|
+
if args.upload and args.test_upload:
|
|
254
|
+
die("choose either --upload or --test-upload, not both")
|
|
255
|
+
if sys.version_info < (3, 9):
|
|
256
|
+
die("Python 3.9 or newer is required")
|
|
257
|
+
|
|
258
|
+
text, name, version = read_project()
|
|
259
|
+
check_metadata(text, version)
|
|
260
|
+
if args.upload or args.test_upload:
|
|
261
|
+
check_name("test.pypi.org" if args.test_upload else "pypi.org", name, version,
|
|
262
|
+
"TestPyPI" if args.test_upload else "PyPI")
|
|
263
|
+
ensure_tools()
|
|
264
|
+
files = build()
|
|
265
|
+
twine_check(files)
|
|
266
|
+
if args.skip_verify:
|
|
267
|
+
warn("skipped the fresh-venv test (--skip-verify)")
|
|
268
|
+
else:
|
|
269
|
+
verify_in_fresh_venv(files, args.offline_verify)
|
|
270
|
+
|
|
271
|
+
if args.upload or args.test_upload:
|
|
272
|
+
upload(files, args.test_upload, args.yes, name, version)
|
|
273
|
+
else:
|
|
274
|
+
say("\nAll checks passed. Nothing was uploaded (no --upload / --test-upload flag).")
|
|
275
|
+
say("Next: py scripts/release.py --test-upload (rehearsal on TestPyPI)")
|
|
276
|
+
say(" py scripts/release.py --upload (the real thing)")
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
if __name__ == "__main__":
|
|
280
|
+
main()
|