diff --git a/.gitmodules b/.gitmodules index fe94639740..36cc5905b6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,9 +5,6 @@ [submodule "third_party/googletest"] path = third_party/googletest url = https://github.com/google/googletest.git -[submodule "third_party/incubator-tvm"] - path = third_party/incubator-tvm - url = https://github.com/apache/incubator-tvm.git [submodule "third_party/protobuf"] path = third_party/protobuf url = https://github.com/protocolbuffers/protobuf.git @@ -17,7 +14,7 @@ url = https://gitee.com/mindspore/akg.git [submodule "graphengine"] path = graphengine - url = https://gitee.com/ms-incubator/graphengine.git + url = https://gitee.com/mindspore/graphengine.git [submodule "third_party/OpenCL-CLHPP"] path = third_party/OpenCL-CLHPP url = https://github.com/KhronosGroup/OpenCL-CLHPP.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cebff4083..2eef710753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") add_subdirectory(mindspore/ccsrc) +add_subdirectory(mindspore/core) if (ENABLE_TESTCASES) add_subdirectory(tests) endif() diff --git a/akg b/akg index 5fe7e5c837..8f9af74f59 160000 --- a/akg +++ b/akg @@ -1 +1 @@ -Subproject commit 5fe7e5c8377dccfd35c9f661e10ed3dc136208c5 +Subproject commit 8f9af74f59837579034610a741f5b8f33db12515 diff --git a/build.sh b/build.sh index 23d26e4eab..82a566d77f 100755 --- a/build.sh +++ b/build.sh @@ -109,7 +109,7 @@ checkopts() ENABLE_GPU="off" # Process the options - while getopts 'drvj:c:t:hsb:a:g:p:ie:m:l:I:LRP:Q:D:zM:V:K:swB:En' opt + while getopts 'drvj:c:t:hsb:a:g:p:ie:m:l:I:LRP:Q:D:zM:V:K:swB:EnT:' opt do OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]') case "${opt}" in @@ -282,6 +282,11 @@ checkopts() ENABLE_IBVERBS="on" echo "enable IBVERBS for parameter server" ;; + T) + check_on_off $OPTARG T + SUPPORT_TRAIN=$OPTARG + echo "support train on device " + ;; *) echo "Unknown option ${opt}!" usage @@ -397,7 +402,7 @@ checkndk() { if [ "${ANDROID_NDK}" ]; then echo -e "\e[31mANDROID_NDK_PATH=$ANDROID_NDK \e[0m" else - echo -e "\e[31mplease set ANDROID_NDK_PATH in environment variable for example: export ANDROID_NDK=/root/usr/android-ndk-r20b/ \e[0m" + echo -e "\e[31mplease set ANDROID_NDK in environment variable for example: export ANDROID_NDK=/root/usr/android-ndk-r20b/ \e[0m" exit 1 fi } @@ -569,6 +574,39 @@ build_minddata_lite_deps() build_jpeg_turbo } +prepare_md_lite() { + if [ "${COMPILE_MINDDATA_LITE}" == "on" ]; then + echo "packaging minddata" + cp ${BASEPATH}/mindspore/ccsrc/minddata/dataset/include/*h ${OUTPUT_DIR}/include/ + cp ${BASEPATH}/mindspore/lite/build/minddata/libminddata-lite.so ${OUTPUT_DIR}/lib/ + if [[ "$LITE_PLATFORM" == "x86_64" ]]; then + mkdir -p ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib + cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libjpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/ + cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libturbojpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/ + mkdir -p ${OUTPUT_DIR}/third_party/opencv/lib/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/libopencv_core.so ${OUTPUT_DIR}/third_party/opencv/lib/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/libopencv_imgcodecs.so ${OUTPUT_DIR}/third_party/opencv/lib/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/libopencv_imgproc.so ${OUTPUT_DIR}/third_party/opencv/lib/ + elif [[ "$LITE_PLATFORM" == "arm64" ]]; then + mkdir -p ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib + cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libjpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/ + cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libturbojpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/ + mkdir -p ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/arm64-v8a/libopencv_core.so ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgcodecs.so ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgproc.so ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/ + elif [[ "$LITE_PLATFORM" == "arm32" ]]; then + mkdir -p ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib + cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libjpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/ + cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libturbojpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/ + mkdir -p ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/armeabi-v7a/libopencv_core.so ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgcodecs.so ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/ + cp -r ${BASEPATH}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgproc.so ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/ + fi + fi +} + build_lite() { echo "start build mindspore lite project" @@ -632,6 +670,7 @@ build_lite() mkdir -p ${OUTPUT_DIR}/converter && mkdir -p ${OUTPUT_DIR}/time_profile mkdir -p ${OUTPUT_DIR}/benchmark && mkdir -p ${OUTPUT_DIR}/include && mkdir -p ${OUTPUT_DIR}/lib mkdir -p ${OUTPUT_DIR}/third_party + prepare_md_lite cp ${BASEPATH}/mindspore/lite/build/tools/converter/converter_lite ${OUTPUT_DIR}/converter/ cp ${BASEPATH}/mindspore/lite/build/tools/benchmark/benchmark ${OUTPUT_DIR}/benchmark/ cp ${BASEPATH}/mindspore/lite/build/tools/time_profile/timeprofile ${OUTPUT_DIR}/time_profile/ @@ -643,8 +682,7 @@ build_lite() cp ${BASEPATH}/mindspore/lite/build/src/libmindspore-lite.so ${OUTPUT_DIR}/lib/ mkdir -p ${OUTPUT_DIR}/third_party/protobuf/lib cp -r ${BASEPATH}/third_party/protobuf/build/include/ ${OUTPUT_DIR}/third_party/protobuf/ - cp -r ${BASEPATH}/third_party/protobuf/build/lib/libprotobuf.so.19 ${OUTPUT_DIR}/third_party/protobuf/lib/ - cp -r ${BASEPATH}/third_party/protobuf/build/lib/libprotobuf.so.19.0.0 ${OUTPUT_DIR}/third_party/protobuf/lib/ + cp -r ${BASEPATH}/third_party/protobuf/build/lib/libprotobuf.so.19.0.0 ${OUTPUT_DIR}/third_party/protobuf/lib/libprotobuf.so.19 mkdir -p ${OUTPUT_DIR}/third_party/flatbuffers cp -r ${BASEPATH}/third_party/flatbuffers/include/ ${OUTPUT_DIR}/third_party/flatbuffers/ cd .. @@ -657,6 +695,7 @@ build_lite() mkdir -p ${OUTPUT_DIR}/time_profile && mkdir -p ${OUTPUT_DIR}/benchmark mkdir -p ${OUTPUT_DIR}/include && mkdir -p ${OUTPUT_DIR}/lib mkdir -p ${OUTPUT_DIR}/third_party + prepare_md_lite cp ${BASEPATH}/mindspore/lite/build/tools/benchmark/benchmark ${OUTPUT_DIR}/benchmark/ cp ${BASEPATH}/mindspore/lite/build/tools/time_profile/timeprofile ${OUTPUT_DIR}/time_profile/ cp ${BASEPATH}/mindspore/lite/include/*.h ${OUTPUT_DIR}/include/ @@ -677,6 +716,7 @@ build_lite() mkdir -p ${OUTPUT_DIR}/time_profile && mkdir -p ${OUTPUT_DIR}/benchmark mkdir -p ${OUTPUT_DIR}/include && mkdir -p ${OUTPUT_DIR}/lib mkdir -p ${OUTPUT_DIR}/third_party + prepare_md_lite cp ${BASEPATH}/mindspore/lite/build/tools/benchmark/benchmark ${OUTPUT_DIR}/benchmark/ cp ${BASEPATH}/mindspore/lite/build/tools/time_profile/timeprofile ${OUTPUT_DIR}/time_profile/ cp ${BASEPATH}/mindspore/lite/include/*.h ${OUTPUT_DIR}/include/ diff --git a/cmake/external_libs/jpeg_turbo.cmake b/cmake/external_libs/jpeg_turbo.cmake index b37089bfa1..4bf64971a5 100644 --- a/cmake/external_libs/jpeg_turbo.cmake +++ b/cmake/external_libs/jpeg_turbo.cmake @@ -8,11 +8,12 @@ endif() set(jpeg_turbo_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack") mindspore_add_pkg(jpeg_turbo VER 2.0.4 - LIBS jpeg + LIBS jpeg turbojpeg URL https://github.com/libjpeg-turbo/libjpeg-turbo/archive/2.0.4.tar.gz MD5 44c43e4a9fb352f47090804529317c88 - CMAKE_OPTION -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_RPATH=TRUE + CMAKE_OPTION -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_RPATH=TRUE -DWITH_SIMD=ON PATCHES ${CMAKE_SOURCE_DIR}/third_party/patch/jpeg_turbo/jpeg_turbo.patch001 ) include_directories(${jpeg_turbo_INC}) add_library(mindspore::jpeg_turbo ALIAS jpeg_turbo::jpeg) +add_library(mindspore::turbojpeg ALIAS jpeg_turbo::turbojpeg) diff --git a/cmake/package.cmake b/cmake/package.cmake index edc88c2b34..a7bbe7d41e 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -52,12 +52,6 @@ install( COMPONENT mindspore ) -install( - TARGETS mindspore_gvar - DESTINATION ${INSTALL_LIB_DIR} - COMPONENT mindspore -) - if (USE_GLOG) file(GLOB_RECURSE GLOG_LIB_LIST ${glog_LIBPATH}/libglog*) install( @@ -146,15 +140,6 @@ if (ENABLE_MPI) COMPONENT mindspore ) endif () - file(GLOB_RECURSE MPI_LIB_LIST - ${ompi_LIBPATH}/libmpi${CMAKE_SHARED_LIBRARY_SUFFIX}* - ${ompi_LIBPATH}/libopen*${CMAKE_SHARED_LIBRARY_SUFFIX}* - ) - install( - FILES ${MPI_LIB_LIST} - DESTINATION ${INSTALL_LIB_DIR} - COMPONENT mindspore - ) endif () if (ENABLE_GPU) diff --git a/graphengine b/graphengine index 377b216518..622af6c1c5 160000 --- a/graphengine +++ b/graphengine @@ -1 +1 @@ -Subproject commit 377b2165184fbfbb32829266822438e439861f14 +Subproject commit 622af6c1c50034bea5a08bd409c5a410782bfe53 diff --git a/mindspore/_extends/parse/__init__.py b/mindspore/_extends/parse/__init__.py index 10a991c1ed..cd13d329a3 100644 --- a/mindspore/_extends/parse/__init__.py +++ b/mindspore/_extends/parse/__init__.py @@ -22,7 +22,7 @@ from .parser import (Parser, create_obj_instance, generate_scope, get_dataclass_attributes, get_dataclass_methods, get_obj_id, get_module_namespace, get_obj_type, get_object_key, get_parse_method_of_class, get_scope_name, - is_class_member, parse_cb, resolve_symbol) + is_class_member, parse_cb, resolve_symbol, convert_to_ms_tensor) from .serialize import * __all__ = ['parse_cb', 'get_parse_method_of_class', 'get_bprop_method_of_class', 'resolve_symbol', @@ -30,4 +30,4 @@ __all__ = ['parse_cb', 'get_parse_method_of_class', 'get_bprop_method_of_class', 'get_obj_type', 'get_obj_id', 'create_obj_instance', 'get_module_namespace', 'get_class_member_namespace_symbol', 'get_obj_id', 'Parser', 'get_dataclass_attributes', 'get_dataclass_methods', 'dump_obj', 'load_obj', 'get_dataclass_methods', 'get_scope_name', - 'create_slice_obj'] + 'create_slice_obj', 'convert_to_ms_tensor'] diff --git a/mindspore/_extends/parse/parser.py b/mindspore/_extends/parse/parser.py index 695f449f83..30f48f826f 100644 --- a/mindspore/_extends/parse/parser.py +++ b/mindspore/_extends/parse/parser.py @@ -25,6 +25,7 @@ from dataclasses import is_dataclass import asttokens import mindspore.nn as nn from mindspore import log as logger +from mindspore import Tensor as MsTensor from mindspore import ops from mindspore.common.dtype import pytype_to_dtype from mindspore.common.api import _MindSporeFunction @@ -316,6 +317,11 @@ def get_dataclass_methods(cls): return methods +def convert_to_ms_tensor(data): + """Convert C++ tensor to mindspore tensor.""" + return MsTensor(data) + + class Parser: """ Parser python code to ast tree. diff --git a/mindspore/ccsrc/CMakeLists.txt b/mindspore/ccsrc/CMakeLists.txt index 41d2c7e726..cd18ff2169 100644 --- a/mindspore/ccsrc/CMakeLists.txt +++ b/mindspore/ccsrc/CMakeLists.txt @@ -130,7 +130,7 @@ set(SUB_COMP frontend/operator pipeline/jit pipeline/pynative - common debug gvar pybind_api utils vm + common debug pybind_api utils vm ) foreach (_comp ${SUB_COMP}) @@ -141,32 +141,21 @@ foreach (_comp ${SUB_COMP}) add_dependencies(_mindspore_${sub}_obj proto_input ) endif () endforeach () -add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/base base) -list(APPEND SUB_OBJECTS_SRC $) -add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/abstract abstract) -list(APPEND SUB_OBJECTS_SRC $) -add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/utils util) -list(APPEND SUB_OBJECTS_SRC $) -add_subdirectory(${CMAKE_SOURCE_DIR}/mindspore/core/ir ir) -list(APPEND SUB_OBJECTS_SRC $) -add_dependencies(_mindspore_core_utils_obj _mindspore_base_obj _mindspore_ir_obj _mindspore_abstract_obj proto_input ) set_property(SOURCE ${SUB_OBJECTS_SRC} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ME) add_library(mindspore STATIC ${SUB_OBJECTS_SRC}) target_link_libraries(proto_input mindspore::protobuf) +target_link_libraries(mindspore mindspore_core) + if (ENABLE_DEBUGGER) # debugger: link grpc target_link_libraries(proto_input mindspore::grpc++) endif() target_link_libraries(mindspore proto_input) -if (ENABLE_MPI AND ENABLE_CPU) - target_link_libraries(mindspore securec mindspore::flatbuffers mpi_adapter) -else () - target_link_libraries(mindspore securec mindspore::flatbuffers) -endif () +target_link_libraries(mindspore securec mindspore::flatbuffers) if (NOT WIN32) target_link_libraries(mindspore dl) @@ -242,7 +231,6 @@ set_target_properties(_c_expression PROPERTIES INSTALL_RPATH ${ORIGIN_PATH}) if (CMAKE_SYSTEM_NAME MATCHES "Windows") target_link_libraries(mindspore mindspore::pybind11_module) - target_link_libraries(mindspore mindspore_gvar) target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore -Wl,--no-whole-archive) else () if (ENABLE_CPU AND (ENABLE_D OR ENABLE_GPU)) @@ -253,7 +241,6 @@ else () endif() target_link_libraries(_c_expression PRIVATE -Wl,--whole-archive mindspore -Wl,--no-whole-archive) target_link_libraries(_c_expression PRIVATE mindspore::pybind11_module) - target_link_libraries(_c_expression PRIVATE mindspore_gvar) endif () if (USE_GLOG) @@ -297,7 +284,7 @@ add_library(inference SHARED ${LOAD_ONNX_SRC} ) target_link_libraries(inference PRIVATE ${PYTHON_LIBRARIES} ${SECUREC_LIBRARY} - -Wl,--whole-archive mindspore -Wl,--no-whole-archive mindspore_gvar mindspore::protobuf) + -Wl,--whole-archive mindspore -Wl,--no-whole-archive mindspore::protobuf) if (ENABLE_CPU) target_link_libraries(inference PRIVATE mindspore::dnnl mindspore::mkldnn) diff --git a/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_build.h b/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_build.h index 41073007bc..6b70cfad81 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_build.h +++ b/mindspore/ccsrc/backend/kernel_compiler/akg/akg_kernel_build.h @@ -25,6 +25,7 @@ #include "backend/kernel_compiler/kernel.h" #include "ir/dtype.h" #include "ir/primitive.h" +#include "pybind11/pybind11.h" #include #include "backend/kernel_compiler/common_utils.h" #include "backend/kernel_compiler/oplib/oplib.h" diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/allgather_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/allgather_cpu_kernel.cc index 55afecb8fa..514cbcdea5 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/allgather_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/allgather_cpu_kernel.cc @@ -15,7 +15,7 @@ */ #include "backend/kernel_compiler/cpu/allgather_cpu_kernel.h" #include "runtime/device/cpu/cpu_device_address.h" -#include "runtime/device/cpu/mpi/mpi_adapter.h" +#include "runtime/device/cpu/mpi/mpi_interface.h" #include "utils/log_adapter.h" namespace mindspore { @@ -45,9 +45,7 @@ bool AllGatherCPUKernel::Launch(const std::vector &inputs, auto input_addr = reinterpret_cast(inputs[0]->addr); auto output_addr = reinterpret_cast(outputs[0]->addr); auto input_data_num = inputs[0]->size / sizeof(float); - auto mpi_instance = device::cpu::MPIAdapter::Instance(); - MS_EXCEPTION_IF_NULL(mpi_instance); - return mpi_instance->AllGather(input_addr, output_addr, ranks_group_, input_data_num); + return MPIAllGather(input_addr, output_addr, ranks_group_, input_data_num); } } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc index 1bcc36faa4..b28dce775c 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.cc @@ -16,7 +16,7 @@ #include #include "backend/kernel_compiler/cpu/embedding_look_up_comm_grad_cpu_kernel.h" #include "runtime/device/cpu/cpu_device_address.h" -#include "runtime/device/cpu/mpi/mpi_adapter.h" +#include "runtime/device/cpu/mpi/mpi_interface.h" namespace mindspore { namespace kernel { @@ -49,11 +49,8 @@ bool EmbeddingLookUpCommGradCPUKernel::Launch(const std::vector &rank_group = {0, 1, 2, 3, 4, 5, 6, 7}; size_t input_split_lens = input_size / split_num_ / sizeof(float_t); size_t output_split_lens = output_size / split_num_ / sizeof(float_t); - auto mpi_instance = device::cpu::MPIAdapter::Instance(); - MS_EXCEPTION_IF_NULL(mpi_instance); for (int i = 0; i < split_num_; i++) { - mpi_instance->AllGather(input_addr + i * input_split_lens, output_addr + i * output_split_lens, rank_group, - input_split_lens); + MPIAllGather(input_addr + i * input_split_lens, output_addr + i * output_split_lens, rank_group, input_split_lens); } #if defined(_WIN32) || defined(_WIN64) auto end_time = std::chrono::steady_clock::now(); diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_scatter_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_scatter_cpu_kernel.cc index f44c109ace..cdbab165d2 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_scatter_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/reduce_scatter_cpu_kernel.cc @@ -15,7 +15,7 @@ */ #include "backend/kernel_compiler/cpu/reduce_scatter_cpu_kernel.h" #include "runtime/device/cpu/cpu_device_address.h" -#include "runtime/device/cpu/mpi/mpi_adapter.h" +#include "runtime/device/cpu/mpi/mpi_interface.h" #include "ir/primitive.h" namespace mindspore { @@ -24,7 +24,7 @@ namespace { constexpr auto kRanksGroup = "group"; } // namespace -ReduceScatterCPUKernel::ReduceScatterCPUKernel() : op_type_(device::cpu::kOpTypeSum) {} +ReduceScatterCPUKernel::ReduceScatterCPUKernel() : op_type_(kMPIOpTypeSum) {} void ReduceScatterCPUKernel::InitKernel(const CNodePtr &kernel_node) { auto op = AnfAlgo::GetCNodePrimitive(kernel_node)->GetAttr("op"); @@ -46,9 +46,7 @@ bool ReduceScatterCPUKernel::Launch(const std::vector &input auto input_addr = reinterpret_cast(inputs[0]->addr); auto output_addr = reinterpret_cast(outputs[0]->addr); auto output_data_num = outputs[0]->size / sizeof(float); - auto mpi_instance = device::cpu::MPIAdapter::Instance(); - MS_EXCEPTION_IF_NULL(mpi_instance); - return mpi_instance->ReduceScatter(input_addr, output_addr, ranks_group_, output_data_num, op_type_); + return MPIReduceScatter(input_addr, output_addr, ranks_group_, output_data_num, op_type_); } } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/backend/kernel_compiler/cpu/sub_cpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/cpu/sub_cpu_kernel.cc index 1e759390a2..f99c53d577 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/cpu/sub_cpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/cpu/sub_cpu_kernel.cc @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include "backend/kernel_compiler/cpu/sub_cpu_kernel.h" +#include +#include #include "runtime/device/cpu/cpu_device_address.h" namespace mindspore { diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h index 0f32519959..8a273965ea 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/array_reduce_gpu_kernel.h @@ -182,30 +182,59 @@ class ArrayReduceGpuKernel : public GpuKernel { void InferInAndOutDesc(const std::vector &input_shape, const std::vector &output_shape) { std::vector inputA; std::vector outputC_shape = output_shape; - ShapeNdTo4d(input_shape, &inputA); - CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(inputA_descriptor_, CUDNN_TENSOR_NCHW, data_type_, inputA[0], - inputA[1], inputA[2], inputA[3]), - "cudnnSetTensor4dDescriptor failed"); + const int split_dim = 4; + + if (input_shape.size() <= split_dim) { + ShapeNdTo4d(input_shape, &inputA); + CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(inputA_descriptor_, CUDNN_TENSOR_NCHW, data_type_, + inputA[0], inputA[1], inputA[2], inputA[3]), + "cudnnSetTensor4dDescriptor failed"); + } else { + CudnnSetTensorNdDescriptor(input_shape, inputA_descriptor_, data_type_); + for (auto dim : input_shape) { + inputA.emplace_back(SizeToInt(dim)); + } + } if (axis_[0] == -1) { - CHECK_CUDNN_RET_WITH_EXCEPT( - cudnnSetTensor4dDescriptor(outputC_descriptor_, CUDNN_TENSOR_NCHW, data_type_, 1, 1, 1, 1), - "cudnnSetTensor4dDescriptor failed"); - if (inputA[0] == 1 && inputA[1] == 1 && inputA[2] == 1 && inputA[3] == 1) { - all_match_ = true; + outputC_shape.resize(input_shape.size(), 1); + if (outputC_shape.size() <= split_dim) { + CHECK_CUDNN_RET_WITH_EXCEPT( + cudnnSetTensor4dDescriptor(outputC_descriptor_, CUDNN_TENSOR_NCHW, data_type_, 1, 1, 1, 1), + "cudnnSetTensor4dDescriptor failed"); + } else { + CudnnSetTensorNdDescriptor(outputC_shape, outputC_descriptor_, data_type_); } + + for (auto dim : inputA) { + if (dim != 1) { + return; + } + } + + all_match_ = true; return; } + + std::vector outputC; if (!keep_dims_) { for (auto i : axis_) { (void)(outputC_shape.insert(outputC_shape.begin() + i, 1)); } } - std::vector outputC; - ShapeNdTo4d(outputC_shape, &outputC); - CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(outputC_descriptor_, CUDNN_TENSOR_NCHW, data_type_, - outputC[0], outputC[1], outputC[2], outputC[3]), - "cudnnSetTensor4dDescriptor failed"); + + if (outputC_shape.size() <= split_dim) { + ShapeNdTo4d(outputC_shape, &outputC); + CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(outputC_descriptor_, CUDNN_TENSOR_NCHW, data_type_, + outputC[0], outputC[1], outputC[2], outputC[3]), + "cudnnSetTensor4dDescriptor failed"); + } else { + CudnnSetTensorNdDescriptor(outputC_shape, outputC_descriptor_, data_type_); + for (auto dim : outputC_shape) { + outputC.emplace_back(SizeToInt(dim)); + } + } + if (inputA == outputC) { all_match_ = true; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h index 7cc0d1f858..9bd4d1f186 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/arrays/scatter_nd_gpu_kernel.h @@ -69,6 +69,10 @@ class ScatterNdGpuFwdKernel : public GpuKernel { memcpy_flag_ = true; } + CHECK_CUDA_RET_WITH_EXCEPT( + cudaMemsetAsync(output, static_cast(0.0), output_size_, reinterpret_cast(stream_ptr)), + "cudaMemSet failed in ScatterNdGpuFwdKernel::Launch."); + const size_t input_size = input_size_ / sizeof(T); const size_t output_size = output_size_ / sizeof(T); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cu b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cu index 827bec11f9..040f57c2bf 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cu +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cu @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include "backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cuh" #include "runtime/device/gpu/cuda_common.h" @@ -54,6 +55,11 @@ struct RealDivFunc { __device__ __forceinline__ S operator()(const T &lhs, const T &rhs) { return (lhs / rhs); } }; +template +struct DivFunc { + __device__ __forceinline__ S operator()(const T &lhs, const T &rhs) { return (lhs / rhs); } +}; + template struct MulFunc { __device__ __forceinline__ S operator()(const T &lhs, const T &rhs) { return (lhs * rhs); } @@ -77,7 +83,7 @@ struct FloorDivFunc { template <> struct FloorDivFunc { __device__ __forceinline__ half operator()(const half &lhs, const half &rhs) { - return __float2half(floor(__half2float(lhs)/ __half2float(rhs))); + return __float2half(floor(__half2float(lhs) / __half2float(rhs))); } }; @@ -95,7 +101,6 @@ struct AbsGradFunc { } }; - template <> struct PowerFunc { // invalid branch @@ -104,72 +109,100 @@ struct PowerFunc { __device__ __forceinline__ int Index(const int &index, const int &dim) { return dim == 1 ? 0 : index; } - template __device__ __forceinline__ void BroadcastOperator(const int &l0, const int &l1, const int &l2, const int &l3, - const int &r0, const int &r1, const int &r2, const int &r3, - const int &d0, const int &d1, const int &d2, const int &d3, - const T *input0, const T *input1, S *output) { - for (size_t pos = blockIdx.x * blockDim.x + threadIdx.x; pos < d0 * d1 * d2 * d3; pos += blockDim.x * gridDim.x) { - int i = pos / (d1 * d2 * d3) % d0; - int j = pos / (d2 * d3) % d1; - int k = pos / d3 % d2; - int l = pos % d3; + const int &l4, const int &l5, const int &l6, const int &r0, + const int &r1, const int &r2, const int &r3, const int &r4, + const int &r5, const int &r6, const int &d0, const int &d1, + const int &d2, const int &d3, const int &d4, const int &d5, + const int &d6, const T *input0, const T *input1, S *output) { + for (size_t pos = blockIdx.x * blockDim.x + threadIdx.x; pos < d0 * d1 * d2 * d3 * d4 * d5 * d6; + pos += blockDim.x * gridDim.x) { + int i = pos / (d1 * d2 * d3 * d4 * d5 * d6) % d0; + int j = pos / (d2 * d3 * d4 * d5 * d6) % d1; + int k = pos / (d3 * d4 * d5 * d6) % d2; + int l = pos / (d4 * d5 * d6) % d3; + int m = pos / (d5 * d6) % d4; + int n = pos / d6 % d5; + int o = pos % d6; - int l_index = Index(i, l0) * l1 * l2 * l3 + Index(j, l1) * l2 * l3 + Index(k, l2) * l3 + Index(l, l3); - int r_index = Index(i, r0) * r1 * r2 * r3 + Index(j, r1) * r2 * r3 + Index(k, r2) * r3 + Index(l, r3); + int l_index = Index(i, l0) * l1 * l2 * l3 * l4 * l5 * l6; + l_index += Index(j, l1) * l2 * l3 * l4 * l5 * l6; + l_index += Index(k, l2) * l3 * l4 * l5 * l6; + l_index += Index(l, l3) * l4 * l5 * l6; + l_index += Index(m, l4) * l5 * l6; + l_index += Index(n, l5) * l6; + l_index += Index(o, l6); + int r_index = Index(i, r0) * r1 * r2 * r3 * r4 * r5 * r6; + r_index += Index(j, r1) * r2 * r3 * r4 * r5 * r6; + r_index += Index(k, r2) * r3 * r4 * r5 * r6; + r_index += Index(l, r3) * r4 * r5 * r6; + r_index += Index(m, r4) * r5 * r6; + r_index += Index(n, r5) * r6; + r_index += Index(o, r6); output[pos] = Func()(input0[l_index], input1[r_index]); } } template -__global__ void BroadcastKernel(const int l0, const int l1, const int l2, const int l3, const int r0, const int r1, - const int r2, const int r3, const int d0, const int d1, const int d2, const int d3, - enum BroadcastOpType op, const T *input0, const T *input1, S *output) { +__global__ void BroadcastKernel(const int l0, const int l1, const int l2, const int l3, const int l4, const int l5, + const int l6, const int r0, const int r1, const int r2, const int r3, const int r4, + const int r5, const int r6, const int d0, const int d1, const int d2, const int d3, + const int d4, const int d5, const int d6, enum BroadcastOpType op, const T *input0, + const T *input1, S *output) { switch (op) { case BROADCAST_TYPE_GREATER: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, + d2, d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_LESS: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, d2, + d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_MINIMUM: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, + d2, d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_MAXIMUM: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, + d2, d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_POWER: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, + d2, d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_REALDIV: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, + d2, d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_MUL: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, d2, + d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_SUB: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, d2, + d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_ADD: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, d2, + d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_FLOORDIV: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, + d2, d3, d4, d5, d6, input0, input1, output); case BROADCAST_TYPE_ABSGRAD: - return BroadcastOperator>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, input0, input1, - output); + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, + d2, d3, d4, d5, d6, input0, input1, output); + case BROADCAST_TYPE_DIV: + return BroadcastOperator>(l0, l1, l2, l3, l4, l5, l6, r0, r1, r2, r3, r4, r5, r6, d0, d1, d2, + d3, d4, d5, d6, input0, input1, output); } } template -void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, const int &r2, - const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, enum BroadcastOpType op, - const T *input0, const T *input1, S *output, cudaStream_t stream) { - int size = d0 * d1 * d2 * d3; - BroadcastKernel<<>>(l0, l1, l2, l3, r0, r1, r2, r3, d0, d1, d2, d3, op, - input0, input1, output); +void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const T *input0, const T *input1, + S *output, cudaStream_t stream) { + int size = 1; + for (auto d : output_shape) { + size *= d; + } + BroadcastKernel<<>>( + lhs_shape[0], lhs_shape[1], lhs_shape[2], lhs_shape[3], lhs_shape[4], lhs_shape[5], lhs_shape[6], rhs_shape[0], + rhs_shape[1], rhs_shape[2], rhs_shape[3], rhs_shape[4], rhs_shape[5], rhs_shape[6], output_shape[0], + output_shape[1], output_shape[2], output_shape[3], output_shape[4], output_shape[5], output_shape[6], op, input0, + input1, output); } template @@ -205,6 +238,8 @@ __global__ void NoBroadcastKernel(const int nums, enum BroadcastOpType op, const return NoBroadcastOperator>(nums, input0, input1, output); case BROADCAST_TYPE_ABSGRAD: return NoBroadcastOperator>(nums, input0, input1, output); + case BROADCAST_TYPE_DIV: + return NoBroadcastOperator>(nums, input0, input1, output); } } @@ -215,8 +250,8 @@ void NoBroadcast(const int &nums, enum BroadcastOpType op, const T *input0, cons } template -__global__ void BroadcastToKernel(const int i0, const int i1, const int i2, const int i3, const int o0, - const int o1, const int o2, const int o3, const T *input_addr, T *output_addr) { +__global__ void BroadcastToKernel(const int i0, const int i1, const int i2, const int i3, const int o0, const int o1, + const int o2, const int o3, const T *input_addr, T *output_addr) { for (size_t pos = blockIdx.x * blockDim.x + threadIdx.x; pos < o0 * o1 * o2 * o3; pos += blockDim.x * gridDim.x) { int i = pos / (o1 * o2 * o3) % o0; int j = pos / (o2 * o3) % o1; @@ -233,33 +268,27 @@ void BroadcastTo(const int &i0, const int &i1, const int &i2, const int &i3, con const int &o2, const int &o3, const T *input_addr, T *output_addr, cudaStream_t stream) { int nums = o0 * o1 * o2 * o3; BroadcastToKernel<<>>(i0, i1, i2, i3, o0, o1, o2, o3, input_addr, - output_addr); + output_addr); } -template void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, - const int &r2, const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, - enum BroadcastOpType op, const float *input0, const float *input1, bool *output, - cudaStream_t stream); -template void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, - const int &r2, const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, - enum BroadcastOpType op, const float *input0, const float *input1, float *output, - cudaStream_t stream); -template void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, - const int &r2, const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, - enum BroadcastOpType op, const half *input0, const half *input1, bool *output, - cudaStream_t stream); -template void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, - const int &r2, const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, - enum BroadcastOpType op, const half *input0, const half *input1, half *output, - cudaStream_t stream); -template void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, - const int &r2, const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, - enum BroadcastOpType op, const int *input0, const int *input1, int *output, - cudaStream_t stream); -template void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, - const int &r2, const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, - enum BroadcastOpType op, const int *input0, const int *input1, bool *output, - cudaStream_t stream); +template void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const float *input0, + const float *input1, bool *output, cudaStream_t stream); +template void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const float *input0, + const float *input1, float *output, cudaStream_t stream); +template void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const half *input0, + const half *input1, bool *output, cudaStream_t stream); +template void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const half *input0, + const half *input1, half *output, cudaStream_t stream); +template void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const int *input0, + const int *input1, int *output, cudaStream_t stream); +template void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const int *input0, + const int *input1, bool *output, cudaStream_t stream); template void NoBroadcast(const int &nums, enum BroadcastOpType op, const float *input0, const float *input1, bool *output, cudaStream_t stream); template void NoBroadcast(const int &nums, enum BroadcastOpType op, const float *input0, const float *input1, @@ -268,10 +297,10 @@ template void NoBroadcast(const int &nums, enum BroadcastOpType op, const half * bool *output, cudaStream_t stream); template void NoBroadcast(const int &nums, enum BroadcastOpType op, const half *input0, const half *input1, half *output, cudaStream_t stream); -template void NoBroadcast(const int &nums, enum BroadcastOpType op, const int *input0, const int *input1, - int *output, cudaStream_t stream); -template void NoBroadcast(const int &nums, enum BroadcastOpType op, const int *input0, const int *input1, - bool *output, cudaStream_t stream); +template void NoBroadcast(const int &nums, enum BroadcastOpType op, const int *input0, const int *input1, int *output, + cudaStream_t stream); +template void NoBroadcast(const int &nums, enum BroadcastOpType op, const int *input0, const int *input1, bool *output, + cudaStream_t stream); template void BroadcastTo(const int &i0, const int &i1, const int &i2, const int &i3, const int &o0, const int &o1, const int &o2, const int &o3, const float *input_addr, float *output_addr, cudaStream_t stream); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cuh b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cuh index 7d762c34d9..c00c12cadb 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cuh +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/broadcast_impl.cuh @@ -17,6 +17,7 @@ #ifndef MINDSPORE_CCSRC_KERNEL_GPU_CUDA_IMPL_BROADCAST_H_ #define MINDSPORE_CCSRC_KERNEL_GPU_CUDA_IMPL_BROADCAST_H_ +#include #include "runtime/device/gpu/cuda_common.h" enum BroadcastOpType { @@ -31,13 +32,14 @@ enum BroadcastOpType { BROADCAST_TYPE_ADD = 8, BROADCAST_TYPE_FLOORDIV = 9, BROADCAST_TYPE_ABSGRAD = 10, + BROADCAST_TYPE_DIV = 11, BROADCAST_TYPE_INVALID = 0xffffffff, }; template -void Broadcast(const int &l0, const int &l1, const int &l2, const int &l3, const int &r0, const int &r1, const int &r2, - const int &r3, const int &d0, const int &d1, const int &d2, const int &d3, enum BroadcastOpType op, - const T *input0, const T *input1, S *output, cudaStream_t stream); +void Broadcast(const std::vector &lhs_shape, const std::vector &rhs_shape, + const std::vector &output_shape, enum BroadcastOpType op, const T *input0, const T *input1, + S *output, cudaStream_t stream); template void NoBroadcast(const int &size, enum BroadcastOpType op, const T *input0, const T *input1, S *output, diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/check_valid_impl.cu b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/check_valid_impl.cu index 588f8c60e2..b45d2749a3 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/check_valid_impl.cu +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/check_valid_impl.cu @@ -25,10 +25,10 @@ __global__ void CheckValidKernel(const size_t size, const T *box, const T *img_m const size_t right_y = i * 4 + 3; S valid_flag = false; - valid_flag |= !(box[left_x] >= 0.f); - valid_flag |= !(box[left_y] >= 0.f); - valid_flag |= !(img_metas[0] * img_metas[2] - 1.f >= box[right_x]); - valid_flag |= !(img_metas[1] * img_metas[2] - 1.f >= box[right_y]); + valid_flag |= !(box[left_x] >= static_cast(0.0)); + valid_flag |= !(box[left_y] >= static_cast(0.0)); + valid_flag |= !(img_metas[1] * img_metas[2] - static_cast(1.0) >= box[right_x]); + valid_flag |= !(img_metas[0] * img_metas[2] - static_cast(1.0) >= box[right_y]); valid[i] = !valid_flag; } @@ -43,3 +43,5 @@ void CheckValid(const size_t &size, const T *box, const T *img_metas, S *valid, template void CheckValid(const size_t &size, const float *box, const float *img_metas, bool *valid, cudaStream_t cuda_stream); +template void CheckValid(const size_t &size, const half *box, const half *img_metas, bool *valid, + cudaStream_t cuda_stream); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cu b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cu index dfc62147b7..30622c60e9 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cu +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cu @@ -18,12 +18,85 @@ #include "runtime/device/gpu/cuda_common.h" template -__global__ void CumSumKernel(T *input, T *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, +__global__ void Copy(T *input, T *output, size_t size) { + size_t step = blockDim.x * gridDim.x; + for (size_t write_index = blockIdx.x * blockDim.x + threadIdx.x; write_index < size; write_index += step) { + input[write_index] = output[write_index]; + } +} + +template +__global__ void LeftMove(const T *input, T *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, + size_t stride2) { + size_t num = dim0 * dim2; + size_t i, k, offset; + size_t step = blockDim.x * gridDim.x; + for (size_t write_index = blockIdx.x * blockDim.x + threadIdx.x; write_index < num; write_index += step) { + i = write_index / dim2 % dim0; + k = write_index % dim2; + offset = i * stride + k; + for (size_t j = 0; j < dim1; ++j) { + size_t read_index = j * stride2 + offset; + if (j == 0) { + output[read_index] = 0; + } else { + size_t read_index2 = (j - 1) * stride2 + offset; + output[read_index] = input[read_index2]; + } + } + } +} + +template +__global__ void RightMove(const T *input, T *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, + size_t stride2) { + size_t num = dim0 * dim2; + size_t i, k, offset; + size_t step = blockDim.x * gridDim.x; + for (size_t write_index = blockIdx.x * blockDim.x + threadIdx.x; write_index < num; write_index += step) { + i = write_index / dim2 % dim0; + k = write_index % dim2; + offset = i * stride + k; + for (int j = dim1 - 1; j >= 0; --j) { + size_t read_index = j * stride2 + offset; + if (j == dim1 - 1) { + output[read_index] = 0; + } else { + size_t read_index2 = (j + 1) * stride2 + offset; + output[read_index] = input[read_index2]; + } + } + } +} +template +__global__ void CumSumKernelReverse(const T *input, T *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, + size_t stride2) { + size_t num = dim0 * dim2; + size_t i, k, offset; + size_t step = blockDim.x * gridDim.x; + for (size_t write_index = blockIdx.x * blockDim.x + threadIdx.x; write_index < num; write_index += step) { + i = write_index / dim2 % dim0; + k = write_index % dim2; + offset = i * stride + k; + for (int j = dim1 - 1; j >= 0; --j) { + size_t read_index = j * stride2 + offset; + if (j == dim1 - 1) { + output[read_index] = input[read_index]; + } else { + size_t read_index2 = (j + 1) * stride2 + offset; + output[read_index] = output[read_index2] + input[read_index]; + } + } + } +} + +template +__global__ void CumSumKernel(const T *input, T *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, size_t stride2) { size_t num = dim0 * dim2; size_t i, k, offset; - for (size_t write_index = blockIdx.x * blockDim.x + threadIdx.x; write_index < num; - write_index += blockDim.x * gridDim.x) { + size_t step = blockDim.x * gridDim.x; + for (size_t write_index = blockIdx.x * blockDim.x + threadIdx.x; write_index < num; write_index += step) { i = write_index / dim2 % dim0; k = write_index % dim2; offset = i * stride + k; @@ -39,12 +112,32 @@ __global__ void CumSumKernel(T *input, T *output, size_t dim0, size_t dim1, size } } template -void CumSum(T *input, T *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, size_t stride2, - cudaStream_t stream) { +void CumSum(const T *input, T *output, T *workspace, size_t dim0, size_t dim1, size_t dim2, size_t stride, + size_t stride2, bool exclusive_, bool reverse_, cudaStream_t stream) { int size = dim0 * dim2; - CumSumKernel<<>>(input, output, dim0, dim1, dim2, stride, stride2); + if (exclusive_) { + if (reverse_) { + RightMove<<>>(input, output, dim0, dim1, dim2, stride, stride2); + Copy<<>>(workspace, output, size * dim1); + CumSumKernelReverse<<>>(workspace, output, dim0, dim1, dim2, stride, + stride2); + } else { + LeftMove<<>>(input, output, dim0, dim1, dim2, stride, stride2); + Copy<<>>(workspace, output, size * dim1); + CumSumKernel<<>>(workspace, output, dim0, dim1, dim2, stride, stride2); + } + } else { + if (reverse_) { + CumSumKernelReverse<<>>(input, output, dim0, dim1, dim2, stride, + stride2); + } else { + CumSumKernel<<>>(input, output, dim0, dim1, dim2, stride, stride2); + } + } return; } -template void CumSum(float *input, float *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, - size_t stride2, cudaStream_t stream); +template void CumSum(const float *input, float *output, float *workspace, size_t dim0, size_t dim1, size_t dim2, + size_t stride, size_t stride2, bool exclusive_, bool reverse_, cudaStream_t stream); +template void CumSum(const half *input, half *output, half *workspace, size_t dim0, size_t dim1, size_t dim2, + size_t stride, size_t stride2, bool exclusive_, bool reverse_, cudaStream_t stream); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cuh b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cuh index 85ca551643..7e3c40c99e 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cuh +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/cumsum_impl.cuh @@ -17,6 +17,6 @@ #ifndef MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_CUMSUM_IMPL_CUH_ #define MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_CUMSUM_IMPL_CUH_ template -void CumSum(T *input, T *output, size_t dim0, size_t dim1, size_t dim2, size_t stride, size_t stride2, - cudaStream_t stream); +void CumSum(const T *input, T *output, T *workspace, size_t dim0, size_t dim1, size_t dim2, size_t stride, + size_t stride2, bool exclusive_, bool reverse_, cudaStream_t stream); #endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_GPU_CUMSUM_IMPL_CUH_ diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/iou_impl.cu b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/iou_impl.cu index a3cdd7e131..3b785e2655 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/iou_impl.cu +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/cuda_impl/iou_impl.cu @@ -16,27 +16,26 @@ #include "backend/kernel_compiler/gpu/cuda_impl/iou_impl.cuh" -template -__device__ T CoordinateMax(const T a, const T b) { +__device__ float CoordinateMax(const float a, const float b) { return (a > b ? a : b); } -template -__device__ T CoordinateMin(const T a, const T b) { +__device__ float CoordinateMin(const float a, const float b) { return (a < b ? a : b); } template __global__ void IOUKernel(const size_t size, const T *box1, const T *box2, T *iou_results, const size_t mode, const size_t input_len_0) { - T location_coordinate[IOU_LOCATION_NUM][IOU_DIMENSION]; - T overlaps_coordinate[IOU_DIMENSION]; - const T epsilon = 1e-10; + float location_coordinate[IOU_LOCATION_NUM][IOU_DIMENSION]; + float overlaps_coordinate[IOU_DIMENSION]; + const float epsilon = 1e-10; + const float offset = 1.0; for (size_t i = blockIdx.x * blockDim.x + threadIdx.x; i < size; i += gridDim.x * blockDim.x) { for (size_t j = 0; j < IOU_DIMENSION; j++) { - location_coordinate[0][j] = box1[(i % input_len_0) * IOU_DIMENSION + j]; - location_coordinate[1][j] = box2[(i / input_len_0) * IOU_DIMENSION + j]; + location_coordinate[0][j] = static_cast(box1[(i % input_len_0) * IOU_DIMENSION + j]); + location_coordinate[1][j] = static_cast(box2[(i / input_len_0) * IOU_DIMENSION + j]); } overlaps_coordinate[0] = CoordinateMax(location_coordinate[0][0], location_coordinate[1][0]); @@ -44,18 +43,18 @@ __global__ void IOUKernel(const size_t size, const T *box1, const T *box2, T *io overlaps_coordinate[2] = CoordinateMin(location_coordinate[0][2], location_coordinate[1][2]); overlaps_coordinate[3] = CoordinateMin(location_coordinate[0][3], location_coordinate[1][3]); - T overlaps_w = CoordinateMax(0.f, overlaps_coordinate[2] - overlaps_coordinate[0] + 1); - T overlaps_h = CoordinateMax(0.f, overlaps_coordinate[3] - overlaps_coordinate[1] + 1); - T overlaps = overlaps_w * overlaps_h; + float overlaps_w = CoordinateMax(0.0, overlaps_coordinate[2] - overlaps_coordinate[0] + offset); + float overlaps_h = CoordinateMax(0.0, overlaps_coordinate[3] - overlaps_coordinate[1] + offset); + float overlaps = overlaps_w * overlaps_h; - T area1 = (location_coordinate[0][2] - location_coordinate[0][0] + 1) * (location_coordinate[0][3] - - location_coordinate[0][1] + 1); - T area2 = (location_coordinate[1][2] - location_coordinate[1][0] + 1) * (location_coordinate[1][3] - - location_coordinate[1][1] + 1); + float area1 = (location_coordinate[0][2] - location_coordinate[0][0] + offset) * (location_coordinate[0][3] - + location_coordinate[0][1] + offset); + float area2 = (location_coordinate[1][2] - location_coordinate[1][0] + offset) * (location_coordinate[1][3] - + location_coordinate[1][1] + offset); if (mode == 0) { - iou_results[i] = overlaps / (area1 + area2 - overlaps + epsilon); + iou_results[i] = static_cast(overlaps / (area1 + area2 - overlaps + epsilon)); } else { - iou_results[i] = overlaps / (area2 + epsilon); + iou_results[i] = static_cast(overlaps / (area2 + epsilon)); } } @@ -70,3 +69,5 @@ void IOU(const size_t &size, const T *box1, const T *box2, T *iou_results, const template void IOU(const size_t &size, const float *box1, const float *box2, float *iou_results, const size_t &mode, const size_t &input_len_0, cudaStream_t cuda_stream); +template void IOU(const size_t &size, const half *box1, const half *box2, half *iou_results, const size_t &mode, + const size_t &input_len_0, cudaStream_t cuda_stream); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/gpu_kernel.h index a6a25096fb..9ee6ead1cb 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/gpu_kernel.h @@ -84,6 +84,40 @@ class GpuKernel : public KernelMod { } } + // set the tensor descriptor for cudnn/cublas + void CudnnSetTensorNdDescriptor(const std::vector &shape, cudnnTensorDescriptor_t descriptor, + cudnnDataType_t data_type) { + if (shape.size() < 3) { + MS_EXCEPTION(ValueError) << "cudnnSetTensorNdDescriptor don't support" << shape.size() << "D."; + } + const int nbDims = shape.size(); + int *dim = new (std::nothrow) int[nbDims]; + if (dim == nullptr) { + MS_LOG(EXCEPTION) << "malloc dim failed."; + } + int *stride = new (std::nothrow) int[nbDims]; + if (stride == nullptr) { + MS_LOG(EXCEPTION) << "malloc stride failed."; + } + + for (int i = 0; i < nbDims; i++) { + dim[i] = SizeToInt(shape[i]); + stride[i] = 1; + } + + for (int i = nbDims - 2; i >= 0; i--) { + stride[i] = stride[i + 1] * SizeToInt(shape[i + 1]); + } + + CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensorNdDescriptor(descriptor, data_type, nbDims, dim, stride), + "cudnnSetTensorNdDescriptor failed"); + + delete[] dim; + dim = nullptr; + delete[] stride; + stride = nullptr; + } + // choose the suitable datatype for cudnn/cublas inline cudnnDataType_t GetCudnnDataType(const std::string &Type) { auto type = kCudnnDtypeMap.find(Type); diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.cc index ccccd767a8..2fcbc9ea6d 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.cc @@ -59,6 +59,9 @@ MS_REG_GPU_KERNEL_TWO( AbsGrad, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), BroadcastOpGpuKernel, float, float) +MS_REG_GPU_KERNEL_TWO( + Div, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), + BroadcastOpGpuKernel, float, float) // fp16 MS_REG_GPU_KERNEL_TWO( @@ -101,6 +104,9 @@ MS_REG_GPU_KERNEL_TWO( AbsGrad, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), BroadcastOpGpuKernel, half, half) +MS_REG_GPU_KERNEL_TWO( + Div, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), + BroadcastOpGpuKernel, half, half) // int32 MS_REG_GPU_KERNEL_TWO( @@ -118,14 +124,14 @@ MS_REG_GPU_KERNEL_TWO( MS_REG_GPU_KERNEL_TWO( Mul, KernelAttr().AddInputAttr(kNumberTypeInt32).AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32), BroadcastOpGpuKernel, int, int) -MS_REG_GPU_KERNEL_TWO( - RealDiv, KernelAttr().AddInputAttr(kNumberTypeInt32).AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32), - BroadcastOpGpuKernel, int, int) MS_REG_GPU_KERNEL_TWO( FloorDiv, KernelAttr().AddInputAttr(kNumberTypeInt32).AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32), BroadcastOpGpuKernel, int, int) MS_REG_GPU_KERNEL_TWO( AbsGrad, KernelAttr().AddInputAttr(kNumberTypeInt32).AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32), BroadcastOpGpuKernel, int, int) +MS_REG_GPU_KERNEL_TWO( + Div, KernelAttr().AddInputAttr(kNumberTypeInt32).AddInputAttr(kNumberTypeInt32).AddOutputAttr(kNumberTypeInt32), + BroadcastOpGpuKernel, int, int) } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.h index b6ac5a3688..5c7927a321 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/broadcast_gpu_kernel.h @@ -27,6 +27,7 @@ #include "backend/kernel_compiler/gpu/kernel_constants.h" namespace mindspore { namespace kernel { +constexpr int MAX_DIMS = 7; template class BroadcastOpGpuKernel : public GpuKernel { public: @@ -45,9 +46,8 @@ class BroadcastOpGpuKernel : public GpuKernel { S *output = GetDeviceAddress(outputs, 0); if (need_broadcast_) { - Broadcast(lhs_shape_[0], lhs_shape_[1], lhs_shape_[2], lhs_shape_[3], rhs_shape_[0], rhs_shape_[1], rhs_shape_[2], - rhs_shape_[3], output_shape_[0], output_shape_[1], output_shape_[2], output_shape_[3], op_type_, lhs, - rhs, output, reinterpret_cast(stream_ptr)); + Broadcast(lhs_shape_, rhs_shape_, output_shape_, op_type_, lhs, rhs, output, + reinterpret_cast(stream_ptr)); } else { NoBroadcast(output_num_, op_type_, lhs, rhs, output, reinterpret_cast(stream_ptr)); } @@ -60,10 +60,13 @@ class BroadcastOpGpuKernel : public GpuKernel { auto shape2 = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 1); auto shape3 = AnfAlgo::GetOutputInferShape(kernel_node, 0); need_broadcast_ = IsBroadcast(shape1, shape2); - if (need_broadcast_ && shape1.size() > 4) { - MS_LOG(EXCEPTION) << "Broadcast operation not support dim greater than 4"; + if (need_broadcast_ && shape1.size() > 7) { + MS_LOG(EXCEPTION) << "Broadcast operation not support dim greater than 7"; } + lhs_shape_.resize(MAX_DIMS, 1); + rhs_shape_.resize(MAX_DIMS, 1); + output_shape_.resize(MAX_DIMS, 1); for (size_t i = 0; i < shape3.size(); i++) { output_shape_[i] = shape3[i]; output_num_ *= shape3[i]; @@ -99,7 +102,7 @@ class BroadcastOpGpuKernel : public GpuKernel { {"Greater", BROADCAST_TYPE_GREATER}, {"Less", BROADCAST_TYPE_LESS}, {"Maximum", BROADCAST_TYPE_MAXIMUM}, {"Minimum", BROADCAST_TYPE_MINIMUM}, {"Pow", BROADCAST_TYPE_POWER}, {"RealDiv", BROADCAST_TYPE_REALDIV}, {"Mul", BROADCAST_TYPE_MUL}, {"Sub", BROADCAST_TYPE_SUB}, {"TensorAdd", BROADCAST_TYPE_ADD}, - {"FloorDiv", BROADCAST_TYPE_FLOORDIV}, {"AbsGrad", BROADCAST_TYPE_ABSGRAD}, + {"FloorDiv", BROADCAST_TYPE_FLOORDIV}, {"AbsGrad", BROADCAST_TYPE_ABSGRAD}, {"Div", BROADCAST_TYPE_DIV}, }; auto iter = kBroadcastTypeMap.find(kernel_name); @@ -127,9 +130,9 @@ class BroadcastOpGpuKernel : public GpuKernel { int input1_num_; int input2_num_; int output_num_; - int lhs_shape_[4] = {1, 1, 1, 1}; - int rhs_shape_[4] = {1, 1, 1, 1}; - int output_shape_[4] = {1, 1, 1, 1}; + std::vector lhs_shape_; + std::vector rhs_shape_; + std::vector output_shape_; std::vector input_size_list_; std::vector output_size_list_; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.cc index deb5e39ff7..e13ec638e8 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.cc @@ -20,5 +20,7 @@ namespace mindspore { namespace kernel { MS_REG_GPU_KERNEL_ONE(CumSum, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), CumSumGpuKernel, float) +MS_REG_GPU_KERNEL_ONE(CumSum, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), + CumSumGpuKernel, half) } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h index 92e9232416..92cac43ce0 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/math/cumsum_gpu_kernel.h @@ -27,7 +27,7 @@ namespace kernel { template class CumSumGpuKernel : public GpuKernel { public: - CumSumGpuKernel() : axis_(0), input_size_0_(0), stride_(0), stride2_(0) {} + CumSumGpuKernel() : exclusive_(false), reverse_(false), axis_(0), input_size_0_(0), stride_(0), stride2_(0) {} ~CumSumGpuKernel() = default; const std::vector &GetInputSizeList() const override { return input_size_list_; } @@ -38,7 +38,8 @@ class CumSumGpuKernel : public GpuKernel { const std::vector &outputs, void *stream_ptr) override { T *input_addr = GetDeviceAddress(inputs, 0); T *output_addr = GetDeviceAddress(outputs, 0); - CumSum(input_addr, output_addr, dims_[0], dims_[1], dims_[2], stride_, stride2_, + T *ws_addr = GetDeviceAddress(workspace, 0); + CumSum(input_addr, output_addr, ws_addr, dims_[0], dims_[1], dims_[2], stride_, stride2_, exclusive_, reverse_, reinterpret_cast(stream_ptr)); return true; } @@ -51,6 +52,8 @@ class CumSumGpuKernel : public GpuKernel { input_size_0_ = sizeof(T); shape_ = AnfAlgo::GetPrevNodeOutputInferShape(kernel_node, 0); axis_ = GetAttr(kernel_node, "axis"); + exclusive_ = GetAttr(kernel_node, "exclusive"); + reverse_ = GetAttr(kernel_node, "reverse"); int input_dim_length = SizeToInt(shape_.size()); if (axis_ >= input_dim_length) { MS_LOG(EXCEPTION) << "Axis out of bounds."; @@ -70,6 +73,7 @@ class CumSumGpuKernel : public GpuKernel { void InitSizeLists() override { input_size_list_.push_back(input_size_0_); output_size_list_.push_back(input_size_0_); + workspace_size_list_.push_back(input_size_0_); } private: @@ -87,6 +91,8 @@ class CumSumGpuKernel : public GpuKernel { stride2_ = dims_[2]; return; } + bool exclusive_; + bool reverse_; int axis_; size_t input_size_0_; size_t stride_; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_gpu_kernel.h index b434ddadd5..01c1079a86 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_gpu_kernel.h @@ -83,12 +83,19 @@ class ActivationGpuFwdKernel : public GpuKernel { return true; } std::vector shape; - ShapeNdTo4d(input_shape, &shape); CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetActivationDescriptor(activation_desc_, mode_, CUDNN_NOT_PROPAGATE_NAN, 0.0), "cudnnSetActivationDescriptor failed"); - CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(data_descriptor_, CUDNN_TENSOR_NCHW, cudnn_data_type_, - shape[0], shape[1], shape[2], shape[3]), - "cudnnSetTensor4dDescriptor failed"); + + const int split_dim = 4; + if (input_shape.size() <= split_dim) { + ShapeNdTo4d(input_shape, &shape); + CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(data_descriptor_, CUDNN_TENSOR_NCHW, cudnn_data_type_, + shape[0], shape[1], shape[2], shape[3]), + "cudnnSetTensor4dDescriptor failed"); + } else { + CudnnSetTensorNdDescriptor(input_shape, data_descriptor_, cudnn_data_type_); + } + InitSizeLists(); return true; } diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_grad_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_grad_kernel.h index 2d7b2012f3..47aadc70af 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_grad_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/activation_grad_kernel.h @@ -90,12 +90,18 @@ class ActivationGradGpuKernel : public GpuKernel { return true; } std::vector shape; - ShapeNdTo4d(input_shape, &shape); CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetActivationDescriptor(activation_desc_, mode_, CUDNN_PROPAGATE_NAN, 0.0), "SetActivationDescriptor failed"); - CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(data_descriptor_, CUDNN_TENSOR_NCHW, cudnn_data_type_, - shape[0], shape[1], shape[2], shape[3]), - "SetTensor4dDescriptor failed"); + + const int split_dim = 4; + if (input_shape.size() <= split_dim) { + ShapeNdTo4d(input_shape, &shape); + CHECK_CUDNN_RET_WITH_EXCEPT(cudnnSetTensor4dDescriptor(data_descriptor_, CUDNN_TENSOR_NCHW, cudnn_data_type_, + shape[0], shape[1], shape[2], shape[3]), + "SetTensor4dDescriptor failed"); + } else { + CudnnSetTensorNdDescriptor(input_shape, data_descriptor_, cudnn_data_type_); + } InitSizeLists(); return true; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/dropout_gpu_kernel.h b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/dropout_gpu_kernel.h index 632caef9ec..1fe3cff151 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/dropout_gpu_kernel.h +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/nn/dropout_gpu_kernel.h @@ -54,12 +54,18 @@ class DropoutGpuFwdKernel : public GpuKernel { float *mask_f = GetDeviceAddress(workspace, 0); if (!states_init_) { - curandCreateGenerator(&mask_generator_, CURAND_RNG_PSEUDO_DEFAULT); - curandSetPseudoRandomGeneratorSeed(mask_generator_, time(NULL)); + CHECK_CURAND_RET_WITH_EXCEPT(curandCreateGenerator(&mask_generator_, CURAND_RNG_PSEUDO_DEFAULT), + "Failed to create generator"); + CHECK_CURAND_RET_WITH_EXCEPT(curandSetPseudoRandomGeneratorSeed(mask_generator_, time(NULL)), + "Failed to SetPseudoRandomGeneratorSeed"); + MS_EXCEPTION_IF_NULL(mask_generator_); states_init_ = true; } + CHECK_CURAND_RET_WITH_EXCEPT(curandSetStream(mask_generator_, reinterpret_cast(stream_ptr)), + "Failed to set stream for generator"); // curandGen only support float or double for mask. - curandGenerateUniform(mask_generator_, mask_f, num_count_); + CHECK_CURAND_RET_WITH_EXCEPT(curandGenerateUniform(mask_generator_, mask_f, num_count_), + "Failed to generate uniform"); DropoutForward(input, mask, output, mask_f, num_count_, keep_prob_, reinterpret_cast(stream_ptr)); return true; diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/check_valid_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/check_valid_gpu_kernel.cc index 208e217e1d..35deb0cd8f 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/check_valid_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/check_valid_gpu_kernel.cc @@ -22,5 +22,9 @@ MS_REG_GPU_KERNEL_TWO( CheckValid, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeBool), CheckValidGpuKernel, float, bool) +MS_REG_GPU_KERNEL_TWO( + CheckValid, + KernelAttr().AddInputAttr(kNumberTypeFloat16).AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeBool), + CheckValidGpuKernel, half, bool) } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/iou_gpu_kernel.cc b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/iou_gpu_kernel.cc index 5d3f0f202b..081d12da3b 100644 --- a/mindspore/ccsrc/backend/kernel_compiler/gpu/other/iou_gpu_kernel.cc +++ b/mindspore/ccsrc/backend/kernel_compiler/gpu/other/iou_gpu_kernel.cc @@ -21,5 +21,8 @@ namespace kernel { MS_REG_GPU_KERNEL_ONE( IOU, KernelAttr().AddInputAttr(kNumberTypeFloat32).AddInputAttr(kNumberTypeFloat32).AddOutputAttr(kNumberTypeFloat32), IOUGpuKernel, float) +MS_REG_GPU_KERNEL_ONE( + IOU, KernelAttr().AddInputAttr(kNumberTypeFloat16).AddInputAttr(kNumberTypeFloat16).AddOutputAttr(kNumberTypeFloat16), + IOUGpuKernel, half) } // namespace kernel } // namespace mindspore diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc b/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc index c1bc8ec638..dcca95fbc0 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ascend_backend_optimization.cc @@ -80,6 +80,7 @@ #include "backend/optimizer/ascend/buffer_fusion/conv_single_in_fusion_pass.h" #include "backend/optimizer/ascend/buffer_fusion/conv_double_in_fusion_pass.h" #include "backend/optimizer/ascend/buffer_fusion/matmul_eltwise_fusion_pass.h" +#include "backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.h" #include "backend/optimizer/ascend/buffer_fusion/depthwiseconv_eltwise_fusion_pass.h" #include "backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h" #include "backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_eltwise_fusion_pass.h" @@ -124,6 +125,10 @@ void AddAscendIRFusionRulesPass(PassManager *ir_fusion_pm) { ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); + ir_fusion_pm->AddPass(std::make_shared()); + ir_fusion_pm->AddPass(std::make_shared()); + ir_fusion_pm->AddPass(std::make_shared()); + ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); @@ -308,6 +313,7 @@ void RunOpAscendBackendIRFusionOptimization(const std::shared_ptr(); auto ir_fusion_pm = std::make_shared("ir_fusion_pm"); + ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc index 74ef83dcf4..017c475eb4 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.cc @@ -27,15 +27,15 @@ namespace mindspore { namespace opt { -void BnupdateEltwiseFusionPass::MatchBnupdateRelu(const CNodePtr &cnode, const AnfNodePtr &relu_input, - const session::KernelGraph &kernel_graph, - FusedNodeRecord *candidate_fusion) { +void BnupdateEltwiseFusionPass::MatchBnupdateDoubleOutputEltwise(const CNodePtr &cnode, const AnfNodePtr &eltwise_input, + const session::KernelGraph &kernel_graph, + FusedNodeRecord *candidate_fusion) { MS_EXCEPTION_IF_NULL(cnode); MS_EXCEPTION_IF_NULL(candidate_fusion); auto manager = kernel_graph.manager(); MS_EXCEPTION_IF_NULL(manager); - MS_EXCEPTION_IF_NULL(relu_input); - auto getitem = relu_input->cast(); + MS_EXCEPTION_IF_NULL(eltwise_input); + auto getitem = eltwise_input->cast(); MS_EXCEPTION_IF_NULL(getitem); auto bnupdate = getitem->input(1); MS_EXCEPTION_IF_NULL(bnupdate); @@ -68,10 +68,11 @@ void BnupdateEltwiseFusionPass::MatchSingleFusionPattern(const session::KernelGr auto cnode = node->cast(); MS_EXCEPTION_IF_NULL(cnode); if (AnfAlgo::GetKernelType(cnode) == KernelType::TBE_KERNEL && - AnfAlgo::GetFusionType(cnode) == kernel::FusionType::ELEMWISE) { + AnfAlgo::GetFusionType(cnode) == kernel::FusionType::ELEMWISE && + AnfAlgo::GetOutputTensorNum(cnode) == ELTWISE_DOUBLE_OUTPUT_SIZE) { auto eltwise_input = cnode->input(1); if (eltwise_input->isa() && AnfAlgo::CheckPrimitiveType(eltwise_input, prim::kPrimTupleGetItem)) { - MatchBnupdateRelu(cnode, eltwise_input, kernel_graph, candidate_fusion); + MatchBnupdateDoubleOutputEltwise(cnode, eltwise_input, kernel_graph, candidate_fusion); } } } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h index 9ca88959de..b9284f424b 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/bnupdate_eltwise_fusion_pass.h @@ -39,8 +39,8 @@ class BnupdateEltwiseFusionPass : public FusionBasePass { void MatchSingleFusionPattern(const session::KernelGraph &kernel_graph, FusedNodeRecord *candidate_fusion) override; private: - void MatchBnupdateRelu(const CNodePtr &cnode, const AnfNodePtr &relu_input, const session::KernelGraph &kernel_graph, - FusedNodeRecord *candidate_fusion); + void MatchBnupdateDoubleOutputEltwise(const CNodePtr &cnode, const AnfNodePtr &eltwise_input, + const session::KernelGraph &kernel_graph, FusedNodeRecord *candidate_fusion); }; } // namespace opt } // namespace mindspore diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h index 024ce416e3..c78e93cd97 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h @@ -33,6 +33,7 @@ const int8_t MAX_ELTWISE_NUM = 3; const int8_t MIN_ELTWISE_SIZE = 2; const int8_t ELTWISE_INPUT_SIZE = 2; const int8_t ELTWISE_DOUBLE_IN_INPUT_SIZE = 3; +const int8_t ELTWISE_DOUBLE_OUTPUT_SIZE = 2; const int8_t CONV_DOUBLE_IN_INPUT_SIZE = 3; const int8_t CONV_QUART_IN_INPUT_SIZE = 5; const int8_t ELTWISE_USE = 1; diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.cc b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.cc new file mode 100644 index 0000000000..d75511d790 --- /dev/null +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.cc @@ -0,0 +1,66 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.h" +#include +#include +#include +#include +#include "backend/kernel_compiler/kernel_fusion.h" +#include "debug/anf_ir_dump.h" +#include "backend/session/anf_runtime_algorithm.h" +#include "frontend/operator/ops.h" +#include "utils/ms_context.h" +#include "backend/optimizer/common/fusion_id_allocator.h" + +namespace mindspore { +namespace opt { +void MatmulConfusionTranposeFusionPass::MatchMatmulConfusionTranpose(const CNodePtr &cnode, + const session::KernelGraph &kernel_graph, + FusedNodeRecord *candidate_fusion) { + MS_EXCEPTION_IF_NULL(cnode); + MS_EXCEPTION_IF_NULL(candidate_fusion); + auto manager = kernel_graph.manager(); + MS_EXCEPTION_IF_NULL(manager); + auto matmul = cnode->input(1); + MS_EXCEPTION_IF_NULL(matmul); + if (matmul->isa() && AnfAlgo::CheckPrimitiveType(matmul, prim::kPrimMatMul)) { + std::vector output_used_num{SizeToInt(manager->node_users()[matmul].size())}; + AnfAlgo::SetNodeAttr(kAttrOutputUsedNum, MakeValue(output_used_num), matmul); + std::unordered_set record{cnode, matmul}; + candidate_fusion->push_back(record); + SetRecordFusionId(record); + } +} + +void MatmulConfusionTranposeFusionPass::MatchSingleFusionPattern(const session::KernelGraph &kernel_graph, + FusedNodeRecord *candidate_fusion) { + MS_EXCEPTION_IF_NULL(candidate_fusion); + std::vector node_list = TopoSort(kernel_graph.get_return()); + for (auto &node : node_list) { + if (!AnfAlgo::IsRealCNodeKernel(node) || fusion_id_allocator->HasFusionIdAttr(node) || + AnfAlgo::CheckPrimitiveType(node, prim::kPrimReturn)) { + continue; + } + auto cnode = node->cast(); + MS_EXCEPTION_IF_NULL(cnode); + + if (AnfAlgo::GetCNodeName(cnode) == kConfusionTransposeDOpName) { + MatchMatmulConfusionTranpose(cnode, kernel_graph, candidate_fusion); + } + } +} +} // namespace opt +} // namespace mindspore diff --git a/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.h b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.h new file mode 100644 index 0000000000..b5d599a66c --- /dev/null +++ b/mindspore/ccsrc/backend/optimizer/ascend/buffer_fusion/matmul_confusiontranspose_fusion_pass.h @@ -0,0 +1,48 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_BUFFER_FUSION_PASS_MATMUL_CONFUSIONTRANSPOSE_FUSION_PASS_H_ +#define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_BUFFER_FUSION_PASS_MATMUL_CONFUSIONTRANSPOSE_FUSION_PASS_H_ + +#include +#include + +#include "backend/optimizer/ascend/buffer_fusion/fusion_base_pass.h" +#include "ir/anf.h" +#include "backend/optimizer/common/pass.h" +#include "backend/optimizer/common/fusion_id_allocator.h" +#include "runtime/device/kernel_info.h" +#include "backend/kernel_compiler/kernel.h" +#include "backend/session/kernel_graph.h" + +namespace mindspore { +namespace opt { +using FusedNodeRecord = std::vector>; + +class MatmulConfusionTranposeFusionPass : public FusionBasePass { + public: + explicit MatmulConfusionTranposeFusionPass(FusionIdAllocatorPtr idAllocator) + : FusionBasePass("MatmulConfusionTranposeFusionPass", idAllocator) {} + ~MatmulConfusionTranposeFusionPass() override = default; + void MatchSingleFusionPattern(const session::KernelGraph &kernel_graph, FusedNodeRecord *candidate_fusion) override; + + private: + void MatchMatmulConfusionTranpose(const CNodePtr &cnode, const session::KernelGraph &kernel_graph, + FusedNodeRecord *candidate_fusion); +}; +} // namespace opt +} // namespace mindspore + +#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_BUFFER_FUSION_PASS_MATMUL_CONFUSIONTRANSPOSE_FUSION_PASS_H_ diff --git a/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc b/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc index 88e9fa77b8..35c484de8d 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/format_type/merge_cast_to_op.cc @@ -172,7 +172,6 @@ AnfNodePtr MergeCastToNextOp(const FuncGraphPtr &graph, const CNodePtr &node, co << "ori kernel info" << ori_kernel_info->ToString() << "alternative kernel info" << (*alternative_kernel_info)->ToString(); AnfAlgo::SetSelectKernelBuildInfo(*alternative_kernel_info, next_cnode.get()); - ChangeNodeInferInfo(next_cnode, node, cast_index); if (node->inputs().size() < kCastInputNum) { MS_LOG(EXCEPTION) << "Op[" << node->DebugString() << "] has wrong input num:"; } diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.cc b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.cc index 189ac94546..9164484b30 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.cc +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.cc @@ -15,30 +15,9 @@ */ #include "backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.h" #include "backend/optimizer/common/helper.h" +#include "backend/session/anf_runtime_algorithm.h" namespace mindspore { namespace opt { -AnfNodePtr AdamApplyOneFusion::CreateAdamApplyOneNode(const FuncGraphPtr &func_graph, const EquivPtr &equiv) const { - MS_EXCEPTION_IF_NULL(func_graph); - MS_EXCEPTION_IF_NULL(equiv); - auto prim = std::make_shared(kAdamApplyOneOpName); - std::vector new_node_inputs = {NewValueNode(prim)}; - for (const auto &input_var : input_vars_) { - auto input_node = utils::cast((*equiv)[input_var]); - MS_EXCEPTION_IF_NULL(input_node); - new_node_inputs.push_back(input_node); - } - for (const auto &mul_x_input_var : mul_x_input_vars_) { - auto mul_x_input_node = utils::cast((*equiv)[mul_x_input_var]); - MS_EXCEPTION_IF_NULL(mul_x_input_node); - new_node_inputs.push_back(mul_x_input_node); - } - auto add2_y_node = utils::cast((*equiv)[add2_y_]); - MS_EXCEPTION_IF_NULL(add2_y_node); - new_node_inputs.push_back(add2_y_node); - auto new_node = func_graph->NewCNode(new_node_inputs); - return new_node; -} - const BaseRef AdamApplyOneFusion::DefinePattern() const { const auto prim_sqrt = std::make_shared(kSqrtOpName); const auto prim_real_div = std::make_shared(kRealDivOpName); @@ -104,16 +83,152 @@ const BaseRef AdamApplyOneCond4Fusion::DefinePattern() const { return VectorRef({prim::kPrimSub, input_vars_[3], VectorRef({prim::kPrimMul, true_div0, input_vars_[4]})}); } +const BaseRef AdamApplyOneAssignFusion::DefinePattern() const { + const auto prim_sqrt = std::make_shared(kSqrtOpName); + const auto prim_real_div = std::make_shared(kRealDivOpName); + VectorRef mul2 = VectorRef({prim::kPrimMul, mul_x_input_vars_[2], input_vars_[1]}); + VectorRef mul3 = VectorRef({prim::kPrimMul, mul_x_input_vars_[3], VectorRef({prim::kPrimSquare, input_vars_[0]})}); + VectorRef add1 = VectorRef({add1_var_, mul2, mul3}); + VectorRef sqrt0 = VectorRef({prim_sqrt, add1}); + VectorRef mul1 = VectorRef({prim::kPrimMul, mul_x_input_vars_[1], input_vars_[0]}); + VectorRef mul0 = VectorRef({prim::kPrimMul, mul_x_input_vars_[0], input_vars_[2]}); + VectorRef add0 = VectorRef({add0_var_, mul0, mul1}); + VectorRef true_div0 = VectorRef({prim_real_div, add0, VectorRef({prim::kPrimTensorAdd, sqrt0, add2_y_})}); + VectorRef sub0 = VectorRef({sub0_var_, input_vars_[3], VectorRef({prim::kPrimMul, input_vars_[4], true_div0})}); + VectorRef assign0 = VectorRef({prim::kPrimAssign, input_vars_[3], sub0}); + VectorRef depend0 = VectorRef({prim::kPrimDepend, sub0, assign0}); + VectorRef assign1 = VectorRef({prim::kPrimAssign, input_vars_[2], add0}); + VectorRef depend1 = VectorRef({prim::kPrimDepend, depend0, assign1}); + VectorRef assign2 = VectorRef({prim::kPrimAssign, input_vars_[1], add1}); + return VectorRef({prim::kPrimDepend, depend1, assign2}); +} + +const BaseRef AdamApplyOneAssignCond1Fusion::DefinePattern() const { + const auto prim_sqrt = std::make_shared(kSqrtOpName); + const auto prim_real_div = std::make_shared(kRealDivOpName); + VectorRef mul2 = VectorRef({prim::kPrimMul, mul_x_input_vars_[2], input_vars_[1]}); + VectorRef mul3 = VectorRef({prim::kPrimMul, mul_x_input_vars_[3], VectorRef({prim::kPrimSquare, input_vars_[0]})}); + VectorRef add1 = VectorRef({add1_var_, mul2, mul3}); + VectorRef sqrt0 = VectorRef({prim_sqrt, add1}); + VectorRef mul1 = VectorRef({prim::kPrimMul, mul_x_input_vars_[1], input_vars_[0]}); + VectorRef mul0 = VectorRef({prim::kPrimMul, mul_x_input_vars_[0], input_vars_[2]}); + VectorRef add0 = VectorRef({add0_var_, mul0, mul1}); + VectorRef true_div0 = VectorRef({prim_real_div, add0, VectorRef({prim::kPrimTensorAdd, add2_y_, sqrt0})}); + VectorRef sub0 = VectorRef({sub0_var_, input_vars_[3], VectorRef({prim::kPrimMul, input_vars_[4], true_div0})}); + VectorRef assign0 = VectorRef({prim::kPrimAssign, input_vars_[3], sub0}); + VectorRef depend0 = VectorRef({prim::kPrimDepend, sub0, assign0}); + VectorRef assign1 = VectorRef({prim::kPrimAssign, input_vars_[2], add0}); + VectorRef depend1 = VectorRef({prim::kPrimDepend, depend0, assign1}); + VectorRef assign2 = VectorRef({prim::kPrimAssign, input_vars_[1], add1}); + return VectorRef({prim::kPrimDepend, depend1, assign2}); +} + +const BaseRef AdamApplyOneAssignCond2Fusion::DefinePattern() const { + const auto prim_sqrt = std::make_shared(kSqrtOpName); + const auto prim_real_div = std::make_shared(kRealDivOpName); + VectorRef mul2 = VectorRef({prim::kPrimMul, mul_x_input_vars_[2], input_vars_[1]}); + VectorRef mul3 = VectorRef({prim::kPrimMul, VectorRef({prim::kPrimSquare, input_vars_[0]}), mul_x_input_vars_[3]}); + VectorRef add1 = VectorRef({add1_var_, mul2, mul3}); + VectorRef sqrt0 = VectorRef({prim_sqrt, add1}); + VectorRef mul1 = VectorRef({prim::kPrimMul, mul_x_input_vars_[1], input_vars_[0]}); + VectorRef mul0 = VectorRef({prim::kPrimMul, mul_x_input_vars_[0], input_vars_[2]}); + VectorRef add0 = VectorRef({add0_var_, mul0, mul1}); + VectorRef true_div0 = VectorRef({prim_real_div, add0, VectorRef({prim::kPrimTensorAdd, sqrt0, add2_y_})}); + VectorRef sub0 = VectorRef({sub0_var_, input_vars_[3], VectorRef({prim::kPrimMul, true_div0, input_vars_[4]})}); + VectorRef assign0 = VectorRef({prim::kPrimAssign, input_vars_[3], sub0}); + VectorRef depend0 = VectorRef({prim::kPrimDepend, sub0, assign0}); + VectorRef assign1 = VectorRef({prim::kPrimAssign, input_vars_[2], add0}); + VectorRef depend1 = VectorRef({prim::kPrimDepend, depend0, assign1}); + VectorRef assign2 = VectorRef({prim::kPrimAssign, input_vars_[1], add1}); + return VectorRef({prim::kPrimDepend, depend1, assign2}); +} + +const BaseRef AdamApplyOneAssignCond3Fusion::DefinePattern() const { + const auto prim_sqrt = std::make_shared(kSqrtOpName); + const auto prim_real_div = std::make_shared(kRealDivOpName); + VectorRef mul2 = VectorRef({prim::kPrimMul, mul_x_input_vars_[2], input_vars_[1]}); + VectorRef mul3 = VectorRef({prim::kPrimMul, mul_x_input_vars_[3], VectorRef({prim::kPrimSquare, input_vars_[0]})}); + VectorRef add1 = VectorRef({add1_var_, mul2, mul3}); + VectorRef sqrt0 = VectorRef({prim_sqrt, add1}); + VectorRef mul1 = VectorRef({prim::kPrimMul, mul_x_input_vars_[1], input_vars_[0]}); + VectorRef mul0 = VectorRef({prim::kPrimMul, mul_x_input_vars_[0], input_vars_[2]}); + VectorRef add0 = VectorRef({add0_var_, mul0, mul1}); + VectorRef true_div0 = VectorRef({prim_real_div, add0, VectorRef({prim::kPrimTensorAdd, sqrt0, add2_y_})}); + VectorRef sub0 = VectorRef({sub0_var_, input_vars_[3], VectorRef({prim::kPrimMul, true_div0, input_vars_[4]})}); + VectorRef assign0 = VectorRef({prim::kPrimAssign, input_vars_[3], sub0}); + VectorRef depend0 = VectorRef({prim::kPrimDepend, sub0, assign0}); + VectorRef assign1 = VectorRef({prim::kPrimAssign, input_vars_[2], add0}); + VectorRef depend1 = VectorRef({prim::kPrimDepend, depend0, assign1}); + VectorRef assign2 = VectorRef({prim::kPrimAssign, input_vars_[1], add1}); + return VectorRef({prim::kPrimDepend, depend1, assign2}); +} + +const BaseRef AdamApplyOneAssignCond4Fusion::DefinePattern() const { + const auto prim_sqrt = std::make_shared(kSqrtOpName); + const auto prim_real_div = std::make_shared(kRealDivOpName); + VectorRef mul2 = VectorRef({prim::kPrimMul, mul_x_input_vars_[2], input_vars_[1]}); + VectorRef mul3 = VectorRef({prim::kPrimMul, mul_x_input_vars_[3], VectorRef({prim::kPrimSquare, input_vars_[0]})}); + VectorRef add1 = VectorRef({add1_var_, mul2, mul3}); + VectorRef sqrt0 = VectorRef({prim_sqrt, add1}); + VectorRef mul1 = VectorRef({prim::kPrimMul, mul_x_input_vars_[1], input_vars_[0]}); + VectorRef mul0 = VectorRef({prim::kPrimMul, mul_x_input_vars_[0], input_vars_[2]}); + VectorRef add0 = VectorRef({add0_var_, mul0, mul1}); + VectorRef true_div0 = VectorRef({prim_real_div, add0, VectorRef({prim::kPrimTensorAdd, add2_y_, sqrt0})}); + VectorRef sub0 = VectorRef({sub0_var_, input_vars_[3], VectorRef({prim::kPrimMul, true_div0, input_vars_[4]})}); + VectorRef assign0 = VectorRef({prim::kPrimAssign, input_vars_[3], sub0}); + VectorRef depend0 = VectorRef({prim::kPrimDepend, sub0, assign0}); + VectorRef assign1 = VectorRef({prim::kPrimAssign, input_vars_[2], add0}); + VectorRef depend1 = VectorRef({prim::kPrimDepend, depend0, assign1}); + VectorRef assign2 = VectorRef({prim::kPrimAssign, input_vars_[1], add1}); + return VectorRef({prim::kPrimDepend, depend1, assign2}); +} + +AnfNodePtr AdamApplyOneFusion::CreateAdamApplyOneNode(const FuncGraphPtr &func_graph, const EquivPtr &equiv, + const AnfNodePtr &final_node) const { + MS_EXCEPTION_IF_NULL(func_graph); + MS_EXCEPTION_IF_NULL(equiv); + PrimitivePtr prim = nullptr; + if (AnfAlgo::CheckPrimitiveType(final_node, prim::kPrimDepend)) { + prim = std::make_shared(kAdamApplyOneAssignOpName); + } else { + prim = std::make_shared(kAdamApplyOneOpName); + } + std::vector new_node_inputs = {NewValueNode(prim)}; + for (const auto &input_var : input_vars_) { + auto input_node = utils::cast((*equiv)[input_var]); + MS_EXCEPTION_IF_NULL(input_node); + new_node_inputs.push_back(input_node); + } + for (const auto &mul_x_input_var : mul_x_input_vars_) { + auto mul_x_input_node = utils::cast((*equiv)[mul_x_input_var]); + MS_EXCEPTION_IF_NULL(mul_x_input_node); + new_node_inputs.push_back(mul_x_input_node); + } + auto add2_y_node = utils::cast((*equiv)[add2_y_]); + MS_EXCEPTION_IF_NULL(add2_y_node); + new_node_inputs.push_back(add2_y_node); + auto new_node = func_graph->NewCNode(new_node_inputs); + return new_node; +} + const AnfNodePtr AdamApplyOneFusion::Process(const FuncGraphPtr &func_graph, const AnfNodePtr &node, const EquivPtr &equiv) const { MS_EXCEPTION_IF_NULL(func_graph); - MS_EXCEPTION_IF_NULL(node); - if (!CheckSupportDataType(node, kFloatDataTypeSet)) { + auto sub0 = node; + if (AnfAlgo::CheckPrimitiveType(node, prim::kPrimDepend)) { + auto iter_sub0 = (*equiv).find(sub0_var_); + if (iter_sub0 == (*equiv).end()) { + MS_LOG(EXCEPTION) << "The equiv map is expected to contains the sub0 var after matched."; + } + sub0 = utils::cast(iter_sub0->second); + } + MS_EXCEPTION_IF_NULL(sub0); + if (!CheckSupportDataType(sub0, kFloatDataTypeSet)) { return nullptr; } - auto new_node = CreateAdamApplyOneNode(func_graph, equiv); + auto new_node = CreateAdamApplyOneNode(func_graph, equiv, node); MS_EXCEPTION_IF_NULL(new_node); - new_node->set_scope(node->scope()); + new_node->set_scope(sub0->scope()); // Set abstract of new node AbstractBasePtrList new_node_abstract_list; auto iter_add0 = (*equiv).find(add0_var_); @@ -130,7 +245,7 @@ const AnfNodePtr AdamApplyOneFusion::Process(const FuncGraphPtr &func_graph, con MS_EXCEPTION_IF_NULL(add1); new_node_abstract_list.push_back(add1->abstract()); new_node_abstract_list.push_back(add0->abstract()); - new_node_abstract_list.push_back(node->abstract()); + new_node_abstract_list.push_back(sub0->abstract()); auto abstract_tuple = std::make_shared(new_node_abstract_list); new_node->set_abstract(abstract_tuple); // Create tuple_getitem node for outputs diff --git a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.h b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.h index 2fe2d32fa0..4c5649f978 100644 --- a/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.h +++ b/mindspore/ccsrc/backend/optimizer/ascend/ir_fusion/adam_apply_one_fusion.h @@ -40,6 +40,7 @@ class AdamApplyOneFusion : public PatternProcessPass { add2_y_ = std::make_shared(); add0_var_ = std::make_shared(std::make_shared(prim::kPrimTensorAdd->name())); add1_var_ = std::make_shared(std::make_shared(prim::kPrimTensorAdd->name())); + sub0_var_ = std::make_shared(std::make_shared(prim::kPrimSub->name())); } ~AdamApplyOneFusion() override = default; @@ -47,12 +48,14 @@ class AdamApplyOneFusion : public PatternProcessPass { const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override; protected: - AnfNodePtr CreateAdamApplyOneNode(const FuncGraphPtr &func_graph, const EquivPtr &equiv) const; + AnfNodePtr CreateAdamApplyOneNode(const FuncGraphPtr &func_graph, const EquivPtr &equiv, + const AnfNodePtr &final_node) const; std::vector input_vars_; std::vector mul_x_input_vars_; VarPtr add2_y_; VarPtr add0_var_; VarPtr add1_var_; + VarPtr sub0_var_; }; class AdamApplyOneCond1Fusion : public AdamApplyOneFusion { @@ -90,6 +93,51 @@ class AdamApplyOneCond4Fusion : public AdamApplyOneFusion { ~AdamApplyOneCond4Fusion() override = default; const BaseRef DefinePattern() const override; }; + +class AdamApplyOneAssignFusion : public AdamApplyOneFusion { + public: + explicit AdamApplyOneAssignFusion(bool multigraph = true) + : AdamApplyOneFusion("adam_apply_one_assign_fusion", multigraph) {} + + ~AdamApplyOneAssignFusion() override = default; + const BaseRef DefinePattern() const override; +}; + +class AdamApplyOneAssignCond1Fusion : public AdamApplyOneFusion { + public: + explicit AdamApplyOneAssignCond1Fusion(bool multigraph = true) + : AdamApplyOneFusion("adam_apply_one_assign_cond1_fusion", multigraph) {} + + ~AdamApplyOneAssignCond1Fusion() override = default; + const BaseRef DefinePattern() const override; +}; + +class AdamApplyOneAssignCond2Fusion : public AdamApplyOneFusion { + public: + explicit AdamApplyOneAssignCond2Fusion(bool multigraph = true) + : AdamApplyOneFusion("adam_apply_one_assign_cond2_fusion", multigraph) {} + + ~AdamApplyOneAssignCond2Fusion() override = default; + const BaseRef DefinePattern() const override; +}; + +class AdamApplyOneAssignCond3Fusion : public AdamApplyOneFusion { + public: + explicit AdamApplyOneAssignCond3Fusion(bool multigraph = true) + : AdamApplyOneFusion("adam_apply_one_assign_cond3_fusion", multigraph) {} + + ~AdamApplyOneAssignCond3Fusion() override = default; + const BaseRef DefinePattern() const override; +}; + +class AdamApplyOneAssignCond4Fusion : public AdamApplyOneFusion { + public: + explicit AdamApplyOneAssignCond4Fusion(bool multigraph = true) + : AdamApplyOneFusion("adam_apply_one_assign_cond4_fusion", multigraph) {} + + ~AdamApplyOneAssignCond4Fusion() override = default; + const BaseRef DefinePattern() const override; +}; } // namespace opt } // namespace mindspore #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_IR_FUSION_ADAM_APPLY_ONE_FUSION_H_ diff --git a/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_output_to_maketuple.cc b/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_output_to_maketuple.cc index 8bdc234e81..f4a57b0baa 100644 --- a/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_output_to_maketuple.cc +++ b/mindspore/ccsrc/backend/optimizer/pass/convert_tuple_output_to_maketuple.cc @@ -62,7 +62,14 @@ const AnfNodePtr ConvertTupleOutputToMaketuple::Process(const FuncGraphPtr &func auto cnode = node->cast(); MS_EXCEPTION_IF_NULL(cnode); std::unordered_map transed_nodes; - if (IsPrimitiveCNode(cnode, prim::kPrimTupleGetItem) || IsPrimitiveCNode(cnode, prim::kPrimControlDepend)) { + if (IsPrimitiveCNode(cnode, prim::kPrimTupleGetItem)) { + auto real_input = AnfAlgo::GetTupleGetItemRealInput(cnode); + MS_EXCEPTION_IF_NULL(real_input); + if (!real_input->isa() && !real_input->isa()) { + return nullptr; + } + } + if (IsPrimitiveCNode(cnode, prim::kPrimControlDepend)) { return nullptr; } bool cnode_input_changed = false; diff --git a/mindspore/ccsrc/backend/session/session_basic.cc b/mindspore/ccsrc/backend/session/session_basic.cc index bf60814564..a357b6f712 100644 --- a/mindspore/ccsrc/backend/session/session_basic.cc +++ b/mindspore/ccsrc/backend/session/session_basic.cc @@ -863,7 +863,7 @@ bool TensorNeedSync(const AnfNodePtr ¶meter, const tensor::TensorPtr &tensor auto ms_context = MsContext::GetInstance(); MS_EXCEPTION_IF_NULL(ms_context); auto device_address = AnfAlgo::GetMutableOutputAddr(parameter, 0); - if (ms_context->enable_pynative_infer()) { + if (ms_context->execution_mode() == kPynativeMode) { return tensor->device_address().get() == nullptr || tensor->device_address() != device_address; } if (tensor->is_dirty()) { diff --git a/mindspore/ccsrc/frontend/operator/cc_implementations.cc b/mindspore/ccsrc/frontend/operator/cc_implementations.cc index 2df68037e5..3526a001f9 100644 --- a/mindspore/ccsrc/frontend/operator/cc_implementations.cc +++ b/mindspore/ccsrc/frontend/operator/cc_implementations.cc @@ -393,40 +393,5 @@ ValuePtr BoolEq(const ValuePtrList &list) { MS_LOG(EXCEPTION) << "Unsported Value for BoolEq, x: " << x->ToString() << "."; } - -std::vector BroadcastShape_(std::vector shpx, std::vector shpy) { - int dlen = SizeToInt(shpx.size()) - SizeToInt(shpy.size()); - if (dlen < 0) { - for (int i = 0; i < -dlen; ++i) { - (void)shpx.insert(shpx.begin(), 1); - } - } else if (dlen > 0) { - for (int i = 0; i < dlen; i++) { - (void)shpy.insert(shpy.begin(), 1); - } - } - if (shpx.size() != shpy.size()) { - MS_LOG(EXCEPTION) << "Failure: shpx.size() != shpy.size()."; - } - std::vector shp; - for (size_t i = 0; i < shpx.size(); i++) { - auto a = shpx[i]; - auto b = shpy[i]; - if (a == 1) { - shp.push_back(b); - } else if (b == 1) { - shp.push_back(a); - } else if (a == -1) { - shp.push_back(b); - } else if (b == -1) { - shp.push_back(a); - } else if (a == b) { - shp.push_back(a); - } else { - return std::vector(); - } - } - return shp; -} } // namespace prim } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/operator/cc_implementations.h b/mindspore/ccsrc/frontend/operator/cc_implementations.h index ffe75cb0c0..beb129645b 100644 --- a/mindspore/ccsrc/frontend/operator/cc_implementations.h +++ b/mindspore/ccsrc/frontend/operator/cc_implementations.h @@ -52,7 +52,6 @@ ValuePtr BoolNot(const ValuePtrList &list); ValuePtr BoolAnd(const ValuePtrList &list); ValuePtr BoolOr(const ValuePtrList &list); ValuePtr BoolEq(const ValuePtrList &list); -std::vector BroadcastShape_(std::vector s1, std::vector s2); } // namespace prim } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/operator/composite/composite.cc b/mindspore/ccsrc/frontend/operator/composite/composite.cc index fbcb06629d..b7fa2cf67d 100644 --- a/mindspore/ccsrc/frontend/operator/composite/composite.cc +++ b/mindspore/ccsrc/frontend/operator/composite/composite.cc @@ -333,28 +333,28 @@ ArgsPairList HyperMap::Harmonize(const FuncGraphPtr &func_graph, const ArgsPairL } FuncGraphPtr HyperMap::GenerateFromTypes(const TypePtrList &args_spec_list) { - FuncGraphPtr ptrGraph = std::make_shared(); - ptrGraph->set_flag(FUNC_GRAPH_FLAG_CORE, true); - ptrGraph->set_flag(FUNC_GRAPH_FLAG_SPECIALIZE_PARAMETER, true); - ptrGraph->debug_info()->set_name("hyper_map"); + FuncGraphPtr ptr_graph = std::make_shared(); + ptr_graph->set_flag(FUNC_GRAPH_FLAG_CORE, true); + ptr_graph->set_flag(FUNC_GRAPH_FLAG_SPECIALIZE_PARAMETER, true); + ptr_graph->debug_info()->set_name("hyper_map"); AnfNodePtr ptrFnArg = nullptr; std::size_t i = 0; ArgsPairList argmap; ArgsPairList argmap2; if (fn_leaf_ == nullptr) { - ptrFnArg = ptrGraph->add_parameter(); + ptrFnArg = ptr_graph->add_parameter(); i = 1; } std::size_t size = args_spec_list.size(); for (; i < size; ++i) { - argmap.push_back(std::make_pair(ptrGraph->add_parameter(), args_spec_list[i])); + argmap.push_back(std::make_pair(ptr_graph->add_parameter(), args_spec_list[i])); } - argmap2 = Harmonize(ptrGraph, argmap); - ptrGraph->set_output(Make(ptrGraph, ptrFnArg, argmap2)); - return ptrGraph; + argmap2 = Harmonize(ptr_graph, argmap); + ptr_graph->set_output(Make(ptr_graph, ptrFnArg, argmap2)); + return ptr_graph; } abstract::AbstractBasePtrList HyperMap::NormalizeArgs(const AbstractBasePtrList &args_spec_list) const { @@ -582,30 +582,30 @@ FuncGraphPtr GradOperation::GetGrad(AnfNodePtr node, const AnfNodePtr &weights, inputs.push_back(opsTupleItem); inputs.push_back(cnode); inputs.push_back(NewValueNode(1)); - AnfNodePtr ptrBprop = ret->NewCNode(inputs); + AnfNodePtr ptr_bprop = ret->NewCNode(inputs); - doGetGrad(ret, out, ptrBprop, weights_node, opsTupleItem); + doGetGrad(ret, out, ptr_bprop, weights_node, opsTupleItem); return ret; } -void GradOperation::doGetGrad(const FuncGraphPtr &func_graph, AnfNodePtr out, AnfNodePtr ptrBprop, AnfNodePtr weights, +void GradOperation::doGetGrad(const FuncGraphPtr &func_graph, AnfNodePtr out, AnfNodePtr ptr_bprop, AnfNodePtr weights, ValueNodePtr opsTupleItem) { MS_EXCEPTION_IF_NULL(func_graph); - AnfNodePtr ptrBPropArg = nullptr; + AnfNodePtr ptr_bprop_arg = nullptr; if (sens_param_) { - ptrBPropArg = func_graph->add_parameter(); + ptr_bprop_arg = func_graph->add_parameter(); } else { auto ones_like = prim::GetPythonOps("ones_like"); - ptrBPropArg = func_graph->NewCNode({NewValueNode(ones_like), out}); + ptr_bprop_arg = func_graph->NewCNode({NewValueNode(ones_like), out}); } - AnfNodePtr ptrBApp = func_graph->NewCNode({ptrBprop, ptrBPropArg}); + AnfNodePtr ptr_bapp = func_graph->NewCNode({ptr_bprop, ptr_bprop_arg}); CNodePtr fv_bprop = nullptr; if (get_by_list_) { // python code: grads = hyper_map(F.partial(env_get, env), weights) - AnfNodePtr env = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), ptrBApp, NewValueNode(0)}); + AnfNodePtr env = func_graph->NewCNode({NewValueNode(prim::kPrimTupleGetItem), ptr_bapp, NewValueNode(0)}); AnfNodePtr partial_env_get = func_graph->NewCNode({NewValueNode(prim::kPrimPartial), NewValueNode(prim::GetPythonOps("env_get")), env}); MetaFuncGraphPtr hyper_map = std::make_shared(); @@ -614,7 +614,7 @@ void GradOperation::doGetGrad(const FuncGraphPtr &func_graph, AnfNodePtr out, An CNodePtr inputs_bprop = nullptr; if (get_all_) { - inputs_bprop = func_graph->NewCNode({NewValueNode(kTail), ptrBApp}); + inputs_bprop = func_graph->NewCNode({NewValueNode(kTail), ptr_bapp}); } // Gradients wrt inputs and parameters @@ -636,8 +636,8 @@ void GradOperation::doGetGrad(const FuncGraphPtr &func_graph, AnfNodePtr out, An } // Gradients wrt first input. - // ptrBApp returns (EnvInstance(grads wrt params), grads wrt input0, grads wrt input1, ...), so 1 is for first input - func_graph->set_output(func_graph->NewCNode({opsTupleItem, ptrBApp, NewValueNode(1)})); + // ptr_bapp returns (EnvInstance(grads wrt params), grads wrt input0, grads wrt input1, ...), so 1 is for first input + func_graph->set_output(func_graph->NewCNode({opsTupleItem, ptr_bapp, NewValueNode(1)})); } // Generate the graph. @@ -657,35 +657,35 @@ FuncGraphPtr GradOperation::GenerateFuncGraph(const AbstractBasePtrList &args_sp auto real_fn = dyn_cast(fn); MS_EXCEPTION_IF_NULL(real_fn); - FuncGraphPtr ptrGraph = real_fn->func_graph(); - MS_EXCEPTION_IF_NULL(ptrGraph); - TraceManager::DebugTrace(std::make_shared(ptrGraph->debug_info())); - FuncGraphPtr dfBuilder = std::make_shared(); + FuncGraphPtr ptr_graph = real_fn->func_graph(); + MS_EXCEPTION_IF_NULL(ptr_graph); + TraceManager::DebugTrace(std::make_shared(ptr_graph->debug_info())); + FuncGraphPtr df_builder = std::make_shared(); TraceManager::EndTrace(); - auto nparam = ptrGraph->parameters().size(); + auto nparam = ptr_graph->parameters().size(); std::ostringstream ss; ss << "grad{" << nparam << "}"; - dfBuilder->set_flag(FUNC_GRAPH_FLAG_CORE, true); - dfBuilder->debug_info()->set_name(ss.str()); - ParameterPtr param_graph = dfBuilder->add_parameter(); + df_builder->set_flag(FUNC_GRAPH_FLAG_CORE, true); + df_builder->debug_info()->set_name(ss.str()); + ParameterPtr param_graph = df_builder->add_parameter(); AnfNodePtr weights = nullptr; if (get_by_list_) { - weights = dfBuilder->add_parameter(); + weights = df_builder->add_parameter(); } std::vector inputs; inputs.push_back(NewValueNode(prim::kPrimJ)); inputs.push_back(param_graph); - auto jf = dfBuilder->NewCNode(inputs); + auto jf = df_builder->NewCNode(inputs); // df is checked in GetGrad - TraceManager::DebugTrace(std::make_shared(ptrGraph->debug_info())); - auto df = GetGrad(jf, weights, ptrGraph->parameters()); + TraceManager::DebugTrace(std::make_shared(ptr_graph->debug_info())); + auto df = GetGrad(jf, weights, ptr_graph->parameters()); TraceManager::EndTrace(); - dfBuilder->set_output(NewValueNode(df)); + df_builder->set_output(NewValueNode(df)); - return dfBuilder; + return df_builder; } REGISTER_PYBIND_DEFINE(GradOperation_, ([](const py::module *m) { @@ -929,7 +929,7 @@ void GenerateTupleSliceParameter(const AbstractTuplePtr &tuple, const AbstractSl *step_value = CheckSliceMember(slice->step(), step_default, step_name); if (*step_value == 0) { - MS_LOG(EXCEPTION) << "TupleSlice require the step value could not be 0, but got 0."; + MS_EXCEPTION(ValueError) << "TupleSlice require the step value could not be 0, but got 0."; } if (*step_value < 0) { @@ -941,8 +941,8 @@ void GenerateTupleSliceParameter(const AbstractTuplePtr &tuple, const AbstractSl *stop_index = CheckSliceMember(slice->stop(), stop_default, stop_name); if (!CheckIndexInRange(*start_index, -tuple_size, tuple_size - 1) || !CheckIndexInRange(*stop_index, -tuple_size - 1, tuple_size)) { - MS_LOG(EXCEPTION) << "TupleSlice the start index " << *start_index << " or end end index " << *stop_index - << " out of range, tuple size " << tuple_size << "."; + MS_EXCEPTION(ValueError) << "TupleSlice the start index " << *start_index << " or end end index " << *stop_index + << " out of range, tuple size " << tuple_size << "."; } *start_index = GetPositiveIndex(*start_index, tuple_size); diff --git a/mindspore/ccsrc/frontend/operator/composite/do_signature.cc b/mindspore/ccsrc/frontend/operator/composite/do_signature.cc index 50be3c5b29..248e42cb5b 100644 --- a/mindspore/ccsrc/frontend/operator/composite/do_signature.cc +++ b/mindspore/ccsrc/frontend/operator/composite/do_signature.cc @@ -72,10 +72,15 @@ void SetMaxType(TypeId *max_type_id, size_t *max_type_number, const TypeId type_ bool GetTensorOrScalarTypeInfo(AbstractBasePtr arg_value, bool is_write, TypeId *arg_type_id, TypeId *arg_type = nullptr) { if (arg_value->isa()) { - if (is_write) { - arg_value = arg_value->cast()->ref_origin(); - } else { - arg_value = arg_value->cast()->ref(); + auto ref = arg_value->cast(); + arg_value = ref->ref(); + if (!is_write && ref->need_cast()) { + auto tensor_type = ref->target_type(); + *arg_type_id = tensor_type->type_id(); + if (arg_type != nullptr) { + *arg_type = kObjectTypeTensorType; + } + return true; } } if (arg_value->isa()) { @@ -248,6 +253,8 @@ void DoAutoCast(const std::string &func_name, const std::vector &sign if (arg_value->isa() && arg_type_id == it->second) { continue; } + MS_LOG(DEBUG) << "do cast for inputs " << i << " " << (*op_inputs)[i + 1]->ToString() << " " << arg_type_id + << " to " << it->second; (*op_inputs)[i + 1] = DoCast((*op_inputs)[i + 1], it->second, graph); } } @@ -289,16 +296,23 @@ AnfNodePtr BuildNewCNode(const FuncGraphPtr &func_graph, const std::string &func TypePtr type = args_spec_list[i]->GetTypeTrack(); if (type && type->type_id() == kObjectTypeRef) { + auto ref_abs = args_spec_list[i]->cast(); if (sig == SignatureEnumRW::kRWRead) { - param = func_graph->NewCNode({NewValueNode(prim::kPrimGetRefValue), param}); + param = NewCNode({NewValueNode(prim::kPrimGetRefValue), param}, func_graph); + if (ref_abs && ref_abs->need_cast()) { + auto cast = prim::GetPythonOps("cast", "mindspore.ops.functional"); + param = NewCNode({NewValueNode(cast), param, NewValueNode(ref_abs->target_type())}, func_graph); + } } else if (sig == SignatureEnumRW::kRWWrite) { - param = func_graph->NewCNode({NewValueNode(prim::kPrimGetRefOrigin), param}); + param = NewCNode({NewValueNode(prim::kPrimGetRefValue), param}, func_graph); write_indices.insert(i); } // If sig is SignatureEnumRW::kRWRef, not do anything. } else if (sig == SignatureEnumRW::kRWWrite && type->type_id() != kObjectTypeRefKey) { MS_EXCEPTION(TypeError) << "Function " << func_name << "'s input " << i << " should be a Parameter."; } + MS_LOG(DEBUG) << "Function " << func_name << "'s input " << i << " " << param->DebugString(2) << " type " + << args_spec_list[i]->ToString(); op_inputs.push_back(param); } // process default diff --git a/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc b/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc index 2c9e0b538f..1b6f358edd 100644 --- a/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc +++ b/mindspore/ccsrc/frontend/operator/composite/unpack_call.cc @@ -49,13 +49,14 @@ FuncGraphPtr UnpackCall::GenerateFuncGraph(const AbstractBasePtrList &args_spec_ MS_LOG(EXCEPTION) << op_name << " requires at least two args, but got " << arg_length << "."; } - (void)abstract::CheckArg(op_name, args_spec_list, 0); + // No need to check, check will be done in infer. auto ret_graph = std::make_shared(); ret_graph->set_flag(FUNC_GRAPH_FLAG_CORE, true); + ret_graph->debug_info()->set_name("UnpackCall"); - AnfNodePtr fnNode = ret_graph->add_parameter(); + AnfNodePtr fn_node = ret_graph->add_parameter(); std::vector elems; - elems.push_back(fnNode); + elems.push_back(fn_node); for (size_t index = 1; index < arg_length; index++) { MS_EXCEPTION_IF_NULL(args_spec_list[index]); if (args_spec_list[index]->isa()) { diff --git a/mindspore/ccsrc/frontend/operator/ops.h b/mindspore/ccsrc/frontend/operator/ops.h index 85b0ac474f..3b49bfbaf1 100755 --- a/mindspore/ccsrc/frontend/operator/ops.h +++ b/mindspore/ccsrc/frontend/operator/ops.h @@ -31,160 +31,43 @@ ValuePtr GetPythonOps(const std::string &op_name, const std::string &module_name = "mindspore._extends.parse.standard_method", bool use_signature = false); -// Arithmetic -inline const PrimitivePtr kPrimScalarAdd = std::make_shared("scalar_add"); -inline const PrimitivePtr kPrimScalarSub = std::make_shared("scalar_sub"); -inline const PrimitivePtr kPrimScalarMul = std::make_shared("scalar_mul"); -inline const PrimitivePtr kPrimScalarDiv = std::make_shared("scalar_div"); -inline const PrimitivePtr kPrimScalarFloordiv = std::make_shared("scalar_floordiv"); -inline const PrimitivePtr kPrimScalarMod = std::make_shared("scalar_mod"); -inline const PrimitivePtr kPrimScalarPow = std::make_shared("scalar_pow"); -inline const PrimitivePtr kPrimScalarTrunc = std::make_shared("scalar_trunc"); -inline const PrimitivePtr kPrimScalarFloor = std::make_shared("scalar_floor"); -inline const PrimitivePtr kPrimScalarUadd = std::make_shared("scalar_uadd"); -inline const PrimitivePtr kPrimScalarUsub = std::make_shared("scalar_usub"); -inline const PrimitivePtr kPrimScalarExp = std::make_shared("scalar_exp"); -inline const PrimitivePtr kPrimScalarLog = std::make_shared("scalar_log"); -inline const PrimitivePtr kPrimScalarSin = std::make_shared("scalar_sin"); -inline const PrimitivePtr kPrimScalarCos = std::make_shared("scalar_cos"); -inline const PrimitivePtr kPrimScalarTan = std::make_shared("scalar_tan"); - -// Comparisons -inline const PrimitivePtr kPrimScalarEq = std::make_shared("scalar_eq"); -inline const PrimitivePtr kPrimScalarLt = std::make_shared("scalar_lt"); -inline const PrimitivePtr kPrimScalarGt = std::make_shared("scalar_gt"); -inline const PrimitivePtr kPrimScalarNe = std::make_shared("scalar_ne"); -inline const PrimitivePtr kPrimScalarLe = std::make_shared("scalar_le"); -inline const PrimitivePtr kPrimScalarGe = std::make_shared("scalar_ge"); -inline const PrimitivePtr kPrimBoolNot = std::make_shared("bool_not"); -inline const PrimitivePtr kPrimBoolAnd = std::make_shared("bool_and"); -inline const PrimitivePtr kPrimBoolOr = std::make_shared("bool_or"); -inline const PrimitivePtr kPrimBoolEq = std::make_shared("bool_eq"); -inline const PrimitivePtr kPrimGreater = std::make_shared("Greater"); -inline const PrimitivePtr kPrimGreaterEqual = std::make_shared("GreaterEqual"); -inline const PrimitivePtr kPrimLess = std::make_shared("Less"); -inline const PrimitivePtr kPrimLessEqual = std::make_shared("LessEqual"); -inline const PrimitivePtr kPrimEqual = std::make_shared("Equal"); -inline const PrimitivePtr kPrimNotEqual = std::make_shared("NotEqual"); - +// Primitives only used by frontend; // Type introspection inline const PrimitivePtr kPrimTypeOf = std::make_shared("typeof"); inline const PrimitivePtr kPrimHasType = std::make_shared("hastype"); -inline const PrimitivePtr kPrimDistribute = std::make_shared("distribute"); -inline const PrimitivePtr kPrimDot = std::make_shared("dot"); -inline const PrimitivePtr kPrimIm2Col = std::make_shared("im2col"); -inline const PrimitivePtr kPrimCol2Im = std::make_shared("col2im"); -inline const PrimitivePtr kPrimIm2ColV1 = std::make_shared("im2col_v1"); -inline const PrimitivePtr kPrimCol2ImV1 = std::make_shared("col2im_v1"); - inline const PrimitivePtr kPrimResolve = std::make_shared("resolve"); inline const PrimitivePtr kPrimEmbed = std::make_shared("embed"); inline const PrimitivePtr kPrimRefToEmbed = std::make_shared("RefToEmbed"); inline const PrimitivePtr kPrimCreateInstance = std::make_shared("create_instance"); -inline const PrimitivePtr kPrimLabelGoto = std::make_shared("LabelGoto"); -inline const PrimitivePtr kPrimLabelSwitch = std::make_shared("LabelSwitch"); -inline const PrimitivePtr kPrimLabelSet = std::make_shared("LabelSet"); +// Other miscellaneous +inline const PrimitivePtr kPrimGetRefOrigin = std::make_shared("get_ref_origin"); +inline const PrimitivePtr kPrimInsertGradientOf = std::make_shared("InsertGradientOf"); +inline const PrimitivePtr kPrimCheckBprop = std::make_shared("CheckBprop"); +inline const PrimitivePtr kPrimMixedPrecisionCast = std::make_shared("mixed_precision_cast"); +inline const PrimitivePtr kPrimMakeRecord = std::make_shared("make_record"); -// Arrays -inline const PrimitivePtr kPrimScalarToArray = std::make_shared("scalar_to_array"); -inline const PrimitivePtr kPrimArrayToScalar = std::make_shared("array_to_scalar"); -inline const PrimitivePtr kPrimBroadcastShape = std::make_shared("broadcast_shape"); -inline const PrimitivePtr kPrimArrayMap = std::make_shared("array_map"); -inline const PrimitivePtr kPrimArrayReduce = std::make_shared("array_reduce"); -inline const PrimitivePtr kPrimCast = std::make_shared("Cast"); -inline const PrimitivePtr kPrimConcat = std::make_shared("Concat"); -inline const PrimitivePtr kPrimSqueeze = std::make_shared("Squeeze"); -inline const PrimitivePtr kPrimTranspose = std::make_shared("Transpose"); -inline const PrimitivePtr kPrimGatherV2 = std::make_shared("GatherV2"); -inline const PrimitivePtr kPrimEmbeddingLookup = std::make_shared("EmbeddingLookup"); -inline const PrimitivePtr kPrimEmbeddingLookupCommGrad = std::make_shared("EmbeddingLookupCommGrad"); -inline const PrimitivePtr kPrimSize = std::make_shared("Size"); -inline const PrimitivePtr kPrimArgMax = std::make_shared("Argmax"); -inline const PrimitivePtr kPrimPack = std::make_shared("Pack"); -inline const PrimitivePtr kPrimUnsortedSegmentSum = std::make_shared("UnsortedSegmentSum"); -inline const PrimitivePtr kPrimUnsortedSegmentMin = std::make_shared("UnsortedSegmentMin"); -inline const PrimitivePtr kPrimConcatOffset = std::make_shared("ConcatOffset"); -inline const PrimitivePtr kPrimReshape = std::make_shared("Reshape"); -inline const PrimitivePtr kPrimTile = std::make_shared("Tile"); -inline const PrimitivePtr kPrimAddN = std::make_shared("AddN"); -inline const PrimitivePtr KPrimTransData = std::make_shared("TransData"); -inline const PrimitivePtr kPrimNMSWithMask = std::make_shared("NMSWithMask"); -inline const PrimitivePtr kPrimPad = std::make_shared("Pad"); -inline const PrimitivePtr kPrimArgMaxWithValue = std::make_shared("ArgMaxWithValue"); -inline const PrimitivePtr kPrimUnique = std::make_shared("Unique"); -inline const PrimitivePtr kPrimUniqueGrad = std::make_shared("UniqueGrad"); +// Structures + +inline const PrimitivePtr kPrimListMap = std::make_shared("list_map"); +inline const PrimitivePtr kPrimListReduce = std::make_shared("list_reduce"); +inline const PrimitivePtr kPrimTupleReversed = std::make_shared("tuple_reversed"); +inline const PrimitivePtr kPrimReducedShape = std::make_shared("reduced_shape"); +inline const PrimitivePtr kPrimTupleDiv = std::make_shared("tuple_div"); +inline const PrimitivePtr kPrimTupleToArray = std::make_shared("tuple_to_array"); +inline const PrimitivePtr kPrimShapeMul = std::make_shared("shape_mul"); +inline const PrimitivePtr kPrimTupleEqual = std::make_shared("tuple_equal"); +inline const PrimitivePtr kPrimListEqual = std::make_shared("list_equal"); +inline const PrimitivePtr kPrimMakeRange = std::make_shared("make_range"); +inline const PrimitivePtr kPrimStopGradient = std::make_shared("stop_gradient"); +inline const PrimitivePtr kPrimStringEqual = std::make_shared("string_equal"); +inline const PrimitivePtr kPrimStringConcat = std::make_shared("string_concat"); +inline const PrimitivePtr kPrimDictLen = std::make_shared("dict_len"); -// NN -inline const PrimitivePtr kPrimFlatten = std::make_shared("Flatten"); -inline const PrimitivePtr kPrimSoftmax = std::make_shared("Softmax"); -inline const PrimitivePtr kPrimLogSoftmax = std::make_shared("LogSoftmax"); -inline const PrimitivePtr kPrimLogSoftmaxGrad = std::make_shared("LogSoftmaxGrad"); -inline const PrimitivePtr kPrimTanh = std::make_shared("Tanh"); -inline const PrimitivePtr kPrimTanhGrad = std::make_shared("TanhGrad"); -inline const PrimitivePtr kPrimPooling = std::make_shared("Pooling"); -inline const PrimitivePtr kPrimPoolingGrad = std::make_shared("PoolingGrad"); -inline const PrimitivePtr kPrimMaxPool = std::make_shared("MaxPool"); -inline const PrimitivePtr kPrimMaxPoolGrad = std::make_shared("MaxPoolGrad"); -inline const PrimitivePtr kPrimApplyCenteredRMSProp = std::make_shared("ApplyCenteredRMSProp"); -inline const PrimitivePtr kPrimAvgPoolGrad = std::make_shared("AvgPoolGrad"); -inline const PrimitivePtr kPrimAvgPoolGradVm = std::make_shared("AvgPoolGradVm"); -inline const PrimitivePtr kPrimFusedBatchNorm = std::make_shared("FusedBatchNorm"); -inline const PrimitivePtr kPrimConv2D = std::make_shared("Conv2D"); -inline const PrimitivePtr kPrimFusedBatchNormGrad = std::make_shared("FusedBatchNormGrad"); -inline const PrimitivePtr kPrimBatchNorm = std::make_shared("BatchNorm"); -inline const PrimitivePtr kPrimBatchNormGrad = std::make_shared("BatchNormGrad"); -inline const PrimitivePtr kPrimReluGrad = std::make_shared("ReluGrad"); -inline const PrimitivePtr kPrimConv2DBackpropInput = std::make_shared("Conv2DBackpropInput"); -inline const PrimitivePtr kPrimConv2DBackpropFilter = std::make_shared("Conv2DBackpropFilter"); -inline const PrimitivePtr kPrimDepthwiseConv2dNative = std::make_shared("DepthwiseConv2dNative"); -inline const PrimitivePtr kPrimDepthwiseConv2dNativeBackpropFilter = - std::make_shared("DepthwiseConv2dNativeBackpropFilter"); -inline const PrimitivePtr kPrimDepthwiseConv2dNativeBackpropInput = - std::make_shared("DepthwiseConv2dNativeBackpropInput"); -inline const PrimitivePtr kPrimBiasAddGrad = std::make_shared("BiasAddGrad"); -inline const PrimitivePtr kPrimSoftmaxCrossEntropyWithLogits = - std::make_shared("SoftmaxCrossEntropyWithLogits"); -inline const PrimitivePtr kPrimSparseSoftmaxCrossEntropyWithLogits = - std::make_shared("SparseSoftmaxCrossEntropyWithLogits"); -inline const PrimitivePtr kPrimMomentum = std::make_shared("Momentum"); -inline const PrimitivePtr kPrimApplyMomentum = std::make_shared("ApplyMomentum"); -inline const PrimitivePtr kPrimLayerNorm = std::make_shared("LayerNorm"); -inline const PrimitivePtr kPrimLayerNormGrad = std::make_shared("LayerNormGrad"); -inline const PrimitivePtr kPrimLayerNormXBackprop = std::make_shared("LayerNormXBackprop"); -inline const PrimitivePtr kPrimLayerNormBetaGammaBackprop = std::make_shared("LayerNormBetaGammaBackprop"); -inline const PrimitivePtr kPrimDropoutGenMask = std::make_shared("DropoutGenMask"); -inline const PrimitivePtr kPrimDropoutDoMask = std::make_shared("DropoutDoMask"); -inline const PrimitivePtr kPrimOneHot = std::make_shared("OneHot"); -inline const PrimitivePtr kPrimGelu = std::make_shared("Gelu"); -inline const PrimitivePtr kPrimGeluGrad = std::make_shared("GeluGrad"); -inline const PrimitivePtr kPrimRelu = std::make_shared("ReLU"); -inline const PrimitivePtr kPrimReluV2 = std::make_shared("ReLUV2"); -inline const PrimitivePtr kPrimZerosLike = std::make_shared("ZerosLike"); inline const PrimitivePtr kPrimFakeBprop = std::make_shared("fake_bprop"); -inline const PrimitivePtr kPrimBpropCut = std::make_shared("bprop_cut"); -inline const PrimitivePtr kPrimFakeQuantPerLayer = std::make_shared("FakeQuantPerLayer"); -inline const PrimitivePtr kPrimFakeQuantPerChannel = std::make_shared("FakeQuantPerChannel"); -inline const PrimitivePtr kPrimApplyRMSProp = std::make_shared("ApplyRMSProp"); -// Comm ops -inline const PrimitivePtr kPrimMirror = std::make_shared("_MirrorOperator"); -inline const PrimitivePtr kPrimVirtualDiv = std::make_shared("_VirtualDiv"); -inline const PrimitivePtr kPrimVirtualDataset = std::make_shared("_VirtualDataset"); -inline const PrimitivePtr kPrimAllReduce = std::make_shared("AllReduce"); - -// RowTensor -inline const PrimitivePtr kPrimMakeRowTensor = std::make_shared("MakeRowTensor"); -inline const PrimitivePtr kPrimRowTensorGetValues = std::make_shared("RowTensorGetValues"); -inline const PrimitivePtr kPrimRowTensorGetIndices = std::make_shared("RowTensorGetIndices"); -inline const PrimitivePtr kPrimRowTensorGetDenseShape = std::make_shared("RowTensorGetDenseShape"); - -// SparseTensor -inline const PrimitivePtr kPrimMakeSparseTensor = std::make_shared("MakeSparseTensor"); -inline const PrimitivePtr kPrimSparseTensorGetValues = std::make_shared("SparseTensorGetValues"); -inline const PrimitivePtr kPrimSparseTensorGetIndices = std::make_shared("SparseTensorGetIndices"); -inline const PrimitivePtr kPrimSparseTensorGetDenseShape = std::make_shared("SparseTensorGetDenseShape"); +inline const PrimitivePtr kPrimBroadcastGradientArgs = std::make_shared("BroadcastGradientArgs"); class UnpackGraphPrimitive : public Primitive { public: diff --git a/mindspore/ccsrc/frontend/operator/prim_structures.cc b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc similarity index 60% rename from mindspore/ccsrc/frontend/operator/prim_structures.cc rename to mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc index cc53f9aa22..90b9a6a5a2 100644 --- a/mindspore/ccsrc/frontend/operator/prim_structures.cc +++ b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.cc @@ -1,6 +1,4 @@ /** - * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). - * * Copyright 2019 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,360 +13,266 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "frontend/operator/ops_front_infer_function.h" +#include +#include +#include +#include +#include + +#include "abstract/abstract_value.h" #include "pipeline/jit/static_analysis/prim.h" -#include "abstract/utils.h" #include "abstract/param_validator.h" -#include "frontend/operator/ops.h" -#include "utils/convert_utils.h" #include "utils/tensor_py.h" - -using mindspore::tensor::TensorPy; - +#include "frontend/operator/ops.h" +#include "abstract/infer_functions.h" namespace mindspore { namespace abstract { +enum State { + SAME, + X_ONE, + Y_ONE, +}; -AbstractBasePtr InferImplStringEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: two scalars whose value is a string. - const std::string op_name = primitive->name(); +struct SlideInfo { + int start; + int step; + int stop; +}; + +template +AbstractBasePtr InferImplTupleOrListEqual(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { + // Inputs: two tuples or two lists. CheckArgsSize(op_name, args_spec_list, 2); - AbstractScalarPtr scalar_x = CheckArg(op_name, args_spec_list, 0); - AbstractScalarPtr scalar_y = CheckArg(op_name, args_spec_list, 1); + auto input_x = CheckArg(op_name, args_spec_list, 0); + auto input_y = CheckArg(op_name, args_spec_list, 1); - ValuePtr value_x = scalar_x->BuildValue(); - ValuePtr value_y = scalar_y->BuildValue(); - if (!value_x->isa() || !value_y->isa()) { - MS_LOG(EXCEPTION) << op_name << " requires 2 parameters are string, but got param0: " << value_x->ToString() - << ", param1: " << value_y->ToString(); - } - - bool ret = (value_x->cast()->value() == value_y->cast()->value()); - return std::make_shared(ret); + ValuePtr x_value = input_x->BuildValue(); + ValuePtr y_value = input_y->BuildValue(); + return std::make_shared(*x_value == *y_value); } -AbstractBasePtr InferImplStringConcat(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: two scalars whose value is a string. - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 2); - AbstractScalarPtr scalar_x = CheckArg(op_name, args_spec_list, 0); - AbstractScalarPtr scalar_y = CheckArg(op_name, args_spec_list, 1); - - ValuePtr value_x = scalar_x->BuildValue(); - ValuePtr value_y = scalar_y->BuildValue(); - if (!value_x->isa() || !value_y->isa()) { - MS_LOG(EXCEPTION) << op_name << " requires 2 parameters are string, but got param0: " << value_x->ToString() - << ", param1: " << value_y->ToString(); - } - - std::string ret = (value_x->cast()->value() + value_y->cast()->value()); - return std::make_shared(ret); -} - -AbstractBasePtr InferImplMakeTuple(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list) { - return std::make_shared(args_spec_list); -} - -AbstractBasePtr InferImplMakeList(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list) { - return std::make_shared(args_spec_list); -} - -AbstractBasePtr InferImplMakeDict(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: two tuples. - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 2); - AbstractTuplePtr keys = CheckArg(op_name, args_spec_list, 0); - AbstractTuplePtr values = CheckArg(op_name, args_spec_list, 1); - - size_t keys_size = keys->size(); - if (values->size() != keys_size) { - MS_LOG(EXCEPTION) << op_name << " evaluator keys' size is not equal with values' size"; - } - - std::vector key_value; - AbstractScalarPtr key; - AbstractBasePtrList key_list = keys->elements(); - AbstractBasePtrList value_list = values->elements(); - for (size_t index = 0; index < keys_size; index++) { - key = CheckArg(op_name + "key", key_list, index); - ValuePtr keyPtr = key->BuildValue(); - MS_EXCEPTION_IF_NULL(keyPtr); - if (!keyPtr->isa()) { - MS_LOG(EXCEPTION) << op_name << " evaluator keys should be string, but got " << keyPtr->ToString(); +void CalcSlidePara(const AbstractBasePtrList &args_spec_list, SlideInfo *slide) { + int arg1 = 0; + int arg2 = 0; + if (!args_spec_list.empty()) { + MS_EXCEPTION_IF_NULL(args_spec_list[0]); + auto arg_value = args_spec_list[0]->BuildValue(); + if (!arg_value->isa()) { + MS_LOG(EXCEPTION) << "Only supported input an int32 number."; } - std::string key_string = GetValue(keyPtr); - key_value.emplace_back(key_string, value_list[index]); + arg1 = GetValue(arg_value); } - return std::make_shared(key_value); -} -AbstractBasePtr InferImplMakeKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a string and an object of a subclass of AbstractBase. - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 2); - AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 0); - - ValuePtr keyPtr = key->BuildValue(); - if (!keyPtr->isa()) { - MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << keyPtr->ToString(); - } - std::string key_string = GetValue(keyPtr); - return std::make_shared(key_string, args_spec_list[1]); -} - -AbstractBasePtr InferImplExtractKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a string and a keyword. - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 2); - AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 0); - AbstractKeywordArgPtr kwarg = CheckArg(op_name, args_spec_list, 1); - - ValuePtr key_value = key->BuildValue(); - if (!key_value->isa()) { - MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << key_value->ToString(); - } - std::string key_input = GetValue(key_value); - std::string key_actual = kwarg->get_key(); - if (key_actual != key_input) { - MS_LOG(EXCEPTION) << op_name << " evaluator input key should be same as AbstractKeywordArg' key, but input is " - << key_input << ", AbstractKeywordArg' key is " << key_actual; - } - return kwarg->get_arg(); -} - -AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: three scalars whose value is an int32 number. - CheckArgsSize(primitive->name(), args_spec_list, 3); - size_t args_size = args_spec_list.size(); - for (size_t index = 0; index < args_size; index++) { - MS_EXCEPTION_IF_NULL(args_spec_list[index]); - if (!args_spec_list[index]->isa() && !args_spec_list[index]->isa()) { - MS_EXCEPTION(TypeError) << "MakeSlice eval " << index << " parameter is neither AbstractScalar nor AbstractNone."; + if (args_spec_list.size() >= 2) { + MS_EXCEPTION_IF_NULL(args_spec_list[1]); + auto arg_value = args_spec_list[1]->BuildValue(); + if (!arg_value->isa()) { + MS_LOG(EXCEPTION) << "Only supported input an int32 number."; } - if (args_spec_list[index]->isa() && - !dyn_cast(args_spec_list[index])->BuildValue()->isa()) { - MS_EXCEPTION(TypeError) << "MakeSlice eval " << index - << " parameter is an AbstractScalar, but is not an int32 number."; + arg2 = GetValue(arg_value); + } + + if (args_spec_list.size() == 3) { + MS_EXCEPTION_IF_NULL(args_spec_list[2]); + auto arg_value = args_spec_list[2]->BuildValue(); + if (!arg_value->isa()) { + MS_LOG(EXCEPTION) << "Only supported input an int32 number."; + } + slide->step = GetValue(arg_value); + slide->start = arg1; + slide->stop = arg2; + } + + if (args_spec_list.size() == 2) { + slide->start = arg1; + slide->stop = arg2; + } + + if (args_spec_list.size() == 1) { + slide->stop = arg1; + } +} + +void ComputeReduceIndex(const std::vector &reverse_x, const std::vector &reverse_y, + std::vector *grad_x_reduce_idx, std::vector *grad_y_reduce_idy) { + const size_t n = reverse_x.size(); + for (size_t i = 0; i < n; ++i) { + State curr; + const int32_t x_i = reverse_x[i]; + const int32_t y_i = reverse_y[i]; + const int reduce_idx = SizeToInt(n - 1 - i); + if (x_i == y_i) { + curr = SAME; + } else if (x_i == 1) { + grad_x_reduce_idx->push_back(reduce_idx); + curr = X_ONE; + } else if (y_i == 1) { + grad_y_reduce_idy->push_back(reduce_idx); + curr = Y_ONE; + } else { + MS_LOG(EXCEPTION) << "not compatible shape input for BroadcastGradientArgs"; + } + if (curr == SAME && x_i == 1) { + grad_x_reduce_idx->push_back(reduce_idx); + grad_y_reduce_idy->push_back(reduce_idx); + continue; } } - // Slice: start, end, step - return std::make_shared(args_spec_list[0], args_spec_list[1], args_spec_list[2]); + + std::reverse(grad_x_reduce_idx->begin(), grad_x_reduce_idx->end()); + std::reverse(grad_y_reduce_idy->begin(), grad_y_reduce_idy->end()); } -// Eval the return type of make_record -AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: at lease two objects of a subclass of AbstractBase. - if (args_spec_list.size() < 2) { - MS_LOG(EXCEPTION) << "Typeof evaluator requires more than 1 parameter, while the input size is " - << args_spec_list.size() << "."; +AbstractBasePtr BroadcastGradientArgsDiff(const std::vector &x_shape, const std::vector &y_shape) { + std::vector reverse_x; + std::vector reverse_y; + + (void)std::transform(x_shape.rbegin(), x_shape.rend(), std::back_inserter(reverse_x), + [](const ValuePtr &v) { return v->cast()->value(); }); + (void)std::transform(y_shape.rbegin(), y_shape.rend(), std::back_inserter(reverse_y), + [](const ValuePtr &v) { return v->cast()->value(); }); + + if (reverse_x.size() > reverse_y.size()) { + reverse_y.resize(reverse_x.size(), 1); + } else { + reverse_x.resize(reverse_y.size(), 1); } - // args_spec_list[0] maybe AbstractScalarPtr or AbstractTypePtr + std::vector grad_x_reduce_idx; + std::vector grad_y_reduce_idy; + ComputeReduceIndex(reverse_x, reverse_y, &grad_x_reduce_idx, &grad_y_reduce_idy); + + AbstractBasePtrList abs_list_x; + AbstractBasePtrList abs_list_y; + (void)std::transform(grad_x_reduce_idx.begin(), grad_x_reduce_idx.end(), std::back_inserter(abs_list_x), + [](int v) { return abstract::FromValue(v); }); + (void)std::transform(grad_y_reduce_idy.begin(), grad_y_reduce_idy.end(), std::back_inserter(abs_list_y), + [](int v) { return abstract::FromValue(v); }); + auto x_reduce_idx = std::make_shared(abs_list_x); + auto y_reduce_idx = std::make_shared(abs_list_y); + AbstractBasePtrList elem_list; + elem_list.push_back(x_reduce_idx); + elem_list.push_back(y_reduce_idx); + + return std::make_shared(elem_list); +} + +AbstractBasePtr InferImplTypeof(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a pointer to an AbstractBase object + if (args_spec_list.size() != 1) { + MS_LOG(EXCEPTION) << "Typeof evaluator requires 1 parameter, while the input size is " << args_spec_list.size() + << "."; + } + AbstractBasePtr abs_base = args_spec_list[0]; + MS_EXCEPTION_IF_NULL(abs_base); + TypePtr type = abs_base->BuildType(); + return std::make_shared(type); +} + +AbstractBasePtr InferImplHasType(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a pointer to an AbstractBase object and a pointer to a Type + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractTypePtr abs_type = CheckArg(op_name, args_spec_list, 1); + + auto mode_v = abs_type->GetValueTrack(); + MS_EXCEPTION_IF_NULL(mode_v); + if (!mode_v->isa()) { + MS_LOG(EXCEPTION) << "Get the type from AbstractType value failed."; + } + + TypePtr mode_t = mode_v->cast(); MS_EXCEPTION_IF_NULL(args_spec_list[0]); - TypePtr type = args_spec_list[0]->GetTypeTrack(); - MS_EXCEPTION_IF_NULL(type); - if (type->type_id() != kMetaTypeTypeType) { - MS_LOG(EXCEPTION) << "Can not make type(" << type->ToString() << ")not TypeType"; - } - - ValuePtr value_track = args_spec_list[0]->GetValueTrack(); - MS_EXCEPTION_IF_NULL(value_track); - TypePtr type_ptr = value_track->cast(); - if (type_ptr == nullptr) { - MS_LOG(EXCEPTION) << "Value type error, not Me type:" << value_track->ToString(); - } - - auto cls = dyn_cast(type_ptr); - MS_EXCEPTION_IF_NULL(cls); - ClassAttrVector attributes = cls->GetAttributes(); - CheckArgsSize(primitive->name(), args_spec_list, attributes.size() + 1); - - std::vector abs_attributes; - for (size_t i = 0; i < attributes.size(); i++) { - AbstractAttribute elem(attributes[i].first, args_spec_list[i + 1]); - abs_attributes.push_back(elem); - } - - return std::make_shared(cls->tag(), abs_attributes, cls->methods()); + bool v = IsSubtype(args_spec_list[0], mode_t); + return std::make_shared(std::make_shared(v), kBool); } -template -AbstractBasePtr InferTupleOrListGetItem(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { - // Inputs: a tuple or list and a scalar whose value is an int32 number. - CheckArgsSize(op_name, args_spec_list, 2); - auto queue = CheckArg(op_name, args_spec_list, 0); - AbstractScalarPtr index = CheckArg(op_name, args_spec_list, 1); +bool CompareShape(const std::vector &x_shape, const std::vector &y_shape) { + if (x_shape.size() != y_shape.size()) { + return false; + } - ValuePtr index_value = index->BuildValue(); - if (!index_value->isa()) { - // when index_value is an AnyValue and args_spec_list[0] is a scalar, try to return the type of the first element - // and continue - if (dyn_cast(queue->elements()[0]) != nullptr) { - return std::make_shared(queue->elements()[0]->BuildType()); + for (size_t i = 0; i < x_shape.size(); ++i) { + if (GetValue(x_shape[i]) != GetValue(y_shape[i])) { + return false; } - MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int32 number, but got " - << index_value->ToString(); - } - int idx_v = GetValue(index_value); - std::size_t nelems = queue->elements().size(); - if (idx_v >= SizeToInt(nelems) || idx_v < -SizeToInt(nelems)) { - MS_EXCEPTION(IndexError) << op_name << " evaluator index should be in range[-" << SizeToInt(nelems) << ", " - << SizeToInt(nelems) << "), but got " << idx_v << "."; } - std::size_t uidx_v = 0; - if (idx_v >= 0) { - uidx_v = IntToSize(idx_v); - } else { - uidx_v = IntToSize(idx_v + SizeToInt(nelems)); - } - return queue->elements()[uidx_v]; + return true; } -template -AbstractBasePtr InferTupleOrListSetItem(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { - // Inputs: a tuple or list, a scalar whose value is an int32 number and an object of a subclass of AbstractBase. - CheckArgsSize(op_name, args_spec_list, 3); - auto queue = CheckArg(op_name, args_spec_list, 0); - AbstractScalarPtr index = CheckArg(op_name, args_spec_list, 1); - - ValuePtr index_value = index->BuildValue(); - if (!index_value->isa()) { - MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int32 number, but got " - << index_value->ToString(); - } - int idx_v = GetValue(index_value); - if (idx_v < 0) { - MS_EXCEPTION(IndexError) << "The index of " << typeid(T).name() << " should be positive number, but got " << idx_v - << "."; +AbstractBasePtr DoInferReduceShape(const AbstractTuplePtr &x_shape, const ValuePtr &x_shp_value, + const ValueTuplePtr &axis_value_ptr, const PrimitivePtr &primitive) { + size_t x_rank = x_shape->size(); + std::set axis_set; + auto axis_data = axis_value_ptr->value(); + if (axis_data.empty()) { + int size = 1; + AbstractBasePtrList values(x_rank, std::make_shared(size)); + return std::make_shared(values); } - size_t uidx_v = IntToSize(idx_v); - AbstractBasePtrList elements = queue->elements(); - std::size_t nelems = elements.size(); - if (uidx_v >= nelems) { - MS_EXCEPTION(IndexError) << op_name << " evaluator the index: " << uidx_v << " to set out of range: " << nelems - 1 - << "."; + for (auto &elem : axis_data) { + int e_value = CheckAxis(primitive->name(), elem, -SizeToInt(x_rank), SizeToInt(x_rank) - 1); + (void)axis_set.insert(e_value); } - elements[uidx_v] = args_spec_list[2]; - return std::make_shared(elements); + + auto x_shp_data = x_shp_value->cast()->value(); + if (x_shp_data.size() < x_rank) { + MS_LOG(EXCEPTION) << "x_shape_data.size() " << x_shp_data.size() << " less than x_shape.size() " << x_rank; + } + AbstractBasePtrList values; + for (size_t i = 0; i < x_rank; i++) { + if (axis_set.count(SizeToInt(i)) || axis_set.count(SizeToInt(i) - SizeToInt(x_rank))) { + auto axis_v = MakeValue(1); + values.push_back(std::make_shared(axis_v, axis_v->type())); + } else { + int dim_value = x_shp_data[i]->cast()->value(); + auto dim = MakeValue(dim_value); + values.push_back(std::make_shared(dim, dim->type())); + } + } + + return std::make_shared(values); } -AbstractBasePtr InferImplTupleGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferTupleOrListGetItem(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplListGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferTupleOrListGetItem(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplTupleSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferTupleOrListSetItem(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplListSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferTupleOrListSetItem(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplDictGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a dict and a scalar whose value is a string. +AbstractBasePtr InferImplBroadcastGradientArgs(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // this primitive get the index that need to reduce + // input: x's shape and y's shape, inputs should be tuple + // output: tuple of x and y 's reduce index, reduce index should be a tuple const std::string op_name = primitive->name(); CheckArgsSize(op_name, args_spec_list, 2); - AbstractDictionaryPtr dict = CheckArg(op_name, args_spec_list, 0); - AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 1); + auto arg_x = CheckArg(op_name, args_spec_list, 0); + auto arg_y = CheckArg(op_name, args_spec_list, 1); - ValuePtr key_value = key->BuildValue(); - if (!key_value->isa()) { - MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << key_value->ToString(); + ValueTuplePtr arg_x_value = arg_x->BuildValue()->cast(); + MS_EXCEPTION_IF_NULL(arg_x_value); + + ValueTuplePtr arg_y_value = arg_y->BuildValue()->cast(); + MS_EXCEPTION_IF_NULL(arg_y_value); + + const std::vector x_shape = arg_x_value->value(); + const std::vector y_shape = arg_y_value->value(); + bool is_same_shape = CompareShape(x_shape, y_shape); + // if it is the same shape , do not need reduce , return empty tuple + if (is_same_shape) { + AbstractBasePtrList empty_list; + auto x_reduce_idx = std::make_shared(empty_list); + auto y_reduce_idx = std::make_shared(empty_list); + + AbstractBasePtrList elem_list; + elem_list.push_back(x_reduce_idx); + elem_list.push_back(y_reduce_idx); + + return std::make_shared(elem_list); } - auto key_str = GetValue(key_value); - std::vector dict_elems = dict->elements(); - auto it = std::find_if(dict_elems.begin(), dict_elems.end(), - [key_str](const AbstractAttribute &item) { return item.first == key_str; }); - if (it == dict_elems.end()) { - MS_LOG(EXCEPTION) << "The key " << key_str << " does not exist in the dict:" << args_spec_list[0]->ToString(); - } - return it->second; -} - -AbstractBasePtr InferImplDictSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a dict and a scalar whose value is a string and an object of a subclass of AbstractBase. - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 3); - AbstractDictionaryPtr dict = CheckArg(op_name, args_spec_list, 0); - AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 1); - - ValuePtr key_value = key->BuildValue(); - if (!key_value->isa()) { - MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << key_value->ToString(); - } - std::string key_str = GetValue(key_value); - std::vector dict_elems = dict->elements(); - auto it = std::find_if(dict_elems.begin(), dict_elems.end(), - [key_str](AbstractAttribute &item) { return item.first == key_str; }); - - MS_EXCEPTION_IF_NULL(args_spec_list[2]); - auto new_ele = std::make_pair(key_str, args_spec_list[2]); - if (it != dict_elems.end()) { - int index = it - dict_elems.begin(); - dict_elems[IntToSize(index)] = new_ele; - } else { - dict_elems.push_back(new_ele); - } - return std::make_shared(dict_elems); -} - -AbstractBasePtr InferImplListAppend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a list and an object of a subclass of AbstractBase. - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 2); - AbstractListPtr list = CheckArg(op_name, args_spec_list, 0); - (void)AbstractJoin(list->elements()); - return list; -} - -template -AbstractBasePtr InferTupleOrListOrDictLen(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { - // Inputs: a tuple or list or dict. - CheckArgsSize(op_name, args_spec_list, 1); - auto arg = CheckArg(op_name, args_spec_list, 0); - return std::make_shared(SizeToInt(arg->size())); -} - -AbstractBasePtr InferImplTupleLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferTupleOrListOrDictLen(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplListLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferTupleOrListOrDictLen(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplDictLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferTupleOrListOrDictLen(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplArrayLen(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list) { - return std::make_shared(kAnyValue, kInt32); + return BroadcastGradientArgsDiff(x_shape, y_shape); } AbstractBasePtr InferImplListMap(const AnalysisEnginePtr &engine, const PrimitivePtr &primitive, @@ -430,41 +334,6 @@ AbstractBasePtr InferImplTupleReversed(const AnalysisEnginePtr &, const Primitiv return std::make_shared(elem_list); } -AbstractBasePtr DoInferReduceShape(const AbstractTuplePtr &x_shape, const ValuePtr &x_shp_value, - const ValueTuplePtr &axis_value_ptr, const PrimitivePtr &primitive) { - size_t x_rank = x_shape->size(); - std::set axis_set; - auto axis_data = axis_value_ptr->value(); - if (axis_data.empty()) { - int size = 1; - AbstractBasePtrList values(x_rank, std::make_shared(size)); - return std::make_shared(values); - } - - for (auto &elem : axis_data) { - int e_value = CheckAxis(primitive->name(), elem, -SizeToInt(x_rank), SizeToInt(x_rank) - 1); - (void)axis_set.insert(e_value); - } - - auto x_shp_data = x_shp_value->cast()->value(); - if (x_shp_data.size() < x_rank) { - MS_LOG(EXCEPTION) << "x_shape_data.size() " << x_shp_data.size() << " less than x_shape.size() " << x_rank; - } - AbstractBasePtrList values; - for (size_t i = 0; i < x_rank; i++) { - if (axis_set.count(SizeToInt(i)) || axis_set.count(SizeToInt(i) - SizeToInt(x_rank))) { - auto axis_v = MakeValue(1); - values.push_back(std::make_shared(axis_v, axis_v->type())); - } else { - int dim_value = x_shp_data[i]->cast()->value(); - auto dim = MakeValue(dim_value); - values.push_back(std::make_shared(dim, dim->type())); - } - } - - return std::make_shared(values); -} - AbstractBasePtr InferImplReduceShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, const AbstractBasePtrList &args_spec_list) { // Inputs: x_shape, axis @@ -563,7 +432,7 @@ AbstractBasePtr InferImplTuple2Array(const AnalysisEnginePtr &, const PrimitiveP py::tuple data_tuple = ValuePtrToPyData(input->BuildValue()); py::array data = py::array(data_tuple); - auto tensor = TensorPy::MakeTensor(data); + auto tensor = tensor::TensorPy::MakeTensor(data); auto ret = tensor->ToAbstract(); ret->set_value(tensor); MS_LOG(DEBUG) << "Tuple2arry result AbstractTensor: " << ret->ToString(); @@ -596,76 +465,6 @@ AbstractBasePtr InferImplShapeMul(const AnalysisEnginePtr &, const PrimitivePtr return std::make_shared(result_v, result_v->type()); } -template -AbstractBasePtr InferImplTupleOrListEqual(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { - // Inputs: two tuples or two lists. - CheckArgsSize(op_name, args_spec_list, 2); - auto input_x = CheckArg(op_name, args_spec_list, 0); - auto input_y = CheckArg(op_name, args_spec_list, 1); - - ValuePtr x_value = input_x->BuildValue(); - ValuePtr y_value = input_y->BuildValue(); - return std::make_shared(*x_value == *y_value); -} - -AbstractBasePtr InferImplTupleEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferImplTupleOrListEqual(primitive->name(), args_spec_list); -} - -AbstractBasePtr InferImplListEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - return InferImplTupleOrListEqual(primitive->name(), args_spec_list); -} - -struct SlideInfo { - int start; - int step; - int stop; -}; - -void CalcSlidePara(const AbstractBasePtrList &args_spec_list, SlideInfo *slide) { - int arg1 = 0; - int arg2 = 0; - if (!args_spec_list.empty()) { - MS_EXCEPTION_IF_NULL(args_spec_list[0]); - auto arg_value = args_spec_list[0]->BuildValue(); - if (!arg_value->isa()) { - MS_LOG(EXCEPTION) << "Only supported input an int32 number."; - } - arg1 = GetValue(arg_value); - } - - if (args_spec_list.size() >= 2) { - MS_EXCEPTION_IF_NULL(args_spec_list[1]); - auto arg_value = args_spec_list[1]->BuildValue(); - if (!arg_value->isa()) { - MS_LOG(EXCEPTION) << "Only supported input an int32 number."; - } - arg2 = GetValue(arg_value); - } - - if (args_spec_list.size() == 3) { - MS_EXCEPTION_IF_NULL(args_spec_list[2]); - auto arg_value = args_spec_list[2]->BuildValue(); - if (!arg_value->isa()) { - MS_LOG(EXCEPTION) << "Only supported input an int32 number."; - } - slide->step = GetValue(arg_value); - slide->start = arg1; - slide->stop = arg2; - } - - if (args_spec_list.size() == 2) { - slide->start = arg1; - slide->stop = arg2; - } - - if (args_spec_list.size() == 1) { - slide->stop = arg1; - } -} - AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr &, const AbstractBasePtrList &args_spec_list) { if (args_spec_list.empty()) { @@ -709,5 +508,145 @@ AbstractBasePtr InferImplStopGradient(const AnalysisEnginePtr &, const Primitive CheckArgsSize(primitive->name(), args_spec_list, 1); return args_spec_list[0]->Clone(); } + +AbstractBasePtr InferImplTupleEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferImplTupleOrListEqual(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplListEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferImplTupleOrListEqual(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplStringEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: two scalars whose value is a string. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractScalarPtr scalar_x = CheckArg(op_name, args_spec_list, 0); + AbstractScalarPtr scalar_y = CheckArg(op_name, args_spec_list, 1); + + ValuePtr value_x = scalar_x->BuildValue(); + ValuePtr value_y = scalar_y->BuildValue(); + if (!value_x->isa() || !value_y->isa()) { + MS_LOG(EXCEPTION) << op_name << " requires 2 parameters are string, but got param0: " << value_x->ToString() + << ", param1: " << value_y->ToString(); + } + + bool ret = (value_x->cast()->value() == value_y->cast()->value()); + return std::make_shared(ret); +} + +AbstractBasePtr InferImplStringConcat(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: two scalars whose value is a string. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractScalarPtr scalar_x = CheckArg(op_name, args_spec_list, 0); + AbstractScalarPtr scalar_y = CheckArg(op_name, args_spec_list, 1); + + ValuePtr value_x = scalar_x->BuildValue(); + ValuePtr value_y = scalar_y->BuildValue(); + if (!value_x->isa() || !value_y->isa()) { + MS_LOG(EXCEPTION) << op_name << " requires 2 parameters are string, but got param0: " << value_x->ToString() + << ", param1: " << value_y->ToString(); + } + + std::string ret = (value_x->cast()->value() + value_y->cast()->value()); + return std::make_shared(ret); +} + +AbstractBasePtr InferImplDictLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferTupleOrListOrDictLen(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplJ(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // args: An object of AbstractFunction. + CheckArgsSize(primitive->name(), args_spec_list, 1); + MS_LOG(DEBUG) << "evaluate J: " << args_spec_list[0]->ToString(); + + AbstractFunctionPtr x = dyn_cast(args_spec_list[0]); + if (x == nullptr) { + return std::make_shared(args_spec_list[0]); + } + + AbstractFuncAtomPtrList jv; + auto build_jv = [&jv](const AbstractFuncAtomPtr &func) { + auto j_closure = std::make_shared(func); + jv.push_back(j_closure); + }; + x->Visit(build_jv); + + return AbstractFunction::MakeAbstractFunction(jv); +} + +AbstractBasePtr InferImplFakeBprop(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a tensor. + CheckArgsSize(primitive->name(), args_spec_list, 1); + return args_spec_list[0]->Broaden(); +} + +// Eval the return type of make_record +AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: at lease two objects of a subclass of AbstractBase. + if (args_spec_list.size() < 2) { + MS_LOG(EXCEPTION) << "Typeof evaluator requires more than 1 parameter, while the input size is " + << args_spec_list.size() << "."; + } + + // args_spec_list[0] maybe AbstractScalarPtr or AbstractTypePtr + MS_EXCEPTION_IF_NULL(args_spec_list[0]); + TypePtr type = args_spec_list[0]->GetTypeTrack(); + MS_EXCEPTION_IF_NULL(type); + if (type->type_id() != kMetaTypeTypeType) { + MS_LOG(EXCEPTION) << "Can not make type(" << type->ToString() << ")not TypeType"; + } + + ValuePtr value_track = args_spec_list[0]->GetValueTrack(); + MS_EXCEPTION_IF_NULL(value_track); + TypePtr type_ptr = value_track->cast(); + if (type_ptr == nullptr) { + MS_LOG(EXCEPTION) << "Value type error, not Me type:" << value_track->ToString(); + } + + auto cls = dyn_cast(type_ptr); + MS_EXCEPTION_IF_NULL(cls); + ClassAttrVector attributes = cls->GetAttributes(); + CheckArgsSize(primitive->name(), args_spec_list, attributes.size() + 1); + + std::vector abs_attributes; + for (size_t i = 0; i < attributes.size(); i++) { + AbstractAttribute elem(attributes[i].first, args_spec_list[i + 1]); + abs_attributes.push_back(elem); + } + + return std::make_shared(cls->tag(), abs_attributes, cls->methods()); +} +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(TypeOf, prim::kPrimTypeOf, InferImplTypeof); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(HasType, prim::kPrimHasType, InferImplHasType); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(MakeRecord, prim::kPrimMakeRecord, InferImplMakeRecord); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(ListMap, prim::kPrimListMap, InferImplListMap); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(ListReduce, prim::kPrimListReduce, InferImplListReduce); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(TupleReversed, prim::kPrimTupleReversed, InferImplTupleReversed); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(ReducedShape, prim::kPrimReducedShape, InferImplReduceShape); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(TupleDiv, prim::kPrimTupleDiv, InferImplTupleDiv); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(TupleToArray, prim::kPrimTupleToArray, InferImplTuple2Array); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(ShapeMul, prim::kPrimShapeMul, InferImplShapeMul); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(TupleEqual, prim::kPrimTupleEqual, InferImplTupleEqual); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(ListEqual, prim::kPrimListEqual, InferImplListEqual); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(MakeRange, prim::kPrimMakeRange, InferImplMakeRange); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(StopGradient, prim::kPrimStopGradient, InferImplStopGradient); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(StringEqual, prim::kPrimStringEqual, InferImplStringEqual); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(StringConcat, prim::kPrimStringConcat, InferImplStringConcat); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(DictLen, prim::kPrimDictLen, InferImplDictLen); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(FakeBprop, prim::kPrimFakeBprop, InferImplFakeBprop); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(J, prim::kPrimJ, InferImplJ); +REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(BroadcastGradientArgs, prim::kPrimBroadcastGradientArgs, + InferImplBroadcastGradientArgs); } // namespace abstract } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/operator/ops_front_infer_function.h b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.h new file mode 100644 index 0000000000..6ddacd199d --- /dev/null +++ b/mindspore/ccsrc/frontend/operator/ops_front_infer_function.h @@ -0,0 +1,77 @@ +/** + * Copyright 2019 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_FRONTEND_OPERATE_OPS_FRONT_INFER_FUNCTION_H_ +#define MINDSPORE_CCSRC_FRONTEND_OPERATE_OPS_FRONT_INFER_FUNCTION_H_ +#include "abstract/abstract_value.h" +#include "abstract/primitive_infer_map.h" +namespace mindspore { +namespace abstract { +AbstractBasePtr InferImplTypeof(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplHasType(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplBroadcastGradientArgs(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplListMap(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplListReduce(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplTupleReversed(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplReduceShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplTupleDiv(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplTuple2Array(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplShapeMul(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplTupleEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplListEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplStopGradient(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplStringEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplStringConcat(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplDictLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplJ(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplFakeBprop(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); + +class RegisterFrontendPrimitiveEvalHelper { + public: + RegisterFrontendPrimitiveEvalHelper(const PrimitivePtr &primitive, const StandardPrimitiveEvalImpl &impl) { + const StandardPrimitiveImplReg impl_reg{impl, false}; + RegisterStandardPrimitiveImpl(primitive, impl_reg); + } + ~RegisterFrontendPrimitiveEvalHelper() = default; +}; + +#define REGISTER_FRONTENT_PRIMITIVE_EVAL_IMPL(name, primitive, impl) \ + static auto helper_##name = RegisterFrontendPrimitiveEvalHelper(primitive, impl) +} // namespace abstract +} // namespace mindspore + +#endif // MINDSPORE_CCSRC_FRONTEND_OPERATE_OPS_FRONT_INFER_FUNCTION_H_ diff --git a/mindspore/ccsrc/frontend/optimizer/irpass.cc b/mindspore/ccsrc/frontend/optimizer/irpass.cc index d1d29fcbae..b41c3081b4 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass.cc +++ b/mindspore/ccsrc/frontend/optimizer/irpass.cc @@ -95,10 +95,10 @@ OptimizeIRPassLib::OptimizeIRPassLib() { // Ref eliminate make_ref_eliminate_ = MakeSubstitution(std::make_shared(), "make_ref_eliminate", prim::kPrimMakeRef); - get_ref_param_eliminate_ = MakeSubstitution(std::make_shared(), "get_ref_param_eliminate", - {prim::kPrimGetRefValue, prim::kPrimGetRefOrigin}); + get_ref_param_eliminate_ = + MakeSubstitution(std::make_shared(), "get_ref_param_eliminate", {prim::kPrimGetRefValue}); get_make_ref_eliminate_ = MakeSubstitution(std::make_shared(), "get_make_ref_eliminate", - {prim::kPrimGetRefKey, prim::kPrimGetRefValue, prim::kPrimGetRefOrigin}); + {prim::kPrimGetRefKey, prim::kPrimGetRefValue}); replace_refkey_by_param_ = MakeSubstitution(std::make_shared(), "replace_refkey_by_param", IsValueNode, opt::FORCE_RENORM); diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.cc b/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.cc index 46cc91443b..3a0e6f6e14 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.cc +++ b/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.cc @@ -20,9 +20,6 @@ namespace mindspore { namespace opt { namespace irpass { AnfNodePtr ArithmeticSimplify::operator()(const OptimizerPtr &, const AnfNodePtr &node) { - if (MsContext::GetInstance()->execution_mode() == kPynativeMode) { - return nullptr; - } PatternNode x, y, z, xs; PConstant one_(node, false, 1); PConstant one_scalar_(node, false, 1, true); @@ -32,16 +29,21 @@ AnfNodePtr ArithmeticSimplify::operator()(const OptimizerPtr &, const AnfNodePtr PConstant const_2(node); PConstant any_const(node); - MATCH_REPLACE(node, x + zero_, x); // Add by zero - MATCH_REPLACE(node, x + zero_scalar_, x); // Add by zero - MATCH_REPLACE(node, PBinOperation(prim::kPrimScalarAdd, x, zero_scalar_, true), x); // Scalar Add by zero - MATCH_REPLACE_IF(node, x * one_, any_const.WithValueOf(x), !one_.CheckFunc(IsParam, node)); // Multiply by one - MATCH_REPLACE(node, PBinOperation(prim::kPrimScalarMul, x, one_scalar_, true), x); // Scalar Mul by one + if (MsContext::GetInstance()->execution_mode() != kPynativeMode) { + MATCH_REPLACE(node, x + zero_, x); // Add by zero + MATCH_REPLACE(node, x + zero_scalar_, x); // Add by zero + MATCH_REPLACE(node, PBinOperation(prim::kPrimScalarAdd, x, zero_scalar_, true), x); // Scalar Add by zero + MATCH_REPLACE_IF(node, x * one_, any_const.WithValueOf(x), !one_.CheckFunc(IsParam, node)); // Multiply by one + MATCH_REPLACE(node, PBinOperation(prim::kPrimScalarMul, x, one_scalar_, true), x); // Scalar Mul by one - // Scalar Mul by zero - MATCH_REPLACE(node, PBinOperation(prim::kPrimScalarMul, x, zero_scalar_, true), zero_scalar_.NewValue()); + // Scalar Mul by zero + MATCH_REPLACE(node, PBinOperation(prim::kPrimScalarMul, x, zero_scalar_, true), zero_scalar_.NewValue()); + } // Prim Eliminate (identity) MATCH_REPLACE(node, PPrimitive(prim::kPrimIdentity, x), x); + if (MsContext::GetInstance()->execution_mode() == kPynativeMode) { + return nullptr; + } // ConstantDuplicateMul auto const_dup_lambda = [&node, &x, &const_, &const_2]() -> AnfNodePtr { @@ -95,37 +97,37 @@ AnfNodePtr ArithmeticSimplify2::operator()(const OptimizerPtr &, const AnfNodePt // {prim::kPrimAddN, {prim::kPrimMakeTuple, {prim::kPrimMul, {prim::kPrimAllReduce, X}, Y}, Z}} -> // {prim::kPrimMul, {prim::kPrimAllReduce, {prim::kPrimAddN,{prim::kPrimMakeTuple, Z, X}}}, Y} AnfNodePtr AdjustAllReduceMulAdd::operator()(const OptimizerPtr &, const AnfNodePtr &node) { - Reset(); - // {prim::kPrimAddN, Zs} - if (!IsPrimitiveCNode(node, prim::kPrimAddN)) { - return nullptr; - } - auto addn = node->cast(); - if (addn->size() != 2) { - return nullptr; - } - AnfVisitor::Match(prim::kPrimMakeTuple, {IsNode, IsNode})(addn->input(1)); - if (x_ == nullptr || y_ == nullptr || z_ == nullptr || all_reduce_fg_ == nullptr) { - return nullptr; - } - auto addn_maketuple = addn->input(1); + PatternNode x, y, z; + auto all_reduce_pat = PPrimitive(prim::kPrimAllReduce, x); + auto mul_pat = PBinOperation(prim::kPrimMul, all_reduce_pat, y, true); + auto admktup_pat = PBinOperation(prim::kPrimMakeTuple, mul_pat, z, true); + auto addn_pat = PPrimitive(prim::kPrimAddN, admktup_pat); + auto adjust_lambda = [&node, &x, &y, &z, &addn_pat, &all_reduce_pat, &admktup_pat, &mul_pat, this]() -> AnfNodePtr { + auto fg = all_reduce_pat.GetFuncGraph(); + auto z_ = z.GetNode(node); + // If addn inputs cross the graph, make the inputs same as allreduce node. + if (z_->isa() && fg != z_->func_graph()) { + auto cnode_z = z_->cast(); + z_ = NewCNode(cnode_z->inputs(), fg); + } - auto fg = all_reduce_fg_; - // addn inputs cross the graph, make the inputs same as allreduce node. - if (z_->isa() && fg != z_->func_graph()) { - auto cnode_z = z_->cast(); - z_ = NewCNode(cnode_z->inputs(), fg); - } + auto addn_cnode = addn_pat.GetOriginalNode()->cast(); + auto addn_op_node = addn_cnode->input(0); + auto make_tuple_op_node = addn_cnode->input(1)->cast()->input(0); + auto all_reduce_prim = all_reduce_pat.GetOriginalNode()->cast()->input(0); + mul_cnode_ = mul_pat.GetOriginalNode(); + auto mul_prim = mul_cnode_->cast()->input(0); + auto addn_maketuple = admktup_pat.GetOriginalNode(); - auto addn_op_node = addn->input(0); - auto make_tuple_op_node = addn->input(1)->cast()->input(0); - - AnfNodePtr tuple = NewCNode({make_tuple_op_node, z_, x_}, fg); - AnfNodePtr add = NewCNode({addn_op_node, tuple}, fg); - AnfNodePtr all_reduce = NewCNode({all_reduce_, add}, fg); - AnfNodePtr mul = NewCNode({mul_, all_reduce, y_}, fg); - ProcessDependEdge(fg, addn_maketuple, all_reduce); - return mul; + AnfNodePtr tuple = NewCNode({make_tuple_op_node, z_, x.GetNode(node)}, fg); + AnfNodePtr add = NewCNode({addn_op_node, tuple}, fg); + AnfNodePtr all_reduce = NewCNode({all_reduce_prim, add}, fg); + AnfNodePtr mul = NewCNode({mul_prim, all_reduce, y.GetNode(node)}, fg); + ProcessDependEdge(fg, addn_maketuple, all_reduce); + return mul; + }; + MATCH_REPLACE_LAMBDA(node, addn_pat, adjust_lambda); + return nullptr; } void AdjustAllReduceMulAdd::ProcessDependEdge(const FuncGraphPtr &fg, const AnfNodePtr &addn_maketuple, @@ -146,48 +148,6 @@ void AdjustAllReduceMulAdd::ProcessDependEdge(const FuncGraphPtr &fg, const AnfN } } -void AdjustAllReduceMulAdd::Visit(const AnfNodePtr &node) { - if (level_ == 0) { - level_ = 1; - is_reduce_match_ = false; - // {prim::kPrimMul, {prim::kPrimAllReduce, X}, Y} - AnfVisitor::Match(prim::kPrimMul)(node); - level_ = 0; - if (is_reduce_match_) { - mul_ = node->cast()->input(0); - mul_cnode_ = node->cast(); - y_ = tmp_; - } else { - z_ = node; - } - } - - if (level_ == 1) { - // {prim::kPrimAllReduce, X} - if (IsPrimitiveCNode(node, prim::kPrimAllReduce)) { - auto cnode = node->cast(); - if (cnode->size() > 1) { - all_reduce_ = cnode->input(0); - x_ = cnode->input(1); - is_reduce_match_ = true; - all_reduce_fg_ = cnode->func_graph(); - } - } else { - tmp_ = node; - } - } -} - -void AdjustAllReduceMulAdd::Reset() { - level_ = 0; - is_reduce_match_ = false; - x_ = nullptr; - y_ = nullptr; - z_ = nullptr; - tmp_ = nullptr; - all_reduce_fg_ = nullptr; -} - } // namespace irpass } // namespace opt } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.h b/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.h index 699005f7bf..177a66fb09 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/arithmetic_simplify.h @@ -38,20 +38,14 @@ namespace irpass { // {prim::kPrimAddN, {prim::kPrimMakeTuple, {prim::kPrimMul, {prim::kPrimAllReduce, X}, Y}, Z}} -> // {prim::kPrimMul, {prim::kPrimAllReduce, {prim::kPrimAddN,{prim::kPrimMakeTuple, Z, X}}}, Y} -class AdjustAllReduceMulAdd : public AnfVisitor { +class AdjustAllReduceMulAdd : public OptimizerCaller { public: AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override; void ProcessDependEdge(const FuncGraphPtr &fg, const AnfNodePtr &addn_maketuple, const AnfNodePtr &new_node); - void Visit(const AnfNodePtr &node) override; - void Reset(); private: - int level_{0}; - bool is_reduce_match_{false}; - AnfNodePtr x_{nullptr}, y_{nullptr}, z_{nullptr}, tmp_{nullptr}; - AnfNodePtr all_reduce_{nullptr}, mul_{nullptr}, mul_cnode_{nullptr}; - FuncGraphPtr all_reduce_fg_{nullptr}; + AnfNodePtr mul_cnode_{nullptr}; }; class ArithmeticSimplify : public OptimizerCaller { diff --git a/mindspore/ccsrc/frontend/optimizer/irpass/ref_eliminate.h b/mindspore/ccsrc/frontend/optimizer/irpass/ref_eliminate.h index b7759daad4..fc859b213e 100644 --- a/mindspore/ccsrc/frontend/optimizer/irpass/ref_eliminate.h +++ b/mindspore/ccsrc/frontend/optimizer/irpass/ref_eliminate.h @@ -37,27 +37,23 @@ class MakeRefEliminater : public OptimizerCaller { }; // {prim::kPrimGetRefValue, Parameter} -> Parameter -// {prim::kPrimGetRefOrigin, Parameter} -> Parameter class GetRefParamEliminater : public OptimizerCaller { public: AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { PatternNode x; MATCH_REPLACE(node, PPrimitive(prim::kPrimGetRefValue, x), x); - MATCH_REPLACE(node, PPrimitive(prim::kPrimGetRefOrigin, x), x); return nullptr; } }; // {prim::kPrimGetRefKey, {prim::kPrimMakeRef, X, Y, Z}} -> X // {prim::kPrimGetRefValue, {prim::kPrimMakeRef, X, Y, Z}} -> Y -// {prim::kPrimGetRefOrigin, {prim::kPrimMakeRef, X, Y, Z}} -> Z class GetMakeRefEliminater : public OptimizerCaller { public: AnfNodePtr operator()(const OptimizerPtr &, const AnfNodePtr &node) override { PatternNode x, y, z; MATCH_REPLACE(node, PPrimitive(prim::kPrimGetRefKey, PPrimitive(prim::kPrimMakeRef, x, y, z)), x); MATCH_REPLACE(node, PPrimitive(prim::kPrimGetRefValue, PPrimitive(prim::kPrimMakeRef, x, y, z)), y); - MATCH_REPLACE(node, PPrimitive(prim::kPrimGetRefOrigin, PPrimitive(prim::kPrimMakeRef, x, y, z)), z); return nullptr; } diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h index 116d188c0e..c00e61b096 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/graph_costmodel.h @@ -197,6 +197,9 @@ class CostGraph { inputs_tensor_name_list_.push_back(inputs_tensor_name); } const std::vector> get_inputs_tensor_name_list() const { return inputs_tensor_name_list_; } + void set_inputs_tensor_name_list(const std::vector> &inputs_tensor_name_list) { + inputs_tensor_name_list_ = inputs_tensor_name_list; + } void add_tuple_getitem(const std::pair &tuple_getitem) { auto ret = tuple_getitem_list_.insert(tuple_getitem); if (ret.second == false) { diff --git a/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h b/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h index 8cd1370fb5..1759fabb03 100644 --- a/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h +++ b/mindspore/ccsrc/frontend/parallel/auto_parallel/operator_costmodel.h @@ -199,6 +199,8 @@ class SoftmaxCost : public OperatorCost { using SoftmaxCostPtr = std::shared_ptr; using TileCost = SoftmaxCost; using TileCostPtr = std::shared_ptr; +using ConcatCost = TileCost; +using ConcatCostPtr = std::shared_ptr; class TmpIdentityCost : public OperatorCost { public: diff --git a/mindspore/ccsrc/frontend/parallel/dynamic_creator.h b/mindspore/ccsrc/frontend/parallel/dynamic_creator.h index 88f5b67355..f5f5a05aed 100644 --- a/mindspore/ccsrc/frontend/parallel/dynamic_creator.h +++ b/mindspore/ccsrc/frontend/parallel/dynamic_creator.h @@ -136,6 +136,7 @@ REGISTER(EmbeddingLookupInfo); REGISTER(TileInfo); REGISTER(StridedSliceInfo); REGISTER(DropoutInfo); +REGISTER(ConcatInfo); } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/node_check.cc b/mindspore/ccsrc/frontend/parallel/node_check.cc index de29417a4d..a6e8f7ea2b 100644 --- a/mindspore/ccsrc/frontend/parallel/node_check.cc +++ b/mindspore/ccsrc/frontend/parallel/node_check.cc @@ -24,7 +24,6 @@ namespace mindspore { namespace parallel { const std::set BLACK_LIST = {TUPLE_GETITEM, - MAKE_TUPLE, J, LIST_GETITEM, ARRAY_GETITEM, diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.cc b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.cc new file mode 100644 index 0000000000..a38c468f57 --- /dev/null +++ b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.cc @@ -0,0 +1,268 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "frontend/parallel/ops_info/concat_info.h" + +#include +#include +#include +#include + +#include "frontend/parallel/device_matrix.h" +#include "frontend/parallel/strategy.h" +#include "frontend/parallel/tensor_layout/tensor_redistribution.h" +#include "pipeline/jit/resource.h" + +namespace mindspore { +namespace parallel { +Status ConcatInfo::GetAttrs() { + int axis = 0; + auto axis_iter = attrs_.find(AXIS); + if (axis_iter != attrs_.end()) { + MS_EXCEPTION_IF_NULL(axis_iter->second); + if (axis_iter->second->isa()) { + axis = axis_iter->second->cast()->value(); + } else { + MS_LOG(ERROR) << name_ << ": The value of axis is not int"; + return FAILED; + } + } else { + MS_LOG(ERROR) << name_ << ": Can not find the axis attr"; + return FAILED; + } + + if (inputs_shape_.empty()) { + MS_LOG(ERROR) << name_ << ": The inputs shape is empty"; + return FAILED; + } + int dim = SizeToInt(inputs_shape_[0].size()); + + if (axis < 0) { + axis = axis + dim; + } + + axis_ = SizeToInt(axis); + return SUCCESS; +} + +Status ConcatInfo::CheckStrategy(const StrategyPtr &strategy) { + MS_EXCEPTION_IF_NULL(strategy); + if (CheckStrategyValue(strategy, inputs_shape_, is_auto_parallel_) != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Invalid strategy"; + return FAILED; + } + + std::vector stra = strategy->GetInputDim(); + if (stra.empty()) { + MS_LOG(ERROR) << name_ << ": The strategy is empty"; + return FAILED; + } + + if (stra.size() != inputs_shape_.size()) { + MS_LOG(ERROR) << name_ << ": The size of strategy must be equal to the size of inputs shape"; + return FAILED; + } + + for (size_t i = 0; i < stra.size(); ++i) { + auto strategy_ele = stra[i]; + auto input_shape_ele = inputs_shape_[i]; + if (strategy_ele.size() != input_shape_ele.size()) { + MS_LOG(ERROR) << name_ << ": The size of strategy element must be equal to the size of input shape"; + return FAILED; + } + + if (axis_ >= strategy_ele.size()) { + MS_LOG(ERROR) << name_ << ": The axis is out of range, the axis is " << axis_; + return FAILED; + } + + if (strategy_ele[axis_] != 1) { + MS_LOG(ERROR) << name_ << ": The axis can not be split"; + return FAILED; + } + + for (size_t j = 0; j < strategy_ele.size(); ++j) { + if (strategy_ele[j] != stra[0][j]) { + MS_LOG(ERROR) << name_ << ": The strategy of each input tensor must be equal"; + return FAILED; + } + } + } + + return SUCCESS; +} + +Status ConcatInfo::InferDevMatrixShape() { + MS_EXCEPTION_IF_NULL(strategy_); + std::vector stra = strategy_->GetInputDim(); + if (stra.empty()) { + MS_LOG(ERROR) << name_ << "The strategy is empty"; + return FAILED; + } + + dev_matrix_shape_ = stra[0]; + return SUCCESS; +} + +Status ConcatInfo::InferTensorMap() { + TensorMap tensor_map; + if (inputs_shape_.empty()) { + MS_LOG(ERROR) << name_ << "The inputs shape is empty"; + return FAILED; + } + + // cannot use dev_matrix_shape_ replace inputs_shape_[0], because it may not be fully split in all devices. + int32_t size = SizeToInt(inputs_shape_[0].size()); + for (int i = 0; i < size; ++i) { + tensor_map.push_back(size - i - 1); + } + + for (size_t i = 0; i < inputs_shape_.size(); ++i) { + inputs_tensor_map_.push_back(tensor_map); + } + outputs_tensor_map_.push_back(tensor_map); + return SUCCESS; +} + +Status ConcatInfo::InferMirrorOps() { + mirror_ops_.clear(); + if (inputs_tensor_map_.empty()) { + MS_LOG(ERROR) << name_ << ": The inputs tensor map is empty"; + return FAILED; + } + + Shape input_tensor_map = inputs_tensor_map_[0]; + std::vector group; + if (CreateGroupByTensorMap(input_tensor_map, &group) != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Create group for input failed."; + return FAILED; + } + + if (group.empty()) { + MS_LOG(INFO) << name_ << ": The mirror group is empty."; + return SUCCESS; + } + + OperatorVector input_op; + input_op = CreateMirrorOps(group[0].name(), group[0].GetDevNum()); + for (size_t i = 0; i < inputs_shape_.size(); ++i) { + mirror_ops_.push_back(input_op); + } + + return SUCCESS; +} + +Status ConcatInfo::InferTensorInfo() { + if (inputs_shape_.empty() || outputs_shape_.empty() || inputs_tensor_map_.empty() || outputs_tensor_map_.empty()) { + MS_LOG(ERROR) << name_ << ": Invalid args"; + return FAILED; + } + + TensorLayout input_layout, output_layout; + for (size_t i = 0; i < inputs_shape_.size(); ++i) { + // infer tensor layout + if (input_layout.InitFromVector(dev_matrix_shape_, inputs_tensor_map_[i], inputs_shape_[i]) != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Infer input tensor layout failed."; + return FAILED; + } + TensorInfo input_tensor_info(input_layout); + inputs_tensor_info_.push_back(input_tensor_info); + } + + if (output_layout.InitFromVector(dev_matrix_shape_, outputs_tensor_map_[0], outputs_shape_[0]) != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Infer output tensor layout failed."; + return FAILED; + } + TensorInfo output_tensor_info(output_layout); + outputs_tensor_info_.push_back(output_tensor_info); + return SUCCESS; +} + +void ConcatInfo::ReComputeBatchSplitFlagList() { + for (size_t i = 0; i < inputs_shape_.size(); i++) { + split_flag_list_[i] = true; + } +} + +Status ConcatInfo::SetCostUnderStrategy(const StrategyPtr &strategy) { + if (SetCostUnderStrategyBase(strategy) != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Set cost under strategy failed."; + return FAILED; + } + + return SUCCESS; +} + +Status ConcatInfo::GenerateStrategies(int32_t stage_id) { + if (InferAttrs() != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Infer attrs failed"; + return FAILED; + } + if (inputs_shape_.empty()) { + MS_LOG(ERROR) << name_ << ": The inputs shape is empty"; + return FAILED; + } + Shape input_split; + for (size_t i = 0; i < inputs_shape_[0].size(); ++i) { + if (i == axis_) { + input_split.push_back(0); + } else { + input_split.push_back(1); + } + } + Shapes splittable_inputs; + for (size_t i = 0; i < inputs_shape_.size(); ++i) { + splittable_inputs.push_back(input_split); + } + + std::vector sp_vector; + is_auto_parallel_ = true; + if (GenerateStrategiesWithBroadcast(stage_id, inputs_shape_, splittable_inputs, &sp_vector) != SUCCESS) { + return FAILED; + } + + size_t success = 0; + for (auto &sp : sp_vector) { + PrintStrategy(sp); + if (SetCostUnderStrategy(sp) == SUCCESS) { + success++; + MS_LOG(INFO) << name_ << ": Successfully generated " << success << " strategy."; + PrintStrategy(sp); + } + } + return SUCCESS; +} + +Status ConcatInfo::Init(const StrategyPtr &strategy) { + if (InitWithAutoRepeatCalc(strategy) != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Init failed."; + return FAILED; + } + MS_LOG(INFO) << name_ << ": Init success."; + return SUCCESS; +} + +Status ConcatInfo::InitForCostModel(const StrategyPtr &strategy) { + if (InitForCostModelWithAutoRepeatCalc(strategy) != SUCCESS) { + MS_LOG(ERROR) << name_ << ": Init for cost model failed."; + return FAILED; + } + + MS_LOG(INFO) << name_ << ": Init for cost model success."; + return SUCCESS; +} +} // namespace parallel +} // namespace mindspore diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.h b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.h new file mode 100644 index 0000000000..183a216660 --- /dev/null +++ b/mindspore/ccsrc/frontend/parallel/ops_info/concat_info.h @@ -0,0 +1,62 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_CONCAT_INFO_H_ +#define MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_CONCAT_INFO_H_ + +#include +#include +#include +#include + +#include "ir/value.h" +#include "frontend/parallel/auto_parallel/operator_costmodel.h" +#include "frontend/parallel/ops_info/operator_info.h" +#include "frontend/parallel/strategy.h" + +namespace mindspore { +namespace parallel { +class ConcatInfo : public OperatorInfo { + public: + ConcatInfo(const std::string &operator_name, const Shapes &inputs_shape, const Shapes &outputs_shape, + const PrimitiveAttrs &attrs) + : OperatorInfo(operator_name, inputs_shape, outputs_shape, attrs, std::make_shared(false)) {} + ~ConcatInfo() override = default; + + Status Init(const StrategyPtr &strategy) override; + Status InitForCostModel(const StrategyPtr &strategy) override; + Status GenerateStrategies(int32_t) override; + Status SetCostUnderStrategy(const StrategyPtr &) override; + void ReComputeBatchSplitFlagList() override; + + protected: + Status GetAttrs() override; + Status CheckStrategy(const StrategyPtr &strategy) override; + Status InferMirrorOps() override; + Status InferForwardCommunication() override { return SUCCESS; } + Status InferTensorInfo() override; + Status InferDevMatrixShape() override; + Status InferTensorMap() override; + + private: + size_t axis_ = 0; +}; + +using ConcatInfoPtr = std::shared_ptr; +} // namespace parallel +} // namespace mindspore + +#endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_CONCAT_INFO_H_ diff --git a/mindspore/ccsrc/frontend/parallel/ops_info/ops_info_head_files.h b/mindspore/ccsrc/frontend/parallel/ops_info/ops_info_head_files.h index de9481c4d5..a48e04b6dd 100644 --- a/mindspore/ccsrc/frontend/parallel/ops_info/ops_info_head_files.h +++ b/mindspore/ccsrc/frontend/parallel/ops_info/ops_info_head_files.h @@ -39,5 +39,6 @@ #include "frontend/parallel/ops_info/gather_v2_p_info.h" #include "frontend/parallel/ops_info/tile_info.h" #include "frontend/parallel/ops_info/strided_slice_info.h" +#include "frontend/parallel/ops_info/concat_info.h" #endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_HEAD_FILES_H_ diff --git a/mindspore/ccsrc/frontend/parallel/ps/common.h b/mindspore/ccsrc/frontend/parallel/ps/common.h index b0d557dc1f..a021dff1ad 100644 --- a/mindspore/ccsrc/frontend/parallel/ps/common.h +++ b/mindspore/ccsrc/frontend/parallel/ps/common.h @@ -56,9 +56,11 @@ constexpr char kMomentum[] = "momentum"; constexpr char kApplyMomentum[] = "ApplyMomentum"; constexpr char kSparseAdam[] = "Adam"; +constexpr char kSparseLazyAdam[] = "LazyAdam"; constexpr char kSparseFtrl[] = "Ftrl"; constexpr char kApplyMomentumOp[] = "Momentum"; constexpr char kSparseAdamOp[] = "Adam"; +constexpr char kSparseLazyAdamOp[] = "LazyAdam"; constexpr char kSparseFtrlOp[] = "FTRL"; constexpr int kInitWeightsCmd = 10; diff --git a/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.cc b/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.cc index 5f25b79c23..5801b241e4 100644 --- a/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.cc +++ b/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.cc @@ -126,6 +126,15 @@ MomentumOptimInfo::MomentumOptimInfo(const AddressPtr &weight, const AddressPtr inputs_.push_back(momentum); } +void MomentumOptimInfo::Update(const Values &values, const Lengths &lens) { + size_t lr_offset = 0; + float *lr = values.data() + lr_offset; + auto ret = memcpy_s(inputs_[2]->addr, sizeof(float), lr, sizeof(float)); + if (ret != 0) { + MS_LOG(EXCEPTION) << "memcpy_s error, errorno(" << ret << ")"; + } +} + const AddressPtr &MomentumOptimInfo::gradient() { return inputs_[3]; } const AddressPtr &MomentumOptimInfo::indices() { return inputs_[3]; } diff --git a/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.h b/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.h index dc567e023c..f59d8ad6c1 100644 --- a/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.h +++ b/mindspore/ccsrc/frontend/parallel/ps/optimizer_info.h @@ -82,6 +82,7 @@ class MomentumOptimInfo : public DenseOptimInfo { const AddressPtr &gradient, const AddressPtr &momentum); ~MomentumOptimInfo() override = default; + void Update(const Values &values, const Lengths &lens) override; const AddressPtr &gradient(); const AddressPtr &indices(); size_t grad_index() override; diff --git a/mindspore/ccsrc/frontend/parallel/ps/parameter_server.h b/mindspore/ccsrc/frontend/parallel/ps/parameter_server.h index 6eedbd76b3..5a9c4af38a 100644 --- a/mindspore/ccsrc/frontend/parallel/ps/parameter_server.h +++ b/mindspore/ccsrc/frontend/parallel/ps/parameter_server.h @@ -42,6 +42,7 @@ #include "backend/kernel_compiler/kernel.h" #include "backend/kernel_compiler/cpu/cpu_kernel_factory.h" #include "backend/kernel_compiler/cpu/ps/pserver_kernel.h" +#include "backend/kernel_compiler/cpu/ps/sparse_apply_adam_ps_kernel.h" #include "backend/kernel_compiler/cpu/ps/sparse_apply_lazy_adam_ps_kernel.h" #include "backend/kernel_compiler/cpu/ps/sparse_apply_ftrl_ps_kernel.h" #include "backend/kernel_compiler/cpu/ps/apply_momentum_ps_kernel.h" @@ -374,6 +375,11 @@ void ParameterServer::InitOptimInputsShape(const Keys &keys, const Values &va const CNodePtr cnode = GetCNode(optim_op_name); MS_EXCEPTION_IF_NULL(cnode); if (optim_name == kSparseAdam) { + std::shared_ptr optimizer = + std::make_shared(rank_id_, pserver_num_); + optimizer->InitKernel(cnode, optim_inputs_shape_[key]); + optimizers_[key] = optimizer; + } else if (optim_name == kSparseLazyAdam) { std::shared_ptr optimizer = std::make_shared(rank_id_, pserver_num_); optimizer->InitKernel(cnode, optim_inputs_shape_[key]); diff --git a/mindspore/ccsrc/frontend/parallel/ps/util.cc b/mindspore/ccsrc/frontend/parallel/ps/util.cc index 1bda9c1323..c951006a8c 100644 --- a/mindspore/ccsrc/frontend/parallel/ps/util.cc +++ b/mindspore/ccsrc/frontend/parallel/ps/util.cc @@ -25,19 +25,22 @@ namespace ps { std::unordered_map Util::optimizer_to_ids{ {kApplyMomentum, 0}, {kSparseAdam, 1}, - {kSparseFtrl, 2}, + {kSparseLazyAdam, 2}, + {kSparseFtrl, 3}, }; std::unordered_map Util::id_to_optimizers{ {0, kApplyMomentum}, {1, kSparseAdam}, - {2, kSparseFtrl}, + {2, kSparseLazyAdam}, + {3, kSparseFtrl}, }; std::unordered_map Util::id_to_optimizer_nodes{ {0, kApplyMomentumOp}, {1, kSparseAdamOp}, - {2, kSparseFtrlOp}, + {2, kSparseLazyAdamOp}, + {3, kSparseFtrlOp}, }; bool Util::IsParamServerMode() { return IsRoleOfWorker() || IsRoleOfPServer() || IsRoleOfScheduler(); } diff --git a/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc b/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc index 33d2bbc609..08ef6fad83 100644 --- a/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc +++ b/mindspore/ccsrc/frontend/parallel/step_auto_parallel.cc @@ -118,6 +118,9 @@ bool StepAutoParallel(const FuncGraphPtr &root, const opt::OptimizerPtr &) { std::vector ExtractInputParameterByNode(const CNodePtr &node) { std::vector is_parameter; std::vector node_inputs{node->inputs()}; + if ((node_inputs.size() == 2) && AnfNodeIsPrimitive(node_inputs[1], MAKE_TUPLE)) { + node_inputs = node_inputs[1]->cast()->inputs(); + } for (size_t i = 1; i < node_inputs.size(); ++i) { auto input = node_inputs[i]; @@ -192,6 +195,10 @@ std::vector ExtractInputTypeLengthByNode(const CNodePtr &node) { std::vector inputs_type_len; std::vector node_inputs{node->inputs()}; + if ((node_inputs.size() == 2) && AnfNodeIsPrimitive(node_inputs[1], MAKE_TUPLE)) { + node_inputs = node_inputs[1]->cast()->inputs(); + } + // extract input element length for (auto &input : node_inputs) { if (IsValueNode(input)) { @@ -255,7 +262,7 @@ bool IsSplittableOperator(const std::string &op_name) { FLOORDIV, L2_NORMALIZE, TENSOR_ADD, MAXPOOL, MAXPOOLV2, VIRTUAL_DATA_SET, RELU, ONEHOT, DROPOUT_DO_MASK, REDUCE_MAX, REDUCE_MIN, ARGMAXWITHVALUE, ARGMINWITHVALUE, REDUCE_SUM, CONV2D, FUSE_BATCH_NORM, POOLING, MAX_POOL_WITH_ARGMAX, SIMPLE_MEAN, FLATTEN, BATCH_NORM, LAYER_NORM, BIAS_ADD, ASSIGN_SUB, COS, ACOS, EXP, - LOG, REDUCE_MEAN, REAL_DIV, SIGMOID, POW, MAXIMUM, MINIMUM, EQUAL, NOT_EQUAL, LOGICALNOT, GATHERV2, SQRT, + LOG, REDUCE_MEAN, REAL_DIV, SIGMOID, POW, MAXIMUM, MINIMUM, EQUAL, NOT_EQUAL, LOGICALNOT, GATHERV2, SQRT, CONCAT, STRIDEDSLICE, GET_NEXT, CAST, NEG, SQUARE, BATCH_MATMUL, EXPAND_DIMS, SQUEEZE, SPARSE_GATHERV2, TILE, DROPOUT, SOFTMAX_CROSS_ENTROPY_WITH_LOGITS, SIGMOID_CROSS_ENTROPY_WITH_LOGITS, SPARSE_SOFTMAX_CROSS_ENTROPY_WITH_LOGITS}; // clang-format on @@ -275,7 +282,7 @@ bool IsAutoParallelCareNode(const CNodePtr &cnode) { return false; } bool bool_result = IsParallelCareNode(cnode) && !IsSplittableOperator(prim->name()); - if (bool_result) { + if (bool_result && (prim->name() != MAKE_TUPLE)) { MS_LOG(EXCEPTION) << "Should implementing OperatorInfo for: " << prim->name(); } else if (prim->name() == CAST) { if (cnode->fullname_with_scope().find(OPTIMIZER_SUB_STRING) != std::string::npos) { @@ -520,6 +527,10 @@ Status ConstructCostGraphNodesByUniqueIdTC(const std::vector &all_no MS_LOG(EXCEPTION) << "The OperatorInfo: " << current_op_ptr->name() << " does not match the Prim: " << prim->name(); } + + // Needed by rec_parser + ModifyInputsTensorNameListIfOperatorInfoCreated(current_op_ptr->name(), cnode->UniqueId()); + cnode->set_user_data(current_op_ptr); MS_LOG(INFO) << "The CNode with UniqueId: " << cnode->UniqueId() << " and UniqueIdThroughCopy: " << cnode->UniqueIdThroughCopy() @@ -1117,6 +1128,27 @@ CNodePtr GetInternalOperatorInfo(const CNodePtr &cnode, const ValueNodePtr &prim return nullptr; } +void ModifyInputsTensorNameListIfOperatorInfoCreated(const std::string &name, const std::string &uniqueid) { + size_t iter_ops = 0; + for (auto op : entire_costgraph->GetOperators()) { + if (op->name() == name) { + break; + } + iter_ops = iter_ops + 1; + } + + std::vector> input_tensor_names = entire_costgraph->get_inputs_tensor_name_list(); + for (size_t i = 0; i < input_tensor_names.size(); i++) { + for (size_t j = 0; j < input_tensor_names[i].size(); j++) { + if (input_tensor_names[i][j] == uniqueid) { + input_tensor_names[i][j] = input_tensor_names[iter_ops][0]; + } + } + } + + entire_costgraph->set_inputs_tensor_name_list(input_tensor_names); +} + Status ParallelStrategyRecSearch(const std::vector &all_nodes, const FuncGraphPtr &root) { if (CostModelContext::GetInstance()->is_multi_subgraphs()) { if (ConstructCostGraphNodesByUniqueIdTC(all_nodes, root) == SUCCESS) { diff --git a/mindspore/ccsrc/frontend/parallel/step_auto_parallel.h b/mindspore/ccsrc/frontend/parallel/step_auto_parallel.h index f87d49b736..59eb50c33a 100644 --- a/mindspore/ccsrc/frontend/parallel/step_auto_parallel.h +++ b/mindspore/ccsrc/frontend/parallel/step_auto_parallel.h @@ -59,6 +59,8 @@ std::vector> RecInputTensorNames(const std::map> input_tensor_names); CNodePtr GetInternalOperatorInfo(const CNodePtr &cnode, const ValueNodePtr &prim_anf_node); + +void ModifyInputsTensorNameListIfOperatorInfoCreated(const std::string &name, const std::string &uniqueid); } // namespace parallel } // namespace mindspore #endif // PARALLEL_STEP_AUTO_PARALLEL_H_ diff --git a/mindspore/ccsrc/frontend/parallel/step_parallel.cc b/mindspore/ccsrc/frontend/parallel/step_parallel.cc index f8ec0d3288..97aa8e931c 100644 --- a/mindspore/ccsrc/frontend/parallel/step_parallel.cc +++ b/mindspore/ccsrc/frontend/parallel/step_parallel.cc @@ -267,6 +267,33 @@ TensorLayout GetTensorInLayout(const CNodePtr &middle_node, const PrimitivePtr & return tensorinfo_in.tensor_layout(); } +bool AnfNodeIsPrimitive(const AnfNodePtr &anf_node, const std::string &prim_name) { + MS_EXCEPTION_IF_NULL(anf_node); + auto cnode = anf_node->cast(); + if ((cnode == nullptr) || !IsValueNode(cnode->input(0))) { + return false; + } + + auto value_node = cnode->input(0)->cast(); + auto prim = GetValueNode(value_node); + MS_EXCEPTION_IF_NULL(prim); + if (prim->name() == prim_name) { + return true; + } + return false; +} + +std::string GetPrimName(const CNodePtr &node) { + MS_EXCEPTION_IF_NULL(node); + if (!IsValueNode(node->input(0))) { + MS_LOG(EXCEPTION) << "The node is not a primitive"; + } + auto value_node = node->input(0)->cast(); + auto prim = GetValueNode(value_node); + MS_EXCEPTION_IF_NULL(prim); + return prim->name(); +} + OperatorInfoPtr GetDistributeOperator(const CNodePtr &node) { MS_EXCEPTION_IF_NULL(node); if (!IsParallelCareNode(node)) { @@ -274,7 +301,7 @@ OperatorInfoPtr GetDistributeOperator(const CNodePtr &node) { } OperatorInfoPtr distribute_operator = node->user_data(); if (distribute_operator == nullptr) { - MS_LOG(EXCEPTION) << "GetDistributeOperator:distribute_operator is nullptr"; + MS_LOG(EXCEPTION) << "Distribute operator is nullptr, the prim is " << GetPrimName(node); } return distribute_operator; } @@ -423,6 +450,11 @@ void StepRedistribution(const CNodePtr &node, const OperatorInfoPtr &distribute_ MS_EXCEPTION_IF_NULL(manager); AnfNodeIndexSet node_set = manager->node_users()[node]; CNodePtr insert_node_new; + + if (AnfNodeIsPrimitive(node, MAKE_TUPLE)) { + MS_LOG(INFO) << "No need to insert redistribution op betweend make_tuple node and the next node"; + return; + } if (IsValueNode(node->input(0))) { auto current_value = node->input(0)->cast(); MS_EXCEPTION_IF_NULL(current_value); @@ -875,9 +907,15 @@ void InsertMirrorOps(const MirrorOps &mirror_ops, const CNodePtr &node) { MS_EXCEPTION_IF_NULL(func_graph); FuncGraphManagerPtr manager = func_graph->manager(); MS_EXCEPTION_IF_NULL(manager); + + if ((node->inputs().size() == 2) && AnfNodeIsPrimitive(node->input(1), MAKE_TUPLE)) { + MS_LOG(INFO) << "The mirror for " << GetPrimName(node) << " has handle by make_tuple node"; + return; + } + if (mirror_ops.size() != node_size - 1) { - MS_LOG(EXCEPTION) << "Failure:Mirrorops's size is wrong! mirror_ops size is " << mirror_ops.size() - << ", node_size is " << node_size; + MS_LOG(EXCEPTION) << "Mirrorops's size is wrong! mirror_ops size is " << mirror_ops.size() << ", node_size is " + << node_size - 1; } for (size_t index = 1; index < node_size; ++index) { OperatorVector backward_op = mirror_ops[index - 1]; @@ -993,7 +1031,7 @@ OperatorInfoPtr OperatorInstance(const PrimitivePtr &prim, const PrimitiveAttrs const std::vector &shape_list) { MS_EXCEPTION_IF_NULL(prim); OperatorInfoPtr operator_ = OperatorInstanceByName(prim->name(), attrs, shape_list); - if (operator_ == nullptr) { + if ((operator_ == nullptr) && (prim->name() != MAKE_TUPLE)) { MS_LOG(INFO) << "Creat " << prim->name() << " failed, use batch parallel"; operator_ = OperatorInstanceByName(BATCH_PARALLEL, attrs, shape_list); MS_EXCEPTION_IF_NULL(operator_); @@ -1177,7 +1215,12 @@ std::vector ExtractShape(const CNodePtr &node) { continue; } if (input_shapes.size() != 1) { - MS_LOG(EXCEPTION) << "ExtractShape:Get input shape failed"; + if (inputs_size == 2) { // like concat + shape_inputs = input_shapes; + break; + } else { + MS_LOG(EXCEPTION) << "ExtractShape: Get input shape failed"; + } } shape_inputs.push_back(input_shapes[0]); } @@ -1269,8 +1312,8 @@ void SetParallelShape(const AnfNodePtr ¶meter, const std::pairinputs_tensor_info()[IntToSize(res.second - 1)]; Shape slice_shape = tensorinfo_in.slice_shape(); - MS_LOG(DEBUG) << "SetParallelShape slice_shape " << parameter->ToString() << " shape " - << MakeValue(slice_shape)->ToString(); + MS_LOG(INFO) << "SetParallelShape slice_shape " << parameter->ToString() << " shape " + << MakeValue(slice_shape)->ToString() << ", op name is " << distribute_operator->name(); std::shared_ptr parallel_shape = std::make_shared(slice_shape); MS_EXCEPTION_IF_NULL(parallel_shape); // Don't modify it in-place as the pointer of this AbstractValue may used as cache key in StaticAnalysis. @@ -1450,6 +1493,9 @@ void ExtractInformation(const std::vector &all_nodes) { SetVirtualDatasetStrategy(cnode); ValueNodePtr prim_anf_node = cnode->input(0)->cast(); PrimitivePtr prim = GetValueNode(prim_anf_node); + if (prim->name() == MAKE_TUPLE) { + continue; + } auto attrs = prim->attrs(); MS_LOG(INFO) << "extract information: node: " << node->ToString() << " prim " << prim->name(); if (IsParallelCareNode(cnode)) { @@ -2045,13 +2091,13 @@ void ParallelCommunication(const FuncGraphPtr &root, const std::vectorisa()) { auto cnode = node->cast(); - if (!IsValueNode(cnode->input(0))) { + // the make_tuple is parallel care node, but it may have not operator info + if (!IsParallelCareNode(cnode) || !cnode->has_user_data()) { continue; } + OperatorInfoPtr distribute_operator = GetDistributeOperator(cnode); - if (distribute_operator == nullptr) { - continue; - } + MS_EXCEPTION_IF_NULL(distribute_operator); // insert forward ops InsertForwardOps(distribute_operator, cnode); @@ -2074,13 +2120,12 @@ void ParallelCommunication(const FuncGraphPtr &root, const std::vectorisa()) { auto cnode = node->cast(); - if (!IsValueNode(cnode->input(0))) { + if (!IsParallelCareNode(cnode) || !cnode->has_user_data()) { continue; } + OperatorInfoPtr distribute_operator = GetDistributeOperator(cnode); - if (distribute_operator == nullptr) { - continue; - } + MS_EXCEPTION_IF_NULL(distribute_operator); // StepReplace StepReplace(distribute_operator, cnode); } @@ -2330,6 +2375,44 @@ Status ParallelInit() { return SUCCESS; } +void HandleForwardMakeTuple(const std::vector &all_nodes) { + for (auto &node : all_nodes) { + if (!AnfNodeIsPrimitive(node, MAKE_TUPLE)) { + continue; + } + + auto cnode = node->cast(); + MS_EXCEPTION_IF_NULL(cnode); + if (!cnode->in_forward_flag()) { + continue; + } + + FuncGraphManagerPtr manager = cnode->func_graph()->manager(); + MS_EXCEPTION_IF_NULL(manager); + auto make_tuple_user = manager->node_users()[cnode]; + if (make_tuple_user.size() != 1) { + MS_LOG(EXCEPTION) << "Now the make_tuple's user must be 1, but got " << make_tuple_user.size(); + } + CNodePtr make_tuple_next_cnode = make_tuple_user.pop().first->cast(); + MS_EXCEPTION_IF_NULL(make_tuple_next_cnode); + + std::string make_tuple_user_prim_name = GetPrimName(make_tuple_next_cnode); + if (!IsParallelCareNode(make_tuple_next_cnode)) { + MS_LOG(INFO) << "The make_tuple's user is " << make_tuple_user_prim_name << ", no need to set operator info"; + continue; + } + if (make_tuple_next_cnode->inputs().size() != 2) { + MS_LOG(EXCEPTION) << "Now the make_tuple's user only support 1 input, but got " + << make_tuple_next_cnode->inputs().size() - 1; + } + + MS_LOG(INFO) << "Set the make_tuple's operator info, and the op name is " << make_tuple_user_prim_name; + OperatorInfoPtr op_info = GetDistributeOperator(make_tuple_next_cnode); + MS_EXCEPTION_IF_NULL(op_info); + cnode->set_user_data(op_info); + } +} + bool StepParallel(const FuncGraphPtr &root, const opt::OptimizerPtr &optimizer) { MS_EXCEPTION_IF_NULL(root); MS_EXCEPTION_IF_NULL(optimizer); @@ -2383,6 +2466,9 @@ bool StepParallel(const FuncGraphPtr &root, const opt::OptimizerPtr &optimizer) ExtractInformation(all_nodes); ReshapeInit(all_nodes); } + + HandleForwardMakeTuple(all_nodes); + // save strategy as checkpoint for multi-train if (StrategyCheckpoint::GetInstance().SaveCheckPointOn()) { CheckpointStrategy(root); diff --git a/mindspore/ccsrc/frontend/parallel/step_parallel.h b/mindspore/ccsrc/frontend/parallel/step_parallel.h index 4e142e4aee..537b43a2f1 100644 --- a/mindspore/ccsrc/frontend/parallel/step_parallel.h +++ b/mindspore/ccsrc/frontend/parallel/step_parallel.h @@ -149,6 +149,8 @@ Status ParallelInit(); std::vector ExtractInputsTensorName(const CNodePtr &node); std::set ForwardGraph(const FuncGraphPtr &root); + +bool AnfNodeIsPrimitive(const AnfNodePtr &anf_node, const std::string &prim_name); } // namespace parallel } // namespace mindspore diff --git a/mindspore/ccsrc/gvar/CMakeLists.txt b/mindspore/ccsrc/gvar/CMakeLists.txt deleted file mode 100644 index 3ee9109832..0000000000 --- a/mindspore/ccsrc/gvar/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -file(GLOB_RECURSE MS_GVAR_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cc) -set_property(SOURCE ${MS_GVAR_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_COMMON) -add_library(mindspore_gvar SHARED ${MS_GVAR_SRC_LIST}) -if (APPLE) - set_target_properties(mindspore_gvar PROPERTIES MACOSX_RPATH ON) -endif () diff --git a/mindspore/ccsrc/minddata/dataset/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/CMakeLists.txt index 81032180b6..ab950b32bb 100644 --- a/mindspore/ccsrc/minddata/dataset/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/CMakeLists.txt @@ -62,12 +62,15 @@ add_subdirectory(text) add_dependencies(utils core) add_dependencies(kernels-image core) add_dependencies(kernels-data core) +add_dependencies(kernels-soft-dvpp-image core soft-dvpp-utils) add_dependencies(kernels core) add_dependencies(engine-datasetops-source core) add_dependencies(engine-datasetops-source-sampler core) add_dependencies(engine-datasetops core) add_dependencies(engine-datasetops-mapop core) add_dependencies(engine-opt core) +add_dependencies(engine-cache-client core) +add_dependencies(engine-cache-server core) add_dependencies(engine-perf core) add_dependencies(engine-gnn core) add_dependencies(engine core) @@ -88,6 +91,8 @@ set(submodules $ $ $ + $ + $ $ $ $ @@ -126,7 +131,7 @@ endif() ###################################################################### ################# Link with external libraries ######################## -target_link_libraries(_c_dataengine PRIVATE mindspore mindspore_gvar) +target_link_libraries(_c_dataengine PRIVATE mindspore) if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") if (ENABLE_PYTHON) target_link_libraries(_c_dataengine PRIVATE mindspore::pybind11_module ${PYTHON_LIBRARIES} mindspore::protobuf ${SECUREC_LIBRARY}) @@ -141,7 +146,7 @@ else() target_link_libraries(_c_dataengine PRIVATE -ldl mindspore::protobuf ${SECUREC_LIBRARY}) endif() endif() -target_link_libraries(_c_dataengine PUBLIC mindspore::jpeg_turbo mindspore::opencv_core mindspore::opencv_imgcodecs +target_link_libraries(_c_dataengine PUBLIC mindspore::jpeg_turbo mindspore::turbojpeg mindspore::opencv_core mindspore::opencv_imgcodecs mindspore::opencv_imgproc mindspore::tinyxml2 mindspore::sentencepiece mindspore::sentencepiece_train ${ICU_LIB}) if (ENABLE_GPUQUE) target_link_libraries(_c_dataengine PRIVATE gpu_queue diff --git a/mindspore/ccsrc/minddata/dataset/api/datasets.cc b/mindspore/ccsrc/minddata/dataset/api/datasets.cc index 0e6090f128..f0d042d9ce 100644 --- a/mindspore/ccsrc/minddata/dataset/api/datasets.cc +++ b/mindspore/ccsrc/minddata/dataset/api/datasets.cc @@ -61,11 +61,19 @@ namespace api { } while (false) // Function to create the iterator, which will build and launch the execution tree. -std::shared_ptr Dataset::CreateIterator() { +std::shared_ptr Dataset::CreateIterator(std::vector columns) { std::shared_ptr iter; try { + auto ds = shared_from_this(); + + // The specified columns will be selected from the dataset and passed down the pipeline + // in the order specified, other columns will be discarded. + if (!columns.empty()) { + ds = ds->Project(columns); + } + iter = std::make_shared(); - Status rc = iter->BuildAndLaunchTree(shared_from_this()); + Status rc = iter->BuildAndLaunchTree(ds); if (rc.IsError()) { MS_LOG(ERROR) << "CreateIterator failed." << rc; return nullptr; @@ -629,13 +637,13 @@ bool VOCDataset::ValidateParams() { } Path imagesets_file = dir / "ImageSets" / "Segmentation" / mode_ + ".txt"; if (!imagesets_file.Exists()) { - MS_LOG(ERROR) << "[Segmentation] imagesets_file is invalid or not exist"; + MS_LOG(ERROR) << "Invalid mode: " << mode_ << ", file \"" << imagesets_file << "\" is not exists!"; return false; } } else if (task_ == "Detection") { Path imagesets_file = dir / "ImageSets" / "Main" / mode_ + ".txt"; if (!imagesets_file.Exists()) { - MS_LOG(ERROR) << "[Detection] imagesets_file is invalid or not exist."; + MS_LOG(ERROR) << "Invalid mode: " << mode_ << ", file \"" << imagesets_file << "\" is not exists!"; return false; } } else { @@ -655,18 +663,33 @@ std::vector> VOCDataset::Build() { sampler_ = CreateDefaultSampler(); } - std::shared_ptr builder = std::make_shared(); - (void)builder->SetDir(dataset_dir_); - (void)builder->SetTask(task_); - (void)builder->SetMode(mode_); - (void)builder->SetNumWorkers(num_workers_); - (void)builder->SetSampler(std::move(sampler_->Build())); - (void)builder->SetDecode(decode_); - (void)builder->SetClassIndex(class_index_); + auto schema = std::make_unique(); + VOCOp::TaskType task_type_; - std::shared_ptr op; - RETURN_EMPTY_IF_ERROR(builder->Build(&op)); - node_ops.push_back(op); + if (task_ == "Segmentation") { + task_type_ = VOCOp::TaskType::Segmentation; + RETURN_EMPTY_IF_ERROR(schema->AddColumn( + ColDescriptor(std::string(kColumnImage), DataType(DataType::DE_UINT8), TensorImpl::kFlexible, 1))); + RETURN_EMPTY_IF_ERROR(schema->AddColumn( + ColDescriptor(std::string(kColumnTarget), DataType(DataType::DE_UINT8), TensorImpl::kFlexible, 1))); + } else if (task_ == "Detection") { + task_type_ = VOCOp::TaskType::Detection; + RETURN_EMPTY_IF_ERROR(schema->AddColumn( + ColDescriptor(std::string(kColumnImage), DataType(DataType::DE_UINT8), TensorImpl::kFlexible, 1))); + RETURN_EMPTY_IF_ERROR(schema->AddColumn( + ColDescriptor(std::string(kColumnBbox), DataType(DataType::DE_FLOAT32), TensorImpl::kFlexible, 1))); + RETURN_EMPTY_IF_ERROR(schema->AddColumn( + ColDescriptor(std::string(kColumnLabel), DataType(DataType::DE_UINT32), TensorImpl::kFlexible, 1))); + RETURN_EMPTY_IF_ERROR(schema->AddColumn( + ColDescriptor(std::string(kColumnDifficult), DataType(DataType::DE_UINT32), TensorImpl::kFlexible, 1))); + RETURN_EMPTY_IF_ERROR(schema->AddColumn( + ColDescriptor(std::string(kColumnTruncate), DataType(DataType::DE_UINT32), TensorImpl::kFlexible, 1))); + } + + std::shared_ptr voc_op; + voc_op = std::make_shared(task_type_, mode_, dataset_dir_, class_index_, num_workers_, rows_per_buffer_, + connector_que_size_, decode_, std::move(schema), std::move(sampler_->Build())); + node_ops.push_back(voc_op); return node_ops; } diff --git a/mindspore/ccsrc/minddata/dataset/api/iterator.cc b/mindspore/ccsrc/minddata/dataset/api/iterator.cc index e60ddc7643..ea6f463a00 100644 --- a/mindspore/ccsrc/minddata/dataset/api/iterator.cc +++ b/mindspore/ccsrc/minddata/dataset/api/iterator.cc @@ -30,6 +30,19 @@ void Iterator::GetNextRow(TensorMap *row) { } } +// Get the next row from the data pipeline. +void Iterator::GetNextRow(TensorVec *row) { + TensorRow tensor_row; + Status rc = iterator_->FetchNextTensorRow(&tensor_row); + if (rc.IsError()) { + MS_LOG(ERROR) << "GetNextRow: Failed to get next row."; + row->clear(); + } + // Generate a vector as return + row->clear(); + std::copy(tensor_row.begin(), tensor_row.end(), std::back_inserter(*row)); +} + // Shut down the data pipeline. void Iterator::Stop() { // Releasing the iterator_ unique_ptre. This should trigger the destructor of iterator_. @@ -61,13 +74,20 @@ Status Iterator::BuildAndLaunchTree(std::shared_ptr ds) { RETURN_STATUS_UNEXPECTED("Node operation returned nothing"); } - auto root_op = root_ops.front(); - - RETURN_UNEXPECTED_IF_NULL(root_op); - - RETURN_IF_NOT_OK(tree_->AssociateNode(root_op)); - - q.push(std::make_pair(ds, root_op)); + // Iterate through all the DatasetOps returned by Dataset's Build(), associate them + // with the execution tree and add the child and parent relationship between the nodes + // Note that some Dataset objects might return more than one DatasetOps + // e.g. MapDataset will return [ProjectOp, MapOp] if project_columns is set for MapDataset + std::shared_ptr prev_op = nullptr; + for (auto op : root_ops) { + RETURN_IF_NOT_OK(tree_->AssociateNode(op)); + if (prev_op != nullptr) { + RETURN_IF_NOT_OK(prev_op->AddChild(op)); + } + prev_op = op; + } + // Add the last DatasetOp to the queue to be BFS. + q.push(std::make_pair(ds, root_ops.back())); // Traverse down to the children and convert them to the corresponding DatasetOps (i.e. execution tree nodes) while (!q.empty()) { @@ -94,7 +114,7 @@ Status Iterator::BuildAndLaunchTree(std::shared_ptr ds) { q.push(std::make_pair(child, child_ops.back())); } } - RETURN_IF_NOT_OK(tree_->AssignRoot(root_op)); + RETURN_IF_NOT_OK(tree_->AssignRoot(root_ops.front())); } // Launch the execution tree. diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc index b2873cd5a4..b51e3ef4b0 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/kernels/image/bindings.cc @@ -28,8 +28,10 @@ #include "minddata/dataset/kernels/image/hwc_to_chw_op.h" #include "minddata/dataset/kernels/image/image_utils.h" #include "minddata/dataset/kernels/image/invert_op.h" +#include "minddata/dataset/kernels/image/mixup_batch_op.h" #include "minddata/dataset/kernels/image/normalize_op.h" #include "minddata/dataset/kernels/image/pad_op.h" +#include "minddata/dataset/kernels/image/random_affine_op.h" #include "minddata/dataset/kernels/image/random_color_adjust_op.h" #include "minddata/dataset/kernels/image/random_crop_and_resize_op.h" #include "minddata/dataset/kernels/image/random_crop_and_resize_with_bbox_op.h" @@ -48,6 +50,8 @@ #include "minddata/dataset/kernels/image/resize_bilinear_op.h" #include "minddata/dataset/kernels/image/resize_op.h" #include "minddata/dataset/kernels/image/resize_with_bbox_op.h" +#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h" +#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h" #include "minddata/dataset/kernels/image/uniform_aug_op.h" namespace mindspore { @@ -92,6 +96,12 @@ PYBIND_REGISTER(CenterCropOp, 1, ([](const py::module *m) { .def(py::init(), py::arg("height"), py::arg("width") = CenterCropOp::kDefWidth); })); +PYBIND_REGISTER(MixUpBatchOp, 1, ([](const py::module *m) { + (void)py::class_>( + *m, "MixUpBatchOp", "Tensor operation to mixup a batch of images") + .def(py::init(), py::arg("alpha")); + })); + PYBIND_REGISTER(ResizeOp, 1, ([](const py::module *m) { (void)py::class_>( *m, "ResizeOp", "Tensor operation to resize an image. Takes height, width and mode") @@ -108,6 +118,19 @@ PYBIND_REGISTER(ResizeWithBBoxOp, 1, ([](const py::module *m) { py::arg("interpolation") = ResizeWithBBoxOp::kDefInterpolation); })); +PYBIND_REGISTER(RandomAffineOp, 1, ([](const py::module *m) { + (void)py::class_>( + *m, "RandomAffineOp", "Tensor operation to apply random affine transformations on an image.") + .def(py::init, std::vector, std::vector, + std::vector, InterpolationMode, std::vector>(), + py::arg("degrees") = RandomAffineOp::kDegreesRange, + py::arg("translate_range") = RandomAffineOp::kTranslationPercentages, + py::arg("scale_range") = RandomAffineOp::kScaleRange, + py::arg("shear_ranges") = RandomAffineOp::kShearRanges, + py::arg("interpolation") = RandomAffineOp::kDefInterpolation, + py::arg("fill_value") = RandomAffineOp::kFillValue); + })); + PYBIND_REGISTER( RandomResizeWithBBoxOp, 1, ([](const py::module *m) { (void)py::class_>( @@ -341,6 +364,24 @@ PYBIND_REGISTER(RandomSelectSubpolicyOp, 1, ([](const py::module *m) { return std::make_shared(cpp_policy); })); })); +PYBIND_REGISTER(SoftDvppDecodeResizeJpegOp, 1, ([](const py::module *m) { + (void)py::class_>( + *m, "SoftDvppDecodeResizeJpegOp", "TensorOp to use soft dvpp decode and resize jpeg image.") + .def(py::init(), py::arg("targetHeight"), py::arg("targetWidth")); + })); +PYBIND_REGISTER( + SoftDvppDecodeRandomCropResizeJpegOp, 1, ([](const py::module *m) { + (void) + py::class_>( + *m, "SoftDvppDecodeRandomCropResizeJpegOp", + "TensorOp to use soft dvpp decode, random crop and resize jepg image.") + .def(py::init(), py::arg("targetHeight"), + py::arg("targetWidth"), py::arg("scaleLb") = RandomCropDecodeResizeOp::kDefScaleLb, + py::arg("scaleUb") = RandomCropDecodeResizeOp::kDefScaleUb, + py::arg("aspectLb") = RandomCropDecodeResizeOp::kDefAspectLb, + py::arg("aspectUb") = RandomCropDecodeResizeOp::kDefAspectUb, + py::arg("maxIter") = RandomCropDecodeResizeOp::kDefMaxIter); + })); } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc index 5c785fcd37..9d3a36f534 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/mindrecord/include/bindings.cc @@ -48,12 +48,12 @@ PYBIND_REGISTER( ShardPkSample, 1, ([](const py::module *m) { (void)py::class_>( *m, "MindrecordPkSampler") - .def(py::init([](int64_t kVal, std::string kColumn, bool shuffle) { + .def(py::init([](int64_t kVal, std::string kColumn, bool shuffle, int64_t num_samples) { if (shuffle == true) { return std::make_shared(kColumn, kVal, std::numeric_limits::max(), - GetSeed()); + GetSeed(), num_samples); } else { - return std::make_shared(kColumn, kVal); + return std::make_shared(kColumn, kVal, num_samples); } })); })); diff --git a/mindspore/ccsrc/minddata/dataset/api/transforms.cc b/mindspore/ccsrc/minddata/dataset/api/transforms.cc index a68fc7747f..b1d80db9dd 100644 --- a/mindspore/ccsrc/minddata/dataset/api/transforms.cc +++ b/mindspore/ccsrc/minddata/dataset/api/transforms.cc @@ -21,8 +21,12 @@ #include "minddata/dataset/kernels/image/crop_op.h" #include "minddata/dataset/kernels/image/cut_out_op.h" #include "minddata/dataset/kernels/image/decode_op.h" +#include "minddata/dataset/kernels/image/hwc_to_chw_op.h" +#include "minddata/dataset/kernels/image/mixup_batch_op.h" #include "minddata/dataset/kernels/image/normalize_op.h" +#include "minddata/dataset/kernels/data/one_hot_op.h" #include "minddata/dataset/kernels/image/pad_op.h" +#include "minddata/dataset/kernels/image/random_affine_op.h" #include "minddata/dataset/kernels/image/random_color_adjust_op.h" #include "minddata/dataset/kernels/image/random_crop_op.h" #include "minddata/dataset/kernels/image/random_horizontal_flip_op.h" @@ -81,6 +85,26 @@ std::shared_ptr Decode(bool rgb) { return op; } +// Function to create HwcToChwOperation. +std::shared_ptr HWC2CHW() { + auto op = std::make_shared(); + // Input validation + if (!op->ValidateParams()) { + return nullptr; + } + return op; +} + +// Function to create MixUpBatchOperation. +std::shared_ptr MixUpBatch(float alpha) { + auto op = std::make_shared(alpha); + // Input validation + if (!op->ValidateParams()) { + return nullptr; + } + return op; +} + // Function to create NormalizeOperation. std::shared_ptr Normalize(std::vector mean, std::vector std) { auto op = std::make_shared(mean, std); @@ -91,6 +115,16 @@ std::shared_ptr Normalize(std::vector mean, std::vect return op; } +// Function to create OneHotOperation. +std::shared_ptr OneHot(int32_t num_classes) { + auto op = std::make_shared(num_classes); + // Input validation + if (!op->ValidateParams()) { + return nullptr; + } + return op; +} + // Function to create PadOperation. std::shared_ptr Pad(std::vector padding, std::vector fill_value, BorderType padding_mode) { @@ -114,10 +148,27 @@ std::shared_ptr RandomColorAdjust(std::vector return op; } +// Function to create RandomAffineOperation. +std::shared_ptr RandomAffine(const std::vector °rees, + const std::vector &translate_range, + const std::vector &scale_range, + const std::vector &shear_ranges, + InterpolationMode interpolation, + const std::vector &fill_value) { + auto op = std::make_shared(degrees, translate_range, scale_range, shear_ranges, interpolation, + fill_value); + // Input validation + if (!op->ValidateParams()) { + return nullptr; + } + return op; +} + // Function to create RandomCropOperation. std::shared_ptr RandomCrop(std::vector size, std::vector padding, - bool pad_if_needed, std::vector fill_value) { - auto op = std::make_shared(size, padding, pad_if_needed, fill_value); + bool pad_if_needed, std::vector fill_value, + BorderType padding_mode) { + auto op = std::make_shared(size, padding, pad_if_needed, fill_value, padding_mode); // Input validation if (!op->ValidateParams()) { return nullptr; @@ -271,6 +322,25 @@ bool DecodeOperation::ValidateParams() { return true; } std::shared_ptr DecodeOperation::Build() { return std::make_shared(rgb_); } +// HwcToChwOperation +bool HwcToChwOperation::ValidateParams() { return true; } + +std::shared_ptr HwcToChwOperation::Build() { return std::make_shared(); } + +// MixUpOperation +MixUpBatchOperation::MixUpBatchOperation(float alpha) : alpha_(alpha) {} + +bool MixUpBatchOperation::ValidateParams() { + if (alpha_ < 0) { + MS_LOG(ERROR) << "MixUpBatch: alpha must be a positive floating value however it is: " << alpha_; + return false; + } + + return true; +} + +std::shared_ptr MixUpBatchOperation::Build() { return std::make_shared(alpha_); } + // NormalizeOperation NormalizeOperation::NormalizeOperation(std::vector mean, std::vector std) : mean_(mean), std_(std) {} @@ -292,6 +362,20 @@ std::shared_ptr NormalizeOperation::Build() { return std::make_shared(mean_[0], mean_[1], mean_[2], std_[0], std_[1], std_[2]); } +// OneHotOperation +OneHotOperation::OneHotOperation(int32_t num_classes) : num_classes_(num_classes) {} + +bool OneHotOperation::ValidateParams() { + if (num_classes_ < 0) { + MS_LOG(ERROR) << "OneHot: Number of classes cannot be negative. Number of classes: " << num_classes_; + return false; + } + + return true; +} + +std::shared_ptr OneHotOperation::Build() { return std::make_shared(num_classes_); } + // PadOperation PadOperation::PadOperation(std::vector padding, std::vector fill_value, BorderType padding_mode) : padding_(padding), fill_value_(fill_value), padding_mode_(padding_mode) {} @@ -401,10 +485,90 @@ std::shared_ptr RandomColorAdjustOperation::Build() { return tensor_op; } +// RandomAffineOperation +RandomAffineOperation::RandomAffineOperation(const std::vector °rees, + const std::vector &translate_range, + const std::vector &scale_range, + const std::vector &shear_ranges, InterpolationMode interpolation, + const std::vector &fill_value) + : degrees_(degrees), + translate_range_(translate_range), + scale_range_(scale_range), + shear_ranges_(shear_ranges), + interpolation_(interpolation), + fill_value_(fill_value) {} + +bool RandomAffineOperation::ValidateParams() { + // Degrees + if (degrees_.size() != 2) { + MS_LOG(ERROR) << "RandomAffine: degrees vector has incorrect size: degrees.size() = " << degrees_.size(); + return false; + } + if (degrees_[0] > degrees_[1]) { + MS_LOG(ERROR) << "RandomAffine: minimum of degrees range is greater than maximum: min = " << degrees_[0] + << ", max = " << degrees_[1]; + return false; + } + // Translate + if (translate_range_.size() != 2) { + MS_LOG(ERROR) << "RandomAffine: translate_range vector has incorrect size: translate_range.size() = " + << translate_range_.size(); + return false; + } + if (translate_range_[0] > translate_range_[1]) { + MS_LOG(ERROR) << "RandomAffine: minimum of translate range is greater than maximum: min = " << translate_range_[0] + << ", max = " << translate_range_[1]; + return false; + } + // Scale + if (scale_range_.size() != 2) { + MS_LOG(ERROR) << "RandomAffine: scale_range vector has incorrect size: scale_range.size() = " + << scale_range_.size(); + return false; + } + if (scale_range_[0] > scale_range_[1]) { + MS_LOG(ERROR) << "RandomAffine: minimum of scale range is greater than maximum: min = " << scale_range_[0] + << ", max = " << scale_range_[1]; + return false; + } + // Shear + if (shear_ranges_.size() != 4) { + MS_LOG(ERROR) << "RandomAffine: shear_ranges vector has incorrect size: shear_ranges.size() = " + << shear_ranges_.size(); + return false; + } + if (shear_ranges_[0] > shear_ranges_[1]) { + MS_LOG(ERROR) << "RandomAffine: minimum of horizontal shear range is greater than maximum: min = " + << shear_ranges_[0] << ", max = " << shear_ranges_[1]; + return false; + } + if (shear_ranges_[2] > shear_ranges_[3]) { + MS_LOG(ERROR) << "RandomAffine: minimum of vertical shear range is greater than maximum: min = " << shear_ranges_[2] + << ", max = " << scale_range_[3]; + return false; + } + // Fill Value + if (fill_value_.size() != 3) { + MS_LOG(ERROR) << "RandomAffine: fill_value vector has incorrect size: fill_value.size() = " << fill_value_.size(); + return false; + } + return true; +} + +std::shared_ptr RandomAffineOperation::Build() { + auto tensor_op = std::make_shared(degrees_, translate_range_, scale_range_, shear_ranges_, + interpolation_, fill_value_); + return tensor_op; +} + // RandomCropOperation RandomCropOperation::RandomCropOperation(std::vector size, std::vector padding, bool pad_if_needed, - std::vector fill_value) - : size_(size), padding_(padding), pad_if_needed_(pad_if_needed), fill_value_(fill_value) {} + std::vector fill_value, BorderType padding_mode) + : size_(size), + padding_(padding), + pad_if_needed_(pad_if_needed), + fill_value_(fill_value), + padding_mode_(padding_mode) {} bool RandomCropOperation::ValidateParams() { if (size_.empty() || size_.size() > 2) { @@ -443,7 +607,7 @@ std::shared_ptr RandomCropOperation::Build() { } auto tensor_op = std::make_shared(crop_height, crop_width, pad_top, pad_bottom, pad_left, pad_right, - BorderType::kConstant, pad_if_needed_, fill_r, fill_g, fill_b); + padding_mode_, pad_if_needed_, fill_r, fill_g, fill_b); return tensor_op; } diff --git a/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.cc b/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.cc index aac0eaa2e9..d737a0fa1b 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.cc +++ b/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.cc @@ -20,6 +20,7 @@ #include "minddata/dataset/engine/datasetops/cache_op.h" #include "minddata/dataset/engine/datasetops/cache_lookup_op.h" #include "minddata/dataset/engine/datasetops/cache_merge_op.h" +#include "minddata/dataset/engine/datasetops/device_queue_op.h" #include "minddata/dataset/engine/datasetops/epoch_ctrl_op.h" namespace mindspore { @@ -258,6 +259,13 @@ Status RepeatPass::RunOnNode(std::shared_ptr node, bool *modified return Status::OK(); } +Status RepeatPass::RunOnNode(std::shared_ptr node, bool *modified) { + // Set total repeats and total epochs for the DeviceQueueOp + node->set_total_repeats(num_epochs_); + node->set_num_repeats_per_epoch(1); + return Status::OK(); +} + // Adds an operator to the eoe operator stack save area void RepeatPass::AddToEOEOpStack(std::shared_ptr dataset_op) { op_stack *current_stack = eoe_op_stacks_.top().get(); diff --git a/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.h b/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.h index 1e865eadac..082f8e2af3 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.h +++ b/mindspore/ccsrc/minddata/dataset/engine/opt/post/repeat_pass.h @@ -92,6 +92,12 @@ class RepeatPass : public NodePass { /// \return Status The error code return Status RunOnNode(std::shared_ptr node, bool *modified) override; + /// \brief Set the epoch count for DeviceQueue + /// \param[in] node The node being visited + /// \param[inout] modified Indicator if the node was changed at all + /// \return Status The error code return + Status RunOnNode(std::shared_ptr node, bool *modified) override; + /// \brief All operators have a flag that might be set related to the repeat and any leaf nodes need to be set up /// for use with a controlling repeat above it. /// \param[in] node The node being visited diff --git a/mindspore/ccsrc/minddata/dataset/include/datasets.h b/mindspore/ccsrc/minddata/dataset/include/datasets.h index eefcb024f6..20193e39b2 100644 --- a/mindspore/ccsrc/minddata/dataset/include/datasets.h +++ b/mindspore/ccsrc/minddata/dataset/include/datasets.h @@ -196,8 +196,9 @@ class Dataset : public std::enable_shared_from_this { } /// \brief Function to create an Iterator over the Dataset pipeline + /// \param[in] columns List of columns to be used to specify the order of columns /// \return Shared pointer to the Iterator - std::shared_ptr CreateIterator(); + std::shared_ptr CreateIterator(std::vector columns = {}); /// \brief Function to create a BatchDataset /// \notes Combines batch_size number of consecutive rows into batches @@ -452,6 +453,12 @@ class VOCDataset : public Dataset { bool ValidateParams() override; private: + const std::string kColumnImage = "image"; + const std::string kColumnTarget = "target"; + const std::string kColumnBbox = "bbox"; + const std::string kColumnLabel = "label"; + const std::string kColumnDifficult = "difficult"; + const std::string kColumnTruncate = "truncate"; std::string dataset_dir_; std::string task_; std::string mode_; diff --git a/mindspore/ccsrc/minddata/dataset/include/iterator.h b/mindspore/ccsrc/minddata/dataset/include/iterator.h index 241a8c65b1..443cca93eb 100644 --- a/mindspore/ccsrc/minddata/dataset/include/iterator.h +++ b/mindspore/ccsrc/minddata/dataset/include/iterator.h @@ -37,6 +37,7 @@ namespace api { class Dataset; using TensorMap = std::unordered_map>; +using TensorVec = std::vector>; // Abstract class for iterating over the dataset. class Iterator { @@ -53,9 +54,15 @@ class Iterator { Status BuildAndLaunchTree(std::shared_ptr ds); /// \brief Function to get the next row from the data pipeline. + /// \note Type of return data is a map(with column name). /// \param[out] row - the output tensor row. void GetNextRow(TensorMap *row); + /// \brief Function to get the next row from the data pipeline. + /// \note Type of return data is a vector(without column name). + /// \param[out] row - the output tensor row. + void GetNextRow(TensorVec *row); + /// \brief Function to shut down the data pipeline. void Stop(); diff --git a/mindspore/ccsrc/minddata/dataset/include/transforms.h b/mindspore/ccsrc/minddata/dataset/include/transforms.h index 1788f9ce51..b33516486b 100644 --- a/mindspore/ccsrc/minddata/dataset/include/transforms.h +++ b/mindspore/ccsrc/minddata/dataset/include/transforms.h @@ -51,8 +51,12 @@ class CenterCropOperation; class CropOperation; class CutOutOperation; class DecodeOperation; +class HwcToChwOperation; +class MixUpBatchOperation; class NormalizeOperation; +class OneHotOperation; class PadOperation; +class RandomAffineOperation; class RandomColorAdjustOperation; class RandomCropOperation; class RandomHorizontalFlipOperation; @@ -90,6 +94,18 @@ std::shared_ptr CutOut(int32_t length, int32_t num_patches = 1) /// \return Shared pointer to the current TensorOperation. std::shared_ptr Decode(bool rgb = true); +/// \brief Function to create a HwcToChw TensorOperation. +/// \notes Transpose the input image; shape (H, W, C) to shape (C, H, W). +/// \return Shared pointer to the current TensorOperation. +std::shared_ptr HWC2CHW(); + +/// \brief Function to create a MixUpBatch TensorOperation. +/// \notes Apply MixUp transformation on an input batch of images and labels. The labels must be in one-hot format and +/// Batch must be called before calling this function. +/// \param[in] alpha hyperparameter of beta distribution (default = 1.0) +/// \return Shared pointer to the current TensorOperation. +std::shared_ptr MixUpBatch(float alpha = 1); + /// \brief Function to create a Normalize TensorOperation. /// \notes Normalize the input image with respect to mean and standard deviation. /// \param[in] mean - a vector of mean values for each channel, w.r.t channel order. @@ -97,6 +113,12 @@ std::shared_ptr Decode(bool rgb = true); /// \return Shared pointer to the current TensorOperation. std::shared_ptr Normalize(std::vector mean, std::vector std); +/// \brief Function to create a OneHot TensorOperation. +/// \notes Convert the labels into OneHot format. +/// \param[in] num_classes number of classes. +/// \return Shared pointer to the current TensorOperation. +std::shared_ptr OneHot(int32_t num_classes); + /// \brief Function to create a Pad TensorOp /// \notes Pads the image according to padding parameters /// \param[in] padding A vector representing the number of pixels to pad the image @@ -119,6 +141,23 @@ std::shared_ptr Normalize(std::vector mean, std::vect std::shared_ptr Pad(std::vector padding, std::vector fill_value = {0}, BorderType padding_mode = BorderType::kConstant); +/// \brief Function to create a RandomAffine TensorOperation. +/// \notes Applies a Random Affine transformation on input image in RGB or Greyscale mode. +/// \param[in] degrees A float vector size 2, representing the starting and ending degree +/// \param[in] translate_range A float vector size 2, representing percentages of translation on x and y axes. +/// \param[in] scale_range A float vector size 2, representing the starting and ending scales in the range. +/// \param[in] shear_ranges A float vector size 4, representing the starting and ending shear degrees vertically and +/// horizontally. +/// \param[in] interpolation An enum for the mode of interpolation +/// \param[in] fill_value A uint8_t vector size 3, representing the pixel intensity of the borders, it is used to +/// fill R, G, B channels respectively. +/// \return Shared pointer to the current TensorOperation. +std::shared_ptr RandomAffine( + const std::vector °rees, const std::vector &translate_range = {0.0, 0.0}, + const std::vector &scale_range = {1.0, 1.0}, const std::vector &shear_ranges = {0.0, 0.0, 0.0, 0.0}, + InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, + const std::vector &fill_value = {0, 0, 0}); + /// \brief Randomly adjust the brightness, contrast, saturation, and hue of the input image /// \param[in] brightness Brightness adjustment factor. Must be a vector of one or two values /// if it's a vector of two values it needs to be in the form of [min, max]. Default value is {1, 1} @@ -148,8 +187,8 @@ std::shared_ptr RandomColorAdjust(std::vector /// fill R, G, B channels respectively. /// \return Shared pointer to the current TensorOperation. std::shared_ptr RandomCrop(std::vector size, std::vector padding = {0, 0, 0, 0}, - bool pad_if_needed = false, - std::vector fill_value = {0, 0, 0}); + bool pad_if_needed = false, std::vector fill_value = {0, 0, 0}, + BorderType padding_mode = BorderType::kConstant); /// \brief Function to create a RandomHorizontalFlip TensorOperation. /// \notes Tensor operation to perform random horizontal flip. @@ -258,6 +297,29 @@ class DecodeOperation : public TensorOperation { bool rgb_; }; +class HwcToChwOperation : public TensorOperation { + public: + ~HwcToChwOperation() = default; + + std::shared_ptr Build() override; + + bool ValidateParams() override; +}; + +class MixUpBatchOperation : public TensorOperation { + public: + explicit MixUpBatchOperation(float alpha = 1); + + ~MixUpBatchOperation() = default; + + std::shared_ptr Build() override; + + bool ValidateParams() override; + + private: + float alpha_; +}; + class NormalizeOperation : public TensorOperation { public: NormalizeOperation(std::vector mean, std::vector std); @@ -273,6 +335,20 @@ class NormalizeOperation : public TensorOperation { std::vector std_; }; +class OneHotOperation : public TensorOperation { + public: + explicit OneHotOperation(int32_t num_classes_); + + ~OneHotOperation() = default; + + std::shared_ptr Build() override; + + bool ValidateParams() override; + + private: + float num_classes_; +}; + class PadOperation : public TensorOperation { public: PadOperation(std::vector padding, std::vector fill_value = {0}, @@ -290,6 +366,29 @@ class PadOperation : public TensorOperation { BorderType padding_mode_; }; +class RandomAffineOperation : public TensorOperation { + public: + RandomAffineOperation(const std::vector °rees, const std::vector &translate_range = {0.0, 0.0}, + const std::vector &scale_range = {1.0, 1.0}, + const std::vector &shear_ranges = {0.0, 0.0, 0.0, 0.0}, + InterpolationMode interpolation = InterpolationMode::kNearestNeighbour, + const std::vector &fill_value = {0, 0, 0}); + + ~RandomAffineOperation() = default; + + std::shared_ptr Build() override; + + bool ValidateParams() override; + + private: + std::vector degrees_; // min_degree, max_degree + std::vector translate_range_; // maximum x translation percentage, maximum y translation percentage + std::vector scale_range_; // min_scale, max_scale + std::vector shear_ranges_; // min_x_shear, max_x_shear, min_y_shear, max_y_shear + InterpolationMode interpolation_; + std::vector fill_value_; +}; + class RandomColorAdjustOperation : public TensorOperation { public: RandomColorAdjustOperation(std::vector brightness = {1.0, 1.0}, std::vector contrast = {1.0, 1.0}, @@ -311,7 +410,8 @@ class RandomColorAdjustOperation : public TensorOperation { class RandomCropOperation : public TensorOperation { public: RandomCropOperation(std::vector size, std::vector padding = {0, 0, 0, 0}, - bool pad_if_needed = false, std::vector fill_value = {0, 0, 0}); + bool pad_if_needed = false, std::vector fill_value = {0, 0, 0}, + BorderType padding_mode = BorderType::kConstant); ~RandomCropOperation() = default; @@ -324,6 +424,7 @@ class RandomCropOperation : public TensorOperation { std::vector padding_; bool pad_if_needed_; std::vector fill_value_; + BorderType padding_mode_; }; class RandomHorizontalFlipOperation : public TensorOperation { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc index 5632dddeec..29fd5ada8b 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include "minddata/dataset/core/constants.h" #include "minddata/dataset/core/data_type.h" @@ -648,5 +649,30 @@ Status Concatenate(const TensorRow &input, TensorRow *output, int8_t axis, std:: return Status::OK(); } +Status BatchTensorToCVTensorVector(const std::shared_ptr &input, + std::vector> *output) { + std::vector tensor_shape = input->shape().AsVector(); + TensorShape remaining({-1}); + std::vector index(tensor_shape.size(), 0); + if (tensor_shape.size() <= 1) { + RETURN_STATUS_UNEXPECTED("Tensor must be at least 2-D in order to unpack"); + } + TensorShape element_shape(std::vector(tensor_shape.begin() + 1, tensor_shape.end())); + + for (; index[0] < tensor_shape[0]; index[0]++) { + uchar *start_addr_of_index = nullptr; + std::shared_ptr out; + + RETURN_IF_NOT_OK(input->StartAddrOfIndex(index, &start_addr_of_index, &remaining)); + RETURN_IF_NOT_OK(input->CreateFromMemory(element_shape, input->type(), start_addr_of_index, &out)); + std::shared_ptr cv_out = CVTensor::AsCVTensor(std::move(out)); + if (!cv_out->mat().data) { + RETURN_STATUS_UNEXPECTED("Could not convert to CV Tensor"); + } + output->push_back(cv_out); + } + return Status::OK(); +} + } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h index 5e82b41024..4fba6aef95 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/data/data_utils.h @@ -152,6 +152,17 @@ Status Mask(const std::shared_ptr &input, std::shared_ptr *outpu Status Concatenate(const TensorRow &input, TensorRow *output, int8_t axis, std::shared_ptr prepend, std::shared_ptr append); + +// helper for concat, always append to the input, and pass that to the output +Status ConcatenateHelper(const std::shared_ptr &input, std::shared_ptr *output, int8_t axis, + std::shared_ptr append); + +/// Convert an n-dimensional Tensor to a vector of (n-1)-dimensional CVTensors +/// @param input[in] input tensor +/// @param output[out] output tensor +/// @return Status ok/error +Status BatchTensorToCVTensorVector(const std::shared_ptr &input, + std::vector> *output); } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt index fc4a6790be..d7efb7fbff 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/CMakeLists.txt @@ -1,6 +1,8 @@ file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) +add_subdirectory(soft_dvpp) add_library(kernels-image OBJECT + affine_op.cc auto_contrast_op.cc center_crop_op.cc crop_op.cc @@ -10,8 +12,11 @@ add_library(kernels-image OBJECT hwc_to_chw_op.cc image_utils.cc invert_op.cc + math_utils.cc + mixup_batch_op.cc normalize_op.cc pad_op.cc + random_affine_op.cc random_color_adjust_op.cc random_crop_decode_resize_op.cc random_crop_and_resize_with_bbox_op.cc @@ -34,3 +39,4 @@ add_library(kernels-image OBJECT resize_with_bbox_op.cc random_resize_with_bbox_op.cc ) +add_dependencies(kernels-image kernels-soft-dvpp-image) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/affine_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/affine_op.cc new file mode 100644 index 0000000000..1ea1ea434c --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/affine_op.cc @@ -0,0 +1,99 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include + +#include "minddata/dataset/kernels/image/affine_op.h" +#include "minddata/dataset/kernels/image/image_utils.h" +#include "minddata/dataset/kernels/image/math_utils.h" +#include "minddata/dataset/util/random.h" + +namespace mindspore { +namespace dataset { + +const InterpolationMode AffineOp::kDefInterpolation = InterpolationMode::kNearestNeighbour; +const float_t AffineOp::kDegrees = 0.0; +const std::vector AffineOp::kTranslation = {0.0, 0.0}; +const float_t AffineOp::kScale = 1.0; +const std::vector AffineOp::kShear = {0.0, 0.0}; +const std::vector AffineOp::kFillValue = {0, 0, 0}; + +AffineOp::AffineOp(float_t degrees, const std::vector &translation, float_t scale, + const std::vector &shear, InterpolationMode interpolation, + const std::vector &fill_value) + : degrees_(degrees), + translation_(translation), + scale_(scale), + shear_(shear), + interpolation_(interpolation), + fill_value_(fill_value) {} + +Status AffineOp::Compute(const std::shared_ptr &input, std::shared_ptr *output) { + IO_CHECK(input, output); + float_t translation_x = translation_[0]; + float_t translation_y = translation_[1]; + float_t degrees = 0.0; + DegreesToRadians(degrees_, °rees); + float_t shear_x = shear_[0]; + float_t shear_y = shear_[1]; + DegreesToRadians(shear_x, &shear_x); + DegreesToRadians(-1 * shear_y, &shear_y); + std::shared_ptr input_cv = CVTensor::AsCVTensor(input); + + // Apply Affine Transformation + // T is translation matrix: [1, 0, tx | 0, 1, ty | 0, 0, 1] + // C is translation matrix to keep center: [1, 0, cx | 0, 1, cy | 0, 0, 1] + // RSS is rotation with scale and shear matrix + // RSS(a, s, (sx, sy)) = + // = R(a) * S(s) * SHy(sy) * SHx(sx) + // = [ s*cos(a - sy)/cos(sy), s*(-cos(a - sy)*tan(x)/cos(y) - sin(a)), 0 ] + // [ s*sin(a - sy)/cos(sy), s*(-sin(a - sy)*tan(x)/cos(y) + cos(a)), 0 ] + // [ 0 , 0 , 1 ] + // + // where R is a rotation matrix, S is a scaling matrix, and SHx and SHy are the shears: + // SHx(s) = [1, -tan(s)] and SHy(s) = [1 , 0] + // [0, 1 ] [-tan(s), 1] + // + // Thus, the affine matrix is M = T * C * RSS * C^-1 + + float_t cx = ((input_cv->mat().cols - 1) / 2.0); + float_t cy = ((input_cv->mat().rows - 1) / 2.0); + // Calculate RSS + std::vector matrix{scale_ * cos(degrees + shear_y) / cos(shear_y), + scale_ * (-1 * cos(degrees + shear_y) * tan(shear_x) / cos(shear_y) - sin(degrees)), + 0, + scale_ * sin(degrees + shear_y) / cos(shear_y), + scale_ * (-1 * sin(degrees + shear_y) * tan(shear_x) / cos(shear_y) + cos(degrees)), + 0}; + // Compute T * C * RSS * C^-1 + matrix[2] = (1 - matrix[0]) * cx - matrix[1] * cy + translation_x; + matrix[5] = (1 - matrix[4]) * cy - matrix[3] * cx + translation_y; + cv::Mat affine_mat(matrix); + affine_mat = affine_mat.reshape(1, {2, 3}); + + std::shared_ptr output_cv; + RETURN_IF_NOT_OK(CVTensor::CreateEmpty(input_cv->shape(), input_cv->type(), &output_cv)); + RETURN_UNEXPECTED_IF_NULL(output_cv); + cv::warpAffine(input_cv->mat(), output_cv->mat(), affine_mat, input_cv->mat().size(), + GetCVInterpolationMode(interpolation_), cv::BORDER_CONSTANT, + cv::Scalar(fill_value_[0], fill_value_[1], fill_value_[2])); + (*output) = std::static_pointer_cast(output_cv); + return Status::OK(); +} +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/affine_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/affine_op.h new file mode 100644 index 0000000000..c84863e4d5 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/affine_op.h @@ -0,0 +1,68 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_AFFINE_OP_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_AFFINE_OP_H_ + +#include +#include +#include + +#include "minddata/dataset/core/cv_tensor.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/kernels/tensor_op.h" +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { +class AffineOp : public TensorOp { + public: + /// Default values + static const float_t kDegrees; + static const std::vector kTranslation; + static const float_t kScale; + static const std::vector kShear; + static const InterpolationMode kDefInterpolation; + static const std::vector kFillValue; + + /// Constructor + public: + explicit AffineOp(float_t degrees, const std::vector &translation = kTranslation, float_t scale = kScale, + const std::vector &shear = kShear, InterpolationMode interpolation = kDefInterpolation, + const std::vector &fill_value = kFillValue); + + ~AffineOp() override = default; + + std::string Name() const override { return kAffineOp; } + + Status Compute(const std::shared_ptr &input, std::shared_ptr *output) override; + + /// Member variables + private: + std::string kAffineOp = "AffineOp"; + + protected: + float_t degrees_; + std::vector translation_; // translation_x and translation_y + float_t scale_; + std::vector shear_; // shear_x and shear_y + InterpolationMode interpolation_; + std::vector fill_value_; +}; +} // namespace dataset +} // namespace mindspore + +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_AFFINE_OP_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc index 86de12597b..0ebe288350 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.cc @@ -21,6 +21,7 @@ #include #include #include "utils/ms_utils.h" +#include "minddata/dataset/kernels/image/math_utils.h" #include "minddata/dataset/core/constants.h" #include "minddata/dataset/core/cv_tensor.h" #include "minddata/dataset/core/tensor.h" @@ -631,36 +632,9 @@ Status AutoContrast(const std::shared_ptr &input, std::shared_ptr((cutoff / 100.0) * n); - if (cut != 0) { - for (int32_t lo = 0; lo < 256 && cut > 0; lo++) { - if (cut > hist_vec[lo]) { - cut -= hist_vec[lo]; - hist_vec[lo] = 0; - } else { - hist_vec[lo] -= cut; - cut = 0; - } - } - cut = static_cast((cutoff / 100.0) * n); - for (int32_t hi = 255; hi >= 0 && cut > 0; hi--) { - if (cut > hist_vec[hi]) { - cut -= hist_vec[hi]; - hist_vec[hi] = 0; - } else { - hist_vec[hi] -= cut; - cut = 0; - } - } - } - int32_t lo = 0; int32_t hi = 255; - for (; lo < 256 && !hist_vec[lo]; lo++) { - } - for (; hi >= 0 && !hist_vec[hi]; hi--) { - } + int32_t lo = 0; + RETURN_IF_NOT_OK(ComputeUpperAndLowerPercentiles(&hist_vec, cutoff, cutoff, &hi, &lo)); if (hi <= lo) { for (int32_t i = 0; i < 256; i++) { table.push_back(i); @@ -685,7 +659,6 @@ Status AutoContrast(const std::shared_ptr &input, std::shared_ptr output_cv; RETURN_IF_NOT_OK(CVTensor::CreateFromMat(result, &output_cv)); (*output) = std::static_pointer_cast(output_cv); - (*output) = std::static_pointer_cast(output_cv); (*output)->Reshape(input->shape()); } catch (const cv::Exception &e) { RETURN_STATUS_UNEXPECTED("Error in auto contrast"); @@ -983,5 +956,24 @@ Status UpdateBBoxesForResize(const std::shared_ptr &bboxList, const size return Status::OK(); } +Status GetJpegImageInfo(const std::shared_ptr &input, int *img_width, int *img_height) { + struct jpeg_decompress_struct cinfo {}; + struct JpegErrorManagerCustom jerr {}; + cinfo.err = jpeg_std_error(&jerr.pub); + jerr.pub.error_exit = JpegErrorExitCustom; + try { + jpeg_create_decompress(&cinfo); + JpegSetSource(&cinfo, input->GetBuffer(), input->SizeInBytes()); + (void)jpeg_read_header(&cinfo, TRUE); + jpeg_calc_output_dimensions(&cinfo); + } catch (std::runtime_error &e) { + jpeg_destroy_decompress(&cinfo); + RETURN_STATUS_UNEXPECTED(e.what()); + } + *img_height = cinfo.output_height; + *img_width = cinfo.output_width; + jpeg_destroy_decompress(&cinfo); + return Status::OK(); +} } // namespace dataset } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.h index 4e1b689bec..f82c4d442f 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/image_utils.h @@ -268,6 +268,12 @@ Status PadBBoxes(const std::shared_ptr *bboxList, const size_t &bboxCoun Status UpdateBBoxesForResize(const std::shared_ptr &bboxList, const size_t &bboxCount, int32_t target_width_, int32_t target_height_, int orig_width, int orig_height); +// Get jpeg image width and height +// @param input: CVTensor containing the not decoded image 1D bytes +// @param img_width: the jpeg image width +// @param img_height: the jpeg image height +Status GetJpegImageInfo(const std::shared_ptr &input, int *img_width, int *img_height); + } // namespace dataset } // namespace mindspore #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_IMAGE_UTILS_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/math_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/math_utils.cc new file mode 100644 index 0000000000..287df68f31 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/math_utils.cc @@ -0,0 +1,84 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "minddata/dataset/kernels/image/math_utils.h" + +#include + +#include +#include + +namespace mindspore { +namespace dataset { +Status ComputeUpperAndLowerPercentiles(std::vector *hist, int32_t hi_p, int32_t low_p, int32_t *hi, + int32_t *lo) { + try { + int32_t n = std::accumulate(hist->begin(), hist->end(), 0); + int32_t cut = static_cast((low_p / 100.0) * n); + for (int32_t lb = 0; lb < hist->size() + 1 && cut > 0; lb++) { + if (cut > (*hist)[lb]) { + cut -= (*hist)[lb]; + (*hist)[lb] = 0; + } else { + (*hist)[lb] -= cut; + cut = 0; + } + } + cut = static_cast((hi_p / 100.0) * n); + for (int32_t ub = hist->size() - 1; ub >= 0 && cut > 0; ub--) { + if (cut > (*hist)[ub]) { + cut -= (*hist)[ub]; + (*hist)[ub] = 0; + } else { + (*hist)[ub] -= cut; + cut = 0; + } + } + *lo = 0; + *hi = hist->size() - 1; + for (; (*lo) < (*hi) && !(*hist)[*lo]; (*lo)++) { + } + for (; (*hi) >= 0 && !(*hist)[*hi]; (*hi)--) { + } + } catch (const std::exception &e) { + const char *err_msg = e.what(); + std::string err_message = "Error in ComputeUpperAndLowerPercentiles: "; + err_message += err_msg; + RETURN_STATUS_UNEXPECTED(err_message); + } + return Status::OK(); +} + +Status DegreesToRadians(float_t degrees, float_t *radians_target) { + *radians_target = CV_PI * degrees / 180.0; + return Status::OK(); +} + +Status GenerateRealNumber(float_t a, float_t b, std::mt19937 *rnd, float_t *result) { + try { + std::uniform_real_distribution distribution{a, b}; + *result = distribution(*rnd); + } catch (const std::exception &e) { + const char *err_msg = e.what(); + std::string err_message = "Error in GenerateRealNumber: "; + err_message += err_msg; + RETURN_STATUS_UNEXPECTED(err_message); + } + return Status::OK(); +} + +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/math_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/image/math_utils.h new file mode 100644 index 0000000000..66c28c0ae3 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/math_utils.h @@ -0,0 +1,50 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MATH_UTILS_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MATH_UTILS_H_ + +#include +#include +#include +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { + +/// \brief Returns lower and upper pth percentiles of the input histogram. +/// \param[in] hist: Input histogram (mutates the histogram for computation purposes) +/// \param[in] hi_p: Right side percentile +/// \param[in] low_p: Left side percentile +/// \param[out] hi: Value at high end percentile +/// \param[out] lo: Value at low end percentile +Status ComputeUpperAndLowerPercentiles(std::vector *hist, int32_t hi_p, int32_t low_p, int32_t *hi, + int32_t *lo); + +/// \brief Converts degrees input to radians. +/// \param[in] degrees: Input degrees +/// \param[out] radians_target: Radians output +Status DegreesToRadians(float_t degrees, float_t *radians_target); + +/// \brief Generates a random real number in [a,b). +/// \param[in] a: Start of range +/// \param[in] b: End of range +/// \param[in] rnd: Random device +/// \param[out] result: Random number in range [a,b) +Status GenerateRealNumber(float_t a, float_t b, std::mt19937 *rnd, float_t *result); + +} // namespace dataset +} // namespace mindspore +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MATH_UTILS_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.cc new file mode 100644 index 0000000000..6386ba121f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.cc @@ -0,0 +1,108 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include +#include "minddata/dataset/core/cv_tensor.h" +#include "minddata/dataset/kernels/image/mixup_batch_op.h" +#include "minddata/dataset/kernels/data/data_utils.h" +#include "minddata/dataset/util/random.h" +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { + +MixUpBatchOp::MixUpBatchOp(float alpha) : alpha_(alpha) { rnd_.seed(GetSeed()); } + +Status MixUpBatchOp::Compute(const TensorRow &input, TensorRow *output) { + if (input.size() < 2) { + RETURN_STATUS_UNEXPECTED("Both images and labels columns are required for this operation"); + } + + std::vector> images; + std::vector image_shape = input.at(0)->shape().AsVector(); + std::vector label_shape = input.at(1)->shape().AsVector(); + + // Check inputs + if (label_shape.size() != 2 || image_shape.size() != 4 || image_shape[0] != label_shape[0]) { + RETURN_STATUS_UNEXPECTED("You must batch before calling MixUpBatch"); + } + + if ((image_shape[1] != 1 && image_shape[1] != 3) && (image_shape[3] != 1 && image_shape[3] != 3)) { + RETURN_STATUS_UNEXPECTED("MixUpBatch: Images must be in the shape of HWC or CHW"); + } + + // Move images into a vector of CVTensors + RETURN_IF_NOT_OK(BatchTensorToCVTensorVector(input.at(0), &images)); + + // Calculating lambda + // If x1 is a random variable from Gamma(a1, 1) and x2 is a random variable from Gamma(a2, 1) + // then x = x1 / (x1+x2) is a random variable from Beta(a1, a2) + std::gamma_distribution distribution(alpha_, 1); + float x1 = distribution(rnd_); + float x2 = distribution(rnd_); + float lam = x1 / (x1 + x2); + + // Calculate random labels + std::vector rand_indx; + for (int64_t i = 0; i < images.size(); i++) rand_indx.push_back(i); + std::shuffle(rand_indx.begin(), rand_indx.end(), rnd_); + + // Compute labels + std::shared_ptr out_labels; + RETURN_IF_NOT_OK(TypeCast(std::move(input.at(1)), &out_labels, DataType("float32"))); + for (int64_t i = 0; i < label_shape[0]; i++) { + for (int64_t j = 0; j < label_shape[1]; j++) { + uint64_t first_value, second_value; + RETURN_IF_NOT_OK(input.at(1)->GetItemAt(&first_value, {i, j})); + RETURN_IF_NOT_OK(input.at(1)->GetItemAt(&second_value, {rand_indx[i], j})); + RETURN_IF_NOT_OK(out_labels->SetItemAt({i, j}, lam * first_value + (1 - lam) * second_value)); + } + } + + // Compute images + for (int64_t i = 0; i < images.size(); i++) { + TensorShape remaining({-1}); + uchar *start_addr_of_index = nullptr; + std::shared_ptr out; + RETURN_IF_NOT_OK(input.at(0)->StartAddrOfIndex({rand_indx[i], 0, 0, 0}, &start_addr_of_index, &remaining)); + RETURN_IF_NOT_OK(input.at(0)->CreateFromMemory(TensorShape({image_shape[1], image_shape[2], image_shape[3]}), + input.at(0)->type(), start_addr_of_index, &out)); + std::shared_ptr rand_image = CVTensor::AsCVTensor(std::move(out)); + if (!rand_image->mat().data) { + RETURN_STATUS_UNEXPECTED("Could not convert to CV Tensor"); + } + images[i]->mat() = lam * images[i]->mat() + (1 - lam) * rand_image->mat(); + } + + // Move the output into a TensorRow + std::shared_ptr output_image; + RETURN_IF_NOT_OK(Tensor::CreateEmpty(input.at(0)->shape(), input.at(0)->type(), &output_image)); + for (int64_t i = 0; i < images.size(); i++) { + RETURN_IF_NOT_OK(output_image->InsertTensor({i}, images[i])); + } + output->push_back(output_image); + output->push_back(out_labels); + + return Status::OK(); +} + +void MixUpBatchOp::Print(std::ostream &out) const { + out << "MixUpBatchOp: " + << "alpha: " << alpha_ << "\n"; +} +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.h new file mode 100644 index 0000000000..de6b21223c --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/mixup_batch_op.h @@ -0,0 +1,51 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MIXUPBATCH_OP_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MIXUPBATCH_OP_H_ + +#include +#include +#include +#include + +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/kernels/tensor_op.h" +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { +class MixUpBatchOp : public TensorOp { + public: + // Default values, also used by python_bindings.cc + + explicit MixUpBatchOp(float alpha); + + ~MixUpBatchOp() override = default; + + void Print(std::ostream &out) const override; + + Status Compute(const TensorRow &input, TensorRow *output) override; + + std::string Name() const override { return kMixUpBatchOp; } + + private: + float alpha_; + std::mt19937 rnd_; +}; +} // namespace dataset +} // namespace mindspore + +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_MIXUPBATCH_OP_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.cc new file mode 100644 index 0000000000..bf2f6a99ce --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.cc @@ -0,0 +1,77 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include + +#include "minddata/dataset/kernels/image/random_affine_op.h" +#include "minddata/dataset/kernels/image/image_utils.h" +#include "minddata/dataset/kernels/image/math_utils.h" +#include "minddata/dataset/util/random.h" + +namespace mindspore { +namespace dataset { + +const std::vector RandomAffineOp::kDegreesRange = {0.0, 0.0}; +const std::vector RandomAffineOp::kTranslationPercentages = {0.0, 0.0}; +const std::vector RandomAffineOp::kScaleRange = {1.0, 1.0}; +const std::vector RandomAffineOp::kShearRanges = {0.0, 0.0, 0.0, 0.0}; +const InterpolationMode RandomAffineOp::kDefInterpolation = InterpolationMode::kNearestNeighbour; +const std::vector RandomAffineOp::kFillValue = {0, 0, 0}; + +RandomAffineOp::RandomAffineOp(std::vector degrees, std::vector translate_range, + std::vector scale_range, std::vector shear_ranges, + InterpolationMode interpolation, std::vector fill_value) + : AffineOp(0.0), + degrees_range_(degrees), + translate_range_(translate_range), + scale_range_(scale_range), + shear_ranges_(shear_ranges) { + interpolation_ = interpolation; + fill_value_ = fill_value; + rnd_.seed(GetSeed()); +} + +Status RandomAffineOp::Compute(const std::shared_ptr &input, std::shared_ptr *output) { + IO_CHECK(input, output); + dsize_t height = input->shape()[0]; + dsize_t width = input->shape()[1]; + float_t max_dx = translate_range_[0] * height; + float_t max_dy = translate_range_[1] * width; + float_t degrees = 0.0; + RETURN_IF_NOT_OK(GenerateRealNumber(degrees_range_[0], degrees_range_[1], &rnd_, °rees)); + float_t translation_x = 0.0; + RETURN_IF_NOT_OK(GenerateRealNumber(-1 * max_dx, max_dx, &rnd_, &translation_x)); + float_t translation_y = 0.0; + RETURN_IF_NOT_OK(GenerateRealNumber(-1 * max_dy, max_dy, &rnd_, &translation_y)); + float_t scale = 1.0; + RETURN_IF_NOT_OK(GenerateRealNumber(scale_range_[0], scale_range_[1], &rnd_, &scale)); + float_t shear_x = 0.0; + RETURN_IF_NOT_OK(GenerateRealNumber(shear_ranges_[0], shear_ranges_[1], &rnd_, &shear_x)); + float_t shear_y = 0.0; + RETURN_IF_NOT_OK(GenerateRealNumber(shear_ranges_[2], shear_ranges_[3], &rnd_, &shear_y)); + // assign to base class variables + degrees_ = degrees; + scale_ = scale; + translation_[0] = translation_x; + translation_[1] = translation_y; + shear_[0] = shear_x; + shear_[1] = shear_y; + return AffineOp::Compute(input, output); +} +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.h new file mode 100644 index 0000000000..dcaad46817 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/random_affine_op.h @@ -0,0 +1,64 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_ +#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_ + +#include +#include +#include + +#include "minddata/dataset/core/cv_tensor.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/kernels/image/affine_op.h" +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { +class RandomAffineOp : public AffineOp { + public: + /// Default values, also used by python_bindings.cc + static const std::vector kDegreesRange; + static const std::vector kTranslationPercentages; + static const std::vector kScaleRange; + static const std::vector kShearRanges; + static const InterpolationMode kDefInterpolation; + static const std::vector kFillValue; + + explicit RandomAffineOp(std::vector degrees, std::vector translate_range = kTranslationPercentages, + std::vector scale_range = kScaleRange, + std::vector shear_ranges = kShearRanges, + InterpolationMode interpolation = kDefInterpolation, + std::vector fill_value = kFillValue); + + ~RandomAffineOp() override = default; + + std::string Name() const override { return kRandomAffineOp; } + + Status Compute(const std::shared_ptr &input, std::shared_ptr *output) override; + + private: + std::string kRandomAffineOp = "RandomAffineOp"; + std::vector degrees_range_; // min_degree, max_degree + std::vector translate_range_; // maximum x translation percentage, maximum y translation percentage + std::vector scale_range_; // min_scale, max_scale + std::vector shear_ranges_; // min_x_shear, max_x_shear, min_y_shear, max_y_shear + std::mt19937 rnd_; // random device +}; +} // namespace dataset +} // namespace mindspore + +#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_RANDOM_AFFINE_OP_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/random_crop_decode_resize_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/random_crop_decode_resize_op.cc index d62aebd37f..c8742a5fe3 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/random_crop_decode_resize_op.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/random_crop_decode_resize_op.cc @@ -37,22 +37,9 @@ Status RandomCropDecodeResizeOp::Compute(const std::shared_ptr &input, s RETURN_IF_NOT_OK(op.Compute(input, &decoded)); return RandomCropAndResizeOp::Compute(decoded, output); } else { - struct jpeg_decompress_struct cinfo {}; - struct JpegErrorManagerCustom jerr {}; - cinfo.err = jpeg_std_error(&jerr.pub); - jerr.pub.error_exit = JpegErrorExitCustom; - try { - jpeg_create_decompress(&cinfo); - JpegSetSource(&cinfo, input->GetBuffer(), input->SizeInBytes()); - (void)jpeg_read_header(&cinfo, TRUE); - jpeg_calc_output_dimensions(&cinfo); - } catch (std::runtime_error &e) { - jpeg_destroy_decompress(&cinfo); - RETURN_STATUS_UNEXPECTED(e.what()); - } - int h_in = cinfo.output_height; - int w_in = cinfo.output_width; - jpeg_destroy_decompress(&cinfo); + int h_in = 0; + int w_in = 0; + RETURN_IF_NOT_OK(GetJpegImageInfo(input, &w_in, &h_in)); int x = 0; int y = 0; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/CMakeLists.txt new file mode 100644 index 0000000000..411986254f --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/CMakeLists.txt @@ -0,0 +1,6 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) +add_subdirectory(utils) +add_library(kernels-soft-dvpp-image OBJECT + soft_dvpp_decode_resize_jpeg_op.cc + soft_dvpp_decode_random_crop_resize_jpeg_op.cc) \ No newline at end of file diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.cc new file mode 100644 index 0000000000..8980329a8c --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.cc @@ -0,0 +1,84 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h" +#include + +#include "opencv2/opencv.hpp" + +#include "minddata/dataset/core/cv_tensor.h" +#include "minddata/dataset/kernels/image/image_utils.h" +#include "minddata/dataset/util/random.h" + +namespace mindspore { +namespace dataset { +SoftDvppDecodeRandomCropResizeJpegOp::SoftDvppDecodeRandomCropResizeJpegOp(int32_t target_height, int32_t target_width, + float scale_lb, float scale_ub, + float aspect_lb, float aspect_ub, + int32_t max_iter) + : RandomCropAndResizeOp(target_height, target_width, scale_lb, scale_ub, aspect_lb, aspect_ub, + InterpolationMode::kLinear, max_iter) {} + +Status SoftDvppDecodeRandomCropResizeJpegOp::GetCropInfo(const std::shared_ptr &input, + SoftDpCropInfo *crop_info) { + int img_width = 0; + int img_height = 0; + RETURN_IF_NOT_OK(GetJpegImageInfo(input, &img_width, &img_height)); + int x = 0; + int y = 0; + int crop_heigh = 0; + int crop_widht = 0; + RETURN_IF_NOT_OK(GetCropBox(img_height, img_width, &x, &y, &crop_heigh, &crop_widht)); + crop_info->left = x; + crop_info->up = y; + crop_info->right = crop_info->left + crop_widht; + crop_info->down = crop_info->up + crop_heigh; + return Status::OK(); +} + +Status SoftDvppDecodeRandomCropResizeJpegOp::Compute(const std::shared_ptr &input, + std::shared_ptr *output) { + IO_CHECK(input, output); + if (!IsNonEmptyJPEG(input)) { + RETURN_STATUS_UNEXPECTED("SoftDvppDecodeRandomCropResizeJpeg only support process jpeg image."); + } + SoftDpCropInfo crop_info; + RETURN_IF_NOT_OK(GetCropInfo(input, &crop_info)); + try { + unsigned char *buffer = const_cast(input->GetBuffer()); + CHECK_FAIL_RETURN_UNEXPECTED(buffer != nullptr, "The input image buffer is empty."); + SoftDpProcsessInfo info; + info.input_buffer = static_cast(buffer); + info.input_buffer_size = input->SizeInBytes(); + info.output_width = target_width_; + info.output_height = target_height_; + cv::Mat out_rgb_img(target_height_, target_width_, CV_8UC3); + info.output_buffer = out_rgb_img.data; + info.output_buffer_size = target_width_ * target_height_ * 3; + info.is_v_before_u = true; + int ret = DecodeAndCropAndResizeJpeg(&info, crop_info); + std::string error_info("Soft dvpp DecodeAndResizeJpeg failed with return code: "); + error_info += std::to_string(ret); + CHECK_FAIL_RETURN_UNEXPECTED(ret == 0, error_info); + std::shared_ptr cv_tensor = nullptr; + RETURN_IF_NOT_OK(CVTensor::CreateFromMat(out_rgb_img, &cv_tensor)); + *output = std::static_pointer_cast(cv_tensor); + } catch (const cv::Exception &e) { + RETURN_STATUS_UNEXPECTED("Error in soft dvpp image decode and resize."); + } + return Status::OK(); +} +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h new file mode 100644 index 0000000000..5c66accb51 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_random_crop_resize_jpeg_op.h @@ -0,0 +1,47 @@ + +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 DATASET_KERNELS_IMAGE_SOFT_DVPP_DECODE_RANDOM_CROP_RESIZE_JPEG_OP_H_ +#define DATASET_KERNELS_IMAGE_SOFT_DVPP_DECODE_RANDOM_CROP_RESIZE_JPEG_OP_H_ + +#include +#include +#include + +#include "./utils/external_soft_dp.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/kernels/image/random_crop_and_resize_op.h" +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { +class SoftDvppDecodeRandomCropResizeJpegOp : public RandomCropAndResizeOp { + public: + SoftDvppDecodeRandomCropResizeJpegOp(int32_t target_height, int32_t target_width, float scale_lb = kDefScaleLb, + float scale_ub = kDefScaleUb, float aspect_lb = kDefAspectLb, + float aspect_ub = kDefAspectUb, int32_t max_iter = kDefMaxIter); + + Status Compute(const std::shared_ptr &input, std::shared_ptr *output) override; + + std::string Name() const override { return kSoftDvppDecodeRandomCropResizeJpegOp; } + + protected: + Status GetCropInfo(const std::shared_ptr &input, SoftDpCropInfo *crop_info); +}; +} // namespace dataset +} // namespace mindspore + +#endif // DATASET_KERNELS_IMAGE_SOFT_DVPP_DECODE_RANDOM_CROP_RESIZE_JPEG_OP_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.cc new file mode 100644 index 0000000000..84bb189ac2 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.cc @@ -0,0 +1,60 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h" +#include + +#include "./utils/external_soft_dp.h" +#include "opencv2/opencv.hpp" + +#include "minddata/dataset/core/cv_tensor.h" +#include "minddata/dataset/kernels/image/image_utils.h" + +namespace mindspore { +namespace dataset { +Status SoftDvppDecodeResizeJpegOp::Compute(const std::shared_ptr &input, std::shared_ptr *output) { + IO_CHECK(input, output); + if (!IsNonEmptyJPEG(input)) { + RETURN_STATUS_UNEXPECTED("SoftDvppDecodeReiszeJpegOp only support process jpeg image."); + } + try { + unsigned char *buffer = const_cast(input->GetBuffer()); + CHECK_FAIL_RETURN_UNEXPECTED(buffer != nullptr, "The input image buffer is empty."); + SoftDpProcsessInfo info; + info.input_buffer = static_cast(buffer); + info.input_buffer_size = input->SizeInBytes(); + info.output_width = target_width_; + info.output_height = target_height_; + + SoftDpCropInfo crop_info{0, 0, 0, 0}; + + cv::Mat out_rgb_img(target_height_, target_width_, CV_8UC3); + info.output_buffer = out_rgb_img.data; + info.output_buffer_size = target_width_ * target_height_ * 3; + info.is_v_before_u = true; + int ret = DecodeAndResizeJpeg(&info); + std::string error_info("Soft dvpp DecodeAndResizeJpeg failed with return code: "); + error_info += std::to_string(ret); + CHECK_FAIL_RETURN_UNEXPECTED(ret == 0, error_info); + std::shared_ptr cv_tensor = nullptr; + RETURN_IF_NOT_OK(CVTensor::CreateFromMat(out_rgb_img, &cv_tensor)); + *output = std::static_pointer_cast(cv_tensor); + } catch (const cv::Exception &e) { + RETURN_STATUS_UNEXPECTED("Error in soft dvpp image decode and resize."); + } + return Status::OK(); +} +} // namespace dataset +} // namespace mindspore diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h new file mode 100644 index 0000000000..0419a86cf3 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/soft_dvpp_decode_resize_jpeg_op.h @@ -0,0 +1,44 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 DATASET_KERNELS_IMAGE_SOFT_DVPP_DECODE_RESIZE_JPEG_OP_H_ +#define DATASET_KERNELS_IMAGE_SOFT_DVPP_DECODE_RESIZE_JPEG_OP_H_ + +#include +#include + +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/kernels/tensor_op.h" +#include "minddata/dataset/util/status.h" + +namespace mindspore { +namespace dataset { +class SoftDvppDecodeResizeJpegOp : public TensorOp { + public: + SoftDvppDecodeResizeJpegOp(int32_t target_height, int32_t target_width) + : target_height_(target_height), target_width_(target_width) {} + + Status Compute(const std::shared_ptr &input, std::shared_ptr *output) override; + + std::string Name() const override { return kSoftDvppDecodeReiszeJpegOp; } + + private: + int32_t target_height_; + int32_t target_width_; +}; +} // namespace dataset +} // namespace mindspore + +#endif // DATASET_KERNELS_IMAGE_SOFT_DVPP_DECODE_RESIZE_JPEG_OP_H_ diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/CMakeLists.txt new file mode 100644 index 0000000000..c9c16b4708 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/CMakeLists.txt @@ -0,0 +1,13 @@ +file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp") +set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) +add_library(soft-dvpp-utils OBJECT + soft_dp.cc + soft_dp_tools.cc + soft_jpegd.cc + soft_vpc.cc + yuv_scaler_para_set.cc) +if (USE_GLOG) + message("Soft dvpp use glog to print message.") +else() + add_compile_definitions(DVPP_UTST) +endif() \ No newline at end of file diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/external_soft_dp.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/external_soft_dp.h new file mode 100644 index 0000000000..88099bb7e8 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/external_soft_dp.h @@ -0,0 +1,57 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 EXTERNAL_SOFTDP_H +#define EXTERNAL_SOFTDP_H + +#include + +struct SoftDpProcsessInfo { + uint8_t *input_buffer; // input buffer + uint32_t input_buffer_size; // input buffer size + + uint8_t *output_buffer; // output buffer + uint32_t output_buffer_size; // output buffer size + + uint32_t output_width; // output width + uint32_t output_height; // output height + + bool is_v_before_u; // uv : true, uv : false +}; + +struct SoftDpCropInfo { + uint32_t left; // crop left boundry + uint32_t right; // crop right boundry + uint32_t up; // crop up boundry + uint32_t down; // crop down boundry +}; + +/* + * @brief decode and resize image + * @param [in] SoftDpProcsessInfo& soft_dp_process_info: soft decode process struct + * @return success: return 0, fail: return error number + */ +uint32_t DecodeAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info); + +/* + * @brief decode and crop and resize image + * @param [in] SoftDpProcsessInfo& soft_dp_process_info: soft decode process struct + * @param [in] SoftDpCropInfo& crop_info: user crop info + * @return success: return 0, fail: return error number + */ +uint32_t DecodeAndCropAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info, const SoftDpCropInfo &crop_info); + +#endif // EXTERNAL_SOFTDP_H diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.cc new file mode 100644 index 0000000000..2956886cc4 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.cc @@ -0,0 +1,69 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.h" + +const int32_t decodeSucc = 0; + +uint32_t DecodeAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info) { + VpcInfo vpc_input_info; + SoftJpegd soft_handler; + int32_t ret = soft_handler.JpegdSoftwareDecodeProcess(&vpc_input_info, soft_dp_process_info); + if (ret != decodeSucc) { + API_LOGE("Jpegd decode fail in resize interface."); + return ret; + } + + // use vpc interface to resize and convert RGB, give user output buf and output size. + SoftDpCropInfo crop; + crop.left = 0; + crop.right = vpc_input_info.real_width - 1; + crop.up = 0; + crop.down = vpc_input_info.real_height - 1; + + VpcInfo output; + output.addr = soft_dp_process_info->output_buffer; + output.width = soft_dp_process_info->output_width; + output.height = soft_dp_process_info->output_height; + SoftVpc soft_vpc; + ret = soft_vpc.Process(vpc_input_info, crop, output); + return ret; +} + +uint32_t DecodeAndCropAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info, const SoftDpCropInfo &crop_info) { + VpcInfo vpc_input_info; + SoftJpegd soft_handler; + + int32_t ret = soft_handler.JpegdSoftwareDecodeProcess(&vpc_input_info, soft_dp_process_info); + if (ret != decodeSucc) { + API_LOGE("Jpegd decode fail in crop and resize interface."); + return ret; + } + + // use vpc interface to resize and crop and convert RGB, give user output buf and output size. + VpcInfo output; + output.addr = soft_dp_process_info->output_buffer; + output.width = soft_dp_process_info->output_width; + output.height = soft_dp_process_info->output_height; + SoftDpCropInfo crop = crop_info; + + SoftVpc soft_vpc; + ret = soft_vpc.Process(vpc_input_info, crop, output); + return ret; +} diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.h new file mode 100644 index 0000000000..5cfb87cf76 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.h @@ -0,0 +1,54 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 SOFT_DP_H +#define SOFT_DP_H + +#include +#include "./external_soft_dp.h" + +enum JpegdToVpcFormat { + INPUT_VPC_UNKNOWN = -1, + INPUT_YUV420_PLANNER = 1, // 1 + INPUT_YUV422_PLANNER, // 2 + INPUT_YUV444_PLANNER, // 3 + INPUT_YUV400_PLANNER, // 4 +}; + +struct VpcInfo { + uint8_t *addr; + int32_t width; + int32_t height; + + int32_t real_width; + int32_t real_height; + + enum JpegdToVpcFormat format; + bool is_v_before_u; + bool is_fake420; + + VpcInfo() + : addr(nullptr), + width(0), + height(0), + real_width(0), + real_height(0), + format(INPUT_VPC_UNKNOWN), + is_v_before_u(false), + is_fake420(false) {} +}; + +#endif // SOFT_DP_H diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h new file mode 100644 index 0000000000..9be7690876 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h @@ -0,0 +1,46 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 SOFT_DP_CHECK_H +#define SOFT_DP_CHECK_H + +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_log.h" + +#define CHECK_COND_FAIL_RETURN(model, cond, ...) \ + do { \ + if (!(cond)) { \ + DP_LOG(model, DP_ERR, "check condition: %s fail", #cond); \ + return __VA_ARGS__; \ + } \ + } while (0) + +#define VPC_CHECK_COND_FAIL_RETURN(cond, ret) CHECK_COND_FAIL_RETURN("VPC", cond, ret) + +#define CHECK_COND_FAIL_PRINT_RETURN(module, cond, ret, format, argv...) \ + do { \ + if (!(cond)) { \ + DP_LOG(module, DP_ERR, format, ##argv); \ + return ret; \ + } \ + } while (0) + +#define VPC_CHECK_COND_FAIL_PRINT_RETURN(cond, ret, format, argv...) \ + CHECK_COND_FAIL_PRINT_RETURN("VPC", cond, ret, format, ##argv) + +#define JPEGD_CHECK_COND_FAIL_PRINT_RETURN(cond, ret, format, argv...) \ + CHECK_COND_FAIL_PRINT_RETURN("JPEGD", cond, ret, format, ##argv) + +#endif // SOFT_DP_CHECK_H diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_log.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_log.h new file mode 100644 index 0000000000..c28b1539d2 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_log.h @@ -0,0 +1,152 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 SOFT_DP_LOG_H +#define SOFT_DP_LOG_H + +#define VERSION_INFO 0x0 +#define DP_DEBUG 0x1 +#define DP_INFO 0x10 +#define DP_WARNING 0x100 +#define DP_ERR 0x1000 +#define DP_EVENT 0x10000 +#define DP_DEBUG_LEVEL (DP_EVENT | DP_ERR | DP_WARNING | DP_INFO | DP_DEBUG) + +#include +#include + +#if defined(DVPP_UTST) || defined(DEBUG) +#include + +#define DP_LOG(model, level, format, ...) \ + do { \ + if (DP_DEBUG_LEVEL & level) { \ + if (DP_DEBUG & level) { \ + printf( \ + "[SOFT_DP-%s] [%s %d] [DEBUG:] " \ + "[T%d] " format "\n", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else if (DP_INFO & level) { \ + printf( \ + "[SOFT_DP-%s] [%s %d] [INFO:] " \ + "[T%d] " format "\n", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else if (DP_WARNING & level) { \ + printf( \ + "[SOFT_DP-%s] [%s %d] [WARNING] " \ + "[T%d] " format "\n", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else if (DP_ERR & level) { \ + printf( \ + "[SOFT_DP-%s] [%s %d] [ERROR:] " \ + "[T%d] " format "\n", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else { \ + printf( \ + "[SOFT_DP-%s] [%s %d] [EVENT:] " \ + "[T%d] " format "\n", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } \ + } \ + } while (0) + +#elif defined(USE_GLOG) + +#include +#include "glog/logging.h" + +template +inline std::string GetFormatString(const char *format, Args... args) { + char buf[BUFSIZ]; + int new_len = snprintf(&buf[0], BUFSIZ, format, args...); + new_len++; + if (new_len > BUFSIZ) { + std::vector buf2(new_len); + snprintf(buf2.data(), new_len, format, args...); + return std::string(buf2.data()); + } + return buf; +} + +#define DP_LOG(model, level, format, ...) \ + do { \ + std::string info = GetFormatString( \ + "[%s] [%s:%d] " \ + "[T%d] " format "", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + if (DP_WARNING & level) { \ + LOG(WARNING) << info; \ + } else if (DP_ERR & level) { \ + LOG(ERROR) << info; \ + } else { \ + LOG(INFO) << info; \ + } \ + } while (0) + +#else // #if defined(DVPP_UTST) || defined(DEBUG) + +#include "./slog.h" + +#define DP_LOG(model, level, format, ...) \ + do { \ + if (DP_DEBUG_LEVEL & level) { \ + if (DP_DEBUG & level) { \ + dlog_debug(SOFT_DP, \ + "[%s] [%s:%d] " \ + "[T%d] " format "", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else if (DP_INFO & level) { \ + dlog_info(SOFT_DP, \ + "[%s] [%s:%d] " \ + "[T%d] " format "", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else if (DP_WARNING & level) { \ + dlog_warn(SOFT_DP, \ + "[%s] [%s:%d] " \ + "[T%d] " format "", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else if (DP_ERR & level) { \ + dlog_error(SOFT_DP, \ + "[%s] [%s:%d] " \ + "[T%d] " format "", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } else { \ + dlog_event(SOFT_DP, \ + "[%s] [%s:%d] " \ + "[T%d] " format "", \ + model, __FUNCTION__, __LINE__, VERSION_INFO, ##__VA_ARGS__); \ + } \ + } \ + } while (0) + +#endif // #if defined(DVPP_UTST) || defined(DEBUG) + +#define VPC_LOG(level, format, argv...) DP_LOG("VPC", level, format, ##argv) +#define VPC_LOGD(format, argv...) DP_LOG("VPC", DP_DEBUG, format, ##argv) +#define VPC_LOGW(format, argv...) DP_LOG("VPC", DP_WARNING, format, ##argv) +#define VPC_LOGE(format, argv...) DP_LOG("VPC", DP_ERR, format, ##argv) + +#define JPEGD_LOG(level, format, argv...) DP_LOG("JPEGD", level, format, ##argv) +#define JPEGD_LOGD(format, argv...) DP_LOG("JPEGD", DP_DEBUG, format, ##argv) +#define JPEGD_LOGW(format, argv...) DP_LOG("JPEGD", DP_WARNING, format, ##argv) +#define JPEGD_LOGE(format, argv...) DP_LOG("JPEGD", DP_ERR, format, ##argv) + +#define API_LOG(level, format, argv...) DP_LOG("API", level, format, ##argv) +#define API_LOGD(format, argv...) DP_LOG("API", DP_DEBUG, format, ##argv) +#define API_LOGW(format, argv...) DP_LOG("API", DP_WARNING, format, ##argv) +#define API_LOGE(format, argv...) DP_LOG("API", DP_ERR, format, ##argv) + +#endif // SOFT_DP_LOG_H diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.cc new file mode 100644 index 0000000000..63288b1736 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.cc @@ -0,0 +1,56 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.h" +#include +#include +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h" + +const uint32_t kMaxPath = 4096; + +std::pair GetRealpath(const std::string &path) { + char resolvedPath[kMaxPath]; +#ifndef DVPP_UTST + if (path.size() > kMaxPath) { + API_LOGD("path size too large."); + return std::make_pair(false, std::string(strerror(errno))); + } +#endif // !DVPP_UTST + +#ifdef _WIN32 + auto err = _fullpath(resolvedPath, path.c_str(), kMaxPath); +#else + auto err = realpath(path.c_str(), resolvedPath); +#endif + if (err == nullptr) { + return std::make_pair(false, std::string(strerror(errno))); + } else { + return std::make_pair(true, std::string(resolvedPath, strlen(resolvedPath))); + } +} + +bool IsDirectory(const std::string &path) { + struct stat buf; + if (stat(path.c_str(), &buf) != 0) { + return false; + } + + if (S_ISDIR(buf.st_mode)) { + return true; + } else { + return false; + } +} diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.h new file mode 100644 index 0000000000..549ad4a6ff --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.h @@ -0,0 +1,66 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 SOFT_DP_TOOLS_H +#define SOFT_DP_TOOLS_H + +#include +#include +#include + +template +T1 AlignUp(T1 num, T2 align) { + if (num % align) { + num = (num / align + 1) * align; + } + + return num; +} + +template +T1 AlignDown(T1 num, T2 align) { + if (num % align) { + num = num / align * align; + } + + return num; +} + +template +bool IsInTheScope(T num, T left_point, T right_point) { + if (num >= left_point && num <= right_point) { + return true; + } + + return false; +} + +template +T TruncatedFunc(T num, T min, T max) { + if (num < min) { + return min; + } + if (num > max) { + return max; + } + + return num; +} + +std::pair GetRealpath(const std::string &path); + +bool IsDirectory(const std::string &path); + +#endif // SOFT_DP_TOOLS_H diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.cc new file mode 100644 index 0000000000..2cfbe3e71d --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.cc @@ -0,0 +1,246 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_log.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h" +#include +#include + +#include +#include +#include +#include +#include + +const uint32_t yuv400UvValue = 0x80; +const int32_t num2 = 2; +const uint32_t channel3 = 3; +const uint32_t zeroBufSize = 0; +const int32_t decodePadding = 1; +const int32_t minValue = 32; +const int32_t maxValue = 8192; +const int32_t decodeSucc = 0; +const int32_t decodeErr = 1; + +SoftJpegd::SoftJpegd() : soft_decode_out_buf_(nullptr) {} + +/* + * @brief : Use libjpeg to determine the image format. + * @param [in] jpeg_decompress_struct& libjpeg_handler : libjpeg + * @param [in] VpcInfo& vpc_input_info : vpc input information + */ +void SetFormat(struct jpeg_decompress_struct *libjpeg_handler, struct VpcInfo *vpc_input_info) { + // yuv400: component 1 1x1 + // yuv420: component 3 2x2 1x1 1x1 + // yuv422: component 3 2x1 1x1 1x1 + // yuv444: component 3 1x1 1x1 1x1 + if ((libjpeg_handler->num_components == 1) && + (libjpeg_handler->comp_info[0].h_samp_factor == libjpeg_handler->comp_info[0].v_samp_factor)) { + vpc_input_info->format = INPUT_YUV420_PLANNER; + vpc_input_info->is_fake420 = true; + } else if ((libjpeg_handler->num_components == channel3) && + (libjpeg_handler->comp_info[1].h_samp_factor == libjpeg_handler->comp_info[2].h_samp_factor) && + (libjpeg_handler->comp_info[1].v_samp_factor == libjpeg_handler->comp_info[2].v_samp_factor)) { + if (libjpeg_handler->comp_info[0].h_samp_factor == ((libjpeg_handler->comp_info[1].h_samp_factor) * num2)) { + if (libjpeg_handler->comp_info[0].v_samp_factor == ((libjpeg_handler->comp_info[1].v_samp_factor) * num2)) { + vpc_input_info->format = INPUT_YUV420_PLANNER; + } else if (libjpeg_handler->comp_info[0].v_samp_factor == libjpeg_handler->comp_info[1].v_samp_factor) { + vpc_input_info->format = INPUT_YUV422_PLANNER; + } + } else if (libjpeg_handler->comp_info[0].h_samp_factor == libjpeg_handler->comp_info[1].h_samp_factor) { + if (libjpeg_handler->comp_info[0].v_samp_factor == libjpeg_handler->comp_info[1].v_samp_factor) { + vpc_input_info->format = INPUT_YUV444_PLANNER; + } + } + } +} + +static void LibjpegErrorExit(j_common_ptr cinfo) { + char jpegLastErrorMsg[JMSG_LENGTH_MAX]; + (*(cinfo->err->format_message))(cinfo, jpegLastErrorMsg); + JPEGD_LOGE("run libjpeg get error : %s", jpegLastErrorMsg); + throw std::runtime_error(jpegLastErrorMsg); +} + +bool CallLibjpeg(struct jpeg_decompress_struct *libjpeg_handler, uint8_t *addr, uint32_t size) { + struct jpeg_error_mgr libjpegErrorMsg; + libjpeg_handler->err = jpeg_std_error(&libjpegErrorMsg); + libjpegErrorMsg.error_exit = LibjpegErrorExit; + + try { + jpeg_mem_src(libjpeg_handler, addr, size); + jpeg_read_header(libjpeg_handler, TRUE); + return true; + } catch (...) { + return false; + } +} + +/* + * @brief : Obtains the JPEG header information through libjpeg to complete the decoding preparation process. + * @param [in] jpeg_decompress_struct& libjpeg_handler : libjpeg. + * @param [in] VpcInfo& vpc_input_info : vpc input information. + * @param [in] SoftDpProcsessInfo& dp_soft_process_info : soft dp struct. + * @return : decodeSucc:parse jpeg head succ, decodeErr:parse jpeg head fail. + */ +uint32_t PrepareDecode(jpeg_decompress_struct *libjpeg_handler, struct VpcInfo *vpc_input_info, + struct SoftDpProcsessInfo *dp_soft_process_info) { + bool call_libjpeg_succ = + CallLibjpeg(libjpeg_handler, dp_soft_process_info->input_buffer, dp_soft_process_info->input_buffer_size); + if (!call_libjpeg_succ) { + JPEGD_LOGE("CallLibjpeg failed!"); + return decodeErr; + } + + SetFormat(libjpeg_handler, vpc_input_info); + return decodeSucc; +} + +/* + * @brief : Check the parameters. The width and height range are as follows: [32,8192] + * @param [in] int32_t height : image height + * @param [in] int32_t width : image width + * @return : decodeSucc:params are valid, decodeErr:params are invalid. + */ +uint32_t CheckInputParam(int32_t height, int32_t width) { + JPEGD_CHECK_COND_FAIL_PRINT_RETURN((width >= minValue), decodeErr, "width(%d) should be >= 32.", width); + JPEGD_CHECK_COND_FAIL_PRINT_RETURN((width <= maxValue), decodeErr, "width(%d) should be <= 8192.", width); + JPEGD_CHECK_COND_FAIL_PRINT_RETURN((height >= minValue), decodeErr, "height(%d) should be >= 32.", height); + JPEGD_CHECK_COND_FAIL_PRINT_RETURN((height <= maxValue), decodeErr, "height(%d) should be <= 8192.", height); + return decodeSucc; +} + +uint32_t SoftJpegd::AllocOutputBuffer(struct VpcInfo *vpc_input_info, int32_t *width, int32_t *height, + int32_t *sub_sample) { + CheckInputParam(*height, *width); + uint32_t output_size = tjBufSizeYUV2(*width, decodePadding, *height, *sub_sample); + if (output_size == zeroBufSize) { + JPEGD_LOGE("get outbuffer size failed!"); + return decodeErr; + } + + if (vpc_input_info->is_fake420) { + output_size = output_size * channel3 / num2; + } + + soft_decode_out_buf_ = new (std::nothrow) uint8_t[output_size]; + if (soft_decode_out_buf_ == nullptr) { + JPEGD_LOGE("alloc outbuffer failed!"); + return decodeErr; + } + + return decodeSucc; +} + +uint32_t SoftJpegd::ConfigVpcInputData(struct VpcInfo *vpc_input_info, int32_t *width, int32_t *height) { + vpc_input_info->real_height = *height; + vpc_input_info->real_width = *width; + + if ((vpc_input_info->format == INPUT_YUV420_PLANNER || vpc_input_info->format == INPUT_YUV422_PLANNER) && + (*width % num2 == 1)) { + *width = reinterpret_cast(AlignUp(*width, num2)); + JPEGD_LOGW("vpc width needs align up %d, height is %d.", width, height); + } + + if ((vpc_input_info->format == INPUT_YUV420_PLANNER || vpc_input_info->format == INPUT_YUV422_PLANNER) && + (*height % num2 == 1)) { + *height = reinterpret_cast(AlignUp(*height, num2)); + JPEGD_LOGW("vpc height needs align up %d, height is %d.", width, height); + } + + vpc_input_info->addr = soft_decode_out_buf_; + vpc_input_info->height = *height; + vpc_input_info->width = *width; + + if (vpc_input_info->is_fake420) { + uint8_t *u_start = vpc_input_info->addr + vpc_input_info->width * vpc_input_info->height; + int32_t uv_size = vpc_input_info->width * vpc_input_info->height / num2; + int32_t safe_ret = memset_s(reinterpret_cast((uintptr_t)u_start), uv_size, yuv400UvValue, uv_size); + if (safe_ret != 0) { + JPEGD_LOGE("config yuv400 uv memory failed."); + delete[] soft_decode_out_buf_; + soft_decode_out_buf_ = nullptr; + vpc_input_info->addr = nullptr; + return decodeErr; + } + } + + return decodeSucc; +} + +/* + * @brief : destory libjpeg source + * @param [in] struct jpeg_decompress_struct &libjpeg_handler : libjpeg handle. + * @param [in] tjhandle &handle : tjhandle. + */ +void DestoryLibjpegSource(struct jpeg_decompress_struct *libjpeg_handler, const tjhandle &handle) { + (void)tjDestroy(handle); + jpeg_destroy_decompress(libjpeg_handler); +} + +uint32_t SoftJpegd::JpegdSoftwareDecodeProcess(struct VpcInfo *vpc_input_info, + struct SoftDpProcsessInfo *soft_dp_process_info) { + int32_t width = 0; + int32_t height = 0; + int32_t sub_sample = 0; + int32_t color_spase = 0; + struct jpeg_decompress_struct libjpeg_handler; + jpeg_create_decompress(&libjpeg_handler); + tjhandle handle = tjInitDecompress(); + int32_t prepare_decode_res = PrepareDecode(&libjpeg_handler, vpc_input_info, soft_dp_process_info); + if (prepare_decode_res != decodeSucc) { + JPEGD_LOGE("prepare decode failed!"); + DestoryLibjpegSource(&libjpeg_handler, handle); + return decodeErr; + } + + int32_t decode_header_res = + tjDecompressHeader3(handle, soft_dp_process_info->input_buffer, soft_dp_process_info->input_buffer_size, &width, + &height, &sub_sample, &color_spase); + if (decode_header_res != decodeSucc) { + JPEGD_LOGE("Decompress header failed, width = %d, height = %d.", width, height); + DestoryLibjpegSource(&libjpeg_handler, handle); + return decodeErr; + } + + int32_t alloc_out_buf_res = AllocOutputBuffer(vpc_input_info, &width, &height, &sub_sample); + if (alloc_out_buf_res != decodeSucc) { + JPEGD_LOGE("alloc output buffer failed!"); + DestoryLibjpegSource(&libjpeg_handler, handle); + return decodeErr; + } + + int32_t decode_res = + tjDecompressToYUV2(handle, soft_dp_process_info->input_buffer, soft_dp_process_info->input_buffer_size, + soft_decode_out_buf_, width, decodePadding, height, JDCT_ISLOW); + if (decode_res != decodeSucc) { + JPEGD_LOGE("Decompress jpeg failed."); + delete[] soft_decode_out_buf_; + soft_decode_out_buf_ = nullptr; + DestoryLibjpegSource(&libjpeg_handler, handle); + return decodeErr; + } + + int32_t config_vpc_res = ConfigVpcInputData(vpc_input_info, &width, &height); + if (config_vpc_res != decodeSucc) { + DestoryLibjpegSource(&libjpeg_handler, handle); + return decodeErr; + } + DestoryLibjpegSource(&libjpeg_handler, handle); + return decodeSucc; +} diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.h new file mode 100644 index 0000000000..0503187755 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.h @@ -0,0 +1,67 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 SOFT_JPEGD_H +#define SOFT_JPEGD_H + +#include +#include +#include +#include +#include "./jpeglib.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/external_soft_dp.h" + +class SoftJpegd { + public: + SoftJpegd(); + + ~SoftJpegd() {} + + /* + * @brief : decode interface + * @param [in] VpcInfo& vpc_input_info : vpc input information + * @param [in] SoftDpProcsessInfo& soft_dp_process_info : softDp process info + * @return : decodeSucc:decode success, decodeErr:decode failed. + */ + uint32_t JpegdSoftwareDecodeProcess(struct VpcInfo *vpc_input_info, struct SoftDpProcsessInfo *soft_dp_process_info); + + private: + uint8_t *soft_decode_out_buf_; + + /* + * @brief : alloc output buffer + * @param [in] VpcInfo& vpc_input_info : vpc input information + * @param [in] int32_t& width : output width + * @param [in] int32_t& height : output height + * @param [in] int32_t& sub_sample : level of chrominance subsampling in the image + * @param [in] int32_t& color_spase : pointer to an integer variable that will receive one of the JPEG + * constants, indicating the colorspace of the JPEG image. + * @return : decodeSucc:alloc output buf success, decodeErr:alloc output buf failed. + */ + uint32_t AllocOutputBuffer(struct VpcInfo *vpc_input_info, int32_t *width, int32_t *height, int32_t *sub_sample); + + /* + * @brief : config decode output + * @param [in] VpcInfo& vpc_input_info : vpc input information + * @param [in] int32_t& width : output width + * @param [in] int32_t& height : output height + * @return : decodeSucc:config output buf succes, decodeErr:config output buf failed. + */ + uint32_t ConfigVpcInputData(struct VpcInfo *vpc_input_info, int32_t *width, int32_t *height); +}; + +#endif // SOFT_JPEGD_H diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.cc new file mode 100755 index 0000000000..5c11bdcdf1 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.cc @@ -0,0 +1,780 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.h" +#include +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.h" + +constexpr int32_t dpSucc = 0; +constexpr int32_t dpFail = -1; +constexpr uint32_t yuvCoeffiNum4 = 4; +constexpr uint32_t yuvCoeffiNum5 = 5; +constexpr uint32_t uvReductCoeffNum = 5; +constexpr int32_t uvReductCoeff[uvReductCoeffNum] = {13, 65, 100, 65, 13}; // yuv444 dimension reduction filter. +constexpr uint32_t scalerTap4 = 4; +constexpr uint32_t scalerTap6 = 6; +constexpr uint32_t scalerCoeff = 16; // yuv conversion coefficient +constexpr uint32_t low3BitVal = 0x7; +constexpr int32_t low16BitVal = 0xffff; +constexpr uint32_t bit8Offset = 8; +constexpr uint32_t bit13Offset = 13; +constexpr uint32_t bit16Offset = 16; +constexpr uint32_t maxCoeff = 65536; +constexpr uint32_t num2 = 2; +constexpr int32_t scalerTap2 = 2; + +// yuv convert rgb coefficient table +constexpr int32_t rtAippYuv2RgbCscMatrixR0c0 = (256); +constexpr int32_t rtAippYuv2RgbCscMatrixR0c1 = (0); +constexpr int32_t rtAippYuv2RgbCscMatrixR0c2 = (359); +constexpr int32_t rtAippYuv2RgbCscMatrixR1c0 = (256); +constexpr int32_t rtAippYuv2RgbCscMatrixR1c1 = (-88); +constexpr int32_t rtAippYuv2RgbCscMatrixR1c2 = (-183); +constexpr int32_t rtAippYuv2RgbCscMatrixR2c0 = (256); +constexpr int32_t rtAippYuv2RgbCscMatrixR2c1 = (454); +constexpr int32_t rtAippYuv2RgbCscMatrixR2c2 = (0); +constexpr int32_t rtAippYuv2RgbCscInputBias0 = (0); +constexpr int32_t rtAippYuv2RgbCscInputBias1 = (128); +constexpr int32_t rtAippYuv2RgbCscInputBias2 = (128); +constexpr int32_t rtAippConverCoeffi = (256); + +SoftVpc::SoftVpc() + : in_format_(INPUT_VPC_UNKNOWN), + in_width_(0), + in_height_(0), + in_data_(nullptr), + in_y_data_(nullptr), + in_u_data_(nullptr), + in_v_data_(nullptr), + left_(0), + right_(0), + up_(0), + down_(0), + out_width_(0), + out_height_(0), + out_data_(nullptr), + out_y_data_(nullptr), + out_u_data_(nullptr), + out_v_data_(nullptr), + pre_scaler_num_(0), + half_line_mode_(false), + horizon_coeff_(0), + vertical_coeff_(0), + horizon_bypass_(false), + vertical_bypass_(false), + y_horizon_tap_(nullptr), + uv_horizon_tap_(nullptr), + vertical_tap_(nullptr) {} + +void SoftVpc::SetYuv422OutBuffer() { + out_y_data_ = out_data_; + out_u_data_ = out_y_data_ + out_width_ * out_height_; + out_v_data_ = out_u_data_ + out_width_ * out_height_ / yuvCoeffiNum2; +} + +int32_t SoftVpc::CheckParamter() { + VPC_CHECK_COND_FAIL_PRINT_RETURN((left_ < right_), dpFail, "left(%u) should be < right(%u).", left_, right_); + VPC_CHECK_COND_FAIL_PRINT_RETURN((right_ < in_width_), dpFail, "right(%u) should be < inWidth(%u).", right_, + in_width_); + VPC_CHECK_COND_FAIL_PRINT_RETURN((up_ < down_), dpFail, "up(%u) should be < down(%u).", up_, down_); + VPC_CHECK_COND_FAIL_PRINT_RETURN((down_ < in_height_), dpFail, "down_(%u) should be < in_height(%u).", down_, + in_height_); + + uint32_t crop_width = right_ - left_ + 1; + uint32_t crop_height = down_ - up_ + 1; + VPC_CHECK_COND_FAIL_PRINT_RETURN((crop_width >= 10), dpFail, // mini width is 10 + "right(%u) - left(%u) + 1 = crop_width(%u) should be >= 10.", right_, left_, + crop_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((in_width_ <= 8192), dpFail, // max width is 8192 + "inWidth(%u) should be <= 8192.", in_width_); + VPC_CHECK_COND_FAIL_PRINT_RETURN((crop_height >= 6), dpFail, // mini height is 6 + "down(%u) - up(%u) + 1 = crop_height(%u) should be >= 6.", down_, up_, crop_height); + VPC_CHECK_COND_FAIL_PRINT_RETURN((in_height_ <= 8192), dpFail, // max height is 8192 + "inHeight(%u) should be <= 8192.", in_height_); + + uint32_t out_width = out_width_; + uint32_t out_height = out_height_; + bool flag = (out_width * 16 >= crop_width) ? true : false; // Up to 16x magnification + VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail, + "Max magnification is 16. Please check left(%u), right(%u), out_width(%u).", left_, + right_, out_width); + flag = (crop_width * 32 >= out_width) ? true : false; // A maximum of 32x zoom-out + VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail, + "Max reduction multiple is 32. Please check left(%u), right(%u), out_width(%u).", + left_, right_, out_width); + flag = (out_height * 16 >= crop_height) ? true : false; // Up to 16x magnification + VPC_CHECK_COND_FAIL_PRINT_RETURN( + flag, dpFail, "Max magnification is 16. Please check up(%u), down(%u), out_height(%u).", up_, down_, out_height); + flag = (crop_height * 32 >= out_height) ? true : false; // A maximum of 32x zoom-out + VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail, + "Max reduction multiple is 32. Please check up(%u), down(%u), out_height(%u).", up_, + down_, out_height); + return dpSucc; +} + +void SoftVpc::Init(VpcInfo input, SoftDpCropInfo crop, VpcInfo output) { + in_info_ = input; + out_info_ = output; + left_ = (crop.left & 0x1) ? (crop.left + 1) : crop.left; // Round up the value to an even number. + right_ = (crop.right & 0x1) ? crop.right : (crop.right - 1); // Take an odd number downwards. + up_ = (crop.up & 0x1) ? (crop.up + 1) : crop.up; // Round up the value to an even number. + down_ = (crop.down & 0x1) ? crop.down : (crop.down - 1); // Take an odd number downwards. + + in_format_ = input.format; + in_width_ = input.width; + in_height_ = input.height; + + in_data_ = input.addr; + // Offset the start address of each channel to the cropped address. + in_y_data_ = in_data_ + up_ * in_width_ + left_; + in_u_data_ = in_data_ + in_width_ * in_height_ + up_ * in_width_ / yuvCoeffiNum4 + left_ / yuvCoeffiNum2; + in_v_data_ = in_data_ + in_width_ * in_height_ * yuvCoeffiNum5 / yuvCoeffiNum4 + up_ * in_width_ / yuvCoeffiNum4 + + left_ / yuvCoeffiNum2; + + if (in_format_ == INPUT_YUV422_PLANNER) { + in_u_data_ = in_data_ + in_width_ * in_height_ + up_ * in_width_ / yuvCoeffiNum2 + left_ / yuvCoeffiNum2; + in_v_data_ = in_data_ + in_width_ * in_height_ * yuvCoeffiNum3 / yuvCoeffiNum2 + up_ * in_width_ / yuvCoeffiNum2 + + left_ / yuvCoeffiNum2; + } + + if (in_format_ == INPUT_YUV444_PLANNER) { + in_u_data_ = in_data_ + in_width_ * in_height_ + up_ * in_width_ + left_; + in_v_data_ = in_data_ + in_width_ * in_height_ * yuvCoeffiNum2 + up_ * in_width_ + left_; + } + + out_width_ = output.width; + out_height_ = output.height; +} + +// Converts the input result of the chip sub-module to the input of the next level and releases the input memory. +void SoftVpc::OutputChangeToInput() { + in_width_ = out_width_; + in_height_ = out_height_; + left_ = 0; + right_ = in_width_ - 1; + up_ = 0; + down_ = in_height_ - 1; + delete[] in_data_; + in_data_ = out_data_; + in_y_data_ = out_y_data_; + in_u_data_ = out_u_data_; + in_v_data_ = out_v_data_; +} + +// For the tasks that cannot be processed by the chip at a time, split the tasks whose scaling coefficients in the +// horizontal direction are greater than those in the vertical direction. +void SoftVpc::HorizonSplit(ResizeUnit *pre_unit, ResizeUnit *can_process_unit) { + uint32_t in_width = pre_unit->in_width; + uint32_t out_width = pre_unit->out_width; + uint32_t in_height = pre_unit->in_height; + uint32_t out_height = pre_unit->out_height; + + if (out_width > 4 * in_width) { // The horizontal scaling ratio is greater than 4x. + // Ensure that the output is less than four times of the input and the input is an even number. + can_process_unit->in_width = AlignUp(out_width, 8) / 4; + if (out_height > 4 * in_height) { // The vertical scaling ratio is greater than 4x. + // Ensure that the output is less than four times of the input and the input is an even number. + can_process_unit->in_height = AlignUp(out_height, 8) / 4; + } else if (out_height >= in_height) { // The vertical scaling range is [1, 4]. + can_process_unit->in_height = in_height; + } else if (out_height * 4 >= in_height) { // The vertical scaling range is [1/4, 1) + can_process_unit->in_height = out_height; + } else { + can_process_unit->in_height = out_height * 4; // vertical scaling range is smaller than 1/4x + } + } else { // The horizontal scaling ratio is less than or equal to 4x. + can_process_unit->in_width = in_width; + can_process_unit->in_height = out_height * 4; // The vertical scaling ratio is less than 1/4. + } + + can_process_unit->out_width = out_width; + can_process_unit->out_height = out_height; + pre_unit->out_width = can_process_unit->in_width; + pre_unit->out_height = can_process_unit->in_height; +} + +// For the tasks that cannot be processed by the chip at a time, split the tasks whose vertical scaling coefficients +// are greater than the horizontal scaling coefficients. +void SoftVpc::VerticalSplit(ResizeUnit *pre_unit, ResizeUnit *can_process_unit) { + uint32_t in_width = pre_unit->in_width; + uint32_t out_width = pre_unit->out_width; + uint32_t in_height = pre_unit->in_height; + uint32_t out_height = pre_unit->out_height; + + if (out_height > 4 * in_height) { // The vertical scaling ratio is greater than 4x. + // // Ensure that the output is less than four times of the input and the input is an even number. + can_process_unit->in_height = AlignUp(out_height, 8) / 4; + if (out_width > 4 * in_width) { + can_process_unit->in_width = AlignUp(out_width, 8) / 4; + } else if (out_width >= in_width) { + can_process_unit->in_width = in_width; + } else if (out_width * 4 >= in_width) { + can_process_unit->in_width = out_width; + } else { + can_process_unit->in_width = out_width * 4; + } + } else { + // If the vertical scaling ratio is less than or equal to 4x, the horizontal scaling + // ratio must be less than 1/4. + can_process_unit->in_height = in_height; + can_process_unit->in_width = out_width * 4; // The horizontal scaling ratio is less than 1/4. + } + + can_process_unit->out_width = out_width; + can_process_unit->out_height = out_height; + pre_unit->out_width = can_process_unit->in_width; + pre_unit->out_height = can_process_unit->in_height; +} + +// Check whether the VPC chip can complete the processing at a time based on the input and output sizes. +bool SoftVpc::CanVpcChipProcess(const ResizeUnit &pre_unit) { + uint32_t input_width = pre_unit.in_width; + uint32_t output_width = pre_unit.out_width; + uint32_t input_height = pre_unit.in_height; + uint32_t output_height = pre_unit.out_height; + uint32_t pre_scaler_num = 0; + + // 4 and 16 inorder to check whether the aspect ratio ranges from 1/4 to 4. + while (!(IsInTheScope(4 * output_width, input_width, 16 * input_width)) || + !(IsInTheScope(4 * output_height, input_height, 16 * input_height))) { + // The number of used prescalers increases by 1. + ++pre_scaler_num; + // Each time the prescaler is used, the input size is reduced to 1/2 of the original size divided by 2, + // and the size must be 2-pixel aligned. + input_width = AlignDown(input_width / 2, 2); + // The value divided by 2 indicates that the input size is reduced to half of + // the original size and must be 2-pixel aligned. + input_height = AlignDown(input_height / 2, 2); + // If the scaling coefficient is still greater than 4 after prescaler, false is returned. If the + // scaling coefficient is greater than 4 or the number of prescalers is greater than 3, false is returned. + if ((output_width > (4 * input_width)) || (output_height > (4 * input_height)) || (pre_scaler_num > 3)) { + return false; + } + } + return true; +} + +// Creates a scaling parameter stack based on the user input and output information. The elements in the stack are +// the input and output information, and the input and output information stores the scaling information. +void SoftVpc::BuildResizeStack() { + uint32_t in_width = right_ - left_ + 1; + uint32_t in_height_ = down_ - up_ + 1; + ResizeUnit pre_unit = {in_width, in_height_, out_width_, out_height_}; // Scaling information to be split. + + while (!CanVpcChipProcess(pre_unit)) { + uint32_t input_width = pre_unit.in_width; + uint32_t output_width = pre_unit.out_width; + uint32_t input_height = pre_unit.in_height; + uint32_t output_height = pre_unit.out_height; + ResizeUnit can_process_unit = {0, 0, 0, 0}; // Scaling information that can be processed by the chip. + + // Split the input and output, the horizontal scaling coefficient is greater than + // the vertical scaling coefficient. + if (output_width * input_height > output_height * input_width) { + HorizonSplit(&pre_unit, &can_process_unit); + } else { // The horizontal scaling coefficient is less than the vertical scaling coefficient. + VerticalSplit(&pre_unit, &can_process_unit); + } + + can_process_unit.out_width = output_width; + can_process_unit.out_height = output_height; + pre_unit.out_width = can_process_unit.in_width; + pre_unit.out_height = can_process_unit.in_height; + + // Pushes a set of scaled information that can be processed into a stack. + resize_stack_.push(can_process_unit); + } + + // Push the information that can be processed by the chip for one time into the stack. + resize_stack_.push(pre_unit); +} + +int32_t SoftVpc::Yuv422pToYuv420p() { + in_format_ = INPUT_YUV420_PLANNER; + out_width_ = in_width_; + out_height_ = in_height_; + uint32_t buffer_size = out_width_ * out_height_ * yuvCoeffiNum3 / yuvCoeffiNum2; + out_data_ = new (std::nothrow) uint8_t[buffer_size]; + VPC_CHECK_COND_FAIL_PRINT_RETURN((out_data_ != nullptr), dpFail, "alloc buffer fail."); + out_y_data_ = out_data_; + out_u_data_ = out_y_data_ + out_width_ * out_height_; + out_v_data_ = out_u_data_ + out_width_ * out_height_ / yuvCoeffiNum4; + + for (uint32_t i = 0; i < out_height_; i++) { // Y data remains unchanged. + for (uint32_t j = 0; j < out_width_; j++) { + out_y_data_[i * out_width_ + j] = in_y_data_[i * out_width_ + j]; + } + } + + uint32_t yuv420_uv_w = out_width_ / yuvCoeffiNum2; + uint32_t yuv420_uv_h = out_height_ / yuvCoeffiNum2; + // The UV data is reduced by half. Only the UV data of 422 odd rows is obtained. + for (uint32_t i = 0; i < yuv420_uv_h; i++) { + for (uint32_t j = 0; j < yuv420_uv_w; j++) { + out_u_data_[i * yuv420_uv_w + j] = in_u_data_[i * out_width_ + j]; + out_v_data_[i * yuv420_uv_w + j] = in_v_data_[i * out_width_ + j]; + } + } + OutputChangeToInput(); + return dpSucc; +} + +void SoftVpc::ChipPreProcess() { + pre_scaler_num_ = 0; + uint32_t crop_width = (right_ - left_ + 1); + uint32_t crop_height = (down_ - up_ + 1); + // The minimum scaling ratio of the scaler module is 1/4. If the scaling ratio is less than 1/4, the prescaler is + // used for scaling. One prescaler is scaled by 1/2. + while ((out_width_ * scalerTap4 < crop_width) || (out_height_ * scalerTap4 < crop_height)) { + pre_scaler_num_++; + crop_width /= yuvCoeffiNum2; + crop_width = AlignDown(crop_width, yuvCoeffiNum2); + crop_height /= yuvCoeffiNum2; + crop_height = AlignDown(crop_height, yuvCoeffiNum2); + } + // Each time a prescaler is used, the alignment value needs to be doubled. + uint32_t align_size = (yuvCoeffiNum2 << pre_scaler_num_); + crop_width = (right_ - left_ + 1); + uint32_t gap = crop_width % align_size; + left_ += AlignDown(gap / yuvCoeffiNum2, yuvCoeffiNum2); + right_ -= AlignUp(gap / yuvCoeffiNum2, yuvCoeffiNum2); + crop_width -= gap; + + crop_height = (down_ - up_ + 1); + gap = crop_height % align_size; + up_ += AlignDown(gap / yuvCoeffiNum2, yuvCoeffiNum2); + down_ -= AlignUp(gap / yuvCoeffiNum2, yuvCoeffiNum2); + crop_height -= gap; + + uint32_t move_step = scalerCoeff - pre_scaler_num_; + horizon_coeff_ = (crop_width << move_step) / out_width_; + horizon_bypass_ = (horizon_coeff_ == maxCoeff) ? true : false; + vertical_coeff_ = (crop_height << move_step) / out_height_; + vertical_bypass_ = (vertical_coeff_ == maxCoeff) ? true : false; + + half_line_mode_ = false; + // If the width is less than 2048, the half mode is used. + if ((vertical_coeff_ >= 0x2aab) && (vertical_coeff_ <= 0x8000) && (out_width_ <= 2048)) { + half_line_mode_ = true; + } + + YuvWPara *yuv_scaler_paraset = YuvScalerParaSet::GetInstance(); + YuvScalerPara *scale = yuv_scaler_paraset->scale; + int32_t index = GetScalerParamterIndex(horizon_coeff_, yuv_scaler_paraset); + y_horizon_tap_ = scale[index].taps_6; + uv_horizon_tap_ = scale[index].taps_4; + + index = GetScalerParamterIndex(vertical_coeff_, yuv_scaler_paraset); + vertical_tap_ = (half_line_mode_) ? scale[index].taps_6 : scale[index].taps_4; +} + +void SoftVpc::SetUvValue(int32_t *u_value, int32_t *v_value, int32_t y, int32_t pos) { + int32_t crop_width = right_ - left_ + 1; + int32_t in_w_stride = in_width_; + // 5-order filtering dimension reduction algorithm. + for (uint32_t i = 0; i < uvReductCoeffNum; i++) { + int32_t index = pos + i - uvReductCoeffNum / yuvCoeffiNum2; + if ((index + static_cast(left_) % 0x80) < 0) { + index = -index; + } + if (index > (crop_width - 1)) { + index = yuvCoeffiNum2 * (crop_width - 1) - index; + } + *u_value += in_u_data_[y * in_w_stride + index] * uvReductCoeff[i]; + *v_value += in_v_data_[y * in_w_stride + index] * uvReductCoeff[i]; + } +} + +int32_t SoftVpc::Yuv444PackedToYuv422Packed() { + int32_t in_w_stride = in_width_; + int32_t crop_width = right_ - left_ + 1; + int32_t crop_height = down_ - up_ + 1; + out_width_ = crop_width; + out_height_ = crop_height; + + out_data_ = new (std::nothrow) uint8_t[out_width_ * out_height_ * yuvCoeffiNum2]; + VPC_CHECK_COND_FAIL_PRINT_RETURN((out_data_ != nullptr), dpFail, "alloc buffer fail."); + SetYuv422OutBuffer(); + + for (int32_t i = 0; i < crop_height; i++) { // 拷贝y数据 + int32_t ret = memcpy_s(out_y_data_ + i * crop_width, crop_width, in_y_data_ + i * in_w_stride, crop_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + } + + int32_t uv_width = crop_width / yuvCoeffiNum2; + // Reduces the dimension of the UV data. The 5-order filtering algorithm is used for dimension reduction. + for (int32_t y = 0; y < crop_height; y++) { + for (int32_t x = 0; x < uv_width; x++) { + int32_t pos = static_cast(x) << 1; + int32_t u_value = 0; + int32_t v_value = 0; + + SetUvValue(&u_value, &v_value, y, pos); + // The most significant eight bits of the dimension reduction result are used. + u_value = static_cast(u_value + 0x80) >> 8; + v_value = static_cast(v_value + 0x80) >> 8; + if (u_value > 0xff) u_value = 0xff; + if (v_value > 0xff) v_value = 0xff; + out_u_data_[y * uv_width + x] = u_value; + out_v_data_[y * uv_width + x] = v_value; + } + } + + in_format_ = INPUT_YUV422_PLANNER; + OutputChangeToInput(); + return dpSucc; +} + +// For the YUV420 input, the output width and height are reduced by 1/2, the output format is YUV422, +// and the amount of output UV data is reduced by only half. +void SoftVpc::Yuv420PlannerUvPrescaler(uint8_t *(&in_uv_data)[yuvCoeffiNum2], uint8_t *(&out_uv_data)[yuvCoeffiNum2], + uint32_t in_w_stride) { + for (uint32_t k = 0; k < yuvCoeffiNum2; k++) { + for (uint32_t i = 0; i < out_height_; i++) { + for (uint32_t j = 0; j < out_width_ / yuvCoeffiNum2; j++) { // Zoom out by 1/2 + uint8_t a = in_uv_data[k][i * in_w_stride / yuvCoeffiNum2 + yuvCoeffiNum2 * j]; + uint8_t b = in_uv_data[k][i * in_w_stride / yuvCoeffiNum2 + yuvCoeffiNum2 * j + 1]; + out_uv_data[k][i * out_width_ / yuvCoeffiNum2 + j] = (a + b + 1) / yuvCoeffiNum2; + } + } + } +} + +// For the YUV420 input, the output width and height are reduced by 1/2, the output format is YUV422, and the +// amount of output UV data is reduced by 3/4. The prescaler scaling algorithm is a bilinear interpolation +// algorithm. The scaling ratio is 1/2 horizontally and vertically. That is, two horizontal points are combined +// into one point, and two vertical points are combined into one point. +void SoftVpc::Yuv422PackedUvPrescaler(uint8_t *(&in_uv_data)[yuvCoeffiNum2], uint8_t *(&out_uv_data)[yuvCoeffiNum2], + uint32_t in_w_stride) { + for (uint32_t k = 0; k < yuvCoeffiNum2; k++) { + for (uint32_t i = 0; i < out_height_; i++) { + for (uint32_t j = 0; j < out_width_ / yuvCoeffiNum2; j++) { + uint8_t a = in_uv_data[k][i * in_w_stride + yuvCoeffiNum2 * j]; + uint8_t b = in_uv_data[k][i * in_w_stride + yuvCoeffiNum2 * j + 1]; + uint8_t aa = (a + b + 1) / yuvCoeffiNum2; + uint8_t c = in_uv_data[k][(yuvCoeffiNum2 * i + 1) * in_w_stride / yuvCoeffiNum2 + yuvCoeffiNum2 * j]; + uint8_t d = in_uv_data[k][(yuvCoeffiNum2 * i + 1) * in_w_stride / yuvCoeffiNum2 + yuvCoeffiNum2 * j + 1]; + uint8_t bb = (c + d + 1) / yuvCoeffiNum2; + out_uv_data[k][i * out_width_ / yuvCoeffiNum2 + j] = (aa + bb + 1) / yuvCoeffiNum2; + } + } + } +} + +void SoftVpc::UvPrescaler() { + uint32_t in_w_stride = in_width_; + uint8_t *in_uv_data[yuvCoeffiNum2] = {in_u_data_, in_v_data_}; + uint8_t *out_uv_data[yuvCoeffiNum2] = {out_u_data_, out_v_data_}; + if (in_format_ == INPUT_YUV420_PLANNER) { + Yuv420PlannerUvPrescaler(in_uv_data, out_uv_data, in_w_stride); + } else { + Yuv422PackedUvPrescaler(in_uv_data, out_uv_data, in_w_stride); + } +} + +int32_t SoftVpc::PreScaler() { + uint32_t in_w_stride = in_width_; + uint32_t crop_width = right_ - left_ + 1; + uint32_t crop_height = down_ - up_ + 1; + out_width_ = crop_width / yuvCoeffiNum2; + out_height_ = crop_height / yuvCoeffiNum2; + out_data_ = new (std::nothrow) uint8_t[out_width_ * out_height_ * yuvCoeffiNum2]; + VPC_CHECK_COND_FAIL_PRINT_RETURN((out_data_ != nullptr), dpFail, "alloc buffer fail."); + SetYuv422OutBuffer(); + + // The scaling algorithm of the rescaler is a bilinear interpolation algorithm. The scaling ratio is 1/2 + // horizontally and vertically. That is, two horizontal points are combined into one point, + // and two vertical points are combined into one point. + for (uint32_t i = 0; i < out_height_; i++) { + for (uint32_t j = 0; j < out_width_; j++) { + uint8_t a = in_y_data_[yuvCoeffiNum2 * i * in_w_stride + yuvCoeffiNum2 * j]; + uint8_t b = in_y_data_[yuvCoeffiNum2 * i * in_w_stride + yuvCoeffiNum2 * j + 1]; + uint8_t aa = (a + b + 1) / yuvCoeffiNum2; + uint8_t c = in_y_data_[(yuvCoeffiNum2 * i + 1) * in_w_stride + yuvCoeffiNum2 * j]; + uint8_t d = in_y_data_[(yuvCoeffiNum2 * i + 1) * in_w_stride + yuvCoeffiNum2 * j + 1]; + uint8_t bb = (c + d + 1) / yuvCoeffiNum2; + out_y_data_[i * out_width_ + j] = (aa + bb + 1) / yuvCoeffiNum2; + } + } + UvPrescaler(); + + in_format_ = INPUT_YUV422_PLANNER; + OutputChangeToInput(); + return dpSucc; +} + +int32_t SoftVpc::BypassHorizonScaler() { + uint32_t in_w_stride = in_width_; + uint32_t crop_width = right_ - left_ + 1; + uint32_t crop_height = down_ - up_ + 1; + for (uint32_t i = 0; i < crop_height; i++) { + int32_t ret = memcpy_s(out_y_data_ + i * crop_width, crop_width, in_y_data_ + i * in_w_stride, crop_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + } + + uint32_t uv_w_stride = in_w_stride / yuvCoeffiNum2; + uint32_t uv_width = crop_width / yuvCoeffiNum2; + + // The input format is 420. After the format is converted to 422, the UV data is doubled. + // Therefore, the data needs to be copied twice. + if (in_format_ == INPUT_YUV420_PLANNER) { + uint32_t uv_height = crop_height / yuvCoeffiNum2; + for (uint32_t i = 0; i < uv_height; i++) { + int32_t ret = + memcpy_s(out_u_data_ + uv_width * i * yuvCoeffiNum2, uv_width, in_u_data_ + uv_w_stride * i, uv_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + ret = + memcpy_s(out_u_data_ + uv_width * (i * yuvCoeffiNum2 + 1), uv_width, in_u_data_ + uv_w_stride * i, uv_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + + ret = memcpy_s(out_v_data_ + uv_width * i * yuvCoeffiNum2, uv_width, in_v_data_ + uv_w_stride * i, uv_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + ret = + memcpy_s(out_v_data_ + uv_width * (i * yuvCoeffiNum2 + 1), uv_width, in_v_data_ + uv_w_stride * i, uv_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + } + } else { + uint32_t uv_height = crop_height; + for (uint32_t i = 0; i < uv_height; i++) { + int32_t ret = memcpy_s(out_u_data_ + uv_width * i, uv_width, in_u_data_ + uv_w_stride * i, uv_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + ret = memcpy_s(out_v_data_ + uv_width * i, uv_width, in_v_data_ + uv_w_stride * i, uv_width); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "memcpy fail."); + } + } + return dpSucc; +} + +void SoftVpc::StartHorizonScalerEx(uint32_t width_index, uint32_t tmp_offset, uint8_t *(&in_data)[yuvCoeffiNum3], + uint8_t *(&out_data)[yuvCoeffiNum3]) { + int16_t *taps[yuvCoeffiNum3] = {y_horizon_tap_, uv_horizon_tap_, uv_horizon_tap_}; + int32_t crop_w = right_ - left_; + int32_t in_w[yuvCoeffiNum3] = {crop_w, crop_w / scalerTap2, crop_w / scalerTap2}; + uint32_t taps_num[yuvCoeffiNum3] = {scalerTap6, scalerTap4, scalerTap4}; + uint32_t out_w[yuvCoeffiNum3] = {out_width_, out_width_ / yuvCoeffiNum2, out_width_ / yuvCoeffiNum2}; + uint32_t mid_num = (taps_num[width_index] >> 1) - 1; + uint32_t acc = 0; + + // higher order filter algorithm + // Map the output position to the input position, calculate the phase based on the input position, and find the + // corresponding filter (6-order or 4-order filter window) based on the phase. + // The input data and the filter perform convolution operation to obtain the output data. + for (uint32_t j = 0; j < out_w[width_index]; j++) { + uint32_t pos = acc >> bit16Offset; + uint32_t phase = (acc >> bit13Offset) & low3BitVal; + int16_t *coeffs = taps[width_index] + taps_num[width_index] * phase; + + int32_t value = 0; + for (uint32_t k = 0; k < taps_num[width_index]; k++) { // convolution operation + int32_t index = pos + k - mid_num; + index = TruncatedFunc(index, 0, in_w[width_index]); + int32_t v1 = static_cast(in_data[width_index][tmp_offset + index]); + int32_t v2 = static_cast(coeffs[k]); + value += v1 * v2; + } + + value = TruncatedFunc((value + 0x80), 0, low16BitVal); + value = static_cast(value) >> bit8Offset; + + *out_data[width_index]++ = static_cast(value); + acc += horizon_coeff_; + } + return; +} + +void SoftVpc::HorizonScalerEx() { + uint8_t *in_data[yuvCoeffiNum3] = {in_y_data_, in_u_data_, in_v_data_}; + uint8_t *out_data[yuvCoeffiNum3] = {out_y_data_, out_u_data_, out_v_data_}; + uint32_t in_w_stride[yuvCoeffiNum3] = {in_width_, in_width_ / yuvCoeffiNum2, in_width_ / yuvCoeffiNum2}; + + for (uint32_t m = 0; m < yuvCoeffiNum3; m++) { + for (uint32_t i = 0; i < out_height_; i++) { + auto tmp_offset = i * in_w_stride[m]; // Offset of each row of data relative to the start position. + if ((m > 0) && (in_format_ == INPUT_YUV420_PLANNER)) { + // The width of the UV channel is half of that of the Y channel. + tmp_offset = i / yuvCoeffiNum2 * in_w_stride[m]; + } + StartHorizonScalerEx(m, tmp_offset, in_data, out_data); + } + } +} + +int32_t SoftVpc::HorizonScaler() { + uint32_t crop_width = right_ - left_ + 1; + uint32_t crop_height = down_ - up_ + 1; + out_width_ = (crop_width << scalerCoeff) / horizon_coeff_; + out_height_ = crop_height; + out_data_ = new (std::nothrow) uint8_t[out_width_ * out_height_ * yuvCoeffiNum2]; + VPC_CHECK_COND_FAIL_PRINT_RETURN((out_data_ != nullptr), dpFail, "alloc buffer fail."); + SetYuv422OutBuffer(); + + // in bypass mode, the input and output sizes are the same. + // To be compatible with the YUV420 output, the YUV422 format is used. + if (horizon_bypass_) { + int32_t ret = BypassHorizonScaler(); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "BypassHorizonScaler fail."); + } else { + HorizonScalerEx(); + } + + in_format_ = INPUT_YUV422_PLANNER; + OutputChangeToInput(); + return dpSucc; +} + +void SoftVpc::StartVerticalScaler(uint32_t yuv_index, uint32_t out_w[], uint8_t *(&in_data)[yuvCoeffiNum3], + uint8_t *(&out_data)[yuvCoeffiNum3]) { + uint32_t num_taps = half_line_mode_ ? scalerTap6 : scalerTap4; + uint32_t mid_num = (num_taps >> 1) - 1; + int32_t max_offset = in_height_ - 1; + + // higher order filter algorithm + // Map the output position to the input position, calculate the phase based on the input position, and find the + // corresponding filter (6-order or 4-order filter window) based on the phase. The input data and the filter + // perform convolution operation to obtain the output data. + for (uint32_t i = 0; i < out_height_; i++) { + uint32_t acc = i * vertical_coeff_; + uint32_t pos = acc >> bit16Offset; + uint32_t phase = (acc >> bit13Offset) & low3BitVal; + int16_t *coeffs = vertical_tap_ + num_taps * phase; + for (uint32_t j = 0; j < out_w[yuv_index]; j++) { + int32_t value = 0; + for (uint32_t k = 0; k < num_taps; k++) { // convolution operation + int32_t index = pos + k - mid_num; + index = TruncatedFunc(index, 0, max_offset); + int32_t v1 = in_data[yuv_index][index * out_w[yuv_index] + j]; + int32_t v2 = coeffs[k]; + value += v1 * v2; + } + value = TruncatedFunc((value + 0x80), 0, low16BitVal); + value = static_cast(value) >> bit8Offset; + *out_data[yuv_index]++ = static_cast(value); + } + } + return; +} + +int32_t SoftVpc::VerticalScaler() { + out_width_ = in_width_; + out_height_ = (in_height_ << scalerCoeff) / vertical_coeff_; + out_data_ = new (std::nothrow) uint8_t[out_width_ * out_height_ * yuvCoeffiNum2]; + VPC_CHECK_COND_FAIL_PRINT_RETURN((out_data_ != nullptr), dpFail, "alloc buffer fail."); + SetYuv422OutBuffer(); + + uint8_t *in_data[yuvCoeffiNum3] = {in_y_data_, in_u_data_, in_v_data_}; + uint8_t *out_data[yuvCoeffiNum3] = {out_y_data_, out_u_data_, out_v_data_}; + uint32_t out_w[yuvCoeffiNum3] = {out_width_, out_width_ / yuvCoeffiNum2, out_width_ / yuvCoeffiNum2}; + for (uint32_t m = 0; m < yuvCoeffiNum3; m++) { + StartVerticalScaler(m, out_w, in_data, out_data); + } + + OutputChangeToInput(); + return dpSucc; +} + +// yuv scalser is core scaler, The high-order filtering and scaling algorithm is used. +int32_t SoftVpc::YuvScaler() { + int32_t ret = HorizonScaler(); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "HorizonScaler fail."); + if (!vertical_bypass_) { + ret = VerticalScaler(); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "VerticalScaler fail."); + } + return ret; +} + +int32_t SoftVpc::ChipProcess() { + ChipPreProcess(); + // Determine whether dimension reduction is required. + if (in_format_ == INPUT_YUV444_PLANNER) { + VPC_CHECK_COND_FAIL_PRINT_RETURN((Yuv444PackedToYuv422Packed() == dpSucc), dpFail, + "Yuv444PackedToYuv422Packed fail."); + } + + // Analog chip PreScaler function + for (uint32_t i = 0; i < pre_scaler_num_; i++) { + VPC_CHECK_COND_FAIL_PRINT_RETURN((PreScaler() == dpSucc), dpFail, "PreScaler fail."); + } + + // Analog chip Yuv Scaler function + VPC_CHECK_COND_FAIL_PRINT_RETURN((YuvScaler() == dpSucc), dpFail, "YuvScaler fail."); + return dpSucc; +} + +void SoftVpc::YuvToRgb() { + uint8_t *out_data = out_info_.addr; + int32_t yy, uu, vv; + int32_t rr, gg, bb; + for (uint32_t j = 0; j < in_height_; j++) { + for (uint32_t i = 0; i < in_width_; i++) { + yy = in_y_data_[(j * in_width_) + i]; + uu = in_u_data_[((j - (j % num2)) * (in_width_ / yuvCoeffiNum2)) + (i / yuvCoeffiNum2)]; + vv = in_v_data_[((j - (j % num2)) * (in_width_ / yuvCoeffiNum2)) + (i / yuvCoeffiNum2)]; + + // yuv convert rgb formula + rr = ((yy - rtAippYuv2RgbCscInputBias0) * rtAippYuv2RgbCscMatrixR0c0 + + (uu - rtAippYuv2RgbCscInputBias1) * rtAippYuv2RgbCscMatrixR0c1 + + (vv - rtAippYuv2RgbCscInputBias2) * rtAippYuv2RgbCscMatrixR0c2) / + rtAippConverCoeffi; + gg = ((yy - rtAippYuv2RgbCscInputBias0) * rtAippYuv2RgbCscMatrixR1c0 + + (uu - rtAippYuv2RgbCscInputBias1) * rtAippYuv2RgbCscMatrixR1c1 + + (vv - rtAippYuv2RgbCscInputBias2) * rtAippYuv2RgbCscMatrixR1c2) / + rtAippConverCoeffi; + bb = ((yy - rtAippYuv2RgbCscInputBias0) * rtAippYuv2RgbCscMatrixR2c0 + + (uu - rtAippYuv2RgbCscInputBias1) * rtAippYuv2RgbCscMatrixR2c1 + + (vv - rtAippYuv2RgbCscInputBias2) * rtAippYuv2RgbCscMatrixR2c2) / + rtAippConverCoeffi; + + *out_data++ = (rr < 0) ? 0 : ((rr < 0xff) ? rr : 0xff); + *out_data++ = (gg < 0) ? 0 : ((gg < 0xff) ? gg : 0xff); + *out_data++ = (bb < 0) ? 0 : ((bb < 0xff) ? bb : 0xff); + } + } + + delete[] in_data_; + in_data_ = nullptr; +} + +int32_t SoftVpc::Process(VpcInfo input, const SoftDpCropInfo crop, const VpcInfo output) { + Init(input, crop, output); + int32_t ret = CheckParamter(); + if (ret != dpSucc) { + delete[] input.addr; + return ret; + } + + BuildResizeStack(); + while (!resize_stack_.empty()) { + ResizeUnit &unit = resize_stack_.top(); + resize_stack_.pop(); + + out_width_ = unit.out_width; + out_height_ = unit.out_height; + + ret = ChipProcess(); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "ChipProcess fail."); + + if (!resize_stack_.empty()) { + ret = Yuv422pToYuv420p(); + VPC_CHECK_COND_FAIL_PRINT_RETURN((ret == dpSucc), dpFail, "Yuv422pToYuv420p fail."); + } + } + YuvToRgb(); + + return dpSucc; +} diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.h new file mode 100644 index 0000000000..4622d7d16e --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.h @@ -0,0 +1,256 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 SOFT_VPC_H +#define SOFT_VPC_H + +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp.h" +#include + +constexpr uint32_t yuvCoeffiNum2 = 2; +constexpr uint32_t yuvCoeffiNum3 = 3; + +struct ResizeUnit { + uint32_t in_width; + uint32_t in_height; + uint32_t out_width; + uint32_t out_height; +}; + +class SoftVpc { + public: + SoftVpc(); + + ~SoftVpc() {} + + /* + * @brief : vpc Cropping and Scaling APIs. + * @param [in] VpcInfo input : Structure input to the VPC for processing. + * @param [in] SoftDpCropInfo crop : crop struct. + * @param [in] VpcInfo output : vpc output struct. + * @return : dpSucc:vpc process succ,dpFail:vpc process failed. + */ + int32_t Process(VpcInfo input, SoftDpCropInfo crop, VpcInfo output); + + private: + enum JpegdToVpcFormat in_format_; + uint32_t in_width_; + uint32_t in_height_; + uint8_t *in_data_; + uint8_t *in_y_data_; + uint8_t *in_u_data_; + uint8_t *in_v_data_; + + // crop area + uint32_t left_; + uint32_t right_; + uint32_t up_; + uint32_t down_; + + // output config + uint32_t out_width_; + uint32_t out_height_; + uint8_t *out_data_; + uint8_t *out_y_data_; + uint8_t *out_u_data_; + uint8_t *out_v_data_; + + // resize config + uint32_t pre_scaler_num_; + + // If the image is amplified by 2x or more and the output width is less than 2048 pixels, + // the half-line mode is required. + bool half_line_mode_; + uint32_t horizon_coeff_; // Horizontal scaling coefficient + uint32_t vertical_coeff_; // Vertical scaling coefficient. + bool horizon_bypass_; + bool vertical_bypass_; + int16_t *y_horizon_tap_; // Filtering coefficients for horizontal scaling of channel y + int16_t *uv_horizon_tap_; // Filtering coefficients of the horizontal scaling UV channel. + int16_t *vertical_tap_; // Filtering coefficient table for vertical scaling. Y and UV signals share the same table. + + // Scaling unit stack, used to store the input and output information processed by the chip at a time. + std::stack resize_stack_; + VpcInfo in_info_; // Original input information. + VpcInfo out_info_; // Original output information. + + /* + * @brief : set output format is YUV422 + */ + void SetYuv422OutBuffer(); + + /* + * @brief : check params + * @return : dpSucc:check succ, dpFail:check failed. + */ + int32_t CheckParamter(); + + /* + * @brief : init vpc output info struct + * @param [in] VpcInfo input : Structure input to the VPC for processing. + * @param [in] SoftDpCropInfo crop : crop struct. + * @param [in] VpcInfo output : vpc output struct. + */ + void Init(VpcInfo input, SoftDpCropInfo crop, VpcInfo output); + + void OutputChangeToInput(); + + /* + * @brief : For the tasks that cannot be processed by the chip at a time, split the tasks whose scaling + * coefficients in the horizontal direction are greater than those in the vertical direction. + * @param [in] ResizeUnit *pre_unit : input resize unit. + * @param [in] ResizeUnit *can_process_unit : chip can process resize unit. + */ + void HorizonSplit(ResizeUnit *pre_unit, ResizeUnit *can_process_unit); + + /* + * @brief : For the tasks that cannot be processed by the chip at a time, split the tasks whose vertical scaling + * coefficients are greater than the horizontal scaling coefficients. + * @param [in] ResizeUnit *pre_unit : input resize unit. + * @param [in] ResizeUnit *can_process_unit : chip can process resize unit. + */ + void VerticalSplit(ResizeUnit *pre_unit, ResizeUnit *can_process_unit); + + /* + * @brief : Check whether the VPC chip can complete the processing at a time based on the input and output sizes. + * @param [in] const ResizeUnit& pre_unit : input resize unit. + * @return : true:vpc process succ, false:vpc process failed. + */ + bool CanVpcChipProcess(const ResizeUnit &pre_unit); + + /* + * @brief : Creates a scaling parameter stack based on the user input and output information. The elements + * in the stack are the input and output information. The input and output information stores the + * scaling information task. + */ + void BuildResizeStack(); + + /* + * @brief : YUV422 planner format convert YUV420 format + * @return : dpSucc: downsampling success, dpFail: downsampling failed + */ + int32_t Yuv422pToYuv420p(); + + /* + * @brief : Preprocesses the chip, calculates the number of chip prescalers, and adjusts the cropping area based on + * the input and output information. + */ + void ChipPreProcess(); + + /* + * @brief : when YUV444 packed format convert YUV422 packed, Calculate the conversion of UV. + * @param [in] int32_t *u_value : u value. + * @param [in] int32_t *v_value : v value. + * @param [in] int32_t y :y value. + * @param [in] int32_t pos : + */ + void SetUvValue(int32_t *u_value, int32_t *v_value, int32_t y, int32_t pos); + + /* + * @brief : YUV444 packed convert YUV422 packed. + * @return : dpSucc:Downsampling succ, dpFail:Downsampling failed. + */ + int32_t Yuv444PackedToYuv422Packed(); + + /* + * @brief : Pre-scaling the UV image. + */ + void UvPrescaler(); + + /* + * @brief : Prescaling the UV in YUV420 format. + * @param [in] uint8_t* (&in_uv_data)[yuvCoeffiNum2] : input uv data + * @param [in] uint8_t* (&out_uv_data)[yuvCoeffiNum2] : output uv data + * @param [in] uint32_t in_w_stride : input stride + */ + void Yuv420PlannerUvPrescaler(uint8_t *(&in_uv_data)[yuvCoeffiNum2], uint8_t *(&out_uv_data)[yuvCoeffiNum2], + uint32_t in_w_stride); + + /* + * @brief : Prescaling the UV in YUV422 format. + * @param [in] uint8_t* (&in_uv_data)[yuvCoeffiNum2] : input uv data + * @param [in] uint8_t* (&out_uv_data)[yuvCoeffiNum2]: output uv data + * @param [in] uint32_t in_w_stride : input stride + */ + void Yuv422PackedUvPrescaler(uint8_t *(&in_uv_data)[yuvCoeffiNum2], uint8_t *(&out_uv_data)[yuvCoeffiNum2], + uint32_t in_w_stride); + + /* + * @brief : Chip prescaler processing. + */ + int32_t PreScaler(); + + /* + * @brief : Horizontal scaling bypass. + */ + int32_t BypassHorizonScaler(); + + /* + * @brief : Single-channel horizontal scaling of the chip. + * @param [in] uint32_t width_index : index of output width array. + * @param [in] uint32_t tmp_offset : Offset of each row of data relative to the start position. + * @param [in] uint8_t* (&in_data)[yuvCoeffiNum3] : input y,u,v data array. + * @param [in] uint8_t* (&out_data)[yuvCoeffiNum3] : output y,u,v data array. + */ + void StartHorizonScalerEx(uint32_t width_index, uint32_t tmp_offset, uint8_t *(&in_data)[yuvCoeffiNum3], + uint8_t *(&out_data)[yuvCoeffiNum3]); + + /* + * @brief : Horizontal scaling. + */ + void HorizonScalerEx(); + + /* + * @brief : Horizontal scaling. + * @return : dpSucc : Horizontal scaling succ, dpFail:Horizontal scaling failed. + */ + int32_t HorizonScaler(); + + /* + * @brief : start Vertical scaling. + * @param [in] uint32_t yuv_index : index of output width array. + * @param [in] uint32_t out_w[] : output width array. + * @param [in] uint8_t* (&in_data)[yuvCoeffiNum3] : input y,u,v data array. + * @param [in] uint8_t* (&out_data)[yuvCoeffiNum3] : output y,u,v data array. + */ + void StartVerticalScaler(uint32_t yuv_index, uint32_t out_w[], uint8_t *(&in_data)[yuvCoeffiNum3], + uint8_t *(&out_data)[yuvCoeffiNum3]); + + /* + * @brief : Vertical scaling + * @return : dpSucc : Vertical scaling succ, dpFail : Vertical scaling failed. + */ + int32_t VerticalScaler(); + + /* + * @brief : Yuv Scaler Horizontal scaling and vertical scaling. + * @return : dpSucc:yuv scaler succ. dpFail:yuv scaler failed. + */ + int32_t YuvScaler(); + + /* + * @brief : Software Implementation of the Simulation Chip PreScaler and Yuv Scaler function. + * @return : dpSucc : Analog chip scaling succ, dpFail: Analog chip scaling failed. + */ + int32_t ChipProcess(); + + /* + * @brief : YUV planner convert RGB format. + */ + void YuvToRgb(); +}; + +#endif // SOFT_VPC_H diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.cc new file mode 100644 index 0000000000..4e32c0cd32 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.cc @@ -0,0 +1,280 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.h" +#include +#include +#include +#include +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h" +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_tools.h" + +pthread_mutex_t YuvScalerParaSet::g_mutex_ = PTHREAD_MUTEX_INITIALIZER; +YuvWPara *YuvScalerParaSet::g_m_instance_ = nullptr; +YuvScalerParaSet::GarbageCollector YuvScalerParaSet::g_collector_; + +const int32_t dpSucc = 0; +const int32_t dpFail = -1; + +/* + * @brief : Replaces the specified symbol in a string with another symbol. + * @param [in] const string &strSrc : src string. + * @param [in] const string &strDst : dest string. + */ +void StringReplace(std::string *str_big, const std::string &str_src, const std::string &str_dst) { + std::string::size_type pos = 0; + std::string::size_type src_len = str_src.size(); + std::string::size_type dst_len = str_dst.size(); + while ((pos = str_big->find(str_src, pos)) != std::string::npos) { + str_big->replace(pos, src_len, str_dst); + pos += dst_len; + } +} + +/* + * @brief : Parse the data in the character string and transfer the data to the structure. + * @param [in] string strLine : parsed string. + * @param [in] int32_t *flagCtl : the number of char. + * @param [in] int32_t *flagTap : the flag of char. + * @param [in] YuvWPara *yuvScalerParaSet : yuv scaler param sets. + * @param [in] ScalerCoefficientIndex *index : scaler index. + */ +void GetParaSet(std::string str_line, int32_t *flag_ctl, int32_t *flag_tap, YuvWPara *yuv_scaler_paraset, + ScalerCoefficientIndex *index) { + std::stringstream ss; + StringReplace(&str_line, ",", " "); // Replaces commas in a string with spaces. + ss.str(str_line); + int32_t cnt = yuv_scaler_paraset->real_count; // Number of saved arrays. + const int32_t arrTypeNum = 3; + const int32_t initBracketNum = 3; + + // {start,end} + if ((*flag_ctl - initBracketNum) % arrTypeNum == 1) { + char chTmp; + ss >> chTmp >> yuv_scaler_paraset->scale[cnt].range.start >> yuv_scaler_paraset->scale[cnt].range.end; + + if (ss.fail()) { // read failed. +#ifndef DVPP_UTST + ss.clear(); +#endif + } + } + + // taps_4, the second character in the square brackets is the start address of the array block. + if ((*flag_ctl - initBracketNum) % arrTypeNum == 2) { + while (1) { + ss >> yuv_scaler_paraset->scale[cnt].taps_4[index->first_index++]; + if (ss.fail()) { // rerad failed. + index->first_index = index->first_index - 1; + ss.clear(); + break; + } + + if (index->first_index == kScalerCoffNb4) { // read finish + index->first_index = 0; + *flag_tap = 0; + ss.clear(); + break; + } + } + } + + // taps_6 + if ((*flag_ctl - initBracketNum) % arrTypeNum == 0) { + while (1) { + ss >> yuv_scaler_paraset->scale[cnt].taps_6[index->second_index++]; + if (ss.fail()) { // read failed. + index->second_index = index->second_index - 1; + ss.clear(); + break; + } + + if (index->second_index == kScalerCoffNb6) { // read finish. + index->second_index = 0; + *flag_tap = 0; + ss.clear(); + ++(yuv_scaler_paraset->real_count); + *flag_ctl = *flag_ctl - 4; // The filtering parameter set has four large blocks. + break; + } + } + } +} + +int32_t CheckParamater(std::pair rlt, uint32_t i) { + int32_t ret = dpSucc; + if (rlt.first == false) { + API_LOGE("Get real path failed. index = %u", i); + return dpFail; + } + + if (IsDirectory(rlt.second)) { + API_LOGE("It is a directory, not file path. index = %u", i); + return dpFail; + } + + return ret; +} + +// Read the parameter set file and skip the comments in the file. +int32_t ParseFileToVar(std::string *para_set_name, uint32_t yuv_scaler_paraset_size, YuvWPara *yuv_scaler_paraset) { + int32_t ret = dpSucc; + + VPC_CHECK_COND_FAIL_RETURN(para_set_name != nullptr, dpFail); + VPC_CHECK_COND_FAIL_RETURN(yuv_scaler_paraset != nullptr, dpFail); + + uint32_t i = 0; + while (i < yuv_scaler_paraset_size && i < maxFileCount && (!para_set_name[i].empty())) { + std::string str_line; + + // Standardize the file path and check whether the path exists. + std::pair rlt = GetRealpath(para_set_name[i]); + ret = CheckParamater(rlt, i); + if (ret != dpSucc) { + return ret; + } + + std::ifstream inFile(rlt.second); + + int32_t flag_tap = 1; + int32_t flag_ctl = 0; + int32_t flag_anno = 0; + ScalerCoefficientIndex index; + const int32_t initBracketNum = 3; + yuv_scaler_paraset[i].real_count = 0; + + while (getline(inFile, str_line)) { // read each row of data. + // Skip the comments. + if (str_line.find("/*") != std::string::npos) { + flag_anno = 1; + continue; + } + + if (flag_anno) { + if (str_line.find("*/") != std::string::npos) { + flag_anno = 0; + continue; + } + continue; + } + + if (str_line.find("//") != std::string::npos) { + continue; + } + + // cale the number of "{",check the location of the data. + if (str_line.find("{") != std::string::npos) { + flag_ctl++; + flag_tap = 1; + } + + if (flag_ctl > initBracketNum && flag_tap == 1) { // parse params + GetParaSet(str_line, &flag_ctl, &flag_tap, &yuv_scaler_paraset[i], &index); + } + } + + inFile.close(); + ++i; + } + return ret; +} + +YuvWPara *YuvScalerParaSet::GetInstance(std::string *paraset_name, uint32_t yuv_scaler_paraset_size) { + if (g_m_instance_ == nullptr) { + (void)pthread_mutex_lock(&g_mutex_); + if (g_m_instance_ == nullptr) { + if (paraset_name == nullptr) { +#ifndef API_MAR_UT +#ifdef DVPP_UTST + YuvWPara p_tmp[10]; // 10: 滤波参数集最大数 + p_tmp[0] = YUV_W_PARA; + g_m_instance_ = p_tmp; +#else + auto p_tmp = static_cast(malloc(sizeof(YuvWPara) * maxFileCount)); + if (p_tmp == nullptr) { + API_LOGE("malloc YuvWPara fail!"); + g_m_instance_ = nullptr; + (void)pthread_mutex_unlock(&g_mutex_); + return g_m_instance_; + } + + uint32_t ret = memcpy_s(&p_tmp[0], sizeof(p_tmp[0]), &YUV_W_PARA, sizeof(YUV_W_PARA)); + if (ret != EOK) { + API_LOGE("memcpy_s p_tmp[0] fail!"); + g_m_instance_ = nullptr; + free(p_tmp); + p_tmp = nullptr; + (void)pthread_mutex_unlock(&g_mutex_); + return g_m_instance_; + } + + g_m_instance_ = p_tmp; +#endif +#endif + } else { + auto p_tmp = static_cast(malloc(sizeof(YuvWPara) * maxFileCount)); + if (p_tmp == nullptr) { +#ifndef DVPP_UTST + API_LOGE("malloc YuvWPara fail!"); + g_m_instance_ = nullptr; + (void)pthread_mutex_unlock(&g_mutex_); + return g_m_instance_; +#endif + } + + if (ParseFileToVar(paraset_name, yuv_scaler_paraset_size, p_tmp) == -1) { + free(p_tmp); + g_m_instance_ = nullptr; + } else { + g_m_instance_ = p_tmp; + } + } + } + (void)pthread_mutex_unlock(&g_mutex_); + } + return g_m_instance_; +} + +// Searching for the index number of the filtering parameter by using the dichotomy +int32_t GetScalerParamterIndex(uint32_t paramter, YuvWPara *paramterset) { + int32_t count = paramterset->real_count; + int32_t left = 0; + int32_t right = count - 1; + YuvScalerPara *scaler = paramterset->scale; + int32_t index = 0; + + if (paramter <= scalerRadio1Time) { + index = 0; + } else { + paramter = paramter >> paramterInterval; + while (left <= right) { + index = (left + right) / 2; // 2-point search + if (paramter > scaler[index].range.start && paramter <= scaler[index].range.end) { + break; + } + if (paramter > scaler[index].range.end) { + left = index + 1; + } else if (paramter <= scaler[index].range.start) { + right = index - 1; + } + } + } + + if (left > right) { + index = count - 1; + } + return index; +} diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.h b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.h new file mode 100644 index 0000000000..95c01edc24 --- /dev/null +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/soft_dvpp/utils/yuv_scaler_para_set.h @@ -0,0 +1,12565 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 YUV_SCALER_PARA_SET +#define YUV_SCALER_PARA_SET + +#include +#include +#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_log.h" + +const uint32_t maxFileCount = 10; +const uint32_t kMaxParaCount = 2048; +const uint32_t kScalerCoffNb4 = 32; +const uint32_t kScalerCoffNb6 = 48; +const uint32_t paramterInterval = 6; // scaler Number of bits between each group of filtering coefficients +const uint32_t scalerRadio1Time = 0X10000; + +struct ScalerCoefficientIndex { + uint32_t first_index; + uint32_t second_index; + + ScalerCoefficientIndex() : first_index(0), second_index() {} +}; + +struct YuvScalerPara { + struct { + uint32_t start; + uint32_t end; + } range; + int16_t taps_4[kScalerCoffNb4]; + int16_t taps_6[kScalerCoffNb6]; +}; + +struct YuvWPara { + int32_t real_count; + YuvScalerPara scale[kMaxParaCount]; +}; + +class YuvScalerParaSet { + public: + static YuvWPara *GetInstance(std::string *paraset_name = nullptr, uint32_t yuv_scaler_paraset_size = 1); + + YuvScalerParaSet(const YuvScalerParaSet &) = delete; + + YuvScalerParaSet &operator=(const YuvScalerParaSet &) = delete; + + static YuvWPara *g_m_instance_; + + protected: + YuvScalerParaSet() {} + + ~YuvScalerParaSet() {} + + private: + class GarbageCollector { + public: + ~GarbageCollector() { + if (YuvScalerParaSet::g_m_instance_) { +#ifndef DVPP_UTST + (void)pthread_mutex_lock(&g_mutex_); + free(YuvScalerParaSet::g_m_instance_); + YuvScalerParaSet::g_m_instance_ = nullptr; + (void)pthread_mutex_unlock(&g_mutex_); +#endif + } + } + }; + + static GarbageCollector g_collector_; + static pthread_mutex_t g_mutex_; +}; + +int32_t GetScalerParamterIndex(uint32_t paramter, YuvWPara *paramterset); + +constexpr YuvWPara YUV_W_PARA = { + 1024, + { + // Band_8_1024 + { + // Scaler inc range + {1023, 1024}, + // Coefficients 4 taps + {1, 254, 1, 0, -20, 253, 29, -6, -30, 231, 68, -13, -33, 199, 112, -22, + -29, 157, 157, -29, -22, 112, 199, -33, -13, 68, 231, -30, -6, 29, 253, -20}, + // Coefficients 6 taps + {0, 1, 254, 1, 0, 0, 8, -24, 248, 32, -11, 3, 13, -38, 225, 71, -22, 7, 15, -43, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -43, 15, 7, -22, 71, 225, -38, 13, 3, -11, 32, 248, -24, 8}, + }, + + // Band_8_1025 + { + // Scaler inc range + {1024, 1025}, + // Coefficients 4 taps + {1, 254, 1, 0, -20, 252, 30, -6, -30, 231, 68, -13, -33, 199, 112, -22, + -29, 157, 157, -29, -22, 112, 199, -33, -13, 68, 231, -30, -6, 30, 252, -20}, + // Coefficients 6 taps + {0, 1, 254, 1, 0, 0, 8, -23, 247, 32, -11, 3, 13, -37, 224, 71, -22, 7, 15, -43, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -43, 15, 7, -22, 71, 224, -37, 13, 3, -11, 32, 247, -23, 8}, + }, + + // Band_8_1026 + { + // Scaler inc range + {1025, 1026}, + // Coefficients 4 taps + {1, 254, 1, 0, -19, 251, 30, -6, -30, 231, 68, -13, -33, 199, 112, -22, + -29, 157, 157, -29, -22, 112, 199, -33, -13, 68, 231, -30, -6, 30, 251, -19}, + // Coefficients 6 taps + {0, 1, 254, 1, 0, 0, 8, -23, 246, 33, -11, 3, 13, -37, 224, 71, -22, 7, 15, -43, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -43, 15, 7, -22, 71, 224, -37, 13, 3, -11, 33, 246, -23, 8}, + }, + + // Band_8_1027 + { + // Scaler inc range + {1026, 1027}, + // Coefficients 4 taps + {1, 254, 1, 0, -19, 251, 30, -6, -30, 231, 68, -13, -33, 199, 112, -22, + -29, 157, 157, -29, -22, 112, 199, -33, -13, 68, 231, -30, -6, 30, 251, -19}, + // Coefficients 6 taps + {0, 1, 254, 1, 0, 0, 8, -23, 245, 33, -11, 4, 13, -37, 225, 71, -23, 7, 15, -42, 192, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 192, -42, 15, 7, -23, 71, 225, -37, 13, 4, -11, 33, 245, -23, 8}, + }, + + // Band_8_1028 + { + // Scaler inc range + {1027, 1028}, + // Coefficients 4 taps + {1, 254, 1, 0, -19, 251, 30, -6, -30, 231, 68, -13, -33, 199, 112, -22, + -29, 157, 157, -29, -22, 112, 199, -33, -13, 68, 231, -30, -6, 30, 251, -19}, + // Coefficients 6 taps + {-1, 2, 254, 2, -1, 0, 8, -23, 245, 33, -11, 4, 13, -37, 225, 71, -23, 7, 15, -42, 192, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 192, -42, 15, 7, -23, 71, 225, -37, 13, 4, -11, 33, 245, -23, 8}, + }, + + // Band_8_1029 + { + // Scaler inc range + {1028, 1029}, + // Coefficients 4 taps + {1, 254, 1, 0, -19, 251, 30, -6, -30, 231, 68, -13, -32, 198, 112, -22, + -29, 157, 157, -29, -22, 112, 198, -32, -13, 68, 231, -30, -6, 30, 251, -19}, + // Coefficients 6 taps + {-1, 2, 254, 2, -1, 0, 8, -23, 245, 33, -11, 4, 13, -37, 224, 72, -23, 7, 15, -42, 192, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 192, -42, 15, 7, -23, 72, 224, -37, 13, 4, -11, 33, 245, -23, 8}, + }, + + // Band_8_1030 + { + // Scaler inc range + {1029, 1030}, + // Coefficients 4 taps + {1, 254, 1, 0, -19, 251, 30, -6, -30, 232, 68, -14, -32, 198, 112, -22, + -29, 157, 157, -29, -22, 112, 198, -32, -14, 68, 232, -30, -6, 30, 251, -19}, + // Coefficients 6 taps + {-1, 2, 254, 2, -1, 0, 7, -22, 245, 34, -12, 4, 13, -37, 223, 72, -23, 8, 14, -42, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -42, 14, 8, -23, 72, 223, -37, 13, 4, -12, 34, 245, -22, 7}, + }, + + // Band_8_1031 + { + // Scaler inc range + {1030, 1031}, + // Coefficients 4 taps + {1, 254, 1, 0, -19, 250, 31, -6, -30, 231, 69, -14, -32, 198, 112, -22, + -29, 157, 157, -29, -22, 112, 198, -32, -14, 69, 231, -30, -6, 31, 250, -19}, + // Coefficients 6 taps + {-1, 2, 254, 2, -1, 0, 7, -22, 245, 34, -12, 4, 12, -37, 224, 72, -23, 8, 14, -42, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -42, 14, 8, -23, 72, 224, -37, 12, 4, -12, 34, 245, -22, 7}, + }, + + // Band_8_1032 + { + // Scaler inc range + {1031, 1032}, + // Coefficients 4 taps + {2, 252, 2, 0, -18, 249, 31, -6, -29, 230, 69, -14, -32, 198, 112, -22, + -29, 157, 157, -29, -22, 112, 198, -32, -14, 69, 230, -29, -6, 31, 249, -18}, + // Coefficients 6 taps + {-1, 2, 254, 2, -1, 0, 7, -22, 245, 34, -12, 4, 12, -36, 223, 72, -23, 8, 14, -42, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -42, 14, 8, -23, 72, 223, -36, 12, 4, -12, 34, 245, -22, 7}, + }, + + // Band_8_1033 + { + // Scaler inc range + {1032, 1033}, + // Coefficients 4 taps + {2, 252, 2, 0, -18, 249, 31, -6, -29, 230, 69, -14, -32, 198, 112, -22, + -29, 157, 157, -29, -22, 112, 198, -32, -14, 69, 230, -29, -6, 31, 249, -18}, + // Coefficients 6 taps + {-1, 2, 254, 2, -1, 0, 7, -22, 245, 34, -12, 4, 12, -36, 223, 72, -23, 8, 14, -42, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -42, 14, 8, -23, 72, 223, -36, 12, 4, -12, 34, 245, -22, 7}, + }, + + // Band_8_1034 + { + // Scaler inc range + {1033, 1034}, + // Coefficients 4 taps + {2, 252, 2, 0, -18, 249, 31, -6, -29, 230, 69, -14, -32, 198, 112, -22, + -29, 157, 157, -29, -22, 112, 198, -32, -14, 69, 230, -29, -6, 31, 249, -18}, + // Coefficients 6 taps + {-2, 3, 254, 3, -2, 0, 7, -22, 245, 34, -12, 4, 12, -36, 223, 72, -23, 8, 14, -42, 193, 113, -33, 11, + 14, -40, 154, 154, -40, 14, 11, -33, 113, 193, -42, 14, 8, -23, 72, 223, -36, 12, 4, -12, 34, 245, -22, 7}, + }, + + // Band_8_1035 + { + // Scaler inc range + {1034, 1035}, + // Coefficients 4 taps + {2, 252, 2, 0, -18, 249, 31, -6, -29, 230, 69, -14, -32, 198, 112, -22, + -29, 157, 157, -29, -22, 112, 198, -32, -14, 69, 230, -29, -6, 31, 249, -18}, + // Coefficients 6 taps + {-2, 3, 254, 3, -2, 0, 7, -21, 243, 35, -12, 4, 12, -36, 223, 72, -23, 8, 14, -42, 193, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 193, -42, 14, 8, -23, 72, 223, -36, 12, 4, -12, 35, 243, -21, 7}, + }, + + // Band_8_1036 + { + // Scaler inc range + {1035, 1036}, + // Coefficients 4 taps + {2, 252, 2, 0, -18, 248, 32, -6, -29, 230, 69, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 69, 230, -29, -6, 32, 248, -18}, + // Coefficients 6 taps + {-2, 3, 254, 3, -2, 0, 7, -21, 243, 35, -12, 4, 12, -36, 223, 73, -24, 8, 14, -42, 193, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 193, -42, 14, 8, -24, 73, 223, -36, 12, 4, -12, 35, 243, -21, 7}, + }, + + // Band_8_1037 + { + // Scaler inc range + {1036, 1037}, + // Coefficients 4 taps + {2, 252, 2, 0, -18, 248, 32, -6, -29, 229, 70, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 70, 229, -29, -6, 32, 248, -18}, + // Coefficients 6 taps + {-2, 3, 254, 3, -2, 0, 6, -21, 245, 35, -13, 4, 12, -36, 223, 73, -24, 8, 14, -42, 193, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 193, -42, 14, 8, -24, 73, 223, -36, 12, 4, -13, 35, 245, -21, 6}, + }, + + // Band_8_1038 + { + // Scaler inc range + {1037, 1038}, + // Coefficients 4 taps + {3, 250, 3, 0, -17, 248, 32, -7, -29, 229, 70, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 70, 229, -29, -7, 32, 248, -17}, + // Coefficients 6 taps + {-2, 3, 254, 3, -2, 0, 6, -21, 245, 35, -13, 4, 12, -36, 223, 73, -24, 8, 14, -42, 193, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 193, -42, 14, 8, -24, 73, 223, -36, 12, 4, -13, 35, 245, -21, 6}, + }, + + // Band_8_1039 + { + // Scaler inc range + {1038, 1039}, + // Coefficients 4 taps + {3, 250, 3, 0, -17, 248, 32, -7, -29, 229, 70, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 70, 229, -29, -7, 32, 248, -17}, + // Coefficients 6 taps + {-2, 3, 254, 3, -2, 0, 6, -21, 245, 35, -13, 4, 12, -35, 222, 73, -24, 8, 14, -41, 192, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 192, -41, 14, 8, -24, 73, 222, -35, 12, 4, -13, 35, 245, -21, 6}, + }, + + // Band_8_1040 + { + // Scaler inc range + {1039, 1040}, + // Coefficients 4 taps + {3, 250, 3, 0, -17, 248, 32, -7, -28, 228, 70, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 70, 228, -28, -7, 32, 248, -17}, + // Coefficients 6 taps + {-2, 4, 252, 4, -2, 0, 6, -20, 243, 36, -13, 4, 12, -35, 222, 73, -24, 8, 14, -41, 192, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 192, -41, 14, 8, -24, 73, 222, -35, 12, 4, -13, 36, 243, -20, 6}, + }, + + // Band_8_1041 + { + // Scaler inc range + {1040, 1041}, + // Coefficients 4 taps + {3, 250, 3, 0, -17, 248, 32, -7, -28, 228, 70, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 70, 228, -28, -7, 32, 248, -17}, + // Coefficients 6 taps + {-3, 4, 254, 4, -3, 0, 6, -20, 243, 36, -13, 4, 11, -35, 223, 73, -24, 8, 14, -41, 192, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 192, -41, 14, 8, -24, 73, 223, -35, 11, 4, -13, 36, 243, -20, 6}, + }, + + // Band_8_1042 + { + // Scaler inc range + {1041, 1042}, + // Coefficients 4 taps + {3, 250, 3, 0, -17, 247, 33, -7, -28, 228, 70, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 70, 228, -28, -7, 33, 247, -17}, + // Coefficients 6 taps + {-3, 4, 254, 4, -3, 0, 6, -20, 242, 36, -13, 5, 11, -35, 222, 74, -24, 8, 14, -41, 192, 114, -34, 11, + 14, -40, 154, 154, -40, 14, 11, -34, 114, 192, -41, 14, 8, -24, 74, 222, -35, 11, 5, -13, 36, 242, -20, 6}, + }, + + // Band_8_1043 + { + // Scaler inc range + {1042, 1043}, + // Coefficients 4 taps + {4, 248, 4, 0, -17, 247, 33, -7, -28, 228, 70, -14, -32, 197, 113, -22, + -29, 157, 157, -29, -22, 113, 197, -32, -14, 70, 228, -28, -7, 33, 247, -17}, + // Coefficients 6 taps + {-3, 4, 254, 4, -3, 0, 6, -20, 242, 36, -13, 5, 11, -35, 222, 74, -24, 8, 14, -41, 191, 114, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 114, 191, -41, 14, 8, -24, 74, 222, -35, 11, 5, -13, 36, 242, -20, 6}, + }, + + // Band_8_1044 + { + // Scaler inc range + {1043, 1044}, + // Coefficients 4 taps + {4, 248, 4, 0, -16, 246, 33, -7, -28, 228, 70, -14, -31, 196, 113, -22, + -29, 157, 157, -29, -22, 113, 196, -31, -14, 70, 228, -28, -7, 33, 246, -16}, + // Coefficients 6 taps + {-3, 4, 254, 4, -3, 0, 6, -20, 243, 36, -14, 5, 11, -35, 222, 74, -24, 8, 14, -41, 191, 114, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 114, 191, -41, 14, 8, -24, 74, 222, -35, 11, 5, -14, 36, 243, -20, 6}, + }, + + // Band_8_1045 + { + // Scaler inc range + {1044, 1045}, + // Coefficients 4 taps + {4, 248, 4, 0, -16, 246, 33, -7, -28, 227, 71, -14, -31, 196, 113, -22, + -29, 157, 157, -29, -22, 113, 196, -31, -14, 71, 227, -28, -7, 33, 246, -16}, + // Coefficients 6 taps + {-3, 5, 252, 5, -3, 0, 5, -19, 242, 37, -14, 5, 11, -34, 222, 74, -25, 8, 14, -41, 191, 114, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 114, 191, -41, 14, 8, -25, 74, 222, -34, 11, 5, -14, 37, 242, -19, 5}, + }, + + // Band_8_1046 + { + // Scaler inc range + {1045, 1046}, + // Coefficients 4 taps + {4, 248, 4, 0, -16, 246, 33, -7, -28, 228, 71, -15, -31, 196, 113, -22, + -29, 157, 157, -29, -22, 113, 196, -31, -15, 71, 228, -28, -7, 33, 246, -16}, + // Coefficients 6 taps + {-3, 5, 252, 5, -3, 0, 5, -19, 242, 37, -14, 5, 11, -34, 222, 74, -25, 8, 14, -41, 190, 115, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 115, 190, -41, 14, 8, -25, 74, 222, -34, 11, 5, -14, 37, 242, -19, 5}, + }, + + // Band_8_1048 + { + // Scaler inc range + {1046, 1048}, + // Coefficients 4 taps + {4, 248, 4, 0, -16, 245, 34, -7, -28, 228, 71, -15, -31, 196, 113, -22, + -29, 157, 157, -29, -22, 113, 196, -31, -15, 71, 228, -28, -7, 34, 245, -16}, + // Coefficients 6 taps + {-3, 5, 252, 5, -3, 0, 5, -19, 242, 37, -14, 5, 11, -34, 222, 74, -25, 8, 14, -41, 190, 115, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 115, 190, -41, 14, 8, -25, 74, 222, -34, 11, 5, -14, 37, 242, -19, 5}, + }, + + // Band_8_1049 + { + // Scaler inc range + {1048, 1049}, + // Coefficients 4 taps + {5, 246, 5, 0, -16, 245, 34, -7, -27, 227, 71, -15, -31, 197, 113, -23, + -29, 157, 157, -29, -23, 113, 197, -31, -15, 71, 227, -27, -7, 34, 245, -16}, + // Coefficients 6 taps + {-4, 5, 254, 5, -4, 0, 5, -19, 242, 37, -14, 5, 11, -34, 221, 75, -25, 8, 13, -41, 191, 115, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 115, 191, -41, 13, 8, -25, 75, 221, -34, 11, 5, -14, 37, 242, -19, 5}, + }, + + // Band_8_1050 + { + // Scaler inc range + {1049, 1050}, + // Coefficients 4 taps + {5, 246, 5, 0, -16, 245, 34, -7, -27, 227, 71, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 71, 227, -27, -7, 34, 245, -16}, + // Coefficients 6 taps + {-4, 6, 252, 6, -4, 0, 5, -19, 241, 38, -14, 5, 11, -34, 220, 75, -25, 9, 13, -41, 191, 115, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 115, 191, -41, 13, 9, -25, 75, 220, -34, 11, 5, -14, 38, 241, -19, 5}, + }, + + // Band_8_1051 + { + // Scaler inc range + {1050, 1051}, + // Coefficients 4 taps + {5, 246, 5, 0, -15, 244, 34, -7, -27, 227, 71, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 71, 227, -27, -7, 34, 244, -15}, + // Coefficients 6 taps + {-4, 6, 252, 6, -4, 0, 5, -18, 240, 38, -14, 5, 11, -34, 220, 75, -25, 9, 13, -41, 191, 115, -34, 12, + 14, -40, 154, 154, -40, 14, 12, -34, 115, 191, -41, 13, 9, -25, 75, 220, -34, 11, 5, -14, 38, 240, -18, 5}, + }, + + // Band_8_1052 + { + // Scaler inc range + {1051, 1052}, + // Coefficients 4 taps + {5, 246, 5, 0, -15, 244, 34, -7, -27, 227, 71, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 71, 227, -27, -7, 34, 244, -15}, + // Coefficients 6 taps + {-4, 6, 252, 6, -4, 0, 5, -18, 240, 38, -14, 5, 10, -34, 221, 75, -25, 9, 13, -40, 190, 115, -34, 12, + 13, -40, 155, 155, -40, 13, 12, -34, 115, 190, -40, 13, 9, -25, 75, 221, -34, 10, 5, -14, 38, 240, -18, 5}, + }, + + // Band_8_1053 + { + // Scaler inc range + {1052, 1053}, + // Coefficients 4 taps + {5, 246, 5, 0, -15, 245, 34, -8, -27, 226, 72, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 72, 226, -27, -8, 34, 245, -15}, + // Coefficients 6 taps + {-4, 6, 252, 6, -4, 0, 4, -18, 242, 38, -15, 5, 10, -33, 220, 75, -25, 9, 13, -40, 190, 115, -34, 12, + 13, -40, 155, 155, -40, 13, 12, -34, 115, 190, -40, 13, 9, -25, 75, 220, -33, 10, 5, -15, 38, 242, -18, 4}, + }, + + // Band_8_1054 + { + // Scaler inc range + {1053, 1054}, + // Coefficients 4 taps + {5, 246, 5, 0, -15, 244, 35, -8, -27, 226, 72, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 72, 226, -27, -8, 35, 244, -15}, + // Coefficients 6 taps + {-4, 7, 250, 7, -4, 0, 4, -18, 242, 38, -15, 5, 10, -33, 220, 75, -25, 9, 13, -40, 190, 115, -34, 12, + 13, -40, 155, 155, -40, 13, 12, -34, 115, 190, -40, 13, 9, -25, 75, 220, -33, 10, 5, -15, 38, 242, -18, 4}, + }, + + // Band_8_1055 + { + // Scaler inc range + {1054, 1055}, + // Coefficients 4 taps + {6, 244, 6, 0, -15, 244, 35, -8, -27, 226, 72, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 72, 226, -27, -8, 35, 244, -15}, + // Coefficients 6 taps + {-5, 7, 252, 7, -5, 0, 4, -18, 241, 39, -15, 5, 10, -33, 219, 76, -25, 9, 13, -40, 191, 115, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 115, 191, -40, 13, 9, -25, 76, 219, -33, 10, 5, -15, 39, 241, -18, 4}, + }, + + // Band_8_1056 + { + // Scaler inc range + {1055, 1056}, + // Coefficients 4 taps + {6, 244, 6, 0, -14, 243, 35, -8, -26, 225, 72, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 72, 225, -26, -8, 35, 243, -14}, + // Coefficients 6 taps + {-5, 7, 252, 7, -5, 0, 4, -17, 240, 39, -15, 5, 10, -33, 220, 76, -26, 9, 13, -40, 191, 115, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 115, 191, -40, 13, 9, -26, 76, 220, -33, 10, 5, -15, 39, 240, -17, 4}, + }, + + // Band_8_1057 + { + // Scaler inc range + {1056, 1057}, + // Coefficients 4 taps + {6, 244, 6, 0, -14, 243, 35, -8, -26, 225, 72, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 72, 225, -26, -8, 35, 243, -14}, + // Coefficients 6 taps + {-5, 7, 252, 7, -5, 0, 4, -17, 240, 39, -15, 5, 10, -33, 220, 76, -26, 9, 13, -40, 191, 115, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 115, 191, -40, 13, 9, -26, 76, 220, -33, 10, 5, -15, 39, 240, -17, 4}, + }, + + // Band_8_1058 + { + // Scaler inc range + {1057, 1058}, + // Coefficients 4 taps + {6, 244, 6, 0, -14, 243, 35, -8, -26, 225, 72, -15, -31, 196, 114, -23, + -29, 157, 157, -29, -23, 114, 196, -31, -15, 72, 225, -26, -8, 35, 243, -14}, + // Coefficients 6 taps + {-5, 7, 252, 7, -5, 0, 4, -17, 240, 39, -15, 5, 10, -33, 220, 76, -26, 9, 13, -40, 191, 115, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 115, 191, -40, 13, 9, -26, 76, 220, -33, 10, 5, -15, 39, 240, -17, 4}, + }, + + // Band_8_1059 + { + // Scaler inc range + {1058, 1059}, + // Coefficients 4 taps + {6, 244, 6, 0, -14, 242, 36, -8, -26, 225, 72, -15, -30, 195, 114, -23, + -29, 157, 157, -29, -23, 114, 195, -30, -15, 72, 225, -26, -8, 36, 242, -14}, + // Coefficients 6 taps + {-5, 8, 250, 8, -5, 0, 4, -17, 239, 39, -15, 6, 10, -32, 219, 76, -26, 9, 13, -40, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -40, 13, 9, -26, 76, 219, -32, 10, 6, -15, 39, 239, -17, 4}, + }, + + // Band_8_1060 + { + // Scaler inc range + {1059, 1060}, + // Coefficients 4 taps + {7, 242, 7, 0, -14, 242, 36, -8, -26, 224, 73, -15, -30, 195, 114, -23, + -29, 157, 157, -29, -23, 114, 195, -30, -15, 73, 224, -26, -8, 36, 242, -14}, + // Coefficients 6 taps + {-5, 8, 250, 8, -5, 0, 4, -17, 239, 40, -16, 6, 10, -32, 219, 76, -26, 9, 13, -40, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -40, 13, 9, -26, 76, 219, -32, 10, 6, -16, 40, 239, -17, 4}, + }, + + // Band_8_1061 + { + // Scaler inc range + {1060, 1061}, + // Coefficients 4 taps + {7, 242, 7, 0, -14, 242, 36, -8, -26, 224, 73, -15, -30, 195, 114, -23, + -29, 157, 157, -29, -23, 114, 195, -30, -15, 73, 224, -26, -8, 36, 242, -14}, + // Coefficients 6 taps + {-5, 8, 250, 8, -5, 0, 3, -16, 239, 40, -16, 6, 9, -32, 219, 77, -26, 9, 13, -40, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -40, 13, 9, -26, 77, 219, -32, 9, 6, -16, 40, 239, -16, 3}, + }, + + // Band_8_1062 + { + // Scaler inc range + {1061, 1062}, + // Coefficients 4 taps + {7, 242, 7, 0, -13, 241, 36, -8, -26, 224, 73, -15, -30, 195, 114, -23, + -29, 157, 157, -29, -23, 114, 195, -30, -15, 73, 224, -26, -8, 36, 241, -13}, + // Coefficients 6 taps + {-6, 8, 252, 8, -6, 0, 3, -16, 239, 40, -16, 6, 9, -32, 219, 77, -26, 9, 13, -39, 189, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 189, -39, 13, 9, -26, 77, 219, -32, 9, 6, -16, 40, 239, -16, 3}, + }, + + // Band_8_1063 + { + // Scaler inc range + {1062, 1063}, + // Coefficients 4 taps + {7, 242, 7, 0, -13, 241, 36, -8, -26, 224, 73, -15, -30, 195, 114, -23, + -28, 156, 156, -28, -23, 114, 195, -30, -15, 73, 224, -26, -8, 36, 241, -13}, + // Coefficients 6 taps + {-6, 9, 250, 9, -6, 0, 3, -16, 239, 40, -16, 6, 9, -32, 219, 77, -26, 9, 13, -39, 189, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 189, -39, 13, 9, -26, 77, 219, -32, 9, 6, -16, 40, 239, -16, 3}, + }, + + // Band_8_1065 + { + // Scaler inc range + {1063, 1065}, + // Coefficients 4 taps + {7, 242, 7, 0, -13, 241, 36, -8, -25, 224, 73, -16, -30, 195, 114, -23, + -28, 156, 156, -28, -23, 114, 195, -30, -16, 73, 224, -25, -8, 36, 241, -13}, + // Coefficients 6 taps + {-6, 9, 250, 9, -6, 0, 3, -16, 239, 40, -16, 6, 9, -32, 219, 77, -26, 9, 12, -39, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -39, 12, 9, -26, 77, 219, -32, 9, 6, -16, 40, 239, -16, 3}, + }, + + // Band_8_1066 + { + // Scaler inc range + {1065, 1066}, + // Coefficients 4 taps + {7, 242, 7, 0, -13, 240, 37, -8, -25, 224, 73, -16, -30, 194, 115, -23, + -28, 156, 156, -28, -23, 115, 194, -30, -16, 73, 224, -25, -8, 37, 240, -13}, + // Coefficients 6 taps + {-6, 9, 250, 9, -6, 0, 3, -16, 238, 41, -16, 6, 9, -32, 219, 77, -26, 9, 12, -39, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -39, 12, 9, -26, 77, 219, -32, 9, 6, -16, 41, 238, -16, 3}, + }, + + // Band_8_1067 + { + // Scaler inc range + {1066, 1067}, + // Coefficients 4 taps + {8, 240, 8, 0, -13, 240, 37, -8, -25, 224, 73, -16, -30, 194, 115, -23, + -28, 156, 156, -28, -23, 115, 194, -30, -16, 73, 224, -25, -8, 37, 240, -13}, + // Coefficients 6 taps + {-6, 9, 250, 9, -6, 0, 3, -15, 237, 41, -16, 6, 9, -31, 219, 77, -27, 9, 12, -39, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -39, 12, 9, -27, 77, 219, -31, 9, 6, -16, 41, 237, -15, 3}, + }, + + // Band_8_1068 + { + // Scaler inc range + {1067, 1068}, + // Coefficients 4 taps + {8, 240, 8, 0, -13, 240, 37, -8, -25, 224, 73, -16, -30, 194, 115, -23, + -28, 156, 156, -28, -23, 115, 194, -30, -16, 73, 224, -25, -8, 37, 240, -13}, + // Coefficients 6 taps + {-6, 9, 250, 9, -6, 0, 3, -15, 238, 41, -17, 6, 9, -31, 219, 77, -27, 9, 12, -39, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -39, 12, 9, -27, 77, 219, -31, 9, 6, -17, 41, 238, -15, 3}, + }, + + // Band_8_1069 + { + // Scaler inc range + {1068, 1069}, + // Coefficients 4 taps + {8, 240, 8, 0, -12, 240, 37, -9, -25, 223, 74, -16, -30, 194, 115, -23, + -28, 156, 156, -28, -23, 115, 194, -30, -16, 74, 223, -25, -9, 37, 240, -12}, + // Coefficients 6 taps + {-7, 10, 250, 10, -7, 0, 2, -15, 239, 41, -17, 6, 9, -31, 218, 78, -27, 9, 12, -39, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -39, 12, 9, -27, 78, 218, -31, 9, 6, -17, 41, 239, -15, 2}, + }, + + // Band_8_1070 + { + // Scaler inc range + {1069, 1070}, + // Coefficients 4 taps + {8, 240, 8, 0, -12, 240, 37, -9, -25, 223, 74, -16, -30, 194, 115, -23, + -28, 156, 156, -28, -23, 115, 194, -30, -16, 74, 223, -25, -9, 37, 240, -12}, + // Coefficients 6 taps + {-7, 10, 250, 10, -7, 0, 2, -15, 239, 41, -17, 6, 9, -31, 218, 78, -27, 9, 12, -39, 190, 116, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 116, 190, -39, 12, 9, -27, 78, 218, -31, 9, 6, -17, 41, 239, -15, 2}, + }, + + // Band_8_1071 + { + // Scaler inc range + {1070, 1071}, + // Coefficients 4 taps + {8, 240, 8, 0, -12, 240, 37, -9, -25, 223, 74, -16, -30, 194, 115, -23, + -28, 156, 156, -28, -23, 115, 194, -30, -16, 74, 223, -25, -9, 37, 240, -12}, + // Coefficients 6 taps + {-7, 10, 250, 10, -7, 0, 2, -15, 238, 42, -17, 6, 8, -31, 219, 78, -27, 9, 12, -39, 189, 117, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 117, 189, -39, 12, 9, -27, 78, 219, -31, 8, 6, -17, 42, 238, -15, 2}, + }, + + // Band_8_1072 + { + // Scaler inc range + {1071, 1072}, + // Coefficients 4 taps + {9, 238, 9, 0, -12, 239, 38, -9, -24, 222, 74, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 74, 222, -24, -9, 38, 239, -12}, + // Coefficients 6 taps + {-7, 10, 250, 10, -7, 0, 2, -14, 237, 42, -17, 6, 8, -31, 219, 78, -27, 9, 12, -39, 189, 117, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 117, 189, -39, 12, 9, -27, 78, 219, -31, 8, 6, -17, 42, 237, -14, 2}, + }, + + // Band_8_1073 + { + // Scaler inc range + {1072, 1073}, + // Coefficients 4 taps + {9, 238, 9, 0, -12, 239, 38, -9, -24, 222, 74, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 74, 222, -24, -9, 38, 239, -12}, + // Coefficients 6 taps + {-7, 11, 248, 11, -7, 0, 2, -14, 237, 42, -17, 6, 8, -30, 218, 78, -27, 9, 12, -38, 188, 117, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 117, 188, -38, 12, 9, -27, 78, 218, -30, 8, 6, -17, 42, 237, -14, 2}, + }, + + // Band_8_1074 + { + // Scaler inc range + {1073, 1074}, + // Coefficients 4 taps + {9, 238, 9, 0, -12, 239, 38, -9, -24, 222, 74, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 74, 222, -24, -9, 38, 239, -12}, + // Coefficients 6 taps + {-7, 11, 248, 11, -7, 0, 2, -14, 237, 42, -17, 6, 8, -30, 218, 78, -27, 9, 12, -38, 188, 117, -35, 12, + 13, -40, 155, 155, -40, 13, 12, -35, 117, 188, -38, 12, 9, -27, 78, 218, -30, 8, 6, -17, 42, 237, -14, 2}, + }, + + // Band_8_1075 + { + // Scaler inc range + {1074, 1075}, + // Coefficients 4 taps + {9, 238, 9, 0, -11, 238, 38, -9, -24, 222, 74, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 74, 222, -24, -9, 38, 238, -11}, + // Coefficients 6 taps + {-7, 11, 248, 11, -7, 0, 2, -14, 237, 42, -17, 6, 8, -30, 217, 79, -27, 9, 12, -38, 188, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 188, -38, 12, 9, -27, 79, 217, -30, 8, 6, -17, 42, 237, -14, 2}, + }, + + // Band_8_1077 + { + // Scaler inc range + {1075, 1077}, + // Coefficients 4 taps + {9, 238, 9, 0, -11, 238, 38, -9, -24, 222, 74, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 74, 222, -24, -9, 38, 238, -11}, + // Coefficients 6 taps + {-8, 11, 250, 11, -8, 0, 1, -14, 238, 43, -18, 6, 8, -30, 216, 79, -27, 10, 12, -38, 188, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 188, -38, 12, 10, -27, 79, 216, -30, 8, 6, -18, 43, 238, -14, 1}, + }, + + // Band_8_1078 + { + // Scaler inc range + {1077, 1078}, + // Coefficients 4 taps + {9, 238, 9, 0, -11, 238, 38, -9, -24, 221, 75, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 75, 221, -24, -9, 38, 238, -11}, + // Coefficients 6 taps + {-8, 12, 248, 12, -8, 0, 1, -13, 237, 43, -18, 6, 8, -30, 216, 79, -27, 10, 12, -38, 188, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 188, -38, 12, 10, -27, 79, 216, -30, 8, 6, -18, 43, 237, -13, 1}, + }, + + // Band_8_1079 + { + // Scaler inc range + {1078, 1079}, + // Coefficients 4 taps + {10, 236, 10, 0, -11, 237, 39, -9, -24, 221, 75, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 75, 221, -24, -9, 39, 237, -11}, + // Coefficients 6 taps + {-8, 12, 248, 12, -8, 0, 1, -13, 236, 43, -18, 7, 8, -30, 217, 79, -28, 10, 11, -38, 189, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 189, -38, 11, 10, -28, 79, 217, -30, 8, 7, -18, 43, 236, -13, 1}, + }, + + // Band_8_1080 + { + // Scaler inc range + {1079, 1080}, + // Coefficients 4 taps + {10, 236, 10, 0, -11, 237, 39, -9, -23, 220, 75, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 75, 220, -23, -9, 39, 237, -11}, + // Coefficients 6 taps + {-8, 12, 248, 12, -8, 0, 1, -13, 236, 43, -18, 7, 8, -29, 216, 79, -28, 10, 11, -38, 189, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 189, -38, 11, 10, -28, 79, 216, -29, 8, 7, -18, 43, 236, -13, 1}, + }, + + // Band_8_1081 + { + // Scaler inc range + {1080, 1081}, + // Coefficients 4 taps + {10, 236, 10, 0, -10, 236, 39, -9, -23, 220, 75, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 75, 220, -23, -9, 39, 236, -10}, + // Coefficients 6 taps + {-8, 12, 248, 12, -8, 0, 1, -13, 236, 43, -18, 7, 7, -29, 217, 79, -28, 10, 11, -38, 189, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 189, -38, 11, 10, -28, 79, 217, -29, 7, 7, -18, 43, 236, -13, 1}, + }, + + // Band_8_1082 + { + // Scaler inc range + {1081, 1082}, + // Coefficients 4 taps + {10, 236, 10, 0, -10, 236, 39, -9, -23, 220, 75, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 75, 220, -23, -9, 39, 236, -10}, + // Coefficients 6 taps + {-8, 12, 248, 12, -8, 0, 1, -13, 235, 44, -18, 7, 7, -29, 217, 79, -28, 10, 11, -38, 189, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 189, -38, 11, 10, -28, 79, 217, -29, 7, 7, -18, 44, 235, -13, 1}, + }, + + // Band_8_1083 + { + // Scaler inc range + {1082, 1083}, + // Coefficients 4 taps + {10, 236, 10, 0, -10, 236, 39, -9, -23, 220, 75, -16, -29, 193, 115, -23, + -28, 156, 156, -28, -23, 115, 193, -29, -16, 75, 220, -23, -9, 39, 236, -10}, + // Coefficients 6 taps + {-8, 13, 246, 13, -8, 0, 1, -12, 234, 44, -18, 7, 7, -29, 216, 80, -28, 10, 11, -37, 188, 117, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 117, 188, -37, 11, 10, -28, 80, 216, -29, 7, 7, -18, 44, 234, -12, 1}, + }, + + // Band_8_1084 + { + // Scaler inc range + {1083, 1084}, + // Coefficients 4 taps + {10, 236, 10, 0, -10, 236, 39, -9, -23, 220, 75, -16, -28, 192, 115, -23, + -28, 156, 156, -28, -23, 115, 192, -28, -16, 75, 220, -23, -9, 39, 236, -10}, + // Coefficients 6 taps + {-9, 13, 248, 13, -9, 0, 0, -12, 235, 44, -18, 7, 7, -29, 216, 80, -28, 10, 11, -37, 187, 118, -35, 12, + 13, -39, 154, 154, -39, 13, 12, -35, 118, 187, -37, 11, 10, -28, 80, 216, -29, 7, 7, -18, 44, 235, -12, 0}, + }, + + // Band_8_1085 + { + // Scaler inc range + {1084, 1085}, + // Coefficients 4 taps + {11, 234, 11, 0, -10, 235, 40, -9, -23, 220, 75, -16, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -16, 75, 220, -23, -9, 40, 235, -10}, + // Coefficients 6 taps + {-9, 13, 248, 13, -9, 0, 0, -12, 236, 44, -19, 7, 7, -29, 216, 80, -28, 10, 11, -37, 187, 118, -35, 12, + 12, -39, 155, 155, -39, 12, 12, -35, 118, 187, -37, 11, 10, -28, 80, 216, -29, 7, 7, -19, 44, 236, -12, 0}, + }, + + // Band_8_1087 + { + // Scaler inc range + {1085, 1087}, + // Coefficients 4 taps + {11, 234, 11, 0, -10, 236, 40, -10, -23, 219, 76, -16, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -16, 76, 219, -23, -10, 40, 236, -10}, + // Coefficients 6 taps + {-9, 13, 248, 13, -9, 0, 0, -12, 236, 44, -19, 7, 7, -28, 215, 80, -28, 10, 11, -37, 187, 118, -35, 12, + 12, -39, 155, 155, -39, 12, 12, -35, 118, 187, -37, 11, 10, -28, 80, 215, -28, 7, 7, -19, 44, 236, -12, 0}, + }, + + // Band_8_1088 + { + // Scaler inc range + {1087, 1088}, + // Coefficients 4 taps + {11, 234, 11, 0, -9, 235, 40, -10, -22, 218, 76, -16, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -16, 76, 218, -22, -10, 40, 235, -9}, + // Coefficients 6 taps + {-9, 14, 246, 14, -9, 0, 0, -11, 234, 45, -19, 7, 7, -28, 215, 80, -28, 10, 11, -37, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -37, 11, 10, -28, 80, 215, -28, 7, 7, -19, 45, 234, -11, 0}, + }, + + // Band_8_1089 + { + // Scaler inc range + {1088, 1089}, + // Coefficients 4 taps + {11, 234, 11, 0, -9, 235, 40, -10, -22, 219, 76, -17, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -17, 76, 219, -22, -10, 40, 235, -9}, + // Coefficients 6 taps + {-9, 14, 246, 14, -9, 0, 0, -11, 234, 45, -19, 7, 7, -28, 215, 80, -28, 10, 11, -37, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -37, 11, 10, -28, 80, 215, -28, 7, 7, -19, 45, 234, -11, 0}, + }, + + // Band_8_1090 + { + // Scaler inc range + {1089, 1090}, + // Coefficients 4 taps + {11, 234, 11, 0, -9, 235, 40, -10, -22, 219, 76, -17, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -17, 76, 219, -22, -10, 40, 235, -9}, + // Coefficients 6 taps + {-9, 14, 246, 14, -9, 0, 0, -11, 234, 45, -19, 7, 6, -28, 215, 81, -28, 10, 11, -37, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -37, 11, 10, -28, 81, 215, -28, 6, 7, -19, 45, 234, -11, 0}, + }, + + // Band_8_1091 + { + // Scaler inc range + {1090, 1091}, + // Coefficients 4 taps + {12, 232, 12, 0, -9, 235, 40, -10, -22, 219, 76, -17, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -17, 76, 219, -22, -10, 40, 235, -9}, + // Coefficients 6 taps + {-10, 14, 248, 14, -10, 0, 0, -11, 234, 45, -19, 7, 6, -28, 215, 81, -28, 10, 11, -37, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -37, 11, 10, -28, 81, 215, -28, 6, 7, -19, 45, 234, -11, 0}, + }, + + // Band_8_1092 + { + // Scaler inc range + {1091, 1092}, + // Coefficients 4 taps + {12, 232, 12, 0, -9, 234, 41, -10, -22, 219, 76, -17, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -17, 76, 219, -22, -10, 41, 234, -9}, + // Coefficients 6 taps + {-10, 14, 248, 14, -10, 0, -1, -11, 235, 45, -19, 7, 6, -28, 216, 81, -29, 10, 10, -37, 189, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 189, -37, 10, 10, -29, 81, 216, -28, 6, 7, -19, 45, 235, -11, -1}, + }, + + // Band_8_1093 + { + // Scaler inc range + {1092, 1093}, + // Coefficients 4 taps + {12, 232, 12, 0, -9, 234, 41, -10, -22, 219, 76, -17, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -17, 76, 219, -22, -10, 41, 234, -9}, + // Coefficients 6 taps + {-10, 15, 246, 15, -10, 0, -1, -10, 233, 46, -19, 7, 6, -27, 215, 81, -29, 10, 10, -36, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -36, 10, 10, -29, 81, 215, -27, 6, 7, -19, 46, 233, -10, -1}, + }, + + // Band_8_1095 + { + // Scaler inc range + {1093, 1095}, + // Coefficients 4 taps + {12, 232, 12, 0, -8, 233, 41, -10, -22, 219, 76, -17, -28, 191, 116, -23, + -28, 156, 156, -28, -23, 116, 191, -28, -17, 76, 219, -22, -10, 41, 233, -8}, + // Coefficients 6 taps + {-10, 15, 246, 15, -10, 0, -1, -10, 234, 46, -20, 7, 6, -27, 215, 81, -29, 10, 10, -36, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -36, 10, 10, -29, 81, 215, -27, 6, 7, -20, 46, 234, -10, -1}, + }, + + // Band_8_1096 + { + // Scaler inc range + {1095, 1096}, + // Coefficients 4 taps + {12, 232, 12, 0, -8, 233, 41, -10, -21, 218, 76, -17, -28, 191, 116, -23, + -27, 155, 155, -27, -23, 116, 191, -28, -17, 76, 218, -21, -10, 41, 233, -8}, + // Coefficients 6 taps + {-10, 15, 246, 15, -10, 0, -1, -10, 234, 46, -20, 7, 6, -27, 215, 81, -29, 10, 10, -36, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -36, 10, 10, -29, 81, 215, -27, 6, 7, -20, 46, 234, -10, -1}, + }, + + // Band_8_1097 + { + // Scaler inc range + {1096, 1097}, + // Coefficients 4 taps + {12, 232, 12, 0, -8, 233, 41, -10, -21, 217, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 217, -21, -10, 41, 233, -8}, + // Coefficients 6 taps + {-10, 15, 246, 15, -10, 0, -1, -10, 234, 46, -20, 7, 6, -27, 215, 81, -29, 10, 10, -36, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -36, 10, 10, -29, 81, 215, -27, 6, 7, -20, 46, 234, -10, -1}, + }, + + // Band_8_1098 + { + // Scaler inc range + {1097, 1098}, + // Coefficients 4 taps + {13, 230, 13, 0, -8, 233, 41, -10, -21, 217, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 217, -21, -10, 41, 233, -8}, + // Coefficients 6 taps + {-10, 16, 244, 16, -10, 0, -1, -10, 234, 46, -20, 7, 6, -27, 214, 82, -29, 10, 10, -36, 188, 118, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 118, 188, -36, 10, 10, -29, 82, 214, -27, 6, 7, -20, 46, 234, -10, -1}, + }, + + // Band_8_1099 + { + // Scaler inc range + {1098, 1099}, + // Coefficients 4 taps + {13, 230, 13, 0, -8, 232, 42, -10, -21, 217, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 217, -21, -10, 42, 232, -8}, + // Coefficients 6 taps + {-11, 16, 246, 16, -11, 0, -1, -9, 232, 47, -20, 7, 6, -26, 213, 82, -29, 10, 10, -36, 187, 119, -36, 12, + 12, -39, 155, 155, -39, 12, 12, -36, 119, 187, -36, 10, 10, -29, 82, 213, -26, 6, 7, -20, 47, 232, -9, -1}, + }, + + // Band_8_1100 + { + // Scaler inc range + {1099, 1100}, + // Coefficients 4 taps + {13, 230, 13, 0, -8, 232, 42, -10, -21, 217, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 217, -21, -10, 42, 232, -8}, + // Coefficients 6 taps + {-11, 16, 246, 16, -11, 0, -2, -9, 233, 47, -20, 7, 5, -26, 214, 82, -29, 10, 10, -36, 187, 119, -36, 12, + 12, -38, 154, 154, -38, 12, 12, -36, 119, 187, -36, 10, 10, -29, 82, 214, -26, 5, 7, -20, 47, 233, -9, -2}, + }, + + // Band_8_1101 + { + // Scaler inc range + {1100, 1101}, + // Coefficients 4 taps + {13, 230, 13, 0, -7, 231, 42, -10, -21, 217, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 217, -21, -10, 42, 231, -7}, + // Coefficients 6 taps + {-11, 16, 246, 16, -11, 0, -2, -9, 233, 47, -20, 7, 5, -26, 214, 82, -29, 10, 10, -36, 187, 119, -36, 12, + 12, -38, 154, 154, -38, 12, 12, -36, 119, 187, -36, 10, 10, -29, 82, 214, -26, 5, 7, -20, 47, 233, -9, -2}, + }, + + // Band_8_1103 + { + // Scaler inc range + {1101, 1103}, + // Coefficients 4 taps + {13, 230, 13, 0, -7, 231, 42, -10, -21, 217, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 217, -21, -10, 42, 231, -7}, + // Coefficients 6 taps + {-11, 17, 244, 17, -11, 0, -2, -9, 233, 47, -20, 7, 5, -26, 214, 82, -29, 10, 10, -36, 187, 119, -36, 12, + 12, -38, 154, 154, -38, 12, 12, -36, 119, 187, -36, 10, 10, -29, 82, 214, -26, 5, 7, -20, 47, 233, -9, -2}, + }, + + // Band_8_1104 + { + // Scaler inc range + {1103, 1104}, + // Coefficients 4 taps + {13, 230, 13, 0, -7, 231, 42, -10, -20, 216, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 216, -20, -10, 42, 231, -7}, + // Coefficients 6 taps + {-11, 17, 244, 17, -11, 0, -2, -9, 232, 47, -20, 8, 5, -26, 214, 82, -29, 10, 10, -35, 186, 119, -36, 12, + 12, -38, 154, 154, -38, 12, 12, -36, 119, 186, -35, 10, 10, -29, 82, 214, -26, 5, 8, -20, 47, 232, -9, -2}, + }, + + // Band_8_1105 + { + // Scaler inc range + {1104, 1105}, + // Coefficients 4 taps + {14, 228, 14, 0, -7, 231, 42, -10, -20, 216, 77, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 77, 216, -20, -10, 42, 231, -7}, + // Coefficients 6 taps + {-11, 17, 244, 17, -11, 0, -2, -8, 231, 48, -21, 8, 5, -26, 214, 82, -29, 10, 9, -35, 187, 119, -36, 12, + 12, -38, 154, 154, -38, 12, 12, -36, 119, 187, -35, 9, 10, -29, 82, 214, -26, 5, 8, -21, 48, 231, -8, -2}, + }, + + // Band_8_1106 + { + // Scaler inc range + {1105, 1106}, + // Coefficients 4 taps + {14, 228, 14, 0, -7, 230, 43, -10, -20, 215, 78, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 78, 215, -20, -10, 43, 230, -7}, + // Coefficients 6 taps + {-11, 17, 244, 17, -11, 0, -2, -8, 231, 48, -21, 8, 5, -25, 212, 83, -29, 10, 9, -35, 187, 119, -36, 12, + 12, -38, 154, 154, -38, 12, 12, -36, 119, 187, -35, 9, 10, -29, 83, 212, -25, 5, 8, -21, 48, 231, -8, -2}, + }, + + // Band_8_1107 + { + // Scaler inc range + {1106, 1107}, + // Coefficients 4 taps + {14, 228, 14, 0, -6, 230, 43, -11, -20, 215, 78, -17, -27, 190, 116, -23, + -27, 155, 155, -27, -23, 116, 190, -27, -17, 78, 215, -20, -11, 43, 230, -6}, + // Coefficients 6 taps + {-12, 17, 246, 17, -12, 0, -2, -8, 231, 48, -21, 8, 5, -25, 212, 83, -29, 10, 9, -35, 187, 119, -36, 12, + 12, -38, 154, 154, -38, 12, 12, -36, 119, 187, -35, 9, 10, -29, 83, 212, -25, 5, 8, -21, 48, 231, -8, -2}, + }, + + // Band_8_1108 + { + // Scaler inc range + {1107, 1108}, + // Coefficients 4 taps + {14, 228, 14, 0, -6, 230, 43, -11, -20, 215, 78, -17, -26, 189, 116, -23, + -27, 155, 155, -27, -23, 116, 189, -26, -17, 78, 215, -20, -11, 43, 230, -6}, + // Coefficients 6 taps + {-12, 18, 244, 18, -12, 0, -2, -8, 231, 48, -21, 8, 5, -25, 213, 83, -30, 10, 9, -35, 187, 119, -36, 12, + 11, -38, 155, 155, -38, 11, 12, -36, 119, 187, -35, 9, 10, -30, 83, 213, -25, 5, 8, -21, 48, 231, -8, -2}, + }, + + // Band_8_1110 + { + // Scaler inc range + {1108, 1110}, + // Coefficients 4 taps + {14, 228, 14, 0, -6, 230, 43, -11, -20, 215, 78, -17, -26, 189, 116, -23, + -27, 155, 155, -27, -23, 116, 189, -26, -17, 78, 215, -20, -11, 43, 230, -6}, + // Coefficients 6 taps + {-12, 18, 244, 18, -12, 0, -3, -7, 231, 48, -21, 8, 4, -25, 214, 83, -30, 10, 9, -35, 187, 119, -36, 12, + 11, -38, 155, 155, -38, 11, 12, -36, 119, 187, -35, 9, 10, -30, 83, 214, -25, 4, 8, -21, 48, 231, -7, -3}, + }, + + // Band_8_1111 + { + // Scaler inc range + {1110, 1111}, + // Coefficients 4 taps + {14, 228, 14, 0, -6, 230, 43, -11, -20, 215, 78, -17, -26, 189, 116, -23, + -27, 155, 155, -27, -23, 116, 189, -26, -17, 78, 215, -20, -11, 43, 230, -6}, + // Coefficients 6 taps + {-12, 18, 244, 18, -12, 0, -3, -7, 230, 49, -21, 8, 4, -25, 214, 83, -30, 10, 9, -35, 187, 119, -36, 12, + 11, -38, 155, 155, -38, 11, 12, -36, 119, 187, -35, 9, 10, -30, 83, 214, -25, 4, 8, -21, 49, 230, -7, -3}, + }, + + // Band_8_1112 + { + // Scaler inc range + {1111, 1112}, + // Coefficients 4 taps + {15, 226, 15, 0, -6, 230, 43, -11, -19, 214, 78, -17, -26, 189, 116, -23, + -27, 155, 155, -27, -23, 116, 189, -26, -17, 78, 214, -19, -11, 43, 230, -6}, + // Coefficients 6 taps + {-12, 18, 244, 18, -12, 0, -3, -7, 230, 49, -21, 8, 4, -25, 214, 83, -30, 10, 9, -35, 187, 119, -36, 12, + 11, -38, 155, 155, -38, 11, 12, -36, 119, 187, -35, 9, 10, -30, 83, 214, -25, 4, 8, -21, 49, 230, -7, -3}, + }, + + // Band_8_1113 + { + // Scaler inc range + {1112, 1113}, + // Coefficients 4 taps + {15, 226, 15, 0, -6, 230, 43, -11, -19, 214, 78, -17, -26, 188, 117, -23, + -27, 155, 155, -27, -23, 117, 188, -26, -17, 78, 214, -19, -11, 43, 230, -6}, + // Coefficients 6 taps + {-12, 19, 242, 19, -12, 0, -3, -7, 230, 49, -21, 8, 4, -24, 212, 84, -30, 10, 9, -34, 186, 119, -36, 12, + 11, -38, 155, 155, -38, 11, 12, -36, 119, 186, -34, 9, 10, -30, 84, 212, -24, 4, 8, -21, 49, 230, -7, -3}, + }, + + // Band_8_1114 + { + // Scaler inc range + {1113, 1114}, + // Coefficients 4 taps + {15, 226, 15, 0, -5, 228, 44, -11, -19, 214, 78, -17, -26, 188, 117, -23, + -27, 155, 155, -27, -23, 117, 188, -26, -17, 78, 214, -19, -11, 44, 228, -5}, + // Coefficients 6 taps + {-12, 19, 242, 19, -12, 0, -3, -7, 230, 49, -21, 8, 4, -24, 212, 84, -30, 10, 9, -34, 186, 120, -36, 11, + 11, -38, 155, 155, -38, 11, 11, -36, 120, 186, -34, 9, 10, -30, 84, 212, -24, 4, 8, -21, 49, 230, -7, -3}, + }, + + // Band_8_1116 + { + // Scaler inc range + {1114, 1116}, + // Coefficients 4 taps + {15, 226, 15, 0, -5, 228, 44, -11, -19, 214, 78, -17, -26, 188, 117, -23, + -27, 155, 155, -27, -23, 117, 188, -26, -17, 78, 214, -19, -11, 44, 228, -5}, + // Coefficients 6 taps + {-13, 19, 244, 19, -13, 0, -3, -6, 230, 49, -22, 8, 4, -24, 212, 84, -30, 10, 9, -34, 186, 120, -36, 11, + 11, -38, 155, 155, -38, 11, 11, -36, 120, 186, -34, 9, 10, -30, 84, 212, -24, 4, 8, -22, 49, 230, -6, -3}, + }, + + // Band_8_1117 + { + // Scaler inc range + {1116, 1117}, + // Coefficients 4 taps + {15, 226, 15, 0, -5, 228, 44, -11, -19, 214, 78, -17, -26, 188, 117, -23, + -27, 155, 155, -27, -23, 117, 188, -26, -17, 78, 214, -19, -11, 44, 228, -5}, + // Coefficients 6 taps + {-13, 19, 244, 19, -13, 0, -3, -6, 229, 50, -22, 8, 4, -24, 212, 84, -30, 10, 9, -34, 186, 120, -36, 11, + 11, -38, 155, 155, -38, 11, 11, -36, 120, 186, -34, 9, 10, -30, 84, 212, -24, 4, 8, -22, 50, 229, -6, -3}, + }, + + // Band_8_1118 + { + // Scaler inc range + {1117, 1118}, + // Coefficients 4 taps + {16, 224, 16, 0, -5, 228, 44, -11, -19, 213, 79, -17, -26, 188, 117, -23, + -27, 155, 155, -27, -23, 117, 188, -26, -17, 79, 213, -19, -11, 44, 228, -5}, + // Coefficients 6 taps + {-13, 20, 242, 20, -13, 0, -4, -6, 230, 50, -22, 8, 4, -24, 212, 84, -30, 10, 8, -34, 187, 120, -36, 11, + 11, -38, 155, 155, -38, 11, 11, -36, 120, 187, -34, 8, 10, -30, 84, 212, -24, 4, 8, -22, 50, 230, -6, -4}, + }, + + // Band_8_1119 + { + // Scaler inc range + {1118, 1119}, + // Coefficients 4 taps + {16, 224, 16, 0, -5, 228, 44, -11, -19, 213, 79, -17, -25, 187, 117, -23, + -27, 155, 155, -27, -23, 117, 187, -25, -17, 79, 213, -19, -11, 44, 228, -5}, + // Coefficients 6 taps + {-13, 20, 242, 20, -13, 0, -4, -6, 230, 50, -22, 8, 3, -23, 212, 84, -30, 10, 8, -34, 187, 120, -36, 11, + 11, -38, 155, 155, -38, 11, 11, -36, 120, 187, -34, 8, 10, -30, 84, 212, -23, 3, 8, -22, 50, 230, -6, -4}, + }, + + // Band_8_1120 + { + // Scaler inc range + {1119, 1120}, + // Coefficients 4 taps + {16, 224, 16, 0, -5, 228, 44, -11, -18, 212, 79, -17, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -17, 79, 212, -18, -11, 44, 228, -5}, + // Coefficients 6 taps + {-13, 20, 242, 20, -13, 0, -4, -6, 230, 50, -22, 8, 3, -23, 212, 84, -30, 10, 8, -34, 187, 120, -36, 11, + 11, -37, 154, 154, -37, 11, 11, -36, 120, 187, -34, 8, 10, -30, 84, 212, -23, 3, 8, -22, 50, 230, -6, -4}, + }, + + // Band_8_1121 + { + // Scaler inc range + {1120, 1121}, + // Coefficients 4 taps + {16, 224, 16, 0, -4, 226, 45, -11, -18, 212, 79, -17, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -17, 79, 212, -18, -11, 45, 226, -4}, + // Coefficients 6 taps + {-13, 20, 242, 20, -13, 0, -4, -5, 229, 50, -22, 8, 3, -23, 211, 85, -30, 10, 8, -34, 187, 120, -36, 11, + 11, -37, 154, 154, -37, 11, 11, -36, 120, 187, -34, 8, 10, -30, 85, 211, -23, 3, 8, -22, 50, 229, -5, -4}, + }, + + // Band_8_1123 + { + // Scaler inc range + {1121, 1123}, + // Coefficients 4 taps + {16, 224, 16, 0, -4, 226, 45, -11, -18, 213, 79, -18, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -18, 79, 213, -18, -11, 45, 226, -4}, + // Coefficients 6 taps + {-13, 20, 242, 20, -13, 0, -4, -5, 228, 51, -22, 8, 3, -23, 211, 85, -30, 10, 8, -33, 186, 120, -36, 11, + 11, -37, 154, 154, -37, 11, 11, -36, 120, 186, -33, 8, 10, -30, 85, 211, -23, 3, 8, -22, 51, 228, -5, -4}, + }, + + // Band_8_1124 + { + // Scaler inc range + {1123, 1124}, + // Coefficients 4 taps + {16, 224, 16, 0, -4, 226, 45, -11, -18, 213, 79, -18, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -18, 79, 213, -18, -11, 45, 226, -4}, + // Coefficients 6 taps + {-13, 21, 240, 21, -13, 0, -4, -5, 228, 51, -22, 8, 3, -23, 211, 85, -30, 10, 8, -33, 186, 120, -36, 11, + 11, -37, 154, 154, -37, 11, 11, -36, 120, 186, -33, 8, 10, -30, 85, 211, -23, 3, 8, -22, 51, 228, -5, -4}, + }, + + // Band_8_1125 + { + // Scaler inc range + {1124, 1125}, + // Coefficients 4 taps + {17, 222, 17, 0, -4, 226, 45, -11, -18, 213, 79, -18, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -18, 79, 213, -18, -11, 45, 226, -4}, + // Coefficients 6 taps + {-14, 21, 242, 21, -14, 0, -4, -5, 228, 51, -22, 8, 3, -23, 211, 85, -30, 10, 8, -33, 186, 120, -36, 11, + 11, -37, 154, 154, -37, 11, 11, -36, 120, 186, -33, 8, 10, -30, 85, 211, -23, 3, 8, -22, 51, 228, -5, -4}, + }, + + // Band_8_1126 + { + // Scaler inc range + {1125, 1126}, + // Coefficients 4 taps + {17, 222, 17, 0, -4, 226, 45, -11, -18, 213, 79, -18, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -18, 79, 213, -18, -11, 45, 226, -4}, + // Coefficients 6 taps + {-14, 21, 242, 21, -14, 0, -5, -4, 228, 51, -22, 8, 3, -22, 210, 85, -30, 10, 8, -33, 186, 120, -36, 11, + 11, -37, 154, 154, -37, 11, 11, -36, 120, 186, -33, 8, 10, -30, 85, 210, -22, 3, 8, -22, 51, 228, -4, -5}, + }, + + // Band_8_1128 + { + // Scaler inc range + {1126, 1128}, + // Coefficients 4 taps + {17, 222, 17, 0, -3, 225, 45, -11, -17, 212, 79, -18, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -18, 79, 212, -17, -11, 45, 225, -3}, + // Coefficients 6 taps + {-14, 21, 242, 21, -14, 0, -5, -4, 229, 51, -23, 8, 3, -22, 210, 85, -30, 10, 8, -33, 186, 120, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 120, 186, -33, 8, 10, -30, 85, 210, -22, 3, 8, -23, 51, 229, -4, -5}, + }, + + // Band_8_1129 + { + // Scaler inc range + {1128, 1129}, + // Coefficients 4 taps + {17, 222, 17, 0, -3, 225, 45, -11, -17, 211, 80, -18, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -18, 80, 211, -17, -11, 45, 225, -3}, + // Coefficients 6 taps + {-14, 22, 240, 22, -14, 0, -5, -4, 228, 52, -23, 8, 2, -22, 212, 85, -31, 10, 8, -33, 186, 120, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 120, 186, -33, 8, 10, -31, 85, 212, -22, 2, 8, -23, 52, 228, -4, -5}, + }, + + // Band_8_1130 + { + // Scaler inc range + {1129, 1130}, + // Coefficients 4 taps + {17, 222, 17, 0, -3, 224, 46, -11, -17, 211, 80, -18, -25, 187, 117, -23, + -26, 154, 154, -26, -23, 117, 187, -25, -18, 80, 211, -17, -11, 46, 224, -3}, + // Coefficients 6 taps + {-14, 22, 240, 22, -14, 0, -5, -4, 228, 52, -23, 8, 2, -22, 211, 86, -31, 10, 7, -33, 186, 121, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 121, 186, -33, 7, 10, -31, 86, 211, -22, 2, 8, -23, 52, 228, -4, -5}, + }, + + // Band_8_1131 + { + // Scaler inc range + {1130, 1131}, + // Coefficients 4 taps + {17, 222, 17, 0, -3, 225, 46, -12, -17, 211, 80, -18, -24, 186, 117, -23, + -26, 154, 154, -26, -23, 117, 186, -24, -18, 80, 211, -17, -12, 46, 225, -3}, + // Coefficients 6 taps + {-14, 22, 240, 22, -14, 0, -5, -4, 228, 52, -23, 8, 2, -22, 211, 86, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 121, 185, -32, 7, 10, -31, 86, 211, -22, 2, 8, -23, 52, 228, -4, -5}, + }, + + // Band_8_1132 + { + // Scaler inc range + {1131, 1132}, + // Coefficients 4 taps + {18, 220, 18, 0, -3, 225, 46, -12, -17, 211, 80, -18, -24, 186, 117, -23, + -26, 154, 154, -26, -23, 117, 186, -24, -18, 80, 211, -17, -12, 46, 225, -3}, + // Coefficients 6 taps + {-14, 22, 240, 22, -14, 0, -5, -3, 227, 52, -23, 8, 2, -21, 210, 86, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 121, 185, -32, 7, 10, -31, 86, 210, -21, 2, 8, -23, 52, 227, -3, -5}, + }, + + // Band_8_1134 + { + // Scaler inc range + {1132, 1134}, + // Coefficients 4 taps + {18, 220, 18, 0, -3, 225, 46, -12, -17, 211, 80, -18, -24, 186, 117, -23, + -26, 154, 154, -26, -23, 117, 186, -24, -18, 80, 211, -17, -12, 46, 225, -3}, + // Coefficients 6 taps + {-15, 22, 242, 22, -15, 0, -5, -3, 227, 52, -23, 8, 2, -21, 210, 86, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 121, 185, -32, 7, 10, -31, 86, 210, -21, 2, 8, -23, 52, 227, -3, -5}, + }, + + // Band_8_1135 + { + // Scaler inc range + {1134, 1135}, + // Coefficients 4 taps + {18, 220, 18, 0, -2, 224, 46, -12, -17, 211, 80, -18, -24, 186, 117, -23, + -26, 154, 154, -26, -23, 117, 186, -24, -18, 80, 211, -17, -12, 46, 224, -2}, + // Coefficients 6 taps + {-15, 23, 240, 23, -15, 0, -6, -3, 228, 52, -23, 8, 2, -21, 210, 86, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 121, 185, -32, 7, 10, -31, 86, 210, -21, 2, 8, -23, 52, 228, -3, -6}, + }, + + // Band_8_1136 + { + // Scaler inc range + {1135, 1136}, + // Coefficients 4 taps + {18, 220, 18, 0, -2, 224, 46, -12, -16, 210, 80, -18, -24, 186, 117, -23, + -26, 154, 154, -26, -23, 117, 186, -24, -18, 80, 210, -16, -12, 46, 224, -2}, + // Coefficients 6 taps + {-15, 23, 240, 23, -15, 0, -6, -3, 227, 53, -23, 8, 2, -21, 210, 86, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -37, 155, 155, -37, 10, 11, -36, 121, 185, -32, 7, 10, -31, 86, 210, -21, 2, 8, -23, 53, 227, -3, -6}, + }, + + // Band_8_1137 + { + // Scaler inc range + {1136, 1137}, + // Coefficients 4 taps + {18, 220, 18, 0, -2, 223, 47, -12, -16, 210, 80, -18, -24, 186, 117, -23, + -26, 154, 154, -26, -23, 117, 186, -24, -18, 80, 210, -16, -12, 47, 223, -2}, + // Coefficients 6 taps + {-15, 23, 240, 23, -15, 0, -6, -3, 227, 53, -23, 8, 2, -21, 210, 86, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -36, 154, 154, -36, 10, 11, -36, 121, 185, -32, 7, 10, -31, 86, 210, -21, 2, 8, -23, 53, 227, -3, -6}, + }, + + // Band_8_1139 + { + // Scaler inc range + {1137, 1139}, + // Coefficients 4 taps + {18, 220, 18, 0, -2, 223, 47, -12, -16, 210, 80, -18, -24, 186, 117, -23, + -26, 154, 154, -26, -23, 117, 186, -24, -18, 80, 210, -16, -12, 47, 223, -2}, + // Coefficients 6 taps + {-15, 23, 240, 23, -15, 0, -6, -2, 226, 53, -23, 8, 1, -21, 211, 86, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -36, 154, 154, -36, 10, 11, -36, 121, 185, -32, 7, 10, -31, 86, 211, -21, 1, 8, -23, 53, 226, -2, -6}, + }, + + // Band_8_1140 + { + // Scaler inc range + {1139, 1140}, + // Coefficients 4 taps + {19, 218, 19, 0, -2, 223, 47, -12, -16, 210, 80, -18, -24, 186, 117, -23, + -25, 153, 153, -25, -23, 117, 186, -24, -18, 80, 210, -16, -12, 47, 223, -2}, + // Coefficients 6 taps + {-15, 24, 238, 24, -15, 0, -6, -2, 227, 53, -24, 8, 1, -20, 209, 87, -31, 10, 7, -32, 185, 121, -36, 11, + 10, -36, 154, 154, -36, 10, 11, -36, 121, 185, -32, 7, 10, -31, 87, 209, -20, 1, 8, -24, 53, 227, -2, -6}, + }, + + // Band_8_1141 + { + // Scaler inc range + {1140, 1141}, + // Coefficients 4 taps + {19, 218, 19, 0, -2, 223, 47, -12, -16, 209, 81, -18, -24, 186, 117, -23, + -25, 153, 153, -25, -23, 117, 186, -24, -18, 81, 209, -16, -12, 47, 223, -2}, + // Coefficients 6 taps + {-15, 24, 238, 24, -15, 0, -6, -2, 227, 53, -24, 8, 1, -20, 209, 87, -31, 10, 6, -31, 185, 121, -36, 11, + 10, -36, 154, 154, -36, 10, 11, -36, 121, 185, -31, 6, 10, -31, 87, 209, -20, 1, 8, -24, 53, 227, -2, -6}, + }, + + // Band_8_1142 + { + // Scaler inc range + {1141, 1142}, + // Coefficients 4 taps + {19, 218, 19, 0, -1, 222, 47, -12, -16, 209, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 209, -16, -12, 47, 222, -1}, + // Coefficients 6 taps + {-15, 24, 238, 24, -15, 0, -6, -2, 226, 54, -24, 8, 1, -20, 209, 87, -31, 10, 6, -31, 185, 121, -36, 11, + 10, -36, 154, 154, -36, 10, 11, -36, 121, 185, -31, 6, 10, -31, 87, 209, -20, 1, 8, -24, 54, 226, -2, -6}, + }, + + // Band_8_1143 + { + // Scaler inc range + {1142, 1143}, + // Coefficients 4 taps + {19, 218, 19, 0, -1, 222, 47, -12, -15, 208, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 208, -15, -12, 47, 222, -1}, + // Coefficients 6 taps + {-16, 24, 240, 24, -16, 0, -6, -1, 224, 54, -24, 9, 1, -20, 209, 87, -31, 10, 6, -31, 185, 121, -36, 11, + 10, -36, 154, 154, -36, 10, 11, -36, 121, 185, -31, 6, 10, -31, 87, 209, -20, 1, 9, -24, 54, 224, -1, -6}, + }, + + // Band_8_1145 + { + // Scaler inc range + {1143, 1145}, + // Coefficients 4 taps + {19, 218, 19, 0, -1, 222, 47, -12, -15, 208, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 208, -15, -12, 47, 222, -1}, + // Coefficients 6 taps + {-16, 25, 238, 25, -16, 0, -7, -1, 225, 54, -24, 9, 1, -20, 209, 87, -31, 10, 6, -31, 185, 121, -36, 11, + 9, -36, 155, 155, -36, 9, 11, -36, 121, 185, -31, 6, 10, -31, 87, 209, -20, 1, 9, -24, 54, 225, -1, -7}, + }, + + // Band_8_1146 + { + // Scaler inc range + {1145, 1146}, + // Coefficients 4 taps + {19, 218, 19, 0, -1, 221, 48, -12, -15, 208, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 208, -15, -12, 48, 221, -1}, + // Coefficients 6 taps + {-16, 25, 238, 25, -16, 0, -7, -1, 225, 54, -24, 9, 1, -19, 208, 87, -31, 10, 6, -31, 185, 121, -36, 11, + 9, -36, 155, 155, -36, 9, 11, -36, 121, 185, -31, 6, 10, -31, 87, 208, -19, 1, 9, -24, 54, 225, -1, -7}, + }, + + // Band_8_1147 + { + // Scaler inc range + {1146, 1147}, + // Coefficients 4 taps + {19, 218, 19, 0, -1, 221, 48, -12, -15, 208, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 208, -15, -12, 48, 221, -1}, + // Coefficients 6 taps + {-16, 25, 238, 25, -16, 0, -7, -1, 225, 54, -24, 9, 0, -19, 209, 87, -31, 10, 6, -31, 184, 122, -36, 11, + 9, -36, 155, 155, -36, 9, 11, -36, 122, 184, -31, 6, 10, -31, 87, 209, -19, 0, 9, -24, 54, 225, -1, -7}, + }, + + // Band_8_1148 + { + // Scaler inc range + {1147, 1148}, + // Coefficients 4 taps + {20, 216, 20, 0, 0, 220, 48, -12, -15, 208, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 208, -15, -12, 48, 220, 0}, + // Coefficients 6 taps + {-16, 25, 238, 25, -16, 0, -7, -1, 224, 55, -24, 9, 0, -19, 208, 88, -31, 10, 6, -31, 184, 122, -36, 11, + 9, -36, 155, 155, -36, 9, 11, -36, 122, 184, -31, 6, 10, -31, 88, 208, -19, 0, 9, -24, 55, 224, -1, -7}, + }, + + // Band_8_1150 + { + // Scaler inc range + {1148, 1150}, + // Coefficients 4 taps + {20, 216, 20, 0, 0, 220, 48, -12, -15, 208, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 208, -15, -12, 48, 220, 0}, + // Coefficients 6 taps + {-16, 25, 238, 25, -16, 0, -7, 0, 223, 55, -24, 9, 0, -19, 208, 88, -31, 10, 6, -30, 184, 122, -36, 10, + 9, -36, 155, 155, -36, 9, 10, -36, 122, 184, -30, 6, 10, -31, 88, 208, -19, 0, 9, -24, 55, 223, 0, -7}, + }, + + // Band_8_1151 + { + // Scaler inc range + {1150, 1151}, + // Coefficients 4 taps + {20, 216, 20, 0, 0, 220, 48, -12, -15, 208, 81, -18, -23, 185, 117, -23, + -25, 153, 153, -25, -23, 117, 185, -23, -18, 81, 208, -15, -12, 48, 220, 0}, + // Coefficients 6 taps + {-16, 26, 236, 26, -16, 0, -7, 0, 223, 55, -24, 9, 0, -19, 208, 88, -31, 10, 6, -30, 184, 122, -36, 10, + 9, -36, 155, 155, -36, 9, 10, -36, 122, 184, -30, 6, 10, -31, 88, 208, -19, 0, 9, -24, 55, 223, 0, -7}, + }, + + // Band_8_1152 + { + // Scaler inc range + {1151, 1152}, + // Coefficients 4 taps + {20, 216, 20, 0, 0, 220, 48, -12, -14, 207, 81, -18, -22, 184, 117, -23, + -25, 153, 153, -25, -23, 117, 184, -22, -18, 81, 207, -14, -12, 48, 220, 0}, + // Coefficients 6 taps + {-17, 26, 238, 26, -17, 0, -7, 0, 223, 55, -24, 9, 0, -18, 207, 88, -31, 10, 6, -30, 183, 122, -35, 10, + 9, -35, 154, 154, -35, 9, 10, -35, 122, 183, -30, 6, 10, -31, 88, 207, -18, 0, 9, -24, 55, 223, 0, -7}, + }, + + // Band_8_1154 + { + // Scaler inc range + {1152, 1154}, + // Coefficients 4 taps + {20, 216, 20, 0, 0, 220, 48, -12, -14, 207, 81, -18, -22, 184, 117, -23, + -25, 153, 153, -25, -23, 117, 184, -22, -18, 81, 207, -14, -12, 48, 220, 0}, + // Coefficients 6 taps + {-17, 26, 238, 26, -17, 0, -8, 0, 225, 55, -25, 9, 0, -18, 207, 88, -31, 10, 5, -30, 184, 122, -35, 10, + 9, -35, 154, 154, -35, 9, 10, -35, 122, 184, -30, 5, 10, -31, 88, 207, -18, 0, 9, -25, 55, 225, 0, -8}, + }, + + // Band_8_1155 + { + // Scaler inc range + {1154, 1155}, + // Coefficients 4 taps + {20, 216, 20, 0, 0, 219, 49, -12, -14, 206, 82, -18, -22, 184, 117, -23, + -25, 153, 153, -25, -23, 117, 184, -22, -18, 82, 206, -14, -12, 49, 219, 0}, + // Coefficients 6 taps + {-17, 26, 238, 26, -17, 0, -8, 0, 224, 56, -25, 9, 0, -18, 207, 88, -31, 10, 5, -30, 184, 122, -35, 10, + 9, -35, 154, 154, -35, 9, 10, -35, 122, 184, -30, 5, 10, -31, 88, 207, -18, 0, 9, -25, 56, 224, 0, -8}, + }, + + // Band_8_1156 + { + // Scaler inc range + {1155, 1156}, + // Coefficients 4 taps + {21, 214, 21, 0, 1, 218, 49, -12, -14, 206, 82, -18, -22, 184, 117, -23, + -25, 153, 153, -25, -23, 117, 184, -22, -18, 82, 206, -14, -12, 49, 218, 1}, + // Coefficients 6 taps + {-17, 27, 236, 27, -17, 0, -8, 1, 223, 56, -25, 9, 0, -18, 207, 88, -31, 10, 5, -30, 184, 122, -35, 10, + 9, -35, 154, 154, -35, 9, 10, -35, 122, 184, -30, 5, 10, -31, 88, 207, -18, 0, 9, -25, 56, 223, 1, -8}, + }, + + // Band_8_1157 + { + // Scaler inc range + {1156, 1157}, + // Coefficients 4 taps + {21, 214, 21, 0, 1, 218, 49, -12, -14, 206, 82, -18, -22, 184, 117, -23, + -25, 153, 153, -25, -23, 117, 184, -22, -18, 82, 206, -14, -12, 49, 218, 1}, + // Coefficients 6 taps + {-17, 27, 236, 27, -17, 0, -8, 1, 223, 56, -25, 9, -1, -18, 208, 89, -32, 10, 5, -30, 184, 122, -35, 10, + 9, -35, 154, 154, -35, 9, 10, -35, 122, 184, -30, 5, 10, -32, 89, 208, -18, -1, 9, -25, 56, 223, 1, -8}, + }, + + // Band_8_1159 + { + // Scaler inc range + {1157, 1159}, + // Coefficients 4 taps + {21, 214, 21, 0, 1, 218, 49, -12, -14, 206, 82, -18, -22, 184, 117, -23, + -24, 152, 152, -24, -23, 117, 184, -22, -18, 82, 206, -14, -12, 49, 218, 1}, + // Coefficients 6 taps + {-17, 27, 236, 27, -17, 0, -8, 1, 223, 56, -25, 9, -1, -17, 207, 89, -32, 10, 5, -29, 183, 122, -35, 10, + 9, -35, 154, 154, -35, 9, 10, -35, 122, 183, -29, 5, 10, -32, 89, 207, -17, -1, 9, -25, 56, 223, 1, -8}, + }, + + // Band_8_1160 + { + // Scaler inc range + {1159, 1160}, + // Coefficients 4 taps + {21, 214, 21, 0, 1, 218, 49, -12, -13, 205, 82, -18, -22, 184, 117, -23, + -24, 152, 152, -24, -23, 117, 184, -22, -18, 82, 205, -13, -12, 49, 218, 1}, + // Coefficients 6 taps + {-17, 27, 236, 27, -17, 0, -8, 1, 223, 56, -25, 9, -1, -17, 207, 89, -32, 10, 5, -29, 183, 122, -35, 10, + 8, -35, 155, 155, -35, 8, 10, -35, 122, 183, -29, 5, 10, -32, 89, 207, -17, -1, 9, -25, 56, 223, 1, -8}, + }, + + // Band_8_1161 + { + // Scaler inc range + {1160, 1161}, + // Coefficients 4 taps + {21, 214, 21, 0, 1, 218, 49, -12, -13, 205, 82, -18, -22, 184, 117, -23, + -24, 152, 152, -24, -23, 117, 184, -22, -18, 82, 205, -13, -12, 49, 218, 1}, + // Coefficients 6 taps + {-17, 27, 236, 27, -17, 0, -8, 2, 222, 56, -25, 9, -1, -17, 207, 89, -32, 10, 5, -29, 183, 122, -35, 10, + 8, -35, 155, 155, -35, 8, 10, -35, 122, 183, -29, 5, 10, -32, 89, 207, -17, -1, 9, -25, 56, 222, 2, -8}, + }, + + // Band_8_1163 + { + // Scaler inc range + {1161, 1163}, + // Coefficients 4 taps + {21, 214, 21, 0, 1, 218, 49, -12, -13, 205, 82, -18, -22, 184, 117, -23, + -24, 152, 152, -24, -23, 117, 184, -22, -18, 82, 205, -13, -12, 49, 218, 1}, + // Coefficients 6 taps + {-17, 28, 234, 28, -17, 0, -9, 2, 222, 57, -25, 9, -1, -17, 207, 89, -32, 10, 5, -29, 183, 122, -35, 10, + 8, -35, 155, 155, -35, 8, 10, -35, 122, 183, -29, 5, 10, -32, 89, 207, -17, -1, 9, -25, 57, 222, 2, -9}, + }, + + // Band_8_1164 + { + // Scaler inc range + {1163, 1164}, + // Coefficients 4 taps + {22, 212, 22, 0, 2, 217, 50, -13, -13, 205, 82, -18, -21, 182, 117, -22, + -24, 152, 152, -24, -22, 117, 182, -21, -18, 82, 205, -13, -13, 50, 217, 2}, + // Coefficients 6 taps + {-18, 28, 236, 28, -18, 0, -9, 2, 222, 57, -25, 9, -1, -17, 207, 89, -32, 10, 5, -29, 183, 122, -35, 10, + 8, -35, 155, 155, -35, 8, 10, -35, 122, 183, -29, 5, 10, -32, 89, 207, -17, -1, 9, -25, 57, 222, 2, -9}, + }, + + // Band_8_1165 + { + // Scaler inc range + {1164, 1165}, + // Coefficients 4 taps + {22, 212, 22, 0, 2, 217, 50, -13, -13, 205, 82, -18, -21, 182, 117, -22, + -24, 152, 152, -24, -22, 117, 182, -21, -18, 82, 205, -13, -13, 50, 217, 2}, + // Coefficients 6 taps + {-18, 28, 236, 28, -18, 0, -9, 2, 222, 57, -25, 9, -1, -17, 207, 89, -32, 10, 4, -29, 183, 123, -35, 10, + 8, -35, 155, 155, -35, 8, 10, -35, 123, 183, -29, 4, 10, -32, 89, 207, -17, -1, 9, -25, 57, 222, 2, -9}, + }, + + // Band_8_1166 + { + // Scaler inc range + {1165, 1166}, + // Coefficients 4 taps + {22, 212, 22, 0, 2, 217, 50, -13, -13, 205, 82, -18, -21, 182, 117, -22, + -24, 152, 152, -24, -22, 117, 182, -21, -18, 82, 205, -13, -13, 50, 217, 2}, + // Coefficients 6 taps + {-18, 28, 236, 28, -18, 0, -9, 2, 222, 57, -25, 9, -1, -16, 206, 89, -32, 10, 4, -28, 182, 123, -35, 10, + 8, -34, 154, 154, -34, 8, 10, -35, 123, 182, -28, 4, 10, -32, 89, 206, -16, -1, 9, -25, 57, 222, 2, -9}, + }, + + // Band_8_1168 + { + // Scaler inc range + {1166, 1168}, + // Coefficients 4 taps + {22, 212, 22, 0, 2, 217, 50, -13, -13, 205, 82, -18, -21, 181, 118, -22, + -24, 152, 152, -24, -22, 118, 181, -21, -18, 82, 205, -13, -13, 50, 217, 2}, + // Coefficients 6 taps + {-18, 29, 234, 29, -18, 0, -9, 3, 221, 57, -25, 9, -2, -16, 206, 90, -32, 10, 4, -28, 182, 123, -35, 10, + 8, -34, 154, 154, -34, 8, 10, -35, 123, 182, -28, 4, 10, -32, 90, 206, -16, -2, 9, -25, 57, 221, 3, -9}, + }, + + // Band_8_1169 + { + // Scaler inc range + {1168, 1169}, + // Coefficients 4 taps + {22, 212, 22, 0, 2, 217, 50, -13, -12, 204, 82, -18, -21, 181, 118, -22, + -24, 152, 152, -24, -22, 118, 181, -21, -18, 82, 204, -12, -13, 50, 217, 2}, + // Coefficients 6 taps + {-18, 29, 234, 29, -18, 0, -9, 3, 220, 58, -25, 9, -2, -16, 206, 90, -32, 10, 4, -28, 182, 123, -35, 10, + 8, -34, 154, 154, -34, 8, 10, -35, 123, 182, -28, 4, 10, -32, 90, 206, -16, -2, 9, -25, 58, 220, 3, -9}, + }, + + // Band_8_1170 + { + // Scaler inc range + {1169, 1170}, + // Coefficients 4 taps + {22, 212, 22, 0, 2, 217, 50, -13, -12, 203, 83, -18, -21, 181, 118, -22, + -24, 152, 152, -24, -22, 118, 181, -21, -18, 83, 203, -12, -13, 50, 217, 2}, + // Coefficients 6 taps + {-18, 29, 234, 29, -18, 0, -9, 3, 221, 58, -26, 9, -2, -16, 206, 90, -32, 10, 4, -28, 182, 123, -35, 10, + 8, -34, 154, 154, -34, 8, 10, -35, 123, 182, -28, 4, 10, -32, 90, 206, -16, -2, 9, -26, 58, 221, 3, -9}, + }, + + // Band_8_1172 + { + // Scaler inc range + {1170, 1172}, + // Coefficients 4 taps + {23, 210, 23, 0, 3, 216, 50, -13, -12, 203, 83, -18, -21, 181, 118, -22, + -24, 152, 152, -24, -22, 118, 181, -21, -18, 83, 203, -12, -13, 50, 216, 3}, + // Coefficients 6 taps + {-18, 29, 234, 29, -18, 0, -9, 3, 221, 58, -26, 9, -2, -16, 206, 90, -32, 10, 4, -28, 182, 123, -35, 10, + 8, -34, 154, 154, -34, 8, 10, -35, 123, 182, -28, 4, 10, -32, 90, 206, -16, -2, 9, -26, 58, 221, 3, -9}, + }, + + // Band_8_1173 + { + // Scaler inc range + {1172, 1173}, + // Coefficients 4 taps + {23, 210, 23, 0, 3, 216, 50, -13, -12, 203, 83, -18, -21, 181, 118, -22, + -24, 152, 152, -24, -22, 118, 181, -21, -18, 83, 203, -12, -13, 50, 216, 3}, + // Coefficients 6 taps + {-18, 29, 234, 29, -18, 0, -10, 4, 221, 58, -26, 9, -2, -15, 205, 90, -32, 10, 4, -28, 182, 123, -35, 10, + 8, -34, 154, 154, -34, 8, 10, -35, 123, 182, -28, 4, 10, -32, 90, 205, -15, -2, 9, -26, 58, 221, 4, -10}, + }, + + // Band_8_1174 + { + // Scaler inc range + {1173, 1174}, + // Coefficients 4 taps + {23, 210, 23, 0, 3, 215, 51, -13, -12, 203, 83, -18, -20, 180, 118, -22, + -24, 152, 152, -24, -22, 118, 180, -20, -18, 83, 203, -12, -13, 51, 215, 3}, + // Coefficients 6 taps + {-19, 30, 234, 30, -19, 0, -10, 4, 221, 58, -26, 9, -2, -15, 205, 90, -32, 10, 4, -28, 182, 123, -35, 10, + 8, -34, 154, 154, -34, 8, 10, -35, 123, 182, -28, 4, 10, -32, 90, 205, -15, -2, 9, -26, 58, 221, 4, -10}, + }, + + // Band_8_1176 + { + // Scaler inc range + {1174, 1176}, + // Coefficients 4 taps + {23, 210, 23, 0, 3, 215, 51, -13, -12, 203, 83, -18, -20, 180, 118, -22, + -23, 151, 151, -23, -22, 118, 180, -20, -18, 83, 203, -12, -13, 51, 215, 3}, + // Coefficients 6 taps + {-19, 30, 234, 30, -19, 0, -10, 4, 221, 58, -26, 9, -2, -15, 205, 90, -32, 10, 3, -27, 183, 123, -35, 9, + 7, -34, 155, 155, -34, 7, 9, -35, 123, 183, -27, 3, 10, -32, 90, 205, -15, -2, 9, -26, 58, 221, 4, -10}, + }, + + // Band_8_1177 + { + // Scaler inc range + {1176, 1177}, + // Coefficients 4 taps + {23, 210, 23, 0, 3, 215, 51, -13, -11, 202, 83, -18, -20, 180, 118, -22, + -23, 151, 151, -23, -22, 118, 180, -20, -18, 83, 202, -11, -13, 51, 215, 3}, + // Coefficients 6 taps + {-19, 30, 234, 30, -19, 0, -10, 4, 220, 59, -26, 9, -2, -15, 205, 90, -32, 10, 3, -27, 183, 123, -35, 9, + 7, -34, 155, 155, -34, 7, 9, -35, 123, 183, -27, 3, 10, -32, 90, 205, -15, -2, 9, -26, 59, 220, 4, -10}, + }, + + // Band_8_1178 + { + // Scaler inc range + {1177, 1178}, + // Coefficients 4 taps + {23, 210, 23, 0, 4, 214, 51, -13, -11, 202, 83, -18, -20, 180, 118, -22, + -23, 151, 151, -23, -22, 118, 180, -20, -18, 83, 202, -11, -13, 51, 214, 4}, + // Coefficients 6 taps + {-19, 30, 234, 30, -19, 0, -10, 4, 220, 59, -26, 9, -3, -15, 205, 91, -32, 10, 3, -27, 183, 123, -35, 9, + 7, -34, 155, 155, -34, 7, 9, -35, 123, 183, -27, 3, 10, -32, 91, 205, -15, -3, 9, -26, 59, 220, 4, -10}, + }, + + // Band_8_1180 + { + // Scaler inc range + {1178, 1180}, + // Coefficients 4 taps + {23, 210, 23, 0, 4, 214, 51, -13, -11, 202, 83, -18, -20, 180, 118, -22, + -23, 151, 151, -23, -22, 118, 180, -20, -18, 83, 202, -11, -13, 51, 214, 4}, + // Coefficients 6 taps + {-19, 31, 232, 31, -19, 0, -10, 5, 219, 59, -26, 9, -3, -14, 204, 91, -32, 10, 3, -27, 183, 123, -35, 9, + 7, -33, 154, 154, -33, 7, 9, -35, 123, 183, -27, 3, 10, -32, 91, 204, -14, -3, 9, -26, 59, 219, 5, -10}, + }, + + // Band_8_1181 + { + // Scaler inc range + {1180, 1181}, + // Coefficients 4 taps + {24, 208, 24, 0, 4, 214, 51, -13, -11, 202, 83, -18, -20, 180, 118, -22, + -23, 151, 151, -23, -22, 118, 180, -20, -18, 83, 202, -11, -13, 51, 214, 4}, + // Coefficients 6 taps + {-19, 31, 232, 31, -19, 0, -10, 5, 219, 59, -26, 9, -3, -14, 204, 91, -32, 10, 3, -27, 183, 123, -35, 9, + 7, -33, 154, 154, -33, 7, 9, -35, 123, 183, -27, 3, 10, -32, 91, 204, -14, -3, 9, -26, 59, 219, 5, -10}, + }, + + // Band_8_1182 + { + // Scaler inc range + {1181, 1182}, + // Coefficients 4 taps + {24, 208, 24, 0, 4, 214, 51, -13, -11, 202, 83, -18, -20, 180, 118, -22, + -23, 151, 151, -23, -22, 118, 180, -20, -18, 83, 202, -11, -13, 51, 214, 4}, + // Coefficients 6 taps + {-19, 31, 232, 31, -19, 0, -10, 5, 219, 59, -26, 9, -3, -14, 204, 91, -32, 10, 3, -27, 183, 123, -35, 9, + 7, -33, 154, 154, -33, 7, 9, -35, 123, 183, -27, 3, 10, -32, 91, 204, -14, -3, 9, -26, 59, 219, 5, -10}, + }, + + // Band_8_1183 + { + // Scaler inc range + {1182, 1183}, + // Coefficients 4 taps + {24, 208, 24, 0, 4, 213, 52, -13, -11, 202, 83, -18, -20, 180, 118, -22, + -23, 151, 151, -23, -22, 118, 180, -20, -18, 83, 202, -11, -13, 52, 213, 4}, + // Coefficients 6 taps + {-19, 31, 232, 31, -19, 0, -11, 5, 220, 59, -26, 9, -3, -14, 204, 91, -32, 10, 3, -26, 182, 123, -35, 9, + 7, -33, 154, 154, -33, 7, 9, -35, 123, 182, -26, 3, 10, -32, 91, 204, -14, -3, 9, -26, 59, 220, 5, -11}, + }, + + // Band_8_1185 + { + // Scaler inc range + {1183, 1185}, + // Coefficients 4 taps + {24, 208, 24, 0, 4, 213, 52, -13, -10, 201, 83, -18, -19, 179, 118, -22, + -23, 151, 151, -23, -22, 118, 179, -19, -18, 83, 201, -10, -13, 52, 213, 4}, + // Coefficients 6 taps + {-19, 31, 232, 31, -19, 0, -11, 5, 219, 60, -26, 9, -3, -14, 204, 91, -32, 10, 3, -26, 182, 123, -35, 9, + 7, -33, 154, 154, -33, 7, 9, -35, 123, 182, -26, 3, 10, -32, 91, 204, -14, -3, 9, -26, 60, 219, 5, -11}, + }, + + // Band_8_1186 + { + // Scaler inc range + {1185, 1186}, + // Coefficients 4 taps + {24, 208, 24, 0, 5, 212, 52, -13, -10, 200, 84, -18, -19, 179, 118, -22, + -23, 151, 151, -23, -22, 118, 179, -19, -18, 84, 200, -10, -13, 52, 212, 5}, + // Coefficients 6 taps + {-20, 32, 232, 32, -20, 0, -11, 6, 218, 60, -26, 9, -3, -13, 203, 91, -32, 10, 3, -26, 181, 124, -35, 9, + 7, -33, 154, 154, -33, 7, 9, -35, 124, 181, -26, 3, 10, -32, 91, 203, -13, -3, 9, -26, 60, 218, 6, -11}, + }, + + // Band_8_1188 + { + // Scaler inc range + {1186, 1188}, + // Coefficients 4 taps + {24, 208, 24, 0, 5, 212, 52, -13, -10, 200, 84, -18, -19, 179, 118, -22, + -23, 151, 151, -23, -22, 118, 179, -19, -18, 84, 200, -10, -13, 52, 212, 5}, + // Coefficients 6 taps + {-20, 32, 232, 32, -20, 0, -11, 6, 218, 60, -26, 9, -4, -13, 203, 92, -32, 10, 2, -26, 182, 124, -35, 9, + 7, -33, 154, 154, -33, 7, 9, -35, 124, 182, -26, 2, 10, -32, 92, 203, -13, -4, 9, -26, 60, 218, 6, -11}, + }, + + // Band_8_1189 + { + // Scaler inc range + {1188, 1189}, + // Coefficients 4 taps + {25, 206, 25, 0, 5, 212, 52, -13, -10, 200, 84, -18, -19, 179, 118, -22, + -23, 151, 151, -23, -22, 118, 179, -19, -18, 84, 200, -10, -13, 52, 212, 5}, + // Coefficients 6 taps + {-20, 32, 232, 32, -20, 0, -11, 6, 219, 60, -27, 9, -4, -13, 204, 92, -32, 9, 2, -26, 181, 124, -34, 9, + 7, -33, 154, 154, -33, 7, 9, -34, 124, 181, -26, 2, 9, -32, 92, 204, -13, -4, 9, -27, 60, 219, 6, -11}, + }, + + // Band_8_1190 + { + // Scaler inc range + {1189, 1190}, + // Coefficients 4 taps + {25, 206, 25, 0, 5, 212, 52, -13, -10, 200, 84, -18, -19, 179, 118, -22, + -23, 151, 151, -23, -22, 118, 179, -19, -18, 84, 200, -10, -13, 52, 212, 5}, + // Coefficients 6 taps + {-20, 32, 232, 32, -20, 0, -11, 6, 219, 60, -27, 9, -4, -13, 204, 92, -32, 9, 2, -26, 181, 124, -34, 9, + 6, -33, 155, 155, -33, 6, 9, -34, 124, 181, -26, 2, 9, -32, 92, 204, -13, -4, 9, -27, 60, 219, 6, -11}, + }, + + // Band_8_1192 + { + // Scaler inc range + {1190, 1192}, + // Coefficients 4 taps + {25, 206, 25, 0, 5, 212, 52, -13, -10, 200, 84, -18, -19, 179, 118, -22, + -22, 150, 150, -22, -22, 118, 179, -19, -18, 84, 200, -10, -13, 52, 212, 5}, + // Coefficients 6 taps + {-20, 32, 232, 32, -20, 0, -11, 7, 217, 61, -27, 9, -4, -13, 204, 92, -32, 9, 2, -25, 180, 124, -34, 9, + 6, -33, 155, 155, -33, 6, 9, -34, 124, 180, -25, 2, 9, -32, 92, 204, -13, -4, 9, -27, 61, 217, 7, -11}, + }, + + // Band_8_1193 + { + // Scaler inc range + {1192, 1193}, + // Coefficients 4 taps + {25, 206, 25, 0, 5, 211, 53, -13, -10, 200, 84, -18, -19, 179, 118, -22, + -22, 150, 150, -22, -22, 118, 179, -19, -18, 84, 200, -10, -13, 53, 211, 5}, + // Coefficients 6 taps + {-20, 33, 230, 33, -20, 0, -11, 7, 217, 61, -27, 9, -4, -12, 203, 92, -32, 9, 2, -25, 180, 124, -34, 9, + 6, -32, 154, 154, -32, 6, 9, -34, 124, 180, -25, 2, 9, -32, 92, 203, -12, -4, 9, -27, 61, 217, 7, -11}, + }, + + // Band_8_1194 + { + // Scaler inc range + {1193, 1194}, + // Coefficients 4 taps + {25, 206, 25, 0, 6, 210, 53, -13, -9, 199, 84, -18, -19, 179, 118, -22, + -22, 150, 150, -22, -22, 118, 179, -19, -18, 84, 199, -9, -13, 53, 210, 6}, + // Coefficients 6 taps + {-20, 33, 230, 33, -20, 0, -12, 7, 218, 61, -27, 9, -4, -12, 203, 92, -32, 9, 2, -25, 180, 124, -34, 9, + 6, -32, 154, 154, -32, 6, 9, -34, 124, 180, -25, 2, 9, -32, 92, 203, -12, -4, 9, -27, 61, 218, 7, -12}, + }, + + // Band_8_1196 + { + // Scaler inc range + {1194, 1196}, + // Coefficients 4 taps + {25, 206, 25, 0, 6, 210, 53, -13, -9, 199, 84, -18, -18, 178, 118, -22, + -22, 150, 150, -22, -22, 118, 178, -18, -18, 84, 199, -9, -13, 53, 210, 6}, + // Coefficients 6 taps + {-20, 33, 230, 33, -20, 0, -12, 7, 218, 61, -27, 9, -4, -12, 203, 92, -32, 9, 2, -25, 180, 124, -34, 9, + 6, -32, 154, 154, -32, 6, 9, -34, 124, 180, -25, 2, 9, -32, 92, 203, -12, -4, 9, -27, 61, 218, 7, -12}, + }, + + // Band_8_1197 + { + // Scaler inc range + {1196, 1197}, + // Coefficients 4 taps + {25, 206, 25, 0, 6, 210, 53, -13, -9, 199, 84, -18, -18, 178, 118, -22, + -22, 150, 150, -22, -22, 118, 178, -18, -18, 84, 199, -9, -13, 53, 210, 6}, + // Coefficients 6 taps + {-20, 33, 230, 33, -20, 0, -12, 7, 218, 61, -27, 9, -4, -12, 203, 92, -32, 9, 2, -25, 181, 124, -34, 8, + 6, -32, 154, 154, -32, 6, 8, -34, 124, 181, -25, 2, 9, -32, 92, 203, -12, -4, 9, -27, 61, 218, 7, -12}, + }, + + // Band_8_1198 + { + // Scaler inc range + {1197, 1198}, + // Coefficients 4 taps + {26, 204, 26, 0, 6, 210, 53, -13, -9, 199, 84, -18, -18, 178, 118, -22, + -22, 150, 150, -22, -22, 118, 178, -18, -18, 84, 199, -9, -13, 53, 210, 6}, + // Coefficients 6 taps + {-20, 34, 228, 34, -20, 0, -12, 8, 217, 61, -27, 9, -5, -12, 204, 92, -32, 9, 2, -25, 181, 124, -34, 8, + 6, -32, 154, 154, -32, 6, 8, -34, 124, 181, -25, 2, 9, -32, 92, 204, -12, -5, 9, -27, 61, 217, 8, -12}, + }, + + // Band_8_1200 + { + // Scaler inc range + {1198, 1200}, + // Coefficients 4 taps + {26, 204, 26, 0, 6, 210, 53, -13, -9, 199, 84, -18, -18, 177, 118, -21, + -22, 150, 150, -22, -21, 118, 177, -18, -18, 84, 199, -9, -13, 53, 210, 6}, + // Coefficients 6 taps + {-21, 34, 230, 34, -21, 0, -12, 8, 216, 62, -27, 9, -5, -11, 202, 93, -32, 9, 1, -25, 182, 124, -34, 8, + 6, -32, 154, 154, -32, 6, 8, -34, 124, 182, -25, 1, 9, -32, 93, 202, -11, -5, 9, -27, 62, 216, 8, -12}, + }, + + // Band_8_1201 + { + // Scaler inc range + {1200, 1201}, + // Coefficients 4 taps + {26, 204, 26, 0, 6, 210, 53, -13, -9, 199, 84, -18, -18, 177, 118, -21, + -22, 150, 150, -22, -21, 118, 177, -18, -18, 84, 199, -9, -13, 53, 210, 6}, + // Coefficients 6 taps + {-21, 34, 230, 34, -21, 0, -12, 8, 216, 62, -27, 9, -5, -11, 202, 93, -32, 9, 1, -24, 181, 124, -34, 8, + 6, -32, 154, 154, -32, 6, 8, -34, 124, 181, -24, 1, 9, -32, 93, 202, -11, -5, 9, -27, 62, 216, 8, -12}, + }, + + // Band_8_1202 + { + // Scaler inc range + {1201, 1202}, + // Coefficients 4 taps + {26, 204, 26, 0, 7, 209, 53, -13, -8, 198, 84, -18, -18, 177, 118, -21, + -22, 150, 150, -22, -21, 118, 177, -18, -18, 84, 198, -8, -13, 53, 209, 7}, + // Coefficients 6 taps + {-21, 34, 230, 34, -21, 0, -12, 8, 216, 62, -27, 9, -5, -11, 202, 93, -32, 9, 1, -24, 181, 124, -34, 8, + 6, -32, 154, 154, -32, 6, 8, -34, 124, 181, -24, 1, 9, -32, 93, 202, -11, -5, 9, -27, 62, 216, 8, -12}, + }, + + // Band_8_1204 + { + // Scaler inc range + {1202, 1204}, + // Coefficients 4 taps + {26, 204, 26, 0, 7, 208, 54, -13, -8, 198, 84, -18, -18, 177, 118, -21, + -22, 150, 150, -22, -21, 118, 177, -18, -18, 84, 198, -8, -13, 54, 208, 7}, + // Coefficients 6 taps + {-21, 34, 230, 34, -21, 0, -12, 9, 215, 62, -27, 9, -5, -11, 202, 93, -32, 9, 1, -24, 181, 124, -34, 8, + 5, -32, 155, 155, -32, 5, 8, -34, 124, 181, -24, 1, 9, -32, 93, 202, -11, -5, 9, -27, 62, 215, 9, -12}, + }, + + // Band_8_1205 + { + // Scaler inc range + {1204, 1205}, + // Coefficients 4 taps + {26, 204, 26, 0, 7, 208, 54, -13, -8, 197, 85, -18, -17, 176, 118, -21, + -22, 150, 150, -22, -21, 118, 176, -17, -18, 85, 197, -8, -13, 54, 208, 7}, + // Coefficients 6 taps + {-21, 35, 228, 35, -21, 0, -13, 9, 216, 62, -27, 9, -5, -11, 202, 93, -32, 9, 1, -24, 181, 124, -34, 8, + 5, -31, 154, 154, -31, 5, 8, -34, 124, 181, -24, 1, 9, -32, 93, 202, -11, -5, 9, -27, 62, 216, 9, -13}, + }, + + // Band_8_1207 + { + // Scaler inc range + {1205, 1207}, + // Coefficients 4 taps + {27, 202, 27, 0, 7, 208, 54, -13, -8, 197, 85, -18, -17, 176, 118, -21, + -21, 149, 149, -21, -21, 118, 176, -17, -18, 85, 197, -8, -13, 54, 208, 7}, + // Coefficients 6 taps + {-21, 35, 228, 35, -21, 0, -13, 9, 216, 62, -27, 9, -5, -10, 201, 93, -32, 9, 1, -24, 181, 124, -34, 8, + 5, -31, 154, 154, -31, 5, 8, -34, 124, 181, -24, 1, 9, -32, 93, 201, -10, -5, 9, -27, 62, 216, 9, -13}, + }, + + // Band_8_1208 + { + // Scaler inc range + {1207, 1208}, + // Coefficients 4 taps + {27, 202, 27, 0, 7, 208, 54, -13, -8, 197, 85, -18, -17, 176, 118, -21, + -21, 149, 149, -21, -21, 118, 176, -17, -18, 85, 197, -8, -13, 54, 208, 7}, + // Coefficients 6 taps + {-21, 35, 228, 35, -21, 0, -13, 9, 215, 63, -27, 9, -5, -10, 201, 93, -32, 9, 1, -24, 181, 124, -34, 8, + 5, -31, 154, 154, -31, 5, 8, -34, 124, 181, -24, 1, 9, -32, 93, 201, -10, -5, 9, -27, 63, 215, 9, -13}, + }, + + // Band_8_1209 + { + // Scaler inc range + {1208, 1209}, + // Coefficients 4 taps + {27, 202, 27, 0, 7, 208, 54, -13, -8, 197, 85, -18, -17, 176, 118, -21, + -21, 149, 149, -21, -21, 118, 176, -17, -18, 85, 197, -8, -13, 54, 208, 7}, + // Coefficients 6 taps + {-21, 35, 228, 35, -21, 0, -13, 9, 215, 63, -27, 9, -6, -10, 202, 93, -32, 9, 1, -23, 180, 124, -34, 8, + 5, -31, 154, 154, -31, 5, 8, -34, 124, 180, -23, 1, 9, -32, 93, 202, -10, -6, 9, -27, 63, 215, 9, -13}, + }, + + // Band_8_1211 + { + // Scaler inc range + {1209, 1211}, + // Coefficients 4 taps + {27, 202, 27, 0, 8, 207, 54, -13, -7, 196, 85, -18, -17, 176, 118, -21, + -21, 149, 149, -21, -21, 118, 176, -17, -18, 85, 196, -7, -13, 54, 207, 8}, + // Coefficients 6 taps + {-21, 35, 228, 35, -21, 0, -13, 10, 214, 63, -27, 9, -6, -10, 201, 94, -32, 9, 0, -23, 180, 125, -34, 8, + 5, -31, 154, 154, -31, 5, 8, -34, 125, 180, -23, 0, 9, -32, 94, 201, -10, -6, 9, -27, 63, 214, 10, -13}, + }, + + // Band_8_1212 + { + // Scaler inc range + {1211, 1212}, + // Coefficients 4 taps + {27, 202, 27, 0, 8, 207, 54, -13, -7, 196, 85, -18, -17, 176, 118, -21, + -21, 149, 149, -21, -21, 118, 176, -17, -18, 85, 196, -7, -13, 54, 207, 8}, + // Coefficients 6 taps + {-21, 36, 226, 36, -21, 0, -13, 10, 214, 63, -27, 9, -6, -10, 201, 94, -32, 9, 0, -23, 180, 125, -34, 8, + 5, -31, 154, 154, -31, 5, 8, -34, 125, 180, -23, 0, 9, -32, 94, 201, -10, -6, 9, -27, 63, 214, 10, -13}, + }, + + // Band_8_1214 + { + // Scaler inc range + {1212, 1214}, + // Coefficients 4 taps + {27, 202, 27, 0, 8, 207, 54, -13, -7, 196, 85, -18, -17, 176, 118, -21, + -21, 149, 149, -21, -21, 118, 176, -17, -18, 85, 196, -7, -13, 54, 207, 8}, + // Coefficients 6 taps + {-21, 36, 226, 36, -21, 0, -13, 10, 214, 63, -27, 9, -6, -9, 200, 94, -32, 9, 0, -23, 179, 125, -33, 8, + 5, -31, 154, 154, -31, 5, 8, -33, 125, 179, -23, 0, 9, -32, 94, 200, -9, -6, 9, -27, 63, 214, 10, -13}, + }, + + // Band_8_1215 + { + // Scaler inc range + {1214, 1215}, + // Coefficients 4 taps + {27, 202, 27, 0, 8, 207, 55, -14, -7, 196, 85, -18, -17, 176, 118, -21, + -21, 149, 149, -21, -21, 118, 176, -17, -18, 85, 196, -7, -14, 55, 207, 8}, + // Coefficients 6 taps + {-22, 36, 228, 36, -22, 0, -13, 10, 215, 63, -28, 9, -6, -9, 200, 94, -32, 9, 0, -23, 179, 125, -33, 8, + 5, -31, 154, 154, -31, 5, 8, -33, 125, 179, -23, 0, 9, -32, 94, 200, -9, -6, 9, -28, 63, 215, 10, -13}, + }, + + // Band_8_1216 + { + // Scaler inc range + {1215, 1216}, + // Coefficients 4 taps + {28, 200, 28, 0, 8, 207, 55, -14, -7, 196, 85, -18, -16, 175, 118, -21, + -21, 149, 149, -21, -21, 118, 175, -16, -18, 85, 196, -7, -14, 55, 207, 8}, + // Coefficients 6 taps + {-22, 36, 228, 36, -22, 0, -13, 10, 214, 64, -28, 9, -6, -9, 200, 94, -32, 9, 0, -23, 180, 125, -33, 7, + 5, -30, 153, 153, -30, 5, 7, -33, 125, 180, -23, 0, 9, -32, 94, 200, -9, -6, 9, -28, 64, 214, 10, -13}, + }, + + // Band_8_1218 + { + // Scaler inc range + {1216, 1218}, + // Coefficients 4 taps + {28, 200, 28, 0, 8, 207, 55, -14, -7, 196, 85, -18, -16, 176, 117, -21, + -21, 149, 149, -21, -21, 117, 176, -16, -18, 85, 196, -7, -14, 55, 207, 8}, + // Coefficients 6 taps + {-22, 37, 226, 37, -22, 0, -14, 11, 214, 64, -28, 9, -6, -9, 200, 94, -32, 9, 0, -22, 179, 125, -33, 7, + 4, -30, 154, 154, -30, 4, 7, -33, 125, 179, -22, 0, 9, -32, 94, 200, -9, -6, 9, -28, 64, 214, 11, -14}, + }, + + // Band_8_1219 + { + // Scaler inc range + {1218, 1219}, + // Coefficients 4 taps + {28, 200, 28, 0, 9, 206, 55, -14, -7, 196, 85, -18, -16, 176, 117, -21, + -21, 149, 149, -21, -21, 117, 176, -16, -18, 85, 196, -7, -14, 55, 206, 9}, + // Coefficients 6 taps + {-22, 37, 226, 37, -22, 0, -14, 11, 214, 64, -28, 9, -6, -9, 200, 94, -32, 9, 0, -22, 179, 125, -33, 7, + 4, -30, 154, 154, -30, 4, 7, -33, 125, 179, -22, 0, 9, -32, 94, 200, -9, -6, 9, -28, 64, 214, 11, -14}, + }, + + // Band_8_1221 + { + // Scaler inc range + {1219, 1221}, + // Coefficients 4 taps + {28, 200, 28, 0, 9, 206, 55, -14, -6, 195, 85, -18, -16, 176, 117, -21, + -21, 149, 149, -21, -21, 117, 176, -16, -18, 85, 195, -6, -14, 55, 206, 9}, + // Coefficients 6 taps + {-22, 37, 226, 37, -22, 0, -14, 11, 215, 64, -28, 8, -7, -8, 200, 94, -32, 9, 0, -22, 179, 125, -33, 7, + 4, -30, 154, 154, -30, 4, 7, -33, 125, 179, -22, 0, 9, -32, 94, 200, -8, -7, 8, -28, 64, 215, 11, -14}, + }, + + // Band_8_1222 + { + // Scaler inc range + {1221, 1222}, + // Coefficients 4 taps + {28, 200, 28, 0, 9, 206, 55, -14, -6, 195, 85, -18, -16, 176, 117, -21, + -20, 148, 148, -20, -21, 117, 176, -16, -18, 85, 195, -6, -14, 55, 206, 9}, + // Coefficients 6 taps + {-22, 37, 226, 37, -22, 0, -14, 11, 215, 64, -28, 8, -7, -8, 200, 94, -32, 9, -1, -22, 180, 125, -33, 7, 4, + -30, 154, 154, -30, 4, 7, -33, 125, 180, -22, -1, 9, -32, 94, 200, -8, -7, 8, -28, 64, 215, 11, -14}, + }, + + // Band_8_1224 + { + // Scaler inc range + {1222, 1224}, + // Coefficients 4 taps + {28, 200, 28, 0, 9, 206, 55, -14, -6, 195, 85, -18, -16, 176, 117, -21, + -20, 148, 148, -20, -21, 117, 176, -16, -18, 85, 195, -6, -14, 55, 206, 9}, + // Coefficients 6 taps + {-22, 37, 226, 37, -22, 0, -14, 12, 214, 64, -28, 8, -7, -8, 200, 95, -32, 8, -1, -22, 180, 125, -33, 7, 4, + -30, 154, 154, -30, 4, 7, -33, 125, 180, -22, -1, 8, -32, 95, 200, -8, -7, 8, -28, 64, 214, 12, -14}, + }, + + // Band_8_1225 + { + // Scaler inc range + {1224, 1225}, + // Coefficients 4 taps + {28, 200, 28, 0, 9, 206, 55, -14, -6, 195, 85, -18, -16, 176, 117, -21, + -20, 148, 148, -20, -21, 117, 176, -16, -18, 85, 195, -6, -14, 55, 206, 9}, + // Coefficients 6 taps + {-22, 38, 224, 38, -22, 0, -14, 12, 213, 65, -28, 8, -7, -8, 200, 95, -32, 8, -1, -21, 179, 125, -33, 7, 4, + -30, 154, 154, -30, 4, 7, -33, 125, 179, -21, -1, 8, -32, 95, 200, -8, -7, 8, -28, 65, 213, 12, -14}, + }, + + // Band_8_1226 + { + // Scaler inc range + {1225, 1226}, + // Coefficients 4 taps + {29, 198, 29, 0, 9, 205, 56, -14, -6, 194, 86, -18, -16, 176, 117, -21, + -20, 148, 148, -20, -21, 117, 176, -16, -18, 86, 194, -6, -14, 56, 205, 9}, + // Coefficients 6 taps + {-22, 38, 224, 38, -22, 0, -14, 12, 213, 65, -28, 8, -7, -7, 199, 95, -32, 8, -1, -21, 179, 125, -33, 7, 4, + -30, 154, 154, -30, 4, 7, -33, 125, 179, -21, -1, 8, -32, 95, 199, -7, -7, 8, -28, 65, 213, 12, -14}, + }, + + // Band_8_1228 + { + // Scaler inc range + {1226, 1228}, + // Coefficients 4 taps + {29, 198, 29, 0, 10, 204, 56, -14, -6, 194, 86, -18, -15, 174, 117, -20, + -20, 148, 148, -20, -20, 117, 174, -15, -18, 86, 194, -6, -14, 56, 204, 10}, + // Coefficients 6 taps + {-22, 38, 224, 38, -22, 0, -14, 12, 213, 65, -28, 8, -7, -7, 199, 95, -32, 8, -1, -21, 179, 125, -33, 7, 4, + -29, 153, 153, -29, 4, 7, -33, 125, 179, -21, -1, 8, -32, 95, 199, -7, -7, 8, -28, 65, 213, 12, -14}, + }, + + // Band_8_1229 + { + // Scaler inc range + {1228, 1229}, + // Coefficients 4 taps + {29, 198, 29, 0, 10, 204, 56, -14, -5, 193, 86, -18, -15, 174, 117, -20, + -20, 148, 148, -20, -20, 117, 174, -15, -18, 86, 193, -5, -14, 56, 204, 10}, + // Coefficients 6 taps + {-22, 38, 224, 38, -22, 0, -14, 12, 213, 65, -28, 8, -7, -7, 199, 95, -32, 8, -1, -21, 179, 125, -33, 7, 4, + -29, 153, 153, -29, 4, 7, -33, 125, 179, -21, -1, 8, -32, 95, 199, -7, -7, 8, -28, 65, 213, 12, -14}, + }, + + // Band_8_1231 + { + // Scaler inc range + {1229, 1231}, + // Coefficients 4 taps + {29, 198, 29, 0, 10, 204, 56, -14, -5, 193, 86, -18, -15, 174, 117, -20, + -20, 148, 148, -20, -20, 117, 174, -15, -18, 86, 193, -5, -14, 56, 204, 10}, + // Coefficients 6 taps + {-23, 38, 226, 38, -23, 0, -15, 13, 213, 65, -28, 8, -7, -7, 199, 95, -32, 8, -1, -21, 179, 125, -33, 7, 4, + -29, 153, 153, -29, 4, 7, -33, 125, 179, -21, -1, 8, -32, 95, 199, -7, -7, 8, -28, 65, 213, 13, -15}, + }, + + // Band_8_1232 + { + // Scaler inc range + {1231, 1232}, + // Coefficients 4 taps + {29, 198, 29, 0, 10, 204, 56, -14, -5, 193, 86, -18, -15, 174, 117, -20, + -20, 148, 148, -20, -20, 117, 174, -15, -18, 86, 193, -5, -14, 56, 204, 10}, + // Coefficients 6 taps + {-23, 39, 224, 39, -23, 0, -15, 13, 213, 65, -28, 8, -8, -7, 200, 95, -32, 8, -1, -21, 179, 125, -33, 7, 3, + -29, 154, 154, -29, 3, 7, -33, 125, 179, -21, -1, 8, -32, 95, 200, -7, -8, 8, -28, 65, 213, 13, -15}, + }, + + // Band_8_1234 + { + // Scaler inc range + {1232, 1234}, + // Coefficients 4 taps + {29, 198, 29, 0, 10, 204, 56, -14, -5, 193, 86, -18, -15, 174, 117, -20, + -20, 148, 148, -20, -20, 117, 174, -15, -18, 86, 193, -5, -14, 56, 204, 10}, + // Coefficients 6 taps + {-23, 39, 224, 39, -23, 0, -15, 13, 212, 66, -28, 8, -8, -6, 199, 95, -32, 8, -1, -20, 178, 125, -33, 7, 3, + -29, 154, 154, -29, 3, 7, -33, 125, 178, -20, -1, 8, -32, 95, 199, -6, -8, 8, -28, 66, 212, 13, -15}, + }, + + // Band_8_1235 + { + // Scaler inc range + {1234, 1235}, + // Coefficients 4 taps + {29, 198, 29, 0, 10, 204, 56, -14, -5, 193, 86, -18, -15, 174, 117, -20, + -20, 148, 148, -20, -20, 117, 174, -15, -18, 86, 193, -5, -14, 56, 204, 10}, + // Coefficients 6 taps + {-23, 39, 224, 39, -23, 0, -15, 13, 212, 66, -28, 8, -8, -6, 199, 95, -32, 8, -2, -20, 179, 125, -32, 6, 3, + -29, 154, 154, -29, 3, 6, -32, 125, 179, -20, -2, 8, -32, 95, 199, -6, -8, 8, -28, 66, 212, 13, -15}, + }, + + // Band_8_1237 + { + // Scaler inc range + {1235, 1237}, + // Coefficients 4 taps + {30, 196, 30, 0, 11, 203, 56, -14, -5, 193, 86, -18, -15, 174, 117, -20, + -19, 147, 147, -19, -20, 117, 174, -15, -18, 86, 193, -5, -14, 56, 203, 11}, + // Coefficients 6 taps + {-23, 39, 224, 39, -23, 0, -15, 14, 211, 66, -28, 8, -8, -6, 198, 96, -32, 8, -2, -20, 179, 125, -32, 6, 3, + -29, 154, 154, -29, 3, 6, -32, 125, 179, -20, -2, 8, -32, 96, 198, -6, -8, 8, -28, 66, 211, 14, -15}, + }, + + // Band_8_1238 + { + // Scaler inc range + {1237, 1238}, + // Coefficients 4 taps + {30, 196, 30, 0, 11, 203, 56, -14, -4, 192, 86, -18, -14, 173, 117, -20, + -19, 147, 147, -19, -20, 117, 173, -14, -18, 86, 192, -4, -14, 56, 203, 11}, + // Coefficients 6 taps + {-23, 39, 224, 39, -23, 0, -15, 14, 211, 66, -28, 8, -8, -6, 198, 96, -32, 8, -2, -20, 179, 125, -32, 6, 3, + -29, 154, 154, -29, 3, 6, -32, 125, 179, -20, -2, 8, -32, 96, 198, -6, -8, 8, -28, 66, 211, 14, -15}, + }, + + // Band_8_1239 + { + // Scaler inc range + {1238, 1239}, + // Coefficients 4 taps + {30, 196, 30, 0, 11, 202, 57, -14, -4, 192, 86, -18, -14, 173, 117, -20, + -19, 147, 147, -19, -20, 117, 173, -14, -18, 86, 192, -4, -14, 57, 202, 11}, + // Coefficients 6 taps + {-23, 40, 222, 40, -23, 0, -15, 14, 211, 66, -28, 8, -8, -6, 198, 96, -32, 8, -2, -20, 179, 125, -32, 6, 3, + -28, 153, 153, -28, 3, 6, -32, 125, 179, -20, -2, 8, -32, 96, 198, -6, -8, 8, -28, 66, 211, 14, -15}, + }, + + // Band_8_1241 + { + // Scaler inc range + {1239, 1241}, + // Coefficients 4 taps + {30, 196, 30, 0, 11, 202, 57, -14, -4, 192, 86, -18, -14, 173, 117, -20, + -19, 147, 147, -19, -20, 117, 173, -14, -18, 86, 192, -4, -14, 57, 202, 11}, + // Coefficients 6 taps + {-23, 40, 222, 40, -23, 0, -15, 14, 211, 66, -28, 8, -8, -5, 197, 96, -32, 8, -2, -20, 178, 126, -32, 6, 3, + -28, 153, 153, -28, 3, 6, -32, 126, 178, -20, -2, 8, -32, 96, 197, -5, -8, 8, -28, 66, 211, 14, -15}, + }, + + // Band_8_1242 + { + // Scaler inc range + {1241, 1242}, + // Coefficients 4 taps + {30, 196, 30, 0, 11, 202, 57, -14, -4, 192, 86, -18, -14, 173, 117, -20, + -19, 147, 147, -19, -20, 117, 173, -14, -18, 86, 192, -4, -14, 57, 202, 11}, + // Coefficients 6 taps + {-23, 40, 222, 40, -23, 0, -15, 14, 210, 67, -28, 8, -8, -5, 197, 96, -32, 8, -2, -19, 177, 126, -32, 6, 3, + -28, 153, 153, -28, 3, 6, -32, 126, 177, -19, -2, 8, -32, 96, 197, -5, -8, 8, -28, 67, 210, 14, -15}, + }, + + // Band_8_1244 + { + // Scaler inc range + {1242, 1244}, + // Coefficients 4 taps + {30, 196, 30, 0, 11, 202, 57, -14, -4, 192, 86, -18, -14, 173, 117, -20, + -19, 147, 147, -19, -20, 117, 173, -14, -18, 86, 192, -4, -14, 57, 202, 11}, + // Coefficients 6 taps + {-23, 40, 222, 40, -23, 0, -16, 15, 210, 67, -28, 8, -9, -5, 198, 96, -32, 8, -2, -19, 177, 126, -32, 6, 3, + -28, 153, 153, -28, 3, 6, -32, 126, 177, -19, -2, 8, -32, 96, 198, -5, -9, 8, -28, 67, 210, 15, -16}, + }, + + // Band_8_1245 + { + // Scaler inc range + {1244, 1245}, + // Coefficients 4 taps + {30, 196, 30, 0, 12, 201, 57, -14, -4, 192, 86, -18, -14, 173, 117, -20, + -19, 147, 147, -19, -20, 117, 173, -14, -18, 86, 192, -4, -14, 57, 201, 12}, + // Coefficients 6 taps + {-23, 40, 222, 40, -23, 0, -16, 15, 210, 67, -28, 8, -9, -5, 198, 96, -32, 8, -2, -19, 177, 126, -32, 6, 2, + -28, 154, 154, -28, 2, 6, -32, 126, 177, -19, -2, 8, -32, 96, 198, -5, -9, 8, -28, 67, 210, 15, -16}, + }, + + // Band_8_1247 + { + // Scaler inc range + {1245, 1247}, + // Coefficients 4 taps + {31, 194, 31, 0, 12, 201, 57, -14, -3, 191, 86, -18, -14, 173, 117, -20, + -19, 147, 147, -19, -20, 117, 173, -14, -18, 86, 191, -3, -14, 57, 201, 12}, + // Coefficients 6 taps + {-23, 41, 220, 41, -23, 0, -16, 15, 210, 67, -28, 8, -9, -5, 198, 96, -32, 8, -3, -19, 178, 126, -32, 6, 2, + -28, 154, 154, -28, 2, 6, -32, 126, 178, -19, -3, 8, -32, 96, 198, -5, -9, 8, -28, 67, 210, 15, -16}, + }, + + // Band_8_1248 + { + // Scaler inc range + {1247, 1248}, + // Coefficients 4 taps + {31, 194, 31, 0, 12, 201, 57, -14, -3, 191, 86, -18, -13, 172, 117, -20, + -19, 147, 147, -19, -20, 117, 172, -13, -18, 86, 191, -3, -14, 57, 201, 12}, + // Coefficients 6 taps + {-23, 41, 220, 41, -23, 0, -16, 15, 210, 67, -28, 8, -9, -4, 197, 96, -32, 8, -3, -19, 178, 126, -32, 6, 2, + -28, 154, 154, -28, 2, 6, -32, 126, 178, -19, -3, 8, -32, 96, 197, -4, -9, 8, -28, 67, 210, 15, -16}, + }, + + // Band_8_1250 + { + // Scaler inc range + {1248, 1250}, + // Coefficients 4 taps + {31, 194, 31, 0, 12, 201, 57, -14, -3, 191, 86, -18, -13, 172, 117, -20, + -19, 147, 147, -19, -20, 117, 172, -13, -18, 86, 191, -3, -14, 57, 201, 12}, + // Coefficients 6 taps + {-23, 41, 220, 41, -23, 0, -16, 15, 210, 67, -28, 8, -9, -4, 197, 97, -32, 7, -3, -18, 177, 126, -32, 6, 2, + -27, 153, 153, -27, 2, 6, -32, 126, 177, -18, -3, 7, -32, 97, 197, -4, -9, 8, -28, 67, 210, 15, -16}, + }, + + // Band_8_1251 + { + // Scaler inc range + {1250, 1251}, + // Coefficients 4 taps + {31, 194, 31, 0, 12, 201, 57, -14, -3, 190, 87, -18, -13, 172, 117, -20, + -18, 146, 146, -18, -20, 117, 172, -13, -18, 87, 190, -3, -14, 57, 201, 12}, + // Coefficients 6 taps + {-24, 41, 222, 41, -24, 0, -16, 16, 209, 67, -28, 8, -9, -4, 197, 97, -32, 7, -3, -18, 178, 126, -32, 5, 2, + -27, 153, 153, -27, 2, 5, -32, 126, 178, -18, -3, 7, -32, 97, 197, -4, -9, 8, -28, 67, 209, 16, -16}, + }, + + // Band_8_1253 + { + // Scaler inc range + {1251, 1253}, + // Coefficients 4 taps + {31, 194, 31, 0, 12, 200, 58, -14, -3, 190, 87, -18, -13, 171, 117, -19, + -18, 146, 146, -18, -19, 117, 171, -13, -18, 87, 190, -3, -14, 58, 200, 12}, + // Coefficients 6 taps + {-24, 41, 222, 41, -24, 0, -16, 16, 208, 68, -28, 8, -9, -4, 197, 97, -32, 7, -3, -18, 177, 126, -31, 5, 2, + -27, 153, 153, -27, 2, 5, -31, 126, 177, -18, -3, 7, -32, 97, 197, -4, -9, 8, -28, 68, 208, 16, -16}, + }, + + // Band_8_1254 + { + // Scaler inc range + {1253, 1254}, + // Coefficients 4 taps + {31, 194, 31, 0, 13, 199, 58, -14, -3, 189, 87, -17, -13, 171, 117, -19, + -18, 146, 146, -18, -19, 117, 171, -13, -17, 87, 189, -3, -14, 58, 199, 13}, + // Coefficients 6 taps + {-24, 42, 220, 42, -24, 0, -16, 16, 208, 68, -28, 8, -9, -4, 197, 97, -32, 7, -3, -18, 177, 126, -31, 5, 2, + -27, 153, 153, -27, 2, 5, -31, 126, 177, -18, -3, 7, -32, 97, 197, -4, -9, 8, -28, 68, 208, 16, -16}, + }, + + // Band_8_1256 + { + // Scaler inc range + {1254, 1256}, + // Coefficients 4 taps + {31, 194, 31, 0, 13, 199, 58, -14, -3, 189, 87, -17, -13, 171, 117, -19, + -18, 146, 146, -18, -19, 117, 171, -13, -17, 87, 189, -3, -14, 58, 199, 13}, + // Coefficients 6 taps + {-24, 42, 220, 42, -24, 0, -16, 16, 208, 68, -28, 8, -9, -3, 196, 97, -32, 7, -3, -18, 177, 126, -31, 5, 2, + -27, 153, 153, -27, 2, 5, -31, 126, 177, -18, -3, 7, -32, 97, 196, -3, -9, 8, -28, 68, 208, 16, -16}, + }, + + // Band_8_1257 + { + // Scaler inc range + {1256, 1257}, + // Coefficients 4 taps + {32, 192, 32, 0, 13, 199, 58, -14, -2, 188, 87, -17, -13, 171, 117, -19, + -18, 146, 146, -18, -19, 117, 171, -13, -17, 87, 188, -2, -14, 58, 199, 13}, + // Coefficients 6 taps + {-24, 42, 220, 42, -24, 0, -16, 17, 207, 68, -28, 8, -10, -3, 196, 97, -31, 7, -3, -18, 177, 126, -31, 5, 2, + -27, 153, 153, -27, 2, 5, -31, 126, 177, -18, -3, 7, -31, 97, 196, -3, -10, 8, -28, 68, 207, 17, -16}, + }, + + // Band_8_1259 + { + // Scaler inc range + {1257, 1259}, + // Coefficients 4 taps + {32, 192, 32, 0, 13, 199, 58, -14, -2, 188, 87, -17, -13, 171, 117, -19, + -18, 146, 146, -18, -19, 117, 171, -13, -17, 87, 188, -2, -14, 58, 199, 13}, + // Coefficients 6 taps + {-24, 42, 220, 42, -24, 0, -17, 17, 208, 68, -28, 8, -10, -3, 196, 97, -31, 7, -3, -17, 176, 126, -31, 5, 2, + -27, 153, 153, -27, 2, 5, -31, 126, 176, -17, -3, 7, -31, 97, 196, -3, -10, 8, -28, 68, 208, 17, -17}, + }, + + // Band_8_1260 + { + // Scaler inc range + {1259, 1260}, + // Coefficients 4 taps + {32, 192, 32, 0, 13, 199, 58, -14, -2, 188, 87, -17, -12, 170, 117, -19, + -18, 146, 146, -18, -19, 117, 170, -12, -17, 87, 188, -2, -14, 58, 199, 13}, + // Coefficients 6 taps + {-24, 42, 220, 42, -24, 0, -17, 17, 208, 68, -28, 8, -10, -3, 196, 97, -31, 7, -4, -17, 177, 126, -31, 5, 1, + -27, 154, 154, -27, 1, 5, -31, 126, 177, -17, -4, 7, -31, 97, 196, -3, -10, 8, -28, 68, 208, 17, -17}, + }, + + // Band_8_1262 + { + // Scaler inc range + {1260, 1262}, + // Coefficients 4 taps + {32, 192, 32, 0, 13, 199, 58, -14, -2, 188, 87, -17, -12, 170, 117, -19, + -18, 146, 146, -18, -19, 117, 170, -12, -17, 87, 188, -2, -14, 58, 199, 13}, + // Coefficients 6 taps + {-24, 43, 218, 43, -24, 0, -17, 17, 207, 69, -28, 8, -10, -2, 195, 97, -31, 7, -4, -17, 177, 126, -31, 5, 1, + -26, 153, 153, -26, 1, 5, -31, 126, 177, -17, -4, 7, -31, 97, 195, -2, -10, 8, -28, 69, 207, 17, -17}, + }, + + // Band_8_1263 + { + // Scaler inc range + {1262, 1263}, + // Coefficients 4 taps + {32, 192, 32, 0, 14, 198, 58, -14, -2, 188, 87, -17, -12, 170, 117, -19, + -18, 146, 146, -18, -19, 117, 170, -12, -17, 87, 188, -2, -14, 58, 198, 14}, + // Coefficients 6 taps + {-24, 43, 218, 43, -24, 0, -17, 17, 208, 69, -29, 8, -10, -2, 195, 97, -31, 7, -4, -17, 177, 126, -31, 5, 1, + -26, 153, 153, -26, 1, 5, -31, 126, 177, -17, -4, 7, -31, 97, 195, -2, -10, 8, -29, 69, 208, 17, -17}, + }, + + // Band_8_1265 + { + // Scaler inc range + {1263, 1265}, + // Coefficients 4 taps + {32, 192, 32, 0, 14, 198, 58, -14, -2, 188, 87, -17, -12, 170, 117, -19, + -18, 146, 146, -18, -19, 117, 170, -12, -17, 87, 188, -2, -14, 58, 198, 14}, + // Coefficients 6 taps + {-24, 43, 218, 43, -24, 0, -17, 18, 207, 69, -29, 8, -10, -2, 195, 97, -31, 7, -4, -17, 177, 126, -31, 5, 1, + -26, 153, 153, -26, 1, 5, -31, 126, 177, -17, -4, 7, -31, 97, 195, -2, -10, 8, -29, 69, 207, 18, -17}, + }, + + // Band_8_1266 + { + // Scaler inc range + {1265, 1266}, + // Coefficients 4 taps + {32, 192, 32, 0, 14, 197, 59, -14, -1, 187, 87, -17, -12, 170, 117, -19, + -17, 145, 145, -17, -19, 117, 170, -12, -17, 87, 187, -1, -14, 59, 197, 14}, + // Coefficients 6 taps + {-24, 43, 218, 43, -24, 0, -17, 18, 207, 69, -29, 8, -10, -2, 194, 98, -31, 7, -4, -16, 176, 126, -31, 5, 1, + -26, 153, 153, -26, 1, 5, -31, 126, 176, -16, -4, 7, -31, 98, 194, -2, -10, 8, -29, 69, 207, 18, -17}, + }, + + // Band_8_1268 + { + // Scaler inc range + {1266, 1268}, + // Coefficients 4 taps + {33, 190, 33, 0, 14, 197, 59, -14, -1, 187, 87, -17, -12, 170, 117, -19, + -17, 145, 145, -17, -19, 117, 170, -12, -17, 87, 187, -1, -14, 59, 197, 14}, + // Coefficients 6 taps + {-24, 43, 218, 43, -24, 0, -17, 18, 207, 69, -29, 8, -10, -2, 194, 98, -31, 7, -4, -16, 176, 126, -31, 5, 1, + -26, 153, 153, -26, 1, 5, -31, 126, 176, -16, -4, 7, -31, 98, 194, -2, -10, 8, -29, 69, 207, 18, -17}, + }, + + // Band_8_1269 + { + // Scaler inc range + {1268, 1269}, + // Coefficients 4 taps + {33, 190, 33, 0, 14, 197, 59, -14, -1, 187, 87, -17, -12, 170, 117, -19, + -17, 145, 145, -17, -19, 117, 170, -12, -17, 87, 187, -1, -14, 59, 197, 14}, + // Coefficients 6 taps + {-24, 44, 216, 44, -24, 0, -17, 18, 208, 69, -29, 7, -10, -1, 193, 98, -31, 7, -4, -16, 176, 126, -30, 4, 1, + -26, 153, 153, -26, 1, 4, -30, 126, 176, -16, -4, 7, -31, 98, 193, -1, -10, 7, -29, 69, 208, 18, -17}, + }, + + // Band_8_1271 + { + // Scaler inc range + {1269, 1271}, + // Coefficients 4 taps + {33, 190, 33, 0, 14, 197, 59, -14, -1, 187, 87, -17, -11, 169, 117, -19, + -17, 145, 145, -17, -19, 117, 169, -11, -17, 87, 187, -1, -14, 59, 197, 14}, + // Coefficients 6 taps + {-24, 44, 216, 44, -24, 0, -17, 18, 208, 69, -29, 7, -11, -1, 194, 98, -31, 7, -4, -16, 176, 126, -30, 4, 1, + -25, 152, 152, -25, 1, 4, -30, 126, 176, -16, -4, 7, -31, 98, 194, -1, -11, 7, -29, 69, 208, 18, -17}, + }, + + // Band_8_1273 + { + // Scaler inc range + {1271, 1273}, + // Coefficients 4 taps + {33, 190, 33, 0, 15, 196, 59, -14, -1, 187, 87, -17, -11, 169, 117, -19, + -17, 145, 145, -17, -19, 117, 169, -11, -17, 87, 187, -1, -14, 59, 196, 15}, + // Coefficients 6 taps + {-24, 44, 216, 44, -24, 0, -17, 19, 206, 70, -29, 7, -11, -1, 195, 98, -31, 6, -5, -16, 177, 126, -30, 4, 1, + -25, 152, 152, -25, 1, 4, -30, 126, 177, -16, -5, 6, -31, 98, 195, -1, -11, 7, -29, 70, 206, 19, -17}, + }, + + // Band_8_1274 + { + // Scaler inc range + {1273, 1274}, + // Coefficients 4 taps + {33, 190, 33, 0, 15, 196, 59, -14, -1, 187, 87, -17, -11, 169, 117, -19, + -17, 145, 145, -17, -19, 117, 169, -11, -17, 87, 187, -1, -14, 59, 196, 15}, + // Coefficients 6 taps + {-24, 44, 216, 44, -24, 0, -17, 19, 206, 70, -29, 7, -11, -1, 195, 98, -31, 6, -5, -16, 177, 126, -30, 4, 0, + -25, 153, 153, -25, 0, 4, -30, 126, 177, -16, -5, 6, -31, 98, 195, -1, -11, 7, -29, 70, 206, 19, -17}, + }, + + // Band_8_1276 + { + // Scaler inc range + {1274, 1276}, + // Coefficients 4 taps + {33, 190, 33, 0, 15, 196, 59, -14, 0, 186, 87, -17, -11, 168, 117, -18, + -17, 145, 145, -17, -18, 117, 168, -11, -17, 87, 186, 0, -14, 59, 196, 15}, + // Coefficients 6 taps + {-24, 44, 216, 44, -24, 0, -18, 19, 207, 70, -29, 7, -11, -1, 195, 98, -31, 6, -5, -15, 176, 126, -30, 4, 0, + -25, 153, 153, -25, 0, 4, -30, 126, 176, -15, -5, 6, -31, 98, 195, -1, -11, 7, -29, 70, 207, 19, -18}, + }, + + // Band_8_1277 + { + // Scaler inc range + {1276, 1277}, + // Coefficients 4 taps + {33, 190, 33, 0, 15, 196, 59, -14, 0, 186, 87, -17, -11, 168, 117, -18, + -17, 145, 145, -17, -18, 117, 168, -11, -17, 87, 186, 0, -14, 59, 196, 15}, + // Coefficients 6 taps + {-25, 44, 218, 44, -25, 0, -18, 19, 207, 70, -29, 7, -11, 0, 194, 98, -31, 6, -5, -15, 176, 126, -30, 4, 0, + -25, 153, 153, -25, 0, 4, -30, 126, 176, -15, -5, 6, -31, 98, 194, 0, -11, 7, -29, 70, 207, 19, -18}, + }, + + // Band_8_1279 + { + // Scaler inc range + {1277, 1279}, + // Coefficients 4 taps + {33, 190, 33, 0, 15, 196, 59, -14, 0, 186, 87, -17, -11, 168, 117, -18, + -17, 145, 145, -17, -18, 117, 168, -11, -17, 87, 186, 0, -14, 59, 196, 15}, + // Coefficients 6 taps + {-25, 45, 216, 45, -25, 0, -18, 19, 207, 70, -29, 7, -11, 0, 194, 98, -31, 6, -5, -15, 176, 126, -30, 4, 0, + -25, 153, 153, -25, 0, 4, -30, 126, 176, -15, -5, 6, -31, 98, 194, 0, -11, 7, -29, 70, 207, 19, -18}, + }, + + // Band_8_1280 + { + // Scaler inc range + {1279, 1280}, + // Coefficients 4 taps + {34, 188, 34, 0, 15, 195, 60, -14, 0, 186, 87, -17, -11, 168, 117, -18, + -16, 144, 144, -16, -18, 117, 168, -11, -17, 87, 186, 0, -14, 60, 195, 15}, + // Coefficients 6 taps + {-25, 45, 216, 45, -25, 0, -18, 20, 206, 70, -29, 7, -11, 0, 194, 98, -31, 6, -5, -15, 176, 126, -30, 4, 0, + -25, 153, 153, -25, 0, 4, -30, 126, 176, -15, -5, 6, -31, 98, 194, 0, -11, 7, -29, 70, 206, 20, -18}, + }, + + // Band_8_1282 + { + // Scaler inc range + {1280, 1282}, + // Coefficients 4 taps + {34, 188, 34, 0, 16, 194, 60, -14, 0, 185, 88, -17, -10, 167, 117, -18, + -16, 144, 144, -16, -18, 117, 167, -10, -17, 88, 185, 0, -14, 60, 194, 16}, + // Coefficients 6 taps + {-25, 45, 216, 45, -25, 0, -18, 20, 206, 70, -29, 7, -11, 0, 193, 99, -31, 6, -5, -15, 176, 126, -30, 4, 0, + -24, 152, 152, -24, 0, 4, -30, 126, 176, -15, -5, 6, -31, 99, 193, 0, -11, 7, -29, 70, 206, 20, -18}, + }, + + // Band_8_1283 + { + // Scaler inc range + {1282, 1283}, + // Coefficients 4 taps + {34, 188, 34, 0, 16, 194, 60, -14, 0, 185, 88, -17, -10, 167, 117, -18, + -16, 144, 144, -16, -18, 117, 167, -10, -17, 88, 185, 0, -14, 60, 194, 16}, + // Coefficients 6 taps + {-25, 45, 216, 45, -25, 0, -18, 20, 205, 71, -29, 7, -11, 0, 193, 99, -31, 6, -5, -14, 175, 126, -30, 4, 0, + -24, 152, 152, -24, 0, 4, -30, 126, 175, -14, -5, 6, -31, 99, 193, 0, -11, 7, -29, 71, 205, 20, -18}, + }, + + // Band_8_1285 + { + // Scaler inc range + {1283, 1285}, + // Coefficients 4 taps + {34, 188, 34, 0, 16, 194, 60, -14, 1, 184, 88, -17, -10, 167, 117, -18, + -16, 144, 144, -16, -18, 117, 167, -10, -17, 88, 184, 1, -14, 60, 194, 16}, + // Coefficients 6 taps + {-25, 45, 216, 45, -25, 0, -18, 20, 205, 71, -29, 7, -12, 1, 193, 99, -31, 6, -5, -14, 175, 126, -29, 3, 0, + -24, 152, 152, -24, 0, 3, -29, 126, 175, -14, -5, 6, -31, 99, 193, 1, -12, 7, -29, 71, 205, 20, -18}, + }, + + // Band_8_1287 + { + // Scaler inc range + {1285, 1287}, + // Coefficients 4 taps + {34, 188, 34, 0, 16, 194, 60, -14, 1, 184, 88, -17, -10, 167, 117, -18, + -16, 144, 144, -16, -18, 117, 167, -10, -17, 88, 184, 1, -14, 60, 194, 16}, + // Coefficients 6 taps + {-25, 46, 214, 46, -25, 0, -18, 21, 204, 71, -29, 7, -12, 1, 193, 99, -31, 6, -6, -14, 175, 127, -29, 3, 0, + -24, 152, 152, -24, 0, 3, -29, 127, 175, -14, -6, 6, -31, 99, 193, 1, -12, 7, -29, 71, 204, 21, -18}, + }, + + // Band_8_1288 + { + // Scaler inc range + {1287, 1288}, + // Coefficients 4 taps + {34, 188, 34, 0, 16, 194, 60, -14, 1, 184, 88, -17, -10, 167, 117, -18, + -16, 144, 144, -16, -18, 117, 167, -10, -17, 88, 184, 1, -14, 60, 194, 16}, + // Coefficients 6 taps + {-25, 46, 214, 46, -25, 0, -18, 21, 204, 71, -29, 7, -12, 1, 193, 99, -31, 6, -6, -14, 175, 127, -29, 3, -1, + -24, 153, 153, -24, -1, 3, -29, 127, 175, -14, -6, 6, -31, 99, 193, 1, -12, 7, -29, 71, 204, 21, -18}, + }, + + // Band_8_1290 + { + // Scaler inc range + {1288, 1290}, + // Coefficients 4 taps + {34, 188, 34, 0, 16, 194, 60, -14, 1, 184, 88, -17, -10, 168, 116, -18, + -16, 144, 144, -16, -18, 116, 168, -10, -17, 88, 184, 1, -14, 60, 194, 16}, + // Coefficients 6 taps + {-25, 46, 214, 46, -25, 0, -18, 21, 204, 71, -29, 7, -12, 1, 193, 99, -31, 6, -6, -14, 175, 127, -29, 3, -1, + -24, 153, 153, -24, -1, 3, -29, 127, 175, -14, -6, 6, -31, 99, 193, 1, -12, 7, -29, 71, 204, 21, -18}, + }, + + // Band_8_1291 + { + // Scaler inc range + {1290, 1291}, + // Coefficients 4 taps + {35, 186, 35, 0, 16, 194, 60, -14, 1, 184, 88, -17, -10, 168, 116, -18, + -16, 144, 144, -16, -18, 116, 168, -10, -17, 88, 184, 1, -14, 60, 194, 16}, + // Coefficients 6 taps + {-25, 46, 214, 46, -25, 0, -18, 21, 204, 71, -29, 7, -12, 2, 191, 99, -30, 6, -6, -13, 174, 127, -29, 3, -1, + -24, 153, 153, -24, -1, 3, -29, 127, 174, -13, -6, 6, -30, 99, 191, 2, -12, 7, -29, 71, 204, 21, -18}, + }, + + // Band_8_1293 + { + // Scaler inc range + {1291, 1293}, + // Coefficients 4 taps + {35, 186, 35, 0, 17, 193, 60, -14, 1, 184, 88, -17, -9, 167, 116, -18, + -16, 144, 144, -16, -18, 116, 167, -9, -17, 88, 184, 1, -14, 60, 193, 17}, + // Coefficients 6 taps + {-25, 46, 214, 46, -25, 0, -18, 21, 204, 71, -29, 7, -12, 2, 191, 99, -30, 6, -6, -13, 174, 127, -29, 3, -1, + -23, 152, 152, -23, -1, 3, -29, 127, 174, -13, -6, 6, -30, 99, 191, 2, -12, 7, -29, 71, 204, 21, -18}, + }, + + // Band_8_1295 + { + // Scaler inc range + {1293, 1295}, + // Coefficients 4 taps + {35, 186, 35, 0, 17, 193, 60, -14, 1, 184, 88, -17, -9, 167, 116, -18, + -15, 143, 143, -15, -18, 116, 167, -9, -17, 88, 184, 1, -14, 60, 193, 17}, + // Coefficients 6 taps + {-25, 46, 214, 46, -25, 0, -19, 22, 203, 72, -29, 7, -12, 2, 192, 99, -30, 5, -6, -13, 174, 127, -29, 3, -1, + -23, 152, 152, -23, -1, 3, -29, 127, 174, -13, -6, 5, -30, 99, 192, 2, -12, 7, -29, 72, 203, 22, -19}, + }, + + // Band_8_1296 + { + // Scaler inc range + {1295, 1296}, + // Coefficients 4 taps + {35, 186, 35, 0, 17, 192, 61, -14, 2, 183, 88, -17, -9, 167, 116, -18, + -15, 143, 143, -15, -18, 116, 167, -9, -17, 88, 183, 2, -14, 61, 192, 17}, + // Coefficients 6 taps + {-25, 47, 212, 47, -25, 0, -19, 22, 203, 72, -29, 7, -12, 2, 192, 99, -30, 5, -6, -13, 174, 127, -29, 3, -1, + -23, 152, 152, -23, -1, 3, -29, 127, 174, -13, -6, 5, -30, 99, 192, 2, -12, 7, -29, 72, 203, 22, -19}, + }, + + // Band_8_1298 + { + // Scaler inc range + {1296, 1298}, + // Coefficients 4 taps + {35, 186, 35, 0, 17, 192, 61, -14, 2, 183, 88, -17, -9, 166, 116, -17, + -15, 143, 143, -15, -17, 116, 166, -9, -17, 88, 183, 2, -14, 61, 192, 17}, + // Coefficients 6 taps + {-25, 47, 212, 47, -25, 0, -19, 22, 203, 72, -29, 7, -12, 2, 192, 99, -30, 5, -6, -13, 174, 127, -29, 3, -1, + -23, 152, 152, -23, -1, 3, -29, 127, 174, -13, -6, 5, -30, 99, 192, 2, -12, 7, -29, 72, 203, 22, -19}, + }, + + // Band_8_1299 + { + // Scaler inc range + {1298, 1299}, + // Coefficients 4 taps + {35, 186, 35, 0, 17, 192, 61, -14, 2, 183, 88, -17, -9, 166, 116, -17, + -15, 143, 143, -15, -17, 116, 166, -9, -17, 88, 183, 2, -14, 61, 192, 17}, + // Coefficients 6 taps + {-25, 47, 212, 47, -25, 0, -19, 22, 203, 72, -29, 7, -13, 3, 192, 99, -30, 5, -7, -12, 173, 127, -28, 3, -1, + -23, 152, 152, -23, -1, 3, -28, 127, 173, -12, -7, 5, -30, 99, 192, 3, -13, 7, -29, 72, 203, 22, -19}, + }, + + // Band_8_1301 + { + // Scaler inc range + {1299, 1301}, + // Coefficients 4 taps + {35, 186, 35, 0, 17, 192, 61, -14, 2, 183, 88, -17, -9, 166, 116, -17, + -15, 143, 143, -15, -17, 116, 166, -9, -17, 88, 183, 2, -14, 61, 192, 17}, + // Coefficients 6 taps + {-25, 47, 212, 47, -25, 0, -19, 22, 203, 72, -29, 7, -13, 3, 191, 100, + -30, 5, -7, -12, 173, 127, -28, 3, -1, -23, 152, 152, -23, -1, 3, -28, + 127, 173, -12, -7, 5, -30, 100, 191, 3, -13, 7, -29, 72, 203, 22, -19}, + }, + + // Band_8_1303 + { + // Scaler inc range + {1301, 1303}, + // Coefficients 4 taps + {35, 186, 35, 0, 18, 191, 61, -14, 2, 182, 88, -16, -9, 166, 116, -17, + -15, 143, 143, -15, -17, 116, 166, -9, -16, 88, 182, 2, -14, 61, 191, 18}, + // Coefficients 6 taps + {-25, 47, 212, 47, -25, 0, -19, 23, 203, 72, -29, 6, -13, 3, 191, 100, + -30, 5, -7, -12, 174, 127, -28, 2, -2, -22, 152, 152, -22, -2, 2, -28, + 127, 174, -12, -7, 5, -30, 100, 191, 3, -13, 6, -29, 72, 203, 23, -19}, + }, + + // Band_8_1304 + { + // Scaler inc range + {1303, 1304}, + // Coefficients 4 taps + {36, 184, 36, 0, 18, 191, 61, -14, 2, 182, 88, -16, -8, 165, 116, -17, + -15, 143, 143, -15, -17, 116, 165, -8, -16, 88, 182, 2, -14, 61, 191, 18}, + // Coefficients 6 taps + {-25, 48, 210, 48, -25, 0, -19, 23, 203, 72, -29, 6, -13, 3, 191, 100, + -30, 5, -7, -12, 174, 127, -28, 2, -2, -22, 152, 152, -22, -2, 2, -28, + 127, 174, -12, -7, 5, -30, 100, 191, 3, -13, 6, -29, 72, 203, 23, -19}, + }, + + // Band_8_1306 + { + // Scaler inc range + {1304, 1306}, + // Coefficients 4 taps + {36, 184, 36, 0, 18, 191, 61, -14, 3, 181, 88, -16, -8, 165, 116, -17, + -15, 143, 143, -15, -17, 116, 165, -8, -16, 88, 181, 3, -14, 61, 191, 18}, + // Coefficients 6 taps + {-25, 48, 210, 48, -25, 0, -19, 23, 202, 73, -29, 6, -13, 3, 191, 100, + -30, 5, -7, -12, 174, 127, -28, 2, -2, -22, 152, 152, -22, -2, 2, -28, + 127, 174, -12, -7, 5, -30, 100, 191, 3, -13, 6, -29, 73, 202, 23, -19}, + }, + + // Band_8_1307 + { + // Scaler inc range + {1306, 1307}, + // Coefficients 4 taps + {36, 184, 36, 0, 18, 191, 61, -14, 3, 181, 88, -16, -8, 165, 116, -17, + -15, 143, 143, -15, -17, 116, 165, -8, -16, 88, 181, 3, -14, 61, 191, 18}, + // Coefficients 6 taps + {-25, 48, 210, 48, -25, 0, -19, 23, 202, 73, -29, 6, -13, 4, 190, 100, + -30, 5, -7, -11, 173, 127, -28, 2, -2, -22, 152, 152, -22, -2, 2, -28, + 127, 173, -11, -7, 5, -30, 100, 190, 4, -13, 6, -29, 73, 202, 23, -19}, + }, + + // Band_8_1309 + { + // Scaler inc range + {1307, 1309}, + // Coefficients 4 taps + {36, 184, 36, 0, 18, 191, 61, -14, 3, 181, 88, -16, -8, 165, 116, -17, + -14, 142, 142, -14, -17, 116, 165, -8, -16, 88, 181, 3, -14, 61, 191, 18}, + // Coefficients 6 taps + {-25, 48, 210, 48, -25, 0, -19, 23, 201, 73, -28, 6, -13, 4, 190, 100, + -30, 5, -7, -11, 173, 127, -28, 2, -2, -22, 152, 152, -22, -2, 2, -28, + 127, 173, -11, -7, 5, -30, 100, 190, 4, -13, 6, -28, 73, 201, 23, -19}, + }, + + // Band_8_1311 + { + // Scaler inc range + {1309, 1311}, + // Coefficients 4 taps + {36, 184, 36, 0, 18, 191, 61, -14, 3, 181, 88, -16, -8, 165, 116, -17, + -14, 142, 142, -14, -17, 116, 165, -8, -16, 88, 181, 3, -14, 61, 191, 18}, + // Coefficients 6 taps + {-25, 48, 210, 48, -25, 0, -19, 24, 200, 73, -28, 6, -13, 4, 190, 100, + -30, 5, -7, -11, 173, 127, -28, 2, -2, -22, 152, 152, -22, -2, 2, -28, + 127, 173, -11, -7, 5, -30, 100, 190, 4, -13, 6, -28, 73, 200, 24, -19}, + }, + + // Band_8_1312 + { + // Scaler inc range + {1311, 1312}, + // Coefficients 4 taps + {36, 184, 36, 0, 19, 189, 62, -14, 3, 181, 88, -16, -8, 165, 116, -17, + -14, 142, 142, -14, -17, 116, 165, -8, -16, 88, 181, 3, -14, 62, 189, 19}, + // Coefficients 6 taps + {-25, 48, 210, 48, -25, 0, -19, 24, 200, 73, -28, 6, -13, 4, 190, 100, + -30, 5, -7, -11, 173, 127, -28, 2, -2, -21, 151, 151, -21, -2, 2, -28, + 127, 173, -11, -7, 5, -30, 100, 190, 4, -13, 6, -28, 73, 200, 24, -19}, + }, + + // Band_8_1314 + { + // Scaler inc range + {1312, 1314}, + // Coefficients 4 taps + {36, 184, 36, 0, 19, 189, 62, -14, 3, 181, 88, -16, -8, 165, 116, -17, + -14, 142, 142, -14, -17, 116, 165, -8, -16, 88, 181, 3, -14, 62, 189, 19}, + // Coefficients 6 taps + {-25, 49, 208, 49, -25, 0, -19, 24, 200, 73, -28, 6, -13, 4, 190, 100, + -30, 5, -8, -11, 173, 127, -27, 2, -2, -21, 151, 151, -21, -2, 2, -27, + 127, 173, -11, -8, 5, -30, 100, 190, 4, -13, 6, -28, 73, 200, 24, -19}, + }, + + // Band_8_1316 + { + // Scaler inc range + {1314, 1316}, + // Coefficients 4 taps + {37, 182, 37, 0, 19, 189, 62, -14, 4, 180, 88, -16, -7, 164, 116, -17, + -14, 142, 142, -14, -17, 116, 164, -7, -16, 88, 180, 4, -14, 62, 189, 19}, + // Coefficients 6 taps + {-25, 49, 208, 49, -25, 0, -19, 24, 200, 73, -28, 6, -14, 5, 191, 100, + -30, 4, -8, -11, 173, 127, -27, 2, -2, -21, 151, 151, -21, -2, 2, -27, + 127, 173, -11, -8, 4, -30, 100, 191, 5, -14, 6, -28, 73, 200, 24, -19}, + }, + + // Band_8_1317 + { + // Scaler inc range + {1316, 1317}, + // Coefficients 4 taps + {37, 182, 37, 0, 19, 189, 62, -14, 4, 180, 88, -16, -7, 164, 116, -17, + -14, 142, 142, -14, -17, 116, 164, -7, -16, 88, 180, 4, -14, 62, 189, 19}, + // Coefficients 6 taps + {-25, 49, 208, 49, -25, 0, -20, 24, 201, 73, -28, 6, -14, 5, 190, 100, + -29, 4, -8, -10, 172, 127, -27, 2, -3, -21, 152, 152, -21, -3, 2, -27, + 127, 172, -10, -8, 4, -29, 100, 190, 5, -14, 6, -28, 73, 201, 24, -20}, + }, + + // Band_8_1319 + { + // Scaler inc range + {1317, 1319}, + // Coefficients 4 taps + {37, 182, 37, 0, 19, 189, 62, -14, 4, 180, 88, -16, -7, 163, 116, -16, + -14, 142, 142, -14, -16, 116, 163, -7, -16, 88, 180, 4, -14, 62, 189, 19}, + // Coefficients 6 taps + {-25, 49, 208, 49, -25, 0, -20, 25, 199, 74, -28, 6, -14, 5, 190, 100, + -29, 4, -8, -10, 173, 127, -27, 1, -3, -21, 152, 152, -21, -3, 1, -27, + 127, 173, -10, -8, 4, -29, 100, 190, 5, -14, 6, -28, 74, 199, 25, -20}, + }, + + // Band_8_1321 + { + // Scaler inc range + {1319, 1321}, + // Coefficients 4 taps + {37, 182, 37, 0, 19, 189, 62, -14, 4, 180, 88, -16, -7, 163, 116, -16, + -14, 142, 142, -14, -16, 116, 163, -7, -16, 88, 180, 4, -14, 62, 189, 19}, + // Coefficients 6 taps + {-25, 49, 208, 49, -25, 0, -20, 25, 199, 74, -28, 6, -14, 5, 190, 100, + -29, 4, -8, -10, 173, 127, -27, 1, -3, -21, 152, 152, -21, -3, 1, -27, + 127, 173, -10, -8, 4, -29, 100, 190, 5, -14, 6, -28, 74, 199, 25, -20}, + }, + + // Band_8_1322 + { + // Scaler inc range + {1321, 1322}, + // Coefficients 4 taps + {37, 182, 37, 0, 19, 189, 62, -14, 4, 179, 89, -16, -7, 163, 116, -16, + -14, 142, 142, -14, -16, 116, 163, -7, -16, 89, 179, 4, -14, 62, 189, 19}, + // Coefficients 6 taps + {-25, 49, 208, 49, -25, 0, -20, 25, 199, 74, -28, 6, -14, 6, 188, 101, + -29, 4, -8, -10, 173, 127, -27, 1, -3, -20, 151, 151, -20, -3, 1, -27, + 127, 173, -10, -8, 4, -29, 101, 188, 6, -14, 6, -28, 74, 199, 25, -20}, + }, + + // Band_8_1324 + { + // Scaler inc range + {1322, 1324}, + // Coefficients 4 taps + {37, 182, 37, 0, 20, 188, 62, -14, 4, 179, 89, -16, -7, 163, 116, -16, + -13, 141, 141, -13, -16, 116, 163, -7, -16, 89, 179, 4, -14, 62, 188, 20}, + // Coefficients 6 taps + {-26, 50, 208, 50, -26, 0, -20, 25, 199, 74, -28, 6, -14, 6, 188, 101, + -29, 4, -8, -10, 173, 127, -27, 1, -3, -20, 151, 151, -20, -3, 1, -27, + 127, 173, -10, -8, 4, -29, 101, 188, 6, -14, 6, -28, 74, 199, 25, -20}, + }, + + // Band_8_1326 + { + // Scaler inc range + {1324, 1326}, + // Coefficients 4 taps + {37, 182, 37, 0, 20, 188, 62, -14, 4, 179, 89, -16, -7, 163, 116, -16, + -13, 141, 141, -13, -16, 116, 163, -7, -16, 89, 179, 4, -14, 62, 188, 20}, + // Coefficients 6 taps + {-26, 50, 208, 50, -26, 0, -20, 25, 199, 74, -28, 6, -14, 6, 188, 101, -29, 4, -8, -9, 172, 127, -27, 1, -3, + -20, 151, 151, -20, -3, 1, -27, 127, 172, -9, -8, 4, -29, 101, 188, 6, -14, 6, -28, 74, 199, 25, -20}, + }, + + // Band_8_1327 + { + // Scaler inc range + {1326, 1327}, + // Coefficients 4 taps + {37, 182, 37, 0, 20, 188, 62, -14, 5, 178, 89, -16, -6, 162, 116, -16, + -13, 141, 141, -13, -16, 116, 162, -6, -16, 89, 178, 5, -14, 62, 188, 20}, + // Coefficients 6 taps + {-26, 50, 208, 50, -26, 0, -20, 26, 198, 74, -28, 6, -14, 6, 188, 101, -29, 4, -8, -9, 171, 127, -26, 1, -3, + -20, 151, 151, -20, -3, 1, -26, 127, 171, -9, -8, 4, -29, 101, 188, 6, -14, 6, -28, 74, 198, 26, -20}, + }, + + // Band_8_1329 + { + // Scaler inc range + {1327, 1329}, + // Coefficients 4 taps + {38, 180, 38, 0, 20, 187, 63, -14, 5, 178, 89, -16, -6, 162, 116, -16, + -13, 141, 141, -13, -16, 116, 162, -6, -16, 89, 178, 5, -14, 63, 187, 20}, + // Coefficients 6 taps + {-26, 50, 208, 50, -26, 0, -20, 26, 198, 74, -28, 6, -14, 6, 188, 101, -29, 4, -8, -9, 171, 127, -26, 1, -3, + -20, 151, 151, -20, -3, 1, -26, 127, 171, -9, -8, 4, -29, 101, 188, 6, -14, 6, -28, 74, 198, 26, -20}, + }, + + // Band_8_1331 + { + // Scaler inc range + {1329, 1331}, + // Coefficients 4 taps + {38, 180, 38, 0, 20, 187, 63, -14, 5, 178, 89, -16, -6, 162, 116, -16, + -13, 141, 141, -13, -16, 116, 162, -6, -16, 89, 178, 5, -14, 63, 187, 20}, + // Coefficients 6 taps + {-26, 50, 208, 50, -26, 0, -20, 26, 198, 74, -28, 6, -14, 7, 187, 101, -29, 4, -9, -9, 172, 127, -26, 1, -3, + -20, 151, 151, -20, -3, 1, -26, 127, 172, -9, -9, 4, -29, 101, 187, 7, -14, 6, -28, 74, 198, 26, -20}, + }, + + // Band_8_1332 + { + // Scaler inc range + {1331, 1332}, + // Coefficients 4 taps + {38, 180, 38, 0, 20, 187, 63, -14, 5, 178, 89, -16, -6, 162, 116, -16, + -13, 141, 141, -13, -16, 116, 162, -6, -16, 89, 178, 5, -14, 63, 187, 20}, + // Coefficients 6 taps + {-26, 50, 208, 50, -26, 0, -20, 26, 198, 75, -28, 5, -14, 7, 187, 101, -29, 4, -9, -9, 172, 127, -26, 1, -4, + -19, 151, 151, -19, -4, 1, -26, 127, 172, -9, -9, 4, -29, 101, 187, 7, -14, 5, -28, 75, 198, 26, -20}, + }, + + // Band_8_1334 + { + // Scaler inc range + {1332, 1334}, + // Coefficients 4 taps + {38, 180, 38, 0, 20, 186, 63, -13, 5, 178, 89, -16, -6, 162, 116, -16, + -13, 141, 141, -13, -16, 116, 162, -6, -16, 89, 178, 5, -13, 63, 186, 20}, + // Coefficients 6 taps + {-26, 51, 206, 51, -26, 0, -20, 27, 197, 75, -28, 5, -15, 7, 188, 101, -29, 4, -9, -8, 171, 127, -26, 1, -4, + -19, 151, 151, -19, -4, 1, -26, 127, 171, -8, -9, 4, -29, 101, 188, 7, -15, 5, -28, 75, 197, 27, -20}, + }, + + // Band_8_1336 + { + // Scaler inc range + {1334, 1336}, + // Coefficients 4 taps + {38, 180, 38, 0, 21, 185, 63, -13, 5, 178, 89, -16, -6, 163, 115, -16, + -13, 141, 141, -13, -16, 115, 163, -6, -16, 89, 178, 5, -13, 63, 185, 21}, + // Coefficients 6 taps + {-26, 51, 206, 51, -26, 0, -20, 27, 197, 75, -28, 5, -15, 7, 188, 101, -29, 4, -9, -8, 172, 127, -26, 0, -4, + -19, 151, 151, -19, -4, 0, -26, 127, 172, -8, -9, 4, -29, 101, 188, 7, -15, 5, -28, 75, 197, 27, -20}, + }, + + // Band_8_1337 + { + // Scaler inc range + {1336, 1337}, + // Coefficients 4 taps + {38, 180, 38, 0, 21, 185, 63, -13, 6, 177, 89, -16, -6, 163, 115, -16, + -12, 140, 140, -12, -16, 115, 163, -6, -16, 89, 177, 6, -13, 63, 185, 21}, + // Coefficients 6 taps + {-26, 51, 206, 51, -26, 0, -20, 27, 197, 75, -28, 5, -15, 7, 189, 101, -29, 3, -9, -8, 172, 127, -26, 0, -4, + -19, 151, 151, -19, -4, 0, -26, 127, 172, -8, -9, 3, -29, 101, 189, 7, -15, 5, -28, 75, 197, 27, -20}, + }, + + // Band_8_1339 + { + // Scaler inc range + {1337, 1339}, + // Coefficients 4 taps + {38, 180, 38, 0, 21, 185, 63, -13, 6, 176, 89, -15, -5, 161, 115, -15, + -12, 140, 140, -12, -15, 115, 161, -5, -15, 89, 176, 6, -13, 63, 185, 21}, + // Coefficients 6 taps + {-26, 51, 206, 51, -26, 0, -20, 27, 197, 75, -28, 5, -15, 8, 187, 101, -28, 3, -9, -8, 172, 127, -26, 0, -4, + -19, 151, 151, -19, -4, 0, -26, 127, 172, -8, -9, 3, -28, 101, 187, 8, -15, 5, -28, 75, 197, 27, -20}, + }, + + // Band_8_1341 + { + // Scaler inc range + {1339, 1341}, + // Coefficients 4 taps + {38, 180, 38, 0, 21, 185, 63, -13, 6, 176, 89, -15, -5, 161, 115, -15, + -12, 140, 140, -12, -15, 115, 161, -5, -15, 89, 176, 6, -13, 63, 185, 21}, + // Coefficients 6 taps + {-26, 51, 206, 51, -26, 0, -20, 27, 197, 75, -28, 5, -15, 8, 187, 101, -28, 3, -9, -8, 171, 127, -25, 0, -4, + -19, 151, 151, -19, -4, 0, -25, 127, 171, -8, -9, 3, -28, 101, 187, 8, -15, 5, -28, 75, 197, 27, -20}, + }, + + // Band_8_1343 + { + // Scaler inc range + {1341, 1343}, + // Coefficients 4 taps + {39, 178, 39, 0, 21, 185, 63, -13, 6, 176, 89, -15, -5, 161, 115, -15, + -12, 140, 140, -12, -15, 115, 161, -5, -15, 89, 176, 6, -13, 63, 185, 21}, + // Coefficients 6 taps + {-26, 51, 206, 51, -26, 0, -20, 28, 196, 75, -28, 5, -15, 8, 187, 101, -28, 3, -9, -7, 170, 127, -25, 0, -4, + -18, 150, 150, -18, -4, 0, -25, 127, 170, -7, -9, 3, -28, 101, 187, 8, -15, 5, -28, 75, 196, 28, -20}, + }, + + // Band_8_1344 + { + // Scaler inc range + {1343, 1344}, + // Coefficients 4 taps + {39, 178, 39, 0, 21, 185, 63, -13, 6, 176, 89, -15, -5, 161, 115, -15, + -12, 140, 140, -12, -15, 115, 161, -5, -15, 89, 176, 6, -13, 63, 185, 21}, + // Coefficients 6 taps + {-26, 52, 204, 52, -26, 0, -21, 28, 197, 75, -28, 5, -15, 8, 187, 101, -28, 3, -9, -7, 170, 127, -25, 0, -4, + -18, 150, 150, -18, -4, 0, -25, 127, 170, -7, -9, 3, -28, 101, 187, 8, -15, 5, -28, 75, 197, 28, -21}, + }, + + // Band_8_1346 + { + // Scaler inc range + {1344, 1346}, + // Coefficients 4 taps + {39, 178, 39, 0, 22, 184, 63, -13, 6, 176, 89, -15, -5, 161, 115, -15, + -12, 140, 140, -12, -15, 115, 161, -5, -15, 89, 176, 6, -13, 63, 184, 22}, + // Coefficients 6 taps + {-26, 52, 204, 52, -26, 0, -21, 28, 196, 76, -28, 5, -15, 8, 186, 102, -28, 3, -10, -7, 171, 127, -25, 0, -4, + -18, 150, 150, -18, -4, 0, -25, 127, 171, -7, -10, 3, -28, 102, 186, 8, -15, 5, -28, 76, 196, 28, -21}, + }, + + // Band_8_1348 + { + // Scaler inc range + {1346, 1348}, + // Coefficients 4 taps + {39, 178, 39, 0, 22, 184, 63, -13, 6, 176, 89, -15, -5, 161, 115, -15, + -12, 140, 140, -12, -15, 115, 161, -5, -15, 89, 176, 6, -13, 63, 184, 22}, + // Coefficients 6 taps + {-26, 52, 204, 52, -26, 0, -21, 28, 196, 76, -28, 5, -15, 9, 185, 102, -28, 3, -10, -7, 171, 127, -25, 0, -4, + -18, 150, 150, -18, -4, 0, -25, 127, 171, -7, -10, 3, -28, 102, 185, 9, -15, 5, -28, 76, 196, 28, -21}, + }, + + // Band_8_1350 + { + // Scaler inc range + {1348, 1350}, + // Coefficients 4 taps + {39, 178, 39, 0, 22, 183, 64, -13, 7, 175, 89, -15, -5, 161, 115, -15, + -12, 140, 140, -12, -15, 115, 161, -5, -15, 89, 175, 7, -13, 64, 183, 22}, + // Coefficients 6 taps + {-26, 52, 204, 52, -26, 0, -21, 28, 196, 76, -28, 5, -15, 9, 185, 102, -28, 3, -10, -7, 171, 127, -25, 0, -5, + -18, 151, 151, -18, -5, 0, -25, 127, 171, -7, -10, 3, -28, 102, 185, 9, -15, 5, -28, 76, 196, 28, -21}, + }, + + // Band_8_1351 + { + // Scaler inc range + {1350, 1351}, + // Coefficients 4 taps + {39, 178, 39, 0, 22, 183, 64, -13, 7, 175, 89, -15, -4, 160, 115, -15, + -12, 140, 140, -12, -15, 115, 160, -4, -15, 89, 175, 7, -13, 64, 183, 22}, + // Coefficients 6 taps + {-26, 52, 204, 52, -26, 0, -21, 29, 195, 76, -28, 5, -15, 9, 185, 102, -28, 3, -10, -6, 170, 127, -25, 0, -5, + -18, 151, 151, -18, -5, 0, -25, 127, 170, -6, -10, 3, -28, 102, 185, 9, -15, 5, -28, 76, 195, 29, -21}, + }, + + // Band_8_1353 + { + // Scaler inc range + {1351, 1353}, + // Coefficients 4 taps + {39, 178, 39, 0, 22, 183, 64, -13, 7, 175, 89, -15, -4, 160, 115, -15, + -11, 139, 139, -11, -15, 115, 160, -4, -15, 89, 175, 7, -13, 64, 183, 22}, + // Coefficients 6 taps + {-26, 52, 204, 52, -26, 0, -21, 29, 195, 76, -28, 5, -15, 9, 185, 102, + -28, 3, -10, -6, 171, 127, -25, -1, -5, -17, 150, 150, -17, -5, -1, -25, + 127, 171, -6, -10, 3, -28, 102, 185, 9, -15, 5, -28, 76, 195, 29, -21}, + }, + + // Band_8_1355 + { + // Scaler inc range + {1353, 1355}, + // Coefficients 4 taps + {39, 178, 39, 0, 22, 183, 64, -13, 7, 175, 89, -15, -4, 160, 115, -15, + -11, 139, 139, -11, -15, 115, 160, -4, -15, 89, 175, 7, -13, 64, 183, 22}, + // Coefficients 6 taps + {-26, 53, 202, 53, -26, 0, -21, 29, 195, 76, -28, 5, -16, 10, 185, 102, + -28, 3, -10, -6, 170, 127, -24, -1, -5, -17, 150, 150, -17, -5, -1, -24, + 127, 170, -6, -10, 3, -28, 102, 185, 10, -16, 5, -28, 76, 195, 29, -21}, + }, + + // Band_8_1357 + { + // Scaler inc range + {1355, 1357}, + // Coefficients 4 taps + {40, 176, 40, 0, 22, 183, 64, -13, 7, 175, 89, -15, -4, 160, 115, -15, + -11, 139, 139, -11, -15, 115, 160, -4, -15, 89, 175, 7, -13, 64, 183, 22}, + // Coefficients 6 taps + {-26, 53, 202, 53, -26, 0, -21, 29, 195, 76, -28, 5, -16, 10, 186, 102, + -28, 2, -10, -6, 170, 127, -24, -1, -5, -17, 150, 150, -17, -5, -1, -24, + 127, 170, -6, -10, 2, -28, 102, 186, 10, -16, 5, -28, 76, 195, 29, -21}, + }, + + // Band_8_1358 + { + // Scaler inc range + {1357, 1358}, + // Coefficients 4 taps + {40, 176, 40, 0, 23, 182, 64, -13, 7, 175, 89, -15, -4, 160, 115, -15, + -11, 139, 139, -11, -15, 115, 160, -4, -15, 89, 175, 7, -13, 64, 182, 23}, + // Coefficients 6 taps + {-26, 53, 202, 53, -26, 0, -21, 29, 196, 76, -28, 4, -16, 10, 186, 102, + -28, 2, -10, -6, 170, 127, -24, -1, -5, -17, 150, 150, -17, -5, -1, -24, + 127, 170, -6, -10, 2, -28, 102, 186, 10, -16, 4, -28, 76, 196, 29, -21}, + }, + + // Band_8_1360 + { + // Scaler inc range + {1358, 1360}, + // Coefficients 4 taps + {40, 176, 40, 0, 23, 182, 64, -13, 8, 174, 89, -15, -4, 159, 115, -14, + -11, 139, 139, -11, -14, 115, 159, -4, -15, 89, 174, 8, -13, 64, 182, 23}, + // Coefficients 6 taps + {-26, 53, 202, 53, -26, 0, -21, 29, 195, 77, -28, 4, -16, 10, 185, 102, + -27, 2, -10, -5, 169, 127, -24, -1, -5, -17, 150, 150, -17, -5, -1, -24, + 127, 169, -5, -10, 2, -27, 102, 185, 10, -16, 4, -28, 77, 195, 29, -21}, + }, + + // Band_8_1362 + { + // Scaler inc range + {1360, 1362}, + // Coefficients 4 taps + {40, 176, 40, 0, 23, 182, 64, -13, 8, 174, 89, -15, -4, 159, 115, -14, + -11, 139, 139, -11, -14, 115, 159, -4, -15, 89, 174, 8, -13, 64, 182, 23}, + // Coefficients 6 taps + {-26, 53, 202, 53, -26, 0, -21, 30, 194, 77, -28, 4, -16, 10, 185, 102, + -27, 2, -10, -5, 169, 127, -24, -1, -5, -17, 150, 150, -17, -5, -1, -24, + 127, 169, -5, -10, 2, -27, 102, 185, 10, -16, 4, -28, 77, 194, 30, -21}, + }, + + // Band_8_1364 + { + // Scaler inc range + {1362, 1364}, + // Coefficients 4 taps + {40, 176, 40, 0, 23, 182, 64, -13, 8, 174, 89, -15, -3, 158, 115, -14, + -11, 139, 139, -11, -14, 115, 158, -3, -15, 89, 174, 8, -13, 64, 182, 23}, + // Coefficients 6 taps + {-26, 53, 202, 53, -26, 0, -21, 30, 193, 77, -27, 4, -16, 11, 184, 102, + -27, 2, -11, -5, 170, 127, -24, -1, -5, -16, 149, 149, -16, -5, -1, -24, + 127, 170, -5, -11, 2, -27, 102, 184, 11, -16, 4, -27, 77, 193, 30, -21}, + }, + + // Band_8_1365 + { + // Scaler inc range + {1364, 1365}, + // Coefficients 4 taps + {40, 176, 40, 0, 23, 182, 64, -13, 8, 174, 89, -15, -3, 158, 115, -14, + -11, 139, 139, -11, -14, 115, 158, -3, -15, 89, 174, 8, -13, 64, 182, 23}, + // Coefficients 6 taps + {-26, 53, 202, 53, -26, 0, -21, 30, 193, 77, -27, 4, -16, 11, 184, 102, + -27, 2, -11, -5, 170, 127, -24, -1, -6, -16, 150, 150, -16, -6, -1, -24, + 127, 170, -5, -11, 2, -27, 102, 184, 11, -16, 4, -27, 77, 193, 30, -21}, + }, + + // Band_8_1367 + { + // Scaler inc range + {1365, 1367}, + // Coefficients 4 taps + {40, 176, 40, 0, 23, 182, 64, -13, 8, 174, 89, -15, -3, 158, 115, -14, + -10, 138, 138, -10, -14, 115, 158, -3, -15, 89, 174, 8, -13, 64, 182, 23}, + // Coefficients 6 taps + {-26, 54, 200, 54, -26, 0, -21, 30, 193, 77, -27, 4, -16, 11, 184, 102, + -27, 2, -11, -5, 169, 127, -23, -1, -6, -16, 150, 150, -16, -6, -1, -23, + 127, 169, -5, -11, 2, -27, 102, 184, 11, -16, 4, -27, 77, 193, 30, -21}, + }, + + // Band_8_1369 + { + // Scaler inc range + {1367, 1369}, + // Coefficients 4 taps + {40, 176, 40, 0, 23, 181, 65, -13, 8, 174, 89, -15, -3, 158, 115, -14, + -10, 138, 138, -10, -14, 115, 158, -3, -15, 89, 174, 8, -13, 65, 181, 23}, + // Coefficients 6 taps + {-26, 54, 200, 54, -26, 0, -21, 30, 193, 77, -27, 4, -16, 11, 184, 102, + -27, 2, -11, -4, 168, 127, -23, -1, -6, -16, 150, 150, -16, -6, -1, -23, + 127, 168, -4, -11, 2, -27, 102, 184, 11, -16, 4, -27, 77, 193, 30, -21}, + }, + + // Band_8_1371 + { + // Scaler inc range + {1369, 1371}, + // Coefficients 4 taps + {40, 176, 40, 0, 24, 180, 65, -13, 8, 174, 89, -15, -3, 158, 115, -14, + -10, 138, 138, -10, -14, 115, 158, -3, -15, 89, 174, 8, -13, 65, 180, 24}, + // Coefficients 6 taps + {-26, 54, 200, 54, -26, 0, -21, 31, 192, 77, -27, 4, -16, 11, 184, 102, + -27, 2, -11, -4, 169, 127, -23, -2, -6, -16, 150, 150, -16, -6, -2, -23, + 127, 169, -4, -11, 2, -27, 102, 184, 11, -16, 4, -27, 77, 192, 31, -21}, + }, + + // Band_8_1372 + { + // Scaler inc range + {1371, 1372}, + // Coefficients 4 taps + {41, 174, 41, 0, 24, 180, 65, -13, 9, 172, 89, -14, -3, 158, 115, -14, + -10, 138, 138, -10, -14, 115, 158, -3, -14, 89, 172, 9, -13, 65, 180, 24}, + // Coefficients 6 taps + {-26, 54, 200, 54, -26, 0, -21, 31, 192, 77, -27, 4, -16, 12, 183, 102, + -27, 2, -11, -4, 169, 127, -23, -2, -6, -15, 149, 149, -15, -6, -2, -23, + 127, 169, -4, -11, 2, -27, 102, 183, 12, -16, 4, -27, 77, 192, 31, -21}, + }, + + // Band_8_1374 + { + // Scaler inc range + {1372, 1374}, + // Coefficients 4 taps + {41, 174, 41, 0, 24, 180, 65, -13, 9, 172, 89, -14, -3, 159, 114, -14, + -10, 138, 138, -10, -14, 114, 159, -3, -14, 89, 172, 9, -13, 65, 180, 24}, + // Coefficients 6 taps + {-26, 54, 200, 54, -26, 0, -21, 31, 192, 77, -27, 4, -16, 12, 183, 102, + -27, 2, -11, -4, 169, 127, -23, -2, -6, -15, 149, 149, -15, -6, -2, -23, + 127, 169, -4, -11, 2, -27, 102, 183, 12, -16, 4, -27, 77, 192, 31, -21}, + }, + + // Band_8_1376 + { + // Scaler inc range + {1374, 1376}, + // Coefficients 4 taps + {41, 174, 41, 0, 24, 180, 65, -13, 9, 172, 89, -14, -2, 158, 114, -14, + -10, 138, 138, -10, -14, 114, 158, -2, -14, 89, 172, 9, -13, 65, 180, 24}, + // Coefficients 6 taps + {-26, 54, 200, 54, -26, 0, -21, 31, 191, 78, -27, 4, -16, 12, 183, 102, + -27, 2, -11, -4, 169, 127, -23, -2, -6, -15, 149, 149, -15, -6, -2, -23, + 127, 169, -4, -11, 2, -27, 102, 183, 12, -16, 4, -27, 78, 191, 31, -21}, + }, + + // Band_8_1378 + { + // Scaler inc range + {1376, 1378}, + // Coefficients 4 taps + {41, 174, 41, 0, 24, 180, 65, -13, 9, 172, 89, -14, -2, 158, 114, -14, + -10, 138, 138, -10, -14, 114, 158, -2, -14, 89, 172, 9, -13, 65, 180, 24}, + // Coefficients 6 taps + {-26, 54, 200, 54, -26, 0, -21, 31, 191, 78, -27, 4, -16, 12, 182, 103, + -26, 1, -11, -3, 168, 127, -23, -2, -6, -15, 149, 149, -15, -6, -2, -23, + 127, 168, -3, -11, 1, -26, 103, 182, 12, -16, 4, -27, 78, 191, 31, -21}, + }, + + // Band_8_1380 + { + // Scaler inc range + {1378, 1380}, + // Coefficients 4 taps + {41, 174, 41, 0, 24, 180, 65, -13, 9, 172, 89, -14, -2, 157, 114, -13, + -10, 138, 138, -10, -13, 114, 157, -2, -14, 89, 172, 9, -13, 65, 180, 24}, + // Coefficients 6 taps + {-26, 55, 198, 55, -26, 0, -21, 32, 190, 78, -27, 4, -17, 12, 183, 103, + -26, 1, -11, -3, 167, 127, -22, -2, -6, -15, 149, 149, -15, -6, -2, -22, + 127, 167, -3, -11, 1, -26, 103, 183, 12, -17, 4, -27, 78, 190, 32, -21}, + }, + + // Band_8_1382 + { + // Scaler inc range + {1380, 1382}, + // Coefficients 4 taps + {41, 174, 41, 0, 24, 180, 65, -13, 9, 172, 89, -14, -2, 157, 114, -13, + -10, 138, 138, -10, -13, 114, 157, -2, -14, 89, 172, 9, -13, 65, 180, 24}, + // Coefficients 6 taps + {-26, 55, 198, 55, -26, 0, -21, 32, 190, 78, -27, 4, -17, 13, 182, 103, + -26, 1, -11, -3, 167, 127, -22, -2, -6, -15, 149, 149, -15, -6, -2, -22, + 127, 167, -3, -11, 1, -26, 103, 182, 13, -17, 4, -27, 78, 190, 32, -21}, + }, + + // Band_8_1383 + { + // Scaler inc range + {1382, 1383}, + // Coefficients 4 taps + {41, 174, 41, 0, 25, 179, 65, -13, 9, 172, 89, -14, -2, 157, 114, -13, + -9, 137, 137, -9, -13, 114, 157, -2, -14, 89, 172, 9, -13, 65, 179, 25}, + // Coefficients 6 taps + {-26, 55, 198, 55, -26, 0, -21, 32, 191, 78, -27, 3, -17, 13, 182, 103, + -26, 1, -12, -3, 168, 127, -22, -2, -7, -14, 149, 149, -14, -7, -2, -22, + 127, 168, -3, -12, 1, -26, 103, 182, 13, -17, 3, -27, 78, 191, 32, -21}, + }, + + // Band_8_1385 + { + // Scaler inc range + {1383, 1385}, + // Coefficients 4 taps + {41, 174, 41, 0, 25, 179, 65, -13, 10, 171, 89, -14, -2, 157, 114, -13, + -9, 137, 137, -9, -13, 114, 157, -2, -14, 89, 171, 10, -13, 65, 179, 25}, + // Coefficients 6 taps + {-26, 55, 198, 55, -26, 0, -21, 32, 191, 78, -27, 3, -17, 13, 182, 103, + -26, 1, -12, -3, 168, 127, -22, -2, -7, -14, 149, 149, -14, -7, -2, -22, + 127, 168, -3, -12, 1, -26, 103, 182, 13, -17, 3, -27, 78, 191, 32, -21}, + }, + + // Band_8_1387 + { + // Scaler inc range + {1385, 1387}, + // Coefficients 4 taps + {42, 172, 42, 0, 25, 179, 65, -13, 10, 170, 90, -14, -2, 157, 114, -13, + -9, 137, 137, -9, -13, 114, 157, -2, -14, 90, 170, 10, -13, 65, 179, 25}, + // Coefficients 6 taps + {-26, 55, 198, 55, -26, 0, -22, 32, 192, 78, -27, 3, -17, 13, 182, 103, + -26, 1, -12, -2, 167, 127, -22, -2, -7, -14, 149, 149, -14, -7, -2, -22, + 127, 167, -2, -12, 1, -26, 103, 182, 13, -17, 3, -27, 78, 192, 32, -22}, + }, + + // Band_8_1389 + { + // Scaler inc range + {1387, 1389}, + // Coefficients 4 taps + {42, 172, 42, 0, 25, 179, 65, -13, 10, 170, 90, -14, -1, 156, 114, -13, + -9, 137, 137, -9, -13, 114, 156, -1, -14, 90, 170, 10, -13, 65, 179, 25}, + // Coefficients 6 taps + {-25, 55, 196, 55, -25, 0, -22, 33, 191, 78, -27, 3, -17, 14, 181, 103, + -26, 1, -12, -2, 168, 127, -22, -3, -7, -14, 149, 149, -14, -7, -3, -22, + 127, 168, -2, -12, 1, -26, 103, 181, 14, -17, 3, -27, 78, 191, 33, -22}, + }, + + // Band_8_1391 + { + // Scaler inc range + {1389, 1391}, + // Coefficients 4 taps + {42, 172, 42, 0, 25, 179, 65, -13, 10, 170, 90, -14, -1, 156, 114, -13, + -9, 137, 137, -9, -13, 114, 156, -1, -14, 90, 170, 10, -13, 65, 179, 25}, + // Coefficients 6 taps + {-25, 55, 196, 55, -25, 0, -22, 33, 191, 78, -27, 3, -17, 14, 181, 103, + -26, 1, -12, -2, 168, 127, -22, -3, -7, -14, 149, 149, -14, -7, -3, -22, + 127, 168, -2, -12, 1, -26, 103, 181, 14, -17, 3, -27, 78, 191, 33, -22}, + }, + + // Band_8_1393 + { + // Scaler inc range + {1391, 1393}, + // Coefficients 4 taps + {42, 172, 42, 0, 25, 178, 66, -13, 10, 170, 90, -14, -1, 156, 114, -13, + -9, 137, 137, -9, -13, 114, 156, -1, -14, 90, 170, 10, -13, 66, 178, 25}, + // Coefficients 6 taps + {-25, 56, 194, 56, -25, 0, -22, 33, 191, 78, -27, 3, -17, 14, 181, 103, + -26, 1, -12, -2, 167, 127, -21, -3, -7, -13, 148, 148, -13, -7, -3, -21, + 127, 167, -2, -12, 1, -26, 103, 181, 14, -17, 3, -27, 78, 191, 33, -22}, + }, + + // Band_8_1394 + { + // Scaler inc range + {1393, 1394}, + // Coefficients 4 taps + {42, 172, 42, 0, 25, 178, 66, -13, 10, 170, 90, -14, -1, 156, 114, -13, + -9, 137, 137, -9, -13, 114, 156, -1, -14, 90, 170, 10, -13, 66, 178, 25}, + // Coefficients 6 taps + {-25, 56, 194, 56, -25, 0, -22, 33, 190, 79, -27, 3, -17, 14, 181, 103, + -26, 1, -12, -1, 166, 127, -21, -3, -7, -13, 148, 148, -13, -7, -3, -21, + 127, 166, -1, -12, 1, -26, 103, 181, 14, -17, 3, -27, 79, 190, 33, -22}, + }, + + // Band_8_1396 + { + // Scaler inc range + {1394, 1396}, + // Coefficients 4 taps + {42, 172, 42, 0, 26, 177, 66, -13, 11, 169, 90, -14, -1, 156, 114, -13, + -9, 137, 137, -9, -13, 114, 156, -1, -14, 90, 169, 11, -13, 66, 177, 26}, + // Coefficients 6 taps + {-25, 56, 194, 56, -25, 0, -22, 33, 190, 79, -27, 3, -17, 14, 180, 103, + -25, 1, -12, -1, 166, 127, -21, -3, -7, -13, 148, 148, -13, -7, -3, -21, + 127, 166, -1, -12, 1, -25, 103, 180, 14, -17, 3, -27, 79, 190, 33, -22}, + }, + + // Band_8_1398 + { + // Scaler inc range + {1396, 1398}, + // Coefficients 4 taps + {42, 172, 42, 0, 26, 177, 66, -13, 11, 169, 90, -14, -1, 156, 114, -13, + -8, 136, 136, -8, -13, 114, 156, -1, -14, 90, 169, 11, -13, 66, 177, 26}, + // Coefficients 6 taps + {-25, 56, 194, 56, -25, 0, -22, 34, 188, 79, -26, 3, -17, 15, 180, 103, + -25, 0, -12, -1, 166, 127, -21, -3, -7, -13, 148, 148, -13, -7, -3, -21, + 127, 166, -1, -12, 0, -25, 103, 180, 15, -17, 3, -26, 79, 188, 34, -22}, + }, + + // Band_8_1400 + { + // Scaler inc range + {1398, 1400}, + // Coefficients 4 taps + {42, 172, 42, 0, 26, 177, 66, -13, 11, 169, 90, -14, -1, 155, 114, -12, + -8, 136, 136, -8, -12, 114, 155, -1, -14, 90, 169, 11, -13, 66, 177, 26}, + // Coefficients 6 taps + {-25, 56, 194, 56, -25, 0, -22, 34, 188, 79, -26, 3, -17, 15, 180, 103, + -25, 0, -12, -1, 166, 127, -21, -3, -7, -13, 148, 148, -13, -7, -3, -21, + 127, 166, -1, -12, 0, -25, 103, 180, 15, -17, 3, -26, 79, 188, 34, -22}, + }, + + // Band_8_1402 + { + // Scaler inc range + {1400, 1402}, + // Coefficients 4 taps + {42, 172, 42, 0, 26, 177, 66, -13, 11, 169, 90, -14, 0, 154, 114, -12, + -8, 136, 136, -8, -12, 114, 154, 0, -14, 90, 169, 11, -13, 66, 177, 26}, + // Coefficients 6 taps + {-25, 56, 194, 56, -25, 0, -22, 34, 188, 79, -26, 3, -17, 15, 180, 103, + -25, 0, -12, -1, 166, 127, -21, -3, -8, -13, 149, 149, -13, -8, -3, -21, + 127, 166, -1, -12, 0, -25, 103, 180, 15, -17, 3, -26, 79, 188, 34, -22}, + }, + + // Band_8_1404 + { + // Scaler inc range + {1402, 1404}, + // Coefficients 4 taps + {43, 170, 43, 0, 26, 177, 66, -13, 11, 168, 90, -13, 0, 154, 114, -12, + -8, 136, 136, -8, -12, 114, 154, 0, -13, 90, 168, 11, -13, 66, 177, 26}, + // Coefficients 6 taps + {-25, 56, 194, 56, -25, 0, -22, 34, 188, 79, -26, 3, -17, 15, 180, 103, + -25, 0, -12, 0, 164, 127, -20, -3, -8, -12, 148, 148, -12, -8, -3, -20, + 127, 164, 0, -12, 0, -25, 103, 180, 15, -17, 3, -26, 79, 188, 34, -22}, + }, + + // Band_8_1406 + { + // Scaler inc range + {1404, 1406}, + // Coefficients 4 taps + {43, 170, 43, 0, 26, 176, 66, -12, 11, 168, 90, -13, 0, 154, 114, -12, + -8, 136, 136, -8, -12, 114, 154, 0, -13, 90, 168, 11, -12, 66, 176, 26}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 34, 188, 79, -26, 3, -17, 15, 180, 103, + -25, 0, -13, 0, 165, 127, -20, -3, -8, -12, 148, 148, -12, -8, -3, -20, + 127, 165, 0, -13, 0, -25, 103, 180, 15, -17, 3, -26, 79, 188, 34, -22}, + }, + + // Band_8_1407 + { + // Scaler inc range + {1406, 1407}, + // Coefficients 4 taps + {43, 170, 43, 0, 26, 176, 66, -12, 11, 168, 90, -13, 0, 154, 114, -12, + -8, 136, 136, -8, -12, 114, 154, 0, -13, 90, 168, 11, -12, 66, 176, 26}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 34, 188, 79, -26, 3, -17, 16, 179, 103, + -25, 0, -13, 0, 165, 127, -20, -3, -8, -12, 148, 148, -12, -8, -3, -20, + 127, 165, 0, -13, 0, -25, 103, 179, 16, -17, 3, -26, 79, 188, 34, -22}, + }, + + // Band_8_1409 + { + // Scaler inc range + {1407, 1409}, + // Coefficients 4 taps + {43, 170, 43, 0, 27, 175, 66, -12, 12, 167, 90, -13, 0, 154, 114, -12, + -8, 136, 136, -8, -12, 114, 154, 0, -13, 90, 167, 12, -12, 66, 175, 27}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 35, 188, 79, -26, 2, -18, 16, 180, 103, + -25, 0, -13, 0, 167, 126, -20, -4, -8, -12, 148, 148, -12, -8, -4, -20, + 126, 167, 0, -13, 0, -25, 103, 180, 16, -18, 2, -26, 79, 188, 35, -22}, + }, + + // Band_8_1411 + { + // Scaler inc range + {1409, 1411}, + // Coefficients 4 taps + {43, 170, 43, 0, 27, 175, 66, -12, 12, 167, 90, -13, 0, 155, 113, -12, + -8, 136, 136, -8, -12, 113, 155, 0, -13, 90, 167, 12, -12, 66, 175, 27}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 35, 188, 79, -26, 2, -18, 16, 180, 103, + -25, 0, -13, 0, 167, 126, -20, -4, -8, -12, 148, 148, -12, -8, -4, -20, + 126, 167, 0, -13, 0, -25, 103, 180, 16, -18, 2, -26, 79, 188, 35, -22}, + }, + + // Band_8_1413 + { + // Scaler inc range + {1411, 1413}, + // Coefficients 4 taps + {43, 170, 43, 0, 27, 175, 66, -12, 12, 167, 90, -13, 0, 155, 113, -12, + -7, 135, 135, -7, -12, 113, 155, 0, -13, 90, 167, 12, -12, 66, 175, 27}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 35, 188, 79, -26, 2, -18, 16, 179, 103, + -24, 0, -13, 1, 166, 126, -20, -4, -8, -11, 147, 147, -11, -8, -4, -20, + 126, 166, 1, -13, 0, -24, 103, 179, 16, -18, 2, -26, 79, 188, 35, -22}, + }, + + // Band_8_1415 + { + // Scaler inc range + {1413, 1415}, + // Coefficients 4 taps + {43, 170, 43, 0, 27, 175, 66, -12, 12, 167, 90, -13, 1, 154, 113, -12, + -7, 135, 135, -7, -12, 113, 154, 1, -13, 90, 167, 12, -12, 66, 175, 27}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 35, 187, 80, -26, 2, -18, 16, 179, 103, + -24, 0, -13, 1, 166, 126, -20, -4, -8, -11, 147, 147, -11, -8, -4, -20, + 126, 166, 1, -13, 0, -24, 103, 179, 16, -18, 2, -26, 80, 187, 35, -22}, + }, + + // Band_8_1417 + { + // Scaler inc range + {1415, 1417}, + // Coefficients 4 taps + {43, 170, 43, 0, 27, 174, 67, -12, 12, 167, 90, -13, 1, 154, 113, -12, + -7, 135, 135, -7, -12, 113, 154, 1, -13, 90, 167, 12, -12, 67, 174, 27}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 35, 187, 80, -26, 2, -18, 17, 178, 103, + -24, 0, -13, 1, 165, 126, -19, -4, -8, -11, 147, 147, -11, -8, -4, -19, + 126, 165, 1, -13, 0, -24, 103, 178, 17, -18, 2, -26, 80, 187, 35, -22}, + }, + + // Band_8_1419 + { + // Scaler inc range + {1417, 1419}, + // Coefficients 4 taps + {44, 168, 44, 0, 27, 174, 67, -12, 12, 167, 90, -13, 1, 153, 113, -11, + -7, 135, 135, -7, -11, 113, 153, 1, -13, 90, 167, 12, -12, 67, 174, 27}, + // Coefficients 6 taps + {-25, 57, 192, 57, -25, 0, -22, 36, 186, 80, -26, 2, -18, 17, 179, 103, + -24, -1, -13, 1, 165, 126, -19, -4, -8, -11, 147, 147, -11, -8, -4, -19, + 126, 165, 1, -13, -1, -24, 103, 179, 17, -18, 2, -26, 80, 186, 36, -22}, + }, + + // Band_8_1421 + { + // Scaler inc range + {1419, 1421}, + // Coefficients 4 taps + {44, 168, 44, 0, 27, 174, 67, -12, 12, 167, 90, -13, 1, 153, 113, -11, + -7, 135, 135, -7, -11, 113, 153, 1, -13, 90, 167, 12, -12, 67, 174, 27}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 36, 186, 80, -26, 2, -18, 17, 179, 103, + -24, -1, -13, 1, 165, 126, -19, -4, -8, -11, 147, 147, -11, -8, -4, -19, + 126, 165, 1, -13, -1, -24, 103, 179, 17, -18, 2, -26, 80, 186, 36, -22}, + }, + + // Band_8_1423 + { + // Scaler inc range + {1421, 1423}, + // Coefficients 4 taps + {44, 168, 44, 0, 28, 173, 67, -12, 13, 166, 90, -13, 1, 153, 113, -11, + -7, 135, 135, -7, -11, 113, 153, 1, -13, 90, 166, 13, -12, 67, 173, 28}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 36, 186, 80, -26, 2, -18, 17, 179, 103, + -24, -1, -13, 2, 164, 126, -19, -4, -9, -11, 148, 148, -11, -9, -4, -19, + 126, 164, 2, -13, -1, -24, 103, 179, 17, -18, 2, -26, 80, 186, 36, -22}, + }, + + // Band_8_1425 + { + // Scaler inc range + {1423, 1425}, + // Coefficients 4 taps + {44, 168, 44, 0, 28, 173, 67, -12, 13, 166, 90, -13, 1, 153, 113, -11, + -7, 135, 135, -7, -11, 113, 153, 1, -13, 90, 166, 13, -12, 67, 173, 28}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 36, 185, 80, -25, 2, -18, 17, 178, 104, + -24, -1, -13, 2, 164, 126, -19, -4, -9, -10, 147, 147, -10, -9, -4, -19, + 126, 164, 2, -13, -1, -24, 104, 178, 17, -18, 2, -25, 80, 185, 36, -22}, + }, + + // Band_8_1427 + { + // Scaler inc range + {1425, 1427}, + // Coefficients 4 taps + {44, 168, 44, 0, 28, 173, 67, -12, 13, 166, 90, -13, 1, 153, 113, -11, + -7, 135, 135, -7, -11, 113, 153, 1, -13, 90, 166, 13, -12, 67, 173, 28}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 36, 185, 80, -25, 2, -18, 18, 177, 104, + -24, -1, -13, 2, 164, 126, -19, -4, -9, -10, 147, 147, -10, -9, -4, -19, + 126, 164, 2, -13, -1, -24, 104, 177, 18, -18, 2, -25, 80, 185, 36, -22}, + }, + + // Band_8_1429 + { + // Scaler inc range + {1427, 1429}, + // Coefficients 4 taps + {44, 168, 44, 0, 28, 173, 67, -12, 13, 166, 90, -13, 2, 152, 113, -11, + -6, 134, 134, -6, -11, 113, 152, 2, -13, 90, 166, 13, -12, 67, 173, 28}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 36, 185, 80, -25, 2, -18, 18, 176, 104, + -23, -1, -13, 2, 164, 126, -18, -5, -9, -10, 147, 147, -10, -9, -5, -18, + 126, 164, 2, -13, -1, -23, 104, 176, 18, -18, 2, -25, 80, 185, 36, -22}, + }, + + // Band_8_1431 + { + // Scaler inc range + {1429, 1431}, + // Coefficients 4 taps + {44, 168, 44, 0, 28, 173, 67, -12, 13, 166, 90, -13, 2, 152, 113, -11, + -6, 134, 134, -6, -11, 113, 152, 2, -13, 90, 166, 13, -12, 67, 173, 28}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 37, 184, 80, -25, 2, -18, 18, 176, 104, + -23, -1, -14, 2, 165, 126, -18, -5, -9, -10, 147, 147, -10, -9, -5, -18, + 126, 165, 2, -14, -1, -23, 104, 176, 18, -18, 2, -25, 80, 184, 37, -22}, + }, + + // Band_8_1432 + { + // Scaler inc range + {1431, 1432}, + // Coefficients 4 taps + {44, 168, 44, 0, 28, 173, 67, -12, 13, 165, 90, -12, 2, 152, 113, -11, + -6, 134, 134, -6, -11, 113, 152, 2, -12, 90, 165, 13, -12, 67, 173, 28}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 37, 184, 80, -25, 2, -18, 18, 176, 104, + -23, -1, -14, 3, 164, 126, -18, -5, -9, -10, 147, 147, -10, -9, -5, -18, + 126, 164, 3, -14, -1, -23, 104, 176, 18, -18, 2, -25, 80, 184, 37, -22}, + }, + + // Band_8_1434 + { + // Scaler inc range + {1432, 1434}, + // Coefficients 4 taps + {44, 168, 44, 0, 28, 173, 67, -12, 13, 165, 90, -12, 2, 152, 113, -11, + -6, 134, 134, -6, -11, 113, 152, 2, -12, 90, 165, 13, -12, 67, 173, 28}, + // Coefficients 6 taps + {-25, 58, 190, 58, -25, 0, -22, 37, 185, 80, -25, 1, -18, 18, 176, 104, + -23, -1, -14, 3, 164, 126, -18, -5, -9, -9, 146, 146, -9, -9, -5, -18, + 126, 164, 3, -14, -1, -23, 104, 176, 18, -18, 1, -25, 80, 185, 37, -22}, + }, + + // Band_8_1436 + { + // Scaler inc range + {1434, 1436}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 172, 67, -12, 14, 164, 90, -12, 2, 152, 113, -11, + -6, 134, 134, -6, -11, 113, 152, 2, -12, 90, 164, 14, -12, 67, 172, 29}, + // Coefficients 6 taps + {-25, 59, 188, 59, -25, 0, -22, 37, 184, 81, -25, 1, -18, 19, 175, 104, + -23, -1, -14, 3, 164, 126, -18, -5, -9, -9, 146, 146, -9, -9, -5, -18, + 126, 164, 3, -14, -1, -23, 104, 175, 19, -18, 1, -25, 81, 184, 37, -22}, + }, + + // Band_8_1438 + { + // Scaler inc range + {1436, 1438}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 172, 67, -12, 14, 164, 90, -12, 2, 151, 113, -10, + -6, 134, 134, -6, -10, 113, 151, 2, -12, 90, 164, 14, -12, 67, 172, 29}, + // Coefficients 6 taps + {-25, 59, 188, 59, -25, 0, -22, 37, 184, 81, -25, 1, -18, 19, 175, 104, + -23, -1, -14, 3, 164, 126, -18, -5, -9, -9, 146, 146, -9, -9, -5, -18, + 126, 164, 3, -14, -1, -23, 104, 175, 19, -18, 1, -25, 81, 184, 37, -22}, + }, + + // Band_8_1440 + { + // Scaler inc range + {1438, 1440}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 172, 67, -12, 14, 164, 90, -12, 2, 151, 113, -10, + -6, 134, 134, -6, -10, 113, 151, 2, -12, 90, 164, 14, -12, 67, 172, 29}, + // Coefficients 6 taps + {-25, 59, 188, 59, -25, 0, -22, 37, 184, 81, -25, 1, -18, 19, 175, 104, + -23, -1, -14, 3, 163, 126, -17, -5, -9, -9, 146, 146, -9, -9, -5, -17, + 126, 163, 3, -14, -1, -23, 104, 175, 19, -18, 1, -25, 81, 184, 37, -22}, + }, + + // Band_8_1442 + { + // Scaler inc range + {1440, 1442}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 172, 67, -12, 14, 164, 90, -12, 3, 150, 113, -10, + -6, 134, 134, -6, -10, 113, 150, 3, -12, 90, 164, 14, -12, 67, 172, 29}, + // Coefficients 6 taps + {-25, 59, 188, 59, -25, 0, -22, 38, 183, 81, -25, 1, -18, 19, 176, 104, + -23, -2, -14, 4, 162, 126, -17, -5, -9, -9, 146, 146, -9, -9, -5, -17, + 126, 162, 4, -14, -2, -23, 104, 176, 19, -18, 1, -25, 81, 183, 38, -22}, + }, + + // Band_8_1444 + { + // Scaler inc range + {1442, 1444}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 171, 68, -12, 14, 164, 90, -12, 3, 150, 113, -10, + -5, 133, 133, -5, -10, 113, 150, 3, -12, 90, 164, 14, -12, 68, 171, 29}, + // Coefficients 6 taps + {-24, 59, 186, 59, -24, 0, -22, 38, 183, 81, -25, 1, -18, 19, 175, 104, + -22, -2, -14, 4, 162, 126, -17, -5, -9, -8, 145, 145, -8, -9, -5, -17, + 126, 162, 4, -14, -2, -22, 104, 175, 19, -18, 1, -25, 81, 183, 38, -22}, + }, + + // Band_8_1446 + { + // Scaler inc range + {1444, 1446}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 171, 68, -12, 14, 164, 90, -12, 3, 151, 112, -10, + -5, 133, 133, -5, -10, 112, 151, 3, -12, 90, 164, 14, -12, 68, 171, 29}, + // Coefficients 6 taps + {-24, 59, 186, 59, -24, 0, -22, 38, 183, 81, -25, 1, -18, 20, 174, 104, + -22, -2, -14, 4, 162, 126, -17, -5, -10, -8, 146, 146, -8, -10, -5, -17, + 126, 162, 4, -14, -2, -22, 104, 174, 20, -18, 1, -25, 81, 183, 38, -22}, + }, + + // Band_8_1448 + { + // Scaler inc range + {1446, 1448}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 171, 68, -12, 15, 163, 90, -12, 3, 151, 112, -10, + -5, 133, 133, -5, -10, 112, 151, 3, -12, 90, 163, 15, -12, 68, 171, 29}, + // Coefficients 6 taps + {-24, 59, 186, 59, -24, 0, -22, 38, 182, 81, -24, 1, -18, 20, 174, 104, + -22, -2, -14, 4, 162, 126, -17, -5, -10, -8, 146, 146, -8, -10, -5, -17, + 126, 162, 4, -14, -2, -22, 104, 174, 20, -18, 1, -24, 81, 182, 38, -22}, + }, + + // Band_8_1450 + { + // Scaler inc range + {1448, 1450}, + // Coefficients 4 taps + {45, 166, 45, 0, 29, 171, 68, -12, 15, 163, 90, -12, 3, 151, 112, -10, + -5, 133, 133, -5, -10, 112, 151, 3, -12, 90, 163, 15, -12, 68, 171, 29}, + // Coefficients 6 taps + {-24, 59, 186, 59, -24, 0, -22, 38, 182, 81, -24, 1, -19, 20, 175, 104, + -22, -2, -14, 4, 163, 126, -17, -6, -10, -8, 146, 146, -8, -10, -6, -17, + 126, 163, 4, -14, -2, -22, 104, 175, 20, -19, 1, -24, 81, 182, 38, -22}, + }, + + // Band_8_1452 + { + // Scaler inc range + {1450, 1452}, + // Coefficients 4 taps + {45, 166, 45, 0, 30, 170, 68, -12, 15, 163, 90, -12, 3, 151, 112, -10, + -5, 133, 133, -5, -10, 112, 151, 3, -12, 90, 163, 15, -12, 68, 170, 30}, + // Coefficients 6 taps + {-24, 59, 186, 59, -24, 0, -22, 39, 181, 81, -24, 1, -19, 20, 175, 104, + -22, -2, -14, 5, 161, 126, -16, -6, -10, -8, 146, 146, -8, -10, -6, -16, + 126, 161, 5, -14, -2, -22, 104, 175, 20, -19, 1, -24, 81, 181, 39, -22}, + }, + + // Band_8_1454 + { + // Scaler inc range + {1452, 1454}, + // Coefficients 4 taps + {45, 166, 45, 0, 30, 170, 68, -12, 15, 163, 90, -12, 3, 151, 112, -10, + -5, 133, 133, -5, -10, 112, 151, 3, -12, 90, 163, 15, -12, 68, 170, 30}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 39, 181, 81, -24, 1, -19, 20, 175, 104, + -22, -2, -14, 5, 161, 126, -16, -6, -10, -7, 145, 145, -7, -10, -6, -16, + 126, 161, 5, -14, -2, -22, 104, 175, 20, -19, 1, -24, 81, 181, 39, -22}, + }, + + // Band_8_1456 + { + // Scaler inc range + {1454, 1456}, + // Coefficients 4 taps + {46, 164, 46, 0, 30, 169, 68, -11, 15, 163, 90, -12, 3, 151, 112, -10, + -5, 133, 133, -5, -10, 112, 151, 3, -12, 90, 163, 15, -11, 68, 169, 30}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 39, 181, 81, -24, 1, -19, 21, 174, 104, + -22, -2, -14, 5, 161, 126, -16, -6, -10, -7, 145, 145, -7, -10, -6, -16, + 126, 161, 5, -14, -2, -22, 104, 174, 21, -19, 1, -24, 81, 181, 39, -22}, + }, + + // Band_8_1458 + { + // Scaler inc range + {1456, 1458}, + // Coefficients 4 taps + {46, 164, 46, 0, 30, 169, 68, -11, 15, 163, 90, -12, 4, 149, 112, -9, + -5, 133, 133, -5, -9, 112, 149, 4, -12, 90, 163, 15, -11, 68, 169, 30}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 39, 181, 81, -24, 1, -19, 21, 174, 104, + -22, -2, -14, 5, 161, 126, -16, -6, -10, -7, 145, 145, -7, -10, -6, -16, + 126, 161, 5, -14, -2, -22, 104, 174, 21, -19, 1, -24, 81, 181, 39, -22}, + }, + + // Band_8_1460 + { + // Scaler inc range + {1458, 1460}, + // Coefficients 4 taps + {46, 164, 46, 0, 30, 169, 68, -11, 15, 162, 90, -11, 4, 149, 112, -9, + -4, 132, 132, -4, -9, 112, 149, 4, -11, 90, 162, 15, -11, 68, 169, 30}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 39, 182, 81, -24, 0, -19, 21, 173, 104, + -21, -2, -15, 5, 163, 125, -16, -6, -10, -7, 145, 145, -7, -10, -6, -16, + 125, 163, 5, -15, -2, -21, 104, 173, 21, -19, 0, -24, 81, 182, 39, -22}, + }, + + // Band_8_1462 + { + // Scaler inc range + {1460, 1462}, + // Coefficients 4 taps + {46, 164, 46, 0, 30, 169, 68, -11, 16, 161, 90, -11, 4, 149, 112, -9, + -4, 132, 132, -4, -9, 112, 149, 4, -11, 90, 161, 16, -11, 68, 169, 30}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 39, 181, 82, -24, 0, -19, 21, 173, 104, + -21, -2, -15, 6, 162, 125, -16, -6, -10, -7, 145, 145, -7, -10, -6, -16, + 125, 162, 6, -15, -2, -21, 104, 173, 21, -19, 0, -24, 82, 181, 39, -22}, + }, + + // Band_8_1464 + { + // Scaler inc range + {1462, 1464}, + // Coefficients 4 taps + {46, 164, 46, 0, 30, 169, 68, -11, 16, 161, 90, -11, 4, 149, 112, -9, + -4, 132, 132, -4, -9, 112, 149, 4, -11, 90, 161, 16, -11, 68, 169, 30}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 40, 180, 82, -24, 0, -19, 21, 174, 104, + -21, -3, -15, 6, 161, 125, -15, -6, -10, -6, 144, 144, -6, -10, -6, -15, + 125, 161, 6, -15, -3, -21, 104, 174, 21, -19, 0, -24, 82, 180, 40, -22}, + }, + + // Band_8_1467 + { + // Scaler inc range + {1464, 1467}, + // Coefficients 4 taps + {46, 164, 46, 0, 31, 168, 68, -11, 16, 161, 90, -11, 4, 149, 112, -9, + -4, 132, 132, -4, -9, 112, 149, 4, -11, 90, 161, 16, -11, 68, 168, 31}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 40, 180, 82, -24, 0, -19, 22, 173, 104, + -21, -3, -15, 6, 161, 125, -15, -6, -10, -6, 144, 144, -6, -10, -6, -15, + 125, 161, 6, -15, -3, -21, 104, 173, 22, -19, 0, -24, 82, 180, 40, -22}, + }, + + // Band_8_1469 + { + // Scaler inc range + {1467, 1469}, + // Coefficients 4 taps + {46, 164, 46, 0, 31, 168, 68, -11, 16, 161, 90, -11, 4, 149, 112, -9, + -4, 132, 132, -4, -9, 112, 149, 4, -11, 90, 161, 16, -11, 68, 168, 31}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 40, 180, 82, -24, 0, -19, 22, 173, 104, + -21, -3, -15, 6, 161, 125, -15, -6, -10, -6, 144, 144, -6, -10, -6, -15, + 125, 161, 6, -15, -3, -21, 104, 173, 22, -19, 0, -24, 82, 180, 40, -22}, + }, + + // Band_8_1471 + { + // Scaler inc range + {1469, 1471}, + // Coefficients 4 taps + {46, 164, 46, 0, 31, 168, 68, -11, 16, 161, 90, -11, 4, 149, 112, -9, + -4, 132, 132, -4, -9, 112, 149, 4, -11, 90, 161, 16, -11, 68, 168, 31}, + // Coefficients 6 taps + {-24, 60, 184, 60, -24, 0, -22, 40, 179, 82, -23, 0, -19, 22, 173, 104, + -21, -3, -15, 6, 161, 125, -15, -6, -11, -6, 145, 145, -6, -11, -6, -15, + 125, 161, 6, -15, -3, -21, 104, 173, 22, -19, 0, -23, 82, 179, 40, -22}, + }, + + // Band_8_1473 + { + // Scaler inc range + {1471, 1473}, + // Coefficients 4 taps + {46, 164, 46, 0, 31, 168, 68, -11, 16, 161, 90, -11, 5, 148, 112, -9, + -4, 132, 132, -4, -9, 112, 148, 5, -11, 90, 161, 16, -11, 68, 168, 31}, + // Coefficients 6 taps + {-24, 61, 182, 61, -24, 0, -22, 40, 179, 82, -23, 0, -19, 22, 173, 104, + -21, -3, -15, 7, 160, 125, -15, -6, -11, -6, 145, 145, -6, -11, -6, -15, + 125, 160, 7, -15, -3, -21, 104, 173, 22, -19, 0, -23, 82, 179, 40, -22}, + }, + + // Band_8_1475 + { + // Scaler inc range + {1473, 1475}, + // Coefficients 4 taps + {47, 162, 47, 0, 31, 168, 68, -11, 16, 161, 90, -11, 5, 148, 112, -9, + -4, 132, 132, -4, -9, 112, 148, 5, -11, 90, 161, 16, -11, 68, 168, 31}, + // Coefficients 6 taps + {-24, 61, 182, 61, -24, 0, -22, 40, 179, 82, -23, 0, -19, 22, 172, 104, + -20, -3, -15, 7, 161, 125, -15, -7, -11, -6, 145, 145, -6, -11, -7, -15, + 125, 161, 7, -15, -3, -20, 104, 172, 22, -19, 0, -23, 82, 179, 40, -22}, + }, + + // Band_8_1477 + { + // Scaler inc range + {1475, 1477}, + // Coefficients 4 taps + {47, 162, 47, 0, 31, 167, 69, -11, 16, 161, 90, -11, 5, 148, 112, -9, + -3, 131, 131, -3, -9, 112, 148, 5, -11, 90, 161, 16, -11, 69, 167, 31}, + // Coefficients 6 taps + {-24, 61, 182, 61, -24, 0, -22, 41, 178, 82, -23, 0, -19, 23, 171, 104, + -20, -3, -15, 7, 160, 125, -14, -7, -11, -5, 144, 144, -5, -11, -7, -14, + 125, 160, 7, -15, -3, -20, 104, 171, 23, -19, 0, -23, 82, 178, 41, -22}, + }, + + // Band_8_1479 + { + // Scaler inc range + {1477, 1479}, + // Coefficients 4 taps + {47, 162, 47, 0, 31, 167, 69, -11, 17, 160, 90, -11, 5, 148, 111, -8, + -3, 131, 131, -3, -8, 111, 148, 5, -11, 90, 160, 17, -11, 69, 167, 31}, + // Coefficients 6 taps + {-24, 61, 182, 61, -24, 0, -22, 41, 178, 82, -23, 0, -19, 23, 171, 104, + -20, -3, -15, 7, 160, 125, -14, -7, -11, -5, 144, 144, -5, -11, -7, -14, + 125, 160, 7, -15, -3, -20, 104, 171, 23, -19, 0, -23, 82, 178, 41, -22}, + }, + + // Band_8_1481 + { + // Scaler inc range + {1479, 1481}, + // Coefficients 4 taps + {47, 162, 47, 0, 31, 167, 69, -11, 17, 160, 90, -11, 5, 148, 111, -8, + -3, 131, 131, -3, -8, 111, 148, 5, -11, 90, 160, 17, -11, 69, 167, 31}, + // Coefficients 6 taps + {-23, 61, 180, 61, -23, 0, -22, 41, 178, 82, -23, 0, -19, 23, 171, 104, + -20, -3, -15, 7, 160, 125, -14, -7, -11, -5, 144, 144, -5, -11, -7, -14, + 125, 160, 7, -15, -3, -20, 104, 171, 23, -19, 0, -23, 82, 178, 41, -22}, + }, + + // Band_8_1483 + { + // Scaler inc range + {1481, 1483}, + // Coefficients 4 taps + {47, 162, 47, 0, 32, 166, 69, -11, 17, 160, 90, -11, 5, 148, 111, -8, + -3, 131, 131, -3, -8, 111, 148, 5, -11, 90, 160, 17, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 61, 180, 61, -23, 0, -22, 41, 178, 82, -23, 0, -19, 23, 171, 104, + -20, -3, -15, 8, 159, 125, -14, -7, -11, -5, 144, 144, -5, -11, -7, -14, + 125, 159, 8, -15, -3, -20, 104, 171, 23, -19, 0, -23, 82, 178, 41, -22}, + }, + + // Band_8_1485 + { + // Scaler inc range + {1483, 1485}, + // Coefficients 4 taps + {47, 162, 47, 0, 32, 166, 69, -11, 17, 160, 90, -11, 5, 148, 111, -8, + -3, 131, 131, -3, -8, 111, 148, 5, -11, 90, 160, 17, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 61, 180, 61, -23, 0, -22, 41, 178, 82, -23, 0, -19, 23, 171, 104, + -20, -3, -15, 8, 159, 125, -14, -7, -11, -5, 144, 144, -5, -11, -7, -14, + 125, 159, 8, -15, -3, -20, 104, 171, 23, -19, 0, -23, 82, 178, 41, -22}, + }, + + // Band_8_1487 + { + // Scaler inc range + {1485, 1487}, + // Coefficients 4 taps + {47, 162, 47, 0, 32, 166, 69, -11, 17, 160, 90, -11, 6, 147, 111, -8, + -3, 131, 131, -3, -8, 111, 147, 6, -11, 90, 160, 17, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 61, 180, 61, -23, 0, -22, 41, 179, 82, -23, -1, -19, 23, 171, 104, + -20, -3, -15, 8, 159, 125, -14, -7, -11, -4, 143, 143, -4, -11, -7, -14, + 125, 159, 8, -15, -3, -20, 104, 171, 23, -19, -1, -23, 82, 179, 41, -22}, + }, + + // Band_8_1489 + { + // Scaler inc range + {1487, 1489}, + // Coefficients 4 taps + {47, 162, 47, 0, 32, 166, 69, -11, 17, 159, 90, -10, 6, 147, 111, -8, + -3, 131, 131, -3, -8, 111, 147, 6, -10, 90, 159, 17, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 61, 180, 61, -23, 0, -22, 42, 178, 82, -23, -1, -19, 24, 170, 104, + -19, -4, -15, 8, 158, 125, -13, -7, -11, -4, 143, 143, -4, -11, -7, -13, + 125, 158, 8, -15, -4, -19, 104, 170, 24, -19, -1, -23, 82, 178, 42, -22}, + }, + + // Band_8_1492 + { + // Scaler inc range + {1489, 1492}, + // Coefficients 4 taps + {47, 162, 47, 0, 32, 166, 69, -11, 17, 159, 90, -10, 6, 147, 111, -8, + -3, 131, 131, -3, -8, 111, 147, 6, -10, 90, 159, 17, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 61, 180, 61, -23, 0, -22, 42, 177, 82, -22, -1, -19, 24, 170, 104, + -19, -4, -15, 8, 158, 125, -13, -7, -11, -4, 143, 143, -4, -11, -7, -13, + 125, 158, 8, -15, -4, -19, 104, 170, 24, -19, -1, -22, 82, 177, 42, -22}, + }, + + // Band_8_1494 + { + // Scaler inc range + {1492, 1494}, + // Coefficients 4 taps + {47, 162, 47, 0, 32, 166, 69, -11, 18, 158, 90, -10, 6, 147, 111, -8, + -2, 130, 130, -2, -8, 111, 147, 6, -10, 90, 158, 18, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 42, 176, 83, -22, -1, -19, 24, 170, 104, + -19, -4, -15, 9, 157, 125, -13, -7, -11, -4, 143, 143, -4, -11, -7, -13, + 125, 157, 9, -15, -4, -19, 104, 170, 24, -19, -1, -22, 83, 176, 42, -22}, + }, + + // Band_8_1496 + { + // Scaler inc range + {1494, 1496}, + // Coefficients 4 taps + {48, 160, 48, 0, 32, 166, 69, -11, 18, 158, 90, -10, 6, 147, 111, -8, + -2, 130, 130, -2, -8, 111, 147, 6, -10, 90, 158, 18, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 42, 176, 83, -22, -1, -19, 24, 170, 104, + -19, -4, -15, 9, 157, 125, -13, -7, -11, -4, 143, 143, -4, -11, -7, -13, + 125, 157, 9, -15, -4, -19, 104, 170, 24, -19, -1, -22, 83, 176, 42, -22}, + }, + + // Band_8_1498 + { + // Scaler inc range + {1496, 1498}, + // Coefficients 4 taps + {48, 160, 48, 0, 32, 166, 69, -11, 18, 158, 90, -10, 6, 147, 111, -8, + -2, 130, 130, -2, -8, 111, 147, 6, -10, 90, 158, 18, -11, 69, 166, 32}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 42, 176, 83, -22, -1, -19, 24, 170, 104, + -19, -4, -15, 9, 158, 124, -13, -7, -11, -3, 142, 142, -3, -11, -7, -13, + 124, 158, 9, -15, -4, -19, 104, 170, 24, -19, -1, -22, 83, 176, 42, -22}, + }, + + // Band_8_1500 + { + // Scaler inc range + {1498, 1500}, + // Coefficients 4 taps + {48, 160, 48, 0, 33, 164, 69, -10, 18, 158, 90, -10, 6, 146, 111, -7, + -2, 130, 130, -2, -7, 111, 146, 6, -10, 90, 158, 18, -10, 69, 164, 33}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 42, 176, 83, -22, -1, -19, 25, 169, 104, + -19, -4, -16, 9, 160, 124, -13, -8, -12, -3, 143, 143, -3, -12, -8, -13, + 124, 160, 9, -16, -4, -19, 104, 169, 25, -19, -1, -22, 83, 176, 42, -22}, + }, + + // Band_8_1502 + { + // Scaler inc range + {1500, 1502}, + // Coefficients 4 taps + {48, 160, 48, 0, 33, 164, 69, -10, 18, 158, 90, -10, 7, 145, 111, -7, + -2, 130, 130, -2, -7, 111, 145, 7, -10, 90, 158, 18, -10, 69, 164, 33}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 42, 176, 83, -22, -1, -19, 25, 169, 104, + -19, -4, -16, 9, 159, 124, -12, -8, -12, -3, 143, 143, -3, -12, -8, -12, + 124, 159, 9, -16, -4, -19, 104, 169, 25, -19, -1, -22, 83, 176, 42, -22}, + }, + + // Band_8_1504 + { + // Scaler inc range + {1502, 1504}, + // Coefficients 4 taps + {48, 160, 48, 0, 33, 164, 69, -10, 18, 158, 90, -10, 7, 145, 111, -7, + -2, 130, 130, -2, -7, 111, 145, 7, -10, 90, 158, 18, -10, 69, 164, 33}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 43, 175, 83, -22, -1, -19, 25, 168, 104, + -18, -4, -16, 10, 158, 124, -12, -8, -12, -3, 143, 143, -3, -12, -8, -12, + 124, 158, 10, -16, -4, -18, 104, 168, 25, -19, -1, -22, 83, 175, 43, -22}, + }, + + // Band_8_1507 + { + // Scaler inc range + {1504, 1507}, + // Coefficients 4 taps + {48, 160, 48, 0, 33, 164, 69, -10, 18, 158, 90, -10, 7, 145, 111, -7, + -2, 130, 130, -2, -7, 111, 145, 7, -10, 90, 158, 18, -10, 69, 164, 33}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 43, 175, 83, -22, -1, -19, 25, 168, 104, + -18, -4, -16, 10, 158, 124, -12, -8, -12, -3, 143, 143, -3, -12, -8, -12, + 124, 158, 10, -16, -4, -18, 104, 168, 25, -19, -1, -22, 83, 175, 43, -22}, + }, + + // Band_8_1509 + { + // Scaler inc range + {1507, 1509}, + // Coefficients 4 taps + {48, 160, 48, 0, 33, 164, 69, -10, 19, 157, 90, -10, 7, 145, 111, -7, + -2, 130, 130, -2, -7, 111, 145, 7, -10, 90, 157, 19, -10, 69, 164, 33}, + // Coefficients 6 taps + {-23, 62, 178, 62, -23, 0, -22, 43, 175, 83, -22, -1, -19, 25, 168, 104, + -18, -4, -16, 10, 158, 124, -12, -8, -12, -2, 142, 142, -2, -12, -8, -12, + 124, 158, 10, -16, -4, -18, 104, 168, 25, -19, -1, -22, 83, 175, 43, -22}, + }, + + // Band_8_1511 + { + // Scaler inc range + {1509, 1511}, + // Coefficients 4 taps + {48, 160, 48, 0, 33, 164, 69, -10, 19, 157, 90, -10, 7, 145, 111, -7, + -1, 129, 129, -1, -7, 111, 145, 7, -10, 90, 157, 19, -10, 69, 164, 33}, + // Coefficients 6 taps + {-22, 62, 176, 62, -22, 0, -22, 43, 174, 83, -21, -1, -19, 26, 167, 104, + -18, -4, -16, 10, 158, 124, -12, -8, -12, -2, 142, 142, -2, -12, -8, -12, + 124, 158, 10, -16, -4, -18, 104, 167, 26, -19, -1, -21, 83, 174, 43, -22}, + }, + + // Band_8_1513 + { + // Scaler inc range + {1511, 1513}, + // Coefficients 4 taps + {48, 160, 48, 0, 33, 163, 70, -10, 19, 157, 90, -10, 7, 146, 110, -7, + -1, 129, 129, -1, -7, 110, 146, 7, -10, 90, 157, 19, -10, 70, 163, 33}, + // Coefficients 6 taps + {-22, 62, 176, 62, -22, 0, -22, 43, 175, 83, -21, -2, -19, 26, 167, 104, + -18, -4, -16, 10, 157, 124, -11, -8, -12, -2, 142, 142, -2, -12, -8, -11, + 124, 157, 10, -16, -4, -18, 104, 167, 26, -19, -2, -21, 83, 175, 43, -22}, + }, + + // Band_8_1515 + { + // Scaler inc range + {1513, 1515}, + // Coefficients 4 taps + {49, 158, 49, 0, 33, 163, 70, -10, 19, 156, 90, -9, 7, 146, 110, -7, + -1, 129, 129, -1, -7, 110, 146, 7, -9, 90, 156, 19, -10, 70, 163, 33}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 43, 174, 83, -21, -2, -19, 26, 168, 104, + -18, -5, -16, 11, 156, 124, -11, -8, -12, -2, 142, 142, -2, -12, -8, -11, + 124, 156, 11, -16, -5, -18, 104, 168, 26, -19, -2, -21, 83, 174, 43, -21}, + }, + + // Band_8_1517 + { + // Scaler inc range + {1515, 1517}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 19, 156, 90, -9, 8, 145, 110, -7, + -1, 129, 129, -1, -7, 110, 145, 8, -9, 90, 156, 19, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 44, 173, 83, -21, -2, -19, 26, 168, 104, + -18, -5, -16, 11, 156, 124, -11, -8, -12, -2, 142, 142, -2, -12, -8, -11, + 124, 156, 11, -16, -5, -18, 104, 168, 26, -19, -2, -21, 83, 173, 44, -21}, + }, + + // Band_8_1520 + { + // Scaler inc range + {1517, 1520}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 19, 156, 90, -9, 8, 144, 110, -6, + -1, 129, 129, -1, -6, 110, 144, 8, -9, 90, 156, 19, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 44, 173, 83, -21, -2, -19, 26, 167, 104, + -17, -5, -16, 11, 156, 124, -11, -8, -12, -1, 141, 141, -1, -12, -8, -11, + 124, 156, 11, -16, -5, -17, 104, 167, 26, -19, -2, -21, 83, 173, 44, -21}, + }, + + // Band_8_1522 + { + // Scaler inc range + {1520, 1522}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 19, 156, 90, -9, 8, 144, 110, -6, + -1, 129, 129, -1, -6, 110, 144, 8, -9, 90, 156, 19, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 44, 173, 83, -21, -2, -19, 26, 167, 104, + -17, -5, -16, 11, 156, 124, -11, -8, -12, -1, 141, 141, -1, -12, -8, -11, + 124, 156, 11, -16, -5, -17, 104, 167, 26, -19, -2, -21, 83, 173, 44, -21}, + }, + + // Band_8_1524 + { + // Scaler inc range + {1522, 1524}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 20, 155, 90, -9, 8, 144, 110, -6, + -1, 129, 129, -1, -6, 110, 144, 8, -9, 90, 155, 20, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 44, 173, 83, -21, -2, -19, 27, 166, 104, + -17, -5, -16, 11, 156, 124, -11, -8, -12, -1, 141, 141, -1, -12, -8, -11, + 124, 156, 11, -16, -5, -17, 104, 166, 27, -19, -2, -21, 83, 173, 44, -21}, + }, + + // Band_8_1526 + { + // Scaler inc range + {1524, 1526}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 20, 155, 90, -9, 8, 144, 110, -6, + -1, 129, 129, -1, -6, 110, 144, 8, -9, 90, 155, 20, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 44, 173, 83, -21, -2, -19, 27, 166, 104, + -17, -5, -16, 12, 154, 124, -10, -8, -12, -1, 141, 141, -1, -12, -8, -10, + 124, 154, 12, -16, -5, -17, 104, 166, 27, -19, -2, -21, 83, 173, 44, -21}, + }, + + // Band_8_1529 + { + // Scaler inc range + {1526, 1529}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 20, 155, 90, -9, 8, 144, 110, -6, + 0, 128, 128, 0, -6, 110, 144, 8, -9, 90, 155, 20, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 44, 173, 83, -21, -2, -19, 27, 166, 104, + -17, -5, -16, 12, 156, 123, -10, -9, -12, -1, 141, 141, -1, -12, -9, -10, + 123, 156, 12, -16, -5, -17, 104, 166, 27, -19, -2, -21, 83, 173, 44, -21}, + }, + + // Band_8_1531 + { + // Scaler inc range + {1529, 1531}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 20, 155, 90, -9, 8, 144, 110, -6, + 0, 128, 128, 0, -6, 110, 144, 8, -9, 90, 155, 20, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 44, 172, 83, -20, -2, -19, 27, 166, 104, + -17, -5, -16, 12, 156, 123, -10, -9, -12, 0, 140, 140, 0, -12, -9, -10, + 123, 156, 12, -16, -5, -17, 104, 166, 27, -19, -2, -20, 83, 172, 44, -21}, + }, + + // Band_8_1533 + { + // Scaler inc range + {1531, 1533}, + // Coefficients 4 taps + {49, 158, 49, 0, 34, 162, 70, -10, 20, 155, 90, -9, 8, 144, 110, -6, + 0, 128, 128, 0, -6, 110, 144, 8, -9, 90, 155, 20, -10, 70, 162, 34}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 45, 170, 84, -20, -2, -19, 27, 165, 104, + -16, -5, -16, 12, 156, 123, -10, -9, -12, 0, 140, 140, 0, -12, -9, -10, + 123, 156, 12, -16, -5, -16, 104, 165, 27, -19, -2, -20, 84, 170, 45, -21}, + }, + + // Band_8_1535 + { + // Scaler inc range + {1533, 1535}, + // Coefficients 4 taps + {49, 158, 49, 0, 35, 161, 70, -10, 20, 155, 90, -9, 9, 143, 110, -6, + 0, 128, 128, 0, -6, 110, 143, 9, -9, 90, 155, 20, -10, 70, 161, 35}, + // Coefficients 6 taps + {-22, 63, 174, 63, -22, 0, -21, 45, 170, 84, -20, -2, -19, 28, 164, 104, + -16, -5, -16, 12, 156, 123, -10, -9, -12, 0, 140, 140, 0, -12, -9, -10, + 123, 156, 12, -16, -5, -16, 104, 164, 28, -19, -2, -20, 84, 170, 45, -21}, + }, + + // Band_8_1538 + { + // Scaler inc range + {1535, 1538}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 161, 70, -10, 20, 155, 90, -9, 9, 143, 110, -6, + 0, 128, 128, 0, -6, 110, 143, 9, -9, 90, 155, 20, -10, 70, 161, 35}, + // Coefficients 6 taps + {-21, 63, 172, 63, -21, 0, -21, 45, 170, 84, -20, -2, -19, 28, 164, 104, + -16, -5, -16, 13, 154, 123, -9, -9, -13, 0, 141, 141, 0, -13, -9, -9, + 123, 154, 13, -16, -5, -16, 104, 164, 28, -19, -2, -20, 84, 170, 45, -21}, + }, + + // Band_8_1540 + { + // Scaler inc range + {1538, 1540}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 161, 70, -10, 20, 155, 90, -9, 9, 143, 110, -6, + 0, 128, 128, 0, -6, 110, 143, 9, -9, 90, 155, 20, -10, 70, 161, 35}, + // Coefficients 6 taps + {-21, 63, 172, 63, -21, 0, -21, 45, 170, 84, -20, -2, -19, 28, 164, 104, + -16, -5, -16, 13, 154, 123, -9, -9, -13, 0, 141, 141, 0, -13, -9, -9, + 123, 154, 13, -16, -5, -16, 104, 164, 28, -19, -2, -20, 84, 170, 45, -21}, + }, + + // Band_8_1542 + { + // Scaler inc range + {1540, 1542}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 160, 70, -9, 21, 154, 90, -9, 9, 142, 110, -5, + 0, 128, 128, 0, -5, 110, 142, 9, -9, 90, 154, 21, -9, 70, 160, 35}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 45, 170, 84, -20, -2, -19, 28, 164, 104, + -16, -5, -16, 13, 154, 123, -9, -9, -13, 1, 140, 140, 1, -13, -9, -9, + 123, 154, 13, -16, -5, -16, 104, 164, 28, -19, -2, -20, 84, 170, 45, -21}, + }, + + // Band_8_1544 + { + // Scaler inc range + {1542, 1544}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 160, 70, -9, 21, 153, 90, -8, 9, 142, 110, -5, + 0, 128, 128, 0, -5, 110, 142, 9, -8, 90, 153, 21, -9, 70, 160, 35}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 45, 171, 84, -20, -3, -19, 28, 165, 104, + -16, -6, -16, 13, 154, 123, -9, -9, -13, 1, 140, 140, 1, -13, -9, -9, + 123, 154, 13, -16, -6, -16, 104, 165, 28, -19, -3, -20, 84, 171, 45, -21}, + }, + + // Band_8_1547 + { + // Scaler inc range + {1544, 1547}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 160, 70, -9, 21, 153, 90, -8, 9, 142, 110, -5, + 1, 127, 127, 1, -5, 110, 142, 9, -8, 90, 153, 21, -9, 70, 160, 35}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 45, 171, 84, -20, -3, -19, 28, 165, 104, + -16, -6, -16, 13, 154, 123, -9, -9, -13, 1, 140, 140, 1, -13, -9, -9, + 123, 154, 13, -16, -6, -16, 104, 165, 28, -19, -3, -20, 84, 171, 45, -21}, + }, + + // Band_8_1549 + { + // Scaler inc range + {1547, 1549}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 160, 70, -9, 21, 153, 90, -8, 9, 143, 109, -5, + 1, 127, 127, 1, -5, 109, 143, 9, -8, 90, 153, 21, -9, 70, 160, 35}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 46, 169, 84, -19, -3, -19, 29, 163, 104, + -15, -6, -16, 14, 153, 123, -9, -9, -13, 1, 140, 140, 1, -13, -9, -9, + 123, 153, 14, -16, -6, -15, 104, 163, 29, -19, -3, -19, 84, 169, 46, -21}, + }, + + // Band_8_1551 + { + // Scaler inc range + {1549, 1551}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 160, 70, -9, 21, 153, 90, -8, 10, 142, 109, -5, + 1, 127, 127, 1, -5, 109, 142, 10, -8, 90, 153, 21, -9, 70, 160, 35}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 46, 169, 84, -19, -3, -19, 29, 163, 104, + -15, -6, -16, 14, 152, 123, -8, -9, -13, 1, 140, 140, 1, -13, -9, -8, + 123, 152, 14, -16, -6, -15, 104, 163, 29, -19, -3, -19, 84, 169, 46, -21}, + }, + + // Band_8_1553 + { + // Scaler inc range + {1551, 1553}, + // Coefficients 4 taps + {50, 156, 50, 0, 35, 160, 70, -9, 21, 153, 90, -8, 10, 142, 109, -5, + 1, 127, 127, 1, -5, 109, 142, 10, -8, 90, 153, 21, -9, 70, 160, 35}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 46, 169, 84, -19, -3, -19, 29, 163, 104, + -15, -6, -16, 14, 152, 123, -8, -9, -13, 1, 140, 140, 1, -13, -9, -8, + 123, 152, 14, -16, -6, -15, 104, 163, 29, -19, -3, -19, 84, 169, 46, -21}, + }, + + // Band_8_1556 + { + // Scaler inc range + {1553, 1556}, + // Coefficients 4 taps + {50, 156, 50, 0, 36, 158, 71, -9, 21, 153, 90, -8, 10, 142, 109, -5, + 1, 127, 127, 1, -5, 109, 142, 10, -8, 90, 153, 21, -9, 71, 158, 36}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 46, 169, 84, -19, -3, -19, 29, 163, 104, + -15, -6, -16, 14, 152, 123, -8, -9, -13, 2, 139, 139, 2, -13, -9, -8, + 123, 152, 14, -16, -6, -15, 104, 163, 29, -19, -3, -19, 84, 169, 46, -21}, + }, + + // Band_8_1558 + { + // Scaler inc range + {1556, 1558}, + // Coefficients 4 taps + {50, 156, 50, 0, 36, 158, 71, -9, 22, 152, 90, -8, 10, 142, 109, -5, + 1, 127, 127, 1, -5, 109, 142, 10, -8, 90, 152, 22, -9, 71, 158, 36}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 46, 169, 84, -19, -3, -19, 29, 163, 104, + -15, -6, -16, 14, 153, 122, -8, -9, -13, 2, 139, 139, 2, -13, -9, -8, + 122, 153, 14, -16, -6, -15, 104, 163, 29, -19, -3, -19, 84, 169, 46, -21}, + }, + + // Band_8_1560 + { + // Scaler inc range + {1558, 1560}, + // Coefficients 4 taps + {50, 156, 50, 0, 36, 158, 71, -9, 22, 152, 90, -8, 10, 142, 109, -5, + 1, 127, 127, 1, -5, 109, 142, 10, -8, 90, 152, 22, -9, 71, 158, 36}, + // Coefficients 6 taps + {-21, 64, 170, 64, -21, 0, -21, 46, 169, 84, -19, -3, -19, 29, 163, 104, + -15, -6, -16, 15, 152, 122, -8, -9, -13, 2, 139, 139, 2, -13, -9, -8, + 122, 152, 15, -16, -6, -15, 104, 163, 29, -19, -3, -19, 84, 169, 46, -21}, + }, + + // Band_8_1563 + { + // Scaler inc range + {1560, 1563}, + // Coefficients 4 taps + {51, 154, 51, 0, 36, 158, 71, -9, 22, 152, 90, -8, 10, 141, 109, -4, + 1, 127, 127, 1, -4, 109, 141, 10, -8, 90, 152, 22, -9, 71, 158, 36}, + // Coefficients 6 taps + {-20, 64, 168, 64, -20, 0, -21, 46, 169, 84, -19, -3, -19, 30, 161, 104, + -14, -6, -16, 15, 153, 122, -8, -10, -13, 2, 139, 139, 2, -13, -10, -8, + 122, 153, 15, -16, -6, -14, 104, 161, 30, -19, -3, -19, 84, 169, 46, -21}, + }, + + // Band_8_1565 + { + // Scaler inc range + {1563, 1565}, + // Coefficients 4 taps + {51, 154, 51, 0, 36, 158, 71, -9, 22, 152, 90, -8, 10, 141, 109, -4, + 2, 126, 126, 2, -4, 109, 141, 10, -8, 90, 152, 22, -9, 71, 158, 36}, + // Coefficients 6 taps + {-20, 64, 168, 64, -20, 0, -21, 47, 168, 84, -19, -3, -19, 30, 161, 104, + -14, -6, -16, 15, 152, 122, -7, -10, -13, 2, 139, 139, 2, -13, -10, -7, + 122, 152, 15, -16, -6, -14, 104, 161, 30, -19, -3, -19, 84, 168, 47, -21}, + }, + + // Band_8_1567 + { + // Scaler inc range + {1565, 1567}, + // Coefficients 4 taps + {51, 154, 51, 0, 36, 158, 71, -9, 22, 152, 90, -8, 10, 141, 109, -4, + 2, 126, 126, 2, -4, 109, 141, 10, -8, 90, 152, 22, -9, 71, 158, 36}, + // Coefficients 6 taps + {-20, 64, 168, 64, -20, 0, -20, 47, 166, 84, -18, -3, -19, 30, 161, 104, + -14, -6, -16, 15, 152, 122, -7, -10, -13, 3, 138, 138, 3, -13, -10, -7, + 122, 152, 15, -16, -6, -14, 104, 161, 30, -19, -3, -18, 84, 166, 47, -20}, + }, + + // Band_8_1570 + { + // Scaler inc range + {1567, 1570}, + // Coefficients 4 taps + {51, 154, 51, 0, 36, 158, 71, -9, 22, 152, 90, -8, 11, 140, 109, -4, + 2, 126, 126, 2, -4, 109, 140, 11, -8, 90, 152, 22, -9, 71, 158, 36}, + // Coefficients 6 taps + {-20, 64, 168, 64, -20, 0, -20, 47, 166, 84, -18, -3, -19, 30, 161, 104, + -14, -6, -16, 15, 152, 122, -7, -10, -13, 3, 138, 138, 3, -13, -10, -7, + 122, 152, 15, -16, -6, -14, 104, 161, 30, -19, -3, -18, 84, 166, 47, -20}, + }, + + // Band_8_1572 + { + // Scaler inc range + {1570, 1572}, + // Coefficients 4 taps + {51, 154, 51, 0, 36, 158, 71, -9, 22, 151, 90, -7, 11, 140, 109, -4, + 2, 126, 126, 2, -4, 109, 140, 11, -7, 90, 151, 22, -9, 71, 158, 36}, + // Coefficients 6 taps + {-20, 65, 166, 65, -20, 0, -20, 47, 166, 84, -18, -3, -19, 30, 161, 104, + -14, -6, -16, 16, 151, 122, -7, -10, -13, 3, 138, 138, 3, -13, -10, -7, + 122, 151, 16, -16, -6, -14, 104, 161, 30, -19, -3, -18, 84, 166, 47, -20}, + }, + + // Band_8_1574 + { + // Scaler inc range + {1572, 1574}, + // Coefficients 4 taps + {51, 154, 51, 0, 37, 157, 71, -9, 22, 151, 90, -7, 11, 140, 109, -4, + 2, 126, 126, 2, -4, 109, 140, 11, -7, 90, 151, 22, -9, 71, 157, 37}, + // Coefficients 6 taps + {-20, 65, 166, 65, -20, 0, -20, 47, 167, 84, -18, -4, -19, 31, 160, 104, + -14, -6, -17, 16, 152, 122, -7, -10, -13, 3, 138, 138, 3, -13, -10, -7, + 122, 152, 16, -17, -6, -14, 104, 160, 31, -19, -4, -18, 84, 167, 47, -20}, + }, + + // Band_8_1577 + { + // Scaler inc range + {1574, 1577}, + // Coefficients 4 taps + {51, 154, 51, 0, 37, 157, 71, -9, 23, 150, 90, -7, 11, 140, 109, -4, + 2, 126, 126, 2, -4, 109, 140, 11, -7, 90, 150, 23, -9, 71, 157, 37}, + // Coefficients 6 taps + {-20, 65, 166, 65, -20, 0, -20, 47, 167, 84, -18, -4, -19, 31, 161, 103, + -13, -7, -17, 16, 151, 122, -6, -10, -13, 3, 138, 138, 3, -13, -10, -6, + 122, 151, 16, -17, -7, -13, 103, 161, 31, -19, -4, -18, 84, 167, 47, -20}, + }, + + // Band_8_1579 + { + // Scaler inc range + {1577, 1579}, + // Coefficients 4 taps + {51, 154, 51, 0, 37, 157, 71, -9, 23, 150, 90, -7, 11, 140, 109, -4, + 2, 126, 126, 2, -4, 109, 140, 11, -7, 90, 150, 23, -9, 71, 157, 37}, + // Coefficients 6 taps + {-20, 65, 166, 65, -20, 0, -20, 47, 167, 84, -18, -4, -19, 31, 161, 103, + -13, -7, -17, 16, 151, 122, -6, -10, -13, 4, 137, 137, 4, -13, -10, -6, + 122, 151, 16, -17, -7, -13, 103, 161, 31, -19, -4, -18, 84, 167, 47, -20}, + }, + + // Band_8_1582 + { + // Scaler inc range + {1579, 1582}, + // Coefficients 4 taps + {51, 154, 51, 0, 37, 156, 71, -8, 23, 150, 90, -7, 11, 140, 109, -4, + 2, 126, 126, 2, -4, 109, 140, 11, -7, 90, 150, 23, -8, 71, 156, 37}, + // Coefficients 6 taps + {-20, 65, 166, 65, -20, 0, -20, 48, 166, 84, -18, -4, -19, 31, 161, 103, + -13, -7, -17, 16, 151, 122, -6, -10, -13, 4, 137, 137, 4, -13, -10, -6, + 122, 151, 16, -17, -7, -13, 103, 161, 31, -19, -4, -18, 84, 166, 48, -20}, + }, + + // Band_8_1584 + { + // Scaler inc range + {1582, 1584}, + // Coefficients 4 taps + {51, 154, 51, 0, 37, 156, 71, -8, 23, 150, 90, -7, 11, 140, 108, -3, + 3, 125, 125, 3, -3, 108, 140, 11, -7, 90, 150, 23, -8, 71, 156, 37}, + // Coefficients 6 taps + {-20, 65, 166, 65, -20, 0, -20, 48, 166, 84, -18, -4, -19, 31, 161, 103, + -13, -7, -17, 16, 152, 121, -6, -10, -13, 4, 137, 137, 4, -13, -10, -6, + 121, 152, 16, -17, -7, -13, 103, 161, 31, -19, -4, -18, 84, 166, 48, -20}, + }, + + // Band_8_1586 + { + // Scaler inc range + {1584, 1586}, + // Coefficients 4 taps + {52, 152, 52, 0, 37, 156, 71, -8, 23, 150, 90, -7, 12, 139, 108, -3, + 3, 125, 125, 3, -3, 108, 139, 12, -7, 90, 150, 23, -8, 71, 156, 37}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 48, 165, 84, -17, -4, -19, 31, 161, 103, + -13, -7, -17, 17, 151, 121, -6, -10, -13, 4, 137, 137, 4, -13, -10, -6, + 121, 151, 17, -17, -7, -13, 103, 161, 31, -19, -4, -17, 84, 165, 48, -20}, + }, + + // Band_8_1589 + { + // Scaler inc range + {1586, 1589}, + // Coefficients 4 taps + {52, 152, 52, 0, 37, 156, 71, -8, 23, 150, 90, -7, 12, 139, 108, -3, + 3, 125, 125, 3, -3, 108, 139, 12, -7, 90, 150, 23, -8, 71, 156, 37}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 48, 165, 84, -17, -4, -19, 32, 160, 103, + -13, -7, -17, 17, 150, 121, -5, -10, -14, 4, 138, 138, 4, -14, -10, -5, + 121, 150, 17, -17, -7, -13, 103, 160, 32, -19, -4, -17, 84, 165, 48, -20}, + }, + + // Band_8_1591 + { + // Scaler inc range + {1589, 1591}, + // Coefficients 4 taps + {52, 152, 52, 0, 37, 156, 71, -8, 23, 150, 90, -7, 12, 139, 108, -3, + 3, 125, 125, 3, -3, 108, 139, 12, -7, 90, 150, 23, -8, 71, 156, 37}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 48, 165, 84, -17, -4, -19, 32, 160, 103, + -13, -7, -17, 17, 150, 121, -5, -10, -14, 5, 137, 137, 5, -14, -10, -5, + 121, 150, 17, -17, -7, -13, 103, 160, 32, -19, -4, -17, 84, 165, 48, -20}, + }, + + // Band_8_1594 + { + // Scaler inc range + {1591, 1594}, + // Coefficients 4 taps + {52, 152, 52, 0, 37, 156, 71, -8, 23, 150, 90, -7, 12, 139, 108, -3, + 3, 125, 125, 3, -3, 108, 139, 12, -7, 90, 150, 23, -8, 71, 156, 37}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 48, 165, 84, -17, -4, -19, 32, 159, 103, + -12, -7, -17, 17, 150, 121, -5, -10, -14, 5, 137, 137, 5, -14, -10, -5, + 121, 150, 17, -17, -7, -12, 103, 159, 32, -19, -4, -17, 84, 165, 48, -20}, + }, + + // Band_8_1596 + { + // Scaler inc range + {1594, 1596}, + // Coefficients 4 taps + {52, 152, 52, 0, 38, 155, 71, -8, 24, 149, 90, -7, 12, 139, 108, -3, + 3, 125, 125, 3, -3, 108, 139, 12, -7, 90, 149, 24, -8, 71, 155, 38}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 48, 165, 84, -17, -4, -19, 32, 159, 103, + -12, -7, -17, 17, 150, 121, -5, -10, -14, 5, 137, 137, 5, -14, -10, -5, + 121, 150, 17, -17, -7, -12, 103, 159, 32, -19, -4, -17, 84, 165, 48, -20}, + }, + + // Band_8_1598 + { + // Scaler inc range + {1596, 1598}, + // Coefficients 4 taps + {52, 152, 52, 0, 38, 155, 71, -8, 24, 148, 90, -6, 12, 139, 108, -3, + 3, 125, 125, 3, -3, 108, 139, 12, -6, 90, 148, 24, -8, 71, 155, 38}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 48, 165, 84, -17, -4, -19, 32, 159, 103, + -12, -7, -17, 18, 149, 121, -5, -10, -14, 5, 137, 137, 5, -14, -10, -5, + 121, 149, 18, -17, -7, -12, 103, 159, 32, -19, -4, -17, 84, 165, 48, -20}, + }, + + // Band_8_1601 + { + // Scaler inc range + {1598, 1601}, + // Coefficients 4 taps + {52, 152, 52, 0, 38, 155, 71, -8, 24, 148, 90, -6, 12, 139, 108, -3, + 3, 125, 125, 3, -3, 108, 139, 12, -6, 90, 148, 24, -8, 71, 155, 38}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 49, 164, 84, -17, -4, -19, 32, 159, 103, + -12, -7, -17, 18, 149, 121, -5, -10, -14, 5, 137, 137, 5, -14, -10, -5, + 121, 149, 18, -17, -7, -12, 103, 159, 32, -19, -4, -17, 84, 164, 49, -20}, + }, + + // Band_8_1603 + { + // Scaler inc range + {1601, 1603}, + // Coefficients 4 taps + {52, 152, 52, 0, 38, 155, 71, -8, 24, 148, 90, -6, 12, 139, 108, -3, + 4, 124, 124, 4, -3, 108, 139, 12, -6, 90, 148, 24, -8, 71, 155, 38}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 49, 162, 85, -16, -4, -19, 33, 158, 103, + -12, -7, -17, 18, 148, 121, -4, -10, -14, 6, 136, 136, 6, -14, -10, -4, + 121, 148, 18, -17, -7, -12, 103, 158, 33, -19, -4, -16, 85, 162, 49, -20}, + }, + + // Band_8_1606 + { + // Scaler inc range + {1603, 1606}, + // Coefficients 4 taps + {52, 152, 52, 0, 38, 155, 71, -8, 24, 148, 90, -6, 13, 137, 108, -2, + 4, 124, 124, 4, -2, 108, 137, 13, -6, 90, 148, 24, -8, 71, 155, 38}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -20, 49, 162, 85, -16, -4, -19, 33, 158, 103, + -12, -7, -17, 18, 149, 121, -4, -11, -14, 6, 136, 136, 6, -14, -11, -4, + 121, 149, 18, -17, -7, -12, 103, 158, 33, -19, -4, -16, 85, 162, 49, -20}, + }, + + // Band_8_1608 + { + // Scaler inc range + {1606, 1608}, + // Coefficients 4 taps + {52, 152, 52, 0, 38, 154, 72, -8, 24, 148, 90, -6, 13, 137, 108, -2, + 4, 124, 124, 4, -2, 108, 137, 13, -6, 90, 148, 24, -8, 72, 154, 38}, + // Coefficients 6 taps + {-19, 65, 164, 65, -19, 0, -19, 49, 161, 85, -16, -4, -19, 33, 157, 103, + -11, -7, -17, 18, 150, 120, -4, -11, -14, 6, 136, 136, 6, -14, -11, -4, + 120, 150, 18, -17, -7, -11, 103, 157, 33, -19, -4, -16, 85, 161, 49, -19}, + }, + + // Band_8_1611 + { + // Scaler inc range + {1608, 1611}, + // Coefficients 4 taps + {52, 152, 52, 0, 38, 154, 72, -8, 24, 148, 90, -6, 13, 137, 108, -2, + 4, 124, 124, 4, -2, 108, 137, 13, -6, 90, 148, 24, -8, 72, 154, 38}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 49, 162, 85, -16, -5, -19, 33, 157, 103, + -11, -7, -17, 19, 149, 120, -4, -11, -14, 6, 136, 136, 6, -14, -11, -4, + 120, 149, 19, -17, -7, -11, 103, 157, 33, -19, -5, -16, 85, 162, 49, -19}, + }, + + // Band_8_1613 + { + // Scaler inc range + {1611, 1613}, + // Coefficients 4 taps + {53, 150, 53, 0, 38, 154, 72, -8, 24, 148, 90, -6, 13, 137, 108, -2, + 4, 124, 124, 4, -2, 108, 137, 13, -6, 90, 148, 24, -8, 72, 154, 38}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 49, 162, 85, -16, -5, -19, 33, 158, 103, + -11, -8, -17, 19, 149, 120, -4, -11, -14, 6, 136, 136, 6, -14, -11, -4, + 120, 149, 19, -17, -8, -11, 103, 158, 33, -19, -5, -16, 85, 162, 49, -19}, + }, + + // Band_8_1616 + { + // Scaler inc range + {1613, 1616}, + // Coefficients 4 taps + {53, 150, 53, 0, 38, 154, 72, -8, 25, 147, 90, -6, 13, 137, 108, -2, + 4, 124, 124, 4, -2, 108, 137, 13, -6, 90, 147, 25, -8, 72, 154, 38}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 49, 162, 85, -16, -5, -19, 33, 158, 103, + -11, -8, -17, 19, 148, 120, -3, -11, -14, 7, 135, 135, 7, -14, -11, -3, + 120, 148, 19, -17, -8, -11, 103, 158, 33, -19, -5, -16, 85, 162, 49, -19}, + }, + + // Band_8_1618 + { + // Scaler inc range + {1616, 1618}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 153, 72, -8, 25, 147, 90, -6, 13, 138, 107, -2, + 4, 124, 124, 4, -2, 107, 138, 13, -6, 90, 147, 25, -8, 72, 153, 39}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 49, 162, 85, -16, -5, -19, 33, 158, 103, + -11, -8, -17, 19, 148, 120, -3, -11, -14, 7, 135, 135, 7, -14, -11, -3, + 120, 148, 19, -17, -8, -11, 103, 158, 33, -19, -5, -16, 85, 162, 49, -19}, + }, + + // Band_8_1621 + { + // Scaler inc range + {1618, 1621}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 25, 147, 90, -6, 13, 138, 107, -2, + 4, 124, 124, 4, -2, 107, 138, 13, -6, 90, 147, 25, -7, 72, 152, 39}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 50, 160, 85, -15, -5, -18, 34, 156, 103, + -11, -8, -17, 19, 148, 120, -3, -11, -14, 7, 135, 135, 7, -14, -11, -3, + 120, 148, 19, -17, -8, -11, 103, 156, 34, -18, -5, -15, 85, 160, 50, -19}, + }, + + // Band_8_1623 + { + // Scaler inc range + {1621, 1623}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 25, 147, 90, -6, 13, 138, 107, -2, + 5, 123, 123, 5, -2, 107, 138, 13, -6, 90, 147, 25, -7, 72, 152, 39}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 50, 160, 85, -15, -5, -18, 34, 155, 103, + -10, -8, -17, 19, 148, 120, -3, -11, -14, 7, 135, 135, 7, -14, -11, -3, + 120, 148, 19, -17, -8, -10, 103, 155, 34, -18, -5, -15, 85, 160, 50, -19}, + }, + + // Band_8_1626 + { + // Scaler inc range + {1623, 1626}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 25, 147, 90, -6, 14, 137, 107, -2, + 5, 123, 123, 5, -2, 107, 137, 14, -6, 90, 147, 25, -7, 72, 152, 39}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 50, 160, 85, -15, -5, -18, 34, 155, 103, + -10, -8, -17, 20, 147, 120, -3, -11, -14, 7, 135, 135, 7, -14, -11, -3, + 120, 147, 20, -17, -8, -10, 103, 155, 34, -18, -5, -15, 85, 160, 50, -19}, + }, + + // Band_8_1628 + { + // Scaler inc range + {1626, 1628}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 25, 146, 90, -5, 14, 137, 107, -2, + 5, 123, 123, 5, -2, 107, 137, 14, -5, 90, 146, 25, -7, 72, 152, 39}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 50, 160, 85, -15, -5, -18, 34, 155, 103, + -10, -8, -17, 20, 147, 120, -3, -11, -14, 7, 135, 135, 7, -14, -11, -3, + 120, 147, 20, -17, -8, -10, 103, 155, 34, -18, -5, -15, 85, 160, 50, -19}, + }, + + // Band_8_1631 + { + // Scaler inc range + {1628, 1631}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 25, 146, 90, -5, 14, 136, 107, -1, + 5, 123, 123, 5, -1, 107, 136, 14, -5, 90, 146, 25, -7, 72, 152, 39}, + // Coefficients 6 taps + {-18, 66, 160, 66, -18, 0, -19, 50, 160, 85, -15, -5, -18, 34, 155, 103, + -10, -8, -17, 20, 147, 119, -2, -11, -14, 8, 134, 134, 8, -14, -11, -2, + 119, 147, 20, -17, -8, -10, 103, 155, 34, -18, -5, -15, 85, 160, 50, -19}, + }, + + // Band_8_1633 + { + // Scaler inc range + {1631, 1633}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 25, 146, 90, -5, 14, 136, 107, -1, + 5, 123, 123, 5, -1, 107, 136, 14, -5, 90, 146, 25, -7, 72, 152, 39}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -19, 50, 160, 85, -15, -5, -18, 34, 155, 103, + -10, -8, -17, 20, 147, 119, -2, -11, -14, 8, 134, 134, 8, -14, -11, -2, + 119, 147, 20, -17, -8, -10, 103, 155, 34, -18, -5, -15, 85, 160, 50, -19}, + }, + + // Band_8_1636 + { + // Scaler inc range + {1633, 1636}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 26, 145, 90, -5, 14, 136, 107, -1, + 5, 123, 123, 5, -1, 107, 136, 14, -5, 90, 145, 26, -7, 72, 152, 39}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -19, 50, 160, 85, -15, -5, -18, 35, 154, 103, + -10, -8, -17, 20, 147, 119, -2, -11, -14, 8, 134, 134, 8, -14, -11, -2, + 119, 147, 20, -17, -8, -10, 103, 154, 35, -18, -5, -15, 85, 160, 50, -19}, + }, + + // Band_8_1638 + { + // Scaler inc range + {1636, 1638}, + // Coefficients 4 taps + {53, 150, 53, 0, 39, 152, 72, -7, 26, 145, 90, -5, 14, 136, 107, -1, + 5, 123, 123, 5, -1, 107, 136, 14, -5, 90, 145, 26, -7, 72, 152, 39}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -19, 50, 159, 85, -14, -5, -18, 35, 154, 102, + -9, -8, -17, 20, 147, 119, -2, -11, -14, 8, 134, 134, 8, -14, -11, -2, + 119, 147, 20, -17, -8, -9, 102, 154, 35, -18, -5, -14, 85, 159, 50, -19}, + }, + + // Band_8_1641 + { + // Scaler inc range + {1638, 1641}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 151, 72, -7, 26, 145, 90, -5, 14, 136, 107, -1, + 5, 123, 123, 5, -1, 107, 136, 14, -5, 90, 145, 26, -7, 72, 151, 40}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -19, 50, 159, 85, -14, -5, -18, 35, 154, 102, + -9, -8, -17, 21, 146, 119, -2, -11, -14, 8, 134, 134, 8, -14, -11, -2, + 119, 146, 21, -17, -8, -9, 102, 154, 35, -18, -5, -14, 85, 159, 50, -19}, + }, + + // Band_8_1644 + { + // Scaler inc range + {1641, 1644}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 151, 72, -7, 26, 145, 90, -5, 15, 135, 107, -1, + 6, 122, 122, 6, -1, 107, 135, 15, -5, 90, 145, 26, -7, 72, 151, 40}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -18, 51, 157, 85, -14, -5, -18, 35, 154, 102, + -9, -8, -17, 21, 145, 119, -1, -11, -14, 9, 133, 133, 9, -14, -11, -1, + 119, 145, 21, -17, -8, -9, 102, 154, 35, -18, -5, -14, 85, 157, 51, -18}, + }, + + // Band_8_1646 + { + // Scaler inc range + {1644, 1646}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 151, 72, -7, 26, 145, 90, -5, 15, 135, 107, -1, + 6, 122, 122, 6, -1, 107, 135, 15, -5, 90, 145, 26, -7, 72, 151, 40}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -18, 51, 157, 85, -14, -5, -18, 35, 154, 102, + -9, -8, -17, 21, 145, 119, -1, -11, -14, 9, 133, 133, 9, -14, -11, -1, + 119, 145, 21, -17, -8, -9, 102, 154, 35, -18, -5, -14, 85, 157, 51, -18}, + }, + + // Band_8_1649 + { + // Scaler inc range + {1646, 1649}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 151, 72, -7, 26, 145, 90, -5, 15, 135, 107, -1, + 6, 122, 122, 6, -1, 107, 135, 15, -5, 90, 145, 26, -7, 72, 151, 40}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -18, 51, 157, 85, -14, -5, -18, 35, 154, 102, + -9, -8, -17, 21, 145, 119, -1, -11, -14, 9, 133, 133, 9, -14, -11, -1, + 119, 145, 21, -17, -8, -9, 102, 154, 35, -18, -5, -14, 85, 157, 51, -18}, + }, + + // Band_8_1651 + { + // Scaler inc range + {1649, 1651}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 151, 72, -7, 26, 145, 90, -5, 15, 135, 107, -1, + 6, 122, 122, 6, -1, 107, 135, 15, -5, 90, 145, 26, -7, 72, 151, 40}, + // Coefficients 6 taps + {-17, 66, 158, 66, -17, 0, -18, 51, 158, 85, -14, -6, -18, 35, 154, 102, + -9, -8, -16, 21, 144, 119, -1, -11, -14, 9, 133, 133, 9, -14, -11, -1, + 119, 144, 21, -16, -8, -9, 102, 154, 35, -18, -6, -14, 85, 158, 51, -18}, + }, + + // Band_8_1654 + { + // Scaler inc range + {1651, 1654}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 151, 72, -7, 26, 145, 90, -5, 15, 134, 107, 0, + 6, 122, 122, 6, 0, 107, 134, 15, -5, 90, 145, 26, -7, 72, 151, 40}, + // Coefficients 6 taps + {-16, 66, 156, 66, -16, 0, -18, 51, 158, 85, -14, -6, -18, 36, 152, 102, + -8, -8, -16, 22, 144, 118, -1, -11, -14, 9, 133, 133, 9, -14, -11, -1, + 118, 144, 22, -16, -8, -8, 102, 152, 36, -18, -6, -14, 85, 158, 51, -18}, + }, + + // Band_8_1657 + { + // Scaler inc range + {1654, 1657}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 151, 72, -7, 27, 143, 90, -4, 15, 135, 106, 0, + 6, 122, 122, 6, 0, 106, 135, 15, -4, 90, 143, 27, -7, 72, 151, 40}, + // Coefficients 6 taps + {-16, 66, 156, 66, -16, 0, -18, 51, 157, 85, -13, -6, -18, 36, 152, 102, + -8, -8, -16, 22, 144, 118, -1, -11, -14, 10, 132, 132, 10, -14, -11, -1, + 118, 144, 22, -16, -8, -8, 102, 152, 36, -18, -6, -13, 85, 157, 51, -18}, + }, + + // Band_8_1659 + { + // Scaler inc range + {1657, 1659}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 150, 72, -6, 27, 143, 90, -4, 15, 135, 106, 0, + 6, 122, 122, 6, 0, 106, 135, 15, -4, 90, 143, 27, -6, 72, 150, 40}, + // Coefficients 6 taps + {-16, 66, 156, 66, -16, 0, -18, 51, 157, 85, -13, -6, -18, 36, 152, 102, + -8, -8, -16, 22, 143, 118, 0, -11, -14, 10, 132, 132, 10, -14, -11, 0, + 118, 143, 22, -16, -8, -8, 102, 152, 36, -18, -6, -13, 85, 157, 51, -18}, + }, + + // Band_8_1662 + { + // Scaler inc range + {1659, 1662}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 150, 72, -6, 27, 143, 90, -4, 15, 135, 106, 0, + 6, 122, 122, 6, 0, 106, 135, 15, -4, 90, 143, 27, -6, 72, 150, 40}, + // Coefficients 6 taps + {-16, 67, 154, 67, -16, 0, -18, 51, 157, 85, -13, -6, -18, 36, 153, 102, + -8, -9, -16, 22, 143, 118, 0, -11, -14, 10, 132, 132, 10, -14, -11, 0, + 118, 143, 22, -16, -9, -8, 102, 153, 36, -18, -6, -13, 85, 157, 51, -18}, + }, + + // Band_8_1664 + { + // Scaler inc range + {1662, 1664}, + // Coefficients 4 taps + {54, 148, 54, 0, 40, 150, 72, -6, 27, 143, 90, -4, 16, 134, 106, 0, + 7, 121, 121, 7, 0, 106, 134, 16, -4, 90, 143, 27, -6, 72, 150, 40}, + // Coefficients 6 taps + {-16, 67, 154, 67, -16, 0, -18, 52, 156, 85, -13, -6, -18, 36, 153, 102, + -8, -9, -16, 22, 143, 118, 0, -11, -14, 10, 132, 132, 10, -14, -11, 0, + 118, 143, 22, -16, -9, -8, 102, 153, 36, -18, -6, -13, 85, 156, 52, -18}, + }, + + // Band_8_1667 + { + // Scaler inc range + {1664, 1667}, + // Coefficients 4 taps + {54, 148, 54, 0, 41, 149, 72, -6, 27, 143, 90, -4, 16, 134, 106, 0, + 7, 121, 121, 7, 0, 106, 134, 16, -4, 90, 143, 27, -6, 72, 149, 41}, + // Coefficients 6 taps + {-16, 67, 154, 67, -16, 0, -18, 52, 156, 85, -13, -6, -18, 36, 153, 102, + -8, -9, -16, 22, 144, 118, 0, -12, -14, 10, 132, 132, 10, -14, -12, 0, + 118, 144, 22, -16, -9, -8, 102, 153, 36, -18, -6, -13, 85, 156, 52, -18}, + }, + + // Band_8_1670 + { + // Scaler inc range + {1667, 1670}, + // Coefficients 4 taps + {54, 148, 54, 0, 41, 149, 72, -6, 27, 144, 89, -4, 16, 134, 106, 0, + 7, 121, 121, 7, 0, 106, 134, 16, -4, 89, 144, 27, -6, 72, 149, 41}, + // Coefficients 6 taps + {-16, 67, 154, 67, -16, 0, -18, 52, 156, 85, -13, -6, -18, 37, 151, 102, + -7, -9, -16, 23, 143, 118, 0, -12, -14, 10, 132, 132, 10, -14, -12, 0, + 118, 143, 23, -16, -9, -7, 102, 151, 37, -18, -6, -13, 85, 156, 52, -18}, + }, + + // Band_8_1672 + { + // Scaler inc range + {1670, 1672}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 149, 72, -6, 27, 144, 89, -4, 16, 134, 106, 0, + 7, 121, 121, 7, 0, 106, 134, 16, -4, 89, 144, 27, -6, 72, 149, 41}, + // Coefficients 6 taps + {-16, 67, 154, 67, -16, 0, -18, 52, 156, 85, -13, -6, -18, 37, 151, 102, + -7, -9, -16, 23, 142, 118, 1, -12, -14, 11, 131, 131, 11, -14, -12, 1, + 118, 142, 23, -16, -9, -7, 102, 151, 37, -18, -6, -13, 85, 156, 52, -18}, + }, + + // Band_8_1675 + { + // Scaler inc range + {1672, 1675}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 148, 73, -6, 27, 144, 89, -4, 16, 134, 106, 0, + 7, 121, 121, 7, 0, 106, 134, 16, -4, 89, 144, 27, -6, 73, 148, 41}, + // Coefficients 6 taps + {-16, 67, 154, 67, -16, 0, -17, 52, 154, 85, -12, -6, -18, 37, 151, 102, + -7, -9, -16, 23, 142, 118, 1, -12, -14, 11, 131, 131, 11, -14, -12, 1, + 118, 142, 23, -16, -9, -7, 102, 151, 37, -18, -6, -12, 85, 154, 52, -17}, + }, + + // Band_8_1678 + { + // Scaler inc range + {1675, 1678}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 148, 73, -6, 28, 143, 89, -4, 16, 133, 106, 1, + 7, 121, 121, 7, 1, 106, 133, 16, -4, 89, 143, 28, -6, 73, 148, 41}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 52, 154, 85, -12, -6, -17, 37, 150, 102, + -7, -9, -16, 23, 143, 117, 1, -12, -14, 11, 131, 131, 11, -14, -12, 1, + 117, 143, 23, -16, -9, -7, 102, 150, 37, -17, -6, -12, 85, 154, 52, -17}, + }, + + // Band_8_1680 + { + // Scaler inc range + {1678, 1680}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 148, 73, -6, 28, 143, 89, -4, 16, 133, 106, 1, + 7, 121, 121, 7, 1, 106, 133, 16, -4, 89, 143, 28, -6, 73, 148, 41}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 52, 154, 85, -12, -6, -17, 37, 150, 102, + -7, -9, -16, 23, 143, 117, 1, -12, -14, 11, 131, 131, 11, -14, -12, 1, + 117, 143, 23, -16, -9, -7, 102, 150, 37, -17, -6, -12, 85, 154, 52, -17}, + }, + + // Band_8_1683 + { + // Scaler inc range + {1680, 1683}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 148, 73, -6, 28, 143, 89, -4, 16, 133, 106, 1, + 7, 121, 121, 7, 1, 106, 133, 16, -4, 89, 143, 28, -6, 73, 148, 41}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 52, 154, 85, -12, -6, -17, 37, 149, 102, + -6, -9, -16, 23, 143, 117, 1, -12, -14, 11, 131, 131, 11, -14, -12, 1, + 117, 143, 23, -16, -9, -6, 102, 149, 37, -17, -6, -12, 85, 154, 52, -17}, + }, + + // Band_8_1686 + { + // Scaler inc range + {1683, 1686}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 148, 73, -6, 28, 142, 89, -3, 17, 132, 106, 1, + 8, 120, 120, 8, 1, 106, 132, 17, -3, 89, 142, 28, -6, 73, 148, 41}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 52, 154, 85, -12, -6, -17, 37, 150, 101, + -6, -9, -16, 24, 142, 117, 1, -12, -14, 12, 130, 130, 12, -14, -12, 1, + 117, 142, 24, -16, -9, -6, 101, 150, 37, -17, -6, -12, 85, 154, 52, -17}, + }, + + // Band_8_1689 + { + // Scaler inc range + {1686, 1689}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 148, 73, -6, 28, 142, 89, -3, 17, 132, 106, 1, + 8, 120, 120, 8, 1, 106, 132, 17, -3, 89, 142, 28, -6, 73, 148, 41}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 52, 154, 85, -12, -6, -17, 38, 149, 101, + -6, -9, -16, 24, 141, 117, 2, -12, -14, 12, 130, 130, 12, -14, -12, 2, + 117, 141, 24, -16, -9, -6, 101, 149, 38, -17, -6, -12, 85, 154, 52, -17}, + }, + + // Band_8_1691 + { + // Scaler inc range + {1689, 1691}, + // Coefficients 4 taps + {55, 146, 55, 0, 41, 148, 73, -6, 28, 142, 89, -3, 17, 132, 106, 1, + 8, 120, 120, 8, 1, 106, 132, 17, -3, 89, 142, 28, -6, 73, 148, 41}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 53, 153, 85, -12, -6, -17, 38, 149, 101, + -6, -9, -16, 24, 141, 117, 2, -12, -14, 12, 130, 130, 12, -14, -12, 2, + 117, 141, 24, -16, -9, -6, 101, 149, 38, -17, -6, -12, 85, 153, 53, -17}, + }, + + // Band_8_1694 + { + // Scaler inc range + {1691, 1694}, + // Coefficients 4 taps + {55, 146, 55, 0, 42, 147, 73, -6, 28, 142, 89, -3, 17, 133, 105, 1, + 8, 120, 120, 8, 1, 105, 133, 17, -3, 89, 142, 28, -6, 73, 147, 42}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 53, 152, 85, -11, -6, -17, 38, 149, 101, + -6, -9, -16, 24, 141, 117, 2, -12, -14, 12, 130, 130, 12, -14, -12, 2, + 117, 141, 24, -16, -9, -6, 101, 149, 38, -17, -6, -11, 85, 152, 53, -17}, + }, + + // Band_8_1697 + { + // Scaler inc range + {1694, 1697}, + // Coefficients 4 taps + {55, 146, 55, 0, 42, 147, 73, -6, 28, 142, 89, -3, 17, 133, 105, 1, + 8, 120, 120, 8, 1, 105, 133, 17, -3, 89, 142, 28, -6, 73, 147, 42}, + // Coefficients 6 taps + {-15, 67, 152, 67, -15, 0, -17, 53, 152, 85, -11, -6, -17, 38, 149, 101, + -6, -9, -16, 24, 141, 117, 2, -12, -14, 12, 130, 130, 12, -14, -12, 2, + 117, 141, 24, -16, -9, -6, 101, 149, 38, -17, -6, -11, 85, 152, 53, -17}, + }, + + // Band_8_1699 + { + // Scaler inc range + {1697, 1699}, + // Coefficients 4 taps + {55, 146, 55, 0, 42, 146, 73, -5, 28, 142, 89, -3, 17, 133, 105, 1, + 8, 120, 120, 8, 1, 105, 133, 17, -3, 89, 142, 28, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -17, 53, 152, 85, -11, -6, -17, 38, 148, 101, + -5, -9, -16, 24, 142, 116, 2, -12, -14, 12, 130, 130, 12, -14, -12, 2, + 116, 142, 24, -16, -9, -5, 101, 148, 38, -17, -6, -11, 85, 152, 53, -17}, + }, + + // Band_8_1702 + { + // Scaler inc range + {1699, 1702}, + // Coefficients 4 taps + {55, 146, 55, 0, 42, 146, 73, -5, 29, 141, 89, -3, 17, 132, 105, 2, + 8, 120, 120, 8, 2, 105, 132, 17, -3, 89, 141, 29, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -17, 53, 153, 85, -11, -7, -17, 38, 148, 101, + -5, -9, -16, 25, 140, 116, 3, -12, -14, 13, 129, 129, 13, -14, -12, 3, + 116, 140, 25, -16, -9, -5, 101, 148, 38, -17, -7, -11, 85, 153, 53, -17}, + }, + + // Band_8_1705 + { + // Scaler inc range + {1702, 1705}, + // Coefficients 4 taps + {56, 144, 56, 0, 42, 146, 73, -5, 29, 141, 89, -3, 17, 132, 105, 2, + 8, 120, 120, 8, 2, 105, 132, 17, -3, 89, 141, 29, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -16, 53, 152, 85, -11, -7, -17, 38, 148, 101, + -5, -9, -16, 25, 140, 116, 3, -12, -14, 13, 129, 129, 13, -14, -12, 3, + 116, 140, 25, -16, -9, -5, 101, 148, 38, -17, -7, -11, 85, 152, 53, -16}, + }, + + // Band_8_1708 + { + // Scaler inc range + {1705, 1708}, + // Coefficients 4 taps + {56, 144, 56, 0, 42, 146, 73, -5, 29, 141, 89, -3, 18, 131, 105, 2, + 8, 120, 120, 8, 2, 105, 131, 18, -3, 89, 141, 29, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -16, 53, 152, 85, -11, -7, -17, 38, 148, 101, + -5, -9, -16, 25, 140, 116, 3, -12, -14, 13, 129, 129, 13, -14, -12, 3, + 116, 140, 25, -16, -9, -5, 101, 148, 38, -17, -7, -11, 85, 152, 53, -16}, + }, + + // Band_8_1711 + { + // Scaler inc range + {1708, 1711}, + // Coefficients 4 taps + {56, 144, 56, 0, 42, 146, 73, -5, 29, 141, 89, -3, 18, 131, 105, 2, + 9, 119, 119, 9, 2, 105, 131, 18, -3, 89, 141, 29, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -16, 53, 151, 85, -10, -7, -17, 39, 147, 101, + -5, -9, -16, 25, 140, 116, 3, -12, -14, 13, 129, 129, 13, -14, -12, 3, + 116, 140, 25, -16, -9, -5, 101, 147, 39, -17, -7, -10, 85, 151, 53, -16}, + }, + + // Band_8_1713 + { + // Scaler inc range + {1711, 1713}, + // Coefficients 4 taps + {56, 144, 56, 0, 42, 146, 73, -5, 29, 141, 89, -3, 18, 131, 105, 2, + 9, 119, 119, 9, 2, 105, 131, 18, -3, 89, 141, 29, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -16, 53, 151, 85, -10, -7, -17, 39, 147, 101, + -5, -9, -16, 25, 140, 116, 3, -12, -14, 13, 129, 129, 13, -14, -12, 3, + 116, 140, 25, -16, -9, -5, 101, 147, 39, -17, -7, -10, 85, 151, 53, -16}, + }, + + // Band_8_1716 + { + // Scaler inc range + {1713, 1716}, + // Coefficients 4 taps + {56, 144, 56, 0, 42, 146, 73, -5, 29, 140, 89, -2, 18, 131, 105, 2, + 9, 119, 119, 9, 2, 105, 131, 18, -2, 89, 140, 29, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -16, 53, 151, 85, -10, -7, -17, 39, 146, 101, + -4, -9, -16, 25, 140, 116, 3, -12, -14, 14, 128, 128, 14, -14, -12, 3, + 116, 140, 25, -16, -9, -4, 101, 146, 39, -17, -7, -10, 85, 151, 53, -16}, + }, + + // Band_8_1719 + { + // Scaler inc range + {1716, 1719}, + // Coefficients 4 taps + {56, 144, 56, 0, 42, 146, 73, -5, 29, 140, 89, -2, 18, 131, 105, 2, + 9, 119, 119, 9, 2, 105, 131, 18, -2, 89, 140, 29, -5, 73, 146, 42}, + // Coefficients 6 taps + {-14, 67, 150, 67, -14, 0, -16, 54, 150, 85, -10, -7, -17, 39, 146, 101, + -4, -9, -16, 26, 138, 116, 4, -12, -14, 14, 128, 128, 14, -14, -12, 4, + 116, 138, 26, -16, -9, -4, 101, 146, 39, -17, -7, -10, 85, 150, 54, -16}, + }, + + // Band_8_1722 + { + // Scaler inc range + {1719, 1722}, + // Coefficients 4 taps + {56, 144, 56, 0, 43, 145, 73, -5, 29, 140, 89, -2, 18, 131, 105, 2, + 9, 119, 119, 9, 2, 105, 131, 18, -2, 89, 140, 29, -5, 73, 145, 43}, + // Coefficients 6 taps + {-13, 67, 148, 67, -13, 0, -16, 54, 150, 85, -10, -7, -16, 39, 145, 101, + -4, -9, -16, 26, 139, 115, 4, -12, -14, 14, 128, 128, 14, -14, -12, 4, + 115, 139, 26, -16, -9, -4, 101, 145, 39, -16, -7, -10, 85, 150, 54, -16}, + }, + + // Band_8_1725 + { + // Scaler inc range + {1722, 1725}, + // Coefficients 4 taps + {56, 144, 56, 0, 43, 145, 73, -5, 29, 140, 89, -2, 18, 131, 105, 2, + 9, 119, 119, 9, 2, 105, 131, 18, -2, 89, 140, 29, -5, 73, 145, 43}, + // Coefficients 6 taps + {-13, 67, 148, 67, -13, 0, -16, 54, 150, 85, -10, -7, -16, 39, 145, 101, + -4, -9, -16, 26, 139, 115, 4, -12, -14, 14, 128, 128, 14, -14, -12, 4, + 115, 139, 26, -16, -9, -4, 101, 145, 39, -16, -7, -10, 85, 150, 54, -16}, + }, + + // Band_8_1727 + { + // Scaler inc range + {1725, 1727}, + // Coefficients 4 taps + {56, 144, 56, 0, 43, 145, 73, -5, 30, 139, 89, -2, 18, 130, 105, 3, + 9, 119, 119, 9, 3, 105, 130, 18, -2, 89, 139, 30, -5, 73, 145, 43}, + // Coefficients 6 taps + {-13, 67, 148, 67, -13, 0, -16, 54, 150, 85, -10, -7, -16, 39, 146, 100, + -4, -9, -16, 26, 139, 115, 4, -12, -14, 14, 128, 128, 14, -14, -12, 4, + 115, 139, 26, -16, -9, -4, 100, 146, 39, -16, -7, -10, 85, 150, 54, -16}, + }, + + // Band_8_1730 + { + // Scaler inc range + {1727, 1730}, + // Coefficients 4 taps + {56, 144, 56, 0, 43, 145, 73, -5, 30, 139, 89, -2, 18, 130, 105, 3, + 9, 119, 119, 9, 3, 105, 130, 18, -2, 89, 139, 30, -5, 73, 145, 43}, + // Coefficients 6 taps + {-13, 67, 148, 67, -13, 0, -16, 54, 149, 85, -9, -7, -16, 40, 146, 100, -4, -10, -16, 26, 139, 115, 4, -12, + -14, 14, 128, 128, 14, -14, -12, 4, 115, 139, 26, -16, -10, -4, 100, 146, 40, -16, -7, -9, 85, 149, 54, -16}, + }, + + // Band_8_1733 + { + // Scaler inc range + {1730, 1733}, + // Coefficients 4 taps + {56, 144, 56, 0, 43, 145, 73, -5, 30, 139, 89, -2, 19, 130, 104, 3, + 10, 118, 118, 10, 3, 104, 130, 19, -2, 89, 139, 30, -5, 73, 145, 43}, + // Coefficients 6 taps + {-13, 67, 148, 67, -13, 0, -15, 54, 148, 85, -9, -7, -16, 40, 145, 100, -3, -10, -16, 26, 138, 115, 5, -12, + -14, 15, 127, 127, 15, -14, -12, 5, 115, 138, 26, -16, -10, -3, 100, 145, 40, -16, -7, -9, 85, 148, 54, -15}, + }, + + // Band_8_1736 + { + // Scaler inc range + {1733, 1736}, + // Coefficients 4 taps + {56, 144, 56, 0, 43, 144, 73, -4, 30, 139, 89, -2, 19, 130, 104, 3, + 10, 118, 118, 10, 3, 104, 130, 19, -2, 89, 139, 30, -4, 73, 144, 43}, + // Coefficients 6 taps + {-13, 67, 148, 67, -13, 0, -15, 54, 148, 85, -9, -7, -16, 40, 145, 100, -3, -10, -16, 27, 137, 115, 5, -12, + -14, 15, 127, 127, 15, -14, -12, 5, 115, 137, 27, -16, -10, -3, 100, 145, 40, -16, -7, -9, 85, 148, 54, -15}, + }, + + // Band_8_1739 + { + // Scaler inc range + {1736, 1739}, + // Coefficients 4 taps + {57, 142, 57, 0, 43, 144, 73, -4, 30, 139, 89, -2, 19, 130, 104, 3, + 10, 118, 118, 10, 3, 104, 130, 19, -2, 89, 139, 30, -4, 73, 144, 43}, + // Coefficients 6 taps + {-13, 68, 146, 68, -13, 0, -15, 54, 148, 85, -9, -7, -16, 40, 145, 100, -3, -10, -16, 27, 137, 115, 5, -12, + -14, 15, 127, 127, 15, -14, -12, 5, 115, 137, 27, -16, -10, -3, 100, 145, 40, -16, -7, -9, 85, 148, 54, -15}, + }, + + // Band_8_1742 + { + // Scaler inc range + {1739, 1742}, + // Coefficients 4 taps + {57, 142, 57, 0, 43, 144, 73, -4, 30, 139, 89, -2, 19, 130, 104, 3, + 10, 118, 118, 10, 3, 104, 130, 19, -2, 89, 139, 30, -4, 73, 144, 43}, + // Coefficients 6 taps + {-13, 68, 146, 68, -13, 0, -15, 54, 148, 85, -9, -7, -16, 40, 145, 100, -3, -10, -16, 27, 138, 114, 5, -12, + -14, 15, 127, 127, 15, -14, -12, 5, 114, 138, 27, -16, -10, -3, 100, 145, 40, -16, -7, -9, 85, 148, 54, -15}, + }, + + // Band_8_1745 + { + // Scaler inc range + {1742, 1745}, + // Coefficients 4 taps + {57, 142, 57, 0, 43, 144, 73, -4, 30, 138, 89, -1, 19, 130, 104, 3, + 10, 118, 118, 10, 3, 104, 130, 19, -1, 89, 138, 30, -4, 73, 144, 43}, + // Coefficients 6 taps + {-12, 68, 144, 68, -12, 0, -15, 54, 148, 85, -9, -7, -16, 40, 145, 100, -3, -10, -15, 27, 137, 114, 5, -12, + -14, 15, 127, 127, 15, -14, -12, 5, 114, 137, 27, -15, -10, -3, 100, 145, 40, -16, -7, -9, 85, 148, 54, -15}, + }, + + // Band_8_1748 + { + // Scaler inc range + {1745, 1748}, + // Coefficients 4 taps + {57, 142, 57, 0, 43, 144, 73, -4, 30, 138, 89, -1, 19, 130, 104, 3, + 10, 118, 118, 10, 3, 104, 130, 19, -1, 89, 138, 30, -4, 73, 144, 43}, + // Coefficients 6 taps + {-12, 68, 144, 68, -12, 0, -15, 54, 147, 85, -8, -7, -16, 40, 145, 100, -3, -10, -15, 27, 137, 114, 5, -12, + -14, 15, 127, 127, 15, -14, -12, 5, 114, 137, 27, -15, -10, -3, 100, 145, 40, -16, -7, -8, 85, 147, 54, -15}, + }, + + // Band_8_1751 + { + // Scaler inc range + {1748, 1751}, + // Coefficients 4 taps + {57, 142, 57, 0, 43, 144, 73, -4, 30, 138, 89, -1, 19, 130, 104, 3, + 10, 118, 118, 10, 3, 104, 130, 19, -1, 89, 138, 30, -4, 73, 144, 43}, + // Coefficients 6 taps + {-12, 68, 144, 68, -12, 0, -15, 54, 147, 85, -8, -7, -16, 40, 144, 100, -2, -10, -15, 27, 136, 114, 6, -12, + -14, 16, 126, 126, 16, -14, -12, 6, 114, 136, 27, -15, -10, -2, 100, 144, 40, -16, -7, -8, 85, 147, 54, -15}, + }, + + // Band_8_1753 + { + // Scaler inc range + {1751, 1753}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 143, 73, -4, 31, 137, 89, -1, 19, 129, 104, 4, + 10, 118, 118, 10, 4, 104, 129, 19, -1, 89, 137, 31, -4, 73, 143, 44}, + // Coefficients 6 taps + {-12, 68, 144, 68, -12, 0, -15, 55, 146, 85, -8, -7, -16, 41, 143, 100, -2, -10, -15, 27, 136, 114, 6, -12, + -14, 16, 126, 126, 16, -14, -12, 6, 114, 136, 27, -15, -10, -2, 100, 143, 41, -16, -7, -8, 85, 146, 55, -15}, + }, + + // Band_8_1756 + { + // Scaler inc range + {1753, 1756}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 143, 73, -4, 31, 137, 89, -1, 20, 128, 104, 4, + 11, 117, 117, 11, 4, 104, 128, 20, -1, 89, 137, 31, -4, 73, 143, 44}, + // Coefficients 6 taps + {-12, 68, 144, 68, -12, 0, -15, 55, 146, 85, -8, -7, -16, 41, 143, 100, -2, -10, -15, 28, 135, 114, 6, -12, + -14, 16, 126, 126, 16, -14, -12, 6, 114, 135, 28, -15, -10, -2, 100, 143, 41, -16, -7, -8, 85, 146, 55, -15}, + }, + + // Band_8_1759 + { + // Scaler inc range + {1756, 1759}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 143, 73, -4, 31, 137, 89, -1, 20, 128, 104, 4, + 11, 117, 117, 11, 4, 104, 128, 20, -1, 89, 137, 31, -4, 73, 143, 44}, + // Coefficients 6 taps + {-12, 68, 144, 68, -12, 0, -14, 55, 145, 85, -8, -7, -16, 41, 143, 100, -2, -10, -15, 28, 135, 114, 6, -12, + -14, 16, 126, 126, 16, -14, -12, 6, 114, 135, 28, -15, -10, -2, 100, 143, 41, -16, -7, -8, 85, 145, 55, -14}, + }, + + // Band_8_1762 + { + // Scaler inc range + {1759, 1762}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 143, 73, -4, 31, 137, 89, -1, 20, 128, 104, 4, + 11, 117, 117, 11, 4, 104, 128, 20, -1, 89, 137, 31, -4, 73, 143, 44}, + // Coefficients 6 taps + {-12, 68, 144, 68, -12, 0, -14, 55, 146, 84, -8, -7, -15, 41, 142, 100, -2, -10, -15, 28, 135, 114, 6, -12, + -14, 16, 126, 126, 16, -14, -12, 6, 114, 135, 28, -15, -10, -2, 100, 142, 41, -15, -7, -8, 84, 146, 55, -14}, + }, + + // Band_8_1765 + { + // Scaler inc range + {1762, 1765}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 143, 73, -4, 31, 137, 89, -1, 20, 128, 104, 4, + 11, 117, 117, 11, 4, 104, 128, 20, -1, 89, 137, 31, -4, 73, 143, 44}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -14, 55, 146, 84, -8, -7, -15, 41, 143, 99, -2, -10, -15, 28, 135, 113, 7, -12, + -14, 16, 126, 126, 16, -14, -12, 7, 113, 135, 28, -15, -10, -2, 99, 143, 41, -15, -7, -8, 84, 146, 55, -14}, + }, + + // Band_8_1768 + { + // Scaler inc range + {1765, 1768}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 142, 74, -4, 31, 137, 89, -1, 20, 128, 104, 4, + 11, 117, 117, 11, 4, 104, 128, 20, -1, 89, 137, 31, -4, 74, 142, 44}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -14, 55, 145, 84, -7, -7, -15, 41, 142, 99, -1, -10, -15, 28, 135, 113, 7, -12, + -14, 17, 125, 125, 17, -14, -12, 7, 113, 135, 28, -15, -10, -1, 99, 142, 41, -15, -7, -7, 84, 145, 55, -14}, + }, + + // Band_8_1771 + { + // Scaler inc range + {1768, 1771}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 142, 74, -4, 31, 137, 89, -1, 20, 128, 104, 4, + 11, 117, 117, 11, 4, 104, 128, 20, -1, 89, 137, 31, -4, 74, 142, 44}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -14, 55, 146, 84, -7, -8, -15, 41, 142, 99, -1, -10, -15, 28, 135, 113, 7, -12, + -14, 17, 125, 125, 17, -14, -12, 7, 113, 135, 28, -15, -10, -1, 99, 142, 41, -15, -8, -7, 84, 146, 55, -14}, + }, + + // Band_8_1774 + { + // Scaler inc range + {1771, 1774}, + // Coefficients 4 taps + {57, 142, 57, 0, 44, 142, 74, -4, 31, 137, 89, -1, 20, 129, 103, 4, + 11, 117, 117, 11, 4, 103, 129, 20, -1, 89, 137, 31, -4, 74, 142, 44}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -14, 55, 146, 84, -7, -8, -15, 41, 142, 99, -1, -10, -15, 29, 134, 113, 7, -12, + -14, 17, 125, 125, 17, -14, -12, 7, 113, 134, 29, -15, -10, -1, 99, 142, 41, -15, -8, -7, 84, 146, 55, -14}, + }, + + // Band_8_1777 + { + // Scaler inc range + {1774, 1777}, + // Coefficients 4 taps + {58, 140, 58, 0, 44, 141, 74, -3, 31, 136, 89, 0, 20, 129, 103, 4, + 11, 117, 117, 11, 4, 103, 129, 20, 0, 89, 136, 31, -3, 74, 141, 44}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -14, 55, 146, 84, -7, -8, -15, 42, 141, 99, -1, -10, -15, 29, 134, 113, 7, -12, + -14, 17, 125, 125, 17, -14, -12, 7, 113, 134, 29, -15, -10, -1, 99, 141, 42, -15, -8, -7, 84, 146, 55, -14}, + }, + + // Band_8_1780 + { + // Scaler inc range + {1777, 1780}, + // Coefficients 4 taps + {58, 140, 58, 0, 44, 141, 74, -3, 32, 135, 89, 0, 20, 128, 103, 5, + 11, 117, 117, 11, 5, 103, 128, 20, 0, 89, 135, 32, -3, 74, 141, 44}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -14, 55, 146, 84, -7, -8, -15, 42, 141, 99, -1, -10, -15, 29, 134, 113, 7, -12, + -14, 17, 125, 125, 17, -14, -12, 7, 113, 134, 29, -15, -10, -1, 99, 141, 42, -15, -8, -7, 84, 146, 55, -14}, + }, + + // Band_8_1783 + { + // Scaler inc range + {1780, 1783}, + // Coefficients 4 taps + {58, 140, 58, 0, 44, 141, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 141, 44}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -14, 55, 146, 84, -7, -8, -15, 42, 140, 99, 0, -10, -15, 29, 133, 113, 8, -12, + -14, 17, 125, 125, 17, -14, -12, 8, 113, 133, 29, -15, -10, 0, 99, 140, 42, -15, -8, -7, 84, 146, 55, -14}, + }, + + // Band_8_1786 + { + // Scaler inc range + {1783, 1786}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 140, 45}, + // Coefficients 6 taps + {-11, 68, 142, 68, -11, 0, -13, 55, 144, 84, -6, -8, -15, 42, 140, 99, 0, -10, -15, 29, 134, 112, 8, -12, + -14, 18, 124, 124, 18, -14, -12, 8, 112, 134, 29, -15, -10, 0, 99, 140, 42, -15, -8, -6, 84, 144, 55, -13}, + }, + + // Band_8_1789 + { + // Scaler inc range + {1786, 1789}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 140, 45}, + // Coefficients 6 taps + {-10, 68, 140, 68, -10, 0, -13, 56, 143, 84, -6, -8, -15, 42, 140, 99, 0, -10, -15, 29, 134, 112, 8, -12, + -14, 18, 124, 124, 18, -14, -12, 8, 112, 134, 29, -15, -10, 0, 99, 140, 42, -15, -8, -6, 84, 143, 56, -13}, + }, + + // Band_8_1792 + { + // Scaler inc range + {1789, 1792}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 140, 45}, + // Coefficients 6 taps + {-10, 68, 140, 68, -10, 0, -13, 56, 143, 84, -6, -8, -15, 42, 140, 99, 0, -10, -15, 29, 134, 112, 8, -12, + -14, 18, 124, 124, 18, -14, -12, 8, 112, 134, 29, -15, -10, 0, 99, 140, 42, -15, -8, -6, 84, 143, 56, -13}, + }, + + // Band_8_1796 + { + // Scaler inc range + {1792, 1796}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 140, 45}, + // Coefficients 6 taps + {-10, 68, 140, 68, -10, 0, -13, 56, 143, 84, -6, -8, -15, 42, 140, 99, 0, -10, -15, 30, 133, 112, 8, -12, + -14, 18, 124, 124, 18, -14, -12, 8, 112, 133, 30, -15, -10, 0, 99, 140, 42, -15, -8, -6, 84, 143, 56, -13}, + }, + + // Band_8_1799 + { + // Scaler inc range + {1796, 1799}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 140, 45}, + // Coefficients 6 taps + {-10, 68, 140, 68, -10, 0, -13, 56, 143, 84, -6, -8, -14, 42, 139, 99, 0, -10, -15, 30, 133, 112, 8, -12, + -14, 18, 124, 124, 18, -14, -12, 8, 112, 133, 30, -15, -10, 0, 99, 139, 42, -14, -8, -6, 84, 143, 56, -13}, + }, + + // Band_8_1802 + { + // Scaler inc range + {1799, 1802}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 140, 45}, + // Coefficients 6 taps + {-10, 68, 140, 68, -10, 0, -13, 56, 143, 84, -6, -8, -14, 42, 139, 98, 1, -10, -15, 30, 132, 112, 9, -12, + -14, 18, 124, 124, 18, -14, -12, 9, 112, 132, 30, -15, -10, 1, 98, 139, 42, -14, -8, -6, 84, 143, 56, -13}, + }, + + // Band_8_1805 + { + // Scaler inc range + {1802, 1805}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 32, 135, 89, 0, 21, 127, 103, 5, + 12, 116, 116, 12, 5, 103, 127, 21, 0, 89, 135, 32, -3, 74, 140, 45}, + // Coefficients 6 taps + {-10, 68, 140, 68, -10, 0, -13, 56, 143, 84, -6, -8, -14, 43, 138, 98, 1, -10, -14, 30, 131, 112, 9, -12, + -14, 19, 123, 123, 19, -14, -12, 9, 112, 131, 30, -14, -10, 1, 98, 138, 43, -14, -8, -6, 84, 143, 56, -13}, + }, + + // Band_8_1808 + { + // Scaler inc range + {1805, 1808}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 33, 134, 89, 0, 22, 126, 103, 5, + 12, 116, 116, 12, 5, 103, 126, 22, 0, 89, 134, 33, -3, 74, 140, 45}, + // Coefficients 6 taps + {-10, 68, 140, 68, -10, 0, -13, 56, 142, 84, -5, -8, -14, 43, 138, 98, 1, -10, -14, 30, 132, 111, 9, -12, + -14, 19, 123, 123, 19, -14, -12, 9, 111, 132, 30, -14, -10, 1, 98, 138, 43, -14, -8, -5, 84, 142, 56, -13}, + }, + + // Band_8_1811 + { + // Scaler inc range + {1808, 1811}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 33, 133, 89, 1, 22, 125, 103, 6, + 13, 115, 115, 13, 6, 103, 125, 22, 1, 89, 133, 33, -3, 74, 140, 45}, + // Coefficients 6 taps + {-9, 68, 138, 68, -9, 0, -13, 56, 142, 84, -5, -8, -14, 43, 138, 98, 1, -10, -14, 30, 132, 111, 9, -12, + -14, 19, 123, 123, 19, -14, -12, 9, 111, 132, 30, -14, -10, 1, 98, 138, 43, -14, -8, -5, 84, 142, 56, -13}, + }, + + // Band_8_1814 + { + // Scaler inc range + {1811, 1814}, + // Coefficients 4 taps + {58, 140, 58, 0, 45, 140, 74, -3, 33, 134, 88, 1, 22, 125, 103, 6, + 13, 115, 115, 13, 6, 103, 125, 22, 1, 88, 134, 33, -3, 74, 140, 45}, + // Coefficients 6 taps + {-9, 68, 138, 68, -9, 0, -12, 56, 141, 84, -5, -8, -14, 43, 138, 98, 1, -10, -14, 30, 132, 111, 9, -12, + -14, 19, 123, 123, 19, -14, -12, 9, 111, 132, 30, -14, -10, 1, 98, 138, 43, -14, -8, -5, 84, 141, 56, -12}, + }, + + // Band_8_1817 + { + // Scaler inc range + {1814, 1817}, + // Coefficients 4 taps + {59, 138, 59, 0, 45, 139, 74, -2, 33, 134, 88, 1, 22, 126, 102, 6, + 13, 115, 115, 13, 6, 102, 126, 22, 1, 88, 134, 33, -2, 74, 139, 45}, + // Coefficients 6 taps + {-9, 68, 138, 68, -9, 0, -12, 56, 141, 84, -5, -8, -14, 43, 138, 98, 1, -10, -14, 31, 131, 111, 9, -12, + -13, 19, 122, 122, 19, -13, -12, 9, 111, 131, 31, -14, -10, 1, 98, 138, 43, -14, -8, -5, 84, 141, 56, -12}, + }, + + // Band_8_1820 + { + // Scaler inc range + {1817, 1820}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 33, 134, 88, 1, 22, 126, 102, 6, + 13, 115, 115, 13, 6, 102, 126, 22, 1, 88, 134, 33, -2, 74, 138, 46}, + // Coefficients 6 taps + {-9, 68, 138, 68, -9, 0, -12, 56, 141, 84, -5, -8, -14, 43, 137, 98, 2, -10, -14, 31, 130, 111, 10, -12, + -13, 19, 122, 122, 19, -13, -12, 10, 111, 130, 31, -14, -10, 2, 98, 137, 43, -14, -8, -5, 84, 141, 56, -12}, + }, + + // Band_8_1824 + { + // Scaler inc range + {1820, 1824}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 33, 134, 88, 1, 22, 126, 102, 6, + 13, 115, 115, 13, 6, 102, 126, 22, 1, 88, 134, 33, -2, 74, 138, 46}, + // Coefficients 6 taps + {-9, 68, 138, 68, -9, 0, -12, 56, 141, 84, -5, -8, -14, 43, 137, 98, 2, -10, -14, 31, 130, 111, 10, -12, + -13, 20, 121, 121, 20, -13, -12, 10, 111, 130, 31, -14, -10, 2, 98, 137, 43, -14, -8, -5, 84, 141, 56, -12}, + }, + + // Band_8_1827 + { + // Scaler inc range + {1824, 1827}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 33, 134, 88, 1, 22, 126, 102, 6, + 13, 115, 115, 13, 6, 102, 126, 22, 1, 88, 134, 33, -2, 74, 138, 46}, + // Coefficients 6 taps + {-9, 68, 138, 68, -9, 0, -12, 56, 140, 84, -4, -8, -14, 43, 137, 98, 2, -10, -14, 31, 130, 111, 10, -12, + -13, 20, 121, 121, 20, -13, -12, 10, 111, 130, 31, -14, -10, 2, 98, 137, 43, -14, -8, -4, 84, 140, 56, -12}, + }, + + // Band_8_1830 + { + // Scaler inc range + {1827, 1830}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 33, 134, 88, 1, 22, 126, 102, 6, + 13, 115, 115, 13, 6, 102, 126, 22, 1, 88, 134, 33, -2, 74, 138, 46}, + // Coefficients 6 taps + {-9, 68, 138, 68, -9, 0, -12, 56, 140, 84, -4, -8, -14, 43, 137, 98, 2, -10, -14, 31, 131, 110, 10, -12, + -13, 20, 121, 121, 20, -13, -12, 10, 110, 131, 31, -14, -10, 2, 98, 137, 43, -14, -8, -4, 84, 140, 56, -12}, + }, + + // Band_8_1833 + { + // Scaler inc range + {1830, 1833}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 33, 134, 88, 1, 22, 126, 102, 6, + 13, 115, 115, 13, 6, 102, 126, 22, 1, 88, 134, 33, -2, 74, 138, 46}, + // Coefficients 6 taps + {-8, 68, 136, 68, -8, 0, -12, 57, 139, 84, -4, -8, -13, 44, 135, 98, 2, -10, -14, 31, 131, 110, 10, -12, + -13, 20, 121, 121, 20, -13, -12, 10, 110, 131, 31, -14, -10, 2, 98, 135, 44, -13, -8, -4, 84, 139, 57, -12}, + }, + + // Band_8_1836 + { + // Scaler inc range + {1833, 1836}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 33, 134, 88, 1, 23, 125, 102, 6, + 14, 114, 114, 14, 6, 102, 125, 23, 1, 88, 134, 33, -2, 74, 138, 46}, + // Coefficients 6 taps + {-8, 68, 136, 68, -8, 0, -12, 57, 139, 84, -4, -8, -13, 44, 136, 97, 2, -10, -14, 31, 131, 110, 10, -12, + -13, 20, 121, 121, 20, -13, -12, 10, 110, 131, 31, -14, -10, 2, 97, 136, 44, -13, -8, -4, 84, 139, 57, -12}, + }, + + // Band_8_1840 + { + // Scaler inc range + {1836, 1840}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 34, 133, 88, 1, 23, 124, 102, 7, + 14, 114, 114, 14, 7, 102, 124, 23, 1, 88, 133, 34, -2, 74, 138, 46}, + // Coefficients 6 taps + {-8, 68, 136, 68, -8, 0, -12, 57, 139, 84, -4, -8, -13, 44, 135, 97, 3, -10, -14, 32, 129, 110, 11, -12, + -13, 20, 121, 121, 20, -13, -12, 11, 110, 129, 32, -14, -10, 3, 97, 135, 44, -13, -8, -4, 84, 139, 57, -12}, + }, + + // Band_8_1843 + { + // Scaler inc range + {1840, 1843}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 34, 132, 88, 2, 23, 124, 102, 7, + 14, 114, 114, 14, 7, 102, 124, 23, 2, 88, 132, 34, -2, 74, 138, 46}, + // Coefficients 6 taps + {-8, 68, 136, 68, -8, 0, -11, 57, 138, 84, -4, -8, -13, 44, 135, 97, 3, -10, -14, 32, 129, 110, 11, -12, + -13, 21, 120, 120, 21, -13, -12, 11, 110, 129, 32, -14, -10, 3, 97, 135, 44, -13, -8, -4, 84, 138, 57, -11}, + }, + + // Band_8_1846 + { + // Scaler inc range + {1843, 1846}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 34, 132, 88, 2, 23, 124, 102, 7, + 14, 114, 114, 14, 7, 102, 124, 23, 2, 88, 132, 34, -2, 74, 138, 46}, + // Coefficients 6 taps + {-8, 68, 136, 68, -8, 0, -11, 57, 137, 84, -3, -8, -13, 44, 135, 97, 3, -10, -14, 32, 129, 110, 11, -12, + -13, 21, 120, 120, 21, -13, -12, 11, 110, 129, 32, -14, -10, 3, 97, 135, 44, -13, -8, -3, 84, 137, 57, -11}, + }, + + // Band_8_1849 + { + // Scaler inc range + {1846, 1849}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 34, 132, 88, 2, 23, 124, 102, 7, + 14, 114, 114, 14, 7, 102, 124, 23, 2, 88, 132, 34, -2, 74, 138, 46}, + // Coefficients 6 taps + {-8, 68, 136, 68, -8, 0, -11, 57, 137, 84, -3, -8, -13, 44, 135, 97, 3, -10, -14, 32, 130, 109, 11, -12, + -13, 21, 120, 120, 21, -13, -12, 11, 109, 130, 32, -14, -10, 3, 97, 135, 44, -13, -8, -3, 84, 137, 57, -11}, + }, + + // Band_8_1853 + { + // Scaler inc range + {1849, 1853}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 34, 132, 88, 2, 23, 124, 102, 7, + 14, 114, 114, 14, 7, 102, 124, 23, 2, 88, 132, 34, -2, 74, 138, 46}, + // Coefficients 6 taps + {-8, 68, 136, 68, -8, 0, -11, 57, 137, 84, -3, -8, -13, 44, 135, 97, 3, -10, -13, 32, 129, 109, 11, -12, + -13, 21, 120, 120, 21, -13, -12, 11, 109, 129, 32, -13, -10, 3, 97, 135, 44, -13, -8, -3, 84, 137, 57, -11}, + }, + + // Band_8_1856 + { + // Scaler inc range + {1853, 1856}, + // Coefficients 4 taps + {59, 138, 59, 0, 46, 138, 74, -2, 34, 132, 88, 2, 23, 124, 102, 7, + 14, 114, 114, 14, 7, 102, 124, 23, 2, 88, 132, 34, -2, 74, 138, 46}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -11, 57, 137, 84, -3, -8, -13, 44, 135, 97, 3, -10, -13, 32, 129, 109, 11, -12, + -13, 21, 120, 120, 21, -13, -12, 11, 109, 129, 32, -13, -10, 3, 97, 135, 44, -13, -8, -3, 84, 137, 57, -11}, + }, + + // Band_8_1859 + { + // Scaler inc range + {1856, 1859}, + // Coefficients 4 taps + {59, 138, 59, 0, 47, 136, 74, -1, 34, 132, 88, 2, 23, 124, 102, 7, + 14, 114, 114, 14, 7, 102, 124, 23, 2, 88, 132, 34, -1, 74, 136, 47}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -11, 57, 137, 84, -3, -8, -13, 44, 134, 97, 4, -10, -13, 32, 128, 109, 12, -12, + -13, 21, 120, 120, 21, -13, -12, 12, 109, 128, 32, -13, -10, 4, 97, 134, 44, -13, -8, -3, 84, 137, 57, -11}, + }, + + // Band_8_1862 + { + // Scaler inc range + {1859, 1862}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 34, 132, 88, 2, 23, 125, 101, 7, + 14, 114, 114, 14, 7, 101, 125, 23, 2, 88, 132, 34, -1, 74, 136, 47}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -11, 57, 137, 84, -3, -8, -13, 44, 134, 97, 4, -10, -13, 32, 128, 109, 12, -12, + -13, 21, 120, 120, 21, -13, -12, 12, 109, 128, 32, -13, -10, 4, 97, 134, 44, -13, -8, -3, 84, 137, 57, -11}, + }, + + // Band_8_1866 + { + // Scaler inc range + {1862, 1866}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 34, 132, 88, 2, 24, 124, 101, 7, + 15, 113, 113, 15, 7, 101, 124, 24, 2, 88, 132, 34, -1, 74, 136, 47}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -11, 57, 138, 83, -3, -8, -12, 45, 132, 97, 4, -10, -13, 33, 127, 109, 12, -12, + -13, 22, 119, 119, 22, -13, -12, 12, 109, 127, 33, -13, -10, 4, 97, 132, 45, -12, -8, -3, 83, 138, 57, -11}, + }, + + // Band_8_1869 + { + // Scaler inc range + {1866, 1869}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 34, 132, 88, 2, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 2, 88, 132, 34, -1, 74, 136, 47}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -10, 57, 136, 83, -2, -8, -12, 45, 132, 97, 4, -10, -13, 33, 127, 109, 12, -12, + -13, 22, 119, 119, 22, -13, -12, 12, 109, 127, 33, -13, -10, 4, 97, 132, 45, -12, -8, -2, 83, 136, 57, -10}, + }, + + // Band_8_1872 + { + // Scaler inc range + {1869, 1872}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 131, 88, 2, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 2, 88, 131, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -10, 57, 136, 83, -2, -8, -12, 45, 133, 96, 4, -10, -13, 33, 128, 108, 12, -12, + -13, 22, 119, 119, 22, -13, -12, 12, 108, 128, 33, -13, -10, 4, 96, 133, 45, -12, -8, -2, 83, 136, 57, -10}, + }, + + // Band_8_1876 + { + // Scaler inc range + {1872, 1876}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 131, 88, 2, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 2, 88, 131, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -10, 57, 136, 83, -2, -8, -12, 45, 133, 96, 4, -10, -13, 33, 128, 108, 12, -12, + -13, 22, 119, 119, 22, -13, -12, 12, 108, 128, 33, -13, -10, 4, 96, 133, 45, -12, -8, -2, 83, 136, 57, -10}, + }, + + // Band_8_1879 + { + // Scaler inc range + {1876, 1879}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 130, 88, 3, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 3, 88, 130, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-7, 68, 134, 68, -7, 0, -10, 57, 136, 83, -2, -8, -12, 45, 132, 96, 5, -10, -13, 33, 127, 108, 13, -12, + -13, 22, 119, 119, 22, -13, -12, 13, 108, 127, 33, -13, -10, 5, 96, 132, 45, -12, -8, -2, 83, 136, 57, -10}, + }, + + // Band_8_1883 + { + // Scaler inc range + {1879, 1883}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 130, 88, 3, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 3, 88, 130, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-6, 68, 132, 68, -6, 0, -10, 57, 136, 83, -2, -8, -12, 45, 132, 96, 5, -10, -13, 33, 127, 108, 13, -12, + -13, 22, 119, 119, 22, -13, -12, 13, 108, 127, 33, -13, -10, 5, 96, 132, 45, -12, -8, -2, 83, 136, 57, -10}, + }, + + // Band_8_1886 + { + // Scaler inc range + {1883, 1886}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 130, 88, 3, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 3, 88, 130, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-6, 68, 132, 68, -6, 0, -10, 57, 136, 83, -2, -8, -12, 45, 132, 96, 5, -10, -13, 33, 127, 108, 13, -12, + -13, 23, 118, 118, 23, -13, -12, 13, 108, 127, 33, -13, -10, 5, 96, 132, 45, -12, -8, -2, 83, 136, 57, -10}, + }, + + // Band_8_1889 + { + // Scaler inc range + {1886, 1889}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 130, 88, 3, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 3, 88, 130, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-6, 68, 132, 68, -6, 0, -10, 58, 134, 83, -1, -8, -12, 45, 132, 96, 5, -10, -13, 33, 127, 108, 13, -12, + -13, 23, 118, 118, 23, -13, -12, 13, 108, 127, 33, -13, -10, 5, 96, 132, 45, -12, -8, -1, 83, 134, 58, -10}, + }, + + // Band_8_1893 + { + // Scaler inc range + {1889, 1893}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 130, 88, 3, 24, 123, 101, 8, + 15, 113, 113, 15, 8, 101, 123, 24, 3, 88, 130, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-6, 68, 132, 68, -6, 0, -10, 58, 134, 83, -1, -8, -12, 45, 132, 96, 5, -10, -13, 34, 126, 108, 13, -12, + -12, 23, 117, 117, 23, -12, -12, 13, 108, 126, 34, -13, -10, 5, 96, 132, 45, -12, -8, -1, 83, 134, 58, -10}, + }, + + // Band_8_1896 + { + // Scaler inc range + {1893, 1896}, + // Coefficients 4 taps + {60, 136, 60, 0, 47, 136, 74, -1, 35, 130, 88, 3, 25, 122, 101, 8, + 16, 112, 112, 16, 8, 101, 122, 25, 3, 88, 130, 35, -1, 74, 136, 47}, + // Coefficients 6 taps + {-6, 68, 132, 68, -6, 0, -9, 58, 133, 83, -1, -8, -12, 45, 132, 96, 5, -10, -13, 34, 127, 107, 13, -12, + -12, 23, 117, 117, 23, -12, -12, 13, 107, 127, 34, -13, -10, 5, 96, 132, 45, -12, -8, -1, 83, 133, 58, -9}, + }, + + // Band_8_1900 + { + // Scaler inc range + {1896, 1900}, + // Coefficients 4 taps + {60, 136, 60, 0, 48, 134, 74, 0, 35, 130, 88, 3, 25, 121, 101, 9, + 16, 112, 112, 16, 9, 101, 121, 25, 3, 88, 130, 35, 0, 74, 134, 48}, + // Coefficients 6 taps + {-6, 68, 132, 68, -6, 0, -9, 58, 133, 83, -1, -8, -11, 45, 130, 96, 6, -10, -12, 34, 125, 107, 14, -12, + -12, 23, 117, 117, 23, -12, -12, 14, 107, 125, 34, -12, -10, 6, 96, 130, 45, -11, -8, -1, 83, 133, 58, -9}, + }, + + // Band_8_1903 + { + // Scaler inc range + {1900, 1903}, + // Coefficients 4 taps + {60, 136, 60, 0, 48, 134, 74, 0, 35, 130, 88, 3, 25, 121, 101, 9, + 16, 112, 112, 16, 9, 101, 121, 25, 3, 88, 130, 35, 0, 74, 134, 48}, + // Coefficients 6 taps + {-6, 68, 132, 68, -6, 0, -9, 58, 133, 83, -1, -8, -11, 46, 129, 96, 6, -10, -12, 34, 125, 107, 14, -12, + -12, 23, 117, 117, 23, -12, -12, 14, 107, 125, 34, -12, -10, 6, 96, 129, 46, -11, -8, -1, 83, 133, 58, -9}, + }, + + // Band_8_1907 + { + // Scaler inc range + {1903, 1907}, + // Coefficients 4 taps + {60, 136, 60, 0, 48, 134, 74, 0, 36, 129, 88, 3, 25, 121, 101, 9, + 16, 112, 112, 16, 9, 101, 121, 25, 3, 88, 129, 36, 0, 74, 134, 48}, + // Coefficients 6 taps + {-5, 68, 130, 68, -5, 0, -9, 58, 133, 83, -1, -8, -11, 46, 130, 95, 6, -10, -12, 34, 124, 107, 14, -11, + -12, 23, 117, 117, 23, -12, -11, 14, 107, 124, 34, -12, -10, 6, 95, 130, 46, -11, -8, -1, 83, 133, 58, -9}, + }, + + // Band_8_1910 + { + // Scaler inc range + {1907, 1910}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 134, 74, 0, 36, 129, 88, 3, 25, 122, 100, 9, + 16, 112, 112, 16, 9, 100, 122, 25, 3, 88, 129, 36, 0, 74, 134, 48}, + // Coefficients 6 taps + {-5, 68, 130, 68, -5, 0, -9, 58, 132, 83, 0, -8, -11, 46, 130, 95, 6, -10, -12, 34, 124, 107, 14, -11, + -12, 24, 116, 116, 24, -12, -11, 14, 107, 124, 34, -12, -10, 6, 95, 130, 46, -11, -8, 0, 83, 132, 58, -9}, + }, + + // Band_8_1913 + { + // Scaler inc range + {1910, 1913}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 134, 74, 0, 36, 128, 88, 4, 25, 122, 100, 9, + 16, 112, 112, 16, 9, 100, 122, 25, 4, 88, 128, 36, 0, 74, 134, 48}, + // Coefficients 6 taps + {-5, 68, 130, 68, -5, 0, -9, 58, 132, 83, 0, -8, -11, 46, 130, 95, 6, -10, -12, 34, 124, 107, 14, -11, + -12, 24, 116, 116, 24, -12, -11, 14, 107, 124, 34, -12, -10, 6, 95, 130, 46, -11, -8, 0, 83, 132, 58, -9}, + }, + + // Band_8_1917 + { + // Scaler inc range + {1913, 1917}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 134, 74, 0, 36, 128, 88, 4, 25, 122, 100, 9, + 16, 112, 112, 16, 9, 100, 122, 25, 4, 88, 128, 36, 0, 74, 134, 48}, + // Coefficients 6 taps + {-5, 68, 130, 68, -5, 0, -9, 58, 132, 83, 0, -8, -11, 46, 130, 95, 6, -10, -12, 34, 125, 106, 14, -11, + -12, 24, 116, 116, 24, -12, -11, 14, 106, 125, 34, -12, -10, 6, 95, 130, 46, -11, -8, 0, 83, 132, 58, -9}, + }, + + // Band_8_1920 + { + // Scaler inc range + {1917, 1920}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 134, 74, 0, 36, 128, 88, 4, 25, 122, 100, 9, + 16, 112, 112, 16, 9, 100, 122, 25, 4, 88, 128, 36, 0, 74, 134, 48}, + // Coefficients 6 taps + {-5, 68, 130, 68, -5, 0, -9, 58, 132, 83, 0, -8, -11, 46, 129, 95, 7, -10, -12, 35, 123, 106, 15, -11, + -12, 24, 116, 116, 24, -12, -11, 15, 106, 123, 35, -12, -10, 7, 95, 129, 46, -11, -8, 0, 83, 132, 58, -9}, + }, + + // Band_8_1924 + { + // Scaler inc range + {1920, 1924}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 133, 75, 0, 36, 128, 88, 4, 25, 122, 100, 9, + 16, 112, 112, 16, 9, 100, 122, 25, 4, 88, 128, 36, 0, 75, 133, 48}, + // Coefficients 6 taps + {-5, 68, 130, 68, -5, 0, -8, 58, 131, 83, 0, -8, -11, 46, 129, 95, 7, -10, -12, 35, 123, 106, 15, -11, + -12, 24, 116, 116, 24, -12, -11, 15, 106, 123, 35, -12, -10, 7, 95, 129, 46, -11, -8, 0, 83, 131, 58, -8}, + }, + + // Band_8_1928 + { + // Scaler inc range + {1924, 1928}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 133, 75, 0, 36, 128, 88, 4, 26, 121, 100, 9, + 17, 111, 111, 17, 9, 100, 121, 26, 4, 88, 128, 36, 0, 75, 133, 48}, + // Coefficients 6 taps + {-5, 68, 130, 68, -5, 0, -8, 58, 131, 83, 0, -8, -11, 46, 129, 95, 7, -10, -12, 35, 123, 106, 15, -11, + -12, 24, 116, 116, 24, -12, -11, 15, 106, 123, 35, -12, -10, 7, 95, 129, 46, -11, -8, 0, 83, 131, 58, -8}, + }, + + // Band_8_1931 + { + // Scaler inc range + {1928, 1931}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 133, 75, 0, 36, 128, 88, 4, 26, 121, 100, 9, + 17, 111, 111, 17, 9, 100, 121, 26, 4, 88, 128, 36, 0, 75, 133, 48}, + // Coefficients 6 taps + {-4, 68, 128, 68, -4, 0, -8, 58, 131, 83, 0, -8, -11, 46, 129, 95, 7, -10, -12, 35, 123, 106, 15, -11, + -12, 24, 116, 116, 24, -12, -11, 15, 106, 123, 35, -12, -10, 7, 95, 129, 46, -11, -8, 0, 83, 131, 58, -8}, + }, + + // Band_8_1935 + { + // Scaler inc range + {1931, 1935}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 133, 75, 0, 36, 128, 88, 4, 26, 120, 100, 10, + 17, 111, 111, 17, 10, 100, 120, 26, 4, 88, 128, 36, 0, 75, 133, 48}, + // Coefficients 6 taps + {-4, 68, 128, 68, -4, 0, -8, 58, 130, 83, 1, -8, -10, 46, 128, 95, 7, -10, -12, 35, 123, 106, 15, -11, + -12, 25, 115, 115, 25, -12, -11, 15, 106, 123, 35, -12, -10, 7, 95, 128, 46, -10, -8, 1, 83, 130, 58, -8}, + }, + + // Band_8_1938 + { + // Scaler inc range + {1935, 1938}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 133, 75, 0, 36, 128, 88, 4, 26, 120, 100, 10, + 17, 111, 111, 17, 10, 100, 120, 26, 4, 88, 128, 36, 0, 75, 133, 48}, + // Coefficients 6 taps + {-4, 68, 128, 68, -4, 0, -8, 58, 130, 83, 1, -8, -10, 46, 128, 95, 7, -10, -12, 35, 123, 106, 15, -11, + -12, 25, 115, 115, 25, -12, -11, 15, 106, 123, 35, -12, -10, 7, 95, 128, 46, -10, -8, 1, 83, 130, 58, -8}, + }, + + // Band_8_1942 + { + // Scaler inc range + {1938, 1942}, + // Coefficients 4 taps + {61, 134, 61, 0, 48, 132, 75, 1, 36, 128, 88, 4, 26, 120, 100, 10, + 17, 111, 111, 17, 10, 100, 120, 26, 4, 88, 128, 36, 1, 75, 132, 48}, + // Coefficients 6 taps + {-4, 68, 128, 68, -4, 0, -8, 58, 131, 82, 1, -8, -10, 47, 127, 94, 8, -10, -11, 35, 122, 105, 16, -11, + -12, 25, 115, 115, 25, -12, -11, 16, 105, 122, 35, -11, -10, 8, 94, 127, 47, -10, -8, 1, 82, 131, 58, -8}, + }, + + // Band_8_1945 + { + // Scaler inc range + {1942, 1945}, + // Coefficients 4 taps + {61, 134, 61, 0, 49, 131, 75, 1, 37, 127, 88, 4, 26, 120, 100, 10, + 17, 111, 111, 17, 10, 100, 120, 26, 4, 88, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-4, 68, 128, 68, -4, 0, -8, 58, 131, 82, 1, -8, -10, 47, 127, 94, 8, -10, -11, 35, 122, 105, 16, -11, + -12, 25, 115, 115, 25, -12, -11, 16, 105, 122, 35, -11, -10, 8, 94, 127, 47, -10, -8, 1, 82, 131, 58, -8}, + }, + + // Band_8_1949 + { + // Scaler inc range + {1945, 1949}, + // Coefficients 4 taps + {61, 134, 61, 0, 49, 131, 75, 1, 37, 127, 87, 5, 26, 120, 100, 10, + 17, 111, 111, 17, 10, 100, 120, 26, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-4, 68, 128, 68, -4, 0, -8, 58, 131, 82, 1, -8, -10, 47, 127, 94, 8, -10, -11, 36, 121, 105, 16, -11, + -12, 25, 115, 115, 25, -12, -11, 16, 105, 121, 36, -11, -10, 8, 94, 127, 47, -10, -8, 1, 82, 131, 58, -8}, + }, + + // Band_8_1953 + { + // Scaler inc range + {1949, 1953}, + // Coefficients 4 taps + {61, 134, 61, 0, 49, 131, 75, 1, 37, 127, 87, 5, 26, 120, 100, 10, + 17, 111, 111, 17, 10, 100, 120, 26, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-4, 68, 128, 68, -4, 0, -7, 58, 130, 82, 1, -8, -10, 47, 127, 94, 8, -10, -11, 36, 121, 105, 16, -11, + -11, 25, 114, 114, 25, -11, -11, 16, 105, 121, 36, -11, -10, 8, 94, 127, 47, -10, -8, 1, 82, 130, 58, -7}, + }, + + // Band_8_1956 + { + // Scaler inc range + {1953, 1956}, + // Coefficients 4 taps + {61, 134, 61, 0, 49, 131, 75, 1, 37, 127, 87, 5, 26, 120, 100, 10, + 17, 111, 111, 17, 10, 100, 120, 26, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-3, 68, 126, 68, -3, 0, -7, 58, 129, 82, 2, -8, -10, 47, 127, 94, 8, -10, -11, 36, 121, 105, 16, -11, + -11, 25, 114, 114, 25, -11, -11, 16, 105, 121, 36, -11, -10, 8, 94, 127, 47, -10, -8, 2, 82, 129, 58, -7}, + }, + + // Band_8_1960 + { + // Scaler inc range + {1956, 1960}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 37, 127, 87, 5, 26, 120, 100, 10, + 18, 110, 110, 18, 10, 100, 120, 26, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-3, 68, 126, 68, -3, 0, -7, 58, 129, 82, 2, -8, -10, 47, 127, 94, 8, -10, -11, 36, 121, 105, 16, -11, + -11, 26, 113, 113, 26, -11, -11, 16, 105, 121, 36, -11, -10, 8, 94, 127, 47, -10, -8, 2, 82, 129, 58, -7}, + }, + + // Band_8_1964 + { + // Scaler inc range + {1960, 1964}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 37, 127, 87, 5, 27, 120, 99, 10, + 18, 110, 110, 18, 10, 99, 120, 27, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-3, 68, 126, 68, -3, 0, -7, 58, 129, 82, 2, -8, -10, 47, 127, 94, 8, -10, -11, 36, 122, 104, 16, -11, + -11, 26, 113, 113, 26, -11, -11, 16, 104, 122, 36, -11, -10, 8, 94, 127, 47, -10, -8, 2, 82, 129, 58, -7}, + }, + + // Band_8_1967 + { + // Scaler inc range + {1964, 1967}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 37, 127, 87, 5, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-3, 68, 126, 68, -3, 0, -7, 59, 128, 82, 2, -8, -9, 47, 125, 94, 9, -10, -11, 36, 121, 104, 17, -11, + -11, 26, 113, 113, 26, -11, -11, 17, 104, 121, 36, -11, -10, 9, 94, 125, 47, -9, -8, 2, 82, 128, 59, -7}, + }, + + // Band_8_1971 + { + // Scaler inc range + {1967, 1971}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 37, 127, 87, 5, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-3, 68, 126, 68, -3, 0, -7, 59, 128, 82, 2, -8, -9, 47, 125, 94, 9, -10, -11, 36, 121, 104, 17, -11, + -11, 26, 113, 113, 26, -11, -11, 17, 104, 121, 36, -11, -10, 9, 94, 125, 47, -9, -8, 2, 82, 128, 59, -7}, + }, + + // Band_8_1975 + { + // Scaler inc range + {1971, 1975}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 37, 127, 87, 5, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-3, 68, 126, 68, -3, 0, -7, 59, 128, 82, 2, -8, -9, 47, 126, 93, 9, -10, -11, 36, 121, 104, 17, -11, + -11, 26, 113, 113, 26, -11, -11, 17, 104, 121, 36, -11, -10, 9, 93, 126, 47, -9, -8, 2, 82, 128, 59, -7}, + }, + + // Band_8_1978 + { + // Scaler inc range + {1975, 1978}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 37, 127, 87, 5, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 5, 87, 127, 37, 1, 75, 131, 49}, + // Coefficients 6 taps + {-3, 68, 126, 68, -3, 0, -6, 59, 126, 82, 3, -8, -9, 47, 126, 93, 9, -10, -11, 36, 121, 104, 17, -11, + -11, 26, 113, 113, 26, -11, -11, 17, 104, 121, 36, -11, -10, 9, 93, 126, 47, -9, -8, 3, 82, 126, 59, -6}, + }, + + // Band_8_1982 + { + // Scaler inc range + {1978, 1982}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 38, 126, 87, 5, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 5, 87, 126, 38, 1, 75, 131, 49}, + // Coefficients 6 taps + {-2, 68, 124, 68, -2, 0, -6, 59, 126, 82, 3, -8, -9, 47, 126, 93, 9, -10, -10, 37, 119, 104, 17, -11, + -11, 26, 113, 113, 26, -11, -11, 17, 104, 119, 37, -10, -10, 9, 93, 126, 47, -9, -8, 3, 82, 126, 59, -6}, + }, + + // Band_8_1986 + { + // Scaler inc range + {1982, 1986}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 131, 75, 1, 38, 126, 87, 5, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 5, 87, 126, 38, 1, 75, 131, 49}, + // Coefficients 6 taps + {-2, 68, 124, 68, -2, 0, -6, 59, 126, 82, 3, -8, -9, 47, 126, 93, 9, -10, -10, 37, 120, 103, 17, -11, + -11, 26, 113, 113, 26, -11, -11, 17, 103, 120, 37, -10, -10, 9, 93, 126, 47, -9, -8, 3, 82, 126, 59, -6}, + }, + + // Band_8_1990 + { + // Scaler inc range + {1986, 1990}, + // Coefficients 4 taps + {62, 132, 62, 0, 49, 130, 75, 2, 38, 125, 87, 6, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 6, 87, 125, 38, 2, 75, 130, 49}, + // Coefficients 6 taps + {-2, 68, 124, 68, -2, 0, -6, 59, 126, 82, 3, -8, -9, 48, 124, 93, 10, -10, -10, 37, 120, 103, 17, -11, + -11, 27, 112, 112, 27, -11, -11, 17, 103, 120, 37, -10, -10, 10, 93, 124, 48, -9, -8, 3, 82, 126, 59, -6}, + }, + + // Band_8_1993 + { + // Scaler inc range + {1990, 1993}, + // Coefficients 4 taps + {62, 132, 62, 0, 50, 129, 75, 2, 38, 125, 87, 6, 27, 119, 99, 11, + 18, 110, 110, 18, 11, 99, 119, 27, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-2, 68, 124, 68, -2, 0, -6, 59, 126, 82, 3, -8, -9, 48, 124, 93, 10, -10, -10, 37, 119, 103, 18, -11, + -11, 27, 112, 112, 27, -11, -11, 18, 103, 119, 37, -10, -10, 10, 93, 124, 48, -9, -8, 3, 82, 126, 59, -6}, + }, + + // Band_8_1997 + { + // Scaler inc range + {1993, 1997}, + // Coefficients 4 taps + {62, 132, 62, 0, 50, 129, 75, 2, 38, 125, 87, 6, 27, 119, 99, 11, + 19, 109, 109, 19, 11, 99, 119, 27, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-2, 68, 124, 68, -2, 0, -6, 59, 126, 82, 3, -8, -8, 48, 123, 93, 10, -10, -10, 37, 118, 103, 18, -10, + -11, 27, 112, 112, 27, -11, -10, 18, 103, 118, 37, -10, -10, 10, 93, 123, 48, -8, -8, 3, 82, 126, 59, -6}, + }, + + // Band_8_2001 + { + // Scaler inc range + {1997, 2001}, + // Coefficients 4 taps + {62, 132, 62, 0, 50, 129, 75, 2, 38, 125, 87, 6, 28, 118, 99, 11, + 19, 109, 109, 19, 11, 99, 118, 28, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-2, 68, 124, 68, -2, 0, -6, 59, 126, 82, 3, -8, -8, 48, 123, 93, 10, -10, -10, 37, 118, 103, 18, -10, + -11, 27, 112, 112, 27, -11, -10, 18, 103, 118, 37, -10, -10, 10, 93, 123, 48, -8, -8, 3, 82, 126, 59, -6}, + }, + + // Band_8_2005 + { + // Scaler inc range + {2001, 2005}, + // Coefficients 4 taps + {62, 132, 62, 0, 50, 129, 75, 2, 38, 125, 87, 6, 28, 117, 99, 12, + 19, 109, 109, 19, 12, 99, 117, 28, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-2, 68, 124, 68, -2, 0, -6, 59, 125, 82, 4, -8, -8, 48, 123, 93, 10, -10, -10, 37, 118, 103, 18, -10, + -11, 27, 112, 112, 27, -11, -10, 18, 103, 118, 37, -10, -10, 10, 93, 123, 48, -8, -8, 4, 82, 125, 59, -6}, + }, + + // Band_8_2009 + { + // Scaler inc range + {2005, 2009}, + // Coefficients 4 taps + {62, 132, 62, 0, 50, 129, 75, 2, 38, 125, 87, 6, 28, 117, 99, 12, + 19, 109, 109, 19, 12, 99, 117, 28, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-1, 68, 122, 68, -1, 0, -5, 59, 125, 81, 4, -8, -8, 48, 124, 92, 10, -10, -10, 37, 118, 103, 18, -10, + -10, 27, 111, 111, 27, -10, -10, 18, 103, 118, 37, -10, -10, 10, 92, 124, 48, -8, -8, 4, 81, 125, 59, -5}, + }, + + // Band_8_2013 + { + // Scaler inc range + {2009, 2013}, + // Coefficients 4 taps + {62, 132, 62, 0, 50, 129, 75, 2, 38, 125, 87, 6, 28, 117, 99, 12, + 19, 109, 109, 19, 12, 99, 117, 28, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-1, 68, 122, 68, -1, 0, -5, 59, 125, 81, 4, -8, -8, 48, 123, 92, 11, -10, -10, 37, 119, 102, 18, -10, + -10, 27, 111, 111, 27, -10, -10, 18, 102, 119, 37, -10, -10, 11, 92, 123, 48, -8, -8, 4, 81, 125, 59, -5}, + }, + + // Band_8_2016 + { + // Scaler inc range + {2013, 2016}, + // Coefficients 4 taps + {62, 132, 62, 0, 50, 129, 75, 2, 38, 125, 87, 6, 28, 118, 98, 12, + 19, 109, 109, 19, 12, 98, 118, 28, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-1, 68, 122, 68, -1, 0, -5, 59, 125, 81, 4, -8, -8, 48, 123, 92, 11, -10, -10, 37, 118, 102, 19, -10, + -10, 28, 110, 110, 28, -10, -10, 19, 102, 118, 37, -10, -10, 11, 92, 123, 48, -8, -8, 4, 81, 125, 59, -5}, + }, + + // Band_8_2020 + { + // Scaler inc range + {2016, 2020}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 129, 75, 2, 38, 125, 87, 6, 28, 118, 98, 12, + 19, 109, 109, 19, 12, 98, 118, 28, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-1, 68, 122, 68, -1, 0, -5, 59, 125, 81, 4, -8, -8, 48, 122, 92, 11, -9, -10, 38, 117, 102, 19, -10, + -10, 28, 110, 110, 28, -10, -10, 19, 102, 117, 38, -10, -9, 11, 92, 122, 48, -8, -8, 4, 81, 125, 59, -5}, + }, + + // Band_8_2024 + { + // Scaler inc range + {2020, 2024}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 129, 75, 2, 38, 125, 87, 6, 28, 118, 98, 12, + 19, 109, 109, 19, 12, 98, 118, 28, 6, 87, 125, 38, 2, 75, 129, 50}, + // Coefficients 6 taps + {-1, 68, 122, 68, -1, 0, -5, 59, 125, 81, 4, -8, -8, 48, 122, 92, 11, -9, -9, 38, 116, 102, 19, -10, + -10, 28, 110, 110, 28, -10, -10, 19, 102, 116, 38, -9, -9, 11, 92, 122, 48, -8, -8, 4, 81, 125, 59, -5}, + }, + + // Band_8_2028 + { + // Scaler inc range + {2024, 2028}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 129, 75, 2, 39, 123, 87, 7, 28, 118, 98, 12, + 19, 109, 109, 19, 12, 98, 118, 28, 7, 87, 123, 39, 2, 75, 129, 50}, + // Coefficients 6 taps + {-1, 68, 122, 68, -1, 0, -5, 59, 124, 81, 5, -8, -8, 48, 122, 92, 11, -9, -9, 38, 116, 102, 19, -10, + -10, 28, 110, 110, 28, -10, -10, 19, 102, 116, 38, -9, -9, 11, 92, 122, 48, -8, -8, 5, 81, 124, 59, -5}, + }, + + // Band_8_2032 + { + // Scaler inc range + {2028, 2032}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 129, 75, 2, 39, 123, 87, 7, 28, 118, 98, 12, + 20, 108, 108, 20, 12, 98, 118, 28, 7, 87, 123, 39, 2, 75, 129, 50}, + // Coefficients 6 taps + {-1, 68, 122, 68, -1, 0, -5, 59, 124, 81, 5, -8, -7, 48, 121, 92, 11, -9, -9, 38, 116, 102, 19, -10, + -10, 28, 110, 110, 28, -10, -10, 19, 102, 116, 38, -9, -9, 11, 92, 121, 48, -7, -8, 5, 81, 124, 59, -5}, + }, + + // Band_8_2036 + { + // Scaler inc range + {2032, 2036}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 128, 75, 3, 39, 123, 87, 7, 28, 118, 98, 12, + 20, 108, 108, 20, 12, 98, 118, 28, 7, 87, 123, 39, 3, 75, 128, 50}, + // Coefficients 6 taps + {0, 68, 120, 68, 0, 0, -4, 59, 123, 81, 5, -8, -7, 48, 121, 92, 11, -9, -9, 38, 117, 101, 19, -10, + -10, 28, 110, 110, 28, -10, -10, 19, 101, 117, 38, -9, -9, 11, 92, 121, 48, -7, -8, 5, 81, 123, 59, -4}, + }, + + // Band_8_2040 + { + // Scaler inc range + {2036, 2040}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 128, 75, 3, 39, 123, 87, 7, 29, 117, 98, 12, + 20, 108, 108, 20, 12, 98, 117, 29, 7, 87, 123, 39, 3, 75, 128, 50}, + // Coefficients 6 taps + {0, 68, 120, 68, 0, 0, -4, 59, 123, 81, 5, -8, -7, 48, 120, 92, 12, -9, -9, 38, 117, 101, 19, -10, + -10, 28, 110, 110, 28, -10, -10, 19, 101, 117, 38, -9, -9, 12, 92, 120, 48, -7, -8, 5, 81, 123, 59, -4}, + }, + + // Band_8_2044 + { + // Scaler inc range + {2040, 2044}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 128, 75, 3, 39, 123, 87, 7, 29, 116, 98, 13, + 20, 108, 108, 20, 13, 98, 116, 29, 7, 87, 123, 39, 3, 75, 128, 50}, + // Coefficients 6 taps + {0, 68, 120, 68, 0, 0, -4, 59, 123, 81, 5, -8, -7, 49, 120, 91, 12, -9, -9, 38, 116, 101, 20, -10, + -10, 28, 110, 110, 28, -10, -10, 20, 101, 116, 38, -9, -9, 12, 91, 120, 49, -7, -8, 5, 81, 123, 59, -4}, + }, + + // Band_8_2048 + { + // Scaler inc range + {2044, 2048}, + // Coefficients 4 taps + {63, 130, 63, 0, 50, 128, 75, 3, 39, 123, 87, 7, 29, 116, 98, 13, + 20, 108, 108, 20, 13, 98, 116, 29, 7, 87, 123, 39, 3, 75, 128, 50}, + // Coefficients 6 taps + {0, 68, 120, 68, 0, 0, -4, 59, 123, 81, 5, -8, -7, 49, 120, 91, 12, -9, -9, 38, 116, 101, 20, -10, + -10, 29, 109, 109, 29, -10, -10, 20, 101, 116, 38, -9, -9, 12, 91, 120, 49, -7, -8, 5, 81, 123, 59, -4}, + }, + + // Band_8_2052 + { + // Scaler inc range + {2048, 2052}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 39, 123, 87, 7, 29, 116, 98, 13, + 20, 108, 108, 20, 13, 98, 116, 29, 7, 87, 123, 39, 3, 75, 127, 51}, + // Coefficients 6 taps + {0, 68, 120, 68, 0, 0, -4, 59, 123, 81, 5, -8, -7, 49, 120, 91, 12, -9, -9, 38, 116, 101, 20, -10, + -10, 29, 109, 109, 29, -10, -10, 20, 101, 116, 38, -9, -9, 12, 91, 120, 49, -7, -8, 5, 81, 123, 59, -4}, + }, + + // Band_8_2056 + { + // Scaler inc range + {2052, 2056}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 39, 123, 87, 7, 29, 116, 98, 13, + 20, 108, 108, 20, 13, 98, 116, 29, 7, 87, 123, 39, 3, 75, 127, 51}, + // Coefficients 6 taps + {0, 68, 120, 68, 0, 0, -4, 59, 122, 81, 6, -8, -7, 49, 120, 91, 12, -9, -9, 38, 116, 101, 20, -10, + -10, 29, 109, 109, 29, -10, -10, 20, 101, 116, 38, -9, -9, 12, 91, 120, 49, -7, -8, 6, 81, 122, 59, -4}, + }, + + // Band_8_2060 + { + // Scaler inc range + {2056, 2060}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 39, 123, 87, 7, 29, 116, 98, 13, + 20, 108, 108, 20, 13, 98, 116, 29, 7, 87, 123, 39, 3, 75, 127, 51}, + // Coefficients 6 taps + {0, 68, 120, 68, 0, 0, -4, 59, 122, 81, 6, -8, -7, 49, 120, 91, 12, -9, -9, 39, 116, 100, 20, -10, + -9, 29, 108, 108, 29, -9, -10, 20, 100, 116, 39, -9, -9, 12, 91, 120, 49, -7, -8, 6, 81, 122, 59, -4}, + }, + + // Band_8_2064 + { + // Scaler inc range + {2060, 2064}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 39, 123, 87, 7, 29, 116, 98, 13, + 20, 108, 108, 20, 13, 98, 116, 29, 7, 87, 123, 39, 3, 75, 127, 51}, + // Coefficients 6 taps + {1, 68, 118, 68, 1, 0, -4, 59, 122, 81, 6, -8, -7, 49, 120, 91, 12, -9, -8, 39, 115, 100, 20, -10, + -9, 29, 108, 108, 29, -9, -10, 20, 100, 115, 39, -8, -9, 12, 91, 120, 49, -7, -8, 6, 81, 122, 59, -4}, + }, + + // Band_8_2068 + { + // Scaler inc range + {2064, 2068}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 39, 123, 87, 7, 29, 116, 98, 13, + 20, 108, 108, 20, 13, 98, 116, 29, 7, 87, 123, 39, 3, 75, 127, 51}, + // Coefficients 6 taps + {1, 68, 118, 68, 1, 0, -3, 59, 121, 81, 6, -8, -6, 49, 118, 91, 13, -9, -8, 39, 115, 100, 20, -10, + -9, 29, 108, 108, 29, -9, -10, 20, 100, 115, 39, -8, -9, 13, 91, 118, 49, -6, -8, 6, 81, 121, 59, -3}, + }, + + // Band_8_2072 + { + // Scaler inc range + {2068, 2072}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 40, 121, 87, 8, 29, 116, 98, 13, + 21, 107, 107, 21, 13, 98, 116, 29, 8, 87, 121, 40, 3, 75, 127, 51}, + // Coefficients 6 taps + {1, 68, 118, 68, 1, 0, -3, 59, 122, 80, 6, -8, -6, 49, 118, 91, 13, -9, -8, 39, 113, 100, 21, -9, + -9, 29, 108, 108, 29, -9, -9, 21, 100, 113, 39, -8, -9, 13, 91, 118, 49, -6, -8, 6, 80, 122, 59, -3}, + }, + + // Band_8_2076 + { + // Scaler inc range + {2072, 2076}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 40, 121, 87, 8, 29, 117, 97, 13, + 21, 107, 107, 21, 13, 97, 117, 29, 8, 87, 121, 40, 3, 75, 127, 51}, + // Coefficients 6 taps + {1, 68, 118, 68, 1, 0, -3, 59, 122, 80, 6, -8, -6, 49, 118, 91, 13, -9, -8, 39, 113, 100, 21, -9, + -9, 29, 108, 108, 29, -9, -9, 21, 100, 113, 39, -8, -9, 13, 91, 118, 49, -6, -8, 6, 80, 122, 59, -3}, + }, + + // Band_8_2081 + { + // Scaler inc range + {2076, 2081}, + // Coefficients 4 taps + {63, 130, 63, 0, 51, 127, 75, 3, 40, 121, 87, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 87, 121, 40, 3, 75, 127, 51}, + // Coefficients 6 taps + {1, 68, 118, 68, 1, 0, -3, 59, 121, 80, 7, -8, -6, 49, 119, 90, 13, -9, -8, 39, 113, 100, 21, -9, + -9, 29, 108, 108, 29, -9, -9, 21, 100, 113, 39, -8, -9, 13, 90, 119, 49, -6, -8, 7, 80, 121, 59, -3}, + }, + + // Band_8_2085 + { + // Scaler inc range + {2081, 2085}, + // Coefficients 4 taps + {64, 128, 64, 0, 51, 126, 75, 4, 40, 122, 86, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 86, 122, 40, 4, 75, 126, 51}, + // Coefficients 6 taps + {1, 68, 118, 68, 1, 0, -3, 59, 121, 80, 7, -8, -6, 49, 119, 90, 13, -9, -8, 39, 113, 100, 21, -9, + -9, 30, 107, 107, 30, -9, -9, 21, 100, 113, 39, -8, -9, 13, 90, 119, 49, -6, -8, 7, 80, 121, 59, -3}, + }, + + // Band_8_2089 + { + // Scaler inc range + {2085, 2089}, + // Coefficients 4 taps + {64, 128, 64, 0, 51, 126, 75, 4, 40, 122, 86, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 86, 122, 40, 4, 75, 126, 51}, + // Coefficients 6 taps + {1, 68, 118, 68, 1, 0, -3, 59, 121, 80, 7, -8, -6, 49, 119, 90, 13, -9, -8, 39, 114, 99, 21, -9, + -9, 30, 107, 107, 30, -9, -9, 21, 99, 114, 39, -8, -9, 13, 90, 119, 49, -6, -8, 7, 80, 121, 59, -3}, + }, + + // Band_8_2093 + { + // Scaler inc range + {2089, 2093}, + // Coefficients 4 taps + {64, 128, 64, 0, 51, 126, 75, 4, 40, 122, 86, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 86, 122, 40, 4, 75, 126, 51}, + // Coefficients 6 taps + {2, 68, 116, 68, 2, 0, -3, 59, 121, 80, 7, -8, -6, 49, 118, 90, 14, -9, -8, 39, 114, 99, 21, -9, + -9, 30, 107, 107, 30, -9, -9, 21, 99, 114, 39, -8, -9, 14, 90, 118, 49, -6, -8, 7, 80, 121, 59, -3}, + }, + + // Band_8_2097 + { + // Scaler inc range + {2093, 2097}, + // Coefficients 4 taps + {64, 128, 64, 0, 51, 126, 75, 4, 40, 122, 86, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 86, 122, 40, 4, 75, 126, 51}, + // Coefficients 6 taps + {2, 68, 116, 68, 2, 0, -2, 59, 120, 80, 7, -8, -6, 49, 118, 90, 14, -9, -8, 39, 114, 99, 21, -9, + -9, 30, 107, 107, 30, -9, -9, 21, 99, 114, 39, -8, -9, 14, 90, 118, 49, -6, -8, 7, 80, 120, 59, -2}, + }, + + // Band_8_2101 + { + // Scaler inc range + {2097, 2101}, + // Coefficients 4 taps + {64, 128, 64, 0, 51, 126, 75, 4, 40, 122, 86, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 86, 122, 40, 4, 75, 126, 51}, + // Coefficients 6 taps + {2, 68, 116, 68, 2, 0, -2, 59, 120, 80, 7, -8, -5, 49, 117, 90, 14, -9, -8, 39, 114, 99, 21, -9, + -9, 30, 107, 107, 30, -9, -9, 21, 99, 114, 39, -8, -9, 14, 90, 117, 49, -5, -8, 7, 80, 120, 59, -2}, + }, + + // Band_8_2106 + { + // Scaler inc range + {2101, 2106}, + // Coefficients 4 taps + {64, 128, 64, 0, 51, 126, 75, 4, 40, 122, 86, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 86, 122, 40, 4, 75, 126, 51}, + // Coefficients 6 taps + {2, 68, 116, 68, 2, 0, -2, 60, 119, 80, 7, -8, -5, 49, 117, 90, 14, -9, -7, 40, 111, 99, 22, -9, + -9, 30, 107, 107, 30, -9, -9, 22, 99, 111, 40, -7, -9, 14, 90, 117, 49, -5, -8, 7, 80, 119, 60, -2}, + }, + + // Band_8_2110 + { + // Scaler inc range + {2106, 2110}, + // Coefficients 4 taps + {64, 128, 64, 0, 51, 126, 75, 4, 40, 122, 86, 8, 30, 115, 97, 14, + 21, 107, 107, 21, 14, 97, 115, 30, 8, 86, 122, 40, 4, 75, 126, 51}, + // Coefficients 6 taps + {2, 68, 116, 68, 2, 0, -2, 60, 118, 80, 8, -8, -5, 49, 117, 90, 14, -9, -7, 40, 111, 99, 22, -9, + -9, 30, 107, 107, 30, -9, -9, 22, 99, 111, 40, -7, -9, 14, 90, 117, 49, -5, -8, 8, 80, 118, 60, -2}, + }, + + // Band_8_2114 + { + // Scaler inc range + {2110, 2114}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 125, 75, 4, 40, 121, 86, 9, 30, 115, 97, 14, + 22, 106, 106, 22, 14, 97, 115, 30, 9, 86, 121, 40, 4, 75, 125, 52}, + // Coefficients 6 taps + {2, 68, 116, 68, 2, 0, -2, 60, 118, 80, 8, -8, -5, 50, 116, 90, 14, -9, -7, 40, 112, 98, 22, -9, + -8, 30, 106, 106, 30, -8, -9, 22, 98, 112, 40, -7, -9, 14, 90, 116, 50, -5, -8, 8, 80, 118, 60, -2}, + }, + + // Band_8_2118 + { + // Scaler inc range + {2114, 2118}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 125, 75, 4, 40, 121, 86, 9, 30, 115, 97, 14, + 22, 106, 106, 22, 14, 97, 115, 30, 9, 86, 121, 40, 4, 75, 125, 52}, + // Coefficients 6 taps + {2, 68, 116, 68, 2, 0, -2, 60, 118, 80, 8, -8, -5, 50, 117, 89, 14, -9, -7, 40, 112, 98, 22, -9, + -8, 31, 105, 105, 31, -8, -9, 22, 98, 112, 40, -7, -9, 14, 89, 117, 50, -5, -8, 8, 80, 118, 60, -2}, + }, + + // Band_8_2123 + { + // Scaler inc range + {2118, 2123}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 125, 75, 4, 41, 120, 86, 9, 30, 114, 97, 15, + 22, 106, 106, 22, 15, 97, 114, 30, 9, 86, 120, 41, 4, 75, 125, 52}, + // Coefficients 6 taps + {3, 68, 114, 68, 3, 0, -2, 60, 118, 80, 8, -8, -5, 50, 116, 89, 15, -9, -7, 40, 112, 98, 22, -9, + -8, 31, 105, 105, 31, -8, -9, 22, 98, 112, 40, -7, -9, 15, 89, 116, 50, -5, -8, 8, 80, 118, 60, -2}, + }, + + // Band_8_2127 + { + // Scaler inc range + {2123, 2127}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 125, 75, 4, 41, 120, 86, 9, 31, 113, 97, 15, + 22, 106, 106, 22, 15, 97, 113, 31, 9, 86, 120, 41, 4, 75, 125, 52}, + // Coefficients 6 taps + {3, 68, 114, 68, 3, 0, -1, 60, 117, 80, 8, -8, -5, 50, 115, 89, 15, -8, -7, 40, 112, 98, 22, -9, + -8, 31, 105, 105, 31, -8, -9, 22, 98, 112, 40, -7, -8, 15, 89, 115, 50, -5, -8, 8, 80, 117, 60, -1}, + }, + + // Band_8_2131 + { + // Scaler inc range + {2127, 2131}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 125, 75, 4, 41, 120, 86, 9, 31, 113, 97, 15, + 22, 106, 106, 22, 15, 97, 113, 31, 9, 86, 120, 41, 4, 75, 125, 52}, + // Coefficients 6 taps + {3, 68, 114, 68, 3, 0, -1, 60, 117, 80, 8, -8, -5, 50, 115, 89, 15, -8, -7, 40, 112, 98, 22, -9, + -8, 31, 105, 105, 31, -8, -9, 22, 98, 112, 40, -7, -8, 15, 89, 115, 50, -5, -8, 8, 80, 117, 60, -1}, + }, + + // Band_8_2136 + { + // Scaler inc range + {2131, 2136}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 124, 75, 5, 41, 120, 86, 9, 31, 113, 97, 15, + 22, 106, 106, 22, 15, 97, 113, 31, 9, 86, 120, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {3, 68, 114, 68, 3, 0, -1, 60, 118, 79, 8, -8, -4, 50, 114, 89, 15, -8, -7, 40, 111, 98, 23, -9, + -8, 31, 105, 105, 31, -8, -9, 23, 98, 111, 40, -7, -8, 15, 89, 114, 50, -4, -8, 8, 79, 118, 60, -1}, + }, + + // Band_8_2140 + { + // Scaler inc range + {2136, 2140}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 124, 75, 5, 41, 120, 86, 9, 31, 114, 96, 15, + 22, 106, 106, 22, 15, 96, 114, 31, 9, 86, 120, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {3, 68, 114, 68, 3, 0, -1, 60, 117, 79, 9, -8, -4, 50, 114, 89, 15, -8, -7, 40, 111, 97, 23, -8, + -8, 31, 105, 105, 31, -8, -8, 23, 97, 111, 40, -7, -8, 15, 89, 114, 50, -4, -8, 9, 79, 117, 60, -1}, + }, + + // Band_8_2144 + { + // Scaler inc range + {2140, 2144}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 124, 75, 5, 41, 120, 86, 9, 31, 114, 96, 15, + 22, 106, 106, 22, 15, 96, 114, 31, 9, 86, 120, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {3, 68, 114, 68, 3, 0, -1, 60, 117, 79, 9, -8, -4, 50, 114, 89, 15, -8, -6, 40, 110, 97, 23, -8, + -8, 31, 105, 105, 31, -8, -8, 23, 97, 110, 40, -6, -8, 15, 89, 114, 50, -4, -8, 9, 79, 117, 60, -1}, + }, + + // Band_8_2149 + { + // Scaler inc range + {2144, 2149}, + // Coefficients 4 taps + {64, 128, 64, 0, 52, 124, 75, 5, 41, 120, 86, 9, 31, 114, 96, 15, + 22, 106, 106, 22, 15, 96, 114, 31, 9, 86, 120, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {3, 68, 114, 68, 3, 0, -1, 60, 117, 79, 9, -8, -4, 50, 114, 89, 15, -8, -6, 40, 110, 97, 23, -8, + -8, 31, 105, 105, 31, -8, -8, 23, 97, 110, 40, -6, -8, 15, 89, 114, 50, -4, -8, 9, 79, 117, 60, -1}, + }, + + // Band_8_2153 + { + // Scaler inc range + {2149, 2153}, + // Coefficients 4 taps + {65, 126, 65, 0, 52, 124, 75, 5, 41, 120, 86, 9, 31, 114, 96, 15, + 22, 106, 106, 22, 15, 96, 114, 31, 9, 86, 120, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {4, 68, 112, 68, 4, 0, -1, 60, 117, 79, 9, -8, -4, 50, 113, 89, 16, -8, -6, 40, 110, 97, 23, -8, + -8, 31, 105, 105, 31, -8, -8, 23, 97, 110, 40, -6, -8, 16, 89, 113, 50, -4, -8, 9, 79, 117, 60, -1}, + }, + + // Band_8_2158 + { + // Scaler inc range + {2153, 2158}, + // Coefficients 4 taps + {65, 126, 65, 0, 52, 124, 75, 5, 41, 120, 86, 9, 31, 114, 96, 15, + 23, 105, 105, 23, 15, 96, 114, 31, 9, 86, 120, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {4, 68, 112, 68, 4, 0, -1, 60, 117, 79, 9, -8, -4, 50, 114, 88, 16, -8, -6, 41, 109, 97, 23, -8, + -8, 32, 104, 104, 32, -8, -8, 23, 97, 109, 41, -6, -8, 16, 88, 114, 50, -4, -8, 9, 79, 117, 60, -1}, + }, + + // Band_8_2162 + { + // Scaler inc range + {2158, 2162}, + // Coefficients 4 taps + {65, 126, 65, 0, 52, 124, 75, 5, 41, 119, 86, 10, 31, 114, 96, 15, + 23, 105, 105, 23, 15, 96, 114, 31, 10, 86, 119, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {4, 67, 114, 67, 4, 0, 0, 60, 116, 79, 9, -8, -4, 50, 114, 88, 16, -8, -6, 41, 109, 97, 23, -8, + -7, 32, 103, 103, 32, -7, -8, 23, 97, 109, 41, -6, -8, 16, 88, 114, 50, -4, -8, 9, 79, 116, 60, 0}, + }, + + // Band_8_2166 + { + // Scaler inc range + {2162, 2166}, + // Coefficients 4 taps + {65, 126, 65, 0, 52, 124, 75, 5, 41, 119, 86, 10, 31, 113, 96, 16, + 23, 105, 105, 23, 16, 96, 113, 31, 10, 86, 119, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {4, 67, 114, 67, 4, 0, 0, 60, 116, 79, 9, -8, -4, 50, 114, 88, 16, -8, -6, 41, 110, 96, 23, -8, + -7, 32, 103, 103, 32, -7, -8, 23, 96, 110, 41, -6, -8, 16, 88, 114, 50, -4, -8, 9, 79, 116, 60, 0}, + }, + + // Band_8_2171 + { + // Scaler inc range + {2166, 2171}, + // Coefficients 4 taps + {65, 126, 65, 0, 52, 124, 75, 5, 41, 119, 86, 10, 32, 112, 96, 16, + 23, 105, 105, 23, 16, 96, 112, 32, 10, 86, 119, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {4, 67, 114, 67, 4, 0, 0, 60, 115, 79, 10, -8, -3, 50, 113, 88, 16, -8, -6, 41, 109, 96, 24, -8, + -7, 32, 103, 103, 32, -7, -8, 24, 96, 109, 41, -6, -8, 16, 88, 113, 50, -3, -8, 10, 79, 115, 60, 0}, + }, + + // Band_8_2175 + { + // Scaler inc range + {2171, 2175}, + // Coefficients 4 taps + {65, 126, 65, 0, 52, 124, 75, 5, 41, 119, 86, 10, 32, 112, 96, 16, + 23, 105, 105, 23, 16, 96, 112, 32, 10, 86, 119, 41, 5, 75, 124, 52}, + // Coefficients 6 taps + {4, 67, 114, 67, 4, 0, 0, 60, 114, 79, 10, -7, -3, 50, 113, 88, 16, -8, -6, 41, 109, 96, 24, -8, + -7, 32, 103, 103, 32, -7, -8, 24, 96, 109, 41, -6, -8, 16, 88, 113, 50, -3, -7, 10, 79, 114, 60, 0}, + }, + + // Band_8_2180 + { + // Scaler inc range + {2175, 2180}, + // Coefficients 4 taps + {65, 126, 65, 0, 52, 124, 75, 5, 42, 118, 86, 10, 32, 112, 96, 16, + 23, 105, 105, 23, 16, 96, 112, 32, 10, 86, 118, 42, 5, 75, 124, 52}, + // Coefficients 6 taps + {4, 67, 114, 67, 4, 0, 0, 60, 114, 79, 10, -7, -3, 50, 113, 88, 16, -8, -6, 41, 109, 96, 24, -8, + -7, 32, 103, 103, 32, -7, -8, 24, 96, 109, 41, -6, -8, 16, 88, 113, 50, -3, -7, 10, 79, 114, 60, 0}, + }, + + // Band_8_2185 + { + // Scaler inc range + {2180, 2185}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 123, 75, 5, 42, 118, 86, 10, 32, 112, 96, 16, + 23, 105, 105, 23, 16, 96, 112, 32, 10, 86, 118, 42, 5, 75, 123, 53}, + // Coefficients 6 taps + {4, 67, 114, 67, 4, 0, 0, 60, 114, 79, 10, -7, -3, 50, 113, 88, 16, -8, -5, 41, 108, 96, 24, -8, + -7, 32, 103, 103, 32, -7, -8, 24, 96, 108, 41, -5, -8, 16, 88, 113, 50, -3, -7, 10, 79, 114, 60, 0}, + }, + + // Band_8_2189 + { + // Scaler inc range + {2185, 2189}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 118, 86, 10, 32, 112, 96, 16, + 23, 105, 105, 23, 16, 96, 112, 32, 10, 86, 118, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {5, 67, 112, 67, 5, 0, 0, 60, 114, 79, 10, -7, -3, 50, 112, 88, 17, -8, -5, 41, 108, 96, 24, -8, + -7, 32, 103, 103, 32, -7, -8, 24, 96, 108, 41, -5, -8, 17, 88, 112, 50, -3, -7, 10, 79, 114, 60, 0}, + }, + + // Band_8_2194 + { + // Scaler inc range + {2189, 2194}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 118, 86, 10, 32, 112, 96, 16, + 23, 105, 105, 23, 16, 96, 112, 32, 10, 86, 118, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {5, 67, 112, 67, 5, 0, 1, 60, 113, 79, 10, -7, -3, 50, 113, 87, 17, -8, -5, 41, 108, 96, 24, -8, + -7, 32, 103, 103, 32, -7, -8, 24, 96, 108, 41, -5, -8, 17, 87, 113, 50, -3, -7, 10, 79, 113, 60, 1}, + }, + + // Band_8_2198 + { + // Scaler inc range + {2194, 2198}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 118, 86, 10, 32, 112, 96, 16, + 23, 105, 105, 23, 16, 96, 112, 32, 10, 86, 118, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {5, 67, 112, 67, 5, 0, 1, 60, 114, 78, 10, -7, -3, 50, 113, 87, 17, -8, -5, 41, 109, 95, 24, -8, + -7, 32, 103, 103, 32, -7, -8, 24, 95, 109, 41, -5, -8, 17, 87, 113, 50, -3, -7, 10, 78, 114, 60, 1}, + }, + + // Band_8_2203 + { + // Scaler inc range + {2198, 2203}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 118, 86, 10, 32, 112, 96, 16, + 24, 104, 104, 24, 16, 96, 112, 32, 10, 86, 118, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {5, 67, 112, 67, 5, 0, 1, 60, 113, 78, 11, -7, -3, 50, 113, 87, 17, -8, -5, 41, 108, 95, 24, -7, + -7, 33, 102, 102, 33, -7, -7, 24, 95, 108, 41, -5, -8, 17, 87, 113, 50, -3, -7, 11, 78, 113, 60, 1}, + }, + + // Band_8_2208 + { + // Scaler inc range + {2203, 2208}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 118, 86, 10, 32, 113, 95, 16, + 24, 104, 104, 24, 16, 95, 113, 32, 10, 86, 118, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {5, 67, 112, 67, 5, 0, 1, 60, 113, 78, 11, -7, -2, 51, 111, 87, 17, -8, -5, 41, 107, 95, 25, -7, + -7, 33, 102, 102, 33, -7, -7, 25, 95, 107, 41, -5, -8, 17, 87, 111, 51, -2, -7, 11, 78, 113, 60, 1}, + }, + + // Band_8_2212 + { + // Scaler inc range + {2208, 2212}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 117, 86, 11, 32, 113, 95, 16, + 24, 104, 104, 24, 16, 95, 113, 32, 11, 86, 117, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {5, 67, 112, 67, 5, 0, 1, 60, 113, 78, 11, -7, -2, 51, 111, 87, 17, -8, -5, 41, 107, 95, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 95, 107, 41, -5, -8, 17, 87, 111, 51, -2, -7, 11, 78, 113, 60, 1}, + }, + + // Band_8_2217 + { + // Scaler inc range + {2212, 2217}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 117, 86, 11, 32, 112, 95, 17, + 24, 104, 104, 24, 17, 95, 112, 32, 11, 86, 117, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {5, 67, 112, 67, 5, 0, 1, 60, 113, 78, 11, -7, -2, 51, 110, 87, 17, -7, -5, 42, 106, 95, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 95, 106, 42, -5, -7, 17, 87, 110, 51, -2, -7, 11, 78, 113, 60, 1}, + }, + + // Band_8_2222 + { + // Scaler inc range + {2217, 2222}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 117, 86, 11, 33, 111, 95, 17, + 24, 104, 104, 24, 17, 95, 111, 33, 11, 86, 117, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {6, 67, 110, 67, 6, 0, 1, 60, 113, 78, 11, -7, -2, 51, 109, 87, 18, -7, -5, 42, 106, 95, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 95, 106, 42, -5, -7, 18, 87, 109, 51, -2, -7, 11, 78, 113, 60, 1}, + }, + + // Band_8_2226 + { + // Scaler inc range + {2222, 2226}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 117, 86, 11, 33, 111, 95, 17, + 24, 104, 104, 24, 17, 95, 111, 33, 11, 86, 117, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {6, 67, 110, 67, 6, 0, 1, 60, 113, 78, 11, -7, -2, 51, 109, 87, 18, -7, -4, 42, 106, 94, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 94, 106, 42, -4, -7, 18, 87, 109, 51, -2, -7, 11, 78, 113, 60, 1}, + }, + + // Band_8_2231 + { + // Scaler inc range + {2226, 2231}, + // Coefficients 4 taps + {65, 126, 65, 0, 53, 122, 75, 6, 42, 118, 85, 11, 33, 111, 95, 17, + 24, 104, 104, 24, 17, 95, 111, 33, 11, 85, 118, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {6, 67, 110, 67, 6, 0, 2, 60, 112, 78, 11, -7, -2, 51, 109, 87, 18, -7, -4, 42, 106, 94, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 94, 106, 42, -4, -7, 18, 87, 109, 51, -2, -7, 11, 78, 112, 60, 2}, + }, + + // Band_8_2236 + { + // Scaler inc range + {2231, 2236}, + // Coefficients 4 taps + {66, 124, 66, 0, 53, 122, 75, 6, 42, 118, 85, 11, 33, 111, 95, 17, + 24, 104, 104, 24, 17, 95, 111, 33, 11, 85, 118, 42, 6, 75, 122, 53}, + // Coefficients 6 taps + {6, 67, 110, 67, 6, 0, 2, 60, 111, 78, 12, -7, -2, 51, 110, 86, 18, -7, -4, 42, 106, 94, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 94, 106, 42, -4, -7, 18, 86, 110, 51, -2, -7, 12, 78, 111, 60, 2}, + }, + + // Band_8_2241 + { + // Scaler inc range + {2236, 2241}, + // Coefficients 4 taps + {66, 124, 66, 0, 53, 122, 75, 6, 43, 117, 85, 11, 33, 111, 95, 17, + 24, 104, 104, 24, 17, 95, 111, 33, 11, 85, 117, 43, 6, 75, 122, 53}, + // Coefficients 6 taps + {6, 67, 110, 67, 6, 0, 2, 60, 111, 78, 12, -7, -2, 51, 110, 86, 18, -7, -4, 42, 106, 94, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 94, 106, 42, -4, -7, 18, 86, 110, 51, -2, -7, 12, 78, 111, 60, 2}, + }, + + // Band_8_2245 + { + // Scaler inc range + {2241, 2245}, + // Coefficients 4 taps + {66, 124, 66, 0, 53, 121, 75, 7, 43, 117, 85, 11, 33, 111, 95, 17, + 24, 104, 104, 24, 17, 95, 111, 33, 11, 85, 117, 43, 7, 75, 121, 53}, + // Coefficients 6 taps + {6, 67, 110, 67, 6, 0, 2, 60, 111, 78, 12, -7, -1, 51, 109, 86, 18, -7, -4, 42, 106, 94, 25, -7, + -6, 33, 101, 101, 33, -6, -7, 25, 94, 106, 42, -4, -7, 18, 86, 109, 51, -1, -7, 12, 78, 111, 60, 2}, + }, + + // Band_8_2250 + { + // Scaler inc range + {2245, 2250}, + // Coefficients 4 taps + {66, 124, 66, 0, 53, 121, 75, 7, 43, 117, 85, 11, 33, 111, 95, 17, + 25, 103, 103, 25, 17, 95, 111, 33, 11, 85, 117, 43, 7, 75, 121, 53}, + // Coefficients 6 taps + {6, 67, 110, 67, 6, 0, 2, 60, 111, 78, 12, -7, -1, 51, 109, 86, 18, -7, -4, 42, 105, 94, 26, -7, + -6, 34, 100, 100, 34, -6, -7, 26, 94, 105, 42, -4, -7, 18, 86, 109, 51, -1, -7, 12, 78, 111, 60, 2}, + }, + + // Band_8_2255 + { + // Scaler inc range + {2250, 2255}, + // Coefficients 4 taps + {66, 124, 66, 0, 53, 121, 75, 7, 43, 117, 85, 11, 33, 111, 95, 17, + 25, 103, 103, 25, 17, 95, 111, 33, 11, 85, 117, 43, 7, 75, 121, 53}, + // Coefficients 6 taps + {7, 67, 108, 67, 7, 0, 2, 60, 111, 78, 12, -7, -1, 51, 109, 86, 18, -7, -4, 42, 105, 94, 26, -7, + -6, 34, 100, 100, 34, -6, -7, 26, 94, 105, 42, -4, -7, 18, 86, 109, 51, -1, -7, 12, 78, 111, 60, 2}, + }, + + // Band_8_2260 + { + // Scaler inc range + {2255, 2260}, + // Coefficients 4 taps + {66, 124, 66, 0, 53, 121, 75, 7, 43, 117, 85, 11, 33, 111, 95, 17, + 25, 103, 103, 25, 17, 95, 111, 33, 11, 85, 117, 43, 7, 75, 121, 53}, + // Coefficients 6 taps + {7, 67, 108, 67, 7, 0, 2, 60, 111, 78, 12, -7, -1, 51, 108, 86, 19, -7, -4, 42, 106, 93, 26, -7, + -6, 34, 100, 100, 34, -6, -7, 26, 93, 106, 42, -4, -7, 19, 86, 108, 51, -1, -7, 12, 78, 111, 60, 2}, + }, + + // Band_8_2265 + { + // Scaler inc range + {2260, 2265}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 33, 110, 95, 18, + 25, 103, 103, 25, 18, 95, 110, 33, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {7, 67, 108, 67, 7, 0, 3, 60, 111, 77, 12, -7, -1, 51, 108, 86, 19, -7, -4, 42, 105, 93, 26, -6, + -5, 34, 99, 99, 34, -5, -6, 26, 93, 105, 42, -4, -7, 19, 86, 108, 51, -1, -7, 12, 77, 111, 60, 3}, + }, + + // Band_8_2270 + { + // Scaler inc range + {2265, 2270}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 33, 110, 95, 18, + 25, 103, 103, 25, 18, 95, 110, 33, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {7, 67, 108, 67, 7, 0, 3, 60, 110, 77, 13, -7, -1, 51, 108, 86, 19, -7, -3, 42, 104, 93, 26, -6, + -5, 34, 99, 99, 34, -5, -6, 26, 93, 104, 42, -3, -7, 19, 86, 108, 51, -1, -7, 13, 77, 110, 60, 3}, + }, + + // Band_8_2275 + { + // Scaler inc range + {2270, 2275}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 33, 110, 95, 18, + 25, 103, 103, 25, 18, 95, 110, 33, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {7, 67, 108, 67, 7, 0, 3, 60, 110, 77, 13, -7, -1, 51, 109, 85, 19, -7, -3, 42, 104, 93, 26, -6, + -5, 34, 99, 99, 34, -5, -6, 26, 93, 104, 42, -3, -7, 19, 85, 109, 51, -1, -7, 13, 77, 110, 60, 3}, + }, + + // Band_8_2280 + { + // Scaler inc range + {2275, 2280}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 34, 109, 95, 18, + 25, 103, 103, 25, 18, 95, 109, 34, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {7, 67, 108, 67, 7, 0, 3, 60, 110, 77, 13, -7, -1, 51, 109, 85, 19, -7, -3, 42, 104, 93, 26, -6, + -5, 34, 99, 99, 34, -5, -6, 26, 93, 104, 42, -3, -7, 19, 85, 109, 51, -1, -7, 13, 77, 110, 60, 3}, + }, + + // Band_8_2284 + { + // Scaler inc range + {2280, 2284}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 34, 110, 94, 18, + 25, 103, 103, 25, 18, 94, 110, 34, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {7, 67, 108, 67, 7, 0, 3, 60, 110, 77, 13, -7, 0, 51, 108, 85, 19, -7, -3, 43, 103, 93, 26, -6, + -5, 34, 99, 99, 34, -5, -6, 26, 93, 103, 43, -3, -7, 19, 85, 108, 51, 0, -7, 13, 77, 110, 60, 3}, + }, + + // Band_8_2289 + { + // Scaler inc range + {2284, 2289}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 34, 110, 94, 18, + 25, 103, 103, 25, 18, 94, 110, 34, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 3, 60, 110, 77, 13, -7, 0, 51, 108, 85, 19, -7, -3, 43, 104, 92, 26, -6, + -5, 34, 99, 99, 34, -5, -6, 26, 92, 104, 43, -3, -7, 19, 85, 108, 51, 0, -7, 13, 77, 110, 60, 3}, + }, + + // Band_8_2294 + { + // Scaler inc range + {2289, 2294}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 34, 110, 94, 18, + 25, 103, 103, 25, 18, 94, 110, 34, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 3, 60, 109, 77, 13, -6, 0, 51, 106, 85, 20, -6, -3, 43, 103, 92, 27, -6, + -5, 34, 99, 99, 34, -5, -6, 27, 92, 103, 43, -3, -6, 20, 85, 106, 51, 0, -6, 13, 77, 109, 60, 3}, + }, + + // Band_8_2300 + { + // Scaler inc range + {2294, 2300}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 120, 75, 7, 43, 116, 85, 12, 34, 110, 94, 18, + 25, 103, 103, 25, 18, 94, 110, 34, 12, 85, 116, 43, 7, 75, 120, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 3, 60, 109, 77, 13, -6, 0, 51, 106, 85, 20, -6, -3, 43, 103, 92, 27, -6, + -5, 34, 99, 99, 34, -5, -6, 27, 92, 103, 43, -3, -6, 20, 85, 106, 51, 0, -6, 13, 77, 109, 60, 3}, + }, + + // Band_8_2305 + { + // Scaler inc range + {2300, 2305}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 119, 75, 8, 44, 115, 85, 12, 34, 110, 94, 18, + 26, 102, 102, 26, 18, 94, 110, 34, 12, 85, 115, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 4, 60, 108, 77, 13, -6, 0, 51, 106, 85, 20, -6, -3, 43, 103, 92, 27, -6, + -5, 35, 98, 98, 35, -5, -6, 27, 92, 103, 43, -3, -6, 20, 85, 106, 51, 0, -6, 13, 77, 108, 60, 4}, + }, + + // Band_8_2310 + { + // Scaler inc range + {2305, 2310}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 119, 75, 8, 44, 115, 85, 12, 34, 110, 94, 18, + 26, 102, 102, 26, 18, 94, 110, 34, 12, 85, 115, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 4, 60, 107, 77, 14, -6, 0, 51, 106, 85, 20, -6, -3, 43, 103, 92, 27, -6, + -5, 35, 98, 98, 35, -5, -6, 27, 92, 103, 43, -3, -6, 20, 85, 106, 51, 0, -6, 14, 77, 107, 60, 4}, + }, + + // Band_8_2315 + { + // Scaler inc range + {2310, 2315}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 119, 75, 8, 44, 115, 85, 12, 34, 110, 94, 18, + 26, 102, 102, 26, 18, 94, 110, 34, 12, 85, 115, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 4, 60, 107, 77, 14, -6, 0, 51, 106, 85, 20, -6, -2, 43, 102, 92, 27, -6, + -4, 35, 97, 97, 35, -4, -6, 27, 92, 102, 43, -2, -6, 20, 85, 106, 51, 0, -6, 14, 77, 107, 60, 4}, + }, + + // Band_8_2320 + { + // Scaler inc range + {2315, 2320}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 119, 75, 8, 44, 114, 85, 13, 34, 109, 94, 19, + 26, 102, 102, 26, 19, 94, 109, 34, 13, 85, 114, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 4, 60, 107, 77, 14, -6, 0, 51, 107, 84, 20, -6, -2, 43, 103, 91, 27, -6, + -4, 35, 97, 97, 35, -4, -6, 27, 91, 103, 43, -2, -6, 20, 84, 107, 51, 0, -6, 14, 77, 107, 60, 4}, + }, + + // Band_8_2325 + { + // Scaler inc range + {2320, 2325}, + // Coefficients 4 taps + {66, 124, 66, 0, 54, 119, 75, 8, 44, 114, 85, 13, 34, 109, 94, 19, + 26, 102, 102, 26, 19, 94, 109, 34, 13, 85, 114, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {8, 67, 106, 67, 8, 0, 4, 60, 107, 77, 14, -6, 1, 51, 106, 84, 20, -6, -2, 43, 102, 91, 27, -5, + -4, 35, 97, 97, 35, -4, -5, 27, 91, 102, 43, -2, -6, 20, 84, 106, 51, 1, -6, 14, 77, 107, 60, 4}, + }, + + // Band_8_2330 + { + // Scaler inc range + {2325, 2330}, + // Coefficients 4 taps + {67, 122, 67, 0, 54, 119, 75, 8, 44, 114, 85, 13, 34, 109, 94, 19, + 26, 102, 102, 26, 19, 94, 109, 34, 13, 85, 114, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {9, 67, 104, 67, 9, 0, 4, 60, 108, 76, 14, -6, 1, 51, 106, 84, 20, -6, -2, 43, 102, 91, 27, -5, + -4, 35, 97, 97, 35, -4, -5, 27, 91, 102, 43, -2, -6, 20, 84, 106, 51, 1, -6, 14, 76, 108, 60, 4}, + }, + + // Band_8_2335 + { + // Scaler inc range + {2330, 2335}, + // Coefficients 4 taps + {67, 122, 67, 0, 54, 119, 75, 8, 44, 114, 85, 13, 34, 109, 94, 19, + 26, 102, 102, 26, 19, 94, 109, 34, 13, 85, 114, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {9, 67, 104, 67, 9, 0, 4, 60, 108, 76, 14, -6, 1, 51, 105, 84, 21, -6, -2, 43, 102, 91, 27, -5, + -4, 35, 97, 97, 35, -4, -5, 27, 91, 102, 43, -2, -6, 21, 84, 105, 51, 1, -6, 14, 76, 108, 60, 4}, + }, + + // Band_8_2341 + { + // Scaler inc range + {2335, 2341}, + // Coefficients 4 taps + {67, 122, 67, 0, 54, 119, 75, 8, 44, 114, 85, 13, 35, 108, 94, 19, + 26, 102, 102, 26, 19, 94, 108, 35, 13, 85, 114, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {9, 67, 104, 67, 9, 0, 5, 60, 107, 76, 14, -6, 1, 51, 105, 84, 21, -6, -2, 43, 101, 91, 28, -5, + -4, 35, 97, 97, 35, -4, -5, 28, 91, 101, 43, -2, -6, 21, 84, 105, 51, 1, -6, 14, 76, 107, 60, 5}, + }, + + // Band_8_2346 + { + // Scaler inc range + {2341, 2346}, + // Coefficients 4 taps + {67, 122, 67, 0, 54, 119, 75, 8, 44, 114, 85, 13, 35, 108, 94, 19, + 26, 102, 102, 26, 19, 94, 108, 35, 13, 85, 114, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {9, 67, 104, 67, 9, 0, 5, 60, 106, 76, 15, -6, 1, 52, 104, 84, 21, -6, -2, 43, 101, 91, 28, -5, + -4, 35, 97, 97, 35, -4, -5, 28, 91, 101, 43, -2, -6, 21, 84, 104, 52, 1, -6, 15, 76, 106, 60, 5}, + }, + + // Band_8_2351 + { + // Scaler inc range + {2346, 2351}, + // Coefficients 4 taps + {67, 122, 67, 0, 54, 119, 75, 8, 44, 114, 85, 13, 35, 108, 94, 19, + 26, 102, 102, 26, 19, 94, 108, 35, 13, 85, 114, 44, 8, 75, 119, 54}, + // Coefficients 6 taps + {9, 67, 104, 67, 9, 0, 5, 60, 106, 76, 15, -6, 1, 52, 104, 84, 21, -6, -2, 43, 101, 91, 28, -5, + -4, 35, 97, 97, 35, -4, -5, 28, 91, 101, 43, -2, -6, 21, 84, 104, 52, 1, -6, 15, 76, 106, 60, 5}, + }, + + // Band_8_2356 + { + // Scaler inc range + {2351, 2356}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 118, 75, 8, 44, 114, 85, 13, 35, 108, 94, 19, + 26, 102, 102, 26, 19, 94, 108, 35, 13, 85, 114, 44, 8, 75, 118, 55}, + // Coefficients 6 taps + {9, 67, 104, 67, 9, 0, 5, 60, 106, 76, 15, -6, 1, 52, 104, 84, 21, -6, -2, 43, 102, 90, 28, -5, + -4, 35, 97, 97, 35, -4, -5, 28, 90, 102, 43, -2, -6, 21, 84, 104, 52, 1, -6, 15, 76, 106, 60, 5}, + }, + + // Band_8_2362 + { + // Scaler inc range + {2356, 2362}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 118, 75, 8, 44, 114, 85, 13, 35, 108, 94, 19, + 27, 101, 101, 27, 19, 94, 108, 35, 13, 85, 114, 44, 8, 75, 118, 55}, + // Coefficients 6 taps + {9, 67, 104, 67, 9, 0, 5, 60, 106, 76, 15, -6, 1, 52, 105, 83, 21, -6, -1, 43, 101, 90, 28, -5, + -4, 35, 97, 97, 35, -4, -5, 28, 90, 101, 43, -1, -6, 21, 83, 105, 52, 1, -6, 15, 76, 106, 60, 5}, + }, + + // Band_8_2367 + { + // Scaler inc range + {2362, 2367}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 44, 114, 85, 13, 35, 109, 93, 19, + 27, 101, 101, 27, 19, 93, 109, 35, 13, 85, 114, 44, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 5, 60, 106, 76, 15, -6, 2, 52, 104, 83, 21, -6, -1, 43, 101, 90, 28, -5, + -3, 36, 95, 95, 36, -3, -5, 28, 90, 101, 43, -1, -6, 21, 83, 104, 52, 2, -6, 15, 76, 106, 60, 5}, + }, + + // Band_8_2372 + { + // Scaler inc range + {2367, 2372}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 44, 114, 85, 13, 35, 109, 93, 19, + 27, 101, 101, 27, 19, 93, 109, 35, 13, 85, 114, 44, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 5, 60, 106, 76, 15, -6, 2, 52, 103, 83, 21, -5, -1, 44, 100, 90, 28, -5, + -3, 36, 95, 95, 36, -3, -5, 28, 90, 100, 44, -1, -5, 21, 83, 103, 52, 2, -6, 15, 76, 106, 60, 5}, + }, + + // Band_8_2378 + { + // Scaler inc range + {2372, 2378}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 44, 113, 85, 14, 35, 108, 93, 20, + 27, 101, 101, 27, 20, 93, 108, 35, 14, 85, 113, 44, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 5, 60, 106, 76, 15, -6, 2, 52, 103, 83, 21, -5, -1, 44, 100, 90, 28, -5, + -3, 36, 95, 95, 36, -3, -5, 28, 90, 100, 44, -1, -5, 21, 83, 103, 52, 2, -6, 15, 76, 106, 60, 5}, + }, + + // Band_8_2383 + { + // Scaler inc range + {2378, 2383}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 112, 85, 14, 35, 108, 93, 20, + 27, 101, 101, 27, 20, 93, 108, 35, 14, 85, 112, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 6, 60, 105, 76, 15, -6, 2, 52, 102, 83, 22, -5, -1, 44, 100, 90, 28, -5, + -3, 36, 95, 95, 36, -3, -5, 28, 90, 100, 44, -1, -5, 22, 83, 102, 52, 2, -6, 15, 76, 105, 60, 6}, + }, + + // Band_8_2389 + { + // Scaler inc range + {2383, 2389}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 112, 85, 14, 35, 108, 93, 20, + 27, 101, 101, 27, 20, 93, 108, 35, 14, 85, 112, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 6, 60, 104, 76, 16, -6, 2, 52, 102, 83, 22, -5, -1, 44, 99, 89, 29, -4, + -3, 36, 95, 95, 36, -3, -4, 29, 89, 99, 44, -1, -5, 22, 83, 102, 52, 2, -6, 16, 76, 104, 60, 6}, + }, + + // Band_8_2394 + { + // Scaler inc range + {2389, 2394}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 112, 85, 14, 35, 108, 93, 20, + 27, 101, 101, 27, 20, 93, 108, 35, 14, 85, 112, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 6, 60, 104, 76, 16, -6, 2, 52, 102, 83, 22, -5, -1, 44, 99, 89, 29, -4, + -3, 36, 95, 95, 36, -3, -4, 29, 89, 99, 44, -1, -5, 22, 83, 102, 52, 2, -6, 16, 76, 104, 60, 6}, + }, + + // Band_8_2399 + { + // Scaler inc range + {2394, 2399}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 113, 84, 14, 35, 108, 93, 20, + 27, 101, 101, 27, 20, 93, 108, 35, 14, 84, 113, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 6, 60, 104, 75, 16, -5, 2, 52, 102, 83, 22, -5, -1, 44, 99, 89, 29, -4, + -3, 36, 95, 95, 36, -3, -4, 29, 89, 99, 44, -1, -5, 22, 83, 102, 52, 2, -5, 16, 75, 104, 60, 6}, + }, + + // Band_8_2405 + { + // Scaler inc range + {2399, 2405}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 113, 84, 14, 36, 107, 93, 20, + 27, 101, 101, 27, 20, 93, 107, 36, 14, 84, 113, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {10, 66, 104, 66, 10, 0, 6, 60, 104, 75, 16, -5, 2, 52, 102, 83, 22, -5, -1, 44, 99, 89, 29, -4, + -3, 36, 95, 95, 36, -3, -4, 29, 89, 99, 44, -1, -5, 22, 83, 102, 52, 2, -5, 16, 75, 104, 60, 6}, + }, + + // Band_8_2411 + { + // Scaler inc range + {2405, 2411}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 113, 84, 14, 36, 107, 93, 20, + 27, 101, 101, 27, 20, 93, 107, 36, 14, 84, 113, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 6, 60, 104, 75, 16, -5, 3, 52, 102, 82, 22, -5, 0, 44, 98, 89, 29, -4, + -3, 36, 95, 95, 36, -3, -4, 29, 89, 98, 44, 0, -5, 22, 82, 102, 52, 3, -5, 16, 75, 104, 60, 6}, + }, + + // Band_8_2416 + { + // Scaler inc range + {2411, 2416}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 113, 84, 14, 36, 107, 93, 20, + 27, 101, 101, 27, 20, 93, 107, 36, 14, 84, 113, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 6, 60, 104, 75, 16, -5, 3, 52, 102, 82, 22, -5, 0, 44, 98, 89, 29, -4, + -3, 36, 95, 95, 36, -3, -4, 29, 89, 98, 44, 0, -5, 22, 82, 102, 52, 3, -5, 16, 75, 104, 60, 6}, + }, + + // Band_8_2422 + { + // Scaler inc range + {2416, 2422}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 113, 84, 14, 36, 107, 93, 20, + 27, 101, 101, 27, 20, 93, 107, 36, 14, 84, 113, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 7, 60, 103, 75, 16, -5, 3, 52, 102, 82, 22, -5, 0, 44, 98, 89, 29, -4, + -2, 36, 94, 94, 36, -2, -4, 29, 89, 98, 44, 0, -5, 22, 82, 102, 52, 3, -5, 16, 75, 103, 60, 7}, + }, + + // Band_8_2427 + { + // Scaler inc range + {2422, 2427}, + // Coefficients 4 taps + {67, 122, 67, 0, 55, 117, 75, 9, 45, 113, 84, 14, 36, 107, 93, 20, + 28, 100, 100, 28, 20, 93, 107, 36, 14, 84, 113, 45, 9, 75, 117, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 7, 60, 103, 75, 16, -5, 3, 52, 101, 82, 23, -5, 0, 44, 99, 88, 29, -4, + -2, 36, 94, 94, 36, -2, -4, 29, 88, 99, 44, 0, -5, 23, 82, 101, 52, 3, -5, 16, 75, 103, 60, 7}, + }, + + // Band_8_2433 + { + // Scaler inc range + {2427, 2433}, + // Coefficients 4 taps + {68, 120, 68, 0, 55, 116, 75, 10, 45, 113, 84, 14, 36, 107, 93, 20, + 28, 100, 100, 28, 20, 93, 107, 36, 14, 84, 113, 45, 10, 75, 116, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 7, 60, 102, 75, 17, -5, 3, 52, 101, 82, 23, -5, 0, 44, 99, 88, 29, -4, + -2, 37, 93, 93, 37, -2, -4, 29, 88, 99, 44, 0, -5, 23, 82, 101, 52, 3, -5, 17, 75, 102, 60, 7}, + }, + + // Band_8_2439 + { + // Scaler inc range + {2433, 2439}, + // Coefficients 4 taps + {68, 120, 68, 0, 55, 116, 75, 10, 45, 112, 84, 15, 36, 106, 93, 21, + 28, 100, 100, 28, 21, 93, 106, 36, 15, 84, 112, 45, 10, 75, 116, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 7, 60, 102, 75, 17, -5, 3, 52, 101, 82, 23, -5, 0, 44, 99, 88, 29, -4, + -2, 37, 93, 93, 37, -2, -4, 29, 88, 99, 44, 0, -5, 23, 82, 101, 52, 3, -5, 17, 75, 102, 60, 7}, + }, + + // Band_8_2444 + { + // Scaler inc range + {2439, 2444}, + // Coefficients 4 taps + {68, 120, 68, 0, 55, 116, 75, 10, 45, 112, 84, 15, 36, 106, 93, 21, + 28, 100, 100, 28, 21, 93, 106, 36, 15, 84, 112, 45, 10, 75, 116, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 7, 60, 102, 75, 17, -5, 3, 52, 101, 82, 23, -5, 0, 44, 98, 88, 30, -4, + -2, 37, 93, 93, 37, -2, -4, 30, 88, 98, 44, 0, -5, 23, 82, 101, 52, 3, -5, 17, 75, 102, 60, 7}, + }, + + // Band_8_2450 + { + // Scaler inc range + {2444, 2450}, + // Coefficients 4 taps + {68, 120, 68, 0, 55, 116, 75, 10, 45, 112, 84, 15, 36, 106, 93, 21, + 28, 100, 100, 28, 21, 93, 106, 36, 15, 84, 112, 45, 10, 75, 116, 55}, + // Coefficients 6 taps + {11, 66, 102, 66, 11, 0, 7, 60, 102, 75, 17, -5, 3, 52, 100, 82, 23, -4, 0, 44, 97, 88, 30, -3, + -2, 37, 93, 93, 37, -2, -3, 30, 88, 97, 44, 0, -4, 23, 82, 100, 52, 3, -5, 17, 75, 102, 60, 7}, + }, + + // Band_8_2456 + { + // Scaler inc range + {2450, 2456}, + // Coefficients 4 taps + {68, 120, 68, 0, 55, 116, 75, 10, 45, 112, 84, 15, 36, 107, 92, 21, + 28, 100, 100, 28, 21, 92, 107, 36, 15, 84, 112, 45, 10, 75, 116, 55}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 7, 60, 102, 75, 17, -5, 4, 52, 99, 82, 23, -4, 0, 44, 97, 88, 30, -3, + -2, 37, 93, 93, 37, -2, -3, 30, 88, 97, 44, 0, -4, 23, 82, 99, 52, 4, -5, 17, 75, 102, 60, 7}, + }, + + // Band_8_2461 + { + // Scaler inc range + {2456, 2461}, + // Coefficients 4 taps + {68, 120, 68, 0, 55, 116, 75, 10, 45, 112, 84, 15, 36, 107, 92, 21, + 28, 100, 100, 28, 21, 92, 107, 36, 15, 84, 112, 45, 10, 75, 116, 55}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 7, 60, 102, 75, 17, -5, 4, 52, 100, 81, 23, -4, 1, 44, 96, 88, 30, -3, + -2, 37, 93, 93, 37, -2, -3, 30, 88, 96, 44, 1, -4, 23, 81, 100, 52, 4, -5, 17, 75, 102, 60, 7}, + }, + + // Band_8_2467 + { + // Scaler inc range + {2461, 2467}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 115, 75, 10, 46, 111, 84, 15, 36, 107, 92, 21, + 28, 100, 100, 28, 21, 92, 107, 36, 15, 84, 111, 46, 10, 75, 115, 56}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 8, 60, 101, 75, 17, -5, 4, 52, 100, 81, 23, -4, 1, 44, 97, 87, 30, -3, + -2, 37, 93, 93, 37, -2, -3, 30, 87, 97, 44, 1, -4, 23, 81, 100, 52, 4, -5, 17, 75, 101, 60, 8}, + }, + + // Band_8_2473 + { + // Scaler inc range + {2467, 2473}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 115, 75, 10, 46, 111, 84, 15, 36, 107, 92, 21, + 28, 100, 100, 28, 21, 92, 107, 36, 15, 84, 111, 46, 10, 75, 115, 56}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 8, 60, 102, 74, 17, -5, 4, 52, 100, 81, 23, -4, 1, 44, 97, 87, 30, -3, + -1, 37, 92, 92, 37, -1, -3, 30, 87, 97, 44, 1, -4, 23, 81, 100, 52, 4, -5, 17, 74, 102, 60, 8}, + }, + + // Band_8_2479 + { + // Scaler inc range + {2473, 2479}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 115, 75, 10, 46, 111, 84, 15, 37, 106, 92, 21, + 28, 100, 100, 28, 21, 92, 106, 37, 15, 84, 111, 46, 10, 75, 115, 56}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 8, 60, 101, 74, 18, -5, 4, 52, 99, 81, 24, -4, 1, 44, 97, 87, 30, -3, + -1, 37, 92, 92, 37, -1, -3, 30, 87, 97, 44, 1, -4, 24, 81, 99, 52, 4, -5, 18, 74, 101, 60, 8}, + }, + + // Band_8_2485 + { + // Scaler inc range + {2479, 2485}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 115, 75, 10, 46, 111, 84, 15, 37, 106, 92, 21, + 28, 100, 100, 28, 21, 92, 106, 37, 15, 84, 111, 46, 10, 75, 115, 56}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 8, 60, 101, 74, 18, -5, 4, 52, 99, 81, 24, -4, 1, 45, 96, 87, 30, -3, + -1, 37, 92, 92, 37, -1, -3, 30, 87, 96, 45, 1, -4, 24, 81, 99, 52, 4, -5, 18, 74, 101, 60, 8}, + }, + + // Band_8_2491 + { + // Scaler inc range + {2485, 2491}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 115, 75, 10, 46, 111, 84, 15, 37, 106, 92, 21, + 29, 99, 99, 29, 21, 92, 106, 37, 15, 84, 111, 46, 10, 75, 115, 56}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 8, 60, 101, 74, 18, -5, 4, 52, 99, 81, 24, -4, 1, 45, 96, 87, 30, -3, + -1, 37, 92, 92, 37, -1, -3, 30, 87, 96, 45, 1, -4, 24, 81, 99, 52, 4, -5, 18, 74, 101, 60, 8}, + }, + + // Band_8_2497 + { + // Scaler inc range + {2491, 2497}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 115, 75, 10, 46, 111, 84, 15, 37, 106, 92, 21, + 29, 99, 99, 29, 21, 92, 106, 37, 15, 84, 111, 46, 10, 75, 115, 56}, + // Coefficients 6 taps + {12, 66, 100, 66, 12, 0, 8, 60, 100, 74, 18, -4, 4, 52, 99, 81, 24, -4, 1, 45, 96, 87, 30, -3, + -1, 37, 92, 92, 37, -1, -3, 30, 87, 96, 45, 1, -4, 24, 81, 99, 52, 4, -4, 18, 74, 100, 60, 8}, + }, + + // Band_8_2503 + { + // Scaler inc range + {2497, 2503}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 111, 84, 15, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 15, 84, 111, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 8, 60, 100, 74, 18, -4, 4, 52, 99, 81, 24, -4, 1, 45, 96, 87, 30, -3, + -1, 37, 92, 92, 37, -1, -3, 30, 87, 96, 45, 1, -4, 24, 81, 99, 52, 4, -4, 18, 74, 100, 60, 8}, + }, + + // Band_8_2509 + { + // Scaler inc range + {2503, 2509}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 8, 60, 100, 74, 18, -4, 5, 52, 99, 80, 24, -4, 2, 45, 95, 86, 31, -3, + -1, 37, 92, 92, 37, -1, -3, 31, 86, 95, 45, 2, -4, 24, 80, 99, 52, 5, -4, 18, 74, 100, 60, 8}, + }, + + // Band_8_2515 + { + // Scaler inc range + {2509, 2515}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 9, 60, 99, 74, 18, -4, 5, 52, 99, 80, 24, -4, 2, 45, 94, 86, 31, -2, + -1, 38, 91, 91, 38, -1, -2, 31, 86, 94, 45, 2, -4, 24, 80, 99, 52, 5, -4, 18, 74, 99, 60, 9}, + }, + + // Band_8_2521 + { + // Scaler inc range + {2515, 2521}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 9, 60, 99, 74, 18, -4, 5, 52, 99, 80, 24, -4, 2, 45, 94, 86, 31, -2, + -1, 38, 91, 91, 38, -1, -2, 31, 86, 94, 45, 2, -4, 24, 80, 99, 52, 5, -4, 18, 74, 99, 60, 9}, + }, + + // Band_8_2527 + { + // Scaler inc range + {2521, 2527}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 9, 60, 98, 74, 19, -4, 5, 52, 98, 80, 24, -3, 2, 45, 94, 86, 31, -2, + -1, 38, 91, 91, 38, -1, -2, 31, 86, 94, 45, 2, -3, 24, 80, 98, 52, 5, -4, 19, 74, 98, 60, 9}, + }, + + // Band_8_2533 + { + // Scaler inc range + {2527, 2533}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 9, 60, 98, 74, 19, -4, 5, 52, 97, 80, 25, -3, 2, 45, 94, 86, 31, -2, + 0, 38, 90, 90, 38, 0, -2, 31, 86, 94, 45, 2, -3, 25, 80, 97, 52, 5, -4, 19, 74, 98, 60, 9}, + }, + + // Band_8_2539 + { + // Scaler inc range + {2533, 2539}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 9, 60, 98, 74, 19, -4, 5, 52, 97, 80, 25, -3, 2, 45, 94, 86, 31, -2, + 0, 38, 90, 90, 38, 0, -2, 31, 86, 94, 45, 2, -3, 25, 80, 97, 52, 5, -4, 19, 74, 98, 60, 9}, + }, + + // Band_8_2545 + { + // Scaler inc range + {2539, 2545}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {13, 66, 98, 66, 13, 0, 9, 60, 99, 73, 19, -4, 5, 52, 97, 80, 25, -3, 2, 45, 95, 85, 31, -2, + 0, 38, 90, 90, 38, 0, -2, 31, 85, 95, 45, 2, -3, 25, 80, 97, 52, 5, -4, 19, 73, 99, 60, 9}, + }, + + // Band_8_2551 + { + // Scaler inc range + {2545, 2551}, + // Coefficients 4 taps + {68, 120, 68, 0, 56, 114, 75, 11, 46, 110, 84, 16, 37, 105, 92, 22, + 29, 99, 99, 29, 22, 92, 105, 37, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {14, 66, 96, 66, 14, 0, 9, 60, 99, 73, 19, -4, 5, 52, 97, 80, 25, -3, 2, 45, 95, 85, 31, -2, + 0, 38, 90, 90, 38, 0, -2, 31, 85, 95, 45, 2, -3, 25, 80, 97, 52, 5, -4, 19, 73, 99, 60, 9}, + }, + + // Band_8_2558 + { + // Scaler inc range + {2551, 2558}, + // Coefficients 4 taps + {69, 118, 69, 0, 56, 114, 75, 11, 46, 110, 84, 16, 38, 105, 91, 22, + 29, 99, 99, 29, 22, 91, 105, 38, 16, 84, 110, 46, 11, 75, 114, 56}, + // Coefficients 6 taps + {14, 66, 96, 66, 14, 0, 9, 59, 100, 73, 19, -4, 6, 52, 96, 80, 25, -3, 2, 45, 95, 85, 31, -2, + 0, 38, 90, 90, 38, 0, -2, 31, 85, 95, 45, 2, -3, 25, 80, 96, 52, 6, -4, 19, 73, 100, 59, 9}, + }, + + // Band_8_2564 + { + // Scaler inc range + {2558, 2564}, + // Coefficients 4 taps + {69, 118, 69, 0, 56, 114, 75, 11, 47, 109, 84, 16, 38, 105, 91, 22, + 30, 98, 98, 30, 22, 91, 105, 38, 16, 84, 109, 47, 11, 75, 114, 56}, + // Coefficients 6 taps + {14, 65, 98, 65, 14, 0, 10, 59, 99, 73, 19, -4, 6, 52, 97, 79, 25, -3, 3, 45, 94, 85, 31, -2, + 0, 38, 90, 90, 38, 0, -2, 31, 85, 94, 45, 3, -3, 25, 79, 97, 52, 6, -4, 19, 73, 99, 59, 10}, + }, + + // Band_8_2570 + { + // Scaler inc range + {2564, 2570}, + // Coefficients 4 taps + {69, 118, 69, 0, 56, 114, 75, 11, 47, 109, 84, 16, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 16, 84, 109, 47, 11, 75, 114, 56}, + // Coefficients 6 taps + {14, 65, 98, 65, 14, 0, 10, 59, 99, 73, 19, -4, 6, 52, 97, 79, 25, -3, 3, 45, 94, 85, 31, -2, + 0, 38, 90, 90, 38, 0, -2, 31, 85, 94, 45, 3, -3, 25, 79, 97, 52, 6, -4, 19, 73, 99, 59, 10}, + }, + + // Band_8_2576 + { + // Scaler inc range + {2570, 2576}, + // Coefficients 4 taps + {69, 118, 69, 0, 56, 114, 75, 11, 47, 108, 84, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 84, 108, 47, 11, 75, 114, 56}, + // Coefficients 6 taps + {14, 65, 98, 65, 14, 0, 10, 59, 99, 73, 19, -4, 6, 52, 97, 79, 25, -3, 3, 45, 93, 85, 32, -2, + 0, 38, 90, 90, 38, 0, -2, 32, 85, 93, 45, 3, -3, 25, 79, 97, 52, 6, -4, 19, 73, 99, 59, 10}, + }, + + // Band_8_2583 + { + // Scaler inc range + {2576, 2583}, + // Coefficients 4 taps + {69, 118, 69, 0, 56, 113, 75, 12, 47, 108, 84, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 84, 108, 47, 12, 75, 113, 56}, + // Coefficients 6 taps + {14, 65, 98, 65, 14, 0, 10, 59, 98, 73, 20, -4, 6, 52, 97, 79, 25, -3, 3, 45, 92, 85, 32, -1, + 0, 38, 90, 90, 38, 0, -1, 32, 85, 92, 45, 3, -3, 25, 79, 97, 52, 6, -4, 20, 73, 98, 59, 10}, + }, + + // Band_8_2589 + { + // Scaler inc range + {2583, 2589}, + // Coefficients 4 taps + {69, 118, 69, 0, 56, 113, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 113, 56}, + // Coefficients 6 taps + {14, 65, 98, 65, 14, 0, 10, 59, 97, 73, 20, -3, 6, 52, 97, 79, 25, -3, 3, 45, 93, 84, 32, -1, + 1, 38, 89, 89, 38, 1, -1, 32, 84, 93, 45, 3, -3, 25, 79, 97, 52, 6, -3, 20, 73, 97, 59, 10}, + }, + + // Band_8_2595 + { + // Scaler inc range + {2589, 2595}, + // Coefficients 4 taps + {69, 118, 69, 0, 56, 113, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 113, 56}, + // Coefficients 6 taps + {14, 65, 98, 65, 14, 0, 10, 59, 97, 73, 20, -3, 6, 52, 96, 79, 26, -3, 3, 45, 93, 84, 32, -1, + 1, 38, 89, 89, 38, 1, -1, 32, 84, 93, 45, 3, -3, 26, 79, 96, 52, 6, -3, 20, 73, 97, 59, 10}, + }, + + // Band_8_2602 + { + // Scaler inc range + {2595, 2602}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 10, 59, 97, 73, 20, -3, 6, 52, 96, 79, 26, -3, 3, 45, 93, 84, 32, -1, + 1, 38, 89, 89, 38, 1, -1, 32, 84, 93, 45, 3, -3, 26, 79, 96, 52, 6, -3, 20, 73, 97, 59, 10}, + }, + + // Band_8_2608 + { + // Scaler inc range + {2602, 2608}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 10, 59, 97, 73, 20, -3, 7, 52, 94, 79, 26, -2, 3, 45, 93, 84, 32, -1, + 1, 39, 88, 88, 39, 1, -1, 32, 84, 93, 45, 3, -2, 26, 79, 94, 52, 7, -3, 20, 73, 97, 59, 10}, + }, + + // Band_8_2615 + { + // Scaler inc range + {2608, 2615}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 11, 59, 96, 73, 20, -3, 7, 52, 94, 79, 26, -2, 3, 45, 93, 84, 32, -1, + 1, 39, 88, 88, 39, 1, -1, 32, 84, 93, 45, 3, -2, 26, 79, 94, 52, 7, -3, 20, 73, 96, 59, 11}, + }, + + // Band_8_2621 + { + // Scaler inc range + {2615, 2621}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 11, 59, 96, 73, 20, -3, 7, 52, 95, 78, 26, -2, 4, 45, 92, 84, 32, -1, + 1, 39, 88, 88, 39, 1, -1, 32, 84, 92, 45, 4, -2, 26, 78, 95, 52, 7, -3, 20, 73, 96, 59, 11}, + }, + + // Band_8_2628 + { + // Scaler inc range + {2621, 2628}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 11, 59, 97, 72, 20, -3, 7, 52, 95, 78, 26, -2, 4, 45, 92, 84, 32, -1, + 1, 39, 88, 88, 39, 1, -1, 32, 84, 92, 45, 4, -2, 26, 78, 95, 52, 7, -3, 20, 72, 97, 59, 11}, + }, + + // Band_8_2635 + { + // Scaler inc range + {2628, 2635}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 11, 59, 97, 72, 20, -3, 7, 52, 95, 78, 26, -2, 4, 46, 92, 83, 32, -1, + 1, 39, 88, 88, 39, 1, -1, 32, 83, 92, 46, 4, -2, 26, 78, 95, 52, 7, -3, 20, 72, 97, 59, 11}, + }, + + // Band_8_2641 + { + // Scaler inc range + {2635, 2641}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 38, 104, 91, 23, + 30, 98, 98, 30, 23, 91, 104, 38, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 11, 59, 96, 72, 21, -3, 7, 52, 95, 78, 26, -2, 4, 46, 92, 83, 32, -1, + 1, 39, 88, 88, 39, 1, -1, 32, 83, 92, 46, 4, -2, 26, 78, 95, 52, 7, -3, 21, 72, 96, 59, 11}, + }, + + // Band_8_2648 + { + // Scaler inc range + {2641, 2648}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 109, 83, 17, 39, 102, 91, 24, + 31, 97, 97, 31, 24, 91, 102, 39, 17, 83, 109, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {15, 65, 96, 65, 15, 0, 11, 59, 96, 72, 21, -3, 7, 52, 95, 78, 26, -2, 4, 46, 92, 83, 32, -1, + 1, 39, 88, 88, 39, 1, -1, 32, 83, 92, 46, 4, -2, 26, 78, 95, 52, 7, -3, 21, 72, 96, 59, 11}, + }, + + // Band_8_2655 + { + // Scaler inc range + {2648, 2655}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 108, 83, 18, 39, 102, 91, 24, + 31, 97, 97, 31, 24, 91, 102, 39, 18, 83, 108, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 11, 59, 96, 72, 21, -3, 7, 52, 95, 78, 26, -2, 4, 46, 90, 83, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 83, 90, 46, 4, -2, 26, 78, 95, 52, 7, -3, 21, 72, 96, 59, 11}, + }, + + // Band_8_2661 + { + // Scaler inc range + {2655, 2661}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 112, 75, 12, 47, 108, 83, 18, 39, 102, 91, 24, + 31, 97, 97, 31, 24, 91, 102, 39, 18, 83, 108, 47, 12, 75, 112, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 11, 59, 96, 72, 21, -3, 8, 52, 93, 78, 27, -2, 4, 46, 90, 83, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 83, 90, 46, 4, -2, 27, 78, 93, 52, 8, -3, 21, 72, 96, 59, 11}, + }, + + // Band_8_2668 + { + // Scaler inc range + {2661, 2668}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 111, 75, 13, 47, 108, 83, 18, 39, 102, 91, 24, + 31, 97, 97, 31, 24, 91, 102, 39, 18, 83, 108, 47, 13, 75, 111, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 11, 59, 96, 72, 21, -3, 8, 52, 93, 78, 27, -2, 4, 46, 90, 83, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 83, 90, 46, 4, -2, 27, 78, 93, 52, 8, -3, 21, 72, 96, 59, 11}, + }, + + // Band_8_2675 + { + // Scaler inc range + {2668, 2675}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 12, 59, 95, 72, 21, -3, 8, 52, 93, 78, 27, -2, 4, 46, 90, 83, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 83, 90, 46, 4, -2, 27, 78, 93, 52, 8, -3, 21, 72, 95, 59, 12}, + }, + + // Band_8_2682 + { + // Scaler inc range + {2675, 2682}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 12, 59, 95, 72, 21, -3, 8, 52, 94, 77, 27, -2, 5, 46, 89, 83, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 83, 89, 46, 5, -2, 27, 77, 94, 52, 8, -3, 21, 72, 95, 59, 12}, + }, + + // Band_8_2689 + { + // Scaler inc range + {2682, 2689}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 12, 59, 94, 72, 21, -2, 8, 52, 93, 77, 27, -1, 5, 46, 90, 82, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 82, 90, 46, 5, -1, 27, 77, 93, 52, 8, -2, 21, 72, 94, 59, 12}, + }, + + // Band_8_2696 + { + // Scaler inc range + {2689, 2696}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 12, 59, 94, 72, 21, -2, 8, 52, 93, 77, 27, -1, 5, 46, 90, 82, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 82, 90, 46, 5, -1, 27, 77, 93, 52, 8, -2, 21, 72, 94, 59, 12}, + }, + + // Band_8_2703 + { + // Scaler inc range + {2696, 2703}, + // Coefficients 4 taps + {69, 118, 69, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {16, 65, 94, 65, 16, 0, 12, 59, 93, 72, 22, -2, 8, 52, 93, 77, 27, -1, 5, 46, 90, 82, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 82, 90, 46, 5, -1, 27, 77, 93, 52, 8, -2, 22, 72, 93, 59, 12}, + }, + + // Band_8_2709 + { + // Scaler inc range + {2703, 2709}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 12, 59, 94, 71, 22, -2, 8, 52, 93, 77, 27, -1, 5, 46, 90, 82, 33, 0, + 2, 39, 87, 87, 39, 2, 0, 33, 82, 90, 46, 5, -1, 27, 77, 93, 52, 8, -2, 22, 71, 94, 59, 12}, + }, + + // Band_8_2717 + { + // Scaler inc range + {2709, 2717}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 12, 59, 94, 71, 22, -2, 8, 53, 92, 77, 27, -1, 5, 46, 90, 82, 33, 0, + 3, 39, 86, 86, 39, 3, 0, 33, 82, 90, 46, 5, -1, 27, 77, 92, 53, 8, -2, 22, 71, 94, 59, 12}, + }, + + // Band_8_2724 + { + // Scaler inc range + {2717, 2724}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 103, 90, 24, + 31, 97, 97, 31, 24, 90, 103, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 12, 59, 94, 71, 22, -2, 9, 53, 91, 77, 27, -1, 5, 46, 89, 82, 33, 1, + 3, 40, 85, 85, 40, 3, 1, 33, 82, 89, 46, 5, -1, 27, 77, 91, 53, 9, -2, 22, 71, 94, 59, 12}, + }, + + // Band_8_2731 + { + // Scaler inc range + {2724, 2731}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 111, 75, 13, 48, 107, 83, 18, 39, 102, 90, 25, + 32, 96, 96, 32, 25, 90, 102, 39, 18, 83, 107, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 13, 59, 93, 71, 22, -2, 9, 53, 91, 77, 27, -1, 5, 46, 89, 82, 33, 1, + 3, 40, 85, 85, 40, 3, 1, 33, 82, 89, 46, 5, -1, 27, 77, 91, 53, 9, -2, 22, 71, 93, 59, 13}, + }, + + // Band_8_2738 + { + // Scaler inc range + {2731, 2738}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 111, 75, 13, 48, 106, 83, 19, 39, 102, 90, 25, + 32, 96, 96, 32, 25, 90, 102, 39, 19, 83, 106, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 13, 59, 93, 71, 22, -2, 9, 53, 90, 77, 28, -1, 6, 46, 89, 81, 33, 1, + 3, 40, 85, 85, 40, 3, 1, 33, 81, 89, 46, 6, -1, 28, 77, 90, 53, 9, -2, 22, 71, 93, 59, 13}, + }, + + // Band_8_2745 + { + // Scaler inc range + {2738, 2745}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 111, 75, 13, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 13, 75, 111, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 13, 59, 93, 71, 22, -2, 9, 53, 91, 76, 28, -1, 6, 46, 88, 81, 34, 1, + 3, 40, 85, 85, 40, 3, 1, 34, 81, 88, 46, 6, -1, 28, 76, 91, 53, 9, -2, 22, 71, 93, 59, 13}, + }, + + // Band_8_2752 + { + // Scaler inc range + {2745, 2752}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 110, 75, 14, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 14, 75, 110, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 13, 59, 93, 71, 22, -2, 9, 53, 91, 76, 28, -1, 6, 46, 88, 81, 34, 1, + 3, 40, 85, 85, 40, 3, 1, 34, 81, 88, 46, 6, -1, 28, 76, 91, 53, 9, -2, 22, 71, 93, 59, 13}, + }, + + // Band_8_2759 + { + // Scaler inc range + {2752, 2759}, + // Coefficients 4 taps + {70, 116, 70, 0, 57, 110, 75, 14, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 14, 75, 110, 57}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 13, 59, 93, 71, 22, -2, 9, 53, 91, 76, 28, -1, 6, 46, 88, 81, 34, 1, + 3, 40, 85, 85, 40, 3, 1, 34, 81, 88, 46, 6, -1, 28, 76, 91, 53, 9, -2, 22, 71, 93, 59, 13}, + }, + + // Band_8_2767 + { + // Scaler inc range + {2759, 2767}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 14, 75, 109, 58}, + // Coefficients 6 taps + {17, 65, 92, 65, 17, 0, 13, 59, 92, 71, 23, -2, 9, 53, 91, 76, 28, -1, 6, 46, 88, 81, 34, 1, + 3, 40, 85, 85, 40, 3, 1, 34, 81, 88, 46, 6, -1, 28, 76, 91, 53, 9, -2, 23, 71, 92, 59, 13}, + }, + + // Band_8_2774 + { + // Scaler inc range + {2767, 2774}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 65, 90, 65, 18, 0, 13, 59, 92, 71, 23, -2, 9, 53, 90, 76, 28, 0, 6, 46, 88, 81, 34, 1, + 3, 40, 85, 85, 40, 3, 1, 34, 81, 88, 46, 6, 0, 28, 76, 90, 53, 9, -2, 23, 71, 92, 59, 13}, + }, + + // Band_8_2781 + { + // Scaler inc range + {2774, 2781}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 13, 59, 92, 71, 23, -2, 9, 53, 90, 76, 28, 0, 6, 46, 88, 81, 34, 1, + 3, 40, 85, 85, 40, 3, 1, 34, 81, 88, 46, 6, 0, 28, 76, 90, 53, 9, -2, 23, 71, 92, 59, 13}, + }, + + // Band_8_2789 + { + // Scaler inc range + {2781, 2789}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 13, 59, 91, 71, 23, -1, 10, 53, 89, 76, 28, 0, 6, 46, 89, 80, 34, 1, + 4, 40, 84, 84, 40, 4, 1, 34, 80, 89, 46, 6, 0, 28, 76, 89, 53, 10, -1, 23, 71, 91, 59, 13}, + }, + + // Band_8_2796 + { + // Scaler inc range + {2789, 2796}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 48, 106, 83, 19, 40, 101, 90, 25, + 32, 96, 96, 32, 25, 90, 101, 40, 19, 83, 106, 48, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 14, 59, 90, 71, 23, -1, 10, 53, 89, 76, 28, 0, 6, 46, 89, 80, 34, 1, + 4, 40, 84, 84, 40, 4, 1, 34, 80, 89, 46, 6, 0, 28, 76, 89, 53, 10, -1, 23, 71, 90, 59, 14}, + }, + + // Band_8_2804 + { + // Scaler inc range + {2796, 2804}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 49, 105, 83, 19, 40, 102, 89, 25, + 32, 96, 96, 32, 25, 89, 102, 40, 19, 83, 105, 49, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 14, 59, 91, 70, 23, -1, 10, 53, 89, 76, 28, 0, 7, 46, 87, 80, 34, 2, + 4, 40, 84, 84, 40, 4, 2, 34, 80, 87, 46, 7, 0, 28, 76, 89, 53, 10, -1, 23, 70, 91, 59, 14}, + }, + + // Band_8_2811 + { + // Scaler inc range + {2804, 2811}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 49, 105, 83, 19, 40, 102, 89, 25, + 32, 96, 96, 32, 25, 89, 102, 40, 19, 83, 105, 49, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 14, 59, 91, 70, 23, -1, 10, 53, 89, 76, 28, 0, 7, 46, 87, 80, 34, 2, + 4, 40, 84, 84, 40, 4, 2, 34, 80, 87, 46, 7, 0, 28, 76, 89, 53, 10, -1, 23, 70, 91, 59, 14}, + }, + + // Band_8_2819 + { + // Scaler inc range + {2811, 2819}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 49, 105, 83, 19, 40, 102, 89, 25, + 32, 96, 96, 32, 25, 89, 102, 40, 19, 83, 105, 49, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 14, 59, 91, 70, 23, -1, 10, 53, 89, 75, 29, 0, 7, 46, 87, 80, 34, 2, + 4, 40, 84, 84, 40, 4, 2, 34, 80, 87, 46, 7, 0, 29, 75, 89, 53, 10, -1, 23, 70, 91, 59, 14}, + }, + + // Band_8_2826 + { + // Scaler inc range + {2819, 2826}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 49, 106, 82, 19, 40, 101, 89, 26, + 32, 96, 96, 32, 26, 89, 101, 40, 19, 82, 106, 49, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 14, 59, 91, 70, 23, -1, 10, 53, 89, 75, 29, 0, 7, 46, 87, 80, 34, 2, + 4, 40, 84, 84, 40, 4, 2, 34, 80, 87, 46, 7, 0, 29, 75, 89, 53, 10, -1, 23, 70, 91, 59, 14}, + }, + + // Band_8_2834 + { + // Scaler inc range + {2826, 2834}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 49, 105, 82, 20, 40, 101, 89, 26, + 33, 95, 95, 33, 26, 89, 101, 40, 20, 82, 105, 49, 14, 75, 109, 58}, + // Coefficients 6 taps + {18, 64, 92, 64, 18, 0, 14, 59, 91, 70, 23, -1, 10, 53, 89, 75, 29, 0, 7, 46, 87, 80, 34, 2, + 4, 40, 84, 84, 40, 4, 2, 34, 80, 87, 46, 7, 0, 29, 75, 89, 53, 10, -1, 23, 70, 91, 59, 14}, + }, + + // Band_8_2842 + { + // Scaler inc range + {2834, 2842}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 109, 75, 14, 49, 105, 82, 20, 40, 101, 89, 26, + 33, 95, 95, 33, 26, 89, 101, 40, 20, 82, 105, 49, 14, 75, 109, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 14, 59, 90, 70, 24, -1, 10, 53, 89, 75, 29, 0, 7, 46, 87, 80, 34, 2, + 4, 40, 84, 84, 40, 4, 2, 34, 80, 87, 46, 7, 0, 29, 75, 89, 53, 10, -1, 24, 70, 90, 59, 14}, + }, + + // Band_8_2849 + { + // Scaler inc range + {2842, 2849}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 108, 75, 15, 49, 105, 82, 20, 40, 101, 89, 26, + 33, 95, 95, 33, 26, 89, 101, 40, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 14, 59, 90, 70, 24, -1, 10, 53, 89, 75, 29, 0, 7, 46, 88, 79, 34, 2, + 4, 40, 84, 84, 40, 4, 2, 34, 79, 88, 46, 7, 0, 29, 75, 89, 53, 10, -1, 24, 70, 90, 59, 14}, + }, + + // Band_8_2857 + { + // Scaler inc range + {2849, 2857}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 108, 75, 15, 49, 105, 82, 20, 40, 101, 89, 26, + 33, 95, 95, 33, 26, 89, 101, 40, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 14, 59, 90, 70, 24, -1, 11, 53, 88, 75, 29, 0, 7, 46, 87, 79, 35, 2, + 4, 40, 84, 84, 40, 4, 2, 35, 79, 87, 46, 7, 0, 29, 75, 88, 53, 11, -1, 24, 70, 90, 59, 14}, + }, + + // Band_8_2865 + { + // Scaler inc range + {2857, 2865}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 15, 59, 89, 70, 24, -1, 11, 53, 87, 75, 29, 1, 7, 46, 87, 79, 35, 2, + 5, 40, 83, 83, 40, 5, 2, 35, 79, 87, 46, 7, 1, 29, 75, 87, 53, 11, -1, 24, 70, 89, 59, 15}, + }, + + // Band_8_2873 + { + // Scaler inc range + {2865, 2873}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 15, 59, 89, 70, 24, -1, 11, 53, 87, 75, 29, 1, 7, 46, 87, 79, 35, 2, + 5, 41, 82, 82, 41, 5, 2, 35, 79, 87, 46, 7, 1, 29, 75, 87, 53, 11, -1, 24, 70, 89, 59, 15}, + }, + + // Band_8_2881 + { + // Scaler inc range + {2873, 2881}, + // Coefficients 4 taps + {70, 116, 70, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 15, 59, 89, 70, 24, -1, 11, 53, 87, 75, 29, 1, 8, 47, 84, 79, 35, 3, + 5, 41, 82, 82, 41, 5, 3, 35, 79, 84, 47, 8, 1, 29, 75, 87, 53, 11, -1, 24, 70, 89, 59, 15}, + }, + + // Band_8_2889 + { + // Scaler inc range + {2881, 2889}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 15, 59, 88, 70, 24, 0, 11, 53, 88, 74, 29, 1, 8, 47, 84, 79, 35, 3, + 5, 41, 82, 82, 41, 5, 3, 35, 79, 84, 47, 8, 1, 29, 74, 88, 53, 11, 0, 24, 70, 88, 59, 15}, + }, + + // Band_8_2897 + { + // Scaler inc range + {2889, 2897}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 15, 59, 88, 70, 24, 0, 11, 53, 88, 74, 29, 1, 8, 47, 84, 79, 35, 3, + 5, 41, 82, 82, 41, 5, 3, 35, 79, 84, 47, 8, 1, 29, 74, 88, 53, 11, 0, 24, 70, 88, 59, 15}, + }, + + // Band_8_2905 + { + // Scaler inc range + {2897, 2905}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {19, 64, 90, 64, 19, 0, 15, 58, 90, 69, 24, 0, 11, 53, 88, 74, 29, 1, 8, 47, 84, 79, 35, 3, + 5, 41, 82, 82, 41, 5, 3, 35, 79, 84, 47, 8, 1, 29, 74, 88, 53, 11, 0, 24, 69, 90, 58, 15}, + }, + + // Band_8_2913 + { + // Scaler inc range + {2905, 2913}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 15, 58, 90, 69, 24, 0, 11, 53, 87, 74, 30, 1, 8, 47, 85, 78, 35, 3, + 5, 41, 82, 82, 41, 5, 3, 35, 78, 85, 47, 8, 1, 30, 74, 87, 53, 11, 0, 24, 69, 90, 58, 15}, + }, + + // Band_8_2921 + { + // Scaler inc range + {2913, 2921}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 100, 89, 26, + 33, 95, 95, 33, 26, 89, 100, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 15, 58, 89, 69, 25, 0, 11, 53, 87, 74, 30, 1, 8, 47, 85, 78, 35, 3, + 5, 41, 82, 82, 41, 5, 3, 35, 78, 85, 47, 8, 1, 30, 74, 87, 53, 11, 0, 25, 69, 89, 58, 15}, + }, + + // Band_8_2929 + { + // Scaler inc range + {2921, 2929}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 105, 82, 20, 41, 99, 89, 27, + 33, 95, 95, 33, 27, 89, 99, 41, 20, 82, 105, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 15, 58, 89, 69, 25, 0, 12, 53, 86, 74, 30, 1, 8, 47, 85, 78, 35, 3, + 5, 41, 82, 82, 41, 5, 3, 35, 78, 85, 47, 8, 1, 30, 74, 86, 53, 12, 0, 25, 69, 89, 58, 15}, + }, + + // Band_8_2937 + { + // Scaler inc range + {2929, 2937}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 104, 82, 21, 41, 99, 89, 27, + 34, 94, 94, 34, 27, 89, 99, 41, 21, 82, 104, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 16, 58, 88, 69, 25, 0, 12, 53, 86, 74, 30, 1, 8, 47, 85, 78, 35, 3, + 6, 41, 81, 81, 41, 6, 3, 35, 78, 85, 47, 8, 1, 30, 74, 86, 53, 12, 0, 25, 69, 88, 58, 16}, + }, + + // Band_8_2945 + { + // Scaler inc range + {2937, 2945}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 49, 104, 82, 21, 41, 99, 89, 27, + 34, 94, 94, 34, 27, 89, 99, 41, 21, 82, 104, 49, 15, 75, 108, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 16, 58, 88, 69, 25, 0, 12, 53, 86, 74, 30, 1, 8, 47, 85, 78, 35, 3, + 6, 41, 81, 81, 41, 6, 3, 35, 78, 85, 47, 8, 1, 30, 74, 86, 53, 12, 0, 25, 69, 88, 58, 16}, + }, + + // Band_8_2954 + { + // Scaler inc range + {2945, 2954}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 108, 75, 15, 50, 103, 82, 21, 41, 100, 88, 27, + 34, 94, 94, 34, 27, 88, 100, 41, 21, 82, 103, 50, 15, 75, 108, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 16, 58, 88, 69, 25, 0, 12, 53, 85, 74, 30, 2, 9, 47, 84, 78, 35, 3, + 6, 41, 81, 81, 41, 6, 3, 35, 78, 84, 47, 9, 2, 30, 74, 85, 53, 12, 0, 25, 69, 88, 58, 16}, + }, + + // Band_8_2962 + { + // Scaler inc range + {2954, 2962}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 107, 75, 16, 50, 103, 82, 21, 41, 100, 88, 27, + 34, 94, 94, 34, 27, 88, 100, 41, 21, 82, 103, 50, 16, 75, 107, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 16, 58, 88, 69, 25, 0, 12, 53, 85, 74, 30, 2, 9, 47, 84, 78, 35, 3, + 6, 41, 81, 81, 41, 6, 3, 35, 78, 84, 47, 9, 2, 30, 74, 85, 53, 12, 0, 25, 69, 88, 58, 16}, + }, + + // Band_8_2970 + { + // Scaler inc range + {2962, 2970}, + // Coefficients 4 taps + {71, 114, 71, 0, 58, 107, 75, 16, 50, 103, 82, 21, 41, 100, 88, 27, + 34, 94, 94, 34, 27, 88, 100, 41, 21, 82, 103, 50, 16, 75, 107, 58}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 16, 58, 88, 69, 25, 0, 12, 53, 86, 73, 30, 2, 9, 47, 83, 78, 35, 4, + 6, 41, 81, 81, 41, 6, 4, 35, 78, 83, 47, 9, 2, 30, 73, 86, 53, 12, 0, 25, 69, 88, 58, 16}, + }, + + // Band_8_2979 + { + // Scaler inc range + {2970, 2979}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 41, 100, 88, 27, + 34, 94, 94, 34, 27, 88, 100, 41, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {20, 64, 88, 64, 20, 0, 16, 58, 88, 69, 25, 0, 12, 53, 86, 73, 30, 2, 9, 47, 83, 77, 36, 4, + 6, 41, 81, 81, 41, 6, 4, 36, 77, 83, 47, 9, 2, 30, 73, 86, 53, 12, 0, 25, 69, 88, 58, 16}, + }, + + // Band_8_2987 + { + // Scaler inc range + {2979, 2987}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 41, 100, 88, 27, + 34, 94, 94, 34, 27, 88, 100, 41, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 64, 86, 64, 21, 0, 16, 58, 88, 69, 25, 0, 12, 53, 86, 73, 30, 2, 9, 47, 83, 77, 36, 4, + 6, 41, 81, 81, 41, 6, 4, 36, 77, 83, 47, 9, 2, 30, 73, 86, 53, 12, 0, 25, 69, 88, 58, 16}, + }, + + // Band_8_2996 + { + // Scaler inc range + {2987, 2996}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 42, 99, 88, 27, + 34, 94, 94, 34, 27, 88, 99, 42, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 64, 86, 64, 21, 0, 16, 58, 87, 69, 25, 1, 12, 53, 86, 73, 30, 2, 9, 47, 83, 77, 36, 4, + 6, 41, 81, 81, 41, 6, 4, 36, 77, 83, 47, 9, 2, 30, 73, 86, 53, 12, 1, 25, 69, 87, 58, 16}, + }, + + // Band_8_3005 + { + // Scaler inc range + {2996, 3005}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 42, 99, 88, 27, + 34, 94, 94, 34, 27, 88, 99, 42, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 64, 86, 64, 21, 0, 16, 58, 87, 69, 25, 1, 13, 53, 85, 73, 30, 2, 9, 47, 83, 77, 36, 4, + 6, 41, 81, 81, 41, 6, 4, 36, 77, 83, 47, 9, 2, 30, 73, 85, 53, 13, 1, 25, 69, 87, 58, 16}, + }, + + // Band_8_3013 + { + // Scaler inc range + {3005, 3013}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 42, 99, 88, 27, + 34, 94, 94, 34, 27, 88, 99, 42, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 64, 86, 64, 21, 0, 17, 58, 86, 68, 26, 1, 13, 53, 85, 73, 30, 2, 9, 47, 83, 77, 36, 4, + 6, 41, 81, 81, 41, 6, 4, 36, 77, 83, 47, 9, 2, 30, 73, 85, 53, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3022 + { + // Scaler inc range + {3013, 3022}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 42, 99, 88, 27, + 34, 94, 94, 34, 27, 88, 99, 42, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 64, 86, 64, 21, 0, 17, 58, 86, 68, 26, 1, 13, 53, 84, 73, 31, 2, 9, 47, 83, 77, 36, 4, + 7, 41, 80, 80, 41, 7, 4, 36, 77, 83, 47, 9, 2, 31, 73, 84, 53, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3031 + { + // Scaler inc range + {3022, 3031}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 42, 99, 88, 27, + 34, 94, 94, 34, 27, 88, 99, 42, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 63, 88, 63, 21, 0, 17, 58, 86, 68, 26, 1, 13, 53, 84, 73, 31, 2, 10, 47, 82, 77, 36, 4, + 7, 41, 80, 80, 41, 7, 4, 36, 77, 82, 47, 10, 2, 31, 73, 84, 53, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3039 + { + // Scaler inc range + {3031, 3039}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 103, 82, 21, 42, 98, 88, 28, + 34, 94, 94, 34, 28, 88, 98, 42, 21, 82, 103, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 63, 88, 63, 21, 0, 17, 58, 86, 68, 26, 1, 13, 53, 84, 73, 31, 2, 10, 47, 82, 77, 36, 4, + 7, 41, 80, 80, 41, 7, 4, 36, 77, 82, 47, 10, 2, 31, 73, 84, 53, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3048 + { + // Scaler inc range + {3039, 3048}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 102, 82, 22, 42, 98, 88, 28, + 34, 94, 94, 34, 28, 88, 98, 42, 22, 82, 102, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 63, 88, 63, 21, 0, 17, 58, 86, 68, 26, 1, 13, 53, 84, 73, 31, 2, 10, 47, 83, 76, 36, 4, + 7, 41, 80, 80, 41, 7, 4, 36, 76, 83, 47, 10, 2, 31, 73, 84, 53, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3057 + { + // Scaler inc range + {3048, 3057}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 102, 82, 22, 42, 98, 88, 28, + 34, 94, 94, 34, 28, 88, 98, 42, 22, 82, 102, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 63, 88, 63, 21, 0, 17, 58, 86, 68, 26, 1, 13, 53, 84, 72, 31, 3, 10, 47, 82, 76, 36, 5, + 7, 41, 80, 80, 41, 7, 5, 36, 76, 82, 47, 10, 3, 31, 72, 84, 53, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3066 + { + // Scaler inc range + {3057, 3066}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 106, 75, 16, 50, 102, 82, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 82, 102, 50, 16, 75, 106, 59}, + // Coefficients 6 taps + {21, 63, 88, 63, 21, 0, 17, 58, 86, 68, 26, 1, 13, 53, 84, 72, 31, 3, 10, 47, 82, 76, 36, 5, + 7, 41, 80, 80, 41, 7, 5, 36, 76, 82, 47, 10, 3, 31, 72, 84, 53, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3075 + { + // Scaler inc range + {3066, 3075}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 105, 75, 17, 50, 102, 82, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 82, 102, 50, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 17, 58, 86, 68, 26, 1, 13, 52, 85, 72, 31, 3, 10, 47, 82, 76, 36, 5, + 7, 42, 79, 79, 42, 7, 5, 36, 76, 82, 47, 10, 3, 31, 72, 85, 52, 13, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3084 + { + // Scaler inc range + {3075, 3084}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 105, 75, 17, 50, 102, 82, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 82, 102, 50, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 17, 58, 86, 68, 26, 1, 14, 52, 84, 72, 31, 3, 10, 47, 82, 76, 36, 5, + 7, 42, 79, 79, 42, 7, 5, 36, 76, 82, 47, 10, 3, 31, 72, 84, 52, 14, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3093 + { + // Scaler inc range + {3084, 3093}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 105, 75, 17, 50, 102, 82, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 82, 102, 50, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 17, 58, 86, 68, 26, 1, 14, 52, 84, 72, 31, 3, 10, 47, 82, 76, 36, 5, + 7, 42, 79, 79, 42, 7, 5, 36, 76, 82, 47, 10, 3, 31, 72, 84, 52, 14, 1, 26, 68, 86, 58, 17}, + }, + + // Band_8_3102 + { + // Scaler inc range + {3093, 3102}, + // Coefficients 4 taps + {71, 114, 71, 0, 59, 105, 75, 17, 50, 102, 82, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 82, 102, 50, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 18, 58, 85, 68, 26, 1, 14, 52, 84, 72, 31, 3, 10, 47, 82, 76, 36, 5, + 7, 42, 79, 79, 42, 7, 5, 36, 76, 82, 47, 10, 3, 31, 72, 84, 52, 14, 1, 26, 68, 85, 58, 18}, + }, + + // Band_8_3112 + { + // Scaler inc range + {3102, 3112}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 50, 103, 81, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 81, 103, 50, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 18, 58, 84, 68, 26, 2, 14, 52, 84, 72, 31, 3, 10, 47, 82, 76, 36, 5, + 8, 42, 78, 78, 42, 8, 5, 36, 76, 82, 47, 10, 3, 31, 72, 84, 52, 14, 2, 26, 68, 84, 58, 18}, + }, + + // Band_8_3121 + { + // Scaler inc range + {3112, 3121}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 50, 103, 81, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 81, 103, 50, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 18, 58, 83, 68, 27, 2, 14, 52, 84, 72, 31, 3, 11, 47, 82, 75, 36, 5, + 8, 42, 78, 78, 42, 8, 5, 36, 75, 82, 47, 11, 3, 31, 72, 84, 52, 14, 2, 27, 68, 83, 58, 18}, + }, + + // Band_8_3130 + { + // Scaler inc range + {3121, 3130}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 50, 103, 81, 22, 42, 98, 88, 28, + 35, 93, 93, 35, 28, 88, 98, 42, 22, 81, 103, 50, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 18, 58, 83, 68, 27, 2, 14, 52, 84, 72, 31, 3, 11, 47, 81, 75, 37, 5, + 8, 42, 78, 78, 42, 8, 5, 37, 75, 81, 47, 11, 3, 31, 72, 84, 52, 14, 2, 27, 68, 83, 58, 18}, + }, + + // Band_8_3139 + { + // Scaler inc range + {3130, 3139}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 51, 102, 81, 22, 42, 99, 87, 28, + 35, 93, 93, 35, 28, 87, 99, 42, 22, 81, 102, 51, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 18, 58, 84, 67, 27, 2, 14, 52, 83, 72, 32, 3, 11, 47, 81, 75, 37, 5, + 8, 42, 78, 78, 42, 8, 5, 37, 75, 81, 47, 11, 3, 32, 72, 83, 52, 14, 2, 27, 67, 84, 58, 18}, + }, + + // Band_8_3149 + { + // Scaler inc range + {3139, 3149}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 51, 102, 81, 22, 43, 98, 87, 28, + 35, 93, 93, 35, 28, 87, 98, 43, 22, 81, 102, 51, 17, 75, 105, 59}, + // Coefficients 6 taps + {22, 63, 86, 63, 22, 0, 18, 58, 84, 67, 27, 2, 14, 52, 84, 71, 32, 3, 11, 47, 81, 75, 37, 5, + 8, 42, 78, 78, 42, 8, 5, 37, 75, 81, 47, 11, 3, 32, 71, 84, 52, 14, 2, 27, 67, 84, 58, 18}, + }, + + // Band_8_3158 + { + // Scaler inc range + {3149, 3158}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 51, 102, 81, 22, 43, 98, 87, 28, + 35, 93, 93, 35, 28, 87, 98, 43, 22, 81, 102, 51, 17, 75, 105, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 18, 58, 84, 67, 27, 2, 14, 52, 83, 71, 32, 4, 11, 47, 80, 75, 37, 6, + 8, 42, 78, 78, 42, 8, 6, 37, 75, 80, 47, 11, 4, 32, 71, 83, 52, 14, 2, 27, 67, 84, 58, 18}, + }, + + // Band_8_3168 + { + // Scaler inc range + {3158, 3168}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 51, 101, 81, 23, 43, 97, 87, 29, + 35, 93, 93, 35, 29, 87, 97, 43, 23, 81, 101, 51, 17, 75, 105, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 18, 58, 84, 67, 27, 2, 14, 52, 83, 71, 32, 4, 11, 47, 80, 75, 37, 6, + 8, 42, 78, 78, 42, 8, 6, 37, 75, 80, 47, 11, 4, 32, 71, 83, 52, 14, 2, 27, 67, 84, 58, 18}, + }, + + // Band_8_3178 + { + // Scaler inc range + {3168, 3178}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 51, 101, 81, 23, 43, 97, 87, 29, + 35, 93, 93, 35, 29, 87, 97, 43, 23, 81, 101, 51, 17, 75, 105, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 18, 58, 84, 67, 27, 2, 15, 52, 82, 71, 32, 4, 11, 47, 80, 75, 37, 6, + 8, 42, 78, 78, 42, 8, 6, 37, 75, 80, 47, 11, 4, 32, 71, 82, 52, 15, 2, 27, 67, 84, 58, 18}, + }, + + // Band_8_3187 + { + // Scaler inc range + {3178, 3187}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 51, 101, 81, 23, 43, 97, 87, 29, + 35, 93, 93, 35, 29, 87, 97, 43, 23, 81, 101, 51, 17, 75, 105, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 18, 58, 84, 67, 27, 2, 15, 52, 82, 71, 32, 4, 11, 47, 80, 75, 37, 6, + 8, 42, 78, 78, 42, 8, 6, 37, 75, 80, 47, 11, 4, 32, 71, 82, 52, 15, 2, 27, 67, 84, 58, 18}, + }, + + // Band_8_3197 + { + // Scaler inc range + {3187, 3197}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 105, 75, 17, 51, 101, 81, 23, 43, 97, 87, 29, + 35, 93, 93, 35, 29, 87, 97, 43, 23, 81, 101, 51, 17, 75, 105, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 19, 58, 83, 67, 27, 2, 15, 52, 82, 71, 32, 4, 11, 47, 80, 75, 37, 6, + 8, 42, 78, 78, 42, 8, 6, 37, 75, 80, 47, 11, 4, 32, 71, 82, 52, 15, 2, 27, 67, 83, 58, 19}, + }, + + // Band_8_3207 + { + // Scaler inc range + {3197, 3207}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 104, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 104, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 19, 58, 83, 67, 27, 2, 15, 52, 82, 71, 32, 4, 11, 47, 81, 74, 37, 6, + 9, 42, 77, 77, 42, 9, 6, 37, 74, 81, 47, 11, 4, 32, 71, 82, 52, 15, 2, 27, 67, 83, 58, 19}, + }, + + // Band_8_3216 + { + // Scaler inc range + {3207, 3216}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 104, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 104, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 19, 58, 83, 67, 27, 2, 15, 52, 82, 71, 32, 4, 12, 47, 80, 74, 37, 6, + 9, 42, 77, 77, 42, 9, 6, 37, 74, 80, 47, 12, 4, 32, 71, 82, 52, 15, 2, 27, 67, 83, 58, 19}, + }, + + // Band_8_3226 + { + // Scaler inc range + {3216, 3226}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 104, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 104, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 19, 58, 83, 67, 27, 2, 15, 52, 82, 71, 32, 4, 12, 47, 80, 74, 37, 6, + 9, 42, 77, 77, 42, 9, 6, 37, 74, 80, 47, 12, 4, 32, 71, 82, 52, 15, 2, 27, 67, 83, 58, 19}, + }, + + // Band_8_3236 + { + // Scaler inc range + {3226, 3236}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 104, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 104, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 19, 58, 81, 67, 28, 3, 15, 52, 82, 71, 32, 4, 12, 47, 80, 74, 37, 6, + 9, 42, 77, 77, 42, 9, 6, 37, 74, 80, 47, 12, 4, 32, 71, 82, 52, 15, 3, 28, 67, 81, 58, 19}, + }, + + // Band_8_3246 + { + // Scaler inc range + {3236, 3246}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 104, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 104, 59}, + // Coefficients 6 taps + {23, 63, 84, 63, 23, 0, 19, 57, 82, 67, 28, 3, 15, 52, 83, 70, 32, 4, 12, 47, 80, 74, 37, 6, + 9, 42, 77, 77, 42, 9, 6, 37, 74, 80, 47, 12, 4, 32, 70, 83, 52, 15, 3, 28, 67, 82, 57, 19}, + }, + + // Band_8_3256 + { + // Scaler inc range + {3246, 3256}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 104, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 104, 59}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 19, 57, 82, 67, 28, 3, 15, 52, 83, 70, 32, 4, 12, 47, 79, 74, 37, 7, + 9, 42, 77, 77, 42, 9, 7, 37, 74, 79, 47, 12, 4, 32, 70, 83, 52, 15, 3, 28, 67, 82, 57, 19}, + }, + + // Band_8_3267 + { + // Scaler inc range + {3256, 3267}, + // Coefficients 4 taps + {72, 112, 72, 0, 59, 104, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 104, 59}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 19, 57, 83, 66, 28, 3, 15, 52, 83, 70, 32, 4, 12, 47, 79, 74, 37, 7, + 9, 42, 77, 77, 42, 9, 7, 37, 74, 79, 47, 12, 4, 32, 70, 83, 52, 15, 3, 28, 66, 83, 57, 19}, + }, + + // Band_8_3277 + { + // Scaler inc range + {3267, 3277}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 19, 57, 83, 66, 28, 3, 16, 52, 81, 70, 32, 5, 12, 47, 79, 74, 37, 7, + 9, 42, 77, 77, 42, 9, 7, 37, 74, 79, 47, 12, 5, 32, 70, 81, 52, 16, 3, 28, 66, 83, 57, 19}, + }, + + // Band_8_3287 + { + // Scaler inc range + {3277, 3287}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 19, 57, 83, 66, 28, 3, 16, 52, 80, 70, 33, 5, 12, 47, 80, 73, 37, 7, + 9, 42, 77, 77, 42, 9, 7, 37, 73, 80, 47, 12, 5, 33, 70, 80, 52, 16, 3, 28, 66, 83, 57, 19}, + }, + + // Band_8_3297 + { + // Scaler inc range + {3287, 3297}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 101, 81, 23, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 23, 81, 101, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 20, 57, 82, 66, 28, 3, 16, 52, 80, 70, 33, 5, 12, 47, 80, 73, 37, 7, + 9, 42, 77, 77, 42, 9, 7, 37, 73, 80, 47, 12, 5, 33, 70, 80, 52, 16, 3, 28, 66, 82, 57, 20}, + }, + + // Band_8_3308 + { + // Scaler inc range + {3297, 3308}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 100, 81, 24, 43, 97, 87, 29, + 36, 92, 92, 36, 29, 87, 97, 43, 24, 81, 100, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 20, 57, 82, 66, 28, 3, 16, 52, 80, 70, 33, 5, 12, 47, 80, 73, 37, 7, + 10, 42, 76, 76, 42, 10, 7, 37, 73, 80, 47, 12, 5, 33, 70, 80, 52, 16, 3, 28, 66, 82, 57, 20}, + }, + + // Band_8_3318 + { + // Scaler inc range + {3308, 3318}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 100, 81, 24, 43, 96, 87, 30, + 36, 92, 92, 36, 30, 87, 96, 43, 24, 81, 100, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 20, 57, 82, 66, 28, 3, 16, 52, 80, 70, 33, 5, 13, 47, 79, 73, 37, 7, + 10, 42, 76, 76, 42, 10, 7, 37, 73, 79, 47, 13, 5, 33, 70, 80, 52, 16, 3, 28, 66, 82, 57, 20}, + }, + + // Band_8_3329 + { + // Scaler inc range + {3318, 3329}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 100, 81, 24, 44, 95, 87, 30, + 36, 92, 92, 36, 30, 87, 95, 44, 24, 81, 100, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 63, 82, 63, 24, 0, 20, 57, 82, 66, 28, 3, 16, 52, 80, 70, 33, 5, 13, 47, 78, 73, 38, 7, + 10, 42, 76, 76, 42, 10, 7, 38, 73, 78, 47, 13, 5, 33, 70, 80, 52, 16, 3, 28, 66, 82, 57, 20}, + }, + + // Band_8_3339 + { + // Scaler inc range + {3329, 3339}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 100, 81, 24, 44, 95, 87, 30, + 36, 92, 92, 36, 30, 87, 95, 44, 24, 81, 100, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 62, 84, 62, 24, 0, 20, 57, 82, 66, 28, 3, 16, 52, 80, 70, 33, 5, 13, 47, 78, 73, 38, 7, + 10, 42, 76, 76, 42, 10, 7, 38, 73, 78, 47, 13, 5, 33, 70, 80, 52, 16, 3, 28, 66, 82, 57, 20}, + }, + + // Band_8_3350 + { + // Scaler inc range + {3339, 3350}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 103, 75, 18, 51, 100, 81, 24, 44, 96, 86, 30, + 36, 92, 92, 36, 30, 86, 96, 44, 24, 81, 100, 51, 18, 75, 103, 60}, + // Coefficients 6 taps + {24, 62, 84, 62, 24, 0, 20, 57, 82, 66, 28, 3, 16, 52, 80, 70, 33, 5, 13, 47, 78, 73, 38, 7, + 10, 42, 76, 76, 42, 10, 7, 38, 73, 78, 47, 13, 5, 33, 70, 80, 52, 16, 3, 28, 66, 82, 57, 20}, + }, + + // Band_8_3361 + { + // Scaler inc range + {3350, 3361}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 102, 75, 19, 51, 100, 81, 24, 44, 96, 86, 30, + 36, 92, 92, 36, 30, 86, 96, 44, 24, 81, 100, 51, 19, 75, 102, 60}, + // Coefficients 6 taps + {24, 62, 84, 62, 24, 0, 20, 57, 81, 66, 29, 3, 16, 52, 81, 69, 33, 5, 13, 47, 78, 73, 38, 7, + 10, 42, 76, 76, 42, 10, 7, 38, 73, 78, 47, 13, 5, 33, 69, 81, 52, 16, 3, 29, 66, 81, 57, 20}, + }, + + // Band_8_3372 + { + // Scaler inc range + {3361, 3372}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 20, 57, 80, 66, 29, 4, 16, 52, 81, 69, 33, 5, 13, 47, 77, 73, 38, 8, + 10, 43, 75, 75, 43, 10, 8, 38, 73, 77, 47, 13, 5, 33, 69, 81, 52, 16, 4, 29, 66, 80, 57, 20}, + }, + + // Band_8_3383 + { + // Scaler inc range + {3372, 3383}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 20, 57, 80, 66, 29, 4, 17, 52, 80, 69, 33, 5, 13, 47, 77, 73, 38, 8, + 10, 43, 75, 75, 43, 10, 8, 38, 73, 77, 47, 13, 5, 33, 69, 80, 52, 17, 4, 29, 66, 80, 57, 20}, + }, + + // Band_8_3393 + { + // Scaler inc range + {3383, 3393}, + // Coefficients 4 taps + {72, 112, 72, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 20, 57, 80, 66, 29, 4, 17, 52, 79, 69, 33, 6, 13, 47, 78, 72, 38, 8, + 10, 43, 75, 75, 43, 10, 8, 38, 72, 78, 47, 13, 6, 33, 69, 79, 52, 17, 4, 29, 66, 80, 57, 20}, + }, + + // Band_8_3404 + { + // Scaler inc range + {3393, 3404}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 20, 57, 80, 66, 29, 4, 17, 52, 79, 69, 33, 6, 13, 47, 78, 72, 38, 8, + 10, 43, 75, 75, 43, 10, 8, 38, 72, 78, 47, 13, 6, 33, 69, 79, 52, 17, 4, 29, 66, 80, 57, 20}, + }, + + // Band_8_3416 + { + // Scaler inc range + {3404, 3416}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 21, 57, 79, 66, 29, 4, 17, 52, 79, 69, 33, 6, 13, 47, 78, 72, 38, 8, + 10, 43, 75, 75, 43, 10, 8, 38, 72, 78, 47, 13, 6, 33, 69, 79, 52, 17, 4, 29, 66, 79, 57, 21}, + }, + + // Band_8_3427 + { + // Scaler inc range + {3416, 3427}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 21, 57, 80, 65, 29, 4, 17, 52, 79, 69, 33, 6, 14, 47, 77, 72, 38, 8, + 11, 43, 74, 74, 43, 11, 8, 38, 72, 77, 47, 14, 6, 33, 69, 79, 52, 17, 4, 29, 65, 80, 57, 21}, + }, + + // Band_8_3438 + { + // Scaler inc range + {3427, 3438}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 21, 57, 80, 65, 29, 4, 17, 52, 79, 69, 33, 6, 14, 47, 77, 72, 38, 8, + 11, 43, 74, 74, 43, 11, 8, 38, 72, 77, 47, 14, 6, 33, 69, 79, 52, 17, 4, 29, 65, 80, 57, 21}, + }, + + // Band_8_3449 + { + // Scaler inc range + {3438, 3449}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 21, 57, 80, 65, 29, 4, 17, 52, 79, 69, 33, 6, 14, 47, 77, 72, 38, 8, + 11, 43, 74, 74, 43, 11, 8, 38, 72, 77, 47, 14, 6, 33, 69, 79, 52, 17, 4, 29, 65, 80, 57, 21}, + }, + + // Band_8_3461 + { + // Scaler inc range + {3449, 3461}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 81, 24, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 24, 81, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 21, 57, 80, 65, 29, 4, 17, 52, 78, 69, 34, 6, 14, 47, 77, 72, 38, 8, + 11, 43, 74, 74, 43, 11, 8, 38, 72, 77, 47, 14, 6, 34, 69, 78, 52, 17, 4, 29, 65, 80, 57, 21}, + }, + + // Band_8_3472 + { + // Scaler inc range + {3461, 3472}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 98, 81, 25, 44, 96, 86, 30, + 37, 91, 91, 37, 30, 86, 96, 44, 25, 81, 98, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 21, 57, 80, 65, 29, 4, 17, 52, 78, 69, 34, 6, 14, 47, 77, 72, 38, 8, + 11, 43, 74, 74, 43, 11, 8, 38, 72, 77, 47, 14, 6, 34, 69, 78, 52, 17, 4, 29, 65, 80, 57, 21}, + }, + + // Band_8_3484 + { + // Scaler inc range + {3472, 3484}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 98, 81, 25, 44, 95, 86, 31, + 37, 91, 91, 37, 31, 86, 95, 44, 25, 81, 98, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {25, 62, 82, 62, 25, 0, 21, 57, 80, 65, 29, 4, 17, 52, 79, 68, 34, 6, 14, 47, 77, 72, 38, 8, + 11, 43, 74, 74, 43, 11, 8, 38, 72, 77, 47, 14, 6, 34, 68, 79, 52, 17, 4, 29, 65, 80, 57, 21}, + }, + + // Band_8_3495 + { + // Scaler inc range + {3484, 3495}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 98, 81, 25, 44, 95, 86, 31, + 37, 91, 91, 37, 31, 86, 95, 44, 25, 81, 98, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 21, 57, 80, 65, 29, 4, 17, 52, 79, 68, 34, 6, 14, 47, 77, 71, 38, 9, + 11, 43, 74, 74, 43, 11, 9, 38, 71, 77, 47, 14, 6, 34, 68, 79, 52, 17, 4, 29, 65, 80, 57, 21}, + }, + + // Band_8_3507 + { + // Scaler inc range + {3495, 3507}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 80, 25, 44, 95, 86, 31, + 37, 91, 91, 37, 31, 86, 95, 44, 25, 80, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 21, 57, 79, 65, 29, 5, 18, 52, 78, 68, 34, 6, 14, 47, 77, 71, 38, 9, + 11, 43, 74, 74, 43, 11, 9, 38, 71, 77, 47, 14, 6, 34, 68, 78, 52, 18, 5, 29, 65, 79, 57, 21}, + }, + + // Band_8_3519 + { + // Scaler inc range + {3507, 3519}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 102, 75, 19, 52, 99, 80, 25, 44, 95, 86, 31, + 37, 91, 91, 37, 31, 86, 95, 44, 25, 80, 99, 52, 19, 75, 102, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 21, 57, 78, 65, 30, 5, 18, 52, 78, 68, 34, 6, 14, 48, 76, 71, 38, 9, + 11, 43, 74, 74, 43, 11, 9, 38, 71, 76, 48, 14, 6, 34, 68, 78, 52, 18, 5, 30, 65, 78, 57, 21}, + }, + + // Band_8_3531 + { + // Scaler inc range + {3519, 3531}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 44, 95, 86, 31, + 37, 91, 91, 37, 31, 86, 95, 44, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 21, 57, 78, 65, 30, 5, 18, 52, 77, 68, 34, 7, 14, 48, 76, 71, 38, 9, + 11, 43, 74, 74, 43, 11, 9, 38, 71, 76, 48, 14, 7, 34, 68, 77, 52, 18, 5, 30, 65, 78, 57, 21}, + }, + + // Band_8_3542 + { + // Scaler inc range + {3531, 3542}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 94, 86, 31, + 37, 91, 91, 37, 31, 86, 94, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 22, 57, 77, 65, 30, 5, 18, 52, 77, 68, 34, 7, 14, 48, 76, 71, 38, 9, + 11, 43, 74, 74, 43, 11, 9, 38, 71, 76, 48, 14, 7, 34, 68, 77, 52, 18, 5, 30, 65, 77, 57, 22}, + }, + + // Band_8_3554 + { + // Scaler inc range + {3542, 3554}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 94, 86, 31, + 37, 91, 91, 37, 31, 86, 94, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 22, 57, 77, 65, 30, 5, 18, 52, 77, 68, 34, 7, 15, 48, 75, 71, 38, 9, + 12, 43, 73, 73, 43, 12, 9, 38, 71, 75, 48, 15, 7, 34, 68, 77, 52, 18, 5, 30, 65, 77, 57, 22}, + }, + + // Band_8_3567 + { + // Scaler inc range + {3554, 3567}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 94, 86, 31, + 38, 90, 90, 38, 31, 86, 94, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 22, 57, 77, 65, 30, 5, 18, 52, 77, 68, 34, 7, 15, 48, 75, 71, 38, 9, + 12, 43, 73, 73, 43, 12, 9, 38, 71, 75, 48, 15, 7, 34, 68, 77, 52, 18, 5, 30, 65, 77, 57, 22}, + }, + + // Band_8_3579 + { + // Scaler inc range + {3567, 3579}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 94, 86, 31, + 38, 90, 90, 38, 31, 86, 94, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 22, 57, 77, 65, 30, 5, 18, 52, 77, 68, 34, 7, 15, 48, 75, 71, 38, 9, + 12, 43, 73, 73, 43, 12, 9, 38, 71, 75, 48, 15, 7, 34, 68, 77, 52, 18, 5, 30, 65, 77, 57, 22}, + }, + + // Band_8_3591 + { + // Scaler inc range + {3579, 3591}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 94, 86, 31, + 38, 90, 90, 38, 31, 86, 94, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 22, 57, 78, 64, 30, 5, 18, 52, 77, 68, 34, 7, 15, 48, 74, 71, 39, 9, + 12, 43, 73, 73, 43, 12, 9, 39, 71, 74, 48, 15, 7, 34, 68, 77, 52, 18, 5, 30, 64, 78, 57, 22}, + }, + + // Band_8_3603 + { + // Scaler inc range + {3591, 3603}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 94, 86, 31, + 38, 90, 90, 38, 31, 86, 94, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 22, 57, 78, 64, 30, 5, 18, 52, 77, 68, 34, 7, 15, 48, 74, 71, 39, 9, + 12, 43, 73, 73, 43, 12, 9, 39, 71, 74, 48, 15, 7, 34, 68, 77, 52, 18, 5, 30, 64, 78, 57, 22}, + }, + + // Band_8_3616 + { + // Scaler inc range + {3603, 3616}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 95, 85, 31, + 38, 90, 90, 38, 31, 85, 95, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {26, 62, 80, 62, 26, 0, 22, 57, 78, 64, 30, 5, 18, 52, 77, 68, 34, 7, 15, 48, 75, 70, 39, 9, + 12, 43, 73, 73, 43, 12, 9, 39, 70, 75, 48, 15, 7, 34, 68, 77, 52, 18, 5, 30, 64, 78, 57, 22}, + }, + + // Band_8_3628 + { + // Scaler inc range + {3616, 3628}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 95, 85, 31, + 38, 90, 90, 38, 31, 85, 95, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 22, 56, 79, 64, 30, 5, 18, 52, 78, 67, 34, 7, 15, 48, 74, 70, 39, 10, + 12, 43, 73, 73, 43, 12, 10, 39, 70, 74, 48, 15, 7, 34, 67, 78, 52, 18, 5, 30, 64, 79, 56, 22}, + }, + + // Band_8_3641 + { + // Scaler inc range + {3628, 3641}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 99, 80, 25, 45, 95, 85, 31, + 38, 90, 90, 38, 31, 85, 95, 45, 25, 80, 99, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 22, 56, 79, 64, 30, 5, 19, 52, 77, 67, 34, 7, 15, 48, 74, 70, 39, 10, + 12, 43, 73, 73, 43, 12, 10, 39, 70, 74, 48, 15, 7, 34, 67, 77, 52, 19, 5, 30, 64, 79, 56, 22}, + }, + + // Band_8_3654 + { + // Scaler inc range + {3641, 3654}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 52, 98, 80, 26, 45, 95, 85, 31, + 38, 90, 90, 38, 31, 85, 95, 45, 26, 80, 98, 52, 20, 75, 101, 60}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 22, 56, 79, 64, 30, 5, 19, 52, 77, 67, 34, 7, 15, 48, 74, 70, 39, 10, + 12, 43, 73, 73, 43, 12, 10, 39, 70, 74, 48, 15, 7, 34, 67, 77, 52, 19, 5, 30, 64, 79, 56, 22}, + }, + + // Band_8_3666 + { + // Scaler inc range + {3654, 3666}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 53, 97, 80, 26, 45, 95, 85, 31, + 38, 90, 90, 38, 31, 85, 95, 45, 26, 80, 97, 53, 20, 75, 101, 60}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 22, 56, 78, 64, 30, 6, 19, 52, 77, 67, 34, 7, 15, 48, 74, 70, 39, 10, + 12, 43, 73, 73, 43, 12, 10, 39, 70, 74, 48, 15, 7, 34, 67, 77, 52, 19, 6, 30, 64, 78, 56, 22}, + }, + + // Band_8_3679 + { + // Scaler inc range + {3666, 3679}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 20, 75, 101, 60}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 22, 56, 78, 64, 30, 6, 19, 52, 75, 67, 35, 8, 15, 48, 74, 70, 39, 10, + 12, 43, 73, 73, 43, 12, 10, 39, 70, 74, 48, 15, 8, 35, 67, 75, 52, 19, 6, 30, 64, 78, 56, 22}, + }, + + // Band_8_3692 + { + // Scaler inc range + {3679, 3692}, + // Coefficients 4 taps + {73, 110, 73, 0, 60, 101, 75, 20, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 20, 75, 101, 60}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 23, 56, 77, 64, 30, 6, 19, 52, 75, 67, 35, 8, 16, 48, 73, 70, 39, 10, + 13, 43, 72, 72, 43, 13, 10, 39, 70, 73, 48, 16, 8, 35, 67, 75, 52, 19, 6, 30, 64, 77, 56, 23}, + }, + + // Band_8_3705 + { + // Scaler inc range + {3692, 3705}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 100, 75, 20, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 20, 75, 100, 61}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 23, 56, 76, 64, 31, 6, 19, 52, 75, 67, 35, 8, 16, 48, 73, 70, 39, 10, + 13, 43, 72, 72, 43, 13, 10, 39, 70, 73, 48, 16, 8, 35, 67, 75, 52, 19, 6, 31, 64, 76, 56, 23}, + }, + + // Band_8_3718 + { + // Scaler inc range + {3705, 3718}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 100, 75, 20, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 20, 75, 100, 61}, + // Coefficients 6 taps + {27, 62, 78, 62, 27, 0, 23, 56, 76, 64, 31, 6, 19, 52, 75, 67, 35, 8, 16, 48, 73, 70, 39, 10, + 13, 43, 72, 72, 43, 13, 10, 39, 70, 73, 48, 16, 8, 35, 67, 75, 52, 19, 6, 31, 64, 76, 56, 23}, + }, + + // Band_8_3732 + { + // Scaler inc range + {3718, 3732}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 99, 75, 21, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {27, 61, 80, 61, 27, 0, 23, 56, 76, 64, 31, 6, 19, 52, 75, 67, 35, 8, 16, 48, 73, 70, 39, 10, + 13, 43, 72, 72, 43, 13, 10, 39, 70, 73, 48, 16, 8, 35, 67, 75, 52, 19, 6, 31, 64, 76, 56, 23}, + }, + + // Band_8_3745 + { + // Scaler inc range + {3732, 3745}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 99, 75, 21, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {27, 61, 80, 61, 27, 0, 23, 56, 76, 64, 31, 6, 19, 52, 75, 67, 35, 8, 16, 48, 74, 69, 39, 10, + 13, 43, 72, 72, 43, 13, 10, 39, 69, 74, 48, 16, 8, 35, 67, 75, 52, 19, 6, 31, 64, 76, 56, 23}, + }, + + // Band_8_3758 + { + // Scaler inc range + {3745, 3758}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 99, 75, 21, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {27, 61, 80, 61, 27, 0, 23, 56, 76, 64, 31, 6, 19, 52, 75, 67, 35, 8, 16, 48, 74, 69, 39, 10, + 13, 43, 72, 72, 43, 13, 10, 39, 69, 74, 48, 16, 8, 35, 67, 75, 52, 19, 6, 31, 64, 76, 56, 23}, + }, + + // Band_8_3772 + { + // Scaler inc range + {3758, 3772}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 99, 75, 21, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {27, 61, 80, 61, 27, 0, 23, 56, 76, 64, 31, 6, 19, 52, 75, 67, 35, 8, 16, 48, 74, 69, 39, 10, + 13, 43, 72, 72, 43, 13, 10, 39, 69, 74, 48, 16, 8, 35, 67, 75, 52, 19, 6, 31, 64, 76, 56, 23}, + }, + + // Band_8_3785 + { + // Scaler inc range + {3772, 3785}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 99, 75, 21, 53, 97, 80, 26, 45, 94, 85, 32, + 38, 90, 90, 38, 32, 85, 94, 45, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 23, 56, 76, 64, 31, 6, 20, 52, 75, 66, 35, 8, 16, 48, 73, 69, 39, 11, + 13, 43, 72, 72, 43, 13, 11, 39, 69, 73, 48, 16, 8, 35, 66, 75, 52, 20, 6, 31, 64, 76, 56, 23}, + }, + + // Band_8_3799 + { + // Scaler inc range + {3785, 3799}, + // Coefficients 4 taps + {73, 110, 73, 0, 61, 99, 75, 21, 53, 97, 80, 26, 45, 94, 85, 32, + 39, 89, 89, 39, 32, 85, 94, 45, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 23, 56, 77, 63, 31, 6, 20, 52, 75, 66, 35, 8, 16, 48, 73, 69, 39, 11, + 13, 43, 72, 72, 43, 13, 11, 39, 69, 73, 48, 16, 8, 35, 66, 75, 52, 20, 6, 31, 63, 77, 56, 23}, + }, + + // Band_8_3813 + { + // Scaler inc range + {3799, 3813}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 75, 21, 53, 97, 80, 26, 46, 93, 85, 32, + 39, 89, 89, 39, 32, 85, 93, 46, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 23, 56, 77, 63, 31, 6, 20, 52, 75, 66, 35, 8, 16, 48, 73, 69, 39, 11, + 13, 43, 72, 72, 43, 13, 11, 39, 69, 73, 48, 16, 8, 35, 66, 75, 52, 20, 6, 31, 63, 77, 56, 23}, + }, + + // Band_8_3827 + { + // Scaler inc range + {3813, 3827}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 75, 21, 53, 97, 80, 26, 46, 93, 85, 32, + 39, 89, 89, 39, 32, 85, 93, 46, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 23, 56, 77, 63, 31, 6, 20, 52, 75, 66, 35, 8, 16, 48, 73, 69, 39, 11, + 13, 43, 72, 72, 43, 13, 11, 39, 69, 73, 48, 16, 8, 35, 66, 75, 52, 20, 6, 31, 63, 77, 56, 23}, + }, + + // Band_8_3841 + { + // Scaler inc range + {3827, 3841}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 75, 21, 53, 97, 80, 26, 46, 93, 85, 32, + 39, 89, 89, 39, 32, 85, 93, 46, 26, 80, 97, 53, 21, 75, 99, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 23, 56, 76, 63, 31, 7, 20, 52, 74, 66, 35, 9, 17, 48, 72, 69, 39, 11, + 14, 43, 71, 71, 43, 14, 11, 39, 69, 72, 48, 17, 9, 35, 66, 74, 52, 20, 7, 31, 63, 76, 56, 23}, + }, + + // Band_8_3855 + { + // Scaler inc range + {3841, 3855}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 100, 74, 21, 53, 97, 80, 26, 46, 93, 85, 32, + 39, 89, 89, 39, 32, 85, 93, 46, 26, 80, 97, 53, 21, 74, 100, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 24, 56, 75, 63, 31, 7, 20, 52, 74, 66, 35, 9, 17, 48, 72, 69, 39, 11, + 14, 43, 71, 71, 43, 14, 11, 39, 69, 72, 48, 17, 9, 35, 66, 74, 52, 20, 7, 31, 63, 75, 56, 24}, + }, + + // Band_8_3869 + { + // Scaler inc range + {3855, 3869}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 100, 74, 21, 53, 96, 80, 27, 46, 93, 85, 32, + 39, 89, 89, 39, 32, 85, 93, 46, 27, 80, 96, 53, 21, 74, 100, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 24, 56, 75, 63, 31, 7, 20, 52, 74, 66, 35, 9, 17, 48, 72, 69, 39, 11, + 14, 43, 71, 71, 43, 14, 11, 39, 69, 72, 48, 17, 9, 35, 66, 74, 52, 20, 7, 31, 63, 75, 56, 24}, + }, + + // Band_8_3884 + { + // Scaler inc range + {3869, 3884}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 100, 74, 21, 53, 96, 80, 27, 46, 93, 85, 32, + 39, 89, 89, 39, 32, 85, 93, 46, 27, 80, 96, 53, 21, 74, 100, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 24, 56, 75, 63, 31, 7, 20, 52, 74, 66, 35, 9, 17, 48, 73, 68, 39, 11, + 14, 43, 71, 71, 43, 14, 11, 39, 68, 73, 48, 17, 9, 35, 66, 74, 52, 20, 7, 31, 63, 75, 56, 24}, + }, + + // Band_8_3898 + { + // Scaler inc range + {3884, 3898}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 100, 74, 21, 53, 96, 80, 27, 46, 93, 85, 32, + 39, 89, 89, 39, 32, 85, 93, 46, 27, 80, 96, 53, 21, 74, 100, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 24, 56, 75, 63, 31, 7, 20, 52, 74, 66, 35, 9, 17, 48, 73, 68, 39, 11, + 14, 44, 70, 70, 44, 14, 11, 39, 68, 73, 48, 17, 9, 35, 66, 74, 52, 20, 7, 31, 63, 75, 56, 24}, + }, + + // Band_8_3913 + { + // Scaler inc range + {3898, 3913}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 100, 74, 21, 53, 96, 80, 27, 46, 92, 85, 33, + 39, 89, 89, 39, 33, 85, 92, 46, 27, 80, 96, 53, 21, 74, 100, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 24, 56, 75, 63, 31, 7, 20, 52, 74, 66, 35, 9, 17, 48, 73, 68, 39, 11, + 14, 44, 70, 70, 44, 14, 11, 39, 68, 73, 48, 17, 9, 35, 66, 74, 52, 20, 7, 31, 63, 75, 56, 24}, + }, + + // Band_8_3927 + { + // Scaler inc range + {3913, 3927}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 100, 74, 21, 53, 96, 80, 27, 46, 92, 85, 33, + 39, 89, 89, 39, 33, 85, 92, 46, 27, 80, 96, 53, 21, 74, 100, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 24, 56, 74, 63, 32, 7, 20, 52, 74, 66, 35, 9, 17, 48, 73, 68, 39, 11, + 14, 44, 70, 70, 44, 14, 11, 39, 68, 73, 48, 17, 9, 35, 66, 74, 52, 20, 7, 32, 63, 74, 56, 24}, + }, + + // Band_8_3942 + { + // Scaler inc range + {3927, 3942}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 100, 74, 21, 53, 96, 80, 27, 46, 92, 85, 33, + 39, 89, 89, 39, 33, 85, 92, 46, 27, 80, 96, 53, 21, 74, 100, 61}, + // Coefficients 6 taps + {28, 61, 78, 61, 28, 0, 24, 56, 74, 63, 32, 7, 20, 52, 74, 66, 35, 9, 17, 48, 73, 68, 39, 11, + 14, 44, 70, 70, 44, 14, 11, 39, 68, 73, 48, 17, 9, 35, 66, 74, 52, 20, 7, 32, 63, 74, 56, 24}, + }, + + // Band_8_3957 + { + // Scaler inc range + {3942, 3957}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 96, 80, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 80, 96, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 24, 56, 74, 63, 32, 7, 20, 52, 73, 66, 36, 9, 17, 48, 71, 68, 40, 12, + 14, 44, 70, 70, 44, 14, 12, 40, 68, 71, 48, 17, 9, 36, 66, 73, 52, 20, 7, 32, 63, 74, 56, 24}, + }, + + // Band_8_3972 + { + // Scaler inc range + {3957, 3972}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 96, 80, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 80, 96, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 24, 56, 74, 63, 32, 7, 21, 52, 73, 65, 36, 9, 17, 48, 71, 68, 40, 12, + 14, 44, 70, 70, 44, 14, 12, 40, 68, 71, 48, 17, 9, 36, 65, 73, 52, 21, 7, 32, 63, 74, 56, 24}, + }, + + // Band_8_3987 + { + // Scaler inc range + {3972, 3987}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 96, 80, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 80, 96, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 24, 56, 74, 63, 32, 7, 21, 52, 73, 65, 36, 9, 17, 48, 71, 68, 40, 12, + 14, 44, 70, 70, 44, 14, 12, 40, 68, 71, 48, 17, 9, 36, 65, 73, 52, 21, 7, 32, 63, 74, 56, 24}, + }, + + // Band_8_4002 + { + // Scaler inc range + {3987, 4002}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 96, 80, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 80, 96, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 24, 56, 74, 63, 32, 7, 21, 52, 73, 65, 36, 9, 17, 48, 71, 68, 40, 12, + 14, 44, 70, 70, 44, 14, 12, 40, 68, 71, 48, 17, 9, 36, 65, 73, 52, 21, 7, 32, 63, 74, 56, 24}, + }, + + // Band_8_4018 + { + // Scaler inc range + {4002, 4018}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 96, 80, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 80, 96, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 24, 56, 74, 63, 32, 7, 21, 52, 72, 65, 36, 10, 18, 48, 70, 68, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 68, 70, 48, 18, 10, 36, 65, 72, 52, 21, 7, 32, 63, 74, 56, 24}, + }, + + // Band_8_4033 + { + // Scaler inc range + {4018, 4033}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 96, 80, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 80, 96, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 24, 56, 74, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 70, 68, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 68, 70, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 74, 56, 24}, + }, + + // Band_8_4049 + { + // Scaler inc range + {4033, 4049}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 96, 80, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 80, 96, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 25, 56, 73, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 71, 67, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 67, 71, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 73, 56, 25}, + }, + + // Band_8_4064 + { + // Scaler inc range + {4049, 4064}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 53, 97, 79, 27, 46, 93, 84, 33, + 39, 89, 89, 39, 33, 84, 93, 46, 27, 79, 97, 53, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 25, 56, 73, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 71, 67, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 67, 71, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 73, 56, 25}, + }, + + // Band_8_4080 + { + // Scaler inc range + {4064, 4080}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 96, 79, 27, 46, 93, 84, 33, + 40, 88, 88, 40, 33, 84, 93, 46, 27, 79, 96, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 25, 56, 73, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 71, 67, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 67, 71, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 73, 56, 25}, + }, + + // Band_8_4096 + { + // Scaler inc range + {4080, 4096}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 96, 79, 27, 46, 93, 84, 33, + 40, 88, 88, 40, 33, 84, 93, 46, 27, 79, 96, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 25, 56, 73, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 71, 67, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 67, 71, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 73, 56, 25}, + }, + + // Band_8_4112 + { + // Scaler inc range + {4096, 4112}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 96, 79, 27, 46, 93, 84, 33, + 40, 88, 88, 40, 33, 84, 93, 46, 27, 79, 96, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 25, 56, 73, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 71, 67, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 67, 71, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 73, 56, 25}, + }, + + // Band_8_4128 + { + // Scaler inc range + {4112, 4128}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 95, 79, 28, 46, 93, 84, 33, + 40, 88, 88, 40, 33, 84, 93, 46, 28, 79, 95, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 25, 55, 74, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 71, 67, 40, 12, + 15, 44, 69, 69, 44, 15, 12, 40, 67, 71, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 74, 55, 25}, + }, + + // Band_8_4145 + { + // Scaler inc range + {4128, 4145}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 95, 79, 28, 46, 93, 84, 33, + 40, 88, 88, 40, 33, 84, 93, 46, 28, 79, 95, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {29, 61, 76, 61, 29, 0, 25, 55, 74, 62, 32, 8, 21, 52, 72, 65, 36, 10, 18, 48, 70, 67, 40, 13, + 15, 44, 69, 69, 44, 15, 13, 40, 67, 70, 48, 18, 10, 36, 65, 72, 52, 21, 8, 32, 62, 74, 55, 25}, + }, + + // Band_8_4161 + { + // Scaler inc range + {4145, 4161}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 95, 79, 28, 47, 92, 84, 33, + 40, 88, 88, 40, 33, 84, 92, 47, 28, 79, 95, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {30, 61, 74, 61, 30, 0, 25, 55, 74, 62, 32, 8, 22, 52, 71, 65, 36, 10, 18, 48, 70, 67, 40, 13, + 15, 44, 69, 69, 44, 15, 13, 40, 67, 70, 48, 18, 10, 36, 65, 71, 52, 22, 8, 32, 62, 74, 55, 25}, + }, + + // Band_8_4178 + { + // Scaler inc range + {4161, 4178}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {30, 61, 74, 61, 30, 0, 25, 55, 74, 62, 32, 8, 22, 52, 72, 64, 36, 10, 18, 48, 70, 67, 40, 13, + 15, 44, 69, 69, 44, 15, 13, 40, 67, 70, 48, 18, 10, 36, 64, 72, 52, 22, 8, 32, 62, 74, 55, 25}, + }, + + // Band_8_4194 + { + // Scaler inc range + {4178, 4194}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {30, 61, 74, 61, 30, 0, 25, 55, 73, 62, 33, 8, 22, 52, 72, 64, 36, 10, 18, 48, 70, 67, 40, 13, + 15, 44, 69, 69, 44, 15, 13, 40, 67, 70, 48, 18, 10, 36, 64, 72, 52, 22, 8, 33, 62, 73, 55, 25}, + }, + + // Band_8_4211 + { + // Scaler inc range + {4194, 4211}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 99, 74, 22, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 22, 74, 99, 61}, + // Coefficients 6 taps + {30, 61, 74, 61, 30, 0, 25, 55, 73, 62, 33, 8, 22, 52, 72, 64, 36, 10, 19, 48, 69, 67, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 67, 69, 48, 19, 10, 36, 64, 72, 52, 22, 8, 33, 62, 73, 55, 25}, + }, + + // Band_8_4228 + { + // Scaler inc range + {4211, 4228}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 61, 74, 61, 30, 0, 25, 55, 73, 62, 33, 8, 22, 52, 71, 64, 36, 11, 19, 48, 69, 67, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 67, 69, 48, 19, 11, 36, 64, 71, 52, 22, 8, 33, 62, 73, 55, 25}, + }, + + // Band_8_4245 + { + // Scaler inc range + {4228, 4245}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 61, 74, 61, 30, 0, 25, 55, 73, 62, 33, 8, 22, 52, 71, 64, 36, 11, 19, 48, 70, 66, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 66, 70, 48, 19, 11, 36, 64, 71, 52, 22, 8, 33, 62, 73, 55, 25}, + }, + + // Band_8_4263 + { + // Scaler inc range + {4245, 4263}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 61, 74, 61, 30, 0, 25, 55, 72, 62, 33, 9, 22, 51, 72, 64, 36, 11, 19, 48, 70, 66, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 66, 70, 48, 19, 11, 36, 64, 72, 51, 22, 9, 33, 62, 72, 55, 25}, + }, + + // Band_8_4280 + { + // Scaler inc range + {4263, 4280}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 60, 76, 60, 30, 0, 26, 55, 71, 62, 33, 9, 22, 51, 72, 64, 36, 11, 19, 48, 70, 66, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 66, 70, 48, 19, 11, 36, 64, 72, 51, 22, 9, 33, 62, 71, 55, 26}, + }, + + // Band_8_4297 + { + // Scaler inc range + {4280, 4297}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 60, 76, 60, 30, 0, 26, 55, 71, 62, 33, 9, 22, 51, 72, 64, 36, 11, 19, 48, 70, 66, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 66, 70, 48, 19, 11, 36, 64, 72, 51, 22, 9, 33, 62, 71, 55, 26}, + }, + + // Band_8_4315 + { + // Scaler inc range + {4297, 4315}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 60, 76, 60, 30, 0, 26, 55, 72, 61, 33, 9, 22, 51, 71, 64, 37, 11, 19, 48, 70, 66, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 66, 70, 48, 19, 11, 37, 64, 71, 51, 22, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4333 + { + // Scaler inc range + {4315, 4333}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 60, 76, 60, 30, 0, 26, 55, 72, 61, 33, 9, 22, 51, 71, 64, 37, 11, 19, 48, 70, 66, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 66, 70, 48, 19, 11, 37, 64, 71, 51, 22, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4351 + { + // Scaler inc range + {4333, 4351}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 60, 76, 60, 30, 0, 26, 55, 72, 61, 33, 9, 22, 51, 71, 64, 37, 11, 19, 48, 70, 66, 40, 13, + 16, 44, 68, 68, 44, 16, 13, 40, 66, 70, 48, 19, 11, 37, 64, 71, 51, 22, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4369 + { + // Scaler inc range + {4351, 4369}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 60, 76, 60, 30, 0, 26, 55, 72, 61, 33, 9, 22, 51, 71, 64, 37, 11, 19, 48, 69, 66, 40, 14, + 16, 44, 68, 68, 44, 16, 14, 40, 66, 69, 48, 19, 11, 37, 64, 71, 51, 22, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4387 + { + // Scaler inc range + {4369, 4387}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {30, 60, 76, 60, 30, 0, 26, 55, 72, 61, 33, 9, 22, 51, 71, 64, 37, 11, 19, 48, 69, 66, 40, 14, + 16, 44, 68, 68, 44, 16, 14, 40, 66, 69, 48, 19, 11, 37, 64, 71, 51, 22, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4406 + { + // Scaler inc range + {4387, 4406}, + // Coefficients 4 taps + {74, 108, 74, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 91, 84, 34, + 40, 88, 88, 40, 34, 84, 91, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 72, 61, 33, 9, 23, 51, 70, 64, 37, 11, 19, 48, 69, 66, 40, 14, + 16, 44, 68, 68, 44, 16, 14, 40, 66, 69, 48, 19, 11, 37, 64, 70, 51, 23, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4424 + { + // Scaler inc range + {4406, 4424}, + // Coefficients 4 taps + {75, 106, 75, 0, 61, 98, 74, 23, 54, 95, 79, 28, 47, 92, 83, 34, + 40, 88, 88, 40, 34, 83, 92, 47, 28, 79, 95, 54, 23, 74, 98, 61}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 72, 61, 33, 9, 23, 51, 70, 64, 37, 11, 19, 48, 69, 66, 40, 14, + 16, 44, 68, 68, 44, 16, 14, 40, 66, 69, 48, 19, 11, 37, 64, 70, 51, 23, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4443 + { + // Scaler inc range + {4424, 4443}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 97, 74, 23, 54, 95, 79, 28, 47, 92, 83, 34, + 41, 87, 87, 41, 34, 83, 92, 47, 28, 79, 95, 54, 23, 74, 97, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 72, 61, 33, 9, 23, 51, 71, 63, 37, 11, 19, 48, 69, 66, 40, 14, + 17, 44, 67, 67, 44, 17, 14, 40, 66, 69, 48, 19, 11, 37, 63, 71, 51, 23, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4462 + { + // Scaler inc range + {4443, 4462}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 97, 74, 23, 54, 94, 79, 29, 47, 92, 83, 34, + 41, 87, 87, 41, 34, 83, 92, 47, 29, 79, 94, 54, 23, 74, 97, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 72, 61, 33, 9, 23, 51, 70, 63, 37, 12, 20, 48, 69, 65, 40, 14, + 17, 44, 67, 67, 44, 17, 14, 40, 65, 69, 48, 20, 12, 37, 63, 70, 51, 23, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4481 + { + // Scaler inc range + {4462, 4481}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 97, 74, 23, 54, 94, 79, 29, 47, 92, 83, 34, + 41, 87, 87, 41, 34, 83, 92, 47, 29, 79, 94, 54, 23, 74, 97, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 72, 61, 33, 9, 23, 51, 70, 63, 37, 12, 20, 48, 69, 65, 40, 14, + 17, 44, 67, 67, 44, 17, 14, 40, 65, 69, 48, 20, 12, 37, 63, 70, 51, 23, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4500 + { + // Scaler inc range + {4481, 4500}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 97, 74, 23, 54, 94, 79, 29, 47, 92, 83, 34, + 41, 87, 87, 41, 34, 83, 92, 47, 29, 79, 94, 54, 23, 74, 97, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 72, 61, 33, 9, 23, 51, 70, 63, 37, 12, 20, 48, 69, 65, 40, 14, + 17, 44, 67, 67, 44, 17, 14, 40, 65, 69, 48, 20, 12, 37, 63, 70, 51, 23, 9, 33, 61, 72, 55, 26}, + }, + + // Band_8_4520 + { + // Scaler inc range + {4500, 4520}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 97, 74, 23, 54, 94, 79, 29, 47, 92, 83, 34, + 41, 87, 87, 41, 34, 83, 92, 47, 29, 79, 94, 54, 23, 74, 97, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 71, 61, 33, 10, 23, 51, 70, 63, 37, 12, 20, 48, 69, 65, 40, 14, + 17, 44, 67, 67, 44, 17, 14, 40, 65, 69, 48, 20, 12, 37, 63, 70, 51, 23, 10, 33, 61, 71, 55, 26}, + }, + + // Band_8_4539 + { + // Scaler inc range + {4520, 4539}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 97, 74, 23, 54, 94, 79, 29, 47, 91, 83, 35, + 41, 87, 87, 41, 35, 83, 91, 47, 29, 79, 94, 54, 23, 74, 97, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 26, 55, 70, 61, 34, 10, 23, 51, 70, 63, 37, 12, 20, 48, 68, 65, 41, 14, + 17, 44, 67, 67, 44, 17, 14, 41, 65, 68, 48, 20, 12, 37, 63, 70, 51, 23, 10, 34, 61, 70, 55, 26}, + }, + + // Band_8_4559 + { + // Scaler inc range + {4539, 4559}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 54, 94, 79, 29, 47, 91, 83, 35, + 41, 87, 87, 41, 35, 83, 91, 47, 29, 79, 94, 54, 24, 74, 96, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 27, 55, 69, 61, 34, 10, 23, 51, 70, 63, 37, 12, 20, 48, 68, 65, 41, 14, + 17, 44, 67, 67, 44, 17, 14, 41, 65, 68, 48, 20, 12, 37, 63, 70, 51, 23, 10, 34, 61, 69, 55, 27}, + }, + + // Band_8_4579 + { + // Scaler inc range + {4559, 4579}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 54, 94, 79, 29, 47, 91, 83, 35, + 41, 87, 87, 41, 35, 83, 91, 47, 29, 79, 94, 54, 24, 74, 96, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 27, 55, 69, 61, 34, 10, 23, 51, 70, 63, 37, 12, 20, 48, 68, 65, 41, 14, + 17, 44, 67, 67, 44, 17, 14, 41, 65, 68, 48, 20, 12, 37, 63, 70, 51, 23, 10, 34, 61, 69, 55, 27}, + }, + + // Band_8_4599 + { + // Scaler inc range + {4579, 4599}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 54, 94, 79, 29, 47, 91, 83, 35, + 41, 87, 87, 41, 35, 83, 91, 47, 29, 79, 94, 54, 24, 74, 96, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 27, 55, 69, 61, 34, 10, 23, 51, 70, 63, 37, 12, 20, 48, 68, 65, 41, 14, + 17, 44, 67, 67, 44, 17, 14, 41, 65, 68, 48, 20, 12, 37, 63, 70, 51, 23, 10, 34, 61, 69, 55, 27}, + }, + + // Band_8_4619 + { + // Scaler inc range + {4599, 4619}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 54, 94, 79, 29, 47, 91, 83, 35, + 41, 87, 87, 41, 35, 83, 91, 47, 29, 79, 94, 54, 24, 74, 96, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 27, 55, 69, 61, 34, 10, 23, 51, 70, 63, 37, 12, 20, 48, 67, 65, 41, 15, + 17, 44, 67, 67, 44, 17, 15, 41, 65, 67, 48, 20, 12, 37, 63, 70, 51, 23, 10, 34, 61, 69, 55, 27}, + }, + + // Band_8_4640 + { + // Scaler inc range + {4619, 4640}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 54, 94, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 94, 54, 24, 74, 96, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 27, 55, 69, 61, 34, 10, 23, 51, 70, 63, 37, 12, 20, 48, 67, 65, 41, 15, + 17, 44, 67, 67, 44, 17, 15, 41, 65, 67, 48, 20, 12, 37, 63, 70, 51, 23, 10, 34, 61, 69, 55, 27}, + }, + + // Band_8_4660 + { + // Scaler inc range + {4640, 4660}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 54, 94, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 94, 54, 24, 74, 96, 62}, + // Coefficients 6 taps + {31, 60, 74, 60, 31, 0, 27, 55, 70, 60, 34, 10, 23, 51, 70, 63, 37, 12, 20, 48, 67, 65, 41, 15, + 17, 44, 67, 67, 44, 17, 15, 41, 65, 67, 48, 20, 12, 37, 63, 70, 51, 23, 10, 34, 60, 70, 55, 27}, + }, + + // Band_8_4681 + { + // Scaler inc range + {4660, 4681}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 54, 94, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 94, 54, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 55, 70, 60, 34, 10, 24, 51, 69, 63, 37, 12, 20, 48, 67, 65, 41, 15, + 17, 44, 67, 67, 44, 17, 15, 41, 65, 67, 48, 20, 12, 37, 63, 69, 51, 24, 10, 34, 60, 70, 55, 27}, + }, + + // Band_8_4702 + { + // Scaler inc range + {4681, 4702}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 93, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 93, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 55, 70, 60, 34, 10, 24, 51, 69, 63, 37, 12, 20, 48, 67, 65, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 65, 67, 48, 20, 12, 37, 63, 69, 51, 24, 10, 34, 60, 70, 55, 27}, + }, + + // Band_8_4723 + { + // Scaler inc range + {4702, 4723}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 93, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 93, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 55, 70, 60, 34, 10, 24, 51, 69, 63, 37, 12, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 12, 37, 63, 69, 51, 24, 10, 34, 60, 70, 55, 27}, + }, + + // Band_8_4745 + { + // Scaler inc range + {4723, 4745}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 93, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 93, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 55, 70, 60, 34, 10, 24, 51, 69, 62, 37, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 37, 62, 69, 51, 24, 10, 34, 60, 70, 55, 27}, + }, + + // Band_8_4766 + { + // Scaler inc range + {4745, 4766}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 93, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 93, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 55, 70, 60, 34, 10, 24, 51, 69, 62, 37, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 37, 62, 69, 51, 24, 10, 34, 60, 70, 55, 27}, + }, + + // Band_8_4788 + { + // Scaler inc range + {4766, 4788}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 93, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 93, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 55, 70, 60, 34, 10, 24, 51, 69, 62, 37, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 37, 62, 69, 51, 24, 10, 34, 60, 70, 55, 27}, + }, + + // Band_8_4810 + { + // Scaler inc range + {4788, 4810}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 93, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 93, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 54, 70, 60, 34, 11, 24, 51, 69, 62, 37, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 37, 62, 69, 51, 24, 11, 34, 60, 70, 54, 27}, + }, + + // Band_8_4832 + { + // Scaler inc range + {4810, 4832}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 93, 79, 29, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 29, 79, 93, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 54, 70, 60, 34, 11, 24, 51, 69, 62, 37, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 37, 62, 69, 51, 24, 11, 34, 60, 70, 54, 27}, + }, + + // Band_8_4855 + { + // Scaler inc range + {4832, 4855}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 92, 79, 30, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 30, 79, 92, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 54, 70, 60, 34, 11, 24, 51, 68, 62, 38, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 38, 62, 68, 51, 24, 11, 34, 60, 70, 54, 27}, + }, + + // Band_8_4877 + { + // Scaler inc range + {4855, 4877}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 92, 79, 30, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 30, 79, 92, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 27, 54, 70, 60, 34, 11, 24, 51, 68, 62, 38, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 38, 62, 68, 51, 24, 11, 34, 60, 70, 54, 27}, + }, + + // Band_8_4900 + { + // Scaler inc range + {4877, 4900}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 92, 79, 30, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 30, 79, 92, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 28, 54, 69, 60, 34, 11, 24, 51, 68, 62, 38, 13, 21, 48, 67, 64, 41, 15, + 18, 44, 66, 66, 44, 18, 15, 41, 64, 67, 48, 21, 13, 38, 62, 68, 51, 24, 11, 34, 60, 69, 54, 28}, + }, + + // Band_8_4923 + { + // Scaler inc range + {4900, 4923}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 92, 79, 30, 48, 90, 83, 35, + 41, 87, 87, 41, 35, 83, 90, 48, 30, 79, 92, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 28, 54, 69, 60, 34, 11, 24, 51, 68, 62, 38, 13, 21, 48, 66, 64, 41, 16, + 18, 44, 66, 66, 44, 18, 16, 41, 64, 66, 48, 21, 13, 38, 62, 68, 51, 24, 11, 34, 60, 69, 54, 28}, + }, + + // Band_8_4946 + { + // Scaler inc range + {4923, 4946}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 96, 74, 24, 55, 92, 79, 30, 48, 90, 83, 35, + 42, 86, 86, 42, 35, 83, 90, 48, 30, 79, 92, 55, 24, 74, 96, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 28, 54, 69, 60, 34, 11, 24, 51, 68, 62, 38, 13, 21, 48, 66, 64, 41, 16, + 18, 44, 66, 66, 44, 18, 16, 41, 64, 66, 48, 21, 13, 38, 62, 68, 51, 24, 11, 34, 60, 69, 54, 28}, + }, + + // Band_8_4970 + { + // Scaler inc range + {4946, 4970}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 83, 35, + 42, 86, 86, 42, 35, 83, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 28, 54, 69, 60, 34, 11, 24, 51, 68, 62, 38, 13, 21, 48, 66, 64, 41, 16, + 18, 44, 66, 66, 44, 18, 16, 41, 64, 66, 48, 21, 13, 38, 62, 68, 51, 24, 11, 34, 60, 69, 54, 28}, + }, + + // Band_8_4993 + { + // Scaler inc range + {4970, 4993}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 89, 83, 36, + 42, 86, 86, 42, 36, 83, 89, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 28, 54, 69, 60, 34, 11, 24, 51, 68, 62, 38, 13, 21, 48, 66, 64, 41, 16, + 18, 44, 66, 66, 44, 18, 16, 41, 64, 66, 48, 21, 13, 38, 62, 68, 51, 24, 11, 34, 60, 69, 54, 28}, + }, + + // Band_8_5017 + { + // Scaler inc range + {4993, 5017}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 89, 83, 36, + 42, 86, 86, 42, 36, 83, 89, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {32, 60, 72, 60, 32, 0, 28, 54, 69, 60, 34, 11, 25, 51, 67, 62, 38, 13, 21, 48, 66, 64, 41, 16, + 18, 44, 66, 66, 44, 18, 16, 41, 64, 66, 48, 21, 13, 38, 62, 67, 51, 25, 11, 34, 60, 69, 54, 28}, + }, + + // Band_8_5041 + { + // Scaler inc range + {5017, 5041}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 89, 83, 36, + 42, 86, 86, 42, 36, 83, 89, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 60, 70, 60, 33, 0, 28, 54, 68, 60, 35, 11, 25, 51, 67, 62, 38, 13, 21, 48, 67, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 67, 48, 21, 13, 38, 62, 67, 51, 25, 11, 35, 60, 68, 54, 28}, + }, + + // Band_8_5066 + { + // Scaler inc range + {5041, 5066}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 89, 83, 36, + 42, 86, 86, 42, 36, 83, 89, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 60, 70, 60, 33, 0, 28, 54, 68, 60, 35, 11, 25, 51, 67, 62, 38, 13, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 13, 38, 62, 67, 51, 25, 11, 35, 60, 68, 54, 28}, + }, + + // Band_8_5090 + { + // Scaler inc range + {5066, 5090}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 60, 70, 60, 33, 0, 28, 54, 68, 60, 35, 11, 25, 51, 66, 62, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 62, 66, 51, 25, 11, 35, 60, 68, 54, 28}, + }, + + // Band_8_5115 + { + // Scaler inc range + {5090, 5115}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 69, 59, 35, 11, 25, 51, 67, 61, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 61, 67, 51, 25, 11, 35, 59, 69, 54, 28}, + }, + + // Band_8_5140 + { + // Scaler inc range + {5115, 5140}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 69, 59, 35, 11, 25, 51, 67, 61, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 61, 67, 51, 25, 11, 35, 59, 69, 54, 28}, + }, + + // Band_8_5165 + { + // Scaler inc range + {5140, 5165}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 68, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 68, 54, 28}, + }, + + // Band_8_5191 + { + // Scaler inc range + {5165, 5191}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 68, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 68, 54, 28}, + }, + + // Band_8_5217 + { + // Scaler inc range + {5191, 5217}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 68, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 68, 54, 28}, + }, + + // Band_8_5243 + { + // Scaler inc range + {5217, 5243}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 68, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 68, 54, 28}, + }, + + // Band_8_5269 + { + // Scaler inc range + {5243, 5269}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 68, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 66, 63, 41, 16, + 19, 44, 65, 65, 44, 19, 16, 41, 63, 66, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 68, 54, 28}, + }, + + // Band_8_5296 + { + // Scaler inc range + {5269, 5296}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 68, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 65, 63, 41, 17, + 19, 44, 65, 65, 44, 19, 17, 41, 63, 65, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 68, 54, 28}, + }, + + // Band_8_5323 + { + // Scaler inc range + {5296, 5323}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 48, 90, 82, 36, + 42, 86, 86, 42, 36, 82, 90, 48, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 28, 54, 68, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 65, 63, 41, 17, + 19, 44, 65, 65, 44, 19, 17, 41, 63, 65, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 68, 54, 28}, + }, + + // Band_8_5350 + { + // Scaler inc range + {5323, 5350}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 93, 78, 30, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 30, 78, 93, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 29, 54, 67, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 65, 63, 41, 17, + 19, 44, 65, 65, 44, 19, 17, 41, 63, 65, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5377 + { + // Scaler inc range + {5350, 5377}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 29, 54, 67, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 65, 63, 41, 17, + 19, 44, 65, 65, 44, 19, 17, 41, 63, 65, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5405 + { + // Scaler inc range + {5377, 5405}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 29, 54, 67, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 65, 63, 41, 17, + 19, 44, 65, 65, 44, 19, 17, 41, 63, 65, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5433 + { + // Scaler inc range + {5405, 5433}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 95, 74, 25, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 25, 74, 95, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 29, 54, 67, 59, 35, 12, 25, 51, 67, 61, 38, 14, 22, 48, 66, 62, 41, 17, + 20, 44, 64, 64, 44, 20, 17, 41, 62, 66, 48, 22, 14, 38, 61, 67, 51, 25, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5461 + { + // Scaler inc range + {5433, 5461}, + // Coefficients 4 taps + {75, 106, 75, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {33, 59, 72, 59, 33, 0, 29, 54, 67, 59, 35, 12, 26, 51, 66, 61, 38, 14, 22, 48, 66, 62, 41, 17, + 20, 44, 64, 64, 44, 20, 17, 41, 62, 66, 48, 22, 14, 38, 61, 66, 51, 26, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5490 + { + // Scaler inc range + {5461, 5490}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 67, 59, 35, 12, 26, 51, 65, 61, 38, 15, 23, 48, 65, 62, 41, 17, + 20, 44, 64, 64, 44, 20, 17, 41, 62, 65, 48, 23, 15, 38, 61, 65, 51, 26, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5519 + { + // Scaler inc range + {5490, 5519}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 67, 59, 35, 12, 26, 51, 65, 61, 38, 15, 23, 48, 65, 62, 41, 17, + 20, 45, 63, 63, 45, 20, 17, 41, 62, 65, 48, 23, 15, 38, 61, 65, 51, 26, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5548 + { + // Scaler inc range + {5519, 5548}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 67, 59, 35, 12, 26, 51, 65, 61, 38, 15, 23, 48, 65, 62, 41, 17, + 20, 45, 63, 63, 45, 20, 17, 41, 62, 65, 48, 23, 15, 38, 61, 65, 51, 26, 12, 35, 59, 67, 54, 29}, + }, + + // Band_8_5578 + { + // Scaler inc range + {5548, 5578}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 89, 82, 36, + 42, 86, 86, 42, 36, 82, 89, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 59, 35, 13, 26, 51, 65, 61, 38, 15, 23, 48, 65, 62, 41, 17, + 20, 45, 63, 63, 45, 20, 17, 41, 62, 65, 48, 23, 15, 38, 61, 65, 51, 26, 13, 35, 59, 66, 54, 29}, + }, + + // Band_8_5607 + { + // Scaler inc range + {5578, 5607}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 88, 82, 37, + 42, 86, 86, 42, 37, 82, 88, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 59, 35, 13, 26, 51, 66, 60, 38, 15, 23, 48, 65, 62, 41, 17, + 20, 45, 63, 63, 45, 20, 17, 41, 62, 65, 48, 23, 15, 38, 60, 66, 51, 26, 13, 35, 59, 66, 54, 29}, + }, + + // Band_8_5638 + { + // Scaler inc range + {5607, 5638}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 59, 35, 13, 26, 51, 66, 60, 38, 15, 23, 48, 65, 62, 41, 17, + 20, 45, 63, 63, 45, 20, 17, 41, 62, 65, 48, 23, 15, 38, 60, 66, 51, 26, 13, 35, 59, 66, 54, 29}, + }, + + // Band_8_5668 + { + // Scaler inc range + {5638, 5668}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 59, 35, 13, 26, 51, 66, 60, 38, 15, 23, 48, 65, 62, 41, 17, + 20, 45, 63, 63, 45, 20, 17, 41, 62, 65, 48, 23, 15, 38, 60, 66, 51, 26, 13, 35, 59, 66, 54, 29}, + }, + + // Band_8_5699 + { + // Scaler inc range + {5668, 5699}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 59, 35, 13, 26, 51, 66, 60, 38, 15, 23, 48, 64, 62, 42, 17, + 20, 45, 63, 63, 45, 20, 17, 42, 62, 64, 48, 23, 15, 38, 60, 66, 51, 26, 13, 35, 59, 66, 54, 29}, + }, + + // Band_8_5730 + { + // Scaler inc range + {5699, 5730}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 55, 92, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 92, 55, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 63, 62, 42, 18, + 20, 45, 63, 63, 45, 20, 18, 42, 62, 63, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 66, 54, 29}, + }, + + // Band_8_5761 + { + // Scaler inc range + {5730, 5761}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 63, 62, 42, 18, + 20, 45, 63, 63, 45, 20, 18, 42, 62, 63, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 66, 54, 29}, + }, + + // Band_8_5793 + { + // Scaler inc range + {5761, 5793}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 63, 62, 42, 18, + 20, 45, 63, 63, 45, 20, 18, 42, 62, 63, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 66, 54, 29}, + }, + + // Band_8_5825 + { + // Scaler inc range + {5793, 5825}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 54, 66, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 63, 62, 42, 18, + 20, 45, 63, 63, 45, 20, 18, 42, 62, 63, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 66, 54, 29}, + }, + + // Band_8_5858 + { + // Scaler inc range + {5825, 5858}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 53, 67, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 63, 62, 42, 18, + 20, 45, 63, 63, 45, 20, 18, 42, 62, 63, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 67, 53, 29}, + }, + + // Band_8_5891 + { + // Scaler inc range + {5858, 5891}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 53, 67, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 63, 62, 42, 18, + 20, 45, 63, 63, 45, 20, 18, 42, 62, 63, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 67, 53, 29}, + }, + + // Band_8_5924 + { + // Scaler inc range + {5891, 5924}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 29, 53, 67, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 64, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 64, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 67, 53, 29}, + }, + + // Band_8_5958 + { + // Scaler inc range + {5924, 5958}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 30, 53, 66, 58, 36, 13, 26, 51, 65, 60, 39, 15, 23, 48, 64, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 64, 48, 23, 15, 39, 60, 65, 51, 26, 13, 36, 58, 66, 53, 30}, + }, + + // Band_8_5992 + { + // Scaler inc range + {5958, 5992}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 30, 53, 66, 58, 36, 13, 26, 51, 64, 60, 39, 16, 23, 48, 64, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 64, 48, 23, 16, 39, 60, 64, 51, 26, 13, 36, 58, 66, 53, 30}, + }, + + // Band_8_6026 + { + // Scaler inc range + {5992, 6026}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {34, 59, 70, 59, 34, 0, 30, 53, 66, 58, 36, 13, 26, 50, 65, 60, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 60, 65, 50, 26, 13, 36, 58, 66, 53, 30}, + }, + + // Band_8_6061 + { + // Scaler inc range + {6026, 6061}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 91, 78, 31, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 31, 78, 91, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 66, 58, 36, 13, 27, 50, 64, 60, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 60, 64, 50, 27, 13, 36, 58, 66, 53, 30}, + }, + + // Band_8_6096 + { + // Scaler inc range + {6061, 6096}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 94, 74, 26, 56, 90, 78, 32, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 32, 78, 90, 56, 26, 74, 94, 62}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 66, 58, 36, 13, 27, 50, 64, 60, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 60, 64, 50, 27, 13, 36, 58, 66, 53, 30}, + }, + + // Band_8_6132 + { + // Scaler inc range + {6096, 6132}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 93, 74, 27, 56, 90, 78, 32, 49, 88, 82, 37, + 43, 85, 85, 43, 37, 82, 88, 49, 32, 78, 90, 56, 27, 74, 93, 62}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 64, 60, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 60, 64, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6168 + { + // Scaler inc range + {6132, 6168}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 93, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 93, 62}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 64, 60, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 60, 64, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6205 + { + // Scaler inc range + {6168, 6205}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 93, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 93, 62}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 64, 60, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 60, 64, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6242 + { + // Scaler inc range + {6205, 6242}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 93, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 93, 62}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6279 + { + // Scaler inc range + {6242, 6279}, + // Coefficients 4 taps + {76, 104, 76, 0, 62, 93, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 93, 62}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6317 + { + // Scaler inc range + {6279, 6317}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 63, 61, 42, 18, + 21, 45, 62, 62, 45, 21, 18, 42, 61, 63, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6355 + { + // Scaler inc range + {6317, 6355}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 62, 61, 42, 19, + 21, 45, 62, 62, 45, 21, 19, 42, 61, 62, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6394 + { + // Scaler inc range + {6355, 6394}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 62, 61, 42, 19, + 21, 45, 62, 62, 45, 21, 19, 42, 61, 62, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6433 + { + // Scaler inc range + {6394, 6433}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 62, 61, 42, 19, + 21, 45, 62, 62, 45, 21, 19, 42, 61, 62, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6473 + { + // Scaler inc range + {6433, 6473}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 49, 89, 81, 37, + 43, 85, 85, 43, 37, 81, 89, 49, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 62, 61, 42, 19, + 21, 45, 62, 62, 45, 21, 19, 42, 61, 62, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6513 + { + // Scaler inc range + {6473, 6513}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 50, 87, 81, 38, + 43, 85, 85, 43, 38, 81, 87, 50, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 62, 61, 42, 19, + 21, 45, 62, 62, 45, 21, 19, 42, 61, 62, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6554 + { + // Scaler inc range + {6513, 6554}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 50, 87, 81, 38, + 43, 85, 85, 43, 38, 81, 87, 50, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 65, 58, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 62, 61, 42, 19, + 21, 45, 62, 62, 45, 21, 19, 42, 61, 62, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 58, 65, 53, 30}, + }, + + // Band_8_6595 + { + // Scaler inc range + {6554, 6595}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 50, 87, 81, 38, + 43, 85, 85, 43, 38, 81, 87, 50, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 66, 57, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 62, 61, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 61, 62, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 57, 66, 53, 30}, + }, + + // Band_8_6637 + { + // Scaler inc range + {6595, 6637}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 50, 87, 81, 38, + 43, 85, 85, 43, 38, 81, 87, 50, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 66, 57, 36, 14, 27, 50, 65, 59, 39, 16, 24, 48, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 48, 24, 16, 39, 59, 65, 50, 27, 14, 36, 57, 66, 53, 30}, + }, + + // Band_8_6679 + { + // Scaler inc range + {6637, 6679}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 50, 87, 81, 38, + 43, 85, 85, 43, 38, 81, 87, 50, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 59, 68, 59, 35, 0, 30, 53, 66, 57, 36, 14, 27, 50, 64, 59, 39, 17, 24, 48, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 48, 24, 17, 39, 59, 64, 50, 27, 14, 36, 57, 66, 53, 30}, + }, + + // Band_8_6722 + { + // Scaler inc range + {6679, 6722}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 58, 70, 58, 35, 0, 30, 53, 66, 57, 36, 14, 27, 50, 64, 59, 39, 17, 24, 47, 64, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 64, 47, 24, 17, 39, 59, 64, 50, 27, 14, 36, 57, 66, 53, 30}, + }, + + // Band_8_6765 + { + // Scaler inc range + {6722, 6765}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 90, 78, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 78, 90, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 58, 70, 58, 35, 0, 30, 53, 66, 57, 36, 14, 27, 50, 64, 59, 39, 17, 24, 47, 64, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 64, 47, 24, 17, 39, 59, 64, 50, 27, 14, 36, 57, 66, 53, 30}, + }, + + // Band_8_6809 + { + // Scaler inc range + {6765, 6809}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 91, 77, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 77, 91, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 58, 70, 58, 35, 0, 31, 53, 64, 57, 36, 15, 27, 50, 64, 59, 39, 17, 25, 47, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 47, 25, 17, 39, 59, 64, 50, 27, 15, 36, 57, 64, 53, 31}, + }, + + // Band_8_6853 + { + // Scaler inc range + {6809, 6853}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 91, 77, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 77, 91, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {35, 58, 70, 58, 35, 0, 31, 53, 64, 57, 36, 15, 28, 50, 63, 59, 39, 17, 25, 47, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 47, 25, 17, 39, 59, 63, 50, 28, 15, 36, 57, 64, 53, 31}, + }, + + // Band_8_6899 + { + // Scaler inc range + {6853, 6899}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 91, 77, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 77, 91, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 64, 57, 36, 15, 28, 50, 63, 59, 39, 17, 25, 47, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 47, 25, 17, 39, 59, 63, 50, 28, 15, 36, 57, 64, 53, 31}, + }, + + // Band_8_6944 + { + // Scaler inc range + {6899, 6944}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 74, 27, 56, 91, 77, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 77, 91, 56, 27, 74, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 63, 59, 39, 17, 25, 47, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 47, 25, 17, 39, 59, 63, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_6991 + { + // Scaler inc range + {6944, 6991}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 91, 74, 28, 56, 91, 77, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 77, 91, 56, 28, 74, 91, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 63, 59, 39, 17, 25, 47, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 47, 25, 17, 39, 59, 63, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7037 + { + // Scaler inc range + {6991, 7037}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 91, 74, 28, 56, 91, 77, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 77, 91, 56, 28, 74, 91, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 63, 59, 39, 17, 25, 47, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 47, 25, 17, 39, 59, 63, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7085 + { + // Scaler inc range + {7037, 7085}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 91, 77, 32, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 32, 77, 91, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 63, 59, 39, 17, 25, 47, 63, 60, 42, 19, + 22, 45, 61, 61, 45, 22, 19, 42, 60, 63, 47, 25, 17, 39, 59, 63, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7133 + { + // Scaler inc range + {7085, 7133}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 63, 59, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 59, 63, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7182 + { + // Scaler inc range + {7133, 7182}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 63, 59, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 59, 63, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7232 + { + // Scaler inc range + {7182, 7232}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 64, 58, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 58, 64, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7282 + { + // Scaler inc range + {7232, 7282}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 64, 58, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 58, 64, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7333 + { + // Scaler inc range + {7282, 7333}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 64, 58, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 58, 64, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7384 + { + // Scaler inc range + {7333, 7384}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 64, 58, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 58, 64, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7437 + { + // Scaler inc range + {7384, 7437}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 64, 58, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 58, 64, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7490 + { + // Scaler inc range + {7437, 7490}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 64, 58, 39, 17, 25, 47, 62, 60, 42, 20, + 22, 45, 61, 61, 45, 22, 20, 42, 60, 62, 47, 25, 17, 39, 58, 64, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7544 + { + // Scaler inc range + {7490, 7544}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 64, 58, 39, 17, 25, 47, 62, 60, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 60, 62, 47, 25, 17, 39, 58, 64, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7598 + { + // Scaler inc range + {7544, 7598}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 62, 58, 40, 18, 25, 47, 63, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 63, 47, 25, 18, 40, 58, 62, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7654 + { + // Scaler inc range + {7598, 7654}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 63, 57, 37, 15, 28, 50, 62, 58, 40, 18, 25, 47, 63, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 63, 47, 25, 18, 40, 58, 62, 50, 28, 15, 37, 57, 63, 53, 31}, + }, + + // Band_8_7710 + { + // Scaler inc range + {7654, 7710}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 62, 57, 37, 16, 28, 50, 62, 58, 40, 18, 25, 47, 63, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 63, 47, 25, 18, 40, 58, 62, 50, 28, 16, 37, 57, 62, 53, 31}, + }, + + // Band_8_7767 + { + // Scaler inc range + {7710, 7767}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 62, 57, 37, 16, 28, 50, 62, 58, 40, 18, 25, 47, 63, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 63, 47, 25, 18, 40, 58, 62, 50, 28, 16, 37, 57, 62, 53, 31}, + }, + + // Band_8_7825 + { + // Scaler inc range + {7767, 7825}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 53, 62, 57, 37, 16, 28, 50, 62, 58, 40, 18, 25, 47, 63, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 63, 47, 25, 18, 40, 58, 62, 50, 28, 16, 37, 57, 62, 53, 31}, + }, + + // Band_8_7884 + { + // Scaler inc range + {7825, 7884}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 52, 63, 57, 37, 16, 28, 50, 62, 58, 40, 18, 25, 47, 63, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 63, 47, 25, 18, 40, 58, 62, 50, 28, 16, 37, 57, 63, 52, 31}, + }, + + // Band_8_7944 + { + // Scaler inc range + {7884, 7944}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 87, 81, 38, + 44, 84, 84, 44, 38, 81, 87, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 52, 64, 56, 37, 16, 28, 50, 62, 58, 40, 18, 26, 47, 62, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 62, 47, 26, 18, 40, 58, 62, 50, 28, 16, 37, 56, 64, 52, 31}, + }, + + // Band_8_8004 + { + // Scaler inc range + {7944, 8004}, + // Coefficients 4 taps + {76, 104, 76, 0, 63, 92, 73, 28, 56, 90, 77, 33, 50, 86, 81, 39, + 44, 84, 84, 44, 39, 81, 86, 50, 33, 77, 90, 56, 28, 73, 92, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 52, 64, 56, 37, 16, 28, 50, 62, 58, 40, 18, 26, 47, 62, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 62, 47, 26, 18, 40, 58, 62, 50, 28, 16, 37, 56, 64, 52, 31}, + }, + + // Band_8_8066 + { + // Scaler inc range + {8004, 8066}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 56, 90, 77, 33, 50, 86, 81, 39, + 44, 84, 84, 44, 39, 81, 86, 50, 33, 77, 90, 56, 29, 73, 91, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 52, 64, 56, 37, 16, 28, 50, 62, 58, 40, 18, 26, 47, 62, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 62, 47, 26, 18, 40, 58, 62, 50, 28, 16, 37, 56, 64, 52, 31}, + }, + + // Band_8_8128 + { + // Scaler inc range + {8066, 8128}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 56, 90, 77, 33, 50, 86, 81, 39, + 44, 84, 84, 44, 39, 81, 86, 50, 33, 77, 90, 56, 29, 73, 91, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 52, 64, 56, 37, 16, 28, 50, 62, 58, 40, 18, 26, 47, 62, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 62, 47, 26, 18, 40, 58, 62, 50, 28, 16, 37, 56, 64, 52, 31}, + }, + + // Band_8_8192 + { + // Scaler inc range + {8128, 8192}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 56, 90, 77, 33, 50, 86, 81, 39, + 44, 84, 84, 44, 39, 81, 86, 50, 33, 77, 90, 56, 29, 73, 91, 63}, + // Coefficients 6 taps + {36, 58, 68, 58, 36, 0, 31, 52, 64, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 62, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 62, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 64, 52, 31}, + }, + + // Band_8_8257 + { + // Scaler inc range + {8192, 8257}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 56, 90, 77, 33, 50, 86, 81, 39, + 44, 84, 84, 44, 39, 81, 86, 50, 33, 77, 90, 56, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 31, 52, 64, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 62, 59, 42, 20, + 23, 45, 60, 60, 45, 23, 20, 42, 59, 62, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 64, 52, 31}, + }, + + // Band_8_8322 + { + // Scaler inc range + {8257, 8322}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 89, 77, 33, 50, 87, 80, 39, + 44, 84, 84, 44, 39, 80, 87, 50, 33, 77, 89, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8389 + { + // Scaler inc range + {8322, 8389}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 89, 77, 33, 50, 87, 80, 39, + 44, 84, 84, 44, 39, 80, 87, 50, 33, 77, 89, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8456 + { + // Scaler inc range + {8389, 8456}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 89, 77, 33, 50, 87, 80, 39, + 44, 84, 84, 44, 39, 80, 87, 50, 33, 77, 89, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8525 + { + // Scaler inc range + {8456, 8525}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 89, 77, 33, 50, 87, 80, 39, + 44, 84, 84, 44, 39, 80, 87, 50, 33, 77, 89, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8595 + { + // Scaler inc range + {8525, 8595}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 89, 77, 33, 50, 87, 80, 39, + 44, 84, 84, 44, 39, 80, 87, 50, 33, 77, 89, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8666 + { + // Scaler inc range + {8595, 8666}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 50, 87, 80, 39, + 44, 84, 84, 44, 39, 80, 87, 50, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8738 + { + // Scaler inc range + {8666, 8738}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 50, 87, 80, 39, + 45, 83, 83, 45, 39, 80, 87, 50, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 61, 58, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 58, 61, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8812 + { + // Scaler inc range + {8738, 8812}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 50, 87, 80, 39, + 45, 83, 83, 45, 39, 80, 87, 50, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 62, 57, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 57, 62, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8886 + { + // Scaler inc range + {8812, 8886}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 50, 87, 80, 39, + 45, 83, 83, 45, 39, 80, 87, 50, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 63, 56, 37, 16, 29, 50, 62, 57, 40, 18, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 18, 40, 57, 62, 50, 29, 16, 37, 56, 63, 52, 32}, + }, + + // Band_8_8962 + { + // Scaler inc range + {8886, 8962}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9039 + { + // Scaler inc range + {8962, 9039}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 61, 59, 42, 21, + 23, 45, 60, 60, 45, 23, 21, 42, 59, 61, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9118 + { + // Scaler inc range + {9039, 9118}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 61, 59, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 59, 61, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9198 + { + // Scaler inc range + {9118, 9198}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9279 + { + // Scaler inc range + {9198, 9279}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 91, 73, 29, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 29, 73, 91, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9362 + { + // Scaler inc range + {9279, 9362}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9447 + { + // Scaler inc range + {9362, 9447}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9533 + { + // Scaler inc range + {9447, 9533}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9620 + { + // Scaler inc range + {9533, 9620}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9709 + { + // Scaler inc range + {9620, 9709}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9800 + { + // Scaler inc range + {9709, 9800}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 62, 56, 37, 17, 29, 50, 61, 57, 40, 19, 26, 47, 62, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 62, 47, 26, 19, 40, 57, 61, 50, 29, 17, 37, 56, 62, 52, 32}, + }, + + // Band_8_9892 + { + // Scaler inc range + {9800, 9892}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 56, 38, 17, 29, 50, 61, 57, 40, 19, 27, 47, 61, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 61, 47, 27, 19, 40, 57, 61, 50, 29, 17, 38, 56, 61, 52, 32}, + }, + + // Band_8_9986 + { + // Scaler inc range + {9892, 9986}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 56, 38, 17, 29, 50, 61, 57, 40, 19, 27, 47, 61, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 61, 47, 27, 19, 40, 57, 61, 50, 29, 17, 38, 56, 61, 52, 32}, + }, + + // Band_8_10082 + { + // Scaler inc range + {9986, 10082}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 56, 38, 17, 29, 50, 61, 57, 40, 19, 27, 47, 61, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 61, 47, 27, 19, 40, 57, 61, 50, 29, 17, 38, 56, 61, 52, 32}, + }, + + // Band_8_10180 + { + // Scaler inc range + {10082, 10180}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 56, 38, 17, 29, 50, 61, 57, 40, 19, 27, 47, 61, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 61, 47, 27, 19, 40, 57, 61, 50, 29, 17, 38, 56, 61, 52, 32}, + }, + + // Band_8_10280 + { + // Scaler inc range + {10180, 10280}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 56, 38, 17, 29, 50, 61, 57, 40, 19, 27, 47, 61, 58, 42, 21, + 24, 45, 59, 59, 45, 24, 21, 42, 58, 61, 47, 27, 19, 40, 57, 61, 50, 29, 17, 38, 56, 61, 52, 32}, + }, + + // Band_8_10382 + { + // Scaler inc range + {10280, 10382}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 56, 38, 17, 29, 50, 61, 57, 40, 19, 27, 47, 60, 58, 42, 22, + 24, 45, 59, 59, 45, 24, 22, 42, 58, 60, 47, 27, 19, 40, 57, 61, 50, 29, 17, 38, 56, 61, 52, 32}, + }, + + // Band_8_10486 + { + // Scaler inc range + {10382, 10486}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 86, 80, 39, + 45, 83, 83, 45, 39, 80, 86, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 56, 38, 17, 29, 50, 61, 57, 40, 19, 27, 47, 60, 58, 42, 22, + 24, 45, 59, 59, 45, 24, 22, 42, 58, 60, 47, 27, 19, 40, 57, 61, 50, 29, 17, 38, 56, 61, 52, 32}, + }, + + // Band_8_10592 + { + // Scaler inc range + {10486, 10592}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 88, 77, 34, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 34, 77, 88, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {37, 58, 66, 58, 37, 0, 32, 52, 61, 55, 38, 18, 29, 50, 61, 57, 40, 19, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 19, 40, 57, 61, 50, 29, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_10700 + { + // Scaler inc range + {10592, 10700}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 90, 73, 30, 57, 87, 77, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 77, 87, 57, 30, 73, 90, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 60, 57, 40, 19, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 19, 40, 57, 60, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_10810 + { + // Scaler inc range + {10700, 10810}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 87, 77, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 77, 87, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 60, 57, 40, 19, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 19, 40, 57, 60, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_10923 + { + // Scaler inc range + {10810, 10923}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 87, 77, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 77, 87, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 60, 57, 40, 19, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 19, 40, 57, 60, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_11038 + { + // Scaler inc range + {10923, 11038}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 87, 77, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 77, 87, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 59, 57, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 57, 59, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_11155 + { + // Scaler inc range + {11038, 11155}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 87, 77, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 77, 87, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 59, 57, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 57, 59, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_11275 + { + // Scaler inc range + {11155, 11275}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 59, 57, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 57, 59, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_11398 + { + // Scaler inc range + {11275, 11398}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 59, 57, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 57, 59, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_11523 + { + // Scaler inc range + {11398, 11523}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 59, 57, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 57, 59, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_11651 + { + // Scaler inc range + {11523, 11651}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 32, 52, 61, 55, 38, 18, 30, 50, 59, 57, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 57, 59, 50, 30, 18, 38, 55, 61, 52, 32}, + }, + + // Band_8_11782 + { + // Scaler inc range + {11651, 11782}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 58, 64, 58, 38, 0, 33, 52, 60, 55, 38, 18, 30, 49, 61, 56, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 56, 61, 49, 30, 18, 38, 55, 60, 52, 33}, + }, + + // Band_8_11916 + { + // Scaler inc range + {11782, 11916}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 60, 55, 38, 18, 30, 49, 61, 56, 40, 20, 27, 47, 59, 58, 43, 22, + 24, 45, 59, 59, 45, 24, 22, 43, 58, 59, 47, 27, 20, 40, 56, 61, 49, 30, 18, 38, 55, 60, 52, 33}, + }, + + // Band_8_12053 + { + // Scaler inc range + {11916, 12053}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 60, 55, 38, 18, 30, 49, 61, 56, 40, 20, 27, 47, 59, 58, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 58, 59, 47, 27, 20, 40, 56, 61, 49, 30, 18, 38, 55, 60, 52, 33}, + }, + + // Band_8_12193 + { + // Scaler inc range + {12053, 12193}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 73, 31, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 31, 73, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 60, 55, 38, 18, 30, 49, 61, 56, 40, 20, 27, 47, 59, 58, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 58, 59, 47, 27, 20, 40, 56, 61, 49, 30, 18, 38, 55, 60, 52, 33}, + }, + + // Band_8_12336 + { + // Scaler inc range + {12193, 12336}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 88, 73, 32, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 32, 73, 88, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 60, 55, 38, 18, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 18, 38, 55, 60, 52, 33}, + }, + + // Band_8_12483 + { + // Scaler inc range + {12336, 12483}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 88, 73, 32, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 32, 73, 88, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 60, 55, 38, 18, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 18, 38, 55, 60, 52, 33}, + }, + + // Band_8_12633 + { + // Scaler inc range + {12483, 12633}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 60, 55, 38, 18, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 18, 38, 55, 60, 52, 33}, + }, + + // Band_8_12788 + { + // Scaler inc range + {12633, 12788}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 88, 76, 35, 51, 85, 80, 40, + 45, 83, 83, 45, 40, 80, 85, 51, 35, 76, 88, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 59, 55, 38, 19, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 19, 38, 55, 59, 52, 33}, + }, + + // Band_8_12945 + { + // Scaler inc range + {12788, 12945}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 87, 76, 36, 51, 85, 80, 40, + 46, 82, 82, 46, 40, 80, 85, 51, 36, 76, 87, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 52, 59, 55, 38, 19, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 19, 38, 55, 59, 52, 33}, + }, + + // Band_8_13107 + { + // Scaler inc range + {12945, 13107}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 87, 76, 36, 51, 86, 79, 40, + 46, 82, 82, 46, 40, 79, 86, 51, 36, 76, 87, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_13273 + { + // Scaler inc range + {13107, 13273}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 87, 76, 36, 51, 86, 79, 40, + 46, 82, 82, 46, 40, 79, 86, 51, 36, 76, 87, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_13443 + { + // Scaler inc range + {13273, 13443}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 87, 76, 36, 51, 86, 79, 40, + 46, 82, 82, 46, 40, 79, 86, 51, 36, 76, 87, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_13618 + { + // Scaler inc range + {13443, 13618}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 87, 76, 36, 51, 86, 79, 40, + 46, 82, 82, 46, 40, 79, 86, 51, 36, 76, 87, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 61, 56, 40, 20, 27, 47, 60, 57, 43, 22, + 25, 45, 58, 58, 45, 25, 22, 43, 57, 60, 47, 27, 20, 40, 56, 61, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_13797 + { + // Scaler inc range + {13618, 13797}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 89, 72, 32, 57, 87, 76, 36, 51, 86, 79, 40, + 46, 82, 82, 46, 40, 79, 86, 51, 36, 76, 87, 57, 32, 72, 89, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 61, 56, 40, 20, 27, 47, 59, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 59, 47, 27, 20, 40, 56, 61, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_13981 + { + // Scaler inc range + {13797, 13981}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 88, 72, 33, 57, 87, 76, 36, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 36, 76, 87, 57, 33, 72, 88, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 60, 56, 40, 21, 27, 47, 59, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 59, 47, 27, 21, 40, 56, 60, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_14170 + { + // Scaler inc range + {13981, 14170}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 88, 72, 33, 57, 87, 76, 36, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 36, 76, 87, 57, 33, 72, 88, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 60, 56, 40, 21, 27, 47, 59, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 59, 47, 27, 21, 40, 56, 60, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_14364 + { + // Scaler inc range + {14170, 14364}, + // Coefficients 4 taps + {77, 102, 77, 0, 63, 88, 72, 33, 57, 87, 76, 36, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 36, 76, 87, 57, 33, 72, 88, 63}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_14564 + { + // Scaler inc range + {14364, 14564}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 89, 72, 33, 57, 87, 76, 36, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 36, 76, 87, 57, 33, 72, 89, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_14769 + { + // Scaler inc range + {14564, 14769}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 89, 72, 33, 57, 87, 76, 36, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 36, 76, 87, 57, 33, 72, 89, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_14980 + { + // Scaler inc range + {14769, 14980}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 89, 72, 33, 57, 87, 76, 36, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 36, 76, 87, 57, 33, 72, 89, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_15197 + { + // Scaler inc range + {14980, 15197}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 89, 72, 33, 57, 86, 76, 37, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 37, 76, 86, 57, 33, 72, 89, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 55, 38, 19, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 19, 38, 55, 60, 51, 33}, + }, + + // Band_8_15420 + { + // Scaler inc range + {15197, 15420}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 72, 34, 57, 86, 76, 37, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 37, 76, 86, 57, 34, 72, 88, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 59, 55, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 55, 59, 51, 33}, + }, + + // Band_8_15650 + { + // Scaler inc range + {15420, 15650}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 72, 34, 57, 86, 76, 37, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 37, 76, 86, 57, 34, 72, 88, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 59, 55, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 55, 59, 51, 33}, + }, + + // Band_8_15888 + { + // Scaler inc range + {15650, 15888}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 72, 34, 57, 86, 76, 37, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 37, 76, 86, 57, 34, 72, 88, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 59, 55, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 55, 59, 51, 33}, + }, + + // Band_8_16132 + { + // Scaler inc range + {15888, 16132}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 72, 34, 57, 86, 76, 37, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 37, 76, 86, 57, 34, 72, 88, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 54, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_16384 + { + // Scaler inc range + {16132, 16384}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 72, 34, 57, 86, 76, 37, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 37, 76, 86, 57, 34, 72, 88, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 54, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_16644 + { + // Scaler inc range + {16384, 16644}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 72, 34, 57, 86, 76, 37, 51, 85, 79, 41, + 46, 82, 82, 46, 41, 79, 85, 51, 37, 76, 86, 57, 34, 72, 88, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 54, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_16913 + { + // Scaler inc range + {16644, 16913}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 72, 34, 57, 87, 75, 37, 52, 83, 79, 42, + 46, 82, 82, 46, 42, 79, 83, 52, 37, 75, 87, 57, 34, 72, 88, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 54, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_17190 + { + // Scaler inc range + {16913, 17190}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 87, 72, 35, 57, 86, 75, 38, 52, 83, 79, 42, + 46, 82, 82, 46, 42, 79, 83, 52, 38, 75, 86, 57, 35, 72, 87, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 54, 38, 20, 30, 49, 60, 56, 40, 21, 28, 47, 58, 57, 43, 23, + 25, 45, 58, 58, 45, 25, 23, 43, 57, 58, 47, 28, 21, 40, 56, 60, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_17476 + { + // Scaler inc range + {17190, 17476}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 87, 72, 35, 57, 86, 75, 38, 52, 83, 79, 42, + 46, 82, 82, 46, 42, 79, 83, 52, 38, 75, 86, 57, 35, 72, 87, 62}, + // Coefficients 6 taps + {38, 57, 66, 57, 38, 0, 33, 51, 60, 54, 38, 20, 30, 49, 59, 56, 40, 22, 28, 47, 58, 57, 43, 23, + 26, 45, 57, 57, 45, 26, 23, 43, 57, 58, 47, 28, 22, 40, 56, 59, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_17772 + { + // Scaler inc range + {17476, 17772}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 87, 72, 35, 57, 86, 75, 38, 52, 83, 79, 42, + 46, 82, 82, 46, 42, 79, 83, 52, 38, 75, 86, 57, 35, 72, 87, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 60, 54, 38, 20, 30, 49, 59, 56, 40, 22, 28, 47, 58, 57, 43, 23, + 26, 45, 57, 57, 45, 26, 23, 43, 57, 58, 47, 28, 22, 40, 56, 59, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_18079 + { + // Scaler inc range + {17772, 18079}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 71, 35, 57, 86, 75, 38, 52, 83, 79, 42, + 47, 81, 81, 47, 42, 79, 83, 52, 38, 75, 86, 57, 35, 71, 88, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 60, 54, 38, 20, 30, 49, 59, 56, 40, 22, 28, 47, 58, 57, 43, 23, + 26, 45, 57, 57, 45, 26, 23, 43, 57, 58, 47, 28, 22, 40, 56, 59, 49, 30, 20, 38, 54, 60, 51, 33}, + }, + + // Band_8_18396 + { + // Scaler inc range + {18079, 18396}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 88, 71, 35, 57, 86, 75, 38, 52, 84, 78, 42, + 47, 81, 81, 47, 42, 78, 84, 52, 38, 75, 86, 57, 35, 71, 88, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 30, 49, 60, 55, 40, 22, 28, 47, 57, 57, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 57, 57, 47, 28, 22, 40, 55, 60, 49, 30, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_18725 + { + // Scaler inc range + {18396, 18725}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 87, 71, 36, 57, 86, 75, 38, 52, 84, 78, 42, + 47, 81, 81, 47, 42, 78, 84, 52, 38, 75, 86, 57, 36, 71, 87, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 31, 49, 59, 55, 40, 22, 28, 47, 57, 57, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 57, 57, 47, 28, 22, 40, 55, 59, 49, 31, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_19065 + { + // Scaler inc range + {18725, 19065}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 87, 71, 36, 57, 85, 75, 39, 52, 84, 78, 42, + 47, 81, 81, 47, 42, 78, 84, 52, 39, 75, 85, 57, 36, 71, 87, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 31, 49, 59, 55, 40, 22, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 22, 40, 55, 59, 49, 31, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_19418 + { + // Scaler inc range + {19065, 19418}, + // Coefficients 4 taps + {77, 102, 77, 0, 62, 87, 71, 36, 57, 85, 75, 39, 52, 84, 78, 42, + 47, 81, 81, 47, 42, 78, 84, 52, 39, 75, 85, 57, 36, 71, 87, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 31, 49, 59, 55, 40, 22, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 22, 40, 55, 59, 49, 31, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_19784 + { + // Scaler inc range + {19418, 19784}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 87, 71, 36, 57, 85, 75, 39, 52, 83, 78, 43, + 47, 81, 81, 47, 43, 78, 83, 52, 39, 75, 85, 57, 36, 71, 87, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 31, 49, 59, 55, 40, 22, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 22, 40, 55, 59, 49, 31, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_20165 + { + // Scaler inc range + {19784, 20165}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 86, 71, 37, 57, 85, 75, 39, 52, 83, 78, 43, + 47, 81, 81, 47, 43, 78, 83, 52, 39, 75, 85, 57, 37, 71, 86, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 31, 49, 59, 55, 40, 22, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 22, 40, 55, 59, 49, 31, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_20560 + { + // Scaler inc range + {20165, 20560}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 86, 71, 37, 57, 85, 75, 39, 52, 83, 78, 43, + 47, 81, 81, 47, 43, 78, 83, 52, 39, 75, 85, 57, 37, 71, 86, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 31, 49, 59, 55, 40, 22, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 22, 40, 55, 59, 49, 31, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_20972 + { + // Scaler inc range + {20560, 20972}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 86, 71, 37, 57, 84, 75, 40, 52, 83, 78, 43, + 47, 81, 81, 47, 43, 78, 83, 52, 40, 75, 84, 57, 37, 71, 86, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 59, 54, 38, 21, 31, 49, 58, 55, 40, 23, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 23, 40, 55, 58, 49, 31, 21, 38, 54, 59, 51, 33}, + }, + + // Band_8_21400 + { + // Scaler inc range + {20972, 21400}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 86, 71, 37, 57, 84, 75, 40, 52, 83, 78, 43, + 47, 81, 81, 47, 43, 78, 83, 52, 40, 75, 84, 57, 37, 71, 86, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 58, 54, 38, 22, 31, 49, 58, 55, 40, 23, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 23, 40, 55, 58, 49, 31, 22, 38, 54, 58, 51, 33}, + }, + + // Band_8_21845 + { + // Scaler inc range + {21400, 21845}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 85, 71, 38, 57, 85, 74, 40, 52, 83, 78, 43, + 47, 81, 81, 47, 43, 78, 83, 52, 40, 74, 85, 57, 38, 71, 85, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 58, 54, 38, 22, 31, 49, 58, 55, 40, 23, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 23, 40, 55, 58, 49, 31, 22, 38, 54, 58, 51, 33}, + }, + + // Band_8_22310 + { + // Scaler inc range + {21845, 22310}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 85, 71, 38, 57, 85, 74, 40, 52, 82, 78, 44, + 48, 80, 80, 48, 44, 78, 82, 52, 40, 74, 85, 57, 38, 71, 85, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 58, 54, 38, 22, 31, 49, 58, 55, 40, 23, 28, 47, 58, 56, 43, 24, + 26, 45, 57, 57, 45, 26, 24, 43, 56, 58, 47, 28, 23, 40, 55, 58, 49, 31, 22, 38, 54, 58, 51, 33}, + }, + + // Band_8_22795 + { + // Scaler inc range + {22310, 22795}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 86, 70, 38, 57, 84, 74, 41, 52, 83, 77, 44, + 48, 80, 80, 48, 44, 77, 83, 52, 41, 74, 84, 57, 38, 70, 86, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 51, 58, 54, 38, 22, 31, 49, 58, 55, 40, 23, 29, 47, 57, 56, 42, 25, + 26, 45, 57, 57, 45, 26, 25, 42, 56, 57, 47, 29, 23, 40, 55, 58, 49, 31, 22, 38, 54, 58, 51, 33}, + }, + + // Band_8_23302 + { + // Scaler inc range + {22795, 23302}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 85, 70, 39, 57, 84, 74, 41, 52, 83, 77, 44, + 48, 80, 80, 48, 44, 77, 83, 52, 41, 74, 84, 57, 39, 70, 85, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 59, 54, 38, 22, 31, 49, 58, 55, 40, 23, 29, 47, 57, 56, 42, 25, + 26, 45, 57, 57, 45, 26, 25, 42, 56, 57, 47, 29, 23, 40, 55, 58, 49, 31, 22, 38, 54, 59, 50, 33}, + }, + + // Band_8_23831 + { + // Scaler inc range + {23302, 23831}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 85, 70, 39, 57, 84, 74, 41, 52, 83, 77, 44, + 48, 80, 80, 48, 44, 77, 83, 52, 41, 74, 84, 57, 39, 70, 85, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 59, 54, 38, 22, 31, 49, 58, 55, 40, 23, 29, 47, 57, 56, 42, 25, + 27, 45, 56, 56, 45, 27, 25, 42, 56, 57, 47, 29, 23, 40, 55, 58, 49, 31, 22, 38, 54, 59, 50, 33}, + }, + + // Band_8_24385 + { + // Scaler inc range + {23831, 24385}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 85, 70, 39, 57, 84, 74, 41, 52, 82, 77, 45, + 48, 80, 80, 48, 45, 77, 82, 52, 41, 74, 84, 57, 39, 70, 85, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 58, 54, 38, 23, 31, 49, 58, 55, 40, 23, 29, 47, 57, 56, 42, 25, + 27, 45, 56, 56, 45, 27, 25, 42, 56, 57, 47, 29, 23, 40, 55, 58, 49, 31, 23, 38, 54, 58, 50, 33}, + }, + + // Band_8_24966 + { + // Scaler inc range + {24385, 24966}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 84, 70, 40, 57, 83, 74, 42, 53, 81, 77, 45, + 48, 80, 80, 48, 45, 77, 81, 53, 42, 74, 83, 57, 40, 70, 84, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 59, 53, 38, 23, 31, 49, 57, 55, 40, 24, 29, 47, 57, 56, 42, 25, + 27, 45, 56, 56, 45, 27, 25, 42, 56, 57, 47, 29, 24, 40, 55, 57, 49, 31, 23, 38, 53, 59, 50, 33}, + }, + + // Band_8_25575 + { + // Scaler inc range + {24966, 25575}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 84, 70, 40, 57, 84, 73, 42, 53, 81, 77, 45, + 49, 79, 79, 49, 45, 77, 81, 53, 42, 73, 84, 57, 40, 70, 84, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 59, 53, 38, 23, 31, 48, 58, 55, 40, 24, 29, 47, 57, 56, 42, 25, + 27, 45, 56, 56, 45, 27, 25, 42, 56, 57, 47, 29, 24, 40, 55, 58, 48, 31, 23, 38, 53, 59, 50, 33}, + }, + + // Band_8_26214 + { + // Scaler inc range + {25575, 26214}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 83, 70, 41, 57, 83, 73, 43, 53, 82, 76, 45, + 49, 79, 79, 49, 45, 76, 82, 53, 43, 73, 83, 57, 41, 70, 83, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 59, 53, 38, 23, 31, 48, 58, 55, 40, 24, 29, 46, 58, 56, 42, 25, + 27, 44, 57, 57, 44, 27, 25, 42, 56, 58, 46, 29, 24, 40, 55, 58, 48, 31, 23, 38, 53, 59, 50, 33}, + }, + + // Band_8_26887 + { + // Scaler inc range + {26214, 26887}, + // Coefficients 4 taps + {78, 100, 78, 0, 62, 83, 70, 41, 57, 83, 73, 43, 53, 81, 76, 46, + 49, 79, 79, 49, 46, 76, 81, 53, 43, 73, 83, 57, 41, 70, 83, 62}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 59, 53, 38, 23, 31, 48, 59, 54, 40, 24, 29, 46, 58, 56, 42, 25, + 27, 44, 57, 57, 44, 27, 25, 42, 56, 58, 46, 29, 24, 40, 54, 59, 48, 31, 23, 38, 53, 59, 50, 33}, + }, + + // Band_8_27594 + { + // Scaler inc range + {26887, 27594}, + // Coefficients 4 taps + {78, 100, 78, 0, 61, 85, 69, 41, 57, 83, 73, 43, 53, 81, 76, 46, + 49, 79, 79, 49, 46, 76, 81, 53, 43, 73, 83, 57, 41, 69, 85, 61}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 58, 53, 38, 24, 31, 48, 59, 54, 40, 24, 29, 46, 58, 55, 42, 26, + 27, 44, 57, 57, 44, 27, 26, 42, 55, 58, 46, 29, 24, 40, 54, 59, 48, 31, 24, 38, 53, 58, 50, 33}, + }, + + // Band_8_28340 + { + // Scaler inc range + {27594, 28340}, + // Coefficients 4 taps + {78, 100, 78, 0, 61, 84, 69, 42, 57, 82, 73, 44, 53, 81, 76, 46, + 50, 78, 78, 50, 46, 76, 81, 53, 44, 73, 82, 57, 42, 69, 84, 61}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 33, 50, 58, 53, 38, 24, 31, 48, 58, 54, 40, 25, 29, 46, 58, 55, 42, 26, + 27, 44, 57, 57, 44, 27, 26, 42, 55, 58, 46, 29, 25, 40, 54, 58, 48, 31, 24, 38, 53, 58, 50, 33}, + }, + + // Band_8_29127 + { + // Scaler inc range + {28340, 29127}, + // Coefficients 4 taps + {78, 100, 78, 0, 61, 84, 69, 42, 57, 82, 73, 44, 53, 80, 76, 47, + 50, 78, 78, 50, 47, 76, 80, 53, 44, 73, 82, 57, 42, 69, 84, 61}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 34, 50, 57, 53, 38, 24, 31, 48, 58, 54, 40, 25, 29, 46, 58, 55, 42, 26, + 28, 44, 56, 56, 44, 28, 26, 42, 55, 58, 46, 29, 25, 40, 54, 58, 48, 31, 24, 38, 53, 57, 50, 34}, + }, + + // Band_8_29959 + { + // Scaler inc range + {29127, 29959}, + // Coefficients 4 taps + {78, 100, 78, 0, 61, 83, 69, 43, 57, 82, 72, 45, 54, 80, 75, 47, + 50, 78, 78, 50, 47, 75, 80, 54, 45, 72, 82, 57, 43, 69, 83, 61}, + // Coefficients 6 taps + {39, 57, 64, 57, 39, 0, 34, 50, 57, 53, 38, 24, 31, 48, 58, 54, 40, 25, 30, 46, 57, 55, 42, 26, + 28, 44, 56, 56, 44, 28, 26, 42, 55, 57, 46, 30, 25, 40, 54, 58, 48, 31, 24, 38, 53, 57, 50, 34}, + }, + + // Band_8_30840 + { + // Scaler inc range + {29959, 30840}, + // Coefficients 4 taps + {78, 100, 78, 0, 61, 82, 69, 44, 58, 81, 72, 45, 54, 80, 75, 47, + 50, 78, 78, 50, 47, 75, 80, 54, 45, 72, 81, 58, 44, 69, 82, 61}, + // Coefficients 6 taps + {40, 57, 62, 57, 40, 0, 34, 50, 56, 53, 38, 25, 32, 48, 57, 54, 40, 25, 30, 46, 57, 55, 42, 26, + 28, 44, 56, 56, 44, 28, 26, 42, 55, 57, 46, 30, 25, 40, 54, 57, 48, 32, 25, 38, 53, 56, 50, 34}, + }, + + // Band_8_31775 + { + // Scaler inc range + {30840, 31775}, + // Coefficients 4 taps + {79, 98, 79, 0, 61, 82, 69, 44, 58, 80, 72, 46, 54, 79, 75, 48, + 51, 77, 77, 51, 48, 75, 79, 54, 46, 72, 80, 58, 44, 69, 82, 61}, + // Coefficients 6 taps + {40, 57, 62, 57, 40, 0, 34, 50, 56, 53, 38, 25, 32, 48, 56, 54, 40, 26, 30, 46, 56, 55, 42, 27, + 28, 44, 56, 56, 44, 28, 27, 42, 55, 56, 46, 30, 26, 40, 54, 56, 48, 32, 25, 38, 53, 56, 50, 34}, + }, + + // Band_8_32768 + { + // Scaler inc range + {31775, 32768}, + // Coefficients 4 taps + {79, 98, 79, 0, 61, 81, 69, 45, 58, 80, 72, 46, 54, 80, 74, 48, + 51, 77, 77, 51, 48, 74, 80, 54, 46, 72, 80, 58, 45, 69, 81, 61}, + // Coefficients 6 taps + {40, 57, 62, 57, 40, 0, 34, 50, 57, 52, 38, 25, 32, 48, 56, 54, 40, 26, 30, 46, 56, 55, 42, 27, + 28, 44, 56, 56, 44, 28, 27, 42, 55, 56, 46, 30, 26, 40, 54, 56, 48, 32, 25, 38, 52, 57, 50, 34}, + }, + + // Band_8_33825 + { + // Scaler inc range + {32768, 33825}, + // Coefficients 4 taps + {79, 98, 79, 0, 61, 82, 68, 45, 58, 80, 71, 47, 55, 78, 74, 49, + 51, 77, 77, 51, 49, 74, 78, 55, 47, 71, 80, 58, 45, 68, 82, 61}, + // Coefficients 6 taps + {40, 57, 62, 57, 40, 0, 34, 49, 58, 52, 38, 25, 32, 48, 56, 54, 40, 26, 30, 46, 56, 55, 42, 27, + 29, 44, 55, 55, 44, 29, 27, 42, 55, 56, 46, 30, 26, 40, 54, 56, 48, 32, 25, 38, 52, 58, 49, 34}, + }, + + // Band_8_34953 + { + // Scaler inc range + {33825, 34953}, + // Coefficients 4 taps + {79, 98, 79, 0, 61, 81, 68, 46, 58, 80, 71, 47, 55, 78, 74, 49, + 52, 76, 76, 52, 49, 74, 78, 55, 47, 71, 80, 58, 46, 68, 81, 61}, + // Coefficients 6 taps + {40, 56, 64, 56, 40, 0, 34, 49, 57, 52, 38, 26, 32, 48, 57, 53, 40, 26, 30, 46, 57, 54, 42, 27, + 29, 44, 55, 55, 44, 29, 27, 42, 54, 57, 46, 30, 26, 40, 53, 57, 48, 32, 26, 38, 52, 57, 49, 34}, + }, + + // Band_8_36158 + { + // Scaler inc range + {34953, 36158}, + // Coefficients 4 taps + {79, 98, 79, 0, 62, 79, 68, 47, 58, 79, 71, 48, 55, 78, 73, 50, + 52, 76, 76, 52, 50, 73, 78, 55, 48, 71, 79, 58, 47, 68, 79, 62}, + // Coefficients 6 taps + {40, 56, 64, 56, 40, 0, 34, 49, 57, 52, 38, 26, 32, 47, 57, 53, 40, 27, 31, 46, 55, 54, 42, 28, + 29, 44, 55, 55, 44, 29, 28, 42, 54, 55, 46, 31, 27, 40, 53, 57, 47, 32, 26, 38, 52, 57, 49, 34}, + }, + + // Band_8_37449 + { + // Scaler inc range + {36158, 37449}, + // Coefficients 4 taps + {79, 98, 79, 0, 62, 78, 68, 48, 58, 79, 70, 49, 55, 77, 73, 51, + 53, 75, 75, 53, 51, 73, 77, 55, 49, 70, 79, 58, 48, 68, 78, 62}, + // Coefficients 6 taps + {40, 56, 64, 56, 40, 0, 34, 49, 56, 52, 38, 27, 32, 47, 57, 53, 40, 27, 31, 46, 55, 54, 42, 28, + 29, 44, 55, 55, 44, 29, 28, 42, 54, 55, 46, 31, 27, 40, 53, 57, 47, 32, 27, 38, 52, 56, 49, 34}, + }, + + // Band_8_38836 + { + // Scaler inc range + {37449, 38836}, + // Coefficients 4 taps + {80, 96, 80, 0, 62, 78, 68, 48, 59, 78, 70, 49, 56, 76, 73, 51, + 53, 75, 75, 53, 51, 73, 76, 56, 49, 70, 78, 59, 48, 68, 78, 62}, + // Coefficients 6 taps + {40, 56, 64, 56, 40, 0, 34, 49, 56, 52, 38, 27, 33, 47, 55, 53, 40, 28, 31, 46, 55, 54, 42, 28, + 30, 44, 54, 54, 44, 30, 28, 42, 54, 55, 46, 31, 28, 40, 53, 55, 47, 33, 27, 38, 52, 56, 49, 34}, + }, + + // Band_8_40330 + { + // Scaler inc range + {38836, 40330}, + // Coefficients 4 taps + {80, 96, 80, 0, 62, 78, 67, 49, 59, 77, 70, 50, 56, 76, 72, 52, + 54, 74, 74, 54, 52, 72, 76, 56, 50, 70, 77, 59, 49, 67, 78, 62}, + // Coefficients 6 taps + {41, 56, 62, 56, 41, 0, 35, 49, 56, 51, 38, 27, 33, 47, 55, 53, 40, 28, 31, 45, 55, 54, 42, 29, + 30, 44, 54, 54, 44, 30, 29, 42, 54, 55, 45, 31, 28, 40, 53, 55, 47, 33, 27, 38, 51, 56, 49, 35}, + }, + + // Band_8_41943 + { + // Scaler inc range + {40330, 41943}, + // Coefficients 4 taps + {80, 96, 80, 0, 62, 77, 67, 50, 59, 77, 69, 51, 57, 74, 72, 53, + 54, 74, 74, 54, 53, 72, 74, 57, 51, 69, 77, 59, 50, 67, 77, 62}, + // Coefficients 6 taps + {41, 56, 62, 56, 41, 0, 35, 48, 56, 51, 38, 28, 33, 47, 56, 52, 40, 28, 32, 45, 55, 53, 42, 29, + 30, 44, 54, 54, 44, 30, 29, 42, 53, 55, 45, 32, 28, 40, 52, 56, 47, 33, 28, 38, 51, 56, 48, 35}, + }, + + // Band_8_43691 + { + // Scaler inc range + {41943, 43691}, + // Coefficients 4 taps + {80, 96, 80, 0, 62, 76, 67, 51, 59, 76, 69, 52, 57, 75, 71, 53, + 55, 73, 73, 55, 53, 71, 75, 57, 52, 69, 76, 59, 51, 67, 76, 62}, + // Coefficients 6 taps + {41, 56, 62, 56, 41, 0, 35, 48, 56, 51, 38, 28, 33, 47, 55, 52, 40, 29, 32, 45, 54, 53, 42, 30, + 31, 43, 54, 54, 43, 31, 30, 42, 53, 54, 45, 32, 29, 40, 52, 55, 47, 33, 28, 38, 51, 56, 48, 35}, + }, + + // Band_8_45590 + { + // Scaler inc range + {43691, 45590}, + // Coefficients 4 taps + {81, 94, 81, 0, 62, 75, 67, 52, 60, 74, 69, 53, 58, 73, 71, 54, + 56, 72, 72, 56, 54, 71, 73, 58, 53, 69, 74, 60, 52, 67, 75, 62}, + // Coefficients 6 taps + {41, 56, 62, 56, 41, 0, 35, 48, 55, 51, 38, 29, 34, 47, 54, 52, 40, 29, 32, 45, 54, 53, 42, 30, + 31, 43, 54, 54, 43, 31, 30, 42, 53, 54, 45, 32, 29, 40, 52, 54, 47, 34, 29, 38, 51, 55, 48, 35}, + }, + + // Band_8_47663 + { + // Scaler inc range + {45590, 47663}, + // Coefficients 4 taps + {81, 94, 81, 0, 62, 75, 66, 53, 60, 74, 68, 54, 58, 73, 70, 55, + 56, 72, 72, 56, 55, 70, 73, 58, 54, 68, 74, 60, 53, 66, 75, 62}, + // Coefficients 6 taps + {42, 56, 60, 56, 42, 0, 35, 48, 55, 50, 38, 30, 34, 46, 55, 51, 40, 30, 33, 45, 53, 52, 42, 31, + 32, 43, 53, 53, 43, 32, 31, 42, 52, 53, 45, 33, 30, 40, 51, 55, 46, 34, 30, 38, 50, 55, 48, 35}, + }, + + // Band_8_49932 + { + // Scaler inc range + {47663, 49932}, + // Coefficients 4 taps + {81, 94, 81, 0, 62, 74, 66, 54, 60, 73, 68, 55, 59, 71, 70, 56, + 57, 71, 71, 57, 56, 70, 71, 59, 55, 68, 73, 60, 54, 66, 74, 62}, + // Coefficients 6 taps + {42, 55, 62, 55, 42, 0, 36, 48, 53, 50, 39, 30, 34, 46, 54, 51, 40, 31, 33, 45, 53, 52, 42, 31, + 32, 43, 53, 53, 43, 32, 31, 42, 52, 53, 45, 33, 31, 40, 51, 54, 46, 34, 30, 39, 50, 53, 48, 36}, + }, + + // Band_8_52429 + { + // Scaler inc range + {49932, 52429}, + // Coefficients 4 taps + {82, 92, 82, 0, 62, 73, 66, 55, 61, 72, 67, 56, 59, 71, 69, 57, + 58, 70, 70, 58, 57, 69, 71, 59, 56, 67, 72, 61, 55, 66, 73, 62}, + // Coefficients 6 taps + {42, 55, 62, 55, 42, 0, 36, 47, 53, 50, 39, 31, 35, 46, 53, 51, 40, 31, 34, 45, 52, 51, 42, 32, + 33, 43, 52, 52, 43, 33, 32, 42, 51, 52, 45, 34, 31, 40, 51, 53, 46, 35, 31, 39, 50, 53, 47, 36}, + }, + + // Band_8_55188 + { + // Scaler inc range + {52429, 55188}, + // Coefficients 4 taps + {82, 92, 82, 0, 63, 71, 66, 56, 61, 71, 67, 57, 60, 70, 68, 58, + 59, 69, 69, 59, 58, 68, 70, 60, 57, 67, 71, 61, 56, 66, 71, 63}, + // Coefficients 6 taps + {43, 55, 60, 55, 43, 0, 36, 47, 53, 49, 39, 32, 35, 46, 53, 50, 40, 32, 34, 44, 52, 51, 42, 33, + 33, 43, 52, 52, 43, 33, 33, 42, 51, 52, 44, 34, 32, 40, 50, 53, 46, 35, 32, 39, 49, 53, 47, 36}, + }, + + // Band_8_58254 + { + // Scaler inc range + {55188, 58254}, + // Coefficients 4 taps + {83, 90, 83, 0, 63, 71, 65, 57, 62, 69, 67, 58, 60, 70, 68, 58, + 59, 69, 69, 59, 58, 68, 70, 60, 58, 67, 69, 62, 57, 65, 71, 63}, + // Coefficients 6 taps + {43, 55, 60, 55, 43, 0, 37, 47, 52, 49, 39, 32, 36, 45, 52, 50, 40, 33, 35, 44, 52, 50, 42, 33, + 34, 43, 51, 51, 43, 34, 33, 42, 50, 52, 44, 35, 33, 40, 50, 52, 45, 36, 32, 39, 49, 52, 47, 37}, + }, + + // Band_8_61681 + { + // Scaler inc range + {58254, 61681}, + // Coefficients 4 taps + {83, 90, 83, 0, 63, 70, 65, 58, 62, 69, 66, 59, 61, 69, 67, 59, + 60, 68, 68, 60, 59, 67, 69, 61, 59, 66, 69, 62, 58, 65, 70, 63}, + // Coefficients 6 taps + {44, 54, 60, 54, 44, 0, 37, 46, 53, 48, 39, 33, 36, 45, 51, 49, 41, 34, 35, 44, 51, 50, 42, 34, + 35, 43, 50, 50, 43, 35, 34, 42, 50, 51, 44, 35, 34, 41, 49, 51, 45, 36, 33, 39, 48, 53, 46, 37}, + }, + + // Band_8_65536 + { + // Scaler inc range + {61681, 65536}, + // Coefficients 4 taps + {83, 90, 83, 0, 63, 69, 65, 59, 62, 68, 66, 60, 62, 68, 66, 60, + 61, 67, 67, 61, 60, 66, 68, 62, 60, 66, 68, 62, 59, 65, 69, 63}, + // Coefficients 6 taps + {45, 54, 58, 54, 45, 0, 38, 46, 50, 48, 40, 34, 37, 45, 50, 49, 41, 34, 36, 44, 50, 49, 42, 35, + 35, 43, 50, 50, 43, 35, 35, 42, 49, 50, 44, 36, 34, 41, 49, 50, 45, 37, 34, 40, 48, 50, 46, 38}, + }, + + // Band_8_69905 + { + // Scaler inc range + {65536, 69905}, + // Coefficients 4 taps + {84, 88, 84, 0, 63, 67, 65, 61, 63, 67, 65, 61, 62, 67, 66, 61, + 62, 66, 66, 62, 61, 66, 67, 62, 61, 65, 67, 63, 61, 65, 67, 63}, + // Coefficients 6 taps + {45, 54, 58, 54, 45, 0, 38, 46, 50, 47, 40, 35, 38, 45, 49, 48, 41, 35, 37, 44, 49, 48, 42, 36, + 36, 43, 49, 49, 43, 36, 36, 42, 48, 49, 44, 37, 35, 41, 48, 49, 45, 38, 35, 40, 47, 50, 46, 38}, + }, + + // Band_8_74898 + { + // Scaler inc range + {69905, 74898}, + // Coefficients 4 taps + {84, 88, 84, 0, 64, 66, 65, 61, 63, 66, 65, 62, 63, 66, 65, 62, + 62, 66, 66, 62, 62, 65, 66, 63, 62, 65, 66, 63, 61, 65, 66, 64}, + // Coefficients 6 taps + {46, 53, 58, 53, 46, 0, 39, 45, 49, 47, 40, 36, 38, 44, 50, 47, 41, 36, 38, 44, 47, 48, 42, 37, + 37, 43, 48, 48, 43, 37, 37, 42, 48, 47, 44, 38, 36, 41, 47, 50, 44, 38, 36, 40, 47, 49, 45, 39}, + }, + + // Band_8_80660 + { + // Scaler inc range + {74898, 80660}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 66, 64, 62, 63, 66, 65, 62, 63, 65, 65, 63, + 63, 65, 65, 63, 63, 65, 65, 63, 62, 65, 66, 63, 62, 64, 66, 64}, + // Coefficients 6 taps + {47, 53, 56, 53, 47, 0, 39, 45, 48, 46, 41, 37, 39, 44, 49, 46, 41, 37, 38, 43, 48, 47, 42, 38, + 38, 43, 47, 47, 43, 38, 38, 42, 47, 48, 43, 38, 37, 41, 46, 49, 44, 39, 37, 41, 46, 48, 45, 39}, + }, + + // Band_8_87381 + { + // Scaler inc range + {80660, 87381}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 65, 64, 63, 64, 65, 64, 63, 63, 65, 65, 63, + 63, 65, 65, 63, 63, 65, 65, 63, 63, 64, 65, 64, 63, 64, 65, 64}, + // Coefficients 6 taps + {48, 53, 54, 53, 48, 0, 40, 44, 48, 45, 41, 38, 40, 44, 46, 46, 42, 38, 39, 43, 47, 46, 42, 39, + 39, 43, 46, 46, 43, 39, 39, 42, 46, 47, 43, 39, 38, 42, 46, 46, 44, 40, 38, 41, 45, 48, 44, 40}, + }, + + // Band_8_95325 + { + // Scaler inc range + {87381, 95325}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 65, 64, 63, 64, 65, 64, 63, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 63, 64, 65, 64, 63, 64, 65, 64}, + // Coefficients 6 taps + {49, 52, 54, 52, 49, 0, 41, 44, 46, 45, 41, 39, 40, 44, 45, 45, 42, 40, 40, 43, 46, 45, 42, 40, + 40, 43, 45, 45, 43, 40, 40, 42, 45, 46, 43, 40, 40, 42, 45, 45, 44, 40, 39, 41, 45, 46, 44, 41}, + }, + + // Band_8_104858 + { + // Scaler inc range + {95325, 104858}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {49, 52, 54, 52, 49, 0, 41, 44, 45, 44, 42, 40, 41, 43, 45, 44, 42, 41, 41, 43, 45, 44, 42, 41, + 41, 43, 44, 44, 43, 41, 41, 42, 44, 45, 43, 41, 41, 42, 44, 45, 43, 41, 40, 42, 44, 45, 44, 41}, + }, + + // Band_8_116508 + { + // Scaler inc range + {104858, 116508}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {50, 52, 52, 52, 50, 0, 42, 43, 45, 43, 42, 41, 42, 43, 44, 44, 42, 41, 42, 43, 43, 44, 43, 41, + 42, 43, 43, 43, 43, 42, 41, 43, 44, 43, 43, 42, 41, 42, 44, 44, 43, 42, 41, 42, 43, 45, 43, 42}, + }, + + // Band_8_131072 + { + // Scaler inc range + {116508, 131072}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 42, 43, 44, 43, 42, 42, 42, 43, 43, 43, 43, 42, 42, 43, 43, 43, 43, 42, + 42, 43, 43, 43, 43, 42, 42, 43, 43, 43, 43, 42, 42, 43, 43, 43, 43, 42, 42, 42, 43, 44, 43, 42}, + }, + + // Band_8_149797 + { + // Scaler inc range + {131072, 149797}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 43, 43, 42, 43, 43, 42, 43, 43, 42, 43, 43, 42, 42, 43, 43, 43, 43, 42, + 42, 43, 43, 43, 43, 42, 42, 43, 43, 43, 43, 42, 42, 43, 43, 42, 43, 43, 42, 43, 43, 42, 43, 43}, + }, + + // Band_8_174763 + { + // Scaler inc range + {149797, 174763}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, + 43, 43, 42, 42, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43}, + }, + + // Band_8_209715 + { + // Scaler inc range + {174763, 209715}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, + 43, 43, 42, 42, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43}, + }, + + // Band_8_262144 + { + // Scaler inc range + {209715, 262144}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, + 43, 43, 42, 42, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43}, + }, + + // Band_8_349525 + { + // Scaler inc range + {262144, 349525}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, + 43, 43, 42, 42, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43}, + }, + + // Band_8_524288 + { + // Scaler inc range + {349525, 524288}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, + 43, 43, 42, 42, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43}, + }, + + // Band_8_1048576 + { + // Scaler inc range + {524288, 1048576}, + // Coefficients 4 taps + {85, 86, 85, 0, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, + // Coefficients 6 taps + {51, 51, 52, 51, 51, 0, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, + 43, 43, 42, 42, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43, 43, 43, 43, 41, 43, 43}, + }, + }, +}; + +#endif // YUV_SCALER_PARA_SET diff --git a/mindspore/ccsrc/minddata/dataset/kernels/tensor_op.h b/mindspore/ccsrc/minddata/dataset/kernels/tensor_op.h index b6fad31330..8e90c8c325 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/tensor_op.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/tensor_op.h @@ -99,6 +99,7 @@ constexpr char kCropOp[] = "CropOp"; constexpr char kEqualizeOp[] = "EqualizeOp"; constexpr char kHwcToChwOp[] = "HwcToChwOp"; constexpr char kInvertOp[] = "InvertOp"; +constexpr char kMixUpBatchOp[] = "MixUpBatchOp"; constexpr char kNormalizeOp[] = "NormalizeOp"; constexpr char kPadOp[] = "PadOp"; constexpr char kRandomColorAdjustOp[] = "RandomColorAdjustOp"; @@ -120,6 +121,8 @@ constexpr char kResizeOp[] = "ResizeOp"; constexpr char kResizeWithBBoxOp[] = "ResizeWithBBoxOp"; constexpr char kSwapRedBlueOp[] = "SwapRedBlueOp"; constexpr char kUniformAugOp[] = "UniformAugOp"; +constexpr char kSoftDvppDecodeRandomCropResizeJpegOp[] = "SoftDvppDecodeRandomCropResizeJpegOp"; +constexpr char kSoftDvppDecodeReiszeJpegOp[] = "SoftDvppDecodeReiszeJpegOp"; // text constexpr char kBasicTokenizerOp[] = "BasicTokenizerOp"; diff --git a/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt b/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt index 4b2a30c9f1..5bd3752d6b 100644 --- a/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/mindrecord/CMakeLists.txt @@ -28,9 +28,9 @@ set_target_properties(_c_mindrecord PROPERTIES # add link library if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") - target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite mindspore mindspore_gvar mindspore::protobuf) + target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite mindspore mindspore::protobuf) else() - target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite ${PYTHON_LIB} ${SECUREC_LIBRARY} mindspore mindspore_gvar mindspore::protobuf) + target_link_libraries(_c_mindrecord PRIVATE mindspore::sqlite ${PYTHON_LIB} ${SECUREC_LIBRARY} mindspore mindspore::protobuf) endif() if (USE_GLOG) diff --git a/mindspore/ccsrc/minddata/mindrecord/include/shard_pk_sample.h b/mindspore/ccsrc/minddata/mindrecord/include/shard_pk_sample.h index 04f47db358..1adb7bbdcd 100644 --- a/mindspore/ccsrc/minddata/mindrecord/include/shard_pk_sample.h +++ b/mindspore/ccsrc/minddata/mindrecord/include/shard_pk_sample.h @@ -29,19 +29,23 @@ namespace mindspore { namespace mindrecord { class ShardPkSample : public ShardCategory { public: - ShardPkSample(const std::string &category_field, int64_t num_elements); + ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_samples); - ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_categories); + ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_categories, int64_t num_samples); - ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_categories, uint32_t seed); + ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_categories, uint32_t seed, + int64_t num_samples); ~ShardPkSample() override{}; MSRStatus SufExecute(ShardTask &tasks) override; + int64_t GetNumSamples() const { return num_samples_; } + private: bool shuffle_; std::shared_ptr shuffle_op_; + int64_t num_samples_; }; } // namespace mindrecord } // namespace mindspore diff --git a/mindspore/ccsrc/minddata/mindrecord/include/shard_reader.h b/mindspore/ccsrc/minddata/mindrecord/include/shard_reader.h index e08375b10f..6f185d5a4e 100644 --- a/mindspore/ccsrc/minddata/mindrecord/include/shard_reader.h +++ b/mindspore/ccsrc/minddata/mindrecord/include/shard_reader.h @@ -49,6 +49,7 @@ #include "minddata/mindrecord/include/shard_error.h" #include "minddata/mindrecord/include/shard_index_generator.h" #include "minddata/mindrecord/include/shard_operator.h" +#include "minddata/mindrecord/include/shard_pk_sample.h" #include "minddata/mindrecord/include/shard_reader.h" #include "minddata/mindrecord/include/shard_sample.h" #include "minddata/mindrecord/include/shard_shuffle.h" diff --git a/mindspore/ccsrc/minddata/mindrecord/include/shard_task.h b/mindspore/ccsrc/minddata/mindrecord/include/shard_task.h index 6074a036da..a9507f0fb5 100644 --- a/mindspore/ccsrc/minddata/mindrecord/include/shard_task.h +++ b/mindspore/ccsrc/minddata/mindrecord/include/shard_task.h @@ -53,7 +53,8 @@ class ShardTask { std::tuple, std::vector, json> &GetRandomTask(); - static ShardTask Combine(std::vector &category_tasks, bool replacement, int64_t num_elements); + static ShardTask Combine(std::vector &category_tasks, bool replacement, int64_t num_elements, + int64_t num_samples); uint32_t categories; diff --git a/mindspore/ccsrc/minddata/mindrecord/io/shard_reader.cc b/mindspore/ccsrc/minddata/mindrecord/io/shard_reader.cc index c42b732463..3aa40434f0 100644 --- a/mindspore/ccsrc/minddata/mindrecord/io/shard_reader.cc +++ b/mindspore/ccsrc/minddata/mindrecord/io/shard_reader.cc @@ -827,6 +827,12 @@ MSRStatus ShardReader::CountTotalRows(const std::vector &file_paths std::string category_field = category_op->GetCategoryField(); auto num_classes = GetNumClasses(category_field); num_samples = category_op->GetNumSamples(num_samples, num_classes); + if (std::dynamic_pointer_cast(op)) { + auto tmp = std::dynamic_pointer_cast(op)->GetNumSamples(); + if (tmp != 0) { + num_samples = std::min(num_samples, tmp); + } + } } else if (std::dynamic_pointer_cast(op)) { if (std::dynamic_pointer_cast(op)) { auto sampler_op = std::dynamic_pointer_cast(op); @@ -958,6 +964,14 @@ MSRStatus ShardReader::CreateTasksByCategory(const std::vector(op); auto categories = category_op->GetCategories(); int64_t num_elements = category_op->GetNumElements(); + int64_t num_samples = 0; + if (std::dynamic_pointer_cast(op)) { + num_samples = std::dynamic_pointer_cast(op)->GetNumSamples(); + if (num_samples < 0) { + MS_LOG(ERROR) << "Parameter num_samples is not positive or zero"; + return FAILED; + } + } if (num_elements <= 0) { MS_LOG(ERROR) << "Parameter num_element is not positive"; return FAILED; @@ -1006,7 +1020,7 @@ MSRStatus ShardReader::CreateTasksByCategory(const std::vectorGetReplacement(), num_elements); + tasks_ = ShardTask::Combine(categoryTasks, category_op->GetReplacement(), num_elements, num_samples); if (SUCCESS != (*category_op)(tasks_)) { return FAILED; } diff --git a/mindspore/ccsrc/minddata/mindrecord/meta/shard_pk_sample.cc b/mindspore/ccsrc/minddata/mindrecord/meta/shard_pk_sample.cc index 081a48352d..ed4cf019dc 100644 --- a/mindspore/ccsrc/minddata/mindrecord/meta/shard_pk_sample.cc +++ b/mindspore/ccsrc/minddata/mindrecord/meta/shard_pk_sample.cc @@ -22,15 +22,18 @@ using mindspore::MsLogLevel::ERROR; namespace mindspore { namespace mindrecord { -ShardPkSample::ShardPkSample(const std::string &category_field, int64_t num_elements) - : ShardCategory(category_field, num_elements, std::numeric_limits::max(), true), shuffle_(false) {} - -ShardPkSample::ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_categories) - : ShardCategory(category_field, num_elements, num_categories, true), shuffle_(false) {} +ShardPkSample::ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_samples) + : ShardCategory(category_field, num_elements, std::numeric_limits::max(), true), + shuffle_(false), + num_samples_(num_samples) {} ShardPkSample::ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_categories, - uint32_t seed) - : ShardCategory(category_field, num_elements, num_categories, true), shuffle_(true) { + int64_t num_samples) + : ShardCategory(category_field, num_elements, num_categories, true), shuffle_(false), num_samples_(num_samples) {} + +ShardPkSample::ShardPkSample(const std::string &category_field, int64_t num_elements, int64_t num_categories, + uint32_t seed, int64_t num_samples) + : ShardCategory(category_field, num_elements, num_categories, true), shuffle_(true), num_samples_(num_samples) { shuffle_op_ = std::make_shared(seed, kShuffleSample); // do shuffle and replacement } diff --git a/mindspore/ccsrc/minddata/mindrecord/meta/shard_task.cc b/mindspore/ccsrc/minddata/mindrecord/meta/shard_task.cc index 972e3b2d14..bfacc90ce6 100644 --- a/mindspore/ccsrc/minddata/mindrecord/meta/shard_task.cc +++ b/mindspore/ccsrc/minddata/mindrecord/meta/shard_task.cc @@ -86,7 +86,8 @@ std::tuple, std::vector, json> &ShardTa return task_list_[dis(gen)]; } -ShardTask ShardTask::Combine(std::vector &category_tasks, bool replacement, int64_t num_elements) { +ShardTask ShardTask::Combine(std::vector &category_tasks, bool replacement, int64_t num_elements, + int64_t num_samples) { ShardTask res; if (category_tasks.empty()) return res; auto total_categories = category_tasks.size(); @@ -96,9 +97,12 @@ ShardTask ShardTask::Combine(std::vector &category_tasks, bool replac for (uint32_t i = 1; i < total_categories; i++) { minTasks = std::min(minTasks, category_tasks[i].Size()); } + int64_t count = 0; for (uint32_t task_no = 0; task_no < minTasks; task_no++) { for (uint32_t i = 0; i < total_categories; i++) { + if (num_samples != 0 && count == num_samples) break; res.InsertTask(std::move(category_tasks[i].GetTaskByID(static_cast(task_no)))); + count++; } } } else { @@ -109,9 +113,12 @@ ShardTask ShardTask::Combine(std::vector &category_tasks, bool replac if (num_elements != std::numeric_limits::max()) { maxTasks = static_cast(num_elements); } + int64_t count = 0; for (uint32_t i = 0; i < total_categories; i++) { for (uint32_t j = 0; j < maxTasks; j++) { + if (num_samples != 0 && count == num_samples) break; res.InsertTask(category_tasks[i].GetRandomTask()); + count++; } } } diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.cc b/mindspore/ccsrc/pipeline/jit/parse/parse.cc index cadb0f6199..be75d6ac2e 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.cc @@ -60,6 +60,17 @@ FuncGraphPtr ParsePythonCode(const py::object &obj, const std::string &python_mo return func_graph; } +ValuePtr GetMixedPrecisionTargetType(const FuncGraphPtr &func_graph, const AnfNodePtr ¶m) { + TypePtr dst_type; + if (func_graph->has_flag(GRAPH_FLAG_MIX_PRECISION_FP32)) { + return kFloat32; + } else if (func_graph->has_flag(GRAPH_FLAG_MIX_PRECISION_FP16)) { + return kFloat16; + } else { + return kNone; + } +} + // if any mixed precision flag add a cast node after the parameter node. AnfNodePtr GetMixedPrecisionCastHelp(const FuncGraphPtr &func_graph, const AnfNodePtr ¶m) { TypePtr dst_type; diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse.h b/mindspore/ccsrc/pipeline/jit/parse/parse.h index afb72ba5c9..47366b664e 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse.h +++ b/mindspore/ccsrc/pipeline/jit/parse/parse.h @@ -359,6 +359,7 @@ class ParseAst { bool UpdateFuncGraphFlags(py::object obj, const FuncGraphPtr &func_graph); AnfNodePtr GetMixedPrecisionCastHelp(const FuncGraphPtr &func_graph, const AnfNodePtr ¶m); +ValuePtr GetMixedPrecisionTargetType(const FuncGraphPtr &func_graph, const AnfNodePtr ¶m); } // namespace parse } // namespace mindspore diff --git a/mindspore/ccsrc/pipeline/jit/parse/parse_base.h b/mindspore/ccsrc/pipeline/jit/parse/parse_base.h index d3c6851eda..d2c8d7a2f4 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/parse_base.h +++ b/mindspore/ccsrc/pipeline/jit/parse/parse_base.h @@ -69,6 +69,7 @@ const char PYTHON_MOD_GET_MODULE_NAMESPACE[] = "get_module_namespace"; const char PYTHON_MOD_GET_MEMBER_NAMESPACE_SYMBOL[] = "get_class_member_namespace_symbol"; const char PYTHON_MOD_GET_PARSE_METHOD[] = "get_parse_method_of_class"; const char PYTHON_MOD_GET_BPROP_METHOD[] = "get_bprop_method_of_class"; +const char PYTHON_MOD_CONVERT_TO_MS_TENSOR[] = "convert_to_ms_tensor"; const char PYTHON_PARSE_GET_ARGS[] = "get_args"; const char PYTHON_PARSE_GET_ARGS_DEFAULT_VALUES[] = "get_args_default_values"; diff --git a/mindspore/ccsrc/pipeline/jit/parse/resolve.cc b/mindspore/ccsrc/pipeline/jit/parse/resolve.cc index 48f3a24652..9f0a4b495c 100644 --- a/mindspore/ccsrc/pipeline/jit/parse/resolve.cc +++ b/mindspore/ccsrc/pipeline/jit/parse/resolve.cc @@ -70,6 +70,7 @@ bool SymbolResolver::Resolve() { } namespace { +// if any mixed precision flag add a cast node after the parameter node. // argument obj should be python Parameter object // it will be converted to Parameter node here AnfNodePtr ResolveParameterObj(const FuncGraphPtr &func_graph, const py::object &obj) { @@ -112,11 +113,12 @@ AnfNodePtr ResolveParameterObj(const FuncGraphPtr &func_graph, const py::object } auto iter = func_graph->make_ref_params().find(para_node); if (iter == func_graph->make_ref_params().end()) { - AnfNodePtr value = GetMixedPrecisionCastHelp(func_graph, para_node); + ValuePtr target_type = GetMixedPrecisionTargetType(func_graph, para_node); AnfNodePtr make_ref = NewValueNode(prim::kPrimMakeRef); AnfNodePtr ref_key = NewValueNode(std::make_shared(param_name)); - AnfNodePtr ref_node = func_graph->NewCNode({make_ref, ref_key, value, para_node}); + AnfNodePtr target_type_node = NewValueNode(target_type); + AnfNodePtr ref_node = func_graph->NewCNode({make_ref, ref_key, para_node, target_type_node}); func_graph->make_ref_params()[para_node] = ref_node; func_graph->add_parameter_obj_node(ref_node); return ref_node; diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc index 2dd0ba6b49..b25fcdd38b 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.cc @@ -36,116 +36,12 @@ #include "utils/convert_utils.h" #include "utils/ms_context.h" #include "pipeline/jit/parse/data_converter.h" +#include "abstract/primitive_infer_map.h" #include "abstract/param_validator.h" #include "utils/ms_utils.h" namespace mindspore { namespace abstract { -PrimitiveEvalImplMap &GetPrimitiveToEvalImplMap() { - static PrimitiveEvalImplMap prim_eval_implement_map = { - // Statements - {prim::kPrimReturn, {InferImplReturn, true}}, - {prim::kPrimTypeOf, {InferImplTypeof, false}}, - {prim::kPrimHasType, {InferImplHasType, false}}, - {prim::kPrimDot, {InferImplDot, true}}, - {prim::kPrimSwitch, {InferImplSwitch, true}}, - {prim::kPrimSwitchLayer, {InferImplSwitchLayer, true}}, - {prim::kPrimIs_, {InferImplIs_, true}}, - {prim::kPrimIsNot, {InferImplIsNot, true}}, - {prim::kPrimInDict, {InferImplInDict, true}}, - {prim::kPrimNotInDict, {InferImplNotInDict, true}}, - {prim::kPrimIsConsant, {InferImplIsConstant, true}}, - // Maths - {prim::kPrimMaximumGrad, {InferImplMinOrMaxGrad, true}}, - {prim::kPrimMinimumGrad, {InferImplMinOrMaxGrad, true}}, - // Array - {prim::kPrimScalarToArray, {InferImplScalarToArray, true}}, - {prim::kPrimArrayToScalar, {InferImplArrayToScalar, true}}, - {prim::kPrimBroadcastShape, {InferImplBroadCastShape, true}}, - {prim::kPrimPack, {InferImplPack, true}}, - {prim::kPrimUnique, {InferImplUnique, true}}, - {prim::kPrimUniqueGrad, {InferImplUniqueGrad, true}}, - // Structure - {prim::kPrimMakeTuple, {InferImplMakeTuple, true}}, - {prim::kPrimMakeList, {InferImplMakeList, true}}, - {prim::kPrimMakeDict, {InferImplMakeDict, true}}, - {prim::kPrimMakeSlice, {InferImplMakeSlice, true}}, - {prim::kPrimMakeKeywordArg, {InferImplMakeKwarg, true}}, - {prim::kPrimExtractKeywordArg, {InferImplExtractKwarg, true}}, - {prim::kPrimMakeRecord, {InferImplMakeRecord, false}}, - {prim::kPrimTupleGetItem, {InferImplTupleGetItem, true}}, - {prim::kPrimListGetItem, {InferImplListGetItem, true}}, - {prim::kPrimTupleSetItem, {InferImplTupleSetItem, true}}, - {prim::kPrimListSetItem, {InferImplListSetItem, true}}, - {prim::kPrimDictGetItem, {InferImplDictGetItem, true}}, - {prim::kPrimDictSetItem, {InferImplDictSetItem, true}}, - {prim::kPrimListAppend, {InferImplListAppend, true}}, - {prim::kPrimTupleLen, {InferImplTupleLen, true}}, - {prim::kPrimListLen, {InferImplListLen, true}}, - {prim::kPrimArrayLen, {InferImplArrayLen, true}}, - {prim::kPrimListMap, {InferImplListMap, false}}, - {prim::kPrimListReduce, {InferImplListReduce, false}}, - {prim::kPrimTupleReversed, {InferImplTupleReversed, false}}, - {prim::kPrimReducedShape, {InferImplReduceShape, false}}, - {prim::kPrimTupleDiv, {InferImplTupleDiv, false}}, - {prim::kPrimTupleToArray, {InferImplTuple2Array, false}}, - {prim::kPrimShapeMul, {InferImplShapeMul, false}}, - {prim::kPrimTupleEqual, {InferImplTupleEqual, false}}, - {prim::kPrimListEqual, {InferImplListEqual, false}}, - {prim::kPrimMakeRange, {InferImplMakeRange, false}}, - {prim::kPrimStopGradient, {InferImplStopGradient, false}}, - {prim::kPrimStringEqual, {InferImplStringEqual, false}}, - {prim::kPrimStringConcat, {InferImplStringConcat, false}}, - {prim::kPrimDictLen, {InferImplDictLen, false}}, - // NN - {prim::kPrimPooling, {InferImplPooling, true}}, - {prim::kPrimPoolingGrad, {InferImplPoolingGrad, true}}, - {prim::kPrimFusedBatchNorm, {InferImplFusedBatchNorm, true}}, - {prim::kPrimFusedBatchNormGrad, {InferImplFusedBatchNormGrad, true}}, - {prim::kPrimReluGrad, {InferImplReluGrad, true}}, - {prim::kPrimConv2DBackpropInput, {InferImplConv2DBackpropInput, true}}, - {prim::kPrimConv2DBackpropFilter, {InferImplConv2DBackpropFilter, true}}, - {prim::kPrimBiasAddGrad, {InferImplBiasAddGrad, true}}, - {prim::kPrimRelu, {InferImplRelu, true}}, - {prim::kPrimFakeBprop, {InferImplFakeBprop, false}}, - {prim::kPrimZerosLike, {InferImplZerosLike, true}}, - {prim::kPrimBpropCut, {InferImplBpropCut, true}}, - {prim::kPrimLayerNorm, {InferImplLayerNorm, true}}, - {prim::kPrimLayerNormGrad, {InferImplLayerNormGrad, true}}, - {prim::kPrimDropoutGenMask, {InferImplDropoutGenMask, true}}, - // Others - {prim::kPrimIdentity, {InferImplIdentity, true}}, - // Set impl to null as it will use PartialEvaluator; - {prim::kPrimPartial, {nullptr, true}}, - {prim::kPrimJ, {InferImplJ, false}}, - {prim::kPrimEnvGetItem, {InferImplEnvGetItem, true}}, - {prim::kPrimEnvSetItem, {InferImplEnvSetItem, true}}, - {prim::kPrimEnvAdd, {InferImplEnvAdd, true}}, - {prim::kPrimMakeRefKey, {InferImplMakeRefKey, true}}, - {prim::kPrimMakeRef, {InferImplMakeRef, true}}, - {prim::kPrimGetRefKey, {InferImplGetRefKey, true}}, - {prim::kPrimGetRefValue, {InferImplGetRefValue, true}}, - {prim::kPrimGetRefOrigin, {InferImplGetRefOrigin, true}}, - {prim::kPrimStateSetItem, {InferImplStateSetItem, true}}, - {prim::kPrimDepend, {InferImplDepend, true}}, - {prim::kPrimBroadcastGradientArgs, {InferImplBroadcastGradientArgs, false}}, - {prim::kPrimControlDepend, {InferImplControlDepend, true}}, - // Debug - {prim::kPrimDebug, {InferImplDebug, true}}, - // RowTensor - {prim::kPrimMakeRowTensor, {InferImplMakeRowTensor, true}}, - {prim::kPrimRowTensorGetValues, {InferImplRowTensorGetValues, true}}, - {prim::kPrimRowTensorGetIndices, {InferImplRowTensorGetIndices, true}}, - {prim::kPrimRowTensorGetDenseShape, {InferImplRowTensorGetDenseShape, true}}, - // SparseTensor - {prim::kPrimMakeSparseTensor, {InferImplMakeSparseTensor, true}}, - {prim::kPrimSparseTensorGetValues, {InferImplSparseTensorGetValues, true}}, - {prim::kPrimSparseTensorGetIndices, {InferImplSparseTensorGetIndices, true}}, - {prim::kPrimSparseTensorGetDenseShape, {InferImplSparseTensorGetDenseShape, true}}, - }; - return prim_eval_implement_map; -} - using mindspore::parse::PyObjectWrapper; std::unordered_set prims_to_skip_undetermined_infer{"make_tuple", "make_list", "switch", "env_setitem", @@ -227,11 +123,11 @@ static AbstractBasePtrList GetUnpackGraphSpecArgsList(AbstractBasePtrList args_s for (size_t index = 0; index < specialize_args_before_unpack.size(); index++) { MS_EXCEPTION_IF_NULL(specialize_args_before_unpack[index]); if (specialize_args_before_unpack[index]->isa()) { - AbstractTuplePtr arg_tuple = specialize_args_before_unpack[index]->cast(); + auto arg_tuple = specialize_args_before_unpack[index]->cast(); std::transform(arg_tuple->elements().begin(), arg_tuple->elements().end(), std::back_inserter(graph_specialize_args), [](AbstractBasePtr abs) { return abs; }); } else if (specialize_args_before_unpack[index]->isa()) { - AbstractDictionaryPtr arg_dict = specialize_args_before_unpack[index]->cast(); + auto arg_dict = specialize_args_before_unpack[index]->cast(); auto dict_elems = arg_dict->elements(); (void)std::transform( dict_elems.begin(), dict_elems.end(), std::back_inserter(graph_specialize_args), @@ -354,7 +250,7 @@ EvalResultPtr MixedPrecisionCastEvaluator::Run(AnalysisEnginePtr engine, const C } auto out_node = out_conf->node()->cast(); const auto &out_node_inputs = out_node->inputs(); - if (out_node->inputs().size() == 0 || (out_node_inputs.size() - 1) != args_conf_list.size()) { + if (out_node->inputs().empty() || (out_node_inputs.size() - 1) != args_conf_list.size()) { MS_LOG(EXCEPTION) << "MixedPrecisionCast" << " args size should equal to inputs size minus 1, but args size " << args_conf_list.size() << ", inputs size " << out_node_inputs.size(); diff --git a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h index 48bb0e990c..8d5aff9305 100644 --- a/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h +++ b/mindspore/ccsrc/pipeline/jit/static_analysis/prim.h @@ -26,19 +26,10 @@ #include #include "pipeline/jit/static_analysis/evaluator.h" +#include "abstract/primitive_infer_map.h" namespace mindspore { namespace abstract { -using StandardPrimitiveEvalImpl = AbstractBasePtr (*)(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &); -struct StandartPrimitiveImplReg { - StandardPrimitiveEvalImpl impl_; // Implement function of Primitive. - bool in_white_list_; // true if this Primitive in white list, else false. -}; - -using PrimitiveEvalImplMap = - std::unordered_map; - class StandardPrimEvaluator : public TrivialPrimEvaluator { public: StandardPrimEvaluator(const PrimitivePtr primitive, StandardPrimitiveEvalImpl eval_impl) @@ -179,191 +170,6 @@ bool IsSubtype(const AbstractBasePtr x, const TypePtr model); void ClearPrimEvaluatorMap(); py::dict ConvertAbstractToPython(const AbstractBasePtr &abs_base); - -AbstractBasePtr InferImplReturn(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTypeof(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplHasType(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplDot(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplSwitch(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplSwitchLayer(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplIs_(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplIsNot(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplInDict(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplNotInDict(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplIsConstant(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplPooling(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplPoolingGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplFusedBatchNorm(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplFusedBatchNormGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplReluGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplConv2DBackpropInput(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplConv2DBackpropFilter(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplBiasAddGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplRelu(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplFakeBprop(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplZerosLike(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplBpropCut(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplLayerNorm(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplLayerNormGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplDropoutGenMask(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); - -AbstractBasePtr InferImplMinOrMaxGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); - -AbstractBasePtr InferImplScalarToArray(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplArrayToScalar(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplBroadCastShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplPack(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplUnique(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplUniqueGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); - -AbstractBasePtr InferImplMakeTuple(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeList(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeDict(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplExtractKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTupleGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplListGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTupleSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplListSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplDictGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplDictSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplListAppend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTupleLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplListLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplArrayLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplListMap(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplListReduce(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTupleReversed(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplReduceShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTupleDiv(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTuple2Array(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplShapeMul(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplGenShapeIndex(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplGenInverseIndex(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplTupleEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplListEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeRange(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplStopGradient(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplStringEqual(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplStringConcat(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplDictLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); - -AbstractBasePtr InferImplIdentity(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplJ(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplEnvGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplEnvSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplEnvAdd(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeRefKey(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeRef(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplGetRefKey(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplGetRefValue(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplGetRefOrigin(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplStateSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplDepend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplBroadcastGradientArgs(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplControlDepend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); - -AbstractBasePtr InferImplDebug(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); - -AbstractBasePtr InferImplMakeRowTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplRowTensorGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplRowTensorGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplRowTensorGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplMakeSparseTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplSparseTensorGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplSparseTensorGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); -AbstractBasePtr InferImplSparseTensorGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list); } // namespace abstract } // namespace mindspore diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc index 703f3dff7e..579af6e94a 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.cc @@ -115,12 +115,12 @@ inline ValuePtr PyAttrValue(const py::object &obj) { static std::string GetId(const py::object &obj) { py::object to_process = obj; std::string prefix = ""; - if (py::isinstance(to_process)) { + if (py::isinstance(to_process) || py::isinstance(to_process)) { auto p_list = py::cast(to_process); - if (p_list.size() == 0) { + if (p_list.empty()) { return "empty"; } - prefix = "tuple:"; + prefix = py::isinstance(to_process) ? "tuple:" : "list"; std::string key = ""; for (size_t i = 0; i < p_list.size(); ++i) { key += std::string(py::str(GetId(p_list[i]))) + ":"; @@ -393,9 +393,7 @@ bool RunOpConvertConstInputToAttr(const py::object &input_object, size_t input_i ValuePtr value = parse::data_converter::PyDataToValue(input_object); MS_EXCEPTION_IF_NULL(value); auto input_name = input_names_vec[input_index]; - op_prim->BeginRecordAddAttr(); op_prim->AddAttr(input_name, value); - op_prim->EndRecordAddAttr(); return true; } return false; @@ -499,6 +497,8 @@ void ConstructInputTensor(const OpExecInfoPtr &op_run_info, std::vector *te opt::ConstInputToAttrInfoRegister reg; bool reg_exist = opt::ConstInputToAttrInfoRegistry::Instance().GetRegisterByOpName(op_run_info->op_name, ®); + + op_prim->BeginRecordAddAttr(); size_t input_num = op_run_info->op_inputs.size(); for (size_t index = 0; index < input_num; ++index) { // convert const input to attr @@ -513,6 +513,7 @@ void ConstructInputTensor(const OpExecInfoPtr &op_run_info, std::vector *te std::vector new_mask(input_tensors->size() - tensors_mask->size(), tensor_mask); tensors_mask->insert(tensors_mask->end(), new_mask.begin(), new_mask.end()); } + op_prim->EndRecordAddAttr(); } void EraseValueNodeTensor(const std::vector &tensors_mask, std::vector *input_tensors) { @@ -737,6 +738,21 @@ AnfNodePtr PynativeExecutor::GetObjNode(const py::object &obj) { return node; } +std::string PynativeExecutor::GetCellId(const py::object &cell, const py::args &args) { + auto cell_id = GetId(cell); + for (size_t i = 0; i < args.size(); i++) { + std::string arg_id = GetId(args[i]); + if (node_abs_map_.find(arg_id) != node_abs_map_.end()) { + cell_id += node_abs_map_[arg_id]->ToString(); + } else { + AbstractBasePtr abs = abstract::FromValueInside(PyAttrValue(args[i]), true); + cell_id += abs->ToString(); + node_abs_map_[arg_id] = abs; + } + } + return cell_id; +} + py::tuple PynativeExecutor::RunOpInner(const OpExecInfoPtr &op_exec_info) { MS_LOG(INFO) << "RunOp start, op name is: " << op_exec_info->op_name; mindspore::parse::python_adapter::set_python_env_flag(true); @@ -784,8 +800,8 @@ py::tuple PynativeExecutor::RunOpInner(const py::args &args) { } auto cnode = PynativeExecutor::GetInstance()->MakeCNode(op_exec_info, &op_masks, &args_spec_list); bool is_find = false; - if (prim_abs_list.find(prim->id()) != prim_abs_list.end()) { - auto abs_list = prim_abs_list[prim->id()]; + if (prim_abs_list_.find(prim->id()) != prim_abs_list_.end()) { + auto abs_list = prim_abs_list_[prim->id()]; MS_LOG(DEBUG) << "match prim input args " << op_exec_info->op_name << mindspore::ToString(args_spec_list); if (abs_list.find(args_spec_list) != abs_list.end()) { MS_LOG(DEBUG) << "match prim ok" << op_exec_info->op_name; @@ -826,7 +842,7 @@ py::tuple PynativeExecutor::RunOpInner(const py::args &args) { if (!is_find) { // const_value need infer every step - auto &out = prim_abs_list[prim->id()]; + auto &out = prim_abs_list_[prim->id()]; out[args_spec_list].abs = op_exec_info->abstract; out[args_spec_list].attrs = prim->evaluate_added_attrs(); MS_LOG(DEBUG) << "set prim " << op_exec_info->op_name << mindspore::ToString(args_spec_list); @@ -889,7 +905,7 @@ PynativeExecutor::~PynativeExecutor() { ClearRes(); } PynativeExecutor::PynativeExecutor() { grad_flag_ = false; } void PynativeExecutor::NewGraphInner(const py::object &cell, const py::args &args) { - auto cell_id = GetId(cell); + auto cell_id = GetCellId(cell, args); if (cell_graph_map_.count(cell_id) != 0) { if (cell_resource_map_.find(cell_id) != cell_resource_map_.end()) { resource_ = cell_resource_map_[cell_id]; @@ -1015,7 +1031,7 @@ void PynativeExecutor::Popp() { } void PynativeExecutor::EndGraphInner(const py::object &cell, const py::object &out, const py::args &args) { - auto cell_id = GetId(cell); + auto cell_id = GetCellId(cell, args); if (cell_graph_map_.count(cell_id) != 0) { MS_LOG(DEBUG) << "Endgraph already compiled"; return; @@ -1077,7 +1093,7 @@ void PynativeExecutor::EndGraphByOutId(const std::string &out_id, const py::obje inputs.push_back(input); } auto out_cnode = curr_g_->NewCNode(inputs); - set_pyobj(curr_g_, GetId(cell)); + set_pyobj(curr_g_, GetCellId(cell, args)); if (py::isinstance(out)) { auto out_list = py::cast(out); auto out_size = static_cast(out_list.size()); @@ -1117,11 +1133,12 @@ std::vector PynativeExecutor::GetWeightsArgs(const py::object &weigh free_param->debug_info()->set_name(param_name); para_node = free_param; } - AnfNodePtr value = parse::GetMixedPrecisionCastHelp(df_builder_, para_node); + ValuePtr target_type = parse::GetMixedPrecisionTargetType(df_builder_, para_node); AnfNodePtr make_ref = NewValueNode(prim::kPrimMakeRef); auto refkey = std::make_shared(para_node->cast()->name()); AnfNodePtr ref_key_node = NewValueNode(refkey); - AnfNodePtr ref_node = df_builder_->NewCNode({make_ref, ref_key_node, value, para_node}); + AnfNodePtr target_type_node = NewValueNode(target_type); + AnfNodePtr ref_node = df_builder_->NewCNode({make_ref, ref_key_node, para_node, target_type_node}); w_args.push_back(ref_node); } } else { @@ -1167,7 +1184,7 @@ void PynativeExecutor::GradNetInner(const GradOperationPtr &grad, const py::obje MS_LOG(INFO) << "GradNet start" << args.size(); std::size_t size = args.size(); - auto cell_id = GetId(cell); + std::string cell_id = GetCellId(cell, args); if (graph_map_.count(cell_id) != 0) { MS_LOG(DEBUG) << "GradNet already compiled"; return; diff --git a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h index 246ceada15..11d651c775 100644 --- a/mindspore/ccsrc/pipeline/pynative/pynative_execute.h +++ b/mindspore/ccsrc/pipeline/pynative/pynative_execute.h @@ -92,6 +92,7 @@ class PynativeExecutor : public std::enable_shared_from_this { void set_grad_flag(bool flag) { grad_flag_ = flag; } AnfNodePtr GetInput(const py::object &obj, bool op_mask); AnfNodePtr GetObjNode(const py::object &obj); + std::string GetCellId(const py::object &obj, const py::args &args); FuncGraphPtr curr_g() { return curr_g_; } void set_pyobj(FuncGraphPtr g, const std::string obj) { graph_info_map_[g].objects.push_back(obj); } void set_obj_node_map(FuncGraphPtr g, const std::string obj, AnfNodePtr node) { @@ -141,7 +142,7 @@ class PynativeExecutor : public std::enable_shared_from_this { FuncGraphPtr top_g_; FuncGraphPtr df_builder_; FuncGraphPtr curr_g_; - std::unordered_map prim_abs_list; + std::unordered_map prim_abs_list_; }; using PynativeExecutorPtr = std::shared_ptr; diff --git a/mindspore/ccsrc/runtime/device/CMakeLists.txt b/mindspore/ccsrc/runtime/device/CMakeLists.txt index fac738ca69..490e783e73 100644 --- a/mindspore/ccsrc/runtime/device/CMakeLists.txt +++ b/mindspore/ccsrc/runtime/device/CMakeLists.txt @@ -14,12 +14,12 @@ endif () if (ENABLE_CPU) file(GLOB_RECURSE CPU_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "cpu/*.cc") - list(REMOVE_ITEM CPU_SRC_LIST "cpu/mpi/mpi_adapter.cc") + list(REMOVE_ITEM CPU_SRC_LIST "cpu/mpi/mpi_adapter.cc", "cpu/mpi/mpi_export.cc") endif () if (ENABLE_MPI) if (ENABLE_CPU) - file(GLOB_RECURSE MPI_SRC_LIST "cpu/mpi/mpi_adapter.cc") + file(GLOB_RECURSE MPI_SRC_LIST "cpu/mpi/mpi_adapter.cc", "cpu/mpi/mpi_export.cc") set_property(SOURCE ${MPI_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_DEVICE) add_library(mpi_adapter SHARED ${MPI_SRC_LIST}) diff --git a/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc b/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc index 0408dac280..3f86010de8 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc +++ b/mindspore/ccsrc/runtime/device/ascend/ascend_kernel_runtime.cc @@ -22,7 +22,7 @@ #include #include #include "runtime/device/ascend/ascend_device_address.h" -#include "runtime/device/cpu/mpi/mpi_adapter.h" +#include "runtime/device/cpu/mpi/mpi_interface.h" #include "utils/ms_context.h" #include "utils/context/context_extends.h" #include "utils/mpi/mpi_config.h" @@ -64,9 +64,7 @@ std::string GetRankId() { auto mpi_config_ptr = MpiConfig::GetInstance(); MS_EXCEPTION_IF_NULL(mpi_config_ptr); if (mpi_config_ptr->enable_mpi()) { - auto mpi_instance = device::cpu::MPIAdapter::Instance(); - MS_EXCEPTION_IF_NULL(mpi_instance); - int rank_id = mpi_instance->GetRankId(); + int rank_id = GetMPIRankId(); const char *offset = std::getenv("RANK_OFFSET"); if (offset != nullptr) { try { diff --git a/mindspore/ccsrc/runtime/device/ascend/ascend_memory_manager.cc b/mindspore/ccsrc/runtime/device/ascend/ascend_memory_manager.cc index 0970fe01ed..7f3174242f 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ascend_memory_manager.cc +++ b/mindspore/ccsrc/runtime/device/ascend/ascend_memory_manager.cc @@ -24,7 +24,6 @@ namespace ascend { constexpr uint64_t kAscendDeviceMemGB = 30; constexpr uint64_t kMemSizeGB = 30; constexpr uint64_t kAscendDeviceMemSize = (kAscendDeviceMemGB << kMemSizeGB); -constexpr uint64_t kReservedMemorySize = 10 * 1024 * 1024; void AscendMemoryManager::MallocDeviceMemory() { auto context_mem = GetDeviceMemSizeFromContext(); @@ -35,8 +34,9 @@ void AscendMemoryManager::MallocDeviceMemory() { MS_EXCEPTION(DeviceProcessError) << "rtMalloc mem size[" << device_mem_size_ << "] fail, ret[" << ret << "]"; } - dynamic_mem_offset_ = device_mem_size_ - kReservedMemorySize; + AscendMemoryPool::GetInstance().set_device_mem_size(device_mem_size_); AscendMemoryPool::GetInstance().set_device_mem_pool_base(device_mem_base_); + AscendMemoryPool::GetInstance().set_device_mem_pool_offset(device_mem_size_); AscendMemoryPool::GetInstance().set_graph_dynamic_mem_offset(dynamic_mem_offset_); } @@ -69,18 +69,11 @@ void AscendMemoryManager::FreeDeviceMemory() { } device_mem_base_ = nullptr; } - if (device_mem_pool_base_ != nullptr) { - auto ret = rtFree(device_mem_pool_base_); - if (ret != RT_ERROR_NONE) { - MS_LOG(ERROR) << "rtFree mem size[" << device_mem_pool_size_ << "] fail, ret[" << ret << "]"; - } - device_mem_pool_base_ = nullptr; - } } void AscendMemoryManager::ResetDynamicMemory() { total_dynamic_size_ = 0; - dynamic_mem_offset_ = device_mem_size_ - kReservedMemorySize; + dynamic_mem_offset_ = 0; AscendMemoryPool::GetInstance().set_graph_dynamic_mem_offset(dynamic_mem_offset_); } @@ -99,7 +92,7 @@ uint8_t *AscendMemoryManager::MallocStaticMem(size_t size, bool communication_me auto device_mem_pool_offset = AscendMemoryPool::GetInstance().device_mem_pool_offset(); MS_LOG(INFO) << "Malloc Memory: Static, total[" << device_mem_size_ << "] (dynamic[" << total_dynamic_size_ - << "] memory pool[" << device_mem_pool_offset << "])" + << "] memory pool[" << device_mem_size_ - device_mem_pool_offset << "])" << " malloc [" << align_size << "] communication_mem: " << communication_mem; if (communication_mem) { @@ -123,15 +116,11 @@ uint8_t *AscendMemoryManager::MallocDynamicMem(size_t size, bool communication_m MS_LOG(INFO) << "Malloc Memory: Dynamic, total[" << device_mem_size_ << "] (dynamic[" << total_dynamic_size_ << "] memory pool[" << device_mem_pool_offset << "])" << " malloc [" << align_size << "] communication_mem: " << communication_mem; - - if (dynamic_mem_offset_ < align_size) { + auto offset = dynamic_mem_offset_; + auto new_offset = dynamic_mem_offset_ + align_size; + if (new_offset >= device_mem_pool_offset) { MS_LOG(EXCEPTION) << "Out of memory!!! total[" << device_mem_size_ << "] (dynamic[" << total_dynamic_size_ - << "]) malloc [" << align_size << "] failed!"; - } - auto new_offset = dynamic_mem_offset_ - align_size; - if (new_offset <= device_mem_pool_offset) { - MS_LOG(EXCEPTION) << "Out of memory!!! total[" << device_mem_size_ << "] (dynamic[" << total_dynamic_size_ - << "] memory pool[" << device_mem_pool_offset << "])" + << "] memory pool[" << device_mem_size_ - device_mem_pool_offset << "])" << " malloc [" << align_size << "] failed!"; } total_dynamic_size_ += align_size; @@ -139,9 +128,9 @@ uint8_t *AscendMemoryManager::MallocDynamicMem(size_t size, bool communication_m AscendMemoryPool::GetInstance().set_graph_dynamic_mem_offset(dynamic_mem_offset_); if (communication_mem) { // create protect area [kMemAlignSize -- data -- kMemAlignSize] - return device_mem_base_ + dynamic_mem_offset_ + kMemAlignSize; + return device_mem_base_ + offset + kMemAlignSize; } else { - return device_mem_base_ + dynamic_mem_offset_; + return device_mem_base_ + offset; } } } // namespace ascend diff --git a/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.cc b/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.cc index 4715a72a20..6d711dacd9 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.cc +++ b/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.cc @@ -25,13 +25,13 @@ size_t AscendMemoryPool::AllocDeviceMem(size_t size, DeviceMemPtr *addr) { if (size == 0) { MS_LOG(EXCEPTION) << "Failed to alloc memory pool resource, the size is zero!"; } - if (device_mem_pool_offset_ + size >= graph_dynamic_mem_offset_) { + if (device_mem_pool_offset_ - size <= graph_dynamic_mem_offset_) { MS_LOG(EXCEPTION) << "Failed to alloc memory pool memory, the current device_mem_pool_offset_ [" << device_mem_pool_offset_ << "], current graph_dynamic_mem_offset_ " << graph_dynamic_mem_offset_ << "], need memory size [" << size << "]"; } + device_mem_pool_offset_ -= size; *addr = device_mem_pool_base_ + device_mem_pool_offset_; - device_mem_pool_offset_ += size; if (*addr == nullptr) { MS_LOG(EXCEPTION) << "Alloc device memory pool address is nullptr, failed to alloc memory pool resource!"; } @@ -57,6 +57,12 @@ void AscendMemoryPool::set_device_mem_pool_base(uint8_t *device_mem_pool_base) { device_mem_pool_base_ = device_mem_pool_base; } +void AscendMemoryPool::set_device_mem_size(uint64_t device_mem_size) { device_mem_size_ = device_mem_size; } + +void AscendMemoryPool::set_device_mem_pool_offset(uint64_t device_mem_pool_offset) { + device_mem_pool_offset_ = device_mem_pool_offset; +} + void AscendMemoryPool::set_graph_dynamic_mem_offset(uint64_t graph_dynamic_mem_offset) { graph_dynamic_mem_offset_ = graph_dynamic_mem_offset; } @@ -64,14 +70,14 @@ void AscendMemoryPool::set_graph_dynamic_mem_offset(uint64_t graph_dynamic_mem_o uint64_t AscendMemoryPool::device_mem_pool_offset() const { return device_mem_pool_offset_; } size_t AscendMemoryPool::free_mem_size() { - if (graph_dynamic_mem_offset_ <= device_mem_pool_offset_) { + if (graph_dynamic_mem_offset_ >= device_mem_pool_offset_) { MS_LOG(EXCEPTION) << "graph dynamic mem offset [" << graph_dynamic_mem_offset_ << "] less than or equal to device mem pool offset [" << device_mem_pool_offset_ << "]!"; } - return graph_dynamic_mem_offset_ - device_mem_pool_offset_; + return device_mem_pool_offset_ - graph_dynamic_mem_offset_; } -size_t AscendMemoryPool::total_mem_size() { return graph_dynamic_mem_offset_ == 0 ? 0 : graph_dynamic_mem_offset_ - 1; } +size_t AscendMemoryPool::total_mem_size() { return device_mem_size_ - graph_dynamic_mem_offset_; } } // namespace ascend } // namespace device } // namespace mindspore diff --git a/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.h b/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.h index 439468fd6f..46b7fd4392 100644 --- a/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.h +++ b/mindspore/ccsrc/runtime/device/ascend/ascend_memory_pool.h @@ -31,7 +31,9 @@ class AscendMemoryPool : public DynamicMemPoolBestFit { size_t AllocDeviceMem(size_t size, DeviceMemPtr *addr) override; bool FreeDeviceMem(const DeviceMemPtr &addr) override; + void set_device_mem_size(uint64_t device_mem_size); void set_device_mem_pool_base(uint8_t *device_mem_pool_base); + void set_device_mem_pool_offset(uint64_t device_mem_pool_offset); void set_graph_dynamic_mem_offset(uint64_t graph_dynamic_mem_offset); uint64_t device_mem_pool_offset() const; @@ -52,6 +54,7 @@ class AscendMemoryPool : public DynamicMemPoolBestFit { private: AscendMemoryPool() = default; uint8_t *device_mem_pool_base_{nullptr}; + uint64_t device_mem_size_{0}; uint64_t device_mem_pool_offset_{0}; uint64_t graph_dynamic_mem_offset_{0}; }; diff --git a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.cc b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.cc index c124523d59..05ca85260a 100644 --- a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.cc +++ b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.cc @@ -14,11 +14,11 @@ * limitations under the License. */ #include "runtime/device/cpu/mpi/mpi_adapter.h" -#ifdef ENABLE_MPI #include #include +#include +#include #include "pybind11/pybind11.h" -#endif // ENABLE_MPI #include "utils/log_adapter.h" namespace mindspore { @@ -33,8 +33,6 @@ std::shared_ptr MPIAdapter::Instance() { return instance_; } -#ifdef ENABLE_MPI - #define RAISE_EXCEPTION(message) \ { \ std::ostringstream oss; \ @@ -271,7 +269,6 @@ bool MPIAdapter::AllGather(const float *input, float *output, const std::vector< } return true; } -#endif // ENABLE_MPI } // namespace cpu } // namespace device } // namespace mindspore diff --git a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.h b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.h index f0a7daf225..4a5a656343 100644 --- a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.h +++ b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_adapter.h @@ -16,13 +16,11 @@ #ifndef MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_ADAPTER_H_ #define MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_ADAPTER_H_ -#ifdef ENABLE_MPI #include #include #include #include #include -#endif // ENABLE_MPI #include namespace mindspore { @@ -31,27 +29,19 @@ namespace cpu { #ifndef FUNC_EXPORT #define FUNC_EXPORT __attribute__((visibility("default"))) #endif - -constexpr auto kOpTypeSum = "sum"; class MPIAdapter { public: FUNC_EXPORT static std::shared_ptr Instance(); FUNC_EXPORT int GetRankId() const { return rank_id_; } FUNC_EXPORT int GetRankSize() const { return rank_size_; } -#ifdef ENABLE_MPI FUNC_EXPORT ~MPIAdapter(); FUNC_EXPORT bool ReduceScatter(const float *input, float *output, const std::vector &ranks_group, - size_t data_num, const std::string &op_type = kOpTypeSum); + size_t data_num, const std::string &op_type); FUNC_EXPORT bool ReduceScatterOverwriteInput(float *input, const std::vector &ranks_group, size_t in_data_num, - size_t output_size, const std::string &op_type = kOpTypeSum, - float *output = nullptr); + size_t output_size, const std::string &op_type, float *output); FUNC_EXPORT bool AllGather(const float *input, float *output, const std::vector &ranks_group, size_t data_num); -#else - FUNC_EXPORT ~MPIAdapter() = default; -#endif // ENABLE_MPI private: -#ifdef ENABLE_MPI MPIAdapter(); void Init(); MPI_Group AddGroup(const std::vector &ranks); @@ -60,9 +50,6 @@ class MPIAdapter { // key:ranks group, value: mpi group std::map, MPI_Group> ranks_group_; std::mutex group_mutex_; -#else - MPIAdapter() = default; -#endif // ENABLE_MPI int rank_id_{-1}; int rank_size_{0}; diff --git a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_export.cc b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_export.cc new file mode 100644 index 0000000000..50eeec92b5 --- /dev/null +++ b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_export.cc @@ -0,0 +1,61 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "runtime/device/cpu/mpi/mpi_export.h" +#include +#include +#include "runtime/device/cpu/mpi/mpi_adapter.h" + +int GetMPIRankId() { + auto inst = mindspore::device::cpu::MPIAdapter::Instance(); + if (inst == nullptr) { + return 0; + } + return inst->GetRankId(); +} + +int GetMPIRankSize() { + auto inst = mindspore::device::cpu::MPIAdapter::Instance(); + if (inst == nullptr) { + return 0; + } + return inst->GetRankSize(); +} + +bool MPIReduceScatter(const float *input, float *output, const std::vector &ranks_group, size_t data_num, + const std::string &op_type) { + auto inst = mindspore::device::cpu::MPIAdapter::Instance(); + if (inst == nullptr) { + return false; + } + return inst->ReduceScatter(input, output, ranks_group, data_num, op_type); +} + +bool MPIReduceScatterOverwriteInput(float *input, const std::vector &ranks_group, size_t in_data_num, + size_t output_size, const std::string &op_type, float *output) { + auto inst = mindspore::device::cpu::MPIAdapter::Instance(); + if (inst == nullptr) { + return false; + } + return inst->ReduceScatterOverwriteInput(input, ranks_group, in_data_num, output_size, op_type, output); +} + +bool MPIAllGather(const float *input, float *output, const std::vector &ranks_group, size_t data_num) { + auto inst = mindspore::device::cpu::MPIAdapter::Instance(); + if (inst == nullptr) { + return false; + } + return inst->AllGather(input, output, ranks_group, data_num); +} diff --git a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_export.h b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_export.h new file mode 100644 index 0000000000..ca7ea098d4 --- /dev/null +++ b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_export.h @@ -0,0 +1,35 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_EXPORT_H_ +#define MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_EXPORT_H_ +#include +#include +#ifndef FUNC_EXPORT +#define FUNC_EXPORT __attribute__((visibility("default"))) +#endif + +extern "C" FUNC_EXPORT FUNC_EXPORT int GetMPIRankId(); +extern "C" FUNC_EXPORT FUNC_EXPORT int GetMPIRankSize(); +extern "C" FUNC_EXPORT bool MPIReduceScatter(const float *input, float *output, const std::vector &ranks_group, + size_t data_num, const std::string &op_type); +extern "C" FUNC_EXPORT bool MPIReduceScatterOverwriteInput(float *input, const std::vector &ranks_group, + size_t in_data_num, size_t output_size, + const std::string &op_type, float *output); +extern "C" FUNC_EXPORT bool MPIAllGather(const float *input, float *output, const std::vector &ranks_group, + size_t data_num); + +#endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_EXPORT_H_ diff --git a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_interface.cc b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_interface.cc new file mode 100644 index 0000000000..229f2c39e0 --- /dev/null +++ b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_interface.cc @@ -0,0 +1,85 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "runtime/device/cpu/mpi/mpi_interface.h" +#ifdef ENABLE_MPI +#include +#include +#include +#include "utils/log_adapter.h" + +inline void *LoadLibrary(const char *name) { + auto handle = dlopen(name, RTLD_LAZY | RTLD_LOCAL); + if (handle == nullptr) { + MS_LOG(EXCEPTION) << "Load lib " << name << " failed, make sure you have installed it!"; + } + return handle; +} + +inline void *GetMPIAdapterHandle() { + static void *handle = LoadLibrary("mpi_adapter.so"); + return handle; +} + +inline void *GetMPIAdapterFunc(const char *name) { + static void *handle = GetMPIAdapterHandle(); + if (handle == nullptr) { + MS_LOG(EXCEPTION) << "Load lib " << name << " failed, make sure you have installed it!"; + } + void *func = dlsym(handle, name); + if (func == nullptr) { + MS_LOG(EXCEPTION) << "Load func " << name << " failed, make sure you have implied it!"; + } + return func; +} + +typedef int (*GetMPIRankIdFunc)(); +typedef int (*GetMPIRankSizeFunc)(); +typedef bool (*MPIReduceScatterFunc)(const float *input, float *output, const std::vector &ranks_group, + size_t data_num, const std::string &op_type); +typedef bool (*MPIReduceScatterOverwriteInputFunc)(float *input, const std::vector &ranks_group, + size_t in_data_num, size_t output_size, const std::string &op_type, + float *output); +typedef bool (*MPIAllGatherFunc)(const float *input, float *output, const std::vector &ranks_group, + size_t data_num); + +int GetMPIRankId() { + static GetMPIRankIdFunc func = reinterpret_cast(GetMPIAdapterFunc("GetMPIRankId")); + return func(); +} + +int GetMPIRankSize() { + static GetMPIRankIdFunc func = reinterpret_cast(GetMPIAdapterFunc("GetMPIRankSize")); + return func(); +} + +bool MPIReduceScatter(const float *input, float *output, const std::vector &ranks_group, size_t data_num, + const std::string &op_type) { + static MPIReduceScatterFunc func = reinterpret_cast(GetMPIAdapterFunc("MPIReduceScatter")); + return func(input, output, ranks_group, data_num, op_type); +} + +bool MPIReduceScatterOverwriteInput(float *input, const std::vector &ranks_group, size_t in_data_num, + size_t output_size, const std::string &op_type, float *output) { + static MPIReduceScatterOverwriteInputFunc func = + reinterpret_cast(GetMPIAdapterFunc("MPIReduceScatterOverwriteInput")); + return func(input, ranks_group, in_data_num, output_size, op_type, output); +} + +bool MPIAllGather(const float *input, float *output, const std::vector &ranks_group, size_t data_num) { + static MPIAllGatherFunc func = reinterpret_cast(GetMPIAdapterFunc("MPIAllGather")); + return func(input, output, ranks_group, data_num); +} +#endif // ENABLE_MPI diff --git a/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_interface.h b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_interface.h new file mode 100644 index 0000000000..cc0ef6e08b --- /dev/null +++ b/mindspore/ccsrc/runtime/device/cpu/mpi/mpi_interface.h @@ -0,0 +1,34 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_INTERFACE_H_ +#define MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_INTERFACE_H_ +#include +#include +#ifndef FUNC_EXPORT +#define FUNC_EXPORT __attribute__((visibility("default"))) +#endif +constexpr auto kMPIOpTypeSum = "sum"; +#ifdef ENABLE_MPI +int GetMPIRankId(); +int GetMPIRankSize(); +bool MPIReduceScatter(const float *input, float *output, const std::vector &ranks_group, size_t data_num, + const std::string &op_type = kMPIOpTypeSum); +bool MPIReduceScatterOverwriteInput(float *input, const std::vector &ranks_group, size_t in_data_num, + size_t output_size, const std::string &op_type = kMPIOpTypeSum, + float *output = nullptr); +bool MPIAllGather(const float *input, float *output, const std::vector &ranks_group, size_t data_num); +#endif // ENABLE_MPI +#endif // MINDSPORE_CCSRC_RUNTIME_DEVICE_CPU_MPI_MPI_INTERFACE_H_ diff --git a/mindspore/ccsrc/runtime/device/gpu/gpu_common.h b/mindspore/ccsrc/runtime/device/gpu/gpu_common.h index ea2b321714..83f00e0fae 100644 --- a/mindspore/ccsrc/runtime/device/gpu/gpu_common.h +++ b/mindspore/ccsrc/runtime/device/gpu/gpu_common.h @@ -20,7 +20,9 @@ #include #include #include +#include #include "utils/log_adapter.h" +#include "include/curand.h" namespace mindspore { namespace device { @@ -131,6 +133,15 @@ inline bool CheckNullInput(std::vector input_shape) { return false; } #define CHECK_NULL_INPUT(input_shape) mindspore::device::gpu::CheckNullInput(input_shape) + +#define CHECK_CURAND_RET_WITH_EXCEPT(expression, message) \ + { \ + curandStatus_t status = (expression); \ + if (status != CURAND_STATUS_SUCCESS) { \ + MS_LOG(EXCEPTION) << "CUAD curand Error: " << message << " | curandStatus: " << status; \ + } \ + } + } // namespace gpu } // namespace device } // namespace mindspore diff --git a/mindspore/ccsrc/runtime/device/gpu/mpi/mpi_initializer.cc b/mindspore/ccsrc/runtime/device/gpu/mpi/mpi_initializer.cc index d34bc55302..0a3bb3da72 100644 --- a/mindspore/ccsrc/runtime/device/gpu/mpi/mpi_initializer.cc +++ b/mindspore/ccsrc/runtime/device/gpu/mpi/mpi_initializer.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace mindspore { diff --git a/mindspore/ccsrc/utils/load_onnx/anf_converter.cc b/mindspore/ccsrc/utils/load_onnx/anf_converter.cc index 9e8e51a46b..f811bfe1f1 100644 --- a/mindspore/ccsrc/utils/load_onnx/anf_converter.cc +++ b/mindspore/ccsrc/utils/load_onnx/anf_converter.cc @@ -22,6 +22,7 @@ #include #include #include +#include "utils/base_ref_extends.h" #include "utils/load_onnx/anf_model_parser.h" #include "utils/load_onnx/anf_converter.h" #include "google/protobuf/io/zero_copy_stream_impl.h" diff --git a/mindspore/ccsrc/utils/primitive_py.cc b/mindspore/ccsrc/utils/primitive_py.cc index ea15abdce9..8b1031e18f 100644 --- a/mindspore/ccsrc/utils/primitive_py.cc +++ b/mindspore/ccsrc/utils/primitive_py.cc @@ -24,6 +24,7 @@ #include "utils/convert_utils_base.h" #include "utils/primitive_utils.h" #include "utils/base_ref_py.h" +#include "utils/base_ref_extends.h" #include "pybind_api/api_register.h" #include "pybind_api/export_flags.h" @@ -77,12 +78,19 @@ py::function PrimitivePy::GetBpropFunction() { } BaseRef PrimitivePy::RunHookFunction(const VectorRef &args) const { - auto py_args = ConvertDatatoPyTuple(args); + py::tuple py_args = ConvertDatatoPyTuple(args); py::object obj; bool is_bprop = this->HasAttr(kBpropAttrName); if (is_bprop) { SyncData(py_args); - obj = hook_(*py_args); + py::tuple convert_args(py_args.size()); + for (size_t i = 0; i < py_args.size(); i++) { + convert_args[i] = py::isinstance(py_args[i]) + ? parse::python_adapter::CallPyFn(parse::PYTHON_MOD_PARSE_MODULE, + parse::PYTHON_MOD_CONVERT_TO_MS_TENSOR, py_args[i]) + : py_args[i]; + } + obj = hook_(*convert_args); return std::make_shared(obj); } SyncData(py_args[2]); diff --git a/mindspore/ccsrc/utils/primitive_utils.cc b/mindspore/ccsrc/utils/primitive_utils.cc index 956041d8fb..8b6b06bfcb 100644 --- a/mindspore/ccsrc/utils/primitive_utils.cc +++ b/mindspore/ccsrc/utils/primitive_utils.cc @@ -21,6 +21,7 @@ #include "pipeline/jit/parse/python_adapter.h" #include "utils/log_adapter.h" #include "utils/ms_utils.h" +#include "utils/base_ref_extends.h" namespace mindspore { py::function GetBpropFunctionByObj(py::object obj) { diff --git a/mindspore/ccsrc/utils/utils.h b/mindspore/ccsrc/utils/utils.h index 6be32a3df5..c1f551258b 100644 --- a/mindspore/ccsrc/utils/utils.h +++ b/mindspore/ccsrc/utils/utils.h @@ -119,6 +119,7 @@ constexpr auto kAdamApplyOneWithDecayOpName = "AdamApplyOneWithDecay"; constexpr auto kBatchNormGradOpName = "BatchNormGrad"; constexpr auto kBNInferOpName = "BNInfer"; constexpr auto kAdamApplyOneOpName = "AdamApplyOne"; +constexpr auto kAdamApplyOneAssignOpName = "AdamApplyOneAssign"; constexpr auto kResizeNearestNeighborGradOpName = "ResizeNearestNeighborGrad"; constexpr auto kFusedMulAddOpName = "FusedMulAdd"; constexpr auto kFusedMulAddNOpName = "FusedMulAddN"; diff --git a/mindspore/common/tensor.py b/mindspore/common/tensor.py index 5730c9f8c8..0a975802f6 100644 --- a/mindspore/common/tensor.py +++ b/mindspore/common/tensor.py @@ -210,12 +210,12 @@ class Tensor(Tensor_): @property def shape(self): - """The shape of tensor.""" + """The shape of tensor is a tuple.""" return self._shape @property def dtype(self): - """The dtype of tensor.""" + """The dtype of tensor is a mindspore type.""" return self._dtype @property @@ -248,6 +248,8 @@ class Tensor(Tensor_): Tensor, has the same data type as x. """ + if axis is None: + axis = () return tensor_operator_registry.get('all')(keep_dims)(self, axis) def any(self, axis=(), keep_dims=False): @@ -264,6 +266,8 @@ class Tensor(Tensor_): Tensor, has the same data type as x. """ + if axis is None: + axis = () return tensor_operator_registry.get('any')(keep_dims)(self, axis) diff --git a/mindspore/core/CMakeLists.txt b/mindspore/core/CMakeLists.txt new file mode 100644 index 0000000000..609fc7ac75 --- /dev/null +++ b/mindspore/core/CMakeLists.txt @@ -0,0 +1,23 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_BINARY_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/mindspore/core) +message("************build core***************") + +if (CMAKE_SYSTEM_NAME MATCHES "Windows") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -DHAVE_SNPRINTF") + add_compile_definitions(BUILDING_DLL) +endif() + +file(GLOB_RECURSE CORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + "abstract/*.cc" + "base/*.cc" + "c_ops/*.cc" + "ir/*.cc" + "utils/*.cc" + "gvar/*.cc" +) +set_property(SOURCE ${CORE_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_CORE) +add_library(mindspore_core STATIC ${CORE_SRC_LIST}) +if (USE_GLOG) + target_link_libraries(mindspore_core PRIVATE mindspore::glog) +endif () diff --git a/mindspore/core/abstract/CMakeLists.txt b/mindspore/core/abstract/CMakeLists.txt deleted file mode 100644 index fa331776b3..0000000000 --- a/mindspore/core/abstract/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -file(GLOB_RECURSE _ABSTRACT_ALL_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") -set_property(SOURCE ${_ABSTRACT_ALL_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_ABSTRACT) -add_library(_mindspore_abstract_obj OBJECT ${_ABSTRACT_ALL_SRC_FILES}) diff --git a/mindspore/core/abstract/abstract_value.cc b/mindspore/core/abstract/abstract_value.cc index efdf12452b..dab262bc89 100644 --- a/mindspore/core/abstract/abstract_value.cc +++ b/mindspore/core/abstract/abstract_value.cc @@ -808,14 +808,40 @@ std::string AbstractJTagged::ToString() const { return buffer.str(); } +AbstractRef::AbstractRef(const AbstractBasePtr &ref_key, const AbstractBasePtr &ref_value, bool need_cast, + TypePtr cast_target) + : ref_key_(ref_key), ref_(ref_value), need_cast_(false), target_type_(nullptr), ref_key_value_(nullptr) { + set_type(std::make_shared()); + auto origin_type = ref_value->BuildType(); + if (need_cast && cast_target && origin_type && origin_type->isa()) { + auto tensor_dtype = origin_type->cast()->element(); + if (tensor_dtype && IsSubType(tensor_dtype, kFloat)) { + if (cast_target != tensor_dtype) { + need_cast_ = true; + target_type_ = cast_target; + } + } + } + if (ref_key && ref_key->isa()) { + ref_key_value_ = ref_key->cast()->ref_key_value(); + } +} + +BaseShapePtr AbstractRef::BuildShape() const { return ref_->BuildShape(); } + TypePtr AbstractRef::BuildType() const { TypePtr subtype = ref_->BuildType(); - TypePtr subtype_origin = ref_origin_->BuildType(); + TypePtr subtype_origin = subtype; + if (need_cast_) { + subtype_origin = std::make_shared(target_type_); + } return std::make_shared(subtype, subtype_origin); } bool AbstractRef::operator==(const AbstractRef &other) const { - return (*ref_ == *other.ref_) && (*ref_key_ == *other.ref_key_) && (*ref_origin_ == *other.ref_origin_); + return (*ref_ == *other.ref_) && (need_cast_ == other.need_cast_) && + (!need_cast_ || (*target_type_ == *other.target_type_)); + // not compare the key for reuse the graph (*ref_key_ == *other.ref_key_); } bool AbstractRef::operator==(const AbstractBase &other) const { @@ -826,27 +852,45 @@ bool AbstractRef::operator==(const AbstractBase &other) const { return false; } +AbstractBasePtr AbstractRefKey::Join(const AbstractBasePtr &other) { + MS_EXCEPTION_IF_NULL(other); + if (*this == *other) { + auto ret = shared_from_base(); + return ret; + } + auto value_self = GetValueTrack(); + MS_EXCEPTION_IF_NULL(value_self); + ValuePtr res_value = ValueJoin(value_self, other->GetValueTrack()); + if (res_value == value_self) { + auto ret = shared_from_base(); + return ret; + } + auto ret = std::make_shared(); + ret->set_value(res_value); + return ret; +} + AbstractBasePtr AbstractRef::Join(const AbstractBasePtr &other) { auto other_ref = other->cast(); if (other_ref == nullptr) { auto new_ref = ref_->Join(other); - return std::make_shared(ref_key_, new_ref, ref_origin_); + return std::make_shared(ref_key_, new_ref); } - if (*this == *other) { + if ((*this == *other) && (*ref_key_ == *other_ref->ref_key_)) { return shared_from_base(); } auto ref_key = ref_key_->Join(other_ref->ref_key_); auto ref = ref_->Join(other_ref->ref()); - auto ref_origin = ref_origin_->Join(other_ref->ref_origin_); - - return std::make_shared(ref_key, ref, ref_origin); + return std::make_shared(ref_key, ref); } std::string AbstractRef::ToString() const { std::ostringstream buffer; buffer << type_name() << "(" - << "key: " << ref_key_->ToString() << " ref_value: " << ref_->ToString() - << " origin_value: " << ref_origin_->ToString(); + << "key: " << ref_key_->ToString() << " ref_value: " << ref_->ToString(); + if (need_cast_) { + buffer << " cast to: " << target_type_->ToString(); + } auto value = GetValueTrack(); if (value) { buffer << ", value: " << value->ToString(); @@ -873,6 +917,12 @@ std::string AbstractNone::ToString() const { ValuePtr AbstractNone::RealBuildValue() const { return kNone; } +AbstractBasePtr AbstractRefKey::Broaden() const { + auto refkey = std::make_shared(); + refkey->set_value(kAnyValue); + return refkey; +} + bool AbstractRefKey::operator==(const AbstractRefKey &other) const { ValuePtr value_self = GetValueTrack(); ValuePtr value_other = other.GetValueTrack(); diff --git a/mindspore/core/abstract/abstract_value.h b/mindspore/core/abstract/abstract_value.h index faf80c639b..eee0fc670c 100644 --- a/mindspore/core/abstract/abstract_value.h +++ b/mindspore/core/abstract/abstract_value.h @@ -535,50 +535,70 @@ using AbstractEllipsisPtr = std::shared_ptr; class AbstractRefKey : public AbstractBase { public: - AbstractRefKey() : AbstractBase() { set_type(std::make_shared()); } + AbstractRefKey() : AbstractBase(), ref_key_value_(nullptr) { set_type(std::make_shared()); } ~AbstractRefKey() override = default; MS_DECLARE_PARENT(AbstractRefKey, AbstractBase) TypePtr BuildType() const override { return std::make_shared(); } bool operator==(const AbstractRefKey &other) const; bool operator==(const AbstractBase &other) const override; - AbstractBasePtr Clone() const override { return std::make_shared(); } + AbstractBasePtr Clone() const override { + auto cloned = std::make_shared(); + cloned->set_value(GetValueTrack()); + return cloned; + } + inline void set_value(const ValuePtr &value) { + AbstractBase::set_value(value); + ref_key_value_ = value->cast(); + } + RefKeyPtr ref_key_value() const { return ref_key_value_; } + AbstractBasePtr Join(const AbstractBasePtr &other) override; + AbstractBasePtr Broaden() const override; std::string ToString() const override; + + private: + // cache for ref_key after build value, when value is null, return nullptr. + RefKeyPtr ref_key_value_{nullptr}; }; using AbstractRefKeyPtr = std::shared_ptr; class AbstractRef : public AbstractBase { public: - AbstractRef(const AbstractBasePtr &ref_key, const AbstractBasePtr &ref_value, const AbstractBasePtr &ref_origin) - : ref_key_(ref_key), ref_(ref_value), ref_origin_(ref_origin) { - set_type(std::make_shared()); - } + AbstractRef(const AbstractBasePtr &ref_key, const AbstractBasePtr &ref_value, bool need_cast = false, + TypePtr cast_target = nullptr); ~AbstractRef() override = default; MS_DECLARE_PARENT(AbstractRef, AbstractBase) TypePtr BuildType() const override; + BaseShapePtr BuildShape() const override; bool operator==(const AbstractRef &other) const; bool operator==(const AbstractBase &other) const override; AbstractBasePtr Clone() const override { - return std::make_shared(ref_key_->Clone(), ref_->Clone(), ref_origin_->Clone()); + return std::make_shared(ref_key_->Clone(), ref_->Clone(), need_cast_, target_type_); } std::string ToString() const override; - AbstractBasePtr ref() { return ref_; } - AbstractBasePtr ref_origin() { return ref_origin_; } - AbstractBasePtr ref_key() { return ref_key_; } + inline AbstractBasePtr ref() const { return ref_; } + inline AbstractBasePtr ref_key() const { return ref_key_; } + inline RefKeyPtr ref_key_value() const { return ref_key_value_; } + inline TypePtr target_type() const { return target_type_; } + inline bool need_cast() const { return need_cast_; } AbstractBasePtr Broaden() const override { - return std::make_shared(ref_key_->Broaden(), ref_->Broaden(), ref_origin_->Broaden()); + return std::make_shared(ref_key_->Broaden(), ref_->Broaden(), need_cast_, target_type_); } AbstractBasePtr Join(const AbstractBasePtr &other) override; std::size_t hash() const override { - return ref_key_->hash() ^ ref_->hash() ^ ref_origin_->hash() ^ (std::hash{}(this->tid()) << 1); + return ref_->hash() ^ (std::hash{}(this->tid()) << 1); // ref_key_->hash() ^ } private: AbstractBasePtr ref_key_; AbstractBasePtr ref_; - AbstractBasePtr ref_origin_; + // For mix presicion, only float type need to cast to float16 of float32 + bool need_cast_; + TypePtr target_type_; + // cache for ref_key after build value, when value is null, return nullptr. + RefKeyPtr ref_key_value_; }; using AbstractRefPtr = std::shared_ptr; diff --git a/mindspore/core/abstract/analysis_context.cc b/mindspore/core/abstract/analysis_context.cc index 228ddf0f54..2270f3c1b0 100644 --- a/mindspore/core/abstract/analysis_context.cc +++ b/mindspore/core/abstract/analysis_context.cc @@ -171,9 +171,7 @@ AnalysisContextPtr AnalysisContext::SpecializeKey() const { } if (arg->isa()) { MS_LOG(DEBUG) << "refkey broaden"; - auto arg_spec = dyn_cast(arg); - auto ret_spec = arg_spec->Broaden(); - return ret_spec; + return arg->Broaden(); } return arg; }); diff --git a/mindspore/core/abstract/infer_functions.h b/mindspore/core/abstract/infer_functions.h new file mode 100644 index 0000000000..5c0625a7e1 --- /dev/null +++ b/mindspore/core/abstract/infer_functions.h @@ -0,0 +1,187 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CORE_ABSTRACT_INFER_FUNCTIONS_H_ +#define MINDSPORE_CORE_ABSTRACT_INFER_FUNCTIONS_H_ +#include +#include +#include "abstract/abstract_value.h" +#include "abstract/param_validator.h" +#include "base/core_ops.h" +namespace mindspore { +namespace abstract { +AbstractBasePtr InferImplReturn(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplDot(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplSwitch(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplSwitchLayer(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplIs_(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplIsNot(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplInDict(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplNotInDict(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplIsConstant(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplPooling(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplPoolingGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplFusedBatchNorm(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplFusedBatchNormGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplReluGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplConv2DBackpropInput(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplConv2DBackpropFilter(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplBiasAddGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplGelu(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplGeluGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplRelu(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplZerosLike(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplBpropCut(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplLayerNorm(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplLayerNormGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplDropoutGenMask(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); + +AbstractBasePtr InferImplMinOrMaxGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); + +AbstractBasePtr InferImplScalarToArray(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplArrayToScalar(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplBroadCastShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplPack(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); + +AbstractBasePtr InferImplMakeTuple(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeList(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeDict(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplExtractKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeRecord(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplTupleGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplListGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplTupleSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplListSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplDictGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplDictSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplListAppend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplTupleLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplListLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplArrayLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplGenShapeIndex(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplGenInverseIndex(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplIdentity(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); + +AbstractBasePtr InferImplEnvGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplEnvSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplEnvAdd(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeRefKey(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeRef(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplGetRefKey(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplGetRefValue(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplGetRefOrigin(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplStateSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplDepend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplControlDepend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplDebug(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplMakeSparseTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplSparseTensorGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplSparseTensorGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplSparseTensorGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); + +AbstractBasePtr InferImplMakeRowTensor(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplRowTensorGetValues(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplRowTensorGetIndices(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplRowTensorGetDenseShape(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplUniqueGrad(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); +AbstractBasePtr InferImplUnique(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list); + +template +AbstractBasePtr InferTupleOrListOrDictLen(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { + // Inputs: a tuple or list or dict. + CheckArgsSize(op_name, args_spec_list, 1); + auto arg = CheckArg(op_name, args_spec_list, 0); + return std::make_shared(SizeToInt(arg->size())); +} +} // namespace abstract +} // namespace mindspore +#endif // MINDSPORE_CORE_ABSTRACT_INFER_FUNCTIONS_H_ diff --git a/mindspore/ccsrc/frontend/operator/prim_arrays.cc b/mindspore/core/abstract/prim_arrays.cc similarity index 89% rename from mindspore/ccsrc/frontend/operator/prim_arrays.cc rename to mindspore/core/abstract/prim_arrays.cc index ea0725ae6e..40dfbc02fe 100644 --- a/mindspore/ccsrc/frontend/operator/prim_arrays.cc +++ b/mindspore/core/abstract/prim_arrays.cc @@ -14,13 +14,48 @@ * limitations under the License. */ -#include "pipeline/jit/static_analysis/prim.h" +#include "abstract/infer_functions.h" #include "abstract/utils.h" -#include "frontend/operator/cc_implementations.h" #include "abstract/param_validator.h" namespace mindspore { namespace abstract { +namespace { +std::vector BroadcastShape(std::vector shpx, std::vector shpy) { + int dlen = SizeToInt(shpx.size()) - SizeToInt(shpy.size()); + if (dlen < 0) { + for (int i = 0; i < -dlen; ++i) { + (void)shpx.insert(shpx.begin(), 1); + } + } else if (dlen > 0) { + for (int i = 0; i < dlen; i++) { + (void)shpy.insert(shpy.begin(), 1); + } + } + if (shpx.size() != shpy.size()) { + MS_LOG(EXCEPTION) << "Failure: shpx.size() != shpy.size()."; + } + std::vector shp; + for (size_t i = 0; i < shpx.size(); i++) { + auto a = shpx[i]; + auto b = shpy[i]; + if (a == 1) { + shp.push_back(b); + } else if (b == 1) { + shp.push_back(a); + } else if (a == -1) { + shp.push_back(b); + } else if (b == -1) { + shp.push_back(a); + } else if (a == b) { + shp.push_back(a); + } else { + return std::vector(); + } + } + return shp; +} +} // namespace AbstractBasePtr InferImplScalarToArray(const AnalysisEnginePtr &, const PrimitivePtr &primitive, const AbstractBasePtrList &args_spec_list) { // Inputs: a scalar. @@ -65,7 +100,7 @@ AbstractBasePtr InferImplBroadCastShape(const AnalysisEnginePtr &, const Primiti (void)std::transform(std::begin(shp_tuple_y), std::end(shp_tuple_y), std::back_inserter(shp_y), [](const ValuePtr &e) -> int { return GetValue(e); }); - std::vector res = prim::BroadcastShape_(shp_x, shp_y); + std::vector res = BroadcastShape(shp_x, shp_y); if (res.empty()) { MS_LOG(EXCEPTION) << "BroadcastShape fail: " << args_spec_list[0]->ToString() << "," << args_spec_list[1]->ToString(); diff --git a/mindspore/ccsrc/frontend/operator/prim_debug.cc b/mindspore/core/abstract/prim_debug.cc similarity index 94% rename from mindspore/ccsrc/frontend/operator/prim_debug.cc rename to mindspore/core/abstract/prim_debug.cc index 718dadf5c1..4b8cde34d8 100644 --- a/mindspore/ccsrc/frontend/operator/prim_debug.cc +++ b/mindspore/core/abstract/prim_debug.cc @@ -15,8 +15,7 @@ */ #include "abstract/param_validator.h" -#include "pipeline/jit/static_analysis/prim.h" -#include "frontend/operator/ops.h" +#include "abstract/infer_functions.h" #include "abstract/utils.h" #include "utils/symbolic.h" diff --git a/mindspore/ccsrc/frontend/operator/prim_maths.cc b/mindspore/core/abstract/prim_maths.cc similarity index 95% rename from mindspore/ccsrc/frontend/operator/prim_maths.cc rename to mindspore/core/abstract/prim_maths.cc index 5d06fb8603..f0da9535b0 100644 --- a/mindspore/ccsrc/frontend/operator/prim_maths.cc +++ b/mindspore/core/abstract/prim_maths.cc @@ -14,8 +14,7 @@ * limitations under the License. */ -#include "pipeline/jit/static_analysis/prim.h" -#include "frontend/operator/ops.h" +#include "abstract/infer_functions.h" #include "abstract/utils.h" #include "abstract/param_validator.h" #include "utils/ms_utils.h" diff --git a/mindspore/ccsrc/frontend/operator/prim_nn.cc b/mindspore/core/abstract/prim_nn.cc similarity index 79% rename from mindspore/ccsrc/frontend/operator/prim_nn.cc rename to mindspore/core/abstract/prim_nn.cc index 67c23307e5..fbd5b3be76 100644 --- a/mindspore/ccsrc/frontend/operator/prim_nn.cc +++ b/mindspore/core/abstract/prim_nn.cc @@ -14,10 +14,12 @@ * limitations under the License. */ -#include "pipeline/jit/static_analysis/prim.h" -#include "frontend/operator/ops.h" +#include "abstract/infer_functions.h" #include "abstract/utils.h" #include "abstract/param_validator.h" +#include "utils/check_convert_utils.h" +#include "c_ops/conv2d.h" +#include "abstract/primitive_infer_map.h" namespace mindspore { namespace abstract { @@ -278,13 +280,6 @@ AbstractBasePtr InferImplZerosLike(const AnalysisEnginePtr &, const PrimitivePtr return args_spec_list[0]->Broaden(); } -AbstractBasePtr InferImplFakeBprop(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a tensor. - CheckArgsSize(primitive->name(), args_spec_list, 1); - return args_spec_list[0]->Broaden(); -} - AbstractBasePtr InferImplBpropCut(const AnalysisEnginePtr &, const PrimitivePtr &primitive, const AbstractBasePtrList &args_spec_list) { // Inputs: a tensor. @@ -433,5 +428,91 @@ AbstractBasePtr InferImplDropoutGenMask(const AnalysisEnginePtr &, const Primiti return std::make_shared(std::make_shared(kAnyValue, kUInt8), std::make_shared(std::vector{shape_y})); } + +abstract::ShapePtr Conv2dInferShape(const PrimitivePtr &primitive, const std::vector &input_args) { + MS_EXCEPTION_IF_NULL(primitive); + auto conv_prim = primitive->cast(); + MS_EXCEPTION_IF_NULL(conv_prim); + auto prim_name = conv_prim->name(); + CheckAndConvertUtils::CheckInRange("Conv2d Infer", input_args.size(), kIncludeLeft, {2, 3}, prim_name); + auto w_shape = CheckAndConvertUtils::ConvertShapePtrToShape("w_shape", input_args[0]->GetShapeTrack(), prim_name); + auto x_shape = CheckAndConvertUtils::ConvertShapePtrToShape("x_shape", input_args[1]->GetShapeTrack(), prim_name); + + CheckAndConvertUtils::CheckInteger("weight rank", w_shape.size(), kEqual, 4, prim_name); + CheckAndConvertUtils::CheckInteger("x rank", x_shape.size(), kEqual, 4, prim_name); + CheckAndConvertUtils::Check("x_shape[1] / group", x_shape[1] / conv_prim->GetGroup(), kEqual, "w_shape[1]", + w_shape[1], conv_prim->name()); + auto out_channel = conv_prim->GetOutputChannel(); + CheckAndConvertUtils::Check("out_channel", out_channel, kEqual, "w_shape[0]", w_shape[0], conv_prim->name()); + std::vector temp_w; + std::copy(w_shape.begin() + 2, w_shape.end(), std::back_inserter(temp_w)); + CheckAndConvertUtils::Check("kernel_size", conv_prim->GetKernelSize(), kEqual, "w_shape[2:4]", temp_w, + conv_prim->name()); + + auto kernel_size_h = w_shape[2]; + auto kernel_size_w = w_shape[3]; + auto stride = conv_prim->GetStride(); + auto dilation = conv_prim->GetDilation(); + auto stride_h = stride[2]; + auto stride_w = stride[3]; + auto dilation_h = dilation[2]; + auto dilation_w = dilation[3]; + int h_out = -1; + int w_out = -1; + std::vector pad_list(4, 0); + auto pad_mode = conv_prim->GetPadMode(); + if (pad_mode == "valid") { + h_out = ceil((x_shape[2] - dilation_h * (kernel_size_h - 1)) / stride_h); + w_out = ceil((x_shape[3] - dilation_w * (kernel_size_w - 1)) / stride_w); + } else if (pad_mode == "same") { + h_out = ceil(x_shape[2] / stride_h); + w_out = ceil(x_shape[3] / stride_w); + + auto pad_needed_h = std::max(0, (h_out - 1) * stride_h + dilation_h * (kernel_size_h - 1) + 1 - x_shape[2]); + pad_list.emplace_back(floor(pad_needed_h / 2)); + pad_list.emplace_back(pad_needed_h / 2); + auto pad_needed_w = std::max(0, (w_out - 1) * stride_w + dilation_w * (kernel_size_w - 1) + 1 - x_shape[3]); + auto pad_left = floor(pad_needed_w / 2); + pad_list.emplace_back(pad_left); + pad_list.emplace_back(pad_needed_h - pad_left); + } else if (pad_mode == "pad") { + std::copy(conv_prim->GetPad().begin(), conv_prim->GetPad().end(), std::back_inserter(pad_list)); + auto pad_top = conv_prim->GetPad()[0]; + auto pad_bottom = conv_prim->GetPad()[1]; + auto pad_right = conv_prim->GetPad()[2]; + auto pad_left = conv_prim->GetPad()[3]; + + h_out = 1 + (x_shape[2] + pad_top + pad_bottom - kernel_size_h - (kernel_size_h - 1) * (dilation_h - 1)) / stride_h; + w_out = 1 + (x_shape[3] + pad_left + pad_right - kernel_size_w - (kernel_size_w - 1) * (dilation_w - 1)) / stride_w; + h_out = floor(h_out); + w_out = floor(w_out); + } + conv_prim->SetPadList(pad_list); + std::vector out_shape = {x_shape[0], out_channel, h_out, w_out}; + return std::make_shared(out_shape); +} + +TypePtr Conv2dInferType(const PrimitivePtr &prim, const std::vector &input_args) { + CheckAndConvertUtils::CheckInRange("", input_args.size(), kIncludeLeft, {2, 3}, prim->name()); + for (const auto &item : input_args) { + MS_EXCEPTION_IF_NULL(item); + } + auto x_type = CheckAndConvertUtils::ConvertTypePtrToTypeId("x_dtype", input_args[0]->GetTypeTrack(), prim->name()); + const std::set valid_types = {kNumberTypeInt8, kNumberTypeInt32, kNumberTypeFloat16, kNumberTypeFloat32}; + std::map types; + types.emplace("x", input_args[0]->GetTypeTrack()); + types.emplace("w", input_args[1]->GetTypeTrack()); + CheckAndConvertUtils::CheckTensorTypeSame(types, valid_types, prim->name()); + if (x_type == kNumberTypeInt8) { + return std::make_shared(TypeIdToType(kNumberTypeInt32)); + } + return std::make_shared(TypeIdToType(x_type)); +} +AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args) { + return std::make_shared(Conv2dInferType(primitive, input_args), + Conv2dInferShape(primitive, input_args)->shape()); +} +REGISTER_PRIMITIVE_EVAL_IMPL(Conv2D, prim::kPrimConv2D, Conv2dInfer); } // namespace abstract } // namespace mindspore diff --git a/mindspore/ccsrc/frontend/operator/prim_others.cc b/mindspore/core/abstract/prim_others.cc similarity index 73% rename from mindspore/ccsrc/frontend/operator/prim_others.cc rename to mindspore/core/abstract/prim_others.cc index 4b2a5be482..358ed75849 100644 --- a/mindspore/ccsrc/frontend/operator/prim_others.cc +++ b/mindspore/core/abstract/prim_others.cc @@ -19,9 +19,9 @@ #include "ir/dtype.h" #include "utils/ms_utils.h" -#include "frontend/operator/ops.h" +#include "base/core_ops.h" #include "abstract/param_validator.h" -#include "pipeline/jit/static_analysis/prim.h" +#include "abstract/infer_functions.h" #include "abstract/utils.h" #include "utils/ms_context.h" #include "utils/symbolic.h" @@ -35,27 +35,6 @@ AbstractBasePtr InferImplIdentity(const AnalysisEnginePtr &, const PrimitivePtr return args_spec_list[0]; } -AbstractBasePtr InferImplJ(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // args: An object of AbstractFunction. - CheckArgsSize(primitive->name(), args_spec_list, 1); - MS_LOG(DEBUG) << "evaluate J: " << args_spec_list[0]->ToString(); - - AbstractFunctionPtr x = dyn_cast(args_spec_list[0]); - if (x == nullptr) { - return std::make_shared(args_spec_list[0]); - } - - AbstractFuncAtomPtrList jv; - auto build_jv = [&jv](const AbstractFuncAtomPtr &func) { - auto j_closure = std::make_shared(func); - jv.push_back(j_closure); - }; - x->Visit(build_jv); - - return AbstractFunction::MakeAbstractFunction(jv); -} - AbstractBasePtr InferImplEnvGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, const AbstractBasePtrList &args_spec_list) { MS_EXCEPTION_IF_NULL(primitive); @@ -129,16 +108,22 @@ AbstractBasePtr InferImplMakeRefKey(const AnalysisEnginePtr &, const PrimitivePt AbstractBasePtr InferImplMakeRef(const AnalysisEnginePtr &, const PrimitivePtr &, const AbstractBasePtrList &args_spec_list) { - // arguments: key, value, original value + // arguments: key, value, target type(None if no target type) if (args_spec_list.size() != 3) { MS_LOG(EXCEPTION) << "make_ref evaluator requires 3 parameters, while the input size is " << args_spec_list.size() << "."; } TypePtr type = args_spec_list[0]->GetTypeTrack(); + ValuePtr tensor_target_v = args_spec_list[2]->BuildValue(); if (type->type_id() != kObjectTypeRefKey) { MS_LOG(EXCEPTION) << "First input of make_ref should be a RefKey but a " << type->ToString(); } - return std::make_shared(args_spec_list[0], args_spec_list[1], args_spec_list[2]); + auto need_cast = !tensor_target_v->isa(); + if (need_cast && !tensor_target_v->isa()) { + MS_LOG(EXCEPTION) << "Third input of make_ref should be a Type but a " << tensor_target_v->ToString(); + } + TypePtr cast_target = tensor_target_v->cast(); + return std::make_shared(args_spec_list[0], args_spec_list[1], need_cast, cast_target); } AbstractBasePtr InferImplGetRefKey(const AnalysisEnginePtr &, const PrimitivePtr &, @@ -163,25 +148,11 @@ AbstractBasePtr InferImplGetRefValue(const AnalysisEnginePtr &, const PrimitiveP } TypePtr type = args_spec_list[0]->GetTypeTrack(); if (type->type_id() != kObjectTypeRef) { - MS_LOG(EXCEPTION) << "First input of get_ref_value should be a Ref but a " << type->ToString(); + return args_spec_list[0]; } return args_spec_list[0]->cast()->ref(); } -AbstractBasePtr InferImplGetRefOrigin(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list) { - // arguments: value - if (args_spec_list.size() != 1) { - MS_LOG(EXCEPTION) << "get_ref_origin requires 1 parameters, while the input size is " << args_spec_list.size() - << "."; - } - TypePtr type = args_spec_list[0]->GetTypeTrack(); - if (type->type_id() != kObjectTypeRef) { - MS_LOG(EXCEPTION) << "First input of get_ref_value should be a Ref but a " << type->ToString(); - } - return args_spec_list[0]->cast()->ref_origin(); -} - AbstractBasePtr InferImplStateSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, const AbstractBasePtrList &args_spec_list) { // args: Two objects of a subclass of AbstractBase, key and value. @@ -204,125 +175,6 @@ AbstractBasePtr InferImplDepend(const AnalysisEnginePtr &, const PrimitivePtr &p return depends; } -bool CompareShape(const std::vector &x_shape, const std::vector &y_shape) { - if (x_shape.size() != y_shape.size()) { - return false; - } - - for (size_t i = 0; i < x_shape.size(); ++i) { - if (GetValue(x_shape[i]) != GetValue(y_shape[i])) { - return false; - } - } - - return true; -} - -enum State { - SAME, - X_ONE, - Y_ONE, -}; - -void ComputeReduceIndex(const std::vector &reverse_x, const std::vector &reverse_y, - std::vector *grad_x_reduce_idx, std::vector *grad_y_reduce_idy) { - const size_t n = reverse_x.size(); - for (size_t i = 0; i < n; ++i) { - State curr; - const int32_t x_i = reverse_x[i]; - const int32_t y_i = reverse_y[i]; - const int reduce_idx = SizeToInt(n - 1 - i); - if (x_i == y_i) { - curr = SAME; - } else if (x_i == 1) { - grad_x_reduce_idx->push_back(reduce_idx); - curr = X_ONE; - } else if (y_i == 1) { - grad_y_reduce_idy->push_back(reduce_idx); - curr = Y_ONE; - } else { - MS_LOG(EXCEPTION) << "not compatible shape input for BroadcastGradientArgs"; - } - if (curr == SAME && x_i == 1) { - grad_x_reduce_idx->push_back(reduce_idx); - grad_y_reduce_idy->push_back(reduce_idx); - continue; - } - } - - std::reverse(grad_x_reduce_idx->begin(), grad_x_reduce_idx->end()); - std::reverse(grad_y_reduce_idy->begin(), grad_y_reduce_idy->end()); -} - -AbstractBasePtr BroadcastGradientArgsDiff(const std::vector &x_shape, const std::vector &y_shape) { - std::vector reverse_x; - std::vector reverse_y; - - (void)std::transform(x_shape.rbegin(), x_shape.rend(), std::back_inserter(reverse_x), - [](const ValuePtr &v) { return v->cast()->value(); }); - (void)std::transform(y_shape.rbegin(), y_shape.rend(), std::back_inserter(reverse_y), - [](const ValuePtr &v) { return v->cast()->value(); }); - - if (reverse_x.size() > reverse_y.size()) { - reverse_y.resize(reverse_x.size(), 1); - } else { - reverse_x.resize(reverse_y.size(), 1); - } - - std::vector grad_x_reduce_idx; - std::vector grad_y_reduce_idy; - ComputeReduceIndex(reverse_x, reverse_y, &grad_x_reduce_idx, &grad_y_reduce_idy); - - AbstractBasePtrList abs_list_x; - AbstractBasePtrList abs_list_y; - (void)std::transform(grad_x_reduce_idx.begin(), grad_x_reduce_idx.end(), std::back_inserter(abs_list_x), - [](int v) { return abstract::FromValue(v); }); - (void)std::transform(grad_y_reduce_idy.begin(), grad_y_reduce_idy.end(), std::back_inserter(abs_list_y), - [](int v) { return abstract::FromValue(v); }); - auto x_reduce_idx = std::make_shared(abs_list_x); - auto y_reduce_idx = std::make_shared(abs_list_y); - AbstractBasePtrList elem_list; - elem_list.push_back(x_reduce_idx); - elem_list.push_back(y_reduce_idx); - - return std::make_shared(elem_list); -} - -AbstractBasePtr InferImplBroadcastGradientArgs(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // this primitive get the index that need to reduce - // input: x's shape and y's shape, inputs should be tuple - // output: tuple of x and y 's reduce index, reduce index should be a tuple - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 2); - auto arg_x = CheckArg(op_name, args_spec_list, 0); - auto arg_y = CheckArg(op_name, args_spec_list, 1); - - ValueTuplePtr arg_x_value = arg_x->BuildValue()->cast(); - MS_EXCEPTION_IF_NULL(arg_x_value); - - ValueTuplePtr arg_y_value = arg_y->BuildValue()->cast(); - MS_EXCEPTION_IF_NULL(arg_y_value); - - const std::vector x_shape = arg_x_value->value(); - const std::vector y_shape = arg_y_value->value(); - bool is_same_shape = CompareShape(x_shape, y_shape); - // if it is the same shape , do not need reduce , return empty tuple - if (is_same_shape) { - AbstractBasePtrList empty_list; - auto x_reduce_idx = std::make_shared(empty_list); - auto y_reduce_idx = std::make_shared(empty_list); - - AbstractBasePtrList elem_list; - elem_list.push_back(x_reduce_idx); - elem_list.push_back(y_reduce_idx); - - return std::make_shared(elem_list); - } - - return BroadcastGradientArgsDiff(x_shape, y_shape); -} - AbstractBasePtr InferImplControlDepend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, const AbstractBasePtrList &args_spec_list) { // args: Two objects of a subclass of AbstractBase diff --git a/mindspore/ccsrc/frontend/operator/prim_statement.cc b/mindspore/core/abstract/prim_statement.cc similarity index 85% rename from mindspore/ccsrc/frontend/operator/prim_statement.cc rename to mindspore/core/abstract/prim_statement.cc index 6a7f54007b..24a95709f9 100644 --- a/mindspore/ccsrc/frontend/operator/prim_statement.cc +++ b/mindspore/core/abstract/prim_statement.cc @@ -15,8 +15,7 @@ */ #include "abstract/param_validator.h" -#include "pipeline/jit/static_analysis/prim.h" -#include "frontend/operator/ops.h" +#include "abstract/infer_functions.h" #include "abstract/utils.h" #include "utils/symbolic.h" @@ -34,38 +33,6 @@ AbstractBasePtr InferImplReturn(const AnalysisEnginePtr &, const PrimitivePtr &, return abs_base; } -AbstractBasePtr InferImplTypeof(const AnalysisEnginePtr &, const PrimitivePtr &, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a pointer to an AbstractBase object - if (args_spec_list.size() != 1) { - MS_LOG(EXCEPTION) << "Typeof evaluator requires 1 parameter, while the input size is " << args_spec_list.size() - << "."; - } - AbstractBasePtr abs_base = args_spec_list[0]; - MS_EXCEPTION_IF_NULL(abs_base); - TypePtr type = abs_base->BuildType(); - return std::make_shared(type); -} - -AbstractBasePtr InferImplHasType(const AnalysisEnginePtr &, const PrimitivePtr &primitive, - const AbstractBasePtrList &args_spec_list) { - // Inputs: a pointer to an AbstractBase object and a pointer to a Type - const std::string op_name = primitive->name(); - CheckArgsSize(op_name, args_spec_list, 2); - AbstractTypePtr abs_type = CheckArg(op_name, args_spec_list, 1); - - auto mode_v = abs_type->GetValueTrack(); - MS_EXCEPTION_IF_NULL(mode_v); - if (!mode_v->isa()) { - MS_LOG(EXCEPTION) << "Get the type from AbstractType value failed."; - } - - TypePtr mode_t = mode_v->cast(); - MS_EXCEPTION_IF_NULL(args_spec_list[0]); - bool v = IsSubtype(args_spec_list[0], mode_t); - return std::make_shared(std::make_shared(v), kBool); -} - AbstractBasePtr InferImplDot(const AnalysisEnginePtr &, const PrimitivePtr &primitive, const AbstractBasePtrList &args_spec_list) { // Inputs: two tensors. diff --git a/mindspore/core/abstract/prim_structures.cc b/mindspore/core/abstract/prim_structures.cc new file mode 100644 index 0000000000..8cdfc5d20f --- /dev/null +++ b/mindspore/core/abstract/prim_structures.cc @@ -0,0 +1,278 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2019 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "abstract/infer_functions.h" +#include "abstract/utils.h" +#include "abstract/param_validator.h" +namespace mindspore { +namespace abstract { +AbstractBasePtr InferImplMakeTuple(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list) { + return std::make_shared(args_spec_list); +} + +AbstractBasePtr InferImplMakeList(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list) { + return std::make_shared(args_spec_list); +} + +AbstractBasePtr InferImplMakeDict(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: two tuples. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractTuplePtr keys = CheckArg(op_name, args_spec_list, 0); + AbstractTuplePtr values = CheckArg(op_name, args_spec_list, 1); + + size_t keys_size = keys->size(); + if (values->size() != keys_size) { + MS_LOG(EXCEPTION) << op_name << " evaluator keys' size is not equal with values' size"; + } + + std::vector key_value; + AbstractScalarPtr key; + AbstractBasePtrList key_list = keys->elements(); + AbstractBasePtrList value_list = values->elements(); + for (size_t index = 0; index < keys_size; index++) { + key = CheckArg(op_name + "key", key_list, index); + ValuePtr keyPtr = key->BuildValue(); + MS_EXCEPTION_IF_NULL(keyPtr); + if (!keyPtr->isa()) { + MS_LOG(EXCEPTION) << op_name << " evaluator keys should be string, but got " << keyPtr->ToString(); + } + std::string key_string = GetValue(keyPtr); + key_value.emplace_back(key_string, value_list[index]); + } + return std::make_shared(key_value); +} + +AbstractBasePtr InferImplMakeKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a string and an object of a subclass of AbstractBase. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 0); + + ValuePtr keyPtr = key->BuildValue(); + if (!keyPtr->isa()) { + MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << keyPtr->ToString(); + } + std::string key_string = GetValue(keyPtr); + return std::make_shared(key_string, args_spec_list[1]); +} + +AbstractBasePtr InferImplExtractKwarg(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a string and a keyword. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 0); + AbstractKeywordArgPtr kwarg = CheckArg(op_name, args_spec_list, 1); + + ValuePtr key_value = key->BuildValue(); + if (!key_value->isa()) { + MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << key_value->ToString(); + } + std::string key_input = GetValue(key_value); + std::string key_actual = kwarg->get_key(); + if (key_actual != key_input) { + MS_LOG(EXCEPTION) << op_name << " evaluator input key should be same as AbstractKeywordArg' key, but input is " + << key_input << ", AbstractKeywordArg' key is " << key_actual; + } + return kwarg->get_arg(); +} + +AbstractBasePtr InferImplMakeSlice(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: three scalars whose value is an int32 number. + CheckArgsSize(primitive->name(), args_spec_list, 3); + size_t args_size = args_spec_list.size(); + for (size_t index = 0; index < args_size; index++) { + MS_EXCEPTION_IF_NULL(args_spec_list[index]); + if (!args_spec_list[index]->isa() && !args_spec_list[index]->isa()) { + MS_EXCEPTION(TypeError) << "MakeSlice eval " << index << " parameter is neither AbstractScalar nor AbstractNone."; + } + if (args_spec_list[index]->isa() && + !dyn_cast(args_spec_list[index])->BuildValue()->isa()) { + MS_EXCEPTION(TypeError) << "MakeSlice eval " << index + << " parameter is an AbstractScalar, but is not an int32 number."; + } + } + // Slice: start, end, step + return std::make_shared(args_spec_list[0], args_spec_list[1], args_spec_list[2]); +} + +template +AbstractBasePtr InferTupleOrListGetItem(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { + // Inputs: a tuple or list and a scalar whose value is an int32 number. + CheckArgsSize(op_name, args_spec_list, 2); + auto queue = CheckArg(op_name, args_spec_list, 0); + AbstractScalarPtr index = CheckArg(op_name, args_spec_list, 1); + + ValuePtr index_value = index->BuildValue(); + if (!index_value->isa()) { + // when index_value is an AnyValue and args_spec_list[0] is a scalar, try to return the type of the first element + // and continue + if (dyn_cast(queue->elements()[0]) != nullptr) { + return std::make_shared(queue->elements()[0]->BuildType()); + } + MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int32 number, but got " + << index_value->ToString(); + } + int idx_v = GetValue(index_value); + std::size_t nelems = queue->elements().size(); + if (idx_v >= SizeToInt(nelems) || idx_v < -SizeToInt(nelems)) { + MS_EXCEPTION(IndexError) << op_name << " evaluator index should be in range[-" << SizeToInt(nelems) << ", " + << SizeToInt(nelems) << "), but got " << idx_v << "."; + } + + std::size_t uidx_v = 0; + if (idx_v >= 0) { + uidx_v = IntToSize(idx_v); + } else { + uidx_v = IntToSize(idx_v + SizeToInt(nelems)); + } + return queue->elements()[uidx_v]; +} + +template +AbstractBasePtr InferTupleOrListSetItem(const std::string &op_name, const AbstractBasePtrList &args_spec_list) { + // Inputs: a tuple or list, a scalar whose value is an int32 number and an object of a subclass of AbstractBase. + CheckArgsSize(op_name, args_spec_list, 3); + auto queue = CheckArg(op_name, args_spec_list, 0); + AbstractScalarPtr index = CheckArg(op_name, args_spec_list, 1); + + ValuePtr index_value = index->BuildValue(); + if (!index_value->isa()) { + MS_EXCEPTION(IndexError) << op_name << " evaluator index should be an int32 number, but got " + << index_value->ToString(); + } + int idx_v = GetValue(index_value); + if (idx_v < 0) { + MS_EXCEPTION(IndexError) << "The index of " << typeid(T).name() << " should be positive number, but got " << idx_v + << "."; + } + + size_t uidx_v = IntToSize(idx_v); + AbstractBasePtrList elements = queue->elements(); + std::size_t nelems = elements.size(); + if (uidx_v >= nelems) { + MS_EXCEPTION(IndexError) << op_name << " evaluator the index: " << uidx_v << " to set out of range: " << nelems - 1 + << "."; + } + elements[uidx_v] = args_spec_list[2]; + return std::make_shared(elements); +} + +AbstractBasePtr InferImplTupleGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferTupleOrListGetItem(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplListGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferTupleOrListGetItem(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplTupleSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferTupleOrListSetItem(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplListSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferTupleOrListSetItem(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplDictGetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a dict and a scalar whose value is a string. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractDictionaryPtr dict = CheckArg(op_name, args_spec_list, 0); + AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 1); + + ValuePtr key_value = key->BuildValue(); + if (!key_value->isa()) { + MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << key_value->ToString(); + } + auto key_str = GetValue(key_value); + std::vector dict_elems = dict->elements(); + auto it = std::find_if(dict_elems.begin(), dict_elems.end(), + [key_str](const AbstractAttribute &item) { return item.first == key_str; }); + + if (it == dict_elems.end()) { + MS_LOG(EXCEPTION) << "The key " << key_str << " does not exist in the dict:" << args_spec_list[0]->ToString(); + } + return it->second; +} + +AbstractBasePtr InferImplDictSetItem(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a dict and a scalar whose value is a string and an object of a subclass of AbstractBase. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 3); + AbstractDictionaryPtr dict = CheckArg(op_name, args_spec_list, 0); + AbstractScalarPtr key = CheckArg(op_name, args_spec_list, 1); + + ValuePtr key_value = key->BuildValue(); + if (!key_value->isa()) { + MS_LOG(EXCEPTION) << op_name << " evaluator key should be string, but got " << key_value->ToString(); + } + std::string key_str = GetValue(key_value); + std::vector dict_elems = dict->elements(); + auto it = std::find_if(dict_elems.begin(), dict_elems.end(), + [key_str](const AbstractAttribute &item) { return item.first == key_str; }); + + MS_EXCEPTION_IF_NULL(args_spec_list[2]); + auto new_ele = std::make_pair(key_str, args_spec_list[2]); + if (it != dict_elems.end()) { + int index = it - dict_elems.begin(); + dict_elems[IntToSize(index)] = new_ele; + } else { + dict_elems.push_back(new_ele); + } + return std::make_shared(dict_elems); +} + +AbstractBasePtr InferImplListAppend(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + // Inputs: a list and an object of a subclass of AbstractBase. + const std::string op_name = primitive->name(); + CheckArgsSize(op_name, args_spec_list, 2); + AbstractListPtr list = CheckArg(op_name, args_spec_list, 0); + (void)AbstractJoin(list->elements()); + return list; +} + +AbstractBasePtr InferImplTupleLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferTupleOrListOrDictLen(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplListLen(const AnalysisEnginePtr &, const PrimitivePtr &primitive, + const AbstractBasePtrList &args_spec_list) { + return InferTupleOrListOrDictLen(primitive->name(), args_spec_list); +} + +AbstractBasePtr InferImplArrayLen(const AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &args_spec_list) { + return std::make_shared(kAnyValue, kInt32); +} +} // namespace abstract +} // namespace mindspore diff --git a/mindspore/core/abstract/primitive_infer_map.cc b/mindspore/core/abstract/primitive_infer_map.cc new file mode 100644 index 0000000000..0b34985d67 --- /dev/null +++ b/mindspore/core/abstract/primitive_infer_map.cc @@ -0,0 +1,114 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "abstract/primitive_infer_map.h" +#include "abstract/abstract_function.h" +#include "abstract/infer_functions.h" + +namespace mindspore { +namespace abstract { +PrimitiveEvalImplMap &GetPrimitiveToEvalImplMap() { + static PrimitiveEvalImplMap prim_eval_implement_map = { + // Statements + {prim::kPrimReturn, {InferImplReturn, true}}, + {prim::kPrimDot, {InferImplDot, true}}, + {prim::kPrimSwitch, {InferImplSwitch, true}}, + {prim::kPrimSwitchLayer, {InferImplSwitchLayer, true}}, + {prim::kPrimIs_, {InferImplIs_, true}}, + {prim::kPrimIsNot, {InferImplIsNot, true}}, + {prim::kPrimInDict, {InferImplInDict, true}}, + {prim::kPrimNotInDict, {InferImplNotInDict, true}}, + {prim::kPrimIsConsant, {InferImplIsConstant, true}}, + // Maths + {prim::kPrimMaximumGrad, {InferImplMinOrMaxGrad, true}}, + {prim::kPrimMinimumGrad, {InferImplMinOrMaxGrad, true}}, + // Array + {prim::kPrimScalarToArray, {InferImplScalarToArray, true}}, + {prim::kPrimArrayToScalar, {InferImplArrayToScalar, true}}, + {prim::kPrimBroadcastShape, {InferImplBroadCastShape, true}}, + {prim::kPrimPack, {InferImplPack, true}}, + {prim::kPrimUnique, {InferImplUnique, true}}, + {prim::kPrimUniqueGrad, {InferImplUniqueGrad, true}}, + // Structure + {prim::kPrimMakeTuple, {InferImplMakeTuple, true}}, + {prim::kPrimMakeList, {InferImplMakeList, true}}, + {prim::kPrimMakeDict, {InferImplMakeDict, true}}, + {prim::kPrimMakeSlice, {InferImplMakeSlice, true}}, + {prim::kPrimMakeKeywordArg, {InferImplMakeKwarg, true}}, + {prim::kPrimExtractKeywordArg, {InferImplExtractKwarg, true}}, + {prim::kPrimTupleGetItem, {InferImplTupleGetItem, true}}, + {prim::kPrimListGetItem, {InferImplListGetItem, true}}, + {prim::kPrimTupleSetItem, {InferImplTupleSetItem, true}}, + {prim::kPrimListSetItem, {InferImplListSetItem, true}}, + {prim::kPrimDictGetItem, {InferImplDictGetItem, true}}, + {prim::kPrimDictSetItem, {InferImplDictSetItem, true}}, + {prim::kPrimListAppend, {InferImplListAppend, true}}, + {prim::kPrimTupleLen, {InferImplTupleLen, true}}, + {prim::kPrimListLen, {InferImplListLen, true}}, + {prim::kPrimArrayLen, {InferImplArrayLen, true}}, + // NN + {prim::kPrimPooling, {InferImplPooling, true}}, + {prim::kPrimPoolingGrad, {InferImplPoolingGrad, true}}, + {prim::kPrimFusedBatchNorm, {InferImplFusedBatchNorm, true}}, + {prim::kPrimFusedBatchNormGrad, {InferImplFusedBatchNormGrad, true}}, + {prim::kPrimReluGrad, {InferImplReluGrad, true}}, + {prim::kPrimConv2DBackpropInput, {InferImplConv2DBackpropInput, true}}, + {prim::kPrimConv2DBackpropFilter, {InferImplConv2DBackpropFilter, true}}, + {prim::kPrimBiasAddGrad, {InferImplBiasAddGrad, true}}, + {prim::kPrimRelu, {InferImplRelu, true}}, + {prim::kPrimZerosLike, {InferImplZerosLike, true}}, + {prim::kPrimBpropCut, {InferImplBpropCut, true}}, + {prim::kPrimLayerNorm, {InferImplLayerNorm, true}}, + {prim::kPrimLayerNormGrad, {InferImplLayerNormGrad, true}}, + {prim::kPrimDropoutGenMask, {InferImplDropoutGenMask, true}}, + // Others + {prim::kPrimIdentity, {InferImplIdentity, true}}, + // Set impl to null as it will use PartialEvaluator; + {prim::kPrimPartial, {nullptr, true}}, + {prim::kPrimEnvGetItem, {InferImplEnvGetItem, true}}, + {prim::kPrimEnvSetItem, {InferImplEnvSetItem, true}}, + {prim::kPrimEnvAdd, {InferImplEnvAdd, true}}, + {prim::kPrimMakeRefKey, {InferImplMakeRefKey, true}}, + {prim::kPrimMakeRef, {InferImplMakeRef, true}}, + {prim::kPrimGetRefKey, {InferImplGetRefKey, true}}, + {prim::kPrimGetRefValue, {InferImplGetRefValue, true}}, + {prim::kPrimStateSetItem, {InferImplStateSetItem, true}}, + {prim::kPrimDepend, {InferImplDepend, true}}, + {prim::kPrimControlDepend, {InferImplControlDepend, true}}, + // Debug + {prim::kPrimDebug, {InferImplDebug, true}}, + // SparseTensor + {prim::kPrimMakeSparseTensor, {InferImplMakeSparseTensor, true}}, + {prim::kPrimSparseTensorGetValues, {InferImplSparseTensorGetValues, true}}, + {prim::kPrimSparseTensorGetIndices, {InferImplSparseTensorGetIndices, true}}, + {prim::kPrimSparseTensorGetDenseShape, {InferImplSparseTensorGetDenseShape, true}}, + // RowTensor + {prim::kPrimMakeRowTensor, {InferImplMakeRowTensor, true}}, + {prim::kPrimRowTensorGetValues, {InferImplRowTensorGetValues, true}}, + {prim::kPrimRowTensorGetIndices, {InferImplRowTensorGetIndices, true}}, + {prim::kPrimRowTensorGetDenseShape, {InferImplRowTensorGetDenseShape, true}}, + }; + return prim_eval_implement_map; +} + +void RegisterStandardPrimitiveImpl(const PrimitivePtr &primitive, const StandardPrimitiveImplReg &impl_reg) { + auto &prim_eval_map = GetPrimitiveToEvalImplMap(); + prim_eval_map[primitive] = impl_reg; +} +} // namespace abstract +} // namespace mindspore diff --git a/mindspore/core/abstract/primitive_infer_map.h b/mindspore/core/abstract/primitive_infer_map.h new file mode 100644 index 0000000000..87380c60e4 --- /dev/null +++ b/mindspore/core/abstract/primitive_infer_map.h @@ -0,0 +1,53 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CORE_ABSTRACT_PRIMITIVE_INFER_MAP_H_ +#define MINDSPORE_CORE_ABSTRACT_PRIMITIVE_INFER_MAP_H_ +#include +#include "ir/primitive.h" +#include "base/core_ops.h" +#include "abstract/abstract_value.h" +namespace mindspore { +namespace abstract { +using StandardPrimitiveEvalImpl = AbstractBasePtr (*)(const abstract::AnalysisEnginePtr &, const PrimitivePtr &, + const AbstractBasePtrList &); +struct StandardPrimitiveImplReg { + StandardPrimitiveEvalImpl impl_; // Implement function of Primitive. + bool in_white_list_; // true if this Primitive in white list, else false. +}; + +using PrimitiveEvalImplMap = + std::unordered_map; + +PrimitiveEvalImplMap &GetPrimitiveToEvalImplMap(); + +void RegisterStandardPrimitiveImpl(const PrimitivePtr &primitive, const StandardPrimitiveImplReg &impl_reg); + +class RegisterStandardPrimitiveEvalHelper { + public: + RegisterStandardPrimitiveEvalHelper(const PrimitivePtr &primitive, const StandardPrimitiveEvalImpl &impl) { + const StandardPrimitiveImplReg impl_reg{impl, true}; + RegisterStandardPrimitiveImpl(primitive, impl_reg); + } + ~RegisterStandardPrimitiveEvalHelper() = default; +}; + +#define REGISTER_PRIMITIVE_EVAL_IMPL(name, primitive, impl) \ + static auto helper_##name = RegisterStandardPrimitiveEvalHelper(primitive, impl) +} // namespace abstract +} // namespace mindspore +#endif // MINDSPORE_CORE_ABSTRACT_PRIMITIVE_INFER_MAP_H_ diff --git a/mindspore/core/base/CMakeLists.txt b/mindspore/core/base/CMakeLists.txt deleted file mode 100644 index d65b91a824..0000000000 --- a/mindspore/core/base/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -file(GLOB_RECURSE _BASE_ALL_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") -set_property(SOURCE ${_BASE_ALL_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_BASE) -add_library(_mindspore_base_obj OBJECT ${_BASE_ALL_SRC_FILES}) diff --git a/mindspore/core/base/core_ops.h b/mindspore/core/base/core_ops.h index a04b983a2d..ba64ff28d5 100755 --- a/mindspore/core/base/core_ops.h +++ b/mindspore/core/base/core_ops.h @@ -25,6 +25,152 @@ namespace mindspore { namespace prim { +// Here list all primitives used in backend or some special primitives used by core. +// Arithmetic +inline const PrimitivePtr kPrimScalarAdd = std::make_shared("scalar_add"); +inline const PrimitivePtr kPrimScalarSub = std::make_shared("scalar_sub"); +inline const PrimitivePtr kPrimScalarMul = std::make_shared("scalar_mul"); +inline const PrimitivePtr kPrimScalarDiv = std::make_shared("scalar_div"); +inline const PrimitivePtr kPrimScalarFloordiv = std::make_shared("scalar_floordiv"); +inline const PrimitivePtr kPrimScalarMod = std::make_shared("scalar_mod"); +inline const PrimitivePtr kPrimScalarPow = std::make_shared("scalar_pow"); +inline const PrimitivePtr kPrimScalarTrunc = std::make_shared("scalar_trunc"); +inline const PrimitivePtr kPrimScalarFloor = std::make_shared("scalar_floor"); +inline const PrimitivePtr kPrimScalarUadd = std::make_shared("scalar_uadd"); +inline const PrimitivePtr kPrimScalarUsub = std::make_shared("scalar_usub"); +inline const PrimitivePtr kPrimScalarExp = std::make_shared("scalar_exp"); +inline const PrimitivePtr kPrimScalarLog = std::make_shared("scalar_log"); +inline const PrimitivePtr kPrimScalarSin = std::make_shared("scalar_sin"); +inline const PrimitivePtr kPrimScalarCos = std::make_shared("scalar_cos"); +inline const PrimitivePtr kPrimScalarTan = std::make_shared("scalar_tan"); + +// Comparisons +inline const PrimitivePtr kPrimScalarEq = std::make_shared("scalar_eq"); +inline const PrimitivePtr kPrimScalarLt = std::make_shared("scalar_lt"); +inline const PrimitivePtr kPrimScalarGt = std::make_shared("scalar_gt"); +inline const PrimitivePtr kPrimScalarNe = std::make_shared("scalar_ne"); +inline const PrimitivePtr kPrimScalarLe = std::make_shared("scalar_le"); +inline const PrimitivePtr kPrimScalarGe = std::make_shared("scalar_ge"); +inline const PrimitivePtr kPrimBoolNot = std::make_shared("bool_not"); +inline const PrimitivePtr kPrimBoolAnd = std::make_shared("bool_and"); +inline const PrimitivePtr kPrimBoolOr = std::make_shared("bool_or"); +inline const PrimitivePtr kPrimBoolEq = std::make_shared("bool_eq"); +inline const PrimitivePtr kPrimGreater = std::make_shared("Greater"); +inline const PrimitivePtr kPrimGreaterEqual = std::make_shared("GreaterEqual"); +inline const PrimitivePtr kPrimLess = std::make_shared("Less"); +inline const PrimitivePtr kPrimLessEqual = std::make_shared("LessEqual"); +inline const PrimitivePtr kPrimEqual = std::make_shared("Equal"); +inline const PrimitivePtr kPrimNotEqual = std::make_shared("NotEqual"); + +inline const PrimitivePtr kPrimDistribute = std::make_shared("distribute"); +inline const PrimitivePtr kPrimDot = std::make_shared("dot"); +inline const PrimitivePtr kPrimIm2Col = std::make_shared("im2col"); +inline const PrimitivePtr kPrimCol2Im = std::make_shared("col2im"); +inline const PrimitivePtr kPrimIm2ColV1 = std::make_shared("im2col_v1"); +inline const PrimitivePtr kPrimCol2ImV1 = std::make_shared("col2im_v1"); + +inline const PrimitivePtr kPrimLabelGoto = std::make_shared("LabelGoto"); +inline const PrimitivePtr kPrimLabelSwitch = std::make_shared("LabelSwitch"); +inline const PrimitivePtr kPrimLabelSet = std::make_shared("LabelSet"); + +// Arrays +inline const PrimitivePtr kPrimScalarToArray = std::make_shared("scalar_to_array"); +inline const PrimitivePtr kPrimArrayToScalar = std::make_shared("array_to_scalar"); +inline const PrimitivePtr kPrimBroadcastShape = std::make_shared("broadcast_shape"); +inline const PrimitivePtr kPrimArrayMap = std::make_shared("array_map"); +inline const PrimitivePtr kPrimArrayReduce = std::make_shared("array_reduce"); +inline const PrimitivePtr kPrimCast = std::make_shared("Cast"); +inline const PrimitivePtr kPrimConcat = std::make_shared("Concat"); +inline const PrimitivePtr kPrimSqueeze = std::make_shared("Squeeze"); +inline const PrimitivePtr kPrimTranspose = std::make_shared("Transpose"); +inline const PrimitivePtr kPrimGatherV2 = std::make_shared("GatherV2"); +inline const PrimitivePtr kPrimEmbeddingLookup = std::make_shared("EmbeddingLookup"); +inline const PrimitivePtr kPrimEmbeddingLookupCommGrad = std::make_shared("EmbeddingLookupCommGrad"); +inline const PrimitivePtr kPrimSize = std::make_shared("Size"); +inline const PrimitivePtr kPrimArgMax = std::make_shared("Argmax"); +inline const PrimitivePtr kPrimPack = std::make_shared("Pack"); +inline const PrimitivePtr kPrimUnsortedSegmentSum = std::make_shared("UnsortedSegmentSum"); +inline const PrimitivePtr kPrimUnsortedSegmentMin = std::make_shared("UnsortedSegmentMin"); +inline const PrimitivePtr kPrimConcatOffset = std::make_shared("ConcatOffset"); +inline const PrimitivePtr kPrimReshape = std::make_shared("Reshape"); +inline const PrimitivePtr kPrimTile = std::make_shared("Tile"); +inline const PrimitivePtr kPrimAddN = std::make_shared("AddN"); +inline const PrimitivePtr KPrimTransData = std::make_shared("TransData"); +inline const PrimitivePtr kPrimNMSWithMask = std::make_shared("NMSWithMask"); +inline const PrimitivePtr kPrimPad = std::make_shared("Pad"); +inline const PrimitivePtr kPrimArgMaxWithValue = std::make_shared("ArgMaxWithValue"); +inline const PrimitivePtr kPrimUnique = std::make_shared("Unique"); +inline const PrimitivePtr kPrimUniqueGrad = std::make_shared("UniqueGrad"); + +// NN +inline const PrimitivePtr kPrimFlatten = std::make_shared("Flatten"); +inline const PrimitivePtr kPrimSoftmax = std::make_shared("Softmax"); +inline const PrimitivePtr kPrimLogSoftmax = std::make_shared("LogSoftmax"); +inline const PrimitivePtr kPrimLogSoftmaxGrad = std::make_shared("LogSoftmaxGrad"); +inline const PrimitivePtr kPrimTanh = std::make_shared("Tanh"); +inline const PrimitivePtr kPrimTanhGrad = std::make_shared("TanhGrad"); +inline const PrimitivePtr kPrimPooling = std::make_shared("Pooling"); +inline const PrimitivePtr kPrimPoolingGrad = std::make_shared("PoolingGrad"); +inline const PrimitivePtr kPrimMaxPool = std::make_shared("MaxPool"); +inline const PrimitivePtr kPrimMaxPoolGrad = std::make_shared("MaxPoolGrad"); +inline const PrimitivePtr kPrimApplyCenteredRMSProp = std::make_shared("ApplyCenteredRMSProp"); +inline const PrimitivePtr kPrimAvgPoolGrad = std::make_shared("AvgPoolGrad"); +inline const PrimitivePtr kPrimAvgPoolGradVm = std::make_shared("AvgPoolGradVm"); +inline const PrimitivePtr kPrimFusedBatchNorm = std::make_shared("FusedBatchNorm"); +inline const PrimitivePtr kPrimConv2D = std::make_shared("Conv2D"); +inline const PrimitivePtr kPrimFusedBatchNormGrad = std::make_shared("FusedBatchNormGrad"); +inline const PrimitivePtr kPrimBatchNorm = std::make_shared("BatchNorm"); +inline const PrimitivePtr kPrimBatchNormGrad = std::make_shared("BatchNormGrad"); +inline const PrimitivePtr kPrimReluGrad = std::make_shared("ReluGrad"); +inline const PrimitivePtr kPrimConv2DBackpropInput = std::make_shared("Conv2DBackpropInput"); +inline const PrimitivePtr kPrimConv2DBackpropFilter = std::make_shared("Conv2DBackpropFilter"); +inline const PrimitivePtr kPrimDepthwiseConv2dNative = std::make_shared("DepthwiseConv2dNative"); +inline const PrimitivePtr kPrimDepthwiseConv2dNativeBackpropFilter = + std::make_shared("DepthwiseConv2dNativeBackpropFilter"); +inline const PrimitivePtr kPrimDepthwiseConv2dNativeBackpropInput = + std::make_shared("DepthwiseConv2dNativeBackpropInput"); +inline const PrimitivePtr kPrimBiasAddGrad = std::make_shared("BiasAddGrad"); +inline const PrimitivePtr kPrimSoftmaxCrossEntropyWithLogits = + std::make_shared("SoftmaxCrossEntropyWithLogits"); +inline const PrimitivePtr kPrimSparseSoftmaxCrossEntropyWithLogits = + std::make_shared("SparseSoftmaxCrossEntropyWithLogits"); +inline const PrimitivePtr kPrimMomentum = std::make_shared("Momentum"); +inline const PrimitivePtr kPrimApplyMomentum = std::make_shared("ApplyMomentum"); +inline const PrimitivePtr kPrimLayerNorm = std::make_shared("LayerNorm"); +inline const PrimitivePtr kPrimLayerNormGrad = std::make_shared("LayerNormGrad"); +inline const PrimitivePtr kPrimLayerNormXBackprop = std::make_shared("LayerNormXBackprop"); +inline const PrimitivePtr kPrimLayerNormBetaGammaBackprop = std::make_shared("LayerNormBetaGammaBackprop"); +inline const PrimitivePtr kPrimDropoutGenMask = std::make_shared("DropoutGenMask"); +inline const PrimitivePtr kPrimDropoutDoMask = std::make_shared("DropoutDoMask"); +inline const PrimitivePtr kPrimOneHot = std::make_shared("OneHot"); +inline const PrimitivePtr kPrimGelu = std::make_shared("Gelu"); +inline const PrimitivePtr kPrimGeluGrad = std::make_shared("GeluGrad"); +inline const PrimitivePtr kPrimRelu = std::make_shared("ReLU"); +inline const PrimitivePtr kPrimReluV2 = std::make_shared("ReLUV2"); +inline const PrimitivePtr kPrimZerosLike = std::make_shared("ZerosLike"); +inline const PrimitivePtr kPrimBpropCut = std::make_shared("bprop_cut"); +inline const PrimitivePtr kPrimFakeQuantPerLayer = std::make_shared("FakeQuantPerLayer"); +inline const PrimitivePtr kPrimFakeQuantPerChannel = std::make_shared("FakeQuantPerChannel"); +inline const PrimitivePtr kPrimApplyRMSProp = std::make_shared("ApplyRMSProp"); + +// Comm ops +inline const PrimitivePtr kPrimMirror = std::make_shared("_MirrorOperator"); +inline const PrimitivePtr kPrimVirtualDiv = std::make_shared("_VirtualDiv"); +inline const PrimitivePtr kPrimVirtualDataset = std::make_shared("_VirtualDataset"); +inline const PrimitivePtr kPrimAllReduce = std::make_shared("AllReduce"); + +// RowTensor +inline const PrimitivePtr kPrimMakeRowTensor = std::make_shared("MakeRowTensor"); +inline const PrimitivePtr kPrimRowTensorGetValues = std::make_shared("RowTensorGetValues"); +inline const PrimitivePtr kPrimRowTensorGetIndices = std::make_shared("RowTensorGetIndices"); +inline const PrimitivePtr kPrimRowTensorGetDenseShape = std::make_shared("RowTensorGetDenseShape"); + +// SparseTensor +inline const PrimitivePtr kPrimMakeSparseTensor = std::make_shared("MakeSparseTensor"); +inline const PrimitivePtr kPrimSparseTensorGetValues = std::make_shared("SparseTensorGetValues"); +inline const PrimitivePtr kPrimSparseTensorGetIndices = std::make_shared("SparseTensorGetIndices"); +inline const PrimitivePtr kPrimSparseTensorGetDenseShape = std::make_shared("SparseTensorGetDenseShape"); + // Maths inline const PrimitivePtr kPrimTensorAdd = std::make_shared("TensorAdd"); inline const PrimitivePtr kPrimMatMul = std::make_shared("MatMul"); @@ -64,44 +210,18 @@ inline const PrimitivePtr kPrimAssignSub = std::make_shared("AssignSu inline const PrimitivePtr kPrimSelect = std::make_shared("Select"); inline const PrimitivePtr kPrimCall = std::make_shared("call"); -// Structures -inline const PrimitivePtr kPrimStringEqual = std::make_shared("string_equal"); -inline const PrimitivePtr kPrimStringConcat = std::make_shared("string_concat"); inline const PrimitivePtr kPrimMakeTuple = std::make_shared("make_tuple"); -inline const PrimitivePtr kPrimMakeDict = std::make_shared("make_dict"); -inline const PrimitivePtr kPrimMakeList = std::make_shared("make_list"); -inline const PrimitivePtr kPrimMakeKeywordArg = std::make_shared("make_keyword_arg"); inline const PrimitivePtr kPrimMakeSlice = std::make_shared("make_slice"); -inline const PrimitivePtr kPrimMakeRecord = std::make_shared("make_record"); inline const PrimitivePtr kPrimTupleGetItem = std::make_shared("tuple_getitem"); -inline const PrimitivePtr kPrimListGetItem = std::make_shared("list_getitem"); inline const PrimitivePtr kPrimArrayGetItem = std::make_shared("array_getitem"); inline const PrimitivePtr kPrimTupleSetItem = std::make_shared("tuple_setitem"); -inline const PrimitivePtr kPrimListSetItem = std::make_shared("list_setitem"); inline const PrimitivePtr kPrimArraySetItem = std::make_shared("array_setitem"); -inline const PrimitivePtr kPrimDictGetItem = std::make_shared("dict_getitem"); -inline const PrimitivePtr kPrimDictSetItem = std::make_shared("dict_setitem"); -inline const PrimitivePtr kPrimListAppend = std::make_shared("list_append"); inline const PrimitivePtr kPrimGetAttr = std::make_shared("getattr"); inline const PrimitivePtr kPrimTupleLen = std::make_shared("tuple_len"); -inline const PrimitivePtr kPrimDictLen = std::make_shared("dict_len"); -inline const PrimitivePtr kPrimListLen = std::make_shared("list_len"); inline const PrimitivePtr kPrimArrayLen = std::make_shared("array_len"); -inline const PrimitivePtr kPrimListMap = std::make_shared("list_map"); -inline const PrimitivePtr kPrimListReduce = std::make_shared("list_reduce"); -inline const PrimitivePtr kPrimTupleReversed = std::make_shared("tuple_reversed"); inline const PrimitivePtr kPrimTileShape = std::make_shared("tile_shape"); -inline const PrimitivePtr kPrimReducedShape = std::make_shared("reduced_shape"); -inline const PrimitivePtr kPrimTupleDiv = std::make_shared("tuple_div"); -inline const PrimitivePtr kPrimTupleToArray = std::make_shared("tuple_to_array"); -inline const PrimitivePtr kPrimShapeMul = std::make_shared("shape_mul"); inline const PrimitivePtr kPrimGenerateShapeIndex = std::make_shared("generate_shape_index"); inline const PrimitivePtr kPrimGenerateInverseIndex = std::make_shared("generate_inverse_index"); -inline const PrimitivePtr kPrimTupleEqual = std::make_shared("tuple_equal"); -inline const PrimitivePtr kPrimListEqual = std::make_shared("list_equal"); -inline const PrimitivePtr kPrimMakeRange = std::make_shared("make_range"); -inline const PrimitivePtr kPrimStopGradient = std::make_shared("stop_gradient"); -inline const PrimitivePtr kPrimExtractKeywordArg = std::make_shared("extract_keyword_arg"); // Debug ops inline const PrimitivePtr kPrimScalarSummary = std::make_shared("ScalarSummary"); @@ -111,35 +231,48 @@ inline const PrimitivePtr kPrimHistogramSummary = std::make_shared("H inline const PrimitivePtr kPrimDebug = std::make_shared("Debug"); // Other miscellaneous -inline const PrimitivePtr kPrimJ = std::make_shared("J"); inline const PrimitivePtr kPrimDepend = std::make_shared("Depend"); inline const PrimitivePtr kPrimPartial = std::make_shared("Partial"); inline const PrimitivePtr kPrimIdentity = std::make_shared("identity"); -inline const PrimitivePtr kPrimEnvSetItem = std::make_shared("env_setitem"); -inline const PrimitivePtr kPrimEnvGetItem = std::make_shared("env_getitem"); -inline const PrimitivePtr kPrimEnvAdd = std::make_shared("env_add"); -inline const PrimitivePtr kPrimMakeRefKey = std::make_shared("MakeRefKey"); -inline const PrimitivePtr kPrimGetRefKey = std::make_shared("get_ref_key"); -inline const PrimitivePtr kPrimGetRefValue = std::make_shared("get_ref_value"); -inline const PrimitivePtr kPrimGetRefOrigin = std::make_shared("get_ref_origin"); -inline const PrimitivePtr kPrimInsertGradientOf = std::make_shared("InsertGradientOf"); inline const PrimitivePtr kPrimHookBackward = std::make_shared("HookBackward"); inline const PrimitivePtr kPrimPrintShapeType = std::make_shared("PrintShapeType"); inline const PrimitivePtr kPrimSameTypeShape = std::make_shared("SameTypeShape"); -inline const PrimitivePtr kPrimCheckBprop = std::make_shared("CheckBprop"); inline const PrimitivePtr kPrimPrint = std::make_shared("Print"); -inline const PrimitivePtr kPrimMakeRef = std::make_shared("make_ref"); -inline const PrimitivePtr kPrimStateSetItem = std::make_shared("state_setitem"); -inline const PrimitivePtr kPrimBroadcastGradientArgs = std::make_shared("BroadcastGradientArgs"); inline const PrimitivePtr kPrimControlDepend = std::make_shared("ControlDepend"); inline const PrimitivePtr kPrimIs_ = std::make_shared("is_"); inline const PrimitivePtr kPrimIsNot = std::make_shared("is_not"); inline const PrimitivePtr kPrimInDict = std::make_shared("in_dict"); inline const PrimitivePtr kPrimNotInDict = std::make_shared("not_in_dict"); -inline const PrimitivePtr kPrimMixedPrecisionCast = std::make_shared("mixed_precision_cast"); inline const PrimitivePtr kPrimIsConsant = std::make_shared("is_constant"); inline const PrimitivePtr kPrimEquivFormat = std::make_shared("EquivFormat"); +// Structures +inline const PrimitivePtr kPrimMakeList = std::make_shared("make_list"); +inline const PrimitivePtr kPrimMakeKeywordArg = std::make_shared("make_keyword_arg"); +inline const PrimitivePtr kPrimListGetItem = std::make_shared("list_getitem"); +inline const PrimitivePtr kPrimListSetItem = std::make_shared("list_setitem"); +inline const PrimitivePtr kPrimDictGetItem = std::make_shared("dict_getitem"); +inline const PrimitivePtr kPrimDictSetItem = std::make_shared("dict_setitem"); +inline const PrimitivePtr kPrimListAppend = std::make_shared("list_append"); +inline const PrimitivePtr kPrimListLen = std::make_shared("list_len"); + +// Other miscellaneous +inline const PrimitivePtr kPrimEnvSetItem = std::make_shared("env_setitem"); +inline const PrimitivePtr kPrimEnvGetItem = std::make_shared("env_getitem"); +inline const PrimitivePtr kPrimEnvAdd = std::make_shared("env_add"); +inline const PrimitivePtr kPrimMakeRefKey = std::make_shared("MakeRefKey"); +inline const PrimitivePtr kPrimGetRefKey = std::make_shared("get_ref_key"); +inline const PrimitivePtr kPrimMakeRef = std::make_shared("make_ref"); +inline const PrimitivePtr kPrimGetRefValue = std::make_shared("get_ref_value"); + +// Other primitve not used by backend but used in core; +inline const PrimitivePtr kPrimStateSetItem = std::make_shared("state_setitem"); +inline const PrimitivePtr kPrimJ = std::make_shared("J"); + +// Used to build graph which have keyword arguments +inline const PrimitivePtr kPrimExtractKeywordArg = std::make_shared("extract_keyword_arg"); +inline const PrimitivePtr kPrimMakeDict = std::make_shared("make_dict"); + class DoSignaturePrimitive : public Primitive { public: explicit DoSignaturePrimitive(const std::string &name, const ValuePtr &function) diff --git a/mindspore/core/c_ops/conv2d.cc b/mindspore/core/c_ops/conv2d.cc new file mode 100644 index 0000000000..77c6a61438 --- /dev/null +++ b/mindspore/core/c_ops/conv2d.cc @@ -0,0 +1,108 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "c_ops/conv2d.h" +#include +#include +#include +#include +#include +#include "utils/check_convert_utils.h" + +namespace mindspore { +namespace { +constexpr auto kKernelSize = "kernel_size"; +constexpr auto kStride = "stride"; +constexpr auto kDilation = "dilation"; +constexpr auto kPadMode = "pad_mode"; +constexpr auto kPad = "pad"; +constexpr auto kMode = "mode"; +constexpr auto kGroup = "group"; +constexpr auto kOutputChannel = "output channel"; +constexpr auto kPadList = "pad_list"; +constexpr auto kConv2DName = "Conv2D"; +} // namespace +Conv2d::Conv2d() : PrimitiveC(kConv2DName) { InitIOName({"x", "w"}, {"output"}); } + +void Conv2d::Init(int out_channel, const std::vector &kernel_size, int mode, const std::string &pad_mode, + const std::vector &pad, const std::vector &stride, const std::vector &dilation, + int group) { + auto prim_name = this->name(); + this->AddAttr("data_format", MakeValue("NCHW")); + this->AddAttr("offset_a", MakeValue(0)); + this->SetKernelSize(CheckAndConvertUtils::CheckPositiveVector(kKernelSize, kernel_size, prim_name)); + this->SetStride(CheckAndConvertUtils::CheckPositiveVector(kStride, stride, this->name(), true, true)); + this->SetDilation(CheckAndConvertUtils::CheckPositiveVector(kDilation, dilation, this->name(), true, true)); + this->SetPadMode(CheckAndConvertUtils::CheckString(kPadMode, pad_mode, {"valid", "same", "pad"}, prim_name)); + CheckAndConvertUtils::CheckInteger("pad size", pad.size(), kEqual, 4, prim_name); + if (pad_mode == "pad") { + for (auto item : pad) { + CheckAndConvertUtils::Check("pad item", item, kGreaterEqual, "zeros list", 0, prim_name); + } + } else { + CheckAndConvertUtils::Check(kPad, pad, kEqual, "zeros list", {0, 0, 0, 0}, prim_name); + } + this->SetPad(CheckAndConvertUtils::CheckPositiveVector(kPad, pad, this->name(), true, true)); + this->SetMode(CheckAndConvertUtils::CheckInteger("mode", mode, kEqual, 1, prim_name)); + this->SetOutChannel(CheckAndConvertUtils::CheckInteger("out_channel", out_channel, kGreaterThan, 0, prim_name)); + this->SetGroup(CheckAndConvertUtils::CheckInteger("group", group, kGreaterThan, 0, prim_name)); +} +std::vector Conv2d::GetKernelSize() const { + auto value_ptr = GetAttr(kKernelSize); + return GetValue>(value_ptr); +} +std::vector Conv2d::GetStride() const { + auto value_ptr = GetAttr(kStride); + return GetValue>(value_ptr); +} +std::vector Conv2d::GetDilation() const { + auto value_ptr = GetAttr(kDilation); + return GetValue>(value_ptr); +} +std::string Conv2d::GetPadMode() const { + auto value_ptr = this->GetAttr(kPadMode); + return GetValue(value_ptr); +} +std::vector Conv2d::GetPad() const { + auto value_ptr = this->GetAttr(kPad); + return GetValue>(value_ptr); +} +int Conv2d::GetMode() const { + auto value_ptr = this->GetAttr(kMode); + return GetValue(value_ptr); +} + +int Conv2d::GetGroup() const { + auto value_ptr = this->GetAttr(kGroup); + return GetValue(value_ptr); +} +int Conv2d::GetOutputChannel() const { + auto value_ptr = this->GetAttr(kOutputChannel); + return GetValue(value_ptr); +} + +void Conv2d::SetKernelSize(const std::vector &kernel_size) { this->AddAttr(kKernelSize, MakeValue(kernel_size)); } +void Conv2d::SetStride(const std::vector &stride) { this->AddAttr(kStride, MakeValue(stride)); } +void Conv2d::SetDilation(const std::vector &dilation) { this->AddAttr(kDilation, MakeValue(dilation)); } +void Conv2d::SetPadMode(const std::string &pad_mode) { this->AddAttr(kPadMode, MakeValue(pad_mode)); } +void Conv2d::SetPad(const std::vector &pad) { this->AddAttr(kPad, MakeValue(pad)); } +void Conv2d::SetMode(int mode) { this->AddAttr(kMode, MakeValue(mode)); } +void Conv2d::SetGroup(int group) { this->AddAttr(kGroup, MakeValue(group)); } +void Conv2d::SetOutChannel(int output_channel) { this->AddAttr(kOutputChannel, MakeValue(output_channel)); } +void Conv2d::SetPadList(const std::vector &pad_list) { this->AddAttr(kPadList, MakeValue(pad_list)); } +} // namespace mindspore diff --git a/mindspore/core/c_ops/conv2d.h b/mindspore/core/c_ops/conv2d.h new file mode 100644 index 0000000000..910fad18af --- /dev/null +++ b/mindspore/core/c_ops/conv2d.h @@ -0,0 +1,59 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CORE_C_OPS_CONV2D_H_ +#define MINDSPORE_CORE_C_OPS_CONV2D_H_ +#include +#include +#include +#include + +#include "c_ops/primitive_c.h" +#include "abstract/abstract_value.h" +#include "utils/check_convert_utils.h" +namespace mindspore { +class Conv2d : public PrimitiveC { + public: + Conv2d(); + void Init(int out_channel, const std::vector &kernel_size, int mode = 1, const std::string &pad_mode = "valid", + const std::vector &pad = {0, 0, 0, 0}, const std::vector &stride = {1, 1, 1, 1}, + const std::vector &dilation = {1, 1, 1, 1}, int group = 1); + std::vector GetKernelSize() const; + std::vector GetStride() const; + std::vector GetDilation() const; + std::string GetPadMode() const; + std::vector GetPad() const; + int GetMode() const; + int GetGroup() const; + int GetOutputChannel() const; + void SetKernelSize(const std::vector &kernel_size); + void SetStride(const std::vector &stride); + void SetDilation(const std::vector &dilation); + void SetPadMode(const std::string &pad_mode); + void SetPad(const std::vector &pad); + void SetMode(int mode); + void SetGroup(int group); + void SetOutChannel(int output_channel); + void SetPadList(const std::vector &pad_list); +}; +AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, + const std::vector &input_args); +using PrimConv2dPtr = std::shared_ptr; +} // namespace mindspore + +#endif // MINDSPORE_CORE_C_OPS_CONV2D_H_ diff --git a/mindspore/core/c_ops/primitive_c.h b/mindspore/core/c_ops/primitive_c.h new file mode 100644 index 0000000000..501f32f964 --- /dev/null +++ b/mindspore/core/c_ops/primitive_c.h @@ -0,0 +1,37 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CORE_C_OPS_PRIMITIVE_C_H_ +#define MINDSPORE_CORE_C_OPS_PRIMITIVE_C_H_ +#include +#include +#include "ir/primitive.h" +#include "ir/value.h" +namespace mindspore { +class PrimitiveC : public Primitive { + public: + explicit PrimitiveC(const std::string &name) : Primitive(name) {} + + protected: + void InitIOName(const std::vector &inputs_name, const std::vector &outputs_name) { + this->AddAttr("input_names", MakeValue(inputs_name)); + this->AddAttr("output_names", MakeValue(outputs_name)); + } +}; +} // namespace mindspore +#endif // MINDSPORE_CORE_C_OPS_PRIMITIVE_C_H_ diff --git a/mindspore/ccsrc/gvar/logging_level.cc b/mindspore/core/gvar/logging_level.cc similarity index 100% rename from mindspore/ccsrc/gvar/logging_level.cc rename to mindspore/core/gvar/logging_level.cc diff --git a/mindspore/ccsrc/gvar/typeid_manager.cc b/mindspore/core/gvar/typeid_manager.cc similarity index 100% rename from mindspore/ccsrc/gvar/typeid_manager.cc rename to mindspore/core/gvar/typeid_manager.cc diff --git a/mindspore/core/ir/CMakeLists.txt b/mindspore/core/ir/CMakeLists.txt deleted file mode 100644 index 77bc1b7661..0000000000 --- a/mindspore/core/ir/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -file(GLOB_RECURSE _IR_SRC_LIST ./*.cc dtype/*.cc) -set_property(SOURCE ${_IR_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_IR) -add_library(_mindspore_ir_obj OBJECT ${_IR_SRC_LIST}) diff --git a/mindspore/core/ir/func_graph.cc b/mindspore/core/ir/func_graph.cc index e8992fda8a..6832a94e82 100644 --- a/mindspore/core/ir/func_graph.cc +++ b/mindspore/core/ir/func_graph.cc @@ -632,6 +632,19 @@ void FuncGraph::CheckOrder() { MS_LOG(DEBUG) << "Check order okay."; } } +CNodePtr FuncGraph::NewCNode(const PrimitivePtr &primitive, const std::vector &inputs) { + auto primitive_node = std::make_shared(primitive); + std::vector input_node_list = {primitive_node}; + std::copy(inputs.begin(), inputs.end(), std::back_inserter(input_node_list)); + return NewCNode(input_node_list); +} + +ParameterPtr FuncGraph::add_parameter(const tensor::MetaTensorPtr &meta_tensor) { + auto parameter = add_parameter(); + parameter->set_default_param(MakeValue(meta_tensor)); + parameter->set_abstract(meta_tensor->ToAbstract()); + return parameter; +} size_t NewFgSeenGeneration() { static size_t fg_seen_generation = 0; diff --git a/mindspore/core/ir/func_graph.h b/mindspore/core/ir/func_graph.h index 3ce74cfb5b..8bcbd3fdc1 100644 --- a/mindspore/core/ir/func_graph.h +++ b/mindspore/core/ir/func_graph.h @@ -170,7 +170,9 @@ class FuncGraph : public FuncGraphBase { // create a cnode with given inputs, bound to this graph, and set to specific scope CNodePtr NewCNodeWithScope(const std::vector &inputs, const ScopePtr &scope); + virtual CNodePtr NewCNode(const PrimitivePtr &primitive, const std::vector &prim_inputs); + virtual ParameterPtr add_parameter(const tensor::MetaTensorPtr &meta_tensor); // Functions for handling variable argument, keyword-only arguments and variable keyword argument AnfNodePtr GetDefaultValueByName(const std::string &name); void set_param_default_value(const std::string &name, const AnfNodePtr &node) { diff --git a/mindspore/core/ir/pattern_matcher.h b/mindspore/core/ir/pattern_matcher.h index 7c1a856df6..1ed559d656 100644 --- a/mindspore/core/ir/pattern_matcher.h +++ b/mindspore/core/ir/pattern_matcher.h @@ -94,8 +94,8 @@ class PBinOperation : public PBase > { ~PBinOperation() = default; AnfNodePtr GetNode(const AnfNodePtr &node) const { - AnfNodePtr lhs = x_.GetNode(node->func_graph()); - AnfNodePtr rhs = y_.GetNode(node->func_graph()); + AnfNodePtr lhs = x_.GetNode(node); + AnfNodePtr rhs = y_.GetNode(node); AnfNodePtrList list = {NewValueNode(prim_), lhs, rhs}; return NewCNode(list, node->func_graph()); } @@ -113,25 +113,42 @@ class PBinOperation : public PBase > { if (!x_.TryCapture(inputs[2]) || !y_.TryCapture(inputs[1])) { return false; } + captured_binop_node_ = node; return true; } return false; } + captured_binop_node_ = node; return true; } } return false; } + + /// Returns the original node captured by this Binary Operation Pattern. + /// Throws exception if a node was not captured before. + AnfNodePtr GetOriginalNode() const { + if (captured_binop_node_ == nullptr) { + MS_EXCEPTION(ValueError) << "A Node wasn't captured for this Pattern before attempting to get it."; + } + + return captured_binop_node_; + } + void Reset() const { x_.Reset(); y_.Reset(); + captured_binop_node_ = nullptr; } + using Internal = const PBinOperation &; + private: const PrimitivePtr prim_; typename T::Internal x_; typename T2::Internal y_; bool is_commutative_{false}; + mutable AnfNodePtr captured_binop_node_{nullptr}; }; /// @@ -265,10 +282,11 @@ class PCNode : public PBase > { return *this; } + using Internal = const PCNode &; + void Reset() const { tuple_utils::PTupleResetCapture reset; tuple_utils::apply_func_tuple(&reset, args_); - has_min_extra_nodes_ = false; extra_nodes_.clear(); } @@ -316,6 +334,9 @@ class PPrimitive : public PBase > { AnfNodePtrList tokens(inputs.begin() + 1, inputs.end()); tuple_utils::PTupleCapture capture_func(tokens); tuple_utils::apply_func_tuple(&capture_func, args_); + if (capture_func.captured_) { + captured_prim_node_ = node; + } return capture_func.captured_; } return false; @@ -329,9 +350,11 @@ class PPrimitive : public PBase > { tuple_utils::apply_func_tuple(&capture_func, args_); // If it could capture the initial set of nodes specified in the Pattern // and there are enough extra inputs to add - if (capture_func.captured_ && inputs.size() > pattern_arg_len + 1) { - extra_nodes_.insert(extra_nodes_.end(), inputs.begin() + 1 + pattern_arg_len, inputs.end()); - return true; + if (capture_func.captured_) { + captured_prim_node_ = node; + if (inputs.size() > pattern_arg_len + 1) { + extra_nodes_.insert(extra_nodes_.end(), inputs.begin() + 1 + pattern_arg_len, inputs.end()); + } } return capture_func.captured_; } @@ -349,19 +372,42 @@ class PPrimitive : public PBase > { return *this; } + /// Returns the FuncGraph of the original node captured by this Primitive Pattern. + /// Throws exception if a node was not captured before. + FuncGraphPtr GetFuncGraph() const { + if (captured_prim_node_ == nullptr) { + MS_EXCEPTION(ValueError) << "A Node wasn't captured for this Pattern before attempting to get its FuncGraph."; + } + + return captured_prim_node_->func_graph(); + } + + /// Returns the original node captured by this Primitive Pattern. + /// Throws exception if a node was not captured before. + AnfNodePtr GetOriginalNode() const { + if (captured_prim_node_ == nullptr) { + MS_EXCEPTION(ValueError) << "A Node wasn't captured for this Pattern before attempting to get it."; + } + + return captured_prim_node_; + } + void Reset() const { tuple_utils::PTupleResetCapture reset; tuple_utils::apply_func_tuple(&reset, args_); - has_min_extra_nodes_ = false; extra_nodes_.clear(); + captured_prim_node_ = nullptr; } + using Internal = const PPrimitive &; + private: const PrimitivePtr prim_; std::tuple args_; mutable AnfNodePtrList extra_nodes_; mutable bool has_min_extra_nodes_{false}; mutable size_t min_extra_nodes_{0}; + mutable AnfNodePtr captured_prim_node_{nullptr}; }; /// diff --git a/mindspore/core/ir/primitive.h b/mindspore/core/ir/primitive.h index 2d52872eef..be1155b40a 100644 --- a/mindspore/core/ir/primitive.h +++ b/mindspore/core/ir/primitive.h @@ -25,7 +25,7 @@ #include "ir/dtype/type.h" #include "abstract/abstract_value.h" -#include "utils/base_ref_extends.h" +#include "base/base_ref.h" namespace mindspore { // Supported meta type diff --git a/mindspore/core/ir/tensor.cc b/mindspore/core/ir/tensor.cc index b0af4411d6..edcabc67be 100644 --- a/mindspore/core/ir/tensor.cc +++ b/mindspore/core/ir/tensor.cc @@ -465,6 +465,7 @@ std::string Tensor::GetShapeAndDataTypeInfo() const { std::string Tensor::ToString() const { const int small_tensor_size = 30; std::ostringstream buf; + data_sync(); buf << "Tensor shape:[" << shape() << "]" << this->Dtype()->ToString(); // only print small tensor if (DataSize() < small_tensor_size) { @@ -477,6 +478,7 @@ std::string Tensor::ToStringRepr() const { std::ostringstream buf; auto type_ptr = this->Dtype(); MS_EXCEPTION_IF_NULL(type_ptr); + data_sync(); buf << "Tensor shape:[" << shape() << "]" << type_ptr->ToString(); buf << "\nvalue:" << data().ToString(data_type_, shape()); return buf.str(); diff --git a/mindspore/core/utils/CMakeLists.txt b/mindspore/core/utils/CMakeLists.txt deleted file mode 100644 index f90d1b426a..0000000000 --- a/mindspore/core/utils/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -file(GLOB_RECURSE _UTIL_ALL_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc") -set_property(SOURCE ${_UTIL_ALL_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_UTILS) -add_library(_mindspore_core_utils_obj OBJECT ${_UTIL_ALL_SRC_FILES}) diff --git a/mindspore/core/utils/check_convert_utils.cc b/mindspore/core/utils/check_convert_utils.cc new file mode 100644 index 0000000000..140f3efc0d --- /dev/null +++ b/mindspore/core/utils/check_convert_utils.cc @@ -0,0 +1,270 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "utils/check_convert_utils.h" +#include +#include "abstract/abstract_value.h" + +namespace mindspore { +namespace { +const std::map> kCompareMap = { + {kEqual, [](int num1, int num2) -> bool { return num1 == num2; }}, + {kNotEqual, [](int num1, int num2) -> bool { return num1 != num2; }}, + {kLessThan, [](int num1, int num2) -> bool { return num1 < num2; }}, + {kLessEqual, [](int num1, int num2) -> bool { return num1 <= num2; }}, + {kGreaterThan, [](int num1, int num2) -> bool { return num1 > num2; }}, + {kGreaterEqual, [](int num1, int num2) -> bool { return num1 >= num2; }}}; + +const std::map)>> kCompareRangeMap = { + {kIncludeNeither, + [](int num1, std::pair range) -> bool { return num1 > range.first && num1 < range.second; }}, + {kIncludeLeft, + [](int num1, std::pair range) -> bool { return num1 >= range.first && num1 < range.second; }}, + {kIncludeRight, + [](int num1, std::pair range) -> bool { return num1 > range.first && num1 <= range.second; }}, + {kIncludeBoth, + [](int num1, std::pair range) -> bool { return num1 >= range.first && num1 <= range.second; }}}; + +const std::map kCompareToString = { + {kEqual, "equal"}, {kNotEqual, "not equal"}, {kLessThan, "less than"}, + {kLessEqual, "less eqaul"}, {kGreaterThan, "greater than"}, {kGreaterEqual, "greate equal"}}; + +const std::map> kCompareRangeToString = { + {kIncludeNeither, {"in (", ")"}}, + {kIncludeLeft, {" in [", ")"}}, + {kIncludeRight, {"in (", "]"}}, + {kIncludeBoth, {"in [", "]"}}}; +} // namespace +bool CheckAndConvertUtils::IsEqualVector(const std::vector &vec_1, const std::vector &vec_2) { + if (vec_1.size() != vec_2.size()) { + return false; + } + for (size_t index = 0; index < vec_1.size(); ++index) { + if (vec_1[index] != vec_2[index]) { + return false; + } + } + return true; +} + +std::vector CheckAndConvertUtils::CheckPositiveVector(const std::string &arg_name, + const std::vector &arg_value, + const std::string &prim_name, bool allow_four, + bool ret_four) { + if (arg_value.size() == 2) { + return ret_four ? std::vector{1, 1, arg_value[0], arg_value[1]} : arg_value; + } else if (arg_value.size() == 4 && allow_four) { + return ret_four ? arg_value : std::vector{arg_value[2], arg_value[3]}; + } + std::ostringstream buffer; + buffer << "For " << prim_name << " attr " << arg_name << " should be a positive vector of size two "; + if (allow_four) { + buffer << "or four "; + } + buffer << " positive int numbers , but got ["; + for (auto item : arg_value) { + buffer << item << ","; + } + buffer << "]"; + MS_EXCEPTION(ValueError) << buffer.str(); +} +std::string CheckAndConvertUtils::CheckString(const std::string &arg_name, const std::string &arg_value, + const std::set &check_list, const std::string &prim_name) { + if (check_list.find(arg_value) != check_list.end()) { + return arg_value; + } + std::ostringstream buffer; + buffer << "For " << prim_name << " the " << arg_name << " should be str and must be "; + if (check_list.size() == 1) { + buffer << (*check_list.begin()) << "but got " << arg_value; + MS_EXCEPTION(ValueError) << buffer.str(); + } + buffer << "one of {"; + for (const auto &item : check_list) { + buffer << item << " ,"; + } + buffer << " }" + << " but got " << arg_value; + MS_EXCEPTION(ValueError) << buffer.str(); +} + +int CheckAndConvertUtils::CheckInteger(const std::string &arg_name, int arg_value, CompareEnum compare_operator, + int match_value, const std::string &prim_name) { + auto iter = kCompareMap.find(compare_operator); + if (iter == kCompareMap.end()) { + MS_EXCEPTION(NotExistsError) << "compare_operator " << compare_operator << " cannot find in the compare map"; + } + if (iter->second(arg_value, match_value)) { + return arg_value; + } + std::ostringstream buffer; + if (prim_name.empty()) { + buffer << "The "; + } else { + buffer << "For " << prim_name << " the "; + } + buffer << arg_name << " must "; + auto iter_to_string = kCompareToString.find(compare_operator); + if (iter_to_string == kCompareToString.end()) { + MS_EXCEPTION(NotExistsError) << "compare_operator " << compare_operator << " cannot find in the compare string map"; + } + buffer << iter_to_string->second << match_value << " , but got " << arg_value; + MS_EXCEPTION(ValueError) << buffer.str(); +} + +void CheckAndConvertUtils::CheckInRange(const std::string &arg_name, int arg_value, CompareRange compare_operator, + const std::pair &range, const std::string &prim_name) { + auto iter = kCompareRangeMap.find(compare_operator); + if (iter == kCompareRangeMap.end()) { + MS_EXCEPTION(NotExistsError) << "compare_operator " << compare_operator << " cannot find in the compare map"; + } + if (iter->second(arg_value, range)) { + return; + } + std::ostringstream buffer; + if (prim_name.empty()) { + buffer << "The "; + } else { + buffer << "For " << prim_name << " the "; + } + buffer << arg_name << " must "; + auto iter_to_string = kCompareRangeToString.find(compare_operator); + if (iter_to_string == kCompareRangeToString.end()) { + MS_EXCEPTION(NotExistsError) << "compare_operator " << compare_operator << " cannot find in the compare string map"; + } + auto range_strng = iter_to_string->second; + buffer << range_strng.first << range.first << "," << range_strng.second << " , but got " << arg_value; + MS_EXCEPTION(ValueError) << buffer.str(); +} + +std::vector CheckAndConvertUtils::ConvertShapePtrToShape(const std::string &arg_name, const BaseShapePtr &shape, + const std::string &prim_name) { + MS_EXCEPTION_IF_NULL(shape); + if (!shape->isa()) { + MS_EXCEPTION(ValueError) << "The " << arg_name << "'s shape is " << shape->ToString() + << "should be a common shape!"; + } + auto shape_element = shape->cast(); + MS_EXCEPTION_IF_NULL(shape_element); + return shape_element->shape(); +} + +TypeId CheckAndConvertUtils::ConvertTypePtrToTypeId(const string &arg_name, const TypePtr &type_ptr, + const string &prim_name) { + MS_EXCEPTION_IF_NULL(type_ptr); + if (!type_ptr->isa() || !type_ptr->isa()) { + MS_EXCEPTION(ValueError) << "The " << arg_name << "'s shape is " << type_ptr->ToString() + << "should be a common type!(tensor_type && numbertype)"; + } + return type_ptr->type_id(); +} + +void CheckAndConvertUtils::Check(const string &arg_name, int arg_value, CompareEnum compare_type, + const string &value_name, int value, const string &prim_name, + ExceptionType exception_type) { + auto iter = kCompareMap.find(compare_type); + if (iter == kCompareMap.end()) { + MS_EXCEPTION(NotExistsError) << "the compare type :" << compare_type << " is not in the compare map"; + } + if (iter->second(arg_value, value)) { + return; + } + std::ostringstream buffer; + if (prim_name.empty()) { + buffer << "The "; + } else { + buffer << "For " << prim_name << " the "; + } + auto iter_to_string = kCompareToString.find(compare_type); + if (iter_to_string == kCompareToString.end()) { + MS_EXCEPTION(NotExistsError) << "compare_operator " << compare_type << " cannot find in the compare string map"; + } + MS_EXCEPTION(exception_type) << buffer.str() << arg_name << " should be " << iter_to_string->second << value + << " but got " << arg_value; +} +void CheckAndConvertUtils::Check(const string &arg_name, const std::vector &arg_value, CompareEnum compare_type, + const string &value_name, const std::vector &value, const string &prim_name, + ExceptionType exception_type) { + if (compare_type != kEqual) { + auto iter = kCompareToString.find(compare_type); + if (iter != kCompareToString.end()) { + MS_EXCEPTION(NotSupportError) << "Only supported equal to compare two vectors but got " << iter->second; + } + MS_EXCEPTION(UnknownError) << "Cannot find the operator " << compare_type << "in the compare map!"; + } + if (arg_value == value) { + return; + } + std::ostringstream buffer; + if (prim_name.empty()) { + buffer << "The "; + } else { + buffer << "For " << prim_name << " the "; + } + auto iter_to_string = kCompareToString.find(compare_type); + if (iter_to_string == kCompareToString.end()) { + MS_EXCEPTION(NotExistsError) << "compare_operator " << compare_type << " cannot find in the compare string map"; + } + buffer << arg_name << "should be " << iter_to_string->second << " ["; + for (auto item : value) { + buffer << item << ","; + } + buffer << "] " + << "but got ["; + for (auto item : arg_value) { + buffer << item << " ,"; + } + buffer << "]"; + MS_EXCEPTION(exception_type) << buffer.str(); +} + +void CheckAndConvertUtils::CheckTensorTypeSame(const std::map &types, + const std::set &check_list, const std::string &prim_name) { + if (types.empty()) { + MS_LOG(WARNING) << "Tryinh to use the function to check a empty types map!"; + return; + } + std::set types_id; + std::ostringstream buffer; + buffer << "For " << prim_name; + for (const auto &type : types) { + MS_EXCEPTION_IF_NULL(type.second); + if (!type.second->isa()) { + MS_EXCEPTION(TypeError) << "The " << prim_name << "'s" << type.first << " input must be tensor type but got " + << type.second->ToString(); + } + types_id.emplace(type.second->type_id()); + } + if (types_id.size() > 1) { + buffer << "'s input type is not same : "; + for (const auto &item : types) { + buffer << "[ name : " << item.first << " ,type : " << item.second->ToString() << "]"; + } + MS_EXCEPTION(TypeError) << buffer.str(); + } + if (check_list.find(*(types_id.begin())) != check_list.end()) { + buffer << " type of "; + for (const auto &elem : types) { + buffer << elem.first << " should be in ["; + for (auto type_elem : check_list) { + buffer << type_elem << " ,"; + } + buffer << "] , but got " << types.begin()->second->ToString(); + } + } + MS_EXCEPTION(TypeError) << buffer.str(); +} +} // namespace mindspore diff --git a/mindspore/core/utils/check_convert_utils.h b/mindspore/core/utils/check_convert_utils.h new file mode 100644 index 0000000000..f61f22d19b --- /dev/null +++ b/mindspore/core/utils/check_convert_utils.h @@ -0,0 +1,72 @@ +/** + * Copyright 2019-2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_CORE_UTILS_CHECK_CONVERT_UTILS_H +#define MINDSPORE_CORE_UTILS_CHECK_CONVERT_UTILS_H +#include +#include +#include +#include +#include +#include "base/base.h" +#include "ir/anf.h" +#include "ir/dtype/type_id.h" +#include "utils/log_adapter.h" +namespace mindspore { +enum CompareEnum : int { + kEqual = 1, // == + kNotEqual = 2, // != + kLessThan = 3, // < + kLessEqual = 4, // <= + kGreaterThan = 5, // > + kGreaterEqual = 6, // >= +}; + +enum CompareRange { + kIncludeNeither = 1, // (a,b) + kIncludeLeft = 2, // [a,b) + kIncludeRight = 3, // (a,b] + kIncludeBoth = 4, // [a,b] +}; + +class CheckAndConvertUtils { + public: + static std::vector CheckPositiveVector(const std::string &arg_name, const std::vector &arg_value, + const std::string &prim_name, bool allow_four = false, + bool ret_four = false); + static std::string CheckString(const std::string &arg_name, const std::string &arg_value, + const std::set &check_list, const std::string &prim_name); + static int CheckInteger(const std::string &arg_name, int arg_value, CompareEnum compare_operator, int match_value, + const std::string &prim_name); + static void CheckInRange(const std::string &arg_name, int arg_value, CompareRange compare_operator, + const std::pair &range, const std::string &prim_name); + static std::vector ConvertShapePtrToShape(const std::string &arg_name, const BaseShapePtr &shape, + const std::string &prim_name); + static TypeId ConvertTypePtrToTypeId(const std::string &arg_name, const TypePtr &type_ptr, + const std::string &prim_name); + static void Check(const std::string &arg_name, int arg_value, CompareEnum compare_type, const std::string &value_name, + int value, const std::string &prim_name = "", ExceptionType exception_type = ValueError); + static void Check(const std::string &arg_name, const std::vector &arg_value, CompareEnum compare_type, + const std::string &value_name, const std::vector &value, const std::string &prim_name = "", + ExceptionType exception_type = ValueError); + static void CheckTensorTypeSame(const std::map &types, const std::set &check_list, + const std::string &prim_name); + + private: + static bool IsEqualVector(const std::vector &vec_1, const std::vector &vec_2); +}; +} // namespace mindspore +#endif // MINDSPORE_CORE_UTILS_CHECK_CONVERT_UTILS_H diff --git a/mindspore/core/utils/label.h b/mindspore/core/utils/label.h index 62b98defd3..21f3493c36 100644 --- a/mindspore/core/utils/label.h +++ b/mindspore/core/utils/label.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_UTILS_LABEL_H_ -#define MINDSPORE_CCSRC_UTILS_LABEL_H_ +#ifndef MINDSPORE_CORE_UTILS_LABEL_H_ +#define MINDSPORE_CORE_UTILS_LABEL_H_ #include #include #include @@ -32,4 +32,4 @@ std::string Label(const DebugInfoPtr &debug_info, TraceLabelType trace_type = Tr } // namespace label_manage } // namespace mindspore -#endif // MINDSPORE_CCSRC_UTILS_LABEL_H_ +#endif // MINDSPORE_CORE_UTILS_LABEL_H_ diff --git a/mindspore/core/utils/log_adapter.cc b/mindspore/core/utils/log_adapter.cc index 8d91a6f776..0c5528353b 100644 --- a/mindspore/core/utils/log_adapter.cc +++ b/mindspore/core/utils/log_adapter.cc @@ -160,7 +160,7 @@ static std::string ExceptionTypeToString(ExceptionType type) { static const char *GetSubModuleName(SubModuleId module_id) { static const char *sub_module_names[NUM_SUBMODUES] = { "UNKNOWN", // SM_UNKNOWN - "BASE", // SM_BASE + "CORE", // SM_CORE "ANALYZER", // SM_ANALYZER "COMMON", // SM_COMMON "DEBUG", // SM_DEBUG @@ -180,7 +180,6 @@ static const char *GetSubModuleName(SubModuleId module_id) { "SESSION", // SM_SESSION "UTILS", // SM_UTILS "VM", // SM_VM - "ABSTRACT" // SM_ABSTRACT }; return sub_module_names[module_id % NUM_SUBMODUES]; diff --git a/mindspore/core/utils/log_adapter.h b/mindspore/core/utils/log_adapter.h index ce31ce9ab8..3b760836fa 100644 --- a/mindspore/core/utils/log_adapter.h +++ b/mindspore/core/utils/log_adapter.h @@ -103,7 +103,7 @@ enum MsLogLevel : int { DEBUG = 0, INFO, WARNING, ERROR, EXCEPTION }; enum SubModuleId : int { SM_UNKNOWN = 0, // unknown submodule - SM_BASE, // base + SM_CORE, // core SM_ANALYZER, // static analyzer SM_COMMON, // common SM_DEBUG, // debug @@ -123,7 +123,6 @@ enum SubModuleId : int { SM_SESSION, // session SM_UTILS, // utils SM_VM, // VM - SM_ABSTRACT, // abstract NUM_SUBMODUES // number of submodules }; diff --git a/mindspore/core/utils/ms_utils.h b/mindspore/core/utils/ms_utils.h index 23d08f8f28..bf85f47dc9 100644 --- a/mindspore/core/utils/ms_utils.h +++ b/mindspore/core/utils/ms_utils.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_COMMON_UTILS_H_ -#define MINDSPORE_CCSRC_COMMON_UTILS_H_ +#ifndef MINDSPORE_CORE_UTILS_MS_UTILS_H_ +#define MINDSPORE_CORE_UTILS_MS_UTILS_H_ #include #include @@ -49,4 +49,4 @@ static inline int SetEnv(const char *envname, const char *envvar, int overwrite } // namespace common } // namespace mindspore -#endif // MINDSPORE_CCSRC_COMMON_UTILS_H_ +#endif // MINDSPORE_CORE_UTILS_MS_UTILS_H_ diff --git a/mindspore/core/utils/profile.h b/mindspore/core/utils/profile.h index 2e236b7f5e..4478e236b8 100644 --- a/mindspore/core/utils/profile.h +++ b/mindspore/core/utils/profile.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_UTILS_PROFILE_H_ -#define MINDSPORE_CCSRC_UTILS_PROFILE_H_ +#ifndef MINDSPORE_CORE_UTILS_PROFILE_H_ +#define MINDSPORE_CORE_UTILS_PROFILE_H_ #include #include @@ -230,4 +230,4 @@ class MsProfile { #define WITH(x) NoProfTransaction(x) - #endif -#endif // MINDSPORE_CCSRC_UTILS_PROFILE_H_ +#endif // MINDSPORE_CORE_UTILS_PROFILE_H_ diff --git a/mindspore/dataset/engine/samplers.py b/mindspore/dataset/engine/samplers.py index 22c0e44d0d..1cc7efb914 100644 --- a/mindspore/dataset/engine/samplers.py +++ b/mindspore/dataset/engine/samplers.py @@ -359,7 +359,8 @@ class PKSampler(BuiltinSampler): if not self.class_column or not isinstance(self.class_column, str): raise ValueError("class_column should be a not empty string value, \ but got class_column={}".format(class_column)) - c_sampler = cde.MindrecordPkSampler(self.num_val, self.class_column, self.shuffle) + num_samples = self.num_samples if self.num_samples is not None else 0 + c_sampler = cde.MindrecordPkSampler(self.num_val, self.class_column, self.shuffle, num_samples) c_child_sampler = self.create_child_for_minddataset() c_sampler.add_child(c_child_sampler) return c_sampler diff --git a/mindspore/dataset/transforms/c_transforms.py b/mindspore/dataset/transforms/c_transforms.py index 41a31e7c50..0f3c8d145b 100644 --- a/mindspore/dataset/transforms/c_transforms.py +++ b/mindspore/dataset/transforms/c_transforms.py @@ -31,7 +31,10 @@ class OneHot(cde.OneHotOp): Tensor operation to apply one hot encoding. Args: - num_classes (int): Number of classes of the label. + num_classes (int): Number of classes of the label, it should be bigger than feature size. + + Raises: + RuntimeError: feature size is bigger than num_classes. """ @check_num_classes diff --git a/mindspore/dataset/transforms/vision/c_transforms.py b/mindspore/dataset/transforms/vision/c_transforms.py index 9a07c58a19..78a907b5f3 100644 --- a/mindspore/dataset/transforms/vision/c_transforms.py +++ b/mindspore/dataset/transforms/vision/c_transforms.py @@ -45,9 +45,10 @@ import mindspore._c_dataengine as cde from .utils import Inter, Border from .validators import check_prob, check_crop, check_resize_interpolation, check_random_resize_crop, \ - check_normalize_c, check_random_crop, check_random_color_adjust, check_random_rotation, check_range, \ - check_resize, check_rescale, check_pad, check_cutout, check_uniform_augment_cpp, check_bounding_box_augment_cpp, \ - check_random_select_subpolicy_op, check_auto_contrast, FLOAT_MAX_INTEGER + check_mix_up_batch_c, check_normalize_c, check_random_crop, check_random_color_adjust, check_random_rotation, \ + check_range, check_resize, check_rescale, check_pad, check_cutout, check_uniform_augment_cpp, \ + check_bounding_box_augment_cpp, check_random_select_subpolicy_op, check_auto_contrast, check_random_affine, \ + check_soft_dvpp_decode_random_crop_resize_jpeg, FLOAT_MAX_INTEGER DE_C_INTER_MODE = {Inter.NEAREST: cde.InterpolationMode.DE_INTER_NEAREST_NEIGHBOUR, Inter.LINEAR: cde.InterpolationMode.DE_INTER_LINEAR, @@ -130,6 +131,30 @@ class CutOut(cde.CutOutOp): super().__init__(length, length, num_patches, False, *fill_value) +class MixUpBatch(cde.MixUpBatchOp): + """ + Apply MixUp transformation on input batch of images and labels. Each image is multiplied by a random weight (lambda) + and then added to a randomly selected image from the batch multiplied by (1 - lambda). Same formula is also applied + to the one-hot labels. + Note that you need to make labels into one-hot format and batch before calling this function. + + Args: + alpha (float): hyperparameter of beta distribution (default = 1.0). + + Examples: + >>> one_hot_op = data.OneHot(num_classes=10) + >>> data = data.map(input_columns=["label"], operations=one_hot_op) + >>> mixup_batch_op = vision.MixUpBatch() + >>> data = data.batch(5) + >>> data = data.map(input_columns=["image", "label"], operations=mixup_batch_op) + """ + + @check_mix_up_batch_c + def __init__(self, alpha=1.0): + self.alpha = alpha + super().__init__(alpha) + + class Normalize(cde.NormalizeOp): """ Normalize the input image with respect to mean and standard deviation. @@ -146,6 +171,95 @@ class Normalize(cde.NormalizeOp): super().__init__(*mean, *std) +class RandomAffine(cde.RandomAffineOp): + """ + Apply Random affine transformation to the input PIL image. + + Args: + degrees (int or float or sequence): Range of the rotation degrees. + If degrees is a number, the range will be (-degrees, degrees). + If degrees is a sequence, it should be (min, max). + translate (sequence, optional): Sequence (tx, ty) of maximum translation in + x(horizontal) and y(vertical) directions (default=None). + The horizontal and vertical shift is selected randomly from the range: + (-tx*width, tx*width) and (-ty*height, ty*height), respectively. + If None, no translations gets applied. + scale (sequence, optional): Scaling factor interval (default=None, original scale is used). + shear (int or float or sequence, optional): Range of shear factor (default=None). + If a number 'shear', then a shear parallel to the x axis in the range of (-shear, +shear) is applied. + If a tuple or list of size 2, then a shear parallel to the x axis in the range of (shear[0], shear[1]) + is applied. + If a tuple of list of size 4, then a shear parallel to x axis in the range of (shear[0], shear[1]) + and a shear parallel to y axis in the range of (shear[2], shear[3]) is applied. + If None, no shear is applied. + resample (Inter mode, optional): An optional resampling filter (default=Inter.NEAREST). + If omitted, or if the image has mode "1" or "P", it is set to be Inter.NEAREST. + It can be any of [Inter.BILINEAR, Inter.NEAREST, Inter.BICUBIC]. + + - Inter.BILINEAR, means resample method is bilinear interpolation. + + - Inter.NEAREST, means resample method is nearest-neighbor interpolation. + + - Inter.BICUBIC, means resample method is bicubic interpolation. + + fill_value (tuple or int, optional): Optional fill_value to fill the area outside the transform + in the output image. Used only in Pillow versions > 5.0.0 (default=0, filling is performed). + + Raises: + ValueError: If degrees is negative. + ValueError: If translation value is not between 0 and 1. + ValueError: If scale is not positive. + ValueError: If shear is a number but is not positive. + TypeError: If degrees is not a number or a list or a tuple. + If degrees is a list or tuple, its length is not 2. + TypeError: If translate is specified but is not list or a tuple of length 2. + TypeError: If scale is not a list or tuple of length 2.'' + TypeError: If shear is not a list or tuple of length 2 or 4. + + Examples: + >>> c_transform.RandomAffine(degrees=15, translate=(0.1, 0.1), scale=(0.9, 1.1)) + """ + + @check_random_affine + def __init__(self, degrees, translate=None, scale=None, shear=None, resample=Inter.NEAREST, fill_value=0): + # Parameter checking + if shear is not None: + if isinstance(shear, numbers.Number): + shear = (-1 * shear, shear, 0., 0.) + else: + if len(shear) == 2: + shear = [shear[0], shear[1], 0., 0.] + elif len(shear) == 4: + shear = [s for s in shear] + + if isinstance(degrees, numbers.Number): + degrees = (-1 * degrees, degrees) + + if isinstance(fill_value, numbers.Number): + fill_value = (fill_value, fill_value, fill_value) + + # translation + if translate is None: + translate = (0.0, 0.0) + + # scale + if scale is None: + scale = (1.0, 1.0) + + # shear + if shear is None: + shear = (0.0, 0.0, 0.0, 0.0) + + self.degrees = degrees + self.translate = translate + self.scale_ = scale + self.shear = shear + self.resample = DE_C_INTER_MODE[resample] + self.fill_value = fill_value + + super().__init__(degrees, translate, scale, shear, DE_C_INTER_MODE[resample], fill_value) + + class RandomCrop(cde.RandomCropOp): """ Crop the input image at a random location. @@ -764,3 +878,57 @@ class RandomSelectSubpolicy(cde.RandomSelectSubpolicyOp): @check_random_select_subpolicy_op def __init__(self, policy): super().__init__(policy) + + +class SoftDvppDecodeResizeJpeg(cde.SoftDvppDecodeResizeJpegOp): + """ + Tensor operation to decode and resize jpeg image using the simulation algorithm of ascend series chip DVPP module. + + It is recommended to use this algorithm in the following scenarios: + When training, the DVPP of the ascend chip is not used, + and the DVPP of the ascend chip is used during inference, + and the accuracy of inference is lower than the accuracy of training. + + Args: + size (Union[int, sequence]): The output size of the resized image. + If size is an int, smaller edge of the image will be resized to this value with + the same image aspect ratio. + If size is a sequence of length 2, it should be (height, width). + """ + + @check_resize + def __init__(self, size): + if isinstance(size, int): + size = (size, size) + self.size = size + super().__init__(*size) + + +class SoftDvppDecodeRandomCropResizeJpeg(cde.SoftDvppDecodeRandomCropResizeJpegOp): + """ + Tensor operation to decode, random crop and resize jpeg image using the simulation algorithm of + ascend series chip DVPP module. + + The usage scenario is consistent with SoftDvppDecodeReiszeJpeg. + + Args: + size (Union[int, sequence], optional): The size of the output image. + If size is an int, a square crop of size (size, size) is returned. + If size is a sequence of length 2, it should be (height, width). + scale (tuple, optional): Range (min, max) of respective size of the + original size to be cropped (default=(0.08, 1.0)). + ratio (tuple, optional): Range (min, max) of aspect ratio to be + cropped (default=(3. / 4., 4. / 3.)). + max_attempts (int, optional): The maximum number of attempts to propose a valid crop_area (default=10). + If exceeded, fall back to use center_crop instead. + """ + + @check_soft_dvpp_decode_random_crop_resize_jpeg + def __init__(self, size, scale=(0.08, 1.0), ratio=(3. / 4., 4. / 3.), max_attempts=10): + if isinstance(size, int): + size = (size, size) + self.size = size + self.scale = scale + self.ratio = ratio + self.max_attempts = max_attempts + super().__init__(*size, *scale, *ratio, max_attempts) diff --git a/mindspore/dataset/transforms/vision/validators.py b/mindspore/dataset/transforms/vision/validators.py index f140673f31..16b7c684b7 100644 --- a/mindspore/dataset/transforms/vision/validators.py +++ b/mindspore/dataset/transforms/vision/validators.py @@ -47,6 +47,19 @@ def check_resize_size(size): raise TypeError("Size should be a single integer or a list/tuple (h, w) of length 2.") +def check_mix_up_batch_c(method): + """Wrapper method to check the parameters of MixUpBatch.""" + + @wraps(method) + def new_method(self, *args, **kwargs): + [alpha], _ = parse_user_args(method, *args, **kwargs) + check_pos_float32(alpha) + + return method(self, *args, **kwargs) + + return new_method + + def check_normalize_c_param(mean, std): if len(mean) != len(std): raise ValueError("Length of mean and std must be equal") @@ -162,30 +175,35 @@ def check_resize(method): return new_method +def check_size_scale_ration_max_attempts_paras(size, scale, ratio, max_attempts): + """Wrapper method to check the parameters of RandomCropDecodeResize and SoftDvppDecodeRandomCropResizeJpeg.""" + + check_crop_size(size) + if scale is not None: + type_check(scale, (tuple,), "scale") + type_check_list(scale, (float, int), "scale") + check_range(scale, [0, FLOAT_MAX_INTEGER]) + if scale[0] > scale[1]: + raise ValueError("scale should be in (min,max) format. Got (max,min).") + if ratio is not None: + type_check(ratio, (tuple,), "ratio") + type_check_list(ratio, (float, int), "ratio") + check_range(ratio, [0, FLOAT_MAX_INTEGER]) + if ratio[0] > ratio[1]: + raise ValueError("ratio should be in (min,max) format. Got (max,min).") + if max_attempts is not None: + check_value(max_attempts, (1, FLOAT_MAX_INTEGER)) + + def check_random_resize_crop(method): """A wrapper that wraps a parameter checker to the original function(random resize crop operation).""" @wraps(method) def new_method(self, *args, **kwargs): [size, scale, ratio, interpolation, max_attempts], _ = parse_user_args(method, *args, **kwargs) - check_crop_size(size) - - if scale is not None: - type_check(scale, (tuple,), "scale") - type_check_list(scale, (float, int), "scale") - check_range(scale, [0, FLOAT_MAX_INTEGER]) - if scale[0] > scale[1]: - raise ValueError("scale should be in (min,max) format. Got (max,min).") - if ratio is not None: - type_check(ratio, (tuple,), "ratio") - type_check_list(ratio, (float, int), "ratio") - check_range(ratio, [0, FLOAT_MAX_INTEGER]) - if ratio[0] > ratio[1]: - raise ValueError("ratio should be in (min,max) format. Got (max,min).") if interpolation is not None: type_check(interpolation, (Inter,), "interpolation") - if max_attempts is not None: - check_value(max_attempts, (1, FLOAT_MAX_INTEGER)) + check_size_scale_ration_max_attempts_paras(size, scale, ratio, max_attempts) return method(self, *args, **kwargs) @@ -645,3 +663,15 @@ def check_random_select_subpolicy_op(method): return method(self, *args, **kwargs) return new_method + + +def check_soft_dvpp_decode_random_crop_resize_jpeg(method): + """Wrapper method to check the parameters of SoftDvppDecodeRandomCropResizeJpeg.""" + + @wraps(method) + def new_method(self, *args, **kwargs): + [size, scale, ratio, max_attempts], _ = parse_user_args(method, *args, **kwargs) + check_size_scale_ration_max_attempts_paras(size, scale, ratio, max_attempts) + + return method(self, *args, **kwargs) + return new_method diff --git a/mindspore/lite/CMakeLists.txt b/mindspore/lite/CMakeLists.txt index 76808d7506..aff588fc5e 100644 --- a/mindspore/lite/CMakeLists.txt +++ b/mindspore/lite/CMakeLists.txt @@ -13,6 +13,7 @@ include_directories(${TOP_DIR}) include_directories(${CORE_DIR}) include_directories(${CCSRC_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/kernel/arm) include_directories(${TOP_DIR}/third_party) include_directories(${TOP_DIR}/third_party/flatbuffers/include) @@ -65,10 +66,10 @@ endif() set(ANF_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../core/ir/meta_tensor.cc - ${CCSRC_DIR}/gvar/logging_level.cc - ${CCSRC_DIR}/gvar/typeid_manager.cc + ${CORE_DIR}/gvar/logging_level.cc + ${CORE_DIR}/gvar/typeid_manager.cc ${CMAKE_CURRENT_SOURCE_DIR}/../core/base/base.cc - ${CMAKE_CURRENT_SOURCE_DIR}/../core/utils/log_adapter.cc + ${CMAKE_CURRENT_SOURCE_DIR}/src/common/log_adapter.cc ) if (BUILD_CONVERTER) if (PLATFORM_ARM64 OR PLATFORM_ARM32) @@ -133,6 +134,10 @@ if (BUILD_MINDDATA) set(OpenCV_DIR ${TOP_DIR}/third_party/opencv/build) find_package(OpenCV REQUIRED) include_directories(${OpenCV_INCLUDE_DIRS}) + # json + if (NOT BUILD_CONVERTER) + include(${TOP_DIR}/cmake/external_libs/json.cmake) + endif() # eigen include_directories(${TOP_DIR}/third_party/eigen/) # jpeg-turbo diff --git a/mindspore/lite/include/context.h b/mindspore/lite/include/context.h index 02b6cd04e2..2e5dd1944a 100644 --- a/mindspore/lite/include/context.h +++ b/mindspore/lite/include/context.h @@ -64,11 +64,17 @@ class MS_API Context { /// \brief Destructor of MindSpore Lite Context. virtual ~Context(); + void InferShapeInterrupt() { + infer_shape_interrupt_ = true; + } + public: DeviceContext device_ctx_{DT_CPU}; int thread_num_ = 2; /**< thread number config for thread pool */ std::shared_ptr allocator = nullptr; CpuBindMode cpu_bind_mode_ = MID_CPU; + bool infer_shape_interrupt_ = false; + bool running_ = false; }; } // namespace mindspore::lite #endif // MINDSPORE_LITE_INCLUDE_CONTEXT_H_ diff --git a/mindspore/lite/include/errorcode.h b/mindspore/lite/include/errorcode.h index 2cdd4659de..c7c8224e07 100644 --- a/mindspore/lite/include/errorcode.h +++ b/mindspore/lite/include/errorcode.h @@ -48,8 +48,11 @@ constexpr int RET_OP_EXECUTE_FAILURE = -304; /**< Failed to execution operator. /* Tensor error code, range: [-401,-500] */ constexpr int RET_FORMAT_ERR = -401; /**< Failed to checking tensor format. */ + +/* InferShape error code, range: [-501,-600] */ +constexpr int RET_INFER_ERR = -501; /**< Failed to infer shape. */ +constexpr int RET_INFER_INVALID = -502; /**< Invalid to infer shape before runtime. */ } // namespace lite } // namespace mindspore #endif // MINDSPORE_LITE_INCLUDE_ERRORCODE_H_ - diff --git a/mindspore/lite/include/lite_session.h b/mindspore/lite/include/lite_session.h index ea762f0f60..80fec03cf5 100644 --- a/mindspore/lite/include/lite_session.h +++ b/mindspore/lite/include/lite_session.h @@ -20,6 +20,7 @@ #include #include #include +#include #include "include/ms_tensor.h" #include "include/model.h" #include "include/context.h" @@ -85,8 +86,8 @@ class MS_API LiteSession { /// \brief Get output MindSpore Lite MSTensors of model. /// - /// \return A vector of MindSpore Lite MSTensor. - virtual std::vector GetOutputs() const = 0; + /// \return A map of output node name and MindSpore Lite MSTensor. + virtual std::unordered_map> GetOutputs() const = 0; /// \brief Get output MindSpore Lite MSTensors of model by node name. /// diff --git a/mindspore/lite/include/model.h b/mindspore/lite/include/model.h index 5000d8a1d5..5813caeca8 100644 --- a/mindspore/lite/include/model.h +++ b/mindspore/lite/include/model.h @@ -45,7 +45,7 @@ class MS_API Model { /// \param[in] size Define bytes numbers of model buffer. /// /// \return Pointer of MindSpore Lite Model. - static std::shared_ptr Import(const char *model_buf, size_t size); + static Model *Import(const char *model_buf, size_t size); /// \brief Constructor of MindSpore Lite Model using default value for parameters. /// @@ -53,7 +53,7 @@ class MS_API Model { Model() = default; /// \brief Destructor of MindSpore Lite Model. - virtual ~Model() = default; + virtual ~Model(); /// \brief Get MindSpore Lite Primitive by name. /// @@ -70,13 +70,13 @@ class MS_API Model { /// \brief Get MindSpore Lite ModelImpl. /// /// \return A pointer of MindSpore Lite ModelImpl. - std::shared_ptr model_impl(); + ModelImpl *model_impl(); /// \brief Free MetaGraph in MindSpore Lite Model. void FreeMetaGraph(); protected: - std::shared_ptr model_impl_ = nullptr; + ModelImpl *model_impl_ = nullptr; }; /// \brief ModelBuilder defined by MindSpore Lite. diff --git a/mindspore/lite/java/src/java/cn/huawei/mindspore/DataType.java b/mindspore/lite/java/src/java/cn/huawei/mindspore/DataType.java new file mode 100644 index 0000000000..69ce2c9725 --- /dev/null +++ b/mindspore/lite/java/src/java/cn/huawei/mindspore/DataType.java @@ -0,0 +1,21 @@ +package cn.huawei.mindspore; + +public class DataType { + public static final int kNumberTypeBool = 30; + public static final int kNumberTypeInt = 31; + public static final int kNumberTypeInt8 = 32; + public static final int kNumberTypeInt16 = 33; + public static final int kNumberTypeInt32 = 34; + public static final int kNumberTypeInt64 = 35; + public static final int kNumberTypeUInt = 36; + public static final int kNumberTypeUInt8 = 37; + public static final int kNumberTypeUInt16 = 38; + public static final int kNumberTypeUint32 = 39; + public static final int kNumberTypeUInt64 = 40; + public static final int kNumberTypeFloat = 41; + public static final int kNumberTypeFloat16 = 42; + public static final int kNumberTypeFloat32 = 43; + public static final int kNumberTypeFloat64 = 44; + + public static native int elementSize(int elementType); +} diff --git a/mindspore/lite/java/src/java/cn/huawei/mindspore/LiteSession.java b/mindspore/lite/java/src/java/cn/huawei/mindspore/LiteSession.java new file mode 100644 index 0000000000..02985aa0ea --- /dev/null +++ b/mindspore/lite/java/src/java/cn/huawei/mindspore/LiteSession.java @@ -0,0 +1,114 @@ +package cn.huawei.mindspore; + +import cn.huawei.mindspore.context.Context; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class LiteSession { + static { + System.loadLibrary("mindspore-lite-jni"); + } + + private long sessionPtr; + + LiteSession() { + this.sessionPtr = 0; + } + + public boolean init(Context context) { + this.sessionPtr = createSession(context.getContextPtr()); + return this.sessionPtr != 0; + } + + public long getSessionPtr() { + return sessionPtr; + } + + public void bindThread(boolean if_bind) { + this.bindThread(this.sessionPtr, if_bind); + } + + public boolean compileGraph(Model model) { + return this.compileGraph(this.sessionPtr, model.getModelPtr()); + } + + public boolean runGraph() { + return this.runGraph(this.sessionPtr); + } + + public List getInputs() { + List ret = this.getInputs(this.sessionPtr); + ArrayList tensors = new ArrayList(); + for (Long ms_tensor_addr : ret) { + MSTensor msTensor = new MSTensor(ms_tensor_addr); + tensors.add(msTensor); + } + return tensors; + } + + public List getInputsByName(String nodeName) { + List ret = this.getInputsByName(this.sessionPtr, nodeName); + ArrayList tensors = new ArrayList<>(); + for (Long msTensorAddr : ret) { + MSTensor msTensor = new MSTensor(msTensorAddr); + tensors.add(msTensor); + } + return tensors; + } + + public Map> getOutputs() { + Map> ret = this.getOutputs(this.sessionPtr); + Map> tensorMap = new HashMap<>(); + Set>> entrySet = ret.entrySet(); + for (Map.Entry> entry : entrySet) { + String name = entry.getKey(); + List msTensorAddrs = entry.getValue(); + ArrayList msTensors = new ArrayList<>(); + for (Long msTensorAddr : msTensorAddrs) { + MSTensor msTensor = new MSTensor(msTensorAddr); + msTensors.add(msTensor); + } + tensorMap.put(name, msTensors); + } + return tensorMap; + } + + public List getOutputsByName(String nodeName) { + List ret = this.getOutputsByName(this.sessionPtr, nodeName); + ArrayList tensors = new ArrayList<>(); + for (Long msTensorAddr : ret) { + MSTensor msTensor = new MSTensor(msTensorAddr); + tensors.add(msTensor); + } + return tensors; + } + + public void free() { + this.free(this.sessionPtr); + this.sessionPtr = 0; + } + + private native long createSession(long contextPtr); + + private native boolean compileGraph(long sessionPtr, long modelPtr); + + private native void bindThread(long sessionPtr, boolean if_bind); + + private native boolean runGraph(long sessionPtr); + + private native List getInputs(long sessionPtr); + + private native List getInputsByName(long sessionPtr, String nodeName); + + private native Map> getOutputs(long sessionPtr); + + private native List getOutputsByName(long sessionPtr, String nodeName); + + private native void free(long sessionPtr); +} diff --git a/mindspore/lite/java/src/java/cn/huawei/mindspore/MSTensor.java b/mindspore/lite/java/src/java/cn/huawei/mindspore/MSTensor.java new file mode 100644 index 0000000000..e4f7ec44c2 --- /dev/null +++ b/mindspore/lite/java/src/java/cn/huawei/mindspore/MSTensor.java @@ -0,0 +1,75 @@ +package cn.huawei.mindspore; + +public class MSTensor { + private long tensorPtr; + + public MSTensor() { + this.tensorPtr = 0; + } + + public MSTensor(long tensorPtr) { + this.tensorPtr = tensorPtr; + } + + public boolean init (int dataType, int[] shape) { + this.tensorPtr = createMSTensor(dataType, shape, shape.length); + return this.tensorPtr != 0; + } + + public int[] getShape() { + return this.getShape(this.tensorPtr); + } + + public void setShape(int[] shape) { + this.setShape(this.tensorPtr, shape, shape.length); + } + + public int getDataType() { + return this.getDataType(this.tensorPtr); + } + + public void setDataType(int dataType) { + this.setDataType(this.tensorPtr, dataType); + } + + public byte[] getData() { + return this.getData(this.tensorPtr); + } + + public void setData(byte[] data) { + this.setData(this.tensorPtr, data, data.length); + } + + public long size() { + return this.size(this.tensorPtr); + } + + public int elementsNum() { + return this.elementsNum(this.tensorPtr); + } + + public void free() { + this.free(this.tensorPtr); + this.tensorPtr = 0; + } + + private native long createMSTensor(int dataType, int[] shape, int shapeLen); + + private native int[] getShape(long tensorPtr); + + private native boolean setShape(long tensorPtr, int[] shape, int shapeLen); + + private native int getDataType(long tensorPtr); + + private native boolean setDataType(long tensorPtr, int dataType); + + private native byte[] getData(long tensorPtr); + + private native boolean setData(long tensorPtr, byte[] data, long dataLen); + + private native long size(long tensorPtr); + + private native int elementsNum(long tensorPtr); + + private native void free(long tensorPtr); +} diff --git a/mindspore/lite/java/src/java/cn/huawei/mindspore/Model.java b/mindspore/lite/java/src/java/cn/huawei/mindspore/Model.java new file mode 100644 index 0000000000..6eb1d1c8d9 --- /dev/null +++ b/mindspore/lite/java/src/java/cn/huawei/mindspore/Model.java @@ -0,0 +1,76 @@ +package cn.huawei.mindspore; + +import android.content.Context; +import android.content.res.AssetFileDescriptor; +import android.util.Log; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; + +public class Model { + static { + System.loadLibrary("mindspore-lite-jni"); + } + + private long modelPtr; + + public Model() { + this.modelPtr = 0; + } + + public long getModelPtr() { + return modelPtr; + } + + public void setModelPtr(long modelPtr) { + this.modelPtr = modelPtr; + } + + public boolean loadModel(Context context, String modelName) { + FileInputStream fis = null; + AssetFileDescriptor fileDescriptor = null; + boolean ret = false; + try { + fileDescriptor = context.getAssets().openFd(modelName); + fis = new FileInputStream(fileDescriptor.getFileDescriptor()); + FileChannel fileChannel = fis.getChannel(); + long startOffset = fileDescriptor.getStartOffset(); + long declaredLen = fileDescriptor.getDeclaredLength(); + MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLen); + this.modelPtr = loadModel(buffer); + ret = this.modelPtr != 0; + } catch (IOException e) { + this.modelPtr = 0; + Log.e("MS_LITE", "Load model failed: " + e.getMessage()); + ret = false; + } finally { + if (null != fis) { + try { + fis.close(); + } catch (IOException e) { + Log.e("MS_LITE", "Close file failed: " + e.getMessage()); + } + } + if (null != fileDescriptor) { + try { + fileDescriptor.close(); + } catch (IOException e) { + Log.e("MS_LITE", "Close fileDescriptor failed: " + e.getMessage()); + } + } + } + return ret; + } + + public void free() { + this.free(this.modelPtr); + this.modelPtr = 0; + } + + private native long loadModel(MappedByteBuffer buffer); + + private native void free(long modelPtr); +} diff --git a/mindspore/lite/java/src/java/cn/huawei/mindspore/context/Context.java b/mindspore/lite/java/src/java/cn/huawei/mindspore/context/Context.java new file mode 100644 index 0000000000..125fcc581f --- /dev/null +++ b/mindspore/lite/java/src/java/cn/huawei/mindspore/context/Context.java @@ -0,0 +1,43 @@ +package cn.huawei.mindspore.context; + +public class Context { + private long contextPtr; + + public Context() { + this.contextPtr = 0; + } + + public long getContextPtr() { + return contextPtr; + } + + public void setContextPtr(long contextPtr) { + this.contextPtr = contextPtr; + } + + public boolean init(int deviceType, int threadNum, int cpuBindMode) { + this.contextPtr = createContext(deviceType, threadNum, cpuBindMode); + return this.contextPtr != 0; + } + + public boolean init(int deviceType, int threadNum) { + return init(deviceType, threadNum, CpuBindMode.MID_CPU); + } + + public boolean init(int deviceType) { + return init(deviceType, 2); + } + + public boolean init() { + return init(DeviceType.DT_CPU); + } + + public void free() { + this.free(this.contextPtr); + this.contextPtr = 0; + } + + private native long createContext(int deviceType, int threadNum, int cpuBindMode); + + private native void free(long contextPtr); +} diff --git a/mindspore/lite/java/src/java/cn/huawei/mindspore/context/CpuBindMode.java b/mindspore/lite/java/src/java/cn/huawei/mindspore/context/CpuBindMode.java new file mode 100644 index 0000000000..3c6e7db52e --- /dev/null +++ b/mindspore/lite/java/src/java/cn/huawei/mindspore/context/CpuBindMode.java @@ -0,0 +1,7 @@ +package cn.huawei.mindspore.context; + +public class CpuBindMode { + public static final int MID_CPU = -1; + public static final int HIGHER_CPU = 1; + public static final int NO_BIND = 0; +} diff --git a/mindspore/lite/java/src/java/cn/huawei/mindspore/context/DeviceType.java b/mindspore/lite/java/src/java/cn/huawei/mindspore/context/DeviceType.java new file mode 100644 index 0000000000..13367f5fcc --- /dev/null +++ b/mindspore/lite/java/src/java/cn/huawei/mindspore/context/DeviceType.java @@ -0,0 +1,7 @@ +package cn.huawei.mindspore.context; + +public class DeviceType { + public static final int DT_CPU = 0; + public static final int DT_GPU = 1; + public static final int DT_NPU = 2; +} diff --git a/mindspore/lite/java/src/native/CMakeLists.txt b/mindspore/lite/java/src/native/CMakeLists.txt new file mode 100644 index 0000000000..fefdde64b9 --- /dev/null +++ b/mindspore/lite/java/src/native/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.4.1) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) +link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}) + +add_library(mindspore-lite-jni SHARED + ${CMAKE_CURRENT_SOURCE_DIR}/src/common/ms_log.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/common/jni_utils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/model.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/context.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/ms_tensor.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/runtime/lite_session.cpp + ) + +find_library(log-lib log) + +target_link_libraries(mindspore-lite-jni mindspore-lite ${log-lib} ) \ No newline at end of file diff --git a/mindspore/lite/java/src/native/common/jni_utils.cpp b/mindspore/lite/java/src/native/common/jni_utils.cpp new file mode 100644 index 0000000000..3320ea7b17 --- /dev/null +++ b/mindspore/lite/java/src/native/common/jni_utils.cpp @@ -0,0 +1,37 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "common/jni_utils.h" +#include + +char *JstringToChar(JNIEnv *env, jstring jstr) { + char *rtn = NULL; + jclass clsstring = env->FindClass("java/lang/String"); + jstring strencode = env->NewStringUTF("GB2312"); + jmethodID mid = env->GetMethodID(clsstring, "getBytes", "(Ljava/lang/String;)[B"); + jbyteArray barr = (jbyteArray)env->CallObjectMethod(jstr, mid, strencode); + jsize alen = env->GetArrayLength(barr); + jbyte *ba = env->GetByteArrayElements(barr, JNI_FALSE); + if (alen > 0) { + rtn = new char[alen + 1]; + memcpy(rtn, ba, alen); + rtn[alen] = 0; + } + env->ReleaseByteArrayElements(barr, ba, 0); + return rtn; +} diff --git a/mindspore/lite/java/src/native/common/jni_utils.h b/mindspore/lite/java/src/native/common/jni_utils.h new file mode 100644 index 0000000000..6f99e950a2 --- /dev/null +++ b/mindspore/lite/java/src/native/common/jni_utils.h @@ -0,0 +1,26 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_JAVA_SRC_COMMON_JNI_UTILS_H +#define MINDSPORE_LITE_JAVA_SRC_COMMON_JNI_UTILS_H + +#include + +char *JstringToChar(JNIEnv *env, jstring jstr); + +#endif // MINDSPORE_LITE_JAVA_SRC_COMMON_JNI_UTILS_H diff --git a/mindspore/lite/java/src/native/common/ms_log.cpp b/mindspore/lite/java/src/native/common/ms_log.cpp new file mode 100644 index 0000000000..0dae12742f --- /dev/null +++ b/mindspore/lite/java/src/native/common/ms_log.cpp @@ -0,0 +1,19 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "common/ms_log.h" diff --git a/mindspore/lite/java/src/native/common/ms_log.h b/mindspore/lite/java/src/native/common/ms_log.h new file mode 100644 index 0000000000..1347ab077c --- /dev/null +++ b/mindspore/lite/java/src/native/common/ms_log.h @@ -0,0 +1,36 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_JAVA_SRC_COMMON_MS_LOG_H +#define MINDSPORE_LITE_JAVA_SRC_COMMON_MS_LOG_H + +#include +#include + +#define TAG "MS_LITE" + +#define MS_LOGD(fmt, args...) \ + { __android_log_print(ANDROID_LOG_DEBUG, TAG, "|%d|%s[%d]|: " fmt, getpid(), __func__, __LINE__, ##args); } + +#define MS_LOGE(fmt, args...) \ + { __android_log_print(ANDROID_LOG_ERROR, TAG, "|%d|%s[%d]|: " fmt, getpid(), __func__, __LINE__, ##args); } + +#define MS_LOGI(fmt, args...) \ + { __android_log_print(ANDROID_LOG_INFO, TAG, "|%d|%s[%d]|: " fmt, getpid(), __func__, __LINE__, ##args); } + +#endif // MINDSPORE_LITE_JAVA_SRC_COMMON_MS_LOG_H diff --git a/mindspore/lite/java/src/native/runtime/context.cpp b/mindspore/lite/java/src/native/runtime/context.cpp new file mode 100644 index 0000000000..2e5b55d7f9 --- /dev/null +++ b/mindspore/lite/java/src/native/runtime/context.cpp @@ -0,0 +1,69 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "common/ms_log.h" +#include "include/context.h" + +extern "C" JNIEXPORT jlong JNICALL Java_cn_huawei_mindspore_context_Context_createContext(JNIEnv *env, jobject thiz, + jint device_type, + jint thread_num, + jint cpu_bind_mode) { + auto *context = new mindspore::lite::Context(); + switch (device_type) { + case 0: + context->device_ctx_.type = mindspore::lite::DT_CPU; + break; + case 1: + context->device_ctx_.type = mindspore::lite::DT_GPU; + break; + case 2: + context->device_ctx_.type = mindspore::lite::DT_NPU; + break; + default: + MS_LOGE("Invalid device_type : %d", device_type); + return (jlong)context; + } + switch (cpu_bind_mode) { + case -1: + context->cpu_bind_mode_ = mindspore::lite::MID_CPU; + break; + case 0: + context->cpu_bind_mode_ = mindspore::lite::NO_BIND; + break; + case 1: + context->cpu_bind_mode_ = mindspore::lite::HIGHER_CPU; + break; + default: + MS_LOGE("Invalid cpu_bind_mode : %d", cpu_bind_mode); + return (jlong)context; + } + context->thread_num_ = thread_num; + return (jlong)context; +} + +extern "C" JNIEXPORT void JNICALL Java_cn_huawei_mindspore_context_Context_free(JNIEnv *env, jobject thiz, + jlong context_ptr) { + auto *pointer = reinterpret_cast(context_ptr); + if (pointer == nullptr) { + MS_LOGE("Context pointer from java is nullptr"); + return; + } + auto *lite_context_ptr = static_cast(pointer); + delete (lite_context_ptr); +} diff --git a/mindspore/lite/java/src/native/runtime/lite_session.cpp b/mindspore/lite/java/src/native/runtime/lite_session.cpp new file mode 100644 index 0000000000..0b3806e400 --- /dev/null +++ b/mindspore/lite/java/src/native/runtime/lite_session.cpp @@ -0,0 +1,196 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "common/ms_log.h" +#include "common/jni_utils.h" +#include "include/lite_session.h" +#include "include/errorcode.h" + +extern "C" JNIEXPORT jlong JNICALL Java_cn_huawei_mindspore_LiteSession_createSession(JNIEnv *env, jobject thiz, + jlong context_ptr) { + auto *pointer = reinterpret_cast(context_ptr); + if (pointer == nullptr) { + MS_LOGE("Context pointer from java is nullptr"); + return jlong(nullptr); + } + auto *lite_context_ptr = static_cast(pointer); + auto session = mindspore::session::LiteSession::CreateSession(lite_context_ptr); + if (session == nullptr) { + MS_LOGE("CreateSession failed"); + return jlong(nullptr); + } + return jlong(session); +} + +extern "C" JNIEXPORT jboolean JNICALL Java_cn_huawei_mindspore_LiteSession_compileGraph(JNIEnv *env, jobject thiz, + jlong session_ptr, + jlong model_ptr) { + auto *session_pointer = reinterpret_cast(session_ptr); + if (session_pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return (jboolean) false; + } + auto *lite_session_ptr = static_cast(session_pointer); + auto *model_pointer = reinterpret_cast(model_ptr); + if (model_pointer == nullptr) { + MS_LOGE("Model pointer from java is nullptr"); + return (jboolean) false; + } + auto *lite_model_ptr = static_cast(model_pointer); + + auto ret = lite_session_ptr->CompileGraph(lite_model_ptr); + return (jboolean)(ret == mindspore::lite::RET_OK); +} + +extern "C" JNIEXPORT void JNICALL Java_cn_huawei_mindspore_LiteSession_bindThread(JNIEnv *env, jobject thiz, + jlong session_ptr, jboolean if_bind) { + auto *pointer = reinterpret_cast(session_ptr); + if (pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return; + } + auto *lite_session_ptr = static_cast(pointer); + lite_session_ptr->BindThread(if_bind); +} + +extern "C" JNIEXPORT jboolean JNICALL Java_cn_huawei_mindspore_LiteSession_runGraph(JNIEnv *env, jobject thiz, + jlong session_ptr) { + auto *pointer = reinterpret_cast(session_ptr); + if (pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return (jboolean) false; + } + auto *lite_session_ptr = static_cast(pointer); + auto ret = lite_session_ptr->RunGraph(); + return (jboolean)(ret == mindspore::lite::RET_OK); +} + +extern "C" JNIEXPORT jobject JNICALL Java_cn_huawei_mindspore_LiteSession_getInputs(JNIEnv *env, jobject thiz, + jlong session_ptr) { + jclass array_list = env->FindClass("java/util/ArrayList"); + jmethodID array_list_construct = env->GetMethodID(array_list, "", "()V"); + jobject ret = env->NewObject(array_list, array_list_construct); + jmethodID array_list_add = env->GetMethodID(array_list, "add", "(Ljava/lang/Object;)Z"); + + jclass long_object = env->FindClass("java/lang/Long"); + jmethodID long_object_construct = env->GetMethodID(long_object, "", "(J)V"); + auto *pointer = reinterpret_cast(session_ptr); + if (pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return ret; + } + auto *lite_session_ptr = static_cast(pointer); + auto inputs = lite_session_ptr->GetInputs(); + for (auto input : inputs) { + jobject tensor_addr = env->NewObject(long_object, long_object_construct, jlong(input)); + env->CallBooleanMethod(ret, array_list_add, tensor_addr); + } + return ret; +} + +extern "C" JNIEXPORT jobject JNICALL Java_cn_huawei_mindspore_LiteSession_getInputsByName(JNIEnv *env, jobject thiz, + jlong session_ptr, + jstring node_name) { + jclass array_list = env->FindClass("java/util/ArrayList"); + jmethodID array_list_construct = env->GetMethodID(array_list, "", "()V"); + jobject ret = env->NewObject(array_list, array_list_construct); + jmethodID array_list_add = env->GetMethodID(array_list, "add", "(Ljava/lang/Object;)Z"); + + jclass long_object = env->FindClass("java/lang/Long"); + jmethodID long_object_construct = env->GetMethodID(long_object, "", "(J)V"); + auto *pointer = reinterpret_cast(session_ptr); + if (pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return ret; + } + auto *lite_session_ptr = static_cast(pointer); + auto inputs = lite_session_ptr->GetInputsByName(JstringToChar(env, node_name)); + for (auto input : inputs) { + jobject tensor_addr = env->NewObject(long_object, long_object_construct, jlong(input)); + env->CallBooleanMethod(ret, array_list_add, tensor_addr); + } + return ret; +} + +extern "C" JNIEXPORT jobject JNICALL Java_cn_huawei_mindspore_LiteSession_getOutputs(JNIEnv *env, jobject thiz, + jlong session_ptr) { + jclass hash_map_clazz = env->FindClass("java/util/HashMap"); + jmethodID hash_map_construct = env->GetMethodID(hash_map_clazz, "", "()V"); + jobject hash_map = env->NewObject(hash_map_clazz, hash_map_construct); + jmethodID hash_map_put = + env->GetMethodID(hash_map_clazz, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); + auto *pointer = reinterpret_cast(session_ptr); + if (pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return hash_map; + } + auto *lite_session_ptr = static_cast(pointer); + auto outputs = lite_session_ptr->GetOutputs(); + jclass long_object = env->FindClass("java/lang/Long"); + jmethodID long_object_construct = env->GetMethodID(long_object, "", "(J)V"); + jclass array_list = env->FindClass("java/util/ArrayList"); + jmethodID array_list_construct = env->GetMethodID(array_list, "", "()V"); + jmethodID array_list_add = env->GetMethodID(array_list, "add", "(Ljava/lang/Object;)Z"); + for (auto output_iter : outputs) { + auto node_name = output_iter.first; + auto ms_tensors = output_iter.second; + jobject vec = env->NewObject(array_list, array_list_construct); + for (auto ms_tensor : ms_tensors) { + jobject tensor_addr = env->NewObject(long_object, long_object_construct, jlong(ms_tensor)); + env->CallBooleanMethod(vec, array_list_add, tensor_addr); + } + env->CallObjectMethod(hash_map, hash_map_put, env->NewStringUTF(node_name.c_str()), vec); + } + return hash_map; +} + +extern "C" JNIEXPORT jobject JNICALL Java_cn_huawei_mindspore_LiteSession_getOutputsByName(JNIEnv *env, jobject thiz, + jlong session_ptr, + jstring node_name) { + jclass array_list = env->FindClass("java/util/ArrayList"); + jmethodID array_list_construct = env->GetMethodID(array_list, "", "()V"); + jobject ret = env->NewObject(array_list, array_list_construct); + jmethodID array_list_add = env->GetMethodID(array_list, "add", "(Ljava/lang/Object;)Z"); + + jclass long_object = env->FindClass("java/lang/Long"); + jmethodID long_object_construct = env->GetMethodID(long_object, "", "(J)V"); + auto *pointer = reinterpret_cast(session_ptr); + if (pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return ret; + } + auto *lite_session_ptr = static_cast(pointer); + auto inputs = lite_session_ptr->GetOutputsByName(JstringToChar(env, node_name)); + for (auto input : inputs) { + jobject tensor_addr = env->NewObject(long_object, long_object_construct, jlong(input)); + env->CallBooleanMethod(ret, array_list_add, tensor_addr); + } + return ret; +} + +extern "C" JNIEXPORT void JNICALL Java_cn_huawei_mindspore_LiteSession_free(JNIEnv *env, jobject thiz, + jlong session_ptr) { + auto *pointer = reinterpret_cast(session_ptr); + if (pointer == nullptr) { + MS_LOGE("Session pointer from java is nullptr"); + return; + } + auto *lite_session_ptr = static_cast(pointer); + delete (lite_session_ptr); +} diff --git a/mindspore/lite/java/src/native/runtime/model.cpp b/mindspore/lite/java/src/native/runtime/model.cpp new file mode 100644 index 0000000000..589f51faa6 --- /dev/null +++ b/mindspore/lite/java/src/native/runtime/model.cpp @@ -0,0 +1,50 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "common/ms_log.h" +#include "include/model.h" + +extern "C" JNIEXPORT jlong JNICALL Java_cn_huawei_mindspore_Model_loadModel(JNIEnv *env, jobject thiz, jobject buffer) { + MS_LOGD("Start getting buffer from java"); + if (buffer == nullptr) { + MS_LOGE("Buffer from java is nullptr"); + return reinterpret_cast(nullptr); + } + jlong buffer_len = env->GetDirectBufferCapacity(buffer); + auto *model_buffer = static_cast(env->GetDirectBufferAddress(buffer)); + + MS_LOGD("Start Loading model"); + auto model = mindspore::lite::Model::Import(model_buffer, buffer_len); + // env->DeleteLocalRef(*(jobject *)model_buffer); + if (model == nullptr) { + MS_LOGE("Import model failed"); + return reinterpret_cast(nullptr); + } + return reinterpret_cast(model); +} + +extern "C" JNIEXPORT void JNICALL Java_cn_huawei_mindspore_Model_free(JNIEnv *env, jobject thiz, jlong model_ptr) { + auto *pointer = reinterpret_cast(model_ptr); + if (pointer == nullptr) { + MS_LOGE("Model pointer from java is nullptr"); + return; + } + auto *lite_model_ptr = static_cast(pointer); + delete (lite_model_ptr); +} diff --git a/mindspore/lite/java/src/native/runtime/ms_tensor.cpp b/mindspore/lite/java/src/native/runtime/ms_tensor.cpp new file mode 100644 index 0000000000..517962570f --- /dev/null +++ b/mindspore/lite/java/src/native/runtime/ms_tensor.cpp @@ -0,0 +1,172 @@ +/** + * This is the C++ adaptation and derivative work of Myia (https://github.com/mila-iqia/myia/). + * + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "common/ms_log.h" +#include "include/ms_tensor.h" +#include "ir/dtype/type_id.h" + +extern "C" JNIEXPORT jlong JNICALL Java_cn_huawei_mindspore_MSTensor_createMSTensor(JNIEnv *env, jobject thiz, + jint data_type, jintArray shape, + jint shape_len) { + jboolean is_copy = false; + jint *local_shape_arr = env->GetIntArrayElements(shape, &is_copy); + std::vector local_shape(shape_len); + for (size_t i = 0; i < shape_len; i++) { + local_shape[i] = local_shape_arr[i]; + } + auto *ms_tensor = mindspore::tensor::MSTensor::CreateTensor(mindspore::TypeId(data_type), local_shape); + env->ReleaseIntArrayElements(shape, local_shape_arr, JNI_ABORT); + if (ms_tensor == nullptr) { + MS_LOGE("CreateTensor failed"); + return reinterpret_cast(nullptr); + } + return reinterpret_cast(ms_tensor); +} + +extern "C" JNIEXPORT jintArray JNICALL Java_cn_huawei_mindspore_MSTensor_getShape(JNIEnv *env, jobject thiz, + jlong tensor_ptr) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return env->NewIntArray(0); + } + auto *ms_tensor_ptr = static_cast(pointer); + auto local_shape = ms_tensor_ptr->shape(); + auto shape_size = local_shape.size(); + jintArray shape = env->NewIntArray(shape_size); + auto *tmp = new jint[shape_size]; + for (size_t i = 0; i < shape_size; i++) { + tmp[i] = local_shape.at(i); + } + delete[](tmp); + env->SetIntArrayRegion(shape, 0, shape_size, tmp); + return shape; +} + +extern "C" JNIEXPORT jboolean JNICALL Java_cn_huawei_mindspore_MSTensor_setShape(JNIEnv *env, jobject thiz, + jlong tensor_ptr, jintArray shape, + jint shape_len) { + jboolean is_copy = false; + jint *local_shape_arr = env->GetIntArrayElements(shape, &is_copy); + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return static_cast(false); + } + auto *ms_tensor_ptr = static_cast(pointer); + std::vector local_shape(shape_len); + for (size_t i = 0; i < shape_len; i++) { + local_shape[i] = local_shape_arr[i]; + } + auto ret = ms_tensor_ptr->set_shape(local_shape); + return ret == shape_len; +} + +extern "C" JNIEXPORT jint JNICALL Java_cn_huawei_mindspore_MSTensor_getDataType(JNIEnv *env, jobject thiz, + jlong tensor_ptr) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return static_cast(false); + } + auto *ms_tensor_ptr = static_cast(pointer); + return jint(ms_tensor_ptr->data_type()); +} + +extern "C" JNIEXPORT jboolean JNICALL Java_cn_huawei_mindspore_MSTensor_setDataType(JNIEnv *env, jobject thiz, + jlong tensor_ptr, jint data_type) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return static_cast(false); + } + auto *ms_tensor_ptr = static_cast(pointer); + auto ret = ms_tensor_ptr->set_data_type(mindspore::TypeId(data_type)); + return ret == data_type; +} + +extern "C" JNIEXPORT jbyteArray JNICALL Java_cn_huawei_mindspore_MSTensor_getData(JNIEnv *env, jobject thiz, + jlong tensor_ptr) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return env->NewByteArray(0); + } + auto *ms_tensor_ptr = static_cast(pointer); + auto *local_data = static_cast(ms_tensor_ptr->MutableData()); + if (local_data == nullptr) { + MS_LOGD("Tensor has no data"); + return env->NewByteArray(0); + } + auto local_data_size = ms_tensor_ptr->Size(); + auto ret = env->NewByteArray(local_data_size); + env->SetByteArrayRegion(ret, 0, local_data_size, local_data); + return ret; +} + +extern "C" JNIEXPORT jboolean JNICALL Java_cn_huawei_mindspore_MSTensor_setData(JNIEnv *env, jobject thiz, + jlong tensor_ptr, jbyteArray data, + jlong data_len) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return static_cast(false); + } + auto *ms_tensor_ptr = static_cast(pointer); + if (data_len != ms_tensor_ptr->Size()) { + MS_LOGE("data_len(%ld) not equal to Size of ms_tensor(%zu)", data_len, ms_tensor_ptr->Size()); + return static_cast(false); + } + jboolean is_copy = false; + auto *data_arr = env->GetByteArrayElements(data, &is_copy); + auto *local_data = ms_tensor_ptr->MutableData(); + memcpy(local_data, data_arr, data_len); + return static_cast(true); +} + +extern "C" JNIEXPORT jlong JNICALL Java_cn_huawei_mindspore_MSTensor_size(JNIEnv *env, jobject thiz, jlong tensor_ptr) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return 0; + } + auto *ms_tensor_ptr = static_cast(pointer); + return ms_tensor_ptr->Size(); +} + +extern "C" JNIEXPORT jint JNICALL Java_cn_huawei_mindspore_MSTensor_elementsNum(JNIEnv *env, jobject thiz, + jlong tensor_ptr) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return 0; + } + auto *ms_tensor_ptr = static_cast(pointer); + return ms_tensor_ptr->ElementsNum(); +} + +extern "C" JNIEXPORT void JNICALL Java_cn_huawei_mindspore_MSTensor_free(JNIEnv *env, jobject thiz, jlong tensor_ptr) { + auto *pointer = reinterpret_cast(tensor_ptr); + if (pointer == nullptr) { + MS_LOGE("Tensor pointer from java is nullptr"); + return; + } + auto *ms_tensor_ptr = static_cast(pointer); + delete (ms_tensor_ptr); +} diff --git a/mindspore/lite/minddata/CMakeLists.txt b/mindspore/lite/minddata/CMakeLists.txt index fcf6d721a9..fa76960560 100644 --- a/mindspore/lite/minddata/CMakeLists.txt +++ b/mindspore/lite/minddata/CMakeLists.txt @@ -4,9 +4,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wno-deprecated-declarations") set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb") -if (CMAKE_BUILD_TYPE EQUAL "DEBUG") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s") -endif() +set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS} -s") AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/core MINDDATA_CORE_SRC_FILES) list(REMOVE_ITEM MINDDATA_CORE_SRC_FILES "${MINDDATA_DIR}/core/client.cc") @@ -33,7 +31,7 @@ add_library(minddata-lite SHARED ${MINDDATA_DIR}/util/path.cc ${MINDDATA_DIR}/api/transforms.cc ${CORE_DIR}/utils/log_adapter.cc - ${CCSRC_DIR}/gvar/logging_level.cc + ${CORE_DIR}/gvar/logging_level.cc ) target_link_libraries(minddata-lite diff --git a/mindspore/lite/schema/model.fbs b/mindspore/lite/schema/model.fbs index cb1bad7031..6d00ff472e 100644 --- a/mindspore/lite/schema/model.fbs +++ b/mindspore/lite/schema/model.fbs @@ -189,7 +189,9 @@ union PrimitiveType { ActivationGrad, PriorBox, SpaceToBatchND, - TopKV2 + TopKV2, + Return, + MakeTuple } enum QuantType: int { diff --git a/mindspore/lite/schema/ops.fbs b/mindspore/lite/schema/ops.fbs index fe97b0fb9e..27b3b942d5 100644 --- a/mindspore/lite/schema/ops.fbs +++ b/mindspore/lite/schema/ops.fbs @@ -142,6 +142,7 @@ table SoftMax { table Activation { type: ActivationType = 0; + alpha: float = 0.2; } table ActivationGrad { type: ActivationGradType = 0; @@ -863,3 +864,9 @@ table TopKV2 { sorted : bool = true; } + +table MakeTuple { +} + +table Return { +} \ No newline at end of file diff --git a/mindspore/lite/src/CMakeLists.txt b/mindspore/lite/src/CMakeLists.txt index 8b96e731ab..85dee64691 100644 --- a/mindspore/lite/src/CMakeLists.txt +++ b/mindspore/lite/src/CMakeLists.txt @@ -23,6 +23,7 @@ endif() if (SUPPORT_TRAIN) set(ANF_SRC + ${ANF_SRC} # ${CCSRC_DIR}/common/trans.cc # ${CCSRC_DIR}/utils/lite/base_ref_utils.cc # ${CCSRC_DIR}/runtime/kernel/kernel_compiler/kernel_build_info.cc @@ -40,14 +41,17 @@ if (SUPPORT_TRAIN) set(LITE_SRC ${LITE_SRC} ${ANF_SRC} - ${PASS_SRC} - ${CMAKE_CURRENT_SOURCE_DIR}/common/anf_importer/anf_importer.cc - ${CMAKE_CURRENT_SOURCE_DIR}/common/anf_importer/import_from_meta_graph.cc - ${CMAKE_CURRENT_SOURCE_DIR}/ir/primitive_value.cc - ${CMAKE_CURRENT_SOURCE_DIR}/train/lite_kernel_runtime.cc - ${CMAKE_CURRENT_SOURCE_DIR}/train/train_session.cc - ${CMAKE_CURRENT_SOURCE_DIR}/train/model_impl.cc + # ${PASS_SRC} + # ${CMAKE_CURRENT_SOURCE_DIR}/common/anf_importer/anf_importer.cc + # ${CMAKE_CURRENT_SOURCE_DIR}/common/anf_importer/import_from_meta_graph.cc + # ${CMAKE_CURRENT_SOURCE_DIR}/ir/primitive_value.cc + # ${CMAKE_CURRENT_SOURCE_DIR}/train/lite_kernel_runtime.cc + # ${CMAKE_CURRENT_SOURCE_DIR}/train/train_session.cc + # ${CMAKE_CURRENT_SOURCE_DIR}/train/model_impl.cc + ${CMAKE_CURRENT_SOURCE_DIR}/lite_session.cc # temporary + ${CMAKE_CURRENT_SOURCE_DIR}/model_impl.cc # temporary ) + else () set(LITE_SRC ${LITE_SRC} @@ -78,11 +82,11 @@ target_link_libraries(mindspore-lite ) add_subdirectory(runtime/kernel/arm) +if (PLATFORM_ARM32 OR PLATFORM_ARM64) + target_link_libraries(mindspore-lite log) +endif() if (BUILD_MINDDATA) target_link_libraries(mindspore-lite minddata-eager minddata-lite) - if (PLATFORM_ARM32 OR PLATFORM_ARM64) - target_link_libraries(mindspore-lite log) - endif() endif () add_subdirectory(ops) diff --git a/mindspore/lite/src/common/anf_exporter/anf_exporter.cc b/mindspore/lite/src/common/anf_exporter/anf_exporter.cc index ec708411a2..a28d40d7d4 100644 --- a/mindspore/lite/src/common/anf_exporter/anf_exporter.cc +++ b/mindspore/lite/src/common/anf_exporter/anf_exporter.cc @@ -29,6 +29,7 @@ #include "src/ir/primitive_t_value.h" #include "src/ir/tensor.h" #include "src/param_value_lite.h" +#include "src/common/utils.h" namespace mindspore::lite { std::set RemoveNodeInAnfExporter{"tuple_getitem", "make_tuple"}; @@ -81,8 +82,7 @@ bool AnfExporter::RemoveIfTupleGetItem(const CNodePtr &cnode) { return false; } ValueNodePtr valueNode = utils::cast(indexNode); - mapRemoveGetItem_[tupleGetItemNode->input(1)->fullname_with_scope()] = - GetValue(valueNode->value()); + mapRemoveGetItem_[tupleGetItemNode->input(1)->fullname_with_scope()] = GetValue(valueNode->value()); } else { inputs.emplace_back(cnode->input(i)); } @@ -114,16 +114,34 @@ schema::MetaGraphT *AnfExporter::Export(const FuncGraphPtr &funcGraph) { auto metaGraphT = std::make_unique(); for (const auto &cnode : cnodes) { auto primitive = GetValueNode(cnode->input(0)); - if (primitive != nullptr && - RemoveNodeInAnfExporter.count(primitive->name()) != 0) { - continue; + if (primitive != nullptr) { + if (RemoveNodeInAnfExporter.count(primitive->name()) != 0) { + continue; + } + } else { + auto primitiveT_value = GetValueNode>(cnode->input(0)); + auto primT = primitiveT_value->GetPrimitiveT(); + if (primT->value.type == schema::PrimitiveType_TupleGetItem || + primT->value.type == schema::PrimitiveType_MakeTuple) { + continue; + } } mapRemoveGetItem_.clear(); RemoveIfMakeTuple(cnode); RemoveIfTupleGetItem(cnode); - if (primitive != nullptr && primitive->name() == prim::kPrimReturn->name()) { - AddOutPutIfReturn(metaGraphT, cnode); - continue; + + if (primitive != nullptr) { + if (primitive->name() == prim::kPrimReturn->name()) { + AddOutPutIfReturn(metaGraphT, cnode); + continue; + } + } else { + auto primitiveT_value = GetValueNode>(cnode->input(0)); + auto primT = primitiveT_value->GetPrimitiveT(); + if (primT->value.type == schema::PrimitiveType_Return) { + AddOutPutIfReturn(metaGraphT, cnode); + continue; + } } auto node = std::make_unique(); @@ -134,27 +152,24 @@ schema::MetaGraphT *AnfExporter::Export(const FuncGraphPtr &funcGraph) { primitive = GetValueNode(cnode->input(0)); MS_ASSERT(primitive != nullptr); std::string opType = primitive->name(); - auto nodeParser = - AnfNodePopulaterRegistry::GetInstance()->GetNodePopulater(opType); + auto nodeParser = AnfNodePopulaterRegistry::GetInstance()->GetNodePopulater(opType); if (nodeParser == nullptr) { MS_LOG(ERROR) << "Find op parser failed, opType: " << opType; return nullptr; } std::vector outputs; if (utils::isa(cnode->abstract())) { - auto abstract_cnode = - utils::cast(cnode->abstract()); + auto abstract_cnode = utils::cast(cnode->abstract()); outputs.resize(abstract_cnode->size()); } nodeParser->Parse(cnode, node.get(), &outputs); SetOpInputNode(cnode, metaGraphT.get(), node.get()); - SetOpOutputNode(outputs, metaGraphT.get(), node.get()); + SetOpOutputNode(cnode, outputs, metaGraphT.get(), node.get()); metaGraphT->nodes.emplace_back(std::move(node)); continue; } - auto primitiveT_value = - GetValueNode>(cnode->input(0)); + auto primitiveT_value = GetValueNode>(cnode->input(0)); if (primitiveT_value == nullptr) { MS_LOG(ERROR) << "PrimitiveT_value is nullptr"; return nullptr; @@ -166,42 +181,54 @@ schema::MetaGraphT *AnfExporter::Export(const FuncGraphPtr &funcGraph) { return nullptr; } - node->primitive = - std::unique_ptr(primitiveT_value->GetPrimitiveT()); + node->primitive = std::unique_ptr(primitiveT_value->GetPrimitiveT()); std::vector outputs; SetOpInputNode(cnode, metaGraphT.get(), node.get()); - SetOpOutputNode(outputs, metaGraphT.get(), node.get()); + SetOpOutputNode(cnode, outputs, metaGraphT.get(), node.get()); // add quant param node->quantType = primitiveT_value->GetQuantType(); if (node->quantType == schema::QuantType_PostTraining) { MS_LOG(INFO) << "node: " << node->name << " add QuantParam"; // activation - auto activate_index = node->inputIndex[0]; - auto tensor_input = metaGraphT->allTensors[activate_index].get(); auto input_quant_params = primitiveT_value->GetInputQuantParams(); - if (input_quant_params.empty()) { - MS_LOG(WARNING) << "node: " << node->name - << " input quant params is empty"; - } else { + auto node_type = primitiveT_value->GetPrimitiveT()->value.type; + for (int i = 0; i < input_quant_params.size(); i++) { + if (i >= node->inputIndex.size()) { + MS_LOG(ERROR) << "node: " << node->name << " input has " << input_quant_params.size() + << " quant_params; but only " << node->inputIndex.size() << " input"; + break; + } + auto activate_index = node->inputIndex[i]; + auto tensor_input = metaGraphT->allTensors[activate_index].get(); std::unique_ptr input_quant_param = - std::make_unique(input_quant_params[0]); + std::make_unique(input_quant_params[i]); + MS_LOG(DEBUG) << "[input]node: " << node->name << " scale: " << input_quant_param->scale + << " zp: " << input_quant_param->zeroPoint; tensor_input->quantParams.emplace_back(std::move(input_quant_param)); + if (!(node_type == schema::PrimitiveType_QuantDTypeCast && + primitiveT_value->GetPrimitiveT()->value.AsQuantDTypeCast()->srcT == kNumberTypeFloat32)) { + tensor_input->dataType = kNumberTypeInt8; + } } - tensor_input->dataType = kNumberTypeInt8; + // output auto output_index = node->outputIndex[0]; auto tensor_output = metaGraphT->allTensors[output_index].get(); auto output_quant_params = primitiveT_value->GetOutputQuantParams(); if (output_quant_params.empty()) { - MS_LOG(WARNING) << "node: " << node->name - << " output quant params is empty"; + MS_LOG(WARNING) << "node: " << node->name << " output quant params is empty"; } else { std::unique_ptr output_quant_param = - std::make_unique(output_quant_params[0]); + std::make_unique(output_quant_params[0]); + MS_LOG(DEBUG) << "[output]node: " << node->name << " scale: " << output_quant_param->scale + << " zp: " << output_quant_param->zeroPoint; tensor_output->quantParams.emplace_back(std::move(output_quant_param)); } - tensor_output->dataType = kNumberTypeInt8; + if (!(node_type == schema::PrimitiveType_QuantDTypeCast && + primitiveT_value->GetPrimitiveT()->value.AsQuantDTypeCast()->dstT == kNumberTypeFloat32)) { + tensor_output->dataType = kNumberTypeInt8; + } // // TensorType // valuePtr = primitive->GetAttr(kInputTensorDataType); // if (valuePtr != nullptr) { @@ -223,17 +250,16 @@ schema::MetaGraphT *AnfExporter::Export(const FuncGraphPtr &funcGraph) { if (tensor->data.empty()) { tensor->nodeType = schema::NodeType_ValueNode; tensor->format = schema::Format_NHWC; - // tensor->refCount = lite::MSCONST_WEIGHT_REFCOUNT; - metaGraphT->inputIndex.emplace_back(input); + if (!IsContain(metaGraphT->inputIndex, input)) { + metaGraphT->inputIndex.emplace_back(input); + } } } } return metaGraphT.release(); } -void AnfExporter::SetOpInputNode(const CNodePtr &cnode, - schema::MetaGraphT *meta_graph, - schema::CNodeT *fbNode) { +void AnfExporter::SetOpInputNode(const CNodePtr &cnode, schema::MetaGraphT *meta_graph, schema::CNodeT *fbNode) { MS_ASSERT(nullptr != meta_graph); MS_ASSERT(nullptr != fbNode); if (cnode->inputs().size() <= 1) { @@ -268,38 +294,30 @@ void AnfExporter::SetOpInputNode(const CNodePtr &cnode, auto paramTensor = std::make_unique(); auto abstractBase = paramNode->abstract(); if (abstractBase == nullptr) { - MS_LOG(ERROR) << "Abstract of parameter is nullptr, " - << paramNode->name(); + MS_LOG(ERROR) << "Abstract of parameter is nullptr, " << paramNode->name(); MS_ASSERT(false); return; } if (!utils::isa(abstractBase)) { - MS_LOG(ERROR) << "Abstract of parameter should be anstract tensor, " - << paramNode->name(); + MS_LOG(ERROR) << "Abstract of parameter should be anstract tensor, " << paramNode->name(); MS_ASSERT(false); return; } - auto abstractTensor = - utils::cast(abstractBase); + auto abstractTensor = utils::cast(abstractBase); auto typePtr = abstractTensor->element()->GetTypeTrack(); MS_ASSERT(typePtr != nullptr); paramTensor->dataType = typePtr->type_id(); if (!utils::isa(abstractTensor->BuildShape())) { - MS_LOG(ERROR) << "Shape of Abstract of parameter should be ShapePtr, " - << paramNode->name(); + MS_LOG(ERROR) << "Shape of Abstract of parameter should be ShapePtr, " << paramNode->name(); MS_ASSERT(false); return; } - paramTensor->dims = - utils::cast(abstractTensor->BuildShape()) - ->shape(); - auto paramValue = - std::dynamic_pointer_cast(paramNode->default_param()); + paramTensor->dims = utils::cast(abstractTensor->BuildShape())->shape(); + auto paramValue = std::dynamic_pointer_cast(paramNode->default_param()); if (paramValue != nullptr) { paramTensor->nodeType = schema::NodeType_ValueNode; paramTensor->data.resize(paramValue->tensor_size()); - memcpy(paramTensor->data.data(), paramValue->tensor_addr(), - paramValue->tensor_size()); + memcpy(paramTensor->data.data(), paramValue->tensor_addr(), paramValue->tensor_size()); for (auto &ite : paramValue->quant_param()) { auto quantPar = std::make_unique(); quantPar->scale = ite->scale; @@ -313,8 +331,7 @@ void AnfExporter::SetOpInputNode(const CNodePtr &cnode, paramTensor->dataType = paramValue->tensor_type(); } } - nodeIdMap[paramNode->fullname_with_scope()] = - meta_graph->allTensors.size(); + nodeIdMap[paramNode->fullname_with_scope()] = meta_graph->allTensors.size(); fbNode->inputIndex.emplace_back(meta_graph->allTensors.size()); meta_graph->allTensors.emplace_back(std::move(paramTensor)); } else if (inputNode->isa()) { @@ -323,19 +340,15 @@ void AnfExporter::SetOpInputNode(const CNodePtr &cnode, auto value = valueNode->value(); if (value->isa()) { auto valueAbstract = valueNode->abstract(); - auto abstractTensor = - utils::cast(valueAbstract); + auto abstractTensor = utils::cast(valueAbstract); auto typePtr = abstractTensor->element()->GetTypeTrack(); paramTensor->dataType = typePtr->type_id(); - paramTensor->dims = - utils::cast(abstractTensor->BuildShape()) - ->shape(); + paramTensor->dims = utils::cast(abstractTensor->BuildShape())->shape(); paramTensor->nodeType = schema::NodeType_ValueNode; auto data = value->cast(); paramTensor->data.resize(data->Size()); memcpy(paramTensor->data.data(), data->Data(), data->Size()); - nodeIdMap[valueNode->fullname_with_scope()] = - meta_graph->allTensors.size(); + nodeIdMap[valueNode->fullname_with_scope()] = meta_graph->allTensors.size(); fbNode->inputIndex.emplace_back(meta_graph->allTensors.size()); meta_graph->allTensors.emplace_back(std::move(paramTensor)); } else if (value->isa()) { @@ -363,30 +376,44 @@ void AnfExporter::SetOpInputNode(const CNodePtr &cnode, } } -void AnfExporter::SetOpOutputNode( - const std::vector &outputTensors, - schema::MetaGraphT *graph, schema::CNodeT *cnode) { +void AnfExporter::SetOpOutputNode(const CNodePtr &cnode, const std::vector &outputTensors, + schema::MetaGraphT *graph, schema::CNodeT *fbnode) { MS_ASSERT(nullptr != graph); - MS_ASSERT(nullptr != cnode); - std::string cnodeName = cnode->name; + MS_ASSERT(nullptr != fbnode); + std::string cnodeName = fbnode->name; if (!outputTensors.empty()) { int i = 0; for (auto outputTensor : outputTensors) { std::string name = cnodeName + "_o:" + std::to_string(i); - auto msTensor = new schema::TensorT(); - msTensor->nodeType = schema::NodeType_Parameter; nodeIdMap[name] = graph->allTensors.size(); - cnode->outputIndex.emplace_back(graph->allTensors.size()); - graph->allTensors.emplace_back(msTensor); + fbnode->outputIndex.emplace_back(graph->allTensors.size()); + graph->allTensors.emplace_back(outputTensor); i++; } return; } - auto msTensor = new schema::TensorT(); - msTensor->nodeType = schema::NodeType_Parameter; - cnode->outputIndex.emplace_back(graph->allTensors.size()); - nodeIdMap[cnodeName] = graph->allTensors.size(); - graph->allTensors.emplace_back(msTensor); + + if (utils::isa(cnode->abstract())) { + auto tuple = std::reinterpret_pointer_cast(cnode->abstract()); + for (int i = 0; i < tuple->size(); i++) { + auto msTensor = new schema::TensorT(); + msTensor->nodeType = schema::NodeType_Parameter; + fbnode->outputIndex.emplace_back(graph->allTensors.size()); + if (tuple->size() == 1) { + nodeIdMap[cnodeName] = graph->allTensors.size(); + } else { + std::string name = cnodeName + "_o:" + std::to_string(i); + nodeIdMap[name] = graph->allTensors.size(); + } + graph->allTensors.emplace_back(msTensor); + } + } else { + auto msTensor = new schema::TensorT(); + msTensor->nodeType = schema::NodeType_Parameter; + fbnode->outputIndex.emplace_back(graph->allTensors.size()); + nodeIdMap[cnodeName] = graph->allTensors.size(); + graph->allTensors.emplace_back(msTensor); + } } schema::MetaGraphT *Export(const FuncGraphPtr &funcGraph) { diff --git a/mindspore/lite/src/common/anf_exporter/anf_exporter.h b/mindspore/lite/src/common/anf_exporter/anf_exporter.h index 8cb04e9d72..c4f5d7a398 100644 --- a/mindspore/lite/src/common/anf_exporter/anf_exporter.h +++ b/mindspore/lite/src/common/anf_exporter/anf_exporter.h @@ -32,8 +32,8 @@ class AnfExporter { AnfExporter() = default; virtual ~AnfExporter() = default; schema::MetaGraphT *Export(const FuncGraphPtr &funcGraph); - void SetOpOutputNode(const std::vector &outputTensors, schema::MetaGraphT *graph, - schema::CNodeT *cnode); + void SetOpOutputNode(const CNodePtr &cnode, const std::vector &outputTensors, + schema::MetaGraphT *graph, schema::CNodeT *fbnode); void SetOpInputNode(const CNodePtr &cnode, schema::MetaGraphT *meta_graph, schema::CNodeT *fbNode); void RemoveIfMakeTuple(const CNodePtr &cnode); bool RemoveIfTupleGetItem(const CNodePtr &cnode); @@ -47,4 +47,3 @@ class AnfExporter { schema::MetaGraphT *Export(const FuncGraphPtr &funcGraph); } // namespace mindspore::lite #endif // MINDSPORE_LITE_SRC_ANF_EXPORTER_ANF_EXPORTER_H_ - diff --git a/mindspore/lite/src/common/anf_importer/import_from_meta_graph.cc b/mindspore/lite/src/common/anf_importer/import_from_meta_graph.cc index 6ec0ba8c54..b0d96fa3ee 100644 --- a/mindspore/lite/src/common/anf_importer/import_from_meta_graph.cc +++ b/mindspore/lite/src/common/anf_importer/import_from_meta_graph.cc @@ -27,96 +27,143 @@ namespace mindspore::lite { void AnfImporterFromMetaGraph::ConverterConstTensor() { - MS_EXCEPTION_IF_NULL(model); - auto *meta_graph = model->GetMetaGraph(); + MS_EXCEPTION_IF_NULL(model_); + auto *meta_graph = model_->GetMetaGraph(); MS_EXCEPTION_IF_NULL(meta_graph); - for (size_t i = 0; i < meta_graph->allTensors()->size(); i++) { + num_of_tensors_ = meta_graph->allTensors()->size(); + for (size_t i = 0; i < num_of_tensors_; i++) { auto *tensor = meta_graph->allTensors()->GetAs(i); MS_EXCEPTION_IF_NULL(tensor); - if (tensor->nodeType() != schema::NodeType_ValueNode) { + if ((tensor->nodeType() != schema::NodeType_ValueNode) && (tensor->nodeType() != schema::NodeType_Parameter)) { continue; } MS_ASSERT(tensor->dims() != nullptr); - auto parameter = model->add_parameter(); + auto parameter = model_->add_parameter(); std::vector shape; for (size_t j = 0; j < tensor->dims()->size(); ++j) { shape.push_back(tensor->dims()->data()[j]); } - auto type_id = static_cast(tensor->dataType()); + auto type_id = static_cast(tensor->dataType()); // todo: check error auto type_ptr = TypeIdToType(type_id); - auto abstract_tensor = std::make_shared(type_ptr, shape); - parameter->set_abstract(abstract_tensor); + auto abstractBase = std::make_shared(type_ptr, shape); + // XXX TODO copy format + parameter->set_abstract(abstractBase); + parameter->set_name(std::string("Parameter")); - ParamValueLitePtr param_value = std::make_shared(); - MS_EXCEPTION_IF_NULL(param_value); - param_value->set_tensor_shape(shape); - param_value->set_tensor_type(type_id); - if (tensor->data() != nullptr) { - auto size = tensor->data()->size(); - char *tensor_data = new char[size](); - std::memcpy(tensor_data, tensor->data()->data(), size); - MS_EXCEPTION_IF_NULL(tensor_data); - param_value->set_tensor_addr(tensor_data); - param_value->set_tensor_size(size); + if (tensor->nodeType() == schema::NodeType_ValueNode) { + ParamValueLitePtr param_value = std::make_shared(); + MS_EXCEPTION_IF_NULL(param_value); + param_value->set_tensor_shape(shape); + param_value->set_tensor_type(type_id); + if (tensor->data() != nullptr) { + auto size = tensor->data()->size(); + char *tensor_data = new char[size](); + std::memcpy(tensor_data, tensor->data()->data(), size); + MS_EXCEPTION_IF_NULL(tensor_data); + param_value->set_tensor_addr(tensor_data); + param_value->set_tensor_size(size); + } + parameter->set_default_param(param_value); } - parameter->set_default_param(param_value); AddNode(i, parameter); + model_->AddAnfNode(i, parameter); } } int AnfImporterFromMetaGraph::ConverterCNode() { - MS_EXCEPTION_IF_NULL(model); - auto *meta_graph = model->GetMetaGraph(); + MS_EXCEPTION_IF_NULL(model_); + auto *meta_graph = model_->GetMetaGraph(); MS_EXCEPTION_IF_NULL(meta_graph); - auto cNodes = meta_graph->nodes(); - for (size_t i = 0; i < cNodes->size(); i++) { - auto cNode = cNodes->GetAs(i); - MS_EXCEPTION_IF_NULL(cNode); - auto tensor_id = cNode->outputIndex()->data()[0]; - if (GetNode(tensor_id)) { - continue; - } - auto prim = std::make_shared(model->GetOp(cNode->name()->str())); + // Crate CNode -- Order of inputs is as follows + // First input should be the Primitive + // Then we have CNodes that contribute to this CNode + // Finally we Have the parameters + + // first itteration -- create CNode with primitive, create originator map + for (size_t i = 0; i < meta_graph->nodes()->size(); i++) { + auto cNode = meta_graph->nodes()->GetAs(i); + MS_EXCEPTION_IF_NULL(cNode); + auto prim = std::make_shared(model_->GetOp(cNode->name()->str())); if (prim == nullptr) { MS_LOG(ERROR) << "th tensorDef in subGraphDef is nullptr"; return RET_ERROR; } auto value_node = NewValueNode(prim); - AddNode(tensor_id, value_node); - + // auto prim_name = std::string("PrimitivePy: ") + std::string(cNode->name()->c_str()); + // value_node->set_fullname_with_scope(prim_name); std::vector op_inputs = {value_node}; + + auto cnode = model_->NewCNode(op_inputs); + auto node_name = std::string(cNode->name()->c_str()) + std::to_string(i); + cnode->set_fullname_with_scope(node_name); + AddNode(num_of_tensors_ + i, cnode); + + for (size_t j = 0; j < cNode->outputIndex()->size(); j++) { + int tensor_id = cNode->outputIndex()->data()[j]; + originator_[tensor_id] = cnode; + } + } + // second itteration -- fill in input CNodes and Parameters + // populate map + for (size_t i = 0; i < meta_graph->nodes()->size(); i++) { + std::vector input; + std::vector output; + int tensor_id; + auto cNode = meta_graph->nodes()->GetAs(i); + MS_EXCEPTION_IF_NULL(cNode); + auto cnode = std::dynamic_pointer_cast(GetNode(num_of_tensors_ + i)); + + for (size_t j = 0; j < cNode->outputIndex()->size(); j++) { + tensor_id = cNode->outputIndex()->data()[j]; + output.push_back(tensor_id); + } + MS_EXCEPTION_IF_NULL(cNode->inputIndex()); for (size_t j = 0; j < cNode->inputIndex()->size(); j++) { - auto node = GetNode(*(cNode->inputIndex()->GetAs(j))); - if (nullptr == node) { - MS_LOG(ERROR) << "Can't find input node."; - return RET_ERROR; + tensor_id = cNode->inputIndex()->data()[j]; + input.push_back(tensor_id); + auto *tensor = meta_graph->allTensors()->GetAs(tensor_id); + MS_EXCEPTION_IF_NULL(tensor); + if ((tensor->nodeType() == schema::NodeType_Parameter) && (originator_[tensor_id] != nullptr)) { + cnode->add_input(originator_[tensor_id]); } - // todo: CheckInputNodeType, the first node should be op; - op_inputs.push_back(node); } - auto cnode = model->NewCNode(op_inputs); - auto node_name = std::string(cNode->name()->c_str()); - cnode->set_fullname_with_scope(node_name); - AddNode(tensor_id, cnode); + // finally add all the Parameters (which are ValueNodes) + for (size_t j = 0; j < cNode->inputIndex()->size(); j++) { + tensor_id = cNode->inputIndex()->data()[j]; + auto *tensor = meta_graph->allTensors()->GetAs(tensor_id); + MS_EXCEPTION_IF_NULL(tensor); + if ((tensor->nodeType() == schema::NodeType_ValueNode) && (GetNode(tensor_id) != nullptr)) { + cnode->add_input(GetNode(tensor_id)); + } + } + + model_->AddCNodeInputOutput(cnode->fullname_with_scope(), input, output); } + return RET_OK; } void AnfImporterFromMetaGraph::AddReturnCNode() { - MS_EXCEPTION_IF_NULL(model); - auto *meta_graph = model->GetMetaGraph(); + MS_EXCEPTION_IF_NULL(model_); + auto *meta_graph = model_->GetMetaGraph(); MS_EXCEPTION_IF_NULL(meta_graph); + std::vector input; + std::vector output; std::vector op_inputs; auto value_node = NewValueNode(prim::kPrimReturn); + // value_node->set_fullname_with_scope("Primitive"); op_inputs.push_back(value_node); - auto tensor_id = meta_graph->outputIndex()->data()[0]; - op_inputs.push_back(GetNode(tensor_id)); - auto cnode = model->NewCNode(op_inputs); + for (int i = 0; i < meta_graph->outputIndex()->size(); i++) { + auto prev_cnode = originator_[meta_graph->outputIndex()->data()[i]]; + if (prev_cnode != nullptr) op_inputs.push_back(prev_cnode); + input.push_back(meta_graph->outputIndex()->data()[i]); + } + auto cnode = model_->NewCNode(op_inputs); cnode->set_fullname_with_scope("return"); - model->set_return(cnode); + model_->set_return(cnode); + model_->AddCNodeInputOutput(cnode->fullname_with_scope(), input, output); } -FuncGraphPtr AnfImporterFromMetaGraph::GetResult() { return this->model; } +FuncGraphPtr AnfImporterFromMetaGraph::GetResult() { return this->model_; } } // namespace mindspore::lite - diff --git a/mindspore/lite/src/common/anf_importer/import_from_meta_graph.h b/mindspore/lite/src/common/anf_importer/import_from_meta_graph.h index fd34930f1c..b8389f42d1 100644 --- a/mindspore/lite/src/common/anf_importer/import_from_meta_graph.h +++ b/mindspore/lite/src/common/anf_importer/import_from_meta_graph.h @@ -18,6 +18,7 @@ #define MINDSPORE_LITE_SRC_ANF_IMPORTER_IMPORTER_FROM_META_GRAPH_H_ #include +#include #include "src/train/model_impl.h" #include "schema/model_generated.h" #include "src/common/anf_importer/anf_importer.h" @@ -25,7 +26,7 @@ namespace mindspore::lite { class AnfImporterFromMetaGraph : public AnfImporter { public: - explicit AnfImporterFromMetaGraph(std::shared_ptr model) : model(model) {} + explicit AnfImporterFromMetaGraph(std::shared_ptr model) : model_(model) {} ~AnfImporterFromMetaGraph() override = default; @@ -39,9 +40,10 @@ class AnfImporterFromMetaGraph : public AnfImporter { void AddReturnCNode() override; private: - std::shared_ptr model = nullptr; + std::shared_ptr model_ = nullptr; + std::map originator_; + int num_of_tensors_ = 0; }; } // namespace mindspore::lite #endif // MINDSPORE_LITE_SRC_ANF_IMPORTER_IMPORTER_FROM_META_GRAPH_H_ - diff --git a/mindspore/lite/src/common/anf_importer/import_from_meta_graphT.cc b/mindspore/lite/src/common/anf_importer/import_from_meta_graphT.cc index c470d6a6e3..703e0b0715 100644 --- a/mindspore/lite/src/common/anf_importer/import_from_meta_graphT.cc +++ b/mindspore/lite/src/common/anf_importer/import_from_meta_graphT.cc @@ -71,11 +71,11 @@ int AnfImporterFromMetaGraphT::ConverterCNode() { for (size_t i = 0; i < meta_graph_->nodes.size(); i++) { auto &cNode = meta_graph_->nodes.at(i); MS_EXCEPTION_IF_NULL(cNode); - auto tensor_id = cNode->outputIndex.front(); - if (nullptr != GetNode(tensor_id)) { - continue; - } + bool flag = false; + if (cNode->outputIndex.size() > 1) { + flag = true; + } auto primTValue = std::make_shared(cNode->primitive.release()); cNode->primitive = nullptr; auto value_node = NewValueNode(primTValue); @@ -90,9 +90,39 @@ int AnfImporterFromMetaGraphT::ConverterCNode() { // todo: CheckInputNodeType, the first node should be op; op_inputs.push_back(node); } - auto cnode = func_graph_->NewCNode(op_inputs); - cnode->set_fullname_with_scope(cNode->name); - AddNode(tensor_id, cnode); + + auto new_cnode = func_graph_->NewCNode(op_inputs); + new_cnode->set_fullname_with_scope(cNode->name); + + std::vector out_tensor_ids = cNode->outputIndex; + + AbstractBasePtrList ptr_list; + int total = 0; + for (auto out_tensor_id : out_tensor_ids) { + if (nullptr != GetNode(out_tensor_id)) { + ptr_list.push_back(GetNode(out_tensor_id)->abstract()); + continue; + } + std::vector shape; + auto &tensor = meta_graph_->allTensors.at(out_tensor_id); + for (int &dim : tensor->dims) { + shape.push_back(dim); + } + auto type_id = static_cast(tensor->dataType); + auto type_ptr = TypeIdToType(type_id); + auto abstract_tensor = std::make_shared(type_ptr, shape); + auto getItemPrim = NewValueNode(prim::kPrimTupleGetItem); + if (flag) { + auto getItemIndex = NewValueNode(MakeValue(total++)); + std::vector inputs{getItemPrim, new_cnode, getItemIndex}; + CNodePtr new_item_cnode = func_graph_->NewCNode(inputs); + AddNode(out_tensor_id, new_item_cnode); + } else { + AddNode(out_tensor_id, new_cnode); + } + ptr_list.push_back(std::move(abstract_tensor)); + } + new_cnode->set_abstract(std::make_shared(ptr_list)); } return RET_OK; } @@ -120,4 +150,3 @@ void AnfImporterFromMetaGraphT::AddReturnCNode() { FuncGraphPtr AnfImporterFromMetaGraphT::GetResult() { return this->func_graph_; } } // namespace mindspore::lite - diff --git a/mindspore/lite/src/common/file_utils.cc b/mindspore/lite/src/common/file_utils.cc index 7babb87b47..545996abbe 100644 --- a/mindspore/lite/src/common/file_utils.cc +++ b/mindspore/lite/src/common/file_utils.cc @@ -72,13 +72,12 @@ std::string RealPath(const char *path) { MS_LOG(ERROR) << "new resolvedPath failed"; return ""; } - std::string realPath = realpath(path, resolvedPath.get()); - if (realPath.empty()) { - MS_LOG(ERROR) << "Proto file path is not valid"; + char *real_path = realpath(path, resolvedPath.get()); + if (real_path == nullptr || strlen(real_path) == 0) { + MS_LOG(ERROR) << "Proto file path is not valid"; return ""; } std::string res = resolvedPath.get(); - return res; } diff --git a/mindspore/lite/src/common/log_adapter.cc b/mindspore/lite/src/common/log_adapter.cc new file mode 100644 index 0000000000..f14f42bd75 --- /dev/null +++ b/mindspore/lite/src/common/log_adapter.cc @@ -0,0 +1,158 @@ +/** + * Copyright 2019 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "utils/log_adapter.h" + +#include +#include +#include +#include +#ifdef ENABLE_ARM +#include +#endif + +// namespace to support utils module definitionnamespace mindspore constexpr const char *ANDROID_LOG_TAG = "MS_LITE"; +namespace mindspore { +constexpr const char *ANDROID_LOG_TAG = "MS_LITE"; + +int EnvToInt(const char *env) { + if (env == nullptr) + return -1; + if (strcmp(env, "DEBUG") == 0) + return 0; + if (strcmp(env, "INFO") == 0) + return 1; + if (strcmp(env, "WARNING") == 0) + return 2; + if (strcmp(env, "ERROR") == 0) + return 3; + return -1; +} + +bool IsPrint(int level) { + static const char *env = std::getenv("MSLOG"); + static int ms_level = EnvToInt(env); + if (ms_level < 0) { + ms_level = 2; + } + return level >= ms_level; +} + +#ifdef ENABLE_ARM +// convert MsLogLevel to corresponding android level +static int GetAndroidLogLevel(MsLogLevel level) { + switch (level) { + case DEBUG: + return ANDROID_LOG_DEBUG; + case INFO: + return ANDROID_LOG_INFO; + case WARNING: + return ANDROID_LOG_WARN; + case ERROR: + default: + return ANDROID_LOG_ERROR; + } +} +#endif + +const char *EnumStrForMsLogLevel(MsLogLevel level) { + if (level == DEBUG) { + return "DEBUG"; + } else if (level == INFO) { + return "INFO"; + } else if (level == WARNING) { + return "WARNING"; + } else if (level == ERROR) { + return "ERROR"; + } else if (level == EXCEPTION) { + return "EXCEPTION"; + } else { + return "NO_LEVEL"; + } +} + +static std::string ExceptionTypeToString(ExceptionType type) { +#define _TO_STRING(x) #x + // clang-format off + static const char *const type_names[] = { + _TO_STRING(NoExceptionType), + _TO_STRING(UnknownError), + _TO_STRING(ArgumentError), + _TO_STRING(NotSupportError), + _TO_STRING(NotExistsError), + _TO_STRING(AlreadyExistsError), + _TO_STRING(UnavailableError), + _TO_STRING(DeviceProcessError), + _TO_STRING(AbortedError), + _TO_STRING(TimeOutError), + _TO_STRING(ResourceUnavailable), + _TO_STRING(NoPermissionError), + _TO_STRING(IndexError), + _TO_STRING(ValueError), + _TO_STRING(TypeError), + _TO_STRING(AttributeError), + }; + // clang-format on +#undef _TO_STRING + if (type < UnknownError || type > AttributeError) { + type = UnknownError; + } + return std::string(type_names[type]); +} + +void LogWriter::OutputLog(const std::ostringstream &msg) const { +if (IsPrint(log_level_)) { +// #ifdef USE_ANDROID_LOG +#ifdef ENABLE_ARM + __android_log_print(GetAndroidLogLevel(log_level_), ANDROID_LOG_TAG, "[%s:%d] %s] %s", location_.file_, + location_.line_, location_.func_, msg.str().c_str()); +#else + printf("%s [%s:%d] %s] %s\n:", EnumStrForMsLogLevel(log_level_), location_.file_, location_.line_, location_.func_, + msg.str().c_str()); +#endif +} +} + +void LogWriter::operator<(const LogStream &stream) const noexcept { + std::ostringstream msg; + msg << stream.sstream_->rdbuf(); + OutputLog(msg); +} + +void LogWriter::operator^(const LogStream &stream) const { + std::ostringstream msg; + msg << stream.sstream_->rdbuf(); + OutputLog(msg); + + std::ostringstream oss; + oss << location_.file_ << ":" << location_.line_ << " " << location_.func_ << "] "; + if (exception_type_ != NoExceptionType && exception_type_ != IndexError && exception_type_ != TypeError && + exception_type_ != ValueError && exception_type_ != AttributeError) { + oss << ExceptionTypeToString(exception_type_) << " "; + } + oss << msg.str(); + + if (trace_provider_ != nullptr) { + trace_provider_(oss); + } + + if (exception_handler_ != nullptr) { + exception_handler_(exception_type_, oss.str()); + } + throw std::runtime_error(oss.str()); +} +} // namespace mindspore + diff --git a/mindspore/lite/src/executor.cc b/mindspore/lite/src/executor.cc index a82d7cd1ed..01b02f4b01 100644 --- a/mindspore/lite/src/executor.cc +++ b/mindspore/lite/src/executor.cc @@ -37,17 +37,10 @@ int Executor::Run(std::vector &inputs, std::vectorGetOutputs(); - for (auto *output : outputs) { - MS_ASSERT(nullptr != output); - output->MallocData(); - } - session::CallBackParam callbackParam; - callbackParam.name_callback_param = kernel->Name(); - callbackParam.type_callback_param = kernel->type_str(); if (before != nullptr) { - if (!before(PackToMSTensors(kernel->GetInputs()), PackToMSTensors(kernel->GetOutputs()), callbackParam)) { + if (!before(PackToMSTensors(kernel->GetInputs()), PackToMSTensors(kernel->GetOutputs()), + {kernel->Name(), kernel->type_str()})) { MS_LOG(ERROR) << "run kernel before_callback failed, name: " << kernel->Name(); } } @@ -58,12 +51,16 @@ int Executor::Run(std::vector &inputs, std::vectorGetInputs()), PackToMSTensors(kernel->GetOutputs()), callbackParam)) { + if (!after(PackToMSTensors(kernel->GetInputs()), PackToMSTensors(kernel->GetOutputs()), + {kernel->Name(), kernel->type_str()})) { MS_LOG(ERROR) << "run kernel after_callback failed, name: " << kernel->Name(); } } for (auto input_kernel : kernel->GetInKernels()) { - MS_EXCEPTION_IF_NULL(input_kernel); + MS_ASSERT(input_kernel != nullptr); + if (input_kernel->is_model_output()) { + continue; + } ret = input_kernel->DecOutTensorRefCount(); if (0 != ret) { MS_LOG(WARNING) << "DecOutTensorRefCount for kernel" << kernel->Name() << " failed"; diff --git a/mindspore/lite/src/kernel_factory.cc b/mindspore/lite/src/kernel_factory.cc index b835506bec..fea004db99 100644 --- a/mindspore/lite/src/kernel_factory.cc +++ b/mindspore/lite/src/kernel_factory.cc @@ -45,7 +45,7 @@ LiteKernel *KernelFactory::GetKernel(const std::vector &inputs } auto creator = KernelRegistry::GetInstance()->GetCreator(key); if (creator != nullptr) { - auto kernel = creator(inputs, outputs, parameter, ctx, key); + auto kernel = creator(inputs, outputs, parameter, ctx, key, primitive); return kernel; } return nullptr; diff --git a/mindspore/lite/src/kernel_registry.h b/mindspore/lite/src/kernel_registry.h index eab7d03a53..772833f775 100644 --- a/mindspore/lite/src/kernel_registry.h +++ b/mindspore/lite/src/kernel_registry.h @@ -45,7 +45,6 @@ class KernelRegistry { int device_type_length_; int data_type_length_; int op_type_length_; - std::mutex lock_; }; class KernelRegistrar { diff --git a/mindspore/lite/src/lite_kernel.cc b/mindspore/lite/src/lite_kernel.cc index 86e172a315..0119f1029f 100644 --- a/mindspore/lite/src/lite_kernel.cc +++ b/mindspore/lite/src/lite_kernel.cc @@ -74,10 +74,6 @@ std::vector LiteKernelUtil::SubgraphInputTensors( for (const auto &kernel : kernels) { all_output_tensors.insert(all_output_tensors.end(), kernel->GetOutputs().begin(), kernel->GetOutputs().end()); } - std::sort(all_output_tensors.begin(), all_output_tensors.end()); - auto end_iter = std::unique(all_output_tensors.begin(), all_output_tensors.end()); - all_output_tensors.erase(end_iter, all_output_tensors.end()); - std::vector input_kernels = SubgraphInputKernels(kernels); for (const auto &kernel : input_kernels) { for (const auto &tensor : kernel->GetInputs()) { @@ -97,10 +93,6 @@ std::vector LiteKernelUtil::SubgraphOutputTensors( for (const auto &kernel : kernels) { all_input_tensors.insert(all_input_tensors.end(), kernel->GetInputs().begin(), kernel->GetInputs().end()); } - std::sort(all_input_tensors.begin(), all_input_tensors.end()); - auto end_iter = std::unique(all_input_tensors.begin(), all_input_tensors.end()); - all_input_tensors.erase(end_iter, all_input_tensors.end()); - std::vector output_kernels = SubgraphOutputKernels(kernels); for (const auto &kernel : output_kernels) { for (const auto &tensor : kernel->GetOutputs()) { diff --git a/mindspore/lite/src/lite_kernel.h b/mindspore/lite/src/lite_kernel.h index 1dba44c862..4f715d4651 100644 --- a/mindspore/lite/src/lite_kernel.h +++ b/mindspore/lite/src/lite_kernel.h @@ -25,6 +25,7 @@ #include "include/context.h" #include "src/ir/tensor.h" #include "src/ops/ops.h" +#include "include/errorcode.h" #ifdef ENABLE_FP16 using FLOAT_t = float16_t; @@ -34,6 +35,8 @@ using FLOAT_t = float; // using mindspore::kernel::AddressPtr; namespace mindspore::kernel { +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; enum KERNEL_ARCH { kCPU, kGPU, kNPU, kKernelArch_MIN = kCPU, kKernelArch_MAX = kNPU }; struct KernelKey { KERNEL_ARCH arch; @@ -55,15 +58,33 @@ class LiteKernel { public: LiteKernel() = default; explicit LiteKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : opParameter(parameter), inputs_(inputs), outputs_(outputs), train_mode(false) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : opParameter(parameter), inputs_(inputs), outputs_(outputs), primitive_(primitive), context_(ctx) { + if (opParameter && ctx) { + opParameter->thread_num_ = ctx->thread_num_; + } this->in_kernel_.clear(); this->out_kernel_.clear(); } virtual ~LiteKernel() { delete opParameter; } - virtual int Prepare() { return -1; } + virtual int Prepare() { + if (!InferShapeDone()) { + (const_cast(primitive_))->InferShape(inputs_, outputs_); + if (need_reinit) { + Init(); + } + } + + auto &outputs = this->GetOutputs(); + for (auto *output : outputs) { + MS_ASSERT(output != nullptr); + output->MallocData(); + } + return RET_OK; + } virtual int Init() { return -1; } virtual int ReSize() { return -1; } virtual int Run() { return -1; } @@ -75,9 +96,16 @@ class LiteKernel { virtual bool is_eval() { return train_mode == false; } void set_name(const std::string &name) { this->name = name; } + void set_is_model_output(bool is_model_output) { this->is_model_output_ = is_model_output; } + + bool is_model_output() { return this->is_model_output_; } + schema::PrimitiveType type() { return (schema::PrimitiveType)this->opParameter->type_; } - std::string type_str() { return schema::EnumNamePrimitiveType((schema::PrimitiveType)this->opParameter->type_); } + std::string type_str() { + return this->opParameter ? schema::EnumNamePrimitiveType((schema::PrimitiveType)this->opParameter->type_) + : "ERROR:undefined primitive!"; + } void SetInputs(const std::vector &inputs) { this->inputs_ = inputs; } @@ -103,16 +131,29 @@ class LiteKernel { void set_desc(const KernelKey kernel_key) { desc = kernel_key; } + void SetNeedReInit() { need_reinit = true; } + protected: + bool InferShapeDone() { + if (primitive_ != nullptr && !primitive_->GetInferFlag()) { + return false; + } + return true; + } + KernelKey desc; std::string name; OpParameter *opParameter = nullptr; + const lite::Primitive *primitive_ = nullptr; + const lite::Context *context_ = nullptr; // tensor will free in ~lite_session() std::vector inputs_; std::vector outputs_; std::vector in_kernel_; std::vector out_kernel_; - bool train_mode; + bool train_mode = false; + bool need_reinit = false; + bool is_model_output_ = false; }; class SubGraphKernel : public LiteKernel { @@ -121,8 +162,9 @@ class SubGraphKernel : public LiteKernel { const std::vector &outputs, const std::vector &inKernels, const std::vector &outKernels, - const std::vector &nodes) - : LiteKernel(nullptr, inputs, outputs), + const std::vector &nodes, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(nullptr, inputs, outputs, ctx, primitive), inputs_(inputs), outputs_(outputs), inkernels_(inKernels), @@ -144,7 +186,7 @@ class SubGraphKernel : public LiteKernel { typedef LiteKernel *(*KernelCreator)(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, - const lite::Context *ctx, const KernelKey &desc); + const lite::Context *ctx, const KernelKey &desc, const lite::Primitive *primitive); class LiteKernelUtil { public: diff --git a/mindspore/lite/src/lite_session.cc b/mindspore/lite/src/lite_session.cc index ae529836ab..9107bf6197 100644 --- a/mindspore/lite/src/lite_session.cc +++ b/mindspore/lite/src/lite_session.cc @@ -64,12 +64,48 @@ int LiteSession::ConvertTensors(const lite::Model *model) { // no copy data, do copy when call LiteKernel::Init dstTensor->SetData(const_cast(srcTensor->data()->data())); } + auto quant_params = srcTensor->quantParams(); + if (quant_params != nullptr) { + for (int j = 0; j < quant_params->size(); j++) { + tensor::QuantArg quant_arg{}; + quant_arg.scale = quant_params->Get(j)->scale(); + quant_arg.zeroPoint = quant_params->Get(j)->zeroPoint(); + dstTensor->AddQuantParam(quant_arg); + } + } + this->tensors.emplace_back(dstTensor); } return RET_OK; } -void LiteSession::InitGraphInOutTensor(const lite::Model *model) { +void LiteSession::InitGraphInputTensors(const lite::Model *model) { + auto meta_graph = model->GetMetaGraph(); + MS_ASSERT(this->inputs.empty()); + MS_ASSERT(meta_graph != nullptr); + for (size_t i = 0; i < meta_graph->inputIndex()->size(); i++) { + auto in_tensor_idx = size_t(meta_graph->inputIndex()->GetAs(i)); + MS_ASSERT(in_tensor_idx < this->tensors.size()); + auto *in_tensor = this->tensors.at(in_tensor_idx); + MS_ASSERT(in_tensor != nullptr); + this->inputs.emplace_back(in_tensor); + } +} + +void LiteSession::InitGraphOutputTensors(const lite::Model *model) { + auto meta_graph = model->GetMetaGraph(); + MS_ASSERT(this->outputs.empty()); + MS_ASSERT(meta_graph != nullptr); + for (size_t i = 0; i < meta_graph->outputIndex()->size(); i++) { + auto out_tensor_idx = size_t(meta_graph->outputIndex()->GetAs(i)); + MS_ASSERT(out_tensor_idx < this->tensors.size()); + auto *out_tensor = this->tensors.at(out_tensor_idx); + MS_ASSERT(out_tensor != nullptr); + this->outputs.emplace_back(out_tensor); + } +} + +void LiteSession::InitGraphInputMap(const lite::Model *model) { auto meta_graph = model->GetMetaGraph(); MS_ASSERT(this->input_map.empty()); MS_ASSERT(meta_graph != nullptr); @@ -98,7 +134,12 @@ void LiteSession::InitGraphInOutTensor(const lite::Model *model) { this->input_map[in_node->name()->str()].emplace_back(ms_tensor); } } +} +void LiteSession::InitGraphOutputMap(const lite::Model *model) { + auto meta_graph = model->GetMetaGraph(); + MS_ASSERT(this->output_map.empty()); + MS_ASSERT(meta_graph != nullptr); auto graph_output_node_indexes = GetGraphOutputNodes(meta_graph); for (auto out_node_index : graph_output_node_indexes) { auto *out_node = meta_graph->nodes()->GetAs(out_node_index); @@ -126,6 +167,13 @@ void LiteSession::InitGraphInOutTensor(const lite::Model *model) { } } +void LiteSession::InitGraphInOutTensors(const lite::Model *model) { + InitGraphInputTensors(model); + InitGraphOutputTensors(model); + InitGraphInputMap(model); + InitGraphOutputMap(model); +} + int LiteSession::CompileGraph(Model *model) { // model.MetaGraph ==> kernels if (model == nullptr) { @@ -139,7 +187,7 @@ int LiteSession::CompileGraph(Model *model) { return ret; } - InitGraphInOutTensor(model); + InitGraphInOutTensors(model); // scheduler kernels Scheduler scheduler(context_); @@ -168,6 +216,7 @@ std::vector LiteSession::GetInputs() const { int LiteSession::RunGraph(const session::KernelCallBack &before, const session::KernelCallBack &after) { MS_EXCEPTION_IF_NULL(this->context_); SetMaxWokerNum(context_->thread_num_); + context_->running_ = true; Executor executor; if (before == nullptr && after == nullptr) { return executor.Run(this->inputs, this->outputs, this->kernels, this->context_->allocator.get()); @@ -176,17 +225,8 @@ int LiteSession::RunGraph(const session::KernelCallBack &before, const session:: } } -std::vector LiteSession::GetOutputs() const { - std::vector ret; - for (auto &iter : this->output_map) { - auto &node_output_tensors = iter.second; - for (auto tensor : node_output_tensors) { - if (!IsContain(ret, tensor)) { - ret.emplace_back(tensor); - } - } - } - return ret; +std::unordered_map> LiteSession::GetOutputs() const { + return this->output_map; } int LiteSession::Init(Context *context) { @@ -226,15 +266,7 @@ LiteSession::~LiteSession() { } delete tensor; } - // inputs outputs input_map output_map are freed in tensors - for (auto *input : inputs) { - ((tensor::LiteTensor *)input)->SetTensorImpl(nullptr); - delete input; - } - for (auto *output : outputs) { - ((tensor::LiteTensor *)output)->SetTensorImpl(nullptr); - delete output; - } + // tensor::Tensor * in input_map output_map are freed in tensors for (auto iter : this->input_map) { for (auto *ms_tensor : iter.second) { ((tensor::LiteTensor *)ms_tensor)->SetTensorImpl(nullptr); diff --git a/mindspore/lite/src/lite_session.h b/mindspore/lite/src/lite_session.h index 4c45809596..05fd11a19e 100644 --- a/mindspore/lite/src/lite_session.h +++ b/mindspore/lite/src/lite_session.h @@ -49,14 +49,22 @@ class LiteSession : public session::LiteSession { int RunGraph(const session::KernelCallBack &before = nullptr, const session::KernelCallBack &after = nullptr) override; - std::vector GetOutputs() const override; + std::unordered_map> GetOutputs() const override; std::vector GetOutputsByName(const std::string &name) const override; protected: int ConvertTensors(const lite::Model *model); - void InitGraphInOutTensor(const lite::Model *model); + void InitGraphInOutTensors(const lite::Model *model); + + void InitGraphInputTensors(const lite::Model *model); + + void InitGraphOutputTensors(const lite::Model *model); + + void InitGraphInputMap(const lite::Model *model); + + void InitGraphOutputMap(const lite::Model *model); protected: Context *context_ = nullptr; diff --git a/mindspore/lite/src/model.cc b/mindspore/lite/src/model.cc index 55d10278f7..a1176216ce 100644 --- a/mindspore/lite/src/model.cc +++ b/mindspore/lite/src/model.cc @@ -14,22 +14,26 @@ * limitations under the License. */ -#ifdef SUPPORT_TRAIN -#include "src/train/model_impl.h" -#else +// #ifdef SUPPORT_TRAIN +// #include "src/train/model_impl.h" +// #else #include "src/model_impl.h" -#endif +// #endif #include "include/model.h" #include "utils/log_adapter.h" namespace mindspore::lite { -std::shared_ptr Model::Import(const char *model_buf, size_t size) { - auto model = std::make_shared(); +Model *Model::Import(const char *model_buf, size_t size) { + auto model = new Model(); model->model_impl_ = ModelImpl::Import(model_buf, size); return model; } +Model::~Model() { + delete(this->model_impl_); +} + lite::Primitive *Model::GetOp(const std::string &name) const { MS_EXCEPTION_IF_NULL(model_impl_); return const_cast(model_impl_->GetOp(name)); @@ -45,9 +49,8 @@ const schema::MetaGraph *Model::GetMetaGraph() const { return model_impl_->GetMetaGraph(); } -std::shared_ptr Model::model_impl() { +ModelImpl *Model::model_impl() { MS_EXCEPTION_IF_NULL(model_impl_); return this->model_impl_; } } // namespace mindspore::lite - diff --git a/mindspore/lite/src/model_impl.cc b/mindspore/lite/src/model_impl.cc index abead7cba1..3b2f10c01d 100644 --- a/mindspore/lite/src/model_impl.cc +++ b/mindspore/lite/src/model_impl.cc @@ -20,7 +20,7 @@ #include "utils/log_adapter.h" namespace mindspore::lite { -std::shared_ptr ModelImpl::Import(const char *model_buf, size_t size) { +ModelImpl *ModelImpl::Import(const char *model_buf, size_t size) { MS_EXCEPTION_IF_NULL(model_buf); flatbuffers::Verifier verify((const uint8_t *)model_buf, size); if (!schema::VerifyMetaGraphBuffer(verify)) { @@ -33,7 +33,7 @@ std::shared_ptr ModelImpl::Import(const char *model_buf, size_t size) return nullptr; } memcpy(inner_model_buf, model_buf, size); - auto model = std::make_shared(inner_model_buf, size); + auto model = new (std::nothrow) ModelImpl(inner_model_buf, size); if (model == nullptr) { MS_LOG(ERROR) << "Create modelImpl failed"; return nullptr; @@ -166,6 +166,8 @@ lite::Primitive *ModelImpl::CopyPrimitive(const schema::Primitive *srcPrim) { return new lite::Exp(const_cast(srcPrim)); case schema::PrimitiveType_Gather: return new lite::Gather(const_cast(srcPrim)); + case schema::PrimitiveType_GatherNd: + return new lite::GatherNd(const_cast(srcPrim)); case schema::PrimitiveType_LocalResponseNormalization: return new lite::LocalResponseNormalization(const_cast(srcPrim)); case schema::PrimitiveType_Maximum: @@ -180,6 +182,8 @@ lite::Primitive *ModelImpl::CopyPrimitive(const schema::Primitive *srcPrim) { return new lite::Prelu(const_cast(srcPrim)); case schema::PrimitiveType_Round: return new lite::Round(const_cast(srcPrim)); + case schema::PrimitiveType_Reverse: + return new lite::Reverse(const_cast(srcPrim)); case schema::PrimitiveType_ReverseSequence: return new lite::ReverseSequence(const_cast(srcPrim)); case schema::PrimitiveType_LogicalAnd: @@ -212,12 +216,20 @@ lite::Primitive *ModelImpl::CopyPrimitive(const schema::Primitive *srcPrim) { return new lite::Split(const_cast(srcPrim)); case schema::PrimitiveType_OneHot: return new lite::OneHot(const_cast(srcPrim)); + case schema::PrimitiveType_Resize: + return new lite::Resize(const_cast(srcPrim)); case schema::PrimitiveType_MatMul: return new lite::MatMul(const_cast(srcPrim)); case schema::PrimitiveType_QuantDTypeCast: return new lite::QuantDTypeCast(const_cast(srcPrim)); case schema::PrimitiveType_EmbeddingLookup: return new lite::EmbeddingLookup(const_cast(srcPrim)); + case schema::PrimitiveType_Elu: + return new lite::Elu(const_cast(srcPrim)); + case schema::PrimitiveType_DeDepthwiseConv2D: + return new lite::DeconvDepthwiseConv2D(const_cast(srcPrim)); + case schema::PrimitiveType_Shape: + return new lite::Shape(const_cast(srcPrim)); default: break; } diff --git a/mindspore/lite/src/model_impl.h b/mindspore/lite/src/model_impl.h index 14e0a1ccb9..8a1af3e9dc 100644 --- a/mindspore/lite/src/model_impl.h +++ b/mindspore/lite/src/model_impl.h @@ -27,7 +27,7 @@ namespace mindspore { namespace lite { class ModelImpl { public: - static std::shared_ptr Import(const char *model_buf, size_t size); + static ModelImpl *Import(const char *model_buf, size_t size); ModelImpl() = default; explicit ModelImpl(const char *model_buf, size_t size) : model_buf_(model_buf), buf_size_(size) { meta_graph = schema::GetMetaGraph(model_buf); diff --git a/mindspore/lite/src/ops/cast.cc b/mindspore/lite/src/ops/cast.cc index 13de84ff5e..565f8de767 100644 --- a/mindspore/lite/src/ops/cast.cc +++ b/mindspore/lite/src/ops/cast.cc @@ -40,7 +40,7 @@ int Cast::InferShape(std::vector inputs_, std::vectordata_type(); return RET_INPUT_TENSOR_ERROR; } - if (cast_prim->dstT() != kNumberTypeFloat || cast_prim->dstT() != kNumberTypeFloat32) { + if (cast_prim->dstT() != kNumberTypeFloat && cast_prim->dstT() != kNumberTypeFloat32) { MS_LOG(ERROR) << "Invalid output datatype " << cast_prim->dstT(); return RET_INPUT_TENSOR_ERROR; } diff --git a/mindspore/lite/src/ops/convolution_depthwise.cc b/mindspore/lite/src/ops/convolution_depthwise.cc index c26bda7b6f..2b8c11ba39 100644 --- a/mindspore/lite/src/ops/convolution_depthwise.cc +++ b/mindspore/lite/src/ops/convolution_depthwise.cc @@ -40,6 +40,7 @@ int DepthwiseConv2D::InferShape(std::vector inputs_, std::vect auto in_shape = input->shape(); int input_h = in_shape.at(1); int input_w = in_shape.at(2); + int input_channel = in_shape.at(3); int output_w = 0, output_h = 0; auto conv_prim = this->primitive->value_as_DepthwiseConv2D(); @@ -69,6 +70,10 @@ int DepthwiseConv2D::InferShape(std::vector inputs_, std::vect std::vector out_shape{input->shape()}; out_shape.at(1) = output_h; out_shape.at(2) = output_w; + if (conv_prim->channelMultiplier() * input_channel != weight->shape()[0]) { + MS_LOG(ERROR) << "Conv depthwise only support group equals output channel."; + return RET_ERROR; + } out_shape.at(3) = weight->shape()[0] * weight->shape()[3]; // in_channel * out_channel output->set_shape(out_shape); diff --git a/mindspore/lite/src/ops/crop.cc b/mindspore/lite/src/ops/crop.cc index dceab29f9b..c1b2bcfb49 100644 --- a/mindspore/lite/src/ops/crop.cc +++ b/mindspore/lite/src/ops/crop.cc @@ -32,7 +32,8 @@ int Crop::InferShape(std::vector inputs, std::vectorset_shape(inputs[1]->shape()); - outputs[0]->SetFormat(inputs[1]->GetFormat()); + outputs[0]->SetFormat(inputs[0]->GetFormat()); + outputs[0]->set_data_type(inputs[0]->data_type()); return RET_OK; } diff --git a/mindspore/lite/src/ops/deconvolution_depthwise.cc b/mindspore/lite/src/ops/deconvolution_depthwise.cc index 01e2542482..fe99cb4afd 100644 --- a/mindspore/lite/src/ops/deconvolution_depthwise.cc +++ b/mindspore/lite/src/ops/deconvolution_depthwise.cc @@ -40,6 +40,7 @@ int DeconvDepthwiseConv2D::InferShape(std::vector inputs_, std auto in_shape = input->shape(); int input_h = in_shape.at(1); int input_w = in_shape.at(2); + int input_channel = in_shape.at(3); int output_w = 0, output_h = 0; auto conv_prim = this->primitive->value_as_DeDepthwiseConv2D(); @@ -58,6 +59,10 @@ int DeconvDepthwiseConv2D::InferShape(std::vector inputs_, std std::vector out_shape{input->shape()}; out_shape.at(1) = output_h; out_shape.at(2) = output_w; + if (conv_prim->channelMultiplier() * input_channel != weight->shape()[0]) { + MS_LOG(ERROR) << "Conv depthwise only support group equals output channel."; + return RET_ERROR; + } out_shape.at(3) = weight->shape()[0] * weight->shape()[3]; // in_channel * out_channel output->set_shape(out_shape); diff --git a/mindspore/lite/src/ops/matmul.cc b/mindspore/lite/src/ops/matmul.cc index 619fcade8c..53ea430a9d 100644 --- a/mindspore/lite/src/ops/matmul.cc +++ b/mindspore/lite/src/ops/matmul.cc @@ -35,7 +35,7 @@ int MatMul::InferShape(std::vector inputs_, std::vector a_shape = input0->shape(); std::vector b_shape = input1->shape(); - if (a_shape.size() < 3 || b_shape.size() < 3) { + if (a_shape.size() < 2 || b_shape.size() < 2) { MS_LOG(ERROR) << "inputs shape is invalid"; return RET_INPUT_TENSOR_ERROR; } diff --git a/mindspore/lite/src/ops/ops.h b/mindspore/lite/src/ops/ops.h index 302f085b9d..f4f5143a4a 100644 --- a/mindspore/lite/src/ops/ops.h +++ b/mindspore/lite/src/ops/ops.h @@ -45,12 +45,15 @@ class Primitive { static Primitive *CreatePrimitive(schema::Primitive *primitive); virtual ~Primitive() {} const schema::Primitive *Value() const { return this->primitive; } + const bool GetInferFlag() const { return this->infer_flag_; } + void SetInferFlag(bool flag) { this->infer_flag_ = flag; } schema::PrimitiveType Type() const { return this->primitive->value_type(); } const void *Attribute() const { return this->primitive->value(); } virtual int InferShape(std::vector inputs_, std::vector outputs_); protected: schema::Primitive *primitive; + bool infer_flag_ = true; }; class Conv2D : public Primitive { @@ -779,6 +782,12 @@ class Lstm : public Primitive { int InferShape(std::vector inputs, std::vector outputs) override; }; +class Elu : public Primitive { + public: + explicit Elu(schema::Primitive *primitive) : Primitive(primitive) {} + const schema::Elu *GetAttribute() const { return this->primitive->value_as_Elu(); } +}; + class EmbeddingLookup : public Primitive { public: explicit EmbeddingLookup(schema::Primitive *primitive) : Primitive(primitive) {} diff --git a/mindspore/lite/src/ops/pad.cc b/mindspore/lite/src/ops/pad.cc index e697b53df8..109e7ab59a 100644 --- a/mindspore/lite/src/ops/pad.cc +++ b/mindspore/lite/src/ops/pad.cc @@ -44,8 +44,10 @@ int Pad::InferShape(std::vector inputs, std::vectorshape(); std::vector output_shape; + MS_ASSERT(input->shape().size() <= kInputRank); for (size_t i = 0; i < input_shape.size(); i++) { - auto shape = input_shape[i] + (*paddings)[2 * i] + (*paddings)[2 * i + 1]; + auto paddings_index = i + kInputRank - input_shape.size(); + auto shape = input_shape[i] + (*paddings)[2 * paddings_index] + (*paddings)[2 * paddings_index + 1]; output_shape.push_back(shape); } diff --git a/mindspore/lite/src/ops/pooling.cc b/mindspore/lite/src/ops/pooling.cc index 20745e7cd0..9fa8c16215 100644 --- a/mindspore/lite/src/ops/pooling.cc +++ b/mindspore/lite/src/ops/pooling.cc @@ -56,13 +56,11 @@ int Pooling::InferShape(std::vector inputs_, std::vectorroundMode(); if (round_mode == schema::RoundMode_FLOOR) { - output_h = std::floor((input_h + pad_u_ + pad_d_ - window_h) / pooling_prim->strideH() + 1); - output_w = std::floor((input_w + pad_l_ + pad_r_ - window_w) / pooling_prim->strideW() + 1); + output_h = std::floor(static_cast(input_h + pad_u_ + pad_d_ - window_h) / pooling_prim->strideH()) + 1; + output_w = std::floor(static_cast(input_w + pad_l_ + pad_r_ - window_w) / pooling_prim->strideW()) + 1; } else if (round_mode == schema::RoundMode_CEIL) { - output_h = - std::ceil((input_h + pooling_prim->padUp() + pooling_prim->padDown() - window_h) / pooling_prim->strideH() + 1); - output_w = std::ceil( - (input_w + pooling_prim->padLeft() + pooling_prim->padRight() - window_w) / pooling_prim->strideW() + 1); + output_h = std::ceil(static_cast(input_h + pad_u_ + pad_d_ - window_h) / pooling_prim->strideH()) + 1; + output_w = std::ceil(static_cast(input_w + pad_l_ + pad_r_ - window_w) / pooling_prim->strideW()) + 1; } else { MS_LOG(ERROR) << "unsupported round mode."; } @@ -80,4 +78,3 @@ int Pooling::InferShape(std::vector inputs_, std::vector inputs, std::vectorprimitive != nullptr); auto x_tensor = inputs[0]; MS_ASSERT(x_tensor != nullptr); - auto exp_tensor = inputs[1]; - MS_ASSERT(exp_tensor != nullptr); + tensor::Tensor *exp_tensor = nullptr; + if (inputs.size() == 2) { + exp_tensor = inputs[1]; + MS_ASSERT(exp_tensor != nullptr); + } auto output_tensor = outputs[0]; MS_ASSERT(output_tensor != nullptr); - if (inputs.size() < 2) { - MS_LOG(ERROR) << "input size" << inputs.size() << " is error!"; - return RET_INPUT_TENSOR_ERROR; - } - if (exp_tensor->shape() != x_tensor->shape() && exp_tensor->shape().size() != 1) { - MS_LOG(ERROR) << "Power inputs shape is not equal!"; - return RET_INPUT_TENSOR_ERROR; + if (exp_tensor) { + if (exp_tensor->shape() != x_tensor->shape() || exp_tensor->data_type() != x_tensor->data_type()) { + MS_LOG(ERROR) << "Power inputs shape or type is not equal!"; + return RET_INPUT_TENSOR_ERROR; + } } - int exp_size = std::accumulate(exp_tensor->shape().begin(), exp_tensor->shape().end(), 1, std::multiplies()); - if (x_tensor->data_type() != exp_tensor->data_type() && exp_size != 1) { - MS_LOG(ERROR) << "Exponent tensor's shape is wrong"; - return RET_INPUT_TENSOR_ERROR; - } output_tensor->SetFormat(x_tensor->GetFormat()); output_tensor->set_shape(x_tensor->shape()); output_tensor->set_data_type(x_tensor->data_type()); diff --git a/mindspore/lite/src/ops/quant_dtype_cast.cc b/mindspore/lite/src/ops/quant_dtype_cast.cc index 93855a89c4..82a9fa6548 100644 --- a/mindspore/lite/src/ops/quant_dtype_cast.cc +++ b/mindspore/lite/src/ops/quant_dtype_cast.cc @@ -30,6 +30,7 @@ int QuantDTypeCast::InferShape(std::vector inputs_, std::vecto auto param = primitive->value_as_QuantDTypeCast(); MS_ASSERT(input->data_type() == param->srcT); output->set_data_type(static_cast(param->dstT())); + output->SetFormat(input->GetFormat()); return RET_OK; } } // namespace mindspore::lite diff --git a/mindspore/lite/src/ops/reshape.cc b/mindspore/lite/src/ops/reshape.cc index 683e3f404e..bd30a74ad1 100644 --- a/mindspore/lite/src/ops/reshape.cc +++ b/mindspore/lite/src/ops/reshape.cc @@ -34,11 +34,11 @@ int Reshape::CalNewShape(const tensor::Tensor *in_tensor, std::vector *out_ inferIndex = i; } else { MS_LOG(ERROR) << "output shape should has no more than one dim which need infer"; - return RET_ERROR; + return RET_INFER_ERR; } } else if (out_shape->at(i) < 0) { MS_LOG(ERROR) << "output shape dim should be non-negative"; - return RET_ERROR; + return RET_INFER_ERR; } else if (out_shape->at(i) == 0) { out_shape->at(i) = in_tensor->shape().at(i); out_shapeSize *= out_shape->at(i); @@ -49,7 +49,7 @@ int Reshape::CalNewShape(const tensor::Tensor *in_tensor, std::vector *out_ if (inferIndex == -1 && out_shapeSize != in_shape_size) { MS_LOG(ERROR) << "output shapeSize: " << out_shapeSize << " should be equal to input shapeSize: " << in_shape_size; - return RET_ERROR; + return RET_INFER_ERR; } if (inferIndex != -1) { out_shape->at(inferIndex) = in_shape_size / out_shapeSize; @@ -88,6 +88,10 @@ int Reshape::InferShape(std::vector inputs_, std::vector out_shape; if (inputs_.size() == kDoubleNum) { auto shape_tensor = inputs_.at(1); + if (shape_tensor->Data() == nullptr) { + MS_LOG(INFO) << "Do infer shape in runtime."; + return RET_INFER_INVALID; + } size_t shape_size = shape_tensor->ElementsNum(); switch (shape_tensor->data_type()) { case kNumberTypeInt8: { @@ -108,13 +112,14 @@ int Reshape::InferShape(std::vector inputs_, std::vectordata_type(); - return RET_ERROR; + return RET_INFER_ERR; } } } else if (inputs_.size() == kSingleNum) { std::copy(reshape_prim->shape()->begin(), reshape_prim->shape()->end(), std::back_inserter(out_shape)); } else { MS_LOG(ERROR) << "inputs tensor size invalid."; + return RET_INFER_ERR; } auto ret = CalNewShape(inputs_.front(), &out_shape); diff --git a/mindspore/lite/src/ops/resize.cc b/mindspore/lite/src/ops/resize.cc index 7ef277b6fb..3ceae2ea1d 100644 --- a/mindspore/lite/src/ops/resize.cc +++ b/mindspore/lite/src/ops/resize.cc @@ -30,6 +30,8 @@ int Resize::InferShape(std::vector inputs_, std::vectorshape().size() == kInputRank); + auto output = outputs_.front(); if (output == nullptr) { return RET_NULL_PTR; diff --git a/mindspore/lite/src/populate_parameter.cc b/mindspore/lite/src/populate_parameter.cc index 22e5b42deb..1c338d24d9 100644 --- a/mindspore/lite/src/populate_parameter.cc +++ b/mindspore/lite/src/populate_parameter.cc @@ -26,12 +26,13 @@ #include "src/runtime/kernel/arm/nnacl/fp32/slice.h" #include "src/runtime/kernel/arm/nnacl/fp32/broadcast_to.h" #include "src/runtime/kernel/arm/nnacl/reshape_parameter.h" +#include "src/runtime/kernel/arm/nnacl/shape.h" #include "src/runtime/kernel/arm/nnacl/fp32/stack.h" #include "src/runtime/kernel/arm/nnacl/unstack.h" #include "src/runtime/kernel/arm/nnacl/depth_to_space.h" #include "src/runtime/kernel/arm/nnacl/conv_parameter.h" #include "src/runtime/kernel/arm/nnacl/fp32/pooling.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" #include "src/runtime/kernel/arm/nnacl/softmax_parameter.h" #include "src/runtime/kernel/arm/nnacl/tile.h" #include "src/runtime/kernel/arm/nnacl/fp32/topk.h" @@ -56,7 +57,7 @@ #include "src/runtime/kernel/arm/nnacl/unique.h" #include "src/runtime/kernel/arm/nnacl/scale.h" #include "src/runtime/kernel/arm/nnacl/fp32/gatherNd.h" -#include "src/runtime/kernel/arm/nnacl/resize.h" +#include "src/runtime/kernel/arm/nnacl/resize_parameter.h" #include "src/runtime/kernel/arm/nnacl/scatter_nd.h" #include "src/runtime/kernel/arm/nnacl/batch_to_space.h" #include "src/runtime/kernel/arm/nnacl/fp32/crop.h" @@ -70,6 +71,7 @@ #include "src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.h" #include "src/runtime/kernel/arm/nnacl/fp32/lstm.h" #include "src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.h" +#include "src/runtime/kernel/arm/nnacl/fp32/elu.h" namespace mindspore::kernel { OpParameter *PopulateBatchNorm(const lite::Primitive *primitive) { @@ -487,6 +489,7 @@ OpParameter *PopulateActivationParameter(const lite::Primitive *primitive) { } auto activation = primitive->Value()->value_as_Activation(); act_param->type_ = static_cast(activation->type()); + act_param->alpha_ = activation->alpha(); return reinterpret_cast(act_param); } @@ -872,6 +875,16 @@ OpParameter *PopulateReshapeParameter(const lite::Primitive *primitive) { return reinterpret_cast(reshape_param); } +OpParameter *PopulateShapeParameter(const lite::Primitive *primitive) { + ShapeParameter *shape_param = new (std::nothrow) ShapeParameter(); + if (shape_param == nullptr) { + MS_LOG(ERROR) << "new ShapeParameter failed."; + return nullptr; + } + shape_param->op_parameter_.type_ = primitive->Type(); + return reinterpret_cast(shape_param); +} + OpParameter *PopulateReverseParameter(const lite::Primitive *primitive) { auto reverse_attr = primitive->Value()->value_as_Reverse(); ReverseParameter *reverse_param = new (std::nothrow) ReverseParameter(); @@ -1010,7 +1023,7 @@ OpParameter *PopulateResizeParameter(const lite::Primitive *primitive) { } resize_param->op_parameter_.type_ = primitive->Type(); auto param = primitive->Value()->value_as_Resize(); - resize_param->method_ = param->method(); + resize_param->method_ = static_cast(param->method()); resize_param->new_height_ = param->newHeight(); resize_param->new_width_ = param->newWidth(); resize_param->align_corners_ = param->alignCorners(); @@ -1227,6 +1240,29 @@ OpParameter *PopulateEmbeddingLookupParameter(const lite::Primitive *primitive) return reinterpret_cast(embedding_lookup_parameter); } +OpParameter *PopulateBiasAddParameter(const lite::Primitive *primitive) { + ArithmeticParameter *arithmetic_param = new (std::nothrow) ArithmeticParameter(); + if (arithmetic_param == nullptr) { + MS_LOG(ERROR) << "new Bias Add Parameter failed"; + return nullptr; + } + arithmetic_param->op_parameter_.type_ = primitive->Type(); + + return reinterpret_cast(arithmetic_param); +} + +OpParameter *PopulateEluParameter(const lite::Primitive *primitive) { + EluParameter *elu_parameter = new (std::nothrow) EluParameter(); + if (elu_parameter == nullptr) { + MS_LOG(ERROR) << "new EluParameter failed"; + return nullptr; + } + elu_parameter->op_parameter_.type_ = primitive->Type(); + auto param = primitive->Value()->value_as_Elu(); + elu_parameter->alpha_ = param->alpha(); + return reinterpret_cast(elu_parameter); +} + PopulateParameterRegistry::PopulateParameterRegistry() { populate_parameter_funcs_[schema::PrimitiveType_SoftMax] = PopulateSoftmaxParameter; populate_parameter_funcs_[schema::PrimitiveType_Activation] = PopulateActivationParameter; @@ -1248,10 +1284,20 @@ PopulateParameterRegistry::PopulateParameterRegistry() { populate_parameter_funcs_[schema::PrimitiveType_Add] = PopulateArithmetic; populate_parameter_funcs_[schema::PrimitiveType_Sub] = PopulateArithmetic; populate_parameter_funcs_[schema::PrimitiveType_Div] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_LogicalAnd] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_LogicalOr] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_Equal] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_Less] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_Greater] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_NotEqual] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_LessEqual] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_GreaterEqual] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_Maximum] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_Minimum] = PopulateArithmetic; populate_parameter_funcs_[schema::PrimitiveType_FloorDiv] = PopulateArithmetic; populate_parameter_funcs_[schema::PrimitiveType_FloorMod] = PopulateArithmetic; populate_parameter_funcs_[schema::PrimitiveType_SquaredDifference] = PopulateArithmetic; - populate_parameter_funcs_[schema::PrimitiveType_BiasAdd] = PopulateArithmetic; + populate_parameter_funcs_[schema::PrimitiveType_BiasAdd] = PopulateBiasAddParameter; populate_parameter_funcs_[schema::PrimitiveType_Eltwise] = PopulateEltwiseParameter; populate_parameter_funcs_[schema::PrimitiveType_ExpandDims] = PopulateExpandDimsParameter; populate_parameter_funcs_[schema::PrimitiveType_Abs] = PopulateArithmeticSelf; @@ -1265,11 +1311,13 @@ PopulateParameterRegistry::PopulateParameterRegistry() { populate_parameter_funcs_[schema::PrimitiveType_LogicalNot] = PopulateArithmeticSelf; populate_parameter_funcs_[schema::PrimitiveType_Floor] = PopulateArithmeticSelf; populate_parameter_funcs_[schema::PrimitiveType_Ceil] = PopulateArithmeticSelf; + populate_parameter_funcs_[schema::PrimitiveType_Round] = PopulateArithmeticSelf; populate_parameter_funcs_[schema::PrimitiveType_ArgMax] = PopulateArgMaxParameter; populate_parameter_funcs_[schema::PrimitiveType_ArgMin] = PopulateArgMinParameter; populate_parameter_funcs_[schema::PrimitiveType_Cast] = PopulateCastParameter; populate_parameter_funcs_[schema::PrimitiveType_Scale] = PopulateScaleParameter; populate_parameter_funcs_[schema::PrimitiveType_Reshape] = PopulateReshapeParameter; + populate_parameter_funcs_[schema::PrimitiveType_Shape] = PopulateShapeParameter; populate_parameter_funcs_[schema::PrimitiveType_Concat] = PopulateConcatParameter; populate_parameter_funcs_[schema::PrimitiveType_Tile] = PopulateTileParameter; populate_parameter_funcs_[schema::PrimitiveType_TopK] = PopulateTopKParameter; @@ -1305,6 +1353,7 @@ PopulateParameterRegistry::PopulateParameterRegistry() { populate_parameter_funcs_[schema::PrimitiveType_QuantDTypeCast] = PopulateQuantDTypeCastParameter; populate_parameter_funcs_[schema::PrimitiveType_Lstm] = PopulateLstmParameter; populate_parameter_funcs_[schema::PrimitiveType_EmbeddingLookup] = PopulateEmbeddingLookupParameter; + populate_parameter_funcs_[schema::PrimitiveType_Elu] = PopulateEluParameter; } PopulateParameterRegistry *PopulateParameterRegistry::GetInstance() { diff --git a/mindspore/lite/src/runtime/kernel/arm/CMakeLists.txt b/mindspore/lite/src/runtime/kernel/arm/CMakeLists.txt index 2a66748ecf..ae23f6a736 100644 --- a/mindspore/lite/src/runtime/kernel/arm/CMakeLists.txt +++ b/mindspore/lite/src/runtime/kernel/arm/CMakeLists.txt @@ -1,3 +1,5 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/) + file(GLOB KERNEL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/base/*.cc nnacl/*.cc @@ -8,6 +10,13 @@ file(GLOB KERNEL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/int8/*.cc ) +if (SUPPORT_TRAIN) +file (GLOB TRAIN_KERNEL_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/fp32_grad/*.cc + ${CMAKE_CURRENT_SOURCE_DIR}/nnacl/fp32_grad/*.cc + ) +endif() + if (PLATFORM_ARM64) # assembly file(GLOB ASSEMBLY_SRC nnacl/assembly/arm64/*.s @@ -25,5 +34,5 @@ if (PLATFORM_ARM32) set(KERNEL_SRC ${KERNEL_SRC} ${ASSEMBLY_SRC}) endif() -add_library(cpu_kernel_mid_ OBJECT ${KERNEL_SRC}) +add_library(cpu_kernel_mid_ OBJECT ${KERNEL_SRC} ${TRAIN_KERNEL_SRC}) add_subdirectory(nnacl) diff --git a/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc index 0e356a5315..0230c7aea2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.cc @@ -24,9 +24,9 @@ using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_PARAM_INVALID; using mindspore::lite::RET_FORMAT_ERR; using mindspore::lite::RET_OK; +using mindspore::lite::RET_PARAM_INVALID; using mindspore::schema::PrimitiveType_ArgMax; using mindspore::schema::PrimitiveType_ArgMin; @@ -44,8 +44,14 @@ int ArgMinMaxBaseCPUKernel::Init() { MS_LOG(ERROR) << "Unexpected type " << opParameter->type_; return RET_ERROR; } + + return RET_OK; +} + +int ArgMinMaxBaseCPUKernel::ReSize() { auto in_shape = inputs_.at(0)->shape(); auto dims_size = in_shape.size(); + auto param = reinterpret_cast(opParameter); int axis = param->axis_ < 0 ? param->axis_ + dims_size : param->axis_; param->axis_ = axis; param->dims_size_ = dims_size; @@ -56,9 +62,9 @@ int ArgMinMaxBaseCPUKernel::Init() { param->topk_ = MSMIN(param->topk_, in_shape[axis]); if (param->topk_ > 1) { if (context_ != nullptr && context_->allocator != nullptr) { - param->arg_elements_ - = reinterpret_cast(context_->allocator->Malloc(sizeof(ArgElement) * in_shape[axis])); - data_from_allocator_ = true; + param->arg_elements_ = + reinterpret_cast(context_->allocator->Malloc(sizeof(ArgElement) * in_shape[axis])); + data_from_allocator_ = true; } else { param->arg_elements_ = reinterpret_cast(malloc(sizeof(ArgElement) * in_shape[axis])); } @@ -98,12 +104,12 @@ void ArgMinMaxBaseCPUKernel::FreeTmpMemory() { kernel::LiteKernel *CpuArgMinMaxInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } - auto kernel = new (std::nothrow) ArgMinMaxInt8CPUKernel(op_parameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) ArgMinMaxInt8CPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ArgMinMaxInt8CPUKernel fail!"; return nullptr; @@ -122,12 +128,12 @@ kernel::LiteKernel *CpuArgMinMaxInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } - auto kernel = new (std::nothrow) ArgMinMaxCPUKernel(op_parameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) ArgMinMaxCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ArgMinMaxCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.h b/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.h index d5ad81f29d..9630fd4c79 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/arg_min_max_base.h @@ -24,23 +24,21 @@ namespace mindspore::kernel { class ArgMinMaxBaseCPUKernel : public LiteKernel { public: ArgMinMaxBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), context_(ctx), data_from_allocator_(false) { - opParameter->thread_num_ = ctx->thread_num_; - } + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), data_from_allocator_(false) {} virtual ~ArgMinMaxBaseCPUKernel() { FreeTmpMemory(); } int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override; void FreeTmpMemory(); private: - const lite::Context *context_; bool data_from_allocator_; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc index e816153411..459364679e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.cc @@ -30,10 +30,6 @@ using mindspore::schema::PrimitiveType_BatchToSpace; namespace mindspore::kernel { int BatchToSpaceBaseCPUKernel::Init() { - if (inputs_[0]->GetFormat() != schema::Format_NHWC) { - MS_LOG(ERROR) << "batch_to_space only support NHWC now!"; - return RET_FORMAT_ERR; - } BatchToSpaceParameter *param = reinterpret_cast(this->opParameter); for (int i = 0; i < BATCH_TO_SPACE_CROPS_SIZE; ++i) { if (param->crops_[i] != 0) { @@ -43,16 +39,24 @@ int BatchToSpaceBaseCPUKernel::Init() { return RET_OK; } +int BatchToSpaceBaseCPUKernel::ReSize() { + if (inputs_[0]->GetFormat() != schema::Format_NHWC) { + MS_LOG(ERROR) << "batch_to_space only support NHWC now!"; + return RET_FORMAT_ERR; + } + return RET_OK; +} + kernel::LiteKernel *CpuBatchToSpaceInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_BatchToSpace); if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) BatchToSpaceInt8CPUKernel(op_parameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) BatchToSpaceInt8CPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new BatchToSpaceInt8CPUKernel fail!"; return nullptr; @@ -71,13 +75,13 @@ kernel::LiteKernel *CpuBatchToSpaceInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_BatchToSpace); if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) BatchToSpaceCPUKernel(op_parameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) BatchToSpaceCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new BatchToSpaceCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.h b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.h index 131b512e76..8e7ca7299d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/batch_to_space_base.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class BatchToSpaceBaseCPUKernel : public LiteKernel { public: BatchToSpaceBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { opParameter->thread_num_ = ctx->thread_num_; } @@ -34,7 +35,7 @@ class BatchToSpaceBaseCPUKernel : public LiteKernel { int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override { return 0; } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/concat_base.cc index ed1e5416b9..5674efc31c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/concat_base.cc @@ -30,6 +30,10 @@ using mindspore::schema::PrimitiveType_Concat; namespace mindspore::kernel { int ConcatBaseCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } axis_ = concat_param_->axis_ >= 0 ? concat_param_->axis_ : inputs_.front()->shape().size() + concat_param_->axis_; return RET_OK; } @@ -37,13 +41,13 @@ int ConcatBaseCPUKernel::Init() { kernel::LiteKernel *CpuConcatInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - auto *kernel = new(std::nothrow) ConcatInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ConcatInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; return nullptr; @@ -59,15 +63,15 @@ kernel::LiteKernel *CpuConcatInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const std::vector &outputs, + OpParameter *opParameter, const Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - auto *kernel = new(std::nothrow) ConcatCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ConcatCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; return nullptr; @@ -83,15 +87,15 @@ kernel::LiteKernel *CpuConcatInt32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const std::vector &outputs, + OpParameter *opParameter, const Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - auto *kernel = new(std::nothrow) ConcatCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ConcatCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; return nullptr; @@ -110,4 +114,3 @@ REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Concat, CpuConcatInt8KernelCreat REG_KERNEL(kCPU, kNumberTypeInt32, PrimitiveType_Concat, CpuConcatInt32KernelCreator) REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Concat, CpuConcatFp32KernelCreator) } // namespace mindspore::kernel - diff --git a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.h b/mindspore/lite/src/runtime/kernel/arm/base/concat_base.h index 9c7f558083..7ed1220b09 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/concat_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/concat_base.h @@ -28,8 +28,9 @@ namespace mindspore::kernel { class ConcatBaseCPUKernel : public LiteKernel { public: ConcatBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { opParameter->thread_num_ = ctx->thread_num_; concat_param_ = reinterpret_cast(opParameter); } @@ -41,6 +42,7 @@ class ConcatBaseCPUKernel : public LiteKernel { int ReSize() override { return 0; } int Run() override { return 0; } + protected: int thread_count_; int axis_; @@ -50,4 +52,3 @@ class ConcatBaseCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_CONCAT_BASE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h b/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h index 89b53dfcad..a2845b6897 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/convolution_base.h @@ -37,8 +37,9 @@ namespace mindspore::kernel { class ConvolutionBaseCPUKernel : public LiteKernel { public: ConvolutionBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { opParameter->thread_num_ = ctx->thread_num_; conv_param_ = reinterpret_cast(opParameter); } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc index 9f66feb208..be27b1f9cc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc @@ -31,15 +31,15 @@ namespace mindspore::kernel { int CropBaseCPUKernel::Init() { return RET_OK; } kernel::LiteKernel *CpuCropInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const std::vector &outputs, + OpParameter *opParameter, const Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Crop); - auto *kernel = new (std::nothrow) CropInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) CropInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new CropCPUKernel fail!"; return nullptr; @@ -55,15 +55,15 @@ kernel::LiteKernel *CpuCropInt8KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const std::vector &outputs, + OpParameter *opParameter, const Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Crop); - auto *kernel = new (std::nothrow) CropCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) CropCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new CropCPUKernel fail!"; return nullptr; @@ -79,15 +79,15 @@ kernel::LiteKernel *CpuCropInt32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const std::vector &outputs, + OpParameter *opParameter, const Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Crop); - auto *kernel = new (std::nothrow) CropCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) CropCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new CropCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h index f4ad763b5f..6e9a6843b8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class CropBaseCPUKernel : public LiteKernel { public: CropBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) { opParameter->thread_num_ = ctx->thread_num_; } ~CropBaseCPUKernel() = default; @@ -39,7 +40,6 @@ class CropBaseCPUKernel : public LiteKernel { protected: int thread_count_; - const Context *ctx_; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc index b18f7dc9bb..cfb555e025 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.cc @@ -25,13 +25,15 @@ using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_PARAM_INVALID; using mindspore::lite::RET_FORMAT_ERR; using mindspore::lite::RET_OK; +using mindspore::lite::RET_PARAM_INVALID; using mindspore::schema::PrimitiveType_DepthToSpace; namespace mindspore::kernel { -int DepthToSpaceBaseCPUKernel::Init() { +int DepthToSpaceBaseCPUKernel::Init() { return RET_OK; } + +int DepthToSpaceBaseCPUKernel::ReSize() { if (inputs_[0]->GetFormat() != schema::Format_NHWC) { MS_LOG(ERROR) << "depth_to_space only support NHWC now!"; return RET_FORMAT_ERR; @@ -62,13 +64,13 @@ int DepthToSpaceBaseCPUKernel::Init() { kernel::LiteKernel *CpuDepthToSpaceInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_DepthToSpace); if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) DepthToSpaceInt8CPUKernel(op_parameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) DepthToSpaceInt8CPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new BatchToSpaceInt8CPUKernel fail!"; return nullptr; @@ -87,13 +89,13 @@ kernel::LiteKernel *CpuDepthToSpaceInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_DepthToSpace); if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) DepthToSpaceCPUKernel(op_parameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) DepthToSpaceCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new DepthToSpaceCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h index 32974271aa..27a2ae73ba 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/depth_to_space_base.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class DepthToSpaceBaseCPUKernel : public LiteKernel { public: DepthToSpaceBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { opParameter->thread_num_ = ctx->thread_num_; } @@ -34,7 +35,7 @@ class DepthToSpaceBaseCPUKernel : public LiteKernel { int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override { return 0; } }; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.cc index 4f74e94360..ecdf77cad4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.cc @@ -35,10 +35,11 @@ int FullconnectionBaseCPUKernel::Init() { kernel::LiteKernel *CpuFullConnectionInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - auto kernel = new (std::nothrow) FullconnectionInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) FullconnectionInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (!kernel) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; @@ -56,10 +57,11 @@ kernel::LiteKernel *CpuFullConnectionInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Concat); - auto kernel = new (std::nothrow) FullconnectionCPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) FullconnectionCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (!kernel) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.h b/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.h index 3d29519370..bf03869188 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/fullconnection_base.h @@ -20,7 +20,7 @@ #include #include "src/lite_kernel.h" #include "include/context.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" using mindspore::lite::Context; @@ -28,8 +28,9 @@ namespace mindspore::kernel { class FullconnectionBaseCPUKernel : public LiteKernel { public: FullconnectionBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { fc_param_ = reinterpret_cast(opParameter); } ~FullconnectionBaseCPUKernel() = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc index eb88cfb4b3..af7ba4afab 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/matmul_base.cc @@ -28,7 +28,8 @@ using mindspore::schema::PrimitiveType_MatMul; namespace mindspore::kernel { kernel::LiteKernel *CpuMatmulKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, - const lite::Context *ctx, const kernel::KernelKey &desc) { + const lite::Context *ctx, const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Concat); auto input_tensor = inputs.at(kInputIndex); @@ -37,7 +38,7 @@ kernel::LiteKernel *CpuMatmulKernelCreator(const std::vector #include "src/lite_kernel.h" #include "include/context.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" using mindspore::lite::Context; @@ -28,8 +28,9 @@ namespace mindspore::kernel { class MatmulBaseCPUKernel : public LiteKernel { public: MatmulBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { params_ = reinterpret_cast(opParameter); } ~MatmulBaseCPUKernel() = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/pad.cc b/mindspore/lite/src/runtime/kernel/arm/base/pad.cc index 723657b603..2e071706a7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/pad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/pad.cc @@ -31,10 +31,10 @@ namespace mindspore::kernel { kernel::LiteKernel *CpuPadInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Pad); - auto *kernel = new (std::nothrow) PadInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) PadInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PadCPUKernel failed."; return nullptr; @@ -52,10 +52,10 @@ kernel::LiteKernel *CpuPadInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Pad); - auto *kernel = new (std::nothrow) PadCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) PadCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PadCPUKernel failed."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc index 68dedfe351..45e7186b6e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.cc @@ -56,6 +56,10 @@ void PoolingBaseCPUKernel::FreeQuantParam() { } int PoolingBaseCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } MS_ASSERT(inputs_.size() == 1); MS_ASSERT(outputs_.size() == 1); pooling_param_->thread_num_ = thread_count_; @@ -78,13 +82,13 @@ int PoolingBaseCPUKernel::Init() { kernel::LiteKernel *CpuPoolingInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Pooling); - auto *kernel = new (std::nothrow) PoolingInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) PoolingInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PoolingInt8CPUKernel fail!"; return nullptr; @@ -102,13 +106,13 @@ kernel::LiteKernel *CpuPoolingInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Pooling); - auto *kernel = new (std::nothrow) PoolingCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) PoolingCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PoolingCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.h b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.h index a601db0bb3..4a56a44f9c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/pooling_base.h @@ -29,8 +29,9 @@ namespace mindspore::kernel { class PoolingBaseCPUKernel : public LiteKernel { public: PoolingBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { pooling_param_ = reinterpret_cast(opParameter); } ~PoolingBaseCPUKernel() = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/prelu_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/prelu_base.cc new file mode 100644 index 0000000000..1c765d6de3 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/base/prelu_base.cc @@ -0,0 +1,58 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "src/runtime/kernel/arm/base/prelu_base.h" +#include +#include "src/runtime/kernel/arm/int8/prelu_int8.h" +#include "schema/model_generated.h" +#include "src/kernel_factory.h" +#include "include/errorcode.h" +#include "include/context.h" + +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Prelu; + +namespace mindspore::kernel { +int PreluBaseCPUKernel::Init() {return RET_OK;} + +kernel::LiteKernel *CpuPreluInt8KernelCreator(const std::vector &inputs, + const std::vector &outputs, + OpParameter *opParameter, const Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { + if (opParameter == nullptr) { + MS_LOG(ERROR) << "Input opParameter is nullptr!"; + return nullptr; + } + MS_ASSERT(desc.type == schema::PrimitiveType_Prelu); + auto *kernel = new(std::nothrow) PreluInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new PreluCPUKernel fail!"; + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + delete kernel; + MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + return nullptr; + } + return kernel; +} + +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Prelu, CpuPreluInt8KernelCreator) +} // namespace mindspore::kernel + diff --git a/mindspore/lite/src/runtime/kernel/arm/base/prelu_base.h b/mindspore/lite/src/runtime/kernel/arm/base/prelu_base.h new file mode 100644 index 0000000000..66c5cdc147 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/base/prelu_base.h @@ -0,0 +1,53 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_Prelu_BASE_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_Prelu_BASE_H_ + +#include +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/nnacl/prelu_parameter.h" +#include "src/runtime/kernel/arm/base/layout_transform.h" + +using mindspore::lite::Context; + +namespace mindspore::kernel { +class PreluBaseCPUKernel : public LiteKernel { + public: + PreluBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { + opParameter->thread_num_ = ctx->thread_num_; + prelu_param_ = reinterpret_cast(opParameter); + } + + ~PreluBaseCPUKernel() = default; + + int Init() override; + + int ReSize() override { return 0; } + + int Run() override { return 0; } + + protected: + int thread_count_; + const Context *ctx_; + PreluParameter *prelu_param_; +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_Prelu_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc index e09ec8889c..680e62e329 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/prior_box.cc @@ -39,6 +39,11 @@ int PriorBoxCPUKernel::Init() { MS_LOG(ERROR) << "PriorBoxParameter nullptr"; return RET_NULL_PTR; } + + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } MS_ASSERT(inputs_.size() == kInputNum); MS_ASSERT(outputs_.size() == kOutputNum); @@ -164,7 +169,7 @@ int PriorBoxCPUKernel::Run() { kernel::LiteKernel *CpuPriorBoxKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; @@ -173,7 +178,7 @@ kernel::LiteKernel *CpuPriorBoxKernelCreator(const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { prior_box_param_ = reinterpret_cast(opParameter); } ~PriorBoxCPUKernel() = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc index ef5516be2d..0e49e78b4c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/quant_dtype_cast.cc @@ -34,6 +34,10 @@ constexpr int kQuantDTypeCastOutputNum = 1; } // namespace int QuantDTypeCastCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } if (inputs_.size() != 1) { MS_LOG(ERROR) << "inputs number should be 1, but " << inputs_.size() << " is given."; return RET_ERROR; @@ -58,7 +62,7 @@ int QuantDTypeCastCPUKernel::Init() { } inverse_ = true; } else { - MS_LOG(ERROR) << "param data type not supported."; + MS_LOG(ERROR) << "param data type not supported:" << " src: " << param->srcT << " dst: " << param->dstT; return RET_ERROR; } @@ -83,8 +87,8 @@ int QuantDTypeCastCPUKernel::QuantDTypeCast(int task_id) { ret = DequantizeInt8(int8_ptr_ + thread_offset, float32_ptr_ + thread_offset, quant_arg.scale, quant_arg.zeroPoint, num_unit_thread); } else { - ret = QuantizeToInt8(float32_ptr_ + thread_offset, int8_ptr_ + thread_offset, quant_arg.scale, - quant_arg.zeroPoint, num_unit_thread); + ret = QuantizeToInt8(float32_ptr_ + thread_offset, int8_ptr_ + thread_offset, quant_arg.scale, quant_arg.zeroPoint, + num_unit_thread); } if (ret != RET_OK) { MS_LOG(ERROR) << "QuantDTypeCast error task_id[" << task_id << "] error_code[" << ret << "]"; @@ -124,12 +128,13 @@ int QuantDTypeCastCPUKernel::Run() { kernel::LiteKernel *CpuQuantDTypeCastFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) QuantDTypeCastCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) QuantDTypeCastCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new QuantDTypeCastCPUKernel fail!"; return nullptr; @@ -143,6 +148,6 @@ kernel::LiteKernel *CpuQuantDTypeCastFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_num_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_num_(ctx->thread_num_) {} ~QuantDTypeCastCPUKernel() = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc index 479bfce181..22f7f3e657 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.cc @@ -36,15 +36,15 @@ int ReshapeBaseCPUKernel::Init() { kernel::LiteKernel *CpuReshapeInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Reshape); - auto *kernel = new (std::nothrow) ReshapeInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ReshapeInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { - MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; + MS_LOG(ERROR) << "new ReshapeInt8CPUKernel fail!"; return nullptr; } auto ret = kernel->Init(); @@ -60,15 +60,15 @@ kernel::LiteKernel *CpuReshapeInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Reshape); - auto *kernel = new (std::nothrow) ReshapeCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ReshapeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { - MS_LOG(ERROR) << "new ConcatCPUKernel fail!"; + MS_LOG(ERROR) << "new ReshapeCPUKernel fail!"; return nullptr; } auto ret = kernel->Init(); @@ -84,13 +84,13 @@ kernel::LiteKernel *CpuReshapeInt32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Reshape); - auto *kernel = new (std::nothrow) ReshapeCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ReshapeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ReshapeCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.h b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.h index 2c0ca7ea30..a9d2fb3ab9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/reshape_base.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class ReshapeBaseCPUKernel : public LiteKernel { public: ReshapeBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { reshape_param_ = reinterpret_cast(opParameter); } ~ReshapeBaseCPUKernel() = default; @@ -45,4 +46,3 @@ class ReshapeBaseCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_RESHAPE_BASE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc new file mode 100644 index 0000000000..9d2959dc47 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.cc @@ -0,0 +1,159 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "schema/model_generated.h" +#include "src/kernel_registry.h" +#include "include/errorcode.h" +#include "src/runtime/kernel/arm/base/resize_base.h" +#include "src/runtime/kernel/arm/fp32/resize.h" +#include "src/runtime/kernel/arm/int8/resize_int8.h" +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_INVALID_OP_ATTR; +using mindspore::lite::RET_NULL_PTR; +using mindspore::lite::RET_OK; + +namespace mindspore::kernel { +namespace { +constexpr int kInputNum = 1; +constexpr int kOutputNum = 1; +constexpr int kRank = 4; +} // namespace + +int ResizeBaseCPUKernel::CheckParameters() { + auto parameter = reinterpret_cast(opParameter); + if (parameter == nullptr) { + MS_LOG(ERROR) << "cast ResizeParameter failed."; + return RET_NULL_PTR; + } + method_ = parameter->method_; + if (method_ != schema::ResizeMethod_BILINEAR && method_ != schema::ResizeMethod_NEAREST_NEIGHBOR) { + MS_LOG(ERROR) << "Resize method should be bilinear or nearest_neighbor, but got " << method_; + return RET_INVALID_OP_ATTR; + } + new_height_ = parameter->new_height_; + if (new_height_ < 1) { + MS_LOG(ERROR) << "Resize new_height should >= 1, but got " << new_height_; + return RET_INVALID_OP_ATTR; + } + new_width_ = parameter->new_width_; + if (new_width_ < 1) { + MS_LOG(ERROR) << "Resize new_width should >= 1, but got " << new_width_; + return RET_INVALID_OP_ATTR; + } + align_corners_ = parameter->align_corners_; + preserve_aspect_ratio = parameter->preserve_aspect_ratio_; + if (preserve_aspect_ratio) { + MS_LOG(ERROR) << "Resize currently not support preserve_aspect_ratio true"; + return RET_ERROR; + } + return RET_OK; +} + +int ResizeBaseCPUKernel::CheckInputsOuputs() { + if (inputs_.size() != kInputNum) { + MS_LOG(ERROR) << "Resize input num should be " << kInputNum << ", but got " << inputs_.size(); + return RET_ERROR; + } + auto input = inputs_.at(0); + if (input == nullptr) { + return RET_NULL_PTR; + } + if (outputs_.size() != kOutputNum) { + MS_LOG(ERROR) << "Resize output num should be " << kOutputNum << ", but got " << outputs_.size(); + return RET_ERROR; + } + auto output = outputs_.at(0); + if (output == nullptr) { + return RET_NULL_PTR; + } + return RET_OK; +} + +int ResizeBaseCPUKernel::Init() { + auto ret = CheckParameters(); + if (ret != RET_OK) { + return ret; + } + ret = CheckInputsOuputs(); + if (ret != RET_OK) { + return ret; + } + + auto input = inputs_.at(0); + auto input_shape = input->shape(); + if (input_shape.size() != kRank) { + MS_LOG(ERROR) << "Resize op support input rank 4, got " << input_shape.size(); + return RET_ERROR; + } + + return RET_OK; +} + +kernel::LiteKernel *CpuResizeFp32KernelCreator(const std::vector &inputs, + const std::vector &outputs, + OpParameter *opParameter, const lite::Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { + if (opParameter == nullptr) { + MS_LOG(ERROR) << "Input opParameter is nullptr!"; + return nullptr; + } + MS_ASSERT(desc.type == schema::PrimitiveType_Resize); + auto *kernel = new (std::nothrow) ResizeCPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new ResizeCPUKernel fail!"; + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + delete kernel; + MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + return nullptr; + } + + return kernel; +} + +kernel::LiteKernel *CpuResizeInt8KernelCreator(const std::vector &inputs, + const std::vector &outputs, + OpParameter *opParameter, const lite::Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { + if (opParameter == nullptr) { + MS_LOG(ERROR) << "Input opParameter is nullptr!"; + return nullptr; + } + MS_ASSERT(desc.type == schema::PrimitiveType_Resize); + auto *kernel = new (std::nothrow) ResizeInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new ResizeCPUKernel fail!"; + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + delete kernel; + MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + return nullptr; + } + + return kernel; +} + +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Resize, CpuResizeInt8KernelCreator) +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Resize, CpuResizeFp32KernelCreator) +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/resize_base.h b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.h new file mode 100644 index 0000000000..5bd3de4e65 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/base/resize_base.h @@ -0,0 +1,53 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_RESIZE_BASE_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_RESIZE_BASE_H_ + +#include +#include "src/lite_kernel.h" +#include "nnacl/resize_parameter.h" + +using mindspore::schema::PrimitiveType_Resize; +using mindspore::schema::ResizeMethod; + +namespace mindspore::kernel { +class ResizeBaseCPUKernel : public LiteKernel { + public: + ResizeBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), context_(ctx) {} + + ~ResizeBaseCPUKernel() = default; + + int Init() override; + int ReSize() override { return 0; }; + + protected: + const lite::Context *context_; + int method_; + int64_t new_height_; + int64_t new_width_; + bool align_corners_; + bool preserve_aspect_ratio; + + private: + int CheckParameters(); + int CheckInputsOuputs(); +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_RESIZE_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc index f5f348e9ee..8029b715ac 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.cc @@ -53,13 +53,13 @@ int SoftmaxBaseCPUKernel::Init() { kernel::LiteKernel *CpuSoftmaxInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_SoftMax); - auto *kernel = new (std::nothrow) SoftmaxInt8CPUKernel(opParameter, inputs, outputs, ctx); + SoftmaxInt8CPUKernel *kernel = new (std::nothrow) SoftmaxInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SoftmaxCPUKernel fail!"; return nullptr; @@ -77,13 +77,13 @@ kernel::LiteKernel *CpuSoftmaxInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_SoftMax); - auto *kernel = new (std::nothrow) SoftmaxCPUKernel(opParameter, inputs, outputs, ctx); + SoftmaxCPUKernel *kernel = new (std::nothrow) SoftmaxCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SoftmaxCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.h b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.h index 4e8873aec0..c150b566a8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/softmax_base.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class SoftmaxBaseCPUKernel : public LiteKernel { public: SoftmaxBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { opParameter->thread_num_ = ctx->thread_num_; softmax_param_ = reinterpret_cast(opParameter); } diff --git a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc index 7e04a8ab2d..4636c90a3e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/split_base.cc @@ -61,13 +61,13 @@ int SplitBaseCPUKernel::Init() { kernel::LiteKernel *CpuSplitInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Split); - auto *kernel = new (std::nothrow) SplitInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) SplitInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SplitCPUKernel fail!"; return nullptr; @@ -85,13 +85,13 @@ kernel::LiteKernel *CpuSplitInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Split); - auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SplitCPUKernel fail!"; return nullptr; @@ -109,13 +109,13 @@ kernel::LiteKernel *CpuSplitInt32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Split); - auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) SplitCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SplitCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/split_base.h b/mindspore/lite/src/runtime/kernel/arm/base/split_base.h index 0f90604cfc..38d876cc1f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/split_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/split_base.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class SplitBaseCPUKernel : public LiteKernel { public: SplitBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { param = reinterpret_cast(opParameter); } ~SplitBaseCPUKernel() = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc new file mode 100644 index 0000000000..76dc57002a --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.cc @@ -0,0 +1,57 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "src/runtime/kernel/arm/base/squeeze_base.h" +#include +#include "src/runtime/kernel/arm/int8/squeeze_int8.h" +#include "schema/model_generated.h" +#include "src/kernel_factory.h" +#include "include/errorcode.h" +#include "include/context.h" + +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Squeeze; + +namespace mindspore::kernel { +int SqueezeBaseCPUKernel::Init() { return RET_OK; } + +kernel::LiteKernel *CpuSqueezeInt8KernelCreator(const std::vector &inputs, + const std::vector &outputs, + OpParameter *opParameter, const Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { + if (opParameter == nullptr) { + MS_LOG(ERROR) << "Input opParameter is nullptr!"; + return nullptr; + } + MS_ASSERT(desc.type == schema::PrimitiveType_Squeeze); + auto *kernel = new (std::nothrow) SqueezeInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new SqueezeCPUKernel fail!"; + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + delete kernel; + MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + return nullptr; + } + return kernel; +} + +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Squeeze, CpuSqueezeInt8KernelCreator) +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h new file mode 100644 index 0000000000..ac203e70ed --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/base/squeeze_base.h @@ -0,0 +1,52 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ + +#include +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/nnacl/squeeze_parameter.h" +#include "src/runtime/kernel/arm/base/layout_transform.h" + +using mindspore::lite::Context; + +namespace mindspore::kernel { +class SqueezeBaseCPUKernel : public LiteKernel { + public: + SqueezeBaseCPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { + opParameter->thread_num_ = ctx->thread_num_; + } + + virtual ~SqueezeBaseCPUKernel() = default; + + int Init() override; + + int ReSize() override { return 0; } + + int Run() override { return 0; } + + protected: + int thread_count_; + int *axis_; + const Context *ctx_; +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_BASE_SQUEEZE_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc index 886bec2e68..9da679e86f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.cc @@ -42,12 +42,18 @@ int StridedSliceCPUKernel::Init() { int StridedSliceCPUKernel::ReSize() { return 0; } int StridedSliceCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } + auto input = inputs_.at(0); auto output = outputs_.at(0); MS_ASSERT(input); MS_ASSERT(output); - auto ret = DoStridedSlice(input->Data(), output->Data(), reinterpret_cast(opParameter)); + ret = DoStridedSlice(input->Data(), output->Data(), reinterpret_cast(opParameter)); if (ret != RET_OK) { MS_LOG(ERROR) << "StridedSlice error error_code[" << ret << "]"; return RET_ERROR; @@ -58,13 +64,13 @@ int StridedSliceCPUKernel::Run() { kernel::LiteKernel *CpuStridedSliceKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_StridedSlice); if (opParameter == nullptr) { MS_LOG(ERROR) << "opParameter null pointer dereferencing."; return nullptr; } - auto *kernel = new (std::nothrow) StridedSliceCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) StridedSliceCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.h b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.h index f6d8845ad1..66d063c7ca 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.h +++ b/mindspore/lite/src/runtime/kernel/arm/base/strided_slice.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class StridedSliceCPUKernel : public LiteKernel { public: StridedSliceCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_num_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_num_(ctx->thread_num_) {} ~StridedSliceCPUKernel() override = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.cc index 0f2e18111c..b294bb30db 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.cc @@ -183,10 +183,14 @@ void Convolution3x3FP16CPUKernel::ConfigInputOutput() { } int Convolution3x3FP16CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; - return RET_ERROR; + return ret; } ret = InitWeightBias(); if (ret != RET_OK) { @@ -228,7 +232,7 @@ int Convolution3x3FP16CPUKernel::ReSize() { auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; - return RET_ERROR; + return ret; } ret = InitTmpBuffer(); if (ret != RET_OK) { @@ -256,7 +260,11 @@ int Convolution3x3Fp16Impl(int task_id, LiteParallelGroupEnv *penv, void *cdata) } int Convolution3x3FP16CPUKernel::Run() { - // cast fp32 input data to fp16 + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_tensor = inputs_.at(kInputIndex); auto ori_input_data = reinterpret_cast(input_tensor->Data()); for (int i = 0; i < input_tensor->ElementsNum(); ++i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.h index e6f8862e9b..8b5994be0a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_3x3_fp16.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class Convolution3x3FP16CPUKernel : public ConvolutionBaseCPUKernel { public: Convolution3x3FP16CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~Convolution3x3FP16CPUKernel() override { if (fp16_input_ != nullptr) { free(fp16_input_); @@ -78,4 +79,3 @@ void ProcessFilterFp16(float16_t *origin_weight, float16_t *dst_weight, ConvPara } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP16_CONVOLUTION_3x3_FP16_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc index ec027deacd..522dd49d90 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.cc @@ -85,14 +85,20 @@ int ConvolutionDepthwiseFp16CPUKernel::InitWeightBias() { } int ConvolutionDepthwiseFp16CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } // conv base init - ConvolutionBaseCPUKernel::Init(); - + auto ret = ConvolutionBaseCPUKernel::Init(); + if (ret != RET_OK) { + return ret; + } // init sliding_ window param sliding_ = new SlidingWindowParam; InitSlidingParam(sliding_, conv_param_, C8NUM); - auto ret = InitWeightBias(); + ret = InitWeightBias(); if (ret != 0) { MS_LOG(ERROR) << "Convolution depthwise fp16 InitWeightBias failed."; return RET_ERROR; @@ -138,6 +144,11 @@ int ConvDwFp16Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ConvolutionDepthwiseFp16CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -149,7 +160,7 @@ int ConvolutionDepthwiseFp16CPUKernel::Run() { PackNHWCFp32ToNHWC8Fp16(input_addr, packed_input_, conv_param_->input_batch_, conv_param_->input_h_ * conv_param_->input_w_, conv_param_->input_channel_); - auto ret = LiteBackendParallelLaunch(ConvDwFp16Run, this, conv_param_->thread_num_); + ret = LiteBackendParallelLaunch(ConvDwFp16Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwFp16Run error: error_code[" << ret << "]"; return RET_ERROR; @@ -165,10 +176,10 @@ int ConvolutionDepthwiseFp16CPUKernel::Run() { kernel::LiteKernel *CpuConvDwFp16KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DepthwiseConv2D); - auto kernel = new (std::nothrow) ConvolutionDepthwiseFp16CPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) ConvolutionDepthwiseFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.h index 5b81404e3e..d605ca5ba0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_depthwise_fp16.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class ConvolutionDepthwiseFp16CPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionDepthwiseFp16CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionDepthwiseFp16CPUKernel() override { delete sliding_; free(packed_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc index 92277efdf6..96ed5bc6fa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.cc @@ -23,6 +23,7 @@ #include "src/kernel_registry.h" #include "include/errorcode.h" #include "src/runtime/runtime_api.h" +#include "nnacl/winograd_utils.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; @@ -153,10 +154,14 @@ void ConvolutionFP16CPUKernel::ConfigInputOutput() { } int ConvolutionFP16CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { - MS_LOG(ERROR) << "ConvolutionBase init failed."; - return RET_ERROR; + MS_LOG(ERROR) << "ConvolutionBase init fail!ret: " << ret; + return ret; } ret = InitWeightBias(); if (ret != RET_OK) { @@ -192,7 +197,7 @@ int ConvolutionFP16CPUKernel::ReSize() { auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; - return RET_ERROR; + return ret; } ret = InitTmpBuffer(); if (ret != RET_OK) { @@ -219,7 +224,11 @@ int ConvolutionFp16Impl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ConvolutionFP16CPUKernel::Run() { - // cast fp32 input data to fp16 + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_tensor = inputs_.at(kInputIndex); auto ori_input_data = reinterpret_cast(input_tensor->Data()); for (int i = 0; i < input_tensor->ElementsNum(); ++i) { @@ -242,7 +251,7 @@ int ConvolutionFP16CPUKernel::Run() { auto out_tensor = outputs_.at(kOutputIndex); auto output_addr = reinterpret_cast(out_tensor->Data()); for (int j = 0; j < out_tensor->ElementsNum(); ++j) { - output_addr[j] = static_cast(fp16_out_[j]); + output_addr[j] = static_cast(fp16_out_[j]); } return RET_OK; } @@ -250,7 +259,7 @@ int ConvolutionFP16CPUKernel::Run() { kernel::LiteKernel *CpuConvFp16KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Conv2D); auto conv_param = reinterpret_cast(opParameter); @@ -264,20 +273,27 @@ kernel::LiteKernel *CpuConvFp16KernelCreator(const std::vectorinput_w_ = inputs.front()->Width(); conv_param->output_h_ = outputs.front()->Height(); conv_param->output_w_ = outputs.front()->Width(); - kernel::LiteKernel *kernel; + kernel::LiteKernel *kernel = nullptr; if (kernel_h == 3 && kernel_w == 3 && stride_h == 1 && stride_w == 1 && dilation_h == 1 && dilation_w == 1) { - kernel = new (std::nothrow) kernel::Convolution3x3FP16CPUKernel(opParameter, inputs, outputs, ctx); + kernel = new (std::nothrow) kernel::Convolution3x3FP16CPUKernel(opParameter, inputs, outputs, ctx, primitive); } else { - kernel = new (std::nothrow) kernel::ConvolutionFP16CPUKernel(opParameter, inputs, outputs, ctx); + bool use_winograd = false; + int out_unit; + InputTransformUnitFunc input_trans_func = nullptr; + OutputTransformUnitFunc output_trans_func = nullptr; + CheckIfUseWinograd(&use_winograd, &out_unit, conv_param, input_trans_func, output_trans_func); + if (kernel_h != 1 && kernel_w != 1 && !use_winograd) { + kernel = new (std::nothrow) kernel::ConvolutionFP16CPUKernel(opParameter, inputs, outputs, ctx, primitive); + } } if (kernel == nullptr) { - MS_LOG(ERROR) << "Create conv fp16 kernel failed."; + MS_LOG(DEBUG) << "Create conv fp16 kernel failed."; return nullptr; } auto ret = kernel->Init(); if (ret != RET_OK) { delete kernel; - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + MS_LOG(INFO) << "Init fp16 kernel failed, name: " << opParameter->name_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); return nullptr; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.h index 8be48714da..2752865650 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_fp16.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class ConvolutionFP16CPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionFP16CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionFP16CPUKernel() override { if (fp16_input_ != nullptr) { free(fp16_input_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc index 4a0097b75c..0df66a963c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc @@ -99,12 +99,19 @@ int DeconvolutionDepthwiseFp16CPUKernel::InitWeightBias() { } int DeconvolutionDepthwiseFp16CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } sliding_ = new SlidingWindowParam; InitSlideParam(); // conv base init - ConvolutionBaseCPUKernel::Init(); + auto ret = ConvolutionBaseCPUKernel::Init(); + if (ret != RET_OK) { + return ret; + } - auto ret = InitWeightBias(); + ret = InitWeightBias(); if (ret != 0) { MS_LOG(ERROR) << "Deconvolution depthwise fp16 InitWeightBias failed."; return RET_ERROR; @@ -150,6 +157,11 @@ int DeconvDwFp16Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int DeconvolutionDepthwiseFp16CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -161,7 +173,7 @@ int DeconvolutionDepthwiseFp16CPUKernel::Run() { PackNHWCFp32ToNHWC8Fp16(input_addr, packed_input_, conv_param_->input_batch_, conv_param_->input_h_ * conv_param_->input_w_, conv_param_->input_channel_); - auto ret = LiteBackendParallelLaunch(DeconvDwFp16Run, this, conv_param_->thread_num_); + ret = LiteBackendParallelLaunch(DeconvDwFp16Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "DeconvDwFp16Run error: error_code[" << ret << "]"; return RET_ERROR; @@ -176,10 +188,10 @@ int DeconvolutionDepthwiseFp16CPUKernel::Run() { kernel::LiteKernel *CpuDeconvDwFp16KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DeDepthwiseConv2D); - auto kernel = new (std::nothrow) DeconvolutionDepthwiseFp16CPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) DeconvolutionDepthwiseFp16CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.h index 0e3a31682c..64807fa9d8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class DeconvolutionDepthwiseFp16CPUKernel : public ConvolutionBaseCPUKernel { public: DeconvolutionDepthwiseFp16CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~DeconvolutionDepthwiseFp16CPUKernel() override { delete sliding_; free(packed_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc index e4fda400a4..756fa678fb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/activation.cc @@ -19,6 +19,7 @@ #include "src/kernel_registry.h" #include "src/runtime/runtime_api.h" #include "include/errorcode.h" +#include "src/ops/ops.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; @@ -78,6 +79,11 @@ int ActivationRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ActivationCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } int error_code = LiteBackendParallelLaunch(ActivationRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Activation function error error_code[" << error_code << "]"; @@ -89,10 +95,10 @@ int ActivationCPUKernel::Run() { kernel::LiteKernel *CpuActivationFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Activation); - auto *kernel = new (std::nothrow) ActivationCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ActivationCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/activation.h b/mindspore/lite/src/runtime/kernel/arm/fp32/activation.h index 2e21629d79..3ecc6e9f62 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/activation.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/activation.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class ActivationCPUKernel : public LiteKernel { public: ActivationCPUKernel(OpParameter *param, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(param, inputs, outputs), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(param, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) { type_ = (reinterpret_cast(param))->type_; alpha_ = (reinterpret_cast(param))->alpha_; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc index 226843c805..7ae87bcd5b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.cc @@ -36,12 +36,9 @@ int AddNLaunch(int thread_id, LiteParallelGroupEnv *penv, void *cdata) { auto kernel = reinterpret_cast(cdata); return kernel->AddNParallelRun(thread_id); } -} +} // namespace -int AddNCPUKernel::Init() { - elements_num_ = inputs_[0]->ElementsNum(); - return RET_OK; -} +int AddNCPUKernel::Init() { return RET_OK; } int AddNCPUKernel::ReSize() { return RET_OK; } @@ -58,6 +55,12 @@ int AddNCPUKernel::AddNParallelRun(int thread_id) { } int AddNCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } + elements_num_ = inputs_[0]->ElementsNum(); auto input0_data = reinterpret_cast(inputs_[0]->Data()); auto input1_data = reinterpret_cast(inputs_[1]->Data()); auto output_data = reinterpret_cast(outputs_[0]->Data()); @@ -71,7 +74,7 @@ int AddNCPUKernel::Run() { in1_addr_ = input0_data; in2_addr_ = input1_data; out_addr_ = output_data; - int ret = LiteBackendParallelLaunch(AddNLaunch, this, opParameter->thread_num_); + ret = LiteBackendParallelLaunch(AddNLaunch, this, opParameter->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "addn launch fail!ret: " << ret; return RET_ERROR; @@ -91,7 +94,7 @@ int AddNCPUKernel::Run() { kernel::LiteKernel *CpuAddNFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; @@ -102,7 +105,7 @@ kernel::LiteKernel *CpuAddNFp32KernelCreator(const std::vectorthread_num_ = ctx->thread_num_; - auto *kernel = new (std::nothrow) AddNCPUKernel(op_parameter, inputs, outputs); + auto *kernel = new (std::nothrow) AddNCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new AddNCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.h b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.h index 43d27fad02..31a2fecfa0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/addn.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/addn.h @@ -21,18 +21,20 @@ #include "src/lite_kernel.h" #include "schema/model_generated.h" - namespace mindspore::kernel { class AddNCPUKernel : public LiteKernel { public: AddNCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~AddNCPUKernel() = default; int Init() override; int ReSize() override; int Run() override; int AddNParallelRun(int thread_id); + private: float *in1_addr_; float *in2_addr_; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc index a89eb715fd..a9cb85147c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.cc @@ -36,11 +36,24 @@ int ArgMinMaxCPUKernel::Init() { } auto param = reinterpret_cast(opParameter); param->data_type_ = kNumberTypeFloat32; - return RET_OK; + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int ArgMinMaxCPUKernel::ReSize() { + ArgMinMaxBaseCPUKernel::FreeTmpMemory(); + return ArgMinMaxBaseCPUKernel::ReSize(); } int ArgMinMaxCPUKernel::Run() { - auto ret = ArgMinMaxBaseCPUKernel::Run(); + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << ret; + return ret; + } + ret = ArgMinMaxBaseCPUKernel::Run(); ArgMinMaxBaseCPUKernel::FreeTmpMemory(); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.h b/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.h index c6c4fb9be7..611e28ea6c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/argminmax.h @@ -23,16 +23,16 @@ namespace mindspore::kernel { class ArgMinMaxCPUKernel : public ArgMinMaxBaseCPUKernel { public: ArgMinMaxCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : ArgMinMaxBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ArgMinMaxBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ArgMinMaxCPUKernel() = default; int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ARGMINMAX_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc index 3d3d55f894..c8e01d387c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.cc @@ -41,6 +41,10 @@ ArithmeticCPUKernel::~ArithmeticCPUKernel() { } } int ArithmeticCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto element_num = outputs_[0]->ElementsNum(); tile_data0_ = new float[element_num]; @@ -92,6 +96,11 @@ int ArithmeticsRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ArithmeticCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } if (arithmeticParameter_->broadcasting_) { auto input_data0 = reinterpret_cast(inputs_[0]->Data()); auto input_data1 = reinterpret_cast(inputs_[1]->Data()); @@ -108,9 +117,9 @@ int ArithmeticCPUKernel::Run() { kernel::LiteKernel *CpuArithmeticFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(parameter != nullptr); - auto kernel = new (std::nothrow) ArithmeticCPUKernel(parameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) ArithmeticCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.h b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.h index 9fae6696c8..a24ee75372 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic.h @@ -48,8 +48,9 @@ class ArithmeticCPUKernel : public LiteKernel { public: ArithmeticCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) { arithmeticParameter_ = reinterpret_cast(parameter); switch (parameter->type_) { case PrimitiveType_Mul: diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc index d65ef0d1c9..88c7e6cd0a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.cc @@ -27,6 +27,10 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int ArithmeticSelfCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } int ret = ReSize(); return ret; } @@ -68,11 +72,16 @@ int ArithmeticSelfCPUKernel::DoArithmeticSelf(int task_id) { } int ArithmeticSelfCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } auto input_tensor = inputs_.at(0); auto out_tensor = outputs_.at(0); in_ptr_ = reinterpret_cast(input_tensor->Data()); out_ptr_ = reinterpret_cast(out_tensor->Data()); - int ret = LiteBackendParallelLaunch(ArithmeticSelfRuns, this, thread_sz_count_); + ret = LiteBackendParallelLaunch(ArithmeticSelfRuns, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; return ret; @@ -83,13 +92,14 @@ int ArithmeticSelfCPUKernel::Run() { kernel::LiteKernel *CpuArithmeticSelfFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); if (opParameter == nullptr) { MS_LOG(ERROR) << "Creator failed, opParameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) ArithmeticSelfCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ArithmeticSelfCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); if (ret != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.h b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.h index bcc56820db..d17a97a914 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_self.h @@ -24,9 +24,9 @@ #include "schema/model_generated.h" #include "include/context.h" - using mindspore::lite::Context; using mindspore::schema::PrimitiveType_Abs; +using mindspore::schema::PrimitiveType_Ceil; using mindspore::schema::PrimitiveType_Cos; using mindspore::schema::PrimitiveType_Exp; using mindspore::schema::PrimitiveType_Floor; @@ -36,7 +36,6 @@ using mindspore::schema::PrimitiveType_Rsqrt; using mindspore::schema::PrimitiveType_Sin; using mindspore::schema::PrimitiveType_Sqrt; using mindspore::schema::PrimitiveType_Square; -using mindspore::schema::PrimitiveType_Ceil; namespace mindspore::kernel { class ArithmeticSelfCPUKernel : public LiteKernel { @@ -44,8 +43,9 @@ class ArithmeticSelfCPUKernel : public LiteKernel { public: explicit ArithmeticSelfCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { switch (parameter->type_) { case PrimitiveType_Abs: arithmeticSelf_run_ = ElementAbs; @@ -106,4 +106,3 @@ class ArithmeticSelfCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ARITHMETIC_SELF_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc index a24cae52de..e42193d9f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.cc @@ -24,10 +24,27 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int BatchToSpaceCPUKernel::Init() { - return BatchToSpaceBaseCPUKernel::Init(); + auto ret = BatchToSpaceBaseCPUKernel::Init(); + if (ret != RET_OK) { + return ret; + } + + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int BatchToSpaceCPUKernel::ReSize() { + return BatchToSpaceBaseCPUKernel::ReSize(); } int BatchToSpaceCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = inputs_[0]; auto output = outputs_[0]; const float *input_data = reinterpret_cast(input->Data()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.h b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.h index 2933bee478..a8060726a6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batch_to_space.h @@ -22,16 +22,16 @@ namespace mindspore::kernel { class BatchToSpaceCPUKernel : public BatchToSpaceBaseCPUKernel { public: BatchToSpaceCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : BatchToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : BatchToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~BatchToSpaceCPUKernel() = default; int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BATCH_TO_SPACE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc index 063fd4f6aa..4a827a78ee 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.cc @@ -28,17 +28,23 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_BatchNorm; namespace mindspore::kernel { -int BatchnormCPUKernel::Init() { return RET_OK; } +int BatchnormCPUKernel::Init() { + auto input_shapes = inputs_[0]->shape(); + auto n_dim = input_shapes.size(); + batchnorm_param_->channel_ = input_shapes[n_dim - 1]; + batchnorm_param_->unit_ = 1; + for (int i = 0; i < n_dim - 1; i++) { + batchnorm_param_->unit_ *= input_shapes[i]; + } + batchnorm_param_->op_parameter_.thread_num_ = + MSMIN(batchnorm_param_->op_parameter_.thread_num_, batchnorm_param_->unit_); + return RET_OK; +} int BatchnormCPUKernel::ReSize() { return RET_OK; } -int BatchnormCPUKernel::DoExecute(int tid) { - int count = MSMIN(thread_unit_, units_ - tid * thread_unit_); - if (count <= 0) { - return RET_OK; - } - int offset = tid * thread_unit_ * channel_; - BatchNorm(in_addr_ + offset, mean_addr_, var_addr_, count, channel_, batchnorm_param_->epsilon_, out_addr_ + offset); +int BatchnormCPUKernel::DoExecute(int task_id) { + BatchNorm(out_addr_, in_addr_, mean_addr_, var_addr_, task_id, batchnorm_param_); return RET_OK; } @@ -53,19 +59,17 @@ int BatchNormRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int BatchnormCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } in_addr_ = reinterpret_cast(inputs_.at(0)->Data()); mean_addr_ = reinterpret_cast(inputs_.at(1)->Data()); var_addr_ = reinterpret_cast(inputs_.at(2)->Data()); out_addr_ = reinterpret_cast(outputs_.at(0)->Data()); - auto input_shapes = inputs_[0]->shape(); - channel_ = input_shapes[3]; - units_ = 1; - for (int i = 0; i < 3; i++) { - units_ *= input_shapes[i]; - } - thread_count_ = MSMIN(thread_count_, units_); - thread_unit_ = UP_DIV(units_, thread_count_); - int ret = LiteBackendParallelLaunch(BatchNormRun, this, thread_count_); + + int ret = LiteBackendParallelLaunch(BatchNormRun, this, batchnorm_param_->op_parameter_.thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "BatchnormRun error error_code[" << ret << "]"; return ret; @@ -76,10 +80,10 @@ int BatchnormCPUKernel::Run() { kernel::LiteKernel *CpuBatchnormKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_BatchNorm); - auto *kernel = new (std::nothrow) BatchnormCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) BatchnormCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new BatchNormCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.h b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.h index e29aa20a2f..4ad0224511 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/batchnorm.h @@ -28,11 +28,13 @@ namespace mindspore::kernel { class BatchnormCPUKernel : public LiteKernel { public: BatchnormCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + opParameter->thread_num_ = ctx->thread_num_; batchnorm_param_ = reinterpret_cast(parameter); } - ~BatchnormCPUKernel() override { delete batchnorm_param_; } + ~BatchnormCPUKernel() override = default; int Init() override; int ReSize() override; @@ -40,15 +42,10 @@ class BatchnormCPUKernel : public LiteKernel { int DoExecute(int tid); private: - int thread_count_; - int thread_unit_; - int units_; - int channel_; float *in_addr_; float *mean_addr_; float *var_addr_; float *out_addr_; - const Context *ctx_; BatchNormParameter *batchnorm_param_; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc index 9464b342a2..8d3d99d7b9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.cc @@ -31,6 +31,11 @@ namespace mindspore::kernel { int BiasCPUKernel::ReSize() { return RET_OK; } int BiasCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto in = reinterpret_cast(inputs_.at(0)->Data()); auto bias = reinterpret_cast(inputs_.at(1)->Data()); auto out = reinterpret_cast(outputs_.at(0)->Data()); @@ -44,6 +49,10 @@ int BiasCPUKernel::Run() { } int BiasCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto dims = inputs_[0]->shape(); MS_ASSERT(dims.size() <= 5); bias_param_->ndim_ = dims.size(); @@ -58,10 +67,11 @@ int BiasCPUKernel::Init() { kernel::LiteKernel *CpuBiasFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, - const lite::Context *ctx, const kernel::KernelKey &desc) { + const lite::Context *ctx, const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(parameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_BiasAdd); - auto kernel = new (std::nothrow) BiasCPUKernel(parameter, inputs, outputs); + auto kernel = new (std::nothrow) BiasCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.h b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.h index a4d88378fd..0282c668cb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bias.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/bias.h @@ -24,9 +24,10 @@ namespace mindspore::kernel { class BiasCPUKernel : public LiteKernel { public: BiasCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) { - bias_param_ = reinterpret_cast(parameter); + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + bias_param_ = reinterpret_cast(parameter); } ~BiasCPUKernel() override = default; @@ -40,4 +41,3 @@ class BiasCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BIAS_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc index ed5ffd9822..84e4366e3d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.cc @@ -27,6 +27,10 @@ using mindspore::schema::PrimitiveType_BroadcastTo; namespace mindspore::kernel { int BroadcastToCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto input_shape = inputs_[0]->shape(); for (size_t i = 0; i < input_shape.size(); ++i) { shape_info_.input_shape_[i] = input_shape[i]; @@ -42,6 +46,11 @@ int BroadcastToCPUKernel::Init() { } int BroadcastToCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input_data = reinterpret_cast(inputs_.at(0)->Data()); auto output_data = reinterpret_cast(outputs_.at(0)->Data()); @@ -51,13 +60,13 @@ int BroadcastToCPUKernel::Run() { kernel::LiteKernel *CpuBroadcastToFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_BroadcastTo); - auto *kernel = new (std::nothrow) BroadcastToCPUKernel(op_parameter, inputs, outputs); + auto *kernel = new (std::nothrow) BroadcastToCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new BroadcastToCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.h b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.h index cfb8969448..c0cefc522b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/broadcast_to.h @@ -25,18 +25,18 @@ namespace mindspore::kernel { class BroadcastToCPUKernel : public LiteKernel { public: BroadcastToCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~BroadcastToCPUKernel() = default; int Init() override; - int ReSize() override { - return 0; - } + int ReSize() override { return 0; } int Run() override; + private: BroadcastShapeInfo shape_info_; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BROADCAST_TO_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc index b17bc4bb7a..efcf7f04fc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/cast.cc @@ -30,9 +30,6 @@ using mindspore::schema::PrimitiveType_Cast; namespace mindspore::kernel { namespace { -constexpr int kInputNum = 1; -constexpr int kOutputNum = 1; -const std::vector kSupportInputDataType = {kNumberTypeUInt8, kNumberTypeInt32}; int CastRun(int thread_id, LiteParallelGroupEnv *penv, void *cdata) { if (cdata == nullptr) { MS_LOG(ERROR) << "input cdata is nullptr!"; @@ -44,12 +41,16 @@ int CastRun(int thread_id, LiteParallelGroupEnv *penv, void *cdata) { } // namespace int CastCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } data_num_ = inputs_[0]->ElementsNum(); if (data_num_ == 0) { return RET_OK; } - thread_num_ = MSMIN(thread_num_, data_num_); - stride_ = UP_DIV(data_num_, thread_num_); + opParameter->thread_num_ = MSMIN(opParameter->thread_num_, data_num_); + stride_ = UP_DIV(data_num_, opParameter->thread_num_); return RET_OK; } @@ -77,16 +78,21 @@ int CastCPUKernel::DoCast(int thread_id) { } int CastCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } if (data_num_ == 0) { return RET_OK; } - return LiteBackendParallelLaunch(CastRun, this, thread_num_); + return LiteBackendParallelLaunch(CastRun, this, opParameter->thread_num_); } kernel::LiteKernel *CpuCastFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; @@ -99,7 +105,7 @@ kernel::LiteKernel *CpuCastFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs) { - if (ctx != nullptr) { - thread_num_ = ctx->thread_num_; - } + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + opParameter->thread_num_ = ctx->thread_num_; } ~CastCPUKernel() = default; int Init() override; - int ReSize() override { - return 0; - }; + int ReSize() override { return 0; }; int Run() override; int DoCast(int thread_id); + private: - uint32_t thread_num_; uint32_t stride_; uint32_t data_num_; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CAST_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc index df3ba83c5c..2ba7ca8fe8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/concat.cc @@ -28,44 +28,54 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Concat; namespace mindspore::kernel { - int ConcatCPUKernel::Init() { - ConcatBaseCPUKernel::Init(); - schema::Format input0_format = inputs_[0]->GetFormat(); - bool need_convert_format = false; - for (size_t i = 1; i < inputs_.size(); ++i) { - if (inputs_[i]->GetFormat() != input0_format) { - need_convert_format = true; - } - } - if (!need_convert_format) { - outputs_[0]->SetFormat(input0_format); - return RET_OK; - } - MS_LOG(ERROR) << "All input format should be the same!"; - return RET_ERROR; +int ConcatCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } + auto ret = ConcatBaseCPUKernel::Init(); + if (ret != RET_OK) { + return ret; + } + schema::Format input0_format = inputs_[0]->GetFormat(); + bool need_convert_format = false; + for (size_t i = 1; i < inputs_.size(); ++i) { + if (inputs_[i]->GetFormat() != input0_format) { + need_convert_format = true; } + } + if (!need_convert_format) { + outputs_[0]->SetFormat(input0_format); + return RET_OK; + } + MS_LOG(ERROR) << "All input format should be the same!"; + return RET_ERROR; +} - int ConcatCPUKernel::ReSize() { return RET_OK; } +int ConcatCPUKernel::ReSize() { return RET_OK; } - int ConcatCPUKernel::Run() { - auto input_num = inputs_.size(); - std::vector inputs_addr(input_num, nullptr); - std::vector inputs_output_shape(input_num + 1, nullptr); +int ConcatCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } + auto input_num = inputs_.size(); + std::vector inputs_addr(input_num, nullptr); + std::vector inputs_output_shape(input_num + 1, nullptr); - std::vector > shapes; - for (size_t i = 0; i < input_num; ++i) { - inputs_addr[i] = inputs_[i]->Data(); - shapes.push_back(inputs_[i]->shape()); - inputs_output_shape[i] = shapes[i].data(); - } - auto output_shape = outputs_.at(0)->shape(); - inputs_output_shape[input_num] = output_shape.data(); - auto output_addr = outputs_.at(0)->Data(); + std::vector> shapes; + for (size_t i = 0; i < input_num; ++i) { + inputs_addr[i] = inputs_[i]->Data(); + shapes.push_back(inputs_[i]->shape()); + inputs_output_shape[i] = shapes[i].data(); + } + auto output_shape = outputs_.at(0)->shape(); + inputs_output_shape[input_num] = output_shape.data(); + auto output_addr = outputs_.at(0)->Data(); - Concat(reinterpret_cast(inputs_addr.data()), input_num, axis_, inputs_output_shape.data(), - output_shape.size(), output_addr); - return RET_OK; - } + Concat(reinterpret_cast(inputs_addr.data()), input_num, axis_, inputs_output_shape.data(), + output_shape.size(), output_addr); + return RET_OK; +} } // namespace mindspore::kernel - - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/concat.h b/mindspore/lite/src/runtime/kernel/arm/fp32/concat.h index 078921a53d..cafd6c84f7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/concat.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/concat.h @@ -28,8 +28,9 @@ namespace mindspore::kernel { class ConcatCPUKernel : public ConcatBaseCPUKernel { public: ConcatCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConcatBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConcatBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConcatCPUKernel() = default; @@ -42,4 +43,3 @@ class ConcatCPUKernel : public ConcatBaseCPUKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONCAT_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc index bee5e46e75..20d3668c94 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.cc @@ -15,6 +15,7 @@ */ #include "src/runtime/kernel/arm/fp32/convolution.h" +#include "src/runtime/kernel/arm/fp32/convolution_slidewindow.h" #include "src/runtime/kernel/arm/fp32/convolution_1x1.h" #include "src/runtime/kernel/arm/fp32/convolution_3x3.h" #include "src/runtime/kernel/arm/fp32/convolution_winograd.h" @@ -28,6 +29,7 @@ using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_INFER_INVALID; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Conv2D; @@ -136,6 +138,10 @@ void ConvolutionCPUKernel::ConfigInputOutput() { } int ConvolutionCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; @@ -204,6 +210,11 @@ int ConvolutionImpl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ConvolutionCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input_tensor = inputs_.at(kInputIndex); auto ori_input_data = input_tensor->Data(); int in_batch = conv_param_->input_batch_; @@ -220,36 +231,23 @@ int ConvolutionCPUKernel::Run() { return RET_OK; } -void CheckIfUseWinograd(bool *use_winograd, int *output_unit, ConvParameter *conv_param, - InputTransformUnitFunc input_trans_func, OutputTransformUnitFunc output_trans_func) { - if (conv_param->kernel_w_ == conv_param->kernel_h_ && conv_param->dilation_h_ == 1 && conv_param->dilation_w_ == 1 && - conv_param->stride_h_ == 1 && conv_param->stride_w_ == 1) { - *output_unit = SelectOutputUnit(conv_param); - if (*output_unit > 1) { - *use_winograd = true; - int input_unit = conv_param->kernel_h_ + *output_unit - 1; - input_trans_func = GetInputTransFunc(input_unit); - if (input_trans_func == nullptr) { - MS_LOG(INFO) << "No matching input trans func. Turn back to common conv."; - *use_winograd = false; - } - output_trans_func = GetOutputTransFunc(input_unit, *output_unit); - if (output_trans_func == nullptr) { - MS_LOG(INFO) << "No matching output trans func. Turn back to common conv."; - *use_winograd = false; - } - } else { - *use_winograd = false; - } - } else { - *use_winograd = false; +bool CheckIfUseSlideWindow(ConvParameter *conv_param) { + int in_channel = conv_param->input_channel_; + int out_h = conv_param->output_h_; + int out_w = conv_param->output_w_; + int out_channel = conv_param->output_channel_; + int ic4 = UP_DIV(in_channel, C4NUM); + int oc4 = UP_DIV(out_channel, C4NUM); + if (out_h * out_w <= 32 || ic4 < 4 || oc4 < 4) { + return true; } + return false; } kernel::LiteKernel *CpuConvFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Conv2D); auto conv_param = reinterpret_cast(opParameter); @@ -268,22 +266,27 @@ kernel::LiteKernel *CpuConvFp32KernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != RET_OK && ret != RET_INFER_INVALID) { delete kernel; MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.h index 9e79609280..20642484c9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class ConvolutionCPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionCPUKernel() override { if (packed_input_ != nullptr) { free(packed_input_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc index e2456bfdf4..d5f11a5104 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.cc @@ -136,6 +136,10 @@ void Convolution1x1CPUKernel::Pre1x1Trans(float *src_input, float *src_output) { } int Convolution1x1CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } ConvolutionBaseCPUKernel::Init(); InitConv1x1MatmulParam(); @@ -167,6 +171,17 @@ int Convolution1x1CPUKernel::DoConv1x1(int task_id) { return RET_OK; } +int Convolution1x1CPUKernel::DoConv1x1Post(int task_id) { + int cur_oc = MSMIN(thread_stride_, matmul_param_->col_ - task_id * thread_stride_); + if (cur_oc <= 0) { + return RET_OK; + } + float *src = pack_output_ + task_id * thread_stride_ * matmul_param_->row_8_; + float *dst = output_ptr_ + task_id * thread_stride_; + Row8x8Major2RowMajor(src, dst, matmul_param_->row_, cur_oc, matmul_param_->col_); + return RET_OK; +} + int Convolution1x1Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { auto conv1x1 = reinterpret_cast(cdata); auto error_code = conv1x1->DoConv1x1(task_id); @@ -177,7 +192,18 @@ int Convolution1x1Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { return RET_OK; } +int Convolution1x1Post(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto conv1x1 = reinterpret_cast(cdata); + conv1x1->DoConv1x1Post(task_id); + return RET_OK; +} + int Convolution1x1CPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto src_in = reinterpret_cast(inputs_[0]->Data()); auto src_out = reinterpret_cast(outputs_[0]->Data()); @@ -191,7 +217,7 @@ int Convolution1x1CPUKernel::Run() { return RET_ERROR; } - Row8x8Major2RowMajor(pack_output_, output_ptr_, matmul_param_->row_, matmul_param_->col_); + LiteBackendParallelLaunch(Convolution1x1Post, this, thread_count_); } return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.h index 6d5840e017..47511fee54 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_1x1.h @@ -27,15 +27,16 @@ #include "src/runtime/kernel/arm/base/layout_transform.h" #include "src/runtime/kernel/arm/nnacl/fp32/conv.h" #include "src/runtime/kernel/arm/nnacl/fp32/common_func.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" #include "src/runtime/kernel/arm/nnacl/fp32/matmul.h" namespace mindspore::kernel { class Convolution1x1CPUKernel : public ConvolutionBaseCPUKernel { public: Convolution1x1CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) { matmul_param_ = new MatMulParameter(); } ~Convolution1x1CPUKernel(); @@ -45,6 +46,7 @@ class Convolution1x1CPUKernel : public ConvolutionBaseCPUKernel { public: int DoConv1x1(int task_id); + int DoConv1x1Post(int task_id); private: int InitConv1x1Param(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.cc index aa1f363010..9bd829bb67 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.cc @@ -166,6 +166,10 @@ void Convolution3x3CPUKernel::ConfigInputOutput() { } int Convolution3x3CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; @@ -237,6 +241,11 @@ int Convolution3x3Impl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int Convolution3x3CPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input_tensor = inputs_.at(kInputIndex); auto ori_input_data = input_tensor->Data(); int in_batch = conv_param_->input_batch_; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.h index 90dbac5a6f..f0aa53ca79 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_3x3.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class Convolution3x3CPUKernel : public ConvolutionBaseCPUKernel { public: Convolution3x3CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~Convolution3x3CPUKernel() override { if (transformed_filter_addr_ != nullptr) { free(transformed_filter_addr_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc index 6eec3f91aa..0de33adb56 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.cc @@ -24,6 +24,7 @@ using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_INFER_INVALID; using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_DepthwiseConv2D; @@ -86,12 +87,16 @@ int ConvolutionDepthwiseCPUKernel::InitBuffer() { } int ConvolutionDepthwiseCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } // conv base init ConvolutionBaseCPUKernel::Init(); // init sliding window param sliding_ = new SlidingWindowParam; - InitSlidingParam(sliding_, conv_param_, C4NUM); + InitSlidingParamConvDw(sliding_, conv_param_, C4NUM); auto ret = InitWeightBias(); if (ret != 0) { @@ -117,7 +122,7 @@ int ConvolutionDepthwiseCPUKernel::ReSize() { // init sliding window param sliding_ = new SlidingWindowParam; - InitSlidingParam(sliding_, conv_param_, C4NUM); + InitSlidingParamConvDw(sliding_, conv_param_, C4NUM); auto ret = InitBuffer(); if (ret != 0) { @@ -144,6 +149,11 @@ int ConvDwRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ConvolutionDepthwiseCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -164,7 +174,7 @@ int ConvolutionDepthwiseCPUKernel::Run() { packed_output_ = output_addr; } - auto ret = LiteBackendParallelLaunch(ConvDwRun, this, conv_param_->thread_num_); + ret = LiteBackendParallelLaunch(ConvDwRun, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwRun error: error_code[" << ret << "]"; return RET_ERROR; @@ -180,11 +190,11 @@ int ConvolutionDepthwiseCPUKernel::Run() { kernel::LiteKernel *CpuConvDwFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DepthwiseConv2D); kernel::LiteKernel *kernel; - kernel = new (std::nothrow) kernel::ConvolutionDepthwiseCPUKernel(opParameter, inputs, outputs, ctx); + kernel = new (std::nothrow) kernel::ConvolutionDepthwiseCPUKernel(opParameter, inputs, outputs, ctx, primitive); // auto param = reinterpret_cast(opParameter); // if (param->kernel_h_ == 3 && param->kernel_w_ == 3 && param->stride_h_ == 1 && param->stride_w_ == 1 && // param->dilation_h_ == 1 && param->dilation_w_ == 1) { @@ -192,12 +202,13 @@ kernel::LiteKernel *CpuConvDwFp32KernelCreator(const std::vectorInit(); - if (ret != RET_OK) { + if (ret != RET_OK && ret != RET_INFER_INVALID) { delete kernel; MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.h index e0d742c6ae..08706ac050 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class ConvolutionDepthwiseCPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionDepthwiseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionDepthwiseCPUKernel() override { delete sliding_; free(packed_weight_); @@ -55,4 +56,3 @@ class ConvolutionDepthwiseCPUKernel : public ConvolutionBaseCPUKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_DEPTHWISE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.cc index 6f2322255b..798cd72a04 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.cc @@ -100,6 +100,10 @@ int ConvolutionDepthwise3x3CPUKernel::InitBuffer() { } int ConvolutionDepthwise3x3CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } // conv base init ConvolutionBaseCPUKernel::Init(); @@ -164,6 +168,11 @@ int ConvDw3x3Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ConvolutionDepthwise3x3CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -184,7 +193,7 @@ int ConvolutionDepthwise3x3CPUKernel::Run() { packed_output_ = output_addr; } - auto ret = LiteBackendParallelLaunch(ConvDw3x3Run, this, conv_param_->thread_num_); + ret = LiteBackendParallelLaunch(ConvDw3x3Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDw3x3Run error: error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.h index 63f3d35cd2..ee937456da 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_3x3.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class ConvolutionDepthwise3x3CPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionDepthwise3x3CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionDepthwise3x3CPUKernel() override { free(packed_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow.cc new file mode 100644 index 0000000000..15a493542a --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow.cc @@ -0,0 +1,211 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "src/runtime/kernel/arm/fp32/convolution_slidewindow.h" +#include "src/runtime/kernel/arm/nnacl/common_func.h" +#include "schema/model_generated.h" +#include "src/kernel_factory.h" +#include "include/errorcode.h" +#include "src/runtime/runtime_api.h" + +namespace mindspore::kernel { +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_INFER_INVALID; +using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Conv2D; + +int ConvolutionSWCPUKernel::InitWeightBias() { + int kernel_h = conv_param_->kernel_h_; + int kernel_w = conv_param_->kernel_w_; + int in_channel = conv_param_->input_channel_; + int out_channel = conv_param_->output_channel_; + int ic4 = UP_DIV(in_channel, C4NUM); + int kernel_plane = kernel_h * kernel_w; + int oc_block = C4NUM; + int oc_block_num = UP_DIV(out_channel, C4NUM); + int pack_weight_size = oc_block_num * oc_block * ic4 * C4NUM * kernel_plane; + + // ==================================init weight======================================// + auto origin_weight = reinterpret_cast(inputs_.at(kWeightIndex)->Data()); + packed_weight_ = reinterpret_cast(malloc(pack_weight_size * sizeof(float))); + if (packed_weight_ == nullptr) { + MS_LOG(ERROR) << "malloc packed weight failed."; + return RET_ERROR; + } + memset(packed_weight_, 0, pack_weight_size * sizeof(float)); + for (int oc = 0; oc < out_channel; ++oc) { + int src_oc_offset = oc * kernel_h * kernel_w * in_channel; + int dst_oc_offset = oc * kernel_h * kernel_w * ic4 * C4NUM; + for (int i = 0; i < kernel_h * kernel_w; ++i) { + const float *src = origin_weight + src_oc_offset + i * in_channel; + float *dst = packed_weight_ + dst_oc_offset + i * ic4 * C4NUM; + memcpy(dst, src, in_channel * sizeof(float)); + } + } + + // ====================================init bias====================================== // + bias_data_ = reinterpret_cast(malloc(oc_block_num * oc_block * sizeof(float))); + if (bias_data_ == nullptr) { + MS_LOG(ERROR) << "malloc bias failed."; + return RET_ERROR; + } + memset(bias_data_, 0, oc_block_num * oc_block * sizeof(float)); + if (inputs_.size() == kInputSize2) { + auto ori_bias = reinterpret_cast(inputs_.at(kBiasIndex)->Data()); + memcpy(bias_data_, ori_bias, out_channel * sizeof(float)); + } else { + MS_ASSERT(inputs_.size() == kInputSize1); + } + return RET_OK; +} + +int ConvolutionSWCPUKernel::InitTmpBuffer() { + int in_channel = conv_param_->input_channel_; + int ic4 = UP_DIV(in_channel, C4NUM); + int out_channel = conv_param_->output_channel_; + int oc4 = UP_DIV(out_channel, C4NUM); + + /*=============================nhwc4_input_============================*/ + size_t nhwc4_input_size = + ic4 * C4NUM * conv_param_->input_batch_ * conv_param_->input_h_ * conv_param_->input_w_ * sizeof(float); + nhwc4_input_ = malloc(nhwc4_input_size); + if (nhwc4_input_ == nullptr) { + MS_LOG(ERROR) << "malloc nhwc4 input failed."; + return RET_ERROR; + } + memset(nhwc4_input_, 0, nhwc4_input_size); + + /*=============================tmp_output_block_============================*/ + tmp_output_block_ = reinterpret_cast( + malloc(conv_param_->output_batch_ * conv_param_->output_h_ * conv_param_->output_w_ * oc4 * C4NUM * sizeof(float))); + if (tmp_output_block_ == nullptr) { + MS_LOG(ERROR) << "malloc tmp output block failed."; + return RET_ERROR; + } + return RET_OK; +} + +void ConvolutionSWCPUKernel::ConfigInputOutput() { + // set output format + auto output_tensor = outputs_.at(kOutputIndex); + output_tensor->SetFormat(schema::Format_NHWC); + + // select trans func for input + auto input_tensor = inputs_.at(kInputIndex); + auto ret = CheckLayout(input_tensor); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Check layout failed."; + return; + } +} + +int ConvolutionSWCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } + auto ret = ConvolutionBaseCPUKernel::Init(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "ConvolutionBase init failed."; + return RET_ERROR; + } + ret = InitWeightBias(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Init weight bias failed."; + return RET_ERROR; + } + // init tmp input, output + ret = InitTmpBuffer(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Init tmp buffer failed."; + return RET_ERROR; + } + // init sliding window param + slidingWindow_param_ = new SlidingWindowParam; + InitSlidingParamConv(slidingWindow_param_, conv_param_, C4NUM); + + // config input output + ConfigInputOutput(); + return RET_OK; +} + +int ConvolutionSWCPUKernel::ReSize() { + if (tmp_output_block_ != nullptr) { + free(tmp_output_block_); + } + if (nhwc4_input_ != nullptr) { + free(nhwc4_input_); + } + delete slidingWindow_param_; + + auto ret = ConvolutionBaseCPUKernel::Init(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "ConvolutionBase init failed."; + return RET_ERROR; + } + // init tmp input, output + ret = InitTmpBuffer(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Init tmp buffer failed."; + return RET_ERROR; + } + // init sliding window param + slidingWindow_param_ = new SlidingWindowParam; + InitSlidingParamConv(slidingWindow_param_, conv_param_, C4NUM); + return RET_OK; +} + +int ConvolutionSWCPUKernel::RunImpl(int task_id) { + auto output_addr = reinterpret_cast(outputs_.at(kOutputIndex)->Data()); + ConvSWFp32(reinterpret_cast(nhwc4_input_), packed_weight_, reinterpret_cast(bias_data_), + tmp_output_block_, output_addr, task_id, conv_param_, slidingWindow_param_); + return RET_OK; +} + +int ConvolutionSWImpl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto conv = reinterpret_cast(cdata); + auto error_code = conv->RunImpl(task_id); + if (error_code != RET_OK) { + MS_LOG(ERROR) << "Convolution Sliding Window Run error task_id[" << task_id << "] error_code[" << error_code << "]"; + return RET_ERROR; + } + return RET_OK; +} + +int ConvolutionSWCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } + auto input_tensor = inputs_.at(kInputIndex); + auto ori_input_data = input_tensor->Data(); + int in_batch = conv_param_->input_batch_; + int in_h = conv_param_->input_h_; + int in_w = conv_param_->input_w_; + int in_channel = conv_param_->input_channel_; + convert_func_(ori_input_data, nhwc4_input_, in_batch, in_h * in_w, in_channel); + + int error_code = LiteBackendParallelLaunch(ConvolutionSWImpl, this, thread_count_); + if (error_code != RET_OK) { + MS_LOG(ERROR) << "conv error error_code[" << error_code << "]"; + return RET_ERROR; + } + return RET_OK; +} +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow.h new file mode 100644 index 0000000000..ca63aa9378 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_slidewindow.h @@ -0,0 +1,59 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_SLIDEWINDOW_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_SLIDEWINDOW_H_ + +#include +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "src/runtime/kernel/arm/base/convolution_base.h" +#include "src/runtime/kernel/arm/nnacl/fp32/conv.h" +#include "src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h" + +namespace mindspore::kernel { +class ConvolutionSWCPUKernel : public ConvolutionBaseCPUKernel { + public: + ConvolutionSWCPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + + ~ConvolutionSWCPUKernel() override { + if (packed_weight_ != nullptr) { + free(packed_weight_); + } + if (tmp_output_block_ != nullptr) { + free(tmp_output_block_); + } + delete slidingWindow_param_; + }; + + int Init() override; + int ReSize() override; + int Run() override; + int RunImpl(int task_id); + int InitWeightBias(); + int InitTmpBuffer(); + void ConfigInputOutput(); + + private: + float *packed_weight_; + float *tmp_output_block_; + SlidingWindowParam *slidingWindow_param_; +}; +} // namespace mindspore::kernel +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_SLIDEWINDOW_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc index 3204ee8e05..95bbb960e1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.cc @@ -247,6 +247,10 @@ int ConvolutionWinogradCPUKernel::ConfigInputOutput() { } int ConvolutionWinogradCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; @@ -339,6 +343,11 @@ int ConvolutionWinogradImpl(int task_id, LiteParallelGroupEnv *penv, void *cdata } int ConvolutionWinogradCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input_tensor = inputs_.at(kInputIndex); auto ori_input_data = input_tensor->Data(); int in_batch = conv_param_->input_batch_; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.h index d11cc8ae4b..04261d1acb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_winograd.h @@ -28,8 +28,9 @@ namespace mindspore::kernel { class ConvolutionWinogradCPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionWinogradCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx, int output_unit) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx), output_unit_(output_unit) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive, int output_unit) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive), output_unit_(output_unit) {} ~ConvolutionWinogradCPUKernel() override { if (tmp_data_ != nullptr) { free(tmp_data_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc index 5282c6cada..6b529637e2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/crop.cc @@ -40,15 +40,7 @@ int CropLaunch(int thread_id, LiteParallelGroupEnv *penv, void *cdata) { } } // namespace -int CropCPUKernel::Init() { - schema::Format input0_format = inputs_[0]->GetFormat(); - if (input0_format != schema::Format_NCHW && input0_format != schema::Format_NHWC) { - MS_LOG(ERROR) << "Unsupport format " << input0_format; - return RET_FORMAT_ERR; - } - outputs_[0]->SetFormat(input0_format); - return RET_OK; -} +int CropCPUKernel::Init() { return RET_OK; } int CropCPUKernel::CropParallelRun(int thread_id) { auto input = inputs_[0]; @@ -61,6 +53,11 @@ int CropCPUKernel::CropParallelRun(int thread_id) { } int CropCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = inputs_[0]; auto output = outputs_[0]; auto param = reinterpret_cast(opParameter); @@ -71,7 +68,7 @@ int CropCPUKernel::Run() { return RET_OK; } - int ret = LiteBackendParallelLaunch(CropLaunch, this, param->op_parameter_.thread_num_); + auto ret = LiteBackendParallelLaunch(CropLaunch, this, param->op_parameter_.thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Crop launch fail!ret: " << ret; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/crop.h b/mindspore/lite/src/runtime/kernel/arm/fp32/crop.h index f9656b2355..8165c84551 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/crop.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/crop.h @@ -24,8 +24,9 @@ namespace mindspore::kernel { class CropCPUKernel : public CropBaseCPUKernel { public: CropCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : CropBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : CropBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~CropCPUKernel() = default; int Init() override; int ReSize() override { return 0; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc index be571478fe..a9e6b15d55 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.cc @@ -173,6 +173,10 @@ int DeConvolutionCPUKernel::DoPostFunc(int task_id) { } int DeConvolutionCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } ConvolutionBaseCPUKernel::Init(); int error_code = InitParam(); @@ -190,6 +194,11 @@ int DeConvolutionCPUKernel::Init() { } int DeConvolutionCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } float *src_in = reinterpret_cast(inputs_[0]->Data()); float *src_out = reinterpret_cast(outputs_[0]->Data()); @@ -214,14 +223,13 @@ int DeConvolutionCPUKernel::Run() { return RET_OK; } - kernel::LiteKernel *CpuDeConvFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DeConv2D); - auto kernel = new (std::nothrow) kernel::DeConvolutionCPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) kernel::DeConvolutionCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.h b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.h index 165ebf5d28..fb29ff9e5e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution.h @@ -31,8 +31,9 @@ namespace mindspore::kernel { class DeConvolutionCPUKernel : public ConvolutionBaseCPUKernel { public: DeConvolutionCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) { matmul_param_ = new MatMulParameter(); } ~DeConvolutionCPUKernel() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc index 07e5747847..a60851e178 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc @@ -39,7 +39,7 @@ int DeconvolutionDepthwiseCPUKernel::InitSlideParam() { // init sliding window param sliding_ = new SlidingWindowParam; - InitSlidingParam(sliding_, conv_param_, C4NUM); + InitSlidingParamConvDw(sliding_, conv_param_, C4NUM); return RET_OK; } @@ -102,6 +102,10 @@ int DeconvolutionDepthwiseCPUKernel::InitBuffer() { } int DeconvolutionDepthwiseCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } InitSlideParam(); // conv base init ConvolutionBaseCPUKernel::Init(); @@ -155,6 +159,11 @@ int DeconvDwRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int DeconvolutionDepthwiseCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -192,10 +201,11 @@ int DeconvolutionDepthwiseCPUKernel::Run() { kernel::LiteKernel *CpuDeconvDwFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DeDepthwiseConv2D); - auto kernel = new (std::nothrow) kernel::DeconvolutionDepthwiseCPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = + new (std::nothrow) kernel::DeconvolutionDepthwiseCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.h b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.h index f2ed4b5d95..0ad3c18d44 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class DeconvolutionDepthwiseCPUKernel : public ConvolutionBaseCPUKernel { public: DeconvolutionDepthwiseCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~DeconvolutionDepthwiseCPUKernel() override { delete sliding_; free(packed_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc index c28a9cd4cd..15d9a203c5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.cc @@ -22,10 +22,10 @@ #include "include/errorcode.h" using mindspore::lite::KernelRegistrar; -using mindspore::lite::RET_FORMAT_ERR; using mindspore::lite::RET_ERROR; -using mindspore::lite::RET_PARAM_INVALID; +using mindspore::lite::RET_FORMAT_ERR; using mindspore::lite::RET_OK; +using mindspore::lite::RET_PARAM_INVALID; using mindspore::schema::PrimitiveType_DepthToSpace; namespace mindspore::kernel { @@ -37,10 +37,23 @@ int DepthToSpaceCPUKernel::Init() { } DepthToSpaceParameter *param = reinterpret_cast(opParameter); param->data_type_size_ = sizeof(float); - return RET_OK; + if (!InferShapeDone()) { + return RET_OK; + } + + return ReSize(); +} + +int DepthToSpaceCPUKernel::ReSize() { + return DepthToSpaceBaseCPUKernel::ReSize(); } int DepthToSpaceCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = inputs_[0]; auto output = outputs_[0]; const float *input_data = reinterpret_cast(input->Data()); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.h b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.h index e1676ccb8e..706f094c37 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/depth_to_space.h @@ -23,17 +23,15 @@ namespace mindspore::kernel { class DepthToSpaceCPUKernel : public DepthToSpaceBaseCPUKernel { public: DepthToSpaceCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : DepthToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : DepthToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~DepthToSpaceCPUKernel() = default; int Init() override; - int ReSize() override { - return 0; - } + int ReSize() override; int Run() override; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_DEPTH_TO_SPACE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc new file mode 100644 index 0000000000..638e4cc915 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.cc @@ -0,0 +1,98 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "src/runtime/kernel/arm/fp32/elu.h" +#include "include/errorcode.h" +#include "src/kernel_registry.h" +#include "src/runtime/runtime_api.h" + +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Elu; + +namespace mindspore::kernel { +int EluCPUKernel::Init() { + elu_parameter_ = reinterpret_cast(opParameter); + elu_parameter_->thread_num_ = thread_count_; + + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int EluCPUKernel::ReSize() { + elu_parameter_->in_size_ = inputs_.front()->ElementsNum(); + return RET_OK; +} + +int EluCPUKernel::DoExcute(int task_id) { Elu(input_addr, output_addr, elu_parameter_, task_id); } + +int EluRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto EluData = reinterpret_cast(cdata); + auto ret = EluData->DoExcute(task_id); + if (ret != RET_OK) { + MS_LOG(ERROR) << "EluRun error task_id[" << task_id << "] error_code[" << ret << "]"; + return RET_ERROR; + } + return RET_OK; +} + +int EluCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } + input_addr = reinterpret_cast(inputs_.front()->Data()); + output_addr = reinterpret_cast(outputs_.front()->Data()); + + auto ret = LiteBackendParallelLaunch(EluRun, this, elu_parameter_->thread_num_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Elu error: error_code[" << ret << "]"; + return RET_ERROR; + } + return RET_OK; +} + +kernel::LiteKernel *CpuEluFp32KernelCreator(const std::vector &inputs, + const std::vector &outputs, OpParameter *parameter, + const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { + if (parameter == nullptr || ctx == nullptr) { + MS_LOG(ERROR) << "parameter or ctx is nullptr"; + return nullptr; + } + MS_ASSERT(desc.type == PrimitiveType_Elu); + auto *kernel = new (std::nothrow) EluCPUKernel(parameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "Create Kernel failed, name: " << parameter->name_; + return nullptr; + } + + auto ret = kernel->Init(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Init Kernel failed, name: " << parameter->name_ + << ", type: " << schema::EnumNamePrimitiveType(static_cast(parameter->type_)); + delete kernel; + return nullptr; + } + return kernel; +} + +REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Elu, CpuEluFp32KernelCreator) +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/elu.h b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.h new file mode 100644 index 0000000000..f703f2b503 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/elu.h @@ -0,0 +1,49 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ELU_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ELU_H_ + +#include +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/nnacl/fp32/elu.h" + +namespace mindspore::kernel { +class EluCPUKernel : public LiteKernel { + public: + explicit EluCPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} + ~EluCPUKernel() override{}; + + int Init() override; + int ReSize() override; + int Run() override; + int DoExcute(int task_id); + + protected: + int thread_count_; + const lite::Context *ctx_; + EluParameter *elu_parameter_; + + private: + float *input_addr; + float *output_addr; +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ELU_H diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc index 0904f90b5d..d41590d06d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.cc @@ -28,6 +28,14 @@ namespace mindspore::kernel { int EmbeddingLookupCPUKernel::Init() { embedding_lookup_parameter_ = reinterpret_cast(opParameter); embedding_lookup_parameter_->thread_num = thread_count_; + + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int EmbeddingLookupCPUKernel::ReSize() { embedding_lookup_parameter_->ids_size_ = inputs_.back()->ElementsNum(); embedding_lookup_parameter_->layer_size_ = 1; @@ -41,18 +49,34 @@ int EmbeddingLookupCPUKernel::Init() { embedding_lookup_parameter_->layer_num_ += inputs_[i]->shape()[0]; } - input_addr_ = reinterpret_cast( - std::malloc(sizeof(float) * embedding_lookup_parameter_->layer_size_ * embedding_lookup_parameter_->layer_num_)); + if (input_addr_ != nullptr) { + free(input_addr_); + } + if (context_ != nullptr && context_->allocator != nullptr) { + input_addr_ = reinterpret_cast(context_->allocator->Malloc( + sizeof(float) * embedding_lookup_parameter_->layer_size_ * embedding_lookup_parameter_->layer_num_)); + } else { + input_addr_ = reinterpret_cast( + malloc(sizeof(float) * embedding_lookup_parameter_->layer_size_ * embedding_lookup_parameter_->layer_num_)); + } if (input_addr_ == nullptr) { - MS_LOG(ERROR) << "Create memory failed"; - return mindspore::lite::RET_MEMORY_FAILED; + MS_LOG(ERROR) << "Malloc buffer failed"; + return RET_ERROR; } - embedding_lookup_parameter_->is_regulated_ = - reinterpret_cast(std::malloc(sizeof(bool) * embedding_lookup_parameter_->layer_num_)); + if (embedding_lookup_parameter_->is_regulated_ != nullptr) { + free(embedding_lookup_parameter_->is_regulated_); + } + if (context_ != nullptr && context_->allocator != nullptr) { + embedding_lookup_parameter_->is_regulated_ = + reinterpret_cast(context_->allocator->Malloc(sizeof(bool) * embedding_lookup_parameter_->layer_num_)); + } else { + embedding_lookup_parameter_->is_regulated_ = + reinterpret_cast(malloc(sizeof(bool) * embedding_lookup_parameter_->layer_num_)); + } if (embedding_lookup_parameter_->is_regulated_ == nullptr) { - MS_LOG(ERROR) << "Create memory failed"; - return mindspore::lite::RET_MEMORY_FAILED; + MS_LOG(ERROR) << "Malloc buffer failed"; + return RET_ERROR; } for (int i = 0; i < embedding_lookup_parameter_->layer_num_; ++i) { @@ -62,8 +86,6 @@ int EmbeddingLookupCPUKernel::Init() { return RET_OK; } -int EmbeddingLookupCPUKernel::ReSize() { return RET_OK; } - int EmbeddingLookupCPUKernel::DoExcute(int task_id) { int error_code = EmbeddingLookup(input_addr_, ids_addr_, output_addr_, embedding_lookup_parameter_, task_id); if (error_code != RET_OK) { @@ -84,6 +106,11 @@ int EmbeddingLookupRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int EmbeddingLookupCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } int dest_loc = 0; for (int i = 0; i < inputs_.size() - 1; i++) { auto input_t = reinterpret_cast(inputs_.at(i)->Data()); @@ -104,13 +131,13 @@ int EmbeddingLookupCPUKernel::Run() { kernel::LiteKernel *CpuEmbeddingLookupFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, const lite::Context *ctx, - const KernelKey &desc) { + const KernelKey &desc, const lite::Primitive *primitive) { if (parameter == nullptr || ctx == nullptr) { MS_LOG(ERROR) << "parameter or ctx is nullptr"; return nullptr; } MS_ASSERT(desc.type == PrimitiveType_EmbeddingLookup); - auto *kernel = new (std::nothrow) EmbeddingLookupCPUKernel(parameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) EmbeddingLookupCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create Kernel failed, name: " << parameter->name_; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.h b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.h index 6afa0d5620..5a80550e82 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/embedding_lookup.h @@ -25,9 +25,17 @@ namespace mindspore::kernel { class EmbeddingLookupCPUKernel : public LiteKernel { public: explicit EmbeddingLookupCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) {} - ~EmbeddingLookupCPUKernel() override{}; + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} + ~EmbeddingLookupCPUKernel() override { + if (input_addr_ != nullptr) { + free(input_addr_); + } + if (embedding_lookup_parameter_->is_regulated_ != nullptr) { + free(embedding_lookup_parameter_->is_regulated_); + } + }; int Init() override; int ReSize() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc index 8f37cb30bb..98bf98d2ca 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/expandDims.cc @@ -29,6 +29,10 @@ using mindspore::schema::PrimitiveType_ExpandDims; namespace mindspore::kernel { int ExpandDimsCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } int ret = ReSize(); return ret; } @@ -65,9 +69,14 @@ int ExpandDimsRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ExpandDimsCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } in_ptr_ = reinterpret_cast(inputs_.at(0)->Data()); out_ptr_ = reinterpret_cast(outputs_.at(0)->Data()); - int ret = LiteBackendParallelLaunch(ExpandDimsRun, this, thread_sz_count_); + auto ret = LiteBackendParallelLaunch(ExpandDimsRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "ExpandDimsRun error error_code[" << ret << "]"; return ret; @@ -78,10 +87,10 @@ int ExpandDimsCPUKernel::Run() { kernel::LiteKernel *CpuExpandsDimsFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_ExpandDims); - auto *kernel = new (std::nothrow) ExpandDimsCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ExpandDimsCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ExpandDimsCPUKernel fail!"; return nullptr; @@ -98,4 +107,3 @@ kernel::LiteKernel *CpuExpandsDimsFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} ~ExpandDimsCPUKernel() override = default; int Init() override; @@ -51,4 +52,3 @@ class ExpandDimsCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_CCSRC_KERNEL_CPU_ARM_FP32_EXPANDDIMS_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc index 96a583decc..32866a54f2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fill.cc @@ -35,6 +35,10 @@ constexpr int kOutputNum = 1; } // namespace int FillCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } data_size_ = outputs_.front()->ElementsNum(); thread_sz_count_ = MSMIN(thread_count_, data_size_); thread_sz_stride_ = UP_DIV(data_size_, thread_sz_count_); @@ -68,12 +72,17 @@ int FillRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int FillCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto fillData = inputs_.at(inputs_.size() - 1); auto output = outputs_.front(); auto fill_data = reinterpret_cast(fillData->Data()); src_data_ = fill_data[0]; out_ptr_ = reinterpret_cast(output->Data()); - int ret = LiteBackendParallelLaunch(FillRun, this, thread_sz_count_); + auto ret = LiteBackendParallelLaunch(FillRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "FillRun error error_code[" << ret << "]"; return ret; @@ -84,14 +93,14 @@ int FillCPUKernel::Run() { kernel::LiteKernel *CpuFillFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); if (opParameter == nullptr) { MS_LOG(ERROR) << "Create kernel failed, opParameter is nullptr, type: PrimitiveType_Fill. "; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Fill); - auto *kernel = new (std::nothrow) FillCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) FillCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new FillCPUKernel fail!"; return nullptr; @@ -108,4 +117,3 @@ kernel::LiteKernel *CpuFillFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} ~FillCPUKernel() override = default; int Init() override; @@ -49,4 +50,3 @@ class FillCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FILL_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc index 3adddbf91f..868705746b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/flatten.cc @@ -28,6 +28,10 @@ using mindspore::schema::PrimitiveType_Flatten; namespace mindspore::kernel { int FlattenCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto output_shape = outputs_[0]->shape(); flatten_param_->size = sizeof(float); for (int i = 0; i < output_shape.size(); i++) { @@ -39,6 +43,11 @@ int FlattenCPUKernel::Init() { int FlattenCPUKernel::ReSize() { return RET_OK; } int FlattenCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = reinterpret_cast(inputs_[0]->Data()); auto output = reinterpret_cast(outputs_[0]->Data()); Flatten(input, output, flatten_param_); @@ -48,14 +57,14 @@ int FlattenCPUKernel::Run() { kernel::LiteKernel *CpuFlattenFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); if (opParameter == nullptr) { MS_LOG(ERROR) << "Create kernel failed, opParameter is nullptr, type: PrimitiveType_Flatten. "; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Flatten); - auto *kernel = new (std::nothrow) FlattenCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) FlattenCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new FlattenCPUKernel fail!"; return nullptr; @@ -72,4 +81,3 @@ kernel::LiteKernel *CpuFlattenFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { flatten_param_ = reinterpret_cast(parameter); } - ~FlattenCPUKernel() override { delete flatten_param_; } + ~FlattenCPUKernel() override = default;; int Init() override; int ReSize() override; @@ -44,4 +45,3 @@ class FlattenCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FLATTEN_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc index 366167b5f3..e5a17176cf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.cc @@ -44,6 +44,10 @@ FullconnectionCPUKernel::~FullconnectionCPUKernel() { int FullconnectionCPUKernel::ReSize() { return RET_OK; } int FullconnectionCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } fc_param_->row_ = (inputs_[0]->shape())[0]; fc_param_->col_ = (inputs_[1]->shape())[0]; fc_param_->deep_ = (inputs_[1]->shape())[1]; @@ -105,6 +109,11 @@ int FullconnectionCPUKernel::DoMatmul(int task_id) { } int FullconnectionCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto a_ptr = reinterpret_cast(inputs_.at(0)->Data()); auto output_ptr = reinterpret_cast(outputs_.at(0)->Data()); @@ -112,7 +121,7 @@ int FullconnectionCPUKernel::Run() { LiteBackendParallelLaunch(FcFp32MatmulRun, this, thread_count_); - Row8x8Major2RowMajor(c_r8x8_ptr_, output_ptr, fc_param_->row_, fc_param_->col_); + Row8x8Major2RowMajor(c_r8x8_ptr_, output_ptr, fc_param_->row_, fc_param_->col_, fc_param_->col_); return RET_OK; } } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.h b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.h index be4c1f72b5..f10f163f95 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fullconnection.h @@ -29,8 +29,9 @@ namespace mindspore::kernel { class FullconnectionCPUKernel : public FullconnectionBaseCPUKernel { public: FullconnectionCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : FullconnectionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : FullconnectionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~FullconnectionCPUKernel() override; int Init() override; @@ -48,4 +49,3 @@ class FullconnectionCPUKernel : public FullconnectionBaseCPUKernel { }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FULLCONNECTION_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc index 4452655bbc..00810f89aa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.cc @@ -28,6 +28,10 @@ using mindspore::schema::PrimitiveType_FusedBatchNorm; namespace mindspore::kernel { int FusedBatchnormCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } input_shape_ = reinterpret_cast(malloc(sizeof(int) * inputs_[0]->shape().size())); memcpy(input_shape_, inputs_[0]->shape().data(), inputs_[0]->shape().size() * sizeof(int)); return RET_OK; @@ -36,6 +40,11 @@ int FusedBatchnormCPUKernel::Init() { int FusedBatchnormCPUKernel::ReSize() { return RET_OK; } int FusedBatchnormCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input_addr = reinterpret_cast(inputs_.at(0)->Data()); auto scale_addr = reinterpret_cast(inputs_.at(1)->Data()); auto offest_addr = reinterpret_cast(inputs_.at(2)->Data()); @@ -51,10 +60,11 @@ int FusedBatchnormCPUKernel::Run() { kernel::LiteKernel *CpuFusedBatchnormKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_FusedBatchNorm); - auto *kernel = new (std::nothrow) FusedBatchnormCPUKernel(opParameter, inputs, outputs); + FusedBatchnormCPUKernel *kernel = new (std::nothrow) FusedBatchnormCPUKernel(opParameter, inputs, outputs, ctx, + primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new FusedBatchnormCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.h b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.h index bce0660be9..55c4ba2bb7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/fused_batchnorm.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class FusedBatchnormCPUKernel : public LiteKernel { public: FusedBatchnormCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { fused_batchnorm_param_ = reinterpret_cast(parameter); } ~FusedBatchnormCPUKernel() override { delete fused_batchnorm_param_; } @@ -42,4 +43,3 @@ class FusedBatchnormCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_FUSED_BATCHNORM_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc index fd073a9f00..d75c836d74 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gather.cc @@ -92,6 +92,11 @@ int GatherRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int GatherCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } int error_code = LiteBackendParallelLaunch(GatherRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Gather function error error_code[" << error_code << "]"; @@ -103,11 +108,11 @@ int GatherCPUKernel::Run() { kernel::LiteKernel *CpuGatherFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Gather); - auto *kernel = new (std::nothrow) GatherCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) GatherCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { return nullptr; } @@ -123,4 +128,3 @@ kernel::LiteKernel *CpuGatherFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) {} ~GatherCPUKernel() override = default; int Init() override; @@ -42,4 +43,3 @@ class GatherCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GATHER_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc index 109ce338f8..3d1c2a245e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/gatherNd.cc @@ -38,6 +38,10 @@ GatherNdCPUKernel::~GatherNdCPUKernel() { } int GatherNdCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto indices_tensor = inputs_.at(1); auto indices_shape = indices_tensor->shape(); int indices_rank = indices_shape.size(); @@ -112,9 +116,14 @@ int GatherNdRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int GatherNdCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } in_ptr_ = reinterpret_cast(inputs_.front()->Data()); out_ptr_ = reinterpret_cast(outputs_.front()->Data()); - int ret = LiteBackendParallelLaunch(GatherNdRun, this, thread_sz_count_); + auto ret = LiteBackendParallelLaunch(GatherNdRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "gatherNd error error_code[" << ret << "]"; return ret; @@ -125,11 +134,11 @@ int GatherNdCPUKernel::Run() { kernel::LiteKernel *CpuGatherNdFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_GatherNd); - auto *kernel = new (std::nothrow) GatherNdCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) GatherNdCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { return nullptr; } @@ -145,4 +154,3 @@ kernel::LiteKernel *CpuGatherNdFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} ~GatherNdCPUKernel() override; int Init() override; @@ -53,4 +54,3 @@ class GatherNdCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GATHERND_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc index bb1286eebd..3a62427a29 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.cc @@ -74,6 +74,11 @@ int LocalResponseNormRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int LocalResponseNormCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } int error_code = LiteBackendParallelLaunch(LocalResponseNormRun, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "LocalResponseNorm function error error_code[" << error_code << "]"; @@ -85,11 +90,12 @@ int LocalResponseNormCPUKernel::Run() { kernel::LiteKernel *CpuLocalResponseNormFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_LocalResponseNormalization); - auto *kernel = new (std::nothrow) LocalResponseNormCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) LocalResponseNormCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new LocalResponseNormCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.h b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.h index ea65a3e923..90cdc8a66e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/local_response_norm.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class LocalResponseNormCPUKernel : public LiteKernel { public: LocalResponseNormCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) {} ~LocalResponseNormCPUKernel() override = default; int Init() override; @@ -40,4 +41,3 @@ class LocalResponseNormCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_LOCAL_RESPONSE_NORM_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc index cc779de6e5..ea01c6a93a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc @@ -99,6 +99,10 @@ int LstmCPUKernel::InitWeightBias() { } int LstmCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = InitParam(); if (ret != RET_OK) { MS_LOG(ERROR) << "LstmCPUKernel InitParam error."; @@ -137,6 +141,11 @@ int LstmCPUKernel::ReSize() { } int LstmCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = inputs_.at(kInputIndex); MS_ASSERT(input != nullptr); auto hidden_state = inputs_.at(4); @@ -162,11 +171,12 @@ int LstmCPUKernel::Run() { kernel::LiteKernel *CpuLstmKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, - const lite::Context *ctx, const kernel::KernelKey &desc) { + const lite::Context *ctx, const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Lstm); - auto *kernel = new (std::nothrow) LstmCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) LstmCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.h b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.h index 61488ca2c4..8fdd4dd8d9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/lstm.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class LstmCPUKernel : public LiteKernel { public: LstmCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { lstm_parm_ = reinterpret_cast(opParameter); } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc index ca20fb76b6..61eea4fd40 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.cc @@ -33,16 +33,20 @@ MatmulCPUKernel::~MatmulCPUKernel() { int MatmulCPUKernel::ReSize() { return RET_OK; } int MatmulCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } int batch = 1; - auto x_shape = inputs_[0]->shape(); - auto o_shape = outputs_[0]->shape(); - for (int i = 0; i < x_shape.size() - 2; ++i) { - batch *= x_shape[i]; + auto a_shape = inputs_[0]->shape(); + auto c_shape = outputs_[0]->shape(); + for (int i = 0; i < a_shape.size() - 2; ++i) { + batch *= a_shape[i]; } params_->batch = batch; - params_->row_ = o_shape[o_shape.size() - 2]; - params_->col_ = o_shape[o_shape.size() - 1]; - params_->deep_ = params_->a_transpose_ ? x_shape[x_shape.size() - 2] : x_shape[x_shape.size() - 1]; + params_->row_ = c_shape[c_shape.size() - 2]; + params_->col_ = c_shape[c_shape.size() - 1]; + params_->deep_ = params_->a_transpose_ ? a_shape[a_shape.size() - 2] : a_shape[a_shape.size() - 1]; params_->row_8_ = UP_ROUND(params_->row_, 8); params_->col_8_ = UP_ROUND(params_->col_, 8); thread_count_ = MSMIN(thread_count_, UP_DIV(params_->col_8_, 8)); @@ -88,6 +92,11 @@ int MatmulFloatRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int MatmulCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto a_ptr = reinterpret_cast(inputs_[0]->Data()); auto b_ptr = reinterpret_cast(inputs_[1]->Data()); auto c_ptr = reinterpret_cast(outputs_[0]->Data()); @@ -109,7 +118,7 @@ int MatmulCPUKernel::Run() { RowMajor2Row8Major(cur_b_ptr, b_r8_ptr_, params_->deep_, params_->col_); } LiteBackendParallelLaunch(MatmulFloatRun, this, thread_count_); - Row8x8Major2RowMajor(c_r8x8_ptr_, cur_c_ptr, params_->row_, params_->col_); + Row8x8Major2RowMajor(c_r8x8_ptr_, cur_c_ptr, params_->row_, params_->col_, params_->col_); } return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.h b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.h index 0f617d0179..6efb35bfe4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul.h @@ -19,15 +19,16 @@ #include #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" #include "src/runtime/kernel/arm/base/matmul_base.h" namespace mindspore::kernel { class MatmulCPUKernel : public MatmulBaseCPUKernel { public: explicit MatmulCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : MatmulBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : MatmulBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~MatmulCPUKernel() override; int Init() override; int ReSize() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc index 9ee4f8a577..74a77bf579 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/nchw2nhwc.cc @@ -28,21 +28,30 @@ int Nchw2NhwcCPUKernel::Init() { return RET_OK; } int Nchw2NhwcCPUKernel::ReSize() { return RET_OK; } int Nchw2NhwcCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = inputs_[0]; auto output = outputs_[0]; - PackNCHWToNHWCFp32(input->Data(), output->Data(), output->Batch(), output->Height() * output->Width(), - output->Channel()); + if (input->shape().size() == 4) { + PackNCHWToNHWCFp32(input->Data(), output->Data(), output->Batch(), output->Height() * output->Width(), + output->Channel()); + } else { + memcpy(output->Data(), input->Data(), input->ElementsNum() * sizeof(float)); + } return RET_OK; } kernel::LiteKernel *CpuNchw2NhwcFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Nchw2Nhwc); - auto *kernel = new (std::nothrow) Nchw2NhwcCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) Nchw2NhwcCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new Nchw2NhwcCPUKernel fail!"; return nullptr; @@ -59,4 +68,3 @@ kernel::LiteKernel *CpuNchw2NhwcFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~Nchw2NhwcCPUKernel() override = default; int Init() override; @@ -39,4 +40,3 @@ class Nchw2NhwcCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_NCHW2NHWC_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc index 480d58eaa2..634961aa71 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/nhwc2nchw.cc @@ -28,21 +28,30 @@ int Nhwc2NchwCPUKernel::Init() { return RET_OK; } int Nhwc2NchwCPUKernel::ReSize() { return RET_OK; } int Nhwc2NchwCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = inputs_[0]; auto output = outputs_[0]; - PackNHWCToNCHWFp32(input->Data(), output->Data(), output->Batch(), output->Height() * output->Width(), - output->Channel()); + if (input->shape().size() == 4) { + PackNHWCToNCHWFp32(input->Data(), output->Data(), output->Batch(), output->Height() * output->Width(), + output->Channel()); + } else { + memcpy(output->Data(), input->Data(), input->ElementsNum() * sizeof(float)); + } return RET_OK; } kernel::LiteKernel *CpuNhwc2NchwFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Nhwc2Nchw); - auto *kernel = new (std::nothrow) Nhwc2NchwCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) Nhwc2NchwCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new Nhwc2NchwCPUKernel fail!"; return nullptr; @@ -59,4 +68,3 @@ kernel::LiteKernel *CpuNhwc2NchwFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~Nhwc2NchwCPUKernel() override = default; int Init() override; @@ -39,4 +40,3 @@ class Nhwc2NchwCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_NHWC2NCHW_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc index afff5d42de..5cb964a3ea 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/one_hot.cc @@ -35,6 +35,10 @@ constexpr size_t kOutputNum = 1; } // namespace int OneHotCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } // indices depth on_value off_value if (inputs_.size() != kInputNum || outputs_.size() != kOutputNum) { MS_LOG(ERROR) << "OneHot input size should be " << kInputNum << ", got " << inputs_.size() @@ -148,6 +152,11 @@ int OneHotCPUKernel::GetParams() { } int OneHotCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } int error_code = LiteBackendParallelLaunch(RunOneHot, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "OneHot function error error_code[" << error_code << "]"; @@ -159,7 +168,7 @@ int OneHotCPUKernel::Run() { kernel::LiteKernel *CpuOneHotFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter != nullptr) { MS_LOG(ERROR) << "OneHot opParameter nullptr."; return nullptr; @@ -168,7 +177,7 @@ kernel::LiteKernel *CpuOneHotFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), context_(ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), context_(ctx) {} ~OneHotCPUKernel() override = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc index 511c7f9d87..28be57faaa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad.cc @@ -36,6 +36,10 @@ constexpr int kOutputNum = 1; } // namespace int PadCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } if (inputs_.size() != kInputNum || outputs_.size() != kOutputNum) { MS_LOG(ERROR) << "Pad input size should be " << kInputNum << ", got " << inputs_.size() << ", output size should be" << kOutputNum << ", got " << outputs_.size(); @@ -85,6 +89,11 @@ int PadCPUKernel::RunImpl(int task_id) { } int PadCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto output = outputs_.at(0); int output_size = output->DataSize(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad.h b/mindspore/lite/src/runtime/kernel/arm/fp32/pad.h index c48ddf581c..f2a598d339 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class PadCPUKernel : public LiteKernel { public: PadCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), context_(ctx) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), context_(ctx) { pad_param_ = reinterpret_cast(parameter); } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc index 960734f994..45255f7ce8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.cc @@ -29,6 +29,10 @@ using mindspore::schema::PrimitiveType_Pooling; namespace mindspore::kernel { int PoolingCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = PoolingBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "PoolingBase Init failed."; @@ -68,6 +72,11 @@ int PoolingImpl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int PoolingCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } int error_code = LiteBackendParallelLaunch(PoolingImpl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "pooling error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.h b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.h index 7edd82a537..1833764e2d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pooling.h @@ -33,8 +33,9 @@ using mindspore::schema::RoundMode; class PoolingCPUKernel : public PoolingBaseCPUKernel { public: PoolingCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : PoolingBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : PoolingBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~PoolingCPUKernel() override = default; int Init() override; @@ -47,4 +48,3 @@ class PoolingCPUKernel : public PoolingBaseCPUKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_POOLING_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc index 26e9a0c5ea..467b92efb6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/power.cc @@ -41,7 +41,12 @@ int PowerImpl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int PowerCPUKernel::Run() { - int ret = LiteBackendParallelLaunch(PowerImpl, this, thread_count_); + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } + auto ret = LiteBackendParallelLaunch(PowerImpl, this, thread_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "PowerCPUKernel error: " << ret; return RET_ERROR; @@ -51,15 +56,19 @@ int PowerCPUKernel::Run() { int PowerCPUKernel::RunImpl(int task_id) { auto x_addr = reinterpret_cast(inputs_[0]->Data()); - auto exp_addr = reinterpret_cast(inputs_[1]->Data()); auto output_addr = reinterpret_cast(outputs_[0]->Data()); auto size = inputs_[0]->ElementsNum(); int stride = UP_DIV(size, thread_count_); int len = MSMIN(stride, size - stride * task_id); - bool broadcast = (inputs_[1]->ElementsNum() == 1) ? true : false; + float *exp_addr = nullptr; + bool broadcast = true; + if (inputs_.size() == 2) { + exp_addr = reinterpret_cast(inputs_[1]->Data()); + broadcast = false; + } float *cur_exp; if (broadcast) { - cur_exp = exp_addr; + cur_exp = &power_; } else { cur_exp = exp_addr + stride * task_id; } @@ -70,11 +79,11 @@ int PowerCPUKernel::RunImpl(int task_id) { kernel::LiteKernel *CpuPowerFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Power); - auto *kernel = - new (std::nothrow) PowerCPUKernel(opParameter, inputs, outputs, ctx); + PowerCPUKernel *kernel = + new (std::nothrow) PowerCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PowerCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power.h b/mindspore/lite/src/runtime/kernel/arm/fp32/power.h index b2ee1f6b62..89a6404baa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/power.h @@ -26,10 +26,12 @@ namespace mindspore::kernel { class PowerCPUKernel : public LiteKernel { public: PowerCPUKernel(OpParameter *param, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(param, inputs, outputs), + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(param, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_), + power_(reinterpret_cast(opParameter)->power_), scale_(reinterpret_cast(opParameter)->scale_), shift_(reinterpret_cast(opParameter)->shift_) {} ~PowerCPUKernel() override = default; @@ -42,6 +44,7 @@ class PowerCPUKernel : public LiteKernel { private: const lite::Context *ctx_; int thread_count_; + float power_; float scale_; float shift_; }; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc index 952392761d..756680726f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/prelu.cc @@ -49,6 +49,11 @@ int PReluRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int PReluCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto input = inputs_.at(0); prelu_param_->input_num_ = input->ElementsNum(); input_data = reinterpret_cast(input->Data()); @@ -65,13 +70,13 @@ int PReluCPUKernel::Run() { kernel::LiteKernel *CpuPReluFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Prelu); - auto *kernel = new (std::nothrow) PReluCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) PReluCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new PReluCPUKernel fail!"; return nullptr; @@ -88,4 +93,3 @@ kernel::LiteKernel *CpuPReluFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { prelu_param_ = (reinterpret_cast(opParameter)); + primitive_ = primitive; } ~PReluCPUKernel() = default; @@ -51,4 +53,3 @@ class PReluCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_PRELU_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc index b965731a35..880ccd5c99 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/range.cc @@ -38,6 +38,11 @@ int RangeCPUKernel::Init() { return RET_OK; } int RangeCPUKernel::ReSize() { return RET_OK; } int RangeCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } size_t start = (reinterpret_cast(opParameter))->start_; size_t limit = (reinterpret_cast(opParameter))->limit_; size_t delta = (reinterpret_cast(opParameter))->delta_; @@ -49,11 +54,11 @@ int RangeCPUKernel::Run() { kernel::LiteKernel *CpuRangeFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Range); - auto *kernel = new (std::nothrow) RangeCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) RangeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new RangeCPUKernel fail!"; return nullptr; @@ -71,4 +76,3 @@ kernel::LiteKernel *CpuRangeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~RangeCPUKernel() override = default; int Init() override; @@ -36,4 +37,3 @@ class RangeCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_RANGE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc index 7917f0928d..e70b862fd1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/rank.cc @@ -38,6 +38,11 @@ int RankCPUKernel::Init() { return RET_OK; } int RankCPUKernel::ReSize() { return RET_OK; } int RankCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } auto output_ptr = reinterpret_cast(outputs_.at(0)->Data()); auto in_shape = inputs_[0]->shape(); auto rank = in_shape.size(); @@ -47,12 +52,12 @@ int RankCPUKernel::Run() { kernel::LiteKernel *CpuRankFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, - OpParameter *opParameter, - const lite::Context *ctx, const kernel::KernelKey &desc) { + OpParameter *opParameter, const lite::Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Rank); - auto *kernel = new (std::nothrow) RankCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) RankCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new RankCPUKernel fail!"; return nullptr; @@ -69,4 +74,3 @@ kernel::LiteKernel *CpuRankFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~RankCPUKernel() override = default; int Init() override; @@ -36,4 +37,3 @@ class RankCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_RANK_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc index 43bdfe9351..d05b8a17c0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.cc @@ -91,6 +91,10 @@ int ReduceCPUKernel::CheckParameters() { } int ReduceCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = CheckInputsOutputs(); if (ret != RET_OK) { return ret; @@ -153,6 +157,11 @@ int ReduceImpl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ReduceCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } tmp_shape_ = inputs_.at(0)->shape(); src_data_ = static_cast(inputs_.at(0)->Data()); for (int i = 0; i < data_buffers_.size(); ++i) { @@ -220,7 +229,7 @@ int ReduceCPUKernel::MallocTmpBuffer() { kernel::LiteKernel *CpuReduceFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Reduce); if (opParameter == nullptr) { @@ -231,8 +240,8 @@ kernel::LiteKernel *CpuReduceFp32KernelCreator(const std::vector(opParameter), inputs, outputs, ctx); + auto *kernel = new (std::nothrow) + ReduceCPUKernel(reinterpret_cast(opParameter), inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; return nullptr; @@ -250,7 +259,7 @@ kernel::LiteKernel *CpuReduceFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Mean); if (opParameter == nullptr) { @@ -261,8 +270,8 @@ kernel::LiteKernel *CpuMeanFp32KernelCreator(const std::vector(opParameter), inputs, outputs, ctx); + auto *kernel = new (std::nothrow) + ReduceCPUKernel(reinterpret_cast(opParameter), inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Reduce new ReduceCPUKernel failed."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h index 2273465c27..2857ee9baf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reduce.h @@ -31,8 +31,9 @@ class ReduceCPUKernel : public LiteKernel { public: ReduceCPUKernel(ReduceParameter *param, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(reinterpret_cast(param), inputs, outputs), + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(reinterpret_cast(param), inputs, outputs, ctx, primitive), context_(ctx), keep_dims_(param->keep_dims_), num_axes_(param->num_axes_), diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc index dc45381b84..f1602fdc8c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.cc @@ -36,6 +36,11 @@ int ReshapeCPUKernel::Init() { int ReshapeCPUKernel::ReSize() { return RET_OK; } int ReshapeCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_ptr = inputs_.at(kInputIndex)->Data(); auto output_ptr = outputs_.at(kOutputIndex)->Data(); size_t data_size = inputs_.at(kInputIndex)->Size(); @@ -43,4 +48,3 @@ int ReshapeCPUKernel::Run() { return RET_OK; } } // namespace mindspore::kernel - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.h b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.h index f366e739d9..65b9de20dc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reshape.h @@ -29,8 +29,9 @@ namespace mindspore::kernel { class ReshapeCPUKernel : public ReshapeBaseCPUKernel { public: ReshapeCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ReshapeBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ReshapeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ReshapeCPUKernel() = default; int Init() override; @@ -42,4 +43,3 @@ class ReshapeCPUKernel : public ReshapeBaseCPUKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_RESHAPE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc index ea89861d32..6273744307 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/resize.cc @@ -15,132 +15,33 @@ */ #include "src/runtime/kernel/arm/fp32/resize.h" -#include #include "schema/model_generated.h" -#include "src/kernel_registry.h" -#include "src/runtime/kernel/arm/nnacl/resize.h" -#include "src/runtime/kernel/arm/nnacl/pack.h" +#include "nnacl/fp32/resize.h" #include "include/errorcode.h" #include "src/runtime/runtime_api.h" using mindspore::kernel::KERNEL_ARCH::kCPU; -using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_INVALID_OP_ATTR; using mindspore::lite::RET_NULL_PTR; using mindspore::lite::RET_OK; namespace mindspore::kernel { -namespace { -constexpr int kInputNum = 1; -constexpr int kOutputNum = 1; -constexpr int kRank = 4; -} // namespace - -int ResizeCPUKernel::CheckParameters() { - auto parameter = reinterpret_cast(opParameter); - if (parameter == nullptr) { - MS_LOG(ERROR) << "cast ResizeParameter failed."; - return RET_NULL_PTR; - } - method_ = parameter->method_; - if (method_ != schema::ResizeMethod_BILINEAR && method_ != schema::ResizeMethod_NEAREST_NEIGHBOR) { - MS_LOG(ERROR) << "Resize method should be bilinear or nearest_neighbor, but got " << method_; - return RET_INVALID_OP_ATTR; - } - new_height_ = parameter->new_height_; - if (new_height_ < 1) { - MS_LOG(ERROR) << "Resize new_height should >= 1, but got " << new_height_; - return RET_INVALID_OP_ATTR; - } - new_width_ = parameter->new_width_; - if (new_width_ < 1) { - MS_LOG(ERROR) << "Resize new_width should >= 1, but got " << new_width_; - return RET_INVALID_OP_ATTR; - } - align_corners_ = parameter->align_corners_; - preserve_aspect_ratio = parameter->preserve_aspect_ratio_; - if (preserve_aspect_ratio) { - MS_LOG(ERROR) << "Resize currently not support preserve_aspect_ratio true"; - return RET_ERROR; - } - return RET_OK; -} - -int ResizeCPUKernel::CheckInputsOuputs() { - if (inputs_.size() != kInputNum) { - MS_LOG(ERROR) << "Resize input num should be " << kInputNum << ", but got " << inputs_.size(); - return RET_ERROR; - } - auto input = inputs_.at(0); - if (input == nullptr) { - return RET_NULL_PTR; - } - if (outputs_.size() != kOutputNum) { - MS_LOG(ERROR) << "Resize output num should be " << kOutputNum << ", but got " << outputs_.size(); - return RET_ERROR; - } - auto output = outputs_.at(0); - if (output == nullptr) { - return RET_NULL_PTR; - } - return RET_OK; -} - int ResizeCPUKernel::Init() { - auto ret = CheckParameters(); + auto ret = ResizeBaseCPUKernel::Init(); if (ret != RET_OK) { return ret; } - ret = CheckInputsOuputs(); - if (ret != RET_OK) { - return ret; + if (!InferShapeDone()) { + return RET_OK; } - - auto output = outputs_.at(0); - auto input = inputs_.at(0); - auto input_shape = input->shape(); - if (input_shape.size() != kRank) { - return RET_ERROR; - } - schema::Format execute_format; - size_t exec_input_size; - switch (method_) { - case schema::ResizeMethod_BILINEAR: { - execute_format = schema::Format_NC4HW4; - output->SetFormat(schema::Format_NC4HW4); - exec_input_size = input->ElementsC4Num(); - break; - } - case schema::ResizeMethod_NEAREST_NEIGHBOR: { - execute_format = schema::Format_NHWC; - output->SetFormat(schema::Format_NHWC); - exec_input_size = input->ElementsNum(); - break; - } - default: { - MS_LOG(ERROR) << "Resize unknown method " << method_; - return RET_ERROR; - } - } - - auto input_format = input->GetFormat(); - if (input_format != execute_format) { - auto input_type = input->data_type(); - layout_convertor_ = LayoutTransform(input_type, input_format, execute_format); - exec_input_data_ = reinterpret_cast(malloc(exec_input_size * sizeof(float))); - if (exec_input_data_ == nullptr) { - return RET_NULL_PTR; - } - } - - return RET_OK; + return ReSize(); } int ResizeImpl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { auto resize = reinterpret_cast(cdata); auto error_code = resize->RunImpl(task_id); - if (error_code != NNACL_OK) { + if (error_code != RET_OK) { MS_LOG(ERROR) << "Resize Run error task_id[" << task_id << "] error_code[" << error_code << "]"; return RET_ERROR; } @@ -158,53 +59,41 @@ int ResizeCPUKernel::RunImpl(int task_id) { return RET_NULL_PTR; } auto input_shape = input->shape(); - if (input_shape.size() != kRank) { - return RET_ERROR; - } if (context_ == nullptr) { return RET_NULL_PTR; } int ret = 0; switch (method_) { - case schema::ResizeMethod_BILINEAR: { - if (layout_convertor_ != nullptr) { - layout_convertor_(input_data, exec_input_data_, input->Batch(), input->Height() * input->Width(), - input->Channel()); - ret = ResizeBilinear(exec_input_data_, output_data, inputs_[0]->shape().data(), outputs_[0]->shape().data(), + case static_cast(schema::ResizeMethod_BILINEAR): { + ret = ResizeBilinear(input_data, output_data, input_shape.data(), outputs_[0]->shape().data(), align_corners_, task_id, context_->thread_num_); - } else { - ret = ResizeBilinear(input_data, output_data, inputs_[0]->shape().data(), outputs_[0]->shape().data(), - align_corners_, task_id, context_->thread_num_); - } break; } - case schema::ResizeMethod_NEAREST_NEIGHBOR: { + case static_cast(schema::ResizeMethod_NEAREST_NEIGHBOR): { if (align_corners_) { MS_LOG(ERROR) << "ResizeNearestNeighbor not support align_corners."; return RET_ERROR; } - if (layout_convertor_ != nullptr) { - layout_convertor_(input_data, exec_input_data_, input->Batch(), input->Height() * input->Width(), - input->Channel()); - ret = ResizeNearestNeighbor(exec_input_data_, output_data, input_shape.data(), outputs_[0]->shape().data(), - task_id, context_->thread_num_); - } else { - ret = ResizeNearestNeighbor(input_data, output_data, input_shape.data(), outputs_[0]->shape().data(), task_id, + ret = ResizeNearestNeighbor(input_data, output_data, input_shape.data(), outputs_[0]->shape().data(), task_id, context_->thread_num_); - } break; } case schema::ResizeMethod_UNKNOW: default: { MS_LOG(ERROR) << "Resize unknown method " << method_; - ret = NNACL_ERR; + ret = RET_ERROR; } } return ret; } int ResizeCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } int error_code = LiteBackendParallelLaunch(ResizeImpl, this, context_->thread_num_); if (error_code != RET_OK) { MS_LOG(ERROR) << "Resize run error, error_code[" << error_code << "]"; @@ -212,32 +101,4 @@ int ResizeCPUKernel::Run() { } return RET_OK; } - -kernel::LiteKernel *CpuResizeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { - if (opParameter == nullptr) { - MS_LOG(ERROR) << "Input opParameter is nullptr!"; - return nullptr; - } - MS_ASSERT(desc.type == schema::PrimitiveType_Resize); - auto *kernel = new (std::nothrow) ResizeCPUKernel(opParameter, inputs, outputs, ctx); - if (kernel == nullptr) { - MS_LOG(ERROR) << "new ResizeCPUKernel fail!"; - return nullptr; - } - auto ret = kernel->Init(); - if (ret != RET_OK) { - delete kernel; - MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " - << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); - return nullptr; - } - - return kernel; -} - -REG_KERNEL(kCPU, kNumberTypeFloat32, PrimitiveType_Resize, CpuResizeFp32KernelCreator) } // namespace mindspore::kernel - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/resize.h b/mindspore/lite/src/runtime/kernel/arm/fp32/resize.h index 6d4f681be2..95ca4e3d0b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/resize.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/resize.h @@ -18,48 +18,26 @@ #include #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/nnacl/resize.h" -#include "src/runtime/kernel/arm/base/layout_transform.h" +#include "src/runtime/kernel/arm/base/resize_base.h" using mindspore::schema::PrimitiveType_Resize; using mindspore::schema::ResizeMethod; namespace mindspore::kernel { -class ResizeCPUKernel : public LiteKernel { +class ResizeCPUKernel : public ResizeBaseCPUKernel { public: ResizeCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), context_(ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ResizeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} - ~ResizeCPUKernel() { - if (exec_input_data_ != nullptr) { - free(exec_input_data_); - exec_input_data_ = nullptr; - } - } + ~ResizeCPUKernel() = default; int Init() override; int ReSize() override { return 0; }; int Run() override; int RunImpl(int task_id); - - protected: - const lite::Context *context_; - - private: - int CheckParameters(); - int CheckInputsOuputs(); - - private: - ResizeMethod method_; - int64_t new_height_; - int64_t new_width_; - bool align_corners_; - bool preserve_aspect_ratio; - LayoutConvertor layout_convertor_ = nullptr; - float *exec_input_data_ = nullptr; }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_RESIZE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc index 9e3b6bb557..80ddfcf320 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse.cc @@ -89,6 +89,10 @@ int ReverseCPUKernel::ReSize() { } int ReverseCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } data_size_ = inputs_.at(0)->ElementsNum(); thread_sz_count_ = MSMIN(thread_count_, data_size_); thread_sz_stride_ = UP_DIV(data_size_, thread_sz_count_); @@ -121,9 +125,14 @@ int ReverseCPUKernel::DoReverse(int task_id) { } int ReverseCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } in_ptr_ = reinterpret_cast(inputs_[0]->Data()); out_ptr_ = reinterpret_cast(outputs_[0]->Data()); - int ret = LiteBackendParallelLaunch(ReverseRun, this, thread_sz_count_); + ret = LiteBackendParallelLaunch(ReverseRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "Reverse run error error_code[" << ret << "]"; return ret; @@ -134,13 +143,13 @@ int ReverseCPUKernel::Run() { kernel::LiteKernel *CpuReverseFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "opParameter is NULL! "; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Reverse); - auto *kernel = new (std::nothrow) ReverseCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ReverseCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Kernel is NULL! name: " << opParameter->name_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); @@ -159,4 +168,3 @@ kernel::LiteKernel *CpuReverseFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} ~ReverseCPUKernel() { if (tmp_ != nullptr) { free(tmp_); @@ -60,4 +61,3 @@ class ReverseCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_REVERSE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc index 8684adaeeb..3ed50ee3e5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/reverse_sequence.cc @@ -24,6 +24,10 @@ using mindspore::schema::PrimitiveType_ReverseSequence; namespace mindspore::kernel { int ReverseSequenceCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto input0 = inputs_.at(0); auto input1 = inputs_.at(1); auto output = outputs_.at(0); @@ -84,6 +88,11 @@ int ReverseSequenceCPUKernel::CalcCountAfterAxis(const std::vector shape, i int ReverseSequenceCPUKernel::ReSize() { return RET_OK; } int ReverseSequenceCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } float *input0 = reinterpret_cast(inputs_.at(0)->Data()); int *input1 = reinterpret_cast(inputs_.at(1)->Data()); float *output = reinterpret_cast(outputs_.at(0)->Data()); @@ -94,10 +103,10 @@ int ReverseSequenceCPUKernel::Run() { kernel::LiteKernel *CpuReverseSequenceFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, const lite::Context *ctx, - const KernelKey &desc) { + const KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(parameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_ReverseSequence); - auto *kernel = new (std::nothrow) ReverseSequenceCPUKernel(parameter, inputs, outputs); + auto *kernel = new (std::nothrow) ReverseSequenceCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; return nullptr; @@ -114,4 +123,3 @@ kernel::LiteKernel *CpuReverseSequenceFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~ReverseSequenceCPUKernel() = default; int Init() override; @@ -40,4 +41,3 @@ class ReverseSequenceCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_REVERSE_SEQUENCE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc index 2323e4ce95..f89da381a7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.cc @@ -45,12 +45,13 @@ int ScaleCPUKernel::InitScaleOffset() { } if (inputs_.size() == 3) { - auto offset_tensor = inputs_.at(1); + auto offset_tensor = inputs_.at(2); offset_ = reinterpret_cast(malloc(offset_tensor->ElementsNum() * sizeof(float))); if (offset_ == nullptr) { MS_LOG(ERROR) << "Malloc buffer failed."; return RET_ERROR; } + memcpy(offset_, offset_tensor->Data(), offset_tensor->ElementsNum() * sizeof(float)); param->has_offset_ = true; } else { offset_ = nullptr; @@ -90,6 +91,10 @@ int ScaleCPUKernel::InitParameter() { } int ScaleCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } if (inputs_.size() < 2 || inputs_.size() > 3) { MS_LOG(ERROR) << "inputs to Scale operator should be 2 or 3, but " << inputs_.size() << " is given."; return RET_ERROR; @@ -133,6 +138,11 @@ int ScaleRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ScaleCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto in_tensor = inputs_.front(); input_ptr_ = reinterpret_cast(in_tensor->Data()); if (scale_ == nullptr) { @@ -142,7 +152,7 @@ int ScaleCPUKernel::Run() { auto out_tensor = outputs_.front(); output_ptr_ = reinterpret_cast(out_tensor->Data()); - int ret = LiteBackendParallelLaunch(ScaleRun, this, opParameter->thread_num_); + ret = LiteBackendParallelLaunch(ScaleRun, this, opParameter->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; @@ -154,13 +164,13 @@ int ScaleCPUKernel::Run() { kernel::LiteKernel *CpuScaleFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_Scale); if (opParameter == nullptr) { MS_LOG(ERROR) << "opParameter is nullptr"; return nullptr; } - auto *kernel = new (std::nothrow) ScaleCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ScaleCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.h b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.h index 32417bcc26..caf4d35376 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scale.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scale.h @@ -25,10 +25,11 @@ namespace mindspore::kernel { class ScaleCPUKernel : public LiteKernel { public: explicit ScaleCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs) { - opParameter->thread_num_ = ctx->thread_num_; - } + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { + opParameter->thread_num_ = ctx->thread_num_; + } ~ScaleCPUKernel() override = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc index 1a9ab72866..e13d74697b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/scatter_nd.cc @@ -30,13 +30,17 @@ using mindspore::schema::PrimitiveType_ScatterND; namespace mindspore::kernel { namespace { - constexpr int kScatterNDInputNum = 3; - constexpr int kScatterNDOutputNum = 1; - constexpr int kScatterShapeIndex = 0; - constexpr int kScatterIndicesIndex = 1; - constexpr int kScatterUpdateIndex = 2; +constexpr int kScatterNDInputNum = 3; +constexpr int kScatterNDOutputNum = 1; +constexpr int kScatterShapeIndex = 0; +constexpr int kScatterIndicesIndex = 1; +constexpr int kScatterUpdateIndex = 2; } // namespace int ScatterNDCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto shape = inputs_.at(kScatterShapeIndex); auto indices = inputs_.at(kScatterIndicesIndex); auto update = inputs_.at(kScatterUpdateIndex); @@ -146,7 +150,12 @@ int ScatterNDRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ScatterNDCPUKernel::Run() { - int ret = LiteBackendParallelLaunch(ScatterNDRun, this, thread_n_num_); + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } + ret = LiteBackendParallelLaunch(ScatterNDRun, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ScatterND error error_code[" << ret << "]"; return RET_ERROR; @@ -158,13 +167,13 @@ int ScatterNDCPUKernel::Run() { kernel::LiteKernel *CpuScatterNDFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_ScatterND); if (opParameter == nullptr) { MS_LOG(ERROR) << "desc type is not scatterND"; return nullptr; } - auto *kernel = new (std::nothrow) ScatterNDCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ScatterNDCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; return nullptr; @@ -183,4 +192,3 @@ kernel::LiteKernel *CpuScatterNDFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_num_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_num_(ctx->thread_num_) {} ~ScatterNDCPUKernel() override = default; int Init() override; @@ -49,4 +50,3 @@ class ScatterNDCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SCATTER_ND_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc index 077e174fcf..aee8f2beaf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/shape.cc @@ -27,14 +27,19 @@ using mindspore::schema::PrimitiveType_Shape; namespace mindspore::kernel { namespace { - constexpr int kShapeInputNum = 1; - constexpr int kShapeOutputNum = 1; +constexpr int kShapeInputNum = 1; +constexpr int kShapeOutputNum = 1; } // namespace int ShapeCPUKernel::Init() { return RET_OK; } int ShapeCPUKernel::ReSize() { return RET_OK; } int ShapeCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto out_tensor = outputs_.front(); auto in_tensor = inputs_.front(); if (in_tensor == nullptr || out_tensor == nullptr) { @@ -55,14 +60,14 @@ int ShapeCPUKernel::Run() { kernel::LiteKernel *CpuShapeFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, - OpParameter *opParameter, - const lite::Context *ctx, const kernel::KernelKey &desc) { + OpParameter *opParameter, const lite::Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_Shape); if (opParameter == nullptr) { MS_LOG(ERROR) << "desc type is not Shape"; return nullptr; } - auto *kernel = new (std::nothrow) ShapeCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) ShapeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; return nullptr; @@ -81,4 +86,3 @@ kernel::LiteKernel *CpuShapeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~ShapeCPUKernel() override = default; int Init() override; @@ -39,4 +40,3 @@ class ShapeCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SHAPE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc index 91d02b5623..97a320d67b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.cc @@ -40,6 +40,10 @@ int SliceLaunch(int thread_id, LiteParallelGroupEnv *penv, void *cdata) { } // namespace int SliceCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto *param = reinterpret_cast(opParameter); auto input_shape = inputs_[0]->shape(); if (input_shape.size() != param->param_length_) { @@ -68,6 +72,11 @@ int SliceCPUKernel::SliceParallelRun(int thread_id) { } int SliceCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } SliceParameter *param = reinterpret_cast(opParameter); for (int i = 0; i < param->param_length_; ++i) { if (param->size_[i] < 0) { @@ -86,7 +95,7 @@ int SliceCPUKernel::Run() { DoSliceNoParallel(input_data, output_data, param); return RET_OK; } - int ret = LiteBackendParallelLaunch(SliceLaunch, this, param->op_parameter_.thread_num_); + ret = LiteBackendParallelLaunch(SliceLaunch, this, param->op_parameter_.thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "slice launch fail!ret: " << ret; return RET_ERROR; @@ -97,7 +106,7 @@ int SliceCPUKernel::Run() { kernel::LiteKernel *CpuSliceFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; @@ -108,7 +117,7 @@ kernel::LiteKernel *CpuSliceFp32KernelCreator(const std::vectorthread_num_ = ctx->thread_num_; - auto *kernel = new (std::nothrow) SliceCPUKernel(op_parameter, inputs, outputs); + auto *kernel = new (std::nothrow) SliceCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SliceCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.h b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.h index a02baf4918..8ed727a503 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/slice.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/slice.h @@ -19,18 +19,17 @@ #include #include "src/lite_kernel.h" - namespace mindspore::kernel { class SliceCPUKernel : public LiteKernel { public: SliceCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~SliceCPUKernel() = default; int Init() override; - int ReSize() override { - return 0; - } + int ReSize() override { return 0; } int Run() override; int SliceParallelRun(int thread_id); }; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc index ffdb5080e0..cda47c6a83 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.cc @@ -30,21 +30,44 @@ using mindspore::schema::PrimitiveType_SoftMax; namespace mindspore::kernel { int SoftmaxCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } SoftmaxBaseCPUKernel::Init(); // malloc tmp buffer + auto n_dim = softmax_param_->n_dim_; auto axis = softmax_param_->axis_; - sum_data = reinterpret_cast(malloc(softmax_param_->input_shape_[axis] * sizeof(float))); - memset(sum_data, 0, softmax_param_->input_shape_[axis] * sizeof(float)); + if (axis == -1) { + softmax_param_->axis_ += n_dim; + axis = softmax_param_->axis_; + } + auto in_shape = inputs_.front()->shape(); + int out_plane_size = 1; + for (int i = 0; i < axis; ++i) { + out_plane_size *= in_shape[i]; + } + int in_plane_size = 1; + for (int i = axis + 1; i < n_dim; i++) { + in_plane_size *= in_shape[i]; + } + sum_data_ = reinterpret_cast(malloc(out_plane_size * in_plane_size * sizeof(float))); + memset(sum_data_, 0, out_plane_size * in_plane_size * sizeof(float)); return RET_OK; } int SoftmaxCPUKernel::ReSize() { return RET_OK; } int SoftmaxCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_ptr = reinterpret_cast(inputs_.at(kInputIndex)->Data()); auto output_ptr = reinterpret_cast(outputs_.at(kOutputIndex)->Data()); - Softmax(input_ptr, output_ptr, sum_data, softmax_param_); + Softmax(input_ptr, output_ptr, sum_data_, softmax_param_); return RET_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.h b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.h index 0e9c0a7ebf..515535a328 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/softmax.h @@ -25,16 +25,21 @@ namespace mindspore::kernel { class SoftmaxCPUKernel : public SoftmaxBaseCPUKernel { public: SoftmaxCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : SoftmaxBaseCPUKernel(parameter, inputs, outputs, ctx) {} - ~SoftmaxCPUKernel() override = default; + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : SoftmaxBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + ~SoftmaxCPUKernel() override { + if (sum_data_ != nullptr) { + free(sum_data_); + } + }; int Init() override; int ReSize() override; int Run() override; private: - float *sum_data; + float *sum_data_; }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc index 5ac8d4db97..6849ee358f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.cc @@ -31,6 +31,10 @@ using mindspore::schema::PrimitiveType_SpaceToBatch; namespace mindspore::kernel { int SpaceToBatchCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } if (inputs_[0]->GetFormat() != schema::Format_NHWC) { MS_LOG(ERROR) << "space_to_batch only support NHWC now!"; return RET_FORMAT_ERR; @@ -50,13 +54,17 @@ int SpaceToBatchCPUKernel::Init() { } int SpaceToBatchCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input = inputs_[0]; auto output = outputs_[0]; input_ptr_ = reinterpret_cast(input->Data()); output_ptr_ = reinterpret_cast(output->Data()); SpaceToBatchParameter *param = reinterpret_cast(this->opParameter); - int ret; float *tmp_space[3] = {nullptr, nullptr, nullptr}; if (param->need_paddings_) { tmp_space[0] = reinterpret_cast(malloc(param->num_elements_padded_ * sizeof(float))); @@ -81,12 +89,12 @@ int SpaceToBatchCPUKernel::Run() { kernel::LiteKernel *CpuSpaceToBatchFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) SpaceToBatchCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) SpaceToBatchCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SpaceToBatchCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.h b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.h index 510649f2c0..453364c6d9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_batch.h @@ -23,8 +23,9 @@ namespace mindspore::kernel { class SpaceToBatchCPUKernel : public LiteKernel { public: SpaceToBatchCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~SpaceToBatchCPUKernel() = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc index 13aa702567..cbb5cc426c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.cc @@ -32,6 +32,10 @@ using mindspore::schema::PrimitiveType_SpaceToDepth; namespace mindspore::kernel { int SpaceToDepthCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } if (inputs_[0]->GetFormat() != schema::Format_NHWC) { MS_LOG(ERROR) << "space_to_depth only support NHWC now!"; return RET_FORMAT_ERR; @@ -77,10 +81,15 @@ int SpaceToDepthRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int SpaceToDepthCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } input_ptr_ = reinterpret_cast(inputs_[0]->Data()); output_ptr_ = reinterpret_cast(outputs_[0]->Data()); if (inputs_[0]->GetFormat() == schema::Format_NHWC) { - int ret = LiteBackendParallelLaunch(SpaceToDepthRun, this, thread_h_num_); + ret = LiteBackendParallelLaunch(SpaceToDepthRun, this, thread_h_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SpaceToDepth error error_code[" << ret << "]"; return ret; @@ -90,16 +99,18 @@ int SpaceToDepthCPUKernel::Run() { MS_LOG(ERROR) << "Only support NHWC now!"; return RET_ERROR; } + return RET_OK; } + kernel::LiteKernel *CpuSpaceToDepthFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "Input opParameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) SpaceToDepthCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) SpaceToDepthCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SpaceToDepthCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.h b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.h index 749de65503..1756358927 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/space_to_depth.h @@ -24,8 +24,9 @@ namespace mindspore::kernel { class SpaceToDepthCPUKernel : public LiteKernel { public: SpaceToDepthCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_num_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_num_(ctx->thread_num_) {} ~SpaceToDepthCPUKernel() = default; int SpaceToDepth(int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc index 359a379985..b48f1c4f80 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_to_dense.cc @@ -49,6 +49,11 @@ int SparseToDenseRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { return RET_OK; } int SparseToDenseCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input = inputs_.at(0); auto input1 = inputs_.at(1); auto input2 = inputs_.at(2); @@ -65,7 +70,7 @@ int SparseToDenseCPUKernel::Run() { std::vector temp_shape = output0->shape(); output_shape_ = reinterpret_cast(temp_shape.data()); - auto ret = LiteBackendParallelLaunch(SparseToDenseRun, this, s2d_param_->thread_num_); + ret = LiteBackendParallelLaunch(SparseToDenseRun, this, s2d_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "SparseToDenseRun error: error_code[" << ret << "]"; return RET_ERROR; @@ -76,13 +81,13 @@ int SparseToDenseCPUKernel::Run() { kernel::LiteKernel *CpuSparseToDenseFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_SparseToDense); - auto *kernel = new (std::nothrow) SparseToDenseCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) SparseToDenseCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new SparseToDenseCPUKernel fail!"; return nullptr; @@ -99,4 +104,3 @@ kernel::LiteKernel *CpuSparseToDenseFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { s2d_param_ = (reinterpret_cast(opParameter)); } ~SparseToDenseCPUKernel() = default; @@ -56,4 +57,3 @@ class SparseToDenseCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SPARSETODENSE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc index 81942f7a37..2b8082ef93 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/split.cc @@ -31,12 +31,12 @@ using mindspore::schema::PrimitiveType_Split; namespace mindspore::kernel { int SplitCPUKernel::Init() { - SplitBaseCPUKernel::Init(); - auto in_tensor = inputs_.front(); - input_ptr_ = reinterpret_cast(in_tensor->Data()); - for (int i = 0; i < param->num_split_; i++) { - output_ptr_.push_back(reinterpret_cast(outputs_.at(i)->Data())); + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; } + SplitBaseCPUKernel::Init(); + output_ptr_.resize(param->num_split_); return RET_OK; } @@ -68,7 +68,17 @@ int SplitRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int SplitCPUKernel::Run() { - int ret = LiteBackendParallelLaunch(SplitRun, this, thread_n_num_); + auto ret = Prepare(); + auto in_tensor = inputs_.front(); + input_ptr_ = reinterpret_cast(in_tensor->Data()); + for (int i = 0; i < output_ptr_.size(); i++) { + output_ptr_[i] = reinterpret_cast(outputs_.at(i)->Data()); + } + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } + ret = LiteBackendParallelLaunch(SplitRun, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/split.h b/mindspore/lite/src/runtime/kernel/arm/fp32/split.h index 5761367abb..0796d7b135 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/split.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/split.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class SplitCPUKernel : public SplitBaseCPUKernel { public: SplitCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : SplitBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : SplitBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~SplitCPUKernel() override = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc index fbc102eec0..0074f975ab 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/squeeze.cc @@ -28,8 +28,8 @@ using mindspore::schema::PrimitiveType_Squeeze; namespace mindspore::kernel { namespace { - constexpr int kSqueezeInputNum = 1; - constexpr int kSqueezeOutputNum = 1; +constexpr int kSqueezeInputNum = 1; +constexpr int kSqueezeOutputNum = 1; } // namespace int SqueezeCPUKernel::Init() { return RET_OK; } @@ -37,10 +37,15 @@ int SqueezeCPUKernel::Init() { return RET_OK; } int SqueezeCPUKernel::ReSize() { return RET_OK; } int SqueezeCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_ptr = reinterpret_cast(inputs_.front()->Data()); auto output_ptr = reinterpret_cast(outputs_.front()->Data()); size_t data_size = inputs_.front()->Size(); - auto ret = DoSqueeze(input_ptr, output_ptr, data_size); + ret = DoSqueeze(input_ptr, output_ptr, data_size); if (ret != RET_OK) { MS_LOG(ERROR) << "Do squeeze failed."; return RET_ERROR; @@ -51,13 +56,13 @@ int SqueezeCPUKernel::Run() { kernel::LiteKernel *CpuSqueezeFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_Squeeze); if (opParameter == nullptr) { MS_LOG(ERROR) << "desc type is not Squeeze"; return nullptr; } - auto *kernel = new (std::nothrow) SqueezeCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) SqueezeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; return nullptr; @@ -76,4 +81,3 @@ kernel::LiteKernel *CpuSqueezeFp32KernelCreator(const std::vector #include "src/lite_kernel.h" - namespace mindspore::kernel { class SqueezeCPUKernel : public LiteKernel { public: explicit SqueezeCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~SqueezeCPUKernel() override = default; int Init() override; @@ -40,4 +40,3 @@ class SqueezeCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_SQUEEZE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc index 344e6762ca..e12079bcf0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/stack.cc @@ -27,6 +27,10 @@ using mindspore::schema::PrimitiveType_Stack; namespace mindspore::kernel { int StackCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } StackParameter *param = reinterpret_cast(opParameter); auto input0_shape = inputs_[0]->shape(); axis_ = param->axis_ < 0 ? param->axis_ + input0_shape.size() : param->axis_; @@ -67,6 +71,11 @@ int StackCPUKernel::Init() { } int StackCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } size_t inputs_num = inputs_.size(); auto input0_shape = inputs_[0]->shape(); auto *output_data = reinterpret_cast(outputs_[0]->Data()); @@ -87,13 +96,13 @@ int StackCPUKernel::Run() { kernel::LiteKernel *CpuStackFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *op_parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (op_parameter == nullptr) { MS_LOG(ERROR) << "Input op_parameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Stack); - auto *kernel = new (std::nothrow) StackCPUKernel(op_parameter, inputs, outputs); + auto *kernel = new (std::nothrow) StackCPUKernel(op_parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new StackCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/stack.h b/mindspore/lite/src/runtime/kernel/arm/fp32/stack.h index c1d76ca193..179bc21392 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/stack.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/stack.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class StackCPUKernel : public LiteKernel { public: StackCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs), + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), convert_functions_(inputs_.size(), nullptr), packed_inputs_(inputs_.size(), nullptr) {} @@ -51,4 +52,3 @@ class StackCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_STACK_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc index 62a1502774..9b6b6336fb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/tile.cc @@ -25,6 +25,10 @@ using mindspore::schema::PrimitiveType_Tile; namespace mindspore::kernel { int TileCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto tile_parameter_ = reinterpret_cast(opParameter); for (int i = 0; i < tile_parameter_->in_dim_; ++i) { tile_parameter_->in_shape_[i] = inputs_[0]->shape()[i]; @@ -46,6 +50,11 @@ void TileCPUKernel::ComputeStrides(int *shape, int *strides, int ndim) { int TileCPUKernel::ReSize() { return RET_OK; } int TileCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_addr = reinterpret_cast(inputs_.at(0)->Data()); auto output_addr = reinterpret_cast(outputs_.at(0)->Data()); @@ -55,13 +64,14 @@ int TileCPUKernel::Run() { kernel::LiteKernel *CpuTileFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, - const lite::Context *ctx, const KernelKey &desc) { + const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { if (parameter == nullptr || ctx == nullptr) { MS_LOG(ERROR) << "parameter or ctx is nullptr"; return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Tile); - auto *kernel = new (std::nothrow) TileCPUKernel(parameter, inputs, outputs); + auto *kernel = new (std::nothrow) TileCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; return nullptr; @@ -79,4 +89,3 @@ kernel::LiteKernel *CpuTileFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~TileCPUKernel() override {} int Init() override; @@ -38,4 +39,3 @@ class TileCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_TILE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc index 954ec041bc..ece7442b49 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.cc @@ -25,6 +25,10 @@ using mindspore::schema::PrimitiveType_TopK; namespace mindspore::kernel { int TopKCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } TopkParameter *parameter = reinterpret_cast(opParameter); lite::tensor::Tensor *input = inputs_.at(0); parameter->last_dim_size_ = input->shape()[input->shape().size() - 1]; @@ -44,6 +48,11 @@ int TopKCPUKernel::Init() { int TopKCPUKernel::ReSize() { return RET_OK; } int TopKCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_data = reinterpret_cast(inputs_.at(0)->Data()); auto output_data = reinterpret_cast(outputs_.at(0)->Data()); auto output_index = reinterpret_cast(outputs_.at(1)->Data()); @@ -54,9 +63,11 @@ int TopKCPUKernel::Run() { kernel::LiteKernel *CpuTopKFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, - const lite::Context *ctx, const KernelKey &desc) { + const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(parameter != nullptr); - auto *kernel = new (std::nothrow) TopKCPUKernel(parameter, inputs, outputs); + MS_ASSERT(desc.type == PrimitiveType_Tile); + auto *kernel = new (std::nothrow) TopKCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new TopKCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.h b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.h index 9ed7af2f39..f07d2847fc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/topk.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/topk.h @@ -24,8 +24,9 @@ namespace mindspore::kernel { class TopKCPUKernel : public LiteKernel { public: explicit TopKCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~TopKCPUKernel() override { TopkParameter *parameter = reinterpret_cast(opParameter); free(parameter->topk_node_list_); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc index a6473114fa..89485726be 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/transpose.cc @@ -28,10 +28,14 @@ using mindspore::schema::PrimitiveType_Transpose; namespace mindspore::kernel { namespace { - constexpr int kTransposeInputNum = 1; - constexpr int kTransposeOutputNum = 1; +constexpr int kTransposeInputNum = 1; +constexpr int kTransposeOutputNum = 1; } // namespace int TransposeCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto &inTensor = inputs_.front(); auto &outTensor = outputs_.front(); auto param = reinterpret_cast(opParameter); @@ -50,6 +54,11 @@ int TransposeCPUKernel::Init() { int TransposeCPUKernel::ReSize() { return RET_OK; } int TransposeCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } MS_ASSERT(inputs_.size() == TransposeInputNum); MS_ASSERT(outputs_.size() == TransposeOutputNum); auto &inTensor = inputs_.front(); @@ -65,21 +74,20 @@ int TransposeCPUKernel::Run() { auto *input_shape = &in_shape.front(); auto *output_shape = &out_shape.front(); - auto ret = - DoTranspose(in_data, out_data, input_shape, output_shape, reinterpret_cast(opParameter)); + ret = DoTranspose(in_data, out_data, input_shape, output_shape, reinterpret_cast(opParameter)); return ret; } kernel::LiteKernel *CpuTransposeFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_Transpose); if (opParameter == nullptr) { MS_LOG(ERROR) << "desc type is not Transpose"; return nullptr; } - auto *kernel = new (std::nothrow) TransposeCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) TransposeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "New kernel fails."; return nullptr; @@ -97,4 +105,3 @@ kernel::LiteKernel *CpuTransposeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(param, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(param, inputs, outputs, ctx, primitive) {} ~TransposeCPUKernel() override = default; int Init() override; @@ -41,4 +41,3 @@ class TransposeCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_CCSRC_KERNEL_CPU_ARM_FP32_TRANSPOSE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc index dc93554fa7..37b28f59d1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unique.cc @@ -28,6 +28,11 @@ int UniqueCPUKernel::Init() { return RET_OK; } int UniqueCPUKernel::ReSize() { return RET_OK; } int UniqueCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input = reinterpret_cast(inputs_.at(0)->Data()); auto output0 = reinterpret_cast(outputs_.at(0)->Data()); auto output1 = reinterpret_cast(outputs_.at(1)->Data()); @@ -43,11 +48,11 @@ int UniqueCPUKernel::Run() { kernel::LiteKernel *CpuUniqueFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, - OpParameter *parameter, const lite::Context *ctx, - const KernelKey &desc) { + OpParameter *parameter, const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(parameter); MS_ASSERT(desc.type == PrimitiveType_Unique); - auto *kernel = new (std::nothrow) UniqueCPUKernel(parameter, inputs, outputs); + auto *kernel = new (std::nothrow) UniqueCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; return nullptr; @@ -64,4 +69,3 @@ kernel::LiteKernel *CpuUniqueFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~UniqueCPUKernel() = default; int Init() override; @@ -37,4 +38,3 @@ class UniqueCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNIQUE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc index 2555605caa..cd1034fcc0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unsqueeze.cc @@ -28,6 +28,10 @@ using mindspore::schema::PrimitiveType_Unsqueeze; namespace mindspore::kernel { int UnsqueezeCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } int ret = ReSize(); return ret; } @@ -64,9 +68,14 @@ int UnsqueezeRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int UnsqueezeCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } in_ptr_ = reinterpret_cast(inputs_.at(0)->Data()); out_ptr_ = reinterpret_cast(outputs_.at(0)->Data()); - int ret = LiteBackendParallelLaunch(UnsqueezeRun, this, thread_sz_count_); + ret = LiteBackendParallelLaunch(UnsqueezeRun, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "UnsqueezeRun error error_code[" << ret << "]"; return ret; @@ -75,12 +84,12 @@ int UnsqueezeCPUKernel::Run() { } kernel::LiteKernel *CpuUnsqueezeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const std::vector &outputs, + OpParameter *opParameter, const lite::Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Unsqueeze); - auto *kernel = new (std::nothrow) UnsqueezeCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) UnsqueezeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new UnsqueezeCPUKernel fail!"; return nullptr; @@ -97,4 +106,3 @@ kernel::LiteKernel *CpuUnsqueezeFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) {} ~UnsqueezeCPUKernel() = default; int Init() override; @@ -48,4 +49,3 @@ class UnsqueezeCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSQUEEZE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc index 8facbc7a9d..1d18036953 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.cc @@ -24,6 +24,10 @@ using mindspore::schema::PrimitiveType_Unstack; namespace mindspore::kernel { int UnstackCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto input = inputs_.at(0); MS_ASSERT(input != nullptr); size_t shape_size = input->shape().size(); @@ -56,6 +60,11 @@ int UnstackCPUKernel::Init() { int UnstackCPUKernel::ReSize() { return RET_OK; } int UnstackCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } float *input = reinterpret_cast(inputs_.at(0)->Data()); size_t out_num = outputs_.size(); for (size_t i = 0; i < out_num; i++) { @@ -67,11 +76,11 @@ int UnstackCPUKernel::Run() { kernel::LiteKernel *CpuUnstackFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, - OpParameter *parameter, const lite::Context *ctx, - const KernelKey &desc) { + OpParameter *parameter, const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(parameter != nullptr); MS_ASSERT(desc.type == PrimitiveType_Unstack); - auto *kernel = new (std::nothrow) UnstackCPUKernel(parameter, inputs, outputs); + auto *kernel = new (std::nothrow) UnstackCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.h b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.h index e652ad6adf..bc7181365f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/unstack.h @@ -24,11 +24,10 @@ namespace mindspore::kernel { class UnstackCPUKernel : public LiteKernel { public: UnstackCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} - ~UnstackCPUKernel() { - free(output_addr_array_); - } + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} + ~UnstackCPUKernel() { free(output_addr_array_); } int Init() override; int ReSize() override; @@ -40,4 +39,3 @@ class UnstackCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSTACK_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc index f2bf03fc46..ad59ff334d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/where.cc @@ -48,6 +48,11 @@ int WhereRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { return RET_OK; } int WhereCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input = inputs_.at(0); auto input1 = inputs_.at(1); auto input2 = inputs_.at(2); @@ -74,7 +79,7 @@ int WhereCPUKernel::Run() { MS_LOG(ERROR) << "Error, inputs' length are zero !!!"; return RET_ERROR; } - auto ret = LiteBackendParallelLaunch(WhereRun, this, where_param_->thread_num_); + ret = LiteBackendParallelLaunch(WhereRun, this, where_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "WhereDwRun error: error_code[" << ret << "]"; return RET_ERROR; @@ -85,13 +90,13 @@ int WhereCPUKernel::Run() { kernel::LiteKernel *CpuWhereFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_Where); - auto *kernel = new (std::nothrow) WhereCPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) WhereCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new WhereCPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/where.h b/mindspore/lite/src/runtime/kernel/arm/fp32/where.h index ad9c73a9fa..d8bb43de25 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/where.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/where.h @@ -29,8 +29,9 @@ namespace mindspore::kernel { class WhereCPUKernel : public LiteKernel { public: WhereCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { where_param_ = reinterpret_cast(opParameter); } ~WhereCPUKernel() = default; @@ -53,4 +54,3 @@ class WhereCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_WHERE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc index 6fcd25dc48..fc897e43c5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/zeroslike.cc @@ -33,6 +33,11 @@ constexpr int kOutputNum = 1; int ZerosLikeCPUKernel::Init() { return RET_OK; } int ZerosLikeCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input = inputs_.at(0); auto input_data = reinterpret_cast(input->Data()); auto output_data = reinterpret_cast(outputs_.at(0)->Data()); @@ -43,13 +48,13 @@ int ZerosLikeCPUKernel::Run() { kernel::LiteKernel *CpuZerosLikeFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (opParameter == nullptr) { MS_LOG(ERROR) << "input opParameter is nullptr!"; return nullptr; } MS_ASSERT(desc.type == schema::PrimitiveType_ZerosLike); - auto *kernel = new (std::nothrow) ZerosLikeCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) ZerosLikeCPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new ZerosLikeCPUKernel fail!"; return nullptr; @@ -66,4 +71,3 @@ kernel::LiteKernel *CpuZerosLikeFp32KernelCreator(const std::vector #include "src/lite_kernel.h" - namespace mindspore::kernel { class ZerosLikeCPUKernel : public LiteKernel { public: ZerosLikeCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~ZerosLikeCPUKernel() = default; @@ -36,4 +36,3 @@ class ZerosLikeCPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ZEROSLIKE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/activation_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc similarity index 85% rename from mindspore/lite/src/runtime/kernel/arm/fp32/activation_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc index 279832aca2..7ed31910cd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/activation_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.cc @@ -14,14 +14,14 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/fp32/activation_grad.h" +#include "src/runtime/kernel/arm/fp32_grad/activation_grad.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "src/runtime/runtime_api.h" #include "include/errorcode.h" -using mindspore::lite::KernelRegistrar; using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; using mindspore::schema::ActivationGradType_HSWISH; @@ -32,8 +32,8 @@ using mindspore::schema::PrimitiveType_ActivationGrad; namespace mindspore::kernel { int ActivationGradCPUKernel::Init() { - outputs_[0]->set_shape(inputs_[0]->shape()); - return RET_OK; + outputs_[0]->set_shape(inputs_[0]->shape()); + return RET_OK; } int ActivationGradCPUKernel::ReSize() { return RET_OK; } @@ -58,7 +58,7 @@ int ActivationGradCPUKernel::DoActivation(int task_id) { error_code = TanhGrad(yt_addr, input_addr, length, output_addr); } else if (type_ == schema::ActivationGradType_HSWISH) { error_code = HSwishGrad(yt_addr, input_addr, length, output_addr); - } else if (type_ == schema::ActivationGradType_HSIGMOID) { + } else if (type_ == schema::ActivationGradType_HSIGMOID) { error_code = HSigmoidGrad(yt_addr, input_addr, length, output_addr); } else { MS_LOG(ERROR) << "Activation type error"; @@ -90,18 +90,20 @@ int ActivationGradCPUKernel::Run() { } kernel::LiteKernel *CpuActivationGradFp32KernelCreator(const std::vector &inputs, - const std::vector &outputs, - OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const std::vector &outputs, + OpParameter *opParameter, const lite::Context *ctx, + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_ActivationGrad); - auto *kernel = new (std::nothrow) ActivationGradCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) ActivationGradCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); if (ret != RET_OK) { - MS_LOG(ERROR) << "InferShape kernel failed, name: " << opParameter->name_ - << ", type: " + MS_LOG(ERROR) << "InferShape kernel failed, name: " << opParameter->name_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + delete kernel; + return nullptr; } return kernel; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/activation_grad.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.h similarity index 77% rename from mindspore/lite/src/runtime/kernel/arm/fp32/activation_grad.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.h index c3de590123..56ddf0f5fc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/activation_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ACTIVATION_GRAD_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ACTIVATION_GRAD_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_ACTIVATION_GRAD_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_ACTIVATION_GRAD_H_ #include #include "src/lite_kernel.h" @@ -27,8 +27,9 @@ namespace mindspore::kernel { class ActivationGradCPUKernel : public LiteKernel { public: explicit ActivationGradCPUKernel(OpParameter *param, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(param, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(param, inputs, outputs, ctx, primitive) { ActivationGradParameter *param_act_grad = reinterpret_cast(param); type_ = param_act_grad->type_; alpha_ = param_act_grad->alpha_; @@ -47,4 +48,4 @@ class ActivationGradCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ACTIVATION_GRAD_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_ACTIVATION_GRAD_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc similarity index 97% rename from mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc index b3f9075bef..0639433ef4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.cc @@ -16,9 +16,9 @@ #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "src/runtime/kernel/arm/nnacl/fp32/reduce_grad.h" -#include "src/runtime/kernel/arm/fp32/arithmetic_grad.h" -#include "src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/reduce_grad.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/arithmetic_grad.h" +#include "src/runtime/kernel/arm/fp32_grad/arithmetic_grad.h" #include "include/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kCPU; @@ -261,12 +261,13 @@ int ArithmeticGradCPUKernel::Run() { kernel::LiteKernel *CpuArithmeticGradFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_EXCEPTION_IF_NULL(opParameter); if (opParameter == nullptr) { return nullptr; } - auto *kernel = new (std::nothrow) ArithmeticGradCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) ArithmeticGradCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); if (ret != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_grad.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.h similarity index 88% rename from mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_grad.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.h index cea0c0e659..0e919c7b7f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ARITHMETIC_GRAD_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ARITHMETIC_GRAD_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_ARITHMETIC_GRAD_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_ARITHMETIC_GRAD_H_ #include #include "src/lite_kernel.h" @@ -37,8 +37,9 @@ class ArithmeticGradCPUKernel : public LiteKernel { public: explicit ArithmeticGradCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs), tile_data0(NULL), tile_data1(NULL), tile_data2(NULL) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), tile_data0(NULL), tile_data1(NULL), tile_data2(NULL) { switch (type()) { case PrimitiveType_MulGrad: arithmetic_grad_ = &ArithmeticGradCPUKernel::ArithmeticGradMul; // this will be adjusted in InferShape @@ -87,4 +88,4 @@ class ArithmeticGradCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_ARITHMETIC_GRAD_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_ARITHMETIC_GRAD_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bias_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc similarity index 91% rename from mindspore/lite/src/runtime/kernel/arm/fp32/bias_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc index e57fe298ab..e5e53b0974 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bias_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.cc @@ -15,17 +15,16 @@ */ #include -#include "src/runtime/kernel/arm/fp32/bias_grad.h" +#include "src/runtime/kernel/arm/fp32_grad/bias_grad.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "include/errorcode.h" - using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; -using mindspore::schema::PrimitiveType_BiasGrad; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_BiasGrad; namespace mindspore::kernel { int BiasGradCPUKernel::InferShape() { @@ -68,10 +67,14 @@ int BiasGradCPUKernel::Init() { return RET_OK; } - int BiasGradCPUKernel::ReSize() { return 0; } int BiasGradCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto in = reinterpret_cast(inputs_.at(0)->Data()); auto out = reinterpret_cast(outputs_.at(0)->Data()); // size_t data_size = inputs_.at(0)->ElementsNum(); @@ -91,14 +94,14 @@ int BiasGradCPUKernel::Run() { return RET_OK; } - kernel::LiteKernel *CpuBiasGradFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_BiasGrad); - auto *kernel = new (std::nothrow) BiasGradCPUKernel(reinterpret_cast(opParameter), inputs, outputs); + auto *kernel = + new (std::nothrow) BiasGradCPUKernel(reinterpret_cast(opParameter), inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bias_grad.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.h similarity index 89% rename from mindspore/lite/src/runtime/kernel/arm/fp32/bias_grad.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.h index 797abfd162..ed652ab617 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bias_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class BiasGradCPUKernel : public LiteKernel { public: explicit BiasGradCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { bias_param = reinterpret_cast(parameter); } ~BiasGradCPUKernel() override = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bngrad_input.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc similarity index 94% rename from mindspore/lite/src/runtime/kernel/arm/fp32/bngrad_input.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc index 2a07167058..752a8440e9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bngrad_input.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.cc @@ -18,8 +18,8 @@ #include #include "schema/model_generated.h" #include "src/kernel_factory.h" -#include "src/runtime/kernel/arm/fp32/bngrad_input.h" -#include "src/runtime//kernel/arm/nnacl/batch_norm.h" +#include "src/runtime/kernel/arm/fp32_grad/bn_grad.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/batch_norm.h" #include "include/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kCPU; @@ -54,10 +54,6 @@ int BNGradInputCPUKernel::Init() { int BNGradInputCPUKernel::ReSize() { return RET_OK; } -/* -according to https://wiseodd.github.io/techblog/2016/07/04/batchnorm -*/ - int BNGradInputCPUKernel::Run() { // std::cout << "run succ" << std::endl; auto *input_x = inputs_.at(0); @@ -96,17 +92,19 @@ int BNGradInputCPUKernel::Run() { kernel::LiteKernel *CpuBNGradInputFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_BNGradInput); // parameter->name = opDef.name()->str().data(); // parameter->type = opDef.attr_type(); - auto *kernel = new (std::nothrow) BNGradInputCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) BNGradInputCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); if (RET_OK != ret) { MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + delete kernel; + return nullptr; } return kernel; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/bngrad_input.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.h similarity index 74% rename from mindspore/lite/src/runtime/kernel/arm/fp32/bngrad_input.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.h index e4e6d6e746..6476ceddbb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/bngrad_input.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/bn_grad.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BNGRAD_INPUT_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BNGRAD_INPUT_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_BNGRAD_INPUT_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_BNGRAD_INPUT_H_ #include #include "src/lite_kernel.h" @@ -25,8 +25,9 @@ namespace mindspore::kernel { class BNGradInputCPUKernel : public LiteKernel { public: explicit BNGradInputCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~BNGradInputCPUKernel() override { delete workspace; } int Init() override; @@ -38,4 +39,4 @@ class BNGradInputCPUKernel : public LiteKernel { int workspace_size; }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_BNGRAD_INPUT_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_BNGRAD_INPUT_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_filter.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc similarity index 93% rename from mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_filter.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc index 3deb6a2017..844062e324 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_filter.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/fp32/convolution_grad_filter.h" +#include "src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.h" #include "src/kernel_registry.h" #include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/pack_ext.h" -#include "src/runtime/kernel/arm/nnacl/fp32/gemm.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/gemm.h" #include "include/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kCPU; @@ -135,11 +135,12 @@ int ConvolutionGradFilterCPUKernel::Run() { kernel::LiteKernel *CpuConvGradFilterFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Conv2DGradFilter); - auto *kernel = new (std::nothrow) ConvolutionGradFilterCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) ConvolutionGradFilterCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_filter.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.h similarity index 72% rename from mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_filter.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.h index c32a798eaf..7a9354be7e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_filter.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_GRAD_FILTER_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_GRAD_FILTER_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_CONVOLUTION_GRAD_FILTER_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_CONVOLUTION_GRAD_FILTER_H_ #include #include "src/lite_kernel.h" @@ -25,8 +25,9 @@ namespace mindspore::kernel { class ConvolutionGradFilterCPUKernel : public LiteKernel { public: explicit ConvolutionGradFilterCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionGradFilterCPUKernel() override { delete workspace; } int Init() override; @@ -38,4 +39,4 @@ class ConvolutionGradFilterCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_GRAD_FILTER_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_CONVOLUTION_GRAD_FILTER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_input.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.cc similarity index 94% rename from mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_input.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.cc index 6e0683b301..8563565bf6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_input.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.cc @@ -14,18 +14,18 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/fp32/convolution_grad_input.h" +#include "src/runtime/kernel/arm/fp32_grad/convolution_grad_input.h" #include "src/kernel_registry.h" #include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/pack_ext.h" -#include "src/runtime/kernel/arm/nnacl/fp32/gemm.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/gemm.h" #include "include/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; -using mindspore::schema::PrimitiveType_Conv2DGradInput; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Conv2DGradInput; namespace mindspore::kernel { int ConvolutionGradInputCPUKernel::Init() { @@ -115,11 +115,11 @@ int ConvolutionGradInputCPUKernel::Run() { kernel::LiteKernel *CpuConvGradInputFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Conv2DGradInput); - auto *kernel = new (std::nothrow) ConvolutionGradInputCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) ConvolutionGradInputCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_input.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.h similarity index 72% rename from mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_input.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.h index 86901b37ba..9653fe06ad 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_input.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_GRAD_INPUT_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_GRAD_INPUT_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_CONVOLUTION_GRAD_INPUT_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_CONVOLUTION_GRAD_INPUT_H_ #include #include "src/lite_kernel.h" @@ -25,8 +25,9 @@ namespace mindspore::kernel { class ConvolutionGradInputCPUKernel : public LiteKernel { public: explicit ConvolutionGradInputCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionGradInputCPUKernel() override { delete workspace; } int Init() override; @@ -38,4 +39,4 @@ class ConvolutionGradInputCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_CONVOLUTION_GRAD_INPUT_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_CONVOLUTION_GRAD_INPUT_H diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/opt_momentum.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.cc similarity index 90% rename from mindspore/lite/src/runtime/kernel/arm/fp32/opt_momentum.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.cc index 84c51509ba..98f2e4143c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/opt_momentum.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.cc @@ -17,20 +17,25 @@ #include "schema/model_generated.h" #include "src/kernel_registry.h" -#include "src/runtime/kernel/arm/fp32/opt_momentum.h" +#include "src/runtime/kernel/arm/fp32_grad/opt_momentum.h" #include "include/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; -using mindspore::schema::PrimitiveType_OptMomentum; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_OptMomentum; namespace mindspore::kernel { int OptMomentumCPUKernel::ReSize() { return 0; } int OptMomentumCPUKernel::Run() { + auto prepare_ret = Prepare(); + if (prepare_ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << prepare_ret; + return prepare_ret; + } if (inputs_.size() != 5 || !outputs_.empty()) { MS_LOG(ERROR) << "OptMomentumCPUKernel error input output size!"; return RET_ERROR; @@ -59,9 +64,9 @@ int OptMomentumCPUKernel::Init() { return 0; } kernel::LiteKernel *CpuOptMomentumFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(desc.type == schema::PrimitiveType_OptMomentum); - auto *kernel = new (std::nothrow) OptMomentumCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) OptMomentumCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/opt_momentum.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.h similarity index 83% rename from mindspore/lite/src/runtime/kernel/arm/fp32/opt_momentum.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.h index ccc2871779..f9e0395ea3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/opt_momentum.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/opt_momentum.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class OptMomentumCPUKernel : public LiteKernel { public: explicit OptMomentumCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~OptMomentumCPUKernel() override {} int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc similarity index 96% rename from mindspore/lite/src/runtime/kernel/arm/fp32/pooling_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc index 23606e6fa7..c98b812515 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/fp32/pooling_grad.h" +#include "src/runtime/kernel/arm/fp32_grad/pooling_grad.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "src/runtime/kernel/arm/nnacl/fp32/pooling.h" -#include "src/runtime/kernel/arm/nnacl/fp32/pooling_grad.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.h" #include "include/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kCPU; @@ -175,11 +175,11 @@ int PoolingGradCPUKernel::Run() { kernel::LiteKernel *CpuPoolingGradFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_PoolingGrad); - auto *kernel = new (std::nothrow) PoolingGradCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) PoolingGradCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); if (RET_OK != ret) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_grad.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.h similarity index 79% rename from mindspore/lite/src/runtime/kernel/arm/fp32/pooling_grad.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.h index eec333d860..32c20f0abd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pooling_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/pooling_grad.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_POOLING_GRAD_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_POOLING_GRAD_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_POOLING_GRAD_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_POOLING_GRAD_H_ #include #include "src/lite_kernel.h" @@ -30,8 +30,9 @@ using mindspore::schema::RoundMode; class PoolingGradCPUKernel : public LiteKernel { public: explicit PoolingGradCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~PoolingGradCPUKernel() override = default; // int TfPadding(int input_w, int input_h, int &output_w, int &output_h); @@ -47,4 +48,4 @@ class PoolingGradCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_POOLING_GRAD_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_POOLING_GRAD_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power_grad.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc similarity index 94% rename from mindspore/lite/src/runtime/kernel/arm/fp32/power_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc index f99bd3e743..57209ab126 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/fp32/power_grad.h" +#include "src/runtime/kernel/arm/fp32_grad/power_grad.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "include/errorcode.h" @@ -50,10 +50,10 @@ int PowerGradCPUKernel::Run() { kernel::LiteKernel *CpuPowerGradFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_PowerGrad); - auto *kernel = new (std::nothrow) PowerGradCPUKernel(opParameter, inputs, outputs); + auto *kernel = new (std::nothrow) PowerGradCPUKernel(opParameter, inputs, outputs, ctx, primitive); auto ret = kernel->Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/power_grad.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.h similarity index 64% rename from mindspore/lite/src/runtime/kernel/arm/fp32/power_grad.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.h index 00b2e882f7..737de8c2a0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/power_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/power_grad.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_POWER_GRAD_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_POWER_GRAD_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_POWER_GRAD_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_POWER_GRAD_H_ #include #include "src/lite_kernel.h" @@ -26,12 +26,13 @@ namespace mindspore::kernel { class PowerGradCPUKernel : public LiteKernel { public: PowerGradCPUKernel(OpParameter *param, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(param, inputs, outputs) { - PowerParameter *power_param = reinterpret_cast(param); - power_ = power_param->power_; - scale_ = power_param->scale_; - shift_ = power_param->shift_; + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(param, inputs, outputs, ctx, primitive) { + PowerParameter *power_param = reinterpret_cast(param); + power_ = power_param->power_; + scale_ = power_param->scale_; + shift_ = power_param->shift_; } ~PowerGradCPUKernel() override = default; @@ -46,4 +47,4 @@ class PowerGradCPUKernel : public LiteKernel { }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_POWER_GRAD_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_GRAD_POWER_GRAD_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_softmax_cross_entropy_with_logits.cc b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc similarity index 87% rename from mindspore/lite/src/runtime/kernel/arm/fp32/sparse_softmax_cross_entropy_with_logits.cc rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc index fec15c1e00..c9d4706bdb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_softmax_cross_entropy_with_logits.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.cc @@ -14,13 +14,12 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/fp32/sparse_softmax_cross_entropy_with_logits.h" -#include "src/runtime/kernel/arm/nnacl/fp32/softmax.h" -#include "schema/model_generated.h" #include "src/kernel_registry.h" +#include "src/runtime/kernel/arm/nnacl/softmax_parameter.h" +#include "src/runtime/kernel/arm/nnacl/fp32/softmax.h" +#include "src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.h" #include "include/errorcode.h" -using mindspore::kernel::KERNEL_ARCH::kCPU; using mindspore::lite::KernelRegistrar; using mindspore::lite::RET_ERROR; using mindspore::lite::RET_OK; @@ -73,7 +72,7 @@ void SparseSoftmaxCrossEntropyWithLogitsCPUKernel::GradPostExecute(const int *la int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Run() { auto ins = reinterpret_cast(inputs_.at(0)->Data()); auto labels = reinterpret_cast(inputs_.at(1)->Data()); - auto out = reinterpret_cast(outputs_.at(0)->Data()); + auto out = reinterpret_cast(outputs_.at(1)->Data()); float *grads = NULL; if (is_train()) { // outputs_.size() > 1) grads = reinterpret_cast(outputs_.at(0)->Data()); @@ -90,10 +89,11 @@ int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Run() { SoftmaxParameter sm_params; sm_params.n_dim_ = param->n_dim_; sm_params.element_size_ = data_size; - sm_params.axis_ = 1; + sm_params.axis_ = 0; for (int i = 0; i < 4; i++) // softmax has only 4 params in shape sm_params.input_shape_[i] = param->input_shape_[i]; - float sum_data[sm_params.input_shape_[sm_params.axis_]]; + float sum_data[sm_params.input_shape_[sm_params.axis_]] = {0}; + std::fill(sum_data, sum_data + sm_params.input_shape_[sm_params.axis_], 0); Softmax(ins, losses, sum_data, &sm_params); if (is_train()) { @@ -105,6 +105,10 @@ int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Run() { } int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto dims = inputs_[0]->shape(); param->n_dim_ = 2; param->number_of_classes_ = dims[1]; @@ -126,10 +130,12 @@ int SparseSoftmaxCrossEntropyWithLogitsCPUKernel::Init() { kernel::LiteKernel *CpuSoftmaxCrossEntropyFp32KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_SoftmaxCrossEntropy); - auto *kernel = new (std::nothrow) SparseSoftmaxCrossEntropyWithLogitsCPUKernel(opParameter, inputs, outputs); + auto *kernel = + new (std::nothrow) SparseSoftmaxCrossEntropyWithLogitsCPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); if (RET_OK != ret) { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_softmax_cross_entropy_with_logits.h b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.h similarity index 86% rename from mindspore/lite/src/runtime/kernel/arm/fp32/sparse_softmax_cross_entropy_with_logits.h rename to mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.h index a8dd3439cd..4447d293ba 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/sparse_softmax_cross_entropy_with_logits.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.h @@ -20,7 +20,7 @@ #include #include "src/lite_kernel.h" #include "ir/anf.h" -#include "src/runtime/kernel/arm/nnacl/fp32/softmax_grad.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/softmax_grad.h" #include "src/runtime/kernel/arm/nnacl/fp32/arithmetic.h" namespace mindspore::kernel { @@ -29,8 +29,9 @@ class SparseSoftmaxCrossEntropyWithLogitsCPUKernel : public LiteKernel { public: explicit SparseSoftmaxCrossEntropyWithLogitsCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, + const lite::Context *ctx, const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { param = reinterpret_cast(parameter); } ~SparseSoftmaxCrossEntropyWithLogitsCPUKernel() override = default; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc b/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc index 32d933d5e8..3d9ba79303 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/activation.cc @@ -15,8 +15,9 @@ */ #include "src/runtime/kernel/arm/fp32/activation.h" -#include "src/runtime/kernel/arm/int8/relu_int8.h" +#include "src/runtime/kernel/arm/int8/relux_int8.h" #include "src/runtime/kernel/arm/int8/hswish_int8.h" +#include "src/runtime/kernel/arm/int8/sigmoid_int8.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "src/runtime/runtime_api.h" @@ -32,7 +33,7 @@ namespace mindspore::kernel { kernel::LiteKernel *CpuActivationInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, const lite::Context *ctx, - const KernelKey &desc) { + const KernelKey &desc, const lite::Primitive *primitive) { if (parameter == nullptr) { MS_LOG(ERROR) << "parameter is nullptr"; return nullptr; @@ -42,10 +43,16 @@ kernel::LiteKernel *CpuActivationInt8KernelCreator(const std::vector(type)) { case schema::ActivationType_RELU: - kernel = new (std::nothrow) ReluInt8CPUKernel(parameter, inputs, outputs, ctx); + kernel = new (std::nothrow) ReluInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); + break; + case schema::ActivationType_RELU6: + kernel = new (std::nothrow) Relu6Int8CPUKernel(parameter, inputs, outputs, ctx, primitive); break; case schema::ActivationType_HSWISH: - kernel = new (std::nothrow) HswishInt8CPUKernel(parameter, inputs, outputs, ctx); + kernel = new (std::nothrow) HswishInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); + break; + case schema::ActivationType_SIGMOID: + kernel = new (std::nothrow) SigmoidInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); break; default: break; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc index 18bb5e80c6..121e16279c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc @@ -18,6 +18,7 @@ #include #include #include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" +#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" #include "src/runtime/runtime_api.h" #include "src/kernel_registry.h" #include "include/errorcode.h" @@ -75,6 +76,11 @@ int QuantizedAddCPUKernel::Init() { int QuantizedAddCPUKernel::ReSize() { return 0; } int QuantizedAddCPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } input0_data_ = static_cast(inputs_.at(0)->Data()); input1_data_ = static_cast(inputs_.at(1)->Data()); output_data_ = static_cast(outputs_.at(0)->Data()); @@ -96,13 +102,13 @@ int QuantizedAddCPUKernel::Run() { TileDimensionsUint8(static_cast(inputs_.at(0)->Data()), static_cast(inputs_.at(1)->Data()), reinterpret_cast(input0_data_), reinterpret_cast(input1_data_), &tile_para); - auto ret = LiteBackendParallelLaunch(AddInt8Run, this, thread_count_); + ret = LiteBackendParallelLaunch(AddInt8Run, this, thread_count_); ctx_->allocator->Free(input0_data_); ctx_->allocator->Free(input1_data_); return ret; } - auto ret = LiteBackendParallelLaunch(AddInt8Run, this, thread_count_); + ret = LiteBackendParallelLaunch(AddInt8Run, this, thread_count_); return ret; } @@ -124,13 +130,14 @@ int QuantizedAddCPUKernel::DoExecute(int tId) { kernel::LiteKernel *CpuAddInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, - const lite::Context *ctx, const KernelKey &desc) { + const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { if (parameter == nullptr || ctx == nullptr) { MS_LOG(ERROR) << "parameter or ctx is nullptr"; return nullptr; } MS_ASSERT(desc.type == PrimitiveType_Add); - auto *kernel = new (std::nothrow) QuantizedAddCPUKernel(parameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) QuantizedAddCPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h index b57aab2279..5a1da51340 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class QuantizedAddCPUKernel : public LiteKernel { public: explicit QuantizedAddCPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx_->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx_->thread_num_) {} ~QuantizedAddCPUKernel() override {} int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc index 03cae3aa86..a35d1575f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.cc @@ -20,8 +20,8 @@ #include "src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.h" #include "include/errorcode.h" -using mindspore::lite::RET_OK; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; namespace mindspore::kernel { int ArgMinMaxInt8CPUKernel::Init() { @@ -40,10 +40,22 @@ int ArgMinMaxInt8CPUKernel::Init() { auto out_quant_args = out_tensor->GetQuantParams(); out_quant_arg_.scale_ = out_quant_args.front().scale; out_quant_arg_.zp_ = out_quant_args.front().zeroPoint; - return RET_OK; + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int ArgMinMaxInt8CPUKernel::ReSize() { + return ArgMinMaxBaseCPUKernel::ReSize(); } int ArgMinMaxInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare fail!ret: " << ret; + return ret; + } auto input = inputs_.at(0); const int8_t *input_data = reinterpret_cast(inputs_.at(0)->Data()); @@ -70,6 +82,7 @@ int ArgMinMaxInt8CPUKernel::Run() { ArgMinMaxDim3(input_data, output_data, in_shape, param, &in_quant_arg_, &out_quant_arg_); break; } + FreeTmpMemory(); return RET_OK; } } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.h index 919acd2037..b8a8762637 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/argminmax_int8.h @@ -24,13 +24,14 @@ namespace mindspore::kernel { class ArgMinMaxInt8CPUKernel : public ArgMinMaxBaseCPUKernel { public: ArgMinMaxInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : ArgMinMaxBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ArgMinMaxBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ArgMinMaxInt8CPUKernel() = default; int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override; private: QuantArg in_quant_arg_; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc index 3c01ca389b..db2d911e84 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.cc @@ -126,6 +126,9 @@ int ArithmeticInt8CPUKernel::DoArithmetic(int thread_id) { MS_ASSERT(thread_count_ != 0); int stride = UP_DIV(element_num, thread_count_); int count = MSMIN(stride, element_num - stride * thread_id); + if (count <= 0) { + return RET_OK; + } int error_code = arithmetic_run_(tile_data0_ + stride * thread_id, tile_data1_ + stride * thread_id, output_data + stride * thread_id, count); @@ -164,12 +167,12 @@ int ArithmeticInt8CPUKernel::Run() { kernel::LiteKernel *CpuArithmeticInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { if (parameter == nullptr) { MS_LOG(ERROR) << "Input parameter is null!"; return nullptr; } - auto kernel = new (std::nothrow) ArithmeticInt8CPUKernel(parameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) ArithmeticInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create ArithmeticInt8CPUKernel failed, name: " << parameter->name_; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.h index 56ebcd7e0b..dfc5a030a7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_int8.h @@ -27,8 +27,9 @@ class ArithmeticInt8CPUKernel : public LiteKernel { public: ArithmeticInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_count_(ctx->thread_num_), context_(ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_), context_(ctx) {} ~ArithmeticInt8CPUKernel(); int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc index 1688f27bb4..c94689722c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.cc @@ -28,6 +28,10 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int ArithmeticSelfInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } int ret = ReSize(); auto *input_tensor = inputs_.at(kInputIndex); auto in_quant_args = input_tensor->GetQuantParams(); @@ -93,11 +97,16 @@ int ArithmeticSelfInt8CPUKernel::DoArithmeticSelf(int task_id) { } int ArithmeticSelfInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_tensor = inputs_.at(0); auto out_tensor = outputs_.at(0); in_ptr_ = reinterpret_cast(input_tensor->Data()); out_ptr_ = reinterpret_cast(out_tensor->Data()); - int ret = LiteBackendParallelLaunch(ArithmeticSelfInt8Runs, this, thread_sz_count_); + ret = LiteBackendParallelLaunch(ArithmeticSelfInt8Runs, this, thread_sz_count_); if (ret != RET_OK) { MS_LOG(ERROR) << "ArithmeticSelfRun error error_code[" << ret << "]"; return ret; @@ -108,13 +117,14 @@ int ArithmeticSelfInt8CPUKernel::Run() { kernel::LiteKernel *CpuArithmeticSelfInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); if (opParameter == nullptr) { MS_LOG(ERROR) << "Creator failed, opParameter is nullptr!"; return nullptr; } - auto *kernel = new (std::nothrow) ArithmeticSelfInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) ArithmeticSelfInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); MS_ASSERT(kernel != nullptr); auto ret = kernel->Init(); if (ret != RET_OK) { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.h index 7dfe7d14ad..a507313a40 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/arithmetic_self_int8.h @@ -24,10 +24,7 @@ #include "schema/model_generated.h" #include "include/context.h" - using mindspore::lite::Context; -using mindspore::schema::PrimitiveType_Round; -using mindspore::schema::PrimitiveType_Floor; using mindspore::schema::PrimitiveType_Ceil; using mindspore::schema::PrimitiveType_Abs; using mindspore::schema::PrimitiveType_Sin; @@ -37,6 +34,8 @@ using mindspore::schema::PrimitiveType_Sqrt; using mindspore::schema::PrimitiveType_Rsqrt; using mindspore::schema::PrimitiveType_Square; using mindspore::schema::PrimitiveType_LogicalNot; +using mindspore::schema::PrimitiveType_Floor; +using mindspore::schema::PrimitiveType_Round; namespace mindspore::kernel { class ArithmeticSelfInt8CPUKernel : public LiteKernel { @@ -44,8 +43,9 @@ class ArithmeticSelfInt8CPUKernel : public LiteKernel { public: explicit ArithmeticSelfInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx->thread_num_) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { switch (parameter->type_) { case PrimitiveType_Round: arithmeticSelf_run_ = ElementRound; @@ -106,4 +106,3 @@ class ArithmeticSelfInt8CPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_ARITHMETIC_SELF_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc index bdf49bf14e..ac3a015bf1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.cc @@ -38,10 +38,22 @@ int BatchToSpaceInt8CPUKernel::Init() { auto out_quant_args = out_tensor->GetQuantParams(); out_quant_arg_.scale_ = out_quant_args.front().scale; out_quant_arg_.zp_ = out_quant_args.front().zeroPoint; - return RET_OK; + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int BatchToSpaceInt8CPUKernel::ReSize() { + return BatchToSpaceBaseCPUKernel::ReSize(); } int BatchToSpaceInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input = inputs_[0]; auto output = outputs_[0]; const int8_t *input_data = reinterpret_cast(input->Data()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h index 17f30f004f..94bb228084 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/batch_to_space_int8.h @@ -23,13 +23,14 @@ namespace mindspore::kernel { class BatchToSpaceInt8CPUKernel : public BatchToSpaceBaseCPUKernel { public: BatchToSpaceInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : BatchToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : BatchToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~BatchToSpaceInt8CPUKernel() = default; int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override; private: QuantArg in_quant_arg_; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc index f80daade18..1c6afa9d4b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc @@ -26,6 +26,10 @@ using mindspore::schema::PrimitiveType_BiasAdd; namespace mindspore::kernel { int BiasAddInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto bias_param = reinterpret_cast(opParameter); auto dims = inputs_[0]->shape(); bias_param->ndim_ = dims.size(); @@ -41,6 +45,11 @@ int BiasAddInt8CPUKernel::Init() { int BiasAddInt8CPUKernel::ReSize() { return NNACL_OK; } int BiasAddInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto in = reinterpret_cast(inputs_.at(0)->Data()); auto bias = reinterpret_cast(inputs_.at(1)->Data()); auto out = reinterpret_cast(outputs_.at(0)->Data()); @@ -59,14 +68,14 @@ int BiasAddInt8CPUKernel::Run() { kernel::LiteKernel *CpuBiasAddInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, - OpParameter *parameter, const lite::Context *ctx, - const KernelKey &desc) { + OpParameter *parameter, const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { if (parameter == nullptr || ctx == nullptr) { MS_LOG(ERROR) << "parameter or context is nullptr"; return nullptr; } MS_ASSERT(desc.type == PrimitiveType_BiasAdd); - auto *kernel = new (std::nothrow) BiasAddInt8CPUKernel(parameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) BiasAddInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "Create kernel failed, name: " << parameter->name_; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h index 3ced965318..c8c7717be4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.h @@ -25,8 +25,9 @@ namespace mindspore::kernel { class BiasAddInt8CPUKernel : public LiteKernel { public: BiasAddInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx) {} ~BiasAddInt8CPUKernel() = default; int Init() override; @@ -39,4 +40,3 @@ class BiasAddInt8CPUKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_BAIS_ADD_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc index ea88847f16..5ccf9907d4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.cc @@ -15,6 +15,7 @@ */ #include "src/runtime/kernel/arm/int8/concat_int8.h" +#include #include "src/runtime/kernel/arm/nnacl/int8/concat_int8.h" #include "schema/model_generated.h" #include "include/errorcode.h" @@ -26,79 +27,51 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int ConcatInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } ConcatBaseCPUKernel::Init(); - quant_concat_parm_ = concat_param_->concat_quant_arg_; - quant_concat_parm_ = new (std::nothrow) ConcatQuantArg; auto input_num = inputs_.size(); - quant_concat_parm_->input_num_ = input_num; - quant_concat_parm_->input_sizes_ = reinterpret_cast(malloc(sizeof(int) * input_num)); - if (quant_concat_parm_->input_sizes_ == nullptr) { - MS_LOG(ERROR) << "Null pointer reference: quant_concat_parm_->input_sizes_."; - return RET_ERROR; - } - + concat_param_->input_num_ = input_num; + concat_param_->input_shapes_ = reinterpret_cast(ctx_->allocator->Malloc(sizeof(int *) * input_num)); for (size_t i = 0; i < input_num; i++) { - quant_concat_parm_->input_sizes_[i] = 1; - } - quant_concat_parm_->input_shapes_ = reinterpret_cast(malloc(sizeof(int *) * input_num)); - if (quant_concat_parm_->input_shapes_ == nullptr) { - MS_LOG(ERROR) << "Null pointer reference: quant_concat_parm_->input_shapes_."; - return RET_ERROR; + concat_param_->input_shapes_[i] = reinterpret_cast(inputs_.at(i)->shape().data()); } - for (size_t i = 0; i < input_num; i++) { - auto *input_tensor = inputs_.at(i); - MS_ASSERT(input_tensor != nullptr); - auto input_size = input_tensor->shape().size(); - MS_ASSERT(input_size != NULL); - quant_concat_parm_->input_shapes_[i] = reinterpret_cast(malloc(sizeof(int) * input_size)); - if (quant_concat_parm_->input_shapes_[i] == nullptr) { - MS_LOG(ERROR) << "Null pointer reference: quant_concat_parm_->input_shapes_[" << i << "]."; - return RET_ERROR; - } - - ::memcpy(quant_concat_parm_->input_shapes_[i], input_tensor->shape().data(), sizeof(int) * input_size); - for (size_t j = 0; j < input_size; j++) { - auto *input_tensor_tmp = inputs_.at(i); - auto input_shape = input_tensor_tmp->shape()[j]; - quant_concat_parm_->input_sizes_[i] *= input_shape; - } + before_axis_size = 1; + for (int i = 0; i < axis_; i++) { + before_axis_size *= outputs_.at(kOutputIndex)->DimensionSize(i); } - quant_concat_parm_->in_quant_args_ = reinterpret_cast(malloc(sizeof(QuantArg) * input_num)); - if (quant_concat_parm_->in_quant_args_ == nullptr) { + int64_t after_axis_size = 1; + auto output_tensor = outputs_.at(kOutputIndex); + int output_dim = output_tensor->shape().size(); + concat_param_->output_shapes_ = output_tensor->shape().data(); + for (size_t i = axis_ + 1; i < output_dim; i++) { + after_axis_size *= concat_param_->output_shapes_[i]; + } + concat_param_->after_axis_size = after_axis_size; + + concat_param_->quant_arg_.in_args_ = + reinterpret_cast(ctx_->allocator->Malloc(sizeof(QuantArg) * input_num)); + if (concat_param_->quant_arg_.in_args_ == nullptr) { MS_LOG(ERROR) << "Null pointer reference: quant_concat_parm_->in_quant_args_."; return RET_ERROR; } - for (size_t i = 0; i < input_num; i++) { auto *input_tensor = inputs_.at(i); auto quant_args = input_tensor->GetQuantParams(); - MS_ASSERT(quant_args.size() == 1); - quant_concat_parm_->in_quant_args_[i].scale_ = quant_args.front().scale; - quant_concat_parm_->in_quant_args_[i].zp_ = quant_args.front().zeroPoint; + concat_param_->quant_arg_.in_args_[i].scale_ = quant_args.front().scale; + concat_param_->quant_arg_.in_args_[i].zp_ = quant_args.front().zeroPoint; } - MS_ASSERT(outputs_.size() == 1); - auto output_tensor = outputs_.at(0); - MS_ASSERT(output_tensor != nullptr); - auto output_shape = output_tensor->shape(); - MS_ASSERT(output_shape != NULL); - auto output_dim = output_shape.size(); - quant_concat_parm_->output_dim_ = output_dim; - int output_size = 1; - for (size_t i = 0; i < output_dim; i++) { - output_size *= output_shape[i]; - } - quant_concat_parm_->output_size_ = output_size; - - quant_concat_parm_->output_shape_ = new int[output_size]; - ::memcpy(quant_concat_parm_->output_shape_, output_shape.data(), sizeof(int) * output_size); - auto quant_args = output_tensor->GetQuantParams(); - MS_ASSERT(quant_args.size() == 1); - quant_concat_parm_->out_quant_args_.scale_ = quant_args.front().scale; - quant_concat_parm_->out_quant_args_.zp_ = quant_args.front().zeroPoint; + concat_param_->quant_arg_.out_args_.scale_ = quant_args.front().scale; + concat_param_->quant_arg_.out_args_.zp_ = quant_args.front().zeroPoint; + + concat_param_->quant_arg_.output_activation_min_ = std::numeric_limits::min(); + concat_param_->quant_arg_.output_activation_max_ = std::numeric_limits::max(); return RET_OK; } @@ -106,39 +79,46 @@ int ConcatInt8CPUKernel::Init() { int ConcatInt8CPUKernel::ReSize() { return 0; } int ConcatInt8CPUKernel::Run() { - auto input_dim = quant_concat_parm_->input_num_; - int8_t **inputs_array = reinterpret_cast(malloc(sizeof(int8_t *) * input_dim)); - for (size_t i = 0; i < input_dim; i++) { - auto input_size = quant_concat_parm_->input_sizes_[i]; - inputs_array[i] = reinterpret_cast(malloc(sizeof(int8_t) * input_size)); - auto input_type = inputs_[i]->data_type(); - if (input_type == kNumberTypeUInt8) { - uint8_t *input_tmp = reinterpret_cast(inputs_[i]->Data()); - for (size_t j = 0; j < input_size; j++) { - inputs_array[i][j] = (int8_t)(input_tmp[j] - 128); - } - for (size_t j = 0; j < input_dim; j++) { - quant_concat_parm_->in_quant_args_[j].zp_ -= 128; - } - quant_concat_parm_->out_quant_args_.zp_ -= 128; - } else { - ::memcpy(inputs_array[i], inputs_.at(i)->Data(), sizeof(int8_t) * input_size); - } - } - int8_t *output_addr = reinterpret_cast(outputs_.at(0)->Data()); - Concat(inputs_array, output_addr, quant_concat_parm_, axis_); - auto output_type = outputs_[0]->data_type(); - if (output_type == kNumberTypeUInt8) { - auto output_size = quant_concat_parm_->output_size_; - for (size_t i = 0; i < output_size; i++) { - output_addr[i] = (uint8_t)(output_addr[i] + 128); - } + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; } - for (int i = 0; i < input_dim; i++) { - free(*(inputs_array + i)); + auto input_num = concat_param_->input_num_; + count_unit_ = thread_count_ > 1 ? UP_DIV(before_axis_size, thread_count_) : before_axis_size; + concat_param_->count_unit_ = count_unit_; + input_data_ = reinterpret_cast(ctx_->allocator->Malloc(sizeof(int8_t *) * input_num)); + if (input_data_ == nullptr) { + MS_LOG(ERROR) << "Null pointer reference: inputs_array."; + return RET_ERROR; } - return RET_OK; + for (size_t i = 0; i < input_num; i++) { + input_data_[i] = static_cast(inputs_.at(i)->Data()); + } + output_data_ = reinterpret_cast(outputs_.at(0)->Data()); + + ret = LiteBackendParallelLaunch(ConcatInt8Run, this, thread_count_); + + ctx_->allocator->Free(input_data_); + ctx_->allocator->Free(concat_param_->input_shapes_); + ctx_->allocator->Free(concat_param_->quant_arg_.in_args_); + + return ret; +} + +int ConcatInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto concat = reinterpret_cast(cdata); + concat->DoExecute(task_id); + return lite::RET_OK; +} + +int ConcatInt8CPUKernel::DoExecute(int task_id) { + int64_t real_dst_count = MSMIN(before_axis_size - task_id * count_unit_, count_unit_); + if (real_dst_count <= 0) { + return lite::RET_OK; + } + Concat(input_data_, output_data_, concat_param_, axis_, real_dst_count, task_id); + return lite::RET_OK; } } // namespace mindspore::kernel - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h index 192f50b46c..1d09049ffe 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/concat_int8.h @@ -21,6 +21,7 @@ #include "src/lite_kernel.h" #include "include/context.h" #include "src/runtime/kernel/arm/base/concat_base.h" +#include "src/runtime/runtime_api.h" using mindspore::lite::Context; @@ -28,18 +29,24 @@ namespace mindspore::kernel { class ConcatInt8CPUKernel : public ConcatBaseCPUKernel { public: ConcatInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConcatBaseCPUKernel(parameter, inputs, outputs, ctx) {} - ~ConcatInt8CPUKernel() override { delete quant_concat_parm_; } + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConcatBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + ~ConcatInt8CPUKernel() override {} int Init() override; int ReSize() override; int Run() override; + int DoExecute(int task_id); private: - ConcatQuantArg *quant_concat_parm_; + int64_t before_axis_size; + int64_t count_unit_; + int8_t **input_data_ = nullptr; + int8_t *output_data_ = nullptr; }; + +int ConcatInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata); } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_CONCAT_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc index e3c9471514..530e1275c3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.cc @@ -161,6 +161,10 @@ void Convolution3x3Int8CPUKernel::ConfigInputOutput() { } int Convolution3x3Int8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; @@ -232,6 +236,11 @@ int Convolution3x3Int8Impl(int task_id, LiteParallelGroupEnv *penv, void *cdata) } int Convolution3x3Int8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_addr = reinterpret_cast(inputs_.at(kInputIndex)->Data()); PackInputToC8Int8(input_addr, input_data_, conv_param_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.h index ef0a8a5560..b5dbc12449 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_3x3_int8.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class Convolution3x3Int8CPUKernel : public ConvolutionBaseCPUKernel { public: Convolution3x3Int8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~Convolution3x3Int8CPUKernel() override; int Init() override; @@ -51,4 +52,3 @@ void ProcessFilterUint8(int8_t *origin_weight, int16_t *dst_weight, ConvParamete } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_CONVOLUTION_3X3_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc index 87fa4e1690..bf107f65c3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.cc @@ -81,12 +81,16 @@ int ConvolutionDepthwiseInt8CPUKernel::InitBuffer() { } int ConvolutionDepthwiseInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } // conv base init ConvolutionBaseCPUKernel::Init(); // init sliding window param sliding = new SlidingWindowParam; - InitSlidingParam(sliding, conv_param_, C4NUM); + InitSlidingParamConvDw(sliding, conv_param_, C4NUM); // init quant param ConvolutionBaseCPUKernel::SetQuantParam(); @@ -115,7 +119,7 @@ int ConvolutionDepthwiseInt8CPUKernel::ReSize() { ConvolutionBaseCPUKernel::Init(); // init sliding window param - InitSlidingParam(sliding, conv_param_, C4NUM); + InitSlidingParamConvDw(sliding, conv_param_, C4NUM); // init quant param ConvolutionBaseCPUKernel::SetQuantParam(); @@ -145,6 +149,11 @@ int ConvDwInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ConvolutionDepthwiseInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -160,7 +169,7 @@ int ConvolutionDepthwiseInt8CPUKernel::Run() { packed_output_ = output_addr; } - auto ret = LiteBackendParallelLaunch(ConvDwInt8Run, this, conv_param_->thread_num_); + ret = LiteBackendParallelLaunch(ConvDwInt8Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvDwInt8Run error: error_code[" << ret << "]"; return RET_ERROR; @@ -176,10 +185,11 @@ int ConvolutionDepthwiseInt8CPUKernel::Run() { kernel::LiteKernel *CpuConvDwInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DepthwiseConv2D); - auto kernel = new (std::nothrow) kernel::ConvolutionDepthwiseInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = + new (std::nothrow) kernel::ConvolutionDepthwiseInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.h index e0ce121dad..a6e068d90d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_depthwise_int8.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class ConvolutionDepthwiseInt8CPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionDepthwiseInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionDepthwiseInt8CPUKernel() override { delete sliding; free(packed_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc index 00415cc542..8aac86c288 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.cc @@ -269,6 +269,10 @@ void ConvolutionInt8CPUKernel::ConfigInputOutput() { } int ConvolutionInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = ConvolutionBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "ConvolutionBase init failed."; @@ -379,6 +383,11 @@ int ConvolutionInt8Impl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int ConvolutionInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_tensor = inputs_.at(kInputIndex); auto ori_input_data = input_tensor->Data(); int in_batch = conv_param_->input_batch_; @@ -398,7 +407,7 @@ int ConvolutionInt8CPUKernel::Run() { kernel::LiteKernel *CpuConvInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Conv2D); auto conv_param = reinterpret_cast(opParameter); @@ -410,9 +419,9 @@ kernel::LiteKernel *CpuConvInt8KernelCreator(const std::vectordilation_w_; kernel::LiteKernel *kernel; if (kernel_h == 3 && kernel_w == 3 && stride_h == 1 && stride_w == 1 && dilation_h == 1 && dilation_w == 1) { - kernel = new (std::nothrow) kernel::Convolution3x3Int8CPUKernel(opParameter, inputs, outputs, ctx); + kernel = new (std::nothrow) kernel::Convolution3x3Int8CPUKernel(opParameter, inputs, outputs, ctx, primitive); } else { - kernel = new (std::nothrow) kernel::ConvolutionInt8CPUKernel(opParameter, inputs, outputs, ctx); + kernel = new (std::nothrow) kernel::ConvolutionInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); } if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.h index 3250cfa112..bc3da9ab01 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/convolution_int8.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class ConvolutionInt8CPUKernel : public ConvolutionBaseCPUKernel { public: ConvolutionInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ConvolutionInt8CPUKernel() override { if (packed_weight_ != nullptr) { free(packed_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc index 4e73001954..4023309b8d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.cc @@ -54,7 +54,12 @@ int CropInt8CPUKernel::Init() { int CropInt8CPUKernel::ReSize() { return 0; } int CropInt8CPUKernel::Run() { - auto ret = LiteBackendParallelLaunch(CropInt8Run, this, thread_count_); + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } + ret = LiteBackendParallelLaunch(CropInt8Run, this, thread_count_); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h index ebcfd22a65..598dde3490 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/crop_int8.h @@ -29,8 +29,9 @@ namespace mindspore::kernel { class CropInt8CPUKernel : public CropBaseCPUKernel { public: CropInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : CropBaseCPUKernel(parameter, inputs, outputs, ctx) { + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : CropBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) { crop_para_ = reinterpret_cast(opParameter); crop_para_->thread_count_ = opParameter->thread_num_; } @@ -39,7 +40,7 @@ class CropInt8CPUKernel : public CropBaseCPUKernel { int Init() override; int ReSize() override; int Run() override; - int DoExecute(int tId); + int DoExecute(int task_id); private: CropParameter *crop_para_; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc index 6de3c47211..542898a089 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.cc @@ -67,7 +67,7 @@ int DeconvolutionDepthwiseInt8CPUKernel::InitSlideParam() { conv_param_->output_channel_ = inputs_.front()->shape().at(kNHWC_C); // init sliding window param - InitSlidingParam(sliding, conv_param_, C4NUM); + InitSlidingParamConvDw(sliding, conv_param_, C4NUM); sliding->in_h_step_ = conv_param_->input_w_ * C4NUM; sliding->in_sh_step_ = conv_param_->input_w_ * C4NUM * conv_param_->stride_h_; // stride H @@ -115,6 +115,10 @@ int DeconvolutionDepthwiseInt8CPUKernel::InitBuffer() { } int DeconvolutionDepthwiseInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } sliding = new SlidingWindowParam; InitSlideParam(); @@ -174,6 +178,11 @@ int DeconvDwInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int DeconvolutionDepthwiseInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } if (conv_param_->input_channel_ != conv_param_->output_channel_) { MS_LOG(ERROR) << "Only support input channel equals output channel."; return RET_ERROR; @@ -190,7 +199,7 @@ int DeconvolutionDepthwiseInt8CPUKernel::Run() { packed_output_ = output_addr; } - auto ret = LiteBackendParallelLaunch(DeconvDwInt8Run, this, conv_param_->thread_num_); + ret = LiteBackendParallelLaunch(DeconvDwInt8Run, this, conv_param_->thread_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "DeconvDwInt8Run error: error_code[" << ret << "]"; return RET_ERROR; @@ -206,10 +215,11 @@ int DeconvolutionDepthwiseInt8CPUKernel::Run() { kernel::LiteKernel *CpuDeconvDwInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DeDepthwiseConv2D); - auto kernel = new (std::nothrow) kernel::DeconvolutionDepthwiseInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = + new (std::nothrow) kernel::DeconvolutionDepthwiseInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.h index 3e56264aae..d7b76438f3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_depthwise_int8.h @@ -26,8 +26,9 @@ namespace mindspore::kernel { class DeconvolutionDepthwiseInt8CPUKernel : public ConvolutionBaseCPUKernel { public: DeconvolutionDepthwiseInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~DeconvolutionDepthwiseInt8CPUKernel() override { delete sliding; free(packed_weight_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc index f21c5bc1c4..13d078d5e0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.cc @@ -115,6 +115,10 @@ int DeConvInt8CPUKernel::InitData() { } int DeConvInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } ConvolutionBaseCPUKernel::Init(); int error_code = ConvolutionBaseCPUKernel::SetQuantParam(); if (error_code != RET_OK) { @@ -196,6 +200,11 @@ int DeConvInt8CPUKernel::DoPostFunc(int task_id) { } int DeConvInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } int8_t *src_in = reinterpret_cast(inputs_[0]->Data()); int8_t *src_out = reinterpret_cast(outputs_[0]->Data()); @@ -222,10 +231,10 @@ int DeConvInt8CPUKernel::Run() { kernel::LiteKernel *CpuDeConvInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_DeConv2D); - auto kernel = new (std::nothrow) kernel::DeConvInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto kernel = new (std::nothrow) kernel::DeConvInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.h index b63633f9a5..df42f2d158 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/deconvolution_int8.h @@ -21,8 +21,9 @@ #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "include/errorcode.h" +#include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" #include "src/runtime/kernel/arm/nnacl/int8/deconv.h" -#include "src/runtime/kernel/arm/nnacl/int8/matmul.h" +#include "src/runtime/kernel/arm/nnacl/int8/matmul_int8.h" #include "src/runtime/kernel/arm/base/layout_transform.h" #include "src/runtime/kernel/arm/base/convolution_base.h" #include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" @@ -31,8 +32,9 @@ namespace mindspore::kernel { class DeConvInt8CPUKernel : public ConvolutionBaseCPUKernel { public: DeConvInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ConvolutionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~DeConvInt8CPUKernel() override; int ReSize() override; @@ -60,4 +62,3 @@ class DeConvInt8CPUKernel : public ConvolutionBaseCPUKernel { }; } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_DECONVOLUTION_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc index b70624aa18..4d535ad562 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.cc @@ -21,8 +21,8 @@ #include "src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.h" #include "include/errorcode.h" -using mindspore::lite::RET_OK; using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; namespace mindspore::kernel { int DepthToSpaceInt8CPUKernel::Init() { @@ -42,10 +42,22 @@ int DepthToSpaceInt8CPUKernel::Init() { auto out_quant_args = out_tensor->GetQuantParams(); out_quant_arg_.scale_ = out_quant_args.front().scale; out_quant_arg_.zp_ = out_quant_args.front().zeroPoint; - return RET_OK; + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int DepthToSpaceInt8CPUKernel::ReSize() { + return DepthToSpaceBaseCPUKernel::ReSize(); } int DepthToSpaceInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input = inputs_[0]; auto output = outputs_[0]; const int8_t *input_data = reinterpret_cast(input->Data()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h index 427b6d5eb0..728e31fadb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/depth_to_space_int8.h @@ -18,18 +18,20 @@ #include #include "src/runtime/kernel/arm/base/depth_to_space_base.h" +#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" namespace mindspore::kernel { class DepthToSpaceInt8CPUKernel : public DepthToSpaceBaseCPUKernel { public: DepthToSpaceInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : DepthToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : DepthToSpaceBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~DepthToSpaceInt8CPUKernel() = default; int Init() override; - int ReSize() override { return 0; } + int ReSize() override; int Run() override; private: QuantArg in_quant_arg_; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc index a14438c815..2975aa8253 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.cc @@ -15,7 +15,7 @@ */ #include "src/runtime/kernel/arm/int8/fullconnection_int8.h" -#include "src/runtime/kernel/arm/nnacl/int8/matmul.h" +#include "src/runtime/kernel/arm/nnacl/int8/matmul_int8.h" #include "src/runtime/kernel/arm/nnacl/common_func.h" #include "src/runtime/runtime_api.h" #include "include/errorcode.h" @@ -25,6 +25,10 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int FullconnectionInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } fc_param_->row_ = (inputs_[0]->shape())[0]; fc_param_->col_ = (inputs_[1]->shape())[0]; fc_param_->deep_ = (inputs_[1]->shape())[1]; @@ -113,6 +117,11 @@ int FcInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int FullconnectionInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto a_ptr = reinterpret_cast(inputs_[0]->Data()); auto output_ptr = reinterpret_cast(outputs_[0]->Data()); auto &p = quant_params_; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.h index 30aef2d45f..66010c584d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/fullconnection_int8.h @@ -28,8 +28,9 @@ namespace mindspore::kernel { class FullconnectionInt8CPUKernel : public FullconnectionBaseCPUKernel { public: FullconnectionInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : FullconnectionBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : FullconnectionBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~FullconnectionInt8CPUKernel() override { ctx_->allocator->Free(a_c8_ptr_); ctx_->allocator->Free(b_r8_ptr_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc index 7b5f9795eb..3c2b688238 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.cc @@ -89,6 +89,11 @@ int HswishInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int HswishInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } int error_code = LiteBackendParallelLaunch(HswishInt8Run, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "HswishInt8Run function error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.h index b907f2c338..9fb8eb83d7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/hswish_int8.h @@ -20,13 +20,15 @@ #include #include "src/lite_kernel.h" #include "src/runtime/kernel/arm/nnacl/int8/hswish_int8.h" +#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" namespace mindspore::kernel { class HswishInt8CPUKernel : public LiteKernel { public: HswishInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_count_(ctx->thread_num_) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) {} ~HswishInt8CPUKernel() override = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc index 5015fa0cea..c9597214c1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.cc @@ -15,7 +15,7 @@ */ #include "src/runtime/kernel/arm/int8/matmul_int8.h" -#include "src/runtime/kernel/arm/nnacl/int8/matmul.h" +#include "src/runtime/kernel/arm/nnacl/int8/matmul_int8.h" #include "src/runtime/kernel/arm/nnacl/common_func.h" #include "src/runtime/runtime_api.h" #include "include/errorcode.h" @@ -31,6 +31,10 @@ MatmulInt8CPUKernel::~MatmulInt8CPUKernel() { } int MatmulInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } int batch = 1; auto x_shape = inputs_[0]->shape(); auto o_shape = outputs_[0]->shape(); @@ -109,6 +113,11 @@ int MatmulInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int MatmulInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto a_ptr = reinterpret_cast(inputs_[0]->Data()); auto b_ptr = reinterpret_cast(inputs_[1]->Data()); auto c_ptr = reinterpret_cast(outputs_[0]->Data()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h index dc8f5ec0b6..d05aeb7c84 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/matmul_int8.h @@ -28,8 +28,9 @@ namespace mindspore::kernel { class MatmulInt8CPUKernel : public MatmulBaseCPUKernel { public: MatmulInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : MatmulBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : MatmulBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~MatmulInt8CPUKernel() override; int Init() override; int ReSize() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc index a9fd7c1378..eab7550f60 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.cc @@ -62,13 +62,17 @@ int MulInt8CPUKernel::Init() { int MulInt8CPUKernel::ReSize() { return RET_OK; } int MulInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } input0_data_ = static_cast(inputs_.at(0)->Data()); input1_data_ = static_cast(inputs_.at(1)->Data()); output_data_ = static_cast(outputs_.at(0)->Data()); elements_num_ = inputs_.at(0)->ElementsNum(); count_unit_ = thread_count_ > 1 ? UP_DIV(elements_num_, thread_count_) : elements_num_; - if (inputs_.at(0)->ElementsNum() != inputs_.at(1)->ElementsNum()) { input0_data_ = static_cast(ctx_->allocator->Malloc(outputs_.at(0)->Size())); input1_data_ = static_cast(ctx_->allocator->Malloc(outputs_.at(0)->Size())); @@ -82,13 +86,13 @@ int MulInt8CPUKernel::Run() { } TileDimensionsInt8(static_cast(inputs_.at(0)->Data()), static_cast(inputs_.at(1)->Data()), input0_data_, input1_data_, &tile_para); - auto ret = LiteBackendParallelLaunch(MulInt8Run, this, thread_count_); + ret = LiteBackendParallelLaunch(MulInt8Run, this, thread_count_); ctx_->allocator->Free(input0_data_); ctx_->allocator->Free(input1_data_); return ret; } - auto ret = LiteBackendParallelLaunch(MulInt8Run, this, thread_count_); + ret = LiteBackendParallelLaunch(MulInt8Run, this, thread_count_); return ret; } @@ -98,11 +102,14 @@ int MulInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { return lite::RET_OK; } -int MulInt8CPUKernel::DoExecute(int tId) { - int64_t real_dst_count = MSMIN(elements_num_ - tId * count_unit_, count_unit_); - int8_t *cur_input0_data = input0_data_ + tId * count_unit_; - int8_t *cur_input1_data = input1_data_ + tId * count_unit_; - int8_t *cur_output_data = output_data_ + tId * count_unit_; +int MulInt8CPUKernel::DoExecute(int task_id) { + int64_t real_dst_count = MSMIN(elements_num_ - task_id * count_unit_, count_unit_); + if (real_dst_count <= 0) { + return lite::RET_OK; + } + int8_t *cur_input0_data = input0_data_ + task_id * count_unit_; + int8_t *cur_input1_data = input1_data_ + task_id * count_unit_; + int8_t *cur_output_data = output_data_ + task_id * count_unit_; Mul(cur_input0_data, cur_input1_data, cur_output_data, real_dst_count, para_.mul_quant_arg_); return lite::RET_OK; @@ -110,10 +117,11 @@ int MulInt8CPUKernel::DoExecute(int tId) { kernel::LiteKernel *CpuMulInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, - OpParameter *opParameter, const lite::Context *ctx, const KernelKey &desc) { + OpParameter *opParameter, const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(opParameter != nullptr); MS_ASSERT(desc.type == schema::PrimitiveType_Mul); - auto *kernel = new (std::nothrow) MulInt8CPUKernel(opParameter, inputs, outputs, ctx); + auto *kernel = new (std::nothrow) MulInt8CPUKernel(opParameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "kernel is nullptr."; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.h index 7725591a06..79f84c4987 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/mul_int8.h @@ -25,14 +25,15 @@ namespace mindspore::kernel { class MulInt8CPUKernel : public LiteKernel { public: explicit MulInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), ctx_(ctx), thread_count_(ctx_->thread_num_) {} - ~MulInt8CPUKernel() override {}; + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx_->thread_num_) {} + ~MulInt8CPUKernel() override{}; int Init() override; int ReSize() override; int Run() override; - int DoExecute(int tId); + int DoExecute(int task_id); private: const lite::Context *ctx_; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc index 42b3f7c16a..a5307f71bf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.cc @@ -93,6 +93,10 @@ int PadInt8CPUKernel::ReSize() { } int PadInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } int error_code = InitPadParam(); if (error_code != RET_OK) { MS_LOG(ERROR) << "InitPadParam failed. errorcode: " << error_code; @@ -108,6 +112,11 @@ int PadInt8CPUKernel::Init() { } int PadInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } int8_t *in_data = reinterpret_cast(inputs_[0]->Data()); int8_t *out_data = reinterpret_cast(outputs_[0]->Data()); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h index 3d9dda740b..4bc7b5f302 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pad_int8.h @@ -27,8 +27,9 @@ namespace mindspore::kernel { class PadInt8CPUKernel : public LiteKernel { public: explicit PadInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs) { + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) { opParameter->thread_num_ = ctx->thread_num_; pad_param_ = reinterpret_cast(opParameter); } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc index 9a810d27f8..36b10c7344 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.cc @@ -26,6 +26,10 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int PoolingInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } auto ret = PoolingBaseCPUKernel::Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "PoolingBase Init failed."; @@ -77,6 +81,11 @@ int PoolingInt8Impl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int PoolingInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } int error_code = LiteBackendParallelLaunch(PoolingInt8Impl, this, thread_count_); if (error_code != RET_OK) { MS_LOG(ERROR) << "poolingInt8 error error_code[" << error_code << "]"; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.h index 367c10f59c..fafdf09c6d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/pooling_int8.h @@ -29,8 +29,9 @@ namespace mindspore::kernel { class PoolingInt8CPUKernel : public PoolingBaseCPUKernel { public: PoolingInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : PoolingBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : PoolingBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~PoolingInt8CPUKernel() { FreeQuantParam(); } int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/prelu_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/prelu_int8.cc new file mode 100644 index 0000000000..2f4d36a6fc --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/prelu_int8.cc @@ -0,0 +1,80 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "src/runtime/kernel/arm/int8/prelu_int8.h" +#include +#include "src/runtime/kernel/arm/nnacl/int8/prelu_int8.h" +#include "src/runtime/runtime_api.h" +#include "src/kernel_registry.h" +#include "include/errorcode.h" + +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Prelu; + +namespace mindspore::kernel { +int PreluInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } + PreluBaseCPUKernel::Init(); + auto *input_tensor = inputs_.at(kInputIndex); + auto in_quant_args = input_tensor->GetQuantParams(); + quant_prelu_parm_->quant_arg.in_args_.scale_ = in_quant_args.front().scale; + quant_prelu_parm_->quant_arg.in_args_.zp_ = in_quant_args.front().zeroPoint; + auto input_dim = input_tensor->shape().size(); + MS_ASSERT(input_dim <= CROP_OFFSET_MAX_SIZE); + quant_prelu_parm_->input_dim_ = input_dim; + quant_prelu_parm_->element_num = inputs_[0]->Size(); + auto *out_tensor = outputs_.at(kOutputIndex); + auto out_quant_args = out_tensor->GetQuantParams(); + quant_prelu_parm_->quant_arg.out_args_.scale_ = out_quant_args.front().scale; + quant_prelu_parm_->quant_arg.out_args_.zp_ = out_quant_args.front().zeroPoint; + quant_prelu_parm_->in_shape_ = input_tensor->shape().data(); + quant_prelu_parm_->out_shape_ = out_tensor->shape().data(); + quant_prelu_parm_->quant_arg.output_activation_max_ = std::numeric_limits::max(); + quant_prelu_parm_->quant_arg.output_activation_min_ = std::numeric_limits::min(); + return RET_OK; +} + +int PreluInt8CPUKernel::ReSize() { return 0; } + +int PreluInt8CPUKernel::Run() { + auto ret = LiteBackendParallelLaunch(PreluInt8Run, this, thread_count_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "RunPreluParam failed. errorcode: "; + } + return RET_OK; +} +int PreluInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto prelu = reinterpret_cast(cdata); + prelu->DoExecute(task_id); + return RET_OK; +} + +int PreluInt8CPUKernel::DoExecute(int task_id) { + auto input_tensor = inputs_.at(kInputIndex); + auto out_tensor = outputs_.at(kOutputIndex); + int8_t *input_data = reinterpret_cast(input_tensor->Data()); + int8_t *output_data = reinterpret_cast(out_tensor->Data()); + prelu(input_data, output_data, quant_prelu_parm_, task_id); + return RET_OK; +} + +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/prelu_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/prelu_int8.h new file mode 100644 index 0000000000..c50378e63d --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/prelu_int8.h @@ -0,0 +1,50 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_PRELU_INT8_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_PRELU_INT8_H_ + +#include +#include "src/lite_kernel.h" +#include "include/context.h" +#include "src/runtime/kernel/arm/base/prelu_base.h" +#include "src/runtime/runtime_api.h" + +using mindspore::lite::Context; + +namespace mindspore::kernel { +class PreluInt8CPUKernel : public PreluBaseCPUKernel { + public: + PreluInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : PreluBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) { + quant_prelu_parm_ = reinterpret_cast(opParameter); + } + ~PreluInt8CPUKernel() override {} + + int Init() override; + int ReSize() override; + int Run() override; + int DoExecute(int task_id); + + private: + PreluParameter *quant_prelu_parm_; +}; +int PreluInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata); +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_PRELU_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc similarity index 70% rename from mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.cc rename to mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc index 62178774b9..fcbffcac79 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/int8/relu_int8.h" +#include "src/runtime/kernel/arm/int8/relux_int8.h" #include "schema/model_generated.h" #include "src/kernel_registry.h" #include "src/runtime/runtime_api.h" @@ -27,7 +27,12 @@ using mindspore::lite::RET_OK; using mindspore::schema::ActivationType_RELU; namespace mindspore::kernel { -int ReluInt8CPUKernel::Init() { +int ReluXInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } + lite::tensor::Tensor *input = inputs_.at(0); lite::tensor::Tensor *output = outputs_.at(0); MS_ASSERT(input); @@ -44,9 +49,9 @@ int ReluInt8CPUKernel::Init() { return RET_OK; } -int ReluInt8CPUKernel::ReSize() { return RET_OK; } +int ReluXInt8CPUKernel::ReSize() { return RET_OK; } -int ReluInt8CPUKernel::DoActivation(int task_id) { +int ReluXInt8CPUKernel::DoActivation(int task_id) { auto input_addr = reinterpret_cast(inputs_.at(0)->Data()); auto output_addr = reinterpret_cast(outputs_.at(0)->Data()); auto length = inputs_.at(0)->ElementsNum(); @@ -54,24 +59,29 @@ int ReluInt8CPUKernel::DoActivation(int task_id) { int stride = UP_DIV(length, thread_count_); int count = MSMIN(stride, length - stride * task_id); - ReluInt8(input_addr + stride * task_id, count, output_addr + stride * task_id, &quant_arg_); + ReluXInt8(input_addr + stride * task_id, count, output_addr + stride * task_id, &quant_arg_); return RET_OK; } -int ReluInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { - auto activation_kernel = reinterpret_cast(cdata); +int ReluXInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto activation_kernel = reinterpret_cast(cdata); auto error_code = activation_kernel->DoActivation(task_id); if (error_code != RET_OK) { - MS_LOG(ERROR) << "ReluInt8Run error task_id[" << task_id << "] error_code[" << error_code << "]"; + MS_LOG(ERROR) << "ReluXInt8Run error task_id[" << task_id << "] error_code[" << error_code << "]"; return RET_ERROR; } return RET_OK; } -int ReluInt8CPUKernel::Run() { - int error_code = LiteBackendParallelLaunch(ReluInt8Run, this, thread_count_); +int ReluXInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } + int error_code = LiteBackendParallelLaunch(ReluXInt8Run, this, thread_count_); if (error_code != RET_OK) { - MS_LOG(ERROR) << "ReluInt8Run function error error_code[" << error_code << "]"; + MS_LOG(ERROR) << "ReluXInt8Run function error error_code[" << error_code << "]"; return RET_ERROR; } return RET_OK; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.h new file mode 100644 index 0000000000..90a31ed0c8 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.h @@ -0,0 +1,83 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_ACTIVATION_H_ +#define MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_ACTIVATION_H_ + +#include +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/nnacl/fp32/activation.h" +#include "src/runtime/kernel/arm/nnacl/int8/relux_int8.h" + +namespace mindspore::kernel { +class ReluXInt8CPUKernel : public LiteKernel { + public: + ReluXInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) { + type_ = (reinterpret_cast(parameter))->type_; + } + ~ReluXInt8CPUKernel() override = default; + + int Init() override; + int ReSize() override; + int Run() override; + int DoActivation(int task_id); + + ReluXQuantArg quant_arg_; + + private: + int thread_count_; + int type_; +}; + +class ReluInt8CPUKernel : public ReluXInt8CPUKernel { + public: + ReluInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ReluXInt8CPUKernel(parameter, inputs, outputs, ctx, primitive) {} + + ~ReluInt8CPUKernel() override = default; + + int Init() override { + auto ret = ReluXInt8CPUKernel::Init(); + quant_arg_.quantized_output_min = quant_arg_.output_arg.zp_; + quant_arg_.quantized_output_max = CHAR_MAX; + return ret; + }; +}; + +class Relu6Int8CPUKernel : public ReluXInt8CPUKernel { + public: + Relu6Int8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ReluXInt8CPUKernel(parameter, inputs, outputs, ctx, primitive) {} + + ~Relu6Int8CPUKernel() override = default; + + int Init() override { + auto ret = ReluXInt8CPUKernel::Init(); + quant_arg_.quantized_output_min = QuantizeToInt8(0, quant_arg_.output_arg.scale_, quant_arg_.output_arg.zp_); + quant_arg_.quantized_output_max = QuantizeToInt8(6, quant_arg_.output_arg.scale_, quant_arg_.output_arg.zp_); + return ret; + }; +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_ACTIVATION_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc index 7969b89a78..a6b8402253 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.cc @@ -15,6 +15,7 @@ */ #include "src/runtime/kernel/arm/int8/reshape_int8.h" +#include #include "src/runtime/kernel/arm/nnacl/int8/reshape_int8.h" #include "schema/model_generated.h" #include "include/errorcode.h" @@ -26,49 +27,62 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int ReshapeInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } ReshapeBaseCPUKernel::Init(); auto *input_tensor = inputs_.at(kInputIndex); auto in_quant_args = input_tensor->GetQuantParams(); - in_quant_arg_.scale_ = in_quant_args.front().scale; - in_quant_arg_.zp_ = in_quant_args.front().zeroPoint; + reshape_param_->quant_para_.in_args_.scale_ = in_quant_args.front().scale; + reshape_param_->quant_para_.in_args_.zp_ = in_quant_args.front().zeroPoint; auto *out_tensor = outputs_.at(kOutputIndex); auto out_quant_args = out_tensor->GetQuantParams(); - out_quant_arg_.scale_ = out_quant_args.front().scale; - out_quant_arg_.zp_ = out_quant_args.front().zeroPoint; + reshape_param_->quant_para_.out_args_.scale_ = out_quant_args.front().scale; + reshape_param_->quant_para_.out_args_.zp_ = out_quant_args.front().zeroPoint; + + reshape_param_->quant_para_.output_activation_min_ = std::numeric_limits::min(); + reshape_param_->quant_para_.output_activation_max_ = std::numeric_limits::max(); + return RET_OK; } int ReshapeInt8CPUKernel::ReSize() { return 0; } int ReshapeInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } MS_ASSERT(inputs_.size() == 1); MS_ASSERT(outputs_.size() == 1); - auto input_type = inputs_[kInputIndex]->data_type(); - auto input_num = inputs_[kInputIndex]->ElementsNum(); - auto output_num = outputs_.at(kOutputIndex)->ElementsNum(); - MS_ASSERT(input_num == output_num); - int8_t *input_ptr = reinterpret_cast(inputs_.at(kInputIndex)->Data()); - int8_t *output_ptr = reinterpret_cast(outputs_.at(kOutputIndex)->Data()); - if (input_type == kNumberTypeUInt8) { - auto *input_tmp = reinterpret_cast(inputs_.at(kInputIndex)->Data()); - for (size_t i = 0; i < input_num; i++) { - input_ptr[i] = (int8_t)(input_tmp[i] - 128); - } - in_quant_arg_.zp_ -= 128; - out_quant_arg_.zp_ -= 128; - } + input_data_ = static_cast(inputs_.at(kInputIndex)->Data()); + output_data_ = static_cast(outputs_.at(kOutputIndex)->Data()); - size_t data_size = inputs_.at(kInputIndex)->Size(); - Reshape(input_ptr, output_ptr, data_size, input_num, in_quant_arg_, out_quant_arg_); + elements_num_ = inputs_.at(kInputIndex)->ElementsNum(); + count_unit_ = thread_count_ > 1 ? UP_DIV(elements_num_, thread_count_) : elements_num_; - auto output_type = outputs_[kOutputIndex]->data_type(); - if (output_type == kNumberTypeUInt8) { - for (size_t i = 0; i < output_num; i++) { - output_ptr[i] = (uint8_t)(output_ptr[i] + 128); - } + ret = LiteBackendParallelLaunch(ReshapeInt8Run, this, thread_count_); + return ret; +} + +int ReshapeInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto reshape = reinterpret_cast(cdata); + reshape->DoExecute(task_id); + return lite::RET_OK; +} + +int ReshapeInt8CPUKernel::DoExecute(int task_id) { + int64_t real_dst_count = MSMIN(elements_num_ - task_id * count_unit_, count_unit_); + if (real_dst_count <= 0) { + return lite::RET_OK; } - return RET_OK; + int8_t *cur_input0_data = input_data_ + task_id * count_unit_; + int8_t *cur_output_data = output_data_ + task_id * count_unit_; + + Reshape(cur_input0_data, cur_output_data, real_dst_count, reshape_param_->quant_para_); + return lite::RET_OK; } } // namespace mindspore::kernel - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h index cb1065a4c0..1112520734 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/reshape_int8.h @@ -19,9 +19,9 @@ #include #include "src/lite_kernel.h" - #include "include/context.h" #include "src/runtime/kernel/arm/base/reshape_base.h" +#include "src/runtime/runtime_api.h" using mindspore::lite::Context; @@ -29,19 +29,25 @@ namespace mindspore::kernel { class ReshapeInt8CPUKernel : public ReshapeBaseCPUKernel { public: ReshapeInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : ReshapeBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : ReshapeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~ReshapeInt8CPUKernel() = default; int Init() override; int ReSize() override; int Run() override; + int DoExecute(int task_id); private: - QuantArg in_quant_arg_; - QuantArg out_quant_arg_; + int thread_count_; + int64_t elements_num_; + int64_t count_unit_; + int8_t *input_data_ = nullptr; + int8_t *output_data_ = nullptr; }; + +int ReshapeInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata); } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_RESHAPE_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc new file mode 100644 index 0000000000..14aca7d6b6 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.cc @@ -0,0 +1,134 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "schema/model_generated.h" +#include "src/kernel_registry.h" +#include "nnacl/int8/resize.h" +#include "include/errorcode.h" +#include "src/runtime/kernel/arm/int8/resize_int8.h" +#include "src/runtime/runtime_api.h" + +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_INVALID_OP_ATTR; +using mindspore::lite::RET_NULL_PTR; +using mindspore::lite::RET_OK; + +namespace mindspore::kernel { +namespace { +constexpr int kInputNum = 1; +constexpr int kOutputNum = 1; +constexpr size_t kRank = 4; +} // namespace + +int ResizeInt8CPUKernel::Init() { + auto ret = ResizeBaseCPUKernel::Init(); + if (ret != RET_OK) { + return ret; + } + quant_in_ = new (std::nothrow) QuantArg; + MS_ASSERT(quant_in_); + quant_out_ = new (std::nothrow) QuantArg; + MS_ASSERT(quant_out_); + auto input = inputs_.at(0); + quant_in_->zp_ = input->GetQuantParams().front().zeroPoint; + quant_in_->scale_ = input->GetQuantParams().front().scale; + auto output = outputs_.at(0); + quant_out_->zp_ = output->GetQuantParams().front().zeroPoint; + quant_out_->scale_ = output->GetQuantParams().front().scale; + + multiplier_ = new (std::nothrow) QuantMulArg; + MS_ASSERT(multiplier_); + QuantizeRoundParameter(quant_in_->scale_ / quant_out_->scale_, &multiplier_->multiplier_, &multiplier_->left_shift_, + &multiplier_->right_shift_); + if (!InferShapeDone()) { + return RET_OK; + } + return ReSize(); +} + +int ResizeInt8Impl(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto resize = reinterpret_cast(cdata); + auto error_code = resize->RunImpl(task_id); + if (error_code != RET_OK) { + MS_LOG(ERROR) << "Resize Run error task_id[" << task_id << "] error_code[" << error_code << "]"; + return RET_ERROR; + } + return RET_OK; +} + +int ResizeInt8CPUKernel::RunImpl(int task_id) { + auto input = inputs_.at(0); + auto input_data = reinterpret_cast(input->Data()); + if (input_data == nullptr) { + return RET_NULL_PTR; + } + auto output_data = reinterpret_cast(outputs_.at(0)->Data()); + if (output_data == nullptr) { + return RET_NULL_PTR; + } + auto input_shape = input->shape(); + + if (context_ == nullptr) { + return RET_NULL_PTR; + } + + int ret = 0; + switch (method_) { + case static_cast(schema::ResizeMethod_BILINEAR): { + ret = ResizeBilinearInt8(input_data, output_data, input_shape.data(), outputs_[0]->shape().data(), align_corners_, + quant_in_, quant_out_, multiplier_, task_id, context_->thread_num_); + + break; + } + case static_cast(schema::ResizeMethod_NEAREST_NEIGHBOR): { + bool same_zp = quant_in_->zp_ == quant_out_->zp_; + bool same_scale = abs(quant_out_->scale_ - quant_in_->scale_) < 1e-6; + if (same_zp && same_scale) { + ret = ResizeNearestNeighborInt8Simple(input_data, output_data, input_shape.data(), outputs_[0]->shape().data(), + align_corners_, task_id, context_->thread_num_); + } else { + ret = + ResizeNearestNeighborInt8(input_data, output_data, input_shape.data(), outputs_[0]->shape().data(), + align_corners_, multiplier_, quant_in_, quant_out_, task_id, context_->thread_num_); + } + break; + } + case schema::ResizeMethod_UNKNOW: + default: { + MS_LOG(ERROR) << "Resize unknown method " << method_; + ret = RET_ERROR; + } + } + return ret; +} + +int ResizeInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } + int error_code = LiteBackendParallelLaunch(ResizeInt8Impl, this, context_->thread_num_); + if (error_code != RET_OK) { + MS_LOG(ERROR) << "Resize run error, error_code[" << error_code << "]"; + return RET_ERROR; + } + return RET_OK; +} +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.h new file mode 100644 index 0000000000..58e45ebf17 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/resize_int8.h @@ -0,0 +1,56 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_RESIZE_INT8_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_RESIZE_INT8_H_ + +#include +#include "src/lite_kernel.h" +#include "src/runtime/kernel/arm/base/resize_base.h" +#include "nnacl/quantization/quantize.h" + +using mindspore::schema::PrimitiveType_Resize; +using mindspore::schema::ResizeMethod; + +namespace mindspore::kernel { +class ResizeInt8CPUKernel : public ResizeBaseCPUKernel { + public: + ResizeInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : ResizeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + + ~ResizeInt8CPUKernel() { + delete quant_out_; + quant_out_ = nullptr; + delete quant_in_; + quant_in_ = nullptr; + delete multiplier_; + multiplier_ = nullptr; + } + + int Init() override; + int ReSize() override { return 0; }; + int Run() override; + int RunImpl(int task_id); + + private: + QuantArg *quant_in_; + QuantArg *quant_out_; + QuantMulArg *multiplier_; +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_RESIZE_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc new file mode 100644 index 0000000000..efd385b2d2 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.cc @@ -0,0 +1,105 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "src/runtime/kernel/arm/int8/sigmoid_int8.h" +#include +#include "src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.h" +#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "schema/model_generated.h" +#include "src/kernel_registry.h" +#include "src/runtime/runtime_api.h" +#include "include/errorcode.h" + +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; +using mindspore::schema::ActivationType_SIGMOID; + +namespace mindspore::kernel { +int SigmoidInt8CPUKernel::Init() { + lite::tensor::Tensor *input = inputs_.at(0); + lite::tensor::Tensor *output = outputs_.at(0); + MS_ASSERT(input); + MS_ASSERT(output); + + quant_arg_.input_scale = input->GetQuantParams().front().scale; + quant_arg_.input_zp = input->GetQuantParams().front().zeroPoint; + quant_arg_.output_scale = output->GetQuantParams().front().scale; + quant_arg_.output_zp = output->GetQuantParams().front().zeroPoint; + + const float output_multiplier = (1.0f / 128.0f) * quant_arg_.input_scale / quant_arg_.output_scale; + + int32_t output_multiplier_fixedpoint; + QuantizeMultiplier(output_multiplier, &output_multiplier_fixedpoint, &quant_arg_.output_multiplier_exponent); + MS_ASSERT(quant_arg_.output_multiplier_exponent <= 0); + MultiplierInt32ToInt16(output_multiplier_fixedpoint, &quant_arg_.output_multiplier_fixedpoint_int16); + + const float relu6_multiplier = (1.0f / 128.0f) * quant_arg_.input_scale / (3.0f / 32768.0f); + int32_t relu6_multiplier_fixedpoint; + QuantizeMultiplier(relu6_multiplier, &relu6_multiplier_fixedpoint, &quant_arg_.relu6_multiplier_exponent); + MultiplierInt32ToInt16(relu6_multiplier_fixedpoint, &quant_arg_.relu6_multiplier_fixedpoint_int16); + + return RET_OK; +} + +void SigmoidInt8CPUKernel::MultiplierInt32ToInt16(int32_t input, int16_t *output) { + MS_ASSERT(input >= 0); + if (input >= std::numeric_limits::max() - (1 << 15)) { + *output = std::numeric_limits::max(); + return; + } + *output = (input + (1 << 15)) >> 16; +} + +int SigmoidInt8CPUKernel::ReSize() { return RET_OK; } + +int SigmoidInt8CPUKernel::DoActivation(int task_id) { + auto input_addr = reinterpret_cast(inputs_.at(0)->Data()); + auto output_addr = reinterpret_cast(outputs_.at(0)->Data()); + auto length = inputs_.at(0)->ElementsNum(); + + int stride = UP_DIV(length, thread_count_); + int count = MSMIN(stride, length - stride * task_id); + + SigmoidInt8(input_addr + stride * task_id, count, output_addr + stride * task_id, &quant_arg_); + return RET_OK; +} + +int SigmoidInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto activation_kernel = reinterpret_cast(cdata); + auto error_code = activation_kernel->DoActivation(task_id); + if (error_code != RET_OK) { + MS_LOG(ERROR) << "SigmoidInt8Run error task_id[" << task_id << "] error_code[" << error_code << "]"; + return RET_ERROR; + } + return RET_OK; +} + +int SigmoidInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } + int error_code = LiteBackendParallelLaunch(SigmoidInt8Run, this, thread_count_); + if (error_code != RET_OK) { + MS_LOG(ERROR) << "SigmoidInt8Run function error error_code[" << error_code << "]"; + return RET_ERROR; + } + return RET_OK; +} +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.h similarity index 52% rename from mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.h rename to mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.h index 5f8f81a3a5..a2d9db97ad 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sigmoid_int8.h @@ -14,23 +14,21 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_ACTIVATION_H_ -#define MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_ACTIVATION_H_ +#ifndef MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_SIGMOID_INT8_H_ +#define MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_SIGMOID_INT8_H_ #include #include "src/lite_kernel.h" -#include "src/runtime/kernel/arm/nnacl/fp32/activation.h" -#include "src/runtime/kernel/arm/nnacl/int8/relu_int8.h" +#include "src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.h" namespace mindspore::kernel { -class ReluInt8CPUKernel : public LiteKernel { +class SigmoidInt8CPUKernel : public LiteKernel { public: - ReluInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : LiteKernel(parameter, inputs, outputs), thread_count_(ctx->thread_num_) { - type_ = (reinterpret_cast(parameter))->type_; - } - ~ReluInt8CPUKernel() override = default; + SigmoidInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), thread_count_(ctx->thread_num_) {} + ~SigmoidInt8CPUKernel() override = default; int Init() override; int ReSize() override; @@ -39,9 +37,9 @@ class ReluInt8CPUKernel : public LiteKernel { private: int thread_count_; - int type_; - ReluQuantArg quant_arg_; + SigmoidQuantArg quant_arg_; + void MultiplierInt32ToInt16(int32_t input, int16_t *output); }; } // namespace mindspore::kernel -#endif // MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_ACTIVATION_H_ +#endif // MINDSPORE_LITE_SRC_BACKEND_ARM_INT8_SIGMOID_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc index 2a3ef9d6ca..2c6591bcb7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.cc @@ -26,6 +26,10 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int SoftmaxInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } SoftmaxBaseCPUKernel::Init(); auto *input_tensor = inputs_.at(kInputIndex); @@ -95,6 +99,11 @@ int SoftmaxRun(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int SoftmaxInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return RET_ERROR; + } auto input_ptr = reinterpret_cast(inputs_.at(0)->Data()); int ele_size = softmax_param_->element_size_; for (int i = 0; i < ele_size; i++) { diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.h index d29da4094a..c3c47ea0e1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/softmax_int8.h @@ -19,13 +19,15 @@ #include #include "src/runtime/kernel/arm/base/softmax_base.h" +#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" namespace mindspore::kernel { class SoftmaxInt8CPUKernel : public SoftmaxBaseCPUKernel { public: SoftmaxInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const lite::Context *ctx) - : SoftmaxBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : SoftmaxBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~SoftmaxInt8CPUKernel() = default; int Init() override; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc index 80f9cdf61c..2c6f0762ef 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.cc @@ -28,6 +28,10 @@ using mindspore::lite::RET_OK; namespace mindspore::kernel { int SplitInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } SplitBaseCPUKernel::Init(); auto in_tensor = inputs_.at(kInputIndex); input_ptr_ = reinterpret_cast(in_tensor->Data()); @@ -81,7 +85,12 @@ int SplitInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { } int SplitInt8CPUKernel::Run() { - int ret = LiteBackendParallelLaunch(SplitInt8Run, this, thread_n_num_); + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } + ret = LiteBackendParallelLaunch(SplitInt8Run, this, thread_n_num_); if (ret != RET_OK) { MS_LOG(ERROR) << "Scale error error_code[" << ret << "]"; return RET_ERROR; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.h index 501d595634..ad20fd4adc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/split_int8.h @@ -29,14 +29,15 @@ namespace mindspore::kernel { class SplitInt8CPUKernel : public SplitBaseCPUKernel { public: SplitInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs, const Context *ctx) - : SplitBaseCPUKernel(parameter, inputs, outputs, ctx) {} + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : SplitBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} ~SplitInt8CPUKernel() = default; int Init() override; int ReSize() override; int Run() override; - int Split(int tId); + int Split(int task_id); private: int8_t *input_ptr_; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc new file mode 100644 index 0000000000..30755bdfc0 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.cc @@ -0,0 +1,176 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "src/runtime/kernel/arm/nnacl/int8/squeeze_int8.h" +#include "src/runtime/kernel/arm/int8/squeeze_int8.h" +#include "src/runtime/kernel/arm/nnacl/squeeze_parameter.h" + +#include "schema/model_generated.h" +#include "src/runtime/runtime_api.h" +#include "include/errorcode.h" + +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; + +namespace mindspore::kernel { + +int SqueezeInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } + SqueezeBaseCPUKernel::Init(); + quant_Squeeze_parm_ = new (std::nothrow) SqueezeQuantArg; + auto input_num = inputs_.size(); + quant_Squeeze_parm_->input_num_ = input_num; + quant_Squeeze_parm_->input_sizes_ = reinterpret_cast(malloc(sizeof(int) * input_num)); + if (quant_Squeeze_parm_->input_sizes_ == nullptr) { + MS_LOG(ERROR) << "Null pointer reference: quant_Squeeze_parm_->input_sizes_."; + return RET_ERROR; + } + + for (size_t i = 0; i < input_num; i++) { + quant_Squeeze_parm_->input_sizes_[i] = 1; + } + quant_Squeeze_parm_->input_shapes_ = reinterpret_cast(malloc(sizeof(int *) * input_num)); + if (quant_Squeeze_parm_->input_shapes_ == nullptr) { + MS_LOG(ERROR) << "Null pointer reference: quant_Squeeze_parm_->input_shapes_."; + return RET_ERROR; + } + + for (size_t i = 0; i < input_num; i++) { + auto *input_tensor = inputs_.at(i); + MS_ASSERT(input_tensor != nullptr); + auto input_size = input_tensor->shape().size(); + MS_ASSERT(input_size != NULL); + quant_Squeeze_parm_->input_shapes_[i] = reinterpret_cast(malloc(sizeof(int) * input_size)); + if (quant_Squeeze_parm_->input_shapes_[i] == nullptr) { + MS_LOG(ERROR) << "Null pointer reference: quant_Squeeze_parm_->input_shapes_[" << i << "]."; + return RET_ERROR; + } + + ::memcpy(quant_Squeeze_parm_->input_shapes_[i], input_tensor->shape().data(), sizeof(int) * input_size); + for (size_t j = 0; j < input_size; j++) { + auto *input_tensor_tmp = inputs_.at(i); + auto input_shape = input_tensor_tmp->shape()[j]; + quant_Squeeze_parm_->input_sizes_[i] *= input_shape; + } + } + quant_Squeeze_parm_->axis_ = 0; + quant_Squeeze_parm_->in_quant_args_ = reinterpret_cast(malloc(sizeof(QuantArg) * input_num)); + if (quant_Squeeze_parm_->in_quant_args_ == nullptr) { + MS_LOG(ERROR) << "Null pointer reference: quant_Squeeze_parm_->in_quant_args_."; + return RET_ERROR; + } + + for (size_t i = 0; i < input_num; i++) { + auto *input_tensor = inputs_.at(i); + auto quant_args = input_tensor->GetQuantParams(); + MS_ASSERT(quant_args.size() == 1); + quant_Squeeze_parm_->in_quant_args_[i].scale_ = quant_args.front().scale; + quant_Squeeze_parm_->in_quant_args_[i].zp_ = quant_args.front().zeroPoint; + } + + MS_ASSERT(outputs_.size() == 1); + auto output_tensor = outputs_.at(0); + MS_ASSERT(output_tensor != nullptr); + auto output_shape = output_tensor->shape(); + MS_ASSERT(output_shape != NULL); + auto output_dim = output_shape.size(); + quant_Squeeze_parm_->output_dim_ = output_dim; + int output_size = 1; + for (size_t i = 0; i < output_dim; i++) { + output_size *= output_shape[i]; + } + quant_Squeeze_parm_->output_size_ = output_size; + + quant_Squeeze_parm_->output_shape_ = new int[output_size]; + ::memcpy(quant_Squeeze_parm_->output_shape_, output_shape.data(), sizeof(int) * output_size); + + auto quant_args = output_tensor->GetQuantParams(); + MS_ASSERT(quant_args.size() == 1); + quant_Squeeze_parm_->out_quant_args_.scale_ = quant_args.front().scale; + quant_Squeeze_parm_->out_quant_args_.zp_ = quant_args.front().zeroPoint; + + return RET_OK; +} + +int SqueezeInt8CPUKernel::ReSize() { return 0; } + +int SqueezeInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } + auto input_dim = quant_Squeeze_parm_->input_num_; + int8_t **inputs_array = reinterpret_cast(malloc(sizeof(int8_t *) * input_dim)); + for (size_t i = 0; i < input_dim; i++) { + auto input_size = quant_Squeeze_parm_->input_sizes_[i]; + inputs_array[i] = reinterpret_cast(malloc(sizeof(int8_t) * input_size)); + auto input_type = inputs_[i]->data_type(); + if (input_type == kNumberTypeUInt8) { + uint8_t *input_tmp = reinterpret_cast(inputs_[i]->Data()); + for (size_t j = 0; j < input_size; j++) { + inputs_array[i][j] = (int8_t)(input_tmp[j] - 128); + } + for (size_t j = 0; j < input_dim; j++) { + quant_Squeeze_parm_->in_quant_args_[j].zp_ -= 128; + } + quant_Squeeze_parm_->out_quant_args_.zp_ -= 128; + } else { + ::memcpy(inputs_array[i], inputs_.at(i)->Data(), sizeof(int8_t) * input_size); + } + } + int8_t *output_addr = reinterpret_cast(outputs_.at(0)->Data()); + auto output_type = outputs_[0]->data_type(); + if (output_type == kNumberTypeUInt8) { + auto output_size = quant_Squeeze_parm_->output_size_; + for (size_t i = 0; i < output_size; i++) { + output_addr[i] = (uint8_t)(output_addr[i] + 128); + } + } + + for (int i = 0; i < input_dim; i++) { + free(*(inputs_array + i)); + } + + ret = LiteBackendParallelLaunch(SqueezeInt8Run, this, thread_count_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "RunSqueezeParam failed. errorcode: "; + } + return RET_OK; +} + +int SqueezeInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto Squeeze = reinterpret_cast(cdata); + Squeeze->DoExecute(task_id); + return RET_OK; +} + +int SqueezeInt8CPUKernel::DoExecute(int task_id) { + auto input_tensor = inputs_.at(kInputIndex); + auto out_tensor = outputs_.at(kOutputIndex); + int8_t *input_data = reinterpret_cast(input_tensor->Data()); + int8_t *output_data = reinterpret_cast(out_tensor->Data()); + + size_t data_size = inputs_.front()->Size(); + Squeeze(&input_data, output_data, task_id, quant_Squeeze_parm_, para_, data_size); + return RET_OK; +} + +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.h new file mode 100644 index 0000000000..d4ae65561f --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/squeeze_int8.h @@ -0,0 +1,51 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_SQUEEZE_INT8_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_SQUEEZE_INT8_H_ + +#include +#include "src/lite_kernel.h" +#include "include/context.h" +#include "src/runtime/runtime_api.h" +#include "src/runtime/kernel/arm/base/squeeze_base.h" + +using mindspore::lite::Context; + +namespace mindspore::kernel { +class SqueezeInt8CPUKernel : public SqueezeBaseCPUKernel { + public: + SqueezeInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : SqueezeBaseCPUKernel(parameter, inputs, outputs, ctx, primitive) {} + ~SqueezeInt8CPUKernel() override { delete quant_Squeeze_parm_; } + + int Init() override; + int ReSize() override; + int Run() override; + int DoExecute(int tId); + + private: + SqueezeParameter *para_; + SqueezeQuantArg *quant_Squeeze_parm_; +}; + +int SqueezeInt8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata); + +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_INT8_SQUEEZE_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc index 2280d9e078..0e96c8c9be 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.cc @@ -25,6 +25,10 @@ using mindspore::schema::PrimitiveType_TopK; namespace mindspore::kernel { int TopKInt8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } TopkParameter *parameter = reinterpret_cast(opParameter); lite::tensor::Tensor *input = inputs_.at(0); parameter->last_dim_size_ = input->shape()[input->shape().size() - 1]; @@ -44,6 +48,11 @@ int TopKInt8CPUKernel::Init() { int TopKInt8CPUKernel::ReSize() { return RET_OK; } int TopKInt8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } int8_t *input_data = reinterpret_cast(inputs_.at(0)->Data()); int8_t *output_data = reinterpret_cast(outputs_.at(0)->Data()); int32_t *output_index = reinterpret_cast(outputs_.at(1)->Data()); @@ -54,9 +63,10 @@ int TopKInt8CPUKernel::Run() { kernel::LiteKernel *CpuTopKInt8KernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *parameter, - const lite::Context *ctx, const KernelKey &desc) { + const lite::Context *ctx, const KernelKey &desc, + const lite::Primitive *primitive) { MS_ASSERT(parameter != nullptr); - auto *kernel = new (std::nothrow) TopKInt8CPUKernel(parameter, inputs, outputs); + TopKInt8CPUKernel *kernel = new (std::nothrow) TopKInt8CPUKernel(parameter, inputs, outputs, ctx, primitive); if (kernel == nullptr) { MS_LOG(ERROR) << "new TopKInt8CPUKernel fail!"; return nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.h index 1216033e9c..513455c1e7 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/int8/topk_int8.h @@ -24,8 +24,9 @@ namespace mindspore::kernel { class TopKInt8CPUKernel : public LiteKernel { public: explicit TopKInt8CPUKernel(OpParameter *parameter, const std::vector &inputs, - const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + const std::vector &outputs, const lite::Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive) {} ~TopKInt8CPUKernel() override { TopkParameter *parameter = reinterpret_cast(opParameter); free(parameter->topk_node_list_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc new file mode 100644 index 0000000000..450034e93f --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.cc @@ -0,0 +1,124 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.h" +#include "src/runtime/kernel/arm/int8/unsqueeze_int8.h" +#include "schema/model_generated.h" +#include "src/kernel_registry.h" +#include "include/errorcode.h" +#include "src/runtime/runtime_api.h" + +using mindspore::kernel::KERNEL_ARCH::kCPU; +using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_ERROR; +using mindspore::lite::RET_OK; +using mindspore::schema::PrimitiveType_Unsqueeze; + +namespace mindspore::kernel { +int Unsqueezeint8CPUKernel::Init() { + if (context_->infer_shape_interrupt_ && !context_->running_) { + SetNeedReInit(); + return RET_OK; + } + auto *input_tensor = inputs_.at(0); + auto quant_args = input_tensor->GetQuantParams(); + MS_ASSERT(quant_args.size() == 1); + Unsq_para_->quant_arg.in_quant_args_.scale_ = quant_args.front().scale; + Unsq_para_->quant_arg.in_quant_args_.zp_ = quant_args.front().zeroPoint; + + auto out_quant_args = input_tensor->GetQuantParams(); + Unsq_para_->quant_arg.out_quant_args_.scale_ = out_quant_args.front().scale; + Unsq_para_->quant_arg.out_quant_args_.zp_ = out_quant_args.front().zeroPoint; + Unsq_para_->thread_count_ = thread_count_; + + int ret = ReSize(); + return ret; +} + +int Unsqueezeint8CPUKernel::ReSize() { + data_size_ = inputs_.at(0)->ElementsNum(); + thread_sz_count_ = MSMIN(thread_count_, data_size_); + thread_sz_stride_ = UP_DIV(data_size_, thread_sz_count_); + return RET_OK; +} + +int Unsqueezeint8CPUKernel::DoUnsqueeze(int task_id) { + size_t size = MSMIN(thread_sz_stride_, data_size_ - task_id * thread_sz_stride_); + if (size == 0) { + return RET_OK; + } + + auto input_ptr = reinterpret_cast(inputs_.front()->Data()); + auto output_ptr = reinterpret_cast(outputs_.front()->Data()); + size_t data_size = outputs_.front()->Size(); + + int ret = Unsqueeze(input_ptr, output_ptr, Unsq_para_, data_size, task_id); + if (ret != RET_OK) { + MS_LOG(ERROR) << "UnsqueezeRun error task_id[" << task_id << "] error_code[" << ret << "]"; + return ret; + } + return RET_OK; +} + +int UnsqueezeIn8Run(int task_id, LiteParallelGroupEnv *penv, void *cdata) { + auto g_kernel = reinterpret_cast(cdata); + auto ret = g_kernel->DoUnsqueeze(task_id); + if (ret != RET_OK) { + MS_LOG(ERROR) << "UnsqueezeRun error task_id[" << task_id << "] error_code[" << ret << "]"; + return ret; + } + return RET_OK; +} + +int Unsqueezeint8CPUKernel::Run() { + auto ret = Prepare(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Prepare failed."; + return ret; + } + in_ptr_ = reinterpret_cast(inputs_.at(0)->Data()); + out_ptr_ = reinterpret_cast(outputs_.at(0)->Data()); + ret = LiteBackendParallelLaunch(UnsqueezeIn8Run, this, thread_sz_count_); + if (ret != RET_OK) { + MS_LOG(ERROR) << "UnsqueezeRun error error_code[" << ret << "]"; + return ret; + } + return RET_OK; +} + +kernel::LiteKernel *CpuUnsqueezeInt8KernelCreator(const std::vector &inputs, + const std::vector &outputs, + OpParameter *opParameter, const lite::Context *ctx, + const kernel::KernelKey &desc, const lite::Primitive *primitive) { + MS_ASSERT(opParameter != nullptr); + MS_ASSERT(desc.type == schema::PrimitiveType_Unsqueeze); + auto *kernel = new (std::nothrow) Unsqueezeint8CPUKernel(opParameter, inputs, outputs, ctx, primitive); + if (kernel == nullptr) { + MS_LOG(ERROR) << "new UnsqueezeCPUKernel fail!"; + return nullptr; + } + auto ret = kernel->Init(); + if (ret != RET_OK) { + MS_LOG(ERROR) << "Init kernel failed, name: " << opParameter->name_ << ", type: " + << schema::EnumNamePrimitiveType(static_cast(opParameter->type_)); + delete kernel; + return nullptr; + } + return kernel; +} + +REG_KERNEL(kCPU, kNumberTypeInt8, PrimitiveType_Unsqueeze, CpuUnsqueezeInt8KernelCreator) +} // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.h b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.h new file mode 100644 index 0000000000..4c32cd05ef --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/int8/unsqueeze_int8.h @@ -0,0 +1,57 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSQUEEZE_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSQUEEZE_H_ + +#include +#include "src/lite_kernel.h" +#include "include/context.h" +#include "src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.h" +#include "src/runtime/kernel/arm/base/layout_transform.h" + +using mindspore::lite::Context; + +namespace mindspore::kernel { +class Unsqueezeint8CPUKernel : public LiteKernel { + public: + Unsqueezeint8CPUKernel(OpParameter *parameter, const std::vector &inputs, + const std::vector &outputs, const Context *ctx, + const lite::Primitive *primitive) + : LiteKernel(parameter, inputs, outputs, ctx, primitive), ctx_(ctx), thread_count_(ctx->thread_num_) { + Unsq_para_ = reinterpret_cast(opParameter); + Unsq_para_->thread_count_ = opParameter->thread_num_; + } + ~Unsqueezeint8CPUKernel() = default; + + int Init() override; + int ReSize() override; + int Run() override; + int DoUnsqueeze(int task_id); + + private: + UnSqueezeQuantArg *quant_Unsqueeze_parm_; + UnSqueezeParameter *Unsq_para_; + int thread_count_; + int thread_sz_count_; + int thread_sz_stride_; + int data_size_; + float *in_ptr_; + float *out_ptr_; + const Context *ctx_; +}; +} // namespace mindspore::kernel + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_FP32_UNSQUEEZE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/activation_grad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/activation_grad.h index c0ebfc368a..30b57094a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/activation_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/activation_grad.h @@ -17,15 +17,15 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ACTIVATION_GRAD_H_ #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/fp32/arithmetic.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/fp32/arithmetic.h" +#include "nnacl/errorcode.h" -struct ActivationGradParameter { +typedef struct ActivationGradParameter { OpParameter op_parameter{}; int type_; float alpha_{0.01}; -}; +} ActivationGradParameter; inline int ReluGrad(float *src0, float *src1, int length, float *dst) { for (int i = 0; i < length; ++i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.cc index a11e76f77c..2aa3bef6d2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/add_int8.h" +#include "nnacl/add_int8.h" #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/quantization/fixed_point.h" #ifdef ENABLE_NEON int16x8_t LoadAndAddOffset(int8_t *data, int index, int offset) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.h index ee667f1713..28ba83720a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/add_int8.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ADD_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ADD_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct AddQuantParameter { +typedef struct AddQuantParameter { int input0_offset_; int input1_offset_; int output_offset_; @@ -40,7 +40,7 @@ struct AddQuantParameter { int right_shift1_; int left_shift_out_; int right_shift_out_; -}; +} AddQuantParameter; void AddInt8(int8_t *input0_data, int8_t *input1_data, int8_t *output_data, int64_t real_dst_count, AddQuantParameter *para); @@ -51,4 +51,3 @@ int16x8_t LoadAndAddOffset(int8_t *data, int index, int offset); #endif #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ADD_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.cc index fd1a6f7c72..80c33f9174 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.cc @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/arg_min_max.h" -#include "src/runtime/kernel/arm/nnacl/fp32/arg_min_max.h" +#include "nnacl/arg_min_max.h" +#include "nnacl/fp32/arg_min_max.h" #define FLOAT_DATA_TYPE 43 diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.h index a308f65c51..01e4fb12be 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max.h @@ -16,9 +16,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARG_MIN_MAX_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARG_MIN_MAX_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/arg_min_max_parameter.h" -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "nnacl/arg_min_max_parameter.h" void ArgMinMax(const void *input, void *output, const int *in_shape, ArgMinMaxParameter *param); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARG_MIN_MAX_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max_parameter.h index c403f2a7c5..f8635c208c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/arg_min_max_parameter.h @@ -17,30 +17,30 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARG_MIN_MAX_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARG_MIN_MAX_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct ArgElement { +typedef struct ArgElement { uint32_t index_; union ArgData { int8_t i8_data_; int32_t i_data_; float f_data_; } data_; -}; +} ArgElement; -struct ArgMinMaxParameter { - OpParameter op_parameter_; - bool out_value_; - bool keep_dims_; - bool get_max_; - int32_t axis_; - int32_t topk_; - int32_t axis_type_; - int32_t dims_size_; - int32_t data_type_; // equals to type_id - int32_t in_strides_[DIMENSION_4D]; - int32_t out_strides_[DIMENSION_4D]; - ArgElement *arg_elements_; -}; +typedef struct ArgMinMaxParameter { + OpParameter op_parameter_; + bool out_value_; + bool keep_dims_; + bool get_max_; + int32_t axis_; + int32_t topk_; + int32_t axis_type_; + int32_t dims_size_; + int32_t data_type_; // equals to type_id + int32_t in_strides_[DIMENSION_4D]; + int32_t out_strides_[DIMENSION_4D]; + ArgElement *arg_elements_; +} ArgMinMaxParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARG_MIN_MAX_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.cc index b136fd8d42..f4a3ff3663 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" +#include "nnacl/arithmetic_common.h" void TileOneDimension(float *inData, float *outData, int dim, size_t ndim, int *inShape, int *inStrides, int *outStrides, int *multiple) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.h index b0e52b8694..73a5108232 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_common.h @@ -20,10 +20,10 @@ #include #endif #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" +#include "nnacl/op_base.h" +#include "nnacl/arithmetic_common.h" -struct ArithmeticParameter { +typedef struct ArithmeticParameter { OpParameter op_parameter_; bool broadcasting_; size_t ndim_; @@ -38,7 +38,8 @@ struct ArithmeticParameter { int multiples0_[5]; int multiples1_[5]; -}; +} ArithmeticParameter; + void TileOneDimension(float *inData, float *outData, int dim, size_t ndim, int *inShape, int *inStrides, int *outStrides, int *multiple); void ComputeStrides(int *shape, int *strides, int ndim); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_parameter.h index 132ad4a0ab..0b51ab8057 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_parameter.h @@ -17,7 +17,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARTITHMETIC_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARTITHMETIC_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_attribute.h" +#include "nnacl/op_attribute.h" diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_self_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_self_parameter.h index 35669c5518..0e4a29e506 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_self_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/arithmetic_self_parameter.h @@ -17,13 +17,14 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARITHMETIC_SELF_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARITHMETIC_SELF_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/quantization/quantize.h" // For Abs, Cos, Exp, Log, Square, Sqrt, Rsqrt ops. -struct ArithmeticSelfParameter { +typedef struct ArithmeticSelfParameter { OpParameter op_parameter_; ArithSelfQuantArg quant_arg_; -}; +} ArithmeticSelfParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ARITHMETIC_SELF_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/ConvDwInt8Center.S b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/ConvDwInt8Center.S index 0381b6bdb0..50378de953 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/ConvDwInt8Center.S +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/ConvDwInt8Center.S @@ -127,102 +127,102 @@ ConvDwInt8Center: subs x20, x20, #1 bne LoopKh16 - sqshl v0.4s, v0.4s ,v26.4s - sqshl v1.4s, v1.4s ,v26.4s - sqshl v2.4s, v2.4s ,v26.4s - sqshl v3.4s, v3.4s ,v26.4s - sqshl v4.4s, v4.4s ,v26.4s - sqshl v5.4s, v5.4s ,v26.4s - sqshl v6.4s, v6.4s ,v26.4s - sqshl v7.4s, v7.4s ,v26.4s - sqshl v8.4s, v8.4s ,v26.4s - sqshl v9.4s, v9.4s ,v26.4s - sqshl v10.4s, v10.4s ,v26.4s - sqshl v11.4s, v11.4s ,v26.4s - sqshl v12.4s, v12.4s ,v26.4s - sqshl v13.4s, v13.4s ,v26.4s - sqshl v14.4s, v14.4s ,v26.4s - sqshl v15.4s, v15.4s ,v26.4s - sqrdmulh v0.4s, v0.4s ,v27.4s - sqrdmulh v1.4s, v1.4s ,v27.4s - sqrdmulh v2.4s, v2.4s ,v27.4s - sqrdmulh v3.4s, v3.4s ,v27.4s - sqrdmulh v4.4s, v4.4s ,v27.4s - sqrdmulh v5.4s, v5.4s ,v27.4s - sqrdmulh v6.4s, v6.4s ,v27.4s - sqrdmulh v7.4s, v7.4s ,v27.4s - sqrdmulh v8.4s, v8.4s ,v27.4s - sqrdmulh v9.4s, v9.4s ,v27.4s - sqrdmulh v10.4s, v10.4s ,v27.4s - sqrdmulh v11.4s, v11.4s ,v27.4s - sqrdmulh v12.4s, v12.4s ,v27.4s - sqrdmulh v13.4s, v13.4s ,v27.4s - sqrdmulh v14.4s, v14.4s ,v27.4s - sqrdmulh v15.4s, v15.4s ,v27.4s - sqrshl v0.4s, v0.4s ,v28.4s - sqrshl v1.4s, v1.4s ,v28.4s - sqrshl v2.4s, v2.4s ,v28.4s - sqrshl v3.4s, v3.4s ,v28.4s - sqrshl v4.4s, v4.4s ,v28.4s - sqrshl v5.4s, v5.4s ,v28.4s - sqrshl v6.4s, v6.4s ,v28.4s - sqrshl v7.4s, v7.4s ,v28.4s - sqrshl v8.4s, v8.4s ,v28.4s - sqrshl v9.4s, v9.4s ,v28.4s - sqrshl v10.4s, v10.4s ,v28.4s - sqrshl v11.4s, v11.4s ,v28.4s - sqrshl v12.4s, v12.4s ,v28.4s - sqrshl v13.4s, v13.4s ,v28.4s - sqrshl v14.4s, v14.4s ,v28.4s - sqrshl v15.4s, v15.4s ,v28.4s - add v0.4s, v0.4s ,v29.4s - add v1.4s, v1.4s ,v29.4s - add v2.4s, v2.4s ,v29.4s - add v3.4s, v3.4s ,v29.4s - add v4.4s, v4.4s ,v29.4s - add v5.4s, v5.4s ,v29.4s - add v6.4s, v6.4s ,v29.4s - add v7.4s, v7.4s ,v29.4s - add v8.4s, v8.4s ,v29.4s - add v9.4s, v9.4s ,v29.4s - add v10.4s, v10.4s ,v29.4s - add v11.4s, v11.4s ,v29.4s - add v12.4s, v12.4s ,v29.4s - add v13.4s, v13.4s ,v29.4s - add v14.4s, v14.4s ,v29.4s - add v15.4s, v15.4s ,v29.4s - smax v0.4s, v0.4s ,v30.4s - smax v1.4s, v1.4s ,v30.4s - smax v2.4s, v2.4s ,v30.4s - smax v3.4s, v3.4s ,v30.4s - smax v4.4s, v4.4s ,v30.4s - smax v5.4s, v5.4s ,v30.4s - smax v6.4s, v6.4s ,v30.4s - smax v7.4s, v7.4s ,v30.4s - smax v8.4s, v8.4s ,v30.4s - smax v9.4s, v9.4s ,v30.4s - smax v10.4s, v10.4s ,v30.4s - smax v11.4s, v11.4s ,v30.4s - smax v12.4s, v12.4s ,v30.4s - smax v13.4s, v13.4s ,v30.4s - smax v14.4s, v14.4s ,v30.4s - smax v15.4s, v15.4s ,v30.4s - smin v0.4s, v0.4s ,v31.4s - smin v1.4s, v1.4s ,v31.4s - smin v2.4s, v2.4s ,v31.4s - smin v3.4s, v3.4s ,v31.4s - smin v4.4s, v4.4s ,v31.4s - smin v5.4s, v5.4s ,v31.4s - smin v6.4s, v6.4s ,v31.4s - smin v7.4s, v7.4s ,v31.4s - smin v8.4s, v8.4s ,v31.4s - smin v9.4s, v9.4s ,v31.4s - smin v10.4s, v10.4s ,v31.4s - smin v11.4s, v11.4s ,v31.4s - smin v12.4s, v12.4s ,v31.4s - smin v13.4s, v13.4s ,v31.4s - smin v14.4s, v14.4s ,v31.4s - smin v15.4s, v15.4s ,v31.4s + sqshl v0.4s, v0.4s, v26.4s + sqshl v1.4s, v1.4s, v26.4s + sqshl v2.4s, v2.4s, v26.4s + sqshl v3.4s, v3.4s, v26.4s + sqshl v4.4s, v4.4s, v26.4s + sqshl v5.4s, v5.4s, v26.4s + sqshl v6.4s, v6.4s, v26.4s + sqshl v7.4s, v7.4s, v26.4s + sqshl v8.4s, v8.4s, v26.4s + sqshl v9.4s, v9.4s, v26.4s + sqshl v10.4s, v10.4s, v26.4s + sqshl v11.4s, v11.4s, v26.4s + sqshl v12.4s, v12.4s, v26.4s + sqshl v13.4s, v13.4s, v26.4s + sqshl v14.4s, v14.4s, v26.4s + sqshl v15.4s, v15.4s, v26.4s + sqrdmulh v0.4s, v0.4s, v27.4s + sqrdmulh v1.4s, v1.4s, v27.4s + sqrdmulh v2.4s, v2.4s, v27.4s + sqrdmulh v3.4s, v3.4s, v27.4s + sqrdmulh v4.4s, v4.4s, v27.4s + sqrdmulh v5.4s, v5.4s, v27.4s + sqrdmulh v6.4s, v6.4s, v27.4s + sqrdmulh v7.4s, v7.4s, v27.4s + sqrdmulh v8.4s, v8.4s, v27.4s + sqrdmulh v9.4s, v9.4s, v27.4s + sqrdmulh v10.4s, v10.4s, v27.4s + sqrdmulh v11.4s, v11.4s, v27.4s + sqrdmulh v12.4s, v12.4s, v27.4s + sqrdmulh v13.4s, v13.4s, v27.4s + sqrdmulh v14.4s, v14.4s, v27.4s + sqrdmulh v15.4s, v15.4s, v27.4s + sqrshl v0.4s, v0.4s, v28.4s + sqrshl v1.4s, v1.4s, v28.4s + sqrshl v2.4s, v2.4s, v28.4s + sqrshl v3.4s, v3.4s, v28.4s + sqrshl v4.4s, v4.4s, v28.4s + sqrshl v5.4s, v5.4s, v28.4s + sqrshl v6.4s, v6.4s, v28.4s + sqrshl v7.4s, v7.4s, v28.4s + sqrshl v8.4s, v8.4s, v28.4s + sqrshl v9.4s, v9.4s, v28.4s + sqrshl v10.4s, v10.4s, v28.4s + sqrshl v11.4s, v11.4s, v28.4s + sqrshl v12.4s, v12.4s, v28.4s + sqrshl v13.4s, v13.4s, v28.4s + sqrshl v14.4s, v14.4s, v28.4s + sqrshl v15.4s, v15.4s, v28.4s + add v0.4s, v0.4s, v29.4s + add v1.4s, v1.4s, v29.4s + add v2.4s, v2.4s, v29.4s + add v3.4s, v3.4s, v29.4s + add v4.4s, v4.4s, v29.4s + add v5.4s, v5.4s, v29.4s + add v6.4s, v6.4s, v29.4s + add v7.4s, v7.4s, v29.4s + add v8.4s, v8.4s, v29.4s + add v9.4s, v9.4s, v29.4s + add v10.4s, v10.4s, v29.4s + add v11.4s, v11.4s, v29.4s + add v12.4s, v12.4s, v29.4s + add v13.4s, v13.4s, v29.4s + add v14.4s, v14.4s, v29.4s + add v15.4s, v15.4s, v29.4s + smax v0.4s, v0.4s, v30.4s + smax v1.4s, v1.4s, v30.4s + smax v2.4s, v2.4s, v30.4s + smax v3.4s, v3.4s, v30.4s + smax v4.4s, v4.4s, v30.4s + smax v5.4s, v5.4s, v30.4s + smax v6.4s, v6.4s, v30.4s + smax v7.4s, v7.4s, v30.4s + smax v8.4s, v8.4s, v30.4s + smax v9.4s, v9.4s, v30.4s + smax v10.4s, v10.4s, v30.4s + smax v11.4s, v11.4s, v30.4s + smax v12.4s, v12.4s, v30.4s + smax v13.4s, v13.4s, v30.4s + smax v14.4s, v14.4s, v30.4s + smax v15.4s, v15.4s, v30.4s + smin v0.4s, v0.4s, v31.4s + smin v1.4s, v1.4s, v31.4s + smin v2.4s, v2.4s, v31.4s + smin v3.4s, v3.4s, v31.4s + smin v4.4s, v4.4s, v31.4s + smin v5.4s, v5.4s, v31.4s + smin v6.4s, v6.4s, v31.4s + smin v7.4s, v7.4s, v31.4s + smin v8.4s, v8.4s, v31.4s + smin v9.4s, v9.4s, v31.4s + smin v10.4s, v10.4s, v31.4s + smin v11.4s, v11.4s, v31.4s + smin v12.4s, v12.4s, v31.4s + smin v13.4s, v13.4s, v31.4s + smin v14.4s, v14.4s, v31.4s + smin v15.4s, v15.4s, v31.4s sqxtn v0.4h, v0.4s sqxtn v1.4h, v1.4s @@ -391,54 +391,54 @@ ConvDwInt8Center: subs x20, x20, #1 bne LoopKh8 - sqshl v0.4s, v0.4s ,v26.4s - sqshl v1.4s, v1.4s ,v26.4s - sqshl v2.4s, v2.4s ,v26.4s - sqshl v3.4s, v3.4s ,v26.4s - sqshl v4.4s, v4.4s ,v26.4s - sqshl v5.4s, v5.4s ,v26.4s - sqshl v6.4s, v6.4s ,v26.4s - sqshl v7.4s, v7.4s ,v26.4s - sqrdmulh v0.4s, v0.4s ,v27.4s - sqrdmulh v1.4s, v1.4s ,v27.4s - sqrdmulh v2.4s, v2.4s ,v27.4s - sqrdmulh v3.4s, v3.4s ,v27.4s - sqrdmulh v4.4s, v4.4s ,v27.4s - sqrdmulh v5.4s, v5.4s ,v27.4s - sqrdmulh v6.4s, v6.4s ,v27.4s - sqrdmulh v7.4s, v7.4s ,v27.4s - sqrshl v0.4s, v0.4s ,v28.4s - sqrshl v1.4s, v1.4s ,v28.4s - sqrshl v2.4s, v2.4s ,v28.4s - sqrshl v3.4s, v3.4s ,v28.4s - sqrshl v4.4s, v4.4s ,v28.4s - sqrshl v5.4s, v5.4s ,v28.4s - sqrshl v6.4s, v6.4s ,v28.4s - sqrshl v7.4s, v7.4s ,v28.4s - add v0.4s, v0.4s ,v29.4s - add v1.4s, v1.4s ,v29.4s - add v2.4s, v2.4s ,v29.4s - add v3.4s, v3.4s ,v29.4s - add v4.4s, v4.4s ,v29.4s - add v5.4s, v5.4s ,v29.4s - add v6.4s, v6.4s ,v29.4s - add v7.4s, v7.4s ,v29.4s - smax v0.4s, v0.4s ,v30.4s - smax v1.4s, v1.4s ,v30.4s - smax v2.4s, v2.4s ,v30.4s - smax v3.4s, v3.4s ,v30.4s - smax v4.4s, v4.4s ,v30.4s - smax v5.4s, v5.4s ,v30.4s - smax v6.4s, v6.4s ,v30.4s - smax v7.4s, v7.4s ,v30.4s - smin v0.4s, v0.4s ,v31.4s - smin v1.4s, v1.4s ,v31.4s - smin v2.4s, v2.4s ,v31.4s - smin v3.4s, v3.4s ,v31.4s - smin v4.4s, v4.4s ,v31.4s - smin v5.4s, v5.4s ,v31.4s - smin v6.4s, v6.4s ,v31.4s - smin v7.4s, v7.4s ,v31.4s + sqshl v0.4s, v0.4s, v26.4s + sqshl v1.4s, v1.4s, v26.4s + sqshl v2.4s, v2.4s, v26.4s + sqshl v3.4s, v3.4s, v26.4s + sqshl v4.4s, v4.4s, v26.4s + sqshl v5.4s, v5.4s, v26.4s + sqshl v6.4s, v6.4s, v26.4s + sqshl v7.4s, v7.4s, v26.4s + sqrdmulh v0.4s, v0.4s, v27.4s + sqrdmulh v1.4s, v1.4s, v27.4s + sqrdmulh v2.4s, v2.4s, v27.4s + sqrdmulh v3.4s, v3.4s, v27.4s + sqrdmulh v4.4s, v4.4s, v27.4s + sqrdmulh v5.4s, v5.4s, v27.4s + sqrdmulh v6.4s, v6.4s, v27.4s + sqrdmulh v7.4s, v7.4s, v27.4s + sqrshl v0.4s, v0.4s, v28.4s + sqrshl v1.4s, v1.4s, v28.4s + sqrshl v2.4s, v2.4s, v28.4s + sqrshl v3.4s, v3.4s, v28.4s + sqrshl v4.4s, v4.4s, v28.4s + sqrshl v5.4s, v5.4s, v28.4s + sqrshl v6.4s, v6.4s, v28.4s + sqrshl v7.4s, v7.4s, v28.4s + add v0.4s, v0.4s, v29.4s + add v1.4s, v1.4s, v29.4s + add v2.4s, v2.4s, v29.4s + add v3.4s, v3.4s, v29.4s + add v4.4s, v4.4s, v29.4s + add v5.4s, v5.4s, v29.4s + add v6.4s, v6.4s, v29.4s + add v7.4s, v7.4s, v29.4s + smax v0.4s, v0.4s, v30.4s + smax v1.4s, v1.4s, v30.4s + smax v2.4s, v2.4s, v30.4s + smax v3.4s, v3.4s, v30.4s + smax v4.4s, v4.4s, v30.4s + smax v5.4s, v5.4s, v30.4s + smax v6.4s, v6.4s, v30.4s + smax v7.4s, v7.4s, v30.4s + smin v0.4s, v0.4s, v31.4s + smin v1.4s, v1.4s, v31.4s + smin v2.4s, v2.4s, v31.4s + smin v3.4s, v3.4s, v31.4s + smin v4.4s, v4.4s, v31.4s + smin v5.4s, v5.4s, v31.4s + smin v6.4s, v6.4s, v31.4s + smin v7.4s, v7.4s, v31.4s sqxtn v0.4h, v0.4s sqxtn v1.4h, v1.4s @@ -524,12 +524,12 @@ ConvDwInt8Center: subs x20, x20, #1 bne LoopKh - sqshl v0.4s, v0.4s ,v26.4s - sqrdmulh v0.4s, v0.4s ,v27.4s - sqrshl v0.4s, v0.4s ,v28.4s - add v0.4s, v0.4s ,v29.4s - smax v0.4s, v0.4s ,v30.4s - smin v0.4s, v0.4s ,v31.4s + sqshl v0.4s, v0.4s, v26.4s + sqrdmulh v0.4s, v0.4s, v27.4s + sqrshl v0.4s, v0.4s, v28.4s + add v0.4s, v0.4s, v29.4s + smax v0.4s, v0.4s, v30.4s + smin v0.4s, v0.4s, v31.4s sqxtn v0.4h, v0.4s sqxtn v0.8b, v0.8h diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmFp32_8x8.S b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmFp32_8x8.S index be649b0e58..6373bb7132 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmFp32_8x8.S +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmFp32_8x8.S @@ -268,40 +268,40 @@ IndirectGemmStart: Relu6: movi v1.4s, #6 scvtf v1.4s, v1.4s - fmin v16.4s, v16.4s ,v1.4s - fmin v17.4s, v17.4s ,v1.4s - fmin v18.4s, v18.4s ,v1.4s - fmin v19.4s, v19.4s ,v1.4s - fmin v20.4s, v20.4s ,v1.4s - fmin v21.4s, v21.4s ,v1.4s - fmin v22.4s, v22.4s ,v1.4s - fmin v23.4s, v23.4s ,v1.4s - fmin v24.4s, v24.4s ,v1.4s - fmin v25.4s, v25.4s ,v1.4s - fmin v26.4s, v26.4s ,v1.4s - fmin v27.4s, v27.4s ,v1.4s - fmin v28.4s, v28.4s ,v1.4s - fmin v29.4s, v29.4s ,v1.4s - fmin v30.4s, v30.4s ,v1.4s - fmin v31.4s, v31.4s ,v1.4s + fmin v16.4s, v16.4s, v1.4s + fmin v17.4s, v17.4s, v1.4s + fmin v18.4s, v18.4s, v1.4s + fmin v19.4s, v19.4s, v1.4s + fmin v20.4s, v20.4s, v1.4s + fmin v21.4s, v21.4s, v1.4s + fmin v22.4s, v22.4s, v1.4s + fmin v23.4s, v23.4s, v1.4s + fmin v24.4s, v24.4s, v1.4s + fmin v25.4s, v25.4s, v1.4s + fmin v26.4s, v26.4s, v1.4s + fmin v27.4s, v27.4s, v1.4s + fmin v28.4s, v28.4s, v1.4s + fmin v29.4s, v29.4s, v1.4s + fmin v30.4s, v30.4s, v1.4s + fmin v31.4s, v31.4s, v1.4s Relu: dup v0.4s, wzr - fmax v16.4s, v16.4s ,v0.4s - fmax v17.4s, v17.4s ,v0.4s - fmax v18.4s, v18.4s ,v0.4s - fmax v19.4s, v19.4s ,v0.4s - fmax v20.4s, v20.4s ,v0.4s - fmax v21.4s, v21.4s ,v0.4s - fmax v22.4s, v22.4s ,v0.4s - fmax v23.4s, v23.4s ,v0.4s - fmax v24.4s, v24.4s ,v0.4s - fmax v25.4s, v25.4s ,v0.4s - fmax v26.4s, v26.4s ,v0.4s - fmax v27.4s, v27.4s ,v0.4s - fmax v28.4s, v28.4s ,v0.4s - fmax v29.4s, v29.4s ,v0.4s - fmax v30.4s, v30.4s ,v0.4s - fmax v31.4s, v31.4s ,v0.4s + fmax v16.4s, v16.4s, v0.4s + fmax v17.4s, v17.4s, v0.4s + fmax v18.4s, v18.4s, v0.4s + fmax v19.4s, v19.4s, v0.4s + fmax v20.4s, v20.4s, v0.4s + fmax v21.4s, v21.4s, v0.4s + fmax v22.4s, v22.4s, v0.4s + fmax v23.4s, v23.4s, v0.4s + fmax v24.4s, v24.4s, v0.4s + fmax v25.4s, v25.4s, v0.4s + fmax v26.4s, v26.4s, v0.4s + fmax v27.4s, v27.4s, v0.4s + fmax v28.4s, v28.4s, v0.4s + fmax v29.4s, v29.4s, v0.4s + fmax v30.4s, v30.4s, v0.4s + fmax v31.4s, v31.4s, v0.4s WriteStart: cbnz x9, WriteC4 @@ -595,24 +595,24 @@ IndirectGemmStart: Relu6Half: movi v1.4s, #6 scvtf v1.4s, v1.4s - fmin v16.4s, v16.4s ,v1.4s - fmin v18.4s, v18.4s ,v1.4s - fmin v20.4s, v20.4s ,v1.4s - fmin v22.4s, v22.4s ,v1.4s - fmin v24.4s, v24.4s ,v1.4s - fmin v26.4s, v26.4s ,v1.4s - fmin v28.4s, v28.4s ,v1.4s - fmin v30.4s, v30.4s ,v1.4s + fmin v16.4s, v16.4s, v1.4s + fmin v18.4s, v18.4s, v1.4s + fmin v20.4s, v20.4s, v1.4s + fmin v22.4s, v22.4s, v1.4s + fmin v24.4s, v24.4s, v1.4s + fmin v26.4s, v26.4s, v1.4s + fmin v28.4s, v28.4s, v1.4s + fmin v30.4s, v30.4s, v1.4s ReluHalf: dup v0.4s, wzr - fmax v16.4s, v16.4s ,v0.4s - fmax v18.4s, v18.4s ,v0.4s - fmax v20.4s, v20.4s ,v0.4s - fmax v22.4s, v22.4s ,v0.4s - fmax v24.4s, v24.4s ,v0.4s - fmax v26.4s, v26.4s ,v0.4s - fmax v28.4s, v28.4s ,v0.4s - fmax v30.4s, v30.4s ,v0.4s + fmax v16.4s, v16.4s, v0.4s + fmax v18.4s, v18.4s, v0.4s + fmax v20.4s, v20.4s, v0.4s + fmax v22.4s, v22.4s, v0.4s + fmax v24.4s, v24.4s, v0.4s + fmax v26.4s, v26.4s, v0.4s + fmax v28.4s, v28.4s, v0.4s + fmax v30.4s, v30.4s, v0.4s WriteStartHalf: cbnz x9, Write4 diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmInt8_4x4.S b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmInt8_4x4.S index f70495e0e2..1843fed283 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmInt8_4x4.S +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/IndirectGemmInt8_4x4.S @@ -87,14 +87,15 @@ IndirectGemmInt8_4x4: ld1 {v2.16b, v3.16b}, [x12], #32 smull v10.8h, v0.8b, v6.8b smull v11.8h, v0.8b, v7.8b + saddlp v16.4s, v8.8h smlal2 v10.8h, v0.16b, v6.16b smlal2 v11.8h, v0.16b, v7.16b - saddlp v16.4s, v8.8h + saddlp v17.4s, v9.8h smull v14.8h, v1.8b, v6.8b smull v15.8h, v1.8b, v7.8b + saddlp v18.4s, v10.8h smlal2 v14.8h, v1.16b, v6.16b smlal2 v15.8h, v1.16b, v7.16b - saddlp v17.4s, v9.8h subs x13, x5, #1 beq LoopIcEnd @@ -102,55 +103,55 @@ IndirectGemmInt8_4x4: LoopIc: // load input for output 1-8 ld1 {v0.16b, v1.16b}, [x12], #32 - sadalp v18.4s, v10.8h + sadalp v19.4s, v11.8h smull v8.8h, v2.8b, v4.8b smull v9.8h, v2.8b, v5.8b - sadalp v19.4s, v11.8h + sadalp v20.4s, v12.8h smlal2 v8.8h, v2.16b, v4.16b smlal2 v9.8h, v2.16b, v5.16b - sadalp v20.4s, v12.8h + sadalp v21.4s, v13.8h smull v10.8h, v2.8b, v6.8b smull v11.8h, v2.8b, v7.8b - sadalp v21.4s, v13.8h + sadalp v22.4s, v14.8h smlal2 v10.8h, v2.16b, v6.16b smlal2 v11.8h, v2.16b, v7.16b - sadalp v22.4s, v14.8h + sadalp v23.4s, v15.8h smull v12.8h, v3.8b, v4.8b smull v13.8h, v3.8b, v5.8b - sadalp v23.4s, v15.8h + sadalp v24.4s, v8.8h smlal2 v12.8h, v3.16b, v4.16b smlal2 v13.8h, v3.16b, v5.16b - sadalp v24.4s, v8.8h ld1 {v4.16b, v5.16b}, [x2], #32 + sadalp v25.4s, v9.8h smull v14.8h, v3.8b, v6.8b smull v15.8h, v3.8b, v7.8b - sadalp v25.4s, v9.8h + sadalp v26.4s, v10.8h smlal2 v14.8h, v3.16b, v6.16b smlal2 v15.8h, v3.16b, v7.16b - sadalp v26.4s, v10.8h ld1 {v6.16b, v7.16b}, [x2], #32 + sadalp v27.4s, v11.8h smull v8.8h, v0.8b, v4.8b smull v9.8h, v0.8b, v5.8b - sadalp v27.4s, v11.8h + sadalp v28.4s, v12.8h smlal2 v8.8h, v0.16b, v4.16b smlal2 v9.8h, v0.16b, v5.16b - sadalp v28.4s, v12.8h ld1 {v2.16b, v3.16b}, [x12], #32 + sadalp v29.4s, v13.8h smull v12.8h, v1.8b, v4.8b smull v13.8h, v1.8b, v5.8b - sadalp v29.4s, v13.8h + sadalp v30.4s, v14.8h smlal2 v12.8h, v1.16b, v4.16b smlal2 v13.8h, v1.16b, v5.16b - sadalp v30.4s, v14.8h + sadalp v31.4s, v15.8h smull v10.8h, v0.8b, v6.8b smull v11.8h, v0.8b, v7.8b - sadalp v31.4s, v15.8h + sadalp v16.4s, v8.8h smlal2 v10.8h, v0.16b, v6.16b smlal2 v11.8h, v0.16b, v7.16b - sadalp v16.4s, v8.8h + sadalp v17.4s, v9.8h smull v14.8h, v1.8b, v6.8b smull v15.8h, v1.8b, v7.8b - sadalp v17.4s, v9.8h + saddlp v18.4s, v10.8h smlal2 v14.8h, v1.16b, v6.16b smlal2 v15.8h, v1.16b, v7.16b @@ -158,33 +159,32 @@ IndirectGemmInt8_4x4: bne LoopIc LoopIcEnd: - sadalp v18.4s, v10.8h + sadalp v19.4s, v11.8h smull v8.8h, v2.8b, v4.8b smull v9.8h, v2.8b, v5.8b - sadalp v19.4s, v11.8h + sadalp v20.4s, v12.8h smlal2 v8.8h, v2.16b, v4.16b smlal2 v9.8h, v2.16b, v5.16b - sadalp v20.4s, v12.8h + sadalp v21.4s, v13.8h smull v10.8h, v2.8b, v6.8b smull v11.8h, v2.8b, v7.8b - sadalp v21.4s, v13.8h + sadalp v22.4s, v14.8h smlal2 v10.8h, v2.16b, v6.16b smlal2 v11.8h, v2.16b, v7.16b - sadalp v22.4s, v14.8h + sadalp v23.4s, v15.8h smull v12.8h, v3.8b, v4.8b smull v13.8h, v3.8b, v5.8b - sadalp v23.4s, v15.8h + sadalp v24.4s, v8.8h smlal2 v12.8h, v3.16b, v4.16b smlal2 v13.8h, v3.16b, v5.16b - sadalp v24.4s, v8.8h + sadalp v25.4s, v9.8h smull v14.8h, v3.8b, v6.8b smull v15.8h, v3.8b, v7.8b - sadalp v25.4s, v9.8h + sadalp v26.4s, v10.8h smlal2 v14.8h, v3.16b, v6.16b smlal2 v15.8h, v3.16b, v7.16b - sadalp v26.4s, v10.8h sadalp v27.4s, v11.8h - sadalp v28.4s ,v12.8h + sadalp v28.4s, v12.8h sadalp v29.4s, v13.8h sadalp v30.4s, v14.8h sadalp v31.4s, v15.8h @@ -204,6 +204,7 @@ IndirectGemmInt8_4x4: addp v26.4s, v26.4s, v27.4s addp v28.4s, v28.4s, v29.4s addp v30.4s, v30.4s, v31.4s + dup v12.4s, wzr cbz x3, NoReadBias ld1 {v12.4s}, [x3] NoReadBias: @@ -221,40 +222,40 @@ IndirectGemmInt8_4x4: add v28.4s, v28.4s, v12.4s dup v2.4s, w18 - sqshl v16.4s, v16.4s ,v2.4s - sqshl v20.4s, v20.4s ,v2.4s - sqshl v24.4s, v24.4s ,v2.4s - sqshl v28.4s, v28.4s ,v2.4s + sqshl v16.4s, v16.4s, v2.4s + sqshl v20.4s, v20.4s, v2.4s + sqshl v24.4s, v24.4s, v2.4s + sqshl v28.4s, v28.4s, v2.4s dup v3.4s, w17 - sqrdmulh v16.4s, v16.4s ,v3.4s - sqrdmulh v20.4s, v20.4s ,v3.4s - sqrdmulh v24.4s, v24.4s ,v3.4s - sqrdmulh v28.4s, v28.4s ,v3.4s + sqrdmulh v16.4s, v16.4s, v3.4s + sqrdmulh v20.4s, v20.4s, v3.4s + sqrdmulh v24.4s, v24.4s, v3.4s + sqrdmulh v28.4s, v28.4s, v3.4s dup v4.4s, w19 - sqrshl v16.4s, v16.4s ,v4.4s - sqrshl v20.4s, v20.4s ,v4.4s - sqrshl v24.4s, v24.4s ,v4.4s - sqrshl v28.4s, v28.4s ,v4.4s + sqrshl v16.4s, v16.4s, v4.4s + sqrshl v20.4s, v20.4s, v4.4s + sqrshl v24.4s, v24.4s, v4.4s + sqrshl v28.4s, v28.4s, v4.4s dup v5.4s, w16 - add v16.4s, v16.4s ,v5.4s - add v20.4s, v20.4s ,v5.4s - add v24.4s, v24.4s ,v5.4s - add v28.4s, v28.4s ,v5.4s + add v16.4s, v16.4s, v5.4s + add v20.4s, v20.4s, v5.4s + add v24.4s, v24.4s, v5.4s + add v28.4s, v28.4s, v5.4s dup v0.4s, w8 - smax v16.4s, v16.4s ,v0.4s - smax v20.4s, v20.4s ,v0.4s - smax v24.4s, v24.4s ,v0.4s - smax v28.4s, v28.4s ,v0.4s + smax v16.4s, v16.4s, v0.4s + smax v20.4s, v20.4s, v0.4s + smax v24.4s, v24.4s, v0.4s + smax v28.4s, v28.4s, v0.4s dup v1.4s, w9 - smin v16.4s, v16.4s ,v1.4s - smin v20.4s, v20.4s ,v1.4s - smin v24.4s, v24.4s ,v1.4s - smin v28.4s, v28.4s ,v1.4s + smin v16.4s, v16.4s, v1.4s + smin v20.4s, v20.4s, v1.4s + smin v24.4s, v24.4s, v1.4s + smin v28.4s, v28.4s, v1.4s sqxtn v13.4h, v16.4s sqxtn2 v13.8h, v20.4s diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/matmul.s b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/matmul.s index b33c71d34e..2231e8debf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/matmul.s +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/arm64/matmul.s @@ -1,9 +1,9 @@ #ifdef __aarch64__ .text .align 5 - .global MatMulFloatNeon64 + .global MatmulFloatNeon64 #ifndef __APPLE__ - .type MatMulFloatNeon64, %function + .type MatmulFloatNeon64, %function #endif // A: LM [row_8 * depth] col_8_major @@ -46,41 +46,39 @@ // accumulators 8x8 block ///////////////////////////////////////////////////////////////////////////////// // -// void MatMulFloatNeon64(const float *a, const float *b, float *c, const float *bias, float maxf, float minf, int depth, int row, int col) +// void MatmulFloatNeon64(const float *a, const float *b, float *c, const float *bias, int act_type, int depth, int row, int col) // x0: a // x1: b // x2: c // x3: bias -// v0.s[0]: maxf -// v1.s[0]: minf -// w4: depth -// w5: row -// w6: col +// w4: act_type +// w5: depth +// w6: row +// w7: col -MatMulFloatNeon64: +MatmulFloatNeon64: sub sp, sp, #128 st1 {v8.4s, v9.4s, v10.4s, v11.4s}, [sp], #64 st1 {v12.4s, v13.4s, v14.4s, v15.4s}, [sp], #64 - mov w7, v0.s[0] - mov w8, v1.s[0] - mov w9, 0 // rm col offset - mov w10, 0 // lm row offset + mov w9, #0 // rm col offset + mov w10, #0 // lm row offset mov w18, #32 // sizeof(float)*8 - mul w15, w4, w18 // the stride of lm/rm: sizeof(float)*8*depth - + mul w15, w5, w18 // the stride of lm/rm: sizeof(float)*8*depth + mov x11, x3 // bias flag L1: - cmp w9, w6 + cmp w9, w7 beq End1 - mov w10, 0 // reset lm row offset + mov w10, #0 // reset lm row offset mov x12, x0 // reload lm ptr - mov x14, x3 // reload bias ptr L2: cmp w10, w6 beq End2 - mov w13, w4 // reload depth + mov x16, x1 // reload rm ptr + mov w13, w5 // reload depth + mov x14, x3 // reload bias ptr dup v16.4s, wzr dup v17.4s, wzr dup v18.4s, wzr @@ -103,7 +101,7 @@ OptLoopMul4: blt CommLoopMul ld1 {v0.4s, v1.4s}, [x12], #32 - ld1 {v8.4s, v9.4s}, [x1], #32 + ld1 {v8.4s, v9.4s}, [x16], #32 fmla v16.4s, v8.4s, v0.s[0] fmla v17.4s, v9.4s, v0.s[0] fmla v18.4s, v8.4s, v0.s[1] @@ -112,7 +110,7 @@ OptLoopMul4: fmla v21.4s, v9.4s, v0.s[2] fmla v22.4s, v8.4s, v0.s[3] fmla v23.4s, v9.4s, v0.s[3] - ld1 {v10.4s, v11.4s}, [x1], #32 + ld1 {v10.4s, v11.4s}, [x16], #32 fmla v24.4s, v8.4s, v1.s[0] fmla v25.4s, v9.4s, v1.s[0] fmla v26.4s, v8.4s, v1.s[1] @@ -130,7 +128,7 @@ OptLoopMul4: fmla v21.4s, v11.4s, v2.s[2] fmla v22.4s, v10.4s, v2.s[3] fmla v23.4s, v11.4s, v2.s[3] - ld1 {v12.4s, v13.4s}, [x1], #32 + ld1 {v12.4s, v13.4s}, [x16], #32 fmla v24.4s, v10.4s, v3.s[0] fmla v25.4s, v11.4s, v3.s[0] fmla v26.4s, v10.4s, v3.s[1] @@ -153,7 +151,7 @@ OptLoopMul4: fmla v25.4s, v13.4s, v5.s[0] fmla v26.4s, v12.4s, v5.s[1] fmla v27.4s, v13.4s, v5.s[1] - ld1 {v14.4s, v15.4s}, [x1], #32 + ld1 {v14.4s, v15.4s}, [x16], #32 fmla v28.4s, v12.4s, v5.s[2] fmla v29.4s, v13.4s, v5.s[2] fmla v30.4s, v12.4s, v5.s[3] @@ -182,7 +180,7 @@ CommLoopMul: blt Bias ld1 {v0.4s, v1.4s}, [x12], #32 - ld1 {v2.4s, v3.4s}, [x1], #32 + ld1 {v2.4s, v3.4s}, [x16], #32 fmla v16.4s, v2.4s, v0.s[0] fmla v17.4s, v3.4s, v0.s[0] fmla v18.4s, v2.4s, v0.s[1] @@ -203,8 +201,7 @@ CommLoopMul: b CommLoopMul Bias: - cmp x3, #0 - beq Relu + cbz x11, Activation ld1 {v0.4s}, [x14], #16 ld1 {v1.4s}, [x14], #16 fadd v16.4s, v16.4s, v0.4s @@ -224,9 +221,34 @@ Bias: fadd v30.4s, v30.4s, v0.4s fadd v31.4s, v31.4s, v1.4s +Activation: + cmp w4, #2 + beq Relu6 + cmp w4, #1 + beq Relu + b TransToOut +Relu6: + mov w8, #6 + dup v15.4s, w8 + scvtf v15.4s, v15.4s + fmin v16.4s, v16.4s, v15.4s + fmin v17.4s, v17.4s, v15.4s + fmin v18.4s, v18.4s, v15.4s + fmin v19.4s, v19.4s, v15.4s + fmin v20.4s, v20.4s, v15.4s + fmin v21.4s, v21.4s, v15.4s + fmin v22.4s, v22.4s, v15.4s + fmin v23.4s, v23.4s, v15.4s + fmin v24.4s, v24.4s, v15.4s + fmin v25.4s, v25.4s, v15.4s + fmin v26.4s, v26.4s, v15.4s + fmin v27.4s, v27.4s, v15.4s + fmin v28.4s, v28.4s, v15.4s + fmin v29.4s, v29.4s, v15.4s + fmin v30.4s, v30.4s, v15.4s + fmin v31.4s, v31.4s, v15.4s Relu: - dup v15.4s, w7 - dup v14.4s, w8 + dup v14.4s, wzr fmax v16.4s, v16.4s, v14.4s fmax v17.4s, v17.4s, v14.4s fmax v18.4s, v18.4s, v14.4s @@ -244,24 +266,6 @@ Relu: fmax v30.4s, v30.4s, v14.4s fmax v31.4s, v31.4s, v14.4s - fmin v16.4s, v16.4s, v15.4s - fmin v17.4s, v17.4s, v15.4s - fmin v18.4s, v18.4s, v15.4s - fmin v19.4s, v19.4s, v15.4s - fmin v20.4s, v20.4s, v15.4s - fmin v20.4s, v20.4s, v15.4s - fmin v21.4s, v21.4s, v15.4s - fmin v22.4s, v22.4s, v15.4s - fmin v23.4s, v23.4s, v15.4s - fmin v24.4s, v24.4s, v15.4s - fmin v25.4s, v25.4s, v15.4s - fmin v26.4s, v26.4s, v15.4s - fmin v27.4s, v27.4s, v15.4s - fmin v28.4s, v28.4s, v15.4s - fmin v29.4s, v29.4s, v15.4s - fmin v30.4s, v30.4s, v15.4s - fmin v31.4s, v31.4s, v15.4s - TransToOut: st1 {v16.4s}, [x2], #16 st1 {v17.4s}, [x2], #16 @@ -280,11 +284,13 @@ TransToOut: st1 {v30.4s}, [x2], #16 st1 {v31.4s}, [x2], #16 - add w10, w10, #8 // lhs row offset + 8 + add w10, w10, #8 // lm row offset + 8 b L2 End2: - add w9, w9, #8 // rhs col offset + 8 + add w9, w9, #8 // rm col offset + 8 + add x1, x1, x15 // rm ptr + stride + add x3, x3, x18 // bias ptr + stride b L1 End1: diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/opt/IndirectGemmInt8_24x4_dp.S b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/opt/IndirectGemmInt8_24x4_dp.S index 278b4376b2..ca7c73e62e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/opt/IndirectGemmInt8_24x4_dp.S +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/assembly/opt/IndirectGemmInt8_24x4_dp.S @@ -277,160 +277,160 @@ IndirectGemmInt8_24x4_dp: Quantization: dup v2.4s, w18 - sqshl v8.4s, v8.4s ,v2.4s - sqshl v9.4s, v9.4s ,v2.4s - sqshl v10.4s, v10.4s ,v2.4s - sqshl v11.4s, v11.4s ,v2.4s - sqshl v12.4s, v12.4s ,v2.4s - sqshl v13.4s, v13.4s ,v2.4s - sqshl v14.4s, v14.4s ,v2.4s - sqshl v15.4s, v15.4s ,v2.4s - sqshl v16.4s, v16.4s ,v2.4s - sqshl v17.4s, v17.4s ,v2.4s - sqshl v18.4s, v18.4s ,v2.4s - sqshl v19.4s, v19.4s ,v2.4s - sqshl v20.4s, v20.4s ,v2.4s - sqshl v21.4s, v21.4s ,v2.4s - sqshl v22.4s, v22.4s ,v2.4s - sqshl v23.4s, v23.4s ,v2.4s - sqshl v24.4s, v24.4s ,v2.4s - sqshl v25.4s, v25.4s ,v2.4s - sqshl v26.4s, v26.4s ,v2.4s - sqshl v27.4s, v27.4s ,v2.4s - sqshl v28.4s, v28.4s ,v2.4s - sqshl v29.4s, v29.4s ,v2.4s - sqshl v30.4s, v30.4s ,v2.4s - sqshl v31.4s, v31.4s ,v2.4s + sqshl v8.4s, v8.4s, v2.4s + sqshl v9.4s, v9.4s, v2.4s + sqshl v10.4s, v10.4s, v2.4s + sqshl v11.4s, v11.4s, v2.4s + sqshl v12.4s, v12.4s, v2.4s + sqshl v13.4s, v13.4s, v2.4s + sqshl v14.4s, v14.4s, v2.4s + sqshl v15.4s, v15.4s, v2.4s + sqshl v16.4s, v16.4s, v2.4s + sqshl v17.4s, v17.4s, v2.4s + sqshl v18.4s, v18.4s, v2.4s + sqshl v19.4s, v19.4s, v2.4s + sqshl v20.4s, v20.4s, v2.4s + sqshl v21.4s, v21.4s, v2.4s + sqshl v22.4s, v22.4s, v2.4s + sqshl v23.4s, v23.4s, v2.4s + sqshl v24.4s, v24.4s, v2.4s + sqshl v25.4s, v25.4s, v2.4s + sqshl v26.4s, v26.4s, v2.4s + sqshl v27.4s, v27.4s, v2.4s + sqshl v28.4s, v28.4s, v2.4s + sqshl v29.4s, v29.4s, v2.4s + sqshl v30.4s, v30.4s, v2.4s + sqshl v31.4s, v31.4s, v2.4s dup v3.4s, w17 - sqrdmulh v8.4s, v8.4s ,v3.4s - sqrdmulh v9.4s, v9.4s ,v3.4s - sqrdmulh v10.4s, v10.4s ,v3.4s - sqrdmulh v11.4s, v11.4s ,v3.4s - sqrdmulh v12.4s, v12.4s ,v3.4s - sqrdmulh v13.4s, v13.4s ,v3.4s - sqrdmulh v14.4s, v14.4s ,v3.4s - sqrdmulh v15.4s, v15.4s ,v3.4s - sqrdmulh v16.4s, v16.4s ,v3.4s - sqrdmulh v17.4s, v17.4s ,v3.4s - sqrdmulh v18.4s, v18.4s ,v3.4s - sqrdmulh v19.4s, v19.4s ,v3.4s - sqrdmulh v20.4s, v20.4s ,v3.4s - sqrdmulh v21.4s, v21.4s ,v3.4s - sqrdmulh v22.4s, v22.4s ,v3.4s - sqrdmulh v23.4s, v23.4s ,v3.4s - sqrdmulh v24.4s, v24.4s ,v3.4s - sqrdmulh v25.4s, v25.4s ,v3.4s - sqrdmulh v26.4s, v26.4s ,v3.4s - sqrdmulh v27.4s, v27.4s ,v3.4s - sqrdmulh v28.4s, v28.4s ,v3.4s - sqrdmulh v29.4s, v29.4s ,v3.4s - sqrdmulh v30.4s, v30.4s ,v3.4s - sqrdmulh v31.4s, v31.4s ,v3.4s + sqrdmulh v8.4s, v8.4s, v3.4s + sqrdmulh v9.4s, v9.4s, v3.4s + sqrdmulh v10.4s, v10.4s, v3.4s + sqrdmulh v11.4s, v11.4s, v3.4s + sqrdmulh v12.4s, v12.4s, v3.4s + sqrdmulh v13.4s, v13.4s, v3.4s + sqrdmulh v14.4s, v14.4s, v3.4s + sqrdmulh v15.4s, v15.4s, v3.4s + sqrdmulh v16.4s, v16.4s, v3.4s + sqrdmulh v17.4s, v17.4s, v3.4s + sqrdmulh v18.4s, v18.4s, v3.4s + sqrdmulh v19.4s, v19.4s, v3.4s + sqrdmulh v20.4s, v20.4s, v3.4s + sqrdmulh v21.4s, v21.4s, v3.4s + sqrdmulh v22.4s, v22.4s, v3.4s + sqrdmulh v23.4s, v23.4s, v3.4s + sqrdmulh v24.4s, v24.4s, v3.4s + sqrdmulh v25.4s, v25.4s, v3.4s + sqrdmulh v26.4s, v26.4s, v3.4s + sqrdmulh v27.4s, v27.4s, v3.4s + sqrdmulh v28.4s, v28.4s, v3.4s + sqrdmulh v29.4s, v29.4s, v3.4s + sqrdmulh v30.4s, v30.4s, v3.4s + sqrdmulh v31.4s, v31.4s, v3.4s dup v4.4s, w19 - sqrshl v8.4s, v8.4s ,v4.4s - sqrshl v9.4s, v9.4s ,v4.4s - sqrshl v10.4s, v10.4s ,v4.4s - sqrshl v11.4s, v11.4s ,v4.4s - sqrshl v12.4s, v12.4s ,v4.4s - sqrshl v13.4s, v13.4s ,v4.4s - sqrshl v14.4s, v14.4s ,v4.4s - sqrshl v15.4s, v15.4s ,v4.4s - sqrshl v16.4s, v16.4s ,v4.4s - sqrshl v17.4s, v17.4s ,v4.4s - sqrshl v18.4s, v18.4s ,v4.4s - sqrshl v19.4s, v19.4s ,v4.4s - sqrshl v20.4s, v20.4s ,v4.4s - sqrshl v21.4s, v21.4s ,v4.4s - sqrshl v22.4s, v22.4s ,v4.4s - sqrshl v23.4s, v23.4s ,v4.4s - sqrshl v24.4s, v24.4s ,v4.4s - sqrshl v25.4s, v25.4s ,v4.4s - sqrshl v26.4s, v26.4s ,v4.4s - sqrshl v27.4s, v27.4s ,v4.4s - sqrshl v28.4s, v28.4s ,v4.4s - sqrshl v29.4s, v29.4s ,v4.4s - sqrshl v30.4s, v30.4s ,v4.4s - sqrshl v31.4s, v31.4s ,v4.4s + sqrshl v8.4s, v8.4s, v4.4s + sqrshl v9.4s, v9.4s, v4.4s + sqrshl v10.4s, v10.4s, v4.4s + sqrshl v11.4s, v11.4s, v4.4s + sqrshl v12.4s, v12.4s, v4.4s + sqrshl v13.4s, v13.4s, v4.4s + sqrshl v14.4s, v14.4s, v4.4s + sqrshl v15.4s, v15.4s, v4.4s + sqrshl v16.4s, v16.4s, v4.4s + sqrshl v17.4s, v17.4s, v4.4s + sqrshl v18.4s, v18.4s, v4.4s + sqrshl v19.4s, v19.4s, v4.4s + sqrshl v20.4s, v20.4s, v4.4s + sqrshl v21.4s, v21.4s, v4.4s + sqrshl v22.4s, v22.4s, v4.4s + sqrshl v23.4s, v23.4s, v4.4s + sqrshl v24.4s, v24.4s, v4.4s + sqrshl v25.4s, v25.4s, v4.4s + sqrshl v26.4s, v26.4s, v4.4s + sqrshl v27.4s, v27.4s, v4.4s + sqrshl v28.4s, v28.4s, v4.4s + sqrshl v29.4s, v29.4s, v4.4s + sqrshl v30.4s, v30.4s, v4.4s + sqrshl v31.4s, v31.4s, v4.4s dup v5.4s, w16 - add v8.4s, v8.4s ,v5.4s - add v9.4s, v9.4s ,v5.4s - add v10.4s, v10.4s ,v5.4s - add v11.4s, v11.4s ,v5.4s - add v12.4s, v12.4s ,v5.4s - add v13.4s, v13.4s ,v5.4s - add v14.4s, v14.4s ,v5.4s - add v15.4s, v15.4s ,v5.4s - add v16.4s, v16.4s ,v5.4s - add v17.4s, v17.4s ,v5.4s - add v18.4s, v18.4s ,v5.4s - add v19.4s, v19.4s ,v5.4s - add v20.4s, v20.4s ,v5.4s - add v21.4s, v21.4s ,v5.4s - add v22.4s, v22.4s ,v5.4s - add v23.4s, v23.4s ,v5.4s - add v24.4s, v24.4s ,v5.4s - add v25.4s, v25.4s ,v5.4s - add v26.4s, v26.4s ,v5.4s - add v27.4s, v27.4s ,v5.4s - add v28.4s, v28.4s ,v5.4s - add v29.4s, v29.4s ,v5.4s - add v30.4s, v30.4s ,v5.4s - add v31.4s, v31.4s ,v5.4s + add v8.4s, v8.4s, v5.4s + add v9.4s, v9.4s, v5.4s + add v10.4s, v10.4s, v5.4s + add v11.4s, v11.4s, v5.4s + add v12.4s, v12.4s, v5.4s + add v13.4s, v13.4s, v5.4s + add v14.4s, v14.4s, v5.4s + add v15.4s, v15.4s, v5.4s + add v16.4s, v16.4s, v5.4s + add v17.4s, v17.4s, v5.4s + add v18.4s, v18.4s, v5.4s + add v19.4s, v19.4s, v5.4s + add v20.4s, v20.4s, v5.4s + add v21.4s, v21.4s, v5.4s + add v22.4s, v22.4s, v5.4s + add v23.4s, v23.4s, v5.4s + add v24.4s, v24.4s, v5.4s + add v25.4s, v25.4s, v5.4s + add v26.4s, v26.4s, v5.4s + add v27.4s, v27.4s, v5.4s + add v28.4s, v28.4s, v5.4s + add v29.4s, v29.4s, v5.4s + add v30.4s, v30.4s, v5.4s + add v31.4s, v31.4s, v5.4s dup v0.4s, w8 - smax v8.4s, v8.4s ,v0.4s - smax v9.4s, v9.4s ,v0.4s - smax v10.4s, v10.4s ,v0.4s - smax v11.4s, v11.4s ,v0.4s - smax v12.4s, v12.4s ,v0.4s - smax v13.4s, v13.4s ,v0.4s - smax v14.4s, v14.4s ,v0.4s - smax v15.4s, v15.4s ,v0.4s - smax v16.4s, v16.4s ,v0.4s - smax v17.4s, v17.4s ,v0.4s - smax v18.4s, v18.4s ,v0.4s - smax v19.4s, v19.4s ,v0.4s - smax v20.4s, v20.4s ,v0.4s - smax v21.4s, v21.4s ,v0.4s - smax v22.4s, v22.4s ,v0.4s - smax v23.4s, v23.4s ,v0.4s - smax v24.4s, v24.4s ,v0.4s - smax v25.4s, v25.4s ,v0.4s - smax v26.4s, v26.4s ,v0.4s - smax v27.4s, v27.4s ,v0.4s - smax v28.4s, v28.4s ,v0.4s - smax v29.4s, v29.4s ,v0.4s - smax v30.4s, v30.4s ,v0.4s - smax v31.4s, v31.4s ,v0.4s + smax v8.4s, v8.4s, v0.4s + smax v9.4s, v9.4s, v0.4s + smax v10.4s, v10.4s, v0.4s + smax v11.4s, v11.4s, v0.4s + smax v12.4s, v12.4s, v0.4s + smax v13.4s, v13.4s, v0.4s + smax v14.4s, v14.4s, v0.4s + smax v15.4s, v15.4s, v0.4s + smax v16.4s, v16.4s, v0.4s + smax v17.4s, v17.4s, v0.4s + smax v18.4s, v18.4s, v0.4s + smax v19.4s, v19.4s, v0.4s + smax v20.4s, v20.4s, v0.4s + smax v21.4s, v21.4s, v0.4s + smax v22.4s, v22.4s, v0.4s + smax v23.4s, v23.4s, v0.4s + smax v24.4s, v24.4s, v0.4s + smax v25.4s, v25.4s, v0.4s + smax v26.4s, v26.4s, v0.4s + smax v27.4s, v27.4s, v0.4s + smax v28.4s, v28.4s, v0.4s + smax v29.4s, v29.4s, v0.4s + smax v30.4s, v30.4s, v0.4s + smax v31.4s, v31.4s, v0.4s dup v1.4s, w9 - smin v8.4s, v8.4s ,v1.4s - smin v9.4s, v9.4s ,v1.4s - smin v10.4s, v10.4s ,v1.4s - smin v11.4s, v11.4s ,v1.4s - smin v12.4s, v12.4s ,v1.4s - smin v13.4s, v13.4s ,v1.4s - smin v14.4s, v14.4s ,v1.4s - smin v15.4s, v15.4s ,v1.4s - smin v16.4s, v16.4s ,v1.4s - smin v17.4s, v17.4s ,v1.4s - smin v18.4s, v18.4s ,v1.4s - smin v19.4s, v19.4s ,v1.4s - smin v20.4s, v20.4s ,v1.4s - smin v21.4s, v21.4s ,v1.4s - smin v22.4s, v22.4s ,v1.4s - smin v23.4s, v23.4s ,v1.4s - smin v24.4s, v24.4s ,v1.4s - smin v25.4s, v25.4s ,v1.4s - smin v26.4s, v26.4s ,v1.4s - smin v27.4s, v27.4s ,v1.4s - smin v28.4s, v28.4s ,v1.4s - smin v29.4s, v29.4s ,v1.4s - smin v30.4s, v30.4s ,v1.4s - smin v31.4s, v31.4s ,v1.4s + smin v8.4s, v8.4s, v1.4s + smin v9.4s, v9.4s, v1.4s + smin v10.4s, v10.4s, v1.4s + smin v11.4s, v11.4s, v1.4s + smin v12.4s, v12.4s, v1.4s + smin v13.4s, v13.4s, v1.4s + smin v14.4s, v14.4s, v1.4s + smin v15.4s, v15.4s, v1.4s + smin v16.4s, v16.4s, v1.4s + smin v17.4s, v17.4s, v1.4s + smin v18.4s, v18.4s, v1.4s + smin v19.4s, v19.4s, v1.4s + smin v20.4s, v20.4s, v1.4s + smin v21.4s, v21.4s, v1.4s + smin v22.4s, v22.4s, v1.4s + smin v23.4s, v23.4s, v1.4s + smin v24.4s, v24.4s, v1.4s + smin v25.4s, v25.4s, v1.4s + smin v26.4s, v26.4s, v1.4s + smin v27.4s, v27.4s, v1.4s + smin v28.4s, v28.4s, v1.4s + smin v29.4s, v29.4s, v1.4s + smin v30.4s, v30.4s, v1.4s + smin v31.4s, v31.4s, v1.4s sqxtn v6.4h, v8.4s sqxtn2 v6.8h, v9.4s diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.cc index e114f59cbf..5773292e1e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/batch_to_space.h" -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" +#include "nnacl/batch_to_space.h" +#include "nnacl/arithmetic_common.h" void BatchToSpaceNoCropForNHWC(const void *input, void *output, const int *in_shape, int out_n, const int *block, int data_size) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.h index 0cee0f071b..3e76096085 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_to_space.h @@ -15,16 +15,16 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_BATCH_TO_SPACE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_BATCH_TO_SPACE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define BATCH_TO_SPACE_BLOCK_SHAPE_SIZE 2 -#define BATCH_TO_SPACE_CROPS_SIZE 4 +#define BATCH_TO_SPACE_CROPS_SIZE 4 -struct BatchToSpaceParameter { - OpParameter op_parameter_; - int32_t block_shape_[BATCH_TO_SPACE_BLOCK_SHAPE_SIZE]; - int32_t crops_[BATCH_TO_SPACE_CROPS_SIZE]; -}; +typedef struct BatchToSpaceParameter { + OpParameter op_parameter_; + int32_t block_shape_[BATCH_TO_SPACE_BLOCK_SHAPE_SIZE]; + int32_t crops_[BATCH_TO_SPACE_CROPS_SIZE]; +} BatchToSpaceParameter; void BatchToSpaceNoCropForNHWC(const void *input, void *output, const int *in_shape, int out_n, const int *block, int data_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.cc index 7e83fded24..55487e7a09 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/common_func.h" -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/common_func.h" +#include "nnacl/quantization/fixed_point.h" #ifndef ENABLE_ARM64 void IndirectGemmFp32(float *output, const float *input, const float *weight, const float *bias, size_t step, int ic4, @@ -151,7 +151,7 @@ int8_t MinInt8(int8_t a, int8_t b) { return b ^ ((a ^ b) & -(a < b)); } int8_t MaxInt8(int8_t a, int8_t b) { return a ^ ((a ^ b) & -(a < b)); } -void ReluFp32(float *data, int ele_num) { +void ReluFp32(float *data, float *dst, int ele_num) { int four_block = UP_DIV(ele_num, C4NUM); for (int i = 0; i < four_block - 1; i++) { int index = i * C4NUM; @@ -159,7 +159,7 @@ void ReluFp32(float *data, int ele_num) { float32x4_t relu_data = vld1q_f32(data + index); float32x4_t zero_data = vdupq_n_f32(0); relu_data = vmaxq_f32(relu_data, zero_data); - vst1q_f32(data + index, relu_data); + vst1q_f32(dst + index, relu_data); #else data[index] = data[index] < 0 ? 0 : data[index]; data[index + 1] = data[index + 1] < 0 ? 0 : data[index + 1]; @@ -172,7 +172,7 @@ void ReluFp32(float *data, int ele_num) { } } -void Relu6Fp32(float *data, int ele_num) { +void Relu6Fp32(float *data, float *dst, int ele_num) { int four_block = UP_DIV(ele_num, C4NUM); for (int i = 0; i < four_block - 1; i++) { int index = i * C4NUM; @@ -182,7 +182,7 @@ void Relu6Fp32(float *data, int ele_num) { float32x4_t six_data = vdupq_n_f32(6); relu6_data = vmaxq_f32(relu6_data, zero_data); relu6_data = vminq_f32(relu6_data, six_data); - vst1q_f32(data + index, relu6_data); + vst1q_f32(dst + index, relu6_data); #else data[index] = data[index] < 0 ? 0 : data[index]; data[index] = data[index] > 6 ? 6 : data[index]; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.h index 82daa49f25..33f6256646 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/common_func.h @@ -20,8 +20,8 @@ #include #include #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/conv_parameter.h" #ifdef __cplusplus extern "C" { @@ -29,8 +29,8 @@ extern "C" { int8_t MinInt8(int8_t a, int8_t b); int8_t MaxInt8(int8_t a, int8_t b); -void ReluFp32(float *data, int ele_num); -void Relu6Fp32(float *data, int ele_num); +void ReluFp32(float *data, float *dst, int ele_num); +void Relu6Fp32(float *data, float *dst, int ele_num); void PostFuncInt8(const int *in, const int *bias, int8_t *out, int oc, int plane, int plane8, int32_t multiplier, int32_t left_shift, int32_t right_shift, int32_t zp, int8_t mini, int8_t maxi); void SimplePostFuncInt8(const int *in, int8_t *out, int oc, int plane, int plane8, int32_t multiplier, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/concat_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/concat_parameter.h index 5b998a4d2d..fba336b755 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/concat_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/concat_parameter.h @@ -17,13 +17,19 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CONCAT_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CONCAT_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -struct ConcatParameter { +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" + +typedef struct ConcatParameter { OpParameter op_parameter_; - ConcatQuantArg *concat_quant_arg_; + ConcatQuantArg quant_arg_; int axis_; int thread_count_; -}; + int input_num_; + const int **input_shapes_; + const int *output_shapes_; + int64_t after_axis_size; + int64_t count_unit_; +} ConcatParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CONCAT_PARAMETER_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/conv_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/conv_parameter.h index 8a4d0ef843..338c1da409 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/conv_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/conv_parameter.h @@ -20,10 +20,10 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" -struct ConvParameter { +typedef struct ConvParameter { OpParameter op_parameter_; ConvQuantArg conv_quant_arg_; int kernel_h_; @@ -53,7 +53,26 @@ struct ConvParameter { int output_unit_; bool is_relu_; bool is_relu6_; -}; +} ConvParameter; + + +typedef struct SlidingWindowParam { + int left_; + int right_; + int top_; + int bottom_; + int c_block_; + int block_channel_; + int ic4_channel_; + int out_step_; + int out_h_step_; + int in_step_; + int in_h_step_; + int in_sh_step_; // stride H + int in_sw_step_; // stride W + int in_kh_step_; // kernel H + int in_kw_step_; // kernel W + int kernel_step_; +} SlidingWindowParam; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CONV_PARAMETER_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/crop_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/crop_parameter.h index 93907046d1..847441dd86 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/crop_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/crop_parameter.h @@ -16,11 +16,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CROP_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CROP_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" + +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" #define CROP_OFFSET_MAX_SIZE 4 -struct CropParameter { +typedef struct CropParameter { OpParameter op_parameter_; CropQuantArg quant_arg; int thread_count_; @@ -32,6 +34,6 @@ struct CropParameter { const int *in_shape_; const int *out_shape_; int input_dim_; -}; +} CropParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_CROP_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.cc index 6ded162136..3de8376102 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/depth_to_space.h" +#include "nnacl/depth_to_space.h" #include void DepthToSpaceForNHWC(const void *input, void *output, int *in_shape, DepthToSpaceParameter *param) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.h index 88ae21c840..471f08d396 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space.h @@ -15,7 +15,7 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_DEPTH_TO_SPACE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_DEPTH_TO_SPACE_H_ -#include "src/runtime/kernel/arm/nnacl/depth_to_space_parameter.h" +#include "nnacl/depth_to_space_parameter.h" void DepthToSpaceForNHWC(const void *input, void *output, int *in_shape, DepthToSpaceParameter *param); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_DEPTH_TO_SPACE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space_parameter.h index 0a44d45dba..61fe9937d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/depth_to_space_parameter.h @@ -15,18 +15,18 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_DEPTH_TO_SPACE_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_DEPTH_TO_SPACE_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct DepthToSpaceParameter { - OpParameter op_parameter_; - int32_t block_size_; - int32_t in_stride_dim0_; - int32_t in_stride_dim1_; - int32_t in_stride_dim2_; - int32_t out_stride_dim0_; - int32_t out_stride_dim1_; - int32_t out_stride_dim2_; - uint8_t data_type_size_; -}; +typedef struct DepthToSpaceParameter { + OpParameter op_parameter_; + int32_t block_size_; + int32_t in_stride_dim0_; + int32_t in_stride_dim1_; + int32_t in_stride_dim2_; + int32_t out_stride_dim0_; + int32_t out_stride_dim1_; + int32_t out_stride_dim2_; + uint8_t data_type_size_; +} DepthToSpaceParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_DEPTH_TO_SPACE_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/errorcode.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/errorcode.h index 8c74dcbf39..2d4553cede 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/errorcode.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/errorcode.h @@ -17,15 +17,15 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ERRORCODE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ERRORCODE_H_ -enum ErrorCodeCommonEnum { +typedef enum ErrorCodeCommonEnum { NNACL_OK = 0, NNACL_ERR = 1, NNACL_NULL_PTR, NNACL_PARAM_INVALID, OPLIB_COMMON_END = 9999 -}; +} ErrorCodeCommonEnum; -enum ErrorCodeFp32OpEnum { +typedef enum ErrorCodeFp32OpEnum { NNACL_ERRCODE_OP_FP32_START = 10000, NNACL_ERRCODE_STRASSEN_RECURSION_MALLOC, NNACL_ERRCODE_REVERSE_MALLOC, @@ -35,13 +35,21 @@ enum ErrorCodeFp32OpEnum { NNACL_ERRCODE_DIVISOR_ZERO, NNACL_ERRCODE_INDEX_OUT_OF_RANGE, NNACL_ERRCODE_OP_FP32_END = 19999 -}; +} ErrorCodeFp32OpEnum; -enum ErrorCodeFp16OpEnum { NNACL_ERRCODE_OP_FP16_START = 20000, NNACL_ERRCODE_OP_FP16_END = 29999 }; +typedef enum ErrorCodeFp16OpEnum { + NNACL_ERRCODE_OP_FP16_START = 20000, + NNACL_ERRCODE_OP_FP16_END = 29999 +} ErrorCodeFp16OpEnum; -enum ErrorCodeUint8OpEnum { NNACL_ERRCODE_OP_UINT8_START = 30000, NNACL_ERRCODE_OP_UINT8_END = 39999 }; +typedef enum ErrorCodeUint8OpEnum { + NNACL_ERRCODE_OP_UINT8_START = 30000, + NNACL_ERRCODE_OP_UINT8_END = 39999 +} ErrorCodeUint8OpEnum; -enum ErrorCodeInt8OpEnum { NNACL_ERRCODE_OP_INT8_START = 40000, NNACL_ERRCODE_OP_INT8_END = 49999 }; +typedef enum ErrorCodeInt8OpEnum { + NNACL_ERRCODE_OP_INT8_START = 40000, + NNACL_ERRCODE_OP_INT8_END = 49999 +} ErrorCodeInt8OpEnums; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ERRORCODE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.cc index 2ca6ad285e..49a7fda62e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/flatten.h" +#include "nnacl/flatten.h" #include void Flatten(const void *input, void *output, FlattenParameter *flatten_param) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.h index feb9c0641c..b2b2fdfebb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/flatten.h @@ -15,12 +15,12 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FLATTEN_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FLATTEN_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct FlattenParameter { +typedef struct FlattenParameter { OpParameter op_parameter_; int size; -}; +} FlattenParameter; void Flatten(const void *input, void *output, FlattenParameter *flatten_param); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FLATTEN_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/common_func.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/common_func.h index ba0c7a35b8..177bc27b10 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/common_func.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/common_func.h @@ -20,8 +20,8 @@ #include #include #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/conv_parameter.h" #ifdef __cplusplus extern "C" { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.cc index 254bbaf115..6ad46b7ac1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.h" +#include "nnacl/fp16/conv_depthwise_fp16.h" #include -#include "src/runtime/kernel/arm/nnacl/fp16/common_func.h" +#include "nnacl/fp16/common_func.h" /*conv depthwise fp16 begin*/ void DepthwiseBorderPixelFp16(float16_t *dst, const float16_t *src, const float16_t *weight, const float16_t *bias, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.h index dec8c48eeb..daab03fc9d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_depthwise_fp16.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP16_CONV_DEPTHWISE_FP16_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP16_CONV_DEPTHWISE_FP16_H_ -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/fp32/conv_depthwise.h" void ConvDwC8Fp16(float16_t *output_data, const float16_t *input_data, const float16_t *weight_data, const float16_t *bias_data, const ConvParameter *conv_param, const SlidingWindowParam *sliding, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.cc index 8bd1e2f023..f8ce5035d1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.cc @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp16/conv_fp16.h" +#include "nnacl/fp16/conv_fp16.h" #include -#include "src/runtime/kernel/arm/nnacl/fp16/pack_fp16.h" -#include "src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.h" +#include "nnacl/fp16/pack_fp16.h" +#include "nnacl/fp16/winograd_transform_fp16.h" extern "C" { #ifdef ENABLE_ARM64 @@ -215,7 +215,7 @@ void Conv3x3Fp16(float16_t *input_data, float16_t *transed_weight, const float16 for (int c = 0; c < output_channel; c++) { int oc8_block = c / C8NUM; int oc8_res = c % C8NUM; - int src_offset = oc8_block * C8NUM * out_w_block * out_h_block * tile_num + + int src_offset = oc8_block * C8NUM * out_w_block * out_h_block * C4NUM * C4NUM + C8NUM * (h * out_w_block * output_unit + w) + oc8_res; int dst_offset = (h * output_w + w) * output_channel + c; (output_data + dst_offset)[0] = (tmp_out + src_offset)[0]; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.h index c28ffbdd30..8d5ffa392d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/conv_fp16.h @@ -17,7 +17,7 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP16_CONV_FP16_H_ #include -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" +#include "nnacl/conv_parameter.h" #ifndef ENABLE_NEON void IndirectGemmFp16_16x8(float16_t *output, float16_t *input, float16_t *weight, float16_t *bias, size_t step, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.cc index 2d2f7a93cc..da628aad16 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp16/pack_fp16.h" +#include "nnacl/fp16/pack_fp16.h" #include #include diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.h index a4ac6201d1..f347628a27 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/pack_fp16.h @@ -20,8 +20,8 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/op_base.h" void Im2ColPackUnitFp16(float16_t *input_data, ConvParameter *conv_param, float16_t *packed_input, int real_cal_num, int block_index); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.cc index e585509825..074653532d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.h" +#include "nnacl/fp16/winograd_transform_fp16.h" // for fp16 convolution 3x3 filter/input/output transform F(4,3) void Conv3x3Fp16InputUnit(float16_t *tmp_data, float16_t *trans_input_data, size_t step) { @@ -508,25 +508,25 @@ void Conv3x3Fp16OutputUnit(const float16_t *gemm_out, const float16_t *bias_data void Conv3x3Fp16OutputTransform(const float16_t *gemm_out, float16_t *out_data, const float16_t *bias_data, int start_index, int real_cal_num, int out_w_block, ConvParameter *conv_param) { int output_channel = conv_param->output_channel_; - int output_w = conv_param->output_w_; int output_h = conv_param->output_h_; + int out_h_block = UP_DIV(output_h, C4NUM); int oc8 = UP_DIV(output_channel, C8NUM); -// todo outputw --> out_w_block * out_unit + for (int i = 0; i < real_cal_num; i++) { int out_w_index = (start_index + i) % out_w_block; int out_h_index = (start_index + i) / out_w_block; int src_tile_offset = i * oc8 * C8NUM * 36; - int dst_tile_offset = 8 * (out_w_index * 4 + out_h_index * 4 * output_w); + int dst_tile_offset = C8NUM * (out_w_index * C4NUM + out_h_index * C4NUM * out_w_block * C4NUM); for (int j = 0; j < oc8; j++) { int src_oc8_offset = src_tile_offset + j * 36 * C8NUM; - int dst_oc8_offset = dst_tile_offset + j * C8NUM * output_h * output_w; + int dst_oc8_offset = dst_tile_offset + j * C8NUM * out_h_block * out_w_block * C4NUM * C4NUM; const float16_t *src_ptr = gemm_out + src_oc8_offset; const float16_t *bias_ptr = bias_data + j * C8NUM; float16_t *dst_ptr = out_data + dst_oc8_offset; // output transform - Conv3x3Fp16OutputUnit(src_ptr, bias_ptr, dst_ptr, output_w); + Conv3x3Fp16OutputUnit(src_ptr, bias_ptr, dst_ptr, out_w_block * C4NUM); } } } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.h index 235b9979c0..f5bd11749e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp16/winograd_transform_fp16.h @@ -19,8 +19,8 @@ #include #include -#include "src/runtime/kernel/arm/nnacl/fp16/pack_fp16.h" -#include "src/runtime/kernel/arm/nnacl/fp16/conv_fp16.h" +#include "nnacl/fp16/pack_fp16.h" +#include "nnacl/fp16/conv_fp16.h" // for fp16 convolution 3x3 filter/input/output transform void Conv3x3Fp16InputUnit(float16_t *tmp_data, float16_t *trans_input_data, size_t step); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h index 249bfacbce..9718d9ae75 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h @@ -17,15 +17,15 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ACTIVATION_H_ #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/quantization/fixed_point.h" -struct ActivationParameter { +typedef struct ActivationParameter { OpParameter op_parameter_; int type_; - float alpha_{0.01}; -}; + float alpha_{0.2}; +} ActivationParameter; inline int Relu(const float *src, int length, float *dst) { for (int i = 0; i < length; ++i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.cc index 2b592dc574..b10ba90a8c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/arg_min_max.h" +#include "nnacl/fp32/arg_min_max.h" #include #include diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.h index 8812459de2..d30b6c4dd3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arg_min_max.h @@ -16,7 +16,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_ARG_MIN_MAX_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_ARG_MIN_MAX_H_ -#include "src/runtime/kernel/arm/nnacl/arg_min_max_parameter.h" +#include "nnacl/arg_min_max_parameter.h" void ArgMax(const float *input, float *output, ArgMinMaxParameter *param, int pre_axis_count, int axis_count, int after_axis_count); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.cc index 0fc3d805a7..a7be697b1d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.cc @@ -14,7 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/arithmetic.h" +#include "nnacl/fp32/arithmetic.h" +#include int ElementMul(float *input0, float *input1, float *output, int element_size) { int block_mod = element_size % C4NUM; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.h index 81f388800a..86eacdaf40 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic.h @@ -19,9 +19,9 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/arithmetic_common.h" +#include "nnacl/errorcode.h" int ElementMul(float *input0, float *input1, float *output, int element_size); int ElementMulRelu(float *input0, float *input1, float *output, int element_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.cc index 6bb22ad021..d426806e11 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.cc @@ -16,7 +16,7 @@ #include #include -#include "src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.h" +#include "nnacl/fp32/arithmetic_self.h" // abs: int ElementAbs(float *input, float *output, int element_size) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.h index 62ad6d3cf9..503fbe820d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_self.h @@ -20,8 +20,8 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" int ElementAbs(float *input, float *output, int element_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.cc index e61d5ea596..269528e0a4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.cc @@ -14,14 +14,15 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/batchnorm.h" +#include "nnacl/fp32/batchnorm.h" +#include -void BatchNorm(const float *input_ptr, const float *mean_ptr, const float *variance_ptr, int units, int channel, - float epsilon, float *output_ptr) { - for (int u = 0; u < units; u++) { - for (int c = 0; c < channel; c++) { - auto variance_sqrt = sqrt(variance_ptr[c] + epsilon); - output_ptr[u * channel + c] = (input_ptr[u * channel + c] - mean_ptr[c]) / variance_sqrt; +void BatchNorm(float *output_ptr, const float *input_ptr, const float *mean_ptr, const float *variance_ptr, int task_id, + BatchNormParameter *param) { + for (int u = task_id; u < param->unit_; u += param->op_parameter_.thread_num_) { + for (int c = 0; c < param->channel_; c++) { + auto variance_sqrt = sqrt(variance_ptr[c] + param->epsilon_); + output_ptr[u * param->channel_ + c] = (input_ptr[u * param->channel_ + c] - mean_ptr[c]) / variance_sqrt; } } } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.h index 135f7a73e0..c6103565e1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/batchnorm.h @@ -17,14 +17,16 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_BATCHNORM_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_BATCHNORM_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct BatchNormParameter { +typedef struct BatchNormParameter { OpParameter op_parameter_; float epsilon_; -}; + int unit_; + int channel_; +} BatchNormParameter; -void BatchNorm(const float *input_ptr, const float *mean_ptr, const float *variance_ptr, int count, int channel, - float epsilon, float *output_ptr); +void BatchNorm(float *output_ptr, const float *input_ptr, const float *mean_ptr, const float *variance_ptr, int task_id, + BatchNormParameter *param); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FUSED_BATCHNORM_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.cc index b16bb3a9c6..63d5c9b5ec 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/broadcast_to.h" +#include "nnacl/fp32/broadcast_to.h" #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" void PadBroadcastShapeInfo(BroadcastShapeInfo *shape_info) { if (shape_info->input_shape_size_ < DIMENSION_4D) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.h index 281cfaaa0d..df7a1eef7c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/broadcast_to.h @@ -19,22 +19,22 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define BROADCAST_TO_SHAPE_MAX_SIZE 4 -struct BroadcastToParameter { +typedef struct BroadcastToParameter { OpParameter op_parameter_; int shape_[BROADCAST_TO_SHAPE_MAX_SIZE]; size_t shape_size_; -}; +} BroadcastToParameter; -struct BroadcastShapeInfo { +typedef struct BroadcastShapeInfo { int input_shape_[BROADCAST_TO_SHAPE_MAX_SIZE]; int input_shape_size_; int output_shape_[BROADCAST_TO_SHAPE_MAX_SIZE]; int output_shape_size_; -}; +} BroadcastShapeInfo; int BroadcastTo(const float *input, BroadcastShapeInfo *shape_info, float *output); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_BROADCAST_TO_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.cc index 4582e31474..9b9d326a50 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/cast.h" +#include "nnacl/fp32/cast.h" void Uint8ToFloat32(const uint8_t *input, float *output, int number) { for (int i = 0; i < number; ++i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.h index 616e0b89fa..9bb2df36e1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/cast.h @@ -19,14 +19,14 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" // For cast. -struct CastParameter { +typedef struct CastParameter { OpParameter op_parameter_; int src_type_; int dst_type_; -}; +} CastParameter; void Uint8ToFloat32(const uint8_t *input, float *output, int number); void Uint8ToInt8(const uint8_t *input, int8_t *output, int number); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.cc index f50036bf3c..1c2037767c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/common_func.h" +#include "nnacl/fp32/common_func.h" #ifndef __aarch64__ void MatrixAdd(const float *a_ptr, const float *b_ptr, float *dst, size_t a_stride, size_t b_stride, size_t c_stride, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.h index 3802a82cf2..8b93e88c4a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/common_func.h @@ -20,8 +20,8 @@ #include #include #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/conv_parameter.h" #ifdef __cplusplus extern "C" { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.cc index 8c50292552..ad3207e598 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/concat.h" +#include "nnacl/fp32/concat.h" #include void Concat(void **input, int input_num, int axis, int **inputs_output_shape, size_t shape_size, void *output) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.h index a692fdc1cb..ffeb27f04b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/concat.h @@ -17,7 +17,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_CONCAT_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_CONCAT_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" void Concat(void **input, int input_num, int axis, int **inputs_output_shape, size_t shape_size, void *output); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.cc index 624ffd7565..81eab10540 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.cc @@ -14,9 +14,180 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/conv.h" +#include "nnacl/fp32/conv.h" #include -#include "src/runtime/kernel/arm/nnacl/winograd_transform.h" +#include "nnacl/winograd_transform.h" + +void SWBorderPixel(float *dst, const float *src, const float *weight, const float *bias, int height, int width, + int in_kh_step, int in_kw_step, int kernel_h, int kernel_w, int ic4, bool is_relu, bool is_relu6) { + for (int c = 0; c < C4NUM; c++) { + dst[c] = 0; + } + const float *weight_oc = weight; + for (int oc = 0; oc < C4NUM; ++oc) { + const float *weight_kh = weight_oc; + const float *src_kh = src; + for (int kh = 0; kh < height; kh++) { + const float *src_kw = src_kh; + const float *weight_kw = weight_kh; + for (int kw = 0; kw < width; kw++) { + const float *src_ic4 = src_kw; + const float *weight_ic4 = weight_kw; + for (int ic = 0; ic < ic4; ++ic) { + for (int c = 0; c < C4NUM; c++) { + dst[oc] += src_ic4[c] * weight_ic4[c]; + } + src_ic4 += C4NUM; + weight_ic4 += C4NUM; + } // ic4 loop + src_kw += in_kw_step; + weight_kw += ic4 * C4NUM; + } // kernel_w loop + src_kh += in_kh_step; + weight_kh += kernel_w * ic4 * C4NUM; + } // kernel_h loop + dst[oc] += bias[oc]; + dst[oc] = (is_relu) ? (MSMAX(0, dst[oc])) : (dst[oc]); + dst[oc] = (is_relu6) ? (MSMIN(6, MSMAX(0, dst[oc]))) : (dst[oc]); + weight_oc += kernel_h * kernel_w * ic4 * C4NUM; + } // oc loop +} + +void SWBorder(float *dst, const float *src, const float *weight, const float *bias, int top, int bottom, int left, + int right, const ConvParameter *conv_param, const SlidingWindowParam *sliding) { + int ic4 = sliding->ic4_channel_ / C4NUM; + float *dst_h = dst + top * sliding->out_h_step_; + for (int oh = top; oh < bottom; oh++) { + int ih = oh * conv_param->stride_h_ - conv_param->pad_h_; + int start_kh = MSMAX(0, UP_DIV(-ih, conv_param->dilation_h_)); + int end_kh = MSMIN(conv_param->kernel_h_, UP_DIV(conv_param->input_h_ - ih, conv_param->dilation_h_)); + const float *src_h = src + ih * sliding->in_h_step_; + + float *dst_kernel = dst_h + left * sliding->block_channel_; + for (int ow = left; ow < right; ow++) { + int iw = ow * conv_param->stride_w_ - conv_param->pad_w_; + int start_kw = MSMAX(0, UP_DIV(-iw, conv_param->dilation_w_)); + int end_kw = MSMIN(conv_param->kernel_w_, UP_DIV(conv_param->input_w_ - iw, conv_param->dilation_w_)); + const float *src_w = src_h + iw * sliding->ic4_channel_; + + const float *src_kernel = src_w + start_kh * sliding->in_kh_step_ + start_kw * sliding->in_kw_step_; + const float *weight_kernel = weight + (start_kh * conv_param->kernel_w_ + start_kw) * sliding->ic4_channel_; + + SWBorderPixel(dst_kernel, src_kernel, weight_kernel, bias, end_kh - start_kh, end_kw - start_kw, + sliding->in_kh_step_, sliding->in_kw_step_, conv_param->kernel_h_, conv_param->kernel_w_, ic4, + conv_param->is_relu_, conv_param->is_relu6_); + + dst_kernel += sliding->block_channel_; + } // width loop + dst_h += sliding->out_h_step_; + } // height loop +} + +void SWCenter(float *dst, const float *src, const float *weight, const float *bias, int height, int width, int kernel_h, + int kernel_w, int out_h_step, int block_channel, int ic4, int in_sh_step, int in_sw_step, int in_kh_step, + int in_kw_step, bool is_relu, bool is_relu6) { + float *dst_h = dst; + const float *src_h = src; + for (int oh = 0; oh < height; oh++) { + float *dst_w = dst_h; + const float *src_w = src_h; + for (int ow = 0; ow < width; ow++) { + const float *weight_oc = weight; + for (int c = 0; c < C4NUM; c++) { + dst_w[c] = 0; + } + + for (int oc = 0; oc < C4NUM; oc++) { + const float *weight_kh = weight_oc; + const float *src_kh = src_w; + for (int kh = 0; kh < kernel_h; kh++) { + const float *src_kw = src_kh; + const float *weight_kw = weight_kh; + for (int kw = 0; kw < kernel_w; kw++) { + const float *src_ic4 = src_kw; + const float *weight_ic4 = weight_kw; + for (int ic = 0; ic < ic4; ++ic) { + for (int c = 0; c < C4NUM; c++) { + dst_w[oc] += src_ic4[c] * weight_ic4[c]; + } + + src_ic4 += C4NUM; + weight_ic4 += C4NUM; + } // ic4 loop + src_kw += in_kw_step; + weight_kw += ic4 * C4NUM; + } // kernel_w loop + src_kh += in_kh_step; + weight_kh += kernel_w * ic4 * C4NUM; + } // kernel_h loop + // add biad relu + + dst_w[oc] += bias[oc]; + dst_w[oc] = (is_relu) ? (MSMAX(0, dst_w[oc])) : (dst_w[oc]); + dst_w[oc] = (is_relu6) ? (MSMIN(6, MSMAX(0, dst_w[oc]))) : (dst_w[oc]); + weight_oc += kernel_h * kernel_w * ic4 * C4NUM; + } // oc block + + dst_w += block_channel; + src_w += in_sw_step; + } // dst_width loop + dst_h += out_h_step; + src_h += in_sh_step; + } // dst_height loop +} + +// fp32 sliding window +void ConvSWFp32(const float *input_data, const float *packed_weight, const float *bias_data, float *tmp_out_block, + float *output_data, int task_id, ConvParameter *conv_param, SlidingWindowParam *slidingWindow_param) { + int ic4 = slidingWindow_param->ic4_channel_ / C4NUM; + int ic4_res = conv_param->input_channel_ % C4NUM; + const float *src = input_data; + float *dst; + if (ic4_res == 0) { + dst = output_data; + } else { + dst = tmp_out_block; + } + + for (int b = 0; b < conv_param->output_batch_; b++) { + for (int oc = task_id; oc < slidingWindow_param->c_block_; oc += conv_param->thread_num_) { + const float *src_data = src; + float *dst_data = dst + oc * C4NUM; + const float *weight = packed_weight + oc * slidingWindow_param->kernel_step_; + const float *bias = bias_data + oc * C4NUM; + SWBorder(dst_data, src_data, weight, bias, 0, slidingWindow_param->top_, 0, conv_param->output_w_, conv_param, + slidingWindow_param); + SWBorder(dst_data, src_data, weight, bias, slidingWindow_param->bottom_, conv_param->output_h_, 0, + conv_param->output_w_, conv_param, slidingWindow_param); + SWBorder(dst_data, src_data, weight, bias, slidingWindow_param->top_, slidingWindow_param->bottom_, 0, + slidingWindow_param->left_, conv_param, slidingWindow_param); + SWBorder(dst_data, src_data, weight, bias, slidingWindow_param->top_, slidingWindow_param->bottom_, + slidingWindow_param->right_, conv_param->output_w_, conv_param, slidingWindow_param); + + if (slidingWindow_param->right_ > slidingWindow_param->left_ && + slidingWindow_param->bottom_ > slidingWindow_param->top_) { + int in_h_start = slidingWindow_param->top_ * conv_param->stride_h_ - conv_param->pad_h_; + int in_w_start = slidingWindow_param->left_ * conv_param->stride_w_ - conv_param->pad_w_; + const float *in_t = + src_data + in_h_start * slidingWindow_param->in_h_step_ + in_w_start * slidingWindow_param->ic4_channel_; + float *out_t = dst_data + slidingWindow_param->top_ * slidingWindow_param->out_h_step_ + + slidingWindow_param->left_ * slidingWindow_param->block_channel_; + SWCenter(out_t, in_t, weight, bias, slidingWindow_param->bottom_ - slidingWindow_param->top_, + slidingWindow_param->right_ - slidingWindow_param->left_, conv_param->kernel_h_, conv_param->kernel_w_, + slidingWindow_param->out_h_step_, slidingWindow_param->block_channel_, ic4, + slidingWindow_param->in_sh_step_, slidingWindow_param->in_sw_step_, slidingWindow_param->in_kh_step_, + slidingWindow_param->in_kw_step_, conv_param->is_relu_, conv_param->is_relu6_); + } + } // output C4 loop + src += slidingWindow_param->in_step_; + dst += slidingWindow_param->out_step_; + } // batch loop + // output nhwc4 + if (ic4_res != 0) { + PackNHWC4ToNHWCFp32(tmp_out_block, output_data, conv_param->output_batch_, + conv_param->output_h_ * conv_param->output_w_, conv_param->output_channel_); + } +} // fp32 conv common void ConvFp32(float *input_data, float *packed_input, float *packed_weight, const float *bias_data, @@ -130,9 +301,9 @@ void ConvWinogardFp32(float *input_data, float *trans_weight, const float *bias_ out_unit); int output_num = out_channel * conv_param->output_h_ * conv_param->output_w_ * conv_param->output_batch_; if (is_relu) { - ReluFp32(output_data, output_num); + ReluFp32(output_data, output_data, output_num); } else if (is_relu6) { - Relu6Fp32(output_data, output_num); + Relu6Fp32(output_data, output_data, output_num); } else { // do nothing } @@ -219,9 +390,9 @@ void Conv3x3Fp32(float *input_data, float *transed_weight, const float *bias_dat } int output_num = output_channel * conv_param->output_h_ * conv_param->output_w_ * conv_param->output_batch_; if (is_relu) { - ReluFp32(output_data, output_num); + ReluFp32(output_data, output_data, output_num); } else if (is_relu6) { - Relu6Fp32(output_data, output_num); + Relu6Fp32(output_data, output_data, output_num); } else { // do nothing } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.h index 97a2b08e70..866c989f64 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv.h @@ -20,18 +20,30 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/common_func.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.h" -#include "src/runtime/kernel/arm/nnacl/winograd_utils.h" +#include "nnacl/pack.h" +#include "nnacl/op_base.h" +#include "nnacl/common_func.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/fp32/strassen_matmul.h" +#include "nnacl/winograd_utils.h" +#include "nnacl/fp32/conv_depthwise.h" using TmpBufferAddress = float *; typedef void (*GEMM_FUNC_FP32)(float *output, const float *input, const float *weight, const float *bias, size_t step, size_t ic4, size_t output_channel, size_t offset, size_t mode, size_t writeC4, size_t relu, size_t relu6); +void SWBorder(float *dst, const float *src, const float *weight, const float *bias, int top, int bottom, int left, + int right, const ConvParameter *conv_param, const SlidingWindowParam *sliding); + +void SWCenter(float *dst, const float *src, const float *weight, const float *bias, int height, int width, int kernel_h, + int kernel_w, int out_h_step, int block_channel, int ic4, int in_sh_step, int in_sw_step, int in_kh_step, + int in_kw_step, bool is_relu, bool is_relu6); + +// fp32 sliding window +void ConvSWFp32(const float *input_data, const float *packed_weight, const float *bias_data, float *tmp_out_block, + float *output_data, int task_id, ConvParameter *conv_param, SlidingWindowParam *slidingWindow_param); + // fp32 convolution common (im2col+gemm) void ConvFp32(float *input_data, float *packed_input, float *packed_weight, const float *bias_data, float *tmp_out_block, float *output_data, int task_id, ConvParameter *conv_param, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc index 0b8123c2e1..cd68bc467e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h" -#include "src/runtime/kernel/arm/nnacl/fp32/common_func.h" -#include "src/runtime/kernel/arm/nnacl/winograd_transform.h" +#include "nnacl/fp32/conv_depthwise.h" +#include "nnacl/fp32/common_func.h" +#include "nnacl/winograd_transform.h" #ifdef ENABLE_ARM64 #include #endif @@ -47,13 +47,39 @@ void InitSlidingParam(SlidingWindowParam *sliding, const ConvParameter *conv_par sliding->bottom_ = bottom; sliding->c_block_ = UP_DIV(conv_param->output_channel_, block); sliding->block_channel_ = UP_DIV(conv_param->output_channel_, block) * block; - sliding->out_step_ = conv_param->output_h_ * conv_param->output_w_ * sliding->block_channel_; sliding->out_h_step_ = conv_param->output_w_ * sliding->block_channel_; +} + +void InitSlidingParamConv(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block) { + InitSlidingParam(sliding, conv_param, block); + AppendSlidingParamConv(sliding, conv_param, block); +} + +void AppendSlidingParamConv(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block) { + int in_channel = conv_param->input_channel_; + int ic4 = UP_DIV(in_channel, C4NUM); + int ic4_channel = ic4 * C4NUM; + sliding->ic4_channel_ = ic4_channel; + sliding->in_step_ = conv_param->input_h_ * conv_param->input_w_ * ic4_channel; // for batch loop + sliding->in_h_step_ = conv_param->input_w_ * ic4_channel; + sliding->in_sh_step_ = conv_param->input_w_ * ic4_channel * conv_param->stride_h_; // stride H + sliding->in_sw_step_ = ic4_channel * conv_param->stride_w_; // stride W + sliding->in_kh_step_ = conv_param->input_w_ * ic4_channel * conv_param->dilation_h_; // kernel H + sliding->in_kw_step_ = ic4_channel * conv_param->dilation_w_; // kernel W + sliding->kernel_step_ = conv_param->kernel_w_ * conv_param->kernel_h_ * ic4_channel * block; +} + +void InitSlidingParamConvDw(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block) { + InitSlidingParam(sliding, conv_param, block); + AppendSlidingParamConvDw(sliding, conv_param, block); +} + +void AppendSlidingParamConvDw(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block) { sliding->in_step_ = conv_param->input_h_ * conv_param->input_w_ * sliding->block_channel_; // for batch loop sliding->in_h_step_ = conv_param->input_w_ * sliding->block_channel_; sliding->in_sh_step_ = conv_param->input_w_ * sliding->block_channel_ * conv_param->stride_h_; // stride H - sliding->in_sw_step_ = sliding->block_channel_ * conv_param->stride_h_; // stride W + sliding->in_sw_step_ = sliding->block_channel_ * conv_param->stride_w_; // stride W sliding->in_kh_step_ = conv_param->input_w_ * sliding->block_channel_ * conv_param->dilation_h_; // kernel H sliding->in_kw_step_ = sliding->block_channel_ * conv_param->dilation_w_; // kernel W sliding->kernel_step_ = conv_param->kernel_w_ * conv_param->kernel_h_ * block; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h index e83b6b6dcf..d294d9d313 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h @@ -17,28 +17,27 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_CONV_DEPTHWISE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_CONV_DEPTHWISE_H_ -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" +#include "nnacl/conv_parameter.h" -struct SlidingWindowParam { - int left_; - int right_; - int top_; - int bottom_; - int c_block_; - int block_channel_; - int out_step_; - int out_h_step_; - int in_step_; - int in_h_step_; - int in_sh_step_; // stride H - int in_sw_step_; // stride W - int in_kh_step_; // kernel H - int in_kw_step_; // kernel W - int kernel_step_; -}; +#ifndef ENABLE_ARM64 +void DepthwiseCenter(float *dst, const float *src, const float *weight, const float *bias, int height, int width, + int kernel_h, int kernel_w, int out_h_step, int block_channel, int in_sh_step, int in_sw_step, + int in_kh_step, int in_kw_step, bool is_relu, bool is_relu6); +#endif void InitSlidingParam(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block); +void InitSlidingParamConv(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block); + +void AppendSlidingParamConv(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block); + +void InitSlidingParamConvDw(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block); + +void AppendSlidingParamConvDw(SlidingWindowParam *sliding, const ConvParameter *conv_param, int block); + +void DepthwiseBorder(float *dst, const float *src, const float *weight, const float *bias, int top, int bottom, + int left, int right, const ConvParameter *conv_param, const SlidingWindowParam *sliding); + void ConvDwC4Fp32(float *output_data, const float *input_data, const float *weight_data, const float *bias_data, const ConvParameter *conv_param, const SlidingWindowParam *sliding, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.cc index 4336b10af8..9ca387fb07 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.cc @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/crop.h" +#include "nnacl/fp32/crop.h" #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/crop_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/crop_parameter.h" void Pad4DOffset(CropParameter *crop_param, int64_t *offset) { int axis = crop_param->axis_; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.h index c728f8aee9..788bd30250 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/crop.h @@ -15,8 +15,8 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_CROP_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_CROP_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/crop_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/crop_parameter.h" #define CROP_OFFSET_MAX_SIZE 4 diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.cc index 16a43f94ec..769802e186 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/deconv.h" +#include "nnacl/fp32/deconv.h" void PackDeConvWeightFp32(const float *weight, float *dst, int input_channel, int output_channel, int plane) { /* ichwoc(nhwc) -> oc4 * h * w * incUP4 * 4 */ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.h index 003fb36c1f..61b26f96c5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/deconv.h @@ -16,10 +16,10 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_DECONV_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_DECONV_H_ -#include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.h" +#include "nnacl/pack.h" +#include "nnacl/op_base.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/fp32/strassen_matmul.h" void PackDeConvWeightFp32(const float *weight, float *dst, int input_channel, int output_channel, int plane); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/elu.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/elu.cc new file mode 100644 index 0000000000..0e9df747a5 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/elu.cc @@ -0,0 +1,32 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "nnacl/fp32/elu.h" +#include +#include "include/errorcode.h" +#include "nnacl/errorcode.h" +#include "mindspore/core/utils/log_adapter.h" + +void Calculate_Data(float *input_data, float *output_data, int num, EluParameter *parameter) { + output_data[num] = input_data[num] < 0 ? parameter->alpha_ * expm1(input_data[num]) : input_data[num]; +} + +int Elu(float *input_data, float *output_data, EluParameter *parameter, int task_id) { + for (size_t i = task_id; i < parameter->in_size_; i += parameter->thread_num_) { + Calculate_Data(input_data, output_data, i, parameter); + } + return NNACL_OK; +} diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/elu.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/elu.h new file mode 100644 index 0000000000..940b2fbe66 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/elu.h @@ -0,0 +1,31 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_ELU_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_ELU_H_ + +#include "nnacl/op_base.h" + +typedef struct EluParameter { + OpParameter op_parameter_; + float alpha_; + int thread_num_; + int in_size_; +} EluParameter; + +int Elu(float *input_data, float *output_data, EluParameter *parameter, int task_id); + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_ELU_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.cc index 964041fa3c..8693986413 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.h" +#include "nnacl/fp32/embedding_lookup.h" #include #include "include/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" #include "mindspore/core/utils/log_adapter.h" void l2_regulate(float *data, int size, float max_norm) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.h index fa9f0ce5da..5b125834da 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/embedding_lookup.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_EMBEDDING_LOOKUP_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_EMBEDDING_LOOKUP_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct EmbeddingLookupParameter { +typedef struct EmbeddingLookupParameter { OpParameter op_parameter_; bool *is_regulated_; float max_norm_; @@ -27,7 +27,7 @@ struct EmbeddingLookupParameter { int layer_size_; int layer_num_; int thread_num; -}; +} EmbeddingLookupParameter; int EmbeddingLookup(float *input_data, int *ids, float *output_data, EmbeddingLookupParameter *parameter, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.cc index 65c2a58e90..f1e14fddc5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/expandDims.h" +#include "nnacl/fp32/expandDims.h" #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" int ExpandDims(float *input_ptr, float *output_ptr, size_t data_size) { memcpy(output_ptr, input_ptr, data_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.h index 21b1fc9789..b49bf77677 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/expandDims.h @@ -17,12 +17,12 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_EXPANDDIMS_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_EXPANDDIMS_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct ExpandDimsParameter { +typedef struct ExpandDimsParameter { OpParameter op_parameter_; int dim_; -}; +} ExpandDimsParameter; int ExpandDims(float *input_ptr, float *output_ptr, size_t data_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.cc index 38bc4dbb27..a19586d3a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/fill.h" +#include "nnacl/fp32/fill.h" int Fill(float *output, int size, float data) { for (int i = 0; i < size; ++i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.h index 905afafd3f..31b0fc8119 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/fill.h @@ -19,16 +19,16 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" #define FILL_DIMS_MAX_SIZE 4 -struct FillParameter { +typedef struct FillParameter { OpParameter op_parameter_; int dims_[FILL_DIMS_MAX_SIZE]; int num_dims_; -}; +} FillParameter; int Fill(float *output, int size, float data); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.cc index c6bef4c940..6691fa0a5b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/gather.h" +#include "nnacl/fp32/gather.h" #include inline int Stride(int *shape, int rank, int index) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.h index 95a4046c46..c2f919a296 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gather.h @@ -17,13 +17,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_GATHER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_GATHER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct GatherParameter { +typedef struct GatherParameter { OpParameter op_parameter_; int axis_; int batchDims_; -}; +} GatherParameter; int Gather(float *input, int outer_size, int inner_size, int limit, int *indices, int indices_element_size, float *output); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.cc index fd62a5ab46..5d6e7827d3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/gatherNd.h" +#include "nnacl/fp32/gatherNd.h" #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" int GatherNd(float *input, float *output, int *in_offset, int area, int count) { int i = 0; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.h index 93c97002a2..8a966a5d04 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gatherNd.h @@ -17,12 +17,12 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_GATHERND_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_GATHERND_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct GatherNdParameter { +typedef struct GatherNdParameter { OpParameter op_parameter_; int batchDims_; -}; +} GatherNdParameter; int GatherNd(float *input, float *output, int *in_offset, int area, int count); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.cc index 0120e93645..860897a5da 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.cc @@ -14,7 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/local_response_norm.h" +#include "nnacl/fp32/local_response_norm.h" +#include int LocalResponseNorm(float *input_ptr, int out_size, int channel, float *output_ptr, LocalResponseNormParameter *param) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.h index ad10be79e9..e046fbd313 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/local_response_norm.h @@ -17,15 +17,15 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_LOCAL_RESPONSE_NORM_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_LOCAL_RESPONSE_NORM_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct LocalResponseNormParameter { +typedef struct LocalResponseNormParameter { OpParameter op_parameter_; int depth_radius_; float bias_; float alpha_; float beta_; -}; +} LocalResponseNormParameter; int LocalResponseNorm(float *input_ptr, int out_size, int channel, float *output_ptr, LocalResponseNormParameter *param); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.cc index 7a3a07ed0d..8742b5c7b8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/lstm.h" +#include "nnacl/fp32/lstm.h" #include -#include "src/runtime/kernel/arm/nnacl/fp32/activation.h" -#include "src/runtime/kernel/arm/nnacl/fp32/arithmetic.h" +#include "nnacl/fp32/activation.h" +#include "nnacl/fp32/arithmetic.h" void InitGate(float *gate_buffer, const float *bias, LstmParameter *lstm_parm) { int gate_offest = 0; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.h index 05fff4f1dc..af50e5a3fb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/lstm.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_LSTM_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_LSTM_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct LstmParameter { +typedef struct LstmParameter { OpParameter op_parameter_; int input_size_; int hidden_size_; // output_size @@ -28,7 +28,7 @@ struct LstmParameter { int input_step_; int output_step_; bool bidirectional_; -}; +} LstmParameter; void Lstm(float *output, const float *input, const float *weight_i, const float *weight_h, const float *bias, float *hidden_state, float *cell_state, float *gate_buffer, LstmParameter *lstm_parm); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.cc index 6c841f7f39..910780ba60 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/matmul.h" +#include "nnacl/fp32/matmul.h" void RowMajor2Row8Major(float *src_ptr, float *dst_ptr, int row, int col) { for (int r = 0; r < row; r++) { @@ -42,7 +42,7 @@ void RowMajor2Col8Major(float *src_ptr, float *dst_ptr, size_t row, size_t col) float *dst_c = dst_r + ci * C8NUM; /* 8x4 row-major to col-major */ -#ifdef ENABLE_NEON +#ifdef ENABLE_ARM64 size_t stride = col * 4; asm volatile( "mov x10, %[src_c]\n" @@ -119,14 +119,104 @@ void RowMajor2Col8Major(float *src_ptr, float *dst_ptr, size_t row, size_t col) return; } -void Row8x8Major2RowMajor(float *src_ptr, float *dst_ptr, int row, int col) { - int row8 = UP_ROUND(row, 8); - for (int c = 0; c < col; c++) { - int cd8 = c / 8; - int cm8 = c % 8; - for (int r = 0; r < row; r++) { - dst_ptr[r * col + c] = src_ptr[cd8 * row8 * 8 + r * 8 + cm8]; +inline void MatrixUnPackUnit(const void *src, void *dst, size_t row, size_t col, size_t src_stride, size_t dst_stride, + size_t data_lenth) { + size_t copy_size = col * data_lenth; + size_t src_size = src_stride * data_lenth; + size_t dst_size = dst_stride * data_lenth; + char *src_ptr = (char *)src; + char *dst_ptr = (char *)dst; + for (int r = 0; r < row; r++) { + memcpy(dst_ptr, src_ptr, copy_size); + src_ptr += src_size; + dst_ptr += dst_size; + } +} + +void Row8x8Major2RowMajor(float *src_ptr, float *dst_ptr, size_t row, size_t col, size_t stride) { + size_t row_up8 = UP_ROUND(row, C8NUM); + size_t row_8div = row / C8NUM * C8NUM; + size_t row_8res = row - row_8div; + size_t col_8div = col / C8NUM * C8NUM; + size_t col_8res = col - col_8div; + float *src_c = src_ptr; + float *dst_c = dst_ptr; + + for (size_t ci = 0; ci < col_8div; ci += C8NUM) { +#ifdef ENABLE_ARM64 + size_t offset = stride * 4 - 16; + asm volatile( + "mov x0, #0 \n" + "mov x1, %[row_8div] \n" + "mov x10, %[src_c] \n" + "mov x11, %[dst_c] \n" + + "Loop8x8: \n" + "cmp x0, x1 \n" + "beq End \n" + + "ld1 {v0.4s}, [x10], #16\n" + "ld1 {v1.4s}, [x10], #16\n" + "ld1 {v2.4s}, [x10], #16\n" + "ld1 {v3.4s}, [x10], #16\n" + "ld1 {v4.4s}, [x10], #16\n" + "ld1 {v5.4s}, [x10], #16\n" + "ld1 {v6.4s}, [x10], #16\n" + "ld1 {v7.4s}, [x10], #16\n" + "ld1 {v8.4s}, [x10], #16\n" + "ld1 {v9.4s}, [x10], #16\n" + "ld1 {v10.4s}, [x10], #16\n" + "ld1 {v11.4s}, [x10], #16\n" + "ld1 {v12.4s}, [x10], #16\n" + "ld1 {v13.4s}, [x10], #16\n" + "ld1 {v14.4s}, [x10], #16\n" + "ld1 {v15.4s}, [x10], #16\n" + + "add x0, x0, #8\n" + + "st1 {v0.4s}, [x11], #16\n" + "st1 {v1.4s}, [x11], %[offset]\n" + "st1 {v2.4s}, [x11], #16\n" + "st1 {v3.4s}, [x11], %[offset]\n" + "st1 {v4.4s}, [x11], #16\n" + "st1 {v5.4s}, [x11], %[offset]\n" + "st1 {v6.4s}, [x11], #16\n" + "st1 {v7.4s}, [x11], %[offset]\n" + "st1 {v8.4s}, [x11], #16\n" + "st1 {v9.4s}, [x11], %[offset]\n" + "st1 {v10.4s}, [x11], #16\n" + "st1 {v11.4s}, [x11], %[offset]\n" + "st1 {v12.4s}, [x11], #16\n" + "st1 {v13.4s}, [x11], %[offset]\n" + "st1 {v14.4s}, [x11], #16\n" + "st1 {v15.4s}, [x11], %[offset]\n" + "b Loop8x8\n" + + "End:\n" + + : + : [ dst_c ] "r"(dst_c), [ src_c ] "r"(src_c), [ offset ] "r"(offset), [ row_8div ] "r"(row_8div) + : "x0", "x1", "x10", "x11", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", + "v13", "v14", "v15"); +#else + for (size_t ri = 0; ri < row_8div; ri += C8NUM) { + float *src_r = src_c + ri * C8NUM; + float *dst_r = dst_c + ri * stride; + MatrixUnPackUnit(src_r, dst_r, C8NUM, C8NUM, C8NUM, stride, sizeof(float)); } +#endif + + if (row != row_8div) { + float *src_r = src_c + row_8div * C8NUM; + float *dst_r = dst_c + row_8div * stride; + MatrixUnPackUnit(src_r, dst_r, row_8res, C8NUM, C8NUM, stride, sizeof(float)); + } + src_c += row_up8 * C8NUM; + dst_c += C8NUM; + } + + if (col != col_8div) { + MatrixUnPackUnit(src_c, dst_c, row, col_8res, C8NUM, stride, sizeof(float)); } return; } @@ -156,6 +246,9 @@ void MatMul8x8(const float *a, const float *b, float *c, const float *bias, ActT void MatMul(const float *a, const float *b, float *c, const float *bias, ActType act_type, int deep, int row_8_, int col_8_) { +#ifdef __aarch64__ + MatmulFloatNeon64(a, b, c, bias, (int)act_type, deep, row_8_, col_8_); +#else MatMul8x8(a, b, c, bias, act_type, deep, row_8_, col_8_); - return; +#endif } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.h index e92f6004b7..e8386cc057 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/matmul.h @@ -17,23 +17,24 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_MATMUL_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_MATMUL_H_ +#include #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/matmul_parameter.h" void MatMul(const float *a, const float *b, float *c, const float *bias, ActType act_type, int depth, int row, int col); void RowMajor2Row8Major(float *src_ptr, float *dst_ptr, int row, int col); void RowMajor2Col8Major(float *src_ptr, float *dst_ptr, size_t row, size_t col); -void Row8x8Major2RowMajor(float *src_ptr, float *dst_ptr, int row, int col); +void Row8x8Major2RowMajor(float *src_ptr, float *dst_ptr, size_t row, size_t col, size_t stride); void MatMul8x8(const float *a, const float *b, float *c, const float *bias, float maxf, float minf, int deep, int row_8_, int col_8_); #ifdef __cplusplus extern "C" { #endif #ifdef __aarch64__ -void MatMulFloatNeon64(const float *a, const float *b, float *c, const float *bias, float maxf, float minf, int depth, - int row, int col); +void MatmulFloatNeon64(const float *a, const float *b, float *c, const float *bias, int act_type, int depth, int row, + int col); #endif #ifdef __cplusplus } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.cc index 351e154290..fbe75876e9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/one_hot.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/fp32/one_hot.h" +#include "nnacl/errorcode.h" int OneHot(const int *indices, float *output, const OneHotParameter *one_hot_param, const int tid, const int thread_num) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.h index 9cefa121ec..4cc0ba1018 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/one_hot.h @@ -20,9 +20,9 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct OneHotParameter { +typedef struct OneHotParameter { OpParameter op_parameter_; int axis_; int depth_; @@ -30,7 +30,7 @@ struct OneHotParameter { float off_value_; int outer_size_; int inner_size_; -}; +} OneHotParameter; int OneHot(const int *indices, float *output, const OneHotParameter *one_hot_param, const int tid, const int thread_num); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.cc index 1857ed6515..5a1448c2e5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/pad.h" -#include "src/runtime/kernel/arm/nnacl/common_func.h" +#include "nnacl/fp32/pad.h" +#include "nnacl/common_func.h" void Pad(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, const int *paddings, const int tid, const int thread_num) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.h index 1b60946e29..eef9796f56 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pad.h @@ -21,8 +21,8 @@ #endif #include #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/pad_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/pad_parameter.h" void Pad(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, const int *paddings, const int tid, const int thread_num); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.cc index da45b8b94d..543ccfb132 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/pooling.h" +#include "nnacl/fp32/pooling.h" #include void AvgPooling(const float *input_ptr, float *output_ptr, PoolingParameter *pooling_param, int task_id) { @@ -150,12 +150,12 @@ void MaxPooling(const float *input_ptr, float *output_ptr, PoolingParameter *poo int in_channel_offset = in_batch_offset + j * C4NUM; int out_channel_offset = out_plane_offset + j * C4NUM; #ifdef ENABLE_NEON - float32x4_t tmp_max = vdupq_n_f32(FLT_MIN); + float32x4_t tmp_max = vdupq_n_f32(-FLT_MAX); #else - float tmp_max1 = FLT_MIN; - float tmp_max2 = FLT_MIN; - float tmp_max3 = FLT_MIN; - float tmp_max4 = FLT_MIN; + float tmp_max1 = -FLT_MAX; + float tmp_max2 = -FLT_MAX; + float tmp_max3 = -FLT_MAX; + float tmp_max4 = -FLT_MAX; #endif for (int h = 0; h < win_h; h++) { for (int w = 0; w < win_w; w++) { @@ -188,7 +188,7 @@ void MaxPooling(const float *input_ptr, float *output_ptr, PoolingParameter *poo for (int k = channel_s; k < channel; k++) { int in_channel_offset = in_batch_offset + k; int out_channel_offset = out_plane_offset + k; - float tmp_max = FLT_MIN; + float tmp_max = -FLT_MAX; for (int h = 0; h < win_h; h++) { for (int w = 0; w < win_w; w++) { if ((in_h_index + h) < 0 || (in_h_index + h) >= in_h || (in_w_index + w) < 0 || diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.h index b460ea490c..8b167a3d65 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling.h @@ -20,9 +20,10 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" -struct PoolingParameter { +typedef struct PoolingParameter { OpParameter op_parameter_; QuantArg **quant_args_; bool global_; @@ -47,7 +48,7 @@ struct PoolingParameter { int stride_w_; int stride_h_; int thread_num_; -}; +} PoolingParameter; void AvgPooling(const float *input_ptr, float *output_ptr, PoolingParameter *pooling_param, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.cc index acb6c18cd5..63b285d506 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/range.h" +#include "nnacl/fp32/range.h" void Range(float *output_ptr, int start, int limit, int delta) { size_t index = 0; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.h index bdb40c6d25..f48d98ca92 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/range.h @@ -17,15 +17,15 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RANGE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RANGE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct RangeParameter { +typedef struct RangeParameter { OpParameter op_parameter_; int dType_; int start_; int limit_; int delta_; -}; +} RangeParameter; void Range(float *output_ptr, int start, int limit, int delta); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.cc index 1cf475b625..b3b27f3a4d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/rank.h" +#include "nnacl/fp32/rank.h" void Rank(float* output, int rank) { output[0] = (float)(rank); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.h index e8133d0ac7..15c5a9affd 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/rank.h @@ -16,7 +16,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RANK_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RANK_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" void Rank(float* output, int rank); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.cc index 4fe680b8cd..4a4e95ea8a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.cc @@ -15,8 +15,8 @@ */ #include -#include "src/runtime/kernel/arm/nnacl/fp32/reduce.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/fp32/reduce.h" +#include "nnacl/errorcode.h" int ReduceMean(const int outer_size, const int inner_size, const int axis_size, const float *src_data, const int *src_shape, float *dst_data, const int tid, const int thread_num) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.h index 9ebdb9638a..e20ae4c45e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.h @@ -16,16 +16,16 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_REDUCE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_REDUCE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define REDUCE_MAX_AXES_NUM 8 -struct ReduceParameter { +typedef struct ReduceParameter { OpParameter op_parameter_; bool keep_dims_; int axes_[REDUCE_MAX_AXES_NUM]; int num_axes_; int mode_; -}; +} ReduceParameter; int ReduceMean(const int outer_size, const int inner_size, const int axis_size, const float *src_data, const int *src_shape, float *dst_data, const int tid, const int thread_num); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.cc new file mode 100644 index 0000000000..48fde607ce --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.cc @@ -0,0 +1,128 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include "nnacl/fp32/resize.h" +#include "nnacl/common_func.h" +#include "nnacl/errorcode.h" + +int ResizeBilinear(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, + bool align_corners, int tid, int thread_num) { + if (input_data == nullptr || output_data == nullptr || input_shape == nullptr || output_shape == nullptr) { + return NNACL_NULL_PTR; + } + + int in_n = input_shape[0]; + int in_h = input_shape[1]; + int in_w = input_shape[2]; + int in_c = input_shape[3]; + + int new_height = output_shape[1]; + int new_width = output_shape[2]; + float height_scale = (float)(in_h) / new_height; + float width_scale = (float)(in_w) / new_width; + if (align_corners && new_height > 1) { + height_scale = (float)(in_h - 1) / (new_height - 1); + } + if (align_corners && new_width > 1) { + width_scale = (float)(in_w - 1) / (new_width - 1); + } + + int n, h, w, c; + for (n = 0; n < in_n; n++) { + for (h = tid; h < new_height; h += thread_num) { + float actual_y = (float)h * height_scale; + int y_bottom = (int)(floor(actual_y)); + int y_top = y_bottom + 1 < in_h ? (y_bottom + 1) : (in_h - 1); + float y_top_weight = actual_y - (float)(y_bottom); + float y_bottom_weight = 1.0f - y_top_weight; + for (w = 0; w < new_width; w++) { + float actual_x = (float)(w)*width_scale; + int x_left = (int)(floor(actual_x)); + int x_right = x_left + 1 < in_w ? (x_left + 1) : (in_w - 1); + float x_right_weight = actual_x - (float)(x_left); + float x_left_weight = 1.0f - x_right_weight; + c = 0; +#ifdef ENABLE_NEON + for (; c <= in_c - 4; c += 4) { + float32x4_t bottom_left = vld1q_f32(input_data + offset(input_shape, n, y_bottom, x_left, c)); + float32x4_t bottom_right = vld1q_f32(input_data + offset(input_shape, n, y_bottom, x_right, c)); + float32x4_t top_left = vld1q_f32(input_data + offset(input_shape, n, y_top, x_left, c)); + float32x4_t top_right = vld1q_f32(input_data + offset(input_shape, n, y_top, x_right, c)); + + float32x4_t y_top_w = vdupq_n_f32(y_top_weight); + float32x4_t y_bottom_w = vdupq_n_f32(y_bottom_weight); + float32x4_t x_left_w = vdupq_n_f32(x_left_weight); + float32x4_t x_right_w = vdupq_n_f32(x_right_weight); + + float32x4_t interp_value = vdupq_n_f32(0.0); + float32x4_t tmp = vmulq_f32(bottom_left, y_bottom_w); + tmp = vmulq_f32(tmp, x_left_w); + interp_value = vaddq_f32(interp_value, tmp); + + tmp = vmulq_f32(bottom_right, y_bottom_w); + tmp = vmulq_f32(tmp, x_right_w); + interp_value = vaddq_f32(interp_value, tmp); + + tmp = vmulq_f32(top_left, y_top_w); + tmp = vmulq_f32(tmp, x_left_w); + interp_value = vaddq_f32(interp_value, tmp); + + tmp = vmulq_f32(top_right, y_top_w); + tmp = vmulq_f32(tmp, x_right_w); + interp_value = vaddq_f32(interp_value, tmp); + vst1q_f32(output_data + offset(output_shape, n, h, w, c), interp_value); + } +#endif + for (; c < in_c; c++) { + auto bottom_left = input_data[offset(input_shape, n, y_bottom, x_left, c)]; + auto bottom_right = input_data[offset(input_shape, n, y_bottom, x_right, c)]; + auto top_left = input_data[offset(input_shape, n, y_top, x_left, c)]; + auto top_right = input_data[offset(input_shape, n, y_top, x_right, c)]; + float interp_value = bottom_left * y_bottom_weight * x_left_weight + + bottom_right * y_bottom_weight * x_right_weight + + top_left * y_top_weight * x_left_weight + top_right * y_top_weight * x_right_weight; + output_data[offset(output_shape, n, h, w, c)] = interp_value; + } + } + } + } + return NNACL_OK; +} + +int ResizeNearestNeighbor(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, + int tid, int thread_num) { + int batch, y, x, c; + c = input_shape[3]; + + float height_scale = (float)(input_shape[1]) / (float)(output_shape[1]); + float width_scale = (float)(input_shape[2]) / (float)(output_shape[2]); + + for (batch = 0; batch < output_shape[0]; batch++) { + for (y = tid; y < output_shape[1]; y += thread_num) { + int actual_y = (int)(floor((float)(y)*height_scale)); + int input_y = actual_y < input_shape[1] ? actual_y : input_shape[1] - 1; + for (x = 0; x < output_shape[2]; x++) { + int actual_x = (int)(floor((float)(x)*width_scale)); + int input_x = actual_x < input_shape[2] ? actual_x : input_shape[2] - 1; + int in_offset = offset(input_shape, batch, input_y, input_x, 0); + int out_offset = offset(output_shape, batch, y, x, 0); + memcpy(output_data + out_offset, input_data + in_offset, c * sizeof(float)); + } + } + } + + return NNACL_OK; +} diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/resize.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.h similarity index 67% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/resize.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.h index e7fd4a6876..1f45c8dd5d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/resize.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.h @@ -13,27 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESIZE_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESIZE_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_RESIZE_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_RESIZE_H_ #ifdef ENABLE_NEON #include #endif #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #include "schema/ops_generated.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" - -using mindspore::schema::ResizeMethod; - -struct ResizeParameter { - OpParameter op_parameter_; - ResizeMethod method_; - int64_t new_height_; - int64_t new_width_; - bool align_corners_; - bool preserve_aspect_ratio_; -}; int ResizeBilinear(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, bool align_corners, int tid, int thread_num); @@ -41,5 +29,5 @@ int ResizeBilinear(const float *input_data, float *output_data, const int *input int ResizeNearestNeighbor(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, int tid, int thread_num); -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESIZE_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_RESIZE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.cc index 6c1867f954..1023c5bbc0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/reverse.h" +#include "nnacl/fp32/reverse.h" #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" int Reverse(const float *input, float *output, size_t elem_size, int *index) { for (int i = 0; i < elem_size; i++) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.h index 8e76eb4b94..d4e45938a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reverse.h @@ -20,15 +20,15 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define REVERSE_SHAPE_MAX_SIZE 4 // For reverse. -struct ReverseParameter { +typedef struct ReverseParameter { OpParameter op_parameter_; int axis_[REVERSE_SHAPE_MAX_SIZE]; int num_axis_; -}; +} ReverseParameter; int Reverse(const float *input, float *output, size_t elem_size, int *index); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.cc index 02e3b3fcee..732b51be33 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/slice.h" +#include "nnacl/fp32/slice.h" #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" void PadSliceParameterTo4D(SliceParameter *param) { int32_t begin[DIMENSION_4D]; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.h index 07da4625c2..835e1623fc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/slice.h @@ -16,10 +16,10 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_SLICE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_SLICE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define SLICE_SHAPE_MAX_SIZE 4 -struct SliceParameter { +typedef struct SliceParameter { OpParameter op_parameter_; int32_t begin_[SLICE_SHAPE_MAX_SIZE]; int32_t end_[SLICE_SHAPE_MAX_SIZE]; @@ -27,7 +27,7 @@ struct SliceParameter { int32_t shape_[SLICE_SHAPE_MAX_SIZE]; int32_t param_length_; int32_t thread_id_; -}; +} SliceParameter; void PadSliceParameterTo4D(SliceParameter *param); void DoSlice(const float *input, float *output, SliceParameter *param); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.cc index 2e046f2651..6bf03d35c4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/softmax.h" -#include +#include "nnacl/fp32/softmax.h" +#include // output = exp(input) / reduce_sum(exp(input), axis) void Softmax(const float *input_ptr, float *output_ptr, float *sum_data, SoftmaxParameter *parameter) { @@ -37,24 +37,25 @@ void Softmax(const float *input_ptr, float *output_ptr, float *sum_data, Softmax for (int i = 0; i < outter_size; i++) { int outter_offset = i * input_shape[axis] * inner_size; - for (int j = 0; j < input_shape[axis]; j++) { - int axis_offset = outter_offset + j * inner_size; - for (int k = 0; k < inner_size; k++) { - int inner_offset = axis_offset + k; - sum_data[j] += output_ptr[inner_offset]; + int sum_outter_offset = i * inner_size; + for (int k = 0; k < inner_size; k++) { + int inner_offset = outter_offset + k; + for (int j = 0; j < input_shape[axis]; j++) { + int axis_offset = inner_offset + j * inner_size; + sum_data[k + sum_outter_offset] += output_ptr[axis_offset]; } } } for (int i = 0; i < outter_size; i++) { int outter_offset = i * input_shape[axis] * inner_size; + int sum_outter_offset = i * inner_size; for (int j = 0; j < input_shape[axis]; j++) { int axis_offset = outter_offset + j * inner_size; for (int k = 0; k < inner_size; k++) { int inner_offset = axis_offset + k; - output_ptr[inner_offset] = output_ptr[inner_offset] / sum_data[j]; + output_ptr[inner_offset] = output_ptr[inner_offset] / sum_data[k + sum_outter_offset]; } } } } - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.h index 7324b0d4d5..bd1a780222 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_SOFTMAX_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_SOFTMAX_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/softmax_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/softmax_parameter.h" void Softmax(const float *input_ptr, float *output_ptr, float *sum_data, SoftmaxParameter *parameter); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.cc index cbc4e247dd..809c0fd324 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.cc @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/space_to_batch.h" -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/fp32/concat.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/fp32/space_to_batch.h" +#include "nnacl/arithmetic_common.h" +#include "nnacl/errorcode.h" +#include "nnacl/fp32/concat.h" +#include "nnacl/op_base.h" int EnumElement(int *shape, int n_dims) { int total = 1; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.h index 4d4ab437f7..53a5c2410c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_batch.h @@ -15,12 +15,12 @@ */ #ifndef MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_FP32_SPACE_TO_BATCH_H_ #define MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_FP32_SPACE_TO_BATCH_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define SPACE_TO_BATCH_BLOCK_SIZES_SIZE 2 #define SPACE_TO_BATCH_PADDINGS_SIZE 4 -struct SpaceToBatchParameter { +typedef struct SpaceToBatchParameter { OpParameter op_parameter_; int block_sizes_[8]; int paddings_[8]; @@ -31,7 +31,7 @@ struct SpaceToBatchParameter { int in_shape_[8]; int padded_in_shape_[8]; bool need_paddings_ = false; -}; +} SpaceToBatchParameter; int SpaceToBatch(const float *input, float *output, SpaceToBatchParameter param, float *tmp_space[3]); int SpaceToBatchForNHWC(const float *input, float *output, int *in_shape, int shape_size, int *block_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.cc index dab1dd7b8e..bf0f6b88b9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.cc @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/space_to_depth.h" -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/fp32/space_to_depth.h" +#include "nnacl/arithmetic_common.h" +#include "nnacl/errorcode.h" +#include "nnacl/op_base.h" int SpaceToDepthForNHWC(const float *input, float *output, int *in_shape, int *out_shape, int shape_size, int block_size, int h_start, int h_end) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.h index 5bfdacac89..e83c6137f6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/space_to_depth.h @@ -15,12 +15,12 @@ */ #ifndef MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_FP32_SPACE_TO_DEPTH_H_ #define MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_FP32_SPACE_TO_DEPTH_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct SpaceToDepthParameter { +typedef struct SpaceToDepthParameter { OpParameter op_parameter_; int32_t block_size_; -}; +} SpaceToDepthParameter; int SpaceToDepthForNHWC(const float *input, float *output, int *in_shape, int *out_shape, int shape_size, int block_size, int h_start, int h_end); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.cc index 1496ec7d47..1ccdb8d347 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/stack.h" -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" +#include "nnacl/fp32/stack.h" +#include "nnacl/arithmetic_common.h" void DoStack(const float * const *inputs, size_t input_num, int *in_shape, size_t shape_size, int axis, float *output) { size_t one_input_size = 1; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.h index cf08d4901b..0b9f656975 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/stack.h @@ -16,12 +16,12 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_STACK_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_STACK_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct StackParameter { +typedef struct StackParameter { OpParameter op_parameter_; int32_t axis_; -}; +} StackParameter; void DoStack(const float * const *inputs, size_t input_num, int *in_shape, size_t shape_size, int axis, float *output); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_STACK_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.cc index 1baa31f8e7..df0c48362d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.h" +#include "nnacl/fp32/strassen_matmul.h" bool CheckRecursion(int row, int col, int deep, int max_recursion, int cur_recursion) { if (cur_recursion >= max_recursion) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.h index 06afd71669..7af6ae7c37 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/strassen_matmul.h @@ -18,11 +18,11 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_STRASSEN_MATMUL_H_ #include -#include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/strassen_matmul.h" -#include "src/runtime/kernel/arm/nnacl/fp32/common_func.h" +#include "nnacl/pack.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/strassen_matmul.h" +#include "nnacl/fp32/common_func.h" #define FP32_STRASSEN_UINT C4NUM #define FP32_STRASSEN_WEIGHT_UINT (C4NUM * C4NUM) diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.cc index be0c8b3f13..fcb6bc7798 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/topk.h" +#include "nnacl/fp32/topk.h" int DescendCmp(const void *a, const void *b) { return ((const TopkNode *)b)->element - ((const TopkNode *)a)->element; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.h index a49e5f8ef4..de4c6b9240 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/topk.h @@ -17,21 +17,21 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_TOPK_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_TOPK_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct TopkNode { +typedef struct TopkNode { float element; int32_t index; -}; +} TopkNode; -struct TopkParameter { +typedef struct TopkParameter { OpParameter op_parameter_; int last_dim_size_; int loop_num_; int k_; bool sorted_; void *topk_node_list_; -}; +} TopkParameter; void Topk(float *input_data, float *output_data, int32_t *output_index, TopkParameter *parameter); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.cc index 4d7d1600cf..b4164bb35d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/unsqueeze.h" +#include "nnacl/fp32/unsqueeze.h" #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" int Unsqueeze(float *input_ptr, float *output_ptr, size_t data_size) { memcpy(output_ptr, input_ptr, data_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.h index 59c01944f3..c609ad1f27 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/unsqueeze.h @@ -17,15 +17,15 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_UNSQUEEZE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_UNSQUEEZE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define UNSQUEEZE_DIMS_MAX_SIZE 4 -struct UnsqueezeParameter { +typedef struct UnsqueezeParameter { OpParameter op_parameter_; int dims_[UNSQUEEZE_DIMS_MAX_SIZE]; int num_dim_; -}; +} UnsqueezeParameter; int Unsqueeze(float *input_ptr, float *output_ptr, size_t data_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/activation_grad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/activation_grad.h new file mode 100644 index 0000000000..41b734085b --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/activation_grad.h @@ -0,0 +1,88 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_ACTIVATION_GRAD_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_ACTIVATION_GRAD_H_ + +#include +#include "nnacl/op_base.h" +#include "nnacl/fp32/arithmetic.h" +#include "nnacl/errorcode.h" + +typedef struct ActivationGradParameter { + OpParameter op_parameter{}; + int type_; + float alpha_{0.01}; +} ActivationGradParameter; + +inline int ReluGrad(float *src0, float *src1, int length, float *dst) { + for (int i = 0; i < length; ++i) { + dst[i] = src1[i] > 0 ? 1.0f : 0.0f; + } + ElementMul(src0, dst, dst, length); + return OPCLIB_OK; +} + +inline int Relu6Grad(float *src0, float *src1, int length, float *dst) { + for (int i = 0; i < length; ++i) { + if (src1[i] < 0) { + dst[i] = 0; + } else { + dst[i] = src1[i] > 6.0f ? 0.0f : 1.0f; + } + } + ElementMul(src0, dst, dst, length); + return OPCLIB_OK; +} + +inline int LReluGrad(float *src0, float *src1, int length, float *dst, float alpha) { + for (int i = 0; i < length; ++i) { + dst[i] = src1[i] > 0.0f ? 1.0f : alpha; + } + ElementMul(src0, dst, dst, length); + return OPCLIB_OK; +} + +inline int SigmoidGrad(float *src0, float *src1, int length, float *dst) { + for (int i = 0; i < length; ++i) { + dst[i] = src0[i] * (src1[i] * (1.0f - src1[i])); + } + return OPCLIB_OK; +} + +inline int TanhGrad(float *src0, float *src1, int length, float *dst) { + for (int i = 0; i < length; ++i) { + dst[i] = (1.0f - (src1[i] * src1[i])) * src0[i]; + } + return OPCLIB_OK; +} + +inline int HSwishGrad(float *src0, float *src1, int length, float *dst) { + for (int i = 0; i < length; ++i) { + float tmp = (src1[i] > 3.0f ? 1.0f : (src1[i] < -3.0f ? 0.0f : (2.0f * src1[i] + 3.0f) / 6.0f)); + dst[i] = tmp * src0[i]; + } + return OPCLIB_OK; +} + +inline int HSigmoidGrad(float *src0, float *src1, int length, float *dst) { + for (int i = 0; i < length; ++i) { + float tmp = (src1[i] > 3.0f ? 1.0f : (src1[i] < -3.0f ? 0.0f : 1.0f / 6.0f)); + dst[i] = tmp * src0[i]; + } + return OPCLIB_OK; +} + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_ACTIVATION_GRAD_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/arithmetic_grad.cc similarity index 94% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/arithmetic_grad.cc index f13dc824f8..6e5b56ecf5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/arithmetic_grad.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.h" +#include "nnacl/fp32_grad/arithmetic_grad.h" void ElementDivNegSquare(const float *nom, const float *denom, float *output, int element_size) { for (int i = 0; i < element_size; i++) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/arithmetic_grad.h similarity index 84% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/arithmetic_grad.h index 9994b4d66d..0b70402a92 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/arithmetic_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/arithmetic_grad.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_ARITHMETIC_GRAD_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_ARITHMETIC_GRAD_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_ARITHMETIC_GRAD_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_ARITHMETIC_GRAD_H_ void ElementDivNegSquare(const float *nom, const float *denom, float *output, int element_size); void ElementMulAndDivNegSquare(const float *a, const float *b, const float *denom, float *output, int element_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_norm.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/batch_norm.cc similarity index 87% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/batch_norm.cc rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/batch_norm.cc index bbe4dc1f3c..fc9893de2d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_norm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/batch_norm.cc @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include -#include "src/runtime/kernel/arm/nnacl/batch_norm.h" +#include +#include +#include "nnacl/fp32_grad/batch_norm.h" static void sumSpatialBatch(const float *in, int size, int ch, float *out) { - std::fill(out, out + ch, 0.f); + memset(out, 0, ch * sizeof(float)); for (int i = 0; i < size; i++) { const float *ptr = in + i * ch; for (int c = 0; c < ch; c++) { @@ -39,7 +39,7 @@ void normalize(const float *x, const float *mean, const float *variance, float e for (i = 0; i < spatial; ++i) { for (f = 0; f < filters; ++f) { int index = b * filters * spatial + i * filters + f; - out[index] = (x[index] - mean[f]) / (std::sqrt(variance[f]) + eps); + out[index] = (x[index] - mean[f]) / (sqrt(variance[f]) + eps); } } } @@ -47,7 +47,7 @@ void normalize(const float *x, const float *mean, const float *variance, float e void backwardScale(const float *x_norm, const float *delta, int batch, int n, int size, float *scale_updates) { int i, b, f; - std::fill(scale_updates, scale_updates + n, 0.f); + memset(scale_updates, 0, n * sizeof(float)); for (b = 0; b < batch; ++b) { for (i = 0; i < size; ++i) { for (f = 0; f < n; ++f) { @@ -62,7 +62,7 @@ void meanVar(const float *in, int batch, int spatial, int ch, float *mean, float float N = batch * spatial; sumSpatialBatch(in, N, ch, mean); for (int f = 0; f < ch; ++f) mean[f] /= N; - std::fill(var, var + ch, 0.f); + memset(var, 0, ch * sizeof(float)); for (int i = 0; i < N; i++) { for (int f = 0; f < ch; f++) { float x = in[i * ch + f]; @@ -74,13 +74,13 @@ void meanVar(const float *in, int batch, int spatial, int ch, float *mean, float void meanDelta(float *yt, int size, int ch, float eps, float *variance, float *mean_delta) { sumSpatialBatch(yt, size, ch, mean_delta); - for (int i = 0; i < ch; i++) mean_delta[i] *= -1.f / std::sqrt((variance[i] + eps)); + for (int i = 0; i < ch; i++) mean_delta[i] *= -1.f / sqrt((variance[i] + eps)); } void meanAdd(const float *x, const float *mean, const float *variance_delta, int batch, int filters, int spatial, float *mean_add, float *mean_delta) { int i, k; - std::fill(mean_add, mean_add + filters, 0.f); + memset(mean_add, 0, filters * sizeof(float)); for (k = 0; k < spatial * batch; ++k) { for (i = 0; i < filters; ++i) { int index = k * filters + i; @@ -96,7 +96,7 @@ void meanAdd(const float *x, const float *mean, const float *variance_delta, int void varianceDelta(const float *x, const float *delta, const float *mean, const float *variance, int batch, int filters, int spatial, float eps, float *variance_delta) { int i, k; - std::fill(variance_delta, variance_delta + filters, 0.f); + memset(variance_delta, 0, filters * sizeof(float)); for (k = 0; k < batch * spatial; k++) { for (i = 0; i < filters; i++) { int index = k * filters + i; @@ -112,7 +112,7 @@ void NormalizeDelta(const float *x, const float *mean, const float *variance, co for (k = 0; k < batch * spatial; k++) { for (f = 0; f < filters; f++) { int index = k * filters + f; - delta[index] = delta[index] * 1. / (std::sqrt(variance[f] + eps)) + + delta[index] = delta[index] * 1. / (sqrt(variance[f] + eps)) + variance_delta[f] * 2. * (x[index] - mean[f]) / (spatial * batch) + mean_delta[f] / (spatial * batch); } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_norm.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/batch_norm.h similarity index 87% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/batch_norm.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/batch_norm.h index 0d9e8b74bf..f4e1616e77 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/batch_norm.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/batch_norm.h @@ -14,15 +14,15 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_BACKEND_ARM_BATCH_NORM_H_ -#define MINDSPORE_LITE_SRC_BACKEND_ARM_BATCH_NORM_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_BATCH_NORM_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_BATCH_NORM_H_ -struct bnParameter { +typedef struct bnParameter { int batch; int channels; int spatial; float eps; -}; +} bnParameter; void scaleBias(const float *scales, int batch, int n, int size, float *output); void normalize(const float *x, const float *mean, const float *variance, float eps, int batch, int filters, int spatial, float *out); @@ -36,4 +36,5 @@ void meanAdd(const float *x, const float *mean, const float *variance_delta, int void NormalizeDelta(const float *x, const float *mean, const float *variance, const float *mean_delta, const float *variance_delta, int batch, int filters, int spatial, float eps, float *delta); -#endif +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_BATCH_NORM_H_ + diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gemm.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/gemm.cc similarity index 98% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gemm.cc rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/gemm.cc index 83705a8fbd..8cfc9e2818 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gemm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/gemm.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fp32/gemm.h" +#include "nnacl/fp32_grad/gemm.h" static void gemm_nn(int M, int N, int K, float alpha, float *mat_a, int lda, float *mat_B, int ldb, float *mat_c, int ldc) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gemm.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/gemm.h similarity index 78% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gemm.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/gemm.h index b3e30d09da..69901bcf66 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/gemm.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/gemm.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GEMM_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GEMM_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_GEMM_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_GEMM_H_ void gemm(int transpose_a, int transpose_b, int M, int N, int K, float alpha, float *mat_a, int lda, float *mat_b, int ldb, float beta, float *mat_c, int ldc); -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GEMM_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_GEMM_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack_ext.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.cc similarity index 99% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/pack_ext.cc rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.cc index 58a52963dd..d95cc6daf9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack_ext.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.cc @@ -15,7 +15,7 @@ */ #include -#include "src/runtime/kernel/arm/nnacl/pack_ext.h" +#include "nnacl/fp32_grad/pack_ext.h" static int is_a_ge_zero_and_a_lt_b(int a, int b) { return (unsigned)(a) < (unsigned)(b); } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack_ext.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.h similarity index 94% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/pack_ext.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.h index d943467f16..e2a771109c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack_ext.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pack_ext.h @@ -17,7 +17,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PACK_EXT_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PACK_EXT_H_ -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" +#include "nnacl/conv_parameter.h" void im2col_hwc(const float *in_data, float *data_col, ConvParameter *conv_param); void im2row_hwc(const float *in_data, float *data_row, ConvParameter *conv_param); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling_grad.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.cc similarity index 98% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.cc index 7c37fd38bc..bb8b979861 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.cc @@ -14,7 +14,7 @@ * limitations under the License. */ #include -#include "src/runtime/kernel/arm/nnacl/fp32/pooling_grad.h" +#include "nnacl/fp32_grad/pooling_grad.h" void AvgPoolingGrad(const float *input_ptr, float *output_ptr, PoolingParameter *pooling_param) { int stride_w = pooling_param->stride_w_; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling_grad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.h similarity index 74% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling_grad.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.h index 0f6049afd4..f16c6b4b31 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/pooling_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.h @@ -14,12 +14,12 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_POOLING_GRAD_H_ -#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_POOLING_GRAD_H_ +#ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_POOLING_GRAD_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_POOLING_GRAD_H_ -#include "src/runtime/kernel/arm/nnacl/fp32/pooling.h" +#include "nnacl/fp32/pooling.h" void AvgPoolingGrad(const float *input_ptr, float *output_ptr, PoolingParameter *pooling_param); void MaxPoolingGrad(const float *dy, const int *indices_ptr, float *output_ptr, PoolingParameter *pooling_param); -#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_POOLING_GRAD_H_ +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_GRAD_POOLING_GRAD_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce_grad.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/reduce_grad.cc similarity index 95% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce_grad.cc rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/reduce_grad.cc index 40801c3f35..f5e313310e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce_grad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/reduce_grad.cc @@ -15,7 +15,7 @@ */ #include #include -#include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce_grad.h" +#include "mindspore/lite/nnacl/fp32_grad/reduce_grad.h" static inline bool NextIndex(const int num_dims, const int *dims, int *current) { int carry = 1; @@ -108,8 +108,7 @@ void ReduceSumByAxes(const float *input, const int *input_dims, float *output, c if (output_dims[idx] != input_dims[idx]) same_shape = false; } if (same_shape) { - std::copy(input, input + num_outputs * sizeof(float), output); - // memcpy(output, input, num_outputs*sizeof(float)); + memcpy(output, input, num_outputs * sizeof(float)); return; } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce_grad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/reduce_grad.h similarity index 100% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce_grad.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/reduce_grad.h diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax_grad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/softmax_grad.h similarity index 90% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax_grad.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/softmax_grad.h index e9b0955d9d..e110308571 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/softmax_grad.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fp32_grad/softmax_grad.h @@ -17,13 +17,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_SOFTMAX_GRAD_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_SOFTMAX_GRAD_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct SoftmaxCrossEntropyParameter { +typedef struct SoftmaxCrossEntropyParameter { OpParameter op_parameter; int32_t batch_size_; unsigned int number_of_classes_; int n_dim_; int input_shape_[5]; -}; +} SoftmaxCrossEntropyParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FP32_SOFTMAX_GRAD_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.cc index 9c8aa0fa8c..c740c9cdb1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.cc @@ -14,7 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/fused_batchnorm.h" +#include "nnacl/fused_batchnorm.h" +#include void FusedBatchNorm(const float *input_ptr, const float *scale_ptr, const float *offest_ptr, const float *mean_ptr, const float *variance_ptr, int *input_shapes, float epsilon, float *output_ptr) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.h index 8aac705e46..259b967ac6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/fused_batchnorm.h @@ -17,13 +17,12 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FUSED_BATCHNORM_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_FUSED_BATCHNORM_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct FusedBatchNormParameter { +typedef struct FusedBatchNormParameter { OpParameter op_parameter_; float epsilon_; -}; - +} FusedBatchNormParameter; void FusedBatchNorm(const float *input_ptr, const float *scale_ptr, const float *offest_ptr, const float *mean_ptr, const float *variance_ptr, int *input_shapes, float epsilon, float *output_ptr); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.cc index 31ac63ec5b..bb7e59f509 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.h" +#include "nnacl/int8/arg_min_max_int8.h" #include void CalcParameter(const int *shape, int dims_number, int axis, int *pre_axis_count, int *axis_count, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.h index ec4f259715..20cd3db8e1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arg_min_max_int8.h @@ -16,8 +16,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_ARG_MIN_MAX_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_ARG_MIN_MAX_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/arg_min_max_parameter.h" -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "nnacl/arg_min_max_parameter.h" +#include "nnacl/quantization/quantize.h" void ArgMinMaxQuant(const int8_t *input, int8_t *output, const int *in_shape, ArgMinMaxParameter *param, QuantArg *in_quant, QuantArg *out_quant); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.cc index d949d64179..893af2bb15 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.cc @@ -14,11 +14,11 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.h" +#include "nnacl/int8/arithmetic_int8.h" #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" int ElementNotEqual(int8_t *input0, int8_t *input1, int8_t *output, int element_size) { for (int index = 0; index < element_size; ++index) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.h index 9229657f51..01562a9e90 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_int8.h @@ -16,7 +16,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_ARITHMETIC_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_ARITHMETIC_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" int ElementNotEqual(int8_t *input0, int8_t *input1, int8_t *output, int element_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.cc index b6b98d109e..7ae664077c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.cc @@ -15,12 +15,12 @@ */ #include -#include "src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.h" +#include "nnacl/int8/arithmetic_self_int8.h" #ifdef ENABLE_NEON #include -#include "src/runtime/kernel/arm/nnacl/add_int8.h" +#include "nnacl/add_int8.h" #endif -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/quantization/fixed_point.h" int ElementFloor(int8_t *input, int8_t *output, int element_size, ArithSelfQuantArg para) { float in_scale = para.in_args_.scale_; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.h index 78c9a42f25..b2d8abc7ba 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/arithmetic_self_int8.h @@ -20,8 +20,9 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/quantization/quantize.h" int ElementRound(int8_t *input, int8_t *output, int element_size, ArithSelfQuantArg para); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.cc index a10a0f151b..d226d1d807 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.h" -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" +#include "nnacl/int8/batch_to_space_int8.h" +#include "nnacl/arithmetic_common.h" void BatchToSpaceNoCropForNHWC(const int8_t *input, int8_t *output, const int *in_shape, int out_n, const int *block, QuantArg *in_quant_arg, QuantArg *out_quant_arg) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.h index 7846e9a1e6..b349e2dcc6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/batch_to_space_int8.h @@ -15,8 +15,8 @@ */ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_BATCH_TO_SPACE_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_BATCH_TO_SPACE_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" void BatchToSpaceNoCropForNHWC(const int8_t *input, int8_t *output, const int *in_shape, int out_n, const int *block, QuantArg *in_quant_arg, QuantArg *out_quant_arg); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/common_func.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/common_func.h index 3439fbe1db..a9b4cb9a4b 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/common_func.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/common_func.h @@ -20,8 +20,8 @@ #include #include #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/conv_parameter.h" #ifdef __cplusplus extern "C" { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.cc index 804c80bf93..a9e2b86332 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.cc @@ -14,51 +14,48 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/concat_int8.h" +#include "nnacl/int8/concat_int8.h" +#include "nnacl/concat_parameter.h" #include -void Concat(int8_t **inputs, int8_t *output_ptr, ConcatQuantArg *quant_concat_parm, int axis) { - float output_scale = quant_concat_parm->out_quant_args_.scale_; +void Concat(int8_t **inputs, int8_t *output, ConcatParameter *para, int axis, int64_t real_dst_count, int task_id) { + float output_scale = para->quant_arg_.out_args_.scale_; float output_inverse_scale = 1.f / output_scale; - int input_num = quant_concat_parm->input_num_; - int *output_shape = quant_concat_parm->output_shape_; - int output_dim = quant_concat_parm->output_dim_; - QuantArg *input_quant = quant_concat_parm->in_quant_args_; - int output_zp = quant_concat_parm->out_quant_args_.zp_; + int input_num = para->input_num_; + int count_unit_ = para->count_unit_; + int after_axis_size = para->after_axis_size; + const int *output_shape = para->output_shapes_; + int out_copy_size = output_shape[axis] * after_axis_size; + QuantArg *input_quant = para->quant_arg_.in_args_; + int output_zp = para->quant_arg_.out_args_.zp_; + int max_int8 = para->quant_arg_.output_activation_max_; + int min_int8 = para->quant_arg_.output_activation_min_; + int64_t start = task_id * count_unit_; + int64_t end = start + real_dst_count; - int before_axis_size = 1; - for (int i = 0; i < axis; i++) { - before_axis_size *= output_shape[i]; - } - - int after_axis_size = 1; - for (size_t i = axis + 1; i < output_dim; i++) { - after_axis_size *= output_shape[i]; - } - - for (int k = 0; k < before_axis_size; k++) { + for (int k = start; k < end; k++) { for (int i = 0; i < input_num; i++) { - int *input_shape = quant_concat_parm->input_shapes_[i]; - int copy_size = input_shape[axis] * after_axis_size; - int8_t *input_ptr = inputs[i] + k * copy_size; + const int *input_shape = para->input_shapes_[i]; + int in_copy_size = input_shape[axis] * after_axis_size; + int8_t *input_ptr = inputs[i] + k * in_copy_size; + int8_t *output_ptr = output + k * out_copy_size; if (input_quant[i].scale_ == output_scale && input_quant[i].zp_ == output_zp) { - memcpy(output_ptr, input_ptr, copy_size); + memcpy(output_ptr, input_ptr, in_copy_size); } else { float scale = input_quant[i].scale_ * output_inverse_scale; float bias = -input_quant[i].zp_ * scale; - for (int j = 0; j < copy_size; j++) { + for (int j = 0; j < in_copy_size; j++) { int32_t output_tmp = round(input_ptr[j] * scale + bias) + output_zp; - if (output_tmp > 127) { - output_ptr[j] = 127; - } else if (output_tmp < -128) { - output_ptr[j] = -128; + if (output_tmp > max_int8) { + output_ptr[j] = max_int8; + } else if (output_tmp < min_int8) { + output_ptr[j] = min_int8; } else { - output_ptr[j] = (int8_t)output_tmp; + output_ptr[j] = static_cast(output_tmp); } } } - output_ptr += copy_size; + output += in_copy_size; } } } - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.h index 6b7edb43d5..c6f860c3a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/concat_int8.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_CONCAT_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_CONCAT_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" +#include "nnacl/concat_parameter.h" -void Concat(int8_t **inputs, int8_t *output_ptr, ConcatQuantArg *quant_concat_parm, int axis); +void Concat(int8_t **inputs, int8_t *output_ptr, ConcatParameter *para, int axis, int64_t real_dst_count, int task_id); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_CONCAT_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.cc index 784b754cd8..46f107f09c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.h" +#include "nnacl/int8/conv_depthwise_int8.h" #include -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" -#include "src/runtime/kernel/arm/nnacl/int8/common_func.h" +#include "nnacl/quantization/fixed_point.h" +#include "nnacl/int8/common_func.h" /*conv depthwise int8 begin*/ void DepthwiseBorderPixelInt8(int8_t *dst, const int16_t *src, const int16_t *weight, const int32_t *bias, int height, @@ -159,18 +159,17 @@ void ConvDwInt8(int8_t *output_data, const int16_t *input_data, const int16_t *w if (sliding->right_ > sliding->left_ && sliding->bottom_ > sliding->top_) { int in_h_start = sliding->top_ * conv_param->stride_h_ - conv_param->pad_h_; int in_w_start = sliding->left_ * conv_param->stride_w_ - conv_param->pad_w_; - const int16_t *in_t = src_data + in_h_start * sliding->in_h_step_ + in_w_start * C4NUM; - int8_t *out_t = dst_data + sliding->top_ * sliding->out_h_step_ + sliding->left_ * C4NUM; + const int16_t *in_t = src_data + in_h_start * sliding->in_h_step_ + in_w_start * sliding->block_channel_; + int8_t *out_t = dst_data + sliding->top_ * sliding->out_h_step_ + sliding->left_ * sliding->block_channel_; #ifdef ENABLE_ARM64 - ConvDwInt8Center( - out_t, in_t, weight, bias, sliding->bottom_ - sliding->top_, sliding->right_ - sliding->left_, - conv_param->kernel_h_, conv_param->kernel_w_, sliding->out_h_step_ * sizeof(int8_t), - sliding->block_channel_ * sizeof(int8_t), sliding->in_sh_step_ * sizeof(int16_t), - sliding->in_sw_step_ * sizeof(int16_t), sliding->in_kh_step_ * sizeof(int16_t), - sliding->in_kw_step_ * sizeof(int16_t), conv_param->conv_quant_arg_.quant_multiplier_[0], - conv_param->conv_quant_arg_.left_shift_[0], conv_param->conv_quant_arg_.right_shift_[0], - conv_param->conv_quant_arg_.quant_args_[2][0].zp_, conv_param->conv_quant_arg_.out_act_min_[0], - conv_param->conv_quant_arg_.out_act_max_[0]); + ConvDwInt8Center(out_t, in_t, weight, bias, sliding->bottom_ - sliding->top_, sliding->right_ - sliding->left_, + conv_param->kernel_h_, conv_param->kernel_w_, sliding->out_h_step_ * sizeof(int8_t), + sliding->block_channel_ * sizeof(int8_t), sliding->in_sh_step_ * sizeof(int16_t), + sliding->in_sw_step_ * sizeof(int16_t), sliding->in_kh_step_ * sizeof(int16_t), + sliding->in_kw_step_ * sizeof(int16_t), conv_param->conv_quant_arg_.quant_multiplier_[0], + conv_param->conv_quant_arg_.left_shift_[0], conv_param->conv_quant_arg_.right_shift_[0], + conv_param->conv_quant_arg_.quant_args_[2][0].zp_, conv_param->conv_quant_arg_.out_act_min_[0], + conv_param->conv_quant_arg_.out_act_max_[0]); #else DepthwiseCenterInt8( out_t, in_t, weight, bias, sliding->bottom_ - sliding->top_, sliding->right_ - sliding->left_, @@ -315,15 +314,15 @@ void DeconvDwInt8(int8_t *output_data, int32_t *output_buffer, const int16_t *in if (sliding->right_ > sliding->left_ && sliding->bottom_ > sliding->top_) { int oh_h_start = sliding->top_ * conv_param->stride_h_ - conv_param->pad_h_; int oh_w_start = sliding->left_ * conv_param->stride_w_ - conv_param->pad_w_; - int32_t *out_t = output_buffer + oh_h_start * sliding->in_h_step_ + oh_w_start * C4NUM; + int32_t *out_t = output_buffer + oh_h_start * sliding->in_h_step_ + oh_w_start * sliding->block_channel_; const int16_t *in_t = src_data + sliding->top_ * sliding->out_h_step_ + sliding->left_ * sliding->block_channel_; #ifdef ENABLE_ARM64 - DeconvDwInt8Center(out_t, in_t, weight, sliding->bottom_ - sliding->top_, - sliding->right_ - sliding->left_, conv_param->kernel_h_, conv_param->kernel_w_, - sliding->out_h_step_ * sizeof(int16_t), sliding->block_channel_ * sizeof(int16_t), - sliding->in_sh_step_ * sizeof(int32_t), sliding->in_sw_step_ * sizeof(int32_t), - sliding->in_kh_step_ * sizeof(int32_t), sliding->in_kw_step_ * sizeof(int32_t)); + DeconvDwInt8Center(out_t, in_t, weight, sliding->bottom_ - sliding->top_, sliding->right_ - sliding->left_, + conv_param->kernel_h_, conv_param->kernel_w_, sliding->out_h_step_ * sizeof(int16_t), + sliding->block_channel_ * sizeof(int16_t), sliding->in_sh_step_ * sizeof(int32_t), + sliding->in_sw_step_ * sizeof(int32_t), sliding->in_kh_step_ * sizeof(int32_t), + sliding->in_kw_step_ * sizeof(int32_t)); #else DeconvDepthwiseCenterInt8(out_t, in_t, weight, sliding->bottom_ - sliding->top_, sliding->right_ - sliding->left_, conv_param->kernel_h_, conv_param->kernel_w_, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.h index 555c3693ab..f4c484e7e2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_depthwise_int8.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_CONV_DEPTHWISE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_CONV_DEPTHWISE_H_ -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/fp32/conv_depthwise.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/fp32/conv_depthwise.h" void ConvDwInt8(int8_t *output_data, const int16_t *input_data, const int16_t *weight_data, const int32_t *bias_data, const ConvParameter *conv_param, const SlidingWindowParam *sliding, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.cc index fa02fd99f1..1fe223c911 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/conv_int8.h" +#include "nnacl/int8/conv_int8.h" #include -#include "src/runtime/kernel/arm/nnacl/winograd_transform.h" -#include "src/runtime/kernel/arm/nnacl/int8/common_func.h" +#include "nnacl/winograd_transform.h" +#include "nnacl/int8/common_func.h" void IndirectGemmInt8(int8_t *dst, int32_t *tmp_dst, const int8_t *src, const int8_t *weight, const int32_t *bias, int ic4, size_t kernel_plane, size_t output_channel, const int32_t *input_sum, @@ -29,11 +29,13 @@ void IndirectGemmInt8(int8_t *dst, int32_t *tmp_dst, const int8_t *src, const in int32_t act_min = conv_param->conv_quant_arg_.out_act_min_[0]; int32_t act_max = conv_param->conv_quant_arg_.out_act_max_[0]; #ifdef __aarch64__ - IndirectGemmInt8_4x4(dst, src, weight, bias, kernel_plane, ic4, output_channel, output_channel * sizeof(int8_t), - input_sum, act_min, act_max, out_zp, out_multiplier, shift_before, shift_after); + IndirectGemmInt8_4x4(dst, src, weight, bias, UP_DIV(kernel_plane, C4NUM), ic4, output_channel, + output_channel * sizeof(int8_t), input_sum, act_min, act_max, out_zp, out_multiplier, + shift_before, shift_after); #elif defined(ENABLE_ARM32) - IndirectGemmInt8_2x4(dst, src, weight, bias, kernel_plane, ic4, output_channel, output_channel * sizeof(int8_t), - input_sum, act_min, act_max, out_zp, out_multiplier, shift_before, shift_after); + IndirectGemmInt8_2x4(dst, src, weight, bias, UP_DIV(kernel_plane, C4NUM), ic4, output_channel, + output_channel * sizeof(int8_t), input_sum, act_min, act_max, out_zp, out_multiplier, + shift_before, shift_after); #else int tile_num = conv_param->tile_num_; int plane_c4 = UP_DIV(kernel_plane, C4NUM); @@ -126,10 +128,10 @@ void IndirectGemmInt8Opt(int8_t *dst, int32_t *tmp_dst, const int8_t *src, const void Conv3x3Uint8Gemm(int32_t *dst, const int16_t *src, const int16_t *weight, int oc, int ic8, size_t real_cal_num) { int oc4 = UP_DIV(oc, C4NUM); - int input_unit_square = 16; #ifdef ENABLE_ARM IndirectGemmInt16to32_8x4(dst, src, weight, 16, ic8, oc4, oc4 * 4 * 16 * sizeof(int32_t)); #else + int input_unit_square = 16; for (int c = 0; c < oc4; c++) { int filter_oc_offset = c * input_unit_square * ic8 * C8NUM * C4NUM; int dst_oc_offset = c * input_unit_square * C4NUM; @@ -198,7 +200,7 @@ void ConvInt8(int8_t *input_data, int8_t *packed_input, int8_t *packed_weight, c for (int thread_id = task_id; thread_id < output_tile_count; thread_id += thread_count) { int start_index = thread_id * tile_n; int real_cal_num = (output_count - start_index) < tile_n ? (output_count - start_index) : tile_n; - int32_t *tmp_input_sum = input_sum + thread_id * tile_n; + int32_t *tmp_input_sum = input_sum + task_id * tile_n; int8_t *gemm_input = packed_input + thread_id * unit_size * tile_n + gemm_in_batch_offset; // clear tmp buffer before compute memset(gemm_input, (int8_t)input_zp, unit_size * tile_n); @@ -208,15 +210,16 @@ void ConvInt8(int8_t *input_data, int8_t *packed_input, int8_t *packed_weight, c int tmp_dst_offset = task_id * tile_n * conv_param->output_channel_; memset(tmp_dst + tmp_dst_offset, 0, tmp_dst_size); - Im2ColPackUnitInt8(input_data + in_batch_offset, gemm_input, real_cal_num, start_index, input_sum, conv_param); + Im2ColPackUnitInt8(input_data + in_batch_offset, gemm_input, real_cal_num, start_index, tmp_input_sum, + conv_param); if (real_cal_num == tile_n) { int8_t *gemm_output = output_data + out_offset; IndirectGemmInt8(gemm_output, tmp_dst + tmp_dst_offset, gemm_input, packed_weight, bias_data, ic4, kernel_plane, - out_channel, input_sum, conv_param); + out_channel, tmp_input_sum, conv_param); } else { // res part IndirectGemmInt8(tmp_out, tmp_dst + tmp_dst_offset, gemm_input, packed_weight, bias_data, ic4, kernel_plane, - out_channel, input_sum, conv_param); + out_channel, tmp_input_sum, conv_param); memcpy(output_data + out_offset, tmp_out, real_cal_num * out_channel); } } @@ -253,7 +256,7 @@ void ConvInt8Opt(int8_t *input_data, int8_t *packed_input, int8_t *packed_weight int start_index = thread_id * tile_n; int real_cal_num = (output_count - start_index) < tile_n ? (output_count - start_index) : tile_n; // todo - int32_t *tmp_input_sum = input_sum + thread_id * tile_n; + int32_t *tmp_input_sum = input_sum + task_id * tile_n; int8_t *gemm_input = packed_input + thread_id * unit_size * tile_n + gemm_in_batch_offset; // clear tmp buffer before compute memset(gemm_input, (int8_t)input_zp, unit_size * tile_n); @@ -263,15 +266,16 @@ void ConvInt8Opt(int8_t *input_data, int8_t *packed_input, int8_t *packed_weight int tmp_dst_offset = task_id * tile_n * conv_param->output_channel_; memset(tmp_dst + tmp_dst_offset, 0, tmp_dst_size); - Im2ColPackUnitInt8Opt(input_data + in_batch_offset, gemm_input, real_cal_num, start_index, input_sum, conv_param); + Im2ColPackUnitInt8Opt(input_data + in_batch_offset, gemm_input, real_cal_num, start_index, tmp_input_sum, + conv_param); if (real_cal_num == tile_n) { int8_t *gemm_output = output_data + out_offset; IndirectGemmInt8Opt(gemm_output, tmp_dst + tmp_dst_offset, gemm_input, packed_weight, bias_data, ic4, - kernel_plane, out_channel, input_sum, conv_param, gemm_func); + kernel_plane, out_channel, tmp_input_sum, conv_param, gemm_func); } else { // res part IndirectGemmInt8Opt(tmp_out, tmp_dst + tmp_dst_offset, gemm_input, packed_weight, bias_data, ic4, kernel_plane, - out_channel, input_sum, conv_param, gemm_func); + out_channel, tmp_input_sum, conv_param, gemm_func); memcpy(output_data + out_offset, tmp_out, real_cal_num * out_channel); } } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.h index 96f08c0c6b..1ec29d6074 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/conv_int8.h @@ -19,12 +19,12 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/common_func.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/winograd_utils.h" -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "nnacl/pack.h" +#include "nnacl/op_base.h" +#include "nnacl/common_func.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/winograd_utils.h" +#include "nnacl/quantization/quantize.h" typedef void (*GEMM_FUNC)(int8_t *dst, const int8_t *src, const int8_t *weight, const int32_t *bias, size_t ksize, size_t ic4, size_t output_channel, size_t offset, const int32_t *input_sum, size_t act_min, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.cc index e7708fcc2a..f13c1ed5b0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/crop_parameter.h" -#include "src/runtime/kernel/arm/nnacl/int8/crop_int8.h" +#include "nnacl/crop_parameter.h" +#include "nnacl/int8/crop_int8.h" #include void Crop(const int8_t *input, int8_t *output, int task_id, CropParameter *para) { @@ -40,6 +40,9 @@ void Crop1D(const int8_t *input, int8_t *output, int task_id, CropParameter *par const int out_batch = para->out_shape_[0]; const int thread_count = para->thread_count_; int64_t task_id_stride = thread_count > 1 ? UP_DIV(out_batch, thread_count) : out_batch; + if (task_id_stride <= 0) { + return; + } float in_scale = para->quant_arg.in_args_.scale_; int32_t in_zp = para->quant_arg.in_args_.zp_; @@ -78,6 +81,9 @@ void Crop2D(const int8_t *input, int8_t *output, int task_id, CropParameter *par const int out_height = para->out_shape_[1]; const int thread_count = para->thread_count_; int64_t task_id_stride = thread_count > 1 ? UP_DIV(out_height, thread_count) : out_height; + if (task_id_stride <= 0) { + return; + } float in_scale = para->quant_arg.in_args_.scale_; int32_t in_zp = para->quant_arg.in_args_.zp_; @@ -120,6 +126,12 @@ void Crop3D(const int8_t *input, int8_t *output, int task_id, CropParameter *par const int out_height = para->out_shape_[1]; const int out_width = para->out_shape_[2]; + const int thread_count = para->thread_count_; + int64_t task_id_stride = thread_count > 1 ? UP_DIV(out_height, thread_count) : out_height; + if (task_id_stride <= 0) { + return; + } + const int in_stride_h = in_width; const int in_stride_n = in_stride_h * in_height; @@ -133,8 +145,6 @@ void Crop3D(const int8_t *input, int8_t *output, int task_id, CropParameter *par float scale = in_scale / out_scale; float bias = -in_zp * scale; - const int thread_count = para->thread_count_; - int64_t task_id_stride = thread_count > 1 ? UP_DIV(out_height, thread_count) : out_height; for (int n = 0; n < out_batch; n++) { for (int t = 0; t < task_id_stride; t++) { auto h = t + task_id * task_id_stride; @@ -173,6 +183,12 @@ void Crop4D(const int8_t *input, int8_t *output, int task_id, CropParameter *par const int out_width = para->out_shape_[2]; const int out_channel = para->out_shape_[3]; + const int thread_count = para->thread_count_; + int64_t task_id_stride = thread_count > 1 ? UP_DIV(out_height, thread_count) : out_height; + if (task_id_stride <= 0) { + return; + } + const int in_stride_w = in_channel; const int in_stride_h = in_channel * in_width; const int in_stride_n = in_stride_h * in_height; @@ -188,8 +204,6 @@ void Crop4D(const int8_t *input, int8_t *output, int task_id, CropParameter *par float scale = in_scale / out_scale; float bias = -in_zp * scale; - const int thread_count = para->thread_count_; - int64_t task_id_stride = thread_count > 1 ? UP_DIV(out_height, thread_count) : out_height; for (int n = 0; n < out_batch; n++) { for (int t = 0; t < task_id_stride; t++) { auto h = t + task_id * task_id_stride; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.h index d574b0813b..1c4b310333 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/crop_int8.h @@ -16,8 +16,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_CROP_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_CROP_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/crop_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/crop_parameter.h" void Crop(const int8_t *input, int8_t *output, int task_id, CropParameter *para); void Crop1D(const int8_t *input, int8_t *output, int task_id, CropParameter *para); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.cc index 32586063a3..691ae7ba0c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.cc @@ -14,7 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/deconv.h" +#include "nnacl/int8/deconv.h" +#include "nnacl/int8/matmul_int8.h" int DeConvInt8(const int8_t *input, const int8_t *weight, int32_t *output, size_t row8, size_t col8, size_t deep, ConvParameter *conv_param) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.h index 145a0c1ff6..041d8f93c9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/deconv.h @@ -17,12 +17,11 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_DECONV_H_ #include -#include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/common_func.h" -#include "src/runtime/kernel/arm/nnacl/int8/matmul.h" +#include "nnacl/pack.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/common_func.h" int DeConvInt8(const int8_t *input, const int8_t *weight, int32_t *output, size_t row8, size_t col8, size_t deep, ConvParameter *conv_param); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.cc index 4ee38a88c4..5c98da4d18 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.h" +#include "nnacl/int8/depth_to_space_int8.h" #include void DepthToSpaceForNHWC(const int8_t *input, int8_t *output, int *in_shape, DepthToSpaceParameter *param, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.h index b2abb1f068..a8fbe0ccaa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/depth_to_space_int8.h @@ -16,8 +16,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_DEPTH_TO_SPACE_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_DEPTH_TO_SPACE_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/depth_to_space_parameter.h" -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "nnacl/depth_to_space_parameter.h" +#include "nnacl/quantization/quantize.h" void DepthToSpaceForNHWC(const int8_t *input, int8_t *output, int *in_shape, DepthToSpaceParameter *param, QuantArg *in_quant_arg, QuantArg *out_quant_arg); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.cc index 3e048590c8..21d8909195 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/hswish_int8.h" +#include "nnacl/int8/hswish_int8.h" int16_t SaturatingLeftShift(int16_t value, int shift_num) { int32_t result = (int32_t)value * (1 << shift_num); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.h index 2d32aee083..62577f3ed4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/hswish_int8.h @@ -17,11 +17,11 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_HSWISH_INT8_H_ #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/quantization/fixed_point.h" -struct HswishQuantArg { +typedef struct HswishQuantArg { double input_scale; int32_t input_zp; double output_scale; @@ -30,7 +30,7 @@ struct HswishQuantArg { int32_t relu6_multiplier_exponent; int16_t output_multiplier_fixedpoint_int16; int32_t output_multiplier_exponent; -}; +} HswishQuantArg; int HSwishInt8(const int8_t *src, int length, int8_t *dst, HswishQuantArg *arg); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul_int8.cc similarity index 94% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul.cc rename to mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul_int8.cc index 972dfd46c5..30185a750d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul_int8.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/matmul.h" +#include "nnacl/int8/matmul_int8.h" #include -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/quantization/fixed_point.h" void RowMajor2Row8MajorInt8(int8_t *src_ptr, int8_t *dst_ptr, int row, int col) { for (int r = 0; r < row; r++) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul_int8.h similarity index 92% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul_int8.h index 7e2cc43ca9..3e189d1472 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/matmul_int8.h @@ -17,8 +17,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_MATMUL_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_MATMUL_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "nnacl/op_base.h" void MatMulInt8(const int8_t *a, const int8_t *b, int32_t *c, const int row8, const int col8, const int deep, const int32_t a_zp, const int32_t b_zp); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.cc index 087e6b0f9d..98157e78ea 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.cc @@ -14,13 +14,13 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/mul_int8.h" -#include "src/runtime/kernel/arm/nnacl/mul_parameter.h" +#include "nnacl/int8/mul_int8.h" +#include "nnacl/mul_parameter.h" #ifdef ENABLE_NEON #include -#include "src/runtime/kernel/arm/nnacl/add_int8.h" +#include "nnacl/add_int8.h" #endif -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/quantization/fixed_point.h" #ifdef ENABLE_NEON @@ -58,6 +58,7 @@ void MulInt8NEON(int8_t *input0_data, int8_t *input1_data, int8_t *output_data, int16x8_t res_s16 = vcombine_s16(sum_low, sum_high); int8x8_t res_u8_n0 = vqmovn_s16(res_s16); vst1_s8(output_data, res_u8_n0); + output_data += 8; } } #endif diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.h index 000fa37b8e..1eb4f3e1f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/mul_int8.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_MUL_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_MUL_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/mul_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/mul_parameter.h" void Mul(int8_t *input0_data, int8_t *input1_data, int8_t *output_data, int64_t real_dst_count, MulQuantArg para); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.cc index 55c6d93404..8a9b2858e6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/pad.h" -#include "src/runtime/kernel/arm/nnacl/common_func.h" +#include "nnacl/int8/pad.h" +#include "nnacl/common_func.h" void PadConstant4D(const int8_t *in_data, int8_t *out_data, const int32_t *in_dims, const int32_t *out_dims, const int32_t *paddings) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.h index 336af7f852..a2ea97c499 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pad.h @@ -18,8 +18,8 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_PAD_INT8_H_ #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/pad_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/pad_parameter.h" void PadConstant4D(const int8_t *in_data, int8_t *out_data, const int32_t *in_dims, const int32_t *out_dims, const int32_t *paddings); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.cc index 854e7e7fc3..45245df425 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/pooling_int8.h" -#include "src/runtime/kernel/arm/nnacl/common_func.h" +#include "nnacl/int8/pooling_int8.h" +#include "nnacl/common_func.h" void AvgPoolingInt8(const int8_t *input_ptr, int8_t *output_ptr, PoolingParameter *pooling_param, int task_id) { int stride_w = pooling_param->stride_w_; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.h index 007b60f32d..f9a471fdf2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/pooling_int8.h @@ -20,8 +20,8 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/fp32/pooling.h" +#include "nnacl/op_base.h" +#include "nnacl/fp32/pooling.h" void AvgPoolingInt8(const int8_t *input_ptr, int8_t *output_ptr, PoolingParameter *pooling_param, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/prelu_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/prelu_int8.cc new file mode 100644 index 0000000000..5e91865cbd --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/prelu_int8.cc @@ -0,0 +1,57 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "nnacl/prelu_parameter.h" +#include "nnacl/int8/prelu_int8.h" + +void prelu(int8_t *inputs, int8_t *output_ptr, PreluParameter *quant_prelu_parm, int task_id) { + float output_scale = quant_prelu_parm->quant_arg.out_args_.scale_; + int output_zp = quant_prelu_parm->quant_arg.out_args_.zp_; + float output_inverse_scale = 1.f / output_scale; + int output_dim = quant_prelu_parm->input_dim_; + + QuantArg *input_quant = new QuantArg; + for (int i = 0; i < output_dim; i++) { + input_quant[i].scale_ = quant_prelu_parm->quant_arg.in_args_.scale_; + input_quant[i].zp_ = quant_prelu_parm->quant_arg.in_args_.zp_; + } + + for (int i = 0; i < output_dim; i++) { + float scale = input_quant[i].scale_ * output_inverse_scale; + float bias = -input_quant[i].zp_ * scale; + for (int j = task_id; j < quant_prelu_parm->element_num; j += quant_prelu_parm->op_parameter_.thread_num_) { + if (inputs[j] <= 0) { + int32_t output_tmp = round(inputs[j] * quant_prelu_parm->alpha_ * scale + bias) + output_zp; + if (output_tmp > 127) { + output_ptr[j] = 127; + } else if (output_tmp < -128) { + output_ptr[j] = -128; + } else { + output_ptr[j] = (int8_t)output_tmp; + } + } else { + int32_t output_tmp = round(inputs[j] * scale + bias) + output_zp; + if (output_tmp > 127) { + output_ptr[j] = 127; + } else if (output_tmp < -128) { + output_ptr[j] = -128; + } else { + output_ptr[j] = (int8_t)output_tmp; + } + } + } + } +} diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/prelu_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/prelu_int8.h new file mode 100644 index 0000000000..947caf9a21 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/prelu_int8.h @@ -0,0 +1,25 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_PRELU_INT8_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_PRELU_INT8_H_ + +#include "nnacl/op_base.h" +#include "nnacl/prelu_parameter.h" + +void prelu(int8_t *inputs, int8_t *output_ptr, PreluParameter *quant_Prelu_parm, int task_id); + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_PRELU_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.cc index de24938986..a0d17523df 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.cc @@ -14,8 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include +#include "nnacl/int8/quant_dtype_cast.h" +#include "nnacl/errorcode.h" int DequantizeInt8(int8_t *quant_values, float *real_values, float scale, int32_t zp, int size) { if (quant_values == nullptr || real_values == nullptr) { @@ -23,7 +24,7 @@ int DequantizeInt8(int8_t *quant_values, float *real_values, float scale, int32_ } for (int i = 0; i < size; ++i) { - real_values[i] = (quant_values[i] + zp) * scale; + real_values[i] = (quant_values[i] - zp) * scale; } return NNACL_OK; } @@ -34,7 +35,14 @@ int QuantizeToInt8(float *real_values, int8_t *quant_values, float scale, int32_ } for (int i = 0; i < size; ++i) { - quant_values[i] = (int8_t)round(real_values[i] / scale + zp); + float temp = round(real_values[i] / scale + zp); + if (temp > 127) { + quant_values[i] = 127; + } else if (temp < -128) { + quant_values[i] = -128; + } else { + quant_values[i] = (int8_t)temp; + } } return NNACL_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.h index d11ae2c5f6..8d74a8a6d8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/quant_dtype_cast.h @@ -17,13 +17,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_QUANTDTYPECAST_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_QUANTDTYPECAST_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct QuantDTypeCastParameter { +typedef struct QuantDTypeCastParameter { OpParameter op_parameter_; int32_t srcT; int32_t dstT; -}; +} QuantDTypeCastParameter; int DequantizeInt8(int8_t *quant_values, float *real_values, float scale, int32_t zp, int size); int QuantizeToInt8(float *real_values, int8_t *quant_values, float scale, int32_t zp, int size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/relu_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/relux_int8.h similarity index 78% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/int8/relu_int8.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/int8/relux_int8.h index 88d5adcb13..c0eba9a5d8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/relu_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/relux_int8.h @@ -17,19 +17,22 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RELU_INT8_H_ #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/quantization/fixed_point.h" +#include "nnacl/quantization/quantize.h" -struct ReluQuantArg { +typedef struct ReluXQuantArg { QuantArg input_arg; QuantArg output_arg; int input_multiplier_; int left_shift_; int right_shift_; -}; + int quantized_output_min; + int quantized_output_max; +} ReluXQuantArg; -inline void ReluInt8(const int8_t *src, int length, int8_t *dst, ReluQuantArg *arg) { +inline void ReluXInt8(const int8_t *src, int length, int8_t *dst, ReluXQuantArg *arg) { for (int i = 0; i < length; ++i) { if (src[i] <= arg->input_arg.zp_) { dst[i] = arg->output_arg.zp_; @@ -39,8 +42,7 @@ inline void ReluInt8(const int8_t *src, int length, int8_t *dst, ReluQuantArg *a const int32_t scaled_input = SaturatingRoundingDoublingHighMul(input_val, arg->input_multiplier_); const int32_t shifted_input = RoundingDivideByPOT(scaled_input * (1 << arg->left_shift_), -arg->right_shift_); const int32_t output = shifted_input + arg->output_arg.zp_; - dst[i] = (int8_t)output; + dst[i] = (int8_t)MSMIN(output, arg->quantized_output_max); } } - #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RELU_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.cc index 3993e3d3d2..786cc048f9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.cc @@ -14,28 +14,27 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/reshape_int8.h" +#include "nnacl/int8/reshape_int8.h" +#include "nnacl/reshape_parameter.h" #include -void Reshape(int8_t *input_ptr, int8_t *output_ptr, size_t data_size, int input_num, QuantArg in_quant_arg, - QuantArg out_quant_arg) { - if (in_quant_arg.scale_ == out_quant_arg.scale_ && in_quant_arg.zp_ == out_quant_arg.zp_) { - memcpy(output_ptr, input_ptr, data_size); +void Reshape(int8_t *input_ptr, int8_t *output_ptr, int64_t real_dst_count, ReshapeQuantArg para) { + if (para.in_args_.scale_ == para.out_args_.scale_ && para.in_args_.zp_ == para.out_args_.zp_) { + memcpy(output_ptr, input_ptr, real_dst_count); } else { - float output_inverse_scale = 1.f / out_quant_arg.scale_; - float scale = in_quant_arg.scale_ * output_inverse_scale; - float bias = -in_quant_arg.zp_ * scale; - int32_t output_zp = out_quant_arg.zp_; - for (int i = 0; i < input_num; i++) { + float output_inverse_scale = 1.f / para.out_args_.scale_; + float scale = para.in_args_.scale_ * output_inverse_scale; + float bias = -para.in_args_.zp_ * scale; + int32_t output_zp = para.out_args_.zp_; + for (int i = 0; i < real_dst_count; i++) { int32_t output_tmp = round(input_ptr[i] * scale + bias) + output_zp; - if (output_tmp > 127) { - output_ptr[i] = 127; - } else if (output_tmp < -128) { - output_ptr[i] = -128; + if (output_tmp > para.output_activation_max_) { + output_ptr[i] = para.output_activation_max_; + } else if (output_tmp < para.output_activation_min_) { + output_ptr[i] = para.output_activation_min_; } else { - output_ptr[i] = (int8_t)output_tmp; + output_ptr[i] = static_cast(output_tmp); } } } } - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.h index 129178086a..4f3bf77e3a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/reshape_int8.h @@ -16,10 +16,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RESHAHPE_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RESHAHPE_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" +#include "nnacl/reshape_parameter.h" -void Reshape(int8_t *input_ptr, int8_t *output_ptr, size_t data_size, int input_num, QuantArg in_quant_arg, - QuantArg out_quant_arg); +void Reshape(int8_t *input_ptr, int8_t *output_ptr, int64_t real_dst_count, ReshapeQuantArg para); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RESHAHPE_INT8_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/resize.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/resize.cc new file mode 100644 index 0000000000..dd1a58823d --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/resize.cc @@ -0,0 +1,179 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include "nnacl/int8/resize.h" +#include "nnacl/common_func.h" +#include "nnacl/quantization/fixed_point.h" +#include "nnacl/errorcode.h" + + +int ResizeBilinearInt8(const int8_t *input_data, int8_t *output_data, const int *input_shape, const int *output_shape, + const bool align_corners, QuantArg *quant_in, QuantArg *quant_out, const QuantMulArg *mul_arg, + int tid, int thread_num) { + if (input_data == nullptr || output_data == nullptr || input_shape == nullptr || output_shape == nullptr) { + return NNACL_NULL_PTR; + } + + int32_t in_n = input_shape[0]; + int32_t in_h = input_shape[1]; + int32_t in_w = input_shape[2]; + int32_t in_c = input_shape[3]; + + int32_t new_height = output_shape[1]; + int32_t new_width = output_shape[2]; + int32_t height_scale, width_scale; + ComputeScale(in_h, new_height, align_corners, &height_scale); + ComputeScale(in_w, new_width, align_corners, &width_scale); + + int n, h, w, c; + for (n = 0; n < in_n; n++) { + for (h = tid; h < new_height; h += thread_num) { + // float actual_y = (float)h * height_scale; + int base_offset = 20; + int scaled_actual_y; + int bottom, top; + int scaled_bottom_weight, scaled_top_weight; + ComputeInterpolationArgs(h, height_scale, in_h, &scaled_actual_y, &bottom, &scaled_bottom_weight, &top, + &scaled_top_weight); + for (w = 0; w < new_width; w++) { + int scaled_actual_x; + int left, right; + int scaled_left_weight, scaled_right_weight; + ComputeInterpolationArgs(w, width_scale, in_w, &scaled_actual_x, &left, &scaled_left_weight, &right, + &scaled_right_weight); + for (c = 0; c < in_c; c++) { + const int64_t bottom_left_value = + (int64_t)(input_data[offset(input_shape, n, bottom, left, c)] - quant_in->zp_) * scaled_bottom_weight * + scaled_left_weight; + const int64_t bottom_right_value = + (int64_t)(input_data[offset(input_shape, n, bottom, right, c)] - quant_in->zp_) * scaled_bottom_weight * + scaled_right_weight; + const int64_t top_left_value = (int64_t)(input_data[offset(input_shape, n, top, left, c)] - quant_in->zp_) * + scaled_top_weight * scaled_left_weight; + const int64_t top_right_value = (int64_t)(input_data[offset(input_shape, n, top, right, c)] - quant_in->zp_) * + scaled_top_weight * scaled_right_weight; + const int64_t scaled_interp_value = bottom_left_value + bottom_right_value + top_left_value + top_right_value; + int32_t interp_value; + if (scaled_interp_value >= 0) { + interp_value = (scaled_interp_value + (1 << 19)) / (1 << 20); + } else { + interp_value = (scaled_interp_value - (1 << 19)) / (1 << 20); + } + + const int out_interp_value = + MultiplyByQuantizedMultiplier(interp_value, mul_arg->multiplier_, mul_arg->left_shift_ + base_offset, + mul_arg->right_shift_ - base_offset) + + quant_out->zp_; + int8_t out_value; + out_value = out_interp_value > INT8_MAX ? INT8_MAX : out_interp_value; + out_value = out_value < INT8_MIN ? INT8_MIN : out_value; + output_data[offset(output_shape, n, h, w, c)] = out_value; + } + } + } + } + return NNACL_OK; +} + +int ResizeNearestNeighborInt8Simple(const int8_t *input_data, int8_t *output_data, const int *input_shape, + const int *output_shape, const bool align_corners, int tid, int thread_num) { + int batch, y, x, c; + c = output_shape[3]; + int in_h, in_w, new_height, new_width; + in_h = input_shape[1]; + in_w = input_shape[2]; + new_height = output_shape[1]; + new_width = output_shape[2]; + + for (batch = 0; batch < output_shape[0]; batch++) { + for (y = tid; y < output_shape[1]; y += thread_num) { + int input_y; + ComputeNearestNeighborInt(y, in_h, new_height, align_corners, &input_y); + for (x = 0; x < output_shape[2]; x++) { + int input_x; + ComputeNearestNeighborInt(x, in_w, new_width, align_corners, &input_x); + int in_offset = offset(input_shape, batch, input_y, input_x, 0); + int out_offset = offset(output_shape, batch, y, x, 0); + memcpy(output_data + out_offset, input_data + in_offset, c * sizeof(int8_t)); + } + } + } + + return NNACL_OK; +} + +void ComputeScale(const int32_t in_value, const int32_t out_value, const bool align_corners, int32_t *scale) { + *scale = (in_value * (1 << 10) + out_value / 2) / out_value; + if (align_corners && out_value > 1) { + *scale = ((in_value - 1) * (1 << 10) + (out_value - 1) / 2) / (out_value - 1); + } +} + +void ComputeInterpolationArgs(const int32_t pos, const int32_t scale, const int32_t size, int32_t *scaled_pos, + int32_t *low, int32_t *scaled_low_weight, int32_t *high, int32_t *scaled_high_weight) { + *scaled_pos = pos * scale; + int scale_back = *scaled_pos / (1 << 10); + *low = scale_back > 0 ? scale_back : 0; + *scaled_low_weight = (1 << 10) - (*scaled_pos - (1 << 10) * (*low)); + *high = scale_back + 1 < size ? scale_back + 1 : size - 1; + *scaled_high_weight = *scaled_pos - (1 << 10) * (*low); +} + +void ComputeNearestNeighborInt(const int32_t pos, const int in_size, const int32_t new_size, const bool align_corners, + int32_t *nearest) { + *nearest = (in_size * pos) / new_size; + if (align_corners) { + *nearest = ((in_size - 1) * pos + (new_size - 1) / 2) / (new_size - 1); + } + *nearest = *nearest < in_size ? *nearest : in_size - 1; +} + +int ResizeNearestNeighborInt8(const int8_t *input_data, int8_t *output_data, const int *input_shape, + const int *output_shape, const bool align_corners, const QuantMulArg *multiplier, + QuantArg *quant_in, QuantArg *quant_out, int tid, int thread_num) { + int base_offset = 20; + int32_t batch, y, x, c; + int32_t in_h, in_w, new_height, new_width; + in_h = input_shape[1]; + in_w = input_shape[2]; + new_height = output_shape[1]; + new_width = output_shape[2]; + + for (batch = 0; batch < output_shape[0]; batch++) { + for (y = tid; y < output_shape[1]; y += thread_num) { + int input_y; + ComputeNearestNeighborInt(y, in_h, new_height, align_corners, &input_y); + for (x = 0; x < output_shape[2]; x++) { + int input_x; + ComputeNearestNeighborInt(x, in_w, new_width, align_corners, &input_x); + for (c = 0; c < output_shape[3]; c++) { + int in_offset = offset(input_shape, batch, input_y, input_x, c); + int out_offset = offset(output_shape, batch, y, x, c); + + int32_t out_value = MultiplyByQuantizedMultiplier( + input_data[in_offset] - quant_in->zp_, multiplier->multiplier_, + multiplier->left_shift_ + base_offset, multiplier->right_shift_ - base_offset) + + quant_out->zp_; + out_value = out_value > INT8_MAX ? INT8_MAX : out_value; + out_value = out_value < INT8_MIN ? INT8_MIN : out_value; + output_data[out_offset] = (int8_t)out_value; + } + } + } + } + + return NNACL_OK; +} diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/resize.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/resize.h new file mode 100644 index 0000000000..a684b5bdd4 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/resize.h @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RESIZE_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RESIZE_H_ + +#ifdef ENABLE_NEON +#include +#endif +#include +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" +#include "nnacl/resize_parameter.h" + +int ResizeBilinearInt8(const int8_t *input_data, int8_t *output_data, const int *input_shape, const int *output_shape, + const bool align_corners, QuantArg *quant_in, QuantArg *quant_out, const QuantMulArg *mul_arg, + int tid, int thread_num); + +int ResizeNearestNeighborInt8Simple(const int8_t *input_data, int8_t *output_data, const int *input_shape, + const int *output_shape, const bool align_corners, int tid, int thread_num); + +int ResizeNearestNeighborInt8(const int8_t *input_data, int8_t *output_data, const int *input_shape, + const int *output_shape, const bool align_corners, const QuantMulArg *multiplier, + QuantArg *quant_in, QuantArg *quant_out, int tid, int thread_num); + +void ComputeScale(const int32_t in_value, const int32_t out_value, const bool align_corners, int32_t *scale); + +void ComputeInterpolationArgs(const int32_t pos, const int32_t scale, const int32_t size, int32_t *scaled_pos, + int32_t *low, int32_t *scaled_low_weight, int32_t *high, int32_t *scaled_high_weight); + +void ComputeNearestNeighborInt(const int32_t pos, const int in_size, const int32_t new_size, const bool align_corners, + int32_t *nearest); +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_RESIZE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.cc new file mode 100644 index 0000000000..3729d2798d --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.cc @@ -0,0 +1,30 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "nnacl/int8/sigmoid_int8.h" + +int SigmoidInt8(const int8_t *src, int length, int8_t *dst, SigmoidQuantArg *arg) { + for (int i = 0; i < length; i++) { + const int16_t input_value = src[i] - arg->input_zp; + int16_t output; + output = round(1 / arg->output_scale * (1 / (1 + exp(-arg->input_scale * input_value)))); + output += arg->output_zp; + output = MSMIN(output, 127); + output = MSMAX(output, -128); + dst[i] = (int8_t)output; + } + return 0; +} diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.h new file mode 100644 index 0000000000..7e3d27ff54 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/sigmoid_int8.h @@ -0,0 +1,37 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_Sigmoid_INT8_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_Sigmoid_INT8_H_ + +#include +#include "nnacl/op_base.h" +#include "nnacl/errorcode.h" +#include "nnacl/quantization/fixed_point.h" + +typedef struct SigmoidQuantArg { + double input_scale; + int32_t input_zp; + double output_scale; + int32_t output_zp; + int16_t relu6_multiplier_fixedpoint_int16; + int32_t relu6_multiplier_exponent; + int16_t output_multiplier_fixedpoint_int16; + int32_t output_multiplier_exponent; +} SigmoidQuantArg; + +int SigmoidInt8(const int8_t *src, int length, int8_t *dst, SigmoidQuantArg *arg); + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_Sigmoid_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.cc index 0428717522..e75a515c84 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/softmax_int8.h" -#include +#include "nnacl/int8/softmax_int8.h" +#include int Softmax(const int8_t *input_ptr, int8_t *output_ptr, int count, float *exp_data, float *sum_data, SoftmaxQuantArg quant_param, SoftmaxParameter *parameter) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.h index 546f9e940a..9a446c5b24 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/softmax_int8.h @@ -17,8 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_SOFTMAX_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_SOFTMAX_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/softmax_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/softmax_parameter.h" +#include "nnacl/quantization/quantize.h" int Softmax(const int8_t *input_ptr, int8_t *output_ptr, int count, float *exp_data, float *sum_data, SoftmaxQuantArg quant_param, SoftmaxParameter *parameter); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.cc index b4d6602124..bd77e0cd17 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/split_int8.h" -#include "src/runtime/kernel/arm/nnacl/split_parameter.h" +#include "nnacl/int8/split_int8.h" +#include "nnacl/split_parameter.h" #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" int DoSplit(int8_t *in_data, int8_t **out_data, const int *input_shape, int offset, int num_unit, SplitParameter *param) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.h index 2c269af394..e9809f5560 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/split_int8.h @@ -16,8 +16,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_SPLIT_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_SPLIT_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/split_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/split_parameter.h" int DoSplit(int8_t *in_data, int8_t **out_data, const int *input_shape, int offset, int num_unit, SplitParameter *split_param); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/squeeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/squeeze_int8.cc new file mode 100644 index 0000000000..e0ac5885bf --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/squeeze_int8.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "nnacl/squeeze_parameter.h" +#include "nnacl/int8/squeeze_int8.h" +#include + +void Squeeze(int8_t **inputs, int8_t *output_ptr, int task_id, SqueezeQuantArg *quant_Squeeze_parm, + SqueezeParameter *para_, size_t osize) { + float output_scale = quant_Squeeze_parm->out_quant_args_.scale_; + float output_inverse_scale = 1.f / output_scale; + QuantArg *input_quant = quant_Squeeze_parm->in_quant_args_; + int output_zp = quant_Squeeze_parm->out_quant_args_.zp_; + + int i = 0; + int8_t *input_ptr = inputs[0]; + for (int j = task_id; j < osize; j += para_->op_parameter_.thread_num_) { + float scale = input_quant[i].scale_ * output_inverse_scale; + float bias = -input_quant[i].zp_ * scale; + int32_t output_tmp = round(input_ptr[j] * scale + bias) + output_zp; + if (output_tmp > 127) { + output_ptr[j] = 127; + } else if (output_tmp < -128) { + output_ptr[j] = -128; + } else { + output_ptr[j] = (int8_t)output_tmp; + } + } +} diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/squeeze_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/squeeze_int8.h new file mode 100644 index 0000000000..bda2cbe90e --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/squeeze_int8.h @@ -0,0 +1,26 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_SQUEEZE_INT8_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_SQUEEZE_INT8_H_ + +#include "nnacl/quantization/quantize.h" +#include "nnacl/squeeze_parameter.h" + +void Squeeze(int8_t **inputs, int8_t *output_ptr, int task_id, SqueezeQuantArg *quant_Squeeze_parm, + SqueezeParameter *para_, size_t osize); + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_SQUEEZE_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.cc index 3cb482177f..cd9f5a9a59 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/int8/topk_int8.h" +#include "nnacl/int8/topk_int8.h" int DescendCmpInt8(const void *a, const void *b) { return ((const TopkNodeInt8 *)b)->element - ((const TopkNodeInt8 *)a)->element; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.h index 5b7bbc554f..998a4ba645 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/topk_int8.h @@ -17,13 +17,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_TOPK_INT8_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_INT8_TOPK_INT8_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/fp32/topk.h" +#include "nnacl/op_base.h" +#include "nnacl/fp32/topk.h" -struct TopkNodeInt8 { +typedef struct TopkNodeInt8 { int8_t element; int32_t index; -}; +} TopkNodeInt8; void TopkInt8(int8_t *input_data, int8_t *output_data, int32_t *output_index, TopkParameter *parameter); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.cc new file mode 100644 index 0000000000..657ed3aacc --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.cc @@ -0,0 +1,32 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "nnacl/unsqueeze_parameter.h" +#include "nnacl/int8/unsqueeze_int8.h" +#include +#include "nnacl/errorcode.h" + +int Unsqueeze(int8_t *input_ptr, int8_t *output_ptr, UnSqueezeParameter *para_, size_t data_size, int task_id) { + float output_scale = para_->quant_arg.out_quant_args_.scale_; + int8_t output_zp = para_->quant_arg.out_quant_args_.zp_; + float input_scale = para_->quant_arg.in_quant_args_.scale_; + int8_t input_zp = para_->quant_arg.in_quant_args_.zp_; + + for (int i = task_id; i < data_size; i += para_->thread_count_) { + output_ptr[i] = output_zp + round(1 / output_scale * input_scale * (input_ptr[i] - input_zp)); + } + return 0; +} diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.h new file mode 100644 index 0000000000..e87d58a91d --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/int8/unsqueeze_int8.h @@ -0,0 +1,24 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_UNSQUEEZE_INT8_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_UNSQUEEZE_INT8_H_ + +#include "nnacl/op_base.h" +#include "nnacl/unsqueeze_parameter.h" + +int Unsqueeze(int8_t *input_ptr, int8_t *output_ptr, UnSqueezeParameter *para_, size_t data_size, int task_id); +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_INT8_UNSQUEEZE_INT8_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/matmul.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/matmul_parameter.h similarity index 87% rename from mindspore/lite/src/runtime/kernel/arm/nnacl/matmul.h rename to mindspore/lite/src/runtime/kernel/arm/nnacl/matmul_parameter.h index 058f0371ab..4bed0f0e07 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/matmul.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/matmul_parameter.h @@ -17,11 +17,11 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_MATMUL_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_MATMUL_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -enum ActType { ActType_No, ActType_Relu, ActType_Relu6 }; +typedef enum ActType { ActType_No, ActType_Relu, ActType_Relu6 } ActType; -struct MatMulParameter { +typedef struct MatMulParameter { OpParameter op_parameter_; int row_; int col_; @@ -33,6 +33,6 @@ struct MatMulParameter { bool a_transpose_; /* false : row-major */ bool b_transpose_; /* true : col-major */ ActType act_type_; -}; +} MatMulParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_MATMUL_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/mul_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/mul_parameter.h index 8b70bd09ee..74c5065614 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/mul_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/mul_parameter.h @@ -17,12 +17,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_MUL_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_MUL_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" -struct MulParameter { +typedef struct MulParameter { OpParameter op_parameter_; int thread_count_; MulQuantArg mul_quant_arg_; -}; +} MulParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_MUL_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/nnacl_utils.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/nnacl_utils.cc index 1607d5793d..6fb1abe472 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/nnacl_utils.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/nnacl_utils.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/nnacl_utils.h" +#include "nnacl/nnacl_utils.h" #ifdef __ANDROID__ #include #endif diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/op_base.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/op_base.h index dcf1e956e7..49b4d405bc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/op_base.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/op_base.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_OP_BASE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_OP_BASE_H_ -#include -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include +#include #define C4NUM 4 #define C8NUM 8 @@ -48,15 +48,15 @@ #define kInputSize1 2 #define kInputSize2 3 -enum LiteDataType { +typedef enum LiteDataType { kDataTypeFloat, kDataTypeInt8, -}; +} LiteDataType; -struct OpParameter { +typedef struct OpParameter { char name_[100]; int type_; int thread_num_; -}; +} OpParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_OP_BASE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/optimized_kernel.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/optimized_kernel.h index d5bf245376..553fe71116 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/optimized_kernel.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/optimized_kernel.h @@ -20,7 +20,7 @@ #include #ifdef __ANDROID__ #include -#include "src/runtime/kernel/arm/nnacl/nnacl_utils.h" +#include "nnacl/nnacl_utils.h" #endif #define OPTIMIZE_SHARED_LIBRARY_PATH "liboptimize.so" diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.cc index 64dcbaaa4c..174ad2f4f2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/pack.h" +#include "nnacl/pack.h" #include #include diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.h index 02ed4c6fba..3f4d4283ed 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/pack.h @@ -20,8 +20,8 @@ #ifdef ENABLE_NEON #include #endif -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/op_base.h" void Im2ColPackUnitFp32(const float *input_data, ConvParameter *conv_param, float *packed_input, int real_cal_num, int block_index); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/pad_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/pad_parameter.h index 230ca70aaf..ba108b66a2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/pad_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/pad_parameter.h @@ -16,17 +16,18 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PAD_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PAD_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" #define MAX_PAD_SIZE 8 #define DEFAULT_PAD_NDIMS 4 -struct PadParameter { +typedef struct PadParameter { OpParameter op_parameter_; PadQuantArg pad_quant_arg_; int paddings_[MAX_PAD_SIZE] = {0}; int pad_mode_; float constant_value_; -}; +} PadParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PAD_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/power.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/power.cc index b1165f12c1..7b86129438 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/power.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/power.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/power.h" +#include "nnacl/power.h" bool CheckInteger(float f) { return floorf(f) == f; } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/power.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/power.h index 61800b47dd..5dbb49c6fb 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/power.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/power.h @@ -17,14 +17,14 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_POWER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_POWER_H_ #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct PowerParameter { +typedef struct PowerParameter { OpParameter op_parameter_; float power_; float scale_; float shift_; -}; +} PowerParameter; void Power(const float *input, const float *exponent, float *output, int len, float scale, float shift, bool broadcast); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.cc index 6b454e94f9..cc04ba5411 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/prelu.h" +#include "nnacl/prelu.h" void PRelu(float *input, float *output, PReluParameter *prelu_param_, int task_id) { for (int i = task_id; i < prelu_param_->input_num_; i += prelu_param_->op_parameter_.thread_num_) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.h index 208274ee6b..1f14c83aa8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu.h @@ -16,14 +16,14 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PRELU_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PRELU_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct PReluParameter { +typedef struct PReluParameter { OpParameter op_parameter_; float *negtive_slope_; int input_num_; int thread_num_; -}; +} PReluParameter; void PRelu(float *input, float *output, PReluParameter *prelu_param_, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu_parameter.h new file mode 100644 index 0000000000..7f8be0d563 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/prelu_parameter.h @@ -0,0 +1,39 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_PRELU_PARAMETER_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_PRELU_PARAMETER_H_ + +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" + +#define PRELU_OFFSET_MAX_SIZE 4 + +typedef struct PreluParameter { + OpParameter op_parameter_; + PreluQuantArg quant_arg; + double alpha_; + int thread_count_; + int64_t offset_[PRELU_OFFSET_MAX_SIZE]; + int64_t in_offset_[PRELU_OFFSET_MAX_SIZE]; + int64_t axis_; + const int *in_shape_; + const int *out_shape_; + int input_dim_; + int element_num; +} PreluParameter; + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_PRELU_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.cc index e149ed90ca..7fd1c0bdef 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.cc @@ -15,8 +15,8 @@ */ #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" -#include "src/runtime/kernel/arm/nnacl/prior_box.h" +#include "nnacl/errorcode.h" +#include "nnacl/prior_box.h" int PriorBox(const float *input_data, float *output_data, const size_t size, const int tid, const int thread_num) { size_t unit_size = size / thread_num; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.h index fd0ea64e28..557934d3e1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/prior_box.h @@ -20,10 +20,10 @@ #include #endif #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" #define PRIOR_BOX_MAX_NUM 8 #define PRIOR_BOX_VAR_NUM 4 -struct PriorBoxParameter { +typedef struct PriorBoxParameter { OpParameter op_parameter_; int32_t min_sizes_size; int32_t min_sizes[PRIOR_BOX_MAX_NUM]; @@ -39,7 +39,7 @@ struct PriorBoxParameter { bool clip; bool flip; float offset; -}; +} PriorBoxParameter; int PriorBox(const float *input_data, float *output_data, const size_t size, const int tid, const int thread_num); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_PRIOR_BOX_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.cc index aee93ed738..502be9e530 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/quantization/quantize.h" +#include "nnacl/quantization/quantize.h" const uint64_t dSignMask = 1ull << 63; const uint64_t dExponentMask = 0x7ffull << 52; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.h index 421d582c5e..1473896a71 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/quantization/quantize.h @@ -22,14 +22,14 @@ #include #include #include -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct QuantArg { +typedef struct QuantArg { double scale_; int32_t zp_; -}; +} QuantArg; -struct ConvQuantArg { +typedef struct ConvQuantArg { QuantArg **quant_args_; double *real_multiplier_; int32_t *left_shift_; @@ -37,20 +37,74 @@ struct ConvQuantArg { int32_t *quant_multiplier_; int32_t *out_act_min_; int32_t *out_act_max_; -}; +} ConvQuantArg; -struct ConcatQuantArg { +typedef struct ConcatQuantArg { + QuantArg *in_args_; + QuantArg out_args_; + int output_activation_min_; + int output_activation_max_; +} ConcatQuantArg; + +typedef struct SqueezeQuantArg { + int *input_sizes_; + int output_size_; + int **input_shapes_; + int *output_shape_; + float alpha; + int axis_; + size_t input_num_; + size_t output_dim_; + QuantArg *in_quant_args_; + QuantArg out_quant_args_; +} SqueezeQuantArg; + +typedef struct UnSqueezeQuantArg { + int *input_sizes_; + int output_size_; + int **input_shapes_; + int *output_shape_; + float alpha; + int axis_; + size_t input_num_; + size_t output_dim_; + QuantArg in_quant_args_; + QuantArg out_quant_args_; +} UnSqueezeQuantArg; + +typedef struct PreluQuantArg { int *input_sizes_; int output_size_; int **input_shapes_; int *output_shape_; size_t input_num_; size_t output_dim_; + float alpha_; + QuantArg in_args_; + QuantArg out_args_; + int output_activation_min_; + int output_activation_max_; QuantArg *in_quant_args_; QuantArg out_quant_args_; -}; +} PreluQuantArg; -struct MatmulQuantArg { +/*typedef struct SigmoidQuantArg { + int *input_sizes_; + int output_size_; + int **input_shapes_; + int *output_shape_; + size_t input_num_; + size_t output_dim_; + float alpha_; + QuantArg in_args_; + QuantArg out_args_; + int output_activation_min_; + int output_activation_max_; + QuantArg *in_quant_args_; + QuantArg out_quant_args_; +} SigmoidQuantArg;*/ + +typedef struct MatmulQuantArg { QuantArg input; QuantArg weight; QuantArg output; @@ -59,15 +113,15 @@ struct MatmulQuantArg { int32_t left_shift; int32_t right_shift; int32_t quant_multiplier; -}; +} MatmulQuantArg; -struct PadQuantArg { +typedef struct PadQuantArg { QuantArg *in_quant_args_ = nullptr; QuantArg *out_quanr_args_ = nullptr; int8_t *constant_value_ = nullptr; -}; +} PadQuantArg; -struct MulQuantArg { +typedef struct MulQuantArg { QuantArg in_quant_args_[2]; QuantArg out_quant_arg_; int output_multiplier_; @@ -75,16 +129,16 @@ struct MulQuantArg { int output_activation_max_; int shift_left_; int shift_right_; -}; +} MulQuantArg; -struct CropQuantArg { +typedef struct CropQuantArg { QuantArg in_args_; QuantArg out_args_; int output_activation_min_; int output_activation_max_; -}; +} CropQuantArg; -struct ArithSelfQuantArg { +typedef struct ArithSelfQuantArg { QuantArg in_args_; QuantArg out_args_; int output_activation_min_; @@ -92,19 +146,32 @@ struct ArithSelfQuantArg { int output_multiplier_; int shift_left_; int shift_right_; -}; +} ArithSelfQuantArg; -struct SplitQuantArg { +typedef struct SplitQuantArg { QuantArg in_args_; QuantArg out_args_[20]; int output_activation_min_; int output_activation_max_; -}; +} SplitQuantArg; -struct SoftmaxQuantArg { +typedef struct SoftmaxQuantArg { QuantArg in_quant_args_; QuantArg out_quant_arg_; -}; +} SoftmaxQuantArg; + +typedef struct ReshapeQuantArg { + QuantArg in_args_; + QuantArg out_args_; + int output_activation_min_; + int output_activation_max_; +} ReshapeQuantArg; + +typedef struct QuantMulArg { + int32_t multiplier_; + int left_shift_; + int right_shift_; +} QuantMulArg; void QuantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, int *shift); @@ -138,8 +205,8 @@ inline int32_t QuantizeToInt8(float real_value, float scale, int32_t zp) { retur inline void CalculateActivationRangeQuantized(bool is_relu, bool is_relu6, int32_t zp, float scale, int *mini, int *maxi) { - int32_t min = std::numeric_limits::min(); - int32_t max = std::numeric_limits::max(); + int32_t min = CHAR_MIN; + int32_t max = CHAR_MAX; int32_t quantized_zero = QuantizeToInt8(0, scale, zp); int32_t quantized_six = QuantizeToInt8(6, scale, zp); if (is_relu) { @@ -157,10 +224,10 @@ inline void CalculateActivationRangeQuantized(bool is_relu, bool is_relu6, int32 // quantize from float to int8 inline void Quantize(float *input_data, int length, float scale, int zero_point, int8_t *output_data) { for (int i = 0; i < length; ++i) { - int r = (int)round(input_data[i] / scale + zero_point); - int8_t q = r > CHAR_MAX ? (int8_t)CHAR_MAX : (int8_t)r; + int q = (int)round(input_data[i] / scale + zero_point); + q = q > CHAR_MAX ? CHAR_MAX : q; q = q < CHAR_MIN ? CHAR_MIN : q; - output_data[i] = q; + output_data[i] = (int8_t)q; } } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.cc index 5505c8b0f9..a44dbd4718 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/reshape.h" +#include "nnacl/reshape.h" #include void Reshape(void *input_ptr, void *output_ptr, size_t data_size) { memcpy(output_ptr, input_ptr, data_size); } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.h index a992a46ba0..9c2ed360fa 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape.h @@ -16,7 +16,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESHAHPE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESHAHPE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" void Reshape(void *input_ptr, void *output_ptr, size_t data_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape_parameter.h index 0243a60f86..a44ae9756e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/reshape_parameter.h @@ -17,12 +17,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESHAHPE_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESHAHPE_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" -struct ReshapeParameter { +typedef struct ReshapeParameter { OpParameter op_parameter_; + ReshapeQuantArg quant_para_; int thread_count_; -}; +} ReshapeParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESHAHPE_PARAMETER_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/resize.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/resize.cc deleted file mode 100644 index 48567ce01b..0000000000 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/resize.cc +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ -#include -#include "src/runtime/kernel/arm/nnacl/resize.h" -#include "src/runtime/kernel/arm/nnacl/common_func.h" - -int ResizeBilinear(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, - bool align_corners, int tid, int thread_num) { - if (input_data == nullptr || output_data == nullptr || input_shape == nullptr || output_shape == nullptr) { - return NNACL_NULL_PTR; - } - // nhwc (memory layout is nc4hw4) - int n = input_shape[0]; - int in_h = input_shape[1]; - int in_w = input_shape[2]; - int channel = input_shape[3]; - int c4 = UP_DIV(channel, C4NUM); - - int new_height = output_shape[1]; - int new_width = output_shape[2]; - float height_scale = (float)(in_h) / new_height; - float width_scale = (float)(in_w) / new_width; - if (align_corners && new_height > 1) { - height_scale = (float)(in_h - 1) / (new_height - 1); - } - if (align_corners && new_width > 1) { - width_scale = (float)(in_w - 1) / (new_width - 1); - } - - int o[5]; // n c4 h w 4 - for (o[0] = 0; o[0] < n; o[0]++) { - for (o[1] = tid; o[1] < c4; o[1] += thread_num) { - for (o[2] = 0; o[2] < new_height; o[2]++) { - float actual_y = (float)(o[2]) * height_scale; - int y_left = (int)(floor(actual_y)); - int y_right = y_left + 1 < in_h ? (y_left + 1) : (in_h - 1); - float y_right_weight = actual_y - (float)(y_left); - float y_left_weight = 1.0 - y_right_weight; - for (o[3] = 0; o[3] < new_width; o[3]++) { - float actual_x = (float)(o[3]) * width_scale; - int x_left = (int)(floor(actual_x)); - int x_right = x_left + 1 < in_w ? (x_left + 1) : (in_w - 1); - float x_right_weight = actual_x - (float)(x_left); - float x_left_weight = 1.0 - x_right_weight; - - auto input_base_offset = (((o[0] * c4 + o[1]) * in_h + y_left) * in_w + x_left) * C4NUM; - auto output_base_offset = (((o[0] * c4 + o[1]) * new_height + o[2]) * new_width + o[3]) * C4NUM; - int in_offset_1_0 = (y_right - y_left) * in_w * C4NUM; - int in_offset_0_1 = (x_right - x_left) * C4NUM; -#ifdef ENABLE_NEON - float32x4_t x_l_weight = vdupq_n_f32(x_left_weight); - float32x4_t x_r_weight = vdupq_n_f32(x_right_weight); - float32x4_t y_l_weight = vdupq_n_f32(y_left_weight); - float32x4_t y_r_weight = vdupq_n_f32(y_right_weight); - - float32x4_t input_yl_xl = vld1q_f32(input_data + input_base_offset); - float32x4_t input_yr_xl = vld1q_f32(input_data + input_base_offset + in_offset_1_0); - float32x4_t input_yl_xr = vld1q_f32(input_data + input_base_offset + in_offset_0_1); - float32x4_t input_yr_xr = vld1q_f32(input_data + input_base_offset + in_offset_0_1 + in_offset_1_0); - - float32x4_t interp_value = vdupq_n_f32(0.0); - float32x4_t interp_value_tmp = vmulq_f32(input_yl_xl, y_l_weight); - interp_value_tmp = vmulq_f32(interp_value_tmp, x_l_weight); - interp_value = vaddq_f32(interp_value, interp_value_tmp); - - interp_value_tmp = vmulq_f32(input_yr_xl, y_r_weight); - interp_value_tmp = vmulq_f32(interp_value_tmp, x_l_weight); - interp_value = vaddq_f32(interp_value, interp_value_tmp); - - interp_value_tmp = vmulq_f32(input_yl_xr, y_l_weight); - interp_value_tmp = vmulq_f32(interp_value_tmp, x_r_weight); - interp_value = vaddq_f32(interp_value, interp_value_tmp); - - interp_value_tmp = vmulq_f32(input_yr_xr, y_r_weight); - interp_value_tmp = vmulq_f32(interp_value_tmp, x_r_weight); - interp_value = vaddq_f32(interp_value, interp_value_tmp); - vst1q_f32(output_base_offset + output_data, interp_value); -#else - // 4 continuous data in a group; - for (o[4] = 0; o[4] < C4NUM; o[4]++) { - auto in_offset = input_base_offset + o[4]; - auto output_offset = output_base_offset + o[4]; - float interp_value = - input_data[in_offset] * y_left_weight * x_left_weight + - input_data[in_offset + in_offset_1_0] * y_right_weight * x_left_weight + - input_data[in_offset + in_offset_0_1] * y_left_weight * x_right_weight + - input_data[in_offset + in_offset_0_1 + in_offset_1_0] * y_right_weight * x_right_weight; - output_data[output_offset] = interp_value; - } -#endif - } - } - } - } - return NNACL_OK; -} - -int ResizeNearestNeighbor(const float *input_data, float *output_data, const int *input_shape, const int *output_shape, - int tid, int thread_num) { - int batch, y, x, c; - c = input_shape[3]; - - float height_scale = (float)(input_shape[1]) / (float)(output_shape[1]); - float width_scale = (float)(input_shape[2]) / (float)(output_shape[2]); - - for (batch = 0; batch < output_shape[0]; batch++) { - for (y = tid; y < output_shape[1]; y += thread_num) { - int actual_y = (int)(floor((float)(y) * height_scale)); - int input_y = actual_y < input_shape[1] ? actual_y : input_shape[1] - 1; - for (x = 0; x < output_shape[2]; x++) { - int actual_x = (int)(floor((float)(x) * width_scale)); - int input_x = actual_x < input_shape[2] ? actual_x : input_shape[2] - 1; - int in_offset = offset(input_shape, batch, input_y, input_x, 0); - int out_offset = offset(output_shape, batch, y, x, 0); - memcpy(output_data + out_offset, input_data + in_offset, c * sizeof(float)); - } - } - } - - return NNACL_OK; -} - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/resize_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/resize_parameter.h new file mode 100644 index 0000000000..946f4f88a1 --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/resize_parameter.h @@ -0,0 +1,28 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESIZE_PARAMETER_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESIZE_PARAMETER_H_ + +#include "src/runtime/kernel/arm/nnacl/op_base.h" +typedef struct ResizeParameter { + OpParameter op_parameter_; + int method_; + int64_t new_height_; + int64_t new_width_; + bool align_corners_; + bool preserve_aspect_ratio_; +} ResizeParameter; +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_RESIZE_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.cc index 7308716fbb..66711c6430 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/reverse_sequence.h" +#include "nnacl/reverse_sequence.h" #include -#include "src/runtime/kernel/arm/nnacl/arithmetic_common.h" +#include "nnacl/arithmetic_common.h" void ReverseSequence(float *input0, int *input1, float *output, ReverseSequenceParameter *para) { (void)memcpy(output, input0, para->total_data_size_); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.h index 582bcd35eb..11dd1c4d7e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/reverse_sequence.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_REVERSE_SEQUENCE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_REVERSE_SEQUENCE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct ReverseSequenceParameter { +typedef struct ReverseSequenceParameter { OpParameter op_parameter_; int ndim_; int input_shape0_[5]; @@ -34,7 +34,7 @@ struct ReverseSequenceParameter { int inner_stride_; int copy_byte_size_; int total_data_size_; -}; +} ReverseSequenceParameter; void ReverseSequence(float *input0, int *input1, float *output, ReverseSequenceParameter *para); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.cc index 37405b67c1..1c39f03e2a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/scale.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/scale.h" +#include "nnacl/errorcode.h" int DoScale(float *in_data, float *out_data, float *scale, float *offset, int task_id, ScaleParameter *scale_param) { if (in_data == nullptr || out_data == nullptr || scale == nullptr || offset == nullptr || scale_param == nullptr) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.h index aaa77b7dda..0b1b733f5f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/scale.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SCALE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SCALE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct ScaleParameter { +typedef struct ScaleParameter { OpParameter op_parameter_; int outer_size_; int axis_size_; @@ -27,7 +27,7 @@ struct ScaleParameter { int axis_; bool has_offset_; // todo yangruoqi: axis -}; +} ScaleParameter; int DoScale(float *in_data, float *out_data, float *scale, float *offset, int task_id, ScaleParameter *scale_param); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SCALE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.cc index 0194e928af..f3c6f21de2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/scatter_nd.h" +#include "nnacl/scatter_nd.h" #include #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" int DoScatterND(float *output_ptr, float *update, int *output_unit_offsets, int unit_size, int num_units) { if (output_ptr == nullptr || update == nullptr || output_unit_offsets == nullptr || unit_size <= 0 || num_units < 0) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.h index adbe179bed..e93453dba4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/scatter_nd.h @@ -17,11 +17,11 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SCATTER_ND_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SCATTER_ND_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct ScatterNDParameter { +typedef struct ScatterNDParameter { OpParameter op_parameter_; -}; +} ScatterNDParameter; int DoScatterND(float *output_ptr, float *update, int *output_unit_offsets, int unit_size, int num_units); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SCATTER_ND_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/shape.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/shape.h index bfcbc4f8dc..d4dedc39db 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/shape.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/shape.h @@ -17,11 +17,11 @@ #ifndef MINDSPORE_CCSRC_KERNEL_CPU_ARM_NNACL_SHAPE_H_ #define MINDSPORE_CCSRC_KERNEL_CPU_ARM_NNACL_SHAPE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct ShapeParameter { +typedef struct ShapeParameter { OpParameter op_parameter_; -}; +} ShapeParameter; #endif // MINDSPORE_CCSRC_KERNEL_CPU_ARM_NNACL_SHAPE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/sigmoid_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/sigmoid_parameter.h new file mode 100644 index 0000000000..0b29da145e --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/sigmoid_parameter.h @@ -0,0 +1,37 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_SIGMOID_PARAMETER_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_SIGMOID_PARAMETER_H_ + +#include "nnacl/op_base.h" +#define SIGMOID_OFFSET_MAX_SIZE 4 + +typedef struct SigmoidParameter { + OpParameter op_parameter_; + SigmoidQuantArg quant_arg; + double alpha_; + int thread_count_; + int64_t offset_[PRELU_OFFSET_MAX_SIZE]; + int64_t in_offset_[PRELU_OFFSET_MAX_SIZE]; + int64_t axis_; + const int *in_shape_; + const int *out_shape_; + int input_dim_; + int element_num; +} SigmoidParameter; + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_SIGMOID_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/softmax_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/softmax_parameter.h index b0fc83ce3e..b8f545444a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/softmax_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/softmax_parameter.h @@ -17,14 +17,14 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SOFTMAX_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SOFTMAX_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct SoftmaxParameter { +typedef struct SoftmaxParameter { OpParameter op_parameter_; int32_t axis_; int element_size_; int n_dim_; int input_shape_[4]; -}; +} SoftmaxParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SOFTMAX_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.cc index 17b80564b3..542f73c8a4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/sparse_to_dense.h" +#include "nnacl/sparse_to_dense.h" void SparseToDense(int *input, int *output_shape_, float *snum, float *dnum, int sp_num, float *output, SparseToDenseParameter *s2d_param_, int task_id) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.h index 3f048dd817..a1cc395ee5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/sparse_to_dense.h @@ -16,13 +16,13 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SPARSETODENSE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SPARSETODENSE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct SparseToDenseParameter { +typedef struct SparseToDenseParameter { OpParameter op_parameter_; int thread_num_; int count_ = 0; -}; +} SparseToDenseParameter; void SparseToDense(int *input, int *output_shape_, float *snum, float *dnum, int sp_num, float *output, SparseToDenseParameter *s2d_param_, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/split.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/split.cc index 712abebe19..d7aa29d22a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/split.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/split.cc @@ -14,10 +14,10 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/split.h" -#include "src/runtime/kernel/arm/nnacl/split_parameter.h" +#include "nnacl/split.h" +#include "nnacl/split_parameter.h" #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" int DoSplit(float *in_data, float **out_data, const int *input_shape, int offset, int num_unit, SplitParameter *split_param) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/split.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/split.h index ff861ff4ca..24c81875d1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/split.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/split.h @@ -17,8 +17,8 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SPLIT_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SPLIT_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" -#include "src/runtime/kernel/arm/nnacl/split_parameter.h" +#include "nnacl/op_base.h" +#include "nnacl/split_parameter.h" int DoSplit(float *in_data, float **out_data, const int *input_shape, int offset, int num_unit, SplitParameter *split_param); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/split_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/split_parameter.h index 30456df654..67864698b2 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/split_parameter.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/split_parameter.h @@ -17,9 +17,10 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SPLIT_PARAMETER_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SPLIT_PARAMETER_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" -struct SplitParameter { +typedef struct SplitParameter { OpParameter op_parameter_; SplitQuantArg quant_arg_; int num_split_; @@ -28,6 +29,6 @@ struct SplitParameter { int split_dim_; int n_dims_; int split_count_; -}; +} SplitParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SPLIT_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.cc index 43e7ffad7c..c2a7554ddf 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/squeeze.h" +#include "nnacl/squeeze.h" #include int DoSqueeze(float *in_data, float *out_data, size_t data_size) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.h index 5da0637e8a..28367138dc 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze.h @@ -17,12 +17,12 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SQUEEZE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_SQUEEZE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct SqueezeParameter { +typedef struct SqueezeParameter { OpParameter op_parameter_; int axes_[8]; -}; +} SqueezeParameter; int DoSqueeze(float *input_ptr, float *output_ptr, size_t data_size); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze_parameter.h new file mode 100644 index 0000000000..b25922fa3d --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze_parameter.h @@ -0,0 +1,38 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_SQUEEZE_PARAMETER_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_SQUEEZE_PARAMETER_H_ +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" + +#define SQUEEZE_OFFSET_MAX_SIZE 4 + +typedef struct SqueezeParameter { + OpParameter op_parameter_; + SqueezeQuantArg quant_arg; + int thread_count_; + int thread_id_; + int offset_size_; + int64_t offset_[SQUEEZE_OFFSET_MAX_SIZE]; + int64_t in_offset_[SQUEEZE_OFFSET_MAX_SIZE]; + int64_t axis_; + const int *in_shape_; + const int *out_shape_; + int input_dim_; +} SqueezeParameter; + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_SQUEEZE_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/strassen_matmul.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/strassen_matmul.h index c385d3b45f..32b7067e55 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/strassen_matmul.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/strassen_matmul.h @@ -17,18 +17,17 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_STRASSEN_MATMUL_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_STRASSEN_MATMUL_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" /* hw*inc4 X inc4*oc4 */ -struct StrassenMatMulParameter { +typedef struct StrassenMatMulParameter { OpParameter op_parameter; - int row_{}; /* h * w */ - int col_{}; /* oc4 / 4 */ - int deep_{}; /* inc4 / 4 */ - int a_stride_{}; /* h * w * 4 */ - int b_stride_{}; /* inc4 * 4 */ - int c_stride_{}; /* h * w * 4 */ -}; + int row_; /* h * w */ + int col_; /* oc4 / 4 */ + int deep_; /* inc4 / 4 */ + int a_stride_; /* h * w * 4 */ + int b_stride_; /* inc4 * 4 */ + int c_stride_; /* h * w * 4 */ +} StrassenMatMulParameter; #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_STRASSEN_MATMUL_H_ - diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.cc index 0c14eb2f71..699203316d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.cc @@ -14,8 +14,8 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/strided_slice.h" -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/strided_slice.h" +#include "nnacl/errorcode.h" void PadStridedSliceParameterTo4D(StridedSliceParameter *param) { int32_t begins[DIMENSION_4D]; diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.h index 0e9bcac593..5b60c2d267 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/strided_slice.h @@ -16,9 +16,9 @@ #ifndef MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_STRIDED_SLICE_H_ #define MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_STRIDED_SLICE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct StridedSliceParameter { +typedef struct StridedSliceParameter { OpParameter op_parameter_; int begins_[8] = {0}; int ends_[8] = {0}; @@ -27,7 +27,7 @@ struct StridedSliceParameter { int num_axes_; int in_shape_[8]; LiteDataType data_type; -}; +} StridedSliceParameter; int DoStridedSlice(const void *inputs, void *output, StridedSliceParameter *param); #endif // MINDSPORE_LITE_SRC_BACKEND_ARM_NNACL_STRIDED_SLICE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.cc index 747a4a51f7..942afde518 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/tile.h" +#include "nnacl/tile.h" #include void CopyData(float *input_data, float *output_data, size_t size, size_t multiple) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.h index da6d09602e..77b8c20bf4 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/tile.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_TILE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_TILE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct TileParameter { +typedef struct TileParameter { OpParameter op_parameter_; int in_dim_; int in_shape_[5]; @@ -27,7 +27,7 @@ struct TileParameter { int multiples_[5]; int in_strides_[5]; int out_strides_[5]; -}; +} TileParameter; void Tile(float *input_data, float *output_data, TileParameter *parameter); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.cc index 0e1b75db9a..bda88804d0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.cc @@ -14,9 +14,9 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/transpose.h" +#include "nnacl/transpose.h" #include -#include "src/runtime/kernel/arm/nnacl/errorcode.h" +#include "nnacl/errorcode.h" void TransposeDim2(float *in_data, float *out_data, int *strides, int *out_strides, int *perm, int *output_shape) { const int stride0 = strides[perm[0]]; @@ -85,6 +85,44 @@ void TransposeDim4(float *in_data, float *out_data, int *strides, int *out_strid } } +void TransposeDim5(float *in_data, float *out_data, int *strides, int *out_strides, int *perm, int *output_shape) { + const int stride0 = strides[perm[0]]; + const int stride1 = strides[perm[1]]; + const int stride2 = strides[perm[2]]; + const int stride3 = strides[perm[3]]; + const int stride4 = strides[perm[4]]; + const int out_stride0 = out_strides[0]; + const int out_stride1 = out_strides[1]; + const int out_stride2 = out_strides[2]; + const int out_stride3 = out_strides[3]; + const int output0 = output_shape[0]; + const int output1 = output_shape[1]; + const int output2 = output_shape[2]; + const int output3 = output_shape[3]; + const int output4 = output_shape[4]; + + for (int i = 0; i < output0; i++) { + int out_stride0_i = i * out_stride0; + int stride0_i = i * stride0; + for (int j = 0; j < output1; j++) { + int out_stride1_j = j * out_stride1; + int stride1_j = j * stride1; + for (int k = 0; k < output2; k++) { + int out_stride2_k = k * out_stride2; + int stride2_k = k * stride2; + for (int m = 0; m < output3; m++) { + int out_stride3_m = m * out_stride3; + int stride3_m = m * stride3; + for (int n = 0; n < output4; n++) { + out_data[out_stride0_i + out_stride1_j + out_stride2_k + out_stride3_m + n] = + in_data[stride0_i + stride1_j + stride2_k + stride3_m + n * stride4]; + } + } + } + } + } +} + int DoTranspose(float *in_data, float *out_data, int *input_shape, int *output_shape, TransposeParameter *transpose_param) { if (in_data == nullptr || out_data == nullptr) { @@ -96,7 +134,7 @@ int DoTranspose(float *in_data, float *out_data, int *input_shape, int *output_s int data_size = transpose_param->data_size_; int num_axes = transpose_param->num_axes_; - if (num_axes < 2 || num_axes > 4) { + if (num_axes < 2 || num_axes > 5) { return NNACL_ERR; } @@ -119,6 +157,8 @@ int DoTranspose(float *in_data, float *out_data, int *input_shape, int *output_s TransposeDim3(in_data, out_data, strides, out_strides, perm, output_shape); } else if (num_axes == 4) { TransposeDim4(in_data, out_data, strides, out_strides, perm, output_shape); + } else if (num_axes == 5) { + TransposeDim5(in_data, out_data, strides, out_strides, perm, output_shape); } return NNACL_OK; } diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.h index 80e19b8ae8..2d3b2d0c50 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/transpose.h @@ -17,9 +17,9 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_TRANSPOSE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_TRANSPOSE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct TransposeParameter { +typedef struct TransposeParameter { OpParameter op_parameter_; int perm_[8]; bool conjugate_; @@ -27,13 +27,14 @@ struct TransposeParameter { int strides_[8]; int out_strides_[8]; int data_size_; -}; +} TransposeParameter; int DoTranspose(float *in_data, float *out_data, int *input_shape, int *output_shape, TransposeParameter *transpose_param); void TransposeDim2(float *in_data, float *out_data, int *strides, int *out_strides, int *perm, int *output_shape); void TransposeDim3(float *in_data, float *out_data, int *strides, int *out_strides, int *perm, int *output_shape); void TransposeDim4(float *in_data, float *out_data, int *strides, int *out_strides, int *perm, int *output_shape); +void TransposeDim5(float *in_data, float *out_data, int *strides, int *out_strides, int *perm, int *output_shape); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_TRANSPOSE_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.cc index 9db29931ae..6f6642c9e3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/unique.h" +#include "nnacl/unique.h" int Find(float *array, int len, float target) { for (int i = 0; i < len; ++i) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.h index dce4b59319..23317e3708 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/unique.h @@ -17,11 +17,11 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_UNIQUE_H #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_UNIQUE_H -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct UniqueParameter { +typedef struct UniqueParameter { OpParameter op_parameter_; -}; +} UniqueParameter; void Unique(float *input, int input_len, float *output0, int *output0_len, int *output1); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/unsqueeze_parameter.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/unsqueeze_parameter.h new file mode 100644 index 0000000000..c1b6c1725c --- /dev/null +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/unsqueeze_parameter.h @@ -0,0 +1,38 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_UNSQUEEZE_PARAMETER_H_ +#define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_UNSQUEEZE_PARAMETER_H_ +#include "nnacl/op_base.h" +#include "nnacl/quantization/quantize.h" + +#define UNSQUEEZE_OFFSET_MAX_SIZE 4 + +typedef struct UnSqueezeParameter { + OpParameter op_parameter_; + UnSqueezeQuantArg quant_arg; + int thread_count_; + int thread_id_; + int offset_size_; + int64_t offset_[UNSQUEEZE_OFFSET_MAX_SIZE]; + int64_t in_offset_[UNSQUEEZE_OFFSET_MAX_SIZE]; + int64_t axis_; + const int *in_shape_; + const int *out_shape_; + int input_dim_; +} UnSqueezeParameter; + +#endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_OPCLIB_SQUEEZE_PARAMETER_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.cc index 5a7fd07b91..216ca888f6 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/unstack.h" +#include "nnacl/unstack.h" #include void Unistack(float *input, float **output, UnstackParameter *para) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.h index ee57a810af..b7d60141d5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/unstack.h @@ -17,16 +17,16 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_UNSTACK_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_UNSTACK_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct UnstackParameter { +typedef struct UnstackParameter { OpParameter op_parameter_; int num_; int axis_; int pre_dims_; int axis_dim_; int after_dims_; -}; +} UnstackParameter; void Unistack(float *input, float **output, UnstackParameter *para); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/where.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/where.cc index 40a4802ab6..5971a68801 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/where.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/where.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/where.h" +#include "nnacl/where.h" void Where(bool *input, float *input1, float *input2, float *output, WhereParameter *where_param_, int task_id) { for (int i = task_id; i < where_param_->number_; i += where_param_->op_parameter_.thread_num_) { diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/where.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/where.h index 73145fd9ec..600daa6fa0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/where.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/where.h @@ -16,16 +16,16 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_WHERE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_WHERE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" -struct WhereParameter { +typedef struct WhereParameter { OpParameter op_parameter_; int num_; int num1_; int num2_; int number_; int thread_num_; -}; +} WhereParameter; void Where(bool *input, float *input1, float *input2, float *output, WhereParameter *where_param_, int task_id); diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.cc index 23b40f6639..148fde8517 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/winograd_transform.h" +#include "nnacl/winograd_transform.h" // fp32 conv winograd void WinogradInputTransform(const float *input_data, float *trans_input, float *tmp_data, int cal_num, diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.h index e31e2e1930..75827cf42a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_transform.h @@ -21,10 +21,10 @@ #include #endif #include -#include "src/runtime/kernel/arm/nnacl/pack.h" -#include "src/runtime/kernel/arm/nnacl/fp32/conv.h" -#include "src/runtime/kernel/arm/nnacl/winograd_utils.h" -#include "src/runtime/kernel/arm/nnacl/quantization/fixed_point.h" +#include "nnacl/pack.h" +#include "nnacl/fp32/conv.h" +#include "nnacl/winograd_utils.h" +#include "nnacl/quantization/fixed_point.h" #define OUPUT_UNIT 2 diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.cc index 0c26437018..fcc3f3ee37 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/winograd_utils.h" +#include "nnacl/winograd_utils.h" #include #define MIN_UNIT 2 @@ -4708,3 +4708,28 @@ OutputTransformUnitFunc GetOutputTransFunc(int input_unit, int output_unit) { return nullptr; } } + +void CheckIfUseWinograd(bool *use_winograd, int *output_unit, ConvParameter *conv_param, + InputTransformUnitFunc input_trans_func, OutputTransformUnitFunc output_trans_func) { + if (conv_param->kernel_w_ == conv_param->kernel_h_ && conv_param->dilation_h_ == 1 && conv_param->dilation_w_ == 1 && + conv_param->stride_h_ == 1 && conv_param->stride_w_ == 1) { + *output_unit = SelectOutputUnit(conv_param); + if (*output_unit > 1) { + *use_winograd = true; + int input_unit = conv_param->kernel_h_ + *output_unit - 1; + input_trans_func = GetInputTransFunc(input_unit); + if (input_trans_func == nullptr) { + *use_winograd = false; + } + output_trans_func = GetOutputTransFunc(input_unit, *output_unit); + if (output_trans_func == nullptr) { + *use_winograd = false; + } + } else { + *use_winograd = false; + } + } else { + *use_winograd = false; + } +} + diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.h index d7a7b7a69c..d651b644e5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/winograd_utils.h @@ -20,9 +20,9 @@ #ifdef ENABLE_ARM #include #endif -#include "src/runtime/kernel/arm/nnacl/matrix_table.h" -#include "src/runtime/kernel/arm/nnacl/conv_parameter.h" -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/matrix_table.h" +#include "nnacl/conv_parameter.h" +#include "nnacl/op_base.h" using InputTransformUnitFunc = void (*)(const float *src_data, float *dst_data, int src_step, int dst_step); using OutputTransformUnitFunc = void (*)(const float *src_data, float *dst_data, const float *bias_data, int src_step, @@ -54,5 +54,7 @@ InputTransformUnitFunc GetInputTransFunc(int input_unit); OutputTransformUnitFunc GetOutputTransFunc(int input_unit, int output_unit); +void CheckIfUseWinograd(bool *use_winograd, int *output_unit, ConvParameter *conv_param, + InputTransformUnitFunc input_trans_func, OutputTransformUnitFunc output_trans_func); #endif // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_WINOGRAD_UTILS_H_ diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.cc b/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.cc index 697d77e6ee..8f56ae532c 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.cc +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.cc @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "src/runtime/kernel/arm/nnacl/zeroslike.h" +#include "nnacl/zeroslike.h" #include #include diff --git a/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.h b/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.h index 8948ad39fa..054fe4f26f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.h +++ b/mindspore/lite/src/runtime/kernel/arm/nnacl/zeroslike.h @@ -16,7 +16,7 @@ #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ZEROSLIKE_H_ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_ARM_NNACL_ZEROSLIKE_H_ -#include "src/runtime/kernel/arm/nnacl/op_base.h" +#include "nnacl/op_base.h" void ApproximateZerosLike(float *input, float *output, int number); diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/fp16/transpose.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/fp16/transpose.cl index ebc3db633f..73c4c076e7 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/fp16/transpose.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/fp16/transpose.cl @@ -1,8 +1,9 @@ #define FLT half #define FLT4 half4 #define READ_IMAGE read_imageh +#define WRITE_IMAGE write_imageh __constant sampler_t smp_zero = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; -__kernel void transpose(__read_only image2d_t src_data, __global float4 *dst_data, int2 HW, int2 C) { +__kernel void transpose(__read_only image2d_t src_data, __write_only image2d_t dst_data, int2 HW, int2 C) { int X = get_global_id(0); int Y = get_global_id(1); if (X >= HW.y || Y >= C.y) { @@ -37,8 +38,8 @@ __kernel void transpose(__read_only image2d_t src_data, __global float4 *dst_dat result[3].z = x2.w; result[3].w = x3.w; - dst_data[4 * Y * HW.y + X] = result[0]; - dst_data[(4 * Y + 1) * HW.y + X] = result[1]; - dst_data[(4 * Y + 2) * HW.y + X] = result[2]; - dst_data[(4 * Y + 3) * HW.y + X] = result[3]; + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y), result[0]); + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y + 1), result[1]); + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y + 2), result[2]); + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y + 3), result[3]); } diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_buffer.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_buffer.cl index 4e9a8422be..691d91ef9b 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_buffer.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_buffer.cl @@ -26,26 +26,9 @@ __kernel void ElementDiv(__global float *input_a, __global float *input_b, __glo output[idx] = input_a[idx] * input_b[idx]; } -__kernel void BoardcastAdd(__global float *input_a, float input_b, __global float *output, const unsigned int n) { +__kernel void BoardcastArith(__global float *input_a, float weight, float bias, __global float *output, + const unsigned int n) { int idx = get_global_id(0); if (idx >= n) return; - output[idx] = input_a[idx] + input_b; -} - -__kernel void BoardcastSub(__global float *input_a, float input_b, __global float *output, const unsigned int n) { - int idx = get_global_id(0); - if (idx >= n) return; - output[idx] = input_a[idx] - input_b; -} - -__kernel void BoardcastMul(__global float *input_a, float input_b, __global float *output, const unsigned int n) { - int idx = get_global_id(0); - if (idx >= n) return; - output[idx] = input_a[idx] * input_b; -} - -__kernel void BoardcastDiv(__global float *input_a, float input_b, __global float *output, const unsigned int n) { - int idx = get_global_id(0); - if (idx >= n) return; - output[idx] = input_a[idx] * input_b; + output[idx] = weight * input_a[idx] + bias; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_image2d.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_image2d.cl index 12f75438f9..33d6143f9d 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_image2d.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/arithmetic_image2d.cl @@ -1,15 +1,65 @@ __constant sampler_t smp_none = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; -__kernel void ElementAdd(__read_only image2d_t *input_a, __read_only image2d_t *input_b, __write_only image2d_t *output, - const int4 output_shape) { +__kernel void ElementAdd(__read_only image2d_t input_a, __read_only image2d_t input_b, __write_only image2d_t output, + const int2 output_shape) { int X = get_global_id(0); int Y = get_global_id(1); - int Z = get_global_id(2); - if (X >= output_shape.x || Y >= output_shape.y || Z >= output_shape.w) return; + if (X >= output_shape.x || Y >= output_shape.y) { + return; + } - if (idx >= n) return; - float4 a = read_imagef(input_a, smp_none, (int2)(X, Y * output_shape.w + Z)); - float4 b = read_imagef(input_b, smp_none, (int2)(X, Y * output_shape.w + Z)); - src = a + b; - write_imagef(output, (int2)(0, 0), src); + float4 a = read_imagef(input_a, smp_none, (int2)(X, Y)); + float4 b = read_imagef(input_b, smp_none, (int2)(X, Y)); + write_imagef(output, (int2)(X, Y), a + b); +} + +__kernel void ElementSub(__read_only image2d_t input_a, __read_only image2d_t input_b, __write_only image2d_t output, + const int2 output_shape) { + int X = get_global_id(0); + int Y = get_global_id(1); + if (X >= output_shape.x || Y >= output_shape.y) { + return; + } + + float4 a = read_imagef(input_a, smp_none, (int2)(X, Y)); + float4 b = read_imagef(input_b, smp_none, (int2)(X, Y)); + write_imagef(output, (int2)(X, Y), a - b); +} + +__kernel void ElementMul(__read_only image2d_t input_a, __read_only image2d_t input_b, __write_only image2d_t output, + const int2 output_shape) { + int X = get_global_id(0); + int Y = get_global_id(1); + if (X >= output_shape.x || Y >= output_shape.y) { + return; + } + + float4 a = read_imagef(input_a, smp_none, (int2)(X, Y)); + float4 b = read_imagef(input_b, smp_none, (int2)(X, Y)); + write_imagef(output, (int2)(X, Y), a * b); +} + +__kernel void ElementDiv(__read_only image2d_t input_a, __read_only image2d_t input_b, __write_only image2d_t output, + const int2 output_shape) { + int X = get_global_id(0); + int Y = get_global_id(1); + if (X >= output_shape.x || Y >= output_shape.y) { + return; + } + + float4 a = read_imagef(input_a, smp_none, (int2)(X, Y)); + float4 b = read_imagef(input_b, smp_none, (int2)(X, Y)); + write_imagef(output, (int2)(X, Y), a / b); +} + +__kernel void BoardcastArith(__read_only image2d_t input_a, float weight, float bias, __write_only image2d_t output, + const int2 output_shape) { + int X = get_global_id(0); + int Y = get_global_id(1); + if (X >= output_shape.x || Y >= output_shape.y) { + return; + } + + float4 a = read_imagef(input_a, smp_none, (int2)(X, Y)); + write_imagef(output, (int2)(X, Y), weight * a + bias); } diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/avg_pool2d.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/avg_pool2d.cl index 0e60a4ca1e..c5fd9e84ca 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/avg_pool2d.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/avg_pool2d.cl @@ -1,5 +1,5 @@ -__kernel void AvgPooling2d(__global float4 *input, __global float4 *output, const int4 input_shape, - const int4 output_shape, const int2 stride, const int2 kernel_size, const int2 padding) { +__kernel void AvgPooling2d_BUF(__global float4 *input, __global float4 *output, const int4 input_shape, + const int4 output_shape, const int2 stride, const int2 kernel_size, const int2 padding) { // axis to dst tensor coordinate int X = get_global_id(0); int Y = get_global_id(1); @@ -31,9 +31,8 @@ __kernel void AvgPooling2d(__global float4 *input, __global float4 *output, cons __constant sampler_t smp_zero = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; -__kernel void AvgPooling2dImage2d(__read_only image2d_t input, __write_only image2d_t output, const int4 input_shape, - const int4 output_shape, const int2 stride, const int2 kernel_size, - const int2 padding) { +__kernel void AvgPooling2d_IMG(__read_only image2d_t input, __write_only image2d_t output, const int4 input_shape, + const int4 output_shape, const int2 stride, const int2 kernel_size, const int2 padding) { // axis to dst tensor coordinate int X = get_global_id(0); int Y = get_global_id(1); @@ -49,17 +48,16 @@ __kernel void AvgPooling2dImage2d(__read_only image2d_t input, __write_only imag int xs = X * stride.x + padding.x; int ys = Y * stride.y + padding.y; - for (int kx = 0; kx < kernel_size.x; ++kx) { - int x_c = xs + kx; - bool outside_x = x_c < 0 || x_c >= input_shape.x; - for (int ky = 0; ky < kernel_size.y; ++ky) { - int y_c = ys + ky; - bool outside = outside_x || y_c < 0 || y_c >= input_shape.y; - - r += read_imagef(input, smp_zero, (int2)(x_c, y_c * input_shape.w + Z)); + for (int ky = 0; ky < kernel_size.y; ++ky) { + int y_c = ys + ky; + bool outside_y = y_c < 0 || y_c >= input_shape.y; + for (int kx = 0; kx < kernel_size.x; ++kx) { + int x_c = xs + kx; + bool outside = outside_y || x_c < 0 || x_c >= input_shape.x; + r += read_imagef(input, smp_zero, (int2)(y_c * input_shape.w + Z, x_c)); window_size += !outside ? 1.0f : 0.0f; } } float4 result = convert_float4(r / window_size); - write_imagef(output, (int2)(X, Y * output_shape.w + Z), result); + write_imagef(output, (int2)(Y * output_shape.w + Z, X), result); } diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/concat.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/concat.cl index d457a3e4fa..fc576b31c2 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/concat.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/concat.cl @@ -1,54 +1,44 @@ #pragma OPENCL EXTENSION cl_khr_fp16 : enable -__kernel void Concat(__global float *input0, __global float *input1, __global float *output, const int4 input_shape0, - const int4 input_shape1, const int4 output_shape, const int axis) { - uint oh = get_global_id(0); - uint ow = get_global_id(1); - uint oc = get_global_id(2); - uint index_output; - uint input_idx; - if ((oh >= output_shape.y || oh < 0) || (ow >= output_shape.z || ow < 0) || (oc >= output_shape.w || oc < 0)) { - return; +#define FLT4 float4 +__constant sampler_t smp_none = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; +__kernel void Concat(__write_only image2d_t output_image2d, __read_only image2d_t input0_image2d, + __read_only image2d_t input1_image2d, int2 shared_int0, int4 shared_out) { + int X = get_global_id(0); // H + int Y = get_global_id(1); // W + int S = 0; + if (X >= shared_out.y || Y >= shared_out.z) return; + for (int i = 0; i < shared_int0.x; i++) { + FLT4 result0 = read_imagef(input0_image2d, smp_none, (int2)((Y)*shared_int0.x + (i), (X))); + write_imagef(output_image2d, (int2)((Y)*shared_out.w + (S), (X)), result0); + S++; } - if (axis == 3) { - index_output = oh * output_shape.z * output_shape.w + ow * output_shape.w + oc; - if (oc < input_shape0.w) { - input_idx = (input_shape0.z * oh + ow) * input_shape0.w + oc; - output[index_output] = input0[input_idx]; - } else if ((input_shape0.w <= oc) && oc < (input_shape0.w + input_shape1.w)) { - input_idx = (input_shape1.z * oh + ow) * input_shape1.w + (oc - input_shape0.w); - output[index_output] = input1[input_idx]; - } else { - output[index_output] = 0; - } + for (int i = 0; i < shared_int0.y; i++) { + FLT4 result1 = read_imagef(input1_image2d, smp_none, (int2)((Y)*shared_int0.y + (i), (X))); + write_imagef(output_image2d, (int2)((Y)*shared_out.w + (S), (X)), result1); + S++; } } -__kernel void Concat3input(__global float *input0, __global float *input1, __global float *input2, - __global float *output, const int4 input_shape0, const int4 input_shape1, - const int4 input_shape2, const int4 output_shape, const int axis) { - uint oh = get_global_id(0); - uint ow = get_global_id(1); - uint oc = get_global_id(2); - uint index_output; - uint input_idx; - if ((oh >= output_shape.y || oh < 0) || (ow >= output_shape.z || ow < 0) || (oc >= output_shape.w || oc < 0)) { - return; +__kernel void Concat3input(__write_only image2d_t output_image2d, __read_only image2d_t input0_image2d, + __read_only image2d_t input1_image2d, __read_only image2d_t input2_image2d, int3 shared_int0, + int4 shared_out) { + int X = get_global_id(0); // H + int Y = get_global_id(1); // W + int S = 0; + if (X >= shared_out.y || Y >= shared_out.z) return; + for (int i = 0; i < shared_int0.x; i++) { + FLT4 result0 = read_imagef(input0_image2d, smp_none, (int2)((Y)*shared_int0.x + (i), (X))); + write_imagef(output_image2d, (int2)((Y)*shared_out.w + (S), (X)), result0); + S++; } - index_output = oh * output_shape.z * output_shape.w + ow * output_shape.w + oc; - if (oc < (input_shape0.w + input_shape1.w)) { - if (oc < input_shape0.w) { - input_idx = (input_shape0.z * oh + ow) * input_shape0.w + oc; - output[index_output] = input0[input_idx]; - } else { - input_idx = (input_shape1.z * oh + ow) * input_shape1.w + (oc - input_shape0.w); - output[index_output] = input1[input_idx]; - } - } else { - if ((input_shape0.w + input_shape1.w + input_shape2.w) <= oc) { - output[index_output] = 0; - } else { - input_idx = (input_shape2.z * oh + ow) * input_shape2.w + (oc - input_shape0.w - input_shape1.w); - output[index_output] = input2[input_idx]; - } + for (int i = 0; i < shared_int0.y; i++) { + FLT4 result1 = read_imagef(input1_image2d, smp_none, (int2)((Y)*shared_int0.y + (i), (X))); + write_imagef(output_image2d, (int2)((Y)*shared_out.w + (S), (X)), result1); + S++; + } + for (int i = 0; i < shared_int0.z; i++) { + FLT4 result2 = read_imagef(input2_image2d, smp_none, (int2)((Y)*shared_int0.z + (i), (X))); + write_imagef(output_image2d, (int2)((Y)*shared_out.w + (S), (X)), result2); + S++; } } diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/max_pool2d.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/max_pool2d.cl index f65e3e06d6..c64d40667e 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/max_pool2d.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/max_pool2d.cl @@ -31,7 +31,7 @@ __kernel void MaxPooling2d_BUF(__global float4 *input, __global float4 *output, output[(output_shape.y * X + Y) * output_shape.w + Z] = maximum; } -__constant sampler_t sample_none = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; +__constant sampler_t smp_none = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_NONE | CLK_FILTER_NEAREST; __kernel void MaxPooling2d_IMG(__read_only image2d_t input, __write_only image2d_t output, const int4 input_shape, const int4 output_shape, const int2 stride, const int2 kernel_size, const int2 padding) { @@ -48,20 +48,15 @@ __kernel void MaxPooling2d_IMG(__read_only image2d_t input, __write_only image2d float4 maximum = (float4)(-10000.0f); int xs = X * stride.x + padding.x; int ys = Y * stride.y + padding.y; - - for (int kx = 0; kx < kernel_size.x; ++kx) { - int x_c = xs + kx; - if (x_c < 0 || x_c >= input_shape.x) { - continue; - } - for (int ky = 0; ky < kernel_size.y; ++ky) { - int y_c = ys + ky; - if (y_c < 0 || y_c >= input_shape.y) { - continue; - } - float4 src = read_imagef(input, sample_none, (int2)(x_c, y_c * input_shape.w + Z)); + for (int ky = 0; ky < kernel_size.y; ++ky) { + int y_c = ys + ky; + if (y_c < 0 || y_c >= input_shape.y) continue; + for (int kx = 0; kx < kernel_size.x; ++kx) { + int x_c = xs + kx; + if (x_c < 0 || x_c >= input_shape.x) continue; + float4 src = read_imagef(input, smp_none, (int2)(y_c * input_shape.w + Z, x_c)); maximum = max(src, maximum); } } - write_imagef(output, (int2)(X, Y * output_shape.w + Z), maximum); + write_imagef(output, (int2)(Y * output_shape.w + Z, X), maximum); } diff --git a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/transpose.cl b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/transpose.cl index 08069ee80f..63def49644 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/transpose.cl +++ b/mindspore/lite/src/runtime/kernel/opencl/cl/fp32/transpose.cl @@ -1,8 +1,9 @@ #define FLT float #define FLT4 float4 #define READ_IMAGE read_imagef +#define WRITE_IMAGE write_imagef __constant sampler_t smp_zero = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; -__kernel void transpose(__read_only image2d_t src_data, __global float4 *dst_data, int2 HW, int2 C) { +__kernel void transpose(__read_only image2d_t src_data, __write_only image2d_t dst_data, int2 HW, int2 C) { int X = get_global_id(0); int Y = get_global_id(1); if (X >= HW.y || Y >= C.y) { @@ -37,8 +38,8 @@ __kernel void transpose(__read_only image2d_t src_data, __global float4 *dst_dat result[3].z = x2.w; result[3].w = x3.w; - dst_data[4 * Y * HW.y + X] = result[0]; - dst_data[(4 * Y + 1) * HW.y + X] = result[1]; - dst_data[(4 * Y + 2) * HW.y + X] = result[2]; - dst_data[(4 * Y + 3) * HW.y + X] = result[3]; + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y), result[0]); + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y + 1), result[1]); + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y + 2), result[2]); + WRITE_IMAGE(dst_data, (int2)(X, 4 * Y + 3), result[3]); } diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc index 8cd3113797..36acee6869 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.cc @@ -40,10 +40,10 @@ std::vector ArithmeticOpenCLKernel::InitGlobalSize() const { } void ArithmeticOpenCLKernel::Image2dGetWorkGroupSize() { - global_size_ = InitGlobalSize(); - int max_work_group_size = runtime_->GetKernelMaxWorkGroupSize(kernel_(), (*runtime_->Device())()); - local_size_ = GetCommonLocalSize(global_size_, max_work_group_size); - global_size_ = GetCommonGlobalSize(local_size_, global_size_); + size_t H = outputs_[0]->Batch() * outputs_[0]->Height(); + size_t W = outputs_[0]->Width() * UP_DIV(outputs_[0]->Channel(), C4NUM); + local_size_ = {16, 16}; + global_size_ = {W, H}; } void ArithmeticOpenCLKernel::BufferGetWorkGroupSize() { @@ -51,63 +51,75 @@ void ArithmeticOpenCLKernel::BufferGetWorkGroupSize() { global_size_ = {element_num}; } +int ArithmeticOpenCLKernel::GetImageSize(size_t idx, std::vector* img_size) { + size_t CO4 = UP_DIV(outputs_[0]->Channel(), C4NUM); + int H = outputs_[0]->Batch() * outputs_[0]->Height(); + int W = outputs_[0]->Width() * CO4; + size_t im_dst_x, im_dst_y; + if (inputs_[0]->GetFormat() == schema::Format_NHWC4) { + im_dst_x = W; + im_dst_y = H; + } else { + im_dst_y = outputs_[0]->Batch() * outputs_[0]->Height() * CO4; + im_dst_x = outputs_[0]->Width(); + } +#ifdef ENABLE_FP16 + size_t img_dtype = CL_HALF_FLOAT; +#else + size_t img_dtype = CL_FLOAT; +#endif + img_size->clear(); + std::vector vec{im_dst_x, im_dst_y, img_dtype}; + *img_size = vec; + return 0; +} + int ArithmeticOpenCLKernel::Init() { runtime_ = lite::opencl::OpenCLRuntime::GetInstance(); - std::string element_name; - std::string boardcast_name; + std::string kernel_name; if (inputs_[1]->TensorType() == schema::NodeType_ValueNode && inputs_[1]->Data() != nullptr) { element_flag_ = false; + kernel_name = "BoardcastArith"; } else { element_flag_ = true; + switch (opParameter->type_) { + case PrimitiveType_Mul: + kernel_name = "ElementMul"; + break; + case PrimitiveType_Add: + kernel_name = "ElementAdd"; + break; + case PrimitiveType_Sub: + kernel_name = "ElementSub"; + break; + case PrimitiveType_Div: + kernel_name = "ElementDiv"; + break; + default: + MS_LOG(ERROR) << "Error Operator type " << opParameter->type_; + break; + } } - switch (opParameter->type_) { - case PrimitiveType_Mul: - element_name = "ElementMul"; - boardcast_name = "BoardcastMul"; - break; - case PrimitiveType_Add: - element_name = "ElementAdd"; - boardcast_name = "BoardcastAdd"; - break; - case PrimitiveType_Sub: - element_name = "ElementSub"; - boardcast_name = "BoardcastSub"; - break; - case PrimitiveType_Div: - element_name = "ElementDiv"; - boardcast_name = "BoardcastDiv"; - break; - default: - MS_LOG(ERROR) << "Error Operator type " << opParameter->type_; - break; - } #ifdef PROGRAM_WITH_IL runtime_->CreateKernelFromIL(kernel_(), kernel_name); #else std::string program_name = "Arithmetic"; std::set build_options; - std::string source = arithmetic_buffer_source_fp32; + std::string source = arithmetic_image2d_source_fp32; runtime_->LoadSource(program_name, source); - - if (element_flag_) { - runtime_->BuildKernel(kernel_, program_name, element_name, build_options); - MS_LOG(DEBUG) << element_name << " Init Done!"; - } else { - runtime_->BuildKernel(kernel_, program_name, boardcast_name, build_options); - MS_LOG(DEBUG) << boardcast_name << " Init Done!"; - } + runtime_->BuildKernel(kernel_, program_name, kernel_name, build_options); #endif outputs_[0]->SetFormat(schema::Format_NHWC4); + Image2dGetWorkGroupSize(); return 0; } int ArithmeticOpenCLKernel::Run() { MS_LOG(DEBUG) << this->Name() << " Running!"; auto runtime_ = lite::opencl::OpenCLRuntime::GetInstance(); - BufferGetWorkGroupSize(); int arg_idx = 0; uint32_t element_num = outputs_[0]->ElementsC4Num(); @@ -116,11 +128,32 @@ int ArithmeticOpenCLKernel::Run() { if (element_flag_) { runtime_->SetKernelArg(kernel_, arg_idx++, inputs_[1]->Data()); } else { - runtime_->SetKernelArg(kernel_, arg_idx++, static_cast(inputs_[1]->Data())[0]); + float value = static_cast(inputs_[1]->Data())[0]; + switch (opParameter->type_) { + case PrimitiveType_Mul: + weight_ = value; + break; + case PrimitiveType_Add: + bias_ = value; + break; + case PrimitiveType_Sub: + bias_ = -1 * value; + break; + case PrimitiveType_Div: + weight_ = 1 / value; + break; + default: + MS_LOG(ERROR) << "Error Operator type " << opParameter->type_; + break; + } + runtime_->SetKernelArg(kernel_, arg_idx++, weight_); + runtime_->SetKernelArg(kernel_, arg_idx++, bias_); } runtime_->SetKernelArg(kernel_, arg_idx++, outputs_[0]->Data()); - runtime_->SetKernelArg(kernel_, arg_idx++, element_num); - + int H = outputs_[0]->Batch() * outputs_[0]->Height(); + int W = outputs_[0]->Width() * UP_DIV(outputs_[0]->Channel(), C4NUM); + cl_int2 output_shape{W, H}; + runtime_->SetKernelArg(kernel_, arg_idx++, output_shape); runtime_->RunKernel(kernel_, global_size_, local_size_, nullptr); return 0; } @@ -128,7 +161,7 @@ int ArithmeticOpenCLKernel::Run() { kernel::LiteKernel *OpenCLArithmeticKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { auto *kernel = new ArithmeticOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs, ctx); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Arithmetic kernel failed!"; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.h index 37143775b0..5210f8e771 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/arithmetic.h @@ -24,15 +24,16 @@ namespace mindspore::kernel { -class ArithmeticOpenCLKernel : public ArithmeticCPUKernel { +class ArithmeticOpenCLKernel : public OpenCLKernel { public: explicit ArithmeticOpenCLKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, const lite::Context *ctx) - : ArithmeticCPUKernel(parameter, inputs, outputs, ctx) {} + : OpenCLKernel(parameter, inputs, outputs) {} ~ArithmeticOpenCLKernel() override{}; int Init() override; int Run() override; + int GetImageSize(size_t idx, std::vector* img_size) override; private: std::vector InitGlobalSize() const; @@ -42,6 +43,8 @@ class ArithmeticOpenCLKernel : public ArithmeticCPUKernel { cl::Kernel kernel_; lite::opencl::OpenCLRuntime *runtime_; bool element_flag_{true}; + float weight_{1.f}; + float bias_{.0f}; std::vector local_size_; std::vector global_size_; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc index 4823f1eca0..536bd84b0d 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.cc @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include #include @@ -27,6 +28,26 @@ using mindspore::schema::PrimitiveType_Concat; namespace mindspore::kernel { +int ConcatOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { + size_t CO4 = UP_DIV(outputs_[0]->Channel(), C4NUM); + size_t im_dst_x, im_dst_y; + if (inputs_[0]->GetFormat() == schema::Format_NHWC4) { + im_dst_x = outputs_[0]->Width() * CO4; + im_dst_y = outputs_[0]->Height(); + } else { + im_dst_y = outputs_[0]->Height() * CO4; + im_dst_x = outputs_[0]->Width(); + } +#ifdef ENABLE_FP16 + size_t img_dtype = CL_HALF_FLOAT; +#else + size_t img_dtype = CL_FLOAT; +#endif + img_size->clear(); + std::vector vec{im_dst_x, im_dst_y, img_dtype}; + *img_size = vec; + return 1; +} int ConcatOpenCLKernel::Init() { if (inputs_[0]->shape().size() != 4) { MS_LOG(ERROR) << "only support dim=4"; @@ -126,83 +147,54 @@ void ConcatGetWorkGroup(const std::vector &global, std::vector * local->push_back(z); } int ConcatOpenCLKernel::Run() { + MS_LOG(DEBUG) << this->Name() << " Running!"; auto param = reinterpret_cast(this->opParameter); if (param->axis_ == 0) { return Run_axis0(); } auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); - std::vector local; - std::vector global; + auto input0_shape = inputs_[0]->shape(); + auto input1_shape = inputs_[1]->shape(); + auto output_shape = outputs_[0]->shape(); + + cl_int2 input0_shape2_ = {DivideRoundUp(input0_shape[3], 4), DivideRoundUp(input1_shape[3], 4)}; // change + cl_int4 output_shape_ = {output_shape[0], output_shape[1], output_shape[2], DivideRoundUp(output_shape[3], 4)}; + + uint32_t OH = output_shape[0] * output_shape[1]; // N*H + uint32_t OW = output_shape[2]; + + std::vector local = {1, 1}; + std::vector global = {OH, OW}; + // ConcatGetWorkGroup(global, &local, 512); + + int arg_cn = 0; if (inputs_.size() == 2) { - auto input0_shape = inputs_[0]->shape(); - auto input1_shape = inputs_[1]->shape(); - auto output_shape = outputs_[0]->shape(); - - cl_int4 input0_shape_ = {input0_shape[0], input0_shape[1], input0_shape[2], input0_shape[3]}; - cl_int4 input1_shape_ = {input1_shape[0], input1_shape[1], input1_shape[2], input1_shape[3]}; - cl_int4 output_shape_ = {output_shape[0], output_shape[1], output_shape[2], output_shape[3]}; - - uint32_t OH = output_shape[0] * output_shape[1]; // N*H - uint32_t OW = output_shape[2]; - uint32_t OC = output_shape[3]; - global = {OH, OW, OC}; // HWC - ConcatGetWorkGroup(global, &local, 384); - std::cout << "local size=:" << std::endl; - for (int i = 0; i < local.size(); i++) { - std::cout << local[i] << " "; - } - std::cout << std::endl; - int arg_cn = 0; + ocl_runtime->SetKernelArg(kernel_, arg_cn++, outputs_[0]->Data()); ocl_runtime->SetKernelArg(kernel_, arg_cn++, inputs_[0]->Data()); ocl_runtime->SetKernelArg(kernel_, arg_cn++, inputs_[1]->Data()); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, outputs_[0]->Data()); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, input0_shape_); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, input1_shape_); + ocl_runtime->SetKernelArg(kernel_, arg_cn++, input0_shape2_); ocl_runtime->SetKernelArg(kernel_, arg_cn++, output_shape_); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, param->axis_); - } - if (inputs_.size() == 3) { - auto input0_shape = inputs_[0]->shape(); - auto input1_shape = inputs_[1]->shape(); + } else if (inputs_.size() == 3) { auto input2_shape = inputs_[2]->shape(); - auto output_shape = outputs_[0]->shape(); - - cl_int4 input0_shape_ = {input0_shape[0], input0_shape[1], input0_shape[2], input0_shape[3]}; - cl_int4 input1_shape_ = {input1_shape[0], input1_shape[1], input1_shape[2], input1_shape[3]}; - cl_int4 input2_shape_ = {input2_shape[0], input2_shape[1], input2_shape[2], input2_shape[3]}; - cl_int4 output_shape_ = {output_shape[0], output_shape[1], output_shape[2], output_shape[3]}; - - uint32_t OH = output_shape[0] * output_shape[1]; // N*H - uint32_t OW = output_shape[2]; - uint32_t OC = output_shape[3]; - global = {OH, OW, OC}; // HWC - ConcatGetWorkGroup(global, &local, 384); - std::cout << "local size=:" << std::endl; - for (int i = 0; i < local.size(); i++) { - std::cout << local[i] << " "; - } - std::cout << std::endl; - int arg_cn = 0; + cl_int3 input0_shape3_ = {DivideRoundUp(input0_shape[3], 4), DivideRoundUp(input1_shape[3], 4), + DivideRoundUp(input2_shape[3], 4)}; + ocl_runtime->SetKernelArg(kernel_, arg_cn++, outputs_[0]->Data()); ocl_runtime->SetKernelArg(kernel_, arg_cn++, inputs_[0]->Data()); ocl_runtime->SetKernelArg(kernel_, arg_cn++, inputs_[1]->Data()); ocl_runtime->SetKernelArg(kernel_, arg_cn++, inputs_[2]->Data()); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, outputs_[0]->Data()); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, input0_shape_); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, input1_shape_); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, input2_shape_); + ocl_runtime->SetKernelArg(kernel_, arg_cn++, input0_shape3_); ocl_runtime->SetKernelArg(kernel_, arg_cn++, output_shape_); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, param->axis_); } ocl_runtime->RunKernel(kernel_, global, local, nullptr); return 0; -} +} // namespace mindspore::kernel kernel::LiteKernel *OpenCLConcatKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { auto *kernel = new ConcatOpenCLKernel(opParameter, inputs, outputs); auto ret = kernel->Init(); if (0 != ret) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h index 1f2c115f87..0f1d1ab13d 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_LITE_SRC_BACKEND_OPENCL_Concat_H_ -#define MINDSPORE_LITE_SRC_BACKEND_OPENCL_Concat_H_ +#ifndef MINDSPORE_LITE_SRC_BACKEND_OPENCL_CONCAT_H_ +#define MINDSPORE_LITE_SRC_BACKEND_OPENCL_CONCAT_H_ #include #include "ir/anf.h" @@ -25,11 +25,11 @@ namespace mindspore::kernel { -class ConcatOpenCLKernel : public LiteKernel { +class ConcatOpenCLKernel : public OpenCLKernel { public: explicit ConcatOpenCLKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + : OpenCLKernel(parameter, inputs, outputs) {} ~ConcatOpenCLKernel() override{}; @@ -40,6 +40,7 @@ class ConcatOpenCLKernel : public LiteKernel { int Run_axis0(); int Run() override; + int GetImageSize(size_t idx, std::vector *img_size) override; private: cl::Kernel kernel_; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc index 6aefa36a69..b4ea3fb933 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.cc @@ -171,7 +171,8 @@ int Conv2dTransposeOpenCLKernel::Run() { kernel::LiteKernel *OpenCLConv2dTransposeKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { auto *kernel = new Conv2dTransposeOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); auto ret = kernel->Init(); if (0 != ret) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.h index b3299d2a53..cf97920102 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/conv2d_transpose.h @@ -35,8 +35,8 @@ class Conv2dTransposeOpenCLKernel : public LiteKernel { public: explicit Conv2dTransposeOpenCLKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} - ~Conv2dTransposeOpenCLKernel() override {}; + : LiteKernel(parameter, inputs, outputs, nullptr, nullptr) {} + ~Conv2dTransposeOpenCLKernel() override{}; int Init() override; int ReSize() override; @@ -52,4 +52,3 @@ class Conv2dTransposeOpenCLKernel : public LiteKernel { } // namespace mindspore::kernel #endif // MINDSPORE_LITE_SRC_BACKEND_OPENCL_CONV2D_TRANSPOSE_H_ - diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc index c2e5e9a447..9fc71ba389 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.cc @@ -18,109 +18,204 @@ #include #include #include "src/runtime/kernel/opencl/kernel/convolution.h" -#include "src/runtime/kernel/opencl/cl/fp32/convolution.cl.inc" #include "src/kernel_registry.h" +#include "include/errorcode.h" using mindspore::kernel::KERNEL_ARCH::kGPU; using mindspore::lite::KernelRegistrar; +using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Conv2D; namespace mindspore::kernel { int ConvolutionOpenCLKernel::Init() { - MS_LOG(INFO) << "ConvolutionOpenCLKernel::Init()"; - - if (inputs_[0]->Batch() != 1 || outputs_[0]->Batch() != 1) { - MS_LOG(ERROR) << "ConvolutionOpenCLKernel only support Batch=1!"; - } - - auto io_NHWC = inputs_[0]->GetFormat() == schema::Format_NHWC && outputs_[0]->GetFormat() == schema::Format_NHWC; - auto io_NHWC4 = inputs_[0]->GetFormat() == schema::Format_NHWC4 && outputs_[0]->GetFormat() == schema::Format_NHWC4; - if (!io_NHWC && !io_NHWC4) { - MS_LOG(ERROR) << "input and output data_format is invalid!"; - } - io_dataformat_ = inputs_[0]->GetFormat(); - - if (inputs_[1]->GetFormat() != schema::Format_KHWC) { - MS_LOG(ERROR) << "weight data_format is invalid!"; - } - + std::cout << "ConvolutionOpenCLKernel::Init()\n"; std::set build_options; - std::string source = convolution_source_fp32; + std::string source = CodeGen(); std::string program_name = "convolution"; - std::string kernel_name = io_NHWC4 ? "convolution_NHWC4_OHWIIO_float8" : "convolution_NHWC_OHWI"; + std::string kernel_name = "convolution"; auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); ocl_runtime->LoadSource(program_name, source); ocl_runtime->BuildKernel(kernel_, program_name, kernel_name, build_options); this->InitBuffer(); - - return 0; + return RET_OK; } + +std::string ConvolutionOpenCLKernel::CodeGen() { + auto param = reinterpret_cast(opParameter); + + auto input_tensor = inputs_[0]; + auto output_tensor = outputs_[0]; + const size_t CI = input_tensor->Channel(); + const size_t CI_SLICES = UP_DIV(CI, C4NUM); + const size_t CI_ALIGN = UP_DIV(CI, C4NUM) * C4NUM; + const size_t IH = input_tensor->Height(); + const size_t IW = input_tensor->Width(); + const size_t CO = output_tensor->Channel(); + const size_t CO_SLICES = UP_DIV(CO, C4NUM); + const size_t CO_ALIGN = UP_DIV(CO, C4NUM) * C4NUM; + const size_t OH = output_tensor->Height(); + const size_t OW = output_tensor->Width(); + const size_t KH = param->kernel_h_; + const size_t KW = param->kernel_w_; + const size_t strideH = param->stride_h_; + const size_t strideW = param->stride_w_; + const size_t padTop = param->pad_u_; + const size_t padBottom = param->pad_d_; + const size_t padLeft = param->pad_l_; + const size_t padRight = param->pad_r_; + + std::string code; + code += "#define CI_TILE 4\n"; + code += "#define CO_TILE 4\n\n"; + code += "#define CI " + std::to_string(CI_ALIGN) + "\n"; + code += "#define IH " + std::to_string(IH) + "\n"; + code += "#define IW " + std::to_string(IW) + "\n"; + code += "#define CO " + std::to_string(CO_ALIGN) + "\n"; + code += "#define OH " + std::to_string(OH) + "\n"; + code += "#define OW " + std::to_string(OW) + "\n"; + code += "#define KH " + std::to_string(KH) + "\n"; + code += "#define KW " + std::to_string(KW) + "\n"; + code += "#define strideH " + std::to_string(strideH) + "\n"; + code += "#define strideW " + std::to_string(strideW) + "\n"; + code += "#define padTop " + std::to_string(padTop) + "\n"; + code += "#define padBottom " + std::to_string(padBottom) + "\n"; + code += "#define padLeft " + std::to_string(padLeft) + "\n"; + code += "#define padRight " + std::to_string(padRight) + "\n"; + code += "#define CI_SLICES " + std::to_string(CI_SLICES) + "\n"; + code += "#define CO_SLICES " + std::to_string(CO_SLICES) + "\n\n"; + +#ifdef ENABLE_FP16 + code += + "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n" + "#define FLT4 half4\n" + "#define READ_FLT4 read_imageh\n" + "#define WRITE_FLT4 write_imageh\n\n"; +#else + code += + "#define FLT4 float4\n" + "#define READ_FLT4 read_imagef\n" + "#define WRITE_FLT4 write_imagef\n\n"; +#endif + + code += "__constant sampler_t smp_zero = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST;\n\n"; + + code += + "__kernel void convolution(__read_only image2d_t input,\n" + " __global FLT4 *weight,\n" + " __global FLT4 *bias,\n" + " __write_only image2d_t output)\n" + "{\n"; + + code += + " int oh = get_global_id(0); // [0, OH)\n" + " int ow = get_global_id(1); // [0, OW)\n" + " int co_slice = get_global_id(2); // [0, UP_DIV(CO, CO_TILE) )\n" + "\n" + " if (oh >= OH || ow >= OW || co_slice >= CO_SLICES)\n" + " return;\n" + "\n" + " FLT4 out0_c4 = (FLT4)(0.0f, 0.0f, 0.0f, 0.0f);\n" + " __global FLT4 *w0_ic1_oc4 = weight + co_slice * KH * KW * CI_SLICES * CI_TILE;\n"; + + code += + " for (int kh = 0; kh < KH; ++kh)\n" + " {\n" + " int ih = kh + oh * strideH - padTop;\n" + " for (int kw = 0; kw < KW; ++kw)\n" + " {\n" + " int iw = kw + ow * strideW - padLeft;\n" + " if (ih >= 0 && ih < IH && iw >= 0 && iw < IW)\n" + " {\n" + " for (int ci_slice = 0; ci_slice < CI_SLICES; ci_slice++)\n" + " {\n"; + + // NHWC4 NHC4W4 NC4HW4 + code += "FLT4 in_c4 = READ_FLT4(input, smp_zero, (int2)(iw * CI_SLICES + ci_slice, ih)); // NHWC4: H WC\n\n"; + // code += "FLT4 in_c4 = READ_FLT4(input, smp_zero, (int2)(iw, ih * CI_SLICES + ci_slice)); // NHC4W4: HC W\n\n"; + // code += "FLT4 in_c4 = READ_FLT4(input, smp_zero, (int2)(iw, ci_slice * IH + ih)); // NC4HW4: CH W\n\n"; + + code += + " out0_c4 += w0_ic1_oc4[0] * in_c4.x;\n" + " out0_c4 += w0_ic1_oc4[1] * in_c4.y;\n" + " out0_c4 += w0_ic1_oc4[2] * in_c4.z;\n" + " out0_c4 += w0_ic1_oc4[3] * in_c4.w;\n" + " w0_ic1_oc4 += 4;\n" + " }\n" + " }\n" + " else\n" + " {\n" + " w0_ic1_oc4 += 4 * CI_SLICES;\n" + " }\n" + " }\n" + " }\n\n"; + code += " FLT4 out0_c4_bias = out0_c4 + bias[co_slice];\n"; + + // NHWC4 NHC4W4 NC4HW4 + if (OW * CO_SLICES < 65536) { + code += " WRITE_FLT4(output, (int2)(ow * CO_SLICES + co_slice, oh), out0_c4_bias);// NHWC4: H WC\n}"; + } else { + code += " WRITE_FLT4(output, (int2)(oh * CO_SLICES + co_slice, ow), out0_c4_bias);// NHWC4: H WC\n}"; + } + // code += " WRITE_FLT4(output, (int2)(ow, oh * CO_SLICES + co_slice), out0_c4_bias);// NHC4W4: HC W\n}"; + // code += " WRITE_FLT4(output, (int2)(ow ,co_slice * OH + oh), out0_c4_bias);// NC4HW4: CH W\n}"; + + // std::cout << code << std::endl; + return code; +} + int ConvolutionOpenCLKernel::InitBuffer() { auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); auto allocator = ocl_runtime->GetAllocator(); + // weight: OHWI -> OHWIIO auto weight_tensor = inputs_[1]; - auto bias_tensor = inputs_[2]; - if (io_dataformat_ == schema::Format_NHWC) { - packed_weight_ = reinterpret_cast(allocator->Malloc(weight_tensor->Size())); - packed_weight_ = reinterpret_cast(allocator->MapBuffer(packed_weight_, CL_MAP_WRITE, nullptr, true)); - memcpy(packed_weight_, weight_tensor->Data(), weight_tensor->Size()); - allocator->UnmapBuffer(packed_weight_); - - packed_bias_ = reinterpret_cast(allocator->Malloc(bias_tensor->Size())); - packed_bias_ = reinterpret_cast(allocator->MapBuffer(packed_bias_, CL_MAP_WRITE, nullptr, true)); - memcpy(packed_bias_, bias_tensor->Data(), bias_tensor->Size()); - allocator->UnmapBuffer(packed_bias_); - } else if (io_dataformat_ == schema::Format_NHWC4) { - // OHWI -> OHWIIO - auto weight_shape = weight_tensor->shape(); - size_t CO = weight_shape[0]; - size_t KH = weight_shape[1]; - size_t KW = weight_shape[2]; - size_t CI = weight_shape[3]; - size_t CI_SLICES = UP_DIV(CI, C4NUM); - size_t CO_SLICES = UP_DIV(CO, C4NUM); - constexpr size_t CI_TILE = C4NUM; - constexpr size_t CO_TILE = C4NUM; - size_t packed_weight_size = CO_SLICES * KH * KW * CI_SLICES * CI_TILE * CO_TILE * sizeof(float); - - packed_weight_ = reinterpret_cast(allocator->Malloc(packed_weight_size)); - packed_weight_ = reinterpret_cast(allocator->MapBuffer(packed_weight_, CL_MAP_WRITE, nullptr, true)); - memset(packed_weight_, 0x00, packed_weight_size); - auto weight_data = reinterpret_cast(weight_tensor->Data()); - for (int co = 0; co < CO; ++co) { - for (int kh = 0; kh < KH; ++kh) { - for (int kw = 0; kw < KW; ++kw) { - for (int ci = 0; ci < CI; ++ci) { - auto co_outer = co / CO_TILE; - auto co_inner = co % CO_TILE; - auto ci_outer = ci / CI_TILE; - auto ci_inner = ci % CI_TILE; - packed_weight_[((((co_outer * KH + kh) * KW + kw) * CI_SLICES + ci_outer) * CI_TILE + ci_inner) * CO_TILE + - co_inner] = *(weight_data++); - } + auto weight_shape = weight_tensor->shape(); + size_t CO = weight_shape[0]; + size_t KH = weight_shape[1]; + size_t KW = weight_shape[2]; + size_t CI = weight_shape[3]; + size_t CI_SLICES = UP_DIV(CI, C4NUM); + size_t CO_SLICES = UP_DIV(CO, C4NUM); + constexpr size_t CI_TILE = C4NUM; + constexpr size_t CO_TILE = C4NUM; + size_t packed_weight_size = CO_SLICES * KH * KW * CI_SLICES * CI_TILE * CO_TILE * sizeof(float); + packed_weight_ = reinterpret_cast(allocator->Malloc(packed_weight_size)); + packed_weight_ = reinterpret_cast(allocator->MapBuffer(packed_weight_, CL_MAP_WRITE, nullptr, true)); + memset(packed_weight_, 0x00, packed_weight_size); + auto weight_data = reinterpret_cast(weight_tensor->Data()); + for (int co = 0; co < CO; ++co) { + for (int kh = 0; kh < KH; ++kh) { + for (int kw = 0; kw < KW; ++kw) { + for (int ci = 0; ci < CI; ++ci) { + auto co_outer = co / CO_TILE; + auto co_inner = co % CO_TILE; + auto ci_outer = ci / CI_TILE; + auto ci_inner = ci % CI_TILE; + packed_weight_[((((co_outer * KH + kh) * KW + kw) * CI_SLICES + ci_outer) * CI_TILE + ci_inner) * CO_TILE + + co_inner] = *(weight_data++); } } } - allocator->UnmapBuffer(packed_weight_); - size_t packed_bias_size = CO_SLICES * CO_TILE * sizeof(float); - packed_bias_ = reinterpret_cast(allocator->Malloc(packed_bias_size)); - packed_bias_ = reinterpret_cast(allocator->MapBuffer(packed_bias_, CL_MAP_WRITE, nullptr, true)); - memset(packed_bias_, 0x00, packed_bias_size); - auto bias_data = reinterpret_cast(bias_tensor->Data()); - for (int co = 0; co < CO; ++co) { - packed_bias_[co] = bias_data[co]; - } - allocator->UnmapBuffer(packed_bias_); } + allocator->UnmapBuffer(packed_weight_); - return 0; + // align bias + auto bias_tensor = inputs_[2]; + size_t packed_bias_size = CO_SLICES * CO_TILE * sizeof(float); + packed_bias_ = reinterpret_cast(allocator->Malloc(packed_bias_size)); + packed_bias_ = reinterpret_cast(allocator->MapBuffer(packed_bias_, CL_MAP_WRITE, nullptr, true)); + memset(packed_bias_, 0x00, packed_bias_size); + auto bias_data = reinterpret_cast(bias_tensor->Data()); + for (int co = 0; co < CO; ++co) { + packed_bias_[co] = bias_data[co]; + } + allocator->UnmapBuffer(packed_bias_); + + return RET_OK; } // namespace mindspore::kernel -int ConvolutionOpenCLKernel::ReSize() { return 0; } - static int GetBiggestDivider(int x, int y) { for (int i = y; i != 0; i--) { if (x % i == 0) { @@ -130,18 +225,22 @@ static int GetBiggestDivider(int x, int y) { return 1; } -static void GetLocalSize(const ConvParameter *param, std::vector *global, std::vector *local) { +int ConvolutionOpenCLKernel::GetGlobalLocal(std::vector *global, std::vector *local) { + auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); + auto param = reinterpret_cast(opParameter); + param->output_h_ = outputs_[0]->Height(); + param->output_w_ = outputs_[0]->Width(); + param->output_channel_ = outputs_[0]->Channel(); + constexpr size_t work_group_size[] = {4, 4, 1}; - constexpr size_t max_work_item_sizes[] = {512, 512, 512}; - constexpr size_t max_work_group_size = 512; + auto max_work_item_sizes = ocl_runtime->GetWorkItemSize(); + size_t max_work_group_size = ocl_runtime->GetKernelMaxWorkGroupSize(kernel_(), (*ocl_runtime->Device())()); const size_t max_z_size = std::min(16, max_work_item_sizes[2]); - // 先用OH OW CO_SLICES初始化global,并且441对齐 size_t global_h = UP_DIV(param->output_h_, work_group_size[0]) * work_group_size[0]; size_t global_w = UP_DIV(param->output_w_, work_group_size[1]) * work_group_size[1]; size_t global_c = UP_DIV(UP_DIV(param->output_channel_, C4NUM), work_group_size[2]) * work_group_size[2]; - // 使用策略计算local size_t local_c = GetBiggestDivider(global_c, max_z_size); size_t local_hw_size = std::min(256, max_work_group_size) / local_c; size_t local_w = std::min(global_w, local_hw_size); @@ -158,68 +257,59 @@ static void GetLocalSize(const ConvParameter *param, std::vector *global local->push_back(local_h); local->push_back(local_w); local->push_back(local_c); + return RET_OK; +} + +int ConvolutionOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { + size_t CO_SLICES = UP_DIV(outputs_[0]->Channel(), C4NUM); + size_t im_dst_x, im_dst_y; + if (inputs_[0]->GetFormat() == schema::Format_NHWC4) { + if (outputs_[0]->Width() * CO_SLICES < 65536) { + { + im_dst_x = outputs_[0]->Width() * CO_SLICES; + im_dst_y = outputs_[0]->Height(); + } + } else { + im_dst_x = outputs_[0]->Height() * CO_SLICES; + im_dst_y = outputs_[0]->Width(); + } + } else { + im_dst_y = outputs_[0]->Height() * CO_SLICES; + im_dst_x = outputs_[0]->Width(); + } +#ifdef ENABLE_FP16 + size_t img_dtype = CL_HALF_FLOAT; +#else + size_t img_dtype = CL_FLOAT; +#endif + img_size->clear(); + img_size->push_back(im_dst_x); + img_size->push_back(im_dst_y); + img_size->push_back(img_dtype); + return RET_OK; } int ConvolutionOpenCLKernel::Run() { - MS_LOG(INFO) << "ConvolutionOpenCLKernel::Run()"; + MS_LOG(DEBUG) << this->Name() << " Running!"; auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); - auto param = reinterpret_cast(opParameter); - auto input0_shape = inputs_[0]->shape(); // NHWC - auto input1_shape = inputs_[1]->shape(); // OHWI - auto outpu0_shape = outputs_[0]->shape(); // NHWC - cl_int N = input0_shape[0]; - cl_int CI = input0_shape[3]; - cl_int IH = input0_shape[1]; - cl_int IW = input0_shape[2]; - cl_int CO = outpu0_shape[3]; - cl_int OH = outpu0_shape[1]; - cl_int OW = outpu0_shape[2]; - cl_int KH = input1_shape[1]; - cl_int KW = input1_shape[2]; - cl_int CI_ALIGN = UP_DIV(CI, C4NUM) * C4NUM; - cl_int CO_ALIGN = UP_DIV(CO, C4NUM) * C4NUM; - - cl_int4 input_shape; - cl_int4 output_shape; - if (io_dataformat_ == schema::Format_NHWC) { - input_shape = {N, IH, IW, CI}; - output_shape = {N, OH, OW, CO}; - } else if (io_dataformat_ == schema::Format_NHWC4) { - input_shape = {N, IH, IW, CI_ALIGN}; - output_shape = {N, OH, OW, CO_ALIGN}; - } - cl_int4 kernel_stride = {KH, KW, param->stride_h_, param->stride_w_}; - cl_int4 pad = {param->pad_u_, param->pad_d_, param->pad_l_, param->pad_r_}; - int arg_cn = 0; ocl_runtime->SetKernelArg(kernel_, arg_cn++, inputs_[0]->Data()); ocl_runtime->SetKernelArg(kernel_, arg_cn++, packed_weight_); ocl_runtime->SetKernelArg(kernel_, arg_cn++, packed_bias_); ocl_runtime->SetKernelArg(kernel_, arg_cn++, outputs_[0]->Data()); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, input_shape); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, output_shape); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, kernel_stride); - ocl_runtime->SetKernelArg(kernel_, arg_cn++, pad); std::vector global; std::vector local; - GetLocalSize(reinterpret_cast(this->opParameter), &global, &local); - // float8 per thread - if (io_dataformat_ == schema::Format_NHWC4) { - local[2] = UP_DIV(local[2], 2); - global[2] = UP_DIV(global[2], 2); - global[2] = UP_DIV(global[2], global[2]) * global[2]; - } + GetGlobalLocal(&global, &local); ocl_runtime->RunKernel(kernel_, global, local, nullptr); - - return 0; + return RET_OK; } kernel::LiteKernel *OpenCLConvolutionKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { auto *kernel = new ConvolutionOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Convolution kernel failed!"; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.h index f757b1968a..d9da43df49 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.h @@ -18,6 +18,7 @@ #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_OPENCL_KERNEL_CONVOLUTION_H_ #include +#include #include "src/ir/tensor.h" #include "src/runtime/kernel/opencl/opencl_kernel.h" #include "schema/model_generated.h" @@ -26,23 +27,25 @@ namespace mindspore::kernel { -class ConvolutionOpenCLKernel : public LiteKernel { +class ConvolutionOpenCLKernel : public OpenCLKernel { public: explicit ConvolutionOpenCLKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + : OpenCLKernel(parameter, inputs, outputs) {} ~ConvolutionOpenCLKernel() override{}; int Init() override; - int ReSize() override; int Run() override; int InitBuffer(); + int GetImageSize(size_t idx, std::vector *img_size) override; private: - schema::Format io_dataformat_ = schema::Format_NHWC4; float *packed_weight_ = nullptr; float *packed_bias_ = nullptr; cl::Kernel kernel_; + + std::string CodeGen(); + int GetGlobalLocal(std::vector *global, std::vector *local); }; } // namespace mindspore::kernel diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc index e7a89821c0..58c343ac90 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/depthwise_conv2d.cc @@ -191,7 +191,8 @@ int DepthwiseConv2dOpenCLKernel::Run() { kernel::LiteKernel *OpenCLDepthwiseConv2dKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, + const lite::Primitive *primitive) { auto *kernel = new DepthwiseConv2dOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); auto ret = kernel->Init(); if (0 != ret) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc index 9a73ef48d7..cef0926aed 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.cc @@ -154,7 +154,7 @@ int MatMulOpenCLKernel::Run() { kernel::LiteKernel *OpenCLMatMulKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { bool hasBias = false; if (opParameter->type_ == PrimitiveType_FullConnection) { hasBias = (reinterpret_cast(opParameter))->has_bias_; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.h index beb874cc67..a1e3e6cbfa 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/matmul.h @@ -36,7 +36,7 @@ class MatMulOpenCLKernel : public LiteKernel { public: explicit MatMulOpenCLKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs, bool hasBias) - : LiteKernel(parameter, inputs, outputs) { + : LiteKernel(parameter, inputs, outputs, nullptr, nullptr) { hasBias_ = hasBias; } ~MatMulOpenCLKernel() override{}; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc index 476ff23dbc..0e7d8dc27c 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc @@ -82,7 +82,7 @@ int PoolingOpenCLKernel::Init() { std::vector PoolingOpenCLKernel::InitGlobalSize() const { const size_t global_x = outputs_[0]->Height(); const size_t global_y = outputs_[0]->Width(); - const size_t global_z = UP_ROUND_DIV(outputs_[0]->Channel(), 4); + const size_t global_z = UP_DIV(outputs_[0]->Channel(), C4NUM); std::vector global = {global_x, global_y, global_z}; return global; } @@ -90,13 +90,8 @@ std::vector PoolingOpenCLKernel::InitGlobalSize() const { int PoolingOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { size_t CO4 = UP_DIV(outputs_[0]->Channel(), C4NUM); size_t im_dst_x, im_dst_y; - if (inputs_[0]->GetFormat() == schema::Format_NHWC4) { - im_dst_x = outputs_[0]->Height(); - im_dst_y = outputs_[0]->Width() * CO4; - } else { - im_dst_y = outputs_[0]->Width(); - im_dst_x = outputs_[0]->Height() * CO4; - } + im_dst_x = outputs_[0]->Width() * CO4; + im_dst_y = outputs_[0]->Height(); #ifdef ENABLE_FP16 size_t img_dtype = CL_HALF_FLOAT; #else @@ -117,7 +112,7 @@ int PoolingOpenCLKernel::Run() { auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); // attribute - int slices = UP_ROUND_DIV(outputs_[0]->Channel(), 4); + int slices = UP_DIV(outputs_[0]->Channel(), C4NUM); cl_int4 input_shape = {inputs_[0]->Height(), inputs_[0]->Width(), inputs_[0]->Channel(), slices}; cl_int4 output_shape = {outputs_[0]->Height(), outputs_[0]->Width(), outputs_[0]->Channel(), slices}; cl_int2 stride = {parameter_->stride_h_, parameter_->stride_w_}; @@ -149,7 +144,7 @@ int PoolingOpenCLKernel::Run() { kernel::LiteKernel *OpenCLPooling2dKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { auto *kernel = new PoolingOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (kernel == nullptr) { MS_LOG(ERROR) << "Create OpenCL Pooling kernel failed!"; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc index 4bdf5db2c4..10e6176ff5 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc @@ -84,7 +84,7 @@ int SoftmaxOpenCLKernel::Run() { kernel::LiteKernel *OpenCLSoftMaxKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { auto *kernel = new SoftmaxOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); if (inputs[0]->shape()[0] > 1) { MS_LOG(ERROR) << "Init `Softmax` kernel failed: Unsupported multi-batch."; @@ -101,4 +101,3 @@ kernel::LiteKernel *OpenCLSoftMaxKernelCreator(const std::vector &inputs, const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) { + : LiteKernel(parameter, inputs, outputs, nullptr, nullptr) { parameter_ = reinterpret_cast(parameter); } ~SoftmaxOpenCLKernel() override{}; diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc index 428c071800..677f99739b 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.cc @@ -67,6 +67,21 @@ int TransposeOpenCLKernel::Init() { int TransposeOpenCLKernel::ReSize() { return 0; } +int TransposeOpenCLKernel::GetImageSize(size_t idx, std::vector *img_size) { + size_t im_dst_x, im_dst_y; + im_dst_x = UP_DIV(outputs_[0]->Height() * outputs_[0]->Width(), C4NUM); + im_dst_y = outputs_[0]->Channel(); +#ifdef ENABLE_FP16 + size_t img_dtype = CL_HALF_FLOAT; +#else + size_t img_dtype = CL_FLOAT; +#endif + img_size->clear(); + std::vector vec{im_dst_x, im_dst_y, img_dtype}; + *img_size = vec; + return RET_OK; +} + int TransposeOpenCLKernel::Run() { MS_LOG(DEBUG) << this->Name() << " Running!"; std::vector shapex = inputs_[0]->shape(); @@ -93,7 +108,7 @@ int TransposeOpenCLKernel::Run() { kernel::LiteKernel *OpenCLTransposeKernelCreator(const std::vector &inputs, const std::vector &outputs, OpParameter *opParameter, const lite::Context *ctx, - const kernel::KernelKey &desc) { + const kernel::KernelKey &desc, const lite::Primitive *primitive) { auto *kernel = new TransposeOpenCLKernel(reinterpret_cast(opParameter), inputs, outputs); auto ret = kernel->Init(); if (0 != ret) { diff --git a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.h b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.h index c16557b5b0..f79f9a273a 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.h +++ b/mindspore/lite/src/runtime/kernel/opencl/kernel/transpose.h @@ -35,7 +35,7 @@ class TransposeOpenCLKernel : public OpenCLKernel { int Init() override; int ReSize() override; int Run() override; - + int GetImageSize(size_t idx, std::vector *img_size) override; private: cl::Kernel kernel_; }; diff --git a/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h b/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h index cf76286e35..10dabfea71 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h +++ b/mindspore/lite/src/runtime/kernel/opencl/opencl_kernel.h @@ -25,7 +25,7 @@ class OpenCLKernel : public LiteKernel { public: explicit OpenCLKernel(OpParameter *parameter, const std::vector &inputs, const std::vector &outputs) - : LiteKernel(parameter, inputs, outputs) {} + : LiteKernel(parameter, inputs, outputs, nullptr, nullptr) {} virtual int Init() { return -1; } virtual int Prepare() { return -1; } diff --git a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc index dcd2fe8943..7c495cf68f 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc +++ b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.cc @@ -24,6 +24,7 @@ SubGraphOpenCLKernel::~SubGraphOpenCLKernel() { UnInit(); } int SubGraphOpenCLKernel::Init() { allocator_ = lite::opencl::OpenCLRuntime::GetInstance()->GetAllocator(); + MS_LOG(DEBUG) << "input num=" << inputs_.size() << ", output num=" << outputs_.size(); for (const auto tensor : inputs_) { tensor->set_allocator(allocator_); } @@ -38,8 +39,7 @@ int SubGraphOpenCLKernel::Init() { data = allocator_->MapBuffer(data, CL_MAP_WRITE, nullptr, true); tensor->SetData(data); } else { - MS_LOG(ERROR) << "OpenCL kernel must use GPU buffer pointer, " - << "please make sure that this buffer allocate by OpenCLAllocator!"; + MS_LOG(ERROR) << "SubGraphOpenCLKernel input nullptr!"; } } return 0; diff --git a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h index 7f7d5a343e..d965c2e7bd 100644 --- a/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h +++ b/mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h @@ -36,7 +36,7 @@ class SubGraphOpenCLKernel : public SubGraphKernel { const std::vector inKernels, const std::vector outKernels, const std::vector nodes) - : SubGraphKernel(inputs, outputs, inKernels, outKernels, nodes) {} + : SubGraphKernel(inputs, outputs, inKernels, outKernels, nodes, nullptr, nullptr) {} ~SubGraphOpenCLKernel() override; int Init() override; diff --git a/mindspore/lite/src/runtime/opencl/opencl_allocator.cc b/mindspore/lite/src/runtime/opencl/opencl_allocator.cc index ed579540b4..649446cbf4 100644 --- a/mindspore/lite/src/runtime/opencl/opencl_allocator.cc +++ b/mindspore/lite/src/runtime/opencl/opencl_allocator.cc @@ -69,8 +69,8 @@ void *OpenCLAllocator::Malloc(size_t size) { host_ptr = clSVMAlloc((*ocl_runtime->Context())(), flags, size, 0); } else { cl_int ret = CL_SUCCESS; - cl::Buffer *buffer = - new cl::Buffer(*ocl_runtime->Context(), CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, size, NULL, &ret); + cl::Buffer *buffer = new cl::Buffer(*ocl_runtime->Context(), CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, + size, NULL, &ret); if (ret != CL_SUCCESS) { MS_LOG(ERROR) << "Create OpenCL buffer failed! (ERROR CODE: " << ret << ")"; UnLock(); @@ -109,7 +109,7 @@ void *OpenCLAllocator::Malloc(size_t size, const std::vector& img_size) auto mem_buf = iter->second; bool is_match{mem_buf->img_size.size() == img_size.size()}; for (int i = 0; i < img_size.size() && is_match; ++i) { - is_match = img_size[i] == mem_buf->img_size[i]; + is_match &= img_size[i] == mem_buf->img_size[i]; } if (is_match) { free_list_.erase(iter); @@ -125,8 +125,8 @@ void *OpenCLAllocator::Malloc(size_t size, const std::vector& img_size) cl_int ret = CL_SUCCESS; // CL_HALF_FLOAT, CL_FLOAT cl::ImageFormat image_format(CL_RGBA, img_size[2]); - cl::Image2D *buffer = new cl::Image2D(*ocl_runtime->Context(), CL_MEM_READ_WRITE, - image_format, img_size[0], img_size[1], 0, nullptr, &ret); + cl::Image2D *buffer = new cl::Image2D(*ocl_runtime->Context(), CL_MEM_READ_WRITE, image_format, + img_size[0], img_size[1], 0, nullptr, &ret); if (ret != CL_SUCCESS) { MS_LOG(ERROR) << "Create OpenCL Image2D failed! (ERROR CODE: " << ret << ")"; UnLock(); @@ -164,20 +164,26 @@ void *OpenCLAllocator::CreateImageFromHost(void *data, size_t size, const std::v auto iter = free_list_.lower_bound(size); if (iter != free_list_.end() && (iter->second->size_ >= size) && (iter->second->size_ < (size << shift_factor_))) { auto mem_buf = iter->second; - free_list_.erase(iter); - allocated_list_[mem_buf->host_ptr_] = mem_buf; - UnLock(); - MS_LOG(DEBUG) << "Malloc Image2D from free list. size: " << mem_buf->size_ << ", host addr: " << mem_buf->host_ptr_ - << ", device addr: " << mem_buf->device_ptr_; - return mem_buf->host_ptr_; + bool is_match{mem_buf->img_size.size() == img_size.size()}; + for (int i = 0; i < img_size.size() && is_match; ++i) { + is_match &= img_size[i] == mem_buf->img_size[i]; + } + if (is_match) { + free_list_.erase(iter); + allocated_list_[mem_buf->host_ptr_] = mem_buf; + UnLock(); + MS_LOG(DEBUG) << "Malloc Image2D from free list. size: " << mem_buf->size_ + << ", host addr: " << mem_buf->host_ptr_ << ", device addr: " << mem_buf->device_ptr_; + return mem_buf->host_ptr_; + } } void *host_ptr = nullptr; void *device_ptr = nullptr; cl_int ret = CL_SUCCESS; // CL_HALF_FLOAT, CL_FLOAT cl::ImageFormat image_format(CL_RGBA, img_size[2]); - cl::Image2D *buffer = new cl::Image2D(*ocl_runtime->Context(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, image_format, - img_size[0], img_size[1], 0, data, &ret); + cl::Image2D *buffer = new cl::Image2D(*ocl_runtime->Context(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, + image_format, img_size[0], img_size[1], 0, data, &ret); if (ret != CL_SUCCESS) { MS_LOG(ERROR) << "Create OpenCL Image2D failed! (ERROR CODE: " << ret << ")"; UnLock(); @@ -372,4 +378,3 @@ int OpenCLAllocator::GetImageSize(void *host_ptr, std::vector* img_size) } } // namespace mindspore::lite::opencl - diff --git a/mindspore/lite/src/runtime/opencl/opencl_executor.cc b/mindspore/lite/src/runtime/opencl/opencl_executor.cc index be273ea523..fec99cd4c0 100644 --- a/mindspore/lite/src/runtime/opencl/opencl_executor.cc +++ b/mindspore/lite/src/runtime/opencl/opencl_executor.cc @@ -56,6 +56,7 @@ int OpenCLExecutor::Run(std::vector &inputs, std::vectorMallocData(allocator); } + output->set_allocator(allocator); } session::CallBackParam callbackParam; callbackParam.name_callback_param = kernel->Name(); @@ -91,7 +92,7 @@ int OpenCLExecutor::Run(std::vector &inputs, std::vectorGetFormat() != schema::Format_NHWC) { - TransformTensorLayout(outTensor, outTensor->GetFormat(), schema::Format_NHWC, false); + TransformTensorLayout(outTensor, outTensor->GetFormat(), schema::Format_NHWC, false); } } return RET_OK; @@ -168,6 +169,7 @@ int OpenCLExecutor::TransformTensorLayoutToBuffer(tensor::Tensor *tensor, schema int OpenCLExecutor::TransformTensorLayoutToImage(tensor::Tensor *tensor, schema::Format src_format, schema::Format dst_format) { if (dst_format == schema::Format_NHWC4) { + tensor->SetFormat(schema::Format_NHWC4); // convert to nhwc4 auto *src_data = tensor->Data(); auto *dst_data{src_data}; @@ -190,7 +192,6 @@ int OpenCLExecutor::TransformTensorLayoutToImage(tensor::Tensor *tensor, schema: dst_data = allocator_->CreateImageFromHost(src_data, tensor->Size(), img_size); tensor->SetData(dst_data); allocator_->Free(src_data); - tensor->SetFormat(schema::Format_NHWC4); return RET_OK; } else { MS_LOG(ERROR) << "Unsupport layout transform: " << schema::EnumNameFormat(tensor->GetFormat()) << " to " diff --git a/mindspore/lite/src/runtime/thread_pool.cc b/mindspore/lite/src/runtime/thread_pool.cc index 933a49664b..adcd8b9026 100644 --- a/mindspore/lite/src/runtime/thread_pool.cc +++ b/mindspore/lite/src/runtime/thread_pool.cc @@ -245,8 +245,6 @@ bool ThreadPool::SetThreadPool() { } else { AddRunThread(localMaxThreadNums); } - MS_LOG(DEBUG) << "configThreadNums=" << configThreadNums << ", curThreadNums=" << curThreadNums - << ", curThreadRunNums=" << curThreadRunNums << ", localMaxThreadNums=" << localMaxThreadNums; return true; } @@ -276,7 +274,6 @@ void ThreadPool::AddNewThread(int newNums) { } curThreadNums += newNums; curThreadRunNums += newNums; - MS_LOG(DEBUG) << "add " << newNums << " thread"; } bool ThreadPool::SetThreadCpuBind(bool ifBind, int mode, bool master) { @@ -330,7 +327,6 @@ bool ThreadPool::AddTask(WorkFun &&worker, void *cdata, int numTask) { } bool ThreadPool::DistributeTask(ThreadPoolTask *task, int numTask) { - MS_LOG(DEBUG) << "numTask = " << numTask << ", curThreadRunNums = " << curThreadRunNums; auto taskOri = *task; if (numTask > curThreadRunNums) { task->first = [taskOri, numTask, this](int task_id, TvmEnv *penv, void *cdata) -> int { @@ -370,12 +366,10 @@ bool ThreadPool::DistributeTask(ThreadPoolTask *task, int numTask) { } } } - MS_LOG(DEBUG) << "finish " << numTask << " task successful"; return CheckResult(); } void ThreadPool::AddRunThread(int num) { - MS_LOG(DEBUG) << "num=" << num << ", curThreadRunNums=" << curThreadRunNums; int activeNums = num - curThreadRunNums; if (activeNums <= 0 || activateList.size() < activeNums) { return; @@ -389,7 +383,6 @@ void ThreadPool::AddRunThread(int num) { } void ThreadPool::SubRunThread(int num) { - MS_LOG(DEBUG) << "num=" << num << ", curThreadRunNums=" << curThreadRunNums; int deactiveNums = curThreadRunNums - num; if (deactiveNums <= 0) { return; diff --git a/mindspore/lite/src/scheduler.cc b/mindspore/lite/src/scheduler.cc index d3a7ca7d69..426c656b06 100644 --- a/mindspore/lite/src/scheduler.cc +++ b/mindspore/lite/src/scheduler.cc @@ -15,10 +15,12 @@ */ #include "src/scheduler.h" -#include #include +#include #include "include/errorcode.h" #include "src/kernel_factory.h" +#include "src/common/graph_util.h" +#include "src/common/utils.h" #if SUPPORT_GPU #include "src/runtime/kernel/opencl/subgraph_opencl_kernel.h" #endif @@ -51,6 +53,7 @@ int Scheduler::InitOp2Kernel(const lite::Model *model, std::vectorGetMetaGraph(); MS_EXCEPTION_IF_NULL(meta_graph); uint32_t kernelCount = meta_graph->nodes()->size(); + auto graph_output_node_indexes = GetGraphOutputNodes(meta_graph); for (uint32_t i = 0; i < kernelCount; i++) { auto cNode = meta_graph->nodes()->GetAs(i); std::vector inputs; @@ -69,11 +72,21 @@ int Scheduler::InitOp2Kernel(const lite::Model *model, std::vectorprimitive()->value_type()); return RET_ERROR; } - auto ret = primitive->InferShape(inputs, outputs); - if (0 != ret) { - MS_LOG(ERROR) << "InferShape failed, name: " << cNode->name()->str() - << ", type: " << schema::EnumNamePrimitiveType(cNode->primitive()->value_type()); - return ret; + if (!context_->infer_shape_interrupt_) { + auto ret = primitive->InferShape(inputs, outputs); + if (ret == RET_INFER_INVALID) { + MS_LOG(INFO) << "InferShape shouldn't be done before runtime, name: " << cNode->name()->str() + << ", type: " << schema::EnumNamePrimitiveType(cNode->primitive()->value_type()) + << "flag set to false."; + primitive->SetInferFlag(false); + context_->InferShapeInterrupt(); + } else if (ret != RET_OK) { + MS_LOG(ERROR) << "InferShape failed, name: " << cNode->name()->str() + << ", type: " << schema::EnumNamePrimitiveType(cNode->primitive()->value_type()); + return RET_INFER_ERR; + } + } else { + primitive->SetInferFlag(false); } auto *kernel = this->ScheduleNode(inputs, outputs, primitive); @@ -83,6 +96,7 @@ int Scheduler::InitOp2Kernel(const lite::Model *model, std::vectorset_name(cNode->name()->str()); + kernel->set_is_model_output(IsContain(graph_output_node_indexes, size_t(i))); kernels->emplace_back(kernel); } return RET_OK; @@ -132,10 +146,26 @@ kernel::LiteKernel *Scheduler::CreateSubKernel(const std::vector input_tensors = kernel::LiteKernelUtil::SubgraphInputTensors(kernels); - std::vector output_tensors = kernel::LiteKernelUtil::SubgraphOutputTensors(kernels); - std::vector input_kernels = kernel::LiteKernelUtil::SubgraphInputKernels(kernels); - std::vector output_kernels = kernel::LiteKernelUtil::SubgraphOutputKernels(kernels); + auto head_kernel = kernels.front(); + auto tail_kernel = kernels.back(); + std::vector input_kernels{head_kernel}; + std::vector output_kernels{tail_kernel}; + std::vector input_tensors; + std::vector output_tensors; + for (auto tensor : head_kernel->GetInputs()) { + if (tensor->Data() == nullptr) { + input_tensors.emplace_back(tensor); + } + } + for (auto tensor : tail_kernel->GetOutputs()) { + if (tensor->Data() == nullptr) { + output_tensors.emplace_back(tensor); + } + } + // std::vector input_tensors = kernel::LiteKernelUtil::SubgraphInputTensors(kernels); + // std::vector output_tensors = kernel::LiteKernelUtil::SubgraphOutputTensors(kernels); + // std::vector input_kernels = kernel::LiteKernelUtil::SubgraphInputKernels(kernels); + // std::vector output_kernels = kernel::LiteKernelUtil::SubgraphOutputKernels(kernels); sub_kernel = new kernel::SubGraphOpenCLKernel(input_tensors, output_tensors, input_kernels, output_kernels, kernels); sub_kernel->Init(); diff --git a/mindspore/lite/src/scheduler.h b/mindspore/lite/src/scheduler.h index f86ca2b035..38a8cca466 100644 --- a/mindspore/lite/src/scheduler.h +++ b/mindspore/lite/src/scheduler.h @@ -25,7 +25,9 @@ namespace mindspore::lite { class Scheduler { public: - explicit Scheduler(const Context *ctx) : context_(ctx) {} + explicit Scheduler(const Context *ctx) { + context_ = const_cast(ctx); + } int Schedule(const lite::Model *model, std::vector *tensors, std::vector *kernels); @@ -48,7 +50,7 @@ class Scheduler { protected: std::vector> markedKernelGroup; - const Context *context_ = nullptr; + Context *context_ = nullptr; }; } // namespace mindspore::lite diff --git a/mindspore/lite/src/train/base_ref_utils.cc b/mindspore/lite/src/train/base_ref_utils.cc index 5df16a9552..61a39d38cb 100644 --- a/mindspore/lite/src/train/base_ref_utils.cc +++ b/mindspore/lite/src/train/base_ref_utils.cc @@ -57,4 +57,3 @@ std::vector>> TransformVectorRefTo return multiTensor; } } // namespace mindspore - diff --git a/mindspore/lite/src/train/base_ref_utils.h b/mindspore/lite/src/train/base_ref_utils.h index 63370efeb9..2d4620ead6 100644 --- a/mindspore/lite/src/train/base_ref_utils.h +++ b/mindspore/lite/src/train/base_ref_utils.h @@ -16,16 +16,15 @@ #include #include -#include "base/base_ref.h" +#include "utils/base_ref.h" #include "include/ms_tensor.h" -#ifndef MINDSPORE_CCSRC_UTILS_BASE_REF_UTILS_H -#define MINDSPORE_CCSRC_UTILS_BASE_REF_UTILS_H +#ifndef MINDSPORE_LITE_SRC_TRAIN_BASE_REF_UTILS_H_ +#define MINDSPORE_LITE_SRC_TRAIN_BASE_REF_UTILS_H_ namespace mindspore { std::vector> TransformBaseRefToMSTensor(const BaseRef &base_ref); std::vector>> TransformVectorRefToMultiTensor( const VectorRef &vector_ref); } // namespace mindspore -#endif // MINDSPORE_CCSRC_UTILS_BASE_REF_UTILS_H - +#endif // MINDSPORE_LITE_SRC_TRAIN_BASE_REF_UTILS_H_ diff --git a/mindspore/lite/src/train/lite_kernel_runtime.cc b/mindspore/lite/src/train/lite_kernel_runtime.cc index e1eb95d442..656e8b3bb7 100644 --- a/mindspore/lite/src/train/lite_kernel_runtime.cc +++ b/mindspore/lite/src/train/lite_kernel_runtime.cc @@ -14,7 +14,8 @@ * limitations under the License. */ -#include "mindspore/lite/src/train/lite_kernel_runtime.h" +#include "src/train/lite_kernel_runtime.h" +#include "backend/session/anf_runtime_algorithm.h" namespace mindspore::lite { std::vector LiteInferKernelRuntime::GetGraphInputs(const std::vector &execution_order) { std::vector graph_inputs; @@ -34,7 +35,8 @@ std::vector LiteInferKernelRuntime::GetGraphInputs(const std::vector &inputs, VectorRef *outputs) { + const std::vector &inputs, + std::vector *outputs) { MS_EXCEPTION_IF_NULL(graph); auto execution_order = graph->execution_order(); auto graph_inputs = GetGraphInputs(execution_order); @@ -56,15 +58,17 @@ void LiteInferKernelRuntime::BindInputOutput(const session::KernelGraph *graph, auto liteKernel = dynamic_cast(AnfAlgo::GetKernelMod(return_input)); auto output_tensors = liteKernel->GetOutputs(); for (auto output_tensor : output_tensors) { - tensor::TensorPtr output_tensor_ptr(output_tensor); - outputs->push_back(output_tensor_ptr); + // tensor::TensorPtr output_tensor_ptr(output_tensor); + outputs->push_back(output_tensor); } } } } -bool LiteInferKernelRuntime::Run(session::KernelGraph *graph) { +bool LiteInferKernelRuntime::Run(session::KernelGraph *graph, const std::vector &inputs, + std::vector *outputs) { MS_EXCEPTION_IF_NULL(graph); + BindInputOutput(graph, inputs, *outputs); std::vector kernels; auto nodes = graph->execution_order(); for (const auto &node : nodes) { @@ -76,8 +80,7 @@ bool LiteInferKernelRuntime::Run(session::KernelGraph *graph) { } kernel::LiteKernelUtil::TopologicalSortKernels(kernels); Executor executor; - auto ret = executor.Run(kernels); + auto ret = executor.Run(inputs, *outputs, kernels); return 0 == ret; } } // namespace mindspore::lite - diff --git a/mindspore/lite/src/train/lite_kernel_runtime.h b/mindspore/lite/src/train/lite_kernel_runtime.h index 27b4ec867b..c5ae2d04d9 100644 --- a/mindspore/lite/src/train/lite_kernel_runtime.h +++ b/mindspore/lite/src/train/lite_kernel_runtime.h @@ -23,35 +23,28 @@ #include #include "src/runtime/allocator.h" #include "src/executor.h" -#include "runtime/device/kernel_runtime.h" +// #include "runtime/device/kernel_runtime.h" #include "runtime/device/device_address.h" #include "src/lite_kernel.h" #include "backend/session/kernel_graph.h" namespace mindspore::lite { -class LiteInferKernelRuntime : public device::KernelRuntime { +class LiteInferKernelRuntime { public: LiteInferKernelRuntime() = default; - ~LiteInferKernelRuntime() override = default; + ~LiteInferKernelRuntime() = default; - bool Init() override { return true; } - - void BindInputOutput(const session::KernelGraph *graph, const std::vector &inputs, - VectorRef *outputs); - - bool Run(session::KernelGraph *graph); + bool Run(session::KernelGraph *graph, const std::vector &inputs, + std::vector *outputs); void AssignKernelAddress(session::KernelGraph *graph) {} protected: + void BindInputOutput(const session::KernelGraph *graph, const std::vector &inputs, + std::vector *outputs); + std::vector GetGraphInputs(const std::vector &execution_order); - bool SyncStream() override { return true; }; - device::DeviceAddressPtr CreateDeviceAddress(void *device_ptr, size_t device_size, const string &format, - TypeId type_id) override { - return nullptr; - }; }; } // namespace mindspore::lite #endif // MINDSPORE_LITE_SRC_TRAIN_LITE_KERNEL_RUNTIME_H_ - diff --git a/mindspore/lite/src/train/model_impl.cc b/mindspore/lite/src/train/model_impl.cc index 30d60f7709..84794dfaaa 100644 --- a/mindspore/lite/src/train/model_impl.cc +++ b/mindspore/lite/src/train/model_impl.cc @@ -16,11 +16,34 @@ #include #include "src/train/model_impl.h" -#include "schema/model_generated.h" #include "ir/func_graph.h" +#include "schema/model_generated.h" +#include "src/common/anf_importer/import_from_meta_graph.h" namespace mindspore::lite::train { +std::shared_ptr ModelImpl::Import(const char *model_buf, size_t size) { + MS_EXCEPTION_IF_NULL(model_buf); + flatbuffers::Verifier verify((const uint8_t *)model_buf, size); + if (!schema::VerifyMetaGraphBuffer(verify)) { + MS_LOG(ERROR) << "The buffer is invalid and fail to create graph."; + return nullptr; + } + // todo hangangqiang remove when copy primitive done + auto *inner_buf = new char[size]; + memcpy(inner_buf, model_buf, size); + auto meta_graph = schema::GetMetaGraph(inner_buf); + auto func_graph_model = std::make_shared(meta_graph); + auto ret = func_graph_model->BuildOps(); + if (0 != ret) { + MS_LOG(ERROR) << "BuildOps failed"; + return nullptr; + } + AnfImporterFromMetaGraph anfImporter(func_graph_model); + anfImporter.Import(); + return func_graph_model; +} + const lite::Primitive *ModelImpl::GetOp(const std::string &name) const { auto iter = ops.find(name); if (iter == ops.end()) { @@ -98,6 +121,8 @@ lite::Primitive *ModelImpl::CopyPrimitive(const schema::Primitive *srcPrim) { return new lite::Nchw2Nhwc(const_cast(srcPrim)); case schema::PrimitiveType_Nhwc2Nchw: return new lite::Nhwc2Nchw(const_cast(srcPrim)); + case schema::PrimitiveType_MatMul: + return new lite::MatMul(const_cast(srcPrim)); default: break; } @@ -115,5 +140,6 @@ int ModelImpl::BuildOps() { auto srcPrim = cNode->primitive(); this->ops[name] = CopyPrimitive(srcPrim); } + return 0; } } // namespace mindspore::lite::train diff --git a/mindspore/lite/src/train/model_impl.h b/mindspore/lite/src/train/model_impl.h index 496fed2ac3..d35956a855 100644 --- a/mindspore/lite/src/train/model_impl.h +++ b/mindspore/lite/src/train/model_impl.h @@ -15,11 +15,12 @@ */ #ifndef MINDSPORE_LITE_SRC_TRAIN_MODEL_IMPL_H_ -#define MINDSPORE_LITE_SRC_TRAIN_MODEL_IMPL_H +#define MINDSPORE_LITE_SRC_TRAIN_MODEL_IMPL_H_ #include #include #include +#include #include "schema/model_generated.h" #include "src/ops/ops.h" #include "ir/func_graph.h" @@ -28,7 +29,7 @@ namespace mindspore::lite { namespace train { class ModelImpl : public FuncGraph { public: - static std::shared_ptr Import(const char *model_buf, size_t size); + static std::shared_ptr Import(const char *model_buf, size_t size); // { return NULL; }; ModelImpl() = default; explicit ModelImpl(const schema::MetaGraph *graph) : meta_graph(graph) {} ~ModelImpl() override = default; @@ -37,16 +38,27 @@ class ModelImpl : public FuncGraph { void FreeMetaGraph(); int BuildOps(); + void AddCNodeInputOutput(std::string name, const std::vector &input, const std::vector &output) { + std::vector *tuple = new std::vector[2]; + tuple[0] = input; + tuple[1] = output; + connectivity_[name] = tuple; + } + std::vector *GetCNodeInputOutputIndices(std::string name) { return connectivity_[name]; } + void AddAnfNode(int id, AnfNodePtr anf_ptr) { tensors_[id] = anf_ptr; } + AnfNodePtr GetAnfNode(int id) { return tensors_[id]; } + protected: lite::Primitive *CopyPrimitive(const schema::Primitive *srcPrim); protected: const schema::MetaGraph *meta_graph = nullptr; + std::map tensors_; + std::map *> connectivity_; std::map ops; }; } // namespace train using ModelImpl = mindspore::lite::train::ModelImpl; } // namespace mindspore::lite -#endif // MINDSPORE_LITE_INCLUDE_MODEL_H - +#endif // MINDSPORE_LITE_SRC_TRAIN_MODEL_IMPL_H_ diff --git a/mindspore/lite/src/train/train_anf_session.cc b/mindspore/lite/src/train/train_anf_session.cc new file mode 100644 index 0000000000..9e7fb5b506 --- /dev/null +++ b/mindspore/lite/src/train/train_anf_session.cc @@ -0,0 +1,253 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "src/train/train_anf_session.h" +#include "include/context.h" +#include "mindspore/ccsrc/runtime/device/kernel_info.h" +#include "mindspore/lite/src/train/train_session.h" +#include "mindspore/lite/src/kernel_factory.h" +#include "mindspore/lite/src/param_value_lite.h" +#include "common/utils.h" +#include "mindspore/lite/src/ops/ops.h" +#include "ir/anf.h" +#include "mindspore/lite/src/ir/tensor.h" +#include "abstract/abstract_value.h" +#include "backend/session/anf_runtime_algorithm.h" +#include "src/ir/primitive_value.h" +#include "src/train/model_impl.h" + +namespace mindspore { +namespace session { +static std::vector GetAnfNodeOutDims(const AnfNodePtr &anfNodePtr) { + auto nodeAbstract = anfNodePtr->abstract(); + if (nodeAbstract != nullptr) { + auto shape = nodeAbstract->GetShapeTrack(); + if (!shape->isa()) { + MS_LOG(EXCEPTION) << "Not a Shape"; + return {}; + } + auto dims = dyn_cast(shape)->shape(); + return dims; + } else { + MS_LOG(WARNING) << "abstract is nullptr, return empty dims"; + return {}; + } +} + +static schema::Format GetAnfNodeFormat(const AnfNodePtr &anfNodePtr) { + auto nodeAbstract = anfNodePtr->abstract(); + if (nodeAbstract != nullptr) { + return schema::Format_NHWC; // XXX TODO -- extract Format from AnfNode + } else { + MS_LOG(WARNING) << "abstract is nullptr, return schema::Format_NHWC"; + return schema::Format_NHWC; + } +} + +static TypeId GetAnfNodeOutTypeId(const AnfNodePtr &anfNodePtr) { + auto nodeAbstract = anfNodePtr->abstract(); + if (nodeAbstract != nullptr) { + return TypeId::kNumberTypeFloat32; // XXX TODO nodeAbstract->GetTypeTrack()->generic_type_id(); + } else { + MS_LOG(WARNING) << "abstract is nullptr, return kTypeUnknown"; + return TypeId::kTypeUnknown; + } +} + +void TrainANFSession::Init(lite::Context *context) { + MS_EXCEPTION_IF_NULL(context); + this->context_ = std::make_shared(context->thread_num_, context->allocator, context->device_ctx_); +} + +lite::tensor::Tensor *TrainANFSession::GetTensorForAnfNode(const AnfNodePtr anf_node) { + lite::tensor::Tensor *out_tensor = tensors_[anf_node]; + if (out_tensor == NULL) { + out_tensor = new lite::tensor::Tensor(GetAnfNodeOutTypeId(anf_node), + GetAnfNodeOutDims(anf_node)); //, schema::NodeType_Parameter); + tensors_[anf_node] = out_tensor; + } + return out_tensor; +} + +int TrainANFSession::BuildKernelInputAndOutputFromFuncGraph(const KernelGraphPtr &kernel_graph) { + auto return_node = kernel_graph->get_return(); + auto node_list = TopoSort(return_node); + auto model_imp = std::dynamic_pointer_cast(func_graph_); + for (auto &node : node_list) { + if (!node->isa()) { + continue; + } + KernelRelation kernel_relation; + auto cnode = node->cast(); + kernel_relation.node_full_name = cnode->fullname_with_scope(); + kernel_relation.cnode = cnode; + std::vector *cnode_io_indices = model_imp->GetCNodeInputOutputIndices(cnode->fullname_with_scope()); + if (cnode_io_indices == NULL) { + MS_LOG(WARNING) << "No IO vectors for " << cnode->fullname_with_scope(); + } else { + for (int i = 0; i < cnode_io_indices[1].size(); i++) { + AnfNodePtr anf_node = model_imp->GetAnfNode(cnode_io_indices[1].data()[i]); + kernel_relation.output_tensor.push_back(GetTensorForAnfNode(anf_node)); + } + } + lite::tensor::Tensor *tensor_ptr = nullptr; + for (size_t index = 1; index < cnode->inputs().size(); ++index) { + if (cnode->input(index)->isa()) { + auto input_cnode = cnode->input(index)->cast(); + auto input_kernel_relation = kernel_relation_infos_[input_cnode->fullname_with_scope()]; + // todo not support multi-outputs kernel sudo as spilt + tensor_ptr = input_kernel_relation.output_tensor.front(); + } else if (cnode->input(index)->isa()) { + auto input_parameter = cnode->input(index)->cast(); + auto para = input_parameter->default_param(); + auto param_value = std::dynamic_pointer_cast(para); + // auto dims = param_value->tensor_shape(); + // tensor_ptr = new lite::tensor::Tensor(param_value->tensor_type(), dims); // schema::NodeType_ValueNode); + tensor_ptr = GetTensorForAnfNode(cnode->input(index)); + if ((param_value != nullptr) && (param_value->tensor_size() != 0)) { + tensor_ptr->SetData(param_value->tensor_addr()); + } + } else if (cnode->input(index)->isa()) { + auto input_valuenode = cnode->input(index)->cast(); + // tensor_ptr = new lite::tensor::Tensor(GetAnfNodeOutTypeId(input_valuenode), + // GetAnfNodeOutDims(input_valuenode)); // schema::NodeType_Parameter); + tensor_ptr = GetTensorForAnfNode(input_valuenode); + // todo(yankai) + } else { + MS_ASSERT(false); + } + kernel_relation.input_tensor.push_back(tensor_ptr); + } + kernel_relation_infos_[cnode->fullname_with_scope()] = kernel_relation; + } + return 0; +} + +GraphId TrainANFSession::graph_sum_ = 0; + +KernelGraphPtr TrainANFSession::NewKernelGraph() { + auto graph = std::make_shared(); + graph->set_graph_id(graph_sum_); + graphs_[graph_sum_++] = graph; + return graph; +} + +std::shared_ptr TrainANFSession::ConstructKernelGraph(const FuncGraphPtr &func_graph) { + MS_EXCEPTION_IF_NULL(func_graph); + auto graph = NewKernelGraph(); + graph->set_return(func_graph->get_return()); + auto node_list = TopoSort(func_graph->get_return()); + std::vector cnode_order; + for (const auto &node : node_list) { + MS_EXCEPTION_IF_NULL(node); + if (node->isa()) { + auto cn_node = node->cast(); + cnode_order.push_back(cn_node); + } + } + graph->set_execution_order(cnode_order); + return graph; +} +GraphId TrainANFSession::CompileGraph(NotNull func_graph) { + auto graph = ConstructKernelGraph(func_graph); + func_graph_ = func_graph; + MS_EXCEPTION_IF_NULL(graph); + MS_LOG(INFO) << "Set kernel info"; + SetKernelInfo(graph.get()); + + (void)BuildKernelInputAndOutputFromFuncGraph(graph); + MS_LOG(INFO) << "Build kernel"; + auto ret = BuildKernel(graph.get()); + if (0 != ret) { + MS_LOG(EXCEPTION) << "BuildKernel failed"; + } + + // return the graph id to backend + auto graph_id = graph->graph_id(); + graphs_[graph_id] = graph; + MS_LOG(INFO) << "Compile graph " << graph_id << " success"; + return graph_id; +} + +void TrainANFSession::RunGraph(const GraphId &graph_id, const std::vector &inputs, + std::vector *outputs) { + auto &kernel_graph = graphs_[graph_id]; + MS_EXCEPTION_IF_NULL(kernel_graph); + MS_LOG(INFO) << "Bind input output address"; + // runtime_.BindInputOutput(kernel_graph.get(), inputs, outputs); -- will be bound in Run + // auto execution_order = kernel_graph->execution_order(); + // Todo : hangangqiang + // Reorder(&execution_order); + // kernel_graph->set_execution_order(execution_order); + MS_LOG(INFO) << "Run graph start"; + auto ret = runtime_.Run(kernel_graph.get(), (std::vector &)inputs, *outputs); + if (!ret) { + MS_LOG(EXCEPTION) << "Run graph failed"; + } + MS_LOG(INFO) << "Run graph end"; +} + +void TrainANFSession::SetKernelInfo(const KernelGraph *kernel_graph) { + MS_EXCEPTION_IF_NULL(kernel_graph); + auto &kernel_nodes = kernel_graph->execution_order(); + for (const auto &kernel_node : kernel_nodes) { + MS_EXCEPTION_IF_NULL(kernel_node); + auto kernel_info = std::make_shared(); + kernel_node->set_kernel_info(kernel_info); + } +} + +int TrainANFSession::BuildKernel(const KernelGraph *kernel_graph) { + MS_EXCEPTION_IF_NULL(kernel_graph); + for (auto iter = kernel_relation_infos_.begin(); iter != kernel_relation_infos_.end(); ++iter) { + std::string kernel_name = iter->first; + KernelRelation anf_register = iter->second; + MS_EXCEPTION_IF_NULL(anf_register.cnode); + if (IsPrimitiveCNode(anf_register.cnode, prim::kPrimReturn)) { + continue; + } + auto value_node_prim = anf_register.cnode->input(0); + MS_EXCEPTION_IF_NULL(value_node_prim); + auto prim = GetValueNode>(value_node_prim); + MS_EXCEPTION_IF_NULL(prim); + auto node_primitive = (lite::Primitive *)(prim->GetPrimitive()); + MS_EXCEPTION_IF_NULL(node_primitive); + auto ret = node_primitive->InferShape(anf_register.input_tensor, anf_register.output_tensor); + if (0 != ret) { + MS_LOG(ERROR) << "InferShape failed, node : " << kernel_name; + return ret; + } + kernel::KernelKey desc{kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, node_primitive->Type()}; + + auto *kernel = lite::KernelFactory::GetInstance()->GetKernel(anf_register.input_tensor, anf_register.output_tensor, + node_primitive, context_.get(), desc); + if (nullptr == kernel) { + MS_LOG(ERROR) << "Create kernel return nullptr, name: " << kernel_name; + return -1; + } + std::shared_ptr kernel_mod(kernel); + kernel_mod->set_name(anf_register.cnode->fullname_with_scope()); + + // kernel->train(); + auto kernel_info = dynamic_cast(anf_register.cnode->kernel_info()); + MS_EXCEPTION_IF_NULL(kernel_info); + kernel_info->set_kernel_mod(kernel_mod); // XXX TODO -- only derived class KernelInfo has this method + } + return 0; +} +} // namespace session +} // namespace mindspore diff --git a/mindspore/lite/src/train/train_anf_session.h b/mindspore/lite/src/train/train_anf_session.h new file mode 100644 index 0000000000..fc495fd49e --- /dev/null +++ b/mindspore/lite/src/train/train_anf_session.h @@ -0,0 +1,76 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 MINDSPORE_LITE_SRC_TRAIN_TRAIN_SESSION_H_ +#define MINDSPORE_LITE_SRC_TRAIN_TRAIN_SESSION_H_ +#include +#include +#include +#include +#include +#include "include/context.h" +#include "backend/session/session_basic.h" +#include "backend/session/kernel_graph.h" +#include "mindspore/lite/src/train/lite_kernel_runtime.h" +// #include "backend/session/session_factory.h" +namespace mindspore { +namespace lite::tensor { +class Tensor; +} +namespace session { +struct KernelRelation { + std::string node_full_name; + std::vector input_tensor; + std::vector output_tensor; + CNodePtr cnode; +}; + +class TrainANFSession { + public: + explicit TrainANFSession(lite::Context *context) { Init(context); } + ~TrainANFSession() = default; + + GraphId CompileGraph(NotNull func_graph); + + void RunGraph(const GraphId &graph_id, const std::vector &inputs, + std::vector *outputs); + + // void RunGraph(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs) override + // {}; + protected: + void Init(lite::Context *context); + std::shared_ptr context_ = nullptr; + std::unordered_map> graphs_; + static GraphId graph_sum_; + KernelGraphPtr NewKernelGraph(); + + private: + // GraphId CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override; + // GraphId CompileGraph(const char *model_buf, size_t size); + std::shared_ptr ConstructKernelGraph(const FuncGraphPtr &func_graph); + int BuildKernelInputAndOutputFromFuncGraph(const KernelGraphPtr &kernel_graph); + + lite::tensor::Tensor *GetTensorForAnfNode(const AnfNodePtr anf_node); + + void SetKernelInfo(const KernelGraph *kernel_graph); + int BuildKernel(const KernelGraph *kernel_graph); + lite::LiteInferKernelRuntime runtime_; + std::map kernel_relation_infos_; + FuncGraphPtr func_graph_ = NULL; + std::map tensors_; +}; +} // namespace session +} // namespace mindspore +#endif // MINDSPORE_LITE_SRC_TRAIN_TRAIN_SESSION_H_ diff --git a/mindspore/lite/src/train/train_session.cc b/mindspore/lite/src/train/train_session.cc index c92473e177..d9d8ddc346 100644 --- a/mindspore/lite/src/train/train_session.cc +++ b/mindspore/lite/src/train/train_session.cc @@ -15,6 +15,8 @@ */ #include +#include "include/context.h" +#include "mindspore/ccsrc/runtime/device/kernel_info.h" #include "mindspore/lite/src/train/train_session.h" #include "mindspore/lite/src/kernel_factory.h" #include "mindspore/lite/src/param_value_lite.h" @@ -25,6 +27,7 @@ #include "abstract/abstract_value.h" #include "backend/session/anf_runtime_algorithm.h" #include "src/ir/primitive_value.h" +#include "src/train/model_impl.h" namespace mindspore { namespace session { @@ -57,16 +60,32 @@ static schema::Format GetAnfNodeFormat(const AnfNodePtr &anfNodePtr) { static TypeId GetAnfNodeOutTypeId(const AnfNodePtr &anfNodePtr) { auto nodeAbstract = anfNodePtr->abstract(); if (nodeAbstract != nullptr) { - return nodeAbstract->GetTypeTrack()->type_id(); + return TypeId::kNumberTypeFloat32; // XXX TODO nodeAbstract->GetTypeTrack()->generic_type_id(); } else { MS_LOG(WARNING) << "abstract is nullptr, return kTypeUnknown"; return TypeId::kTypeUnknown; } } +void TrainSession::Init(lite::Context *context) { + MS_EXCEPTION_IF_NULL(context); + this->context_ = std::make_shared(context->thread_num_, context->allocator, context->device_ctx_); +} + +lite::tensor::Tensor *TrainSession::GetTensorForAnfNode(const AnfNodePtr anf_node) { + lite::tensor::Tensor *out_tensor = tensors_[anf_node]; + if (out_tensor == NULL) { + out_tensor = new lite::tensor::Tensor(GetAnfNodeOutTypeId(anf_node), + GetAnfNodeOutDims(anf_node)); //, schema::NodeType_Parameter); + tensors_[anf_node] = out_tensor; + } + return out_tensor; +} + int TrainSession::BuildKernelInputAndOutputFromFuncGraph(const KernelGraphPtr &kernel_graph) { auto return_node = kernel_graph->get_return(); auto node_list = TopoSort(return_node); + auto model_imp = std::dynamic_pointer_cast(func_graph_); for (auto &node : node_list) { if (!node->isa()) { continue; @@ -75,11 +94,16 @@ int TrainSession::BuildKernelInputAndOutputFromFuncGraph(const KernelGraphPtr &k auto cnode = node->cast(); kernel_relation.node_full_name = cnode->fullname_with_scope(); kernel_relation.cnode = cnode; - auto *out_tensor = - new tensor::Tensor(GetAnfNodeOutTypeId(cnode), GetAnfNodeOutDims(cnode), GetAnfNodeFormat(cnode), - schema::NodeType_Parameter); - kernel_relation.output_tensor.push_back(out_tensor); - tensor::Tensor *tensor_ptr = nullptr; + std::vector *cnode_io_indices = model_imp->GetCNodeInputOutputIndices(cnode->fullname_with_scope()); + if (cnode_io_indices == NULL) { + MS_LOG(WARNING) << "No IO vectors for " << cnode->fullname_with_scope(); + } else { + for (int i = 0; i < cnode_io_indices[1].size(); i++) { + AnfNodePtr anf_node = model_imp->GetAnfNode(cnode_io_indices[1].data()[i]); + kernel_relation.output_tensor.push_back(GetTensorForAnfNode(anf_node)); + } + } + lite::tensor::Tensor *tensor_ptr = nullptr; for (size_t index = 1; index < cnode->inputs().size(); ++index) { if (cnode->input(index)->isa()) { auto input_cnode = cnode->input(index)->cast(); @@ -90,17 +114,17 @@ int TrainSession::BuildKernelInputAndOutputFromFuncGraph(const KernelGraphPtr &k auto input_parameter = cnode->input(index)->cast(); auto para = input_parameter->default_param(); auto param_value = std::dynamic_pointer_cast(para); - auto dims = param_value->tensor_shape(); - tensor_ptr = new tensor::Tensor(param_value->tensor_type(), dims, schema::Format_NHWC, - schema::NodeType_ValueNode); // XXX TODO -- extract Format from AnfNode - if (param_value->tensor_size() != 0) { + // auto dims = param_value->tensor_shape(); + // tensor_ptr = new lite::tensor::Tensor(param_value->tensor_type(), dims); // schema::NodeType_ValueNode); + tensor_ptr = GetTensorForAnfNode(cnode->input(index)); + if ((param_value != nullptr) && (param_value->tensor_size() != 0)) { tensor_ptr->SetData(param_value->tensor_addr()); } } else if (cnode->input(index)->isa()) { auto input_valuenode = cnode->input(index)->cast(); - tensor_ptr = new tensor::Tensor(GetAnfNodeOutTypeId(input_valuenode), GetAnfNodeOutDims(input_valuenode), - schema::Format_NHWC, - schema::NodeType_Parameter); // XXX TODO -- extract Format from AnfNode + // tensor_ptr = new lite::tensor::Tensor(GetAnfNodeOutTypeId(input_valuenode), + // GetAnfNodeOutDims(input_valuenode)); // schema::NodeType_Parameter); + tensor_ptr = GetTensorForAnfNode(input_valuenode); // todo(yankai) } else { MS_ASSERT(false); @@ -111,7 +135,7 @@ int TrainSession::BuildKernelInputAndOutputFromFuncGraph(const KernelGraphPtr &k } return 0; } - +#if 0 GraphId TrainSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) { auto graph_id = graph_sum_; auto graph = SessionBasic::ConstructKernelGraph(lst, outputs); @@ -124,6 +148,17 @@ GraphId TrainSession::CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrLi } GraphId TrainSession::CompileGraph(const char *model_buf, size_t size) { return 0; } +#else +GraphId TrainSession::graph_sum_ = 0; + +KernelGraphPtr TrainSession::NewKernelGraph() { + auto graph = std::make_shared(); + graph->set_graph_id(graph_sum_); + graphs_[graph_sum_++] = graph; + return graph; +} + +#endif std::shared_ptr TrainSession::ConstructKernelGraph(const FuncGraphPtr &func_graph) { MS_EXCEPTION_IF_NULL(func_graph); @@ -141,14 +176,14 @@ std::shared_ptr TrainSession::ConstructKernelGraph(const FuncGraphP graph->set_execution_order(cnode_order); return graph; } - GraphId TrainSession::CompileGraph(NotNull func_graph) { auto graph = ConstructKernelGraph(func_graph); + func_graph_ = func_graph; MS_EXCEPTION_IF_NULL(graph); MS_LOG(INFO) << "Set kernel info"; SetKernelInfo(graph.get()); - (void) BuildKernelInputAndOutputFromFuncGraph(graph); + (void)BuildKernelInputAndOutputFromFuncGraph(graph); MS_LOG(INFO) << "Build kernel"; auto ret = BuildKernel(graph.get()); if (0 != ret) { @@ -162,18 +197,18 @@ GraphId TrainSession::CompileGraph(NotNull func_graph) { return graph_id; } -void TrainSession::RunGraph(const GraphId &graph_id, const std::vector &inputs, - std::vector &outputs) { +void TrainSession::RunGraph(const GraphId &graph_id, const std::vector &inputs, + std::vector *outputs) { auto &kernel_graph = graphs_[graph_id]; MS_EXCEPTION_IF_NULL(kernel_graph); MS_LOG(INFO) << "Bind input output address"; - runtime_.BindInputOutput(kernel_graph.get(), inputs, outputs); + // runtime_.BindInputOutput(kernel_graph.get(), inputs, outputs); -- will be bound in Run // auto execution_order = kernel_graph->execution_order(); // Todo : hangangqiang // Reorder(&execution_order); // kernel_graph->set_execution_order(execution_order); MS_LOG(INFO) << "Run graph start"; - auto ret = runtime_.Run(kernel_graph.get(), (std::vector &) inputs, outputs); + auto ret = runtime_.Run(kernel_graph.get(), (std::vector &)inputs, outputs); if (!ret) { MS_LOG(EXCEPTION) << "Run graph failed"; } @@ -199,34 +234,34 @@ int TrainSession::BuildKernel(const KernelGraph *kernel_graph) { if (IsPrimitiveCNode(anf_register.cnode, prim::kPrimReturn)) { continue; } - lite::Context context; - context.deviceCtx.type = lite::DeviceType::DT_CPU; auto value_node_prim = anf_register.cnode->input(0); MS_EXCEPTION_IF_NULL(value_node_prim); auto prim = GetValueNode>(value_node_prim); MS_EXCEPTION_IF_NULL(prim); - auto node_primitive = (lite::Primitive *) (prim->GetPrimitive()); + auto node_primitive = (lite::Primitive *)(prim->GetPrimitive()); MS_EXCEPTION_IF_NULL(node_primitive); auto ret = node_primitive->InferShape(anf_register.input_tensor, anf_register.output_tensor); if (0 != ret) { MS_LOG(ERROR) << "InferShape failed, node : " << kernel_name; return ret; } - kernel::KernelKey desc{kernel::KERNEL_ARCH::kCPU, node_primitive->Type()}; + kernel::KernelKey desc{kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, node_primitive->Type()}; auto *kernel = lite::KernelFactory::GetInstance()->GetKernel(anf_register.input_tensor, anf_register.output_tensor, - node_primitive, &context, desc); + node_primitive, context_.get(), desc); if (nullptr == kernel) { MS_LOG(ERROR) << "Create kernel return nullptr, name: " << kernel_name; return -1; } - kernel->train(); - auto *kernel_info = anf_register.cnode->kernel_info(); std::shared_ptr kernel_mod(kernel); - kernel_info->set_kernel_mod(kernel_mod); + kernel_mod->set_name(anf_register.cnode->fullname_with_scope()); + + // kernel->train(); + auto kernel_info = dynamic_cast(anf_register.cnode->kernel_info()); + MS_EXCEPTION_IF_NULL(kernel_info); + kernel_info->set_kernel_mod(kernel_mod); // XXX TODO -- only derived class KernelInfo has this method } return 0; } } // namespace session } // namespace mindspore - diff --git a/mindspore/lite/src/train/train_session.h b/mindspore/lite/src/train/train_session.h index d9b026d55f..ff712ffd83 100644 --- a/mindspore/lite/src/train/train_session.h +++ b/mindspore/lite/src/train/train_session.h @@ -19,47 +19,58 @@ #include #include #include +#include +#include "include/context.h" #include "backend/session/session_basic.h" #include "backend/session/kernel_graph.h" #include "mindspore/lite/src/train/lite_kernel_runtime.h" -#include "backend/session/session_factory.h" +// #include "backend/session/session_factory.h" namespace mindspore { namespace lite::tensor { class Tensor; } namespace session { struct KernelRelation { - std::string node_full_name; - std::vector input_tensor; - std::vector output_tensor; - CNodePtr cnode; + std::string node_full_name; + std::vector input_tensor; + std::vector output_tensor; + CNodePtr cnode; }; -class TrainSession : public SessionBasic { +class TrainSession { public: - TrainSession() : SessionBasic() {} - ~TrainSession() override = default; - void Init(uint32_t device_id) override { - SessionBasic::Init(device_id); - context_ = std::make_shared(kCPUDevice, device_id); - } + explicit TrainSession(lite::Context * context) { Init(context); } + ~TrainSession() = default; - GraphId CompileGraph(NotNull func_graph) override; + GraphId CompileGraph(NotNull func_graph); - void RunGraph(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs) override; + void RunGraph(const GraphId &graph_id, const std::vector &inputs, + std::vector *outputs); + + // void RunGraph(const GraphId &graph_id, const std::vector &inputs, VectorRef *outputs) override + // {}; + protected: + void Init(lite::Context *context); + std::shared_ptr context_ = nullptr; + std::unordered_map> graphs_; + static GraphId graph_sum_; + KernelGraphPtr NewKernelGraph(); private: - GraphId CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override; - GraphId CompileGraph(const char *model_buf, size_t size); + // GraphId CompileGraph(const AnfNodePtrList &lst, const AnfNodePtrList &outputs) override; + // GraphId CompileGraph(const char *model_buf, size_t size); std::shared_ptr ConstructKernelGraph(const FuncGraphPtr &func_graph); int BuildKernelInputAndOutputFromFuncGraph(const KernelGraphPtr &kernel_graph); + + lite::tensor::Tensor *GetTensorForAnfNode(const AnfNodePtr anf_node); + void SetKernelInfo(const KernelGraph *kernel_graph); int BuildKernel(const KernelGraph *kernel_graph); lite::LiteInferKernelRuntime runtime_; std::map kernel_relation_infos_; + FuncGraphPtr func_graph_ = NULL; + std::map tensors_; }; -MS_REG_SESSION(kCPUDevice, TrainSession); } // namespace session } // namespace mindspore #endif // MINDSPORE_LITE_SRC_TRAIN_TRAIN_SESSION_H_ - diff --git a/mindspore/lite/test/CMakeLists.txt b/mindspore/lite/test/CMakeLists.txt index 8a9c47ce4a..bd5a436e15 100644 --- a/mindspore/lite/test/CMakeLists.txt +++ b/mindspore/lite/test/CMakeLists.txt @@ -1,5 +1,7 @@ +set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) set(TEST_DIR ${TOP_DIR}/mindspore/lite/test) set(LITE_DIR ${TOP_DIR}/mindspore/lite) +set(CCSRC_DIR ${TOP_DIR}/mindspore/ccsrc) include_directories(${TOP_DIR}) include_directories(${TEST_DIR}) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/dependency_gtest.cmake) @@ -7,11 +9,12 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/dependency_gtest.cmake) ### anf src set(ANF_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../core/ir/meta_tensor.cc - ${CCSRC_DIR}/gvar/logging_level.cc - ${CCSRC_DIR}/gvar/typeid_manager.cc + ${CORE_DIR}/gvar/logging_level.cc + ${CORE_DIR}/gvar/typeid_manager.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../core/base/base.cc ${CMAKE_CURRENT_SOURCE_DIR}/../../core/utils/log_adapter.cc ) + if(BUILD_CONVERTER) set(ANF_SRC ${ANF_SRC} @@ -84,6 +87,16 @@ file(GLOB KERNEL_OP_SRC ${LITE_DIR}/src/runtime/kernel/arm/nnacl/int8/*.cc ${LITE_DIR}/src/runtime/kernel/arm/nnacl/quantization/*.cc ) + +file(GLOB KERNEL_OP_TRAIN_SRC + ${LITE_DIR}/src/runtime/kernel/arm/nnacl/fp32_grad/*.cc + ${LITE_DIR}/src/runtime/kernel/arm/fp32_grad/*.cc +) + +if (SUPPORT_TRAIN) + list(APPEND KERNEL_OP_SRC ${KERNEL_OP_TRAIN_SRC}) +endif() + if (PLATFORM_ARM64) # assembly file(GLOB TEST_ASSEMBLY_SRC ${LITE_DIR}/src/runtime/kernel/arm/nnacl/assembly/arm64/*.s @@ -242,12 +255,13 @@ if (SUPPORT_TRAIN) # ${SRC_DIR}/device/kernel_info.cc # ${SRC_DIR}/device/kernel_runtime.cc # ${SRC_DIR}/device/lite/kernel_runtime_extends.cc - ${LITE_DIR}/src/common/anf_importer/anf_importer.cc - ${LITE_DIR}/src/common/anf_importer/import_from_meta_graph.cc - ${LITE_DIR}/src/ir/primitive_value.cc - ${LITE_DIR}/src/train/lite_kernel_runtime.cc - ${LITE_DIR}/src/train/train_session.cc - ${LITE_DIR}/src/train/model_impl.cc + # ${LITE_DIR}/src/common/anf_importer/anf_importer.cc + # ${LITE_DIR}/src/common/anf_importer/import_from_meta_graph.cc + # ${LITE_DIR}/src/ir/primitive_value.cc + # ${LITE_DIR}/src/train/lite_kernel_runtime.cc + # ${LITE_DIR}/src/train/train_session.cc + # ${LITE_DIR}/src/train/model_impl.cc + ${LITE_DIR}/src/lite_session.cc # temporary ) else() set(TEST_LITE_SRC @@ -262,6 +276,10 @@ file(GLOB_RECURSE TEST_CASE_KERNEL_SRC ${TEST_DIR}/ut/src/runtime/kernel/arm/int8/*.cc ) +file(GLOB_RECURSE TEST_CASE_KERNEL_TRAIN_SRC + ${TEST_DIR}/ut/src/runtime/kernel/arm/fp32_grad/*.cc +) + set(TEST_SRC ${TEST_LITE_SRC} ${TEST_MINDDATA_SRC} @@ -275,7 +293,9 @@ set(TEST_SRC if (SUPPORT_TRAIN) set(TEST_SRC ${TEST_SRC} - ${TEST_DIR}/ut/src/train_test.cc + ${TEST_CASE_KERNEL_TRAIN_SRC} + # ${TEST_DIR}/ut/src/train_test.cc + ${TEST_DIR}/ut/src/infer_test.cc # temporary ) else() set(TEST_SRC @@ -297,6 +317,7 @@ if (SUPPORT_GPU) ${TEST_DIR}/ut/src/runtime/kernel/opencl/utils_tests.cc ${TEST_DIR}/ut/src/runtime/kernel/opencl/conv2d_transpose_tests.cc ${TEST_DIR}/ut/src/runtime/kernel/opencl/transpose_tests.cc + ${TEST_DIR}/ut/src/runtime/kernel/opencl/convolution_tests.cc ) endif() diff --git a/mindspore/lite/test/common/common_test.h b/mindspore/lite/test/common/common_test.h index 7aafb9780c..09fb487f15 100644 --- a/mindspore/lite/test/common/common_test.h +++ b/mindspore/lite/test/common/common_test.h @@ -56,6 +56,19 @@ class Common : public testing::Test { } } + void CompareOutputInt8(int8_t *output_data, int8_t *correct_data, int size, float err_percent) { + int bias_count = 0; + for (size_t i = 0; i < size; i++) { + int8_t diff = abs(output_data[i] - correct_data[i]); + ASSERT_LE(diff, 1); + if (diff == 1) { + bias_count++; + } + } + float bias_percent = static_cast(bias_count) / size; + ASSERT_LE(bias_percent, err_percent); + } + void ReadFile(const char *file, size_t *size, char **buf) { ASSERT_NE(nullptr, file); ASSERT_NE(nullptr, size); diff --git a/mindspore/lite/test/models_caffe.cfg b/mindspore/lite/test/models_caffe.cfg new file mode 100644 index 0000000000..bb769a2470 --- /dev/null +++ b/mindspore/lite/test/models_caffe.cfg @@ -0,0 +1,15 @@ +age_medium +beard +emotion +gender_res_large_deploy +glasses +hat +isface +ml_bank_detect_0312 +ml_face_div_parsing +ml_hardware_eyeclose +ml_ocr_detect_20200305 +Mnet6_0312_extract_pay +pose_3d +RFB-Epoch-170-no-transpose +tracking diff --git a/mindspore/lite/test/models_tflite.cfg b/mindspore/lite/test/models_tflite.cfg index 708784b158..1e39dbb5b7 100644 --- a/mindspore/lite/test/models_tflite.cfg +++ b/mindspore/lite/test/models_tflite.cfg @@ -4,9 +4,6 @@ hiai_bigmodel_ghost_2_1_no_normalized_no_trans_tflite.tflite hiai_bigmodel_ghost_5_1_no_normalized_no_trans_tflite.tflite hiai_cn_recognize_modify_padv2.tflite hiai_model_normalize_object_scene_ps_20200519.tflite -hiai_detectmodel_06_23_960_480_1180700.tflite -hiai_detect_curve_model_float32.tflite -hiai_detectmodel_desnet_256_128_64_32.tflite mtk_AADB_HADB_MBV2_model_fp32.tflite mobilenet_v1_0.25_128.tflite mobilenet_v1_0.25_160.tflite @@ -25,3 +22,5 @@ mobilenet_v1_1.0_160.tflite mobilenet_v1_1.0_192.tflite mobilenet_v1_1.0_224.tflite mobilenet_v2_1.0_224.tflite +densenet.tflite +resnet_v2_101_299.tflite diff --git a/mindspore/lite/test/run_benchmark_nets.sh b/mindspore/lite/test/run_benchmark_nets.sh index 4fc0891c3a..67fe1baa5d 100644 --- a/mindspore/lite/test/run_benchmark_nets.sh +++ b/mindspore/lite/test/run_benchmark_nets.sh @@ -50,10 +50,13 @@ cd $convertor_path/MSLite-*-linux_x86_64 #models_config_filename=/home/workspace/mindspore_dataset/mslite/models/models_config.txt models_tflite_config=${basepath}/models_tflite.cfg +models_caffe_config=${basepath}/models_caffe.cfg + rm -rf ${basepath}/ms_models mkdir -p ${basepath}/ms_models ms_models_path=${basepath}/ms_models +#convert tflite models: while read line;do model_name=$line echo $model_name @@ -61,30 +64,40 @@ while read line;do ./converter_lite --fmk=TFLITE --modelFile=$models_path/${model_name} --outputFile=${ms_models_path}/${model_name} done < ${models_tflite_config} +#convert caffe models: +while read line;do + model_name=$line + echo $model_name + pwd + echo './converter_lite --fmk=CAFFE --modelFile='${models_path}'/'${model_name}'.prototxt --weightFile='${models_path}'/'${model_name}'.caffemodel --outputFile='${ms_models_path}'/'${model_name}'' + ./converter_lite --fmk=CAFFE --modelFile=${models_path}/${model_name}.prototxt --weightFile=${models_path}/${model_name}.caffemodel --outputFile=${ms_models_path}/${model_name} +done < ${models_caffe_config} + + #push to the arm and run benchmark: -#first:copy to the server which connected to the phone +#=====first:copy benchmark exe and so files to the server which connected to the phone rm -rf ${basepath}/benchmark_test mkdir -p ${basepath}/benchmark_test benchmark_test_path=${basepath}/benchmark_test cd ${benchmark_test_path} -cp $arm_path/MSLite-0.6.0-linux_arm64/lib/libmindspore-lite.so ${benchmark_test_path}/libmindspore-lite.so -cp $arm_path/MSLite-0.6.0-linux_arm64/benchmark/benchmark ${benchmark_test_path}/benchmark +cp $arm_path/MSLite-*-linux_arm64/lib/libmindspore-lite.so ${benchmark_test_path}/libmindspore-lite.so +cp $arm_path/MSLite-*-linux_arm64/benchmark/benchmark ${benchmark_test_path}/benchmark -#copy the models: +#copy the MindSpore models: cp ${ms_models_path}/*.ms ${benchmark_test_path} -#second:adb push to the phone +#=====second:adb push all needed files to the phone adb -s $device_id push ${benchmark_test_path} /data/local/tmp/ -#third:run adb ,run session ,check the result: +#=====third:run adb ,run session ,check the result: echo 'cd /data/local/tmp/benchmark_test' > adb_cmd.txt echo 'cp /data/local/tmp/libc++_shared.so ./' >> adb_cmd.txt echo 'chmod 777 benchmark' >> adb_cmd.txt adb -s $device_id shell < adb_cmd.txt -#run models: +#run tflite converted models: while read line;do model_name=$line echo $model_name @@ -94,4 +107,12 @@ while read line;do adb -s $device_id shell < adb_run_cmd.txt done < ${models_tflite_config} - +#run caffe converted models: +while read line;do + model_name=$line + echo $model_name + echo 'cd /data/local/tmp/benchmark_test' > adb_run_cmd.txt + echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/benchmark_test;./benchmark --modelPath='${model_name}'.ms --inDataPath=/data/local/tmp/input_output/input/'${model_name}'.ms.bin --calibDataPath=/data/local/tmp/input_output/output/'${model_name}'.ms.out --warmUpLoopCount=1 --loopCount=1' + echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/benchmark_test;./benchmark --modelPath='${model_name}'.ms --inDataPath=/data/local/tmp/input_output/input/'${model_name}'.ms.bin --calibDataPath=/data/local/tmp/input_output/output/'${model_name}'.ms.out --warmUpLoopCount=1 --loopCount=1' >> adb_run_cmd.txt + adb -s $device_id shell < adb_run_cmd.txt +done < ${models_caffe_config} diff --git a/mindspore/lite/test/run_test.sh b/mindspore/lite/test/run_test.sh index adfb48130f..9e9d677d9b 100755 --- a/mindspore/lite/test/run_test.sh +++ b/mindspore/lite/test/run_test.sh @@ -12,17 +12,19 @@ cp -r ${CUR_DIR}/ut/tools/converter/parser/tflite/test_data/* ./ TEST_DATA_DIR=${CUR_DIR}/../../../tests/ut/data/dataset/ cp -fr $TEST_DATA_DIR/testPK ./data -./lite-test --gtest_filter="*MindDataTestTensorDE*" -./lite-test --gtest_filter="*MindDataTestEager*" +#./lite-test --gtest_filter="*MindDataTestTensorDE*" +#./lite-test --gtest_filter="*MindDataTestEager*" +# +#./lite-test --gtest_filter="TestTfliteParser*" +# +#./lite-test --gtest_filter="*TestHebing*" +# +#./lite-test --gtest_filter=TestFcFp32* +#./lite-test --gtest_filter=TestConv1x1Fp32* +#./lite-test --gtest_filter=TestStrassenFp32* +#./lite-test --gtest_filter=TestDeConvolutionFp32* +# +#./lite-test --gtest_filter=TestPadInt8.* +#./lite-test --gtest_filter=TestDeconvInt8.* ./lite-test --gtest_filter="TestTfliteParser*" - -./lite-test --gtest_filter="*TestHebing*" - -./lite-test --gtest_filter=TestFcFp32* -./lite-test --gtest_filter=TestConv1x1Fp32* -./lite-test --gtest_filter=TestStrassenFp32* -./lite-test --gtest_filter=TestDeConvolutionFp32* - -./lite-test --gtest_filter=TestPadInt8.* -./lite-test --gtest_filter=TestDeconvInt8.* diff --git a/mindspore/lite/test/st/benchmark_test.cc b/mindspore/lite/test/st/benchmark_test.cc index 86b468677b..7454565a04 100644 --- a/mindspore/lite/test/st/benchmark_test.cc +++ b/mindspore/lite/test/st/benchmark_test.cc @@ -26,18 +26,18 @@ class BenchmarkTest : public mindspore::Common { }; TEST_F(BenchmarkTest, TestVideo) { - const char *argv[] = {"./benchmark", "--modelPath=./hiai/hiai_label_and_video.ms" - "--inDataPath=./hiai/hiai_label_and_video.bin" + const char *argv[] = {"./benchmark", "--modelPath=./hiai/hiai_label_and_video.ms", + "--inDataPath=./hiai/hiai_label_and_video.bin", "--calibDataPath=./hiai/hiai_label_and_video.txt"}; - auto status = RunBenchmark(2, argv); + auto status = RunBenchmark(4, argv); ASSERT_EQ(status, RET_OK); } TEST_F(BenchmarkTest, TestOCR_02) { - const char *argv[] = {"./benchmark", "--modelPath=./hiai/hiai_cv_focusShootOCRMOdel_02.ms" - "--inDataPath=./hiai/hiai_cv_focusShootOCRMOdel_02.bin" + const char *argv[] = {"./benchmark", "--modelPath=./hiai/hiai_cv_focusShootOCRMOdel_02.ms", + "--inDataPath=./hiai/hiai_cv_focusShootOCRMOdel_02.bin", "--calibDataPath=./hiai/hiai_cv_focusShootOCRMOdel_02.txt"}; - auto status = RunBenchmark(2, argv); + auto status = RunBenchmark(4, argv); ASSERT_EQ(status, RET_OK); } @@ -50,11 +50,20 @@ auto status = RunBenchmark(5, argv); ASSERT_EQ(status, RET_OK); } +TEST_F(BenchmarkTest, Test_MV2_GPU) { +const char *argv[] = {"./benchmark", "--modelPath=./hiai/mobilenet_v2.ms", + "--inDataPath=./hiai/mobilenet_v2_in.bin", + "--calibDataPath=./hiai/mobilenet_v2_out.bin", + "--device=GPU"}; +auto status = RunBenchmark(5, argv); +ASSERT_EQ(status, RET_OK); +} + TEST_F(BenchmarkTest, TestHebing) { - const char *argv[] = {"./benchmark", "--modelPath=./hiai/model_hebing_3branch.ms" - "--inDataPath=./hiai/model_hebing_3branch.bin" + const char *argv[] = {"./benchmark", "--modelPath=./hiai/model_hebing_3branch.ms", + "--inDataPath=./hiai/model_hebing_3branch.bin", "--calibDataPath=./hiai/model_hebing_3branch.txt"}; - auto status = RunBenchmark(2, argv); + auto status = RunBenchmark(4, argv); ASSERT_EQ(status, RET_OK); } } // namespace lite diff --git a/mindspore/lite/test/ut/src/dataset/eager_test.cc b/mindspore/lite/test/ut/src/dataset/eager_test.cc index ffc271a981..2621bd99b0 100644 --- a/mindspore/lite/test/ut/src/dataset/eager_test.cc +++ b/mindspore/lite/test/ut/src/dataset/eager_test.cc @@ -17,8 +17,7 @@ #include "common/common_test.h" #include "gtest/gtest.h" #include "./securec.h" -#include "minddata/dataset/core/tensor.h" -#include "minddata/dataset/core/config_manager.h" +#include "minddata/dataset/include/tensor.h" #include "minddata/dataset/include/datasets.h" #include "minddata/dataset/include/execute.h" #include "minddata/dataset/util/path.h" diff --git a/mindspore/lite/test/ut/src/infer_test.cc b/mindspore/lite/test/ut/src/infer_test.cc index 5931d89034..04c30e241b 100644 --- a/mindspore/lite/test/ut/src/infer_test.cc +++ b/mindspore/lite/test/ut/src/infer_test.cc @@ -109,7 +109,7 @@ TEST_F(InferTest, TestConvNode) { context->thread_num_ = 4; auto session = session::LiteSession::CreateSession(context); ASSERT_NE(nullptr, session); - auto ret = session->CompileGraph(model.get()); + auto ret = session->CompileGraph(model); ASSERT_EQ(lite::RET_OK, ret); auto inputs = session->GetInputs(); ASSERT_EQ(inputs.size(), 1); @@ -130,7 +130,8 @@ TEST_F(InferTest, TestConvNode) { ASSERT_EQ(lite::RET_OK, ret); auto outputs = session->GetOutputs(); ASSERT_EQ(outputs.size(), 1); - auto outTensor = outputs.front(); + ASSERT_EQ(outputs.begin()->second.size(), 1); + auto outTensor = outputs.begin()->second.front(); ASSERT_NE(nullptr, outTensor); ASSERT_EQ(28 * 28 * 32, outTensor->ElementsNum()); ASSERT_EQ(TypeId::kNumberTypeFloat32, outTensor->data_type()); @@ -206,7 +207,7 @@ TEST_F(InferTest, TestAddNode) { context->thread_num_ = 4; auto session = session::LiteSession::CreateSession(context); ASSERT_NE(nullptr, session); - auto ret = session->CompileGraph(model.get()); + auto ret = session->CompileGraph(model); ASSERT_EQ(lite::RET_OK, ret); auto inputs = session->GetInputs(); ASSERT_EQ(inputs.size(), 2); @@ -220,7 +221,8 @@ TEST_F(InferTest, TestAddNode) { ASSERT_EQ(lite::RET_OK, ret); auto outputs = session->GetOutputs(); ASSERT_EQ(outputs.size(), 1); - auto outTensor = outputs.front(); + ASSERT_EQ(outputs.begin()->second.size(), 1); + auto outTensor = outputs.begin()->second.front(); ASSERT_NE(nullptr, outTensor); ASSERT_EQ(28 * 28 * 3, outTensor->ElementsNum()); ASSERT_EQ(TypeId::kNumberTypeFloat32, outTensor->data_type()); @@ -257,7 +259,7 @@ TEST_F(InferTest, TestModel) { context->thread_num_ = 4; auto session = session::LiteSession::CreateSession(context); ASSERT_NE(nullptr, session); - auto ret = session->CompileGraph(model.get()); + auto ret = session->CompileGraph(model); ASSERT_EQ(lite::RET_OK, ret); auto inputs = session->GetInputs(); ASSERT_EQ(inputs.size(), 1); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/common/strided_slice_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/common/strided_slice_tests.cc index 16ea9e1f75..60e2acff00 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/common/strided_slice_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/common/strided_slice_tests.cc @@ -63,7 +63,7 @@ TEST_F(TestStridedSlice, StridedSlice) { ASSERT_NE(creator, nullptr); auto ctx = std::make_shared(); - auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); ASSERT_NE(kernel, nullptr); auto ret = kernel->Run(); @@ -109,7 +109,7 @@ TEST_F(TestStridedSlice, StridedSliceInt8) { ASSERT_NE(creator, nullptr); auto ctx = std::make_shared(); - auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); ASSERT_NE(kernel, nullptr); auto ret = kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/activation_fp32_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/activation_fp32_test.cc index 0fdfe5f29e..f09caab0b5 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/activation_fp32_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/activation_fp32_test.cc @@ -114,7 +114,7 @@ TEST_F(TestActivationFp32, HSwishFp32) { lite::Context ctx; ctx.thread_num_ = 7; kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), &ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), &ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor.shape(); kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/batchnorm_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/batchnorm_fp32_tests.cc index 8e8c191866..b65e6ecaab 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/batchnorm_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/batchnorm_fp32_tests.cc @@ -77,7 +77,7 @@ TEST_F(TestBatchnormFp32, BNTest) { lite::Context ctx; ctx.thread_num_ = 7; kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), &ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), &ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor.shape(); kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/conv1x1_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/conv1x1_fp32_tests.cc index da3c661697..3d57b070c3 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/conv1x1_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/conv1x1_fp32_tests.cc @@ -20,7 +20,7 @@ #include "common/common_test.h" #include "src/common/file_utils.h" #include "src/runtime/kernel/arm/fp32/convolution_1x1.h" -#include "src/runtime/kernel/arm/nnacl/matmul.h" +#include "src/runtime/kernel/arm/nnacl/matmul_parameter.h" #include "src/runtime/kernel/arm/nnacl/strassen_matmul.h" namespace mindspore { @@ -296,7 +296,7 @@ TEST_F(TestConv1x1Fp32, Conv1x1Test1) { float *correct; int total_size = Conv1x1TestInit1(&inputs_, &outputs_, conv_param, &correct); kernel::Convolution1x1CPUKernel *conv1x1 = - new kernel::Convolution1x1CPUKernel(reinterpret_cast(conv_param), inputs_, outputs_, ctx); + new kernel::Convolution1x1CPUKernel(reinterpret_cast(conv_param), inputs_, outputs_, ctx, nullptr); conv1x1->Init(); conv1x1->Run(); @@ -364,7 +364,7 @@ TEST_F(TestConv1x1Fp32, Conv1x1Test2) { float *correct; int total_size = Conv1x1TestInit2(&inputs_, &outputs_, conv_param, &correct); kernel::Convolution1x1CPUKernel *conv1x1 = - new kernel::Convolution1x1CPUKernel(reinterpret_cast(conv_param), inputs_, outputs_, ctx); + new kernel::Convolution1x1CPUKernel(reinterpret_cast(conv_param), inputs_, outputs_, ctx, nullptr); conv1x1->Init(); conv1x1->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32_tests.cc index 3394ecb5af..86acfe7b57 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/convolution_depthwise_fp32_tests.cc @@ -116,7 +116,8 @@ TEST_F(TestConvolutionDwFp32, ConvDwFp32Accuracy) { kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_DepthwiseConv2D}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); - kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(conv_param), ctx, desc); + kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(conv_param), ctx, desc, + nullptr); ASSERT_NE(kernel, nullptr); // op run kernel->Run(); @@ -166,7 +167,8 @@ TEST_F(TestConvolutionDwFp32, ConvDwFp32Performance) { kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, schema::PrimitiveType_DepthwiseConv2D}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); - kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(conv_param), ctx, desc); + kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(conv_param), ctx, desc, + nullptr); ASSERT_NE(kernel, nullptr); /* running warm up */ diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc index 727f86f3b9..df598547e2 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/deconvolution_fp32_tests.cc @@ -297,7 +297,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest1) { float *correct; int total_size = DeConvTestInit1(&inputs_, &outputs_, deconv_param, &correct); kernel::DeConvolutionCPUKernel *deconv = - new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx); + new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx, nullptr); deconv->Init(); deconv->Run(); @@ -366,7 +366,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest2) { lite::Context *ctx = new lite::Context; ctx->thread_num_ = 4; kernel::DeConvolutionCPUKernel *deconv = - new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx); + new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx, nullptr); deconv->Init(); deconv->Run(); @@ -445,7 +445,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest3) { lite::Context *ctx = new lite::Context; ctx->thread_num_ = 2; kernel::DeConvolutionCPUKernel *deconv = - new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx); + new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx, nullptr); deconv->Init(); deconv->Run(); @@ -517,7 +517,7 @@ TEST_F(TestDeConvolutionFp32, DeConvTest4) { lite::Context *ctx = new lite::Context; ctx->thread_num_ = 2; kernel::DeConvolutionCPUKernel *deconv = - new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx); + new kernel::DeConvolutionCPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx, nullptr); deconv->Init(); deconv->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/elu_fp32_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/elu_fp32_test.cc new file mode 100644 index 0000000000..acefdb8733 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/elu_fp32_test.cc @@ -0,0 +1,72 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "src/runtime/kernel/arm/fp32/elu.h" +#include "src/runtime/kernel/arm/nnacl/fp32/elu.h" +#include "src/common/file_utils.h" +#include "common/common_test.h" +#include "utils/log_adapter.h" + +namespace mindspore { +using mindspore::lite::tensor::Tensor; + +class TestEluFp32 : public mindspore::Common { + public: + TestEluFp32() {} +}; + +void EluTestInit(std::vector *inputs_, std::vector *outputs_, EluParameter *elu_param) { + Tensor *in_t_first = new Tensor(kNumberTypeFloat32, {6, 2}, schema::Format_NHWC, static_cast(1)); + in_t_first->MallocData(); + float in_first[] = {-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 0}; + memcpy(in_t_first->Data(), in_first, sizeof(float) * in_t_first->ElementsNum()); + inputs_->push_back(in_t_first); + + Tensor *outputs_t = new Tensor(kNumberTypeFloat32, {6, 2}, schema::Format_NHWC, static_cast(1)); + outputs_t->MallocData(); + outputs_->push_back(outputs_t); + + elu_param->alpha_ = 2.0; +} + +TEST_F(TestEluFp32, EluTest) { + std::vector inputs_; + std::vector outputs_; + auto elu_param_ = new EluParameter(); + EluTestInit(&inputs_, &outputs_, elu_param_); + + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + kernel::EluCPUKernel *elu = + new kernel::EluCPUKernel(reinterpret_cast(elu_param_), inputs_, outputs_, ctx, nullptr); + + elu->Init(); + elu->Run(); + + std::cout << "output shape:" << std::endl; + for (int i = 0; i < outputs_.front()->shape().size(); ++i) { + std::cout << outputs_.front()->shape()[i] << ' '; + } + std::cout << std::endl; + float *out = reinterpret_cast(outputs_.front()->Data()); + for (int i = 0; i < outputs_.front()->ElementsNum(); ++i) { + std::cout << out[i] << ' '; + } + std::cout << std::endl; +} + +}; // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/embedding_lookup_fp32_test.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/embedding_lookup_fp32_test.cc index 1f6d2997c4..02aff1d460 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/embedding_lookup_fp32_test.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/embedding_lookup_fp32_test.cc @@ -65,7 +65,7 @@ TEST_F(TestEmbeddingLookupFp32, ElTest) { lite::Context *ctx = new lite::Context; ctx->thread_num_ = 2; kernel::EmbeddingLookupCPUKernel *el = new kernel::EmbeddingLookupCPUKernel( - reinterpret_cast(embedding_lookup_param_), inputs_, outputs_, ctx); + reinterpret_cast(embedding_lookup_param_), inputs_, outputs_, ctx, nullptr); el->Init(); el->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc index 9a226fef65..fd4ed81a14 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/fullconnection_fp32_tests.cc @@ -79,7 +79,7 @@ TEST_F(TestFcFp32, FcTest1) { lite::Context *ctx = new lite::Context; ctx->thread_num_ = 2; kernel::FullconnectionCPUKernel *fc = - new kernel::FullconnectionCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx); + new kernel::FullconnectionCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); fc->Init(); fc->Run(); @@ -136,7 +136,7 @@ TEST_F(TestFcFp32, FcTest2) { lite::Context *ctx = new lite::Context; ctx->thread_num_ = 1; kernel::FullconnectionCPUKernel *fc = - new kernel::FullconnectionCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx); + new kernel::FullconnectionCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); fc->Init(); fc->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/lstm_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/lstm_fp32_tests.cc index f591548c00..41312db0b1 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/lstm_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/lstm_fp32_tests.cc @@ -152,7 +152,8 @@ TEST_F(LstmFp32, LstmForwardFp32Accuracy) { kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, mindspore::schema::PrimitiveType_Lstm}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); - kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(lstm_param), ctx, desc); + kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(lstm_param), ctx, desc, + nullptr); ASSERT_NE(kernel, nullptr); // op run kernel->Run(); @@ -299,7 +300,8 @@ TEST_F(LstmFp32, LstmBackwardFp32Accuracy) { kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeFloat32, mindspore::schema::PrimitiveType_Lstm}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); - kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(lstm_param), ctx, desc); + kernel::LiteKernel *kernel = creator(inputs, outputs, reinterpret_cast(lstm_param), ctx, desc, + nullptr); ASSERT_NE(kernel, nullptr); // op run kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc index 8ce0da32d0..b4890a0cb0 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/matmul_fp32_tests.cc @@ -88,7 +88,7 @@ TEST_F(TestMatMulFp32, Row8x82RowTest1) { 0.04, 0.24, 0.52, 0.43, 0.14, 0.67, 0.10, 0.73, 0.37, 0.24, 0.93, 0.31, 0.35, 0.52, 0.02, 0.33, 0.99, 0.49, 0.67, 0.75, 0.66, 0.04, 0.10, 0.18, 0.92, 0.46, 0.08, 0.04, 0.24, 0.52}; float out[90] = {0}; - Row8x8Major2RowMajor(in, out, 18, 5); + Row8x8Major2RowMajor(in, out, 18, 5, 5); CompareOutputData(out, co, 90, 0.0001); } @@ -100,7 +100,7 @@ TEST_F(TestMatMulFp32, Row8x82RowTest2) { float co[] = {0.21, 0.38, 0.81, 0.98, 0.09, 0.68, 0.02, 0.33, 0.85, 0.67, 0.81, 0.57, 0.70, 0.27, 0.90, 0.07, 0.13, 0.03, 0.53, 0.97, 0.92, 0.35, 0.74, 0.78, 0.87, 0.23, 0.34, 0.09, 0.50, 0.39}; float out[30] = {0}; - Row8x8Major2RowMajor(in, out, 6, 5); + Row8x8Major2RowMajor(in, out, 6, 5, 5); CompareOutputData(out, co, 30, 0.0001); } @@ -161,10 +161,24 @@ TEST_F(TestMatMulFp32, Row8x82RowTest3) { 0.31, 0.35, 0.52, 0.02, 0.33, 0.99, 0.49, 0.67, 0.75, 0.66, 0.04, 0.10, 0.18, 0.92, 0.46, 0.08, 0.04, 0.24, 0.52, 0.21, 0.38, 0.81, 0.98, 0.09, 0.68, 0.02, 0.33, 0.85, 0.67, 0.81, 0.57, 0.70, 0.27, 0.90, 0.07, 0.13, 0.03, 0.53}; float out[418] = {0}; - Row8x8Major2RowMajor(in, out, 22, 19); + Row8x8Major2RowMajor(in, out, 22, 19, 19); CompareOutputData(out, co, 418, 0.0001); } +TEST_F(TestMatMulFp32, Row8x82RowTest4) { + float in[] = {0.21, 0.38, 0.81, 0.98, 0.09, 0.68, 0.02, 0.33, 0.85, 0.67, 0.81, 0.57, 0.70, 0.27, 0.90, 0.27, + 0.14, 0.67, 0.10, 0.73, 0.37, 0.24, 0.93, 0.31, 0.70, 0.27, 0.90, 0.07, 0.13, 0.03, 0.53, 0.97, + 0.93, 0.91, 0.20, 0.97, 0.61, 0.43, 0.14, 0.67, 0.49, 0.67, 0.75, 0.66, 0.04, 0.10, 0.18, 0.92, + 0.07, 0.13, 0.03, 0.53, 0.97, 0.92, 0.35, 0.74, 0.78, 0.87, 0.23, 0.34, 0.09, 0.50, 0.27, 0.39}; + float co[] = {0.21, 0.38, 0.81, 0.98, 0.09, 0.68, 0.02, 0.33, 0.85, 0.67, 0.81, 0.57, 0.70, 0.27, 0.90, 0.27, + 0.14, 0.67, 0.10, 0.73, 0.37, 0.24, 0.93, 0.31, 0.70, 0.27, 0.90, 0.07, 0.13, 0.03, 0.53, 0.97, + 0.93, 0.91, 0.20, 0.97, 0.61, 0.43, 0.14, 0.67, 0.49, 0.67, 0.75, 0.66, 0.04, 0.10, 0.18, 0.92, + 0.07, 0.13, 0.03, 0.53, 0.97, 0.92, 0.35, 0.74, 0.78, 0.87, 0.23, 0.34, 0.09, 0.50, 0.27, 0.39}; + float out[64] = {0}; + Row8x8Major2RowMajor(in, out, 8, 8, 8); + CompareOutputData(out, co, 64, 0.0001); +} + int MMTestInit(std::vector *inputs_, std::vector *outputs_, float *a_ptr, float *b_ptr, std::vector a_shape, std::vector b_shape, std::vector c_shape) { @@ -201,19 +215,108 @@ TEST_F(TestMatMulFp32, simple) { 0.006050155, 0.008656233, 0.012911413, -0.0028635843, -0.00034080597, -0.0010622552, -0.012254699, -0.01312836, 0.0025241964, -0.004706142, 0.002451482, -0.009558459, 0.004481974, 0.0033251503, -0.011705584, -0.001720293, -0.0039410214, -0.0073637343}; - std::vector a_shape = {1, 2, 8}; - std::vector b_shape = {1, 8, 3}; - std::vector c_shape = {1, 2, 3}; + std::vector a_shape = {2, 8}; + std::vector b_shape = {8, 3}; + std::vector c_shape = {2, 3}; int total_size = MMTestInit(&inputs_, &outputs_, a, b, a_shape, b_shape, c_shape); auto ctx = new lite::Context; - ctx->thread_num_ = 2; - auto mm = new kernel::MatmulCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx); + ctx->thread_num_ = 1; + auto mm = new kernel::MatmulCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); mm->Init(); mm->Run(); float correct[] = {-0.1256939023733139, -0.07744802534580231, 0.07410638779401779, -0.3049793541431427, -0.027687929570674896, -0.18109679222106934}; CompareOutputData(reinterpret_cast(outputs_[0]->Data()), correct, total_size, 0.0001); - delete matmul_param; + delete mm; + for (auto t : inputs_) delete t; + for (auto t : outputs_) delete t; +} + +TEST_F(TestMatMulFp32, simple2) { + std::vector inputs_; + std::vector outputs_; + auto matmul_param = new MatMulParameter(); + matmul_param->a_transpose_ = false; + matmul_param->b_transpose_ = false; + matmul_param->has_bias_ = false; + float a[25 * 12] = { + 1, 4, 10, 2, 3, 10, 4, 6, 5, 6, 9, 5, 4, 2, 5, 7, 5, 8, 0, 5, 1, 0, 10, 3, 0, 4, 2, 3, 2, 9, + 8, 9, 5, 4, 4, 9, 7, 4, 2, 6, 10, 2, 1, 7, 2, 10, 5, 10, 1, 2, 2, 9, 8, 8, 2, 5, 6, 3, 2, 8, + 3, 3, 7, 3, 0, 4, 10, 9, 0, 5, 2, 6, 1, 10, 7, 6, 9, 6, 0, 3, 8, 0, 8, 3, 10, 4, 7, 7, 0, 5, + 6, 5, 4, 6, 5, 5, 3, 7, 1, 9, 3, 2, 8, 3, 0, 0, 6, 7, 6, 3, 6, 5, 1, 0, 4, 2, 6, 0, 7, 7, + 7, 4, 9, 8, 6, 1, 10, 10, 7, 3, 0, 6, 9, 4, 1, 4, 4, 3, 1, 6, 7, 3, 8, 6, 4, 10, 9, 8, 10, 5, + 2, 3, 8, 10, 0, 8, 2, 9, 5, 3, 3, 0, 1, 8, 1, 1, 2, 0, 1, 5, 5, 0, 1, 10, 9, 9, 3, 6, 7, 1, + 2, 3, 7, 5, 0, 8, 2, 8, 7, 8, 9, 10, 4, 2, 5, 3, 10, 1, 5, 0, 6, 2, 3, 5, 5, 1, 5, 5, 5, 1, + 8, 2, 6, 9, 10, 4, 9, 1, 10, 9, 8, 2, 5, 2, 4, 2, 3, 7, 7, 2, 9, 10, 10, 10, 5, 1, 8, 8, 10, 3, + 2, 10, 2, 6, 5, 9, 10, 6, 10, 0, 5, 5, 4, 0, 9, 4, 4, 9, 4, 6, 4, 2, 5, 2, 10, 5, 9, 8, 1, 4, + 7, 9, 6, 5, 0, 3, 6, 4, 3, 10, 6, 4, 10, 5, 8, 8, 9, 4, 5, 6, 8, 9, 2, 2, 4, 4, 8, 0, 4, 5}; + float b[12 * 36] = { + 6, 6, 7, 2, 1, 10, 3, 7, 7, 5, 5, 5, 6, 6, 9, 8, 4, 10, 9, 5, 5, 7, 2, 1, 7, 9, 10, 0, 3, + 10, 4, 2, 7, 4, 3, 10, 5, 3, 1, 3, 3, 1, 9, 6, 7, 6, 6, 6, 7, 6, 10, 8, 2, 8, 5, 2, 1, 7, + 5, 9, 10, 9, 0, 8, 10, 2, 3, 4, 0, 7, 5, 5, 0, 9, 6, 1, 6, 7, 4, 1, 0, 3, 0, 7, 3, 0, 10, + 7, 6, 4, 10, 7, 6, 5, 10, 2, 10, 9, 10, 6, 9, 10, 8, 8, 5, 3, 9, 10, 8, 3, 3, 4, 6, 2, 6, 0, + 4, 0, 3, 4, 1, 0, 3, 10, 5, 4, 0, 2, 3, 2, 4, 3, 10, 5, 4, 10, 8, 2, 0, 4, 0, 5, 8, 0, 1, + 10, 0, 3, 1, 1, 9, 4, 0, 3, 0, 1, 6, 3, 10, 0, 10, 3, 3, 0, 6, 7, 3, 2, 3, 5, 10, 6, 1, 5, + 7, 3, 3, 1, 1, 10, 5, 4, 0, 8, 4, 0, 9, 6, 2, 3, 6, 10, 10, 0, 2, 2, 1, 2, 7, 10, 9, 7, 10, + 2, 8, 5, 3, 7, 0, 4, 3, 4, 8, 3, 8, 0, 5, 5, 6, 9, 10, 0, 1, 5, 6, 6, 4, 7, 7, 6, 7, 9, + 5, 5, 6, 0, 4, 1, 2, 6, 8, 4, 10, 4, 10, 9, 8, 8, 1, 7, 1, 8, 1, 0, 10, 8, 8, 1, 8, 0, 10, + 3, 1, 7, 0, 10, 5, 0, 2, 8, 4, 1, 8, 1, 6, 7, 1, 8, 3, 4, 3, 4, 7, 0, 9, 1, 1, 4, 8, 10, + 0, 3, 3, 2, 7, 9, 3, 3, 10, 10, 9, 4, 4, 0, 7, 1, 1, 3, 5, 1, 4, 8, 5, 7, 3, 9, 10, 1, 5, + 9, 7, 4, 10, 10, 3, 4, 3, 5, 1, 10, 5, 2, 3, 3, 0, 3, 1, 2, 8, 7, 4, 2, 0, 8, 7, 6, 6, 6, + 5, 7, 5, 5, 3, 0, 4, 10, 1, 7, 8, 9, 6, 7, 0, 1, 9, 3, 1, 6, 8, 4, 9, 0, 3, 2, 4, 0, 2, + 7, 2, 2, 8, 0, 4, 1, 3, 2, 6, 8, 5, 5, 2, 3, 9, 0, 1, 7, 6, 9, 1, 10, 4, 10, 5, 10, 0, 9, + 5, 1, 6, 2, 9, 9, 8, 8, 10, 8, 1, 6, 5, 8, 8, 6, 4, 8, 10, 3, 0, 6, 2, 8, 4, 2}; + std::vector a_shape = {25, 12}; + std::vector b_shape = {12, 36}; + std::vector c_shape = {25, 36}; + int total_size = MMTestInit(&inputs_, &outputs_, a, b, a_shape, b_shape, c_shape); + auto ctx = new lite::Context; + ctx->thread_num_ = 2; + auto mm = new kernel::MatmulCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); + mm->Init(); + mm->Run(); + float correct[] = { + 263, 386, 184, 309, 338, 244, 359, 294, 252, 254, 273, 353, 320, 183, 412, 273, 271, 307, 329, 314, 391, 261, 400, + 280, 416, 399, 355, 427, 373, 302, 288, 349, 336, 241, 349, 393, 226, 285, 134, 209, 264, 163, 281, 212, 219, 171, + 221, 228, 227, 131, 289, 196, 204, 270, 238, 205, 303, 196, 280, 156, 311, 284, 282, 335, 243, 245, 181, 188, 280, + 142, 229, 256, 270, 310, 184, 377, 323, 187, 345, 295, 255, 262, 259, 332, 310, 222, 357, 275, 253, 301, 296, 254, + 316, 221, 323, 322, 370, 353, 281, 386, 363, 240, 245, 301, 270, 263, 275, 292, 278, 388, 199, 324, 252, 336, 385, + 300, 257, 274, 215, 243, 272, 230, 485, 335, 343, 366, 293, 272, 337, 313, 310, 305, 385, 421, 377, 398, 343, 262, + 249, 309, 258, 280, 286, 411, 268, 337, 127, 307, 244, 185, 368, 263, 178, 205, 223, 281, 288, 154, 339, 255, 295, + 250, 241, 236, 289, 240, 296, 261, 361, 333, 282, 399, 315, 202, 203, 272, 231, 229, 300, 273, 199, 253, 246, 315, + 307, 213, 257, 202, 243, 230, 163, 288, 220, 212, 361, 314, 219, 296, 300, 217, 274, 196, 285, 264, 351, 339, 312, + 289, 338, 282, 256, 274, 214, 243, 228, 302, 276, 394, 110, 224, 274, 163, 395, 296, 231, 223, 289, 311, 331, 177, + 405, 236, 294, 293, 264, 213, 314, 258, 330, 270, 403, 381, 305, 450, 382, 250, 248, 287, 278, 211, 324, 374, 306, + 350, 246, 298, 309, 305, 315, 289, 292, 256, 264, 341, 295, 218, 427, 382, 272, 359, 335, 286, 333, 263, 327, 275, + 448, 423, 380, 369, 397, 330, 260, 329, 285, 284, 333, 397, 259, 258, 146, 261, 281, 156, 248, 234, 236, 219, 220, + 207, 233, 173, 326, 316, 223, 301, 237, 145, 202, 181, 209, 236, 357, 279, 265, 332, 352, 230, 165, 219, 154, 233, + 189, 237, 246, 316, 147, 197, 247, 221, 212, 256, 201, 208, 239, 220, 231, 153, 322, 263, 237, 278, 254, 178, 215, + 164, 217, 211, 326, 295, 284, 306, 354, 247, 178, 244, 216, 199, 229, 308, 298, 409, 306, 359, 359, 273, 388, 291, + 301, 281, 239, 395, 323, 290, 505, 398, 370, 381, 365, 235, 344, 268, 340, 351, 473, 481, 445, 415, 481, 373, 354, + 365, 284, 309, 338, 469, 285, 336, 166, 244, 245, 247, 305, 304, 273, 233, 281, 260, 276, 218, 364, 241, 255, 330, + 257, 213, 296, 221, 252, 251, 325, 355, 301, 341, 319, 246, 206, 243, 295, 210, 249, 357, 328, 481, 196, 345, 276, + 338, 493, 349, 236, 299, 265, 388, 383, 224, 573, 425, 411, 354, 353, 340, 363, 385, 414, 387, 541, 528, 412, 515, + 486, 298, 320, 438, 254, 361, 454, 494, 120, 156, 151, 140, 176, 99, 231, 113, 197, 132, 113, 190, 134, 171, 264, + 169, 137, 219, 165, 92, 172, 145, 188, 186, 225, 260, 166, 216, 225, 161, 173, 134, 147, 130, 152, 218, 226, 273, + 205, 314, 331, 157, 311, 242, 289, 228, 238, 346, 285, 223, 344, 235, 194, 282, 274, 238, 358, 207, 333, 270, 345, + 345, 302, 339, 309, 273, 284, 291, 297, 219, 261, 338, 319, 396, 200, 356, 349, 311, 377, 330, 280, 280, 308, 351, + 311, 204, 421, 319, 294, 348, 328, 346, 387, 261, 403, 335, 434, 428, 333, 467, 422, 270, 254, 370, 345, 285, 381, + 378, 200, 347, 110, 195, 189, 184, 252, 242, 134, 191, 179, 205, 256, 140, 349, 219, 287, 216, 225, 155, 223, 203, + 203, 196, 295, 281, 321, 291, 292, 235, 219, 255, 177, 186, 213, 349, 286, 389, 180, 262, 306, 275, 269, 284, 257, + 239, 256, 262, 270, 189, 410, 306, 302, 297, 244, 226, 335, 213, 276, 257, 371, 351, 398, 376, 378, 289, 265, 355, + 258, 252, 286, 446, 274, 419, 214, 263, 277, 296, 317, 276, 202, 240, 214, 287, 292, 174, 454, 366, 352, 328, 342, + 247, 300, 273, 300, 232, 440, 401, 436, 374, 394, 351, 269, 317, 247, 255, 312, 416, 384, 533, 202, 336, 369, 322, + 449, 373, 291, 282, 343, 409, 416, 198, 526, 383, 405, 363, 355, 355, 478, 348, 435, 296, 544, 490, 519, 540, 449, + 390, 345, 444, 378, 307, 454, 542, 356, 394, 179, 370, 364, 152, 424, 370, 316, 291, 358, 420, 419, 267, 429, 323, + 311, 348, 320, 232, 344, 260, 344, 369, 472, 424, 339, 479, 470, 297, 298, 350, 300, 302, 340, 389, 211, 314, 186, + 248, 277, 184, 294, 217, 204, 184, 203, 311, 262, 154, 324, 221, 233, 249, 283, 241, 331, 210, 318, 191, 341, 330, + 331, 323, 278, 289, 255, 259, 294, 174, 280, 323, 295, 348, 303, 319, 321, 286, 365, 266, 310, 251, 240, 406, 302, + 265, 457, 396, 297, 366, 350, 270, 343, 271, 347, 314, 469, 476, 396, 375, 428, 351, 315, 341, 291, 296, 361, 428, + 383, 442, 232, 360, 387, 279, 391, 349, 348, 288, 334, 374, 360, 262, 485, 391, 362, 379, 296, 262, 406, 270, 346, + 346, 486, 451, 451, 490, 475, 339, 319, 409, 315, 324, 367, 493, 286, 348, 185, 240, 287, 214, 312, 265, 237, 218, + 261, 316, 279, 186, 377, 319, 279, 304, 281, 207, 261, 209, 287, 270, 415, 378, 312, 388, 423, 273, 230, 294, 239, + 243, 319, 346}; + CompareOutputData(reinterpret_cast(outputs_[0]->Data()), correct, total_size, 0.0001); delete mm; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; @@ -238,12 +341,11 @@ TEST_F(TestMatMulFp32, simple_transb) { int total_size = MMTestInit(&inputs_, &outputs_, a, b, a_shape, b_shape, c_shape); auto ctx = new lite::Context; ctx->thread_num_ = 2; - auto mm = new kernel::MatmulCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx); + auto mm = new kernel::MatmulCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); mm->Init(); mm->Run(); float correct[] = {0.00533547, 0.002545945, 0.062974121, -0.445441471, -0.246223617, -0.142070031}; CompareOutputData(reinterpret_cast(outputs_[0]->Data()), correct, total_size, 0.0001); - delete matmul_param; delete mm; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; @@ -288,7 +390,7 @@ TEST_F(TestMatMulFp32, batch) { int total_size = MMTestInit(&inputs_, &outputs_, a, b, a_shape, b_shape, c_shape); auto ctx = new lite::Context; ctx->thread_num_ = 1; - auto mm = new kernel::MatmulCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx); + auto mm = new kernel::MatmulCPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); mm->Init(); mm->Run(); float correct[] = {21.38518524169922, -14.514888763427734, -11.040614128112793, 16.91403579711914, @@ -298,9 +400,7 @@ TEST_F(TestMatMulFp32, batch) { 8.869029998779297, 25.034008026123047}; float *output = reinterpret_cast(outputs_[0]->Data()); - for (int i = 0; i < 18; ++i) printf("%f ", output[i]); CompareOutputData(reinterpret_cast(outputs_[0]->Data()), correct, total_size, 0.0001); - delete matmul_param; delete mm; for (auto t : inputs_) delete t; for (auto t : outputs_) delete t; diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc index 46423d89a4..4b3538316f 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/power_fp32_tests.cc @@ -62,7 +62,8 @@ TEST_F(TestPowerFp32, Simple) { int total_size = PowerTestInit(&inputs_, &outputs_, a, b, a_shape, b_shape, c_shape); auto ctx = new lite::Context; ctx->thread_num_ = 1; - auto op = new kernel::PowerCPUKernel(reinterpret_cast(param), inputs_, outputs_, ctx); + kernel::PowerCPUKernel *op = new kernel::PowerCPUKernel(reinterpret_cast(param), inputs_, outputs_, + ctx, nullptr); op->Init(); op->Run(); float correct[] = {1, 64, 2187, 65536}; @@ -88,7 +89,8 @@ TEST_F(TestPowerFp32, Broadcast) { int total_size = PowerTestInit(&inputs_, &outputs_, a, b, a_shape, b_shape, c_shape); auto ctx = new lite::Context; ctx->thread_num_ = 2; - auto op = new kernel::PowerCPUKernel(reinterpret_cast(param), inputs_, outputs_, ctx); + kernel::PowerCPUKernel *op = new kernel::PowerCPUKernel(reinterpret_cast(param), inputs_, outputs_, + ctx, nullptr); op->Init(); op->Run(); float correct[] = {1, 4, 9, 16}; diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/reduce_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/reduce_fp32_tests.cc new file mode 100644 index 0000000000..fbb947615f --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/reduce_fp32_tests.cc @@ -0,0 +1,326 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.h" + +namespace mindspore { + +class TestReduceFp32 : public mindspore::Common { + public: + TestReduceFp32() = default; + int tid = 0; + int thread_num = 1; + float err_tol = 1e-5; +}; + +TEST_F(TestReduceFp32, Mean) { + /* 2 4 4 3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, + 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + (void)ReduceMean(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, Mean2Thread) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, + 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + thread_num = 2; + tid = 0; + (void)ReduceMean(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + tid = 1; + (void)ReduceMean(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, MeanAllAxis) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[1] = {47.5}; + float out[1] = {0}; + + int input_shape[4] = {2, 4, 4, 3}; + int outer_size = 1; + int inner_size = 48; + int axis_size = 2; + float *src = in; + float dst1[48] = {0}; + MS_ASSERT(dst != nullptr); + (void)ReduceMean(outer_size, inner_size, axis_size, src, input_shape, dst1, tid, thread_num); + + input_shape[0] = 1; // 1 4 4 3 + outer_size = 1; + inner_size = 12; + axis_size = 4; + src = dst1; + float dst2[12] = {0}; + (void)ReduceMean(outer_size, inner_size, axis_size, src, input_shape, dst2, tid, thread_num); + + input_shape[1] = 1; // 1 1 4 3 + outer_size = 1; + inner_size = 3; + axis_size = 4; + src = dst2; + float dst3[3] = {0}; + (void)ReduceMean(outer_size, inner_size, axis_size, src, input_shape, dst3, tid, thread_num); + + input_shape[2] = 1; // 1 1 1 3 + outer_size = 1; + inner_size = 1; + axis_size = 3; + src = dst3; + (void)ReduceMean(outer_size, inner_size, axis_size, src, input_shape, out, tid, thread_num); + + int output_size = 1; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, Sum) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {72.0, 76.0, 80.0, 84.0, 88.0, 92.0, 96.0, 100.0, 104.0, 108.0, 112.0, 116.0, + 264.0, 268.0, 272.0, 276.0, 280.0, 284.0, 288.0, 292.0, 296.0, 300.0, 304.0, 308.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + (void)ReduceSum(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, Sum2Thread) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {72.0, 76.0, 80.0, 84.0, 88.0, 92.0, 96.0, 100.0, 104.0, 108.0, 112.0, 116.0, + 264.0, 268.0, 272.0, 276.0, 280.0, 284.0, 288.0, 292.0, 296.0, 300.0, 304.0, 308.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + thread_num = 2; + tid = 0; + (void)ReduceSum(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + tid = 1; + (void)ReduceSum(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, SumAllAxis) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[1] = {4560}; + float out[1] = {0}; + + int input_shape[4] = {2, 4, 4, 3}; + int outer_size = 1; + int inner_size = 48; + int axis_size = 2; + float *src = in; + float dst1[48] = {0}; + MS_ASSERT(dst != nullptr); + (void)ReduceSum(outer_size, inner_size, axis_size, src, input_shape, dst1, tid, thread_num); + + input_shape[0] = 1; // 1 4 4 3 + outer_size = 1; + inner_size = 12; + axis_size = 4; + src = dst1; + float dst2[12] = {0}; + (void)ReduceSum(outer_size, inner_size, axis_size, src, input_shape, dst2, tid, thread_num); + + input_shape[1] = 1; // 1 1 4 3 + outer_size = 1; + inner_size = 3; + axis_size = 4; + src = dst2; + float dst3[3] = {0}; + (void)ReduceSum(outer_size, inner_size, axis_size, src, input_shape, dst3, tid, thread_num); + + input_shape[2] = 1; // 1 1 1 3 + outer_size = 1; + inner_size = 1; + axis_size = 3; + src = dst3; + (void)ReduceSum(outer_size, inner_size, axis_size, src, input_shape, out, tid, thread_num); + + int output_size = 1; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, Max) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + (void)ReduceMax(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, Min) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + (void)ReduceMin(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, Prod) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {0.0, 12025.0, 27664.0, 47385.0, 71680.0, 101065.0, 136080.0, 177289.0, + 225280.0, 280665.0, 344080.0, 416185.0, 17418240.0, 18546744.0, 19728400.0, 20964824.0, + 22257664.0, 23608584.0, 25019280.0, 26491464.0, 28026880.0, 29627288.0, 31294480.0, 33030264.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + (void)ReduceProd(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} + +TEST_F(TestReduceFp32, SumSquare) { + /* 2*4*4*3 NHWC */ + float in[96] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, + 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, + 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0, + 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0, 75.0, 76.0, 77.0, 78.0, 79.0, + 80.0, 81.0, 82.0, 83.0, 84.0, 85.0, 86.0, 87.0, 88.0, 89.0, 90.0, 91.0, 92.0, 93.0, 94.0, 95.0}; + float correct[24] = {2016.0, 2164.0, 2320.0, 2484.0, 2656.0, 2836.0, 3024.0, 3220.0, + 3424.0, 3636.0, 3856.0, 4084.0, 18144.0, 18676.0, 19216.0, 19764.0, + 20320.0, 20884.0, 21456.0, 22036.0, 22624.0, 23220.0, 23824.0, 24436.0}; + + int input_shape[4] = {2, 4, 4, 3}; + // int output_shape[4] = {2, 1, 4, 3}; + + float out[24] = {0}; + int outer_size = 2; + int inner_size = 12; + int axis_size = 4; + (void)ReduceSumSquare(outer_size, inner_size, axis_size, in, input_shape, out, tid, thread_num); + + int output_size = 24; + CompareOutputData(out, correct, output_size, err_tol); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/resize_bilinear_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/resize_bilinear_fp32_tests.cc new file mode 100644 index 0000000000..3c5e98f398 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/resize_bilinear_fp32_tests.cc @@ -0,0 +1,337 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.h" + +namespace mindspore { + +class TestResizeBilinearFp32 : public mindspore::Common { + public: + TestResizeBilinearFp32() = default; + + public: + int tid = 0; + int thread_num = 1; + float err_tol = 1e-5; +}; + +// 1*1 -> 1*1 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest1) { + std::vector input = {1.0}; + std::vector input_shape = {1, 1, 1, 1}; + std::vector output_shape = {1, 1, 1, 1}; + std::vector expect = {1.0}; + bool align_corners = false; + + auto output_size = 1; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 1*1 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest2) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 1, 1, 1}; + std::vector expect = {0.0}; + bool align_corners = false; + + int output_size = 1; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 1*2 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest3) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 1, 2, 1}; + std::vector expect = {0.0, 1.0}; + bool align_corners = false; + + auto output_size = 2; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 2*1 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest4) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 2, 1, 1}; + std::vector expect = {0.0, 2.0}; + bool align_corners = false; + + auto output_size = 2; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 2*2 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest5) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 2, 2, 1}; + std::vector expect = {0.0, 1.0, 2.0, 3.0}; + bool align_corners = false; + + auto output_size = 4; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 1*4 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest6) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 1, 4, 1}; + std::vector expect = {0.0, 0.5, 1.0, 1.0}; + bool align_corners = false; + + auto output_size = 4; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 4*1 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest7) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 4, 1, 1}; + std::vector expect = {0.0, 1.0, 2.0, 2.0}; + bool align_corners = false; + + auto output_size = 4; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 2*4 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest8) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 2, 4, 1}; + std::vector expect = {0.0, 0.5, 1.0, 1.0, 2.0, 2.5, 3.0, 3.0}; + bool align_corners = false; + + auto output_size = 8; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 4*2 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest9) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 4, 2, 1}; + std::vector expect = {0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 2.0, 3.0}; + bool align_corners = false; + + auto output_size = 8; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 3*3 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest10) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 3, 3, 1}; + std::vector expect = {0.0, 0.6666667, 1.0, 1.3333334, 2.0, 2.3333335, 2.0, 2.6666667, 3.0}; + bool align_corners = false; + + auto output_size = 9; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 4*4 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest11) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 4, 4, 1}; + std::vector expect = {0.0, 0.5, 1.0, 1.0, 1.0, 1.5, 2.0, 2.0, 2.0, 2.5, 3.0, 3.0, 2.0, 2.5, 3.0, 3.0}; + bool align_corners = false; + + auto output_size = 16; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2*2*5 -> 2*4*4*5 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest12) { + std::vector input = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, + 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, + 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + std::vector input_shape = {2, 2, 2, 5}; + std::vector output_shape = {2, 4, 4, 5}; + std::vector expect = { + 0.0, 1.0, 2.0, 3.0, 4.0, 2.5, 3.5, 4.5, 5.5, 6.5, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 5.0, 6.0, 7.0, 8.0, 9.0, 7.5, 8.5, 9.5, 10.5, 11.5, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, + 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 12.5, 13.5, 14.5, 15.5, 16.5, 15.0, 16.0, 17.0, 18.0, + 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0, 13.0, 14.0, 12.5, 13.5, 14.5, 15.5, 16.5, 15.0, 16.0, + 17.0, 18.0, 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 22.5, 23.5, 24.5, 25.5, 26.5, + 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 27.5, 28.5, 29.5, + 30.5, 31.5, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 32.5, + 33.5, 34.5, 35.5, 36.5, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0, 30.0, 31.0, 32.0, 33.0, + 34.0, 32.5, 33.5, 34.5, 35.5, 36.5, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + bool align_corners = false; + + auto output_size = 160; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2*2*5 -> 2*4*4*5 align corners +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest13) { + std::vector input = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, + 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, + 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + std::vector input_shape = {2, 2, 2, 5}; + std::vector output_shape = {2, 4, 4, 5}; + std::vector expect = { + 0.0, 1.0, 2.0, 3.0, 4.0, 1.6666667, 2.6666667, 3.6666667, 4.666667, 5.666667, + 3.3333335, 4.3333335, 5.3333335, 6.3333335, 7.3333335, 5.0, 6.0, 7.0, 8.0, 9.0, + 3.3333335, 4.3333335, 5.3333335, 6.3333335, 7.3333335, 5.0, 6.0, 7.0, 8.0, 9.0, + 6.666667, 7.666667, 8.666667, 9.666667, 10.666667, 8.333334, 9.333334, 10.333334, 11.333334, 12.333334, + 6.666667, 7.666667, 8.666667, 9.666667, 10.666667, 8.333334, 9.333334, 10.333334, 11.333334, 12.333334, + 10.0, 11.0, 12.0, 13.0, 14.0, 11.666667, 12.666667, 13.666667, 14.666667, 15.666667, + 10.0, 11.0, 12.0, 13.0, 14.0, 11.666667, 12.666667, 13.666667, 14.666667, 15.666667, + 13.333334, 14.333334, 15.333334, 16.333334, 17.333334, 15.0, 16.0, 17.0, 18.0, 19.0, + 20.0, 21.0, 22.0, 23.0, 24.0, 21.666666, 22.666666, 23.666666, 24.666666, 25.666666, + 23.333334, 24.333334, 25.333334, 26.333334, 27.333334, 25.0, 26.0, 27.0, 28.0, 29.0, + 23.333334, 24.333334, 25.333334, 26.333334, 27.333334, 25.0, 26.0, 27.0, 28.0, 29.0, + 26.666666, 27.666666, 28.666666, 29.666666, 30.666666, 28.333334, 29.333334, 30.333334, 31.333334, 32.333332, + 26.666668, 27.666668, 28.666668, 29.666668, 30.666668, 28.333332, 29.333334, 30.333334, 31.333334, 32.333336, + 30.0, 31.0, 32.0, 33.0, 34.0, 31.666668, 32.666668, 33.666668, 34.666668, 35.666668, + 30.0, 31.0, 32.0, 33.0, 34.0, 31.666666, 32.666668, 33.666668, 34.666668, 35.666668, + 33.333332, 34.333332, 35.333332, 36.333332, 37.333332, 35.0, 36.0, 37.0, 38.0, 39.0}; + bool align_corners = true; + + auto output_size = 160; + std::vector output(output_size, 0.0); + + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2*2*5 -> 2*4*4*5 thread_num 2 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest14) { + std::vector input = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, + 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, + 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + std::vector input_shape = {2, 2, 2, 5}; + std::vector output_shape = {2, 4, 4, 5}; + std::vector expect = { + 0.0, 1.0, 2.0, 3.0, 4.0, 2.5, 3.5, 4.5, 5.5, 6.5, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 5.0, 6.0, 7.0, 8.0, 9.0, 7.5, 8.5, 9.5, 10.5, 11.5, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, + 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 12.5, 13.5, 14.5, 15.5, 16.5, 15.0, 16.0, 17.0, 18.0, + 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0, 13.0, 14.0, 12.5, 13.5, 14.5, 15.5, 16.5, 15.0, 16.0, + 17.0, 18.0, 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 22.5, 23.5, 24.5, 25.5, 26.5, + 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 27.5, 28.5, 29.5, + 30.5, 31.5, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 32.5, + 33.5, 34.5, 35.5, 36.5, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0, 30.0, 31.0, 32.0, 33.0, + 34.0, 32.5, 33.5, 34.5, 35.5, 36.5, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + bool align_corners = false; + + auto output_size = 160; + std::vector output(output_size, 0.0); + thread_num = 2; + tid = 0; + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + tid = 1; + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2*2*5 -> 2*4*4*5 thread_num 4 +TEST_F(TestResizeBilinearFp32, ResizeBilinearTest15) { + std::vector input = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, + 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, + 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + std::vector input_shape = {2, 2, 2, 5}; + std::vector output_shape = {2, 4, 4, 5}; + std::vector expect = { + 0.0, 1.0, 2.0, 3.0, 4.0, 2.5, 3.5, 4.5, 5.5, 6.5, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 5.0, 6.0, 7.0, 8.0, 9.0, 7.5, 8.5, 9.5, 10.5, 11.5, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, + 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 12.5, 13.5, 14.5, 15.5, 16.5, 15.0, 16.0, 17.0, 18.0, + 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0, 13.0, 14.0, 12.5, 13.5, 14.5, 15.5, 16.5, 15.0, 16.0, + 17.0, 18.0, 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 22.5, 23.5, 24.5, 25.5, 26.5, + 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 27.5, 28.5, 29.5, + 30.5, 31.5, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 32.5, + 33.5, 34.5, 35.5, 36.5, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0, 30.0, 31.0, 32.0, 33.0, + 34.0, 32.5, 33.5, 34.5, 35.5, 36.5, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + bool align_corners = false; + + auto output_size = 160; + std::vector output(output_size, 0.0); + thread_num = 4; + tid = 0; + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + tid = 1; + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + tid = 2; + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + tid = 3; + ResizeBilinear(input.data(), output.data(), input_shape.data(), output_shape.data(), align_corners, tid, + thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/resize_nearest_neighbor_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/resize_nearest_neighbor_fp32_tests.cc new file mode 100644 index 0000000000..ea59c40db2 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/resize_nearest_neighbor_fp32_tests.cc @@ -0,0 +1,258 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/resize.h" + +namespace mindspore { + +class TestResizeNearestNeighborFp32 : public mindspore::Common { + public: + TestResizeNearestNeighborFp32() = default; + + public: + int tid = 0; + int thread_num = 1; + float err_tol = 1e-5; +}; + +// 1*1 -> 1*1 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest1) { + std::vector input = {1.0}; + std::vector input_shape = {1, 1, 1, 1}; + std::vector output_shape = {1, 1, 1, 1}; + std::vector expect = {1.0}; + size_t output_size = 1; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 1*1 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest2) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 1, 1, 1}; + std::vector expect = {0.0}; + size_t output_size = 1; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 1*2 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest3) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 1, 2, 1}; + std::vector expect = {0.0, 1.0}; + size_t output_size = 2; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 2*1 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest4) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 2, 1, 1}; + std::vector expect = {0.0, 2.0}; + size_t output_size = 2; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 2*2 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest5) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 2, 2, 1}; + std::vector expect = {0.0, 1.0, 2.0, 3.0}; + size_t output_size = 4; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 1*4 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest6) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 1, 4, 1}; + std::vector expect = {0.0, 0.0, 1.0, 1.0}; + size_t output_size = 4; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 4*1 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest7) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 4, 1, 1}; + std::vector expect = {0.0, 0.0, 2.0, 2.0}; + size_t output_size = 4; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 2*4 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest8) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 2, 4, 1}; + std::vector expect = {0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0}; + size_t output_size = 8; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 4*2 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest9) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 4, 2, 1}; + std::vector expect = {0.0, 1.0, 0.0, 1.0, 2.0, 3.0, 2.0, 3.0}; + size_t output_size = 8; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 3*3 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest10) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 3, 3, 1}; + std::vector expect = {0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 2.0, 2.0, 3.0}; + size_t output_size = 9; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2 -> 4*4 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest11) { + std::vector input = {0.0, 1.0, 2.0, 3.0}; + std::vector input_shape = {1, 2, 2, 1}; + std::vector output_shape = {1, 4, 4, 1}; + std::vector expect = {0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 2.0, 2.0, 3.0, 3.0}; + size_t output_size = 16; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2*2*5 -> 2*4*4*5 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest12) { + std::vector input = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, + 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, + 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + std::vector input_shape = {2, 2, 2, 5}; + std::vector output_shape = {2, 4, 4, 5}; + std::vector expect = { + 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, + 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, + 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, + 17.0, 18.0, 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 20.0, 21.0, 22.0, 23.0, 24.0, + 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 20.0, 21.0, 22.0, 23.0, 24.0, 20.0, 21.0, 22.0, + 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, + 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0, 30.0, 31.0, 32.0, 33.0, + 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + size_t output_size = 160; + std::vector output(output_size, 0.0); + + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2*2*5 -> 2*4*4*5 thread_num 2 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest13) { + std::vector input = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, + 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, + 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + std::vector input_shape = {2, 2, 2, 5}; + std::vector output_shape = {2, 4, 4, 5}; + std::vector expect = { + 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, + 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, + 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, + 17.0, 18.0, 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 20.0, 21.0, 22.0, 23.0, 24.0, + 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 20.0, 21.0, 22.0, 23.0, 24.0, 20.0, 21.0, 22.0, + 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, + 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0, 30.0, 31.0, 32.0, 33.0, + 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + size_t output_size = 160; + std::vector output(output_size, 0.0); + + thread_num = 2; + tid = 0; + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + tid = 1; + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} + +// 2*2*2*5 -> 2*4*4*5 thread_num 4 +TEST_F(TestResizeNearestNeighborFp32, ResizeNearestNeighborTest14) { + std::vector input = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, + 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, + 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + std::vector input_shape = {2, 2, 2, 5}; + std::vector output_shape = {2, 4, 4, 5}; + std::vector expect = { + 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, 6.0, 7.0, + 8.0, 9.0, 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 5.0, + 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, + 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 10.0, 11.0, 12.0, 13.0, 14.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, + 17.0, 18.0, 19.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 20.0, 21.0, 22.0, 23.0, 24.0, + 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 20.0, 21.0, 22.0, 23.0, 24.0, 20.0, 21.0, 22.0, + 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 30.0, + 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0, 30.0, 31.0, 32.0, 33.0, + 34.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0, 35.0, 36.0, 37.0, 38.0, 39.0}; + size_t output_size = 160; + std::vector output(output_size, 0.0); + + thread_num = 4; + tid = 0; + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + tid = 1; + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + tid = 2; + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + tid = 3; + ResizeNearestNeighbor(input.data(), output.data(), input_shape.data(), output_shape.data(), tid, thread_num); + CompareOutputData(output.data(), expect.data(), output_size, err_tol); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_batch_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_batch_fp32_tests.cc index c6b1e5c7e3..696647687d 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_batch_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_batch_fp32_tests.cc @@ -149,7 +149,7 @@ TEST_F(SpaceToBatchTestFp32, SpaceToBatchTest3) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(¶m), &ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(¶m), &ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_depth_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_depth_fp32_tests.cc index a758336be2..ac0258b1fa 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_depth_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/space_to_depth_fp32_tests.cc @@ -80,7 +80,7 @@ TEST_F(SpaceToDepthTestFp32, SpaceToDepthTest2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), &ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), &ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/topk_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/topk_fp32_tests.cc index b45037d36c..fd005cff64 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/topk_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/topk_fp32_tests.cc @@ -45,7 +45,7 @@ TEST_F(TestTopKFp32, TopK) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); - auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), nullptr, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), nullptr, desc, nullptr); ASSERT_NE(kernel, nullptr); auto ret = kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/activation_grad_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/activation_grad_fp32_tests.cc similarity index 99% rename from mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/activation_grad_fp32_tests.cc rename to mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/activation_grad_fp32_tests.cc index 1badd29a26..e1fd748bb3 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/activation_grad_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/activation_grad_fp32_tests.cc @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include #include #include @@ -25,7 +24,7 @@ #include "mindspore/lite/src/kernel_registry.h" #include "mindspore/lite/src/ir/tensor.h" #include "mindspore/lite/src/lite_kernel.h" -#include "mindspore/lite/src/runtime/kernel/arm/fp32/activation_grad.h" +#include "mindspore/lite/src/runtime/kernel/arm/fp32_grad/activation_grad.h" namespace mindspore { class TestActGradFp32 : public mindspore::Common { diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/arithmetic_grad_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/arithmetic_grad_fp32_tests.cc similarity index 97% rename from mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/arithmetic_grad_fp32_tests.cc rename to mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/arithmetic_grad_fp32_tests.cc index fe4a3b7cf2..7ca2daf26a 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/arithmetic_grad_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/arithmetic_grad_fp32_tests.cc @@ -21,7 +21,7 @@ #include "src/common/file_utils.h" #include "src/common/file_utils_ext.h" #include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/reduce.h" -#include "mindspore/lite/src/runtime/kernel/arm/fp32/arithmetic_grad.h" +#include "mindspore/lite/src/runtime/kernel/arm/fp32_grad/arithmetic_grad.h" #include "mindspore/lite/src/kernel_registry.h" namespace mindspore { @@ -91,7 +91,7 @@ TEST_F(TestArithmeticGradFp32, TestAddGradFp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_AddGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[1]->Data()); @@ -122,7 +122,7 @@ TEST_F(TestArithmeticGradFp32, TestAddGrad2Fp32) { std::vector outputs = {all_tensors[4], all_tensors[3]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_AddGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[0]->Data()); @@ -153,7 +153,7 @@ TEST_F(TestArithmeticGradFp32, TestAddGrad3Fp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_AddGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[0]->Data()); @@ -184,7 +184,7 @@ TEST_F(TestArithmeticGradFp32, TestSubGradFp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_SubGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[1]->Data()); @@ -215,7 +215,7 @@ TEST_F(TestArithmeticGradFp32, TestSubGrad2Fp32) { std::vector outputs = {all_tensors[4], all_tensors[3]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_SubGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[0]->Data()); @@ -246,7 +246,7 @@ TEST_F(TestArithmeticGradFp32, TestMulGradFp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_MulGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); int loop_count = 1000; auto time_start = mindspore::lite::GetTimeUs(); @@ -287,7 +287,7 @@ TEST_F(TestArithmeticGradFp32, TestMulGrad2Fp32) { std::vector outputs = {all_tensors[4], all_tensors[3]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_MulGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[0]->Data()); @@ -318,7 +318,7 @@ TEST_F(TestArithmeticGradFp32, TestMulGrad3Fp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_MulGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[1]->Data()); @@ -349,7 +349,7 @@ TEST_F(TestArithmeticGradFp32, TestMulGrad4Fp32) { std::vector outputs = {all_tensors[4], all_tensors[3]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_MulGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[0]->Data()); @@ -380,7 +380,7 @@ TEST_F(TestArithmeticGradFp32, TestDivGradFp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_DivGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[1]->Data()); @@ -411,7 +411,7 @@ TEST_F(TestArithmeticGradFp32, TestDivGrad2Fp32) { std::vector outputs = {all_tensors[4], all_tensors[3]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_DivGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[0]->Data()); @@ -442,7 +442,7 @@ TEST_F(TestArithmeticGradFp32, TestDivGrad3Fp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_DivGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[1]->Data()); @@ -473,7 +473,7 @@ TEST_F(TestArithmeticGradFp32, Test3DDivGrad2Fp32) { std::vector outputs = {all_tensors[3], all_tensors[4]}; kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_DivGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(param), NULL, desc, nullptr); kernel_obj->Run(); float *output_ptr = reinterpret_cast(outputs[1]->Data()); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/bias_grad_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/bias_grad_fp32_tests.cc similarity index 95% rename from mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/bias_grad_fp32_tests.cc rename to mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/bias_grad_fp32_tests.cc index 7c26e95022..8146950ab6 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/bias_grad_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/bias_grad_fp32_tests.cc @@ -18,7 +18,7 @@ #include "utils/log_adapter.h" #include "common/common_test.h" #include "src/common/file_utils.h" -#include "mindspore/lite/src/runtime/kernel/arm/fp32/bias_grad.h" +#include "mindspore/lite/src/runtime/kernel/arm/fp32_grad/bias_grad.h" #include "mindspore/lite/src/kernel_registry.h" namespace mindspore { @@ -50,7 +50,7 @@ TEST_F(TestBiasGradFp32, BiasGradFp32) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_BiasGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(bias_param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(bias_param), NULL, desc, nullptr); kernel_obj->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/convolution_grad_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/convolution_grad_fp32_tests.cc similarity index 97% rename from mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/convolution_grad_fp32_tests.cc rename to mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/convolution_grad_fp32_tests.cc index 7847e013a3..1d114587ec 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/convolution_grad_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/convolution_grad_fp32_tests.cc @@ -21,8 +21,8 @@ #include "common/common_test.h" #include "src/common/file_utils.h" #include "src/common/file_utils_ext.h" -#include "mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_filter.h" -#include "mindspore/lite/src/runtime/kernel/arm/fp32/convolution_grad_input.h" +#include "mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_filter.h" +#include "mindspore/lite/src/runtime/kernel/arm/fp32_grad/convolution_grad_input.h" #include "mindspore/lite/src/runtime/kernel/arm/nnacl/conv_parameter.h" #include "mindspore/lite/src/kernel_registry.h" @@ -109,7 +109,7 @@ TEST_F(TestConvolutionGradFp32, ConvFp32FilterGrad) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_Conv2DGradFilter}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc, nullptr); // warm up loop for (int i = 0; i < 3; i++) { @@ -174,7 +174,7 @@ TEST_F(TestConvolutionGradFp32, ConvFp32InputGrad) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_Conv2DGradInput}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc, nullptr); // warm up loop for (int i = 0; i < 3; i++) { @@ -234,7 +234,7 @@ TEST_F(TestConvolutionGradFp32, ConvFp32GroupFilterGrad) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_Conv2DGradFilter}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc, nullptr); // warm up loop for (int i = 0; i < 3; i++) { @@ -298,7 +298,7 @@ TEST_F(TestConvolutionGradFp32, ConvFp32GroupInputGrad) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_Conv2DGradInput}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc, nullptr); // warm up loop for (int i = 0; i < 3; i++) { @@ -359,7 +359,7 @@ TEST_F(TestConvolutionGradFp32, ConvFp32GroupDilationFilterGrad) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_Conv2DGradFilter}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc, nullptr); // warm up loop for (int i = 0; i < 3; i++) { @@ -422,7 +422,7 @@ TEST_F(TestConvolutionGradFp32, ConvFp32GroupDilationInputGrad) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_Conv2DGradInput}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(conv_param), NULL, desc, nullptr); // warm up loop for (int i = 0; i < 3; i++) { diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/pooling_grad_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/pooling_grad_fp32_tests.cc similarity index 98% rename from mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/pooling_grad_fp32_tests.cc rename to mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/pooling_grad_fp32_tests.cc index fb9e262e28..5194cab5ac 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32/pooling_grad_fp32_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/pooling_grad_fp32_tests.cc @@ -22,8 +22,8 @@ #include "mindspore/lite/src/kernel_registry.h" #include "src/common/utils.h" #include "src/common/file_utils.h" -#include "src/runtime/kernel/arm/fp32/pooling_grad.h" -#include "src/runtime/kernel/arm/nnacl/fp32/pooling_grad.h" +#include "src/runtime/kernel/arm/fp32_grad/pooling_grad.h" +#include "src/runtime/kernel/arm/nnacl/fp32_grad/pooling_grad.h" namespace mindspore { class TestPoolingGradFp32 : public mindspore::Common { @@ -138,7 +138,7 @@ TEST_F(TestPoolingGradFp32, AvgPoolingKernelGradFp32) { kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_PoolingGrad}; auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); - auto kernel_obj = creator(inputs, outputs, reinterpret_cast(pooling_param), NULL, desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(pooling_param), NULL, desc, nullptr); kernel_obj->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/softmax_crossentropy_fp32_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/softmax_crossentropy_fp32_tests.cc new file mode 100644 index 0000000000..c35bac8fa4 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/fp32_grad/softmax_crossentropy_fp32_tests.cc @@ -0,0 +1,92 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "src/common/file_utils.h" +#include "src/runtime/kernel/arm/fp32_grad/sparse_softmax_cross_entropy_with_logits.h" +#include "src/kernel_registry.h" + +namespace mindspore { + +class TestSoftmaxCrossEntropyFp32 : public mindspore::Common { + public: + TestSoftmaxCrossEntropyFp32() {} +}; + +TEST_F(TestSoftmaxCrossEntropyFp32, SoftmaxCrossEntropyFp32) { + // prepare stage + SoftmaxCrossEntropyParameter *sce_param = new SoftmaxCrossEntropyParameter(); + size_t input_size; + + std::string input_path = "./test_data/operators/sce_fp32_1_y_6_4.bin"; + auto input_data = reinterpret_cast(mindspore::lite::ReadFile(input_path.c_str(), &input_size)); + std::vector dim_y({6, 4}); + lite::tensor::Tensor y_tensor(TypeId::kNumberTypeFloat32, dim_y); + y_tensor.SetData(input_data); + + std::string label_path = "./test_data/operators/sce_fp32_1_l_6.bin"; + auto ll_labels = reinterpret_cast(mindspore::lite::ReadFile(label_path.c_str(), &input_size)); + auto labels = new int[6]; + for (int i = 0; i < 6; i++) labels[i] = static_cast(ll_labels[i]); + + std::vector dim_l({6}); + lite::tensor::Tensor l_tensor(TypeId::kNumberTypeInt32, dim_l); + l_tensor.SetData(labels); + + std::vector inputs = {&y_tensor, &l_tensor}; + + auto loss = new float[1]; + std::vector dim_dw({1}); + lite::tensor::Tensor loss_tensor(TypeId::kNumberTypeFloat32, dim_dw); + loss_tensor.SetData(loss); + auto grad = new float[24]; + lite::tensor::Tensor grad_tensor(TypeId::kNumberTypeFloat32, dim_y); + grad_tensor.SetData(grad); + std::vector outputs = {&grad_tensor, &loss_tensor}; + + kernel::KernelKey desc = {kernel::kCPU, TypeId::kNumberTypeFloat32, schema::PrimitiveType_SoftmaxCrossEntropy}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + auto kernel_obj = creator(inputs, outputs, reinterpret_cast(sce_param), NULL, desc, nullptr); + kernel_obj->Run(); + + printf("==================total loss=================\n"); + std::cout << loss[0] << " ," << std::endl; + + printf("==================Testing Grad===============\n"); + + std::string output_path = "./test_data/operators/sce_fp32_1_loss_1.bin"; + lite::CompareOutput(loss, output_path); + + ((mindspore::kernel::SparseSoftmaxCrossEntropyWithLogitsCPUKernel *)kernel_obj)->train(); + kernel_obj->Run(); + + printf("==================output data=================\n"); + for (int i = 0; i < 12; i++) { + std::cout << grad[i] << " ,"; + } + std::cout << std::endl; + std::string grad_path = "./test_data/operators/sce_fp32_1_dy_6_4.bin"; + lite::CompareOutput(grad, grad_path); + + delete sce_param; + l_tensor.SetData(NULL); + y_tensor.SetData(NULL); + MS_LOG(INFO) << "SoftmaxCrossEntropyFp32 passed"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/add_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/add_int8_tests.cc index a8d738ddaa..40f108d4a3 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/add_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/add_int8_tests.cc @@ -56,7 +56,7 @@ TEST_F(TestQuantizedAdd, Add) { ASSERT_NE(creator, nullptr); auto ctx = std::make_shared(); - auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); ASSERT_NE(kernel, nullptr); auto ret = kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/arithmetic_self_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/arithmetic_self_int8_tests.cc index 3ab4e5f26b..ecc5bcb3f2 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/arithmetic_self_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/arithmetic_self_int8_tests.cc @@ -70,7 +70,7 @@ TEST_F(TestArithmeticSelfInt8, floor_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -129,7 +129,7 @@ TEST_F(TestArithmeticSelfInt8, floor_quant1_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -188,7 +188,7 @@ TEST_F(TestArithmeticSelfInt8, round_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -247,7 +247,7 @@ TEST_F(TestArithmeticSelfInt8, round_quant1_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -306,7 +306,7 @@ TEST_F(TestArithmeticSelfInt8, ceil_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -365,7 +365,7 @@ TEST_F(TestArithmeticSelfInt8, ceil_quant1_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -424,7 +424,7 @@ TEST_F(TestArithmeticSelfInt8, abs_quant0_thread0) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -483,7 +483,7 @@ TEST_F(TestArithmeticSelfInt8, abs_quant1_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -542,7 +542,7 @@ TEST_F(TestArithmeticSelfInt8, sin_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -601,7 +601,7 @@ TEST_F(TestArithmeticSelfInt8, cos_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -660,7 +660,7 @@ TEST_F(TestArithmeticSelfInt8, log_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -719,7 +719,7 @@ TEST_F(TestArithmeticSelfInt8, sqrt_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -778,7 +778,7 @@ TEST_F(TestArithmeticSelfInt8, rsqrt_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -837,7 +837,7 @@ TEST_F(TestArithmeticSelfInt8, square_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -896,7 +896,7 @@ TEST_F(TestArithmeticSelfInt8, square_quant1_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -955,7 +955,7 @@ TEST_F(TestArithmeticSelfInt8, logical_not_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/concat_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/concat_int8_tests.cc new file mode 100644 index 0000000000..cc7084b25b --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/concat_int8_tests.cc @@ -0,0 +1,247 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/concat_parameter.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "mindspore/lite/src/lite_kernel.h" +#include "mindspore/lite/src/ir/tensor.h" + +namespace mindspore { + +class TestConcatInt8 : public mindspore::Common { + public: + TestConcatInt8() {} +}; + +TEST_F(TestConcatInt8, Concat1_axis0) { + std::vector input1 = {1, 2, 3, 4, 5, 6}; + std::vector shape1 = {3, 2}; + std::vector input2 = {7, 8, 9, 10, 11, 12}; + std::vector shape2 = {3, 2}; + std::vector input(2, nullptr); + input[0] = input1.data(); + input[1] = input2.data(); + + int8_t output[12]; + std::vector output_shape = {6, 2}; + + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + lite::tensor::Tensor *input_tensor2 = new lite::tensor::Tensor; + input_tensor2->SetData(input2.data()); + input_tensor2->set_shape(shape2); + input_tensor2->AddQuantParam(input_quant_arg); + input_tensor2->set_data_type(tid_int8); + + std::vector inputs_tensor(2); + inputs_tensor[0] = input_tensor1; + inputs_tensor[1] = input_tensor2; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + ConcatParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Concat; + op_param.axis_ = 0; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Concat}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + PrintData("output data", output, input1.size() + input2.size()); + CompareOutputData(output, except_result.data(), input1.size() + input2.size(), 0.000001); + input_tensor1->SetData(nullptr); + input_tensor2->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete input_tensor2; + delete output0_tensor; + delete ctx; +} + +TEST_F(TestConcatInt8, Concat1_axis1_thread2) { + std::vector input1 = {10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25}; + std::vector shape1 = {2, 3, 2}; + std::vector input2 = {30, 31, 32, 33}; + std::vector shape2 = {2, 1, 2}; + std::vector input(2, nullptr); + input[0] = input1.data(); + input[1] = input2.data(); + + int8_t output[16]; + std::vector output_shape = {2, 4, 2}; + + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + lite::tensor::Tensor *input_tensor2 = new lite::tensor::Tensor; + input_tensor2->SetData(input2.data()); + input_tensor2->set_shape(shape2); + input_tensor2->AddQuantParam(input_quant_arg); + input_tensor2->set_data_type(tid_int8); + + std::vector inputs_tensor(2); + inputs_tensor[0] = input_tensor1; + inputs_tensor[1] = input_tensor2; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + ConcatParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Concat; + op_param.axis_ = 1; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Concat}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {10, 11, 12, 13, 14, 15, 30, 31, 20, 21, 22, 23, 24, 25, 32, 33}; + PrintData("output data", output, input1.size() + input2.size()); + CompareOutputData(output, except_result.data(), input1.size() + input2.size(), 0.000001); + + input_tensor1->SetData(nullptr); + input_tensor2->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete input_tensor2; + delete output0_tensor; + delete ctx; +} + +TEST_F(TestConcatInt8, Concat1_axis1_thread2_quant1) { + std::vector input1 = {10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25}; + std::vector shape1 = {2, 3, 2}; + std::vector input2 = {30, 31, 32, 33}; + std::vector shape2 = {2, 1, 2}; + std::vector input(2, nullptr); + input[0] = input1.data(); + input[1] = input2.data(); + + int8_t output[16]; + std::vector output_shape = {2, 4, 2}; + + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 2.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + lite::tensor::Tensor *input_tensor2 = new lite::tensor::Tensor; + input_tensor2->SetData(input2.data()); + input_tensor2->set_shape(shape2); + input_tensor2->AddQuantParam(input_quant_arg); + input_tensor2->set_data_type(tid_int8); + + std::vector inputs_tensor(2); + inputs_tensor[0] = input_tensor1; + inputs_tensor[1] = input_tensor2; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + ConcatParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Concat; + op_param.axis_ = 1; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Concat}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {5, 6, 6, 7, 7, 8, 15, 16, 10, 11, 11, 12, 12, 13, 16, 17}; + PrintData("output data", output, input1.size() + input2.size()); + CompareOutputData(output, except_result.data(), input1.size() + input2.size(), 0.000001); + + input_tensor1->SetData(nullptr); + input_tensor2->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete input_tensor2; + delete output0_tensor; + delete ctx; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/crop_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/crop_int8_tests.cc index d94ae6eefe..6ee9e96976 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/crop_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/crop_int8_tests.cc @@ -74,7 +74,7 @@ TEST_F(TestCropInt8, crop_1d_axis0_offset0_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -137,7 +137,7 @@ TEST_F(TestCropInt8, crop_2d_axis1_offset0_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -200,7 +200,7 @@ TEST_F(TestCropInt8, crop_3d_axis1_offset0_quant0_thread0) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -264,7 +264,7 @@ TEST_F(TestCropInt8, crop_3d_axis1_offset0_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -327,7 +327,7 @@ TEST_F(TestCropInt8, crop_4d_axis0_offset0_quant0_thread0) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -390,7 +390,7 @@ TEST_F(TestCropInt8, crop_4d_axis1_offset0_quant0_thread0) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -456,7 +456,7 @@ TEST_F(TestCropInt8, crop_4d_axis1_offset1_quant0_thread0) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -522,7 +522,7 @@ TEST_F(TestCropInt8, crop_4d_axis1_offset1_quant1_thread0) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -587,7 +587,7 @@ TEST_F(TestCropInt8, crop_4d_axis0_offset0_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); @@ -652,7 +652,7 @@ TEST_F(TestCropInt8, crop_4d_axis0_offset0_quant0_thread3) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor->shape(); ASSERT_EQ(output_tensor_shape, output_shape); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc index 632abad686..227a1cd938 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/deconv_int8_tests.cc @@ -160,7 +160,7 @@ TEST_F(TestDeconvInt8, MatMulTest1) { RowMajor2Col8MajorInt8(a_row_major_10_12, a_col8_major, 10, 12); RowMajor2Col8MajorInt8(b_col_major_12_18, b_row8_major, 18, 12); MatMulInt8(a_col8_major, b_row8_major, c_row8x8_major, 16, 24, 12, zp_a, zp_b); - Row8x8Major2RowMajor(reinterpret_cast(c_row8x8_major), reinterpret_cast(out_row_major), 10, 18); + Row8x8Major2RowMajor(reinterpret_cast(c_row8x8_major), reinterpret_cast(out_row_major), 10, 18, 18); CompareOutputData(out_row_major, co_row_major_10_18, 180, 1); } @@ -250,8 +250,8 @@ TEST_F(TestDeconvInt8, DeConvInt8Test1) { ctx->thread_num_ = 2; int8_t *correct; int total_size = DeConvInt8TestInit1(&inputs_, &outputs_, deconv_param, &correct); - mindspore::kernel::DeConvInt8CPUKernel *deconv = - new mindspore::kernel::DeConvInt8CPUKernel(reinterpret_cast(deconv_param), inputs_, outputs_, ctx); + mindspore::kernel::DeConvInt8CPUKernel *deconv = new mindspore::kernel::DeConvInt8CPUKernel( + reinterpret_cast(deconv_param), inputs_, outputs_, ctx, nullptr); deconv->Init(); deconv->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/fullconnection_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/fullconnection_int8_tests.cc index d5ca51733f..51a3796271 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/fullconnection_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/fullconnection_int8_tests.cc @@ -107,8 +107,8 @@ TEST_F(TestFcInt8, fcint8) { int total_size = FcInt8TestInit(&inputs_, &outputs_, matmul_param, &correct, &output_scale, &output_zp); lite::Context *ctx = new lite::Context; ctx->thread_num_ = 2; - kernel::FullconnectionInt8CPUKernel *fc = - new kernel::FullconnectionInt8CPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx); + kernel::FullconnectionInt8CPUKernel *fc = new kernel::FullconnectionInt8CPUKernel( + reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); fc->Init(); fc->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/hswish_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/hswish_int8_tests.cc index ef2f1b0e77..e9caaec997 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/hswish_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/hswish_int8_tests.cc @@ -56,7 +56,7 @@ TEST_F(TestHSwishInt8, HSwish) { ASSERT_NE(creator, nullptr); auto ctx = std::make_shared(); - auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); ASSERT_NE(kernel, nullptr); auto ret = kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc index 36d7ecd23e..fdce152ef2 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/matmul_int8_tests.cc @@ -108,7 +108,7 @@ TEST_F(TestMatmulInt8, mmint8) { auto ctx = new lite::Context; ctx->thread_num_ = 2; kernel::MatmulInt8CPUKernel *mm = - new kernel::MatmulInt8CPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx); + new kernel::MatmulInt8CPUKernel(reinterpret_cast(matmul_param), inputs_, outputs_, ctx, nullptr); mm->Init(); mm->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/mul_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/mul_int8_tests.cc new file mode 100644 index 0000000000..7185c13bfa --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/mul_int8_tests.cc @@ -0,0 +1,311 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/mul_parameter.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "mindspore/lite/src/lite_kernel.h" +#include "mindspore/lite/src/ir/tensor.h" + +namespace mindspore { + +class TestMulInt8 : public mindspore::Common { + public: + TestMulInt8() {} +}; + +TEST_F(TestMulInt8, Mul_quant0) { + std::vector input1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + std::vector shape1 = {2, 3, 2}; + std::vector input2 = {1, 2, 3, 4}; + std::vector shape2 = {2, 1, 2}; + std::vector input(2, nullptr); + input[0] = input1.data(); + input[1] = input2.data(); + + int8_t output[12]; + std::vector output_shape = {2, 3, 2}; + + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + lite::tensor::Tensor *input_tensor2 = new lite::tensor::Tensor; + input_tensor2->SetData(input2.data()); + input_tensor2->set_shape(shape2); + input_tensor2->AddQuantParam(input_quant_arg); + input_tensor2->set_data_type(tid_int8); + + std::vector inputs_tensor(2); + inputs_tensor[0] = input_tensor1; + inputs_tensor[1] = input_tensor2; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + MulParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Mul; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Mul}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, 4, 3, 8, 5, 12, 21, 32, 27, 40, 33, 48}; + PrintData("output data", output, input1.size()); + CompareOutputData(output, except_result.data(), input1.size(), 0.000001); + input_tensor1->SetData(nullptr); + input_tensor2->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete input_tensor2; + delete output0_tensor; + delete ctx; +} + +TEST_F(TestMulInt8, Mul_quant0_thread0) { + std::vector input1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; + std::vector shape1 = {2, 3, 3}; + std::vector input2 = {1, 1, 1, 1, 1, 1}; + std::vector shape2 = {2, 1, 3}; + std::vector input(2, nullptr); + input[0] = input1.data(); + input[1] = input2.data(); + + int8_t output[18]; + std::vector output_shape = {2, 3, 3}; + + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + lite::tensor::Tensor *input_tensor2 = new lite::tensor::Tensor; + input_tensor2->SetData(input2.data()); + input_tensor2->set_shape(shape2); + input_tensor2->AddQuantParam(input_quant_arg); + input_tensor2->set_data_type(tid_int8); + + std::vector inputs_tensor(2); + inputs_tensor[0] = input_tensor1; + inputs_tensor[1] = input_tensor2; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + MulParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Mul; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Mul}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; + PrintData("output data", output, input1.size()); + CompareOutputData(output, except_result.data(), input1.size(), 0.000001); + input_tensor1->SetData(nullptr); + input_tensor2->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete input_tensor2; + delete output0_tensor; + delete ctx; +} + +TEST_F(TestMulInt8, Mul_quant1) { + std::vector input1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + std::vector shape1 = {2, 3, 2}; + std::vector input2 = {1, 2, 3, 4}; + std::vector shape2 = {2, 1, 2}; + std::vector input(2, nullptr); + input[0] = input1.data(); + input[1] = input2.data(); + + int8_t output[12]; + std::vector output_shape = {2, 3, 2}; + + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 2.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + lite::tensor::Tensor *input_tensor2 = new lite::tensor::Tensor; + input_tensor2->SetData(input2.data()); + input_tensor2->set_shape(shape2); + input_tensor2->AddQuantParam(input_quant_arg); + input_tensor2->set_data_type(tid_int8); + + std::vector inputs_tensor(2); + inputs_tensor[0] = input_tensor1; + inputs_tensor[1] = input_tensor2; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + MulParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Mul; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Mul}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, 2, 2, 4, 3, 6, 11, 16, 14, 20, 17, 24}; + PrintData("output data", output, input1.size()); + CompareOutputData(output, except_result.data(), input1.size(), 0.000001); + input_tensor1->SetData(nullptr); + input_tensor2->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete input_tensor2; + delete output0_tensor; + delete ctx; +} + +TEST_F(TestMulInt8, Mul_quant1_thread1) { + std::vector input1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + std::vector shape1 = {2, 3, 2}; + std::vector input2 = {1, 2, 3, 4}; + std::vector shape2 = {2, 1, 2}; + std::vector input(2, nullptr); + input[0] = input1.data(); + input[1] = input2.data(); + + int8_t output[12]; + std::vector output_shape = {2, 3, 2}; + + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 2.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + lite::tensor::Tensor *input_tensor2 = new lite::tensor::Tensor; + input_tensor2->SetData(input2.data()); + input_tensor2->set_shape(shape2); + input_tensor2->AddQuantParam(input_quant_arg); + input_tensor2->set_data_type(tid_int8); + + std::vector inputs_tensor(2); + inputs_tensor[0] = input_tensor1; + inputs_tensor[1] = input_tensor2; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + MulParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Mul; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Mul}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, 2, 2, 4, 3, 6, 11, 16, 14, 20, 17, 24}; + PrintData("output data", output, input1.size()); + CompareOutputData(output, except_result.data(), input1.size(), 0.000001); + input_tensor1->SetData(nullptr); + input_tensor2->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete input_tensor2; + delete output0_tensor; + delete ctx; +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/pad_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/pad_int8_tests.cc index 4230ec4ae4..3bd462cc8a 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/pad_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/pad_int8_tests.cc @@ -68,7 +68,7 @@ TEST_F(TestPadInt8, PadInt8Test1) { int8_t *correct; int total_size = PadInt8TestInit1(&inputs_, &outputs_, pad_param, &correct); kernel::PadInt8CPUKernel *pad = - new kernel::PadInt8CPUKernel(reinterpret_cast(pad_param), inputs_, outputs_, ctx); + new kernel::PadInt8CPUKernel(reinterpret_cast(pad_param), inputs_, outputs_, ctx, nullptr); pad->Init(); pad->Run(); @@ -120,7 +120,7 @@ TEST_F(TestPadInt8, PadInt8Test2) { int8_t *correct; int total_size = PadInt8TestInit2(&inputs_, &outputs_, pad_param, &correct); kernel::PadInt8CPUKernel *pad = - new kernel::PadInt8CPUKernel(reinterpret_cast(pad_param), inputs_, outputs_, ctx); + new kernel::PadInt8CPUKernel(reinterpret_cast(pad_param), inputs_, outputs_, ctx, nullptr); pad->Init(); pad->Run(); @@ -186,7 +186,7 @@ TEST_F(TestPadInt8, PadInt8TestInit4) { int8_t *correct; int total_size = PadInt8TestInit2(&inputs_, &outputs_, pad_param, &correct); kernel::PadInt8CPUKernel *pad = - new kernel::PadInt8CPUKernel(reinterpret_cast(pad_param), inputs_, outputs_, ctx); + new kernel::PadInt8CPUKernel(reinterpret_cast(pad_param), inputs_, outputs_, ctx, nullptr); pad->Init(); pad->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/prelu_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/prelu_int8_tests.cc new file mode 100644 index 0000000000..297316a7b5 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/prelu_int8_tests.cc @@ -0,0 +1,95 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/prelu_parameter.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "mindspore/lite/src/lite_kernel.h" +#include "mindspore/lite/src/ir/tensor.h" + +namespace mindspore { + +class TestPreluInt8 : public mindspore::Common { + public: + TestPreluInt8() {} +}; + +TEST_F(TestPreluInt8, prelu_1) { + std::vector input1 = {1, -2, 3, 4, 5, 6, 7, -8}; + std::vector shape1 = {8}; + std::vector input(1, nullptr); + input[0] = input1.data(); + + const int output_size = 8; + int8_t output[8]; + std::vector output_shape = {8}; + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + std::vector inputs_tensor(1); + inputs_tensor[0] = input_tensor1; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + PreluParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Prelu; + + op_param.alpha_ = 0.25; + + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + op_param.axis_ = 0.25; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Prelu}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, -1, 3, 4, 5, 6, 7, -2}; + PrintData("output data", output, output_size); + PrintData("output data shape", output_tensor_shape.data(), output_tensor_shape.size()); + CompareOutputData(output, except_result.data(), output_size, 0.000001); + + input_tensor1->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete ctx; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/quant_dtype_cast_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/quant_dtype_cast_tests.cc index 89b2385b3f..665d18a217 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/quant_dtype_cast_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/quant_dtype_cast_tests.cc @@ -67,7 +67,7 @@ TEST_F(QuantDTypeCastTestFp32, QuantDTypeCastTest1) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(¶m), &ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(¶m), &ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); kernel->Run(); @@ -113,7 +113,7 @@ TEST_F(QuantDTypeCastTestFp32, QuantDTypeCastTest2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(¶m), &ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(¶m), &ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/relux_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/relux_int8_tests.cc new file mode 100644 index 0000000000..70de924b24 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/relux_int8_tests.cc @@ -0,0 +1,115 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/int8/relux_int8.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "mindspore/lite/include/context.h" + +namespace mindspore { +class TestReluXInt8 : public mindspore::Common { + public: + TestReluXInt8() {} +}; + +TEST_F(TestReluXInt8, Relu) { + lite::tensor::Tensor in_tensor(kNumberTypeInt8, {2, 2}); + lite::tensor::Tensor out_tensor(kNumberTypeInt8, {2, 2}); + + int8_t input_data[] = {-102, 25, -51, 89}; // -0.8 0.2 -0.4 0.7 + int8_t output_data[4] = {0}; + in_tensor.SetData(input_data); + out_tensor.SetData(output_data); + + const lite::tensor::QuantArg quant_in = {0.00784314f, 0}; // -1.0--1.0 -> + const lite::tensor::QuantArg quant_out = {0.00784314f, 0}; + in_tensor.AddQuantParam(quant_in); + out_tensor.AddQuantParam(quant_out); + + std::vector inputs = {&in_tensor}; + std::vector outputs = {&out_tensor}; + + ActivationParameter parameter = {0}; + parameter.op_parameter_.type_ = schema::PrimitiveType_Activation; + parameter.type_ = schema::ActivationType_RELU; + + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Activation}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + ASSERT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + int8_t expect0[4] = {0, 26, 0, 90}; // + for (int i = 0; i < 4; ++i) { + EXPECT_EQ(output_data[i], expect0[i]); + } + + in_tensor.SetData(nullptr); + out_tensor.SetData(nullptr); +} + +TEST_F(TestReluXInt8, Relu6) { + lite::tensor::Tensor in_tensor(kNumberTypeInt8, {2, 4}); + lite::tensor::Tensor out_tensor(kNumberTypeInt8, {2, 4}); + + // -2.5f, -1.5f, 1.25f, 3.0f, 4.5f, 6.0f, 6.5f, 9.0f + int8_t input_data[] = {-118, -98, -44, -10, 19, 49, 59, 108}; + int8_t output_data[8] = {0}; + in_tensor.SetData(input_data); + out_tensor.SetData(output_data); + + const lite::tensor::QuantArg quant_in = {0.0509804f, -69}; // -3.0 -- 10.0 + const lite::tensor::QuantArg quant_out = {0.0392157f, -128}; // 0.0 -- 10.0 + in_tensor.AddQuantParam(quant_in); + out_tensor.AddQuantParam(quant_out); + + std::vector inputs = {&in_tensor}; + std::vector outputs = {&out_tensor}; + + ActivationParameter parameter = {0}; + parameter.op_parameter_.type_ = schema::PrimitiveType_Activation; + parameter.type_ = schema::ActivationType_RELU6; + + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Activation}; + + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + + auto ctx = std::make_shared(); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); + ASSERT_NE(kernel, nullptr); + + auto ret = kernel->Run(); + EXPECT_EQ(0, ret); + + // 0.0f, 0.0f, 1.25f, 3.0f, 4.5f, 6.0f, 6.0f, 6.0f + int8_t expect[8] = {-128, -128, -96, -52, -14, 25, 25, 25}; + for (int i = 0; i < sizeof(expect); ++i) { + EXPECT_EQ(output_data[i], expect[i]); + } + + in_tensor.SetData(nullptr); + out_tensor.SetData(nullptr); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/reshape_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/reshape_int8_tests.cc new file mode 100644 index 0000000000..33dcc3050d --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/reshape_int8_tests.cc @@ -0,0 +1,150 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/reshape_parameter.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "mindspore/lite/src/lite_kernel.h" +#include "mindspore/lite/src/ir/tensor.h" + +namespace mindspore { + +class TestReshapeInt8 : public mindspore::Common { + public: + TestReshapeInt8() {} +}; + +TEST_F(TestReshapeInt8, reshape_quant0) { + std::vector input1 = {10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25}; + std::vector shape1 = {2, 3, 2}; + std::vector input(1, nullptr); + input[0] = input1.data(); + + int8_t output[12]; + std::vector output_shape = {2, 6}; + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + std::vector inputs_tensor(1); + inputs_tensor[0] = input_tensor1; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + ReshapeParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Reshape; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Reshape}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25}; + PrintData("output data", output, input1.size()); + PrintData("output data shape", output_tensor_shape.data(), output_tensor_shape.size()); + CompareOutputData(output, except_result.data(), input1.size(), 0.000001); + + input_tensor1->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete output0_tensor; + delete ctx; +} + +TEST_F(TestReshapeInt8, reshape_quant1_thread2) { + std::vector input1 = {10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, 25}; + std::vector shape1 = {2, 3, 2}; + std::vector input(1, nullptr); + input[0] = input1.data(); + + int8_t output[12]; + std::vector output_shape = {2, 6}; + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 2.0; + output_quant_arg.zeroPoint = 1; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + std::vector inputs_tensor(1); + inputs_tensor[0] = input_tensor1; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + ReshapeParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Reshape; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Reshape}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {6, 7, 7, 8, 8, 9, 11, 12, 12, 13, 13, 14}; + PrintData("output data", output, input1.size()); + PrintData("output data shape", output_tensor_shape.data(), output_tensor_shape.size()); + CompareOutputData(output, except_result.data(), input1.size(), 0.000001); + + input_tensor1->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete output0_tensor; + delete ctx; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/resize_bilinear_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/resize_bilinear_int8_tests.cc new file mode 100644 index 0000000000..8860be9f34 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/resize_bilinear_int8_tests.cc @@ -0,0 +1,153 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "include/context.h" +#include "src/ir/tensor.h" +#include "common/common_test.h" +#include "src/common/file_utils.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "src/runtime/kernel/arm/nnacl/int8/resize.h" +#include "src/runtime/kernel/arm/int8/resize_int8.h" + +namespace mindspore { +using mindspore::lite::tensor::QuantArg; +using mindspore::lite::tensor::Tensor; + +class TestResizeBilinearInt8 : public mindspore::Common { + public: + TestResizeBilinearInt8() = default; + void TearDown() override; + void Prepare(const std::vector &in_shape, const std::vector &out_shape, int8_t *input_data, + int8_t *output_data, const QuantArg quant_in, const QuantArg quant_out, const bool align_corners, + const int thread_num); + std::vector inputs; + std::vector outputs; + ResizeParameter param_ = {}; + lite::tensor::Tensor in_tensor; + lite::tensor::Tensor out_tensor; + + kernel::KernelKey desc_ = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Resize}; + kernel::KernelCreator creator_ = nullptr; + lite::Context ctx_ = lite::Context(); + kernel::LiteKernel *kernel_ = nullptr; + float err_percent_ = 0.2f; +}; + +void TestResizeBilinearInt8::TearDown() { + in_tensor.SetData(nullptr); + out_tensor.SetData(nullptr); +} + +void TestResizeBilinearInt8::Prepare(const std::vector &in_shape, const std::vector &out_shape, + int8_t *input_data, int8_t *output_data, const mindspore::QuantArg quant_in, + const mindspore::QuantArg quant_out, const bool align_corners, + const int thread_num) { + in_tensor.set_data_type(kNumberTypeInt8); + in_tensor.set_shape(in_shape); + in_tensor.SetData(input_data); + in_tensor.AddQuantParam(quant_in); + + out_tensor.set_data_type(kNumberTypeInt8); + out_tensor.set_shape(out_shape); + out_tensor.SetData(output_data); + out_tensor.AddQuantParam(quant_out); + + inputs.push_back(&in_tensor); + outputs.push_back(&out_tensor); + + param_.method_ = static_cast(schema::ResizeMethod_BILINEAR); + param_.new_width_ = out_shape[2]; + param_.new_height_ = out_shape[1]; + param_.align_corners_ = align_corners; + + creator_ = lite::KernelRegistry::GetInstance()->GetCreator(desc_); + + ctx_.thread_num_ = thread_num; + kernel_ = creator_(inputs, outputs, reinterpret_cast(¶m_), &ctx_, desc_, nullptr); +} + +TEST_F(TestResizeBilinearInt8, Bilinear0) { + int8_t input_data[] = {0, 1, 2, 3}; + int8_t output_data[16] = {0}; + std::vector in_shape = {1, 2, 2, 1}; + std::vector out_shape = {1, 4, 4, 1}; + const lite::tensor::QuantArg quant_in = {0.005f, 2}; + const lite::tensor::QuantArg quant_out = {0.008f, 5}; + bool align_corners = false; + int thread_num = 1; + int8_t expect[16] = {4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 5, 5, 6, 6}; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, align_corners, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, 16, err_percent_); +} + +// 2*2*2*5 -> 2*4*4*5 +TEST_F(TestResizeBilinearInt8, Bilinear1) { + std::vector in_shape = {2, 2, 2, 5}; + std::vector out_shape = {2, 4, 4, 5}; + int8_t input_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; + int8_t output_data[160] = {0}; + const lite::tensor::QuantArg quant_in = {0.005f, 2}; + const lite::tensor::QuantArg quant_out = {0.008f, 5}; + int thread_num = 1; + bool align_corners = false; + int8_t expect[160] = {4, 4, 5, 6, 6, 5, 6, 7, 7, 8, 7, 8, 8, 9, 9, 7, 8, 8, 9, 9, 7, 8, 8, + 9, 9, 8, 9, 10, 10, 11, 10, 11, 11, 12, 13, 10, 11, 11, 12, 13, 10, 11, 11, 12, 13, 12, + 12, 13, 13, 14, 13, 14, 14, 15, 16, 13, 14, 14, 15, 16, 10, 11, 11, 12, 13, 12, 12, 13, 13, + 14, 13, 14, 14, 15, 16, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 18, 18, 19, 20, 20, 19, 20, + 21, 21, 22, 19, 20, 21, 21, 22, 19, 20, 21, 21, 22, 21, 22, 22, 23, 23, 23, 23, 24, 24, 25, + 23, 23, 24, 24, 25, 23, 23, 24, 24, 25, 24, 25, 25, 26, 27, 26, 26, 27, 28, 28, 26, 26, 27, + 28, 28, 23, 23, 24, 24, 25, 24, 25, 25, 26, 27, 26, 26, 27, 28, 28, 26, 26, 27, 28, 28}; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, align_corners, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, 160, err_percent_); +} + +// 2*2*2*5 -> 2*4*4*5 thread num 2, align corners +TEST_F(TestResizeBilinearInt8, Bilinear2) { + std::vector in_shape = {2, 2, 2, 5}; + std::vector out_shape = {2, 4, 4, 5}; + int8_t input_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; + int8_t output_data[160] = {0}; + + const lite::tensor::QuantArg quant_in = {0.005f, 2}; + const lite::tensor::QuantArg quant_out = {0.008f, 5}; + int thread_num = 2; + bool align_corners = true; + int8_t expect[160] = {4, 4, 5, 6, 6, 5, 5, 6, 7, 7, 6, 6, 7, 8, 8, 7, 8, 8, 9, 9, 6, 6, 7, + 8, 8, 7, 8, 8, 9, 9, 8, 9, 9, 10, 10, 9, 10, 10, 11, 11, 8, 9, 9, 10, 10, 9, + 10, 10, 11, 11, 10, 11, 11, 12, 13, 11, 12, 12, 13, 14, 10, 11, 11, 12, 13, 11, 12, 12, 13, + 14, 12, 13, 13, 14, 15, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 17, 18, 19, 19, 20, 18, 19, + 20, 20, 21, 19, 20, 21, 21, 22, 18, 19, 20, 20, 21, 19, 20, 21, 21, 22, 20, 21, 22, 22, 23, + 21, 22, 23, 23, 24, 20, 21, 22, 22, 23, 21, 22, 23, 23, 24, 23, 23, 24, 24, 25, 24, 24, 25, + 25, 26, 23, 23, 24, 24, 25, 24, 24, 25, 25, 26, 25, 25, 26, 26, 27, 26, 26, 27, 28, 28}; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, align_corners, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, 160, err_percent_); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/resize_nearest_neighbor_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/resize_nearest_neighbor_int8_tests.cc new file mode 100644 index 0000000000..07b8d352e2 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/resize_nearest_neighbor_int8_tests.cc @@ -0,0 +1,206 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "include/context.h" +#include "src/ir/tensor.h" +#include "common/common_test.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "src/runtime/kernel/arm/nnacl/int8/resize.h" + +namespace mindspore { +using mindspore::lite::tensor::QuantArg; +using mindspore::lite::tensor::Tensor; + +class TestResizeNearestNeighborInt8 : public mindspore::Common { + public: + TestResizeNearestNeighborInt8() = default; + void Prepare(const std::vector &in_shape, const std::vector &out_shape, int8_t *input_data, + int8_t *output_data, const QuantArg quant_in, const QuantArg quant_out, const bool align_corners, + const int thread_num); + void TearDown() override; + + std::vector inputs; + std::vector outputs; + ResizeParameter param_ = {}; + lite::tensor::Tensor in_tensor; + lite::tensor::Tensor out_tensor; + + kernel::KernelKey desc_ = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Resize}; + kernel::KernelCreator creator_ = nullptr; + lite::Context ctx_ = lite::Context(); + kernel::LiteKernel *kernel_ = nullptr; + float err_percent_ = 0.05f; +}; + +void TestResizeNearestNeighborInt8::Prepare(const std::vector &in_shape, const std::vector &out_shape, + int8_t *input_data, int8_t *output_data, const QuantArg quant_in, + const QuantArg quant_out, const bool align_corners, const int thread_num) { + in_tensor.set_data_type(kNumberTypeInt8); + in_tensor.set_shape(in_shape); + in_tensor.SetData(input_data); + in_tensor.AddQuantParam(quant_in); + + out_tensor.set_data_type(kNumberTypeInt8); + out_tensor.set_shape(out_shape); + out_tensor.SetData(output_data); + out_tensor.AddQuantParam(quant_out); + + inputs.push_back(&in_tensor); + outputs.push_back(&out_tensor); + + param_.method_ = static_cast(schema::ResizeMethod_NEAREST_NEIGHBOR); + param_.new_width_ = out_shape[2]; + param_.new_height_ = out_shape[1]; + param_.align_corners_ = align_corners; + + creator_ = lite::KernelRegistry::GetInstance()->GetCreator(desc_); + + ctx_.thread_num_ = thread_num; + kernel_ = creator_(inputs, outputs, reinterpret_cast(¶m_), &ctx_, desc_, nullptr); +} + +void TestResizeNearestNeighborInt8::TearDown() { + in_tensor.SetData(nullptr); + out_tensor.SetData(nullptr); +} + +// 2*2*1 -> 4*4*1 +TEST_F(TestResizeNearestNeighborInt8, NearestNeighbor0) { + std::vector in_shape = {1, 2, 2, 1}; + std::vector out_shape = {1, 4, 4, 1}; + QuantArg quant_in = {0.00390625, 2}; + QuantArg quant_out = {0.015625, 5}; + int8_t input_data[] = {0, 1, 2, 3}; + const int out_element_num = 16; + int8_t output_data[out_element_num] = {0}; + int thread_num = 1; + int8_t expect[16] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}; + err_percent_ = 0.25f; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, false, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, 16, err_percent_); +} + +// 2*2*2*5 -> 2*4*4*5 +TEST_F(TestResizeNearestNeighborInt8, NearestNeighbor1) { + std::vector in_shape = {2, 2, 2, 5}; + std::vector out_shape = {2, 4, 4, 5}; + QuantArg quant_in = {0.00390625, 2}; + QuantArg quant_out = {0.015625, 5}; + int8_t input_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; + const int out_element_num = 160; + int8_t output_data[out_element_num] = {0}; + int thread_num = 1; + int8_t expect[160] = {5, 5, 5, 5, 6, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 6, 6, 6, 7, 7, 5, 5, 5, + 5, 6, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 7, + 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 9, 9, 9, 9, 7, 7, 8, 8, 8, 7, 7, 8, 8, + 8, 8, 9, 9, 9, 9, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11, 10, 10, 10, 10, 11, 11, 11, + 11, 12, 12, 11, 11, 11, 12, 12, 10, 10, 10, 10, 11, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, + 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 13, 14, 14, + 14, 14, 12, 12, 13, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 13, 14, 14, 14, 14}; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, false, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, out_element_num, err_percent_); +} + +// 2*2*2*5 -> 2*4*4*5 thread num 2 align_corners +TEST_F(TestResizeNearestNeighborInt8, NearestNeighbor2) { + std::vector in_shape = {2, 2, 2, 5}; + std::vector out_shape = {2, 4, 4, 5}; + QuantArg quant_in = {0.00390625, 2}; + QuantArg quant_out = {0.015625, 5}; + int8_t input_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; + const int out_element_num = 160; + int8_t output_data[out_element_num] = {0}; + int thread_num = 2; + int8_t expect[160] = { + 5, 5, 5, 5, 6, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 6, 6, 6, 7, 7, 5, 5, 5, 5, 6, 5, 5, + 5, 5, 6, 6, 6, 6, 7, 7, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 7, 7, 8, 8, 8, 8, 9, 9, 9, + 9, 8, 9, 9, 9, 9, 7, 7, 8, 8, 8, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 9, 9, 9, 9, 10, + 10, 10, 10, 11, 10, 10, 10, 10, 11, 11, 11, 11, 12, 12, 11, 11, 11, 12, 12, 10, 10, 10, 10, 11, 10, 10, 10, + 10, 11, 11, 11, 11, 12, 12, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, + 13, 14, 14, 14, 14, 12, 12, 13, 13, 13, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 13, 14, 14, 14, 14, + }; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, true, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, out_element_num, err_percent_); +} + +// 2*2*2*5 -> 2*4*4*5 thread num 2, same quant args +TEST_F(TestResizeNearestNeighborInt8, NearestNeighbor3) { + std::vector in_shape = {2, 2, 2, 5}; + std::vector out_shape = {2, 4, 4, 5}; + QuantArg quant_in = {0.00390625, 2}; + QuantArg quant_out = {0.00390625, 2}; + int8_t input_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; + const int out_element_num = 160; + int8_t output_data[out_element_num] = {0}; + int thread_num = 2; + int8_t expect[160] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 0, 1, 2, + 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 10, + 11, 12, 13, 14, 15, 16, 17, 18, 19, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 25, 26, 27, 28, 29, 20, 21, 22, 23, 24, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 35, 36, 37, + 38, 39, 30, 31, 32, 33, 34, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 35, 36, 37, 38, 39}; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, false, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, out_element_num, err_percent_); +} + +// 2*2*2*5 -> 2*4*4*5 thread num 2 align_corners, same quant args +TEST_F(TestResizeNearestNeighborInt8, NearestNeighbor4) { + std::vector in_shape = {2, 2, 2, 5}; + std::vector out_shape = {2, 4, 4, 5}; + QuantArg quant_in = {0.00390625, 2}; + QuantArg quant_out = {0.00390625, 2}; + int8_t input_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}; + const int out_element_num = 160; + int8_t output_data[out_element_num] = {0}; + int thread_num = 2; + int8_t expect[160] = { + 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 0, 1, + 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 15, 16, 17, 18, 19, 10, 11, 12, 13, 14, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 15, 16, 17, 18, 19, 20, + 21, 22, 23, 24, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 25, 26, 27, 28, 29, 20, 21, 22, 23, 24, 20, 21, 22, + 23, 24, 25, 26, 27, 28, 29, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 35, 36, 37, 38, 39, 30, 31, 32, 33, 34, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 35, 36, 37, 38, 39, + }; + + Prepare(in_shape, out_shape, input_data, output_data, quant_in, quant_out, true, thread_num); + kernel_->Init(); + kernel_->Run(); + + CompareOutputInt8(output_data, expect, out_element_num, err_percent_); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/relu_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/sigmoid_int8_tests.cc similarity index 66% rename from mindspore/lite/test/ut/src/runtime/kernel/arm/int8/relu_int8_tests.cc rename to mindspore/lite/test/ut/src/runtime/kernel/arm/int8/sigmoid_int8_tests.cc index 99ca0098a8..361c7be45f 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/relu_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/sigmoid_int8_tests.cc @@ -14,30 +14,29 @@ * limitations under the License. */ -#include #include #include "common/common_test.h" -#include "mindspore/lite/src/runtime/kernel/arm/int8/relu_int8.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/fp32/activation.h" #include "mindspore/lite/src/kernel_registry.h" #include "mindspore/lite/include/context.h" namespace mindspore { -class TestReluInt8 : public mindspore::Common { +class TestSigmoidInt8 : public mindspore::Common { public: - TestReluInt8() {} + TestSigmoidInt8() {} }; -TEST_F(TestReluInt8, Relu) { - lite::tensor::Tensor in_tensor(kNumberTypeInt8, {2, 2}); - lite::tensor::Tensor out_tensor(kNumberTypeInt8, {2, 2}); +TEST_F(TestSigmoidInt8, Sigmoid) { + lite::tensor::Tensor in_tensor(kNumberTypeInt8, {4, 4}); + lite::tensor::Tensor out_tensor(kNumberTypeInt8, {4, 4}); - int8_t input_data[] = {-102, 25, -51, 89}; // -0.8 0.2 -0.4 0.7 - int8_t output_data[4] = {0}; + int8_t input_data[] = {0, 0, 0, 0, 1, 1, 1, 1}; // -3.5f, -3.0f, -2.5f, 0.f, 2.5f, 3.0f, 3.5f, 6.0f + int8_t output_data[8] = {0}; in_tensor.SetData(input_data); out_tensor.SetData(output_data); - const lite::tensor::QuantArg quant_in = {0.00784314f, 0}; // -1.0--1.0 -> - const lite::tensor::QuantArg quant_out = {0.00784314f, 0}; + const lite::tensor::QuantArg quant_in = {1.0, 0}; // -4.0 -- 7.0 + const lite::tensor::QuantArg quant_out = {1.0, 0}; // -3.0 -- 7.0 in_tensor.AddQuantParam(quant_in); out_tensor.AddQuantParam(quant_out); @@ -46,7 +45,7 @@ TEST_F(TestReluInt8, Relu) { ActivationParameter parameter = {0}; parameter.op_parameter_.type_ = schema::PrimitiveType_Activation; - parameter.type_ = schema::ActivationType_RELU; + parameter.type_ = schema::ActivationType_SIGMOID; kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Activation}; @@ -54,15 +53,15 @@ TEST_F(TestReluInt8, Relu) { ASSERT_NE(creator, nullptr); auto ctx = std::make_shared(); - auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), ctx.get(), desc, nullptr); ASSERT_NE(kernel, nullptr); auto ret = kernel->Run(); EXPECT_EQ(0, ret); - int8_t expect0[4] = {0, 26, 0, 90}; // - for (int i = 0; i < 4; ++i) { - EXPECT_EQ(output_data[i], expect0[i]); + int8_t expect[8] = {1, 1, 1, 1, 1, 1, 1, 1}; // 0, 0, -0.208333, 0, 2.29167, 3, 3.5, 6 + for (int i = 0; i < 8; ++i) { + EXPECT_EQ(output_data[i], expect[i]); } in_tensor.SetData(nullptr); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/softmax_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/softmax_int8_tests.cc index 1c22a52dee..20a5ff88a4 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/softmax_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/softmax_int8_tests.cc @@ -75,7 +75,7 @@ TEST_F(TestSoftmaxInt8, SoftmaxInt8) { ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx.get(), desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx.get(), desc, nullptr); ASSERT_NE(kernel, nullptr); auto output_tensor_shape = output0_tensor.shape(); kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/split_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/split_int8_tests.cc index 8437edaa76..70d7e5c313 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/split_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/split_int8_tests.cc @@ -84,7 +84,7 @@ TEST_F(TestSplitInt8, Split_quant0_thread2) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output1_tensor_shape = output1_tensor->shape(); auto output2_tensor_shape = output2_tensor->shape(); @@ -172,7 +172,7 @@ TEST_F(TestSplitInt8, Split_quant0_thread2_num) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output1_tensor_shape = output1_tensor->shape(); auto output2_tensor_shape = output2_tensor->shape(); @@ -268,7 +268,7 @@ TEST_F(TestSplitInt8, Split_quant1_thread2_num) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); kernel::LiteKernel *kernel = - creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc); + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); ASSERT_NE(kernel, nullptr); auto output1_tensor_shape = output1_tensor->shape(); auto output2_tensor_shape = output2_tensor->shape(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/squeeze_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/squeeze_int8_tests.cc new file mode 100644 index 0000000000..a2c2a76481 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/squeeze_int8_tests.cc @@ -0,0 +1,95 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/squeeze_parameter.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "mindspore/lite/src/lite_kernel.h" +#include "mindspore/lite/src/ir/tensor.h" + +namespace mindspore { + +class TestSqueezeInt8 : public mindspore::Common { + public: + TestSqueezeInt8() {} +}; + +TEST_F(TestSqueezeInt8, Squeeze_1d_axis0_offset0_quant0_thread2) { + std::vector input1 = {1, 2, 3, 4, 5, 6, 7, 8}; + std::vector shape1 = {8, 1}; + std::vector input(1, nullptr); + input[0] = input1.data(); + + const int output_size = 8; + int8_t output[8]; + std::vector output_shape = {8}; + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + std::vector inputs_tensor(1); + inputs_tensor[0] = input_tensor1; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + SqueezeParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Squeeze; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + op_param.axis_ = 0; + op_param.offset_[0] = 1; + op_param.offset_size_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Squeeze}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, 2, 3, 4, 5, 6, 7, 8}; + PrintData("output data", output, output_size); + PrintData("output data shape", output_tensor_shape.data(), output_tensor_shape.size()); + CompareOutputData(output, except_result.data(), output_size, 0.000001); + + input_tensor1->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete output0_tensor; + delete ctx; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/topk_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/topk_int8_tests.cc index 1334f72b35..ea9bf54dbc 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/topk_int8_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/topk_int8_tests.cc @@ -45,7 +45,7 @@ TEST_F(TestTopKInt8, TopK) { auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); ASSERT_NE(creator, nullptr); - auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), nullptr, desc); + auto kernel = creator(inputs, outputs, reinterpret_cast(¶meter), nullptr, desc, nullptr); ASSERT_NE(kernel, nullptr); auto ret = kernel->Run(); diff --git a/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/unsqueeze_int8_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/unsqueeze_int8_tests.cc new file mode 100644 index 0000000000..b8fb3423c1 --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/arm/int8/unsqueeze_int8_tests.cc @@ -0,0 +1,95 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/runtime/kernel/arm/nnacl/unsqueeze_parameter.h" +#include "mindspore/lite/src/kernel_registry.h" +#include "mindspore/lite/src/lite_kernel.h" +#include "mindspore/lite/src/ir/tensor.h" + +namespace mindspore { + +class TestUnsqueezeInt8 : public mindspore::Common { + public: + TestUnsqueezeInt8() {} +}; + +TEST_F(TestUnsqueezeInt8, Unsqueeze_1) { + std::vector input1 = {1, 2, 3, 4, 5, 6, 7, 8}; + std::vector shape1 = {8}; + std::vector input(1, nullptr); + input[0] = input1.data(); + + const int output_size = 8; + int8_t output[8]; + std::vector output_shape = {8, 1}; + lite::tensor::QuantArg input_quant_arg; + input_quant_arg.scale = 1.0; + input_quant_arg.zeroPoint = 0; + lite::tensor::QuantArg output_quant_arg; + output_quant_arg.scale = 1.0; + output_quant_arg.zeroPoint = 0; + + lite::tensor::Tensor *input_tensor1 = new lite::tensor::Tensor; + TypeId tid_int8 = kNumberTypeInt8; + input_tensor1->SetData(input1.data()); + input_tensor1->set_shape(shape1); + input_tensor1->AddQuantParam(input_quant_arg); + input_tensor1->set_data_type(tid_int8); + + std::vector inputs_tensor(1); + inputs_tensor[0] = input_tensor1; + + std::vector outputs_tensor(1); + lite::tensor::Tensor *output0_tensor = new lite::tensor::Tensor; + output0_tensor->SetData(output); + output0_tensor->set_shape(output_shape); + output0_tensor->AddQuantParam(output_quant_arg); + output0_tensor->set_data_type(tid_int8); + outputs_tensor[0] = output0_tensor; + + UnSqueezeParameter op_param; + op_param.op_parameter_.type_ = schema::PrimitiveType_Unsqueeze; + lite::Context *ctx = new lite::Context; + ctx->thread_num_ = 2; + op_param.axis_ = 0; + op_param.offset_[0] = 1; + op_param.offset_size_ = 1; + kernel::KernelKey desc = {kernel::KERNEL_ARCH::kCPU, kNumberTypeInt8, schema::PrimitiveType_Unsqueeze}; + auto creator = lite::KernelRegistry::GetInstance()->GetCreator(desc); + ASSERT_NE(creator, nullptr); + kernel::LiteKernel *kernel = + creator(inputs_tensor, outputs_tensor, reinterpret_cast(&op_param), ctx, desc, nullptr); + ASSERT_NE(kernel, nullptr); + auto output_tensor_shape = output0_tensor->shape(); + ASSERT_EQ(output_tensor_shape, output_shape); + kernel->Run(); + + std::vector except_result = {1, 2, 3, 4, 5, 6, 7, 8}; + PrintData("output data", output, output_size); + PrintData("output data shape", output_tensor_shape.data(), output_tensor_shape.size()); + CompareOutputData(output, except_result.data(), output_size, 0.000001); + + input_tensor1->SetData(nullptr); + output0_tensor->SetData(nullptr); + delete input_tensor1; + delete output0_tensor; + delete ctx; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/opencl/arithmetic_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/opencl/arithmetic_tests.cc index e7fccfe1a3..5d9e99dd0b 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/opencl/arithmetic_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/opencl/arithmetic_tests.cc @@ -61,13 +61,12 @@ void LogData(void *data, const int size, const std::string prefix) { } void TestCase(const std::vector &shape_a, const std::vector &shape_b) { - std::cout << "TestCase" << std::endl; auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); + auto allocator = ocl_runtime->GetAllocator(); bool is_bias_add = shape_b.empty(); auto tensorType = schema::NodeType_ValueNode; - std::cout << "TestCase tensor" << std::endl; lite::tensor::Tensor *tensor_a = new lite::tensor::Tensor(kNumberTypeFloat32, shape_a, schema::Format_NHWC4, tensorType); lite::tensor::Tensor *tensor_b = @@ -77,7 +76,6 @@ void TestCase(const std::vector &shape_a, const std::vector &shape_b) int64_t element_num = tensor_a->ElementsC4Num(); int64_t element_num_b = is_bias_add ? 1 : tensor_b->ElementsC4Num(); - std::cout << "TestCase new data" << std::endl; float *data_a = new float[element_num]; float *data_b = new float[element_num_b]; float *data_c_cpu = new float[element_num]; @@ -87,14 +85,12 @@ void TestCase(const std::vector &shape_a, const std::vector &shape_b) InitData(data_b, element_num_b); memset(data_c_ocl, 0, sizeof(float) * element_num); - std::cout << "TestCase run cpu" << std::endl; if (is_bias_add) { BoardcaseAdd(data_a, static_cast(data_b)[0], data_c_cpu, element_num); } else { ElementAdd(data_a, data_b, data_c_cpu, element_num); } - std::cout << "TestCase set data" << std::endl; std::vector inputs = {tensor_a}; if (!is_bias_add) { inputs.push_back(tensor_b); @@ -114,9 +110,10 @@ void TestCase(const std::vector &shape_a, const std::vector &shape_b) new kernel::ArithmeticOpenCLKernel(reinterpret_cast(param), arithmetic_inputs, outputs, &ctx); arith_kernel->Init(); + tensor_a->MallocData(allocator); + tensor_b->MallocData(allocator); std::vector kernels{arith_kernel}; auto *kernel = new kernel::SubGraphOpenCLKernel(inputs, outputs, kernels, kernels, kernels); - std::cout << "TestCase Init" << std::endl; kernel->Init(); memcpy(inputs[0]->Data(), data_a, sizeof(float) * element_num); @@ -124,7 +121,6 @@ void TestCase(const std::vector &shape_a, const std::vector &shape_b) memcpy(inputs[1]->Data(), data_b, sizeof(float) * element_num_b); } - std::cout << "TestCase Run" << std::endl; kernel->Run(); memcpy(data_c_ocl, outputs[0]->Data(), sizeof(float) * element_num); @@ -136,7 +132,6 @@ void TestCase(const std::vector &shape_a, const std::vector &shape_b) LogData(outputs[0]->Data(), 10, "OpenCL compute : "); bool cmp = DataCompare(data_c_cpu, data_c_ocl, element_num); MS_LOG(INFO) << "Compare " << (cmp ? "success!" : "failed!"); - std::cout << "TestCase End" << std::endl; // free delete[] data_a; @@ -162,15 +157,15 @@ class TestArithmeticOpenCL : public mindspore::Common { }; TEST_F(TestArithmeticOpenCL, AddElementwiseTest) { - const std::vector &shape_a = {1, 32, 32, 4}; - const std::vector &shape_b = {1, 32, 32, 4}; + const std::vector &shape_a = {1, 1024, 1024, 4}; + const std::vector &shape_b = {1, 1024, 1024, 4}; TestCase(shape_a, shape_b); } -// TEST_F(TestOpenCLKernel, AddBoardcaseTest) { -// const std::vector &shape_a = {1, 4, 128, 128}; -// const std::vector &shape_b = {}; -// TestCase(shape_a, shape_b); -//} +TEST_F(TestArithmeticOpenCL, AddBoardcaseTest) { + const std::vector &shape_a = {1, 128, 128, 4}; + const std::vector &shape_b = {}; + TestCase(shape_a, shape_b); +} } // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/opencl/concat_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/opencl/concat_tests.cc index 7c039d47ca..0cb6156ae5 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/opencl/concat_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/opencl/concat_tests.cc @@ -21,7 +21,6 @@ #include "mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h" #include "mindspore/lite/src/runtime/kernel/opencl/kernel/concat.h" - int DivideRoundUp(int n, int div) { int q = n / div; return n % div == 0 ? q : q + 1; @@ -77,15 +76,26 @@ void ConcatComputeByCPU_3input_dim4_axis3(float *input0, float *input1, float *i postion = i * output_shape[1] * output_shape[2] * output_shape[3] + j * output_shape[2] * output_shape[3] + k * output_shape[3]; for (int w = 0; w < output_shape[3]; w++) { - if (w < input_shape0[3] + input_shape1[3]) { - output[postion++] = (w < input_shape0[3]) ? input0[index0++] : input1[index1++]; + if (w < input_shape0[3]) { + int align = DivideRoundUp(input_shape0[3], 4) * 4; + index0 = i * input_shape0[1] * input_shape0[2] * align + j * input_shape0[2] * align + k * align + w; + output[postion++] = input0[index0]; + } else if (w >= input_shape0[3] && w < (input_shape0[3] + input_shape1[3])) { + int align = DivideRoundUp(input_shape1[3], 4) * 4; + index1 = i * input_shape1[1] * input_shape1[2] * align + j * input_shape1[2] * align + k * align + w - + input_shape0[3]; + output[postion++] = input1[index1]; } else if ((input_shape0[3] + input_shape1[3]) <= w && w < (input_shape0[3] + input_shape1[3] + input_shape2[3])) { - output[postion++] = input2[index2++]; + int align = DivideRoundUp(input_shape2[3], 4) * 4; + index2 = i * input_shape2[1] * input_shape2[2] * align + j * input_shape2[2] * align + k * align + w - + input_shape0[3] - input_shape1[3]; + output[postion++] = input2[index2]; } else { - for (int ind = input_shape0[3] + input_shape1[3]; ind < output_shape[3]; ind++) { + for (int ind = input_shape0[3] + input_shape1[3] + input_shape2[3]; ind < output_shape[3]; ind++) { output[postion++] = 0; } + break; } } } @@ -96,18 +106,31 @@ void ConcatComputeByCPU_3input_dim4_axis3(float *input0, float *input1, float *i namespace mindspore { class TestConcatOpenCL : public mindspore::Common { public: - TestConcatOpenCL(){} + TestConcatOpenCL() {} }; + +template +void CompareOutputData1(T *output_data, T *correct_data, int size, float err_bound) { + for (size_t i = 0; i < size; i++) { + T abs = fabs(output_data[i] - correct_data[i]); + // printf("i=%d %.3f %.3f\n", i, output_data[i], correct_data[i]); + ASSERT_LE(abs, err_bound); + } +} + TEST_F(TestConcatOpenCL, ConcatFp32_2input_dim4_axis3) { MS_LOG(INFO) << "begin test"; auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); ocl_runtime->Init(); + auto allocator = ocl_runtime->GetAllocator(); MS_LOG(INFO) << "init tensors"; - constexpr int INPUT_NUM = 3; - std::array, INPUT_NUM> input_shapes = { - std::vector{1, 240, 240, 16}, std::vector{1, 240, 240, 16}, std::vector{1, 240, 240, 64}}; - std::vector output_shape = {1, 240, 240, 96}; + constexpr int INPUT_NUM = 2; + // std::array, INPUT_NUM> input_shapes = { + // std::vector{1, 120, 120, 16}, std::vector{1, 120, 120, 16},std::vector{1, 120, 120, 96}}; + std::array, INPUT_NUM> input_shapes = {std::vector{1, 32, 512, 48}, + std::vector{1, 32, 512, 48}}; + std::vector output_shape = {1, 32, 512, 96}; output_shape[3] = DivideRoundUp(output_shape[3], 4) * 4; auto data_type = kNumberTypeFloat32; auto tensor_type = schema::NodeType_ValueNode; @@ -118,32 +141,30 @@ TEST_F(TestConcatOpenCL, ConcatFp32_2input_dim4_axis3) { auto *output_tensor = new lite::tensor::Tensor(data_type, output_shape, schema::Format_NHWC, tensor_type); std::vector outputs{output_tensor}; std::cout << "input_shapes size=: " << input_shapes.size() << std::endl; - MS_LOG(INFO) << "initialize tensors"; + + std::cout << "initialize tensors"; auto param = new ConcatParameter(); param->axis_ = 3; auto *concat_kernel = new kernel::ConcatOpenCLKernel(reinterpret_cast(param), inputs, outputs); concat_kernel->Init(); - MS_LOG(INFO) << "initialize sub_graph"; std::vector kernels{concat_kernel}; auto *sub_graph = new kernel::SubGraphOpenCLKernel(inputs, outputs, kernels, kernels, kernels); + // to do allocate memory for inputs and outputs + for (auto &input_tensor : inputs) { + input_tensor->MallocData(allocator); + } sub_graph->Init(); - + unsigned int seed = 123; MS_LOG(INFO) << "initialize input data"; - srand(time(NULL)); for (auto &input_tensor : inputs) { auto input_data = reinterpret_cast(input_tensor->Data()); - static unsigned int seed = 123; for (int i = 0; i < input_tensor->ElementsNum(); ++i) { input_data[i] = static_cast(rand_r(&seed) % 10 + 1); } - printf("\n"); } - MS_LOG(INFO) << "==================output data================"; - sub_graph->Run(); - auto *output_data_gpu = reinterpret_cast(output_tensor->Data()); - printf("\n"); + // compute the result for CPU auto *input_data0 = reinterpret_cast(inputs[0]->Data()); auto *input_data1 = reinterpret_cast(inputs[1]->Data()); std::vector output_data_cpu(output_shape[0] * output_shape[1] * output_shape[2] * output_shape[3]); @@ -156,8 +177,10 @@ TEST_F(TestConcatOpenCL, ConcatFp32_2input_dim4_axis3) { ConcatComputeByCPU_3input_dim4_axis3(input_data0, input_data1, input_data2, output_data_cpu.data(), input_shapes[0], input_shapes[1], input_shapes[2], output_shape, param->axis_); } - printf("\n"); - CompareOutputData(output_data_gpu, output_data_cpu.data(), output_tensor->ElementsNum(), 0.00001); - MS_LOG(INFO) << "Testconcat passed"; + + std::cout << "==================output data================" << std::endl; + sub_graph->Run(); + auto *output_data_gpu = reinterpret_cast(output_tensor->Data()); + CompareOutputData1(output_data_gpu, output_data_cpu.data(), output_tensor->ElementsNum(), 0.00001); } } // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/opencl/convolution_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/opencl/convolution_tests.cc new file mode 100644 index 0000000000..86efc7886d --- /dev/null +++ b/mindspore/lite/test/ut/src/runtime/kernel/opencl/convolution_tests.cc @@ -0,0 +1,179 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include "utils/log_adapter.h" +#include "common/common_test.h" +#include "mindspore/lite/src/common/file_utils.h" +#include "mindspore/lite/src/runtime/opencl/opencl_runtime.h" +#include "src/runtime/kernel/arm/nnacl/pack.h" +#include "mindspore/lite/src/runtime/kernel/opencl/subgraph_opencl_kernel.h" +#include "mindspore/lite/src/runtime/kernel/opencl/kernel/convolution.h" + +using mindspore::kernel::ConvolutionOpenCLKernel; +using mindspore::kernel::LiteKernel; +using mindspore::kernel::SubGraphOpenCLKernel; + +namespace mindspore { + +class TestConvolutionOpenCL : public mindspore::Common {}; + +void LoadData(void *dst, size_t dst_size, const std::string &file_path) { + if (file_path.empty()) { + memset(dst, 0x00, dst_size); + } else { + auto src_data = reinterpret_cast(mindspore::lite::ReadFile(file_path.c_str(), &dst_size)); + memcpy(dst, src_data, dst_size); + } +} + +void MyCompareOutput(lite::tensor::Tensor *output_tensor, const std::string &file_path) { + auto *output_data = reinterpret_cast(output_tensor->Data()); + printf("output[0:10]:"); + for (int i = 0; i < 10; i++) { + printf("%d:%.3f ", i, output_data[i]); + } + printf("\n"); + + size_t output_size = output_tensor->Size(); + auto expect_data = reinterpret_cast(mindspore::lite::ReadFile(file_path.c_str(), &output_size)); + constexpr float atol = 0.5; + for (int i = 0; i < output_tensor->ElementsNum(); ++i) { + if (std::fabs(output_data[i] - expect_data[i]) > atol) { + printf("error at idx[%d] expect=%.3f output=%.3f\n", i, expect_data[i], output_data[i]); + printf("error at idx[%d] expect=%.3f output=%.3f\n", i, expect_data[i], output_data[i]); + printf("error at idx[%d] expect=%.3f output=%.3f\n\n\n", i, expect_data[i], output_data[i]); + return; + } + } + printf("compare success!\n"); + printf("compare success!\n"); + printf("compare success!\n\n\n"); +} + +void TEST_MAIN(ConvParameter *param, schema::Format data_format, const std::string &input_file, + const std::string &weight_file, const std::string &bias_file, const std::string &expect_file) { + assert(data_format == schema::Format_NHWC || data_format == schema::Format_NHWC4); + + std::cout << "initialize OpenCLRuntime"; + auto ocl_runtime = lite::opencl::OpenCLRuntime::GetInstance(); + ocl_runtime->Init(); + auto allocator = ocl_runtime->GetAllocator(); + + std::cout << "create inputs/weights/outputs Tensors(framework do)"; + std::vector input_shape = {param->input_batch_, param->input_h_, param->input_w_, param->input_channel_}; + std::vector weight_shape = {param->output_channel_, param->kernel_h_, param->kernel_w_, param->input_channel_}; + std::vector bias_shape = {param->output_channel_}; + std::vector output_shape = {param->output_batch_, param->output_h_, param->output_w_, param->output_channel_}; + auto data_type = kNumberTypeFloat32; + auto tensorType = schema::NodeType_ValueNode; + auto input_tensor = new lite::tensor::Tensor(data_type, input_shape, data_format, tensorType); + auto weight_tensor = new lite::tensor::Tensor(data_type, weight_shape, schema::Format_KHWC, tensorType); + auto bias_tensor = new lite::tensor::Tensor(data_type, bias_shape, schema::Format_KHWC, tensorType); + auto output_tensor = new lite::tensor::Tensor(data_type, output_shape, data_format, tensorType); + std::vector inputs{input_tensor, weight_tensor, bias_tensor}; + std::vector outputs{output_tensor}; + + std::cout << "initialize weight Tensors data(framework do)"; + std::vector weight_vec(weight_tensor->ElementsNum()); + std::vector bias_vec(weight_tensor->ElementsNum()); + weight_tensor->SetData(weight_vec.data()); + bias_tensor->SetData(bias_vec.data()); + LoadData(weight_tensor->Data(), weight_tensor->Size(), weight_file); + LoadData(bias_tensor->Data(), bias_tensor->Size(), bias_file); + + std::cout << "create OpenCL Kernel"; // weight has been allcated by framework + auto *conv_kernel = new ConvolutionOpenCLKernel(reinterpret_cast(param), inputs, outputs); + conv_kernel->Init(); + std::vector kernels{conv_kernel}; + + // freamework to do!!! allocate memory by hand + inputs[0]->MallocData(allocator); + + std::cout << "create SubGraphOpenCLKernel"; + auto *sub_graph = new SubGraphOpenCLKernel({input_tensor}, outputs, kernels, kernels, kernels); + sub_graph->Init(); + + std::cout << "initialize input Tensors data"; // inputs has been allcated by sub_graph->Init() + LoadData(input_tensor->Data(), input_tensor->Size(), input_file); + printf("input[0] =%.3f\n", reinterpret_cast(input_tensor->Data())[0]); + printf("weight[0]=%.3f\n", reinterpret_cast(weight_tensor->Data())[0]); + printf("bias[0] =%.3f\n", reinterpret_cast(bias_tensor->Data())[0]); + + std::cout << "sub_graph->Run()"; + sub_graph->Run(); + printf("output_tensor->Size() =%zu\n", output_tensor->Size()); + + std::cout << "compare result"; + MyCompareOutput(output_tensor, expect_file); + // lite::CompareOutput(reinterpret_cast(output_tensor->Data()), expect_file); + + mindspore::lite::opencl::OpenCLRuntime::DeleteInstance(); +} + +std::array GenFilenames(ConvParameter *param, schema::Format data_format, const std::string &path) { + auto full_path = path + "inputNHWC_" + std::to_string(param->input_batch_) + "x" + std::to_string(param->input_h_) + + "x" + std::to_string(param->input_w_) + "x" + std::to_string(param->input_channel_) + + "_outputNHWC_" + std::to_string(param->output_batch_) + "x" + std::to_string(param->output_h_) + + "x" + std::to_string(param->output_w_) + "x" + std::to_string(param->output_channel_) + + "_kernelHW_" + std::to_string(param->kernel_h_) + "x" + std::to_string(param->kernel_w_) + + "_strideHW_" + std::to_string(param->stride_h_) + "x" + std::to_string(param->stride_w_) + + "_padTopBottomLeftRight_" + std::to_string(param->pad_u_) + "x" + std::to_string(param->pad_d_) + + "x" + std::to_string(param->pad_l_) + "x" + std::to_string(param->pad_r_) + "_dilationHW_1x1/"; + + if (data_format == schema::Format_NHWC4) { + return std::array{full_path + "input_NHWC4.bin", full_path + "weight_OHWI.bin", + full_path + "bias_C4.bin", full_path + "expect_NHWC4.bin"}; + } else { + return std::array{full_path + "input_NHWC.bin", full_path + "weight_OHWI.bin", + full_path + "bias_C.bin", full_path + "expect_NHWC.bin"}; + } +} + +TEST_F(TestConvolutionOpenCL, in1x224x224x3_out1x112x112x32_k33_s22_p0101) { + auto param = new ConvParameter; + param->input_batch_ = 1, param->input_h_ = 224, param->input_w_ = 224, param->input_channel_ = 3; + param->output_batch_ = 1, param->output_h_ = 112, param->output_w_ = 112, param->output_channel_ = 32; + param->kernel_h_ = 3, param->kernel_w_ = 3; + param->stride_h_ = 2, param->stride_w_ = 2; + param->pad_u_ = 0, param->pad_d_ = 1, param->pad_l_ = 0, param->pad_r_ = 1; + + auto filenames = GenFilenames(param, schema::Format_NHWC4, "testcases/mobilenetv2_fp32/"); + // std::cout << filenames[0] << std::endl; + // std::cout << filenames[1] << std::endl; + // std::cout << filenames[2] << std::endl; + // std::cout << filenames[3] << std::endl; + TEST_MAIN(param, schema::Format_NHWC4, filenames[0], filenames[1], filenames[2], filenames[3]); + lite::opencl::OpenCLRuntime::DeleteInstance(); +} + +TEST_F(TestConvolutionOpenCL, in1x1x64x512_out1x1x64x7358_k11_s11_p0000) { + auto param = new ConvParameter; + param->input_batch_ = 1, param->input_h_ = 1, param->input_w_ = 64, param->input_channel_ = 512; + param->output_batch_ = 1, param->output_h_ = 1, param->output_w_ = 64, param->output_channel_ = 7358; + param->kernel_h_ = 1, param->kernel_w_ = 1; + param->stride_h_ = 1, param->stride_w_ = 1; + param->pad_u_ = 0, param->pad_d_ = 0, param->pad_l_ = 0, param->pad_r_ = 0; + + auto filenames = GenFilenames(param, schema::Format_NHWC4, "testcases/02_fp32/"); + // std::cout << filenames[0] << std::endl; + // std::cout << filenames[1] << std::endl; + // std::cout << filenames[2] << std::endl; + // std::cout << filenames[3] << std::endl; + TEST_MAIN(param, schema::Format_NHWC4, filenames[0], filenames[1], filenames[2], filenames[3]); + lite::opencl::OpenCLRuntime::DeleteInstance(); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/src/runtime/kernel/opencl/transpose_tests.cc b/mindspore/lite/test/ut/src/runtime/kernel/opencl/transpose_tests.cc index 20324e0cdb..0f432ba599 100644 --- a/mindspore/lite/test/ut/src/runtime/kernel/opencl/transpose_tests.cc +++ b/mindspore/lite/test/ut/src/runtime/kernel/opencl/transpose_tests.cc @@ -66,6 +66,9 @@ TEST_F(TestTransposeOpenCL, TransposeFp32) { size_n = size_n > 100 ? 100 : size_n; for (int i = 0; i < size_n; i++) { std::cout << output_data[i] << " "; + if ((i + 1) % c == 0) { + std::cout << std::endl; + } } std::cout << std::endl; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite new file mode 100644 index 0000000000..762c2e7d3f Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite new file mode 100644 index 0000000000..c0c379a60c Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite new file mode 100644 index 0000000000..d36b81e327 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/add3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite new file mode 100644 index 0000000000..05b172c71e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/argmin.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite new file mode 100644 index 0000000000..75b2d77d30 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/ceil.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div1.tflite new file mode 100644 index 0000000000..6ba493eebf Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite new file mode 100644 index 0000000000..bc367d8f1e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite new file mode 100644 index 0000000000..a8b7e5ec7b Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/div3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/expand_dims.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/expand_dims.tflite new file mode 100644 index 0000000000..b76878f102 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/expand_dims.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/fill.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/fill.tflite new file mode 100644 index 0000000000..7e87baac9e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/fill.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor.tflite new file mode 100644 index 0000000000..9a24dbd20c Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite new file mode 100644 index 0000000000..3bf705e36d Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_div.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite new file mode 100644 index 0000000000..b101b93076 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/floor_mod.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather.tflite new file mode 100644 index 0000000000..422ff5c51e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather_nd.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather_nd.tflite new file mode 100644 index 0000000000..9fe5da76ba Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/gather_nd.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite new file mode 100644 index 0000000000..ba8c13f363 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/leaky_relu.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/lrn.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/lrn.tflite new file mode 100644 index 0000000000..a5a20a1ddf Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/lrn.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite new file mode 100644 index 0000000000..0621a681ac Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite new file mode 100644 index 0000000000..089de5cb2d Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite new file mode 100644 index 0000000000..a0b90cde82 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/mul3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite new file mode 100644 index 0000000000..bc5c86a334 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pad.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite new file mode 100644 index 0000000000..2920f9ae4e Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/pow.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite new file mode 100644 index 0000000000..6e9afb7bab Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/range.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite new file mode 100644 index 0000000000..8733544eba Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/rank.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/relu.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/relu.tflite new file mode 100644 index 0000000000..a99a4ddce8 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/relu.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite new file mode 100644 index 0000000000..6a55540324 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/resize_nearest_neighbor.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite new file mode 100644 index 0000000000..96b50b4e23 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/reverse.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite new file mode 100644 index 0000000000..d636c870ec Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sigmoid.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squeeze.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squeeze.tflite new file mode 100644 index 0000000000..7eb0678150 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/squeeze.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite new file mode 100644 index 0000000000..8e3b3aaf80 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub1.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite new file mode 100644 index 0000000000..dbca4e40a1 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub2.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite new file mode 100644 index 0000000000..c223cdbf90 Binary files /dev/null and b/mindspore/lite/test/ut/tools/converter/parser/tflite/test_data/sub3.tflite differ diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc index c90ff924a1..7f0453bd11 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_abs_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserAbs : public TestTfliteParser { public: - TestTfliteParserAbs() {} + TestTfliteParserAbs() = default; void SetUp() override { meta_graph = LoadAndConvert("./abs.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc new file mode 100644 index 0000000000..d590be8131 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_add_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserAdd1 : public TestTfliteParser { + public: + TestTfliteParserAdd1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add1.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserAdd2 : public TestTfliteParser { + public: + TestTfliteParserAdd2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add2.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserAdd3 : public TestTfliteParser { + public: + TestTfliteParserAdd3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./add3.tflite", ""); } +}; + +TEST_F(TestTfliteParserAdd3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Add) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserAdd3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc index 89519cea10..72a8237673 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_addn_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserAddN : public TestTfliteParser { public: - TestTfliteParserAddN() {} + TestTfliteParserAddN() = default; void SetUp() override { meta_graph = LoadAndConvert("./addn.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc new file mode 100644 index 0000000000..0bb625ec87 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_argmin_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserArgmin : public TestTfliteParser { + public: + TestTfliteParserArgmin() = default; + void SetUp() override { meta_graph = LoadAndConvert("./argmin.tflite", ""); } +}; + +TEST_F(TestTfliteParserArgmin, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_ArgMin) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserArgmin, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsArgMin(); + ASSERT_EQ(val->axis, 1); + ASSERT_EQ(val->topK, 1); + ASSERT_EQ(val->axisType, 1); + ASSERT_EQ(val->keepDims, false); + ASSERT_EQ(val->outMaxValue, false); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc index 4d37fa506a..c78d8eac54 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_batch_to_space_nd_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserBatchToSpaceNd : public TestTfliteParser { public: - TestTfliteParserBatchToSpaceNd() {} + TestTfliteParserBatchToSpaceNd() = default; void SetUp() override { meta_graph = LoadAndConvert("./batch_to_space_nd.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc index c986d595d7..28fe10828c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cast_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserCast : public TestTfliteParser { public: - TestTfliteParserCast() {} + TestTfliteParserCast() = default; void SetUp() override { meta_graph = LoadAndConvert("./cast.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc new file mode 100644 index 0000000000..59d8664be1 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_ceil_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserCeil : public TestTfliteParser { + public: + TestTfliteParserCeil() = default; + void SetUp() override { meta_graph = LoadAndConvert("./ceil.tflite", ""); } +}; + +TEST_F(TestTfliteParserCeil, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Ceil) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc index 785cd35e44..756cd626c6 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_cos_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserCos : public TestTfliteParser { public: - TestTfliteParserCos() {} + TestTfliteParserCos() = default; void SetUp() override { meta_graph = LoadAndConvert("./cos.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc index d1983e0b84..5283c0a85d 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_depth_to_space_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserDepthToSpace : public TestTfliteParser { public: - TestTfliteParserDepthToSpace() {} + TestTfliteParserDepthToSpace() = default; void SetUp() override { meta_graph = LoadAndConvert("./depth_to_space.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc new file mode 100644 index 0000000000..8ee47212a4 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_div_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserDiv1 : public TestTfliteParser { + public: + TestTfliteParserDiv1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div1.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserDiv2 : public TestTfliteParser { + public: + TestTfliteParserDiv2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div2.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserDiv3 : public TestTfliteParser { + public: + TestTfliteParserDiv3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./div3.tflite", ""); } +}; + +TEST_F(TestTfliteParserDiv3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Div) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserDiv3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc index 7e816a9d39..ba2e4b0f51 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserEqual : public TestTfliteParser { public: - TestTfliteParserEqual() {} + TestTfliteParserEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc new file mode 100644 index 0000000000..359d54b6e5 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_fill_parser_test.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFill : public TestTfliteParser { + public: + TestTfliteParserFill() = default; + void SetUp() override { meta_graph = LoadAndConvert("./fill.tflite", ""); } +}; + +TEST_F(TestTfliteParserFill, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Fill) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserFill, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsFill(); + + std::vector dims = {9}; + ASSERT_EQ(val->dims, dims); +} +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc new file mode 100644 index 0000000000..d92c1608a7 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_div_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloorDiv : public TestTfliteParser { + public: + TestTfliteParserFloorDiv() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor_div.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloorDiv, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_FloorDiv) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc new file mode 100644 index 0000000000..f8cf0fdf03 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_mod_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloorMod : public TestTfliteParser { + public: + TestTfliteParserFloorMod() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor_mod.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloorMod, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_FloorMod) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc new file mode 100644 index 0000000000..d7777f24b9 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_floor_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserFloor : public TestTfliteParser { + public: + TestTfliteParserFloor() = default; + void SetUp() override { meta_graph = LoadAndConvert("./floor.tflite", ""); } +}; + +TEST_F(TestTfliteParserFloor, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Floor) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc new file mode 100644 index 0000000000..d6badec6a7 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_nd_parser_test.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGatherNd : public TestTfliteParser { + public: + TestTfliteParserGatherNd() = default; + void SetUp() override { meta_graph = LoadAndConvert("./gather_nd.tflite", ""); } +}; + +TEST_F(TestTfliteParserGatherNd, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_GatherNd) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserGatherNd, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsGatherNd(); + ASSERT_EQ(val->batchDims, 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc new file mode 100644 index 0000000000..13420abada --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_gather_parser_test.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserGather : public TestTfliteParser { + public: + TestTfliteParserGather() = default; + void SetUp() override { meta_graph = LoadAndConvert("./gather.tflite", ""); } +}; + +TEST_F(TestTfliteParserGather, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Gather) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserGather, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsGather(); + ASSERT_EQ(val->axis, 0); + ASSERT_EQ(val->batchDims, 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc index 3b5dba47c2..c65b80cc88 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserGreaterEqual : public TestTfliteParser { public: - TestTfliteParserGreaterEqual() {} + TestTfliteParserGreaterEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./greater_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc index 055dbab7da..b765fc8d85 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_greater_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserGreater : public TestTfliteParser { public: - TestTfliteParserGreater() {} + TestTfliteParserGreater() = default; void SetUp() override { meta_graph = LoadAndConvert("./greater.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc new file mode 100644 index 0000000000..80c8826088 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_leaky_relu_parser_test.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLeakyRelu : public TestTfliteParser { + public: + TestTfliteParserLeakyRelu() = default; + void SetUp() override { meta_graph = LoadAndConvert("./leaky_relu.tflite", ""); } +}; + +TEST_F(TestTfliteParserLeakyRelu, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_LeakyReLU) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserLeakyRelu, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsLeakyReLU(); + ASSERT_NE(val, nullptr); + ASSERT_EQ(val->negativeSlope, 0.20000000298023224); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc index 6c1d29877f..06f57a4bab 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserLessEqual : public TestTfliteParser { public: - TestTfliteParserLessEqual() {} + TestTfliteParserLessEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./less_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc index 795acfce7d..1872d2d3f1 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_less_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserLess : public TestTfliteParser { public: - TestTfliteParserLess() {} + TestTfliteParserLess() = default; void SetUp() override { meta_graph = LoadAndConvert("./less.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc index fe869019ce..22976eceb8 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_log_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLog : public TestTfliteParser { public: - TestTfliteParserLog() {} + TestTfliteParserLog() = default; void SetUp() override { meta_graph = LoadAndConvert("./log.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc index 415dc874ee..a1a5159ae0 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_and_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteLogicalParserAnd : public TestTfliteParser { public: - TestTfliteLogicalParserAnd() {} + TestTfliteLogicalParserAnd() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_and.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc index a34ae07afe..cb2c21411e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_not_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLogicalNot : public TestTfliteParser { public: - TestTfliteParserLogicalNot() {} + TestTfliteParserLogicalNot() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_not.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc index 19141d6125..508293542f 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_logical_or_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserLogicalOr : public TestTfliteParser { public: - TestTfliteParserLogicalOr() {} + TestTfliteParserLogicalOr() = default; void SetUp() override { meta_graph = LoadAndConvert("./logical_or.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc new file mode 100644 index 0000000000..88a504a6ae --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_lrn_parser_test.cc @@ -0,0 +1,45 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserLRN : public TestTfliteParser { + public: + TestTfliteParserLRN() = default; + void SetUp() override { meta_graph = LoadAndConvert("./lrn.tflite", ""); } +}; + +TEST_F(TestTfliteParserLRN, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, + schema::PrimitiveType_LocalResponseNormalization) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserLRN, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsLocalResponseNormalization(); + ASSERT_EQ(val->alpha, 1); + ASSERT_EQ(val->beta, 0.5); + ASSERT_EQ(val->bias, 1); + ASSERT_EQ(val->depth_radius, 5); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc index a21dba4d8b..b99119df5a 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_maximum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserMaximum : public TestTfliteParser { public: - TestTfliteParserMaximum() {} + TestTfliteParserMaximum() = default; void SetUp() override { meta_graph = LoadAndConvert("./maximum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc index 2999d33b16..431a15e5bd 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_minimum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserMinimum : public TestTfliteParser { public: - TestTfliteParserMinimum() {} + TestTfliteParserMinimum() = default; void SetUp() override { meta_graph = LoadAndConvert("./minimum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc new file mode 100644 index 0000000000..140960e53b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_mul_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserMul1 : public TestTfliteParser { + public: + TestTfliteParserMul1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul1.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserMul2 : public TestTfliteParser { + public: + TestTfliteParserMul2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul2.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserMul3 : public TestTfliteParser { + public: + TestTfliteParserMul3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./mul3.tflite", ""); } +}; + +TEST_F(TestTfliteParserMul3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Mul) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserMul3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc index e7260a1262..3e697c862e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_not_equal_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserNotEqual : public TestTfliteParser { public: - TestTfliteParserNotEqual() {} + TestTfliteParserNotEqual() = default; void SetUp() override { meta_graph = LoadAndConvert("./not_equal.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc index f1f007e849..ed3d946a96 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_one_hot_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserOneHot : public TestTfliteParser { public: - TestTfliteParserOneHot() {} + TestTfliteParserOneHot() = default; void SetUp() override { meta_graph = LoadAndConvert("./one_hot.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc index 11e5fe7c14..7b64cb1d02 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_p_relu_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserPrelu : public TestTfliteParser { public: - TestTfliteParserPrelu() {} + TestTfliteParserPrelu() = default; void SetUp() override { meta_graph = LoadAndConvert("./prelu.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc new file mode 100644 index 0000000000..ada4657759 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pad_parser_test.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserPad : public TestTfliteParser { + public: + TestTfliteParserPad() = default; + void SetUp() override { meta_graph = LoadAndConvert("./pad.tflite", ""); } +}; + +TEST_F(TestTfliteParserPad, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Pad) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserPad, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsPad(); + + std::vector paddings = {1, 1, 2, 2, 3, 3, 4, 4}; + ASSERT_EQ(val->paddings, paddings); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc index 881d95b89f..66ec6ad1ec 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.cc @@ -22,9 +22,12 @@ namespace mindspore { schema::MetaGraphT *TestTfliteParser::LoadAndConvert(const string &model_path, const string &weight_path) { - schema::MetaGraphT *meta_graph = nullptr; lite::TfliteModelParser parser; meta_graph = parser.Parse(model_path, weight_path); + if (meta_graph == nullptr) { + MS_LOG(ERROR) << "Parse to metaGraph return nullptr"; + return nullptr; + } return meta_graph; } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h index cf592570c3..200e322c7c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h @@ -24,10 +24,10 @@ namespace mindspore { class TestTfliteParser : public Common { public: - TestTfliteParser() {} + TestTfliteParser() = default; void TearDown() override; schema::MetaGraphT *LoadAndConvert(const std::string &model_path, const std::string &weight_path = ""); - schema::MetaGraphT *meta_graph; + schema::MetaGraphT *meta_graph = nullptr; }; } // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc new file mode 100644 index 0000000000..52188a5d9b --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_pow_parser_test.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserPow : public TestTfliteParser { + public: + TestTfliteParserPow() = default; + void SetUp() override { meta_graph = LoadAndConvert("./pow.tflite", ""); } +}; + +TEST_F(TestTfliteParserPow, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Power) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserPow, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsPower(); + + ASSERT_EQ(val->scale, 1.0); + ASSERT_EQ(val->shift, 0.0); + ASSERT_EQ(val->power, 0.0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc index 6c2ff57114..8b5c97a3f8 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_max_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceMax : public TestTfliteParser { public: - TestTfliteParserReduceMax() {} + TestTfliteParserReduceMax() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_max.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc index dce6a95fb0..01995e9bba 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_min_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceMin : public TestTfliteParser { public: - TestTfliteParserReduceMin() {} + TestTfliteParserReduceMin() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_min.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc index dc19ad983f..2b0352231f 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reduce_prod_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserReduceProd : public TestTfliteParser { public: - TestTfliteParserReduceProd() {} + TestTfliteParserReduceProd() = default; void SetUp() override { meta_graph = LoadAndConvert("./reduce_prod.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc new file mode 100644 index 0000000000..a0d44c30cd --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_relu_parser_test.cc @@ -0,0 +1,33 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserRelu : public TestTfliteParser { + public: + TestTfliteParserRelu() = default; + void SetUp() override { meta_graph = LoadAndConvert("./relu.tflite", ""); } +}; + +TEST_F(TestTfliteParserRelu, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Activation) << "wrong Op Type"; +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc new file mode 100644 index 0000000000..199c560f13 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_resize_nn_parser_test.cc @@ -0,0 +1,44 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserResizeNN : public TestTfliteParser { + public: + TestTfliteParserResizeNN() = default; + void SetUp() override { meta_graph = LoadAndConvert("./resize_nearest_neighbor.tflite", ""); } +}; + +TEST_F(TestTfliteParserResizeNN, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Resize) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserResizeNN, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsResize(); + + ASSERT_EQ(val->alignCorners, false); + ASSERT_EQ(val->newHeight, 3); + ASSERT_EQ(val->newWidth, 100); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc new file mode 100644 index 0000000000..ea1ffff935 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_parser_test.cc @@ -0,0 +1,43 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserReverse : public TestTfliteParser { + public: + TestTfliteParserReverse() = default; + void SetUp() override { meta_graph = LoadAndConvert("./reverse.tflite", ""); } +}; + +TEST_F(TestTfliteParserReverse, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Reverse) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserReverse, AttrValue) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + + auto val = meta_graph->nodes.front()->primitive->value.AsReverse(); + + std::vector axis = {3}; + ASSERT_EQ(val->axis, axis); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc index f1a972f6e4..a5f3e58d99 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_reverse_sequence_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserReverseSequence : public TestTfliteParser { public: - TestTfliteParserReverseSequence() {} + TestTfliteParserReverseSequence() = default; void SetUp() override { meta_graph = LoadAndConvert("./reverse_sequence.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc index ffb6a26ffe..9ec5ed9b21 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_round_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserRound : public TestTfliteParser { public: - TestTfliteParserRound() {} + TestTfliteParserRound() = default; void SetUp() override { meta_graph = LoadAndConvert("./round.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc index c1db7380cb..9b8afe78b3 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_rsqrt_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserRsqrt : public TestTfliteParser { public: - TestTfliteParserRsqrt() {} + TestTfliteParserRsqrt() = default; void SetUp() override { meta_graph = LoadAndConvert("./rsqrt.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc index a859cabc87..6ad75bb28c 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sin_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSin : public TestTfliteParser { public: - TestTfliteParserSin() {} + TestTfliteParserSin() = default; void SetUp() override { meta_graph = LoadAndConvert("./sin.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc index a9d66ceaf4..dab7110c1a 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSpaceToBatchND : public TestTfliteParser { public: - TestTfliteParserSpaceToBatchND() {} + TestTfliteParserSpaceToBatchND() = default; void SetUp() override { meta_graph = LoadAndConvert("./space_to_batch_nd.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc index 76245204a7..785baff517 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_space_to_depth_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSpaceToDepth : public TestTfliteParser { public: - TestTfliteParserSpaceToDepth() {} + TestTfliteParserSpaceToDepth() = default; void SetUp() override { meta_graph = LoadAndConvert("./space_to_depth.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc index 043fdbfe63..93e7badacf 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sparse_to_dense_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSparseToDense : public TestTfliteParser { public: - TestTfliteParserSparseToDense() {} + TestTfliteParserSparseToDense() = default; void SetUp() override { meta_graph = LoadAndConvert("./sparse_to_dense.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc index aae2b629d1..b7c9e38cb9 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSplit : public TestTfliteParser { public: - TestTfliteParserSplit() {} + TestTfliteParserSplit() = default; void SetUp() override { meta_graph = LoadAndConvert("./split.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc index 30a7049a42..76eb564247 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_split_v_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSplitV : public TestTfliteParser { public: - TestTfliteParserSplitV() {} + TestTfliteParserSplitV() = default; void SetUp() override { meta_graph = LoadAndConvert("./split_v.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc index 427907dc70..e66b0cb938 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sqrt_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSqrt : public TestTfliteParser { public: - TestTfliteParserSqrt() {} + TestTfliteParserSqrt() = default; void SetUp() override { meta_graph = LoadAndConvert("./sqrt.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc index 96e0e71f0c..7bbfeb3eae 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_square_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSquare : public TestTfliteParser { public: - TestTfliteParserSquare() {} + TestTfliteParserSquare() = default; void SetUp() override { meta_graph = LoadAndConvert("./square.tflite", ""); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc index f6be7a992d..74548b4d76 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_squared_difference_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserSquaredDifference : public TestTfliteParser { public: - TestTfliteParserSquaredDifference() {} + TestTfliteParserSquaredDifference() = default; void SetUp() override { meta_graph = LoadAndConvert("./squared_difference.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc index bbb327b998..88177cd9aa 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_strided_slice_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserStridedSlice : public TestTfliteParser { public: - TestTfliteParserStridedSlice() {} + TestTfliteParserStridedSlice() = default; void SetUp() override { meta_graph = LoadAndConvert("./strided_slice.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc new file mode 100644 index 0000000000..3b9c0e26a6 --- /dev/null +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sub_parser_test.cc @@ -0,0 +1,78 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "ut/tools/converter/parser/tflite/tflite_parsers_test_utils.h" +#include +#include "common/common_test.h" + +namespace mindspore { +class TestTfliteParserSub1 : public TestTfliteParser { + public: + TestTfliteParserSub1() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub1.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub1, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub1, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserSub2 : public TestTfliteParser { + public: + TestTfliteParserSub2() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub2.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub2, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub2, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_GT(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +class TestTfliteParserSub3 : public TestTfliteParser { + public: + TestTfliteParserSub3() = default; + void SetUp() override { meta_graph = LoadAndConvert("./sub3.tflite", ""); } +}; + +TEST_F(TestTfliteParserSub3, OpType) { + ASSERT_GT(meta_graph->nodes.size(), 0); + ASSERT_NE(meta_graph->nodes.front()->primitive.get(), nullptr); + ASSERT_EQ(meta_graph->nodes.front()->primitive->value.type, schema::PrimitiveType_Sub) << "wrong Op Type"; +} + +TEST_F(TestTfliteParserSub3, Tensor) { + ASSERT_GT(meta_graph->allTensors.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(0)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(1)->data.size(), 0); + ASSERT_EQ(meta_graph->allTensors.at(2)->data.size(), 0); +} + +} // namespace mindspore diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc index f028516da2..49a5a2f091 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_sum_parser_test.cc @@ -20,7 +20,7 @@ namespace mindspore { class TestTfliteParserSum : public TestTfliteParser { public: - TestTfliteParserSum() {} + TestTfliteParserSum() = default; void SetUp() override { meta_graph = LoadAndConvert("./sum.tflite"); } }; diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc index 19401218f7..e025bad6f9 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_tile_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserTile : public TestTfliteParser { public: - TestTfliteParserTile() {} + TestTfliteParserTile() = default; void SetUp() override { meta_graph = LoadAndConvert("./tile.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc index d358fdb2d5..68e3629611 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_topk_v2_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserTopKV2 : public TestTfliteParser { public: - TestTfliteParserTopKV2() {} + TestTfliteParserTopKV2() = default; void SetUp() override { meta_graph = LoadAndConvert("./topk_v2.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc index 244abf8ee2..5b49883b78 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unique_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserUnique : public TestTfliteParser { public: - TestTfliteParserUnique() {} + TestTfliteParserUnique() = default; void SetUp() override { meta_graph = LoadAndConvert("./unique.tflite"); } diff --git a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc index e2c03a5bec..9c8e59232e 100644 --- a/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc +++ b/mindspore/lite/test/ut/tools/converter/parser/tflite/tflite_unstack_parser_test.cc @@ -21,7 +21,7 @@ namespace mindspore { class TestTfliteParserUnstack : public TestTfliteParser { public: - TestTfliteParserUnstack() {} + TestTfliteParserUnstack() = default; void SetUp() override { meta_graph = LoadAndConvert("./unstack.tflite"); } diff --git a/mindspore/lite/tools/benchmark/benchmark.cc b/mindspore/lite/tools/benchmark/benchmark.cc index c36fe113fd..57f2ed1e5a 100644 --- a/mindspore/lite/tools/benchmark/benchmark.cc +++ b/mindspore/lite/tools/benchmark/benchmark.cc @@ -371,7 +371,7 @@ int Benchmark::RunBenchmark(const std::string &deviceType) { return RET_ERROR; } delete[](graphBuf); - auto context = new(std::nothrow) lite::Context; + auto context = new (std::nothrow) lite::Context; if (context == nullptr) { MS_LOG(ERROR) << "New context failed while running %s", modelName.c_str(); return RET_ERROR; @@ -393,15 +393,16 @@ int Benchmark::RunBenchmark(const std::string &deviceType) { } context->thread_num_ = _flags->numThreads; session = session::LiteSession::CreateSession(context); - delete(context); + delete (context); if (session == nullptr) { MS_LOG(ERROR) << "CreateSession failed while running %s", modelName.c_str(); return RET_ERROR; } - auto ret = session->CompileGraph(model.get()); + auto ret = session->CompileGraph(model); if (ret != RET_OK) { MS_LOG(ERROR) << "CompileGraph failed while running %s", modelName.c_str(); - delete(session); + delete (session); + delete (model); return ret; } msInputs = session->GetInputs(); @@ -419,21 +420,24 @@ int Benchmark::RunBenchmark(const std::string &deviceType) { auto status = LoadInput(); if (status != 0) { MS_LOG(ERROR) << "Generate input data error"; - delete(session); + delete (session); + delete (model); return status; } if (!_flags->calibDataPath.empty()) { status = MarkAccuracy(); if (status != 0) { MS_LOG(ERROR) << "Run MarkAccuracy error: %d" << status; - delete(session); + delete (session); + delete (model); return status; } } else { status = MarkPerformance(); if (status != 0) { MS_LOG(ERROR) << "Run MarkPerformance error: %d" << status; - delete(session); + delete (session); + delete (model); return status; } } @@ -447,7 +451,8 @@ int Benchmark::RunBenchmark(const std::string &deviceType) { calibData.clear(); } - delete(session); + delete (session); + delete (model); return RET_OK; } diff --git a/mindspore/lite/tools/common/node_util.cc b/mindspore/lite/tools/common/node_util.cc index 2f3312a8cb..16c146052e 100644 --- a/mindspore/lite/tools/common/node_util.cc +++ b/mindspore/lite/tools/common/node_util.cc @@ -96,7 +96,7 @@ static const std::vector nhwcOpList = { schema::PrimitiveType_Conv2D, schema::PrimitiveType_DeConv2D, schema::PrimitiveType_DepthwiseConv2D, schema::PrimitiveType_DeDepthwiseConv2D, schema::PrimitiveType_Pooling, schema::PrimitiveType_Resize, - schema::PrimitiveType_FusedBatchNorm}; + schema::PrimitiveType_BatchNorm}; static const std::vector fp32FullOpList = { schema::PrimitiveType_Concat, schema::PrimitiveType_Add, diff --git a/mindspore/lite/tools/converter/converter.cc b/mindspore/lite/tools/converter/converter.cc index 3f3f5a03a3..87ab8a9910 100644 --- a/mindspore/lite/tools/converter/converter.cc +++ b/mindspore/lite/tools/converter/converter.cc @@ -90,7 +90,7 @@ MetaGraphT *Converter::Convert(const converter::Flags *flag) { return nullptr; } - // graph = anfTransform->Transform(graph); + graph = anfTransform->Transform(graph); CreateQuantizer(graph, flag); if (mQuantizer != nullptr) { diff --git a/mindspore/lite/tools/converter/graphdef_transform.cc b/mindspore/lite/tools/converter/graphdef_transform.cc index ec92083597..d0240ed9f3 100644 --- a/mindspore/lite/tools/converter/graphdef_transform.cc +++ b/mindspore/lite/tools/converter/graphdef_transform.cc @@ -100,20 +100,20 @@ int GraphDefTransform::Transform(const converter::Flags &ctx) { // } // fusion - { - Optimizer fusionOptimizer; - fusionOptimizer.AddPass(new (std::nothrow) ConvBiasAddFusionPass()); - fusionOptimizer.AddPass(new (std::nothrow) ConvBNFusionPass()); - fusionOptimizer.AddPass(new (std::nothrow) ConvScaleFusionPass()); - fusionOptimizer.AddPass(new (std::nothrow) ConvReluFusionPass()); - fusionOptimizer.AddPass(new (std::nothrow) ConvRelu6FusionPass()); - fusionOptimizer.AddPass(new (std::nothrow) IsolatedNodeRemovePass()); - status = fusionOptimizer.Run(graphDefT); - if (status != RET_OK && status != RET_NO_CHANGE) { - MS_LOG(ERROR) << "Run fusionOptimizer graphPasses Failed"; - return status; - } - } + // { + // Optimizer fusionOptimizer; + // fusionOptimizer.AddPass(new (std::nothrow) ConvBiasAddFusionPass()); + // fusionOptimizer.AddPass(new (std::nothrow) ConvBNFusionPass()); + // fusionOptimizer.AddPass(new (std::nothrow) ConvScaleFusionPass()); + // fusionOptimizer.AddPass(new (std::nothrow) ConvReluFusionPass()); + // fusionOptimizer.AddPass(new (std::nothrow) ConvRelu6FusionPass()); + // fusionOptimizer.AddPass(new (std::nothrow) IsolatedNodeRemovePass()); + // status = fusionOptimizer.Run(graphDefT); + // if (status != RET_OK && status != RET_NO_CHANGE) { + // MS_LOG(ERROR) << "Run fusionOptimizer graphPasses Failed"; + // return status; + // } + // } // weight format trans if (ctx.formatTrans) { diff --git a/mindspore/lite/tools/converter/legacy_optimizer/fusion/format_trans_fusion_pass.cc b/mindspore/lite/tools/converter/legacy_optimizer/fusion/format_trans_fusion_pass.cc index 156c79103a..edad265bff 100644 --- a/mindspore/lite/tools/converter/legacy_optimizer/fusion/format_trans_fusion_pass.cc +++ b/mindspore/lite/tools/converter/legacy_optimizer/fusion/format_trans_fusion_pass.cc @@ -149,8 +149,14 @@ STATUS FormatTransFusionPass::DoFusion(schema::MetaGraphT *graph, const std::str } else { MS_ASSERT(false); } - MS_ASSERT(srcPath != nullptr); - MS_ASSERT(dstPath != nullptr); + if (srcPath == nullptr) { + MS_LOG(ERROR) << "srcPath is failed to get"; + return RET_ERROR; + } + if (dstPath == nullptr) { + MS_LOG(ERROR) << "dstPath is failed to get"; + return RET_ERROR; + } auto srcNode = graph->nodes.at(srcPath->nodeIdx).get(); auto dstNode = graph->nodes.at(dstPath->nodeIdx).get(); MS_ASSERT(srcNode != nullptr); diff --git a/mindspore/lite/tools/converter/legacy_optimizer/node/weight_format_pass.cc b/mindspore/lite/tools/converter/legacy_optimizer/node/weight_format_pass.cc index 5432f58ae3..2e894a24f4 100644 --- a/mindspore/lite/tools/converter/legacy_optimizer/node/weight_format_pass.cc +++ b/mindspore/lite/tools/converter/legacy_optimizer/node/weight_format_pass.cc @@ -50,7 +50,7 @@ void WeightFormatPass::SetFmkType(converter::FmkType fmkType) { this->fmkType = // pre set tensor format // non quant, filterFormat: // conv deconv depth dedepth -// caffe K(C/g)HW C(K/g)HW / / // todo with deconvOp +// caffe K(C/g)HW C(K/g)HW / / // tf HWCK HWKC HWCK HWKC // onnx K(C/g)HW C(K/g)HW / / @@ -78,7 +78,8 @@ int WeightFormatPass::ShapeFormatTrans(GraphNode *graphNode) { if (fmkType == converter::FmkType_CAFFE) { switch (node->quantType) { case QuantType_QUANT_NONE: { - if (opType == schema::PrimitiveType_Conv2D || opType == schema::PrimitiveType_DepthwiseConv2D) { + if (opType == schema::PrimitiveType_Conv2D || opType == schema::PrimitiveType_DepthwiseConv2D || + opType == schema::PrimitiveType_DeConv2D || opType == schema::PrimitiveType_DeDepthwiseConv2D) { weightTensor->format = schema::Format_KCHW; } else { MS_LOG(ERROR) << "Invalid opType: " << schema::EnumNamePrimitiveType(opType) @@ -165,6 +166,7 @@ int WeightFormatPass::ShapeFormatTrans(GraphNode *graphNode) { return -1; } } + MS_LOG(DEBUG) << "weight_tensor_format: " << weightTensor->format; return 0; } else if (fmkType == converter::FmkType_ONNX) { switch (node->quantType) { @@ -216,7 +218,7 @@ int WeightFormatPass::QuantDataFormatTrans(GraphNode *graphNode) { auto opType = node->primitive->value.type; if (opType != schema::PrimitiveType_Conv2D && opType != schema::PrimitiveType_DepthwiseConv2D && opType != schema::PrimitiveType_DeConv2D && opType != schema::PrimitiveType_DeDepthwiseConv2D) { - return 0; + return RET_OK; } MS_ASSERT(node->inputIndex.size() >= 2); @@ -224,10 +226,10 @@ int WeightFormatPass::QuantDataFormatTrans(GraphNode *graphNode) { MS_ASSERT(subGraph->allTensors.size() > weightIndex); auto &weightTensor = subGraph->allTensors[weightIndex]; MS_ASSERT(weightTensor->dataType == kNumberTypeInt8); // DataType_DT_FLOAT - STATUS status; + STATUS status = RET_OK; if (opType == schema::PrimitiveType_Conv2D) { // weight should be HWCK if (weightTensor->format == schema::Format_KCHW) { // from caffe - if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { + if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { MS_LOG(DEBUG) << "**weight tensor index: %d, format: %d, datatype: " << weightIndex << weightTensor->format << weightTensor->dataType; status = TransFilterFormat(weightTensor.get(), kKCHW2HWCK); @@ -237,11 +239,12 @@ int WeightFormatPass::QuantDataFormatTrans(GraphNode *graphNode) { status = TransFilterFormat(weightTensor.get(), kKCHW2HWCK); } } else if (weightTensor->format == schema::Format_KHWC) { // from onnx - if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { - status = TransFilterFormat(weightTensor.get(), kKHWC2HWCK); - } else { - status = TransFilterFormat(weightTensor.get(), kKHWC2HWCK); - } + return RET_OK; + // if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { + // status = TransFilterFormat(weightTensor.get(), kKHWC2HWCK); + // } else { + // status = TransFilterFormat(weightTensor.get(), kKHWC2HWCK); + // } } else if (weightTensor->format == schema::Format_HWCK) { // from tf return 0; } else { @@ -259,7 +262,7 @@ int WeightFormatPass::QuantDataFormatTrans(GraphNode *graphNode) { } } else if (opType == schema::PrimitiveType_DepthwiseConv2D) { // weight should be HWCK if (weightTensor->format == schema::Format_CKHW) { // from caffe - if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { + if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { MS_LOG(DEBUG) << "**weight tensor index: %d, format: %d, datatype: " << weightIndex, weightTensor->format, weightTensor->dataType; status = TransFilterFormat(weightTensor.get(), kCKHW2HWCK); @@ -272,13 +275,13 @@ int WeightFormatPass::QuantDataFormatTrans(GraphNode *graphNode) { } else if (weightTensor->format == schema::Format_HWCK) { // from tf return 0; } else if (weightTensor->format == schema::Format_CHWK) { // from onnx - if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { - status = TransFilterFormat(weightTensor.get(), kCHWK2HWCK); + if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { + status = TransFilterFormat(weightTensor.get(), kCHWK2KHWC); } else { status = TransFilterFormat(weightTensor.get(), kCHWK2HWCK); } } else if (weightTensor->format == schema::Format_KCHW) { - if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { + if (weightTensor->dataType == kNumberTypeInt8) { // DataType_DT_UINT8) { status = TransFilterFormat(weightTensor.get(), kKCHW2HWCK); } else { status = TransFilterFormat(weightTensor.get(), kKCHW2HWCK); @@ -365,7 +368,7 @@ int WeightFormatPass::NonQuantDataFormatTrans(GraphNode *graphNode) { // todo(00445839): consider varible weight condition } } else if (opType == schema::PrimitiveType_DeConv2D) { // weight should be KHWC - if (weightTensor->format == schema::Format_KCHW) { // from caffe or onnx or ms + if (weightTensor->format == schema::Format_KCHW) { // from caffe or onnx or ms status = TransFilterFormat(weightTensor.get(), kKCHW2KHWC); } else if (weightTensor->format == schema::Format_CHWK) { // from tf status = TransFilterFormat(weightTensor.get(), kCHWK2KHWC); @@ -380,9 +383,11 @@ int WeightFormatPass::NonQuantDataFormatTrans(GraphNode *graphNode) { MS_LOG(WARNING) << "TransFilter HWKCToKCHW failed, node : " << node->name.c_str(); // todo(00445839): consider varible weight condition } - } else if (opType == schema::PrimitiveType_DeDepthwiseConv2D) { // weight should be CKHW - if (weightTensor->format == schema::Format_CKHW) { // from caffe + } else if (opType == schema::PrimitiveType_DeDepthwiseConv2D) { // weight should be KHWC + if (weightTensor->format == schema::Format_KHWC) { return 0; + } else if (weightTensor->format == schema::Format_KCHW) { // from caffe + status = TransFilterFormat(weightTensor.get(), kKCHW2KHWC); } else if (weightTensor->format == schema::Format_HWKC) { // from tf or onnx status = TransFilterFormat(weightTensor.get(), kHWKC2CKHW); } else { @@ -390,7 +395,7 @@ int WeightFormatPass::NonQuantDataFormatTrans(GraphNode *graphNode) { return -1; } if (status == 0) { - node->primitive->value.AsDepthwiseConv2D()->format = schema::Format_NHWC; + node->primitive->value.AsDeDepthwiseConv2D()->format = schema::Format_NHWC; weightTensor->format = schema::Format_CKHW; } else { MS_LOG(WARNING) << "TransFilter HWKCToCKHW failed, node : " << node->name.c_str(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc index 5c622f13d0..17b657143e 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_convolution_parser.cc @@ -20,7 +20,7 @@ namespace mindspore { namespace lite { void CaffeConvolutionParser::ParseGroupConvolution(schema::CNodeT *op, schema::Conv2DT *attr) { - if (attr == nullptr || attr->group == 1 || attr->group != attr->channelOut) { + if (attr == nullptr || attr->group == 1) { return; } std::unique_ptr depthwiseConv2DParam(new schema::DepthwiseConv2DT()); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc index be9682f2fd..d461ceb5fa 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_deconvolution_parser.cc @@ -20,7 +20,7 @@ namespace mindspore { namespace lite { void CaffeDeconvolutionParser::ParseGroupDeconvolution(schema::CNodeT *op, schema::DeConv2DT *attr) { - if (attr == nullptr || attr->group == 1 || attr->group != attr->channelIn) { + if (attr == nullptr || attr->group == 1) { return; } @@ -46,14 +46,13 @@ void CaffeDeconvolutionParser::ParseGroupDeconvolution(schema::CNodeT *op, schem deDepthwiseConv2DParam->hasBias = attr->hasBias; deDepthwiseConv2DParam->activationType = attr->activationType; delete attr; - op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_DeDepthwiseConv2D; op->primitive->value.value = deDepthwiseConv2DParam.release(); } STATUS CaffeDeconvolutionParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, std::vector *weightVec) { op->name = proto.name(); - schema::DeConv2DT *attr = new schema::DeConv2DT(); + auto *attr = new schema::DeConv2DT(); attr->format = schema::Format_NCHW; const caffe::ConvolutionParameter convParam = proto.convolution_param(); diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.cc new file mode 100644 index 0000000000..9eb1f05095 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.cc @@ -0,0 +1,38 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include "mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.h" + +namespace mindspore { +namespace lite { +STATUS CaffeFlattenParser::Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, + schema::CNodeT *op, std::vector *weightVec) { + if (op == nullptr) { + // MS_LOGE("null pointer dereferencing."); + return RET_NULL_PTR; + } + std::unique_ptr attr(new schema::ReshapeT()); + attr->format = schema::Format_NCHW; + + op->primitive = std::make_unique(); + op->primitive->value.type = schema::PrimitiveType_Flatten; + op->primitive->value.value = attr.release(); + return RET_OK; +} + +CaffeNodeRegistrar g_CaffeFlattenParser("Flatten", new CaffeFlattenParser()); +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.h b/mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.h new file mode 100644 index 0000000000..249fc62541 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_flatten_parser.h @@ -0,0 +1,36 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 PREDICT_CONVERTER_PARSER_CAFFE_CAFFE_FLATTEN_PARSER_H_ +#define PREDICT_CONVERTER_PARSER_CAFFE_CAFFE_FLATTEN_PARSER_H_ + +#include +#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser.h" +#include "mindspore/lite/tools/converter/parser/caffe/caffe_node_parser_registry.h" + +namespace mindspore { +namespace lite { +class CaffeFlattenParser : public CaffeNodeParser { + public: + CaffeFlattenParser() : CaffeNodeParser("flatten") {} + + STATUS Parse(const caffe::LayerParameter &proto, const caffe::LayerParameter &weight, schema::CNodeT *op, + std::vector *weightVec) override; +}; +} // namespace lite +} // namespace mindspore + +#endif // PREDICT_CONVERTER_PARSER_CAFFE_CAFFE_FLATTEN_PARSER_H_ diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc index c80dd6b21d..0dbe2927a9 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_pooling_parser.cc @@ -56,6 +56,8 @@ STATUS CaffePoolingParser::Parse(const caffe::LayerParameter &proto, return RET_ERROR; } + // default roundMode RoundMode_CEIL + attr->roundMode = schema::RoundMode_CEIL; if (poolingParam.has_round_mode()) { if (poolingParam.round_mode() == caffe::PoolingParameter_RoundMode_FLOOR) { attr->roundMode = schema::RoundMode_FLOOR; diff --git a/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc b/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc index 49ea560a5d..65e5710257 100644 --- a/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc +++ b/mindspore/lite/tools/converter/parser/caffe/caffe_relu_parser.cc @@ -25,22 +25,18 @@ STATUS CaffeReluParser::Parse(const caffe::LayerParameter &proto, std::vector *weightVec) { std::unique_ptr attr(new schema::ActivationT()); attr->type = schema::ActivationType_RELU; - op->primitive = std::make_unique(); - op->primitive->value.value = attr.release(); - op->primitive->value.type = schema::PrimitiveType_Activation; // relu: negative_slope = 0, no parameter; // leakyrelu: negative_slope != 0; if (proto.has_relu_param() && proto.relu_param().has_negative_slope()) { float negative_slope = proto.relu_param().negative_slope(); - if (0 != negative_slope) { - std::unique_ptr attrLeakyReLu(new schema::LeakyReLUT()); - attrLeakyReLu->negativeSlope = negative_slope; - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_LeakyReLU; - op->primitive->value.value = attrLeakyReLu.release(); + attr->type = schema::ActivationType_LEAKY_RELU; + attr->alpha = negative_slope; } } + op->primitive = std::make_unique(); + op->primitive->value.value = attr.release(); + op->primitive->value.type = schema::PrimitiveType_Activation; return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc b/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc index 2f06beb0a5..103c234ec9 100755 --- a/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/onnx/onnx_model_parser.cc @@ -47,7 +47,6 @@ TypeId OnnxModelParser::GetDateTypeFromOnnx(onnx::TensorProto_DataType onnx_type std::vector OnnxModelParser::GetDimsFromOnnxValue(const onnx::ValueInfoProto &onnx_value) { std::vector dims; - const auto shape_info = onnx_value.type().tensor_type().shape(); for (const auto &it : onnx_value.type().tensor_type().shape().dim()) { dims.emplace_back(it.dim_value()); } @@ -97,7 +96,7 @@ STATUS OnnxModelParser::SetGraphConstTensor(const onnx::GraphProto &onnx_graph, if (CopyOnnxTensorData(onnx_const_value, tensor.get())) { return RET_ERROR; } - const auto index = tensor_cache->AddTensor(onnx_const_value.name(), tensor.release(), GRAPH_INPUT); + // const auto index = tensor_cache->AddTensor(onnx_const_value.name(), tensor.release(), GRAPH_INPUT); // MS_LOGD("add const tensor: %s, index %d", onnx_const_value.name().c_str(), index) } return RET_OK; @@ -290,11 +289,6 @@ void OnnxModelParser::SetOpQuantParams(const onnx::GraphProto &onnx_graph, const // MS_LOGE("new QuantParamT failed, node: %s", dst_op->name.c_str()); return; } - // std::unique_ptr quant_param_array(new (std::nothrow) QuantParamArrayT()); - if (quant_param == nullptr) { - // MS_LOGE("new QuantParamArrayT failed, node: %s", dst_op->name.c_str()); - return; - } int argNum = 0; for (const auto &onnx_node_attr : node.attribute()) { if (onnx_node_attr.name() == "Y_scale") { diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc deleted file mode 100644 index 2ec1f0257d..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_abs_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteAbsParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteAbsParser"; - std::unique_ptr attr(new schema::AbsT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Abs; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteAbsParser("Abs", new TfliteAbsParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.h deleted file mode 100644 index 7d4493f954..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_abs_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_ABS_PARSER_H -#define PREDICT_TFLITE_ABS_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteAbsParser : public TfliteNodeParser { - public: - TfliteAbsParser() : TfliteNodeParser("Abs") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_ABS_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.cc new file mode 100644 index 0000000000..e6032f4bc3 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.cc @@ -0,0 +1,133 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include +#include +#include "tools/converter/parser/tflite/tflite_activation_parser.h" + +namespace mindspore { +namespace lite { +STATUS TfliteActivationParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::unique_ptr attr(new schema::ActivationT()); + + std::vector node_name_str; + Split(op->name, &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + + if (std::strcmp(node_name, "Relu") == 0) { + MS_LOG(DEBUG) << "parse TfliteReluParser"; + attr->type = schema::ActivationType_RELU; + } else if (std::strcmp(node_name, "Relu6") == 0) { + MS_LOG(DEBUG) << "parse TfliteRelu6Parser"; + attr->type = schema::ActivationType_RELU6; + } else if (std::strcmp(node_name, "Tanh") == 0) { + MS_LOG(DEBUG) << "parse TfliteTanhParser"; + attr->type = schema::ActivationType_TANH; + } else if (std::strcmp(node_name, "Logistic") == 0) { + MS_LOG(DEBUG) << "parse TfliteLogisticParser"; + attr->type = schema::ActivationType_SIGMOID; + } else { + MS_LOG(ERROR) << "wrong activation type"; + return RET_ERROR; + } + + op->primitive->value.type = schema::PrimitiveType_Activation; + op->primitive->value.value = attr.release(); + return RET_OK; +} + +STATUS TflitePreluParser::Parse(const std::unique_ptr &tflite_op, + const std::vector> &tflite_tensors, + const std::vector> &tflite_model_buffer, + const std::vector> &tflite_opset, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + MS_LOG(DEBUG) << "paser TflitePreluParser"; + std::unique_ptr attr(new schema::PreluT()); + + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->slope)) { + MS_LOG(ERROR) << "get pRelu -> slope failed"; + return RET_ERROR; + } + + op->primitive->value.type = schema::PrimitiveType_Prelu; + op->primitive->value.value = attr.release(); + return RET_OK; +} + +STATUS TfliteLeakyReluParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + MS_LOG(DEBUG) << "parse TfliteLeakyReluParser"; + std::unique_ptr attr(new schema::LeakyReLUT()); + + const auto &tflite_attr = tfliteOp->builtin_options.AsLeakyReluOptions(); + if (tflite_attr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->negativeSlope = tflite_attr->alpha; + + op->primitive->value.type = schema::PrimitiveType_LeakyReLU; + op->primitive->value.value = attr.release(); + return RET_OK; +} + +TfliteNodeRegister g_TfliteReluParser("Relu", new TfliteReluParser()); +TfliteNodeRegister g_TfliteRelu6Parser("Relu6", new TfliteRelu6Parser()); +TfliteNodeRegister g_TfliteTanhParser("Tanh", new TfliteTanhParser()); +TfliteNodeRegister g_tfliteLogisticParser("Logistic", new TfliteLogisticParser()); +TfliteNodeRegister g_tflitePreluParser("Prelu", new TflitePreluParser()); +TfliteNodeRegister g_TfliteLeakyReluParser("LeakyRelu", new TfliteLeakyReluParser()); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.h new file mode 100644 index 0000000000..5695e1cc1d --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_activation_parser.h @@ -0,0 +1,85 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 PREDICT_TFLITE_RELU_PARSER_H +#define PREDICT_TFLITE_RELU_PARSER_H + +#include "tools/converter/parser/tflite/tflite_node_parser.h" +#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" +#include +#include + +namespace mindspore { +namespace lite { + +class TfliteActivationParser : public TfliteNodeParser { + public: + TfliteActivationParser() : TfliteNodeParser("node_name") {} + + STATUS Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, schema::CNodeT *op, + TensorCache *tensor_cache, bool quantizedModel) override; +}; + +class TfliteReluParser : public TfliteActivationParser { + public: + TfliteReluParser() : TfliteActivationParser() {} +}; + +class TfliteRelu6Parser : public TfliteActivationParser{ + public: + TfliteRelu6Parser() : TfliteActivationParser() {} +}; + +class TfliteTanhParser : public TfliteActivationParser{ + public: + TfliteTanhParser() : TfliteActivationParser() {} +}; + +class TfliteLogisticParser : public TfliteActivationParser { + public: + TfliteLogisticParser() : TfliteActivationParser() {} +}; + +class TflitePreluParser : public TfliteNodeParser { + public: + TflitePreluParser() : TfliteNodeParser("Prelu") {} + + STATUS Parse(const std::unique_ptr &tflite_op, + const std::vector> &tflite_tensors, + const std::vector> &tflite_model_buffer, + const std::vector> &tflite_opset, schema::CNodeT *op, + TensorCache *tensor_cache, bool quantized_model) override; +}; + +class TfliteLeakyReluParser : public TfliteNodeParser { + public: + TfliteLeakyReluParser() : TfliteNodeParser("LeakyRelu") {} + + STATUS Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, schema::CNodeT *op, + TensorCache *tensor_cache, bool quantizedModel) override; +}; + +} // namespace lite +} // namespace mindspore + +#endif // PREDICT_TFLITE_RELU_PARSER_H + diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc deleted file mode 100644 index 3981b4b6ae..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.cc +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include "tools/converter/parser/tflite/tflite_add_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteAddParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteAddParser"; - std::unique_ptr attr(new schema::AddT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsAddOptions(); - if (nullptr == tfliteAttr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - return RET_ERROR; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Add; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteAddParser("Add", new TfliteAddParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.h deleted file mode 100644 index cb5c04d1f8..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_add_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_ADD_PARSER_H -#define PREDICT_TFLITE_ADD_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteAddParser : public TfliteNodeParser { - public: - TfliteAddParser() : TfliteNodeParser("Add") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_ADD_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc index 5dc9ee5bfd..cf518ceafb 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_addn_parser.cc @@ -15,27 +15,34 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_addn_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_addn_parser.h" namespace mindspore { namespace lite { -STATUS TfliteAddNParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) { +STATUS TfliteAddNParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteAddNParser"; std::unique_ptr attr(new schema::AddNT()); - attr->N = tflite_tensors.size() - 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_AddN; - op->primitive->value.value = attr.release(); - } + + attr->N = tfliteTensors.size() - 1; + + op->primitive->value.type = schema::PrimitiveType_AddN; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc index 30706902b8..b3fe114303 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmax_parser.cc @@ -27,19 +27,40 @@ STATUS TfliteArgmaxParser::Parse(const std::unique_ptr &tflit schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteArgmaxParser"; std::unique_ptr attr(new schema::ArgMaxT()); - // These are caffe attributes, set to default value. - attr->axisType = 1; + attr->outMaxValue = false; attr->topK = 1; attr->keepDims = false; + attr->axisType = 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_ArgMax; - op->primitive->value.value = attr.release(); + auto axis_idx = tfliteOp->inputs[1]; + std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); + auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; + if (buf_data == nullptr) { + MS_LOG(ERROR) << "the buf data is null"; + return RET_NULL_PTR; } + auto data_ptr = buf_data->data.data(); + if (data_ptr == nullptr) { + MS_LOG(ERROR) << "the data is null"; + return RET_NULL_PTR; + } + attr->axis = *(static_cast(static_cast(data_ptr))); + + op->primitive->value.type = schema::PrimitiveType_ArgMax; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc index 2ff86ae045..37a47c0ea3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_argmin_parser.cc @@ -24,34 +24,41 @@ STATUS TfliteArgminParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteArgminParser"; - std::unique_ptr attr(new schema::ArgMinT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsArgMinOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; } - // get axis - auto axis_idx = tfliteOp->inputs[1]; - std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); - auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; - auto data_ptr = buf_data->data.data(); - attr->axis = *(static_cast(static_cast(data_ptr))); + MS_LOG(DEBUG) << "parse TfliteArgminParser"; + std::unique_ptr attr(new schema::ArgMinT()); - // the following use default values attr->outMaxValue = false; attr->topK = 1; attr->keepDims = false; - attr->axisType = 0; + attr->axisType = 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_ArgMin; - op->primitive->value.value = attr.release(); + auto axis_idx = tfliteOp->inputs[1]; + std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); + auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; + if (buf_data == nullptr) { + MS_LOG(ERROR) << "the buf data is null"; + return RET_NULL_PTR; } + auto data_ptr = buf_data->data.data(); + if (data_ptr == nullptr) { + MS_LOG(ERROR) << "the data is null"; + return RET_NULL_PTR; + } + attr->axis = *(static_cast(static_cast(data_ptr))); + + op->primitive->value.type = schema::PrimitiveType_ArgMin; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.cc new file mode 100644 index 0000000000..8a5a16ccf7 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.cc @@ -0,0 +1,370 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include "tools/converter/parser/tflite/tflite_arithmetic_parser.h" +#include +#include +#include + +namespace mindspore { +namespace lite { +STATUS TfliteDoubleInputOpParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + + if (std::strcmp(node_name, "Add") == 0 + || std::strcmp(node_name, "Sub") == 0 + || std::strcmp(node_name, "Mul") == 0 + || std::strcmp(node_name, "Div") == 0) { + auto x_index = tfliteOp->inputs[0]; + const auto &x_tensor = tfliteTensors[x_index]; + if (x_tensor == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; + } + auto &x_data = tfliteModelBuffer.at(x_tensor->buffer); + if (x_data == nullptr) { + MS_LOG(ERROR) << "the data of the first input is null"; + return RET_NULL_PTR; + } + if (!x_data->data.empty()) { + std::vector x_tensors{x_tensor.get()}; + if (RET_OK != ParseTensor(x_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { + MS_LOG(ERROR) << "parse the first tensor failed"; + return RET_ERROR; + } + } + + auto y_index = tfliteOp->inputs[1]; + const auto &y_tensor = tfliteTensors[y_index]; + if (y_tensor == nullptr) { + MS_LOG(ERROR) << "the second input is null"; + return RET_NULL_PTR; + } + auto &y_data = tfliteModelBuffer.at(y_tensor->buffer); + if (y_data == nullptr) { + MS_LOG(ERROR) << "the data of the second input is null"; + return RET_NULL_PTR; + } + if (!y_data->data.empty()) { + std::vector y_tensors{y_tensor.get()}; + if (RET_OK != ParseTensor(y_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { + MS_LOG(ERROR) << "parse the second tensor failed"; + return RET_ERROR; + } + } + + if (std::strcmp(node_name, "Add") == 0) { + MS_LOG(DEBUG) << "parse TfliteAddParser"; + std::unique_ptr attr(new schema::AddT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsAddOptions(); + if (nullptr == tfliteAttr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + op->primitive->value.type = schema::PrimitiveType_Add; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Sub") == 0) { + MS_LOG(DEBUG) << "parse TfliteSubParser"; + std::unique_ptr attr(new schema::SubT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsSubOptions(); + if (nullptr == tfliteAttr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + op->primitive->value.type = schema::PrimitiveType_Sub; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Mul") == 0) { + MS_LOG(DEBUG) << "parse TfliteMulParser"; + std::unique_ptr attr(new schema::MulT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsMulOptions(); + if (nullptr == tfliteAttr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + op->primitive->value.type = schema::PrimitiveType_Mul; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Div") == 0) { + MS_LOG(DEBUG) << "parse TfliteDivParser"; + std::unique_ptr attr(new schema::DivT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsDivOptions(); + if (nullptr == tfliteAttr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); + op->primitive->value.type = schema::PrimitiveType_Div; + op->primitive->value.value = attr.release(); + return RET_OK; + } + } else if (std::strcmp(node_name, "FloorDiv") == 0) { + MS_LOG(DEBUG) << "parse TfliteFloorDivParser"; + std::unique_ptr attr(new schema::FloorDivT()); + op->primitive->value.type = schema::PrimitiveType_FloorDiv; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "FloorMod") == 0) { + MS_LOG(DEBUG) << "parse TfliteFloorModParser"; + std::unique_ptr attr(new schema::FloorModT()); + op->primitive->value.type = schema::PrimitiveType_FloorMod; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "RealDiv") == 0) { + MS_LOG(DEBUG) << "parse TfliteRealDivParser"; + std::unique_ptr attr(new schema::RealDivT()); + op->primitive->value.type = schema::PrimitiveType_RealDiv; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "SquaredDifference") == 0) { + MS_LOG(DEBUG) << "parse TfliteSquaredDifferenceParser"; + std::unique_ptr attr(new schema::SquaredDifferenceT()); + op->primitive->value.type = schema::PrimitiveType_SquaredDifference; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Pow") == 0) { + MS_LOG(DEBUG) << "parse TflitePowParser"; + std::unique_ptr attr(new schema::PowerT()); + attr->power = 0.0f; + attr->scale = 1.0f; + attr->shift = 0.0f; + op->primitive->value.type = schema::PrimitiveType_Power; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Maximum") == 0) { + MS_LOG(DEBUG) << "parse TfliteMaximumParser"; + std::unique_ptr attr(new schema::MaximumT()); + op->primitive->value.type = schema::PrimitiveType_Maximum; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Minimum") == 0) { + MS_LOG(DEBUG) << "parse TfliteMinimumParser"; + std::unique_ptr attr(new schema::MinimumT()); + op->primitive->value.type = schema::PrimitiveType_Minimum; + op->primitive->value.value = attr.release(); + return RET_OK; + } else { + MS_LOG(ERROR) << "wrong op type"; + return RET_ERROR; + } + return RET_OK; +} + +STATUS TfliteSingleInputOpParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + if (std::strcmp(node_name, "Abs") == 0) { + MS_LOG(DEBUG) << "parse TfliteAbsParser"; + std::unique_ptr attr(new schema::AbsT()); + op->primitive->value.type = schema::PrimitiveType_Abs; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Exp") == 0) { + MS_LOG(DEBUG) << "parse TfliteExpParser"; + std::unique_ptr attr(new schema::ExpT()); + op->primitive->value.type = schema::PrimitiveType_Exp; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Sqrt") == 0) { + MS_LOG(DEBUG) << "parse TfliteSqrtParser"; + std::unique_ptr attr(new schema::SqrtT()); + op->primitive->value.type = schema::PrimitiveType_Sqrt; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Rsqrt") == 0) { + MS_LOG(DEBUG) << "parse TfliteRsqrtParser"; + std::unique_ptr attr(new schema::RsqrtT()); + op->primitive->value.type = schema::PrimitiveType_Rsqrt; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Square") == 0) { + MS_LOG(DEBUG) << "parse TfliteSquareParser"; + std::unique_ptr attr(new schema::SquareT()); + op->primitive->value.type = schema::PrimitiveType_Square; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Sin") == 0) { + MS_LOG(DEBUG) << "parse TfliteSinParser"; + std::unique_ptr attr(new schema::SinT()); + op->primitive->value.type = schema::PrimitiveType_Sin; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Cos") == 0) { + MS_LOG(DEBUG) << "parse TfliteCosParser"; + std::unique_ptr attr(new schema::CosT()); + op->primitive->value.type = schema::PrimitiveType_Cos; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Log") == 0) { + MS_LOG(DEBUG) << "parse TfliteLogParser"; + std::unique_ptr attr(new schema::LogT()); + op->primitive->value.type = schema::PrimitiveType_Log; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Round") == 0) { + MS_LOG(DEBUG) << "parse TfliteRoundParser"; + std::unique_ptr attr(new schema::RoundT()); + op->primitive->value.type = schema::PrimitiveType_Round; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Ceil") == 0) { + MS_LOG(DEBUG) << "parse TfliteCeilParser"; + std::unique_ptr attr(new schema::CeilT()); + op->primitive->value.type = schema::PrimitiveType_Ceil; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "flOOR") == 0) { + MS_LOG(DEBUG) << "parse TfliteFloorParser"; + std::unique_ptr attr(new schema::FloorT()); + op->primitive->value.type = schema::PrimitiveType_Floor; + op->primitive->value.value = attr.release(); + return RET_OK; + } else { + MS_LOG(ERROR) << "wrong op type"; + return RET_ERROR; + } +} + +STATUS TfliteCompareOpParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + if (std::strcmp(node_name, "Equal") == 0) { + MS_LOG(DEBUG) << "parse TfliteEqualParser"; + std::unique_ptr attr(new schema::EqualT()); + op->primitive->value.type = schema::PrimitiveType_Equal; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "NotEqual") == 0) { + MS_LOG(DEBUG) << "parse TfliteNotEqualParser"; + std::unique_ptr attr(new schema::NotEqualT()); + op->primitive->value.type = schema::PrimitiveType_NotEqual; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Greater") == 0) { + MS_LOG(DEBUG) << "parse TfliteGreaterParser"; + std::unique_ptr attr(new schema::GreaterT()); + op->primitive->value.type = schema::PrimitiveType_Greater; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "GreaterEqual") == 0) { + MS_LOG(DEBUG) << "parse TfliteGreaterEqualParser"; + std::unique_ptr attr(new schema::GreaterEqualT()); + op->primitive->value.type = schema::PrimitiveType_GreaterEqual; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "Less") == 0) { + MS_LOG(DEBUG) << "parse TfliteLessParser"; + std::unique_ptr attr(new schema::LessT()); + op->primitive->value.type = schema::PrimitiveType_Less; + op->primitive->value.value = attr.release(); + return RET_OK; + } else if (std::strcmp(node_name, "LessEqual") == 0) { + MS_LOG(DEBUG) << "parse TfliteLessEqualParser"; + std::unique_ptr attr(new schema::LessEqualT()); + op->primitive->value.type = schema::PrimitiveType_LessEqual; + op->primitive->value.value = attr.release(); + return RET_OK; + } else { + MS_LOG(ERROR) << "wrong op type"; + return RET_ERROR; + } +} + +TfliteNodeRegister g_tfliteAddParser("Add", new TfliteAddParser()); +TfliteNodeRegister g_tfliteSubParser("Sub", new TfliteSubParser()); +TfliteNodeRegister g_TfliteMulParser("Mul", new TfliteMulParser()); +TfliteNodeRegister g_TfliteDivParser("Div", new TfliteDivParser()); +TfliteNodeRegister g_tfliteFloorDivParser("FloorDiv", new TfliteFloorDivParser()); +TfliteNodeRegister g_tfliteFloorModParser("FloorMod", new TfliteFloorModParser()); +TfliteNodeRegister g_tfliteRealDivParser("RealDiv", new TfliteRealDivParser()); +TfliteNodeRegister g_TflitePowParser("Pow", new TflitePowParser()); +TfliteNodeRegister g_tfliteSquaredDifferenceParser("SquaredDifference", new TfliteSquaredDifferenceParser()); +TfliteNodeRegister g_TfliteMaximumParser("Maximum", new TfliteMaximumParser()); +TfliteNodeRegister g_TfliteMinimumParser("Minimum", new TfliteMinimumParser()); + +TfliteNodeRegister g_TfliteAbsParser("Abs", new TfliteAbsParser()); +TfliteNodeRegister g_TfliteExpParser("Exp", new TfliteExpParser()); +TfliteNodeRegister g_TfliteSqrtParser("Sqrt", new TfliteSqrtParser()); +TfliteNodeRegister g_tfliteRsqrtParser("Rsqrt", new TfliteRsqrtParser()); +TfliteNodeRegister g_TfliteSquareParser("Square", new TfliteSquareParser()); +TfliteNodeRegister g_TfliteSinParser("Sin", new TfliteSinParser()); +TfliteNodeRegister g_TfliteCosParser("Cos", new TfliteCosParser()); +TfliteNodeRegister g_TfliteLogParser("Log", new TfliteLogParser()); +TfliteNodeRegister g_tfliteRoundParser("Round", new TfliteRoundParser()); +TfliteNodeRegister g_TfliteCeilParser("Ceil", new TfliteCeilParser()); +TfliteNodeRegister g_tfliteFloorParser("flOOR", new TfliteFloorParser()); + +TfliteNodeRegister g_tfliteEqualParser("Equal", new TfliteEqualParser()); +TfliteNodeRegister g_tfliteNotEqualParser("NotEqual", new TfliteNotEqualParser()); +TfliteNodeRegister g_tfliteGreaterEParser("Greater", new TfliteGreaterParser()); +TfliteNodeRegister g_tfliteGreaterEqualParser("GreaterEqual", new TfliteGreaterEqualParser()); +TfliteNodeRegister g_tfliteLessParser("Less", new TfliteLessParser()); +TfliteNodeRegister g_tfliteLessEqualParser("LessEqual", new TfliteLessEqualParser()); + +} // namespace lite +} // namespace mindspore + + diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.h new file mode 100644 index 0000000000..8df29fb87b --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_arithmetic_parser.h @@ -0,0 +1,207 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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 PREDICT_TFLITE_MATH_PARSER_H +#define PREDICT_TFLITE_MATH_PARSER_H + +#include +#include +#include "tools/converter/parser/tflite/tflite_node_parser.h" +#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" + +namespace mindspore { +namespace lite { + +class TfliteDoubleInputOpParser : public TfliteNodeParser { + public: + TfliteDoubleInputOpParser() : TfliteNodeParser("node_name") {} + + STATUS Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, schema::CNodeT *op, + TensorCache *tensor_cache, bool quantizedModel) override; +}; + +class TfliteAddParser : public TfliteDoubleInputOpParser { + public: + TfliteAddParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteSubParser : public TfliteDoubleInputOpParser { + public: + TfliteSubParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteMulParser : public TfliteDoubleInputOpParser { + public: + TfliteMulParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteDivParser : public TfliteDoubleInputOpParser { + public: + TfliteDivParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteFloorDivParser : public TfliteDoubleInputOpParser { + public: + TfliteFloorDivParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteFloorModParser : public TfliteDoubleInputOpParser { + public: + TfliteFloorModParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteSquaredDifferenceParser : public TfliteDoubleInputOpParser { + public: + TfliteSquaredDifferenceParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteRealDivParser : public TfliteDoubleInputOpParser { + public: + TfliteRealDivParser() : TfliteDoubleInputOpParser() {} +}; + +class TflitePowParser : public TfliteDoubleInputOpParser { + public: + TflitePowParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteMaximumParser : public TfliteDoubleInputOpParser { + public: + TfliteMaximumParser() : TfliteDoubleInputOpParser() {} +}; + +class TfliteMinimumParser : public TfliteDoubleInputOpParser { + public: + TfliteMinimumParser() : TfliteDoubleInputOpParser() {} +}; + + +class TfliteSingleInputOpParser : public TfliteNodeParser { + public: + TfliteSingleInputOpParser() : TfliteNodeParser("node_name") {} + + STATUS Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, schema::CNodeT *op, + TensorCache *tensor_cache, bool quantizedModel) override; +}; + +class TfliteAbsParser : public TfliteSingleInputOpParser { + public: + TfliteAbsParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteExpParser : public TfliteSingleInputOpParser { + public: + TfliteExpParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteSqrtParser : public TfliteSingleInputOpParser { + public: + TfliteSqrtParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteSquareParser : public TfliteSingleInputOpParser { + public: + TfliteSquareParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteSinParser : public TfliteSingleInputOpParser { + public: + TfliteSinParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteCosParser : public TfliteSingleInputOpParser { + public: + TfliteCosParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteRsqrtParser : public TfliteSingleInputOpParser { + public: + TfliteRsqrtParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteLogParser : public TfliteSingleInputOpParser { + public: + TfliteLogParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteRoundParser : public TfliteSingleInputOpParser { + public: + TfliteRoundParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteCeilParser : public TfliteSingleInputOpParser { + public: + TfliteCeilParser() : TfliteSingleInputOpParser() {} +}; + +class TfliteFloorParser : public TfliteSingleInputOpParser { + public: + TfliteFloorParser() : TfliteSingleInputOpParser() {} +}; + + +class TfliteCompareOpParser : public TfliteNodeParser { + public: + TfliteCompareOpParser() : TfliteNodeParser("node_name") {} + + STATUS Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, schema::CNodeT *op, + TensorCache *tensor_cache, bool quantizedModel) override; +}; + +class TfliteEqualParser : public TfliteCompareOpParser { + public: + TfliteEqualParser() : TfliteCompareOpParser() {} +}; + +class TfliteNotEqualParser : public TfliteCompareOpParser { + public: + TfliteNotEqualParser() : TfliteCompareOpParser() {} +}; + +class TfliteGreaterParser : public TfliteCompareOpParser { + public: + TfliteGreaterParser() : TfliteCompareOpParser() {} +}; + +class TfliteGreaterEqualParser : public TfliteCompareOpParser { + public: + TfliteGreaterEqualParser() : TfliteCompareOpParser() {} +}; + +class TfliteLessParser : public TfliteCompareOpParser { + public: + TfliteLessParser() : TfliteCompareOpParser() {} +}; + +class TfliteLessEqualParser : public TfliteCompareOpParser { + public: + TfliteLessEqualParser() : TfliteCompareOpParser() {} +}; + +} // namespace lite +} // namespace mindspore + +#endif // PREDICT_TFLITE_MATH_PARSER_H + diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc deleted file mode 100644 index 6ed52bfb12..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.cc +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteBatchToSpaceNDParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteBatchToSpaceNDParser"; - std::unique_ptr attr(new schema::BatchToSpaceT()); - - // in tflite - // blockShape should be a 1D tensor with dimension [spatial_dims_num] - // crops should be a 2D tensor with dimension [spatial_dims_num, 2] - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { - MS_LOG(ERROR) << "BatchToSpaceNd get blockShape attr failed"; - return RET_ERROR; - } - if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->crops)) { - MS_LOG(ERROR) << "BatchToSpaceNd get crops attr failed"; - return RET_ERROR; - } - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_BatchToSpace; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteBatchToSpaceNDParser("BatchToSpaceND", new TfliteBatchToSpaceNDParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h deleted file mode 100644 index 59269fe454..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_sapce_nd_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_BATCH_TO_SPACE_ND_PARSER_H -#define PREDICT_TFLITE_BATCH_TO_SPACE_ND_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteBatchToSpaceNDParser : public TfliteNodeParser { - public: - TfliteBatchToSpaceNDParser() : TfliteNodeParser("BatchToSpaceND") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_BATCH_TO_SPACE_ND_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc index 6fe391f4b6..f42338bcaf 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.cc @@ -15,37 +15,58 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_batch_to_space_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_batch_to_space_parser.h" +#include namespace mindspore { namespace lite { -STATUS TfliteBatchToSpaceParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteBatchToSpaceParser"; +STATUS TfliteBatchToSpaceParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + if (std::strcmp(node_name, "BatchToSpace") == 0) { + MS_LOG(DEBUG) << "parse TfliteBatchToSpaceParser"; + } else if (std::strcmp(node_name, "BatchToSpaceND") == 0) { + MS_LOG(DEBUG) << "parse TfliteBatchToSpaceNDParser"; + // in tflite + // blockShape should be a 1D tensor with dimension [spatial_dims_num] + // crops should be a 2D tensor with dimension [spatial_dims_num, 2] + } + std::unique_ptr attr(new schema::BatchToSpaceT()); - if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) { - MS_LOG(ERROR) << "batchToSpace -> blockShape get failed"; + + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->blockShape)) { + MS_LOG(ERROR) << "get batchToSpace -> blockShape failed"; return RET_ERROR; } - if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->crops)) { - MS_LOG(ERROR) << "batchToSpace -> crops get failed"; + if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->crops)) { + MS_LOG(ERROR) << "get batchToSpace -> crops failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_BatchToSpace; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_BatchToSpace; + op->primitive->value.value = attr.release(); return RET_OK; } TfliteNodeRegister g_tfliteBatchToSpaceParser("BatchToSpace", new TfliteBatchToSpaceParser()); +TfliteNodeRegister g_TfliteBatchToSpaceNDParser("BatchToSpaceND", new TfliteBatchToSpaceNDParser()); + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.h index 37f20766a9..def11ce9f9 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_batch_to_space_parser.h @@ -32,9 +32,14 @@ class TfliteBatchToSpaceParser : public TfliteNodeParser { const std::vector> &tflite_tensors, const std::vector> &tflite_model_buffer, const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; + TensorCache *tensor_cache, bool quantized_model) override; }; + +class TfliteBatchToSpaceNDParser : public TfliteBatchToSpaceParser { + public: + TfliteBatchToSpaceNDParser() : TfliteBatchToSpaceParser() {} +}; + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc index bc508ef7d6..f73bcc9a87 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_broadcast_to_parser.cc @@ -15,31 +15,38 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_broadcast_to_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_broadcast_to_parser.h" namespace mindspore { namespace lite { -STATUS TfliteBroadcastToParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteBroadcastToParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteBroadcastToParser"; std::unique_ptr attr(new schema::BroadcastToT()); - if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->dst_shape)) { - MS_LOG(ERROR) << "broadCastTo -> dst_shape get failed"; + + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->dst_shape)) { + MS_LOG(ERROR) << "get broadCastTo -> dst_shape failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_BroadcastTo; - op->primitive->value.value = attr.release(); - } - return RET_OK; + op->primitive->value.type = schema::PrimitiveType_BroadcastTo; + op->primitive->value.value = attr.release(); + return RET_OK; } TfliteNodeRegister g_tfliteBroadcastToParser("BroadcastTo", new TfliteBroadcastToParser()); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc index a7cce134a6..78fe45fb25 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_cast_parser.cc @@ -15,29 +15,46 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_cast_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_cast_parser.h" namespace mindspore { namespace lite { -STATUS TfliteCastParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteCastParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteCastParser"; std::unique_ptr attr(new schema::CastT()); - attr->srcT = dtype_map[tflite_tensors[tflite_op->inputs[0]]->type]; - attr->dstT = dtype_map[tflite_tensors[tflite_op->outputs[0]]->type]; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Cast; - op->primitive->value.value = attr.release(); + const auto &in_tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (in_tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; } + attr->srcT = dtype_map[in_tensor->type]; + + const auto &out_tensor = tfliteTensors[tfliteOp->outputs[0]]; + if (out_tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + attr->dstT = dtype_map[out_tensor->type]; + + op->primitive->value.type = schema::PrimitiveType_Cast; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc deleted file mode 100644 index c8902c5f41..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_ceil_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteCeilParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteCeilParser"; - std::unique_ptr attr(new schema::CeilT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Ceil; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteCeilParser("Ceil", new TfliteCeilParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.h deleted file mode 100644 index 289c7b40c7..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_ceil_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_CEIL_PARSER_H -#define PREDICT_TFLITE_CEIL_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteCeilParser : public TfliteNodeParser { - public: - TfliteCeilParser() : TfliteNodeParser("Ceil") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_CEIL_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc index 5dbe6b2fea..a930233cee 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_concat_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_concat_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_concat_parser.h" namespace mindspore { namespace lite { @@ -24,25 +24,31 @@ STATUS TfliteConcatParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteConcatParser"; std::unique_ptr attr(new schema::ConcatT()); + const auto &tfliteAttr = tfliteOp->builtin_options.AsConcatenationOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } - attr->axis = tfliteAttr->axis; + attr->n = tfliteOp->inputs.size(); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Concat; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Concat; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc index 66c2c13492..3a60f9281a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_conv_parser.cc @@ -14,21 +14,30 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_conv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_conv_parser.h" namespace mindspore { namespace lite { -STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, +STATUS TfliteConvParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteConvParser"; std::unique_ptr attr(new schema::Conv2DT()); - const auto &tfliteAttr = tflite_op->builtin_options.AsConv2DOptions(); + const auto &tfliteAttr = tfliteOp->builtin_options.AsConv2DOptions(); if (tfliteAttr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; return RET_NULL_PTR; @@ -41,12 +50,16 @@ STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_ attr->padMode = GetPadMode(tfliteAttr->padding); attr->format = schema::Format_NHWC; attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_tensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { + // get the conv op weight tensor + auto weight_index = tfliteOp->inputs[1]; + const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } + std::vector weight_tensors{weight_tensor.get()}; + if (RET_OK != ParseTensor(weight_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } @@ -55,23 +68,27 @@ STATUS TfliteConvParser::Parse(const std::unique_ptr &tflite_ attr->channelOut = weight_shape[KHWC_K]; attr->kernelW = weight_shape[KHWC_W]; attr->kernelH = weight_shape[KHWC_H]; - if (tflite_op->inputs.size() == 3) { + + // get the conv op bias tensor + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; - auto bias_index = tflite_op->inputs[2]; - const auto &bias_tensor = tflite_tensors[bias_index]; + auto bias_index = tfliteOp->inputs[2]; + const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; - if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { + if (RET_OK != ParseTensor(bias_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse bias failed"; return RET_ERROR; } } + // calculate pad params - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Conv2D; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Conv2D; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_converter.h b/mindspore/lite/tools/converter/parser/tflite/tflite_converter.h index 88f0710851..9269502330 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_converter.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_converter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_CAFFE_CONVERTER_H_ -#define MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_CAFFE_CONVERTER_H_ +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_CONVERTER_H_ +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_CONVERTER_H_ #include #include @@ -34,5 +34,5 @@ class TfliteConverter : public Converter { } // namespace lite } // namespace mindspore -#endif // MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_CAFFE_CONVERTER_H_ +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_CONVERTER_H_ diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc deleted file mode 100644 index a61d95aaf7..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_cos_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteCosParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteCosParser"; - std::unique_ptr attr(new schema::CosT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Cos; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteCosParser("Cos", new TfliteCosParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.h deleted file mode 100644 index f2dedf2c22..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_cos_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_COS_PARSER_H -#define PREDICT_TFLITE_COS_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteCosParser : public TfliteNodeParser { - public: - TfliteCosParser() : TfliteNodeParser("Cos") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_COS_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc index 50ca889d87..5856077cb7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_deconv_parser.cc @@ -14,25 +14,35 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_deconv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_deconv_parser.h" namespace mindspore { namespace lite { -STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_op_set, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse tflite Transpose_Conv parser"; std::unique_ptr attr(new schema::DeConv2DT()); - const auto &tflite_attr = tflite_op->builtin_options.AsTransposeConvOptions(); + const auto &tflite_attr = tfliteOp->builtin_options.AsTransposeConvOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); return RET_NULL_PTR; } + attr->group = 1; attr->strideW = tflite_attr->stride_w; attr->strideH = tflite_attr->stride_h; @@ -40,12 +50,16 @@ STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tflit attr->dilateW = 1; attr->padMode = GetPadMode(tflite_attr->padding); attr->format = schema::Format_NHWC; - // get the conv op weight tensor - auto weight_index = tflite_op->inputs[1]; - const auto &weight_tensor = tflite_tensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tflite_model_buffer, tensor_cache, schema::Format_KHWC)) { + // get the conv op weight tensor + auto weight_index = tfliteOp->inputs[1]; + const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } + std::vector weight_tensors{weight_tensor.get()}; + if (RET_OK != ParseTensor(weight_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { return RET_ERROR; } auto weight_shape = weight_tensor->shape; @@ -54,11 +68,8 @@ STATUS TfliteDeConvParser::Parse(const std::unique_ptr &tflit attr->kernelW = weight_shape[CHWK_W]; attr->kernelH = weight_shape[CHWK_H]; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_DeConv2D; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_DeConv2D; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc index 0c441396c8..04586855f5 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_depth_to_space_parser.cc @@ -15,33 +15,41 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_depth_to_space_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_depth_to_space_parser.h" namespace mindspore { namespace lite { -STATUS TfliteDepthToSpaceParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { +STATUS TfliteDepthToSpaceParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteDepthToSpaceParser"; std::unique_ptr attr(new schema::DepthToSpaceT()); - const auto &tflite_attr = tflite_op->builtin_options.AsDepthToSpaceOptions(); + + const auto &tflite_attr = tfliteOp->builtin_options.AsDepthToSpaceOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); return RET_NULL_PTR; } attr->blockSize = tflite_attr->block_size; + attr->format = schema::Format_NHWC; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_DepthToSpace; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_DepthToSpace; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc index 0d231d73dd..96215944d1 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_depthwise_conv_parser.cc @@ -14,9 +14,9 @@ * limitations under the License. */ +#include "tools/converter/parser/tflite/tflite_depthwise_conv_parser.h" #include #include -#include "tools/converter/parser/tflite/tflite_depthwise_conv_parser.h" #include "tools/common/node_util.h" namespace mindspore { @@ -26,6 +26,7 @@ STATUS TfliteDepthwiseConv2DParser::ParseGroupDepthwiseConv(schema::CNodeT *op, const std::unique_ptr &weightTensor, TensorCache *tensor_cache) { std::unique_ptr convAttr(new schema::Conv2DT); + convAttr->format = attr->format; convAttr->channelIn = attr->channelIn; convAttr->channelOut = attr->channelIn * attr->channelMultiplier; @@ -64,7 +65,7 @@ STATUS TfliteDepthwiseConv2DParser::ParseGroupDepthwiseConv(schema::CNodeT *op, } } } - op->primitive = std::make_unique(); + op->primitive->value.type = schema::PrimitiveType_Conv2D; op->primitive->value.value = convAttr.release(); return RET_OK; @@ -75,6 +76,16 @@ STATUS TfliteDepthwiseConv2DParser::Parse(const std::unique_ptr> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteDepthwiseConv2DParser"; std::unique_ptr attr(new schema::DepthwiseConv2DT()); const auto &tflite_attr = tflite_op->builtin_options.AsDepthwiseConv2DOptions(); @@ -92,10 +103,18 @@ STATUS TfliteDepthwiseConv2DParser::Parse(const std::unique_ptrinputs[0]; const auto &input_tenosr = tflite_tensors[input_index]; + if (input_tenosr == nullptr) { + MS_LOG(ERROR) << "the first input is null"; + return RET_NULL_PTR; + } auto input_shape = input_tenosr->shape; auto weight_index = tflite_op->inputs[1]; const auto &weight_tensor = tflite_tensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "the weight tensor is null"; + return RET_NULL_PTR; + } auto weight_shape = weight_tensor->shape; attr->channelIn = input_shape[KHWC_C]; attr->channelMultiplier = tflite_attr->depth_multiplier; @@ -104,7 +123,7 @@ STATUS TfliteDepthwiseConv2DParser::Parse(const std::unique_ptr weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { + if (RET_OK != ParseTensor(weight_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } @@ -114,7 +133,7 @@ STATUS TfliteDepthwiseConv2DParser::Parse(const std::unique_ptrinputs[2]; const auto &bias_tensor = tflite_tensors[bias_index]; std::vector bias_tensors{bias_tensor.get()}; - if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { + if (RET_OK != ParseTensor(bias_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse bias failed"; return RET_ERROR; } @@ -122,11 +141,10 @@ STATUS TfliteDepthwiseConv2DParser::Parse(const std::unique_ptrchannelMultiplier > 1) { if (RET_OK != ParseGroupDepthwiseConv(op, attr, weight_tensor, tensor_cache)) { - // MS_LOGE("Parse Group DepthwiseConv failed"); + MS_LOG(ERROR) << "Parse Group DepthwiseConv failed"; return RET_ERROR; } } else { - op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_DepthwiseConv2D; op->primitive->value.value = attr.release(); } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc deleted file mode 100644 index b7b6efe123..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_div_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteDivParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteDivParser"; - std::unique_ptr attr(new schema::DivT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsDivOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Div; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteDivParser("Div", new TfliteDivParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.h deleted file mode 100644 index 1a82a0f806..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_div_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_DIV_PARSER_H -#define PREDICT_TFLITE_DIV_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteDivParser : public TfliteNodeParser { - public: - TfliteDivParser() : TfliteNodeParser("Div") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_DIV_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_equal_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_equal_parser.cc deleted file mode 100644 index 3ef4ddd286..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_equal_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_equal_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteEqualParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteEqualParser"; - std::unique_ptr attr(new schema::EqualT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Equal; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteEqualParser("Equal", new TfliteEqualParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_equal_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_equal_parser.h deleted file mode 100644 index 3435285b2a..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_equal_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_EQUAL_PARSER_H -#define LITE_TFLITE_EQUAL_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteEqualParser : public TfliteNodeParser { - public: - TfliteEqualParser() : TfliteNodeParser("Equal") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_EQUAL_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_exp_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_exp_parser.cc deleted file mode 100644 index 2d89b47dca..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_exp_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_exp_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteExpParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteExpParser"; - std::unique_ptr attr(new schema::ExpT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Exp; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteExpParser("Exp", new TfliteExpParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_exp_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_exp_parser.h deleted file mode 100644 index ec27390ace..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_exp_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_EXP_PARSER_H -#define PREDICT_TFLITE_EXP_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteExpParser : public TfliteNodeParser { - public: - TfliteExpParser() : TfliteNodeParser("Exp") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_EXP_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc index 3c42bf4d3b..624a0e5193 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_expand_dims_parser.cc @@ -27,26 +27,38 @@ STATUS TfliteExpandDimsParser::Parse(const std::unique_ptr &t schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteExpandDimsParser"; std::unique_ptr attr(new schema::ExpandDimsT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsExpandDimsOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - // get axis - auto axis_idx = tfliteOp->inputs[1]; - std::for_each(tfliteTensors[axis_idx]->shape.begin(), tfliteTensors[axis_idx]->shape.end(), [&](int32_t sha){}); - auto &buf_data = tfliteModelBuffer[tfliteTensors[axis_idx]->buffer]; - auto data_ptr = buf_data->data.data(); - attr->dim = *(static_cast(static_cast(data_ptr))); + attr->dim = -1; + MS_LOG(ERROR) << "The attr dim is folded by TFLite."; + return RET_ERROR; + + /* if (op != nullptr) { op->primitive = std::make_unique(); op->primitive->value.type = schema::PrimitiveType_ExpandDims; op->primitive->value.value = attr.release(); } return RET_OK; + */ } TfliteNodeRegister g_tfliteExpandDimsParser("ExpandDims", new TfliteExpandDimsParser()); diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc index 9d2dfddcfb..58ca290f36 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fakequant_parser.cc @@ -24,32 +24,49 @@ STATUS TfliteFakeQuantParser::Parse(const std::unique_ptr &tf const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteFullyConnectedParser"; std::unique_ptr attr(new schema::FullConnectionT()); auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { + if (RET_OK != ParseTensor(weight_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; auto bias_index = tfliteOp->inputs[2]; const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; - if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { + if (RET_OK != ParseTensor(bias_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse bias failed"; return RET_ERROR; } } attr->axis = 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_FullConnection; - op->primitive->value.value = attr.release(); - } + + op->primitive->value.type = schema::PrimitiveType_FullConnection; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc index e41141b560..a7b3be7f66 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fill_parser.cc @@ -27,20 +27,28 @@ STATUS TfliteFillParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteFillParser"; std::unique_ptr attr(new schema::FillT()); if (tfliteOp->inputs.size() > 1) { if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->dims)) { + MS_LOG(ERROR) << "get Fill -> dims failed"; return RET_ERROR; } } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Fill; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Fill; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_div_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_div_parser.cc deleted file mode 100644 index 2f38e6a35e..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_div_parser.cc +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include "tools/converter/parser/tflite/tflite_floor_div_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteFloorDivParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteFloorDivParser"; - std::unique_ptr attr(new schema::FloorDivT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_FloorDiv; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteFloorDivParser("FloorDiv", new TfliteFloorDivParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_div_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_div_parser.h deleted file mode 100644 index 3ee5f51305..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_div_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_FLOOR_DIV_PARSER_H -#define PREDICT_TFLITE_FLOOR_DIV_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteFloorDivParser : public TfliteNodeParser { - public: - TfliteFloorDivParser() : TfliteNodeParser("FloorDiv") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_FLOOR_DIV_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_mod_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_mod_parser.cc deleted file mode 100644 index ea99cef833..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_mod_parser.cc +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include "tools/converter/parser/tflite/tflite_floor_mod_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteFloorModParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteFloorModParser"; - std::unique_ptr attr(new schema::FloorModT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_FloorMod; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteFloorModParser("FloorMod", new TfliteFloorModParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_mod_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_mod_parser.h deleted file mode 100644 index b0ed989508..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_mod_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_FLOOR_MOD_PARSER_H -#define PREDICT_TFLITE_FLOOR_MOD_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteFloorModParser : public TfliteNodeParser { - public: - TfliteFloorModParser() : TfliteNodeParser("FloorMod") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_FLOOR_MOD_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc deleted file mode 100644 index 70abaef920..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.cc +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include "tools/converter/parser/tflite/tflite_floor_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteFloorParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteFloorParser"; - std::unique_ptr attr(new schema::FloorT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Floor; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteFloorParser("Floor", new TfliteFloorParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h deleted file mode 100644 index 7db0e83324..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_floor_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_FLOOR_PARSER_H -#define PREDICT_TFLITE_FLOOR_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteFloorParser : public TfliteNodeParser { - public: - TfliteFloorParser() : TfliteNodeParser("Floor") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_FLOOR_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc index 8ee363335f..21664183f5 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_fullyconnected_parser.cc @@ -25,33 +25,49 @@ STATUS TfliteFullyConnectedParser::Parse(const std::unique_ptr> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteFullyConnectedParser"; std::unique_ptr attr(new schema::FullConnectionT()); auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; - + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_NULL_PTR; + } std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { + if (RET_OK != ParseTensor(weight_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } + if (tfliteOp->inputs.size() == 3) { attr->hasBias = true; auto bias_index = tfliteOp->inputs[2]; const auto &bias_tensor = tfliteTensors[bias_index]; + if (bias_tensor == nullptr) { + MS_LOG(ERROR) << "bias_tensor is null"; + return RET_NULL_PTR; + } std::vector bias_tensors{bias_tensor.get()}; - if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { + if (RET_OK != ParseTensor(bias_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse bias failed"; return RET_ERROR; } } attr->axis = 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_FullConnection; - op->primitive->value.value = attr.release(); - } + + op->primitive->value.type = schema::PrimitiveType_FullConnection; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc index 41841f4a28..3d277cd986 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.cc @@ -27,24 +27,27 @@ STATUS TfliteGatherNdParser::Parse(const std::unique_ptr &tfl schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteGatherNdParser"; std::unique_ptr attr(new schema::GatherNdT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsGatherNdOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - attr->batchDims = 0; // default + attr->batchDims = 0; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_GatherNd; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_GatherNd; + op->primitive->value.value = attr.release(); return RET_OK; } -TfliteNodeRegister g_tfliteGatherNdParser("GatherNd", new TfliteGatherNdParser()); +TfliteNodeRegister g_tfliteGatherNdParser("GatherND", new TfliteGatherNdParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h index 18b8b5531d..c79d8aa753 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_nd_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteGatherNdParser : public TfliteNodeParser { public: - TfliteGatherNdParser() : TfliteNodeParser("GatherNd") {} + TfliteGatherNdParser() : TfliteNodeParser("GatherND") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc index 4c9efde2b4..c95e378216 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_parser.cc @@ -27,21 +27,30 @@ STATUS TfliteGatherParser::Parse(const std::unique_ptr &tflit schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteGatherParser"; std::unique_ptr attr(new schema::GatherT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsGatherOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - attr->axis = tflite_attr->axis; - attr->batchDims = 0; // default - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Gather; - op->primitive->value.value = attr.release(); - } + attr->batchDims = 0; + + op->primitive->value.type = schema::PrimitiveType_Gather; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc deleted file mode 100644 index 514fe5280c..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.cc +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include "tools/converter/parser/tflite/tflite_gather_v2_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteGatherV2Parser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteGatherV2Parser"; - std::unique_ptr attr(new schema::GatherT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsGatherOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - attr->axis = tflite_attr->axis; - attr->batchDims = 0; // default - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Gather; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteGatherV2Parser("GatherV2", new TfliteGatherV2Parser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h deleted file mode 100644 index d9acc3721d..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_gather_v2_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_GATHER_V2_PARSER_H -#define PREDICT_TFLITE_GATHER_V2_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteGatherV2Parser : public TfliteNodeParser { - public: - TfliteGatherV2Parser() : TfliteNodeParser("GatherV2") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_GATHER_V2_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_equal_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_greater_equal_parser.cc deleted file mode 100644 index 0ca417a180..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_equal_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_greater_equal_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteGreaterEqualParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteGreaterEqualParser"; - std::unique_ptr attr(new schema::GreaterEqualT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_GreaterEqual; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteGreaterEqualParser("GreaterEqual", new TfliteGreaterEqualParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_equal_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_greater_equal_parser.h deleted file mode 100644 index aacd8e3ab0..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_equal_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_GREATER_EQUAL_PARSER_H -#define LITE_TFLITE_GREATER_EQUAL_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteGreaterEqualParser : public TfliteNodeParser { - public: - TfliteGreaterEqualParser() : TfliteNodeParser("GreaterEqual") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_GREATER_EQUAL_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_greater_parser.cc deleted file mode 100644 index c706140dc6..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_greater_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteGreaterParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteGreaterParser"; - std::unique_ptr attr(new schema::GreaterT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Greater; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteGreaterParser("Greater", new TfliteGreaterParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_greater_parser.h deleted file mode 100644 index 99ab59c1f6..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_greater_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_GREATER_PARSER_H -#define LITE_TFLITE_GREATER_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteGreaterParser : public TfliteNodeParser { - public: - TfliteGreaterParser() : TfliteNodeParser("Greater") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_GREATER_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_hard_swish_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_hard_swish_parser.cc index 4dd7fe9b89..e7ff131f73 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_hard_swish_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_hard_swish_parser.cc @@ -25,16 +25,23 @@ STATUS TfliteHardSwishParser::Parse(const std::unique_ptr &tf const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(INFO) << "parse TfliteHardSwishParser"; std::unique_ptr attr(new schema::ActivationT()); attr->type = schema::ActivationType_HSWISH; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Activation; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc deleted file mode 100644 index aaf9366e81..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.cc +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include "tools/converter/parser/tflite/tflite_inner_product_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteInnerProductParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteInnerProductParser"; - std::unique_ptr attr(new schema::FullConnectionT()); - - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_NHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; - } - if (tfliteOp->inputs.size() == 3) { - attr->hasBias = true; - auto bias_index = tfliteOp->inputs[2]; - const auto &bias_tensor = tfliteTensors[bias_index]; - std::vector bias_tensors{bias_tensor.get()}; - if (RET_OK != ParseBias(bias_tensors, tfliteModelBuffer, tensor_cache)) { - MS_LOG(ERROR) << "parse bias failed"; - return RET_ERROR; - } - } - attr->axis = 1; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_FullConnection; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteInnerProductParser("InnerProduct", new TfliteInnerProductParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h deleted file mode 100644 index 0505e8ce23..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_inner_product_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_INNER_PRODUCT_PARSER_H -#define PREDICT_TFLITE_INNER_PRODUCT_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteInnerProductParser : public TfliteNodeParser { - public: - TfliteInnerProductParser() : TfliteNodeParser("InnerProduct") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_INNER_PRODUCT_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc deleted file mode 100644 index f04c65c4d3..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_leaky_relu_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLeakyReluParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteLeakyReluParser"; - std::unique_ptr attr(new schema::LeakyReLUT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsLeakyReluOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - attr->negativeSlope = tflite_attr->alpha; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteLeakyReluParser("LeakyRelu", new TfliteLeakyReluParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.h deleted file mode 100644 index bce9c90a9f..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_leaky_relu_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_LEAKY_RELU_PARSER_H -#define PREDICT_TFLITE_LEAKY_RELU_PARSER_H - -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" -#include -#include - -namespace mindspore { -namespace lite { -class TfliteLeakyReluParser : public TfliteNodeParser { - public: - TfliteLeakyReluParser() : TfliteNodeParser("LeakyRelu") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_LEAKY_RELU_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_less_equal_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_less_equal_parser.cc deleted file mode 100644 index 72f26ebc6e..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_less_equal_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_less_equal_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLessEqualParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteLessEqualParser"; - std::unique_ptr attr(new schema::LessEqualT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_LessEqual; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteLessEqualParser("LessEqual", new TfliteLessEqualParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_less_equal_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_less_equal_parser.h deleted file mode 100644 index 87fa8cedd8..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_less_equal_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_LESS_EQUAL_PARSER_H -#define LITE_TFLITE_LESS_EQUAL_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteLessEqualParser : public TfliteNodeParser { - public: - TfliteLessEqualParser() : TfliteNodeParser("LessEqual") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_LESS_EQUAL_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_less_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_less_parser.cc deleted file mode 100644 index 250272aa1f..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_less_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_less_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLessParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteLessParser"; - std::unique_ptr attr(new schema::LessT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Less; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteLessParser("Less", new TfliteLessParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_less_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_less_parser.h deleted file mode 100644 index 7cbe1c38da..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_less_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_LESS_PARSER_H -#define LITE_TFLITE_LESS_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteLessParser : public TfliteNodeParser { - public: - TfliteLessParser() : TfliteNodeParser("Less") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_LESS_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_log_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_log_parser.cc deleted file mode 100644 index 032c57225b..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_log_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_log_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLogParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteLogParser"; - std::unique_ptr attr(new schema::LogT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Log; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteLogParser("Log", new TfliteLogParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_log_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_log_parser.h deleted file mode 100644 index cb828b6706..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_log_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_LOG_PARSER_H -#define PREDICT_TFLITE_LOG_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteLogParser : public TfliteNodeParser { - public: - TfliteLogParser() : TfliteNodeParser("Log") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_LOG_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_and_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_and_parser.cc deleted file mode 100644 index c7df7acc8c..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_and_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_logical_and_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLogicalAndParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteLogicalAndParser"; - std::unique_ptr attr(new schema::LogicalAndT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_LogicalAnd; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteLogicalAndParser("LogicalAnd", new TfliteLogicalAndParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_not_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_not_parser.cc deleted file mode 100644 index 396decce53..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_not_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_logical_not_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLogicalNotParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteLogicalNotParser"; - std::unique_ptr attr(new schema::LogicalNotT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_LogicalNot; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteLogicalNotParser("LogicalNot", new TfliteLogicalNotParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_not_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_not_parser.h deleted file mode 100644 index 41f8f1bd2f..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_not_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_LOGICAL_NOT_PARSER_H -#define PREDICT_TFLITE_LOGICAL_NOT_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteLogicalNotParser : public TfliteNodeParser { - public: - TfliteLogicalNotParser() : TfliteNodeParser("LogicalNot") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_LOGICAL_NOT_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_or_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_or_parser.cc deleted file mode 100644 index 24582be41d..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_or_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_logical_or_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLogicalOrParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteLogicalOrParser"; - std::unique_ptr attr(new schema::LogicalOrT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_LogicalOr; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteLogicalOrParser("LogicalOr", new TfliteLogicalOrParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_or_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_or_parser.h deleted file mode 100644 index 55f74c174b..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_or_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_LOGICAL_OR_PARSER_H -#define PREDICT_TFLITE_LOGICAL_OR_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteLogicalOrParser : public TfliteNodeParser { - public: - TfliteLogicalOrParser() : TfliteNodeParser("LogicalOr") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_LOGICAL_OR_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.cc new file mode 100644 index 0000000000..078523ff40 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.cc @@ -0,0 +1,70 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include +#include +#include "tools/converter/parser/tflite/tflite_logical_parser.h" + +namespace mindspore { +namespace lite { +STATUS TfliteLogicalParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + if (std::strcmp(node_name, "LogicalAnd") == 0) { + MS_LOG(DEBUG) << "parse TfliteLogicalAndParser"; + std::unique_ptr attr(new schema::LogicalAndT()); + op->primitive->value.type = schema::PrimitiveType_LogicalAnd; + op->primitive->value.value = attr.release(); + } else if (std::strcmp(node_name, "LogicalNot") == 0) { + MS_LOG(INFO) << "parse TfliteLogicalNotParser"; + std::unique_ptr attr(new schema::LogicalNotT()); + op->primitive->value.type = schema::PrimitiveType_LogicalNot; + op->primitive->value.value = attr.release(); + } else if (std::strcmp(node_name, "LogicalOr") == 0) { + MS_LOG(INFO) << "parse TfliteLogicalOrParser"; + std::unique_ptr attr(new schema::LogicalOrT()); + op->primitive->value.type = schema::PrimitiveType_LogicalOr; + op->primitive->value.value = attr.release(); + } else { + MS_LOG(ERROR) << "wrong logical type"; + return RET_ERROR; + } + +return RET_OK; +} + +TfliteNodeRegister g_TfliteLogicalAndParser("LogicalAnd", new TfliteLogicalAndParser()); +TfliteNodeRegister g_TfliteLogicalNotParser("LogicalNot", new TfliteLogicalNotParser()); +TfliteNodeRegister g_TfliteLogicalOrParser("LogicalOr", new TfliteLogicalOrParser()); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_and_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.h similarity index 74% rename from mindspore/lite/tools/converter/parser/tflite/tflite_logical_and_parser.h rename to mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.h index 6e28d75f39..3608f1f12d 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logical_and_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_logical_parser.h @@ -24,9 +24,10 @@ namespace mindspore { namespace lite { -class TfliteLogicalAndParser : public TfliteNodeParser { + +class TfliteLogicalParser : public TfliteNodeParser { public: - TfliteLogicalAndParser() : TfliteNodeParser("LogicalAnd") {} + TfliteLogicalParser() : TfliteNodeParser("node_name") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, @@ -35,6 +36,21 @@ class TfliteLogicalAndParser : public TfliteNodeParser { TensorCache *tensor_cache, bool quantizedModel) override; }; + +class TfliteLogicalAndParser : public TfliteLogicalParser { + public: + TfliteLogicalAndParser() : TfliteLogicalParser() {} +}; + +class TfliteLogicalNotParser : public TfliteLogicalParser { + public: + TfliteLogicalNotParser() : TfliteLogicalParser() {} +}; + +class TfliteLogicalOrParser : public TfliteLogicalParser { + public: + TfliteLogicalOrParser() : TfliteLogicalParser() {} +}; } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logistic_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_logistic_parser.cc deleted file mode 100644 index bb254f2c3e..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logistic_parser.cc +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_logistic_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteLogisticParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteLogisticParser"; - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_SIGMOID; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteLogisticParser("Logistic", new TfliteLogisticParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_logistic_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_logistic_parser.h deleted file mode 100644 index 6c5402faa8..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_logistic_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_LOGISTIC_PARSER_H -#define PREDICT_TFLITE_LOGISTIC_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteLogisticParser : public TfliteNodeParser { - public: - TfliteLogisticParser() : TfliteNodeParser("Logistic") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_CONCAT_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc index 3ac19a2920..7d37779377 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_lrn_parser.cc @@ -27,23 +27,31 @@ STATUS TfliteLRNParser::Parse(const std::unique_ptr &tfliteOp schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteLRNParser"; std::unique_ptr attr(new schema::LocalResponseNormalizationT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsLocalResponseNormalizationOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - attr->depth_radius = tflite_attr->radius; attr->alpha = tflite_attr->alpha; attr->beta = tflite_attr->beta; attr->bias = tflite_attr->bias; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_LocalResponseNormalization; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_LocalResponseNormalization; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc deleted file mode 100644 index 387b0302e2..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.cc +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_max_pooling_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteMaxPoolingParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteMaxPoolingParser"; - std::unique_ptr attr(new schema::PoolingT()); - const auto &tflite_attr = tflite_op->builtin_options.AsPool2DOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - attr->format = schema::Format_NHWC; - // attr->global - attr->poolingMode = schema::PoolMode_MAX_POOLING; - attr->windowW = tflite_attr->filter_width; - attr->windowH = tflite_attr->filter_height; - attr->strideW = tflite_attr->stride_w; - attr->strideH = tflite_attr->stride_h; - attr->padMode = GetPadMode(tflite_attr->padding); - // calculate pad params - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Pooling; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteMaxPoolingParser("MaxPooling", new TfliteMaxPoolingParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.h deleted file mode 100644 index 0893b580ca..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_max_pooling_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_MAX_POOLING_PARSER_H -#define PREDICT_TFLITE_MAX_POOLING_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteMaxPoolingParser : public TfliteNodeParser { - public: - TfliteMaxPoolingParser() : TfliteNodeParser("MaxPooling") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_CONV_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_maximum_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_maximum_parser.cc deleted file mode 100644 index dc55c07713..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_maximum_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_maximum_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteMaximumParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteMaximumParser"; - std::unique_ptr attr(new schema::MaximumT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Maximum; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteMaximumParser("Maximum", new TfliteMaximumParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_maximum_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_maximum_parser.h deleted file mode 100644 index 5f3587d656..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_maximum_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_MAXIMUM_PARSER_H -#define PREDICT_TFLITE_MAXIMUM_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteMaximumParser : public TfliteNodeParser { - public: - TfliteMaximumParser() : TfliteNodeParser("Maximum") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_MAXIMUM_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc deleted file mode 100644 index caaf43a09f..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.cc +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_mean_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteMeanParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteMeanParser"; - std::unique_ptr attr(new schema::MeanT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_ERROR; - } - - attr->keepDims = tflite_attr->keep_dims; - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axis)) { - MS_LOG(ERROR) << "Mean get axis attr failed"; - return RET_ERROR; - } - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Mean; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteMeanParser("Mean", new TfliteMeanParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.h deleted file mode 100644 index 09e926fc62..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_MEAN_PARSER_H -#define PREDICT_TFLITE_MEAN_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteMeanParser : public TfliteNodeParser { - public: - TfliteMeanParser() : TfliteNodeParser("Mean") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_MEAN_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc deleted file mode 100644 index 2ec3e0221f..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_mean_pooling_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteMeanPoolingParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parser TfliteMeanPoolingParser"; - std::unique_ptr attr(new schema::PoolingT()); - const auto &tflite_attr = tflite_op->builtin_options.AsPool2DOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - attr->format = schema::Format_NHWC; - // attr->global - attr->poolingMode = schema::PoolMode_MEAN_POOLING; - attr->windowW = tflite_attr->filter_width; - attr->windowH = tflite_attr->filter_height; - attr->strideW = tflite_attr->stride_w; - attr->strideH = tflite_attr->stride_h; - attr->padMode = GetPadMode(tflite_attr->padding); - // calculate pad params - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Pooling; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteMeanPoolingParser("MeanPooling", new TfliteMeanPoolingParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_minimum_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_minimum_parser.cc deleted file mode 100644 index 245b69fd24..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_minimum_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_minimum_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteMinimumParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteMinimumParser"; - std::unique_ptr attr(new schema::MinimumT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Minimum; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteMinimumParser("Minimum", new TfliteMinimumParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_minimum_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_minimum_parser.h deleted file mode 100644 index 0e0bda8a4b..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_minimum_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_MINIMUM_PARSER_H -#define PREDICT_TFLITE_MINIMUM_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteMinimumParser : public TfliteNodeParser { - public: - TfliteMinimumParser() : TfliteNodeParser("Minimum") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_MINIMUM_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc index eebe4941f5..253a94c1e3 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.cc @@ -15,7 +15,6 @@ */ #include "tools/converter/parser/tflite/tflite_model_parser.h" -#include #include #include #include "tools/common/graph_util.h" @@ -71,6 +70,10 @@ STATUS TfliteModelParser::ParseTfliteQuantParams(const std::unique_ptroutputs.begin(), tflite_op->outputs.end()); for (const auto &index : quant_params_index) { const auto &tflite_tensor = tflite_subgraph->tensors[index]; + if (tflite_tensor == nullptr) { + MS_LOG(ERROR) << "tensor with id = " << index <<" is null"; + return RET_ERROR; + } if (tflite_tensor->quantization->scale.empty() && tflite_tensor->quantization->zero_point.empty() && tflite_tensor->quantization->min.empty() && tflite_tensor->quantization->max.empty()) { continue; @@ -101,6 +104,10 @@ STATUS TfliteModelParser::SetOpOutputIdx(const std::unique_ptroutputs) { const auto &tflite_tensor = tflite_subgraph->tensors[index]; + if (tflite_tensor == nullptr) { + MS_LOG(ERROR) << "tensor with id = " << index <<" is null"; + return RET_ERROR; + } std::unique_ptr tensor(new schema::TensorT()); tensor->dataType = GetTfliteDataType(tflite_tensor->type); tensor->dims = tflite_tensor->shape; @@ -108,7 +115,6 @@ STATUS TfliteModelParser::SetOpOutputIdx(const std::unique_ptrAddTensor(tflite_tensor->name, tensor.release(), OP_OUTPUT); op->outputIndex.emplace_back(opOutputIndex); } - return RET_OK; } @@ -123,6 +129,10 @@ STATUS TfliteModelParser::SetOpInputIdx(const std::unique_ptr &t for (const auto &tflite_index : op_inputs) { const auto &tflite_tensor = tflite_subgraph->tensors[tflite_index]; + if (tflite_tensor == nullptr) { + MS_LOG(ERROR) << "tensor with id = " << tflite_index <<" is null"; + return RET_ERROR; + } auto tensor_name = tflite_tensor->name; auto op = tfliteOpMap[tflite_op.get()]; unsigned int index = tensorCache->FindTensor(tensor_name); @@ -144,10 +154,8 @@ STATUS TfliteModelParser::ParseOp(const std::unique_ptr &tflite_ std::unique_ptr op(new schema::CNodeT); op->name = opType + "-" + std::to_string(i++); + MS_LOG(INFO) << "parse op: " << op->name.c_str(); - MS_LOG(INFO) << "parse op: [%s]" << op->name.c_str(); - - // 1. init op attr params auto node_parser = TfliteNodeParserRegistry::GetInstance()->GetNodeParser(opType); if (node_parser == nullptr) { MS_LOG(ERROR) << "cannot find node parser, opType: "<< opType.c_str(); @@ -164,7 +172,7 @@ STATUS TfliteModelParser::ParseOp(const std::unique_ptr &tflite_ status = SetOpOutputIdx(tflite_subgraph, tflite_op, op.get(), tensorCache); if (status != RET_OK) { - MS_LOG(ERROR) << "Set Op " << op->name.c_str() << " Output Index Failed!"; + MS_LOG(ERROR) << "Set Op "<< op->name.c_str() << " Output Index Failed!"; return RET_ERROR; } @@ -175,8 +183,7 @@ STATUS TfliteModelParser::ParseOp(const std::unique_ptr &tflite_ return RET_OK; } -void TfliteModelParser::SetInputTensor(const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, +void TfliteModelParser::SetInputTensor(const std::unique_ptr &tflite_subgraph, TensorCache *tensor_cache) { for (const auto &index : tflite_subgraph->inputs) { const auto &tflite_tensor = tflite_subgraph->tensors[index]; @@ -206,29 +213,31 @@ void TfliteModelParser::SetGraphTensorIndex(const mindspore::lite::TensorCache & } MetaGraphT *TfliteModelParser::Parse(const std::string &modelFile, const std::string &weightFile) { - std::unique_ptr subGraph(new schema::MetaGraphT); if (ValidateFileStr(modelFile, ".tflite") != RET_OK) { - // MS_LOGE("INPUT ILLEGAL: modelFile must be *.tflite"); + MS_LOG(ERROR) << "INPUT ILLEGAL: modelFile must be *.tflite"; return nullptr; } + std::unique_ptr tflite_model(new tflite::ModelT()); tflite_model = ReadTfliteModelFromFlat(modelFile.c_str()); if (tflite_model == nullptr) { - // MS_LOGE("read tflite model failed"); + MS_LOG(ERROR) << "read tflite model failed"; return nullptr; } - TensorCache tensorCache; + if (tflite_model->subgraphs.size() != 1) { MS_LOG(ERROR) << "read tflite model subgraphs failed"; return nullptr; } - const auto &tflite_subgraph = tflite_model->subgraphs[0]; - subGraph->name = "MS_model converted by TF-Lite"; // set dst subGraph input/output tensor - SetInputTensor(tflite_model, tflite_subgraph, &tensorCache); - // set dst subGraph op attr etc. + TensorCache tensorCache; + SetInputTensor(tflite_subgraph, &tensorCache); + + // set dst subGraph op attr and tensor_cache. + std::unique_ptr subGraph(new schema::MetaGraphT); + subGraph->name = "MS_model converted by TF-Lite"; auto status = ParseOp(tflite_model, tflite_subgraph, subGraph.get(), &tensorCache); if (status != RET_OK) { MS_LOG(ERROR) << "ParseOp failed."; @@ -238,21 +247,20 @@ MetaGraphT *TfliteModelParser::Parse(const std::string &modelFile, const std::st for (const auto &tflite_op : tflite_subgraph->operators) { auto status_tmp = SetOpInputIdx(tflite_model, tflite_subgraph, tflite_op, &tensorCache); if (status_tmp != RET_OK) { - // MS_LOGE("Set Op %s Input Index Failed!", tfliteOpMap.at(tflite_op.get())->name.c_str()); + MS_LOG(ERROR) << "Set Op " << tfliteOpMap.at(tflite_op.get())->name.c_str() << " Input Index Failed!"; } } for (const auto &tflite_op : tflite_subgraph->operators) { auto statusTmp = ParseTfliteQuantParams(tflite_subgraph, tflite_op); if (statusTmp != RET_OK) { - // MS_LOGE("ParseTfliteQuantParams %s Failed!", tfliteOpMap.at(tflite_op.get())->name.c_str()); + MS_LOG(ERROR) << "ParseTfliteQuantParams " << tfliteOpMap.at(tflite_op.get())->name.c_str() << " Failed!"; } } SetGraphTensorIndex(tensorCache, subGraph.get()); SetAllTensors(tensorCache, subGraph.get()); return subGraph.release(); -// return Fb2Anf(subGraph.release()); } } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.h index 0ebd9a7199..2b1a8d046b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_model_parser.h @@ -14,29 +14,24 @@ * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_MODEL_PARSER_H -#define MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_MODEL_PARSER_H +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_MODEL_PARSER_H +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_MODEL_PARSER_H #include #include #include #include #include - #include #include #include #include - #include "securec/include/securec.h" #include "tools/converter/model_parser.h" #include "tools/converter/parser/tflite/tflite_node_parser_registry.h" #include "tools/common/tensor_util.h" - #include "mindspore/lite/schema/inner/model_generated.h" -// using namespace tflite; - namespace mindspore { namespace lite { class TfliteModelParser : public ModelParser { @@ -50,8 +45,7 @@ class TfliteModelParser : public ModelParser { private: std::unique_ptr ReadTfliteModelFromFlat(const char *buf); - void SetInputTensor(const std::unique_ptr &tflite_model, - const std::unique_ptr &tflite_subgraph, TensorCache *tensor_cache); + void SetInputTensor(const std::unique_ptr &tflite_subgraph, TensorCache *tensor_cache); void SetGraphTensorIndex(const mindspore::lite::TensorCache &tensorCache, schema::MetaGraphT *subGraphDef); @@ -82,6 +76,5 @@ class TfliteModelParser : public ModelParser { }; } // namespace lite } // namespace mindspore -#endif // PREDICT_CONV -// ERTER_PARSER_TFLITE_MODEL_PARSER_H +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_MODEL_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc deleted file mode 100644 index efdefbc743..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.cc +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_mul_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteMulParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteMulParser"; - std::unique_ptr attr(new schema::MulT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsMulOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - return RET_ERROR; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Mul; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteMulParser("Mul", new TfliteMulParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.h deleted file mode 100644 index 5514c1af4e..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mul_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_MUL_PARSER_H -#define PREDICT_TFLITE_MUL_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteMulParser : public TfliteNodeParser { - public: - TfliteMulParser() : TfliteNodeParser("Mul") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_MUL_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc index 54167499b6..45f3cdd275 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.cc @@ -16,87 +16,52 @@ #include #include -#include #include "securec/include/securec.h" #include "tools/converter/parser/tflite/tflite_node_parser.h" +#include "tools/converter/parser/tflite/tflite_util.h" namespace mindspore { namespace lite { STATUS TfliteNodeParser::CopyTfliteTensorData(const std::vector> &tfliteModelBuffer, - const tflite::TensorT *tflite_tensor, schema::TensorT *tensor) { + const tflite::TensorT *tflite_tensor, + schema::TensorT *tensor) { auto count = 1; std::for_each(tflite_tensor->shape.begin(), tflite_tensor->shape.end(), [&](int32_t sha) { count *= sha; }); auto data_size = count * GetDataTypeSize(TypeId(tensor->dataType)); auto buffer_idx = tflite_tensor->buffer; if (!tfliteModelBuffer[buffer_idx]->data.empty()) { tensor->data.resize(data_size); - auto ret = memcpy_s(tensor->data.data(), data_size, tfliteModelBuffer[buffer_idx]->data.data(), data_size); - if (ret) { - MS_LOG(ERROR) << "memcpy tensor data failed, error code: %d" << ret; - return ret; + if (memcpy_s(tensor->data.data(), data_size, tfliteModelBuffer[buffer_idx]->data.data(), data_size)) { + MS_LOG(ERROR) << "memcpy tensor data failed"; + return RET_ERROR; } } else { - MS_LOG(ERROR) << "src tensor data is empty."; + MS_LOG(ERROR) << "src tensor data is empty"; return RET_ERROR; } return RET_OK; } -STATUS TfliteNodeParser::ParseWeight(const std::vector &weight_tenosrs, +STATUS TfliteNodeParser::ParseTensor(const std::vector &ts, const std::vector> &tfliteModelBuffer, - mindspore::lite::TensorCache *tensor_cache, schema::Format format) { - for (const auto &weight_tensor : weight_tenosrs) { - auto idx = tensor_cache->FindTensor(weight_tensor->name); + mindspore::lite::TensorCache *tensor_cache, + int node_type) { + for (const auto &t : ts) { + auto idx = tensor_cache->FindTensor(t->name); if (idx < 0) { std::unique_ptr tensor(new schema::TensorT); - tensor->dataType = GetTfliteDataType(weight_tensor->type); - tensor->dims = weight_tensor->shape; - tensor->nodeType = schema::NodeType_ValueNode; - // memcpy tensor data - // buffer is 0 (which refers to an always existent empty buffer) - if (weight_tensor->buffer > 0) { - CopyTfliteTensorData(tfliteModelBuffer, weight_tensor, tensor.get()); + tensor->dataType = GetTfliteDataType(t->type); + tensor->dims = t->shape; + + if (t->buffer > 0) { + CopyTfliteTensorData(tfliteModelBuffer, t, tensor.get()); } - MS_LOG(DEBUG) << "add weight tensor name: %s", weight_tensor->name.c_str(); - tensor_cache->AddTensor(weight_tensor->name, tensor.release(), TF_CONST); + + MS_LOG(DEBUG) << "add tensor name: " << t->name.c_str(); + tensor_cache->AddTensor(t->name, tensor.release(), node_type); } } return RET_OK; } - -STATUS TfliteNodeParser::ParseBias(const std::vector &bias_tensors, - const std::vector> &tfliteModelBuffer, - TensorCache *tensor_cache) { - for (const auto &bias_tensor : bias_tensors) { - auto idx = tensor_cache->FindTensor(bias_tensor->name); - if (idx < 0) { - std::unique_ptr tensor(new schema::TensorT); - tensor->dataType = GetTfliteDataType(bias_tensor->type); - tensor->dims = bias_tensor->shape; - tensor->nodeType = schema::NodeType_ValueNode; - // memcpy tensor data - // buffer is 0 (which refers to an always existent empty buffer) - if (bias_tensor->buffer > 0) { - CopyTfliteTensorData(tfliteModelBuffer, bias_tensor, tensor.get()); - } - // MS_LOGD("add weight tensor name: %s", bias_tensor->name.c_str()); - tensor_cache->AddTensor(bias_tensor->name, tensor.release(), TF_CONST); - } - } - return RET_OK; -} - -TypeId TfliteNodeParser::GetTfliteDataType(const tflite::TensorType &tflite_data_type) { - static std::unordered_map type_map = { - {tflite::TensorType_FLOAT32, TypeId::kNumberTypeFloat32}, {tflite::TensorType_FLOAT16, TypeId::kNumberTypeFloat16}, - {tflite::TensorType_INT32, TypeId::kNumberTypeInt32}, {tflite::TensorType_UINT8, TypeId::kNumberTypeUInt8}, - {tflite::TensorType_INT16, TypeId::kNumberTypeInt16}, {tflite::TensorType_INT8, TypeId::kNumberTypeInt8}, - }; - auto iter = type_map.find(tflite_data_type); - if (iter == type_map.end()) { - return kTypeUnknown; - } - return iter->second; -} } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h index 3eeea81f83..94ae5f8c55 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef PREDICT_TFLITE_NODE_PARSER_H -#define PREDICT_TFLITE_NODE_PARSER_H +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_NODE_PARSER_H +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_NODE_PARSER_H #include #include @@ -34,29 +34,24 @@ class TfliteNodeParser { public: explicit TfliteNodeParser(const std::string &nodeName) : name(nodeName) {} - virtual ~TfliteNodeParser() {} + virtual ~TfliteNodeParser() = default; virtual STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) = 0; + const std::vector> &tfliteOpSet, + schema::CNodeT *op, + TensorCache *tensor_cache, + bool quantizedModel) = 0; - STATUS ParseWeight(const std::vector &weight_tenosr, - const std::vector> &tfliteModelBuffer, TensorCache *tensor_cache, - schema::Format format); - - STATUS ParseBias(const std::vector &weight_tenosr, - const std::vector> &tfliteModelBuffer, TensorCache *tensor_cache); - - STATUS ParseAttr(const std::vector &attr_tenosrs, - const std::vector> &tfliteModelBuffer, - mindspore::lite::TensorCache *tensor_cache, schema::Format format); + STATUS ParseTensor(const std::vector &ts, + const std::vector> &tfliteModelBuffer, + mindspore::lite::TensorCache *tensor_cache, + int node_type); STATUS CopyTfliteTensorData(const std::vector> &tfliteModelBuffer, - const tflite::TensorT *tflite_tensor, schema::TensorT *tensor); - - TypeId GetTfliteDataType(const tflite::TensorType &tflite_data_type); + const tflite::TensorT *tflite_tensor, + schema::TensorT *tensor); template STATUS GetTfliteData(const int32_t tensor_index, const std::vector> &tfliteTensors, @@ -66,6 +61,10 @@ class TfliteNodeParser { std::for_each(tfliteTensors[tensor_index]->shape.begin(), tfliteTensors[tensor_index]->shape.end(), [&](int32_t sha) { count *= sha; }); auto &buf_data = tfliteModelBuffer[tfliteTensors[tensor_index]->buffer]; + if (buf_data == nullptr) { + MS_LOG(ERROR) << "buf_data is null"; + return RET_NULL_PTR; + } auto data_ptr = buf_data->data.data(); switch (tfliteTensors[tensor_index]->type) { case tflite::TensorType_UINT8: { @@ -116,18 +115,18 @@ class TfliteNodeParser { } break; } + default: { + MS_LOG(ERROR) << "wrong tensor type"; + return RET_ERROR; + } } return RET_OK; } - protected: - bool isQuantizedModel(); - protected: const std::string &name; - bool quantizedModel; }; } // namespace lite } // namespace mindspore -#endif // PREDICT_TFLITE_NODE_PARSER_H +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_NODE_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h index c2b533e241..ac8118b6e7 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_NODE_PARSER_REGISTRY_H -#define MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_NODE_PARSER_REGISTRY_H +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_NODE_PARSER_REGISTRY_H +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_NODE_PARSER_REGISTRY_H #include #include @@ -46,5 +46,5 @@ class TfliteNodeRegister { } // namespace lite } // namespace mindspore -#endif // MINDSPORE_CCSRC_TOOLS_LITE_CONVERTER_PARSER_TFLITE_NODE_PARSER_REGISTRY_H +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_NODE_PARSER_REGISTRY_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_not_equal_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_not_equal_parser.cc deleted file mode 100644 index c2dafab666..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_not_equal_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_not_equal_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteNotEqualParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteNotEqualParser"; - std::unique_ptr attr(new schema::NotEqualT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_NotEqual; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteNotEqualParser("NotEqual", new TfliteNotEqualParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_not_equal_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_not_equal_parser.h deleted file mode 100644 index bf69218ae4..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_not_equal_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_NOT_EQUAL_PARSER_H -#define LITE_TFLITE_NOT_EQUAL_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteNotEqualParser : public TfliteNodeParser { - public: - TfliteNotEqualParser() : TfliteNodeParser("NotEqual") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_NOT_EQUAL_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc index 8694a71840..0da5759332 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_one_hot_parser.cc @@ -25,25 +25,39 @@ STATUS TfliteOneHotParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(INFO) << "parse TfliteOneHotParser"; std::unique_ptr attr(new schema::OneHotT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsOneHotOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + auto axis = tflite_attr->axis; - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + const auto &tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (tensor == nullptr) { + MS_LOG(ERROR) << "tensor is null"; + return RET_NULL_PTR; + } + const auto tensor_shape = tensor->shape; if (axis < 0) { axis += tensor_shape.size(); } attr->axis = axis; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_OneHot; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_OneHot; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc deleted file mode 100644 index 92ec67de8f..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.cc +++ /dev/null @@ -1,45 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_p_relu_parser.h" - -namespace mindspore { -namespace lite { -STATUS TflitePreluParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "paser TflitePreluParser"; - std::unique_ptr attr(new schema::PreluT()); - if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->slope)) { - MS_LOG(ERROR) << "pRelu -> slope get failed"; - return RET_ERROR; - } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Prelu; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tflitePreluParser("Prelu", new TflitePreluParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.h deleted file mode 100644 index 5e79ce6914..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_p_relu_parser.h +++ /dev/null @@ -1,40 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_P_RELU_PARSER_H -#define LITE_TFLITE_P_RELU_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TflitePreluParser : public TfliteNodeParser { - public: - TflitePreluParser() : TfliteNodeParser("Prelu") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_P_RELU_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc index a49e032894..cfd1700547 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pad_parser.cc @@ -25,26 +25,33 @@ STATUS TflitePadParser::Parse(const std::unique_ptr &tfliteOp const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TflitePadParser"; std::unique_ptr attr(new schema::PadT()); const auto &tflite_attr = tfliteOp->builtin_options.AsPadOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } attr->paddingMode = schema::PaddingMode_CONSTANT; - if (tfliteOp->inputs.size() > 1) { - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->paddings)) { - return RET_ERROR; - } + attr->constantValue = 0.0f; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->paddings)) { + MS_LOG(ERROR) << "get pad -> paddings failed"; + return RET_ERROR; } - // attr->constantValue = 0.0f; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Pad; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Pad; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc new file mode 100644 index 0000000000..15e67a9d34 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.cc @@ -0,0 +1,80 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include +#include +#include "tools/converter/parser/tflite/tflite_pooling_parser.h" + +namespace mindspore { +namespace lite { +STATUS TflitePoolingParser::Parse(const std::unique_ptr &tflite_op, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::unique_ptr attr(new schema::PoolingT()); + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + if (std::strcmp(node_name, "MeanPooling") == 0) { + MS_LOG(DEBUG) << "parser TfliteMeanPoolingParser"; + attr->poolingMode = schema::PoolMode_MEAN_POOLING; + } else if (std::strcmp(node_name, "MaxPooling") == 0) { + MS_LOG(DEBUG) << "parse TfliteMaxPoolingParser"; + attr->poolingMode = schema::PoolMode_MAX_POOLING; + } else { + MS_LOG(ERROR) << "wrong pooling type"; + return RET_ERROR; + } + + const auto &tflite_attr = tflite_op->builtin_options.AsPool2DOptions(); + if (tflite_attr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->windowW = tflite_attr->filter_width; + attr->windowH = tflite_attr->filter_height; + attr->strideW = tflite_attr->stride_w; + attr->strideH = tflite_attr->stride_h; + attr->padMode = GetPadMode(tflite_attr->padding); + attr->format = schema::Format_NHWC; + // attr->global + + // calculate pad params + + op->primitive->value.type = schema::PrimitiveType_Pooling; + op->primitive->value.value = attr.release(); + return RET_OK; +} + +TfliteNodeRegister g_tfliteMeanPoolingParser("MeanPooling", new TfliteMeanPoolingParser()); +TfliteNodeRegister g_tfliteMaxPoolingParser("MaxPooling", new TfliteMaxPoolingParser()); +} // namespace lite +} // namespace mindspore + + diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.h similarity index 79% rename from mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.h rename to mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.h index 9f1dca30a2..1129df01cd 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_mean_pooling_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_pooling_parser.h @@ -24,9 +24,9 @@ namespace mindspore { namespace lite { -class TfliteMeanPoolingParser : public TfliteNodeParser { +class TflitePoolingParser : public TfliteNodeParser { public: - TfliteMeanPoolingParser() : TfliteNodeParser("MeanPooling") {} + TflitePoolingParser() : TfliteNodeParser("node_name") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, @@ -35,6 +35,16 @@ class TfliteMeanPoolingParser : public TfliteNodeParser { TensorCache *tensor_cache, bool quantizedModel) override; }; + +class TfliteMeanPoolingParser : public TflitePoolingParser { + public: + TfliteMeanPoolingParser() : TflitePoolingParser() {} +}; + +class TfliteMaxPoolingParser : public TflitePoolingParser { + public: + TfliteMaxPoolingParser() : TflitePoolingParser() {} +}; } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc deleted file mode 100644 index aac929ff7a..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.cc +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_pow_parser.h" - -namespace mindspore { -namespace lite { -STATUS TflitePowParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TflitePowParser"; - std::unique_ptr attr(new schema::PowerT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsPowOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - // the following use default values. This op is doing... - attr->power = 0.0f; - attr->scale = 0.0f; - attr->shift = 0.0f; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Power; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TflitePowParser("Pow", new TflitePowParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.h deleted file mode 100644 index e3a6b07bf9..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_pow_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_POW_PARSER_H -#define PREDICT_TFLITE_POW_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TflitePowParser : public TfliteNodeParser { - public: - TflitePowParser() : TfliteNodeParser("Pow") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_POW_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc index ee7e66d2db..38216a911e 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_range_parser.cc @@ -27,42 +27,23 @@ STATUS TfliteRangeParser::Parse(const std::unique_ptr &tflite schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteRangeParser"; std::unique_ptr attr(new schema::RangeT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsRangeOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - auto start_idx = tfliteOp->inputs[1]; - std::for_each(tfliteTensors[start_idx]->shape.begin(), tfliteTensors[start_idx]->shape.end(), [&](int32_t sha){}); - auto &start_buf_data = tfliteModelBuffer[tfliteTensors[start_idx]->buffer]; - auto start_data_ptr = start_buf_data->data.data(); - attr->start = *(static_cast(static_cast(start_data_ptr))); + attr->dType = 0; - auto limit_idx = tfliteOp->inputs[2]; - std::for_each(tfliteTensors[limit_idx]->shape.begin(), tfliteTensors[limit_idx]->shape.end(), [&](int32_t sha){}); - auto &limit_buf_data = tfliteModelBuffer[tfliteTensors[limit_idx]->buffer]; - auto limit_data_ptr = limit_buf_data->data.data(); - attr->limit = *(static_cast(static_cast(limit_data_ptr))); - - if (tfliteOp->inputs.size() > 2) { - auto delta_idx = tfliteOp->inputs[3]; - std::for_each(tfliteTensors[delta_idx]->shape.begin(), tfliteTensors[delta_idx]->shape.end(), [&](int32_t sha){}); - auto &delta_buf_data = tfliteModelBuffer[tfliteTensors[delta_idx]->buffer]; - auto delta_data_ptr = delta_buf_data->data.data(); - attr->delta = *(static_cast(static_cast(delta_data_ptr))); - } else { - attr->delta = 0; // default - } - - attr->dType = 0; // default - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Range; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Range; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc index bb64242230..d66b5278dc 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_rank_parser.cc @@ -27,18 +27,21 @@ STATUS TfliteRankParser::Parse(const std::unique_ptr &tfliteO schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteRankParser"; - std::unique_ptr attr(new schema::RankT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsRankOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Rank; - op->primitive->value.value = attr.release(); - } + MS_LOG(DEBUG) << "parse TfliteRankParser"; + std::unique_ptr attr(new schema::RankT()); + + op->primitive->value.type = schema::PrimitiveType_Rank; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_real_div_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_real_div_parser.cc deleted file mode 100644 index 12dbd47878..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_real_div_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_real_div_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteRealDivParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteRealDivParser"; - std::unique_ptr attr(new schema::RealDivT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_RealDiv; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteRealDivParser("RealDiv", new TfliteRealDivParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_real_div_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_real_div_parser.h deleted file mode 100644 index 110e813d0e..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_real_div_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_REAL_DIV_PARSER_H -#define LITE_TFLITE_REAL_DIV_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteRealDivParser : public TfliteNodeParser { - public: - TfliteRealDivParser() : TfliteNodeParser("RealDiv") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_REAL_DIV_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc deleted file mode 100644 index 10f6489575..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.cc +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_reduce_any_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteReduceAnyParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteReduceAnyParser"; - std::unique_ptr attr(new schema::ReduceT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - // attr->mode = schema::; - MS_LOG(ERROR) << "ms-lite haven't supported REDUCE_ANY now"; - return RET_NOT_FIND_OP; - - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_ANY get axes attr failed"; - return RET_ERROR; - } - attr->keepDims = tflite_attr->keep_dims; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Reduce; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteReduceAnyParser("ReduceAny", new TfliteReduceAnyParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.h deleted file mode 100644 index daa9b84e0b..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_any_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_REDUCE_ANY_PARSER_H -#define PREDICT_TFLITE_REDUCE_ANY_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteReduceAnyParser : public TfliteNodeParser { - public: - TfliteReduceAnyParser() : TfliteNodeParser("ReduceAny") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_REDUCE_ANY_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc deleted file mode 100644 index 85e9dc70d6..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.cc +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_reduce_max_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteReduceMaxParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteReduceMaxParser"; - std::unique_ptr attr(new schema::ReduceT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->mode = schema::ReduceMode_ReduceMax; - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_MAX get axes attr failed"; - return RET_ERROR; - } - attr->keepDims = tflite_attr->keep_dims; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Reduce; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteReduceMaxParser("ReduceMax", new TfliteReduceMaxParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc deleted file mode 100644 index 5c385b43a4..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.cc +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_reduce_min_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteReduceMinParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteReduceMinParser"; - std::unique_ptr attr(new schema::ReduceT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->mode = schema::ReduceMode_ReduceMin; - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_MIN get axes attr failed"; - return RET_ERROR; - } - attr->keepDims = tflite_attr->keep_dims; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Reduce; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteReduceMinParser("ReduceMin", new TfliteReduceMinParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.h deleted file mode 100644 index 38d6598c6a..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_min_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_REDUCE_MIN_PARSER_H -#define PREDICT_TFLITE_REDUCE_MIN_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteReduceMinParser : public TfliteNodeParser { - public: - TfliteReduceMinParser() : TfliteNodeParser("ReduceMin") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_REDUCE_MIN_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.cc new file mode 100644 index 0000000000..4472430e48 --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.cc @@ -0,0 +1,93 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include +#include +#include "tools/converter/parser/tflite/tflite_reduce_parser.h" + +namespace mindspore { +namespace lite { +STATUS TfliteReduceParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::unique_ptr attr(new schema::ReduceT()); + + const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); + if (tflite_attr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; + return RET_NULL_PTR; + } + attr->keepDims = tflite_attr->keep_dims; + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + if (std::strcmp(node_name, "ReduceMax") == 0) { + MS_LOG(DEBUG) << "parse TfliteReduceMaxParser"; + attr->mode = schema::ReduceMode_ReduceMax; + } else if (std::strcmp(node_name, "ReduceMin") == 0) { + MS_LOG(DEBUG) << "parse TfliteReduceMinParser"; + attr->mode = schema::ReduceMode_ReduceMin; + } else if (std::strcmp(node_name, "ReduceProd") == 0) { + MS_LOG(DEBUG) << "parse TfliteReduceProdParser"; + attr->mode = schema::ReduceMode_ReduceProd; + } else if (std::strcmp(node_name, "Sum") == 0) { + MS_LOG(DEBUG) << "parse TfliteSumParser"; + attr->mode = schema::ReduceMode_ReduceSum; + } else if (std::strcmp(node_name, "Mean") == 0) { + MS_LOG(DEBUG) << "parse TfliteMeanParser"; + attr->mode = schema::ReduceMode_ReduceMean; + } else if (std::strcmp(node_name, "ReduceAny") == 0) { + // attr->mode; + MS_LOG(ERROR) << "ms-lite haven't supported REDUCE_ANY now"; + return RET_NOT_FIND_OP; + } else { + MS_LOG(ERROR) << "wrong reduce type"; + return RET_ERROR; + } + + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { + MS_LOG(ERROR) << "get reduce_prod -> axes failed"; + return RET_ERROR; + } + + op->primitive->value.type = schema::PrimitiveType_Reduce; + op->primitive->value.value = attr.release(); + return RET_OK; +} + +TfliteNodeRegister g_TfliteSumParser("Sum", new TfliteSumParser()); +TfliteNodeRegister g_TfliteMeanParser("Mean", new TfliteMeanParser()); +TfliteNodeRegister g_TfliteReduceMaxParser("ReduceMax", new TfliteReduceMaxParser()); +TfliteNodeRegister g_TfliteReduceMinParser("ReduceMin", new TfliteReduceMinParser()); +TfliteNodeRegister g_TfliteReduceProdParser("ReduceProd", new TfliteReduceProdParser()); +TfliteNodeRegister g_TfliteReduceAnyParser("ReduceAny", new TfliteReduceAnyParser()); + +} // namespace lite +} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.h similarity index 63% rename from mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.h rename to mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.h index 9372b73584..628243881c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_max_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_parser.h @@ -24,9 +24,9 @@ namespace mindspore { namespace lite { -class TfliteReduceMaxParser : public TfliteNodeParser { +class TfliteReduceParser : public TfliteNodeParser { public: - TfliteReduceMaxParser() : TfliteNodeParser("ReduceMax") {} + TfliteReduceParser() : TfliteNodeParser("node_name") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, @@ -35,6 +35,37 @@ class TfliteReduceMaxParser : public TfliteNodeParser { TensorCache *tensor_cache, bool quantizedModel) override; }; + +class TfliteReduceMaxParser : public TfliteReduceParser { + public: + TfliteReduceMaxParser() : TfliteReduceParser() {} +}; + +class TfliteReduceMinParser : public TfliteReduceParser { + public: + TfliteReduceMinParser() : TfliteReduceParser() {} +}; + +class TfliteReduceProdParser : public TfliteReduceParser { + public: + TfliteReduceProdParser() : TfliteReduceParser() {} +}; + +class TfliteSumParser : public TfliteReduceParser { + public: + TfliteSumParser() : TfliteReduceParser() {} +}; + +class TfliteMeanParser : public TfliteReduceParser { + public: + TfliteMeanParser() : TfliteReduceParser() {} +}; + +class TfliteReduceAnyParser : public TfliteReduceParser { + public: + TfliteReduceAnyParser() : TfliteReduceParser() {} +}; + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc deleted file mode 100644 index 4d40540bf8..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.cc +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_reduce_prod_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteReduceProdParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteReduceProdParser"; - std::unique_ptr attr(new schema::ReduceT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->mode = schema::ReduceMode_ReduceProd; - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "REDUCE_PROD get axes attr failed"; - return RET_ERROR; - } - attr->keepDims = tflite_attr->keep_dims; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Reduce; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteReduceProdParser("ReduceProd", new TfliteReduceProdParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.h deleted file mode 100644 index cadfe9b707..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reduce_prod_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_REDUCE_PROD_PARSER_H -#define PREDICT_TFLITE_REDUCE_PROD_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteReduceProdParser : public TfliteNodeParser { - public: - TfliteReduceProdParser() : TfliteNodeParser("ReduceProd") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_REDUCE_PROD_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc deleted file mode 100644 index 657c3eaf17..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.cc +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_relu6_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteRelu6Parser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteRelu6Parser"; - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_RELU6; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteRelu6Parser("Relu6", new TfliteRelu6Parser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.h deleted file mode 100644 index 3d1f84ff0c..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu6_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_RELU6_PARSER_H -#define PREDICT_TFLITE_RELU6_PARSER_H - -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" -#include -#include - -namespace mindspore { -namespace lite { -class TfliteRelu6Parser : public TfliteNodeParser { - public: - TfliteRelu6Parser() : TfliteNodeParser("Relu6") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_RELU6_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc deleted file mode 100644 index 31877c8d8f..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.cc +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_relu_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteReluParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteReluParser"; - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_RELU; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteReluParser("Relu", new TfliteReluParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.h deleted file mode 100644 index 7b67e0c4ee..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_relu_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_RELU_PARSER_H -#define PREDICT_TFLITE_RELU_PARSER_H - -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" -#include -#include - -namespace mindspore { -namespace lite { -class TfliteReluParser : public TfliteNodeParser { - public: - TfliteReluParser() : TfliteNodeParser("Relu") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_RELU_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc index 968989f0c2..c78c51f1bc 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reshape_parser.cc @@ -24,8 +24,17 @@ STATUS TfliteReshapeParser::Parse(const std::unique_ptr &tfli const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteReshapeParser"; std::unique_ptr attr(new schema::ReshapeT()); @@ -37,8 +46,12 @@ STATUS TfliteReshapeParser::Parse(const std::unique_ptr &tfli } auto shape_tensor_index = tfliteOp->inputs[1]; const auto & shape_tensor = tfliteTensors[shape_tensor_index]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } std::vector shape_tensors{shape_tensor.get()}; - if (RET_OK != ParseWeight(shape_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { + if (RET_OK != ParseTensor(shape_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse shape tensor error"; return RET_ERROR; } @@ -50,11 +63,8 @@ STATUS TfliteReshapeParser::Parse(const std::unique_ptr &tfli } } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Reshape; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Reshape; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc deleted file mode 100644 index 13c7eb48c1..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.cc +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_resize_bilinear_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteResizeBilinearParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteResizeBilinearParser"; - std::unique_ptr attr(new schema::ResizeT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeBilinearOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - - attr->format = schema::Format_NHWC; - attr->method = schema::ResizeMethod_BILINEAR; - attr->alignCorners = tfliteAttr->align_corners; - auto tfliteResizeTensorIndex = tfliteOp->inputs[1]; - auto resizeTensorBufferIndex = tfliteTensors.at(tfliteResizeTensorIndex)->buffer; - auto buffData = reinterpret_cast(tfliteModelBuffer.at(resizeTensorBufferIndex)->data.data()); - auto height = buffData[0]; - auto width = buffData[1]; - attr->newWidth = width; - attr->newHeight = height; - // attr->preserveAspectRatio - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Resize; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteResizeBilinearParser("ResizeBilinear", new TfliteResizeBilinearParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc deleted file mode 100644 index 20438d63a4..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.cc +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteResizeNearestNeighborParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteResizeNearestNeighborParser"; - std::unique_ptr attr(new schema::ResizeT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeNearestNeighborOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - return RET_NULL_PTR; - } - - attr->format = schema::Format_NHWC; - attr->method = schema::ResizeMethod_NEAREST_NEIGHBOR; - attr->alignCorners = tfliteAttr->align_corners; - auto tfliteResizeTensorIndex = tfliteOp->inputs[1]; - auto resizeTensorBufferIndex = tfliteTensors.at(tfliteResizeTensorIndex)->buffer; - auto buffData = reinterpret_cast(tfliteModelBuffer.at(resizeTensorBufferIndex)->data.data()); - auto height = buffData[0]; - auto width = buffData[1]; - attr->newWidth = width; - attr->newHeight = height; - // attr->preserveAspectRatio - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Resize; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteResizeNearestNeighborParser("NearestNeighbor", - new TfliteResizeNearestNeighborParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.h deleted file mode 100644 index 4657a67d96..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_nearest_neighbor_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_RESIZE_NN_PARSER_H -#define PREDICT_TFLITE_RESIZE_NN_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteResizeNearestNeighborParser : public TfliteNodeParser { - public: - TfliteResizeNearestNeighborParser() : TfliteNodeParser("NearestNeighbor") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_RESIZE_NN_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.cc new file mode 100644 index 0000000000..4dfc27c32e --- /dev/null +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.cc @@ -0,0 +1,100 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ + +#include +#include +#include +#include "tools/converter/parser/tflite/tflite_resize_parser.h" + +namespace mindspore { +namespace lite { +STATUS TfliteResizeParser::Parse(const std::unique_ptr &tfliteOp, + const std::vector> &tfliteTensors, + const std::vector> &tfliteModelBuffer, + const std::vector> &tfliteOpSet, + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + std::unique_ptr attr(new schema::ResizeT()); + + std::vector node_name_str; + Split(op->name.data(), &node_name_str, "-"); + const char *node_name = node_name_str.data()->c_str(); + + if (std::strcmp(node_name, "ResizeBilinear") == 0) { + MS_LOG(DEBUG) << "parse TfliteResizeBilinearParser"; + const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeBilinearOptions(); + if (tfliteAttr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->alignCorners = tfliteAttr->align_corners; + attr->method = schema::ResizeMethod_BILINEAR; + } else if (std::strcmp(node_name, "NearestNeighbor") == 0) { + MS_LOG(DEBUG) << "parse TfliteResizeNearestNeighborParser"; + const auto &tfliteAttr = tfliteOp->builtin_options.AsResizeNearestNeighborOptions(); + if (tfliteAttr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } + attr->alignCorners = tfliteAttr->align_corners; + attr->method = schema::ResizeMethod_NEAREST_NEIGHBOR; + } else { + MS_LOG(ERROR) << "wrong resize type"; + return RET_ERROR; + } + + attr->format = schema::Format_NHWC; + attr->preserveAspectRatio = false; + + auto tfliteResizeTensorIndex = tfliteOp->inputs[1]; + const auto & shape_tensor = tfliteTensors[tfliteResizeTensorIndex]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } + auto resizeTensorBufferIndex = shape_tensor->buffer; + const auto & buff = tfliteModelBuffer.at(resizeTensorBufferIndex); + if (buff == nullptr) { + MS_LOG(ERROR) << "buff_data is null"; + return RET_NULL_PTR; + } + auto buffData = reinterpret_cast(buff->data.data()); + auto height = buffData[0]; + auto width = buffData[1]; + attr->newWidth = width; + attr->newHeight = height; + + op->primitive->value.type = schema::PrimitiveType_Resize; + op->primitive->value.value = attr.release(); + return RET_OK; +} + +TfliteNodeRegister g_tfliteResizeBilinearParser("ResizeBilinear", new TfliteResizeBilinearParser()); +TfliteNodeRegister g_tfliteResizeNearestNeighborParser("NearestNeighbor", + new TfliteResizeNearestNeighborParser()); +} // namespace lite +} // namespace mindspore + + diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.h similarity index 74% rename from mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.h rename to mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.h index bbe48edd51..779a1cf0cd 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_resize_bilinear_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_resize_parser.h @@ -24,17 +24,27 @@ namespace mindspore { namespace lite { -class TfliteResizeBilinearParser : public TfliteNodeParser { +class TfliteResizeParser : public TfliteNodeParser { public: - TfliteResizeBilinearParser() : TfliteNodeParser("ResizeBilinear") {} + TfliteResizeParser() : TfliteNodeParser("node_name") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; + TensorCache *tensor_cache, bool quantizedModel) override; }; + +class TfliteResizeBilinearParser : public TfliteResizeParser { + public: + TfliteResizeBilinearParser() : TfliteResizeParser() {} +}; + +class TfliteResizeNearestNeighborParser : public TfliteResizeParser { + public: + TfliteResizeNearestNeighborParser() : TfliteResizeParser() {} +}; + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc index f516d7e2d1..a1ddd7f13c 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.cc @@ -27,27 +27,29 @@ STATUS TfliteReverseParser::Parse(const std::unique_ptr &tfli schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteReverseParser"; - std::unique_ptr attr(new schema::ReverseT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsReverseV2Options(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; return RET_NULL_PTR; } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + + MS_LOG(DEBUG) << "parse TfliteReverseParser"; + std::unique_ptr attr(new schema::ReverseT()); if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axis)) { return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Reverse; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Reverse; + op->primitive->value.value = attr.release(); return RET_OK; } -TfliteNodeRegister g_tfliteReverseParser("Reverse", new TfliteReverseParser()); +TfliteNodeRegister g_tfliteReverseParser("reverse", new TfliteReverseParser()); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h index 1db4301566..3965ab1ece 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_parser.h @@ -26,7 +26,7 @@ namespace mindspore { namespace lite { class TfliteReverseParser : public TfliteNodeParser { public: - TfliteReverseParser() : TfliteNodeParser("Reverse") {} + TfliteReverseParser() : TfliteNodeParser("reverse") {} STATUS Parse(const std::unique_ptr &tfliteOp, const std::vector> &tfliteTensors, diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc index 3658541d98..867ca6bc77 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_reverse_sequence_parser.cc @@ -25,22 +25,35 @@ STATUS TfliteReverseSequenceParser::Parse(const std::unique_ptr> &tflite_tensors, const std::vector> &tflite_model_buffer, const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteReverseSequenceParser"; std::unique_ptr attr(new schema::ReverseSequenceT()); - const auto &tflite_attr = tflite_op->builtin_options.AsReverseSequenceOptions(); + const auto &tflite_attr = tflite_op->builtin_options.AsReverseSequenceOptions(); + if (tflite_attr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } attr->seqAxis = tflite_attr->seq_dim; attr->batchAxis = tflite_attr->batch_dim; + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->seqLengths)) { + MS_LOG(ERROR) << "get reverse_sequence -> seqLengths failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_ReverseSequence; - op->primitive->value.value = attr.release(); - } + + op->primitive->value.type = schema::PrimitiveType_ReverseSequence; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_round_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_round_parser.cc deleted file mode 100644 index 3e385c8e44..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_round_parser.cc +++ /dev/null @@ -1,43 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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, -* distributed under the License is distributed on an AS -* 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. -*/ - -#include -#include -#include "tools/converter/parser/tflite/tflite_round_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteRoundParser::Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantized_model) { - MS_LOG(DEBUG) << "parse TfliteRoundParser"; - std::unique_ptr attr(new schema::RoundT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Round; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteRoundParser("Round", new TfliteRoundParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_round_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_round_parser.h deleted file mode 100644 index 060f4d0991..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_round_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** -* Copyright 2020 Huawei Technologies Co., Ltd -* -* 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 LITE_TFLITE_ROUND_PARSER_H -#define LITE_TFLITE_ROUND_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteRoundParser : public TfliteNodeParser { - public: - TfliteRoundParser() : TfliteNodeParser("Round") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_ROUND_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_rsqrt_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_rsqrt_parser.cc deleted file mode 100644 index 15eac6e874..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_rsqrt_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_rsqrt_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteRsqrtParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "paser TfliteRsqrtParser"; - std::unique_ptr attr(new schema::RsqrtT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Rsqrt; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteRsqrtParser("Rsqrt", new TfliteRsqrtParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_rsqrt_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_rsqrt_parser.h deleted file mode 100644 index 8a81b42f99..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_rsqrt_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_RSQRT_PARSER_H -#define PREDICT_TFLITE_RSQRT_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteRsqrtParser : public TfliteNodeParser { - public: - TfliteRsqrtParser() : TfliteNodeParser("Rsqrt") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_RSQRT_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc index a113266496..f1dac84959 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_scatter_nd_parser.cc @@ -26,8 +26,19 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr &tf const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(INFO) << "parse TfliteScatterNdParser"; std::unique_ptr attr(new schema::ScatterNDT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsScatterNdOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; @@ -50,11 +61,8 @@ STATUS TfliteScatterNdParser::Parse(const std::unique_ptr &tf } */ - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_ScatterND; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_ScatterND; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc index eab6694a7a..95163afde1 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_shape_parser.cc @@ -25,16 +25,21 @@ STATUS TfliteShapeParser::Parse(const std::unique_ptr &tflite const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(INFO) << "parse TfliteShapeParser"; std::unique_ptr attr(new schema::ShapeT()); - // tflite_attr->out_type; // this attr is dropped - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Shape; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Shape; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc deleted file mode 100644 index fcfe4110d1..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.cc +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_sigmoid_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSigmoidParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteSigmoidParser"; - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_SIGMOID; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteSigmoidParser("Sigmoid", new TfliteSigmoidParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h deleted file mode 100644 index f291125964..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sigmoid_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_SIGMOID_PARSER_H -#define PREDICT_TFLITE_SIGMOID_PARSER_H - -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" -#include -#include - -namespace mindspore { -namespace lite { -class TfliteSigmoidParser : public TfliteNodeParser { - public: - TfliteSigmoidParser() : TfliteNodeParser("Sigmoid") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_SIGMOID_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sin_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sin_parser.cc deleted file mode 100644 index d02173496e..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sin_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_sin_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSinParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteSinParser"; - std::unique_ptr attr(new schema::SinT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Sin; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteSinParser("Sin", new TfliteSinParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sin_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sin_parser.h deleted file mode 100644 index 3b02203635..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sin_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_SIN_PARSER_H -#define PREDICT_TFLITE_SIN_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteSinParser : public TfliteNodeParser { - public: - TfliteSinParser() : TfliteNodeParser("Sin") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_SIN_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc index 9f74bddd8f..a18e624380 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_slice_parser.cc @@ -26,21 +26,30 @@ STATUS TfliteSliceParser::Parse(const std::unique_ptr &tflite const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteSliceParser"; std::unique_ptr attr(new schema::SliceT()); if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->begin)) { + MS_LOG(ERROR) << "get slice -> begin failed"; return RET_ERROR; } if (GetTfliteData(tfliteOp->inputs[2], tfliteTensors, tfliteModelBuffer, attr->size)) { + MS_LOG(ERROR) << "get slice -> size failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Slice; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Slice; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc index 07bb3a9507..87277a5872 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_softmax_parser.cc @@ -24,21 +24,30 @@ STATUS TfliteSoftmaxParser::Parse(const std::unique_ptr &tfli const std::vector> &tfliteTensors, const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) { + schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteSoftmaxParser"; std::unique_ptr attr(new schema::SoftMaxT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSoftmaxOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } - // attr->axis - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_SoftMax; - op->primitive->value.value = attr.release(); - } + attr->axis = -1; + + op->primitive->value.type = schema::PrimitiveType_SoftMax; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc index ea3c2c8a3f..9e3fd7db39 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_batch_nd_parser.cc @@ -27,22 +27,30 @@ STATUS TfliteSpaceToBatchNDParser::Parse(const std::unique_ptr> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteSpaceToBatchNDParser"; std::unique_ptr attr(new schema::SpaceToBatchNDT()); + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->blockShape)) { - MS_LOG(ERROR) << "spaceToBatchND -> blockShape get failed"; + MS_LOG(ERROR) << "get spaceToBatchND -> blockShape failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->paddings)) { - MS_LOG(ERROR) << "spaceToBatchND -> paddings get failed"; + MS_LOG(ERROR) << "get spaceToBatchND -> paddings failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_SpaceToBatchND; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_SpaceToBatchND; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc index e3435bc5f3..19d33c1bfa 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_space_to_depth_parser.cc @@ -27,22 +27,30 @@ STATUS TfliteSpaceToDepthParser::Parse(const std::unique_ptr const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteSpaceToDepthParser"; std::unique_ptr attr(new schema::SpaceToDepthT()); + const auto &tflite_attr = tflite_op->builtin_options.AsSpaceToDepthOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op:" << op->name.c_str() << " attr failed"; return RET_NULL_PTR; } - attr->blockSize = tflite_attr->block_size; + attr->format = schema::Format_NHWC; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_SpaceToDepth; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_SpaceToDepth; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc index 86ed3d0a2a..4a98f90d8f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_sparse_to_dense_parser.cc @@ -27,27 +27,36 @@ STATUS TfliteSparseToDenseParser::Parse(const std::unique_ptr const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteSparseToDenseParser"; std::unique_ptr attr(new schema::SparseToDenseT()); + attr->validateIndices = false; + if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->outputShape)) { - MS_LOG(ERROR) << "sparseToDense -> outputShape get failed"; + MS_LOG(ERROR) << "get sparseToDense -> outputShape failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[2], tflite_tensors, tflite_model_buffer, attr->sparseValue)) { - MS_LOG(ERROR) << "sparseToDense -> sparseValue get failed"; + MS_LOG(ERROR) << "get sparseToDense -> sparseValue failed"; return RET_ERROR; } if (GetTfliteData(tflite_op->inputs[3], tflite_tensors, tflite_model_buffer, attr->defaultValue)) { - MS_LOG(ERROR) << "sparseToDense -> defaultValue get failed"; + MS_LOG(ERROR) << "get sparseToDense -> defaultValue failed"; return RET_ERROR; } - attr->validateIndices = false; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_SparseToDense; - op->primitive->value.value = attr.release(); - } + + op->primitive->value.type = schema::PrimitiveType_SparseToDense; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc index eeb5d7c226..9e90bbfa03 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_parser.cc @@ -27,17 +27,38 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(INFO) << "parse TfliteSplitParser"; std::unique_ptr attr(new schema::SplitT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSplitOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } + auto num_splits = tflite_attr->num_splits; - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[1]].get()->shape; - auto axis = - *(reinterpret_cast(tfliteModelBuffer[tfliteTensors[tfliteOp->inputs[0]]->buffer]->data.data())); + const auto &shape_tensor = tfliteTensors[tfliteOp->inputs[1]]; + if (shape_tensor == nullptr) { + MS_LOG(ERROR) << "shape_tensor is null"; + return RET_NULL_PTR; + } + const auto tensor_shape = shape_tensor->shape; + const auto &axis_tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (axis_tensor == nullptr) { + MS_LOG(ERROR) << "axis_tensor is null"; + return RET_NULL_PTR; + } + auto axis = *(reinterpret_cast(tfliteModelBuffer[axis_tensor->buffer]->data.data())); if (axis < 0) { axis += tensor_shape.size(); } @@ -46,8 +67,6 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite return RET_ERROR; } attr->splitDim = axis; - - auto num_splits = tflite_attr->num_splits; if (tensor_shape[axis] % num_splits != 0) { MS_LOG(ERROR) << "num_splits can't divide tensor's length at axis " << axis; return RET_ERROR; @@ -58,11 +77,8 @@ STATUS TfliteSplitParser::Parse(const std::unique_ptr &tflite attr->sizeSplits.push_back(tensor_shape[axis] / num_splits); } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Split; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Split; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc index 938ce612c2..0fdf4b3a3f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_split_v_parser.cc @@ -25,23 +25,43 @@ STATUS TfliteSplitVParser::Parse(const std::unique_ptr &tflit const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(INFO) << "parse TfliteSplitVParser"; std::unique_ptr attr(new schema::SplitT()); + const auto &tflite_attr = tfliteOp->builtin_options.AsSplitVOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; return RET_NULL_PTR; } - attr->numberSplit = tflite_attr->num_splits; + if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->sizeSplits)) { - MS_LOG(ERROR) << "SPLIT_V get sizeSplits attr failed"; + MS_LOG(ERROR) << "get splite_v -> sizeSplits failed"; return RET_ERROR; } - auto axis = - *(reinterpret_cast(tfliteModelBuffer[tfliteTensors[tfliteOp->inputs[2]]->buffer]->data.data())); - const auto tensor_shape = tfliteTensors[tfliteOp->inputs[0]].get()->shape; + const auto &tensor = tfliteTensors[tfliteOp->inputs[0]]; + if (tensor == nullptr) { + MS_LOG(ERROR) << "tensor_shape is null"; + return RET_NULL_PTR; + } + auto tensor_shape = tensor->shape; + const auto &axis_tensor = tfliteTensors[tfliteOp->inputs[2]]; + if (axis_tensor == nullptr) { + MS_LOG(ERROR) << "axis_tensor is null"; + return RET_NULL_PTR; + } + auto axis = *(reinterpret_cast(tfliteModelBuffer[axis_tensor->buffer]->data.data())); if (axis < 0) { axis += tensor_shape.size(); } @@ -49,11 +69,10 @@ STATUS TfliteSplitVParser::Parse(const std::unique_ptr &tflit MS_LOG(ERROR) << "axis value too large"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Split; - op->primitive->value.value = attr.release(); - } + attr->splitDim = axis; + + op->primitive->value.type = schema::PrimitiveType_Split; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sqrt_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sqrt_parser.cc deleted file mode 100644 index e27ebfd47a..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sqrt_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_sqrt_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSqrtParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteSqrtParser"; - std::unique_ptr attr(new schema::SqrtT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Sqrt; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteSqrtParser("Sqrt", new TfliteSqrtParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sqrt_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sqrt_parser.h deleted file mode 100644 index 0b0ce97b78..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sqrt_parser.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_SQRT_PARSER_H -#define PREDICT_TFLITE_SQRT_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteSqrtParser : public TfliteNodeParser { - public: - TfliteSqrtParser() : TfliteNodeParser("Sqrt") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_SQRT_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_square_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_square_parser.cc deleted file mode 100644 index e577ce5f9a..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_square_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_square_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSquareParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteSquareParser"; - std::unique_ptr attr(new schema::SquareT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Square; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteSquareParser("Square", new TfliteSquareParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_square_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_square_parser.h deleted file mode 100644 index 7e349a6b89..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_square_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 LITE_TFLITE_SQUARE_PARSER_H -#define LITE_TFLITE_SQUARE_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteSquareParser : public TfliteNodeParser { - public: - TfliteSquareParser() : TfliteNodeParser("Square") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_SQUARE_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_squared_difference_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_squared_difference_parser.cc deleted file mode 100644 index 18488fb734..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_squared_difference_parser.cc +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_squared_difference_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSquaredDifferenceParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteSquaredDifferenceParser"; - std::unique_ptr attr(new schema::SquaredDifferenceT()); - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_SquaredDifference; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteSquaredDifferenceParser("SquaredDifference", new TfliteSquaredDifferenceParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_squared_difference_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_squared_difference_parser.h deleted file mode 100644 index 67dd05b109..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_squared_difference_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 LITE_TFLITE_SQUARED_DIFFERENCE_PARSER_H -#define LITE_TFLITE_SQUARED_DIFFERENCE_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteSquaredDifferenceParser : public TfliteNodeParser { - public: - TfliteSquaredDifferenceParser() : TfliteNodeParser("SquaredDifference") {} - - STATUS Parse(const std::unique_ptr &tflite_op, - const std::vector> &tflite_tensors, - const std::vector> &tflite_model_buffer, - const std::vector> &tflite_opset, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantized_model) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // LITE_TFLITE_SQUARED_DIFFERENCE_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc index 932acb90b0..bd6ee5f641 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_squeeze_parser.cc @@ -25,21 +25,28 @@ STATUS TfliteSqueezeParser::Parse(const std::unique_ptr &tfli const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteSqueezeParser"; - std::unique_ptr attr(new schema::SqueezeT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsSqueezeOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; return RET_NULL_PTR; } + MS_LOG(INFO) << "parse TfliteSqueezeParser"; + std::unique_ptr attr(new schema::SqueezeT()); + + const auto &tflite_attr = tfliteOp->builtin_options.AsSqueezeOptions(); + if (tflite_attr == nullptr) { + MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; + } attr->axis = tflite_attr->squeeze_dims; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Squeeze; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Squeeze; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc index 43d76b3c56..b6b7da18b1 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_stack_parser.cc @@ -25,11 +25,22 @@ STATUS TfliteStackParser::Parse(const std::unique_ptr &tflite const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteStackParser"; std::unique_ptr attr(new schema::StackT()); const auto &tflite_attr = tfliteOp->builtin_options.AsPackOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; + return RET_NULL_PTR; } attr->axis = tflite_attr->axis; @@ -37,11 +48,8 @@ STATUS TfliteStackParser::Parse(const std::unique_ptr &tflite attr->isScale.assign(tfliteTensors[tfliteOp->inputs[0]]->shape.begin(), tfliteTensors[tfliteOp->inputs[0]]->shape.end()); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Stack; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Stack; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc index 44843a550f..04f33beb16 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_strided_slice_parser.cc @@ -26,6 +26,16 @@ STATUS TfliteStridedSliceParser::Parse(const std::unique_ptr const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteStridedSliceParser"; std::unique_ptr attr(new schema::StridedSliceT()); const auto &tflite_attr = tflite_op->builtin_options.AsStridedSliceOptions(); @@ -55,11 +65,8 @@ STATUS TfliteStridedSliceParser::Parse(const std::unique_ptr attr->isScale.assign(tflite_tensors[tflite_op->inputs[0]]->shape.begin(), tflite_tensors[tflite_op->inputs[0]]->shape.end()); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_StridedSlice; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_StridedSlice; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc deleted file mode 100644 index 1a517f1490..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.cc +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "tools/converter/parser/tflite/tflite_sub_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSubParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteSubParser"; - std::unique_ptr attr(new schema::SubT()); - const auto &tfliteAttr = tfliteOp->builtin_options.AsSubOptions(); - if (tfliteAttr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name.c_str() << " attr failed"; - } - - auto weight_index = tfliteOp->inputs[1]; - const auto &weight_tensor = tfliteTensors[weight_index]; - std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { - MS_LOG(ERROR) << "parse weight failed"; - } - attr->activationType = GetActivationFunctionType(tfliteAttr->fused_activation_function); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Sub; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_tfliteSubParser("Sub", new TfliteSubParser()); -} // namespace lite -} // namespace mindspore - - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.h deleted file mode 100644 index f84c30c781..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sub_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_SUB_PARSER_H -#define PREDICT_TFLITE_SUB_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteSubParser : public TfliteNodeParser { - public: - TfliteSubParser() : TfliteNodeParser("Sub") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_SUB_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc deleted file mode 100644 index 9844d45467..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.cc +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include -#include -#include "mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.h" - -namespace mindspore { -namespace lite { -STATUS TfliteSumParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(INFO) << "parse TfliteSumParser"; - std::unique_ptr attr(new schema::ReduceT()); - const auto &tflite_attr = tfliteOp->builtin_options.AsReducerOptions(); - if (tflite_attr == nullptr) { - MS_LOG(ERROR) << "get op: " << op->name << " attr failed"; - return RET_NULL_PTR; - } - attr->mode = schema::ReduceMode_ReduceSum; - if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->axes)) { - MS_LOG(ERROR) << "SUM get axes attr failed"; - return RET_ERROR; - } - attr->keepDims = tflite_attr->keep_dims; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Reduce; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteSumParser("Sum", new TfliteSumParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.h deleted file mode 100644 index 6457be43f1..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_sum_parser.h +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_SUM_PARSER_H -#define PREDICT_TFLITE_SUM_PARSER_H - -#include -#include -#include "mindspore/lite/tools/converter/parser/tflite/tflite_node_parser.h" -#include "mindspore/lite/tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteSumParser : public TfliteNodeParser { - public: - TfliteSumParser() : TfliteNodeParser("Sum") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_SUM_PARSER_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc deleted file mode 100644 index f78b8fa71e..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.cc +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ - -#include "tools/converter/parser/tflite/tflite_tanh_parser.h" -#include -#include - -namespace mindspore { -namespace lite { -STATUS TfliteTanhParser::Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, - schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { - MS_LOG(DEBUG) << "parse TfliteTanhParser"; - std::unique_ptr attr(new schema::ActivationT()); - attr->type = schema::ActivationType_TANH; - - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Activation; - op->primitive->value.value = attr.release(); - } - return RET_OK; -} - -TfliteNodeRegister g_TfliteTanhParser("Tanh", new TfliteTanhParser()); -} // namespace lite -} // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.h b/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.h deleted file mode 100644 index 38a003d87a..0000000000 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tanh_parser.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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 PREDICT_TFLITE_TANH_PARSER_H -#define PREDICT_TFLITE_TANH_PARSER_H - -#include -#include -#include "tools/converter/parser/tflite/tflite_node_parser.h" -#include "tools/converter/parser/tflite/tflite_node_parser_registry.h" - -namespace mindspore { -namespace lite { -class TfliteTanhParser : public TfliteNodeParser { - public: - TfliteTanhParser() : TfliteNodeParser("Tanh") {} - - STATUS Parse(const std::unique_ptr &tfliteOp, - const std::vector> &tfliteTensors, - const std::vector> &tfliteModelBuffer, - const std::vector> &tfliteOpSet, schema::CNodeT *op, - TensorCache *tensor_cache, - bool quantizedModel) override; -}; -} // namespace lite -} // namespace mindspore - -#endif // PREDICT_TFLITE_TANH_PARSER_H - diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc index c3e259fa27..c73477ef3f 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_tile_parser.cc @@ -27,19 +27,26 @@ STATUS TfliteTileParser::Parse(const std::unique_ptr &tflite_ const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteTileParser"; std::unique_ptr attr(new schema::TileT()); if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->multiples)) { - MS_LOG(ERROR) << "tile -> multiples get failed"; + MS_LOG(ERROR) << "get tile -> multiples failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Tile; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Tile; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc index c086eab7d4..cd55c852b4 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_topk_v2_parser.cc @@ -27,18 +27,26 @@ STATUS TfliteTopKV2Parser::Parse(const std::unique_ptr &tflit const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteTopKV2Parser"; std::unique_ptr attr(new schema::TopKV2T()); if (GetTfliteData(tflite_op->inputs[1], tflite_tensors, tflite_model_buffer, attr->k)) { - MS_LOG(ERROR) << "topKV2 -> k get failed"; + MS_LOG(ERROR) << "get topKV2 -> k failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_TopKV2; - op->primitive->value.value = attr.release(); - } + + op->primitive->value.type = schema::PrimitiveType_TopKV2; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc index 829a813701..cf11963fba 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_transpose_parser.cc @@ -25,27 +25,38 @@ STATUS TfliteTransposeParser::Parse(const std::unique_ptr &tf const std::vector> &tfliteModelBuffer, const std::vector> &tfliteOpSet, schema::CNodeT *op, TensorCache *tensor_cache, bool quantizedModel) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteTransposeParser"; std::unique_ptr attr(new schema::TransposeT()); if (GetTfliteData(tfliteOp->inputs[1], tfliteTensors, tfliteModelBuffer, attr->perm)) { - MS_LOG(ERROR) << "parse Transpose attr perm failed"; + MS_LOG(ERROR) << "get transpose -> perm failed"; return RET_ERROR; } auto weight_index = tfliteOp->inputs[1]; const auto &weight_tensor = tfliteTensors[weight_index]; + if (weight_tensor == nullptr) { + MS_LOG(ERROR) << "weight_tensor is null"; + return RET_ERROR; + } std::vector weight_tensors{weight_tensor.get()}; - if (RET_OK != ParseWeight(weight_tensors, tfliteModelBuffer, tensor_cache, schema::Format_KHWC)) { + if (RET_OK != ParseTensor(weight_tensors, tfliteModelBuffer, tensor_cache, TF_CONST)) { MS_LOG(ERROR) << "parse weight failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Transpose; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Transpose; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc index 12131d606f..6860c01bab 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unique_parser.cc @@ -27,8 +27,19 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr &tflit const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteUniqueParser"; std::unique_ptr attr(new schema::UniqueT()); + const auto &tflite_attr = tflite_op->builtin_options.AsUniqueOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); @@ -36,11 +47,9 @@ STATUS TfliteUniqueParser::Parse(const std::unique_ptr &tflit } attr->outType = dtype_map[tflite_attr->idx_out_type]; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Unique; - op->primitive->value.value = attr.release(); - } + + op->primitive->value.type = schema::PrimitiveType_Unique; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc index eca413ba7a..a2ea8b5a6b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_unstack_parser.cc @@ -26,22 +26,29 @@ STATUS TfliteUnstackParser::Parse(const std::unique_ptr &tfli const std::vector> &tflite_model_buffer, const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "paser TfliteUnstackParser"; std::unique_ptr attr(new schema::UnstackT()); + const auto &tflite_attr = tflite_op->builtin_options.AsUnpackOptions(); if (tflite_attr == nullptr) { MS_LOG(ERROR) << "get op: %s attr failed", op->name.c_str(); return RET_NULL_PTR; } - attr->num = tflite_attr->num; attr->axis = tflite_attr->axis; - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Unstack; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_Unstack; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc index 0ead307e90..08d7a8932a 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_util.cc @@ -17,7 +17,9 @@ #include "tools/converter/parser/tflite/tflite_util.h" #include #include +#include #include "utils/log_adapter.h" +#include "include/errorcode.h" namespace mindspore { namespace lite { @@ -25,6 +27,7 @@ std::map tfMsActivationF {tflite::ActivationFunctionType_NONE, schema::ActivationType_NO_ACTIVATION}, {tflite::ActivationFunctionType_RELU, schema::ActivationType_RELU}, {tflite::ActivationFunctionType_RELU6, schema::ActivationType_RELU6}, + {tflite::ActivationFunctionType_TANH, schema::ActivationType_TANH}, }; schema::ActivationType GetActivationFunctionType(tflite::ActivationFunctionType tfliteAFType) { @@ -64,7 +67,7 @@ std::map tfMsOpTypeMap{ {tflite::BuiltinOperator_POW, "Pow"}, {tflite::BuiltinOperator_ARG_MIN, "Argmin"}, {tflite::BuiltinOperator_CEIL, "Ceil"}, - {tflite::BuiltinOperator_EXPAND_DIMS, "ExpandDims"}, + // {tflite::BuiltinOperator_EXPAND_DIMS, "ExpandDims"}, {tflite::BuiltinOperator_FILL, "Fill"}, {tflite::BuiltinOperator_DIV, "Div"}, {tflite::BuiltinOperator_FLOOR, "flOOR"}, @@ -136,9 +139,12 @@ std::string GetMSOpType(tflite::BuiltinOperator tfliteOpType) { } std::map type_map = { - {tflite::TensorType_FLOAT32, TypeId::kNumberTypeFloat32}, {tflite::TensorType_FLOAT16, TypeId::kNumberTypeFloat16}, - {tflite::TensorType_INT32, TypeId::kNumberTypeInt32}, {tflite::TensorType_UINT8, TypeId::kNumberTypeUInt8}, + {tflite::TensorType_FLOAT32, TypeId::kNumberTypeFloat32}, + {tflite::TensorType_FLOAT16, TypeId::kNumberTypeFloat16}, + {tflite::TensorType_INT32, TypeId::kNumberTypeInt32}, + {tflite::TensorType_UINT8, TypeId::kNumberTypeUInt8}, {tflite::TensorType_INT16, TypeId::kNumberTypeInt16}, + {tflite::TensorType_INT8, TypeId::kNumberTypeInt8}, }; TypeId GetTfliteDataType(const tflite::TensorType &tflite_data_type) { @@ -175,7 +181,21 @@ size_t GetDataTypeSize(const TypeId &data_type) { return sizeof(uint32_t); default: MS_LOG(ERROR) << "unsupport datatype"; + return RET_ERROR; } } + +void Split(const std::string &src_str, std::vector *dst_str, const std::string &chr) { + std::string ::size_type p1 = 0, p2 = src_str.find(chr); + while (std::string::npos != p2) { + dst_str->push_back(src_str.substr(p1, p2 - p1)); + p1 = p2 + chr.size(); + p2 = src_str.find(chr, p1); + } + if (p1 != src_str.length()) { + dst_str->push_back(src_str.substr(p1)); + } +} + } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_util.h b/mindspore/lite/tools/converter/parser/tflite/tflite_util.h index 3598c2f3a2..ee78e96a36 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_util.h +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_util.h @@ -14,19 +14,17 @@ * limitations under the License. */ -#ifndef MS_TFLITE_UTIL_H -#define MS_TFLITE_UTIL_H - +#ifndef MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_UTIL_H +#define MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_UTIL_H #include +#include #include "utils/log_adapter.h" #include "schema/inner/model_generated.h" #include "tools/converter/parser/tflite/schema_generated.h" #include "schema/inner/ops_generated.h" #include "ir/dtype/type_id.h" -// using namespace std; - namespace mindspore { namespace lite { schema::PadMode GetPadMode(tflite::Padding tflite_padmode); @@ -38,8 +36,10 @@ schema::ActivationType GetActivationFunctionType(tflite::ActivationFunctionType std::string GetMSOpType(tflite::BuiltinOperator tfliteOpType); TypeId GetTfliteDataType(const tflite::TensorType &tflite_data_type); + +void Split(const std::string &src_str, std::vector *dst_str, const std::string &chr); } // namespace lite } // namespace mindspore -#endif // MS_TFLITE_UTIL_H +#endif // MINDSPORE_LITE_TOOLS_CONVERTER_PARSER_TFLITE_UTIL_H diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc index e05e7cb507..d13b35a6d5 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_where_parser.cc @@ -27,18 +27,26 @@ STATUS TfliteWhereParser::Parse(const std::unique_ptr &tflite const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteWhereParser"; std::unique_ptr attr(new schema::WhereT()); if (GetTfliteData(tflite_op->inputs[0], tflite_tensors, tflite_model_buffer, attr->condition)) { - MS_LOG(ERROR) << "where -> condition get failed"; + MS_LOG(ERROR) << "get where -> condition failed"; return RET_ERROR; } - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_Where; - op->primitive->value.value = attr.release(); - } + + op->primitive->value.type = schema::PrimitiveType_Where; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc b/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc index 1393ab5701..fb88ba965b 100644 --- a/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc +++ b/mindspore/lite/tools/converter/parser/tflite/tflite_zeros_like_parser.cc @@ -27,14 +27,21 @@ STATUS TfliteZerosLikeParser::Parse(const std::unique_ptr &tf const std::vector> &tflite_opset, schema::CNodeT *op, TensorCache *tensor_cache, bool quantized_model) { + if (op == nullptr) { + MS_LOG(ERROR) << "op is null"; + return RET_NULL_PTR; + } + op->primitive = std::make_unique(); + if (op->primitive == nullptr) { + MS_LOG(ERROR) << "op->primitive is null"; + return RET_NULL_PTR; + } + MS_LOG(DEBUG) << "parse TfliteZerosLikeParser"; std::unique_ptr attr(new schema::ZerosLikeT()); - if (op != nullptr) { - op->primitive = std::make_unique(); - op->primitive->value.type = schema::PrimitiveType_ZerosLike; - op->primitive->value.value = attr.release(); - } + op->primitive->value.type = schema::PrimitiveType_ZerosLike; + op->primitive->value.value = attr.release(); return RET_OK; } diff --git a/mindspore/lite/tools/converter/quantizer/post_training.cc b/mindspore/lite/tools/converter/quantizer/post_training.cc index 10e0609add..bf149ff9cf 100644 --- a/mindspore/lite/tools/converter/quantizer/post_training.cc +++ b/mindspore/lite/tools/converter/quantizer/post_training.cc @@ -54,7 +54,7 @@ struct DivergInfo { size_t bit_num; int quant_max = 255; int quant_min = 0; - DivergInfo(CNodePtr cnode, int bins, size_t bits, int quant_max = 255, int quant_min = 0) { + DivergInfo(CNodePtr cnode, int bins, size_t bits, int quant_max, int quant_min) { this->cnode = cnode; this->bin_num = bins; this->bit_num = bits; @@ -81,6 +81,9 @@ struct DivergInfo { STATUS UpdateHistogram(const std::vector &data, const std::vector &shape) { for (auto value : data) { + if (value == 0) { + continue; + } int bin_index = std::min(static_cast(std::fabs(value) / this->interval), bin_num - 1); this->histogram[bin_index]++; } @@ -470,8 +473,10 @@ STATUS Calibrator::ReadConfig() { Calibrator::Calibrator(string path, size_t bitNum, int quantMax, int quantMin) : config_path_(path), bit_num_(bitNum), quant_max_(quantMax), quant_min_(quantMin) {} -PostTrainingQuantizer::PostTrainingQuantizer(FuncGraphPtr graph, string path, int bit_num, TypeId target_type) +PostTrainingQuantizer::PostTrainingQuantizer(FuncGraphPtr graph, string path, int bit_num, TypeId target_type, + bool per_channel) : Quantizer(graph) { + this->per_channel_ = per_channel; this->bit_num = bit_num; this->target_type_ = target_type; if (target_type == kNumberTypeInt8) { @@ -533,7 +538,7 @@ STATUS PostTrainingQuantizer::DoWeightQuant(AnfNodePtr node) { } auto parameter = std::dynamic_pointer_cast(node); ParamValueLitePtr paramValue = std::dynamic_pointer_cast(parameter->default_param()); - auto status = QuantFilter(paramValue, QuantType_PostTraining, quant_max, quant_min, bit_num); + auto status = QuantFilter(paramValue, QuantType_PostTraining, quant_max, quant_min, bit_num, per_channel_); if (status != RET_OK) { MS_LOG(ERROR) << "QuantFilter failed: " << status; return status; @@ -670,18 +675,32 @@ STATUS PostTrainingQuantizer::QuantNode() { MS_LOG(ERROR) << "PrimitiveT_value is nullptr"; continue; } - if (input_scale.find(cnode) == input_scale.end()) { primitiveT_value->SetQuantType(schema::QuantType_QUANT_NONE); continue; } auto input_vec = cnode->inputs(); auto op_name = cnode->fullname_with_scope(); + auto op_type = primitiveT_value->GetPrimitiveT()->value.type; MS_LOG(INFO) << "OpName: " << op_name; - if (input_vec.size() <= 3 && op_name != "Conv2D" && op_name != "DepthwiseConv2D") { - MS_LOG(INFO) << "todo(x): "; - // int32_t qnodeOutputZeropoint = outputZeropoint[cnode]; - // p->AddAttr(kInputTensorDataType, MakeValue((int)targetType)); + if (op_type != PrimitiveType_Conv2D && op_type != PrimitiveType_DepthwiseConv2D) { + for (auto i = 1; i < cnode->inputs().size(); i++) { + auto input_node = cnode->input(i); + if (!input_node->isa()) { + MS_LOG(WARNING) << "node: " << cnode_name << " input " << i << " not a cnode"; + continue; + } + auto input_cnode = std::dynamic_pointer_cast(input_node); + auto input_cnode_primitiveT_value = GetValueNode>(input_cnode->input(0)); + if (input_cnode_primitiveT_value == nullptr) { + MS_LOG(DEBUG) << "input: " << i << " " << input_cnode->fullname_with_scope() << ": " + << " PrimitiveTValue is null"; + continue; + } + for (auto &quant_param : input_cnode_primitiveT_value->GetOutputQuantParams()) { + primitiveT_value->AddInputQuantParam(quant_param); + } + } } else { // do input quant double scale = input_scale[cnode]; @@ -920,7 +939,7 @@ STATUS PostTrainingQuantizer::DoQuantize(FuncGraphPtr funcGraph) { return RET_ERROR; } - auto ret = session_->CompileGraph(model.get()); + auto ret = session_->CompileGraph(model); if (ret != lite::RET_OK) { MS_LOG(ERROR) << "compile graph error"; return RET_ERROR; diff --git a/mindspore/lite/tools/converter/quantizer/post_training.h b/mindspore/lite/tools/converter/quantizer/post_training.h index d000df53ef..06273396b8 100644 --- a/mindspore/lite/tools/converter/quantizer/post_training.h +++ b/mindspore/lite/tools/converter/quantizer/post_training.h @@ -55,15 +55,18 @@ struct ConfigParam { class PostTrainingQuantizer : public Quantizer { public: - PostTrainingQuantizer(FuncGraphPtr graph, std::string path, int bit_num, TypeId target_type = kNumberTypeInt8); + PostTrainingQuantizer(FuncGraphPtr graph, std::string path, int bit_num, TypeId target_type = kNumberTypeInt8, + bool per_channel = false); STATUS DoQuantize(FuncGraphPtr funcGraph) override; size_t bit_num; - int quant_max{255}; - int quant_min{0}; + int quant_max{127}; + int quant_min{-128}; private: + bool per_channel_; + TypeId target_type_{kNumberTypeInt8}; std::unique_ptr calibrator_; diff --git a/mindspore/lite/tools/converter/quantizer/quant_cast.cc b/mindspore/lite/tools/converter/quantizer/quant_cast.cc index 0d4857c182..f924cda6ef 100644 --- a/mindspore/lite/tools/converter/quantizer/quant_cast.cc +++ b/mindspore/lite/tools/converter/quantizer/quant_cast.cc @@ -25,10 +25,11 @@ namespace mindspore::lite::quant { ValueNodePtr NewQuantCastValueNode(int src_type, int dst_type, const std::vector &quant_params) { std::unique_ptr primitive = std::make_unique(); schema::QuantDTypeCastT quant_dtype_cast; - quant_dtype_cast.srcT = src_type; // kNumberTypeUInt8; + quant_dtype_cast.srcT = src_type; // kNumberTypeInt8; quant_dtype_cast.dstT = dst_type; // kNumberTypeFloat32; primitive->value.Set(quant_dtype_cast); auto primTValue = std::make_shared(primitive.release()); + primTValue->SetQuantType(schema::QuantType_PostTraining); for (auto &quant_param : quant_params) { primTValue->AddInputQuantParam(quant_param); } @@ -52,7 +53,7 @@ STATUS QuantCast::Run(FuncGraphPtr graph) { if (first) { if (curnode_quant_type == schema::QuantType_PostTraining && inputDataDType == kNumberTypeFloat32) { auto value_node = - NewQuantCastValueNode(kNumberTypeFloat32, kNumberTypeUInt8, primitiveT_value->GetInputQuantParams()); + NewQuantCastValueNode(kNumberTypeFloat32, kNumberTypeInt8, primitiveT_value->GetInputQuantParams()); std::vector op_inputs = {value_node, cnode->input(1)}; auto quant_cast_cnode = graph->NewCNode(op_inputs); quant_cast_cnode->set_fullname_with_scope(cnode->fullname_with_scope() + "_quant_cast"); @@ -82,11 +83,11 @@ STATUS QuantCast::Run(FuncGraphPtr graph) { ValueNodePtr value_node = nullptr; if (curnode_quant_type == schema::QuantType_PostTraining && input_cnode_quant_type == schema::QuantType_QUANT_NONE) { - value_node = NewQuantCastValueNode(kNumberTypeFloat32, kNumberTypeUInt8, - input_cnode_primitiveT_value->GetInputQuantParams()); + value_node = NewQuantCastValueNode(kNumberTypeFloat32, kNumberTypeInt8, + primitiveT_value->GetInputQuantParams()); } else if (curnode_quant_type == schema::QuantType_QUANT_NONE && input_cnode_quant_type == schema::QuantType_PostTraining) { - value_node = NewQuantCastValueNode(kNumberTypeUInt8, kNumberTypeFloat32, + value_node = NewQuantCastValueNode(kNumberTypeInt8, kNumberTypeFloat32, input_cnode_primitiveT_value->GetInputQuantParams()); } if (value_node == nullptr) { diff --git a/mindspore/lite/tools/converter/quantizer/quantize_util.cc b/mindspore/lite/tools/converter/quantizer/quantize_util.cc index 0e0ba14f93..151bdacd52 100644 --- a/mindspore/lite/tools/converter/quantizer/quantize_util.cc +++ b/mindspore/lite/tools/converter/quantizer/quantize_util.cc @@ -98,7 +98,7 @@ bool QuantStrategy::CanOpPostQuantized(AnfNodePtr &node) const { static const std::vector uint8OpList = { schema::PrimitiveType_Nchw2Nhwc, schema::PrimitiveType_Nhwc2Nchw, schema::PrimitiveType_Conv2D, schema::PrimitiveType_DepthwiseConv2D, schema::PrimitiveType_Add, schema::PrimitiveType_Pooling, - schema::PrimitiveType_Concat, schema::PrimitiveType_SoftMax, schema::PrimitiveType_Reshape, + schema::PrimitiveType_Concat, /*schema::PrimitiveType_SoftMax,*/ schema::PrimitiveType_Reshape, schema::PrimitiveType_Activation}; return IsContain(uint8OpList, type); } @@ -242,64 +242,122 @@ STATUS CalQuantizationParams(std::unique_ptr &quantParam, double return RET_OK; } -STATUS QuantFilter(ParamValueLitePtr &weightPtr, QuantType quantType, int quant_max, int quant_min, size_t bitNum) { +STATUS QuantFilter(ParamValueLitePtr &weightPtr, QuantType quantType, int quant_max, int quant_min, size_t bitNum, + bool per_channel) { + if (per_channel) { + // per channel auto dims = weightPtr->tensor_shape(); if (dims.size() < 1) { - MS_LOG(ERROR) << "weight dims size error"; - return RET_ERROR; + MS_LOG(ERROR) << "weight dims size error"; + return RET_ERROR; } - uint32_t channels = dims[0]; + // todo(x) + uint32_t channels = dims[3]; if (channels == 0) { - MS_LOG(ERROR) << "channels error 0"; - return RET_ERROR; + MS_LOG(ERROR) << "channels error 0"; + return RET_ERROR; } size_t shapeSize = weightPtr->tensor_shape_size(); size_t oneFilterSize = shapeSize / channels; auto *rawDatas = reinterpret_cast(weightPtr->tensor_addr()); if (rawDatas == nullptr) { - MS_LOG(ERROR) << "rawDatas is nullptr"; - return RET_ERROR; + MS_LOG(ERROR) << "rawDatas is nullptr"; + return RET_ERROR; } weightPtr->quant_param().clear(); - vector qDatas(shapeSize); + vector qDatas(shapeSize); for (uint32_t i = 0; i < channels; i++) { - float min = 0; - float max = 0; - // find min and max - for (uint32_t j = 0; j < oneFilterSize; j++) { - min = std::min(min, rawDatas[j + i * oneFilterSize]); - max = std::max(max, rawDatas[j + i * oneFilterSize]); - } + float min = 0; + float max = 0; + // find min and max + for (uint32_t j = 0; j < oneFilterSize; j++) { + min = std::min(min, rawDatas[j + i * oneFilterSize]); + max = std::max(max, rawDatas[j + i * oneFilterSize]); + } - std::unique_ptr quantParam = std::unique_ptr(new AnfQuantParam); - STATUS status = CalQuantizationParams(quantParam, min, max, false, quant_max, quant_min, bitNum); - if (status != RET_OK) { - MS_LOG(ERROR) << "CalQuantizationParams failed" << status; - return status; - } - // update data and datatype - for (uint32_t j = 0; j < oneFilterSize; j++) { - float rawData = rawDatas[j + i * oneFilterSize]; - auto qData = QuantizeData(rawData, quantParam.get()); - qDatas[j + i * oneFilterSize] = qData; - } + std::unique_ptr quantParam = std::unique_ptr(new AnfQuantParam); + STATUS status = CalQuantizationParams(quantParam, min, max, false, quant_max, quant_min, bitNum); + if (status != RET_OK) { + MS_LOG(ERROR) << "CalQuantizationParams failed" << status; + return status; + } + // update data and datatype + for (uint32_t j = 0; j < oneFilterSize; j++) { + float rawData = rawDatas[j + i * oneFilterSize]; + auto qData = QuantizeData(rawData, quantParam.get(), quant_max, quant_min); + qDatas[j + i * oneFilterSize] = qData; + } - weightPtr->set_quant_param(quantParam); + weightPtr->set_quant_param(quantParam); } auto ret = memcpy_s(const_cast(rawDatas), weightPtr->tensor_size(), - qDatas.data(), shapeSize * sizeof(uint8_t)); + qDatas.data(), shapeSize * sizeof(int8_t)); if (ret != EOK) { - MS_LOG(ERROR) << "memcpy error: " << ret; - return RET_ERROR; + MS_LOG(ERROR) << "memcpy error: " << ret; + return RET_ERROR; } if (quantType == QuantType_WeightQuant) { - PostBitPack(const_cast(rawDatas), shapeSize, bitNum); + PostBitPack(const_cast(rawDatas), shapeSize, bitNum); } weightPtr->set_tensor_type(kNumberTypeInt8); weightPtr->set_tensor_size(shapeSize * sizeof(int8_t)); + } else { + // per layer + size_t shapeSize = weightPtr->tensor_shape_size(); + auto *rawDatas = static_cast(weightPtr->tensor_addr()); + if (rawDatas == nullptr) { + MS_LOG(ERROR) << "rawDatas is nullptr"; + return RET_ERROR; + } + + weightPtr->quant_param().clear(); + vector qDatas(shapeSize); + + float min = 0; + float max = 0; + for (uint32_t i = 0; i < shapeSize; i++) { + // find max min + min = std::min(min, rawDatas[i]); + max = std::max(max, rawDatas[i]); + } + + std::unique_ptr quantParam = std::unique_ptr(new AnfQuantParam); + STATUS status = CalQuantizationParams(quantParam, min, max, false, quant_max, quant_min, bitNum); + if (status != RET_OK) { + MS_LOG(ERROR) << "CalQuantizationParams failed" << status; + return status; + } + // update data and datatype + for (uint32_t i = 0; i < shapeSize; i++) { + float rawData = rawDatas[i]; + auto quant_data = std::round(rawData / quantParam->scale + quantParam->zeroPoint); + if (quant_data > quant_max) { + qDatas[i] = quant_max; + } else if (quant_data < quant_min) { + qDatas[i] = quant_min; + } else { + qDatas[i] = static_cast(quant_data); + } + } + + weightPtr->set_quant_param(quantParam); + auto ret = memcpy_s(rawDatas, weightPtr->tensor_size() * sizeof(int8_t), + qDatas.data(), shapeSize * sizeof(int8_t)); + if (ret != EOK) { + MS_LOG(ERROR) << "memcpy error: " << ret; + return RET_ERROR; + } + if (quantType == QuantType_WeightQuant) { + PostBitPack(rawDatas, shapeSize, bitNum); + } + + weightPtr->set_tensor_type(kNumberTypeInt8); + weightPtr->set_tensor_size(shapeSize * sizeof(int8_t)); + } + return RET_OK; } diff --git a/mindspore/lite/tools/converter/quantizer/quantize_util.h b/mindspore/lite/tools/converter/quantizer/quantize_util.h index b310d586ae..a287473458 100644 --- a/mindspore/lite/tools/converter/quantizer/quantize_util.h +++ b/mindspore/lite/tools/converter/quantizer/quantize_util.h @@ -63,41 +63,30 @@ STATUS CalQuantizationParams(std::unique_ptr &quantParam, double bool narrowRange, int quant_max, int quant_min, int num_bits); template -T QuantizeData(const float originData, const AnfQuantParam *quantParam) { +T QuantizeData(float originData, const AnfQuantParam *quantParam, int quant_max, int quant_min) { MS_ASSERT(quantParam != nullptr); MS_ASSERT(quantParam->inited); const auto scale = quantParam->scale; - const auto zeroPoint = quantParam->zeroPoint; - const auto numBit = quantParam->numBits; + const int zeroPoint = quantParam->zeroPoint; const auto narrowRange = quantParam->narrowRange; - const double maxLimit = static_cast((1 << (unsigned int)numBit) - 1 - zeroPoint) * scale; - double minLimit; - if (narrowRange) { - minLimit = static_cast(1 - zeroPoint) * scale; - } else { - minLimit = static_cast(0 - zeroPoint) * scale; - } + const int maxLimit = quant_max; + const int minLimit = quant_min; + return [maxLimit, minLimit, zeroPoint, scale, narrowRange, originData] { - double tmp = 0.0f; - if (originData > maxLimit) { - tmp = maxLimit; - } else if (originData < minLimit) { - tmp = minLimit; - } else { - tmp = originData; + int quant_data = std::round(originData / scale + zeroPoint); + if (quant_data > maxLimit) { + quant_data = maxLimit; + } else if (quant_data < minLimit) { + quant_data = minLimit; } - auto quantData = static_cast(std::round(tmp / scale + zeroPoint)); - if (quantData == 0 && narrowRange) { - quantData++; - } - return quantData; + return static_cast(quant_data); }(); } void CalFakeNode(const AnfNodePtr &inTensor); STATUS QuantFilter(ParamValueLitePtr &weightPtr, QuantType quantType, int quant_max, int quant_min, - size_t bitNum = UINT8_QUANTIZATION); + size_t bitNum = UINT8_QUANTIZATION, bool per_channel = false); STATUS PostBitPack(float *weights, size_t shapeSize, size_t bitNum = UINT8_QUANTIZATION); diff --git a/mindspore/lite/tools/optimizer/fusion/conv_biasadd_fusion.cc b/mindspore/lite/tools/optimizer/fusion/conv_biasadd_fusion.cc index 2d8d6a8678..c7ebce2232 100644 --- a/mindspore/lite/tools/optimizer/fusion/conv_biasadd_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/conv_biasadd_fusion.cc @@ -89,10 +89,10 @@ void GenConvNewBias(const FuncGraphPtr &func_graph, const CNodePtr &conv_node, c auto add_weight_param = bias_add_weight->cast()->default_param(); auto add_weight_tensor = std::dynamic_pointer_cast(add_weight_param); auto add_weight_data = reinterpret_cast(add_weight_tensor->tensor_addr()); - - if (add_weight_tensor->tensor_shape().empty()) { - if (EOK != memset_s(add_bias_data, kernel_nums * sizeof(float), *add_weight_data, kernel_nums * sizeof(float))) { - MS_LOG(EXCEPTION) << "memset_s conv_bias_data failed"; + auto add_weight_shape = add_weight_tensor->tensor_shape(); + if (add_weight_shape.empty() || (add_weight_shape.size() == 1 && add_weight_shape[0] ==1)) { + for (size_t i = 0; i < kernel_nums; i++) { + add_bias_data[i] = *add_weight_data; } } else { if (EOK != memcpy_s(add_bias_data, kernel_nums * sizeof(float), add_weight_data, kernel_nums * sizeof(float))) { diff --git a/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc b/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc index ee7e56de6c..e4f346e0cf 100644 --- a/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc @@ -145,8 +145,8 @@ const { // conv has bias,bias_flag true bool bias_flag = false; if (conv_bias_node != nullptr) { - auto bias_weight_param = conv_weight_node->cast()->default_param(); - auto bias_tensor = std::dynamic_pointer_cast(bias_weight_param); + auto conv_bias_param = conv_bias_node->cast()->default_param(); + auto bias_tensor = std::dynamic_pointer_cast(conv_bias_param); bias_data = reinterpret_cast(bias_tensor->tensor_addr()); bias_flag = true; } else { @@ -187,7 +187,7 @@ const void ConvTransformFusion::CalNewBiasTensor(float *bias_data, int kernel_nu MS_ASSERT(bias_data != nullptr); if (bias_flag) { auto tmp_bias_data = new(std::nothrow) float[kernel_num]; - if (EOK != memset_s(bias_data, kernel_num * sizeof(float), 0, kernel_num * sizeof(float))) { + if (EOK != memset_s(tmp_bias_data, kernel_num * sizeof(float), 0, kernel_num * sizeof(float))) { MS_LOG(EXCEPTION) << "memset bias data failed"; } for (size_t i = 0; i < kernel_num; i++) { diff --git a/mindspore/lite/tools/time_profile/time_profile.cc b/mindspore/lite/tools/time_profile/time_profile.cc index 65b375c284..1f03189c31 100644 --- a/mindspore/lite/tools/time_profile/time_profile.cc +++ b/mindspore/lite/tools/time_profile/time_profile.cc @@ -42,12 +42,14 @@ int TimeProfile::GenerateInputData() { auto input_data = tensor->MutableData(); if (input_data == nullptr) { MS_LOG(ERROR) << "MallocData for inTensor failed"; + return RET_ERROR; } MS_ASSERT(tensor->GetData() != nullptr); auto tensor_byte_size = tensor->Size(); auto status = GenerateRandomData(tensor_byte_size, input_data); if (status != RET_OK) { - MS_LOG(ERROR) << "Generate RandomData for inTensor failed %d" << status; + MS_LOG(ERROR) << "Generate RandomData for inTensor failed " << status; + return RET_ERROR; } } return RET_OK; @@ -63,10 +65,14 @@ int TimeProfile::ReadInputFile() { size_t size; char *bin_buf = ReadFile(_flags->in_data_path_.c_str(), &size); - + if (bin_buf == nullptr) { + MS_LOG(ERROR) << "Input data file error, required: "; + return RET_ERROR; + } auto tensor_data_size = inTensor->Size(); if (size != tensor_data_size) { - MS_LOG(ERROR) << "Input binary file size error, required: %zu, in fact: %zu" << tensor_data_size << size; + MS_LOG(ERROR) << "Input binary file size error, required: " << tensor_data_size << " in fact: %zu" << size; + return RET_ERROR; } auto input_data = inTensor->MutableData(); memcpy(input_data, bin_buf, tensor_data_size); @@ -79,11 +85,13 @@ int TimeProfile::LoadInput() { auto status = GenerateInputData(); if (status != RET_OK) { MS_LOG(ERROR) << "Generate input data error " << status; + return RET_ERROR; } } else { auto status = ReadInputFile(); if (status != RET_OK) { MS_LOG(ERROR) << "ReadInputFile error, " << status; + return RET_ERROR; } } return RET_OK; @@ -93,7 +101,8 @@ int TimeProfile::InitSession() { size_t size = 0; char *graph_buf = ReadFile(_flags->model_path_.c_str(), &size); if (graph_buf == nullptr) { - MS_LOG(ERROR) << "Load graph failed, path %s" << _flags->model_path_; + MS_LOG(ERROR) << "Load graph failed, path " << _flags->model_path_; + return RET_ERROR; } auto ctx = new lite::Context; @@ -104,6 +113,7 @@ int TimeProfile::InitSession() { session_ = session::LiteSession::CreateSession(ctx); if (session_ == nullptr) { MS_LOG(ERROR) << "New session failed while running."; + return RET_ERROR; } return RET_OK; @@ -165,17 +175,31 @@ int TimeProfile::Init() { MS_LOG(INFO) << "InDataPath = " << _flags->in_data_path_; MS_LOG(INFO) << "LoopCount = " << _flags->loop_count_; MS_LOG(INFO) << "NumThreads = " << _flags->num_threads_; - if (_flags->cpu_bind_mode_ == -1) { + + if (_flags->num_threads_ < 1) { + MS_LOG(ERROR) << "NumThreads: " << _flags->num_threads_ << " must greater than or equal 1"; + return RET_ERROR; + } + + if (_flags->loop_count_ < 1) { + MS_LOG(ERROR) << "LoopCount: " << _flags->loop_count_ << " must greater than or equal 1"; + return RET_ERROR; + } + + if (_flags->cpu_bind_mode_ == CpuBindMode::MID_CPU) { MS_LOG(INFO) << "cpuBindMode = MID_CPU"; - } else if (_flags->cpu_bind_mode_ == 1) { + } else if (_flags->cpu_bind_mode_ == CpuBindMode::HIGHER_CPU) { MS_LOG(INFO) << "cpuBindMode = HIGHER_CPU"; - } else { + } else if (_flags->cpu_bind_mode_ == CpuBindMode::NO_BIND) { MS_LOG(INFO) << "cpuBindMode = NO_BIND"; + } else { + MS_LOG(ERROR) << "cpuBindMode Error"; + return RET_ERROR; } if (_flags->model_path_.empty()) { MS_LOG(ERROR) << "modelPath is required"; - return 1; + return RET_ERROR; } auto status = InitSession(); @@ -274,11 +298,11 @@ int TimeProfile::RunTimeProfile() { char *graphBuf = ReadFile(_flags->model_path_.c_str(), &size); if (graphBuf == nullptr) { MS_LOG(ERROR) << "Load graph failed while running %s", modelName.c_str(); - return 1; + return RET_ERROR; } auto model = lite::Model::Import(graphBuf, size); - auto ret = session_->CompileGraph(model.get()); + auto ret = session_->CompileGraph(model); if (ret != RET_OK) { MS_LOG(ERROR) << "Compile graph failed."; return RET_ERROR; @@ -300,6 +324,7 @@ int TimeProfile::RunTimeProfile() { ret = session_->RunGraph(before_call_back_, after_call_back_); if (ret != RET_OK) { MS_LOG(ERROR) << "Run graph failed."; + return RET_ERROR; } auto outputs = session_->GetOutputs(); @@ -307,22 +332,12 @@ int TimeProfile::RunTimeProfile() { uint64_t time = run_end - run_begin; time_avg += time; session_->BindThread(false); - /* - for(auto &output : outputs) { - for (auto &outputTensor : output.second) { - delete outputTensor; - } - }*/ outputs.clear(); } time_avg /= _flags->loop_count_; float runCost = static_cast(time_avg) / 1000.0f; - if (ret != RET_OK) { - MS_LOG(ERROR) << "Run session failed."; - } - const std::vector per_op_name = {"opName", "avg(ms)", "percent", "calledTimes", "opTotalTime"}; const std::vector per_op_type = {"opType", "avg(ms)", "percent", "calledTimes", "opTotalTime"}; PrintResult(per_op_name, op_times_by_name_); @@ -336,6 +351,8 @@ int TimeProfile::RunTimeProfile() { } ms_inputs_.clear(); delete graphBuf; + delete session_; + delete model; return ret; } @@ -358,11 +375,13 @@ int RunTimeProfile(int argc, const char **argv) { auto ret = time_profile.Init(); if (ret != RET_OK) { MS_LOG(ERROR) << "Init TimeProfile failed."; + return RET_ERROR; } ret = time_profile.RunTimeProfile(); if (ret != RET_OK) { MS_LOG(ERROR) << "Run TimeProfile failed."; + return RET_ERROR; } return RET_OK; diff --git a/mindspore/mindrecord/tools/tfrecord_to_mr.py b/mindspore/mindrecord/tools/tfrecord_to_mr.py index c351f4307f..7b71697942 100644 --- a/mindspore/mindrecord/tools/tfrecord_to_mr.py +++ b/mindspore/mindrecord/tools/tfrecord_to_mr.py @@ -104,7 +104,7 @@ class TFRecordToMR: Args: source (str): the TFRecord file to be transformed. destination (str): the MindRecord file path to tranform into. - feature_dict (dict): a dictionary than states the feature type, i.e. + feature_dict (dict): a dictionary that states the feature type, i.e. feature_dict = {"xxxx": tf.io.FixedLenFeature([], tf.string), \ "yyyy": tf.io.FixedLenFeature([], tf.int64)} diff --git a/mindspore/nn/cell.py b/mindspore/nn/cell.py index 93375d15dd..024f93f5d3 100755 --- a/mindspore/nn/cell.py +++ b/mindspore/nn/cell.py @@ -33,7 +33,7 @@ from ..common.tensor import Tensor class Cell: """ - Base class for all neural network. + Base class for all neural networks. A 'Cell' could be a single neural network cell, such as conv2d, relu, batch_norm, etc. or a composition of cells to constructing a network. @@ -42,8 +42,8 @@ class Cell: In general, the autograd algorithm will automatically generate the implementation of the gradient function, but if bprop method is implemented, the gradient function will be replaced by the bprop. The bprop implementation will receive a Tensor `dout` containing the gradient - of the loss w.r.t. the output, and a Tensor `out` containing the forward result. The bprop need to compute the - gradient of the loss w.r.t. the inputs, gradient of the loss w.r.t. Parameter variables is not supported + of the loss w.r.t. the output, and a Tensor `out` containing the forward result. The bprop needs to compute the + gradient of the loss w.r.t. the inputs, gradient of the loss w.r.t. Parameter variables are not supported currently. Args: @@ -138,7 +138,7 @@ class Cell: """ Update the all child cells' self.param_prefix. - After invoked, can get all the cell's children's name prefix by '_param_prefix'. + After being invoked, it can get all the cell's children's name prefix by '_param_prefix'. """ cells_name = self.cells_and_names() @@ -147,9 +147,9 @@ class Cell: def update_cell_type(self, cell_type): """ - Update current cell type mainly identify if quantization aware training network. + Update the current cell type mainly identify if quantization aware training network. - After invoked, can set the cell type to 'cell_type'. + After being invoked, it can set the cell type to 'cell_type'. """ self.cell_type = cell_type @@ -346,7 +346,7 @@ class Cell: Please refer to the usage in source code of `mindspore.common._Executor.compile`. Args: - params (dict): The parameters dictionary used for init data graph. + params (dict): The parameters dictionary used for initializing the data graph. """ if params is None: params = self.parameters_dict() @@ -499,7 +499,7 @@ class Cell: """ Adds a child cell to the current cell. - Inserts a subcell with given name to current cell. + Inserts a subcell with a given name to the current cell. Args: child_name (str): Name of the child cell. @@ -534,7 +534,7 @@ class Cell: def init_parameters_data(self, auto_parallel_mode=False): """ - Init all parameters' data and replace the original saved parameters in cell. + Initialize all parameters and replace the original saved parameters in cell. Notes: trainable_params() and other similar interfaces may return different parameter instance after @@ -655,7 +655,7 @@ class Cell: Yields parameters of this cell. If `expand` is True, yield parameters of this cell and all subcells. Args: - expand (bool): If True, yields parameters of this cell and all subcells. Otherwise, yields only parameters + expand (bool): If True, yields parameters of this cell and all subcells. Otherwise, only yield parameters that are direct members of this cell. Default: True. Examples: @@ -682,7 +682,7 @@ class Cell: Args: name_prefix (str): Namespace. Default: ''. - expand (bool): If True, yields parameters of this cell and all subcells. Otherwise, yields only parameters + expand (bool): If True, yields parameters of this cell and all subcells. Otherwise, only yield parameters that are direct members of this cell. Default: True. Examples: @@ -772,7 +772,7 @@ class Cell: return self._scope def generate_scope(self): - """Generate the scope for every cell object in the network.""" + """Generate the scope for each cell object in the network.""" for name, cell in self._children_scope_recursive(): cell._set_scope(name) @@ -819,14 +819,14 @@ class Cell: `mindspore.train.amp.build_train_network`. Note: - Call multiple times will overwrite the previous. + Multiple calls will overwrite. Args: dst_type (:class:`mindspore.dtype`): Transfer Cell to Run with dst_type. dst_type can be `mindspore.dtype.float16` or `mindspore.dtype.float32`. Raises: - ValueError: If dst_type is not float32 or float16. + ValueError: If dst_type is not float32 nor float16. """ if dst_type not in (mstype.float16, mstype.float32): raise ValueError("dst_type should inside float32 or float16.") @@ -871,8 +871,8 @@ class Cell: Set the cell to auto parallel mode. Note: - If a cell needs to use auto parallel or semi auto parallel mode for training, evaluation or prediction, - this interface needs to be called for the cell. + If a cell needs to use the auto parallel or semi auto parallel mode for training, evaluation or prediction, + this interface needs to be called by the cell. """ self._auto_parallel_mode = True self.add_flags(auto_parallel=True) @@ -890,9 +890,9 @@ class Cell: Set the cell backward hook function. Note that this function is only supported in Pynative Mode. Note: - fn should be defined as following code shows, `cell_name` is the name of registered cell, - `grad_input` is gradient passed to the cell, `grad_output` is the gradient computed and pass to - next cell or primitve, which may be modified and return. + fn should be defined as the following code. `cell_name` is the name of registered cell. + `grad_input` is gradient passed to the cell. `grad_output` is the gradient computed and passed to the + next cell or primitve, which may be modified and returned. >>> hook_fn(cell_name, grad_input, grad_output) -> Tensor or None Args: @@ -907,7 +907,7 @@ class Cell: Set whether the trainable parameter is updated by parameter server. Note: - This only works when running task in parameter server mode. + It only works when a running task is in the parameter server mode. Args: recurse (bool): Whether sets the trainable parameters of subcells. Default: True. diff --git a/mindspore/nn/layer/basic.py b/mindspore/nn/layer/basic.py index f41268b6bf..a822cf7567 100644 --- a/mindspore/nn/layer/basic.py +++ b/mindspore/nn/layer/basic.py @@ -172,7 +172,7 @@ class Dense(Cell): bias_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable bias_init parameter. The dtype is same as input x. The values of str refer to the function `initializer`. Default: 'zeros'. has_bias (bool): Specifies whether the layer uses a bias vector. Default: True. - activation (str): activate function applied to the output of the fully connected layer, eg. 'relu'. + activation (str): activate function applied to the output of the fully connected layer, eg. 'ReLU'. Default: None. Raises: diff --git a/mindspore/nn/layer/container.py b/mindspore/nn/layer/container.py index ed36a1dd5f..c881f41744 100644 --- a/mindspore/nn/layer/container.py +++ b/mindspore/nn/layer/container.py @@ -236,7 +236,7 @@ class CellList(_CellListBase, Cell): Appends cells from a Python iterable to the end of the list. Raises: - TypeError: If the cells is not a list of subcells. + TypeError: If the cells are not a list of subcells. """ if not isinstance(cells, list): raise TypeError('Cells {} should be list of subcells'.format(cells)) diff --git a/mindspore/nn/layer/conv.py b/mindspore/nn/layer/conv.py index 2a6c21c0ab..185271fb53 100644 --- a/mindspore/nn/layer/conv.py +++ b/mindspore/nn/layer/conv.py @@ -111,11 +111,11 @@ class Conv2d(_Conv): out_j = \sum_{i=0}^{C_{in} - 1} ccor(W_{ij}, X_i) + b_j, - where :math:`ccor` is cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges - from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to :math:`i`-th channel of the :math:`j`-th + where :math:`ccor` is the cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges + from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to the :math:`i`-th channel of the :math:`j`-th filter and :math:`out_{j}` corresponds to the :math:`j`-th channel of the output. :math:`W_{ij}` is a slice of kernel and it has shape :math:`(\text{ks_h}, \text{ks_w})`, where :math:`\text{ks_h}` and - :math:`\text{ks_w}` are height and width of the convolution kernel. The full kernel has shape + :math:`\text{ks_w}` are the height and width of the convolution kernel. The full kernel has shape :math:`(C_{out}, C_{in} // \text{group}, \text{ks_h}, \text{ks_w})`, where group is the group number to split the input in the channel dimension. @@ -132,7 +132,7 @@ class Conv2d(_Conv): in_channels (int): The number of input channel :math:`C_{in}`. out_channels (int): The number of output channel :math:`C_{out}`. kernel_size (Union[int, tuple[int]]): The data type is int or tuple with 2 integers. Specifies the height - and width of the 2D convolution window. Single int means the value if for both height and width of + and width of the 2D convolution window. Single int means the value is for both the height and the width of the kernel. A tuple of 2 ints means the first value is for the height and the other is for the width of the kernel. stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents @@ -141,13 +141,13 @@ class Conv2d(_Conv): pad_mode (str): Specifies padding mode. The optional values are "same", "valid", "pad". Default: "same". - - same: Adopts the way of completion. Output height and width will be the same as the input. - Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. Otherwise, the + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. If this mode is set, `padding` must be 0. - - valid: Adopts the way of discarding. The possibly largest height and width of output will be return + - valid: Adopts the way of discarding. The possibly largest height and width of output will be returned without padding. Extra pixels will be discarded. If this mode is set, `padding` must be 0. @@ -155,9 +155,9 @@ class Conv2d(_Conv): Tensor borders. `padding` should be greater than or equal to 0. padding (Union[int, tuple[int]]): Implicit paddings on both sides of the input. If `padding` is one integer, - the padding of top, bottom, left and right is same, equal to padding. If `padding` is tuple with - four integer, the padding of top, bottom, left and right equal to padding[0], padding[1], - padding[2], padding[3] with corresponding. Default: 0. + the padding of top, bottom, left and right is the same, equal to padding. If `padding` is a tuple + with four integers, the padding of top, bottom, left and right will be equal to padding[0], + padding[1], padding[2], and padding[3] accordingly. Default: 0. dilation (Union[int, tuple[int]]): The data type is int or tuple with 2 integers. Specifies the dilation rate to use for dilated convolution. If set to be :math:`k > 1`, there will be :math:`k - 1` pixels skipped for each sampling location. Its value should @@ -167,7 +167,7 @@ class Conv2d(_Conv): divisible by the number of groups. Default: 1. has_bias (bool): Specifies whether the layer uses a bias vector. Default: False. weight_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the convolution kernel. - It can be a Tensor, a string, an Initializer or a numbers.Number. When a string is specified, + It can be a Tensor, a string, an Initializer or a number. When a string is specified, values from 'TruncatedNormal', 'Normal', 'Uniform', 'HeUniform' and 'XavierUniform' distributions as well as constant 'One' and 'Zero' distributions are possible. Alias 'xavier_uniform', 'he_uniform', 'ones' and 'zeros' are acceptable. Uppercase and lowercase are both acceptable. Refer to the values of @@ -274,10 +274,10 @@ class Conv1d(_Conv): out_j = \sum_{i=0}^{C_{in} - 1} ccor(W_{ij}, X_i) + b_j, - where :math:`ccor` is cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges - from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to :math:`i`-th channel of the :math:`j`-th + where :math:`ccor` is the cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges + from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to the :math:`i`-th channel of the :math:`j`-th filter and :math:`out_{j}` corresponds to the :math:`j`-th channel of the output. :math:`W_{ij}` is a slice - of kernel and it has shape :math:`(\text{ks_w})`, where :math:`\text{ks_w}` are width of the convolution kernel. + of kernel and it has shape :math:`(\text{ks_w})`, where :math:`\text{ks_w}` is the width of the convolution kernel. The full kernel has shape :math:`(C_{out}, C_{in} // \text{group}, \text{ks_w})`, where group is the group number to split the input in the channel dimension. @@ -285,8 +285,8 @@ class Conv1d(_Conv): :math:`\left \lfloor{1 + \frac{W_{in} + 2 \times \text{padding} - \text{ks_w} - (\text{ks_w} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` respectively. - The first introduction can be found in paper `Gradient Based Learning Applied to Document Recognition - `_. + The first introduction of convolution layer can be found in paper `Gradient Based Learning Applied to Document + Recognition `_. Args: in_channels (int): The number of input channel :math:`C_{in}`. @@ -298,13 +298,13 @@ class Conv1d(_Conv): pad_mode (str): Specifies padding mode. The optional values are "same", "valid", "pad". Default: "same". - - same: Adopts the way of completion. Output width will be the same as the input. - Total number of padding will be calculated for horizontal + - same: Adopts the way of completion. The output width will be the same as the input. + The total number of padding will be calculated in the horizontal direction and evenly distributed to left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. If this mode is set, `padding` must be 0. - - valid: Adopts the way of discarding. The possibly largest width of output will be return + - valid: Adopts the way of discarding. The possible largest width of the output will be returned without padding. Extra pixels will be discarded. If this mode is set, `padding` must be 0. @@ -320,8 +320,8 @@ class Conv1d(_Conv): group (int): Split filter into groups, `in_ channels` and `out_channels` should be divisible by the number of groups. Default: 1. has_bias (bool): Specifies whether the layer uses a bias vector. Default: False. - weight_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the convolution kernel. - It can be a Tensor, a string, an Initializer or a numbers.Number. When a string is specified, + weight_init (Union[Tensor, str, Initializer, numbers.Number]): An initializer for the convolution kernel. + It can be a Tensor, a string, an Initializer or a number. When a string is specified, values from 'TruncatedNormal', 'Normal', 'Uniform', 'HeUniform' and 'XavierUniform' distributions as well as constant 'One' and 'Zero' distributions are possible. Alias 'xavier_uniform', 'he_uniform', 'ones' and 'zeros' are acceptable. Uppercase and lowercase are both acceptable. Refer to the values of @@ -443,8 +443,8 @@ class Conv2dTranspose(_Conv): r""" 2D transposed convolution layer. - Compute a 2D transposed convolution, which is also know as a deconvolution - (although it is not actual deconvolution). + Compute a 2D transposed convolution, which is also known as a deconvolution + (although it is not an actual deconvolution). Input is typically of shape :math:`(N, C, H, W)`, where :math:`N` is batch size and :math:`C` is channel number. @@ -452,7 +452,7 @@ class Conv2dTranspose(_Conv): in_channels (int): The number of channels in the input space. out_channels (int): The number of channels in the output space. kernel_size (Union[int, tuple]): int or tuple with 2 integers, which specifies the height - and width of the 2D convolution window. Single int means the value is for both height and width of + and width of the 2D convolution window. Single int means the value is for both the height and the width of the kernel. A tuple of 2 ints means the first value is for the height and the other is for the width of the kernel. stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents @@ -467,19 +467,19 @@ class Conv2dTranspose(_Conv): - valid: Adopted the way of discarding. padding (Union[int, tuple[int]]): Implicit paddings on both sides of the input. If `padding` is one integer, - the padding of top, bottom, left and right is same, equal to padding. If `padding` is tuple with - four integer, the padding of top, bottom, left and right equal to padding[0], padding[1], - padding[2], padding[3] with corresponding. Default: 0. - dilation (Union[int, tuple[int]]): The data type is int or tuple with 2 integers. Specifies the dilation rate + the padding of top, bottom, left and right is the same, equal to padding. If `padding` is a tuple + with four integers, the padding of top, bottom, left and right will be equal to padding[0], + padding[1], padding[2], and padding[3] accordingly. Default: 0. + dilation (Union[int, tuple[int]]): The data type is int or a tuple of 2 integers. Specifies the dilation rate to use for dilated convolution. If set to be :math:`k > 1`, there will be :math:`k - 1` pixels skipped for each sampling location. Its value should - be greater or equal to 1 and bounded by the height and width of the + be greater than or equal to 1 and bounded by the height and width of the input. Default: 1. group (int): Split filter into groups, `in_channels` and `out_channels` should be - divisible by the number of groups. This is not support for Davinci devices when group > 1. Default: 1. + divisible by the number of groups. This does not support for Davinci devices when group > 1. Default: 1. has_bias (bool): Specifies whether the layer uses a bias vector. Default: False. weight_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the convolution kernel. - It can be a Tensor, a string, an Initializer or a numbers.Number. When a string is specified, + It can be a Tensor, a string, an Initializer or a number. When a string is specified, values from 'TruncatedNormal', 'Normal', 'Uniform', 'HeUniform' and 'XavierUniform' distributions as well as constant 'One' and 'Zero' distributions are possible. Alias 'xavier_uniform', 'he_uniform', 'ones' and 'zeros' are acceptable. Uppercase and lowercase are both acceptable. Refer to the values of @@ -614,8 +614,8 @@ class Conv1dTranspose(_Conv): r""" 1D transposed convolution layer. - Compute a 1D transposed convolution, which is also know as a deconvolution - (although it is not actual deconvolution). + Compute a 1D transposed convolution, which is also known as a deconvolution + (although it is not an actual deconvolution). Input is typically of shape :math:`(N, C, W)`, where :math:`N` is batch size and :math:`C` is channel number. @@ -805,11 +805,11 @@ class DepthwiseConv2d(Cell): out_j = \sum_{i=0}^{C_{in} - 1} ccor(W_{ij}, X_i) + b_j, - where :math:`ccor` is cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges - from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to :math:`i`-th channel of the :math:`j`-th + where :math:`ccor` is the cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges + from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to the :math:`i`-th channel of the :math:`j`-th filter and :math:`out_{j}` corresponds to the :math:`j`-th channel of the output. :math:`W_{ij}` is a slice of kernel and it has shape :math:`(\text{ks_h}, \text{ks_w})`, where :math:`\text{ks_h}` and - :math:`\text{ks_w}` are height and width of the convolution kernel. The full kernel has shape + :math:`\text{ks_w}` are the height and width of the convolution kernel. The full kernel has shape :math:`(C_{out}, C_{in} // \text{group}, \text{ks_h}, \text{ks_w})`, where group is the group number to split the input in the channel dimension. @@ -826,7 +826,7 @@ class DepthwiseConv2d(Cell): in_channels (int): The number of input channel :math:`C_{in}`. out_channels (int): The number of output channel :math:`C_{out}`. kernel_size (Union[int, tuple[int]]): The data type is int or tuple with 2 integers. Specifies the height - and width of the 2D convolution window. Single int means the value if for both height and width of + and width of the 2D convolution window. Single int means the value is for both the height and the width of the kernel. A tuple of 2 ints means the first value is for the height and the other is for the width of the kernel. stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents @@ -835,13 +835,13 @@ class DepthwiseConv2d(Cell): pad_mode (str): Specifies padding mode. The optional values are "same", "valid", "pad". Default: "same". - - same: Adopts the way of completion. Output height and width will be the same as the input. - Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. Otherwise, the + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. If this mode is set, `padding` must be 0. - - valid: Adopts the way of discarding. The possibly largest height and width of output will be return + - valid: Adopts the way of discarding. The possibly largest height and width of output will be returned without padding. Extra pixels will be discarded. If this mode is set, `padding` must be 0. diff --git a/mindspore/nn/layer/math.py b/mindspore/nn/layer/math.py index ddcaf2da6b..d278437e13 100644 --- a/mindspore/nn/layer/math.py +++ b/mindspore/nn/layer/math.py @@ -14,16 +14,18 @@ # ============================================================================ """math""" import math +import numpy as np from mindspore.ops import operations as P from mindspore.ops.operations import _inner_ops as inner from mindspore.common.tensor import Tensor +from mindspore.ops.primitive import constexpr from ..cell import Cell from ...common import dtype as mstype from ..._checkparam import Validator as validator from ..._checkparam import Rel -__all__ = ['ReduceLogSumExp', 'Range', 'LinSpace'] +__all__ = ['ReduceLogSumExp', 'Range', 'LinSpace', 'LGamma'] class ReduceLogSumExp(Cell): @@ -169,3 +171,134 @@ class LinSpace(Cell): lin_space_out = self.lin_space(self.assist, self.start, self.stop, self.num) return lin_space_out + +@constexpr +def check_tensors_dtype_same(data_dtype, value_dtype, op_name): + """Check tensors data type same.""" + if data_dtype in value_dtype: + return True + raise TypeError(f"For '{op_name}', the value data type '{value_dtype}' " + f"is not consistent with assigned tensor data type {data_dtype}.") + +class LGamma(Cell): + r""" + Calculate LGamma using Lanczos' approximation refering to "A Precision Approximationof the Gamma Function". + The algorithm is: + + .. math:: + lgamma(z + 1) = \frac{(\log(2) + \log(pi))}{2} + (z + 1/2) * log(t(z)) - t(z) + A(z) + + t(z) = z + kLanczosGamma + 1/2 + + A(z) = kBaseLanczosCoeff + \sum_{k=1}^n \frac{kLanczosCoefficients[i]}{z + k} + + However, if the input is less than 0.5 use Euler's reflection formula: + + .. math:: + + lgamma(x) = \log(pi) - lgamma(1-x) - \log(abs(sin(pi * x))) + + And please note that + + .. math:: + + lgamma(+/-inf) = +inf + + Thus, the behaviour of LGamma follows: + when x > 0.5, return log(Gamma(x)) + when x < 0.5 and is not an interger, return the real part of Log(Gamma(x)) where Log is the complex logarithm + when x is an integer less or equal to 0, return +inf + when x = +/- inf, return +inf + + Inputs: + - **input_x** (Tensor[Number]) - The input tensor. Only float16, float32 are supported. + + Outputs: + Tensor, has the same shape and dtype as the 'input_x'. + + Examples: + >>> input_x = Tensor(np.array(2, 3, 4).astype(np.float32)) + >>> op = nn.LGamma() + >>> output = op(input_x) + """ + + def __init__(self): + super(LGamma, self).__init__() + # const numbers + self.k_lanczos_gamma = 7 + self.k_base_lanczos_coeff = 0.99999999999980993227684700473478 + self.k_lanczos_coefficients = [676.520368121885098567009190444019, + -1259.13921672240287047156078755283, + 771.3234287776530788486528258894, + -176.61502916214059906584551354, + 12.507343278686904814458936853, + -0.13857109526572011689554707, + 9.984369578019570859563e-6, + 1.50563273514931155834e-7] + self.one_half = 0.5 + self.one = 1 + self.two = 2 + self.inf = np.inf + self.pi = np.pi + self.log_2 = np.log(self.two) + self.log_pi = np.log(np.pi) + self.log_sqrt_two_pi = (self.log_2 + self.log_pi) / self.two + self.lanczos_gamma_plus_one_half = self.k_lanczos_gamma + 0.5 + self.log_lanczos_gamma_plus_one_half = np.log(self.lanczos_gamma_plus_one_half) + + # operations + self.log = P.Log() + self.log1p = P.Log1p() + self.abs = P.Abs() + self.shape = P.Shape() + self.dtype = P.DType() + self.fill = P.Fill() + self.floor = P.Floor() + self.equal = P.Equal() + self.greater = P.Greater() + self.less = P.Less() + self.lessequal = P.LessEqual() + self.select = P.Select() + self.sin = P.Sin() + self.isfinite = P.IsFinite() + + def construct(self, input_x): + input_dtype = self.dtype(input_x) + check_tensors_dtype_same(input_dtype, [mstype.float16, mstype.float32], "LGamma") + infinity = self.fill(input_dtype, self.shape(input_x), self.inf) + + need_to_reflect = self.less(input_x, 0.5) + neg_input = -input_x + z = self.select(need_to_reflect, neg_input, input_x - 1) + + @constexpr + def _calculate_x(z, k_base_lanczos_coeff, k_lanczos_coefficients): + x = k_base_lanczos_coeff + for i in range(8): + product_ = k_lanczos_coefficients[i] / (z + i + 1) + x = product_ + x + return x + x = _calculate_x(z, self.k_base_lanczos_coeff, self.k_lanczos_coefficients) + + t = z + self.lanczos_gamma_plus_one_half + log_t = self.log1p(z / self.lanczos_gamma_plus_one_half) + self.log_lanczos_gamma_plus_one_half + + log_y = self.log(x) + (z + self.one_half - t / log_t) * log_t + self.log_sqrt_two_pi + + abs_input = self.abs(input_x) + abs_frac_input = abs_input - self.floor(abs_input) + input_x = self.select(self.lessequal(input_x, 0.0), + self.select(self.equal(abs_frac_input, 0.0), + infinity, input_x), + input_x) + reduced_frac_input = self.select(self.greater(abs_frac_input, 0.5), + 1 - abs_frac_input, abs_frac_input) + reflection_denom = self.log(self.sin(self.pi * reduced_frac_input)) + + reflection = self.select(self.isfinite(reflection_denom), + -reflection_denom - log_y + self.log_pi, + -reflection_denom) + + result = self.select(need_to_reflect, reflection, log_y) + + return self.select(self.isfinite(input_x), result, infinity) diff --git a/mindspore/nn/layer/normalization.py b/mindspore/nn/layer/normalization.py index c09a02b3c2..b129673210 100644 --- a/mindspore/nn/layer/normalization.py +++ b/mindspore/nn/layer/normalization.py @@ -248,7 +248,7 @@ class BatchNorm1d(_BatchNorm): eps (float): A value added to the denominator for numerical stability. Default: 1e-5. momentum (float): A floating hyperparameter of the momentum for the running_mean and running_var computation. Default: 0.9. - affine (bool): A bool value when set to True, gamma and beta can be learnable. Default: True. + affine (bool): A bool value. When set to True, gamma and beta can be learned. Default: True. gamma_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the gamma weight. The values of str refer to the function `initializer` including 'zeros', 'ones', 'xavier_uniform', 'he_uniform', etc. Default: 'ones'. @@ -262,9 +262,9 @@ class BatchNorm1d(_BatchNorm): The values of str refer to the function `initializer` including 'zeros', 'ones', 'xavier_uniform', 'he_uniform', etc. Default: 'ones'. use_batch_statistics (bool): If true, use the mean value and variance value of current batch data. If false, - use the mean value and variance value of specified value. If None, training process will use the mean and - variance of current batch data and track the running mean and variance, eval process will use the running - mean and variance. Default: None. + use the mean value and variance value of specified value. If None, the training process will use the mean + and variance of current batch data and track the running mean and variance, the evaluation process will use + the running mean and variance. Default: None. Inputs: - **input** (Tensor) - Tensor of shape :math:`(N, C_{in})`. @@ -324,7 +324,7 @@ class BatchNorm2d(_BatchNorm): eps (float): A value added to the denominator for numerical stability. Default: 1e-5. momentum (float): A floating hyperparameter of the momentum for the running_mean and running_var computation. Default: 0.9. - affine (bool): A bool value when set to True, gamma and beta can be learnable. Default: True. + affine (bool): A bool value. When set to True, gamma and beta can be learned. Default: True. gamma_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the gamma weight. The values of str refer to the function `initializer` including 'zeros', 'ones', 'xavier_uniform', 'he_uniform', etc. Default: 'ones'. @@ -338,9 +338,9 @@ class BatchNorm2d(_BatchNorm): The values of str refer to the function `initializer` including 'zeros', 'ones', 'xavier_uniform', 'he_uniform', etc. Default: 'ones'. use_batch_statistics (bool): If true, use the mean value and variance value of current batch data. If false, - use the mean value and variance value of specified value. If None, training process will use the mean and - variance of current batch data and track the running mean and variance, eval process will use the running - mean and variance. Default: None. + use the mean value and variance value of specified value. If None, the training process will use the mean + and variance of current batch data and track the running mean and variance, the evaluation process will use + the running mean and variance. Default: None. Inputs: - **input** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. diff --git a/mindspore/nn/layer/pooling.py b/mindspore/nn/layer/pooling.py index 1277dc9e35..068309430c 100644 --- a/mindspore/nn/layer/pooling.py +++ b/mindspore/nn/layer/pooling.py @@ -84,16 +84,16 @@ class MaxPool2d(_PoolNd): stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1. - pad_mode (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + pad_mode (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: - **input** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. @@ -158,23 +158,23 @@ class AvgPool2d(_PoolNd): pad_mode for training only supports "same" and "valid". Args: - kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value, - is an int number that represents height and width are both kernel_size, + kernel_size (Union[int, tuple[int]]): The size of kernel used to take the average value. + The data type of kernel_size should be int and the value represents the height and width, or a tuple of two int numbers that represent height and width respectively. Default: 1. stride (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1. - pad_mode (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + pad_mode (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: @@ -238,16 +238,16 @@ class AvgPool1d(_PoolNd): kernel_size (int): The size of kernel window used to take the average value, Default: 1. stride (int): The distance of kernel moving, an int number that represents the width of movement is strides, Default: 1. - pad_mode (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + pad_mode (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: diff --git a/mindspore/nn/layer/quant.py b/mindspore/nn/layer/quant.py index 0b94de155d..8c9b6401ee 100644 --- a/mindspore/nn/layer/quant.py +++ b/mindspore/nn/layer/quant.py @@ -56,27 +56,27 @@ class Conv2dBnAct(Cell): r""" A combination of convolution, Batchnorm, activation layer. - For a more Detailed overview of Conv2d op. + This part is a more detailed overview of Conv2d op. Args: in_channels (int): The number of input channel :math:`C_{in}`. out_channels (int): The number of output channel :math:`C_{out}`. kernel_size (Union[int, tuple]): The data type is int or tuple with 2 integers. Specifies the height - and width of the 2D convolution window. Single int means the value if for both height and width of + and width of the 2D convolution window. Single int means the value is for both height and width of the kernel. A tuple of 2 ints means the first value is for the height and the other is for the width of the kernel. - stride (int): Specifies stride for all spatial dimensions with the same value. Value of stride should be - greater or equal to 1 but bounded by the height and width of the input. Default: 1. + stride (int): Specifies stride for all spatial dimensions with the same value. The value of stride should be + greater than or equal to 1 and lower than any one of the height and width of the input. Default: 1. pad_mode (str): Specifies padding mode. The optional values are "same", "valid", "pad". Default: "same". padding (int): Implicit paddings on both sides of the input. Default: 0. dilation (int): Specifying the dilation rate to use for dilated convolution. If set to be :math:`k > 1`, - there will be :math:`k - 1` pixels skipped for each sampling location. Its value should be greater - or equal to 1 and bounded by the height and width of the input. Default: 1. + there will be :math:`k - 1` pixels skipped for each sampling location. Its value should be greater than + or equal to 1 and lower than any one of the height and width of the input. Default: 1. group (int): Split filter into groups, `in_ channels` and `out_channels` should be divisible by the number of groups. Default: 1. has_bias (bool): Specifies whether the layer uses a bias vector. Default: False. weight_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the convolution kernel. - It can be a Tensor, a string, an Initializer or a numbers.Number. When a string is specified, + It can be a Tensor, a string, an Initializer or a number. When a string is specified, values from 'TruncatedNormal', 'Normal', 'Uniform', 'HeUniform' and 'XavierUniform' distributions as well as constant 'One' and 'Zero' distributions are possible. Alias 'xavier_uniform', 'he_uniform', 'ones' and 'zeros' are acceptable. Uppercase and lowercase are both acceptable. Refer to the values of @@ -160,9 +160,9 @@ class Conv2dBnAct(Cell): class DenseBnAct(Cell): r""" - A combination of Dense, Batchnorm, activation layer. + A combination of Dense, Batchnorm, and the activation layer. - For a more Detailed overview of Dense op. + This part is a more detailed overview of Dense op. Args: in_channels (int): The number of channels in the input space. @@ -172,11 +172,11 @@ class DenseBnAct(Cell): bias_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable bias_init parameter. The dtype is same as input x. The values of str refer to the function `initializer`. Default: 'zeros'. has_bias (bool): Specifies whether the layer uses a bias vector. Default: True. - activation (Cell): Regularizer function applied to the output of the layer, eg. 'relu'. Default: None. - has_bn (bool): Specifies to used batchnorm or not. Default: False. + activation (Cell): The regularization function applied to the output of the layer, eg. 'ReLU'. Default: None. + has_bn (bool): Specifies to use batchnorm or not. Default: False. activation (string): Specifies activation type. The optional values are as following: - 'softmax', 'logsoftmax', 'relu', 'relu6', 'tanh', 'gelu', 'sigmoid', - 'prelu', 'leakyrelu', 'hswish', 'hsigmoid'. Default: None. + 'Softmax', 'LogSoftmax', 'ReLU', 'ReLU6', 'Tanh', 'GELU', 'Sigmoid', + 'PReLU', 'LeakyReLU', 'h-Swish', and 'h-Sigmoid'. Default: None. Inputs: - **input** (Tensor) - Tensor of shape :math:`(N, in\_channels)`. @@ -292,10 +292,10 @@ class FakeQuantWithMinMax(Cell): per_channel (bool): Quantization granularity based on layer or on channel. Default: False. channel_axis (int): Quantization by channel axis. Default: 1. num_channels (int): declarate the min and max channel size, Default: 1. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - The input of FakeQuantWithMinMax. @@ -396,9 +396,9 @@ class FakeQuantWithMinMax(Cell): class Conv2dBnFoldQuant(Cell): r""" - 2D convolution with BatchNormal op folded layer. + 2D convolution with BatchNormal op folded construct. - For a more Detailed overview of Conv2d op. + This part is a more detailed overview of Conv2d op. Args: in_channels (int): The number of input channel :math:`C_{in}`. @@ -419,13 +419,13 @@ class Conv2dBnFoldQuant(Cell): mean vector. Default: 'zeros'. var_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the variance vector. Default: 'ones'. - fake (bool): Conv2dBnFoldQuant Cell add FakeQuantWithMinMax op or not. Default: True. + fake (bool): Whether Conv2dBnFoldQuant Cell adds FakeQuantWithMinMax op. Default: True. per_channel (bool): FakeQuantWithMinMax Parameters. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. - freeze_bn (int): Quantization freeze BatchNormal op according by global step. Default: 100000. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): The Quantization delay parameters according to the global step. Default: 0. + freeze_bn (int): The quantization freeze BatchNormal op is according to the global step. Default: 100000. Inputs: - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. @@ -434,10 +434,9 @@ class Conv2dBnFoldQuant(Cell): Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`. Examples: - >>> batchnorm_quant = nn.Conv2dBnFoldQuant(1, 6, kernel_size= (2, 2), stride=(1, 1), pad_mode="valid", - >>> dilation=(1, 1)) - >>> input_x = Tensor(np.random.randint(-2, 2, (2, 1, 1, 3)), mindspore.float32) - >>> result = batchnorm_quant(input_x) + >>> conv2d_bn = nn.Conv2dBnFoldQuant(1, 6, kernel_size=(2, 2), stride=(1, 1), pad_mode="valid") + >>> x = Tensor(np.random.randint(-2, 2, (2, 1, 1, 3)), mindspore.float32) + >>> y = conv2d_bn(x) """ def __init__(self, @@ -508,7 +507,7 @@ class Conv2dBnFoldQuant(Cell): channel_axis = 0 self.weight = Parameter(initializer(weight_init, weight_shape), name='weight') - # initialize batchnorm Parameter + # initialize BatchNorm Parameter self.gamma = Parameter(initializer(gamma_init, [out_channels]), name='gamma') self.beta = Parameter(initializer(beta_init, [out_channels]), name='beta') self.moving_mean = Parameter(initializer(mean_init, [out_channels]), name='moving_mean', requires_grad=False) @@ -583,9 +582,9 @@ class Conv2dBnFoldQuant(Cell): class Conv2dBnWithoutFoldQuant(Cell): r""" - 2D convolution + batchnorm without fold with fake quant op layer. + 2D convolution + batchnorm without fold with fake quant construct. - For a more Detailed overview of Conv2d op. + This part is a more detailed overview of Conv2d op. Args: in_channels (int): The number of input channel :math:`C_{in}`. @@ -605,10 +604,10 @@ class Conv2dBnWithoutFoldQuant(Cell): Default: 'normal'. bias_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the bias vector. Default: 'zeros'. per_channel (bool): FakeQuantWithMinMax Parameters. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. @@ -617,10 +616,9 @@ class Conv2dBnWithoutFoldQuant(Cell): Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`. Examples: - >>> conv2d_quant = nn.Conv2dQuant(1, 6, kernel_size=(2, 2), stride=(1, 1), pad_mode="valid", - >>> dilation=(1, 1)) - >>> input_x = Tensor(np.random.randint(-2, 2, (2, 1, 1, 3)), mstype.float32) - >>> result = conv2d_quant(input_x) + >>> conv2d_quant = nn.Conv2dBnWithoutFoldQuant(1, 6, kernel_size=(2, 2), stride=(1, 1), pad_mode="valid") + >>> x = Tensor(np.random.randint(-2, 2, (2, 1, 1, 3)), mstype.float32) + >>> y = conv2d_quant(x) """ def __init__(self, @@ -687,7 +685,7 @@ class Conv2dBnWithoutFoldQuant(Cell): quant_delay=quant_delay) self.has_bn = validator.check_bool("has_bn", has_bn) if has_bn: - self.batchnorm = BatchNorm2d(out_channels) + self.batchnorm = BatchNorm2d(out_channels, eps=eps, momentum=momentum) def construct(self, x): weight = self.fake_quant_weight(self.weight) @@ -711,7 +709,7 @@ class Conv2dQuant(Cell): r""" 2D convolution with fake quant op layer. - For a more Detailed overview of Conv2d op. + This part is a more detailed overview of Conv2d op. Args: in_channels (int): The number of input channel :math:`C_{in}`. @@ -728,10 +726,10 @@ class Conv2dQuant(Cell): Default: 'normal'. bias_init (Union[Tensor, str, Initializer, numbers.Number]): Initializer for the bias vector. Default: 'zeros'. per_channel (bool): FakeQuantWithMinMax Parameters. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. @@ -740,10 +738,9 @@ class Conv2dQuant(Cell): Tensor of shape :math:`(N, C_{out}, H_{out}, W_{out})`. Examples: - >>> conv2d_quant = nn.Conv2dQuant(1, 6, kernel_size= (2, 2), stride=(1, 1), pad_mode="valid", - >>> dilation=(1, 1)) - >>> input_x = Tensor(np.random.randint(-2, 2, (2, 1, 1, 3)), mindspore.float32) - >>> result = conv2d_quant(input_x) + >>> conv2d_quant = nn.Conv2dQuant(1, 6, kernel_size= (2, 2), stride=(1, 1), pad_mode="valid") + >>> x = Tensor(np.random.randint(-2, 2, (2, 1, 1, 3)), mindspore.float32) + >>> y = conv2d_quant(x) """ def __init__(self, @@ -826,7 +823,7 @@ class DenseQuant(Cell): r""" The fully connected layer with fake quant op. - For a more Detailed overview of Dense op. + This part is a more detailed overview of Dense op. Args: in_channels (int): The dimension of the input space. @@ -836,12 +833,12 @@ class DenseQuant(Cell): bias_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable bias_init parameter. The dtype is same as input x. The values of str refer to the function `initializer`. Default: 'zeros'. has_bias (bool): Specifies whether the layer uses a bias vector. Default: True. - activation (str): Regularizer function applied to the output of the layer, eg. 'relu'. Default: None. + activation (str): The regularization function applied to the output of the layer, eg. 'relu'. Default: None. per_channel (bool): FakeQuantWithMinMax Parameters. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. @@ -906,7 +903,7 @@ class DenseQuant(Cell): quant_delay=quant_delay) def construct(self, x): - """Use operators to construct to Dense layer.""" + """Use operators to construct the Dense layer.""" output = self.fake_quant_weight(self.weight) output = self.matmul(x, output) if self.has_bias: @@ -942,16 +939,16 @@ class ActQuant(_QuantActivation): Add Fake Quant OP after activation. Not Recommand to used these cell for Fake Quant Op Will climp the max range of the activation and the relu6 do the same operation. - For a more Detailed overview of ReLU6 op. + This part is a more detailed overview of ReLU6 op. Args: activation (Cell): Activation cell class. ema_decay (float): Exponential Moving Average algorithm parameter. Default: 0.999. per_channel (bool): Quantization granularity based on layer or on channel. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global steps. Default: 0. Inputs: - **x** (Tensor) - The input of ReLU6Quant. @@ -997,16 +994,16 @@ class LeakyReLUQuant(_QuantActivation): r""" LeakyReLUQuant activation function. Add Fake Quant OP after HSwish OP. - For a more Detailed overview of HSwish op. + This part is a more detailed overview of HSwish op. Args: activation (Cell): Activation cell class. ema_decay (float): Exponential Moving Average algorithm parameter. Default: 0.999. per_channel (bool): Quantization granularity based on layer or on channel. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - The input of LeakyReLUQuant. @@ -1067,16 +1064,16 @@ class HSwishQuant(_QuantActivation): r""" HSwishQuant activation function. Add Fake Quant OP after HSwish OP. - For a more Detailed overview of HSwish op. + This part is a more detailed overview of HSwish op. Args: activation (Cell): Activation cell class. ema_decay (float): Exponential Moving Average algorithm parameter. Default: 0.999. per_channel (bool): Quantization granularity based on layer or on channel. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - The input of HSwishQuant. @@ -1136,16 +1133,16 @@ class HSigmoidQuant(_QuantActivation): r""" HSigmoidQuant activation function. Add Fake Quant OP before and after HSigmoid OP. - For a more Detailed overview of HSigmoid op. + This part is a more detailed overview of HSigmoid op. Args: activation (Cell): Activation cell class. ema_decay (float): Exponential Moving Average algorithm parameter. Default: 0.999. per_channel (bool): Quantization granularity based on layer or on channel. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - The input of HSigmoidQuant. @@ -1205,15 +1202,15 @@ class TensorAddQuant(Cell): r""" Add Fake Quant OP after TensorAdd OP. - For a more Detailed overview of TensorAdd op. + This part is a more detailed overview of TensorAdd op. Args: ema_decay (float): Exponential Moving Average algorithm parameter. Default: 0.999. per_channel (bool): Quantization granularity based on layer or on channel. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - The input of TensorAddQuant. @@ -1257,15 +1254,15 @@ class MulQuant(Cell): r""" Add Fake Quant OP after Mul OP. - For a more Detailed overview of Mul op. + This part is a more detailed overview of Mul op. Args: ema_decay (float): Exponential Moving Average algorithm parameter. Default: 0.999. per_channel (bool): Quantization granularity based on layer or on channel. Default: False. - num_bits (int): Quantization number bit, support 4 and 8bit. Default: 8. - symmetric (bool): Quantization algorithm use symmetric or not. Default: False. - narrow_range (bool): Quantization algorithm use narrow range or not. Default: False. - quant_delay (int): Quantization delay parameters according by global step. Default: 0. + num_bits (int): The quantization number bit, support 4 and 8bit. Default: 8. + symmetric (bool): The quantization algorithm is symmetric or not. Default: False. + narrow_range (bool): The quantization algorithm uses narrow range or not. Default: False. + quant_delay (int): Quantization delay parameters according to the global step. Default: 0. Inputs: - **x** (Tensor) - The input of MulQuant. @@ -1317,7 +1314,7 @@ class QuantBlock(Cell): bias_init (Union[Tensor, str, Initializer, numbers.Number]): The trainable bias_init parameter. The dtype is same as input x. The values of str refer to the function `initializer`. Default: 'zeros'. has_bias (bool): Specifies whether the layer uses a bias vector. Default: True. - activation (str): Regularizer function applied to the output of the layer, eg. 'relu'. Default: None. + activation (str): The regularization function applied to the output of the layer, eg. 'relu'. Default: None. batchnorm (bool): Specifies to used batchnorm or not. Default: None. activation (string): Specifies activation type. The optional values are as following: 'softmax', 'logsoftmax', 'relu', 'relu6', 'tanh', 'gelu', 'sigmoid', diff --git a/mindspore/nn/loss/loss.py b/mindspore/nn/loss/loss.py index 5f17baf64a..f1599754cb 100644 --- a/mindspore/nn/loss/loss.py +++ b/mindspore/nn/loss/loss.py @@ -353,17 +353,18 @@ class CosineEmbeddingLoss(_Loss): Args: margin (float): Should be in [-1.0, 1.0]. Default 0.0. - reduction (str): Specifies which reduction to apply to the output. It should be one of - "none", "mean", "sum", meaning no reduction, reduce mean or sum on output, respectively. Default "mean". + reduction (str): Specifies which reduction to be applied to the output. It should be one of + "none", "mean", and "sum", meaning no reduction, reduce mean and sum on output, respectively. Default "mean". Inputs: - **input_x1** (Tensor) - Input tensor. - **input_x2** (Tensor) - Its shape and data type should be the same as `input_x1`'s shape and data type. - - **y** (Tensor) - Contains value 1 or -1. Suppose `input_x1` shape is - :math:`(x_1, x_2, x_3,..., x_R)`, then `target` shape should be :math:`(x_1, x_3, x_4, ..., x_R)`. + - **y** (Tensor) - Contains value 1 or -1. Suppose the shape of `input_x1` is + :math:`(x_1, x_2, x_3,..., x_R)`, then the shape of `target` should be :math:`(x_1, x_3, x_4, ..., x_R)`. Outputs: - - **loss** (Tensor) - If `reduction` is "none", its shape is the same as `y`'s shape, loss value otherwise. + - **loss** (Tensor) - If `reduction` is "none", its shape is the same as `y`'s shape, otherwise a scalar value + will be returned. Examples: >>> x1 = Tensor(np.array([[0.3, 0.8], [0.4, 0.3]]), mindspore.float32) diff --git a/mindspore/nn/metrics/accuracy.py b/mindspore/nn/metrics/accuracy.py index 9537b4b95c..e55a869738 100644 --- a/mindspore/nn/metrics/accuracy.py +++ b/mindspore/nn/metrics/accuracy.py @@ -21,9 +21,9 @@ class Accuracy(EvaluationBase): r""" Calculates the accuracy for classification and multilabel data. - The accuracy class creates two local variables, correct number and total number that are used to compute the + The accuracy class creates two local variables, the correct number and the total number that are used to compute the frequency with which predictions matches labels. This frequency is ultimately returned as the accuracy: an - idempotent operation that simply divides correct number by total number. + idempotent operation that simply divides the correct number by the total number. .. math:: \text{accuracy} =\frac{\text{true_positive} + \text{true_negative}} @@ -58,17 +58,17 @@ class Accuracy(EvaluationBase): Args: inputs: Input `y_pred` and `y`. `y_pred` and `y` are a `Tensor`, a list or an array. - For 'classification' evaluation type, `y_pred` is in most cases (not strictly) a list + For the 'classification' evaluation type, `y_pred` is in most cases (not strictly) a list of floating numbers in range :math:`[0, 1]` and the shape is :math:`(N, C)`, where :math:`N` is the number of cases and :math:`C` is the number of categories. Shape of `y` can be :math:`(N, C)` with values 0 and 1 if one-hot encoding is used or the shape is :math:`(N,)` with integer values if index of category is used. For 'multilabel' evaluation type, `y_pred` and `y` can only be one-hot encoding with - values 0 or 1. Indices with 1 indicate positive category. The shape of `y_pred` and `y` + values 0 or 1. Indices with 1 indicate the positive category. The shape of `y_pred` and `y` are both :math:`(N, C)`. Raises: - ValueError: If the number of the input is not 2. + ValueError: If the number of the inputs is not 2. """ if len(inputs) != 2: raise ValueError('Accuracy need 2 inputs (y_pred, y), but got {}'.format(len(inputs))) diff --git a/mindspore/nn/optim/adam.py b/mindspore/nn/optim/adam.py index 56de737176..400c4fc9c3 100755 --- a/mindspore/nn/optim/adam.py +++ b/mindspore/nn/optim/adam.py @@ -132,7 +132,7 @@ def _check_param_value(beta1, beta2, eps, prim_name): class Adam(Optimizer): r""" - Updates gradients by Adaptive Moment Estimation (Adam) algorithm. + Updates gradients by the Adaptive Moment Estimation (Adam) algorithm. The Adam algorithm is proposed in `Adam: A Method for Stochastic Optimization `_. @@ -157,9 +157,9 @@ class Adam(Optimizer): weight decay is positive. When not separating parameter groups, the `weight_decay` in the API will be applied on the parameters without 'beta' or 'gamma' in their names if `weight_decay` is positive. - To improve parameter groups performance, the customized order of parameters can be supported. + To improve parameter groups performance, the customized order of parameters is supported. - The sparse strategy is applied while the SparseGatherV2 operator being used for forward network. + The sparse strategy is applied while the SparseGatherV2 operator is used for forward network. The sparse feature is under continuous development. The sparse behavior is currently performed on the CPU. @@ -170,36 +170,36 @@ class Adam(Optimizer): - params: Required. The value should be a list of `Parameter`. - - lr: Optional. If "lr" in the keys, the value of corresponding learning rate will be used. + - lr: Optional. If "lr" is in the keys, the value of the corresponding learning rate will be used. If not, the `learning_rate` in the API will be used. - - weight_decay: Optional. If "weight_decay" in the keys, the value of corresponding weight decay + - weight_decay: Optional. If "weight_decay" is in the keys, the value of the corresponding weight decay will be used. If not, the `weight_decay` in the API will be used. - - order_params: Optional. If "order_params" in the keys, the value should be the order of parameters and - the order will be followed in optimizer. There are no other keys in the `dict` and the parameters which - in the value of 'order_params' should be in one of group parameters. + - order_params: Optional. If "order_params" is in the keys, the value should be the order of parameters and + the order will be followed in the optimizer. There are no other keys in the `dict` and the parameters + which in the 'order_params' should be in one of group parameters. learning_rate (Union[float, Tensor, Iterable, LearningRateSchedule]): A value or graph for the learning rate. - When the learning_rate is a Iterable or a Tensor with dimension of 1, use dynamic learning rate, then + When the learning_rate is a Iterable or a Tensor with dimension of 1, use the dynamic learning rate, then the i-th step will take the i-th value as the learning rate. When the learning_rate is LearningRateSchedule, use dynamic learning rate, the i-th learning rate will be calculated during the process of training according to the formula of LearningRateSchedule. When the learning_rate is a float or a Tensor with dimension of 0, use fixed learning rate. Other cases are not supported. The float learning rate should be equal to or greater than 0. If the type of `learning_rate` is int, it will be converted to float. Default: 1e-3. - beta1 (float): The exponential decay rate for the 1st moment estimates. Should be in range (0.0, 1.0). Default: - 0.9. - beta2 (float): The exponential decay rate for the 2nd moment estimates. Should be in range (0.0, 1.0). Default: - 0.999. + beta1 (float): The exponential decay rate for the 1st moment estimations. Should be in range (0.0, 1.0). + Default: 0.9. + beta2 (float): The exponential decay rate for the 2nd moment estimations. Should be in range (0.0, 1.0). + Default: 0.999. eps (float): Term added to the denominator to improve numerical stability. Should be greater than 0. Default: 1e-8. use_locking (bool): Whether to enable a lock to protect updating variable tensors. If True, updating of the var, m, and v tensors will be protected by a lock. If False, the result is unpredictable. Default: False. use_nesterov (bool): Whether to use Nesterov Accelerated Gradient (NAG) algorithm to update the gradients. - If True, updates the gradients using NAG. - If False, updates the gradients without using NAG. Default: False. + If True, update the gradients using NAG. + If False, update the gradients without using NAG. Default: False. weight_decay (float): Weight decay (L2 penalty). It should be equal to or greater than 0. Default: 0.0. loss_scale (float): A floating point value for the loss scale. Should be greater than 0. Default: 1.0. @@ -278,11 +278,11 @@ class Adam(Optimizer): class AdamWeightDecay(Optimizer): """ - Implements Adam algorithm weight decay fix. + Implements the Adam algorithm to fix the weight decay. Note: When separating parameter groups, the weight decay in each group will be applied on the parameters if the - weight decay is posigive. When not separating parameter groups, the `weight_decay` in the API will be applied + weight decay is positive. When not separating parameter groups, the `weight_decay` in the API will be applied on the parameters without 'beta' or 'gamma' in their names if `weight_decay` is positive. To improve parameter groups performance, the customized order of parameters can be supported. @@ -294,27 +294,27 @@ class AdamWeightDecay(Optimizer): - params: Required. The value should be a list of `Parameter`. - - lr: Optional. If "lr" in the keys, the value of corresponding learning rate will be used. + - lr: Optional. If "lr" is in the keys, the value of the corresponding learning rate will be used. If not, the `learning_rate` in the API will be used. - - weight_decay: Optional. If "weight_decay" in the keys, the value of corresponding weight decay + - weight_decay: Optional. If "weight_decay" is in the keys, the value of the corresponding weight decay will be used. If not, the `weight_decay` in the API will be used. - - order_params: Optional. If "order_params" in the keys, the value should be the order of parameters and - the order will be followed in optimizer. There are no other keys in the `dict` and the parameters which - in the value of 'order_params' should be in one of group parameters. + - order_params: Optional. If "order_params" is in the keys, the value should be the order of parameters and + the order will be followed in the optimizer. There are no other keys in the `dict` and the parameters + which in the 'order_params' should be in one of group parameters. learning_rate (Union[float, Tensor, Iterable, LearningRateSchedule]): A value or graph for the learning rate. - When the learning_rate is a Iterable or a Tensor with dimension of 1, use dynamic learning rate, then + When the learning_rate is a Iterable or a Tensor with dimension of 1, use the dynamic learning rate, then the i-th step will take the i-th value as the learning rate. When the learning_rate is LearningRateSchedule, use dynamic learning rate, the i-th learning rate will be calculated during the process of training according to the formula of LearningRateSchedule. When the learning_rate is a float or a Tensor with dimension of 0, use fixed learning rate. Other cases are not supported. The float learning rate should be equal to or greater than 0. If the type of `learning_rate` is int, it will be converted to float. Default: 1e-3. - beta1 (float): The exponential decay rate for the 1st moment estimates. Default: 0.9. + beta1 (float): The exponential decay rate for the 1st moment estimations. Default: 0.9. Should be in range (0.0, 1.0). - beta2 (float): The exponential decay rate for the 2nd moment estimates. Default: 0.999. + beta2 (float): The exponential decay rate for the 2nd moment estimations. Default: 0.999. Should be in range (0.0, 1.0). eps (float): Term added to the denominator to improve numerical stability. Default: 1e-6. Should be greater than 0. diff --git a/mindspore/nn/optim/lazyadam.py b/mindspore/nn/optim/lazyadam.py index 80dfd9d38c..788c68a2a8 100644 --- a/mindspore/nn/optim/lazyadam.py +++ b/mindspore/nn/optim/lazyadam.py @@ -27,25 +27,40 @@ from .optimizer import Optimizer _lazy_adam_opt = C.MultitypeFuncGraph("lazy_adam_opt") -@_lazy_adam_opt.register("Function", "Function", "Tensor", "Tensor", "Tensor", "Tensor", "Number", "Tensor", - "RowTensor", "Tensor", "Tensor", "Tensor") -def _run_opt_with_sparse(opt, sparse_opt, beta1_power, beta2_power, beta1, beta2, eps, lr, gradient, params, - moment1, moment2): +@_lazy_adam_opt.register("Function", "Function", "Function", "Function", "Tensor", "Tensor", "Tensor", "Tensor", + "Tensor", "Tensor", "RowTensor", "Tensor", "Tensor", "Tensor", "Bool") +def _run_opt_with_sparse(opt, sparse_opt, push, pull, beta1_power, beta2_power, beta1, beta2, eps, + lr, gradient, params, moment1, moment2, ps_parameter): """Apply sparse lazy adam optimizer to the weight parameter when the gradient is sparse.""" success = True - success = F.depend(success, sparse_opt(params, moment1, moment2, beta1_power, beta2_power, lr, beta1, beta2, - eps, gradient.values, gradient.indices)) + indices = gradient.indices + values = gradient.values + if ps_parameter: + op_shape = P.Shape() + shapes = (op_shape(params), op_shape(moment1), op_shape(moment2), + op_shape(beta1_power), op_shape(beta2_power), op_shape(lr), op_shape(beta1), + op_shape(beta2), op_shape(eps), op_shape(values), op_shape(indices)) + success = F.depend(success, pull(push((beta1_power, beta2_power, lr, beta1, beta2, + eps, values, indices), shapes), params)) + else: + success = F.depend(success, sparse_opt(params, moment1, moment2, beta1_power, beta2_power, lr, beta1, beta2, + eps, values, indices)) return success -@_lazy_adam_opt.register("Function", "Function", "Tensor", "Tensor", "Tensor", "Tensor", "Number", "Tensor", "Tensor", - "Tensor", "Tensor", "Tensor") -def _run_opt_with_one_number(opt, sparse_opt, beta1_power, beta2_power, beta1, beta2, eps, lr, gradient, params, - moment1, moment2): - """Apply adam optimizer to the weight parameter using Tensor.""" +@_lazy_adam_opt.register("Function", "Function", "Function", "Function", "Tensor", "Tensor", "Tensor", "Tensor", + "Tensor", "Tensor", "Tensor", "Tensor", "Tensor", "Tensor", "Bool") +def _run_opt_with_one_number(opt, sparse_opt, push, pull, beta1_power, beta2_power, beta1, beta2, eps, + lr, gradient, params, moment1, moment2, ps_parameter): + """Apply lazy adam optimizer to the weight parameter using Tensor.""" success = True - success = F.depend(success, opt(params, moment1, moment2, beta1_power, beta2_power, lr, beta1, beta2, - eps, gradient)) + if ps_parameter: + op_shape = P.Shape() + success = F.depend(success, pull(push((beta1_power, beta2_power, lr, beta1, beta2, eps, gradient), + (op_shape(params), op_shape(moment1), op_shape(moment2))), params)) + else: + success = F.depend(success, opt(params, moment1, moment2, beta1_power, beta2_power, lr, beta1, beta2, + eps, gradient)) return success @@ -173,7 +188,7 @@ class LazyAdam(Optimizer): self.beta2 = Tensor(beta2, mstype.float32) self.beta1_power = Parameter(initializer(1, [1], mstype.float32), name="beta1_power") self.beta2_power = Parameter(initializer(1, [1], mstype.float32), name="beta2_power") - self.eps = eps + self.eps = Tensor(eps, mstype.float32) self.use_nesterov = use_nesterov self.use_locking = use_locking @@ -184,6 +199,10 @@ class LazyAdam(Optimizer): self.opt = P.Adam(use_locking, use_nesterov) self.sparse_opt = P.FusedSparseLazyAdam(use_locking, use_nesterov) + self._ps_pull = P.Pull() + self._ps_push = P.Push("Adam", [0, 1, 2]) + self._ps_push.add_prim_attr("use_nesterov", use_nesterov) + def construct(self, gradients): gradients = self.decay_weight(gradients) gradients = self.scale_grad(gradients) @@ -193,11 +212,11 @@ class LazyAdam(Optimizer): self.beta2_power = self.beta2_power * self.beta2 if self.is_group_lr: - success = self.map_(F.partial(_lazy_adam_opt, self.opt, self.sparse_opt, self.beta1_power, - self.beta2_power, self.beta1, self.beta2, self.eps), - lr, gradients, self.parameters, self.moment1, self.moment2) + success = self.map_(F.partial(_lazy_adam_opt, self.opt, self.sparse_opt, self._ps_push, self._ps_pull, + self.beta1_power, self.beta2_power, self.beta1, self.beta2, self.eps), + lr, gradients, self.parameters, self.moment1, self.moment2, self.ps_parameters) else: - success = self.map_(F.partial(_lazy_adam_opt, self.opt, self.sparse_opt, self.beta1_power, - self.beta2_power, self.beta1, self.beta2, self.eps, lr), - gradients, self.parameters, self.moment1, self.moment2) + success = self.map_(F.partial(_lazy_adam_opt, self.opt, self.sparse_opt, self._ps_push, self._ps_pull, + self.beta1_power, self.beta2_power, self.beta1, self.beta2, self.eps, lr), + gradients, self.parameters, self.moment1, self.moment2, self.ps_parameters) return success diff --git a/mindspore/nn/probability/bijector/__init__.py b/mindspore/nn/probability/bijector/__init__.py index 3108742aea..8caf4e428f 100644 --- a/mindspore/nn/probability/bijector/__init__.py +++ b/mindspore/nn/probability/bijector/__init__.py @@ -21,7 +21,13 @@ The high-level components(Bijectors) used to construct the probabilistic network from .bijector import Bijector from .power_transform import PowerTransform from .exp import Exp +from .scalar_affine import ScalarAffine +from .softplus import Softplus -__all__ = ['Bijector', - 'PowerTransform', - 'Exp'] +__all__ = [ + 'Bijector', + 'PowerTransform', + 'Exp', + 'ScalarAffine', + 'Softplus', +] diff --git a/mindspore/nn/probability/bijector/bijector.py b/mindspore/nn/probability/bijector/bijector.py index 22777231f6..ac011fda33 100644 --- a/mindspore/nn/probability/bijector/bijector.py +++ b/mindspore/nn/probability/bijector/bijector.py @@ -14,6 +14,7 @@ # ============================================================================ """Bijector""" from mindspore.nn.cell import Cell +from mindspore._checkparam import Validator as validator from ..distribution import Distribution from ..distribution import TransformedDistribution @@ -39,6 +40,9 @@ class Bijector(Cell): Constructor of bijector class. """ super(Bijector, self).__init__() + validator.check_value_type('name', name, [str], 'Bijector') + validator.check_value_type('is_constant_jacobian', is_constant_jacobian, [bool], name) + validator.check_value_type('is_injective', is_injective, [bool], name) self._name = name self._dtype = dtype self._parameters = {} @@ -69,31 +73,31 @@ class Bijector(Cell): def is_injective(self): return self._is_injective - def forward(self, *args): + def forward(self, *args, **kwargs): """ Forward transformation: transform the input value to another distribution. """ - return self._forward(*args) + return self._forward(*args, **kwargs) - def inverse(self, *args): + def inverse(self, *args, **kwargs): """ Inverse transformation: transform the input value back to the original distribution. """ - return self._inverse(*args) + return self._inverse(*args, **kwargs) - def forward_log_jacobian(self, *args): + def forward_log_jacobian(self, *args, **kwargs): """ Logarithm of the derivative of forward transformation. """ - return self._forward_log_jacobian(*args) + return self._forward_log_jacobian(*args, **kwargs) - def inverse_log_jacobian(self, *args): + def inverse_log_jacobian(self, *args, **kwargs): """ Logarithm of the derivative of forward transformation. """ - return self._inverse_log_jacobian(*args) + return self._inverse_log_jacobian(*args, **kwargs) - def __call__(self, *args): + def __call__(self, *args, **kwargs): """ Call Bijector directly. This __call__ may go into two directions: @@ -107,9 +111,9 @@ class Bijector(Cell): """ if isinstance(args[0], Distribution): return TransformedDistribution(self, args[0]) - return super(Bijector, self).__call__(*args) + return super(Bijector, self).__call__(*args, **kwargs) - def construct(self, name, *args): + def construct(self, name, *args, **kwargs): """ Override construct in Cell. @@ -120,11 +124,11 @@ class Bijector(Cell): Always raise RuntimeError as Distribution should not be called directly. """ if name == 'forward': - return self.forward(*args) + return self.forward(*args, **kwargs) if name == 'inverse': - return self.inverse(*args) + return self.inverse(*args, **kwargs) if name == 'forward_log_jacobian': - return self.forward_log_jacobian(*args) + return self.forward_log_jacobian(*args, **kwargs) if name == 'inverse_log_jacobian': - return self.inverse_log_jacobian(*args) + return self.inverse_log_jacobian(*args, **kwargs) return None diff --git a/mindspore/nn/probability/bijector/scalar_affine.py b/mindspore/nn/probability/bijector/scalar_affine.py new file mode 100644 index 0000000000..b48df1f0a7 --- /dev/null +++ b/mindspore/nn/probability/bijector/scalar_affine.py @@ -0,0 +1,116 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +"""Scalar Affine Bijector""" +from mindspore.ops import operations as P +from mindspore._checkparam import Validator as validator +from ..distribution._utils.utils import cast_to_tensor +from .bijector import Bijector + +class ScalarAffine(Bijector): + """ + Scalar Affine Bijector. + This Bijector performs the operation: Y = a * X + b, where a is the scale + factor and b is the shift factor. + + Args: + scale (float): scale factor. Default: 1.0. + shift (float): shift factor. Default: 0.0. + + Examples: + >>> # To initialize a ScalarAffine bijector of scale 1 and shift 2 + >>> scalaraffine = nn.probability.bijector.ScalarAffine(1, 2) + >>> + >>> # To use ScalarAffine bijector in a network + >>> class net(Cell): + >>> def __init__(self): + >>> super(net, self).__init__(): + >>> self.s1 = nn.probability.bijector.ScalarAffine(1, 2) + >>> + >>> def construct(self, value): + >>> # Similar calls can be made to other probability functions + >>> # by replacing 'forward' with the name of the function + >>> ans = self.s1.forward(value) + >>> ans = self.s1.inverse(value) + >>> ans = self.s1.forward_log_jacobian(value) + >>> ans = self.s1.inverse_log_jacobian(value) + """ + def __init__(self, + scale=1.0, + shift=0.0, + name='ScalarAffine'): + """ + Constructor of scalar affine bijector. + """ + param = dict(locals()) + validator.check_value_type('scale', scale, [float], name) + validator.check_value_type('shift', shift, [float], name) + self._scale = cast_to_tensor(scale) + self._shift = cast_to_tensor(shift) + super(ScalarAffine, self).__init__( + is_constant_jacobian=True, + is_injective=True, + name=name, + dtype=None, + param=param) + + self.log = P.Log() + self.oneslike = P.OnesLike() + + @property + def scale(self): + return self._scale + + @property + def shift(self): + return self._shift + + def extend_repr(self): + str_info = f'scale = {self.scale}, shift = {self.shift}' + return str_info + + def shape_mapping(self, shape): + return shape + + def _forward(self, x): + r""" + .. math:: + f(x) = a * x + b + """ + return self.scale * x + self.shift + + def _inverse(self, y): + r""" + .. math:: + f(y) = \frac{y - b}{a} + """ + return (y - self.shift) / self.scale + + def _forward_log_jacobian(self, value): + r""" + .. math:: + f(x) = a * x + b + f'(x) = a + \log(f'(x)) = \log(a) + """ + return self.log(self.scale) * self.oneslike(value) + + def _inverse_log_jacobian(self, value): + r""" + .. math:: + f(y) = \frac{(y - b)}{a} + f'(x) = \frac{1.0}{a} + \log(f'(x)) = - \log(a) + """ + return -1. * self.log(self.scale) * self.oneslike(value) diff --git a/mindspore/nn/probability/bijector/softplus.py b/mindspore/nn/probability/bijector/softplus.py new file mode 100644 index 0000000000..26f70c8fc7 --- /dev/null +++ b/mindspore/nn/probability/bijector/softplus.py @@ -0,0 +1,124 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +"""Softplus Bijector""" +from mindspore.ops import operations as P +from mindspore.nn.layer.activation import LogSigmoid +from mindspore._checkparam import Validator as validator +from ..distribution._utils.utils import cast_to_tensor +from .bijector import Bijector + +class Softplus(Bijector): + r""" + Softplus Bijector. + This Bijector performs the operation: Y = \frac{\log(1 + e ^ {kX})}{k}, where k is the sharpness factor. + + Args: + sharpness (float): scale factor. Default: 1.0. + + Examples: + >>> # To initialize a Softplus bijector of sharpness 2 + >>> softplus = nn.probability.bijector.Softfplus(2) + >>> + >>> # To use ScalarAffine bijector in a network + >>> class net(Cell): + >>> def __init__(self): + >>> super(net, self).__init__(): + >>> self.sp1 = nn.probability.bijector.Softflus(2) + >>> + >>> def construct(self, value): + >>> # Similar calls can be made to other probability functions + >>> # by replacing 'forward' with the name of the function + >>> ans = self.sp1.forward(value) + >>> ans = self.sp1.inverse(value) + >>> ans = self.sp1.forward_log_jacobian(value) + >>> ans = self.sp1.inverse_log_jacobian(value) + """ + def __init__(self, + sharpness=1.0, + name='Softplus'): + param = dict(locals()) + validator.check_value_type('sharpness', sharpness, [float], name) + super(Softplus, self).__init__(name=name, param=param) + self._sharpness = cast_to_tensor(sharpness) + + self.exp = P.Exp() + self.expm1 = self._expm1_by_step + self.log_sigmoid = LogSigmoid() + self.log = P.Log() + self.sigmoid = P.Sigmoid() + + self.softplus = self._softplus + self.inverse_softplus = self._inverse_softplus + + def _expm1_by_step(self, x): + """ + Expm1 ops under GPU context. + """ + return self.exp(x) - 1.0 + + def _softplus(self, x): + return self.log(self.exp(x) + 1.0) + + def _inverse_softplus(self, x): + r""" + .. math:: + f(x) = \frac{\log(1 + e^{x}))} + f^{-1}(y) = \frac{\log(e^{y} - 1)} + """ + return self.log(self.expm1(x)) + + @property + def sharpness(self): + return self._sharpness + + def extend_repr(self): + str_info = f'sharpness = {self.sharpness}' + return str_info + + def shape_mapping(self, shape): + return shape + + def _forward(self, x): + scaled_value = self.sharpness * x + return self.softplus(scaled_value) / self.sharpness + + def _inverse(self, y): + r""" + .. math:: + f(x) = \frac{\log(1 + e^{kx}))}{k} + f^{-1}(y) = \frac{\log(e^{ky} - 1)}{k} + """ + scaled_value = self.sharpness * y + return self.inverse_softplus(scaled_value) / self.sharpness + + def _forward_log_jacobian(self, x): + r""" + .. math: + f(x) = \log(1 + e^{kx}) / k + f'(x) = \frac{e^{kx}}{ 1 + e^{kx}} + \log(f'(x)) = kx - \log(1 + e^{kx}) = kx - f(kx) + """ + scaled_value = self.sharpness * x + return self.log_sigmoid(scaled_value) + + def _inverse_log_jacobian(self, y): + r""" + .. math: + f(y) = \frac{\log(e^{ky} - 1)}{k} + f'(y) = \frac{e^{ky}}{e^{ky} - 1} + \log(f'(y)) = ky - \log(e^{ky} - 1) = ky - f(ky) + """ + scaled_value = self.sharpness * y + return scaled_value - self.inverse_softplus(scaled_value) diff --git a/mindspore/nn/probability/distribution/_utils/__init__.py b/mindspore/nn/probability/distribution/_utils/__init__.py index f9cd3d3c2e..68586ae4fd 100644 --- a/mindspore/nn/probability/distribution/_utils/__init__.py +++ b/mindspore/nn/probability/distribution/_utils/__init__.py @@ -17,11 +17,14 @@ Distribution operation utility functions. """ from .utils import * -__all__ = ['convert_to_batch', - 'cast_to_tensor', - 'check_greater', - 'check_greater_equal_zero', - 'check_greater_zero', - 'calc_broadcast_shape_from_param', - 'check_scalar_from_param', - 'check_prob'] +__all__ = [ + 'convert_to_batch', + 'cast_to_tensor', + 'check_greater', + 'check_greater_equal_zero', + 'check_greater_zero', + 'calc_broadcast_shape_from_param', + 'check_scalar_from_param', + 'check_prob', + 'check_type', +] diff --git a/mindspore/nn/probability/distribution/_utils/utils.py b/mindspore/nn/probability/distribution/_utils/utils.py index aeccfc2b8f..2c11106be5 100644 --- a/mindspore/nn/probability/distribution/_utils/utils.py +++ b/mindspore/nn/probability/distribution/_utils/utils.py @@ -1,4 +1,3 @@ - # Copyright 2020 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +22,7 @@ from mindspore.ops import operations as P from mindspore.ops import composite as C import mindspore.nn as nn -def cast_to_tensor(t, dtype=mstype.float32): +def cast_to_tensor(t, hint_dtype=mstype.float32): """ Cast an user input value into a Tensor of dtype. If the input t is of type Parameter, t is directly returned as a Parameter. @@ -41,25 +40,26 @@ def cast_to_tensor(t, dtype=mstype.float32): if isinstance(t, Parameter): return t if isinstance(t, Tensor): + if t.dtype != hint_dtype: + raise TypeError(f"Input tensor should be type {hint_dtype}.") #check if the Tensor in shape of Tensor(4) if t.dim() == 0: value = t.asnumpy() - return Tensor([t], dtype=dtype) + return Tensor([value], dtype=hint_dtype) #convert the type of tensor to dtype - t.set_dtype(dtype) return t if isinstance(t, (list, np.ndarray)): - return Tensor(t, dtype=dtype) + return Tensor(t, dtype=hint_dtype) if np.isscalar(t): - return Tensor([t], dtype=dtype) + return Tensor([t], dtype=hint_dtype) raise RuntimeError("Input type is not supported.") -def convert_to_batch(t, batch_shape, dtype): +def convert_to_batch(t, batch_shape, hint_dtype): """ Convert a Tensor to a given batch shape. Args: - t (Tensor, Parameter): Tensor to be converted. + t (int, float, list, numpy.ndarray, Tensor, Parameter): Tensor to be converted. batch_shape (tuple): desired batch shape. dtype (mindspore.dtype): desired dtype. @@ -71,9 +71,8 @@ def convert_to_batch(t, batch_shape, dtype): """ if isinstance(t, Parameter): return t - if isinstance(t, Tensor): - return Tensor(np.broadcast_to(t.asnumpy(), batch_shape), dtype=dtype) - return Tensor(np.broadcast_to(t, batch_shape), dtype=dtype) + t = cast_to_tensor(t, hint_dtype) + return Tensor(np.broadcast_to(t.asnumpy(), batch_shape), dtype=hint_dtype) def check_scalar_from_param(params): """ @@ -85,6 +84,8 @@ def check_scalar_from_param(params): Notes: String parameters are excluded. """ for value in params.values(): + if isinstance(value, (nn.probability.bijector.Bijector, nn.probability.distribution.Distribution)): + return params['distribution'].is_scalar_batch if isinstance(value, Parameter): return False if isinstance(value, (str, type(params['dtype']))): @@ -108,6 +109,8 @@ def calc_broadcast_shape_from_param(params): """ broadcast_shape = [] for value in params.values(): + if isinstance(value, (nn.probability.bijector.Bijector, nn.probability.distribution.Distribution)): + return params['distribution'].broadcast_shape if isinstance(value, (str, type(params['dtype']))): continue if value is None: @@ -251,3 +254,7 @@ def check_tensor_type(name, inputs, valid_type): inputs = P.DType()(inputs) if inputs not in valid_type: raise TypeError(f"{name} dtype is invalid") + +def check_type(data_type, value_type, name): + if not data_type in value_type: + raise TypeError(f"For {name}, valid type include {value_type}, {data_type} is invalid") diff --git a/mindspore/nn/probability/distribution/bernoulli.py b/mindspore/nn/probability/distribution/bernoulli.py index 0aaeabf9a2..31253259e5 100644 --- a/mindspore/nn/probability/distribution/bernoulli.py +++ b/mindspore/nn/probability/distribution/bernoulli.py @@ -16,7 +16,7 @@ from mindspore.common import dtype as mstype from mindspore.ops import operations as P from .distribution import Distribution -from ._utils.utils import cast_to_tensor, check_prob +from ._utils.utils import cast_to_tensor, check_prob, check_type class Bernoulli(Distribution): """ @@ -95,13 +95,14 @@ class Bernoulli(Distribution): Constructor of Bernoulli distribution. """ param = dict(locals()) - super(Bernoulli, self).__init__(dtype, name, param) + valid_dtype = mstype.int_type + mstype.uint_type + check_type(dtype, valid_dtype, "Bernoulli") + super(Bernoulli, self).__init__(seed, dtype, name, param) if probs is not None: - self._probs = cast_to_tensor(probs, dtype=mstype.float32) + self._probs = cast_to_tensor(probs, hint_dtype=mstype.float32) check_prob(self.probs) else: self._probs = probs - self.seed = seed # ops needed for the class self.cast = P.Cast() @@ -231,8 +232,8 @@ class Bernoulli(Distribution): probs1_a (Tensor): probs1 of distribution a. Default: self.probs. .. math:: - KL(a||b) = probs1_a * \log(\fract{probs1_a}{probs1_b}) + - probs0_a * \log(\fract{probs0_a}{probs0_b}) + KL(a||b) = probs1_a * \log(\frac{probs1_a}{probs1_b}) + + probs0_a * \log(\frac{probs0_a}{probs0_b}) """ if dist == 'Bernoulli': probs1_a = self.probs if probs1_a is None else probs1_a diff --git a/mindspore/nn/probability/distribution/distribution.py b/mindspore/nn/probability/distribution/distribution.py index dd3d39f0d7..d3e7d3ccd9 100644 --- a/mindspore/nn/probability/distribution/distribution.py +++ b/mindspore/nn/probability/distribution/distribution.py @@ -14,6 +14,7 @@ # ============================================================================ """basic""" from mindspore.nn.cell import Cell +from mindspore._checkparam import Validator as validator from ._utils.utils import calc_broadcast_shape_from_param, check_scalar_from_param class Distribution(Cell): @@ -27,7 +28,7 @@ class Distribution(Cell): Note: Derived class should override operations such as ,_mean, _prob, - and _log_prob. Arguments should be passed in through *args. + and _log_prob. Arguments should be passed in through *args or **kwargs. Dist_spec_args are unique for each type of distribution. For example, mean and sd are the dist_spec_args for a Normal distribution. @@ -38,6 +39,7 @@ class Distribution(Cell): original distribuion. """ def __init__(self, + seed, dtype, name, param): @@ -46,7 +48,11 @@ class Distribution(Cell): Constructor of distribution class. """ super(Distribution, self).__init__() + validator.check_value_type('name', name, [str], 'distribution_name') + validator.check_value_type('seed', seed, [int], name) + self._name = name + self._seed = seed self._dtype = dtype self._parameters = {} # parsing parameters @@ -77,6 +83,10 @@ class Distribution(Cell): def dtype(self): return self._dtype + @property + def seed(self): + return self._seed + @property def parameters(self): return self._parameters @@ -85,6 +95,10 @@ class Distribution(Cell): def is_scalar_batch(self): return self._is_scalar_batch + @property + def broadcast_shape(self): + return self._broadcast_shape + def _set_prob(self): """ Set probability funtion based on the availability of _prob and _log_likehood. @@ -171,7 +185,7 @@ class Distribution(Cell): if hasattr(self, '_cross_entropy'): self._call_cross_entropy = self._cross_entropy - def log_prob(self, *args): + def log_prob(self, *args, **kwargs): """ Evaluate the log probability(pdf or pmf) at the given value. @@ -179,18 +193,18 @@ class Distribution(Cell): Args must include value. Dist_spec_args are optional. """ - return self._call_log_prob(*args) + return self._call_log_prob(*args, **kwargs) - def _calc_prob_from_log_prob(self, *args): + def _calc_prob_from_log_prob(self, *args, **kwargs): r""" Evaluate prob from log probability. .. math:: probability(x) = \exp(log_likehood(x)) """ - return self.exp(self._log_prob(*args)) + return self.exp(self._log_prob(*args, **kwargs)) - def prob(self, *args): + def prob(self, *args, **kwargs): """ Evaluate the probability (pdf or pmf) at given value. @@ -198,18 +212,18 @@ class Distribution(Cell): Args must include value. Dist_spec_args are optional. """ - return self._call_prob(*args) + return self._call_prob(*args, **kwargs) - def _calc_log_prob_from_prob(self, *args): + def _calc_log_prob_from_prob(self, *args, **kwargs): r""" Evaluate log probability from probability. .. math:: log_prob(x) = \log(prob(x)) """ - return self.log(self._prob(*args)) + return self.log(self._prob(*args, **kwargs)) - def cdf(self, *args): + def cdf(self, *args, **kwargs): """ Evaluate the cdf at given value. @@ -217,36 +231,36 @@ class Distribution(Cell): Args must include value. Dist_spec_args are optional. """ - return self._call_cdf(*args) + return self._call_cdf(*args, **kwargs) - def _calc_cdf_from_log_cdf(self, *args): + def _calc_cdf_from_log_cdf(self, *args, **kwargs): r""" Evaluate cdf from log_cdf. .. math:: cdf(x) = \exp(log_cdf(x)) """ - return self.exp(self._log_cdf(*args)) + return self.exp(self._log_cdf(*args, **kwargs)) - def _calc_cdf_from_survival(self, *args): + def _calc_cdf_from_survival(self, *args, **kwargs): r""" Evaluate cdf from survival function. .. math:: cdf(x) = 1 - (survival_function(x)) """ - return 1.0 - self._survival_function(*args) + return 1.0 - self._survival_function(*args, **kwargs) - def _calc_cdf_from_log_survival(self, *args): + def _calc_cdf_from_log_survival(self, *args, **kwargs): r""" Evaluate cdf from log survival function. .. math:: cdf(x) = 1 - (\exp(log_survival(x))) """ - return 1.0 - self.exp(self._log_survival(*args)) + return 1.0 - self.exp(self._log_survival(*args, **kwargs)) - def log_cdf(self, *args): + def log_cdf(self, *args, **kwargs): """ Evaluate the log cdf at given value. @@ -254,18 +268,18 @@ class Distribution(Cell): Args must include value. Dist_spec_args are optional. """ - return self._call_log_cdf(*args) + return self._call_log_cdf(*args, **kwargs) - def _calc_log_cdf_from_call_cdf(self, *args): + def _calc_log_cdf_from_call_cdf(self, *args, **kwargs): r""" Evaluate log cdf from cdf. .. math:: log_cdf(x) = \log(cdf(x)) """ - return self.log(self._call_cdf(*args)) + return self.log(self._call_cdf(*args, **kwargs)) - def survival_function(self, *args): + def survival_function(self, *args, **kwargs): """ Evaluate the survival function at given value. @@ -273,27 +287,27 @@ class Distribution(Cell): Args must include value. Dist_spec_args are optional. """ - return self._call_survival(*args) + return self._call_survival(*args, **kwargs) - def _calc_survival_from_call_cdf(self, *args): + def _calc_survival_from_call_cdf(self, *args, **kwargs): r""" Evaluate survival function from cdf. .. math:: survival_function(x) = 1 - (cdf(x)) """ - return 1.0 - self._call_cdf(*args) + return 1.0 - self._call_cdf(*args, **kwargs) - def _calc_survival_from_log_survival(self, *args): + def _calc_survival_from_log_survival(self, *args, **kwargs): r""" Evaluate survival function from log survival function. .. math:: survival(x) = \exp(survival_function(x)) """ - return self.exp(self._log_survival(*args)) + return self.exp(self._log_survival(*args, **kwargs)) - def log_survival(self, *args): + def log_survival(self, *args, **kwargs): """ Evaluate the log survival function at given value. @@ -301,18 +315,18 @@ class Distribution(Cell): Args must include value. Dist_spec_args are optional. """ - return self._call_log_survival(*args) + return self._call_log_survival(*args, **kwargs) - def _calc_log_survival_from_call_survival(self, *args): + def _calc_log_survival_from_call_survival(self, *args, **kwargs): r""" Evaluate log survival function from survival function. .. math:: log_survival(x) = \log(survival_function(x)) """ - return self.log(self._call_survival(*args)) + return self.log(self._call_survival(*args, **kwargs)) - def kl_loss(self, *args): + def kl_loss(self, *args, **kwargs): """ Evaluate the KL divergence, i.e. KL(a||b). @@ -320,72 +334,72 @@ class Distribution(Cell): Args must include type of the distribution, parameters of distribution b. Parameters for distribution a are optional. """ - return self._kl_loss(*args) + return self._kl_loss(*args, **kwargs) - def mean(self, *args): + def mean(self, *args, **kwargs): """ Evaluate the mean. Note: Dist_spec_args are optional. """ - return self._mean(*args) + return self._mean(*args, **kwargs) - def mode(self, *args): + def mode(self, *args, **kwargs): """ Evaluate the mode. Note: Dist_spec_args are optional. """ - return self._mode(*args) + return self._mode(*args, **kwargs) - def sd(self, *args): + def sd(self, *args, **kwargs): """ Evaluate the standard deviation. Note: Dist_spec_args are optional. """ - return self._call_sd(*args) + return self._call_sd(*args, **kwargs) - def var(self, *args): + def var(self, *args, **kwargs): """ Evaluate the variance. Note: Dist_spec_args are optional. """ - return self._call_var(*args) + return self._call_var(*args, **kwargs) - def _calc_sd_from_var(self, *args): + def _calc_sd_from_var(self, *args, **kwargs): r""" Evaluate log probability from probability. .. math:: STD(x) = \sqrt(VAR(x)) """ - return self.sqrt(self._var(*args)) + return self.sqrt(self._var(*args, **kwargs)) - def _calc_var_from_sd(self, *args): + def _calc_var_from_sd(self, *args, **kwargs): r""" Evaluate log probability from probability. .. math:: VAR(x) = STD(x) ^ 2 """ - return self.sq(self._sd(*args)) + return self.sq(self._sd(*args, **kwargs)) - def entropy(self, *args): + def entropy(self, *args, **kwargs): """ Evaluate the entropy. Note: Dist_spec_args are optional. """ - return self._entropy(*args) + return self._entropy(*args, **kwargs) - def cross_entropy(self, *args): + def cross_entropy(self, *args, **kwargs): """ Evaluate the cross_entropy between distribution a and b. @@ -393,32 +407,29 @@ class Distribution(Cell): Args must include type of the distribution, parameters of distribution b. Parameters for distribution a are optional. """ - return self._call_cross_entropy(*args) + return self._call_cross_entropy(*args, **kwargs) - def _calc_cross_entropy(self, *args): + def _calc_cross_entropy(self, *args, **kwargs): r""" Evaluate cross_entropy from entropy and kl divergence. .. math:: H(X, Y) = H(X) + KL(X||Y) """ - return self._entropy(*args) + self._kl_loss(*args) + return self._entropy(*args, **kwargs) + self._kl_loss(*args, **kwargs) - def sample(self, *args): + def sample(self, *args, **kwargs): """ Sampling function. - Args: - *args (list): arguments passed in through construct. - Note: Shape of the sample is default to (). Dist_spec_args are optional. """ - return self._sample(*args) + return self._sample(*args, **kwargs) - def construct(self, name, *args): + def construct(self, name, *args, **kwargs): """ Override construct in Cell. @@ -433,31 +444,31 @@ class Distribution(Cell): """ if name == 'log_prob': - return self._call_log_prob(*args) + return self._call_log_prob(*args, **kwargs) if name == 'prob': - return self._call_prob(*args) + return self._call_prob(*args, **kwargs) if name == 'cdf': - return self._call_cdf(*args) + return self._call_cdf(*args, **kwargs) if name == 'log_cdf': - return self._call_log_cdf(*args) + return self._call_log_cdf(*args, **kwargs) if name == 'survival_function': - return self._call_survival(*args) + return self._call_survival(*args, **kwargs) if name == 'log_survival': - return self._call_log_survival(*args) + return self._call_log_survival(*args, **kwargs) if name == 'kl_loss': - return self._kl_loss(*args) + return self._kl_loss(*args, **kwargs) if name == 'mean': - return self._mean(*args) + return self._mean(*args, **kwargs) if name == 'mode': - return self._mode(*args) + return self._mode(*args, **kwargs) if name == 'sd': - return self._call_sd(*args) + return self._call_sd(*args, **kwargs) if name == 'var': - return self._call_var(*args) + return self._call_var(*args, **kwargs) if name == 'entropy': - return self._entropy(*args) + return self._entropy(*args, **kwargs) if name == 'cross_entropy': - return self._call_cross_entropy(*args) + return self._call_cross_entropy(*args, **kwargs) if name == 'sample': - return self._sample(*args) + return self._sample(*args, **kwargs) return None diff --git a/mindspore/nn/probability/distribution/exponential.py b/mindspore/nn/probability/distribution/exponential.py index 74c6a40ab0..6f15958f95 100644 --- a/mindspore/nn/probability/distribution/exponential.py +++ b/mindspore/nn/probability/distribution/exponential.py @@ -17,7 +17,7 @@ import numpy as np from mindspore.ops import operations as P from mindspore.common import dtype as mstype from .distribution import Distribution -from ._utils.utils import cast_to_tensor, check_greater_zero +from ._utils.utils import cast_to_tensor, check_greater_zero, check_type class Exponential(Distribution): """ @@ -96,9 +96,11 @@ class Exponential(Distribution): Constructor of Exponential distribution. """ param = dict(locals()) - super(Exponential, self).__init__(dtype, name, param) + valid_dtype = mstype.float_type + check_type(dtype, valid_dtype, "Exponential") + super(Exponential, self).__init__(seed, dtype, name, param) if rate is not None: - self._rate = cast_to_tensor(rate, mstype.float32) + self._rate = cast_to_tensor(rate, dtype) check_greater_zero(self._rate, "rate") else: self._rate = rate @@ -135,7 +137,7 @@ class Exponential(Distribution): def _mean(self, rate=None): r""" .. math:: - MEAN(EXP) = \fract{1.0}{\lambda}. + MEAN(EXP) = \frac{1.0}{\lambda}. """ rate = self.rate if rate is None else rate return 1.0 / rate @@ -152,7 +154,7 @@ class Exponential(Distribution): def _sd(self, rate=None): r""" .. math:: - sd(EXP) = \fract{1.0}{\lambda}. + sd(EXP) = \frac{1.0}{\lambda}. """ rate = self.rate if rate is None else rate return 1.0 / rate diff --git a/mindspore/nn/probability/distribution/geometric.py b/mindspore/nn/probability/distribution/geometric.py index 59bc8f0c99..87ad7ad8a4 100644 --- a/mindspore/nn/probability/distribution/geometric.py +++ b/mindspore/nn/probability/distribution/geometric.py @@ -17,7 +17,7 @@ import numpy as np from mindspore.ops import operations as P from mindspore.common import dtype as mstype from .distribution import Distribution -from ._utils.utils import cast_to_tensor, check_prob +from ._utils.utils import cast_to_tensor, check_prob, check_type class Geometric(Distribution): """ @@ -97,9 +97,11 @@ class Geometric(Distribution): Constructor of Geometric distribution. """ param = dict(locals()) - super(Geometric, self).__init__(dtype, name, param) + valid_dtype = mstype.int_type + mstype.uint_type + check_type(dtype, valid_dtype, "Geometric") + super(Geometric, self).__init__(seed, dtype, name, param) if probs is not None: - self._probs = cast_to_tensor(probs, dtype=mstype.float32) + self._probs = cast_to_tensor(probs, hint_dtype=mstype.float32) check_prob(self._probs) else: self._probs = probs @@ -154,7 +156,7 @@ class Geometric(Distribution): def _var(self, probs1=None): r""" .. math:: - VAR(Geo) = \fract{1 - probs1}{probs1 ^ {2}} + VAR(Geo) = \frac{1 - probs1}{probs1 ^ {2}} """ probs1 = self.probs if probs1 is None else probs1 return (1.0 - probs1) / self.sq(probs1) @@ -162,7 +164,7 @@ class Geometric(Distribution): def _entropy(self, probs=None): r""" .. math:: - H(Geo) = \fract{-1 * probs0 \log_2 (1-probs0)\ - prob1 * \log_2 (1-probs1)\ }{probs1} + H(Geo) = \frac{-1 * probs0 \log_2 (1-probs0)\ - prob1 * \log_2 (1-probs1)\ }{probs1} """ probs1 = self.probs if probs is None else probs probs0 = 1.0 - probs1 @@ -244,7 +246,7 @@ class Geometric(Distribution): probs1_a (Tensor): probability of success of distribution a. Default: self.probs. .. math:: - KL(a||b) = \log(\fract{probs1_a}{probs1_b}) + \fract{probs0_a}{probs1_a} * \log(\fract{probs0_a}{probs0_b}) + KL(a||b) = \log(\frac{probs1_a}{probs1_b}) + \frac{probs0_a}{probs1_a} * \log(\frac{probs0_a}{probs0_b}) """ if dist == 'Geometric': probs1_a = self.probs if probs1_a is None else probs1_a diff --git a/mindspore/nn/probability/distribution/normal.py b/mindspore/nn/probability/distribution/normal.py index f243a2bc31..e1dfbee89d 100644 --- a/mindspore/nn/probability/distribution/normal.py +++ b/mindspore/nn/probability/distribution/normal.py @@ -18,7 +18,7 @@ from mindspore.ops import operations as P from mindspore.ops import composite as C from mindspore.common import dtype as mstype from .distribution import Distribution -from ._utils.utils import convert_to_batch, check_greater_equal_zero +from ._utils.utils import convert_to_batch, check_greater_equal_zero, check_type class Normal(Distribution): @@ -100,15 +100,17 @@ class Normal(Distribution): Constructor of normal distribution. """ param = dict(locals()) - super(Normal, self).__init__(dtype, name, param) + valid_dtype = mstype.float_type + check_type(dtype, valid_dtype, "Normal") + super(Normal, self).__init__(seed, dtype, name, param) if mean is not None and sd is not None: - self._mean_value = convert_to_batch(mean, self._broadcast_shape, dtype) - self._sd_value = convert_to_batch(sd, self._broadcast_shape, dtype) + self._mean_value = convert_to_batch(mean, self.broadcast_shape, dtype) + self._sd_value = convert_to_batch(sd, self.broadcast_shape, dtype) check_greater_equal_zero(self._sd_value, "Standard deviation") else: self._mean_value = mean self._sd_value = sd - self.seed = seed + #ops needed for the class self.const = P.ScalarToArray() @@ -191,7 +193,7 @@ class Normal(Distribution): sd (Tensor): standard deviation the distribution. Default: self._sd_value. .. math:: - L(x) = -1* \fract{(x - \mu)^2}{2. * \sigma^2} - \log(\sqrt(2* \pi * \sigma^2)) + L(x) = -1* \frac{(x - \mu)^2}{2. * \sigma^2} - \log(\sqrt(2* \pi * \sigma^2)) """ mean = self._mean_value if mean is None else mean sd = self._sd_value if sd is None else sd @@ -229,7 +231,7 @@ class Normal(Distribution): sd_a (Tensor): standard deviation distribution a. Default: self._sd_value. .. math:: - KL(a||b) = 0.5 * (\fract{MEAN(a)}{STD(b)} - \fract{MEAN(b)}{STD(b)}) ^ 2 + + KL(a||b) = 0.5 * (\frac{MEAN(a)}{STD(b)} - \frac{MEAN(b)}{STD(b)}) ^ 2 + 0.5 * EXPM1(2 * (\log(STD(a)) - \log(STD(b))) - (\log(STD(a)) - \log(STD(b))) """ if dist == 'Normal': @@ -256,8 +258,5 @@ class Normal(Distribution): sd = self._sd_value if sd is None else sd batch_shape = self.shape(self.zeroslike(mean) + self.zeroslike(sd)) sample_shape = shape + batch_shape - mean_zero = self.const(0.0) - sd_one = self.const(1.0) - sample_norm = C.normal(sample_shape, mean_zero, sd_one, self.seed) - sample = mean + sample_norm * sd - return sample + sample_norm = C.normal(sample_shape, mean, sd, self.seed) + return sample_norm diff --git a/mindspore/nn/probability/distribution/transformed_distribution.py b/mindspore/nn/probability/distribution/transformed_distribution.py index 37f474e943..baed5f10d1 100644 --- a/mindspore/nn/probability/distribution/transformed_distribution.py +++ b/mindspore/nn/probability/distribution/transformed_distribution.py @@ -14,7 +14,11 @@ # ============================================================================ """Transformed Distribution""" from mindspore.ops import operations as P +from mindspore._checkparam import Validator as validator +from mindspore.common import dtype as mstype +import mindspore.nn as nn from .distribution import Distribution +from ._utils.utils import check_type class TransformedDistribution(Distribution): """ @@ -35,12 +39,19 @@ class TransformedDistribution(Distribution): def __init__(self, bijector, distribution, + dtype, + seed=0, name="transformed_distribution"): """ Constructor of transformed_distribution class. """ param = dict(locals()) - super(TransformedDistribution, self).__init__(distribution.dtype, name, param) + validator.check_value_type('bijector', bijector, [nn.probability.bijector.Bijector], name) + validator.check_value_type('distribution', distribution, [Distribution], name) + valid_dtype = mstype.number_type + check_type(dtype, valid_dtype, "transformed_distribution") + super(TransformedDistribution, self).__init__(seed, dtype, name, param) + self._bijector = bijector self._distribution = distribution self._is_linear_transformation = bijector.is_constant_jacobian diff --git a/mindspore/nn/probability/distribution/uniform.py b/mindspore/nn/probability/distribution/uniform.py index 2fc459f56d..b1f2aba90a 100644 --- a/mindspore/nn/probability/distribution/uniform.py +++ b/mindspore/nn/probability/distribution/uniform.py @@ -16,7 +16,7 @@ from mindspore.ops import operations as P from mindspore.common import dtype as mstype from .distribution import Distribution -from ._utils.utils import convert_to_batch, check_greater +from ._utils.utils import convert_to_batch, check_greater, check_type class Uniform(Distribution): """ @@ -97,10 +97,12 @@ class Uniform(Distribution): Constructor of Uniform distribution. """ param = dict(locals()) - super(Uniform, self).__init__(dtype, name, param) + valid_dtype = mstype.float_type + check_type(dtype, valid_dtype, "Uniform") + super(Uniform, self).__init__(seed, dtype, name, param) if low is not None and high is not None: - self._low = convert_to_batch(low, self._broadcast_shape, dtype) - self._high = convert_to_batch(high, self._broadcast_shape, dtype) + self._low = convert_to_batch(low, self.broadcast_shape, dtype) + self._high = convert_to_batch(high, self.broadcast_shape, dtype) check_greater(self.low, self.high, "low value", "high value") else: self._low = low @@ -156,7 +158,7 @@ class Uniform(Distribution): def _mean(self, low=None, high=None): r""" .. math:: - MEAN(U) = \fract{low + high}{2}. + MEAN(U) = \frac{low + high}{2}. """ low = self.low if low is None else low high = self.high if high is None else high @@ -166,7 +168,7 @@ class Uniform(Distribution): def _var(self, low=None, high=None): r""" .. math:: - VAR(U) = \fract{(high -low) ^ 2}{12}. + VAR(U) = \frac{(high -low) ^ 2}{12}. """ low = self.low if low is None else low high = self.high if high is None else high @@ -207,7 +209,7 @@ class Uniform(Distribution): .. math:: pdf(x) = 0 if x < low; - pdf(x) = \fract{1.0}{high -low} if low <= x <= high; + pdf(x) = \frac{1.0}{high -low} if low <= x <= high; pdf(x) = 0 if x > high; """ low = self.low if low is None else low @@ -251,7 +253,7 @@ class Uniform(Distribution): .. math:: cdf(x) = 0 if x < low; - cdf(x) = \fract{x - low}{high -low} if low <= x <= high; + cdf(x) = \frac{x - low}{high -low} if low <= x <= high; cdf(x) = 1 if x > high; """ low = self.low if low is None else low diff --git a/mindspore/nn/wrap/cell_wrapper.py b/mindspore/nn/wrap/cell_wrapper.py index 9e3d00cc95..a7fb4adcf0 100644 --- a/mindspore/nn/wrap/cell_wrapper.py +++ b/mindspore/nn/wrap/cell_wrapper.py @@ -201,8 +201,8 @@ class DataWrapper(Cell): Args: network (Cell): The training network for dataset. - dataset_types (list): The type of dataset. The list contains describes the types of the inputs. - dataset_shapes (list): The shapes of dataset. The list contains multiple sublists that describes + dataset_types (list): The type of dataset. The list contains the types of the inputs. + dataset_shapes (list): The shapes of dataset. The list contains multiple sublists that describe the shape of the inputs. queue_name (str): The identification of dataset channel which specifies the dataset channel to supply data for the network. diff --git a/mindspore/ops/_grad/grad_array_ops.py b/mindspore/ops/_grad/grad_array_ops.py index d4079f38e2..043d3aeb9c 100644 --- a/mindspore/ops/_grad/grad_array_ops.py +++ b/mindspore/ops/_grad/grad_array_ops.py @@ -693,7 +693,7 @@ def get_bprop_unsorted_segment_min(self): select = P.Select() def bprop(x, segment_ids, num_segments, out, dout): - gathered_outputs, zero_clipped_indices, is_positive = _GatherDropNegatives(out, segment_ids) + gathered_outputs, zero_clipped_indices, is_positive = _GatherDropNegatives(out, segment_ids, None, None) is_selected = equal(x, gathered_outputs) is_selected = logical_and(is_selected, is_positive) num_selected = unsorted_segment_sum(cast(is_selected, get_dtype(dout)), diff --git a/mindspore/ops/_grad/grad_comm_ops.py b/mindspore/ops/_grad/grad_comm_ops.py index fb54eab172..d1282f8ecb 100644 --- a/mindspore/ops/_grad/grad_comm_ops.py +++ b/mindspore/ops/_grad/grad_comm_ops.py @@ -222,9 +222,17 @@ def get_bprop_virtual_div_operator(self): dtype = P.DType() def bprop(x, out, dout): - if F.issubclass_(F.dtype(dout), mstype.bool_): - return (dout,) - dx = op(dout, cast(F.scalar_to_array(divisor), dtype(dout))) + if F.issubclass_(F.typeof(dout), mstype.tensor): + if F.issubclass_(F.dtype(dout), mstype.bool_): + return (dout,) + dx = op(dout, cast(F.scalar_to_array(divisor), dtype(dout))) + return (dx,) + + dx = () + input_nums = F.tuple_len(dout) + for i in range(input_nums): + ele_grad = op(dout[i], cast(F.scalar_to_array(divisor), dtype(dout[i]))) + dx = dx + (ele_grad,) return (dx,) return bprop diff --git a/mindspore/ops/_op_impl/akg/gpu/cast.py b/mindspore/ops/_op_impl/akg/gpu/cast.py index 68c280f348..0e6e29154a 100644 --- a/mindspore/ops/_op_impl/akg/gpu/cast.py +++ b/mindspore/ops/_op_impl/akg/gpu/cast.py @@ -23,6 +23,7 @@ cast_op_info = AkgGpuRegOp("Cast") \ .dtype_format(DataType.F16_Default, DataType.F32_Default) \ .dtype_format(DataType.F16_Default, DataType.I32_Default) \ .dtype_format(DataType.F16_Default, DataType.F64_Default) \ + .dtype_format(DataType.F16_Default, DataType.BOOL_Default) \ .dtype_format(DataType.I32_Default, DataType.F16_Default) \ .dtype_format(DataType.I32_Default, DataType.F32_Default) \ .dtype_format(DataType.I32_Default, DataType.I8_Default) \ @@ -34,6 +35,7 @@ cast_op_info = AkgGpuRegOp("Cast") \ .dtype_format(DataType.I8_Default, DataType.I32_Default) \ .dtype_format(DataType.I8_Default, DataType.I16_Default) \ .dtype_format(DataType.I8_Default, DataType.I64_Default) \ + .dtype_format(DataType.I8_Default, DataType.BOOL_Default) \ .dtype_format(DataType.BOOL_Default, DataType.F32_Default) \ .dtype_format(DataType.BOOL_Default, DataType.F16_Default) \ .dtype_format(DataType.BOOL_Default, DataType.F64_Default) \ @@ -44,19 +46,29 @@ cast_op_info = AkgGpuRegOp("Cast") \ .dtype_format(DataType.U8_Default, DataType.F32_Default) \ .dtype_format(DataType.U8_Default, DataType.F16_Default) \ .dtype_format(DataType.U8_Default, DataType.I32_Default) \ + .dtype_format(DataType.U8_Default, DataType.BOOL_Default) \ .dtype_format(DataType.I16_Default, DataType.F64_Default) \ .dtype_format(DataType.I16_Default, DataType.F32_Default) \ .dtype_format(DataType.I16_Default, DataType.F16_Default) \ .dtype_format(DataType.I16_Default, DataType.I32_Default) \ .dtype_format(DataType.I16_Default, DataType.I64_Default) \ + .dtype_format(DataType.I16_Default, DataType.F32_Default) \ + .dtype_format(DataType.I16_Default, DataType.BOOL_Default) \ .dtype_format(DataType.I64_Default, DataType.F64_Default) \ .dtype_format(DataType.I64_Default, DataType.F32_Default) \ .dtype_format(DataType.I64_Default, DataType.F16_Default) \ .dtype_format(DataType.I64_Default, DataType.I32_Default) \ - .dtype_format(DataType.I16_Default, DataType.F32_Default) \ - .dtype_format(DataType.I16_Default, DataType.F16_Default) \ + .dtype_format(DataType.I64_Default, DataType.BOOL_Default) \ .dtype_format(DataType.F32_Default, DataType.I32_Default) \ .dtype_format(DataType.F32_Default, DataType.F16_Default) \ + .dtype_format(DataType.F32_Default, DataType.BOOL_Default) \ + .dtype_format(DataType.F64_Default, DataType.BOOL_Default) \ + .dtype_format(DataType.F64_Default, DataType.F32_Default) \ + .dtype_format(DataType.F64_Default, DataType.F16_Default) \ + .dtype_format(DataType.F64_Default, DataType.I64_Default) \ + .dtype_format(DataType.F64_Default, DataType.I32_Default) \ + .dtype_format(DataType.F64_Default, DataType.I16_Default) \ + .dtype_format(DataType.F64_Default, DataType.I8_Default) \ .get_op_info() diff --git a/mindspore/ops/_op_impl/tbe/__init__.py b/mindspore/ops/_op_impl/tbe/__init__.py index 4146089ffa..4f272326e3 100644 --- a/mindspore/ops/_op_impl/tbe/__init__.py +++ b/mindspore/ops/_op_impl/tbe/__init__.py @@ -177,8 +177,8 @@ from .lamb_update_with_lr import _lamb_update_with_lr_tbe from .rsqrt import _rsqrt_tbe from .sigmoid import _sigmoid_tbe from .sigmoid_grad import _sigmoid_grad_tbe -from .resize_nearest_neighbor_d import _resize_nearest_neighbor_d_tbe -from .resize_nearest_neighbor_grad_d import _resize_nearest_neighbor_grad_d_tbe +from .resize_nearest_neighbor import _resize_nearest_neighbor_tbe +from .resize_nearest_neighbor_grad import _resize_nearest_neighbor_grad_tbe from .pad_d import _pad_d_tbe from .arg_max_with_value import _arg_max_with_value_tbe from .arg_min_with_value import _arg_min_with_value_tbe diff --git a/mindspore/ops/_op_impl/tbe/broadcast_to.py b/mindspore/ops/_op_impl/tbe/broadcast_to.py index 5d4b642017..e9684bcea2 100644 --- a/mindspore/ops/_op_impl/tbe/broadcast_to.py +++ b/mindspore/ops/_op_impl/tbe/broadcast_to.py @@ -30,7 +30,7 @@ broadcast_to_op_info = TBERegOp("BroadcastTo") \ .dtype_format(DataType.F32_Default, DataType.F32_Default) \ .dtype_format(DataType.I32_Default, DataType.I32_Default) \ .dtype_format(DataType.I8_Default, DataType.I8_Default) \ - .dtype_format(DataType.U8_Default, DataType.U16_Default) \ + .dtype_format(DataType.U8_Default, DataType.U8_Default) \ .get_op_info() diff --git a/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py b/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py index 8a66f75dbb..4fa3107f59 100644 --- a/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py +++ b/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor.py @@ -27,20 +27,12 @@ resize_nearest_neighbor_op_info = TBERegOp("ResizeNearestNeighbor") \ .attr("align_corners", "optional", "bool", "all") \ .input(0, "images", False, "required", "all") \ .output(0, "y", True, "required", "all") \ - .dtype_format(DataType.I8_Default, DataType.I8_Default) \ - .dtype_format(DataType.I8_5HD, DataType.I8_5HD) \ - .dtype_format(DataType.U8_Default, DataType.U8_Default) \ - .dtype_format(DataType.U8_5HD, DataType.U8_5HD) \ - .dtype_format(DataType.I32_Default, DataType.I32_Default) \ - .dtype_format(DataType.I32_5HD, DataType.I32_5HD) \ - .dtype_format(DataType.F16_Default, DataType.F16_Default) \ .dtype_format(DataType.F16_5HD, DataType.F16_5HD) \ - .dtype_format(DataType.F32_Default, DataType.F32_Default) \ .dtype_format(DataType.F32_5HD, DataType.F32_5HD) \ .get_op_info() @op_info_register(resize_nearest_neighbor_op_info) -def _resize_nearest_neighbor_d_tbe(): +def _resize_nearest_neighbor_tbe(): """ResizeNearestNeighbor TBE register""" return diff --git a/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_d.py b/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_d.py deleted file mode 100644 index 4b54da991a..0000000000 --- a/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_d.py +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2020 Huawei Technologies Co., Ltd -# -# 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. -# ============================================================================ - -"""ResizeNearestNeighbor op""" -from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType - -resize_nearest_neighbor_d_op_info = TBERegOp("ResizeNearestNeighbor") \ - .fusion_type("OPAQUE") \ - .async_flag(False) \ - .binfile_name("resize_nearest_neighbor_d.so") \ - .compute_cost(10) \ - .kernel_name("resize_nearest_neighbor_d") \ - .partial_flag(True) \ - .attr("size", "required", "listInt", "all") \ - .attr("align_corners", "optional", "bool", "all") \ - .input(0, "images", False, "required", "all") \ - .output(0, "y", True, "required", "all") \ - .dtype_format(DataType.I8_5HD, DataType.I8_5HD) \ - .dtype_format(DataType.U8_5HD, DataType.U8_5HD) \ - .dtype_format(DataType.I32_5HD, DataType.I32_5HD) \ - .dtype_format(DataType.F16_5HD, DataType.F16_5HD) \ - .dtype_format(DataType.F32_5HD, DataType.F32_5HD) \ - .get_op_info() - - -@op_info_register(resize_nearest_neighbor_d_op_info) -def _resize_nearest_neighbor_d_tbe(): - """ResizeNearestNeighbor TBE register""" - return diff --git a/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_d.py b/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py similarity index 88% rename from mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_d.py rename to mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py index 6ee6c56146..d13150b5fb 100644 --- a/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad_d.py +++ b/mindspore/ops/_op_impl/tbe/resize_nearest_neighbor_grad.py @@ -16,7 +16,7 @@ """ResizeNearestNeighborgrad op""" from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType -resize_nearest_neighbor_grad_d_op_info = TBERegOp("ResizeNearestNeighborGrad") \ +resize_nearest_neighbor_grad_op_info = TBERegOp("ResizeNearestNeighborGrad") \ .fusion_type("OPAQUE") \ .async_flag(False) \ .binfile_name("resize_nearest_neighbor_grad_d.so") \ @@ -31,7 +31,7 @@ resize_nearest_neighbor_grad_d_op_info = TBERegOp("ResizeNearestNeighborGrad") \ .get_op_info() -@op_info_register(resize_nearest_neighbor_grad_d_op_info) -def _resize_nearest_neighbor_grad_d_tbe(): +@op_info_register(resize_nearest_neighbor_grad_op_info) +def _resize_nearest_neighbor_grad_tbe(): """ResizeNearestNeighborGrad TBE register""" return diff --git a/mindspore/ops/_op_impl/tbe/transpose_d.py b/mindspore/ops/_op_impl/tbe/transpose_d.py index fffc95a38f..3a43a7341d 100644 --- a/mindspore/ops/_op_impl/tbe/transpose_d.py +++ b/mindspore/ops/_op_impl/tbe/transpose_d.py @@ -26,6 +26,7 @@ transpose_d_op_info = TBERegOp("Transpose") \ .attr("perm", "optional", "listInt", "all") \ .input(0, "x", False, "required", "all") \ .output(0, "y", False, "required", "all") \ + .dtype_format(DataType.BOOL_Default, DataType.BOOL_Default) \ .dtype_format(DataType.I8_Default, DataType.I8_Default) \ .dtype_format(DataType.U8_Default, DataType.U8_Default) \ .dtype_format(DataType.I16_Default, DataType.I16_Default) \ diff --git a/mindspore/ops/operations/_grad_ops.py b/mindspore/ops/operations/_grad_ops.py index 7940662f48..105e0807cc 100644 --- a/mindspore/ops/operations/_grad_ops.py +++ b/mindspore/ops/operations/_grad_ops.py @@ -663,16 +663,16 @@ class MaxPoolGradGrad(_PoolGrad): strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1. - padding (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + padding (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: - **origin_input** (Tensor) - Tensor with data format "NCHW", data type should be float16. @@ -736,16 +736,16 @@ class MaxPoolGradGradWithArgmax(_PoolGrad): strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1. - padding (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + padding (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: - **x** (Tensor) - Tensor with data format "NCHW", data type should be float16. diff --git a/mindspore/ops/operations/array_ops.py b/mindspore/ops/operations/array_ops.py index e76ab49ee7..35a91d0c61 100644 --- a/mindspore/ops/operations/array_ops.py +++ b/mindspore/ops/operations/array_ops.py @@ -1463,7 +1463,9 @@ class UnsortedSegmentMin(PrimitiveWithInfer): Inputs: - **input_x** (Tensor) - The shape is :math:`(x_1, x_2, ..., x_R)`. + The data type should be float16, float32 or int32. - **segment_ids** (Tensor) - A `1-D` tensor whose shape is :math:`(x_1)`, the value should be >= 0. + The data type must be int32. - **num_segments** (int) - The value spcifies the number of distinct `segment_ids`. Outputs: @@ -2450,7 +2452,7 @@ class GatherNd(PrimitiveWithInfer): Inputs: - **input_x** (Tensor) - The target tensor to gather values. - - **indices** (Tensor) - The index tensor. + - **indices** (Tensor) - The index tensor, with int data type. Outputs: Tensor, has the same type as `input_x` and the shape is indices_shape[:-1] + x_shape[indices_shape[-1]:]. @@ -2847,7 +2849,7 @@ class ScatterNonAliasingAdd(_ScatterNdOp): This operation outputs the `input_x` after the update is done, which makes it convenient to use the updated value. Inputs: - - **input_x** (Parameter) - The target parameter. + - **input_x** (Parameter) - The target parameter. The data type should be float16, float32 or int32. - **indices** (Tensor) - The index to do add operation whose data type should be mindspore.int32. - **updates** (Tensor) - The tensor doing the add operation with `input_x`, the data type is same as `input_x`, the shape is `indices_shape[:-1] + x_shape[indices_shape[-1]:]`. diff --git a/mindspore/ops/operations/math_ops.py b/mindspore/ops/operations/math_ops.py index 9bfa078560..6666c8bb5c 100644 --- a/mindspore/ops/operations/math_ops.py +++ b/mindspore/ops/operations/math_ops.py @@ -943,9 +943,9 @@ class InplaceAdd(PrimitiveWithInfer): to add with v. It is a int or tuple, whose value is in [0, the first dimension size of x). Inputs: - - **input_x** (Tensor) - The first input is a tensor whose data type is number. + - **input_x** (Tensor) - The first input is a tensor whose data type is float16, float32 or int32. - **input_v** (Tensor) - The second input is a tensor who has the same dimension sizes as x except - the first dimension, which must be the same as indices's size. + the first dimension, which must be the same as indices's size. It has the same data type with `input_x`. Outputs: Tensor, has the same shape and dtype as input. @@ -1001,9 +1001,9 @@ class InplaceSub(PrimitiveWithInfer): to sub with v. It is a int or tuple, whose value is in [0, the first dimension size of x). Inputs: - - **input_x** (Tensor) - The first input is a tensor whose data type is number. + - **input_x** (Tensor) - The first input is a tensor whose data type is float16, float32 or int32. - **input_v** (Tensor) - The second input is a tensor who has the same dimension sizes as x except - the first dimension, which must be the same as indices's size. + the first dimension, which must be the same as indices's size. It has the same data type with `input_x`. Outputs: Tensor, has the same shape and dtype as input. @@ -1403,7 +1403,7 @@ class Expm1(PrimitiveWithInfer): Returns exponential then minus 1 of a tensor element-wise. Inputs: - - **input_x** (Tensor) - The input tensor. + - **input_x** (Tensor) - The input tensor. With float16 or float32 data type. Outputs: Tensor, has the same shape as the `input_x`. @@ -1425,6 +1425,7 @@ class Expm1(PrimitiveWithInfer): def infer_dtype(self, x_type): validator.check_subclass("x", x_type, mstype.tensor, self.name) + validator.check_tensor_type_same({"x": x_type}, [mstype.float16, mstype.float32], self.name) return x_type @@ -1515,7 +1516,7 @@ class Log1p(PrimitiveWithInfer): Returns the natural logarithm of one plus the input tensor element-wise. Inputs: - - **input_x** (Tensor) - The input tensor. + - **input_x** (Tensor) - The input tensor. With float16 or float32 data type. Outputs: Tensor, has the same shape as the `input_x`. @@ -1536,6 +1537,7 @@ class Log1p(PrimitiveWithInfer): def infer_dtype(self, x): validator.check_subclass("x", x, mstype.tensor, self.name) + validator.check_tensor_type_same({"x": x}, [mstype.float16, mstype.float32], self.name) return x @@ -1544,7 +1546,7 @@ class Erf(PrimitiveWithInfer): Computes the Gauss error function of `input_x` element-wise. Inputs: - - **input_x** (Tensor) - The input tensor. + - **input_x** (Tensor) - The input tensor. The data type must be float16 or float32. Outputs: Tensor, has the same shape and dtype as the `input_x`. @@ -1574,7 +1576,7 @@ class Erfc(PrimitiveWithInfer): Computes the complementary error function of `input_x` element-wise. Inputs: - - **input_x** (Tensor) - The input tensor. + - **input_x** (Tensor) - The input tensor. The data type mast be float16 or float32. Outputs: Tensor, has the same shape and dtype as the `input_x`. @@ -1674,6 +1676,7 @@ class Maximum(_MathBinaryOp): return Tensor(out) return None + class RealDiv(_MathBinaryOp): """ Divide the first input tensor by the second input tensor in floating-point type element-wise. @@ -1923,7 +1926,7 @@ class Floor(PrimitiveWithInfer): Round a tensor down to the closest integer element-wise. Inputs: - - **input_x** (Tensor) - The input tensor. Its element data type must be float. + - **input_x** (Tensor) - The input tensor. It's element data type must be float. Outputs: Tensor, has the same shape as `input_x`. @@ -1981,7 +1984,7 @@ class Ceil(PrimitiveWithInfer): Round a tensor up to the closest integer element-wise. Inputs: - - **input_x** (Tensor) - The input tensor. Its element data type must be float. + - **input_x** (Tensor) - The input tensor. It's element data type must be float16 or float32. Outputs: Tensor, has the same shape as `input_x`. @@ -2001,7 +2004,7 @@ class Ceil(PrimitiveWithInfer): return x_shape def infer_dtype(self, x_dtype): - validator.check_tensor_type_same({"x": x_dtype}, mstype.float_type, self.name) + validator.check_tensor_type_same({"x": x_dtype}, [mstype.float16, mstype.float32], self.name) return x_dtype @@ -2666,7 +2669,7 @@ class FloatStatus(PrimitiveWithInfer): Determine if the elements contains nan, inf or -inf. `0` for normal, `1` for overflow. Inputs: - - **input_x** (Tensor) - The input tensor. + - **input_x** (Tensor) - The input tensor. The data type must be float16 or float32. Outputs: Tensor, has the shape of `(1,)`, and has the same dtype of input `mindspore.dtype.float32` or @@ -2731,6 +2734,7 @@ class NPUGetFloatStatus(PrimitiveWithInfer): Inputs: - **input_x** (Tensor) - The output tensor of `NPUAllocFloatStatus`. + The data type must be float16 or float32. Outputs: Tensor, has the same shape as `input_x`. All the elements in the tensor will be zero. @@ -2755,7 +2759,7 @@ class NPUGetFloatStatus(PrimitiveWithInfer): return [8] def infer_dtype(self, x_dtype): - validator.check_tensor_type_same({'x': x_dtype}, [mstype.float32], self.name) + validator.check_tensor_type_same({'x': x_dtype}, [mstype.float16, mstype.float32], self.name) return mstype.float32 @@ -2771,6 +2775,7 @@ class NPUClearFloatStatus(PrimitiveWithInfer): Inputs: - **input_x** (Tensor) - The output tensor of `NPUAllocFloatStatus`. + The data type must be float16 or float32. Outputs: Tensor, has the same shape as `input_x`. All the elements in the tensor will be zero. @@ -2797,7 +2802,7 @@ class NPUClearFloatStatus(PrimitiveWithInfer): return [8] def infer_dtype(self, x_dtype): - validator.check_tensor_type_same({'x': x_dtype}, [mstype.float32], self.name) + validator.check_tensor_type_same({'x': x_dtype}, [mstype.float16, mstype.float32], self.name) return mstype.float32 @@ -2932,6 +2937,7 @@ class NMSWithMask(PrimitiveWithInfer): `N` is the number of input bounding boxes. Every bounding box contains 5 values, the first 4 values are the coordinates of bounding box, and the last value is the score of this bounding box. + The data type must be float16 or float32. Outputs: tuple[Tensor], tuple of three tensors, they are selected_boxes, selected_idx and selected_mask. @@ -3186,12 +3192,13 @@ class Atan2(_MathBinaryOp): [[0. 0.7853982]] """ + class SquareSumAll(PrimitiveWithInfer): """ Returns square sum all of a tensor element-wise Inputs: - - **input_x1** (Tensor) - The input tensor. + - **input_x1** (Tensor) - The input tensor. The data type must be float16 or float32. - **input_x2** (Tensor) - The input tensor same type and shape as the `input_x1`. Note: @@ -3227,7 +3234,7 @@ class BitwiseAnd(_BitwiseBinaryOp): Returns bitwise `and` of two tensors element-wise. Inputs: - - **input_x1** (Tensor) - The input tensor with int or uint type. + - **input_x1** (Tensor) - The input tensor with int16 or uint16 data type. - **input_x2** (Tensor) - The input tensor with same type as the `input_x1`. Outputs: @@ -3247,7 +3254,7 @@ class BitwiseOr(_BitwiseBinaryOp): Returns bitwise `or` of two tensors element-wise. Inputs: - - **input_x1** (Tensor) - The input tensor with int or uint type. + - **input_x1** (Tensor) - The input tensor with int16 or uint16 data type. - **input_x2** (Tensor) - The input tensor with same type as the `input_x1`. Outputs: @@ -3267,7 +3274,7 @@ class BitwiseXor(_BitwiseBinaryOp): Returns bitwise `xor` of two tensors element-wise. Inputs: - - **input_x1** (Tensor) - The input tensor with int or uint type. + - **input_x1** (Tensor) - The input tensor with int16 or uint16 data type. - **input_x2** (Tensor) - The input tensor with same type as the `input_x1`. Outputs: @@ -3405,7 +3412,7 @@ class Eps(PrimitiveWithInfer): Creates a tensor filled with `input_x` dtype minimum val. Inputs: - - **input_x** (Tensor) - Input tensor. + - **input_x** (Tensor) - Input tensor. The data type must be float16 or float32. Outputs: Tensor, has the same type and shape as `input_x`, but filled with `input_x` dtype minimum val. diff --git a/mindspore/ops/operations/nn_ops.py b/mindspore/ops/operations/nn_ops.py index 1ebba14064..9818792513 100644 --- a/mindspore/ops/operations/nn_ops.py +++ b/mindspore/ops/operations/nn_ops.py @@ -112,7 +112,7 @@ class Softmax(PrimitiveWithInfer): axis (Union[int, tuple]): The axis to do the Softmax operation. Default: -1. Inputs: - - **logits** (Tensor) - The input of Softmax. + - **logits** (Tensor) - The input of Softmax, with float16 or float32 data type. Outputs: Tensor, with the same type and shape as the logits. @@ -142,6 +142,7 @@ class Softmax(PrimitiveWithInfer): def infer_dtype(self, logits): validator.check_subclass("logits", logits, mstype.tensor, self.name) + validator.check_tensor_type_same({"logits": logits}, mstype.float_type, self.name) return logits @@ -162,7 +163,7 @@ class LogSoftmax(PrimitiveWithInfer): axis (int): The axis to do the Log softmax operation. Default: -1. Inputs: - - **logits** (Tensor) - The input of Log Softmax. + - **logits** (Tensor) - The input of Log Softmax, with float16 or float32 data type. Outputs: Tensor, with the same type and shape as the logits. @@ -185,6 +186,7 @@ class LogSoftmax(PrimitiveWithInfer): def infer_dtype(self, logits): validator.check_subclass("logits", logits, mstype.tensor, self.name) + validator.check_tensor_type_same({"logits": logits}, mstype.float_type, self.name) return logits @@ -298,7 +300,7 @@ class ReLU6(PrimitiveWithInfer): It returns :math:`\min(\max(0,x), 6)` element-wise. Inputs: - - **input_x** (Tensor) - The input tensor. + - **input_x** (Tensor) - The input tensor. With float16 or float32 data type. Outputs: Tensor, with the same type and shape as the `input_x`. @@ -430,7 +432,7 @@ class HSwish(PrimitiveWithInfer): where :math:`x_{i}` is the :math:`i`-th slice along the given dim of the input Tensor. Inputs: - - **input_data** (Tensor) - The input of HSwish. + - **input_data** (Tensor) - The input of HSwish, data type should be float16 or float32. Outputs: Tensor, with the same type and shape as the `input_data`. @@ -465,7 +467,7 @@ class Sigmoid(PrimitiveWithInfer): where :math:`x_i` is the element of the input. Inputs: - - **input_x** (Tensor) - The input of Sigmoid. + - **input_x** (Tensor) - The input of Sigmoid, data type should be float16 or float32. Outputs: Tensor, with the same type and shape as the input_x. @@ -503,7 +505,7 @@ class HSigmoid(PrimitiveWithInfer): where :math:`x_{i}` is the :math:`i`-th slice along the given dim of the input Tensor. Inputs: - - **input_data** (Tensor) - The input of HSigmoid. + - **input_data** (Tensor) - The input of HSigmoid, data type should be float16 or float32. Outputs: Tensor, with the same type and shape as the `input_data`. @@ -687,11 +689,11 @@ class BatchNorm(PrimitiveWithInfer): epsilon (float): A small value added for numerical stability. Default: 1e-5. Inputs: - - **input_x** (Tensor) - Tensor of shape :math:`(N, C)`. - - **scale** (Tensor) - Tensor of shape :math:`(C,)`. - - **bias** (Tensor) - Tensor of shape :math:`(C,)`. - - **mean** (Tensor) - Tensor of shape :math:`(C,)`. - - **variance** (Tensor) - Tensor of shape :math:`(C,)`. + - **input_x** (Tensor) - Tensor of shape :math:`(N, C)`, with float16 or float32 data type. + - **scale** (Tensor) - Tensor of shape :math:`(C,)`, with float16 or float32 data type. + - **bias** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `scale`. + - **mean** (Tensor) - Tensor of shape :math:`(C,)`, with float16 or float32 data type. + - **variance** (Tensor) - Tensor of shape :math:`(C,)`, has the same data type with `mean`. Outputs: Tuple of 5 Tensor, the normalized inputs and the updated parameters. @@ -756,11 +758,11 @@ class Conv2D(PrimitiveWithInfer): out_j = \sum_{i=0}^{C_{in} - 1} ccor(W_{ij}, X_i) + b_j, - where :math:`ccor` is cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges - from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to :math:`i`-th channel of the :math:`j`-th + where :math:`ccor` is the cross correlation operator, :math:`C_{in}` is the input channel number, :math:`j` ranges + from :math:`0` to :math:`C_{out} - 1`, :math:`W_{ij}` corresponds to the :math:`i`-th channel of the :math:`j`-th filter and :math:`out_{j}` corresponds to the :math:`j`-th channel of the output. :math:`W_{ij}` is a slice of kernel and it has shape :math:`(\text{ks_h}, \text{ks_w})`, where :math:`\text{ks_h}` and - :math:`\text{ks_w}` are height and width of the convolution kernel. The full kernel has shape + :math:`\text{ks_w}` are the height and width of the convolution kernel. The full kernel has shape :math:`(C_{out}, C_{in} // \text{group}, \text{ks_h}, \text{ks_w})`, where group is the group number to split the input in the channel dimension. @@ -1029,7 +1031,7 @@ class _Pool(PrimitiveWithInfer): of two `int` for height and width. Default: 1. strides (Union[int, tuple[int]]): The stride of the window, that should be a tuple of two `int` for height and width. Default: 1. - padding (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + padding (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". """ @@ -1104,16 +1106,16 @@ class MaxPool(_Pool): strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1. - padding (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + padding (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: - **input** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. @@ -1151,20 +1153,21 @@ class MaxPoolWithArgmax(_Pool): strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1. - padding (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + padding (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: - **input** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. + Data type should be float16 or float32. Outputs: Tuple of 2 Tensor, the maxpool result and where max values from. @@ -1233,16 +1236,16 @@ class AvgPool(_Pool): strides (Union[int, tuple[int]]): The distance of kernel moving, an int number that represents the height and width of movement are both strides, or a tuple of two int numbers that represent height and width of movement respectively. Default: 1. - padding (str): The optional values for pad mode, is "same" or "valid", not case sensitive. + padding (str): The optional value for pad mode, is "same" or "valid", not case sensitive. Default: "valid". - - same: Adopts the way of completion. Output height and width will be the same as - the input. Total number of padding will be calculated for horizontal and vertical - direction and evenly distributed to top and bottom, left and right if possible. + - same: Adopts the way of completion. The height and width of the output will be the same as + the input. The total number of padding will be calculated in horizontal and vertical + directions and evenly distributed to top and bottom, left and right if possible. Otherwise, the last extra padding will be done from the bottom and the right side. - - valid: Adopts the way of discarding. The possibly largest height and width of output - will be return without padding. Extra pixels will be discarded. + - valid: Adopts the way of discarding. The possible largest height and width of output + will be returned without padding. Extra pixels will be discarded. Inputs: - **input** (Tensor) - Tensor of shape :math:`(N, C_{in}, H_{in}, W_{in})`. @@ -1407,7 +1410,7 @@ class BiasAdd(PrimitiveWithInfer): except for the channel axis. Inputs: - - **input_x** (Tensor) - Input value, with shape :math:`(N, C)` or :math:`(N, C, H, W)`. + - **input_x** (Tensor) - Input value. The input shape can be 2-4 dimensions. - **bias** (Tensor) - Bias value, with shape :math:`(C)`. Outputs: @@ -1433,8 +1436,7 @@ class BiasAdd(PrimitiveWithInfer): def infer_dtype(self, x_type, b_type): args = {"input_x": x_type, "bias": b_type} - valid_types = (mstype.int8, mstype.int32, mstype.float16, mstype.float32) - validator.check_tensor_type_same(args, valid_types, self.name) + validator.check_tensor_type_same(args, mstype.number_type, self.name) return x_type @@ -1447,7 +1449,7 @@ class TopK(PrimitiveWithInfer): be sorted by the values in descending order. Default: False. Inputs: - - **input_x** (Tensor) - Input to be computed. + - **input_x** (Tensor) - Input to be computed, data type should be float16, float32 or int32. - **k** (int) - Number of top elements to be computed along the last dimension, constant input is needed. Outputs: @@ -1499,8 +1501,8 @@ class SoftmaxCrossEntropyWithLogits(PrimitiveWithInfer): loss_{ij} = -\sum_j{Y_{ij} * ln(p_{ij})} Inputs: - - **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. - - **labels** (Tensor) - Ground truth labels, with shape :math:`(N, C)`. + - **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. Data type should be float16 or float32. + - **labels** (Tensor) - Ground truth labels, with shape :math:`(N, C)`. Has the same data type with `logits`. Outputs: Tuple of 2 Tensor, the loss shape is `(N,)`, and the dlogits with the same shape as `logits`. @@ -1550,8 +1552,9 @@ class SparseSoftmaxCrossEntropyWithLogits(PrimitiveWithInfer): is_grad (bool): If it's true, this operation returns the computed gradient. Default: False. Inputs: - - **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. + - **logits** (Tensor) - Input logits, with shape :math:`(N, C)`. Data type should be float16 or float32. - **labels** (Tensor) - Ground truth labels, with shape :math:`(N)`. + Data type should be int32 or int64. Outputs: Tensor, if `is_grad` is False, the output tensor is the value of loss which is a scalar tensor; @@ -1593,11 +1596,14 @@ class ApplyMomentum(PrimitiveWithInfer): gradient_scale (float): The scale of the gradient. Default: 1.0. Inputs: - - **variable** (Tensor) - Weights to be updated. - - **accumulation** (Tensor) - Accumulated gradient value by moment weight. - - **learning_rate** (float) - Learning rate. - - **gradient** (Tensor) - Gradients. - - **momentum** (float) - Momentum. + - **variable** (Parameter) - Weights to be updated. data type should be float. + - **accumulation** (Parameter) - Accumulated gradient value by moment weight. + Has the same data type with `variable`. + - **learning_rate** (Union[Number, Tensor]) - The learning rate value, should be a float number or + a scalar tensor with float data type. + - **gradient** (Tensor) - Gradients, has the same data type as `variable`. + - **momentum** (Union[Number, Tensor]) - Momentum, should be a float number or + a scalar tensor with float data type. Outputs: Tensor, parameters to be updated. @@ -1659,7 +1665,7 @@ class SmoothL1Loss(PrimitiveWithInfer): quadratic to linear. Default: 1.0. Inputs: - - **prediction** (Tensor) - Predict data. + - **prediction** (Tensor) - Predict data. Data type should be float16 or float32. - **target** (Tensor) - Ground truth data, with the same type and shape as `prediction`. Outputs: @@ -1701,7 +1707,7 @@ class L2Loss(PrimitiveWithInfer): :math:`nelement(x)` represents the number of `input_x`. Inputs: - - **input_x** (Tensor) - A input Tensor. + - **input_x** (Tensor) - A input Tensor. Data type should be float16 or float32. Outputs: Tensor. Has the same dtype as `input_x`. The output tensor is the value of loss which is a scalar tensor. @@ -1766,6 +1772,7 @@ class DataFormatDimMap(PrimitiveWithInfer): validator.check_tensor_type_same({"x": x_type}, valid_types, self.name) return x_type + class RNNTLoss(PrimitiveWithInfer): """ Computes the RNNTLoss and its gradient with respect to the softmax outputs. @@ -1774,7 +1781,7 @@ class RNNTLoss(PrimitiveWithInfer): blank_label (int): blank label. Default: 0. Inputs: - - **acts** (Tensor[float32]) - Tensor of shape :math:`(B, T, U, V)`. + - **acts** (Tensor) - Tensor of shape :math:`(B, T, U, V)`. Data type should be float16 or float32. - **labels** (Tensor[int32]) - Tensor of shape :math:`(B, U-1)`. - **input_lengths** (Tensor[int32]) - Tensor of shape :math:`(B,)`. - **label_lebgths** (Tensor[int32]) - Tensor of shape :math:`(B,)`. @@ -1792,6 +1799,7 @@ class RNNTLoss(PrimitiveWithInfer): >>> rnnt_loss = P.RNNTLoss(blank_label=blank) >>> costs, grads = rnnt_loss(Tensor(acts), Tensor(labels), Tensor(input_length), Tensor(label_length)) """ + @prim_attr_register def __init__(self, blank_label=0): validator.check_value_type('blank_label', blank_label, [int], self.name) @@ -1815,7 +1823,7 @@ class RNNTLoss(PrimitiveWithInfer): validator.check_subclass("labels_type", labels_type, mstype.tensor, self.name) validator.check_subclass("input_length_type", input_length_type, mstype.tensor, self.name) validator.check_subclass("label_length_type", label_length_type, mstype.tensor, self.name) - validator.check_tensor_type_same({"acts_type": acts_type}, [mstype.float32], self.name) + validator.check_tensor_type_same({"acts_type": acts_type}, [mstype.float32, mstype.float16], self.name) validator.check_tensor_type_same({"labels_type": labels_type}, [mstype.int32], self.name) validator.check_tensor_type_same({"input_length_type": input_length_type}, [mstype.int32], self.name) validator.check_tensor_type_same({"label_length_type": label_length_type}, [mstype.int32], self.name) @@ -1838,12 +1846,14 @@ class SGD(PrimitiveWithInfer): nesterov (bool): Enable Nesterov momentum. Default: False. Inputs: - - **parameters** (Tensor) - Parameters to be updated. Their data type can be list or tuple. - - **gradient** (Tensor) - Gradients. - - **learning_rate** (Tensor) - Learning rate. Must be float value. e.g. Tensor(0.1, mindspore.float32). - - **accum** (Tensor) - Accum(velocity) to be updated. - - **momentum** (Tensor) - Momentum. e.g. Tensor(0.1, mindspore.float32). - - **stat** (Tensor) - States to be updated with the same shape as gradient. + - **parameters** (Tensor) - Parameters to be updated. With float16 or float32 data type. + - **gradient** (Tensor) - Gradients. With float16 or float32 data type. + - **learning_rate** (Tensor) - Learning rate, a scalar tensor with float16 or float32 data type. + e.g. Tensor(0.1, mindspore.float32) + - **accum** (Tensor) - Accum(velocity) to be updated. With float16 or float32 data type. + - **momentum** (Tensor) - Momentum, a scalar tensor with float16 or float32 data type. + e.g. Tensor(0.1, mindspore.float32). + - **stat** (Tensor) - States to be updated with the same shape as gradient. With float16 or float32 data type. Outputs: Tensor, parameters to be updated. @@ -1921,7 +1931,8 @@ class ApplyRMSProp(PrimitiveWithInfer): - **var** (Tensor) - Weights to be update. - **mean_square** (Tensor) - Mean square gradients, must have the same type as `var`. - **moment** (Tensor) - Delta of `var`, must have the same type as `var`. - - **learning_rate** (Union[Number, Tensor]) - Learning rate. + - **learning_rate** (Union[Number, Tensor]) - Learning rate. Should be a float number or + a scalar tensor with float16 or float32 data type. - **grad** (Tensor) - Gradients, must have the same type as `var`. - **decay** (float) - Decay rate. Only constant value is allowed. - **momentum** (float) - Momentum. Only constant value is allowed. @@ -2017,7 +2028,8 @@ class ApplyCenteredRMSProp(PrimitiveWithInfer): - **mean_square** (Tensor) - Mean square gradients, must have the same type as `var`. - **moment** (Tensor) - Delta of `var`, must have the same type as `var`. - **grad** (Tensor) - Gradients, must have the same type as `var`. - - **learning_rate** (Union[Number, Tensor]) - Learning rate. + - **learning_rate** (Union[Number, Tensor]) - Learning rate. Should be a float number or + a scalar tensor with float16 or float32 data type. - **decay** (float) - Decay rate. - **momentum** (float) - Momentum. - **epsilon** (float) - Ridge term. @@ -2145,7 +2157,7 @@ class L2Normalize(PrimitiveWithInfer): epsilon (float): A small value added for numerical stability. Default: 1e-4. Inputs: - - **input_x** (Tensor) - Input to compute the normalization. + - **input_x** (Tensor) - Input to compute the normalization. Data type should be float16 or float32. Outputs: Tensor, with the same type and shape as the input. @@ -2174,6 +2186,7 @@ class L2Normalize(PrimitiveWithInfer): def infer_dtype(self, input_x): validator.check_subclass("x", input_x, mstype.tensor, self.name) + validator.check_tensor_type_same({"input_x": input_x}, [mstype.float16, mstype.float32], self.name) return input_x @@ -2328,9 +2341,11 @@ class OneHot(PrimitiveWithInfer): Inputs: - **indices** (Tensor) - A tensor of indices. Tensor of shape :math:`(X_0, \ldots, X_n)`. + Data type must be int32. - **depth** (int) - A scalar defining the depth of the one hot dimension. - - **on_value** (Tensor) - A value to fill in output when `indices[j] = i`. + - **on_value** (Tensor) - A value to fill in output when `indices[j] = i`. With data type of float16 or float32. - **off_value** (Tensor) - A value to fill in output when `indices[j] != i`. + Has the same data type with as `on_value`. Outputs: Tensor, one_hot tensor. Tensor of shape :math:`(X_0, \ldots, X_{axis}, \text{depth} ,X_{axis+1}, \ldots, X_n)`. @@ -2384,7 +2399,7 @@ class Gelu(PrimitiveWithInfer): where :math:`erf` is the "Gauss error function" . Inputs: - - **input_x** (Tensor) - Input to compute the Gelu. + - **input_x** (Tensor) - Input to compute the Gelu. With data type of float16 or float32. Outputs: Tensor, with the same type and shape as input. @@ -2466,8 +2481,9 @@ class PReLU(PrimitiveWithInfer): Inputs: - **input_x** (Tensor) - Float tensor, representing the output of the preview layer. + With data type of float16 or float32. - **weight** (Tensor) - Float Tensor, w > 0, there is only two shapes are legitimate, - 1 or the number of channels at input. + 1 or the number of channels at input. With data type of float16 or float32. Outputs: Tensor, with the same type as `input_x`. @@ -2796,9 +2812,9 @@ class ROIAlign(PrimitiveWithInfer): Inputs: - **features** (Tensor) - The input features, whose shape should be `(N, C, H, W)`. - - **rois** (Tensor) - The shape is `(rois_n, 5)`. `rois_n` represents the number of RoI. The size of - the second dimension should be `5` and the `5` colunms are - `(image_index, top_left_x, top_left_y, bottom_right_x, bottom_right_y)`. `image_index` represents the + - **rois** (Tensor) - The shape is `(rois_n, 5)`. With data type of float16 or float32. + `rois_n` represents the number of RoI. The size of the second dimension should be `5` and the `5` colunms + are `(image_index, top_left_x, top_left_y, bottom_right_x, bottom_right_y)`. `image_index` represents the index of image. `top_left_x` and `top_left_y` represent the `x, y` coordinates of the top left corner of corresponding RoI, respectively. `bottom_right_x` and `bottom_right_y` represent the `x, y` coordinates of the bottom right corner of corresponding RoI, respectively. @@ -2833,6 +2849,9 @@ class ROIAlign(PrimitiveWithInfer): return [rois_shape[0], inputs_shape[1], self.pooled_height, self.pooled_width] def infer_dtype(self, inputs_type, rois_type): + valid_types = (mstype.float16, mstype.float32) + validator.check_tensor_type_same({"inputs_type": inputs_type}, valid_types, self.name) + validator.check_tensor_type_same({"rois_type": rois_type}, valid_types, self.name) return inputs_type @@ -2877,7 +2896,7 @@ class Adam(PrimitiveWithInfer): - **beta1** (float) - The exponential decay rate for the 1st moment estimates. - **beta2** (float) - The exponential decay rate for the 2nd moment estimates. - **epsilon** (float) - Term added to the denominator to improve numerical stability. - - **gradient** (Tensor) - Gradients. + - **gradient** (Tensor) - Gradients. Has the same type as `var`. Outputs: Tuple of 3 Tensor, the updated parameters. @@ -3471,10 +3490,10 @@ class BinaryCrossEntropy(PrimitiveWithInfer): Its value should be one of 'none', 'mean', 'sum'. Default: 'mean'. Inputs: - - **input_x** (Tensor) - The input Tensor. - - **input_y** (Tensor) - The label Tensor which has same shape as `input_x`. + - **input_x** (Tensor) - The input Tensor. The data type should be float16 or float32. + - **input_y** (Tensor) - The label Tensor which has same shape and data type as `input_x`. - **weight** (Tensor, optional) - A rescaling weight applied to the loss of each batch element. - And it should have same shape as `input_x`. Default: None. + And it should have same shape and data type as `input_x`. Default: None. Outputs: Tensor or Scalar, if `reduction` is 'none', then output is a tensor and same shape as `input_x`. @@ -3844,12 +3863,13 @@ class ApplyAdagradV2(PrimitiveWithInfer): update_slots (bool): If `True`, `accum` will be updated. Default: True. Inputs: - - **var** (Parameter) - Variable to be updated. With float32 data type. + - **var** (Parameter) - Variable to be updated. With float16 or float32 data type. - **accum** (Parameter) - Accum to be updated. The shape and dtype should be the same as `var`. - With float32 data type. - - **lr** (Union[Number, Tensor]) - The learning rate value, should be scalar. With float32 data type. + With float16 or float32 data type. + - **lr** (Union[Number, Tensor]) - The learning rate value, should be a float number or + a scalar tensor with float16 or float32 data type. - **grad** (Tensor) - A tensor for gradient. The shape and dtype should be the same as `var`. - With float32 data type. + With float16 or float32 data type. Outputs: Tuple of 2 Tensor, the updated parameters. @@ -3901,8 +3921,8 @@ class ApplyAdagradV2(PrimitiveWithInfer): def infer_dtype(self, var_dtype, accum_dtype, lr_dtype, grad_dtype): args = {'var': var_dtype, 'accum': accum_dtype, 'grad': grad_dtype} - validator.check_tensor_type_same(args, [mstype.float32], self.name) - validator.check_scalar_or_tensor_type_same({'lr': lr_dtype}, [mstype.float32], self.name) + validator.check_tensor_type_same(args, [mstype.float16, mstype.float32], self.name) + validator.check_scalar_or_tensor_type_same({'lr': lr_dtype}, [mstype.float16, mstype.float32], self.name) return var_dtype, accum_dtype @@ -3921,11 +3941,10 @@ class SparseApplyAdagrad(PrimitiveWithInfer): use_locking (bool): If True, updating of the var and accum tensors will be protected. Default: False. Inputs: - - **var** (Parameter) - Variable to be updated. The type must be float32. - - **accum** (Parameter) - Accum to be updated. The shape must be the same as `var`'s shape, - the type must be float32. - - **grad** (Tensor) - Gradient. The shape must be the same as `var`'s shape - except first dimension, the type must be float32. + - **var** (Parameter) - Variable to be updated. The data type must be float16 or float32. + - **accum** (Parameter) - Accum to be updated. The shape and dtype should be the same as `var`. + - **grad** (Tensor) - Gradient. The shape must be the same as `var`'s shape except first dimension. + Has the same data type as `var`. - **indices** (Tensor) - A vector of indices into the first dimension of `var` and `accum`. The shape of `indices` must be the same as `grad` in first dimension, the type must be int32. @@ -3981,7 +4000,7 @@ class SparseApplyAdagrad(PrimitiveWithInfer): def infer_dtype(self, var_type, accum_type, grad_type, indices_type): args = {'var': var_type, 'accum': accum_type, 'grad': grad_type} - validator.check_tensor_type_same(args, (mstype.float32,), self.name) + validator.check_tensor_type_same(args, [mstype.float16, mstype.float32], self.name) validator.check_tensor_type_same({'indices': indices_type}, [mstype.int32], self.name) return var_type, accum_type @@ -4002,11 +4021,10 @@ class SparseApplyAdagradV2(PrimitiveWithInfer): update_slots (bool): If `True`, the computation logic will be different to `False`. Default: True. Inputs: - - **var** (Parameter) - Variable to be updated. The type must be float32. - - **accum** (Parameter) - Accum to be updated. The shape must be the same as `var`'s shape, - the type must be float32. - - **grad** (Tensor) - Gradient. The shape must be the same as `var`'s shape except first dimension, - the type must be float32. + - **var** (Parameter) - Variable to be updated. The data type must be float16 or float32. + - **accum** (Parameter) - Accum to be updated. The shape and dtype should be the same as `var`. + - **grad** (Tensor) - Gradient. The shape must be the same as `var`'s shape except first dimension. + Has the same data type as `var`. - **indices** (Tensor) - A vector of indices into the first dimension of `var` and `accum`. The shape of `indices` must be the same as `grad` in first dimension, the type must be int32. @@ -4063,7 +4081,7 @@ class SparseApplyAdagradV2(PrimitiveWithInfer): def infer_dtype(self, var_type, accum_type, grad_type, indices_type): args = {'var': var_type, 'accum': accum_type, 'grad': grad_type} - validator.check_tensor_type_same(args, [mstype.float32], self.name) + validator.check_tensor_type_same(args, [mstype.float16, mstype.float32], self.name) validator.check_tensor_type_same({'indices': indices_type}, [mstype.int32], self.name) return var_type, accum_type @@ -4179,12 +4197,16 @@ class SparseApplyProximalAdagrad(PrimitiveWithInfer): use_locking (bool): If True, updating of the var and accum tensors will be protected. Default: False. Inputs: - - **var** (Parameter) - Variable tensor to be updated. The data type must be float32. + - **var** (Parameter) - Variable tensor to be updated. The data type must be float16 or float32. - **accum** (Parameter) - Variable tensor to be updated. Has the same dtype as `var`. - - **lr** (Union[Number, Tensor]) - The learning rate value. The data type must be float32. - - **l1** (Union[Number, Tensor]) - l1 regularization strength. The data type must be float32. - - **l2** (Union[Number, Tensor]) - l2 regularization strength. The data type must be float32. - - **grad** (Tensor) - A tensor of the same type as `var`, for the gradient. The data type must be float32. + - **lr** (Union[Number, Tensor]) - The learning rate value. Tshould be a float number or + a scalar tensor with float16 or float32 data type. + - **l1** (Union[Number, Tensor]) - l1 regularization strength. should be a float number or + a scalar tensor with float16 or float32 data type. + - **l2** (Union[Number, Tensor]) - l2 regularization strength. should be a float number or + a scalar tensor with float16 or float32 data type.. + - **grad** (Tensor) - A tensor of the same type as `var`, for the gradient. + The data type must be float16 or float32. - **indices** (Tensor) - A vector of indices into the first dimension of `var` and `accum`. Outputs: @@ -4239,10 +4261,10 @@ class SparseApplyProximalAdagrad(PrimitiveWithInfer): def infer_dtype(self, var_dtype, accum_dtype, lr_dtype, l1_dtype, l2_dtype, grad_dtype, indices_dtype): args = {'var': var_dtype, 'accum': accum_dtype, 'grad': grad_dtype} - validator.check_tensor_type_same(args, [mstype.float32], self.name) - validator.check_scalar_or_tensor_type_same({"lr": lr_dtype}, [mstype.float32], self.name) - validator.check_scalar_or_tensor_type_same({"l1": l1_dtype}, [mstype.float32], self.name) - validator.check_scalar_or_tensor_type_same({"l2": l2_dtype}, [mstype.float32], self.name) + validator.check_tensor_type_same(args, [mstype.float16, mstype.float32], self.name) + validator.check_scalar_or_tensor_type_same({"lr": lr_dtype}, [mstype.float16, mstype.float32], self.name) + validator.check_scalar_or_tensor_type_same({"l1": l1_dtype}, [mstype.float16, mstype.float32], self.name) + validator.check_scalar_or_tensor_type_same({"l2": l2_dtype}, [mstype.float16, mstype.float32], self.name) valid_types = [mstype.int16, mstype.int32, mstype.int64, mstype.uint16, mstype.uint32, mstype.uint64] validator.check_tensor_type_same({'indices': indices_dtype}, valid_types, self.name) @@ -4677,18 +4699,19 @@ class ApplyFtrl(PrimitiveWithInfer): use_locking (bool): Use locks for update operation if True . Default: False. Inputs: - - **var** (Tensor) - The variable to be updated. - - **accum** (Tensor) - The accum to be updated, must be same type and shape as `var`. - - **linear** (Tensor) - The linear to be updated, must be same type and shape as `var`. - - **grad** (Tensor) - Gradient. + - **var** (Parameter) - The variable to be updated. The data type should be float16 or float32. + - **accum** (Parameter) - The accum to be updated, must be same type and shape as `var`. + - **linear** (Parameter) - The linear to be updated, must be same type and shape as `var`. + - **grad** (Tensor) - Gradient. The data type should be float16 or float32. - **lr** (Union[Number, Tensor]) - The learning rate value, must be positive. Default: 0.001. + It should be a float number or a scalar tensor with float16 or float32 data type. - **l1** (Union[Number, Tensor]) - l1 regularization strength, must be greater than or equal to zero. - Default: 0.0. + Default: 0.0. It should be a float number or a scalar tensor with float16 or float32 data type. - **l2** (Union[Number, Tensor]) - l2 regularization strength, must be greater than or equal to zero. - Default: 0.0. + Default: 0.0. It should be a float number or a scalar tensor with float16 or float32 data type. - **lr_power** (Union[Number, Tensor]) - Learning rate power controls how the learning rate decreases during training, must be less than or equal to zero. Use fixed learning rate if lr_power is zero. - Default: -0.5. + Default: -0.5. It should be a float number or a scalar tensor with float16 or float32 data type. Outputs: Tensor, representing the updated var. @@ -4767,7 +4790,7 @@ class SparseApplyFtrl(PrimitiveWithInfer): use_locking (bool): Use locks for update operation if True . Default: False. Inputs: - - **var** (Parameter) - The variable to be updated. The data type must be float32. + - **var** (Parameter) - The variable to be updated. The data type must be float16 or float32. - **accum** (Parameter) - The accum to be updated, must be same type and shape as `var`. - **linear** (Parameter) - The linear to be updated, must be same type and shape as `var`. - **grad** (Tensor) - A tensor of the same type as `var`, for the gradient. @@ -4836,7 +4859,7 @@ class SparseApplyFtrl(PrimitiveWithInfer): def infer_dtype(self, var_dtype, accum_dtype, linear_dtype, grad_dtype, indices_dtype): args = {"var_dtype": var_dtype, "accum_dtype": accum_dtype, "linear_dtype": linear_dtype, "grad_dtype": grad_dtype} - validator.check_tensor_type_same(args, [mstype.float32], self.name) + validator.check_tensor_type_same(args, [mstype.float16, mstype.float32], self.name) validator.check_tensor_type_same({"indices_dtype": indices_dtype}, [mstype.int32], self.name) return var_dtype, accum_dtype, linear_dtype @@ -4855,7 +4878,7 @@ class SparseApplyFtrlV2(PrimitiveWithInfer): use_locking (bool): If `True`, updating of the var and accum tensors will be protected. Default: False. Inputs: - - **var** (Parameter) - The variable to be updated. The data type must be float32. + - **var** (Parameter) - The variable to be updated. The data type must be float16 or float32. - **accum** (Parameter) - The accum to be updated, must be same type and shape as `var`. - **linear** (Parameter) - The linear to be updated, must be same type and shape as `var`. - **grad** (Tensor) - A tensor of the same type as `var`, for the gradient. @@ -4928,7 +4951,7 @@ class SparseApplyFtrlV2(PrimitiveWithInfer): def infer_dtype(self, var_dtype, accum_dtype, linear_dtype, grad_dtype, indices_dtype): args = {"var_dtype": var_dtype, "accum_dtype": accum_dtype, "linear_dtype": linear_dtype, "grad_dtype": grad_dtype} - validator.check_tensor_type_same(args, [mstype.float32], self.name) + validator.check_tensor_type_same(args, [mstype.float16, mstype.float32], self.name) validator.check_tensor_type_same({"indices_dtype": indices_dtype}, [mstype.int32], self.name) return var_dtype, accum_dtype, linear_dtype @@ -5256,7 +5279,7 @@ class InTopK(PrimitiveWithInfer): k (int): Special the number of top elements to look at for computing precision. Inputs: - - **x1** (Tensor) - A 2D Tensor define the predictions of a batch of samples with float32 data type. + - **x1** (Tensor) - A 2D Tensor define the predictions of a batch of samples with float16 or float32 data type. - **x2** (Tensor) - A 1D Tensor define the labels of a batch of samples with int32 data type. Outputs: @@ -5277,7 +5300,7 @@ class InTopK(PrimitiveWithInfer): validator.check_value_type("k", k, [int], self.name) def infer_dtype(self, x1_dtype, x2_dtype): - validator.check_tensor_type_same({"x1": x1_dtype}, (mstype.float32,), self.name) + validator.check_tensor_type_same({"x1": x1_dtype}, (mstype.float16, mstype.float32,), self.name) validator.check_tensor_type_same({"x2": x2_dtype}, (mstype.int32,), self.name) return mstype.tensor_type(mstype.bool_) @@ -5331,6 +5354,7 @@ class LRN(PrimitiveWithInfer): validator.check_integer("x_shape", len(x_shape), 4, Rel.EQ, self.name) return x_shape + class CTCLossV2(PrimitiveWithInfer): r""" Calculates the CTC(Connectionist Temporal Classification) loss. Also calculates the gradient. diff --git a/mindspore/ops/operations/other_ops.py b/mindspore/ops/operations/other_ops.py index ef3751f3e2..b7e7991caa 100644 --- a/mindspore/ops/operations/other_ops.py +++ b/mindspore/ops/operations/other_ops.py @@ -75,8 +75,8 @@ class BoundingBoxEncode(PrimitiveWithInfer): stds (tuple): Stds for encoding bounding boxes calculation. Default: (1.0, 1.0, 1.0, 1.0). Inputs: - - **anchor_box** (Tensor) - Anchor boxes. - - **groundtruth_box** (Tensor) - Ground truth boxes. + - **anchor_box** (Tensor) - Anchor boxes. The shape of anchor_box must be (n, 4). + - **groundtruth_box** (Tensor) - Ground truth boxes. Which has the same shape with anchor_box. Outputs: Tensor, encoded bounding boxes. @@ -93,8 +93,8 @@ class BoundingBoxEncode(PrimitiveWithInfer): @prim_attr_register def __init__(self, means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0)): - validator.check_value_type('means', means, [tuple, list], self.name) - validator.check_value_type('stds', stds, [tuple, list], self.name) + validator.check_value_type('means', means, (tuple), self.name) + validator.check_value_type('stds', stds, (tuple), self.name) for i, value in enumerate(means): validator.check_value_type("means[%d]" % i, value, [float], self.name) for i, value in enumerate(stds): @@ -128,8 +128,8 @@ class BoundingBoxDecode(PrimitiveWithInfer): wh_ratio_clip (float): The limit of width and height ratio for decoding box calculation. Default: 0.016. Inputs: - - **anchor_box** (Tensor) - Anchor boxes. - - **deltas** (Tensor) - Delta of boxes. + - **anchor_box** (Tensor) - Anchor boxes. The shape of anchor_box must be (n, 4). + - **deltas** (Tensor) - Delta of boxes. Which has the same shape with anchor_box. Outputs: Tensor, decoded boxes. @@ -147,8 +147,8 @@ class BoundingBoxDecode(PrimitiveWithInfer): @prim_attr_register def __init__(self, max_shape, means=(0.0, 0.0, 0.0, 0.0), stds=(1.0, 1.0, 1.0, 1.0), wh_ratio_clip=0.016): - validator.check_value_type('means', means, [tuple, list], self.name) - validator.check_value_type('stds', stds, [tuple, list], self.name) + validator.check_value_type('means', means, (tuple), self.name) + validator.check_value_type('stds', stds, (tuple), self.name) for i, value in enumerate(means): validator.check_value_type("means[%d]" % i, value, [float], self.name) for i, value in enumerate(stds): @@ -181,8 +181,9 @@ class CheckValid(PrimitiveWithInfer): Check whether the bounding box cross data and data border. Inputs: - - **bboxes** (Tensor) - Bounding boxes tensor with shape (N, 4). + - **bboxes** (Tensor) - Bounding boxes tensor with shape (N, 4). Data type should be float16 or float32. - **img_metas** (Tensor) - Raw image size information, format (height, width, ratio). + Data type should be float16 or float32. Outputs: Tensor, the valided tensor. @@ -220,6 +221,9 @@ class CheckValid(PrimitiveWithInfer): return bboxes_shape[:-1] def infer_dtype(self, bboxes_type, metas_type): + valid_type = [mstype.float32, mstype.float16] + validator.check_tensor_type_same({"bboxes_type": bboxes_type}, valid_type, self.name) + validator.check_tensor_type_same({"metas_type": metas_type}, valid_type, self.name) return mstype.bool_ @@ -242,12 +246,12 @@ class IOU(PrimitiveWithInfer): Inputs: - **anchor_boxes** (Tensor) - Anchor boxes, tensor of shape (N, 4). "N" indicates the number of anchor boxes, - and the value "4" refers to "x0", "x1", "y0", and "y1". Data type must be float16. + and the value "4" refers to "x0", "x1", "y0", and "y1". Data type must be float16 or float32. - **gt_boxes** (Tensor) - Ground truth boxes, tensor of shape (M, 4). "M" indicates the number of ground - truth boxes, and the value "4" refers to "x0", "x1", "y0", and "y1". Data type must be float16. + truth boxes, and the value "4" refers to "x0", "x1", "y0", and "y1". Data type must be float16 or float32. Outputs: - Tensor, the 'iou' values, tensor of shape (M, N), with data type float16. + Tensor, the 'iou' values, tensor of shape (M, N), with the same data type as `anchor_boxes`. Raises: KeyError: When `mode` is not 'iou' or 'iof'. @@ -274,6 +278,9 @@ class IOU(PrimitiveWithInfer): return iou def infer_dtype(self, anchor_boxes, gt_boxes): + valid_type = [mstype.float32, mstype.float16] + validator.check_tensor_type_same({"anchor_boxes": anchor_boxes}, valid_type, self.name) + validator.check_tensor_type_same({"gt_boxes": gt_boxes}, valid_type, self.name) return anchor_boxes diff --git a/mindspore/train/quant/quant.py b/mindspore/train/quant/quant.py index b947811030..45000d0194 100644 --- a/mindspore/train/quant/quant.py +++ b/mindspore/train/quant/quant.py @@ -473,7 +473,7 @@ def export(network, *inputs, file_name, mean=127.5, std_dev=127.5, file_format=' def convert_quant_network(network, bn_fold=False, - freeze_bn=0, + freeze_bn=10000, quant_delay=(0, 0), num_bits=(8, 8), per_channel=(False, False), diff --git a/model_zoo/official/cv/alexnet/src/config.py b/model_zoo/official/cv/alexnet/src/config.py index 9edfec2b60..65146795a9 100644 --- a/model_zoo/official/cv/alexnet/src/config.py +++ b/model_zoo/official/cv/alexnet/src/config.py @@ -22,7 +22,7 @@ alexnet_cfg = edict({ 'num_classes': 10, 'learning_rate': 0.002, 'momentum': 0.9, - 'epoch_size': 1, + 'epoch_size': 30, 'batch_size': 32, 'buffer_size': 1000, 'image_height': 227, diff --git a/model_zoo/official/cv/deeplabv3/src/deeplabv3.py b/model_zoo/official/cv/deeplabv3/src/deeplabv3.py index bbfc4dceb3..7b3c8eb53b 100644 --- a/model_zoo/official/cv/deeplabv3/src/deeplabv3.py +++ b/model_zoo/official/cv/deeplabv3/src/deeplabv3.py @@ -381,6 +381,7 @@ class DeepLabV3(nn.Cell): self.concat = P.Concat(axis=2) self.expand_dims = P.ExpandDims() self.reduce_mean = P.ReduceMean() + self.argmax = P.Argmax(axis=1) self.sample_common = P.ResizeBilinear((int(feature_shape[2]), int(feature_shape[3])), align_corners=True) @@ -419,6 +420,8 @@ class DeepLabV3(nn.Cell): logits_i = self.expand_dims(logits_i, 2) logits = self.concat((logits, logits_i)) logits = self.reduce_mean(logits, 2) + if not self.training: + logits = self.argmax(logits) return logits diff --git a/model_zoo/official/cv/deeplabv3/src/losses.py b/model_zoo/official/cv/deeplabv3/src/losses.py index af782c2de9..db45cbb6b6 100644 --- a/model_zoo/official/cv/deeplabv3/src/losses.py +++ b/model_zoo/official/cv/deeplabv3/src/losses.py @@ -42,6 +42,8 @@ class OhemLoss(nn.Cell): self.loss_weight = 1.0 def construct(self, logits, labels): + if not self.training: + return 0 logits = self.transpose(logits, (0, 2, 3, 1)) logits = self.reshape(logits, (-1, self.num)) labels = F.cast(labels, mstype.int32) diff --git a/model_zoo/official/cv/deeplabv3/src/md_dataset.py b/model_zoo/official/cv/deeplabv3/src/md_dataset.py index e136da23e1..358c28ef2a 100644 --- a/model_zoo/official/cv/deeplabv3/src/md_dataset.py +++ b/model_zoo/official/cv/deeplabv3/src/md_dataset.py @@ -13,10 +13,10 @@ # limitations under the License. # ============================================================================ """Dataset module.""" +import numpy as np from PIL import Image import mindspore.dataset as de import mindspore.dataset.transforms.vision.c_transforms as C -import numpy as np from .ei_dataset import HwVocRawDataset from .utils import custom_transforms as tr diff --git a/model_zoo/official/cv/deeplabv3/src/miou_precision.py b/model_zoo/official/cv/deeplabv3/src/miou_precision.py index b73b3947d4..8b3e2f5d08 100644 --- a/model_zoo/official/cv/deeplabv3/src/miou_precision.py +++ b/model_zoo/official/cv/deeplabv3/src/miou_precision.py @@ -50,10 +50,7 @@ class MiouPrecision(Metric): raise ValueError('Need 2 inputs (y_pred, y), but got {}'.format(len(inputs))) predict_in = self._convert_data(inputs[0]) label_in = self._convert_data(inputs[1]) - if predict_in.shape[1] != self._num_class: - raise ValueError('Class number not match, last input data contain {} classes, but current data contain {} ' - 'classes'.format(self._num_class, predict_in.shape[1])) - pred = np.argmax(predict_in, axis=1) + pred = predict_in label = label_in if len(label.flatten()) != len(pred.flatten()): print('Skipping: len(gt) = {:d}, len(pred) = {:d}'.format(len(label.flatten()), len(pred.flatten()))) diff --git a/model_zoo/official/cv/faster_rcnn/src/network_define.py b/model_zoo/official/cv/faster_rcnn/src/network_define.py index b4fde3f824..348c72cee5 100644 --- a/model_zoo/official/cv/faster_rcnn/src/network_define.py +++ b/model_zoo/official/cv/faster_rcnn/src/network_define.py @@ -110,8 +110,6 @@ class LossCallBack(Callback): class LossNet(nn.Cell): """FasterRcnn loss method""" - def __init__(self): - super(LossNet, self).__init__() def construct(self, x1, x2, x3, x4, x5, x6): return x1 + x2 diff --git a/model_zoo/official/cv/lenet/src/config.py b/model_zoo/official/cv/lenet/src/config.py index 9a13ae535f..405b5ff5fa 100644 --- a/model_zoo/official/cv/lenet/src/config.py +++ b/model_zoo/official/cv/lenet/src/config.py @@ -22,7 +22,7 @@ mnist_cfg = edict({ 'num_classes': 10, 'lr': 0.01, 'momentum': 0.9, - 'epoch_size': 1, + 'epoch_size': 10, 'batch_size': 32, 'buffer_size': 1000, 'image_height': 32, diff --git a/model_zoo/official/cv/maskrcnn/src/network_define.py b/model_zoo/official/cv/maskrcnn/src/network_define.py index dc18da3956..481632667b 100644 --- a/model_zoo/official/cv/maskrcnn/src/network_define.py +++ b/model_zoo/official/cv/maskrcnn/src/network_define.py @@ -117,8 +117,6 @@ class LossCallBack(Callback): class LossNet(nn.Cell): """MaskRcnn loss method""" - def __init__(self): - super(LossNet, self).__init__() def construct(self, x1, x2, x3, x4, x5, x6, x7): return x1 + x2 diff --git a/model_zoo/official/cv/mobilenetv2_quant/scripts/run_train_quant.sh b/model_zoo/official/cv/mobilenetv2_quant/scripts/run_train_quant.sh index e4d41ac9a2..c7a3d00863 100644 --- a/model_zoo/official/cv/mobilenetv2_quant/scripts/run_train_quant.sh +++ b/model_zoo/official/cv/mobilenetv2_quant/scripts/run_train_quant.sh @@ -75,15 +75,15 @@ run_gpu() python ${BASEPATH}/../train.py \ --dataset_path=$4 \ --device_target=$1 \ - --quantization_aware=True \ - &> ../train.log & # dataset train folder + --pre_trained=$5 \ + --quantization_aware=True &> ../train.log & # dataset train folder } -if [ $# -gt 6 ] || [ $# -lt 4 ] +if [ $# -gt 6 ] || [ $# -lt 5 ] then echo "Usage:\n \ - Ascend: sh run_train.sh Ascend [DEVICE_NUM] [SERVER_IP(x.x.x.x)] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH]\n \ - GPU: sh run_train.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH]\n \ + Ascend: sh run_train_quant.sh Ascend [DEVICE_NUM] [SERVER_IP(x.x.x.x)] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH]\n \ + GPU: sh run_train_quant.sh GPU [DEVICE_NUM] [VISIABLE_DEVICES(0,1,2,3,4,5,6,7)] [DATASET_PATH] [CKPT_PATH]\n \ " exit 1 fi diff --git a/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py b/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py index 105a5e1396..ce9f2d8faf 100644 --- a/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py +++ b/model_zoo/official/cv/mobilenetv2_quant/src/dataset.py @@ -22,7 +22,6 @@ import mindspore.dataset.engine as de import mindspore.dataset.transforms.vision.c_transforms as C import mindspore.dataset.transforms.c_transforms as C2 import mindspore.dataset.transforms.vision.py_transforms as P -from src.config import config_ascend def create_dataset(dataset_path, do_train, config, device_target, repeat_num=1, batch_size=32): @@ -42,7 +41,7 @@ def create_dataset(dataset_path, do_train, config, device_target, repeat_num=1, rank_size = int(os.getenv("RANK_SIZE")) rank_id = int(os.getenv("RANK_ID")) columns_list = ['image', 'label'] - if config_ascend.data_load_mode == "mindrecord": + if config.data_load_mode == "mindrecord": load_func = partial(de.MindDataset, dataset_path, columns_list) else: load_func = partial(de.ImageFolderDatasetV2, dataset_path) @@ -54,6 +53,13 @@ def create_dataset(dataset_path, do_train, config, device_target, repeat_num=1, num_shards=rank_size, shard_id=rank_id) else: ds = load_func(num_parallel_workers=8, shuffle=False) + elif device_target == "GPU": + if do_train: + from mindspore.communication.management import get_rank, get_group_size + ds = de.ImageFolderDatasetV2(dataset_path, num_parallel_workers=8, shuffle=True, + num_shards=get_group_size(), shard_id=get_rank()) + else: + ds = de.ImageFolderDatasetV2(dataset_path, num_parallel_workers=8, shuffle=True) else: raise ValueError("Unsupport device_target.") diff --git a/model_zoo/official/cv/mobilenetv2_quant/src/mobilenetV2_quant.py b/model_zoo/official/cv/mobilenetv2_quant/src/mobilenetV2_quant.py new file mode 100644 index 0000000000..77b403713d --- /dev/null +++ b/model_zoo/official/cv/mobilenetv2_quant/src/mobilenetV2_quant.py @@ -0,0 +1,218 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +"""MobileNetV2 Quant model define""" + +import mindspore.nn as nn +from mindspore.ops import operations as P + +__all__ = ['mobilenetV2_quant'] + +_quant_delay = 200 +_ema_decay = 0.999 +_symmetric = False +_per_channel = False + + +def _make_divisible(v, divisor, min_value=None): + if min_value is None: + min_value = divisor + new_v = max(min_value, int(v + divisor / 2) // divisor * divisor) + # Make sure that round down does not go down by more than 10%. + if new_v < 0.9 * v: + new_v += divisor + return new_v + + +class GlobalAvgPooling(nn.Cell): + """ + Global avg pooling definition. + + Args: + + Returns: + Tensor, output tensor. + + Examples: + >>> GlobalAvgPooling() + """ + + def __init__(self): + super(GlobalAvgPooling, self).__init__() + self.mean = P.ReduceMean(keep_dims=False) + + def construct(self, x): + x = self.mean(x, (2, 3)) + return x + + +class ConvBNReLU(nn.Cell): + """ + Convolution/Depthwise fused with Batchnorm and ReLU block definition. + + Args: + in_planes (int): Input channel. + out_planes (int): Output channel. + kernel_size (int): Input kernel size. + stride (int): Stride size for the first convolutional layer. Default: 1. + groups (int): channel group. Convolution is 1 while Depthiwse is input channel. Default: 1. + + Returns: + Tensor, output tensor. + + Examples: + >>> ConvBNReLU(16, 256, kernel_size=1, stride=1, groups=1) + """ + + def __init__(self, in_planes, out_planes, kernel_size=3, stride=1, groups=1): + super(ConvBNReLU, self).__init__() + padding = (kernel_size - 1) // 2 + conv = nn.Conv2dBnFoldQuant(in_planes, out_planes, kernel_size, stride, + pad_mode='pad', padding=padding, quant_delay=_quant_delay, group=groups, + per_channel=_per_channel, symmetric=_symmetric) + layers = [conv, nn.ReLU()] + self.features = nn.SequentialCell(layers) + self.fake = nn.FakeQuantWithMinMax(ema=True, ema_decay=_ema_decay, min_init=0, quant_delay=_quant_delay) + + def construct(self, x): + output = self.features(x) + output = self.fake(output) + return output + + +class InvertedResidual(nn.Cell): + """ + Mobilenetv2 residual block definition. + + Args: + inp (int): Input channel. + oup (int): Output channel. + stride (int): Stride size for the first convolutional layer. Default: 1. + expand_ratio (int): expand ration of input channel + + Returns: + Tensor, output tensor. + + Examples: + >>> ResidualBlock(3, 256, 1, 1) + """ + + def __init__(self, inp, oup, stride, expand_ratio): + super(InvertedResidual, self).__init__() + assert stride in [1, 2] + + hidden_dim = int(round(inp * expand_ratio)) + self.use_res_connect = stride == 1 and inp == oup + + layers = [] + if expand_ratio != 1: + layers.append(ConvBNReLU(inp, hidden_dim, kernel_size=1)) + layers.extend([ + # dw + ConvBNReLU(hidden_dim, hidden_dim, stride=stride, groups=hidden_dim), + # pw-linear + nn.Conv2dBnFoldQuant(hidden_dim, oup, kernel_size=1, stride=1, pad_mode='pad', padding=0, group=1, + per_channel=_per_channel, symmetric=_symmetric, quant_delay=_quant_delay), + nn.FakeQuantWithMinMax(ema=True, ema_decay=_ema_decay, quant_delay=_quant_delay) + ]) + self.conv = nn.SequentialCell(layers) + self.add = P.TensorAdd() + self.add_fake = nn.FakeQuantWithMinMax(ema=True, ema_decay=_ema_decay, quant_delay=_quant_delay) + + def construct(self, x): + identity = x + x = self.conv(x) + if self.use_res_connect: + x = self.add(identity, x) + x = self.add_fake(x) + return x + + +class MobileNetV2Quant(nn.Cell): + """ + MobileNetV2Quant architecture. + + Args: + class_num (Cell): number of classes. + width_mult (int): Channels multiplier for round to 8/16 and others. Default is 1. + has_dropout (bool): Is dropout used. Default is false + inverted_residual_setting (list): Inverted residual settings. Default is None + round_nearest (list): Channel round to . Default is 8 + Returns: + Tensor, output tensor. + + Examples: + >>> MobileNetV2Quant(num_classes=1000) + """ + + def __init__(self, num_classes=1000, width_mult=1., + has_dropout=False, inverted_residual_setting=None, round_nearest=8): + super(MobileNetV2Quant, self).__init__() + block = InvertedResidual + input_channel = 32 + last_channel = 1280 + # setting of inverted residual blocks + self.cfgs = inverted_residual_setting + if inverted_residual_setting is None: + self.cfgs = [ + # t, c, n, s + [1, 16, 1, 1], + [6, 24, 2, 2], + [6, 32, 3, 2], + [6, 64, 4, 2], + [6, 96, 3, 1], + [6, 160, 3, 2], + [6, 320, 1, 1], + ] + + # building first layer + input_channel = _make_divisible(input_channel * width_mult, round_nearest) + self.out_channels = _make_divisible(last_channel * max(1.0, width_mult), round_nearest) + self.input_fake = nn.FakeQuantWithMinMax(ema=True, ema_decay=_ema_decay, quant_delay=_quant_delay) + features = [ConvBNReLU(3, input_channel, stride=2)] + # building inverted residual blocks + for t, c, n, s in self.cfgs: + output_channel = _make_divisible(c * width_mult, round_nearest) + for i in range(n): + stride = s if i == 0 else 1 + features.append(block(input_channel, output_channel, stride, expand_ratio=t)) + input_channel = output_channel + # building last several layers + features.append(ConvBNReLU(input_channel, self.out_channels, kernel_size=1)) + # make it nn.CellList + self.features = nn.SequentialCell(features) + # mobilenet head + head = ([GlobalAvgPooling(), + nn.DenseQuant(self.out_channels, num_classes, has_bias=True, per_channel=_per_channel, + symmetric=_symmetric, quant_delay=_quant_delay), + nn.FakeQuantWithMinMax(ema=True, ema_decay=_ema_decay)] if not has_dropout else + [GlobalAvgPooling(), + nn.Dropout(0.2), + nn.DenseQuant(self.out_channels, num_classes, has_bias=True, per_channel=_per_channel, + symmetric=_symmetric, quant_delay=_quant_delay), + nn.FakeQuantWithMinMax(ema=True, ema_decay=_ema_decay, quant_delay=_quant_delay)]) + self.head = nn.SequentialCell(head) + + def construct(self, x): + x = self.input_fake(x) + x = self.features(x) + x = self.head(x) + return x + + +def mobilenetV2_quant(**kwargs): + """ + Constructs a MobileNet V2 model + """ + return MobileNetV2Quant(**kwargs) diff --git a/model_zoo/official/cv/mobilenetv2_quant/train.py b/model_zoo/official/cv/mobilenetv2_quant/train.py index 2253fbb5a0..bd8051cccc 100644 --- a/model_zoo/official/cv/mobilenetv2_quant/train.py +++ b/model_zoo/official/cv/mobilenetv2_quant/train.py @@ -56,7 +56,7 @@ if args_opt.device_target == "Ascend": context.set_context(mode=context.GRAPH_MODE, device_target="Ascend", device_id=device_id, save_graphs=False) -elif args_opt.platform == "GPU": +elif args_opt.device_target == "GPU": init("nccl") context.set_auto_parallel_context(device_num=get_group_size(), parallel_mode=ParallelMode.DATA_PARALLEL, @@ -205,5 +205,5 @@ def train_on_gpu(): if __name__ == '__main__': if args_opt.device_target == "Ascend": train_on_ascend() - elif args_opt.platform == "GPU": + elif args_opt.device_target == "GPU": train_on_gpu() diff --git a/model_zoo/official/cv/resnet/README.md b/model_zoo/official/cv/resnet/README.md index a22df320e7..2f5f77c269 100644 --- a/model_zoo/official/cv/resnet/README.md +++ b/model_zoo/official/cv/resnet/README.md @@ -41,20 +41,22 @@ ImageNet2012 └──resnet ├── README.md ├── script - ├── run_distribute_train.sh # launch distributed training(8 pcs) - ├── run_eval.sh # launch evaluation - └── run_standalone_train.sh # launch standalone training(1 pcs) - ├── run_distribute_train_gpu.sh # launch gpu distributed training(8 pcs) - ├── run_eval_gpu.sh # launch gpu evaluation - └── run_standalone_train_gpu.sh # launch gpu standalone training(1 pcs) + ├── run_distribute_train.sh # launch distributed training(8 pcs) + ├── run_parameter_server_train.sh # launch Ascend parameter server training(8 pcs) + ├── run_eval.sh # launch evaluation + └── run_standalone_train.sh # launch standalone training(1 pcs) + ├── run_distribute_train_gpu.sh # launch gpu distributed training(8 pcs) + ├── run_parameter_server_train_gpu.sh # launch gpu parameter server training(8 pcs) + ├── run_eval_gpu.sh # launch gpu evaluation + └── run_standalone_train_gpu.sh # launch gpu standalone training(1 pcs) ├── src - ├── config.py # parameter configuration - ├── dataset.py # data preprocessing - ├── crossentropy.py # loss definition for ImageNet2012 dataset - ├── lr_generator.py # generate learning rate for each step - └── resnet.py # resnet backbone, including resnet50 and resnet101 - ├── eval.py # eval net - └── train.py # train net + ├── config.py # parameter configuration + ├── dataset.py # data preprocessing + ├── crossentropy.py # loss definition for ImageNet2012 dataset + ├── lr_generator.py # generate learning rate for each step + └── resnet.py # resnet backbone, including resnet50 and resnet101 + ├── eval.py # eval net + └── train.py # train net ``` @@ -71,6 +73,7 @@ Parameters for both training and evaluation can be set in config.py. "momentum": 0.9, # momentum "weight_decay": 1e-4, # weight decay "epoch_size": 90, # only valid for taining, which is always 1 for inference +"pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size "save_checkpoint": True, # whether save checkpoint or not "save_checkpoint_steps": 195, # the step interval between two checkpoints. By default, the last checkpoint will be saved after the last step "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint @@ -91,7 +94,7 @@ Parameters for both training and evaluation can be set in config.py. "momentum": 0.9, # momentum optimizer "weight_decay": 1e-4, # weight decay "epoch_size": 90, # only valid for taining, which is always 1 for inference -"pretrained_epoch_size": 1, # epoch size that model has been trained before load pretrained checkpoint +"pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size "save_checkpoint": True, # whether save checkpoint or not "save_checkpoint_epochs": 1, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint @@ -112,8 +115,8 @@ Parameters for both training and evaluation can be set in config.py. "loss_scale": 1024, # loss scale "momentum": 0.9, # momentum optimizer "weight_decay": 1e-4, # weight decay -"epoch_size": 120, # epoch sizes for training -"pretrain_epoch_size": 0, # epoch size of pretrain checkpoint +"epoch_size": 120, # epoch size for training +"pretrain_epoch_size": 0, # epoch size that model has been trained before loading pretrained checkpoint, actual training epoch size is equal to epoch_size minus pretrain_epoch_size "save_checkpoint": True, # whether save checkpoint or not "save_checkpoint_epochs": 1, # the epoch interval between two checkpoints. By default, the last checkpoint will be saved after the last epoch "keep_checkpoint_max": 10, # only keep the last keep_checkpoint_max checkpoint @@ -252,3 +255,14 @@ sh run_standalone_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATA # infer example sh run_eval_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [CHECKPOINT_PATH] ``` + +### Running parameter server mode training +``` +# parameter server training Ascend example +sh run_parameter_server_train.sh [resnet50|resnet101] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional) + +# parameter server training GPU example +sh run_parameter_server_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional) + +> The way to evaluate is the same as the examples above. +``` diff --git a/model_zoo/official/cv/resnet/scripts/run_parameter_server_train.sh b/model_zoo/official/cv/resnet/scripts/run_parameter_server_train.sh new file mode 100644 index 0000000000..a041aef04e --- /dev/null +++ b/model_zoo/official/cv/resnet/scripts/run_parameter_server_train.sh @@ -0,0 +1,158 @@ +#!/bin/bash +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ + +if [ $# != 4 ] && [ $# != 5 ] +then + echo "Usage: sh run_distribute_train.sh [resnet50|resnet101] [cifar10|imagenet2012] [RANK_TABLE_FILE] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)" +exit 1 +fi + +if [ $1 != "resnet50" ] && [ $1 != "resnet101" ] +then + echo "error: the selected net is neither resnet50 nor resnet101" +exit 1 +fi + +if [ $2 != "cifar10" ] && [ $2 != "imagenet2012" ] +then + echo "error: the selected dataset is neither cifar10 nor imagenet2012" +exit 1 +fi + +if [ $1 == "resnet101" ] && [ $2 == "cifar10" ] +then + echo "error: training resnet101 with cifar10 dataset is unsupported now!" +exit 1 +fi + + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + +PATH1=$(get_real_path $3) +PATH2=$(get_real_path $4) + +if [ $# == 5 ] +then + PATH3=$(get_real_path $5) +fi + +if [ ! -f $PATH1 ] +then + echo "error: RANK_TABLE_FILE=$PATH1 is not a file" +exit 1 +fi + +if [ ! -d $PATH2 ] +then + echo "error: DATASET_PATH=$PATH2 is not a directory" +exit 1 +fi + +if [ $# == 5 ] && [ ! -f $PATH3 ] +then + echo "error: PRETRAINED_CKPT_PATH=$PATH3 is not a file" +exit 1 +fi + +ulimit -u unlimited +export DEVICE_NUM=8 +export RANK_SIZE=8 +export RANK_TABLE_FILE=$PATH1 + +export MS_COMM_TYPE=zmq +export MS_SCHED_NUM=1 +export MS_WORKER_NUM=$RANK_SIZE +export MS_SERVER_NUM=1 +export MS_SCHED_HOST=127.0.0.1 +export MS_SCHED_PORT=8081 + +export MS_ROLE=MS_SCHED +export DEVICE_ID=0 +export RANK_ID=0 +rm -rf ./sched +mkdir ./sched +cp ../*.py ./sched +cp *.sh ./sched +cp -r ../src ./sched +cd ./sched || exit +echo "start scheduler" +if [ $# == 4 ] +then + python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=1 --dataset_path=$PATH2 --parameter_server=True &> sched.log & +fi + +if [ $# == 5 ] +then + python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=1 --dataset_path=$PATH2 --parameter_server=True --pre_trained=$PATH3 &> sched.log & +fi +cd .. + +export MS_ROLE=MS_PSERVER +for((i=0; i<1; i++)) +do + export DEVICE_ID=$i + export RANK_ID=$i + rm -rf ./server_$i + mkdir ./server_$i + cp ../*.py ./server_$i + cp *.sh ./server_$i + cp -r ../src ./server_$i + cd ./server_$i || exit + echo "start server" + if [ $# == 4 ] + then + python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=1 --dataset_path=$PATH2 --parameter_server=True &> server_$i.log & + fi + + if [ $# == 5 ] + then + python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=1 --dataset_path=$PATH2 --parameter_server=True --pre_trained=$PATH3 &> server_$i.log & + fi + + cd .. +done + +export MS_ROLE=MS_WORKER +for((i=0; i<${DEVICE_NUM}; i++)) +do + export DEVICE_ID=$i + export RANK_ID=$i + rm -rf ./worker_$i + mkdir ./worker_$i + cp ../*.py ./worker_$i + cp *.sh ./worker_$i + cp -r ../src ./worker_$i + cd ./worker_$i || exit + echo "start training for worker rank $RANK_ID, device $DEVICE_ID" + env > env.log + if [ $# == 4 ] + then + python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=$DEVICE_NUM --dataset_path=$PATH2 --parameter_server=True &> worker_$i.log & + fi + + if [ $# == 5 ] + then + python train.py --net=$1 --dataset=$2 --run_distribute=True --device_num=$DEVICE_NUM --dataset_path=$PATH2 --parameter_server=True --pre_trained=$PATH3 &> worker_$i.log & + fi + + cd .. +done diff --git a/model_zoo/official/cv/resnet/scripts/run_parameter_server_train_gpu.sh b/model_zoo/official/cv/resnet/scripts/run_parameter_server_train_gpu.sh new file mode 100755 index 0000000000..7ccfdddb2f --- /dev/null +++ b/model_zoo/official/cv/resnet/scripts/run_parameter_server_train_gpu.sh @@ -0,0 +1,144 @@ +#!/bin/bash +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ + +if [ $# != 3 ] && [ $# != 4 ] +then + echo "Usage: sh run_distribute_train_gpu.sh [resnet50|resnet101] [cifar10|imagenet2012] [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)" +exit 1 +fi + +if [ $1 != "resnet50" ] && [ $1 != "resnet101" ] +then + echo "error: the selected net is neither resnet50 nor resnet101" +exit 1 +fi + +if [ $2 != "cifar10" ] && [ $2 != "imagenet2012" ] +then + echo "error: the selected dataset is neither cifar10 nor imagenet2012" +exit 1 +fi + +if [ $1 == "resnet101" ] && [ $2 == "cifar10" ] +then + echo "error: training resnet101 with cifar10 dataset is unsupported now!" +exit 1 +fi + + +get_real_path(){ + if [ "${1:0:1}" == "/" ]; then + echo "$1" + else + echo "$(realpath -m $PWD/$1)" + fi +} + +PATH1=$(get_real_path $3) + +if [ $# == 4 ] +then + PATH2=$(get_real_path $4) +fi + + +if [ ! -d $PATH2 ] +then + echo "error: DATASET_PATH=$PATH1 is not a directory" +exit 1 +fi + +if [ $# == 5 ] && [ ! -f $PATH2 ] +then + echo "error: PRETRAINED_CKPT_PATH=$PATH2 is not a file" +exit 1 +fi + +export DEVICE_NUM=8 +export RANK_SIZE=8 + +export MS_COMM_TYPE=zmq +export MS_SCHED_NUM=1 +export MS_WORKER_NUM=8 +export MS_SERVER_NUM=1 +export MS_SCHED_HOST=127.0.0.1 +export MS_SCHED_PORT=8081 + +export MS_ROLE=MS_SCHED +rm -rf ./sched +mkdir ./sched +cp ../*.py ./sched +cp *.sh ./sched +cp -r ../src ./sched +cd ./sched || exit +if [ $# == 3 ] +then + mpirun --allow-run-as-root -n 1 \ + python train.py --net=$1 --dataset=$2 --run_distribute=True \ + --device_num=$DEVICE_NUM --device_target="GPU" --dataset_path=$PATH1 --parameter_server=True &> sched.log & +fi + +if [ $# == 4 ] +then + mpirun --allow-run-as-root -n 1 \ + python train.py --net=$1 --dataset=$2 --run_distribute=True \ + --device_num=$DEVICE_NUM --device_target="GPU" --dataset_path=$PATH1 --parameter_server=True --pre_trained=$PATH2 &> sched.log & +fi +cd .. + +export MS_ROLE=MS_PSERVER +rm -rf ./server +mkdir ./server +cp ../*.py ./server +cp *.sh ./server +cp -r ../src ./server +cd ./server || exit +if [ $# == 3 ] +then + mpirun --allow-run-as-root -n 1 \ + python train.py --net=$1 --dataset=$2 --run_distribute=True \ + --device_num=$DEVICE_NUM --device_target="GPU" --dataset_path=$PATH1 --parameter_server=True &> server.log & +fi + +if [ $# == 4 ] +then + mpirun --allow-run-as-root -n 1 \ + python train.py --net=$1 --dataset=$2 --run_distribute=True \ + --device_num=$DEVICE_NUM --device_target="GPU" --dataset_path=$PATH1 --parameter_server=True --pre_trained=$PATH2 &> server.log & +fi +cd .. + +export MS_ROLE=MS_WORKER +rm -rf ./worker +mkdir ./worker +cp ../*.py ./worker +cp *.sh ./worker +cp -r ../src ./worker +cd ./worker || exit +if [ $# == 3 ] +then + mpirun --allow-run-as-root -n $RANK_SIZE \ + python train.py --net=$1 --dataset=$2 --run_distribute=True \ + --device_num=$DEVICE_NUM --device_target="GPU" --dataset_path=$PATH1 --parameter_server=True &> worker.log & +fi + +if [ $# == 4 ] +then + mpirun --allow-run-as-root -n $RANK_SIZE \ + python train.py --net=$1 --dataset=$2 --run_distribute=True \ + --device_num=$DEVICE_NUM --device_target="GPU" --dataset_path=$PATH1 --parameter_server=True --pre_trained=$PATH2 &> worker.log & +fi +cd .. diff --git a/model_zoo/official/cv/resnet/src/config.py b/model_zoo/official/cv/resnet/src/config.py index 7b1759fde0..29cd0a50fc 100755 --- a/model_zoo/official/cv/resnet/src/config.py +++ b/model_zoo/official/cv/resnet/src/config.py @@ -25,6 +25,7 @@ config1 = ed({ "momentum": 0.9, "weight_decay": 1e-4, "epoch_size": 90, + "pretrain_epoch_size": 0, "save_checkpoint": True, "save_checkpoint_epochs": 5, "keep_checkpoint_max": 10, @@ -44,7 +45,7 @@ config2 = ed({ "momentum": 0.9, "weight_decay": 1e-4, "epoch_size": 90, - "pretrain_epoch_size": 1, + "pretrain_epoch_size": 0, "save_checkpoint": True, "save_checkpoint_epochs": 5, "keep_checkpoint_max": 10, diff --git a/model_zoo/official/cv/resnet/train.py b/model_zoo/official/cv/resnet/train.py index 414fa4c7de..235b1f13c4 100755 --- a/model_zoo/official/cv/resnet/train.py +++ b/model_zoo/official/cv/resnet/train.py @@ -41,6 +41,7 @@ parser.add_argument('--device_num', type=int, default=1, help='Device num.') parser.add_argument('--dataset_path', type=str, default=None, help='Dataset path') parser.add_argument('--device_target', type=str, default='Ascend', help='Device target') parser.add_argument('--pre_trained', type=str, default=None, help='Pretrained checkpoint path') +parser.add_argument('--parameter_server', type=bool, default=False, help='Run parameter server train') args_opt = parser.parse_args() random.seed(1) @@ -92,6 +93,8 @@ if __name__ == '__main__': # define net net = resnet(class_num=config.class_num) + if args_opt.parameter_server: + net.set_param_ps() # init weight if args_opt.pre_trained: @@ -181,4 +184,5 @@ if __name__ == '__main__': cb += [ckpt_cb] # train model - model.train(config.epoch_size, dataset, callbacks=cb) + model.train(config.epoch_size - config.pretrain_epoch_size, dataset, callbacks=cb, + dataset_sink_mode=(not args_opt.parameter_server)) diff --git a/model_zoo/official/cv/ssd/src/dataset.py b/model_zoo/official/cv/ssd/src/dataset.py index d842aef709..f3f7000426 100644 --- a/model_zoo/official/cv/ssd/src/dataset.py +++ b/model_zoo/official/cv/ssd/src/dataset.py @@ -20,8 +20,8 @@ from __future__ import division import os import json import xml.etree.ElementTree as et -import cv2 import numpy as np +import cv2 import mindspore.dataset as de import mindspore.dataset.transforms.vision.c_transforms as C diff --git a/model_zoo/official/cv/ssd/src/init_params.py b/model_zoo/official/cv/ssd/src/init_params.py index b71ee2c4dc..e144bc7f08 100644 --- a/model_zoo/official/cv/ssd/src/init_params.py +++ b/model_zoo/official/cv/ssd/src/init_params.py @@ -14,8 +14,8 @@ # ============================================================================ """Parameters utils""" -from mindspore.common.initializer import initializer, TruncatedNormal import numpy as np +from mindspore.common.initializer import initializer, TruncatedNormal def init_net_param(network, initialize_mode='TruncatedNormal'): """Init the parameters in net.""" diff --git a/model_zoo/official/cv/vgg16/README.md b/model_zoo/official/cv/vgg16/README.md index 346738a8fa..4ecd749a74 100644 --- a/model_zoo/official/cv/vgg16/README.md +++ b/model_zoo/official/cv/vgg16/README.md @@ -212,7 +212,7 @@ parameters/options: Usage: sh script/run_distribute_train.sh [RANK_TABLE_FILE] [DATA_PATH] parameters/options: - RANK_TABLE_FILE HCCL configuration file path. + RANK_TABLE_FILE HCCL configuration file path. DATA_PATH the storage path of dataset. ``` diff --git a/model_zoo/official/cv/vgg16/scripts/run_distribute_train.sh b/model_zoo/official/cv/vgg16/scripts/run_distribute_train.sh index 1a9e022fd2..92359a4386 100755 --- a/model_zoo/official/cv/vgg16/scripts/run_distribute_train.sh +++ b/model_zoo/official/cv/vgg16/scripts/run_distribute_train.sh @@ -22,7 +22,7 @@ fi if [ ! -f $1 ] then - echo "error: RANK_TABLE_FILEH=$1 is not a file" + echo "error: RANK_TABLE_FILE=$1 is not a file" exit 1 fi diff --git a/model_zoo/official/cv/warpctc/src/warpctc_for_train.py b/model_zoo/official/cv/warpctc/src/warpctc_for_train.py index 8cbf2f986a..5654f05e5d 100755 --- a/model_zoo/official/cv/warpctc/src/warpctc_for_train.py +++ b/model_zoo/official/cv/warpctc/src/warpctc_for_train.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """Automatic differentiation with grad clip.""" +import numpy as np from mindspore.parallel._utils import (_get_device_num, _get_mirror_mean, _get_parallel_mode) from mindspore.train.parallel_utils import ParallelMode @@ -24,7 +25,6 @@ from mindspore.nn.cell import Cell from mindspore.nn.wrap.grad_reducer import DistributedGradReducer import mindspore.nn as nn from mindspore.common.tensor import Tensor -import numpy as np compute_norm = C.MultitypeFuncGraph("compute_norm") diff --git a/model_zoo/official/cv/yolov3_darknet53/scripts/run_distribute_train.sh b/model_zoo/official/cv/yolov3_darknet53/scripts/run_distribute_train.sh index fcc0ef2867..f6791821c8 100644 --- a/model_zoo/official/cv/yolov3_darknet53/scripts/run_distribute_train.sh +++ b/model_zoo/official/cv/yolov3_darknet53/scripts/run_distribute_train.sh @@ -55,7 +55,7 @@ fi export DEVICE_NUM=8 export RANK_SIZE=8 -export RANK_TABLE_FILEH=$RANK_TABLE_FILE +export RANK_TABLE_FILE=$RANK_TABLE_FILE for((i=0; i<${DEVICE_NUM}; i++)) do diff --git a/model_zoo/official/gnn/gat/src/gat.py b/model_zoo/official/gnn/gat/src/gat.py index ff0c964e9b..2245aae214 100644 --- a/model_zoo/official/gnn/gat/src/gat.py +++ b/model_zoo/official/gnn/gat/src/gat.py @@ -297,6 +297,9 @@ class AttentionHead(nn.Cell): self.activation = activation def construct(self, input_feature, bias_mat, training=True): + """ + Attention Head for Graph Attention Networks. + """ if training is True: input_feature = self.in_drop(input_feature) diff --git a/model_zoo/official/gnn/gat/src/utils.py b/model_zoo/official/gnn/gat/src/utils.py index 03305ca3d3..06d3252994 100644 --- a/model_zoo/official/gnn/gat/src/utils.py +++ b/model_zoo/official/gnn/gat/src/utils.py @@ -38,7 +38,7 @@ class MaskedSoftMaxLoss(nn.Cell): self.num_params = len(self.params) def construct(self, logits): - # calc l2 loss + """calc l2 loss""" l2_loss = 0 for i in range(self.num_params): l2_loss = l2_loss + self.l2_coeff * P.L2Loss()(self.params[i]) @@ -69,6 +69,7 @@ class MaskedAccuracy(nn.Cell): self.mask = Tensor(mask, dtype=mstype.float32) def construct(self, logits): + """Calculate accuracy""" logits = P.Reshape()(logits, (-1, self.num_class)) labels = P.Reshape()(self.label, (-1, self.num_class)) mask = P.Reshape()(self.mask, (-1,)) diff --git a/model_zoo/official/gnn/gcn/src/gcn.py b/model_zoo/official/gnn/gcn/src/gcn.py index 6e01c45d8b..3e1c432405 100644 --- a/model_zoo/official/gnn/gcn/src/gcn.py +++ b/model_zoo/official/gnn/gcn/src/gcn.py @@ -66,6 +66,9 @@ class GraphConvolution(nn.Cell): self.matmul = P.MatMul() def construct(self, adj, input_feature): + """ + GCN graph convolution layer. + """ dropout = input_feature if self.dropout_flag: dropout = self.dropout(dropout) diff --git a/model_zoo/official/gnn/gcn/src/metrics.py b/model_zoo/official/gnn/gcn/src/metrics.py index e923f17e39..0d47a9bc6c 100644 --- a/model_zoo/official/gnn/gcn/src/metrics.py +++ b/model_zoo/official/gnn/gcn/src/metrics.py @@ -39,6 +39,7 @@ class Loss(nn.Cell): self.param = param def construct(self, preds): + """Calculate loss""" param = self.l2_loss(self.param) loss = self.weight_decay * param preds = self.cast(preds, mstype.float32) diff --git a/model_zoo/official/nlp/bert/pretrain_eval.py b/model_zoo/official/nlp/bert/pretrain_eval.py index 5089d88459..fa02ebbcd4 100644 --- a/model_zoo/official/nlp/bert/pretrain_eval.py +++ b/model_zoo/official/nlp/bert/pretrain_eval.py @@ -88,6 +88,7 @@ class BertPretrainEva(nn.Cell): def construct(self, input_ids, input_mask, token_type_id, masked_pos, masked_ids, masked_weights, nsp_label): + """Calculate prediction scores""" bs, _ = self.shape(input_ids) probs = self.bert(input_ids, input_mask, token_type_id, masked_pos) index = self.argmax(probs) diff --git a/model_zoo/official/nlp/bert/run_classifier.py b/model_zoo/official/nlp/bert/run_classifier.py index d2278bbc3c..e9a7e78645 100644 --- a/model_zoo/official/nlp/bert/run_classifier.py +++ b/model_zoo/official/nlp/bert/run_classifier.py @@ -50,7 +50,7 @@ def do_train(dataset=None, network=None, load_checkpoint_path="", save_checkpoin power=optimizer_cfg.AdamWeightDecay.power) params = net_with_loss.trainable_params() decay_params = list(filter(optimizer_cfg.AdamWeightDecay.decay_filter, params)) - other_params = list(filter(lambda x: not cfg.AdamWeightDecay.decay_filter(x), params)) + other_params = list(filter(lambda x: not optimizer_cfg.AdamWeightDecay.decay_filter(x), params)) group_params = [{'params': decay_params, 'weight_decay': optimizer_cfg.AdamWeightDecay.weight_decay}, {'params': other_params, 'weight_decay': 0.0}] @@ -70,7 +70,9 @@ def do_train(dataset=None, network=None, load_checkpoint_path="", save_checkpoin # load checkpoint into network ckpt_config = CheckpointConfig(save_checkpoint_steps=steps_per_epoch, keep_checkpoint_max=1) - ckpoint_cb = ModelCheckpoint(prefix="classifier", directory=save_checkpoint_path, config=ckpt_config) + ckpoint_cb = ModelCheckpoint(prefix="classifier", + directory=None if save_checkpoint_path == "" else save_checkpoint_path, + config=ckpt_config) param_dict = load_checkpoint(load_checkpoint_path) load_param_into_net(network, param_dict) diff --git a/model_zoo/official/nlp/bert/run_ner.py b/model_zoo/official/nlp/bert/run_ner.py index b311950315..933e9b6a70 100644 --- a/model_zoo/official/nlp/bert/run_ner.py +++ b/model_zoo/official/nlp/bert/run_ner.py @@ -52,7 +52,7 @@ def do_train(dataset=None, network=None, load_checkpoint_path="", save_checkpoin power=optimizer_cfg.AdamWeightDecay.power) params = network.trainable_params() decay_params = list(filter(optimizer_cfg.AdamWeightDecay.decay_filter, params)) - other_params = list(filter(lambda x: not cfg.AdamWeightDecay.decay_filter(x), params)) + other_params = list(filter(lambda x: not optimizer_cfg.AdamWeightDecay.decay_filter(x), params)) group_params = [{'params': decay_params, 'weight_decay': optimizer_cfg.AdamWeightDecay.weight_decay}, {'params': other_params, 'weight_decay': 0.0}] optimizer = AdamWeightDecay(group_params, lr_schedule, eps=optimizer_cfg.AdamWeightDecay.eps) @@ -71,7 +71,9 @@ def do_train(dataset=None, network=None, load_checkpoint_path="", save_checkpoin # load checkpoint into network ckpt_config = CheckpointConfig(save_checkpoint_steps=steps_per_epoch, keep_checkpoint_max=1) - ckpoint_cb = ModelCheckpoint(prefix="ner", directory=save_checkpoint_path, config=ckpt_config) + ckpoint_cb = ModelCheckpoint(prefix="ner", + directory=None if save_checkpoint_path == "" else save_checkpoint_path, + config=ckpt_config) param_dict = load_checkpoint(load_checkpoint_path) load_param_into_net(network, param_dict) diff --git a/model_zoo/official/nlp/bert/run_pretrain.py b/model_zoo/official/nlp/bert/run_pretrain.py index 6b4cb1548a..291a784441 100644 --- a/model_zoo/official/nlp/bert/run_pretrain.py +++ b/model_zoo/official/nlp/bert/run_pretrain.py @@ -142,10 +142,11 @@ def run_pretrain(): raise ValueError("Don't support optimizer {}, only support [Lamb, Momentum, AdamWeightDecay]". format(cfg.optimizer)) callback = [TimeMonitor(args_opt.data_sink_steps), LossCallBack()] - if args_opt.enable_save_ckpt == "true": + if args_opt.enable_save_ckpt == "true" and args_opt.device_id % min(8, device_num) == 0: config_ck = CheckpointConfig(save_checkpoint_steps=args_opt.save_checkpoint_steps, keep_checkpoint_max=args_opt.save_checkpoint_num) - ckpoint_cb = ModelCheckpoint(prefix='checkpoint_bert', directory=ckpt_save_dir, config=config_ck) + ckpoint_cb = ModelCheckpoint(prefix='checkpoint_bert', + directory=None if ckpt_save_dir == "" else ckpt_save_dir, config=config_ck) callback.append(ckpoint_cb) if args_opt.load_checkpoint_path: diff --git a/model_zoo/official/nlp/bert/run_squad.py b/model_zoo/official/nlp/bert/run_squad.py index a026408e7c..1b3433c9a2 100644 --- a/model_zoo/official/nlp/bert/run_squad.py +++ b/model_zoo/official/nlp/bert/run_squad.py @@ -52,7 +52,7 @@ def do_train(dataset=None, network=None, load_checkpoint_path="", save_checkpoin power=optimizer_cfg.AdamWeightDecay.power) params = network.trainable_params() decay_params = list(filter(optimizer_cfg.AdamWeightDecay.decay_filter, params)) - other_params = list(filter(lambda x: not cfg.AdamWeightDecay.decay_filter(x), params)) + other_params = list(filter(lambda x: not optimizer_cfg.AdamWeightDecay.decay_filter(x), params)) group_params = [{'params': decay_params, 'weight_decay': optimizer_cfg.AdamWeightDecay.weight_decay}, {'params': other_params, 'weight_decay': 0.0}] @@ -72,7 +72,9 @@ def do_train(dataset=None, network=None, load_checkpoint_path="", save_checkpoin # load checkpoint into network ckpt_config = CheckpointConfig(save_checkpoint_steps=steps_per_epoch, keep_checkpoint_max=1) - ckpoint_cb = ModelCheckpoint(prefix="squad", directory=save_checkpoint_path, config=ckpt_config) + ckpoint_cb = ModelCheckpoint(prefix="squad", + directory=None if save_checkpoint_path == "" else save_checkpoint_path, + config=ckpt_config) param_dict = load_checkpoint(load_checkpoint_path) load_param_into_net(network, param_dict) diff --git a/model_zoo/official/nlp/bert/src/bert_for_finetune.py b/model_zoo/official/nlp/bert/src/bert_for_finetune.py index 5fbf1d81b9..97262b6fae 100644 --- a/model_zoo/official/nlp/bert/src/bert_for_finetune.py +++ b/model_zoo/official/nlp/bert/src/bert_for_finetune.py @@ -99,7 +99,7 @@ class BertFinetuneCell(nn.Cell): token_type_id, label_ids, sens=None): - + """Bert Finetune""" weights = self.weights init = False @@ -195,6 +195,7 @@ class BertSquadCell(nn.Cell): unique_id, is_impossible, sens=None): + """BertSquad""" weights = self.weights init = self.alloc_status() loss = self.network(input_ids, @@ -313,6 +314,7 @@ class BertSquad(nn.Cell): self.squeeze = P.Squeeze(axis=-1) def construct(self, input_ids, input_mask, token_type_id, start_position, end_position, unique_id, is_impossible): + """interface for SQuAD finetuning task""" logits = self.bert(input_ids, input_mask, token_type_id) if self.is_training: unstacked_logits_0 = self.squeeze(logits[:, :, 0:1]) diff --git a/model_zoo/official/nlp/bert/src/bert_for_pre_training.py b/model_zoo/official/nlp/bert/src/bert_for_pre_training.py index 1d12ddaf06..14e00281d0 100644 --- a/model_zoo/official/nlp/bert/src/bert_for_pre_training.py +++ b/model_zoo/official/nlp/bert/src/bert_for_pre_training.py @@ -103,6 +103,7 @@ class GetMaskedLMOutput(nn.Cell): input_tensor, output_weights, positions): + """Get output log_probs""" flat_offsets = self.reshape( self.rng * self.seq_length_tensor, self.shape_flat_offsets) flat_position = self.reshape(positions + flat_offsets, self.last_idx) @@ -248,6 +249,7 @@ class BertNetworkWithLoss(nn.Cell): masked_lm_positions, masked_lm_ids, masked_lm_weights): + """Get pre-training loss""" prediction_scores, seq_relationship_score = \ self.bert(input_ids, input_mask, token_type_id, masked_lm_positions) total_loss = self.loss(prediction_scores, seq_relationship_score, diff --git a/model_zoo/official/nlp/bert/src/bert_model.py b/model_zoo/official/nlp/bert/src/bert_model.py index 8f972f8cec..4199c13b5a 100644 --- a/model_zoo/official/nlp/bert/src/bert_model.py +++ b/model_zoo/official/nlp/bert/src/bert_model.py @@ -137,6 +137,7 @@ class EmbeddingLookup(nn.Cell): self.shape = tuple(embedding_shape) def construct(self, input_ids): + """Get output and embeddings lookup table""" extended_ids = self.expand(input_ids, -1) flat_ids = self.reshape(extended_ids, self.shape_flat) if self.use_one_hot_embeddings: @@ -205,6 +206,7 @@ class EmbeddingPostprocessor(nn.Cell): name='full_position_embeddings') def construct(self, token_type_ids, word_embeddings): + """Postprocessors apply positional and token type embeddings to word embeddings.""" output = word_embeddings if self.use_token_type: flat_ids = self.reshape(token_type_ids, self.shape_flat) @@ -288,6 +290,7 @@ class RelaPosMatrixGenerator(nn.Cell): self.cast = P.Cast() def construct(self): + """Generates matrix of relative positions between inputs.""" range_vec_row_out = self.cast(F.tuple_to_array(F.make_range(self._length)), mstype.int32) range_vec_col_out = self.range_mat(range_vec_row_out, (self._length, -1)) tile_row_out = self.tile(range_vec_row_out, (self._length,)) @@ -342,9 +345,9 @@ class RelaPosEmbeddingsGenerator(nn.Cell): self.matmul = P.BatchMatMul() def construct(self): + """Generate embedding for each relative position of dimension depth.""" relative_positions_matrix_out = self.relative_positions_matrix() - # Generate embedding for each relative position of dimension depth. if self.use_one_hot_embeddings: flat_relative_positions_matrix = self.reshape(relative_positions_matrix_out, (-1,)) one_hot_relative_positions_matrix = self.one_hot( @@ -495,7 +498,7 @@ class BertAttention(nn.Cell): use_one_hot_embeddings=use_one_hot_embeddings) def construct(self, from_tensor, to_tensor, attention_mask): - # reshape 2d/3d input tensors to 2d + """reshape 2d/3d input tensors to 2d""" from_tensor_2d = self.reshape(from_tensor, self.shape_from_2d) to_tensor_2d = self.reshape(to_tensor, self.shape_to_2d) query_out = self.query_layer(from_tensor_2d) @@ -784,6 +787,7 @@ class BertTransformer(nn.Cell): self.out_shape = (batch_size, seq_length, hidden_size) def construct(self, input_tensor, attention_mask): + """Multi-layer bert transformer.""" prev_output = self.reshape(input_tensor, self.shape) all_encoder_layers = () @@ -915,7 +919,7 @@ class BertModel(nn.Cell): self._create_attention_mask_from_input_mask = CreateAttentionMaskFromInputMask(config) def construct(self, input_ids, token_type_ids, input_mask): - + """Bidirectional Encoder Representations from Transformers.""" # embedding if not self.token_type_ids_from_dataset: token_type_ids = self.token_type_ids diff --git a/model_zoo/official/nlp/bert/src/finetune_eval_model.py b/model_zoo/official/nlp/bert/src/finetune_eval_model.py index 047decc377..5cfb202082 100644 --- a/model_zoo/official/nlp/bert/src/finetune_eval_model.py +++ b/model_zoo/official/nlp/bert/src/finetune_eval_model.py @@ -110,6 +110,7 @@ class BertNERModel(nn.Cell): self.origin_shape = (config.batch_size, config.seq_length, self.num_labels) def construct(self, input_ids, input_mask, token_type_id): + """Return the final logits as the results of log_softmax.""" sequence_output, _, _ = \ self.bert(input_ids, token_type_id, input_mask) seq = self.dropout(sequence_output) diff --git a/model_zoo/official/nlp/bert/src/fused_layer_norm.py b/model_zoo/official/nlp/bert/src/fused_layer_norm.py index 5dbe9999ad..2736fdbd57 100644 --- a/model_zoo/official/nlp/bert/src/fused_layer_norm.py +++ b/model_zoo/official/nlp/bert/src/fused_layer_norm.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """fused layernorm""" +import numpy as np from mindspore.ops import operations as P from mindspore.ops import functional as F from mindspore.common.parameter import Parameter @@ -21,7 +22,6 @@ from mindspore.ops.primitive import constexpr import mindspore.common.dtype as mstype from mindspore.nn.cell import Cell -import numpy as np __all__ = ['FusedLayerNorm'] @@ -101,6 +101,7 @@ class FusedLayerNorm(Cell): self.use_batch_norm = use_batch_norm def construct(self, input_x): + """Applies Layer Normalization over a mini-batch of inputs""" if self.use_batch_norm and self.training: ones = P.Fill()(mstype.float32, F.shape(input_x)[:self.begin_norm_axis], 1.0) zeros = P.Fill()(mstype.float32, F.shape(input_x)[:self.begin_norm_axis], 0.0) diff --git a/model_zoo/official/nlp/mass/src/transformer/components.py b/model_zoo/official/nlp/mass/src/transformer/components.py index 2efa1ee757..81db1a345a 100644 --- a/model_zoo/official/nlp/mass/src/transformer/components.py +++ b/model_zoo/official/nlp/mass/src/transformer/components.py @@ -52,6 +52,7 @@ class LayerNorm(nn.Cell): self.get_shape = P.Shape() def construct(self, input_tensor): + """layer norm""" shape = self.get_shape(input_tensor) batch_size = shape[0] max_len = shape[1] diff --git a/model_zoo/official/nlp/tinybert/run_general_distill.py b/model_zoo/official/nlp/tinybert/run_general_distill.py index 50e586f0af..199ee6adf2 100644 --- a/model_zoo/official/nlp/tinybert/run_general_distill.py +++ b/model_zoo/official/nlp/tinybert/run_general_distill.py @@ -99,7 +99,7 @@ def run_general_distill(): power=common_cfg.AdamWeightDecay.power) params = netwithloss.trainable_params() decay_params = list(filter(common_cfg.AdamWeightDecay.decay_filter, params)) - other_params = list(filter(lambda x: not cfg.AdamWeightDecay.decay_filter(x), params)) + other_params = list(filter(lambda x: not common_cfg.AdamWeightDecay.decay_filter(x), params)) group_params = [{'params': decay_params, 'weight_decay': common_cfg.AdamWeightDecay.weight_decay}, {'params': other_params, 'weight_decay': 0.0}, {'order_params': params}] diff --git a/model_zoo/official/nlp/tinybert/run_task_distill.py b/model_zoo/official/nlp/tinybert/run_task_distill.py index 9469c475d2..fd689f141d 100644 --- a/model_zoo/official/nlp/tinybert/run_task_distill.py +++ b/model_zoo/official/nlp/tinybert/run_task_distill.py @@ -107,7 +107,7 @@ def run_predistill(): power=optimizer_cfg.AdamWeightDecay.power) params = netwithloss.trainable_params() decay_params = list(filter(optimizer_cfg.AdamWeightDecay.decay_filter, params)) - other_params = list(filter(lambda x: not cfg.AdamWeightDecay.decay_filter(x), params)) + other_params = list(filter(lambda x: not optimizer_cfg.AdamWeightDecay.decay_filter(x), params)) group_params = [{'params': decay_params, 'weight_decay': optimizer_cfg.AdamWeightDecay.weight_decay}, {'params': other_params, 'weight_decay': 0.0}, {'order_params': params}] @@ -165,7 +165,7 @@ def run_task_distill(ckpt_file): power=optimizer_cfg.AdamWeightDecay.power) params = netwithloss.trainable_params() decay_params = list(filter(optimizer_cfg.AdamWeightDecay.decay_filter, params)) - other_params = list(filter(lambda x: not cfg.AdamWeightDecay.decay_filter(x), params)) + other_params = list(filter(lambda x: not optimizer_cfg.AdamWeightDecay.decay_filter(x), params)) group_params = [{'params': decay_params, 'weight_decay': optimizer_cfg.AdamWeightDecay.weight_decay}, {'params': other_params, 'weight_decay': 0.0}, {'order_params': params}] diff --git a/model_zoo/official/nlp/tinybert/src/fused_layer_norm.py b/model_zoo/official/nlp/tinybert/src/fused_layer_norm.py index d290842c58..7b9fb56227 100644 --- a/model_zoo/official/nlp/tinybert/src/fused_layer_norm.py +++ b/model_zoo/official/nlp/tinybert/src/fused_layer_norm.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """fused layernorm""" +import numpy as np from mindspore.ops import operations as P from mindspore.ops import functional as F from mindspore.common.parameter import Parameter @@ -21,7 +22,6 @@ from mindspore.ops.primitive import constexpr import mindspore.common.dtype as mstype from mindspore.nn.cell import Cell -import numpy as np __all__ = ['FusedLayerNorm'] diff --git a/model_zoo/official/nlp/transformer/src/beam_search.py b/model_zoo/official/nlp/transformer/src/beam_search.py index 9742924a73..5200ee32c3 100644 --- a/model_zoo/official/nlp/transformer/src/beam_search.py +++ b/model_zoo/official/nlp/transformer/src/beam_search.py @@ -241,6 +241,7 @@ class BeamSearchDecoder(nn.Cell): return cur_input_ids, state_log_probs, state_seq, state_finished, state_length def construct(self, enc_states, enc_attention_mask): + """Get beam search result.""" cur_input_ids = self.start_ids # beam search states state_log_probs = self.init_scores diff --git a/model_zoo/official/nlp/transformer/src/transformer_for_train.py b/model_zoo/official/nlp/transformer/src/transformer_for_train.py index 76237bee96..164c9391e9 100644 --- a/model_zoo/official/nlp/transformer/src/transformer_for_train.py +++ b/model_zoo/official/nlp/transformer/src/transformer_for_train.py @@ -55,7 +55,7 @@ class ClipGradients(nn.Cell): grads, clip_type, clip_value): - # return grads + """return grads""" if clip_type != 0 and clip_type != 1: return grads diff --git a/model_zoo/official/nlp/transformer/src/transformer_model.py b/model_zoo/official/nlp/transformer/src/transformer_model.py index fb33f526da..f05757143e 100644 --- a/model_zoo/official/nlp/transformer/src/transformer_model.py +++ b/model_zoo/official/nlp/transformer/src/transformer_model.py @@ -131,6 +131,7 @@ class EmbeddingLookup(nn.Cell): self.shape = P.Shape() def construct(self, input_ids): + """Get a embeddings lookup table with a fixed dictionary and size.""" input_shape = self.shape(input_ids) flat_ids = self.reshape(input_ids, self.shape_flat) @@ -200,6 +201,7 @@ class EmbeddingPostprocessor(nn.Cell): self.shape = P.Shape() def construct(self, word_embeddings): + """Postprocessors apply positional embeddings to word embeddings.""" input_shape = self.shape(word_embeddings) input_len = input_shape[1] @@ -377,7 +379,7 @@ class MultiheadAttention(nn.Cell): self.softmax_cast = P.Cast() def construct(self, from_tensor, to_tensor, attention_mask=None): - # reshape 2d/3d input tensors to 2d + """reshape 2d/3d input tensors to 2d""" from_tensor_2d = self.reshape(from_tensor, self.shape_from_2d) to_tensor_2d = self.reshape(to_tensor, self.shape_to_2d) query_out = self.query_layer(from_tensor_2d) @@ -476,6 +478,7 @@ class SelfAttention(nn.Cell): self.reshape = P.Reshape() self.shape = (-1, hidden_size) def construct(self, input_tensor, memory_tensor, attention_mask): + """Apply self-attention.""" input_tensor = self.reshape(input_tensor, self.shape) memory_tensor = self.reshape(memory_tensor, self.shape) @@ -831,6 +834,7 @@ class CreateAttentionMaskFromInputMask(nn.Cell): self.batch_matmul = P.BatchMatMul() def construct(self, input_mask): + """Create attention mask according to input mask.""" input_shape = self.shape(input_mask) shape_right = (input_shape[0], 1, input_shape[1]) shape_left = input_shape + (1,) @@ -876,6 +880,7 @@ class PredLogProbs(nn.Cell): def construct(self, input_tensor, output_weights): + """Get log probs.""" input_tensor = self.reshape(input_tensor, self.shape_flat_sequence_tensor) input_tensor = self.cast(input_tensor, self.compute_type) output_weights = self.cast(output_weights, self.compute_type) @@ -962,7 +967,10 @@ class TransformerDecoderStep(nn.Cell): self.cast_compute_type = CastWrapper(dst_type=compute_type) def construct(self, input_ids, enc_states, enc_attention_mask): - # input_ids: [batch_size * beam_width] + """ + Multi-layer transformer decoder step. + input_ids: [batch_size * beam_width] + """ # process embedding input_embedding, embedding_tables = self.tfm_embedding_lookup(input_ids) input_embedding = self.tfm_embedding_processor(input_embedding) @@ -1122,6 +1130,7 @@ class TransformerModel(nn.Cell): self.encdec_mask = Tensor(ones, dtype=mstype.float32) def construct(self, source_ids, source_mask, target_ids=None, target_mask=None): + """Transformer with encoder and decoder.""" # process source sentence src_word_embeddings, embedding_tables = self.tfm_embedding_lookup(source_ids) src_embedding_output = self.tfm_embedding_postprocessor_for_encoder(src_word_embeddings) diff --git a/model_zoo/official/nlp/transformer/train.py b/model_zoo/official/nlp/transformer/train.py index f84c4214e3..8b7dc43456 100644 --- a/model_zoo/official/nlp/transformer/train.py +++ b/model_zoo/official/nlp/transformer/train.py @@ -69,6 +69,7 @@ class LossCallBack(Callback): time_stamp_init = True def step_end(self, run_context): + """Monitor the loss in training.""" global time_stamp_first time_stamp_current = get_ms_timestamp() cb_params = run_context.original_args() diff --git a/model_zoo/official/recommend/deepfm/README.md b/model_zoo/official/recommend/deepfm/README.md index 81cb023b97..ab6b117714 100644 --- a/model_zoo/official/recommend/deepfm/README.md +++ b/model_zoo/official/recommend/deepfm/README.md @@ -44,7 +44,7 @@ The overall network architecture of DeepFM is show below: ### Usage -- sh run_train.sh [DEVICE_NUM] [DATASET_PATH] [MINDSPORE_HCCL_CONFIG_PAHT] +- sh run_train.sh [DEVICE_NUM] [DATASET_PATH] [RANK_TABLE_FILE] - python train.py --dataset_path [DATASET_PATH] ### Launch diff --git a/model_zoo/official/recommend/deepfm/scripts/run_distribute_train.sh b/model_zoo/official/recommend/deepfm/scripts/run_distribute_train.sh index 6da44819d7..c8c0f1f809 100644 --- a/model_zoo/official/recommend/deepfm/scripts/run_distribute_train.sh +++ b/model_zoo/official/recommend/deepfm/scripts/run_distribute_train.sh @@ -14,7 +14,7 @@ # limitations under the License. # ============================================================================ echo "Please run the script as: " -echo "sh scripts/run_distribute_train.sh DEVICE_NUM DATASET_PATH MINDSPORE_HCCL_CONFIG_PAHT" +echo "sh scripts/run_distribute_train.sh DEVICE_NUM DATASET_PATH RANK_TABLE_FILE" echo "for example: sh scripts/run_distribute_train.sh 8 /dataset_path /rank_table_8p.json" echo "After running the script, the network runs in the background, The log will be generated in logx/output.log" diff --git a/model_zoo/official/recommend/deepfm/src/callback.py b/model_zoo/official/recommend/deepfm/src/callback.py index fce7b29fa6..fedc3548e0 100644 --- a/model_zoo/official/recommend/deepfm/src/callback.py +++ b/model_zoo/official/recommend/deepfm/src/callback.py @@ -68,6 +68,7 @@ class LossCallBack(Callback): self._per_print_times = per_print_times def step_end(self, run_context): + """Monitor the loss in training.""" cb_params = run_context.original_args() loss = cb_params.net_outputs.asnumpy() cur_step_in_epoch = (cb_params.cur_step_num - 1) % cb_params.batch_num + 1 diff --git a/model_zoo/official/recommend/deepfm/src/dataset.py b/model_zoo/official/recommend/deepfm/src/dataset.py index 4904715220..e023786f42 100644 --- a/model_zoo/official/recommend/deepfm/src/dataset.py +++ b/model_zoo/official/recommend/deepfm/src/dataset.py @@ -19,8 +19,8 @@ import os import math from enum import Enum -import pandas as pd import numpy as np +import pandas as pd import mindspore.dataset.engine as de import mindspore.common.dtype as mstype diff --git a/model_zoo/official/recommend/deepfm/src/deepfm.py b/model_zoo/official/recommend/deepfm/src/deepfm.py index 0fbe3afa49..61dd3b5f85 100644 --- a/model_zoo/official/recommend/deepfm/src/deepfm.py +++ b/model_zoo/official/recommend/deepfm/src/deepfm.py @@ -147,6 +147,7 @@ class DenseLayer(nn.Cell): return act_func def construct(self, x): + """Dense Layer for Deep Layer of DeepFM Model.""" x = self.act_func(x) if self.training: x = self.dropout(x) diff --git a/model_zoo/official/recommend/wide_and_deep/script/run_auto_parallel_train_cluster.sh b/model_zoo/official/recommend/wide_and_deep/script/run_auto_parallel_train_cluster.sh index f3482a4205..495c4fc40d 100644 --- a/model_zoo/official/recommend/wide_and_deep/script/run_auto_parallel_train_cluster.sh +++ b/model_zoo/official/recommend/wide_and_deep/script/run_auto_parallel_train_cluster.sh @@ -28,7 +28,6 @@ EMB_DIM=$5 DATASET=$6 ENV_SH=$7 MODE=$8 -export MINDSPORE_HCCL_CONFIG=$9 export RANK_TABLE_FILE=$9 DEVICE_START=0 # shellcheck source=/dev/null diff --git a/model_zoo/official/recommend/wide_and_deep/src/callbacks.py b/model_zoo/official/recommend/wide_and_deep/src/callbacks.py index 9325292705..d2a2e94427 100644 --- a/model_zoo/official/recommend/wide_and_deep/src/callbacks.py +++ b/model_zoo/official/recommend/wide_and_deep/src/callbacks.py @@ -47,6 +47,7 @@ class LossCallBack(Callback): self.config = config def step_end(self, run_context): + """Monitor the loss in training.""" cb_params = run_context.original_args() wide_loss, deep_loss = cb_params.net_outputs[0].asnumpy(), cb_params.net_outputs[1].asnumpy() cur_step_in_epoch = (cb_params.cur_step_num - 1) % cb_params.batch_num + 1 diff --git a/model_zoo/official/recommend/wide_and_deep/src/wide_and_deep.py b/model_zoo/official/recommend/wide_and_deep/src/wide_and_deep.py index d66cb0772c..b00b40905d 100644 --- a/model_zoo/official/recommend/wide_and_deep/src/wide_and_deep.py +++ b/model_zoo/official/recommend/wide_and_deep/src/wide_and_deep.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """wide and deep model""" +import numpy as np from mindspore import nn from mindspore import Parameter, ParameterTuple import mindspore.common.dtype as mstype @@ -28,7 +29,6 @@ from mindspore.parallel._utils import _get_device_num, _get_parallel_mode, _get_ from mindspore.train.parallel_utils import ParallelMode from mindspore.nn.wrap.grad_reducer import DistributedGradReducer from mindspore.communication.management import get_group_size -import numpy as np np_type = np.float32 ms_type = mstype.float32 @@ -328,20 +328,13 @@ class TrainStepWrap(nn.Cell): self.weights_w = ParameterTuple(weights_w) self.weights_d = ParameterTuple(weights_d) - if host_device_mix and is_auto_parallel: + if (host_device_mix and is_auto_parallel) or parameter_server: self.optimizer_d = LazyAdam( self.weights_d, learning_rate=3.5e-4, eps=1e-8, loss_scale=sens) self.optimizer_w = FTRL(learning_rate=5e-2, params=self.weights_w, l1=1e-8, l2=1e-8, initial_accum=1.0, loss_scale=sens) self.optimizer_w.sparse_opt.add_prim_attr("primitive_target", "CPU") self.optimizer_d.sparse_opt.add_prim_attr("primitive_target", "CPU") - elif parameter_server: - self.optimizer_d = Adam( - self.weights_d, learning_rate=3.5e-4, eps=1e-8, loss_scale=sens) - self.optimizer_w = FTRL(learning_rate=5e-2, params=self.weights_w, - l1=1e-8, l2=1e-8, initial_accum=1.0, loss_scale=sens) - self.optimizer_w.sparse_opt.add_prim_attr("primitive_target", "CPU") - self.optimizer_d.sparse_opt.add_prim_attr("primitive_target", "CPU") else: self.optimizer_d = Adam( self.weights_d, learning_rate=3.5e-4, eps=1e-8, loss_scale=sens) diff --git a/serving/CMakeLists.txt b/serving/CMakeLists.txt index 8b60168228..91a9cd678a 100644 --- a/serving/CMakeLists.txt +++ b/serving/CMakeLists.txt @@ -110,5 +110,5 @@ if (ENABLE_ACL) target_link_libraries(ms_serving ${ALC_LIB_SO}) target_link_libraries(ms_serving jpeg_turbo::jpeg) else () - target_link_libraries(ms_serving inference mindspore_gvar) + target_link_libraries(ms_serving inference) endif () diff --git a/tests/st/ops/ascend/test_bijector/test_scalar_affine.py b/tests/st/ops/ascend/test_bijector/test_scalar_affine.py new file mode 100644 index 0000000000..137f5e0f05 --- /dev/null +++ b/tests/st/ops/ascend/test_bijector/test_scalar_affine.py @@ -0,0 +1,99 @@ +# Copyright 2019 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +"""test cases for scalar affine""" +import numpy as np +import mindspore.context as context +import mindspore.nn as nn +import mindspore.nn.probability.bijector as msb +from mindspore import Tensor +from mindspore import dtype + +context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") + +class Net(nn.Cell): + """ + Test class: forward pass of bijector. + """ + def __init__(self): + super(Net, self).__init__() + self.bijector = msb.ScalarAffine(scale=2.0, shift=1.0) + + def construct(self, x_): + return self.bijector.forward(x_) + +def test_forward(): + forward = Net() + x = np.array([2.0, 3.0, 4.0, 5.0]).astype(np.float32) + ans = forward(Tensor(x, dtype=dtype.float32)) + tol = 1e-6 + expected = 2 * x + 1 + assert (np.abs(ans.asnumpy() - expected) < tol).all() + +class Net1(nn.Cell): + """ + Test class: backward pass of bijector. + """ + def __init__(self): + super(Net1, self).__init__() + self.bijector = msb.ScalarAffine(shift=1.0, scale=2.0) + + def construct(self, x_): + return self.bijector.inverse(x_) + +def test_backward(): + backward = Net1() + x = np.array([2.0, 3.0, 4.0, 5.0]).astype(np.float32) + ans = backward(Tensor(x, dtype=dtype.float32)) + tol = 1e-6 + expected = 0.5 * (x - 1.0) + assert (np.abs(ans.asnumpy() - expected) < tol).all() + +class Net2(nn.Cell): + """ + Test class: Forward Jacobian. + """ + def __init__(self): + super(Net2, self).__init__() + self.bijector = msb.ScalarAffine(shift=1.0, scale=2.0) + + def construct(self, x_): + return self.bijector.forward_log_jacobian(x_) + +def test_forward_jacobian(): + forward_jacobian = Net2() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = forward_jacobian(x) + expected = np.log([2.0, 2.0, 2.0, 2.0]) + tol = 1e-6 + assert (np.abs(ans.asnumpy() - expected) < tol).all() + +class Net3(nn.Cell): + """ + Test class: Backward Jacobian. + """ + def __init__(self): + super(Net3, self).__init__() + self.bijector = msb.ScalarAffine(shift=1.0, scale=2.0) + + def construct(self, x_): + return self.bijector.inverse_log_jacobian(x_) + +def test_backward_jacobian(): + backward_jacobian = Net3() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = backward_jacobian(x) + expected = np.log([0.5, 0.5, 0.5, 0.5]) + tol = 1e-6 + assert (np.abs(ans.asnumpy() - expected) < tol).all() diff --git a/tests/st/ops/ascend/test_bijector/test_softplus.py b/tests/st/ops/ascend/test_bijector/test_softplus.py new file mode 100644 index 0000000000..9bf33aa254 --- /dev/null +++ b/tests/st/ops/ascend/test_bijector/test_softplus.py @@ -0,0 +1,99 @@ +# Copyright 2019 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +"""test cases for scalar affine""" +import numpy as np +import mindspore.context as context +import mindspore.nn as nn +import mindspore.nn.probability.bijector as msb +from mindspore import Tensor +from mindspore import dtype + +context.set_context(device_target="Ascend") + +class Net(nn.Cell): + """ + Test class: forward pass of bijector. + """ + def __init__(self): + super(Net, self).__init__() + self.bijector = msb.Softplus(sharpness=2.0) + + def construct(self, x_): + return self.bijector.forward(x_) + +def test_forward(): + forward = Net() + x = np.array([2.0, 3.0, 4.0, 5.0]).astype(np.float32) + ans = forward(Tensor(x, dtype=dtype.float32)) + expected = np.log(1 + np.exp(2 * x)) * 0.5 + tol = 1e-6 + assert (np.abs(ans.asnumpy() - expected) < tol).all() + +class Net1(nn.Cell): + """ + Test class: backward pass of bijector. + """ + def __init__(self): + super(Net1, self).__init__() + self.bijector = msb.Softplus(sharpness=2.0) + + def construct(self, x_): + return self.bijector.inverse(x_) + +def test_backward(): + backward = Net1() + x = np.array([2.0, 3.0, 4.0, 5.0]).astype(np.float32) + ans = backward(Tensor(x, dtype=dtype.float32)) + expected = np.log(np.exp(2 * x) - 1) * 0.5 + tol = 1e-6 + assert (np.abs(ans.asnumpy() - expected) < tol).all() + +class Net2(nn.Cell): + """ + Test class: Forward Jacobian. + """ + def __init__(self): + super(Net2, self).__init__() + self.bijector = msb.Softplus(sharpness=2.0) + + def construct(self, x_): + return self.bijector.forward_log_jacobian(x_) + +def test_forward_jacobian(): + forward_jacobian = Net2() + x = np.array([2.0, 3.0, 4.0, 5.0]).astype(np.float32) + ans = forward_jacobian(Tensor(x, dtype=dtype.float32)) + expected = np.log(np.exp(2 * x) / (1 + np.exp(2.0 * x))) + tol = 1e-6 + assert (np.abs(ans.asnumpy() - expected) < tol).all() + +class Net3(nn.Cell): + """ + Test class: Backward Jacobian. + """ + def __init__(self): + super(Net3, self).__init__() + self.bijector = msb.Softplus(sharpness=2.0) + + def construct(self, x_): + return self.bijector.inverse_log_jacobian(x_) + +def test_backward_jacobian(): + backward_jacobian = Net3() + x = np.array([2.0, 3.0, 4.0, 5.0]).astype(np.float32) + ans = backward_jacobian(Tensor(x, dtype=dtype.float32)) + expected = np.log(np.exp(2.0 * x) / np.expm1(2.0 * x)) + tol = 1e-6 + assert (np.abs(ans.asnumpy() - expected) < tol).all() diff --git a/tests/st/ops/gpu/test_cast_op.py b/tests/st/ops/gpu/test_cast_op.py index d3c8543101..8fa784d03a 100644 --- a/tests/st/ops/gpu/test_cast_op.py +++ b/tests/st/ops/gpu/test_cast_op.py @@ -359,3 +359,122 @@ def test_cast18(): assert type0 == 'float32' type1 = output[1].asnumpy().dtype assert type1 == 'float16' + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_cast19(): + x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int8)) + t0 = mstype.bool_ + x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int16)) + t1 = mstype.bool_ + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + net = Net(t0, t1) + output = net(x0, x1) + type0 = output[0].asnumpy().dtype + assert type0 == 'bool' + type1 = output[1].asnumpy().dtype + assert type1 == 'bool' + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_cast20(): + x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int64)) + t0 = mstype.bool_ + x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float16)) + t1 = mstype.bool_ + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + net = Net(t0, t1) + output = net(x0, x1) + type0 = output[0].asnumpy().dtype + assert type0 == 'bool' + type1 = output[1].asnumpy().dtype + assert type1 == 'bool' + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_cast21(): + x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float32)) + t0 = mstype.bool_ + x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64)) + t1 = mstype.bool_ + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + net = Net(t0, t1) + output = net(x0, x1) + type0 = output[0].asnumpy().dtype + assert type0 == 'bool' + type1 = output[1].asnumpy().dtype + assert type1 == 'bool' + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_cast22(): + x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.uint8)) + t0 = mstype.bool_ + x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.int32)) + t1 = mstype.bool_ + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + net = Net(t0, t1) + output = net(x0, x1) + type0 = output[0].asnumpy().dtype + assert type0 == 'bool' + type1 = output[1].asnumpy().dtype + assert type1 == 'bool' + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_cast23(): + x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64)) + t0 = mstype.float32 + x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64)) + t1 = mstype.float16 + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + net = Net(t0, t1) + output = net(x0, x1) + type0 = output[0].asnumpy().dtype + assert type0 == 'float32' + type1 = output[1].asnumpy().dtype + assert type1 == 'float16' + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_cast24(): + x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64)) + t0 = mstype.int64 + x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64)) + t1 = mstype.int32 + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + net = Net(t0, t1) + output = net(x0, x1) + type0 = output[0].asnumpy().dtype + assert type0 == 'int64' + type1 = output[1].asnumpy().dtype + assert type1 == 'int32' + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_cast25(): + x0 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64)) + t0 = mstype.int16 + x1 = Tensor(np.arange(24).reshape((4, 3, 2)).astype(np.float64)) + t1 = mstype.int8 + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + net = Net(t0, t1) + output = net(x0, x1) + type0 = output[0].asnumpy().dtype + assert type0 == 'int16' + type1 = output[1].asnumpy().dtype + assert type1 == 'int8' diff --git a/tests/st/ops/gpu/test_div_op.py b/tests/st/ops/gpu/test_div_op.py new file mode 100644 index 0000000000..03438e9305 --- /dev/null +++ b/tests/st/ops/gpu/test_div_op.py @@ -0,0 +1,116 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ + +import numpy as np +import pytest + +import mindspore.context as context +import mindspore.nn as nn +from mindspore import Tensor +from mindspore.ops import operations as P + +class NetDiv(nn.Cell): + def __init__(self): + super(NetDiv, self).__init__() + self.div = P.Div() + + def construct(self, x, y): + return self.div(x, y) + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_div(): + x0_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32) + y0_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32) + x1_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32) + y1_np = np.random.randint(1, 5, (2, 1, 4, 4)).astype(np.float32) + x2_np = np.random.randint(1, 5, (2, 1, 1, 4)).astype(np.float32) + y2_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32) + x3_np = np.random.randint(1, 5, 1).astype(np.float32) + y3_np = np.random.randint(1, 5, 1).astype(np.float32) + x4_np = np.array(768).astype(np.float32) + y4_np = np.array(3072.5).astype(np.float32) + x5_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float16) + y5_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float16) + x6_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.int32) + y6_np = np.random.randint(1, 5, (2, 1, 4, 4)).astype(np.int32) + + x0 = Tensor(x0_np) + y0 = Tensor(y0_np) + x1 = Tensor(x1_np) + y1 = Tensor(y1_np) + x2 = Tensor(x2_np) + y2 = Tensor(y2_np) + x3 = Tensor(x3_np) + y3 = Tensor(y3_np) + x4 = Tensor(x4_np) + y4 = Tensor(y4_np) + x5 = Tensor(x5_np) + y5 = Tensor(y5_np) + x6 = Tensor(x6_np) + y6 = Tensor(y6_np) + + context.set_context(mode=context.GRAPH_MODE, device_target='GPU') + div = NetDiv() + output0 = div(x0, y0) + expect0 = np.divide(x0_np, y0_np) + diff0 = output0.asnumpy() - expect0 + error0 = np.ones(shape=expect0.shape) * 1.0e-5 + assert np.all(diff0 < error0) + assert output0.shape == expect0.shape + + output1 = div(x1, y1) + expect1 = np.divide(x1_np, y1_np) + diff1 = output1.asnumpy() - expect1 + error1 = np.ones(shape=expect1.shape) * 1.0e-5 + assert np.all(diff1 < error1) + assert output1.shape == expect1.shape + + output2 = div(x2, y2) + expect2 = np.divide(x2_np, y2_np) + diff2 = output2.asnumpy() - expect2 + error2 = np.ones(shape=expect2.shape) * 1.0e-5 + assert np.all(diff2 < error2) + assert output2.shape == expect2.shape + + context.set_context(mode=context.PYNATIVE_MODE, device_target='GPU') + output3 = div(x3, y3) + expect3 = np.divide(x3_np, y3_np) + diff3 = output3.asnumpy() - expect3 + error3 = np.ones(shape=expect3.shape) * 1.0e-5 + assert np.all(diff3 < error3) + assert output3.shape == expect3.shape + + output4 = div(x4, y4) + expect4 = np.divide(x4_np, y4_np) + diff4 = output4.asnumpy() - expect4 + error4 = np.ones(shape=expect4.shape) * 1.0e-5 + assert np.all(diff4 < error4) + assert output4.shape == expect4.shape + + output5 = div(x5, y5) + expect5 = np.divide(x5_np, y5_np) + diff5 = output5.asnumpy() - expect5 + error5 = np.ones(shape=expect5.shape) * 1.0e-5 + assert np.all(diff5 < error5) + assert output5.shape == expect5.shape + + output6 = div(x6, y6) + expect6 = np.divide(x6_np, y6_np) + diff6 = output6.asnumpy() - expect6 + error6 = np.ones(shape=expect6.shape) * 1.0e-5 + assert np.all(diff6 < error6) + assert output6.shape == expect6.shape diff --git a/tests/st/ops/gpu/test_dropout.py b/tests/st/ops/gpu/test_dropout.py new file mode 100644 index 0000000000..9a9f9d5b09 --- /dev/null +++ b/tests/st/ops/gpu/test_dropout.py @@ -0,0 +1,54 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +import numpy as np +import pytest + +import mindspore.nn as nn +from mindspore import Tensor +from mindspore.ops import operations as P + + +class Net(nn.Cell): + def __init__(self, keep_prob): + super(Net, self).__init__() + self.drop = P.Dropout(keep_prob) + + def construct(self, x_): + return self.drop(x_) + + +@pytest.mark.level0 +@pytest.mark.platform_x86_gpu_training +@pytest.mark.env_onecard +def test_dropout(): + x_shape = [32, 16, 2, 5] + x = np.ones(x_shape).astype(np.float32) + keep_prob = 0.4 + dropout = Net(keep_prob) + tx = Tensor(x) + output, mask = dropout(tx) + # check output + output_np = output.asnumpy() + elem_count = x.size + nonzero_count = np.count_nonzero(output_np) + assert (elem_count * (keep_prob - 0.1)) < nonzero_count < (elem_count * (keep_prob + 0.1)) + output_sum = np.sum(output_np) + x_sum = np.sum(x) + assert abs(output_sum - x_sum)/x_sum < 0.1 + # check mask + mask_np = mask.asnumpy() + mask_sum = np.sum(mask_np) + assert np.count_nonzero(mask_np) == nonzero_count + assert abs(mask_sum - nonzero_count)/nonzero_count < 0.1 diff --git a/tests/st/ops/gpu/test_floordiv_op.py b/tests/st/ops/gpu/test_floordiv_op.py index dc7d76807f..26c32f9213 100644 --- a/tests/st/ops/gpu/test_floordiv_op.py +++ b/tests/st/ops/gpu/test_floordiv_op.py @@ -37,8 +37,8 @@ def test_floor_div(): y0_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32) x1_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32) y1_np = np.random.randint(1, 5, (2, 1, 4, 4)).astype(np.float32) - x2_np = np.random.randint(1, 5, (2, 1, 1, 4)).astype(np.float32) - y2_np = np.random.randint(1, 5, (2, 3, 4, 4)).astype(np.float32) + x2_np = np.random.randint(1, 5, (2, 1, 1, 4, 9)).astype(np.float32) + y2_np = np.random.randint(1, 5, (2, 3, 4, 4, 9)).astype(np.float32) x3_np = np.random.randint(1, 5, 1).astype(np.float32) y3_np = np.random.randint(1, 5, 1).astype(np.float32) x4_np = np.array(768).astype(np.float32) diff --git a/tests/st/ops/gpu/test_reduce_mean_op.py b/tests/st/ops/gpu/test_reduce_mean_op.py index 867d7e8a33..7033449b5a 100644 --- a/tests/st/ops/gpu/test_reduce_mean_op.py +++ b/tests/st/ops/gpu/test_reduce_mean_op.py @@ -70,7 +70,7 @@ x11 = np.random.rand(1, 1, 1, 1).astype(np.float32) axis11 = (0, 1, 2, 3) keep_dims11 = False -x12 = np.random.rand(2, 3, 4, 4).astype(np.float32) +x12 = np.random.rand(2, 3, 4, 4, 5, 6).astype(np.float32) axis12 = -2 keep_dims12 = False diff --git a/tests/ut/cpp/CMakeLists.txt b/tests/ut/cpp/CMakeLists.txt index eddf8f66ba..81d2b8a14b 100644 --- a/tests/ut/cpp/CMakeLists.txt +++ b/tests/ut/cpp/CMakeLists.txt @@ -61,6 +61,7 @@ file(GLOB_RECURSE MINDSPORE_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../../../mindspore/core/abstract/*.cc" "../../../mindspore/core/ir/*.cc" "../../../mindspore/core/utils/*.cc" + "../../../mindspore/core/c_ops/*.cc" "../../../mindspore/ccsrc/common/*.cc" "../../../mindspore/ccsrc/utils/*.cc" "../../../mindspore/ccsrc/pipeline/jit/parse/*.cc" @@ -180,12 +181,12 @@ if (ENABLE_GE) endif() if (CMAKE_SYSTEM_NAME MATCHES "Linux") - target_link_libraries(ut_tests PRIVATE mindspore::gtest mindspore_gvar ${PYTHON_LIBRARIES} pthread util dl) + target_link_libraries(ut_tests PRIVATE mindspore::gtest ${PYTHON_LIBRARIES} pthread util dl) if (ENABLE_MINDDATA) target_link_libraries(ut_tests PRIVATE _c_dataengine _c_mindrecord) endif() else() - target_link_libraries(ut_tests PRIVATE mindspore::gtest mindspore_gvar ${PYTHON_LIBRARIES}) + target_link_libraries(ut_tests PRIVATE mindspore::gtest ${PYTHON_LIBRARIES}) endif() if (USE_GLOG) target_link_libraries(ut_tests PRIVATE mindspore::glog) diff --git a/tests/ut/cpp/dataset/CMakeLists.txt b/tests/ut/cpp/dataset/CMakeLists.txt index bc6d772ad8..f33a6ca49d 100644 --- a/tests/ut/cpp/dataset/CMakeLists.txt +++ b/tests/ut/cpp/dataset/CMakeLists.txt @@ -4,6 +4,7 @@ SET(DE_UT_SRCS common/common.cc common/cvop_common.cc common/bboxop_common.cc + auto_contrast_op_test.cc batch_op_test.cc bit_functions_test.cc storage_container_test.cc @@ -22,11 +23,13 @@ SET(DE_UT_SRCS cut_out_op_test.cc datatype_test.cc decode_op_test.cc + equalize_op_test.cc execution_tree_test.cc global_context_test.cc main_test.cc map_op_test.cc mind_record_op_test.cc + mixup_batch_op_test.cc memory_pool_test.cc normalize_op_test.cc one_hot_op_test.cc @@ -35,6 +38,7 @@ SET(DE_UT_SRCS path_test.cc project_op_test.cc queue_test.cc + random_affine_op_test.cc random_crop_op_test.cc random_crop_with_bbox_op_test.cc random_crop_decode_resize_op_test.cc @@ -88,7 +92,14 @@ SET(DE_UT_SRCS concatenate_op_test.cc cyclic_array_test.cc perf_data_test.cc - c_api_test.cc + c_api_samplers_test.cc + c_api_transforms_test.cc + c_api_dataset_ops_test.cc + c_api_dataset_cifar_test.cc + c_api_dataset_coco_test.cc + c_api_dataset_voc_test.cc + c_api_datasets_test.cc + c_api_dataset_iterator_test.cc tensor_op_fusion_pass_test.cc sliding_window_op_test.cc epoch_ctrl_op_test.cc diff --git a/tests/ut/cpp/dataset/auto_contrast_op_test.cc b/tests/ut/cpp/dataset/auto_contrast_op_test.cc new file mode 100644 index 0000000000..b62d5a99c0 --- /dev/null +++ b/tests/ut/cpp/dataset/auto_contrast_op_test.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "common/common.h" +#include "common/cvop_common.h" +#include "minddata/dataset/kernels/image/auto_contrast_op.h" +#include "minddata/dataset/core/cv_tensor.h" +#include "utils/log_adapter.h" + +using namespace mindspore::dataset; +using mindspore::LogStream; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::MsLogLevel::INFO; + +class MindDataTestAutoContrastOp : public UT::CVOP::CVOpCommon { + public: + MindDataTestAutoContrastOp() : CVOpCommon() {} +}; + +TEST_F(MindDataTestAutoContrastOp, TestOp1) { + MS_LOG(INFO) << "Doing testAutoContrastOp."; + + std::shared_ptr output_tensor; + std::unique_ptr op(new AutoContrastOp(1.0, {0, 255})); + EXPECT_TRUE(op->OneToOne()); + Status s = op->Compute(input_tensor_, &output_tensor); + EXPECT_TRUE(s.IsOk()); + CheckImageShapeAndData(output_tensor, kAutoContrast); +} diff --git a/tests/ut/cpp/dataset/c_api_dataset_cifar_test.cc b/tests/ut/cpp/dataset/c_api_dataset_cifar_test.cc new file mode 100644 index 0000000000..7f248c5f1a --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_dataset_cifar_test.cc @@ -0,0 +1,135 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::TensorShape; +using mindspore::dataset::TensorImpl; +using mindspore::dataset::DataType; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; +using mindspore::dataset::dsize_t; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + +TEST_F(MindDataTestPipeline, TestCifar10Dataset) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar10Dataset."; + + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + EXPECT_NE(row.find("image"), row.end()); + EXPECT_NE(row.find("label"), row.end()); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 10); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCifar10DatasetFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar10DatasetFail1."; + + // Create a Cifar10 Dataset + std::shared_ptr ds = Cifar10("", RandomSampler(false, 10)); + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestCifar100Dataset) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar100Dataset."; + + // Create a Cifar100 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar100Data/"; + std::shared_ptr ds = Cifar100(folder_path, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + EXPECT_NE(row.find("image"), row.end()); + EXPECT_NE(row.find("coarse_label"), row.end()); + EXPECT_NE(row.find("fine_label"), row.end()); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 10); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCifar100DatasetFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar100DatasetFail1."; + + // Create a Cifar100 Dataset + std::shared_ptr ds = Cifar100("", RandomSampler(false, 10)); + EXPECT_EQ(ds, nullptr); +} diff --git a/tests/ut/cpp/dataset/c_api_dataset_coco_test.cc b/tests/ut/cpp/dataset/c_api_dataset_coco_test.cc new file mode 100644 index 0000000000..b4986c53cc --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_dataset_coco_test.cc @@ -0,0 +1,316 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::TensorShape; +using mindspore::dataset::TensorImpl; +using mindspore::dataset::DataType; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; +using mindspore::dataset::dsize_t; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + +TEST_F(MindDataTestPipeline, TestCocoDetection) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDetection."; + // Create a Coco Dataset + std::string folder_path = datasets_root_path_ + "/testCOCO/train"; + std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; + + std::shared_ptr ds = Coco(folder_path, annotation_file, "Detection", false, SequentialSampler(0, 6)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + std::string expect_file[] = {"000000391895", "000000318219", "000000554625", "000000574769", "000000060623", + "000000309022"}; + std::vector> expect_bbox_vector = {{10.0, 10.0, 10.0, 10.0, 70.0, 70.0, 70.0, 70.0}, + {20.0, 20.0, 20.0, 20.0, 80.0, 80.0, 80.0, 80.0}, + {30.0, 30.0, 30.0, 30.0}, {40.0, 40.0, 40.0, 40.0}, + {50.0, 50.0, 50.0, 50.0}, {60.0, 60.0, 60.0, 60.0}}; + std::vector> expect_catagoryid_list = {{1, 7}, {2, 8}, {3}, {4}, {5}, {6}}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto bbox = row["bbox"]; + auto category_id = row["category_id"]; + std::shared_ptr expect_image; + Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); + EXPECT_EQ(*image, *expect_image); + std::shared_ptr expect_bbox; + dsize_t bbox_num = static_cast(expect_bbox_vector[i].size() / 4); + Tensor::CreateFromVector(expect_bbox_vector[i], TensorShape({bbox_num, 4}), &expect_bbox); + EXPECT_EQ(*bbox, *expect_bbox); + std::shared_ptr expect_categoryid; + Tensor::CreateFromVector(expect_catagoryid_list[i], TensorShape({bbox_num, 1}), &expect_categoryid); + EXPECT_EQ(*category_id, *expect_categoryid); + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 6); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCocoStuff) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoStuff."; + // Create a Coco Dataset + std::string folder_path = datasets_root_path_ + "/testCOCO/train"; + std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; + + std::shared_ptr ds = Coco(folder_path, annotation_file, "Stuff", false, SequentialSampler(0, 6)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + std::string expect_file[] = {"000000391895", "000000318219", "000000554625", "000000574769", "000000060623", + "000000309022"}; + std::vector> expect_segmentation_vector = + {{10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, + 70.0, 72.0, 73.0, 74.0, 75.0, -1.0, -1.0, -1.0, -1.0, -1.0}, + {20.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, + 10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, -1.0}, + {40.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 40.0, 41.0, 42.0}, + {50.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0}, + {60.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0}, + {60.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0}}; + std::vector> expect_size = {{2, 10}, {2, 11}, {1, 12}, {1, 13}, {1, 14}, {2, 7}}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto segmentation = row["segmentation"]; + auto iscrowd = row["iscrowd"]; + std::shared_ptr expect_image; + Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); + EXPECT_EQ(*image, *expect_image); + std::shared_ptr expect_segmentation; + Tensor::CreateFromVector(expect_segmentation_vector[i], TensorShape(expect_size[i]), &expect_segmentation); + EXPECT_EQ(*segmentation, *expect_segmentation); + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 6); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCocoKeypoint) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoKeypoint."; + // Create a Coco Dataset + std::string folder_path = datasets_root_path_ + "/testCOCO/train"; + std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/key_point.json"; + + std::shared_ptr ds = Coco(folder_path, annotation_file, "Keypoint", false, SequentialSampler(0, 2)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + std::string expect_file[] = {"000000391895", "000000318219"}; + std::vector> expect_keypoint_vector = + {{368.0, 61.0, 1.0, 369.0, 52.0, 2.0, 0.0, 0.0, 0.0, 382.0, 48.0, 2.0, 0.0, 0.0, 0.0, 368.0, 84.0, 2.0, 435.0, + 81.0, 2.0, 362.0, 125.0, 2.0, 446.0, 125.0, 2.0, 360.0, 153.0, 2.0, 0.0, 0.0, 0.0, 397.0, 167.0, 1.0, 439.0, + 166.0, 1.0, 369.0, 193.0, 2.0, 461.0, 234.0, 2.0, 361.0, 246.0, 2.0, 474.0, 287.0, 2.0}, + {244.0, 139.0, 2.0, 0.0, 0.0, 0.0, 226.0, 118.0, 2.0, 0.0, 0.0, 0.0, 154.0, 159.0, 2.0, 143.0, 261.0, 2.0, 135.0, + 312.0, 2.0, 271.0, 423.0, 2.0, 184.0, 530.0, 2.0, 261.0, 280.0, 2.0, 347.0, 592.0, 2.0, 0.0, 0.0, 0.0, 123.0, + 596.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}; + std::vector> expect_size = {{1, 51}, {1, 51}}; + std::vector> expect_num_keypoints_list = {{14}, {10}}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto keypoints = row["keypoints"]; + auto num_keypoints = row["num_keypoints"]; + std::shared_ptr expect_image; + Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); + EXPECT_EQ(*image, *expect_image); + std::shared_ptr expect_keypoints; + dsize_t keypoints_size = expect_size[i][0]; + Tensor::CreateFromVector(expect_keypoint_vector[i], TensorShape(expect_size[i]), &expect_keypoints); + EXPECT_EQ(*keypoints, *expect_keypoints); + std::shared_ptr expect_num_keypoints; + Tensor::CreateFromVector(expect_num_keypoints_list[i], TensorShape({keypoints_size, 1}), &expect_num_keypoints); + EXPECT_EQ(*num_keypoints, *expect_num_keypoints); + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCocoPanoptic) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoPanoptic."; + // Create a Coco Dataset + std::string folder_path = datasets_root_path_ + "/testCOCO/train"; + std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/panoptic.json"; + + std::shared_ptr ds = Coco(folder_path, annotation_file, "Panoptic", false, SequentialSampler(0, 2)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + std::string expect_file[] = {"000000391895", "000000574769"}; + std::vector> expect_bbox_vector = {{472, 173, 36, 48, 340, 22, 154, 301, 486, 183, 30, 35}, + {103, 133, 229, 422, 243, 175, 93, 164}}; + std::vector> expect_categoryid_vector = {{1, 1, 2}, {1, 3}}; + std::vector> expect_iscrowd_vector = {{0, 0, 0}, {0, 0}}; + std::vector> expect_area_vector = {{705, 14062, 626}, {43102, 6079}}; + std::vector> expect_size = {{3, 4}, {2, 4}}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto bbox = row["bbox"]; + auto category_id = row["category_id"]; + auto iscrowd = row["iscrowd"]; + auto area = row["area"]; + std::shared_ptr expect_image; + Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); + EXPECT_EQ(*image, *expect_image); + std::shared_ptr expect_bbox; + dsize_t bbox_size = expect_size[i][0]; + Tensor::CreateFromVector(expect_bbox_vector[i], TensorShape(expect_size[i]), &expect_bbox); + EXPECT_EQ(*bbox, *expect_bbox); + std::shared_ptr expect_categoryid; + Tensor::CreateFromVector(expect_categoryid_vector[i], TensorShape({bbox_size, 1}), &expect_categoryid); + EXPECT_EQ(*category_id, *expect_categoryid); + std::shared_ptr expect_iscrowd; + Tensor::CreateFromVector(expect_iscrowd_vector[i], TensorShape({bbox_size, 1}), &expect_iscrowd); + EXPECT_EQ(*iscrowd, *expect_iscrowd); + std::shared_ptr expect_area; + Tensor::CreateFromVector(expect_area_vector[i], TensorShape({bbox_size, 1}), &expect_area); + EXPECT_EQ(*area, *expect_area); + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCocoDefault) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDetection."; + // Create a Coco Dataset + std::string folder_path = datasets_root_path_ + "/testCOCO/train"; + std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; + + std::shared_ptr ds = Coco(folder_path, annotation_file); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto bbox = row["bbox"]; + auto category_id = row["category_id"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + MS_LOG(INFO) << "Tensor bbox shape: " << bbox->shape(); + MS_LOG(INFO) << "Tensor category_id shape: " << category_id->shape(); + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 6); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCocoException) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDetection."; + // Create a Coco Dataset + std::string folder_path = datasets_root_path_ + "/testCOCO/train"; + std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; + std::string invalid_folder_path = "./NotExist"; + std::string invalid_annotation_file = "./NotExistFile"; + + std::shared_ptr ds = Coco(invalid_folder_path, annotation_file); + EXPECT_EQ(ds, nullptr); + + std::shared_ptr ds1 = Coco(folder_path, invalid_annotation_file); + EXPECT_EQ(ds1, nullptr); + + std::shared_ptr ds2 = Coco(folder_path, annotation_file, "valid_mode"); + EXPECT_EQ(ds2, nullptr); +} diff --git a/tests/ut/cpp/dataset/c_api_dataset_iterator_test.cc b/tests/ut/cpp/dataset/c_api_dataset_iterator_test.cc new file mode 100644 index 0000000000..a6fbe7a623 --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_dataset_iterator_test.cc @@ -0,0 +1,223 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::TensorShape; +using mindspore::dataset::TensorImpl; +using mindspore::dataset::DataType; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; +using mindspore::dataset::dsize_t; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + + +TEST_F(MindDataTestPipeline, TestIteratorOneColumn) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestIteratorOneColumn."; + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 4)); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 2; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // Only select "image" column and drop others + std::vector columns = {"image"}; + std::shared_ptr iter = ds->CreateIterator(columns); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::vector> row; + iter->GetNextRow(&row); + TensorShape expect({2, 28, 28, 1}); + + uint64_t i = 0; + while (row.size() != 0) { + for (auto &v : row) { + MS_LOG(INFO) << "image shape:" << v->shape(); + EXPECT_EQ(expect, v->shape()); + } + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestIteratorTwoColumns) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestIteratorTwoColumns."; + // Create a VOC Dataset + std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; + std::shared_ptr ds = VOC(folder_path, "Detection", "train", {}, false, SequentialSampler(0, 4)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // Only select "image" and "bbox" column + std::vector columns = {"image", "bbox"}; + std::shared_ptr iter = ds->CreateIterator(columns); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::vector> row; + iter->GetNextRow(&row); + std::vector expect = {TensorShape({173673}), TensorShape({1, 4}), + TensorShape({173673}), TensorShape({1, 4}), + TensorShape({147025}), TensorShape({1, 4}), + TensorShape({211653}), TensorShape({1, 4})}; + + uint64_t i = 0; + uint64_t j = 0; + while (row.size() != 0) { + MS_LOG(INFO) << "row[0]:" << row[0]->shape() << ", row[1]:" << row[1]->shape(); + EXPECT_EQ(2, row.size()); + EXPECT_EQ(expect[j++], row[0]->shape()); + EXPECT_EQ(expect[j++], row[1]->shape()); + iter->GetNextRow(&row); + i++; + j = (j == expect.size()) ? 0 : j; + } + + EXPECT_EQ(i, 8); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestIteratorEmptyColumn) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestIteratorEmptyColumn."; + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 5)); + EXPECT_NE(ds, nullptr); + + // Create a Rename operation on ds + ds = ds->Rename({"image", "label"}, {"col1", "col2"}); + EXPECT_NE(ds, nullptr); + + // No columns are specified, use all columns + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::vector> row; + iter->GetNextRow(&row); + TensorShape expect0({32, 32, 3}); + TensorShape expect1({}); + + uint64_t i = 0; + while (row.size() != 0) { + MS_LOG(INFO) << "row[0]:" << row[0]->shape() << ", row[1]:" << row[1]->shape(); + EXPECT_EQ(expect0, row[0]->shape()); + EXPECT_EQ(expect1, row[1]->shape()); + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 5); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestIteratorReOrder) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestIteratorReOrder."; + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, SequentialSampler(false, 4)); + EXPECT_NE(ds, nullptr); + + // Create a Take operation on ds + ds = ds->Take(2); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // Reorder "image" and "label" column + std::vector columns = {"label", "image"}; + std::shared_ptr iter = ds->CreateIterator(columns); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::vector> row; + iter->GetNextRow(&row); + TensorShape expect0({32, 32, 3}); + TensorShape expect1({}); + + // Check if we will catch "label" before "image" in row + std::vector expect = {"label", "image"}; + uint64_t i = 0; + while (row.size() != 0) { + MS_LOG(INFO) << "row[0]:" << row[0]->shape() << ", row[1]:" << row[1]->shape(); + EXPECT_EQ(expect1, row[0]->shape()); + EXPECT_EQ(expect0, row[1]->shape()); + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestIteratorWrongColumn) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestIteratorOneColumn."; + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 4)); + EXPECT_NE(ds, nullptr); + + // Pass wrong column name + std::vector columns = {"digital"}; + std::shared_ptr iter = ds->CreateIterator(columns); + EXPECT_EQ(iter, nullptr); +} diff --git a/tests/ut/cpp/dataset/c_api_dataset_ops_test.cc b/tests/ut/cpp/dataset/c_api_dataset_ops_test.cc new file mode 100644 index 0000000000..23751cccee --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_dataset_ops_test.cc @@ -0,0 +1,865 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::TensorShape; +using mindspore::dataset::TensorImpl; +using mindspore::dataset::DataType; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; +using mindspore::dataset::dsize_t; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + +TEST_F(MindDataTestPipeline, TestBatchAndRepeat) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestBatchAndRepeat."; + + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 2; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 10); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestTensorOpsAndMap) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTensorOpsAndMap."; + + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 20)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr resize_op = vision::Resize({30, 30}); + EXPECT_NE(resize_op, nullptr); + + std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); + EXPECT_NE(center_crop_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({resize_op, center_crop_op}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 40); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestImageFolderBatchAndRepeat) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestImageFolderBatchAndRepeat."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 2; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 10); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestShuffleDataset) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestShuffleDataset."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Shuffle operation on ds + int32_t shuffle_size = 10; + ds = ds->Shuffle(shuffle_size); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 2; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 10); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestSkipDataset) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSkipDataset."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Skip operation on ds + int32_t count = 3; + ds = ds->Skip(count); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + MS_LOG(INFO) << "Number of rows: " << i; + + // Expect 10-3=7 rows + EXPECT_EQ(i, 7); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestSkipDatasetError1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSkipDatasetError1."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Skip operation on ds with invalid count input + int32_t count = -1; + ds = ds->Skip(count); + // Expect nullptr for invalid input skip_count + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestTakeDatasetDefault) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTakeDatasetDefault."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 7)); + EXPECT_NE(ds, nullptr); + + // Create a Take operation on ds, dafault count = -1 + ds = ds->Take(); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + MS_LOG(INFO) << "Number of rows: " << i; + + // Expect 7 rows + EXPECT_EQ(i, 7); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestTakeDatasetNormal) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTakeDatasetNormal."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 8)); + EXPECT_NE(ds, nullptr); + + // Create a Take operation on ds + ds = ds->Take(5); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + MS_LOG(INFO) << "Number of rows: " << i; + + // Expect 5 rows + EXPECT_EQ(i, 5); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestTakeDatasetError1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTakeDatasetError1."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Take operation on ds with invalid count input + int32_t count = -5; + ds = ds->Take(count); + // Expect nullptr for invalid input take_count + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestProjectMap) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestProjectMap."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_vertical_flip_op = vision::RandomVerticalFlip(0.5); + EXPECT_NE(random_vertical_flip_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({random_vertical_flip_op}, {}, {}, {"image", "label"}); + EXPECT_NE(ds, nullptr); + + // Create a Project operation on ds + std::vector column_project = {"image"}; + ds = ds->Project(column_project); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + + +TEST_F(MindDataTestPipeline, TestProjectMapAutoInjection) { + MS_LOG(INFO) << "Doing MindDataTestPipeline.TestProjectMapAutoInjection"; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr resize_op = vision::Resize({30, 30}); + EXPECT_NE(resize_op, nullptr); + + // Create a Map operation on ds + // {"image"} is the project columns. This will trigger auto injection of ProjectOp after MapOp. + ds = ds->Map({resize_op}, {}, {}, {"image"}); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // 'label' is dropped during the project op + EXPECT_EQ(row.find("label"), row.end()); + // 'image' column should still exist + EXPECT_NE(row.find("image"), row.end()); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + EXPECT_EQ(image->shape()[0], 30); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestZipSuccess) { + // Testing the member zip() function + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipSuccess."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Project operation on ds + std::vector column_project = {"image"}; + ds = ds->Project(column_project); + EXPECT_NE(ds, nullptr); + + // Create an ImageFolder Dataset + std::shared_ptr ds1 = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds1, nullptr); + + // Create a Rename operation on ds (so that the 3 datasets we are going to zip have distinct column names) + ds1 = ds1->Rename({"image", "label"}, {"col1", "col2"}); + EXPECT_NE(ds1, nullptr); + + folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds2 = Cifar10(folder_path, RandomSampler(false, 10)); + EXPECT_NE(ds2, nullptr); + + // Create a Project operation on ds + column_project = {"label"}; + ds2 = ds2->Project(column_project); + EXPECT_NE(ds2, nullptr); + + // Create a Zip operation on the datasets + ds = ds->Zip({ds1, ds2}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // Check zipped column names + EXPECT_EQ(row.size(), 4); + EXPECT_NE(row.find("image"), row.end()); + EXPECT_NE(row.find("label"), row.end()); + EXPECT_NE(row.find("col1"), row.end()); + EXPECT_NE(row.find("col2"), row.end()); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 10); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestZipSuccess2) { + // Testing the static zip() function + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipSuccess2."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 9)); + EXPECT_NE(ds, nullptr); + std::shared_ptr ds2 = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds2, nullptr); + + // Create a Rename operation on ds (so that the 2 datasets we are going to zip have distinct column names) + ds = ds->Rename({"image", "label"}, {"col1", "col2"}); + EXPECT_NE(ds, nullptr); + + // Create a Zip operation on the datasets + ds = Zip({ds, ds2}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // Check zipped column names + EXPECT_EQ(row.size(), 4); + EXPECT_NE(row.find("image"), row.end()); + EXPECT_NE(row.find("label"), row.end()); + EXPECT_NE(row.find("col1"), row.end()); + EXPECT_NE(row.find("col2"), row.end()); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 9); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestZipFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipFail."; + // We expect this test to fail because we are the both datasets we are zipping have "image" and "label" columns + // and zip doesn't accept datasets with same column names + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create an ImageFolder Dataset + std::shared_ptr ds1 = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds1, nullptr); + + // Create a Zip operation on the datasets + ds = Zip({ds, ds1}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_EQ(iter, nullptr); +} + +TEST_F(MindDataTestPipeline, TestZipFail2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipFail2."; + // This case is expected to fail because the input dataset is empty. + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Zip operation on the datasets + // Input dataset to zip is empty + ds = Zip({}); + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestRenameSuccess) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRenameSuccess."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create a Rename operation on ds + ds = ds->Rename({"image", "label"}, {"col1", "col2"}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + EXPECT_NE(row.find("col1"), row.end()); + EXPECT_NE(row.find("col2"), row.end()); + EXPECT_EQ(row.find("image"), row.end()); + EXPECT_EQ(row.find("label"), row.end()); + + while (row.size() != 0) { + i++; + auto image = row["col1"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestRenameFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRenameFail."; + // We expect this test to fail because input and output in Rename are not the same size + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create a Rename operation on ds + ds = ds->Rename({"image", "label"}, {"col2"}); + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestConcatSuccess) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatSuccess."; + + // Create an ImageFolder Dataset + // Column names: {"image", "label"} + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Cifar10 Dataset + // Column names: {"image", "label"} + folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds2 = Cifar10(folder_path, RandomSampler(false, 9)); + EXPECT_NE(ds2, nullptr); + + // Create a Project operation on ds + ds = ds->Project({"image"}); + EXPECT_NE(ds, nullptr); + ds2 = ds2->Project({"image"}); + EXPECT_NE(ds, nullptr); + + // Create a Concat operation on the ds + ds = ds->Concat({ds2}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 19); + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestConcatSuccess2) { + // Test "+" operator to concat two datasets + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatSuccess2."; + + // Create an ImageFolder Dataset + // Column names: {"image", "label"} + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Cifar10 Dataset + // Column names: {"image", "label"} + folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds2 = Cifar10(folder_path, RandomSampler(false, 9)); + EXPECT_NE(ds2, nullptr); + + // Create a Project operation on ds + ds = ds->Project({"image"}); + EXPECT_NE(ds, nullptr); + ds2 = ds2->Project({"image"}); + EXPECT_NE(ds, nullptr); + + // Create a Concat operation on the ds + ds = ds + ds2; + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 19); + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestConcatFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatFail1."; + // This case is expected to fail because the input column names of concatenated datasets are not the same + + // Create an ImageFolder Dataset + // Column names: {"image", "label"} + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + std::shared_ptr ds2 = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Rename operation on ds + ds2 = ds2->Rename({"image", "label"}, {"col1", "col2"}); + EXPECT_NE(ds, nullptr); + + // Create a Project operation on the ds + // Name of datasets to concat doesn't not match + ds = ds->Concat({ds2}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_EQ(iter, nullptr); +} + +TEST_F(MindDataTestPipeline, TestConcatFail2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatFail2."; + // This case is expected to fail because the input dataset is empty. + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Project operation on the ds + // Input dataset to concat is empty + ds = ds->Concat({}); + EXPECT_EQ(ds, nullptr); +} diff --git a/tests/ut/cpp/dataset/c_api_dataset_voc_test.cc b/tests/ut/cpp/dataset/c_api_dataset_voc_test.cc new file mode 100644 index 0000000000..68c2555743 --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_dataset_voc_test.cc @@ -0,0 +1,221 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" +#include "minddata/dataset/engine/datasetops/source/voc_op.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::TensorShape; +using mindspore::dataset::TensorImpl; +using mindspore::dataset::DataType; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; +using mindspore::dataset::dsize_t; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + +TEST_F(MindDataTestPipeline, TestVOCSegmentation) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCSegmentation."; + + // Create a VOC Dataset + std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; + std::shared_ptr ds = VOC(folder_path, "Segmentation", "train", {}, false, SequentialSampler(0, 3)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // Check if VOCOp read correct images/targets + using Tensor = mindspore::dataset::Tensor; + std::string expect_file[] = {"32", "33", "39", "32", "33", "39"}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto target = row["target"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + MS_LOG(INFO) << "Tensor target shape: " << target->shape(); + + std::shared_ptr expect_image; + Tensor::CreateFromFile(folder_path + "/JPEGImages/" + expect_file[i] + ".jpg", &expect_image); + EXPECT_EQ(*image, *expect_image); + + std::shared_ptr expect_target; + Tensor::CreateFromFile(folder_path + "/SegmentationClass/" + expect_file[i] + ".png", &expect_target); + EXPECT_EQ(*target, *expect_target); + + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 6); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestVOCSegmentationError1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCSegmentationError1."; + + // Create a VOC Dataset + std::map class_index; + class_index["car"] = 0; + std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; + std::shared_ptr ds = VOC(folder_path, "Segmentation", "train", class_index, false, RandomSampler(false, 6)); + + // Expect nullptr for segmentation task with class_index + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestVOCInvalidTaskOrMode) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCInvalidTaskOrMode."; + + // Create a VOC Dataset + std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; + std::shared_ptr ds_1 = VOC(folder_path, "Classification", "train", {}, false, SequentialSampler(0, 3)); + // Expect nullptr for invalid task + EXPECT_EQ(ds_1, nullptr); + + std::shared_ptr ds_2 = VOC(folder_path, "Segmentation", "validation", {}, false, RandomSampler(false, 4)); + // Expect nullptr for invalid mode + EXPECT_EQ(ds_2, nullptr); +} + +TEST_F(MindDataTestPipeline, TestVOCDetection) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCDetection."; + + // Create a VOC Dataset + std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; + std::shared_ptr ds = VOC(folder_path, "Detection", "train", {}, false, SequentialSampler(0, 4)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // Check if VOCOp read correct images/labels + std::string expect_file[] = {"15", "32", "33", "39"}; + uint32_t expect_num[] = {5, 5, 4, 3}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto label = row["label"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + MS_LOG(INFO) << "Tensor label shape: " << label->shape(); + + std::shared_ptr expect_image; + Tensor::CreateFromFile(folder_path + "/JPEGImages/" + expect_file[i] + ".jpg", &expect_image); + EXPECT_EQ(*image, *expect_image); + + std::shared_ptr expect_label; + Tensor::CreateFromMemory(TensorShape({1, 1}), DataType(DataType::DE_UINT32), nullptr, &expect_label); + expect_label->SetItemAt({0, 0}, expect_num[i]); + EXPECT_EQ(*label, *expect_label); + + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 4); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestVOCClassIndex) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCClassIndex."; + + // Create a VOC Dataset + std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; + std::map class_index; + class_index["car"] = 0; + class_index["cat"] = 1; + class_index["train"] = 9; + + std::shared_ptr ds = VOC(folder_path, "Detection", "train", class_index, false, SequentialSampler(0, 6)); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // Check if VOCOp read correct labels + // When we provide class_index, label of ["car","cat","train"] become [0,1,9] + std::shared_ptr expect_label; + Tensor::CreateFromMemory(TensorShape({1, 1}), DataType(DataType::DE_UINT32), nullptr, &expect_label); + + uint32_t expect[] = {9, 9, 9, 1, 1, 0}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto label = row["label"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + MS_LOG(INFO) << "Tensor label shape: " << label->shape(); + expect_label->SetItemAt({0, 0}, expect[i]); + EXPECT_EQ(*label, *expect_label); + + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 6); + + // Manually terminate the pipeline + iter->Stop(); +} diff --git a/tests/ut/cpp/dataset/c_api_datasets_test.cc b/tests/ut/cpp/dataset/c_api_datasets_test.cc new file mode 100644 index 0000000000..4b21e1f048 --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_datasets_test.cc @@ -0,0 +1,160 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::TensorShape; +using mindspore::dataset::TensorImpl; +using mindspore::dataset::DataType; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; +using mindspore::dataset::dsize_t; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + +TEST_F(MindDataTestPipeline, TestMnistFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMnistFail1."; + + // Create a Mnist Dataset + std::shared_ptr ds = Mnist("", RandomSampler(false, 10)); + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestImageFolderFail1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestImageFolderFail1."; + + // Create an ImageFolder Dataset + std::shared_ptr ds = ImageFolder("", true, nullptr); + EXPECT_EQ(ds, nullptr); +} + +TEST_F(MindDataTestPipeline, TestCelebADataset) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCelebADataset."; + + // Create a CelebA Dataset + std::string folder_path = datasets_root_path_ + "/testCelebAData/"; + std::shared_ptr ds = CelebA(folder_path, "all", SequentialSampler(0, 2), false, {}); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // Check if CelebAOp read correct images/attr + std::string expect_file[] = {"1.JPEG", "2.jpg"}; + std::vector> expect_attr_vector = + {{0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, + 1, 0, 0, 1}, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 1}}; + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto attr = row["attr"]; + + std::shared_ptr expect_image; + Tensor::CreateFromFile(folder_path + expect_file[i], &expect_image); + EXPECT_EQ(*image, *expect_image); + + std::shared_ptr expect_attr; + Tensor::CreateFromVector(expect_attr_vector[i], TensorShape({40}), &expect_attr); + EXPECT_EQ(*attr, *expect_attr); + + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCelebADefault) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCelebADefault."; + + // Create a CelebA Dataset + std::string folder_path = datasets_root_path_ + "/testCelebAData/"; + std::shared_ptr ds = CelebA(folder_path); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + // Check if CelebAOp read correct images/attr + uint64_t i = 0; + while (row.size() != 0) { + auto image = row["image"]; + auto attr = row["attr"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + MS_LOG(INFO) << "Tensor attr shape: " << attr->shape(); + + iter->GetNextRow(&row); + i++; + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCelebAException) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCelebAException."; + + // Create a CelebA Dataset + std::string folder_path = datasets_root_path_ + "/testCelebAData/"; + std::string invalid_folder_path = "./testNotExist"; + std::string invalid_dataset_type = "invalid_type"; + std::shared_ptr ds = CelebA(invalid_folder_path); + EXPECT_EQ(ds, nullptr); + std::shared_ptr ds1 = CelebA(folder_path, invalid_dataset_type); + EXPECT_EQ(ds1, nullptr); +} diff --git a/tests/ut/cpp/dataset/c_api_samplers_test.cc b/tests/ut/cpp/dataset/c_api_samplers_test.cc new file mode 100644 index 0000000000..78a81184f3 --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_samplers_test.cc @@ -0,0 +1,115 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + +TEST_F(MindDataTestPipeline, TestImageFolderWithSamplers) { + std::shared_ptr sampl = DistributedSampler(2, 1); + EXPECT_NE(sampl, nullptr); + + sampl = PKSampler(3); + EXPECT_NE(sampl, nullptr); + + sampl = RandomSampler(false, 12); + EXPECT_NE(sampl, nullptr); + + sampl = SequentialSampler(0, 12); + EXPECT_NE(sampl, nullptr); + + std::vector weights = {0.9, 0.8, 0.68, 0.7, 0.71, 0.6, 0.5, 0.4, 0.3, 0.5, 0.2, 0.1}; + sampl = WeightedRandomSampler(weights, 12); + EXPECT_NE(sampl, nullptr); + + std::vector indices = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}; + sampl = SubsetRandomSampler(indices); + EXPECT_NE(sampl, nullptr); + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, false, sampl); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 2; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 12); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestSamplersMoveParameters) { + std::vector indices = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}; + std::shared_ptr sampl1 = SubsetRandomSampler(indices); + EXPECT_FALSE(indices.empty()); + EXPECT_NE(sampl1->Build(), nullptr); + std::shared_ptr sampl2 = SubsetRandomSampler(std::move(indices)); + EXPECT_TRUE(indices.empty()); + EXPECT_NE(sampl2->Build(), nullptr); +} diff --git a/tests/ut/cpp/dataset/c_api_test.cc b/tests/ut/cpp/dataset/c_api_test.cc deleted file mode 100644 index 11e84f7de4..0000000000 --- a/tests/ut/cpp/dataset/c_api_test.cc +++ /dev/null @@ -1,1937 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * 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. - */ -#include -#include -#include -#include -#include - -#include "utils/log_adapter.h" -#include "utils/ms_utils.h" -#include "common/common.h" -#include "gtest/gtest.h" -#include "securec.h" -#include "minddata/dataset/include/datasets.h" -#include "minddata/dataset/include/status.h" -#include "minddata/dataset/include/transforms.h" -#include "minddata/dataset/include/iterator.h" -#include "minddata/dataset/core/constants.h" -#include "minddata/dataset/core/tensor_shape.h" -#include "minddata/dataset/core/tensor.h" -#include "minddata/dataset/include/samplers.h" -#include "minddata/dataset/engine/datasetops/source/voc_op.h" - - -using namespace mindspore::dataset::api; -using mindspore::MsLogLevel::ERROR; -using mindspore::ExceptionType::NoExceptionType; -using mindspore::LogStream; -using mindspore::dataset::Tensor; -using mindspore::dataset::TensorShape; -using mindspore::dataset::TensorImpl; -using mindspore::dataset::DataType; -using mindspore::dataset::Status; -using mindspore::dataset::BorderType; -using mindspore::dataset::dsize_t; - - -class MindDataTestPipeline : public UT::DatasetOpTesting { - protected: -}; - - -TEST_F(MindDataTestPipeline, TestBatchAndRepeat) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestBatchAndRepeat."; - - // Create a Mnist Dataset - std::string folder_path = datasets_root_path_ + "/testMnistData/"; - std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 2; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestMnistFail1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestMnistFail1."; - - // Create a Mnist Dataset - std::shared_ptr ds = Mnist("", RandomSampler(false, 10)); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestTensorOpsAndMap) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTensorOpsAndMap."; - - // Create a Mnist Dataset - std::string folder_path = datasets_root_path_ + "/testMnistData/"; - std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 20)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr resize_op = vision::Resize({30, 30}); - EXPECT_NE(resize_op, nullptr); - - std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); - EXPECT_NE(center_crop_op, nullptr); - - // Create a Map operation on ds - ds = ds->Map({resize_op, center_crop_op}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 40); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestUniformAugWithOps) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestUniformAugWithOps."; - - // Create a Mnist Dataset - std::string folder_path = datasets_root_path_ + "/testMnistData/"; - std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 20)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 1; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr resize_op = vision::Resize({30, 30}); - EXPECT_NE(resize_op, nullptr); - - std::shared_ptr random_crop_op = vision::RandomCrop({28, 28}); - EXPECT_NE(random_crop_op, nullptr); - - std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); - EXPECT_NE(center_crop_op, nullptr); - - std::shared_ptr uniform_aug_op = vision::UniformAugment({random_crop_op, center_crop_op}, 2); - EXPECT_NE(uniform_aug_op, nullptr); - - // Create a Map operation on ds - ds = ds->Map({resize_op, uniform_aug_op}); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestRandomFlip) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomFlip."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr random_vertical_flip_op = vision::RandomVerticalFlip(0.5); - EXPECT_NE(random_vertical_flip_op, nullptr); - - std::shared_ptr random_horizontal_flip_op = vision::RandomHorizontalFlip(0.5); - EXPECT_NE(random_horizontal_flip_op, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_vertical_flip_op, random_horizontal_flip_op}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestImageFolderBatchAndRepeat) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestImageFolderBatchAndRepeat."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 2; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestImageFolderFail1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestImageFolderFail1."; - - // Create an ImageFolder Dataset - std::shared_ptr ds = ImageFolder("", true, nullptr); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestImageFolderWithSamplers) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestImageFolderWithSamplers."; - - std::shared_ptr sampl = DistributedSampler(2, 1); - EXPECT_NE(sampl, nullptr); - - sampl = PKSampler(3); - EXPECT_NE(sampl, nullptr); - - sampl = RandomSampler(false, 12); - EXPECT_NE(sampl, nullptr); - - sampl = SequentialSampler(0, 12); - EXPECT_NE(sampl, nullptr); - - std::vector weights = {0.9, 0.8, 0.68, 0.7, 0.71, 0.6, 0.5, 0.4, 0.3, 0.5, 0.2, 0.1}; - sampl = WeightedRandomSampler(weights, 12); - EXPECT_NE(sampl, nullptr); - - std::vector indices = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}; - sampl = SubsetRandomSampler(indices); - EXPECT_NE(sampl, nullptr); - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, false, sampl); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 2; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 12); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestSamplersMoveParameters) { - std::vector indices = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}; - std::shared_ptr sampl1 = SubsetRandomSampler(indices); - EXPECT_FALSE(indices.empty()); - EXPECT_NE(sampl1->Build(), nullptr); - std::shared_ptr sampl2 = SubsetRandomSampler(std::move(indices)); - EXPECT_TRUE(indices.empty()); - EXPECT_NE(sampl2->Build(), nullptr); -} - -TEST_F(MindDataTestPipeline, TestPad) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestPad."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr pad_op1 = vision::Pad({1, 2, 3, 4}, {0}, BorderType::kSymmetric); - EXPECT_NE(pad_op1, nullptr); - - std::shared_ptr pad_op2 = vision::Pad({1}, {1, 1, 1}, BorderType::kEdge); - EXPECT_NE(pad_op2, nullptr); - - std::shared_ptr pad_op3 = vision::Pad({1, 4}); - EXPECT_NE(pad_op3, nullptr); - - // Create a Map operation on ds - ds = ds->Map({pad_op1, pad_op2, pad_op3}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCutOut) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCutOut."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr cut_out1 = vision::CutOut(30, 5); - EXPECT_NE(cut_out1, nullptr); - - std::shared_ptr cut_out2 = vision::CutOut(30); - EXPECT_NE(cut_out2, nullptr); - - // Create a Map operation on ds - ds = ds->Map({cut_out1, cut_out2}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestNormalize) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestNormalize."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr normalize = vision::Normalize({121.0, 115.0, 100.0}, {70.0, 68.0, 71.0}); - EXPECT_NE(normalize, nullptr); - - // Create a Map operation on ds - ds = ds->Map({normalize}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestDecode) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestDecode."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, false, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr decode = vision::Decode(true); - EXPECT_NE(decode, nullptr); - - // Create a Map operation on ds - ds = ds->Map({decode}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestShuffleDataset) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestShuffleDataset."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Shuffle operation on ds - int32_t shuffle_size = 10; - ds = ds->Shuffle(shuffle_size); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 2; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestSkipDataset) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSkipDataset."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Skip operation on ds - int32_t count = 3; - ds = ds->Skip(count); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - MS_LOG(INFO) << "Number of rows: " << i; - - // Expect 10-3=7 rows - EXPECT_EQ(i, 7); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestSkipDatasetError1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestSkipDatasetError1."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Skip operation on ds with invalid count input - int32_t count = -1; - ds = ds->Skip(count); - // Expect nullptr for invalid input skip_count - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestTakeDatasetDefault) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTakeDatasetDefault."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 7)); - EXPECT_NE(ds, nullptr); - - // Create a Take operation on ds, dafault count = -1 - ds = ds->Take(); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - MS_LOG(INFO) << "Number of rows: " << i; - - // Expect 7 rows - EXPECT_EQ(i, 7); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestTakeDatasetNormal) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTakeDatasetNormal."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 8)); - EXPECT_NE(ds, nullptr); - - // Create a Take operation on ds - ds = ds->Take(5); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - MS_LOG(INFO) << "Number of rows: " << i; - - // Expect 5 rows - EXPECT_EQ(i, 5); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestTakeDatasetError1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestTakeDatasetError1."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Take operation on ds with invalid count input - int32_t count = -5; - ds = ds->Take(count); - // Expect nullptr for invalid input take_count - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestCifar10Dataset) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar10Dataset."; - - // Create a Cifar10 Dataset - std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - EXPECT_NE(row.find("image"), row.end()); - EXPECT_NE(row.find("label"), row.end()); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCifar10DatasetFail1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar10DatasetFail1."; - - // Create a Cifar10 Dataset - std::shared_ptr ds = Cifar10("", RandomSampler(false, 10)); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestCifar100Dataset) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar100Dataset."; - - // Create a Cifar100 Dataset - std::string folder_path = datasets_root_path_ + "/testCifar100Data/"; - std::shared_ptr ds = Cifar100(folder_path, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - EXPECT_NE(row.find("image"), row.end()); - EXPECT_NE(row.find("coarse_label"), row.end()); - EXPECT_NE(row.find("fine_label"), row.end()); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCifar100DatasetFail1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCifar100DatasetFail1."; - - // Create a Cifar100 Dataset - std::shared_ptr ds = Cifar100("", RandomSampler(false, 10)); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestRandomColorAdjust) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomColorAdjust."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr random_color_adjust1 = vision::RandomColorAdjust({1.0}, {0.0}, {0.5}, {0.5}); - EXPECT_NE(random_color_adjust1, nullptr); - - std::shared_ptr random_color_adjust2 = vision::RandomColorAdjust({1.0, 1.0}, {0.0, 0.0}, {0.5, 0.5}, - {0.5, 0.5}); - EXPECT_NE(random_color_adjust2, nullptr); - - std::shared_ptr random_color_adjust3 = vision::RandomColorAdjust({0.5, 1.0}, {0.0, 0.5}, {0.25, 0.5}, - {0.25, 0.5}); - EXPECT_NE(random_color_adjust3, nullptr); - - std::shared_ptr random_color_adjust4 = vision::RandomColorAdjust(); - EXPECT_NE(random_color_adjust4, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_color_adjust1, random_color_adjust2, random_color_adjust3, random_color_adjust4}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestRandomRotation) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomRotation."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr random_rotation_op = vision::RandomRotation({-180, 180}); - EXPECT_NE(random_rotation_op, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_rotation_op}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestProjectMap) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestProjectMap."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create objects for the tensor ops - std::shared_ptr random_vertical_flip_op = vision::RandomVerticalFlip(0.5); - EXPECT_NE(random_vertical_flip_op, nullptr); - - // Create a Map operation on ds - ds = ds->Map({random_vertical_flip_op}, {}, {}, {"image", "label"}); - EXPECT_NE(ds, nullptr); - - // Create a Project operation on ds - std::vector column_project = {"image"}; - ds = ds->Project(column_project); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestZipSuccess) { - // Testing the member zip() function - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipSuccess."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Project operation on ds - std::vector column_project = {"image"}; - ds = ds->Project(column_project); - EXPECT_NE(ds, nullptr); - - // Create an ImageFolder Dataset - std::shared_ptr ds1 = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds1, nullptr); - - // Create a Rename operation on ds (so that the 3 datasets we are going to zip have distinct column names) - ds1 = ds1->Rename({"image", "label"}, {"col1", "col2"}); - EXPECT_NE(ds1, nullptr); - - folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds2 = Cifar10(folder_path, RandomSampler(false, 10)); - EXPECT_NE(ds2, nullptr); - - // Create a Project operation on ds - column_project = {"label"}; - ds2 = ds2->Project(column_project); - EXPECT_NE(ds2, nullptr); - - // Create a Zip operation on the datasets - ds = ds->Zip({ds1, ds2}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - // Check zipped column names - EXPECT_EQ(row.size(), 4); - EXPECT_NE(row.find("image"), row.end()); - EXPECT_NE(row.find("label"), row.end()); - EXPECT_NE(row.find("col1"), row.end()); - EXPECT_NE(row.find("col2"), row.end()); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 10); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestZipSuccess2) { - // Testing the static zip() function - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipSuccess2."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 9)); - EXPECT_NE(ds, nullptr); - std::shared_ptr ds2 = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds2, nullptr); - - // Create a Rename operation on ds (so that the 2 datasets we are going to zip have distinct column names) - ds = ds->Rename({"image", "label"}, {"col1", "col2"}); - EXPECT_NE(ds, nullptr); - - // Create a Zip operation on the datasets - ds = Zip({ds, ds2}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - // Check zipped column names - EXPECT_EQ(row.size(), 4); - EXPECT_NE(row.find("image"), row.end()); - EXPECT_NE(row.find("label"), row.end()); - EXPECT_NE(row.find("col1"), row.end()); - EXPECT_NE(row.find("col2"), row.end()); - - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 9); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestZipFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipFail."; - // We expect this test to fail because we are the both datasets we are zipping have "image" and "label" columns - // and zip doesn't accept datasets with same column names - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create an ImageFolder Dataset - std::shared_ptr ds1 = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds1, nullptr); - - // Create a Zip operation on the datasets - ds = Zip({ds, ds1}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_EQ(iter, nullptr); -} - -TEST_F(MindDataTestPipeline, TestZipFail2) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestZipFail2."; - // This case is expected to fail because the input dataset is empty. - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Zip operation on the datasets - // Input dataset to zip is empty - ds = Zip({}); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestRenameSuccess) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRenameSuccess."; - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create a Rename operation on ds - ds = ds->Rename({"image", "label"}, {"col1", "col2"}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - EXPECT_NE(row.find("col1"), row.end()); - EXPECT_NE(row.find("col2"), row.end()); - EXPECT_EQ(row.find("image"), row.end()); - EXPECT_EQ(row.find("label"), row.end()); - - while (row.size() != 0) { - i++; - auto image = row["col1"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 20); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestRenameFail) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRenameFail."; - // We expect this test to fail because input and output in Rename are not the same size - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create a Rename operation on ds - ds = ds->Rename({"image", "label"}, {"col2"}); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestVOCSegmentation) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCSegmentation."; - - // Create a VOC Dataset - std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; - std::shared_ptr ds = VOC(folder_path, "Segmentation", "train", {}, false, SequentialSampler(0, 3)); - EXPECT_NE(ds, nullptr); - - // Create a Repeat operation on ds - int32_t repeat_num = 2; - ds = ds->Repeat(repeat_num); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - // Check if VOCOp read correct images/targets - using Tensor = mindspore::dataset::Tensor; - std::string expect_file[] = {"32", "33", "39", "32", "33", "39"}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto target = row["target"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - MS_LOG(INFO) << "Tensor target shape: " << target->shape(); - - std::shared_ptr expect_image; - Tensor::CreateFromFile(folder_path + "/JPEGImages/" + expect_file[i] + ".jpg", &expect_image); - EXPECT_EQ(*image, *expect_image); - - std::shared_ptr expect_target; - Tensor::CreateFromFile(folder_path + "/SegmentationClass/" + expect_file[i] + ".png", &expect_target); - EXPECT_EQ(*target, *expect_target); - - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 6); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestVOCSegmentationError1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCSegmentationError1."; - - // Create a VOC Dataset - std::map class_index; - class_index["car"] = 0; - std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; - std::shared_ptr ds = VOC(folder_path, "Segmentation", "train", class_index, false, RandomSampler(false, 6)); - - // Expect nullptr for segmentation task with class_index - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestVOCInvalidTaskOrMode) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCInvalidTaskOrMode."; - - // Create a VOC Dataset - std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; - std::shared_ptr ds_1 = VOC(folder_path, "Classification", "train", {}, false, SequentialSampler(0, 3)); - // Expect nullptr for invalid task - EXPECT_EQ(ds_1, nullptr); - - std::shared_ptr ds_2 = VOC(folder_path, "Segmentation", "validation", {}, false, RandomSampler(false, 4)); - // Expect nullptr for invalid mode - EXPECT_EQ(ds_2, nullptr); -} - -TEST_F(MindDataTestPipeline, TestVOCDetection) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCDetection."; - - // Create a VOC Dataset - std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; - std::shared_ptr ds = VOC(folder_path, "Detection", "train", {}, false, SequentialSampler(0, 4)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - // Check if VOCOp read correct images/labels - std::string expect_file[] = {"15", "32", "33", "39"}; - uint32_t expect_num[] = {5, 5, 4, 3}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto label = row["label"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - MS_LOG(INFO) << "Tensor label shape: " << label->shape(); - - std::shared_ptr expect_image; - Tensor::CreateFromFile(folder_path + "/JPEGImages/" + expect_file[i] + ".jpg", &expect_image); - EXPECT_EQ(*image, *expect_image); - - std::shared_ptr expect_label; - Tensor::CreateFromMemory(TensorShape({1, 1}), DataType(DataType::DE_UINT32), nullptr, &expect_label); - expect_label->SetItemAt({0, 0}, expect_num[i]); - EXPECT_EQ(*label, *expect_label); - - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 4); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestVOCClassIndex) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestVOCClassIndex."; - - // Create a VOC Dataset - std::string folder_path = datasets_root_path_ + "/testVOC2012_2"; - std::map class_index; - class_index["car"] = 0; - class_index["cat"] = 1; - class_index["train"] = 9; - - std::shared_ptr ds = VOC(folder_path, "Detection", "train", class_index, false, SequentialSampler(0, 6)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - // Check if VOCOp read correct labels - // When we provide class_index, label of ["car","cat","train"] become [0,1,9] - std::shared_ptr expect_label; - Tensor::CreateFromMemory(TensorShape({1, 1}), DataType(DataType::DE_UINT32), nullptr, &expect_label); - - uint32_t expect[] = {9, 9, 9, 1, 1, 0}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto label = row["label"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - MS_LOG(INFO) << "Tensor label shape: " << label->shape(); - expect_label->SetItemAt({0, 0}, expect[i]); - EXPECT_EQ(*label, *expect_label); - - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 6); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCocoDetection) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDetection."; - // Create a Coco Dataset - std::string folder_path = datasets_root_path_ + "/testCOCO/train"; - std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; - - std::shared_ptr ds = Coco(folder_path, annotation_file, "Detection", false, SequentialSampler(0, 6)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - std::string expect_file[] = {"000000391895", "000000318219", "000000554625", "000000574769", "000000060623", - "000000309022"}; - std::vector> expect_bbox_vector = {{10.0, 10.0, 10.0, 10.0, 70.0, 70.0, 70.0, 70.0}, - {20.0, 20.0, 20.0, 20.0, 80.0, 80.0, 80.0, 80.0}, - {30.0, 30.0, 30.0, 30.0}, {40.0, 40.0, 40.0, 40.0}, - {50.0, 50.0, 50.0, 50.0}, {60.0, 60.0, 60.0, 60.0}}; - std::vector> expect_catagoryid_list = {{1, 7}, {2, 8}, {3}, {4}, {5}, {6}}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto bbox = row["bbox"]; - auto category_id = row["category_id"]; - std::shared_ptr expect_image; - Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); - EXPECT_EQ(*image, *expect_image); - std::shared_ptr expect_bbox; - dsize_t bbox_num = static_cast(expect_bbox_vector[i].size() / 4); - Tensor::CreateFromVector(expect_bbox_vector[i], TensorShape({bbox_num, 4}), &expect_bbox); - EXPECT_EQ(*bbox, *expect_bbox); - std::shared_ptr expect_categoryid; - Tensor::CreateFromVector(expect_catagoryid_list[i], TensorShape({bbox_num, 1}), &expect_categoryid); - EXPECT_EQ(*category_id, *expect_categoryid); - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 6); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCocoStuff) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoStuff."; - // Create a Coco Dataset - std::string folder_path = datasets_root_path_ + "/testCOCO/train"; - std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; - - std::shared_ptr ds = Coco(folder_path, annotation_file, "Stuff", false, SequentialSampler(0, 6)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - std::string expect_file[] = {"000000391895", "000000318219", "000000554625", "000000574769", "000000060623", - "000000309022"}; - std::vector> expect_segmentation_vector = - {{10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, - 70.0, 72.0, 73.0, 74.0, 75.0, -1.0, -1.0, -1.0, -1.0, -1.0}, - {20.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, - 10.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, -1.0}, - {40.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 40.0, 41.0, 42.0}, - {50.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0, 59.0, 60.0, 61.0, 62.0, 63.0}, - {60.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0}, - {60.0, 62.0, 63.0, 64.0, 65.0, 66.0, 67.0, 68.0, 69.0, 70.0, 71.0, 72.0, 73.0, 74.0}}; - std::vector> expect_size = {{2, 10}, {2, 11}, {1, 12}, {1, 13}, {1, 14}, {2, 7}}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto segmentation = row["segmentation"]; - auto iscrowd = row["iscrowd"]; - std::shared_ptr expect_image; - Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); - EXPECT_EQ(*image, *expect_image); - std::shared_ptr expect_segmentation; - Tensor::CreateFromVector(expect_segmentation_vector[i], TensorShape(expect_size[i]), &expect_segmentation); - EXPECT_EQ(*segmentation, *expect_segmentation); - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 6); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCocoKeypoint) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoKeypoint."; - // Create a Coco Dataset - std::string folder_path = datasets_root_path_ + "/testCOCO/train"; - std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/key_point.json"; - - std::shared_ptr ds = Coco(folder_path, annotation_file, "Keypoint", false, SequentialSampler(0, 2)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - std::string expect_file[] = {"000000391895", "000000318219"}; - std::vector> expect_keypoint_vector = - {{368.0, 61.0, 1.0, 369.0, 52.0, 2.0, 0.0, 0.0, 0.0, 382.0, 48.0, 2.0, 0.0, 0.0, 0.0, 368.0, 84.0, 2.0, 435.0, - 81.0, 2.0, 362.0, 125.0, 2.0, 446.0, 125.0, 2.0, 360.0, 153.0, 2.0, 0.0, 0.0, 0.0, 397.0, 167.0, 1.0, 439.0, - 166.0, 1.0, 369.0, 193.0, 2.0, 461.0, 234.0, 2.0, 361.0, 246.0, 2.0, 474.0, 287.0, 2.0}, - {244.0, 139.0, 2.0, 0.0, 0.0, 0.0, 226.0, 118.0, 2.0, 0.0, 0.0, 0.0, 154.0, 159.0, 2.0, 143.0, 261.0, 2.0, 135.0, - 312.0, 2.0, 271.0, 423.0, 2.0, 184.0, 530.0, 2.0, 261.0, 280.0, 2.0, 347.0, 592.0, 2.0, 0.0, 0.0, 0.0, 123.0, - 596.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}}; - std::vector> expect_size = {{1, 51}, {1, 51}}; - std::vector> expect_num_keypoints_list = {{14}, {10}}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto keypoints = row["keypoints"]; - auto num_keypoints = row["num_keypoints"]; - std::shared_ptr expect_image; - Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); - EXPECT_EQ(*image, *expect_image); - std::shared_ptr expect_keypoints; - dsize_t keypoints_size = expect_size[i][0]; - Tensor::CreateFromVector(expect_keypoint_vector[i], TensorShape(expect_size[i]), &expect_keypoints); - EXPECT_EQ(*keypoints, *expect_keypoints); - std::shared_ptr expect_num_keypoints; - Tensor::CreateFromVector(expect_num_keypoints_list[i], TensorShape({keypoints_size, 1}), &expect_num_keypoints); - EXPECT_EQ(*num_keypoints, *expect_num_keypoints); - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 2); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCocoPanoptic) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoPanoptic."; - // Create a Coco Dataset - std::string folder_path = datasets_root_path_ + "/testCOCO/train"; - std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/panoptic.json"; - - std::shared_ptr ds = Coco(folder_path, annotation_file, "Panoptic", false, SequentialSampler(0, 2)); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - std::string expect_file[] = {"000000391895", "000000574769"}; - std::vector> expect_bbox_vector = {{472, 173, 36, 48, 340, 22, 154, 301, 486, 183, 30, 35}, - {103, 133, 229, 422, 243, 175, 93, 164}}; - std::vector> expect_categoryid_vector = {{1, 1, 2}, {1, 3}}; - std::vector> expect_iscrowd_vector = {{0, 0, 0}, {0, 0}}; - std::vector> expect_area_vector = {{705, 14062, 626}, {43102, 6079}}; - std::vector> expect_size = {{3, 4}, {2, 4}}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto bbox = row["bbox"]; - auto category_id = row["category_id"]; - auto iscrowd = row["iscrowd"]; - auto area = row["area"]; - std::shared_ptr expect_image; - Tensor::CreateFromFile(folder_path + "/" + expect_file[i] + ".jpg", &expect_image); - EXPECT_EQ(*image, *expect_image); - std::shared_ptr expect_bbox; - dsize_t bbox_size = expect_size[i][0]; - Tensor::CreateFromVector(expect_bbox_vector[i], TensorShape(expect_size[i]), &expect_bbox); - EXPECT_EQ(*bbox, *expect_bbox); - std::shared_ptr expect_categoryid; - Tensor::CreateFromVector(expect_categoryid_vector[i], TensorShape({bbox_size, 1}), &expect_categoryid); - EXPECT_EQ(*category_id, *expect_categoryid); - std::shared_ptr expect_iscrowd; - Tensor::CreateFromVector(expect_iscrowd_vector[i], TensorShape({bbox_size, 1}), &expect_iscrowd); - EXPECT_EQ(*iscrowd, *expect_iscrowd); - std::shared_ptr expect_area; - Tensor::CreateFromVector(expect_area_vector[i], TensorShape({bbox_size, 1}), &expect_area); - EXPECT_EQ(*area, *expect_area); - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 2); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCocoDefault) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoDefault."; - // Create a Coco Dataset - std::string folder_path = datasets_root_path_ + "/testCOCO/train"; - std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; - - std::shared_ptr ds = Coco(folder_path, annotation_file); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto bbox = row["bbox"]; - auto category_id = row["category_id"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - MS_LOG(INFO) << "Tensor bbox shape: " << bbox->shape(); - MS_LOG(INFO) << "Tensor category_id shape: " << category_id->shape(); - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 6); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCocoException) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCocoException."; - // Create a Coco Dataset - std::string folder_path = datasets_root_path_ + "/testCOCO/train"; - std::string annotation_file = datasets_root_path_ + "/testCOCO/annotations/train.json"; - std::string invalid_folder_path = "./NotExist"; - std::string invalid_annotation_file = "./NotExistFile"; - - std::shared_ptr ds = Coco(invalid_folder_path, annotation_file); - EXPECT_EQ(ds, nullptr); - - std::shared_ptr ds1 = Coco(folder_path, invalid_annotation_file); - EXPECT_EQ(ds1, nullptr); - - std::shared_ptr ds2 = Coco(folder_path, annotation_file, "valid_mode"); - EXPECT_EQ(ds2, nullptr); -} - -TEST_F(MindDataTestPipeline, TestConcatSuccess) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatSuccess."; - - // Create an ImageFolder Dataset - // Column names: {"image", "label"} - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Cifar10 Dataset - // Column names: {"image", "label"} - folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds2 = Cifar10(folder_path, RandomSampler(false, 9)); - EXPECT_NE(ds2, nullptr); - - // Create a Project operation on ds - ds = ds->Project({"image"}); - EXPECT_NE(ds, nullptr); - ds2 = ds2->Project({"image"}); - EXPECT_NE(ds, nullptr); - - // Create a Concat operation on the ds - ds = ds->Concat({ds2}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 19); - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestConcatSuccess2) { - // Test "+" operator to concat two datasets - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatSuccess2."; - - // Create an ImageFolder Dataset - // Column names: {"image", "label"} - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Cifar10 Dataset - // Column names: {"image", "label"} - folder_path = datasets_root_path_ + "/testCifar10Data/"; - std::shared_ptr ds2 = Cifar10(folder_path, RandomSampler(false, 9)); - EXPECT_NE(ds2, nullptr); - - // Create a Project operation on ds - ds = ds->Project({"image"}); - EXPECT_NE(ds, nullptr); - ds2 = ds2->Project({"image"}); - EXPECT_NE(ds, nullptr); - - // Create a Concat operation on the ds - ds = ds + ds2; - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - uint64_t i = 0; - while (row.size() != 0) { - i++; - auto image = row["image"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - iter->GetNextRow(&row); - } - - EXPECT_EQ(i, 19); - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestConcatFail1) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatFail1."; - // This case is expected to fail because the input column names of concatenated datasets are not the same - - // Create an ImageFolder Dataset - // Column names: {"image", "label"} - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - std::shared_ptr ds2 = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Rename operation on ds - ds2 = ds2->Rename({"image", "label"}, {"col1", "col2"}); - EXPECT_NE(ds, nullptr); - - // Create a Project operation on the ds - // Name of datasets to concat doesn't not match - ds = ds->Concat({ds2}); - EXPECT_NE(ds, nullptr); - - // Create a Batch operation on ds - int32_t batch_size = 1; - ds = ds->Batch(batch_size); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_EQ(iter, nullptr); -} - -TEST_F(MindDataTestPipeline, TestConcatFail2) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestConcatFail2."; - // This case is expected to fail because the input dataset is empty. - - // Create an ImageFolder Dataset - std::string folder_path = datasets_root_path_ + "/testPK/data/"; - std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); - EXPECT_NE(ds, nullptr); - - // Create a Project operation on the ds - // Input dataset to concat is empty - ds = ds->Concat({}); - EXPECT_EQ(ds, nullptr); -} - -TEST_F(MindDataTestPipeline, TestCelebADataset) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCelebADataset."; - - // Create a CelebA Dataset - std::string folder_path = datasets_root_path_ + "/testCelebAData/"; - std::shared_ptr ds = CelebA(folder_path, "all", SequentialSampler(0, 2), false, {}); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - // Check if CelebAOp read correct images/attr - std::string expect_file[] = {"1.JPEG", "2.jpg"}; - std::vector> expect_attr_vector = - {{0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, - 1, 0, 0, 1}, {0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 1}}; - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto attr = row["attr"]; - - std::shared_ptr expect_image; - Tensor::CreateFromFile(folder_path + expect_file[i], &expect_image); - EXPECT_EQ(*image, *expect_image); - - std::shared_ptr expect_attr; - Tensor::CreateFromVector(expect_attr_vector[i], TensorShape({40}), &expect_attr); - EXPECT_EQ(*attr, *expect_attr); - - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 2); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCelebADefault) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCelebADefault."; - - // Create a CelebA Dataset - std::string folder_path = datasets_root_path_ + "/testCelebAData/"; - std::shared_ptr ds = CelebA(folder_path); - EXPECT_NE(ds, nullptr); - - // Create an iterator over the result of the above dataset - // This will trigger the creation of the Execution Tree and launch it. - std::shared_ptr iter = ds->CreateIterator(); - EXPECT_NE(iter, nullptr); - - // Iterate the dataset and get each row - std::unordered_map> row; - iter->GetNextRow(&row); - - // Check if CelebAOp read correct images/attr - uint64_t i = 0; - while (row.size() != 0) { - auto image = row["image"]; - auto attr = row["attr"]; - MS_LOG(INFO) << "Tensor image shape: " << image->shape(); - MS_LOG(INFO) << "Tensor attr shape: " << attr->shape(); - - iter->GetNextRow(&row); - i++; - } - - EXPECT_EQ(i, 2); - - // Manually terminate the pipeline - iter->Stop(); -} - -TEST_F(MindDataTestPipeline, TestCelebAException) { - MS_LOG(INFO) << "Doing MindDataTestPipeline-TestCelebAException."; - - // Create a CelebA Dataset - std::string folder_path = datasets_root_path_ + "/testCelebAData/"; - std::string invalid_folder_path = "./testNotExist"; - std::string invalid_dataset_type = "invalid_type"; - std::shared_ptr ds = CelebA(invalid_folder_path); - EXPECT_EQ(ds, nullptr); - std::shared_ptr ds1 = CelebA(folder_path, invalid_dataset_type); - EXPECT_EQ(ds1, nullptr); -} \ No newline at end of file diff --git a/tests/ut/cpp/dataset/c_api_transforms_test.cc b/tests/ut/cpp/dataset/c_api_transforms_test.cc new file mode 100644 index 0000000000..06ca76d70f --- /dev/null +++ b/tests/ut/cpp/dataset/c_api_transforms_test.cc @@ -0,0 +1,731 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include +#include +#include +#include +#include + +#include "utils/log_adapter.h" +#include "utils/ms_utils.h" +#include "common/common.h" +#include "gtest/gtest.h" +#include "securec.h" +#include "minddata/dataset/include/datasets.h" +#include "minddata/dataset/include/status.h" +#include "minddata/dataset/include/transforms.h" +#include "minddata/dataset/include/iterator.h" +#include "minddata/dataset/core/constants.h" +#include "minddata/dataset/core/tensor_shape.h" +#include "minddata/dataset/core/tensor.h" +#include "minddata/dataset/include/samplers.h" + +using namespace mindspore::dataset::api; +using mindspore::MsLogLevel::ERROR; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; +using mindspore::dataset::Tensor; +using mindspore::dataset::Status; +using mindspore::dataset::BorderType; + +class MindDataTestPipeline : public UT::DatasetOpTesting { + protected: +}; + +TEST_F(MindDataTestPipeline, TestUniformAugWithOps) { + // Create a Mnist Dataset + std::string folder_path = datasets_root_path_ + "/testMnistData/"; + std::shared_ptr ds = Mnist(folder_path, RandomSampler(false, 20)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 1; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr resize_op = vision::Resize({30, 30}); + EXPECT_NE(resize_op, nullptr); + + std::shared_ptr random_crop_op = vision::RandomCrop({28, 28}); + EXPECT_NE(random_crop_op, nullptr); + + std::shared_ptr center_crop_op = vision::CenterCrop({16, 16}); + EXPECT_NE(center_crop_op, nullptr); + + std::shared_ptr uniform_aug_op = vision::UniformAugment({random_crop_op, center_crop_op}, 2); + EXPECT_NE(uniform_aug_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({resize_op, uniform_aug_op}); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestRandomFlip) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_vertical_flip_op = vision::RandomVerticalFlip(0.5); + EXPECT_NE(random_vertical_flip_op, nullptr); + + std::shared_ptr random_horizontal_flip_op = vision::RandomHorizontalFlip(0.5); + EXPECT_NE(random_horizontal_flip_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({random_vertical_flip_op, random_horizontal_flip_op}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess1) { + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 5; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr one_hot_op = vision::OneHot(10); + EXPECT_NE(one_hot_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({one_hot_op},{"label"}); + EXPECT_NE(ds, nullptr); + + std::shared_ptr mixup_batch_op = vision::MixUpBatch(0.5); + EXPECT_NE(mixup_batch_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({mixup_batch_op}, {"image", "label"}); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestMixUpBatchSuccess2) { + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 5; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr one_hot_op = vision::OneHot(10); + EXPECT_NE(one_hot_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({one_hot_op},{"label"}); + EXPECT_NE(ds, nullptr); + + std::shared_ptr mixup_batch_op = vision::MixUpBatch(); + EXPECT_NE(mixup_batch_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({mixup_batch_op}, {"image", "label"}); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 2); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestMixUpBatchFail1) { + // Create a Cifar10 Dataset + std::string folder_path = datasets_root_path_ + "/testCifar10Data/"; + std::shared_ptr ds = Cifar10(folder_path, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 5; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr one_hot_op = vision::OneHot(10); + EXPECT_NE(one_hot_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({one_hot_op},{"label"}); + EXPECT_NE(ds, nullptr); + + std::shared_ptr mixup_batch_op = vision::MixUpBatch(-1); + EXPECT_EQ(mixup_batch_op, nullptr); +} + +TEST_F(MindDataTestPipeline, TestPad) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr pad_op1 = vision::Pad({1, 2, 3, 4}, {0}, BorderType::kSymmetric); + EXPECT_NE(pad_op1, nullptr); + + std::shared_ptr pad_op2 = vision::Pad({1}, {1, 1, 1}, BorderType::kEdge); + EXPECT_NE(pad_op2, nullptr); + + std::shared_ptr pad_op3 = vision::Pad({1, 4}); + EXPECT_NE(pad_op3, nullptr); + + // Create a Map operation on ds + ds = ds->Map({pad_op1, pad_op2, pad_op3}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestCutOut) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr cut_out1 = vision::CutOut(30, 5); + EXPECT_NE(cut_out1, nullptr); + + std::shared_ptr cut_out2 = vision::CutOut(30); + EXPECT_NE(cut_out2, nullptr); + + // Create a Map operation on ds + ds = ds->Map({cut_out1, cut_out2}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestNormalize) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr normalize = vision::Normalize({121.0, 115.0, 100.0}, {70.0, 68.0, 71.0}); + EXPECT_NE(normalize, nullptr); + + // Create a Map operation on ds + ds = ds->Map({normalize}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestDecode) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, false, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr decode = vision::Decode(true); + EXPECT_NE(decode, nullptr); + + // Create a Map operation on ds + ds = ds->Map({decode}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestHwcToChw) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr channel_swap = vision::HWC2CHW(); + EXPECT_NE(channel_swap, nullptr); + + // Create a Map operation on ds + ds = ds->Map({channel_swap}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + // check if the image is in NCHW + EXPECT_EQ(batch_size == image->shape()[0] && 3 == image->shape()[1] + && 2268 == image->shape()[2] && 4032 == image->shape()[3], true); + iter->GetNextRow(&row); + } + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestRandomColorAdjust) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_color_adjust1 = vision::RandomColorAdjust({1.0}, {0.0}, {0.5}, {0.5}); + EXPECT_NE(random_color_adjust1, nullptr); + + std::shared_ptr random_color_adjust2 = vision::RandomColorAdjust({1.0, 1.0}, {0.0, 0.0}, {0.5, 0.5}, + {0.5, 0.5}); + EXPECT_NE(random_color_adjust2, nullptr); + + std::shared_ptr random_color_adjust3 = vision::RandomColorAdjust({0.5, 1.0}, {0.0, 0.5}, {0.25, 0.5}, + {0.25, 0.5}); + EXPECT_NE(random_color_adjust3, nullptr); + + std::shared_ptr random_color_adjust4 = vision::RandomColorAdjust(); + EXPECT_NE(random_color_adjust4, nullptr); + + // Create a Map operation on ds + ds = ds->Map({random_color_adjust1, random_color_adjust2, random_color_adjust3, random_color_adjust4}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestRandomAffineSuccess1) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineSuccess1 with non-default params."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr affine = + vision::RandomAffine({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0, 10.0, 20.0, 20.0}); + EXPECT_NE(affine, nullptr); + + // Create a Map operation on ds + ds = ds->Map({affine}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestRandomAffineSuccess2) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineSuccess2 with default params."; + + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr affine = vision::RandomAffine({0.0, 0.0}); + EXPECT_NE(affine, nullptr); + + // Create a Map operation on ds + ds = ds->Map({affine}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} + +TEST_F(MindDataTestPipeline, TestRandomAffineFail) { + MS_LOG(INFO) << "Doing MindDataTestPipeline-TestRandomAffineFail with invalid params."; + + // Create objects for the tensor ops + std::shared_ptr affine = vision::RandomAffine({0.0, 0.0}, {}); + EXPECT_EQ(affine, nullptr); + // Invalid number of values for translate + affine = vision::RandomAffine({0.0, 0.0}, {1, 1, 1, 1}); + EXPECT_EQ(affine, nullptr); + // Invalid number of values for shear + affine = vision::RandomAffine({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0, 10.0}); + EXPECT_EQ(affine, nullptr); +} + +TEST_F(MindDataTestPipeline, TestRandomRotation) { + // Create an ImageFolder Dataset + std::string folder_path = datasets_root_path_ + "/testPK/data/"; + std::shared_ptr ds = ImageFolder(folder_path, true, RandomSampler(false, 10)); + EXPECT_NE(ds, nullptr); + + // Create a Repeat operation on ds + int32_t repeat_num = 2; + ds = ds->Repeat(repeat_num); + EXPECT_NE(ds, nullptr); + + // Create objects for the tensor ops + std::shared_ptr random_rotation_op = vision::RandomRotation({-180, 180}); + EXPECT_NE(random_rotation_op, nullptr); + + // Create a Map operation on ds + ds = ds->Map({random_rotation_op}); + EXPECT_NE(ds, nullptr); + + // Create a Batch operation on ds + int32_t batch_size = 1; + ds = ds->Batch(batch_size); + EXPECT_NE(ds, nullptr); + + // Create an iterator over the result of the above dataset + // This will trigger the creation of the Execution Tree and launch it. + std::shared_ptr iter = ds->CreateIterator(); + EXPECT_NE(iter, nullptr); + + // Iterate the dataset and get each row + std::unordered_map> row; + iter->GetNextRow(&row); + + uint64_t i = 0; + while (row.size() != 0) { + i++; + auto image = row["image"]; + MS_LOG(INFO) << "Tensor image shape: " << image->shape(); + iter->GetNextRow(&row); + } + + EXPECT_EQ(i, 20); + + // Manually terminate the pipeline + iter->Stop(); +} diff --git a/tests/ut/cpp/dataset/common/cvop_common.cc b/tests/ut/cpp/dataset/common/cvop_common.cc index 28d0c07764..6f9cfde820 100644 --- a/tests/ut/cpp/dataset/common/cvop_common.cc +++ b/tests/ut/cpp/dataset/common/cvop_common.cc @@ -130,6 +130,18 @@ void CVOpCommon::CheckImageShapeAndData(const std::shared_ptr &output_te expect_image_path = dir_path + "imagefolder/apple_expect_changemode.jpg"; actual_image_path = dir_path + "imagefolder/apple_actual_changemode.jpg"; break; + case kRandomAffine: + expect_image_path = dir_path + "imagefolder/apple_expect_randomaffine.jpg"; + actual_image_path = dir_path + "imagefolder/apple_actual_randomaffine.jpg"; + break; + case kAutoContrast: + expect_image_path = dir_path + "imagefolder/apple_expect_autocontrast.jpg"; + actual_image_path = dir_path + "imagefolder/apple_actual_autocontrast.jpg"; + break; + case kEqualize: + expect_image_path = dir_path + "imagefolder/apple_expect_equalize.jpg"; + actual_image_path = dir_path + "imagefolder/apple_actual_equalize.jpg"; + break; default: MS_LOG(INFO) << "Not pass verification! Operation type does not exists."; EXPECT_EQ(0, 1); diff --git a/tests/ut/cpp/dataset/common/cvop_common.h b/tests/ut/cpp/dataset/common/cvop_common.h index 59134091fd..000077d431 100644 --- a/tests/ut/cpp/dataset/common/cvop_common.h +++ b/tests/ut/cpp/dataset/common/cvop_common.h @@ -37,7 +37,10 @@ class CVOpCommon : public Common { kChannelSwap, kChangeMode, kTemplate, - kCrop + kCrop, + kRandomAffine, + kAutoContrast, + kEqualize }; CVOpCommon(); diff --git a/tests/ut/cpp/dataset/equalize_op_test.cc b/tests/ut/cpp/dataset/equalize_op_test.cc new file mode 100644 index 0000000000..1c5cfb03ae --- /dev/null +++ b/tests/ut/cpp/dataset/equalize_op_test.cc @@ -0,0 +1,41 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "common/common.h" +#include "common/cvop_common.h" +#include "minddata/dataset/kernels/image/equalize_op.h" +#include "minddata/dataset/core/cv_tensor.h" +#include "utils/log_adapter.h" + +using namespace mindspore::dataset; +using mindspore::LogStream; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::MsLogLevel::INFO; + +class MindDataTestEqualizeOp : public UT::CVOP::CVOpCommon { + public: + MindDataTestEqualizeOp() : CVOpCommon() {} +}; + +TEST_F(MindDataTestEqualizeOp, TestOp1) { + MS_LOG(INFO) << "Doing testEqualizeOp."; + + std::shared_ptr output_tensor; + std::unique_ptr op(new EqualizeOp()); + EXPECT_TRUE(op->OneToOne()); + Status s = op->Compute(input_tensor_, &output_tensor); + EXPECT_TRUE(s.IsOk()); + CheckImageShapeAndData(output_tensor, kEqualize); +} diff --git a/tests/ut/cpp/dataset/mixup_batch_op_test.cc b/tests/ut/cpp/dataset/mixup_batch_op_test.cc new file mode 100644 index 0000000000..844566ec79 --- /dev/null +++ b/tests/ut/cpp/dataset/mixup_batch_op_test.cc @@ -0,0 +1,69 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "common/common.h" +#include "common/cvop_common.h" +#include "minddata/dataset/kernels/image/mixup_batch_op.h" +#include "utils/log_adapter.h" + +using namespace mindspore::dataset; +using mindspore::MsLogLevel::INFO; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::LogStream; + +class MindDataTestMixUpBatchOp : public UT::CVOP::CVOpCommon { + protected: + MindDataTestMixUpBatchOp() : CVOpCommon() {} + + std::shared_ptr output_tensor_; +}; + +TEST_F(MindDataTestMixUpBatchOp, TestSuccess) { + MS_LOG(INFO) << "Doing MindDataTestMixUpBatchOp success case"; + std::shared_ptr batched_tensor; + std::shared_ptr batched_labels; + Tensor::CreateEmpty(TensorShape({2, input_tensor_->shape()[0], input_tensor_->shape()[1], input_tensor_->shape()[2]}), input_tensor_->type(), &batched_tensor); + for (int i = 0; i < 2; i++) { + batched_tensor->InsertTensor({i}, input_tensor_); + } + Tensor::CreateFromVector(std::vector({0, 1, 1, 0}), TensorShape({2, 2}), &batched_labels); + std::shared_ptr op = std::make_shared(1); + TensorRow in; + in.push_back(batched_tensor); + in.push_back(batched_labels); + TensorRow out; + ASSERT_TRUE(op->Compute(in, &out).IsOk()); + + EXPECT_EQ(in.at(0)->shape()[0], out.at(0)->shape()[0]); + EXPECT_EQ(in.at(0)->shape()[1], out.at(0)->shape()[1]); + EXPECT_EQ(in.at(0)->shape()[2], out.at(0)->shape()[2]); + EXPECT_EQ(in.at(0)->shape()[3], out.at(0)->shape()[3]); + + EXPECT_EQ(in.at(1)->shape()[0], out.at(1)->shape()[0]); + EXPECT_EQ(in.at(1)->shape()[1], out.at(1)->shape()[1]); +} + +TEST_F(MindDataTestMixUpBatchOp, TestFail) { + // This is a fail case because our labels are not batched and are 1-dimensional + MS_LOG(INFO) << "Doing MindDataTestMixUpBatchOp fail case"; + std::shared_ptr labels; + Tensor::CreateFromVector(std::vector({0, 1, 1, 0}), TensorShape({4}), &labels); + std::shared_ptr op = std::make_shared(1); + TensorRow in; + in.push_back(input_tensor_); + in.push_back(labels); + TensorRow out; + ASSERT_FALSE(op->Compute(in, &out).IsOk()); +} diff --git a/tests/ut/cpp/dataset/random_affine_op_test.cc b/tests/ut/cpp/dataset/random_affine_op_test.cc new file mode 100644 index 0000000000..8db93c589a --- /dev/null +++ b/tests/ut/cpp/dataset/random_affine_op_test.cc @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Huawei Technologies Co., Ltd + * + * 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. + */ +#include "common/common.h" +#include "common/cvop_common.h" +#include "minddata/dataset/kernels/image/random_affine_op.h" +#include "minddata/dataset/core/cv_tensor.h" +#include "utils/log_adapter.h" + +using namespace mindspore::dataset; +using mindspore::LogStream; +using mindspore::ExceptionType::NoExceptionType; +using mindspore::MsLogLevel::INFO; + +class MindDataTestRandomAffineOp : public UT::CVOP::CVOpCommon { + public: + MindDataTestRandomAffineOp() : CVOpCommon() {} +}; + +TEST_F(MindDataTestRandomAffineOp, TestOp1) { + MS_LOG(INFO) << "Doing testRandomAffineOp."; + + std::shared_ptr output_tensor; + std::unique_ptr op(new RandomAffineOp({30.0, 30.0}, {0.0, 0.0}, {2.0, 2.0}, {10.0, 10.0, 20.0, 20.0}, + InterpolationMode::kNearestNeighbour, {255, 0, 0})); + EXPECT_TRUE(op->OneToOne()); + Status s = op->Compute(input_tensor_, &output_tensor); + EXPECT_TRUE(s.IsOk()); + CheckImageShapeAndData(output_tensor, kRandomAffine); +} diff --git a/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc b/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc index 2137fb4a13..7b9186ac37 100644 --- a/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc +++ b/tests/ut/cpp/mindrecord/ut_shard_operator_test.cc @@ -162,7 +162,7 @@ TEST_F(TestShardOperator, TestShardPkSamplerBasic) { auto column_list = std::vector{"file_name", "label"}; std::vector> ops; - ops.push_back(std::make_shared("label", 2)); + ops.push_back(std::make_shared("label", 2, 0)); ShardReader dataset; dataset.Open({file_name},true, 4, column_list, ops); @@ -187,7 +187,7 @@ TEST_F(TestShardOperator, TestShardPkSamplerNumClass) { auto column_list = std::vector{"file_name", "label"}; std::vector> ops; - ops.push_back(std::make_shared("label", 2, 3, 0)); + ops.push_back(std::make_shared("label", 2, 3, 0, 0)); ShardReader dataset; dataset.Open({file_name},true, 4, column_list, ops); @@ -204,7 +204,7 @@ TEST_F(TestShardOperator, TestShardPkSamplerNumClass) { } dataset.Finish(); ASSERT_TRUE(i == 6); -} // namespace mindrecord +} TEST_F(TestShardOperator, TestShardCategory) { MS_LOG(INFO) << common::SafeCStr(FormatInfo("Test read imageNet")); diff --git a/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc b/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc index 2759864037..add4ef8e41 100644 --- a/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc +++ b/tests/ut/cpp/pre_activate/ascend/ir_fusion/adam_apply_one_fusion_test.cc @@ -217,5 +217,105 @@ TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_cond4_fusion) { FuncGraphPtr g_after = get_py_fun_.CallAndParseRet("test_adam_apply_one_fusion", "after"); EXPECT_TRUE(CheckEqualGraph(g_after, new_graph)); } + +TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_fusion) { + FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before"); + std::vector shp{2, 32, 224, 224}; + auto x_abstract = std::make_shared(kFloat32, shp); + AbstractBasePtrList args_spec_list; + for (size_t i = 0; i < 10; ++i) { + args_spec_list.push_back(x_abstract); + } + auto fg = GetKernelGraph(g, args_spec_list); + + auto optimizer = std::make_shared(); + auto pm = std::make_shared(); + pm->AddPass(std::make_shared()); + optimizer->AddPassManager(pm); + FuncGraphPtr new_graph = optimizer->Optimize(fg); + + FuncGraphPtr g_after = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "after"); + EXPECT_TRUE(CheckEqualGraph(g_after, new_graph)); +} + +TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond1_fusion) { + FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond1"); + std::vector shp{2, 32, 224, 224}; + auto x_abstract = std::make_shared(kFloat32, shp); + AbstractBasePtrList args_spec_list; + for (size_t i = 0; i < 10; ++i) { + args_spec_list.push_back(x_abstract); + } + auto fg = GetKernelGraph(g, args_spec_list); + + auto optimizer = std::make_shared(); + auto pm = std::make_shared(); + pm->AddPass(std::make_shared()); + optimizer->AddPassManager(pm); + FuncGraphPtr new_graph = optimizer->Optimize(fg); + + FuncGraphPtr g_after = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "after"); + EXPECT_TRUE(CheckEqualGraph(g_after, new_graph)); +} + +TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond2_fusion) { + FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond2"); + std::vector shp{2, 32, 224, 224}; + auto x_abstract = std::make_shared(kFloat32, shp); + AbstractBasePtrList args_spec_list; + for (size_t i = 0; i < 10; ++i) { + args_spec_list.push_back(x_abstract); + } + auto fg = GetKernelGraph(g, args_spec_list); + + auto optimizer = std::make_shared(); + auto pm = std::make_shared(); + pm->AddPass(std::make_shared()); + optimizer->AddPassManager(pm); + FuncGraphPtr new_graph = optimizer->Optimize(fg); + + FuncGraphPtr g_after = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "after"); + EXPECT_TRUE(CheckEqualGraph(g_after, new_graph)); +} + +TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond3_fusion) { + FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond3"); + std::vector shp{2, 32, 224, 224}; + auto x_abstract = std::make_shared(kFloat32, shp); + AbstractBasePtrList args_spec_list; + for (size_t i = 0; i < 10; ++i) { + args_spec_list.push_back(x_abstract); + } + auto fg = GetKernelGraph(g, args_spec_list); + + auto optimizer = std::make_shared(); + auto pm = std::make_shared(); + pm->AddPass(std::make_shared()); + optimizer->AddPassManager(pm); + FuncGraphPtr new_graph = optimizer->Optimize(fg); + + FuncGraphPtr g_after = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "after"); + EXPECT_TRUE(CheckEqualGraph(g_after, new_graph)); +} + +TEST_F(TestHWAdamApplyOneFusion, test_adam_apply_one_assign_cond4_fusion) { + FuncGraphPtr g = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "before_cond4"); + std::vector shp{2, 32, 224, 224}; + auto x_abstract = std::make_shared(kFloat32, shp); + AbstractBasePtrList args_spec_list; + for (size_t i = 0; i < 10; ++i) { + args_spec_list.push_back(x_abstract); + } + auto fg = GetKernelGraph(g, args_spec_list); + + auto optimizer = std::make_shared(); + auto pm = std::make_shared(); + pm->AddPass(std::make_shared()); + optimizer->AddPassManager(pm); + FuncGraphPtr new_graph = optimizer->Optimize(fg); + + FuncGraphPtr g_after = get_py_fun_.CallAndParseRet("test_adam_apply_one_assign_fusion", "after"); + EXPECT_TRUE(CheckEqualGraph(g_after, new_graph)); +} } // namespace opt } // namespace mindspore diff --git a/tests/ut/cpp/python_input/gtest_input/pre_activate/adam_apply_one_fusion_test.py b/tests/ut/cpp/python_input/gtest_input/pre_activate/adam_apply_one_fusion_test.py index 27cfe38b8f..654b922c25 100644 --- a/tests/ut/cpp/python_input/gtest_input/pre_activate/adam_apply_one_fusion_test.py +++ b/tests/ut/cpp/python_input/gtest_input/pre_activate/adam_apply_one_fusion_test.py @@ -14,6 +14,7 @@ # ============================================================================ from mindspore.ops import Primitive from mindspore.ops import operations as P +from mindspore.ops import functional as F Add = P.TensorAdd() Sub = P.Sub() @@ -21,9 +22,11 @@ Mul = P.Mul() RealDiv = P.RealDiv() Sqrt = P.Sqrt() Square = P.Square() +Assign = P.Assign() make_tuple = Primitive('make_tuple') tuple_getitem = Primitive('tuple_getitem') AdamApplyOne = Primitive('AdamApplyOne') +AdamApplyOneAssign = Primitive('AdamApplyOneAssign') class FnDict: @@ -139,3 +142,138 @@ def test_adam_apply_one_fusion(tag): return make_tuple(output) return fns[tag] + + +def test_adam_apply_one_assign_fusion(tag): + fns = FnDict() + + @fns + def before(input0, input1, input2, input3, input4, mul0_x, mul1_x, mul2_x, mul3_x, add2_y): + square0 = Square(input0) + mul1 = Mul(mul1_x, input0) + mul0 = Mul(mul0_x, input2) + mul2 = Mul(mul2_x, input1) + mul3 = Mul(mul3_x, square0) + add0 = Add(mul0, mul1) + add1 = Add(mul2, mul3) + sqrt0 = Sqrt(add1) + add2 = Add(sqrt0, add2_y) + true_div0 = RealDiv(add0, add2) + mul4 = Mul(input4, true_div0) + sub0 = Sub(input3, mul4) + assign0 = Assign(input3, sub0) + depend0 = F.depend(sub0, assign0) + assign1 = Assign(input2, add0) + depend1 = F.depend(depend0, assign1) + assign2 = Assign(input1, add1) + depend2 = F.depend(depend1, assign2) + outputs = make_tuple(add1, add0, depend2) + output = tuple_getitem(outputs, 0) + return output + + @fns + def before_cond1(input0, input1, input2, input3, input4, mul0_x, mul1_x, mul2_x, mul3_x, add2_y): + square0 = Square(input0) + mul1 = Mul(mul1_x, input0) + mul0 = Mul(mul0_x, input2) + mul2 = Mul(mul2_x, input1) + mul3 = Mul(mul3_x, square0) + add0 = Add(mul0, mul1) + add1 = Add(mul2, mul3) + sqrt0 = Sqrt(add1) + add2 = Add(add2_y, sqrt0) + true_div0 = RealDiv(add0, add2) + mul4 = Mul(input4, true_div0) + sub0 = Sub(input3, mul4) + assign0 = Assign(input3, sub0) + depend0 = F.depend(sub0, assign0) + assign1 = Assign(input2, add0) + depend1 = F.depend(depend0, assign1) + assign2 = Assign(input1, add1) + depend2 = F.depend(depend1, assign2) + outputs = make_tuple(add1, add0, depend2) + output = tuple_getitem(outputs, 0) + return output + + @fns + def before_cond2(input0, input1, input2, input3, input4, mul0_x, mul1_x, mul2_x, mul3_x, add2_y): + square0 = Square(input0) + mul1 = Mul(mul1_x, input0) + mul0 = Mul(mul0_x, input2) + mul2 = Mul(mul2_x, input1) + mul3 = Mul(square0, mul3_x) + add0 = Add(mul0, mul1) + add1 = Add(mul2, mul3) + sqrt0 = Sqrt(add1) + add2 = Add(sqrt0, add2_y) + true_div0 = RealDiv(add0, add2) + mul4 = Mul(true_div0, input4) + sub0 = Sub(input3, mul4) + assign0 = Assign(input3, sub0) + depend0 = F.depend(sub0, assign0) + assign1 = Assign(input2, add0) + depend1 = F.depend(depend0, assign1) + assign2 = Assign(input1, add1) + depend2 = F.depend(depend1, assign2) + outputs = make_tuple(add1, add0, depend2) + output = tuple_getitem(outputs, 0) + return output + + @fns + def before_cond3(input0, input1, input2, input3, input4, mul0_x, mul1_x, mul2_x, mul3_x, add2_y): + square0 = Square(input0) + mul1 = Mul(mul1_x, input0) + mul0 = Mul(mul0_x, input2) + mul2 = Mul(mul2_x, input1) + mul3 = Mul(mul3_x, square0) + add0 = Add(mul0, mul1) + add1 = Add(mul2, mul3) + sqrt0 = Sqrt(add1) + add2 = Add(sqrt0, add2_y) + true_div0 = RealDiv(add0, add2) + mul4 = Mul(true_div0, input4) + sub0 = Sub(input3, mul4) + assign0 = Assign(input3, sub0) + depend0 = F.depend(sub0, assign0) + assign1 = Assign(input2, add0) + depend1 = F.depend(depend0, assign1) + assign2 = Assign(input1, add1) + depend2 = F.depend(depend1, assign2) + outputs = make_tuple(add1, add0, depend2) + output = tuple_getitem(outputs, 0) + return output + + @fns + def before_cond4(input0, input1, input2, input3, input4, mul0_x, mul1_x, mul2_x, mul3_x, add2_y): + square0 = Square(input0) + mul1 = Mul(mul1_x, input0) + mul0 = Mul(mul0_x, input2) + mul2 = Mul(mul2_x, input1) + mul3 = Mul(mul3_x, square0) + add0 = Add(mul0, mul1) + add1 = Add(mul2, mul3) + sqrt0 = Sqrt(add1) + add2 = Add(add2_y, sqrt0) + true_div0 = RealDiv(add0, add2) + mul4 = Mul(true_div0, input4) + sub0 = Sub(input3, mul4) + assign0 = Assign(input3, sub0) + depend0 = F.depend(sub0, assign0) + assign1 = Assign(input2, add0) + depend1 = F.depend(depend0, assign1) + assign2 = Assign(input1, add1) + depend2 = F.depend(depend1, assign2) + outputs = make_tuple(add1, add0, depend2) + output = tuple_getitem(outputs, 0) + return output + + @fns + def after(input0, input1, input2, input3, input4, mul0_x, mul1_x, mul2_x, mul3_x, add2_y): + adam_apply_one_assign = AdamApplyOneAssign(input0, input1, input2, input3, input4, mul0_x, mul1_x, mul2_x, + mul3_x, add2_y) + outputs = make_tuple(tuple_getitem(adam_apply_one_assign, 0), tuple_getitem(adam_apply_one_assign, 1), + tuple_getitem(adam_apply_one_assign, 2)) + output = tuple_getitem(outputs, 0) + return make_tuple(output) + + return fns[tag] diff --git a/tests/ut/data/dataset/golden/autcontrast_01_result_c.npz b/tests/ut/data/dataset/golden/autocontrast_01_result_c.npz similarity index 100% rename from tests/ut/data/dataset/golden/autcontrast_01_result_c.npz rename to tests/ut/data/dataset/golden/autocontrast_01_result_c.npz diff --git a/tests/ut/data/dataset/golden/autcontrast_01_result_py.npz b/tests/ut/data/dataset/golden/autocontrast_01_result_py.npz similarity index 100% rename from tests/ut/data/dataset/golden/autcontrast_01_result_py.npz rename to tests/ut/data/dataset/golden/autocontrast_01_result_py.npz diff --git a/tests/ut/data/dataset/golden/autocontrast_mnist_result_c.npz b/tests/ut/data/dataset/golden/autocontrast_mnist_result_c.npz new file mode 100644 index 0000000000..683ed673a0 Binary files /dev/null and b/tests/ut/data/dataset/golden/autocontrast_mnist_result_c.npz differ diff --git a/tests/ut/data/dataset/golden/equalize_mnist_result_c.npz b/tests/ut/data/dataset/golden/equalize_mnist_result_c.npz new file mode 100644 index 0000000000..683ed673a0 Binary files /dev/null and b/tests/ut/data/dataset/golden/equalize_mnist_result_c.npz differ diff --git a/tests/ut/data/dataset/golden/mixup_batch_c_result.npz b/tests/ut/data/dataset/golden/mixup_batch_c_result.npz new file mode 100644 index 0000000000..ad606d0d3c Binary files /dev/null and b/tests/ut/data/dataset/golden/mixup_batch_c_result.npz differ diff --git a/tests/ut/data/dataset/golden/random_affine_01_c_result.npz b/tests/ut/data/dataset/golden/random_affine_01_c_result.npz new file mode 100644 index 0000000000..277acd9540 Binary files /dev/null and b/tests/ut/data/dataset/golden/random_affine_01_c_result.npz differ diff --git a/tests/ut/data/dataset/imagefolder/apple_expect_autocontrast.jpg b/tests/ut/data/dataset/imagefolder/apple_expect_autocontrast.jpg new file mode 100644 index 0000000000..a624de836c Binary files /dev/null and b/tests/ut/data/dataset/imagefolder/apple_expect_autocontrast.jpg differ diff --git a/tests/ut/data/dataset/imagefolder/apple_expect_equalize.jpg b/tests/ut/data/dataset/imagefolder/apple_expect_equalize.jpg new file mode 100644 index 0000000000..4cbb5d5e85 Binary files /dev/null and b/tests/ut/data/dataset/imagefolder/apple_expect_equalize.jpg differ diff --git a/tests/ut/data/dataset/imagefolder/apple_expect_randomaffine.jpg b/tests/ut/data/dataset/imagefolder/apple_expect_randomaffine.jpg new file mode 100644 index 0000000000..f383e06bb8 Binary files /dev/null and b/tests/ut/data/dataset/imagefolder/apple_expect_randomaffine.jpg differ diff --git a/tests/ut/python/dataset/test_autocontrast.py b/tests/ut/python/dataset/test_autocontrast.py index 6c3fc671d7..c657c74296 100644 --- a/tests/ut/python/dataset/test_autocontrast.py +++ b/tests/ut/python/dataset/test_autocontrast.py @@ -20,9 +20,10 @@ import mindspore.dataset.engine as de import mindspore.dataset.transforms.vision.py_transforms as F import mindspore.dataset.transforms.vision.c_transforms as C from mindspore import log as logger -from util import visualize_list, diff_mse, save_and_check_md5 +from util import visualize_list, visualize_one_channel_dataset, diff_mse, save_and_check_md5 DATA_DIR = "../data/dataset/testImageNetData/train/" +MNIST_DATA_DIR = "../data/dataset/testMnistData" GENERATE_GOLDEN = False @@ -81,7 +82,7 @@ def test_auto_contrast_py(plot=False): logger.info("MSE= {}".format(str(np.mean(mse)))) # Compare with expected md5 from images - filename = "autcontrast_01_result_py.npz" + filename = "autocontrast_01_result_py.npz" save_and_check_md5(ds_auto_contrast, filename, generate_golden=GENERATE_GOLDEN) if plot: @@ -144,7 +145,7 @@ def test_auto_contrast_c(plot=False): np.testing.assert_equal(np.mean(mse), 0.0) # Compare with expected md5 from images - filename = "autcontrast_01_result_c.npz" + filename = "autocontrast_01_result_c.npz" save_and_check_md5(ds_auto_contrast_c, filename, generate_golden=GENERATE_GOLDEN) if plot: @@ -213,6 +214,34 @@ def test_auto_contrast_one_channel_c(plot=False): visualize_list(images_auto_contrast_c, images_auto_contrast_py, visualize_mode=2) +def test_auto_contrast_mnist_c(plot=False): + """ + Test AutoContrast C op with MNIST dataset (Grayscale images) + """ + logger.info("Test AutoContrast C Op With MNIST Images") + ds = de.MnistDataset(dataset_dir=MNIST_DATA_DIR, num_samples=2, shuffle=False) + ds_auto_contrast_c = ds.map(input_columns="image", + operations=C.AutoContrast(cutoff=1, ignore=(0, 255))) + ds_orig = de.MnistDataset(dataset_dir=MNIST_DATA_DIR, num_samples=2, shuffle=False) + + images = [] + images_trans = [] + labels = [] + for _, (data_orig, data_trans) in enumerate(zip(ds_orig, ds_auto_contrast_c)): + image_orig, label_orig = data_orig + image_trans, _ = data_trans + images.append(image_orig) + labels.append(label_orig) + images_trans.append(image_trans) + + # Compare with expected md5 from images + filename = "autocontrast_mnist_result_c.npz" + save_and_check_md5(ds_auto_contrast_c, filename, generate_golden=GENERATE_GOLDEN) + + if plot: + visualize_one_channel_dataset(images, images_trans, labels) + + def test_auto_contrast_invalid_ignore_param_c(): """ Test AutoContrast C Op with invalid ignore parameter @@ -333,6 +362,7 @@ if __name__ == "__main__": test_auto_contrast_py(plot=True) test_auto_contrast_c(plot=True) test_auto_contrast_one_channel_c(plot=True) + test_auto_contrast_mnist_c(plot=True) test_auto_contrast_invalid_ignore_param_c() test_auto_contrast_invalid_ignore_param_py() test_auto_contrast_invalid_cutoff_param_c() diff --git a/tests/ut/python/dataset/test_equalize.py b/tests/ut/python/dataset/test_equalize.py index 26102ae809..bdc8375b67 100644 --- a/tests/ut/python/dataset/test_equalize.py +++ b/tests/ut/python/dataset/test_equalize.py @@ -21,12 +21,14 @@ import mindspore.dataset.engine as de import mindspore.dataset.transforms.vision.c_transforms as C import mindspore.dataset.transforms.vision.py_transforms as F from mindspore import log as logger -from util import visualize_list, diff_mse, save_and_check_md5 +from util import visualize_list, visualize_one_channel_dataset, diff_mse, save_and_check_md5 DATA_DIR = "../data/dataset/testImageNetData/train/" +MNIST_DATA_DIR = "../data/dataset/testMnistData" GENERATE_GOLDEN = False + def test_equalize_py(plot=False): """ Test Equalize py op @@ -216,6 +218,34 @@ def test_equalize_one_channel(): assert "The shape" in str(e) +def test_equalize_mnist_c(plot=False): + """ + Test Equalize C op with MNIST dataset (Grayscale images) + """ + logger.info("Test Equalize C Op With MNIST Images") + ds = de.MnistDataset(dataset_dir=MNIST_DATA_DIR, num_samples=2, shuffle=False) + ds_equalize_c = ds.map(input_columns="image", + operations=C.Equalize()) + ds_orig = de.MnistDataset(dataset_dir=MNIST_DATA_DIR, num_samples=2, shuffle=False) + + images = [] + images_trans = [] + labels = [] + for _, (data_orig, data_trans) in enumerate(zip(ds_orig, ds_equalize_c)): + image_orig, label_orig = data_orig + image_trans, _ = data_trans + images.append(image_orig) + labels.append(label_orig) + images_trans.append(image_trans) + + # Compare with expected md5 from images + filename = "equalize_mnist_result_c.npz" + save_and_check_md5(ds_equalize_c, filename, generate_golden=GENERATE_GOLDEN) + + if plot: + visualize_one_channel_dataset(images, images_trans, labels) + + def test_equalize_md5_py(): """ Test Equalize py op with md5 check @@ -258,7 +288,7 @@ if __name__ == "__main__": test_equalize_py(plot=False) test_equalize_c(plot=False) test_equalize_py_c(plot=False) + test_equalize_mnist_c(plot=True) test_equalize_one_channel() test_equalize_md5_py() test_equalize_md5_c() - \ No newline at end of file diff --git a/tests/ut/python/dataset/test_five_crop.py b/tests/ut/python/dataset/test_five_crop.py index 86f52bdcd7..84bb0624ba 100644 --- a/tests/ut/python/dataset/test_five_crop.py +++ b/tests/ut/python/dataset/test_five_crop.py @@ -86,12 +86,8 @@ def test_five_crop_error_msg(): transform = vision.ComposeOp(transforms) data = data.map(input_columns=["image"], operations=transform()) - with pytest.raises(RuntimeError) as info: + with pytest.raises(RuntimeError): data.create_tuple_iterator().__next__() - error_msg = "TypeError: img should be PIL Image or Numpy array. Got " - - # error msg comes from ToTensor() - assert error_msg in str(info.value) def test_five_crop_md5(): diff --git a/tests/ut/python/dataset/test_minddataset_sampler.py b/tests/ut/python/dataset/test_minddataset_sampler.py index 9c110c0e1f..b60302c3e3 100644 --- a/tests/ut/python/dataset/test_minddataset_sampler.py +++ b/tests/ut/python/dataset/test_minddataset_sampler.py @@ -101,7 +101,6 @@ def test_cv_minddataset_pk_sample_basic(add_and_remove_cv_file): "-------------- item[label]: {} ----------------------------".format(item["label"])) num_iter += 1 - def test_cv_minddataset_pk_sample_shuffle(add_and_remove_cv_file): """tutorial for cv minderdataset.""" columns_list = ["data", "file_name", "label"] @@ -120,9 +119,51 @@ def test_cv_minddataset_pk_sample_shuffle(add_and_remove_cv_file): logger.info( "-------------- item[label]: {} ----------------------------".format(item["label"])) num_iter += 1 + assert num_iter == 9 -def test_cv_minddataset_pk_sample_out_of_range(add_and_remove_cv_file): +def test_cv_minddataset_pk_sample_shuffle_1(add_and_remove_cv_file): + """tutorial for cv minderdataset.""" + columns_list = ["data", "file_name", "label"] + num_readers = 4 + sampler = ds.PKSampler(3, None, True, 'label', 5) + data_set = ds.MindDataset(CV_FILE_NAME + "0", columns_list, num_readers, + sampler=sampler) + + assert data_set.get_dataset_size() == 5 + num_iter = 0 + for item in data_set.create_dict_iterator(): + logger.info( + "-------------- cv reader basic: {} ------------------------".format(num_iter)) + logger.info("-------------- item[file_name]: \ + {}------------------------".format(to_str(item["file_name"]))) + logger.info( + "-------------- item[label]: {} ----------------------------".format(item["label"])) + num_iter += 1 + assert num_iter == 5 + +def test_cv_minddataset_pk_sample_shuffle_2(add_and_remove_cv_file): + """tutorial for cv minderdataset.""" + columns_list = ["data", "file_name", "label"] + num_readers = 4 + sampler = ds.PKSampler(3, None, True, 'label', 10) + data_set = ds.MindDataset(CV_FILE_NAME + "0", columns_list, num_readers, + sampler=sampler) + + assert data_set.get_dataset_size() == 9 + num_iter = 0 + for item in data_set.create_dict_iterator(): + logger.info( + "-------------- cv reader basic: {} ------------------------".format(num_iter)) + logger.info("-------------- item[file_name]: \ + {}------------------------".format(to_str(item["file_name"]))) + logger.info( + "-------------- item[label]: {} ----------------------------".format(item["label"])) + num_iter += 1 + assert num_iter == 9 + + +def test_cv_minddataset_pk_sample_out_of_range_0(add_and_remove_cv_file): """tutorial for cv minderdataset.""" columns_list = ["data", "file_name", "label"] num_readers = 4 @@ -139,6 +180,45 @@ def test_cv_minddataset_pk_sample_out_of_range(add_and_remove_cv_file): logger.info( "-------------- item[label]: {} ----------------------------".format(item["label"])) num_iter += 1 + assert num_iter == 15 + +def test_cv_minddataset_pk_sample_out_of_range_1(add_and_remove_cv_file): + """tutorial for cv minderdataset.""" + columns_list = ["data", "file_name", "label"] + num_readers = 4 + sampler = ds.PKSampler(5, None, True, 'label', 20) + data_set = ds.MindDataset(CV_FILE_NAME + "0", columns_list, num_readers, + sampler=sampler) + assert data_set.get_dataset_size() == 15 + num_iter = 0 + for item in data_set.create_dict_iterator(): + logger.info( + "-------------- cv reader basic: {} ------------------------".format(num_iter)) + logger.info("-------------- item[file_name]: \ + {}------------------------".format(to_str(item["file_name"]))) + logger.info( + "-------------- item[label]: {} ----------------------------".format(item["label"])) + num_iter += 1 + assert num_iter == 15 + +def test_cv_minddataset_pk_sample_out_of_range_2(add_and_remove_cv_file): + """tutorial for cv minderdataset.""" + columns_list = ["data", "file_name", "label"] + num_readers = 4 + sampler = ds.PKSampler(5, None, True, 'label', 10) + data_set = ds.MindDataset(CV_FILE_NAME + "0", columns_list, num_readers, + sampler=sampler) + assert data_set.get_dataset_size() == 10 + num_iter = 0 + for item in data_set.create_dict_iterator(): + logger.info( + "-------------- cv reader basic: {} ------------------------".format(num_iter)) + logger.info("-------------- item[file_name]: \ + {}------------------------".format(to_str(item["file_name"]))) + logger.info( + "-------------- item[label]: {} ----------------------------".format(item["label"])) + num_iter += 1 + assert num_iter == 10 def test_cv_minddataset_subset_random_sample_basic(add_and_remove_cv_file): diff --git a/tests/ut/python/dataset/test_mixup_op.py b/tests/ut/python/dataset/test_mixup_op.py new file mode 100644 index 0000000000..9641a642fe --- /dev/null +++ b/tests/ut/python/dataset/test_mixup_op.py @@ -0,0 +1,247 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================== +""" +Testing the MixUpBatch op in DE +""" +import numpy as np +import pytest +import mindspore.dataset as ds +import mindspore.dataset.transforms.vision.c_transforms as vision +import mindspore.dataset.transforms.c_transforms as data_trans +from mindspore import log as logger +from util import save_and_check_md5, diff_mse, visualize_list, config_get_set_seed, \ + config_get_set_num_parallel_workers + +DATA_DIR = "../data/dataset/testCifar10Data" + +GENERATE_GOLDEN = False + +def test_mixup_batch_success1(plot=False): + """ + Test MixUpBatch op with specified alpha parameter + """ + logger.info("test_mixup_batch_success1") + + # Original Images + ds_original = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + ds_original = ds_original.batch(5, drop_remainder=True) + + images_original = None + for idx, (image, _) in enumerate(ds_original): + if idx == 0: + images_original = image + else: + images_original = np.append(images_original, image, axis=0) + + # MixUp Images + data1 = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + + one_hot_op = data_trans.OneHot(num_classes=10) + data1 = data1.map(input_columns=["label"], operations=one_hot_op) + mixup_batch_op = vision.MixUpBatch(2) + data1 = data1.batch(5, drop_remainder=True) + data1 = data1.map(input_columns=["image", "label"], operations=mixup_batch_op) + + images_mixup = None + for idx, (image, _) in enumerate(data1): + if idx == 0: + images_mixup = image + else: + images_mixup = np.append(images_mixup, image, axis=0) + if plot: + visualize_list(images_original, images_mixup) + + num_samples = images_original.shape[0] + mse = np.zeros(num_samples) + for i in range(num_samples): + mse[i] = diff_mse(images_mixup[i], images_original[i]) + logger.info("MSE= {}".format(str(np.mean(mse)))) + + +def test_mixup_batch_success2(plot=False): + """ + Test MixUpBatch op without specified alpha parameter. + Alpha parameter will be selected by default in this case + """ + logger.info("test_mixup_batch_success2") + + # Original Images + ds_original = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + ds_original = ds_original.batch(5, drop_remainder=True) + + images_original = None + for idx, (image, _) in enumerate(ds_original): + if idx == 0: + images_original = image + else: + images_original = np.append(images_original, image, axis=0) + + # MixUp Images + data1 = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + + one_hot_op = data_trans.OneHot(num_classes=10) + data1 = data1.map(input_columns=["label"], operations=one_hot_op) + mixup_batch_op = vision.MixUpBatch() + data1 = data1.batch(5, drop_remainder=True) + data1 = data1.map(input_columns=["image", "label"], operations=mixup_batch_op) + + images_mixup = np.array([]) + for idx, (image, _) in enumerate(data1): + if idx == 0: + images_mixup = image + else: + images_mixup = np.append(images_mixup, image, axis=0) + if plot: + visualize_list(images_original, images_mixup) + + num_samples = images_original.shape[0] + mse = np.zeros(num_samples) + for i in range(num_samples): + mse[i] = diff_mse(images_mixup[i], images_original[i]) + logger.info("MSE= {}".format(str(np.mean(mse)))) + + +def test_mixup_batch_md5(): + """ + Test MixUpBatch with MD5: + """ + logger.info("test_mixup_batch_md5") + original_seed = config_get_set_seed(0) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) + + # MixUp Images + data = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + + one_hot_op = data_trans.OneHot(num_classes=10) + data = data.map(input_columns=["label"], operations=one_hot_op) + mixup_batch_op = vision.MixUpBatch() + data = data.batch(5, drop_remainder=True) + data = data.map(input_columns=["image", "label"], operations=mixup_batch_op) + + filename = "mixup_batch_c_result.npz" + save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + + # Restore config setting + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers(original_num_parallel_workers) + + +def test_mixup_batch_fail1(): + """ + Test MixUpBatch Fail 1 + We expect this to fail because the images and labels are not batched + """ + logger.info("test_mixup_batch_fail1") + + # Original Images + ds_original = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + ds_original = ds_original.batch(5) + + images_original = np.array([]) + for idx, (image, _) in enumerate(ds_original): + if idx == 0: + images_original = image + else: + images_original = np.append(images_original, image, axis=0) + + # MixUp Images + data1 = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + + one_hot_op = data_trans.OneHot(num_classes=10) + data1 = data1.map(input_columns=["label"], operations=one_hot_op) + mixup_batch_op = vision.MixUpBatch(0.1) + with pytest.raises(RuntimeError) as error: + data1 = data1.map(input_columns=["image", "label"], operations=mixup_batch_op) + for idx, (image, _) in enumerate(data1): + if idx == 0: + images_mixup = image + else: + images_mixup = np.append(images_mixup, image, axis=0) + error_message = "You must batch before calling MixUp" + assert error_message in str(error.value) + + +def test_mixup_batch_fail2(): + """ + Test MixUpBatch Fail 2 + We expect this to fail because alpha is negative + """ + logger.info("test_mixup_batch_fail2") + + # Original Images + ds_original = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + ds_original = ds_original.batch(5) + + images_original = np.array([]) + for idx, (image, _) in enumerate(ds_original): + if idx == 0: + images_original = image + else: + images_original = np.append(images_original, image, axis=0) + + # MixUp Images + data1 = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + + one_hot_op = data_trans.OneHot(num_classes=10) + data1 = data1.map(input_columns=["label"], operations=one_hot_op) + with pytest.raises(ValueError) as error: + vision.MixUpBatch(-1) + error_message = "Input is not within the required interval" + assert error_message in str(error.value) + + +def test_mixup_batch_fail3(): + """ + Test MixUpBatch op + We expect this to fail because label column is not passed to mixup_batch + """ + # Original Images + ds_original = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + ds_original = ds_original.batch(5, drop_remainder=True) + + images_original = None + for idx, (image, _) in enumerate(ds_original): + if idx == 0: + images_original = image + else: + images_original = np.append(images_original, image, axis=0) + + # MixUp Images + data1 = ds.Cifar10Dataset(DATA_DIR, num_samples=10, shuffle=False) + + one_hot_op = data_trans.OneHot(num_classes=10) + data1 = data1.map(input_columns=["label"], operations=one_hot_op) + mixup_batch_op = vision.MixUpBatch() + data1 = data1.batch(5, drop_remainder=True) + data1 = data1.map(input_columns=["image"], operations=mixup_batch_op) + + with pytest.raises(RuntimeError) as error: + images_mixup = np.array([]) + for idx, (image, _) in enumerate(data1): + if idx == 0: + images_mixup = image + else: + images_mixup = np.append(images_mixup, image, axis=0) + error_message = "Both images and labels columns are required" + assert error_message in str(error.value) + + +if __name__ == "__main__": + test_mixup_batch_success1(plot=True) + test_mixup_batch_success2(plot=True) + test_mixup_batch_md5() + test_mixup_batch_fail1() + test_mixup_batch_fail2() + test_mixup_batch_fail3() diff --git a/tests/ut/python/dataset/test_random_affine.py b/tests/ut/python/dataset/test_random_affine.py index ec829eb53a..68267030a7 100644 --- a/tests/ut/python/dataset/test_random_affine.py +++ b/tests/ut/python/dataset/test_random_affine.py @@ -18,6 +18,7 @@ Testing RandomAffine op in DE import numpy as np import mindspore.dataset as ds import mindspore.dataset.transforms.vision.py_transforms as py_vision +import mindspore.dataset.transforms.vision.c_transforms as c_vision from mindspore import log as logger from util import visualize_list, save_and_check_md5, \ config_get_set_seed, config_get_set_num_parallel_workers @@ -65,6 +66,39 @@ def test_random_affine_op(plot=False): visualize_list(image_original, image_affine) +def test_random_affine_op_c(plot=False): + """ + Test RandomAffine in C transformations + """ + logger.info("test_random_affine_op_c") + # define map operations + transforms1 = [ + c_vision.Decode(), + c_vision.RandomAffine(degrees=15, translate=(0.1, 0.1), scale=(0.9, 1.1)) + ] + + transforms2 = [ + c_vision.Decode() + ] + + # First dataset + data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + data1 = data1.map(input_columns=["image"], operations=transforms1) + # Second dataset + data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + data2 = data2.map(input_columns=["image"], operations=transforms2) + + image_affine = [] + image_original = [] + for item1, item2 in zip(data1.create_dict_iterator(), data2.create_dict_iterator()): + image1 = item1["image"] + image2 = item2["image"] + image_affine.append(image1) + image_original.append(image2) + if plot: + visualize_list(image_original, image_affine) + + def test_random_affine_md5(): """ Test RandomAffine with md5 comparison @@ -94,6 +128,33 @@ def test_random_affine_md5(): ds.config.set_num_parallel_workers((original_num_parallel_workers)) +def test_random_affine_c_md5(): + """ + Test RandomAffine C Op with md5 comparison + """ + logger.info("test_random_affine_c_md5") + original_seed = config_get_set_seed(1) + original_num_parallel_workers = config_get_set_num_parallel_workers(1) + # define map operations + transforms = [ + c_vision.Decode(), + c_vision.RandomAffine(degrees=(-5, 15), translate=(0.1, 0.3), + scale=(0.9, 1.1), shear=(-10, 10, -5, 5)) + ] + + # Generate dataset + data = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + data = data.map(input_columns=["image"], operations=transforms) + + # check results with md5 comparison + filename = "random_affine_01_c_result.npz" + save_and_check_md5(data, filename, generate_golden=GENERATE_GOLDEN) + + # Restore configuration + ds.config.set_seed(original_seed) + ds.config.set_num_parallel_workers((original_num_parallel_workers)) + + def test_random_affine_exception_negative_degrees(): """ Test RandomAffine: input degrees in negative, expected to raise ValueError @@ -199,7 +260,9 @@ def test_random_affine_exception_shear_size(): if __name__ == "__main__": test_random_affine_op(plot=True) + test_random_affine_op_c(plot=True) test_random_affine_md5() + test_random_affine_c_md5() test_random_affine_exception_negative_degrees() test_random_affine_exception_translation_range() test_random_affine_exception_scale_value() diff --git a/tests/ut/python/dataset/test_soft_dvpp.py b/tests/ut/python/dataset/test_soft_dvpp.py new file mode 100644 index 0000000000..1c8cfa9c9c --- /dev/null +++ b/tests/ut/python/dataset/test_soft_dvpp.py @@ -0,0 +1,90 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================== +""" +Testing soft dvpp SoftDvppDecodeResizeJpeg and SoftDvppDecodeRandomCropResizeJpeg in DE +""" +import mindspore.dataset as ds +import mindspore.dataset.transforms.vision.c_transforms as vision +from mindspore import log as logger +from util import diff_mse, visualize_image + +DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"] +SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json" + + +def test_soft_dvpp_decode_resize_jpeg(plot=False): + """ + Test SoftDvppDecodeResizeJpeg op + """ + logger.info("test_random_decode_resize_op") + + # First dataset + data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + decode_op = vision.Decode() + resize_op = vision.Resize((256, 512)) + data1 = data1.map(input_columns=["image"], operations=[decode_op, resize_op]) + + # Second dataset + data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + soft_dvpp_decode_resize_op = vision.SoftDvppDecodeResizeJpeg((256, 512)) + data2 = data2.map(input_columns=["image"], operations=soft_dvpp_decode_resize_op) + + num_iter = 0 + for item1, item2 in zip(data1.create_dict_iterator(), data2.create_dict_iterator()): + if num_iter > 0: + break + image1 = item1["image"] + image2 = item2["image"] + mse = diff_mse(image1, image2) + assert mse <= 0.02 + logger.info("random_crop_decode_resize_op_{}, mse: {}".format(num_iter + 1, mse)) + if plot: + visualize_image(image1, image2, mse) + num_iter += 1 + + +def test_soft_dvpp_decode_random_crop_resize_jpeg(plot=False): + """ + Test SoftDvppDecodeRandomCropResizeJpeg op + """ + logger.info("test_random_decode_resize_op") + + # First dataset + data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + random_crop_decode_resize_op = vision.RandomCropDecodeResize((256, 512), (1, 1), (0.5, 0.5)) + data1 = data1.map(input_columns=["image"], operations=random_crop_decode_resize_op) + + # Second dataset + data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False) + soft_dvpp_random_crop_decode_resize_op = vision.SoftDvppDecodeRandomCropResizeJpeg((256, 512), (1, 1), (0.5, 0.5)) + data2 = data2.map(input_columns=["image"], operations=soft_dvpp_random_crop_decode_resize_op) + + num_iter = 0 + for item1, item2 in zip(data1.create_dict_iterator(), data2.create_dict_iterator()): + if num_iter > 0: + break + image1 = item1["image"] + image2 = item2["image"] + mse = diff_mse(image1, image2) + assert mse <= 0.06 + logger.info("random_crop_decode_resize_op_{}, mse: {}".format(num_iter + 1, mse)) + if plot: + visualize_image(image1, image2, mse) + num_iter += 1 + + +if __name__ == "__main__": + test_soft_dvpp_decode_resize_jpeg(plot=True) + test_soft_dvpp_decode_random_crop_resize_jpeg(plot=True) diff --git a/tests/ut/python/dataset/util.py b/tests/ut/python/dataset/util.py index 65ea55824c..74009dbd05 100644 --- a/tests/ut/python/dataset/util.py +++ b/tests/ut/python/dataset/util.py @@ -200,6 +200,23 @@ def diff_me(in1, in2): return mse / 255 * 100 +def visualize_one_channel_dataset(images_original, images_transformed, labels): + """ + Helper function to visualize one channel grayscale images + """ + num_samples = len(images_original) + for i in range(num_samples): + plt.subplot(2, num_samples, i + 1) + # Note: Use squeeze() to convert (H, W, 1) images to (H, W) + plt.imshow(images_original[i].squeeze(), cmap=plt.cm.gray) + plt.title(PLOT_TITLE_DICT[1][0] + ":" + str(labels[i])) + + plt.subplot(2, num_samples, i + num_samples + 1) + plt.imshow(images_transformed[i].squeeze(), cmap=plt.cm.gray) + plt.title(PLOT_TITLE_DICT[1][1] + ":" + str(labels[i])) + plt.show() + + def visualize_list(image_list_1, image_list_2, visualize_mode=1): """ visualizes a list of images using DE op diff --git a/tests/ut/python/nn/bijector/test_exp.py b/tests/ut/python/nn/bijector/test_exp.py index 13e3e09a34..98f6315a5f 100644 --- a/tests/ut/python/nn/bijector/test_exp.py +++ b/tests/ut/python/nn/bijector/test_exp.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """test cases for exp""" +import pytest import mindspore.nn as nn import mindspore.nn.probability.bijector as msb from mindspore import Tensor @@ -21,8 +22,10 @@ from mindspore import dtype def test_init(): b = msb.Exp() assert isinstance(b, msb.Bijector) - b = msb.Exp(1.0) - assert isinstance(b, msb.Bijector) + +def test_type(): + with pytest.raises(TypeError): + msb.Exp(name=0.1) class Net(nn.Cell): """ diff --git a/tests/ut/python/nn/bijector/test_power_transform.py b/tests/ut/python/nn/bijector/test_power_transform.py index 50ea5dbd44..e5ed5cd271 100644 --- a/tests/ut/python/nn/bijector/test_power_transform.py +++ b/tests/ut/python/nn/bijector/test_power_transform.py @@ -13,6 +13,7 @@ # limitations under the License. # ============================================================================ """test cases for powertransform""" +import pytest import mindspore.nn as nn import mindspore.nn.probability.bijector as msb from mindspore import Tensor @@ -24,6 +25,12 @@ def test_init(): b = msb.PowerTransform(1) assert isinstance(b, msb.Bijector) +def test_type(): + with pytest.raises(TypeError): + msb.PowerTransform(power='power') + with pytest.raises(TypeError): + msb.PowerTransform(name=0.1) + class Net(nn.Cell): """ Test class: forward and inverse pass of bijector. diff --git a/tests/ut/python/nn/bijector/test_scalar_affine.py b/tests/ut/python/nn/bijector/test_scalar_affine.py new file mode 100644 index 0000000000..eab0946c7e --- /dev/null +++ b/tests/ut/python/nn/bijector/test_scalar_affine.py @@ -0,0 +1,139 @@ +# Copyright 2019 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +"""test cases for scalar affine""" +import pytest +import mindspore.nn as nn +import mindspore.nn.probability.bijector as msb +from mindspore import Tensor +from mindspore import dtype + +def test_init(): + """ + Test initializations. + """ + b = msb.ScalarAffine() + assert isinstance(b, msb.Bijector) + b = msb.ScalarAffine(scale=1.0) + assert isinstance(b, msb.Bijector) + b = msb.ScalarAffine(shift=2.0) + assert isinstance(b, msb.Bijector) + b = msb.ScalarAffine(3.0, 4.0) + assert isinstance(b, msb.Bijector) + +def test_type(): + with pytest.raises(TypeError): + msb.ScalarAffine(scale='scale') + with pytest.raises(TypeError): + msb.ScalarAffine(shift='shift') + with pytest.raises(TypeError): + msb.ScalarAffine(name=0.1) + +class ForwardBackward(nn.Cell): + """ + Test class: forward and backward pass. + """ + def __init__(self): + super(ForwardBackward, self).__init__() + self.b1 = msb.ScalarAffine(2.0, 1.0) + self.b2 = msb.ScalarAffine() + + def construct(self, x_): + ans1 = self.b1.inverse(self.b1.forward(x_)) + ans2 = self.b2.inverse(self.b2.forward(x_)) + return ans1 + ans2 + +def test_forward_and_backward_pass(): + """ + Test forward and backward pass of ScalarAffine bijector. + """ + net = ForwardBackward() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) + +class ForwardJacobian(nn.Cell): + """ + Test class: Forward log Jacobian. + """ + def __init__(self): + super(ForwardJacobian, self).__init__() + self.b1 = msb.ScalarAffine(2.0, 1.0) + self.b2 = msb.ScalarAffine() + + def construct(self, x_): + ans1 = self.b1.forward_log_jacobian(x_) + ans2 = self.b2.forward_log_jacobian(x_) + return ans1 + ans2 + +def test_forward_jacobian(): + """ + Test forward log jacobian of ScalarAffine bijector. + """ + net = ForwardJacobian() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) + + +class BackwardJacobian(nn.Cell): + """ + Test class: Backward log Jacobian. + """ + def __init__(self): + super(BackwardJacobian, self).__init__() + self.b1 = msb.ScalarAffine(2.0, 1.0) + self.b2 = msb.ScalarAffine() + + def construct(self, x_): + ans1 = self.b1.inverse_log_jacobian(x_) + ans2 = self.b2.inverse_log_jacobian(x_) + return ans1 + ans2 + +def test_backward_jacobian(): + """ + Test backward log jacobian of ScalarAffine bijector. + """ + net = BackwardJacobian() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) + + +class Net(nn.Cell): + """ + Test class: function calls going through construct. + """ + def __init__(self): + super(Net, self).__init__() + self.b1 = msb.ScalarAffine(1.0, 0.0) + self.b2 = msb.ScalarAffine() + + def construct(self, x_): + ans1 = self.b1('inverse', self.b1('forward', x_)) + ans2 = self.b2('inverse', self.b2('forward', x_)) + ans3 = self.b1('forward_log_jacobian', x_) + ans4 = self.b2('forward_log_jacobian', x_) + ans5 = self.b1('inverse_log_jacobian', x_) + ans6 = self.b2('inverse_log_jacobian', x_) + return ans1 - ans2 + ans3 -ans4 + ans5 - ans6 + +def test_old_api(): + """ + Test old api which goes through construct. + """ + net = Net() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) diff --git a/tests/ut/python/nn/bijector/test_softplus.py b/tests/ut/python/nn/bijector/test_softplus.py new file mode 100644 index 0000000000..4255751a78 --- /dev/null +++ b/tests/ut/python/nn/bijector/test_softplus.py @@ -0,0 +1,133 @@ +# Copyright 2019 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +"""test cases for scalar affine""" +import pytest +import mindspore.nn as nn +import mindspore.nn.probability.bijector as msb +from mindspore import Tensor +from mindspore import dtype + +def test_init(): + """ + Test initializations. + """ + b = msb.Softplus() + assert isinstance(b, msb.Bijector) + b = msb.Softplus(1.0) + assert isinstance(b, msb.Bijector) + +def test_type(): + with pytest.raises(TypeError): + msb.Softplus(sharpness='sharpness') + with pytest.raises(TypeError): + msb.Softplus(name=0.1) + +class ForwardBackward(nn.Cell): + """ + Test class: forward and backward pass. + """ + def __init__(self): + super(ForwardBackward, self).__init__() + self.b1 = msb.Softplus(2.0) + self.b2 = msb.Softplus() + + def construct(self, x_): + ans1 = self.b1.inverse(self.b1.forward(x_)) + ans2 = self.b2.inverse(self.b2.forward(x_)) + return ans1 + ans2 + +def test_forward_and_backward_pass(): + """ + Test forward and backward pass of Softplus bijector. + """ + net = ForwardBackward() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) + +class ForwardJacobian(nn.Cell): + """ + Test class: Forward log Jacobian. + """ + def __init__(self): + super(ForwardJacobian, self).__init__() + self.b1 = msb.Softplus(2.0) + self.b2 = msb.Softplus() + + def construct(self, x_): + ans1 = self.b1.forward_log_jacobian(x_) + ans2 = self.b2.forward_log_jacobian(x_) + return ans1 + ans2 + +def test_forward_jacobian(): + """ + Test forward log jacobian of Softplus bijector. + """ + net = ForwardJacobian() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) + + +class BackwardJacobian(nn.Cell): + """ + Test class: Backward log Jacobian. + """ + def __init__(self): + super(BackwardJacobian, self).__init__() + self.b1 = msb.Softplus(2.0) + self.b2 = msb.Softplus() + + def construct(self, x_): + ans1 = self.b1.inverse_log_jacobian(x_) + ans2 = self.b2.inverse_log_jacobian(x_) + return ans1 + ans2 + +def test_backward_jacobian(): + """ + Test backward log jacobian of Softplus bijector. + """ + net = BackwardJacobian() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) + + +class Net(nn.Cell): + """ + Test class: function calls going through construct. + """ + def __init__(self): + super(Net, self).__init__() + self.b1 = msb.Softplus(1.0) + self.b2 = msb.Softplus() + + def construct(self, x_): + ans1 = self.b1('inverse', self.b1('forward', x_)) + ans2 = self.b2('inverse', self.b2('forward', x_)) + ans3 = self.b1('forward_log_jacobian', x_) + ans4 = self.b2('forward_log_jacobian', x_) + ans5 = self.b1('inverse_log_jacobian', x_) + ans6 = self.b2('inverse_log_jacobian', x_) + return ans1 - ans2 + ans3 -ans4 + ans5 - ans6 + +def test_old_api(): + """ + Test old api which goes through construct. + """ + net = Net() + x = Tensor([2.0, 3.0, 4.0, 5.0], dtype=dtype.float32) + ans = net(x) + assert isinstance(ans, Tensor) diff --git a/tests/ut/python/nn/distribution/test_bernoulli.py b/tests/ut/python/nn/distribution/test_bernoulli.py index d34455dbe4..cecf563219 100644 --- a/tests/ut/python/nn/distribution/test_bernoulli.py +++ b/tests/ut/python/nn/distribution/test_bernoulli.py @@ -31,6 +31,18 @@ def test_arguments(): b = msd.Bernoulli([0.0, 0.3, 0.5, 1.0], dtype=dtype.int32) assert isinstance(b, msd.Distribution) +def test_type(): + with pytest.raises(TypeError): + msd.Bernoulli([0.1], dtype=dtype.float32) + +def test_name(): + with pytest.raises(TypeError): + msd.Bernoulli([0.1], name=1.0) + +def test_seed(): + with pytest.raises(TypeError): + msd.Bernoulli([0.1], seed='seed') + def test_prob(): """ Invalid probability. diff --git a/tests/ut/python/nn/distribution/test_exponential.py b/tests/ut/python/nn/distribution/test_exponential.py index 43aa428277..3452667db2 100644 --- a/tests/ut/python/nn/distribution/test_exponential.py +++ b/tests/ut/python/nn/distribution/test_exponential.py @@ -32,6 +32,18 @@ def test_arguments(): e = msd.Exponential([0.1, 0.3, 0.5, 1.0], dtype=dtype.float32) assert isinstance(e, msd.Distribution) +def test_type(): + with pytest.raises(TypeError): + msd.Exponential([0.1], dtype=dtype.int32) + +def test_name(): + with pytest.raises(TypeError): + msd.Exponential([0.1], name=1.0) + +def test_seed(): + with pytest.raises(TypeError): + msd.Exponential([0.1], seed='seed') + def test_rate(): """ Invalid rate. diff --git a/tests/ut/python/nn/distribution/test_geometric.py b/tests/ut/python/nn/distribution/test_geometric.py index b705aae781..11c12f62dc 100644 --- a/tests/ut/python/nn/distribution/test_geometric.py +++ b/tests/ut/python/nn/distribution/test_geometric.py @@ -32,6 +32,18 @@ def test_arguments(): g = msd.Geometric([0.0, 0.3, 0.5, 1.0], dtype=dtype.int32) assert isinstance(g, msd.Distribution) +def test_type(): + with pytest.raises(TypeError): + msd.Geometric([0.1], dtype=dtype.float32) + +def test_name(): + with pytest.raises(TypeError): + msd.Geometric([0.1], name=1.0) + +def test_seed(): + with pytest.raises(TypeError): + msd.Geometric([0.1], seed='seed') + def test_prob(): """ Invalid probability. diff --git a/tests/ut/python/nn/distribution/test_normal.py b/tests/ut/python/nn/distribution/test_normal.py index f569aa67a5..76602bde80 100644 --- a/tests/ut/python/nn/distribution/test_normal.py +++ b/tests/ut/python/nn/distribution/test_normal.py @@ -30,6 +30,17 @@ def test_normal_shape_errpr(): with pytest.raises(ValueError): msd.Normal([[2.], [1.]], [[2.], [3.], [4.]], dtype=dtype.float32) +def test_type(): + with pytest.raises(TypeError): + msd.Normal(0., 1., dtype=dtype.int32) + +def test_name(): + with pytest.raises(TypeError): + msd.Normal(0., 1., name=1.0) + +def test_seed(): + with pytest.raises(TypeError): + msd.Normal(0., 1., seed='seed') def test_arguments(): """ diff --git a/tests/ut/python/nn/distribution/test_uniform.py b/tests/ut/python/nn/distribution/test_uniform.py index a631998e83..82af4cb38d 100644 --- a/tests/ut/python/nn/distribution/test_uniform.py +++ b/tests/ut/python/nn/distribution/test_uniform.py @@ -30,6 +30,17 @@ def test_uniform_shape_errpr(): with pytest.raises(ValueError): msd.Uniform([[2.], [1.]], [[2.], [3.], [4.]], dtype=dtype.float32) +def test_type(): + with pytest.raises(TypeError): + msd.Uniform(0., 1., dtype=dtype.int32) + +def test_name(): + with pytest.raises(TypeError): + msd.Uniform(0., 1., name=1.0) + +def test_seed(): + with pytest.raises(TypeError): + msd.Uniform(0., 1., seed='seed') def test_arguments(): """ diff --git a/tests/ut/python/ops/test_nn_ops.py b/tests/ut/python/ops/test_nn_ops.py index ed7a8e695e..9eb1653ed6 100644 --- a/tests/ut/python/ops/test_nn_ops.py +++ b/tests/ut/python/ops/test_nn_ops.py @@ -584,7 +584,10 @@ test_cases = [ ('ReduceLogSumExp', { 'block': nn.ReduceLogSumExp((0,), False), 'desc_inputs': [Tensor(np.array([3, 4, 5, 6]).astype(np.float32))], - 'desc_bprop': [Tensor(np.array([1, 2, 3, 4]).astype(np.float32))], + 'skip': ['backward']}), + ('LGamma', { + 'block': nn.LGamma(), + 'desc_inputs': [Tensor(np.array([3, 4, 5, 6]).astype(np.float32))], 'skip': ['backward']}), ('FlattenNet', { 'block': FlattenNet(), diff --git a/tests/ut/python/parallel/test_concat.py b/tests/ut/python/parallel/test_concat.py new file mode 100644 index 0000000000..07b0eed89e --- /dev/null +++ b/tests/ut/python/parallel/test_concat.py @@ -0,0 +1,128 @@ +# Copyright 2020 Huawei Technologies Co., Ltd +# +# 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. +# ============================================================================ +import numpy as np + +import mindspore as ms +from mindspore import context, Tensor, Parameter +from mindspore.common.api import _executor +from mindspore.nn import Cell, TrainOneStepCell, Momentum +from mindspore.ops import operations as P + +class Net(Cell): + def __init__(self, weight, weight2, strategy1=None, strategy2=None, is_parameter=True): + super().__init__() + self.concat = P.Concat(axis=0).set_strategy(strategy1) + if is_parameter: + self.weight = Parameter(weight, "w1") + else: + self.weight = weight + self.mul = P.Mul().set_strategy(strategy2) + self.weight2 = Parameter(weight2, "w2") + + def construct(self, x, b): + out = self.concat((self.weight, self.weight2)) + out = self.mul(x, out) + return out + + +class Net2(Cell): + def __init__(self, weight, strategy1=None, strategy2=None, axis=0): + super().__init__() + self.mul = P.Mul().set_strategy(strategy1) + self.concat = P.Concat(axis=axis).set_strategy(strategy2) + self.weight = Parameter(weight, "w") + + def construct(self, x, b): + out = self.mul(x, b) + out = self.concat((out, self.weight)) + return out + + +_x = Tensor(np.ones([128, 64, 32]), dtype=ms.float32) +_w1 = Tensor(np.ones([96, 64, 32]), dtype=ms.float32) +_w2 = Tensor(np.ones([32, 64, 32]), dtype=ms.float32) +_w3 = Tensor(np.ones([128, 16, 32]), dtype=ms.float32) +_b = Tensor(np.ones([128, 64, 32]), dtype=ms.float32) + + +def compile_net(net): + context.set_context(save_graphs=True) + optimizer = Momentum(net.trainable_params(), learning_rate=0.1, momentum=0.9) + train_net = TrainOneStepCell(net, optimizer) + train_net.set_auto_parallel() + _executor.compile(train_net, _x, _b) + context.reset_auto_parallel_context() + + +def test_concat_parameter(): + context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) + strategy1 = ((1, 4, 2), (1, 4, 2)) + strategy2 = ((1, 4, 2), (1, 4, 2)) + net = Net(_w1, _w2, strategy1, strategy2, is_parameter=True) + compile_net(net) + + +def test_concat_parameter_no_full_split(): + context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) + strategy1 = ((1, 2, 2), (1, 2, 2)) + strategy2 = ((1, 4, 2), (1, 4, 2)) + net = Net(_w1, _w2, strategy1, strategy2, is_parameter=True) + compile_net(net) + + +def test_concat_tensor_and_parameter(): + context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) + strategy1 = ((1, 2, 2), (1, 2, 2)) + strategy2 = ((1, 4, 2), (1, 4, 2)) + net = Net(_w1, _w2, strategy1, strategy2, is_parameter=False) + compile_net(net) + + +def test_concat_output(): + context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) + strategy1 = ((2, 2, 2), (2, 2, 2)) + strategy2 = ((1, 4, 2), (1, 4, 2)) + net = Net2(_w1, strategy1, strategy2) + compile_net(net) + + +def test_concat_output_no_full_split(): + context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) + strategy1 = ((2, 2, 2), (2, 2, 2)) + strategy2 = ((1, 2, 2), (1, 2, 2)) + net = Net2(_w1, strategy1, strategy2) + compile_net(net) + + +def test_concat_no_strategy(): + context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=8, global_rank=0) + strategy1 = ((2, 2, 2), (2, 2, 2)) + strategy2 = None + net = Net2(_w3, strategy1, strategy2, axis=1) + compile_net(net) + + +def test_concat_auto_parallel(): + context.set_auto_parallel_context(parallel_mode="auto_parallel", device_num=8, global_rank=0) + net = Net2(_w2) + compile_net(net) + + +def test_concat_auto_parallel2(): + context.set_auto_parallel_context(parallel_mode="auto_parallel", device_num=8, global_rank=0) + strategy1 = None + strategy2 = None + net = Net2(_w3, strategy1, strategy2, axis=1) + compile_net(net) diff --git a/third_party/incubator-tvm b/third_party/incubator-tvm deleted file mode 160000 index c6f8c23c34..0000000000 --- a/third_party/incubator-tvm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c6f8c23c349f3ef8bacceaf3203f7cc08e6529de