Skip to content

Commit 34e7ad8

Browse files
dbortfacebook-github-bot
authored andcommitted
Migrate backends/xnnpack to the new namespace (#5865)
Summary: Pull Request resolved: #5865 Move the XNNPACK backend out of the `torch::` namespace, and update to avoid using the `torch::` or `exec_aten::` namespaces. Also update utils.h to use a namespace that matches the rest of the code (`xnnpack::utils` instead of `qnnpack_utils`). Reviewed By: mcr229 Differential Revision: D63876576 fbshipit-source-id: 42624fdaf35ee8c45c71e57bc9768613367ac44b
1 parent a6d67c7 commit 34e7ad8

File tree

14 files changed

+142
-103
lines changed

14 files changed

+142
-103
lines changed

backends/xnnpack/runtime/XNNCompiler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
#pragma clang diagnostic ignored "-Wmissing-prototypes"
1717
#pragma clang diagnostic ignored "-Wglobal-constructors"
1818

19-
namespace torch {
20-
namespace executor {
19+
namespace executorch {
20+
namespace backends {
2121
namespace xnnpack {
2222
namespace delegate {
2323

24+
using executorch::runtime::Error;
25+
using executorch::runtime::MemoryAllocator;
26+
using executorch::runtime::Result;
27+
2428
/*
2529
* Provide compile-time allocation.
2630
*/
@@ -1811,5 +1815,5 @@ ET_NODISCARD Error XNNCompiler::compileModel(
18111815

18121816
} // namespace delegate
18131817
} // namespace xnnpack
1814-
} // namespace executor
1815-
} // namespace torch
1818+
} // namespace backends
1819+
} // namespace executorch

backends/xnnpack/runtime/XNNCompiler.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include <memory>
1616
#include <vector>
1717

18-
namespace torch {
19-
namespace executor {
18+
namespace executorch {
19+
namespace backends {
2020
namespace xnnpack {
2121
namespace delegate {
2222

@@ -25,15 +25,15 @@ class XNNCompiler {
2525
// Takes Flatbuffer Serialized XNNPACK Model and rebuilds the xnn-subgraph
2626
// returns an executor object that holds the xnn runtime object which we
2727
// can then use to set inputs and run inference using the xnn graph.
28-
ET_NODISCARD static Error compileModel(
28+
ET_NODISCARD static executorch::runtime::Error compileModel(
2929
const void* buffer_pointer,
3030
size_t num_bytes,
3131
XNNExecutor* executor,
32-
MemoryAllocator* runtime_allocator,
32+
executorch::runtime::MemoryAllocator* runtime_allocator,
3333
xnn_workspace_t workspace);
3434
};
3535

3636
} // namespace delegate
3737
} // namespace xnnpack
38-
} // namespace executor
39-
} // namespace torch
38+
} // namespace backends
39+
} // namespace executorch

backends/xnnpack/runtime/XNNExecutor.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88

99
#include <executorch/backends/xnnpack/runtime/XNNExecutor.h>
1010

11-
namespace torch {
12-
namespace executor {
11+
namespace executorch {
12+
namespace backends {
1313
namespace xnnpack {
1414
namespace delegate {
1515

16-
using Tensor = exec_aten::Tensor;
17-
using ScalarType = exec_aten::ScalarType;
18-
using SizesType = exec_aten::SizesType;
16+
using executorch::aten::ScalarType;
17+
using executorch::aten::SizesType;
18+
using executorch::aten::Tensor;
19+
using executorch::runtime::BackendExecutionContext;
20+
using executorch::runtime::Error;
21+
using executorch::runtime::EValue;
22+
using executorch::runtime::is_contiguous_dim_order;
23+
using executorch::runtime::kTensorDimensionLimit;
1924

2025
/**
2126
* Initializes the XNNExecutor with the runtime and given number of
@@ -204,7 +209,7 @@ ET_NODISCARD Error XNNExecutor::resize_outputs(EValue** args) const {
204209
expected_output_size[d] = static_cast<SizesType>(dims[d]);
205210
}
206211

207-
exec_aten::ArrayRef<SizesType> output_size{
212+
executorch::aten::ArrayRef<SizesType> output_size{
208213
expected_output_size, static_cast<size_t>(num_dim)};
209214

210215
ET_LOG(Debug, "Resizing output tensor to a new shape");
@@ -231,5 +236,5 @@ ET_NODISCARD Error XNNExecutor::resize_outputs(EValue** args) const {
231236

232237
} // namespace delegate
233238
} // namespace xnnpack
234-
} // namespace executor
235-
} // namespace torch
239+
} // namespace backends
240+
} // namespace executorch

backends/xnnpack/runtime/XNNExecutor.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <memory>
2020
#include <vector>
2121

22-
namespace torch {
23-
namespace executor {
22+
namespace executorch {
23+
namespace backends {
2424
namespace xnnpack {
2525
namespace delegate {
2626

@@ -51,7 +51,7 @@ class XNNExecutor {
5151
* The input/output ids are expected to be sorted in order of their
5252
* flatbuffer id_outs
5353
*/
54-
ET_NODISCARD Error initialize(
54+
ET_NODISCARD executorch::runtime::Error initialize(
5555
xnn_runtime_t runtime,
5656
std::vector<uint32_t>&& input_ids,
5757
std::vector<uint32_t>&& output_ids);
@@ -62,24 +62,27 @@ class XNNExecutor {
6262
* input shapes will be propagated through the runtime, and perform
6363
* any additional memory planning as needed
6464
*/
65-
ET_NODISCARD Error prepare_args(EValue** args);
65+
ET_NODISCARD executorch::runtime::Error prepare_args(
66+
executorch::runtime::EValue** args);
6667

6768
/**
6869
* Executes the graph using the args prepared at prepare_args().
6970
*/
70-
ET_NODISCARD Error forward(BackendExecutionContext& context);
71+
ET_NODISCARD executorch::runtime::Error forward(
72+
executorch::runtime::BackendExecutionContext& context);
7173

7274
/**
7375
* Prepares the outputs to be returned by the delegate
7476
*
7577
* Performs any post processing of outputs like tensor resizing
7678
*/
77-
ET_NODISCARD Error resize_outputs(EValue** args) const;
79+
ET_NODISCARD executorch::runtime::Error resize_outputs(
80+
executorch::runtime::EValue** args) const;
7881

7982
friend class XNNCompiler;
8083
};
8184

8285
} // namespace delegate
8386
} // namespace xnnpack
84-
} // namespace executor
85-
} // namespace torch
87+
} // namespace backends
88+
} // namespace executorch

backends/xnnpack/runtime/XNNHeader.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
#pragma clang diagnostic ignored "-Wdeprecated"
1717

18-
namespace torch {
19-
namespace executor {
18+
namespace executorch {
19+
namespace backends {
2020
namespace xnnpack {
2121
namespace delegate {
2222

23+
using executorch::runtime::Error;
24+
using executorch::runtime::Result;
25+
2326
namespace {
2427
/// Interprets the 8 bytes at `data` as a little-endian uint64_t.
2528
uint64_t GetUInt64LE(const uint8_t* data) {
@@ -73,5 +76,5 @@ constexpr char XNNHeader::kMagic[kMagicSize];
7376

7477
} // namespace delegate
7578
} // namespace xnnpack
76-
} // namespace executor
77-
} // namespace torch
79+
} // namespace backends
80+
} // namespace executorch

backends/xnnpack/runtime/XNNHeader.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include <executorch/runtime/core/result.h>
1212

13-
namespace torch {
14-
namespace executor {
13+
namespace executorch {
14+
namespace backends {
1515
namespace xnnpack {
1616
namespace delegate {
1717

@@ -98,7 +98,9 @@ struct XNNHeader {
9898
* error if size was too short, if the header was not found, or if the
9999
* header appeared to be corrupt.
100100
*/
101-
static Result<XNNHeader> Parse(const void* data, size_t size);
101+
static executorch::runtime::Result<XNNHeader> Parse(
102+
const void* data,
103+
size_t size);
102104

103105
/**
104106
* The offset in bytes to the beginning of the flatbuffer data.
@@ -121,5 +123,5 @@ struct XNNHeader {
121123

122124
} // namespace delegate
123125
} // namespace xnnpack
124-
} // namespace executor
125-
} // namespace torch
126+
} // namespace backends
127+
} // namespace executorch

backends/xnnpack/runtime/XNNPACKBackend.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,19 @@
1717

1818
#pragma clang diagnostic ignored "-Wglobal-constructors"
1919

20-
namespace torch {
21-
namespace executor {
20+
namespace executorch {
21+
namespace backends {
22+
23+
using executorch::runtime::ArrayRef;
24+
using executorch::runtime::Backend;
25+
using executorch::runtime::BackendExecutionContext;
26+
using executorch::runtime::BackendInitContext;
27+
using executorch::runtime::CompileSpec;
28+
using executorch::runtime::DelegateHandle;
29+
using executorch::runtime::Error;
30+
using executorch::runtime::EValue;
31+
using executorch::runtime::FreeableBuffer;
32+
using executorch::runtime::Result;
2233

2334
class XnnpackBackend final : public ::executorch::runtime::BackendInterface {
2435
public:
@@ -145,5 +156,5 @@ Backend backend{"XnnpackBackend", &cls};
145156
static auto success_with_compiler = register_backend(backend);
146157
} // namespace
147158

148-
} // namespace executor
149-
} // namespace torch
159+
} // namespace backends
160+
} // namespace executorch

backends/xnnpack/runtime/XNNStatus.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <assert.h>
1212
#include <xnnpack.h>
1313

14-
namespace torch {
15-
namespace executor {
14+
namespace executorch {
15+
namespace backends {
1616
namespace xnnpack {
1717
namespace delegate {
1818

@@ -34,5 +34,5 @@ inline const char* xnn_status_to_string(enum xnn_status type) {
3434

3535
} // namespace delegate
3636
} // namespace xnnpack
37-
} // namespace executor
38-
} // namespace torch
37+
} // namespace backends
38+
} // namespace executorch

backends/xnnpack/runtime/profiling/XNNProfiler.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
#include <unordered_map>
2323
// NOLINTEND
2424

25-
namespace torch::executor::xnnpack::delegate::profiling {
25+
namespace executorch::backends::xnnpack::delegate::profiling {
26+
27+
using executorch::runtime::Error;
28+
using executorch::runtime::EventTracer;
2629

2730
#if defined(ET_EVENT_TRACER_ENABLED) || defined(ENABLE_XNNPACK_PROFILING)
31+
2832
XNNProfiler::XNNProfiler()
2933
: state_(XNNProfilerState::Uninitialized), run_count_(0) {}
3034

@@ -210,10 +214,10 @@ void XNNProfiler::submit_trace() {
210214

211215
auto end_time = time + interval_ticks;
212216

213-
torch::executor::event_tracer_log_profiling_delegate(
217+
executorch::runtime::event_tracer_log_profiling_delegate(
214218
event_tracer_,
215219
name_formatted.c_str(),
216-
/*delegate_debug_id=*/static_cast<torch::executor::DebugHandle>(-1),
220+
/*delegate_debug_id=*/static_cast<executorch::runtime::DebugHandle>(-1),
217221
time,
218222
end_time);
219223

@@ -246,4 +250,4 @@ Error XNNProfiler::end() {
246250

247251
#endif
248252

249-
} // namespace torch::executor::xnnpack::delegate::profiling
253+
} // namespace executorch::backends::xnnpack::delegate::profiling

backends/xnnpack/runtime/profiling/XNNProfiler.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include <xnnpack.h>
1515
#include <vector>
1616

17-
namespace torch {
18-
namespace executor {
17+
namespace executorch {
18+
namespace backends {
1919
namespace xnnpack {
2020
namespace delegate {
2121
namespace profiling {
@@ -30,24 +30,25 @@ class XNNProfiler {
3030
* Initialize the profiler. This must be called after model is
3131
* compiled and before calling begin_execution.
3232
*/
33-
Error initialize(xnn_runtime_t runtime);
33+
executorch::runtime::Error initialize(xnn_runtime_t runtime);
3434

3535
/**
3636
* Start a new profiling session. This is typically invoked
3737
* immediately before invoking the XNNPACK runtime as part
3838
* of a forward pass.
3939
*/
40-
Error start(EventTracer* event_tracer);
40+
executorch::runtime::Error start(
41+
executorch::runtime::EventTracer* event_tracer);
4142

4243
/**
4344
* End a profiling session. This is typically invoked immediately
4445
* after the XNNPACK runtime invocation completes.
4546
*/
46-
Error end();
47+
executorch::runtime::Error end();
4748

4849
private:
4950
#if defined(ET_EVENT_TRACER_ENABLED) || defined(ENABLE_XNNPACK_PROFILING)
50-
EventTracer* event_tracer_;
51+
executorch::runtime::EventTracer* event_tracer_;
5152
xnn_runtime_t runtime_;
5253
XNNProfilerState state_;
5354

@@ -64,9 +65,9 @@ class XNNProfiler {
6465
std::vector<uint64_t> op_timings_sum_;
6566
#endif
6667

67-
Error get_runtime_operator_names();
68-
Error get_runtime_num_operators();
69-
Error get_runtime_operator_timings();
68+
executorch::runtime::Error get_runtime_operator_names();
69+
executorch::runtime::Error get_runtime_num_operators();
70+
executorch::runtime::Error get_runtime_operator_timings();
7071

7172
void log_operator_timings();
7273

@@ -80,5 +81,5 @@ class XNNProfiler {
8081
} // namespace profiling
8182
} // namespace delegate
8283
} // namespace xnnpack
83-
} // namespace executor
84-
} // namespace torch
84+
} // namespace backends
85+
} // namespace executorch

backends/xnnpack/runtime/utils/utils.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
#include <executorch/runtime/platform/assert.h>
1111
#include <cinttypes>
1212

13-
namespace torch {
14-
namespace executor {
15-
namespace qnnpack_utils {
13+
namespace executorch {
14+
namespace backends {
15+
namespace xnnpack {
16+
namespace utils {
1617

17-
using Tensor = exec_aten::Tensor;
18-
using ScalarType = exec_aten::ScalarType;
18+
using executorch::aten::ScalarType;
19+
using executorch::aten::Tensor;
20+
using executorch::runtime::Error;
1921

2022
constexpr float SMALL_SCALE_THRESHOLD = 6.1e-5f;
2123

@@ -222,6 +224,8 @@ void quantize_tensor_arm64_q8_wrapper<int8_t>(
222224
quantize_tensor_arm64_q8<int8_t, int8x8_t>(in, out, N, scale, zero_point);
223225
}
224226
#endif
225-
} // namespace qnnpack_utils
226-
} // namespace executor
227-
} // namespace torch
227+
228+
} // namespace utils
229+
} // namespace xnnpack
230+
} // namespace backends
231+
} // namespace executorch

0 commit comments

Comments
 (0)