-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path00_minimal.py
More file actions
46 lines (35 loc) · 1.07 KB
/
00_minimal.py
File metadata and controls
46 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""
Example 0: Minimal Example
===========================
This is the absolute minimal example to get started with Nsight Python.
It shows the core concepts:
- Using `@nsight.analyze.kernel` to profile a function
- Using `with nsight.annotate()` to mark a kernel of interest
"""
import torch
import nsight
@nsight.analyze.kernel
def benchmark_matmul(n: int) -> torch.Tensor:
"""
The simplest possible benchmark.
We create two matrices and multiply them.
"""
# Create two NxN matrices on GPU
a = torch.randn(n, n, device="cuda")
b = torch.randn(n, n, device="cuda")
# Mark the operation we want to profile
with nsight.annotate("matmul"):
c = a @ b
def main() -> None:
# Run the benchmark
result = benchmark_matmul(1024)
print(
result.to_dataframe()[
["Annotation", "n", "Metric", "AvgValue", "NumRuns", "GPU"]
]
)
print("Benchmark complete!")
if __name__ == "__main__":
main()