Ben Vanik | eefc3b0 | 2022-11-27 09:14:53 -0800 | [diff] [blame] | 1 | # Synchronous tensor I/O custom module sample |
| 2 | |
| 3 | This sample expects that you've already produced a working version of the |
| 4 | [basic sample](/samples/custom_module/basic/) (including compiler installation |
| 5 | and CMake setup). |
| 6 | |
| 7 | This sample demonstrates adding custom modules callable from compiler-produced |
| 8 | programs that take and return `tensor` types. By default custom calls are |
| 9 | treated as blocking operations that synchronize with the underlying device to |
| 10 | ensure all passed `tensor` buffer views are host coherent and it's assumed that |
| 11 | any returned `tensor` buffer views are ready for use when the call returns. |
| 12 | |
| 13 | This approach is the easiest to integrate and looks similar to classic ML |
| 14 | frameworks custom calls. There are many significant performance implications of |
| 15 | using this approach, though, and synchronous calls should only be used when |
| 16 | no asynchronous approach is possible. See the |
| 17 | [async tensor](/samples/custom_module/async/) sample for how to define |
| 18 | custom calls that work asynchronously. |
| 19 | |
| 20 | ## Instructions |
| 21 | |
| 22 | 1. 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 | |
| 28 | 2. 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 Todd | c7b2912 | 2023-02-21 17:33:35 -0800 | [diff] [blame] | 37 | [See here](https://openxla.github.io/iree/building-from-source/getting-started/) |
Ben Vanik | eefc3b0 | 2022-11-27 09:14:53 -0800 | [diff] [blame] | 38 | for general instructions on building using CMake. |
| 39 | |
| 40 | 3. 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 | ``` |