kernox 1.0.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.
Files changed (72) hide show
  1. kernox-1.0.1/LICENSE-APACHE +202 -0
  2. kernox-1.0.1/LICENSE-MIT +21 -0
  3. kernox-1.0.1/PKG-INFO +151 -0
  4. kernox-1.0.1/README.md +112 -0
  5. kernox-1.0.1/THIRD_PARTY.md +20 -0
  6. kernox-1.0.1/kernox/__init__.py +101 -0
  7. kernox-1.0.1/kernox/_env.py +13 -0
  8. kernox-1.0.1/kernox/_plan_key.py +118 -0
  9. kernox-1.0.1/kernox/_symox_compat.py +128 -0
  10. kernox-1.0.1/kernox/autograd.py +464 -0
  11. kernox-1.0.1/kernox/backends/__init__.py +1 -0
  12. kernox-1.0.1/kernox/backends/base.py +252 -0
  13. kernox-1.0.1/kernox/backends/cuda/__init__.py +10 -0
  14. kernox-1.0.1/kernox/backends/cuda/_driver.py +335 -0
  15. kernox-1.0.1/kernox/backends/cuda/_kernel.py +886 -0
  16. kernox-1.0.1/kernox/backends/cuda/backend.py +796 -0
  17. kernox-1.0.1/kernox/backends/hip/__init__.py +11 -0
  18. kernox-1.0.1/kernox/backends/hip/_cache.py +85 -0
  19. kernox-1.0.1/kernox/backends/hip/_hip.py +252 -0
  20. kernox-1.0.1/kernox/backends/hip/_kernel.py +801 -0
  21. kernox-1.0.1/kernox/backends/hip/backend.py +711 -0
  22. kernox-1.0.1/kernox/backends/hip/diagnostics.py +99 -0
  23. kernox-1.0.1/kernox/backends/sycl/__init__.py +601 -0
  24. kernox-1.0.1/kernox/backends/sycl/_pair_local.py +67 -0
  25. kernox-1.0.1/kernox/backends/sycl/codegen.py +888 -0
  26. kernox-1.0.1/kernox/backends/sycl/toolchain.py +179 -0
  27. kernox-1.0.1/kernox/builder.py +371 -0
  28. kernox-1.0.1/kernox/codegen/__init__.py +1 -0
  29. kernox-1.0.1/kernox/codegen/pair.py +512 -0
  30. kernox-1.0.1/kernox/complex.py +407 -0
  31. kernox-1.0.1/kernox/diagnostics/__init__.py +335 -0
  32. kernox-1.0.1/kernox/diagnostics/__main__.py +5 -0
  33. kernox-1.0.1/kernox/errors.py +33 -0
  34. kernox-1.0.1/kernox/expr.py +615 -0
  35. kernox-1.0.1/kernox/linalg.py +388 -0
  36. kernox-1.0.1/kernox/ops.py +501 -0
  37. kernox-1.0.1/kernox/oracle.py +626 -0
  38. kernox-1.0.1/kernox/plan.py +157 -0
  39. kernox-1.0.1/kernox/ranges.py +246 -0
  40. kernox-1.0.1/kernox/runtime.py +977 -0
  41. kernox-1.0.1/kernox/tuning.py +404 -0
  42. kernox-1.0.1/kernox.egg-info/PKG-INFO +151 -0
  43. kernox-1.0.1/kernox.egg-info/SOURCES.txt +70 -0
  44. kernox-1.0.1/kernox.egg-info/dependency_links.txt +1 -0
  45. kernox-1.0.1/kernox.egg-info/requires.txt +17 -0
  46. kernox-1.0.1/kernox.egg-info/top_level.txt +1 -0
  47. kernox-1.0.1/pyproject.toml +55 -0
  48. kernox-1.0.1/setup.cfg +4 -0
  49. kernox-1.0.1/tests/test_autograd.py +186 -0
  50. kernox-1.0.1/tests/test_batch.py +264 -0
  51. kernox-1.0.1/tests/test_complex.py +144 -0
  52. kernox-1.0.1/tests/test_derivative_ops.py +100 -0
  53. kernox-1.0.1/tests/test_diagnostics.py +30 -0
  54. kernox-1.0.1/tests/test_docs_examples.py +53 -0
  55. kernox-1.0.1/tests/test_env.py +31 -0
  56. kernox-1.0.1/tests/test_factor_pow2.py +38 -0
  57. kernox-1.0.1/tests/test_fp16.py +141 -0
  58. kernox-1.0.1/tests/test_frontend.py +245 -0
  59. kernox-1.0.1/tests/test_linalg.py +334 -0
  60. kernox-1.0.1/tests/test_ops.py +415 -0
  61. kernox-1.0.1/tests/test_oracle_semantics.py +163 -0
  62. kernox-1.0.1/tests/test_pair_codegen.py +119 -0
  63. kernox-1.0.1/tests/test_pair_compile.py +73 -0
  64. kernox-1.0.1/tests/test_plan_key.py +68 -0
  65. kernox-1.0.1/tests/test_ranges.py +313 -0
  66. kernox-1.0.1/tests/test_reduction_gradients.py +192 -0
  67. kernox-1.0.1/tests/test_reductions_v08.py +191 -0
  68. kernox-1.0.1/tests/test_runtime.py +225 -0
  69. kernox-1.0.1/tests/test_softmax_reductions.py +204 -0
  70. kernox-1.0.1/tests/test_sum_scheme.py +152 -0
  71. kernox-1.0.1/tests/test_symox_compat.py +38 -0
  72. kernox-1.0.1/tests/test_tuning.py +348 -0
