-
Notifications
You must be signed in to change notification settings - Fork 27
/
CommandListDevices.cpp
94 lines (77 loc) · 3.68 KB
/
CommandListDevices.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
/*
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 <cstdlib>
#include <memory>
#include <exception>
#include "util.h"
#include "OpenclError.h"
#include "OpenclPlatform.h"
#include "OpenclDevice.h"
#include "CommandListDevices.h"
namespace cryo {
namespace gpuPlotGenerator {
CommandListDevices::CommandListDevices()
: Command("List the available OpenCL devices of the specified platform.") {
}
CommandListDevices::CommandListDevices(const CommandListDevices& p_command)
: Command(p_command) {
}
CommandListDevices::~CommandListDevices() throw () {
}
void CommandListDevices::help() const {
std::cout << "Usage: ./gpuPlotGenerator listDevices <platformId>" << std::endl;
std::cout << " List the available OpenCL devices of the specified platform." << std::endl;
std::cout << "Parameters:" << std::endl;
std::cout << " - platformId: The id of the platform to scan." << std::endl;
}
int CommandListDevices::execute(const std::vector<std::string>& p_args) {
if(p_args.size() < 1) {
help();
return -1;
}
try {
std::size_t platformId = std::atol(p_args[0].c_str());
std::vector<std::shared_ptr<OpenclPlatform>> platforms(OpenclPlatform::list());
if(platformId >= platforms.size()) {
throw std::runtime_error("No platform found with the provided id");
}
std::vector<unsigned long long> sizeUnits {1024, 1024, 1024};
std::vector<std::string> sizeLabels {"KB", "MB", "GB", "TB"};
std::vector<std::shared_ptr<OpenclDevice>> devices(OpenclDevice::list(platforms[platformId]));
std::cout << "Devices number: " << devices.size() << std::endl;
std::size_t i = 0;
for(const std::shared_ptr<OpenclDevice>& device : devices) {
std::cout << "----" << std::endl;
std::cout << "Id: " << i++ << std::endl;
std::cout << "Type: " << device->getType() << std::endl;
std::cout << "Name: " << device->getName() << std::endl;
std::cout << "Vendor: " << device->getVendor() << std::endl;
std::cout << "Version: " << device->getVersion() << std::endl;
std::cout << "Driver version: " << device->getDriverVersion() << std::endl;
std::cout << "Max clock frequency: " << device->getMaxClockFrequency() << "MHz" << std::endl;
std::cout << "Max compute units: " << device->getMaxComputeUnits() << std::endl;
std::cout << "Global memory size: " << cryo::util::formatValue(device->getGlobalMemorySize() >> 10, sizeUnits, sizeLabels) << std::endl;
std::cout << "Max memory allocation size: " << cryo::util::formatValue(device->getMaxMemoryAllocationSize() >> 10, sizeUnits, sizeLabels) << std::endl;
std::cout << "Max work group size: " << device->getMaxWorkGroupSize() << std::endl;
std::cout << "Local memory size: " << cryo::util::formatValue(device->getLocalMemorySize() >> 10, sizeUnits, sizeLabels) << std::endl;
std::vector<std::size_t> maxWorkItemSizes(device->getMaxWorkItemSizes());
std::cout << "Max work-item sizes: (" << cryo::util::join(maxWorkItemSizes.begin(), maxWorkItemSizes.end(), ", ") << ")" << 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;
}
}}