-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to create eltwise ternary op starting with whereOp.
- Loading branch information
Showing
17 changed files
with
143 additions
and
151 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
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
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,27 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "where.h" | ||
#include "tt/runtime/detail/logger.h" | ||
#include "tt/runtime/detail/ttnn.h" | ||
#include "tt/runtime/ttnn/operations/eltwise/ternary/utils.h" | ||
#include "tt/runtime/ttnn/operations/utils.h" | ||
|
||
namespace tt::runtime::ttnn::operations::ternary { | ||
|
||
void run(const ::tt::target::ttnn::EltwiseOp *op, ProgramContext &context) { | ||
ProgramTensorPool &tensorPool = context.getTensorPool(); | ||
|
||
::ttnn::Tensor *first = nullptr; | ||
::ttnn::Tensor *second = nullptr; | ||
::ttnn::Tensor *third = nullptr; | ||
getEltwiseTernaryOPInputTensors(op, tensorPool, &first, &second, &third); | ||
|
||
::tt::tt_metal::MemoryConfig outputMemoryConfig = | ||
utils::createMemoryConfig(op->out()); | ||
|
||
::ttnn::Tensor out = ::ttnn::where(*first, *second, *third, outputMemoryConfig); | ||
tensorPool.insert_or_assign(op->out()->global_id(), out); | ||
} | ||
} // namespace tt::runtime::ttnn::operations::ternary |
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,21 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef TTNN_RUNTIME_LIB_TTNN_OPERATIONS_ELTWISE_TERNARY_WHERE_H | ||
#define TTNN_RUNTIME_LIB_TTNN_OPERATIONS_ELTWISE_TERNARY_WHERE_H | ||
|
||
#include "tt/runtime/ttnn/types.h" | ||
#include "ttmlir/Target/TTNN/program_generated.h" | ||
|
||
namespace tt::runtime::ttnn::operations::ternary { | ||
|
||
inline bool isTernaryOp(const ::tt::target::ttnn::EltwiseOp *op) { | ||
return op->ins()->size() == 3; | ||
} | ||
|
||
void run(const ::tt::target::ttnn::EltwiseOp *op, ProgramContext &context); | ||
|
||
} // namespace tt::runtime::ttnn::operations::ternary | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
runtime/lib/ttnn/operations/include/tt/runtime/ttnn/operations/eltwise/ternary/utils.cpp
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,24 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#include "utils.h" | ||
#include "tt/runtime/detail/logger.h" | ||
#include "tt/runtime/detail/workarounds.h" | ||
|
||
namespace tt::runtime::ttnn::operations::binary { | ||
|
||
void getEltwiseTernaryOPInputTensors(const ::tt::target::ttnn::EltwiseOp *op, | ||
ProgramTensorPool &tensorPool, | ||
::ttnn::Tensor **first, | ||
::ttnn::Tensor **seccond, | ||
::ttnn::Tensor **third) { | ||
LOG_ASSERT(op->ins()->size() == 3, "Expected 3 inputs"); | ||
*first = &(tensorPool.at(op->ins()->Get(0)->global_id())); | ||
*second = &(tensorPool.at(op->ins()->Get(1)->global_id())); | ||
*third = &(tensorPool.at(op->ins()->Get(2)->global_id())); | ||
DEBUG_ASSERT((*first)->is_allocated()); | ||
DEBUG_ASSERT((*second)->is_allocated()); | ||
DEBUG_ASSERT((*third)->is_allocated()); | ||
} | ||
|
||
} // namespace tt::runtime::ttnn::operations::binary |
Oops, something went wrong.