-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathCMakeLists.txt
89 lines (82 loc) · 3.24 KB
/
CMakeLists.txt
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
include(${CMAKE_SOURCE_DIR}/cmake/cxx_standard.cmake)
file(GLOB python_srcs CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/*.h"
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp"
)
pybind11_add_module(python ${python_srcs})
target_include_directories(python PRIVATE ${ORT_HEADER_DIR})
target_link_directories(python PRIVATE ${ORT_LIB_DIR})
target_link_libraries(python PRIVATE onnxruntime-genai-static ${ONNXRUNTIME_LIB})
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set_property(TARGET python APPEND_STRING PROPERTY LINK_FLAGS " -Xlinker -rpath=\\$ORIGIN")
target_link_libraries(python PRIVATE stdc++fs)
endif()
set_target_properties(python PROPERTIES OUTPUT_NAME "onnxruntime_genai")
if(CMAKE_GENERATOR_TOOLSET MATCHES "Visual Studio")
target_link_options(python PRIVATE "/CETCOMPAT")
target_compile_options(python PRIVATE "/sdl" PRIVATE "/Qspectre")
endif()
if(USE_CUDA AND CMAKE_CUDA_COMPILER)
cmake_policy(SET CMP0104 OLD)
enable_language(CUDA)
set_target_properties(python PROPERTIES LINKER_LANGUAGE CUDA)
target_link_libraries(python PRIVATE cublasLt cublas cudnn curand cufft cudart)
endif()
source_group("Sources" FILES ${python_srcs})
if(BUILD_WHEEL)
set(WHEEL_FILES_DIR "${CMAKE_BINARY_DIR}/wheel")
message("Setting up wheel files in : ${WHEEL_FILES_DIR}")
if(USE_CUDA)
set(TARGET_NAME "onnxruntime-genai-cuda")
else()
set(TARGET_NAME "onnxruntime-genai")
endif()
set(PACKAGE_DIR_NAME "onnxruntime_genai")
set(WHEEL_TARGET_NAME "${WHEEL_FILES_DIR}/${PACKAGE_DIR_NAME}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in ${WHEEL_FILES_DIR}/setup.py @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in ${WHEEL_TARGET_NAME}/__init__.py @ONLY)
# Copy over any additional python files
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/py/" DESTINATION ${WHEEL_TARGET_NAME}/)
file(COPY "${CMAKE_SOURCE_DIR}/ThirdPartyNotices.txt" DESTINATION ${WHEEL_TARGET_NAME}/)
add_custom_command(TARGET python POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${onnxruntime_libs} $<TARGET_FILE:python>
${WHEEL_TARGET_NAME}
COMMENT "Copying files to wheel directory: ${WHEEL_TARGET_NAME}"
)
set(auditwheel_exclude_list
"libcublas.so.11"
"libcublas.so.12"
"libcublasLt.so.11"
"libcublasLt.so.12"
"libcudart.so.11.0"
"libcudart.so.12"
"libcudnn.so.8"
"libcufft.so.10"
"libcufft.so.11"
"libcurand.so.10"
"libnvinfer.so.8"
"libnvinfer_plugin.so.8"
"libnvonnxparser.so.8"
)
set(modified_exclude_list)
foreach(item IN LISTS auditwheel_exclude_list)
list(APPEND modified_exclude_list "--exclude" ${item})
endforeach()
if(MANYLINUX)
add_custom_target(PyPackageBuild ALL
COMMAND ${PYTHON_EXECUTABLE} -m pip wheel .
COMMAND ${CMAKE_COMMAND} -E remove ${WHEEL_TARGET_NAME}/onnxruntime_genai.cpython-*
COMMAND auditwheel repair onnxruntime_genai*linux_x86_64.whl -w ${WHEEL_FILES_DIR} ${modified_exclude_list}
WORKING_DIRECTORY "${WHEEL_FILES_DIR}"
COMMENT "Building wheel with MANYLINUX on ${WHEEL_FILES_DIR}"
)
else()
add_custom_target(PyPackageBuild ALL
COMMAND ${PYTHON_EXECUTABLE} -m pip wheel .
WORKING_DIRECTORY "${WHEEL_FILES_DIR}"
COMMENT "Building wheel on ${WHEEL_FILES_DIR}"
)
endif()
add_dependencies(PyPackageBuild python)
endif()