Skip to content

Commit

Permalink
Merge pull request #2647 from fireice-uk/xmr-stak-rx-dev
Browse files Browse the repository at this point in the history
[RX] release 1.0.4
  • Loading branch information
fireice-uk committed Dec 29, 2019
2 parents a90fcc9 + 6091644 commit 65ade74
Show file tree
Hide file tree
Showing 35 changed files with 932 additions and 314 deletions.
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,19 @@ target_link_libraries(xmr-stak-rx ${MHTD} ${LIBS} xmr-stak-rx-backend)
# Install
################################################################################

# install booster script
if(NOT WIN32)
install(DIRECTORY "${CMAKE_SOURCE_DIR}/scripts/" DESTINATION ${CMAKE_INSTALL_PREFIX}/${LIBRARY_OUTPUT_PATH}
FILES_MATCHING PATTERN "*.sh"
PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE GROUP_READ GROUP_EXECUTE
PATTERN .git EXCLUDE
)
endif()

# do not install the binary if the project and install are equal
if( NOT CMAKE_INSTALL_PREFIX STREQUAL PROJECT_BINARY_DIR )
install(TARGETS xmr-stak-rx
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${EXECUTABLE_OUTPUT_PATH}")
RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/${EXECUTABLE_OUTPUT_PATH}")
if(CUDA_FOUND)
if(WIN32)
install(TARGETS xmrstakrx_cuda_backend
Expand Down
11 changes: 11 additions & 0 deletions doc/tuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Content Overview
* [Fast Startup](#fast-startup)
* [Booster Script](#booster-script)
* [Huge Page Support](#huge-page-support)
* [Benchmark](#benchmark)
* [Windows](#windows)
Expand All @@ -24,9 +25,19 @@
## Fast Startup
You can disable the miner self test performed on each miner start by adding the command line option `--noTest`

## Booster Script

The linux booster script manipulates the CPU caching behavior and activates huge pages.

Call `sudo ./randomx_booster.sh`.

The booster script will try to install all dependencies if need.
If the script can not install the dependencies (e.g. unknown systems) please install the tools `wrmsr` and `numactl`.

## Huge Page Support

In Linux you can enable 2 MiB huge pages with the following command.
In linux you can use our [booster script](#booster-script) to active huge pages

```
sudo sysctl -w vm.nr_hugepages=1300
Expand Down
111 changes: 111 additions & 0 deletions scripts/randomx_booster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env bash
# based on xmrig's randomx_boost.sh script
# lifted by psychocrypt

function help()
{
echo "$(basename $0) modifies caching behaviors of your CPU"
echo "and activates huge pages."
echo "Reboot your system to revert the changes."
echo ""
echo "must be called with administrative privileges e.g. 'sudo $(basename $0)'"
}

if [ $# -ge 1 ] ; then
help
exit 1
fi

hasAptGet=$(which apt-get >/dev/null && { echo 1; } || { echo 0; })
hasApt=$(which apt >/dev/null && { echo 1; } || { echo 0; })
hasYum=$(which yum >/dev/null && { echo 1; } || { echo 0; })

tools=$(which wrmsr >/dev/null || { echo "msr-tools "; })$(which numactl >/dev/null || { echo " numactl"; })

if [ -n "$tools" ] ; then
echo "tool '$tools' not found, $(basename $0) is trying to install the dependency"
if [ $hasAptGet -eq 1 ] ; then
comm="apt-get --no-install-recommends --yes install $tools"
echo "execute: $comm"
$comm
elif [ $hasApt -eq 1 ] ; then
comm="apt-get --no-install-recommends --yes install $tools"
echo "execute: $comm"
$comm
elif [ $hasYum -eq 1 ] ; then
comm="yum install -y $tools"
echo "execute: $comm"
$comm
else
echo "package manager unknown, please install '$tools' by hand" >&2
exit 1
fi
fi

hasWrmsr=$(which wrmsr >/dev/null && { echo 1; } || { echo 0; })
if [ $hasWrmsr -eq 0 ] ; then
echo "dependency 'wrmsr' not found, tool failed" >&2
exit 1
fi

hasNumactl=$(which numactl >/dev/null && { echo 1; } || { echo 0; })
if [ $hasNumactl -eq 0 ] ; then
echo "dependency 'numactl' not found, tool failed" >&2
exit 1
fi

echo ""
modprobe msr

if cat /proc/cpuinfo | grep -q "AMD Ryzen" ; then
echo "Detected Ryzen"
wrmsr -a 0xc0011022 0x510000
wrmsr -a 0xc001102b 0x1808cc16
wrmsr -a 0xc0011020 0
echo "MSR register values for Ryzen applied"
echo "WARNING: MSR register changes can result into stability issues!"
echo "Reboot your system to revert the changes."
elif cat /proc/cpuinfo | grep -q "Intel" ; then
echo "Detected Intel"
wrmsr -a 0x1a4 7
echo "MSR register values for Intel applied"
echo "WARNING: MSR register changes can result into stability issues!"
echo "Reboot your system to revert the changes."
else
echo "No supported CPU detected"
fi

echo ""

### begin enable huge pages
required_num_huge_pages=1280
num_huge_pages=$(cat /proc/meminfo | grep "HugePages_Free" | sed 's/ \{2,\}/ /g' | cut -d" " -f2)

if [ $num_huge_pages -lt $required_num_huge_pages ] ; then
echo "active 2 MiB pages"
echo "execute: sysctl -w vm.nr_hugepages=$required_num_huge_pages"
sysctl -w vm.nr_hugepages="$required_num_huge_pages"
fi
# verify number of huge pages
num_huge_pages=$(cat /proc/meminfo | grep "HugePages_Free" | sed 's/ \{2,\}/ /g' | cut -d" " -f2)
num_memsets=$((num_huge_pages/required_num_huge_pages))

if [ $num_memsets -eq 0 ] ; then
echo "Error: not enough 2 MiB pages $num_huge_pages/$required_num_huge_pages" >&2
fi

# apply gigabyte pages last because 2MiB pages will give more performance
numNodes=$(numactl --hardware | grep available | cut -d" " -f2)
freeGigPages=$(cat /sys/kernel/mm/hugepages/hugepages-1048576kB/free_hugepages)
neededGigPages=$((numNodes * 3))

if [ $freeGigPages -lt $neededGigPages ] ; then
echo ""
echo "activate 1 GiB pages"
comm="echo $neededGigPages > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages"
echo "execute: $comm"
echo "$neededGigPages" > /sys/kernel/mm/hugepages/hugepages-1048576kB/nr_hugepages
fi
### end enable huge pages

exit 0
12 changes: 5 additions & 7 deletions xmrstak/backend/amd/amd_gpu/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_
size_t scratchPadSize = 0;
for(const auto algo : neededAlgorithms)
{
scratchPadSize = std::max(scratchPadSize, algo.Mem());
scratchPadSize = std::max(scratchPadSize, algo.L3());
}

size_t g_thd = ctx->rawIntensity;
Expand All @@ -182,7 +182,7 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_
ctx->rx_dataset[ctx->deviceIdx] = clCreateBuffer(opencl_ctx, CL_MEM_READ_ONLY, dataset_size, nullptr, &ret);
}
else {
void* dataset = getRandomXDataset();
void* dataset = getRandomXDataset(0);
ctx->rx_dataset[ctx->deviceIdx] = clCreateBuffer(opencl_ctx, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, dataset_size, dataset, &ret);
}

Expand All @@ -193,7 +193,7 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_
}
}

ctx->rx_scratchpads = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, (user_algo.Mem() + 64) * g_thd, nullptr, &ret);
ctx->rx_scratchpads = clCreateBuffer(opencl_ctx, CL_MEM_READ_WRITE, (user_algo.L3() + 64) * g_thd, nullptr, &ret);
if(ret != CL_SUCCESS)
{
printer::inst()->print_msg(L1, "Error %s when calling clCreateBuffer to create RandomX scratchpads.", err_to_str(ret));
Expand Down Expand Up @@ -294,9 +294,7 @@ size_t InitOpenCLGpu(cl_context opencl_ctx, GpuContext* ctx, const char* source_
for(const auto miner_algo : neededAlgorithms)
{
// scratchpad size for the selected mining algorithm
size_t hashMemSize = miner_algo.Mem();
int threadMemMask = miner_algo.Mask();
int hashIterations = miner_algo.Iter();
size_t hashMemSize = miner_algo.L3();

std::string options;
options += " -DALGO=" + std::to_string(miner_algo.Id());
Expand Down Expand Up @@ -1364,7 +1362,7 @@ uint64_t interleaveAdjustDelay(GpuContext* ctx, const bool enableAutoAdjustment)
size_t RXSetJob(GpuContext *ctx, uint8_t *input, size_t input_len, uint64_t target, const uint8_t* seed_hash, const xmrstak_algo& miner_algo)
{
cl_int ret;
void* dataset = getRandomXDataset();
void* dataset = getRandomXDataset(0);
const size_t dataset_size = getRandomXDatasetSize();

if((memcmp(ctx->rx_dataset_seedhash, seed_hash, sizeof(ctx->rx_dataset_seedhash)) != 0))
Expand Down
7 changes: 4 additions & 3 deletions xmrstak/backend/amd/autoAdjust.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class autoAdjust
size_t hashMemSize = 0;
for(const auto algo : neededAlgorithms)
{
hashMemSize = std::max(hashMemSize, algo.Mem());
hashMemSize = std::max(hashMemSize, algo.L3());
}

std::string conf;
Expand Down Expand Up @@ -171,9 +171,10 @@ class autoAdjust
ctx.gcnAsm = false;


if(hashMemSize < CN_MEMORY)
size_t _2MiB = 2llu * 1024 * 1024;
if(hashMemSize < _2MiB)
{
size_t factor = CN_MEMORY / hashMemSize;
size_t factor = _2MiB / hashMemSize;
// increase all intensity relative to the original scratchpad size
maxThreads *= factor;
}
Expand Down
8 changes: 6 additions & 2 deletions xmrstak/backend/amd/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include "xmrstak/backend/cpu/crypto/cryptonight.h"
#include "xmrstak/backend/cpu/crypto/cryptonight_aesni.h"
#include "xmrstak/backend/cpu/hwlocMemory.hpp"
#include "xmrstak/backend/cpu/hwlocHelper.hpp"
#include "xmrstak/backend/cpu/minethd.hpp"
#include "xmrstak/jconf.hpp"
#include "xmrstak/misc/configEditor.hpp"
Expand Down Expand Up @@ -68,9 +68,11 @@ minethd::minethd(miner_work& pWork, size_t iNo, GpuContext* ctx, const jconf::th

order_guard.wait();

#if defined(CONF_NO_HWLOC) || defined(_WIN32)
if(affinity >= 0) //-1 means no affinity
if(!cpu::minethd::thd_setaffinity(oWorkThd.native_handle(), affinity))
printer::inst()->print_msg(L1, "WARNING setting affinity failed.");
#endif
}

extern "C"
Expand Down Expand Up @@ -164,7 +166,7 @@ std::vector<iBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor
void minethd::work_main()
{
if(affinity >= 0) //-1 means no affinity
bindMemoryToNUMANode(affinity);
hwlocBind(affinity);

order_fix.set_value();
std::unique_lock<std::mutex> lck(thd_aff_set);
Expand All @@ -173,6 +175,8 @@ void minethd::work_main()

cryptonight_ctx* cpu_ctx;
cpu_ctx = cpu::minethd::minethd_alloc_ctx();
cpu_ctx->numa = affinity < 0 ? 0 : numdaId(affinity);
randomX_global_ctx::inst().init(cpu_ctx->numa);

if(cpu_ctx == nullptr)
{
Expand Down
2 changes: 1 addition & 1 deletion xmrstak/backend/cpu/autoAdjust.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class autoAdjust
size_t hashMemSize = 0;
for(const auto algo : neededAlgorithms)
{
hashMemSize = std::max(hashMemSize, algo.Mem());
hashMemSize = std::max(hashMemSize, algo.L3());
}
const size_t hashMemSizeKB = hashMemSize / 1024u;

Expand Down
Loading

0 comments on commit 65ade74

Please sign in to comment.