Initial RandomX source code prepare and compile.

This commit is contained in:
XMRig 2019-09-08 21:56:18 +07:00
parent 29790da63d
commit ff89ec660c
17 changed files with 5481 additions and 57 deletions

View file

@ -5,7 +5,7 @@
const fs = require('fs');
const path = require('path');
const { text2h, text2h_bundle, addIncludes } = require('./js/opencl');
// const cwd = process.cwd();
const cwd = process.cwd();
function cn()
@ -51,8 +51,34 @@ function cn_gpu()
}
function rx()
{
let rx = addIncludes('randomx.cl', [
'../cn/algorithm.cl',
'randomx_constants_monero.h',
'randomx_constants_wow.h',
'randomx_constants_loki.h',
'aes.cl',
'blake2b.cl',
'randomx_vm.cl',
'randomx_jit.cl'
]);
rx = rx.replace(/ #include "fillAes1Rx4.cl"/g, fs.readFileSync('fillAes1Rx4.cl', 'utf8'));
rx = rx.replace(/ #include "blake2b_double_block.cl"/g, fs.readFileSync('blake2b_double_block.cl', 'utf8'));
//fs.writeFileSync('randomx_gen.cl', rx);
fs.writeFileSync('randomx_cl.h', text2h(rx, 'xmrig', 'randomx_cl'));
}
process.chdir(path.resolve('src/backend/opencl/cl/cn'));
cn();
cn_r();
cn_gpu();
cn_gpu();
process.chdir(cwd);
process.chdir(path.resolve('src/backend/opencl/cl/rx'));
rx();

View file

@ -33,12 +33,18 @@
# include "backend/opencl/cl/cn/cryptonight_gpu_cl.h"
#endif
#ifdef XMRIG_ALGO_RANDOMX
# include "backend/opencl/cl/rx/randomx_cl.h"
#endif
const char *xmrig::OclSource::get(const Algorithm &algorithm)
{
# ifdef XMRIG_ALGO_RANDOMX
if (algorithm.family() == Algorithm::RANDOM_X) {
return nullptr; // FIXME
return randomx_cl;
}
# endif
# ifdef XMRIG_ALGO_CN_GPU
if (algorithm == Algorithm::CN_GPU) {

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
@ -297,8 +296,6 @@ __constant static const uint AES_TABLE[2048] =
0x9d532e34U, 0xa055f3a2U, 0x32e18a05U, 0x75ebf6a4U,
0x39ec830bU, 0xaaef6040U, 0x069f715eU, 0x51106ebdU,
0xf98a213eU, 0x3d06dd96U, 0xae053eddU, 0x46bde64dU,
)==="
R"===(
0xb58d5491U, 0x055dc471U, 0x6fd40604U, 0xff155060U,
0x24fb9819U, 0x97e9bdd6U, 0xcc434089U, 0x779ed967U,
0xbd42e8b0U, 0x888b8907U, 0x385b19e7U, 0xdbeec879U,
@ -536,9 +533,6 @@ R"===(
0x7b6184cbU, 0xd570b632U, 0x48745c6cU, 0xd04257b8U,
};
)==="
R"===(
__constant static const uint AES_KEY_FILL[16] = {
0x6daca553, 0x62716609, 0xdbb5552b, 0xb4f44917,
0x6d7caf07, 0x846a710d, 0x1725d378, 0x0da1dc4e,
@ -639,4 +633,3 @@ __kernel void hashAes1Rx4(__global const void* input, __global void* hash, uint
*((__global uint4*)(hash) + idx * (hashStrideBytes / sizeof(uint4)) + sub + (hashOffsetBytes / sizeof(uint4))) = *(uint4*)(x);
}
)==="

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
@ -156,4 +155,3 @@ __kernel void blake2b_initial_hash(__global void *out, __global const void* bloc
#undef blake2b_hash_registers_name
#undef blake2b_512_process_double_block_name
#undef out_len
)==="

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
@ -99,4 +98,3 @@ __kernel void blake2b_hash_registers_name(__global void *out, __global const voi
if (out_len > 48) h[6] = hash[6];
if (out_len > 56) h[7] = hash[7];
}
)==="

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
@ -117,4 +116,3 @@ __kernel void fillAes_name(__global void* state, __global void* out, uint batch_
*(__global uint4*)(s) = *(uint4*)(x);
}
)==="

