tritonparse 0.3.2.dev20251210071601__py3-none-any.whl

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.

Potentially problematic release.


This version of tritonparse might be problematic. Click here for more details.

Files changed (62) hide show
  1. tritonparse/__init__.py +0 -0
  2. tritonparse/__main__.py +7 -0
  3. tritonparse/cli.py +110 -0
  4. tritonparse/common.py +409 -0
  5. tritonparse/context_manager.py +64 -0
  6. tritonparse/event_diff.py +122 -0
  7. tritonparse/extract_source_mappings.py +49 -0
  8. tritonparse/info/__init__.py +30 -0
  9. tritonparse/info/cli.py +121 -0
  10. tritonparse/info/kernel_query.py +209 -0
  11. tritonparse/info/parse_helper.py +70 -0
  12. tritonparse/ir_analysis.py +427 -0
  13. tritonparse/ir_parser.py +365 -0
  14. tritonparse/mapper.py +102 -0
  15. tritonparse/reproducer/__init__.py +0 -0
  16. tritonparse/reproducer/ast_analyzer.py +636 -0
  17. tritonparse/reproducer/cli.py +72 -0
  18. tritonparse/reproducer/consolidated_result.py +52 -0
  19. tritonparse/reproducer/function_extractor.py +228 -0
  20. tritonparse/reproducer/import_info.py +25 -0
  21. tritonparse/reproducer/import_parser.py +178 -0
  22. tritonparse/reproducer/import_resolver.py +151 -0
  23. tritonparse/reproducer/ingestion/ndjson.py +237 -0
  24. tritonparse/reproducer/multi_file_analyzer.py +824 -0
  25. tritonparse/reproducer/orchestrator.py +110 -0
  26. tritonparse/reproducer/placeholder_replacer.py +335 -0
  27. tritonparse/reproducer/templates/__init__.py +0 -0
  28. tritonparse/reproducer/templates/example.py +38 -0
  29. tritonparse/reproducer/templates/loader.py +59 -0
  30. tritonparse/reproducer/templates/tritonbench.py +106 -0
  31. tritonparse/reproducer/templates/utils.py +48 -0
  32. tritonparse/reproducer/tests/__init__.py +0 -0
  33. tritonparse/reproducer/tests/artifacts/__init__.py +5 -0
  34. tritonparse/reproducer/tests/artifacts/triton_fused_kernel.py +65 -0
  35. tritonparse/reproducer/tests/artifacts/triton_preprocess.py +16 -0
  36. tritonparse/reproducer/tests/artifacts/triton_utils.py +14 -0
  37. tritonparse/reproducer/tests/test_import_parser.py +164 -0
  38. tritonparse/reproducer/tests/test_import_resolver.py +88 -0
  39. tritonparse/reproducer/tests/test_multi_file_analyzer.py +118 -0
  40. tritonparse/reproducer/types.py +20 -0
  41. tritonparse/reproducer/utils.py +580 -0
  42. tritonparse/shared_vars.py +12 -0
  43. tritonparse/source_type.py +56 -0
  44. tritonparse/sourcemap_utils.py +96 -0
  45. tritonparse/structured_logging.py +1634 -0
  46. tritonparse/tools/__init__.py +0 -0
  47. tritonparse/tools/decompress_bin_ndjson.py +120 -0
  48. tritonparse/tools/disasm.py +81 -0
  49. tritonparse/tools/extract_irs.py +244 -0
  50. tritonparse/tools/format_fix.py +151 -0
  51. tritonparse/tools/load_tensor.py +76 -0
  52. tritonparse/tools/prettify_ndjson.py +334 -0
  53. tritonparse/tools/readme.md +37 -0
  54. tritonparse/tp_logger.py +9 -0
  55. tritonparse/trace_processor.py +367 -0
  56. tritonparse/utils.py +155 -0
  57. tritonparse-0.3.2.dev20251210071601.dist-info/METADATA +195 -0
  58. tritonparse-0.3.2.dev20251210071601.dist-info/RECORD +62 -0
  59. tritonparse-0.3.2.dev20251210071601.dist-info/WHEEL +5 -0
  60. tritonparse-0.3.2.dev20251210071601.dist-info/entry_points.txt +2 -0
  61. tritonparse-0.3.2.dev20251210071601.dist-info/licenses/LICENSE +29 -0
  62. tritonparse-0.3.2.dev20251210071601.dist-info/top_level.txt +1 -0
