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

INCLUDE(ExternalProject)

17
SET(WARPCTC_PREFIX_DIR ${THIRD_PARTY_PATH}/warpctc)
18
SET(WARPCTC_SOURCE_DIR ${THIRD_PARTY_PATH}/warpctc/src/extern_warpctc)
Y
Yu Yang 已提交
19
SET(WARPCTC_INSTALL_DIR ${THIRD_PARTY_PATH}/install/warpctc)
20
set(WARPCTC_REPOSITORY https://github.com/baidu-research/warp-ctc)
21
set(WARPCTC_TAG        6d5b8fac130638862d97dc48ef43a8d7b5a503bb)
22

23 24
SET(WARPCTC_INCLUDE_DIR "${WARPCTC_INSTALL_DIR}/include"
    CACHE PATH "Warp-ctc Directory" FORCE)
25 26 27
# Used in unit test test_WarpCTCLayer
SET(WARPCTC_LIB_DIR "${WARPCTC_INSTALL_DIR}/lib"
    CACHE PATH "Warp-ctc Library Directory" FORCE)
L
liaogang 已提交
28

P
peizhilin 已提交
29
IF(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" OR WIN32)
L
liaogang 已提交
30 31 32 33 34
    SET(USE_OMP OFF)
ELSE()
    SET(USE_OMP ON)
ENDIF()

35
cache_third_party(extern_warpctc
36 37
    REPOSITORY   ${WARPCTC_REPOSITORY}
    TAG          ${WARPCTC_TAG})
P
peizhilin 已提交
38

39 40 41 42 43
if(WIN32)
    file(TO_NATIVE_PATH ${PADDLE_SOURCE_DIR}/patches/warpctc native_src)
    file(TO_NATIVE_PATH ${WARPCTC_SOURCE_DIR} native_dst)
    set(WARPCTC_PATCH_COMMAND xcopy ${native_src} ${native_dst} /E/Y)
else()
44
    set(WARPCTC_PATCH_COMMAND cp -r ${PADDLE_SOURCE_DIR}/patches/warpctc/ ${WARPCTC_SOURCE_DIR})
45 46
endif()

L
liaogang 已提交
47
ExternalProject_Add(
L
liaogang 已提交
48
    extern_warpctc
L
liaogang 已提交
49
    ${EXTERNAL_PROJECT_LOG_ARGS}
50
    ${SHALLOW_CLONE}
51 52 53
    "${WARPCTC_DOWNLOAD_CMD}"
    PREFIX          ${WARPCTC_PREFIX_DIR}
    SOURCE_DIR      ${WARPCTC_SOURCE_DIR}
L
liaogang 已提交
54
    UPDATE_COMMAND  ""
55
    PATCH_COMMAND   ${WARPCTC_PATCH_COMMAND}
L
liaogang 已提交
56
    CMAKE_ARGS      -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
57 58
                    -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
                    -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
P
peizhilin 已提交
59 60 61 62 63
                    -DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
                    -DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
                    -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
                    -DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}
                    -DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}
64 65 66 67 68 69
                    -DCMAKE_INSTALL_PREFIX=${WARPCTC_INSTALL_DIR}
                    -DWITH_GPU=${WITH_GPU}
                    -DWITH_OMP=${USE_OMP}
                    -DWITH_TORCH=OFF
                    -DCMAKE_DISABLE_FIND_PACKAGE_Torch=ON
                    -DBUILD_SHARED=ON
70
                    -DBUILD_TESTS=OFF
71
                    -DCMAKE_POSITION_INDEPENDENT_CODE=ON
72
                    -DCMAKE_BUILD_TYPE=${THIRD_PARTY_BUILD_TYPE}
73
                    ${EXTERNAL_OPTIONAL_ARGS}
74
    CMAKE_CACHE_ARGS -DCMAKE_BUILD_TYPE:STRING=${THIRD_PARTY_BUILD_TYPE}
L
liaogang 已提交
75 76
                     -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
                     -DCMAKE_INSTALL_PREFIX:PATH=${WARPCTC_INSTALL_DIR}
L
liaogang 已提交
77
)
P
peizhilin 已提交
78
IF(WIN32)
79
    SET(WARPCTC_LIBRARIES "${WARPCTC_INSTALL_DIR}/bin/warpctc${CMAKE_SHARED_LIBRARY_SUFFIX}"
P
peizhilin 已提交
80 81 82 83 84
            CACHE FILEPATH "Warp-ctc Library" FORCE)
else(WIN32)
    SET(WARPCTC_LIBRARIES "${WARPCTC_INSTALL_DIR}/lib/libwarpctc${CMAKE_SHARED_LIBRARY_SUFFIX}"
            CACHE FILEPATH "Warp-ctc Library" FORCE)
ENDIF(WIN32)
L
liaogang 已提交
85

86
MESSAGE(STATUS "warp-ctc library: ${WARPCTC_LIBRARIES}")
87
get_filename_component(WARPCTC_LIBRARY_PATH ${WARPCTC_LIBRARIES} DIRECTORY)
88
INCLUDE_DIRECTORIES(${WARPCTC_INCLUDE_DIR}) # For warpctc code to include its headers.
89

Y
Yiqun Liu 已提交
90
ADD_LIBRARY(warpctc SHARED IMPORTED GLOBAL)
L
liaogang 已提交
91 92
SET_PROPERTY(TARGET warpctc PROPERTY IMPORTED_LOCATION ${WARPCTC_LIBRARIES})
ADD_DEPENDENCIES(warpctc extern_warpctc)