Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Versions {
const val COMPILE_SDK = 35
const val TARGET_SDK = 35
const val MIN_SDK = 21
const val NDK = "27.1.12297006" // r27b
const val NDK = "28.2.13676358" // r28c
const val CMAKE = "4.1.0"
val JAVA = JavaVersion.VERSION_1_8
}
17 changes: 9 additions & 8 deletions vectorization/src/main/cpp/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ Vec4 result;
* @return The average duration per call in nanoseconds.
*/
[[nodiscard, clang::noinline]] std::chrono::nanoseconds Benchmark(
Vec4& position, Mat4& translation,
std::function<Vec4(const Vec4&, const Mat4&)> func) {
Vec4<>& position, Mat4<>& translation,
std::function<Vec4<>(const Vec4<>&, const Mat4<>&)> func) {
// TODO: Move to a unit test.
auto test = func(position, translation);
auto expected = Vec4{{20, 10, 10, 1}};
Expand Down Expand Up @@ -82,11 +82,11 @@ BenchmarkMatrixMultiplication(Backend backend) {
switch (backend) {
case Backend::kAutoVectorization:
LOG(INFO) << "Benchmarking auto-vectorization";
return Benchmark(position, translation, [](Vec4 p, Mat4 t) {
return Benchmark(position, translation, [](Vec4<> p, Mat4<> t) {
return MultiplyWithAutoVectorization(t, p);
});
case Backend::kCxxSimd:
#if __NDK_MAJOR__ >= 28
#if __NDK_MAJOR__ >= 29
#error check if std::simd works yet
#endif
// The libc++ in NDK r27 has only a skeleton implementation of std::simd.
Expand All @@ -96,19 +96,20 @@ BenchmarkMatrixMultiplication(Backend backend) {
return std::unexpected{BenchmarkError::kNotImplemented};
case Backend::kClangVector:
LOG(INFO) << "Benchmarking Clang vectors";
return Benchmark(position, translation, [](Vec4 p, Mat4 t) {
return Benchmark(position, translation, [](Vec4<> p, Mat4<> t) {
return MultiplyWithClangVectors(t, p);
});
case Backend::kClangMatrix:
LOG(INFO) << "Benchmarking Clang matrices";
return Benchmark(position, translation, [](Vec4 p, Mat4 t) {
return Benchmark(position, translation, [](Vec4<> p, Mat4<> t) {
// This is the default implementation since it's the fastest.
return t * p;
});
case Backend::kOpenMp:
LOG(INFO) << "Benchmarking OpenMP SIMD";
return Benchmark(position, translation,
[](Vec4 p, Mat4 t) { return MultiplyWithOpenMP(t, p); });
return Benchmark(position, translation, [](Vec4<> p, Mat4<> t) {
return MultiplyWithOpenMP(t, p);
});
default:
return std::unexpected{BenchmarkError::kUnknownBackend};
}
Expand Down
10 changes: 5 additions & 5 deletions vectorization/src/main/cpp/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ class Matrix {
template <size_t Rows, size_t Columns, typename T>
Matrix(T (&&)[Rows][Columns]) -> Matrix<Rows, Columns, T>;

#if __NDK_MAJOR__ >= 28
#error "TODO: `template <typename T = float>` each of these"
#endif
using Mat4 = Matrix<4, 4>;
using Vec4 = Matrix<4, 1>;
template <typename T = float>
using Mat4 = Matrix<4, 4, T>;

template <typename T = float>
using Vec4 = Matrix<4, 1, T>;

} // namespace samples::vectorization