Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-GPU and genproclimit for maximizing GPU usage support #57

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 94 additions & 3 deletions src/libstratum/ZcashStratum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,100 @@ void ZcashMiner::start()
}

minerThreads = new boost::thread_group();
for (int i = 0; i < nThreads; i++) {
minerThreads->create_thread(boost::bind(&ZcashMinerThread, this, nThreads, i, conf));
}

// If using GPU
if(conf.useGPU) {

conf.currentPlatform = 0;
conf.currentDevice = conf.selGPU;

std::vector<cl::Platform> platforms = cl_zogminer::getPlatforms();

// use all available GPUs
if(conf.allGPU) {

int devicesFound = 0;
unsigned numPlatforms = platforms.size();

for(unsigned platform = 0; platform < numPlatforms; ++platform) {

std::vector<cl::Device> devices = cl_zogminer::getDevices(platforms, platform);
unsigned noDevices = devices.size();
devicesFound += noDevices;
for(unsigned device = 0; device < noDevices; ++device) {

conf.currentPlatform = platform;
conf.currentDevice = device;

cl_ulong result;
devices[device].getInfo(CL_DEVICE_GLOBAL_MEM_SIZE, &result);

int maxThreads = nThreads;
if (!conf.forceGenProcLimit) {
if (result > 7500000000) {
maxThreads = std::min(4, nThreads);
} else if (result > 5500000000) {
maxThreads = std::min(3, nThreads);
} else if (result > 3500000000) {
maxThreads = std::min(2, nThreads);
} else {
maxThreads = std::min(1, nThreads);
}
}

LogPrintf("ZcashMiner GPU[%d][%d] MemLimit: %s nThreads: %d\n", platform, device, std::to_string(result), maxThreads);

for (int i = 0; i < maxThreads; i++)
minerThreads->create_thread(boost::bind(&ZcashMinerThread, this, nThreads, i, conf));

}
}

if (devicesFound <= 0) {
LogPrintf("ZcashMiner ERROR, No OpenCL devices found!\n");
}

} else {

// mine on specified GPU device
std::vector<cl::Device> devices = cl_zogminer::getDevices(platforms, conf.currentPlatform);

if (devices.size() > conf.currentDevice) {

cl_ulong result;
devices[conf.currentDevice].getInfo(CL_DEVICE_GLOBAL_MEM_SIZE, &result);

int maxThreads = nThreads;
if (!conf.forceGenProcLimit) {
if (result > 7500000000) {
maxThreads = std::min(4, nThreads);
} else if (result > 5500000000) {
maxThreads = std::min(3, nThreads);
} else if (result > 3500000000) {
maxThreads = std::min(2, nThreads);
} else {
maxThreads = std::min(1, nThreads);
}
}

LogPrintf("ZcashMiner GPU[%d][%d] MemLimit: %s nThreads: %d\n", conf.currentPlatform, conf.currentDevice, std::to_string(result), maxThreads);

for (int i = 0; i < maxThreads; i++)
minerThreads->create_thread(boost::bind(&ZcashMinerThread, this, nThreads, i, conf));

} else {
LogPrintf("ZcashMiner ERROR, No OpenCL devices found!\n");
}

}

} else {

for (int i = 0; i < nThreads; i++)
minerThreads->create_thread(boost::bind(&ZcashMinerThread, this, nThreads, i, conf));

}

}

void ZcashMiner::stop()
Expand Down
4 changes: 2 additions & 2 deletions src/libzogminer/cl_zogminer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class cl_zogminer
static unsigned getNumDevices(unsigned _platformId = 0);
static std::string platform_info(unsigned _platformId = 0, unsigned _deviceId = 0);
static void listDevices();
static std::vector<cl::Device> getDevices(std::vector<cl::Platform> const& _platforms, unsigned _platformId);
static std::vector<cl::Platform> getPlatforms();

// Currently just prints memory of the GPU
static bool configureGPU(
Expand Down Expand Up @@ -112,8 +114,6 @@ class cl_zogminer
static const size_t z_collision_bit_length = z_n / (z_k + 1);
static const eh_index z_N = 1 << (z_collision_bit_length + 1);

static std::vector<cl::Device> getDevices(std::vector<cl::Platform> const& _platforms, unsigned _platformId);
static std::vector<cl::Platform> getPlatforms();
int compare_indices32(uint32_t* a, uint32_t* b, size_t n_current_indices) {
for(size_t i = 0; i < n_current_indices; ++i, ++a, ++b) {
if(*a < *b) {
Expand Down
6 changes: 5 additions & 1 deletion src/libzogminer/gpuconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class GPUConfig {
//~GPUConfig();

bool useGPU;
int64_t selGPU;
unsigned selGPU;
bool allGPU;
bool forceGenProcLimit;
unsigned currentPlatform;
unsigned currentDevice;
unsigned globalWorkSize;
unsigned workgroupSize;

Expand Down
9 changes: 6 additions & 3 deletions src/standaloneminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ int main(int argc, char* argv[])

GPUConfig conf;

conf.useGPU = GetBoolArg("-G", false);
conf.useGPU = GetBoolArg("-G", false) || GetBoolArg("-GPU", false);
conf.selGPU = GetArg("-S", 0);
conf.allGPU = GetBoolArg("-allgpu", false);
conf.forceGenProcLimit = GetBoolArg("-forcenolimit", false);
int nThreads = GetArg("-genproclimit", 1);
//std::cout << GPU << " " << selGPU << std::endl;

// Zcash debugging
Expand Down Expand Up @@ -290,7 +293,7 @@ int main(int argc, char* argv[])
return false;
}

ZcashMiner miner(GetArg("-genproclimit", 1), conf);
ZcashMiner miner(GetArg("-genproclimit", 1), conf);
ZcashStratumClient sc {
&miner, host, port,
GetArg("-user", "x"),
Expand All @@ -303,7 +306,7 @@ int main(int argc, char* argv[])
});

scSig = &sc;
signal(SIGINT, stratum_sigint_handler);
signal(SIGINT, stratum_sigint_handler);

while(sc.isRunning()) {
MilliSleep(1000);
Expand Down