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

Refine CMake CUDA version handling #5192

Merged
merged 8 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,17 @@ jobs:
include:
- test_suite: cuda
cuda_version: 10.2
extra_flags: --extra_oneflow_cmake_args=-DFOR_CI=ON --extra_oneflow_cmake_args=-DRPC_BACKEND=GRPC,LOCAL --extra_oneflow_cmake_args=-DPIP_INDEX_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
extra_flags: --extra_oneflow_cmake_args=-DCUDA_NVCC_GENCODES=arch=compute_61,code=sm_61 --extra_oneflow_cmake_args=-DRPC_BACKEND=GRPC,LOCAL --extra_oneflow_cmake_args=-DPIP_INDEX_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
os: [self-hosted, linux, build]
allow_fail: false
- test_suite: cpu
cuda_version: 10.2
extra_flags: --extra_oneflow_cmake_args=-DFOR_CI=ON --extra_oneflow_cmake_args=-DBUILD_SHARED_LIBS=ON --extra_oneflow_cmake_args=-DRPC_BACKEND=LOCAL --cpu --gcc7
extra_flags: --extra_oneflow_cmake_args=-DCUDA_NVCC_GENCODES=arch=compute_61,code=sm_61 --extra_oneflow_cmake_args=-DBUILD_SHARED_LIBS=ON --extra_oneflow_cmake_args=-DRPC_BACKEND=LOCAL --cpu --gcc7
os: [self-hosted, linux, build]
allow_fail: false
- test_suite: xla
cuda_version: 10.1
extra_flags: --extra_oneflow_cmake_args=-DFOR_CI=ON --extra_oneflow_cmake_args=-DRPC_BACKEND=GRPC,LOCAL --xla --extra_oneflow_cmake_args=-DPIP_INDEX_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
extra_flags: --extra_oneflow_cmake_args=-DCUDA_NVCC_GENCODES=arch=compute_61,code=sm_61 --extra_oneflow_cmake_args=-DRPC_BACKEND=GRPC,LOCAL --xla --extra_oneflow_cmake_args=-DPIP_INDEX_MIRROR=https://pypi.tuna.tsinghua.edu.cn/simple
os: [self-hosted, linux, build]
allow_fail: true
- test_suite: mac
Expand Down Expand Up @@ -196,6 +196,7 @@ jobs:
- name: Build OneFlow
if: env.is_built != '1' && matrix.test_suite != 'mac'
uses: ./.github/actions/whl
timeout-minutes: 45
with:
tmp_dir: ${ci_tmp_dir}
extra_flags: ${{ matrix.extra_flags }}
Expand Down
65 changes: 29 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ option(BUILD_CUDA "" ON)
option(BUILD_TESTING "" ON)
option(WITH_XLA "Option to build with XLA" OFF)
option(WITH_TENSORRT "Option to build with TensorRT" OFF)
option(FOR_CI "" OFF)
option(BUILD_GIT_VERSION "" ON)
option(BUILD_PROFILER "" OFF)
option(OF_SOFTMAX_USE_FAST_MATH "" ON)
Expand Down Expand Up @@ -130,44 +129,38 @@ endif()
include(third_party)

