Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Parallel Longest Satisfying Segment
--
-- ==
-- compiled input {
-- [1i32, -2i32, -2i32, 0i32, 0i32, 0i32, 0i32, 0i32, 3i32, 4i32, -6i32, 1i32]
-- }
-- output {
-- 5i32
-- }

-- ==
-- compiled input { [7i32] }
-- output { 1 }

-- ==
-- compiled input { [1i32,1,1,2,2,2,2,3] }
-- output { 4 }

-- ==
-- compiled input { [3i32,3,2,2,2,1,1,1,1,0] }
-- output { 4 }

import "lssp"
import "lssp-seq"

let main (xs: []i32) : i32 =
let pred1 _x = true
let pred2 x y = (x == y)
-- in lssp_seq pred1 pred2 xs
in lssp pred1 pred2 xs

entry bench_same_gpu (n: i32) : i32 =
let pred1 _ = true
let pred2 x y = (x == y)
let xs = map (\i -> i32.i64 ((i / 5i64) % 97i64))
(iota (i64.i32 n))
in lssp pred1 pred2 xs

entry bench_same_seq (n: i32) : i32 =
let pred1 _ = true
let pred2 x y = (x == y)
let xs = map (\i -> i32.i64 ((i / 5i64) % 97i64))
(iota (i64.i32 n))
in lssp_seq pred1 pred2 xs

-- ==
-- entry: bench_same_gpu
-- input { 1000000i32 }
-- input { 5000000i32 }

-- ==
-- entry: bench_same_seq
-- input { 1000000i32 }
-- input { 5000000i32 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--------------------------------------------------------
--- Attempting the sequential implementation of lssp ---
--------------------------------------------------------

type int = i32
let max (x:int, y:int) = i32.max x y

let lssp_seq [n]
(pred1 : int -> bool)
(pred2 : int -> int -> bool)
(xs : [n]int ) : int =
let (best_len, _, _) =
loop(best_len, curr_len, prev) = (0, 0, 0)
for i < n do
let x = xs[i]
let connected = if i==0 then true else pred2 prev x
let satisfied = pred1 x
let curr_len = if satisfied && connected
then curr_len+1
else if satisfied then 1 else 0
let best_len = max(best_len, curr_len)
in (best_len, curr_len, x)
in best_len
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- Parallel Longest Satisfying Segment
--
-- ==
-- compiled input {
-- [1, -2, -2, 0, 0, 0, 0, 0, 3, 4, -6, 1]
-- }
-- output {
-- 9
-- }

-- ==
-- compiled input { [5i32] }
-- output { 1 }

-- ==
-- compiled input { [1i32, 2, 2, 3, 0, 1, 2] }
-- output { 4 }

-- ==
-- compiled input { [3i32,2,1,0] }
-- output { 1 }

import "lssp"
import "lssp-seq"

type int = i32

let main (xs: []int) : int =
let pred1 _ = true
let pred2 x y = (x <= y)
-- in lssp_seq pred1 pred2 xs
in lssp pred1 pred2 xs

entry bench_sorted_gpu (n: i32) : i32 =
let pred1 _ = true
let pred2 x y = (x <= y)
let xs = map (\i -> i32.i64 (i % 1000i64))
(iota (i64.i32 n))
in lssp pred1 pred2 xs

entry bench_sorted_seq (n: i32) : i32 =
let pred1 _ = true
let pred2 x y = (x <= y)
let xs = map (\i -> i32.i64 (i % 1000i64))
(iota (i64.i32 n))
in lssp_seq pred1 pred2 xs

-- ==
-- entry: bench_sorted_gpu
-- input { 1000000i32 }
-- input { 5000000i32 }

-- ==
-- entry: bench_sorted_seq
-- input { 1000000i32 }
-- input { 5000000i32 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-- Parallel Longest Satisfying Segment
--
-- ==
-- compiled input {
-- [1i32, -2, -2, 0, 0, 0, 0, 0, 3, 4, -6, 1]
-- }
-- output {
-- 5
-- }

-- ==
-- compiled input { [1i32,2,3] }
-- output { 0 }

-- ==
-- compiled input { [0i32] }
-- output { 1 }

-- ==
-- compiled input { [0i32,0,1,0,0,0,2,0] }
-- output { 3 }

import "lssp-seq"
import "lssp"

type int = i32

let main (xs: []int) : int =
let pred1 x = (x == 0)
let pred2 x y = (x == 0) && (y == 0)
-- in lssp_seq pred1 pred2 xs
in lssp pred1 pred2 xs

-- Bench entries (large synthetic inputs)
entry bench_zeros_gpu (n: i32) : i32 =
let pred1 x = (x == 0)
let pred2 x y = (x == 0) && (y == 0)
let xs = map (\i -> if (i % 8i64 == 0i64) then 1i32 else 0i32)
(iota (i64.i32 n))
in lssp pred1 pred2 xs

entry bench_zeros_seq (n: i32) : i32 =
let pred1 x = (x == 0)
let pred2 x y = (x == 0) && (y == 0)
let xs = map (\i -> if (i % 8i64 == 0i64) then 1i32 else 0i32)
(iota (i64.i32 n))
in lssp_seq pred1 pred2 xs

-- Bench datasets
-- ==
-- entry: bench_zeros_gpu
-- input { 1000000i32 }
-- input { 5000000i32 }

-- ==
-- entry: bench_zeros_seq
-- input { 1000000i32 }
-- input { 5000000i32 }

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-----------------------------------------
-- Parallel Longest Satisfying Segment --
-- Longest Satisfying Segment --
-- ASSIGNMENT 1: fill in the blanks --
-- See lecture notes --
-- pred1 x = p [x] --
-- pred2 x y = p [x,y] --
-----------------------------------------

-- use `max a b` to compute the max between i32 values a and b.
let max = i32.max

-- The sextuple (6-tuple) used to hold meta-data for the LSS computation.
type lss_t = (i32, i32, i32, i32, i32, i32)

let lss_redOp (pred2: i32 -> i32 -> bool)
((x_lss, x_lis, x_lcs, x_len, x_first, x_last): lss_t)
((y_lss, y_lis, y_lcs, y_len, y_first, y_last): lss_t)
: lss_t =

-- Weekly 1, task 2 -- LSSP
-- TODO: fill in the 5 missing values (indicated by `???`).
let segments_connect =
(x_len > 0) && (y_len > 0) && pred2 x_last y_first

let new_lss =
max (max x_lss y_lss)
(if segments_connect then x_lcs + y_lis else 0)

let new_lis =
if x_len == 0 then y_lis
else if x_lis == x_len
then x_lis + (if segments_connect then y_lis else 0)
else x_lis

let new_lcs =
if y_len == 0 then x_lcs
else if y_lcs == y_len
then y_lcs + (if segments_connect then x_lcs else 0)
else y_lcs

let new_len = x_len + y_len

let new_first = if x_len == 0 then y_first else x_first
let new_last = if y_len == 0 then x_last else y_last
in (new_lss, new_lis, new_lcs, new_len, new_first, new_last)

let lss_mapOp (pred1: i32 -> bool) (x: i32) : lss_t =
let xmatch = i32.bool (pred1 x)
in (xmatch, xmatch, xmatch, 1, x, x)

let lssp (pred1: i32 -> bool)
(pred2: i32 -> i32 -> bool)
(xs: []i32)
: i32 =
map (lss_mapOp pred1) xs
|> reduce (lss_redOp pred2) (0, 0, 0, 0, 0, 0)
|> (.0)
Loading