Skip to content

Commit 4a57735

Browse files
committed
Reintegrating [4.0] branch.
2 parents f93f70f + e1c316a commit 4a57735

30 files changed

Lines changed: 1546 additions & 699 deletions

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
4.0.0 (24/10/2014)
2+
- Support for multiple output files added.
3+
- Direct writing added.
4+
- Memory management improved.
5+
- File seek() calls enhanced.
6+
17
3.1.0 (09/10/2014)
28
- [setup] command added.
39
- Display bug corrected in the [listDevices] command.

CommandGenerate.cpp

Lines changed: 318 additions & 168 deletions
Large diffs are not rendered by default.

CommandGenerate.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@
1212

1313
#include <string>
1414
#include <vector>
15+
#include <list>
16+
#include <memory>
17+
#include <mutex>
18+
#include <condition_variable>
19+
#include <exception>
1520

1621
#include "Command.h"
22+
#include "GenerationDevice.h"
23+
#include "GenerationContext.h"
24+
#include "GenerationWork.h"
25+
#include "GenerationWriter.h"
1726

1827
namespace cryo {
1928
namespace gpuPlotGenerator {
@@ -28,6 +37,22 @@ class CommandGenerate : public cryo::gpuPlotGenerator::Command {
2837
virtual int execute(const std::vector<std::string>& p_args);
2938
};
3039

40+
void computePlots(
41+
std::exception_ptr& p_error,
42+
std::mutex& p_mutex,
43+
std::condition_variable& p_barrier,
44+
std::list<std::shared_ptr<GenerationContext>>& p_generationContexts,
45+
std::shared_ptr<GenerationDevice>& p_generationDevice
46+
) throw (std::exception);
47+
48+
void writeNonces(
49+
std::exception_ptr& p_error,
50+
std::mutex& p_mutex,
51+
std::condition_variable& p_barrier,
52+
std::list<std::shared_ptr<GenerationContext>>& p_generationContexts,
53+
std::shared_ptr<GenerationWriter>& p_writer
54+
) throw (std::exception);
55+
3156
}}
3257

3358
#endif

CommandHelp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,18 @@
1313
#include <string>
1414
#include <vector>
1515
#include <map>
16+
#include <memory>
1617

1718
#include "Command.h"
1819

1920
namespace cryo {
2021
namespace gpuPlotGenerator {
2122

2223
class CommandHelp : public cryo::gpuPlotGenerator::Command {
24+
public:
25+
typedef std::map<std::string, std::shared_ptr<cryo::gpuPlotGenerator::Command>> CommandsMap;
26+
2327
private:
24-
typedef std::map<std::string, cryo::gpuPlotGenerator::Command*> CommandsMap;
2528
const CommandsMap& m_commands;
2629

2730
public:

CommandListDevices.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <iostream>
1111
#include <cstdlib>
12+
#include <memory>
13+
#include <exception>
1214

1315
#include "util.h"
1416
#include "OpenclError.h"
@@ -43,8 +45,6 @@ int CommandListDevices::execute(const std::vector<std::string>& p_args) {
4345
return -1;
4446
}
4547

46-
int returnCode = 0;
47-
4848
try {
4949
std::size_t platformId = std::atol(p_args[0].c_str());
5050

@@ -81,14 +81,14 @@ int CommandListDevices::execute(const std::vector<std::string>& p_args) {
8181
} catch(const OpenclError& ex) {
8282
std::cout << std::endl;
8383
std::cout << "[ERROR][" << ex.getCode() << "][" << ex.getCodeString() << "] " << ex.what() << std::endl;
84-
returnCode = -1;
84+
return -1;
8585
} catch(const std::exception& ex) {
8686
std::cout << std::endl;
8787
std::cout << "[ERROR] " << ex.what() << std::endl;
88-
returnCode = -1;
88+
return -1;
8989
}
9090

91-
return returnCode;
91+
return 0;
9292
}
9393

9494
}}

CommandListPlatforms.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
#include <iostream>
11-
#include <vector>
1211
#include <memory>
1312
#include <exception>
1413

@@ -36,8 +35,6 @@ void CommandListPlatforms::help() const {
3635
}
3736

3837
int CommandListPlatforms::execute(const std::vector<std::string>&) {
39-
int returnCode = 0;
40-
4138
try {
4239
std::vector<std::shared_ptr<OpenclPlatform>> platforms(OpenclPlatform::list());
4340
std::cout << "Platforms number: " << platforms.size() << std::endl;
@@ -53,14 +50,14 @@ int CommandListPlatforms::execute(const std::vector<std::string>&) {
5350
} catch(const OpenclError& ex) {
5451
std::cout << std::endl;
5552
std::cout << "[ERROR][" << ex.getCode() << "][" << ex.getCodeString() << "] " << ex.what() << std::endl;
56-
returnCode = -1;
53+
return -1;
5754
} catch(const std::exception& ex) {
5855
std::cout << std::endl;
5956
std::cout << "[ERROR] " << ex.what() << std::endl;
60-
returnCode = -1;
57+
return -1;
6158
}
6259

63-
return returnCode;
60+
return 0;
6461
}
6562

6663
}}