@@ -0,0 +1,96 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import logging
4
+ from typing import Any, Dict, List
5
+
6
+ logger = logging.getLogger("SourceMapping")
7
+
8
+
9
+ def get_file_extension(filename: str) -> str:
10
+ """
11
+ Get the file extension from a given filename or return the filename itself if it has no extension.
12
+
13
+ Args:
14
+ filename (str): The filename or file extension.
15
+
16
+ Returns:
17
+ str: The file extension or the filename itself if no extension is present.
18
+ """
19
+ # Split the filename by '.' and return the last part if it exists
20
+ parts = filename.split(".")
21
+ return parts[-1] if len(parts) > 1 else filename
22
+
23
+
24
+ def _flatten_dict(
25
+ d: Dict[str, Any], parent_key: str = "", sep: str = "."
26
+ ) -> Dict[str, Any]:
27
+ """
28
+ Flattens a nested dictionary.
29
+ """
30
+ items = []
31
+ for k, v in d.items():
32
+ new_key = parent_key + sep + k if parent_key else k
33
+ if isinstance(v, dict):
34
+ items.extend(_flatten_dict(v, new_key, sep=sep).items())
35
+ else:
36
+ items.append((new_key, v))
37
+ return dict(items)
38
+
39
+
40
+ def _unflatten_dict(d: Dict[str, Any], sep: str = ".") -> Dict[str, Any]:
41
+ """
42
+ Unflattens a dictionary with delimited keys.
43
+ """
44
+ result = {}
45
+ for key, value in d.items():
46
+ parts = key.split(sep)
47
+ d_ref = result
48
+ for part in parts[:-1]:
49
+ if part not in d_ref:
50
+ d_ref[part] = {}
51
+ d_ref = d_ref[part]
52
+ d_ref[parts[-1]] = value
53
+ return result
54
+
55
+
56
+ def _to_ranges(indices: List[int]) -> List[Dict[str, int]]:
57
+ """
58
+ Converts a sorted list of indices into a list of continuous ranges.
59
+ e.g., [0, 1, 2, 5, 6, 8] -> [{'start': 0, 'end': 2}, {'start': 5, 'end': 6}, {'start': 8, 'end': 8}]
60
+ """
61
+ if not indices:
62
+ return []
63
+
64
+ indices = sorted(indices)
65
+ ranges = []
66
+ start = indices[0]
67
+ end = indices[0]
68
+
69
+ for i in range(1, len(indices)):
70
+ if indices[i] == end + 1:
71
+ end = indices[i]
72
+ else:
73
+ ranges.append({"start": start, "end": end})
74
+ start = end = indices[i]
75
+
76
+ ranges.append({"start": start, "end": end})
77
+ return ranges
78
+
79
+
80
+ def load_ir_contents(
81
+ key: str,
82
+ file_content: dict[str, str],
83
+ file_path: dict[str, str],
84
+ ):
85
+ if not key:
86
+ return {}
87
+ logger.debug(f"Processing {key}")
88
+ ir_content = file_content.get(key, None)
89
+ if not ir_content:
90
+ ir_file_path = file_path.get(key, None)
91
+ if not ir_file_path:
92
+ logger.warning(f"No content found for {key}")
93
+ return {}
94
+ with open(ir_file_path, "r") as f:
95
+ ir_content = f.read()
96
+ return ir_content