MCPcopy Create free account
hub / github.com/compiler-explorer/compiler-explorer / put

Method put

etc/scripts/triton_wrapper.py:82–122  ·  view source on GitHub ↗
(self, data, filename, binary=True)

Source from the content-addressed store, hash-verified

80 return self.files.get(filename, None)
81
82 def put(self, data, filename, binary=True) -> str:
83 name = Path(filename).stem
84 suffix = Path(filename).suffix
85 binary = isinstance(data, bytes)
86 if not binary:
87 data = str(data)
88
89 # Write the final file to the output file, so that we can view it in the default assembly view.
90 if suffix in (".ptx", ".amdgcn"):
91 with open(MockCacheManager.output_file, "a") as f:
92 f.write(data)
93 f.write("\n\n")
94
95 # Write intermediate files to the output file, so that we can see them in the Device View.
96 self.stage += 1
97 if suffix == ".json":
98 path = MockCacheManager.output_file.parent / filename
99 with open(path, "w") as fout:
100 json.dump(json.loads(data), fout, indent=2)
101 else:
102 path = (
103 MockCacheManager.output_file.parent
104 / f"{name} [stage {self.stage}]{suffix}"
105 )
106 if not binary:
107 with open(path, "w") as fout:
108 fout.write(data)
109 elif suffix == ".cubin":
110 try:
111 # The try-catch is needed because `disasm` was broken in Triton v3.0.0 and v3.1.0. See
112 # https://github.com/triton-lang/triton/commit/f424f656b3528c47d8c48126cdccafca29e536ae
113 from triton.tools import disasm
114
115 with open(path.with_suffix(".sass"), "w") as fout:
116 fout.write(disasm.get_sass(data))
117 except Exception:
118 pass
119
120 # Write the file to the "cache"
121 self.files[filename] = data
122 return filename
123
124 def get_group(self, filename: str) -> Optional[Dict[str, str]]:
125 self.groups.get(filename, None)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected