syncsan 0.10.4__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.
syncsan-0.10.4/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ include LICENSE README.md
2
+ recursive-include src *
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: syncsan
3
+ Version: 0.10.4
4
+ Summary: Finds data races in GPU megakernels and shows what each one does to your output.
5
+ Author: Shreshth Rajan
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/ShreshthRajan/syncsan
8
+ Project-URL: Issues, https://github.com/ShreshthRajan/syncsan/issues
9
+ Keywords: cuda,gpu,race detection,megakernel,ptx,memory model,nvbit,sanitizer
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: GPU :: NVIDIA CUDA
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: C++
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Software Development :: Debuggers
18
+ Classifier: Topic :: Software Development :: Testing
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: cmake>=3.29
23
+ Dynamic: license-file
24
+
25
+ # syncsan
26
+
27
+ syncsan finds data races in GPU megakernels. It runs your CUDA program unchanged under
28
+ [NVBit](https://github.com/NVlabs/NVBit) and reports every pair of memory accesses that no barrier, fence,
29
+ release/acquire or async-copy wait puts in order. With `SYNCSAN_ADVERSARIAL=1` it also hands each racy load the stale
30
+ value the PTX memory model allows, so you can see what the race does to your output.
31
+
32
+ Megakernels need this more than most code. They run a whole model in one launch and pass activations between SMs
33
+ through counters in global memory. A missing fence in one of those handoffs rarely fails on today's GPUs, so it
34
+ survives testing.
35
+
36
+ ## Quick start
37
+
38
+ You need Linux, an NVIDIA GPU from the A100 onward, and CUDA 12.
39
+
40
+ ```
41
+ pip install syncsan
42
+ syncsan build --arch 90 # once; use 100 for B200, 120 for RTX 50xx, 80 for A100
43
+ syncsan run -- python generate.py
44
+ ```
45
+
46
+ To see it work before pointing it at your own code, try [examples/handoff.cu](examples/handoff.cu). It is the most
47
+ common megakernel bug in 30 lines: one block writes data, fences and bumps a counter, and another block spins on the
48
+ counter and reads the data with no fence after the spin.
49
+
50
+ ```
51
+ $ nvcc -arch=sm_90 -lineinfo -o handoff examples/handoff.cu
52
+ $ ./handoff
53
+ sum = 32896 (expected 32896): correct
54
+ $ syncsan run -- ./handoff
55
+ syncsan: RACE (write then read) at 0x7ef8ffe00300
56
+ block 1 warp 2: STG.E desc[UR6][R2.64], R5 ; [handoff(unsigned int*, int*, int*)+0x1e0 handoff.cu:15]
57
+ block 0 warp 2: LDG.E R2, desc[UR6][R2.64] ; [handoff(unsigned int*, int*, int*)+0x120 handoff.cu:26]
58
+ sum = 32896 (expected 32896): correct
59
+ $ SYNCSAN_ADVERSARIAL=1 syncsan run -- ./handoff
60
+ sum = 0 (expected 32896): WRONG
61
+ ```
62
+
63
+ The kernel gives the right sum on the GPU, syncsan points at the write on line 15 and the read on line 26, and
64
+ adversarial mode shows the wrong sum the memory model allows. Rebuild with `-DFIXED`, which adds the fence after the
65
+ spin, and syncsan reports nothing. Build your own kernels with `-lineinfo` so the reports name source lines.
66
+
67
+ `--kernel NAME` checks only the kernels whose name contains `NAME`, `--exitcode 1` makes a race fail your CI
68
+ ([example workflow](examples/github-actions.yml)), and `--sample k` checks one in `k` plain accesses when the full
69
+ check is too slow. `syncsan run --help` lists the rest.
70
+
71
+ ## What it has found
72
+
73
+ The clearest case is SuperLU_DIST. A commit that fixed a dropped fence in its GPU triangular solve restored the
74
+ consumer's acquire but left out the producer's release. syncsan flagged the producer's decrement, and in adversarial
75
+ mode the solve came back with an error of 0.7. On the fixed commit the error is 6e-15. The maintainers confirmed it and fixed it the same day
76
+ ([xiaoyeli/superlu_dist#261](https://github.com/xiaoyeli/superlu_dist/issues/261)).
77
+
78
+ In Hazy Research's [Llama-1B megakernel](https://github.com/HazyResearch/Megakernels), activations move between SMs
79
+ through a TMA store, a relaxed `atomicAdd` on a counter and a `volatile` spin, with no gpu-scope fence. syncsan
80
+ reports 25 racing pairs, and in adversarial mode the model stops making sense (H100, 8 tokens):
81
+
82
+ | Build | Mode | Output |
83
+ |---|---|---|
84
+ | original | native | "Why did the cookie go to the" |
85
+ | original | adversarial | "iteriteriter abstractجرineronde" |
86
+ | original | control | "Why did the cookie go to the" |
87
+ | release/acquire counters | adversarial | "Why did the cookie go to the" |
88
+
89
+ The control run redirects the same loads but hands them their current values, so the redirection itself is not what
90
+ breaks the output. This race also fails on real hardware. When `silu_out` is filled with NaN before each step, the
91
+ original megakernel reads the NaN in all 1,000 generations and the fixed one in none. Making the counters
92
+ release/acquire fixes it at a 9% latency cost
93
+ ([HazyResearch/Megakernels#16](https://github.com/HazyResearch/Megakernels/issues/16)).
94
+
95
+ The other finds:
96
+
97
+ - [AutoMegaKernel](https://github.com/RightNow-AI/AutoMegaKernel) waits with `atomicAdd(c, 0)`, which a comment calls
98
+ an acquire but PTX treats as relaxed. In adversarial mode its own `--verify` check fails
99
+ ([RightNow-AI/AutoMegaKernel#6](https://github.com/RightNow-AI/AutoMegaKernel/issues/6)).
100
+ - [megakernel-zoo](https://github.com/dangxingyu/megakernel-zoo) and [Lucebox](https://github.com/Luce-Org/lucebox)
101
+ release correctly but spin on a `volatile` load with no fence after it. In both, the adversarial output is garbage
102
+ and a fence after the spin fixes it ([dangxingyu/megakernel-zoo#3](https://github.com/dangxingyu/megakernel-zoo/issues/3),
103
+ [Luce-Org/lucebox#1075](https://github.com/Luce-Org/lucebox/issues/1075)).
104
+ - [Mirage MPK](https://github.com/mirage-project/mirage)'s argmax reduction has no barrier between warp 0 reading the
105
+ per-warp maxima and the other warps writing the next row's
106
+ ([mirage-project/mirage#843](https://github.com/mirage-project/mirage/issues/843)).
107
+ - [Magni VM](https://github.com/Bobliuuu/mvm) had an admission race that 3,200 passing test runs never hit
108
+ ([Bobliuuu/mvm#97](https://github.com/Bobliuuu/mvm/pull/97)).
109
+ - On CUTLASS 3.6.0, syncsan finds the known Stream-K race from issue #2027, and it finds nothing in the fixed 3.7.0.
110
+
111
+ Each one has a write-up in [docs/findings](docs/findings/) and a script in [reproduce](reproduce/) that reruns it on a
112
+ rented GPU. The summary of every run is in [results](results/).
113
+
114
+ ## What it checks
115
+
116
+ syncsan follows the PTX memory model for global memory between thread blocks and for shared memory between warps,
117
+ including mbarriers and the Hopper and Blackwell copy engine (TMA, `cp.async.bulk`, `cp.async`). It does not check
118
+ races between lanes of one warp, distributed shared memory, or ordering across kernels and streams. It is slow: a
119
+ 4-token decode of the Hazy megakernel takes 54 s under syncsan and 14 s without it.
120
+ [docs/how-it-works.md](docs/how-it-works.md) describes the model and its limits, and
121
+ [docs/prior-work.md](docs/prior-work.md) compares syncsan with Barracuda, iGUARD, SuperCollider and compute-sanitizer.
122
+
123
+ ## Tests
124
+
125
+ `tests/run_tests.sh sm_90` runs 51 cases with known answers on a local GPU. [tests/cuhadron](tests/cuhadron/) adds six
126
+ cross-block synchronization tests to NVIDIA's [cuHadron](https://github.com/NVlabs/cuHadron) race benchmark.
127
+
128
+ ## License
129
+
130
+ Apache 2.0. To cite syncsan, see [CITATION.cff](CITATION.cff).
@@ -0,0 +1,106 @@
1
+ # syncsan
2
+
3
+ syncsan finds data races in GPU megakernels. It runs your CUDA program unchanged under
4
+ [NVBit](https://github.com/NVlabs/NVBit) and reports every pair of memory accesses that no barrier, fence,
5
+ release/acquire or async-copy wait puts in order. With `SYNCSAN_ADVERSARIAL=1` it also hands each racy load the stale
6
+ value the PTX memory model allows, so you can see what the race does to your output.
7
+
8
+ Megakernels need this more than most code. They run a whole model in one launch and pass activations between SMs
9
+ through counters in global memory. A missing fence in one of those handoffs rarely fails on today's GPUs, so it
10
+ survives testing.
11
+
12
+ ## Quick start
13
+
14
+ You need Linux, an NVIDIA GPU from the A100 onward, and CUDA 12.
15
+
16
+ ```
17
+ pip install syncsan
18
+ syncsan build --arch 90 # once; use 100 for B200, 120 for RTX 50xx, 80 for A100
19
+ syncsan run -- python generate.py
20
+ ```
21
+
22
+ To see it work before pointing it at your own code, try [examples/handoff.cu](examples/handoff.cu). It is the most
23
+ common megakernel bug in 30 lines: one block writes data, fences and bumps a counter, and another block spins on the
24
+ counter and reads the data with no fence after the spin.
25
+
26
+ ```
27
+ $ nvcc -arch=sm_90 -lineinfo -o handoff examples/handoff.cu
28
+ $ ./handoff
29
+ sum = 32896 (expected 32896): correct
30
+ $ syncsan run -- ./handoff
31
+ syncsan: RACE (write then read) at 0x7ef8ffe00300
32
+ block 1 warp 2: STG.E desc[UR6][R2.64], R5 ; [handoff(unsigned int*, int*, int*)+0x1e0 handoff.cu:15]
33
+ block 0 warp 2: LDG.E R2, desc[UR6][R2.64] ; [handoff(unsigned int*, int*, int*)+0x120 handoff.cu:26]
34
+ sum = 32896 (expected 32896): correct
35
+ $ SYNCSAN_ADVERSARIAL=1 syncsan run -- ./handoff
36
+ sum = 0 (expected 32896): WRONG
37
+ ```
38
+
39
+ The kernel gives the right sum on the GPU, syncsan points at the write on line 15 and the read on line 26, and
40
+ adversarial mode shows the wrong sum the memory model allows. Rebuild with `-DFIXED`, which adds the fence after the
41
+ spin, and syncsan reports nothing. Build your own kernels with `-lineinfo` so the reports name source lines.
42
+
43
+ `--kernel NAME` checks only the kernels whose name contains `NAME`, `--exitcode 1` makes a race fail your CI
44
+ ([example workflow](examples/github-actions.yml)), and `--sample k` checks one in `k` plain accesses when the full
45
+ check is too slow. `syncsan run --help` lists the rest.
46
+
47
+ ## What it has found
48
+
49
+ The clearest case is SuperLU_DIST. A commit that fixed a dropped fence in its GPU triangular solve restored the
50
+ consumer's acquire but left out the producer's release. syncsan flagged the producer's decrement, and in adversarial
51
+ mode the solve came back with an error of 0.7. On the fixed commit the error is 6e-15. The maintainers confirmed it and fixed it the same day
52
+ ([xiaoyeli/superlu_dist#261](https://github.com/xiaoyeli/superlu_dist/issues/261)).
53
+
54
+ In Hazy Research's [Llama-1B megakernel](https://github.com/HazyResearch/Megakernels), activations move between SMs
55
+ through a TMA store, a relaxed `atomicAdd` on a counter and a `volatile` spin, with no gpu-scope fence. syncsan
56
+ reports 25 racing pairs, and in adversarial mode the model stops making sense (H100, 8 tokens):
57
+
58
+ | Build | Mode | Output |
59
+ |---|---|---|
60
+ | original | native | "Why did the cookie go to the" |
61
+ | original | adversarial | "iteriteriter abstractجرineronde" |
62
+ | original | control | "Why did the cookie go to the" |
63
+ | release/acquire counters | adversarial | "Why did the cookie go to the" |
64
+
65
+ The control run redirects the same loads but hands them their current values, so the redirection itself is not what
66
+ breaks the output. This race also fails on real hardware. When `silu_out` is filled with NaN before each step, the
67
+ original megakernel reads the NaN in all 1,000 generations and the fixed one in none. Making the counters
68
+ release/acquire fixes it at a 9% latency cost
69
+ ([HazyResearch/Megakernels#16](https://github.com/HazyResearch/Megakernels/issues/16)).
70
+
71
+ The other finds:
72
+
73
+ - [AutoMegaKernel](https://github.com/RightNow-AI/AutoMegaKernel) waits with `atomicAdd(c, 0)`, which a comment calls
74
+ an acquire but PTX treats as relaxed. In adversarial mode its own `--verify` check fails
75
+ ([RightNow-AI/AutoMegaKernel#6](https://github.com/RightNow-AI/AutoMegaKernel/issues/6)).
76
+ - [megakernel-zoo](https://github.com/dangxingyu/megakernel-zoo) and [Lucebox](https://github.com/Luce-Org/lucebox)
77
+ release correctly but spin on a `volatile` load with no fence after it. In both, the adversarial output is garbage
78
+ and a fence after the spin fixes it ([dangxingyu/megakernel-zoo#3](https://github.com/dangxingyu/megakernel-zoo/issues/3),
79
+ [Luce-Org/lucebox#1075](https://github.com/Luce-Org/lucebox/issues/1075)).
80
+ - [Mirage MPK](https://github.com/mirage-project/mirage)'s argmax reduction has no barrier between warp 0 reading the
81
+ per-warp maxima and the other warps writing the next row's
82
+ ([mirage-project/mirage#843](https://github.com/mirage-project/mirage/issues/843)).
83
+ - [Magni VM](https://github.com/Bobliuuu/mvm) had an admission race that 3,200 passing test runs never hit
84
+ ([Bobliuuu/mvm#97](https://github.com/Bobliuuu/mvm/pull/97)).
85
+ - On CUTLASS 3.6.0, syncsan finds the known Stream-K race from issue #2027, and it finds nothing in the fixed 3.7.0.
86
+
87
+ Each one has a write-up in [docs/findings](docs/findings/) and a script in [reproduce](reproduce/) that reruns it on a
88
+ rented GPU. The summary of every run is in [results](results/).
89
+
90
+ ## What it checks
91
+
92
+ syncsan follows the PTX memory model for global memory between thread blocks and for shared memory between warps,
93
+ including mbarriers and the Hopper and Blackwell copy engine (TMA, `cp.async.bulk`, `cp.async`). It does not check
94
+ races between lanes of one warp, distributed shared memory, or ordering across kernels and streams. It is slow: a
95
+ 4-token decode of the Hazy megakernel takes 54 s under syncsan and 14 s without it.
96
+ [docs/how-it-works.md](docs/how-it-works.md) describes the model and its limits, and
97
+ [docs/prior-work.md](docs/prior-work.md) compares syncsan with Barracuda, iGUARD, SuperCollider and compute-sanitizer.
98
+
99
+ ## Tests
100
+
101
+ `tests/run_tests.sh sm_90` runs 51 cases with known answers on a local GPU. [tests/cuhadron](tests/cuhadron/) adds six
102
+ cross-block synchronization tests to NVIDIA's [cuHadron](https://github.com/NVlabs/cuHadron) race benchmark.
103
+
104
+ ## License
105
+
106
+ Apache 2.0. To cite syncsan, see [CITATION.cff](CITATION.cff).
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "syncsan"
7
+ version = "0.10.4"
8
+ description = "Finds data races in GPU megakernels and shows what each one does to your output."
9
+ license = {text = "Apache-2.0"}
10
+ readme = "README.md"
11
+ requires-python = ">=3.9"
12
+ dependencies = ["cmake>=3.29"]
13
+ authors = [{name = "Shreshth Rajan"}]
14
+ keywords = ["cuda", "gpu", "race detection", "megakernel", "ptx", "memory model", "nvbit", "sanitizer"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Environment :: GPU :: NVIDIA CUDA",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: Apache Software License",
20
+ "Operating System :: POSIX :: Linux",
21
+ "Programming Language :: C++",
22
+ "Programming Language :: Python :: 3",
23
+ "Topic :: Software Development :: Debuggers",
24
+ "Topic :: Software Development :: Testing",
25
+ ]
26
+
27
+ [project.scripts]
28
+ syncsan = "syncsan.cli:main"
29
+
30
+ [tool.setuptools]
31
+ package-dir = {"" = "python"}
32
+ packages = ["syncsan"]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/ShreshthRajan/syncsan"
36
+ Issues = "https://github.com/ShreshthRajan/syncsan/issues"
@@ -0,0 +1,2 @@
1
+ """syncsan: a happens-before race detector for persistent GPU kernels (NVBit tool). See `syncsan --help`."""
2
+ __version__ = "0.10.4"
@@ -0,0 +1,96 @@
1
+ """syncsan command line.
2
+
3
+ syncsan build download NVBit 1.8.2 and build the tool (needs nvcc and cmake >= 3.29), once
4
+ syncsan run [options] -- CMD ... run CMD with every (or the chosen) CUDA kernel checked for races
5
+ syncsan where print the path of the built tool
6
+
7
+ Exit status of `run`: CMD's own, or --exitcode N when syncsan reported a race (for CI).
8
+ """
9
+ import argparse
10
+ import os
11
+ import pathlib
12
+ import shutil
13
+ import subprocess
14
+ import sys
15
+ import tarfile
16
+ import urllib.request
17
+
18
+ NVBIT_URL = "https://github.com/NVlabs/NVBit/releases/download/v1.8.2/nvbit-Linux-x86_64-1.8.2.tar.bz2"
19
+ CACHE = pathlib.Path(os.environ.get("SYNCSAN_HOME", pathlib.Path.home() / ".cache" / "syncsan"))
20
+ SRC = pathlib.Path(__file__).resolve().parent / "csrc"
21
+
22
+
23
+ def tool_path() -> pathlib.Path:
24
+ return CACHE / "build" / "syncsan.so"
25
+
26
+
27
+ def build(arch: str) -> pathlib.Path:
28
+ nvbit = CACHE / "nvbit_release_x86_64"
29
+ if not nvbit.exists():
30
+ CACHE.mkdir(parents=True, exist_ok=True)
31
+ tar = CACHE / "nvbit.tar.bz2"
32
+ print(f"syncsan: downloading NVBit 1.8.2 to {CACHE}", file=sys.stderr)
33
+ urllib.request.urlretrieve(NVBIT_URL, tar)
34
+ with tarfile.open(tar) as t:
35
+ t.extractall(CACHE)
36
+ tar.unlink()
37
+ src = CACHE / "src"
38
+ if src.exists():
39
+ shutil.rmtree(src)
40
+ shutil.copytree(SRC, src)
41
+ b = CACHE / "build"
42
+ subprocess.run(["cmake", "-S", str(src), "-B", str(b), f"-DNVBIT_ROOT={nvbit}", f"-DNVBIT_TOOL_CUDA_ARCHITECTURES={arch}"], check=True)
43
+ subprocess.run(["cmake", "--build", str(b), "-j", str(os.cpu_count() or 4)], check=True)
44
+ print(tool_path())
45
+ return tool_path()
46
+
47
+
48
+ def run(a: argparse.Namespace) -> int:
49
+ so = tool_path()
50
+ if not so.exists():
51
+ build(a.arch)
52
+ cmd = a.cmd[1:] if a.cmd and a.cmd[0] == "--" else a.cmd
53
+ if not cmd:
54
+ print("syncsan run: give a command after --", file=sys.stderr)
55
+ return 2
56
+ env = dict(os.environ)
57
+ env["LD_PRELOAD"] = f"{so}:{env['LD_PRELOAD']}" if env.get("LD_PRELOAD") else str(so)
58
+ env["SYNCSAN_EXITCODE"] = str(a.exitcode)
59
+ for flag, var in ((a.kernel, "SYNCSAN_KERNEL"), (a.sample, "SYNCSAN_SAMPLE"), (a.instrument, "SYNCSAN_INSTRUMENT"),
60
+ (a.async_, "SYNCSAN_ASYNC")):
61
+ if flag:
62
+ env[var] = str(flag)
63
+ if a.verbose:
64
+ env["SYNCSAN_VERBOSE"] = str(a.verbose)
65
+ if a.check_nc:
66
+ env["SYNCSAN_CHECK_NC"] = "1"
67
+ return subprocess.run(cmd, env=env).returncode
68
+
69
+
70
+ def main() -> None:
71
+ p = argparse.ArgumentParser(prog="syncsan", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
72
+ sub = p.add_subparsers(dest="what", required=True)
73
+ pb = sub.add_parser("build", help="download NVBit and build the tool")
74
+ pb.add_argument("--arch", default="90", help="CUDA architecture of the tool's device code (90 = H100, 80 = A100)")
75
+ sub.add_parser("where", help="print the built tool's path")
76
+ pr = sub.add_parser("run", help="run a command under syncsan")
77
+ pr.add_argument("--kernel", help="check only kernels whose name contains this")
78
+ pr.add_argument("--sample", help="k or k:seed: check one plain load/store site in k (sync operations always checked)")
79
+ pr.add_argument("--instrument", help="comma list of mem,bar,fence (default all)")
80
+ pr.add_argument("--async", dest="async_", help="comma list of tma,bulk,wait (default all)")
81
+ pr.add_argument("--check-nc", action="store_true", help="also check ld.global.nc (read-only) loads")
82
+ pr.add_argument("--exitcode", type=int, default=0, help="exit with this code when a race is reported (0: CMD's own)")
83
+ pr.add_argument("-v", "--verbose", type=int, default=0)
84
+ pr.add_argument("--arch", default="90")
85
+ pr.add_argument("cmd", nargs=argparse.REMAINDER)
86
+ a = p.parse_args()
87
+ if a.what == "build":
88
+ build(a.arch)
89
+ elif a.what == "where":
90
+ print(tool_path() if tool_path().exists() else "not built: run `syncsan build`")
91
+ else:
92
+ sys.exit(run(a))
93
+
94
+
95
+ if __name__ == "__main__":
96
+ main()