Skip to content
Snippets Groups Projects
Commit e4debb92 authored by Hashim Sharif's avatar Hashim Sharif
Browse files

Loading approx metrics - InsertApproxInfo pass

parent 2c3681f8
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,8 @@
#include <unordered_map>
#include <dirent.h>
#include <stdio.h>
#include <sstream>
#include <fstream>
using namespace llvm;
......@@ -71,6 +73,8 @@ private:
void codeGen(DFInternalNode* N);
void codeGen(DFLeafNode* N);
void loadTrainedApproxMetrics(std::string dir_path);
void loadMetricsFromFile(std::string dir_path, std::string file_path);
void readApproxValues(const std::string line, ApproxMetrics* approx_metrics);
// private data
std::unordered_map<std::string, std::vector<ApproxMetrics*>> operation_metrics;
......@@ -108,11 +112,72 @@ bool InsertApproxInfoWrapperPass::runOnModule(Module &M) {
}
void InsertApproxInfo::readApproxValues(const std::string line, ApproxMetrics* approx_metrics){
std::istringstream in(line);
std::string op_name;
float approx_level;
float mean_l1;
float mean_l2;
float mean_linf;
float relative_l1;
float relative_l2;
float relative_linf;
in >> op_name;
in >> approx_level;
in >> mean_l1;
in >> mean_l2;
in >> mean_linf;
in >> relative_l1;
in >> relative_l2;
in >> relative_linf;
printf("\n *** op_name = %s \n", op_name.c_str());
printf("approx_level = %f \n", approx_level);
printf("relative_l1 = %f \n", relative_l1);
printf("relative_l2 = %f \n", relative_l2);
printf("relative_linf = %f \n", relative_linf);
printf("mean_l1 = %f \n", mean_l1);
printf("mean_l2 = %f \n", mean_l2);
printf("mean_linf = %f \n", mean_linf);
}
void InsertApproxInfo::loadMetricsFromFile(std::string dir_path, std::string file_path){
std::string full_path = dir_path + "/" + file_path;
printf("full_path = %s \n", full_path.c_str());
std::ifstream infile(full_path.c_str());
std::string line;
unsigned int it_count = 0;
while(std::getline(infile, line)){
// Skip first line with confidence information
if(it_count > 0){
std::vector<float> approx_values;
ApproxMetrics* approx_metrics = new ApproxMetrics;
readApproxValues(line, approx_metrics);
}
it_count++;
}
}
void InsertApproxInfo::loadTrainedApproxMetrics(std::string dir_path){
struct dirent* entry;
dir_path += "/high_confidence";
DIR* dir = opendir(dir_path.c_str());
if(dir == NULL){
printf("Directory %s not found . Aborting ... \n\n ", dir_path.c_str());
......@@ -120,7 +185,9 @@ void InsertApproxInfo::loadTrainedApproxMetrics(std::string dir_path){
}
while((entry = readdir(dir)) != NULL){
printf("%s \n", entry->d_name);
printf("f_name = %s \n", entry->d_name);
std::string f_name = entry->d_name;
loadMetricsFromFile(dir_path, f_name);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment