Skip to content

Commit

Permalink
Merge pull request #282 from SChernykh/dev
Browse files Browse the repository at this point in the history
 Integrated RandomX,  added RandomXL (Loki)
  • Loading branch information
xmrig authored Jul 6, 2019
2 parents 16faa2b + 3deb062 commit 06930e6
Show file tree
Hide file tree
Showing 92 changed files with 10,756 additions and 171 deletions.
47 changes: 41 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,48 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
find_package(UV REQUIRED)

if (WITH_RANDOMX)
find_package(RandomX REQUIRED)
include_directories(${RANDOMX_INCLUDE_DIR})

include_directories(src/crypto/randomx)
add_definitions(/DXMRIG_ALGO_RANDOMX)
set(SOURCES_CRYPTO
"${SOURCES_CRYPTO}"
src/crypto/randomx/aes_hash.cpp
src/crypto/randomx/argon2_ref.c
src/crypto/randomx/bytecode_machine.cpp
src/crypto/randomx/dataset.cpp
src/crypto/randomx/soft_aes.cpp
src/crypto/randomx/virtual_memory.cpp
src/crypto/randomx/vm_interpreted.cpp
src/crypto/randomx/allocator.cpp
src/crypto/randomx/randomx.cpp
src/crypto/randomx/superscalar.cpp
src/crypto/randomx/vm_compiled.cpp
src/crypto/randomx/vm_interpreted_light.cpp
src/crypto/randomx/argon2_core.c
src/crypto/randomx/blake2_generator.cpp
src/crypto/randomx/instructions_portable.cpp
src/crypto/randomx/reciprocal.c
src/crypto/randomx/virtual_machine.cpp
src/crypto/randomx/vm_compiled_light.cpp
src/crypto/randomx/blake2/blake2b.c
)
if (NOT ARCH_ID)
set(ARCH_ID ${CMAKE_HOST_SYSTEM_PROCESSOR})
endif()
if (CMAKE_C_COMPILER_ID MATCHES MSVC)
enable_language(ASM_MASM)
list(APPEND SOURCES_CRYPTO
src/crypto/randomx/jit_compiler_x86_static.asm
src/crypto/randomx/jit_compiler_x86.cpp
)
elseif (NOT XMRIG_ARM AND CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND SOURCES_CRYPTO
src/crypto/randomx/jit_compiler_x86_static.S
src/crypto/randomx/jit_compiler_x86.cpp
)
# cheat because cmake and ccache hate each other
set_property(SOURCE src/crypto/randomx/jit_compiler_x86_static.S PROPERTY LANGUAGE C)
endif()
else()
set(RANDOMX_LIBRARIES "")

remove_definitions(/DXMRIG_ALGO_RANDOMX)
endif()

Expand Down Expand Up @@ -308,7 +343,7 @@ if (WITH_DEBUG_LOG)
endif()

add_executable(${CMAKE_PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_NVML} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${TLS_SOURCES} ${CN_GPU_SOURCES} ${XMRIG_ASM_SOURCES})
target_link_libraries(${CMAKE_PROJECT_NAME} xmrig-cuda ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${RANDOMX_LIBRARIES} ${MHD_LIBRARY} ${LIBS} ${EXTRA_LIBS} ${CPUID_LIB})
target_link_libraries(${CMAKE_PROJECT_NAME} xmrig-cuda ${XMRIG_ASM_LIBRARY} ${OPENSSL_LIBRARIES} ${UV_LIBRARIES} ${MHD_LIBRARY} ${LIBS} ${EXTRA_LIBS} ${CPUID_LIB})

if (WIN32)
file(GLOB NVRTCDLL "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvrtc64*.dll")
Expand Down
14 changes: 10 additions & 4 deletions cmake/CUDA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,16 @@ endif()

if (WITH_RANDOMX)
set(CUDA_RANDOMX_SOURCES
src/nvidia/RandomWOW/random_wow.cu
src/nvidia/RandomWOW/aes_cuda.hpp
src/nvidia/RandomWOW/blake2b_cuda.hpp
src/nvidia/RandomWOW/randomx_cuda.hpp
src/nvidia/RandomX/aes_cuda.hpp
src/nvidia/RandomX/blake2b_cuda.hpp
src/nvidia/RandomX/common.hpp
src/nvidia/RandomX/hash.hpp
src/nvidia/RandomX/randomx.cu
src/nvidia/RandomX/randomx_cuda.hpp
src/nvidia/RandomX_Wownero/configuration.h
src/nvidia/RandomX_Wownero/randomx_wownero.cu
src/nvidia/RandomX_Loki/configuration.h
src/nvidia/RandomX_Loki/randomx_loki.cu
)
else()
set(CUDA_RANDOMX_SOURCES "")
Expand Down
25 changes: 0 additions & 25 deletions cmake/FindRandomX.cmake

