Skip to content
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
19 changes: 19 additions & 0 deletions cpp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,25 @@ cc_library(
}),
)

# Registration only, for the same reason as the allocator above: the kernel
# registry aborts when the same kernel is registered twice, so this cannot ride
# along with the backend. Executables that run a TensorRT delegated program
# depend on this directly.
#
# Not part of :executorch_backend_source_files. The CMake build of the reference
# runner links executorch::kernels, which already registers these.
cc_library(
name = "tensorrt_executorch_device_copy_kernels",
srcs = [
"src/torch_tensorrt/executorch/RegisterDeviceCopyKernels.cpp",
],
alwayslink = True,
deps = [
"@executorch//:executorch_device_copy_kernels",
"@executorch//:executorch_headers",
],
)

cc_library(
name = "tensorrt_executorch_backend",
srcs = [
Expand Down
32 changes: 32 additions & 0 deletions cpp/src/torch_tensorrt/executorch/RegisterDeviceCopyKernels.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <executorch/extension/kernel_util/make_boxed_from_unboxed_functor.h>

namespace torch {
namespace executor {
namespace native {

using executorch::aten::Tensor;
using executorch::runtime::KernelRuntimeContext;

// ExecuTorch publishes no header for its portable kernel sources, and the
// Bazel target that owns this file compiles op__device_copy.cpp straight from
// the pinned tree, so the two entry points are declared here.
Tensor& _h2d_copy_out(KernelRuntimeContext& ctx, const Tensor& self, Tensor& out);
Tensor& _d2h_copy_out(KernelRuntimeContext& ctx, const Tensor& self, Tensor& out);

} // namespace native
} // namespace executor
} // namespace torch

// A program delegated to TensorRT still runs two ops outside the delegate: the
// host to device copy of its inputs and the device to host copy of its outputs,
// which the device placement pass inserts at export time. ExecuTorch registers
// their kernels from a generated kernel library, which this Bazel build does
// not produce, so a runner linking the core runtime alone fails every
// load_method with
//
// kernel 'et_copy::_h2d_copy.out' not found.
//
// Register those two rather than the whole portable kernel set, which a fully
// delegated program never calls.
EXECUTORCH_LIBRARY(et_copy, "_h2d_copy.out", torch::executor::native::_h2d_copy_out);
EXECUTORCH_LIBRARY(et_copy, "_d2h_copy.out", torch::executor::native::_d2h_copy_out);
2 changes: 2 additions & 0 deletions examples/executorch_reference_runner/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cc_binary(
deps = [
"//cpp:tensorrt_executorch_backend",
"//cpp:tensorrt_executorch_cuda_device_allocator",
"//cpp:tensorrt_executorch_device_copy_kernels",
"@executorch//:executorch_core",
"@executorch//:executorch_file_data_loader",
"@executorch//:extension_cuda",
Expand All @@ -38,6 +39,7 @@ cc_binary(
deps = [
"//cpp:tensorrt_executorch_backend",
"//cpp:tensorrt_executorch_cuda_device_allocator",
"//cpp:tensorrt_executorch_device_copy_kernels",
"@cuda//:cudart",
"@executorch//:executorch_core",
"@executorch//:executorch_file_data_loader",
Expand Down
9 changes: 2 additions & 7 deletions tests/py/dynamo/conversion/test_cumsum_aten.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def forward(self, x):
)
return

self.run_test(
Cumsum(), inputs, immutable_weights=False, use_dynamo_tracer=True
)
self.run_test(Cumsum(), inputs, immutable_weights=False, use_dynamo_tracer=True)

@parameterized.expand(
[
Expand Down Expand Up @@ -108,10 +106,7 @@ def forward(self, x):
== opt_shape[positive_dim]
== max_shape[positive_dim]
)
if (
has_static_trip_count
and not is_tensorrt_rtx_version_supported("1.7")
):
if has_static_trip_count and not is_tensorrt_rtx_version_supported("1.7"):
with self.assertRaises(UnsupportedOperatorException):
self.run_test_with_dynamic_shape(
Cumsum(),
Expand Down
15 changes: 15 additions & 0 deletions third_party/executorch/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ cc_library(
],
)

# The kernels behind the device copies that an exported program runs around the
# delegate. In the pinned ExecuTorch release these reach a binary only through
# the generated kernel library, which this overlay does not build, so compile
# the two implementations on their own. Registering them is left to
# //cpp:tensorrt_executorch_device_copy_kernels, because a binary that already
# gets them from ExecuTorch's own kernel library must not register them twice.
cc_library(
name = "executorch_device_copy_kernels",
srcs = ["executorch/kernels/portable/cpu/op__device_copy.cpp"],
deps = [
":executorch_core",
":executorch_headers",
],
)

cc_library(
name = "executorch_headers",
hdrs = glob(
Expand Down
Loading