Skip to content

Commit

Permalink
refactor: parallel (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorErin committed Feb 8, 2024
1 parent 14b850d commit beb96ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/julia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ static const float cr = 0.0;
static const uint8_t step_bound = 255;
static const uint8_t upper_bound = 4;

static const int parallel_factor = 4;
static const int vector_factor = 4;

// no Expr type in riscv build
#ifndef __riscv
// src :: Int -> fraction :: Float -> Float
Expand Down Expand Up @@ -67,7 +70,6 @@ void halide_julia(uint8_t* dst, int height, int width) {
halide_julia_rv(output);
#else
static Func julia("julia");
static const int vector_factor = 16;

if (!julia.defined()) {
Var x, y;
Expand All @@ -91,12 +93,18 @@ void halide_julia(uint8_t* dst, int height, int width) {
Expr esc_cond = HComplex(julia(x, y, index)).magnitude_squared() < upper_bound;
Tuple first_escape = argmin(esc_cond);

julia.update(0).vectorize(x, 4);

// proj to result
Func result;
result(x, y) = cast<uint8_t>(first_escape[0]);

julia.compute_at(result, y);
julia.update(0).vectorize(x, 4);
Var yi, yo;
result.split(y, yo, yi, parallel_factor);
result.parallel(yo);

julia.store_at(result, yo);
julia.compute_at(result, yi);

Target target;
target.os = Target::OS::Linux;
Expand Down
2 changes: 1 addition & 1 deletion test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST(convolution_nhwc, halide) {


TEST(idw, halide) {
Mat src(height, width, CV_8U);
Mat src(height, width, CV_8U);
Mat dst(height, width, CV_8U), cl_dst(height, width, CV_8UC3), dst_h(height, width, CV_8U), cl_dst_h(height, width, CV_8UC3);
// randu(src, 0, 256);

Expand Down

0 comments on commit beb96ce

Please sign in to comment.