diff --git a/.gitignore b/.gitignore index f9fec50..7cf9060 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,8 @@ CMakeUserPresets.json *.ptx *.cubin *.fatbin + +# Coin miner executables +coin_miner_cpu +coin_miner_simd +coin_miner_cuda diff --git a/aad_coin_miner_simd.c b/aad_coin_miner_simd.c index c05ab9a..28405bd 100644 --- a/aad_coin_miner_simd.c +++ b/aad_coin_miner_simd.c @@ -30,39 +30,61 @@ static int is_valid_coin(u32_t *hash) return hash[0] == 0xAAD20250u; } +// +// increment coin variable part using the same logic as CPU miner +// returns 0 if overflow (all positions wrapped around), 1 otherwise +// +static int increment_coin(u32_t coin[14]) +{ + // Increment the variable part using byte-by-byte logic with carry + // Increment from the end to beginning (positions 53 down to 12) + int pos = 53; + while(pos >= 12) + { + u08_t *byte = &((u08_t *)coin)[pos ^ 3]; + if(*byte == '\n' || *byte == 0x80) + *byte = 32; // Start from space + + (*byte)++; + + // Skip newline character + if(*byte == '\n') + (*byte)++; + + // Wrap around at 127 (printable ASCII limit) + if(*byte >= 127) + { + *byte = 32; // Reset to space + pos--; // Carry to next position + } + else + { + break; // No carry needed + } + } + + // Return 0 if we carried all the way through (overflow), 1 otherwise + return (pos >= 12); +} + // // prepare interleaved data for SIMD processing // -static void prepare_coins(u32_t base_coin[14], u32_t *interleaved_data, int simd_width, u64_t base_counter) +static void prepare_coins(u32_t base_coin[14], u32_t *interleaved_data, int simd_width) { for(int lane = 0; lane < simd_width; lane++) { u32_t coin[14]; memcpy(coin, base_coin, sizeof(coin)); - // Modify the coin for this lane (encode counter in the variable part) - u64_t counter = base_counter + lane; - for(int i = 12; i < 20 && i < 54; i++) - { - int shift = (19 - i) * 8; - if(shift >= 0 && shift < 64) - { - u08_t byte = (counter >> shift) & 0xFF; - // Map to ASCII printable range (32-126, excluding newline position) - if(byte == '\n' || byte >= 0x80) - byte = 'X'; - // Ensure byte is in printable ASCII range (32-126) - // Map all values to ASCII printable characters: space (32) to tilde (126) - // byte = 32 + (byte % 95); - ((u08_t *)coin)[i ^ 3] = byte; - } - } - // Interleave the data for(int idx = 0; idx < 14; idx++) { interleaved_data[idx * simd_width + lane] = coin[idx]; } + + // Increment the base coin for the next lane + increment_coin(base_coin); } } @@ -125,19 +147,21 @@ static void mine_coins_avx(u64_t max_attempts) ((u08_t *)base_coin)[0x36 ^ 3] = '\n'; ((u08_t *)base_coin)[0x37 ^ 3] = 0x80; - // Initialize variable part + // Initialize variable part with A-Z cycling pattern (same as CPU miner) for(int i = 12; i < 54; i++) - ((u08_t *)base_coin)[i ^ 3] = 'A'; + ((u08_t *)base_coin)[i ^ 3] = 'A' + (i - 12) % 26; printf("Mining DETI coins using AVX (4-way SIMD)...\n"); printf("Press Ctrl+C to stop\n\n"); time_measurement(); + time_measurement(); + double start_time = wall_time_delta(); while(keep_running && (max_attempts == 0 || attempts < max_attempts)) { // Prepare coins for this batch - prepare_coins(base_coin, interleaved_data, SIMD_WIDTH, attempts); + prepare_coins(base_coin, interleaved_data, SIMD_WIDTH); // Compute SHA1 hashes sha1_avx((v4si *)interleaved_data, (v4si *)interleaved_hash); @@ -163,13 +187,16 @@ static void mine_coins_avx(u64_t max_attempts) // Print progress every 1M attempts if(attempts % 1000000 < SIMD_WIDTH) { - printf("Attempts: %llu, Coins: %u\n", - (unsigned long long)attempts, coins_found); + time_measurement(); + double current_time = wall_time_delta() - start_time; + double rate = attempts / current_time; + printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u\n", + (unsigned long long)attempts, rate / 1e6, coins_found); } } time_measurement(); - double total_time = wall_time_delta(); + double total_time = wall_time_delta() - start_time; printf("\n=== Mining Statistics ===\n"); printf("Total attempts: %llu\n", (unsigned long long)attempts); @@ -212,17 +239,20 @@ static void mine_coins_avx2(u64_t max_attempts) ((u08_t *)base_coin)[0x36 ^ 3] = '\n'; ((u08_t *)base_coin)[0x37 ^ 3] = 0x80; + // Initialize variable part with A-Z cycling pattern (same as CPU miner) for(int i = 12; i < 54; i++) - ((u08_t *)base_coin)[i ^ 3] = 'A'; + ((u08_t *)base_coin)[i ^ 3] = 'A' + (i - 12) % 26; printf("Mining DETI coins using AVX2 (8-way SIMD)...\n"); printf("Press Ctrl+C to stop\n\n"); time_measurement(); + time_measurement(); + double start_time = wall_time_delta(); while(keep_running && (max_attempts == 0 || attempts < max_attempts)) { - prepare_coins(base_coin, interleaved_data, SIMD_WIDTH, attempts); + prepare_coins(base_coin, interleaved_data, SIMD_WIDTH); sha1_avx2((v8si *)interleaved_data, (v8si *)interleaved_hash); attempts += SIMD_WIDTH; @@ -244,13 +274,16 @@ static void mine_coins_avx2(u64_t max_attempts) if(attempts % 1000000 < SIMD_WIDTH) { - printf("Attempts: %llu, Coins: %u\n", - (unsigned long long)attempts, coins_found); + time_measurement(); + double current_time = wall_time_delta() - start_time; + double rate = attempts / current_time; + printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u\n", + (unsigned long long)attempts, rate / 1e6, coins_found); } } time_measurement(); - double total_time = wall_time_delta(); + double total_time = wall_time_delta() - start_time; printf("\n=== Mining Statistics ===\n"); printf("Total attempts: %llu\n", (unsigned long long)attempts); diff --git a/makefile b/makefile index a295547..c3c2381 100644 --- a/makefile +++ b/makefile @@ -42,6 +42,7 @@ CUDA_ARCH = sm_75 clean: rm -f sha1_tests rm -f sha1_cuda_test sha1_cuda_kernel.cubin + rm -f coin_miner_cpu coin_miner_simd coin_miner_cuda rm -f a.out @@ -63,4 +64,15 @@ sha1_cuda_test: aad_sha1_cuda_test.c sha1_cuda_kernel.cubin aad_sha1.h aad_data_ sha1_cuda_kernel.cubin: aad_sha1_cuda_kernel.cu aad_sha1.h makefile nvcc -arch=$(CUDA_ARCH) --compiler-options -O2,-Wall -I$(CUDA_DIR)/include --cubin $< -o $@ -all: sha1_tests sha1_cuda_test sha1_cuda_kernel.cubin +# +# DETI coin miners +# + +coin_miner_cpu: aad_coin_miner_cpu.c aad_data_types.h aad_utilities.h aad_sha1.h aad_sha1_cpu.h aad_vault.h makefile + cc -march=native -Wall -Wshadow -Werror -O3 $< -o $@ + +coin_miner_simd: aad_coin_miner_simd.c aad_data_types.h aad_utilities.h aad_sha1.h aad_sha1_cpu.h aad_vault.h makefile + cc -march=native -mavx2 -Wall -Wshadow -Werror -O3 $< -o $@ + + +all: sha1_tests sha1_cuda_test sha1_cuda_kernel.cubin coin_miner_cpu coin_miner_simd diff --git a/sha1_cuda_kernel.cubin b/sha1_cuda_kernel.cubin deleted file mode 100644 index 957c529..0000000 Binary files a/sha1_cuda_kernel.cubin and /dev/null differ diff --git a/sha1_tests b/sha1_tests deleted file mode 100755 index b3ee06c..0000000 Binary files a/sha1_tests and /dev/null differ