Use external script to prepare OpenCL source.

This commit is contained in:
XMRig 2019-08-28 00:33:49 +07:00
parent 82696000e4
commit fcfb738ded
17 changed files with 2948 additions and 693 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
/build
/CMakeLists.txt.user
/.idea
/src/backend/opencl/cl/cn/cryptonight_gen.cl

23
package.json Normal file
View File

@ -0,0 +1,23 @@
{
"name": "xmrig",
"version": "3.0.0",
"description": "RandomX, CryptoNight and Argon2 miner",
"main": "index.js",
"directories": {
"doc": "doc"
},
"scripts": {
"build": "node scripts/generate_cl.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xmrig/xmrig.git"
},
"keywords": [],
"author": "",
"license": "GPLv3",
"bugs": {
"url": "https://github.com/xmrig/xmrig/issues"
},
"homepage": "https://github.com/xmrig/xmrig#readme"
}

32
scripts/generate_cl.js Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const { text2h, addIncludes } = require('./js/opencl');
const cwd = process.cwd();
function cn()
{
process.chdir(cwd);
process.chdir(path.resolve('src/backend/opencl/cl/cn'));
const cn = addIncludes('cryptonight.cl', [
'algorithm.cl',
'wolf-aes.cl',
'wolf-skein.cl',
'jh.cl',
'blake256.cl',
'groestl256.cl',
'fast_int_math_v2.cl',
'fast_div_heavy.cl'
]);
//fs.writeFileSync('cryptonight_gen.cl', cn);
fs.writeFileSync('cryptonight_cl.h', text2h(cn, 'xmrig', 'cryptonight_cl'));
}
cn();

72
scripts/js/opencl.js Normal file
View File

@ -0,0 +1,72 @@
'use strict';
const fs = require('fs');
function bin2h(buf, namespace, name)
{
const size = buf.byteLength;
let out = `#pragma once\n\nnamespace ${namespace} {\n\nstatic unsigned char ${name}[${size}] = {\n `;
let b = 32;
for (let i = 0; i < size; i++) {
out += `0x${buf.readUInt8(i).toString(16).padStart(2, '0')}${size - i > 1 ? ',' : ''}`;
if (--b === 0) {
b = 32;
out += '\n ';
}
}
out += `\n};\n\n} // namespace ${namespace}\n`;
return out;
}
function text2h(text, namespace, name)
{
const buf = Buffer.from(text);
const size = buf.byteLength;
let out = `#pragma once\n\nnamespace ${namespace} {\n\nstatic char ${name}[${size + 1}] = {\n `;
let b = 32;
for (let i = 0; i < size; i++) {
out += `0x${buf.readUInt8(i).toString(16).padStart(2, '0')},`;
if (--b === 0) {
b = 32;
out += '\n ';
}
}
out += '0x00';
out += `\n};\n\n} // namespace ${namespace}\n`;
return out;
}
function addInclude(input, name)
{
return input.replace(`#include "${name}"`, fs.readFileSync(name, 'utf8'));
}
function addIncludes(inputFileName, names)
{
let data = fs.readFileSync(inputFileName, 'utf8');
for (let name of names) {
data = addInclude(data, name);
}
return data;
}
module.exports.bin2h = bin2h;
module.exports.text2h = text2h;
module.exports.addInclude = addInclude;
module.exports.addIncludes = addIncludes;

View File

@ -29,7 +29,6 @@
#include "backend/common/Hashrate.h"
#include "backend/common/interfaces/IWorker.h"
#include "backend/common/Workers.h"
#include "backend/opencl/cl/OclSource.h"
#include "backend/opencl/OclBackend.h"
#include "backend/opencl/OclConfig.h"
#include "backend/opencl/OclLaunchData.h"
@ -96,8 +95,6 @@ public:
inline OclBackendPrivate(Controller *controller) :
controller(controller)
{
OclSource::init();
init(controller->config()->cl());
}

View File

