Skip to content

Commit c7ebdda

Browse files
committed
[slimtensor] integration into backend
Differential Revision: [D90606409](https://our.internmc.facebook.com/intern/diff/D90606409/) ghstack-source-id: 333239044 Pull Request resolved: #16565
1 parent 38c00e3 commit c7ebdda

32 files changed

+3240
-8815
lines changed

backends/aoti/aoti_delegate_handle.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
#include <executorch/runtime/core/error.h>
1212
#include <executorch/runtime/core/evalue.h>
1313
#include <string>
14+
#include <vector>
15+
16+
#ifdef CUDA_AVAILABLE
17+
#include <executorch/backends/aoti/slim/core/slim_tensor.h>
18+
#endif
1419

1520
namespace executorch {
1621
namespace backends {
@@ -95,6 +100,13 @@ struct AOTIDelegateHandle {
95100
AOTInductorModelContainerGetNumOutputsFunc get_num_outputs;
96101
AOTInductorModelContainerRunFunc run;
97102
AOTInductorModelUpdateConstantsFromBlobFunc update_constants_from_blob;
103+
104+
#ifdef CUDA_AVAILABLE
105+
// Cached output tensors for skip-copy optimization.
106+
// When copy-skip is enabled, output SlimTensors are cached here to keep
107+
// GPU memory alive while the caller processes the results.
108+
std::vector<slim::SlimTensor> cached_outputs;
109+
#endif
98110
};
99111

100112
} // namespace aoti

backends/aoti/common_shims.cpp

Lines changed: 0 additions & 268 deletions
This file was deleted.

backends/aoti/slim/c10/cuda/Exception.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
/// Checks a CUDA expression and aborts on error.
2121
/// @param EXPR The CUDA expression to check.
22+
#ifndef ET_CUDA_CHECK
2223
#define ET_CUDA_CHECK(EXPR) \
2324
do { \
2425
const cudaError_t __err = EXPR; \
2526
ET_CHECK_MSG( \
2627
__err == cudaSuccess, "CUDA error: %s", cudaGetErrorString(__err)); \
2728
} while (0)
29+
#endif
2830

2931
/// Checks a CUDA expression and logs a warning on error (non-fatal).
3032
/// @param EXPR The CUDA expression to check.

backends/aoti/targets.bzl

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,22 @@ def define_common_targets():
3333
],
3434
)
3535

36-
# AOTI common shims functionality
36+
# AOTI common shims functionality (header-only library)
37+
# The caller determines which tensor type is used by defining CUDA_AVAILABLE.
38+
# - With CUDA_AVAILABLE=1: Uses SlimTensor
39+
# - Without CUDA_AVAILABLE: Uses ETensor
3740
runtime.cxx_library(
3841
name = "common_shims",
39-
srcs = [
40-
"common_shims.cpp",
41-
],
4242
headers = [
4343
"common_shims.h",
4444
"export.h",
4545
"utils.h",
4646
],
47-
# @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
48-
link_whole = True,
49-
supports_python_dlopen = True,
50-
# Constructor needed for backend registration.
51-
compiler_flags = ["-Wno-global-constructors"],
5247
visibility = ["PUBLIC"],
53-
deps = [
48+
exported_deps = [
5449
"//executorch/runtime/core:core",
5550
"//executorch/runtime/core/exec_aten:lib",
51+
"//executorch/backends/aoti/slim/core:slimtensor",
5652
],
5753
)
5854

@@ -86,21 +82,3 @@ def define_common_targets():
8682
":delegate_handle",
8783
],
8884
)
89-
90-
# SlimTensor-based common shims (header-only library)
91-
# The caller determines which tensor type is used by defining CUDA_AVAILABLE.
92-
# - With CUDA_AVAILABLE=1: Uses SlimTensor
93-
# - Without CUDA_AVAILABLE: Uses ETensor
94-
runtime.cxx_library(
95-
name = "common_shims_slim",
96-
headers = [
97-
"common_shims_slim.h",
98-
"export.h",
99-
],
100-
visibility = ["@EXECUTORCH_CLIENTS"],
101-
deps = [
102-
"//executorch/runtime/core:core",
103-
"//executorch/runtime/core/exec_aten:lib",
104-
"//executorch/backends/aoti/slim/core:slimtensor",
105-
],
106-
)

backends/aoti/tests/TARGETS

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,8 @@ cpp_unittest(
88
srcs = [
99
"test_common_shims.cpp",
1010
],
11-
headers = [
12-
"utils.h",
13-
],
1411
deps = [
1512
"//executorch/backends/aoti:common_shims",
16-
"//executorch/extension/tensor:tensor",
17-
"//executorch/runtime/core:core",
18-
"//executorch/runtime/platform:platform",
19-
"//executorch/runtime/core/exec_aten/testing_util:tensor_util",
20-
"//executorch/runtime/core/exec_aten:lib",
21-
"//executorch/extension/tensor:tensor",
22-
],
23-
)
24-
25-
cpp_unittest(
26-
name = "test_common_shims_slim",
27-
srcs = [
28-
"test_common_shims_slim.cpp",
29-
],
30-
deps = [
31-
"//executorch/backends/aoti:common_shims_slim",
3213
"//executorch/backends/aoti/slim/core:slimtensor",
3314
"//executorch/backends/aoti/slim/factory:empty",
3415
"//executorch/runtime/core:core",

0 commit comments

Comments
 (0)