Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandomX integration (Wownero and Loki variants) #268

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ option(WITH_AEON "CryptoNight-Lite support" ON)
option(WITH_SUMO "CryptoNight-Heavy support" ON)
option(WITH_CN_PICO "CryptoNight-Pico support" ON)
option(WITH_CN_GPU "CryptoNight-GPU support" ON)
option(WITH_RANDOMX "RandomX support" ON)
option(WITH_HTTPD "HTTP REST API" ON)
option(WITH_TLS "Enable OpenSSL support" ON)
option(WITH_ASM "Enable ASM PoW implementations" ON)
Expand Down Expand Up @@ -233,6 +234,52 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")

find_package(UV REQUIRED)

if (WITH_RANDOMX)
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()
remove_definitions(/DXMRIG_ALGO_RANDOMX)
endif()

include(cmake/flags.cmake)

add_definitions(/DCL_TARGET_OPENCL_VERSION=200)
Expand Down
23 changes: 22 additions & 1 deletion src/amd/GpuContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct GpuContext
deviceIdx(0),
rawIntensity(0),
workSize(0),
bfactor(6),
threads(0),
stridedIndex(2),
memChunk(2),
Expand All @@ -69,15 +70,25 @@ struct GpuContext
freeMem(0),
globalMem(0),
computeUnits(0),
Nonce(0)
Nonce(0),
rx_variant(xmrig::VARIANT_AUTO),
rx_dataset(nullptr),
rx_scratchpads(nullptr),
rx_hashes(nullptr),
rx_entropy(nullptr),
rx_vm_states(nullptr),
rx_rounding(nullptr)
{
memset(Kernels, 0, sizeof(Kernels));
memset(rx_dataset_seedhash, 0, sizeof(rx_dataset_seedhash));
memset(rx_kernels, 0, sizeof(rx_kernels));
}

/*Input vars*/
size_t deviceIdx;
size_t rawIntensity;
size_t workSize;
size_t bfactor;
size_t threads;
int stridedIndex;
int memChunk;
Expand Down Expand Up @@ -107,6 +118,16 @@ struct GpuContext
xmrig::String name;

uint32_t Nonce;

uint8_t rx_dataset_seedhash[32];
xmrig::Variant rx_variant;
cl_mem rx_dataset;
cl_mem rx_scratchpads;
cl_mem rx_hashes;
cl_mem rx_entropy;
cl_mem rx_vm_states;
cl_mem rx_rounding;
cl_kernel rx_kernels[32];
};


Expand Down
50 changes: 36 additions & 14 deletions src/amd/OclCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,42 @@ cl_int OclCache::wait_build(cl_program program, cl_device_id device)

void OclCache::getOptions(xmrig::Algo algo, xmrig::Variant, const GpuContext* ctx, char* options, size_t options_size)
{
snprintf(options, options_size, "-DITERATIONS=%u -DMASK=%u -DWORKSIZE=%zu -DSTRIDED_INDEX=%d -DMEM_CHUNK_EXPONENT=%d -DCOMP_MODE=%d -DMEMORY=%zu "
"-DALGO=%d -DUNROLL_FACTOR=%d -DOPENCL_DRIVER_MAJOR=%d -DWORKSIZE_GPU=%zu -cl-fp32-correctly-rounded-divide-sqrt",
xmrig::cn_select_iter(algo, xmrig::VARIANT_AUTO),
xmrig::cn_select_mask(algo),
ctx->workSize,
ctx->stridedIndex,
static_cast<int>(1u << ctx->memChunk),
ctx->compMode,
xmrig::cn_select_memory(algo),
static_cast<int>(algo),
ctx->unrollFactor,
ctx->amdDriverMajorVersion,
worksize(ctx, xmrig::VARIANT_GPU)
);
# ifdef XMRIG_ALGO_RANDOMX
if (algo == xmrig::RANDOM_X) {
uint32_t workSize;
switch (ctx->workSize)
{
case 2:
case 4:
case 8:
case 16:
workSize = ctx->workSize;
break;

default:
workSize = 8;
}

snprintf(options, options_size, "-DWORKERS_PER_HASH=%u", workSize);
}
else
# endif
{
snprintf(options, options_size, "-DITERATIONS=%u -DMASK=%u -DWORKSIZE=%zu -DSTRIDED_INDEX=%d -DMEM_CHUNK_EXPONENT=%d -DCOMP_MODE=%d -DMEMORY=%zu "
"-DALGO=%d -DUNROLL_FACTOR=%d -DOPENCL_DRIVER_MAJOR=%d -DWORKSIZE_GPU=%zu -cl-fp32-correctly-rounded-divide-sqrt",
xmrig::cn_select_iter(algo, xmrig::VARIANT_AUTO),
xmrig::cn_select_mask(algo),
ctx->workSize,
ctx->stridedIndex,
static_cast<int>(1u << ctx->memChunk),
ctx->compMode,
xmrig::cn_select_memory(algo),
static_cast<int>(algo),
ctx->unrollFactor,
ctx->amdDriverMajorVersion,
worksize(ctx, xmrig::VARIANT_GPU)
);
}
}

bool OclCache::load()
Expand Down
Loading