()
| 14 | |
| 15 | @app.function(gpu="B200", image=nsys_image, volumes=make_volumes()) |
| 16 | def nsys_test(): |
| 17 | os.makedirs(REPORT_DIR, exist_ok=True) |
| 18 | |
| 19 | script = """ |
| 20 | import torch |
| 21 | |
| 22 | a = torch.randn(1024, 1024, device="cuda", dtype=torch.bfloat16) |
| 23 | b = torch.randn(1024, 1024, device="cuda", dtype=torch.bfloat16) |
| 24 | torch.cuda.synchronize() |
| 25 | c = a + b |
| 26 | torch.cuda.synchronize() |
| 27 | """ |
| 28 | with open("/tmp/nsys_kernel.py", "w") as f: |
| 29 | f.write(script) |
| 30 | |
| 31 | result = subprocess.run( |
| 32 | [ |
| 33 | "nsys", |
| 34 | "profile", |
| 35 | "-o", |
| 36 | REPORT_PATH, |
| 37 | "--force-overwrite=true", |
| 38 | "python", |
| 39 | "/tmp/nsys_kernel.py", |
| 40 | ], |
| 41 | capture_output=True, |
| 42 | text=True, |
| 43 | ) |
| 44 | print("=== stdout ===") |
| 45 | print(result.stdout[-3000:] if len(result.stdout) > 3000 else result.stdout) |
| 46 | print("=== stderr ===") |
| 47 | print(result.stderr[-3000:] if len(result.stderr) > 3000 else result.stderr) |
| 48 | print(f"=== returncode: {result.returncode} ===") |
| 49 | |
| 50 | report_file = f"{REPORT_PATH}.nsys-rep" |
| 51 | if os.path.exists(report_file): |
| 52 | size_mb = os.path.getsize(report_file) / (1024 * 1024) |
| 53 | print(f"Report saved: {report_file} ({size_mb:.1f} MB)") |
| 54 | from modal import Volume |
| 55 | |
| 56 | Volume.from_name("fused-mm-sample").commit() |
| 57 | else: |
| 58 | print(f"Report file not found at {report_file}") |
| 59 | |
| 60 | |
| 61 | @app.local_entrypoint() |
nothing calls this directly
no outgoing calls
no test coverage detected