@ -23,75 +23,16 @@
*/
#include <string>
#include <regex>
#include "backend/opencl/cl/cn/cryptonight_cl.h"
#include "backend/opencl/cl/OclSource.h"
#include "crypto/common/Algorithm.h"
namespace xmrig {
static std::string cn_source;
} // namespace xmrig
const char *xmrig::OclSource::get(const Algorithm &algorithm)
{
if (algorithm.family() == Algorithm::RANDOM_X) {
return nullptr; // FIXME
}
return cn_source.c_str();
}
void xmrig::OclSource::init()
{
const char *cryptonightCL =
#include "./cn/cryptonight.cl"
;
const char *cryptonightCL2 =
#include "./cn/cryptonight2.cl"
;
const char *blake256CL =
#include "./cn/blake256.cl"
;
const char *groestl256CL =
#include "./cn/groestl256.cl"
;
const char *jhCL =
#include "./cn/jh.cl"
;
const char *wolfAesCL =
#include "./cn/wolf-aes.cl"
;
const char *wolfSkeinCL =
#include "./cn/wolf-skein.cl"
;
const char *fastIntMathV2CL =
#include "./cn/fast_int_math_v2.cl"
;
const char *fastDivHeavyCL =
#include "./cn/fast_div_heavy.cl"
;
const char *cryptonight_gpu =
#include "./cn/cryptonight_gpu.cl"
;
cn_source.append(cryptonightCL);
cn_source.append(cryptonightCL2);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_WOLF_AES"), wolfAesCL);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_WOLF_SKEIN"), wolfSkeinCL);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_JH"), jhCL);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_BLAKE256"), blake256CL);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_GROESTL256"), groestl256CL);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_FAST_INT_MATH_V2"), fastIntMathV2CL);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_FAST_DIV_HEAVY"), fastDivHeavyCL);
cn_source = std::regex_replace(cn_source, std::regex("XMRIG_INCLUDE_CN_GPU"), cryptonight_gpu);
return cryptonight_cl;
}

View File

@ -0,0 +1,27 @@
enum Algorithm {
ALGO_INVALID = -1,
ALGO_CN_0, // "cn/0" CryptoNight (original).
ALGO_CN_1, // "cn/1" CryptoNight variant 1 also known as Monero7 and CryptoNightV7.
ALGO_CN_2, // "cn/2" CryptoNight variant 2.
ALGO_CN_R, // "cn/r" CryptoNightR (Monero's variant 4).
ALGO_CN_FAST, // "cn/fast" CryptoNight variant 1 with half iterations.
ALGO_CN_HALF, // "cn/half" CryptoNight variant 2 with half iterations (Masari/Torque).
ALGO_CN_XAO, // "cn/xao" CryptoNight variant 0 (modified, Alloy only).
ALGO_CN_RTO, // "cn/rto" CryptoNight variant 1 (modified, Arto only).
ALGO_CN_RWZ, // "cn/rwz" CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft).
ALGO_CN_ZLS, // "cn/zls" CryptoNight variant 2 with 3/4 iterations (Zelerius).
ALGO_CN_DOUBLE, // "cn/double" CryptoNight variant 2 with double iterations (X-CASH).
ALGO_CN_GPU, // "cn/gpu" CryptoNight-GPU (Ryo).
ALGO_CN_LITE_0, // "cn-lite/0" CryptoNight-Lite variant 0.
ALGO_CN_LITE_1, // "cn-lite/1" CryptoNight-Lite variant 1.
ALGO_CN_HEAVY_0, // "cn-heavy/0" CryptoNight-Heavy (4 MB).
ALGO_CN_HEAVY_TUBE, // "cn-heavy/tube" CryptoNight-Heavy (modified, TUBE only).
ALGO_CN_HEAVY_XHV, // "cn-heavy/xhv" CryptoNight-Heavy (modified, Haven Protocol only).
ALGO_CN_PICO_0, // "cn-pico" CryptoNight Turtle (TRTL)
ALGO_RX_0, // "rx/0" RandomX (reference configuration).
ALGO_RX_WOW, // "rx/wow" RandomWOW (Wownero).
ALGO_RX_LOKI, // "rx/loki" RandomXL (Loki).
ALGO_AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa).
ALGO_AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ)
ALGO_MAX
};

View File

