Skip to content

Commit

Permalink
created channel for polimorph buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyFFM committed Aug 18, 2018
1 parent 92f3ebd commit 0551b38
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 52 deletions.
120 changes: 99 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ hex = "0.3.1"
tokio = "0.1"
tokio-core = "0.1"
url = "1.7.1"
chan = "0.1.21"
crossbeam-channel = "0.2.4"
futures = "0.1.22"
rayon = "1.0"
num_cpus = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[macro_use]
extern crate serde_derive;
extern crate chan;
extern crate crossbeam_channel as chan;
extern crate futures;
extern crate hex;
extern crate hyper;
Expand Down
28 changes: 13 additions & 15 deletions src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,22 @@ pub struct State {

pub trait Buffer {
// Static method signature; `Self` refers to the implementor type.
fn new(buffer_size: usize, context: Option<GpuContext>) -> Self where Self: Sized;
fn new(buffer_size: usize, context: Option<GpuContext>) -> Self
where
Self: Sized;
// Instance method signatures; these will return a string.
fn get_buffer(&self) -> Arc<Mutex<Vec<u8>>>;
}

pub struct CpuBuffer {
data: Arc<Mutex<Vec<u8>>>
data: Arc<Mutex<Vec<u8>>>,
}

impl Buffer for CpuBuffer {
fn new(buffer_size: usize, _context: Option<GpuContext>) -> Self where Self: Sized {
fn new(buffer_size: usize, _context: Option<GpuContext>) -> Self
where
Self: Sized,
{
let pointer = aligned_alloc::aligned_alloc(buffer_size, page_size::get());
let data: Vec<u8>;
unsafe {
Expand Down Expand Up @@ -152,28 +157,21 @@ impl Miner {
let buffer_count = (cpu_worker_thread_count + gpu_worker_thread_count) * 2;
let buffer_size = cfg.nonces_per_cache * SCOOP_SIZE as usize;

let (tx_empty_buffers, rx_empty_buffers) = chan::sync(buffer_count as usize);
let (tx_read_replies, rx_read_replies) = chan::sync(buffer_count as usize);
let (tx_empty_buffers, rx_empty_buffers) = chan::bounded(buffer_count as usize);
let (tx_read_replies, rx_read_replies) = chan::bounded(buffer_count as usize);

let gpu_context = Arc::new(GpuContext::new(
cfg.gpu_platform,
cfg.gpu_device,
cfg.nonces_per_cache,
));

//First approach Vec<u8> to Buffer
//WORK IN PROGRESS
for _ in 0..buffer_count {
let cpu_buffer = CpuBuffer::new(buffer_size, None);
//let pointer = aligned_alloc::aligned_alloc(buffer_size, page_size::get());
// let data: Vec<u8>;
//unsafe {
//data = Vec::from_raw_parts(pointer as *mut u8, buffer_size, buffer_size);
//}
tx_empty_buffers.send(cpu_buffer);
tx_empty_buffers.send(Box::new(cpu_buffer) as Box<Buffer + Send>);
}



let core_ids = core_affinity::get_core_ids().unwrap();
let (tx_nonce_data, rx_nonce_data) =
mpsc::channel(cpu_worker_thread_count + gpu_worker_thread_count);
Expand Down
12 changes: 7 additions & 5 deletions src/ocl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use miner::Buffer;
use std::ffi::CString;
use std::mem;
use std::process;
use std::sync::{Arc, Mutex};
use std::u64;
use std::sync::{Mutex, Arc};

static SRC: &'static str = include_str!("ocl/kernel.cl");

Expand Down Expand Up @@ -136,7 +136,10 @@ pub struct GpuBuffer {
}

impl Buffer for GpuBuffer {
fn new(buffer_size: usize, context: Option<GpuContext>) -> Self where Self: Sized{
fn new(buffer_size: usize, context: Option<GpuContext>) -> Self
where
Self: Sized,
{
let context = context.unwrap();
let gensig_gpu = unsafe {
core::create_buffer::<_, u8>(&context.context, core::MEM_READ_ONLY, 32, None).unwrap()
Expand Down Expand Up @@ -190,10 +193,9 @@ impl Buffer for GpuBuffer {
best_offset_gpu: best_offset_gpu,
}
}
fn get_buffer(&self) ->Arc<Mutex<Vec<u8>>>{
let test = Arc::new(Mutex::new(vec!(0u8;1)));
fn get_buffer(&self) -> Arc<Mutex<Vec<u8>>> {
let test = Arc::new(Mutex::new(vec![0u8; 1]));
test

}
}

Expand Down
Loading

0 comments on commit 0551b38

Please sign in to comment.