1 #ifndef BW_COMMON_H_ 2 #define BW_COMMON_H_ 3 4 /* This file gathers the parameters that are relevant to all BW 5 * programs -- most programs parse the corresponding values -- for some, 6 * the values are unused, which is not a lot to worry about. 7 */ 8 9 #include <gmp.h> 10 #include <stdio.h> 11 #include <stdint.h> // for uint32_t 12 #include "params.h" 13 14 /* relevant to secure.c as well ; really, this is almost a hard-coded 15 * constant. Don't imagine it's easily tunable. If one really insists, 16 * perhaps a u64k/secure or or m128/secure would work, but 17 * this has not been checked. */ 18 #define NCHECKS_CHECK_VECTOR_GF2 64 19 #define NCHECKS_CHECK_VECTOR_GFp 1 20 21 #define MAX_NUMBER_OF_CHECK_STOPS 32 22 23 struct bw_params { 24 25 /* m,n blocking factors as in the textbook BW description */ 26 int m,n; 27 28 /* We have 0<=nrhs<=n. This corresponds to solving inhomogeneous 29 * systems, but in reality we consider this parameter only when 30 * related to SM handling in the DL computation, when the SM blocks 31 * are part of the block Wiedemann starting vectors. This influences 32 * the number of columns which are shifted in the generator 33 * computation ("considering A(X) div X"), so that we force the 34 * computed relation to have non-zero coefficients for the SM columns 35 * (hence, not shifted in A(X)), while those corresponding to random 36 * vectors _are_ shifted. 37 * 38 * mksol and gather are also affected by this parameter. 39 * 40 * By default we have nrhs=0 41 */ 42 // we make this a phantom parameter. It's deduced from reading the 43 // rhs file, and we have no compelling need for allotting room for it 44 // in the global struct, given its rare use. 45 // int nrhs; 46 47 /* modulus */ 48 mpz_t p; 49 50 /* _at the moment_ this corresponds to the checking & checkpointing 51 * interval. Quite clearly, the two could be separated. 52 */ 53 int interval; 54 55 /* defined, but unused */ 56 int verbose; 57 58 /* Whether the current job/thread may print to stdout */ 59 int can_print; 60 61 /* This indicates the starting iteration -- only for krylov and mksol */ 62 int start; 63 int end; 64 65 /* 66 * relevant for krylov mostly, but not only. 67 * 68 * for krylov: indicates the coordinate range in [0..n[ that is 69 * relevant for us. ys[1]-ys[0] defines the ``local'' blocking factor 70 * n'. 71 * 72 * for dispatch: only the difference ys[1]-ys[0] is used, and fed as 73 * a parameter to the cache building routines (those have an interest 74 * in knowing the width of the vectors which will be worked on. 75 */ 76 int ys[2]; 77 78 /* for mksol and gather, indicate which sub-range of the solution 79 * space we intend to compute. This must be aligned on multiples of 80 * the quantity ys[1]-ys[0] derived from the supplied values ys. 81 */ 82 unsigned int solutions[2]; 83 84 /* dir is a boolean flag equal to 1 if we are looking for the right 85 * nullspace of the matrix. In matmul_top speak, it indicates where the 86 * source vector is. 87 */ 88 int dir; 89 90 /* secure, prep, and lingen are not deterministic. */ 91 int seed; 92 93 /* If enabled, do not check the intermediate results while running 94 * (the possibility of doing the checks offline still exists, 95 * though). This makes it possible to run krylov without having run 96 * the secure program first. 97 */ 98 int skip_online_checks; 99 100 /* If keep_rolling_checkpoints is defined to a positive integer X, 101 * keep only the last X vector checkpoints, and remove the others. 102 * Otherwise (if the parameter is zero), all checkpoints are kept. 103 * See also next parameter. 104 * 105 * Note that having skip_online_checks and keep_rolling_checkpoints 106 * at the same time is dangerous. 107 */ 108 int keep_rolling_checkpoints; 109 110 /* This moderates the previous behaviour. If a checkpoint to be 111 * discarded as per the previous flag turns out to have been 112 * modified less than X seconds ago, keep it anyway. 113 */ 114 int keep_checkpoints_younger_than; 115 116 /* In case the previous flag is enabled, still keep all the 117 * checkpoints which are multiple of the length given here. 118 */ 119 int checkpoint_precious; 120 121 /* The check_stops[] array contains the number of known check 122 * vectors, against which data is checked while running. 123 * Note that krylov and mksol store only one vector for the check 124 * stops, and do not afford storing many. This is of course to save 125 * memory. The secure program computes all requested check vectors. 126 * The yet-to-be-written offline check program checks against 127 * everything it can. 128 * 129 * The interval specified by the interval parameter is automatically 130 * counted as a check stop, unless skip_online_checks is true. 131 */ 132 int number_of_check_stops; 133 int check_stops[MAX_NUMBER_OF_CHECK_STOPS]; 134 135 int original_argc; 136 char ** original_argv; 137 138 double wct_base; 139 }; 140 141 extern struct bw_params bw[1]; 142 extern const char * bw_dirtext[]; 143 144 #ifdef __cplusplus 145 extern "C" { 146 #endif 147 148 /* Typical use pattern: 149 150 bw_common_init(bw, &argc, &argv); 151 param_list_init(pl); 152 153 bw_common_decl_usage(pl); 154 // more decl_usage functions. 155 156 bw_common_parse_cmdline(bw, pl, &argc, &argv); 157 158 bw_common_interpret_parameters(bw, pl); 159 // bw_common_cheat_parameter_lookup(pl); 160 // more interpret_parameters functions. 161 162 param_list_warn_unused(pl); 163 param_list_clear(pl); 164 165 // program ! 166 167 bw_common_clear(bw); 168 169 */ 170 171 void bw_common_decl_usage(param_list); 172 void bw_common_parse_cmdline(struct bw_params * bw, param_list pl, int * p_argc, char *** p_argv); 173 void bw_common_interpret_parameters(struct bw_params * bw, param_list pl); 174 int bw_common_init(struct bw_params * bw, int * p_argc, char *** p_argv); 175 int bw_common_clear(struct bw_params * bw); 176 177 178 /* utility function. */ 179 extern int get_rhs_file_header(const char * filename, uint32_t * p_nrows, unsigned int * p_nrhs, mpz_ptr p_p); 180 extern int get_rhs_file_header_stream(FILE * f, uint32_t * p_nrows, unsigned int * p_nrhs, mpz_ptr p_p); 181 182 extern unsigned int bw_set_length_and_interval_krylov(struct bw_params * bw, unsigned int dims[2]); 183 extern unsigned int bw_set_length_and_interval_mksol(struct bw_params * bw, unsigned int dims[2]); 184 #ifdef __cplusplus 185 } 186 #endif 187 188 #endif /* BW_COMMON_H_ */ 189