Skip to content

Commit

Permalink
Merge pull request #13 from imrn99/revert-12-better-views
Browse files Browse the repository at this point in the history
Revert "Better views implementation"
  • Loading branch information
imrn99 authored Dec 22, 2023
2 parents b06724d + 24dbbae commit c64fcb3
Show file tree
Hide file tree
Showing 11 changed files with 381 additions and 455 deletions.
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::MemoryLayout, View},
view::{parameters::Layout, ViewOwned},
};
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 = View::new_from_data(x_init, MemoryLayout::Right, [length]);
let mut y = View::new_from_data(y_init, MemoryLayout::Right, [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]);
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 = View::new_from_data(x_init, MemoryLayout::Right, [length]);
let mut y = View::new_from_data(y_init, MemoryLayout::Right, [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]);
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::MemoryLayout, View},
view::{parameters::Layout, ViewOwned},
};
use rand::{
distributions::{Distribution, Uniform},
Expand All @@ -22,9 +22,9 @@ fn f1(
alpha: f64,
beta: f64,
) {
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]);
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]);
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 = 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]);
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]);
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::MemoryLayout, View},
view::{parameters::Layout, ViewOwned},
};
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 = 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]);
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]);
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 = 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]);
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]);
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::MemoryLayout, View},
view::{parameters::Layout, ViewOwned},
};
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 = 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]);
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]);
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 = 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]);
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]);
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 = 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]);
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]);
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::MemoryLayout, View},
view::{parameters::Layout, ViewOwned},
};
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 = 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]);
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]);
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 = 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]);
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]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down
16 changes: 7 additions & 9 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::MemoryLayout, View};
use poc_kokkos_rs::view::{parameters::Layout, ViewOwned};
use rand::prelude::*;

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

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

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

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

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

// 3D view access
fn f3_b(length: usize, indices: &[(usize, usize, usize)]) {
let v_y: View<3, f64> = View::new_from_data(
let v_y: ViewOwned<'_, 3, f64> = ViewOwned::new_from_data(
vec![0.0; length * length * length],
MemoryLayout::Right,
Layout::Right,
[length, length, length],
);
let idx = &indices[0..length];
Expand Down
22 changes: 10 additions & 12 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::MemoryLayout, View};
use poc_kokkos_rs::view::{parameters::Layout, ViewOwned};

// 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: View<1, f64> = View::new_from_data(y, MemoryLayout::Right, [length]);
let v_y: ViewOwned<'_, 1, f64> = ViewOwned::new_from_data(y, Layout::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: View<1, f64> =
View::new_from_data(vec![0.0; length], MemoryLayout::Right, [length]);
let v_y: ViewOwned<'_, 1, f64> =
ViewOwned::new_from_data(vec![0.0; length], Layout::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: View<1, f64> = View::new(MemoryLayout::Right, [length]);
let v_y: ViewOwned<'_, 1, f64> = ViewOwned::new(Layout::Right, [length]);
black_box(v_y);
}
}
Expand All @@ -59,7 +59,8 @@ 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: View<2, f64> = View::new_from_data(y, MemoryLayout::Right, [length, length]);
let v_y: ViewOwned<'_, 2, f64> =
ViewOwned::new_from_data(y, Layout::Right, [length, length]);
black_box(v_y);
}
}
Expand All @@ -68,11 +69,8 @@ fn f2_b(size: u32) {
fn f2_bb(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..100 {
let v_y: View<2, f64> = View::new_from_data(
vec![0.0; length * length],
MemoryLayout::Right,
[length, length],
);
let v_y: ViewOwned<'_, 2, f64> =
ViewOwned::new_from_data(vec![0.0; length * length], Layout::Right, [length, length]);
black_box(v_y);
}
}
Expand All @@ -81,7 +79,7 @@ fn f2_bb(size: u32) {
fn f2_bbb(size: u32) {
let length = 2_usize.pow(size);
for _ in 0..100 {
let v_y: View<2, f64> = View::new(MemoryLayout::Right, [length, length]);
let v_y: ViewOwned<'_, 2, f64> = ViewOwned::new(Layout::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::MemoryLayout, View},
view::{parameters::Layout, ViewOwned},
};
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 = 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]);
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]);
black_box(&mut aa);
black_box(&mut bb);
black_box(&mut cc);
Expand Down
Loading

0 comments on commit c64fcb3

Please sign in to comment.