Skip to content

Commit ae158db

Browse files
author
root
committed
[ENHANCE] Update Project Structure and CMake
1 parent f6b9e8b commit ae158db

File tree

17 files changed

+94
-86
lines changed

17 files changed

+94
-86
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ __pycache__/
1010
.Python
1111
build/
1212
develop-eggs/
13-
dist/
1413
downloads/
1514
eggs/
1615
.eggs/
17-
/lib/
18-
lib64/
19-
parts/
2016
sdist/
2117
var/
2218
wheels/
@@ -162,6 +158,6 @@ cython_debug/
162158
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163159
.idea/
164160

165-
/src/pmpp/_torch_ops
161+
/pmpp/_torch_ops
166162
vcpkg_installed
167163
/tmp

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ To build the C++ part only:
6565
bash scripts/build.sh
6666
```
6767

68+
> 📝**NOTE**
69+
> See "[cmake-parameters.md](csrc/cmake/cmake-parameters.md)" for details about setting up the build process.
70+
6871
You will find "./build/lib/libPmppTorchOps.so" which is the operator library and "./build/test/pmpp_test" which is the test executable (with gtest).
6972

7073
Execute the test executable to test the library manually:
@@ -77,11 +80,12 @@ Note that the test is already integrated into CMake build system (with ctest); I
7780

7881
```bash
7982
# $BUILD_DIR is "./build" by default
83+
# Set `GTEST_COLOR` to yes or no to enable or disable colored output
8084

