1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import Group from '../common/group.component'
import Param from '../common/param.component'
import * as systemActions from './system.actions'
import * as liveActions from '../live/live.actions'
import * as queueActions from '../queue/queue.actions'
const cpu_test_task = {
activity: 'cpu',
module: 'test',
dataset: 'test',
epochs: 1,
opt: {}
}
const gpu_test_task = {
activity: 'gpu',
module: 'test',
dataset: 'test',
epochs: 1,
opt: {}
}
const live_test_task = {
activity: 'live',
module: 'test',
dataset: 'test',
epochs: 1,
opt: {}
}
const wait_test_task = {
activity: 'wait',
module: 'test',
dataset: 'test',
epochs: 1,
opt: {}
}
const fruits = ["apple","pear","orange","strawberry"]
function choice(a){ return a[Math.floor(Math.random()*a.length)]}
class System extends Component {
constructor(props){
super()
}
componentDidUpdate(){
if (this._screen.scrollHeight > this._screen.scrollTop - this._screen.offsetHeight + 100) {
this._screen.scrollTop = this._screen.scrollHeight
}
}
render(){
const { site, server, relay, runner, rpc, actions } = this.props
return (
<div className='app system'>
<div className='heading'>
<h1>{site.name} system</h1>
</div>
<div className='row params'>
<div className='column'>
<Group title="Status">
<Param title='Server'>{server.status}</Param>
{server.error &&
<Param title='Server error'>{server.error.message}</Param>
}
<Param title='Relay'>{relay.status}</Param>
<Param title='RPC'>{rpc.status}</Param>
<Param title='CPU'>{this.renderStatus(runner.cpu)}</Param>
<Param title='GPU'>{this.renderStatus(runner.gpu)}</Param>
</Group>
<Group title="Diagnostics">
<Param title='Check GPU'>
<button onClick={() => actions.system.run('nvidia-smi')}>nvidia-smi</button>
</Param>
<Param title='List processes'>
<button onClick={() => actions.system.run('ps')}>ps</button>
</Param>
<Param title='List users'>
<button onClick={() => actions.system.run('w')}>w</button>
</Param>
<Param title='Disk free space'>
<button onClick={() => actions.system.run('df')}>df</button>
</Param>
</Group>
<Group title="Tasks">
<Param title='Kill task'>
<button onClick={() => actions.queue.stop_task('cpu')}>CPU</button>
<button onClick={() => actions.queue.stop_task('gpu')}>GPU</button>
</Param>
<Param title='Queue'>
<button onClick={() => actions.queue.start_queue()}>Start</button>
<button onClick={() => actions.queue.stop_queue()}>Stop</button>
</Param>
</Group>
<Group title="Test">
<Param title='CPU Test Task'>
<button onClick={() => actions.queue.start_task(cpu_test_task, { preempt: true, watch: true })}>Start</button>
<button onClick={() => actions.queue.stop_task(runner.cpu.task)}>Stop</button>
</Param>
<Param title='GPU Test Task'>
<button onClick={() => actions.queue.start_task(gpu_test_task, { preempt: true, watch: true })}>Start</button>
<button onClick={() => actions.queue.stop_task(runner.gpu.task)}>Stop</button>
</Param>
<Param title='Live Test Task'>
<button onClick={() => actions.queue.start_task(live_test_task, { preempt: true, watch: true })}>Start</button>
<button onClick={() => actions.queue.stop_task(runner.cpu.task)}>Stop</button>
</Param>
<Param title='Test Live RPC'>
<button onClick={() => actions.live.get_params()}>Get</button>
<button onClick={() => actions.live.set_param('fruit', choice(fruits))}>Set</button>
</Param>
<Param title=''>
<button onClick={() => actions.system.enqueue_test_task(choice(fruits))}>+Add</button>
</Param>
<Param title=''>
<button onClick={() => actions.queue.start_task(wait_test_task, { preempt: true, watch: true })}>Wait and Buzz</button>
</Param>
</Group>
</div>
{this.renderCommandOutput()}
</div>
</div>
)
}
renderStatus(processor){
if (!processor) {
return 'unknown'
}
if (processor.status === 'IDLE') {
return 'idle'
}
const task = processor.task
return task.activity + ' ' + task.module
}
renderCommandOutput(){
const { cmd, stdout, stderr } = this.props
let output
if (cmd.loading) {
output = 'Loading: ' + cmd.name
}
else if (cmd.loaded) {
if (cmd.error) {
output = 'Error: ' + cmd.name + '\n\n' + JSON.stringify(cmd.error, null, 2)
} else {
output = cmd.stdout
if (cmd.stderr) {
output += '\n\n_________________________________\n\n'
output += cmd.stderr
}
}
}
else {
output = stdout
if (stderr.length) {
output += '\n\n_________________________________\n\n'
output += stderr
}
}
return (
<div>
<div ref={(ref) => this._screen = ref} className='screen'>{output}</div>
</div>
)
}
}
const mapStateToProps = state => ({
...state.system,
...state.live,
})
const mapDispatchToProps = (dispatch, ownProps) => ({
actions: {
system: bindActionCreators(systemActions, dispatch),
queue: bindActionCreators(queueActions, dispatch),
live: bindActionCreators(liveActions, dispatch),
},
})
export default connect(mapStateToProps, mapDispatchToProps)(System)
|