python-parsec 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.
- python_parsec-0.1.0/CHANGELOG.md +79 -0
- python_parsec-0.1.0/LICENSE +40 -0
- python_parsec-0.1.0/MANIFEST.in +7 -0
- python_parsec-0.1.0/PKG-INFO +328 -0
- python_parsec-0.1.0/README.md +299 -0
- python_parsec-0.1.0/benchmarks/c_overhead.c +140 -0
- python_parsec-0.1.0/benchmarks/overhead.py +121 -0
- python_parsec-0.1.0/examples/dtd_gemm.py +131 -0
- python_parsec-0.1.0/examples/redistribute.py +81 -0
- python_parsec-0.1.0/pyproject.toml +50 -0
- python_parsec-0.1.0/setup.cfg +4 -0
- python_parsec-0.1.0/setup.py +119 -0
- python_parsec-0.1.0/src/py_parsec/__init__.py +60 -0
- python_parsec-0.1.0/src/py_parsec/cparsec.pxd +201 -0
- python_parsec-0.1.0/src/py_parsec/dtd.pyx +1018 -0
- python_parsec-0.1.0/src/py_parsec/matrix.pxd +43 -0
- python_parsec-0.1.0/src/py_parsec/matrix.pyx +417 -0
- python_parsec-0.1.0/src/py_parsec/pyparsec.h +409 -0
- python_parsec-0.1.0/src/py_parsec/runtime.pxd +95 -0
- python_parsec-0.1.0/src/py_parsec/runtime.pyx +688 -0
- python_parsec-0.1.0/src/python_parsec.egg-info/PKG-INFO +328 -0
- python_parsec-0.1.0/src/python_parsec.egg-info/SOURCES.txt +29 -0
- python_parsec-0.1.0/src/python_parsec.egg-info/dependency_links.txt +1 -0
- python_parsec-0.1.0/src/python_parsec.egg-info/requires.txt +4 -0
- python_parsec-0.1.0/src/python_parsec.egg-info/top_level.txt +1 -0
- python_parsec-0.1.0/tests/conftest.py +67 -0
- python_parsec-0.1.0/tests/test_dtd.py +699 -0
- python_parsec-0.1.0/tests/test_matrix.py +91 -0
- python_parsec-0.1.0/tests/test_process.py +101 -0
- python_parsec-0.1.0/tests/test_redistribute.py +183 -0
- python_parsec-0.1.0/tests/test_runtime.py +84 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to py-parsec are listed here. The project follows
|
|
4
|
+
[semantic versioning](https://semver.org); until 1.0, minor versions may
|
|
5
|
+
change the API.
|
|
6
|
+
|
|
7
|
+
## 0.1.0 (2026-11-26)
|
|
8
|
+
|
|
9
|
+
First release, moved out of the PaRSEC repository (ICLDisco/parsec#834,
|
|
10
|
+
which replaced ICLDisco/parsec#765) into a standalone package built against
|
|
11
|
+
an installed PaRSEC. Published on PyPI as `python-parsec`; the module is
|
|
12
|
+
`py_parsec`.
|
|
13
|
+
|
|
14
|
+
- `Context` (`parsec_init` / `parsec_fini`), one per process; compute
|
|
15
|
+
threads start when work is scheduled, `wait()` completes every taskpool.
|
|
16
|
+
- `Taskpool` for every DSL: DTD taskpools, PTG taskpools from library calls,
|
|
17
|
+
and C-built taskpools through `Taskpool.from_address`, all in one context.
|
|
18
|
+
- `BlockCyclic` tiled matrices with tiles exposed as NumPy views, shared by
|
|
19
|
+
DTD and PTG taskpools; `redistribute_new` (PTG) and `redistribute_dtd`.
|
|
20
|
+
- DTD task classes with `Data` / `Value` parameters, Python bodies (CPU) and
|
|
21
|
+
C chores (any device), `insert_task`, batched `insert_tasks`, tiles given
|
|
22
|
+
as `(matrix, m, n)` tuples, read-only views for `INPUT` tiles, exceptions
|
|
23
|
+
of bodies raised by the next wait.
|
|
24
|
+
- Lifetimes: the context keeps taskpools until their work completes;
|
|
25
|
+
finalizers never call PaRSEC, releases are deferred to the next runtime
|
|
26
|
+
call from the thread that created the context, outside of calls that may
|
|
27
|
+
run tasks. `insert_tasks` behaves exactly like a loop of `insert_task`,
|
|
28
|
+
also when its iterable inserts, flushes or waits.
|
|
29
|
+
- Import fails with a clear message when the loaded `libparsec` is not the
|
|
30
|
+
build the extension modules were compiled against, and the modules are
|
|
31
|
+
rebuilt when that PaRSEC changes.
|
|
32
|
+
|
|
33
|
+
Changes from the version reviewed in ICLDisco/parsec#834:
|
|
34
|
+
|
|
35
|
+
- `redistribute_*` reject matrices other than float64 instead of corrupting
|
|
36
|
+
them (the PaRSEC kernels are compiled for double).
|
|
37
|
+
- `Taskpool.wait()` on a PTG taskpool works on a single process: the
|
|
38
|
+
communication engine is made ready when the context is created
|
|
39
|
+
(ICLDisco/parsec#836 fixes this in PaRSEC).
|
|
40
|
+
- No blocking call from finalizers: a taskpool with work pending is kept by
|
|
41
|
+
its context, and collected taskpools are released by the next runtime call.
|
|
42
|
+
- Inserting or flushing on an idle context starts it instead of hanging once
|
|
43
|
+
the DTD window is full.
|
|
44
|
+
- `redistribute_dtd` first completes the other taskpools of the context,
|
|
45
|
+
with the flushes and error reporting of `Context.wait()`.
|
|
46
|
+
- The variadic DTD calls are made with the exact number of arguments
|
|
47
|
+
instead of 64 padded pairs; per-insert validation is cached; body
|
|
48
|
+
arguments are built with one array allocation per tile; PaRSEC worker
|
|
49
|
+
threads keep their Python thread state; `insert_tasks` converts tasks in
|
|
50
|
+
batches and inserts them without the GIL. In the same conditions, the
|
|
51
|
+
binding adds 0.5 to 0.7 us per insertion over C instead of 1.0 to 1.6 us
|
|
52
|
+
(0.2 to 0.3 us with `insert_tasks`), an empty Python body on 8 workers
|
|
53
|
+
costs 8.1 us per task instead of 25.5 us (6.0 us with `insert_tasks`), and
|
|
54
|
+
the GEMM example with 128 x 128 tiles and the same body runs at 143
|
|
55
|
+
GFlop/s instead of 56 on 16 cores.
|
|
56
|
+
- All exceptions raised by bodies are reported (the first is raised with a
|
|
57
|
+
note counting the others).
|
|
58
|
+
- A second `Context` raises an error instead of crashing in `parsec_init`.
|
|
59
|
+
- Matrices are released like taskpools (never from a finalizer), and their
|
|
60
|
+
storage outlives the context while tile arrays refer to it, so results can
|
|
61
|
+
be read after a `with` block.
|
|
62
|
+
- Saved exceptions of task bodies no longer keep the body's locals, which
|
|
63
|
+
are arrays over data copies that do not outlive the task.
|
|
64
|
+
- The GEMM example verifies correctly when the matrix size is not a multiple
|
|
65
|
+
of the tile size, and keeps its update column-major (`c += (b.T @ a.T).T`),
|
|
66
|
+
which doubles the speed of its body with 128 x 128 tiles.
|
|
67
|
+
- Calls into the runtime from a thread other than the one that created the
|
|
68
|
+
context, or from a task body, raise `RuntimeError` instead of crashing or
|
|
69
|
+
hanging. A context whose thread has ended is still finalized at exit.
|
|
70
|
+
- An exception of a task body no longer makes `redistribute_dtd` skip the
|
|
71
|
+
collective copy on that rank (the other ranks waited for good): it is
|
|
72
|
+
raised after the copy.
|
|
73
|
+
- `add_chore` raises past the 24 task classes a DTD taskpool can hold
|
|
74
|
+
(`dtd.MAX_TASK_CLASSES`), where PaRSEC aborted the process.
|
|
75
|
+
- `TiledMatrix.release()` raises while a taskpool whose work no wait has
|
|
76
|
+
completed uses the matrix, instead of aborting or freeing tiles PaRSEC
|
|
77
|
+
still holds.
|
|
78
|
+
- Empty matrices, `Param` subclasses, parameters and tiles created without
|
|
79
|
+
their constructor are rejected instead of crashing in PaRSEC.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
BSD 3-Clause Open MPI variant (BSD-3-Clause-Open-MPI), the license of PaRSEC
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The University of Tennessee and The University
|
|
4
|
+
of Tennessee Research Foundation. All rights
|
|
5
|
+
reserved.
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are
|
|
9
|
+
met:
|
|
10
|
+
|
|
11
|
+
- Redistributions of source code must retain the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer.
|
|
13
|
+
|
|
14
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer listed
|
|
16
|
+
in this license in the documentation and/or other materials
|
|
17
|
+
provided with the distribution.
|
|
18
|
+
|
|
19
|
+
- Neither the name of the copyright holders nor the names of its
|
|
20
|
+
contributors may be used to endorse or promote products derived from
|
|
21
|
+
this software without specific prior written permission.
|
|
22
|
+
|
|
23
|
+
The copyright holders provide no reassurances that the source code
|
|
24
|
+
provided does not infringe any patent, copyright, or any other
|
|
25
|
+
intellectual property rights of third parties. The copyright holders
|
|
26
|
+
disclaim any liability to any recipient for claims brought against
|
|
27
|
+
recipient by any third party for infringement of that parties
|
|
28
|
+
intellectual property rights.
|
|
29
|
+
|
|
30
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
31
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
32
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
33
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
34
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
35
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
36
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
37
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
38
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
39
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
40
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-parsec
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python bindings for the PaRSEC task-based runtime system
|
|
5
|
+
Author: Qinglei Cao
|
|
6
|
+
License-Expression: BSD-3-Clause-Open-MPI
|
|
7
|
+
Project-URL: Homepage, https://github.com/QingleiCao/py-parsec
|
|
8
|
+
Project-URL: Issues, https://github.com/QingleiCao/py-parsec/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/QingleiCao/py-parsec/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: PaRSEC, https://github.com/ICLDisco/parsec
|
|
11
|
+
Keywords: parsec,task-based runtime,dataflow,DTD,PTG,MPI,HPC
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Programming Language :: C
|
|
17
|
+
Classifier: Programming Language :: Cython
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=1.23
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# py-parsec
|
|
31
|
+
|
|
32
|
+
[](https://github.com/QingleiCao/py-parsec/actions/workflows/ci.yml)
|
|
33
|
+
|
|
34
|
+
Python bindings for [PaRSEC](https://github.com/ICLDisco/parsec), the
|
|
35
|
+
task-based runtime system for distributed heterogeneous architectures.
|
|
36
|
+
|
|
37
|
+
The bindings follow the C API closely and keep its structure: one context
|
|
38
|
+
per process, one kind of taskpool for every DSL, and data collections that
|
|
39
|
+
are not tied to a DSL. Task bodies are Python callables (NumPy, SciPy, ...)
|
|
40
|
+
or C function pointers, and the same program runs on one process or under
|
|
41
|
+
`mpiexec`.
|
|
42
|
+
|
|
43
|
+
| Python | C |
|
|
44
|
+
| --- | --- |
|
|
45
|
+
| `py_parsec.Context(nb_cores, args)` | `parsec_init` / `parsec_fini` |
|
|
46
|
+
| `ctx.add_taskpool(tp)`, `ctx.start()`, `ctx.wait()` | `parsec_context_add_taskpool`, `parsec_context_start`, `parsec_context_wait` |
|
|
47
|
+
| `py_parsec.Taskpool`: `wait()`, `free()`, `from_address()` | a `parsec_taskpool_t` of any DSL |
|
|
48
|
+
| `py_parsec.BlockCyclic(ctx, m, n, mb, nb, dtype, P)` | `parsec_matrix_block_cyclic_t` |
|
|
49
|
+
| `py_parsec.dtd.Taskpool()` | `parsec_dtd_taskpool_new` |
|
|
50
|
+
| `tp.task_class(name, dtd.Data(...), dtd.Value(...))`, `tc.add_chore(dev, body)` | `parsec_dtd_create_task_class`, `parsec_dtd_task_class_add_chore` |
|
|
51
|
+
| `tp.insert_task(tc, (A, m, n), 3)`, `tp.insert_tasks(tc, iterable)` | `parsec_dtd_insert_task_with_task_class` |
|
|
52
|
+
| `tp.data_flush_all(A)` | `parsec_dtd_data_flush_all` |
|
|
53
|
+
| `py_parsec.matrix.redistribute_new(src, dst, ...)` | `parsec_redistribute_New` (a PTG taskpool) |
|
|
54
|
+
|
|
55
|
+
## Example
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import py_parsec
|
|
59
|
+
from py_parsec import dtd
|
|
60
|
+
|
|
61
|
+
with py_parsec.Context() as ctx:
|
|
62
|
+
A = py_parsec.BlockCyclic(ctx, 1000, 1000, 100, 100, name="A")
|
|
63
|
+
tp = dtd.Taskpool()
|
|
64
|
+
ctx.add_taskpool(tp)
|
|
65
|
+
|
|
66
|
+
scale = tp.task_class("scale", dtd.Data(dtd.INOUT | dtd.AFFINITY, A), dtd.Value("d"))
|
|
67
|
+
|
|
68
|
+
def body(tile, alpha): # tile: (100, 100) column-major view of the PaRSEC data
|
|
69
|
+
tile *= alpha
|
|
70
|
+
|
|
71
|
+
scale.add_chore(py_parsec.DEV_CPU, body)
|
|
72
|
+
for m in range(A.mt):
|
|
73
|
+
for n in range(A.nt):
|
|
74
|
+
tp.insert_task(scale, (A, m, n), 2.0)
|
|
75
|
+
tp.wait() # flushes A, then completes the tasks
|
|
76
|
+
|
|
77
|
+
for m, n, tile in A.local_tiles(): # the tiles owned by this process
|
|
78
|
+
...
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Run it with `python example.py` or `mpiexec -n 4 python example.py`. More in
|
|
82
|
+
[`examples/`](examples): a tiled GEMM (`dtd_gemm.py`) and DTD and PTG
|
|
83
|
+
taskpools working on the same data (`redistribute.py`).
|
|
84
|
+
|
|
85
|
+
## Requirements
|
|
86
|
+
|
|
87
|
+
- PaRSEC from its `master` branch, 2026-11-07 or later (4.1.0 development
|
|
88
|
+
version, which includes ICLDisco/parsec#840), built as a shared library
|
|
89
|
+
(`-DBUILD_SHARED_LIBS=ON`) with its development headers
|
|
90
|
+
(`-DPARSEC_WITH_DEVEL_HEADERS=ON`, the default). MPI support is optional.
|
|
91
|
+
- Python 3.10 or later and NumPy.
|
|
92
|
+
- To build: a C compiler, `pkg-config`, Cython 3 (installed automatically by
|
|
93
|
+
`pip`).
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
Point `PARSEC_ROOT` at the PaRSEC installation prefix (the directory that
|
|
98
|
+
holds `lib/pkgconfig/parsec.pc` or `lib64/pkgconfig/parsec.pc`):
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
PARSEC_ROOT=/path/to/parsec/install pip install python-parsec
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The PyPI package is named `python-parsec`, because PyPI treats `py-parsec` as
|
|
105
|
+
the same name as the unrelated `pyparsec` project; it installs the
|
|
106
|
+
`py_parsec` module.
|
|
107
|
+
|
|
108
|
+
or, from a clone of this repository:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
PARSEC_ROOT=/path/to/parsec/install pip install .
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The build reads the PaRSEC flags from `pkg-config parsec` and links the
|
|
115
|
+
extension modules with `libparsec`, with a run path to it. `CC` selects the C
|
|
116
|
+
compiler. Without a pkg-config file, set `PARSEC_INCLUDE_DIRS` and
|
|
117
|
+
`PARSEC_LIBRARY_DIRS` instead (`os.pathsep`-separated lists).
|
|
118
|
+
|
|
119
|
+
The bindings read some PaRSEC structures directly, whose layout depends on
|
|
120
|
+
how PaRSEC was configured, so py-parsec must run with the PaRSEC build it
|
|
121
|
+
was compiled against: importing it with another `libparsec` (another commit,
|
|
122
|
+
or the same commit configured again) raises an `ImportError` that says so.
|
|
123
|
+
Reinstall py-parsec after rebuilding PaRSEC.
|
|
124
|
+
|
|
125
|
+
## Concepts
|
|
126
|
+
|
|
127
|
+
### The context
|
|
128
|
+
|
|
129
|
+
`py_parsec.Context(nb_cores=-1, args=None)` initializes PaRSEC; `nb_cores`
|
|
130
|
+
counts the calling thread, and `args` are PaRSEC options (for instance
|
|
131
|
+
`["--mca", "runtime_comm_short_limit", "0"]`). PaRSEC can be initialized once
|
|
132
|
+
per process, so create one context and keep it for the whole run. It is
|
|
133
|
+
finalized by `fini()`, at the end of a `with` block, or at interpreter exit;
|
|
134
|
+
finalizing completes and releases every taskpool and matrix. PaRSEC
|
|
135
|
+
initializes MPI if the application has not, and then finalizes it in
|
|
136
|
+
`fini()`: import `mpi4py.MPI` before creating the context to keep using MPI
|
|
137
|
+
after that.
|
|
138
|
+
|
|
139
|
+
The compute threads start when work is scheduled (`ctx.start()` starts them
|
|
140
|
+
explicitly, for instance to let PTG taskpools run while Python does something
|
|
141
|
+
else). `ctx.wait()` completes every taskpool of the context and leaves the
|
|
142
|
+
threads idle; `tp.wait()` completes one taskpool and leaves the others
|
|
143
|
+
running.
|
|
144
|
+
|
|
145
|
+
### Taskpools
|
|
146
|
+
|
|
147
|
+
Every DSL produces a `parsec_taskpool_t`, wrapped by `py_parsec.Taskpool`.
|
|
148
|
+
DTD taskpools (`py_parsec.dtd.Taskpool`), PTG taskpools returned by library
|
|
149
|
+
calls (`py_parsec.matrix.redistribute_new`), and taskpools built by C code
|
|
150
|
+
(`Taskpool.from_address(addr, keepalive=...)`, for instance a JDF compiled
|
|
151
|
+
into its own library) are added to the context and waited the same way.
|
|
152
|
+
`Context.address` and `TiledMatrix.address` hand the context and the
|
|
153
|
+
matrices to such C code.
|
|
154
|
+
|
|
155
|
+
A taskpool can be dropped at any time: the context keeps it until a wait has
|
|
156
|
+
completed its work, and it is released afterwards. `tp.free()` completes and
|
|
157
|
+
releases it right away. No PaRSEC function is ever called from a Python
|
|
158
|
+
finalizer: taskpools and matrices collected by Python are released by the
|
|
159
|
+
next call into the runtime from the thread that created the context.
|
|
160
|
+
|
|
161
|
+
Only the thread that created the context can drive the runtime (insert,
|
|
162
|
+
flush, wait, free, release a matrix): PaRSEC identifies its callers by an
|
|
163
|
+
execution stream that only that thread has. Calls from other threads, and
|
|
164
|
+
from task bodies, raise `RuntimeError`. If that thread has ended when the
|
|
165
|
+
interpreter exits, the exit handler takes over its role to finalize the
|
|
166
|
+
context.
|
|
167
|
+
|
|
168
|
+
### Matrices
|
|
169
|
+
|
|
170
|
+
`py_parsec.BlockCyclic(ctx, m, n, mb, nb, dtype=np.float64, P=None, ...)` is
|
|
171
|
+
a 2D block-cyclic tiled matrix (float32, float64, complex64, complex128,
|
|
172
|
+
int32, int8 or uint8) over a `P x Q` process grid. Its local tiles are
|
|
173
|
+
allocated and zeroed; `A.tile(m, n)` and `A.local_tiles()` give them as
|
|
174
|
+
`(mb, nb)` Fortran-ordered NumPy arrays that share the PaRSEC storage. The
|
|
175
|
+
same matrix can be used by DTD and PTG taskpools. A matrix and its storage
|
|
176
|
+
live as long as the matrix object or one of its tile arrays; `A.release()`
|
|
177
|
+
frees them earlier, once no taskpool that used the matrix has work that no
|
|
178
|
+
wait has completed (it raises `RuntimeError` otherwise). Once the context is finalized, the tile arrays still
|
|
179
|
+
hold their data (to read results after a `with` block), but the matrix can
|
|
180
|
+
no longer be used by tasks.
|
|
181
|
+
|
|
182
|
+
### DTD
|
|
183
|
+
|
|
184
|
+
A task class lists its parameters: `dtd.Data(mode, like=A)` (or
|
|
185
|
+
`shape=(mb, nb), dtype=...`) for a tile, where the mode is `dtd.INPUT`,
|
|
186
|
+
`dtd.OUTPUT` or `dtd.INOUT`, possibly with `dtd.AFFINITY` (run the task where
|
|
187
|
+
this tile lives; tasks that write data need it in distributed runs),
|
|
188
|
+
`dtd.DONT_TRACK`, `dtd.PUSHOUT` or `dtd.PULLIN`; and `dtd.Value(fmt)` for a
|
|
189
|
+
number passed by value, `fmt` being a `struct` code among `b B h H i I l L q
|
|
190
|
+
Q f d`.
|
|
191
|
+
|
|
192
|
+
- `tp.insert_task(tc, *args, priority=0, device=DEV_ALL)` inserts one task.
|
|
193
|
+
A tile argument is `(A, m, n)`, `(A, m, n, flags)` (flags added for this
|
|
194
|
+
insertion only, such as `dtd.PUSHOUT`) or `dtd.tile_of(A, m, n)`.
|
|
195
|
+
- `tp.insert_tasks(tc, tasks)` inserts one task per argument tuple of an
|
|
196
|
+
iterable, in batches, without taking the GIL back between the tasks of a
|
|
197
|
+
batch (see Performance). It is equivalent to a loop of `insert_task`: if
|
|
198
|
+
the iterable inserts other tasks, flushes or waits, the tasks it produced
|
|
199
|
+
before are inserted first, and if it raises, the tasks before the failing
|
|
200
|
+
item are inserted.
|
|
201
|
+
- `tc.add_chore(py_parsec.DEV_CPU, body)` adds a Python body. It is called
|
|
202
|
+
with one argument per parameter: NumPy arrays for tiles (read-only for
|
|
203
|
+
`INPUT`), numbers for values. The arrays are only valid during the call.
|
|
204
|
+
A body may return `py_parsec.HOOK_RETURN_AGAIN` to be rescheduled; any
|
|
205
|
+
other result completes the task. A task whose body raises completes, and
|
|
206
|
+
the next wait raises the exception (with a note counting the others).
|
|
207
|
+
- `tc.add_chore(device, address)` adds a C chore for any device type, given
|
|
208
|
+
as an int, a PyCapsule or a ctypes function pointer with the DTD chore
|
|
209
|
+
signature `parsec_hook_return_t f(parsec_execution_stream_t *, parsec_task_t *)`.
|
|
210
|
+
Accelerator kernels stay in user code this way. `dtd.NOOP_CHORE` is a C
|
|
211
|
+
chore that does nothing.
|
|
212
|
+
- Waits flush the collections the taskpool's tasks used since their last
|
|
213
|
+
flush, as DTD requires; `tp.data_flush(tile)` and `tp.data_flush_all(A)`
|
|
214
|
+
flush explicitly.
|
|
215
|
+
|
|
216
|
+
## Performance
|
|
217
|
+
|
|
218
|
+
- **One BLAS thread per task.** Each task is one core's work, but NumPy's
|
|
219
|
+
BLAS (OpenBLAS, MKL) starts its own threads on every call by default, so
|
|
220
|
+
every worker oversubscribes the cores PaRSEC already uses. Set
|
|
221
|
+
`OPENBLAS_NUM_THREADS=1` (and `OMP_NUM_THREADS`, `MKL_NUM_THREADS`) before
|
|
222
|
+
NumPy is imported, as `examples/dtd_gemm.py` does. In that example (4096,
|
|
223
|
+
256 x 256 tiles, 16 cores), 16 BLAS threads per call instead of one cut the
|
|
224
|
+
throughput by more than half on one rank, and more on 4 ranks of 4 cores.
|
|
225
|
+
- **Keep results column-major.** Tiles are Fortran-ordered, while NumPy
|
|
226
|
+
returns products in C order, so `c += a @ b` adds two arrays of opposite
|
|
227
|
+
layouts: a strided pass over the tile that halved the speed of the GEMM
|
|
228
|
+
kernel with 128 x 128 tiles. `c += (b.T @ a.T).T` computes the same
|
|
229
|
+
product in column-major order, at full speed.
|
|
230
|
+
- **Enough work per Python body.** A Python body runs with the GIL, which
|
|
231
|
+
NumPy releases in its heavy calls. With one worker, a Python body costs
|
|
232
|
+
about 0.2 us more than a C one; with many workers per process, the bodies
|
|
233
|
+
and the inserting thread queue for the GIL (an empty body costs about
|
|
234
|
+
8 us per task with 8 workers, 6 us with `insert_tasks`). Give each body a fraction of a millisecond
|
|
235
|
+
of work or more, and use `insert_tasks` for many small tasks. A body that
|
|
236
|
+
spends long in pure Python keeps the GIL for up to
|
|
237
|
+
`sys.getswitchinterval()` (5 ms) before another thread gets it.
|
|
238
|
+
- **Ranks rather than threads for small tasks.** Each process has its own
|
|
239
|
+
GIL, so several ranks per node with a few cores each scale better than
|
|
240
|
+
one rank with many cores when tasks are short. Give each rank its own
|
|
241
|
+
cores: PaRSEC binds its threads inside the CPU set of the process, so with
|
|
242
|
+
Open MPI run `mpiexec -n 4 --map-by slot:PE=4 --bind-to core ...` for 4
|
|
243
|
+
ranks of 4 cores, not `--bind-to none`, which puts the threads of every
|
|
244
|
+
rank on the same cores (PaRSEC warns about it).
|
|
245
|
+
- **C bodies for fine-grained tasks.** A C chore runs without the GIL.
|
|
246
|
+
|
|
247
|
+
Measured on a node with two Xeon Gold 6140 (one process unless noted),
|
|
248
|
+
Python 3.11, NumPy 2.4 with OpenBLAS, PaRSEC master built in Release mode.
|
|
249
|
+
Per-task cost from `benchmarks/overhead.py` and its C counterpart
|
|
250
|
+
`benchmarks/c_overhead.c`, which insert independent tasks on 1 x 1 tiles,
|
|
251
|
+
so that the time is the runtime's and the binding's:
|
|
252
|
+
|
|
253
|
+
| per task, 1 core | PaRSEC from C | `insert_task` | `insert_tasks` |
|
|
254
|
+
| --- | --- | --- | --- |
|
|
255
|
+
| insert, 1 tile, C body | 1.57 us | 2.06 us | 1.75 us |
|
|
256
|
+
| insert, 3 tiles, C body | 5.38 us | 6.04 us | 5.68 us |
|
|
257
|
+
| insert, 1 tile and 2 values, C body | 1.60 us | 2.26 us | 1.93 us |
|
|
258
|
+
| Python body instead of a C one | | +0.22 us | |
|
|
259
|
+
|
|
260
|
+
PaRSEC executes the same instructions in both cases. Of the extra
|
|
261
|
+
instructions of an insertion from Python, about a quarter are the binding's
|
|
262
|
+
(1,100 per task with `insert_task`, 400 with `insert_tasks`) and the rest
|
|
263
|
+
are the caller's own loop. With 8 workers, an empty Python body costs 8.1 us
|
|
264
|
+
per task with `insert_task` and 6.0 us with `insert_tasks` (insertion and
|
|
265
|
+
completion).
|
|
266
|
+
|
|
267
|
+
Tiled GEMM, C += A B with 4096 x 4096 doubles (`examples/dtd_gemm.py`, NumPy
|
|
268
|
+
bodies, one BLAS thread, best of 3 runs), and its fraction of 16 times the
|
|
269
|
+
single-core speed of the same NumPy tile update (63.7 GFlop/s for 256 x 256
|
|
270
|
+
tiles, 56.6 for 128 x 128):
|
|
271
|
+
|
|
272
|
+
| tile | 1 rank x 16 cores | 4 ranks x 4 cores |
|
|
273
|
+
| --- | --- | --- |
|
|
274
|
+
| 256 (0.53 ms per task) | 653 GFlop/s, 64% | 558 GFlop/s, 55% |
|
|
275
|
+
| 128 (0.07 ms per task) | 154 GFlop/s, 17% | 399 GFlop/s, 44% |
|
|
276
|
+
|
|
277
|
+
## Limitations
|
|
278
|
+
|
|
279
|
+
- One PaRSEC context per process, initialized once (PaRSEC cannot be
|
|
280
|
+
initialized again after `parsec_fini`).
|
|
281
|
+
- Python bodies run on CPU devices; accelerator chores are C functions.
|
|
282
|
+
- `parsec_context_test()` and `parsec_taskpool_test()` are not exposed: the
|
|
283
|
+
first cannot report completion while the context is started, and the
|
|
284
|
+
second returns the number of tasks the caller ran, which is 0 both when the
|
|
285
|
+
taskpool completed and when no task was ready.
|
|
286
|
+
- `redistribute_new` / `redistribute_dtd` handle float64 matrices only, as
|
|
287
|
+
PaRSEC compiles them for double precision.
|
|
288
|
+
- A DTD taskpool holds at most `dtd.MAX_TASK_CLASSES` (24) task classes
|
|
289
|
+
with a chore, released ones included: create task classes once and reuse
|
|
290
|
+
them for every insertion.
|
|
291
|
+
|
|
292
|
+
## Tests, examples and benchmarks
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
pip install pytest
|
|
296
|
+
python -m pytest tests
|
|
297
|
+
mpiexec -n 4 python -m pytest tests
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Each rank runs every test and checks the tiles it owns;
|
|
301
|
+
`PY_PARSEC_TEST_CORES` sets the cores per process (2 by default).
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
mpiexec -n 4 python examples/dtd_gemm.py -M 2048 -b 256 --check
|
|
305
|
+
mpiexec -n 4 python examples/redistribute.py
|
|
306
|
+
python benchmarks/overhead.py --cores 1 8
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Development
|
|
310
|
+
|
|
311
|
+
Build in place against a PaRSEC installation and run the tests from the
|
|
312
|
+
source tree:
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
pip install cython numpy pytest setuptools
|
|
316
|
+
PARSEC_ROOT=/path/to/parsec/install python setup.py build_ext --inplace
|
|
317
|
+
PYTHONPATH=src python -m pytest tests
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
The extension modules are rebuilt automatically when the PaRSEC found by
|
|
321
|
+
`pkg-config` changes. Continuous integration builds PaRSEC `master` and runs
|
|
322
|
+
the tests on 1, 2 and 4 ranks, and the examples on 4 ranks
|
|
323
|
+
([`.github/workflows/ci.yml`](.github/workflows/ci.yml)). See
|
|
324
|
+
[RELEASING.md](RELEASING.md) to cut a release.
|
|
325
|
+
|
|
326
|
+
## License
|
|
327
|
+
|
|
328
|
+
BSD 3-Clause Open MPI variant, the license of PaRSEC; see [LICENSE](LICENSE).
|