Parses the nvtx_gpu_proj_trace JSON generated by NSYS and returns a dictionary keyed by process_id, thread_id and range_id. The values are various fields important to the benchmarking process. :param json_path: Full path to the nvtx_gpu_proj_trace.json file.
(json_path)
| 144 | |
| 145 | |
| 146 | def parse_nvtx_gpu_proj_trace_json(json_path): |
| 147 | """ |
| 148 | Parses the nvtx_gpu_proj_trace JSON generated by NSYS and returns a dictionary |
| 149 | keyed by process_id, thread_id and range_id. The values are various fields |
| 150 | important to the benchmarking process. |
| 151 | :param json_path: Full path to the nvtx_gpu_proj_trace.json file. |
| 152 | """ |
| 153 | |
| 154 | # |
| 155 | # The nvtx_gpu_proj_trace JSON has the following structure. It is a list of |
| 156 | # dictionaries. |
| 157 | # e.g. |
| 158 | # [ { |
| 159 | # "Projected Start (ns)": 2372801266, |
| 160 | # "Projected Duration (ns)" : 13528369268, |
| 161 | # ... |
| 162 | # }, |
| 163 | # ... |
| 164 | # ] |
| 165 | # |
| 166 | # We will store the parsed data in the range_info dictionary. The overall |
| 167 | # structure of the dictionary is: |
| 168 | # range_info = { |
| 169 | # process_id : { |
| 170 | # thread_id : { |
| 171 | # range_id : NvtxRange(flat_name, parent_range_id, cpu_duration_ms, gpu_duration_ms) |
| 172 | # } |
| 173 | # } |
| 174 | # } |
| 175 | # |
| 176 | # NOTE: Even though this report returns the cpu_duration_ms and gpu_duration_ms, it will |
| 177 | # only do so for operations which had gpu_duration_ms > 0. For pure CPU operations, |
| 178 | # this report will not even return those ranges. That is the reason why we need to |
| 179 | # query the pushpop_trace report. |
| 180 | # |
| 181 | range_info = {} |
| 182 | |
| 183 | # Check if the file was empty or not. Empty file means no GPU ops were recorded. |
| 184 | if os.stat(json_path).st_size == 0: |
| 185 | return range_info |
| 186 | |
| 187 | # Read the JSON. |
| 188 | with open(json_path, "r") as f: |
| 189 | json_data = json.loads(f.read()) |
| 190 | |
| 191 | for row in json_data: |
| 192 | # Grab the necessary values from the JSON file. |
| 193 | range_id = row["RangeId"] |
| 194 | |
| 195 | if not range_id or range_id == "None": |
| 196 | continue |
| 197 | |
| 198 | flat_name = row["Name"] |
| 199 | cpu_start_ns = float(row["Orig Start (ns)"]) |
| 200 | cpu_duration_ns = float(row["Orig Duration (ns)"]) |
| 201 | cpu_end_ns = cpu_start_ns + cpu_duration_ns |
| 202 | |
| 203 | gpu_start_ns = float(row["Projected Start (ns)"]) |
no test coverage detected