Debian Codegraph @

packages/kokkos-kernels/perf_test/blas/blas3/KokkosBlas3_gemm_tracked_perf_test.cpp

raw
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16
17 #include <Kokkos_Core.hpp>
18 #include <KokkosBlas3_gemm.hpp>
19 #include <Kokkos_Random.hpp>
20
21 // Required for tracked_testing version
22 #include "KokkosBlas3_gemm_tracked_perf_test.hpp"
23
24 #ifdef KOKKOSKERNELS_ENABLE_TESTS_AND_PERFSUITE
25 #include <PerfTestUtilities.hpp>
26 #endif
27
28 // API ref for "General Matrix Multiplication" (gemm)
29 // https://github.com/kokkos/kokkos-kernels/wiki/BLAS-3%3A%3Agemm
30
31 // Usage: KokkosBlas::gemm(modeA, modeB, alpha, A, B, beta, C);
32 /*
33 * transA [in] "N" for non-transpose, "T" for transpose,
34 * "C" for conjugate transpose.
35 * All characters after the first are ignored. This works just like the BLAS
36 routines.
37 *
38 * transB [in] "N" for non-transpose,
39 * "T" for transpose,
40 * "C" for conjugate transpose.
41 * All characters after the first are ignored. This works just like the BLAS
42 routines.
43
44 * alpha [in] Input coefficient of A*x
45 * A [in] Input matrix, as a 2-D Kokkos::View
46 * B [in] Input matrix, as a 2-D Kokkos::View
47 * beta [in] Input coefficient of C
48 * C [in/out] Output vector, as a nonconst 2-D Kokkos::View
49
50 */
51
52 // Define setup_test
53 template <class ExecSpace, class ALayout, class BLayout>
54 testData_gemm<ExecSpace, ALayout, BLayout> setup_test(int m, int n, int k, int repeat) {
55 testData_gemm<ExecSpace, ALayout, BLayout> testData_gemm_obj(m, n, k, repeat);
56
57 return testData_gemm_obj;
58 }
59
60 test_list construct_gemm_kernel_base(const rajaperf::RunParams& run_params, const std::vector<gemmConfig>& m_n_k_vect)
61
62 {
63 // instantiate kernel_base_vector as type test_list
64 // kernel_base_vector will contain which tests to run, and data to run them
65 test_list kernel_base_vector;
66
67 for (const auto& value : m_n_k_vect) {
68 kernel_base_vector.push_back(rajaperf::make_kernel_base(
69 "BLAS3_GEMM_" + std::to_string(value.m) + "_" + std::to_string(value.n) + "_" + std::to_string(value.k),
70 run_params,
71 // setup_test lambda captures by value;
72 // Mapping Kokkos features to RAJAPerf Suite
73 // repeat = runreps (RAJAPerf Suite)
74 // m = getActualRunSize() (RAJAPerf Suite)
75 [=](const int repeat, const int) {
76 // returns a tuple of testData objects
77 return std::make_tuple(
78 // setup_test is templated on ExecSpace and Layout
79 setup_test<Kokkos::DefaultExecutionSpace, Kokkos::DefaultExecutionSpace::array_layout,
80 Kokkos::DefaultExecutionSpace::array_layout>(value.m, value.n, value.k, repeat));
81 },
82 // the run lambda will capture the returned setup_test tuple by
83 // reference
84 [&](const int iteration, const int runsize, auto& data) {
85 // KokkosBlas::gemm(modeA, modeB, alpha, A, B, beta, C);
86 KokkosBlas::gemm("N", "N", 1.0, data.A, data.B, 0.0, data.C);
87 }));
88 }
89
90 // return a vector of kernel base objects of type test_list
91 return kernel_base_vector;
92 }