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

feat(cmake): format all cmake file

GitOrigin-RevId: 0a4ecab99b0251bd4c4ee5c49d155343c7759c84
上级 769302e4
此差异已折叠。
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
# General function to create FlatBuffer build rules for the given list of
# schemas.
# General function to create FlatBuffer build rules for the given list of schemas.
#
# flatbuffers_schemas: A list of flatbuffer schema files to process.
#
# schema_include_dirs: A list of schema file include directories, which will be
# passed to flatc via the -I parameter.
# schema_include_dirs: A list of schema file include directories, which will be passed
# to flatc via the -I parameter.
#
# custom_target_name: The generated files will be added as dependencies for a
# new custom target with this name. You should add that target as a dependency
# for your main target to ensure these files are built. You can also retrieve
# various properties from this target, such as GENERATED_INCLUDES_DIR,
# BINARY_SCHEMAS_DIR, and COPY_TEXT_SCHEMAS_DIR.
# custom_target_name: The generated files will be added as dependencies for a new custom
# target with this name. You should add that target as a dependency for your main target
# to ensure these files are built. You can also retrieve various properties from this
# target, such as GENERATED_INCLUDES_DIR, BINARY_SCHEMAS_DIR, and COPY_TEXT_SCHEMAS_DIR.
#
# additional_dependencies: A list of additional dependencies that you'd like
# all generated files to depend on. Pass in a blank string if you have none.
# additional_dependencies: A list of additional dependencies that you'd like all
# generated files to depend on. Pass in a blank string if you have none.
#
# generated_includes_dir: Where to generate the C++ header files for these
# schemas. The generated includes directory will automatically be added to
# CMake's include directories, and will be where generated header files are
# placed. This parameter is optional; pass in empty string if you don't want to
# generate include files for these schemas.
# generated_includes_dir: Where to generate the C++ header files for these schemas. The
# generated includes directory will automatically be added to CMake's include
# directories, and will be where generated header files are placed. This parameter is
# optional; pass in empty string if you don't want to generate include files for these
# schemas.
#
# binary_schemas_dir: If you specify an optional binary schema directory, binary
# schemas will be generated for these schemas as well, and placed into the given
# directory.
# binary_schemas_dir: If you specify an optional binary schema directory, binary schemas
# will be generated for these schemas as well, and placed into the given directory.
#
# copy_text_schemas_dir: If you want all text schemas (including schemas from
# all schema include directories) copied into a directory (for example, if you
# need them within your project to build JSON files), you can specify that
# folder here. All text schemas will be copied to that folder.
# copy_text_schemas_dir: If you want all text schemas (including schemas from all schema
# include directories) copied into a directory (for example, if you need them within
# your project to build JSON files), you can specify that folder here. All text schemas
# will be copied to that folder.
#
# IMPORTANT: Make sure you quote all list arguments you pass to this function!
# Otherwise CMake will only pass in the first element.
# Example: build_flatbuffers("${fb_files}" "${include_dirs}" target_name ...)
function(build_flatbuffers flatbuffers_schemas
schema_include_dirs
custom_target_name
additional_dependencies
generated_includes_dir
binary_schemas_dir
copy_text_schemas_dir)
# IMPORTANT: Make sure you quote all list arguments you pass to this function! Otherwise
# CMake will only pass in the first element. Example: build_flatbuffers("${fb_files}"
# "${include_dirs}" target_name ...)
function(
build_flatbuffers
flatbuffers_schemas
schema_include_dirs
custom_target_name
additional_dependencies
generated_includes_dir
binary_schemas_dir
copy_text_schemas_dir)
# Test if including from FindFlatBuffers
if(FLATBUFFERS_FLATC_EXECUTABLE)
......@@ -65,10 +62,7 @@ function(build_flatbuffers flatbuffers_schemas
endif()
set(FLATC_SCHEMA_ARGS --gen-mutable)
if(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS)
set(FLATC_SCHEMA_ARGS
${FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS}
${FLATC_SCHEMA_ARGS}
)
set(FLATC_SCHEMA_ARGS ${FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS} ${FLATC_SCHEMA_ARGS})
endif()
set(working_dir "${CMAKE_CURRENT_SOURCE_DIR}")
......@@ -77,12 +71,12 @@ function(build_flatbuffers flatbuffers_schemas
# Generate the include files parameters.
set(include_params "")
set(all_generated_files "")
foreach (include_dir ${schema_include_dirs})
foreach(include_dir ${schema_include_dirs})
set(include_params -I ${include_dir} ${include_params})
if (NOT ${copy_text_schemas_dir} STREQUAL "")
if(NOT ${copy_text_schemas_dir} STREQUAL "")
# Copy text schemas from dependent folders.
file(GLOB_RECURSE dependent_schemas ${include_dir}/${schema_glob})
foreach (dependent_schema ${dependent_schemas})
foreach(dependent_schema ${dependent_schemas})
file(COPY ${dependent_schema} DESTINATION ${copy_text_schemas_dir})
endforeach()
endif()
......@@ -91,62 +85,54 @@ function(build_flatbuffers flatbuffers_schemas
foreach(schema ${flatbuffers_schemas})
get_filename_component(filename ${schema} NAME_WE)
# For each schema, do the things we requested.
if (NOT ${generated_includes_dir} STREQUAL "")
if(NOT ${generated_includes_dir} STREQUAL "")
set(generated_include ${generated_includes_dir}/${filename}_generated.h)
add_custom_command(
OUTPUT ${generated_include}
COMMAND ${FLATC} ${FLATC_SCHEMA_ARGS}
-o ${generated_includes_dir}
${include_params}
-c ${schema}
COMMAND ${FLATC} ${FLATC_SCHEMA_ARGS} -o ${generated_includes_dir}
${include_params} -c ${schema}
DEPENDS ${FLATC_TARGET} ${schema} ${additional_dependencies}
WORKING_DIRECTORY "${working_dir}")
list(APPEND all_generated_files ${generated_include})
endif()
if (NOT ${binary_schemas_dir} STREQUAL "")
if(NOT ${binary_schemas_dir} STREQUAL "")
set(binary_schema ${binary_schemas_dir}/${filename}.bfbs)
add_custom_command(
OUTPUT ${binary_schema}
COMMAND ${FLATC} -b --schema
-o ${binary_schemas_dir}
${include_params}
${schema}
COMMAND ${FLATC} -b --schema -o ${binary_schemas_dir} ${include_params}
${schema}
DEPENDS ${FLATC_TARGET} ${schema} ${additional_dependencies}
WORKING_DIRECTORY "${working_dir}")
list(APPEND all_generated_files ${binary_schema})
endif()
if (NOT ${copy_text_schemas_dir} STREQUAL "")
if(NOT ${copy_text_schemas_dir} STREQUAL "")
file(COPY ${schema} DESTINATION ${copy_text_schemas_dir})
endif()
endforeach()
# Create a custom target that depends on all the generated files.
# This is the target that you can depend on to trigger all these
# to be built.
add_custom_target(${custom_target_name}
DEPENDS ${all_generated_files} ${additional_dependencies})
# Create a custom target that depends on all the generated files. This is the target
# that you can depend on to trigger all these to be built.
add_custom_target(${custom_target_name} DEPENDS ${all_generated_files}
${additional_dependencies})
# Register the include directory we are using.
if (NOT ${generated_includes_dir} STREQUAL "")
if(NOT ${generated_includes_dir} STREQUAL "")
include_directories(${generated_includes_dir})
set_property(TARGET ${custom_target_name}
PROPERTY GENERATED_INCLUDES_DIR
${generated_includes_dir})
set_property(TARGET ${custom_target_name} PROPERTY GENERATED_INCLUDES_DIR
${generated_includes_dir})
endif()
# Register the binary schemas dir we are using.
if (NOT ${binary_schemas_dir} STREQUAL "")
set_property(TARGET ${custom_target_name}
PROPERTY BINARY_SCHEMAS_DIR
${binary_schemas_dir})
if(NOT ${binary_schemas_dir} STREQUAL "")
set_property(TARGET ${custom_target_name} PROPERTY BINARY_SCHEMAS_DIR
${binary_schemas_dir})
endif()
# Register the text schema copy dir we are using.
if (NOT ${copy_text_schemas_dir} STREQUAL "")
set_property(TARGET ${custom_target_name}
PROPERTY COPY_TEXT_SCHEMAS_DIR
${copy_text_schemas_dir})
if(NOT ${copy_text_schemas_dir} STREQUAL "")
set_property(TARGET ${custom_target_name} PROPERTY COPY_TEXT_SCHEMAS_DIR
${copy_text_schemas_dir})
endif()
endfunction()
# Parses the version set in src/core/include/megbrain/version.h
# Exports the following variables:
# MGB_VER_MAJOR: Major version
# MGB_VER_MINOR: Minor version
# MGB_VER_PATCH: Patch version
# MGB_IS_DEV: Is development version
# MGB_VER_STRING: Version string
# Parses the version set in src/core/include/megbrain/version.h Exports the following
# variables: MGB_VER_MAJOR: Major version MGB_VER_MINOR: Minor version MGB_VER_PATCH:
# Patch version MGB_IS_DEV: Is development version MGB_VER_STRING: Version string
option(MGB_FORCE_DEV_VERSION "Force -dev tag in version stamp" OFF)
file (READ "${CMAKE_CURRENT_SOURCE_DIR}/src/core/include/megbrain/version.h" content)
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/core/include/megbrain/version.h" content)
string (REGEX MATCH "MGB_MAJOR +([0-9]+)" _ ${content})
set (MGB_VER_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "MGB_MAJOR +([0-9]+)" _ ${content})
set(MGB_VER_MAJOR ${CMAKE_MATCH_1})
string (REGEX MATCH "MGB_MINOR +([0-9]+)" _ ${content})
set (MGB_VER_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "MGB_MINOR +([0-9]+)" _ ${content})
set(MGB_VER_MINOR ${CMAKE_MATCH_1})
string (REGEX MATCH "MGB_PATCH *([0-9]+)" _ ${content})
set (MGB_VER_PATCH ${CMAKE_MATCH_1})
string(REGEX MATCH "MGB_PATCH *([0-9]+)" _ ${content})
set(MGB_VER_PATCH ${CMAKE_MATCH_1})
string (REGEX MATCH "MGE_MAJOR +([0-9]+)" _ ${content})
set (MGE_VER_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "MGE_MAJOR +([0-9]+)" _ ${content})
set(MGE_VER_MAJOR ${CMAKE_MATCH_1})
string (REGEX MATCH "MGE_MINOR +([0-9]+)" _ ${content})
set (MGE_VER_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "MGE_MINOR +([0-9]+)" _ ${content})
set(MGE_VER_MINOR ${CMAKE_MATCH_1})
string (REGEX MATCH "MGE_PATCH *([0-9]+)" _ ${content})
set (MGE_VER_PATCH ${CMAKE_MATCH_1})
string(REGEX MATCH "MGE_PATCH *([0-9]+)" _ ${content})
set(MGE_VER_PATCH ${CMAKE_MATCH_1})
string (REGEX MATCH "MGE_EXTRA_NAME *\"(.*)\"" _ ${content})
set (MGE_EXTRA_NAME ${CMAKE_MATCH_1})
string(REGEX MATCH "MGE_EXTRA_NAME *\"(.*)\"" _ ${content})
set(MGE_EXTRA_NAME ${CMAKE_MATCH_1})
if (MGB_FORCE_DEV_VERSION)
set (MGB_IS_DEV 1)
if(MGB_FORCE_DEV_VERSION)
set(MGB_IS_DEV 1)
else()
string (REGEX MATCH "MGB_IS_DEV +([01])" _ ${content})
set (MGB_IS_DEV ${CMAKE_MATCH_1})
string(REGEX MATCH "MGB_IS_DEV +([01])" _ ${content})
set(MGB_IS_DEV ${CMAKE_MATCH_1})
endif()
if (DEFINED MGB_VER_MAJOR)
set (MGB_VER_STRING "${MGB_VER_MAJOR}.${MGB_VER_MINOR}.${MGB_VER_PATCH}")
if(DEFINED MGB_VER_MAJOR)
set(MGB_VER_STRING "${MGB_VER_MAJOR}.${MGB_VER_MINOR}.${MGB_VER_PATCH}")
else()
set (MGB_VER_STRING "${MGE_VER_MAJOR}.${MGE_VER_MINOR}.${MGE_VER_PATCH}")
set(MGB_VER_STRING "${MGE_VER_MAJOR}.${MGE_VER_MINOR}.${MGE_VER_PATCH}")
endif(DEFINED MGB_VER_MAJOR)
if (MGB_IS_DEV)
set (MGB_VER_STRING "${MGB_VER_STRING}-dev")
if(MGB_IS_DEV)
set(MGB_VER_STRING "${MGB_VER_STRING}-dev")
endif()
message(STATUS "Building MegBrain ${MGB_VER_STRING}")
......@@ -2,31 +2,40 @@
include(ExternalProject)
find_package(LLVM 6.0 REQUIRED CONFIG)
STRING(REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION})
string(REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION})
list(GET LLVM_VERSION_LIST 0 LLVM_VERSION_MAJOR)
list(GET LLVM_VERSION_LIST 1 LLVM_VERSION_MINOR)
set(HALIDE_DIR "${PROJECT_SOURCE_DIR}/third_party/Halide" CACHE STRING "halide directory")
set(HALIDE_DIR
"${PROJECT_SOURCE_DIR}/third_party/Halide"
CACHE STRING "halide directory")
set(HALIDE_BUILD_DIR ${PROJECT_BINARY_DIR}/third_party/Halide)
set(HALIDE_LIB ${HALIDE_BUILD_DIR}/lib/libHalide.a)
ExternalProject_add(
halide
SOURCE_DIR ${HALIDE_DIR}
PREFIX ${HALIDE_BUILD_DIR}
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_INSTALL_PREFIX=${HALIDE_BUILD_DIR} -DWITH_APPS=OFF -DWITH_TESTS=OFF -DWITH_TUTORIALS=OFF -DHALIDE_SHARED_LIBRARY=OFF -DHALIDE_REQUIRE_LLVM_VERSION=${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR} -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DTARGET_MIPS=OFF -DTARGET_POWERPC=OFF
BUILD_BYPRODUCTS ${HALIDE_LIB}
)
ExternalProject_Add(
halide
SOURCE_DIR ${HALIDE_DIR}
PREFIX ${HALIDE_BUILD_DIR}
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_PREFIX=${HALIDE_BUILD_DIR}
-DWITH_APPS=OFF
-DWITH_TESTS=OFF
-DWITH_TUTORIALS=OFF
-DHALIDE_SHARED_LIBRARY=OFF
-DHALIDE_REQUIRE_LLVM_VERSION=${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DTARGET_MIPS=OFF
-DTARGET_POWERPC=OFF
BUILD_BYPRODUCTS ${HALIDE_LIB})
set(HALIDE_INC ${HALIDE_BUILD_DIR}/include)
file(MAKE_DIRECTORY ${HALIDE_INC})
add_library(libhalide STATIC IMPORTED GLOBAL)
add_dependencies(libhalide halide)
set_target_properties(
libhalide PROPERTIES
IMPORTED_LOCATION ${HALIDE_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${HALIDE_INC}
)
set_target_properties(libhalide PROPERTIES IMPORTED_LOCATION ${HALIDE_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${HALIDE_INC})
set(LLVM_COMPONENTS mcjit;bitwriter;linker;passes;X86;ARM;AArch64;Hexagon;NVPTX;AMDGPU)
llvm_map_components_to_libnames(HALIDE_LLVM_LIBS ${LLVM_COMPONENTS})
if (MGE_USE_SYSTEM_LIB)
find_package(dnnl)
if (dnnl_FOUND)
message(STATUS "Using system provided MKL-DNN.")
set (MGE_USE_SYSTEM_MKLDNN ON)
return()
endif()
if(MGE_USE_SYSTEM_LIB)
find_package(dnnl)
if(dnnl_FOUND)
message(STATUS "Using system provided MKL-DNN.")
set(MGE_USE_SYSTEM_MKLDNN ON)
return()
endif()
endif()
option(DNNL_BUILD_TESTS "" OFF)
option(DNNL_BUILD_EXAMPLES "" OFF)
# we do not want to use OMP now, so config to CPU mode
# if set to OMP, some dnnl algo will be more fast
set(DNNL_CPU_RUNTIME "SEQ" CACHE STRING "config dnnl to DNNL_RUNTIME_SEQ")
# we do not want to use OMP now, so config to CPU mode if set to OMP, some dnnl algo
# will be more fast
set(DNNL_CPU_RUNTIME
"SEQ"
CACHE STRING "config dnnl to DNNL_RUNTIME_SEQ")
if(MGE_BLAS STREQUAL "MKL")
option(_DNNL_USE_MKL "" ON)
set(MKLROOT ${MKL_ROOT_DIR} CACHE STRING "MKL ROOT FOR DNNL")
set(MKLLIB libmkl)
option(_DNNL_USE_MKL "" ON)
set(MKLROOT
${MKL_ROOT_DIR}
CACHE STRING "MKL ROOT FOR DNNL")
set(MKLLIB libmkl)
else()
option(_DNNL_USE_MKL "" OFF)
option(_DNNL_USE_MKL "" OFF)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter -Wno-extra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-extra")
set(DNNL_LIBRARY_TYPE STATIC CACHE STRING "config dnnl to STATIC")
set(DNNL_LIBRARY_TYPE
STATIC
CACHE STRING "config dnnl to STATIC")
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/intel-mkl-dnn)
# - Find the NumPy libraries
# This module finds if NumPy is installed, and sets the following variables
# indicating where it is.
# * Find the NumPy libraries This module finds if NumPy is installed, and sets the
# following variables indicating where it is.
#
# TODO: Update to provide the libraries and paths for linking npymath lib.
#
# NUMPY_FOUND - was NumPy found
# NUMPY_VERSION - the version of NumPy found as a string
# NUMPY_VERSION_MAJOR - the major version number of NumPy
# NUMPY_VERSION_MINOR - the minor version number of NumPy
# NUMPY_VERSION_PATCH - the patch version number of NumPy
# NUMPY_VERSION_DECIMAL - e.g. version 1.6.1 is 10601
# NUMPY_INCLUDE_DIR - path to the NumPy include files
# NUMPY_FOUND - was NumPy found NUMPY_VERSION - the version of
# NumPy found as a string NUMPY_VERSION_MAJOR - the major version number of NumPy
# NUMPY_VERSION_MINOR - the minor version number of NumPy NUMPY_VERSION_PATCH -
# the patch version number of NumPy NUMPY_VERSION_DECIMAL - e.g. version 1.6.1 is
# 10601 NUMPY_INCLUDE_DIR - path to the NumPy include files
unset(NUMPY_VERSION)
unset(NUMPY_INCLUDE_DIR)
if(PYTHONINTERP_FOUND)
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import numpy as n; print(n.__version__); print(n.get_include());"
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" "-c"
"import numpy as n; print(n.__version__); print(n.get_include());"
RESULT_VARIABLE __result
OUTPUT_VARIABLE __output
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(__result MATCHES 0)
string(REGEX REPLACE ";" "\\\\;" __values ${__output})
string(REGEX REPLACE "\r?\n" ";" __values ${__values})
string(REGEX REPLACE "\r?\n" ";" __values ${__values})
list(GET __values 0 NUMPY_VERSION)
list(GET __values 1 NUMPY_INCLUDE_DIR)
......@@ -33,13 +31,18 @@ if(PYTHONINTERP_FOUND)
set(NUMPY_VERSION_MAJOR ${CMAKE_MATCH_1})
set(NUMPY_VERSION_MINOR ${CMAKE_MATCH_2})
set(NUMPY_VERSION_PATCH ${CMAKE_MATCH_3})
math(EXPR NUMPY_VERSION_DECIMAL
"(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}")
string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIR ${NUMPY_INCLUDE_DIR})
math(
EXPR
NUMPY_VERSION_DECIMAL
"(${NUMPY_VERSION_MAJOR} * 10000) + (${NUMPY_VERSION_MINOR} * 100) + ${NUMPY_VERSION_PATCH}"
)
string(REGEX REPLACE "\\\\" "/" NUMPY_INCLUDE_DIR ${NUMPY_INCLUDE_DIR})
else()
unset(NUMPY_VERSION)
unset(NUMPY_INCLUDE_DIR)
message(STATUS "Requested NumPy version and include path, but got instead:\n${__output}\n")
unset(NUMPY_VERSION)
unset(NUMPY_INCLUDE_DIR)
message(
STATUS
"Requested NumPy version and include path, but got instead:\n${__output}\n")
endif()
endif()
else()
......@@ -47,8 +50,10 @@ else()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NumPy REQUIRED_VARS NUMPY_INCLUDE_DIR NUMPY_VERSION
VERSION_VAR NUMPY_VERSION)
find_package_handle_standard_args(
NumPy
REQUIRED_VARS NUMPY_INCLUDE_DIR NUMPY_VERSION
VERSION_VAR NUMPY_VERSION)
if(NUMPY_FOUND)
message(STATUS "NumPy ver. ${NUMPY_VERSION} found (include: ${NUMPY_INCLUDE_DIR})")
......
if (MGE_USE_SYSTEM_LIB)
find_package(OpenBLAS)
set (MGE_USE_SYSTEM_OPENBLAS ON)
message(STATUS "Using system provided OpenBLAS ${OpenBLAS_VERSION}")
add_library(libopenblas IMPORTED GLOBAL)
set_target_properties(
libopenblas PROPERTIES
IMPORTED_LOCATION ${OpenBLAS_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${OpenBLAS_INCLUDE_DIRS}
)
return()
if(MGE_USE_SYSTEM_LIB)
find_package(OpenBLAS)
set(MGE_USE_SYSTEM_OPENBLAS ON)
message(STATUS "Using system provided OpenBLAS ${OpenBLAS_VERSION}")
add_library(libopenblas IMPORTED GLOBAL)
set_target_properties(
libopenblas PROPERTIES IMPORTED_LOCATION ${OpenBLAS_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${OpenBLAS_INCLUDE_DIRS})
return()
endif()
include(ExternalProject)
include(GNUInstallDirs)
set(OPENBLAS_DIR "${PROJECT_SOURCE_DIR}/third_party/OpenBLAS" CACHE STRING "OpenBLAS directory")
set(OPENBLAS_DIR
"${PROJECT_SOURCE_DIR}/third_party/OpenBLAS"
CACHE STRING "OpenBLAS directory")
set(OPENBLAS_BUILD_DIR ${PROJECT_BINARY_DIR}/third_party/OpenBLAS)
set(OPENBLAS_INC ${OPENBLAS_BUILD_DIR}/include)
set(OPENBLAS_LIB ${OPENBLAS_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/libopenblas.a)
if(${CMAKE_GENERATOR} STREQUAL "Ninja")
set(MAKE_COMMAND make)
set(MAKE_COMMAND make)
else()
set(MAKE_COMMAND "$(MAKE)")
set(MAKE_COMMAND "$(MAKE)")
endif()
ExternalProject_add(
openblas
SOURCE_DIR ${OPENBLAS_DIR}
PREFIX ${OPENBLAS_BUILD_DIR}
CMAKE_GENERATOR "Unix Makefiles"
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${OPENBLAS_BUILD_DIR} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_COMMAND ${MAKE_COMMAND}
BUILD_BYPRODUCTS ${OPENBLAS_LIB} ${OPENBLAS_PROTOC_EXECUTABLE}
)
ExternalProject_Add(
openblas
SOURCE_DIR ${OPENBLAS_DIR}
PREFIX ${OPENBLAS_BUILD_DIR}
CMAKE_GENERATOR "Unix Makefiles"
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${OPENBLAS_BUILD_DIR}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_COMMAND ${MAKE_COMMAND}
BUILD_BYPRODUCTS ${OPENBLAS_LIB} ${OPENBLAS_PROTOC_EXECUTABLE})
file(MAKE_DIRECTORY ${OPENBLAS_INC})
add_library(libopenblas STATIC IMPORTED GLOBAL)
add_dependencies(libopenblas openblas)
set_target_properties(
libopenblas PROPERTIES
IMPORTED_LOCATION ${OPENBLAS_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${OPENBLAS_BUILD_DIR}/include
)
libopenblas PROPERTIES IMPORTED_LOCATION ${OPENBLAS_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${OPENBLAS_BUILD_DIR}/include)
find_library(ACLRT_LIBRARY
NAMES libascendcl.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{ACLRT_HOME}/lib64/stub" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES stub
DOC "ACL library." )
find_library(
ACLRT_LIBRARY
NAMES libascendcl.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{ACLRT_HOME}/lib64/stub" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES stub
DOC "ACL library.")
if(ACLRT_LIBRARY STREQUAL "ACLRT_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find ACLRT Library")
message(FATAL_ERROR "Can not find ACLRT Library")
endif()
get_filename_component(__found_aclrt_root "${ACLRT_LIBRARY}/../../../" REALPATH)
find_path(ACLRT_INCLUDE_DIR
NAMES acl/acl.h
HINTS "$ENV{ACLRT_HOME}/include" ${__found_aclrt_root}
PATH_SUFFIXES include
DOC "Path to ACLRT include directory." )
find_path(
ACLRT_INCLUDE_DIR
NAMES acl/acl.h
HINTS "$ENV{ACLRT_HOME}/include" ${__found_aclrt_root}
PATH_SUFFIXES include
DOC "Path to ACLRT include directory.")
if(ACLRT_INCLUDE_DIR STREQUAL "ACLRT_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find ACLRT Library")
message(FATAL_ERROR "Can not find ACLRT Library")
endif()
add_library(libascendcl SHARED IMPORTED)
set_target_properties(libascendcl PROPERTIES
IMPORTED_LOCATION ${ACLRT_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${ACLRT_INCLUDE_DIR}
)
set_target_properties(
libascendcl PROPERTIES IMPORTED_LOCATION ${ACLRT_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${ACLRT_INCLUDE_DIR})
message(STATUS "Found ACLRT: ${__found_aclrt_root}")
find_library(CNDEV_LIBRARY
NAMES libcndev.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNDEV library." )
find_library(
CNDEV_LIBRARY
NAMES libcndev.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNDEV library.")
if(CNDEV_LIBRARY STREQUAL "CNDEV_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find CNDEV Library")
message(FATAL_ERROR "Can not find CNDEV Library")
endif()
get_filename_component(__found_cndev_root ${CNDEV_LIBRARY}/../.. REALPATH)
find_path(CNDEV_INCLUDE_DIR
NAMES cndev.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cndev_root}
PATH_SUFFIXES include
DOC "Path to CNDEV include directory." )
find_path(
CNDEV_INCLUDE_DIR
NAMES cndev.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cndev_root}
PATH_SUFFIXES include
DOC "Path to CNDEV include directory.")
if(CNDEV_INCLUDE_DIR STREQUAL "CNDEV_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find CNDEV Library")
message(FATAL_ERROR "Can not find CNDEV Library")
endif()
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_1 REGEX "^#define CNDEV_VERSION_1 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_2 REGEX "^#define CNDEV_VERSION_2 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_3 REGEX "^#define CNDEV_VERSION_3 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_4 REGEX "^#define CNDEV_VERSION_4 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_5 REGEX "^#define CNDEV_VERSION_5 [0-9]+.*$")
string(REGEX REPLACE "^#define CNDEV_VERSION_1 ([0-9]+).*$" "\\1" CNDEV_VERSION_1 "${CNDEV_1}")
string(REGEX REPLACE "^#define CNDEV_VERSION_2 ([0-9]+).*$" "\\1" CNDEV_VERSION_2 "${CNDEV_2}")
string(REGEX REPLACE "^#define CNDEV_VERSION_3 ([0-9]+).*$" "\\1" CNDEV_VERSION_3 "${CNDEV_3}")
string(REGEX REPLACE "^#define CNDEV_VERSION_4 ([0-9]+).*$" "\\1" CNDEV_VERSION_4 "${CNDEV_4}")
string(REGEX REPLACE "^#define CNDEV_VERSION_5 ([0-9]+).*$" "\\1" CNDEV_VERSION_5 "${CNDEV_5}")
set(CNDEV_VERSION_STRING "${CNDEV_VERSION_1}.${CNDEV_VERSION_2}.${CNDEV_VERSION_3}.${CNDEV_VERSION_4}.${CNDEV_VERSION_5}")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_1
REGEX "^#define CNDEV_VERSION_1 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_2
REGEX "^#define CNDEV_VERSION_2 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_3
REGEX "^#define CNDEV_VERSION_3 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_4
REGEX "^#define CNDEV_VERSION_4 [0-9]+.*$")
file(STRINGS "${CNDEV_INCLUDE_DIR}/cndev.h" CNDEV_5
REGEX "^#define CNDEV_VERSION_5 [0-9]+.*$")
string(REGEX REPLACE "^#define CNDEV_VERSION_1 ([0-9]+).*$" "\\1" CNDEV_VERSION_1
"${CNDEV_1}")
string(REGEX REPLACE "^#define CNDEV_VERSION_2 ([0-9]+).*$" "\\1" CNDEV_VERSION_2
"${CNDEV_2}")
string(REGEX REPLACE "^#define CNDEV_VERSION_3 ([0-9]+).*$" "\\1" CNDEV_VERSION_3
"${CNDEV_3}")
string(REGEX REPLACE "^#define CNDEV_VERSION_4 ([0-9]+).*$" "\\1" CNDEV_VERSION_4
"${CNDEV_4}")
string(REGEX REPLACE "^#define CNDEV_VERSION_5 ([0-9]+).*$" "\\1" CNDEV_VERSION_5
"${CNDEV_5}")
set(CNDEV_VERSION_STRING
"${CNDEV_VERSION_1}.${CNDEV_VERSION_2}.${CNDEV_VERSION_3}.${CNDEV_VERSION_4}.${CNDEV_VERSION_5}"
)
add_library(libcndev SHARED IMPORTED)
set_target_properties(libcndev PROPERTIES
IMPORTED_LOCATION ${CNDEV_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNDEV_INCLUDE_DIR}
)
message(STATUS "Found CNDEV: ${__found_cndev_root} (found version: ${CNDEV_VERSION_STRING})")
set_target_properties(
libcndev PROPERTIES IMPORTED_LOCATION ${CNDEV_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES
${CNDEV_INCLUDE_DIR})
message(
STATUS "Found CNDEV: ${__found_cndev_root} (found version: ${CNDEV_VERSION_STRING})")
find_library(CNLIGHT_LIBRARY
NAMES libcnlight.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNLIGHT library." )
find_library(
CNLIGHT_LIBRARY
NAMES libcnlight.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNLIGHT library.")
if(CNLIGHT_LIBRARY STREQUAL "CNLIGHT_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find CNLIGHT Library")
message(FATAL_ERROR "Can not find CNLIGHT Library")
endif()
get_filename_component(__found_cnlight_root "${CNLIGHT_LIBRARY}/../.." REALPATH)
find_path(CNLIGHT_INCLUDE_DIR
NAMES cnlight.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnlight_root}
PATH_SUFFIXES include
DOC "Path to CNLIGHT include directory." )
find_path(
CNLIGHT_INCLUDE_DIR
NAMES cnlight.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnlight_root}
PATH_SUFFIXES include
DOC "Path to CNLIGHT include directory.")
if(CNLIGHT_INCLUDE_DIR STREQUAL "CNLIGHT_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find CNLIGHT Library")
message(FATAL_ERROR "Can not find CNLIGHT Library")
endif()
file(STRINGS "${CNLIGHT_INCLUDE_DIR}/cnlight.h" CNLIGHT_MAJOR REGEX "^#define CNLIGHT_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${CNLIGHT_INCLUDE_DIR}/cnlight.h" CNLIGHT_MINOR REGEX "^#define CNLIGHT_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${CNLIGHT_INCLUDE_DIR}/cnlight.h" CNLIGHT_PATCH REGEX "^#define CNLIGHT_PATCH_VERSION [0-9]+.*$")
string(REGEX REPLACE "^#define CNLIGHT_MAJOR_VERSION ([0-9]+).*$" "\\1" CNLIGHT_VERSION_MAJOR "${CNLIGHT_MAJOR}")
string(REGEX REPLACE "^#define CNLIGHT_MINOR_VERSION ([0-9]+).*$" "\\1" CNLIGHT_VERSION_MINOR "${CNLIGHT_MINOR}")
string(REGEX REPLACE "^#define CNLIGHT_PATCH_VERSION ([0-9]+).*$" "\\1" CNLIGHT_VERSION_PATCH "${CNLIGHT_PATCH}")
set(CNLIGHT_VERSION_STRING "${CNLIGHT_VERSION_MAJOR}.${CNLIGHT_VERSION_MINOR}.${CNLIGHT_VERSION_PATCH}")
file(STRINGS "${CNLIGHT_INCLUDE_DIR}/cnlight.h" CNLIGHT_MAJOR
REGEX "^#define CNLIGHT_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${CNLIGHT_INCLUDE_DIR}/cnlight.h" CNLIGHT_MINOR
REGEX "^#define CNLIGHT_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${CNLIGHT_INCLUDE_DIR}/cnlight.h" CNLIGHT_PATCH
REGEX "^#define CNLIGHT_PATCH_VERSION [0-9]+.*$")
string(REGEX REPLACE "^#define CNLIGHT_MAJOR_VERSION ([0-9]+).*$" "\\1"
CNLIGHT_VERSION_MAJOR "${CNLIGHT_MAJOR}")
string(REGEX REPLACE "^#define CNLIGHT_MINOR_VERSION ([0-9]+).*$" "\\1"
CNLIGHT_VERSION_MINOR "${CNLIGHT_MINOR}")
string(REGEX REPLACE "^#define CNLIGHT_PATCH_VERSION ([0-9]+).*$" "\\1"
CNLIGHT_VERSION_PATCH "${CNLIGHT_PATCH}")
set(CNLIGHT_VERSION_STRING
"${CNLIGHT_VERSION_MAJOR}.${CNLIGHT_VERSION_MINOR}.${CNLIGHT_VERSION_PATCH}")
add_library(libcnlight SHARED IMPORTED)
set_target_properties(libcnlight PROPERTIES
IMPORTED_LOCATION ${CNLIGHT_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNLIGHT_INCLUDE_DIR}
)
message(STATUS "Found CNLIGHT: ${__found_cnlight_root} (found version: ${CNLIGHT_VERSION_STRING})")
set_target_properties(
libcnlight PROPERTIES IMPORTED_LOCATION ${CNLIGHT_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNLIGHT_INCLUDE_DIR})
message(
STATUS
"Found CNLIGHT: ${__found_cnlight_root} (found version: ${CNLIGHT_VERSION_STRING})")
find_library(CNML_LIBRARY
NAMES libcnml.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNML library." )
find_library(
CNML_LIBRARY
NAMES libcnml.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNML library.")
if(CNML_LIBRARY STREQUAL "CNML_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find CNML Library")
message(FATAL_ERROR "Can not find CNML Library")
endif()
get_filename_component(__found_cnml_root "${CNML_LIBRARY}/../.." REALPATH)
find_path(CNML_INCLUDE_DIR
NAMES cnml.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnml_root}
PATH_SUFFIXES include
DOC "Path to CNML include directory." )
find_path(
CNML_INCLUDE_DIR
NAMES cnml.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnml_root}
PATH_SUFFIXES include
DOC "Path to CNML include directory.")
if(CNML_INCLUDE_DIR STREQUAL "CNML_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find CNML Library")
message(FATAL_ERROR "Can not find CNML Library")
endif()
file(STRINGS "${CNML_INCLUDE_DIR}/cnml.h" CNML_MAJOR REGEX "^#define CNML_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${CNML_INCLUDE_DIR}/cnml.h" CNML_MINOR REGEX "^#define CNML_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${CNML_INCLUDE_DIR}/cnml.h" CNML_PATCH REGEX "^#define CNML_PATCH_VERSION [0-9]+.*$")
string(REGEX REPLACE "^#define CNML_MAJOR_VERSION ([0-9]+).*$" "\\1" CNML_VERSION_MAJOR "${CNML_MAJOR}")
string(REGEX REPLACE "^#define CNML_MINOR_VERSION ([0-9]+).*$" "\\1" CNML_VERSION_MINOR "${CNML_MINOR}")
string(REGEX REPLACE "^#define CNML_PATCH_VERSION ([0-9]+).*$" "\\1" CNML_VERSION_PATCH "${CNML_PATCH}")
set(CNML_VERSION_STRING "${CNML_VERSION_MAJOR}.${CNML_VERSION_MINOR}.${CNML_VERSION_PATCH}")
file(STRINGS "${CNML_INCLUDE_DIR}/cnml.h" CNML_MAJOR
REGEX "^#define CNML_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${CNML_INCLUDE_DIR}/cnml.h" CNML_MINOR
REGEX "^#define CNML_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${CNML_INCLUDE_DIR}/cnml.h" CNML_PATCH
REGEX "^#define CNML_PATCH_VERSION [0-9]+.*$")
string(REGEX REPLACE "^#define CNML_MAJOR_VERSION ([0-9]+).*$" "\\1" CNML_VERSION_MAJOR
"${CNML_MAJOR}")
string(REGEX REPLACE "^#define CNML_MINOR_VERSION ([0-9]+).*$" "\\1" CNML_VERSION_MINOR
"${CNML_MINOR}")
string(REGEX REPLACE "^#define CNML_PATCH_VERSION ([0-9]+).*$" "\\1" CNML_VERSION_PATCH
"${CNML_PATCH}")
set(CNML_VERSION_STRING
"${CNML_VERSION_MAJOR}.${CNML_VERSION_MINOR}.${CNML_VERSION_PATCH}")
add_library(libcnml SHARED IMPORTED)
set_target_properties(libcnml PROPERTIES
IMPORTED_LOCATION ${CNML_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNML_INCLUDE_DIR}
)
message(STATUS "Found CNML: ${__found_cnml_root} (found version: ${CNML_VERSION_STRING})")
set_target_properties(
libcnml PROPERTIES IMPORTED_LOCATION ${CNML_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES
${CNML_INCLUDE_DIR})
message(
STATUS "Found CNML: ${__found_cnml_root} (found version: ${CNML_VERSION_STRING})")
find_library(CNNL_LIBRARY
NAMES libcnnl.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNNL library." )
find_library(
CNNL_LIBRARY
NAMES libcnnl.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNNL library.")
if(CNNL_LIBRARY STREQUAL "CNNL_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find CNNL Library")
message(FATAL_ERROR "Can not find CNNL Library")
endif()
get_filename_component(__found_cnnl_root "${CNNL_LIBRARY}/../.." REALPATH)
find_path(CNNL_INCLUDE_DIR
NAMES cnnl.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnnl_root}
PATH_SUFFIXES include
DOC "Path to CNNL include directory." )
find_path(
CNNL_INCLUDE_DIR
NAMES cnnl.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnnl_root}
PATH_SUFFIXES include
DOC "Path to CNNL include directory.")
if(CNNL_INCLUDE_DIR STREQUAL "CNNL_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find CNNL Library")
message(FATAL_ERROR "Can not find CNNL Library")
endif()
file(STRINGS "${CNNL_INCLUDE_DIR}/cnnl.h" CNNL_MAJOR REGEX "^#define CNNL_MAJOR [0-9]+.*$")
file(STRINGS "${CNNL_INCLUDE_DIR}/cnnl.h" CNNL_MINOR REGEX "^#define CNNL_MINOR [0-9]+.*$")
file(STRINGS "${CNNL_INCLUDE_DIR}/cnnl.h" CNNL_PATCH REGEX "^#define CNNL_PATCHLEVEL [0-9]+.*$")
string(REGEX REPLACE "^#define CNNL_MAJOR ([0-9]+).*$" "\\1" CNNL_VERSION_MAJOR "${CNNL_MAJOR}")
string(REGEX REPLACE "^#define CNNL_MINOR ([0-9]+).*$" "\\1" CNNL_VERSION_MINOR "${CNNL_MINOR}")
string(REGEX REPLACE "^#define CNNL_PATCHLEVEL ([0-9]+).*$" "\\1" CNNL_VERSION_PATCH "${CNNL_PATCH}")
set(CNNL_VERSION_STRING "${CNNL_VERSION_MAJOR}.${CNNL_VERSION_MINOR}.${CNNL_VERSION_PATCH}")
file(STRINGS "${CNNL_INCLUDE_DIR}/cnnl.h" CNNL_MAJOR
REGEX "^#define CNNL_MAJOR [0-9]+.*$")
file(STRINGS "${CNNL_INCLUDE_DIR}/cnnl.h" CNNL_MINOR
REGEX "^#define CNNL_MINOR [0-9]+.*$")
file(STRINGS "${CNNL_INCLUDE_DIR}/cnnl.h" CNNL_PATCH
REGEX "^#define CNNL_PATCHLEVEL [0-9]+.*$")
string(REGEX REPLACE "^#define CNNL_MAJOR ([0-9]+).*$" "\\1" CNNL_VERSION_MAJOR
"${CNNL_MAJOR}")
string(REGEX REPLACE "^#define CNNL_MINOR ([0-9]+).*$" "\\1" CNNL_VERSION_MINOR
"${CNNL_MINOR}")
string(REGEX REPLACE "^#define CNNL_PATCHLEVEL ([0-9]+).*$" "\\1" CNNL_VERSION_PATCH
"${CNNL_PATCH}")
set(CNNL_VERSION_STRING
"${CNNL_VERSION_MAJOR}.${CNNL_VERSION_MINOR}.${CNNL_VERSION_PATCH}")
add_library(libcnnl SHARED IMPORTED)
set_target_properties(libcnnl PROPERTIES
IMPORTED_LOCATION ${CNNL_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNNL_INCLUDE_DIR}
)
set_target_properties(
libcnnl PROPERTIES IMPORTED_LOCATION ${CNNL_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES
${CNNL_INCLUDE_DIR})
message(STATUS "Found CNNL: ${__found_cnnl_root} (found version: ${CNNL_VERSION_STRING})")
message(
STATUS "Found CNNL: ${__found_cnnl_root} (found version: ${CNNL_VERSION_STRING})")
find_library(CNNL_EXTRA_LIBRARY
NAMES libcnnl_extra.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNNL_EXTRA library." )
find_library(
CNNL_EXTRA_LIBRARY
NAMES libcnnl_extra.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNNL_EXTRA library.")
if(CNNL_EXTRA_LIBRARY STREQUAL "CNNL_EXTRA_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find CNNL_EXTRA Library")
message(FATAL_ERROR "Can not find CNNL_EXTRA Library")
endif()
get_filename_component(__found_cnnl_extra_root "${CNNL_EXTRA_LIBRARY}/../.." REALPATH)
find_path(CNNL_EXTRA_INCLUDE_DIR
NAMES cnnl_extra.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnnl_extra_root}
PATH_SUFFIXES include
DOC "Path to CNNL_EXTRA include directory." )
find_path(
CNNL_EXTRA_INCLUDE_DIR
NAMES cnnl_extra.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnnl_extra_root}
PATH_SUFFIXES include
DOC "Path to CNNL_EXTRA include directory.")
if(CNNL_EXTRA_INCLUDE_DIR STREQUAL "CNNL_EXTRA_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find CNNL_EXTRA Library")
message(FATAL_ERROR "Can not find CNNL_EXTRA Library")
endif()
file(STRINGS "${CNNL_EXTRA_INCLUDE_DIR}/cnnl_extra.h" CNNL_EXTRA_MAJOR REGEX "^#define CNNL_EXTRA_MAJOR [0-9]+.*$")
file(STRINGS "${CNNL_EXTRA_INCLUDE_DIR}/cnnl_extra.h" CNNL_EXTRA_MINOR REGEX "^#define CNNL_EXTRA_MINOR [0-9]+.*$")
file(STRINGS "${CNNL_EXTRA_INCLUDE_DIR}/cnnl_extra.h" CNNL_EXTRA_PATCH REGEX "^#define CNNL_EXTRA_PATCHLEVEL [0-9]+.*$")
string(REGEX REPLACE "^#define CNNL_EXTRA_MAJOR ([0-9]+).*$" "\\1" CNNL_EXTRA_VERSION_MAJOR "${CNNL_EXTRA_MAJOR}")
string(REGEX REPLACE "^#define CNNL_EXTRA_MINOR ([0-9]+).*$" "\\1" CNNL_EXTRA_VERSION_MINOR "${CNNL_EXTRA_MINOR}")
string(REGEX REPLACE "^#define CNNL_EXTRA_PATCHLEVEL ([0-9]+).*$" "\\1" CNNL_EXTRA_VERSION_PATCH "${CNNL_EXTRA_PATCH}")
set(CNNL_EXTRA_VERSION_STRING "${CNNL_EXTRA_VERSION_MAJOR}.${CNNL_EXTRA_VERSION_MINOR}.${CNNL_EXTRA_VERSION_PATCH}")
file(STRINGS "${CNNL_EXTRA_INCLUDE_DIR}/cnnl_extra.h" CNNL_EXTRA_MAJOR
REGEX "^#define CNNL_EXTRA_MAJOR [0-9]+.*$")
file(STRINGS "${CNNL_EXTRA_INCLUDE_DIR}/cnnl_extra.h" CNNL_EXTRA_MINOR
REGEX "^#define CNNL_EXTRA_MINOR [0-9]+.*$")
file(STRINGS "${CNNL_EXTRA_INCLUDE_DIR}/cnnl_extra.h" CNNL_EXTRA_PATCH
REGEX "^#define CNNL_EXTRA_PATCHLEVEL [0-9]+.*$")
string(REGEX REPLACE "^#define CNNL_EXTRA_MAJOR ([0-9]+).*$" "\\1"
CNNL_EXTRA_VERSION_MAJOR "${CNNL_EXTRA_MAJOR}")
string(REGEX REPLACE "^#define CNNL_EXTRA_MINOR ([0-9]+).*$" "\\1"
CNNL_EXTRA_VERSION_MINOR "${CNNL_EXTRA_MINOR}")
string(REGEX REPLACE "^#define CNNL_EXTRA_PATCHLEVEL ([0-9]+).*$" "\\1"
CNNL_EXTRA_VERSION_PATCH "${CNNL_EXTRA_PATCH}")
set(CNNL_EXTRA_VERSION_STRING
"${CNNL_EXTRA_VERSION_MAJOR}.${CNNL_EXTRA_VERSION_MINOR}.${CNNL_EXTRA_VERSION_PATCH}"
)
add_library(libcnnl_extra SHARED IMPORTED)
set_target_properties(libcnnl_extra PROPERTIES
IMPORTED_LOCATION ${CNNL_EXTRA_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNNL_EXTRA_INCLUDE_DIR}
)
message(STATUS "Found CNNL_EXTRA: ${__found_cnnl_extra_root} (found version: ${CNNL_EXTRA_VERSION_STRING})")
set_target_properties(
libcnnl_extra PROPERTIES IMPORTED_LOCATION ${CNNL_EXTRA_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNNL_EXTRA_INCLUDE_DIR})
message(
STATUS
"Found CNNL_EXTRA: ${__found_cnnl_extra_root} (found version: ${CNNL_EXTRA_VERSION_STRING})"
)
find_library(CNRT_LIBRARY
NAMES libcnrt.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNRT library." )
find_library(
CNRT_LIBRARY
NAMES libcnrt.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CNRT library.")
if(CNRT_LIBRARY STREQUAL "CNRT_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find CNRT Library")
message(FATAL_ERROR "Can not find CNRT Library")
endif()
get_filename_component(__found_cnrt_root ${CNRT_LIBRARY}/../../ REALPATH)
find_path(CNRT_INCLUDE_DIR
NAMES cnrt.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnrt_root}
PATH_SUFFIXES include
DOC "Path to CNRT include directory." )
find_path(
CNRT_INCLUDE_DIR
NAMES cnrt.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_cnrt_root}
PATH_SUFFIXES include
DOC "Path to CNRT include directory.")
if(CNRT_INCLUDE_DIR STREQUAL "CNRT_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find CNRT Library")
message(FATAL_ERROR "Can not find CNRT Library")
endif()
file(STRINGS "${CNRT_INCLUDE_DIR}/cnrt.h" CNRT_MAJOR REGEX "^#define CNRT_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${CNRT_INCLUDE_DIR}/cnrt.h" CNRT_MINOR REGEX "^#define CNRT_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${CNRT_INCLUDE_DIR}/cnrt.h" CNRT_PATCH REGEX "^#define CNRT_PATCH_VERSION [0-9]+.*$")
string(REGEX REPLACE "^#define CNRT_MAJOR_VERSION ([0-9]+).*$" "\\1" CNRT_VERSION_MAJOR "${CNRT_MAJOR}")
string(REGEX REPLACE "^#define CNRT_MINOR_VERSION ([0-9]+).*$" "\\1" CNRT_VERSION_MINOR "${CNRT_MINOR}")
string(REGEX REPLACE "^#define CNRT_PATCH_VERSION ([0-9]+).*$" "\\1" CNRT_VERSION_PATCH "${CNRT_PATCH}")
set(CNRT_VERSION_STRING "${CNRT_VERSION_MAJOR}.${CNRT_VERSION_MINOR}.${CNRT_VERSION_PATCH}")
file(STRINGS "${CNRT_INCLUDE_DIR}/cnrt.h" CNRT_MAJOR
REGEX "^#define CNRT_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${CNRT_INCLUDE_DIR}/cnrt.h" CNRT_MINOR
REGEX "^#define CNRT_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${CNRT_INCLUDE_DIR}/cnrt.h" CNRT_PATCH
REGEX "^#define CNRT_PATCH_VERSION [0-9]+.*$")
string(REGEX REPLACE "^#define CNRT_MAJOR_VERSION ([0-9]+).*$" "\\1" CNRT_VERSION_MAJOR
"${CNRT_MAJOR}")
string(REGEX REPLACE "^#define CNRT_MINOR_VERSION ([0-9]+).*$" "\\1" CNRT_VERSION_MINOR
"${CNRT_MINOR}")
string(REGEX REPLACE "^#define CNRT_PATCH_VERSION ([0-9]+).*$" "\\1" CNRT_VERSION_PATCH
"${CNRT_PATCH}")
set(CNRT_VERSION_STRING
"${CNRT_VERSION_MAJOR}.${CNRT_VERSION_MINOR}.${CNRT_VERSION_PATCH}")
add_library(libcnrt SHARED IMPORTED)
set_target_properties(libcnrt PROPERTIES
IMPORTED_LOCATION ${CNRT_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CNRT_INCLUDE_DIR}
)
message(STATUS "Found CNRT: ${__found_cnrt_root} (found version: ${CNRT_VERSION_STRING})")
set_target_properties(
libcnrt PROPERTIES IMPORTED_LOCATION ${CNRT_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES
${CNRT_INCLUDE_DIR})
message(
STATUS "Found CNRT: ${__found_cnrt_root} (found version: ${CNRT_VERSION_STRING})")
file(GLOB_RECURSE CPP_REDIS_SRCS ${PROJECT_SOURCE_DIR}/third_party/cpp_redis/sources/*.cpp ${PROJECT_SOURCE_DIR}/third_party/tacopie/sources/*.cpp)
set(CPP_REDIS_INCLUDES ${PROJECT_SOURCE_DIR}/third_party/cpp_redis/includes ${PROJECT_SOURCE_DIR}/third_party/tacopie/includes)
\ No newline at end of file
file(GLOB_RECURSE CPP_REDIS_SRCS
${PROJECT_SOURCE_DIR}/third_party/cpp_redis/sources/*.cpp
${PROJECT_SOURCE_DIR}/third_party/tacopie/sources/*.cpp)
set(CPP_REDIS_INCLUDES ${PROJECT_SOURCE_DIR}/third_party/cpp_redis/includes
${PROJECT_SOURCE_DIR}/third_party/tacopie/includes)
if (MGE_USE_SYSTEM_LIB)
find_package(Cpuinfo)
message(STATUS "Using system provided cpuinfo ${cpuinfo_VERSION}")
add_library(libcpuinfo IMPORTED GLOBAL)
set_target_properties(
libcpuinfo PROPERTIES
IMPORTED_LOCATION ${cpuinfo_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${cpuinfo_INCLUDE_DIRS}
)
return()
if(MGE_USE_SYSTEM_LIB)
find_package(Cpuinfo)
message(STATUS "Using system provided cpuinfo ${cpuinfo_VERSION}")
add_library(libcpuinfo IMPORTED GLOBAL)
set_target_properties(
libcpuinfo PROPERTIES IMPORTED_LOCATION ${cpuinfo_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${cpuinfo_INCLUDE_DIRS})
return()
endif()
SET(CPUINFO_LIBRARY_TYPE "static" CACHE STRING "Type of cpuinfo library (shared, static, or default) to build")
OPTION(CPUINFO_BUILD_TOOLS "Build command-line tools" OFF)
OPTION(CPUINFO_BUILD_UNIT_TESTS "Build cpuinfo unit tests" OFF)
OPTION(CPUINFO_BUILD_MOCK_TESTS "Build cpuinfo mock tests" OFF)
OPTION(CPUINFO_BUILD_BENCHMARKS "Build cpuinfo micro-benchmarks" OFF)
set(CPUINFO_LIBRARY_TYPE
"static"
CACHE STRING "Type of cpuinfo library (shared, static, or default) to build")
option(CPUINFO_BUILD_TOOLS "Build command-line tools" OFF)
option(CPUINFO_BUILD_UNIT_TESTS "Build cpuinfo unit tests" OFF)
option(CPUINFO_BUILD_MOCK_TESTS "Build cpuinfo mock tests" OFF)
option(CPUINFO_BUILD_BENCHMARKS "Build cpuinfo micro-benchmarks" OFF)
include_directories("${PROJECT_SOURCE_DIR}/third_party/cpuinfo/include")
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/cpuinfo ${CMAKE_CURRENT_BINARY_DIR}/cpuinfo EXCLUDE_FROM_ALL)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/cpuinfo
${CMAKE_CURRENT_BINARY_DIR}/cpuinfo EXCLUDE_FROM_ALL)
find_package(PkgConfig)
if(${PkgConfig_FOUND})
pkg_check_modules(PC_CUDNN QUIET CUDNN)
pkg_check_modules(PC_CUDNN QUIET CUDNN)
endif()
if("${CUDNN_ROOT_DIR}" STREQUAL "" AND NOT "$ENV{CUDNN_ROOT_DIR}" STREQUAL "")
set(CUDNN_ROOT_DIR $ENV{CUDNN_ROOT_DIR})
if("${CUDNN_ROOT_DIR}" STREQUAL "" AND NOT "$ENV{CUDNN_ROOT_DIR}" STREQUAL "")
set(CUDNN_ROOT_DIR $ENV{CUDNN_ROOT_DIR})
endif()
if(MGE_CUDA_USE_STATIC AND NOT MGE_WITH_CUDNN_SHARED)
find_library(CUDNN_LIBRARY
NAMES libcudnn_static.a cudnn.lib
PATHS ${ALTER_LD_LIBRARY_PATHS} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CUDNN library." )
find_library(
CUDNN_LIBRARY
NAMES libcudnn_static.a cudnn.lib
PATHS ${ALTER_LD_LIBRARY_PATHS} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS}
${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CUDNN library.")
else()
find_library(CUDNN_LIBRARY
NAMES libcudnn.so libcudnn.dylib cudnn64.dll
PATHS ${ALTER_LD_LIBRARY_PATHS} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CUDNN library." )
find_library(
CUDNN_LIBRARY
NAMES libcudnn.so libcudnn.dylib cudnn64.dll
PATHS ${ALTER_LD_LIBRARY_PATHS} ${CUDNN_ROOT_DIR} ${PC_CUDNN_LIBRARY_DIRS}
${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "CUDNN library.")
endif()
if(CUDNN_LIBRARY STREQUAL "CUDNN_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find CuDNN Library, please refer to scripts/cmake-build/BUILD_README.md to init CUDNN env")
message(
FATAL_ERROR
"Can not find CuDNN Library, please refer to scripts/cmake-build/BUILD_README.md to init CUDNN env"
)
endif()
get_filename_component(__found_cudnn_root ${CUDNN_LIBRARY}/../.. REALPATH)
find_path(CUDNN_INCLUDE_DIR
NAMES cudnn.h
HINTS $ENV{PC_CUDNN_INCLUDE_DIRS} ${CUDNN_ROOT_DIR} ${CUDA_TOOLKIT_INCLUDE} ${__found_cudnn_root}
PATH_SUFFIXES include
DOC "Path to CUDNN include directory." )
find_path(
CUDNN_INCLUDE_DIR
NAMES cudnn.h
HINTS $ENV{PC_CUDNN_INCLUDE_DIRS} ${CUDNN_ROOT_DIR} ${CUDA_TOOLKIT_INCLUDE}
${__found_cudnn_root}
PATH_SUFFIXES include
DOC "Path to CUDNN include directory.")
if(CUDNN_INCLUDE_DIR STREQUAL "CUDNN_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find CuDNN INCLUDE, please refer to scripts/cmake-build/BUILD_README.md to init CUDNN env")
message(
FATAL_ERROR
"Can not find CuDNN INCLUDE, please refer to scripts/cmake-build/BUILD_README.md to init CUDNN env"
)
endif()
if(EXISTS ${CUDNN_INCLUDE_DIR}/cudnn_version.h)
file(READ ${CUDNN_INCLUDE_DIR}/cudnn_version.h CUDNN_VERSION_FILE_CONTENTS)
file(READ ${CUDNN_INCLUDE_DIR}/cudnn_version.h CUDNN_VERSION_FILE_CONTENTS)
else()
file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_VERSION_FILE_CONTENTS)
file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_VERSION_FILE_CONTENTS)
endif()
string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)"
CUDNN_MAJOR_VERSION "${CUDNN_VERSION_FILE_CONTENTS}")
string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1"
CUDNN_MAJOR_VERSION "${CUDNN_MAJOR_VERSION}")
string(REGEX MATCH "define CUDNN_MINOR * +([0-9]+)"
CUDNN_MINOR_VERSION "${CUDNN_VERSION_FILE_CONTENTS}")
string(REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1"
CUDNN_MINOR_VERSION "${CUDNN_MINOR_VERSION}")
string(REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)"
CUDNN_PATCH_VERSION "${CUDNN_VERSION_FILE_CONTENTS}")
string(REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1"
CUDNN_PATCH_VERSION "${CUDNN_PATCH_VERSION}")
string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)" CUDNN_MAJOR_VERSION
"${CUDNN_VERSION_FILE_CONTENTS}")
string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1" CUDNN_MAJOR_VERSION
"${CUDNN_MAJOR_VERSION}")
string(REGEX MATCH "define CUDNN_MINOR * +([0-9]+)" CUDNN_MINOR_VERSION
"${CUDNN_VERSION_FILE_CONTENTS}")
string(REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1" CUDNN_MINOR_VERSION
"${CUDNN_MINOR_VERSION}")
string(REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)" CUDNN_PATCH_VERSION
"${CUDNN_VERSION_FILE_CONTENTS}")
string(REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1" CUDNN_PATCH_VERSION
"${CUDNN_PATCH_VERSION}")
set(CUDNN_VERSION ${CUDNN_MAJOR_VERSION}.${CUDNN_MINOR_VERSION}.${CUDNN_PATCH_VERSION})
if(MGE_CUDA_USE_STATIC)
add_library(libcudnn STATIC IMPORTED)
add_library(libcudnn STATIC IMPORTED)
else()
add_library(libcudnn SHARED IMPORTED)
add_library(libcudnn SHARED IMPORTED)
endif()
set_target_properties(libcudnn PROPERTIES
IMPORTED_LOCATION ${CUDNN_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${CUDNN_INCLUDE_DIR})
set_target_properties(
libcudnn PROPERTIES IMPORTED_LOCATION ${CUDNN_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES
${CUDNN_INCLUDE_DIR})
message(STATUS "Found CuDNN: ${__found_cudnn_root} (found version: ${CUDNN_VERSION})")
if (MGE_USE_SYSTEM_LIB)
find_package(Flatbuffers REQUIRED)
message(STATUS "Using system provided Flatbuffers ${Flatbuffers_VERSION}")
include(cmake/BuildFlatBuffers.cmake)
return()
if(MGE_USE_SYSTEM_LIB)
find_package(Flatbuffers REQUIRED)
message(STATUS "Using system provided Flatbuffers ${Flatbuffers_VERSION}")
include(cmake/BuildFlatBuffers.cmake)
return()
endif()
if(MSVC OR WIN32)
message(DEBUG "add flags flatc for clang-cl build")
set(FLATC_FLAGS "")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=unknown-argument -Wno-error=c++98-compat -Wno-error=reserved-id-macro")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=sign-conversion -Wno-error=exceptions -Wno-error=argument-outside-range")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=delete-non-virtual-dtor -Wno-error=ignored-attributes -Wno-error=format")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=sign-compare -Wno-error=unused-private-field -Wno-error=braced-scalar-init")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=return-type-c-linkage -Wno-error=invalid-noreturn -Wno-error=c++98-compat-pedantic")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=extra-semi-stmt -Wno-error=missing-prototypes -Wno-error=documentation-unknown-command")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=missing-variable-declarations -Wno-error=nonportable-system-include-path")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=exit-time-destructors -Wno-error=unused-macros -Wno-error=global-constructors")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=switch-enum -Wno-error=missing-noreturn -Wno-error=float-equal")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0.0")
set(FLATC_FLAGS "${FLATC_FLAGS} -Wno-error=suggest-override -Wno-error=suggest-destructor-override")
endif()
message(DEBUG "add flags flatc for clang-cl build")
set(FLATC_FLAGS "")
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=unknown-argument -Wno-error=c++98-compat -Wno-error=reserved-id-macro"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=sign-conversion -Wno-error=exceptions -Wno-error=argument-outside-range"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=delete-non-virtual-dtor -Wno-error=ignored-attributes -Wno-error=format"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=sign-compare -Wno-error=unused-private-field -Wno-error=braced-scalar-init"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=return-type-c-linkage -Wno-error=invalid-noreturn -Wno-error=c++98-compat-pedantic"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=extra-semi-stmt -Wno-error=missing-prototypes -Wno-error=documentation-unknown-command"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=missing-variable-declarations -Wno-error=nonportable-system-include-path"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=exit-time-destructors -Wno-error=unused-macros -Wno-error=global-constructors"
)
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=switch-enum -Wno-error=missing-noreturn -Wno-error=float-equal"
)
if(${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "11.0.0")
set(FLATC_FLAGS
"${FLATC_FLAGS} -Wno-error=suggest-override -Wno-error=suggest-destructor-override"
)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLATC_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATC_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLATC_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATC_FLAGS}")
endif()
option(FLATBUFFERS_BUILD_TESTS "" OFF)
......
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/gflags ${CMAKE_CURRENT_BINARY_DIR}/gflags)
\ No newline at end of file
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/gflags
${CMAKE_CURRENT_BINARY_DIR}/gflags)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/gtest ${CMAKE_CURRENT_BINARY_DIR}/gtest EXCLUDE_FROM_ALL)
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/gtest
${CMAKE_CURRENT_BINARY_DIR}/gtest EXCLUDE_FROM_ALL)
# - Find the llvm/mlir libraries
# This module finds if llvm/mlir is installed, or build llvm/mlir from source.
# This module sets the following variables.
# * Find the llvm/mlir libraries This module finds if llvm/mlir is installed, or build
# llvm/mlir from source. This module sets the following variables.
#
# MLIR_LLVM_INCLUDE_DIR - path to the LLVM/MLIR include files
# MLIR_LLVM_LIBS - path to the LLVM/MLIR libraries
# MLIR_LLVM_INCLUDE_DIR - path to the LLVM/MLIR include files MLIR_LLVM_LIBS - path
# to the LLVM/MLIR libraries
#
# This module define the following functions.
#
# external_tablegen_library - created interface library which depends on tablegen outputs
# external_tablegen_library - created interface library which depends on tablegen
# outputs
include(CMakeParseArguments)
function(external_tablegen_library)
cmake_parse_arguments(
_RULE
"TESTONLY"
"NAME;TBLGEN"
"SRCS;INCLUDES;OUTS"
${ARGN}
)
cmake_parse_arguments(_RULE "TESTONLY" "NAME;TBLGEN" "SRCS;INCLUDES;OUTS" ${ARGN})
if(_RULE_TESTONLY AND NOT MGE_WITH_TEST)
return()
endif()
if(_RULE_TESTONLY AND NOT MGE_WITH_TEST)
return()
endif()
set(_NAME ${_RULE_NAME})
set(_NAME ${_RULE_NAME})
set(LLVM_TARGET_DEFINITIONS ${_RULE_SRCS})
set(_INCLUDE_DIRS ${_RULE_INCLUDES})
list(TRANSFORM _INCLUDE_DIRS PREPEND "-I")
set(_OUTPUTS)
while(_RULE_OUTS)
list(GET _RULE_OUTS 0 _COMMAND)
list(REMOVE_AT _RULE_OUTS 0)
list(GET _RULE_OUTS 0 _FILE)
list(REMOVE_AT _RULE_OUTS 0)
tablegen(${_RULE_TBLGEN} ${_FILE} ${_COMMAND} ${_INCLUDE_DIRS})
list(APPEND _OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE})
endwhile()
add_custom_target(${_NAME}_target DEPENDS ${_OUTPUTS})
set(LLVM_TARGET_DEFINITIONS ${_RULE_SRCS})
set(_INCLUDE_DIRS ${_RULE_INCLUDES})
list(TRANSFORM _INCLUDE_DIRS PREPEND "-I")
set(_OUTPUTS)
while(_RULE_OUTS)
list(GET _RULE_OUTS 0 _COMMAND)
list(REMOVE_AT _RULE_OUTS 0)
list(GET _RULE_OUTS 0 _FILE)
list(REMOVE_AT _RULE_OUTS 0)
tablegen(${_RULE_TBLGEN} ${_FILE} ${_COMMAND} ${_INCLUDE_DIRS})
list(APPEND _OUTPUTS ${CMAKE_CURRENT_BINARY_DIR}/${_FILE})
endwhile()
add_custom_target(${_NAME}_target DEPENDS ${_OUTPUTS})
add_library(${_NAME} INTERFACE)
add_dependencies(${_NAME} ${_NAME}_target)
add_library(${_NAME} INTERFACE)
add_dependencies(${_NAME} ${_NAME}_target)
target_include_directories(${_NAME} INTERFACE
"$<BUILD_INTERFACE:${_RULE_INCLUDES}>")
target_include_directories(${_NAME} INTERFACE "$<BUILD_INTERFACE:${_RULE_INCLUDES}>")
install(TARGETS ${_NAME} EXPORT ${MGE_EXPORT_TARGETS})
install(TARGETS ${_NAME} EXPORT ${MGE_EXPORT_TARGETS})
endfunction()
set(LLVM_LIBS LLVMCore LLVMSupport LLVMX86CodeGen LLVMOrcJIT LLVMNVPTXCodeGen LLVMNVPTXDesc LLVMNVPTXInfo)
set(MLIR_CORE_LIBS MLIRAnalysis MLIRExecutionEngine MLIRIR MLIRParser MLIRPass MLIRSideEffectInterfaces MLIRTransforms)
set(MLIR_DIALECT_LIBS MLIRAsync MLIRAVX512 MLIRGPU MLIRLLVMAVX512 MLIRNVVMIR MLIROpenACC MLIRPDL MLIRPDLInterp MLIRQuant MLIRROCDLIR MLIRSDBM MLIRShape MLIRSPIRV MLIRStandardOpsTransforms MLIRTosa)
set(MLIR_CONVERSION_LIBS MLIRAffineToStandard MLIRAVX512ToLLVM MLIRGPUToGPURuntimeTransforms MLIRGPUToNVVMTransforms MLIRSCFToStandard)
set(LLVM_LIBS
LLVMCore
LLVMSupport
LLVMX86CodeGen
LLVMOrcJIT
LLVMNVPTXCodeGen
LLVMNVPTXDesc
LLVMNVPTXInfo)
set(MLIR_CORE_LIBS
MLIRAnalysis
MLIRExecutionEngine
MLIRIR
MLIRParser
MLIRPass
MLIRSideEffectInterfaces
MLIRTransforms)
set(MLIR_DIALECT_LIBS
MLIRAsync
MLIRAVX512
MLIRGPU
MLIRLLVMAVX512
MLIRNVVMIR
MLIROpenACC
MLIRPDL
MLIRPDLInterp
MLIRQuant
MLIRROCDLIR
MLIRSDBM
MLIRShape
MLIRSPIRV
MLIRStandardOpsTransforms
MLIRTosa)
set(MLIR_CONVERSION_LIBS
MLIRAffineToStandard MLIRAVX512ToLLVM MLIRGPUToGPURuntimeTransforms
MLIRGPUToNVVMTransforms MLIRSCFToStandard)
set(MLIR_TRANSLATION_LIBS MLIRTargetLLVMIR MLIRTargetNVVMIR)
set(MLIR_LIBS ${MLIR_CORE_LIBS} ${MLIR_DIALECT_LIBS} ${MLIR_CONVERSION_LIBS} ${MLIR_TRANSLATION_LIBS})
set(MLIR_LIBS ${MLIR_CORE_LIBS} ${MLIR_DIALECT_LIBS} ${MLIR_CONVERSION_LIBS}
${MLIR_TRANSLATION_LIBS})
set(MLIR_LLVM_LIBS ${LLVM_LIBS} ${MLIR_LIBS})
function(add_mge_mlir_src_dep llvm_monorepo_path)
set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if(NOT uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
set(CMAKE_BUILD_TYPE "Debug")
endif()
set(_CMAKE_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(_CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if(NOT uppercase_CMAKE_BUILD_TYPE MATCHES
"^(DEBUG|RELEASE|RELWITHDEBINFO|MINSIZEREL)$")
set(CMAKE_BUILD_TYPE "Debug")
endif()
set(_CMAKE_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS
OFF
CACHE BOOL "" FORCE)
add_subdirectory("${llvm_monorepo_path}/llvm" ${LLVM_BUILD_DIR} EXCLUDE_FROM_ALL)
add_subdirectory("${llvm_monorepo_path}/llvm" ${LLVM_BUILD_DIR} EXCLUDE_FROM_ALL)
# Reset CMAKE_BUILD_TYPE to its previous setting
set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type" FORCE)
# Reset BUILD_SHARED_LIBS to its previous setting
set(BUILD_SHARED_LIBS ${_CMAKE_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libraries" FORCE)
# Reset CMAKE_BUILD_TYPE to its previous setting
set(CMAKE_BUILD_TYPE
"${_CMAKE_BUILD_TYPE}"
CACHE STRING "Build type" FORCE)
# Reset BUILD_SHARED_LIBS to its previous setting
set(BUILD_SHARED_LIBS
${_CMAKE_BUILD_SHARED_LIBS}
CACHE BOOL "Build shared libraries" FORCE)
endfunction()
# llvm build options
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "" FORCE)
set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "" FORCE)
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "" FORCE)
set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "" FORCE)
set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "" FORCE)
set(LLVM_ENABLE_RTTI ${MGE_ENABLE_RTTI} CACHE BOOL "" FORCE)
set(LLVM_TARGETS_TO_BUILD "X86;NVPTX;AArch64;ARM" CACHE STRING "" FORCE)
set(LLVM_ENABLE_PROJECTS "mlir" CACHE STRING "" FORCE)
set(LLVM_INCLUDE_EXAMPLES
OFF
CACHE BOOL "" FORCE)
set(LLVM_INCLUDE_TESTS
OFF
CACHE BOOL "" FORCE)
set(LLVM_INCLUDE_DOCS
OFF
CACHE BOOL "" FORCE)
set(LLVM_ENABLE_BINDINGS
OFF
CACHE BOOL "" FORCE)
set(LLVM_INCLUDE_BENCHMARKS
OFF
CACHE BOOL "" FORCE)
set(LLVM_ENABLE_RTTI
${MGE_ENABLE_RTTI}
CACHE BOOL "" FORCE)
set(LLVM_TARGETS_TO_BUILD
"X86;NVPTX;AArch64;ARM"
CACHE STRING "" FORCE)
set(LLVM_ENABLE_PROJECTS
"mlir"
CACHE STRING "" FORCE)
set(LLVM_BUILD_DIR ${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm)
add_mge_mlir_src_dep("third_party/llvm-project")
......@@ -91,6 +139,5 @@ set(MLIR_LLVM_INCLUDE_DIR
${PROJECT_SOURCE_DIR}/third_party/llvm-project/llvm/include
${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/include
${PROJECT_SOURCE_DIR}/third_party/llvm-project/mlir/include
${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include
)
${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/tools/mlir/include)
set(MLIR_TABLEGEN_EXE mlir-tblgen)
find_library(MAGICMIND_LIBRARY
NAMES libmagicmind.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "MAGICMIND library." )
find_library(
MAGICMIND_LIBRARY
NAMES libmagicmind.so
PATHS ${ALTER_LD_LIBRARY_PATHS} "$ENV{NEUWARE_HOME}/lib64" ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "MAGICMIND library.")
if(MAGICMIND_LIBRARY STREQUAL "MAGICMIND_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find MAGICMIND Library")
message(FATAL_ERROR "Can not find MAGICMIND Library")
endif()
get_filename_component(__found_magicmind_root "${MAGICMIND_LIBRARY}/../../" REALPATH)
find_path(MAGICMIND_INCLUDE_DIR
NAMES common.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_magicmind_root}
PATH_SUFFIXES include
DOC "Path to MAGICMIND include directory." )
find_path(
MAGICMIND_INCLUDE_DIR
NAMES common.h
HINTS "$ENV{NEUWARE_HOME}/include" ${__found_magicmind_root}
PATH_SUFFIXES include
DOC "Path to MAGICMIND include directory.")
if(MAGICMIND_INCLUDE_DIR STREQUAL "MAGICMIND_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find MAGICMIND Library")
message(FATAL_ERROR "Can not find MAGICMIND Library")
endif()
file(STRINGS "${MAGICMIND_INCLUDE_DIR}/common.h" MAGICMIND_MAJOR REGEX "^#define MM_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${MAGICMIND_INCLUDE_DIR}/common.h" MAGICMIND_MINOR REGEX "^#define MM_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${MAGICMIND_INCLUDE_DIR}/common.h" MAGICMIND_PATCH REGEX "^#define MM_PATCH_VERSION [0-9]+.*$")
file(STRINGS "${MAGICMIND_INCLUDE_DIR}/common.h" MAGICMIND_MAJOR
REGEX "^#define MM_MAJOR_VERSION [0-9]+.*$")
file(STRINGS "${MAGICMIND_INCLUDE_DIR}/common.h" MAGICMIND_MINOR
REGEX "^#define MM_MINOR_VERSION [0-9]+.*$")
file(STRINGS "${MAGICMIND_INCLUDE_DIR}/common.h" MAGICMIND_PATCH
REGEX "^#define MM_PATCH_VERSION [0-9]+.*$")
string(REGEX REPLACE "^#define MM_MAJOR_VERSION ([0-9]+).*$" "\\1" MAGICMIND_VERSION_MAJOR "${MAGICMIND_MAJOR}")
string(REGEX REPLACE "^#define MM_MINOR_VERSION ([0-9]+).*$" "\\1" MAGICMIND_VERSION_MINOR "${MAGICMIND_MINOR}")
string(REGEX REPLACE "^#define MM_PATCH_VERSION ([0-9]+).*$" "\\1" MAGICMIND_VERSION_PATCH "${MAGICMIND_PATCH}")
set(MAGICMIND_VERSION_STRING "${MAGICMIND_VERSION_MAJOR}.${MAGICMIND_VERSION_MINOR}.${MAGICMIND_VERSION_PATCH}")
string(REGEX REPLACE "^#define MM_MAJOR_VERSION ([0-9]+).*$" "\\1"
MAGICMIND_VERSION_MAJOR "${MAGICMIND_MAJOR}")
string(REGEX REPLACE "^#define MM_MINOR_VERSION ([0-9]+).*$" "\\1"
MAGICMIND_VERSION_MINOR "${MAGICMIND_MINOR}")
string(REGEX REPLACE "^#define MM_PATCH_VERSION ([0-9]+).*$" "\\1"
MAGICMIND_VERSION_PATCH "${MAGICMIND_PATCH}")
set(MAGICMIND_VERSION_STRING
"${MAGICMIND_VERSION_MAJOR}.${MAGICMIND_VERSION_MINOR}.${MAGICMIND_VERSION_PATCH}")
add_library(libmagicmind SHARED IMPORTED)
set_target_properties(libmagicmind PROPERTIES
IMPORTED_LOCATION ${MAGICMIND_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${MAGICMIND_INCLUDE_DIR}
)
set_target_properties(
libmagicmind PROPERTIES IMPORTED_LOCATION ${MAGICMIND_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${MAGICMIND_INCLUDE_DIR})
message(STATUS "Found MAGICMIND: ${__found_magicmind_root} (found version: ${MAGICMIND_VERSION_STRING})")
message(
STATUS
"Found MAGICMIND: ${__found_magicmind_root} (found version: ${MAGICMIND_VERSION_STRING})"
)
find_library(MAGICMIND_RUNTIME_LIBRARY
NAMES libmagicmind_runtime.so
PATHS "${__found_magicmind_root}/lib64"
)
find_library(
MAGICMIND_RUNTIME_LIBRARY
NAMES libmagicmind_runtime.so
PATHS "${__found_magicmind_root}/lib64")
if(MAGICMIND_RUNTIME_LIBRARY STREQUAL "MAGICMIND_RUNTIME_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find MAGICMIND_RUNTIME Library")
message(FATAL_ERROR "Can not find MAGICMIND_RUNTIME Library")
else()
message(STATUS "Found MAGICMIND_RUNTIME: ${MAGICMIND_RUNTIME_LIBRARY}")
message(STATUS "Found MAGICMIND_RUNTIME: ${MAGICMIND_RUNTIME_LIBRARY}")
endif()
add_library(libmagicmind_runtime SHARED IMPORTED)
set_target_properties(libmagicmind_runtime PROPERTIES
IMPORTED_LOCATION ${MAGICMIND_RUNTIME_LIBRARY}
)
set_target_properties(libmagicmind_runtime PROPERTIES IMPORTED_LOCATION
${MAGICMIND_RUNTIME_LIBRARY})
find_path(MKL_ROOT_DIR
include/mkl_cblas.h
PATHS
${PROJECT_SOURCE_DIR}/third_party/mkl/${MGE_ARCH}
${PROJECT_SOURCE_DIR}/third_party/mkl/${MGE_ARCH}/Library
${PROJECT_SOURCE_DIR}/third_party/mkl/x86_32/Library
${PROJECT_SOURCE_DIR}/third_party/mkl/x86_32
$ENV{MKLDIR}
/opt/intel/mkl/*/
/opt/intel/cmkl/*/
/Library/Frameworks/Intel_MKL.framework/Versions/Current/lib/universal
)
find_path(
MKL_ROOT_DIR include/mkl_cblas.h
PATHS ${PROJECT_SOURCE_DIR}/third_party/mkl/${MGE_ARCH}
${PROJECT_SOURCE_DIR}/third_party/mkl/${MGE_ARCH}/Library
${PROJECT_SOURCE_DIR}/third_party/mkl/x86_32/Library
${PROJECT_SOURCE_DIR}/third_party/mkl/x86_32
$ENV{MKLDIR}
/opt/intel/mkl/*/
/opt/intel/cmkl/*/
/Library/Frameworks/Intel_MKL.framework/Versions/Current/lib/universal)
if(${MKL_ROOT_DIR} STREQUAL "MKL_ROOT_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find MKL")
message(FATAL_ERROR "Can not find MKL")
endif()
message(STATUS "Build with MKL in ${MKL_ROOT_DIR}")
find_path(MKL_INCLUDE_DIR
mkl_cblas.h
PATHS
${MKL_ROOT_DIR}/include
${INCLUDE_INSTALL_DIR}
)
find_path(MKL_INCLUDE_DIR mkl_cblas.h PATHS ${MKL_ROOT_DIR}/include
${INCLUDE_INSTALL_DIR})
option(MGE_MKL_USE_STATIC "Build MegEngine with static MKL" ON)
if(MGE_MKL_USE_STATIC)
find_library(MKL_CORE_LIBRARY
NAMES libmkl_core.a mkl_core.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
find_library(
MKL_CORE_LIBRARY
NAMES libmkl_core.a mkl_core.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
find_library(MKL_SEQUENTIAL_LIBRARY
NAMES libmkl_sequential.a mkl_sequential.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
find_library(
MKL_SEQUENTIAL_LIBRARY
NAMES libmkl_sequential.a mkl_sequential.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
if(${MGE_ARCH} STREQUAL "x86_64")
find_library(MKL_IPL_LIBRARY
NAMES libmkl_intel_ilp64.a mkl_intel_ilp64.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
elseif(${MGE_ARCH} STREQUAL "i386")
find_library(MKL_IPL_LIBRARY
NAMES libmkl_intel_32.a mkl_intel_32.lib mkl_intel_c.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
endif()
if(${MGE_ARCH} STREQUAL "x86_64")
find_library(
MKL_IPL_LIBRARY
NAMES libmkl_intel_ilp64.a mkl_intel_ilp64.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
elseif(${MGE_ARCH} STREQUAL "i386")
find_library(
MKL_IPL_LIBRARY
NAMES libmkl_intel_32.a mkl_intel_32.lib mkl_intel_c.lib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
endif()
add_library(libmkl INTERFACE IMPORTED)
if(UNIX AND NOT APPLE)
target_link_libraries(libmkl INTERFACE -Wl,--start-group ${MKL_CORE_LIBRARY} ${MKL_SEQUENTIAL_LIBRARY} ${MKL_IPL_LIBRARY} -Wl,--end-group)
else()
target_link_libraries(libmkl INTERFACE ${MKL_CORE_LIBRARY} ${MKL_SEQUENTIAL_LIBRARY} ${MKL_IPL_LIBRARY})
endif()
target_include_directories(libmkl INTERFACE ${MKL_INCLUDE_DIR})
add_library(libmkl INTERFACE IMPORTED)
if(UNIX AND NOT APPLE)
target_link_libraries(
libmkl INTERFACE -Wl,--start-group ${MKL_CORE_LIBRARY} ${MKL_SEQUENTIAL_LIBRARY}
${MKL_IPL_LIBRARY} -Wl,--end-group)
else()
target_link_libraries(libmkl INTERFACE ${MKL_CORE_LIBRARY}
${MKL_SEQUENTIAL_LIBRARY} ${MKL_IPL_LIBRARY})
endif()
target_include_directories(libmkl INTERFACE ${MKL_INCLUDE_DIR})
else()
find_library(MKL_CORE_LIBRARY
NAMES libmkl_core.so libmkl_core.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
find_library(
MKL_CORE_LIBRARY
NAMES libmkl_core.so libmkl_core.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
find_library(MKL_SEQUENTIAL_LIBRARY
NAMES libmkl_sequential.so libmkl_sequential.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
find_library(
MKL_SEQUENTIAL_LIBRARY
NAMES libmkl_sequential.so libmkl_sequential.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
if(${MGE_ARCH} STREQUAL "x86_64")
find_library(MKL_IPL_LIBRARY
NAMES libmkl_intel_ilp64.so libmkl_intel_ilp64.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
elseif(${MGE_ARCH} STREQUAL "x86_32")
find_library(MKL_IPL_LIBRARY
NAMES libmkl_intel_32.so libmkl_intel_32.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
endif()
target_link_libraries(libmkl INTERFACE ${MKL_CORE_LIBRARY} ${MKL_SEQUENTIAL_LIBRARY} ${MKL_IPL_LIBRARY})
target_include_directories(libmkl INTERFACE ${MKL_INCLUDE_DIR})
if(${MGE_ARCH} STREQUAL "x86_64")
find_library(
MKL_IPL_LIBRARY
NAMES libmkl_intel_ilp64.so libmkl_intel_ilp64.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
elseif(${MGE_ARCH} STREQUAL "x86_32")
find_library(
MKL_IPL_LIBRARY
NAMES libmkl_intel_32.so libmkl_intel_32.dylib
PATHS ${MKL_ROOT_DIR}/lib/${MKL_ARCH_DIR} ${MKL_ROOT_DIR}/lib/)
endif()
target_link_libraries(libmkl INTERFACE ${MKL_CORE_LIBRARY} ${MKL_SEQUENTIAL_LIBRARY}
${MKL_IPL_LIBRARY})
target_include_directories(libmkl INTERFACE ${MKL_INCLUDE_DIR})
endif()
if(${MGE_ARCH} STREQUAL "x86_64")
target_compile_definitions(libmkl INTERFACE -DMKL_ILP64)
target_compile_definitions(libmkl INTERFACE -DMKL_ILP64)
endif()
function(PROTOBUF_GENERATE_CPP_WITH_ROOT SRCS HDRS ROOT_DIR)
if(NOT ARGN)
message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP_WITH_ROOT() called without any proto files")
return()
endif()
if(NOT ARGN)
message(
SEND_ERROR
"Error: PROTOBUF_GENERATE_CPP_WITH_ROOT() called without any proto files")
return()
endif()
set(${SRCS})
set(${HDRS})
foreach(FIL ${ARGN})
set(ABS_FIL ${ROOT_DIR}/${FIL})
get_filename_component(FIL_WE ${FIL} NAME_WE)
get_filename_component(FIL_DIR ${ABS_FIL} PATH)
file(RELATIVE_PATH REL_DIR ${ROOT_DIR} ${FIL_DIR})
set(${SRCS})
set(${HDRS})
foreach(FIL ${ARGN})
set(ABS_FIL ${ROOT_DIR}/${FIL})
get_filename_component(FIL_WE ${FIL} NAME_WE)
get_filename_component(FIL_DIR ${ABS_FIL} PATH)
file(RELATIVE_PATH REL_DIR ${ROOT_DIR} ${FIL_DIR})
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${FIL_DIR} ${ABS_FIL} -I ${PROTOBUF_INCLUDE_DIRS}
DEPENDS ${ABS_FIL} libprotobuf
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
VERBATIM)
endforeach()
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR}
-I ${FIL_DIR} ${ABS_FIL} -I ${PROTOBUF_INCLUDE_DIRS}
DEPENDS ${ABS_FIL} libprotobuf
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
VERBATIM)
endforeach()
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
set(${HDRS} ${${HDRS}} PARENT_SCOPE)
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
set(${SRCS}
${${SRCS}}
PARENT_SCOPE)
set(${HDRS}
${${HDRS}}
PARENT_SCOPE)
endfunction()
if(MGE_USE_SYSTEM_LIB)
find_package(Protobuf)
if(Protobuf_FOUND)
add_library(libprotobuf INTERFACE)
target_link_libraries(libprotobuf INTERFACE ${Protobuf_LIBRARIES})
target_include_directories(libprotobuf INTERFACE ${Protobuf_INCLUDE_DIRS})
get_filename_component(Protobuf_ROOT ${Protobuf_INCLUDE_DIR} DIRECTORY)
set(PROTOBUF_ROOT ${Protobuf_ROOT})
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
set(PROTOBUF_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS})
return()
endif()
find_package(Protobuf)
if(Protobuf_FOUND)
add_library(libprotobuf INTERFACE)
target_link_libraries(libprotobuf INTERFACE ${Protobuf_LIBRARIES})
target_include_directories(libprotobuf INTERFACE ${Protobuf_INCLUDE_DIRS})
get_filename_component(Protobuf_ROOT ${Protobuf_INCLUDE_DIR} DIRECTORY)
set(PROTOBUF_ROOT ${Protobuf_ROOT})
set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
set(PROTOBUF_INCLUDE_DIRS ${Protobuf_INCLUDE_DIRS})
return()
endif()
endif()
include(ExternalProject)
include(GNUInstallDirs)
set(PROTOBUF_DIR "${PROJECT_SOURCE_DIR}/third_party/protobuf" CACHE STRING "protobuf directory")
set(PROTOBUF_DIR
"${PROJECT_SOURCE_DIR}/third_party/protobuf"
CACHE STRING "protobuf directory")
set(PROTOBUF_BUILD_DIR ${PROJECT_BINARY_DIR}/third_party/protobuf)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(PROTOBUF_LIB ${PROTOBUF_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/libprotobufd.a)
set(PROTOBUF_LIB ${PROTOBUF_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/libprotobufd.a)
else()
set(PROTOBUF_LIB ${PROTOBUF_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/libprotobuf.a)
set(PROTOBUF_LIB ${PROTOBUF_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/libprotobuf.a)
endif()
set(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_BUILD_DIR}/bin/protoc)
ExternalProject_add(
protobuf
SOURCE_DIR ${PROTOBUF_DIR}/cmake
PREFIX ${PROTOBUF_BUILD_DIR}
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${PROTOBUF_BUILD_DIR} -Dprotobuf_BUILD_EXAMPLES=OFF -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_BYPRODUCTS ${PROTOBUF_LIB} ${PROTOBUF_PROTOC_EXECUTABLE}
)
ExternalProject_Add(
protobuf
SOURCE_DIR ${PROTOBUF_DIR}/cmake
PREFIX ${PROTOBUF_BUILD_DIR}
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${PROTOBUF_BUILD_DIR}
-Dprotobuf_BUILD_EXAMPLES=OFF
-Dprotobuf_BUILD_TESTS=OFF
-DBUILD_SHARED_LIBS=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_BYPRODUCTS ${PROTOBUF_LIB} ${PROTOBUF_PROTOC_EXECUTABLE})
set(PROTOBUF_INC ${PROTOBUF_BUILD_DIR}/include)
file(MAKE_DIRECTORY ${PROTOBUF_INC})
......@@ -72,19 +85,14 @@ file(MAKE_DIRECTORY ${PROTOBUF_INC})
add_library(libprotobuf STATIC IMPORTED GLOBAL)
add_dependencies(libprotobuf protobuf)
set_target_properties(
libprotobuf PROPERTIES
IMPORTED_LOCATION ${PROTOBUF_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_BUILD_DIR}/include
)
libprotobuf PROPERTIES IMPORTED_LOCATION ${PROTOBUF_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${PROTOBUF_BUILD_DIR}/include)
add_executable(protoc IMPORTED GLOBAL)
add_dependencies(protoc protobuf)
set_target_properties(
protoc PROPERTIES
IMPORTED_LOCATION ${PROTOBUF_BUILD_DIR}/bin/protoc
)
set_target_properties(protoc PROPERTIES IMPORTED_LOCATION
${PROTOBUF_BUILD_DIR}/bin/protoc)
set(PROTOBUF_ROOT ${PROTOBUF_BUILD_DIR})
set(PROTOBUF_PROTOC_EXECUTABLE protoc)
set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_BUILD_DIR}/include)
if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
endif()
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH
"/opt/rocm/hip"
CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH
$ENV{HIP_PATH}
CACHE PATH "Path to which HIP has been installed")
endif()
endif()
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})
find_package(HIP QUIET)
if (HIP_FOUND)
message(STATUS "Found HIP: " ${HIP_VERSION})
if(HIP_FOUND)
message(STATUS "Found HIP: " ${HIP_VERSION})
else()
message(FATAL_ERROR "Could not find HIP. Ensure that HIP is either installed in /opt/rocm/hip or the variable HIP_PATH is set to point to the right location.")
message(
FATAL_ERROR
"Could not find HIP. Ensure that HIP is either installed in /opt/rocm/hip or the variable HIP_PATH is set to point to the right location."
)
endif()
if (${HIP_VERSION} VERSION_LESS 3.0)
message(FATAL_ERROR "ROCM version needed 3. Please update ROCM.")
if(${HIP_VERSION} VERSION_LESS 3.0)
message(FATAL_ERROR "ROCM version needed 3. Please update ROCM.")
endif()
macro(hipconfig_get_option variable option)
if(NOT DEFINED ${variable})
execute_process(
COMMAND ${HIP_HIPCONFIG_EXECUTABLE} ${option}
OUTPUT_VARIABLE ${variable})
endif()
if(NOT DEFINED ${variable})
execute_process(COMMAND ${HIP_HIPCONFIG_EXECUTABLE} ${option}
OUTPUT_VARIABLE ${variable})
endif()
endmacro()
hipconfig_get_option(HIP_COMPILER "--compiler")
......@@ -31,30 +37,33 @@ hipconfig_get_option(HIP_CPP_CONFIG "--cpp_config")
separate_arguments(HIP_CPP_CONFIG)
foreach(hip_config_item ${HIP_CPP_CONFIG})
foreach(macro_name "__HIP_PLATFORM_HCC__" "__HIP_ROCclr__")
if(${hip_config_item} STREQUAL "-D${macro_name}=")
set(HIP_CPP_DEFINE "${HIP_CPP_DEFINE}#define ${macro_name}\n")
set(HIP_CPP_UNDEFINE "${HIP_CPP_UNDEFINE}\
foreach(macro_name "__HIP_PLATFORM_HCC__" "__HIP_ROCclr__")
if(${hip_config_item} STREQUAL "-D${macro_name}=")
set(HIP_CPP_DEFINE "${HIP_CPP_DEFINE}#define ${macro_name}\n")
set(HIP_CPP_UNDEFINE
"${HIP_CPP_UNDEFINE}\
#ifdef ${macro_name}\n#undef ${macro_name}\n\
#else\n#error\n\
#endif\n")
elseif(${hip_config_item} STREQUAL "-D${macro_name}")
set(HIP_CPP_DEFINE "${HIP_CPP_DEFINE}#define ${macro_name} 1\n")
set(HIP_CPP_UNDEFINE "${HIP_CPP_UNDEFINE}\
elseif(${hip_config_item} STREQUAL "-D${macro_name}")
set(HIP_CPP_DEFINE "${HIP_CPP_DEFINE}#define ${macro_name} 1\n")
set(HIP_CPP_UNDEFINE
"${HIP_CPP_UNDEFINE}\
#ifdef ${macro_name}\n#undef ${macro_name}\n\
#else\n#error\n\
#endif\n")
endif()
endforeach()
endif()
endforeach()
endforeach()
message(STATUS "Using HIP compiler ${HIP_COMPILER}")
if(${HIP_COMPILER} STREQUAL "hcc")
set(MGE_ROCM_LIBS hip_hcc)
message(WARNING "hcc is not well supported, please modify link.txt to link with hipcc")
elseif (${HIP_COMPILER} STREQUAL "clang")
set(MGE_ROCM_LIBS amdhip64)
set(MGE_ROCM_LIBS hip_hcc)
message(
WARNING "hcc is not well supported, please modify link.txt to link with hipcc")
elseif(${HIP_COMPILER} STREQUAL "clang")
set(MGE_ROCM_LIBS amdhip64)
endif()
list(APPEND MGE_ROCM_LIBS amdocl64 MIOpen rocblas rocrand)
......@@ -63,26 +72,28 @@ set(HIP_INCLUDE_DIR ${HIP_ROOT_DIR}/../include)
set(HIP_LIBRARY_DIR ${HIP_ROOT_DIR}/../lib)
function(find_rocm_library name dirname include library)
find_path(${name}_LIBRARY_DIR
NAMES ${library}
HINTS "${${name}_ROOT_DIR}" "${HIP_ROOT_DIR}/../${dirname}"
PATH_SUFFIXES lib lib/x86_64
DOC "Path to ${name} library directory")
find_path(
${name}_LIBRARY_DIR
NAMES ${library}
HINTS "${${name}_ROOT_DIR}" "${HIP_ROOT_DIR}/../${dirname}"
PATH_SUFFIXES lib lib/x86_64
DOC "Path to ${name} library directory")
if(${${name}_LIBRARY_DIR} MATCHES "NOTFOUND$")
message(FATAL_ERROR "Can not find ${name} library")
endif()
if(${${name}_LIBRARY_DIR} MATCHES "NOTFOUND$")
message(FATAL_ERROR "Can not find ${name} library")
endif()
find_path(${name}_INCLUDE_DIR
NAMES ${include}
HINTS "${${name}_ROOT_DIR}" "${HIP_ROOT_DIR}/../${dirname}"
PATH_SUFFIXES include
DOC "Path to ${name} include directory")
find_path(
${name}_INCLUDE_DIR
NAMES ${include}
HINTS "${${name}_ROOT_DIR}" "${HIP_ROOT_DIR}/../${dirname}"
PATH_SUFFIXES include
DOC "Path to ${name} include directory")
if(${name}_INCLUDE_DIR MATCHES "NOTFOUND$")
message(FATAL_ERROR "Can not find ${name} include")
endif()
message(DEBUG "Found lib ${${name}_LIBRARY_DIR}, include ${${name}_INCLUDE_DIR}")
if(${name}_INCLUDE_DIR MATCHES "NOTFOUND$")
message(FATAL_ERROR "Can not find ${name} include")
endif()
message(DEBUG "Found lib ${${name}_LIBRARY_DIR}, include ${${name}_INCLUDE_DIR}")
endfunction()
find_rocm_library(MIOPEN miopen miopen libMIOpen.so)
......
if("${TRT_ROOT_DIR}" STREQUAL "" AND NOT "$ENV{TRT_ROOT_DIR}" STREQUAL "")
set(TRT_ROOT_DIR $ENV{TRT_ROOT_DIR})
if("${TRT_ROOT_DIR}" STREQUAL "" AND NOT "$ENV{TRT_ROOT_DIR}" STREQUAL "")
set(TRT_ROOT_DIR $ENV{TRT_ROOT_DIR})
endif()
if(MGE_CUDA_USE_STATIC)
find_library(TRT_LIBRARY
NAMES libnvinfer_static.a nvinfer.lib
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT library." )
find_library(TRT_PLUGIN_LIBRARY
NAMES libnvinfer_plugin_static.a nvinfer_plugin.lib
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT plugin library." )
find_library(
TRT_LIBRARY
NAMES libnvinfer_static.a nvinfer.lib
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT library.")
find_library(
TRT_PLUGIN_LIBRARY
NAMES libnvinfer_plugin_static.a nvinfer_plugin.lib
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT plugin library.")
else()
find_library(TRT_LIBRARY
NAMES libnvinfer.so libnvinfer.dylib nvinfer.dll
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT library." )
find_library(TRT_PLUGIN_LIBRARY
NAMES libnvinfer_plugin.so libnvinfer_plugin.dylib nvinfer_plugin.dll
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT plugin library." )
find_library(
TRT_LIBRARY
NAMES libnvinfer.so libnvinfer.dylib nvinfer.dll
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT library.")
find_library(
TRT_PLUGIN_LIBRARY
NAMES libnvinfer_plugin.so libnvinfer_plugin.dylib nvinfer_plugin.dll
PATHS ${ALTER_LD_LIBRARY_PATHS} ${TRT_ROOT_DIR} ${CMAKE_INSTALL_PREFIX}
HINTS ${ALTER_LIBRARY_PATHS}
PATH_SUFFIXES lib lib64
DOC "TRT plugin library.")
endif()
if(TRT_LIBRARY STREQUAL "TRT_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find TensorRT Library, please refer to scripts/cmake-build/BUILD_README.md to init TRT env")
message(
FATAL_ERROR
"Can not find TensorRT Library, please refer to scripts/cmake-build/BUILD_README.md to init TRT env"
)
endif()
if(TRT_PLUGIN_LIBRARY STREQUAL "TRT_PLUGIN_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find TensorRT Plugin Library, please refer to scripts/cmake-build/BUILD_README.md to init TRT env")
message(
FATAL_ERROR
"Can not find TensorRT Plugin Library, please refer to scripts/cmake-build/BUILD_README.md to init TRT env"
)
endif()
get_filename_component(__found_trt_root ${TRT_LIBRARY}/../.. REALPATH)
find_path(TRT_INCLUDE_DIR
NAMES NvInfer.h
HINTS ${TRT_ROOT_DIR} ${CUDA_TOOLKIT_INCLUDE} ${__found_trt_root}
PATH_SUFFIXES include
DOC "Path to TRT include directory." )
find_path(TRT_PLUGIN_INCLUDE_DIR
NAMES NvInferPlugin.h
HINTS ${TRT_ROOT_DIR} ${CUDA_TOOLKIT_INCLUDE} ${__found_trt_root}
PATH_SUFFIXES include
DOC "Path to TRT plugin include directory." )
find_path(
TRT_INCLUDE_DIR
NAMES NvInfer.h
HINTS ${TRT_ROOT_DIR} ${CUDA_TOOLKIT_INCLUDE} ${__found_trt_root}
PATH_SUFFIXES include
DOC "Path to TRT include directory.")
find_path(
TRT_PLUGIN_INCLUDE_DIR
NAMES NvInferPlugin.h
HINTS ${TRT_ROOT_DIR} ${CUDA_TOOLKIT_INCLUDE} ${__found_trt_root}
PATH_SUFFIXES include
DOC "Path to TRT plugin include directory.")
if(TRT_INCLUDE_DIR STREQUAL "TRT_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find TensorRT INCLUDE, please refer to scripts/cmake-build/BUILD_README.md to init TRT env")
message(
FATAL_ERROR
"Can not find TensorRT INCLUDE, please refer to scripts/cmake-build/BUILD_README.md to init TRT env"
)
endif()
if(TRT_PLUGIN_INCLUDE_DIR STREQUAL "TRT_PLUGIN_INCLUDE_DIR-NOTFOUND")
message(FATAL_ERROR "Can not find TensorRT Plugin INCLUDE, please refer to scripts/cmake-build/BUILD_README.md to init TRT env")
message(
FATAL_ERROR
"Can not find TensorRT Plugin INCLUDE, please refer to scripts/cmake-build/BUILD_README.md to init TRT env"
)
endif()
file(STRINGS "${TRT_INCLUDE_DIR}/NvInfer.h" TensorRT_MAJOR REGEX "^#define NV_TENSORRT_MAJOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInfer.h" TensorRT_MINOR REGEX "^#define NV_TENSORRT_MINOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInfer.h" TensorRT_PATCH REGEX "^#define NV_TENSORRT_PATCH [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInfer.h" TensorRT_MAJOR
REGEX "^#define NV_TENSORRT_MAJOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInfer.h" TensorRT_MINOR
REGEX "^#define NV_TENSORRT_MINOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInfer.h" TensorRT_PATCH
REGEX "^#define NV_TENSORRT_PATCH [0-9]+.*$")
if (TensorRT_MAJOR STREQUAL "")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_MAJOR REGEX "^#define NV_TENSORRT_MAJOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_MINOR REGEX "^#define NV_TENSORRT_MINOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_PATCH REGEX "^#define NV_TENSORRT_PATCH [0-9]+.*$")
if(TensorRT_MAJOR STREQUAL "")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_MAJOR
REGEX "^#define NV_TENSORRT_MAJOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_MINOR
REGEX "^#define NV_TENSORRT_MINOR [0-9]+.*$")
file(STRINGS "${TRT_INCLUDE_DIR}/NvInferVersion.h" TensorRT_PATCH
REGEX "^#define NV_TENSORRT_PATCH [0-9]+.*$")
endif()
string(REGEX REPLACE "^#define NV_TENSORRT_MAJOR ([0-9]+).*$" "\\1" TensorRT_VERSION_MAJOR "${TensorRT_MAJOR}")
string(REGEX REPLACE "^#define NV_TENSORRT_MINOR ([0-9]+).*$" "\\1" TensorRT_VERSION_MINOR "${TensorRT_MINOR}")
string(REGEX REPLACE "^#define NV_TENSORRT_PATCH ([0-9]+).*$" "\\1" TensorRT_VERSION_PATCH "${TensorRT_PATCH}")
set(TRT_VERSION_STRING "${TensorRT_VERSION_MAJOR}.${TensorRT_VERSION_MINOR}.${TensorRT_VERSION_PATCH}")
string(REGEX REPLACE "^#define NV_TENSORRT_MAJOR ([0-9]+).*$" "\\1"
TensorRT_VERSION_MAJOR "${TensorRT_MAJOR}")
string(REGEX REPLACE "^#define NV_TENSORRT_MINOR ([0-9]+).*$" "\\1"
TensorRT_VERSION_MINOR "${TensorRT_MINOR}")
string(REGEX REPLACE "^#define NV_TENSORRT_PATCH ([0-9]+).*$" "\\1"
TensorRT_VERSION_PATCH "${TensorRT_PATCH}")
set(TRT_VERSION_STRING
"${TensorRT_VERSION_MAJOR}.${TensorRT_VERSION_MINOR}.${TensorRT_VERSION_PATCH}")
if(MGE_CUDA_USE_STATIC)
add_library(libnvinfer STATIC IMPORTED)
add_library(libnvinfer_plugin STATIC IMPORTED)
add_library(libnvinfer STATIC IMPORTED)
add_library(libnvinfer_plugin STATIC IMPORTED)
else()
add_library(libnvinfer SHARED IMPORTED)
add_library(libnvinfer_plugin SHARED IMPORTED)
add_library(libnvinfer SHARED IMPORTED)
add_library(libnvinfer_plugin SHARED IMPORTED)
endif()
set_target_properties(libnvinfer PROPERTIES
IMPORTED_LOCATION ${TRT_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${TRT_INCLUDE_DIR}
)
set_target_properties(libnvinfer_plugin PROPERTIES
IMPORTED_LOCATION ${TRT_PLUGIN_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${TRT_PLUGIN_INCLUDE_DIR}
)
set_target_properties(
libnvinfer PROPERTIES IMPORTED_LOCATION ${TRT_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES
${TRT_INCLUDE_DIR})
set_target_properties(
libnvinfer_plugin PROPERTIES IMPORTED_LOCATION ${TRT_PLUGIN_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${TRT_PLUGIN_INCLUDE_DIR})
message(STATUS "Found TensorRT: ${__found_trt_root} (found version: ${TRT_VERSION_STRING})")
message(
STATUS "Found TensorRT: ${__found_trt_root} (found version: ${TRT_VERSION_STRING})")
if(TensorRT_VERSION_MAJOR GREATER_EQUAL 7)
if(MGE_CUDA_USE_STATIC)
find_library(LIBMYELIN_COMPILER
NAMES libmyelin_compiler_static.a myelin_compiler_static.lib
PATHS ${__found_trt_root}/lib
)
if(LIBMYELIN_COMPILER STREQUAL "LIBMYELIN_COMPILER-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_COMPILER Library")
else()
message(STATUS "Found TensorRT myelin_compiler: ${LIBMYELIN_COMPILER}")
endif()
add_library(libmyelin_compiler STATIC IMPORTED)
set_target_properties(libmyelin_compiler PROPERTIES
IMPORTED_LOCATION ${LIBMYELIN_COMPILER}
)
if(MGE_CUDA_USE_STATIC)
find_library(
LIBMYELIN_COMPILER
NAMES libmyelin_compiler_static.a myelin_compiler_static.lib
PATHS ${__found_trt_root}/lib)
if(LIBMYELIN_COMPILER STREQUAL "LIBMYELIN_COMPILER-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_COMPILER Library")
else()
message(STATUS "Found TensorRT myelin_compiler: ${LIBMYELIN_COMPILER}")
endif()
add_library(libmyelin_compiler STATIC IMPORTED)
set_target_properties(libmyelin_compiler PROPERTIES IMPORTED_LOCATION
${LIBMYELIN_COMPILER})
find_library(LIBMYELIN_EXECUTOR
NAMES libmyelin_executor_static.a myelin_executor_static.lib
PATHS ${__found_trt_root}/lib
)
if(LIBMYELIN_EXECUTOR STREQUAL "LIBMYELIN_EXECUTOR-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_EXECUTOR Library")
else()
message(STATUS "Found TensorRT libmyelin_executor: ${LIBMYELIN_EXECUTOR}")
endif()
add_library(libmyelin_executor STATIC IMPORTED)
set_target_properties(libmyelin_executor PROPERTIES
IMPORTED_LOCATION ${LIBMYELIN_EXECUTOR}
)
find_library(
LIBMYELIN_EXECUTOR
NAMES libmyelin_executor_static.a myelin_executor_static.lib
PATHS ${__found_trt_root}/lib)
if(LIBMYELIN_EXECUTOR STREQUAL "LIBMYELIN_EXECUTOR-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_EXECUTOR Library")
else()
message(STATUS "Found TensorRT libmyelin_executor: ${LIBMYELIN_EXECUTOR}")
endif()
add_library(libmyelin_executor STATIC IMPORTED)
set_target_properties(libmyelin_executor PROPERTIES IMPORTED_LOCATION
${LIBMYELIN_EXECUTOR})
find_library(LIBMYELIN_PATTERN_RUNTIME
NAMES libmyelin_pattern_runtime_static.a myelin_pattern_runtime_static.lib
PATHS ${__found_trt_root}/lib
)
if(LIBMYELIN_PATTERN_RUNTIME STREQUAL "LIBMYELIN_PATTERN_RUNTIME-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_PATTERN_RUNTIME Library")
else()
message(STATUS "Found TensorRT libmyelin_pattern_runtime: ${LIBMYELIN_PATTERN_RUNTIME}")
endif()
add_library(libmyelin_pattern_runtime STATIC IMPORTED)
set_target_properties(libmyelin_pattern_runtime PROPERTIES
IMPORTED_LOCATION ${LIBMYELIN_PATTERN_RUNTIME}
)
find_library(
LIBMYELIN_PATTERN_RUNTIME
NAMES libmyelin_pattern_runtime_static.a myelin_pattern_runtime_static.lib
PATHS ${__found_trt_root}/lib)
if(LIBMYELIN_PATTERN_RUNTIME STREQUAL "LIBMYELIN_PATTERN_RUNTIME-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_PATTERN_RUNTIME Library")
else()
message(
STATUS "Found TensorRT libmyelin_pattern_runtime: ${LIBMYELIN_PATTERN_RUNTIME}")
endif()
add_library(libmyelin_pattern_runtime STATIC IMPORTED)
set_target_properties(libmyelin_pattern_runtime
PROPERTIES IMPORTED_LOCATION ${LIBMYELIN_PATTERN_RUNTIME})
find_library(LIBMYELIN_PATTERN_LIBRARY
NAMES libmyelin_pattern_library_static.a myelin_pattern_library_static.lib
PATHS ${__found_trt_root}/lib
)
if(LIBMYELIN_PATTERN_LIBRARY STREQUAL "LIBMYELIN_PATTERN_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_PATTERN_LIBRARY Library")
else()
message(STATUS "Found TensorRT libmyelin_pattern_library: ${LIBMYELIN_PATTERN_LIBRARY}")
endif()
add_library(libmyelin_pattern_library STATIC IMPORTED)
set_target_properties(libmyelin_pattern_library PROPERTIES
IMPORTED_LOCATION ${LIBMYELIN_PATTERN_LIBRARY}
)
find_library(
LIBMYELIN_PATTERN_LIBRARY
NAMES libmyelin_pattern_library_static.a myelin_pattern_library_static.lib
PATHS ${__found_trt_root}/lib)
if(LIBMYELIN_PATTERN_LIBRARY STREQUAL "LIBMYELIN_PATTERN_LIBRARY-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_PATTERN_LIBRARY Library")
else()
find_library(LIBMYELIN_SHARED
NAMES libmyelin.so myelin.dll
PATHS ${__found_trt_root}/lib
)
message(
STATUS "Found TensorRT libmyelin_pattern_library: ${LIBMYELIN_PATTERN_LIBRARY}")
endif()
add_library(libmyelin_pattern_library STATIC IMPORTED)
set_target_properties(libmyelin_pattern_library
PROPERTIES IMPORTED_LOCATION ${LIBMYELIN_PATTERN_LIBRARY})
else()
find_library(
LIBMYELIN_SHARED
NAMES libmyelin.so myelin.dll
PATHS ${__found_trt_root}/lib)
if(LIBMYELIN_SHARED STREQUAL "LIBMYELIN_SHARED-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_SHARED Library")
else()
message(STATUS "Found TensorRT libmyelin_shared: ${LIBMYELIN_SHARED}")
endif()
add_library(libmyelin SHARED IMPORTED)
set_target_properties(libmyelin PROPERTIES
IMPORTED_LOCATION ${LIBMYELIN_SHARED}
)
if(LIBMYELIN_SHARED STREQUAL "LIBMYELIN_SHARED-NOTFOUND")
message(FATAL_ERROR "Can not find LIBMYELIN_SHARED Library")
else()
message(STATUS "Found TensorRT libmyelin_shared: ${LIBMYELIN_SHARED}")
endif()
add_library(libmyelin SHARED IMPORTED)
set_target_properties(libmyelin PROPERTIES IMPORTED_LOCATION ${LIBMYELIN_SHARED})
endif()
endif()
include(ExternalProject)
include(GNUInstallDirs)
set(ZMQ_DIR ${PROJECT_SOURCE_DIR}/third_party/libzmq CACHE STRING "ZMQ directory")
set(ZMQ_DIR
${PROJECT_SOURCE_DIR}/third_party/libzmq
CACHE STRING "ZMQ directory")
set(ZMQ_BUILD_DIR ${PROJECT_BINARY_DIR}/third_party/libzmq)
set(ZMQ_LIB ${ZMQ_BUILD_DIR}/${CMAKE_INSTALL_LIBDIR}/libzmq.a)
ExternalProject_add(
zmq
SOURCE_DIR ${ZMQ_DIR}
PREFIX ${ZMQ_BUILD_DIR}
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} -DCMAKE_INSTALL_PREFIX=${ZMQ_BUILD_DIR} -DWITH_PERF_TOOL=OFF -DZMQ_BUILD_TESTS=OFF -DENABLE_CPACK=OFF -DENABLE_CURVE=OFF
BUILD_BYPRODUCTS ${ZMQ_LIB}
)
ExternalProject_Add(
zmq
SOURCE_DIR ${ZMQ_DIR}
PREFIX ${ZMQ_BUILD_DIR}
CMAKE_ARGS -DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_INSTALL_PREFIX=${ZMQ_BUILD_DIR}
-DWITH_PERF_TOOL=OFF
-DZMQ_BUILD_TESTS=OFF
-DENABLE_CPACK=OFF
-DENABLE_CURVE=OFF
BUILD_BYPRODUCTS ${ZMQ_LIB})
set(ZMQ_INC ${ZMQ_BUILD_DIR}/include)
include_directories(${ZMQ_INC})
......@@ -19,8 +28,5 @@ file(MAKE_DIRECTORY ${ZMQ_INC})
add_library(libzmq STATIC IMPORTED GLOBAL)
add_dependencies(libzmq zmq)
set_target_properties(
libzmq PROPERTIES
IMPORTED_LOCATION ${ZMQ_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${ZMQ_INC}
)
set_target_properties(libzmq PROPERTIES IMPORTED_LOCATION ${ZMQ_LIB}
INTERFACE_INCLUDE_DIRECTORIES ${ZMQ_INC})
......@@ -4,66 +4,61 @@ set(OPR_PARAM_DEFS_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen_param_defs.py)
set(OPR_PARAM_DEFS_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/include/)
file(MAKE_DIRECTORY ${OPR_PARAM_DEFS_OUT_DIR}/megdnn)
add_custom_command(
OUTPUT
${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_defs.h
${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_json.h
COMMAND ${PYTHON3_EXECUTABLE_WITHOUT_VERSION} ${OPR_PARAM_DEFS_SCRIPT} ${OPR_PARAM_DEFS_SRCS}
${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_defs.h
COMMAND ${PYTHON3_EXECUTABLE_WITHOUT_VERSION} ${OPR_PARAM_DEFS_SCRIPT} ${OPR_PARAM_DEFS_SRCS}
tmp_unuse.log --write-cppjson ${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_json.h
DEPENDS ${OPR_PARAM_DEFS_SRCS} ${OPR_PARAM_DEFS_SCRIPT}
VERBATIM
)
list(APPEND OPR_PARAM_DEFS_OUTS
${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_defs.h
OUTPUT ${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_defs.h
${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_json.h
COMMAND ${PYTHON3_EXECUTABLE_WITHOUT_VERSION} ${OPR_PARAM_DEFS_SCRIPT}
${OPR_PARAM_DEFS_SRCS} ${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_defs.h
COMMAND
${PYTHON3_EXECUTABLE_WITHOUT_VERSION} ${OPR_PARAM_DEFS_SCRIPT}
${OPR_PARAM_DEFS_SRCS} tmp_unuse.log --write-cppjson
${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_json.h
)
DEPENDS ${OPR_PARAM_DEFS_SRCS} ${OPR_PARAM_DEFS_SCRIPT}
VERBATIM)
list(APPEND OPR_PARAM_DEFS_OUTS ${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_defs.h
${OPR_PARAM_DEFS_OUT_DIR}/megdnn/opr_param_json.h)
list(APPEND OPR_PARAM_DEFS_INC ${OPR_PARAM_DEFS_OUT_DIR})
set(OPR_PARAM_DEFS_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
file(MAKE_DIRECTORY ${OPR_PARAM_DEFS_OUT_DIR}/src/common)
add_custom_command(
OUTPUT
${OPR_PARAM_DEFS_OUT_DIR}/src/common/opr_param_defs_enumv.cuh
COMMAND ${PYTHON3_EXECUTABLE_WITHOUT_VERSION} ${OPR_PARAM_DEFS_SCRIPT}
--enumv ${OPR_PARAM_DEFS_SRCS}
${OPR_PARAM_DEFS_OUT_DIR}/src/common/opr_param_defs_enumv.cuh
DEPENDS ${OPR_PARAM_DEFS_SRCS} ${OPR_PARAM_DEFS_SCRIPT}
VERBATIM
)
OUTPUT ${OPR_PARAM_DEFS_OUT_DIR}/src/common/opr_param_defs_enumv.cuh
COMMAND
${PYTHON3_EXECUTABLE_WITHOUT_VERSION} ${OPR_PARAM_DEFS_SCRIPT} --enumv
${OPR_PARAM_DEFS_SRCS} ${OPR_PARAM_DEFS_OUT_DIR}/src/common/opr_param_defs_enumv.cuh
DEPENDS ${OPR_PARAM_DEFS_SRCS} ${OPR_PARAM_DEFS_SCRIPT}
VERBATIM)
list(APPEND OPR_PARAM_DEFS_OUTS
${OPR_PARAM_DEFS_OUT_DIR}/src/common/opr_param_defs_enumv.cuh
)
${OPR_PARAM_DEFS_OUT_DIR}/src/common/opr_param_defs_enumv.cuh)
list(APPEND OPR_PARAM_DEFS_INC ${OPR_PARAM_DEFS_OUT_DIR})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/megdnn DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h")
install(
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/megdnn
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h")
add_custom_target(_opr_param_defs DEPENDS ${OPR_PARAM_DEFS_OUTS})
add_library(opr_param_defs INTERFACE)
target_include_directories(opr_param_defs
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
foreach (INCPATH IN LISTS OPR_PARAM_DEFS_INC)
target_include_directories(opr_param_defs
INTERFACE $<BUILD_INTERFACE:${INCPATH}>
)
INTERFACE $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
foreach(INCPATH IN LISTS OPR_PARAM_DEFS_INC)
target_include_directories(opr_param_defs INTERFACE $<BUILD_INTERFACE:${INCPATH}>)
endforeach()
add_dependencies(opr_param_defs _opr_param_defs)
install(TARGETS opr_param_defs EXPORT ${MGE_EXPORT_TARGETS})
if(MGE_WITH_CUDA)
add_library(cutlass INTERFACE)
target_include_directories(cutlass
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party/cutlass/include>)
add_library(cutlass INTERFACE)
target_include_directories(
cutlass
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party/cutlass/include>)
endif()
if(MGE_WITH_TEST)
add_subdirectory(test)
add_subdirectory(test)
endif()
add_subdirectory(src)
......
add_library(atlas-stub STATIC src/libatlas-wrap.cpp)
target_include_directories(atlas-stub PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(
atlas-stub PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
install(TARGETS atlas-stub EXPORT ${MGE_EXPORT_TARGETS})
add_library(acl-cblas STATIC src/libacl_cblas-wrap.cpp)
target_include_directories(acl-cblas PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_include_directories(
acl-cblas PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
file (GLOB_RECURSE CUDA_STUB src/libcuda.cpp)
file (GLOB_RECURSE NVRTC_STUB src/libnvrtc.cpp)
file(GLOB_RECURSE CUDA_STUB src/libcuda.cpp)
file(GLOB_RECURSE NVRTC_STUB src/libnvrtc.cpp)
if(MGE_WITH_CUDA_STUB)
list(APPEND STUB_SRC ${CUDA_STUB})
list(APPEND STUB_SRC ${CUDA_STUB})
endif()
if(MGE_WITH_NVRTC_STUB)
list(APPEND STUB_SRC ${NVRTC_STUB})
list(APPEND STUB_SRC ${NVRTC_STUB})
endif()
if(MSVC OR WIN32)
add_library (cuda-stub STATIC ${STUB_SRC})
add_library(cuda-stub STATIC ${STUB_SRC})
else()
add_library (cuda-stub SHARED ${STUB_SRC})
add_library(cuda-stub SHARED ${STUB_SRC})
endif()
set_target_properties(cuda-stub PROPERTIES OUTPUT_NAME cuda_stub)
target_compile_definitions(cuda-stub PRIVATE __CUDA_API_VERSION_INTERNAL)
if (MSVC OR WIN32)
target_link_libraries(cuda-stub PRIVATE -Wl,--no-undefined)
if(MSVC OR WIN32)
target_link_libraries(cuda-stub PRIVATE -Wl,--no-undefined)
else()
target_link_libraries(cuda-stub PRIVATE dl -Wl,--no-undefined)
target_link_libraries(cuda-stub PRIVATE dl -Wl,--no-undefined)
endif()
target_include_directories(cuda-stub PRIVATE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/genfiles>)
install (TARGETS cuda-stub EXPORT ${MGE_EXPORT_TARGETS})
target_include_directories(cuda-stub
PRIVATE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/genfiles>)
install(TARGETS cuda-stub EXPORT ${MGE_EXPORT_TARGETS})
此差异已折叠。
......@@ -5,38 +5,38 @@ file(GLOB SOURCES_ *.cpp)
list(APPEND SOURCES ${SOURCES_})
if(NOT ${MGE_ARCH} STREQUAL "naive")
file(GLOB_RECURSE SOURCES_ fallback/*.cpp)
file(GLOB_RECURSE SOURCES_ fallback/*.cpp)
list(APPEND SOURCES ${SOURCES_})
file(GLOB_RECURSE SOURCES_ cpu/*.cpp)
list(APPEND SOURCES ${SOURCES_})
if(${MGE_ARCH} STREQUAL "fallback")
message(WARNING "build only with fallback")
elseif(${MGE_ARCH} STREQUAL "x86_64" OR ${MGE_ARCH} STREQUAL "i386")
file(GLOB_RECURSE SOURCES_ x86/*.cpp)
list(APPEND SOURCES ${SOURCES_})
file(GLOB_RECURSE SOURCES_ cpu/*.cpp)
list(APPEND SOURCES ${SOURCES_})
if(${MGE_ARCH} STREQUAL "fallback")
message(WARNING "build only with fallback")
elseif(${MGE_ARCH} STREQUAL "x86_64" OR ${MGE_ARCH} STREQUAL "i386")
file(GLOB_RECURSE SOURCES_ x86/*.cpp)
list(APPEND SOURCES ${SOURCES_})
endif()
endif()
endif()
if(MGE_WITH_CUDA)
file(GLOB_RECURSE SOURCES_ cuda/*.cpp)
list(APPEND SOURCES ${SOURCES_})
file(GLOB_RECURSE SOURCES_ cuda/*.cpp)
list(APPEND SOURCES ${SOURCES_})
file(GLOB_RECURSE CUSOURCES cuda/*.cu)
list(APPEND SOURCES ${CUSOURCES})
file(GLOB_RECURSE CUSOURCES cuda/*.cu)
list(APPEND SOURCES ${CUSOURCES})
endif()
if(MGE_WITH_MIDOUT_PROFILE)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/third_party/midout/src/midout.cpp)
list(APPEND SOURCES ${PROJECT_SOURCE_DIR}/third_party/midout/src/midout.cpp)
endif()
if(MGE_WITH_ATLAS)
file(GLOB_RECURSE SOURCES_ atlas/*.cpp)
list(APPEND SOURCES ${SOURCES_})
file(GLOB_RECURSE SOURCES_ atlas/*.cpp)
list(APPEND SOURCES ${SOURCES_})
endif()
if (MGE_WITH_ROCM)
file (GLOB_RECURSE SOURCES_ rocm/*.cpp)
list (APPEND SOURCES ${SOURCES_})
if(MGE_WITH_ROCM)
file(GLOB_RECURSE SOURCES_ rocm/*.cpp)
list(APPEND SOURCES ${SOURCES_})
endif()
add_executable(megdnn_test ${SOURCES})
......@@ -44,37 +44,36 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
target_link_libraries(megdnn_test gtest)
target_link_libraries(megdnn_test megdnn ${MGE_BLAS_LIBS} ${MGE_CUDA_LIBS})
if (MGE_WITH_CUDA)
target_link_libraries(megdnn_test cutlass)
target_include_directories(megdnn_test PRIVATE ${CUDNN_INCLUDE_DIR})
if(MGE_WITH_CUDA)
target_link_libraries(megdnn_test cutlass)
target_include_directories(megdnn_test PRIVATE ${CUDNN_INCLUDE_DIR})
endif()
if(MGE_WITH_ATLAS)
target_link_libraries(megdnn_test atlas-stub)
target_link_libraries(megdnn_test atlas-stub)
endif()
target_include_directories(megdnn_test
PRIVATE
${PROJECT_SOURCE_DIR}/third_party/midout/src
)
PRIVATE ${PROJECT_SOURCE_DIR}/third_party/midout/src)
if(APPLE OR ANDROID)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
else()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
if(MGE_ENABLE_COVERAGE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
if (MEG_WITH_ROCM)
target_link_libraries (megdnn_test ${MGE_ROCM_LIBS})
endif ()
if(MEG_WITH_ROCM)
target_link_libraries(megdnn_test ${MGE_ROCM_LIBS})
endif()
if(UNIX)
if(APPLE OR ANDROID)
target_link_libraries(megdnn_test dl)
else()
target_link_libraries(megdnn_test dl rt)
endif()
if(APPLE OR ANDROID)
target_link_libraries(megdnn_test dl)
else()
target_link_libraries(megdnn_test dl rt)
endif()
endif()
此差异已折叠。
# mgb tablegen executable
set(TABLE_TARGET mgb-mlir-autogen)
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
file(GLOB_RECURSE SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.h
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
add_executable(${TABLE_TARGET} ${SRCS})
target_include_directories(${TABLE_TARGET} PRIVATE ${MLIR_LLVM_INCLUDE_DIR})
target_link_libraries(${TABLE_TARGET} PRIVATE LLVMTableGen MLIRTableGen LLVMSupport)
......@@ -13,5 +14,8 @@ tablegen(MGB opdef.cpp.inl ${MGE_IR_INCLUDE_DIRS} "--gen-cpp-body")
tablegen(MGB opdef.py.inl ${MGE_IR_INCLUDE_DIRS} "--gen-python-binding")
tablegen(MGB opdef.cpy.inl ${MGE_IR_INCLUDE_DIRS} "--gen-python-c-extension")
tablegen(MGB enum_macro.h ${MGE_IR_INCLUDE_DIRS} "--gen-enum-list-macro")
add_custom_target(mgb_opdef ALL DEPENDS opdef.h.inl opdef.cpp.inl opdef.py.inl opdef.cpy.inl enum_macro.h param_defs_tblgen)
set(MGB_OPDEF_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
add_custom_target(mgb_opdef ALL DEPENDS opdef.h.inl opdef.cpp.inl opdef.py.inl
opdef.cpy.inl enum_macro.h param_defs_tblgen)
set(MGB_OPDEF_OUT_DIR
${CMAKE_CURRENT_BINARY_DIR}
PARENT_SCOPE)
......@@ -5,46 +5,60 @@ file(GLOB_RECURSE SOURCES ../src/test/*.cpp ../src/impl/*.cpp ${MGB_TEST_DIR}/*.
# disable distributed tests
if(NOT MGE_WITH_DISTRIBUTED)
list(FILTER SOURCES EXCLUDE REGEX ".*test/collective_comm.cpp")
list(FILTER SOURCES EXCLUDE REGEX ".*test/io_remote.cpp")
list(FILTER SOURCES EXCLUDE REGEX ".*test/collective_comm.cpp")
list(FILTER SOURCES EXCLUDE REGEX ".*test/io_remote.cpp")
endif()
# TODO: turn python binding into a static/object library
add_executable(imperative_test ${SOURCES} ${SRCS})
add_dependencies(imperative_test mgb_opdef)
target_include_directories(imperative_test PRIVATE ${MGB_TEST_DIR}/include ../src/include ${MGB_OPDEF_OUT_DIR} ${CPP_REDIS_INCLUDES})
target_include_directories(
imperative_test PRIVATE ${MGB_TEST_DIR}/include ../src/include ${MGB_OPDEF_OUT_DIR}
${CPP_REDIS_INCLUDES})
# Python binding
target_include_directories(imperative_test PRIVATE ${MODULE_SRC_INCLUDE} ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR})
target_include_directories(
imperative_test PRIVATE ${MODULE_SRC_INCLUDE} ${PYTHON_INCLUDE_DIRS}
${NUMPY_INCLUDE_DIR})
target_compile_definitions(imperative_test PRIVATE MODULE_NAME=C)
target_compile_options(imperative_test PRIVATE -Wno-unused-parameter)
set(LINK_LIBS megbrain megdnn ${MGE_CUDA_LIBS} gtest gmock pybind11::embed range-v3 nlohmann_json::nlohmann_json)
set(LINK_LIBS
megbrain
megdnn
${MGE_CUDA_LIBS}
gtest
gmock
pybind11::embed
range-v3
nlohmann_json::nlohmann_json)
if(MGE_WITH_CUDA)
list(APPEND LINK_LIBS cudart)
list(APPEND LINK_LIBS cudart)
endif()
if(MGE_WITH_DISTRIBUTED)
list(APPEND LINK_LIBS megray)
list(APPEND LINK_LIBS megray)
endif()
target_link_libraries(imperative_test ${LINK_LIBS})
if(CXX_SUPPORT_WCLASS_MEMACCESS)
if(MGE_WITH_CUDA)
target_compile_options(imperative_test PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-Wno-class-memaccess>"
"$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-Wno-class-memaccess>")
else()
target_compile_options(imperative_test PRIVATE "-Wno-class-memaccess")
endif()
if(MGE_WITH_CUDA)
target_compile_options(
imperative_test
PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=-Wno-class-memaccess>"
"$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-Wno-class-memaccess>")
else()
target_compile_options(imperative_test PRIVATE "-Wno-class-memaccess")
endif()
endif()
if(UNIX)
if(APPLE OR ANDROID)
target_link_libraries(imperative_test dl)
else()
target_link_libraries(imperative_test dl rt)
endif()
if(APPLE OR ANDROID)
target_link_libraries(imperative_test dl)
else()
target_link_libraries(imperative_test dl rt)
endif()
endif()
install(TARGETS imperative_test RUNTIME DESTINATION test)
此差异已折叠。
add_executable(lite_c_examples ./main.c)
if(LITE_BUILD_WITH_RKNPU)
#rknn sdk1.0.0 depend on libc++_shared, use gold to remove NEEDED so symbol check
target_link_options(lite_c_examples PRIVATE "-fuse-ld=gold")
# rknn sdk1.0.0 depend on libc++_shared, use gold to remove NEEDED so symbol check
target_link_options(lite_c_examples PRIVATE "-fuse-ld=gold")
endif()
target_link_libraries(lite_c_examples lite_static)
if(LITE_BUILD_WITH_MGE AND MGE_WITH_ROCM)
# FIXME: hip obj can not find cpp obj only through lite_static
target_link_libraries(lite_c_examples megdnn)
# FIXME: hip obj can not find cpp obj only through lite_static
target_link_libraries(lite_c_examples megdnn)
endif()
if(UNIX)
if(APPLE OR ANDROID)
target_link_libraries(lite_c_examples dl)
else()
target_link_libraries(lite_c_examples dl rt)
endif()
if(APPLE OR ANDROID)
target_link_libraries(lite_c_examples dl)
else()
target_link_libraries(lite_c_examples dl rt)
endif()
endif()
install (TARGETS lite_c_examples
EXPORT ${LITE_EXPORT_TARGETS}
RUNTIME DESTINATION lite/bin)
install(
TARGETS lite_c_examples
EXPORT ${LITE_EXPORT_TARGETS}
RUNTIME DESTINATION lite/bin)
# add lite_examples_depends_shared for CI check symbol export valid
add_executable(lite_c_examples_depends_shared ./main.c)
add_executable(lite_c_examples_depends_shared ./main.c)
if(LITE_BUILD_WITH_RKNPU)
#rknn sdk1.0.0 depend on libc++_shared, use gold to remove NEEDED so symbol check
target_link_options(lite_c_examples_depends_shared PRIVATE "-fuse-ld=gold")
# rknn sdk1.0.0 depend on libc++_shared, use gold to remove NEEDED so symbol check
target_link_options(lite_c_examples_depends_shared PRIVATE "-fuse-ld=gold")
endif()
target_link_libraries(lite_c_examples_depends_shared lite_shared)
if(UNIX)
if(APPLE OR ANDROID)
target_link_libraries(lite_c_examples_depends_shared dl)
else()
target_link_libraries(lite_c_examples_depends_shared dl rt)
endif()
if(APPLE OR ANDROID)
target_link_libraries(lite_c_examples_depends_shared dl)
else()
target_link_libraries(lite_c_examples_depends_shared dl rt)
endif()
endif()
install (TARGETS lite_c_examples_depends_shared
EXPORT ${LITE_EXPORT_TARGETS}
RUNTIME DESTINATION lite/bin)
install(
TARGETS lite_c_examples_depends_shared
EXPORT ${LITE_EXPORT_TARGETS}
RUNTIME DESTINATION lite/bin)
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册