From cb3b8f6618f8c9e33d93c6e3e150c2f8d4866b73 Mon Sep 17 00:00:00 2001 From: Russel Arbore <russel.jma@gmail.com> Date: Sun, 12 Jan 2025 20:05:41 -0800 Subject: [PATCH] get rest of tests working --- Cargo.lock | 5 +++ juno_samples/antideps/Cargo.toml | 1 + juno_samples/implicit_clone/Cargo.toml | 1 + juno_samples/matmul/Cargo.toml | 1 + juno_samples/matmul/src/main.rs | 61 +++++++------------------- juno_samples/nested_ccp/Cargo.toml | 1 + juno_samples/nested_ccp/src/main.rs | 27 ++++-------- juno_samples/simple3/Cargo.toml | 1 + juno_samples/simple3/src/main.rs | 25 +++-------- 9 files changed, 42 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 53e26bbb..7e99e454 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 40b4d47c..9bd1d5a0 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 928fa1f2..b312f5de 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 ea705ddd..8ad95853 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 1c5b9d42..11066e8b 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 7ffc13f2..8c9b969d 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 83132aca..11561eb8 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 201c8d37..8060c5b3 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 89be5527..8ca54344 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); }); -- GitLab