#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

@ -155,11 +155,14 @@ public:
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,
CudaLib::version(runtimeVersion).c_str(), CudaLib::version(driverVersion).c_str(), CudaLib::pluginVersion());
devices = CudaLib::devices(cuda.bfactor(), cuda.bsleep());
# ifdef XMRIG_FEATURE_NVML
if (cuda.isNvmlEnabled()) {
if (NvmlLib::init(cuda.nvmlLoader())) {
@ -172,7 +175,7 @@ public:
);
}
else {
printDisabled(kLabel, RED_S " (failed to load NVML)");
printDisabled(kNvmlLabel, RED_S " (failed to load NVML)");
}
}
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
{
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;
const auto &threads = m_threads.get(algorithm);
@ -85,15 +95,16 @@ std::vector<xmrig::CudaLaunchData> xmrig::CudaConfig::get(const Miner *miner, co
return out;
}
out.reserve(threads.count() * 2);
out.reserve(threads.count());
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());
continue;
}
out.emplace_back(miner, algorithm, thread, devices[thread.index()]);
out.emplace_back(miner, algorithm, thread, devices[static_cast<size_t>(index)]);
}
return out;
@ -153,7 +164,7 @@ void xmrig::CudaConfig::generate()
return;
}
const auto devices = CudaLib::devices(bfactor(), bsleep());
const auto devices = CudaLib::devices(bfactor(), bsleep(), m_devicesHint);
if (devices.empty()) {
return;
}

View file

@ -43,16 +43,17 @@ public:
std::vector<CudaLaunchData> get(const Miner *miner, const Algorithm &algorithm, const std::vector<CudaDevice> &devices) const;
void read(const rapidjson::Value &value);
inline bool isEnabled() const { return m_enabled; }
inline bool isShouldSave() const { return m_shouldSave; }
inline const String &loader() const { return m_loader; }
inline const Threads<CudaThreads> &threads() const { return m_threads; }
inline int32_t bfactor() const { return m_bfactor; }
inline int32_t bsleep() const { return m_bsleep; }
inline bool isEnabled() const { return m_enabled; }
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 Threads<CudaThreads> &threads() const { return m_threads; }
inline int32_t bfactor() const { return m_bfactor; }
inline int32_t bsleep() const { return m_bsleep; }
# ifdef XMRIG_FEATURE_NVML
inline bool isNvmlEnabled() const { return m_nvml; }
inline const String &nvmlLoader() const { return m_nvmlLoader; }
inline bool isNvmlEnabled() const { return m_nvml; }
inline const String &nvmlLoader() const { return m_nvmlLoader; }
# endif
private:

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();
if (!count) {
@ -219,10 +219,24 @@ std::vector<xmrig::CudaDevice> xmrig::CudaLib::devices(int32_t bfactor, int32_t
std::vector<CudaDevice> out;
out.reserve(count);
for (uint32_t i = 0; i < count; ++i) {
CudaDevice device(i, bfactor, bsleep);
if (device.isValid()) {
out.emplace_back(std::move(device));
if (hints.empty()) {
for (uint32_t i = 0; i < count; ++i) {
CudaDevice device(i, bfactor, bsleep);
if (device.isValid()) {
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));
}
}
}

View file

@ -85,7 +85,7 @@ public:
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 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 deviceUint(nvid_ctx *ctx, DeviceProperty property) noexcept;
static uint32_t driverVersion() noexcept;