Skip to content

Commit b9b943a

Browse files
shoikedakurbeco
authored andcommitted
MiniDxNN v0.2.0
1 parent 9fab527 commit b9b943a

52 files changed

Lines changed: 8873 additions & 2594 deletions

Some content is hidden

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

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
# debug information files
4141
*.dwo
4242

43-
#
4443
clang/
4544
tmp/
4645
.cache/

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/project.cmake)
1515
include(${CMAKE_CURRENT_LIST_DIR}/cmake/utility.cmake)
1616

1717
set(project_desc "A minimal DirectX-based neural network library")
18-
project(MiniDxNN DESCRIPTION ${project_desc} VERSION 0.1.0 LANGUAGES CXX)
18+
project(MiniDXNN DESCRIPTION ${project_desc} VERSION 0.2.0 LANGUAGES CXX)
1919

2020
# Configure project options (build flags, sanitizers, etc.)
2121
setProjectOptions()
2222

2323
# Top-level project configuration
24-
# Only applied when MiniDxNN is the main project (not when included as a subproject)
24+
# Only applied when MiniDXNN is the main project (not when included as a subproject)
2525
if(PROJECT_IS_TOP_LEVEL)
2626
# Configure available build types (multi-config generators like Visual Studio)
2727
set(CMAKE_CONFIGURATION_TYPES "Debug" "RelWithDebInfo" "Release")
@@ -39,8 +39,8 @@ project(MiniDxNN DESCRIPTION ${project_desc} VERSION 0.1.0 LANGUAGES CXX)
3939
# Build third-party dependencies
4040
add_subdirectory("${PROJECT_SOURCE_DIR}/third_party" "${PROJECT_BINARY_DIR}/third_party")
4141

42-
# Configure MiniDxNN core library
43-
setMiniDxNNCore(minidxnn-core)
42+
# Configure MiniDXNN core library
43+
setMiniDXNNCore(minidxnn-core)
4444
checkTarget(minidxnn-core)
4545

4646
# Configure and build examples

NOTICE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# MiniDxNn - Third Party Notices
1+
# MiniDXNN - Third Party Notices
22

