Skip to content

Commit

Permalink
Reintegrating [4.0] branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhamon committed Oct 24, 2014
2 parents f93f70f + e1c316a commit 4a57735
Show file tree
Hide file tree
Showing 30 changed files with 1,546 additions and 699 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
4.0.0 (24/10/2014)
- Support for multiple output files added.
- Direct writing added.
- Memory management improved.
- File seek() calls enhanced.

3.1.0 (09/10/2014)
- [setup] command added.
- Display bug corrected in the [listDevices] command.
Expand Down
486 changes: 318 additions & 168 deletions CommandGenerate.cpp

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions CommandGenerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@

#include <string>
#include <vector>
#include <list>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <exception>

#include "Command.h"
#include "GenerationDevice.h"
#include "GenerationContext.h"
#include "GenerationWork.h"
#include "GenerationWriter.h"

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

void computePlots(
std::exception_ptr& p_error,
std::mutex& p_mutex,
std::condition_variable& p_barrier,
std::list<std::shared_ptr<GenerationContext>>& p_generationContexts,
std::shared_ptr<GenerationDevice>& p_generationDevice
) throw (std::exception);

void writeNonces(
std::exception_ptr& p_error,
std::mutex& p_mutex,
std::condition_variable& p_barrier,
std::list<std::shared_ptr<GenerationContext>>& p_generationContexts,
std::shared_ptr<GenerationWriter>& p_writer
) throw (std::exception);

}}

#endif
5 changes: 4 additions & 1 deletion CommandHelp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
#include <string>
#include <vector>
#include <map>
#include <memory>

#include "Command.h"

namespace cryo {
namespace gpuPlotGenerator {

class CommandHelp : public cryo::gpuPlotGenerator::Command {
public:
typedef std::map<std::string, std::shared_ptr<cryo::gpuPlotGenerator::Command>> CommandsMap;

private:
typedef std::map<std::string, cryo::gpuPlotGenerator::Command*> CommandsMap;
const CommandsMap& m_commands;

public:
Expand Down
10 changes: 5 additions & 5 deletions CommandListDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <iostream>
#include <cstdlib>
#include <memory>
#include <exception>

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

int returnCode = 0;

try {
std::size_t platformId = std::atol(p_args[0].c_str());

Expand Down Expand Up @@ -81,14 +81,14 @@ int CommandListDevices::execute(const std::vector<std::string>& p_args) {
} catch(const OpenclError& ex) {
std::cout << std::endl;
std::cout << "[ERROR][" << ex.getCode() << "][" << ex.getCodeString() << "] " << ex.what() << std::endl;
returnCode = -1;
return -1;
} catch(const std::exception& ex) {
std::cout << std::endl;
std::cout << "[ERROR] " << ex.what() << std::endl;
returnCode = -1;
return -1;
}

return returnCode;
return 0;
}

}}
9 changes: 3 additions & 6 deletions CommandListPlatforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

#include <iostream>
#include <vector>
#include <memory>
#include <exception>

Expand Down Expand Up @@ -36,8 +35,6 @@ void CommandListPlatforms::help() const {
}

int CommandListPlatforms::execute(const std::vector<std::string>&) {
int returnCode = 0;

try {
std::vector<std::shared_ptr<OpenclPlatform>> platforms(OpenclPlatform::list());
std::cout << "Platforms number: " << platforms.size() << std::endl;
Expand All @@ -53,14 +50,14 @@ int CommandListPlatforms::execute(const std::vector<std::string>&) {
} catch(const OpenclError& ex) {
std::cout << std::endl;
std::cout << "[ERROR][" << ex.getCode() << "][" << ex.getCodeString() << "] " << ex.what() << std::endl;
returnCode = -1;
return -1;
} catch(const std::exception& ex) {
std::cout << std::endl;
std::cout << "[ERROR] " << ex.what() << std::endl;
returnCode = -1;
return -1;
}

return returnCode;
return 0;
}

}}
27 changes: 16 additions & 11 deletions CommandSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "OpenclError.h"
#include "OpenclPlatform.h"
#include "OpenclDevice.h"
#include "GenerationConfig.h"
#include "OpenclError.h"
#include "DeviceConfig.h"
#include "CommandSetup.h"

