├── .gitignore
├── .gitattributes
├── .gitmodules
├── RandomX_OpenCL
├── makefile
├── RandomX_OpenCL.vcxproj.user
├── tests.h
├── CL
│ ├── randomx_constants_jit.h
│ ├── randomx_constants.h
│ ├── blake2b_double_block.cl
│ ├── randomx_run.cl
│ ├── fillAes1Rx4.cl
│ ├── blake2b.cl
│ └── aes.cl
├── miner.h
├── definitions.h
├── RandomX_OpenCL.vcxproj.filters
├── RandomX_OpenCL.cpp
├── opencl_helpers.h
├── RandomX_OpenCL.vcxproj
├── opencl_helpers.cpp
├── tests.cpp
├── miner.cpp
└── GCNASM
│ ├── randomx_run_gfx900.asm
│ ├── randomx_run_gfx803.asm
│ └── randomx_run_gfx1010.asm
├── RandomX_OpenCL.sln
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs
2 | x64
3 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "RandomX"]
2 | path = RandomX
3 | url = https://github.com/SChernykh/RandomX
4 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/makefile:
--------------------------------------------------------------------------------
1 | release: *.h *.cpp GCNASM/*.asm
2 | clrxasm GCNASM/randomx_run_gfx803.asm -o randomx_run_gfx803.bin
3 | clrxasm GCNASM/randomx_run_gfx900.asm -o randomx_run_gfx900.bin
4 | g++ *.cpp -O3 -lOpenCL -lpthread ../RandomX/build/librandomx.a -o opencl_test
5 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/RandomX_OpenCL.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | --mine --validate --portable --workers 8 --bfactor 5 --intensity 3584
5 | WindowsLocalDebugger
6 |
7 |
8 | --mine --validate --intensity 1984
9 | WindowsLocalDebugger
10 |
11 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/tests.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | bool tests(uint32_t platform_id, uint32_t device_id, size_t intensity);
23 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/CL/randomx_constants_jit.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #define INITIAL_HASH_SIZE 64
23 | #define INTERMEDIATE_PROGRAM_SIZE (RANDOMX_PROGRAM_SIZE * 16)
24 | #define COMPILED_PROGRAM_SIZE 10048
25 | #define NUM_VGPR_REGISTERS 128
26 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/miner.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | bool test_mining(uint32_t platform_id, uint32_t device_id, size_t intensity, uint32_t start_nonce, uint32_t workers_per_hash, uint32_t bfactor, bool portable, bool dataset_host_allocated, bool validate);
23 |
--------------------------------------------------------------------------------
/RandomX_OpenCL.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.28307.645
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RandomX_OpenCL", "RandomX_OpenCL\RandomX_OpenCL.vcxproj", "{32C205F3-317C-4EE6-8B8B-E2B6D87B8CC4}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {3346A4AD-C438-4324-8B77-47A16452954B} = {3346A4AD-C438-4324-8B77-47A16452954B}
9 | EndProjectSection
10 | EndProject
11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "randomx", "RandomX\vcxproj\randomx.vcxproj", "{3346A4AD-C438-4324-8B77-47A16452954B}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|x64 = Debug|x64
16 | Debug|x86 = Debug|x86
17 | Release|x64 = Release|x64
18 | Release|x86 = Release|x86
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {32C205F3-317C-4EE6-8B8B-E2B6D87B8CC4}.Debug|x64.ActiveCfg = Debug|x64
22 | {32C205F3-317C-4EE6-8B8B-E2B6D87B8CC4}.Debug|x64.Build.0 = Debug|x64
23 | {32C205F3-317C-4EE6-8B8B-E2B6D87B8CC4}.Debug|x86.ActiveCfg = Debug|x64
24 | {32C205F3-317C-4EE6-8B8B-E2B6D87B8CC4}.Release|x64.ActiveCfg = Release|x64
25 | {32C205F3-317C-4EE6-8B8B-E2B6D87B8CC4}.Release|x64.Build.0 = Release|x64
26 | {32C205F3-317C-4EE6-8B8B-E2B6D87B8CC4}.Release|x86.ActiveCfg = Release|x64
27 | {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x64.ActiveCfg = Release|x64
28 | {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x64.Build.0 = Release|x64
29 | {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x86.ActiveCfg = Debug|Win32
30 | {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x86.Build.0 = Debug|Win32
31 | {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x64.ActiveCfg = Release|x64
32 | {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x64.Build.0 = Release|x64
33 | {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x86.ActiveCfg = Release|Win32
34 | {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x86.Build.0 = Release|Win32
35 | EndGlobalSection
36 | GlobalSection(SolutionProperties) = preSolution
37 | HideSolutionNode = FALSE
38 | EndGlobalSection
39 | GlobalSection(ExtensibilityGlobals) = postSolution
40 | SolutionGuid = {D7CE6C55-7FD7-4C3E-A52E-E3128C74A127}
41 | EndGlobalSection
42 | EndGlobal
43 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RandomX OpenCL implementation
2 |
3 | This repository contains full RandomX OpenCL implementation (portable code for all GPUs and optimized code AMD Vega GPUs). The latest version of RandomX (1.1.0 as of August 30th, 2019) is supported.
4 |
5 | Note: it's only a benchmark/testing tool, not an actual miner. RandomX hashrate is expected to improve somewhat in the future thanks to further optimizations.
6 |
7 | GPUs tested so far:
8 |
9 | Model|CryptonightR H/S|RandomX H/S|Relative speed|Comment
10 | -----|---------------|-----------|---------------|-------
11 | AMD Radeon VII (stock)|3125|1500|48%|JIT compiled mode, 150W
12 | AMD Vega 64 (1700/1100 MHz)|2200|1225|55.7%|JIT compiled mode, 285W
13 | AMD Vega 64 (1100/800 MHz)|1023|845|82.6%|JIT compiled mode, 115W
14 | AMD Vega 64 (1700/1100 MHz)|2200|163|7.4%|VM interpreted mode
15 | AMD Vega FE (stock)|2150|980|45.6%|JIT compiled mode (intensity 4096)
16 | AMD Radeon RX 560 4GB (1400/2200 MHz)|495|260|52.5%|JIT compiled mode (intensity 896)
17 | AMD Radeon RX RX470/570 4GB|930-950|400-410|43%|JIT compiled mode, 50W
18 | AMD Radeon RX RX480/580 4GB|960-1000|470|47%|JIT compiled mode, 60W
19 | GeForce GTX 1080 Ti (2037/11800 MHz)|927|601|64.8%|VM interpreted mode
20 |
21 | ## Building on Windows
22 |
23 | - Install Visual Studio 2017 Community and [CLRadeonExtender](https://github.com/CLRX/CLRX-mirror/releases)
24 | - Add CLRadeonExtender's bin directory to PATH environment variable
25 | - Open .sln file in Visual Studio and build it
26 |
27 | ## Building on Ubuntu
28 |
29 | - Install prerequisites `sudo apt install git cmake build-essential`
30 | - If you want to try JIT compiled code for Vega or Polaris GPUs, install amdgpu-pro drivers with OpenCL enabled (run the install script like this `./amdgpu-pro-install --opencl=pal`)
31 | - Download [CLRadeonExtender](https://github.com/CLRX/CLRX-mirror/releases) and copy `clrxasm` to `/usr/local/bin`
32 | - Then run commands:
33 | ```
34 | git clone --recursive https://github.com/SChernykh/RandomX_OpenCL
35 | cd RandomX_OpenCL/RandomX
36 | mkdir build && cd build
37 | cmake -DARCH=native ..
38 | make
39 | cd ../../RandomX_OpenCL
40 | make
41 | ```
42 |
43 | ## Donations
44 |
45 | If you'd like to support further development/optimization of RandomX miners (both CPU and AMD/NVIDIA), you're welcome to send any amount of XMR to the following address:
46 |
47 | ```
48 | 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg
49 | ```
50 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/definitions.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 | #include "CL/randomx_constants.h"
24 | #include "CL/randomx_constants_jit.h"
25 |
26 | static const std::string AES_CL = "CL/aes.cl";
27 | static const std::string CL_FILLAES1RX4_SCRATCHPAD = "fillAes1Rx4_scratchpad";
28 | static const std::string CL_FILLAES4RX4_ENTROPY = "fillAes4Rx4_entropy";
29 | static const std::string CL_HASHAES1RX4 = "hashAes1Rx4";
30 |
31 | static const std::string BLAKE2B_CL = "CL/blake2b.cl";
32 | static const std::string CL_BLAKE2B_INITIAL_HASH = "blake2b_initial_hash";
33 | static const std::string CL_BLAKE2B_HASH_REGISTERS_32 = "blake2b_hash_registers_32";
34 | static const std::string CL_BLAKE2B_HASH_REGISTERS_64 = "blake2b_hash_registers_64";
35 | static const std::string CL_BLAKE2B_512_SINGLE_BLOCK_BENCH = "blake2b_512_single_block_bench";
36 | static const std::string CL_BLAKE2B_512_DOUBLE_BLOCK_BENCH = "blake2b_512_double_block_bench";
37 |
38 | static const std::string RANDOMX_INIT_CL = "CL/randomx_init.cl";
39 | static const std::string CL_RANDOMX_INIT = "randomx_init";
40 |
41 | static const std::string RANDOMX_RUN_CL = "CL/randomx_run.cl";
42 | static const std::string CL_RANDOMX_RUN = "randomx_run";
43 |
44 | static const std::string RANDOMX_VM_CL = "CL/randomx_vm.cl";
45 | static const std::string CL_INIT_VM = "init_vm";
46 | static const std::string CL_EXECUTE_VM = "execute_vm";
47 |
48 | static uint8_t blockTemplate[] = {
49 | 0x07, 0x07, 0xf7, 0xa4, 0xf0, 0xd6, 0x05, 0xb3, 0x03, 0x26, 0x08, 0x16, 0xba, 0x3f, 0x10, 0x90, 0x2e, 0x1a, 0x14,
50 | 0x5a, 0xc5, 0xfa, 0xd3, 0xaa, 0x3a, 0xf6, 0xea, 0x44, 0xc1, 0x18, 0x69, 0xdc, 0x4f, 0x85, 0x3f, 0x00, 0x2b, 0x2e,
51 | 0xea, 0x00, 0x00, 0x00, 0x00, 0x77, 0xb2, 0x06, 0xa0, 0x2c, 0xa5, 0xb1, 0xd4, 0xce, 0x6b, 0xbf, 0xdf, 0x0a, 0xca,
52 | 0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09
53 | };
54 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/RandomX_OpenCL.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {7789d323-c959-469b-addc-91336f3201fc}
14 |
15 |
16 | {181c0a82-12c6-4d82-8e7f-51fe2a1cee17}
17 |
18 |
19 |
20 |
21 | Source Files
22 |
23 |
24 | Source Files
25 |
26 |
27 | Source Files
28 |
29 |
30 | Source Files
31 |
32 |
33 |
34 |
35 | Header Files
36 |
37 |
38 | Header Files
39 |
40 |
41 | Header Files
42 |
43 |
44 | Header Files
45 |
46 |
47 | Header Files
48 |
49 |
50 | Header Files
51 |
52 |
53 |
54 |
55 | Source Files\CL
56 |
57 |
58 | Source Files\CL
59 |
60 |
61 | Source Files\CL
62 |
63 |
64 | Source Files\CL
65 |
66 |
67 | Source Files\CL
68 |
69 |
70 | Source Files\CL
71 |
72 |
73 | Source Files\CL
74 |
75 |
76 |
77 |
78 | Source Files\GCNASM
79 |
80 |
81 | Source Files\GCNASM
82 |
83 |
84 | Source Files\GCNASM
85 |
86 |
87 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/RandomX_OpenCL.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include "tests.h"
25 | #include "miner.h"
26 |
27 | int main(int argc, char** argv)
28 | {
29 | if (argc < 2)
30 | {
31 | printf("Usage: %s --mine [--validate] [--platform_id N] [--device_id N] [--intensity N] [--portable] [--workers N] [--bfactor N] [--dataset_host]\n\n", argv[0]);
32 | printf("platform_id 0 if you have only 1 OpenCL platform\n");
33 | printf("device_id 0 if you have only 1 GPU\n");
34 | printf("intensity number of scratchpads to allocate, if it's not set then as many as possible will be allocated.\n\n");
35 | printf("portable use generic OpenCL code that works on all GPUs.\n\n");
36 | printf("workers number of parallel workers per hash to run in portable mode. Can be 2,4,8,16, default is 8.\n\n");
37 | printf("bfactor splits main loop into multiple sub-steps. Use it to improve screen responsiveness. Can be 0-10, default is 5.\n\n");
38 | printf("dataset_host allocate dataset on host. This is required for 2 GB GPUs.\n\n");
39 | printf("Examples:\n%s --mine --validate --intensity 1984\n", argv[0]);
40 | return 0;
41 | }
42 |
43 | uint32_t platform_id = 0;
44 | uint32_t device_id = 0;
45 | size_t intensity = 0;
46 | uint32_t start_nonce = 0;
47 | uint32_t workers_per_hash = 8;
48 | uint32_t bfactor = 5;
49 | bool portable = false;
50 | bool dataset_host_allocated = false;
51 | bool validate = false;
52 |
53 | for (int i = 1; i < argc; ++i)
54 | {
55 | if ((strcmp(argv[i], "--platform_id") == 0) && (i + 1 < argc))
56 | platform_id = atoi(argv[i + 1]);
57 | else if ((strcmp(argv[i], "--device_id") == 0) && (i + 1 < argc))
58 | device_id = atoi(argv[i + 1]);
59 | else if ((strcmp(argv[i], "--intensity") == 0) && (i + 1 < argc))
60 | intensity = atoi(argv[i + 1]);
61 | else if ((strcmp(argv[i], "--nonce") == 0) && (i + 1 < argc))
62 | start_nonce = atoi(argv[i + 1]);
63 | else if ((strcmp(argv[i], "--workers") == 0) && (i + 1 < argc))
64 | workers_per_hash = atoi(argv[i + 1]);
65 | else if ((strcmp(argv[i], "--bfactor") == 0) && (i + 1 < argc))
66 | bfactor = atoi(argv[i + 1]);
67 | else if (strcmp(argv[i], "--portable") == 0)
68 | portable = true;
69 | else if (strcmp(argv[i], "--dataset_host") == 0)
70 | dataset_host_allocated = true;
71 | else if (strcmp(argv[i], "--validate") == 0)
72 | validate = true;
73 | }
74 |
75 | if (strcmp(argv[1], "--mine") == 0)
76 | return test_mining(platform_id, device_id, intensity, start_nonce, workers_per_hash, bfactor, portable, dataset_host_allocated, validate) ? 0 : 1;
77 | else if (strcmp(argv[1], "--test") == 0)
78 | return tests(platform_id, device_id, intensity) ? 0 : 1;
79 |
80 | return 0;
81 | }
82 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/CL/randomx_constants.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | //Dataset base size in bytes. Must be a power of 2.
23 | #define RANDOMX_DATASET_BASE_SIZE 2147483648
24 |
25 | //Dataset extra size. Must be divisible by 64.
26 | #define RANDOMX_DATASET_EXTRA_SIZE 33554368
27 |
28 | //Scratchpad L3 size in bytes. Must be a power of 2.
29 | #define RANDOMX_SCRATCHPAD_L3 2097152
30 |
31 | //Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3.
32 | #define RANDOMX_SCRATCHPAD_L2 262144
33 |
34 | //Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2.
35 | #define RANDOMX_SCRATCHPAD_L1 16384
36 |
37 | //Jump condition mask size in bits.
38 | #define RANDOMX_JUMP_BITS 8
39 |
40 | //Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16.
41 | #define RANDOMX_JUMP_OFFSET 8
42 |
43 | //Integer instructions
44 | #define RANDOMX_FREQ_IADD_RS 16
45 | #define RANDOMX_FREQ_IADD_M 7
46 | #define RANDOMX_FREQ_ISUB_R 16
47 | #define RANDOMX_FREQ_ISUB_M 7
48 | #define RANDOMX_FREQ_IMUL_R 16
49 | #define RANDOMX_FREQ_IMUL_M 4
50 | #define RANDOMX_FREQ_IMULH_R 4
51 | #define RANDOMX_FREQ_IMULH_M 1
52 | #define RANDOMX_FREQ_ISMULH_R 4
53 | #define RANDOMX_FREQ_ISMULH_M 1
54 | #define RANDOMX_FREQ_IMUL_RCP 8
55 | #define RANDOMX_FREQ_INEG_R 2
56 | #define RANDOMX_FREQ_IXOR_R 15
57 | #define RANDOMX_FREQ_IXOR_M 5
58 | #define RANDOMX_FREQ_IROR_R 8
59 | #define RANDOMX_FREQ_IROL_R 2
60 | #define RANDOMX_FREQ_ISWAP_R 4
61 |
62 | //Floating point instructions
63 | #define RANDOMX_FREQ_FSWAP_R 4
64 | #define RANDOMX_FREQ_FADD_R 16
65 | #define RANDOMX_FREQ_FADD_M 5
66 | #define RANDOMX_FREQ_FSUB_R 16
67 | #define RANDOMX_FREQ_FSUB_M 5
68 | #define RANDOMX_FREQ_FSCAL_R 6
69 | #define RANDOMX_FREQ_FMUL_R 32
70 | #define RANDOMX_FREQ_FDIV_M 4
71 | #define RANDOMX_FREQ_FSQRT_R 6
72 |
73 | //Control instructions
74 | #define RANDOMX_FREQ_CBRANCH 25
75 | #define RANDOMX_FREQ_CFROUND 1
76 |
77 | //Store instruction
78 | #define RANDOMX_FREQ_ISTORE 16
79 |
80 | //No-op instruction
81 | #define RANDOMX_FREQ_NOP 0
82 |
83 | #define RANDOMX_DATASET_ITEM_SIZE 64
84 |
85 | #define RANDOMX_PROGRAM_SIZE 256
86 |
87 | #define HASH_SIZE 64
88 | #define ENTROPY_SIZE (128 + RANDOMX_PROGRAM_SIZE * 8)
89 | #define REGISTERS_SIZE 256
90 | #define IMM_BUF_SIZE (RANDOMX_PROGRAM_SIZE * 4 - REGISTERS_SIZE)
91 | #define IMM_INDEX_COUNT ((IMM_BUF_SIZE / 4) - 2)
92 | #define VM_STATE_SIZE (REGISTERS_SIZE + IMM_BUF_SIZE + RANDOMX_PROGRAM_SIZE * 4)
93 | #define ROUNDING_MODE (RANDOMX_FREQ_CFROUND ? -1 : 0)
94 |
95 | // Scratchpad L1/L2/L3 bits
96 | #define LOC_L1 (32 - 14)
97 | #define LOC_L2 (32 - 18)
98 | #define LOC_L3 (32 - 21)
99 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/CL/blake2b_double_block.cl:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | void blake2b_512_process_double_block_name(ulong *out, ulong* m, __global const ulong* in)
21 | {
22 | ulong v[16] =
23 | {
24 | iv0 ^ (0x01010000u | out_len), iv1, iv2, iv3, iv4 , iv5, iv6, iv7,
25 | iv0 , iv1, iv2, iv3, iv4 ^ 128, iv5, iv6, iv7,
26 | };
27 |
28 | BLAKE2B_ROUNDS();
29 |
30 | ulong h[8];
31 | v[0] = h[0] = v[0] ^ v[8] ^ iv0 ^ (0x01010000u | out_len);
32 | v[1] = h[1] = v[1] ^ v[9] ^ iv1;
33 | v[2] = h[2] = v[2] ^ v[10] ^ iv2;
34 | v[3] = h[3] = v[3] ^ v[11] ^ iv3;
35 | v[4] = h[4] = v[4] ^ v[12] ^ iv4;
36 | v[5] = h[5] = v[5] ^ v[13] ^ iv5;
37 | v[6] = h[6] = v[6] ^ v[14] ^ iv6;
38 | v[7] = h[7] = v[7] ^ v[15] ^ iv7;
39 | v[8] = iv0;
40 | v[9] = iv1;
41 | v[10] = iv2;
42 | v[11] = iv3;
43 | v[12] = iv4 ^ in_len;
44 | v[13] = iv5;
45 | v[14] = ~iv6;
46 | v[15] = iv7;
47 |
48 | m[ 0] = (in_len > 128) ? in[16] : 0;
49 | m[ 1] = (in_len > 136) ? in[17] : 0;
50 | m[ 2] = (in_len > 144) ? in[18] : 0;
51 | m[ 3] = (in_len > 152) ? in[19] : 0;
52 | m[ 4] = (in_len > 160) ? in[20] : 0;
53 | m[ 5] = (in_len > 168) ? in[21] : 0;
54 | m[ 6] = (in_len > 176) ? in[22] : 0;
55 | m[ 7] = (in_len > 184) ? in[23] : 0;
56 | m[ 8] = (in_len > 192) ? in[24] : 0;
57 | m[ 9] = (in_len > 200) ? in[25] : 0;
58 | m[10] = (in_len > 208) ? in[26] : 0;
59 | m[11] = (in_len > 216) ? in[27] : 0;
60 | m[12] = (in_len > 224) ? in[28] : 0;
61 | m[13] = (in_len > 232) ? in[29] : 0;
62 | m[14] = (in_len > 240) ? in[30] : 0;
63 | m[15] = (in_len > 248) ? in[31] : 0;
64 |
65 | if (in_len % sizeof(ulong))
66 | m[(in_len - 128) / sizeof(ulong)] &= (ulong)(-1) >> (64 - (in_len % sizeof(ulong)) * 8);
67 |
68 | BLAKE2B_ROUNDS();
69 |
70 | if (out_len > 0) out[0] = h[0] ^ v[0] ^ v[8];
71 | if (out_len > 8) out[1] = h[1] ^ v[1] ^ v[9];
72 | if (out_len > 16) out[2] = h[2] ^ v[2] ^ v[10];
73 | if (out_len > 24) out[3] = h[3] ^ v[3] ^ v[11];
74 | if (out_len > 32) out[4] = h[4] ^ v[4] ^ v[12];
75 | if (out_len > 40) out[5] = h[5] ^ v[5] ^ v[13];
76 | if (out_len > 48) out[6] = h[6] ^ v[6] ^ v[14];
77 | if (out_len > 56) out[7] = h[7] ^ v[7] ^ v[15];
78 | }
79 |
80 | __attribute__((reqd_work_group_size(64, 1, 1)))
81 | __kernel void blake2b_hash_registers_name(__global void *out, __global const void* in, uint inStrideBytes)
82 | {
83 | const uint global_index = get_global_id(0);
84 | __global const ulong* p = ((__global const ulong*) in) + global_index * (inStrideBytes / sizeof(ulong));
85 | __global ulong* h = ((__global ulong*) out) + global_index * (out_len / sizeof(ulong));
86 |
87 | ulong m[16] = { p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15] };
88 |
89 | ulong hash[8];
90 | blake2b_512_process_double_block_name(hash, m, p);
91 |
92 | if (out_len > 0) h[0] = hash[0];
93 | if (out_len > 8) h[1] = hash[1];
94 | if (out_len > 16) h[2] = hash[2];
95 | if (out_len > 24) h[3] = hash[3];
96 | if (out_len > 32) h[4] = hash[4];
97 | if (out_len > 40) h[5] = hash[5];
98 | if (out_len > 48) h[6] = hash[6];
99 | if (out_len > 56) h[7] = hash[7];
100 | }
101 |
--------------------------------------------------------------------------------
/RandomX_OpenCL/opencl_helpers.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2019 SChernykh
3 |
4 | This file is part of RandomX OpenCL.
5 |
6 | RandomX OpenCL is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | RandomX OpenCL is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with RandomX OpenCL. If not, see .
18 | */
19 |
20 | #pragma once
21 |
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include