Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cmake install to copy cpp api related files #7200

Merged
merged 71 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
89a81d3
install cpp api
mosout Jan 6, 2022
afd6b85
install mlir related files
mosout Jan 7, 2022
a5a134b
clean
mosout Jan 7, 2022
9e26e27
Merge remote-tracking branch 'upstream/master' into install_cpp_api
mosout Jan 7, 2022
d95533d
Merge remote-tracking branch 'upstream/master' into install_cpp_api
mosout Jan 10, 2022
75b16e1
handle third party dependences
mosout Jan 10, 2022
10f9aa3
support cpack
mosout Jan 10, 2022
d83d953
Merge remote-tracking branch 'upstream/master' into install_cpp_api
mosout Jan 11, 2022
2ff0bb7
fix
mosout Jan 12, 2022
c8aeb45
Merge remote-tracking branch 'upstream/master' into install_cpp_api
mosout Jan 12, 2022
f6c55f0
Update oneflow.cmake
jackalcooper Jan 12, 2022
4ba5efd
fix
mosout Jan 12, 2022
5a19411
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 12, 2022
a3554d5
fix compiling error
mosout Jan 12, 2022
785544d
refine
jackalcooper Jan 13, 2022
5b1d550
add exe test as deps
jackalcooper Jan 13, 2022
8c1c37f
install third party
mosout Jan 13, 2022
6b75ff9
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 13, 2022
00b140b
refine
jackalcooper Jan 13, 2022
d062e87
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 13, 2022
a6664a7
refine
mosout Jan 13, 2022
c667be6
revert install dir
mosout Jan 13, 2022
ac64e89
install third party
mosout Jan 13, 2022
a60d52c
refine
mosout Jan 13, 2022
511eb57
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow into …
jackalcooper Jan 14, 2022
235d3d1
refine rpath
jackalcooper Jan 14, 2022
7617880
set cpack dir
mosout Jan 15, 2022
2bb4313
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 15, 2022
0da5f84
Merge remote-tracking branch 'upstream/master' into install_cpp_api
mosout Jan 15, 2022
5c89675
set version for cpack on ci
mosout Jan 15, 2022
7aa23ed
update ci exe test
mosout Jan 15, 2022
49782b2
fix
mosout Jan 15, 2022
0e997c7
Merge branch 'master' into install_cpp_api
mosout Jan 15, 2022
6a8c41d
refine
mosout Jan 15, 2022
68df3cc
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 15, 2022
7cb596e
fix
mosout Jan 15, 2022
3eb7d69
Merge branch 'master' into install_cpp_api
mosout Jan 15, 2022
e336f99
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 15, 2022
17848e4
fix xla download
mosout Jan 16, 2022
785ddc5
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 16, 2022
56e1f44
refine
mosout Jan 16, 2022
71aed89
addcheck
jackalcooper Jan 16, 2022
396c852
refine
jackalcooper Jan 16, 2022
30187d7
fix xla
mosout Jan 16, 2022
b324b99
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 16, 2022
64b926e
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 16, 2022
a268079
fix unzip
mosout Jan 17, 2022
b9b9498
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 17, 2022
10580c5
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 17, 2022
249b580
fix cpp api test
mosout Jan 17, 2022
2b4b334
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 17, 2022
6105295
Merge remote-tracking branch 'upstream/master' into install_cpp_api
mosout Jan 17, 2022
1e1853c
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 17, 2022
8261edf
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 17, 2022
a39b81f
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 17, 2022
5983ad7
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 17, 2022
c69861e
comment out a deconv2d test
mosout Jan 18, 2022
42783cb
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 18, 2022
05564d8
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 18, 2022
1223228
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 18, 2022
6637f64
Merge branch 'master' into install_cpp_api
jackalcooper Jan 19, 2022
a15c72b
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 19, 2022
40407cb
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 19, 2022
9f1adf5
fix
mosout Jan 19, 2022
f2bad89
Merge remote-tracking branch 'origin/install_cpp_api' into install_cp…
mosout Jan 19, 2022
3a4a522
fix glog link
mosout Jan 19, 2022
fbc16a6
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 19, 2022
a35cc81
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 19, 2022
9c674df
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 19, 2022
9139f30
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 19, 2022
5b4e6a6
Merge branch 'master' into install_cpp_api
oneflow-ci-bot Jan 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ jobs:
if: ${{ matrix.entry =='cu101_xla' && !matrix.cache-hit }}
with:
cmake-init-cache: ${{ env.ONEFLOW_SRC }}/cmake/caches/ci/cuda-xla.cmake
build-script: ${{ env.ONEFLOW_SRC }}/ci/manylinux/build-gcc7.sh
build-script: ${{ env.ONEFLOW_SRC }}/ci/manylinux/build-gcc7-xla.sh
oneflow-src: ${{ env.ONEFLOW_SRC }}
oneflow-build-env: manylinux
wheelhouse-dir: ${{ env.WHEELHOUSE_DIR }}
Expand All @@ -275,18 +275,7 @@ jobs:
clean-ccache: ${{ contains(github.event.pull_request.labels.*.name, 'need-clean-ccache') }}
python-versions: |
3.6
- name: Upload bin
if: ${{ !fromJson(matrix.cache-hit) && contains(matrix.runs-on, 'self-hosted') && (steps.build-cpu.outcome == 'success' || steps.build-cuda.outcome == 'success' || steps.build-xla.outcome == 'success') }}
uses: Oneflow-Inc/get-oneflow/digest/upload@remove-single-client
timeout-minutes: 10
with:
digest: ${{ steps.save-cache.outputs.build-digest }}
entry: ${{ matrix.entry }}
ssh-tank-host: ${{ env.SSH_TANK_HOST }}
ssh-tank-path: ${{ env.SSH_TANK_PATH }}
src-dir: ${{ env.MANYLINUX_CACHE_DIR }}/build/bin
dst-dir: bin
- name: Upload liboneflow_cpp library
- name: Upload packed liboneflow
if: ${{ !fromJson(matrix.cache-hit) && contains(matrix.runs-on, 'self-hosted') && (steps.build-cpu.outcome == 'success' || steps.build-cuda.outcome == 'success') }}
uses: Oneflow-Inc/get-oneflow/digest/upload@remove-single-client
timeout-minutes: 10
Expand All @@ -295,8 +284,8 @@ jobs:
entry: ${{ matrix.entry }}
ssh-tank-host: ${{ env.SSH_TANK_HOST }}
ssh-tank-path: ${{ env.SSH_TANK_PATH }}
src-dir: ${{ env.MANYLINUX_CACHE_DIR }}/build/liboneflow_cpp/lib
dst-dir: liboneflow_cpp/lib
src-dir: ${{ env.MANYLINUX_CACHE_DIR }}/build/cpack
dst-dir: cpack
- name: Upload whl
if: ${{ !fromJson(matrix.cache-hit) && contains(matrix.runs-on, 'self-hosted') && (steps.build-cpu.outcome == 'success' || steps.build-cuda.outcome == 'success' || steps.build-xla.outcome == 'success') }}
uses: Oneflow-Inc/get-oneflow/digest/upload@remove-single-client
Expand Down Expand Up @@ -426,7 +415,7 @@ jobs:
run: |
echo "::error file=test.yml,line=204,col=10::steps.save-cache.outputs.cache-hit != matrix.cache-hit"
exit 1
- name: Download wheel, binary and liboneflow_cpp lib
- name: Download wheel and packed liboneflow
if: ${{ !fromJson(matrix.cache-hit) && contains(matrix.runs-on, 'self-hosted') }}
uses: Oneflow-Inc/get-oneflow/digest/download@remove-single-client
id: download-digest
Expand Down Expand Up @@ -479,20 +468,17 @@ jobs:
if: ${{ !fromJson(matrix.cache-hit) && contains(matrix.runs-on, 'self-hosted') }}
working-directory: ${{ env.ONEFLOW_SRC }}
env:
ONEFLOW_BIN_PATH: ${{ steps.download-digest.outputs.entry-dir }}/bin
ONEFLOW_CPP_API_LIB_PATH: ${{ steps.download-digest.outputs.entry-dir }}/liboneflow_cpp/lib
ONEFLOW_CPACK_PATH: ${{ steps.download-digest.outputs.entry-dir }}/cpack
run: |
docker run -d --rm --privileged --shm-size=8g \
--cap-add=SYS_PTRACE --security-opt seccomp=unconfined \
--runtime=nvidia \
-v /dataset:/dataset:ro -v /model_zoo:/model_zoo:ro \
-v ${ONEFLOW_WHEEL_PATH}:${ONEFLOW_WHEEL_PATH}:ro \
-v ${ONEFLOW_BIN_PATH}:${ONEFLOW_BIN_PATH}:ro \
-v ${ONEFLOW_CPP_API_LIB_PATH}:${ONEFLOW_CPP_API_LIB_PATH}:ro \
-v ${ONEFLOW_CPACK_PATH}:${ONEFLOW_CPACK_PATH}:ro \
-v $HOME/test-container-cache/dot-local:/root/.local \
-v $HOME/test-container-cache/dot-cache:/root/.cache \
-e ONEFLOW_WHEEL_PATH=${ONEFLOW_WHEEL_PATH} \
-e ONEFLOW_BIN_PATH=${ONEFLOW_BIN_PATH} \
-e ONEFLOW_CI=1 \
-v $PWD:$PWD \
-w $PWD \
Expand All @@ -516,14 +502,18 @@ jobs:
if: ${{ !fromJson(matrix.cache-hit) && contains(matrix.runs-on, 'self-hosted') }}
run: |
docker exec ${{ env.TEST_CONTAINER_NAME }} python3 -m oneflow --doctor
- name: Unzip packed liboneflow
if: ${{ !fromJson(matrix.cache-hit) && contains(matrix.runs-on, 'self-hosted') && !fromJson(matrix.is-xla) }}
run: |
unzip ${{ steps.download-digest.outputs.entry-dir }}/cpack/liboneflow-ci-linux.zip -d ${{ steps.download-digest.outputs.entry-dir }}/cpack/
- name: Exe test
if: ${{ !fromJson(matrix.cache-hit) && matrix.test-type == 'misc' && matrix.device == 'cpu' }}
timeout-minutes: 10
run: |
chmod +x ${{ steps.download-digest.outputs.entry-dir }}/bin/oneflow_testexe
docker exec ${{ env.TEST_CONTAINER_NAME }} ${{ steps.download-digest.outputs.entry-dir }}/bin/oneflow_testexe
chmod +x ${{ steps.download-digest.outputs.entry-dir }}/bin/oneflow_cpp_api_testexe
docker exec -e LD_LIBRARY_PATH=${{ steps.download-digest.outputs.entry-dir }}/liboneflow_cpp/lib ${{ env.TEST_CONTAINER_NAME }} ${{ steps.download-digest.outputs.entry-dir }}/bin/oneflow_cpp_api_testexe
chmod +x ${{ steps.download-digest.outputs.entry-dir }}/cpack/liboneflow-ci-linux/bin/oneflow_testexe
docker exec ${{ env.TEST_CONTAINER_NAME }} ${{ steps.download-digest.outputs.entry-dir }}/cpack/liboneflow-ci-linux/bin/oneflow_testexe
chmod +x ${{ steps.download-digest.outputs.entry-dir }}/cpack/liboneflow-ci-linux/bin/oneflow_cpp_api_testexe
docker exec ${{ env.TEST_CONTAINER_NAME }} ${{ steps.download-digest.outputs.entry-dir }}/cpack/liboneflow-ci-linux/bin/oneflow_cpp_api_testexe
- name: Build documentation
timeout-minutes: 10
if: ${{ !fromJson(matrix.cache-hit) && matrix.test-type == 'misc' && matrix.device == 'cpu' }}
Expand Down
42 changes: 17 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,37 @@ option(USE_CLANG_FORMAT "" OFF)
option(USE_CLANG_TIDY "" OFF)
option(BUILD_PYTHON "" ON)
option(BUILD_CPP_API "Option to build OneFlow C++ API (beta)" OFF)
option(BUILD_MONOLITHIC_LIBONEFLOW_CPP_SO "Option to build a monolithic liboneflow_cpp.so (only meaningful when BUILD_CPP_API is ON)" ON)
option(BUILD_RDMA "" OFF)
option(BUILD_CUDA "" ON)
option(WITH_ONEDNN "" OFF)
option(BUILD_TESTING "" OFF)
option(BUILD_GIT_VERSION "" ON)
option(BUILD_PROFILER "" OFF)
option(BUILD_FOR_CI "" OFF)
option(WITH_XLA "Option to build with XLA" OFF)
option(WITH_TENSORRT "Option to build with TensorRT" OFF)
option(WITH_OPENVINO "Option to build with OpenVINO" OFF)
option(WITH_MLIR "" OFF)
option(WITH_MLIR_CUDA_CODEGEN "" OFF)
set(LLVM_PROVIDER "in-tree" CACHE STRING "in-tree, install")
if (NOT WITH_MLIR)
set(LLVM_PROVIDER "install" CACHE STRING "in-tree will build LLVM's ALL, not what we want when not building MLIR" FORCE)
endif(NOT WITH_MLIR)
option(WITH_COCOAPI "Option to build with COCO API" ON)
option(WITH_ZLIB "" ON)
option(BUILD_GIT_VERSION "" ON)
option(BUILD_PROFILER "" OFF)
option(WITH_ONEDNN "" OFF)
option(WITH_MLIR "" OFF)
option(WITH_MLIR_CUDA_CODEGEN "" OFF)
option(OF_SOFTMAX_USE_FAST_MATH "" ON)
option(OF_LAYER_NORM_USE_FAST_MATH "" ON)
option(TREAT_WARNINGS_AS_ERRORS "" ON)
# Reference:
# https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949
option(OF_FORCE_COLORED_DIAGNOSTICS "Always produce ANSI-colored diagnostics (GNU/Clang only)." ON)

