cyxla 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.
- cyxla-0.1.0/.gitignore +18 -0
- cyxla-0.1.0/.python-version +1 -0
- cyxla-0.1.0/LICENSE.md +135 -0
- cyxla-0.1.0/PKG-INFO +235 -0
- cyxla-0.1.0/README.md +211 -0
- cyxla-0.1.0/docs/api/cache.md +13 -0
- cyxla-0.1.0/docs/api/custom-calls.md +12 -0
- cyxla-0.1.0/docs/api/extension.md +13 -0
- cyxla-0.1.0/docs/api/plugins.md +29 -0
- cyxla-0.1.0/docs/api/programs.md +17 -0
- cyxla-0.1.0/docs/cpu-plugin.md +62 -0
- cyxla-0.1.0/docs/design.md +63 -0
- cyxla-0.1.0/docs/development.md +74 -0
- cyxla-0.1.0/docs/guide/caching.md +56 -0
- cyxla-0.1.0/docs/guide/custom-calls.md +116 -0
- cyxla-0.1.0/docs/guide/extensions.md +65 -0
- cyxla-0.1.0/docs/guide/plugins.md +65 -0
- cyxla-0.1.0/docs/guide/running.md +107 -0
- cyxla-0.1.0/docs/index.md +75 -0
- cyxla-0.1.0/docs/installation.md +53 -0
- cyxla-0.1.0/docs/references.md +19 -0
- cyxla-0.1.0/meson.build +19 -0
- cyxla-0.1.0/meson.options +2 -0
- cyxla-0.1.0/notebooks/colab_gpu_tests.ipynb +417 -0
- cyxla-0.1.0/pyproject.toml +93 -0
- cyxla-0.1.0/src/cyxla/__init__.py +114 -0
- cyxla-0.1.0/src/cyxla/__main__.py +38 -0
- cyxla-0.1.0/src/cyxla/_cache.py +281 -0
- cyxla-0.1.0/src/cyxla/_ffi.py +320 -0
- cyxla-0.1.0/src/cyxla/_lowering.py +189 -0
- cyxla-0.1.0/src/cyxla/_pjrt.pxd +291 -0
- cyxla-0.1.0/src/cyxla/_platform.h +118 -0
- cyxla-0.1.0/src/cyxla/_platform.pxd +10 -0
- cyxla-0.1.0/src/cyxla/_plugins.py +326 -0
- cyxla-0.1.0/src/cyxla/_runtime.pxd +77 -0
- cyxla-0.1.0/src/cyxla/_runtime.py +979 -0
- cyxla-0.1.0/src/cyxla/_runtime.pyi +44 -0
- cyxla-0.1.0/src/cyxla/_types.py +66 -0
- cyxla-0.1.0/src/cyxla/include/xla/LICENSE +201 -0
- cyxla-0.1.0/src/cyxla/include/xla/README.md +11 -0
- cyxla-0.1.0/src/cyxla/include/xla/pjrt/c/pjrt_c_api.h +3241 -0
- cyxla-0.1.0/src/cyxla/include/xla/pjrt/c/pjrt_c_api_ffi_extension.h +108 -0
- cyxla-0.1.0/src/cyxla/meson.build +72 -0
- cyxla-0.1.0/src/cyxla/py.typed +0 -0
- cyxla-0.1.0/tests/conftest.py +164 -0
- cyxla-0.1.0/tests/downstream/meson.build +27 -0
- cyxla-0.1.0/tests/downstream/src/downstream_square.py +61 -0
- cyxla-0.1.0/tests/ffi_library/meson.build +9 -0
- cyxla-0.1.0/tests/ffi_library/meson.options +1 -0
- cyxla-0.1.0/tests/ffi_library/scale.cc +33 -0
- cyxla-0.1.0/tests/libraries/export.h +6 -0
- cyxla-0.1.0/tests/libraries/meson.build +9 -0
- cyxla-0.1.0/tests/libraries/meson.options +1 -0
- cyxla-0.1.0/tests/libraries/not_plugin.c +4 -0
- cyxla-0.1.0/tests/libraries/old_plugin.c +15 -0
- cyxla-0.1.0/tests/libraries/preloaded.c +4 -0
- cyxla-0.1.0/tests/test_cache.py +184 -0
- cyxla-0.1.0/tests/test_downstream.py +81 -0
- cyxla-0.1.0/tests/test_ffi.py +464 -0
- cyxla-0.1.0/tests/test_gpu_notebook.py +85 -0
- cyxla-0.1.0/tests/test_lowering.py +218 -0
- cyxla-0.1.0/tests/test_main.py +24 -0
- cyxla-0.1.0/tests/test_plugins.py +203 -0
- cyxla-0.1.0/tests/test_runtime.py +347 -0
- cyxla-0.1.0/uv.lock +2054 -0
- cyxla-0.1.0/zensical.toml +54 -0
cyxla-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Python-generated files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[oc]
|
|
4
|
+
build/
|
|
5
|
+
dist/
|
|
6
|
+
wheels/
|
|
7
|
+
*.egg-info
|
|
8
|
+
|
|
9
|
+
# Virtual environments
|
|
10
|
+
.venv*
|
|
11
|
+
|
|
12
|
+
# Test output
|
|
13
|
+
.coverage
|
|
14
|
+
.coverage.*
|
|
15
|
+
coverage.xml
|
|
16
|
+
|
|
17
|
+
# Coverage builds copy the generated C file next to the Cython source.
|
|
18
|
+
/src/cyxla/*.c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
cyxla-0.1.0/LICENSE.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
**HIPPOCRATIC LICENSE**
|
|
2
|
+
|
|
3
|
+
**Version 3.0, October 2021**
|
|
4
|
+
|
|
5
|
+
<https://firstdonoharm.dev/version/3/0/bds-eco-ffd-law-mil-sv.md>
|
|
6
|
+
|
|
7
|
+
**TERMS AND CONDITIONS**
|
|
8
|
+
|
|
9
|
+
TERMS AND CONDITIONS FOR USE, COPY, MODIFICATION, PREPARATION OF DERIVATIVE WORK, REPRODUCTION, AND DISTRIBUTION:
|
|
10
|
+
|
|
11
|
+
**[1.](#1) DEFINITIONS:**
|
|
12
|
+
|
|
13
|
+
_This section defines certain terms used throughout this license agreement._
|
|
14
|
+
|
|
15
|
+
[1.1.](#1.1) “License” means the terms and conditions, as stated herein, for use, copy, modification, preparation of derivative work, reproduction, and distribution of Software (as defined below).
|
|
16
|
+
|
|
17
|
+
[1.2.](#1.2) “Licensor” means the copyright and/or patent owner or entity authorized by the copyright and/or patent owner that is granting the License.
|
|
18
|
+
|
|
19
|
+
[1.3.](#1.3) “Licensee” means the individual or entity exercising permissions granted by this License, including the use, copy, modification, preparation of derivative work, reproduction, and distribution of Software (as defined below).
|
|
20
|
+
|
|
21
|
+
[1.4.](#1.4) “Software” means any copyrighted work, including but not limited to software code, authored by Licensor and made available under this License.
|
|
22
|
+
|
|
23
|
+
[1.5.](#1.5) “Supply Chain” means the sequence of processes involved in the production and/or distribution of a commodity, good, or service offered by the Licensee.
|
|
24
|
+
|
|
25
|
+
[1.6.](#1.6) “Supply Chain Impacted Party” or “Supply Chain Impacted Parties” means any person(s) directly impacted by any of Licensee’s Supply Chain, including the practices of all persons or entities within the Supply Chain prior to a good or service reaching the Licensee.
|
|
26
|
+
|
|
27
|
+
[1.7.](#1.7) “Duty of Care” is defined by its use in tort law, delict law, and/or similar bodies of law closely related to tort and/or delict law, including without limitation, a requirement to act with the watchfulness, attention, caution, and prudence that a reasonable person in the same or similar circumstances would use towards any Supply Chain Impacted Party.
|
|
28
|
+
|
|
29
|
+
[1.8.](#1.8) “Worker” is defined to include any and all permanent, temporary, and agency workers, as well as piece-rate, salaried, hourly paid, legal young (minors), part-time, night, and migrant workers.
|
|
30
|
+
|
|
31
|
+
**[2.](#2) INTELLECTUAL PROPERTY GRANTS:**
|
|
32
|
+
|
|
33
|
+
_This section identifies intellectual property rights granted to a Licensee_.
|
|
34
|
+
|
|
35
|
+
[2.1.](#2.1) _Grant of Copyright License_: Subject to the terms and conditions of this License, Licensor hereby grants to Licensee a worldwide, non-exclusive, no-charge, royalty-free copyright license to use, copy, modify, prepare derivative work, reproduce, or distribute the Software, Licensor authored modified software, or other work derived from the Software.
|
|
36
|
+
|
|
37
|
+
[2.2.](#2.2) _Grant of Patent License_: Subject to the terms and conditions of this License, Licensor hereby grants Licensee a worldwide, non-exclusive, no-charge, royalty-free patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer Software.
|
|
38
|
+
|
|
39
|
+
**[3.](#3) ETHICAL STANDARDS:**
|
|
40
|
+
|
|
41
|
+
_This section lists conditions the Licensee must comply with in order to have rights under this License._
|
|
42
|
+
|
|
43
|
+
The rights granted to the Licensee by this License are expressly made subject to the Licensee’s ongoing compliance with the following conditions:
|
|
44
|
+
|
|
45
|
+
* [3.1.](#3.1) The Licensee SHALL NOT, whether directly or indirectly, through agents or assigns:
|
|
46
|
+
|
|
47
|
+
* [3.1.1.](#3.1.1) Infringe upon any person’s right to life or security of person, engage in extrajudicial killings, or commit murder, without lawful cause (See Article 3, _United Nations Universal Declaration of Human Rights_; Article 6, _International Covenant on Civil and Political Rights_)
|
|
48
|
+
* [3.1.2.](#3.1.2) Hold any person in slavery, servitude, or forced labor (See Article 4, _United Nations Universal Declaration of Human Rights_; Article 8, _International Covenant on Civil and Political Rights_);
|
|
49
|
+
* [3.1.3.](#3.1.3) Contribute to the institution of slavery, slave trading, forced labor, or unlawful child labor (See Article 4, _United Nations Universal Declaration of Human Rights_; Article 8, _International Covenant on Civil and Political Rights_);
|
|
50
|
+
* [3.1.4.](#3.1.4) Torture or subject any person to cruel, inhumane, or degrading treatment or punishment (See Article 5, _United Nations Universal Declaration of Human Rights_; Article 7, _International Covenant on Civil and Political Rights_);
|
|
51
|
+
* [3.1.5.](#3.1.5) Discriminate on the basis of sex, gender, sexual orientation, race, ethnicity, nationality, religion, caste, age, medical disability or impairment, and/or any other like circumstances (See Article 7, _United Nations Universal Declaration of Human Rights_; Article 2, _International Covenant on Economic, Social and Cultural Rights_; Article 26, _International Covenant on Civil and Political Rights_);
|
|
52
|
+
* [3.1.6.](#3.1.6) Prevent any person from exercising his/her/their right to seek an effective remedy by a competent court or national tribunal (including domestic judicial systems, international courts, arbitration bodies, and other adjudicating bodies) for actions violating the fundamental rights granted to him/her/them by applicable constitutions, applicable laws, or by this License (See Article 8, _United Nations Universal Declaration of Human Rights_; Articles 9 and 14, _International Covenant on Civil and Political Rights_);
|
|
53
|
+
* [3.1.7.](#3.1.7) Subject any person to arbitrary arrest, detention, or exile (See Article 9, _United Nations Universal Declaration of Human Rights_; Article 9, _International Covenant on Civil and Political Rights_);
|
|
54
|
+
* [3.1.8.](#3.1.8) Subject any person to arbitrary interference with a person’s privacy, family, home, or correspondence without the express written consent of the person (See Article 12, _United Nations Universal Declaration of Human Rights_; Article 17, _International Covenant on Civil and Political Rights_);
|
|
55
|
+
* [3.1.9.](#3.1.9) Arbitrarily deprive any person of his/her/their property (See Article 17, _United Nations Universal Declaration of Human Rights_);
|
|
56
|
+
* [3.1.10.](#3.1.10) Forcibly remove indigenous peoples from their lands or territories or take any action with the aim or effect of dispossessing indigenous peoples from their lands, territories, or resources, including without limitation the intellectual property or traditional knowledge of indigenous peoples, without the free, prior, and informed consent of indigenous peoples concerned (See Articles 8 and 10, _United Nations Declaration on the Rights of Indigenous Peoples_);
|
|
57
|
+
* [3.1.11.](#3.1.11) _Fossil Fuel Divestment_: Be an individual or entity, or a representative, agent, affiliate, successor, attorney, or assign of an individual or entity, on the [FFI Solutions Carbon Underground 200 list](https://www.ffisolutions.com/research-analytics-index-solutions/research-screening/the-carbon-underground-200/?cn-reloaded=1);
|
|
58
|
+
* [3.1.12.](#3.1.12) _Ecocide_: Commit ecocide:
|
|
59
|
+
|
|
60
|
+
* [3.1.12.1.](#3.1.12.1) For the purpose of this section, “ecocide” means unlawful or wanton acts committed with knowledge that there is a substantial likelihood of severe and either widespread or long-term damage to the environment being caused by those acts;
|
|
61
|
+
* [3.1.12.2.](#3.1.12.2) For the purpose of further defining ecocide and the terms contained in the previous paragraph:
|
|
62
|
+
|
|
63
|
+
* [3.1.12.2.1.](#3.1.12.2.1) “Wanton” means with reckless disregard for damage which would be clearly excessive in relation to the social and economic benefits anticipated;
|
|
64
|
+
* [3.1.12.2.2.](#3.1.12.2.2) “Severe” means damage which involves very serious adverse changes, disruption, or harm to any element of the environment, including grave impacts on human life or natural, cultural, or economic resources;
|
|
65
|
+
* [3.1.12.2.3.](#3.1.12.2.3) “Widespread” means damage which extends beyond a limited geographic area, crosses state boundaries, or is suffered by an entire ecosystem or species or a large number of human beings;
|
|
66
|
+
* [3.1.12.2.4.](#3.1.12.2.4) “Long-term” means damage which is irreversible or which cannot be redressed through natural recovery within a reasonable period of time; and
|
|
67
|
+
* [3.1.12.2.5.](#3.1.12.2.5) “Environment” means the earth, its biosphere, cryosphere, lithosphere, hydrosphere, and atmosphere, as well as outer space
|
|
68
|
+
(See Section II, _Independent Expert Panel for the Legal Definition of Ecocide_, Stop Ecocide Foundation and the Promise Institute for Human Rights at UCLA School of Law, June 2021);
|
|
69
|
+
* [3.1.13.](#3.1.13) _Boycott / Divestment / Sanctions_: Be an individual or entity, or a representative, agent, affiliate, successor, attorney, or assign of an individual or entity, identified by the Boycott, Divestment, Sanctions (“BDS”) movement on its website (<https://bdsmovement.net/> and <https://bdsmovement.net/get-involved/what-to-boycott>) as a target for boycott;
|
|
70
|
+
* [3.1.14.](#3.1.14) _Mass Surveillance_: Be a government agency or multinational corporation, or a representative, agent, affiliate, successor, attorney, or assign of a government or multinational corporation, which participates in mass surveillance programs;
|
|
71
|
+
* [3.1.15.](#3.1.15) _Military Activities_: Be an entity or a representative, agent, affiliate, successor, attorney, or assign of an entity which conducts military activities;
|
|
72
|
+
* [3.1.16.](#3.1.16) _Law Enforcement_: Be an individual or entity, or a representative, agent, affiliate, successor, attorney, or assign of an individual or entity, that provides good or services to, or otherwise enters into any commercial contracts with, any local, state, or federal law enforcement agency;
|
|
73
|
+
* [3.1.17.](#3.1.17) Interfere with Workers’ free exercise of the right to organize and associate (See Article 20, United Nations Universal Declaration of Human Rights; C087 - Freedom of Association and Protection of the Right to Organise Convention, 1948 (No. 87), International Labour Organization; Article 8, International Covenant on Economic, Social and Cultural Rights); and
|
|
74
|
+
* [3.1.18.](#3.1.18) Harm the environment in a manner inconsistent with local, state, national, or international law.
|
|
75
|
+
* [3.2.](#3.2) The Licensee SHALL:
|
|
76
|
+
|
|
77
|
+
* [3.2.1.](#3.2.1) Provide equal pay for equal work where the performance of such work requires equal skill, effort, and responsibility, and which are performed under similar working conditions, except where such payment is made pursuant to:
|
|
78
|
+
|
|
79
|
+
* [3.2.1.1.](#3.2.1.1) A seniority system;
|
|
80
|
+
* [3.2.1.2.](#3.2.1.2) A merit system;
|
|
81
|
+
* [3.2.1.3.](#3.2.1.3) A system which measures earnings by quantity or quality of production; or
|
|
82
|
+
* [3.2.1.4.](#3.2.1.4) A differential based on any other factor other than sex, gender, sexual orientation, race, ethnicity, nationality, religion, caste, age, medical disability or impairment, and/or any other like circumstances (See 29 U.S.C.A. § 206(d)(1); Article 23, _United Nations Universal Declaration of Human Rights_; Article 7, _International Covenant on Economic, Social and Cultural Rights_; Article 26, _International Covenant on Civil and Political Rights_); and
|
|
83
|
+
* [3.2.2.](#3.2.2) Allow for reasonable limitation of working hours and periodic holidays with pay (See Article 24, _United Nations Universal Declaration of Human Rights_; Article 7, _International Covenant on Economic, Social and Cultural Rights_).
|
|
84
|
+
|
|
85
|
+
**[4.](#4) SUPPLY CHAIN IMPACTED PARTIES:**
|
|
86
|
+
|
|
87
|
+
_This section identifies additional individuals or entities that a Licensee could harm as a result of violating the Ethical Standards section, the condition that the Licensee must voluntarily accept a Duty of Care for those individuals or entities, and the right to a private right of action that those individuals or entities possess as a result of violations of the Ethical Standards section._
|
|
88
|
+
|
|
89
|
+
[4.1.](#4.1) In addition to the above Ethical Standards, Licensee voluntarily accepts a Duty of Care for Supply Chain Impacted Parties of this License, including individuals and communities impacted by violations of the Ethical Standards. The Duty of Care is breached when a provision within the Ethical Standards section is violated by a Licensee, one of its successors or assigns, or by an individual or entity that exists within the Supply Chain prior to a good or service reaching the Licensee.
|
|
90
|
+
|
|
91
|
+
[4.2.](#4.2) Breaches of the Duty of Care, as stated within this section, shall create a private right of action, allowing any Supply Chain Impacted Party harmed by the Licensee to take legal action against the Licensee in accordance with applicable negligence laws, whether they be in tort law, delict law, and/or similar bodies of law closely related to tort and/or delict law, regardless if Licensee is directly responsible for the harms suffered by a Supply Chain Impacted Party. Nothing in this section shall be interpreted to include acts committed by individuals outside of the scope of his/her/their employment.
|
|
92
|
+
|
|
93
|
+
[5.](#5) **NOTICE:** _This section explains when a Licensee must notify others of the License._
|
|
94
|
+
|
|
95
|
+
[5.1.](#5.1) _Distribution of Notice_: Licensee must ensure that everyone who receives a copy of or uses any part of Software from Licensee, with or without changes, also receives the License and the copyright notice included with Software (and if included by the Licensor, patent, trademark, and attribution notice). Licensee must ensure that License is prominently displayed so that any individual or entity seeking to download, copy, use, or otherwise receive any part of Software from Licensee is notified of this License and its terms and conditions. Licensee must cause any modified versions of the Software to carry prominent notices stating that Licensee changed the Software.
|
|
96
|
+
|
|
97
|
+
[5.2.](#5.2) _Modified Software_: Licensee is free to create modifications of the Software and distribute only the modified portion created by Licensee, however, any derivative work stemming from the Software or its code must be distributed pursuant to this License, including this Notice provision.
|
|
98
|
+
|
|
99
|
+
[5.3.](#5.3) _Recipients as Licensees_: Any individual or entity that uses, copies, modifies, reproduces, distributes, or prepares derivative work based upon the Software, all or part of the Software’s code, or a derivative work developed by using the Software, including a portion of its code, is a Licensee as defined above and is subject to the terms and conditions of this License.
|
|
100
|
+
|
|
101
|
+
**[6.](#6) REPRESENTATIONS AND WARRANTIES:**
|
|
102
|
+
|
|
103
|
+
[6.1.](#6.1) _Disclaimer of Warranty_: TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES “AS IS,” WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR SHALL NOT BE LIABLE TO ANY PERSON OR ENTITY FOR ANY DAMAGES OR OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THIS LICENSE, UNDER ANY LEGAL CLAIM.
|
|
104
|
+
|
|
105
|
+
[6.2.](#6.2) _Limitation of Liability_: LICENSEE SHALL HOLD LICENSOR HARMLESS AGAINST ANY AND ALL CLAIMS, DEBTS, DUES, LIABILITIES, LIENS, CAUSES OF ACTION, DEMANDS, OBLIGATIONS, DISPUTES, DAMAGES, LOSSES, EXPENSES, ATTORNEYS’ FEES, COSTS, LIABILITIES, AND ALL OTHER CLAIMS OF EVERY KIND AND NATURE WHATSOEVER, WHETHER KNOWN OR UNKNOWN, ANTICIPATED OR UNANTICIPATED, FORESEEN OR UNFORESEEN, ACCRUED OR UNACCRUED, DISCLOSED OR UNDISCLOSED, ARISING OUT OF OR RELATING TO LICENSEE’S USE OF THE SOFTWARE. NOTHING IN THIS SECTION SHOULD BE INTERPRETED TO REQUIRE LICENSEE TO INDEMNIFY LICENSOR, NOR REQUIRE LICENSOR TO INDEMNIFY LICENSEE.
|
|
106
|
+
|
|
107
|
+
**[7.](#7) TERMINATION**
|
|
108
|
+
|
|
109
|
+
[7.1.](#7.1) _Violations of Ethical Standards or Breaching Duty of Care_: If Licensee violates the Ethical Standards section or Licensee, or any other person or entity within the Supply Chain prior to a good or service reaching the Licensee, breaches its Duty of Care to Supply Chain Impacted Parties, Licensee must remedy the violation or harm caused by Licensee within 30 days of being notified of the violation or harm. If Licensee fails to remedy the violation or harm within 30 days, all rights in the Software granted to Licensee by License will be null and void as between Licensor and Licensee.
|
|
110
|
+
|
|
111
|
+
[7.2.](#7.2) _Failure of Notice_: If any person or entity notifies Licensee in writing that Licensee has not complied with the Notice section of this License, Licensee can keep this License by taking all practical steps to comply within 30 days after the notice of noncompliance. If Licensee does not do so, Licensee’s License (and all rights licensed hereunder) will end immediately.
|
|
112
|
+
|
|
113
|
+
[7.3.](#7.3) _Judicial Findings_: In the event Licensee is found by a civil, criminal, administrative, or other court of competent jurisdiction, or some other adjudicating body with legal authority, to have committed actions which are in violation of the Ethical Standards or Supply Chain Impacted Party sections of this License, all rights granted to Licensee by this License will terminate immediately.
|
|
114
|
+
|
|
115
|
+
[7.4.](#7.4) _Patent Litigation_: If Licensee institutes patent litigation against any entity (including a cross-claim or counterclaim in a suit) alleging that the Software, all or part of the Software’s code, or a derivative work developed using the Software, including a portion of its code, constitutes direct or contributory patent infringement, then any patent license, along with all other rights, granted to Licensee under this License will terminate as of the date such litigation is filed.
|
|
116
|
+
|
|
117
|
+
[7.5.](#7.5) _Additional Remedies_: Termination of the License by failing to remedy harms in no way prevents Licensor or Supply Chain Impacted Party from seeking appropriate remedies at law or in equity.
|
|
118
|
+
|
|
119
|
+
**[8.](#8) MISCELLANEOUS:**
|
|
120
|
+
|
|
121
|
+
[8.1.](#8.1) _Conditions_: Sections 3, 4.1, 5.1, 5.2, 7.1, 7.2, 7.3, and 7.4 are conditions of the rights granted to Licensee in the License.
|
|
122
|
+
|
|
123
|
+
[8.2.](#8.2) _Equitable Relief_: Licensor and any Supply Chain Impacted Party shall be entitled to equitable relief, including injunctive relief or specific performance of the terms hereof, in addition to any other remedy to which they are entitled at law or in equity.
|
|
124
|
+
|
|
125
|
+
[8.3.](#8.3) _Severability_: If any term or provision of this License is determined to be invalid, illegal, or unenforceable by a court of competent jurisdiction, any such determination of invalidity, illegality, or unenforceability shall not affect any other term or provision of this License or invalidate or render unenforceable such term or provision in any other jurisdiction. If the determination of invalidity, illegality, or unenforceability by a court of competent jurisdiction pertains to the terms or provisions contained in the Ethical Standards section of this License, all rights in the Software granted to Licensee shall be deemed null and void as between Licensor and Licensee.
|
|
126
|
+
|
|
127
|
+
[8.4.](#8.4) _Section Titles_: Section titles are solely written for organizational purposes and should not be used to interpret the language within each section.
|
|
128
|
+
|
|
129
|
+
[8.5.](#8.5) _Citations_: Citations are solely written to provide context for the source of the provisions in the Ethical Standards.
|
|
130
|
+
|
|
131
|
+
[8.6.](#8.6) _Section Summaries_: Some sections have a brief _italicized description_ which is provided for the sole purpose of briefly describing the section and should not be used to interpret the terms of the License.
|
|
132
|
+
|
|
133
|
+
[8.7.](#8.7) _Entire License_: This is the entire License between the Licensor and Licensee with respect to the claims released herein and that the consideration stated herein is the only consideration or compensation to be paid or exchanged between them for this License. This License cannot be modified or amended except in a writing signed by Licensor and Licensee.
|
|
134
|
+
|
|
135
|
+
[8.8.](#8.8) _Successors and Assigns_: This License shall be binding upon and inure to the benefit of the Licensor’s and Licensee’s respective heirs, successors, and assigns.
|
cyxla-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cyxla
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A bridge from JAX to native code through the PJRT C API
|
|
5
|
+
Author-Email: Nardi Lam <mail@nardilam.nl>
|
|
6
|
+
License-File: LICENSE.md
|
|
7
|
+
License-File: src/cyxla/include/xla/LICENSE
|
|
8
|
+
Project-URL: Source, https://github.com/nardi/cyxla/tree/main/cyxla
|
|
9
|
+
Project-URL: Documentation, https://nardi.github.io/cyxla/
|
|
10
|
+
Requires-Python: >=3.11
|
|
11
|
+
Requires-Dist: jax>=0.10
|
|
12
|
+
Requires-Dist: numpy>=1.26
|
|
13
|
+
Provides-Extra: cpu
|
|
14
|
+
Requires-Dist: cyxla-pjrt-cpu>=0.12; extra == "cpu"
|
|
15
|
+
Provides-Extra: cuda12
|
|
16
|
+
Requires-Dist: jax-cuda12-plugin[with-cuda]; extra == "cuda12"
|
|
17
|
+
Provides-Extra: cuda13
|
|
18
|
+
Requires-Dist: jax-cuda13-plugin[with-cuda]; extra == "cuda13"
|
|
19
|
+
Provides-Extra: rocm7
|
|
20
|
+
Requires-Dist: jax-rocm7-pjrt; extra == "rocm7"
|
|
21
|
+
Provides-Extra: tpu
|
|
22
|
+
Requires-Dist: libtpu; extra == "tpu"
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# cyxla
|
|
26
|
+
|
|
27
|
+
cyxla lowers JAX functions to StableHLO, compiles them with a PJRT plugin, and runs them
|
|
28
|
+
from Cython extension modules without the GIL. It suits native libraries that call JAX
|
|
29
|
+
functions thousands of times per second, such as the SCIP callbacks of
|
|
30
|
+
[JAX-CIP](https://github.com/nardi/jax-cip). The
|
|
31
|
+
[documentation](https://nardi.github.io/cyxla/) has guides and the API reference.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
The package and a plugin install from wheels, and nothing downloads at run time.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install cyxla[cpu]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Each extra installs the plugin of one platform:
|
|
42
|
+
|
|
43
|
+
| Extra | Platform | Plugin |
|
|
44
|
+
| --- | --- | --- |
|
|
45
|
+
| `cpu` | Linux on x86-64 and arm64, macOS on arm64, Windows on x86-64 | [cyxla-pjrt-cpu](../cyxla-pjrt-cpu) |
|
|
46
|
+
| `cuda12`, `cuda13` | NVIDIA GPUs on Linux | JAX's `jax-cuda12-pjrt` or `jax-cuda13-pjrt`, with the CUDA libraries |
|
|
47
|
+
| `rocm7` | AMD GPUs on Linux | JAX's `jax-rocm7-pjrt`, with ROCm from the system |
|
|
48
|
+
| `tpu` | Cloud TPUs | `libtpu` |
|
|
49
|
+
|
|
50
|
+
jaxlib links its own CPU client statically and ships no plugin library, which is why the
|
|
51
|
+
CPU plugin is a separate package.
|
|
52
|
+
|
|
53
|
+
## Example
|
|
54
|
+
|
|
55
|
+
<!-- name: test_readme -->
|
|
56
|
+
```python
|
|
57
|
+
import jax
|
|
58
|
+
import jax.numpy as jnp
|
|
59
|
+
import numpy as np
|
|
60
|
+
|
|
61
|
+
import cyxla as cx
|
|
62
|
+
|
|
63
|
+
program = cx.lower(lambda x: jnp.sin(x) * 2, [jax.ShapeDtypeStruct((3,), jnp.float32)])
|
|
64
|
+
executable, statistics = cx.compile_program(program)
|
|
65
|
+
(result,) = executable.run([np.array([0.0, 1.0, 2.0])])
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The linear algebra of `jnp.linalg` works the same way, as the section on custom calls
|
|
69
|
+
explains:
|
|
70
|
+
|
|
71
|
+
<!-- name: test_readme -->
|
|
72
|
+
```python
|
|
73
|
+
matrix = np.array([[4.0, 1.0], [1.0, 3.0]])
|
|
74
|
+
program = cx.lower(jnp.linalg.cholesky, [jax.ShapeDtypeStruct((2, 2), jnp.float32)])
|
|
75
|
+
executable, _ = cx.compile_program(program)
|
|
76
|
+
(factor,) = executable.run([matrix])
|
|
77
|
+
assert np.allclose(factor, np.linalg.cholesky(matrix))
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The first function that needs a plugin loads the default one, so a program needs no
|
|
81
|
+
setup call. JAX lowers to 32-bit types unless `jax.enable_x64` is on, as it does without
|
|
82
|
+
cyxla. Arguments and results can be `bool`, 8 to 64-bit integers, `float16`, `bfloat16`,
|
|
83
|
+
`float32`, `float64`, `complex64` and `complex128`.
|
|
84
|
+
|
|
85
|
+
`Executable.run` returns arrays with the shapes and dtypes of the outputs, and converts
|
|
86
|
+
arguments to the types that the program takes. It is for tests and interactive checks.
|
|
87
|
+
Extension modules call `execute` from `cyxla/_runtime.pxd` instead, as the next section
|
|
88
|
+
shows.
|
|
89
|
+
|
|
90
|
+
## Extension modules
|
|
91
|
+
|
|
92
|
+
An extension module cimports the runtime and runs programs with `execute`, which takes
|
|
93
|
+
no GIL. On the CPU, inputs alias host arrays that the module fills in place, and outputs
|
|
94
|
+
are read from the buffers' memory, so an execution copies nothing beyond the arrays that
|
|
95
|
+
the caller passes. On other platforms every execution copies its inputs to the device
|
|
96
|
+
and its outputs back.
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
import cython
|
|
100
|
+
from cython.cimports.cyxla._runtime import ABI_VERSION, Input, ProgramSpec, execute
|
|
101
|
+
|
|
102
|
+
import cyxla
|
|
103
|
+
|
|
104
|
+
cyxla.check_abi(ABI_VERSION)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`check_abi` rejects a module that was compiled against declarations of another cyxla
|
|
108
|
+
version. Cython checks the signatures of shared functions itself, but not the layout of
|
|
109
|
+
structs such as `ProgramSpec`.
|
|
110
|
+
|
|
111
|
+
Host arrays for inputs come from `aligned_memory`, which takes a size in bytes, and go
|
|
112
|
+
back with `free_aligned`. The pair exists because Windows frees aligned memory with a
|
|
113
|
+
function other than `free`. Each `Input` names the PJRT element type of its array, such
|
|
114
|
+
as `PJRT_Buffer_Type_F32` from `cyxla._pjrt`, and `ProgramSpec.output_bytes` holds the
|
|
115
|
+
size of each output, which `Executable.output_bytes` returns.
|
|
116
|
+
|
|
117
|
+
The build needs the PJRT header and the `.pxd` files, and `cyxla.get_include()` returns
|
|
118
|
+
their directories. A Meson build reads them like this, and `tests/downstream` is a
|
|
119
|
+
complete example.
|
|
120
|
+
|
|
121
|
+
```meson
|
|
122
|
+
cyxla_include = run_command(
|
|
123
|
+
python, '-c', 'import cyxla; print("\\n".join(cyxla.get_include()))', check: true,
|
|
124
|
+
).stdout().strip().split('\n')
|
|
125
|
+
# Pass cyxla_include[1] to Cython with -I, and cyxla_include[0] to the C compiler.
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Downstream packages list `cyxla` in `build-system.requires` and pin it to a narrow
|
|
129
|
+
range, because a new version may change the declarations.
|
|
130
|
+
|
|
131
|
+
## Plugins
|
|
132
|
+
|
|
133
|
+
A process loads one plugin. `cx.lower` picks a platform like JAX does, from the device
|
|
134
|
+
that the arguments are committed to, then `jax.default_device`, then the loaded plugin,
|
|
135
|
+
then `jax_platforms`, and last the CPU plugin if one is installed, then CUDA, ROCm and
|
|
136
|
+
TPU in that order. The program records the platform, and compiling it loads the plugin
|
|
137
|
+
for that platform. `cx.initialize` chooses a plugin or its options instead, and has to
|
|
138
|
+
come before that first use. `cx.initialize(platform="cuda")` asks for a platform, and
|
|
139
|
+
`cx.initialize(Path("libpjrt.so"), platform="cpu")` loads a library by path. `python -m
|
|
140
|
+
cyxla` lists what it finds.
|
|
141
|
+
|
|
142
|
+
Each plugin comes with the options that `PJRT_Client_Create` receives, and `options`
|
|
143
|
+
adds to or replaces them:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
cx.initialize(platform="cuda", options={"memory_fraction": 0.5})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The CPU client runs synchronously on one device, so executions stay in the calling
|
|
150
|
+
thread. The GPU clients do not preallocate most of the device memory, as JAX does by
|
|
151
|
+
default. Before it loads JAX's CUDA plugin, cyxla loads the CUDA libraries of the
|
|
152
|
+
`nvidia` wheels, the same way JAX does.
|
|
153
|
+
|
|
154
|
+
Other packages can provide a plugin with an entry point in the `cyxla.plugins` group.
|
|
155
|
+
The entry point names a module with `PLATFORM`, `CREATE_OPTIONS` and `library_path()`,
|
|
156
|
+
as `cyxla_pjrt_cpu` has.
|
|
157
|
+
|
|
158
|
+
## Custom calls
|
|
159
|
+
|
|
160
|
+
Some JAX functions lower to custom calls, which are native functions that the program
|
|
161
|
+
runs. On the CPU, `jnp.linalg` and `jax.scipy.linalg` call the LAPACK kernels that
|
|
162
|
+
jaxlib ships. A PJRT plugin is a separate build of XLA that does not know them, so
|
|
163
|
+
loading the plugin registers jaxlib's typed FFI handlers with it by name. Programs with
|
|
164
|
+
`cholesky`, `solve`, `svd`, `eigh`, `qr`, `lu`, `eigvals` and the other linear algebra
|
|
165
|
+
functions then compile and run like they do in JAX.
|
|
166
|
+
|
|
167
|
+
A library with its own primitives registers a typed FFI handler with
|
|
168
|
+
`jax.ffi.register_ffi_target`, and cyxla passes it on to the plugin. Importing cyxla
|
|
169
|
+
mirrors every later registration, and loading the plugin registers the ones that JAX
|
|
170
|
+
already holds, so the order of the imports does not matter. A library that does not use
|
|
171
|
+
JAX calls `cx.register_ffi_target` with the same arguments. `jax.export` refuses custom
|
|
172
|
+
calls it has no compatibility promise for, so `cx.lower` takes the names of the targets
|
|
173
|
+
that the function may call.
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
import my_library
|
|
177
|
+
|
|
178
|
+
program = cx.lower(my_library.function, shapes, custom_calls=["my_target"])
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The plugin accepts typed FFI handlers with an `execute` stage. It does not run the older
|
|
182
|
+
untyped custom calls (`api_version=0`) or the Python callbacks of `jax.pure_callback`
|
|
183
|
+
and `jax.experimental.io_callback`, and compiling a program with one raises an error
|
|
184
|
+
that names the target.
|
|
185
|
+
|
|
186
|
+
## Disk cache
|
|
187
|
+
|
|
188
|
+
`compile_program` stores executables in the cache directory under a hash of their
|
|
189
|
+
StableHLO, the compile options and the plugin. A later run of the same program loads the
|
|
190
|
+
executable instead of compiling it. `store_lowered` and `load_lowered` keep lowered
|
|
191
|
+
programs under a key from `cache_key`, which includes the versions of JAX, cyxla and any
|
|
192
|
+
distributions that the caller names.
|
|
193
|
+
|
|
194
|
+
## Environment variables
|
|
195
|
+
|
|
196
|
+
| Variable | Meaning |
|
|
197
|
+
| --- | --- |
|
|
198
|
+
| `CYXLA_PJRT_PLUGIN` | Path of a plugin that replaces the installed ones |
|
|
199
|
+
| `CYXLA_PLATFORM` | Platform to load when `initialize` gets none |
|
|
200
|
+
| `CYXLA_CACHE_DIR` | Directory of the disk cache, `~/.cache/cyxla` if unset |
|
|
201
|
+
| `CYXLA_MIRROR_JAX` | Set to `0` to keep cyxla from mirroring the FFI registrations of JAX |
|
|
202
|
+
|
|
203
|
+
## Limitations
|
|
204
|
+
|
|
205
|
+
- Buffers hold the dtypes listed above and no others, such as the 8-bit floats, 4-bit
|
|
206
|
+
integers and PRNG keys. `cx.lower` refuses a function that uses them. TPUs do not
|
|
207
|
+
support `float64`, so programs for them fail to compile.
|
|
208
|
+
- Custom calls need a typed FFI handler. Untyped custom calls and Python callbacks do
|
|
209
|
+
not work.
|
|
210
|
+
- The GPU and TPU paths are tested up to client creation. CI has no GPU, so execution on
|
|
211
|
+
one is untested.
|
|
212
|
+
- On Windows only the CPU plugin exists, since JAX publishes no native GPU plugins
|
|
213
|
+
there.
|
|
214
|
+
|
|
215
|
+
## Development
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
uv sync
|
|
219
|
+
uv run pytest
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
`uv sync` builds the CPU plugin package from `../cyxla-pjrt-cpu`, which downloads its
|
|
223
|
+
archive once. Development builds trace lines in the Cython module, so its coverage is
|
|
224
|
+
measured too. The tests need 100% coverage.
|
|
225
|
+
|
|
226
|
+
CI has no GPU, so [`notebooks/colab_gpu_tests.ipynb`](notebooks/colab_gpu_tests.ipynb)
|
|
227
|
+
runs the CUDA plugin on a Colab GPU.
|
|
228
|
+
|
|
229
|
+
[](https://colab.research.google.com/github/nardi/cyxla/blob/main/cyxla/notebooks/colab_gpu_tests.ipynb)
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
[Hippocratic License 3.0](LICENSE.md). The vendored PJRT header is under XLA's Apache
|
|
235
|
+
2.0 license.
|
cyxla-0.1.0/README.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# cyxla
|
|
2
|
+
|
|
3
|
+
cyxla lowers JAX functions to StableHLO, compiles them with a PJRT plugin, and runs them
|
|
4
|
+
from Cython extension modules without the GIL. It suits native libraries that call JAX
|
|
5
|
+
functions thousands of times per second, such as the SCIP callbacks of
|
|
6
|
+
[JAX-CIP](https://github.com/nardi/jax-cip). The
|
|
7
|
+
[documentation](https://nardi.github.io/cyxla/) has guides and the API reference.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
The package and a plugin install from wheels, and nothing downloads at run time.
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install cyxla[cpu]
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Each extra installs the plugin of one platform:
|
|
18
|
+
|
|
19
|
+
| Extra | Platform | Plugin |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `cpu` | Linux on x86-64 and arm64, macOS on arm64, Windows on x86-64 | [cyxla-pjrt-cpu](../cyxla-pjrt-cpu) |
|
|
22
|
+
| `cuda12`, `cuda13` | NVIDIA GPUs on Linux | JAX's `jax-cuda12-pjrt` or `jax-cuda13-pjrt`, with the CUDA libraries |
|
|
23
|
+
| `rocm7` | AMD GPUs on Linux | JAX's `jax-rocm7-pjrt`, with ROCm from the system |
|
|
24
|
+
| `tpu` | Cloud TPUs | `libtpu` |
|
|
25
|
+
|
|
26
|
+
jaxlib links its own CPU client statically and ships no plugin library, which is why the
|
|
27
|
+
CPU plugin is a separate package.
|
|
28
|
+
|
|
29
|
+
## Example
|
|
30
|
+
|
|
31
|
+
<!-- name: test_readme -->
|
|
32
|
+
```python
|
|
33
|
+
import jax
|
|
34
|
+
import jax.numpy as jnp
|
|
35
|
+
import numpy as np
|
|
36
|
+
|
|
37
|
+
import cyxla as cx
|
|
38
|
+
|
|
39
|
+
program = cx.lower(lambda x: jnp.sin(x) * 2, [jax.ShapeDtypeStruct((3,), jnp.float32)])
|
|
40
|
+
executable, statistics = cx.compile_program(program)
|
|
41
|
+
(result,) = executable.run([np.array([0.0, 1.0, 2.0])])
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The linear algebra of `jnp.linalg` works the same way, as the section on custom calls
|
|
45
|
+
explains:
|
|
46
|
+
|
|
47
|
+
<!-- name: test_readme -->
|
|
48
|
+
```python
|
|
49
|
+
matrix = np.array([[4.0, 1.0], [1.0, 3.0]])
|
|
50
|
+
program = cx.lower(jnp.linalg.cholesky, [jax.ShapeDtypeStruct((2, 2), jnp.float32)])
|
|
51
|
+
executable, _ = cx.compile_program(program)
|
|
52
|
+
(factor,) = executable.run([matrix])
|
|
53
|
+
assert np.allclose(factor, np.linalg.cholesky(matrix))
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The first function that needs a plugin loads the default one, so a program needs no
|
|
57
|
+
setup call. JAX lowers to 32-bit types unless `jax.enable_x64` is on, as it does without
|
|
58
|
+
cyxla. Arguments and results can be `bool`, 8 to 64-bit integers, `float16`, `bfloat16`,
|
|
59
|
+
`float32`, `float64`, `complex64` and `complex128`.
|
|
60
|
+
|
|
61
|
+
`Executable.run` returns arrays with the shapes and dtypes of the outputs, and converts
|
|
62
|
+
arguments to the types that the program takes. It is for tests and interactive checks.
|
|
63
|
+
Extension modules call `execute` from `cyxla/_runtime.pxd` instead, as the next section
|
|
64
|
+
shows.
|
|
65
|
+
|
|
66
|
+
## Extension modules
|
|
67
|
+
|
|
68
|
+
An extension module cimports the runtime and runs programs with `execute`, which takes
|
|
69
|
+
no GIL. On the CPU, inputs alias host arrays that the module fills in place, and outputs
|
|
70
|
+
are read from the buffers' memory, so an execution copies nothing beyond the arrays that
|
|
71
|
+
the caller passes. On other platforms every execution copies its inputs to the device
|
|
72
|
+
and its outputs back.
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
import cython
|
|
76
|
+
from cython.cimports.cyxla._runtime import ABI_VERSION, Input, ProgramSpec, execute
|
|
77
|
+
|
|
78
|
+
import cyxla
|
|
79
|
+
|
|
80
|
+
cyxla.check_abi(ABI_VERSION)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`check_abi` rejects a module that was compiled against declarations of another cyxla
|
|
84
|
+
version. Cython checks the signatures of shared functions itself, but not the layout of
|
|
85
|
+
structs such as `ProgramSpec`.
|
|
86
|
+
|
|
87
|
+
Host arrays for inputs come from `aligned_memory`, which takes a size in bytes, and go
|
|
88
|
+
back with `free_aligned`. The pair exists because Windows frees aligned memory with a
|
|
89
|
+
function other than `free`. Each `Input` names the PJRT element type of its array, such
|
|
90
|
+
as `PJRT_Buffer_Type_F32` from `cyxla._pjrt`, and `ProgramSpec.output_bytes` holds the
|
|
91
|
+
size of each output, which `Executable.output_bytes` returns.
|
|
92
|
+
|
|
93
|
+
The build needs the PJRT header and the `.pxd` files, and `cyxla.get_include()` returns
|
|
94
|
+
their directories. A Meson build reads them like this, and `tests/downstream` is a
|
|
95
|
+
complete example.
|
|
96
|
+
|
|
97
|
+
```meson
|
|
98
|
+
cyxla_include = run_command(
|
|
99
|
+
python, '-c', 'import cyxla; print("\\n".join(cyxla.get_include()))', check: true,
|
|
100
|
+
).stdout().strip().split('\n')
|
|
101
|
+
# Pass cyxla_include[1] to Cython with -I, and cyxla_include[0] to the C compiler.
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Downstream packages list `cyxla` in `build-system.requires` and pin it to a narrow
|
|
105
|
+
range, because a new version may change the declarations.
|
|
106
|
+
|
|
107
|
+
## Plugins
|
|
108
|
+
|
|
109
|
+
A process loads one plugin. `cx.lower` picks a platform like JAX does, from the device
|
|
110
|
+
that the arguments are committed to, then `jax.default_device`, then the loaded plugin,
|
|
111
|
+
then `jax_platforms`, and last the CPU plugin if one is installed, then CUDA, ROCm and
|
|
112
|
+
TPU in that order. The program records the platform, and compiling it loads the plugin
|
|
113
|
+
for that platform. `cx.initialize` chooses a plugin or its options instead, and has to
|
|
114
|
+
come before that first use. `cx.initialize(platform="cuda")` asks for a platform, and
|
|
115
|
+
`cx.initialize(Path("libpjrt.so"), platform="cpu")` loads a library by path. `python -m
|
|
116
|
+
cyxla` lists what it finds.
|
|
117
|
+
|
|
118
|
+
Each plugin comes with the options that `PJRT_Client_Create` receives, and `options`
|
|
119
|
+
adds to or replaces them:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
cx.initialize(platform="cuda", options={"memory_fraction": 0.5})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The CPU client runs synchronously on one device, so executions stay in the calling
|
|
126
|
+
thread. The GPU clients do not preallocate most of the device memory, as JAX does by
|
|
127
|
+
default. Before it loads JAX's CUDA plugin, cyxla loads the CUDA libraries of the
|
|
128
|
+
`nvidia` wheels, the same way JAX does.
|
|
129
|
+
|
|
130
|
+
Other packages can provide a plugin with an entry point in the `cyxla.plugins` group.
|
|
131
|
+
The entry point names a module with `PLATFORM`, `CREATE_OPTIONS` and `library_path()`,
|
|
132
|
+
as `cyxla_pjrt_cpu` has.
|
|
133
|
+
|
|
134
|
+
## Custom calls
|
|
135
|
+
|
|
136
|
+
Some JAX functions lower to custom calls, which are native functions that the program
|
|
137
|
+
runs. On the CPU, `jnp.linalg` and `jax.scipy.linalg` call the LAPACK kernels that
|
|
138
|
+
jaxlib ships. A PJRT plugin is a separate build of XLA that does not know them, so
|
|
139
|
+
loading the plugin registers jaxlib's typed FFI handlers with it by name. Programs with
|
|
140
|
+
`cholesky`, `solve`, `svd`, `eigh`, `qr`, `lu`, `eigvals` and the other linear algebra
|
|
141
|
+
functions then compile and run like they do in JAX.
|
|
142
|
+
|
|
143
|
+
A library with its own primitives registers a typed FFI handler with
|
|
144
|
+
`jax.ffi.register_ffi_target`, and cyxla passes it on to the plugin. Importing cyxla
|
|
145
|
+
mirrors every later registration, and loading the plugin registers the ones that JAX
|
|
146
|
+
already holds, so the order of the imports does not matter. A library that does not use
|
|
147
|
+
JAX calls `cx.register_ffi_target` with the same arguments. `jax.export` refuses custom
|
|
148
|
+
calls it has no compatibility promise for, so `cx.lower` takes the names of the targets
|
|
149
|
+
that the function may call.
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
import my_library
|
|
153
|
+
|
|
154
|
+
program = cx.lower(my_library.function, shapes, custom_calls=["my_target"])
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The plugin accepts typed FFI handlers with an `execute` stage. It does not run the older
|
|
158
|
+
untyped custom calls (`api_version=0`) or the Python callbacks of `jax.pure_callback`
|
|
159
|
+
and `jax.experimental.io_callback`, and compiling a program with one raises an error
|
|
160
|
+
that names the target.
|
|
161
|
+
|
|
162
|
+
## Disk cache
|
|
163
|
+
|
|
164
|
+
`compile_program` stores executables in the cache directory under a hash of their
|
|
165
|
+
StableHLO, the compile options and the plugin. A later run of the same program loads the
|
|
166
|
+
executable instead of compiling it. `store_lowered` and `load_lowered` keep lowered
|
|
167
|
+
programs under a key from `cache_key`, which includes the versions of JAX, cyxla and any
|
|
168
|
+
distributions that the caller names.
|
|
169
|
+
|
|
170
|
+
## Environment variables
|
|
171
|
+
|
|
172
|
+
| Variable | Meaning |
|
|
173
|
+
| --- | --- |
|
|
174
|
+
| `CYXLA_PJRT_PLUGIN` | Path of a plugin that replaces the installed ones |
|
|
175
|
+
| `CYXLA_PLATFORM` | Platform to load when `initialize` gets none |
|
|
176
|
+
| `CYXLA_CACHE_DIR` | Directory of the disk cache, `~/.cache/cyxla` if unset |
|
|
177
|
+
| `CYXLA_MIRROR_JAX` | Set to `0` to keep cyxla from mirroring the FFI registrations of JAX |
|
|
178
|
+
|
|
179
|
+
## Limitations
|
|
180
|
+
|
|
181
|
+
- Buffers hold the dtypes listed above and no others, such as the 8-bit floats, 4-bit
|
|
182
|
+
integers and PRNG keys. `cx.lower` refuses a function that uses them. TPUs do not
|
|
183
|
+
support `float64`, so programs for them fail to compile.
|
|
184
|
+
- Custom calls need a typed FFI handler. Untyped custom calls and Python callbacks do
|
|
185
|
+
not work.
|
|
186
|
+
- The GPU and TPU paths are tested up to client creation. CI has no GPU, so execution on
|
|
187
|
+
one is untested.
|
|
188
|
+
- On Windows only the CPU plugin exists, since JAX publishes no native GPU plugins
|
|
189
|
+
there.
|
|
190
|
+
|
|
191
|
+
## Development
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
uv sync
|
|
195
|
+
uv run pytest
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`uv sync` builds the CPU plugin package from `../cyxla-pjrt-cpu`, which downloads its
|
|
199
|
+
archive once. Development builds trace lines in the Cython module, so its coverage is
|
|
200
|
+
measured too. The tests need 100% coverage.
|
|
201
|
+
|
|
202
|
+
CI has no GPU, so [`notebooks/colab_gpu_tests.ipynb`](notebooks/colab_gpu_tests.ipynb)
|
|
203
|
+
runs the CUDA plugin on a Colab GPU.
|
|
204
|
+
|
|
205
|
+
[](https://colab.research.google.com/github/nardi/cyxla/blob/main/cyxla/notebooks/colab_gpu_tests.ipynb)
|
|
207
|
+
|
|
208
|
+
## License
|
|
209
|
+
|
|
210
|
+
[Hippocratic License 3.0](LICENSE.md). The vendored PJRT header is under XLA's Apache
|
|
211
|
+
2.0 license.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Custom calls
|
|
2
|
+
|
|
3
|
+
Registering the native functions that programs call. The [custom calls
|
|
4
|
+
guide](../guide/custom-calls.md) explains when each is needed.
|
|
5
|
+
|
|
6
|
+
::: cyxla.register_ffi_target
|
|
7
|
+
|
|
8
|
+
::: cyxla.register_jax_targets
|
|
9
|
+
|
|
10
|
+
::: cyxla.mirror_jax_registrations
|
|
11
|
+
|
|
12
|
+
::: cyxla.MIRROR_ENVIRONMENT_VARIABLE
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Extension modules
|
|
2
|
+
|
|
3
|
+
What a module that cimports the runtime needs at build and import time. The functions
|
|
4
|
+
that the module calls, such as `execute`, are declared in `cyxla/_runtime.pxd` and are
|
|
5
|
+
described in the [extension modules guide](../guide/extensions.md).
|
|
6
|
+
|
|
7
|
+
::: cyxla.get_include
|
|
8
|
+
|
|
9
|
+
::: cyxla.check_abi
|
|
10
|
+
|
|
11
|
+
::: cyxla.ABI_VERSION
|
|
12
|
+
|
|
13
|
+
::: cyxla.abi_version
|