From 45412a2ace9fc1bcd5ea7a2da93a70ec869cf812 Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Wed, 18 Dec 2019 16:17:22 -0700 Subject: [PATCH 1/2] Add MoneroV (rx/v) algorithm [based on MoneroOcean/master] --- src/backend/opencl/cl/cn/algorithm.cl | 5 +- src/backend/opencl/cl/rx/randomx.cl | 2 + .../opencl/cl/rx/randomx_constants_v.h | 96 +++++++++++++++++++ src/crypto/common/Algorithm.cpp | 4 + src/crypto/common/Algorithm.h | 1 + src/crypto/randomx/randomx.cpp | 6 ++ src/crypto/randomx/randomx.h | 2 + src/crypto/rx/RxAlgo.cpp | 3 + 8 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 src/backend/opencl/cl/rx/randomx_constants_v.h diff --git a/src/backend/opencl/cl/cn/algorithm.cl b/src/backend/opencl/cl/cn/algorithm.cl index a1bed3cc4..4f33a6805 100644 --- a/src/backend/opencl/cl/cn/algorithm.cl +++ b/src/backend/opencl/cl/cn/algorithm.cl @@ -21,8 +21,9 @@ #define ALGO_RX_LOKI 20 #define ALGO_RX_ARQMA 21 #define ALGO_RX_SFX 22 -#define ALGO_AR2_CHUKWA 23 -#define ALGO_AR2_WRKZ 24 +#define ALGO_RX_V 23 +#define ALGO_AR2_CHUKWA 24 +#define ALGO_AR2_WRKZ 25 #define FAMILY_UNKNOWN 0 #define FAMILY_CN 1 diff --git a/src/backend/opencl/cl/rx/randomx.cl b/src/backend/opencl/cl/rx/randomx.cl index 6fee74edf..b62f78fca 100644 --- a/src/backend/opencl/cl/rx/randomx.cl +++ b/src/backend/opencl/cl/rx/randomx.cl @@ -8,6 +8,8 @@ #include "randomx_constants_loki.h" #elif (ALGO == ALGO_RX_ARQMA) #include "randomx_constants_arqma.h" +#elif (ALGO == ALGO_RX_V) +#include "randomx_constants_v.h" #endif #include "aes.cl" diff --git a/src/backend/opencl/cl/rx/randomx_constants_v.h b/src/backend/opencl/cl/rx/randomx_constants_v.h new file mode 100644 index 000000000..1967a8c2c --- /dev/null +++ b/src/backend/opencl/cl/rx/randomx_constants_v.h @@ -0,0 +1,96 @@ +/* +Copyright (c) 2019 SChernykh + +This file is part of RandomX OpenCL. + +RandomX OpenCL is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +RandomX OpenCL is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with RandomX OpenCL. If not, see . +*/ + +//Dataset base size in bytes. Must be a power of 2. +#define RANDOMX_DATASET_BASE_SIZE 2147483648 + +//Dataset extra size. Must be divisible by 64. +#define RANDOMX_DATASET_EXTRA_SIZE 33554368 + +//Scratchpad L3 size in bytes. Must be a power of 2. +#define RANDOMX_SCRATCHPAD_L3 2097152 + +//Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3. +#define RANDOMX_SCRATCHPAD_L2 262144 + +//Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2. +#define RANDOMX_SCRATCHPAD_L1 16384 + +//Jump condition mask size in bits. +#define RANDOMX_JUMP_BITS 8 + +//Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16. +#define RANDOMX_JUMP_OFFSET 8 + +//Integer instructions +#define RANDOMX_FREQ_IADD_RS 16 +#define RANDOMX_FREQ_IADD_M 7 +#define RANDOMX_FREQ_ISUB_R 16 +#define RANDOMX_FREQ_ISUB_M 7 +#define RANDOMX_FREQ_IMUL_R 16 +#define RANDOMX_FREQ_IMUL_M 4 +#define RANDOMX_FREQ_IMULH_R 4 +#define RANDOMX_FREQ_IMULH_M 1 +#define RANDOMX_FREQ_ISMULH_R 4 +#define RANDOMX_FREQ_ISMULH_M 1 +#define RANDOMX_FREQ_IMUL_RCP 8 +#define RANDOMX_FREQ_INEG_R 2 +#define RANDOMX_FREQ_IXOR_R 15 +#define RANDOMX_FREQ_IXOR_M 5 +#define RANDOMX_FREQ_IROR_R 8 +#define RANDOMX_FREQ_IROL_R 2 +#define RANDOMX_FREQ_ISWAP_R 4 + +//Floating point instructions +#define RANDOMX_FREQ_FSWAP_R 4 +#define RANDOMX_FREQ_FADD_R 16 +#define RANDOMX_FREQ_FADD_M 5 +#define RANDOMX_FREQ_FSUB_R 16 +#define RANDOMX_FREQ_FSUB_M 5 +#define RANDOMX_FREQ_FSCAL_R 6 +#define RANDOMX_FREQ_FMUL_R 32 +#define RANDOMX_FREQ_FDIV_M 4 +#define RANDOMX_FREQ_FSQRT_R 6 + +//Control instructions +#define RANDOMX_FREQ_CBRANCH 25 +#define RANDOMX_FREQ_CFROUND 1 + +//Store instruction +#define RANDOMX_FREQ_ISTORE 16 + +//No-op instruction +#define RANDOMX_FREQ_NOP 0 + +#define RANDOMX_DATASET_ITEM_SIZE 64 + +#define RANDOMX_PROGRAM_SIZE 256 + +#define HASH_SIZE 64 +#define ENTROPY_SIZE (128 + RANDOMX_PROGRAM_SIZE * 8) +#define REGISTERS_SIZE 256 +#define IMM_BUF_SIZE (RANDOMX_PROGRAM_SIZE * 4 - REGISTERS_SIZE) +#define IMM_INDEX_COUNT ((IMM_BUF_SIZE / 4) - 2) +#define VM_STATE_SIZE (REGISTERS_SIZE + IMM_BUF_SIZE + RANDOMX_PROGRAM_SIZE * 4) +#define ROUNDING_MODE (RANDOMX_FREQ_CFROUND ? -1 : 0) + +// Scratchpad L1/L2/L3 bits +#define LOC_L1 (32 - 14) +#define LOC_L2 (32 - 18) +#define LOC_L3 (32 - 21) diff --git a/src/crypto/common/Algorithm.cpp b/src/crypto/common/Algorithm.cpp index 99883daa7..f7c988166 100644 --- a/src/crypto/common/Algorithm.cpp +++ b/src/crypto/common/Algorithm.cpp @@ -114,6 +114,7 @@ static AlgoName const algorithm_names[] = { { "RandomARQ", nullptr, Algorithm::RX_ARQ }, { "randomx/sfx", "rx/sfx", Algorithm::RX_SFX }, { "RandomSFX", nullptr, Algorithm::RX_SFX }, + { "RandomV", "rx/v", Algorithm::RX_V }, # endif # ifdef XMRIG_ALGO_ARGON2 { "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA }, @@ -141,6 +142,7 @@ size_t xmrig::Algorithm::l2() const case RX_0: case RX_LOKI: case RX_SFX: + case RX_V: return 0x40000; case RX_WOW: @@ -177,6 +179,7 @@ size_t xmrig::Algorithm::l3() const case RX_0: case RX_LOKI: case RX_SFX: + case RX_V: return oneMiB * 2; case RX_WOW: @@ -277,6 +280,7 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id) case RX_LOKI: case RX_ARQ: case RX_SFX: + case RX_V: return RANDOM_X; # endif diff --git a/src/crypto/common/Algorithm.h b/src/crypto/common/Algorithm.h index bfdcea5a2..c72b4e6aa 100644 --- a/src/crypto/common/Algorithm.h +++ b/src/crypto/common/Algorithm.h @@ -68,6 +68,7 @@ public: RX_LOKI, // "rx/loki" RandomXL (Loki). RX_ARQ, // "rx/arq" RandomARQ (Arqma). RX_SFX, // "rx/sfx" RandomSFX (Safex Cash). + RX_V, // "rx/v" RandomV (Monerov). AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa). AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ) MAX diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index dfbda9684..c6d6ff38f 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -97,6 +97,11 @@ RandomX_ConfigurationSafex::RandomX_ConfigurationSafex() ArgonSalt = "RandomSFX\x01"; } +RandomX_ConfigurationV::RandomX_ConfigurationV() +{ + ArgonSalt = "RandomV\x03"; +} + RandomX_ConfigurationBase::RandomX_ConfigurationBase() : ArgonMemory(262144) , ArgonIterations(3) @@ -273,6 +278,7 @@ RandomX_ConfigurationWownero RandomX_WowneroConfig; RandomX_ConfigurationLoki RandomX_LokiConfig; RandomX_ConfigurationArqma RandomX_ArqmaConfig; RandomX_ConfigurationSafex RandomX_SafexConfig; +RandomX_ConfigurationV RandomX_VConfig; RandomX_ConfigurationBase RandomX_CurrentConfig; diff --git a/src/crypto/randomx/randomx.h b/src/crypto/randomx/randomx.h index 793e6e1b2..90203a441 100644 --- a/src/crypto/randomx/randomx.h +++ b/src/crypto/randomx/randomx.h @@ -183,12 +183,14 @@ struct RandomX_ConfigurationWownero : public RandomX_ConfigurationBase { RandomX struct RandomX_ConfigurationLoki : public RandomX_ConfigurationBase { RandomX_ConfigurationLoki(); }; struct RandomX_ConfigurationArqma : public RandomX_ConfigurationBase { RandomX_ConfigurationArqma(); }; struct RandomX_ConfigurationSafex : public RandomX_ConfigurationBase { RandomX_ConfigurationSafex(); }; +struct RandomX_ConfigurationV : public RandomX_ConfigurationBase { RandomX_ConfigurationV(); }; extern RandomX_ConfigurationMonero RandomX_MoneroConfig; extern RandomX_ConfigurationWownero RandomX_WowneroConfig; extern RandomX_ConfigurationLoki RandomX_LokiConfig; extern RandomX_ConfigurationArqma RandomX_ArqmaConfig; extern RandomX_ConfigurationSafex RandomX_SafexConfig; +extern RandomX_ConfigurationV RandomX_VConfig; extern RandomX_ConfigurationBase RandomX_CurrentConfig; diff --git a/src/crypto/rx/RxAlgo.cpp b/src/crypto/rx/RxAlgo.cpp index 4630303e7..7f82227ec 100644 --- a/src/crypto/rx/RxAlgo.cpp +++ b/src/crypto/rx/RxAlgo.cpp @@ -52,6 +52,9 @@ const RandomX_ConfigurationBase *xmrig::RxAlgo::base(Algorithm::Id algorithm) case Algorithm::RX_SFX: return &RandomX_SafexConfig; + case Algorithm::RX_V: + return &RandomX_VConfig; + default: break; } From 2911bb3a8128c600bd1defbe4df27ee9f58684b3 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 20 Dec 2019 04:05:09 +0700 Subject: [PATCH 2/2] Fix OpenCL. --- src/backend/opencl/OclLaunchData.cpp | 6 +- src/backend/opencl/cl/rx/randomx.cl | 2 - .../opencl/cl/rx/randomx_constants_v.h | 96 ------------------- .../opencl/runners/OclRxBaseRunner.cpp | 5 +- src/crypto/rx/RxAlgo.cpp | 10 ++ src/crypto/rx/RxAlgo.h | 1 + 6 files changed, 15 insertions(+), 105 deletions(-) delete mode 100644 src/backend/opencl/cl/rx/randomx_constants_v.h diff --git a/src/backend/opencl/OclLaunchData.cpp b/src/backend/opencl/OclLaunchData.cpp index 149ba075b..70465a566 100644 --- a/src/backend/opencl/OclLaunchData.cpp +++ b/src/backend/opencl/OclLaunchData.cpp @@ -25,9 +25,9 @@ #include "backend/opencl/OclLaunchData.h" - #include "backend/common/Tags.h" #include "backend/opencl/OclConfig.h" +#include "crypto/rx/RxAlgo.h" xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorithm, const OclConfig &config, const OclPlatform &platform, const OclThread &thread, const OclDevice &device, int64_t affinity) : @@ -44,8 +44,8 @@ xmrig::OclLaunchData::OclLaunchData(const Miner *miner, const Algorithm &algorit bool xmrig::OclLaunchData::isEqual(const OclLaunchData &other) const { - return (other.algorithm == algorithm && - other.thread == thread); + return (RxAlgo::id(other.algorithm) == RxAlgo::id(algorithm) && + other.thread == thread); } diff --git a/src/backend/opencl/cl/rx/randomx.cl b/src/backend/opencl/cl/rx/randomx.cl index b62f78fca..6fee74edf 100644 --- a/src/backend/opencl/cl/rx/randomx.cl +++ b/src/backend/opencl/cl/rx/randomx.cl @@ -8,8 +8,6 @@ #include "randomx_constants_loki.h" #elif (ALGO == ALGO_RX_ARQMA) #include "randomx_constants_arqma.h" -#elif (ALGO == ALGO_RX_V) -#include "randomx_constants_v.h" #endif #include "aes.cl" diff --git a/src/backend/opencl/cl/rx/randomx_constants_v.h b/src/backend/opencl/cl/rx/randomx_constants_v.h deleted file mode 100644 index 1967a8c2c..000000000 --- a/src/backend/opencl/cl/rx/randomx_constants_v.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -Copyright (c) 2019 SChernykh - -This file is part of RandomX OpenCL. - -RandomX OpenCL is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -RandomX OpenCL is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with RandomX OpenCL. If not, see . -*/ - -//Dataset base size in bytes. Must be a power of 2. -#define RANDOMX_DATASET_BASE_SIZE 2147483648 - -//Dataset extra size. Must be divisible by 64. -#define RANDOMX_DATASET_EXTRA_SIZE 33554368 - -//Scratchpad L3 size in bytes. Must be a power of 2. -#define RANDOMX_SCRATCHPAD_L3 2097152 - -//Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3. -#define RANDOMX_SCRATCHPAD_L2 262144 - -//Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2. -#define RANDOMX_SCRATCHPAD_L1 16384 - -//Jump condition mask size in bits. -#define RANDOMX_JUMP_BITS 8 - -//Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16. -#define RANDOMX_JUMP_OFFSET 8 - -//Integer instructions -#define RANDOMX_FREQ_IADD_RS 16 -#define RANDOMX_FREQ_IADD_M 7 -#define RANDOMX_FREQ_ISUB_R 16 -#define RANDOMX_FREQ_ISUB_M 7 -#define RANDOMX_FREQ_IMUL_R 16 -#define RANDOMX_FREQ_IMUL_M 4 -#define RANDOMX_FREQ_IMULH_R 4 -#define RANDOMX_FREQ_IMULH_M 1 -#define RANDOMX_FREQ_ISMULH_R 4 -#define RANDOMX_FREQ_ISMULH_M 1 -#define RANDOMX_FREQ_IMUL_RCP 8 -#define RANDOMX_FREQ_INEG_R 2 -#define RANDOMX_FREQ_IXOR_R 15 -#define RANDOMX_FREQ_IXOR_M 5 -#define RANDOMX_FREQ_IROR_R 8 -#define RANDOMX_FREQ_IROL_R 2 -#define RANDOMX_FREQ_ISWAP_R 4 - -//Floating point instructions -#define RANDOMX_FREQ_FSWAP_R 4 -#define RANDOMX_FREQ_FADD_R 16 -#define RANDOMX_FREQ_FADD_M 5 -#define RANDOMX_FREQ_FSUB_R 16 -#define RANDOMX_FREQ_FSUB_M 5 -#define RANDOMX_FREQ_FSCAL_R 6 -#define RANDOMX_FREQ_FMUL_R 32 -#define RANDOMX_FREQ_FDIV_M 4 -#define RANDOMX_FREQ_FSQRT_R 6 - -//Control instructions -#define RANDOMX_FREQ_CBRANCH 25 -#define RANDOMX_FREQ_CFROUND 1 - -//Store instruction -#define RANDOMX_FREQ_ISTORE 16 - -//No-op instruction -#define RANDOMX_FREQ_NOP 0 - -#define RANDOMX_DATASET_ITEM_SIZE 64 - -#define RANDOMX_PROGRAM_SIZE 256 - -#define HASH_SIZE 64 -#define ENTROPY_SIZE (128 + RANDOMX_PROGRAM_SIZE * 8) -#define REGISTERS_SIZE 256 -#define IMM_BUF_SIZE (RANDOMX_PROGRAM_SIZE * 4 - REGISTERS_SIZE) -#define IMM_INDEX_COUNT ((IMM_BUF_SIZE / 4) - 2) -#define VM_STATE_SIZE (REGISTERS_SIZE + IMM_BUF_SIZE + RANDOMX_PROGRAM_SIZE * 4) -#define ROUNDING_MODE (RANDOMX_FREQ_CFROUND ? -1 : 0) - -// Scratchpad L1/L2/L3 bits -#define LOC_L1 (32 - 14) -#define LOC_L2 (32 - 18) -#define LOC_L3 (32 - 21) diff --git a/src/backend/opencl/runners/OclRxBaseRunner.cpp b/src/backend/opencl/runners/OclRxBaseRunner.cpp index 8eb390e68..36a31e1b7 100644 --- a/src/backend/opencl/runners/OclRxBaseRunner.cpp +++ b/src/backend/opencl/runners/OclRxBaseRunner.cpp @@ -56,10 +56,7 @@ xmrig::OclRxBaseRunner::OclRxBaseRunner(size_t index, const OclLaunchData &data) m_gcn_version = 14; } - // rx/sfx is the same as rx/0 except Argon salt for dataset generation - Algorithm::Id id = (m_algorithm.id() == Algorithm::RX_SFX) ? Algorithm::RX_0 : m_algorithm.id(); - - m_options += " -DALGO=" + std::to_string(id); + m_options += " -DALGO=" + std::to_string(RxAlgo::id(m_algorithm)); m_options += " -DWORKERS_PER_HASH=" + std::to_string(m_worksize); m_options += " -DGCN_VERSION=" + std::to_string(m_gcn_version); } diff --git a/src/crypto/rx/RxAlgo.cpp b/src/crypto/rx/RxAlgo.cpp index 7f82227ec..b08b3b8e2 100644 --- a/src/crypto/rx/RxAlgo.cpp +++ b/src/crypto/rx/RxAlgo.cpp @@ -37,6 +37,16 @@ xmrig::Algorithm::Id xmrig::RxAlgo::apply(Algorithm::Id algorithm) } +xmrig::Algorithm::Id xmrig::RxAlgo::id(Algorithm::Id algorithm) +{ + if (algorithm == Algorithm::RX_SFX || algorithm == Algorithm::RX_V) { + return Algorithm::RX_0; + } + + return algorithm; +} + + const RandomX_ConfigurationBase *xmrig::RxAlgo::base(Algorithm::Id algorithm) { switch (algorithm) { diff --git a/src/crypto/rx/RxAlgo.h b/src/crypto/rx/RxAlgo.h index 00c44ece7..ff2750c62 100644 --- a/src/crypto/rx/RxAlgo.h +++ b/src/crypto/rx/RxAlgo.h @@ -46,6 +46,7 @@ class RxAlgo { public: static Algorithm::Id apply(Algorithm::Id algorithm); + static Algorithm::Id id(Algorithm::Id algorithm); static const RandomX_ConfigurationBase *base(Algorithm::Id algorithm); static uint32_t programCount(Algorithm::Id algorithm); static uint32_t programIterations(Algorithm::Id algorithm);