#1274 Added --cuda-devices command line option.

This commit is contained in:
XMRig 2019-11-13 00:40:22 +07:00
parent 74d62c92cd
commit ed4cfd55ac
10 changed files with 61 additions and 25 deletions

View file

@ -74,7 +74,7 @@ API:
OpenCL backend: OpenCL backend:
--opencl enable OpenCL mining backend --opencl enable OpenCL mining backend
--opencl-devices=N list of OpenCL devices to use --opencl-devices=N comma separated list of OpenCL devices to use
--opencl-platform=N OpenCL platform index or name --opencl-platform=N OpenCL platform index or name
--opencl-loader=PATH path to OpenCL-ICD-Loader (OpenCL.dll or libOpenCL.so) --opencl-loader=PATH path to OpenCL-ICD-Loader (OpenCL.dll or libOpenCL.so)
--opencl-no-cache disable OpenCL cache --opencl-no-cache disable OpenCL cache
@ -83,6 +83,7 @@ OpenCL backend:
CUDA backend: CUDA backend:
--cuda enable CUDA mining backend --cuda enable CUDA mining backend
--cuda-loader=PATH path to CUDA plugin (xmrig-cuda.dll or libxmrig-cuda.so) --cuda-loader=PATH path to CUDA plugin (xmrig-cuda.dll or libxmrig-cuda.so)
--cuda-devices=N comma separated list of CUDA devices to use
--no-nvml disable NVML (NVIDIA Management Library) support --no-nvml disable NVML (NVIDIA Management Library) support
Logging: Logging:

View file

