Debian Codegraph @

packages/kokkos-kernels/perf_test/blas/blas3/KokkosBlas3_common.hpp

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 #ifndef KOKKOSBLAS3_COMMON_H_
17 #define KOKKOSBLAS3_COMMON_H_
18 #include "KokkosKernels_default_types.hpp"
19
20 #include <iostream>
21 #include <fstream>
22
23 /************************ perf test default value definitions **********/
24 #define DEFAULT_TEST BLAS
25 #define DEFAULT_LOOP SERIAL
26 #define DEFAULT_MATRIX_START 10
27 #define DEFAULT_MATRIX_STOP 2430
28 #define DEFAULT_STEP 3
29 #define DEFAULT_WARM_UP_N 100
30 #define DEFAULT_N 100
31 #define DEFAULT_K 1024
32 #define DEFAULT_OUT &std::cout
33 #define DEFAULT_BLAS_ROUTINES "trmm,gemm,"
34 #define DEFAULT_TEAM_SIZE 1
35 #define DEFAULT_VECTOR_LEN 1
36 #define DEFAULT_USE_AUTO 0
37 #define DEFAULT_BATCH_SIZE_LAST_DIM 0
38 #define DEFAULT_VERIFY 1
39 #define DEFAULT_NINTER 4
40 #define DEFAULT_USE_SIMD 0
41
42 /************************ blas routine structure definitions **********/
43 struct perf_test_trmm_args {
44 std::string trmm_args;
45 KokkosKernels::default_scalar alpha;
46 };
47 typedef struct perf_test_trmm_args pt_trmm_args_t;
48
49 struct perf_test_gemm_args {
50 std::string gemm_args; //[N,T,C][N,T,C] for transA and transB
51 KokkosKernels::default_scalar alpha;
52 KokkosKernels::default_scalar beta;
53 };
54 typedef struct perf_test_gemm_args pt_gemm_args_t;
55 // ADD MORE BLAS3 ROUTINE ARG STRUCTS HERE.
56
57 struct blas_args {
58 pt_trmm_args_t trmm;
59 pt_gemm_args_t gemm;
60 // ADD MORE BLAS3 ROUTINES HERE
61 int team_size;
62 int vector_len;
63 bool use_auto, batch_size_last_dim;
64 // ADD MORE COMMON BLAS3 OPTIONS HERE
65 };
66 typedef struct blas_args blas_args_t;
67
68 typedef enum BLAS_ROUTINES {
69 TRMM,
70 GEMM,
71 // ADD MORE BLAS3 ROUTINES HERE
72 BLAS_ROUTINES_N
73 } blas_routines_e;
74
75 static std::string blas_routines_e_str[BLAS_ROUTINES_N] = {
76 "trmm", "gemm"
77 // ADD MORE BLAS3 ROUTINES HERE
78 };
79
80 /************************ perf test type definitions ************************/
81 /**
82 * @var SERIAL: Run the blas routine iteratively, within a for-loop
83 * @var PARALLEL: Run the blas routine iteratively, within a
84 * Kokkos::parallel_for-loop
85 */
86 typedef enum LOOP {
87 SERIAL,
88 PARALLEL,
89 // ADD MORE LOOP TYPES HERE
90 LOOP_N
91 } loop_e;
92
93 static std::string loop_e_str[LOOP_N] = {"serial", "parallel"};
94
95 /**
96 * @var BLAS: Run the blas routine through the
97 * KokkosBlas namespace.
98 * @var BATCHED_SERIAL{_BLOCKED}: Run the serial blas routine through the
99 * KokkosBatched namespace.
100 * @var BATCHED_SERIAL_SIMD{_BLOCKED}: Run the serial blas routine through the
101 * KokkosBatched namespace using SIMD views.
102 * @var BATCHED_SERIAL_COMPACT_MKL: Run the serial blas mkl routine through
103 * the KokkosBatched namespace.
104 * @var BATCHED_TEAM{_BLOCKED}: Run the team blas routine through the
105 * KokkosBatched namespace.
106 * @var BATCHED_TEAM_VECTOR{_BLOCKED}: Run the team vector blas routine through
107 * the KokkosBatched namespace.
108 * @var BATCHED_TEAM_SIMD{_BLOCKED}: Run the team vector blas routine through
109 * the KokkosBatched namespace using SIMD views.
110 * @var EXPERIMENT: Run the blas routine as a custom
111 * experiment.
112 */
113 typedef enum TEST {
114 BLAS,
115 BATCHED_HEURISTIC,
116 BATCHED_SERIAL,
117 BATCHED_SERIAL_BLOCKED,
118 BATCHED_SERIAL_SIMD,
119 BATCHED_SERIAL_SIMD_BLOCKED,
120 BATCHED_SERIAL_COMPACT_MKL,
121 BATCHED_TEAM,
122 BATCHED_TEAM_BLOCKED,
123 BATCHED_TEAM_VECTOR,
124 BATCHED_TEAM_VECTOR_BLOCKED,
125 BATCHED_TEAM_SIMD,
126 BATCHED_TEAM_SIMD_BLOCKED,
127 // ADD MORE TEST TYPES HERE
128 EXPERIMENT,
129 TEST_N
130 } test_e;
131
132 static std::string test_e_str[TEST_N]{
133 "blas", "batched_heuristic", "batched_serial", "batched_serial_blocked", "batched_serial_simd",
134 "batched_serial_simd_blocked", "batched_serial_compact_mkl", "batched_team", "batched_team_blocked",
135 "batched_team_vector", "batched_team_vector_blocked", "batched_team_simd", "batched_team_simd_blocked",
136 // ADD MORE TEST TYPES HERE
137 "experiment"};
138
139 /**
140 * @var k: Number of 2D matrices.
141 * @var m: Number of rows.
142 * @var n: Number of columns.
143 */
144 struct matrix_dim {
145 int k, m, n;
146 };
147 typedef struct matrix_dim matrix_dim_t;
148
149 struct matrix_dims {
150 matrix_dim_t a, b, c;
151 };
152 typedef struct matrix_dims matrix_dims_t;
153
154 /**
155 * @var test: Selects which namespace to test.
156 * @var loop: Selects how to invoke the blas routine.
157 * @var start: Selects which matrix dimensions to start with.
158 * @var stop: Selects which matrix dimensions to end with.
159 * @var step: Selects the multiplier to increase start by.
160 * @var warm_up_n: Selects how many untimed runs to perform for each matrix
161 * dimension.
162 * @var n: Selects how many timed runs to perform for each matrix
163 * dimension.
164 * @var out: Selects where to write the csv data for each matrix
165 * dimension.
166 * @var out_file: The file to write csv data to. Defaults to stdout.
167 * @var blas_args: Arguments for each supported blas routine.
168 * @var blas_routines: Selects which supported blas routines to test.
169 * @var verify: Performs verification of the blas routine for each input
170 * before timing it.
171 * @var ninter: The number of interleaved matrices for armpl.
172 */
173 struct perf_test_options {
174 test_e test;
175 loop_e loop;
176 matrix_dims_t start;
177 matrix_dims_t stop;
178 uint32_t step;
179 uint32_t warm_up_n;
180 uint32_t n;
181 std::ostream* out;
182 std::string out_file;
183 blas_args_t blas_args;
184 std::string blas_routines;
185 bool verify;
186 int ninter;
187 bool use_simd;
188 };
189 typedef struct perf_test_options options_t;
190
191 /*************************** Print macros **************************/
192 // #define PERF_TEST_DEBUG
193 #ifdef PERF_TEST_DEBUG
194 #define STATUS printf("STATUS: %s:%d.\n", __func__, __LINE__);
195 #else
196 #define STATUS
197 #endif // PERF_TEST_DEBUG
198 #define FATAL_ERROR(msg) printf("FATAL_ERROR: %s:%s:%d %s\n", __FILE__, __func__, __LINE__, (msg));
199 #endif // KOKKOSBLAS3_COMMON_H_