blob: c86dc8bcb293b9f71e85339d98bc11ae955c5062 [file] [log] [blame] [view]
Ben Vanikeefc3b02022-11-27 09:14:53 -08001# Synchronous tensor I/O custom module sample
2
3This sample expects that you've already produced a working version of the
4[basic sample](/samples/custom_module/basic/) (including compiler installation
5and CMake setup).
6
7This sample demonstrates adding custom modules callable from compiler-produced
8programs that take and return `tensor` types. By default custom calls are
9treated as blocking operations that synchronize with the underlying device to
10ensure all passed `tensor` buffer views are host coherent and it's assumed that
11any returned `tensor` buffer views are ready for use when the call returns.
12
13This approach is the easiest to integrate and looks similar to classic ML
14frameworks custom calls. There are many significant performance implications of
15using this approach, though, and synchronous calls should only be used when
16no asynchronous approach is possible. See the
17[async tensor](/samples/custom_module/async/) sample for how to define
18custom calls that work asynchronously.
19
20## Instructions
21
221. Compile the [example module](./test/example.mlir) to a .vmfb file:
23
24 ```
25 iree-compile --iree-hal-target-backends=llvm-cpu samples/custom_module/sync/test/example.mlir -o=/tmp/example.vmfb
26 ```
27
282. Build the `iree_samples_custom_module_sync_run` CMake target :
29
30 ```
31 cmake -B ../iree-build/ -DCMAKE_BUILD_TYPE=RelWithDebInfo . \
32 -DCMAKE_C_FLAGS=-DIREE_VM_EXECUTION_TRACING_FORCE_ENABLE=1
33 cmake --build ../iree-build/ --target iree_samples_custom_module_sync_run
34 ```
35 (here we force runtime execution tracing for demonstration purposes)
36
Scott Toddc7b29122023-02-21 17:33:35 -080037 [See here](https://openxla.github.io/iree/building-from-source/getting-started/)
Ben Vanikeefc3b02022-11-27 09:14:53 -080038 for general instructions on building using CMake.
39
403. Run the example program to call the main function:
41
42 ```
43 ../iree-build/samples/custom_module/sync/custom-module-sync-run \
44 /tmp/example.vmfb example.main
45 ```