Skip to content

Commit 50f70f3

Browse files
dbortfacebook-github-bot
authored andcommitted
Migrate backends/mediatek to the new namespace (#5956)
Summary: Pull Request resolved: #5956 Move the mediatek backend out of the torch:: namespace, and update to avoid using the torch:: or exec_aten:: namespaces. Reviewed By: cccclai Differential Revision: D63928380 fbshipit-source-id: 685529e4aab2cc2bdd66bb100dba0cf61e5286b4
1 parent cb3a546 commit 50f70f3

File tree

6 files changed

+64
-41
lines changed

6 files changed

+64
-41
lines changed

backends/mediatek/runtime/NeuronBackend.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,20 @@
1919
#include <new>
2020
#include <unordered_set>
2121

22-
namespace torch {
23-
namespace executor {
22+
namespace executorch {
23+
namespace backends {
24+
namespace neuron {
25+
26+
using executorch::runtime::ArrayRef;
27+
using executorch::runtime::BackendExecutionContext;
28+
using executorch::runtime::BackendInitContext;
29+
using executorch::runtime::CompileSpec;
30+
using executorch::runtime::DelegateHandle;
31+
using executorch::runtime::Error;
32+
using executorch::runtime::EValue;
33+
using executorch::runtime::FreeableBuffer;
34+
using executorch::runtime::MemoryAllocator;
35+
using executorch::runtime::Result;
2436

2537
const char kHighAddrKey[] = "HighAddr";
2638
const char kImportForeverKey[] = "ImportForever";
@@ -94,8 +106,8 @@ Error NeuronExecuTorchDelegate::execute(
94106
return Error::InvalidState;
95107
};
96108

97-
auto allocator =
98-
dynamic_cast<neuron::BufferAllocator*>(context.get_temp_allocator());
109+
auto allocator = dynamic_cast<torch::executor::neuron::BufferAllocator*>(
110+
context.get_temp_allocator());
99111
size_t inputCount = mInputSizes.size(), outputCount = mOutputSizes.size();
100112

101113
for (int i = 0; i < inputCount; i++) {
@@ -175,11 +187,13 @@ int NeuronExecuTorchDelegate::HintNeuronBackend(EValue** args) const {
175187
return NEURON_NO_ERROR;
176188
}
177189

178-
} // namespace executor
179-
} // namespace torch
190+
} // namespace neuron
191+
} // namespace backends
192+
} // namespace executorch
180193

181194
namespace {
182-
auto cls = torch::executor::NeuronBackend();
183-
torch::executor::Backend backend{"NeuropilotBackend", &cls};
184-
static auto success_with_compiler = register_backend(backend);
195+
auto cls = executorch::backends::neuron::NeuronBackend();
196+
executorch::runtime::Backend backend{"NeuropilotBackend", &cls};
197+
static auto success_with_compiler =
198+
executorch::runtime::register_backend(backend);
185199
} // namespace

backends/mediatek/runtime/NeuronExecutor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#define RESTORE_DLA_EXTENSION_OPERATION_TYPE 0x0000
1818
#define RESTORE_DLA_EXTENSION_NAME "com.mediatek.compiled_network"
1919

20-
namespace torch {
21-
namespace executor {
20+
namespace executorch {
21+
namespace backends {
2222
namespace neuron {
2323

2424
NeuronExecutor::NeuronExecutor(){};
@@ -164,5 +164,5 @@ int NeuronExecutor::LoadFromCompiledNetwork(
164164
}
165165

166166
} // namespace neuron
167-
} // namespace executor
168-
} // namespace torch
167+
} // namespace backends
168+
} // namespace executorch

backends/mediatek/runtime/include/NeuronBackend.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@
2323
#include <unordered_map>
2424
#include <unordered_set>
2525

26-
namespace torch {
27-
namespace executor {
26+
namespace executorch {
27+
namespace backends {
28+
namespace neuron {
2829

2930
class NeuronBackend final : public ::executorch::runtime::BackendInterface {
3031
public:
31-
Result<DelegateHandle*> init(
32-
BackendInitContext& context,
33-
FreeableBuffer* processed,
34-
ArrayRef<CompileSpec> compile_specs) const override;
32+
::executorch::runtime::Result<::executorch::runtime::DelegateHandle*> init(
33+
::executorch::runtime::BackendInitContext& context,
34+
::executorch::runtime::FreeableBuffer* processed,
35+
::executorch::runtime::ArrayRef<::executorch::runtime::CompileSpec>
36+
compile_specs) const override;
3537

36-
Error execute(
37-
ET_UNUSED BackendExecutionContext& context,
38-
DelegateHandle* handle,
39-
EValue** args) const override;
38+
::executorch::runtime::Error execute(
39+
ET_UNUSED ::executorch::runtime::BackendExecutionContext& context,
40+
::executorch::runtime::DelegateHandle* handle,
41+
::executorch::runtime::EValue** args) const override;
4042

41-
void destroy(DelegateHandle* handle) const override;
43+
void destroy(::executorch::runtime::DelegateHandle* handle) const override;
4244

4345
bool is_available() const override;
4446
};
@@ -111,8 +113,9 @@ class NeuronExecuTorchDelegate {
111113
return NEURON_NO_ERROR;
112114
}
113115

114-
Error execute(ET_UNUSED BackendExecutionContext& context, EValue** args)
115-
const;
116+
::executorch::runtime::Error execute(
117+
ET_UNUSED ::executorch::runtime::BackendExecutionContext& context,
118+
::executorch::runtime::EValue** args) const;
116119

117120
private:
118121
template <bool isInput>
@@ -145,7 +148,7 @@ class NeuronExecuTorchDelegate {
145148
return NEURON_NO_ERROR;
146149
}
147150

148-
int HintNeuronBackend(EValue** args) const;
151+
int HintNeuronBackend(::executorch::runtime::EValue** args) const;
149152

150153
private:
151154
std::vector<size_t> mInputSizes;
@@ -168,5 +171,6 @@ class NeuronExecuTorchDelegate {
168171
NeuronExecuTorchDelegate operator=(const NeuronExecuTorchDelegate&);
169172
};
170173

171-
} // namespace executor
172-
} // namespace torch
174+
} // namespace neuron
175+
} // namespace backends
176+
} // namespace executorch

backends/mediatek/runtime/include/NeuronBufferAllocator.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#define GET_NEURON_ALLOCATOR \
2525
::torch::executor::neuron::BufferAllocator::GetInstance()
2626

27+
// TODO: Move this code to the executorch::backends::neuron namespace.
28+
// The torch:: namespace is deprecated for ExecuTorch code.
2729
namespace torch {
2830
namespace executor {
2931
namespace neuron {
@@ -82,15 +84,18 @@ class MemoryUnit {
8284
NeuronMemory* memory = nullptr;
8385
NeuronMemory_createFromAHardwareBuffer(Abuffer, &memory);
8486
CHECK_VALID_PTR(memory);
85-
mNeuronMemory = std::unique_ptr<NeuronMemory, NeuronDeleter>(memory);
87+
mNeuronMemory = std::
88+
unique_ptr<NeuronMemory, executorch::backends::neuron::NeuronDeleter>(
89+
memory);
8690

8791
AHardwareBuffer_lock(Abuffer, mAhwbType, -1, nullptr, &mAddress);
8892
CHECK_VALID_PTR(mAddress);
8993
return NEURON_NO_ERROR;
9094
}
9195

9296
private:
93-
std::unique_ptr<NeuronMemory, NeuronDeleter> mNeuronMemory;
97+
std::unique_ptr<NeuronMemory, executorch::backends::neuron::NeuronDeleter>
98+
mNeuronMemory;
9499

95100
std::unique_ptr<AHardwareBuffer, BufferDeleter> mAhwb;
96101

@@ -102,7 +107,7 @@ class MemoryUnit {
102107
size_t mSize = 0;
103108
};
104109

105-
class BufferAllocator : public MemoryAllocator {
110+
class BufferAllocator : public executorch::runtime::MemoryAllocator {
106111
public:
107112
static BufferAllocator& GetInstance();
108113

@@ -119,7 +124,7 @@ class BufferAllocator : public MemoryAllocator {
119124
void Clear();
120125

121126
private:
122-
BufferAllocator() : MemoryAllocator(0, nullptr) {}
127+
BufferAllocator() : executorch::runtime::MemoryAllocator(0, nullptr) {}
123128

124129
BufferAllocator(const BufferAllocator&) = delete;
125130

backends/mediatek/runtime/include/NeuronExecutor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <string>
1919
#include <vector>
2020

21-
namespace torch {
22-
namespace executor {
21+
namespace executorch {
22+
namespace backends {
2323
namespace neuron {
2424

2525
struct NeuronDeleter {
@@ -119,5 +119,5 @@ class NeuronExecutor {
119119
};
120120

121121
} // namespace neuron
122-
} // namespace executor
123-
} // namespace torch
122+
} // namespace backends
123+
} // namespace executorch

backends/mediatek/runtime/include/NeuronLog.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include <cstdlib>
1717
#include <string>
1818

19-
namespace torch {
20-
namespace executor {
19+
namespace executorch {
20+
namespace backends {
2121
namespace neuron {
2222

2323
#define AndroidLog(priority, tag, format, ...) \
@@ -83,5 +83,5 @@ inline int ReadSystemProperty(std::string& property) {
8383
}
8484

8585
} // namespace neuron
86-
} // namespace executor
87-
} // namespace torch
86+
} // namespace backends
87+
} // namespace executorch

0 commit comments

Comments
 (0)