if (BUILD_CUDA)
message(STATUS "CUDA_VERSION: ${CUDA_VERSION}")
message(STATUS "CUDA_TOOLKIT_ROOT_DIR: ${CUDA_TOOLKIT_ROOT_DIR}")
set(CUDA_SEPARABLE_COMPILATION OFF)
list(APPEND CUDA_NVCC_FLAGS -w -Wno-deprecated-gpu-targets)
if((CMAKE_BUILD_TYPE MATCHES Debug) OR (FOR_CI))
if(CUDA_VERSION VERSION_GREATER_EQUAL "10.0")
set(DEFAULT_CUDA_NVCC_GENCODES "arch=compute_61,code=sm_61" "arch=compute_61,code=compute_61" "arch=compute_75,code=sm_75" "arch=compute_75,code=compute_75")
else()
set(DEFAULT_CUDA_NVCC_GENCODES "arch=compute_61,code=sm_61" "arch=compute_61,code=compute_61")
endif()
# half is not fully supported when __CUDA_ARCH__ < 530
# list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_30,code=sm_30")
# list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_52,code=sm_52")
# cubin
# Tesla P100
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_60,code=sm_60")
# Tesla P40/P4, Quadro Pxxx/Pxxxx, GeForce GTX 10xx, TITAN X/Xp
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_61,code=sm_61")
# V100, TITAN V
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_70,code=sm_70")
if(CUDA_VERSION VERSION_GREATER_EQUAL "10.0")
# T4, Quadro RTX xxxx, Txxxx, Geforce RTX 20xx, TITAN RTX
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_75,code=sm_75")
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0")
# A100
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_80,code=sm_80")
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.1")
# GeForce RTX 30xx
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_86,code=sm_86")
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0")
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_80,code=compute_80")
elseif(CUDA_VERSION VERSION_GREATER_EQUAL "10.0")
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_75,code=compute_75")
else()
# half is not fully supported when __CUDA_ARCH__ < 530
# list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_30,code=sm_30")
# list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_52,code=sm_52")
# cubin
# Tesla P100
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_60,code=sm_60")
# Tesla P40/P4, Quadro Pxxx/Pxxxx, GeForce GTX 10xx, TITAN X/Xp
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_61,code=sm_61")
# V100, TITAN V
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_70,code=sm_70")
if(CUDA_VERSION VERSION_GREATER_EQUAL "10.0")
# T4, Quadro RTX xxxx, Txxxx, Geforce RTX 20xx, TITAN RTX
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_75,code=sm_75")
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0")
# A100
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_80,code=sm_80")
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.1")
# GeForce RTX 30xx
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_86,code=sm_86")
endif()
if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0")
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_80,code=compute_80")
elseif(CUDA_VERSION VERSION_GREATER_EQUAL "10.0")
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_75,code=compute_75")
else()
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_70,code=compute_70")
endif()
list(APPEND DEFAULT_CUDA_NVCC_GENCODES "arch=compute_70,code=compute_70")
endif()
if(NOT DEFINED CUDA_NVCC_GENCODES)
set(CUDA_NVCC_GENCODES ${DEFAULT_CUDA_NVCC_GENCODES})
Copy link
Contributor

Choose a reason for hiding this comment

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

165-167 行可以改成

set(CUDA_NVCC_GENCODES "${DEFAULT_CUDA_NVCC_GENCODES}" CACHE STRING "")

Expand Down
2 changes: 1 addition & 1 deletion docker/ci/make/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COPY oneflow /workspace/oneflow
COPY tools /workspace/tools

RUN export LD_LIBRARY_PATH=/opt/intel/lib/intel64_lin:/opt/intel/mkl/lib/intel64:$LD_LIBRARY_PATH; \
cmake -DTHIRD_PARTY=OFF -DONEFLOW=ON -DFOR_CI=ON .. && make -j $(nproc) ;
cmake -DTHIRD_PARTY=OFF -DONEFLOW=ON .. && make -j $(nproc) ;

## BUILD WHEEL
WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion docker/ci/third_party/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ COPY CMakeLists.txt /workspace/CMakeLists.txt
# BUILD DEPENDENCY
COPY build/third_party /workspace/build/third_party
RUN export LD_LIBRARY_PATH=/opt/intel/lib/intel64_lin:/opt/intel/mkl/lib/intel64:$LD_LIBRARY_PATH; \
cmake -DTHIRD_PARTY=ON -DONEFLOW=OFF -DFOR_CI=ON -DCMAKE_BUILD_TYPE=Release -DRELEASE_VERSION=ON .. && make -j prepare_oneflow_third_party
cmake -DTHIRD_PARTY=ON -DONEFLOW=OFF -DCMAKE_BUILD_TYPE=Release -DRELEASE_VERSION=ON .. && make -j prepare_oneflow_third_party