@plasius/gpu-lock-free-queue 0.1.1-beta.1
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.
- package/CHANGELOG.md +57 -0
- package/LICENSE +203 -0
- package/README.md +45 -0
- package/legal/CLA-REGISTRY.csv +2 -0
- package/legal/CLA.md +22 -0
- package/legal/CORPORATE_CLA.md +57 -0
- package/legal/INDIVIDUAL_CLA.md +91 -0
- package/package.json +58 -0
- package/src/index.js +6 -0
- package/src/queue.wgsl +104 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/)**, and this project adheres to **[Semantic Versioning](https://semver.org/spec/v2.0.0.html)**.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
- **Added**
|
|
12
|
+
- (placeholder)
|
|
13
|
+
|
|
14
|
+
- **Changed**
|
|
15
|
+
- (placeholder)
|
|
16
|
+
|
|
17
|
+
- **Fixed**
|
|
18
|
+
- (placeholder)
|
|
19
|
+
|
|
20
|
+
- **Security**
|
|
21
|
+
- (placeholder)
|
|
22
|
+
|
|
23
|
+
## [0.1.1-beta.1] - 2026-01-08
|
|
24
|
+
|
|
25
|
+
- **Added**
|
|
26
|
+
- (placeholder)
|
|
27
|
+
|
|
28
|
+
- **Changed**
|
|
29
|
+
- (placeholder)
|
|
30
|
+
|
|
31
|
+
- **Fixed**
|
|
32
|
+
- (placeholder)
|
|
33
|
+
|
|
34
|
+
- **Security**
|
|
35
|
+
- (placeholder)
|
|
36
|
+
|
|
37
|
+
## [0.1.1-beta.0] - 2026-01-08
|
|
38
|
+
|
|
39
|
+
- **Added**
|
|
40
|
+
- (placeholder)
|
|
41
|
+
|
|
42
|
+
- **Changed**
|
|
43
|
+
- (placeholder)
|
|
44
|
+
|
|
45
|
+
- **Fixed**
|
|
46
|
+
- (placeholder)
|
|
47
|
+
|
|
48
|
+
- **Security**
|
|
49
|
+
- (placeholder)
|
|
50
|
+
|
|
51
|
+
## [0.1.0] - 2025-01-08
|
|
52
|
+
|
|
53
|
+
- **Added**
|
|
54
|
+
- WebGPU lock-free MPMC queue with sequence counters.
|
|
55
|
+
- Demo for enqueue/dequeue, FFT spectrogram, and randomness heuristics.
|
|
56
|
+
[0.1.1-beta.0]: https://github.com/Plasius-LTD/gpu-lock-free-queue/releases/tag/v0.1.1-beta.0
|
|
57
|
+
[0.1.1-beta.1]: https://github.com/Plasius-LTD/gpu-lock-free-queue/releases/tag/v0.1.1-beta.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright 2025 Plasius LTD
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright [yyyy] [name of copyright owner]
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @plasius/gpu-lock-free-queue
|
|
2
|
+
|
|
3
|
+
A minimal WebGPU lock-free MPMC ring queue using a per-slot sequence counter (Vyukov-style). This is a starter implementation focused on correctness, robustness, and low overhead.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
```
|
|
7
|
+
npm install @plasius/gpu-lock-free-queue
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
```js
|
|
12
|
+
import { loadQueueWgsl, queueWgslUrl } from "@plasius/gpu-lock-free-queue";
|
|
13
|
+
|
|
14
|
+
const shaderCode = await loadQueueWgsl();
|
|
15
|
+
// Or, fetch the WGSL file directly:
|
|
16
|
+
// const shaderCode = await fetch(queueWgslUrl).then((res) => res.text());
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What this is
|
|
20
|
+
- Lock-free multi-producer, multi-consumer ring queue on the GPU.
|
|
21
|
+
- Uses per-slot sequence numbers to avoid ABA for slots within a 32-bit epoch.
|
|
22
|
+
- Fixed-size jobs (u32) for now; a "job" can be expanded to a fixed-size struct or an index into a separate payload buffer.
|
|
23
|
+
|
|
24
|
+
## Limitations
|
|
25
|
+
- Sequence counters are 32-bit. At extreme throughput over a long time, counters wrap and ABA can reappear. If you need true long-running safety, consider a reset protocol, sharding, or a future 64-bit atomic extension.
|
|
26
|
+
- Jobs are fixed-size and must be power-of-two capacity.
|
|
27
|
+
- This demo is intentionally minimal; it is not yet integrated with a scheduler or backpressure policy.
|
|
28
|
+
|
|
29
|
+
## Run the demo
|
|
30
|
+
WebGPU requires a secure context. Use a local server, for example:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
python3 -m http.server
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then open `http://localhost:8000` and check the console/output.
|
|
37
|
+
|
|
38
|
+
## Files
|
|
39
|
+
- `demo/index.html`: Loads the demo.
|
|
40
|
+
- `demo/main.js`: WebGPU setup, enqueue/dequeue test, FFT spectrogram, and randomness heuristics.
|
|
41
|
+
- `src/queue.wgsl`: Lock-free queue implementation.
|
|
42
|
+
- `src/index.js`: Package entry point for loading the WGSL file.
|
|
43
|
+
|
|
44
|
+
## Job shape
|
|
45
|
+
Current jobs are `u32` values. If you need richer jobs, use a fixed-size struct (e.g., 16 bytes) or store indices into a separate payload buffer. Variable-length jobs should be modeled as an index + length into a payload arena to keep the queue fixed-size.
|
package/legal/CLA.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Contributor License Agreements (CLA)
|
|
2
|
+
|
|
3
|
+
To protect the intellectual property of this project and ensure clarity of rights, all contributors must sign a Contributor License Agreement (CLA) before their first contribution.
|
|
4
|
+
|
|
5
|
+
## Which CLA should I sign?
|
|
6
|
+
|
|
7
|
+
- **Individual CLA**: If you are contributing personally and not on behalf of an employer, sign the [Individual CLA](INDIVIDUAL_CLA.md).
|
|
8
|
+
- **Corporate CLA**: If you are contributing as part of your work for a company, the company should sign the [Corporate CLA](CORPORATE_CLA.md).
|
|
9
|
+
|
|
10
|
+
## How to sign
|
|
11
|
+
|
|
12
|
+
1. Download the appropriate CLA file (Individual or Corporate).
|
|
13
|
+
2. Fill in the required details, sign, and date it.
|
|
14
|
+
3. Email a PDF copy of the signed document to **[contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)** with subject: `CLA – Individual` or `CLA – Corporate`.
|
|
15
|
+
|
|
16
|
+
## Registry
|
|
17
|
+
|
|
18
|
+
All signed CLAs are logged internally in the CLA registry (`CLA-REGISTRY.csv`).
|
|
19
|
+
|
|
20
|
+
## Questions?
|
|
21
|
+
|
|
22
|
+
If you have any questions about which CLA to sign or how the process works, please email **[contributors@plasius.co.uk](mailtocontributors@plasius.co.uk)**.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Corporate Contributor License Agreement (CLA)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
This Corporate Contributor License Agreement ("Agreement") is intended to protect the intellectual property rights of the contributors and the project, ensure clear licensing terms for contributions, and maintain trust within the community. By signing this Agreement, the corporation agrees to the terms that facilitate the use, distribution, and modification of contributions under the project's licensing framework.
|
|
6
|
+
|
|
7
|
+
## Agreement
|
|
8
|
+
|
|
9
|
+
1. **Representation of Authority**
|
|
10
|
+
The undersigned individual represents and warrants that they have the full legal authority to enter into this Agreement on behalf of the corporation named below ("Corporation") and to grant the rights contained herein.
|
|
11
|
+
|
|
12
|
+
2. **Grant of Copyright License**
|
|
13
|
+
The Corporation hereby grants to the project maintainers and users a perpetual, worldwide, non-exclusive, royalty-free, irrevocable copyright license to use, reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the contributions submitted to the project.
|
|
14
|
+
|
|
15
|
+
3. **Grant of Patent License**
|
|
16
|
+
The Corporation hereby grants to the project maintainers and users a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under any patent claims that are necessarily infringed by the contributions to make, use, sell, offer for sale, import, and otherwise dispose of the contributions or derivative works thereof.
|
|
17
|
+
|
|
18
|
+
4. **Warranties and Representations**
|
|
19
|
+
The Corporation represents and warrants that:
|
|
20
|
+
|
|
21
|
+
- The contributions are the original work of the Corporation or that the Corporation has sufficient rights to grant the licenses herein.
|
|
22
|
+
- The submission of the contributions does not violate any agreements or rights of third parties.
|
|
23
|
+
|
|
24
|
+
5. **No Revocation**
|
|
25
|
+
This license is granted on a perpetual basis and cannot be revoked, provided that the terms of this Agreement are met.
|
|
26
|
+
|
|
27
|
+
6. **Governing Law**
|
|
28
|
+
This Agreement shall be governed by and construed in accordance with the laws of the United Kingdom, without regard to its conflict of laws principles.
|
|
29
|
+
|
|
30
|
+
7. **Execution**
|
|
31
|
+
|
|
32
|
+
This Agreement is effective upon signature by the authorized representative of the Corporation. Please sign and date this document, then email a scanned PDF copy to [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk).
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### **@plasius/gpu-lock-free-queue**
|
|
37
|
+
|
|
38
|
+
**Corporation Legal Name:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
39
|
+
|
|
40
|
+
**Authorized Representative:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
41
|
+
|
|
42
|
+
**Title:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
43
|
+
|
|
44
|
+
**Email:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
45
|
+
|
|
46
|
+
**Date:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
47
|
+
|
|
48
|
+
**Signature:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## How to Sign
|
|
53
|
+
|
|
54
|
+
- Download this file as a template.
|
|
55
|
+
- Fill in the Corporation’s legal name, authorized representative, title, email, date, and provide a signature.
|
|
56
|
+
- Sign and date the document.
|
|
57
|
+
- Send a scanned copy of the signed Agreement to [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk).
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Individual Contributor License Agreement (CLA)
|
|
2
|
+
|
|
3
|
+
**Project:** @plasius/gpu-lock-free-queue (Plasius LTD)
|
|
4
|
+
**Version:** 1.0 — 2025‑09‑12
|
|
5
|
+
**Contact:** [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Definitions
|
|
10
|
+
|
|
11
|
+
- **"You"** (or **"Contributor"**) means the individual signing this CLA and submitting Contributions to the Project.
|
|
12
|
+
- **"Contribution"** means any original work of authorship, including code, documentation, data, designs, or feedback that You submit to the Project in any form (e.g., pull request, issue comment, email, file upload).
|
|
13
|
+
- **"Project"** means the @plasius/gpu-lock-free-queue repositories and related materials owned or managed by **Plasius LTD**.
|
|
14
|
+
|
|
15
|
+
## 2. Copyright License Grant
|
|
16
|
+
|
|
17
|
+
You hereby grant to Plasius LTD a **perpetual, worldwide, non‑exclusive, transferable, sublicensable, royalty‑free, irrevocable** copyright license to:
|
|
18
|
+
|
|
19
|
+
- use, reproduce, publicly display, publicly perform, modify, create derivative works of, and
|
|
20
|
+
- distribute Contributions in source and object form,
|
|
21
|
+
- and to **sublicense** these rights under any terms Plasius LTD chooses, including proprietary or open‑source licenses.
|
|
22
|
+
|
|
23
|
+
## 3. Patent License Grant
|
|
24
|
+
|
|
25
|
+
You hereby grant to Plasius LTD and its sublicensees a **perpetual, worldwide, non‑exclusive, transferable, royalty‑free, irrevocable** patent license to **make, have made, use, offer to sell, sell, import, and otherwise transfer** the Contribution and derivative works thereof, where such license applies only to patent claims that You **own or control** and that would be infringed by Your Contribution or its combination with the Project.
|
|
26
|
+
|
|
27
|
+
## 4. Moral Rights & Attribution
|
|
28
|
+
|
|
29
|
+
To the maximum extent permitted by applicable law, You **waive** and agree not to assert any moral rights (e.g., rights of attribution or integrity) in or to the Contribution against Plasius LTD. Plasius LTD may, but is not required to, credit You.
|
|
30
|
+
|
|
31
|
+
## 5. Representations & Warranties
|
|
32
|
+
|
|
33
|
+
You represent that:
|
|
34
|
+
|
|
35
|
+
1. **Originality / Rights:** Each Contribution is Your original creation, or You have sufficient rights to submit it and grant the licenses above.
|
|
36
|
+
2. **No Confidential Info:** Contributions **do not** include confidential information or trade secrets of any third party.
|
|
37
|
+
3. **No Infringement:** To the best of Your knowledge, Contributions do not infringe any third‑party IP rights.
|
|
38
|
+
4. **Employment / Contractor Status:** If Your employer or a third party might claim rights in Your Contribution, You have obtained **written permission** to make the Contribution and grant these licenses (attach or reference below), or Your Contribution is made **outside the scope** of your employment and without using your employer’s confidential information or resources.
|
|
39
|
+
5. **Compliance:** You will follow the Project’s policies (e.g., Code of Conduct, Security Policy) and applicable laws.
|
|
40
|
+
|
|
41
|
+
## 6. Third‑Party Code
|
|
42
|
+
|
|
43
|
+
If Your Contribution includes code, data, or other material from a third party, You will **identify the material and its license** in the pull request or submission, and ensure it is **compatible** with the Project’s licensing model. You will not submit material subject to terms that require the Project to disclose proprietary source code (e.g., certain copyleft obligations) unless the Project has **pre‑approved** such inclusion in writing.
|
|
44
|
+
|
|
45
|
+
## 7. Scope & Duration
|
|
46
|
+
|
|
47
|
+
- This CLA covers **all past and future** Contributions You submit to the Project, unless and until You provide written notice to **revoke** it.
|
|
48
|
+
- Revocation is **not retroactive**: rights granted for prior Contributions remain in effect.
|
|
49
|
+
|
|
50
|
+
## 8. Disclaimer
|
|
51
|
+
|
|
52
|
+
THE CONTRIBUTION IS PROVIDED “AS IS” WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON‑INFRINGEMENT.
|
|
53
|
+
|
|
54
|
+
## 9. Governing Law & Jurisdiction
|
|
55
|
+
|
|
56
|
+
This CLA is governed by the **laws of England and Wales**, and the courts of England and Wales shall have **exclusive jurisdiction** over any dispute arising out of or relating to it.
|
|
57
|
+
|
|
58
|
+
## 10. Entire Agreement
|
|
59
|
+
|
|
60
|
+
This CLA is the entire agreement between You and Plasius LTD regarding Contributions. It supersedes any prior discussions relating to Contributions. If any provision is held unenforceable, the remaining provisions remain in full force.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 11. Contributor Information & Signature
|
|
65
|
+
|
|
66
|
+
By signing below, You agree to the terms of this CLA for Your Contributions to the Project.
|
|
67
|
+
|
|
68
|
+
**Full Name:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
69
|
+
|
|
70
|
+
**Email:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
71
|
+
|
|
72
|
+
**GitHub Handle:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
73
|
+
|
|
74
|
+
**Address (optional):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
75
|
+
|
|
76
|
+
**Employer (if applicable):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
77
|
+
|
|
78
|
+
**If employed:** ☐ I confirm Contributions are made outside the scope of employment **or** ☐ I have attached my employer’s written permission.
|
|
79
|
+
|
|
80
|
+
**Signature:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
81
|
+
|
|
82
|
+
**Date (YYYY‑MM‑DD):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
|
|
83
|
+
|
|
84
|
+
_Electronic signatures are accepted. You may type your name in the Signature field and email a PDF copy._
|
|
85
|
+
|
|
86
|
+
**Submission:** Please email the signed CLA to **[contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)** with subject line: `CLA – Individual – <GitHubHandle>`.
|
|
87
|
+
|
|
88
|
+
**(Optional) Attachments / Notes:**
|
|
89
|
+
|
|
90
|
+
- Employer permission letter (if required)
|
|
91
|
+
- Third‑party license disclosures (if any)
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@plasius/gpu-lock-free-queue",
|
|
3
|
+
"version": "0.1.1-beta.1",
|
|
4
|
+
"description": "WebGPU lock-free MPMC ring queue with sequence counters.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"private": false,
|
|
8
|
+
"files": [
|
|
9
|
+
"src",
|
|
10
|
+
"README.md",
|
|
11
|
+
"CHANGELOG.md",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"legal"
|
|
14
|
+
],
|
|
15
|
+
"exports": {
|
|
16
|
+
".": "./src/index.js",
|
|
17
|
+
"./queue.wgsl": "./src/queue.wgsl",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"demo": "python3 -m http.server"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"webgpu",
|
|
25
|
+
"lock-free",
|
|
26
|
+
"mpmc",
|
|
27
|
+
"queue",
|
|
28
|
+
"ring-buffer",
|
|
29
|
+
"sequence-counter",
|
|
30
|
+
"gpu",
|
|
31
|
+
"compute",
|
|
32
|
+
"concurrency",
|
|
33
|
+
"plasius"
|
|
34
|
+
],
|
|
35
|
+
"author": "Plasius LTD <development@plasius.co.uk>",
|
|
36
|
+
"license": "Apache-2.0",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/Plasius-LTD/gpu-lock-free-queue.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/Plasius-LTD/gpu-lock-free-queue/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/Plasius-LTD/gpu-lock-free-queue#readme",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"funding": [
|
|
49
|
+
{
|
|
50
|
+
"type": "patreon",
|
|
51
|
+
"url": "https://www.patreon.com/c/plasiusltd/membership"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"type": "github",
|
|
55
|
+
"url": "https://github.com/sponsors/Plasius-LTD"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
}
|
package/src/index.js
ADDED
package/src/queue.wgsl
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
struct Queue {
|
|
2
|
+
head: atomic<u32>,
|
|
3
|
+
tail: atomic<u32>,
|
|
4
|
+
capacity: u32,
|
|
5
|
+
mask: u32,
|
|
6
|
+
_pad: vec2<u32>,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
struct Slot {
|
|
10
|
+
seq: atomic<u32>,
|
|
11
|
+
value: u32,
|
|
12
|
+
_pad: vec2<u32>,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
struct Params {
|
|
16
|
+
job_count: u32,
|
|
17
|
+
_pad: vec3<u32>,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
@group(0) @binding(0) var<storage, read_write> queue: Queue;
|
|
21
|
+
@group(0) @binding(1) var<storage, read_write> slots: array<Slot>;
|
|
22
|
+
@group(0) @binding(2) var<storage, read> input_jobs: array<u32>;
|
|
23
|
+
@group(0) @binding(3) var<storage, read_write> output_jobs: array<u32>;
|
|
24
|
+
@group(0) @binding(4) var<storage, read_write> status: array<u32>;
|
|
25
|
+
@group(0) @binding(5) var<uniform> params: Params;
|
|
26
|
+
|
|
27
|
+
const MAX_RETRIES: u32 = 512u;
|
|
28
|
+
|
|
29
|
+
fn enqueue(val: u32) -> u32 {
|
|
30
|
+
for (var attempt: u32 = 0u; attempt < MAX_RETRIES; attempt++) {
|
|
31
|
+
let t = atomicLoad(&queue.tail);
|
|
32
|
+
let slot_index = t & queue.mask;
|
|
33
|
+
let seq = atomicLoad(&slots[slot_index].seq);
|
|
34
|
+
let diff = i32(seq) - i32(t);
|
|
35
|
+
|
|
36
|
+
if (diff == 0) {
|
|
37
|
+
let res = atomicCompareExchangeWeak(&queue.tail, t, t + 1u);
|
|
38
|
+
if (res.exchanged) {
|
|
39
|
+
slots[slot_index].value = val;
|
|
40
|
+
atomicStore(&slots[slot_index].seq, t + 1u);
|
|
41
|
+
return 1u;
|
|
42
|
+
}
|
|
43
|
+
} else if (diff < 0) {
|
|
44
|
+
return 0u;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return 0u;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn dequeue(idx: u32) -> u32 {
|
|
52
|
+
for (var attempt: u32 = 0u; attempt < MAX_RETRIES; attempt++) {
|
|
53
|
+
let h = atomicLoad(&queue.head);
|
|
54
|
+
let slot_index = h & queue.mask;
|
|
55
|
+
let seq = atomicLoad(&slots[slot_index].seq);
|
|
56
|
+
let diff = i32(seq) - i32(h + 1u);
|
|
57
|
+
|
|
58
|
+
if (diff == 0) {
|
|
59
|
+
let res = atomicCompareExchangeWeak(&queue.head, h, h + 1u);
|
|
60
|
+
if (res.exchanged) {
|
|
61
|
+
let val = slots[slot_index].value;
|
|
62
|
+
output_jobs[idx] = val;
|
|
63
|
+
atomicStore(&slots[slot_index].seq, h + queue.capacity);
|
|
64
|
+
return 1u;
|
|
65
|
+
}
|
|
66
|
+
} else if (diff < 0) {
|
|
67
|
+
return 0u;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return 0u;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@compute @workgroup_size(64)
|
|
75
|
+
fn enqueue_main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
76
|
+
let idx = gid.x;
|
|
77
|
+
if (idx >= params.job_count) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (status[idx] == 1u) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let ok = enqueue(input_jobs[idx]);
|
|
85
|
+
if (ok == 1u) {
|
|
86
|
+
status[idx] = 1u;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@compute @workgroup_size(64)
|
|
91
|
+
fn dequeue_main(@builtin(global_invocation_id) gid: vec3<u32>) {
|
|
92
|
+
let idx = gid.x;
|
|
93
|
+
if (idx >= params.job_count) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (status[idx] == 1u) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let ok = dequeue(idx);
|
|
101
|
+
if (ok == 1u) {
|
|
102
|
+
status[idx] = 1u;
|
|
103
|
+
}
|
|
104
|
+
}
|