Skip to content

Commit

Permalink
Multi-Platform Build Support for Ruy Project in NNTrainer
Browse files Browse the repository at this point in the history
This pull request enables the Ruy project to be built in NNTrainer across multiple platforms, specifically Ubuntu, Tizen, and Android, and supports both x86 and ARM processors.
For the Tizen and Ubuntu pdebuilds, we are currently using ruy.tar.gz, which contains the packaged Ruy sources, until the Ruy package becomes available.

**Self-evaluation:**
1. Build test: [X]Passed [ ]Failed [ ]Skipped
2. Run test:   [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghyeon Jeong <[email protected]>
  • Loading branch information
djeong20 committed Feb 25, 2025
1 parent 150c744 commit 2925049
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "third_party/iniparser"]
path = third_party/iniparser
[submodule "subprojects/iniparser"]
path = subprojects/iniparser
url = https://github.com/ndevilla/iniparser.git

[submodule "third_party/ruy"]
path = third_party/ruy
[submodule "subprojects/ruy"]
path = subprojects/ruy
url = https://github.com/google/ruy
6 changes: 6 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ Depends: nnstreamer-nntrainer-trainer, ${shlibs:Depends}, ${misc:Depends}
Description: Development package for nntrainer tensor trainer
This is a developement package of nntrainer's tensor trainer.

Package: ruy
Architecture: any
Multi-Arch: same
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Ruy package
This is a ruy package for NNTrainer.
9 changes: 7 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ override_dh_auto_clean:
rm -rf build

override_dh_auto_configure:
tar -xf packaging/ruy.tar.gz -C third_party
tar -xf packaging/ruy.tar.gz -C subprojects
mkdir -p build
meson --buildtype=plain --prefix=/usr --sysconfdir=/etc \
--libdir=lib/$(DEB_HOST_MULTIARCH) --bindir=lib/nntrainer/bin \
Expand All @@ -45,7 +45,7 @@ override_dh_auto_configure:
-Dcapi-ml-common-actual=capi-ml-common \
-Dcapi-ml-inference-actual=capi-ml-inference \
-Denable-capi=enabled \
build
build --wrap-mode=nodownload

override_dh_auto_build:
ninja -C build
Expand All @@ -58,6 +58,11 @@ override_dh_auto_install:

override_dh_install:
dh_install --sourcedir=debian/tmp
if [ "$(DEB_HOST_ARCH)" = "amd64" ]; then \
dh_install /usr/bin/cpuid_dump; \
else \
echo "Skipping cpuid_dump on non-x86_64 architecture"; \
fi

