-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,745 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "engraver" | ||
version = "2.0.5" | ||
version = "2.2.0" | ||
license = "GPL-3.0" | ||
authors = ["PoC Consortium <[email protected]>"] | ||
description = """ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
use libc::{c_void, size_t, uint64_t}; | ||
use std::sync::mpsc::Sender; | ||
|
||
extern "C" { | ||
pub fn noncegen( | ||
cache: *mut c_void, | ||
cache_size: size_t, | ||
chunk_offset: size_t, | ||
numeric_ID: uint64_t, | ||
local_startnonce: uint64_t, | ||
local_nonces: uint64_t, | ||
); | ||
pub fn noncegen_sse( | ||
cache: *mut c_void, | ||
cache_size: size_t, | ||
chunk_offset: size_t, | ||
numeric_ID: uint64_t, | ||
local_startnonce: uint64_t, | ||
local_nonces: uint64_t, | ||
); | ||
pub fn noncegen_avx( | ||
cache: *mut c_void, | ||
cache_size: size_t, | ||
chunk_offset: size_t, | ||
numeric_ID: uint64_t, | ||
local_startnonce: uint64_t, | ||
local_nonces: uint64_t, | ||
); | ||
pub fn noncegen_avx2( | ||
cache: *mut c_void, | ||
cache_size: size_t, | ||
chunk_offset: size_t, | ||
numeric_ID: uint64_t, | ||
local_startnonce: uint64_t, | ||
local_nonces: uint64_t, | ||
); | ||
pub fn noncegen_avx512( | ||
cache: *mut c_void, | ||
cache_size: size_t, | ||
chunk_offset: size_t, | ||
numeric_ID: uint64_t, | ||
local_startnonce: uint64_t, | ||
local_nonces: uint64_t, | ||
); | ||
} | ||
pub struct SafeCVoid { | ||
pub ptr: *mut c_void, | ||
} | ||
unsafe impl Send for SafeCVoid {} | ||
|
||
pub struct CpuTask { | ||
pub cache: SafeCVoid, | ||
pub cache_size: size_t, | ||
pub chunk_offset: size_t, | ||
pub numeric_id: uint64_t, | ||
pub local_startnonce: uint64_t, | ||
pub local_nonces: uint64_t, | ||
} | ||
|
||
pub fn hash_cpu( | ||
tx: Sender<(u8, u8, u64)>, | ||
hasher_task: CpuTask, | ||
simd_ext: String, | ||
) -> impl FnOnce() { | ||
move || { | ||
unsafe { | ||
match &*simd_ext { | ||
"AVX512F" => noncegen_avx512( | ||
hasher_task.cache.ptr, | ||
hasher_task.cache_size, | ||
hasher_task.chunk_offset, | ||
hasher_task.numeric_id, | ||
hasher_task.local_startnonce, | ||
hasher_task.local_nonces, | ||
), | ||
"AVX2" => noncegen_avx2( | ||
hasher_task.cache.ptr, | ||
hasher_task.cache_size, | ||
hasher_task.chunk_offset, | ||
hasher_task.numeric_id, | ||
hasher_task.local_startnonce, | ||
hasher_task.local_nonces, | ||
), | ||
"AVX" => noncegen_avx( | ||
hasher_task.cache.ptr, | ||
hasher_task.cache_size, | ||
hasher_task.chunk_offset, | ||
hasher_task.numeric_id, | ||
hasher_task.local_startnonce, | ||
hasher_task.local_nonces, | ||
), | ||
"SSE2" => noncegen_sse( | ||
hasher_task.cache.ptr, | ||
hasher_task.cache_size, | ||
hasher_task.chunk_offset, | ||
hasher_task.numeric_id, | ||
hasher_task.local_startnonce, | ||
hasher_task.local_nonces, | ||
), | ||
_ => noncegen( | ||
hasher_task.cache.ptr, | ||
hasher_task.cache_size, | ||
hasher_task.chunk_offset, | ||
hasher_task.numeric_id, | ||
hasher_task.local_startnonce, | ||
hasher_task.local_nonces, | ||
), | ||
} | ||
} | ||
// report hashing done | ||
tx.send((0u8, 1u8, 0)) | ||
.expect("CPU task can't communicate with scheduler thread."); | ||
// report data in hostmem | ||
tx.send((0u8, 0u8, hasher_task.local_nonces)) | ||
.expect("CPU task can't communicate with scheduler thread."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use chan::Receiver; | ||
use ocl::{gpu_hash, gpu_hash_and_transfer_to_host, gpu_transfer_to_host, GpuContext}; | ||
use std::sync::mpsc::Sender; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
pub struct SafePointer { | ||
pub ptr: *mut u8, | ||
} | ||
unsafe impl Send for SafePointer {} | ||
unsafe impl Sync for SafePointer {} | ||
|
||
pub struct GpuTask { | ||
pub cache: SafePointer, | ||
pub cache_size: u64, | ||
pub chunk_offset: u64, | ||
pub numeric_id: u64, | ||
pub local_startnonce: u64, | ||
pub local_nonces: u64, | ||
} | ||
|
||
pub fn create_gpu_hasher_thread( | ||
gpu_id: u8, | ||
gpu_context: Arc<Mutex<GpuContext>>, | ||
tx: Sender<(u8, u8, u64)>, | ||
rx_hasher_task: Receiver<Option<GpuTask>>, | ||
) -> impl FnOnce() { | ||
move || { | ||
let mut first_run = true; | ||
let mut buffer_id = 0u8; | ||
let mut last_task = GpuTask { | ||
cache: SafePointer { ptr: &mut 0u8 }, | ||
cache_size: 0, | ||
chunk_offset: 0, | ||
numeric_id: 0, | ||
local_startnonce: 0, | ||
local_nonces: 0, | ||
}; | ||
for task in rx_hasher_task { | ||
// check if new task or termination | ||
match task { | ||
// new task | ||
Some(task) => { | ||
// first run - just hash | ||
if first_run { | ||
if task.local_nonces != 0 { | ||
first_run = false; | ||
gpu_hash(&gpu_context, &task); | ||
buffer_id = 1 - buffer_id; | ||
last_task = task; | ||
tx.send((gpu_id, 1u8, 0)) | ||
.expect("GPU task can't communicate with scheduler thread."); | ||
} | ||
// last run - just transfer | ||
} else if task.local_nonces == 0 { | ||
gpu_transfer_to_host(&gpu_context, buffer_id, &last_task); | ||
first_run = true; | ||
buffer_id = 0; | ||
tx.send((gpu_id, 0u8, last_task.local_nonces)) | ||
.expect("GPU task can't communicate with scheduler thread."); | ||
// normal run - hash and transfer async | ||
} else { | ||
gpu_hash_and_transfer_to_host(&gpu_context, buffer_id, &task, &last_task); | ||
buffer_id = 1 - buffer_id; | ||
tx.send((gpu_id, 0u8, last_task.local_nonces)) | ||
.expect("GPU task can't communicate with scheduler thread."); | ||
last_task = task; | ||
tx.send((gpu_id, 1u8, 0)) | ||
.expect("GPU task can't communicate with scheduler thread."); | ||
} | ||
} | ||
// termination | ||
None => { | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.