diff --git a/juno_samples/edge_detection/benches/edge_detection_bench.rs b/juno_samples/edge_detection/benches/edge_detection_bench.rs index 760352754ccd39df878fa45523c5b7e76dd84f98..01ae418a6de2923d9ce24069f699972f9bc81f09 100644 --- a/juno_samples/edge_detection/benches/edge_detection_bench.rs +++ b/juno_samples/edge_detection/benches/edge_detection_bench.rs @@ -87,9 +87,6 @@ fn edge_detection_bench(c: &mut Criterion) { r.run( height as u64, width as u64, - gs as u64, - sz as u64, - sb as u64, input_h.to(), gaussian_filter_h, structure_h, diff --git a/juno_samples/edge_detection/src/cpu.sch b/juno_samples/edge_detection/src/cpu.sch index 64fee6b648c6fc0e17b39677353e442b4b37596e..34431711516635f2a0cfd2e2f24213fdd9f7d25c 100644 --- a/juno_samples/edge_detection/src/cpu.sch +++ b/juno_samples/edge_detection/src/cpu.sch @@ -134,7 +134,9 @@ if !feature("seq") { reject_zero_crossings = reject_zero_crossings_body; } -async-call(edge_detection@le, edge_detection@zc); +if !feature("seq") { + async-call(edge_detection@le, edge_detection@zc); +} fork-split(gaussian_smoothing, laplacian_estimate, zero_crossings, gradient, reject_zero_crossings); unforkify(gaussian_smoothing, laplacian_estimate, zero_crossings, gradient, reject_zero_crossings); diff --git a/juno_samples/edge_detection/src/edge_detection.jn b/juno_samples/edge_detection/src/edge_detection.jn index 3e49cb365b186037cf6f380c3aa6a4d3b483fb5b..be98781210791bddb7aa11ac353457e791c1d4b0 100644 --- a/juno_samples/edge_detection/src/edge_detection.jn +++ b/juno_samples/edge_detection/src/edge_detection.jn @@ -1,6 +1,10 @@ -fn gaussian_smoothing<n, m, gs : usize>( +const gs : usize = 7; +const sz : usize = 3; +const sb : usize = 3; + +fn gaussian_smoothing<n, m : usize>( input: f32[n, m], - filter: f32[gs, gs], + filter: f32[7, 7], ) -> f32[n, m] { @res let result : f32[n, m]; @@ -13,12 +17,9 @@ fn gaussian_smoothing<n, m, gs : usize>( @filter_loop for i = 0 to gs { for j = 0 to gs { - let val = input[if row + i < gr then 0 - else if row + i - gr > n - 1 then n - 1 - else row + i - gr, - if col + j < gr then 0 - else if col + j - gr > m - 1 then m - 1 - else col + j - gr]; + let br = min!(max!(row + i, gr) - gr, n - 1); + let bc = min!(max!(col + j, gr) - gr, m - 1); + let val = input[br, bc]; smoothed += val * filter[i, j]; } } @@ -33,9 +34,9 @@ fn gaussian_smoothing<n, m, gs : usize>( const MIN_BR : f32 = 0; const MAX_BR : f32 = 1; -fn laplacian_estimate<n, m, sz: usize>( +fn laplacian_estimate<n, m : usize>( input: f32[n, m], - structure: f32[sz, sz], + structure: f32[3, 3], ) -> f32[n, m] { const r = sz / 2; @@ -77,9 +78,9 @@ fn laplacian_estimate<n, m, sz: usize>( return result; } -fn zero_crossings<n, m, sz: usize>( +fn zero_crossings<n, m : usize>( input: f32[n, m], - structure: f32[sz, sz], + structure: f32[3, 3], ) -> f32[n, m] { const r = sz / 2; @@ -123,10 +124,10 @@ fn zero_crossings<n, m, sz: usize>( return result; } -fn gradient<n, m, sb: usize>( +fn gradient<n, m : usize>( input: f32[n, m], - sx: f32[sb, sb], - sy: f32[sb, sb], + sx: f32[3, 3], + sy: f32[3, 3], ) -> f32[n, m] { const sbr = sb / 2; @@ -191,18 +192,18 @@ fn reject_zero_crossings<n, m: usize>( } #[entry] -fn edge_detection<n, m, gs, sz, sb: usize>( +fn edge_detection<n, m : usize>( input: f32[n, m], gaussian_filter: f32[gs, gs], - structure: f32[sz, sz], - sx: f32[sb, sb], - sy: f32[sb, sb], + structure: f32[3, 3], + sx: f32[3, 3], + sy: f32[3, 3], theta: f32, ) -> f32[n, m] { - let smoothed = gaussian_smoothing::<n, m, gs>(input, gaussian_filter); - @le let laplacian = laplacian_estimate::<n, m, sz>(smoothed, structure); - @zc let zcs = zero_crossings::<n, m, sz>(laplacian, structure); - let gradient = gradient::<n, m, sb>(smoothed, sx, sy); + let smoothed = gaussian_smoothing::<n, m>(input, gaussian_filter); + @le let laplacian = laplacian_estimate::<n, m>(smoothed, structure); + @zc let zcs = zero_crossings::<n, m>(laplacian, structure); + let gradient = gradient::<n, m>(smoothed, sx, sy); let maxgrad = max_gradient::<n, m>(gradient); return reject_zero_crossings::<n, m>(zcs, gradient, maxgrad, theta); } diff --git a/juno_samples/edge_detection/src/lib.rs b/juno_samples/edge_detection/src/lib.rs index aa44e2e7e7215ee21560fefefc8c748610e183ce..c1d04b0f9a7b4950f9b8bf6ff6438b46291cb2f3 100644 --- a/juno_samples/edge_detection/src/lib.rs +++ b/juno_samples/edge_detection/src/lib.rs @@ -194,9 +194,6 @@ pub fn edge_detection_harness(args: EdgeDetectionInputs) { r.run( height as u64, width as u64, - gs as u64, - sz as u64, - sb as u64, input_h.to(), gaussian_filter_h.to(), structure_h.to(),