From ebfd4e06b60f1da57c55b956c7c6a712484f5572 Mon Sep 17 00:00:00 2001 From: hashimsharif <hashim.sharif91@gmail.com> Date: Thu, 11 Jun 2020 21:45:50 -0500 Subject: [PATCH] Fixing global_knobs.txt path - make it relative to LLVM_SRC_ROOT --- .../tensor_runtime/src/approx_knobs_utils.cc | 112 ++++++++++++------ 1 file changed, 78 insertions(+), 34 deletions(-) diff --git a/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/approx_knobs_utils.cc b/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/approx_knobs_utils.cc index c4f5f484cc..35278b763e 100644 --- a/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/approx_knobs_utils.cc +++ b/llvm/projects/hpvm-tensor-rt/tensor_runtime/src/approx_knobs_utils.cc @@ -4,6 +4,7 @@ #include <fstream> #include <map> #include <vector> +#include <string.h> #include "approx_knob_utils.h" @@ -24,8 +25,22 @@ PerfParams::PerfParams(int row1, int col1, int skip_offset1){ PerfParamSet::PerfParamSet(){ - - std::ifstream file("../autotuner/data/global_knobs.txt"); + + char llvm_src_root[100]; + strcpy(llvm_src_root, getenv("LLVM_SRC_ROOT")); + + if (llvm_src_root == NULL){ + + printf("ERROR: SET LLVM_SRC_ROOT \n"); + abort(); + } + + printf ("*LLVM_SRC_ROOT = %s", llvm_src_root); + + char* knobs_file_path = strcat(llvm_src_root, "/projects/hpvm-tensor-rt/autotuner/data/global_knobs.txt"); + printf ("- knobs_file_path = %s \n", knobs_file_path); + + std::ifstream file(knobs_file_path); std::string line; std::string partial; @@ -33,6 +48,8 @@ PerfParamSet::PerfParamSet(){ while(std::getline(file, line)) { // Read each line + printf ("***** line === ", line); + std::istringstream iss(line); std::string token; while(std::getline(iss, token, '\t')){ // Read each token in the line @@ -58,7 +75,8 @@ PerfParamSet::PerfParamSet(){ std::getline(token_stream, tok, ','); int offset = atoi(tok.c_str()); - + + printf ("**** knob = %d, row = %d, col = %d, offset = %d \n\n", knob, row, col, offset); PerfParams params(row, col, offset); perf_knob_map[knob] = params; @@ -66,11 +84,16 @@ PerfParamSet::PerfParamSet(){ } } - + + file.close(); } PerfParams PerfParamSet::getPerfParams(int swing){ + + if (swing >= 150){ + swing = swing - 30; + } return perf_knob_map[swing]; @@ -94,58 +117,79 @@ SampParams::SampParams(int skip_rate1, int skip_offset1, float interpolation_id1 SampParamSet::SampParamSet(){ - std::ifstream file("../autotuner/data/global_knobs.txt"); + char llvm_src_root[100]; + strcpy(llvm_src_root, getenv("LLVM_SRC_ROOT")); + + if (llvm_src_root == NULL){ + + printf("ERROR: SET LLVM_SRC_ROOT \n"); + abort(); + } + + printf ("* LLVM_SRC_ROOT = %s \n", llvm_src_root); - std::string line; - std::string partial; - std::vector<std::string> tokens; + char* knobs_file_path = strcat(llvm_src_root, "/projects/hpvm-tensor-rt/autotuner/data/global_knobs.txt"); + printf ("- knobs_file_path = %s \n", knobs_file_path); + + std::ifstream file(knobs_file_path); - while(std::getline(file, line)) { // Read each line + std::string line; + std::string partial; + std::vector<std::string> tokens; + + while(std::getline(file, line)) { // Read each line - std::istringstream iss(line); - std::string token; - while(std::getline(iss, token, '\t')){ // Read each token in the line - tokens.push_back(token); + std::istringstream iss(line); + std::string token; + while(std::getline(iss, token, '\t')){ // Read each token in the line + tokens.push_back(token); - int index = token.find("samp"); - int test_index = token.find("reduction"); + int index = token.find("samp"); + int test_index = token.find("reduction"); - if (index != std::string::npos && test_index == std::string::npos){ + if (index != std::string::npos && test_index == std::string::npos){ - int index2 = token.find(","); - std::string knob_str = token.substr(index2 + 1); - int knob = atoi(knob_str.c_str()); - printf ("knob = %d \n", knob); + int index2 = token.find(","); + std::string knob_str = token.substr(index2 + 1); + int knob = atoi(knob_str.c_str()); + printf ("knob = %d \n", knob); - std::getline(iss, token, '\t'); - std::istringstream token_stream(token); + std::getline(iss, token, '\t'); + std::istringstream token_stream(token); - std::string tok; + std::string tok; - std::getline(token_stream, tok, ','); - int skip_every = atoi(tok.c_str()); + std::getline(token_stream, tok, ','); + int skip_every = atoi(tok.c_str()); - std::getline(token_stream, tok, ','); - int offset = atoi(tok.c_str()); + std::getline(token_stream, tok, ','); + int offset = atoi(tok.c_str()); - std::getline(token_stream, tok, ','); - float interpolation_id = atof(tok.c_str()); + std::getline(token_stream, tok, ','); + float interpolation_id = atof(tok.c_str()); - printf ("skip_every = %d, offset = %d \n", skip_every, offset); - SampParams params(skip_every, offset, interpolation_id); - samp_knob_map[knob] = params; + printf ("skip_every = %d, offset = %d \n", skip_every, offset); + SampParams params(skip_every, offset, interpolation_id); + samp_knob_map[knob] = params; - } - } + } + } + + file.close(); + } SampParams SampParamSet::getSampParams(int swing){ + if (swing >= 260){ + swing = swing - 30; + } + return samp_knob_map[swing]; } -- GitLab