1+ import logging
2+ import os
3+ import sys
4+ import json
5+ import platform
6+
7+ from deepview_profile .analysis .runner import analyze_project
8+ from deepview_profile .nvml import NVML
9+ from deepview_profile .utils import release_memory , next_message_to_dict , files_encoded_unique
10+
11+ from deepview_profile .initialization import (
12+ check_skyline_preconditions ,
13+ initialize_skyline ,
14+ )
15+ from deepview_profile .error_printing import print_analysis_error
16+
17+ logger = logging .getLogger (__name__ )
18+
19+ def register_command (subparsers ):
20+ parser = subparsers .add_parser (
21+ "analysis" ,
22+ help = "Generate usage report for various analysis." ,
23+ )
24+ parser .add_argument (
25+ "entry_point" ,
26+ help = "The entry point file in this project that contains the DeepView "
27+ "provider functions."
28+ )
29+ parser .add_argument (
30+ "--all" ,
31+ action = "store_true" ,
32+ help = "The complete analysis of all methods"
33+ )
34+ parser .add_argument (
35+ "-breakdown" , "--measure-breakdown" ,
36+ action = "store_true" ,
37+ help = "Adds breakdown data to results"
38+ )
39+ parser .add_argument (
40+ "-throughput" , "--measure-throughput" ,
41+ action = "store_true" ,
42+ help = "Adds throughput data to results"
43+ )
44+ parser .add_argument (
45+ "-predict" , "--habitat-predict" ,
46+ action = "store_true" ,
47+ help = "Adds habitat data prediction to results"
48+ )
49+ parser .add_argument (
50+ "-utilization" , "--measure-utilization" ,
51+ action = "store_true" ,
52+ help = "Adds utilization data to results"
53+ )
54+ parser .add_argument (
55+ "-energy" , "--energy-compute" ,
56+ action = "store_true" ,
57+ help = "Adds energy use to results"
58+ )
59+ parser .add_argument (
60+ "-o" , "--output" ,
61+ help = "The location where the complete report should be stored" ,
62+ required = True
63+ )
64+ parser .add_argument (
65+ "--log-file" ,
66+ help = "The location of the log file" ,
67+ )
68+ parser .add_argument (
69+ "--exclude-source" ,
70+ action = "store_true" ,
71+ help = "Allows not adding encodedFiles section"
72+ )
73+ parser .add_argument ("--debug" , action = "store_true" , help = "Log debug messages." )
74+ parser .set_defaults (func = main )
75+
76+ def measure_breakdown (session , nvml ):
77+ print ("analysis: running measure_breakdown()" )
78+ yield session .measure_breakdown (nvml )
79+ release_memory ()
80+
81+ def measure_throughput (session ):
82+ print ("analysis: running measure_throughput()" )
83+ yield session .measure_throughput ()
84+ release_memory ()
85+
86+ def habitat_predict (session ):
87+ print ("analysis: running deepview_predict()" )
88+ yield session .habitat_predict ()
89+ release_memory ()
90+
91+ def measure_utilization (session ):
92+ print ("analysis: running measure_utilization()" )
93+ yield session .measure_utilization ()
94+ release_memory ()
95+
96+ def energy_compute (session ):
97+ print ("analysis: running energy_compute()" )
98+ yield session .energy_compute ()
99+ release_memory ()
100+
101+ def hardware_information (nvml ):
102+
103+ hardware_info = {
104+ 'hostname' : platform .node (),
105+ 'os' : " " .join (list (platform .uname ())),
106+ 'gpus' : nvml .get_device_names ()
107+ }
108+ return hardware_info
109+
110+ def actual_main (args ):
111+ from deepview_profile .analysis .session import AnalysisSession
112+ from deepview_profile .exceptions import AnalysisError
113+
114+ if os .path .exists (args .output ):
115+ print (
116+ "ERROR: The specified output file already exists." ,
117+ file = sys .stderr ,
118+ )
119+ sys .exit (1 )
120+
121+ try :
122+ project_root = os .getcwd ()
123+ data = {
124+ "analysisState" : {
125+ "message_type" : "analysis" ,
126+ "project_root" : project_root ,
127+ "project_entry_point" : args .entry_point ,
128+ "hardware_info" : {},
129+ "throughput" : {},
130+ "breakdown" : {},
131+ "habitat" : {},
132+ "additionalProviders" : "" ,
133+ "energy" : {},
134+ "utilization" : {}
135+ },
136+ "epochs" : 50 ,
137+ "iterPerEpoch" : 1000 ,
138+ "encodedFiles" : []
139+ }
140+
141+ session = AnalysisSession .new_from (project_root , args .entry_point )
142+ release_memory ()
143+
144+ is_return_all = args .all
145+
146+ with NVML () as nvml :
147+ data ['analysisState' ]['hardware_info' ] = hardware_information (nvml )
148+ if args .measure_breakdown or is_return_all :
149+ data ['analysisState' ]['breakdown' ] = next_message_to_dict (measure_breakdown (session , nvml ))
150+
151+ operation_tree = data ['analysisState' ]['breakdown' ]['operationTree' ]
152+ if not args .exclude_source and operation_tree is not None :
153+ data ['encodedFiles' ] = files_encoded_unique (operation_tree )
154+
155+ if args .measure_throughput or is_return_all :
156+ data ['analysisState' ]['throughput' ] = next_message_to_dict (measure_throughput (session ))
157+
158+ if args .habitat_predict or is_return_all :
159+ data ['analysisState' ]['habitat' ] = next_message_to_dict (habitat_predict (session ))
160+
161+ if args .measure_utilization or is_return_all :
162+ data ['analysisState' ]['utilization' ] = next_message_to_dict (measure_utilization (session ))
163+
164+ if args .energy_compute or is_return_all :
165+ data ['analysisState' ]['energy' ] = next_message_to_dict (energy_compute (session ))
166+
167+ with open (args .output , "w" ) as json_file :
168+ json .dump (data , json_file , indent = 4 )
169+
170+ except AnalysisError as ex :
171+ print_analysis_error (ex )
172+ sys .exit (1 )
173+
174+ def main (args ):
175+ check_skyline_preconditions (args )
176+ initialize_skyline (args )
177+ actual_main (args )
0 commit comments