set(ONEFLOW_CURRENT_VERSION 0.7.0 CACHE STRING "")
if(BUILD_FOR_CI)
set(ONEFLOW_CURRENT_VERSION ci)
endif()

set(LLVM_PROVIDER "in-tree" CACHE STRING "in-tree, install")
if (NOT WITH_MLIR)
set(LLVM_PROVIDER "install" CACHE STRING "in-tree will build LLVM's ALL, not what we want when not building MLIR" FORCE)
endif(NOT WITH_MLIR)

set(RPC_BACKEND "GRPC,LOCAL" CACHE STRING "")
set(THIRD_PARTY_MIRROR "" CACHE STRING "")
set(PIP_INDEX_MIRROR "" CACHE STRING "")
Expand Down Expand Up @@ -210,21 +217,6 @@ if(BUILD_PYTHON)
set(ONEFLOW_INCLUDE_DIR "${ONEFLOW_PYTHON_DIR}/oneflow/include")
endif(BUILD_PYTHON)

if(BUILD_CPP_API)
set(LIBONEFLOW_LIBRARY_DIR "${PROJECT_BINARY_DIR}/liboneflow_cpp/lib")
set(LIBONEFLOW_SHARE_DIR "${PROJECT_BINARY_DIR}/liboneflow_cpp/share")
make_directory(${LIBONEFLOW_LIBRARY_DIR})
make_directory(${LIBONEFLOW_SHARE_DIR})

