// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "test_util.h" template class MlasTransposeTest : public MlasTestBase { private: MatrixGuardBuffer BufferInput; MatrixGuardBuffer BufferOutput; MatrixGuardBuffer BufferOutputReference; MLAS_THREADPOOL* threadpool_; void Test(size_t M, size_t N) { ElementType* Input = BufferInput.GetBuffer(M * N); ElementType* Output = BufferOutput.GetBuffer(M * N); ElementType* OutputReference = BufferOutputReference.GetBuffer(M * N); MlasTranspose(Input, Output, M, N, threadpool_); ReferenceTranspose(Input, OutputReference, M, N); ASSERT_EQ(memcmp(Output, OutputReference, M * N * sizeof(ElementType)), 0) << " [" << M << "," << N << "]"; } void ReferenceTranspose(const ElementType* Input, ElementType* Output, size_t M, size_t N) { for (size_t m = 0; m < M; m++) { for (size_t n = 0; n < N; n++) { Output[n * M + m] = Input[m * N + n]; } } } public: MlasTransposeTest() : threadpool_(Threaded ? GetMlasThreadPool() : nullptr) {} static const char* GetTestSuiteName() { static const std::string suite_name = std::string("Transpose_") + GetTypeString() + std::string(Threaded ? "_Threaded" : "_SingleThread"); return suite_name.c_str(); } static const std::string GetTypeString() { if (std::is_same::value) return std::string("FP32"); if (std::is_same::value) return std::string("U32"); if (std::is_same::value) return std::string("U16"); if (std::is_same::value) return std::string("U8"); return std::string("unknown"); } void ExecuteShort(void) override { for (size_t m = 1; m <= 32; m++) { for (size_t n = 1; n <= 32; n++) { Test(m, n); } } } }; static UNUSED_VARIABLE bool added_to_main = AddTestRegister([](bool is_short_execute) { size_t count = 0; if (is_short_execute) { count += MlasDirectShortExecuteTests>::RegisterShortExecute(); count += MlasDirectShortExecuteTests>::RegisterShortExecute(); count += MlasDirectShortExecuteTests>::RegisterShortExecute(); count += MlasDirectShortExecuteTests>::RegisterShortExecute(); count += MlasDirectShortExecuteTests>::RegisterShortExecute(); count += MlasDirectShortExecuteTests>::RegisterShortExecute(); count += MlasDirectShortExecuteTests>::RegisterShortExecute(); count += MlasDirectShortExecuteTests>::RegisterShortExecute(); } return count; });