#include "ijk.h" #include #include #include #include #include #include #include #include template void test_type(F &f) { T a[N][N], b[N][N], c[N][N]; for (size_t i = 0; i < N; ++i) for (size_t j = 0; j < N; ++j) { a[i][j] = 0; b[i][j] = B; c[i][j] = C; } const size_t R = 33; std::chrono::duration rep[R]; for (auto &r : rep) { auto start = std::chrono::high_resolution_clock::now(); f(a, b, c); auto stop = std::chrono::high_resolution_clock::now(); r = stop - start; } std::nth_element(rep, rep + R / 2, rep + R); std::cout << std::fixed << std::setprecision(2) << std::setw(8) << rep[R / 2].count(); if constexpr (std::is_integral_v) assert(a[N - 1][N - 1] == T(B * C * N * R)); }; #define test_function(f) \ std::cout << std::setw(8) << #f; \ test_type(f); \ test_type(f); \ test_type(f); \ test_type(f); \ test_type(f); \ test_type(f); \ test_type(f); \ test_type(f); \ test_type(f); \ std::cout << std::endl; int32_t main() { const char *types[] = {"(ms)", "int8", "int16", "int32", "int64", "bfloa16", "float16", "float32", "float64", "floa128"}; for (auto &i : types) std::cout << std::setw(8) << i; std::cout << std::endl; for (size_t i = 0; i < sizeof(types) / sizeof(char *); ++i) std::cout << std::setw(8) << "-------"; std::cout << std::endl; test_function(ijk); test_function(ikj); test_function(jik); test_function(jki); test_function(kij); test_function(kji); }