This file was deleted.

1 change: 1 addition & 0 deletions src/base/net/Pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ void xmrig::Pool::rebuild()
addVariant(VARIANT_DOUBLE);
# ifdef XMRIG_ALGO_RANDOMX
addVariant(VARIANT_RX_WOW);
addVariant(VARIANT_RX_LOKI);
# endif
addVariant(VARIANT_AUTO);
# endif
Expand Down
2 changes: 2 additions & 0 deletions src/common/crypto/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static AlgoData const algorithms[] = {
{ "cryptonight/double", "cn/double", xmrig::CRYPTONIGHT, xmrig::VARIANT_DOUBLE },

{ "randomx/wow", "rx/wow", xmrig::RANDOM_X, xmrig::VARIANT_RX_WOW },
{ "randomx/loki", "rx/loki", xmrig::RANDOM_X, xmrig::VARIANT_RX_LOKI },

# ifndef XMRIG_NO_AEON
{ "cryptonight-lite", "cn-lite", xmrig::CRYPTONIGHT_LITE, xmrig::VARIANT_AUTO },
Expand Down Expand Up @@ -142,6 +143,7 @@ static const char *variants[] = {
"zls",
"double",
"rx/wow",
"rx/loki",
};


Expand Down
1 change: 1 addition & 0 deletions src/common/xmrig.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ enum Variant {
VARIANT_ZLS = 15, // CryptoNight variant 2 with 3/4 iterations (Zelerius)
VARIANT_DOUBLE = 16, // CryptoNight variant 2 with double iterations (X-CASH)
VARIANT_RX_WOW = 17, // RandomX (Wownero)
VARIANT_RX_LOKI = 18, // RandomX (Loki)
VARIANT_MAX
};

Expand Down
8 changes: 8 additions & 0 deletions src/crypto/CryptoNight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
cryptonight_single_hash<CRYPTONIGHT, true, VARIANT_DOUBLE>,

nullptr, nullptr, // VARIANT_RX_WOW
nullptr, nullptr, // VARIANT_RX_LOKI

# ifndef XMRIG_NO_AEON
cryptonight_single_hash<CRYPTONIGHT_LITE, false, VARIANT_0>,
Expand All @@ -273,6 +274,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, // VARIANT_RX_WOW
nullptr, nullptr, // VARIANT_RX_LOKI
# else
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
Expand All @@ -283,6 +285,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
# endif

# ifndef XMRIG_NO_SUMO
Expand Down Expand Up @@ -312,6 +315,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, // VARIANT_RX_WOW
nullptr, nullptr, // VARIANT_RX_LOKI
# else
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
Expand All @@ -322,6 +326,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
# endif
# ifndef XMRIG_NO_CN_PICO
nullptr, nullptr, // VARIANT_0
Expand Down Expand Up @@ -349,6 +354,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
nullptr, nullptr, // VARIANT_ZLS
nullptr, nullptr, // VARIANT_DOUBLE
nullptr, nullptr, // VARIANT_RX_WOW
nullptr, nullptr, // VARIANT_RX_LOKI
# else
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
Expand All @@ -359,6 +365,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
# endif
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
Expand All @@ -369,6 +376,7 @@ CryptoNight::cn_hash_fun CryptoNight::fn(xmrig::Algo algorithm, xmrig::AlgoVerif
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
};

static_assert((VARIANT_MAX * 2 * ALGO_MAX) == sizeof(func_table) / sizeof(func_table[0]), "func_table size mismatch");
Expand Down
7 changes: 6 additions & 1 deletion src/crypto/CryptoNight_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ inline size_t cn_select_memory(Algo algorithm)
switch(algorithm)
{
case CRYPTONIGHT:
case RANDOM_X:
return CRYPTONIGHT_MEMORY;

case CRYPTONIGHT_LITE:
case RANDOM_X:
return CRYPTONIGHT_LITE_MEMORY;

case CRYPTONIGHT_HEAVY:
Expand All @@ -94,6 +94,11 @@ inline size_t cn_select_memory(Algo algorithm)
return 0;
}

inline size_t rx_select_memory(Variant variant)
{
return ((variant == xmrig::VARIANT_RX_WOW) ? 1048576 : 2097152);
}


template<Algo ALGO> inline constexpr uint32_t cn_select_mask() { return 0; }
template<> inline constexpr uint32_t cn_select_mask<CRYPTONIGHT>() { return CRYPTONIGHT_MASK; }
Expand Down
Loading

0 comments on commit 06930e6

Please sign in to comment.