Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
xmrig committed Nov 8, 2020
1 parent 87b7039 commit 788d513
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 113 deletions.
28 changes: 18 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ option(WITH_CN_LITE "Enable CryptoNight-Lite algorithms family" ON)
option(WITH_CN_HEAVY "Enable CryptoNight-Heavy algorithms family" ON)
option(WITH_CN_PICO "Enable CryptoNight-Pico algorithm" ON)
option(WITH_ARGON2 "Enable Argon2 algorithms family" OFF) #unsupported

if (CUDA_VERSION VERSION_LESS 9.0)
message(STATUS "CUDA ${CUDA_VERSION}: RandomX, AstroBWT, and KawPow disabled, they do not work with old CUDA")
option(WITH_RANDOMX "Enable RandomX algorithms family" OFF)
Expand All @@ -22,10 +23,6 @@ else()
option(WITH_KAWPOW "Enable KawPow algorithms family" ON)
endif()

if (WITH_CN_R)
add_definitions(/DXMRIG_ALGO_CN_R)
endif()

if (WITH_CN_LITE)
add_definitions(/DXMRIG_ALGO_CN_LITE)
endif()
Expand All @@ -51,13 +48,24 @@ if (WITH_ASTROBWT)
endif()

if (WITH_KAWPOW)
if (WITH_DRIVER_API)
add_definitions(/DXMRIG_ALGO_KAWPOW)
else()
message(STATUS "CUDA ${CUDA_VERSION}: KawPow disabled, requires WITH_DRIVER_API=ON for CUDA Driver API and NVRTC")
endif()
if (WITH_DRIVER_API)
add_definitions(/DXMRIG_ALGO_KAWPOW)
else()
set(WITH_KAWPOW OFF)
message(STATUS "CUDA ${CUDA_VERSION}: KawPow disabled, requires WITH_DRIVER_API=ON for CUDA Driver API and NVRTC")
endif()
endif()

if (WITH_CN_R)
if (WITH_DRIVER_API)
add_definitions(/DXMRIG_ALGO_CN_R)
else()
set(WITH_CN_R OFF)
message(STATUS "CUDA ${CUDA_VERSION}: CryptoNight-R disabled, requires WITH_DRIVER_API=ON for CUDA Driver API and NVRTC")
endif()
endif()


include_directories(src)
add_definitions(/DCUB_IGNORE_DEPRECATED_CPP_DIALECT)

Expand All @@ -78,7 +86,7 @@ set(SOURCES
)


if (WITH_DRIVER_API)
if (WITH_DRIVER_API AND WITH_CN_R)
list(APPEND SOURCES src/CudaCryptonightR_gen.cpp)
endif()

Expand Down
4 changes: 0 additions & 4 deletions cmake/CUDA-Version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ if (WITH_DRIVER_API)
find_library(CUDA_NVRTC_LIB libnvrtc nvrtc HINTS "${CUDA_TOOLKIT_ROOT_DIR}/lib64" "${LIBNVRTC_LIBRARY_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64" /usr/lib64 /usr/local/cuda/lib64)

set(LIBS ${LIBS} ${CUDA_LIBRARIES} ${CUDA_LIB} ${CUDA_NVRTC_LIB})

add_definitions(-DXMRIG_DRIVER_API)
else()
set(LIBS ${LIBS} ${CUDA_LIBRARIES})

remove_definitions(-DXMRIG_DRIVER_API)
endif()
18 changes: 14 additions & 4 deletions src/crypto/common/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ struct AlgoName


