Configuration - Getting Information from the User
The behavior of DAPHNE can be influenced by the user by means of a cascading configuration mechanism.
There is a set of options that can be passed from the user to the system.
These options are collected in the DaphneUserConfig (src/api/cli/DaphneUserConfig.h).
The cascade consists of the following steps:
- The defaults of all options are hard-coded directly in the
DaphneUserConfig. - At program start-up, a configuration file is loaded, which overrides the defaults (WIP, #141).
- After that, command-line arguments further override the configuration (src/api/internal/daphne_internal.cpp).
- (In the future, DaphneDSL will also offer means to change the configuration at run-time.)
The DaphneUserConfig is available to all parts of the code, including:
- The DAPHNE compiler: The
DaphneUserConfigis passed to theDaphneIrExecutorand from there to all passes that need it. - The DAPHNE runtime: The
DaphneUserConfigis part of theDaphneContext, which is passed to all kernels.
Hence, information provided by the user can be used to influence both, the compiler and the runtime. The use of environment variables to pass information into the system is discouraged.
How to Extend the Configuration?
If you need to add additional information from the user, you must take roughly the following steps:
- Create a new member in
DaphneUserConfigand hard-code a reasonable default. - Add a command-line argument to the system's CLI API in src/api/internal/daphne_internal.cpp. We use LLVM's CommandLine 2.0 library for parsing CLI arguments. Make sure to update the corresponding member the
DaphneUserConfigwith the parsed argument. - For compiler passes: If necessary, pass on the
DaphneUserConfigto the compiler pass you are working on in src/compiler/execution/DaphneIrExecutor.cpp. For kernels: All kernels automatically get theDaphneUserConfigvia theDaphneContext(their last parameter), so no action is required from your side. - Access the new member of the
DaphneUserConfigin your code.