@ -155,11 +155,14 @@ public:
return; return;
} }
devices = CudaLib::devices(cuda.bfactor(), cuda.bsleep(), cuda.devicesHint());
if (devices.empty()) {
return printDisabled(kLabel, RED_S " (no devices)");
}
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") WHITE_BOLD("%s") "/" WHITE_BOLD("%s") BLACK_BOLD("/%s"), kLabel, Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") WHITE_BOLD("%s") "/" WHITE_BOLD("%s") BLACK_BOLD("/%s"), kLabel,
CudaLib::version(runtimeVersion).c_str(), CudaLib::version(driverVersion).c_str(), CudaLib::pluginVersion()); CudaLib::version(runtimeVersion).c_str(), CudaLib::version(driverVersion).c_str(), CudaLib::pluginVersion());
devices = CudaLib::devices(cuda.bfactor(), cuda.bsleep());
# ifdef XMRIG_FEATURE_NVML # ifdef XMRIG_FEATURE_NVML
if (cuda.isNvmlEnabled()) { if (cuda.isNvmlEnabled()) {
if (NvmlLib::init(cuda.nvmlLoader())) { if (NvmlLib::init(cuda.nvmlLoader())) {
@ -172,7 +175,7 @@ public:
); );
} }
else { else {
printDisabled(kLabel, RED_S " (failed to load NVML)"); printDisabled(kNvmlLabel, RED_S " (failed to load NVML)");
} }
} }
else { else {

View file

@ -78,6 +78,16 @@ rapidjson::Value xmrig::CudaConfig::toJSON(rapidjson::Document &doc) const
std::vector<xmrig::CudaLaunchData> xmrig::CudaConfig::get(const Miner *miner, const Algorithm &algorithm, const std::vector<CudaDevice> &devices) const std::vector<xmrig::CudaLaunchData> xmrig::CudaConfig::get(const Miner *miner, const Algorithm &algorithm, const std::vector<CudaDevice> &devices) const
{ {
auto deviceIndex = [&devices](uint32_t index) -> int {
for (uint32_t i = 0; i < devices.size(); ++i) {
if (devices[i].index() == index) {
return i;
}
}
return -1;
};
std::vector<CudaLaunchData> out; std::vector<CudaLaunchData> out;
const auto &threads = m_threads.get(algorithm); const auto &threads = m_threads.get(algorithm);
@ -85,15 +95,16 @@ std::vector<xmrig::CudaLaunchData> xmrig::CudaConfig::get(const Miner *miner, co
return out; return out;
} }
out.reserve(threads.count() * 2); out.reserve(threads.count());
for (const auto &thread : threads.data()) { for (const auto &thread : threads.data()) {
if (thread.index() >= devices.size()) { const int index = deviceIndex(thread.index());
if (index == -1) {
LOG_INFO("%s" YELLOW(" skip non-existing device with index ") YELLOW_BOLD("%u"), cuda_tag(), thread.index()); LOG_INFO("%s" YELLOW(" skip non-existing device with index ") YELLOW_BOLD("%u"), cuda_tag(), thread.index());
continue; continue;
} }
out.emplace_back(miner, algorithm, thread, devices[thread.index()]); out.emplace_back(miner, algorithm, thread, devices[static_cast<size_t>(index)]);
} }
return out; return out;
@ -153,7 +164,7 @@ void xmrig::CudaConfig::generate()
return; return;
} }
const auto devices = CudaLib::devices(bfactor(), bsleep()); const auto devices = CudaLib::devices(bfactor(), bsleep(), m_devicesHint);
if (devices.empty()) { if (devices.empty()) {
return; return;
} }

View file

@ -45,6 +45,7 @@ public:
inline bool isEnabled() const { return m_enabled; } inline bool isEnabled() const { return m_enabled; }
inline bool isShouldSave() const { return m_shouldSave; } inline bool isShouldSave() const { return m_shouldSave; }
inline const std::vector<uint32_t> &devicesHint() const { return m_devicesHint; }
inline const String &loader() const { return m_loader; } inline const String &loader() const { return m_loader; }
inline const Threads<CudaThreads> &threads() const { return m_threads; } inline const Threads<CudaThreads> &threads() const { return m_threads; }
inline int32_t bfactor() const { return m_bfactor; } inline int32_t bfactor() const { return m_bfactor; }

View file

@ -209,7 +209,7 @@ std::string xmrig::CudaLib::version(uint32_t version)
} }
std::vector<xmrig::CudaDevice> xmrig::CudaLib::devices(int32_t bfactor, int32_t bsleep) noexcept std::vector<xmrig::CudaDevice> xmrig::CudaLib::devices(int32_t bfactor, int32_t bsleep, const std::vector<uint32_t> &hints) noexcept
{ {
const uint32_t count = deviceCount(); const uint32_t count = deviceCount();
if (!count) { if (!count) {
@ -219,12 +219,26 @@ std::vector<xmrig::CudaDevice> xmrig::CudaLib::devices(int32_t bfactor, int32_t
std::vector<CudaDevice> out; std::vector<CudaDevice> out;
out.reserve(count); out.reserve(count);
if (hints.empty()) {
for (uint32_t i = 0; i < count; ++i) { for (uint32_t i = 0; i < count; ++i) {
CudaDevice device(i, bfactor, bsleep); CudaDevice device(i, bfactor, bsleep);
if (device.isValid()) { if (device.isValid()) {
out.emplace_back(std::move(device)); out.emplace_back(std::move(device));
} }
} }
}
else {
for (const uint32_t i : hints) {
if (i >= count) {
continue;
}
CudaDevice device(i, bfactor, bsleep);
if (device.isValid()) {
out.emplace_back(std::move(device));
}
}
}
return out; return out;
} }

View file

@ -85,7 +85,7 @@ public:
static int32_t deviceInt(nvid_ctx *ctx, DeviceProperty property) noexcept; static int32_t deviceInt(nvid_ctx *ctx, DeviceProperty property) noexcept;
static nvid_ctx *alloc(uint32_t id, int32_t bfactor, int32_t bsleep) noexcept; static nvid_ctx *alloc(uint32_t id, int32_t bfactor, int32_t bsleep) noexcept;
static std::string version(uint32_t version); static std::string version(uint32_t version);
static std::vector<CudaDevice> devices(int32_t bfactor, int32_t bsleep) noexcept; static std::vector<CudaDevice> devices(int32_t bfactor, int32_t bsleep, const std::vector<uint32_t> &hints) noexcept;
static uint32_t deviceCount() noexcept; static uint32_t deviceCount() noexcept;
static uint32_t deviceUint(nvid_ctx *ctx, DeviceProperty property) noexcept; static uint32_t deviceUint(nvid_ctx *ctx, DeviceProperty property) noexcept;
static uint32_t driverVersion() noexcept; static uint32_t driverVersion() noexcept;

View file

@ -187,10 +187,14 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
# ifdef XMRIG_FEATURE_CUDA # ifdef XMRIG_FEATURE_CUDA
case IConfig::CudaKey: /* --cuda */ case IConfig::CudaKey: /* --cuda */
return set(doc, kCuda, "enabled", true); return set(doc, kCuda, kEnabled, true);
case IConfig::CudaLoaderKey: /* --cuda-loader */ case IConfig::CudaLoaderKey: /* --cuda-loader */
return set(doc, kCuda, "loader", arg); return set(doc, kCuda, "loader", arg);
case IConfig::CudaDevicesKey: /* --cuda-devices */
set(doc, kCuda, kEnabled, true);
return set(doc, kCuda, "devices-hint", arg);
# endif # endif
# ifdef XMRIG_FEATURE_NVML # ifdef XMRIG_FEATURE_NVML

View file

@ -107,6 +107,7 @@ static const option options[] = {
# ifdef XMRIG_FEATURE_CUDA # ifdef XMRIG_FEATURE_CUDA
{ "cuda", 0, nullptr, IConfig::CudaKey }, { "cuda", 0, nullptr, IConfig::CudaKey },
{ "cuda-loader", 1, nullptr, IConfig::CudaLoaderKey }, { "cuda-loader", 1, nullptr, IConfig::CudaLoaderKey },
{ "cuda-devices", 1, nullptr, IConfig::CudaDevicesKey },
# endif # endif
# ifdef XMRIG_FEATURE_NVML # ifdef XMRIG_FEATURE_NVML
{ "no-nvml", 0, nullptr, IConfig::NvmlKey }, { "no-nvml", 0, nullptr, IConfig::NvmlKey },

View file

@ -101,7 +101,7 @@ static inline const std::string &usage()
# ifdef XMRIG_FEATURE_OPENCL # ifdef XMRIG_FEATURE_OPENCL
u += "\nOpenCL backend:\n"; u += "\nOpenCL backend:\n";
u += " --opencl enable OpenCL mining backend\n"; u += " --opencl enable OpenCL mining backend\n";
u += " --opencl-devices=N list of OpenCL devices to use\n"; u += " --opencl-devices=N comma separated list of OpenCL devices to use\n";
u += " --opencl-platform=N OpenCL platform index or name\n"; u += " --opencl-platform=N OpenCL platform index or name\n";
u += " --opencl-loader=PATH path to OpenCL-ICD-Loader (OpenCL.dll or libOpenCL.so)\n"; u += " --opencl-loader=PATH path to OpenCL-ICD-Loader (OpenCL.dll or libOpenCL.so)\n";
u += " --opencl-no-cache disable OpenCL cache\n"; u += " --opencl-no-cache disable OpenCL cache\n";
@ -112,6 +112,7 @@ static inline const std::string &usage()
u += "\nCUDA backend:\n"; u += "\nCUDA backend:\n";
u += " --cuda enable CUDA mining backend\n"; u += " --cuda enable CUDA mining backend\n";
u += " --cuda-loader=PATH path to CUDA plugin (xmrig-cuda.dll or libxmrig-cuda.so)\n"; u += " --cuda-loader=PATH path to CUDA plugin (xmrig-cuda.dll or libxmrig-cuda.so)\n";
u += " --cuda-devices=N comma separated list of CUDA devices to use\n";
# endif # endif
# ifdef XMRIG_FEATURE_NVML # ifdef XMRIG_FEATURE_NVML
u += " --no-nvml disable NVML (NVIDIA Management Library) support\n"; u += " --no-nvml disable NVML (NVIDIA Management Library) support\n";