Skip to content

Commit b8517e9

Browse files
committed
[update] BIG UPDATE
1 parent 46b0b34 commit b8517e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+780
-320
lines changed

.clangd

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
CompileFlags:
2-
Add:
3-
# [TODO] Maybe add a python script to change cuda path automatically?
4-
# You may need to change this to /usr/local/cuda if using Linux:
5-
# - --cuda-path=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.5/
6-
- --no-cuda-version-check
7-
Remove:
8-
- -ccbin
9-
- -forward-unknown-to-host-compiler
10-
- -rdc=true
11-
- -gencode
12-
- --generate-code*
13-
- -Xcudafe
14-
- --diag_suppress=*
15-
- --expt-relaxed-constexpr
16-
- --expt-extended-lambda
17-
- -Xcompiler*
18-
- -arch=*
1+
Index:
2+
Background: Build
3+
StandardLibrary: Yes
194

205
Diagnostics:
21-
UnusedIncludes: Strict
22-
MissingIncludes: Strict
6+
UnusedIncludes: None
7+
MissingIncludes: None
238

249
ClangTidy:
2510
Add: [
@@ -33,16 +18,48 @@ Diagnostics:
3318
readability-isolate-declaration,
3419
readability-identifier-length,
3520
readability-magic-numbers,
21+
readability-function-cognitive-complexity,
22+
readability-redundant-access-specifiers,
23+
modernize-avoid-c-arrays,
24+
readability-math-missing-parentheses,
3625
]
3726

