-
Notifications
You must be signed in to change notification settings - Fork 26
/
CommandSetup.cpp
202 lines (168 loc) · 6.06 KB
/
CommandSetup.cpp
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*
GPU plot generator for Burst coin.
Author: Cryo
Bitcoin: 138gMBhCrNkbaiTCmUhP9HLU9xwn5QKZgD
Burst: BURST-YA29-QCEW-QXC3-BKXDL
Based on the code of the official miner and dcct's plotgen.
*/
#include <iostream>
#include <memory>
#include <algorithm>
#include <exception>
#include "util.h"
#include "OpenclError.h"
#include "OpenclPlatform.h"
#include "OpenclDevice.h"
#include "DeviceConfig.h"
#include "CommandSetup.h"
namespace cryo {
namespace gpuPlotGenerator {
CommandSetup::CommandSetup()
: Command("Step by step setup guide.") {
}
CommandSetup::CommandSetup(const CommandSetup& p_command)
: Command(p_command) {
}
CommandSetup::~CommandSetup() throw () {
}
void CommandSetup::help() const {
std::cout << "Usage: ./gpuPlotGenerator setup" << std::endl;
std::cout << " Launch a step by step setup guide to create the [devices.txt] file." << std::endl;
}
int CommandSetup::execute(const std::vector<std::string>&) {
try {
std::cout << "Loading platforms..." << std::endl;
std::vector<std::shared_ptr<OpenclPlatform>> platforms(OpenclPlatform::list());
std::cout << "Loading devices..." << std::endl;
std::vector<std::vector<std::shared_ptr<OpenclDevice>>> devices;
for(const std::shared_ptr<OpenclPlatform>& platform : platforms) {
devices.push_back(OpenclDevice::list(platform));
}
std::cout << "Loading devices configurations..." << std::endl;
std::vector<std::shared_ptr<DeviceConfig>> configs;
try {
configs = DeviceConfig::loadFromFile(DEVICES_FILE);
} catch(...) {
std::cout << "[WARNING] No config file found" << std::endl;
}
std::vector<unsigned long long> sizeUnits {1024, 1024};
std::vector<std::string> sizeLabels {"MB", "GB", "TB"};
bool run = true;
while(run) {
std::cout << "----" << std::endl;
std::cout << "1. List all devices" << std::endl;
std::cout << "2. List configured devices" << std::endl;
std::cout << "3. Add device config" << std::endl;
std::cout << "4. Remove device config" << std::endl;
std::cout << "9. Save config" << std::endl;
std::cout << "0. Quit" << std::endl;
unsigned int action;
std::cout << std::endl;
std::cout << "> Select an option: ";
std::cin >> action;
std::cout << std::endl;
switch(action) {
case 1:{
std::cout << "----" << std::endl;
std::size_t i = 0;
for(const std::shared_ptr<OpenclPlatform>& platform : platforms) {
std::cout << "[" << i << "] " << platform->getName() << " (" << platform->getVersion() << ")" << std::endl;
std::size_t j = 0;
for(const std::shared_ptr<OpenclDevice>& device : devices[i]) {
std::cout << " [" << j << "] " << device->getName() << " (" << device->getVersion() << ")" << std::endl;
++j;
}
++i;
}
}
break;
case 2:{
std::cout << "Number of configured devices: " << configs.size() << std::endl;
std::size_t i = 0;
for(const std::shared_ptr<DeviceConfig>& config : configs) {
std::cout << "----" << std::endl;
std::cout << "Index: " << i++ << std::endl;
std::cout << "Platform: " << config->getPlatform() << std::endl;
std::cout << "Device: " << config->getDevice() << std::endl;
std::cout << "Global work size: " << config->getGlobalWorkSize() << std::endl;
std::cout << "Local work size: " << config->getLocalWorkSize() << std::endl;
std::cout << "Hashes number: " << config->getHashesNumber() << std::endl;
std::cout << "Used memory: " << cryo::util::formatValue(config->getBufferSize() >> 20, sizeUnits, sizeLabels) << std::endl;
}
}
break;
case 3:{
unsigned int platformId;
std::cout << "Platform id: ";
std::cin >> platformId;
if(platformId >= platforms.size()) {
std::cout << "[ERROR] No platform found with the provided id" << std::endl;
break;
}
unsigned int deviceId;
std::cout << "Device id: ";
std::cin >> deviceId;
if(deviceId >= devices[platformId].size()) {
std::cout << "[ERROR] No device found with the provided id" << std::endl;
break;
}
std::shared_ptr<OpenclDevice> device(devices[platformId][deviceId]);
std::shared_ptr<DeviceConfig> config(new DeviceConfig(
platformId,
deviceId,
std::min(device->getGlobalMemorySize() / PLOT_SIZE, device->getMaxMemoryAllocationSize() / PLOT_SIZE),
1,
PLOT_SIZE / HASH_SIZE
));
config->normalize();
std::cout << "Global work size (" << config->getGlobalWorkSize() << " recommended): ";
std::cin >> config->globalWorkSize();
std::vector<std::size_t> maxWorkItemSizes(device->getMaxWorkItemSizes());
config->setLocalWorkSize(std::max((std::size_t)1, maxWorkItemSizes[0] / 4) * 3);
config->normalize();
std::cout << "Local work size (" << config->getLocalWorkSize() << " recommended): ";
std::cin >> config->localWorkSize();
std::cout << "Hashes number (" << config->getHashesNumber() << " recommended): ";
std::cin >> config->hashesNumber();
std::cout << "----" << std::endl;
std::cout << "Normalizing config..." << std::endl;
config->normalize();
configs.push_back(config);
std::cout << "New config added" << std::endl;
}
break;
case 4:{
std::size_t configIndex;
std::cout << "Config index: ";
std::cin >> configIndex;
if(configIndex >= configs.size()) {
std::cout << "[ERROR] No config found with the provided index" << std::endl;
break;
}
configs.erase(configs.begin() + configIndex);
std::cout << "Config removed" << std::endl;
}
break;
case 9:{
DeviceConfig::storeToFile(DEVICES_FILE, configs);
std::cout << "Config saved" << std::endl;
}
break;
case 0:
run = false;
break;
}
std::cout << std::endl;
}
} catch(const OpenclError& ex) {
std::cout << std::endl;
std::cout << "[ERROR][" << ex.getCode() << "][" << ex.getCodeString() << "] " << ex.what() << std::endl;
return -1;
} catch(const std::exception& ex) {
std::cout << std::endl;
std::cout << "[ERROR] " << ex.what() << std::endl;
return -1;
}
return 0;
}
}}