namespace cryo {
Expand All @@ -40,8 +39,6 @@ void CommandSetup::help() const {
}

int CommandSetup::execute(const std::vector<std::string>&) {
int returnCode = 0;

try {
std::cout << "Loading platforms..." << std::endl;
std::vector<std::shared_ptr<OpenclPlatform>> platforms(OpenclPlatform::list());
Expand All @@ -53,7 +50,12 @@ int CommandSetup::execute(const std::vector<std::string>&) {
}

std::cout << "Loading devices configurations..." << std::endl;
std::vector<std::shared_ptr<GenerationConfig>> configs(GenerationConfig::loadFromFile(DEVICES_FILE));
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"};
Expand Down Expand Up @@ -84,15 +86,18 @@ int CommandSetup::execute(const std::vector<std::string>&) {
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<GenerationConfig>& config : configs) {
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;
Expand Down Expand Up @@ -124,7 +129,7 @@ int CommandSetup::execute(const std::vector<std::string>&) {
}

std::shared_ptr<OpenclDevice> device(devices[platformId][deviceId]);
std::shared_ptr<GenerationConfig> config(new GenerationConfig(
std::shared_ptr<DeviceConfig> config(new DeviceConfig(
platformId,
deviceId,
std::min(device->getGlobalMemorySize() / PLOT_SIZE, device->getMaxMemoryAllocationSize() / PLOT_SIZE),
Expand Down Expand Up @@ -170,7 +175,7 @@ int CommandSetup::execute(const std::vector<std::string>&) {
}
break;
case 9:{
GenerationConfig::storeToFile(DEVICES_FILE, configs);
DeviceConfig::storeToFile(DEVICES_FILE, configs);
std::cout << "Config saved" << std::endl;
}
break;
Expand All @@ -184,14 +189,14 @@ int CommandSetup::execute(const std::vector<std::string>&) {
} catch(const OpenclError& ex) {
std::cout << std::endl;
std::cout << "[ERROR][" << ex.getCode() << "][" << ex.getCodeString() << "] " << ex.what() << std::endl;
returnCode = -1;
return -1;
} catch(const std::exception& ex) {
std::cout << std::endl;
std::cout << "[ERROR] " << ex.what() << std::endl;
returnCode = -1;
return -1;
}

return returnCode;
return 0;
}

}}
69 changes: 30 additions & 39 deletions CommandVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include <sstream>
#include <stdexcept>
#include <algorithm>
#include <memory>

#include "constants.h"
#include "util.h"
#include "GenerationConfig.h"
#include "PlotsFile.h"
#include "CommandVerify.h"

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

unsigned char* generatedBuffer = 0;
unsigned char* referenceBuffer = 0;

int returnCode = 0;

try {
PlotsFile generated(p_args[0]);
PlotsFile reference(p_args[1]);
GenerationConfig generatedConfig(p_args[0]);
GenerationConfig referenceConfig(p_args[1]);

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

if(generated.getAddress() != reference.getAddress()) {
if(generatedConfig.getAddress() != referenceConfig.getAddress()) {
throw std::runtime_error("Files don't share the same address");
}

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

unsigned long long commonStart = std::max(generated.getStartNonce(), reference.getStartNonce());
unsigned long long commonEnd = std::min(generated.getEndNonce(), reference.getEndNonce());
PlotsFile generated(generatedConfig.getFullPath(), false);
PlotsFile reference(referenceConfig.getFullPath(), false);

unsigned long long commonStart = std::max(generatedConfig.getStartNonce(), referenceConfig.getStartNonce());
unsigned long long commonEnd = std::min(generatedConfig.getEndNonce(), referenceConfig.getEndNonce());
unsigned int commonNb = commonEnd - commonStart + 1;
if(commonStart > commonEnd) {
throw std::runtime_error("No common nonces between the two files");
Expand All @@ -90,63 +90,54 @@ int CommandVerify::execute(const std::vector<std::string>& p_args) {
std::cout << "CPU memory: " << cryo::util::formatValue(cpuMemory, sizeUnitsB, sizeLabelsB) << std::endl;
std::cout << "----" << std::endl;

generatedBuffer = new unsigned char[generatedBufferSize];
if(!generatedBuffer) {
throw std::runtime_error("Unable to create the generated file buffer");
}

referenceBuffer = new unsigned char[referenceBufferSize];
if(!referenceBuffer) {
throw std::runtime_error("Unable to create the reference file buffer");
}
std::unique_ptr<unsigned char[]> generatedBuffer(new unsigned char[generatedBufferSize]);
std::unique_ptr<unsigned char[]> referenceBuffer(new unsigned char[referenceBufferSize]);

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

std::ostringstream console;
console << std::fixed << std::setprecision(2);

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

double percent = 100.0 * (double)i / (double)commonNb;
console << percent << "% (" << i << "/" << commonNb << " nonces)";
console << "... ";
console << "...";
std::cout << console.str();

std::streamoff generatedNonceStaggerOffset = generated.getNonceStaggerOffset(commonStart + i);
std::streamoff generatedNonceStaggerDecal = generated.getNonceStaggerDecal(commonStart + i);

std::streamoff referenceNonceStaggerOffset = reference.getNonceStaggerOffset(commonStart + i);
std::streamoff referenceNonceStaggerDecal = reference.getNonceStaggerDecal(commonStart + i);
generated.seek((std::streamoff)generatedConfig.getNonceStaggerOffset(commonStart + i) + generatedConfig.getNonceStaggerDecal(commonStart + i), std::ios::beg);
reference.seek((std::streamoff)referenceConfig.getNonceStaggerOffset(commonStart + i) + referenceConfig.getNonceStaggerDecal(commonStart + i), std::ios::beg);

for(unsigned int j = 0 ; j < PLOT_SIZE ; j += SCOOP_SIZE) {
generated.seek(generatedNonceStaggerOffset + generatedNonceStaggerDecal + (std::streamoff)j * generated.getStaggerSize());
reference.seek(referenceNonceStaggerOffset + referenceNonceStaggerDecal + (std::streamoff)j * reference.getStaggerSize());

generated.read(generatedBuffer, SCOOP_SIZE);
reference.read(referenceBuffer, SCOOP_SIZE);
generated.read(generatedBuffer.get(), SCOOP_SIZE);
reference.read(referenceBuffer.get(), SCOOP_SIZE);

if(!std::equal(generatedBuffer, generatedBuffer + SCOOP_SIZE, referenceBuffer)) {
if(!std::equal(generatedBuffer.get(), generatedBuffer.get() + SCOOP_SIZE, referenceBuffer.get())) {
throw std::runtime_error("Common nonces doesn't match");
}

generated.seek(((std::streamoff)generatedConfig.getStaggerSize() - 1) * SCOOP_SIZE, std::ios::cur);
reference.seek(((std::streamoff)referenceConfig.getStaggerSize() - 1) * SCOOP_SIZE, std::ios::cur);
}
}

std::cout << std::string(console.str().length(), '\b');
std::cout << "100% (" << commonNb << "/" << commonNb << " nonces)";
std::cout << " " << std::endl << std::endl;
std::cout << std::string(console.str().length(), ' ');
std::cout << std::string(console.str().length(), '\b');

std::cout << "100% (" << commonNb << "/" << commonNb << " nonces)" << std::endl << std::endl;
std::cout << "[OK] The generated plots file has been successfully verified against the provided reference" << std::endl;
} catch(const std::exception& ex) {
std::cout << std::endl;
std::cout << "[ERROR] " << ex.what() << std::endl;
returnCode = -1;
return -1;
}

if(referenceBuffer) { delete[] referenceBuffer; }
if(generatedBuffer) { delete[] generatedBuffer; }

return returnCode;
return 0;
}

}}
Loading

0 comments on commit 4a57735

Please sign in to comment.