1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::env;
use config::{Config, ConfigError, Environment, File};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
lazy_static! {
pub static ref SETTINGS: Settings = Settings::new().expect("invalid configuration");
}
const SETTINGS_PATH: &str = "./rust-fil-proofs.config.toml";
const PREFIX: &str = "FIL_PROOFS";
#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Settings {
pub verify_cache: bool,
pub verify_production_params: bool,
pub use_gpu_column_builder: bool,
pub max_gpu_column_batch_size: u32,
pub column_write_batch_size: u32,
pub use_gpu_tree_builder: bool,
pub max_gpu_tree_batch_size: u32,
pub rows_to_discard: u32,
pub sdr_parents_cache_size: u32,
pub window_post_synthesis_num_cpus: u32,
pub parameter_cache: String,
pub parent_cache: String,
pub use_multicore_sdr: bool,
pub multicore_sdr_producers: usize,
pub multicore_sdr_producer_stride: u64,
pub multicore_sdr_lookahead: usize,
}
impl Default for Settings {
fn default() -> Self {
Settings {
verify_cache: false,
verify_production_params: false,
use_gpu_column_builder: false,
max_gpu_column_batch_size: 400_000,
column_write_batch_size: 262_144,
use_gpu_tree_builder: false,
max_gpu_tree_batch_size: 700_000,
rows_to_discard: 2,
sdr_parents_cache_size: 2_048,
window_post_synthesis_num_cpus: num_cpus::get() as u32,
parameter_cache: "/var/tmp/filecoin-proof-parameters/".to_string(),
parent_cache: cache("filecoin-parents"),
use_multicore_sdr: false,
multicore_sdr_producers: 3,
multicore_sdr_producer_stride: 128,
multicore_sdr_lookahead: 800,
}
}
}
fn cache(s: &str) -> String {
let cache_var = format!("{}_CACHE_DIR", PREFIX);
let mut cache_name = env::var(cache_var).unwrap_or_else(|_| "/var/tmp/".to_string());
cache_name.push_str(s);
cache_name
}
fn set_env_var_if_unset(env_var: &str, value: &str) {
if env::var(env_var).is_err() {
env::set_var(env_var, value);
}
}
fn set_gpu_framework() {
if let Ok(framework) = env::var(format!("{}_GPU_FRAMEWORK", PREFIX)) {
set_env_var_if_unset("BELLMAN_GPU_FRAMEWORK", &framework);
set_env_var_if_unset("NEPTUNE_GPU_FRAMEWORK", &framework);
}
}
impl Settings {
fn new() -> Result<Settings, ConfigError> {
set_gpu_framework();
let mut s = Config::new();
s.merge(File::with_name(SETTINGS_PATH).required(false))?;
s.merge(Environment::with_prefix(PREFIX))?;
s.try_into()
}
}