View file

@ -0,0 +1,14 @@
#include "../cn/algorithm.cl"
#if (ALGO == ALGO_RX_0)
#include "randomx_constants_monero.h"
#elif (ALGO == ALGO_RX_WOW)
#include "randomx_constants_wow.h"
#elif (ALGO == ALGO_RX_LOKI)
#include "randomx_constants_loki.h"
#endif
#include "aes.cl"
#include "blake2b.cl"
#include "randomx_vm.cl"
#include "randomx_jit.cl"

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
@ -95,4 +94,3 @@ along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.
#define LOC_L1 (32 - 14)
#define LOC_L2 (32 - 18)
#define LOC_L3 (32 - 21)
)==="

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
@ -40,7 +39,7 @@ along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.
#define RANDOMX_JUMP_OFFSET 8
//Integer instructions
#define RANDOMX_FREQ_IADD_RS 25
#define RANDOMX_FREQ_IADD_RS 16
#define RANDOMX_FREQ_IADD_M 7
#define RANDOMX_FREQ_ISUB_R 16
#define RANDOMX_FREQ_ISUB_M 7
@ -70,7 +69,7 @@ along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.
#define RANDOMX_FREQ_FSQRT_R 6
//Control instructions
#define RANDOMX_FREQ_CBRANCH 16
#define RANDOMX_FREQ_CBRANCH 25
#define RANDOMX_FREQ_CFROUND 1
//Store instruction
@ -95,4 +94,3 @@ along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.
#define LOC_L1 (32 - 14)
#define LOC_L2 (32 - 18)
#define LOC_L3 (32 - 21)
)==="

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
@ -95,4 +94,3 @@ along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.
#define LOC_L1 (32 - 14)
#define LOC_L2 (32 - 17)
#define LOC_L3 (32 - 20)
)==="

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
Portions Copyright (c) 2018-2019 tevador
@ -152,9 +151,6 @@ __global uint* jit_scratchpad_load2_fp(__global uint* p, uint vgpr_index, int vm
return p;
}
)==="
R"===(
__global uint* jit_emit_instruction(__global uint* p, __global uint* last_branch_target, const uint2 inst, int prefetch_vgpr_index, int vmcnt, uint batch_size)
{
uint opcode = inst.x & 0xFF;
@ -670,9 +666,6 @@ __global uint* jit_emit_instruction(__global uint* p, __global uint* last_branch
}
opcode -= RANDOMX_FREQ_FADD_R;
)==="
R"===(
if (opcode < RANDOMX_FREQ_FADD_M)
{
if (prefetch_vgpr_index >= 0)
@ -905,9 +898,6 @@ int jit_prefetch_read(
return prefetch_data_count + 1;
}
)==="
R"===(
__global uint* generate_jit_code(__global uint2* e, __global uint2* p0, __global uint* p, uint batch_size)
{
int prefetch_data_count;
@ -1440,9 +1430,6 @@ __global uint* generate_jit_code(__global uint2* e, __global uint2* p0, __global
return p;
}
)==="
R"===(
__attribute__((reqd_work_group_size(64, 1, 1)))
__kernel void randomx_jit(__global ulong* entropy, __global ulong* registers, __global uint2* intermediate_programs, __global uint* programs, uint batch_size, __global uint32_t* rounding, uint32_t iteration)
{
@ -1506,5 +1493,3 @@ __kernel void randomx_jit(__global ulong* entropy, __global ulong* registers, __
R[20] = getFloatMask(entropy[14]);
R[21] = getFloatMask(entropy[15]);
}
)==="

View file

