Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia #14

Merged
merged 4 commits into from
Feb 7, 2024
Merged

Julia #14

merged 4 commits into from
Feb 7, 2024

Conversation

IgorErin
Copy link

@IgorErin IgorErin commented Feb 6, 2024

Done:

  • host ref x86
  • halide naive

src/julia.cpp Outdated Show resolved Hide resolved
test/test_main.cpp Outdated Show resolved Hide resolved
test/test_main.cpp Outdated Show resolved Hide resolved
CMakeLists.txt Outdated
@@ -114,6 +114,7 @@ add_executable(test_algo ${PERF_SOURCES})
target_link_libraries(test_algo
algos
"${binary_dir}/lib/libopencv_ts.a"
"${binary_dir}/lib/libopencv_imgcodecs.so"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "${binary_dir}/install/lib/libopencv_imgcodecs.so" to target_link_libraries(algos instead:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -92,6 +92,7 @@ target_include_directories(algos PRIVATE
 target_link_libraries(algos
   "${binary_dir}/install/lib/libopencv_core.so"
   "${binary_dir}/install/lib/libopencv_imgproc.so"
+  "${binary_dir}/install/lib/libopencv_imgcodecs.so"
 )

@IgorErin
Copy link
Author

IgorErin commented Feb 6, 2024

@dkurt Добавил наивную реализацю на halide. На моем x86 работает заметно медленнее референсной. Cейчас буду мерить, заодно подготовлю бенчмарки на завтра. Или есть задачи актуальнее?

Стала ли лучше картинка?

@dkurt
Copy link
Owner

dkurt commented Feb 6, 2024

@IgorErin, да, всё супер! Если увеличить julia_width/julia_height то побольше картинка, всё рисует правильно. Да, пока медленнее референс части, но предлагаю сейчас PR довести до зелёного состояния и мерджить, работа сделана уже большая.

src/julia.cpp Show resolved Hide resolved
src/julia.cpp Outdated
Comment on lines 59 to 92
void halide_julia(uint8_t* dst, int height, int width) {
static const uint8_t step_bound = 255;
static const uint8_t upper_bound = 4;

Buffer output(dst, width, height);

Var x, y;

Complex c(cr, ci);

Expr x_ranged;
x_ranged = halide_julia_norm(x, height);

Expr y_ranged;
y_ranged = halide_julia_norm(y, width);

Func julia;
Var t;
julia(x, y, t) = Complex(x_ranged, y_ranged);

// loop
RDom index(1, step_bound);
Complex current = julia(x, y, index - 1);
julia(x, y, index) = current * current + c;

Expr esc_cond = Complex(julia(x, y, index)).magnitude_squared() < upper_bound;
Tuple first_escape = argmin(esc_cond);

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

result.realize(output);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void halide_julia(uint8_t* dst, int height, int width) {
static const uint8_t step_bound = 255;
static const uint8_t upper_bound = 4;
Buffer output(dst, width, height);
Var x, y;
Complex c(cr, ci);
Expr x_ranged;
x_ranged = halide_julia_norm(x, height);
Expr y_ranged;
y_ranged = halide_julia_norm(y, width);
Func julia;
Var t;
julia(x, y, t) = Complex(x_ranged, y_ranged);
// loop
RDom index(1, step_bound);
Complex current = julia(x, y, index - 1);
julia(x, y, index) = current * current + c;
Expr esc_cond = Complex(julia(x, y, index)).magnitude_squared() < upper_bound;
Tuple first_escape = argmin(esc_cond);
// proj to result
Func result;
result(x, y) = cast<uint8_t>(first_escape[0]);
result.realize(output);
}
void halide_julia(uint8_t* dst, int height, int width) {
#ifdef __riscv
// add later
#else
static const uint8_t step_bound = 255;
static const uint8_t upper_bound = 4;
Buffer output(dst, width, height);
Var x, y;
Complex c(cr, ci);
Expr x_ranged;
x_ranged = halide_julia_norm(x, height);
Expr y_ranged;
y_ranged = halide_julia_norm(y, width);
Func julia;
Var t;
julia(x, y, t) = Complex(x_ranged, y_ranged);
// loop
RDom index(1, step_bound);
Complex current = julia(x, y, index - 1);
julia(x, y, index) = current * current + c;
Expr esc_cond = Complex(julia(x, y, index)).magnitude_squared() < upper_bound;
Tuple first_escape = argmin(esc_cond);
// proj to result
Func result;
result(x, y) = cast<uint8_t>(first_escape[0]);
result.realize(output);
#endif
}

@IgorErin IgorErin requested a review from dkurt February 6, 2024 22:37
@dkurt dkurt merged commit cb37f84 into dkurt:main Feb 7, 2024
2 checks passed
@dkurt dkurt mentioned this pull request Feb 7, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants