Skip to content
Snippets Groups Projects
Unverified Commit b862dc25 authored by fireice-uk's avatar fireice-uk Committed by GitHub
Browse files

Merge pull request #1898 from psychocrypt/topic-supportMultipleCUDALibraries

NVIDIA: support for multiple CUDA libs
parents db55e8a3 732b0e41
No related branches found
No related tags found
No related merge requests found
...@@ -63,10 +63,35 @@ std::vector<iBackend*>* BackendConnector::thread_starter(miner_work& pWork) ...@@ -63,10 +63,35 @@ std::vector<iBackend*>* BackendConnector::thread_starter(miner_work& pWork)
#ifndef CONF_NO_CUDA #ifndef CONF_NO_CUDA
if(params::inst().useNVIDIA) if(params::inst().useNVIDIA)
{ {
plugin nvidiaplugin("NVIDIA", "xmrstak_cuda_backend"); plugin nvidiaplugin;
std::vector<iBackend*>* nvidiaThreads = nvidiaplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst()); std::vector<iBackend*>* nvidiaThreads;
pvThreads->insert(std::end(*pvThreads), std::begin(*nvidiaThreads), std::end(*nvidiaThreads)); std::vector<std::string> libNames = {"xmrstak_cuda_backend_cuda10_0", "xmrstak_cuda_backend_cuda9_2", "xmrstak_cuda_backend"};
if(nvidiaThreads->size() == 0) size_t numWorkers = 0u;
for( const auto & name : libNames)
{
printer::inst()->print_msg(L0, "NVIDIA: try to load library '%s'", name.c_str());
nvidiaplugin.load("NVIDIA", name);
std::vector<iBackend*>* nvidiaThreads = nvidiaplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
if(nvidiaThreads != nullptr)
{
pvThreads->insert(std::end(*pvThreads), std::begin(*nvidiaThreads), std::end(*nvidiaThreads));
numWorkers = nvidiaThreads->size();
delete nvidiaThreads;
}
else
{
// remove the plugin if we have found no GPUs
nvidiaplugin.unload();
}
// we found at leat one working GPU
if(numWorkers != 0)
{
printer::inst()->print_msg(L0, "NVIDIA: use library '%s'", name.c_str());
break;
}
}
if(numWorkers == 0)
printer::inst()->print_msg(L0, "WARNING: backend NVIDIA disabled."); printer::inst()->print_msg(L0, "WARNING: backend NVIDIA disabled.");
} }
#endif #endif
...@@ -75,10 +100,17 @@ std::vector<iBackend*>* BackendConnector::thread_starter(miner_work& pWork) ...@@ -75,10 +100,17 @@ std::vector<iBackend*>* BackendConnector::thread_starter(miner_work& pWork)
if(params::inst().useAMD) if(params::inst().useAMD)
{ {
const std::string backendName = xmrstak::params::inst().openCLVendor; const std::string backendName = xmrstak::params::inst().openCLVendor;
plugin amdplugin(backendName, "xmrstak_opencl_backend"); plugin amdplugin;
amdplugin.load(backendName, "xmrstak_opencl_backend");
std::vector<iBackend*>* amdThreads = amdplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst()); std::vector<iBackend*>* amdThreads = amdplugin.startBackend(static_cast<uint32_t>(pvThreads->size()), pWork, environment::inst());
pvThreads->insert(std::end(*pvThreads), std::begin(*amdThreads), std::end(*amdThreads)); size_t numWorkers = 0u;
if(amdThreads->size() == 0) if(amdThreads != nullptr)
{
pvThreads->insert(std::end(*pvThreads), std::begin(*amdThreads), std::end(*amdThreads));
numWorkers = amdThreads->size();
delete amdThreads;
}
if(numWorkers == 0)
printer::inst()->print_msg(L0, "WARNING: backend %s (OpenCL) disabled.", backendName.c_str()); printer::inst()->print_msg(L0, "WARNING: backend %s (OpenCL) disabled.", backendName.c_str());
} }
#endif #endif
......
...@@ -165,6 +165,10 @@ std::vector<iBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor ...@@ -165,6 +165,10 @@ std::vector<iBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor
std::cout<<"WARNING: NVIDIA no device found"<<std::endl; std::cout<<"WARNING: NVIDIA no device found"<<std::endl;
return pvThreads; return pvThreads;
} }
else
{
std::cout<<"NVIDIA: found "<< deviceCount <<" potential device's"<<std::endl;
}
size_t i, n = jconf::inst()->GetGPUThreadCount(); size_t i, n = jconf::inst()->GetGPUThreadCount();
pvThreads->reserve(n); pvThreads->reserve(n);
......
...@@ -27,8 +27,11 @@ namespace xmrstak ...@@ -27,8 +27,11 @@ namespace xmrstak
struct plugin struct plugin
{ {
plugin(const std::string backendName, const std::string libName) : fn_startBackend(nullptr), m_backendName(backendName) plugin() = default;
void load(const std::string backendName, const std::string libName)
{ {
m_backendName = backendName;
#ifdef WIN32 #ifdef WIN32
libBackend = LoadLibrary(TEXT((libName + ".dll").c_str())); libBackend = LoadLibrary(TEXT((libName + ".dll").c_str()));
if(!libBackend) if(!libBackend)
...@@ -81,32 +84,36 @@ struct plugin ...@@ -81,32 +84,36 @@ struct plugin
if(fn_startBackend == nullptr) if(fn_startBackend == nullptr)
{ {
std::vector<iBackend*>* pvThreads = new std::vector<iBackend*>(); std::vector<iBackend*>* pvThreads = new std::vector<iBackend*>();
std::cerr << "WARNING: " << m_backendName << " Backend disabled"<< std::endl;
return pvThreads; return pvThreads;
} }
return fn_startBackend(threadOffset, pWork, env); return fn_startBackend(threadOffset, pWork, env);
} }
void unload()
{
if(libBackend)
{
#ifdef WIN32
FreeLibrary(libBackend);
#else
dlclose(libBackend);
#endif
}
fn_startBackend = nullptr;
}
std::string m_backendName; std::string m_backendName;
typedef std::vector<iBackend*>* (*startBackend_t)(uint32_t threadOffset, miner_work& pWork, environment& env); typedef std::vector<iBackend*>* (*startBackend_t)(uint32_t threadOffset, miner_work& pWork, environment& env);
startBackend_t fn_startBackend; startBackend_t fn_startBackend = nullptr;
#ifdef WIN32 #ifdef WIN32
HINSTANCE libBackend; HINSTANCE libBackend;
#else #else
void *libBackend; void *libBackend = nullptr;
#endif
/* \todo add unload to destructor and change usage of plugin that libs kept open until the miner ends
#ifdef WIN32
FreeLibrary(libBackend);
#else
dlclose(libBackend);
#endif #endif
* */
}; };
} // namespace xmrstak } // namespace xmrstak
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment