1 #include "caffe2/core/logging.h" 2 #include "l2_minimization.h" 11 int main(
int argc,
const char* argv[]) {
13 cerr <<
"Usage: " << argv[0]
14 <<
" in_file out_file [preserve_sparsity] [precision]" << endl;
19 ofstream out(argv[2]);
20 bool preserve_sparsity = argc >= 4 ? atoi(argv[3]) : false;
21 int precision = argc >= 5 ? atoi(argv[4]) : 8;
23 vector<tuple<int, string, int, string>> infos;
24 vector<Histogram> hists;
27 while (getline(in, line)) {
28 istringstream ist(line);
30 int op_index, output_index;
31 string op_type, tensor_name;
35 ist >> op_index >> op_type >> output_index >> tensor_name >> min >> max >>
37 infos.push_back(tuple<int, string, int, string>(
38 op_index, op_type, output_index, tensor_name));
40 vector<uint64_t> bins;
41 for (
int i = 0; i < nbins; ++i) {
46 assert(bins.size() == nbins);
49 hists.emplace_back(min, max, bins);
52 vector<TensorQuantizationParams> qparams(hists.size());
54 #pragma omp parallel for 55 for (
int i = 0; i < hists.size(); ++i) {
57 hists[i], preserve_sparsity, precision);
60 for (
int i = 0; i < qparams.size(); ++i) {
61 out << std::get<0>(infos[i]) <<
" " << std::get<1>(infos[i]) <<
" " 62 << std::get<2>(infos[i]) <<
" " << std::get<3>(infos[i]) <<
" " 63 << qparams[i].Min() <<
" " << qparams[i].Max() << endl;
bin_width = (max - min)/nbins ith bin (zero-based indexing) contains [i*bin_width, (i+1)*bin_width) with an exception that (nbins - 1)th bin contains [(nbins-1)*bin_width, nbins*bin_width]