@@ -134,7 +134,7 @@ def store_output_file(output_filename: str, results, tune_params, objective="tim
134134 version , _ = output_file_schema ("results" )
135135 output_json = dict (results = output_data , schema_version = version )
136136 with open (output_filenamepath , "w+" ) as fh :
137- json .dump (output_json , fh )
137+ json .dump (output_json , fh , cls = util . NpEncoder )
138138
139139
140140def get_dependencies (package = "kernel_tuner" ):
@@ -185,41 +185,48 @@ def store_metadata_file(metadata_filename: str):
185185 metadata_filenamepath = Path (filename_ensure_json_extension (metadata_filename ))
186186 make_filenamepath (metadata_filenamepath )
187187 metadata = {}
188+ supported_operating_systems = ["linux" , "win32" , "darwin" ]
188189
189- # differentiate between OSes, possible values: https://docs.python.org/3/library/sys.html#sys.platform
190- if platform == "linux" :
191- os_string = "Linux"
192- hardware_description_out = subprocess .run (["lshw" , "-json" ], capture_output = True )
193- elif platform == "win32" :
194- os_string = "Windows"
195- raise NotImplementedError (f"Hardware specification not yet implemented for Windows" )
196- elif platform == "darwin" :
197- os_string = "Mac"
198- hardware_description_out = subprocess .run (
199- [
200- "system_profiler" ,
201- "-json" ,
202- "-detailLevel" ,
203- "mini" ,
204- "SPSoftwareDataType" ,
205- "SPHardwareDataType" ,
206- "SPiBridgeDataType" ,
207- "SPPCIDataType" ,
208- "SPMemoryDataType" ,
209- "SPNVMeDataType" ,
210- ],
211- capture_output = True ,
212- )
213- else :
190+ if all (platform != supported for supported in supported_operating_systems ):
214191 raise ValueError (f"Platform { platform } not supported for metadata collection" )
215192
216- # process the hardware description output
217- hardware_description_string = hardware_description_out .stdout .decode ("utf-8" ).strip ()
218- if hardware_description_string [0 ] == "{" and hardware_description_string [- 1 ] == "}" :
219- # sometimes lshw outputs a list of length 1, sometimes just as a dict, schema wants a list
220- hardware_description_string = "[" + hardware_description_string + "]"
221- metadata ["hardware" ] = dict (hardware_description = json .loads (hardware_description_string ))
222- metadata ["operating_system" ] = os_string
193+ try :
194+ # differentiate between OSes, possible values: https://docs.python.org/3/library/sys.html#sys.platform
195+ if platform == "linux" :
196+ os_string = "Linux"
197+ hardware_description_out = subprocess .run (["lshw" , "-json" ], capture_output = True )
198+ elif platform == "win32" :
199+ os_string = "Windows"
200+ raise NotImplementedError ("Hardware specification not yet implemented for Windows" )
201+ elif platform == "darwin" :
202+ os_string = "Mac"
203+ hardware_description_out = subprocess .run (
204+ [
205+ "system_profiler" ,
206+ "-json" ,
207+ "-detailLevel" ,
208+ "mini" ,
209+ "SPSoftwareDataType" ,
210+ "SPHardwareDataType" ,
211+ "SPiBridgeDataType" ,
212+ "SPPCIDataType" ,
213+ "SPMemoryDataType" ,
214+ "SPNVMeDataType" ,
215+ ],
216+ capture_output = True ,
217+ )
218+ else :
219+ raise ValueError ("This code is supposed to be unreachable, the supported platform check has failed" )
220+
221+ # process the hardware description output
222+ hardware_description_string = hardware_description_out .stdout .decode ("utf-8" ).strip ()
223+ if hardware_description_string [0 ] == "{" and hardware_description_string [- 1 ] == "}" :
224+ # sometimes lshw outputs a list of length 1, sometimes just as a dict, schema wants a list
225+ hardware_description_string = "[" + hardware_description_string + "]"
226+ metadata ["hardware" ] = dict (hardware_description = json .loads (hardware_description_string ))
227+ metadata ["operating_system" ] = os_string
228+ except :
229+ metadata ["hardware" ] = "error retrieving hardware description"
223230
224231 # attempts to use nvidia-smi or rocm-smi if present
225232 device_query = {}
0 commit comments