Skip to content

Commit ab3400d

Browse files
committed
Fixed the documentation conflict in kernel-library-selective-build.md
1 parent 8ebb8eb commit ab3400d

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

docs/source/kernel-library-selective-build.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ The basic flow looks like this:
3636

3737
## APIs
3838

39-
We expose a CMake macro `[gen_selected_ops](https://github.com/pytorch/executorch/blob/main/tools/cmake/Codegen.cmake#L12)`, to allow users specifying op info:
39+
We expose a CMake macro [gen_selected_ops](https://github.com/pytorch/executorch/blob/main/tools/cmake/Codegen.cmake#L12), to allow users specifying op info:
4040

4141
```
4242
gen_selected_ops(
43-
LIB_NAME # the name of the selective build operator library to be generated
44-
OPS_SCHEMA_YAML # path to a yaml file containing operators to be selected
45-
ROOT_OPS # comma separated operator names to be selected
46-
INCLUDE_ALL_OPS # boolean flag to include all operators
43+
LIB_NAME # the name of the selective build operator library to be generated
44+
OPS_SCHEMA_YAML # path to a yaml file containing operators to be selected
45+
ROOT_OPS # comma separated operator names to be selected
46+
INCLUDE_ALL_OPS # boolean flag to include all operators
47+
OPS_FROM_MODEL # path to a pte file of model to select operators from
48+
DTYPE_SELECTIVE_BUILD # boolean flag to enable dtye selection
4749
)
4850
```
4951

52+
The macro makes a call to gen_oplist.py, which requires a [distinct selection](https://github.com/BujSet/executorch/blob/main/codegen/tools/gen_oplist.py#L222-L228) of API choice. `OPS_SCHEMA_YAML`, `ROOT_OPS`, `INCLUDE_ALL_OPS`, and `OPS_FROM_MODEL` are mutually exclusive options, and should not be used in conjunction.
5053

5154
### Select all ops
5255

@@ -62,40 +65,39 @@ Context: each kernel library is designed to have a yaml file associated with it.
6265

6366
This API lets users pass in a list of operator names. Note that this API can be combined with the API above and we will create a allowlist from the union of both API inputs.
6467

68+
### Select ops from model
69+
70+
This API lets users pass in a pte file of an exported model. When used, the pte file will be parsed to generate a yaml file that enumerates the operators and dtypes used in the model.
71+
72+
### Dtype Selective Build
73+
74+
Beyond pruning the binary to remove unused operators, the binary size can further reduced by removing unused dtypes. For example, if your model only uses floats for the `add` operator, then including variants of the `add` operators for `doubles` and `ints` is unnecessary. The flag `DTYPE_SELECTIVE_BUILD` can be set to `ON` to support this additional optimization. Currently, dtype selective build is only supported with the model API described above. Once enabled, a header file that specifies only the operators and dtypes used by the model is created and linked against a rebuild of the `portable_kernels` lib. This feature is only supported for the portable kernels library; it's not supported for optimized, quantized or custom kernel libraries.
6575

6676
## Example Walkthrough
6777

68-
In CMakeLists.txt we have the following logic:
69-
```cmake
70-
set(_kernel_lib)
71-
if(SELECT_ALL_OPS)
72-
gen_selected_ops("" "" "${SELECT_ALL_OPS}")
73-
elseif(SELECT_OPS_LIST)
74-
gen_selected_ops("" "${SELECT_OPS_LIST}" "")
75-
elseif(SELECT_OPS_YAML)
76-
set(_custom_ops_yaml ${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml)
77-
gen_selected_ops("${_custom_ops_yaml}" "" "")
78-
endif()
79-
```
80-
Then when calling CMake, we can do:
78+
In [CMakeLists.txt](https://github.com/BujSet/executorch/blob/main/examples/selective_build/CMakeLists.txt#L48-L72), we have the following cmake config options:
8179

82-
```
83-
cmake -D… -DSELECT_OPS_LIST="aten::add.out,aten::mm.out”
84-
```
80+
1. `EXECUTORCH_SELECT_OPS_YAML`
81+
2. `EXECUTORCH_SELECT_OPS_LIST`
82+
3. `EXECUTORCH_SELECT_ALL_OPS`
83+
4. `EXECUTORCH_SELECT_OPS_FROM_MODEL`
84+
5. `EXECUTORCH_DTYPE_SELECTIVE_BUILD`
8585

86-
Or
86+
These options allow a user to tailor the cmake build process to utilize the different APIs, and results in different invocations on the `gen_selected_ops` [function](https://github.com/BujSet/executorch/blob/main/examples/selective_build/CMakeLists.txt#L110-L123). The following table describes some examples of how the invocation changes when these configs are set:
8787

88-
```
89-
cmake -D… -DSELECT_OPS_YAML=ON
90-
```
88+
| Example cmake Call | Resultant `gen_selected_ops` Invocation |
89+
| :----: | :---:|
90+
|<code><br> cmake -D… -DSELECT_OPS_LIST="aten::add.out,aten::mm.out" <br></code> | <code><br> gen_selected_ops("" "${SELECT_OPS_LIST}" "" "" "") <br></code> |
91+
|<code><br> cmake -D… -DSELECT_OPS_YAML=ON <br></code> | <code><br> set(_custom_ops_yaml ${EXECUTORCH_ROOT}/examples/portable/custom_ops/custom_ops.yaml) <br> gen_selected_ops("${_custom_ops_yaml}" "" "") <br></code> |
92+
|<code><br> cmake -D… -DEXECUTORCH_SELECT_OPS_FROM_MODEL="model.pte.out" <br></code> | <code><br> gen_selected_ops("" "" "" "${_model_path}" "") <br></code> |
93+
|<code><br> cmake -D… -DEXECUTORCH_SELECT_OPS_FROM_MODEL="model.pte.out" -DEXECUTORCH_DTYPE_SELECTIVE_BUILD=ON<br></code> | <code><br> gen_selected_ops("" "" "" "${_model_path}" "ON") <br></code> |
9194

92-
To select from either an operator name list or a schema yaml from kernel library.
9395

94-
## Manual Kernel Registration with '--lib-name'
95-
ExecuTorch now supports generating library-specific kernel registration APIs using the '--lib-name' option along with '--manual-registration' during codegen. This allows applications to avoid using static initialization or linker flags like '-force_load' when linking in kernel libraries.
96+
## Manual Kernel Registration with `--lib-name`
97+
ExecuTorch now supports generating library-specific kernel registration APIs using the `--lib-name` option along with `--manual-registration` during codegen. This allows applications to avoid using static initialization or linker flags like `-force_load` when linking in kernel libraries.
9698

9799
## Motivation
98-
In environments like Xcode, using static libraries requires developers to manually specify '-force_load' flags to ensure kernel registration code is executed. This is inconvenient and error-prone.
100+
In environments like Xcode, using static libraries requires developers to manually specify `-force_load` flags to ensure kernel registration code is executed. This is inconvenient and error-prone.
99101

100102
By passing a library name to the codegen script, developers can generate explicit registration functions and headers, which they can call directly in their application.
101103

@@ -110,7 +112,7 @@ python -m codegen.gen \
110112
```
111113
This will generate:
112114

113-
'register_custom_kernels.cpp' defines 'register_custom_kernels()' with only the kernels selected and 'register_custom_kernels.h' declares the function for inclusion in your application
115+
`register_custom_kernels.cpp` defines `register_custom_kernels()` with only the kernels selected and `register_custom_kernels.h` declares the function for inclusion in your application
114116

115117
Then in your application, call:
116118

@@ -123,4 +125,4 @@ register_custom_kernels(); // Registers only the "custom" kernels
123125
This avoids relying on static initialization and enables you to register only the kernels you want.
124126

125127
### Compatibility
126-
If '--lib-name' is not passed, the default behavior remains unchanged, the codegen script will generate a general 'RegisterKernels.cpp' and 'register_all_kernels()' function.
128+
If `--lib-name` is not passed, the default behavior remains unchanged, the codegen script will generate a general `RegisterKernels.cpp` and `register_all_kernels()` function.

0 commit comments

Comments
 (0)