Skip to content

Commit

Permalink
Expose Randomx Dataset Constants as build flags (#4)
Browse files Browse the repository at this point in the history
Allow RANDOMX_DATASET_BASE_SIZE and RANDOMX_ARGON_MEMORY
to be overridden using -D build flags
  • Loading branch information
JamesPiechota authored Aug 29, 2024
1 parent 913873c commit 0c93c89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,21 @@ endif()

set(RANDOMX_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "RandomX Include path")

# Define variables for custom preprocessor definitions with default values
set(RANDOMX_ARGON_MEMORY "" CACHE STRING "Set the RANDOMX_ARGON_MEMORY value")
set(RANDOMX_DATASET_BASE_SIZE "" CACHE STRING "Set the RANDOMX_DATASET_BASE_SIZE value")

add_library(randomx ${randomx_sources})

# Apply the custom preprocessor definitions only if they are set
if(RANDOMX_ARGON_MEMORY)
target_compile_definitions(randomx PRIVATE RANDOMX_ARGON_MEMORY=${RANDOMX_ARGON_MEMORY})
endif()

if(RANDOMX_DATASET_BASE_SIZE)
target_compile_definitions(randomx PRIVATE RANDOMX_DATASET_BASE_SIZE=${RANDOMX_DATASET_BASE_SIZE})
endif()

if(TARGET generate-asm)
add_dependencies(randomx generate-asm)
endif()
Expand Down
4 changes: 4 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

//Cache size in KiB. Must be a power of 2.
#ifndef RANDOMX_ARGON_MEMORY
#define RANDOMX_ARGON_MEMORY 262144
#endif

//Number of Argon2d iterations for Cache initialization.
#define RANDOMX_ARGON_ITERATIONS 3
Expand All @@ -47,7 +49,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define RANDOMX_SUPERSCALAR_LATENCY 170

//Dataset base size in bytes. Must be a power of 2.
#ifndef RANDOMX_DATASET_BASE_SIZE
#define RANDOMX_DATASET_BASE_SIZE 536870912 // 2^29 = 512 Mi (bytes), tweaked for Arweave
#endif

//Dataset extra size. Must be divisible by 64.
#define RANDOMX_DATASET_EXTRA_SIZE 31563008 // 493172 (just an arbitrary number) * 64, tweaked for Arweave
Expand Down

0 comments on commit 0c93c89

Please sign in to comment.