@ -1,4 +1,3 @@
R"===(
/*
Copyright (c) 2019 SChernykh
Portions Copyright (c) 2018-2019 tevador
@ -150,9 +149,6 @@ uint64_t imul_rcp_value(uint32_t divisor)
return quotient;
}
)==="
R"===(
#define set_byte(a, position, value) do { ((uint8_t*)&(a))[(position)] = (value); } while (0)
uint32_t get_byte(uint64_t a, uint32_t position) { return (a >> (position << 3)) & 0xFF; }
#define update_max(value, next_value) do { if ((value) < (next_value)) (value) = (next_value); } while (0)
@ -343,9 +339,6 @@ __kernel void init_vm(__global const void* entropy_data, __global void* vm_state
// printf("\n");
//}
)==="
R"===(
// Schedule instructions
bool update_branch_target_mark = false;
bool first_available_slot_is_branch_target = false;
@ -931,9 +924,6 @@ R"===(
int32_t imm_index_fscal_r = -1;
__global uint32_t* compiled_program = (__global uint32_t*)(R + (REGISTERS_SIZE + IMM_BUF_SIZE) / sizeof(uint64_t));
)==="
R"===(
// Generate opcodes for execute_vm
int32_t branch_target_slot = -1;
int32_t k = -1;
@ -1413,9 +1403,6 @@ double load_F_E_groups(int value, uint64_t andMask, uint64_t orMask)
return as_double(x);
}
)==="
R"===(
// You're one ugly motherfucker!
double fma_soft(double a, double b, double c, uint32_t rounding_mode)
{
@ -1881,9 +1868,6 @@ uint32_t inner_loop(
return fprc;
}
)==="
R"===(
#if WORKERS_PER_HASH == 16
__attribute__((reqd_work_group_size(32, 1, 1)))
#else
@ -2066,5 +2050,3 @@ __kernel void find_shares(__global const uint64_t* hashes, uint64_t target, uint
}
}
}
)==="

View file

@ -43,9 +43,16 @@ class OclLaunchData;
class OclBaseRunner : public IOclRunner
{
public:
OclBaseRunner() = delete;
OclBaseRunner(const OclBaseRunner &other) = delete;
OclBaseRunner(OclBaseRunner &&other) = delete;
OclBaseRunner(size_t id, const OclLaunchData &data);
~OclBaseRunner() override;
OclBaseRunner &operator=(const OclBaseRunner &other) = delete;
OclBaseRunner &operator=(OclBaseRunner &&other) = delete;
protected:
inline cl_context ctx() const override { return m_ctx; }
inline const Algorithm &algorithm() const override { return m_algorithm; }

View file

@ -24,9 +24,33 @@
#include "backend/opencl/runners/OclRxRunner.h"
#include "backend/opencl/OclLaunchData.h"
xmrig::OclRxRunner::OclRxRunner(size_t index, const OclLaunchData &data) : OclBaseRunner(index, data)
{
uint32_t worksize = 0;
uint32_t gcn_version = 12;
switch (data.thread.worksize()) {
case 2:
case 4:
case 8:
case 16:
worksize = data.thread.worksize();
break;
default:
worksize = 8;
}
if (data.device.type() == OclDevice::Vega_10 || data.device.type() == OclDevice::Vega_20) {
gcn_version = 14;
}
m_options += " -DALGO=" + std::to_string(m_algorithm.id());
m_options += " -DWORKERS_PER_HASH=" + std::to_string(worksize);
m_options += " -DGCN_VERSION=" + std::to_string(gcn_version);
}
@ -46,3 +70,13 @@ bool xmrig::OclRxRunner::set(const Job &job, uint8_t *blob)
{
return false;
}
void xmrig::OclRxRunner::build()
{
OclBaseRunner::build();
if (!m_program) {
return;
}
}

View file

@ -41,6 +41,7 @@ protected:
bool run(uint32_t nonce, uint32_t *hashOutput) override;
bool selfTest() const override;
bool set(const Job &job, uint8_t *blob) override;
void build() override;
};

View file

@ -39,6 +39,10 @@ namespace xmrig {
class Algorithm
{
public:
// Changes in following file is required if this enum changed:
//
// src/backend/opencl/cl/cn/algorithm.cl
//
enum Id : int {
INVALID = -1,
CN_0, // "cn/0" CryptoNight (original).