You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.3 KiB
89 lines
2.3 KiB
11 years ago
|
#include <stdio.h>
|
||
|
#include <memory.h>
|
||
|
|
||
10 years ago
|
#include "cuda_helper.h"
|
||
|
|
||
10 years ago
|
// Hash Target gegen das wir testen sollen
|
||
11 years ago
|
__constant__ uint32_t pTarget[8];
|
||
|
|
||
10 years ago
|
static uint32_t *d_resNounce[8];
|
||
|
static uint32_t *h_resNounce[8];
|
||
11 years ago
|
|
||
10 years ago
|
__global__
|
||
|
void cuda_check_gpu_hash_64(int threads, uint32_t startNounce, uint32_t *g_nonceVector, uint32_t *g_hash, uint32_t *resNounce)
|
||
11 years ago
|
{
|
||
|
int thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||
|
if (thread < threads)
|
||
|
{
|
||
10 years ago
|
// bestimme den aktuellen Zähler
|
||
11 years ago
|
uint32_t nounce = (g_nonceVector != NULL) ? g_nonceVector[thread] : (startNounce + thread);
|
||
|
|
||
|
int hashPosition = nounce - startNounce;
|
||
10 years ago
|
uint32_t *inpHash = &g_hash[hashPosition<<4];
|
||
11 years ago
|
|
||
|
uint32_t hash[8];
|
||
10 years ago
|
|
||
|
#pragma unroll 8
|
||
11 years ago
|
for (int i=0; i < 8; i++)
|
||
|
hash[i] = inpHash[i];
|
||
|
|
||
10 years ago
|
for (int i = 7; i >= 0; i--) {
|
||
11 years ago
|
if (hash[i] > pTarget[i]) {
|
||
10 years ago
|
return;
|
||
|
}
|
||
|
if (hash[i] < pTarget[i]) {
|
||
|
break;
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
if(resNounce[0] > nounce)
|
||
|
resNounce[0] = nounce;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// Setup-Funktionen
|
||
10 years ago
|
__host__
|
||
|
void cuda_check_cpu_init(int thr_id, int threads)
|
||
11 years ago
|
{
|
||
|
cudaMallocHost(&h_resNounce[thr_id], 1*sizeof(uint32_t));
|
||
|
cudaMalloc(&d_resNounce[thr_id], 1*sizeof(uint32_t));
|
||
|
}
|
||
|
|
||
|
// Target Difficulty setzen
|
||
10 years ago
|
__host__
|
||
|
void cuda_check_cpu_setTarget(const void *ptarget)
|
||
11 years ago
|
{
|
||
|
// die Message zur Berechnung auf der GPU
|
||
10 years ago
|
cudaMemcpyToSymbol(pTarget, ptarget, 8*sizeof(uint32_t), 0, cudaMemcpyHostToDevice);
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
__host__
|
||
|
uint32_t cuda_check_cpu_hash_64(int thr_id, int threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_inputHash, int order)
|
||
11 years ago
|
{
|
||
|
uint32_t result = 0xffffffff;
|
||
|
cudaMemset(d_resNounce[thr_id], 0xff, sizeof(uint32_t));
|
||
|
|
||
|
const int threadsperblock = 256;
|
||
|
|
||
|
// berechne wie viele Thread Blocks wir brauchen
|
||
|
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||
|
dim3 block(threadsperblock);
|
||
|
|
||
10 years ago
|
// Größe des dynamischen Shared Memory Bereichs
|
||
11 years ago
|
size_t shared_size = 0;
|
||
|
|
||
10 years ago
|
cuda_check_gpu_hash_64 <<<grid, block, shared_size>>>(threads, startNounce, d_nonceVector, d_inputHash, d_resNounce[thr_id]);
|
||
11 years ago
|
|
||
|
// Strategisches Sleep Kommando zur Senkung der CPU Last
|
||
|
MyStreamSynchronize(NULL, order, thr_id);
|
||
|
|
||
|
// Ergebnis zum Host kopieren (in page locked memory, damits schneller geht)
|
||
|
cudaMemcpy(h_resNounce[thr_id], d_resNounce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||
|
|
||
|
// cudaMemcpy() ist asynchron!
|
||
|
cudaThreadSynchronize();
|
||
|
result = *h_resNounce[thr_id];
|
||
|
|
||
|
return result;
|
||
|
}
|