@ -1,4 +1,3 @@
R"===(
/*
* blake256 kernel implementation.
*
@ -90,4 +89,3 @@ __constant static const sph_u32 c_u256[16] = {
v[b] ^= v[c]; \
v[b] = rotate(v[b], 25U); \
}
)==="

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,3 @@
R"===(
#ifndef FAST_DIV_HEAVY_CL
#define FAST_DIV_HEAVY_CL
@ -26,4 +25,3 @@ inline long fast_div_heavy(long _a, int _b)
}
#endif
)==="

View File

@ -1,4 +1,3 @@
R"===(
/*
* @author SChernykh
*/
@ -53,5 +52,3 @@ inline uint fast_sqrt_v2(const ulong n1)
return result;
}
)==="

View File

@ -1,4 +1,3 @@
R"===(
/* $Id: groestl.c 260 2011-07-21 01:02:38Z tp $ */
/*
* Groestl256
@ -124,9 +123,6 @@ static const __constant ulong T0_G[] =
0x7bcbf646cb463d7bUL, 0xa8fc4b1ffc1fb7a8UL, 0x6dd6da61d6610c6dUL, 0x2c3a584e3a4e622cUL
};
)==="
R"===(
static const __constant ulong T4_G[] =
{
0xA5F432C6C6A597F4UL, 0x84976FF8F884EB97UL, 0x99B05EEEEE99C7B0UL, 0x8D8C7AF6F68DF78CUL,
@ -291,5 +287,3 @@ static const __constant ulong T4_G[] =
ROUND_SMALL_Q(a, r); \
} while (0)
)==="

View File

@ -1,4 +1,3 @@
R"===(
/* $Id: jh.c 255 2011-06-07 19:50:20Z tp $ */
/*
* JH implementation.
@ -270,5 +269,3 @@ static const __constant ulong C[] =
} while (0)
#endif
)==="

View File

@ -1,4 +1,3 @@
R"===(
#ifndef WOLF_AES_CL
#define WOLF_AES_CL
@ -149,5 +148,3 @@ uint4 AES_Round_Two_Tables(const __local uint *AES0, const __local uint *AES1, c
}
#endif
)==="

View File

@ -1,4 +1,3 @@
R"===(
#ifndef WOLF_SKEIN_CL
#define WOLF_SKEIN_CL
@ -137,5 +136,3 @@ ulong8 Skein512Block(ulong8 p, ulong8 h, ulong h8, const ulong *t)
}
#endif
)==="

View File

@ -52,30 +52,18 @@ public:
CN_RWZ, // "cn/rwz" CryptoNight variant 2 with 3/4 iterations and reversed shuffle operation (Graft).
CN_ZLS, // "cn/zls" CryptoNight variant 2 with 3/4 iterations (Zelerius).
CN_DOUBLE, // "cn/double" CryptoNight variant 2 with double iterations (X-CASH).
# ifdef XMRIG_ALGO_CN_GPU
CN_GPU, // "cn/gpu" CryptoNight-GPU (Ryo).
# endif
# ifdef XMRIG_ALGO_CN_LITE
CN_LITE_0, // "cn-lite/0" CryptoNight-Lite variant 0.
CN_LITE_1, // "cn-lite/1" CryptoNight-Lite variant 1.
# endif
# ifdef XMRIG_ALGO_CN_HEAVY
CN_HEAVY_0, // "cn-heavy/0" CryptoNight-Heavy (4 MB).
CN_HEAVY_TUBE, // "cn-heavy/tube" CryptoNight-Heavy (modified, TUBE only).
CN_HEAVY_XHV, // "cn-heavy/xhv" CryptoNight-Heavy (modified, Haven Protocol only).
# endif
# ifdef XMRIG_ALGO_CN_PICO
CN_PICO_0, // "cn-pico" CryptoNight Turtle (TRTL)
# endif
# ifdef XMRIG_ALGO_RANDOMX
RX_0, // "rx/0" RandomX (reference configuration).
RX_WOW, // "rx/wow" RandomWOW (Wownero).
RX_LOKI, // "rx/loki" RandomXL (Loki).
# endif
# ifdef XMRIG_ALGO_ARGON2
AR2_CHUKWA, // "argon2/chukwa"
AR2_WRKZ, // "argon2/wrkz"
# endif
AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa).
AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ)
MAX
};