-
Notifications
You must be signed in to change notification settings - Fork 1
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
Bench against vcl and optimize #5
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ad76363
bench against VCL
NamorNiradnug 437b5cc
optimize sin/cos and bechmarks
NamorNiradnug 619e148
remove _f32 suffix from name of a function
NamorNiradnug 1a688d8
optimize round()
NamorNiradnug 361155c
change cpp benches naming
NamorNiradnug 781df50
speedup quadratic poly
NamorNiradnug cc5d221
add more benchmarks; remove `core::simd` benchmarks
NamorNiradnug 5900378
optimize `round` in exp; optimize vecsize in benchmarks
NamorNiradnug 9312201
refactor benchmarks; add vcl and libmvec f64 benchmarks
NamorNiradnug 3965b7e
add python script to format benchmark output; remove unneeded compile…
NamorNiradnug 72f6ea7
fix `Linspace`
NamorNiradnug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "benches/vcl"] | ||
path = benches/cpp/vcl | ||
url = https://github.com/vectorclass/version2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
#include <cstddef> | ||
|
||
using f32 = float; | ||
using f64 = double; | ||
|
||
static constexpr size_t BENCH_POINTS = 200'000; | ||
|
||
template <class X> | ||
using Func = X (*)(X); | ||
|
||
#define CPP_BENCH_FUNC_NAME(func, ftype, suffix) func##_##ftype##_##suffix | ||
|
||
#define CPP_BENCH_FUNC_DECL(func, ftype, suffix) \ | ||
void CPP_BENCH_FUNC_NAME(func, ftype, suffix)(const ftype *__restrict__ x, ftype *__restrict__ result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "libmvecbench.hpp" | ||
|
||
#include <cmath> | ||
|
||
namespace { | ||
template <class T, Func<T> func> | ||
void libmvec_bench_impl(const T *__restrict__ x, T *__restrict__ result) { | ||
for (size_t i = 0; i < BENCH_POINTS; ++i) { | ||
result[i] = func(x[i]); | ||
} | ||
} | ||
} // namespace | ||
|
||
namespace bench { | ||
#define IMPL_LIBMVEC_BENCHES(func) \ | ||
CPP_BENCH_FUNC_DECL(func, f32, libmvec) { libmvec_bench_impl<f32, func##f>(x, result); } \ | ||
CPP_BENCH_FUNC_DECL(func, f64, libmvec) { libmvec_bench_impl<f64, func>(x, result); } | ||
|
||
IMPL_LIBMVEC_BENCHES(exp) | ||
IMPL_LIBMVEC_BENCHES(exp2) | ||
CPP_BENCH_FUNC_DECL(exp_m1, f32, libmvec) { libmvec_bench_impl<f32, expm1f>(x, result); } | ||
CPP_BENCH_FUNC_DECL(exp_m1, f64, libmvec) { libmvec_bench_impl<f64, expm1>(x, result); } | ||
|
||
IMPL_LIBMVEC_BENCHES(sin) | ||
IMPL_LIBMVEC_BENCHES(cos) | ||
IMPL_LIBMVEC_BENCHES(tan) | ||
IMPL_LIBMVEC_BENCHES(asin) | ||
IMPL_LIBMVEC_BENCHES(acos) | ||
IMPL_LIBMVEC_BENCHES(atan) | ||
|
||
#undef IMPL_LIBMVEC_BENCHES | ||
} // namespace benches |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "cppbench.hpp" | ||
|
||
namespace bench { | ||
#define DEF_VECLIB_BENCHES(func) \ | ||
CPP_BENCH_FUNC_DECL(func, f32, libmvec); \ | ||
CPP_BENCH_FUNC_DECL(func, f64, libmvec); | ||
|
||
DEF_VECLIB_BENCHES(exp) | ||
DEF_VECLIB_BENCHES(exp2) | ||
DEF_VECLIB_BENCHES(exp_m1) | ||
DEF_VECLIB_BENCHES(sin) | ||
DEF_VECLIB_BENCHES(cos) | ||
DEF_VECLIB_BENCHES(tan) | ||
DEF_VECLIB_BENCHES(asin) | ||
DEF_VECLIB_BENCHES(acos) | ||
DEF_VECLIB_BENCHES(atan) | ||
|
||
#undef DEF_VECLIB_BENCHES | ||
} // namespace bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#[cxx::bridge(namespace = "bench")] | ||
pub mod ffi { | ||
unsafe extern "C++" { | ||
include!("portable-simd-addons/benches/cpp/libmvecbench.hpp"); | ||
|
||
unsafe fn exp_f32_libmvec(x: *const f32, result: *mut f32); | ||
unsafe fn exp2_f32_libmvec(x: *const f32, result: *mut f32); | ||
unsafe fn exp_m1_f32_libmvec(x: *const f32, result: *mut f32); | ||
|
||
unsafe fn sin_f32_libmvec(x: *const f32, result: *mut f32); | ||
unsafe fn cos_f32_libmvec(x: *const f32, result: *mut f32); | ||
unsafe fn tan_f32_libmvec(x: *const f32, result: *mut f32); | ||
|
||
unsafe fn asin_f32_libmvec(x: *const f32, result: *mut f32); | ||
unsafe fn acos_f32_libmvec(x: *const f32, result: *mut f32); | ||
unsafe fn atan_f32_libmvec(x: *const f32, result: *mut f32); | ||
|
||
unsafe fn exp_f64_libmvec(x: *const f64, result: *mut f64); | ||
unsafe fn exp2_f64_libmvec(x: *const f64, result: *mut f64); | ||
unsafe fn exp_m1_f64_libmvec(x: *const f64, result: *mut f64); | ||
|
||
unsafe fn sin_f64_libmvec(x: *const f64, result: *mut f64); | ||
unsafe fn cos_f64_libmvec(x: *const f64, result: *mut f64); | ||
unsafe fn tan_f64_libmvec(x: *const f64, result: *mut f64); | ||
|
||
unsafe fn asin_f64_libmvec(x: *const f64, result: *mut f64); | ||
unsafe fn acos_f64_libmvec(x: *const f64, result: *mut f64); | ||
unsafe fn atan_f64_libmvec(x: *const f64, result: *mut f64); | ||
} | ||
} | ||
|
||
pub use ffi::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "vclbench.hpp" | ||
|
||
#define VCL_NAMESPACE vcl | ||
#include "vcl/vectormath_exp.h" | ||
#include "vcl/vectormath_trig.h" | ||
|
||
namespace { | ||
template <class Scalar, class Vec, Func<Vec> func> | ||
void vcl_bench_impl(const Scalar *__restrict__ x, Scalar *__restrict__ result) { | ||
Vec x_vec; | ||
for (size_t i = 0; i < BENCH_POINTS; i += Vec::size()) { | ||
x_vec.load(x + i); | ||
func(x_vec).store(result + i); | ||
} | ||
} | ||
} // namespace | ||
|
||
namespace bench { | ||
#define IMPL_VCL_BECHES(func) \ | ||
CPP_BENCH_FUNC_DECL(func, f32, vcl) { vcl_bench_impl<f32, vcl::Vec16f, vcl::func>(x, result); } \ | ||
CPP_BENCH_FUNC_DECL(func, f64, vcl) { vcl_bench_impl<f64, vcl::Vec8d, vcl::func>(x, result); } | ||
|
||
IMPL_VCL_BECHES(exp) | ||
IMPL_VCL_BECHES(exp2) | ||
CPP_BENCH_FUNC_DECL(exp_m1, f32, vcl) { vcl_bench_impl<f32, vcl::Vec16f, vcl::expm1>(x, result); } | ||
CPP_BENCH_FUNC_DECL(exp_m1, f64, vcl) { vcl_bench_impl<f64, vcl::Vec8d, vcl::expm1>(x, result); } | ||
|
||
IMPL_VCL_BECHES(sin) | ||
IMPL_VCL_BECHES(cos) | ||
IMPL_VCL_BECHES(tan) | ||
IMPL_VCL_BECHES(asin) | ||
IMPL_VCL_BECHES(acos) | ||
IMPL_VCL_BECHES(atan) | ||
|
||
void atan2_f32_vcl(const float *x, const float *y, float *result) { | ||
vcl::Vec16f x_vec; | ||
vcl::Vec16f y_vec; | ||
for (size_t i = 0; i < BENCH_POINTS; i += vcl::Vec16f::size()) { | ||
x_vec.load(x + i); | ||
y_vec.load(y + i); | ||
vcl::atan2(y_vec, x_vec).store(result + i); | ||
} | ||
} | ||
|
||
#undef IMPL_VCL_BECHES | ||
} // namespace bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include "cppbench.hpp" | ||
|
||
namespace bench { | ||
#define DEF_VCL_BENCHES(func) \ | ||
CPP_BENCH_FUNC_DECL(func, f32, vcl); \ | ||
CPP_BENCH_FUNC_DECL(func, f64, vcl); | ||
|
||
DEF_VCL_BENCHES(exp) | ||
DEF_VCL_BENCHES(exp2) | ||
DEF_VCL_BENCHES(exp_m1) | ||
DEF_VCL_BENCHES(sin) | ||
DEF_VCL_BENCHES(cos) | ||
DEF_VCL_BENCHES(tan) | ||
DEF_VCL_BENCHES(asin) | ||
DEF_VCL_BENCHES(acos) | ||
DEF_VCL_BENCHES(atan) | ||
|
||
#undef DEF_VCL_BENCHES | ||
} // namespace bench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#[cfg(all(not(target_arch = "x86"), not(target_arch = "x86_64")))] | ||
compile_error!("VCL supports only x86-compatible platforms"); | ||
|
||
#[cxx::bridge(namespace = "bench")] | ||
pub mod ffi { | ||
unsafe extern "C++" { | ||
include!("portable-simd-addons/benches/cpp/vclbench.hpp"); | ||
|
||
unsafe fn exp_f32_vcl(x: *const f32, result: *mut f32); | ||
unsafe fn exp2_f32_vcl(x: *const f32, result: *mut f32); | ||
unsafe fn exp_m1_f32_vcl(x: *const f32, result: *mut f32); | ||
|
||
unsafe fn sin_f32_vcl(x: *const f32, result: *mut f32); | ||
unsafe fn cos_f32_vcl(x: *const f32, result: *mut f32); | ||
unsafe fn tan_f32_vcl(x: *const f32, result: *mut f32); | ||
|
||
unsafe fn asin_f32_vcl(x: *const f32, result: *mut f32); | ||
unsafe fn acos_f32_vcl(x: *const f32, result: *mut f32); | ||
unsafe fn atan_f32_vcl(x: *const f32, result: *mut f32); | ||
|
||
unsafe fn exp_f64_vcl(x: *const f64, result: *mut f64); | ||
unsafe fn exp2_f64_vcl(x: *const f64, result: *mut f64); | ||
unsafe fn exp_m1_f64_vcl(x: *const f64, result: *mut f64); | ||
|
||
unsafe fn sin_f64_vcl(x: *const f64, result: *mut f64); | ||
unsafe fn cos_f64_vcl(x: *const f64, result: *mut f64); | ||
unsafe fn tan_f64_vcl(x: *const f64, result: *mut f64); | ||
|
||
unsafe fn asin_f64_vcl(x: *const f64, result: *mut f64); | ||
unsafe fn acos_f64_vcl(x: *const f64, result: *mut f64); | ||
unsafe fn atan_f64_vcl(x: *const f64, result: *mut f64); | ||
} | ||
} | ||
|
||
pub use ffi::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А в этом макросе нигде не надо
black_box
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут как раз важно, что оно не
black_box
, т.к. это ломает оптимизации. Там даже удалениеassert
-а замедляет бенчмарк.Наверное можно в
black_box
засунуть сразу весь слайс типа такого:но кажется это не должно ничего поменять (я попробую).