From 84b053b572b89877f7b19f0e4cc9f9cae079cd11 Mon Sep 17 00:00:00 2001 From: Daksh Shami Date: Thu, 16 Oct 2025 11:50:47 -0700 Subject: [PATCH] Add exception free quantized kernels (#14962) Summary: Explicitly declaring generated libs with exception code off for quantized kernels as executorch does not use exceptions in general, and it can cause downstream errors. Detailed error is P1986979595 but the relevant part is: ``` buck-out/ABC/gen/fbsource/6e53edb0a9a0d828/xplat/executorch/kernels/quantized/__generated_lib_combined__/out/RegisterCodegenUnboxedKernelsEverything.cpp:77:44: error: exception handling disabled, use '-fexceptions' to enable 77 | } catch (const std::exception& ex) { | ``` This means the existing generated code uses exceptions in its code, so when we use these kernels with -fno-exceptions downstream, the build fails. After this diff, we can use the exception free kernels with 'no_exceptions' suffix -- `//xplat/executorch/kernels/quantized:generated_lib_no_exceptions` or `//xplat/executorch/kernels/quantized:generated_lib_aten_no_exceptions` as appropriate. We still have `//xplat/executorch/kernels/quantized:generated_lib` and `//xplat/executorch/kernels/quantized:generated_lib_aten` available, same as before, so no downstream side effects are expected. Reviewed By: swolchok Differential Revision: D84284541 --- kernels/quantized/targets.bzl | 73 +++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/kernels/quantized/targets.bzl b/kernels/quantized/targets.bzl index 7bd8f6852a7..3448fd9c603 100644 --- a/kernels/quantized/targets.bzl +++ b/kernels/quantized/targets.bzl @@ -96,41 +96,46 @@ def define_common_targets(): ], ) - executorch_generated_lib( - name = "generated_lib" + aten_suffix, - deps = [ - ":quantized_operators" + aten_suffix, - ":all_quantized_ops", - ], - custom_ops_yaml_target = ":quantized.yaml", - custom_ops_aten_kernel_deps = [":quantized_operators_aten"] if aten_mode else [], - custom_ops_requires_aot_registration = False, - aten_mode = aten_mode, - visibility = [ - "//executorch/...", - "@EXECUTORCH_CLIENTS", - ], - define_static_targets = True, - ) + for support_exceptions in [True, False]: + exception_suffix = "_no_exceptions" if not support_exceptions else "" - # On Windows we can only compile these two ops currently, so adding a - # separate target for this. - executorch_generated_lib( - name = "q_dq_ops_generated_lib" + aten_suffix, - custom_ops_yaml_target = ":quantized.yaml", - kernel_deps = [ - "//executorch/kernels/quantized/cpu:op_quantize" + aten_suffix, - "//executorch/kernels/quantized/cpu:op_dequantize" + aten_suffix, - ], - aten_mode = aten_mode, - deps = [ - ":q_dq_ops", - ], - visibility = [ - "//executorch/...", - "@EXECUTORCH_CLIENTS", - ], - ) + executorch_generated_lib( + name = "generated_lib" + aten_suffix + exception_suffix, + deps = [ + ":quantized_operators" + aten_suffix, + ":all_quantized_ops", + ], + custom_ops_yaml_target = ":quantized.yaml", + custom_ops_aten_kernel_deps = [":quantized_operators_aten"] if aten_mode else [], + custom_ops_requires_aot_registration = False, + aten_mode = aten_mode, + support_exceptions = support_exceptions, + visibility = [ + "//executorch/...", + "@EXECUTORCH_CLIENTS", + ], + define_static_targets = True, + ) + + # On Windows we can only compile these two ops currently, so adding a + # separate target for this. + executorch_generated_lib( + name = "q_dq_ops_generated_lib" + aten_suffix + exception_suffix, + custom_ops_yaml_target = ":quantized.yaml", + kernel_deps = [ + "//executorch/kernels/quantized/cpu:op_quantize" + aten_suffix, + "//executorch/kernels/quantized/cpu:op_dequantize" + aten_suffix, + ], + aten_mode = aten_mode, + deps = [ + ":q_dq_ops", + ], + support_exceptions = support_exceptions, + visibility = [ + "//executorch/...", + "@EXECUTORCH_CLIENTS", + ], + ) runtime.python_library( name = "quantized_ops_lib",