Skip to content

Commit a7a9565

Browse files
kirklandsignlucylq
andauthored
[executorch] Create target for named_data_map
Pull Request resolved: #8110 named_data_map depends on tensor_layout, which depends on exec_lib. Move it out from core, as we have a circular dep when exec_lib is part of core. Also make TensorLayout::create return a const. ghstack-source-id: 264157518 Differential Revision: [D68972364](https://our.internmc.facebook.com/intern/diff/D68972364/) Co-authored-by: lucylq <lfq@meta.com>
1 parent 38e0bc7 commit a7a9565

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

runtime/core/targets.bzl

+14-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def define_common_targets():
4141
"defines.h",
4242
"error.h",
4343
"freeable_buffer.h",
44-
"named_data_map.h",
4544
"result.h",
4645
"span.h",
4746
],
@@ -133,6 +132,20 @@ def define_common_targets():
133132
],
134133
)
135134

135+
runtime.cxx_library(
136+
name = "named_data_map",
137+
exported_headers = [
138+
"named_data_map.h",
139+
],
140+
visibility = [
141+
"//executorch/...",
142+
"@EXECUTORCH_CLIENTS",
143+
],
144+
exported_deps = [
145+
":tensor_layout",
146+
],
147+
)
148+
136149
runtime.cxx_library(
137150
name = "tensor_layout",
138151
srcs = ["tensor_layout.cpp"],

runtime/core/tensor_layout.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Result<size_t> calculate_nbytes(
3030
}
3131
} // namespace
3232

33-
Result<TensorLayout> TensorLayout::create(
33+
Result<const TensorLayout> TensorLayout::create(
3434
Span<const int32_t> sizes,
3535
Span<const uint8_t> dim_order,
3636
executorch::aten::ScalarType scalar_type) {

runtime/core/tensor_layout.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ET_EXPERIMENTAL TensorLayout final {
3333
* @param[in] scalar_type The scalar type of the tensor.
3434
* @return A Result containing the TensorLayout on success, or an error.
3535
*/
36-
static executorch::runtime::Result<TensorLayout> create(
36+
static executorch::runtime::Result<const TensorLayout> create(
3737
Span<const int32_t> sizes,
3838
Span<const uint8_t> dim_order,
3939
executorch::aten::ScalarType scalar_type);
@@ -77,16 +77,16 @@ class ET_EXPERIMENTAL TensorLayout final {
7777
scalar_type_(scalar_type),
7878
nbytes_(nbytes) {}
7979
/// The sizes of the tensor.
80-
Span<const int32_t> sizes_;
80+
const Span<const int32_t> sizes_;
8181

8282
/// The dim order of the tensor.
83-
Span<const uint8_t> dim_order_;
83+
const Span<const uint8_t> dim_order_;
8484

8585
/// The scalar type of the tensor.
86-
executorch::aten::ScalarType scalar_type_;
86+
const executorch::aten::ScalarType scalar_type_;
8787

8888
/// The size in bytes of the tensor.
89-
size_t nbytes_;
89+
const size_t nbytes_;
9090
};
9191

9292
} // namespace runtime

runtime/core/test/tensor_layout_test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TEST(TestTensorLayout, Ctor) {
2626
Span<const int32_t> sizes_span = {sizes.data(), sizes.size()};
2727
Span<const uint8_t> dim_order_span = {dim_order.data(), dim_order.size()};
2828

29-
Result<TensorLayout> layout_res =
29+
Result<const TensorLayout> layout_res =
3030
TensorLayout::create(sizes_span, dim_order_span, ScalarType::Float);
3131
EXPECT_TRUE(layout_res.ok());
3232

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

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

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

75-
Result<TensorLayout> layout_res =
75+
Result<const TensorLayout> layout_res =
7676
TensorLayout::create(sizes_span, dim_order_span, ScalarType::Float);
7777
EXPECT_EQ(layout_res.error(), Error::InvalidArgument);
7878
}

0 commit comments

Comments
 (0)