3827
CheckOptions:
39-
readability-identifier-naming.VariableCase: lowerCamelCase
40-
readability-identifier-naming.ProtectedMemberCase: lowerCamelCase
41-
readability-identifier-naming.PrivateMemberCase: lowerCamelCase
42-
readability-identifier-naming.PublicMemberCase: lowerCamelCase
28+
readability-identifier-naming.VariableCase: aNy_CasE
29+
readability-identifier-naming.ProtectedMemberCase: aNy_CasE
30+
readability-identifier-naming.PrivateMemberCase: aNy_CasE
31+
readability-identifier-naming.PublicMemberCase: aNy_CasE
4332
readability-identifier-naming.NamespaceCase: lower_case
44-
readability-identifier-naming.EnumCase: lowerCamelCase
33+
readability-identifier-naming.EnumCase: CamelCase
4534
readability-identifier-naming.ClassCase: CamelCase
4635
readability-identifier-naming.StructCase: CamelCase
47-
readability-identifier-naming.FunctionCase: lowerCamelCase
48-
readability-identifier-naming.ClassMethodCase: lowerCamelCase
36+
readability-identifier-naming.FunctionCase: camelBack
37+
readability-identifier-naming.ClassMethodCase: camelBack
38+
39+
CompileFlags:
40+
Add:
41+
- -Wall
42+
- -Wextra
43+
Remove:
44+
- -ccbin
45+
- -forward-unknown-to-host-compiler
46+
- --generate-code*
47+
- -arch*
48+
- -rdc=true
49+
- -Xcudafe
50+
- --diag_suppress=*
51+
- --expt-relaxed-constexpr
52+
- --expt-extended-lambda
53+
- -gencode
54+
- -Xcompiler*
55+
- -fmodules*
56+
- -fmodule-mapper*
57+
- -fdeps-format*
58+
59+
---
60+
61+
If:
62+
PathMatch: [.*\.cu, .*\.cuh]
63+
CompileFlags:
64+
Add:
65+
- --cuda-gpu-arch=sm_89

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ cython_debug/
164164
# Not ignore anything from ./csrc
165165
!/csrc/*
166166
# But ignore ./build in case someone build with -B ./csrc/build (better not do this)
167-
/csrc/build
168167

169168
# Ignore installation directory
170169
/example_package/_torch_ops
170+
171+
/src/simple_py/extended_clib

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"twxs.cmake", // cmake
55
"ms-vscode.cpptools", // C/C++
66
"ms-python.python", // Python
7-
"ms-python.black-formatter", // Python formatter
87
"njpwerner.autodocstring", // Python docstring generator
8+
"charliermarsh.ruff",
99
]
1010
}

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ A Template of Python Project in Visual Studio Code with Github Actions CI/CD (Es
66
Create a new conda environment:
77

88
```bash
9-
conda create -n pytemplate python=3.12
10-
conda activate pytemplate
9+
$ uv venv -p 3.12
10+
$ source .venv/bin/activate
1111
```
1212

13-
Install `example_package`:
13+
Install `simple_py`:
1414

1515
```bash
16-
pip3 install --no-build-isolation .
16+
$ uv install -v .
1717
```
1818

19-
`torch.ops.example_package.vector_add` will be available after installation; See [test.py](test/test.py) for usage.
19+
`torch.ops.simple_py.vector_add` will be available after installation; See [test.py](test/test.py) for usage.
2020

2121
## How to Test
2222

2323
```bash
24-
conda activate pytemplate
2524
python test/test.py
2625
```

configs/loggers.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
__default__:
2+
level: INFO
3+
to_console: true
4+
save_path: null
5+
mode: null
6+
max_bytes: null
7+
backup_count: null
8+
log_prefix: "[%(asctime)s,%(msecs)03d][pid=%(process)d][%(levelname)s]"
9+
log_data: " > %(message)s"
10+
log_suffix: ""
11+
date_fmt: "%y-%m-%d %H:%M:%S"
12+
13+
BASIC:
14+
level: INFO
15+
to_console: true
16+
save_path: null
17+
mode: null
18+
max_bytes: null
19+
backup_count: null
20+
log_prefix: "[%(asctime)s,%(msecs)03d][pid=%(process)d][%(levelname)s]"
21+
log_data: " > %(message)s"
22+
log_suffix: ""
23+
date_fmt: "%y-%m-%d %H:%M:%S"
24+
25+
DEBUG:
26+
level: DEBUG
27+
to_console: true
28+
save_path: logs/debug.log
29+
mode: "a"
30+
max_bytes: 1048576
31+
backup_count: 10
32+
log_prefix: "[%(asctime)s,%(msecs)03d][pid=%(process)d][%(levelname)s][%(module)s:L%(lineno)d]"
33+
log_data: " > %(message)s"
34+
log_suffix: ""
35+
date_fmt: "%y-%m-%d %H:%M:%S"

csrc/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@
22
cmake_minimum_required(VERSION 3.30)
33

44
# Project Name and version
5-
project(VSC-CMAKE-CXX-TEMPLATE VERSION 1.0.0)
5+
project(SIMPLE_PY VERSION 1.0.0)
66

77
# Common utility functions
88
include(${PROJECT_SOURCE_DIR}/cmake/utils/common.cmake)
99

1010
# @see "./cmake/utils/variables.cmake"
1111
set_default_values(
1212
# CMake project namespace:
13-
# All the libs should have a alias with this namespace
14-
# [NOTE] Change this to your own namespace
15-
PROJECT_NAMESPACE "_template_project_name_::"
13+
# All the libs should have a alias with this namespace
14+
PROJECT_NAMESPACE "simple_py::"
15+
STDOUT_IS_TERMINAL OFF
16+
CMAKE_EXECUTABLE_SUFFIX ""
1617
)
1718

1819
# Utility functions for installing libraries:
1920
include(${PROJECT_SOURCE_DIR}/cmake/utils/lib-install.cmake)
2021

2122
# Compiler configurations for cpp, e.g., g++, clang++, msvc(cl), etc.
2223
include(${PROJECT_SOURCE_DIR}/cmake/compilers/cxx-compiler-configs.cmake)
23-
24-
# Compiler configurations for Python and PyTorch(with CUDA):
24+
# Compiler configurations for CUDA:
2525
include(${PROJECT_SOURCE_DIR}/cmake/compilers/cuda-compiler-configs.cmake)
26+
27+
# Find other libraries:
2628
include(${PROJECT_SOURCE_DIR}/cmake/libraries/libpython.cmake)
2729
include(${PROJECT_SOURCE_DIR}/cmake/libraries/libtorch.cmake)
30+
include(${PROJECT_SOURCE_DIR}/cmake/libraries/libpybind11.cmake)
2831

2932
add_subdirectory(${PROJECT_SOURCE_DIR}/lib)
3033
add_subdirectory(${PROJECT_SOURCE_DIR}/test)

csrc/cmake/cmake-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
Default: *Auto-Detect*.
3636
- `PROJECT_NAMESPACE`: Project namespace; Library targets should have an alias with project namespace as the prefix.
3737
See: [CMakelists.txt](../CMakeLists.txt).
38-
Default: `_template_project_name_`;
38+
Default: `_simple_py_`;
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).
4141
Default: `1048576` (Bytes).

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
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
# ==================================================================================================
99

10-
include(${PROJECT_SOURCE_DIR}/cmake/utils/logging.cmake)
10+
include(${CMAKE_CURRENT_LIST_DIR}/../utils/logging.cmake)
1111

1212
enable_language(CUDA)
1313

@@ -22,6 +22,6 @@ set(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
2222
set(CMAKE_CUDA_ARCHITECTURES native)
2323
log_info("CMAKE_CUDA_STANDARD: ${CMAKE_CUDA_STANDARD}")
2424

25-
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
26-
set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -O3")
27-
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -lineinfo")
25+
string(APPEND CMAKE_CUDA_FLAGS " --expt-relaxed-constexpr")
26+
string(APPEND CMAKE_CUDA_FLAGS_RELWITHDEBINFO " -lineinfo")
27+
string(APPEND CMAKE_CUDA_FLAGS_DEBUG " -lineinfo")

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,59 @@
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.
911
# - `STACK_SIZE`: Stack size for the executable. Default: 1048576 (1MB).
1012
# ==================================================================================================
1113

12-
include(${PROJECT_SOURCE_DIR}/cmake/utils/common.cmake)
14+
include(${CMAKE_CURRENT_LIST_DIR}/../utils/common.cmake)
1315

14-
set_default_values(CMAKE_CXX_SCAN_FOR_MODULES OFF)
1516
enable_language(CXX)
1617

17-
# Generate compile_commands.json in build directory
18-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
18+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1919

20-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
21-
log_info("CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
20+
set_default_values(
21+
CMAKE_CXX_STANDARD 20
22+
CMAKE_CXX_SCAN_FOR_MODULES OFF
23+
STACK_SIZE 1048576
24+
)
2225

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

28-
# Compiler flags for MSVC
30+
# MSVC ----------------------------------------------------------------------------------------------------------------
2931
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
3032
string(APPEND CMAKE_CXX_FLAGS " /permissive- /Zc:forScope /openmp /Zc:__cplusplus")
31-
string(APPEND CMAKE_CXX_FLAGS_RELEASE " /O2")
32-
string(APPEND CMAKE_CXX_FLAGS_DEBUG " /Zi")
33-
# Set stack size
3433
string(APPEND CMAKE_EXE_LINKER_FLAGS " /STACK:${STACK_SIZE}")
35-
# Compiler flags for Clang
34+
# Clang ---------------------------------------------------------------------------------------------------------------
3635
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
37-
string(APPEND CMAKE_CXX_FLAGS " -fopenmp -Wall -Wextra -Werror")
38-
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O3")
39-
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -g")
40-
# Set stack size
36+
string(APPEND CMAKE_CXX_FLAGS " -stdlib=libc++ -fopenmp -Wall -Wextra -Werror")
4137
if (WIN32)
4238
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-stack,${STACK_SIZE}")
4339
else()
4440
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-zstack-size=${STACK_SIZE}")
4541
endif()
46-
# Compiler flags for GNU
42+
# GNU -----------------------------------------------------------------------------------------------------------------
4743
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
4844
string(APPEND CMAKE_CXX_FLAGS " -fopenmp -Wall -Wextra -Werror")
49-
string(APPEND CMAKE_CXX_FLAGS_RELEASE " -O3")
50-
string(APPEND CMAKE_CXX_FLAGS_DEBUG " -g")
51-
# Set stack size
5245
if (WIN32)
5346
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,--stack,${STACK_SIZE}")
5447
else()
5548
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-zstack-size=${STACK_SIZE}")
5649
endif()
57-
# @todo @jamesnulliu
58-
# |- Add compiler flags for other compilers
5950
else()
6051
log_fatal("Unsupported compiler")
52+
endif()
53+
54+
if(STDOUT_IS_TERMINAL)
55+
add_compile_options(
56+
$<$<CXX_COMPILER_ID:GNU>:-fdiagnostics-color=always>
57+
$<$<CXX_COMPILER_ID:Clang>:-fcolor-diagnostics>
58+
$<$<CXX_COMPILER_ID:MSVC>:/FC>
59+
)
6160
endif()

csrc/cmake/config.cmake.in/examplePackageLibConfig.cmake.in renamed to csrc/cmake/config.cmake.in/ExtendedPetConfig.cmake.in

File renamed without changes.

0 commit comments

Comments
 (0)