poplar.cmake 3.5 KB
Newer Older
J
jianghaicheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
# 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.
A
Allen Guo 已提交
14

A
Allen Guo 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27
macro(find_popart_version popart_version_file)
  file(READ ${popart_version_file} popart_version_file_content)
  string(REGEX MATCH "(POPART_VERSION_STRING)[ \t\r\n](\")([0-9]+\.[0-9]+\.[0-9]+)(\\+)([A-Za-z0-9_]*)(\")" POPART_VERSION ${popart_version_file_content})
  string(REPLACE "POPART_VERSION_STRING" "" POPART_VERSION "${POPART_VERSION}")
  string(REPLACE "\"" "" POPART_VERSION "${POPART_VERSION}")
  string(REPLACE " " "" POPART_VERSION "${POPART_VERSION}")
  if(NOT POPART_VERSION)
    set(POPART_VERSION "Unknown version")
  else()
    message(STATUS "Current PopART version is ${POPART_VERSION}")
  endif()
endmacro()

J
jianghaicheng 已提交
28 29 30 31 32
if(WITH_IPU)
  set(POPLAR_DIR CACHE PATH "Path to a Poplar install")
  set(POPART_DIR CACHE PATH "Path to a Popart install")
  set(POPLAR_SDK_DIR CACHE PATH "Path to an extracted SDK archive or to a Poplar & Popart install directory (Will populate POPLAR_DIR and POPART_DIR)")

A
Allen Guo 已提交
33 34
  # support setting SDK both from environment variable or command line arguments

J
jianghaicheng 已提交
35 36
  if(DEFINED ENV{POPLAR_SDK_DIR})
    set(POPLAR_SDK_DIR $ENV{POPLAR_SDK_DIR})
A
Allen Guo 已提交
37 38
  endif()
  if(EXISTS ${POPLAR_SDK_DIR})
J
jianghaicheng 已提交
39 40 41 42 43
    execute_process(COMMAND find ${POPLAR_SDK_DIR}/ -maxdepth 1 -type d -name "popart*"
      OUTPUT_VARIABLE POPART_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
    execute_process(COMMAND find ${POPLAR_SDK_DIR}/ -maxdepth 1 -type d -name "poplar-*" -o -name "poplar"
      OUTPUT_VARIABLE POPLAR_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
  endif()
A
Allen Guo 已提交
44 45 46 47 48 49
  if(DEFINED ENV{POPLAR_DIR})
    set(POPLAR_DIR $ENV{POPLAR_DIR})
  endif()
  if(DEFINED ENV{POPART_DIR})
    set(POPART_DIR $ENV{POPART_DIR})
  endif()
J
jianghaicheng 已提交
50 51

  if(EXISTS ${POPLAR_DIR})
A
Allen Guo 已提交
52 53 54 55
    message("POPLAR_DIR is ${POPLAR_DIR}")
    if(NOT IS_DIRECTORY "${POPLAR_DIR}")
      message(FATAL_ERROR "Couldn't find a \"poplar\" or \"poplar-*\" folder in '${POPLAR_SDK_DIR}'")
    endif()
J
jianghaicheng 已提交
56 57 58 59 60 61 62 63 64 65
    list(APPEND CMAKE_PREFIX_PATH ${POPLAR_DIR})
    set(ENABLE_POPLAR_CMD "source ${POPLAR_DIR}/enable.sh")
    find_package(poplar REQUIRED)
    include_directories("${POPLAR_DIR}/include")
    link_directories("${POPLAR_DIR}/lib")
  endif()
  if(NOT poplar_FOUND)
      message(FATAL_ERROR "You must provide a path to a Poplar install using -DPOPLAR_DIR=/path/to/popart/build/install")
  endif()
  if(EXISTS ${POPART_DIR})
A
Allen Guo 已提交
66 67 68 69
    message("POPART_DIR is ${POPART_DIR}")
    if(NOT IS_DIRECTORY "${POPART_DIR}")
      message(FATAL_ERROR "Couldn't find a \"popart*\" folder in '${POPLAR_SDK_DIR}'")
    endif()
J
jianghaicheng 已提交
70 71 72 73 74 75 76 77 78
    list(APPEND CMAKE_PREFIX_PATH ${POPART_DIR})
    set(ENABLE_POPART_CMD "source ${POPART_DIR}/enable.sh")
    find_package(popart REQUIRED COMPONENTS popart-only)
    include_directories("${POPART_DIR}/include")
    link_directories("${POPART_DIR}/lib")
  endif()
  if(NOT popart_FOUND)
    message(FATAL_ERROR "You must provide a path to a Popart build using -DPOPART_DIR=/path/to/popart/build")
  endif()
A
Allen Guo 已提交
79

A
Allen Guo 已提交
80 81
  find_popart_version("${POPART_DIR}/include/popart/version.hpp")

J
jianghaicheng 已提交
82 83 84
  add_definitions(-DONNX_NAMESPACE=onnx)
  add_custom_target(extern_poplar DEPENDS poplar popart-only)
endif()