Debian Codegraph @

packages/kokkos/benchmarks/policy_performance/main.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 "policy_perf_test.hpp"
19
20 int main(int argc, char* argv[]) {
21 Kokkos::initialize(argc, argv);
22
23 if (argc < 10) {
24 printf(" Ten arguments are needed to run this program:\n");
25 printf(
26 " (1)team_range, (2)thread_range, (3)vector_range, (4)outer_repeat, "
27 "(5)thread_repeat, (6)vector_repeat, (7)team_size, (8)vector_size, "
28 "(9)schedule, (10)test_type\n");
29 printf(" team_range: number of teams (league_size)\n");
30 printf(" thread_range: range for nested TeamThreadRange parallel_*\n");
31 printf(" vector_range: range for nested ThreadVectorRange parallel_*\n");
32 printf(" outer_repeat: number of repeats for outer parallel_* call\n");
33 printf(
34 " thread_repeat: number of repeats for TeamThreadRange parallel_* "
35 "call\n");
36 printf(
37 " vector_repeat: number of repeats for ThreadVectorRange parallel_* "
38 "call\n");
39 printf(" team_size: number of team members (team_size)\n");
40 printf(" vector_size: desired vectorization (if possible)\n");
41 printf(" schedule: 1 == Static 2 == Dynamic\n");
42 printf(
43 " test_type: 3-digit code XYZ for testing (nested) parallel_*\n");
44 printf(
45 " code key: XYZ X in {1,2,3,4,5}, Y in {0,1,2}, Z in "
46 "{0,1,2}\n");
47 printf(" TeamPolicy:\n");
48 printf(
49 " X: 0 = none (never used, makes no sense); 1 = "
50 "parallel_for; 2 = parallel_reduce\n");
51 printf(
52 " Y: 0 = none; 1 = parallel_for; 2 = "
53 "parallel_reduce\n");
54 printf(
55 " Z: 0 = none; 1 = parallel_for; 2 = "
56 "parallel_reduce\n");
57 printf(" RangePolicy:\n");
58 printf(
59 " X: 3 = parallel_for; 4 = parallel_reduce; 5 = "
60 "parallel_scan\n");
61 printf(" Y: 0 = none\n");
62 printf(" Z: 0 = none\n");
63 printf(" Example Input:\n");
64 printf(" 100000 32 32 100 100 100 8 1 1 100\n");
65 Kokkos::finalize();
66 return 0;
67 }
68
69 int team_range = std::stoi(argv[1]);
70 int thread_range = std::stoi(argv[2]);
71 int vector_range = std::stoi(argv[3]);
72
73 int outer_repeat = std::stoi(argv[4]);
74 int thread_repeat = std::stoi(argv[5]);
75 int vector_repeat = std::stoi(argv[6]);
76
77 int team_size = std::stoi(argv[7]);
78 int vector_size = std::stoi(argv[8]);
79 int schedule = std::stoi(argv[9]);
80 int test_type = std::stoi(argv[10]);
81
82 int disable_verbose_output = 0;
83 if (argc > 11) {
84 disable_verbose_output = std::stoi(argv[11]);
85 }
86
87 if (schedule != 1 && schedule != 2) {
88 printf("schedule: %d\n", schedule);
89 printf("Options for schedule are: 1 == Static 2 == Dynamic\n");
90 Kokkos::finalize();
91 return -1;
92 }
93
94 if (test_type != 100 && test_type != 110 && test_type != 111 &&
95 test_type != 112 && test_type != 120 && test_type != 121 &&
96 test_type != 122 && test_type != 200 && test_type != 210 &&
97 test_type != 211 && test_type != 212 && test_type != 220 &&
98 test_type != 221 && test_type != 222 && test_type != 300 &&
99 test_type != 400 && test_type != 500) {
100 printf("Incorrect test_type option\n");
101 Kokkos::finalize();
102 return -2;
103 }
104
105 double result = 0.0;
106
107 Kokkos::parallel_reduce(
108 "parallel_reduce warmup", Kokkos::TeamPolicy<>(10, 1),
109 KOKKOS_LAMBDA(const Kokkos::TeamPolicy<>::member_type&, double& lval) {
110 lval += 1;
111 },
112 result);
113
114 using view_type_1d = Kokkos::View<double*, Kokkos::LayoutRight>;
115 using view_type_2d = Kokkos::View<double**, Kokkos::LayoutRight>;
116 using view_type_3d = Kokkos::View<double***, Kokkos::LayoutRight>;
117
118 // Allocate view without initializing
119 // Call a 'warmup' test with 1 repeat - this will initialize the corresponding
120 // view appropriately for test and should obey first-touch etc Second call to
121 // test is the one we actually care about and time
122 view_type_1d v_1(Kokkos::view_alloc(Kokkos::WithoutInitializing, "v_1"),
123 team_range * team_size);
124 view_type_2d v_2(Kokkos::view_alloc(Kokkos::WithoutInitializing, "v_2"),
125 team_range * team_size, thread_range);
126 view_type_3d v_3(Kokkos::view_alloc(Kokkos::WithoutInitializing, "v_3"),
127 team_range * team_size, thread_range, vector_range);
128
129 double result_computed = 0.0;
130 double result_expect = 0.0;
131 double time = 0.0;
132
133 if (schedule == 1) {
134 if (test_type != 500) {
135 // warmup - no repeat of loops
136 test_policy<Kokkos::Schedule<Kokkos::Static>, int>(
137 team_range, thread_range, vector_range, 1, 1, 1, team_size,
138 vector_size, test_type, v_1, v_2, v_3, result_computed, result_expect,
139 time);
140 test_policy<Kokkos::Schedule<Kokkos::Static>, int>(
141 team_range, thread_range, vector_range, outer_repeat, thread_repeat,
142 vector_repeat, team_size, vector_size, test_type, v_1, v_2, v_3,
143 result_computed, result_expect, time);
144 } else {
145 // parallel_scan: initialize 1d view for parallel_scan
146 test_policy<Kokkos::Schedule<Kokkos::Static>, int>(
147 team_range, thread_range, vector_range, 1, 1, 1, team_size,
148 vector_size, 100, v_1, v_2, v_3, result_computed, result_expect,
149 time);
150 test_policy<Kokkos::Schedule<Kokkos::Static>, int>(
151 team_range, thread_range, vector_range, outer_repeat, thread_repeat,
152 vector_repeat, team_size, vector_size, test_type, v_1, v_2, v_3,
153 result_computed, result_expect, time);
154 }
155 }
156 if (schedule == 2) {
157 if (test_type != 500) {
158 // warmup - no repeat of loops
159 test_policy<Kokkos::Schedule<Kokkos::Dynamic>, int>(
160 team_range, thread_range, vector_range, 1, 1, 1, team_size,
161 vector_size, test_type, v_1, v_2, v_3, result_computed, result_expect,
162 time);
163 test_policy<Kokkos::Schedule<Kokkos::Dynamic>, int>(
164 team_range, thread_range, vector_range, outer_repeat, thread_repeat,
165 vector_repeat, team_size, vector_size, test_type, v_1, v_2, v_3,
166 result_computed, result_expect, time);
167 } else {
168 // parallel_scan: initialize 1d view for parallel_scan
169 test_policy<Kokkos::Schedule<Kokkos::Static>, int>(
170 team_range, thread_range, vector_range, 1, 1, 1, team_size,
171 vector_size, 100, v_1, v_2, v_3, result_computed, result_expect,
172 time);
173 test_policy<Kokkos::Schedule<Kokkos::Static>, int>(
174 team_range, thread_range, vector_range, outer_repeat, thread_repeat,
175 vector_repeat, team_size, vector_size, test_type, v_1, v_2, v_3,
176 result_computed, result_expect, time);
177 }
178 }
179
180 if (disable_verbose_output == 0) {
181 printf("%7i %4i %2i %9i %4i %4i %4i %2i %1i %3i %e %e %lf\n", team_range,
182 thread_range, vector_range, outer_repeat, thread_repeat,
183 vector_repeat, team_size, vector_size, schedule, test_type,
184 result_computed, result_expect, time);
185 } else {
186 printf("%lf\n", time);
187 }
188
189 Kokkos::finalize();
190
191 return 0;
192 }