Skip to content

Commit f0c449c

Browse files
authored
Jingxu10/cppsdk 20 (#1466)
* update cppsdk usage * correct IPEXConfig.cmake.in * append installed files, gitrev and build type to the install log file
1 parent ad63503 commit f0c449c

File tree

5 files changed

+63
-46
lines changed

5 files changed

+63
-46
lines changed

cmake/IPEXConfig.cmake.in

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
#
44
# Finds the Torch IPEX library
55
#
6-
# This will define the following variables. The last 3 are appended to the
7-
# TORCH counterpart variables respectively.
6+
# This will define the following variables:
87
#
9-
# IPEX_FOUND -- True if the system has the Torch IPEX library
10-
# IPEX_INCLUDE_DIRS -- The include directories for torch
11-
# IPEX_LIBRARIES -- Libraries to link against
12-
# IPEX_CXX_FLAGS -- Additional (required) compiler flags
8+
# IPEX_FOUND -- True if the system has the Torch IPEX library
9+
# IPEX_INCLUDE_DIRS -- The include directories for torch
10+
# IPEX_LIBRARIES -- Libraries to link against
11+
# IPEX_CXX_FLAGS -- Additional (required) compiler flags
12+
#
13+
# TORCH_IPEX_INCLUDE_DIRS -- TORCH_INCLUDE_DIRS + IPEX_INCLUDE_DIRS
14+
# TORCH_IPEX_LIBRARIES -- TORCH_LIBRARIES + IPEX_LIBRARIES
15+
# TORCH_IPEX_CXX_FLAGS -- TORCH_CXX_FLAGS + IPEX_CXX_FLAGS
1316
#
1417
# and the following imported targets:
1518
#
@@ -18,8 +21,6 @@
1821

1922
include(FindPackageHandleStandardArgs)
2023

21-
FIND_PACKAGE(Torch REQUIRED)
22-
2324
if(DEFINED ENV{IPEX_INSTALL_PREFIX})
2425
set(IPEX_INSTALL_PREFIX $ENV{IPEX_INSTALL_PREFIX})
2526
else()
@@ -30,35 +31,33 @@ endif()
3031

3132
# Include directories.
3233
if(EXISTS "${IPEX_INSTALL_PREFIX}/include")
33-
set(IPEX_INCLUDE_DIRS ${IPEX_INSTALL_PREFIX}/include)
34-
list(APPEND TORCH_INCLUDE_DIRS ${IPEX_INCLUDE_DIRS})
34+
list(APPEND IPEX_INCLUDE_DIRS ${IPEX_INSTALL_PREFIX}/include)
3535
endif()
3636

3737
# Library dependencies.
3838
if(@BUILD_WITH_CPU@)
3939
find_library(IPEX_CPU_CORE_LIBRARY intel-ext-pt-cpu PATHS "${IPEX_INSTALL_PREFIX}/lib")
40-
set(IPEX_LIBRARIES ${IPEX_CPU_CORE_LIBRARY})
41-
list(APPEND TORCH_LIBRARIES ${IPEX_CPU_CORE_LIBRARY})
40+
list(APPEND IPEX_LIBRARIES_PRINT ${IPEX_CPU_CORE_LIBRARY})
41+
list(APPEND IPEX_LIBRARIES intel-ext-pt-cpu)
4242
endif()
4343

4444
if(@BUILD_WITH_XPU@)
4545
find_library(IPEX_GPU_CORE_LIBRARY intel-ext-pt-gpu PATHS "${IPEX_INSTALL_PREFIX}/lib")
46-
list(APPEND IPEX_LIBRARIES ${IPEX_GPU_CORE_LIBRARY})
47-
list(APPEND TORCH_LIBRARIES ${IPEX_GPU_CORE_LIBRARY})
46+
list(APPEND IPEX_LIBRARIES_PRINT ${IPEX_GPU_CORE_LIBRARY})
47+
list(APPEND IPEX_LIBRARIES intel-ext-pt-gpu)
4848
endif()
4949

50-
find_package_handle_standard_args(IPEX DEFAULT_MSG IPEX_LIBRARIES IPEX_INCLUDE_DIRS)
51-
5250
# When we build ipex with the old GCC ABI, dependent libraries must too.
5351
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
54-
set(IPEX_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@")
52+
list(APPEND IPEX_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@")
5553
endif()
5654

5755
if(@BUILD_WITH_CPU@)
58-
add_library(intel-ext-pt-cpu SHARED IMPORTED)
56+
add_library(intel-ext-pt-cpu INTERFACE IMPORTED)
5957
set_target_properties(intel-ext-pt-cpu PROPERTIES
6058
IMPORTED_LOCATION "${IPEX_CPU_CORE_LIBRARY}"
6159
INTERFACE_INCLUDE_DIRECTORIES "${IPEX_INCLUDE_DIRS}"
60+
INTERFACE_LINK_LIBRARIES "-Wl,--no-as-needed,\"${IPEX_CPU_CORE_LIBRARY}\""
6261
CXX_STANDARD 14
6362
)
6463
if(IPEX_CXX_FLAGS)
@@ -68,14 +67,26 @@ if(@BUILD_WITH_CPU@)
6867
endif()
6968

7069
if(@BUILD_WITH_XPU@)
71-
add_library(intel-ext-pt-gpu SHARED IMPORTED)
70+
add_library(intel-ext-pt-gpu INTERFACE IMPORTED)
7271
set_target_properties(intel-ext-pt-gpu PROPERTIES
7372
IMPORTED_LOCATION "${IPEX_GPU_CORE_LIBRARY}"
7473
INTERFACE_INCLUDE_DIRECTORIES "${IPEX_INCLUDE_DIRS}"
74+
INTERFACE_LINK_LIBRARIES "-Wl,--no-as-needed,\"${IPEX_GPU_CORE_LIBRARY}\""
7575
CXX_STANDARD 17
7676
)
7777
if(IPEX_CXX_FLAGS)
7878
set_property(TARGET intel-ext-pt-gpu PROPERTY INTERFACE_COMPILE_OPTIONS "${IPEX_CXX_FLAGS}")
7979
endif()
8080
set(IPEX_WITH_XPU ON)
8181
endif()
82+
83+
# Import Torch to simplify usage
84+
FIND_PACKAGE(Torch REQUIRED)
85+
if(TORCH_LIBRARIES)
86+
list(APPEND TORCH_IPEX_LIBRARIES ${TORCH_LIBRARIES})
87+
if(IPEX_LIBRARIES)
88+
list(APPEND TORCH_IPEX_LIBRARIES ${IPEX_LIBRARIES})
89+
endif()
90+
endif()
91+
92+
find_package_handle_standard_args(IPEX DEFAULT_MSG IPEX_LIBRARIES_PRINT IPEX_INCLUDE_DIRS)

cmake/cppsdk/libintel-ext-pt.installer.sh.in

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ SCRIPT_PATH=$(dirname "$SCRIPT")
77

88
COMMAND=""
99
LIBTORCH_PATH=""
10+
LOGFILE="ipex-info"
1011

1112
# Below values will be set automatically. DO NOT modify them manually!
1213
# Append new required relative_path/components in LIBIPEX_COMP_LIST in cmake scripts
1314
LIBIPEX_VERSION="@CMAKE_PROJECT_VERSION@"
15+
LIBIPEX_GITREV="@LIBIPEX_GITREV@"
16+
LIBIPEX_BUILD_TYPE="@CMAKE_BUILD_TYPE@"
1417
LIBIPEX_PACK_NAME="@CPACK_PACKAGE_NAME@"
1518
LIBIPEX_COMPS_LIST="@LIBIPEX_COMP_LIST@"
1619

@@ -78,13 +81,18 @@ if [[ ${COMMAND} == "install" ]]; then
7881
ARCHIVE_NR=$(awk '/^__ARCHIVE_BELOW_ONLY__/ {print NR + 1; exit 0; }' $0)
7982
tail -n+${ARCHIVE_NR} $0 | tar xJfv - -C ${TMP_DIR} --strip-components=1
8083

84+
echo "Version: $LIBIPEX_VERSION" > ${LIBTORCH_PATH}/${LOGFILE}
85+
echo "Gitrev: $LIBIPEX_GITREV" >> ${LIBTORCH_PATH}/${LOGFILE}
86+
echo "Build: $LIBIPEX_BUILD_TYPE" >> ${LIBTORCH_PATH}/${LOGFILE}
87+
echo "" >> ${LIBTORCH_PATH}/${LOGFILE}
8188
for comp in ${LIBIPEX_COMPS_LIST}; do
8289
fn=$(basename ${comp})
8390
fp=$(dirname ${comp})
8491

8592
if [ ! -f ${TMP_DIR}/${comp} ]; then
8693
echo "Installation failed."
8794
echo "ERROR! Cannot find ${fn} in ${TMP_DIR}/${fp}. Uncompress failed!"
95+
rm ${LIBTORCH_PATH}/${LOGFILE} 2>/dev/null
8896
exit 17
8997
fi
9098

@@ -94,50 +102,46 @@ if [[ ${COMMAND} == "install" ]]; then
94102
echo "Installation failed."
95103
echo "ERROR! Failed to create folder ${LIBTORCH_PATH}/${fp}!"
96104
echo "Please check if you have privileges to write in ${LIBTORCH_PATH}."
105+
rm ${LIBTORCH_PATH}/${LOGFILE} 2>/dev/null
97106
exit 18
98107
fi
108+
echo "d|${fp}" >> ${LIBTORCH_PATH}/${LOGFILE}
99109
fi
100110

101111
cp ${TMP_DIR}/${comp} ${LIBTORCH_PATH}/${comp}
102112
if [ $? -gt 0 ]; then
103113
echo "Installation failed."
104114
echo "ERROR! Failed to install ${fn} into ${LIBTORCH_PATH}/${fp}!"
105115
echo "Please check if you have privileges to write in ${LIBTORCH_PATH}/${fp}."
116+
rm ${LIBTORCH_PATH}/${LOGFILE} 2>/dev/null
106117
exit 19
107118
fi
119+
echo "f|${comp}" >> ${LIBTORCH_PATH}/${LOGFILE}
108120
done
109121

110-
echo $LIBIPEX_VERSION > ${LIBTORCH_PATH}/build-version-ipex
111122
echo "Installation successed!"
112123

113124
# LIBIPEX Uninstallation
114125
elif [[ ${COMMAND} == "uninstall" ]]; then
115-
for comp in ${LIBIPEX_COMPS_LIST}; do
116-
if [ -f ${LIBTORCH_PATH}/${comp} ]; then
117-
rm -f ${LIBTORCH_PATH}/${comp}
126+
while read -r line; do
127+
FILE=$(echo ${line} | cut -d '|' -f 2)
128+
if [ -f ${LIBTORCH_PATH}/${FILE} ]; then
129+
rm -f ${LIBTORCH_PATH}/${FILE}
118130
fi
119-
done
120-
121-
if [ -f ${LIBTORCH_PATH}/lib/libintel-ext-pt-cpu.so ]; then
122-
rm -rf ${LIBTORCH_PATH}/lib/libintel-ext-pt-cpu.so
123-
fi
124-
if [ -f ${LIBTORCH_PATH}/lib/libintel-ext-pt-gpu.so ]; then
125-
rm -rf ${LIBTORCH_PATH}/lib/libintel-ext-pt-gpu.so
126-
fi
127-
128-
if [ -f ${LIBTORCH_PATH}/include/ipex.h ]; then
129-
rm -rf ${LIBTORCH_PATH}/include/ipex.h
130-
fi
131-
if [ -d ${LIBTORCH_PATH}/include/xpu ]; then
132-
rm -rf ${LIBTORCH_PATH}/include/xpu
133-
fi
134-
135-
if [ -d ${LIBTORCH_PATH}/share/cmake/IPEX ]; then
136-
rm -rf ${LIBTORCH_PATH}/share/cmake/IPEX
137-
fi
131+
done < <(grep "f|" ${LIBTORCH_PATH}/${LOGFILE})
132+
133+
while read -r line; do
134+
FOLDER=$(echo ${line} | cut -d '|' -f 2)
135+
COUNT=$(ls -1 ${LIBTORCH_PATH}/${FOLDER} | wc -l)
136+
if [ ${COUNT} -eq 0 ]; then
137+
rm -rf ${LIBTORCH_PATH}/${FOLDER}
138+
else
139+
echo "${LIBTORCH_PATH}/${FOLDER} is not empty, skip."
140+
fi
141+
done < <(grep "d|" ${LIBTORCH_PATH}/${LOGFILE})
138142

139-
if [ -f ${LIBTORCH_PATH}/build-version-ipex ]; then
140-
rm -f ${LIBTORCH_PATH}/build-version-ipex
143+
if [ -f ${LIBTORCH_PATH}/${LOGFILE} ]; then
144+
rm -f ${LIBTORCH_PATH}/${LOGFILE}
141145
fi
142146

143147
echo "Uninstallation successed!"

csrc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
set(IPEX_CSRC_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
2+
set(LIBIPEX_GITREV "${IPEX_GITREV}")
23

34
if(BUILD_MODULE_TYPE STREQUAL "GPU")
45
add_subdirectory(${IPEX_CSRC_ROOT_DIR}/gpu)

examples/cpu/inference/cpp/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ project(example-app)
44
find_package(IPEX REQUIRED)
55

66
add_executable(example-app example-app.cpp)
7-
target_link_libraries(example-app "${TORCH_LIBRARIES}")
7+
target_link_libraries(example-app "${TORCH_IPEX_LIBRARIES}")
88

99
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,8 @@ def run(self):
533533
'PYTHON_PLATFORM_INFO' : platform.platform(),
534534
'PYTHON_INCLUDE_DIR' : sysconfig.get_paths()['include'],
535535
'PYTHON_EXECUTABLE' : sys.executable,
536-
'IPEX_PROJ_NAME' : PACKAGE_NAME
536+
'IPEX_PROJ_NAME' : PACKAGE_NAME,
537+
'IPEX_GITREV' : ipex_git_sha,
537538
}
538539

539540
build_with_cpu = True # Default ON

0 commit comments

Comments
 (0)