Debian Codegraph @

origami/include/origami/utils.hpp

raw
1 // Copyright Advanced Micro Devices, Inc., or its affiliates.
2 // SPDX-License-Identifier: MIT
3
4 #pragma once
5
6 #include "origami/gemm.hpp"
7 #include "origami/hardware.hpp"
8 #include <set>
9 #include <tuple>
10 #include <vector>
11 #include <functional> // For std::function
12
13 namespace origami
14 {
15 using result_tuple = std::tuple<double, // latency
16 size_t, // MT_M
17 size_t, // MT_N
18 size_t, // MT_K
19 size_t, // MI_M
20 size_t, // MI_N
21 size_t, // MI_K
22 size_t, // Occupancy
23 int, // WGM
24 size_t, // non_temporal_a
25 size_t>; // non_temporal_b
26
27 using tile_tuple = std::tuple<size_t, // MT_M
28 size_t, // MT_N
29 size_t, // MT_K
30 size_t, // MI_M
31 size_t, // MI_N
32 size_t, // MI_K
33 size_t, // Occupancy
34 int, // WGM
35 size_t, // non_temporal_a
36 size_t>; // non_temporal_b
37
38 size_t select_best_grid_size(size_t M,
39 size_t N,
40 size_t K,
41 size_t batch,
42 bool transA,
43 bool transB,
44 const hardware_t& hardware,
45 size_t MT_M,
46 size_t MT_N,
47 size_t MT_K,
48 size_t MI_M,
49 size_t MI_N,
50 size_t MI_K,
51 size_t element_size_A,
52 size_t element_size_B,
53 size_t element_size_out,
54 data_type_t mi_datatype,
55 size_t mx_block_size,
56 double H_L2,
57 size_t WGM,
58 size_t biggest_allowable_split = 8);
59
60 std::vector<result_tuple> select_best_macro_tile_size(size_t M,
61 size_t N,
62 size_t K,
63 size_t batch,
64 bool transA,
65 bool transB,
66 const hardware_t& hardware,
67 const std::vector<tile_tuple>& MT_list,
68 size_t element_size_A,
69 size_t element_size_B,
70 size_t element_size_out,
71 data_type_t mi_datatype,
72 size_t mx_block_size,
73 double H_L2,
74 bool print,
75 size_t WGM);
76
77 std::vector<result_tuple> sweep_macro_tile_sizes(size_t M,
78 size_t N,
79 size_t K,
80 bool transA,
81 bool transB,
82 hardware_t& hardware,
83 size_t element_size = 2,
84 size_t max_MT_M = 256,
85 size_t max_MT_N = 256,
86 size_t max_MT_K = 128,
87 size_t step_MT_M = 32,
88 size_t step_MT_N = 32,
89 size_t step_MT_K = 32,
90 double H_L2 = 0.8,
91 const std::vector<tile_tuple>& tiles_to_add
92 = {},
93 bool print = false);
94
95 std::pair<double, size_t> select_best_wgm(
96 size_t M,
97 size_t N,
98 size_t K,
99 size_t batch,
100 const hardware_t& hardware,
101 size_t MT_M,
102 size_t MT_N,
103 size_t MT_K,
104 size_t MI_M,
105 size_t MI_N,
106 size_t MI_K,
107 const std::vector<size_t>& WGM_list,
108 size_t element_size,
109 double H_L2, // not needed for L2 hit rate but retained if your code expects it
110 bool print);
111
112 double compute_tflops_from_latency(double latency_cycles,
113 size_t M,
114 size_t N,
115 size_t K,
116 double clock_GHz);
117
118 } // namespace origami