Skip to content

Commit 565e18e

Browse files
authored
Merge pull request #18 from tmrlvi/v0.4
V0.4
2 parents 53c7f86 + 0492183 commit 565e18e

30 files changed

+45640
-9194
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Kaspa-miner
2-
[![Build status](https://github.com/elichai/kaspa-miner/workflows/ci/badge.svg)](https://github.com/elichai/kaspa-miner/actions)
2+
[![Build status](https://github.com/tmrlvi/kaspa-miner/workflows/ci/badge.svg)](https://github.com/tmrlvi/kaspa-miner/actions)
33
[![Latest version](https://img.shields.io/crates/v/kaspa-miner.svg)](https://crates.io/crates/kaspa-miner)
44
![License](https://img.shields.io/crates/l/kaspa-miner.svg)
55
[![dependency status](https://deps.rs/repo/github/elichai/kaspa-miner/status.svg)](https://deps.rs/repo/github/elichai/kaspa-miner)
66

7-
A Rust binary for file encryption to multiple participants.
7+
[![Discord](https://img.shields.io/badge/Discord-%237289DA.svg?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/kS3SK5F36R)
8+
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/Kaspaenglish)
89

910

1011
## Installation
@@ -99,7 +100,7 @@ A miner that wants to mine a percentage into the dev-fund can pass the following
99100
and can pass `--devfund-precent=XX.YY` to mine only XX.YY% of the blocks into the devfund (passing `--devfund` without specifying a percent will default to 1%)
100101

101102
**This version automatically sets the devfund donation to the community designated address.
102-
To turn it off, run `--devfund-precent=0`**
103+
Due to community decision, the minimum amount in the precompiled binaries is 2%**
103104

104105
# Donation Addresses
105106

plugins/cuda/README.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ you have to clone the project:
1414
```sh
1515
git clone https://github.com/tmrlvi/kaspa-miner.git
1616
cd kaspa-miner
17-
# Using cuda nvcc that supports sm_30 (e.g., 9.2)
18-
nvcc kaspa-cuda-native/src/kaspa-cuda.cu -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_30 --gpu-code=sm_30 -o ./resources/kaspa-cuda-sm30.ptx -Xptxas -O3 -Xcompiler -O3
19-
# Using cuda nvcc from a recent cuda (e.g. 11.5)
20-
nvcc kaspa-cuda-native/src/kaspa-cuda.cu -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_61 --gpu-code=sm_61 -o ./resources/kaspa-cuda-sm61.ptx -Xptxas -O3 -Xcompiler -O3
17+
# Compute version 8.6
18+
/usr/local/cuda-11.5/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_86 --gpu-code=sm_86 -o plugins/cuda/resources/kaspa-cuda-sm86.ptx -Xptxas -O3 -Xcompiler -O3
19+
# Compute version 7.5
20+
/usr/local/cuda-11.5/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_75 --gpu-code=sm_75 -o plugins/cuda/resources/kaspa-cuda-sm75.ptx -Xptxas -O3 -Xcompiler -O3
21+
# Compute version 6.1
22+
/usr/local/cuda-11.2/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_61 --gpu-code=sm_61 -o plugins/cuda/resources/kaspa-cuda-sm61.ptx -Xptxas -O3 -Xcompiler -O3
23+
# Compute version 3.0
24+
/usr/local/cuda-9.2/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -ccbin=gcc-7 -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_30 --gpu-code=sm_30 -o plugins/cuda/resources/kaspa-cuda-sm30.ptx
25+
# Compute version 2.0
26+
/usr/local/cuda-8.0/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -ccbin=gcc-5 -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_20 --gpu-code=sm_20 -o plugins/cuda/resources/kaspa-cuda-sm20.ptx
27+
2128
cargo build --release
2229
```
30+
31+
/usr/local/cuda-11.2/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_61 --gpu-code=sm_61 -o plugins/cuda/resources/kaspa-cuda-sm61.ptx -Xptxas -O3 -Xcompiler -O3
32+
/usr/local/cuda-9.2/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -ccbin=gcc-7 -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_30 --gpu-code=sm_30 -o plugins/cuda/resources/kaspa-cuda-sm30.ptx
33+
/usr/local/cuda-8.0/bin/nvcc plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu -ccbin=gcc-5 -std=c++11 -O3 --restrict --ptx --gpu-architecture=compute_20 --gpu-code=sm_20 -o plugins/cuda/resources/kaspa-cuda-sm20.ptx

plugins/cuda/kaspa-cuda-native/src/kaspa-cuda.cu

+20-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ __constant__ uint256_t target;
2626
__constant__ static const uint8_t powP[Plen] = { 0x3d, 0xd8, 0xf6, 0xa1, 0x0d, 0xff, 0x3c, 0x11, 0x3c, 0x7e, 0x02, 0xb7, 0x55, 0x88, 0xbf, 0x29, 0xd2, 0x44, 0xfb, 0x0e, 0x72, 0x2e, 0x5f, 0x1e, 0xa0, 0x69, 0x98, 0xf5, 0xa3, 0xa4, 0xa5, 0x1b, 0x65, 0x2d, 0x5e, 0x87, 0xca, 0xaf, 0x2f, 0x7b, 0x46, 0xe2, 0xdc, 0x29, 0xd6, 0x61, 0xef, 0x4a, 0x10, 0x5b, 0x41, 0xad, 0x1e, 0x98, 0x3a, 0x18, 0x9c, 0xc2, 0x9b, 0x78, 0x0c, 0xf6, 0x6b, 0x77, 0x40, 0x31, 0x66, 0x88, 0x33, 0xf1, 0xeb, 0xf8, 0xf0, 0x5f, 0x28, 0x43, 0x3c, 0x1c, 0x65, 0x2e, 0x0a, 0x4a, 0xf1, 0x40, 0x05, 0x07, 0x96, 0x0f, 0x52, 0x91, 0x29, 0x5b, 0x87, 0x67, 0xe3, 0x44, 0x15, 0x37, 0xb1, 0x25, 0xa4, 0xf1, 0x70, 0xec, 0x89, 0xda, 0xe9, 0x82, 0x8f, 0x5d, 0xc8, 0xe6, 0x23, 0xb2, 0xb4, 0x85, 0x1f, 0x60, 0x1a, 0xb2, 0x46, 0x6a, 0xa3, 0x64, 0x90, 0x54, 0x85, 0x34, 0x1a, 0x85, 0x2f, 0x7a, 0x1c, 0xdd, 0x06, 0x0f, 0x42, 0xb1, 0x3b, 0x56, 0x1d, 0x02, 0xa2, 0xc1, 0xe4, 0x68, 0x16, 0x45, 0xe4, 0xe5, 0x1d, 0xba, 0x8d, 0x5f, 0x09, 0x05, 0x41, 0x57, 0x02, 0xd1, 0x4a, 0xcf, 0xce, 0x9b, 0x84, 0x4e, 0xca, 0x89, 0xdb, 0x2e, 0x74, 0xa8, 0x27, 0x94, 0xb0, 0x48, 0x72, 0x52, 0x8b, 0xe7, 0x9c, 0xce, 0xfc, 0xb1, 0xbc, 0xa5, 0xaf, 0x82, 0xcf, 0x29, 0x11, 0x5d, 0x83, 0x43, 0x82, 0x6f, 0x78, 0x7c, 0xb9, 0x02 };
2727
__constant__ static const uint8_t heavyP[Plen] = { 0x09, 0x85, 0x24, 0xb2, 0x52, 0x4c, 0xd7, 0x3a, 0x16, 0x42, 0x9f, 0x2f, 0x0e, 0x9b, 0x62, 0x79, 0xee, 0xf8, 0xc7, 0x16, 0x48, 0xff, 0x14, 0x7a, 0x98, 0x64, 0x05, 0x80, 0x4c, 0x5f, 0xa7, 0x11, 0xda, 0xce, 0xee, 0x44, 0xdf, 0xe0, 0x20, 0xe7, 0x69, 0x40, 0xf3, 0x14, 0x2e, 0xd8, 0xc7, 0x72, 0xba, 0x35, 0x89, 0x93, 0x2a, 0xff, 0x00, 0xc1, 0x62, 0xc4, 0x0f, 0x25, 0x40, 0x90, 0x21, 0x5e, 0x48, 0x6a, 0xcf, 0x0d, 0xa6, 0xf9, 0x39, 0x80, 0x0c, 0x3d, 0x2a, 0x79, 0x9f, 0xaa, 0xbc, 0xa0, 0x26, 0xa2, 0xa9, 0xd0, 0x5d, 0xc0, 0x31, 0xf4, 0x3f, 0x8c, 0xc1, 0x54, 0xc3, 0x4c, 0x1f, 0xd3, 0x3d, 0xcc, 0x69, 0xa7, 0x01, 0x7d, 0x6b, 0x6c, 0xe4, 0x93, 0x24, 0x56, 0xd3, 0x5b, 0xc6, 0x2e, 0x44, 0xb0, 0xcd, 0x99, 0x3a, 0x4b, 0xf7, 0x4e, 0xb0, 0xf2, 0x34, 0x54, 0x83, 0x86, 0x4c, 0x77, 0x16, 0x94, 0xbc, 0x36, 0xb0, 0x61, 0xe9, 0x07, 0x07, 0xcc, 0x65, 0x77, 0xb1, 0x1d, 0x8f, 0x7e, 0x39, 0x6d, 0xc4, 0xba, 0x80, 0xdb, 0x8f, 0xea, 0x58, 0xca, 0x34, 0x7b, 0xd3, 0xf2, 0x92, 0xb9, 0x57, 0xb9, 0x81, 0x84, 0x04, 0xc5, 0x76, 0xc7, 0x2e, 0xc2, 0x12, 0x51, 0x67, 0x9f, 0xc3, 0x47, 0x0a, 0x0c, 0x29, 0xb5, 0x9d, 0x39, 0xbb, 0x92, 0x15, 0xc6, 0x9f, 0x2f, 0x31, 0xe0, 0x9a, 0x54, 0x35, 0xda, 0xb9, 0x10, 0x7d, 0x32, 0x19, 0x16 };
2828

29-
__device__ __inline__ uint32_t amul4bit(uint32_t packed_vec1[32], uint32_t packed_vec2[32]) {
29+
__device__ __inline__ void amul4bit(uint32_t packed_vec1[32], uint32_t packed_vec2[32], uint32_t *ret) {
3030
// We assume each 32 bits have four values: A0 B0 C0 D0
3131
unsigned int res = 0;
3232
#if __CUDA_ARCH__ < 610
@@ -45,7 +45,7 @@ __device__ __inline__ uint32_t amul4bit(uint32_t packed_vec1[32], uint32_t packe
4545
#endif
4646
}
4747

48-
return res;
48+
*ret = res;
4949
}
5050

5151

@@ -65,7 +65,7 @@ extern "C" {
6565
// TODO: check endianity?
6666
uint256_t hash_;
6767
memcpy(input + HASH_HEADER_SIZE, (uint8_t *)(&nonce), 8);
68-
hash(powP, hash_.hash, input, 80);
68+
hash(powP, hash_.hash, input);
6969

7070
//assert((rowId != 0) || (hashId != 0) );
7171
uchar4 packed_hash[QUARTER_MATRIX_SIZE] = {0};
@@ -78,17 +78,26 @@ extern "C" {
7878
(hash_.hash[2*i+1] & 0x0F)
7979
);
8080
}
81-
81+
uint32_t product1, product2;
82+
#pragma unroll
8283
for (int rowId=0; rowId<HALF_MATRIX_SIZE; rowId++){
8384

84-
uint32_t product1 = amul4bit((uint32_t *)(matrix[(2*rowId)]), (uint32_t *)(packed_hash)) >> 10;
85-
uint32_t product2 = amul4bit((uint32_t *)(matrix[(2*rowId+1)]), (uint32_t *)(packed_hash)) >> 10;
86-
87-
88-
hash_.hash[rowId] = hash_.hash[rowId] ^ ((uint8_t)(product1 << 4) | (uint8_t)(product2));
85+
amul4bit((uint32_t *)(matrix[(2*rowId)]), (uint32_t *)(packed_hash), &product1);
86+
amul4bit((uint32_t *)(matrix[(2*rowId+1)]), (uint32_t *)(packed_hash), &product2);
87+
product1 >>= 6;
88+
product1 &= 0xF0;
89+
product2 >>= 10;
90+
#if __CUDA_ARCH__ < 500 || __CUDA_ARCH__ > 700
91+
hash_.hash[rowId] = hash_.hash[rowId] ^ ((uint8_t)(product1) | (uint8_t)(product2));
92+
#else
93+
uint32_t lop_temp = hash_.hash[rowId];
94+
asm("lop3.b32" " %0, %1, %2, %3, 0x56;": "=r" (lop_temp): "r" (product1), "r" (product2), "r" (lop_temp));
95+
hash_.hash[rowId] = lop_temp;
96+
#endif
8997
}
90-
91-
hash(heavyP, hash_.hash, hash_.hash, 32);
98+
memset(input, 0, 80);
99+
memcpy(input, hash_.hash, 32);
100+
hash(heavyP, hash_.hash, input);
92101
if (LT_U256(hash_, target)){
93102
atomicCAS((unsigned long long int*) final_nonce, 0, (unsigned long long int) nonce);
94103
}

plugins/cuda/kaspa-cuda-native/src/keccak-tiny.c

+11-21
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ __device__ static inline void keccakf(void* state) {
5050
uint64_t t = 0;
5151
uint8_t x, y;
5252

53-
//#pragma unroll
5453
for (int i = 0; i < 24; i++) {
5554
// Theta
5655
FOR5(x, 1,
@@ -82,36 +81,27 @@ __device__ static inline void keccakf(void* state) {
8281
/******** The FIPS202-defined functions. ********/
8382

8483
/*** Some helper macros. ***/
85-
86-
#define _(S) do { S } while (0)
87-
#define FOR(i, ST, L, S) \
88-
_(for (size_t i = 0; i < L; i += ST) { S; })
89-
#define mkapply_ds(NAME, S) \
90-
__device__ static inline void NAME(uint8_t* dst, \
91-
const uint8_t* src, \
92-
size_t len) { \
93-
FOR(i, 1, len, S); \
94-
}
95-
96-
mkapply_ds(xorin, dst[i] ^= src[i]) // xorin
97-
9884
#define P keccakf
9985
#define Plen 200
10086

10187

10288
/** The sponge-based hash construction. **/
103-
__device__ __forceinline__ static int hash(
89+
__device__ __forceinline__ static void hash(
10490
const uint8_t initP[Plen],
10591
uint8_t* out,
106-
const uint8_t* in, size_t inlen) {
92+
const uint8_t* in) {
10793
uint8_t a[Plen] = {0};
108-
memcpy(a, initP, Plen);
109-
// Xor in the last block.
110-
xorin(a, in, inlen);
94+
95+
#pragma unroll
96+
for (int i=0; i<10; i++) ((uint64_t *)a)[i] = ((uint64_t *)initP)[i] ^ ((uint64_t *)in)[i];
97+
#pragma unroll
98+
for (int i=10; i<25; i++) ((uint64_t *)a)[i] = ((uint64_t *)initP)[i];
99+
111100
// Apply P
112101
P(a);
113102
// Squeeze output.
114-
memcpy(out, a, 32);
115-
return 0;
103+
#pragma unroll
104+
for (int i=0; i<4; i++) ((uint64_t *)out)[i] = ((uint64_t *)a)[i];
105+
116106
}
117107

0 commit comments

Comments
 (0)