From b097ef8ad83c67e6bed0f881369e5debb73e4673 Mon Sep 17 00:00:00 2001 From: wangguokun Date: Tue, 19 Mar 2024 02:56:57 +0000 Subject: [PATCH] lib/ruy: port lib-ruy to tenonos Signed-off-by: wangguokun --- Config.uk | 3 ++ Makefile.uk | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 20 +++++++++++ patches/.keep | 0 4 files changed, 117 insertions(+) create mode 100644 Config.uk create mode 100644 Makefile.uk create mode 100644 README.md create mode 100644 patches/.keep diff --git a/Config.uk b/Config.uk new file mode 100644 index 0000000..03f35be --- /dev/null +++ b/Config.uk @@ -0,0 +1,3 @@ +menuconfig LIBRUY + bool "ruy: ruy is a matrix multiplication library" + default n diff --git a/Makefile.uk b/Makefile.uk new file mode 100644 index 0000000..ae31e7a --- /dev/null +++ b/Makefile.uk @@ -0,0 +1,94 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2024 The TenonOS Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +################################################################################ +# Library registration +################################################################################ +$(eval $(call addlib_s,libruy,$(CONFIG_LIBRUY))) + +################################################################################ +# Sources +################################################################################ +LIBRUY_COMMIT=841ea4172ba904fe3536789497f9565f2ef64129 +LIBRUY_URL=https://github.com/google/ruy/archive/$(LIBRUY_COMMIT).zip +LIBRUY_DIRNAME=ruy-$(LIBRUY_COMMIT) + +ifeq ($(CONFIG_LIBRUY), y) +$(eval $(call fetch,libruy,$(LIBRUY_URL))) +endif + +################################################################################ +# Helpers +################################################################################ +LIBRUY_SRC = $(LIBRUY_ORIGIN)/$(LIBRUY_DIRNAME) + +################################################################################ +# Library includes +################################################################################ +LIBRUY__INCLUDES += $(LIBRUY_SRC) +CINCLUDES-$(CONFIG_LIBRUY) += -I$(LIBRUY__INCLUDES) +CXXINCLUDES-$(CONFIG_LIBRUY) += -I$(LIBRUY__INCLUDES) + +################################################################################ +# Global flags +################################################################################ +GCC_INSTALLDIR_FLAGS := -idirafter $(shell LC_ALL=C $(CC) -v 2>&1 | \ + $(SED) -e '/^COLLECT_LTO_WRAPPER=\(.*\)\/lto-wrapper/!d' -e 's//\1/')/include + +ifdef CONFIG_ARCH_X86_64 +LIBRUY_CFLAGS-$(CONFIG_ARCH_X86_64) += $(GCC_INSTALLDIR_FLAGS) +LIBRUY_CXXFLAGS-$(CONFIG_ARCH_X86_64) += $(GCC_INSTALLDIR_FLAGS) +endif + +ifdef CONFIG_ARCH_ARM_64 +LIBRUY_CFLAGS-$(CONFIG_ARCH_ARM_64) += $(GCC_INSTALLDIR_FLAGS) +LIBRUY_CXXFLAGS-$(CONFIG_ARCH_ARM_64) += $(GCC_INSTALLDIR_FLAGS) +endif + +################################################################################ +# Library sources +################################################################################ +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/profiler/treeview.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/profiler/profiler.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/profiler/instrumentation.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/pack_arm.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/tune.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/cpuinfo.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/system_aligned_alloc.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/prepare_packed_matrices.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/prepacked_cache.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/kernel_avx2_fma.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/pack_avx512.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/thread_pool.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/have_built_path_for_avx.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/context.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/kernel_arm64.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/denormal.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/apply_multiplier.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/kernel_avx.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/kernel_avx512.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/wait.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/pack_avx.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/have_built_path_for_avx2_fma.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/kernel_arm32.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/block_map.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/context_get_ctx.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/have_built_path_for_avx512.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/ctx.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/pack_avx2_fma.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/frontend.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/trmul.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/blocking_counter.cc +LIBRUY_SRCS-y += $(LIBRUY_SRC)/ruy/allocator.cc diff --git a/README.md b/README.md new file mode 100644 index 0000000..aeb28bd --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +# lib-ruy + +## 微库提供的功能与说明 + +ruy是一个矩阵乘法库,旨在满足神经网络推理引擎的矩阵乘法需求。它的最初用户是TensorFlow Lite,默认在ARM CPU架构上使用。 + +ruy支持的详细特性可见其官方文档: https://github.com/google/ruy + +本仓库将ruy作为微库移植到TenonOS,目录结构如下: + +```powershell +. +├── Config.uk ----- 维护微库配置 +├── Makefile.uk ------ 用于微库构建 +└── patches ------ 维护对ruy源码的修改 +``` + +## 编译构建与配置说明 + +ruy微库不依赖其他微库,默认不启用 diff --git a/patches/.keep b/patches/.keep new file mode 100644 index 0000000..e69de29 -- Gitee