pravaha-mem 1.0.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.
Files changed (32) hide show
  1. pravaha_mem-1.0.0/LICENSE +21 -0
  2. pravaha_mem-1.0.0/PKG-INFO +210 -0
  3. pravaha_mem-1.0.0/README.md +180 -0
  4. pravaha_mem-1.0.0/pyproject.toml +55 -0
  5. pravaha_mem-1.0.0/python/pravaha_mem/__init__.py +17 -0
  6. pravaha_mem-1.0.0/python/pravaha_mem/c2c_checks.py +75 -0
  7. pravaha_mem-1.0.0/python/pravaha_mem/c2c_sampler.py +244 -0
  8. pravaha_mem-1.0.0/python/pravaha_mem/cli.py +212 -0
  9. pravaha_mem-1.0.0/python/pravaha_mem/install.py +149 -0
  10. pravaha_mem-1.0.0/python/pravaha_mem/kernels.py +148 -0
  11. pravaha_mem-1.0.0/python/pravaha_mem/known_bytes.py +113 -0
  12. pravaha_mem-1.0.0/python/pravaha_mem/observer.py +335 -0
  13. pravaha_mem-1.0.0/python/pravaha_mem/pravaha_c2c.cpp +167 -0
  14. pravaha_mem-1.0.0/python/pravaha_mem/reader.cpp +179 -0
  15. pravaha_mem-1.0.0/python/pravaha_mem/smmu/__init__.py +7 -0
  16. pravaha_mem-1.0.0/python/pravaha_mem/smmu/commands.py +120 -0
  17. pravaha_mem-1.0.0/python/pravaha_mem/smmu/discover.py +110 -0
  18. pravaha_mem-1.0.0/python/pravaha_mem/smmu/helper.py +98 -0
  19. pravaha_mem-1.0.0/python/pravaha_mem/smmu/identity.py +79 -0
  20. pravaha_mem-1.0.0/python/pravaha_mem/smmu/perf.py +187 -0
  21. pravaha_mem-1.0.0/python/pravaha_mem/smmu/pravaha_pmcg.c +153 -0
  22. pravaha_mem-1.0.0/python/pravaha_mem/status.py +133 -0
  23. pravaha_mem-1.0.0/python/pravaha_mem/verify.py +117 -0
  24. pravaha_mem-1.0.0/python/pravaha_mem.egg-info/PKG-INFO +210 -0
  25. pravaha_mem-1.0.0/python/pravaha_mem.egg-info/SOURCES.txt +30 -0
  26. pravaha_mem-1.0.0/python/pravaha_mem.egg-info/dependency_links.txt +1 -0
  27. pravaha_mem-1.0.0/python/pravaha_mem.egg-info/entry_points.txt +2 -0
  28. pravaha_mem-1.0.0/python/pravaha_mem.egg-info/requires.txt +3 -0
  29. pravaha_mem-1.0.0/python/pravaha_mem.egg-info/top_level.txt +1 -0
  30. pravaha_mem-1.0.0/setup.cfg +4 -0
  31. pravaha_mem-1.0.0/tests/test_gpu.py +75 -0
  32. pravaha_mem-1.0.0/tests/test_observer.py +77 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MANTRA Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,210 @@
