mirror of
https://github.com/xmrig/xmrig.git
synced 2025-03-21 06:38:56 +00:00
Added config option for AVX2 dataset init
-1 = Auto detect 0 = Always disabled 1 = Enabled if AVX2 is supported
This commit is contained in:
parent
410313d933
commit
633aaccd9c
14 changed files with 74 additions and 38 deletions
|
@ -16,6 +16,7 @@
|
||||||
"title": true,
|
"title": true,
|
||||||
"randomx": {
|
"randomx": {
|
||||||
"init": -1,
|
"init": -1,
|
||||||
|
"init-avx2": -1,
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"1gb-pages": false,
|
"1gb-pages": false,
|
||||||
"rdmsr": true,
|
"rdmsr": true,
|
||||||
|
|
|
@ -50,6 +50,7 @@ R"===(
|
||||||
"colors": true,
|
"colors": true,
|
||||||
"randomx": {
|
"randomx": {
|
||||||
"init": -1,
|
"init": -1,
|
||||||
|
"init-avx2": -1,
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"1gb-pages": false,
|
"1gb-pages": false,
|
||||||
"rdmsr": true,
|
"rdmsr": true,
|
||||||
|
|
|
@ -36,12 +36,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "crypto/randomx/virtual_memory.hpp"
|
#include "crypto/randomx/virtual_memory.hpp"
|
||||||
|
|
||||||
static bool hugePagesJIT = false;
|
static bool hugePagesJIT = false;
|
||||||
|
static int optimizedDatasetInit = -1;
|
||||||
|
|
||||||
void randomx_set_huge_pages_jit(bool hugePages)
|
void randomx_set_huge_pages_jit(bool hugePages)
|
||||||
{
|
{
|
||||||
hugePagesJIT = hugePages;
|
hugePagesJIT = hugePages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void randomx_set_optimized_dataset_init(int value)
|
||||||
|
{
|
||||||
|
optimizedDatasetInit = value;
|
||||||
|
}
|
||||||
|
|
||||||
namespace ARMV8A {
|
namespace ARMV8A {
|
||||||
|
|
||||||
constexpr uint32_t B = 0x14000000;
|
constexpr uint32_t B = 0x14000000;
|
||||||
|
@ -98,7 +104,7 @@ static size_t CalcDatasetItemSize()
|
||||||
|
|
||||||
constexpr uint32_t IntRegMap[8] = { 4, 5, 6, 7, 12, 13, 14, 15 };
|
constexpr uint32_t IntRegMap[8] = { 4, 5, 6, 7, 12, 13, 14, 15 };
|
||||||
|
|
||||||
JitCompilerA64::JitCompilerA64(bool hugePagesEnable) :
|
JitCompilerA64::JitCompilerA64(bool hugePagesEnable, bool) :
|
||||||
hugePages(hugePagesJIT && hugePagesEnable),
|
hugePages(hugePagesJIT && hugePagesEnable),
|
||||||
literalPos(ImulRcpLiteralsEnd)
|
literalPos(ImulRcpLiteralsEnd)
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace randomx {
|
||||||
|
|
||||||
class JitCompilerA64 {
|
class JitCompilerA64 {
|
||||||
public:
|
public:
|
||||||
explicit JitCompilerA64(bool hugePagesEnable);
|
explicit JitCompilerA64(bool hugePagesEnable, bool optimizedInitDatasetEnable);
|
||||||
~JitCompilerA64();
|
~JitCompilerA64();
|
||||||
|
|
||||||
void prepare() {}
|
void prepare() {}
|
||||||
|
|
|
@ -35,3 +35,6 @@ void randomx_set_huge_pages_jit(bool)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void randomx_set_optimized_dataset_init(int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace randomx {
|
||||||
|
|
||||||
class JitCompilerFallback {
|
class JitCompilerFallback {
|
||||||
public:
|
public:
|
||||||
explicit JitCompilerFallback(bool) {
|
explicit JitCompilerFallback(bool, bool) {
|
||||||
throw std::runtime_error("JIT compilation is not supported on this platform");
|
throw std::runtime_error("JIT compilation is not supported on this platform");
|
||||||
}
|
}
|
||||||
void prepare() {}
|
void prepare() {}
|
||||||
|
|
|
@ -52,12 +52,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool hugePagesJIT = false;
|
static bool hugePagesJIT = false;
|
||||||
|
static int optimizedDatasetInit = -1;
|
||||||
|
|
||||||
void randomx_set_huge_pages_jit(bool hugePages)
|
void randomx_set_huge_pages_jit(bool hugePages)
|
||||||
{
|
{
|
||||||
hugePagesJIT = hugePages;
|
hugePagesJIT = hugePages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void randomx_set_optimized_dataset_init(int value)
|
||||||
|
{
|
||||||
|
optimizedDatasetInit = value;
|
||||||
|
}
|
||||||
|
|
||||||
namespace randomx {
|
namespace randomx {
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -209,32 +215,41 @@ namespace randomx {
|
||||||
static std::atomic<size_t> codeOffset;
|
static std::atomic<size_t> codeOffset;
|
||||||
constexpr size_t codeOffsetIncrement = 59 * 64;
|
constexpr size_t codeOffsetIncrement = 59 * 64;
|
||||||
|
|
||||||
JitCompilerX86::JitCompilerX86(bool hugePagesEnable) {
|
JitCompilerX86::JitCompilerX86(bool hugePagesEnable, bool optimizedInitDatasetEnable) {
|
||||||
BranchesWithin32B = xmrig::Cpu::info()->jccErratum();
|
BranchesWithin32B = xmrig::Cpu::info()->jccErratum();
|
||||||
|
|
||||||
hasAVX = xmrig::Cpu::info()->hasAVX();
|
hasAVX = xmrig::Cpu::info()->hasAVX();
|
||||||
hasAVX2 = xmrig::Cpu::info()->hasAVX2();
|
hasAVX2 = xmrig::Cpu::info()->hasAVX2();
|
||||||
|
|
||||||
// Set to false by default
|
// Disable by default
|
||||||
initDatasetAVX2 = false;
|
initDatasetAVX2 = false;
|
||||||
|
|
||||||
|
if (optimizedInitDatasetEnable) {
|
||||||
|
// Dataset init using AVX2:
|
||||||
|
// -1 = Auto detect
|
||||||
|
// 0 = Always disabled
|
||||||
|
// +1 = Always enabled
|
||||||
|
if (optimizedDatasetInit > 0) {
|
||||||
|
initDatasetAVX2 = true;
|
||||||
|
}
|
||||||
|
else if (optimizedDatasetInit < 0) {
|
||||||
xmrig::ICpuInfo::Vendor vendor = xmrig::Cpu::info()->vendor();
|
xmrig::ICpuInfo::Vendor vendor = xmrig::Cpu::info()->vendor();
|
||||||
xmrig::ICpuInfo::Arch arch = xmrig::Cpu::info()->arch();
|
xmrig::ICpuInfo::Arch arch = xmrig::Cpu::info()->arch();
|
||||||
|
|
||||||
if (vendor == xmrig::ICpuInfo::VENDOR_INTEL) {
|
if (vendor == xmrig::ICpuInfo::VENDOR_INTEL) {
|
||||||
// AVX2 init is faster on Intel CPUs without HT
|
// AVX2 init is faster on Intel CPUs without HT
|
||||||
initDatasetAVX2 = xmrig::Cpu::info()->cores() == xmrig::Cpu::info()->threads();
|
initDatasetAVX2 = (xmrig::Cpu::info()->cores() == xmrig::Cpu::info()->threads());
|
||||||
}
|
}
|
||||||
else if (vendor == xmrig::ICpuInfo::VENDOR_AMD) {
|
else if (vendor == xmrig::ICpuInfo::VENDOR_AMD) {
|
||||||
switch (arch) {
|
switch (arch) {
|
||||||
case xmrig::ICpuInfo::ARCH_ZEN:
|
case xmrig::ICpuInfo::ARCH_ZEN:
|
||||||
case xmrig::ICpuInfo::ARCH_ZEN_PLUS:
|
case xmrig::ICpuInfo::ARCH_ZEN_PLUS:
|
||||||
// AVX2 init is slow on Zen/Zen+
|
// AVX2 init is slower on Zen/Zen+
|
||||||
initDatasetAVX2 = false;
|
initDatasetAVX2 = false;
|
||||||
break;
|
break;
|
||||||
case xmrig::ICpuInfo::ARCH_ZEN2:
|
case xmrig::ICpuInfo::ARCH_ZEN2:
|
||||||
// AVX2 init is faster on Zen2 without SMT (mobile CPUs)
|
// AVX2 init is faster on Zen2 without SMT (mobile CPUs)
|
||||||
initDatasetAVX2 = xmrig::Cpu::info()->cores() == xmrig::Cpu::info()->threads();
|
initDatasetAVX2 = (xmrig::Cpu::info()->cores() == xmrig::Cpu::info()->threads());
|
||||||
break;
|
break;
|
||||||
case xmrig::ICpuInfo::ARCH_ZEN3:
|
case xmrig::ICpuInfo::ARCH_ZEN3:
|
||||||
// AVX2 init is faster on Zen3
|
// AVX2 init is faster on Zen3
|
||||||
|
@ -242,8 +257,10 @@ namespace randomx {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sorry low-end Intel CPUs
|
// Sorry, low-end Intel CPUs
|
||||||
if (!hasAVX2) {
|
if (!hasAVX2) {
|
||||||
initDatasetAVX2 = false;
|
initDatasetAVX2 = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace randomx {
|
||||||
|
|
||||||
class JitCompilerX86 {
|
class JitCompilerX86 {
|
||||||
public:
|
public:
|
||||||
explicit JitCompilerX86(bool hugePagesEnable);
|
explicit JitCompilerX86(bool hugePagesEnable, bool optimizedInitDatasetEnable);
|
||||||
~JitCompilerX86();
|
~JitCompilerX86();
|
||||||
void prepare();
|
void prepare();
|
||||||
void generateProgram(Program&, ProgramConfiguration&, uint32_t);
|
void generateProgram(Program&, ProgramConfiguration&, uint32_t);
|
||||||
|
|
|
@ -381,7 +381,7 @@ extern "C" {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RANDOMX_FLAG_JIT:
|
case RANDOMX_FLAG_JIT:
|
||||||
cache->jit = new randomx::JitCompiler(false);
|
cache->jit = new randomx::JitCompiler(false, true);
|
||||||
cache->initialize = &randomx::initCacheCompile;
|
cache->initialize = &randomx::initCacheCompile;
|
||||||
cache->datasetInit = nullptr;
|
cache->datasetInit = nullptr;
|
||||||
cache->memory = memory;
|
cache->memory = memory;
|
||||||
|
|
|
@ -170,6 +170,7 @@ void randomx_apply_config(const T& config)
|
||||||
|
|
||||||
void randomx_set_scratchpad_prefetch_mode(int mode);
|
void randomx_set_scratchpad_prefetch_mode(int mode);
|
||||||
void randomx_set_huge_pages_jit(bool hugePages);
|
void randomx_set_huge_pages_jit(bool hugePages);
|
||||||
|
void randomx_set_optimized_dataset_init(int value);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace randomx {
|
||||||
protected:
|
protected:
|
||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
JitCompiler compiler{ true };
|
JitCompiler compiler{ true, false };
|
||||||
};
|
};
|
||||||
|
|
||||||
using CompiledVmDefault = CompiledVm<1>;
|
using CompiledVmDefault = CompiledVm<1>;
|
||||||
|
|
|
@ -96,6 +96,7 @@ bool xmrig::Rx::init(const T &seed, const RxConfig &config, const CpuConfig &cpu
|
||||||
|
|
||||||
randomx_set_scratchpad_prefetch_mode(config.scratchpadPrefetchMode());
|
randomx_set_scratchpad_prefetch_mode(config.scratchpadPrefetchMode());
|
||||||
randomx_set_huge_pages_jit(cpu.isHugePagesJit());
|
randomx_set_huge_pages_jit(cpu.isHugePagesJit());
|
||||||
|
randomx_set_optimized_dataset_init(config.initDatasetAVX2());
|
||||||
|
|
||||||
if (!msrInitialized) {
|
if (!msrInitialized) {
|
||||||
msrEnabled = msrInit(config, cpu.threads().get(seed.algorithm()).data());
|
msrEnabled = msrInit(config, cpu.threads().get(seed.algorithm()).data());
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
const char *RxConfig::kInit = "init";
|
const char *RxConfig::kInit = "init";
|
||||||
|
const char *RxConfig::kInitAVX2 = "init-avx2";
|
||||||
const char *RxConfig::kField = "randomx";
|
const char *RxConfig::kField = "randomx";
|
||||||
const char *RxConfig::kMode = "mode";
|
const char *RxConfig::kMode = "mode";
|
||||||
const char *RxConfig::kOneGbPages = "1gb-pages";
|
const char *RxConfig::kOneGbPages = "1gb-pages";
|
||||||
|
@ -87,6 +88,7 @@ bool xmrig::RxConfig::read(const rapidjson::Value &value)
|
||||||
{
|
{
|
||||||
if (value.IsObject()) {
|
if (value.IsObject()) {
|
||||||
m_threads = Json::getInt(value, kInit, m_threads);
|
m_threads = Json::getInt(value, kInit, m_threads);
|
||||||
|
m_initDatasetAVX2 = Json::getInt(value, kInitAVX2, m_initDatasetAVX2);
|
||||||
m_mode = readMode(Json::getValue(value, kMode));
|
m_mode = readMode(Json::getValue(value, kMode));
|
||||||
m_rdmsr = Json::getBool(value, kRdmsr, m_rdmsr);
|
m_rdmsr = Json::getBool(value, kRdmsr, m_rdmsr);
|
||||||
|
|
||||||
|
@ -141,6 +143,7 @@ rapidjson::Value xmrig::RxConfig::toJSON(rapidjson::Document &doc) const
|
||||||
|
|
||||||
Value obj(kObjectType);
|
Value obj(kObjectType);
|
||||||
obj.AddMember(StringRef(kInit), m_threads, allocator);
|
obj.AddMember(StringRef(kInit), m_threads, allocator);
|
||||||
|
obj.AddMember(StringRef(kInitAVX2), m_initDatasetAVX2, allocator);
|
||||||
obj.AddMember(StringRef(kMode), StringRef(modeName()), allocator);
|
obj.AddMember(StringRef(kMode), StringRef(modeName()), allocator);
|
||||||
obj.AddMember(StringRef(kOneGbPages), m_oneGbPages, allocator);
|
obj.AddMember(StringRef(kOneGbPages), m_oneGbPages, allocator);
|
||||||
obj.AddMember(StringRef(kRdmsr), m_rdmsr, allocator);
|
obj.AddMember(StringRef(kRdmsr), m_rdmsr, allocator);
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
static const char *kCacheQoS;
|
static const char *kCacheQoS;
|
||||||
static const char *kField;
|
static const char *kField;
|
||||||
static const char *kInit;
|
static const char *kInit;
|
||||||
|
static const char *kInitAVX2;
|
||||||
static const char *kMode;
|
static const char *kMode;
|
||||||
static const char *kOneGbPages;
|
static const char *kOneGbPages;
|
||||||
static const char *kRdmsr;
|
static const char *kRdmsr;
|
||||||
|
@ -83,6 +84,7 @@ public:
|
||||||
const char *modeName() const;
|
const char *modeName() const;
|
||||||
uint32_t threads(uint32_t limit = 100) const;
|
uint32_t threads(uint32_t limit = 100) const;
|
||||||
|
|
||||||
|
inline int initDatasetAVX2() const { return m_initDatasetAVX2; }
|
||||||
inline bool isOneGbPages() const { return m_oneGbPages; }
|
inline bool isOneGbPages() const { return m_oneGbPages; }
|
||||||
inline bool rdmsr() const { return m_rdmsr; }
|
inline bool rdmsr() const { return m_rdmsr; }
|
||||||
inline bool wrmsr() const { return m_wrmsr; }
|
inline bool wrmsr() const { return m_wrmsr; }
|
||||||
|
@ -115,6 +117,7 @@ private:
|
||||||
bool m_oneGbPages = false;
|
bool m_oneGbPages = false;
|
||||||
bool m_rdmsr = true;
|
bool m_rdmsr = true;
|
||||||
int m_threads = -1;
|
int m_threads = -1;
|
||||||
|
int m_initDatasetAVX2 = -1;
|
||||||
Mode m_mode = AutoMode;
|
Mode m_mode = AutoMode;
|
||||||
|
|
||||||
ScratchpadPrefetchMode m_scratchpadPrefetchMode = ScratchpadPrefetchT0;
|
ScratchpadPrefetchMode m_scratchpadPrefetchMode = ScratchpadPrefetchT0;
|
||||||
|
|
Loading…
Reference in a new issue