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.
- tritonparse/__init__.py +0 -0
- tritonparse/__main__.py +7 -0
- tritonparse/cli.py +110 -0
- tritonparse/common.py +409 -0
- tritonparse/context_manager.py +64 -0
- tritonparse/event_diff.py +122 -0
- tritonparse/extract_source_mappings.py +49 -0
- tritonparse/info/__init__.py +30 -0
- tritonparse/info/cli.py +121 -0
- tritonparse/info/kernel_query.py +209 -0
- tritonparse/info/parse_helper.py +70 -0
- tritonparse/ir_analysis.py +427 -0
- tritonparse/ir_parser.py +365 -0
- tritonparse/mapper.py +102 -0
- tritonparse/reproducer/__init__.py +0 -0
- tritonparse/reproducer/ast_analyzer.py +636 -0
- tritonparse/reproducer/cli.py +72 -0
- tritonparse/reproducer/consolidated_result.py +52 -0
- tritonparse/reproducer/function_extractor.py +228 -0
- tritonparse/reproducer/import_info.py +25 -0
- tritonparse/reproducer/import_parser.py +178 -0
- tritonparse/reproducer/import_resolver.py +151 -0
- tritonparse/reproducer/ingestion/ndjson.py +237 -0
- tritonparse/reproducer/multi_file_analyzer.py +824 -0
- tritonparse/reproducer/orchestrator.py +110 -0
- tritonparse/reproducer/placeholder_replacer.py +335 -0
- tritonparse/reproducer/templates/__init__.py +0 -0
- tritonparse/reproducer/templates/example.py +38 -0
- tritonparse/reproducer/templates/loader.py +59 -0
- tritonparse/reproducer/templates/tritonbench.py +106 -0
- tritonparse/reproducer/templates/utils.py +48 -0
- tritonparse/reproducer/tests/__init__.py +0 -0
- tritonparse/reproducer/tests/artifacts/__init__.py +5 -0
- tritonparse/reproducer/tests/artifacts/triton_fused_kernel.py +65 -0
- tritonparse/reproducer/tests/artifacts/triton_preprocess.py +16 -0
- tritonparse/reproducer/tests/artifacts/triton_utils.py +14 -0
- tritonparse/reproducer/tests/test_import_parser.py +164 -0
- tritonparse/reproducer/tests/test_import_resolver.py +88 -0
- tritonparse/reproducer/tests/test_multi_file_analyzer.py +118 -0
- tritonparse/reproducer/types.py +20 -0
- tritonparse/reproducer/utils.py +580 -0
- tritonparse/shared_vars.py +12 -0
- tritonparse/source_type.py +56 -0
- tritonparse/sourcemap_utils.py +96 -0
- tritonparse/structured_logging.py +1634 -0
- tritonparse/tools/__init__.py +0 -0
- tritonparse/tools/decompress_bin_ndjson.py +120 -0
- tritonparse/tools/disasm.py +81 -0
- tritonparse/tools/extract_irs.py +244 -0
- tritonparse/tools/format_fix.py +151 -0
- tritonparse/tools/load_tensor.py +76 -0
- tritonparse/tools/prettify_ndjson.py +334 -0
- tritonparse/tools/readme.md +37 -0
- tritonparse/tp_logger.py +9 -0
- tritonparse/trace_processor.py +367 -0
- tritonparse/utils.py +155 -0
- tritonparse-0.3.2.dev20251210071601.dist-info/METADATA +195 -0
- tritonparse-0.3.2.dev20251210071601.dist-info/RECORD +62 -0
- tritonparse-0.3.2.dev20251210071601.dist-info/WHEEL +5 -0
- tritonparse-0.3.2.dev20251210071601.dist-info/entry_points.txt +2 -0
- tritonparse-0.3.2.dev20251210071601.dist-info/licenses/LICENSE +29 -0
- 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
|