@@ -22,6 +22,18 @@ public class MinerRunner : IRunner
2222 [ Dependency ]
2323 public MasterConfigurationModel MasterConfigurationModel { get ; set ; }
2424
25+ private bool HasSolution
26+ =>
27+ MasterConfigurationModel . SolutionProfiles . ContainsKey (
28+ RunConfigurationModel . ActiveSolutionConfiguration ?? string . Empty ) ;
29+
30+ private bool HasWorkload
31+ =>
32+ MasterConfigurationModel . WorkloadProfiles . ContainsKey (
33+ RunConfigurationModel . ActiveWorkloadConfiguration ?? string . Empty ) ;
34+
35+ private bool CanRun => HasSolution && HasWorkload ;
36+
2537 public void Run ( )
2638 {
2739 if ( MasterConfigurationModel == null )
@@ -30,73 +42,140 @@ public void Run()
3042 return ;
3143 }
3244
33- DoRun ( ) ;
45+ //TODO: refactor
46+ while ( true )
47+ {
48+ Console . Clear ( ) ;
49+ Console . WriteLine ( @"Active solution: {0}" , HasSolution ? RunConfigurationModel . ActiveSolutionConfiguration : "<UNKNOWN>" ) ;
50+ Console . WriteLine ( @"Active workload: {0}" , HasWorkload ? RunConfigurationModel . ActiveWorkloadConfiguration : "<UNKNOWN>" ) ;
51+ Console . WriteLine ( ) ;
52+ Console . WriteLine ( @"What would you like to do?" ) ;
53+ if ( CanRun ) Console . WriteLine ( @"0. Run/restart miners" ) ;
54+ Console . WriteLine ( @"1. Exit" ) ;
55+ Console . WriteLine ( @"2. Exit & terminate miners" ) ;
56+ Console . WriteLine ( @"3. Change solution" ) ;
57+ Console . WriteLine ( @"4. Change workload" ) ;
58+ Console . WriteLine ( ) ;
59+
60+ Console . Write ( @"Select: " ) ;
61+ int index ;
62+ if ( ! int . TryParse ( Console . ReadLine ( ) , out index ) || index < ( CanRun ? 0 : 1 ) || index > 5 ) continue ;
63+
64+ Console . Clear ( ) ;
65+ switch ( ( UserAction ) index )
66+ {
67+ case UserAction . Run :
68+ DoRun ( ) ;
69+ return ;
70+ case UserAction . Exit :
71+ Environment . Exit ( 0 ) ;
72+ break ;
73+ case UserAction . ExitTerminate :
74+ KillMiners ( ) ;
75+ Environment . Exit ( 0 ) ;
76+ break ;
77+ case UserAction . ChangeSolution :
78+ SelectSolution ( ) ;
79+ break ;
80+ case UserAction . ChangeWorkload :
81+ SelectWorkload ( ) ;
82+ break ;
83+ default :
84+ throw new ArgumentOutOfRangeException ( ) ;
85+ }
86+ }
87+ }
88+
89+ private enum UserAction
90+ {
91+ Run ,
92+ Exit ,
93+ ExitTerminate ,
94+ ChangeSolution ,
95+ ChangeWorkload
96+ }
97+
98+ private class UtilizedHardware
99+ {
100+ public HardwareEntry Hardware { get ; set ; }
101+ public string Profile { get ; set ; }
34102 }
35103
36104 private void DoRun ( )
37105 {
38- var activeSolution = GetActiveSolution ( ) ;
39106 KillMiners ( ) ;
40107
41- var solution = MasterConfigurationModel . SolutionConfiguration . SolutionProfiles . GetValue ( activeSolution ) ;
108+ var solution = MasterConfigurationModel . SolutionProfiles . GetValue ( RunConfigurationModel . ActiveSolutionConfiguration ) ;
109+ var workload = MasterConfigurationModel . WorkloadProfiles . GetValue ( RunConfigurationModel . ActiveWorkloadConfiguration ) ;
110+
111+ var i = 0 ;
42112 foreach ( var instances in solution )
43113 {
44- var outputPools = GetOutputPools ( instances ) ;
114+ i ++ ;
115+ var outputPools = GetOutputPools ( instances . Pools ) ;
45116
46117 if ( outputPools . Count == 0 )
47118 {
48- Console . WriteLine ( @"Solution does not contain any pool bindings." ) ;
119+ Console . WriteLine ( @"Instance {0}.{1} does not contain any pool bindings." , RunConfigurationModel . ActiveSolutionConfiguration , i ) ;
49120 continue ;
50121 }
51122
52123 var configArgument = GetConfigurationArgument ( outputPools ) ;
53-
54- foreach ( var instance in instances . Value )
124+ var utilizedHardware = instances . Hardware . Select ( x => new UtilizedHardware
55125 {
56- var entry = MasterConfigurationModel . InstanceConfiguration . InstanceProfiles . GetValue ( instance ) ;
126+ Hardware = MasterConfigurationModel . Hardware . GetValue ( x ) ,
127+ Profile = workload . GetValue ( x )
128+ } ) . ToList ( ) ;
57129
58- var cpuArgument = GetCpuArgument ( entry ) ;
59- var amdArgument = GetAmdArgument ( entry ) ;
60- var nvidiaArgument = GetNvidiaArgument ( entry ) ;
130+ var cpuArgument = GetCpuArgument ( utilizedHardware . Where ( x => x . Hardware . Type == "cpu" ) . ToList ( ) ) ;
131+ var amdArgument = GetAmdArgument ( utilizedHardware . Where ( x => x . Hardware . Type == "amd" ) . ToList ( ) ) ;
132+ var nvidiaArgument = GetNvidiaArgument ( utilizedHardware . Where ( x => x . Hardware . Type == "nvidia" ) . ToList ( ) ) ;
61133
62- RunMiner ( $ "{ configArgument } { cpuArgument } { amdArgument } { nvidiaArgument } ") ;
63- }
134+ RunMiner ( $ "{ configArgument } { cpuArgument } { amdArgument } { nvidiaArgument } ") ;
64135 }
65136 }
66137
67- private string GetActiveSolution ( )
138+ private void SelectSolution ( )
68139 {
69- //TODO: rewrite once configuration is changed
70- var activeSolution = RunConfigurationModel . ActiveSolutionConfiguration ;
71-
72- while ( string . IsNullOrEmpty ( activeSolution ) )
140+ Console . WriteLine ( @"Available solutions: " ) ;
141+ var keys = MasterConfigurationModel . SolutionProfiles . Keys . ToList ( ) ;
142+ var i = 0 ;
143+ foreach ( var key in keys )
73144 {
74- Console . WriteLine ( @"Available solutions: " ) ;
75- var keys = MasterConfigurationModel . SolutionConfiguration . SolutionProfiles . Keys . ToList ( ) ;
76- var i = 0 ;
77- foreach ( var key in keys )
78- {
79- Console . WriteLine ( @"{0,3}: {1}" , i , key ) ;
80- i ++ ;
81- }
82- Console . Write ( @"Select: " ) ;
83- int index ;
84- if ( int . TryParse ( Console . ReadLine ( ) , out index ) && index >= 0 && index < keys . Count )
85- {
86- activeSolution = keys [ index ] ;
87- }
145+ Console . WriteLine ( @"{0,3}: {1}" , i , key ) ;
146+ i ++ ;
88147 }
148+ Console . Write ( @"Select: " ) ;
149+ int index ;
150+ if ( int . TryParse ( Console . ReadLine ( ) , out index ) && index >= 0 && index < keys . Count )
151+ {
152+ RunConfigurationModel . ActiveSolutionConfiguration = keys [ index ] ;
153+ }
154+ }
89155
90- return activeSolution ;
156+ private void SelectWorkload ( )
157+ {
158+ Console . WriteLine ( @"Available workloads: " ) ;
159+ var keys = MasterConfigurationModel . WorkloadProfiles . Keys . ToList ( ) ;
160+ var i = 0 ;
161+ foreach ( var key in keys )
162+ {
163+ Console . WriteLine ( @"{0,3}: {1}" , i , key ) ;
164+ i ++ ;
165+ }
166+ Console . Write ( @"Select: " ) ;
167+ int index ;
168+ if ( int . TryParse ( Console . ReadLine ( ) , out index ) && index >= 0 && index < keys . Count )
169+ {
170+ RunConfigurationModel . ActiveWorkloadConfiguration = keys [ index ] ;
171+ }
91172 }
92173
93- private List < PrioritizedPoolEntry > GetOutputPools ( KeyValuePair < string , IList < string > > instances )
174+ private List < PrioritizedPoolEntry > GetOutputPools ( IEnumerable < string > pools )
94175 {
95- return MasterConfigurationModel
96- . PoolConfiguration
97- . PoolSets . GetValue ( instances . Key )
176+ return pools
177+ . Select ( x => MasterConfigurationModel . Pools . GetValue ( x ) )
98178 . Reverse ( )
99- . Select ( x => MasterConfigurationModel . PoolConfiguration . Pools . GetValue ( x ) )
100179 . Select ( ( x , i ) => new PrioritizedPoolEntry
101180 {
102181 PoolWeight = i + 1 ,
@@ -124,49 +203,77 @@ private static void RunMiner(string arguments)
124203
125204 private string GetConfigurationArgument ( IReadOnlyCollection < PrioritizedPoolEntry > pools )
126205 {
127- var configPath = CreateTemporaryConfiguration ( MasterConfigurationModel . ConfigTemplate , "config" , "%POOLS%" , pools ) ;
206+ var configPath = CreateTemporaryConfiguration ( MasterConfigurationModel . PathsConfiguration . ConfigTemplate , "config" , "%POOLS%" , pools ) ;
128207 ScheduleFileDelete ( configPath ) ;
129208
130209 return $ "--config \" { configPath } \" ";
131210 }
132211
133- private string GetCpuArgument ( InstanceEntry entry )
212+ private string GetCpuArgument ( IList < UtilizedHardware > entry )
134213 {
135- if ( string . IsNullOrEmpty ( entry . CpuProfile ) )
214+ if ( entry . Count == 0 )
136215 {
137216 return "--noCPU" ;
138217 }
139218
140- var cpuProfile = MasterConfigurationModel . CpuConfiguration . Profiles . GetValue ( entry . CpuProfile ) ;
141- var path = CreateTemporaryConfiguration ( MasterConfigurationModel . CpuTemplate , "cpu" , "%THREADS%" , cpuProfile ) ;
219+ var cpuProfile = entry . SelectMany ( x => MasterConfigurationModel . CpuProfiles . GetValue ( x . Profile ) ) . ToList ( ) ;
220+ var path = CreateTemporaryConfiguration ( MasterConfigurationModel . PathsConfiguration . CpuTemplate , "cpu" , "%THREADS%" , cpuProfile ) ;
142221 ScheduleFileDelete ( path ) ;
143222
144223 return $ "--cpu \" { path } \" ";
145224 }
146225
147- private string GetAmdArgument ( InstanceEntry entry )
226+ private string GetAmdArgument ( IList < UtilizedHardware > entry )
148227 {
149- if ( entry . AmdProfiles == null || entry . AmdProfiles . Count == 0 )
228+ if ( entry . Count == 0 )
150229 {
151230 return "--noAMD" ;
152231 }
153232
154- var amdProfile = entry . AmdProfiles . SelectMany ( x => MasterConfigurationModel . AmdConfiguration . Profiles . GetValue ( x ) ) . ToList ( ) ;
155- var path = CreateTemporaryConfiguration ( MasterConfigurationModel . AmdTemplate , "amd" , "%THREADS%" , amdProfile ) ;
233+ var amdProfile = entry
234+ . SelectMany (
235+ x =>
236+ MasterConfigurationModel . AmdProfiles . GetValue ( x . Profile )
237+ . Select ( profile => new IndexedAmdThreadEntry
238+ {
239+ Index = x . Hardware . Index ,
240+ AffineToCpu = profile . AffineToCpu ,
241+ Intensity = profile . Intensity ,
242+ StridedIndex = profile . StridedIndex ,
243+ Worksize = profile . Worksize
244+ } ) )
245+ . ToList ( ) ;
246+
247+ var path = CreateTemporaryConfiguration ( MasterConfigurationModel . PathsConfiguration . AmdTemplate , "amd" , "%THREADS%" , amdProfile ) ;
156248 ScheduleFileDelete ( path ) ;
157249
158250 return $ "--amd \" { path } \" ";
159251 }
160252
161- private string GetNvidiaArgument ( InstanceEntry entry )
253+ private string GetNvidiaArgument ( IList < UtilizedHardware > entry )
162254 {
163- if ( entry . NvidiaProfiles == null || entry . NvidiaProfiles . Count == 0 )
255+ if ( entry . Count == 0 )
164256 {
165257 return "--noNVIDIA" ;
166258 }
167259
168- var nvidiaProfile = entry . NvidiaProfiles . SelectMany ( x => MasterConfigurationModel . NvidiaConfiguration . Profiles . GetValue ( x ) ) . ToList ( ) ;
169- var path = CreateTemporaryConfiguration ( MasterConfigurationModel . NvidiaTemplate , "nvidia" , "%THREADS%" , nvidiaProfile ) ;
260+ var nvidiaProfile = entry
261+ . SelectMany (
262+ x =>
263+ MasterConfigurationModel . NvidiaProfiles . GetValue ( x . Profile )
264+ . Select ( profile => new IndexedNvidiaThreadEntry
265+ {
266+ Index = x . Hardware . Index ,
267+ AffineToCpu = profile . AffineToCpu ,
268+ Bfactor = profile . Bfactor ,
269+ Blocks = profile . Blocks ,
270+ Bsleep = profile . Bsleep ,
271+ SyncMode = profile . SyncMode ,
272+ Threads = profile . Threads
273+ } ) )
274+ . ToList ( ) ;
275+
276+ var path = CreateTemporaryConfiguration ( MasterConfigurationModel . PathsConfiguration . NvidiaTemplate , "nvidia" , "%THREADS%" , nvidiaProfile ) ;
170277 ScheduleFileDelete ( path ) ;
171278
172279 return $ "--nvidia \" { path } \" ";
0 commit comments