Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tizen7.0] PR to support Tizen7.0 #2720

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/ccapi/include/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ class Layer {
*/
virtual const std::string getType() const = 0;

/**
* @brief Initialize layer
*/
virtual void initialize() = 0;

/**
* @brief Default allowed properties
* - input shape : string
Expand Down
1 change: 1 addition & 0 deletions debian/nntrainer-dev.install
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/usr/include/nntrainer/layer_context.h
/usr/include/nntrainer/layer_devel.h
/usr/include/nntrainer/layer_impl.h
/usr/include/nntrainer/acti_func.h
# custom layer kits
/usr/include/nntrainer/app_context.h
# logger
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ if get_option('enable-fp16')
# comaptible with armv8.0 machines.
if cxx.has_argument('-mfp16-format=ieee')
add_project_arguments('-mfp16-format=ieee', language: ['c', 'cpp'])
add_project_arguments('-march=armv8.2-a+fp16', language: ['c', 'cpp'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you explain why this change is necessary?

Copy link
Contributor Author

@EunjuYang EunjuYang Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, this option is required to support FP16-SIMD. If this option is missing, it cannot use FP16-SIMD.

else
message ('The compiler does not support -mfp16-format=ieee. However, according to https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Half-Precision.html, gcc may use IEEE fp16 anyway. Thus, we will proceed without the option for FP16 support.')
endif
Expand Down
2 changes: 1 addition & 1 deletion nnstreamer/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ if get_option('enable-nnstreamer-tensor-filter').enabled()
subdir('tensor_filter')
endif
if get_option('enable-nnstreamer-tensor-trainer').enabled()
subdir('tensor_trainer')
subdir('tensor_trainer')
endif
5 changes: 3 additions & 2 deletions nntrainer/layers/layer_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,10 @@ bool RunLayerContext::validate(bool skip_input, bool skip_label) {
} else if (val->getVariableRef().getTensorType().data_type ==
TensorDim::DataType::FP16) {
#ifdef ENABLE_FP16
tensor_map[val->getName()] = val->getVariableRef().getData<_FP16>();
tensor_map[val->getName()] =
val->getVariableRef().template getData<_FP16>();
tensor_map[val->getGradientName()] =
val->getGradientRef().getData<_FP16>();
val->getGradientRef().template getData<_FP16>();
#else
throw std::invalid_argument("Error: enable-fp16 is not enabled");
#endif
Expand Down
3 changes: 0 additions & 3 deletions nntrainer/layers/layer_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,6 @@ class RunLayerContext {
d.setDataType(o_t);
w = Tensor(d, true);
}
unsigned int o_ax = getWeightObject(idx).getOutputAxis();

// t_w.dequantize(w, o_ax);

return;
}
Expand Down
5 changes: 5 additions & 0 deletions nntrainer/layers/layer_devel.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ class Layer {
*/
virtual void finalize(InitLayerContext &context) = 0;

/**
* @brief Initialize the layer
*/
virtual void initialize(RunLayerContext &context){};

/**
* @brief Forward Propagation of a layer
* @param context Context of the layer
Expand Down
2 changes: 2 additions & 0 deletions nntrainer/layers/layer_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ class LayerNode final : public ml::train::Layer, public GraphNode {
*/
InitLayerContext refinalize(const std::vector<TensorDim> &input_dims = {});

void initialize() override { layer->initialize(*run_context); }

/**
* @brief Forward Propagation of a layer
* @param training true if training, false if inference
Expand Down
1 change: 1 addition & 0 deletions nntrainer/layers/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ layer_headers = [
'layer_context.h',
'layer_devel.h',
'layer_impl.h',
'acti_func.h',
'common_properties.h',
]

Expand Down
8 changes: 4 additions & 4 deletions nntrainer/tensor/hgemm/hgemm_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ void packing_B8(unsigned int K, unsigned int N, const __fp16 *src,
unsigned int ldb, const __fp16 *dst) {
assert(K != 0 && N != 0 && N % 8 == 0);

for (int i = 0; i < K; i++) {
for (unsigned int i = 0; i < K; i++) {
const __fp16 *a_off = src + i * ldb;
__fp16 *b_off = (__fp16 *)dst + i * 8;
for (int j = 0; j < N; j += 8) {
for (unsigned int j = 0; j < N; j += 8) {
float16x8_t v = vld1q_f16(a_off);
a_off += 8;

Expand All @@ -384,10 +384,10 @@ void packing_B16(unsigned int K, unsigned int N, const __fp16 *src,
unsigned int ldb, const __fp16 *dst) {
assert(K != 0 && N != 0 && N % 16 == 0);

for (int i = 0; i < K; i++) {
for (unsigned int i = 0; i < K; i++) {
const __fp16 *a_off = src + i * ldb;
__fp16 *b_off = (__fp16 *)dst + i * 16;
for (int j = 0; j < N; j += 16) {
for (unsigned int j = 0; j < N; j += 16) {
float16x8_t v0_7 = vld1q_f16(a_off);
float16x8_t v8_15 = vld1q_f16(a_off + 8);
a_off += 16;
Expand Down
28 changes: 21 additions & 7 deletions packaging/nntrainer.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Execute gbs with --define "testcoverage 1" in case that you must get unittest coverage statistics
%define use_cblas 1
%define nnstreamer_filter 1
%define nnstreamer_trainer 1
%define nnstreamer_trainer 0
%define nnstreamer_subplugin_path /usr/lib/nnstreamer
%define use_gym 0
%define support_ccapi 1
Expand Down Expand Up @@ -131,13 +131,13 @@ BuildRequires: tensorflow2-lite-devel
BuildRequires: tensorflow2-lite-devel
%endif # support_tflite_interpreter

%define enable_nnstreamer_tensor_filter -Denable-nnstreamer-tensor-filter=false
%define enable_nnstreamer_tensor_trainer -Denable-nnstreamer-tensor-trainer=false
%define enable_nnstreamer_tensor_filter -Denable-nnstreamer-tensor-filter=disabled
%define enable_nnstreamer_tensor_trainer -Denable-nnstreamer-tensor-trainer=disabled

%if 0%{?nnstreamer_filter}
Requires: nnstreamer-nntrainer = %{version}-%{release}
BuildRequires: nnstreamer-devel
%define enable_nnstreamer_tensor_filter -Denable-nnstreamer-tensor-filter=true
%define enable_nnstreamer_tensor_filter -Denable-nnstreamer-tensor-filter=enabled

%if 0%{?unit_test}
%if 0%{tizen_version_major}%{tizen_version_minor} > 60
Expand All @@ -151,7 +151,7 @@ BuildRequires: python
%if 0%{?nnstreamer_trainer}
Requires: nnstreamer-nntrainer = %{version}-%{release}
BuildRequires: nnstreamer-devel
%define enable_nnstreamer_tensor_trainer -Denable-nnstreamer-tensor-trainer=true
%define enable_nnstreamer_tensor_trainer -Denable-nnstreamer-tensor-trainer=enabled
%endif # nnstreamer_trainer
%endif # tizen

Expand Down Expand Up @@ -393,6 +393,11 @@ export CFLAGS+=" -fprofile-arcs -ftest-coverage"
export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
%endif

%if 0%{?enable_fp16}
export CFLAGS+=" -march=armv8.2-a+fp16"
export CXXFLAGS+=" -march=armv8.2-a+fp16"
%endif

# Add backward competibility for tizen < 6
%if 0%{tizen_version_major} < 6
ln -sf %{_includedir}/nnstreamer/nnstreamer.h %{_includedir}/nnstreamer/ml-api-common.h
Expand All @@ -408,8 +413,8 @@ meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} \
%{enable_profile} %{enable_nnstreamer_backbone} %{enable_tflite_backbone} \
%{enable_tflite_interpreter} %{capi_ml_pkg_dep_resolution} \
%{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 \
-Dml-api-support=enabled \
-Denable-capi=enabled \
%{fp16_support} %{neon_support} build

ninja -C build %{?_smp_mflags}
Expand Down Expand Up @@ -560,9 +565,18 @@ cp -r result %{buildroot}%{_datadir}/nntrainer/unittest/
%{_includedir}/nntrainer/util_func.h
%{_includedir}/nntrainer/fp16.h
%{_includedir}/nntrainer/util_simd.h
# In the current version, Neon SIMD is enabled only when FP16 is enabled with AArch64.
# This may be subject to change in future versions.
%ifarch aarch64
%if 0%{?enable_fp16}
%{_includedir}/nntrainer/util_simd_neon.h
%{_includedir}/nntrainer/blas_neon.h
%{_includedir}/nntrainer/hgemm.h
%{_includedir}/nntrainer/hgemm_util.h
%endif
%endif
%{_includedir}/nntrainer/acti_func.h


%files devel-static
%{_libdir}/libnntrainer*.a
Expand Down
Loading