Skip to content

Commit d778627

Browse files
Added Fusion G3 NN library with kernels related to add, mul, quantize… (#6738)
* Added Fusion G3 NN library with kernels related to add, mul, quantize, dequantize, cat, layer norm, softmax to backends/cadence folder. Added operators to backends/cadence folder * Updated name space of the operators by appending cadence Signed-off-by: [email protected] <[email protected]> * Added nnlib-FusionG3 submodule from FOSS-xtensa git space Signed-off-by: [email protected] <[email protected]> * Resolved Linter errors Signed-off-by: [email protected] <[email protected]> --------- Signed-off-by: [email protected] <[email protected]> Co-authored-by: [email protected] <[email protected]>
1 parent 04f9ced commit d778627

File tree

13 files changed

+2888
-1
lines changed

13 files changed

+2888
-1
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
[submodule "third-party/pybind11"]
6565
path = third-party/pybind11
6666
url = https://github.com/pybind/pybind11.git
67+
[submodule "backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3"]
68+
path = backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3
69+
url = https://github.com/foss-xtensa/nnlib-FusionG3/
6770
[submodule "third-party/ao"]
6871
path = third-party/ao
6972
url = https://github.com/pytorch/ao.git

backends/cadence/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ endif()
7676
if(EXECUTORCH_NNLIB_OPT)
7777
set(TARGET_DIR hifi)
7878
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/third-party/nnlib)
79+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/kernels)
80+
endif()
81+
82+
if(EXECUTORCH_FUSION_G3_OPT)
83+
set(TARGET_DIR fusion_g3)
84+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/third-party/nnlib)
7985
endif()
8086

