Name Date Size #Lines LOC

..--

README.mdH A D25-Apr-20252.3 KiB4834

TARGETSH A D25-Apr-2025172 95

my_functions.yamlH A D25-Apr-2025228 94

op_relu.cppH A D25-Apr-20252.6 KiB9960

supported_features_def.yamlH A D25-Apr-2025104 52

targets.bzlH A D25-Apr-20251.4 KiB5143

tests.bzlH A D25-Apr-20251.5 KiB2923

README.md

1# custom_kernel_example
2
3This directory shows an example about how to use the kernel library framework to automatically test an ATen-compliant operator from a custom kernel.
4
5- my_functions.yaml: contains the op for my custom kernel. Contains only relu for now.
6- op_relu.cpp: the impl for my custom kernel. The code is copied from portable kernel.
7- targets.bzl: defines the op library and the ET codegen generated lib for the kernel.
8- tests.bzl: defines the new targets needed to invoke tests from kernel library framework to test my relu implementation automatically.
9
10## What's tests.bzl?
11
12To clarify, we don't need a separate bzl file for it. We can use targets.bzl and add targets there directly. Here it's for demo purpose.
13
14We need to invoke `generated_op_test` from executorch/kernels/test/util.bzl so we can test automatically.
15
16Follow steps in tests.bzl to define required targets.
17
18- Step 1: Define the function header wrapper in executorch/kernels/test/targets.bzl, like
19  `codegen_function_header_wrapper("executorch/kernels/test/custom_kernel_example", "custom_kernel_example")`
20  or generally `codegen_function_header_wrapper("<path-to-your-kernel>/<your-kernel-name>", "<your-kernel-name>")`
21  This is needed because tests need to know our Functions.h target.
22  TODO(T149423767): We should codegen this wrapper in #include, not let user define it.
23
24- Step 2: Use the helper to produce the supported feature list for tests.
25
26  We need an additional supported_features_def.yaml for test codegen. See examples in executorch/kernels/test/supported_features.yaml and supported_features_def_example.yaml.
27  Need to override some default features if different.
28
29   ```
30   define_supported_features_lib()
31   ```
32
33- Step 3: Use the helper generated_op_test to re-use existing tests
34  ```
35    for op in MY_ATEN_COMPLIANT_OPS:
36        op_name = op["name"]
37
38        generated_op_test(
39            name = op_name + "_test",
40            op_impl_target = ":my_operators",
41            generated_lib_headers_target = ":generated_lib_headers",
42
43            # those two targets are defined in previous steps
44            supported_features_target = ":supported_features",
45            function_header_wrapper_target = "//executorch/kernels/test:function_header_wrapper_custom_kernel_example",
46        )
47  ```
48