aboutsummaryrefslogtreecommitdiff
path: root/aberth
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-04-20 10:26:24 +0200
committertomsmeding <tom.smeding@gmail.com>2019-04-20 10:26:24 +0200
commit3a7e1c80cb28a5d63da056f4889eb207140c0e67 (patch)
treeeed8ff398fcef7c44afea06480fe91b7534e2c7a /aberth
parent68d2ce9c59e90bb9a8bee4ad65a0e87185304354 (diff)
Different image bounds layout
Diffstat (limited to 'aberth')
-rw-r--r--aberth/aberth.cpp12
-rw-r--r--aberth/aberth_kernel.fut25
2 files changed, 22 insertions, 15 deletions
diff --git a/aberth/aberth.cpp b/aberth/aberth.cpp
index 6936809..550760d 100644
--- a/aberth/aberth.cpp
+++ b/aberth/aberth.cpp
@@ -342,11 +342,12 @@ static vector<uint8_t> drawImage(int W, int H, const vector<int> &counts, int ma
static vector<int32_t> invoke_kernel(
int32_t width, int32_t height,
- double left, double top, double right, double bottom,
+ Com bottomLeft, Com topRight,
int32_t seed) {
futhark_context_config *config = futhark_context_config_new();
// futhark_context_config_select_device_interactively(config);
+ futhark_context_config_set_debugging(config, 1);
futhark_context *ctx = futhark_context_new(config);
@@ -364,7 +365,8 @@ static vector<int32_t> invoke_kernel(
check_ret(futhark_entry_main_all(
ctx, &dest_arr,
width, height,
- left, top, right, bottom,
+ bottomLeft.real(), topRight.imag(),
+ topRight.real(), bottomLeft.imag(),
seed));
check_ret(futhark_context_sync(ctx));
@@ -391,9 +393,9 @@ int main(int argc, char **argv) {
if (argc <= 1) {
// tie(W, H, counts) = computeCounts();
W = H = 2000;
- Com bottomLeft = Com(-1.6, -1.6);
- Com topRight = Com(1.6, 1.6);
- counts = invoke_kernel(W, H, bottomLeft.real(), topRight.imag(), topRight.real(), bottomLeft.imag(), 42);
+ Com bottomLeft = Com(0, -1.6);
+ Com topRight = Com(1.6, 0);
+ counts = invoke_kernel(W, H, bottomLeft, topRight, 42);
writeCounts(W, H, counts, "out.txt");
} else if (argc == 2) {
tie(W, H, counts) = readCounts(argv[1]);
diff --git a/aberth/aberth_kernel.fut b/aberth/aberth_kernel.fut
index fae1450..58b8838 100644
--- a/aberth/aberth_kernel.fut
+++ b/aberth/aberth_kernel.fut
@@ -128,11 +128,13 @@ let calc_index (value: f64) (left: f64) (right: f64) (steps: i32): i32 =
let point_index
(width: i32) (height: i32)
- (top_left: complex) (bottom_right: complex)
+ (bottom_left: complex) (top_right: complex)
(pt: complex)
: i32 =
- let xi = calc_index (c64.re pt) (c64.re top_left) (c64.re bottom_right) width
- let yi = calc_index (c64.im pt) (c64.im bottom_right) (c64.im top_left) height
+ -- Range for 'yi' is reversed because image coordinates go down in the y
+ -- direction, while complex coordinates go up in the y direction
+ let xi = calc_index (c64.re pt) (c64.re bottom_left) (c64.re top_right) width
+ let yi = calc_index (c64.im pt) (c64.im top_right) (c64.im bottom_left) height
in if 0 <= xi && xi < width && 0 <= yi && yi < height
then width * yi + xi
else -1
@@ -145,16 +147,19 @@ entry main_job
: []i32 =
-- Unnecessary to give each polynomial a different seed
let rng = rand_engine.rng_from_seed [seed]
- let top_left = c64.mk left top
- let bottom_right = c64.mk right bottom
- let indices = filter (\i -> i != -1) (flatten
+ let bottom_left = c64.mk left bottom
+ let top_right = c64.mk right top
+ let indices = flatten
(map (\idx ->
let p = derbyshire_at_index idx
let (_, pts) = aberth.aberth p rng
- let indices = map (point_index width height top_left bottom_right) pts
- in indices)
- (start_index ..< start_index + num_polys)))
- in reduce_by_index (replicate (width * height) 0) (+) 0 indices (replicate (length indices) 1)
+ in map (point_index width height bottom_left top_right) pts)
+ (start_index ..< start_index + num_polys))
+ let filtered = filter (\i -> i != -1) indices
+ in reduce_by_index (replicate (width * height) 0)
+ (+) 0
+ filtered
+ (replicate (length filtered) 1)
entry main_all
(width: i32) (height: i32)