Skip to content

Commit 31986ac

Browse files
committed
module example
1 parent 1bac885 commit 31986ac

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

CMakeLists.txt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,16 @@ option(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT "Build the custom ops lib for AOT"
181181
)
182182

183183
option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER "Build the Data Loader extension"
184-
OFF
184+
ON
185185
)
186186

187-
option(EXECUTORCH_BUILD_EXTENSION_MODULE "Build the Module extension" OFF)
187+
option(EXECUTORCH_BUILD_EXTENSION_MODULE "Build the Module extension" ON)
188188

189189
option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL "Build the Runner Util extension"
190190
OFF
191191
)
192192

193-
option(EXECUTORCH_BUILD_EXTENSION_TENSOR "Build the Tensor extension" OFF)
193+
option(EXECUTORCH_BUILD_EXTENSION_TENSOR "Build the Tensor extension" ON)
194194

195195
option(EXECUTORCH_BUILD_EXTENSION_TRAINING "Build the training extension" OFF)
196196

@@ -834,6 +834,23 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
834834
target_compile_options(executor_runner PUBLIC ${_common_compile_options})
835835
endif()
836836

837+
if(TRUE)
838+
# Build Module
839+
set(_module_libs executorch gflags)
840+
list(APPEND _module_libs
841+
portable_ops_lib
842+
portable_kernels
843+
extension_data_loader
844+
extension_tensor
845+
extension_module_static
846+
)
847+
848+
add_executable(module_runner examples/portable/module/module.cpp)
849+
target_link_libraries(module_runner ${_module_libs})
850+
target_compile_options(module_runner PUBLIC ${_common_compile_options})
851+
852+
endif()
853+
837854
if(EXECUTORCH_BUILD_VULKAN)
838855
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan)
839856
endif()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <executorch/extension/module/module.h>
2+
#include <executorch/extension/tensor/tensor.h>
3+
4+
#include <iostream>
5+
using namespace ::executorch::extension;
6+
7+
int main(int argc, char** argv) {
8+
// Create a Module.
9+
Module module(
10+
"/data/users/lfq/executorch/extension/module/test/resources/add.pte");
11+
12+
// Wrap the input data with a Tensor.
13+
float input[1] = {4.f};
14+
auto tensor = from_blob(input, {1});
15+
16+
auto err = module.set_inputs({tensor, tensor});
17+
18+
// Perform an inference.
19+
const auto result = module.forward();
20+
21+
// Check for success or failure.
22+
if (result.ok()) {
23+
// Retrieve the output data.
24+
const auto output = result->at(0).toTensor().const_data_ptr<float>();
25+
std::cout << "Output: " << output[0] << std::endl;
26+
}
27+
return 0;
28+
}

0 commit comments

Comments
 (0)