Skip to content

Commit 0d19ade

Browse files
committed
Update on "[ExecuTorch] Add broadcast support for optimized add op"
Summary: This brings add op to feature parity, wrt, broadcasting, to mul op in optimized kernels lib Test Plan: tests added Reviewers: Subscribers: Tasks: Tags: cc larryliu0820 manuelcandales Differential Revision: [D69491814](https://our.internmc.facebook.com/intern/diff/D69491814) [ghstack-poisoned]
2 parents 5fb4107 + 9e0855b commit 0d19ade

File tree

7 files changed

+68
-18
lines changed

7 files changed

+68
-18
lines changed

backends/xnnpack/partition/config/gemm_configs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ def check_constraints(self, node: torch.fx.Node, ep: ExportedProgram) -> bool:
334334
is_transpose = node.args[6]
335335
groups = cast(int, node.args[8])
336336

337+
# XNNPack does not support non-zero output padding in transposed
338+
# convolutions.
339+
if is_transpose and any(
340+
out_pad != 0 for out_pad in cast(List[int], node.args[7])
341+
):
342+
why(
343+
node,
344+
"XNNPACK does not support transposed convolutions with"
345+
"non-zero output padding",
346+
)
347+
return False
348+
337349
if (
338350
is_transpose
339351
and weight_quant_params is not None

backends/xnnpack/test/ops/test_conv2d.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,3 +657,42 @@ def get_inputs(self):
657657
quant_config=None,
658658
conv_count=1,
659659
)
660+
661+
def test_padded_output_tconv(self):
662+
class TConv2d(torch.nn.Module):
663+
def __init__(self):
664+
super().__init__()
665+
self.conv = torch.nn.ConvTranspose2d(
666+
in_channels=2,
667+
out_channels=1,
668+
kernel_size=(3, 3),
669+
stride=(2, 2),
670+
padding=(1, 1),
671+
output_padding=(0, 1),
672+
dilation=(1, 1),
673+
groups=1,
674+
bias=True,
675+
).to(torch.float)
676+
677+
def forward(self, x):
678+
return self.conv(x)
679+
680+
m = TConv2d()
681+
inputs = (torch.randn(1, 2, 8, 8),)
682+
tester = Tester(m.eval(), inputs)
683+
684+
conv_count: int = 1
685+
op = "torch.ops.aten.conv_transpose2d"
686+
687+
(tester.export().check_count({op: conv_count}).to_edge_transform_and_lower())
688+
689+
# tconv should not be offloaded to XNNPack, since output padding is not
690+
(
691+
tester.check(
692+
["executorch_exir_dialects_edge__ops_aten_convolution_default"]
693+
)
694+
.check_not(["torch.ops.higher_order.executorch_call_delegate"])
695+
.to_executorch()
696+
.serialize()
697+
.run_method_and_compare_outputs(qtol=1)
698+
)

examples/xnnpack/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Once we have the model binary (pte) file, then let's run it with ExecuTorch runt
3131
cd executorch
3232

3333
# Get a clean cmake-out directory
34-
./install_requiements.sh --clean
34+
./install_executorch.sh --clean
3535
mkdir cmake-out
3636

3737
# Configure cmake

extension/flat_tensor/serialize/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# Flatbuffer schema header lib. Please this file formatted by running:
7+
# Flatbuffer schema header lib. Please keep this file formatted by running:
88
# ~~~
99
# cmake-format -i CMakeLists.txt
1010
# ~~~

extension/flat_tensor/test/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# @generated by test/utils/generate_gtest_cmakelists.py
87
#
98
# This file should be formatted with
109
# ~~~

runtime/executor/program.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ Result<const void*> Program::get_constant_buffer_data(
294294
// loaded during Program::load, or stored inside the flatbuffer data
295295
// (constant_buffer).
296296
if (constant_segment_data_.data() != nullptr) {
297-
size_t num_elems = internal_program->constant_segment()->offsets()->size();
297+
const auto* constant_segment = internal_program->constant_segment();
298+
size_t num_elems = constant_segment == nullptr
299+
? 0
300+
: (constant_segment->offsets() == nullptr
301+
? 0
302+
: constant_segment->offsets()->size());
298303
ET_CHECK_OR_RETURN_ERROR(
299304
buffer_index < num_elems,
300305
InvalidArgument,
@@ -326,25 +331,27 @@ Result<const void*> Program::get_constant_buffer_data(
326331
offset);
327332
} else {
328333
// Otherwise, the constant data is stored inside Program.constant_buffer.
329-
size_t num_elems = internal_program->constant_buffer()->size();
334+
const auto* constant_buffer_ptr = internal_program->constant_buffer();
335+
size_t num_elems =
336+
constant_buffer_ptr == nullptr ? 0 : constant_buffer_ptr->size();
330337
ET_CHECK_OR_RETURN_ERROR(
331338
buffer_index < num_elems,
332339
InvalidArgument,
333340
"Constant buffer index %zu invalid for program constant buffer range %zu",
334341
buffer_index,
335342
num_elems);
336343

337-
const auto& constant_buffer = *internal_program->constant_buffer();
338-
344+
const auto& constant_buffer = *constant_buffer_ptr;
345+
const auto* storage = constant_buffer[buffer_index]->storage();
346+
auto storage_size = storage == nullptr ? 0 : storage->size();
339347
ET_CHECK_OR_RETURN_ERROR(
340-
constant_buffer[buffer_index]->storage()->size() <= nbytes,
348+
storage_size <= nbytes,
341349
InvalidArgument,
342350
"Constant buffer size %u larger than allocated nbytes %zu",
343-
constant_buffer[buffer_index]->storage()->size(),
351+
storage_size,
344352
nbytes);
345353

346-
return static_cast<const void*>(
347-
constant_buffer[buffer_index]->storage()->data());
354+
return storage->data();
348355
}
349356
}
350357

test/utils/OSSTestConfig.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@
1818
"../print_evalue.cpp"
1919
]
2020
},
21-
{
22-
"directory": "extension/flat_tensor/test",
23-
"sources": [
24-
"flat_tensor_data_map_test.cpp",
25-
"flat_tensor_header_test.cpp"
26-
]
27-
},
2821
{
2922
"directory": "extension/kernel_util/test",
3023
"sources": [

0 commit comments

Comments
 (0)