@@ -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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jean-Baptiste Keck
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.
kernox-1.0.1/PKG-INFO ADDED
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: kernox
3
+ Version: 1.0.1
4
+ Summary: Fused symbolic reductions on GPUs (CUDA, ROCm/HIP, SYCL), built on symox
5
+ Author: Jean-Baptiste Keck
6
+ License-Expression: MIT OR Apache-2.0
7
+ Project-URL: Homepage, https://github.com/keckj/kernox
8
+ Project-URL: Documentation, https://keckj.github.io/kernox/
9
+ Project-URL: Source, https://github.com/keckj/kernox
10
+ Project-URL: Issues, https://github.com/keckj/kernox/issues
11
+ Project-URL: Changelog, https://github.com/keckj/kernox/releases
12
+ Project-URL: symox, https://github.com/keckj/symox
13
+ Keywords: gpu,cuda,rocm,sycl,kernel,reduction,pytorch,keops
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
19
+ Classifier: Environment :: GPU :: NVIDIA CUDA
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE-MIT
23
+ License-File: LICENSE-APACHE
24
+ License-File: THIRD_PARTY.md
25
+ Requires-Dist: numpy>=2.3
26
+ Requires-Dist: symox>=0.1.1
27
+ Provides-Extra: cuda
28
+ Requires-Dist: torch>=2.11; extra == "cuda"
29
+ Requires-Dist: nvidia-cuda-nvrtc-cu12>=12.6; extra == "cuda"
30
+ Provides-Extra: rocm
31
+ Requires-Dist: torch>=2.15; extra == "rocm"
32
+ Provides-Extra: xpu
33
+ Requires-Dist: torch>=2.15; extra == "xpu"
34
+ Requires-Dist: intel-sycl-rt>=2026.2.0; extra == "xpu"
35
+ Requires-Dist: intel-cmplr-lib-ur>=2026.2.0; extra == "xpu"
36
+ Provides-Extra: test
37
+ Requires-Dist: pytest>=8.4; extra == "test"
38
+ Dynamic: license-file
39
+
40
+ # kernox
41
+
42
+ <p align="center">
43
+ <img src="https://raw.githubusercontent.com/keckj/kernox/v1.0.1/docs/images/kernox-banner.png" alt="kernox logo" width="560">
44
+ </p>
45
+
46
+ kernox computes pairwise reductions on GPUs (Gaussian kernel sums, nearest
47
+ neighbours, log-sum-exp, softmax-weighted sums, ...) without ever building the
48
+ M×N matrix. You write the formula with symbolic variables indexed by `i` and
49
+ `j`, and kernox turns it into a single fused GPU kernel for NVIDIA (CUDA),
50
+ AMD (ROCm/HIP) or Intel (SYCL) cards. Support for other accelerators may be
51
+ added later.
52
+
53
+ kernox is a successor to [PyKeOps](https://github.com/getkeops/keops), built on
54
+ the [symox](https://github.com/keckj/symox) symbolic engine. It works with
55
+ PyTorch tensors.
56
+
57
+ - Documentation: <https://keckj.github.io/kernox/>
58
+ - Getting started: <https://keckj.github.io/kernox/getting-started/>
59
+
60
+ ## Why kernox
61
+
62
+ - **No M×N matrix.** Memory stays linear in the number of points, so each row
63
+ can be reduced over millions of points.
64
+ - **Three GPU vendors.** One formula runs on NVIDIA, AMD and Intel GPUs.
65
+ - **Formulas, not strings.** Formulas are Python expressions. Derivatives are
66
+ computed symbolically and run as fused reductions too.
67
+ - **Predictable numerics.** IEEE arithmetic by default, an explicit opt-in for
68
+ approximate `exp` and `log`, and an explicit error instead of a silent
69
+ fallback when something is not supported.
70
+ - **Familiar to PyKeOps users.** The PyKeOps reductions and formula operations
71
+ are available for PyTorch on GPUs. kernox has no NumPy interface and no CPU
72
+ backend; the other differences are listed in
73
+ [Coming from PyKeOps](https://keckj.github.io/kernox/pykeops/).
74
+
75
+ ## Installation
76
+
77
+ kernox needs Python 3.10 or later, PyTorch and a supported GPU. Install PyTorch
78
+ for your platform first, then kernox from PyPI (symox, its symbolic engine, comes
79
+ with it as a dependency):
80
+
81
+ ```sh
82
+ pip install torch --index-url https://download.pytorch.org/whl/cu126 # NVIDIA
83
+ pip install "kernox[cuda]"
84
+ python -m kernox.diagnostics --check
85
+ ```
86
+
87
+ AMD and Intel instructions, and the details, are in
88
+ [Getting started](https://keckj.github.io/kernox/getting-started/).
89
+
90
+ ## Performance
91
+
92
+ The goal of kernox is to be **at least as fast as PyKeOps** wherever PyKeOps
93
+ runs, and to bring the same performance to AMD and Intel GPUs, which PyKeOps
94
+ does not support. On NVIDIA GPUs, kernox is already faster than PyKeOps in
95
+ several cases.
96
+
97
+ LogSumExp reduction, M = N = 10⁵, FP32, on an RTX 2080 Ti; kernox with
98
+ `fast_math=True`, PyKeOps 2.4b in its best configuration (each kernel compiled
99
+ alone in a fresh process); median of two runs:
100
+
101
+ | Case | kernox | PyKeOps | kernox / PyKeOps |
102
+ | --- | --- | --- | --- |
103
+ | D = 2, dense | 20.1 ms | 21.9 ms | ×0.92 |
104
+ | D = 3, dense | 24.6 ms | 25.8 ms | ×0.95 |
105
+ | D = 2, block-sparse ranges | 8.4 ms | 8.9 ms | ×0.95 |
106
+ | D = 3, block-sparse ranges | 4.2 ms | 4.2 ms | ×1.01 (same within noise) |
107
+
108
+ These figures cover only the cases listed; they are not a general claim of
109
+ superiority over PyKeOps on every workload or card. A case where kernox is
110
+ slower than PyKeOps is treated as a bug.
111
+
112
+ ## Learn more
113
+
114
+ - [Getting started](https://keckj.github.io/kernox/getting-started/): installation and a first
115
+ reduction, step by step.
116
+ - [Concepts](https://keckj.github.io/kernox/concepts/): variables, formulas, reductions, devices and
117
+ dtypes.
118
+ - How-to guides: [kernel sums](https://keckj.github.io/kernox/guides/kernel-sums/),
119
+ [nearest neighbours](https://keckj.github.io/kernox/guides/nearest-neighbours/),
120
+ [log-sum-exp and Sinkhorn](https://keckj.github.io/kernox/guides/logsumexp/),
121
+ [gradients](https://keckj.github.io/kernox/guides/gradients/),
122
+ [linear systems](https://keckj.github.io/kernox/guides/linear-systems/) and more.
123
+ - [Coming from PyKeOps](https://keckj.github.io/kernox/pykeops/): a migration guide.
124
+ - [Backends and hardware](https://keckj.github.io/kernox/backends/): what runs where, and the known
125
+ limitations.
126
+
127
+ ## About the name and logo
128
+
129
+ symox is *symbolic* plus *ox*: a rusty ox, since symox is written in Rust.
130
+ kernox is *kernels* plus the ox of symox, and also a nod to the redox chemistry
131
+ of copper. The logo goes from orange copper (the ox) to turquoise verdigris
132
+ (the trails and the compute grid), that is, from copper to its oxidation
133
+ patina. And redox contains *reduction*, which is what kernox does: sum, min and
134
+ max, as drawn in the logo.
135
+
136
+ ## License
137
+
138
+ At your option, [MIT](https://github.com/keckj/kernox/blob/v1.0.1/LICENSE-MIT) or [Apache-2.0](https://github.com/keckj/kernox/blob/v1.0.1/LICENSE-APACHE).
139
+ Provenance of third-party code and algorithms (KeOps, symox):
140
+ [`THIRD_PARTY.md`](https://github.com/keckj/kernox/blob/v1.0.1/THIRD_PARTY.md).
141
+
142
+ ## Projects using kernox
143
+
144
+ - [remblais](https://github.com/keckj/remblais): a faster GeomLoss (Sinkhorn
145
+ divergences, kernel norms and optimal transport) on NVIDIA, AMD and Intel
146
+ GPUs. Documentation: <https://keckj.github.io/remblais/>
147
+
148
+ ## Related projects
149
+
150
+ - symox, symbolic engine and code generation: <https://github.com/keckj/symox>
151
+ - KeOps / PyKeOps: <https://github.com/getkeops/keops>
kernox-1.0.1/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # kernox
2
+
3
+ <p align="center">
4
+ <img src="https://raw.githubusercontent.com/keckj/kernox/v1.0.1/docs/images/kernox-banner.png" alt="kernox logo" width="560">
5
+ </p>
6
+
7
+ kernox computes pairwise reductions on GPUs (Gaussian kernel sums, nearest
8
+ neighbours, log-sum-exp, softmax-weighted sums, ...) without ever building the
9
+ M×N matrix. You write the formula with symbolic variables indexed by `i` and
10
+ `j`, and kernox turns it into a single fused GPU kernel for NVIDIA (CUDA),
11
+ AMD (ROCm/HIP) or Intel (SYCL) cards. Support for other accelerators may be
12
+ added later.
13
+
14
+ kernox is a successor to [PyKeOps](https://github.com/getkeops/keops), built on
15
+ the [symox](https://github.com/keckj/symox) symbolic engine. It works with
16
+ PyTorch tensors.
17
+
18
+ - Documentation: <https://keckj.github.io/kernox/>
19
+ - Getting started: <https://keckj.github.io/kernox/getting-started/>
20
+
21
+ ## Why kernox
22
+
23
+ - **No M×N matrix.** Memory stays linear in the number of points, so each row
24
+ can be reduced over millions of points.
25
+ - **Three GPU vendors.** One formula runs on NVIDIA, AMD and Intel GPUs.
26
+ - **Formulas, not strings.** Formulas are Python expressions. Derivatives are
27
+ computed symbolically and run as fused reductions too.
28
+ - **Predictable numerics.** IEEE arithmetic by default, an explicit opt-in for
29
+ approximate `exp` and `log`, and an explicit error instead of a silent
30
+ fallback when something is not supported.
31
+ - **Familiar to PyKeOps users.** The PyKeOps reductions and formula operations
32
+ are available for PyTorch on GPUs. kernox has no NumPy interface and no CPU
33
+ backend; the other differences are listed in
34
+ [Coming from PyKeOps](https://keckj.github.io/kernox/pykeops/).
35
+
36
+ ## Installation
37
+
38
+ kernox needs Python 3.10 or later, PyTorch and a supported GPU. Install PyTorch
39
+ for your platform first, then kernox from PyPI (symox, its symbolic engine, comes
40
+ with it as a dependency):
41
+
42
+ ```sh
43
+ pip install torch --index-url https://download.pytorch.org/whl/cu126 # NVIDIA
44
+ pip install "kernox[cuda]"
45
+ python -m kernox.diagnostics --check
46
+ ```
47
+
48
+ AMD and Intel instructions, and the details, are in
49
+ [Getting started](https://keckj.github.io/kernox/getting-started/).
50
+
51
+ ## Performance
52
+
53
+ The goal of kernox is to be **at least as fast as PyKeOps** wherever PyKeOps
54
+ runs, and to bring the same performance to AMD and Intel GPUs, which PyKeOps
55
+ does not support. On NVIDIA GPUs, kernox is already faster than PyKeOps in
56
+ several cases.
57
+
58
+ LogSumExp reduction, M = N = 10⁵, FP32, on an RTX 2080 Ti; kernox with
59
+ `fast_math=True`, PyKeOps 2.4b in its best configuration (each kernel compiled
60
+ alone in a fresh process); median of two runs:
61
+
62
+ | Case | kernox | PyKeOps | kernox / PyKeOps |
63
+ | --- | --- | --- | --- |
64
+ | D = 2, dense | 20.1 ms | 21.9 ms | ×0.92 |
65
+ | D = 3, dense | 24.6 ms | 25.8 ms | ×0.95 |
66
+ | D = 2, block-sparse ranges | 8.4 ms | 8.9 ms | ×0.95 |
67
+ | D = 3, block-sparse ranges | 4.2 ms | 4.2 ms | ×1.01 (same within noise) |
68
+
69
+ These figures cover only the cases listed; they are not a general claim of
70
+ superiority over PyKeOps on every workload or card. A case where kernox is
71
+ slower than PyKeOps is treated as a bug.
72
+
73
+ ## Learn more
74
+
75
+ - [Getting started](https://keckj.github.io/kernox/getting-started/): installation and a first
76
+ reduction, step by step.
77
+ - [Concepts](https://keckj.github.io/kernox/concepts/): variables, formulas, reductions, devices and
78
+ dtypes.
79
+ - How-to guides: [kernel sums](https://keckj.github.io/kernox/guides/kernel-sums/),
80
+ [nearest neighbours](https://keckj.github.io/kernox/guides/nearest-neighbours/),
81
+ [log-sum-exp and Sinkhorn](https://keckj.github.io/kernox/guides/logsumexp/),
82
+ [gradients](https://keckj.github.io/kernox/guides/gradients/),
83
+ [linear systems](https://keckj.github.io/kernox/guides/linear-systems/) and more.
84
+ - [Coming from PyKeOps](https://keckj.github.io/kernox/pykeops/): a migration guide.
85
+ - [Backends and hardware](https://keckj.github.io/kernox/backends/): what runs where, and the known
86
+ limitations.
87
+
88
+ ## About the name and logo
89
+
90
+ symox is *symbolic* plus *ox*: a rusty ox, since symox is written in Rust.
91
+ kernox is *kernels* plus the ox of symox, and also a nod to the redox chemistry
92
+ of copper. The logo goes from orange copper (the ox) to turquoise verdigris
93
+ (the trails and the compute grid), that is, from copper to its oxidation
94
+ patina. And redox contains *reduction*, which is what kernox does: sum, min and
95
+ max, as drawn in the logo.
96
+
97
+ ## License
98
+
99
+ At your option, [MIT](https://github.com/keckj/kernox/blob/v1.0.1/LICENSE-MIT) or [Apache-2.0](https://github.com/keckj/kernox/blob/v1.0.1/LICENSE-APACHE).
100
+ Provenance of third-party code and algorithms (KeOps, symox):
101
+ [`THIRD_PARTY.md`](https://github.com/keckj/kernox/blob/v1.0.1/THIRD_PARTY.md).
102
+
103
+ ## Projects using kernox
104
+
105
+ - [remblais](https://github.com/keckj/remblais): a faster GeomLoss (Sinkhorn
106
+ divergences, kernel norms and optimal transport) on NVIDIA, AMD and Intel
107
+ GPUs. Documentation: <https://keckj.github.io/remblais/>
108
+
109
+ ## Related projects
110
+
111
+ - symox, symbolic engine and code generation: <https://github.com/keckj/symox>
112
+ - KeOps / PyKeOps: <https://github.com/getkeops/keops>
@@ -0,0 +1,20 @@
1
+ # Third-party code and algorithms
2
+
3
+ Kernox is dual-licensed under MIT or Apache-2.0, at your option
4
+ ([`LICENSE-MIT`](LICENSE-MIT), [`LICENSE-APACHE`](LICENSE-APACHE)). The table
5
+ below lists the code and algorithms taken from third-party projects.
6
+
7
+ | Kernox file | Source | Revision | License | Nature |
8
+ | --- | --- | --- | --- | --- |
9
+ | `kernox/backends/cuda/_driver.py` | `symox/python/symox/extra/codegen/cuda.py` (keckj/symox) | `2e623e66bb31882e31f6dbfff6f77ae4bd945408` | MIT OR Apache-2.0 | structure of the ctypes Driver/NVRTC binding taken and adapted (CUBIN, occupancy, shared primary context) |
10
+ | `kernox/backends/cuda/_kernel.py` | KeOps `keopscore/keopscore/mapreduce/gpu/GpuReduc1D.py`, `keopscore/keopscore/formulas/reductions/KMin_ArgKMin_Reduction.py` (getkeops/keops) | `ef72bc907df78cd18bff866d3dc7cb6375f11a4d` | MIT | algorithmic scheme (one thread per row i, j tiles in shared memory, blockwise sum, sorted K list); **no line copied**, code rewritten |
11
+ | `kernox/backends/sycl/codegen.py` | KeOps `keopscore/keopscore/mapreduce/gpu/GpuReduc1D.py`, `keopscore/keopscore/formulas/reductions/KMin_ArgKMin_Reduction.py`, `keopscore/keopscore/formulas/reductions/sum_schemes.py` (getkeops/keops) | `ef72bc907df78cd18bff866d3dc7cb6375f11a4d` | MIT | algorithmic scheme (one work-item per row i, j tiles in local memory, blockwise sum, sorted K list); **no line copied**, SYCL code rewritten |
12
+ | `kernox/backends/sycl/_pair_local.py` (temporary) | `symox/python/symox/extra/codegen/sycl.py` (keckj/symox) | `2e623e66bb31882e31f6dbfff6f77ae4bd945408` | MIT OR Apache-2.0 | call to `syclcode_function` (library, no copy) |
13
+ | `tests/conformance/test_keops_port.py` | KeOps `pykeops/pykeops/test/test_torch.py` (`test_generic_syntax_float`, `test_generic_syntax_double`, `test_LazyTensor_sum`, `test_LazyTensor_min`, `test_LazyTensor_min_chunked`), `test_numpy.py` (`test_argkmin`), `test_chunks.py`, `test_finalchunks.py`, `test_lazytensor_clamp.py` (getkeops/keops) | `ef72bc907df78cd18bff866d3dc7cb6375f11a4d` | MIT | formulas, dimensions, sizes and data distributions of the forward tests, rewritten on the Kernox frontend (without autograd, batch or LogSumExp); tolerances replaced by the judgment of the conformance suite; no line copied verbatim |
14
+ | `kernox/ops.py`, `tests/test_ops.py` | KeOps `keopscore/keopscore/formulas/maths/{Round,Mod,ReLU,Step,SinXDivX,XLogX,ClampInt,IfElse,Inv,Normalize,SqDist,WeightedSqNorm,WeightedSqDist,SqNormIso,SqNormDiag,SymSqNorm,OneHot,Elem,Extract,MatVecMult,VecMatMult,TensorProd,TensorDot,Kron,BSpline,SoftDTW_SqDist}.py`, `keopscore/keopscore/utils/math_functions.py`, signatures from `pykeops/pykeops/common/lazy_tensor.py` (getkeops/keops) | `ef72bc907df78cd18bff866d3dc7cb6375f11a4d` | MIT | semantics of the operations (C expressions, order of operations of De Boor, row-major layouts, names and signatures) re-expressed as symox primitives; the NumPy references of the tests (`keops_bspline`, `keops_one_hot`, `keops_round`, `keops_softdtw`) transcribe this C; no line copied |
15
+ | `kernox/linalg.py` | KeOps `pykeops/pykeops/common/operations.py` (`ConjugateGradientSolver`, `_get_atol_rtol`), `pykeops/pykeops/torch/operations.py` (`KernelSolveAutograd`), `pykeops/pykeops/common/lazy_tensor.py` (`solve`, `matvec`, `rmatvec`, `T`) (getkeops/keops) | `ef72bc907df78cd18bff866d3dc7cb6375f11a4d` | MIT | conjugate gradient iteration (criterion `‖r‖ < max(eps‖b‖, eps)`, `maxiter = 10·M`), default value `alpha = 1e-10`, backward pass through the adjoint solve (`Kᵀ = K`); rewritten (symbolic linearity check, VJP for `rmatvec`); no line copied |
16
+ | `kernox/complex.py` | KeOps `keopscore/keopscore/formulas/complex/*.py` (`Real2Complex`, `Imag2Complex`, `ComplexExp1j`, `ComplexReal`, `ComplexImag`, `Conj`, `ComplexSquareAbs`, `ComplexAbs`, `ComplexAngle`, `ComplexExp`, `ComplexAdd`, `ComplexSubtract`, `ComplexMult`, `ComplexRealScal`, `ComplexDivide`, `ComplexSum`), `pykeops/pykeops/common/lazy_tensor.py` (`ComplexGenericLazyTensor`) (getkeops/keops) | `ef72bc907df78cd18bff866d3dc7cb6375f11a4d` | MIT | interleaved representation and definition of each operation (including division via `1/|g|²`, modulus without hypot), promotion and refusal rules; re-expressed as symox primitives; no line copied |
17
+
18
+ The full licenses are in the original repositories: symox
19
+ (<https://github.com/keckj/symox>, `LICENSE-MIT` and `LICENSE-APACHE`, MIT OR
20
+ Apache-2.0); KeOps (<https://github.com/getkeops/keops>, `licence.txt`, MIT).
@@ -0,0 +1,101 @@
1
+ """kernox: fused symbolic reductions on GPUs.
2
+
3
+ Documentation: https://keckj.github.io/kernox/. Expressions are symox objects; ``compile`` produces a
4
+ callable that validates its inputs before any native launch.
5
+ """
6
+
7
+ from .errors import (
8
+ BackendUnavailableError,
9
+ ConstantConversionError,
10
+ KernoxError,
11
+ UnsupportedError,
12
+ ValidationError,
13
+ )
14
+ from .expr import (
15
+ Formula,
16
+ Param,
17
+ ReductionExpr,
18
+ Vi,
19
+ Vj,
20
+ abs,
21
+ acos,
22
+ asin,
23
+ atan,
24
+ atan2,
25
+ cat,
26
+ ceiling,
27
+ clamp,
28
+ constant,
29
+ cos,
30
+ cosh,
31
+ eq,
32
+ exp,
33
+ floor,
34
+ log,
35
+ maximum,
36
+ minimum,
37
+ ne,
38
+ rsqrt,
39
+ sign,
40
+ sin,
41
+ sinh,
42
+ sqrt,
43
+ square,
44
+ tan,
45
+ tanh,
46
+ where,
47
+ )
48
+ from .ops import ( # noqa: E402 - also attaches the PyKeOps methods to Formula
49
+ bspline,
50
+ clampint,
51
+ elem,
52
+ extract,
53
+ ifelse,
54
+ inv,
55
+ kron,
56
+ matvecmult,
57
+ mod,
58
+ normalize,
59
+ one_hot,
60
+ relu,
61
+ round,
62
+ sinc,
63
+ sinxdivx,
64
+ softdtw_sqdist,
65
+ grad,
66
+ diff,
67
+ grad_matrix,
68
+ divergence,
69
+ laplacian,
70
+ trace_operator,
71
+ sqdist,
72
+ step,
73
+ tensordot,
74
+ tensorprod,
75
+ vecmatmult,
76
+ weightedsqdist,
77
+ weightedsqnorm,
78
+ xlogx,
79
+ )
80
+ from .complex import ComplexFormula, angle, complex_formula, conj, exp1j, imag, imag2complex, real, real2complex
81
+ from .linalg import LinearOperator, conjugate_gradient
82
+ from .ranges import Ranges, ranges_from_labels
83
+ from .runtime import RangedReduction, Reduction, compile, get_backend, register_backend
84
+ from .tuning import export_wisdom, forget_wisdom, import_wisdom
85
+ from .diagnostics import diagnostics # noqa: E402 - also `python -m kernox.diagnostics`
86
+
87
+ __all__ = [
88
+ "Vi", "Vj", "Param", "Formula", "ReductionExpr", "Reduction", "RangedReduction", "compile",
89
+ "Ranges", "ranges_from_labels", "LinearOperator", "conjugate_gradient",
90
+ "ComplexFormula", "real2complex", "imag2complex", "exp1j", "complex_formula", "conj", "angle", "real", "imag",
91
+ "register_backend", "get_backend", "diagnostics", "export_wisdom", "import_wisdom", "forget_wisdom", "constant", "where", "eq", "ne", "cat",
92
+ "exp", "log", "sqrt", "rsqrt", "sin", "cos", "tan", "asin", "acos", "atan", "atan2",
93
+ "sinh", "cosh", "tanh", "abs", "sign", "floor", "ceiling", "square",
94
+ "minimum", "maximum", "clamp",
95
+ "relu", "step", "sinxdivx", "sinc", "xlogx", "inv", "round", "mod", "clampint", "ifelse",
96
+ "normalize", "sqdist", "weightedsqnorm", "weightedsqdist", "one_hot", "elem", "extract",
97
+ "matvecmult", "vecmatmult", "tensorprod", "tensordot", "kron", "bspline", "softdtw_sqdist",
98
+ "grad", "diff", "grad_matrix", "divergence", "laplacian", "trace_operator",
99
+ "KernoxError", "ValidationError", "ConstantConversionError",
100
+ "BackendUnavailableError", "UnsupportedError",
101
+ ]
@@ -0,0 +1,13 @@
1
+ """Reading of the ``KERNOX_*`` environment variables.
2
+
3
+ An empty value is treated as an unset variable.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import os
9
+
10
+
11
+ def getenv(name: str, default: str | None = None) -> str | None:
12
+ """Value of ``name`` if it is set and non-empty, otherwise ``default``."""
13
+ return os.environ.get(name) or default