|
6 | 6 | * LICENSE file in the root directory of this source tree. |
7 | 7 | */ |
8 | 8 |
|
| 9 | +#include <c10/util/irange.h> |
9 | 10 | #include <cstring> |
10 | 11 |
|
11 | 12 | #include <executorch/kernels/portable/cpu/util/dtype_util.h> |
@@ -91,25 +92,25 @@ void conv2d_impl( |
91 | 92 | if (!transposed) { |
92 | 93 | w_coord[0] = out_c; |
93 | 94 | // Compute 2D output region |
94 | | - for (size_t out_y = 0; out_y < out_H; ++out_y) { |
| 95 | + for (const auto out_y : c10::irange(out_H)) { |
95 | 96 | out_coord[2] = out_y; |
96 | | - for (size_t out_x = 0; out_x < out_W; ++out_x) { |
| 97 | + for (const auto out_x : c10::irange(out_W)) { |
97 | 98 | out_coord[3] = out_x; |
98 | 99 |
|
99 | 100 | CTYPE accum = 0.0f; |
100 | | - for (size_t in_c = in_c_start; in_c < in_c_start + in_C_per_group; |
101 | | - ++in_c) { |
| 101 | + for (const auto in_c : |
| 102 | + c10::irange(in_c_start, in_c_start + in_C_per_group)) { |
102 | 103 | in_coord[1] = in_c; |
103 | 104 | w_coord[1] = in_c - in_c_start; |
104 | 105 |
|
105 | | - for (size_t w_y = 0; w_y < w_H; ++w_y) { |
| 106 | + for (const auto w_y : c10::irange(w_H)) { |
106 | 107 | w_coord[2] = w_y; |
107 | 108 |
|
108 | 109 | size_t in_y = stride_y * out_y + dilation_y * w_y - padding_y; |
109 | 110 | in_coord[2] = in_y; |
110 | 111 | // Only proceed if input y coordinate is within bounds |
111 | 112 | if (in_y >= 0 && in_y < in_H) { |
112 | | - for (size_t w_x = 0; w_x < w_W; ++w_x) { |
| 113 | + for (const auto w_x : c10::irange(w_W)) { |
113 | 114 | w_coord[3] = w_x; |
114 | 115 |
|
115 | 116 | size_t in_x = stride_x * out_x + dilation_x * w_x - padding_x; |
@@ -143,29 +144,29 @@ void conv2d_impl( |
143 | 144 | } else { // transposed convolution |
144 | 145 | w_coord[1] = out_c - out_c_start; |
145 | 146 |
|
146 | | - for (size_t in_y = 0; in_y < in_H; ++in_y) { |
| 147 | + for (const auto in_y : c10::irange(in_H)) { |
147 | 148 | in_coord[2] = in_y; |
148 | 149 |
|
149 | | - for (size_t in_x = 0; in_x < in_W; ++in_x) { |
| 150 | + for (const auto in_x : c10::irange(in_W)) { |
150 | 151 | in_coord[3] = in_x; |
151 | 152 |
|
152 | | - for (size_t in_c = in_c_start; in_c < in_c_start + in_C_per_group; |
153 | | - ++in_c) { |
| 153 | + for (const auto in_c : |
| 154 | + c10::irange(in_c_start, in_c_start + in_C_per_group)) { |
154 | 155 | in_coord[1] = in_c; |
155 | 156 |
|
156 | 157 | size_t in_idx = |
157 | 158 | calculate_linear_index(in_coord, in_strides.data(), 4); |
158 | 159 | CTYPE in_val = in_ptr[in_idx]; |
159 | 160 |
|
160 | 161 | w_coord[0] = in_c; |
161 | | - for (size_t w_y = 0; w_y < w_H; ++w_y) { |
| 162 | + for (const auto w_y : c10::irange(w_H)) { |
162 | 163 | w_coord[2] = w_y; |
163 | 164 | size_t out_y = stride_y * in_y + dilation_y * w_y - padding_y; |
164 | 165 | out_coord[2] = out_y; |
165 | 166 |
|
166 | 167 | // Only proceed if output y coordinate is within bounds |
167 | 168 | if (out_y >= 0 && out_y < out_H) { |
168 | | - for (size_t w_x = 0; w_x < w_W; ++w_x) { |
| 169 | + for (const auto w_x : c10::irange(w_W)) { |
169 | 170 | w_coord[3] = w_x; |
170 | 171 | size_t out_x = stride_x * in_x + dilation_x * w_x - padding_x; |
171 | 172 | out_coord[3] = out_x; |
@@ -302,21 +303,21 @@ void convolution_wrapper( |
302 | 303 | memset(out_ptr, 0, out.nbytes()); |
303 | 304 | } else { |
304 | 305 | // If bias is present, we initialize the output to the bias value |
305 | | - for (size_t out_ix = 0; out_ix < out.numel(); ++out_ix) { |
| 306 | + for (const auto out_ix : c10::irange(out.numel())) { |
306 | 307 | out_ptr[out_ix] = load_bias(&bias_ptr |
307 | 308 | [((out_ix / out_strides[1]) % out_C) * |
308 | 309 | bias.value().element_size()]); |
309 | 310 | } |
310 | 311 | } |
311 | 312 | } |
312 | 313 |
|
313 | | - for (size_t batch = 0; batch < out_N; ++batch) { |
314 | | - for (size_t group = 0; group < groups; ++group) { |
| 314 | + for (const auto batch : c10::irange(out_N)) { |
| 315 | + for (const auto group : c10::irange(groups)) { |
315 | 316 | // Align channel offset based on the group |
316 | 317 | size_t out_c_start = group * out_C_per_group; |
317 | 318 | // Populate all the out channels in the group |
318 | | - for (size_t out_c = out_c_start; out_c < out_c_start + out_C_per_group; |
319 | | - ++out_c) { |
| 319 | + for (const auto out_c : |
| 320 | + c10::irange(out_c_start, out_c_start + out_C_per_group)) { |
320 | 321 | conv2d_impl( |
321 | 322 | in_ptr, |
322 | 323 | in_sizes, |
|
0 commit comments