Skip to content

Instantly share code, notes, and snippets.

@athas
Created April 29, 2020 09:59
Show Gist options
  • Select an option

  • Save athas/cff9711f1bb6ad4ffdcbcef57140b85b to your computer and use it in GitHub Desktop.

Select an option

Save athas/cff9711f1bb6ad4ffdcbcef57140b85b to your computer and use it in GitHub Desktop.
-- $ futhark bench imgrep.fut --backend=opencl
-- Compiling imgrep.fut...
-- Results for imgrep.fut:test_a:
-- dataset [2000][2000][3]u8: 240.00μs (avg. of 10 runs; RSD: 0.08)
-- Results for imgrep.fut:test_b:
-- dataset [2000][2000]u8 [2000][2000]u8 [2000][2000]u8: 172.90μs (avg. of 10 runs; RSD: 0.01)
-- Results for imgrep.fut:test_c:
-- dataset [2000][2000]u32: 216.70μs (avg. of 10 runs; RSD: 0.01)
-- ==
-- entry: test_a
-- random input { [2000][2000][3]u8 }
entry test_a [n][m] (img: [n][m][3]u8) =
let f pixel = [pixel[0]+1, pixel[1]+2, pixel[2]+3]
in map (map f) img
-- ==
-- entry: test_b
-- random input { [2000][2000]u8 [2000][2000]u8 [2000][2000]u8 }
entry test_b [n][m] (rs: [n][m]u8) (gs: [n][m]u8) (bs: [n][m]u8) =
let f r g b = (r+1, g+2, b+3)
in map3 (map3 f) rs gs bs |> map unzip3 |> unzip3
-- ==
-- entry: test_c
-- random input { [2000][2000]u32 }
entry test_c [n][m] (img: [n][m]u32) =
let f pixel = let r = (pixel>>16)&0xFF
let g = (pixel>>8)&0xFF
let b = pixel&0xFF
in ((r+1)<<16) | ((g+2)<<8) | (b+1)
in map (map f) img
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment