Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better views implementation #12

Merged
merged 28 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5c11e2c
refactor: Renamed ViewBase into View
imrn99 Dec 20, 2023
3318d77
refactor: removed type aliases for view variants
imrn99 Dec 20, 2023
b563c24
refactor: removed last type alias ViewOwned
imrn99 Dec 20, 2023
2467f5b
docs: updated doc accordingly to aliases deletion
imrn99 Dec 20, 2023
4e43a21
refactor: removed DataType enum from View implementation
imrn99 Dec 20, 2023
c51380f
feat: impl PartialEq for View
imrn99 Dec 20, 2023
6f108e4
refactor: delete DataType enum
imrn99 Dec 20, 2023
2bf44b1
feat: MemorySpace enum
imrn99 Dec 20, 2023
509712b
refactor: rename Layout as MemoryLayout
imrn99 Dec 20, 2023
a6c007f
feature: allocation method for view data
imrn99 Dec 20, 2023
72bdf65
feature: add ViewData type
imrn99 Dec 20, 2023
ef76f45
feature: more methods for ViewData
imrn99 Dec 20, 2023
b54e814
refactor: isize -> usize in ViewData methods
imrn99 Dec 20, 2023
b68a68a
feat: add mirror field to ViewData struct
imrn99 Dec 21, 2023
64e2f00
feeat: add take_vals method & ensure initialization of ViewData
imrn99 Dec 21, 2023
46c2e1e
fix: revert init addition in ViewData::new
imrn99 Dec 21, 2023
8d7163d
fix: correct inconsistent signatures across features
imrn99 Dec 21, 2023
544f6f4
test: add simple testing for ViewData
imrn99 Dec 21, 2023
b5ca815
refactor: replaced Vec by ViewData in View structure
imrn99 Dec 21, 2023
9963bc6
fix: adjust raw_val method to match new data holding type
imrn99 Dec 21, 2023
ef2ead5
fix: add impl Sync/Send to ViewData structure
imrn99 Dec 21, 2023
61b045a
refactor: pointer & layout of ViewData are now private fields
imrn99 Dec 21, 2023
f5152a5
docs: update view::parameters module
imrn99 Dec 21, 2023
e4fdf79
fix: remove useless as_ref call in get method of ViewData
imrn99 Dec 21, 2023
b46731f
docs: update view module
imrn99 Dec 21, 2023
30396ce
refactor: removed duplicate constructors of View
imrn99 Dec 21, 2023
c22594e
fix: ensure consistency of view init
imrn99 Dec 21, 2023
dd60029
fix: ViewData tests
imrn99 Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions benches/blas-speedup/axpy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poc_kokkos_rs::{
parallel_for,
parameters::{ExecutionPolicy, ExecutionSpace, RangePolicy, Schedule},
},
view::{parameters::Layout, ViewOwned},
view::{parameters::MemoryLayout, View},
};
use rand::{
distributions::{Distribution, Uniform},
Expand All @@ -16,8 +16,8 @@ use rand::{
// Serial AXPY
fn f1(x_init: Vec<f64>, y_init: Vec<f64>, alpha: f64) {
let length = x_init.len();
let mut x = ViewOwned::new_from_data(x_init, Layout::Right, [length]);
let mut y = ViewOwned::new_from_data(y_init, Layout::Right, [length]);
let mut x = View::new_from_data(x_init, MemoryLayout::Right, [length]);
let mut y = View::new_from_data(y_init, MemoryLayout::Right, [length]);
black_box(&mut x);
black_box(&mut y);

Expand All @@ -43,8 +43,8 @@ fn f1(x_init: Vec<f64>, y_init: Vec<f64>, alpha: f64) {
// DeviceCPU AXPY
fn f2(x_init: Vec<f64>, y_init: Vec<f64>, alpha: f64) {
let length = x_init.len();
let mut x = ViewOwned::new_from_data(x_init, Layout::Right, [length]);
let mut y = ViewOwned::new_from_data(y_init, Layout::Right, [length]);
let mut x = View::new_from_data(x_init, MemoryLayout::Right, [length]);
let mut y = View::new_from_data(y_init, MemoryLayout::Right, [length]);
black_box(&mut x);
black_box(&mut y);

Expand Down
14 changes: 7 additions & 7 deletions benches/blas-speedup/gemm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poc_kokkos_rs::{
parallel_for,
parameters::{ExecutionPolicy, ExecutionSpace, RangePolicy, Schedule},
},
view::{parameters::Layout, ViewOwned},
view::{parameters::MemoryLayout, View},
};
use rand::{
distributions::{Distribution, Uniform},
Expand All @@ -22,9 +22,9 @@ fn f1(
alpha: f64,
beta: f64,
) {
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Left, [length, length]); // optimal layout since we iterate inside columns :)
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Right, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Left, [length, length]); // optimal layout since we iterate inside columns :)
let mut cc = View::new_from_data(cc_init, MemoryLayout::Right, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down Expand Up @@ -63,9 +63,9 @@ fn f2(
alpha: f64,
beta: f64,
) {
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Left, [length, length]); // optimal layout since we iterate inside columns :)
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Right, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Left, [length, length]); // optimal layout since we iterate inside columns :)
let mut cc = View::new_from_data(cc_init, MemoryLayout::Right, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down
14 changes: 7 additions & 7 deletions benches/blas-speedup/gemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poc_kokkos_rs::{
parallel_for,
parameters::{ExecutionPolicy, ExecutionSpace, RangePolicy, Schedule},
},
view::{parameters::Layout, ViewOwned},
view::{parameters::MemoryLayout, View},
};
use rand::{
distributions::{Distribution, Uniform},
Expand All @@ -16,9 +16,9 @@ use rand::{
// Serial GEMV
fn f1(aa_init: Vec<f64>, x_init: Vec<f64>, y_init: Vec<f64>, alpha: f64, beta: f64) {
let length = x_init.len();
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut x = ViewOwned::new_from_data(x_init, Layout::Right, [length]);
let mut y = ViewOwned::new_from_data(y_init, Layout::Right, [length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut x = View::new_from_data(x_init, MemoryLayout::Right, [length]);
let mut y = View::new_from_data(y_init, MemoryLayout::Right, [length]);
black_box(&mut aa);
black_box(&mut x);
black_box(&mut y);
Expand Down Expand Up @@ -46,9 +46,9 @@ fn f1(aa_init: Vec<f64>, x_init: Vec<f64>, y_init: Vec<f64>, alpha: f64, beta: f
// DeviceCPU GEMV
fn f2(aa_init: Vec<f64>, x_init: Vec<f64>, y_init: Vec<f64>, alpha: f64, beta: f64) {
let length = x_init.len();
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut x = ViewOwned::new_from_data(x_init, Layout::Right, [length]);
let mut y = ViewOwned::new_from_data(y_init, Layout::Right, [length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut x = View::new_from_data(x_init, MemoryLayout::Right, [length]);
let mut y = View::new_from_data(y_init, MemoryLayout::Right, [length]);
black_box(&mut aa);
black_box(&mut x);
black_box(&mut y);
Expand Down
20 changes: 10 additions & 10 deletions benches/layout/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poc_kokkos_rs::{
parallel_for,
parameters::{ExecutionPolicy, ExecutionSpace, RangePolicy, Schedule},
},
view::{parameters::Layout, ViewOwned},
view::{parameters::MemoryLayout, View},
};
use rand::{
distributions::{Distribution, Uniform},
Expand All @@ -25,9 +25,9 @@ fn f1(
// worst case layout:
// iterate on lines -> column-major layout (Left)
// iterate on rows -> line-major layout (Right)
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Left, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Right, [length, length]);
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Left, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Left, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Right, [length, length]);
let mut cc = View::new_from_data(cc_init, MemoryLayout::Left, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down Expand Up @@ -69,9 +69,9 @@ fn f2(
// best case layout:
// iterate on lines -> line-major layout (Right)
// iterate on rows -> column-major layout (Left)
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Right, [length, length]);
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Right, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Right, [length, length]);
let mut cc = View::new_from_data(cc_init, MemoryLayout::Right, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down Expand Up @@ -110,9 +110,9 @@ fn f3(
alpha: f64,
beta: f64,
) {
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Left, [length, length]);
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Right, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Left, [length, length]);
let mut cc = View::new_from_data(cc_init, MemoryLayout::Right, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down
14 changes: 7 additions & 7 deletions benches/layout/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use poc_kokkos_rs::{
parallel_for,
parameters::{ExecutionPolicy, ExecutionSpace, RangePolicy, Schedule},
},
view::{parameters::Layout, ViewOwned},
view::{parameters::MemoryLayout, View},
};
use rand::{
distributions::{Distribution, Uniform},
Expand All @@ -27,9 +27,9 @@ fn f1(
// best case layout:
// iterate on lines -> line-major layout (Right)
// iterate on rows -> column-major layout (Left)
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Right, [length, length]);
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Right, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Right, [length, length]);
let mut cc = View::new_from_data(cc_init, MemoryLayout::Right, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down Expand Up @@ -68,9 +68,9 @@ fn f2(
alpha: FloatType,
beta: FloatType,
) {
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Left, [length, length]);
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Right, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Left, [length, length]);
let mut cc = View::new_from_data(cc_init, MemoryLayout::Right, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down
16 changes: 9 additions & 7 deletions benches/view_access.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use poc_kokkos_rs::view::{parameters::Layout, ViewOwned};
use poc_kokkos_rs::view::{parameters::MemoryLayout, View};
use rand::prelude::*;

// this bench is used to evaluate the cost of accessing views' data
Expand All @@ -18,8 +18,7 @@ fn f1(length: usize, indices: &[usize]) {

// 1D view access
fn f1_b(length: usize, indices: &[usize]) {
let v_y: ViewOwned<'_, 1, f64> =
ViewOwned::new_from_data(vec![0.0; length], Layout::Right, [length]);
let v_y: View<1, f64> = View::new_from_data(vec![0.0; length], MemoryLayout::Right, [length]);
let idx = &indices[0..length];

idx.iter().for_each(|i| {
Expand All @@ -41,8 +40,11 @@ fn f2(length: usize, indices: &[(usize, usize)]) {

// 2D view access
fn f2_b(length: usize, indices: &[(usize, usize)]) {
let v_y: ViewOwned<'_, 2, f64> =
ViewOwned::new_from_data(vec![0.0; length * length], Layout::Right, [length, length]);
let v_y: View<2, f64> = View::new_from_data(
vec![0.0; length * length],
MemoryLayout::Right,
[length, length],
);
let idx = &indices[0..length];

idx.iter().for_each(|(i, j)| {
Expand Down Expand Up @@ -71,9 +73,9 @@ fn f3(length: usize, indices: &[(usize, usize, usize)]) {

// 3D view access
fn f3_b(length: usize, indices: &[(usize, usize, usize)]) {
let v_y: ViewOwned<'_, 3, f64> = ViewOwned::new_from_data(
let v_y: View<3, f64> = View::new_from_data(
vec![0.0; length * length * length],
Layout::Right,
MemoryLayout::Right,
[length, length, length],
);
let idx = &indices[0..length];
Expand Down
22 changes: 12 additions & 10 deletions benches/view_init.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
use poc_kokkos_rs::view::{parameters::Layout, ViewOwned};
use poc_kokkos_rs::view::{parameters::MemoryLayout, View};

// this bench is used to evaluate the cost of creating views

Expand All @@ -19,7 +19,7 @@ fn f1_b(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..1000 {
let y: Vec<f64> = vec![0.0; length];
let v_y: ViewOwned<'_, 1, f64> = ViewOwned::new_from_data(y, Layout::Right, [length]);
let v_y: View<1, f64> = View::new_from_data(y, MemoryLayout::Right, [length]);
black_box(v_y);
}
}
Expand All @@ -28,8 +28,8 @@ fn f1_b(size: u32) {
fn f1_bb(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..1000 {
let v_y: ViewOwned<'_, 1, f64> =
ViewOwned::new_from_data(vec![0.0; length], Layout::Right, [length]);
let v_y: View<1, f64> =
View::new_from_data(vec![0.0; length], MemoryLayout::Right, [length]);
black_box(v_y);
}
}
Expand All @@ -38,7 +38,7 @@ fn f1_bb(size: u32) {
fn f1_bbb(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..1000 {
let v_y: ViewOwned<'_, 1, f64> = ViewOwned::new(Layout::Right, [length]);
let v_y: View<1, f64> = View::new(MemoryLayout::Right, [length]);
black_box(v_y);
}
}
Expand All @@ -59,8 +59,7 @@ fn f2_b(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..100 {
let y: Vec<f64> = vec![0.0; length * length];
let v_y: ViewOwned<'_, 2, f64> =
ViewOwned::new_from_data(y, Layout::Right, [length, length]);
let v_y: View<2, f64> = View::new_from_data(y, MemoryLayout::Right, [length, length]);
black_box(v_y);
}
}
Expand All @@ -69,8 +68,11 @@ fn f2_b(size: u32) {
fn f2_bb(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..100 {
let v_y: ViewOwned<'_, 2, f64> =
ViewOwned::new_from_data(vec![0.0; length * length], Layout::Right, [length, length]);
let v_y: View<2, f64> = View::new_from_data(
vec![0.0; length * length],
MemoryLayout::Right,
[length, length],
);
black_box(v_y);
}
}
Expand All @@ -79,7 +81,7 @@ fn f2_bb(size: u32) {
fn f2_bbb(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..100 {
let v_y: ViewOwned<'_, 2, f64> = ViewOwned::new(Layout::Right, [length, length]);
let v_y: View<2, f64> = View::new(MemoryLayout::Right, [length, length]);
black_box(v_y);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use poc_kokkos_rs::{
parallel_for,
parameters::{ExecutionPolicy, ExecutionSpace, RangePolicy, Schedule},
},
view::{parameters::Layout, ViewOwned},
view::{parameters::MemoryLayout, View},
};
use rand::{distributions::Uniform, prelude::*, rngs::SmallRng, SeedableRng};

Expand Down Expand Up @@ -36,9 +36,9 @@ fn main() {
let beta: f64 = range.sample(&mut rng);

// inits again
let mut aa = ViewOwned::new_from_data(aa_init, Layout::Right, [length, length]);
let mut bb = ViewOwned::new_from_data(bb_init, Layout::Left, [length, length]); // optimal layout since we iterate inside columns :)
let mut cc = ViewOwned::new_from_data(cc_init, Layout::Right, [length, length]);
let mut aa = View::new_from_data(aa_init, MemoryLayout::Right, [length, length]);
let mut bb = View::new_from_data(bb_init, MemoryLayout::Left, [length, length]); // optimal layout since we iterate inside columns :)
let mut cc = View::new_from_data(cc_init, MemoryLayout::Right, [length, length]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down
Loading
Loading