# Profiling

Depending whether the system has NVIDIA or AMD hardware, different profilers are used. For NVIDIA systems, we use the `nsys` profiler, and for AMD systems we use `rocprof`. How to use both is described in more detail below.

## nsys

Nsight systems is a profiler that can be ran through the `nsys` command. In order to profile GPU code and collect statistics, you can run the following line:

```bash
nsys profile -t cuda --stats=true <application>
```

This will generate the result files, including the `report1.nsys-rep` file. This file contains the timelines, which can be visualized through the nsys UI, which can be launched with `nsys-ui` on your own machine.

## rocprof

Rocprof is a CLI profiler, which allows for collecting hardware counters and making traces. Hardware counters are specified through the input file with the `-i` option. Traces are made with the `--hip-trace`, `--hsa-trace`, and `--sys-trace` flags. An example execution is:

```bash
rocprof -i rocprof_counters.txt --hip-trace --stats -o results.csv"
```

This will generate the result files, including the `results.json` file. This file contains the timelines, which can be visualized through `Perfetto`, which can be reached at [ui.perfetto.dev](https://www.ui.perfetto.dev).
