@@ -45,10 +45,23 @@ char* model_pte = nullptr;
45
45
#include " model_pte.h"
46
46
#endif
47
47
48
- using namespace exec_aten ;
49
- using namespace std ;
50
- using torch::executor::Error;
51
- using torch::executor::Result;
48
+ using executorch::aten::ScalarType;
49
+ using executorch::aten::Tensor;
50
+ using executorch::aten::TensorImpl;
51
+ using executorch::extension::BufferCleanup;
52
+ using executorch::extension::BufferDataLoader;
53
+ using executorch::runtime::Error;
54
+ using executorch::runtime::EValue;
55
+ using executorch::runtime::HierarchicalAllocator;
56
+ using executorch::runtime::MemoryAllocator;
57
+ using executorch::runtime::MemoryManager;
58
+ using executorch::runtime::Method;
59
+ using executorch::runtime::MethodMeta;
60
+ using executorch::runtime::Program;
61
+ using executorch::runtime::Result;
62
+ using executorch::runtime::Span;
63
+ using executorch::runtime::Tag;
64
+ using executorch::runtime::TensorInfo;
52
65
53
66
#define METHOD_ALLOCATOR_POOL_SIZE (70 * 1024 * 1024 )
54
67
unsigned char __attribute__ ((
@@ -86,11 +99,10 @@ void et_pal_emit_log_message(
86
99
}
87
100
88
101
namespace {
89
- using namespace torch ::executor;
90
102
91
- Result<util:: BufferCleanup> prepare_input_tensors (
103
+ Result<BufferCleanup> prepare_input_tensors (
92
104
Method& method,
93
- torch::executor:: MemoryAllocator& allocator,
105
+ MemoryAllocator& allocator,
94
106
std::vector<std::pair<char *, size_t >>& input_buffers) {
95
107
MethodMeta method_meta = method.method_meta ();
96
108
size_t num_inputs = method_meta.num_inputs ();
@@ -175,18 +187,18 @@ Result<util::BufferCleanup> prepare_input_tensors(
175
187
ET_LOG (
176
188
Error, " Failed to prepare input %zu: 0x%" PRIx32, i, (uint32_t )err);
177
189
// The BufferCleanup will free the inputs when it goes out of scope.
178
- util:: BufferCleanup cleanup ({inputs, num_allocated});
190
+ BufferCleanup cleanup ({inputs, num_allocated});
179
191
return err;
180
192
}
181
193
}
182
- return util:: BufferCleanup ({inputs, num_allocated});
194
+ return BufferCleanup ({inputs, num_allocated});
183
195
}
184
196
185
197
#ifdef SEMIHOSTING
186
198
187
199
std::pair<char *, size_t > read_binary_file (
188
200
const char * filename,
189
- torch::executor:: MemoryAllocator& allocator) {
201
+ MemoryAllocator& allocator) {
190
202
FILE* fp = fopen (filename, " rb" );
191
203
if (!fp) {
192
204
ET_LOG (
@@ -238,13 +250,13 @@ int main(int argc, const char* argv[]) {
238
250
(void )argv;
239
251
#endif
240
252
241
- torch::executor ::runtime_init ();
253
+ executorch::runtime ::runtime_init ();
242
254
std::vector<std::pair<char *, size_t >> input_buffers;
243
255
size_t pte_size = sizeof (model_pte);
244
256
245
257
#ifdef SEMIHOSTING
246
258
const char * output_basename = nullptr ;
247
- torch::executor:: MemoryAllocator input_allocator (
259
+ MemoryAllocator input_allocator (
248
260
input_allocation_pool_size, input_allocation_pool);
249
261
250
262
/* parse input parameters */
@@ -277,10 +289,9 @@ int main(int argc, const char* argv[]) {
277
289
}
278
290
#endif
279
291
ET_LOG (Info, " Model in %p %c" , model_pte, model_pte[0 ]);
280
- auto loader = torch::executor::util:: BufferDataLoader (model_pte, pte_size);
292
+ auto loader = BufferDataLoader (model_pte, pte_size);
281
293
ET_LOG (Info, " Model PTE file loaded. Size: %lu bytes." , pte_size);
282
- Result<torch::executor::Program> program =
283
- torch::executor::Program::load (&loader);
294
+ Result<Program> program = Program::load (&loader);
284
295
if (!program.ok ()) {
285
296
ET_LOG (
286
297
Info,
@@ -299,8 +310,7 @@ int main(int argc, const char* argv[]) {
299
310
}
300
311
ET_LOG (Info, " Running method %s" , method_name);
301
312
302
- Result<torch::executor::MethodMeta> method_meta =
303
- program->method_meta (method_name);
313
+ Result<MethodMeta> method_meta = program->method_meta (method_name);
304
314
if (!method_meta.ok ()) {
305
315
ET_LOG (
306
316
Info,
@@ -309,13 +319,11 @@ int main(int argc, const char* argv[]) {
309
319
(unsigned int )method_meta.error ());
310
320
}
311
321
312
- torch::executor::MemoryAllocator method_allocator{
313
- torch::executor::MemoryAllocator (
314
- METHOD_ALLOCATOR_POOL_SIZE, method_allocation_pool)};
322
+ MemoryAllocator method_allocator (
323
+ METHOD_ALLOCATOR_POOL_SIZE, method_allocation_pool);
315
324
316
325
std::vector<uint8_t *> planned_buffers; // Owns the memory
317
- std::vector<torch::executor::Span<uint8_t >>
318
- planned_spans; // Passed to the allocator
326
+ std::vector<Span<uint8_t >> planned_spans; // Passed to the allocator
319
327
size_t num_memory_planned_buffers = method_meta->num_memory_planned_buffers ();
320
328
321
329
for (size_t id = 0 ; id < num_memory_planned_buffers; ++id) {
@@ -330,17 +338,16 @@ int main(int argc, const char* argv[]) {
330
338
planned_spans.push_back ({planned_buffers.back (), buffer_size});
331
339
}
332
340
333
- torch::executor:: HierarchicalAllocator planned_memory (
341
+ HierarchicalAllocator planned_memory (
334
342
{planned_spans.data (), planned_spans.size ()});
335
343
336
- torch::executor:: MemoryAllocator temp_allocator (
344
+ MemoryAllocator temp_allocator (
337
345
temp_allocation_pool_size, temp_allocation_pool);
338
346
339
- torch::executor:: MemoryManager memory_manager (
347
+ MemoryManager memory_manager (
340
348
&method_allocator, &planned_memory, &temp_allocator);
341
349
342
- Result<torch::executor::Method> method =
343
- program->load_method (method_name, &memory_manager);
350
+ Result<Method> method = program->load_method (method_name, &memory_manager);
344
351
if (!method.ok ()) {
345
352
ET_LOG (
346
353
Info,
@@ -379,7 +386,7 @@ int main(int argc, const char* argv[]) {
379
386
ET_LOG (Info, " Model executed successfully." );
380
387
}
381
388
382
- std::vector<torch::executor:: EValue> outputs (method->outputs_size ());
389
+ std::vector<EValue> outputs (method->outputs_size ());
383
390
ET_LOG (Info, " %zu outputs: " , outputs.size ());
384
391
status = method->get_outputs (outputs.data (), outputs.size ());
385
392
ET_CHECK (status == Error::Ok);
0 commit comments