8185
# If the library has not been build, target `all` before `check` is required
82-
GTEST_COLOR=yes cmake --build $BUILD_DIR -j $(nproc) --target all check
86+
cmake --build $BUILD_DIR -j $(nproc) --target all check
8387
# Or if the library has been build, `check` is enough
84-
GTEST_COLOR=yes cmake --build $BUILD_DIR -j $(nproc) --target check
88+
cmake --build $BUILD_DIR -j $(nproc) --target check
8589
```
8690

8791
To build and install the python package `pmpp` in current activated conda environment (pmpp operator library would be built automatically if it has not been built yet):

csrc/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ cmake_minimum_required(VERSION 3.30)
55
project(PMPP VERSION 1.0.0)
66

77
# Common utility functions
8-
include(${PROJECT_SOURCE_DIR}/cmake/utils/logging.cmake)
98
include(${PROJECT_SOURCE_DIR}/cmake/utils/common.cmake)
109

1110
log_info("CMake Tookchain File Path: ${CMAKE_TOOLCHAIN_FILE}")
1211

1312
set_default_values(
1413
PROJECT_NAMESPACE "pmpp::"
15-
FORCE_COLORED_OUTPUT ON
14+
STDOUT_IS_TERMINAL OFF
1615
)
1716

1817
# Utility functions for installing libraries:
@@ -35,13 +34,6 @@ find_package(yaml-cpp CONFIG REQUIRED)
3534
enable_testing()
3635
find_package(GTest CONFIG REQUIRED)
3736

38-
if (${FORCE_COLORED_OUTPUT})
39-
add_compile_options(
40-
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
41-
$<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>
42-
)
43-
endif ()
44-
4537
add_subdirectory(${PROJECT_SOURCE_DIR}/lib)
4638
add_subdirectory(${PROJECT_SOURCE_DIR}/test)
4739

csrc/cmake/cmake-parameters.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
## Required Parameters
44

5-
- `[ENV]{CUDA_HOME}`/`[ENV]{CUDA_DIR}`: CUDA toolkit installation path.
5+
- `CUDA_HOME`/`CUDA_DIR`/`ENV{CUDA_HOME}`/`ENV{CUDA_DIR}`: CUDA toolkit installation path.
66
See: [cmake/libraries/cuda.cmake](../cmake/libraries/libcuda.cmake).
77

88
## Optional Parameters
99

1010
- `CMAKE_CUDA_STANDARD`: CUDA standard.
1111
See: [cmake/compilers/cuda-compiler-configs.cmake](../cmake/compilers/cuda-compiler-configs.cmake).
1212
Default: *Auto-Detect*.
13-
Possible values: `14`, `17`, `20`, `23`.
13+
Possible values: `20`, `23`.
1414
- `CMAKE_CXX_SCAN_FOR_MODULES`: Whether to use C++ modules.
1515
See: [cmake/compilers/cxx-compiler-configs.cmake](../cmake/compilers/cxx-compiler-configs.cmake).
1616
Default: `OFF`.
1717
Possible values: `ON`, `OFF`.
1818
- `CMAKE_CXX_STANDARD`: C++ standard.
1919
See: [cmake/compilers/cxx-compiler-configs.cmake](../cmake/compilers/cxx-compiler-configs.cmake).
2020
Default: *Auto-Detect*.
21-
Possible values: `14`, `17`, `20`, `23`.
21+
Possible values: `20`, `23`.
2222
- `CMAKE_EXECUTABLE_SUFFIX`: Executable suffix.
2323
See: [CMakelists.txt](../CMakeLists.txt).
2424
Default: `.exe`.
@@ -38,4 +38,8 @@
3838
Default: `pmpp`;
3939
- `STACK_SIZE`: Stack size for the executable targets (if any).
4040
See: [cmake/compilers/cxx-compiler-configs.cmake](../cmake/compilers/cxx-compiler-configs.cmake).
41-
Default: `1048576` (Bytes).
41+
Default: `1048576` (Bytes).
42+
- `STDOUT_IS_TERMINAL`: Whether the standard output is a terminal.
43+
See: [CMakelists.txt](../CMakeLists.txt).
44+
Default: `OFF`.
45+
Possible values: `ON`, `OFF`.

csrc/cmake/compilers/cuda-compiler-configs.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# @file compiler-configs-cuda.cmake
33
# @brief Compiler configurations for cuda.
44
#
5-
# @note Several parameters SHOULD be set BEFORE including this file:
5+
# @note Values SHOULD be set BEFORE including this file:
66
# - `ENV{NVCC_CCBIN}`: CUDA Compiler bindir. Default: auto-detected.
77
# - `CMAKE_CUDA_STANDARD`: CUDA Standard. Default: 20.
88
# ==================================================================================================

csrc/cmake/compilers/cxx-compiler-configs.cmake

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# @file compiler-configs-cpp.cmake
33
# @brief Compiler configurations for the host.
44
#
5-
# @note Several parameters SHOULD be set BEFORE including this file:
5+
# @note Values MUST be set BEFORE including this file:
6+
# - `STDOUT_IS_TERMINAL`: Whether stdout is a terminal.
7+
# Values SHOULD be set BEFORE including this file:
68
# - `ENV{CXX}`: C++ Compiler. Default: auto-detected.
79
# - `CMAKE_CXX_STANDARD`: C++ Standard. Default: 20.
810
# - `CMAKE_CXX_SCAN_FOR_MODULES`: Whether to use modules. Default: OFF.
@@ -12,18 +14,18 @@
1214
include(${PROJECT_SOURCE_DIR}/cmake/utils/common.cmake)
1315

1416
enable_language(CXX)
15-
set_default_values(CMAKE_CXX_SCAN_FOR_MODULES OFF)
1617

17-
# Generate compile_commands.json in build directory
18-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
18+
set_default_values(
19+
CMAKE_EXPORT_COMPILE_COMMANDS ON
20+
CMAKE_CXX_STANDARD 20
21+
CMAKE_CXX_STANDARD_REQUIRED ON
22+
CMAKE_CXX_SCAN_FOR_MODULES OFF
23+
STACK_SIZE 1048576
24+
)
1925

20-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2126
log_info("CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
22-
23-
# Set stack size
24-
if(NOT DEFINED STACK_SIZE)
25-
set(STACK_SIZE 1048576) # 1MB by default
26-
endif()
27+
log_info("CMAKE_CXX_SCAN_FOR_MODULES: ${CMAKE_CXX_SCAN_FOR_MODULES}")
28+
log_info("STACK_SIZE: ${STACK_SIZE}")
2729

2830
# Compiler flags for MSVC
2931
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
@@ -54,8 +56,16 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
5456
else()
5557
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-zstack-size=${STACK_SIZE}")
5658
endif()
57-
# @todo @jamesnulliu
58-
# |- Add compiler flags for other compilers
59+
# [TODO] @jamesnulliu
60+
# Support more compilers
5961
else()
6062
log_fatal("Unsupported compiler")
63+
endif()
64+
65+
if(STDOUT_IS_TERMINAL)
66+
add_compile_options(
67+
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
68+
$<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>
69+
$<$<CXX_COMPILER_ID:MSVC>:/FC>
70+
)
6171
endif()

csrc/cmake/libraries/libcuda.cmake

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# @brief Enable CUDA support.
33
# @see "https://cliutils.gitlab.io/modern-cmake/chapters/packages/CUDA.html"
44
#
5-
# @note Several parameters should be set before including this file:
6-
# - [ENV]{CUDA_HOME}/[ENV]{CUDA_DIR}:
5+
# @note Values should be set before including this file:
6+
# - CUDA_HOME/CUDA_DIR/ENV{CUDA_HOME}/ENV{CUDA_DIR}:
77
# Path to spdlog libaray installation path.
88
# ==================================================================================================
99

@@ -19,7 +19,5 @@ set(CUDA_CMAKE_PREFIX_PATH "${CUDA_HOME}/lib64/cmake")
1919
list(APPEND CMAKE_PREFIX_PATH ${CUDA_CMAKE_PREFIX_PATH})
2020

2121
# Find the CUDA package
22-
# @see
23-
# |- All imported targets:
24-
# |- "https://cmake.org/cmake/help/git-stage/module/FindCUDAToolkit.html#imported-targets"
22+
# [SEE] All imported targets: https://cmake.org/cmake/help/git-stage/module/FindCUDAToolkit.html#imported-targets
2523
find_package(CUDAToolkit REQUIRED)

csrc/cmake/libraries/libpython.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# @see "https://cmake.org/cmake/help/latest/module/FindPython.html"
1+
# [SEE] "https://cmake.org/cmake/help/latest/module/FindPython.html"
22
find_package(
33
Python
44
REQUIRED

csrc/cmake/libraries/libspdlog.cmake

Lines changed: 0 additions & 19 deletions
This file was deleted.

csrc/cmake/libraries/libtorch.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ list(APPEND CMAKE_PREFIX_PATH ${PYTORCH_CMAKE_PREFIX_PATH})
1212

1313
find_package(Torch REQUIRED)
1414

15-
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -DTORCH_USE_CUDA_DSA=1")
15+
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG}")

0 commit comments

Comments
 (0)