Skip to content

[executorch] Create target for named_data_map #8110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion runtime/core/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def define_common_targets():
"defines.h",
"error.h",
"freeable_buffer.h",
"named_data_map.h",
"result.h",
"span.h",
],
Expand Down Expand Up @@ -133,6 +132,20 @@ def define_common_targets():
],
)

runtime.cxx_library(
name = "named_data_map",
exported_headers = [
"named_data_map.h",
],
visibility = [
"//executorch/...",
"@EXECUTORCH_CLIENTS",
],
exported_deps = [
":tensor_layout",
],
)

runtime.cxx_library(
name = "tensor_layout",
srcs = ["tensor_layout.cpp"],
Expand Down
2 changes: 1 addition & 1 deletion runtime/core/tensor_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Result<size_t> calculate_nbytes(
}
} // namespace

Result<TensorLayout> TensorLayout::create(
Result<const TensorLayout> TensorLayout::create(
Span<const int32_t> sizes,
Span<const uint8_t> dim_order,
executorch::aten::ScalarType scalar_type) {
Expand Down
10 changes: 5 additions & 5 deletions runtime/core/tensor_layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ET_EXPERIMENTAL TensorLayout final {
* @param[in] scalar_type The scalar type of the tensor.
* @return A Result containing the TensorLayout on success, or an error.
*/
static executorch::runtime::Result<TensorLayout> create(
static executorch::runtime::Result<const TensorLayout> create(
Span<const int32_t> sizes,
Span<const uint8_t> dim_order,
executorch::aten::ScalarType scalar_type);
Expand Down Expand Up @@ -77,16 +77,16 @@ class ET_EXPERIMENTAL TensorLayout final {
scalar_type_(scalar_type),
nbytes_(nbytes) {}
/// The sizes of the tensor.
Span<const int32_t> sizes_;
const Span<const int32_t> sizes_;

/// The dim order of the tensor.
Span<const uint8_t> dim_order_;
const Span<const uint8_t> dim_order_;

/// The scalar type of the tensor.
executorch::aten::ScalarType scalar_type_;
const executorch::aten::ScalarType scalar_type_;

/// The size in bytes of the tensor.
size_t nbytes_;
const size_t nbytes_;
};

} // namespace runtime
Expand Down
8 changes: 4 additions & 4 deletions runtime/core/test/tensor_layout_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TEST(TestTensorLayout, Ctor) {
Span<const int32_t> sizes_span = {sizes.data(), sizes.size()};
Span<const uint8_t> dim_order_span = {dim_order.data(), dim_order.size()};

Result<TensorLayout> layout_res =
Result<const TensorLayout> layout_res =
TensorLayout::create(sizes_span, dim_order_span, ScalarType::Float);
EXPECT_TRUE(layout_res.ok());

Expand All @@ -50,7 +50,7 @@ TEST(TestTensorLayout, Ctor_InvalidDimOrder) {
Span<const int32_t> sizes_span = {sizes.data(), sizes.size()};
Span<const uint8_t> dim_order_span = {dim_order.data(), dim_order.size()};

Result<TensorLayout> layout_res =
Result<const TensorLayout> layout_res =
TensorLayout::create(sizes_span, dim_order_span, ScalarType::Float);
EXPECT_EQ(layout_res.error(), Error::InvalidArgument);
}
Expand All @@ -61,7 +61,7 @@ TEST(TestTensorLayout, Ctor_InvalidSizes) {
Span<const int32_t> sizes_span = {sizes.data(), sizes.size()};
Span<const uint8_t> dim_order_span = {dim_order.data(), dim_order.size()};

Result<TensorLayout> layout_res =
Result<const TensorLayout> layout_res =
TensorLayout::create(sizes_span, dim_order_span, ScalarType::Float);
EXPECT_EQ(layout_res.error(), Error::InvalidArgument);
}
Expand All @@ -72,7 +72,7 @@ TEST(TestTensorLayout, Ctor_SizesDimOrderMismatch) {
Span<const int32_t> sizes_span = {sizes.data(), sizes.size()};
Span<const uint8_t> dim_order_span = {dim_order.data(), dim_order.size()};

Result<TensorLayout> layout_res =
Result<const TensorLayout> layout_res =
TensorLayout::create(sizes_span, dim_order_span, ScalarType::Float);
EXPECT_EQ(layout_res.error(), Error::InvalidArgument);
}
Loading