Skip to content

Commit

Permalink
Create a separate header for macros used with nnlib kernel calls.
Browse files Browse the repository at this point in the history
Differential Revision: D67839291

Pull Request resolved: #7516
  • Loading branch information
hsharma35 authored Jan 6, 2025
1 parent ca32105 commit 68c0208
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
10 changes: 1 addition & 9 deletions backends/cadence/fusion_g3/operators/op_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <xa_nnlib_kernels_api.h>

#include <executorch/backends/cadence/fusion_g3/operators/xt_macros.h>
#include <executorch/kernels/portable/cpu/scalar_utils.h>
#include <executorch/kernels/portable/cpu/util/elementwise_util.h>
#include <executorch/kernels/portable/cpu/util/kernel_ops_util.h>
Expand All @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions backends/cadence/fusion_g3/operators/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down Expand Up @@ -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)
20 changes: 20 additions & 0 deletions backends/cadence/fusion_g3/operators/xt_macros.h
Original file line number Diff line number Diff line change
@@ -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 <executorch/runtime/core/exec_aten/util/tensor_util.h>

#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__ ")");

0 comments on commit 68c0208

Please sign in to comment.