diff --git a/Cargo.lock b/Cargo.lock index 53e26bbb3a7fe7062df1012ecf93fb8706c6baad..7e99e45471829330a11d4abc178b775f27b00426 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,6 +707,7 @@ name = "juno_antideps" version = "0.1.0" dependencies = [ "async-std", + "hercules_rt", "juno_build", "with_builtin_macros", ] @@ -751,6 +752,7 @@ name = "juno_implicit_clone" version = "0.1.0" dependencies = [ "async-std", + "hercules_rt", "juno_build", "with_builtin_macros", ] @@ -760,6 +762,7 @@ name = "juno_matmul" version = "0.1.0" dependencies = [ "async-std", + "hercules_rt", "juno_build", "rand", "with_builtin_macros", @@ -770,6 +773,7 @@ name = "juno_nested_ccp" version = "0.1.0" dependencies = [ "async-std", + "hercules_rt", "juno_build", "with_builtin_macros", ] @@ -789,6 +793,7 @@ name = "juno_simple3" version = "0.1.0" dependencies = [ "async-std", + "hercules_rt", "juno_build", "with_builtin_macros", ] diff --git a/juno_samples/antideps/Cargo.toml b/juno_samples/antideps/Cargo.toml index 40b4d47c57bbe422bfe983ee73a1d140a2ab1b94..9bd1d5a0d484e257ee3ad1e425a09f503da4b503 100644 --- a/juno_samples/antideps/Cargo.toml +++ b/juno_samples/antideps/Cargo.toml @@ -13,5 +13,6 @@ juno_build = { path = "../../juno_build" } [dependencies] juno_build = { path = "../../juno_build" } +hercules_rt = { path = "../../hercules_rt" } with_builtin_macros = "0.1.0" async-std = "*" diff --git a/juno_samples/implicit_clone/Cargo.toml b/juno_samples/implicit_clone/Cargo.toml index 928fa1f2718b9637da2ac3fe740a0d893345d576..b312f5def295a6c31a7d2c9eab5c23f4e16ccd2f 100644 --- a/juno_samples/implicit_clone/Cargo.toml +++ b/juno_samples/implicit_clone/Cargo.toml @@ -13,5 +13,6 @@ juno_build = { path = "../../juno_build" } [dependencies] juno_build = { path = "../../juno_build" } +hercules_rt = { path = "../../hercules_rt" } with_builtin_macros = "0.1.0" async-std = "*" diff --git a/juno_samples/matmul/Cargo.toml b/juno_samples/matmul/Cargo.toml index ea705dddd2fac0e4b5a4b8fe0ddfeef72039e3c4..8ad95853d25509d91713a080c0b63b01c0469110 100644 --- a/juno_samples/matmul/Cargo.toml +++ b/juno_samples/matmul/Cargo.toml @@ -13,6 +13,7 @@ juno_build = { path = "../../juno_build" } [dependencies] juno_build = { path = "../../juno_build" } +hercules_rt = { path = "../../hercules_rt" } with_builtin_macros = "0.1.0" async-std = "*" rand = "*" diff --git a/juno_samples/matmul/src/main.rs b/juno_samples/matmul/src/main.rs index 1c5b9d42b020b3acd7dbaba0db11ec734e83e574..11066e8bf4762247a50881ccdd3dfeea8fae9fea 100644 --- a/juno_samples/matmul/src/main.rs +++ b/juno_samples/matmul/src/main.rs @@ -1,13 +1,14 @@ -#![feature(future_join, box_as_ptr, let_chains)] +#![feature(box_as_ptr, let_chains)] extern crate async_std; +extern crate hercules_rt; extern crate juno_build; extern crate rand; -use core::ptr::copy_nonoverlapping; - use rand::random; +use hercules_rt::HerculesBox; + juno_build::juno!("matmul"); fn main() { @@ -17,45 +18,6 @@ fn main() { const K: usize = 128; let a: Box<[i32]> = (0..I * J).map(|_| random::<i32>() % 100).collect(); let b: Box<[i32]> = (0..J * K).map(|_| random::<i32>() % 100).collect(); - let mut a_bytes: Box<[u8]> = Box::new([0; I * J * 4]); - let mut b_bytes: Box<[u8]> = Box::new([0; J * K * 4]); - unsafe { - copy_nonoverlapping( - Box::as_ptr(&a) as *const u8, - Box::as_mut_ptr(&mut a_bytes) as *mut u8, - I * J * 4, - ); - copy_nonoverlapping( - Box::as_ptr(&b) as *const u8, - Box::as_mut_ptr(&mut b_bytes) as *mut u8, - J * K * 4, - ); - }; - let c_bytes = matmul( - I as u64, - J as u64, - K as u64, - a_bytes.clone(), - b_bytes.clone(), - ) - .await; - let mut c: Box<[i32]> = (0..I * K).map(|_| 0).collect(); - unsafe { - copy_nonoverlapping( - Box::as_ptr(&c_bytes) as *const u8, - Box::as_mut_ptr(&mut c) as *mut u8, - I * K * 4, - ); - }; - let tiled_c_bytes = tiled_64_matmul(I as u64, J as u64, K as u64, a_bytes, b_bytes).await; - let mut tiled_c: Box<[i32]> = (0..I * K).map(|_| 0).collect(); - unsafe { - copy_nonoverlapping( - Box::as_ptr(&tiled_c_bytes) as *const u8, - Box::as_mut_ptr(&mut tiled_c) as *mut u8, - I * K * 4, - ); - }; let mut correct_c: Box<[i32]> = (0..I * K).map(|_| 0).collect(); for i in 0..I { for k in 0..K { @@ -64,8 +26,18 @@ fn main() { } } } - assert_eq!(c, correct_c); - assert_eq!(tiled_c, correct_c); + let c = { + let a = HerculesBox::from_slice(&a); + let b = HerculesBox::from_slice(&b); + matmul(I as u64, J as u64, K as u64, a, b).await + }; + let tiled_c = { + let a = HerculesBox::from_slice(&a); + let b = HerculesBox::from_slice(&b); + tiled_64_matmul(I as u64, J as u64, K as u64, a, b).await + }; + assert_eq!(c.as_slice::<i32>(), &*correct_c); + assert_eq!(tiled_c.as_slice::<i32>(), &*correct_c); }); } @@ -73,3 +45,4 @@ fn main() { fn matmul_test() { main(); } + diff --git a/juno_samples/nested_ccp/Cargo.toml b/juno_samples/nested_ccp/Cargo.toml index 7ffc13f21b155dbe6028d808be97aaf0e5ffb8d6..8c9b969d23019b8bbd3bf28b3506e2e497ae8ec7 100644 --- a/juno_samples/nested_ccp/Cargo.toml +++ b/juno_samples/nested_ccp/Cargo.toml @@ -13,5 +13,6 @@ juno_build = { path = "../../juno_build" } [dependencies] juno_build = { path = "../../juno_build" } +hercules_rt = { path = "../../hercules_rt" } with_builtin_macros = "0.1.0" async-std = "*" diff --git a/juno_samples/nested_ccp/src/main.rs b/juno_samples/nested_ccp/src/main.rs index 83132aca516bd59a6e5b5c0e5ca4562a2e1cc3cc..11561eb8fcdbe9be4b163506f98d9952ecbc749d 100644 --- a/juno_samples/nested_ccp/src/main.rs +++ b/juno_samples/nested_ccp/src/main.rs @@ -1,32 +1,21 @@ #![feature(box_as_ptr, let_chains)] extern crate async_std; +extern crate hercules_rt; extern crate juno_build; -use core::ptr::copy_nonoverlapping; +use hercules_rt::HerculesBox; juno_build::juno!("nested_ccp"); fn main() { async_std::task::block_on(async { - let a: Box<[f32]> = Box::new([17.0, 18.0, 19.0]); - let b: Box<[i32]> = Box::new([12, 16, 4, 18, 23, 56, 93, 22, 14]); - let mut a_bytes: Box<[u8]> = Box::new([0; 12]); - let mut b_bytes: Box<[u8]> = Box::new([0; 36]); - unsafe { - copy_nonoverlapping( - Box::as_ptr(&a) as *const u8, - Box::as_mut_ptr(&mut a_bytes) as *mut u8, - 12, - ); - copy_nonoverlapping( - Box::as_ptr(&b) as *const u8, - Box::as_mut_ptr(&mut b_bytes) as *mut u8, - 36, - ); - }; - let output_example = ccp_example(a_bytes).await; - let output_median = median_array(9, b_bytes).await; + let mut a: Box<[f32]> = Box::new([17.0, 18.0, 19.0]); + let mut b: Box<[i32]> = Box::new([12, 16, 4, 18, 23, 56, 93, 22, 14]); + let a = HerculesBox::from_slice_mut(&mut a); + let b = HerculesBox::from_slice_mut(&mut b); + let output_example = ccp_example(a).await; + let output_median = median_array(9, b).await; println!("{}", output_example); println!("{}", output_median); assert_eq!(output_example, 1.0); diff --git a/juno_samples/simple3/Cargo.toml b/juno_samples/simple3/Cargo.toml index 201c8d3782d4b41d7bfef5b7df4b5b29758e6e00..8060c5b3472ad898cb48e011332a852cd7b6705e 100644 --- a/juno_samples/simple3/Cargo.toml +++ b/juno_samples/simple3/Cargo.toml @@ -13,5 +13,6 @@ juno_build = { path = "../../juno_build" } [dependencies] juno_build = { path = "../../juno_build" } +hercules_rt = { path = "../../hercules_rt" } with_builtin_macros = "0.1.0" async-std = "*" diff --git a/juno_samples/simple3/src/main.rs b/juno_samples/simple3/src/main.rs index 89be5527a2e4d1e5842778818aa934db98fcdf09..8ca54344fd6b8f574c3e2b43e50c58185812188a 100644 --- a/juno_samples/simple3/src/main.rs +++ b/juno_samples/simple3/src/main.rs @@ -1,31 +1,20 @@ #![feature(box_as_ptr, let_chains)] extern crate async_std; +extern crate hercules_rt; extern crate juno_build; -use core::ptr::copy_nonoverlapping; +use hercules_rt::HerculesBox; juno_build::juno!("simple3"); fn main() { async_std::task::block_on(async { - let a: Box<[u32]> = Box::new([1, 2, 3, 4, 5, 6, 7, 8]); - let b: Box<[u32]> = Box::new([8, 7, 6, 5, 4, 3, 2, 1]); - let mut a_bytes: Box<[u8]> = Box::new([0; 32]); - let mut b_bytes: Box<[u8]> = Box::new([0; 32]); - unsafe { - copy_nonoverlapping( - Box::as_ptr(&a) as *const u8, - Box::as_mut_ptr(&mut a_bytes) as *mut u8, - 32, - ); - copy_nonoverlapping( - Box::as_ptr(&b) as *const u8, - Box::as_mut_ptr(&mut b_bytes) as *mut u8, - 32, - ); - }; - let c = simple3(8, a_bytes, b_bytes).await; + let mut a: Box<[u32]> = Box::new([1, 2, 3, 4, 5, 6, 7, 8]); + let mut b: Box<[u32]> = Box::new([8, 7, 6, 5, 4, 3, 2, 1]); + let a = HerculesBox::from_slice_mut(&mut a); + let b = HerculesBox::from_slice_mut(&mut b); + let c = simple3(8, a, b).await; println!("{}", c); assert_eq!(c, 120); });