8187
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/operators)
82-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_DIR}/kernels)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This yaml file contains operators that are also defined by the ATen library.
4+
# For lean mode:
5+
# - Codegen'd target `executorch_generated_lib` will be reading all the information
6+
# from this file, including operator schema and kernel metadata.
7+
# - Selective build target `codegen:executorch_defined_ops` now is selecting all the
8+
# operators in this file, by dumping all the op names into `selected_operators.yaml`.
9+
#
10+
# See the README.md file in executorch/kernels/portable for a description of the syntax used
11+
# by this file.
12+
13+
14+
# aten ops
15+
- op: _to_copy.out
16+
kernels:
17+
- arg_meta: null
18+
kernel_name: torch::executor::to_copy_out
19+
20+
- op: _softmax.out
21+
kernels:
22+
- arg_meta: null
23+
kernel_name: cadence::impl::G3::softmax_out
24+
25+
- op: add.out
26+
kernels:
27+
- arg_meta: null
28+
kernel_name: cadence::impl::G3::add_out
29+
30+
- op: add.Scalar_out
31+
kernels:
32+
- arg_meta: null
33+
kernel_name: cadence::impl::G3::add_scalar_out
34+
35+
- op: bmm.out
36+
kernels:
37+
- arg_meta: null
38+
kernel_name: torch::executor::bmm_out
39+
40+
- op: cat.out
41+
kernels:
42+
- arg_meta: null
43+
kernel_name: cadence::impl::G3::cat_out
44+
45+
- op: clone.out
46+
kernels:
47+
- arg_meta: null
48+
kernel_name: torch::executor::clone_out
49+
50+
- op: div.out
51+
kernels:
52+
- arg_meta: null
53+
kernel_name: torch::executor::div_out
54+
55+
- op: div.out_mode
56+
kernels:
57+
- arg_meta: null
58+
kernel_name: torch::executor::div_out_mode
59+
60+
- op: embedding.out
61+
kernels:
62+
- arg_meta: null
63+
kernel_name: torch::executor::embedding_out
64+
65+
- op: full.out
66+
kernels:
67+
- arg_meta: null
68+
kernel_name: torch::executor::full_out
69+
70+
- op: mul.out
71+
kernels:
72+
- arg_meta: null
73+
kernel_name: cadence::impl::G3::mul_out
74+
75+
- op: mul.Scalar_out
76+
kernels:
77+
- arg_meta: null
78+
kernel_name: cadence::impl::G3::mul_scalar_out
79+
80+
- op: permute_copy.out
81+
kernels:
82+
- arg_meta: null
83+
kernel_name: torch::executor::permute_copy_out
84+
85+
- op: sigmoid.out
86+
kernels:
87+
- arg_meta: null
88+
kernel_name: torch::executor::sigmoid_out
89+
90+
- op: slice_copy.Tensor_out
91+
kernels:
92+
- arg_meta: null
93+
kernel_name: torch::executor::slice_copy_Tensor_out
94+
95+
- op: split_with_sizes_copy.out
96+
kernels:
97+
- arg_meta: null
98+
kernel_name: torch::executor::split_with_sizes_copy_out
99+
100+
- op: sub.out
101+
kernels:
102+
- arg_meta: null
103+
kernel_name: torch::executor::sub_out
104+
105+
- op: view_copy.out
106+
kernels:
107+
- arg_meta: null
108+
kernel_name: torch::executor::view_copy_out
109+
110+
- op: where.self_out
111+
kernels:
112+
- arg_meta: null
113+
kernel_name: torch::executor::where_out
114+
115+
- op: native_layer_norm.out
116+
kernels:
117+
- arg_meta: null
118+
kernel_name: cadence::impl::G3::native_layer_norm_out
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
cmake_minimum_required(VERSION 3.19)
8+
9+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
10+
if(NOT CMAKE_CXX_STANDARD)
11+
set(CMAKE_CXX_STANDARD 17)
12+
endif()
13+
14+
include(${EXECUTORCH_ROOT}/build/Utils.cmake)
15+
include(${EXECUTORCH_ROOT}/build/Codegen.cmake)
16+
17+
if(NOT PYTHON_EXECUTABLE)
18+
resolve_python_executable()
19+
endif()
20+
21+
# ATen compliant ops that are needed to run this model.
22+
set(_aten_ops__srcs
23+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/activation_ops_util.cpp"
24+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/copy_ops_util.cpp"
25+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/broadcast_util.cpp"
26+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/index_util.cpp"
27+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/kernel_ops_util.cpp"
28+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/matmul_ops_util.cpp"
29+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/reduce_util.cpp"
30+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/repeat_util.cpp"
31+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/slice_util.cpp"
32+
"${CMAKE_CURRENT_SOURCE_DIR}/op_add.cpp"
33+
"${CMAKE_CURRENT_SOURCE_DIR}/op_mul.cpp"
34+
"${CMAKE_CURRENT_SOURCE_DIR}/op_cat.cpp"
35+
"${CMAKE_CURRENT_SOURCE_DIR}/op_softmax.cpp"
36+
"${CMAKE_CURRENT_SOURCE_DIR}/op_native_layer_norm.cpp"
37+
"${CMAKE_CURRENT_SOURCE_DIR}/op_quantize.cpp"
38+
"${CMAKE_CURRENT_SOURCE_DIR}/op_dequantize.cpp"
39+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_bmm.cpp"
40+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_clone.cpp"
41+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_div.cpp"
42+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_embedding.cpp"
43+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_full.cpp"
44+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_permute_copy.cpp"
45+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_sigmoid.cpp"
46+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_slice_copy.cpp"
47+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_split_with_sizes_copy.cpp"
48+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_sub.cpp"
49+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_to_copy.cpp"
50+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_view_copy.cpp"
51+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/op_where.cpp"
52+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/dtype_util.cpp"
53+
"${EXECUTORCH_ROOT}/kernels/portable/cpu/util/normalization_ops_util.cpp"
54+
)
55+
add_library(aten_ops_cadence ${_aten_ops__srcs})
56+
target_link_libraries(aten_ops_cadence PUBLIC executorch)
57+
target_link_libraries(aten_ops_cadence PRIVATE xa_nnlib)
58+
59+
# Let files say "include <executorch/path/to/header.h>".
60+
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
61+
62+
target_include_directories(
63+
aten_ops_cadence PUBLIC ${ROOT_DIR}/.. ${CMAKE_BINARY_DIR}
64+
${_common_include_directories}
65+
${EXECUTORCH_ROOT}/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3/xa_nnlib/algo/common/include/
66+
${EXECUTORCH_ROOT}/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3/xa_nnlib/include/nnlib
67+
${EXECUTORCH_ROOT}/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3/xa_nnlib/include
68+
${EXECUTORCH_ROOT}/backends/cadence/fusion_g3/third-party/nnlib/nnlib-FusionG3/xa_nnlib/algo/kernels/tables/include
69+
)
70+
71+
# Generate C++ bindings to register kernels into both PyTorch (for AOT) and
72+
# Executorch (for runtime). Here select all ops in functions.yaml
73+
gen_selected_ops(
74+
LIB_NAME "cadence_ops_lib" OPS_SCHEMA_YAML
75+
"${CMAKE_CURRENT_LIST_DIR}/../../aot/functions_fusion_g3.yaml" "" ""
76+
)
77+
generate_bindings_for_kernels(
78+
LIB_NAME "cadence_ops_lib" OPS_SCHEMA_YAML FUNCTIONS_YAML
79+
${CMAKE_CURRENT_SOURCE_DIR}/../../aot/functions_fusion_g3.yaml
80+
)
81+
message("Generated files ${gen_command_sources}")
82+
83+
gen_operators_lib(
84+
LIB_NAME "cadence_ops_lib" KERNEL_LIBS DEPS aten_ops_cadence
85+
)

0 commit comments

Comments
 (0)