-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #9329: Restructure ttnn::argmax
- Loading branch information
1 parent
c543781
commit 6958b94
Showing
11 changed files
with
145 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ttnn/decorators.hpp" | ||
#include "ttnn/operations/core.hpp" | ||
#include "ttnn/validation.hpp" | ||
|
||
#include "tt_eager/tt_dnn/op_library/run_operation.hpp" | ||
|
||
#include "device/argmax_op.hpp" | ||
|
||
namespace ttnn { | ||
namespace operations::reduction { | ||
|
||
struct ExecuteArgMax { | ||
static inline const std::array<TensorSchema, 1> input_tensor_schemas() { | ||
return {ttnn::TensorSchema{4, 4, {ttnn::bfloat16}, {ttnn::ROW_MAJOR_LAYOUT}, true, false, false, false}}; | ||
} | ||
|
||
template <typename... Args> | ||
static auto input_tensors_to_validate(uint8_t queue_id, const Tensor& input_tensor, Args&&... args) { | ||
return std::forward_as_tuple(input_tensor); | ||
} | ||
|
||
static ttnn::Tensor execute_on_worker_thread( | ||
uint8_t queue_id, | ||
const Tensor& input_tensor, | ||
const std::optional<int> dim = std::nullopt, | ||
const std::optional<MemoryConfig>& memory_config = std::nullopt, | ||
std::optional<Tensor> optional_output_tensor = std::nullopt) { | ||
return operation::run( | ||
ArgMax{tt::tt_metal::DataType::UINT32, dim, memory_config.value_or(input_tensor.memory_config())}, | ||
{input_tensor}, {}, {optional_output_tensor}, queue_id) | ||
.at(0); | ||
} | ||
|
||
template <typename... Args> | ||
static auto input_tensors_to_validate(const Tensor& input_tensor, Args&&... args) { | ||
return std::forward_as_tuple(input_tensor); | ||
} | ||
|
||
static ttnn::Tensor execute_on_worker_thread( | ||
const Tensor& input_tensor, | ||
const std::optional<int> dim = std::nullopt, | ||
const std::optional<MemoryConfig>& memory_config = std::nullopt, | ||
std::optional<Tensor> optional_output_tensor = std::nullopt) { | ||
return execute_on_worker_thread(DefaultQueueId, input_tensor, dim, memory_config, optional_output_tensor); | ||
} | ||
}; | ||
|
||
} // namespace operations::reduction | ||
|
||
constexpr auto argmax = ttnn::register_operation<ttnn::operations::reduction::ExecuteArgMax>("ttnn::argmax"); | ||
|
||
} // namespace ttnn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
ttnn/cpp/ttnn/operations/reduction/generic/generic_reductions_pybind.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
#include "ttnn/cpp/pybind11/decorators.hpp" | ||
|
||
namespace ttnn::operations::reduction::detail { | ||
|
||
template <typename reduction_operation_t> | ||
void bind_reduction_operation(py::module& module, const reduction_operation_t& operation) { | ||
namespace py = pybind11; | ||
auto doc = fmt::format( | ||
R"doc({0}(input_tensor: ttnn.Tensor, dim: Optional[Union[int, Tuple[int]]] = None, keepdim: bool = True, memory_config: Optional[ttnn.MemoryConfig] = None) -> ttnn.Tensor)doc", | ||
operation.name()); | ||
|
||
bind_registered_operation( | ||
module, | ||
operation, | ||
doc, | ||
ttnn::pybind_arguments_t{ | ||
py::arg("input_tensor"), | ||
py::arg("dim") = std::nullopt, | ||
py::arg("keepdim") = true, | ||
py::arg("memory_config") = std::nullopt}); | ||
} | ||
|
||
} // namespace ttnn::operations::reduction::detail |
Oops, something went wrong.