Skip to content

Commit 444480b

Browse files
hsharma35facebook-github-bot
authored andcommitted
Buckify Cadence HiFi4 Operators. (#5154)
Summary: Pull Request resolved: #5154 Add c++ code under cadence/hifi to buck build targets. Reviewed By: zonglinpeng Differential Revision: D62317545 fbshipit-source-id: e91cf9167fd6a701cd2e2ed52ea2cc6d07517cf4
1 parent 861a7bf commit 444480b

File tree

10 files changed

+74
-17
lines changed

10 files changed

+74
-17
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("targets.bzl", "define_common_targets")
2+
3+
oncall("odai_jarvis")
4+
5+
define_common_targets()

backends/cadence/hifi/kernels/kernels.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/cadence/reference/kernels/kernels.h>
10-
#include "xa_nnlib_common.h"
11-
#include "xa_nnlib_common_macros.h"
9+
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
10+
#include <xa_nnlib_common.h>
11+
#include <xa_nnlib_common_macros.h>
1212

1313
namespace impl {
1414
namespace HiFi {

backends/cadence/hifi/kernels/kernels.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88

99
#pragma once
1010

11-
#include "inttypes.h"
12-
#include "stddef.h"
13-
#include "xa_type_def.h"
14-
15-
/* For NNLIB APIs */
16-
#include "xa_nnlib_kernels_api.h"
11+
#include <inttypes.h>
12+
#include <stddef.h>
13+
#include <xa_type_def.h>
1714

1815
namespace impl {
1916
namespace HiFi {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
load("@fbsource//tools/build_defs:platform_defs.bzl", "CXX")
2+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
3+
4+
def define_common_targets():
5+
runtime.cxx_library(
6+
name = "kernels",
7+
srcs = ["kernels.cpp"],
8+
exported_headers = [
9+
"kernels.h",
10+
],
11+
visibility = [
12+
"//executorch/backends/cadence/...",
13+
],
14+
exported_deps = [
15+
"fbsource//third-party/nnlib-hifi4/xa_nnlib:libxa_nnlib_common",
16+
],
17+
platforms = CXX,
18+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
load("targets.bzl", "define_common_targets")
2+
3+
oncall("odai_jarvis")
4+
5+
define_common_targets()

backends/cadence/hifi/operators/dequantize_per_tensor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/cadence/reference/kernels/kernels.h>
9+
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
1010
#include <executorch/runtime/kernel/kernel_includes.h>
11+
#include <xa_nnlib_kernels_api.h>
1112

1213
namespace impl {
1314
namespace HiFi {

backends/cadence/hifi/operators/quantize_per_tensor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/cadence/reference/kernels/kernels.h>
9+
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
1010
#include <executorch/runtime/kernel/kernel_includes.h>
11+
#include <xa_nnlib_kernels_api.h>
1112

1213
namespace impl {
1314
namespace HiFi {

backends/cadence/hifi/operators/quantized_layer_norm.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/cadence/reference/kernels/kernels.h>
9+
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
1010
#include <executorch/runtime/kernel/kernel_includes.h>
11-
1211
#include <algorithm>
1312
#include <cmath>
1413
#include <tuple>
@@ -76,9 +75,11 @@ void quantized_layer_norm_(
7675
for (size_t j = 0; j < last_dim; ++j) {
7776
// Since X is quantized, we dequantize it, compute fp32 result, and
7877
// quantize the result to an int8/uint8 value.
79-
float val = kernels::dequantize<T>(x[j], input_scale, input_zero_point);
78+
float val = impl::HiFi::kernels::dequantize<T>(
79+
x[j], input_scale, input_zero_point);
8080
val = (val - mean) * inv_std * weight_data[j] + bias_data[j];
81-
y[j] = kernels::quantize<T>(val, output_inv_scale, output_zero_point);
81+
y[j] = impl::HiFi::kernels::quantize<T>(
82+
val, output_inv_scale, output_zero_point);
8283
}
8384
}
8485
}

backends/cadence/hifi/operators/quantized_linear_out.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
#include <executorch/backends/cadence/reference/kernels/kernels.h>
10-
9+
#include <executorch/backends/cadence/hifi/kernels/kernels.h>
1110
#include <executorch/runtime/kernel/kernel_includes.h>
1211
#include <algorithm>
1312
#include <cmath>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load("@fbsource//tools/build_defs:platform_defs.bzl", "CXX")
2+
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
3+
4+
def define_common_targets():
5+
"""Defines targets that should be shared between fbcode and xplat.
6+
7+
The directory containing this targets.bzl file should also contain both
8+
TARGETS and BUCK files that call this function.
9+
"""
10+
11+
# Define build targets for all operators registered in the tables above.
12+
13+
runtime.cxx_library(
14+
name = "cadence_hifi_ops",
15+
srcs = glob([
16+
"*.cpp",
17+
]),
18+
platforms = CXX,
19+
deps = [
20+
"//executorch/kernels/portable/cpu/util:broadcast_util",
21+
"//executorch/runtime/kernel:kernel_includes",
22+
"//executorch/kernels/portable/cpu:scalar_utils",
23+
"fbsource//third-party/nnlib-hifi4/xa_nnlib:libxa_nnlib",
24+
"fbsource//third-party/nnlib-hifi4/xa_nnlib:libxa_nnlib_common",
25+
"//executorch/backends/cadence/hifi/kernels:kernels",
26+
],
27+
visibility = [
28+
"//executorch/backends/cadence/...",
29+
],
30+
)

0 commit comments

Comments
 (0)