From 89f345d5fb1ea0883a4cd5d43bdb64c320239381 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Sun, 19 Aug 2018 12:13:55 +0200 Subject: [PATCH] Added perf tests --- test/perf/perf_matrix_div.cpp | 193 +++++++++++++-------------- test/perf/perf_matrix_mul.cpp | 99 ++++++++++++-- test/perf/perf_matrix_mul_vector.cpp | 159 ++++++++++++++++++++++ 3 files changed, 341 insertions(+), 110 deletions(-) create mode 100644 test/perf/perf_matrix_mul_vector.cpp diff --git a/test/perf/perf_matrix_div.cpp b/test/perf/perf_matrix_div.cpp index 72b1327d..913fc5d0 100644 --- a/test/perf/perf_matrix_div.cpp +++ b/test/perf/perf_matrix_div.cpp @@ -1,6 +1,8 @@ #define GLM_FORCE_INLINE #include +#include #include +#include #include #if GLM_CONFIG_SIMD == GLM_ENABLE #include @@ -8,145 +10,134 @@ #include #include -template -static void test_mat_mul_vec(matType const& M, std::vector const& I, std::vector& O) +template +static void test_mat_div_mat(matType const& M, std::vector const& I, std::vector& O) { for (std::size_t i = 0, n = I.size(); i < n; ++i) - O[i] = M * I[i]; + O[i] = M / I[i]; } -template -static int launch_mat_mul_vec(std::size_t Samples) +template +static int launch_mat_div_mat(std::vector& O, matType const& Transform, matType const& Scale, std::size_t Samples) { - typedef typename vecType::value_type T; - - static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + typedef typename matType::value_type T; - { - std::vector I(Samples); - std::vector O(Samples); + std::vector I(Samples); + O.resize(Samples); - for(std::size_t i = 0; i < Samples; ++i) - I[i] = vecType(static_cast(i)) * vecType(0.01, 0.02, 0.03, 0.05); + for(std::size_t i = 0; i < Samples; ++i) + I[i] = Scale * static_cast(i); - std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); - test_mat_mul_vec(Transform, I, O); - std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); + test_mat_div_mat(Transform, I, O); + std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); - return static_cast(std::chrono::duration_cast(t2 - t1).count()); - } + return static_cast(std::chrono::duration_cast(t2 - t1).count()); } -template -static void test_vec_mul_mat(matType const& M, std::vector const& I, std::vector& O) +template +static int comp_mat2_div_mat2(std::size_t Samples) { - for (std::size_t i = 0, n = I.size(); i < n; ++i) - O[i] = I[i] * M; -} + typedef typename packedMatType::value_type T; + + int Error = 0; -template -static int launch_vec_mul_mat(std::size_t Samples) -{ - typedef typename vecType::value_type T; + packedMatType const Transform(1, 2, 3, 4); + packedMatType const Scale(0.01, 0.02, 0.03, 0.05); - static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + std::vector SISD; + printf("- SISD: %d us\n", launch_mat_div_mat(SISD, Transform, Scale, Samples)); - std::vector I(Samples); - std::vector O(Samples); + std::vector SIMD; + printf("- SIMD: %d us\n", launch_mat_div_mat(SIMD, Transform, Scale, Samples)); for(std::size_t i = 0; i < Samples; ++i) - I[i] = vecType(static_cast(i)) * vecType(0.01, 0.02, 0.03, 0.05); - - std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); - test_vec_mul_mat(Transform, I, O); - std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); - - return static_cast(std::chrono::duration_cast(t2 - t1).count()); + { + packedMatType const A = SISD[i]; + packedMatType const B = SIMD[i]; + Error += glm::all(glm::equal(A, B, static_cast(0.001))) ? 0 : 1; + } + + return Error; } -template -static void test_mat_mul_mat(matType const& M, std::vector const& I, std::vector& O) +template +static int comp_mat3_div_mat3(std::size_t Samples) { - for (std::size_t i = 0, n = I.size(); i < n; ++i) - O[i] = M * I[i]; -} + typedef typename packedMatType::value_type T; + + int Error = 0; -template -static int launch_mat_mul_mat(std::size_t Samples) -{ - typedef typename matType::value_type T; + packedMatType const Transform(1, 2, 3, 4, 5, 6, 7, 8, 9); + packedMatType const Scale(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01); - static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + std::vector SISD; + printf("- SISD: %d us\n", launch_mat_div_mat(SISD, Transform, Scale, Samples)); - std::vector I(Samples); - std::vector O(Samples); + std::vector SIMD; + printf("- SIMD: %d us\n", launch_mat_div_mat(SIMD, Transform, Scale, Samples)); for(std::size_t i = 0; i < Samples; ++i) - I[i] = matType(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05) * static_cast(i); - - std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); - test_mat_mul_mat(Transform, I, O); - std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); - - return static_cast(std::chrono::duration_cast(t2 - t1).count()); -} - -template -static void test_mat_div_mat(matType const& M, std::vector const& I, std::vector& O) -{ - for (std::size_t i = 0, n = I.size(); i < n; ++i) - O[i] = M / I[i]; + { + packedMatType const A = SISD[i]; + packedMatType const B = SIMD[i]; + Error += glm::all(glm::equal(A, B, static_cast(0.001))) ? 0 : 1; + } + + return Error; } -template -static int launch_mat_div_mat(std::size_t Samples) +template +static int comp_mat4_div_mat4(std::size_t Samples) { - typedef typename matType::value_type T; + typedef typename packedMatType::value_type T; - static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + int Error = 0; - std::vector I(Samples); - std::vector O(Samples); + packedMatType const Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + packedMatType const Scale(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05); - for(std::size_t i = 0; i < Samples; ++i) - I[i] = matType(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05) * static_cast(i); + std::vector SISD; + printf("- SISD: %d us\n", launch_mat_div_mat(SISD, Transform, Scale, Samples)); - std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); - test_mat_div_mat(Transform, I, O); - std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + std::vector SIMD; + printf("- SIMD: %d us\n", launch_mat_div_mat(SIMD, Transform, Scale, Samples)); - return static_cast(std::chrono::duration_cast(t2 - t1).count()); + for(std::size_t i = 0; i < Samples; ++i) + { + packedMatType const A = SISD[i]; + packedMatType const B = SIMD[i]; + Error += glm::all(glm::equal(A, B, static_cast(0.001))) ? 0 : 1; + } + + return Error; } int main() { - std::size_t const Samples = 50000; - - printf("\nmat4 * vec4\n"); - printf("- dmat4 * dvec4 duration %d us\n", launch_mat_mul_vec(Samples)); - printf("- dmat4 * dvec4 (SIMD) duration %d us\n", launch_mat_mul_vec(Samples)); - printf("- mat4 * vec4 duration %d us\n", launch_mat_mul_vec(Samples)); - printf("- mat4 * vec4 (SIMD) duration %d us\n", launch_mat_mul_vec(Samples)); - - printf("\nvec4 * mat4\n"); - printf("- dvec4 * dmat4 duration %d us\n", launch_vec_mul_mat(Samples)); - printf("- dvec4 * dmat4 (SIMD) duration %d us\n", launch_vec_mul_mat(Samples)); - printf("- vec4 * mat4 duration %d us\n", launch_vec_mul_mat(Samples)); - printf("- vec4 * mat4 (SIMD) duration %d us\n", launch_vec_mul_mat(Samples)); - - printf("\nmat4 * mat4\n"); - printf("- dmat4 * dmat4 duration %d us\n", launch_mat_mul_mat(Samples)); - printf("- dmat4 * dmat4 (SIMD) duration %d us\n", launch_mat_mul_mat(Samples)); - printf("- mat4 * mat4 duration %d us\n", launch_mat_mul_mat(Samples)); - printf("- mat4 * mat4 (SIMD) duration %d us\n", launch_mat_mul_mat(Samples)); - - printf("\nmat4 / mat4\n"); - printf("- dmat4 / dmat4 duration %d us\n", launch_mat_div_mat(Samples)); - printf("- dmat4 / dmat4 (SIMD) duration %d us\n", launch_mat_div_mat(Samples)); - printf("- mat4 / mat4 duration %d us\n", launch_mat_div_mat(Samples)); - printf("- mat4 / mat4 (SIMD) duration %d us\n", launch_mat_div_mat(Samples)); + std::size_t const Samples = 100000; - return 0; + int Error = 0; + + printf("mat2 / mat2:\n"); + Error += comp_mat2_div_mat2(Samples); + + printf("dmat2 / dmat2:\n"); + Error += comp_mat2_div_mat2(Samples); + + printf("mat3 / mat3:\n"); + Error += comp_mat3_div_mat3(Samples); + + printf("dmat3 / dmat3:\n"); + Error += comp_mat3_div_mat3(Samples); + + printf("mat4 / mat4:\n"); + Error += comp_mat4_div_mat4(Samples); + + printf("dmat4 / dmat4:\n"); + Error += comp_mat4_div_mat4(Samples); + + return Error; } #else diff --git a/test/perf/perf_matrix_mul.cpp b/test/perf/perf_matrix_mul.cpp index 7c57b7ec..61c8674a 100644 --- a/test/perf/perf_matrix_mul.cpp +++ b/test/perf/perf_matrix_mul.cpp @@ -1,5 +1,10 @@ #define GLM_FORCE_INLINE +#include +#include +#include +#include #include +#include #include #include #include @@ -34,22 +39,81 @@ static int launch_mat_mul_mat(std::vector& O, matType const& Transform, return static_cast(std::chrono::duration_cast(t2 - t1).count()); } -static int comp_mat_mul_mat(std::size_t Samples) +template +static int comp_mat2_mul_mat2(std::size_t Samples) { + typedef typename packedMatType::value_type T; + int Error = 0; - glm::mat4 const Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); - glm::mat4 const Scale(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05); + packedMatType const Transform(1, 2, 3, 4); + packedMatType const Scale(0.01, 0.02, 0.03, 0.05); - std::vector Mat4SISD; - printf("mat4 * mat4 (SISD) duration %d us\n", launch_mat_mul_mat(Mat4SISD, Transform, Scale, Samples)); + std::vector SISD; + printf("- SISD: %d us\n", launch_mat_mul_mat(SISD, Transform, Scale, Samples)); - std::vector Mat4SIMD; - printf("mat4 * mat4 (SIMD) duration %d us\n", launch_mat_mul_mat(Mat4SIMD, Transform, Scale, Samples)); + std::vector SIMD; + printf("- SIMD: %d us\n", launch_mat_mul_mat(SIMD, Transform, Scale, Samples)); for(std::size_t i = 0; i < Samples; ++i) - Error += glm::all(glm::equal(Mat4SISD[i], Mat4SIMD[i], 0.001)) ? 0 : 1; + { + packedMatType const A = SISD[i]; + packedMatType const B = SIMD[i]; + Error += glm::all(glm::equal(A, B, static_cast(0.001))) ? 0 : 1; + } + + return Error; +} + +template +static int comp_mat3_mul_mat3(std::size_t Samples) +{ + typedef typename packedMatType::value_type T; + + int Error = 0; + + packedMatType const Transform(1, 2, 3, 4, 5, 6, 7, 8, 9); + packedMatType const Scale(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01); + + std::vector SISD; + printf("- SISD: %d us\n", launch_mat_mul_mat(SISD, Transform, Scale, Samples)); + + std::vector SIMD; + printf("- SIMD: %d us\n", launch_mat_mul_mat(SIMD, Transform, Scale, Samples)); + + for(std::size_t i = 0; i < Samples; ++i) + { + packedMatType const A = SISD[i]; + packedMatType const B = SIMD[i]; + Error += glm::all(glm::equal(A, B, static_cast(0.001))) ? 0 : 1; + } + + return Error; +} + +template +static int comp_mat4_mul_mat4(std::size_t Samples) +{ + typedef typename packedMatType::value_type T; + + int Error = 0; + packedMatType const Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + packedMatType const Scale(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05); + + std::vector SISD; + printf("- SISD: %d us\n", launch_mat_mul_mat(SISD, Transform, Scale, Samples)); + + std::vector SIMD; + printf("- SIMD: %d us\n", launch_mat_mul_mat(SIMD, Transform, Scale, Samples)); + + for(std::size_t i = 0; i < Samples; ++i) + { + packedMatType const A = SISD[i]; + packedMatType const B = SIMD[i]; + Error += glm::all(glm::equal(A, B, static_cast(0.001))) ? 0 : 1; + } + return Error; } @@ -58,7 +122,24 @@ int main() std::size_t const Samples = 100000; int Error = 0; - Error += comp_mat_mul_mat(Samples); + + printf("mat2 * mat2:\n"); + Error += comp_mat2_mul_mat2(Samples); + + printf("dmat2 * dmat2:\n"); + Error += comp_mat2_mul_mat2(Samples); + + printf("mat3 * mat3:\n"); + Error += comp_mat3_mul_mat3(Samples); + + printf("dmat3 * dmat3:\n"); + Error += comp_mat3_mul_mat3(Samples); + + printf("mat4 * mat4:\n"); + Error += comp_mat4_mul_mat4(Samples); + + printf("dmat4 * dmat4:\n"); + Error += comp_mat4_mul_mat4(Samples); return Error; } diff --git a/test/perf/perf_matrix_mul_vector.cpp b/test/perf/perf_matrix_mul_vector.cpp new file mode 100644 index 00000000..72b1327d --- /dev/null +++ b/test/perf/perf_matrix_mul_vector.cpp @@ -0,0 +1,159 @@ +#define GLM_FORCE_INLINE +#include +#include +#include +#if GLM_CONFIG_SIMD == GLM_ENABLE +#include +#include +#include +#include + +template +static void test_mat_mul_vec(matType const& M, std::vector const& I, std::vector& O) +{ + for (std::size_t i = 0, n = I.size(); i < n; ++i) + O[i] = M * I[i]; +} + +template +static int launch_mat_mul_vec(std::size_t Samples) +{ + typedef typename vecType::value_type T; + + static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + { + std::vector I(Samples); + std::vector O(Samples); + + for(std::size_t i = 0; i < Samples; ++i) + I[i] = vecType(static_cast(i)) * vecType(0.01, 0.02, 0.03, 0.05); + + std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); + test_mat_mul_vec(Transform, I, O); + std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + + return static_cast(std::chrono::duration_cast(t2 - t1).count()); + } +} + +template +static void test_vec_mul_mat(matType const& M, std::vector const& I, std::vector& O) +{ + for (std::size_t i = 0, n = I.size(); i < n; ++i) + O[i] = I[i] * M; +} + +template +static int launch_vec_mul_mat(std::size_t Samples) +{ + typedef typename vecType::value_type T; + + static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + std::vector I(Samples); + std::vector O(Samples); + + for(std::size_t i = 0; i < Samples; ++i) + I[i] = vecType(static_cast(i)) * vecType(0.01, 0.02, 0.03, 0.05); + + std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); + test_vec_mul_mat(Transform, I, O); + std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + + return static_cast(std::chrono::duration_cast(t2 - t1).count()); +} + +template +static void test_mat_mul_mat(matType const& M, std::vector const& I, std::vector& O) +{ + for (std::size_t i = 0, n = I.size(); i < n; ++i) + O[i] = M * I[i]; +} + +template +static int launch_mat_mul_mat(std::size_t Samples) +{ + typedef typename matType::value_type T; + + static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + std::vector I(Samples); + std::vector O(Samples); + + for(std::size_t i = 0; i < Samples; ++i) + I[i] = matType(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05) * static_cast(i); + + std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); + test_mat_mul_mat(Transform, I, O); + std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + + return static_cast(std::chrono::duration_cast(t2 - t1).count()); +} + +template +static void test_mat_div_mat(matType const& M, std::vector const& I, std::vector& O) +{ + for (std::size_t i = 0, n = I.size(); i < n; ++i) + O[i] = M / I[i]; +} + +template +static int launch_mat_div_mat(std::size_t Samples) +{ + typedef typename matType::value_type T; + + static const matType Transform(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); + + std::vector I(Samples); + std::vector O(Samples); + + for(std::size_t i = 0; i < Samples; ++i) + I[i] = matType(0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05, 0.01, 0.02, 0.03, 0.05) * static_cast(i); + + std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); + test_mat_div_mat(Transform, I, O); + std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + + return static_cast(std::chrono::duration_cast(t2 - t1).count()); +} + +int main() +{ + std::size_t const Samples = 50000; + + printf("\nmat4 * vec4\n"); + printf("- dmat4 * dvec4 duration %d us\n", launch_mat_mul_vec(Samples)); + printf("- dmat4 * dvec4 (SIMD) duration %d us\n", launch_mat_mul_vec(Samples)); + printf("- mat4 * vec4 duration %d us\n", launch_mat_mul_vec(Samples)); + printf("- mat4 * vec4 (SIMD) duration %d us\n", launch_mat_mul_vec(Samples)); + + printf("\nvec4 * mat4\n"); + printf("- dvec4 * dmat4 duration %d us\n", launch_vec_mul_mat(Samples)); + printf("- dvec4 * dmat4 (SIMD) duration %d us\n", launch_vec_mul_mat(Samples)); + printf("- vec4 * mat4 duration %d us\n", launch_vec_mul_mat(Samples)); + printf("- vec4 * mat4 (SIMD) duration %d us\n", launch_vec_mul_mat(Samples)); + + printf("\nmat4 * mat4\n"); + printf("- dmat4 * dmat4 duration %d us\n", launch_mat_mul_mat(Samples)); + printf("- dmat4 * dmat4 (SIMD) duration %d us\n", launch_mat_mul_mat(Samples)); + printf("- mat4 * mat4 duration %d us\n", launch_mat_mul_mat(Samples)); + printf("- mat4 * mat4 (SIMD) duration %d us\n", launch_mat_mul_mat(Samples)); + + printf("\nmat4 / mat4\n"); + printf("- dmat4 / dmat4 duration %d us\n", launch_mat_div_mat(Samples)); + printf("- dmat4 / dmat4 (SIMD) duration %d us\n", launch_mat_div_mat(Samples)); + printf("- mat4 / mat4 duration %d us\n", launch_mat_div_mat(Samples)); + printf("- mat4 / mat4 (SIMD) duration %d us\n", launch_mat_div_mat(Samples)); + + return 0; +} + +#else + +int main() +{ + return 0; +} + +#endif