// Copyright (c) 2026 Eoin Jordan // SPDX-License-Identifier: Apache-2.0 // // Registers the two Cortex-M kernels PoseMicro's int8 program calls with the ExecuTorch runtime of a PC, so // train/export_pose.py can run the program before it goes on a board. build.sh compiles this file with // ExecuTorch's own kernel sources and CMSIS-NN in plain C, the code the firmware builds for the ESP32-S3. // // The firmware gets this registration from ExecuTorch's code generator instead. The argument order below // is that of backends/cortex_m/ops/operators.yaml in ExecuTorch v1.5.1. #include #include #include #include #include using executorch::aten::Tensor; using executorch::runtime::EValue; using executorch::runtime::Kernel; using executorch::runtime::KernelRuntimeContext; using executorch::runtime::Span; using Int64ArrayRef = executorch::aten::ArrayRef; namespace cortex_m { namespace native { Tensor& quantized_conv2d_out( KernelRuntimeContext& context, const Tensor& input, const Tensor& weight, const std::optional& bias, const Int64ArrayRef stride, const Int64ArrayRef padding, const Int64ArrayRef dilation, const int64_t input_offset, const int64_t output_offset, const Tensor& requantize_multipliers, const Tensor& requantize_shifts, const int64_t activation_min, const int64_t activation_max, const Tensor& scratch, Tensor& out); Tensor& quantized_depthwise_conv2d_out( KernelRuntimeContext& context, const Tensor& input, const Tensor& weight, const std::optional& bias, const Int64ArrayRef stride, const Int64ArrayRef padding, const Int64ArrayRef dilation, const int64_t depth_multiplier, const int64_t input_offset, const int64_t output_offset, const Tensor& requantize_multipliers, const Tensor& requantize_shifts, const int64_t activation_min, const int64_t activation_max, const Tensor& scratch, Tensor& out); } // namespace native } // namespace cortex_m namespace { void conv2d(KernelRuntimeContext& context, Span s) { auto bias = s[2]->toOptional(); cortex_m::native::quantized_conv2d_out( context, s[0]->toTensor(), s[1]->toTensor(), bias, s[3]->toIntList(), s[4]->toIntList(), s[5]->toIntList(), s[6]->toInt(), s[7]->toInt(), s[8]->toTensor(), s[9]->toTensor(), s[10]->toInt(), s[11]->toInt(), s[12]->toTensor(), s[13]->toTensor()); } void depthwise_conv2d(KernelRuntimeContext& context, Span s) { auto bias = s[2]->toOptional(); cortex_m::native::quantized_depthwise_conv2d_out( context, s[0]->toTensor(), s[1]->toTensor(), bias, s[3]->toIntList(), s[4]->toIntList(), s[5]->toIntList(), s[6]->toInt(), s[7]->toInt(), s[8]->toInt(), s[9]->toTensor(), s[10]->toTensor(), s[11]->toInt(), s[12]->toInt(), s[13]->toTensor(), s[14]->toTensor()); } const Kernel kKernels[] = { Kernel("cortex_m::quantized_conv2d.out", conv2d), Kernel("cortex_m::quantized_depthwise_conv2d.out", depthwise_conv2d), }; const auto kRegistered = executorch::runtime::register_kernels({kKernels, 2}); } // namespace