1
+ Metadata-Version: 2.4
2
+ Name: pravaha-mem
3
+ Version: 1.0.0
4
+ Summary: Live GPU memory traffic over NVLink C2C on the NVIDIA GB10 (DGX Spark), from the GPU's L2 cache counters
5
+ Author: Sirisha Kota
6
+ Author-email: Deepak Panigrahy <deepakp@tamu.edu>
7
+ Maintainer-email: Deepak Panigrahy <deepakp@tamu.edu>
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/deepakpanigrahy03/pravaha-mem
10
+ Project-URL: Documentation, https://github.com/deepakpanigrahy03/pravaha-mem/blob/main/docs/MANUAL.md
11
+ Project-URL: Source, https://github.com/deepakpanigrahy03/pravaha-mem
12
+ Project-URL: Issues, https://github.com/deepakpanigrahy03/pravaha-mem/issues
13
+ Project-URL: Changelog, https://github.com/deepakpanigrahy03/pravaha-mem/blob/main/CHANGELOG.md
14
+ Keywords: gb10,dgx-spark,nvlink,nvlink-c2c,gpu,memory-traffic,l2-cache,performance-counters,cupti,smmu,energy,llm
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: Environment :: Console
17
+ Classifier: Intended Audience :: Science/Research
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: Operating System :: POSIX :: Linux
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3 :: Only
22
+ Classifier: Topic :: System :: Monitoring
23
+ Classifier: Topic :: System :: Hardware
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: test
28
+ Requires-Dist: pytest; extra == "test"
29
+ Dynamic: license-file
30
+
31
+ <p align="center">
32
+ <img src="assets/pravaha-banner.svg" alt="pravaha: GPU memory flow on the NVIDIA GB10" width="100%">
33
+ </p>
34
+
35
+ <p align="center">
36
+ <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
37
+ <img alt="Python 3.8+" src="https://img.shields.io/badge/python-3.8%2B-blue.svg">
38
+ <img alt="Platform: NVIDIA GB10" src="https://img.shields.io/badge/platform-NVIDIA%20GB10-76B900.svg">
39
+ <img alt="Dependencies: none" src="https://img.shields.io/badge/dependencies-none-brightgreen.svg">
40
+ <!-- PyPI and DOI badges are added after the first release -->
41
+ </p>
42
+
43
+ # pravaha-mem
44
+
45
+ **Live GPU memory traffic on the NVIDIA GB10 (DGX Spark, Acer GN100 and other GB10 systems), for any program, without changing it.**
46
+
47
+ > **New here? Read [The whole idea](docs/THE_WHOLE_IDEA.md) first:** the machine, the problem, the solution and how we know it is right, in one read.
48
+
49
+ On the GB10 the GPU has no memory of its own: every byte it reads or writes goes to the shared LPDDR5X behind the CPU die, over NVLink C2C. NVIDIA exposes no counter for that link on GB10. pravaha reads the GPU's own L2 cache counters every 10 ms, from a separate process, and reports the bytes moved: by copy engines, by GPU code reading and writing, and in total.
50
+
51
+ *Pravaha* (प्रवाह) is Sanskrit for *flow*.
52
+
53
+ ## 🧭 What it gives you
54
+
55
+ | | feature | command |
56
+ |---|---|---|
57
+ | 1 | allow counter reading, once per machine | `pravaha install` |
58
+ | 2 | is this machine ready? | `pravaha status` |
59
+ | 3 | check the numbers against known bytes | `pravaha verify` |
60
+ | 4 | traffic while a program runs | `pravaha run -- CMD` |
61
+ | 5 | traffic over a time window, e.g. a running LLM server | `pravaha observe --seconds 60` |
62
+ | 6 | live samples | `pravaha observe --live` |
63
+ | 7 | phases inside your own Python code | `with pv.observe() as m: m.mark("decode")` |
64
+ | 8 | save data with full provenance | `--csv FILE`, `--json FILE` |
65
+ | 9 | GPU address translations (counts, not bytes) | `pravaha smmu status / run / observe` |
66
+ | 10 | traffic per kernel (Nsight Compute) | `pravaha kernels -- CMD` |
67
+ | 11 | remove it | `pravaha uninstall` |
68
+
69
+ ## 🚀 Start
70
+
71
+ pravaha has two parts: a **Python package** (installed with pip, like any library) and two small **counter readers** that need one admin step per machine, because NVIDIA's driver lets only privileged programs read GPU counters. The program you measure needs nothing.
72
+
73
+ **On a fresh machine (Ubuntu and similar), once:**
74
+ ```bash
75
+ sudo apt install python3-venv gcc g++ # venv support, and compilers to build the readers
76
+ ```
77
+
78
+ **The command line, in its own environment:**
79
+ ```bash
80
+ python3 -m venv ~/pravaha-venv
81
+ source ~/pravaha-venv/bin/activate # in every new terminal before using pravaha
82
+ pip install pravaha-mem # until it is on PyPI: pip install git+https://github.com/deepakpanigrahy03/pravaha-mem
83
+ pravaha install # once per machine: asks for the admin password once
84
+ pravaha status # "ready", or exactly what is missing and how to fix it
85
+ pravaha verify # optional: about 3 minutes, light work only
86
+ pravaha run --idle 2 -- python my_app.py
87
+ ```
88
+
89
+ **As a library inside a platform** (A-LEMS, your own harness): add `pravaha-mem` to the platform's `requirements.txt`, like any library. The readers are shared by every environment on the machine, so `pravaha install` is still needed once per machine (a platform's own install script can run it). Check at startup:
90
+ ```python
91
+ import pravaha_mem as pv
92
+ s = pv.status()
93
+ if not s["ready"]:
94
+ print("GPU traffic measurement disabled:", "; ".join(s["fix"]))
95
+ ```
96
+
97
+ | where | what | how often |
98
+ |---|---|---|
99
+ | your venv, or the platform's venv | the Python package (`pravaha` command, `import pravaha_mem`) | in each environment that measures |
100
+ | `/usr/local/libexec/pravaha` | the two readers, one permission each | once per machine (`pravaha install`) |
101
+
102
+ If something is missing, pravaha says it in one line with the fix, for example: `GPU counter reader not installed on this machine. Run once (asks for the admin password): pravaha install`. If you use pipx: `pipx install pravaha-mem` gives the command in every terminal without activating a venv.
103
+
104
+ For example, measuring pravaha's test program while it copies 2 GiB into the GPU:
105
+ ```
106
+ pravaha: measuring 1 s of idle baseline ...
107
+ pravaha: observing the whole GPU while 'python -m pravaha_mem.known_bytes h2d 8 256' runs; results print when it ends
108
+ phase sec copy GiB kread GiB kwrite GiB C2C GiB GB/s
109
+ total 1.52 2.0146 0.0669 0.2500 4.6802 3.3
110
+ idle 1.00 0.0000 0.0244 0.0000 0.0989 0.1
111
+ run 0.52 2.0146 0.0425 0.2500 4.5813 9.4
112
+ ```
113
+ That command is pravaha's test program copying 2 GiB into the GPU (see below). The extra 0.0146 GiB of copies is CUDA's startup; the 0.25 GiB of kwrite is the program clearing its GPU buffer before the copies.
114
+
115
+ ## 🧪 The test program: known_bytes
116
+
117
+ To check pravaha you need data whose amount is known in advance. `known_bytes` is a small, readable program ([python/pravaha_mem/known_bytes.py](python/pravaha_mem/known_bytes.py)) that moves exactly that, with NVIDIA's standard CUDA calls, and says what it did.
118
+
119
+ ```bash
120
+ python -m pravaha_mem.known_bytes DIRECTION TIMES SIZE_MIB # moves TIMES x SIZE_MIB
121
+ ```
122
+
123
+ | DIRECTION | stands for | what happens | who moves it | pravaha column |
124
+ |---|---|---|---|---|
125
+ | `h2d` | host to device | copy from the computer's memory into the GPU | copy engines (`cudaMemcpy`) | copy |
126
+ | `d2h` | device to host | copy from the GPU back to the computer's memory | copy engines (`cudaMemcpy`) | copy |
127
+ | `d2d` | device to device | copy from one GPU buffer to another | GPU code reading and writing | kread, kwrite |
128
+ | `memset` | memory set | fill a GPU buffer with a value | GPU code writing (`cudaMemset`) | kwrite |
129
+
130
+ "Host" is NVIDIA's word for the computer side, "device" for the GPU. Examples: `h2d 8 256` copies 8 x 256 MiB = 2 GiB into the GPU; `memset 16 256` makes GPU code write 4 GiB. Before its work it reserves its buffers and clears the two GPU buffers (2 x SIZE_MIB in kwrite); every CUDA program also moves about 15 MiB of copies when it starts. `pravaha verify` runs these four directions and compares.
131
+
132
+ ## 🔐 What `pravaha install` puts on your system
133
+
134
+ Exactly one folder, and nothing else:
135
+ ```
136
+ /usr/local/libexec/pravaha/
137
+ pravaha-reader reads the GPU's L2 counters capability cap_perfmon
138
+ pravaha-pmcg reads the GPU's SMMU counters capability cap_perfmon
139
+ MANIFEST what install created (with checksums)
140
+ ```
141
+ Root owned, not writable by users, not in your PATH. No system setting, driver option, group, sudoers entry or service is changed. The readers run as the normal user and only read counters. `pravaha uninstall` removes exactly what MANIFEST lists and confirms nothing is left; then `pip uninstall pravaha-mem`. Manual cleanup, if ever needed: `sudo rm -r /usr/local/libexec/pravaha`.
142
+
143
+ Why a password at all: NVIDIA's driver lets only privileged programs read GPU counters, and only root can attach a capability to a file.
144
+
145
+ ## 🐍 From Python
146
+
147
+ ```python
148
+ import pravaha_mem as pv
149
+
150
+ with pv.observe() as m:
151
+ m.metadata({"model": "qwen3-4b"})
152
+ m.mark("load"); model = load_model()
153
+ m.mark("decode"); out = model.generate(prompt)
154
+
155
+ print(m.summary()) # bytes per phase
156
+ m.to_csv("trace.csv") # one row per sample, system clock in ns
157
+ m.to_json("run.json") # totals, phases, baseline, sampling quality, provenance
158
+ ```
159
+ `m.start()` and `m.stop()` work too, for harnesses with their own hooks (A-LEMS uses these).
160
+
161
+ ## 📏 What the numbers mean
162
+
163
+ | column | from the GPU's L2 counter | meaning |
164
+ |---|---|---|
165
+ | copy | `lts__t_sectors_srcunit_ce` (sectors x 32 / 2) | bytes moved by copy engines: `cudaMemcpy`, `.cuda()`, model loading. Each copied byte passes L2 twice, hence / 2. |
166
+ | kread | `..._srcunit_tex_op_read_lookup_miss_realtime` (x 32) | bytes GPU code read from memory (L2 misses) |
167
+ | kwrite | `..._srcunit_tex_op_write_realtime` (x 32) | bytes GPU code wrote |
168
+ | C2C | all L2 read misses + all L2 writes (x 32) | all GPU memory traffic. On GB10 all GPU memory lies behind the CPU die, so this traffic crosses NVLink C2C. |
169
+
170
+ How the counting works: every GPU request to memory passes the GPU's L2 cache. If the data is already in L2 (a hit), nothing crosses C2C and nothing is counted. If not (a miss), it is fetched over C2C and counted (kread for GPU code). Every write passes L2 and goes to memory over C2C (kwrite). Copies pass L2 twice, as a read and a write, hence copy = sectors x 32 / 2. Diagrams: [GB10 architecture](docs/GB10_ARCHITECTURE.md).
171
+
172
+ * **Device wide.** The counters see every process on the GPU. `run -- CMD` reports the GPU's traffic while CMD runs, not CMD's alone. Use `--idle` or phases for a baseline; the JSON reports raw, baseline and subtracted values separately.
173
+ * **One reader at a time.** The GPU has one sampling unit. While another profiler holds it, pravaha says "counters busy".
174
+ * **GPU side.** CPU memory traffic is not included.
175
+
176
+ ## ✅ Checked against known bytes
177
+
178
+ `pravaha verify` on an Acer GN100 and a DGX Spark (driver 580, CUDA 13.0), each check the middle of 3 runs:
179
+ ```
180
+ PASS copy host to GPU 2048.0 MiB expected 2048.0 ratio 1.0000
181
+ PASS copy GPU to host 2048.0 MiB expected 2048.0 ratio 1.0000
182
+ PASS kernel write (cudaMemset) 4096.0 MiB expected 4096.0 ratio 1.0000
183
+ PASS kernel read (GPU to GPU copy) 4095.9 MiB expected 4096.0 ratio 1.0000
184
+ ```
185
+ Samples carry the system clock; on GB10 it agrees with the GPU's sample clock within 1 microsecond. On real frameworks, observed from outside: PyTorch `.cuda()` 8 minus 4 copies of 1 GiB gives 3.9999 GiB; vLLM serving Qwen3 4B reads 7.52 GiB per generated token, against 7.49 GiB of weights. PASS means agreement for these workloads on that machine and software, not a claim about every workload.
186
+
187
+ ## 📚 Documentation
188
+
189
+ | read this | if you want to |
190
+ |---|---|
191
+ | [The whole idea](docs/THE_WHOLE_IDEA.md) | understand everything in one read: start here |
192
+ | [GB10 architecture](docs/GB10_ARCHITECTURE.md) | understand the GB10, NVLink C2C and what pravaha counts (with diagrams) |
193
+ | [Tutorial](docs/TUTORIAL.md) | learn by running: each lesson one command, with the expected output |
194
+ | [Manual](docs/MANUAL.md) | look up every command, option, column and word |
195
+ | [Developer guide](docs/DEVELOPER_GUIDE.md) | use pravaha inside your Python programs and harnesses |
196
+ | [Researcher guide](docs/RESEARCHER_GUIDE.md) | methodology, accuracy, time base, and what to report in a paper |
197
+ | [Validation record](docs/VALIDATION.md) and [test matrix](docs/TEST_MATRIX.md) | see every test, on which machine, with what result; add yours |
198
+ | [Design](docs/DESIGN.md) | the system design and its rules |
199
+ | [Contributing](CONTRIBUTING.md) | report results from your GB10, or change the code |
200
+
201
+ Examples, each with what it does, what it needs and what to expect: [examples/README.md](examples/README.md).
202
+
203
+ ## 📦 Requirements
204
+ NVIDIA GB10 system, Linux, NVIDIA driver 565 or newer with CUDA 13 (CUPTI included), `gcc` and `g++`, Python 3.8 or newer.
205
+
206
+ ## 📖 Cite
207
+ See [CITATION.cff](CITATION.cff).
208
+
209
+ ## License
210
+ MIT. Copyright (c) 2026 MANTRA Labs.
@@ -0,0 +1,180 @@
1
+ <p align="center">
2
+ <img src="assets/pravaha-banner.svg" alt="pravaha: GPU memory flow on the NVIDIA GB10" width="100%">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
7
+ <img alt="Python 3.8+" src="https://img.shields.io/badge/python-3.8%2B-blue.svg">
8
+ <img alt="Platform: NVIDIA GB10" src="https://img.shields.io/badge/platform-NVIDIA%20GB10-76B900.svg">
9
+ <img alt="Dependencies: none" src="https://img.shields.io/badge/dependencies-none-brightgreen.svg">
10
+ <!-- PyPI and DOI badges are added after the first release -->
11
+ </p>
12
+
13
+ # pravaha-mem
14
+
15
+ **Live GPU memory traffic on the NVIDIA GB10 (DGX Spark, Acer GN100 and other GB10 systems), for any program, without changing it.**
16
+
17
+ > **New here? Read [The whole idea](docs/THE_WHOLE_IDEA.md) first:** the machine, the problem, the solution and how we know it is right, in one read.
18
+
19
+ On the GB10 the GPU has no memory of its own: every byte it reads or writes goes to the shared LPDDR5X behind the CPU die, over NVLink C2C. NVIDIA exposes no counter for that link on GB10. pravaha reads the GPU's own L2 cache counters every 10 ms, from a separate process, and reports the bytes moved: by copy engines, by GPU code reading and writing, and in total.
20
+
21
+ *Pravaha* (प्रवाह) is Sanskrit for *flow*.
22
+
23
+ ## 🧭 What it gives you
24
+
25
+ | | feature | command |
26
+ |---|---|---|
27
+ | 1 | allow counter reading, once per machine | `pravaha install` |
28
+ | 2 | is this machine ready? | `pravaha status` |
29
+ | 3 | check the numbers against known bytes | `pravaha verify` |
30
+ | 4 | traffic while a program runs | `pravaha run -- CMD` |
31
+ | 5 | traffic over a time window, e.g. a running LLM server | `pravaha observe --seconds 60` |
32
+ | 6 | live samples | `pravaha observe --live` |
33
+ | 7 | phases inside your own Python code | `with pv.observe() as m: m.mark("decode")` |
34
+ | 8 | save data with full provenance | `--csv FILE`, `--json FILE` |
35
+ | 9 | GPU address translations (counts, not bytes) | `pravaha smmu status / run / observe` |
36
+ | 10 | traffic per kernel (Nsight Compute) | `pravaha kernels -- CMD` |
37
+ | 11 | remove it | `pravaha uninstall` |
38
+
39
+ ## 🚀 Start
40
+
41
+ pravaha has two parts: a **Python package** (installed with pip, like any library) and two small **counter readers** that need one admin step per machine, because NVIDIA's driver lets only privileged programs read GPU counters. The program you measure needs nothing.
42
+
43
+ **On a fresh machine (Ubuntu and similar), once:**
44
+ ```bash
45
+ sudo apt install python3-venv gcc g++ # venv support, and compilers to build the readers
46
+ ```
47
+
48
+ **The command line, in its own environment:**
49
+ ```bash
50
+ python3 -m venv ~/pravaha-venv
51
+ source ~/pravaha-venv/bin/activate # in every new terminal before using pravaha
52
+ pip install pravaha-mem # until it is on PyPI: pip install git+https://github.com/deepakpanigrahy03/pravaha-mem
53
+ pravaha install # once per machine: asks for the admin password once
54
+ pravaha status # "ready", or exactly what is missing and how to fix it
55
+ pravaha verify # optional: about 3 minutes, light work only
56
+ pravaha run --idle 2 -- python my_app.py
57
+ ```
58
+
59
+ **As a library inside a platform** (A-LEMS, your own harness): add `pravaha-mem` to the platform's `requirements.txt`, like any library. The readers are shared by every environment on the machine, so `pravaha install` is still needed once per machine (a platform's own install script can run it). Check at startup:
60
+ ```python
61
+ import pravaha_mem as pv
62
+ s = pv.status()
63
+ if not s["ready"]:
64
+ print("GPU traffic measurement disabled:", "; ".join(s["fix"]))
65
+ ```
66
+
67
+ | where | what | how often |
68
+ |---|---|---|
69
+ | your venv, or the platform's venv | the Python package (`pravaha` command, `import pravaha_mem`) | in each environment that measures |
70
+ | `/usr/local/libexec/pravaha` | the two readers, one permission each | once per machine (`pravaha install`) |
71
+
72
+ If something is missing, pravaha says it in one line with the fix, for example: `GPU counter reader not installed on this machine. Run once (asks for the admin password): pravaha install`. If you use pipx: `pipx install pravaha-mem` gives the command in every terminal without activating a venv.
73
+
74
+ For example, measuring pravaha's test program while it copies 2 GiB into the GPU:
75
+ ```
76
+ pravaha: measuring 1 s of idle baseline ...
77
+ pravaha: observing the whole GPU while 'python -m pravaha_mem.known_bytes h2d 8 256' runs; results print when it ends
78
+ phase sec copy GiB kread GiB kwrite GiB C2C GiB GB/s
79
+ total 1.52 2.0146 0.0669 0.2500 4.6802 3.3
80
+ idle 1.00 0.0000 0.0244 0.0000 0.0989 0.1
81
+ run 0.52 2.0146 0.0425 0.2500 4.5813 9.4
82
+ ```
83
+ That command is pravaha's test program copying 2 GiB into the GPU (see below). The extra 0.0146 GiB of copies is CUDA's startup; the 0.25 GiB of kwrite is the program clearing its GPU buffer before the copies.
84
+
85
+ ## 🧪 The test program: known_bytes
86
+
87
+ To check pravaha you need data whose amount is known in advance. `known_bytes` is a small, readable program ([python/pravaha_mem/known_bytes.py](python/pravaha_mem/known_bytes.py)) that moves exactly that, with NVIDIA's standard CUDA calls, and says what it did.
88
+
89
+ ```bash
90
+ python -m pravaha_mem.known_bytes DIRECTION TIMES SIZE_MIB # moves TIMES x SIZE_MIB
91
+ ```
92
+
93
+ | DIRECTION | stands for | what happens | who moves it | pravaha column |
94
+ |---|---|---|---|---|
95
+ | `h2d` | host to device | copy from the computer's memory into the GPU | copy engines (`cudaMemcpy`) | copy |
96
+ | `d2h` | device to host | copy from the GPU back to the computer's memory | copy engines (`cudaMemcpy`) | copy |
97
+ | `d2d` | device to device | copy from one GPU buffer to another | GPU code reading and writing | kread, kwrite |
98
+ | `memset` | memory set | fill a GPU buffer with a value | GPU code writing (`cudaMemset`) | kwrite |
99
+
100
+ "Host" is NVIDIA's word for the computer side, "device" for the GPU. Examples: `h2d 8 256` copies 8 x 256 MiB = 2 GiB into the GPU; `memset 16 256` makes GPU code write 4 GiB. Before its work it reserves its buffers and clears the two GPU buffers (2 x SIZE_MIB in kwrite); every CUDA program also moves about 15 MiB of copies when it starts. `pravaha verify` runs these four directions and compares.
101
+
102
+ ## 🔐 What `pravaha install` puts on your system
103
+
104
+ Exactly one folder, and nothing else:
105
+ ```
106
+ /usr/local/libexec/pravaha/
107
+ pravaha-reader reads the GPU's L2 counters capability cap_perfmon
108
+ pravaha-pmcg reads the GPU's SMMU counters capability cap_perfmon
109
+ MANIFEST what install created (with checksums)
110
+ ```
111
+ Root owned, not writable by users, not in your PATH. No system setting, driver option, group, sudoers entry or service is changed. The readers run as the normal user and only read counters. `pravaha uninstall` removes exactly what MANIFEST lists and confirms nothing is left; then `pip uninstall pravaha-mem`. Manual cleanup, if ever needed: `sudo rm -r /usr/local/libexec/pravaha`.
112
+
113
+ Why a password at all: NVIDIA's driver lets only privileged programs read GPU counters, and only root can attach a capability to a file.
114
+
115
+ ## 🐍 From Python
116
+
117
+ ```python
118
+ import pravaha_mem as pv
119
+
120
+ with pv.observe() as m:
121
+ m.metadata({"model": "qwen3-4b"})
122
+ m.mark("load"); model = load_model()
123
+ m.mark("decode"); out = model.generate(prompt)
124
+
125
+ print(m.summary()) # bytes per phase
126
+ m.to_csv("trace.csv") # one row per sample, system clock in ns
127
+ m.to_json("run.json") # totals, phases, baseline, sampling quality, provenance
128
+ ```
129
+ `m.start()` and `m.stop()` work too, for harnesses with their own hooks (A-LEMS uses these).
130
+
131
+ ## 📏 What the numbers mean
132
+
133
+ | column | from the GPU's L2 counter | meaning |
134
+ |---|---|---|
135
+ | copy | `lts__t_sectors_srcunit_ce` (sectors x 32 / 2) | bytes moved by copy engines: `cudaMemcpy`, `.cuda()`, model loading. Each copied byte passes L2 twice, hence / 2. |
136
+ | kread | `..._srcunit_tex_op_read_lookup_miss_realtime` (x 32) | bytes GPU code read from memory (L2 misses) |
137
+ | kwrite | `..._srcunit_tex_op_write_realtime` (x 32) | bytes GPU code wrote |
138
+ | C2C | all L2 read misses + all L2 writes (x 32) | all GPU memory traffic. On GB10 all GPU memory lies behind the CPU die, so this traffic crosses NVLink C2C. |
139
+
140
+ How the counting works: every GPU request to memory passes the GPU's L2 cache. If the data is already in L2 (a hit), nothing crosses C2C and nothing is counted. If not (a miss), it is fetched over C2C and counted (kread for GPU code). Every write passes L2 and goes to memory over C2C (kwrite). Copies pass L2 twice, as a read and a write, hence copy = sectors x 32 / 2. Diagrams: [GB10 architecture](docs/GB10_ARCHITECTURE.md).
141
+
142
+ * **Device wide.** The counters see every process on the GPU. `run -- CMD` reports the GPU's traffic while CMD runs, not CMD's alone. Use `--idle` or phases for a baseline; the JSON reports raw, baseline and subtracted values separately.
143
+ * **One reader at a time.** The GPU has one sampling unit. While another profiler holds it, pravaha says "counters busy".
144
+ * **GPU side.** CPU memory traffic is not included.
145
+
146
+ ## ✅ Checked against known bytes
147
+
148
+ `pravaha verify` on an Acer GN100 and a DGX Spark (driver 580, CUDA 13.0), each check the middle of 3 runs:
149
+ ```
150
+ PASS copy host to GPU 2048.0 MiB expected 2048.0 ratio 1.0000
151
+ PASS copy GPU to host 2048.0 MiB expected 2048.0 ratio 1.0000
152
+ PASS kernel write (cudaMemset) 4096.0 MiB expected 4096.0 ratio 1.0000
153
+ PASS kernel read (GPU to GPU copy) 4095.9 MiB expected 4096.0 ratio 1.0000
154
+ ```
155
+ Samples carry the system clock; on GB10 it agrees with the GPU's sample clock within 1 microsecond. On real frameworks, observed from outside: PyTorch `.cuda()` 8 minus 4 copies of 1 GiB gives 3.9999 GiB; vLLM serving Qwen3 4B reads 7.52 GiB per generated token, against 7.49 GiB of weights. PASS means agreement for these workloads on that machine and software, not a claim about every workload.
156
+
157
+ ## 📚 Documentation
158
+
159
+ | read this | if you want to |
160
+ |---|---|
161
+ | [The whole idea](docs/THE_WHOLE_IDEA.md) | understand everything in one read: start here |
162
+ | [GB10 architecture](docs/GB10_ARCHITECTURE.md) | understand the GB10, NVLink C2C and what pravaha counts (with diagrams) |
163
+ | [Tutorial](docs/TUTORIAL.md) | learn by running: each lesson one command, with the expected output |
164
+ | [Manual](docs/MANUAL.md) | look up every command, option, column and word |
165
+ | [Developer guide](docs/DEVELOPER_GUIDE.md) | use pravaha inside your Python programs and harnesses |
166
+ | [Researcher guide](docs/RESEARCHER_GUIDE.md) | methodology, accuracy, time base, and what to report in a paper |
167
+ | [Validation record](docs/VALIDATION.md) and [test matrix](docs/TEST_MATRIX.md) | see every test, on which machine, with what result; add yours |
168
+ | [Design](docs/DESIGN.md) | the system design and its rules |
169
+ | [Contributing](CONTRIBUTING.md) | report results from your GB10, or change the code |
170
+
171
+ Examples, each with what it does, what it needs and what to expect: [examples/README.md](examples/README.md).
172
+
173
+ ## 📦 Requirements
174
+ NVIDIA GB10 system, Linux, NVIDIA driver 565 or newer with CUDA 13 (CUPTI included), `gcc` and `g++`, Python 3.8 or newer.
175
+
176
+ ## 📖 Cite
177
+ See [CITATION.cff](CITATION.cff).
178
+
179
+ ## License
180
+ MIT. Copyright (c) 2026 MANTRA Labs.
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pravaha-mem"
7
+ version = "1.0.0"
8
+ description = "Live GPU memory traffic over NVLink C2C on the NVIDIA GB10 (DGX Spark), from the GPU's L2 cache counters"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.8"
13
+ authors = [
14
+ {name = "Deepak Panigrahy", email = "deepakp@tamu.edu"},
15
+ {name = "Sirisha Kota"},
16
+ ]
17
+ maintainers = [{name = "Deepak Panigrahy", email = "deepakp@tamu.edu"}]
18
+ keywords = ["gb10", "dgx-spark", "nvlink", "nvlink-c2c", "gpu", "memory-traffic", "l2-cache",
19
+ "performance-counters", "cupti", "smmu", "energy", "llm"]
20
+ classifiers = [
21
+ "Development Status :: 5 - Production/Stable",
22
+ "Environment :: Console",
23
+ "Intended Audience :: Science/Research",
24
+ "Intended Audience :: Developers",
25
+ "Operating System :: POSIX :: Linux",
26
+ "Programming Language :: Python :: 3",
27
+ "Programming Language :: Python :: 3 :: Only",
28
+ "Topic :: System :: Monitoring",
29
+ "Topic :: System :: Hardware",
30
+ ]
31
+ dependencies = [] # standard library only
32
+
33
+ [project.optional-dependencies]
34
+ test = ["pytest"]
35
+
36
+ [project.urls]
37
+ Homepage = "https://github.com/deepakpanigrahy03/pravaha-mem"
38
+ Documentation = "https://github.com/deepakpanigrahy03/pravaha-mem/blob/main/docs/MANUAL.md"
39
+ Source = "https://github.com/deepakpanigrahy03/pravaha-mem"
40
+ Issues = "https://github.com/deepakpanigrahy03/pravaha-mem/issues"
41
+ Changelog = "https://github.com/deepakpanigrahy03/pravaha-mem/blob/main/CHANGELOG.md"
42
+
43
+ [project.scripts]
44
+ pravaha = "pravaha_mem.cli:main"
45
+
46
+ [tool.setuptools.packages.find]
47
+ where = ["python"]
48
+ include = ["pravaha_mem*"]
49
+
50
+ [tool.setuptools.package-data]
51
+ pravaha_mem = ["reader.cpp", "smmu/pravaha_pmcg.c"]
52
+
53
+ [tool.pytest.ini_options]
54
+ markers = ["gpu: needs a GB10 with pravaha installed (light work only)"]
55
+ addopts = "-m 'not gpu'"
@@ -0,0 +1,17 @@
1
+ """pravaha: live GPU memory traffic over NVLink C2C on the NVIDIA GB10.
2
+
3
+ import pravaha_mem as pv
4
+ with pv.observe() as m:
5
+ m.mark("load"); load_model()
6
+ m.mark("decode"); generate()
7
+ print(m.summary())
8
+
9
+ Values are device wide (all processes on the GPU). Command line: `pravaha --help`.
10
+ Part of pravaha-mem. MIT License. Copyright (c) 2026 MANTRA Labs.
11
+ """
12
+
13
+ __version__ = "1.0.0" # defined before the imports: submodules read it
14
+
15
+ from .observer import observe, run # noqa: E402,F401
16
+ from .status import status # noqa: E402,F401
17
+ from .verify import verify # noqa: E402,F401
@@ -0,0 +1,75 @@
1
+ """pravaha test: check the live C2C counters against programs that move known bytes.
2
+
3
+ Each check starts a separate worker process (the CUDA runtime through ctypes, so
4
+ nothing is compiled) while pravaha watches the whole GPU from outside. pravaha first
5
+ measures one second of the machine's background (the desktop and other programs),
6
+ then starts the worker, which prints when its work ran. pravaha sums the samples in
7
+ that window, subtracts the background, and compares with the bytes the worker moved.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import subprocess
13
+ import sys
14
+ import time
15
+
16
+ from .c2c_sampler import c2c
17
+
18
+ MIB = 2 ** 20
19
+
20
+ # name, worker mode, copies, MiB, measured field, tolerance (relative)
21
+ CHECKS = [
22
+ ("copy host to GPU", "h2d", 8, 256, "copy", 0.002),
23
+ ("copy GPU to host", "d2h", 8, 256, "copy", 0.002),
24
+ ("kernel write (cudaMemset)", "memset", 16, 256, "kernel_write", 0.01),
25
+ ("kernel read and write (GPU to GPU copy)", "d2d", 16, 256, "kernel_read", 0.02),
26
+ ]
27
+
28
+
29
+ def _worker(mode, n, mib):
30
+ import os
31
+ out = subprocess.run([sys.executable, "-m", "pravaha_mem.demo", mode, str(n), str(mib)],
32
+ capture_output=True, text=True, env={**os.environ, "PRAVAHA_DEMO_WINDOW": "1"})
33
+ if out.returncode:
34
+ raise RuntimeError(out.stderr.strip() or "demo failed")
35
+ w = [l.split() for l in out.stdout.splitlines() if l.startswith("WINDOW")][0]
36
+ return int(w[1]), int(w[2])
37
+
38
+
39
+ def main(json_path: str | None = None) -> int:
40
+ results, ok = [], True
41
+ print("pravaha test: does pravaha report exactly the bytes a test program moves? (about 1 minute)")
42
+ with c2c() as m:
43
+ time.sleep(2)
44
+ idle = m.total()
45
+ r = {"check": "idle machine: no copies", "measured_mib": idle["copy"] / MIB, "expected_mib": 0,
46
+ "pass": idle["copy"] < 1 * MIB}
47
+ results.append(r)
48
+ for name, mode, n, mib, field, tol in CHECKS:
49
+ exp = n * mib * MIB
50
+ tries = []
51
+ for _ in range(3): # the middle of 3 runs: a burst from the desktop cannot decide the result
52
+ with c2c() as m:
53
+ b0 = time.time_ns(); time.sleep(1.0); b1 = time.time_ns() # background first
54
+ t0, t1 = _worker(mode, n, mib)
55
+ a, b = t0 - 40_000_000, t1 + 40_000_000 # covers the edge samples, little background
56
+ q = m._sum(b0, b1)
57
+ bg = q[field] / q["seconds"] * (b - a) / 1e9 if q["seconds"] else 0.0
58
+ tries.append((m._sum(a, b)[field] - bg, bg))
59
+ tries.sort()
60
+ got, bg = tries[1]
61
+ results.append({"check": name, "measured_mib": got / MIB, "expected_mib": exp / MIB,
62
+ "ratio": got / exp, "pass": abs(got / exp - 1) <= tol, "tolerance": tol,
63
+ "runs_mib": [round(t[0] / MIB, 1) for t in tries], "background_mib": bg / MIB})
64
+ for r in results:
65
+ ok &= r["pass"]
66
+ extra = f" ratio {r['ratio']:.4f} (middle of 3 runs)" if "ratio" in r else ""
67
+ print(f" {'PASS' if r['pass'] else 'FAIL'} {r['check']:42} {r['measured_mib']:10.1f} MiB"
68
+ f" expected {r['expected_mib']:8.1f}{extra}")
69
+ print("all checks passed: pravaha measures this GPU correctly" if ok else
70
+ "some checks failed. pravaha sees the whole GPU, so busy windows (videos, browsers) add traffic.\n"
71
+ "Close them and run again; if it still fails, please report the output.")
72
+ if json_path:
73
+ with open(json_path, "w") as fh:
74
+ json.dump(results, fh, indent=1)
75
+ return 0 if ok else 1