33
This product includes software developed by other organizations
44
and contains third-party components under various open source licenses.
@@ -8,7 +8,7 @@ and contains third-party components under various open source licenses.
88
- **license:** MIT License
99
* [gfx](https://github.com/gboisse/gfx)
1010
- **used for:** To introduce Direct3D12 framework
11-
- **license:** MIT license
11+
- **license:** MIT License
1212
* [CLI11](https://github.com/CLIUtils/CLI11)
1313
- **used for:** Command line parser for C++
1414
- **license:** BSD-3-Clause license

README.md

Lines changed: 113 additions & 185 deletions
Large diffs are not rendered by default.

cmake/compiler.cmake

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
## MINIDXNN_ARCH_FEATURE_LEVEL: CPU architecture level (Amd64V1/V2/V3/V4)
1717
function(setCxxCompileFlags target scope)
1818
# Detect compiler type using generator expressions
19-
set(has_msvc $<OR:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>)
20-
set(has_gcc $<OR:$<C_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:GNU>>)
21-
set(has_clang $<OR:$<C_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:Clang>,$<C_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:AppleClang>>)
22-
set(has_apple_clang $<OR:$<C_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:AppleClang>>)
19+
set(has_msvc $<CXX_COMPILER_ID:MSVC>)
20+
set(has_gcc $<CXX_COMPILER_ID:GNU>)
21+
set(has_apple_clang $<CXX_COMPILER_ID:AppleClang>)
22+
set(has_clang $<OR:$<CXX_COMPILER_ID:Clang>,${has_apple_clang}>)
2323

2424
# Check if using MSVC frontend (e.g., clang-cl)
2525
set(has_msvc_frontend 0)
@@ -132,14 +132,29 @@ function(setCxxWarningFlags target scope)
132132
# Check if extra warnings are enabled
133133
set(has_extra $<BOOL:${MINIDXNN_WARNING_EXTRA}>)
134134
135-
# Detect compiler type
136-
set(has_msvc $<OR:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>)
137-
set(has_gcc $<OR:$<C_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:GNU>>)
138-
set(has_clang $<OR:$<C_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:Clang>,$<C_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:AppleClang>>)
135+
# Detect compiler type using generator expressions
136+
set(has_msvc $<CXX_COMPILER_ID:MSVC>)
137+
set(has_gcc $<CXX_COMPILER_ID:GNU>)
138+
set(has_apple_clang $<CXX_COMPILER_ID:AppleClang>)
139+
set(has_clang $<OR:$<CXX_COMPILER_ID:Clang>,${has_apple_clang}>)
139140
140141
# MSVC warning levels
141-
set(msvc_options /W4) # Warning level 4 (high but reasonable)
142-
set(msvc_options_extra /Wall) # All warnings (may be noisy)
142+
set(msvc_options /W4 /wd4244) # Warning level 4 (high but reasonable)
143+
set(msvc_options_extra /Wall
144+
/wd4514 # unreferenced inline function removed (informational)
145+
/wd4625 # copy constructor implicitly deleted (GoogleTest)
146+
/wd4626 # copy assignment implicitly deleted (GoogleTest)
147+
/wd4710 # function not inlined (compiler decision, informational)
148+
/wd4711 # function selected for automatic inline expansion (informational)
149+
/wd4820 # struct padding added (informational)
150+
/wd4866 # left-to-right evaluation order (third-party)
151+
/wd4868 # left-to-right evaluation order in braced init (third-party)
152+
/wd5026 # move constructor implicitly deleted (GoogleTest)
153+
/wd5027 # move assignment implicitly deleted (GoogleTest)
154+
/wd5045 # Spectre mitigation insertion (informational)
155+
/wd4324 # structure padded due to alignment specifier
156+
/wd5264 # 'const' variable is not used (used only with GFX)
157+
) # All warnings with noise suppressions
143158
144159
# GCC warning options
145160
set(gcc_options -Wall
@@ -174,11 +189,35 @@ function(setCxxWarningFlags target scope)
174189
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
175190
# Clang-CL (MSVC-compatible frontend)
176191
set(clang_options /W4)
177-
set(clang_options_extra /Wall -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic)
192+
set(clang_options_extra /Wall -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic
193+
-Wno-padded # Struct padding is intentional
194+
-Wno-covered-switch-default # All enum values handled; default added for safety
195+
-Wno-global-constructors # Google Test macros require global constructors
196+
-Wno-unsafe-buffer-usage # Clang hardening opt-in; valid pointer usage
197+
-Wno-unsafe-buffer-usage-in-libc-call
198+
-Wno-unsafe-buffer-usage-in-container
199+
-Wno-weak-vtables # vtable placement hint, not a bug
200+
-Wno-ctad-maybe-unsupported # CTAD is intentional C++17/20 usage
201+
-Wno-missing-prototypes # C-only concept, not meaningful for C++
202+
-Wno-unused-template # Templates in headers may not be used in every TU
203+
-Wno-undefined-func-template # Template instantiation across TUs is by design
204+
)
178205
elseif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU")
179206
# Clang with GNU-compatible frontend
180207
set(clang_options -Wall -Wextra -pedantic)
181-
set(clang_options_extra -Weverything -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic)
208+
set(clang_options_extra -Weverything -Wno-c++-compat -Wno-c++98-compat -Wno-c++98-compat-pedantic
209+
-Wno-padded # Struct padding is intentional
210+
-Wno-covered-switch-default # All enum values handled; default added for -Wswitch-default
211+
-Wno-global-constructors # Google Test macros require global constructors
212+
-Wno-unsafe-buffer-usage # Clang hardening opt-in; valid pointer usage
213+
-Wno-unsafe-buffer-usage-in-libc-call
214+
-Wno-unsafe-buffer-usage-in-container
215+
-Wno-weak-vtables # vtable placement hint, not a bug
216+
-Wno-ctad-maybe-unsupported # CTAD is intentional C++17/20 usage
217+
-Wno-missing-prototypes # C-only concept, not meaningful for C++
218+
-Wno-unused-template # Templates in headers may not be used in every TU
219+
-Wno-undefined-func-template # Template instantiation across TUs is by design
220+
)
182221
endif()
183222
184223
# Apply warning flags to target
@@ -201,33 +240,38 @@ endfunction(setCxxWarningFlags)
201240
function(setSanitizerFlags target scope)
202241
# Check which sanitizers are enabled via cache options
203242
set(has_address $<BOOL:${MINIDXNN_ENABLE_SANITIZER_ADDRESS}>)
243+
set(has_undef $<BOOL:${MINIDXNN_ENABLE_SANITIZER_UNDEF_BEHAVIOR}>)
204244
#set(has_thread $<BOOL:${MINIDXNN_ENABLE_SANITIZER_THREAD}>)
205245
#set(has_memory $<BOOL:${MINIDXNN_ENABLE_SANITIZER_MEMORY}>)
206-
#set(has_undef $<BOOL:${MINIDXNN_ENABLE_SANITIZER_UNDEF_BEHAVIOR}>)
207-
#set(has_leak $<BOOL:${MINIDXNN_ENABLE_SANITIZER_LEAK}>)
208-
#set(has_cfi $<BOOL:${MINIDXNN_ENABLE_SANITIZER_CFI}>)
209246
#set(has_safe_stack $<BOOL:${MINIDXNN_ENABLE_SANITIZER_SAFE_STACK}>)
210247
248+
# Detect compiler type using generator expressions
249+
set(has_msvc $<CXX_COMPILER_ID:MSVC>)
250+
set(has_gcc $<CXX_COMPILER_ID:GNU>)
251+
set(has_apple_clang $<CXX_COMPILER_ID:AppleClang>)
252+
set(has_clang $<OR:$<CXX_COMPILER_ID:Clang>,${has_apple_clang}>)
253+
254+
# UBSan: GCC supports a subset; Clang supports additional checks
255+
set(ubsan_gcc -fsanitize=undefined,float-divide-by-zero)
256+
set(ubsan_clang -fsanitize=undefined,float-divide-by-zero,unsigned-integer-overflow,implicit-conversion,local-bounds,nullability)
257+
211258
# Apply sanitizer compile options
212-
# TODO: Support other sanitizers
213259
target_compile_options(${target} ${scope}
214260
$<${has_address}:-fsanitize=address;-fno-omit-frame-pointer>
261+
$<${has_undef}:$<${has_gcc}:${ubsan_gcc}>
262+
$<${has_clang}:${ubsan_clang}>>
215263
#$<${has_thread}:-fsanitize=thread>
216264
#$<${has_memory}:-fsanitize=memory;-fno-omit-frame-pointer>
217-
#$<${has_undef}:-fsanitize=undefined,float-divide-by-zero,unsigned-integer-overflow,implicit-conversion,local-bounds,nullability>
218-
#$<${has_leak}:-fsanitize=leak>
219-
#$<${has_cfi}:-fsanitize=cfi>
220265
#$<${has_safe_stack}:-fsanitize=safe-stack>
221266
)
222267
223268
# Apply sanitizer link options (must match compile options)
224269
target_link_options(${target} ${scope}
225270
$<${has_address}:-fsanitize=address>
271+
$<${has_undef}:$<${has_gcc}:${ubsan_gcc}>
272+
$<${has_clang}:${ubsan_clang}>>
226273
#$<${has_thread}:-fsanitize=thread>
227274
#$<${has_memory}:-fsanitize=memory>
228-
#$<${has_undef}:-fsanitize=undefined,float-divide-by-zero,unsigned-integer-overflow,implicit-conversion,local-bounds,nullability>
229-
#$<${has_leak}:-fsanitize=leak>
230-
#$<${has_cfi}:-fsanitize=cfi>
231275
#$<${has_safe_stack}:-fsanitize=safe-stack>
232276
)
233277
endfunction(setSanitizerFlags)

cmake/options.cmake

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,25 @@ function(setProjectOptions)
3232
"AddressSanitizer: Detect memory errors (buffer overflows, use-after-free, etc.)"
3333
OFF)
3434

35+
option(MINIDXNN_ENABLE_SANITIZER_UNDEF_BEHAVIOR
36+
"UndefinedBehaviorSanitizer: Detect undefined behavior (integer overflow, null deref, etc.)"
37+
OFF)
38+
3539
# TODO: Support other sanitizers
3640
#option(MINIDXNN_ENABLE_SANITIZER_THREAD
3741
# "ThreadSanitizer: Detect data races and threading issues"
3842
# OFF)
3943
#option(MINIDXNN_ENABLE_SANITIZER_MEMORY
4044
# "MemorySanitizer: Detect reads of uninitialized memory (Clang/LLVM only)"
4145
# OFF)
42-
#option(MINIDXNN_ENABLE_SANITIZER_UNDEF_BEHAVIOR
43-
# "UndefinedBehaviorSanitizer: Detect undefined behavior (integer overflow, null deref, etc.)"
44-
# OFF)
45-
#option(MINIDXNN_ENABLE_SANITIZER_LEAK
46-
# "LeakSanitizer: Detect memory leaks at program exit"
47-
# OFF)
48-
#option(MINIDXNN_ENABLE_SANITIZER_CFI
49-
# "Control Flow Integrity: Protect against control flow hijacking (Clang with LTO only)"
50-
# OFF)
5146
#option(MINIDXNN_ENABLE_SANITIZER_SAFE_STACK
5247
# "SafeStack: Protect against stack buffer overflows (Clang only)"
5348
# OFF)
5449

55-
# MiniDxNN options
50+
# MiniDXNN options
51+
option(MINIDXNN_CPP_FALLBACK_ONLY
52+
"Build without DirectX 12 / gfx dependency; use C++ fallback for MLP computation"
53+
OFF)
5654
option(MINIDXNN_BUILD_EXAMPLES
5755
"Build example programs demonstrating library usage"
5856
ON)
@@ -63,5 +61,4 @@ function(setProjectOptions)
6361
"Add unit tests for 32-bit floating point into GoogleTest"
6462
OFF)
6563

66-
6764
endfunction(setProjectOptions)

cmake/project.cmake

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
# SPDX-License-Identifier: MIT
88
#
99

10-
## Configure MiniDxNN interface library
10+
## Configure MiniDXNN interface library
1111
## Creates an INTERFACE target that links all dependencies
12-
function(setMiniDxNNCore target)
12+
function(setMiniDXNNCore target)
1313
# Dependencies
1414
if(NOT TARGET Threads::Threads)
1515
set(THREADS_PREFER_PTHREAD_FLAG ON)
@@ -19,6 +19,17 @@ function(setMiniDxNNCore target)
1919
add_library(${target} INTERFACE)
2020

2121
#
22-
target_include_directories(${target} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../include)
23-
target_link_libraries(${target} INTERFACE Threads::Threads half-float-dep gfx-dep)
24-
endfunction(setMiniDxNNCore)
22+
target_include_directories(${target} SYSTEM INTERFACE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../include)
23+
24+
target_link_libraries(${target} INTERFACE Threads::Threads half-float-dep)
25+
if(MINIDXNN_CPP_FALLBACK_ONLY)
26+
target_compile_definitions(${target} INTERFACE
27+
MINIDXNN_CPP_FALLBACK_ONLY=1
28+
#MINIDXNN_NO_INCLUDE_DX_LINALG=1
29+
#MINIDXNN_USE_SOFTWARE_LINALG_IMPL=1
30+
#MINIDXNN_CPP_FALLBACK_HALF_TYPE=half_float::half
31+
)
32+
else()
33+
target_link_libraries(${target} INTERFACE gfx-dep)
34+
endif()
35+
endfunction(setMiniDXNNCore)

0 commit comments

Comments
 (0)