Skip to content

Commit

Permalink
publish commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioSieg committed Jan 2, 2025
0 parents commit daa08e6
Show file tree
Hide file tree
Showing 348 changed files with 137,587 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.gitignore
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
101 changes: 101 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Multi-Platform CMake Build

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
- os: macos-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
- os: macos-latest
c_compiler: gcc
- os: macos-latest
c_compiler: cl

steps:
- uses: actions/checkout@v4

- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build C++ Runtime
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j4

- name: Prepare C++ Test Data
run: cp -r ${{ github.workspace }}/test_data ${{ steps.strings.outputs.build-output-dir }}/test/test_data

- name: Run C++ Runtime Tests
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }} --verbose

- name: Setup Python Virtual Environment
shell: bash
run: |
python3 -m venv .venv
. .venv/bin/activate
pip install --upgrade pip
- name: Build Python wheel
shell: bash
run: |
. .venv/bin/activate
cd ${{ github.workspace }}/python/magnetron_framework
pip wheel --verbose -w dist .
- name: Install Python wheel
shell: bash
run: |
. .venv/bin/activate
pip install ${{ github.workspace }}/python/magnetron_framework/dist/*.whl
- name: Install Pytest
shell: bash
run: |
. .venv/bin/activate
pip install pytest
- name: Run Python Tests
shell: bash
run: |
. .venv/bin/activate
python -m pytest ${{ github.workspace }}/python/tests/tests.py
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
/cmake-build-debug
/cmake-build-release
/cmake-build-relwithdebinfo
/.idea
/.vscode
/bin
/python/.venv
/python/.vscode
/python/.idea
/python/magnetron_framework/build/
/python/magnetron_framework/dist/
/python/magnetron_framework/magnetron.egg-info/
/python/__pycache__
/python/magnetron/__pycache__/
/python/examples/__pycache__/
/python/extra/__pycache__/
/python/tests/__pycache__/
**/.DS_Store
.vs/
out/
.tmp
CMakeSettings.json
magnetron_chat/.idea
126 changes: 126 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# (c) 2024 Mario "Neo" Sieg. <[email protected]>

cmake_minimum_required(VERSION 3.18)

project(magnetron LANGUAGES C)

message("Configuring magnetron project for ${CMAKE_SYSTEM_PROCESSOR}...")

set(CMAKE_C_STANDARD 99)
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}")

option(MAGNETRON_BUILD_TESTS "Build tests" ON)
option(MAGNETRON_BUILD_BENCHMARKS "Build benchmarks" ON)
option(MAGNETRON_BUILD_FUZZERS "Build fuzzers" OFF)

# (CPU only) Enable SIMD math function approximations. Greatly increases performance. Try disabling if you encounter numerical instability. Does NOT enable -ffast-math or similar compiler flags.
option(MAGNETRON_CPU_APPROX_MATH "Use faster but less precise math functions" ON)
option(MAGNETRON_ENABLE_CUDA "Enable CUDA support" ON) # Enable CUDA support
if (APPLE)
option(MAGNETRON_ENABLE_ACCELERATE "Use Apple's Accelerate framework" ON)
endif()

if (${MAGNETRON_BUILD_TESTS})
enable_testing()
endif()

set(MAGNETRON_CUDA_COMPILER "/usr/local/cuda-12.6/bin/nvcc" CACHE STRING "Path to the CUDA compiler") # Set to your CUDA compiler path
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
set(IS_AMD64 TRUE)
else()
set(IS_AMD64 FALSE)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64)|(arm64)")
set(IS_ARM64 TRUE)
else()
set(IS_ARM64 FALSE)
endif()

file(GLOB_RECURSE MAGNETRON_SOURCES magnetron/*.h magnetron/*.c magnetron/*.m)
add_library(magnetron SHARED ${MAGNETRON_SOURCES})
target_include_directories(magnetron PRIVATE extern)
if(WIN32) # Windows specific config
target_compile_options(magnetron PRIVATE /W3 /Oi)
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") # Enable optimizations for release builds
target_compile_options(magnetron PRIVATE /O2 /Oy)
endif()
else() # POSIX specific config
target_link_libraries(magnetron m) # link math library
target_compile_options(magnetron PRIVATE
-Wall
-Werror
-std=c99
-Wno-gnu-zero-variadic-macro-arguments
-Wno-error=overflow
-Wno-error=unused-function
-fvisibility=hidden
-std=gnu99
)
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(magnetron PRIVATE -Wno-error=format-truncation)
endif()
if (APPLE) # Apple specific configuration
if (${MAGNETRON_ENABLE_ACCELERATE})
find_library(ACCELERATE_FRAMEWORK Accelerate)
if (ACCELERATE_FRAMEWORK)
message(STATUS "Accelerate framework found")
target_compile_definitions(magnetron PRIVATE MAG_ACCELERATE)
target_compile_definitions(magnetron PRIVATE ACCELERATE_NEW_LAPACK)
target_compile_definitions(magnetron PRIVATE ACCELERATE_LAPACK_ILP64)
target_link_libraries(magnetron ${ACCELERATE_FRAMEWORK})
else()
message(WARNING "Accelerate framework not found, using fallback")
endif()
endif()
endif()
if (${MAGNETRON_CPU_APPROX_MATH})
target_compile_definitions(magnetron PRIVATE MAG_APPROXMATH)
endif()
if(${IS_AMD64}) # x86-64 specific compilation options
target_compile_options(magnetron PRIVATE -msse2 -msse3 -mssse3 -msse4.1 -msse4.2 -mpclmul)
elseif(${IS_ARM64})
target_compile_options(magnetron PRIVATE -march=armv8-a+simd)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") # Enable optimizations only for release builds
target_compile_options(magnetron PRIVATE -O3 -flto)
target_link_options(magnetron PRIVATE -flto)
endif()
endif()

if (${MAGNETRON_ENABLE_CUDA})
find_package(CUDAToolkit)
if (CUDAToolkit_FOUND)
if (NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES "52;61;70;75")
endif()
if (NOT DEFINED CMAKE_CUDA_COMPILER)
set(CMAKE_CUDA_COMPILER "${MAGNETRON_CUDA_COMPILER}")
endif()
set(CMAKE_CUDA_STANDARD 20)
enable_language(CUDA)
file(GLOB_RECURSE MAGNETRON_CUDA_SOURCES magnetron/*.cu magnetron/*.cuh)
add_library(magnetron_cuda SHARED ${MAGNETRON_CUDA_SOURCES})
target_include_directories(magnetron_cuda PRIVATE extern)
target_link_libraries(magnetron_cuda CUDA::cudart CUDA::cuda_driver)
target_compile_definitions(magnetron_cuda PRIVATE MAG_ENABLE_CUDA)
target_compile_definitions(magnetron PRIVATE MAG_ENABLE_CUDA)
target_link_libraries(magnetron magnetron_cuda)
else()
message(WARNING "CUDA not found, disabling CUDA support")
set(MAGNETRON_ENABLE_CUDA OFF)
endif()
endif()

if (${MAGNETRON_BUILD_TESTS})
add_subdirectory(test)
endif()

if (${MAGNETRON_BUILD_FUZZERS})
add_subdirectory(fuzzer)
endif()

if (${MAGNETRON_BUILD_BENCHMARKS})
add_subdirectory(benchmark)
endif()

Loading

0 comments on commit daa08e6

Please sign in to comment.