CommandSetup.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
#include "OpenclError.h"
1717
#include "OpenclPlatform.h"
1818
#include "OpenclDevice.h"
19-
#include "GenerationConfig.h"
20-
#include "OpenclError.h"
19+
#include "DeviceConfig.h"
2120
#include "CommandSetup.h"
2221

2322
namespace cryo {
@@ -40,8 +39,6 @@ void CommandSetup::help() const {
4039
}
4140

4241
int CommandSetup::execute(const std::vector<std::string>&) {
43-
int returnCode = 0;
44-
4542
try {
4643
std::cout << "Loading platforms..." << std::endl;
4744
std::vector<std::shared_ptr<OpenclPlatform>> platforms(OpenclPlatform::list());
@@ -53,7 +50,12 @@ int CommandSetup::execute(const std::vector<std::string>&) {
5350
}
5451

5552
std::cout << "Loading devices configurations..." << std::endl;
56-
std::vector<std::shared_ptr<GenerationConfig>> configs(GenerationConfig::loadFromFile(DEVICES_FILE));
53+
std::vector<std::shared_ptr<DeviceConfig>> configs;
54+
try {
55+
configs = DeviceConfig::loadFromFile(DEVICES_FILE);
56+
} catch(...) {
57+
std::cout << "[WARNING] No config file found" << std::endl;
58+
}
5759

5860
std::vector<unsigned long long> sizeUnits {1024, 1024};
5961
std::vector<std::string> sizeLabels {"MB", "GB", "TB"};
@@ -84,15 +86,18 @@ int CommandSetup::execute(const std::vector<std::string>&) {
8486
std::size_t j = 0;
8587
for(const std::shared_ptr<OpenclDevice>& device : devices[i]) {
8688
std::cout << " [" << j << "] " << device->getName() << " (" << device->getVersion() << ")" << std::endl;
89+
++j;
8790
}
91+
92+
++i;
8893
}
8994
}
9095
break;
9196
case 2:{
9297
std::cout << "Number of configured devices: " << configs.size() << std::endl;
9398

9499
std::size_t i = 0;
95-
for(const std::shared_ptr<GenerationConfig>& config : configs) {
100+
for(const std::shared_ptr<DeviceConfig>& config : configs) {
96101
std::cout << "----" << std::endl;
97102
std::cout << "Index: " << i++ << std::endl;
98103
std::cout << "Platform: " << config->getPlatform() << std::endl;
@@ -124,7 +129,7 @@ int CommandSetup::execute(const std::vector<std::string>&) {
124129
}
125130

126131
std::shared_ptr<OpenclDevice> device(devices[platformId][deviceId]);
127-
std::shared_ptr<GenerationConfig> config(new GenerationConfig(
132+
std::shared_ptr<DeviceConfig> config(new DeviceConfig(
128133
platformId,
129134
deviceId,
130135
std::min(device->getGlobalMemorySize() / PLOT_SIZE, device->getMaxMemoryAllocationSize() / PLOT_SIZE),
@@ -170,7 +175,7 @@ int CommandSetup::execute(const std::vector<std::string>&) {
170175
}
171176
break;
172177
case 9:{
173-
GenerationConfig::storeToFile(DEVICES_FILE, configs);
178+
DeviceConfig::storeToFile(DEVICES_FILE, configs);
174179
std::cout << "Config saved" << std::endl;
175180
}
176181
break;
@@ -184,14 +189,14 @@ int CommandSetup::execute(const std::vector<std::string>&) {
184189
} catch(const OpenclError& ex) {
185190
std::cout << std::endl;
186191
std::cout << "[ERROR][" << ex.getCode() << "][" << ex.getCodeString() << "] " << ex.what() << std::endl;
187-
returnCode = -1;
192+
return -1;
188193
} catch(const std::exception& ex) {
189194
std::cout << std::endl;
190195
std::cout << "[ERROR] " << ex.what() << std::endl;
191-
returnCode = -1;
196+
return -1;
192197
}
193198

194-
return returnCode;
199+
return 0;
195200
}
196201

197202
}}

CommandVerify.cpp

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#include <sstream>
1313
#include <stdexcept>
1414
#include <algorithm>
15+
#include <memory>
1516

1617
#include "constants.h"
1718
#include "util.h"
19+
#include "GenerationConfig.h"
1820
#include "PlotsFile.h"
1921
#include "CommandVerify.h"
2022

@@ -48,27 +50,25 @@ int CommandVerify::execute(const std::vector<std::string>& p_args) {
4850
return -1;
4951
}
5052

51-
unsigned char* generatedBuffer = 0;
52-
unsigned char* referenceBuffer = 0;
53-
54-
int returnCode = 0;
55-
5653
try {
57-
PlotsFile generated(p_args[0]);
58-
PlotsFile reference(p_args[1]);
54+
GenerationConfig generatedConfig(p_args[0]);
55+
GenerationConfig referenceConfig(p_args[1]);
5956

6057
std::cout << "Checking input parameters..." << std::endl;
6158

62-
if(generated.getAddress() != reference.getAddress()) {
59+
if(generatedConfig.getAddress() != referenceConfig.getAddress()) {
6360
throw std::runtime_error("Files don't share the same address");
6461
}
6562

66-
if(sizeof(std::size_t) == 4 && (generated.getStaggerSize() > 16000 || reference.getStaggerSize() > 16000)) {
63+
if(sizeof(std::size_t) == 4 && (generatedConfig.getStaggerSize() > 16000 || referenceConfig.getStaggerSize() > 16000)) {
6764
throw std::runtime_error("Stagger size value too high (32bits platform restriction)");
6865
}
6966

70-
unsigned long long commonStart = std::max(generated.getStartNonce(), reference.getStartNonce());
71-
unsigned long long commonEnd = std::min(generated.getEndNonce(), reference.getEndNonce());
67+
PlotsFile generated(generatedConfig.getFullPath(), false);
68+
PlotsFile reference(referenceConfig.getFullPath(), false);
69+
70+
unsigned long long commonStart = std::max(generatedConfig.getStartNonce(), referenceConfig.getStartNonce());
71+
unsigned long long commonEnd = std::min(generatedConfig.getEndNonce(), referenceConfig.getEndNonce());
7272
unsigned int commonNb = commonEnd - commonStart + 1;
7373
if(commonStart > commonEnd) {
7474
throw std::runtime_error("No common nonces between the two files");
@@ -90,63 +90,54 @@ int CommandVerify::execute(const std::vector<std::string>& p_args) {
9090
std::cout << "CPU memory: " << cryo::util::formatValue(cpuMemory, sizeUnitsB, sizeLabelsB) << std::endl;
9191
std::cout << "----" << std::endl;
9292

93-
generatedBuffer = new unsigned char[generatedBufferSize];
94-
if(!generatedBuffer) {
95-
throw std::runtime_error("Unable to create the generated file buffer");
96-
}
97-
98-
referenceBuffer = new unsigned char[referenceBufferSize];
99-
if(!referenceBuffer) {
100-
throw std::runtime_error("Unable to create the reference file buffer");
101-
}
93+
std::unique_ptr<unsigned char[]> generatedBuffer(new unsigned char[generatedBufferSize]);
94+
std::unique_ptr<unsigned char[]> referenceBuffer(new unsigned char[referenceBufferSize]);
10295

10396
std::cout << "Checking generated plots file..." << std::endl;
10497

10598
std::ostringstream console;
10699
console << std::fixed << std::setprecision(2);
107100

108101
for(unsigned int i = 0 ; i < commonNb ; ++i) {
102+
std::cout << std::string(console.str().length(), '\b');
103+
std::cout << std::string(console.str().length(), ' ');
109104
std::cout << std::string(console.str().length(), '\b');
110105
console.str("");
111106

112107
double percent = 100.0 * (double)i / (double)commonNb;
113108
console << percent << "% (" << i << "/" << commonNb << " nonces)";
114-
console << "... ";
109+
console << "...";
115110
std::cout << console.str();
116111

117-
std::streamoff generatedNonceStaggerOffset = generated.getNonceStaggerOffset(commonStart + i);
118-
std::streamoff generatedNonceStaggerDecal = generated.getNonceStaggerDecal(commonStart + i);
119-
120-
std::streamoff referenceNonceStaggerOffset = reference.getNonceStaggerOffset(commonStart + i);
121-
std::streamoff referenceNonceStaggerDecal = reference.getNonceStaggerDecal(commonStart + i);
112+
generated.seek((std::streamoff)generatedConfig.getNonceStaggerOffset(commonStart + i) + generatedConfig.getNonceStaggerDecal(commonStart + i), std::ios::beg);
113+
reference.seek((std::streamoff)referenceConfig.getNonceStaggerOffset(commonStart + i) + referenceConfig.getNonceStaggerDecal(commonStart + i), std::ios::beg);
122114

123115
for(unsigned int j = 0 ; j < PLOT_SIZE ; j += SCOOP_SIZE) {
124-
generated.seek(generatedNonceStaggerOffset + generatedNonceStaggerDecal + (std::streamoff)j * generated.getStaggerSize());
125-
reference.seek(referenceNonceStaggerOffset + referenceNonceStaggerDecal + (std::streamoff)j * reference.getStaggerSize());
126-
127-
generated.read(generatedBuffer, SCOOP_SIZE);
128-
reference.read(referenceBuffer, SCOOP_SIZE);
116+
generated.read(generatedBuffer.get(), SCOOP_SIZE);
117+
reference.read(referenceBuffer.get(), SCOOP_SIZE);
129118

130-
if(!std::equal(generatedBuffer, generatedBuffer + SCOOP_SIZE, referenceBuffer)) {
119+
if(!std::equal(generatedBuffer.get(), generatedBuffer.get() + SCOOP_SIZE, referenceBuffer.get())) {
131120
throw std::runtime_error("Common nonces doesn't match");
132121
}
122+
123+
generated.seek(((std::streamoff)generatedConfig.getStaggerSize() - 1) * SCOOP_SIZE, std::ios::cur);
124+
reference.seek(((std::streamoff)referenceConfig.getStaggerSize() - 1) * SCOOP_SIZE, std::ios::cur);
133125
}
134126
}
135127

136128
std::cout << std::string(console.str().length(), '\b');
137-
std::cout << "100% (" << commonNb << "/" << commonNb << " nonces)";
138-
std::cout << " " << std::endl << std::endl;
129+
std::cout << std::string(console.str().length(), ' ');
130+
std::cout << std::string(console.str().length(), '\b');
131+
132+
std::cout << "100% (" << commonNb << "/" << commonNb << " nonces)" << std::endl << std::endl;
139133
std::cout << "[OK] The generated plots file has been successfully verified against the provided reference" << std::endl;
140134
} catch(const std::exception& ex) {
141135
std::cout << std::endl;
142136
std::cout << "[ERROR] " << ex.what() << std::endl;
143-
returnCode = -1;
137+
return -1;
144138
}
145139

146-
if(referenceBuffer) { delete[] referenceBuffer; }
147-
if(generatedBuffer) { delete[] generatedBuffer; }
148-
149-
return returnCode;
140+
return 0;
150141
}
151142

152143
}}

0 commit comments

Comments
 (0)