// SPDX-License-Identifier: MIT // Copyright (c) 2023, Advanced Micro Devices, Inc. All rights reserved. #include #include #include #include #include #include #include #include "profiler/profile_contraction_impl.hpp" using F32 = float; using F64 = double; using Row = ck::tensor_layout::gemm::RowMajor; using Col = ck::tensor_layout::gemm::ColumnMajor; using Bilinear = ck::tensor_operation::element_wise::Bilinear; using Scale = ck::tensor_operation::element_wise::Scale; struct MemoryParams { std::vector M; std::vector N; std::vector K; std::vector StridesA; std::vector StridesB; std::vector StridesC; std::vector StridesD; }; template class TestContraction : public ::testing::Test { protected: using ALayout = std::tuple_element_t<0, Tuple>; using BLayout = std::tuple_element_t<1, Tuple>; using CDLayout = std::tuple_element_t<2, Tuple>; using DataType = std::tuple_element_t<3, Tuple>; using DTupleDataType = std::tuple_element_t<4, Tuple>; using CDElementOp = std::tuple_element_t<5, Tuple>; std::vector list_of_memory_params = {{{32, 32}, {32, 32}, {32, 32}, {32768, 1024, 32, 1}, {32768, 1024, 32, 1}, {32768, 1024, 32, 1}, {32768, 1024, 32, 1}}, {{16, 16}, {32, 32}, {16, 16}, {4096, 256, 16, 1}, {16, 1, 8192, 256}, {16384, 1024, 32, 1}, {16384, 1024, 32, 1}}}; std::vector init_methods = {0, 1, 2}; std::unique_ptr p_cd_element_op; void Run() { for(auto& memory_params : list_of_memory_params) { for(const ck::index_t init_method : init_methods) { bool pass = ck::profiler::profile_contraction_impl(true /*do_verification*/, init_method, false /*do_logs*/, false /*time_kernel*/, *p_cd_element_op, memory_params.M, memory_params.N, memory_params.K, memory_params.StridesA, memory_params.StridesB, memory_params.StridesC, memory_params.StridesD); EXPECT_TRUE(pass); } } } }; template class TestContractionScale : public TestContraction { }; template class TestContractionBilinear : public TestContraction { }; using BilinearKernelTypes = ::testing::Types, Bilinear>, std::tuple, Bilinear>, std::tuple, Bilinear>, std::tuple, Bilinear>, std::tuple, Bilinear>, std::tuple, Bilinear>, std::tuple, Bilinear>, std::tuple, Bilinear>>; using ScaleKernelTypes = ::testing::Types, Scale>, std::tuple, Scale>, std::tuple, Scale>, std::tuple, Scale>, std::tuple, Scale>, std::tuple, Scale>, std::tuple, Scale>, std::tuple, Scale>>; TYPED_TEST_SUITE(TestContractionBilinear, BilinearKernelTypes); TYPED_TEST_SUITE(TestContractionScale, ScaleKernelTypes); TYPED_TEST(TestContractionBilinear, bilinear) { this->p_cd_element_op = std::make_unique(1.f, 1.f); this->Run(); this->p_cd_element_op = std::make_unique(-0.5f, 0.5f); this->Run(); } TYPED_TEST(TestContractionScale, scale) { this->p_cd_element_op = std::make_unique(1.f); this->Run(); this->p_cd_element_op = std::make_unique(0.5f); this->Run(); }