@@ -22,6 +22,18 @@ public class MinerRunner : IRunner
22
22
[ Dependency ]
23
23
public MasterConfigurationModel MasterConfigurationModel { get ; set ; }
24
24
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
+
25
37
public void Run ( )
26
38
{
27
39
if ( MasterConfigurationModel == null )
@@ -30,73 +42,140 @@ public void Run()
30
42
return ;
31
43
}
32
44
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 ; }
34
102
}
35
103
36
104
private void DoRun ( )
37
105
{
38
- var activeSolution = GetActiveSolution ( ) ;
39
106
KillMiners ( ) ;
40
107
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 ;
42
112
foreach ( var instances in solution )
43
113
{
44
- var outputPools = GetOutputPools ( instances ) ;
114
+ i ++ ;
115
+ var outputPools = GetOutputPools ( instances . Pools ) ;
45
116
46
117
if ( outputPools . Count == 0 )
47
118
{
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 ) ;
49
120
continue ;
50
121
}
51
122
52
123
var configArgument = GetConfigurationArgument ( outputPools ) ;
53
-
54
- foreach ( var instance in instances . Value )
124
+ var utilizedHardware = instances . Hardware . Select ( x => new UtilizedHardware
55
125
{
56
- var entry = MasterConfigurationModel . InstanceConfiguration . InstanceProfiles . GetValue ( instance ) ;
126
+ Hardware = MasterConfigurationModel . Hardware . GetValue ( x ) ,
127
+ Profile = workload . GetValue ( x )
128
+ } ) . ToList ( ) ;
57
129
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 ( ) ) ;
61
133
62
- RunMiner ( $ "{ configArgument } { cpuArgument } { amdArgument } { nvidiaArgument } ") ;
63
- }
134
+ RunMiner ( $ "{ configArgument } { cpuArgument } { amdArgument } { nvidiaArgument } ") ;
64
135
}
65
136
}
66
137
67
- private string GetActiveSolution ( )
138
+ private void SelectSolution ( )
68
139
{
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 )
73
144
{
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 ++ ;
88
147
}
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
+ }
89
155
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
+ }
91
172
}
92
173
93
- private List < PrioritizedPoolEntry > GetOutputPools ( KeyValuePair < string , IList < string > > instances )
174
+ private List < PrioritizedPoolEntry > GetOutputPools ( IEnumerable < string > pools )
94
175
{
95
- return MasterConfigurationModel
96
- . PoolConfiguration
97
- . PoolSets . GetValue ( instances . Key )
176
+ return pools
177
+ . Select ( x => MasterConfigurationModel . Pools . GetValue ( x ) )
98
178
. Reverse ( )
99
- . Select ( x => MasterConfigurationModel . PoolConfiguration . Pools . GetValue ( x ) )
100
179
. Select ( ( x , i ) => new PrioritizedPoolEntry
101
180
{
102
181
PoolWeight = i + 1 ,
@@ -124,49 +203,77 @@ private static void RunMiner(string arguments)
124
203
125
204
private string GetConfigurationArgument ( IReadOnlyCollection < PrioritizedPoolEntry > pools )
126
205
{
127
- var configPath = CreateTemporaryConfiguration ( MasterConfigurationModel . ConfigTemplate , "config" , "%POOLS%" , pools ) ;
206
+ var configPath = CreateTemporaryConfiguration ( MasterConfigurationModel . PathsConfiguration . ConfigTemplate , "config" , "%POOLS%" , pools ) ;
128
207
ScheduleFileDelete ( configPath ) ;
129
208
130
209
return $ "--config \" { configPath } \" ";
131
210
}
132
211
133
- private string GetCpuArgument ( InstanceEntry entry )
212
+ private string GetCpuArgument ( IList < UtilizedHardware > entry )
134
213
{
135
- if ( string . IsNullOrEmpty ( entry . CpuProfile ) )
214
+ if ( entry . Count == 0 )
136
215
{
137
216
return "--noCPU" ;
138
217
}
139
218
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 ) ;
142
221
ScheduleFileDelete ( path ) ;
143
222
144
223
return $ "--cpu \" { path } \" ";
145
224
}
146
225
147
- private string GetAmdArgument ( InstanceEntry entry )
226
+ private string GetAmdArgument ( IList < UtilizedHardware > entry )
148
227
{
149
- if ( entry . AmdProfiles == null || entry . AmdProfiles . Count == 0 )
228
+ if ( entry . Count == 0 )
150
229
{
151
230
return "--noAMD" ;
152
231
}
153
232
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 ) ;
156
248
ScheduleFileDelete ( path ) ;
157
249
158
250
return $ "--amd \" { path } \" ";
159
251
}
160
252
161
- private string GetNvidiaArgument ( InstanceEntry entry )
253
+ private string GetNvidiaArgument ( IList < UtilizedHardware > entry )
162
254
{
163
- if ( entry . NvidiaProfiles == null || entry . NvidiaProfiles . Count == 0 )
255
+ if ( entry . Count == 0 )
164
256
{
165
257
return "--noNVIDIA" ;
166
258
}
167
259
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 ) ;
170
277
ScheduleFileDelete ( path ) ;
171
278
172
279
return $ "--nvidia \" { path } \" ";
0 commit comments