static AlgoName const algorithm_names[] = {
# ifdef XMRIG_ALGO_RANDOMX
{ "rx/0", Algorithm::RX_0 },
{ "rx/wow", Algorithm::RX_WOW },
{ "rx/arq", Algorithm::RX_ARQ },
{ "rx/sfx", Algorithm::RX_SFX },
{ "rx/keva", Algorithm::RX_KEVA },
# endif
{ "cn/0", Algorithm::CN_0 },
{ "cn/1", Algorithm::CN_1 },
{ "cn/2", Algorithm::CN_2 },
Expand All @@ -65,19 +67,27 @@ static AlgoName const algorithm_names[] = {
{ "cn/rwz", Algorithm::CN_RWZ },
{ "cn/zls", Algorithm::CN_ZLS },
{ "cn/double", Algorithm::CN_DOUBLE },
{ "cn/ccx", Algorithm::CN_CCX },
# ifdef XMRIG_ALGO_CN_LITE
{ "cn-lite/0", Algorithm::CN_LITE_0 },
{ "cn-lite/1", Algorithm::CN_LITE_1 },
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
{ "cn-heavy/0", Algorithm::CN_HEAVY_0 },
{ "cn-heavy/xhv", Algorithm::CN_HEAVY_XHV },
{ "cn-heavy/tube", Algorithm::CN_HEAVY_TUBE },
# endif
# ifdef XMRIG_ALGO_CN_PICO
{ "cn-pico", Algorithm::CN_PICO_0 },
{ "cn-pico/tlo", Algorithm::CN_PICO_TLO },
{ "cn/ccx", Algorithm::CN_CCX },
# endif
# ifdef XMRIG_ALGO_ASTROBWT
{ "astrobwt", Algorithm::ASTROBWT_DERO },
{ "astrobwt/dero", Algorithm::ASTROBWT_DERO },
# ifdef XMRIG_DRIVER_API
# endif
# ifdef XMRIG_ALGO_KAWPOW
{ "kawpow", Algorithm::KAWPOW_RVN },
{ "kawpow/rvn", Algorithm::KAWPOW_RVN },
# endif
# ifdef XMRIG_ALGO_CN_R
{ "cn/r", Algorithm::CN_R },
# endif
};
Expand Down
8 changes: 4 additions & 4 deletions src/cryptonight.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
#include <cstdint>


#ifdef XMRIG_DRIVER_API
#if defined(XMRIG_ALGO_KAWPOW) || defined(XMRIG_ALGO_CN_R)
# include <cuda.h>
#endif


struct nvid_ctx {
# ifdef XMRIG_DRIVER_API
# ifdef XMRIG_ALGO_CN_R
CUdevice cuDevice = -1;
CUmodule module = nullptr;
CUfunction kernel = nullptr;
Expand Down Expand Up @@ -101,7 +101,7 @@ struct nvid_ctx {
void* astrobwt_offsets_begin = nullptr;
void* astrobwt_offsets_end = nullptr;

# ifdef XMRIG_DRIVER_API
# ifdef XMRIG_ALGO_KAWPOW
void* kawpow_cache = nullptr;
size_t kawpow_cache_size = 0;
size_t kawpow_cache_capacity = 0;
Expand Down Expand Up @@ -143,7 +143,7 @@ void astrobwt_prepare(nvid_ctx *ctx, uint32_t batch_size);

namespace AstroBWT_Dero { void hash(nvid_ctx *ctx, uint32_t nonce, uint64_t target, uint32_t *rescount, uint32_t *resnonce); }

#ifdef XMRIG_DRIVER_API
#ifdef XMRIG_ALGO_KAWPOW
void kawpow_prepare(nvid_ctx *ctx, const void* cache, size_t cache_size, const void* dag_precalc, size_t dag_size, uint32_t height, const uint64_t* dag_sizes);
void kawpow_stop_hash(nvid_ctx *ctx);

Expand Down
6 changes: 3 additions & 3 deletions src/cuda_core.cu
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void cryptonight_core_gpu_hash(nvid_ctx* ctx, uint32_t nonce)
}

for (int i = 0; i < partcount; i++) {
# ifdef XMRIG_DRIVER_API
# ifdef XMRIG_ALGO_CN_R
if (ALGO == Algorithm::CN_R) {
int threads = ctx->device_blocks * ctx->device_threads;
void* args[] = { &threads, &ctx->device_bfactor, &i, &ctx->d_long_state, &ctx->d_ctx_a, &ctx->d_ctx_b, &ctx->d_ctx_state, &nonce, &ctx->d_input };
Expand Down Expand Up @@ -823,7 +823,7 @@ void cryptonight_gpu_hash(nvid_ctx *ctx, const xmrig_cuda::Algorithm &algorithm,

if (algorithm.family() == Algorithm::CN) {
if (algorithm == Algorithm::CN_R) {
# ifdef XMRIG_DRIVER_API
# ifdef XMRIG_ALGO_CN_R
if ((ctx->algorithm != algorithm) || (ctx->kernel_height != height)) {
if (ctx->module) {
cuModuleUnload(ctx->module);
Expand Down Expand Up @@ -857,7 +857,7 @@ void cryptonight_gpu_hash(nvid_ctx *ctx, const xmrig_cuda::Algorithm &algorithm,
cryptonight_core_gpu_hash<Algorithm::CN_2>(ctx, startNonce);
break;

# ifdef XMRIG_DRIVER_API
# ifdef XMRIG_ALGO_CN_R
case Algorithm::CN_R:
cryptonight_core_gpu_hash<Algorithm::CN_R>(ctx, startNonce);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/cuda_device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
__VA_ARGS__; \
CUDA_CHECK(id, cudaGetLastError())

#ifdef XMRIG_DRIVER_API
#if defined(XMRIG_ALGO_KAWPOW) || defined(XMRIG_ALGO_CN_R)
#define CU_CHECK(id, ...) { \
CUresult result = __VA_ARGS__; \
if(result != CUDA_SUCCESS){ \
Expand Down
2 changes: 1 addition & 1 deletion src/cuda_extra.cu
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ int cryptonight_extra_cpu_init(nvid_ctx *ctx, const xmrig_cuda::Algorithm &algor
{
using namespace xmrig_cuda;

# ifdef XMRIG_DRIVER_API
# ifdef XMRIG_ALGO_CN_R
CU_CHECK(ctx->device_id, cuDeviceGet(&ctx->cuDevice, ctx->device_id));

CUcontext cuContext;
Expand Down
Loading

0 comments on commit 788d513

Please sign in to comment.