Fix timers
Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
3829b9b9df
commit
ecf0ac85cd
|
|
@ -65,3 +65,9 @@ CMakeUserPresets.json
|
||||||
coin_miner_cpu
|
coin_miner_cpu
|
||||||
coin_miner_simd
|
coin_miner_simd
|
||||||
coin_miner_cuda
|
coin_miner_cuda
|
||||||
|
coin_miner_ocl
|
||||||
|
coin_miner_wasm.js
|
||||||
|
coin_miner_wasm.wasm
|
||||||
|
|
||||||
|
# Vault
|
||||||
|
deti_coins*_vault.txt
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,14 @@ static int is_valid_coin(u32_t *hash)
|
||||||
return hash[0] == 0xAAD20250u;
|
return hash[0] == 0xAAD20250u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get current wall time in seconds
|
||||||
|
static double get_wall_time(void)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return (double)ts.tv_sec + (double)ts.tv_nsec * 1.0e-9;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// mine DETI coins using the CPU (no SIMD)
|
// mine DETI coins using the CPU (no SIMD)
|
||||||
//
|
//
|
||||||
|
|
@ -69,9 +77,7 @@ static void mine_coins_cpu(u64_t max_attempts)
|
||||||
printf("Mining DETI coins using CPU (no SIMD)...\n");
|
printf("Mining DETI coins using CPU (no SIMD)...\n");
|
||||||
printf("Press Ctrl+C to stop\n\n");
|
printf("Press Ctrl+C to stop\n\n");
|
||||||
|
|
||||||
time_measurement();
|
double start_time = get_wall_time();
|
||||||
time_measurement();
|
|
||||||
double start_time = wall_time_delta();
|
|
||||||
|
|
||||||
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
||||||
{
|
{
|
||||||
|
|
@ -117,16 +123,14 @@ static void mine_coins_cpu(u64_t max_attempts)
|
||||||
// Print progress every 1M attempts
|
// Print progress every 1M attempts
|
||||||
if(attempts % 1000000 == 0)
|
if(attempts % 1000000 == 0)
|
||||||
{
|
{
|
||||||
time_measurement();
|
double elapsed = get_wall_time() - start_time;
|
||||||
double current_time = wall_time_delta() - start_time;
|
double rate = attempts / elapsed;
|
||||||
double rate = attempts / current_time;
|
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u, Elapsed: %.2fs\n",
|
||||||
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u\n",
|
(unsigned long long)attempts, rate / 1e6, coins_found, elapsed);
|
||||||
(unsigned long long)attempts, rate / 1e6, coins_found);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_measurement();
|
double total_time = get_wall_time() - start_time;
|
||||||
double total_time = wall_time_delta() - start_time;
|
|
||||||
|
|
||||||
printf("\n=== Mining Statistics ===\n");
|
printf("\n=== Mining Statistics ===\n");
|
||||||
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
||||||
|
|
@ -160,4 +164,3 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,14 @@ static void reconstruct_coin(u32_t *stored_data, u32_t coin[14])
|
||||||
coin[i] = stored_data[i];
|
coin[i] = stored_data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get current wall time in seconds
|
||||||
|
static double get_wall_time(void)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return (double)ts.tv_sec + (double)ts.tv_nsec * 1.0e-9;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Mine DETI coins using OpenCL
|
// Mine DETI coins using OpenCL
|
||||||
//
|
//
|
||||||
|
|
@ -57,7 +65,7 @@ static void mine_coins_ocl(u64_t max_attempts, int use_scan_kernel)
|
||||||
|
|
||||||
// Kernel configuration
|
// Kernel configuration
|
||||||
od.local_work_size = RECOMMENDED_OCL_WORK_GROUP_SIZE;
|
od.local_work_size = RECOMMENDED_OCL_WORK_GROUP_SIZE;
|
||||||
od.global_work_size = 4096 * od.local_work_size; // Large grid for maximum GPU utilization
|
od.global_work_size = 4096 * od.local_work_size;
|
||||||
|
|
||||||
u32_t n_threads = od.global_work_size;
|
u32_t n_threads = od.global_work_size;
|
||||||
|
|
||||||
|
|
@ -68,58 +76,16 @@ static void mine_coins_ocl(u64_t max_attempts, int use_scan_kernel)
|
||||||
printf("Kernel: %s\n", od.kernel_name);
|
printf("Kernel: %s\n", od.kernel_name);
|
||||||
printf("Press Ctrl+C to stop\n\n");
|
printf("Press Ctrl+C to stop\n\n");
|
||||||
|
|
||||||
// Test SHA1 on host to verify it matches
|
|
||||||
printf("Testing SHA1 implementation on host...\n");
|
|
||||||
u32_t test_coin[14];
|
|
||||||
memset(test_coin, 0, sizeof(test_coin));
|
|
||||||
((u08_t *)test_coin)[0x0 ^ 3] = 'D';
|
|
||||||
((u08_t *)test_coin)[0x1 ^ 3] = 'E';
|
|
||||||
((u08_t *)test_coin)[0x2 ^ 3] = 'T';
|
|
||||||
((u08_t *)test_coin)[0x3 ^ 3] = 'I';
|
|
||||||
((u08_t *)test_coin)[0x4 ^ 3] = ' ';
|
|
||||||
((u08_t *)test_coin)[0x5 ^ 3] = 'c';
|
|
||||||
((u08_t *)test_coin)[0x6 ^ 3] = 'o';
|
|
||||||
((u08_t *)test_coin)[0x7 ^ 3] = 'i';
|
|
||||||
((u08_t *)test_coin)[0x8 ^ 3] = 'n';
|
|
||||||
((u08_t *)test_coin)[0x9 ^ 3] = ' ';
|
|
||||||
((u08_t *)test_coin)[0xa ^ 3] = '2';
|
|
||||||
((u08_t *)test_coin)[0xb ^ 3] = ' ';
|
|
||||||
((u08_t *)test_coin)[0x36 ^ 3] = '\n';
|
|
||||||
((u08_t *)test_coin)[0x37 ^ 3] = 0x80;
|
|
||||||
for(int i = 12; i < 54; i++)
|
|
||||||
((u08_t *)test_coin)[i ^ 3] = 'A' + (i - 12) % 26;
|
|
||||||
|
|
||||||
u32_t test_hash[5];
|
|
||||||
sha1(test_coin, test_hash);
|
|
||||||
printf("Host test hash: 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n",
|
|
||||||
test_hash[0], test_hash[1], test_hash[2], test_hash[3], test_hash[4]);
|
|
||||||
|
|
||||||
// Now test on device
|
|
||||||
printf("Testing SHA1 implementation on device...\n");
|
|
||||||
host_storage[0] = 1u;
|
|
||||||
|
|
||||||
// Put the test coin in storage starting at index 1
|
|
||||||
for(int i = 0; i < 14; i++)
|
|
||||||
host_storage[1 + i] = test_coin[i];
|
|
||||||
|
|
||||||
// Copy to device
|
|
||||||
host_to_device_copy(&od, 0);
|
|
||||||
|
|
||||||
// We'll add a test kernel - for now just verify basic kernel launch works
|
|
||||||
printf("Starting mining...\n\n");
|
|
||||||
|
|
||||||
u32_t param1 = (u32_t)time(NULL);
|
u32_t param1 = (u32_t)time(NULL);
|
||||||
u32_t param2 = 0x12345678u;
|
u32_t param2 = 0x12345678u;
|
||||||
int scan_pos = 12;
|
int scan_pos = 12;
|
||||||
|
|
||||||
time_measurement();
|
double start_time = get_wall_time();
|
||||||
time_measurement();
|
|
||||||
double start_time = wall_time_delta();
|
|
||||||
|
|
||||||
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
||||||
{
|
{
|
||||||
// Initialize storage area
|
// Initialize storage area
|
||||||
host_storage[0] = 1u; // First unused index
|
host_storage[0] = 1u;
|
||||||
|
|
||||||
// Copy to device
|
// Copy to device
|
||||||
host_to_device_copy(&od, 0);
|
host_to_device_copy(&od, 0);
|
||||||
|
|
@ -139,7 +105,6 @@ static void mine_coins_ocl(u64_t max_attempts, int use_scan_kernel)
|
||||||
device_to_host_copy(&od, 0);
|
device_to_host_copy(&od, 0);
|
||||||
|
|
||||||
// Process found coins
|
// Process found coins
|
||||||
u32_t n_coins_this_kernel = 0;
|
|
||||||
u32_t n_stored = (host_storage[0] - 1) / 14;
|
u32_t n_stored = (host_storage[0] - 1) / 14;
|
||||||
|
|
||||||
if(n_stored > 0 && host_storage[0] < COINS_STORAGE_SIZE)
|
if(n_stored > 0 && host_storage[0] < COINS_STORAGE_SIZE)
|
||||||
|
|
@ -156,9 +121,7 @@ static void mine_coins_ocl(u64_t max_attempts, int use_scan_kernel)
|
||||||
if(hash[0] == 0xAAD20250u)
|
if(hash[0] == 0xAAD20250u)
|
||||||
{
|
{
|
||||||
coins_found++;
|
coins_found++;
|
||||||
n_coins_this_kernel++;
|
printf("COIN FOUND! (kernel %u)\n", kernel_runs);
|
||||||
printf("COIN FOUND! (kernel %u, coin %u in this kernel)\n",
|
|
||||||
kernel_runs, n_coins_this_kernel);
|
|
||||||
save_coin(coin);
|
save_coin(coin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +130,7 @@ static void mine_coins_ocl(u64_t max_attempts, int use_scan_kernel)
|
||||||
// Update counters
|
// Update counters
|
||||||
kernel_runs++;
|
kernel_runs++;
|
||||||
if(use_scan_kernel)
|
if(use_scan_kernel)
|
||||||
attempts += n_threads * 256; // Each thread tries 256 values
|
attempts += n_threads * 95; // Each thread tries 95 printable ASCII values
|
||||||
else
|
else
|
||||||
attempts += n_threads;
|
attempts += n_threads;
|
||||||
|
|
||||||
|
|
@ -175,21 +138,19 @@ static void mine_coins_ocl(u64_t max_attempts, int use_scan_kernel)
|
||||||
param1++;
|
param1++;
|
||||||
param2 = param2 ^ 0x9E3779B9u;
|
param2 = param2 ^ 0x9E3779B9u;
|
||||||
if(use_scan_kernel)
|
if(use_scan_kernel)
|
||||||
scan_pos = (scan_pos + 1) % 42 + 12; // Cycle through positions 12-53
|
scan_pos = (scan_pos + 1) % 42 + 12;
|
||||||
|
|
||||||
// Print progress every 10 kernel launches
|
// Print progress every 10 kernel launches
|
||||||
if(kernel_runs % 10 == 0)
|
if(kernel_runs % 10 == 0)
|
||||||
{
|
{
|
||||||
time_measurement();
|
double elapsed = get_wall_time() - start_time;
|
||||||
double current_time = wall_time_delta() - start_time;
|
double rate = attempts / elapsed;
|
||||||
double rate = attempts / current_time;
|
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u, Kernels: %u, Elapsed: %.2fs\n",
|
||||||
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u, Kernels: %u\n",
|
(unsigned long long)attempts, rate / 1e6, coins_found, kernel_runs, elapsed);
|
||||||
(unsigned long long)attempts, rate / 1e6, coins_found, kernel_runs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_measurement();
|
double total_time = get_wall_time() - start_time;
|
||||||
double total_time = wall_time_delta() - start_time;
|
|
||||||
|
|
||||||
printf("\n=== Mining Statistics ===\n");
|
printf("\n=== Mining Statistics ===\n");
|
||||||
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
||||||
|
|
@ -217,7 +178,7 @@ int main(int argc, char *argv[])
|
||||||
if(argc > 2 && strcmp(argv[2], "scan") == 0)
|
if(argc > 2 && strcmp(argv[2], "scan") == 0)
|
||||||
{
|
{
|
||||||
use_scan_kernel = 1;
|
use_scan_kernel = 1;
|
||||||
printf("Using scan kernel (tries 256 values per thread)\n");
|
printf("Using scan kernel (tries 95 values per thread)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
mine_coins_ocl(max_attempts, use_scan_kernel);
|
mine_coins_ocl(max_attempts, use_scan_kernel);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,14 @@ static int is_valid_coin(u32_t *hash)
|
||||||
return hash[0] == 0xAAD20250u;
|
return hash[0] == 0xAAD20250u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get current wall time in seconds
|
||||||
|
static double get_wall_time(void)
|
||||||
|
{
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return (double)ts.tv_sec + (double)ts.tv_nsec * 1.0e-9;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// increment coin variable part using the same logic as CPU miner
|
// increment coin variable part using the same logic as CPU miner
|
||||||
// returns 0 if overflow (all positions wrapped around), 1 otherwise
|
// returns 0 if overflow (all positions wrapped around), 1 otherwise
|
||||||
|
|
@ -154,9 +162,7 @@ static void mine_coins_avx(u64_t max_attempts)
|
||||||
printf("Mining DETI coins using AVX (4-way SIMD)...\n");
|
printf("Mining DETI coins using AVX (4-way SIMD)...\n");
|
||||||
printf("Press Ctrl+C to stop\n\n");
|
printf("Press Ctrl+C to stop\n\n");
|
||||||
|
|
||||||
time_measurement();
|
double start_time = get_wall_time();
|
||||||
time_measurement();
|
|
||||||
double start_time = wall_time_delta();
|
|
||||||
|
|
||||||
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
||||||
{
|
{
|
||||||
|
|
@ -187,16 +193,14 @@ static void mine_coins_avx(u64_t max_attempts)
|
||||||
// Print progress every 1M attempts
|
// Print progress every 1M attempts
|
||||||
if(attempts % 1000000 < SIMD_WIDTH)
|
if(attempts % 1000000 < SIMD_WIDTH)
|
||||||
{
|
{
|
||||||
time_measurement();
|
double elapsed = get_wall_time() - start_time;
|
||||||
double current_time = wall_time_delta() - start_time;
|
double rate = attempts / elapsed;
|
||||||
double rate = attempts / current_time;
|
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u, Elapsed: %.2fs\n",
|
||||||
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u\n",
|
(unsigned long long)attempts, rate / 1e6, coins_found, elapsed);
|
||||||
(unsigned long long)attempts, rate / 1e6, coins_found);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_measurement();
|
double total_time = get_wall_time() - start_time;
|
||||||
double total_time = wall_time_delta() - start_time;
|
|
||||||
|
|
||||||
printf("\n=== Mining Statistics ===\n");
|
printf("\n=== Mining Statistics ===\n");
|
||||||
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
||||||
|
|
@ -246,9 +250,7 @@ static void mine_coins_avx2(u64_t max_attempts)
|
||||||
printf("Mining DETI coins using AVX2 (8-way SIMD)...\n");
|
printf("Mining DETI coins using AVX2 (8-way SIMD)...\n");
|
||||||
printf("Press Ctrl+C to stop\n\n");
|
printf("Press Ctrl+C to stop\n\n");
|
||||||
|
|
||||||
time_measurement();
|
double start_time = get_wall_time();
|
||||||
time_measurement();
|
|
||||||
double start_time = wall_time_delta();
|
|
||||||
|
|
||||||
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
while(keep_running && (max_attempts == 0 || attempts < max_attempts))
|
||||||
{
|
{
|
||||||
|
|
@ -274,16 +276,14 @@ static void mine_coins_avx2(u64_t max_attempts)
|
||||||
|
|
||||||
if(attempts % 1000000 < SIMD_WIDTH)
|
if(attempts % 1000000 < SIMD_WIDTH)
|
||||||
{
|
{
|
||||||
time_measurement();
|
double elapsed = get_wall_time() - start_time;
|
||||||
double current_time = wall_time_delta() - start_time;
|
double rate = attempts / elapsed;
|
||||||
double rate = attempts / current_time;
|
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u, Elapsed: %.2fs\n",
|
||||||
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u\n",
|
(unsigned long long)attempts, rate / 1e6, coins_found, elapsed);
|
||||||
(unsigned long long)attempts, rate / 1e6, coins_found);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time_measurement();
|
double total_time = get_wall_time() - start_time;
|
||||||
double total_time = wall_time_delta() - start_time;
|
|
||||||
|
|
||||||
printf("\n=== Mining Statistics ===\n");
|
printf("\n=== Mining Statistics ===\n");
|
||||||
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
||||||
|
|
@ -294,6 +294,7 @@ static void mine_coins_avx2(u64_t max_attempts)
|
||||||
save_coin(NULL);
|
save_coin(NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__AVX2__)
|
#if defined(__AVX2__)
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
//
|
//
|
||||||
|
|
@ -310,16 +311,13 @@ static void mine_coins_avx2_omp(u64_t max_attempts)
|
||||||
printf("Mining DETI coins using AVX2 (8-way SIMD) + OpenMP (%d threads)...\n", num_threads);
|
printf("Mining DETI coins using AVX2 (8-way SIMD) + OpenMP (%d threads)...\n", num_threads);
|
||||||
printf("Press Ctrl+C to stop\n\n");
|
printf("Press Ctrl+C to stop\n\n");
|
||||||
|
|
||||||
time_measurement();
|
double start_time = get_wall_time();
|
||||||
time_measurement();
|
|
||||||
double start_time = wall_time_delta();
|
|
||||||
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
u32_t base_coin[14];
|
u32_t base_coin[14];
|
||||||
u32_t interleaved_data[14 * SIMD_WIDTH] __attribute__((aligned(32)));
|
u32_t interleaved_data[14 * SIMD_WIDTH] __attribute__((aligned(32)));
|
||||||
u32_t interleaved_hash[5 * SIMD_WIDTH] __attribute__((aligned(32)));
|
u32_t interleaved_hash[5 * SIMD_WIDTH] __attribute__((aligned(32)));
|
||||||
// u32_t thread_coins_found = 0;
|
|
||||||
u64_t thread_attempts = 0;
|
u64_t thread_attempts = 0;
|
||||||
|
|
||||||
// Initialize base coin template (unique per thread)
|
// Initialize base coin template (unique per thread)
|
||||||
|
|
@ -375,11 +373,10 @@ static void mine_coins_avx2_omp(u64_t max_attempts)
|
||||||
{
|
{
|
||||||
#pragma omp critical
|
#pragma omp critical
|
||||||
{
|
{
|
||||||
time_measurement();
|
double elapsed = get_wall_time() - start_time;
|
||||||
double current_time = wall_time_delta() - start_time;
|
double rate = (attempts + thread_attempts) / elapsed;
|
||||||
double rate = (attempts + thread_attempts) / current_time;
|
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u, Elapsed: %.2fs\n",
|
||||||
printf("Attempts: %llu, Rate: %.2f MH/s, Coins: %u\n",
|
(unsigned long long)(attempts + thread_attempts), rate / 1e6, coins_found, elapsed);
|
||||||
(unsigned long long)(attempts + thread_attempts), rate / 1e6, coins_found);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -388,8 +385,7 @@ static void mine_coins_avx2_omp(u64_t max_attempts)
|
||||||
attempts += thread_attempts;
|
attempts += thread_attempts;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_measurement();
|
double total_time = get_wall_time() - start_time;
|
||||||
double total_time = wall_time_delta() - start_time;
|
|
||||||
|
|
||||||
printf("\n=== Mining Statistics ===\n");
|
printf("\n=== Mining Statistics ===\n");
|
||||||
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
printf("Total attempts: %llu\n", (unsigned long long)attempts);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue