From 4c7f4c0d3c7b88ac299f4addb01926bd21ef58ee Mon Sep 17 00:00:00 2001 From: Hardik Sharma Date: Sun, 5 Jan 2025 09:46:04 -0800 Subject: [PATCH] Create a separate header for macros used with nnlib kernel calls. Summary: Moves the `XT_KERNEL_CHECK` to a separate header. Differential Revision: D67839291 --- .../cadence/fusion_g3/operators/op_add.cpp | 10 +--------- .../cadence/fusion_g3/operators/targets.bzl | 13 ++++++++++++ .../cadence/fusion_g3/operators/xt_macros.h | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 backends/cadence/fusion_g3/operators/xt_macros.h diff --git a/backends/cadence/fusion_g3/operators/op_add.cpp b/backends/cadence/fusion_g3/operators/op_add.cpp index a68cef54b44..f40fcc973b0 100644 --- a/backends/cadence/fusion_g3/operators/op_add.cpp +++ b/backends/cadence/fusion_g3/operators/op_add.cpp @@ -10,6 +10,7 @@ #include +#include #include #include #include @@ -28,15 +29,6 @@ namespace impl { namespace G3 { namespace native { -#define XT_KERNEL_CHECK(ctx, out, kernel, ...) \ - const auto ret = kernel(__VA_ARGS__); \ - ET_KERNEL_CHECK_MSG( \ - ctx, \ - ret == 0, \ - InvalidArgument, \ - out, \ - "Failed to run kernel: " #kernel "(" #__VA_ARGS__ ")"); - Tensor& add_out( KernelRuntimeContext& ctx, const Tensor& a, diff --git a/backends/cadence/fusion_g3/operators/targets.bzl b/backends/cadence/fusion_g3/operators/targets.bzl index 47d035d420d..3e5900e3634 100644 --- a/backends/cadence/fusion_g3/operators/targets.bzl +++ b/backends/cadence/fusion_g3/operators/targets.bzl @@ -27,6 +27,7 @@ def define_operator(name: str, deps: list[str] | None = None) -> None: deps = deps + common_deps, exported_deps = [ ":operators_header", + ":xt_macros", ], ) @@ -61,5 +62,17 @@ def define_common_targets(): ], ) + runtime.cxx_library( + name = "xt_macros", + exported_headers = ["xt_macros.h"], + visibility = [ + "//executorch/backends/cadence/...", + ], + exported_deps = [ + "//executorch/runtime/core/exec_aten:lib", + "//executorch/runtime/kernel:kernel_runtime_context", + ], + ) + for op in OPERATORS: define_operator(op) diff --git a/backends/cadence/fusion_g3/operators/xt_macros.h b/backends/cadence/fusion_g3/operators/xt_macros.h new file mode 100644 index 00000000000..4ab99380a2d --- /dev/null +++ b/backends/cadence/fusion_g3/operators/xt_macros.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +#define XT_KERNEL_CHECK(ctx, out, kernel, ...) \ + const auto ret = kernel(__VA_ARGS__); \ + ET_KERNEL_CHECK_MSG( \ + ctx, \ + ret == 0, \ + InvalidArgument, \ + out, \ + "Failed to run kernel: " #kernel "(" #__VA_ARGS__ ")");