@@ -49,7 +49,7 @@ def compilation_cache_key(compilation) -> str:
4949 "backend_options" : request .backend_options ,
5050 "pipeline" : request .pipeline ,
5151 "pass_options" : request .pass_options ,
52- "architecture" : _architecture (),
52+ "architecture" : _architecture (compilation ),
5353 "versions" : _compiler_versions (),
5454 }
5555 )
@@ -191,13 +191,51 @@ def _compiler_versions() -> Mapping[str, str]:
191191 return result
192192
193193
194- def _architecture () -> Mapping [str , str | None ]:
195- return {
194+ def _architecture (compilation ) -> Mapping [str , Any ]:
195+ backend = compilation .artifact .backend .value
196+ backend_options = dict (compilation .request .backend_options or {})
197+ architecture = {
196198 "machine" : platform .machine (),
197199 "cuda_arch" : os .environ .get ("TORCH_CUDA_ARCH_LIST" ),
198200 "cuda_visible_devices" : os .environ .get ("CUDA_VISIBLE_DEVICES" ),
199201 }
200202
203+ if backend == "cuda" :
204+ target = str (backend_options .get ("arch" , "native" ))
205+ architecture ["cuda_target" ] = target
206+
207+ if target != "native" :
208+ return architecture
209+
210+ if backend in {"cuda" , "tilelang" , "triton" }:
211+ architecture .update (_runtime_cuda_architecture ())
212+ return architecture
213+
214+
215+ def _runtime_cuda_architecture () -> Mapping [str , Any ]:
216+ import torch
217+
218+ if not torch .cuda .is_available ():
219+ return {
220+ "cuda_current_capability" : None ,
221+ "cuda_visible_capabilities" : (),
222+ }
223+
224+ def capability (device : int ) -> str :
225+ major , minor = torch .cuda .get_device_capability (device )
226+
227+ return f"sm_{ major } { minor } "
228+
229+ current = capability (torch .cuda .current_device ())
230+ visible = tuple (
231+ dict .fromkeys (capability (device ) for device in range (torch .cuda .device_count ()))
232+ )
233+
234+ return {
235+ "cuda_current_capability" : current ,
236+ "cuda_visible_capabilities" : visible ,
237+ }
238+
201239
202240def _json_value (value : Any ) -> Any :
203241 if value is None or isinstance (value , (bool , int , float , str )):
0 commit comments