15
15
16
16
#include < executorch/extension/data_loader/file_data_loader.h>
17
17
18
- using namespace ::testing;
19
-
20
- namespace torch ::executor {
18
+ using namespace ::executorch::extension;
19
+ using namespace ::executorch::runtime;
21
20
22
21
class ModuleTest : public ::testing::Test {
23
22
protected:
@@ -102,13 +101,13 @@ TEST_F(ModuleTest, TestMethodMeta) {
102
101
103
102
const auto input_meta = meta->input_tensor_meta (0 );
104
103
EXPECT_TRUE (input_meta.ok ());
105
- EXPECT_EQ (input_meta->scalar_type (), ScalarType::Float);
104
+ EXPECT_EQ (input_meta->scalar_type (), exec_aten:: ScalarType::Float);
106
105
EXPECT_EQ (input_meta->sizes ().size (), 1 );
107
106
EXPECT_EQ (input_meta->sizes ()[0 ], 1 );
108
107
109
108
const auto output_meta = meta->output_tensor_meta (0 );
110
109
EXPECT_TRUE (output_meta.ok ());
111
- EXPECT_EQ (output_meta->scalar_type (), ScalarType::Float);
110
+ EXPECT_EQ (output_meta->scalar_type (), exec_aten:: ScalarType::Float);
112
111
EXPECT_EQ (output_meta->sizes ().size (), 1 );
113
112
EXPECT_EQ (output_meta->sizes ()[0 ], 1 );
114
113
}
@@ -125,11 +124,11 @@ TEST_F(ModuleTest, TestExecute) {
125
124
126
125
std::array<float , 1 > input{1 };
127
126
std::array<int32_t , 1 > sizes{1 };
128
- TensorImpl tensor (
129
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
127
+ exec_aten:: TensorImpl tensor (
128
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
130
129
131
- const auto result =
132
- module . execute ( " forward" , {Tensor (&tensor), Tensor (&tensor)});
130
+ const auto result = module . execute (
131
+ " forward" , {exec_aten:: Tensor (&tensor), exec_aten:: Tensor (&tensor)});
133
132
EXPECT_TRUE (result.ok ());
134
133
135
134
EXPECT_TRUE (result.ok ());
@@ -149,11 +148,11 @@ TEST_F(ModuleTest, TestExecutePreload) {
149
148
150
149
std::array<float , 1 > input{1 };
151
150
std::array<int32_t , 1 > sizes{1 };
152
- TensorImpl tensor (
153
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
151
+ exec_aten:: TensorImpl tensor (
152
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
154
153
155
- const auto result =
156
- module . execute ( " forward" , {Tensor (&tensor), Tensor (&tensor)});
154
+ const auto result = module . execute (
155
+ " forward" , {exec_aten:: Tensor (&tensor), exec_aten:: Tensor (&tensor)});
157
156
EXPECT_TRUE (result.ok ());
158
157
159
158
const auto data = result->at (0 ).toTensor ().const_data_ptr <float >();
@@ -169,11 +168,11 @@ TEST_F(ModuleTest, TestExecutePreload_method) {
169
168
170
169
std::array<float , 1 > input{1 };
171
170
std::array<int32_t , 1 > sizes{1 };
172
- TensorImpl tensor (
173
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
171
+ exec_aten:: TensorImpl tensor (
172
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
174
173
175
- const auto result =
176
- module . execute ( " forward" , {Tensor (&tensor), Tensor (&tensor)});
174
+ const auto result = module . execute (
175
+ " forward" , {exec_aten:: Tensor (&tensor), exec_aten:: Tensor (&tensor)});
177
176
EXPECT_TRUE (result.ok ());
178
177
179
178
const auto data = result->at (0 ).toTensor ().const_data_ptr <float >();
@@ -192,11 +191,11 @@ TEST_F(ModuleTest, TestExecutePreloadProgramAndMethod) {
192
191
193
192
std::array<float , 1 > input{1 };
194
193
std::array<int32_t , 1 > sizes{1 };
195
- TensorImpl tensor (
196
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
194
+ exec_aten:: TensorImpl tensor (
195
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
197
196
198
- const auto result =
199
- module . execute ( " forward" , {Tensor (&tensor), Tensor (&tensor)});
197
+ const auto result = module . execute (
198
+ " forward" , {exec_aten:: Tensor (&tensor), exec_aten:: Tensor (&tensor)});
200
199
EXPECT_TRUE (result.ok ());
201
200
202
201
const auto data = result->at (0 ).toTensor ().const_data_ptr <float >();
@@ -225,10 +224,11 @@ TEST_F(ModuleTest, TestGet) {
225
224
226
225
std::array<float , 1 > input{1 };
227
226
std::array<int32_t , 1 > sizes{1 };
228
- TensorImpl tensor (
229
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
227
+ exec_aten:: TensorImpl tensor (
228
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
230
229
231
- const auto result = module .get (" forward" , {Tensor (&tensor), Tensor (&tensor)});
230
+ const auto result = module .get (
231
+ " forward" , {exec_aten::Tensor (&tensor), exec_aten::Tensor (&tensor)});
232
232
233
233
EXPECT_TRUE (result.ok ());
234
234
const auto data = result->toTensor ().const_data_ptr <float >();
@@ -240,20 +240,22 @@ TEST_F(ModuleTest, TestForward) {
240
240
241
241
std::array<float , 1 > input{1 };
242
242
std::array<int32_t , 1 > sizes{1 };
243
- TensorImpl tensor (
244
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
243
+ exec_aten:: TensorImpl tensor (
244
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
245
245
246
- const auto result = module ->forward ({Tensor (&tensor), Tensor (&tensor)});
246
+ const auto result =
247
+ module ->forward ({exec_aten::Tensor (&tensor), exec_aten::Tensor (&tensor)});
247
248
EXPECT_TRUE (result.ok ());
248
249
249
250
const auto data = result->at (0 ).toTensor ().const_data_ptr <float >();
250
251
251
252
EXPECT_NEAR (data[0 ], 2 , 1e-5 );
252
253
253
254
std::array<float , 2 > input2{2 , 3 };
254
- TensorImpl tensor2 (
255
- ScalarType::Float, sizes.size (), sizes.data (), input2.data ());
256
- const auto result2 = module ->forward ({Tensor (&tensor2), Tensor (&tensor2)});
255
+ exec_aten::TensorImpl tensor2 (
256
+ exec_aten::ScalarType::Float, sizes.size (), sizes.data (), input2.data ());
257
+ const auto result2 = module ->forward (
258
+ {exec_aten::Tensor (&tensor2), exec_aten::Tensor (&tensor2)});
257
259
EXPECT_TRUE (result2.ok ());
258
260
259
261
const auto data2 = result->at (0 ).toTensor ().const_data_ptr <float >();
@@ -298,10 +300,9 @@ TEST_F(ModuleTest, TestProgramSharingBetweenModules) {
298
300
}
299
301
300
302
TEST_F (ModuleTest, TestProgramSharingAndDataLoaderManagement) {
301
- auto loader = util:: FileDataLoader::from (model_path_.c_str ());
303
+ auto loader = FileDataLoader::from (model_path_.c_str ());
302
304
EXPECT_TRUE (loader.ok ());
303
- auto data_loader =
304
- std::make_unique<util::FileDataLoader>(std::move (loader.get ()));
305
+ auto data_loader = std::make_unique<FileDataLoader>(std::move (loader.get ()));
305
306
306
307
auto module1 = std::make_unique<Module>(std::move (data_loader));
307
308
@@ -311,35 +312,35 @@ TEST_F(ModuleTest, TestProgramSharingAndDataLoaderManagement) {
311
312
312
313
std::array<float , 1 > input{1 };
313
314
std::array<int32_t , 1 > sizes{1 };
314
- TensorImpl tensor (
315
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
315
+ exec_aten:: TensorImpl tensor (
316
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
316
317
317
- auto result1 =
318
- module1-> execute ( " forward" , {Tensor (&tensor), Tensor (&tensor)});
318
+ auto result1 = module1-> execute (
319
+ " forward" , {exec_aten:: Tensor (&tensor), exec_aten:: Tensor (&tensor)});
319
320
EXPECT_TRUE (result1.ok ());
320
321
321
322
auto module2 = std::make_unique<Module>(module1->program ());
322
323
323
- auto result2 =
324
- module2-> execute ( " forward" , {Tensor (&tensor), Tensor (&tensor)});
324
+ auto result2 = module2-> execute (
325
+ " forward" , {exec_aten:: Tensor (&tensor), exec_aten:: Tensor (&tensor)});
325
326
EXPECT_TRUE (result2.ok ());
326
327
327
328
module1 = std::make_unique<Module>(" /path/to/nonexistent/file.pte" );
328
329
EXPECT_FALSE (module1->is_loaded ());
329
330
330
- auto result3 =
331
- module2-> execute ( " forward" , {Tensor (&tensor), Tensor (&tensor)});
331
+ auto result3 = module2-> execute (
332
+ " forward" , {exec_aten:: Tensor (&tensor), exec_aten:: Tensor (&tensor)});
332
333
EXPECT_TRUE (result3.ok ());
333
334
}
334
335
335
336
TEST_F (ModuleTest, TestProgramPersistenceAndReuseAfterModuleDestruction) {
336
337
std::shared_ptr<Program> shared_program;
337
338
338
339
{
339
- auto loader = util:: FileDataLoader::from (model_path_.c_str ());
340
+ auto loader = FileDataLoader::from (model_path_.c_str ());
340
341
EXPECT_TRUE (loader.ok ());
341
342
auto data_loader =
342
- std::make_unique<util:: FileDataLoader>(std::move (loader.get ()));
343
+ std::make_unique<FileDataLoader>(std::move (loader.get ()));
343
344
auto * data_loader_ptr = data_loader.get ();
344
345
345
346
Module module (std::move (data_loader));
@@ -362,10 +363,11 @@ TEST_F(ModuleTest, TestProgramPersistenceAndReuseAfterModuleDestruction) {
362
363
363
364
std::array<float , 1 > input{1 };
364
365
std::array<int32_t , 1 > sizes{1 };
365
- TensorImpl tensor (
366
- ScalarType::Float, sizes.size (), sizes.data (), input.data ());
366
+ exec_aten:: TensorImpl tensor (
367
+ exec_aten:: ScalarType::Float, sizes.size (), sizes.data (), input.data ());
367
368
368
- auto result = module .execute (" forward" , {Tensor (&tensor), Tensor (&tensor)});
369
+ auto result = module .execute (
370
+ " forward" , {exec_aten::Tensor (&tensor), exec_aten::Tensor (&tensor)});
369
371
EXPECT_TRUE (result.ok ());
370
372
371
373
auto data = result->at (0 ).toTensor ().const_data_ptr <float >();
@@ -391,10 +393,14 @@ TEST_F(ModuleTest, TestConcurrentExecutionWithSharedProgram) {
391
393
const std::array<float , 1 >& input) {
392
394
Module module (program);
393
395
std::array<int32_t , 1 > sizes{1 };
394
- TensorImpl tensor (
395
- ScalarType::Float, sizes.size (), sizes.data (), (void *)input.data ());
396
-
397
- const auto result = module .forward ({Tensor (&tensor), Tensor (&tensor)});
396
+ exec_aten::TensorImpl tensor (
397
+ exec_aten::ScalarType::Float,
398
+ sizes.size (),
399
+ sizes.data (),
400
+ (void *)input.data ());
401
+
402
+ const auto result = module .forward (
403
+ {exec_aten::Tensor (&tensor), exec_aten::Tensor (&tensor)});
398
404
EXPECT_TRUE (result.ok ());
399
405
400
406
const auto data = result->at (0 ).toTensor ().const_data_ptr <float >();
@@ -413,5 +419,3 @@ TEST_F(ModuleTest, TestConcurrentExecutionWithSharedProgram) {
413
419
t4.join ();
414
420
t5.join ();
415
421
}
416
-
417
- } // namespace torch::executor
0 commit comments