hanajit 0.20.1__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.
- hanajit-0.20.1/LICENSE +202 -0
- hanajit-0.20.1/PKG-INFO +428 -0
- hanajit-0.20.1/README.md +387 -0
- hanajit-0.20.1/hanajit/__init__.py +13 -0
- hanajit-0.20.1/hanajit/autopar.py +50 -0
- hanajit-0.20.1/hanajit/backends/__init__.py +0 -0
- hanajit-0.20.1/hanajit/backends/cpu.py +193 -0
- hanajit-0.20.1/hanajit/backends/detect.py +73 -0
- hanajit-0.20.1/hanajit/backends/fastcall.py +146 -0
- hanajit-0.20.1/hanajit/backends/fpga.py +39 -0
- hanajit-0.20.1/hanajit/backends/gpu.py +126 -0
- hanajit-0.20.1/hanajit/backends/metal.py +226 -0
- hanajit-0.20.1/hanajit/backends/vectorcall.py +223 -0
- hanajit-0.20.1/hanajit/cache.py +64 -0
- hanajit-0.20.1/hanajit/codegen.py +1112 -0
- hanajit-0.20.1/hanajit/decorator.py +637 -0
- hanajit-0.20.1/hanajit/doctor.py +611 -0
- hanajit-0.20.1/hanajit/errors.py +6 -0
- hanajit-0.20.1/hanajit/evolve.py +314 -0
- hanajit-0.20.1/hanajit/inline.py +188 -0
- hanajit-0.20.1/hanajit/parallel.py +184 -0
- hanajit-0.20.1/hanajit/rewrite.py +190 -0
- hanajit-0.20.1/hanajit/typeinfer.py +398 -0
- hanajit-0.20.1/hanajit.egg-info/PKG-INFO +428 -0
- hanajit-0.20.1/hanajit.egg-info/SOURCES.txt +45 -0
- hanajit-0.20.1/hanajit.egg-info/dependency_links.txt +1 -0
- hanajit-0.20.1/hanajit.egg-info/requires.txt +15 -0
- hanajit-0.20.1/hanajit.egg-info/top_level.txt +1 -0
- hanajit-0.20.1/pyproject.toml +47 -0
- hanajit-0.20.1/setup.cfg +4 -0
- hanajit-0.20.1/tests/test_amd_valid.py +76 -0
- hanajit-0.20.1/tests/test_arrays_advanced.py +222 -0
- hanajit-0.20.1/tests/test_autopar.py +92 -0
- hanajit-0.20.1/tests/test_basic.py +388 -0
- hanajit-0.20.1/tests/test_evolve_differential.py +91 -0
- hanajit-0.20.1/tests/test_float32.py +137 -0
- hanajit-0.20.1/tests/test_fusion.py +156 -0
- hanajit-0.20.1/tests/test_gpu_arch.py +127 -0
- hanajit-0.20.1/tests/test_hyper.py +90 -0
- hanajit-0.20.1/tests/test_inline.py +134 -0
- hanajit-0.20.1/tests/test_numerics.py +261 -0
- hanajit-0.20.1/tests/test_numpy_scipy.py +430 -0
- hanajit-0.20.1/tests/test_parallel.py +107 -0
- hanajit-0.20.1/tests/test_ptx_valid.py +67 -0
- hanajit-0.20.1/tests/test_reduce_reassoc.py +109 -0
- hanajit-0.20.1/tests/test_rewrite.py +95 -0
- hanajit-0.20.1/tests/test_type_contracts.py +179 -0
hanajit-0.20.1/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
hanajit-0.20.1/PKG-INFO
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hanajit
|
|
3
|
+
Version: 0.20.1
|
|
4
|
+
Summary: LLVM-backed JIT for Python using CPython's own parser, with transparent interpreter fallback. Targets CPU (working), NVIDIA GPU and FPGA (experimental IR emission).
|
|
5
|
+
Author-email: Iqbal Addou <cto@ezducate.ai>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/ezducate/HanaJit
|
|
8
|
+
Project-URL: Repository, https://github.com/ezducate/HanaJit
|
|
9
|
+
Project-URL: Issues, https://github.com/ezducate/HanaJit/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/ezducate/HanaJit/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: jit,compiler,llvm,numpy,performance,numba,vectorization,gpu,ptx,simd
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
22
|
+
Classifier: Operating System :: MacOS
|
|
23
|
+
Classifier: Intended Audience :: Developers
|
|
24
|
+
Classifier: Intended Audience :: Science/Research
|
|
25
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: llvmlite>=0.42
|
|
30
|
+
Provides-Extra: cuda
|
|
31
|
+
Requires-Dist: cuda-python; extra == "cuda"
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: pytest; extra == "test"
|
|
34
|
+
Requires-Dist: numpy; extra == "test"
|
|
35
|
+
Provides-Extra: bench
|
|
36
|
+
Requires-Dist: numba; extra == "bench"
|
|
37
|
+
Requires-Dist: scipy; extra == "bench"
|
|
38
|
+
Provides-Extra: scipy
|
|
39
|
+
Requires-Dist: scipy; extra == "scipy"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
<div align="center">
|
|
43
|
+
|
|
44
|
+
# HanaJit
|
|
45
|
+
|
|
46
|
+
**An LLVM-backed JIT compiler for Python — compile ordinary functions and NumPy code to native machine code, with a transparent interpreter fallback and no DSL to learn.**
|
|
47
|
+
|
|
48
|
+
[](https://github.com/ezducate/HanaJit/actions/workflows/ci.yml)
|
|
49
|
+
[](https://www.python.org/)
|
|
50
|
+
[](LICENSE)
|
|
51
|
+
[](#project-status)
|
|
52
|
+
|
|
53
|
+
*ها أنا — "here I am" (Darija) + JIT*
|
|
54
|
+
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
> **Project status: alpha.** HanaJit is under active development. The CPU
|
|
60
|
+
> compiler is stable and tested (207 tests across Python 3.10–3.14 on Linux,
|
|
61
|
+
> Windows, and macOS). GPU support is **code generation only** — hanajit
|
|
62
|
+
> emits GPU assembly that real vendor toolchains accept, but does not yet
|
|
63
|
+
> *launch* kernels on a GPU (see [Scope & honest limitations](#scope--honest-limitations)).
|
|
64
|
+
> APIs may change before 1.0.
|
|
65
|
+
|
|
66
|
+
## What is HanaJit?
|
|
67
|
+
|
|
68
|
+
HanaJit takes a normal Python function, compiles it to optimized native
|
|
69
|
+
machine code through [LLVM](https://llvm.org/) (via
|
|
70
|
+
[llvmlite](https://llvmlite.readthedocs.io/)), and runs that instead of the
|
|
71
|
+
interpreter — often **10–100× faster than CPython**, and competitive with or
|
|
72
|
+
faster than [Numba](https://numba.pydata.org/) on the workloads it targets.
|
|
73
|
+
|
|
74
|
+
You do not learn a new language, annotate types, or restructure your data.
|
|
75
|
+
You add a decorator:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from hanajit import jit
|
|
79
|
+
|
|
80
|
+
@jit
|
|
81
|
+
def sum_squares(x):
|
|
82
|
+
acc = 0.0
|
|
83
|
+
for i in range(len(x)):
|
|
84
|
+
acc += x[i] * x[i]
|
|
85
|
+
return acc
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The first call with a given argument type compiles a specialization; later
|
|
89
|
+
calls reuse it. Anything HanaJit can't compile falls back to the normal
|
|
90
|
+
Python interpreter **transparently**, with a single warning — so adopting it
|
|
91
|
+
never breaks working code.
|
|
92
|
+
|
|
93
|
+
### Why it exists
|
|
94
|
+
|
|
95
|
+
HanaJit was built in the R&D pipeline of [EZducate](https://ezducate.ai), an
|
|
96
|
+
AI-powered special-education platform, to accelerate the numeric and
|
|
97
|
+
array-heavy code (on-device inference, simulation, data processing) that sits
|
|
98
|
+
between "too slow in pure Python" and "not worth rewriting in C." It is
|
|
99
|
+
designed around three principles:
|
|
100
|
+
|
|
101
|
+
1. **No DSL.** It compiles the Python you already wrote, parsed by CPython's
|
|
102
|
+
own `ast` module — not a restricted dialect, not a new syntax.
|
|
103
|
+
2. **Correctness is never negotiable.** Every optimization is either provably
|
|
104
|
+
equivalent, or a *bounded, opt-in* trade-off (like float32 precision)
|
|
105
|
+
documented with its exact cost. Anything HanaJit can't compile runs in the
|
|
106
|
+
interpreter rather than compiling something wrong.
|
|
107
|
+
3. **Honesty about performance.** Every number in this README is measured and
|
|
108
|
+
reproducible from the scripts in [`benchmarks/`](benchmarks/). Where a
|
|
109
|
+
feature ties or loses, we say so.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Highlights
|
|
114
|
+
|
|
115
|
+
- **Drop-in `@jit`** on ordinary functions — loops, recursion, math, NumPy.
|
|
116
|
+
- **Lazy fusion engine** — whole-array NumPy expressions compile to a single
|
|
117
|
+
allocation-free loop (no temporaries), beating NumPy *and* Numba
|
|
118
|
+
structurally.
|
|
119
|
+
- **`reduce_reassoc=True`** — numpy-class reduction throughput by vectorizing
|
|
120
|
+
accumulators, without global fast-math; integers stay bit-exact.
|
|
121
|
+
- **Native float32** — pass a `float32` array and get 32-bit compute: half
|
|
122
|
+
the memory bandwidth, 2× the SIMD lanes, exact (bounded) f32 precision.
|
|
123
|
+
- **Genetic optimizer** (`f.evolve()`) — an equivalence-preserving search over
|
|
124
|
+
compilation strategies that tunes each kernel to your machine.
|
|
125
|
+
- **Near-zero dispatch** — ~20–50 ns/call via an LLVM-compiled vectorcall path
|
|
126
|
+
on CPython 3.12+.
|
|
127
|
+
- **Multithreading** — `prange`, `pmap`, `nogil`, and `parallel=True`
|
|
128
|
+
auto-parallelization.
|
|
129
|
+
- **GPU code generation** — emits CUDA PTX, AMD GCN, Intel SPIR-V, and Apple
|
|
130
|
+
Metal, each validated against the real vendor assembler (emission only; see
|
|
131
|
+
scope below).
|
|
132
|
+
- **Transparent fallback** — unsupported code runs in CPython automatically.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Performance
|
|
137
|
+
|
|
138
|
+
Measured on a single core (shared CI container — **ratios are reliable,
|
|
139
|
+
absolute milliseconds are noisy**; rerun on your hardware with the scripts in
|
|
140
|
+
[`benchmarks/`](benchmarks/)). Compared against NumPy 2.x and Numba 0.66.
|
|
141
|
+
|
|
142
|
+
| Benchmark | Result |
|
|
143
|
+
|---|---|
|
|
144
|
+
| 5-operation fused NumPy reduction | **3.2× vs NumPy, 3.9× vs Numba** |
|
|
145
|
+
| 20M-element reduction (`reduce_reassoc`) | **2.5×** over the float64 baseline |
|
|
146
|
+
| 20M-element reduction (float32 + `reduce_reassoc`) | **3.2×** over the float64 baseline |
|
|
147
|
+
| Genetic optimizer (`evolve`) on an fp reduction | **2.1×**, equivalence-guaranteed |
|
|
148
|
+
| Dispatch / call overhead | **~36 ns** (3.5× faster than Numba) |
|
|
149
|
+
| `fib(30)` recursion | **1.85× vs Numba** |
|
|
150
|
+
|
|
151
|
+
**How to read this honestly:** on bare scalar loops, HanaJit and Numba are at
|
|
152
|
+
parity — they share the LLVM backend, so loop codegen is a wash. HanaJit's
|
|
153
|
+
wins come from (a) the fusion engine, which is a structural advantage on
|
|
154
|
+
array expressions, (b) targeted reduction vectorization, (c) native float32,
|
|
155
|
+
(d) dispatch latency and cold-start. Where the underlying operation is already
|
|
156
|
+
at the hardware roofline, there is no magic to extract, and we don't pretend
|
|
157
|
+
otherwise.
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Installation
|
|
162
|
+
|
|
163
|
+
HanaJit requires **Python 3.10+** and depends only on `llvmlite` (which ships
|
|
164
|
+
prebuilt LLVM wheels for all major platforms — you do **not** need to install
|
|
165
|
+
LLVM yourself).
|
|
166
|
+
|
|
167
|
+
### From PyPI
|
|
168
|
+
|
|
169
|
+
> Not yet published. Once released, this will be:
|
|
170
|
+
>
|
|
171
|
+
> ```bash
|
|
172
|
+
> pip install hanajit
|
|
173
|
+
> ```
|
|
174
|
+
>
|
|
175
|
+
> See [`docs/publishing.md`](docs/publishing.md) for the release process.
|
|
176
|
+
|
|
177
|
+
### From GitHub (available now)
|
|
178
|
+
|
|
179
|
+
Install the latest version directly from this repository:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
pip install "git+https://github.com/ezducate/HanaJit.git"
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Pin to a specific tag or commit for reproducibility:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# a released tag
|
|
189
|
+
pip install "git+https://github.com/ezducate/HanaJit.git@v0.20.0"
|
|
190
|
+
|
|
191
|
+
# a specific commit
|
|
192
|
+
pip install "git+https://github.com/ezducate/HanaJit.git@<commit-sha>"
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Add it to `requirements.txt`:
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
hanajit @ git+https://github.com/ezducate/HanaJit.git@v0.20.0
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Or to `pyproject.toml` dependencies:
|
|
202
|
+
|
|
203
|
+
```toml
|
|
204
|
+
dependencies = [
|
|
205
|
+
"hanajit @ git+https://github.com/ezducate/HanaJit.git@v0.20.0",
|
|
206
|
+
]
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Optional extras
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# run the test suite
|
|
213
|
+
pip install "hanajit[test] @ git+https://github.com/ezducate/HanaJit.git"
|
|
214
|
+
|
|
215
|
+
# run the benchmarks (adds numba + scipy for comparison)
|
|
216
|
+
pip install "hanajit[bench] @ git+https://github.com/ezducate/HanaJit.git"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### From a local clone (for development)
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
git clone https://github.com/ezducate/HanaJit.git
|
|
223
|
+
cd HanaJit
|
|
224
|
+
pip install -e ".[test]" # editable install with test deps
|
|
225
|
+
python -m pytest tests/ -q # run the suite
|
|
226
|
+
python -m hanajit.doctor # environment + capability diagnostic
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Quick start
|
|
232
|
+
|
|
233
|
+
### Accelerate a numeric function
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
from hanajit import jit
|
|
237
|
+
import numpy as np
|
|
238
|
+
|
|
239
|
+
@jit
|
|
240
|
+
def euclidean_norm(x):
|
|
241
|
+
acc = 0.0
|
|
242
|
+
for i in range(len(x)):
|
|
243
|
+
acc += x[i] * x[i]
|
|
244
|
+
return acc ** 0.5
|
|
245
|
+
|
|
246
|
+
a = np.random.rand(1_000_000)
|
|
247
|
+
euclidean_norm(a) # compiles on first call, runs native thereafter
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Fuse a NumPy expression (no temporaries)
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
@jit
|
|
254
|
+
def score(a, b):
|
|
255
|
+
# compiles to ONE loop — no intermediate arrays are ever allocated
|
|
256
|
+
return np.sum(np.exp(-a * a) * b + np.where(a > 0, a, 2 * a))
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Numpy-class reductions
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
@jit(reduce_reassoc=True) # vectorizes the accumulator; integers stay exact
|
|
263
|
+
def total(x):
|
|
264
|
+
acc = 0.0
|
|
265
|
+
for i in range(len(x)):
|
|
266
|
+
acc += x[i]
|
|
267
|
+
return acc
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Native float32 (2× on memory-bound work)
|
|
271
|
+
|
|
272
|
+
```python
|
|
273
|
+
total(a.astype(np.float32)) # 32-bit compute, exact f32 precision
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Tune a kernel to your machine
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
f = jit(heavy_kernel)
|
|
280
|
+
f(example_args) # compile
|
|
281
|
+
report = f.evolve(example_args) # genetic search, keeps the fastest
|
|
282
|
+
# equivalence-verified variant
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Parallelize
|
|
286
|
+
|
|
287
|
+
```python
|
|
288
|
+
from hanajit import jit, prange
|
|
289
|
+
|
|
290
|
+
@jit(parallel=True) # outermost range loop auto-parallelizes
|
|
291
|
+
def process(x, out):
|
|
292
|
+
for i in range(len(x)):
|
|
293
|
+
out[i] = expensive(x[i])
|
|
294
|
+
return 0
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
See [`docs/`](docs/) for the full API, and [`examples/`](examples/) for
|
|
298
|
+
runnable programs.
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## How it works
|
|
303
|
+
|
|
304
|
+
HanaJit is ~3,000 lines of readable Python. One IR, many machines:
|
|
305
|
+
|
|
306
|
+
1. **Frontend** — `inspect.getsource` + `ast.parse` give the exact tree
|
|
307
|
+
CPython would execute. No custom parser.
|
|
308
|
+
2. **Type inference** — a fixpoint over a small lattice (`i64`, `f64`, `f32`,
|
|
309
|
+
`bool`, pointers, array kinds). Anything outside it raises
|
|
310
|
+
`UnsupportedError` → transparent interpreter fallback.
|
|
311
|
+
3. **Code generation** — the typed AST lowers to LLVM IR (via `llvmlite.ir`),
|
|
312
|
+
including the fusion engine that turns array expressions into element
|
|
313
|
+
generators fused into one loop.
|
|
314
|
+
4. **Backends** — the same IR module is optimized (`-O3`) and either JITed for
|
|
315
|
+
your exact host CPU, or re-targeted for GPUs (PTX / GCN / SPIR-V / MSL) or
|
|
316
|
+
exported for FPGA HLS.
|
|
317
|
+
|
|
318
|
+
For a deeper tour, see [`docs/architecture.md`](docs/architecture.md).
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Scope & honest limitations
|
|
323
|
+
|
|
324
|
+
HanaJit is deliberately clear about what it does and does not do.
|
|
325
|
+
|
|
326
|
+
**What works and is tested:**
|
|
327
|
+
- CPU compilation of a useful subset of Python + NumPy, with transparent
|
|
328
|
+
fallback for the rest.
|
|
329
|
+
- The fusion engine, reductions, float32, the genetic optimizer, inlining,
|
|
330
|
+
auto-parallelization, and multithreading.
|
|
331
|
+
- **207 tests** passing across Python 3.10–3.14 on Linux, Windows 11, and
|
|
332
|
+
macOS (Apple Silicon).
|
|
333
|
+
|
|
334
|
+
**GPU: code generation is verified; kernel launch is not implemented.**
|
|
335
|
+
HanaJit emits GPU assembly and this output is validated by the *real* vendor
|
|
336
|
+
toolchains — NVIDIA `ptxas` assembles our PTX to a cubin, LLVM's AMDGPU
|
|
337
|
+
`llvm-mc` assembles our GCN to an object, and `xcrun metal` compiles our Metal
|
|
338
|
+
source on Apple Silicon. **However, HanaJit does not yet launch kernels on a
|
|
339
|
+
GPU** (the host-side `cuLaunchKernel`/HIP/Metal dispatch bridge is on the
|
|
340
|
+
roadmap). Today the GPU backends are a verified *compiler target*, not a
|
|
341
|
+
runtime. Claims in this repo say "emits and assembles," never "runs on GPU."
|
|
342
|
+
|
|
343
|
+
**FPGA** support is IR + Vitis HLS TCL *export* only — an FPGA is synthesized,
|
|
344
|
+
not JITed, so it can never be a runtime target.
|
|
345
|
+
|
|
346
|
+
**Not supported** (falls back to CPython): allocating new arrays inside a
|
|
347
|
+
kernel, most of the object model (classes, dicts, arbitrary Python objects),
|
|
348
|
+
generators, exceptions as control flow, and the long tail of the NumPy API.
|
|
349
|
+
HanaJit targets numeric, loop- and array-heavy code, not general Python.
|
|
350
|
+
|
|
351
|
+
**Numerical notes:** `reduce_reassoc` reorders float additions (like NumPy's
|
|
352
|
+
pairwise sum) so results are not bit-identical to a sequential sum, but stay
|
|
353
|
+
within the same ~1e-10 tolerance; integers are unaffected. `float32` gives
|
|
354
|
+
exact float32 precision (~7 significant digits), a bounded trade-off you opt
|
|
355
|
+
into by passing float32 arrays. Experimental modes
|
|
356
|
+
(`evolve_hyper`, `rewrite=True`) are opt-in, CPU-only, and documented with
|
|
357
|
+
their risks in [`docs/experimental.md`](docs/experimental.md).
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## Diagnostics
|
|
362
|
+
|
|
363
|
+
HanaJit ships a self-diagnostic that probes your environment and writes a
|
|
364
|
+
report:
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
python -m hanajit.doctor
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
It checks compilation, dispatch, threading, caching, the GPU code-generation
|
|
371
|
+
backends (and runs the real assemblers if `ptxas` / `llvm-mc` are on your
|
|
372
|
+
PATH), and hardware detection — then writes `hanajit_report_<platform>.md`.
|
|
373
|
+
Committed example reports live in [`reports/`](reports/).
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
## Project layout
|
|
378
|
+
|
|
379
|
+
```
|
|
380
|
+
hanajit/ the package (frontend, typeinfer, codegen, backends, ...)
|
|
381
|
+
backends/ cpu, gpu (cuda/amd/intel), metal, fpga
|
|
382
|
+
docs/ API, architecture, GPU, performance, limitations, ...
|
|
383
|
+
benchmarks/ reproducible benchmark scripts
|
|
384
|
+
examples/ runnable example programs
|
|
385
|
+
tests/ the test suite (207 tests)
|
|
386
|
+
reports/ committed doctor reports (Linux / Windows / macOS)
|
|
387
|
+
site/ the project landing page
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## Contributing
|
|
393
|
+
|
|
394
|
+
Issues and pull requests are welcome. Please run the suite before submitting:
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
pip install -e ".[test]"
|
|
398
|
+
python -m pytest tests/ -q
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
New optimizations must include tests that verify **correctness against a
|
|
402
|
+
reference** before any performance claim — that is the core rule of this
|
|
403
|
+
project. Contributions are accepted under the repository's license (below).
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## License
|
|
408
|
+
|
|
409
|
+
Licensed under the **Apache License 2.0** — see [`LICENSE`](LICENSE).
|
|
410
|
+
|
|
411
|
+
Apache-2.0 was chosen over MIT for its explicit patent grant and
|
|
412
|
+
patent-retaliation clause, which matter for a compiler project in
|
|
413
|
+
patent-adjacent fields. If you prefer MIT, the change is a one-file swap plus
|
|
414
|
+
a line in `pyproject.toml` — but note that relicensing after external
|
|
415
|
+
contributions requires contributors' agreement.
|
|
416
|
+
|
|
417
|
+
---
|
|
418
|
+
|
|
419
|
+
## Acknowledgements
|
|
420
|
+
|
|
421
|
+
Built on [LLVM](https://llvm.org/) and
|
|
422
|
+
[llvmlite](https://llvmlite.readthedocs.io/). Benchmarked against
|
|
423
|
+
[NumPy](https://numpy.org/) and [Numba](https://numba.pydata.org/). Some
|
|
424
|
+
ergonomic ideas (helper inlining, auto-parallel `for`) were inspired by
|
|
425
|
+
[Taichi](https://github.com/taichi-dev/taichi) — the *ideas*, implemented
|
|
426
|
+
without a DSL.
|
|
427
|
+
|
|
428
|
+
Developed in the R&D pipeline of [EZducate](https://ezducate.ai).
|