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

[WIP] Add cmake build scheme #3068

Draft
wants to merge 87 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
67921c3
start building out cmake to work with the tests. Now had batched test…
SteveBronder May 13, 2024
56ec5f4
update test
SteveBronder May 14, 2024
82dcd7a
update cmake
SteveBronder May 14, 2024
275ea24
add inline to a lot of test functions and comment out the dae tests
SteveBronder May 15, 2024
c2e298e
Merge remote-tracking branch 'origin/develop' into feature/cmake-tests
SteveBronder May 23, 2024
617ee47
update
SteveBronder May 29, 2024
0b95d16
newline error on jenkinsfile
SteveBronder May 29, 2024
211839c
newline error on jenkinsfile
SteveBronder May 29, 2024
2bda7e4
Merge commit 'e1fcbe8dca2bfa85b1e109b2bfb1cf65fe0363b7' into HEAD
yashikno May 29, 2024
a8efa32
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot May 29, 2024
238a7fd
fix lint issues
SteveBronder May 29, 2024
5dc921b
update
SteveBronder May 29, 2024
2f7f627
fix subtest builders
SteveBronder May 29, 2024
7ccf07c
fix windows compile tests
SteveBronder May 29, 2024
a844ca4
move cmake deps to own folder
SteveBronder May 29, 2024
e97a61e
revert changes to runtests.py
SteveBronder May 29, 2024
ce4f814
trying to fix git tests
SteveBronder May 30, 2024
4d591a7
update to remove std::cout in dae solver debugging
SteveBronder May 31, 2024
70163a9
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot May 31, 2024
fff42b0
remove && from powershell commands
SteveBronder May 31, 2024
33e172e
update workflow
SteveBronder Jun 3, 2024
026fc47
update tbb
SteveBronder Jun 3, 2024
a39fa9d
update tbb
SteveBronder Jun 3, 2024
b0cf280
update tbb
SteveBronder Jun 3, 2024
b4bc673
update tbb
SteveBronder Jun 3, 2024
3e921d9
update tbb
SteveBronder Jun 3, 2024
6da07ac
update tbb
SteveBronder Jun 3, 2024
eda1c0b
update tbb
SteveBronder Jun 3, 2024
4f85d92
update tbb
SteveBronder Jun 3, 2024
0e39fbf
update to use stan::math::pi() instead of M_PI
SteveBronder Jun 3, 2024
a397f99
Merge commit '8a09048f5187662687e04c14d7737cf4d20a18a1' into HEAD
yashikno Jun 3, 2024
cd921b2
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 3, 2024
1fbd7e7
fix tbb flags
SteveBronder Jun 3, 2024
14d0c4e
Merge remote-tracking branch 'refs/remotes/origin/feature/cmake-tests…
SteveBronder Jun 3, 2024
a672ed3
just test making test_unit_math
SteveBronder Jun 5, 2024
2c20934
run all unit tests in jenkinsfile
SteveBronder Jun 5, 2024
8b4589c
update matrix exp test
SteveBronder Jun 5, 2024
27b1e26
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 5, 2024
8201295
update with OpenCL enabled for tests and add .exe to windows ci execu…
SteveBronder Jun 5, 2024
8bedcae
Merge remote-tracking branch 'refs/remotes/origin/feature/cmake-tests…
SteveBronder Jun 5, 2024
b2816c1
update linking options to not use generator expression for OpenCL
SteveBronder Jun 5, 2024
6490b79
test github action
SteveBronder Jun 6, 2024
b2be36e
test github action
SteveBronder Jun 6, 2024
542f636
test github action
SteveBronder Jun 6, 2024
58ee686
update
SteveBronder Jun 7, 2024
0224042
update
SteveBronder Jun 7, 2024
14a78f9
update
SteveBronder Jun 7, 2024
a549064
update
SteveBronder Jun 7, 2024
d0eae22
update
SteveBronder Jun 7, 2024
ad86bf0
update
SteveBronder Jun 8, 2024
a25224c
update
SteveBronder Jun 8, 2024
333988f
update
SteveBronder Jun 8, 2024
1b12e27
update
SteveBronder Jun 8, 2024
57c1710
use ctest in github actions instead of directly calling test
SteveBronder Jun 10, 2024
2ff8d50
Jenkins uses ctest
SteveBronder Jun 10, 2024
63b0ca6
use ctest for opencl
SteveBronder Jun 10, 2024
88632fd
use ctest for opencl
SteveBronder Jun 10, 2024
cde5c09
allow cmake to compile doxygen
SteveBronder Jun 10, 2024
82f5ab8
update test headers and tag for mix fun tests in windows
SteveBronder Jun 11, 2024
4004d23
adds inline to gpu util functions
SteveBronder Jun 11, 2024
10cf4ef
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 11, 2024
7fcb220
add inline to opencl kernel test functions
SteveBronder Jun 12, 2024
6e12385
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 12, 2024
0f9ff17
get mpi tests working locally
SteveBronder Jun 12, 2024
46933ba
Merge remote-tracking branch 'refs/remotes/origin/feature/cmake-tests…
SteveBronder Jun 12, 2024
59d1265
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 12, 2024
bfc4714
update mpi test for cpplint
SteveBronder Jun 12, 2024
b8ea220
update mpi test for cpplint
SteveBronder Jun 12, 2024
02b0ed6
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 12, 2024
dd5d1b9
update names of tests
SteveBronder Jun 12, 2024
2813c37
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 12, 2024
163cfae
fix boost download for timestamp
SteveBronder Jun 12, 2024
ddef41c
Merge remote-tracking branch 'refs/remotes/origin/feature/cmake-tests…
SteveBronder Jun 12, 2024
c162fdf
fix mpi links for cmake
SteveBronder Jun 12, 2024
0f0b0e5
have opencl use a gtest suite to cleanup the allocator between rev tests
SteveBronder Jun 18, 2024
7ed5c3f
Merge remote-tracking branch 'origin/develop' into feature/cmake-tests
SteveBronder Jun 18, 2024
1166b99
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 18, 2024
a5cf6a0
cpplint fixes
SteveBronder Jun 18, 2024
5c9de1c
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 18, 2024
54a3da2
cpplint fixes
SteveBronder Jun 18, 2024
b53e777
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 18, 2024
ecbf433
update jenkinsfile with cc and to report output on ctest error
SteveBronder Jun 18, 2024
e5f47d3
cleanup opencl and comment out device switching test
SteveBronder Jun 20, 2024
06fedf5
Merge remote-tracking branch 'refs/remotes/origin/feature/cmake-tests…
SteveBronder Jun 20, 2024
820c2d7
update
SteveBronder Jun 20, 2024
5f5dc74
[Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1
stan-buildbot Jun 20, 2024
52f6a79
comment out bad opencl test
SteveBronder Jun 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
70 changes: 18 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ jobs:
- name: Build Math libs
shell: powershell
run: |
make -f make/standalone math-libs -j2
make -f make/standalone math-libs -j4
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Run prim and rev unit tests
shell: powershell
run: |
python.exe runTests.py -j2 test/unit/*_test.cpp
python.exe runTests.py -j2 test/unit/math/*_test.cpp
python.exe runTests.py -j2 test/unit/math/prim
python.exe runTests.py -j2 test/unit/math/rev
python.exe runTests.py -j2 test/unit/math/memory
cmake -S . -B build -DCMAKE_BUILD_TYPE=RELEASE
cd build
make -j4 unit_math_prim_rev_subtests
cd test
ctest -R "unit_math_prim_rev"

- name: Upload gtest_output xml
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
- name: Build Math libs
shell: powershell
run: |
make -f make/standalone math-libs -j2
make -f make/standalone math-libs -j4
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
Expand All @@ -91,12 +91,11 @@ jobs:
- name: Run fwd unit tests and all the mix tests except those in mix/fun
shell: powershell
run: |
python.exe runTests.py test/unit/math/fwd -j2
python.exe runTests.py test/unit/math/mix/core -j2
python.exe runTests.py test/unit/math/mix/functor -j2
python.exe runTests.py test/unit/math/mix/meta -j2
python.exe runTests.py test/unit/math/mix/prob -j2
python.exe runTests.py test/unit/math/mix/*_test.cpp -j2
cmake -S . -B build -DCMAKE_BUILD_TYPE=RELEASE
cd build
make -j4 unit_math_fwd_nonfun_mix_subtests
cd test
ctest -R "unit_math_fwd_nonfun_mix"

- name: Upload gtest_output xml
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -126,17 +125,18 @@ jobs:
- name: Build Math libs
shell: powershell
run: |
make -f make/standalone math-libs -j2
make -f make/standalone math-libs -j4
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Run mix/fun unit tests
shell: powershell
run: |
$MixFunTests = Get-ChildItem -Path test\unit\math\mix\fun\* -Include *.cpp | Resolve-Path -Relative
$NumberTests = $MixFunTests.Length
$HalfNumberTests = [math]::Floor($NumberTests / 2)
python.exe runTests.py $MixFunTests[0..$HalfNumberTests]
cmake -S . -B build -DCMAKE_BUILD_TYPE=RELEASE
cd build
make -j4 test_unit_math_mix_fun
cd test
ctest -L "unit_math_mix_fun"

- name: Upload gtest_output xml
uses: actions/upload-artifact@v4
Expand All @@ -145,40 +145,6 @@ jobs:
name: gtest_outputs_xml
path: '**/*_test.xml'

mix-fun-2:
name: mix/fun tests 2
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: r-lib/actions/setup-r@v2
with:
r-version: 'release'
rtools-version: '44'

- name: Set path for Rtools44
if: runner.os == 'Windows'
run: echo "C:/rtools44/usr/bin;C:/rtools44/x86_64-w64-mingw32.static.posix/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8

- name: Build Math libs
shell: powershell
run: |
Add-Content make\local "O=1`n"
make -f make/standalone math-libs -j2
- name: Add TBB to PATH
shell: powershell
run: echo "D:/a/math/math/lib/tbb" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- name: Run mix/fun unit tests
shell: powershell
run: |
$MixFunTests = Get-ChildItem -Path test\unit\math\mix\fun\* -Include *.cpp | Resolve-Path -Relative
$NumberTests = $MixFunTests.Length
$HalfNumberTests = [math]::Floor($NumberTests / 2)
python.exe runTests.py $MixFunTests[($HalfNumberTests + 1)..($NumberTests - 1)]

- name: Upload gtest_output xml
uses: actions/upload-artifact@v4
if: failure()
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ benchmarks/*.csv
*.exe
*.a

#build directory
/build/**
# Intel template building blocks (TBB)
lib/tbb

Expand Down
236 changes: 236 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
cmake_minimum_required(VERSION 3.16.3)
project(
stanmath
VERSION 0.0.1
LANGUAGES C CXX)

include(FetchContent)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
set(CMAKE_VERBOSE_MAKEFILE YES)
cmake_policy(SET CMP0069 NEW)
# Configuration Options
option(STAN_BUILD_DOCS "Build the Stan Math library documentation" OFF)
option(STAN_TEST_HEADERS "Build the targets for the header checks" OFF)
option(STAN_NO_RANGE_CHECKS "Disable range checks within the Stan library" OFF)
option(STAN_MPI "Enable MPI support" OFF)
option(STAN_OPENCL "Enable OpenCL support" OFF)
set(STAN_OPENCL_DEVICE_ID "0" CACHE STRING "Set the OpenCL Device ID at compile time" FORCE)
set(STAN_OPENCL_PLATFORM_ID "0" CACHE STRING "Set the OpenCL Platform ID at compile time" FORCE)
set(STAN_INTEGRATED_OPENCL "0" CACHE STRING "Whether the platform and device can use integrated opencl features" FORCE)
message(STATUS "OpenCL Platform: " ${STAN_OPENCL_PLATFORM_ID})
message(STATUS "OpenCL Device: " ${STAN_OPENCL_DEVICE_ID})
option(STAN_THREADS "Enable multi-threading support" OFF)
if(STAN_NO_RANGE_CHECKS)
add_compile_definitions(STAN_NO_RANGE_CHECKS)
endif()
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()

# Set compiler flags
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-deprecated-declarations)
if(APPLE)
add_compile_options(-Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare)
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-Wno-sign-compare)
endif()

add_compile_options(
-DNO_FPRINTF_OUTPUT
-DBOOST_DISABLE_ASSERTS
-DTBB_INTERFACE_NEW
-D_REENTRANT
-Wno-deprecated-declarations
-Wall )

if(STAN_THREADS)
add_compile_definitions(STAN_THREADS)
endif()

if(STAN_MPI)
find_package(MPI REQUIRED)
add_compile_definitions(STAN_MPI)
add_compile_options(-Wno-delete-non-virtual-dtor)
endif()

# Handle OpenCL if necessary
if(STAN_OPENCL)
# Externally provided libraries
FetchContent_Declare(OpenCLHeaders
GIT_REPOSITORY https://github.com/KhronosGroup/OpenCL-CLHPP
GIT_TAG v2.0.15)
FetchContent_MakeAvailable(OpenCLHeaders)
find_package(OpenCL REQUIRED)
add_compile_definitions(STAN_OPENCL OPENCL_DEVICE_ID=${STAN_OPENCL_DEVICE_ID}
OPENCL_PLATFORM_ID=${STAN_OPENCL_PLATFORM_ID} CL_HPP_TARGET_OPENCL_VERSION=120
CL_HPP_MINIMUM_OPENCL_VERSION=120 CL_HPP_ENABLE_EXCEPTIONS INTEGRATED_OPENCL=${STAN_INTEGRATED_OPENCL})
add_compile_options(-Wno-ignored-attributes)

endif()

# Externally provided libraries
FetchContent_Declare(googletest
DOWNLOAD_EXTRACT_TIMESTAMP ON
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG main)
FetchContent_Declare(googlebenchmark
DOWNLOAD_EXTRACT_TIMESTAMP ON
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG main) # need master for benchmark::benchmark

FetchContent_MakeAvailable(googletest googlebenchmark)


if(STAN_USE_SYSTEM_TBB)
find_package(TBB REQUIRED)
else()
FetchContent_Declare(
tbb
DOWNLOAD_EXTRACT_TIMESTAMP ON
GIT_REPOSITORY https://github.com/oneapi-src/oneTBB
GIT_TAG v2021.7.0 # adjust this to the version you need
CMAKE_ARGS -DTBB_STRICT=OFF -DTBB_TEST=OFF
CMAKE_CACHE_ARGS -DTBB_STRICT:BOOL=OFF -DTBB_TEST:BOOL=OFF
)
FetchContent_GetProperties(tbb)
if(NOT tbb_POPULATED)
FetchContent_Populate(tbb)
# Add the fetched content to your build
set(TBB_STRICT OFF CACHE BOOL "Treat compiler warnings as errors")
add_subdirectory(${tbb_SOURCE_DIR} ${tbb_BINARY_DIR})
endif()
endif()
# For tbb
add_compile_options(-Wno-error -Wno-unused-value)
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()
if(STAN_USE_SYSTEM_EIGEN)
find_package(Eigen3 REQUIRED)
else()
set(EIGEN_BUILD_DOC OFF)
# note: To disable eigen tests,
# you should put this code in a add_subdirectory to avoid to change
# BUILD_TESTING for your own project too since variables are directory
# scoped
set(EIGEN_BUILD_BTL OFF)
set(EIGEN_BUILD_TESTING OFF)
set(EIGEN_BUILD_PKGCONFIG OFF)
set(EIGEN_LEAVE_TEST_IN_ALL_TARGET OFF)
FetchContent_Declare(
Eigen
DOWNLOAD_EXTRACT_TIMESTAMP ON
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0)
FetchContent_MakeAvailable(Eigen)
#TODO: Need to just put dependency file in subdirectory
# since macros are directory scoped
set(BUILD_TESTING ON)
set(EIGEN_BUILD_TESTING ON)
endif()

if (STAN_USE_SYSTEM_SUNDIALS)
find_package(SUNDIALS REQUIRED)
else()
FetchContent_Declare(
sundials
DOWNLOAD_EXTRACT_TIMESTAMP ON
GIT_REPOSITORY https://github.com/LLNL/sundials
GIT_TAG v6.1.1
# adjust this to the version you need
)
FetchContent_GetProperties(sundials)
if(NOT sundials_POPULATED)
FetchContent_Populate(sundials)
add_subdirectory(${sundials_SOURCE_DIR} ${sundials_BINARY_DIR})
endif()
endif()


if (STAN_USE_SYSTEM_BOOST)
find_package(Boost REQUIRED)
else()
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(BOOST_ENABLE_CMAKE ON)
set(BUILD_SHARED_LIBS OFF)
set(BOOST_DETAILED_CONFIGURE ON)
set(BOOST_ENABLE_PYTHON OFF)
set(BOOST_BUILD_TESTS OFF)
set(CMAKE_BUILD_TYPE Release)
set(BOOST_ENABLE_MPI ON)

set(BOOST_INCLUDE_LIBRARIES math numeric/odeint lexical_cast optional random mpi serialization)
FetchContent_Declare(
Boost
DOWNLOAD_EXTRACT_TIMESTAMP ON
URL https://github.com/boostorg/boost/releases/download/boost-1.85.0/boost-1.85.0-cmake.tar.xz
)
FetchContent_MakeAvailable(Boost)
endif()
# Library target
add_library(stanmath INTERFACE) # Assuming you only have headers
target_include_directories(stanmath INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)

# If you have sources, specify them and use add_library(stanmath SHARED or STATIC) instead

include(GNUInstallDirs)
install(DIRECTORY stan/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/stan)
install(TARGETS stanmath
EXPORT stanmathTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Export targets
install(EXPORT stanmathTargets
FILE stanmathTargets.cmake
NAMESPACE stanmath::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/stanmath)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"stanmathConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

install(FILES "stanmathConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/stanmathConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/stanmath)

# add docs
if (STAN_BUILD_DOCS)
find_package(Doxygen REQUIRED)

add_custom_target(
doxygen ALL
COMMAND mkdir -p doc/api
COMMAND
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/doxygen.cfg
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/pretty_stuff/eigen_navtree_hacks.js ${CMAKE_CURRENT_SOURCE_DIR}/doc/api/html/eigen_navtree_hacks.js
COMMENT "Generating API documentation with Doxygen"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
)
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(CheckIPOSupported)
check_ipo_supported(RESULT flto_support OUTPUT error LANGUAGES CXX)

# Becuase of bug with mingw
# lto1.exe: error: two or more sections for .gnu.lto__ZN4stan...
IF (NOT WIN32)
if(flto_support)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO/LTO is not supported: ${error}")
endif()
endif()
add_subdirectory(test)


Loading