xref: /aosp_15_r20/external/executorch/kernels/portable/cpu/selective_build.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <executorch/runtime/core/exec_aten/exec_aten.h>
12 
13 #ifdef EXECUTORCH_SELECTIVE_BUILD_DTYPE
14 // include header generated by
15 // executorch/codegen/tools/gen_selected_op_variants.py
16 #include <executorch/kernels/portable/cpu/selected_op_variants.h>
17 #else
18 // dummy implementation
should_include_kernel_dtype(const char *,exec_aten::ScalarType)19 inline constexpr bool should_include_kernel_dtype(
20     const char* /*operator_name*/,
21     exec_aten::ScalarType /*scalar_type*/
22 ) {
23   return true;
24 }
25 #endif
26 
27 namespace torch {
28 namespace executor {
29 #define ET_INTERNAL_CHECK_SELECTIVE_BUILD(enum_type)               \
30   do {                                                             \
31     if (!should_include_kernel_dtype(et_switch_name, enum_type)) { \
32       ET_LOG(                                                      \
33           Error,                                                   \
34           "dtype '%" PRId8 "' not selected for operator %s",       \
35           static_cast<int8_t>(enum_type),                          \
36           et_switch_name);                                         \
37       torch::executor::runtime_abort();                            \
38     }                                                              \
39   } while (0)
40 
41 } // namespace executor
42 } // namespace torch
43 
44 #include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
45