stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
751 stars 188 forks source link

Improve compile time configuration #1287

Open wds15 opened 5 years ago

wds15 commented 5 years ago

Description

We are having an increasing number of optional features in Stan-math. At the moment these are OpenCL, MPI and threading. Moreover, there are sometimes choices to make at compile time which should be kept optional rather than hard-coded in the code.

Right now we basically configure these compile time things using our makefiles in make/local. Unfortunately this is also somewhat inconsistent for the different features. While for MPI we define a makefile variable STAN_MPI=true we have simple defines for the others (ok, there is a reason for this which is that MPI needs more bells and whistles to go live as I recall).

Example

We should have better ways to control compile time options. Many other projects define config headers. Boost has this and sundials has it as well. Given how Stan-math grows we should probably have a similar facility.

Oftentimes these config.hpp files have defaults which work in many cases, but sometimes these files are generated from tools like cmake or automake which adapt the config file to the available things on the target system.

Expected Output

Better and more flexible way of setting compile time options. We should also rethink how much we want to control by makefiles vs the config.hpp (or whatever we come up with).

Current Version:

v2.20.0

rok-cesnovar commented 5 years ago

+1

Having something like a config file where a user just changes the value of a flag to use some feature is also much better than saying add XYZW=true to make/local. That reason alone make this worthwhile to me.

For instance I use OpenCL all the time but keep having to go to a wiki page to see the exact names of certain flags. But that might just be me being forgetful.

SteveBronder commented 5 years ago

exact names of certain flags. But that might just be me being forgetful.

Same tbh

alashworth commented 5 years ago

You might be interested in my CMake-ified stan-math build, it is located here: https://github.com/alashworth/stan-monorepo/blob/develop/CMakeLists.txt

I basically handle this use-case by defining separate targets for the four main Stan math use cases: vanilla Stan, Stan + OpenCL, Stan + OpenMPI, Stan + multithreading.

If the user is also using CMake, it is trivial to link against them. Configuration is done automatically via find_package calls and settings specific CMake options.

alashworth commented 5 years ago

This is actually only part of an entire monorepo that merges Stan, Stan Math, and Cmdstan; bits are missing from the public repo because I'm in a long rebase process of moving onto Stan 2.20. However, Stan and Cmdstan should appear within the next week or so, and I will make an announcement on Discourse.

SteveBronder commented 5 years ago

I looked over the readme and the stuff you have going on (and issues you found) in the monorepo and it is absolutely fantastic!