Skip to content

Commit 6efb31d

Browse files
authored
Remove min from dataflow_api.h (#23463)
### Ticket #18872 ### Problem description dataflow_api.h should not define `min`. ### What's changed Deleted `min`. Changed affected kernels to use `std::min` instead. ### Checklist - [x] [All post commit](https://github.com/tenstorrent/tt-metal/actions/runs/15597989329/) CI passes - [ ] [Blackhole Post commit](https://github.com/tenstorrent/tt-metal/actions/runs/15597890233) CI with demo tests passes (if applicable) - [ ] [Model regression](https://github.com/tenstorrent/tt-metal/actions/workflows/perf-models.yaml) CI passes (if applicable) - [ ] [Device performance regression](https://github.com/tenstorrent/tt-metal/actions/workflows/perf-device-models.yaml) CI passes (if applicable) - [ ] (For models and ops writers) [Single-card demo tests](https://github.com/tenstorrent/tt-metal/actions/workflows/single-card-demo-tests.yaml) CI passes (if applicable) See [recommended dev flow](https://github.com/tenstorrent/tt-metal/blob/main/models/MODEL_ADD.md#a-recommended-dev-flow-on-github-for-adding-new-models). - [ ] New/Existing tests provide coverage for changes
1 parent 05618bb commit 6efb31d

File tree

10 files changed

+21
-15
lines changed

10 files changed

+21
-15
lines changed

tt_metal/hw/inc/dataflow_api.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,9 +1725,6 @@ inline void RISC_POST_HEARTBEAT(uint32_t& heartbeat) {
17251725
ptr[0] = 0xAABB0000 | (heartbeat & 0xFFFF);
17261726
}
17271727

1728-
FORCE_INLINE
1729-
uint32_t min(uint32_t a, uint32_t b) { return (a < b) ? a : b; }
1730-
17311728
template <bool use_vc>
17321729
FORCE_INLINE uint32_t noc_async_read_tile_dram_sharded_set_state(
17331730
uint32_t bank_base_address,

ttnn/cpp/ttnn/operations/data_movement/permute/device/kernels/dataflow/reader_permute_interleaved_rm_blocked_generic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include <stdint.h>
6+
#include <algorithm>
67
#include "dataflow_api.h"
78

89
void kernel_main() {
@@ -69,11 +70,11 @@ void kernel_main() {
6970

7071
// Compute X block boundaries
7172
uint32_t x_start = x_block * x_block_size;
72-
uint32_t x_end = min(x_start + x_block_size, X);
73+
uint32_t x_end = std::min(x_start + x_block_size, X);
7374

7475
// Compute W block boundaries
7576
uint32_t w_start = w_block * w_block_size;
76-
uint32_t w_end = min(w_start + w_block_size, input_shape[N - 1]);
77+
uint32_t w_end = std::min(w_start + w_block_size, input_shape[N - 1]);
7778
uint32_t w_offset = w_start * element_size;
7879

7980
uint32_t w_read_size_bytes = (w_end - w_start) * element_size;

ttnn/cpp/ttnn/operations/data_movement/permute/device/kernels/dataflow/writer_permute_interleaved_rm_blocked_generic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include <stdint.h>
6+
#include <algorithm>
67
#include "dataflow_api.h"
78
#include "cpp/ttnn/operations/data_movement/common/kernels/common.hpp"
89

@@ -98,10 +99,10 @@ void kernel_main() {
9899

99100
// Compute start/end boundaries for the current X and W blocks
100101
const uint32_t x_start = x_block * x_block_size;
101-
const uint32_t x_end = min(x_start + x_block_size, X);
102+
const uint32_t x_end = std::min(x_start + x_block_size, X);
102103

103104
const uint32_t w_start = w_block * w_block_size;
104-
const uint32_t w_end = min(w_start + w_block_size, W);
105+
const uint32_t w_end = std::min(w_start + w_block_size, W);
105106

106107
// Compute the read size for the X dimension
107108
const uint32_t x_read_size_bytes = (x_end - x_start) * element_size;

ttnn/cpp/ttnn/operations/experimental/slice_write/device/kernels/dataflow/slice_write_writer_interleaved.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include <stdint.h>
6+
#include <algorithm>
67
#include "dataflow_api.h"
78

89
void kernel_main() {
@@ -34,7 +35,7 @@ void kernel_main() {
3435
constexpr bool dst0_is_dram = get_compile_time_arg_val(1) == 1;
3536

3637
const InterleavedAddrGen<dst0_is_dram> s0 = {.bank_base_address = dst_addr, .page_size = output_stick_size};
37-
const uint32_t noc_write_size = min(output_stick_size, input_stick_size);
38+
const uint32_t noc_write_size = std::min(output_stick_size, input_stick_size);
3839
uint32_t dst_stick_id = start_id;
3940
uint32_t sticks_read = 0;
4041
for (uint32_t iter = 0; iter < num_sticks_per_core_read and sticks_read < num_sticks_per_core; ++iter) {

ttnn/cpp/ttnn/operations/moreh/moreh_getitem/device/moreh_getitem_tilized_kernels/reader_moreh_getitem_tilize_w.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#include <algorithm>
56
#include "dataflow_api.h"
67
#include "cpp/ttnn/operations/moreh/moreh_getitem/device/moreh_getitem_tilized_kernels/common.hpp"
78

@@ -140,7 +141,7 @@ void kernel_main() {
140141
uint32_t index_w_index = i % num_alignment_width;
141142
uint32_t index_off = index_w_index * num_elements_per_alignment;
142143
uint32_t index_start = index_off;
143-
uint32_t index_end = min(index_off + num_elements_per_alignment, index_size_w);
144+
uint32_t index_end = std::min(index_off + num_elements_per_alignment, index_size_w);
144145

145146
uint32_t j = 0;
146147
for (uint32_t index_index = index_start; index_index < index_end; index_index++, j++) {

ttnn/cpp/ttnn/operations/moreh/moreh_getitem/device/moreh_getitem_tilized_kernels/writer_moreh_getitem_tilize_w.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#include <algorithm>
56
#include "dataflow_api.h"
67
#include "cpp/ttnn/operations/moreh/moreh_getitem/device/moreh_getitem_tilized_kernels/common.hpp"
78

@@ -49,7 +50,7 @@ void kernel_main() {
4950
uint32_t output_stick_w = i % num_alignment_width;
5051
uint32_t w_off = output_stick_w * num_elements_per_alignment;
5152
uint32_t w_start = w_off;
52-
uint32_t w_end = min(w_off + num_elements_per_alignment, output_size_w_without_padding);
53+
uint32_t w_end = std::min(w_off + num_elements_per_alignment, output_size_w_without_padding);
5354

5455
uint32_t stick_y = (i / num_alignment_width);
5556
uint32_t stick_x = w_start / FACE_WIDTH;

ttnn/cpp/ttnn/operations/moreh/moreh_nll_loss/moreh_nll_loss_step2/device/kernels/reader_moreh_nll_loss_step2_2d.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#include <algorithm>
56
#include "cpp/ttnn/deprecated/tt_dnn/kernels/dataflow/moreh_common.hpp"
67

78
void kernel_main() {
@@ -72,7 +73,7 @@ void kernel_main() {
7273
for (uint32_t i = start_id; i < end_id; ++i) {
7374
// loop from n_start to n_end
7475
uint32_t n_start = i * TILE_HEIGHT;
75-
uint32_t n_end = min(i * TILE_HEIGHT + TILE_HEIGHT, N);
76+
uint32_t n_end = std::min(i * TILE_HEIGHT + TILE_HEIGHT, N);
7677
uint32_t nt = i;
7778

7879
// target: (1, N)

ttnn/cpp/ttnn/operations/moreh/moreh_nll_loss/moreh_nll_loss_step2/device/kernels/reader_moreh_nll_loss_step2_3d.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#include <algorithm>
56
#include "cpp/ttnn/deprecated/tt_dnn/kernels/dataflow/moreh_common.hpp"
67

78
void kernel_main() {
@@ -105,7 +106,7 @@ void kernel_main() {
105106
auto tmp_input_l1_ptr = get_write_ptr<FP32_DEST_ACC_FTYPE>(cb_tmp_input);
106107
auto target_l1_ptr = get_read_ptr<int32_t>(cb_target);
107108

108-
uint32_t idx_max = min(w + FACE_WIDTH, W);
109+
uint32_t idx_max = std::min(w + FACE_WIDTH, W);
109110
for (uint32_t idx = 0; idx < idx_max; idx++) {
110111
int32_t target_val = target_l1_ptr[idx];
111112

ttnn/cpp/ttnn/operations/pool/upsample/device/kernels/dataflow/reader_bilinear_multi_core_sharded.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include "dataflow_api.h"
6+
#include <algorithm>
67
#include "cpp/ttnn/deprecated/tt_dnn/kernels/dataflow/moreh_common.hpp"
78

89
#define ALWI inline __attribute__((always_inline))
@@ -78,10 +79,10 @@ void kernel_main() {
7879

7980
uint32_t x1 = int(x);
8081
uint32_t y1 = int(y);
81-
uint32_t x2 = min(x1 + 1, in_w - 1);
82+
uint32_t x2 = std::min(x1 + 1, in_w - 1);
8283
uint32_t y2 = y1 + 1;
8384
if (is_last_row) {
84-
y2 = min(y2, in_image_rows_per_core); // if last row, y2 should be in_image_rows_per_core
85+
y2 = std::min(y2, in_image_rows_per_core); // if last row, y2 should be in_image_rows_per_core
8586
}
8687

8788
fill_four_val(

ttnn/cpp/ttnn/operations/reduction/argmax/device/kernels/reader_argmax_interleaved_multicore.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#include <stdint.h>
6+
#include <algorithm>
67

78
#include "dataflow_api.h"
89
#include "utils/bfloat16.h"
@@ -64,7 +65,7 @@ inline void find_argmax_for_core(
6465
max_val = val;
6566
} else if (val == max_val) {
6667
auto full_idx = outer_idx * inner_dim_units * red_dim_units + j * red_dim_units + i;
67-
max_idx = reduce_all ? min(max_idx, full_idx) : min(max_idx, i);
68+
max_idx = reduce_all ? std::min(max_idx, full_idx) : std::min(max_idx, i);
6869
}
6970
}
7071

0 commit comments

Comments
 (0)