提交 a29f1c8c 编写于 作者: M Megvii Engine Team

fix(cmake/midout): fix cmake midout

GitOrigin-RevId: 0fb93deb191ba235cbe312f7e7deaa979e810c9f
上级 369c2ccc
...@@ -50,7 +50,7 @@ option(MGE_WITH_JIT "Build MegEngine with JIT." ON) ...@@ -50,7 +50,7 @@ option(MGE_WITH_JIT "Build MegEngine with JIT." ON)
option(MGE_WITH_JIT_MLIR "Build MegEngine with MLIR JIT." OFF) option(MGE_WITH_JIT_MLIR "Build MegEngine with MLIR JIT." OFF)
option(MGE_WITH_HALIDE "Build MegEngine with Halide JIT" OFF) option(MGE_WITH_HALIDE "Build MegEngine with Halide JIT" OFF)
option(MGE_WITH_MIDOUT_PROFILE "Build MegEngine with Midout profile." OFF) option(MGE_WITH_MIDOUT_PROFILE "Build MegEngine with Midout profile." OFF)
option(MGE_WITH_MINIMUM_SIZE "Swith off MGE_ENABLE_RTTI、MGE_ENABLE_EXCEPTIONS、MGE_ENABLE_LOGGING and switch on MGE_INFERENCE_ONLY so that compile minimum load_and_run. Take effect only when MGE_BIN_REDUCE was set" OFF) option(MGE_WITH_MINIMUM_SIZE "Swith off MGE_ENABLE_RTTI、MGE_ENABLE_EXCEPTIONS、MGE_ENABLE_LOGGING and switch on MGE_INFERENCE_ONLY so that compile minimum load_and_run." OFF)
option(MGE_ARMV8_2_FEATURE_FP16 "Enable armv8.2-a+fp16 support" OFF) option(MGE_ARMV8_2_FEATURE_FP16 "Enable armv8.2-a+fp16 support" OFF)
option(MGE_DISABLE_FLOAT16 "Disable MegEngine float16 support." OFF) option(MGE_DISABLE_FLOAT16 "Disable MegEngine float16 support." OFF)
option(MGE_WITH_CUDA "Enable MegEngine CUDA support." ON) option(MGE_WITH_CUDA "Enable MegEngine CUDA support." ON)
...@@ -143,16 +143,32 @@ else() ...@@ -143,16 +143,32 @@ else()
set(MGE_WITH_ANY_CUDA_STUB OFF) set(MGE_WITH_ANY_CUDA_STUB OFF)
endif() endif()
if(NOT ${MGE_BIN_REDUCE} STREQUAL "") if(MGE_WITH_MIDOUT_PROFILE)
message(STATUS "build with BIN REDUCE") message(STATUS "build with MIDOUT PROFILE and force set MGE_WITH_MINIMUM_SIZE off and force rtti ON")
if(MGE_WITH_MINIMUM_SIZE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMIDOUT_PROFILING")
set(MGE_ENABLE_RTTI OFF) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMIDOUT_PROFILING")
set(MGE_ENABLE_LOGGING OFF) set(MGE_WITH_MINIMUM_SIZE OFF)
set(MGE_ENABLE_EXCEPTIONS OFF) set(MGE_ENABLE_RTTI ON)
set(MGE_INFERENCE_ONLY ON) if(WIN32)
message(FATAL_ERROR "do not support midout at WIN32")
endif() endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${MGE_BIN_REDUCE}") endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include ${MGE_BIN_REDUCE}")
set(BIN_REDUCE ${PROJECT_SOURCE_DIR}/src/bin_reduce_cmake.h)
if(MGE_WITH_MINIMUM_SIZE)
message(STATUS "build with MGE_WITH_MINIMUM_SIZE bin_reduce header is: ${BIN_REDUCE}")
set(MGE_ENABLE_RTTI OFF)
set(MGE_ENABLE_LOGGING OFF)
set(MGE_ENABLE_EXCEPTIONS OFF)
set(MGE_INFERENCE_ONLY ON)
# MGE_WITH_MINIMUM_SIZE will triger unused-parameter
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
endif()
if(NOT MGE_WITH_MIDOUT_PROFILE AND NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include ${BIN_REDUCE}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -include ${BIN_REDUCE}")
endif() endif()
if (NOT APPLE) if (NOT APPLE)
...@@ -176,12 +192,6 @@ else() ...@@ -176,12 +192,6 @@ else()
message(STATUS "lto is not supported in this compiler") message(STATUS "lto is not supported in this compiler")
endif() endif()
if(MGE_WITH_MIDOUT_PROFILE)
message(STATUS "build with MIDOUT PROFILE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMIDOUT_PROFILING")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMIDOUT_PROFILING")
endif()
if (APPLE) if (APPLE)
set (BUILD_SHARED_LIBS OFF) set (BUILD_SHARED_LIBS OFF)
message(STATUS "build static for xcode framework require") message(STATUS "build static for xcode framework require")
...@@ -253,9 +263,9 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) ...@@ -253,9 +263,9 @@ if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo) set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif() endif()
if(${CMAKE_BUILD_TYPE} STREQUAL "Release" AND NOT MGE_WITH_TEST AND NOT ${MGE_ARCH} STREQUAL "x86_64") if(${CMAKE_BUILD_TYPE} STREQUAL "Release" AND NOT MGE_WITH_TEST AND NOT ${MGE_ARCH} STREQUAL "x86_64" AND NOT MGE_WITH_MIDOUT_PROFILE)
set(MGE_ENABLE_RTTI OFF) set(MGE_ENABLE_RTTI OFF)
message(STATUS "disable MGE_ENABLE_RTTI when Release/NON-x86_64 mode!!") message(STATUS "disable MGE_ENABLE_RTTI when Release/NON-x86_64/NON-MGE_WITH_MIDOUT_PROFILE mode!!")
endif() endif()
if(MSVC OR WIN32) if(MSVC OR WIN32)
......
...@@ -83,9 +83,11 @@ LTensorLayout lite::to_impl_layout(const Layout& layout) { ...@@ -83,9 +83,11 @@ LTensorLayout lite::to_impl_layout(const Layout& layout) {
case LiteDataType::LITE_FLOAT: case LiteDataType::LITE_FLOAT:
mge_layout.dtype = mgb::dtype::Float32(); mge_layout.dtype = mgb::dtype::Float32();
break; break;
#if !MEGDNN_DISABLE_FLOAT16
case LiteDataType::LITE_HALF: case LiteDataType::LITE_HALF:
mge_layout.dtype = mgb::dtype::Float16(); mge_layout.dtype = mgb::dtype::Float16();
break; break;
#endif
case LiteDataType::LITE_INT: case LiteDataType::LITE_INT:
mge_layout.dtype = mgb::dtype::Int32(); mge_layout.dtype = mgb::dtype::Int32();
break; break;
...@@ -120,9 +122,11 @@ Layout lite::to_lite_layout(const LTensorLayout& mge_layout) { ...@@ -120,9 +122,11 @@ Layout lite::to_lite_layout(const LTensorLayout& mge_layout) {
case mgb::DTypeEnum::Float32: case mgb::DTypeEnum::Float32:
layout.data_type = LiteDataType::LITE_FLOAT; layout.data_type = LiteDataType::LITE_FLOAT;
break; break;
#if !MEGDNN_DISABLE_FLOAT16
case mgb::DTypeEnum::Float16: case mgb::DTypeEnum::Float16:
layout.data_type = LiteDataType::LITE_HALF; layout.data_type = LiteDataType::LITE_HALF;
break; break;
#endif
case mgb::DTypeEnum::Int32: case mgb::DTypeEnum::Int32:
layout.data_type = LiteDataType::LITE_INT; layout.data_type = LiteDataType::LITE_INT;
break; break;
......
/**
* \file src/bin_reduce_cmake.h
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
*
* Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/
/*
* always empty, override by ../tools/gen_header_for_bin_reduce.py
*/
/** /**
* \file src/core/include/megbrain_build_config.h * \file src/megbrain_build_config.h.in
* MegEngine is Licensed under the Apache License, Version 2.0 (the "License") * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
* *
* Copyright (c) 2014-2021 Megvii Inc. All rights reserved. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
......
...@@ -53,7 +53,16 @@ class HeaderGen: ...@@ -53,7 +53,16 @@ class HeaderGen:
cls._megvii3_root_cache = str(wd) cls._megvii3_root_cache = str(wd)
return cls._megvii3_root_cache return cls._megvii3_root_cache
wd = wd.parent wd = wd.parent
raise RuntimeError('This script is supposed to run in megvii3.') return None
_megengine_root_cache = None
@classmethod
def get_megengine_root(cls):
if cls._megengine_root_cache is not None:
return cls._megengine_root_cache
wd = Path(__file__).resolve().parent.parent
cls._megengine_root_cache = str(wd)
return cls._megengine_root_cache
def extend_netinfo(self, data): def extend_netinfo(self, data):
self._has_netinfo = True self._has_netinfo = True
...@@ -125,11 +134,11 @@ class HeaderGen: ...@@ -125,11 +134,11 @@ class HeaderGen:
with tempfile.NamedTemporaryFile() as ftmp: with tempfile.NamedTemporaryFile() as ftmp:
fpath = os.path.realpath(ftmp.name) fpath = os.path.realpath(ftmp.name)
subprocess.check_call( subprocess.check_call(
['./brain/megbrain/dnn/scripts/gen_param_defs.py', ['./dnn/scripts/gen_param_defs.py',
'--write-enum-items', 'Elemwise:Mode', '--write-enum-items', 'Elemwise:Mode',
'./brain/megbrain/dnn/scripts/opr_param_defs.py', './dnn/scripts/opr_param_defs.py',
fpath], fpath],
cwd=self.get_megvii3_root() cwd=self.get_megengine_root()
) )
with open(fpath) as fin: with open(fpath) as fin:
...@@ -178,8 +187,10 @@ class HeaderGen: ...@@ -178,8 +187,10 @@ class HeaderGen:
if not self._midout_files: if not self._midout_files:
return return
gen = os.path.join(self.get_megvii3_root(), 'brain', 'midout', gen = os.path.join(self.get_megengine_root(), 'third_party', 'midout', 'gen_header.py')
'gen_header.py') if self.get_megvii3_root():
gen = os.path.join(self.get_megvii3_root(), 'brain', 'midout', 'gen_header.py')
print('use {} to gen bin_reduce header'.format(gen))
cvt = subprocess.run( cvt = subprocess.run(
[gen] + self._midout_files, [gen] + self._midout_files,
stdout=subprocess.PIPE, check=True, stdout=subprocess.PIPE, check=True,
...@@ -212,10 +223,13 @@ def main(): ...@@ -212,10 +223,13 @@ def main():
' 1. json files generated by ' ' 1. json files generated by '
'megbrain.serialize_comp_graph_to_file() in python; ' 'megbrain.serialize_comp_graph_to_file() in python; '
' 2. trace files generated by midout library') ' 2. trace files generated by midout library')
parser.add_argument('-o', '--output', help='output file', default_file=os.path.join(HeaderGen.get_megengine_root(), 'src', 'bin_reduce_cmake.h')
default=os.path.join(HeaderGen.get_megvii3_root(), is_megvii3 = HeaderGen.get_megvii3_root()
'utils', 'bin_reduce.h')) if is_megvii3:
default_file=os.path.join(HeaderGen.get_megvii3_root(), 'utils', 'bin_reduce.h')
parser.add_argument('-o', '--output', help='output file', default=default_file)
args = parser.parse_args() args = parser.parse_args()
print('config output file: {}'.format(args.output))
gen = HeaderGen() gen = HeaderGen()
for i in args.inputs: for i in args.inputs:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册