implement vmv in pim-simulator
Validate Operations / validate-operations (push) Has been cancelled

fix offset selection implementation to match the pim isa
automatic code format for pim-simulator
This commit is contained in:
NiccoloN
2026-07-31 17:24:19 +02:00
parent a0131c6f7a
commit 9ca1a0ed9f
23 changed files with 584 additions and 497 deletions
@@ -7,7 +7,7 @@ use pimcore::{
memory_manager::CoreMemory,
};
fn simple_read(path: &Path) -> Vec<f32> {
fn simple_read(path: &Path) -> Vec<f32> {
if !path.exists() {
panic!("{:?} not exists", path)
}
@@ -19,9 +19,7 @@ fn simple_read(path: &Path) -> Vec<f32> {
}
/// mvmul Test
fn mvmul_f32(err: &str)
where
{
fn mvmul_f32(err: &str) {
let matrix = simple_read(Path::new("tests/B.txt"));
let mut crossbar = Crossbar::new(1024 * size_of::<f32>(), 1024, CoreMemory::new());
crossbar.execute_store(&matrix).unwrap();
@@ -36,7 +34,9 @@ where
inst_builder.make_inst(sldi, idata_build.set_rdimm(1, 0).build());
inst_builder.make_inst(
sldi,
idata_build.set_rdimm(3, 1024 * size_of::<f32>() as i32).build(),
idata_build
.set_rdimm(3, 1024 * size_of::<f32>() as i32)
.build(),
);
inst_builder.make_inst(
setbw,
@@ -48,7 +48,7 @@ where
mvmul,
idata_build
.set_rdr1(3, 1)
.set_mbiw_immrelu_immgroup(8*size_of::<f32>() as i32, 0, 0)
.set_mbiw_immrelu_immgroup(8 * size_of::<f32>() as i32, 0, 0)
.build(),
);
let core_instruction = vec![inst_builder.build().into()];
@@ -59,8 +59,11 @@ where
executable
.cpu_mut()
.host()
.load::<f32>(1024 * size_of::<f32>(), 1024*size_of::<f32>()).unwrap()[0].iter().zip(
simple_read(Path::new("tests/X.txt")) ).all(|(&a,b) : (&f32, f32)| {a-b < 0.001}),
.load::<f32>(1024 * size_of::<f32>(), 1024 * size_of::<f32>())
.unwrap()[0]
.iter()
.zip(simple_read(Path::new("tests/X.txt")))
.all(|(&a, b): (&f32, f32)| { a - b < 0.001 }),
"Wrong result for {}",
err
);
@@ -69,6 +72,4 @@ where
#[test]
fn mvmul_big_test() {
mvmul_f32("mvmul_f32");
}
@@ -6,9 +6,7 @@ use std::{
use anyhow::{Context, Result};
use pimcore::{
cpu::crossbar::Crossbar,
json_to_instruction::json_to_executor,
memory_manager::CoreMemory,
cpu::crossbar::Crossbar, json_to_instruction::json_to_executor, memory_manager::CoreMemory,
};
use serde_json::Value;
@@ -95,9 +93,14 @@ fn json_folder_tester() {
.map(|core_crossbars| core_crossbars.iter().collect())
.collect();
let mut executable = json_to_executor::json_to_executor(config, &mut core_readers, crossbars);
let mut executable =
json_to_executor::json_to_executor(config, &mut core_readers, crossbars);
let memory = fs::read(folder.join("memory.bin")).unwrap();
executable.cpu_mut().host().execute_store(0, &memory).unwrap();
executable
.cpu_mut()
.host()
.execute_store(0, &memory)
.unwrap();
executable.execute();
}
}
@@ -7,26 +7,17 @@ use pimcore::{
},
};
#[test]
#[should_panic(expected = "Function not found for the requested size") ]
#[should_panic(expected = "Function not found for the requested size")]
fn wrong_size_place_holder() {
let cpu = common::empty_cpu(0);
let mut inst_builder = InstructionsBuilder::new();
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(0).fix_core_indx();
inst_builder.make_inst(
setbw,
idata_build
.set_ibiw_obiw(55, 55)
.build(),
);
inst_builder.make_inst(setbw, idata_build.set_ibiw_obiw(55, 55).build());
inst_builder.make_inst(
vvadd,
idata_build
.set_rdr1r2(3, 1, 2)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 2).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
@@ -39,97 +30,88 @@ fn unsupported_8_bit_vectors_do_not_alias_f32() {
let mut inst_builder = InstructionsBuilder::new();
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(0).fix_core_indx();
inst_builder.make_inst(
setbw,
idata_build.set_ibiw_obiw(8, 8).build(),
);
inst_builder.make_inst(setbw, idata_build.set_ibiw_obiw(8, 8).build());
inst_builder.make_inst(
vvadd,
idata_build
.set_rdr1r2(3, 1, 2)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 2).set_imm_len(8).build(),
);
}
fn place_holder(inst : InstructionType) {
fn place_holder(inst: InstructionType) {
let mut cpu = common::empty_cpu(0);
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(0).fix_core_indx();
inst(&mut cpu, idata_build.build()).unwrap();
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vvadd_placeholder() {
place_holder(vvadd);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vvsub_placeholder() {
place_holder(vvsub);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vvmul_placeholder() {
place_holder(vvmul);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vvdmul_placeholder() {
place_holder(vvdmul);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vvmax_placeholder() {
place_holder(vvmax);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vavg_placeholder() {
place_holder(vavg);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vrelu_placeholder() {
place_holder(vrelu);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vtanh_placeholder() {
place_holder(vtanh);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn vsigm_placeholder() {
place_holder(vsigm);
}
#[test]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version") ]
#[should_panic(expected = "You are calling a placeholder, the real call is the generic version")]
fn mvmul_placeholder() {
place_holder(mvmul);
}
#[test]
#[should_panic ]
#[should_panic]
fn vvsll_why_inst() {
place_holder(vvsll);
}
#[test]
#[should_panic ]
#[should_panic]
fn vvsra_why_inst() {
place_holder(vvsra);
}
+206 -195
View File
@@ -53,10 +53,7 @@ where
);
inst_builder.make_inst(
vvadd,
idata_build
.set_rdr1r2(3, 1, 2)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 2).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
@@ -67,7 +64,8 @@ where
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>()).unwrap()[0],
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>())
.unwrap()[0],
vec![
10.0.into(),
12.0.into(),
@@ -86,17 +84,22 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -157,10 +160,7 @@ where
);
inst_builder.make_inst(
vvsub,
idata_build
.set_rdr1r2(3, 1, 2)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 2).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
@@ -171,7 +171,8 @@ where
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>()).unwrap()[0],
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>())
.unwrap()[0],
vec![
(-8.0).into(),
(-8.0).into(),
@@ -190,17 +191,22 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -261,10 +267,7 @@ where
);
inst_builder.make_inst(
vvmul,
idata_build
.set_rdr1r2(3, 1, 2)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 2).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
@@ -275,7 +278,8 @@ where
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>()).unwrap()[0],
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>())
.unwrap()[0],
vec![
(9.0).into(),
(20.0).into(),
@@ -294,17 +298,22 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -365,10 +374,7 @@ where
);
inst_builder.make_inst(
vvdmul,
idata_build
.set_rdr1r2(3, 1, 2)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 2).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
@@ -379,10 +385,9 @@ where
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), size_of::<T>()).unwrap()[0],
vec![
(492.0).into(),
],
.load::<T>(16 * size_of::<F>(), size_of::<T>())
.unwrap()[0],
vec![(492.0).into(),],
"Wrong result for {}",
err
);
@@ -391,17 +396,19 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(16 * size_of::<F>() + size_of::<T>(), 4 * size_of::<i32>())
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -462,10 +469,7 @@ where
);
inst_builder.make_inst(
vvmax,
idata_build
.set_rdr1r2(3, 1, 2)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 2).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
@@ -476,16 +480,17 @@ where
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>()).unwrap()[0],
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>())
.unwrap()[0],
vec![
9.0.into(),
10.0.into(),
11.0.into(),
12.0.into(),
13.0.into(),
14.0.into(),
15.0.into(),
16.0.into(),
9.0.into(),
10.0.into(),
11.0.into(),
12.0.into(),
13.0.into(),
14.0.into(),
15.0.into(),
16.0.into(),
],
"Wrong result for {}",
err
@@ -495,17 +500,22 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -577,10 +587,9 @@ where
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), size_of::<T>()).unwrap()[0],
vec![
7.5.into(),
],
.load::<T>(16 * size_of::<F>(), size_of::<T>())
.unwrap()[0],
vec![7.5.into(),],
"Wrong result for {}",
err
);
@@ -589,17 +598,19 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(16 * size_of::<F>() + size_of::<T>(), 4 * size_of::<i32>())
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -656,10 +667,7 @@ where
);
inst_builder.make_inst(
vrelu,
idata_build
.set_rdr1r2(3, 1, 1)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 1).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
@@ -670,16 +678,17 @@ where
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), 8*size_of::<T>()).unwrap()[0],
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>())
.unwrap()[0],
vec![
0.0.into(),
2.0.into(),
11.0.into(),
0.0.into(),
13.0.into(),
0.0.into(),
7.0.into(),
0.0.into(),
0.0.into(),
2.0.into(),
11.0.into(),
0.0.into(),
13.0.into(),
0.0.into(),
7.0.into(),
0.0.into(),
],
"Wrong result for {}",
err
@@ -689,17 +698,22 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + 8*size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -756,32 +770,32 @@ where
);
inst_builder.make_inst(
vtanh,
idata_build
.set_rdr1r2(3, 1, 1)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 1).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
executable.execute();
// Check result correct
assert!(
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), 8*size_of::<T>()).unwrap()[0].iter().zip(
vec![
T::from(0.1).tanh(),
T::from(0.2).tanh(),
T::from(0.3).tanh(),
T::from(0.4).tanh(),
T::from(0.5).tanh(),
T::from(0.6).tanh(),
T::from(0.7).tanh(),
T::from(0.8).tanh(),
]).all(|(&a,b) : (&T, T)| {a-b < 0.001.into()}),
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>())
.unwrap()[0]
.iter()
.zip(vec![
T::from(0.1).tanh(),
T::from(0.2).tanh(),
T::from(0.3).tanh(),
T::from(0.4).tanh(),
T::from(0.5).tanh(),
T::from(0.6).tanh(),
T::from(0.7).tanh(),
T::from(0.8).tanh(),
])
.all(|(&a, b): (&T, T)| { a - b < 0.001.into() }),
"Wrong result for {}",
err
);
@@ -790,17 +804,22 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + 8*size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -815,7 +834,6 @@ fn vtanh_test() {
vtanh_test_generic::<f64, f64>("vtanh<f64,f64>");
}
/// vsigm Test
fn vsigm_test_generic<F, T>(err: &str)
where
@@ -858,32 +876,32 @@ where
);
inst_builder.make_inst(
vsigm,
idata_build
.set_rdr1r2(3, 1, 1)
.set_imm_len(8)
.build(),
idata_build.set_rdr1r2(3, 1, 1).set_imm_len(8).build(),
);
let core_instruction = vec![inst_builder.build().into()];
let mut executable = Executable::new(cpu, core_instruction);
executable.execute();
// Check result correct
assert!(
executable
.cpu_mut()
.host()
.load::<T>(16 * size_of::<F>(), 8*size_of::<T>()).unwrap()[0].iter().zip(
vec![
T::from(0.1).sigm(),
T::from(0.2).sigm(),
T::from(0.3).sigm(),
T::from(0.4).sigm(),
T::from(0.5).sigm(),
T::from(0.6).sigm(),
T::from(0.7).sigm(),
T::from(0.8).sigm(),
]).all(|(&a,b) : (&T, T)| {a-b < 0.001.into()}),
.load::<T>(16 * size_of::<F>(), 8 * size_of::<T>())
.unwrap()[0]
.iter()
.zip(vec![
T::from(0.1).sigm(),
T::from(0.2).sigm(),
T::from(0.3).sigm(),
T::from(0.4).sigm(),
T::from(0.5).sigm(),
T::from(0.6).sigm(),
T::from(0.7).sigm(),
T::from(0.8).sigm(),
])
.all(|(&a, b): (&T, T)| { a - b < 0.001.into() }),
"Wrong result for {}",
err
);
@@ -892,17 +910,22 @@ where
executable
.cpu_mut()
.host()
.load::<F>(0, 16 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 16 * size_of::<F>())
.unwrap()[0],
&buff,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
16 * size_of::<F>() + 8*size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
16 * size_of::<F>() + 8 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -917,10 +940,8 @@ fn vsigm_test() {
vsigm_test_generic::<f64, f64>("vsigm<f64,f64>");
}
/// mvmul Test
fn mvmul_test_generic<F,M, T>(err: &str, relu:i32)
fn mvmul_test_generic<F, M, T>(err: &str, relu: i32)
where
F: From<f32> + std::fmt::Debug + PartialEq<F> + MemoryStorable,
M: From<f32> + std::fmt::Debug + PartialEq<M> + MemoryStorable,
@@ -948,12 +969,7 @@ where
crossbar.execute_store(&matrix).unwrap();
let mut cpu = pimcore::cpu::CPU::new(0, vec![vec![&crossbar]]);
let (memory, _) = cpu.host().get_memory_crossbar();
let vector: [F; _] = [
1.0.into(),
2.0.into(),
3.0.into(),
4.0.into(),
];
let vector: [F; _] = [1.0.into(), 2.0.into(), 3.0.into(), 4.0.into()];
memory.execute_store(0, &vector).unwrap();
let mut inst_builder = InstructionsBuilder::new();
@@ -974,7 +990,7 @@ where
mvmul,
idata_build
.set_rdr1(3, 1)
.set_mbiw_immrelu_immgroup(8*size_of::<M>() as i32, relu, 0)
.set_mbiw_immrelu_immgroup(8 * size_of::<M>() as i32, relu, 0)
.build(),
);
let core_instruction = vec![inst_builder.build().into()];
@@ -982,54 +998,50 @@ where
executable.execute();
// Check result correct
if relu == 0 {
assert_eq!(
executable
.cpu_mut()
.host()
.load::<T>(4 * size_of::<F>(), 4*size_of::<T>()).unwrap()[0],
vec![
90.0.into(),
(-24.0).into(),
110.0.into(),
120.0.into(),
],
"Wrong result for {}",
err
);
}
else {
assert_eq!(
executable
.cpu_mut()
.host()
.load::<T>(4 * size_of::<F>(), 4*size_of::<T>()).unwrap()[0],
vec![
90.0.into(),
0.0.into(),
110.0.into(),
120.0.into(),
],
"Wrong result for {}",
err
);
}
if relu == 0 {
assert_eq!(
executable
.cpu_mut()
.host()
.load::<T>(4 * size_of::<F>(), 4 * size_of::<T>())
.unwrap()[0],
vec![90.0.into(), (-24.0).into(), 110.0.into(), 120.0.into(),],
"Wrong result for {}",
err
);
} else {
assert_eq!(
executable
.cpu_mut()
.host()
.load::<T>(4 * size_of::<F>(), 4 * size_of::<T>())
.unwrap()[0],
vec![90.0.into(), 0.0.into(), 110.0.into(), 120.0.into(),],
"Wrong result for {}",
err
);
}
// Check first part equal
assert_eq!(
executable
.cpu_mut()
.host()
.load::<F>(0, 4 * size_of::<F>()).unwrap()[0],
.load::<F>(0, 4 * size_of::<F>())
.unwrap()[0],
&vector,
"Altered first part for {}",
err
);
//Check that later is 0
assert_eq!(
executable.cpu_mut().host().load::<i32>(
4 * size_of::<F>() + 4*size_of::<T>(),
4 * size_of::<i32>()
).unwrap()[0],
executable
.cpu_mut()
.host()
.load::<i32>(
4 * size_of::<F>() + 4 * size_of::<T>(),
4 * size_of::<i32>()
)
.unwrap()[0],
[0, 0, 0, 0],
"Altered first part for {}",
err
@@ -1038,22 +1050,21 @@ where
#[test]
fn mvmul_test() {
mvmul_test_generic::<f32,f32,f32>("mvmul<f32,f32,f32>",0);
mvmul_test_generic::<f32,f32,f64>("mvmul<f32,f32,f64>",0);
mvmul_test_generic::<f32,f64,f32>("mvmul<f32,f64,f32>",0);
mvmul_test_generic::<f32,f64,f64>("mvmul<f32,f64,f64>",0);
mvmul_test_generic::<f64,f32,f32>("mvmul<f64,f32,f32>",0);
mvmul_test_generic::<f64,f32,f64>("mvmul<f64,f32,f64>",0);
mvmul_test_generic::<f64,f64,f32>("mvmul<f64,f64,f32>",0);
mvmul_test_generic::<f64,f64,f64>("mvmul<f64,f64,f64>",0);
mvmul_test_generic::<f32,f32,f32>("mvmul<f32,f32,f32>",1);
mvmul_test_generic::<f32,f32,f64>("mvmul<f32,f32,f64>",1);
mvmul_test_generic::<f32,f64,f32>("mvmul<f32,f64,f32>",1);
mvmul_test_generic::<f32,f64,f64>("mvmul<f32,f64,f64>",1);
mvmul_test_generic::<f64,f32,f32>("mvmul<f64,f32,f32>",1);
mvmul_test_generic::<f64,f32,f64>("mvmul<f64,f32,f64>",1);
mvmul_test_generic::<f64,f64,f32>("mvmul<f64,f64,f32>",1);
mvmul_test_generic::<f64,f64,f64>("mvmul<f64,f64,f64>",1);
mvmul_test_generic::<f32, f32, f32>("mvmul<f32,f32,f32>", 0);
mvmul_test_generic::<f32, f32, f64>("mvmul<f32,f32,f64>", 0);
mvmul_test_generic::<f32, f64, f32>("mvmul<f32,f64,f32>", 0);
mvmul_test_generic::<f32, f64, f64>("mvmul<f32,f64,f64>", 0);
mvmul_test_generic::<f64, f32, f32>("mvmul<f64,f32,f32>", 0);
mvmul_test_generic::<f64, f32, f64>("mvmul<f64,f32,f64>", 0);
mvmul_test_generic::<f64, f64, f32>("mvmul<f64,f64,f32>", 0);
mvmul_test_generic::<f64, f64, f64>("mvmul<f64,f64,f64>", 0);
mvmul_test_generic::<f32, f32, f32>("mvmul<f32,f32,f32>", 1);
mvmul_test_generic::<f32, f32, f64>("mvmul<f32,f32,f64>", 1);
mvmul_test_generic::<f32, f64, f32>("mvmul<f32,f64,f32>", 1);
mvmul_test_generic::<f32, f64, f64>("mvmul<f32,f64,f64>", 1);
mvmul_test_generic::<f64, f32, f32>("mvmul<f64,f32,f32>", 1);
mvmul_test_generic::<f64, f32, f64>("mvmul<f64,f32,f64>", 1);
mvmul_test_generic::<f64, f64, f32>("mvmul<f64,f64,f32>", 1);
mvmul_test_generic::<f64, f64, f64>("mvmul<f64,f64,f64>", 1);
}
@@ -1,7 +1,7 @@
mod common;
use pimcore::{
Executable, CoreInstructionsBuilder,
CoreInstructionsBuilder, Executable,
instruction_set::{InstructionsBuilder, instruction_data::InstructionDataBuilder, isa::*},
};
@@ -158,7 +158,12 @@ fn simple_send_recv_test() {
let mut inst_builder = InstructionsBuilder::new();
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(1).fix_core_indx();
inst_builder.make_inst(sldi, idata_build.set_rdimm(1, 3*size_of::<f32>() as i32).build());
inst_builder.make_inst(
sldi,
idata_build
.set_rdimm(1, 3 * size_of::<f32>() as i32)
.build(),
);
inst_builder.make_inst(
send,
idata_build
@@ -188,15 +193,11 @@ fn simple_send_recv_test() {
assert_eq!(
res.unwrap()[0],
[
4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0
],
[4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0],
"send_recv failed to store"
);
}
// 1 -> 3
// 2 -> 3
// 3 <- 2
@@ -210,53 +211,54 @@ fn simple_send_recv_test() {
fn multiple_send_recv_test() {
let mut cpu = common::empty_cpu(4);
let mut core_instruction_builder = CoreInstructionsBuilder::new(4);
let buff: [f32; _] = [
1.0, 1.0, 1.0, 1.0, 1.0
];
let buff: [f32; _] = [1.0, 1.0, 1.0, 1.0, 1.0];
cpu.core(1).execute_store(0, &buff).unwrap();
let buff: [f32; _] = [
2.0, 2.0, 2.0, 2.0, 2.0
];
let buff: [f32; _] = [2.0, 2.0, 2.0, 2.0, 2.0];
cpu.core(2).execute_store(0, &buff).unwrap();
let buff: [f32; _] = [
3.0, 3.0, 3.0, 3.0, 3.0
];
let buff: [f32; _] = [3.0, 3.0, 3.0, 3.0, 3.0];
cpu.core(3).execute_store(0, &buff).unwrap();
let buff: [f32; _] = [
4.0, 4.0, 4.0, 4.0, 4.0
];
let buff: [f32; _] = [4.0, 4.0, 4.0, 4.0, 4.0];
cpu.core(4).execute_store(0, &buff).unwrap();
let send_inst = |inst_builder: &mut InstructionsBuilder, from: i32, to: i32| {
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(from).fix_core_indx();
inst_builder.make_inst(sldi, idata_build.set_rdimm(1, from*size_of::<f32>() as i32).build());
inst_builder.make_inst(
send,
idata_build
.set_r1(1)
.set_imm_core(to)
.set_imm_len(size_of::<f32>() as i32)
.build(),
);
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(from).fix_core_indx();
inst_builder.make_inst(
sldi,
idata_build
.set_rdimm(1, from * size_of::<f32>() as i32)
.build(),
);
inst_builder.make_inst(
send,
idata_build
.set_r1(1)
.set_imm_core(to)
.set_imm_len(size_of::<f32>() as i32)
.build(),
);
};
let recv_inst = |inst_builder: &mut InstructionsBuilder, to: i32, from: i32| {
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(to).fix_core_indx();
inst_builder.make_inst(sldi, idata_build.set_rdimm(1, from*size_of::<f32>() as i32).build());
inst_builder.make_inst(
recv,
idata_build
.set_rd(1)
.set_imm_core(from)
.set_imm_len(size_of::<f32>() as i32)
.build(),
);
let mut idata_build = InstructionDataBuilder::new();
idata_build.set_core_indx(to).fix_core_indx();
inst_builder.make_inst(
sldi,
idata_build
.set_rdimm(1, from * size_of::<f32>() as i32)
.build(),
);
inst_builder.make_inst(
recv,
idata_build
.set_rd(1)
.set_imm_core(from)
.set_imm_len(size_of::<f32>() as i32)
.build(),
);
};
let mut inst_builder = InstructionsBuilder::new();
// 1 -> 3
send_inst(&mut inst_builder, 1, 3);
core_instruction_builder.set_core(1, inst_builder.build());
@@ -289,7 +291,7 @@ fn multiple_send_recv_test() {
assert_eq!(
res.unwrap()[0],
[ 1.0, 2.0, 3.0, 4.0 ],
[1.0, 2.0, 3.0, 4.0],
"send_recv failed to store"
);
}