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