| 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 |
// This file is for the "tracked test" version of |
| 18 |
// a Kokkos Kernels performance test. |
| 19 |
// Created by David Poliakoff and Amy Powell on 9/22/2021 |
| 20 |
|
| 21 |
#ifndef KOKKOSKERNELS_KOKKOSBLAS_GEMM_TEST_RPS_HPP |
| 22 |
#define KOKKOSKERNELS_KOKKOSBLAS_GEMM_TEST_RPS_HPP |
| 23 |
|
| 24 |
#include <Kokkos_Core.hpp> |
| 25 |
#include "blas/KokkosBlas3_gemm.hpp" |
| 26 |
#include <Kokkos_Random.hpp> |
| 27 |
|
| 28 |
// These headers are required for RPS tracked perf testing |
| 29 |
#ifdef KOKKOSKERNELS_ENABLE_TESTS_AND_PERFSUITE |
| 30 |
#include <PerfTestUtilities.hpp> |
| 31 |
|
| 32 |
struct gemmConfig { |
| 33 |
int m; |
| 34 |
int n; |
| 35 |
int k; |
| 36 |
}; |
| 37 |
|
| 38 |
test_list construct_gemm_kernel_base(const rajaperf::RunParams& run_params, const std::vector<gemmConfig>& n_k_vect); |
| 39 |
|
| 40 |
#endif // KOKKOSKERNELS_ENABLE_TESTS_AND_PERFSUITE |
| 41 |
|
| 42 |
// Templating on these three types, mirroring |
| 43 |
template <class ExecSpace, class ALayout, class BLayout> |
| 44 |
struct testData_gemm { |
| 45 |
// Data for running tests |
| 46 |
// m is the number of rows in A |
| 47 |
int m = 1000; |
| 48 |
// n is the number of columns in A; |
| 49 |
// n is the number of rows in B; |
| 50 |
int n = 1000; |
| 51 |
// k is the number of columns in B; |
| 52 |
int k = 1000; |
| 53 |
int repeat = 1; |
| 54 |
|
| 55 |
std::string modeA = "N"; |
| 56 |
std::string modeB = "N"; |
| 57 |
|
| 58 |
// Usage: KokkosBlas::gemm(modeA, modeB, alpha, A, B, beta, C); |
| 59 |
// Dense matrix-matrix multiply: C = beta*C + alpha*op(A)*op(B); |
| 60 |
// alpha: alpha [in] Input coefficient of A*x |
| 61 |
// beta [in] Input coefficient of C |
| 62 |
|
| 63 |
double alpha = 1.0; |
| 64 |
double beta = 0.0; |
| 65 |
|
| 66 |
using Scalar = double; |
| 67 |
using MemSpace = typename ExecSpace::memory_space; |
| 68 |
using Device = Kokkos::Device<ExecSpace, MemSpace>; |
| 69 |
|
| 70 |
// Create 2D Kokoks::View, "A" containing an input matrix with m x n |
| 71 |
// dimensions |
| 72 |
Kokkos::View<Scalar**, ALayout, Device> A; |
| 73 |
|
| 74 |
// Create 2D Kokkos::View, "B" containing an input matrix with n x k |
| 75 |
// dimensions |
| 76 |
Kokkos::View<Scalar**, BLayout, Device> B; |
| 77 |
|
| 78 |
// Create 2D Kokkos::View, "C" , the resultant matrix |
| 79 |
Kokkos::View<Scalar**, Kokkos::LayoutLeft, Device> C; |
| 80 |
|
| 81 |
// class Constructor: |
| 82 |
testData_gemm(int m_in, int n_in, int k_in, int repeat_in) : m(m_in), n(n_in), k(k_in), repeat(repeat_in) { |
| 83 |
// You must set A, B and C equal to its intended value |
| 84 |
A = Kokkos::View<Scalar**, ALayout, Device>(Kokkos::view_alloc(Kokkos::WithoutInitializing, "A"), m, n); |
| 85 |
B = Kokkos::View<Scalar**, BLayout, Device>(Kokkos::view_alloc(Kokkos::WithoutInitializing, "B"), n, k); |
| 86 |
C = Kokkos::View<Scalar**, Kokkos::LayoutLeft, Device>(Kokkos::view_alloc(Kokkos::WithoutInitializing, "C"), m, k); |
| 87 |
// Seed random number generation |
| 88 |
Kokkos::Random_XorShift64_Pool<ExecSpace> pool(123); |
| 89 |
// Fill input matrices A and x with 10 random values from pool |
| 90 |
Kokkos::fill_random(A, pool, 10.0); |
| 91 |
Kokkos::fill_random(B, pool, 10.0); |
| 92 |
} |
| 93 |
}; |
| 94 |
|
| 95 |
// Declare setup_test |
| 96 |
template <typename ExecSpace, typename ALayout, typename BLayout> |
| 97 |
testData_gemm<ExecSpace, ALayout, BLayout> setup_test(int m, int n, int k, int repeat); |
| 98 |
|
| 99 |
#endif // KOKKOSKERNELS_KOKKOSBLAS_GEMM_TEST_RPS_HPP |