cmake_minimum_required(VERSION 3.16.3)
project(PTO_Framework_PyPTO_Impl LANGUAGES C CXX)
if (NOT DEFINED PTO_FWK_SRC_ROOT)
get_filename_component(_WhlLibDir "${CMAKE_CURRENT_SOURCE_DIR}/../../" REALPATH)
get_filename_component(_WhlLibFwkDir "${_WhlLibDir}/framework" REALPATH)
if ("${Python3_EXECUTABLE}x" STREQUAL "x")
message(FATAL_ERROR "Python3 interpreter path not defined, can't build pypto_impl online")
endif ()
get_filename_component(_Python3__EXECUTABLE "${Python3_EXECUTABLE}" REALPATH)
get_filename_component(_Python3_ROOT_DIR "${_Python3__EXECUTABLE}" DIRECTORY)
get_filename_component(_Python3_ROOT_DIR "${_Python3_ROOT_DIR}/../" REALPATH)
set(Python3_ROOT_DIR "${_Python3_ROOT_DIR}" CACHE INTERNAL "Python3 root path" FORCE)
message(STATUS "Python3_ROOT_DIR=${Python3_ROOT_DIR}")
if ("${Python3_EXECUTABLE_VERSION}x" STREQUAL "x")
message(FATAL_ERROR "Python3 interpreter version not defined, can't build pypto_impl online")
endif ()
find_package(Python3 ${Python3_EXECUTABLE_VERSION} EXACT COMPONENTS Development)
if (NOT Python3_Development_FOUND)
message(FATAL_ERROR "Can't get python3-dev, can't build pypto_impl online.")
endif ()
if ("${Python3_MOD_PYBIND11_CMAKE_DIR}x" STREQUAL "x")
message(FATAL_ERROR "Can't get pybind11 cmake dir, can't build pypto_impl online")
endif ()
find_package(pybind11 CONFIG REQUIRED PATHS ${Python3_MOD_PYBIND11_CMAKE_DIR} NO_DEFAULT_PATH)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include("${_WhlLibFwkDir}/cmake/intf.cmake")
option(BUILD_WITH_CANN "Build with CANN." ON)
endif ()
pybind11_add_module(pypto_impl
MODULE
pybind11.cpp
bindings/torch_tensor_converter.cpp
bindings/enum.cpp
bindings/element.cpp
bindings/tensor.cpp
bindings/symbolic_scalar.cpp
bindings/controller.cpp
bindings/operation.cpp
bindings/runtime.cpp
bindings/cost_model.cpp
bindings/pass_config.cpp
bindings/function.cpp
bindings/distributed.cpp
bindings/platform.cpp
bindings/utils.cpp
bindings/ir/ir.cpp
bindings/ir/builder.cpp
bindings/ir/logging.cpp
bindings/ir/pass.cpp
bindings/pypto_pro/codegen.cpp
bindings/pypto_pro/backend.cpp
)
target_include_directories(pypto_impl
PRIVATE
$<$<NOT:$<BOOL:${PTO_FWK_SRC_ROOT}>>:${_WhlLibFwkDir}/3rd/include>
$<$<NOT:$<BOOL:${PTO_FWK_SRC_ROOT}>>:${_WhlLibFwkDir}/include>
$<$<NOT:$<BOOL:${PTO_FWK_SRC_ROOT}>>:${_WhlLibFwkDir}/include/pypto_pro>
$<$<NOT:$<BOOL:${PTO_FWK_SRC_ROOT}>>:${_WhlLibFwkDir}/src>
$<$<NOT:$<BOOL:${PTO_FWK_SRC_ROOT}>>:${_WhlLibFwkDir}/src/interface>
$<$<NOT:$<BOOL:${PTO_FWK_SRC_ROOT}>>:${_WhlLibFwkDir}/src/interface/machine/device>
${PTO_FWK_SRC_ROOT}/framework/include/pypto_pro
${CMAKE_CURRENT_LIST_DIR}
)
target_compile_definitions(pypto_impl
PRIVATE
$<BUILD_INTERFACE:$<$<BOOL:${BUILD_WITH_CANN}>:BUILD_WITH_CANN>>
)
target_link_libraries(pypto_impl
PRIVATE
$<$<BOOL:${PTO_FWK_SRC_ROOT}>:json>
c_sec
intf_pub_cxx17
tile_fwk_intf_pub
)
target_link_directories(pypto_impl
PRIVATE
$<$<NOT:$<BOOL:${PTO_FWK_SRC_ROOT}>>:${_WhlLibDir}>
)
if (DEFINED PTO_FWK_SRC_ROOT)
if (TARGET c_sec_shared)
add_dependencies(pypto_impl c_sec_shared)
endif ()
PTO_Fwk_GenerateGCovConfigJson(TARGET pypto_impl)
else ()
install(TARGETS pypto_impl LIBRARY DESTINATION ".")
endif ()