-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
121 lines (110 loc) · 4.88 KB
/
CMakeLists.txt
File metadata and controls
121 lines (110 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Copyright (c) PyPTO Contributors.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# -----------------------------------------------------------------------------------------------------------
# Build Host runtime using host/* + common/* + custom includes and sources (for `Runtime`)
# CMAKE_C_COMPILER and CMAKE_CXX_COMPILER are set when calling cmake
# CUSTOM_INCLUDE_DIRS and CUSTOM_SOURCE_DIRS are set when calling cmake
# ASCEND_HOME_PATH is set when calling cmake
cmake_minimum_required(VERSION 3.16.3)
project(host_runtime LANGUAGES C CXX)
# Build complete include list
set(CMAKE_CUSTOM_INCLUDE_DIRS "")
list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../include")
list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/task_interface")
list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/worker")
list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/host")
list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/aicpu_dispatcher")
if(DEFINED CUSTOM_INCLUDE_DIRS)
foreach(INC_DIR ${CUSTOM_INCLUDE_DIRS})
list(APPEND CMAKE_CUSTOM_INCLUDE_DIRS "${INC_DIR}")
endforeach()
else()
message(FATAL_ERROR "MUST set CUSTOM_INCLUDE_DIRS to build Host runtime")
endif()
# Build complete source list: core host sources + sources from CUSTOM_SOURCE_DIRS
set(HOST_RUNTIME_SOURCES "")
list(APPEND HOST_RUNTIME_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/device_runner.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/memory_allocator.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/pto_runtime_c_api.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/platform_compile_info.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/host_regs.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/aicpu_loader.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../../src/host/host_log.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../../src/host/unified_log_host.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../../src/host/performance_collector.cpp"
)
# Add common/host sources (LoadAicpuOp)
list(APPEND HOST_RUNTIME_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../common/host/load_aicpu_op.cpp"
)
if(DEFINED CUSTOM_SOURCE_DIRS)
foreach(SRC_DIR ${CUSTOM_SOURCE_DIRS})
file(GLOB DIR_SOURCES "${SRC_DIR}/*.cpp" "${SRC_DIR}/*.c")
list(APPEND HOST_RUNTIME_SOURCES ${DIR_SOURCES})
endforeach()
else()
message(STATUS "CUSTOM_SOURCE_DIRS not set, using only core sources")
endif()
# Create shared library
list(LENGTH HOST_RUNTIME_SOURCES NUM_HOST_RUNTIME_SOURCES)
message(STATUS "Host runtime: ${NUM_HOST_RUNTIME_SOURCES} source files")
message(VERBOSE "Host runtime sources: ${HOST_RUNTIME_SOURCES}")
add_library(host_runtime SHARED ${HOST_RUNTIME_SOURCES})
# C++ standard (applied only to C++ files)
set_target_properties(host_runtime PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
# Compile options (matching AICPU pattern)
target_compile_options(host_runtime
PRIVATE
-Wall
-Wextra
-fPIC
-O3
-g
)
# Include directories - always include local headers
target_include_directories(host_runtime
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../include
${CMAKE_CUSTOM_INCLUDE_DIRS}
PRIVATE
${ASCEND_HOME_PATH}/include
${ASCEND_HOME_PATH}/pkg_inc
${ASCEND_HOME_PATH}/pkg_inc/runtime
${ASCEND_HOME_PATH}/pkg_inc/profiling
${ASCEND_HOME_PATH}/${CMAKE_SYSTEM_PROCESSOR}-linux/include/driver
)
# Conditional compilation for new CANN interface
option(BUILD_WITH_NEW_CANN "Use new rtsLaunchCpuKernel interface (CANN 7.0+)" ON)
if(BUILD_WITH_NEW_CANN)
target_compile_definitions(host_runtime PRIVATE BUILD_WITH_NEW_CANN)
# Add additional include path for new RTS headers (CANN 7.0+)
target_include_directories(host_runtime PRIVATE
${ASCEND_HOME_PATH}/pkg_inc/runtime/runtime
)
message(STATUS "Building with new CANN rtsLaunchCpuKernel interface")
endif()
# Link against CANN runtime libraries
# ascend_hal is dynamically loaded at runtime via dlopen in device_runner
# when performance profiling is enabled
target_link_libraries(host_runtime
PRIVATE
runtime
ascendcl
dl
)
target_link_directories(host_runtime
PRIVATE
${ASCEND_HOME_PATH}/lib64
${ASCEND_HOME_PATH}/runtime/lib64
)
set_target_properties(host_runtime PROPERTIES OUTPUT_NAME "host_runtime")