if(BUILD_SHARED_LIBS)
if(BUILD_MONOLITHIC_LIBONEFLOW_CPP_SO)
message(FATAL_ERROR "BUILD_MONOLITHIC_LIBONEFLOW_CPP_SO is incompatible with BUILD_SHARED_LIBS. Please set either of them to OFF.")
else()
set(LIBRARY_OUTPUT_PATH ${LIBONEFLOW_LIBRARY_DIR})
endif(BUILD_MONOLITHIC_LIBONEFLOW_CPP_SO)
endif(BUILD_SHARED_LIBS)
endif(BUILD_CPP_API)

include(third_party)

if (BUILD_CUDA)
Expand Down
32 changes: 32 additions & 0 deletions ci/manylinux/build-gcc7-xla.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
source scl_source enable devtoolset-7
set -ex
export PATH=/usr/lib64/ccache:$PATH
gcc --version
ld --version
# clean python dir
cd ${ONEFLOW_CI_SRC_DIR}
${ONEFLOW_CI_PYTHON_EXE} -m pip install -i https://mirrors.aliyun.com/pypi/simple --user -r ci/fixed-dev-requirements.txt
cd python
git clean -nXd -e \!dist -e \!dist/**
git clean -fXd -e \!dist -e \!dist/**
# cmake config
mkdir -p ${ONEFLOW_CI_BUILD_DIR}
cd ${ONEFLOW_CI_BUILD_DIR}
find ${ONEFLOW_CI_BUILD_DIR} -name CMakeCache.txt
find ${ONEFLOW_CI_BUILD_DIR} -name CMakeCache.txt -delete
if [ ! -f "$ONEFLOW_CI_CMAKE_INIT_CACHE" ]; then
echo "$ONEFLOW_CI_CMAKE_INIT_CACHE does not exist."
exit 1
fi
export PATH="${PATH}:$(dirname ${ONEFLOW_CI_PYTHON_EXE})"
export PYTHON_BIN_PATH=${ONEFLOW_CI_PYTHON_EXE}
cmake -S ${ONEFLOW_CI_SRC_DIR} -C ${ONEFLOW_CI_CMAKE_INIT_CACHE} -DPython3_EXECUTABLE=${ONEFLOW_CI_PYTHON_EXE}

# cmake build
cd ${ONEFLOW_CI_BUILD_DIR}
cmake --build . -j $(nproc)

# build pip
cd ${ONEFLOW_CI_SRC_DIR}
cd python
${ONEFLOW_CI_PYTHON_EXE} setup.py bdist_wheel
2 changes: 2 additions & 0 deletions ci/manylinux/build-gcc7.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ cmake -S ${ONEFLOW_CI_SRC_DIR} -C ${ONEFLOW_CI_CMAKE_INIT_CACHE} -DPython3_EXECU
# cmake build
cd ${ONEFLOW_CI_BUILD_DIR}
cmake --build . -j $(nproc)
cpack
rm -rf ./cpack/_CPack_Packages

# build pip
cd ${ONEFLOW_CI_SRC_DIR}
Expand Down
2 changes: 2 additions & 0 deletions ci/manylinux/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ cmake -S ${ONEFLOW_CI_SRC_DIR} -C ${ONEFLOW_CI_CMAKE_INIT_CACHE} -DPython3_EXECU
# cmake build
cd ${ONEFLOW_CI_BUILD_DIR}
cmake --build . -j $(nproc)
cpack
rm -rf ./cpack/_CPack_Packages

# build pip
cd ${ONEFLOW_CI_SRC_DIR}
Expand Down
1 change: 1 addition & 0 deletions cmake/caches/ci/cpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ set(CMAKE_GENERATOR Ninja CACHE STRING "")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF CACHE BOOL "")
set(BUILD_CPP_API ON CACHE BOOL "")
set(WITH_MLIR ON CACHE BOOL "")
set(BUILD_FOR_CI ON CACHE BOOL "")
1 change: 1 addition & 0 deletions cmake/caches/ci/cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ set(CUDNN_STATIC ON CACHE BOOL "")
set(WITH_MLIR ON CACHE BOOL "")
set(BUILD_CPP_API ON CACHE BOOL "")
set(CUDA_NVCC_THREADS_NUMBER 8 CACHE STRING "")
set(BUILD_FOR_CI ON CACHE BOOL "")
119 changes: 91 additions & 28 deletions cmake/oneflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,7 @@ if (BUILD_CPP_API)
file(GLOB_RECURSE of_cpp_api_files
${PROJECT_SOURCE_DIR}/oneflow/api/cpp/*.cpp
${PROJECT_SOURCE_DIR}/oneflow/api/cpp/*.h)
if(BUILD_MONOLITHIC_LIBONEFLOW_CPP_SO)
oneflow_add_library(oneflow_cpp SHARED ${of_cpp_api_files})
else()
oneflow_add_library(oneflow_cpp ${of_cpp_api_files})
endif()
oneflow_add_library(oneflow_cpp SHARED ${of_cpp_api_files})
set_target_properties(oneflow_cpp PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${LIBONEFLOW_LIBRARY_DIR}" LIBRARY_OUTPUT_DIRECTORY "${LIBONEFLOW_LIBRARY_DIR}")
target_link_libraries(oneflow_cpp PRIVATE ${of_libs} of_api_common ${oneflow_third_party_libs})
endif()
Expand Down Expand Up @@ -392,7 +388,8 @@ if(BUILD_TESTING)
if (BUILD_CPP_API)
file(GLOB_RECURSE cpp_api_test_files ${PROJECT_SOURCE_DIR}/oneflow/api/cpp/tests/*.cpp)
oneflow_add_test(oneflow_cpp_api_testexe SRCS ${cpp_api_test_files} TEST_NAME oneflow_cpp_api_test WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
target_link_libraries(oneflow_cpp_api_testexe oneflow_cpp ${oneflow_test_libs})
find_package(Threads REQUIRED)
target_link_libraries(oneflow_cpp_api_testexe oneflow_cpp ${oneflow_test_libs} Threads::Threads)
endif()
endif()

Expand Down Expand Up @@ -463,28 +460,94 @@ if(BUILD_PYTHON)

endif(BUILD_PYTHON)

if(BUILD_CPP_API)

set(LIBONEFLOW_INCLUDE_DIR "${PROJECT_BINARY_DIR}/liboneflow_cpp/include/oneflow/api")
install(DIRECTORY oneflow/api/cpp DESTINATION ${LIBONEFLOW_INCLUDE_DIR}
COMPONENT oneflow_cpp_include
EXCLUDE_FROM_ALL
FILES_MATCHING
PATTERN "*.h"
)

add_custom_target(install_oneflow_cpp_include
COMMAND
"${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=oneflow_cpp_include
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
DEPENDS oneflow_internal
)
if (BUILD_CPP_API)
add_dependencies(of_include_copy oneflow_cpp)
add_dependencies(of_include_copy install_oneflow_cpp_include)
copy_files("${PROJECT_SOURCE_DIR}/cmake/oneflow-config.cmake" "${PROJECT_SOURCE_DIR}/cmake" "${LIBONEFLOW_SHARE_DIR}" of_include_copy)
set(LIBONEFLOW_DIR ${PROJECT_BINARY_DIR}/liboneflow_cpp)

if(WITH_MLIR)
file(GLOB mlir_shared_libs "${PROJECT_BINARY_DIR}/oneflow/ir/llvm_monorepo-build/lib/*.14git")
copy_files("${mlir_shared_libs}" "${PROJECT_BINARY_DIR}/oneflow/ir/llvm_monorepo-build/lib" "${LIBONEFLOW_LIBRARY_DIR}" of_include_copy)
endif(WITH_MLIR)
install(DIRECTORY oneflow/api/cpp/
COMPONENT oneflow_cpp_all
DESTINATION include/oneflow
FILES_MATCHING
PATTERN "*.h"
PATTERN "tests" EXCLUDE
)
set(LIBONEFLOW_THIRD_PARTY_DIRS)
checkDirAndAppendSlash(DIR ${GLOG_LIBRARY_DIR} OUTPUT GLOG_LIBRARY_DIR_APPENDED)
checkDirAndAppendSlash(DIR ${PROTOBUF_LIBRARY_DIR} OUTPUT PROTOBUF_LIBRARY_DIR_APPENDED)
list(APPEND LIBONEFLOW_THIRD_PARTY_DIRS ${GLOG_LIBRARY_DIR_APPENDED} ${GLOG_LIBRARY_DIR_APPENDED})
if(BUILD_CUDA)
checkDirAndAppendSlash(DIR ${NCCL_LIBRARY_DIR} OUTPUT NCCL_LIBRARY_DIR_APPENDED)
list(APPEND LIBONEFLOW_THIRD_PARTY_DIRS ${NCCL_LIBRARY_DIR_APPENDED})
endif()
Copy link
Collaborator

@jackalcooper jackalcooper Jan 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要这样写呢,这样不保险。还是提取个函数来check吧,除了 BUILD_CUDA 还有 xla 等情况

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我来改一下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看了下编译xla的时候也会编译nccl 这样写应该没问题吧 之前xla的编译也是过了的

Copy link
Collaborator

@jackalcooper jackalcooper Jan 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看了下编译xla的时候也会编译nccl 这样写应该没问题吧 之前xla的编译也是过了的

我也不知道为什么,现在其他的xla编译全挂了,怀疑和这里有关。不能因为能编译就可以认为没问题了,主要是考虑以后其他人加新的库并不知道这里为什么要多一个if(BUILD_CUDA),所以多一个用来check的函数比较好


install(DIRECTORY ${LIBONEFLOW_THIRD_PARTY_DIRS}
COMPONENT oneflow_cpp_all
DESTINATION lib
FILES_MATCHING
PATTERN "*.so*"
PATTERN "*.a" EXCLUDE
PATTERN "libprotobuf-lite.so*" EXCLUDE
PATTERN "libprotoc.so*" EXCLUDE
PATTERN "cmake" EXCLUDE
PATTERN "pkgconfig" EXCLUDE
)

install(FILES ${PROJECT_SOURCE_DIR}/cmake/oneflow-config.cmake
COMPONENT oneflow_cpp_all
DESTINATION share
)

get_property(MLIR_RELATED_TARGETS GLOBAL PROPERTY MLIR_EXPORTS)
get_property(LLVM_RELATED_TARGETS GLOBAL PROPERTY LLVM_EXPORTS)

list(REMOVE_ITEM LLVM_RELATED_TARGETS
count
not
FileCheck
lli-child-target
llvm-jitlink-executor
llvm-PerfectShuffle
llvm-tblgen
mlir-tblgen
obj2yaml
oneflow_tblgen
yaml-bench
yaml2obj
)

set(LIBONEFLOW_TARGETS)
list(APPEND LIBONEFLOW_TARGETS oneflow_cpp oneflow of_cfgobj of_protoobj ${MLIR_RELATED_TARGETS} ${LLVM_RELATED_TARGETS})

if(BUILD_TESTING)
list(APPEND LIBONEFLOW_TARGETS oneflow_cpp_api_testexe)
list(APPEND LIBONEFLOW_TARGETS oneflow_testexe)
endif(BUILD_TESTING)

install(TARGETS ${LIBONEFLOW_TARGETS}
COMPONENT oneflow_cpp_all
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)

add_custom_target(install_oneflow_cpp
COMMAND
"${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=oneflow_cpp_all
-DCMAKE_INSTALL_PREFIX="${LIBONEFLOW_DIR}"
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
DEPENDS oneflow_cpp
)
if(BUILD_TESTING)
add_dependencies(install_oneflow_cpp oneflow_cpp_api_testexe oneflow_testexe)
endif(BUILD_TESTING)
add_dependencies(of_include_copy install_oneflow_cpp)

string(TOLOWER ${CMAKE_SYSTEM_NAME} CPACK_SYSTEM_NAME)
set(CPACK_GENERATOR ZIP)
set(CPACK_PACKAGE_DIRECTORY ${PROJECT_BINARY_DIR}/cpack)
set(CPACK_PACKAGE_NAME liboneflow)
# TODO: by Shenghang, unify python and c++ version genenerating and getting
set(CPACK_PACKAGE_VERSION ${ONEFLOW_CURRENT_VERSION})
set(CPACK_INSTALL_CMAKE_PROJECTS ${PROJECT_BINARY_DIR};oneflow;oneflow_cpp_all;/)
include(CPack)
endif(BUILD_CPP_API)
Loading