Skip to content

Commit

Permalink
[onert] Update version eigen (Samsung#3086)
Browse files Browse the repository at this point in the history
- Update version eigen used for cker computation library (eigen for 2.3.0-rc0)
- TFLite 1.13.1 library uses eigen for 1.13.1
- Update copyright eigen_sptial_convolutions-inl.h

Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh authored Jul 14, 2020
1 parent 1c863c7 commit 1c931aa
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 58 deletions.
4 changes: 4 additions & 0 deletions compute/cker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ if(PROFILE_RUY)
endif(PROFILE_RUY)

target_include_directories(nnfw_lib_cker INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Workaround to avoid warning
# TODO Resolve warning
target_compile_options(nnfw_lib_cker INTERFACE -Wno-attributes)
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TensorEvaluatorHasPartialPacket
typedef decltype(
functionExistsSfinae<TensorEvaluatorType, PacketType, IndexType>(nullptr)) status;

static const bool value = status::value;
static constexpr bool value = status::value;
};

// Compute a mask for loading/storing coefficients in/from a packet in a
Expand Down
79 changes: 54 additions & 25 deletions compute/cker/include/cker/eigen/eigen_spatial_convolutions-inl.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
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.
==============================================================================*/
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
*
* 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.
*/

#ifndef __NNFW_CKER_EIGEN_EIGEN_SPATIAL_CONVOLUTIONS_INL_H__
#define __NNFW_CKER_EIGEN_EIGEN_SPATIAL_CONVOLUTIONS_INL_H__
Expand Down Expand Up @@ -127,6 +129,7 @@ class TensorContractionInputMapper<
m_colStride = patch_rows;

m_outputRows = tensor.impl().outputRows();
m_outputCols = tensor.impl().outputCols();
m_row_strides = tensor.impl().userRowStride();
m_col_strides = tensor.impl().userColStride();

Expand Down Expand Up @@ -185,6 +188,7 @@ class TensorContractionInputMapper<
m_inputCols = base_mapper.m_inputCols;

m_outputRows = base_mapper.m_outputRows;
m_outputCols = base_mapper.m_outputCols;
m_row_strides = base_mapper.m_row_strides;
m_col_strides = base_mapper.m_col_strides;

Expand Down Expand Up @@ -361,7 +365,7 @@ class TensorContractionInputMapper<
// the elements corresponding to the column (specified through colOffset) are
// loaded and the rest of the elements are zero-filled into the 'partial'
// packet. This function is called from loadPacketStandardFromTwoColumns().
// This code path is exercied only when the packet type supports masked load
// This code path is exercised only when the packet type supports masked load
// and when the partial packet load is available in the TensorEvaluator.
EIGEN_DEVICE_FUNC
EIGEN_ALWAYS_INLINE Packet loadPartialPacketStandard(Index rowIndex, Index colIndex,
Expand Down Expand Up @@ -482,7 +486,7 @@ class TensorContractionInputMapper<
// Load standard packet from a patch specified by the "within patch offset"
// (patchId) and the precomputed indices of the first element of the patch.
// This function will be called if partial packet loading is not available
// for the TesnorEvaluator or if the packet type does not support masked
// for the TensorEvaluator or if the packet type does not support masked
// load.
template <typename PacketT, typename TensorEvaluatorT>
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE typename std::enable_if<
Expand Down Expand Up @@ -524,7 +528,7 @@ class TensorContractionInputMapper<
// Load standard packet from a patch specified by the "within patch offset"
// (patchId) and the precomputed indices of the first element of the patch.
// This function will be called if partial packet loading is available for
// the TesnorEvaluator and if the packet type supports masked load.
// the TensorEvaluator and if the packet type supports masked load.
// The only difference between this and the other case is that if the packet
// to load is split across two columns, then in this case instead of going to
// the slow (element-by-element) load, we load two packets - each containing
Expand Down Expand Up @@ -651,7 +655,7 @@ class TensorContractionInputMapper<
internal::TensorIntDivisor<Index> m_fastInputRowStride;
internal::TensorIntDivisor<Index> m_fastInputColStride;

// Index m_otherStride; // Unused this field
Index m_otherStride;
Index m_colStride;
internal::TensorIntDivisor<Index> m_fastNumPatches;
internal::TensorIntDivisor<Index> m_fastColStride;
Expand All @@ -663,7 +667,8 @@ class TensorContractionInputMapper<
Index m_inputRows; // Number of rows in the input tensor
Index m_inputCols; // Number of cols in the input tensor

Index m_outputRows; // Number of patch rows
Index m_outputRows; // Number of convolution output rows
Index m_outputCols; // Number of convolution output column

Index m_row_strides; // User specified row stride
Index m_col_strides; // User specified col stride
Expand Down Expand Up @@ -865,6 +870,32 @@ class TensorContractionSubMapper<
mask<PacketT>(0, num_coeffs));
}
EIGEN_DEVICE_FUNC
EIGEN_ALWAYS_INLINE bool hasPadding() const
{
// TODO(ezhulenev): It does seems that for inflated filter it's still
// possible to guarantee "no padding or skipping" for non-standard packing.
if (nonStandardPatches())
return true;

// Non zero padding before.
if (m_base_mapper.m_rowPaddingTop > 0)
return true;
if (m_base_mapper.m_colPaddingLeft > 0)
return true;

// Non zero padding after in rows.
const Index last_row = (m_base_mapper.m_outputRows - 1) * m_base_mapper.m_row_strides;
if (last_row + (patchRows() - 1) >= m_base_mapper.m_inputRows)
return true;

// Non zero padding after in cols.
const Index last_col = (m_base_mapper.m_outputCols - 1) * m_base_mapper.m_col_strides;
if (last_col + (patchCols() - 1) >= m_base_mapper.m_inputCols)
return true;

return false;
}
EIGEN_DEVICE_FUNC
EIGEN_ALWAYS_INLINE bool padRow(const Index row) const
{
const Index r = m_rowIndex + row;
Expand Down Expand Up @@ -1619,17 +1650,15 @@ SpatialConvolution(const Input &input, const Kernel &kernel, const Index row_str
{
const TensorIndex InputRowsEff = InputRows + padding_top + padding_bottom;
const TensorIndex InputColsEff = InputCols + padding_left + padding_right;
out_height =
numext::ceil((InputRowsEff - kernelRowsEff + 1.f) / static_cast<float>(row_stride));
out_width =
numext::ceil((InputColsEff - kernelColsEff + 1.f) / static_cast<float>(col_stride));
out_height = divup(InputRowsEff - kernelRowsEff + 1, row_stride);
out_width = divup(InputColsEff - kernelColsEff + 1, col_stride);
break;
}
case PADDING_SAME:
{
eigen_assert(!padding_explicit);
out_height = numext::ceil(InputRows / static_cast<float>(row_stride));
out_width = numext::ceil(InputCols / static_cast<float>(col_stride));
out_height = divup(InputRows, row_stride);
out_width = divup(InputCols, col_stride);
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ typedef unsigned __int64 uint64_t;
#include <time.h>
#endif

// #if defined(EIGEN_USE_LIBXSMM)
// #include "libxsmm.h"
// #endif

#ifdef EIGEN_USE_THREADS
#include "unsupported/Eigen/CXX11/ThreadPool"
#endif
Expand All @@ -97,7 +93,6 @@ typedef unsigned __int64 uint64_t;
#include "unsupported/Eigen/CXX11/src/Tensor/TensorDeviceDefault.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorDeviceThreadPool.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorDeviceGpu.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorDeviceSycl.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorIndexList.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorDimensionList.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorDimensions.h"
Expand Down Expand Up @@ -154,7 +149,6 @@ typedef unsigned __int64 uint64_t;
#include "unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorScan.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorTrace.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorSycl.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h"
#include "unsupported/Eigen/CXX11/src/Tensor/TensorStorage.h"
Expand Down
23 changes: 23 additions & 0 deletions infra/cmake/packages/TensorFlowEigenSource-2.3.0-rc0Config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function(_TensorFlowEigenSource_import)
if(NOT DOWNLOAD_EIGEN)
set(TensorFlowEigenSource_FOUND FALSE PARENT_SCOPE)
return()
endif(NOT DOWNLOAD_EIGEN)

nnas_include(ExternalSourceTools)
nnas_include(OptionTools)

# NOTE TensorFlow 2.3.0-rc0 uses the following URL
envoption(EXTERNAL_DOWNLOAD_SERVER "https://gitlab.com")
envoption(TENSORFLOW_2_3_0_EIGEN_URL ${EXTERNAL_DOWNLOAD_SERVER}/libeigen/eigen/-/archive/386d809bde475c65b7940f290efe80e6a05878c4/eigen-386d809bde475c65b7940f290efe80e6a05878c4.tar.gz)

ExternalSource_Download(EIGEN
DIRNAME TENSORFLOW-2.3.0-EIGEN
URL ${TENSORFLOW_2_3_0_EIGEN_URL}
)

set(TensorFlowEigenSource_DIR ${EIGEN_SOURCE_DIR} PARENT_SCOPE)
set(TensorFlowEigenSource_FOUND TRUE PARENT_SCOPE)
endfunction(_TensorFlowEigenSource_import)

_TensorFlowEigenSource_import()
8 changes: 4 additions & 4 deletions infra/nnfw/cmake/packages/EigenConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
function(_Eigen_import)
nnfw_find_package(EigenSource QUIET)
nnas_find_package(TensorFlowEigenSource-2.3.0-rc0 QUIET)

if(NOT EigenSource_FOUND)
if(NOT TensorFlowEigenSource_FOUND)
set(Eigen_FOUND FALSE PARENT_SCOPE)
return()
endif(NOT EigenSource_FOUND)
endif(NOT TensorFlowEigenSource_FOUND)

if(NOT TARGET eigen)
add_library(eigen INTERFACE)
target_include_directories(eigen SYSTEM INTERFACE "${EigenSource_DIR}")
target_include_directories(eigen SYSTEM INTERFACE "${TensorFlowEigenSource_DIR}")
# Add EIGEN_MPL2_ONLY to remove license issue posibility
target_compile_definitions(eigen INTERFACE EIGEN_MPL2_ONLY)
endif(NOT TARGET eigen)
Expand Down
19 changes: 0 additions & 19 deletions infra/nnfw/cmake/packages/EigenSourceConfig.cmake

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function(_Eigen_import)
nnas_find_package(EigenSource QUIET)

if(NOT EigenSource_FOUND)
set(TensorFlowEigen_1_13_1_FOUND FALSE PARENT_SCOPE)
return()
endif(NOT EigenSource_FOUND)

if(NOT TARGET eigen-tf-1.13.1)
add_library(eigen-tf-1.13.1 INTERFACE)
target_include_directories(eigen-tf-1.13.1 SYSTEM INTERFACE "${EigenSource_DIR}")
# Add EIGEN_MPL2_ONLY to remove license issue posibility
target_compile_definitions(eigen-tf-1.13.1 INTERFACE EIGEN_MPL2_ONLY)
endif(NOT TARGET eigen-tf-1.13.1)

set(TensorFlowEigen_1_13_1_FOUND TRUE PARENT_SCOPE)
endfunction(_Eigen_import)

_Eigen_import()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(PACKAGE_VERSION "1.13.1")
set(PACKAGE_VERSION_EXACT FALSE)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
set(PACKAGE_VERSION_UNSUITABLE TRUE)

if(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
set(PACKAGE_VERSION_EXACT TRUE)
set(PACKAGE_VERSION_UNSUITABLE FALSE)
endif(PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION)
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ add_library(tensorflow-lite STATIC ${TFLITE_SRCS})
target_include_directories(tensorflow-lite SYSTEM PUBLIC ${TFLITE_INCLUDES})
target_compile_definitions(tensorflow-lite PUBLIC "GEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK")
set_property(TARGET tensorflow-lite PROPERTY POSITION_INDEPENDENT_CODE ON)
target_link_libraries(tensorflow-lite eigen flatbuffers::flatbuffers ${LIB_PTHREAD} dl)
target_link_libraries(tensorflow-lite eigen-tf-1.13.1 flatbuffers::flatbuffers ${LIB_PTHREAD} dl)

if(ANDROID)
target_link_libraries(tensorflow-lite log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ if(BUILD_TENSORFLOW_LITE)
# Required packages
nnas_find_package(AbseilSource QUIET)
return_unless(AbseilSource_FOUND)
nnfw_find_package(Eigen QUIET)
return_unless(Eigen_FOUND)
nnfw_find_package(TensorFlowEigen EXACT 1.13.1 QUIET)
return_unless(TensorFlowEigen_1_13_1_FOUND)
nnfw_find_package(FarmhashSource QUIET)
return_unless(FarmhashSource_FOUND)
nnfw_find_package(FlatBuffers QUIET)
Expand Down
Binary file modified packaging/eigen.tar.gz
Binary file not shown.

0 comments on commit 1c931aa

Please sign in to comment.