-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated imports Added TTNN Ops, Attrs, & Enums to Python Bindings
- Loading branch information
1 parent
43c63a5
commit cc5f60e
Showing
13 changed files
with
268 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef TTMLIR_C_TTNNATTRS_H | ||
#define TTMLIR_C_TTNNATTRS_H | ||
|
||
#include "ttmlir-c/Dialects.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ttmlirTTNNCoreRangeAttrGet(MlirContext ctx, | ||
int64_t *offset, | ||
size_t offsetSize, | ||
int64_t *size, | ||
size_t sizeSize); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ttmlirTTNNCoreRangeArrayAttrGet( | ||
MlirContext ctx, MlirAttribute *coreRangeAttrs, size_t coreRangeAttrsSize); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ttmlirTTNNLayoutAttrGet(MlirContext ctx, | ||
uint32_t layout); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ttmlirTTNNTensorMemoryLayoutAttrGet( | ||
MlirContext ctx, uint32_t tensorMemoryLayout); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute | ||
ttmlirTTNNBufferTypeAttrGet(MlirContext ctx, uint32_t bufferType); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ttmlirTTNNMemoryConfigAttrGet( | ||
MlirContext ctx, MlirAttribute tensorMemoryLayoutAttr, | ||
MlirAttribute bufferTypeAttr); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ttmlirTTNNShapeAttrGet(MlirContext ctx, | ||
int64_t *shape, | ||
size_t shapeSize); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ttmlirTTNNMeshShapeAttrGet(MlirContext ctx, | ||
int64_t y, | ||
int64_t x); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // TTMLIR_C_TTNNATTRS_H |
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,66 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "ttmlir-c/TTNNAttrs.h" | ||
#include "mlir/CAPI/IR.h" | ||
#include "mlir/CAPI/Support.h" | ||
|
||
#include "ttmlir/Dialect/TTNN/IR/TTNNOpsAttrs.h" | ||
|
||
namespace mlir::tt::ttnn { | ||
|
||
MlirAttribute ttmlirTTNNCoreRangeAttrGet(MlirContext ctx, int64_t *offset, | ||
size_t offsetSize, int64_t *size, | ||
size_t sizeSize) { | ||
return wrap(CoreRangeAttr::get(unwrap(ctx), {offset, offset + offsetSize}, | ||
{size, size + sizeSize})); | ||
} | ||
|
||
MlirAttribute ttmlirTTNNCoreRangeArrayAttrGet(MlirContext ctx, | ||
MlirAttribute *coreRangeAttrs, | ||
size_t coreRangeAttrsSize) { | ||
std::vector<mlir::Attribute> coreRanges; | ||
for (size_t i = 0; i < coreRangeAttrsSize; i++) { | ||
coreRanges.push_back(mlir::cast<CoreRangeAttr>(unwrap(coreRangeAttrs[i]))); | ||
} | ||
return wrap(ArrayAttr::get(unwrap(ctx), coreRanges)); | ||
} | ||
|
||
MlirAttribute ttmlirTTNNLayoutAttrGet(MlirContext ctx, uint32_t layout) { | ||
return wrap(LayoutAttr::get(unwrap(ctx), static_cast<Layout>(layout))); | ||
} | ||
|
||
MlirAttribute ttmlirTTNNTensorMemoryLayoutAttrGet(MlirContext ctx, | ||
uint32_t tensorMemoryLayout) { | ||
return wrap(TensorMemoryLayoutAttr::get( | ||
unwrap(ctx), static_cast<TensorMemoryLayout>(tensorMemoryLayout))); | ||
} | ||
|
||
MlirAttribute ttmlirTTNNBufferTypeAttrGet(MlirContext ctx, | ||
uint32_t bufferType) { | ||
return wrap( | ||
BufferTypeAttr::get(unwrap(ctx), static_cast<BufferType>(bufferType))); | ||
} | ||
|
||
MlirAttribute | ||
ttmlirTTNNMemoryConfigAttrGet(MlirContext ctx, | ||
MlirAttribute tensorMemoryLayoutAttr, | ||
MlirAttribute bufferTypeAttr) { | ||
return wrap(MemoryConfigAttr::get( | ||
unwrap(ctx), | ||
mlir::cast<TensorMemoryLayoutAttr>(unwrap(tensorMemoryLayoutAttr)), | ||
mlir::cast<BufferTypeAttr>(unwrap(bufferTypeAttr)))); | ||
} | ||
|
||
MlirAttribute ttmlirTTNNShapeAttrGet(MlirContext ctx, int64_t *shape, | ||
size_t shapeSize) { | ||
return wrap(ShapeAttr::get(unwrap(ctx), {shape, shape + shapeSize})); | ||
} | ||
|
||
MlirAttribute ttmlirTTNNMeshShapeAttrGet(MlirContext ctx, int64_t y, | ||
int64_t x) { | ||
return wrap(MeshShapeAttr::get(unwrap(ctx), y, x)); | ||
} | ||
|
||
} // namespace mlir::tt::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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "ttmlir/Bindings/Python/TTMLIRModule.h" | ||
|
||
namespace mlir::ttmlir::python { | ||
void populateTTNNModule(py::module &m) { | ||
|
||
py::class_<tt::ttnn::CoreRangeAttr>(m, "CoreRangeAttr") | ||
.def_static("get", | ||
[](MlirContext ctx, std::vector<int64_t> offset, | ||
std::vector<int64_t> size) { | ||
return wrap(tt::ttnn::CoreRangeAttr::get(unwrap(ctx), | ||
offset, size)); | ||
}) | ||
.def_static( | ||
"get_with_grid", | ||
[](MlirContext ctx, MlirAttribute grid, std::vector<int64_t> offset) { | ||
llvm::SmallVector<int64_t> offsetVec{0, 0}; | ||
if (offset.size() == 2 && not(offset[0] == 0 && offset[1] == 0)) { | ||
offsetVec[0] = offset[0]; | ||
offsetVec[1] = offset[1]; | ||
} | ||
return wrap(tt::ttnn::CoreRangeAttr::get( | ||
unwrap(ctx), mlir::cast<tt::GridAttr>(unwrap(grid)), | ||
offsetVec)); | ||
}, | ||
py::arg("ctx"), py::arg("grid"), | ||
py::arg("offset") = std::vector<int64_t>{0, 0}); | ||
py::class_<tt::ttnn::LayoutAttr>(m, "LayoutAttr") | ||
.def_static("get", | ||
[](MlirContext ctx, uint32_t layout) { | ||
return wrap(tt::ttnn::LayoutAttr::get( | ||
unwrap(ctx), static_cast<tt::ttnn::Layout>(layout))); | ||
}) | ||
.def_property_readonly("value", [](tt::ttnn::LayoutAttr self) { | ||
return static_cast<uint32_t>(self.getValue()); | ||
}); | ||
py::class_<tt::ttnn::TensorMemoryLayoutAttr>(m, "TensorMemoryLayoutAttr") | ||
.def_static("get", | ||
[](MlirContext ctx, uint32_t tensorMemoryLayout) { | ||
return wrap(tt::ttnn::TensorMemoryLayoutAttr::get( | ||
unwrap(ctx), static_cast<tt::ttnn::TensorMemoryLayout>( | ||
tensorMemoryLayout))); | ||
}) | ||
.def_property_readonly("value", | ||
[](tt::ttnn::TensorMemoryLayoutAttr self) { | ||
return static_cast<uint32_t>(self.getValue()); | ||
}); | ||
py::class_<tt::ttnn::BufferTypeAttr>(m, "BufferTypeAttr") | ||
.def_static( | ||
"get", | ||
[](MlirContext ctx, uint32_t bufferType) { | ||
return wrap(tt::ttnn::BufferTypeAttr::get( | ||
unwrap(ctx), static_cast<tt::ttnn::BufferType>(bufferType))); | ||
}) | ||
.def_property_readonly("value", [](tt::ttnn::BufferTypeAttr self) { | ||
return static_cast<uint32_t>(self.getValue()); | ||
}); | ||
py::class_<tt::ttnn::MemoryConfigAttr>(m, "MemoryConfigAttr") | ||
.def_static("get", | ||
[](MlirContext ctx, | ||
tt::ttnn::TensorMemoryLayoutAttr tensorMemoryLayoutAttr, | ||
tt::ttnn::BufferTypeAttr bufferTypeAttr) { | ||
return wrap(tt::ttnn::MemoryConfigAttr::get( | ||
unwrap(ctx), tensorMemoryLayoutAttr, bufferTypeAttr)); | ||
}) | ||
.def_static( | ||
"get_by_value", | ||
[](MlirContext ctx, uint32_t tensorMemoryLayout, | ||
uint32_t bufferType) { | ||
return wrap(tt::ttnn::MemoryConfigAttr::get( | ||
unwrap(ctx), | ||
tt::ttnn::TensorMemoryLayoutAttr::get( | ||
unwrap(ctx), static_cast<tt::ttnn::TensorMemoryLayout>( | ||
tensorMemoryLayout)), | ||
tt::ttnn::BufferTypeAttr::get( | ||
unwrap(ctx), | ||
static_cast<tt::ttnn::BufferType>(bufferType)))); | ||
}) | ||
.def_property_readonly("tensor_memory_layout", | ||
&tt::ttnn::MemoryConfigAttr::getTensorMemoryLayout) | ||
.def_property_readonly("buffer_type", | ||
&tt::ttnn::MemoryConfigAttr::getBufferType); | ||
py::class_<tt::ttnn::ShapeAttr>(m, "ShapeAttr") | ||
.def_static("get", | ||
[](MlirContext ctx, std::vector<int64_t> shape) { | ||
return wrap(tt::ttnn::ShapeAttr::get(unwrap(ctx), shape)); | ||
}) | ||
.def_property_readonly("shape", [](tt::ttnn::ShapeAttr self) { | ||
return std::vector<int64_t>(self.getShape().begin(), | ||
self.getShape().end()); | ||
}); | ||
py::class_<tt::ttnn::MeshShapeAttr>(m, "MeshShapeAttr") | ||
.def_static("get", | ||
[](MlirContext ctx, int64_t y, int64_t x) { | ||
return wrap( | ||
tt::ttnn::MeshShapeAttr::get(unwrap(ctx), y, x)); | ||
}) | ||
.def_property_readonly("y", &tt::ttnn::MeshShapeAttr::getY) | ||
.def_property_readonly("x", &tt::ttnn::MeshShapeAttr::getX); | ||
} | ||
} // namespace mlir::ttmlir::python |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef PYTHON_BINDINGS_TTMLIR_TTNNOPS | ||
#define PYTHON_BINDINGS_TTMLIR_TTNNOPS | ||
|
||
include "ttmlir/Dialect/TTNN/IR/TTNNOps.td" | ||
|
||
#endif |
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,10 @@ | ||
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#ifndef PYTHON_BINDINGS_TTMLIR_TTNNENUMS | ||
#define PYTHON_BINDINGS_TTMLIR_TTNNENUMS | ||
|
||
include "ttmlir/Dialect/TTNN/IR/TTNNOpsEnums.td" | ||
|
||
#endif |
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,7 @@ | ||
# SPDX-FileCopyrightText: (c) 2024 Tenstorrent AI ULC | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from ._ttnn_ops_gen import * | ||
from ._ttnn_enum_gen import * | ||
from .._mlir_libs._ttmlir import register_dialect, ttnn_ir as ir |