cinn.cmake 3.0 KB
Newer Older
H
Huihuang Zheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

15
if(NOT WITH_CINN)
H
Huihuang Zheng 已提交
16 17 18
  return()
endif()

19 20 21 22 23 24
if(NOT CINN_GIT_TAG)
  set(CINN_GIT_TAG release/v0.2)
endif()

message(STATUS "CINN version: " ${CINN_GIT_TAG})

H
Huihuang Zheng 已提交
25 26 27 28 29 30 31 32 33
# TODO(zhhsplendid): CINN has lots of warnings during early development.
# They will be treated as errors under paddle. We set no-error now and we will
# clean the code in the future.
add_definitions(-w)

######################################
# Build CINN from Git External Project
######################################
include(ExternalProject)
34
set(CINN_PREFIX_DIR ${THIRD_PARTY_PATH}/CINN)
35 36 37 38 39 40 41 42
set(CINN_OPTIONAL_ARGS
    -DPY_VERSION=${PY_VERSION}
    -DWITH_CUDA=${WITH_GPU}
    -DWITH_CUDNN=${WITH_GPU}
    -DWITH_MKL_CBLAS=${WITH_MKL}
    -DWITH_MKLDNN=${WITH_MKL}
    -DPUBLISH_LIBS=ON
    -DWITH_TESTING=ON)
43
set(CINN_BUILD_COMMAND $(MAKE) cinnapi -j)
H
Huihuang Zheng 已提交
44 45 46
ExternalProject_Add(
  external_cinn
  ${EXTERNAL_PROJECT_LOG_ARGS}
47 48 49 50 51 52
  GIT_REPOSITORY "${GIT_URL}/PaddlePaddle/CINN.git"
  GIT_TAG ${CINN_GIT_TAG}
  PREFIX ${CINN_PREFIX_DIR}
  BUILD_COMMAND ${CINN_BUILD_COMMAND}
  INSTALL_COMMAND ""
  CMAKE_ARGS ${CINN_OPTIONAL_ARGS})
H
Huihuang Zheng 已提交
53

54 55
ExternalProject_Get_Property(external_cinn BINARY_DIR)
ExternalProject_Get_Property(external_cinn SOURCE_DIR)
H
Huihuang Zheng 已提交
56 57 58 59 60 61
set(CINN_BINARY_DIR ${BINARY_DIR})
set(CINN_SOURCE_DIR ${SOURCE_DIR})

message(STATUS "CINN BINARY_DIR: ${CINN_BINARY_DIR}")
message(STATUS "CINN SOURCE_DIR: ${CINN_SOURCE_DIR}")

62 63 64
######################################
# Add CINN's dependencies header files
######################################
H
Huihuang Zheng 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

# Add absl
set(ABSL_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/third_party/absl/include")
include_directories(${ABSL_INCLUDE_DIR})

# Add isl
set(ISL_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/third_party/isl/include")
include_directories(${ISL_INCLUDE_DIR})

# Add LLVM
set(LLVM_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/third_party/llvm/include")
include_directories(${LLVM_INCLUDE_DIR})

######################################################
# Put external_cinn and dependencies together as a lib
######################################################

set(CINN_LIB_NAME "libcinnapi.so")
set(CINN_LIB_LOCATION "${CINN_BINARY_DIR}/dist/cinn/lib")
set(CINN_INCLUDE_DIR "${CINN_BINARY_DIR}/dist/cinn/include")

add_library(cinn SHARED IMPORTED GLOBAL)
87 88
set_target_properties(cinn PROPERTIES IMPORTED_LOCATION
                                      "${CINN_LIB_LOCATION}/${CINN_LIB_NAME}")
H
Huihuang Zheng 已提交
89
include_directories(${CINN_INCLUDE_DIR})
90
add_dependencies(cinn external_cinn)