override_dh_missing:
dh_missing --fail-missing
Expand Down
6 changes: 6 additions & 0 deletions debian/ruy.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/usr/lib/*/libruy*.a
/usr/lib/*/libclog.a
/usr/lib/*/libcpuinfo.a
/usr/bin/cache_info
/usr/bin/cpu_info
/usr/bin/isa_info
17 changes: 17 additions & 0 deletions jni/Android.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := ruy
LOCAL_SRC_FILES := @MESON_RUY_ROOT@/ruy/apply_multiplier.cc \
@MESON_RUY_ROOT@/ruy/block_map.cc \
@MESON_RUY_ROOT@/ruy/blocking_counter.cc \
@MESON_RUY_ROOT@/ruy/context.cc \
@MESON_RUY_ROOT@/ruy/context_get_ctx.cc \
@MESON_RUY_ROOT@/ruy/ctx.cc \
@MESON_RUY_ROOT@/ruy/frontend.cc \
@MESON_RUY_ROOT@/ruy/kernel_arm32.cc \
@MESON_RUY_ROOT@/ruy/pack_arm.cc \
LOCAL_C_INCLUDES := @MESON_RUY_ROOT@/ruy
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := nntrainer
LOCAL_SRC_FILES := @MESON_NNTRAINER_SRCS@
# @todo ML_API_COMMON_ROOT should be included by exporting ml-api-common lib later
Expand Down
4 changes: 4 additions & 0 deletions jni/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ if iniparser_dep.found()
and_conf.set('MESON_INIPARSER_ROOT', iniparser_root)
endif

if ruy_dep.found()
and_conf.set('MESON_RUY_ROOT', ruy_root)
endif

if tflite_dep.found()
and_conf.set('MESON_HAS_TFLITE', 1)
and_conf.set('MESON_TFLITE_ROOT', tflite_root)
Expand Down
27 changes: 25 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ project('nntrainer', 'c', 'cpp',
'cpp_std=c++17',
'buildtype=release'
],
subproject_dir: 'third_party'
)

# Set version info
Expand Down Expand Up @@ -370,7 +369,7 @@ endif
thread_dep = dependency('threads') # pthread for tensorflow-lite

if get_option('platform') == 'android'
iniparser_root = meson.source_root() / 'third_party' / 'iniparser'
iniparser_root = meson.source_root() / 'subprojects' / 'iniparser'
iniparser_dep = declare_dependency()
else
iniparser_dep = dependency('iniparser', required : false, version : '>=3.2') # iniparser
Expand All @@ -390,6 +389,30 @@ else
endif
endif

# Configure the Ruy project (CMake)
if get_option('platform') == 'android'
ruy_root = meson.source_root() / 'subprojects' / 'ruy'
ruy_dep = declare_dependency()
else
cmake = import('cmake')

ruy_options = cmake.subproject_options()
ruy_options.add_cmake_defines({'RUY_MINIMAL_BUILD': true})
ruy_flags = [
'-Wno-error=unused-result',
'-Wno-error=comment',
'-Wno-error=maybe-uninitialized',
'-Wno-error=unknown-pragmas',
'-Wno-error=unused-function',
'-Wno-error=stringop-overread',
'-Wno-error=array-parameter'
]
ruy_options.append_compile_args('c', ruy_flags)
ruy_options.append_compile_args('cpp', ruy_flags)
ruy_proj = cmake.subproject('ruy', options: ruy_options, required: true)
ruy_dep = ruy_proj.dependency('ruy').partial_dependency(includes: true)
endif

if get_option('platform') == 'android'
message('preparing ml api')
run_command(meson.source_root() / 'jni' / 'prepare_ml-api.sh', meson.build_root() / 'ml-api-inference', check: true)
Expand Down
12 changes: 3 additions & 9 deletions nntrainer/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ else
nntrainer_base_deps=[
blas_dep,
iniparser_dep,
ruy_dep,
ml_api_common_dep,
libm_dep,
libdl_dep,
Expand Down Expand Up @@ -64,20 +65,13 @@ foreach elem : nntrainer_elements
nntrainer_inc_abs += meson.current_source_dir() / elem
endforeach

# add third party to include path
fs = import('fs')
if fs.is_dir('../third_party/ruy')
nntrainer_inc += include_directories('../third_party/ruy')
nntrainer_inc_abs += meson.source_root() / 'third_party' / 'ruy'
else
error('The git submodules of the nntrainer repository have not been checked out.\n Try: git submodule update --init')
endif

nntrainer_common_sources = [
'nntrainer_logger.cpp',
'app_context.cpp'
]

nntrainer_inc_abs += meson.source_root() / 'subprojects' / 'ruy'

if get_option('enable-opencl')
nntrainer_headers += meson.current_source_dir() / 'cl_context.h'
nntrainer_headers += meson.current_source_dir() / 'cl_buffer_manager.h'
Expand Down
24 changes: 22 additions & 2 deletions packaging/nntrainer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ BuildRequires: gtest-devel
BuildRequires: python3
BuildRequires: python3-numpy
BuildRequires: flatbuffers-devel
BuildRequires: cmake

%if 0%{?unit_test}
BuildRequires: ssat >= 1.1.0
Expand Down Expand Up @@ -325,6 +326,10 @@ Requires: nnstreamer-nntrainer-trainer = %{version}-%{release}
NNSteamer tensor trainer static package for nntrainer to support inference.
%endif #nnstreamer_trainer

%package -n ruy
Summary: Ruy support in NNTrainer
%description -n ruy

%endif #tizen

## Define build options
Expand Down Expand Up @@ -412,7 +417,7 @@ ln -sf %{_libdir}/pkgconfig/capi-nnstreamer.pc %{_libdir}/pkgconfig/capi-ml-comm
%endif

# Setup Ruy
tar -xf packaging/ruy.tar.gz -C third_party
tar -xf packaging/ruy.tar.gz -C subprojects

mkdir -p build
meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} \
Expand All @@ -425,7 +430,7 @@ meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} \
%{enable_reduce_tolerance} %{configure_subplugin_install_path} %{enable_debug} \
-Dml-api-support=enabled -Denable-nnstreamer-tensor-filter=enabled \
-Denable-nnstreamer-tensor-trainer=enabled -Denable-capi=enabled \
%{fp16_support} %{neon_support} %{avx_support} build
%{fp16_support} %{neon_support} %{avx_support} build --wrap-mode=nodownload

ninja -C build %{?_smp_mflags}

Expand Down Expand Up @@ -690,6 +695,21 @@ cp -r result %{buildroot}%{_datadir}/nntrainer/unittest/
%{_libdir}/libnnstreamer_trainer_nntrainer.a
%endif #nnstreamer_trainer

# Ruy
%files -n ruy
%manifest nntrainer.manifest
%defattr(-,root,root,-)
%license LICENSE
%{_libdir}/libruy*.a
%{_libdir}/libclog.a
%{_libdir}/libcpuinfo.a
%{_bindir}/cache_info
%{_bindir}/cpu_info
%{_bindir}/isa_info
%ifarch x86_64
%{_bindir}/cpuid_dump
%endif #x86_64

%endif #tizen

%files applications
Expand Down
Binary file modified packaging/ruy.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions subprojects/iniparser
Submodule iniparser added at 4bef81
File renamed without changes.
4 changes: 4 additions & 0 deletions subprojects/ruy.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wrap-git]
url = https://github.com/google/ruy
directory = ruy
revision = HEAD
4 changes: 4 additions & 0 deletions test/jni/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if iniparser_dep.found()
and_conf.set('MESON_INIPARSER_ROOT', iniparser_root)
endif

if ruy_dep.found()
and_conf.set('MESON_RUY_ROOT', ruy_root)
endif

if tflite_dep.found()
and_conf.set('MESON_HAS_TFLITE', 1)
and_conf.set('MESON_TFLITE_ROOT', tflite_root)
Expand Down
1 change: 0 additions & 1 deletion third_party/iniparser
Submodule iniparser deleted from 19e0ad

0 comments on commit 2925049

Please sign in to comment.