diff options
| author | Jonathan <[email protected]> | 2018-06-21 17:35:07 -0700 |
|---|---|---|
| committer | Jonathan <[email protected]> | 2018-06-21 17:35:07 -0700 |
| commit | 76a124e9186b9574858238d423b9c5ce715f2c32 (patch) | |
| tree | 0e1c3a82661f06baafbf9505b216ef94ab3cbc91 /src/cuda-sim/cuda-sim.cc | |
| parent | 37dc5311a75548b848a33a3b7369ce4bee64b444 (diff) | |
WIP adding support for PTX JIT and dumping params to cudaLaunches
Diffstat (limited to 'src/cuda-sim/cuda-sim.cc')
| -rw-r--r-- | src/cuda-sim/cuda-sim.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index 34368ce..6875edd 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -1226,6 +1226,87 @@ void function_info::list_param( FILE *fout ) const fflush(fout); } +void function_info::debug_param( ) const +{ + char filename[] = "params.txt"; + char buff[1024]; + snprintf(buff,1024,"c++filt %s > %s", get_name().c_str(), filename); + system(buff); + FILE *fp = fopen(filename, "r"); + fgets(buff, 1024, fp); + fclose(fp); + + std::string fn(buff); + size_t pos1, pos2; + pos1 = fn.find("("); + pos2 = fn.find(")"); + assert(pos2>pos1&&pos1>0); + strcpy(buff, fn.substr(pos1 + 1, pos2 - pos1 - 1).c_str()); + printf("params: %s\n", buff); + char *tok; + std::vector<std::string> params; + tok = strtok(buff, ","); + while(tok!=NULL){ + std::string param(tok); + param.erase(0, param.find_first_not_of(" ")); + param.erase(param.find_last_not_of(" ")+1); + params.push_back(param); + tok = strtok(NULL, ","); + } + for (auto const& it : params){ + std::cout<<it<<std::endl; + } + + FILE *fout = fopen (filename, "w"); + fprintf(fout, "Name of function:%s\n", fn.c_str()); + + for( std::map<unsigned,param_info>::const_iterator i=m_ptx_kernel_param_info.begin(); i!=m_ptx_kernel_param_info.end(); i++ ) { + const param_info &p = i->second; + std::string name = p.get_name(); + param_t param_value = p.get_value(); + if(params[i->first].find("const")!=std::string::npos){ + fprintf(fout, "Input: "); + } else { + fprintf(fout, "Input/output: "); + } + + symbol *param = m_symtab->lookup(name.c_str()); + addr_t param_addr = param->get_address(); + fprintf(fout, "%s: %#08x, ", name.c_str(), param_addr); + + if(params[i->first].find("int")!=std::string::npos){ + size_t len = param_value.size/sizeof(int); + int val[len]; + memcpy((void*) val, param_value.pdata+param_value.offset, param_value.size); + fprintf(fout, "val (int) = "); + for (unsigned i = 0; i<len; i++){ + fprintf(fout, "%d ", val[i]); + } + fprintf(fout, "\n"); + } else if(params[i->first].find("float")!=std::string::npos){ + size_t len = param_value.size/sizeof(float); + float val[len]; + memcpy((void*) val, param_value.pdata+param_value.offset, param_value.size); + fprintf(fout, "val (float) = "); + for (unsigned i = 0; i<len; i++){ + fprintf(fout, "%f ", val[i]); + } + fprintf(fout, "\n"); + }else{ + size_t len = param_value.size/sizeof(char); + char val[len]; + memcpy((void*) val, param_value.pdata+param_value.offset, param_value.size); + fprintf(fout, "val (char) = "); + for (unsigned i = 0; i<len; i++){ + fprintf(fout, "%c ", val[i]); + } + fprintf(fout, "\n"); + } + } + fflush(fout); + fclose(fout); +} + template<int activate_level> bool ptx_debug_exec_dump_cond(int thd_uid, addr_t pc) { |
