summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTor Aamodt <[email protected]>2010-07-17 10:29:05 -0800
committerTor Aamodt <[email protected]>2010-07-17 10:29:05 -0800
commitd3d0b38b90f14660ecb6243373daa921f8ae02b1 (patch)
tree9211056ccf334f37babafcecc662400bc42d278b /src
parent9b43d5685c269331ea6d15fe3ed0dade063a798a (diff)
integrating Wilson's bugfixes from release branch
[git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6869]
Diffstat (limited to 'src')
-rw-r--r--src/cuda-sim/cuda-sim.cc98
-rw-r--r--src/cuda-sim/instructions.cc136
-rw-r--r--src/cuda-sim/memory.cc13
-rw-r--r--src/cuda-sim/memory.h19
-rw-r--r--src/cuda-sim/ptx-stats.cc18
-rw-r--r--src/cuda-sim/ptx_ir.cc2
-rw-r--r--src/cuda-sim/ptx_ir.h72
-rw-r--r--src/cuda-sim/ptx_sim.cc22
-rw-r--r--src/cuda-sim/ptx_sim.h30
-rw-r--r--src/gpgpu-sim/histogram.h1
-rw-r--r--src/gpgpu-sim/stat-tool.cc14
11 files changed, 256 insertions, 169 deletions
diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc
index 705a80a..f7b127c 100644
--- a/src/cuda-sim/cuda-sim.cc
+++ b/src/cuda-sim/cuda-sim.cc
@@ -994,7 +994,7 @@ unsigned function_info::ptx_get_inst_op( ptx_thread_info *thread )
return ALU_OP;
}
-void function_info::add_param_name_and_type( unsigned index, std::string name, int type )
+void function_info::add_param_name_type_size( unsigned index, std::string name, int type, size_t size )
{
unsigned parsed_index;
char buffer[2048];
@@ -1002,10 +1002,10 @@ void function_info::add_param_name_and_type( unsigned index, std::string name, i
int ntokens = sscanf(name.c_str(),buffer,&parsed_index);
if( ntokens == 1 ) {
assert( m_ptx_param_info.find(parsed_index) == m_ptx_param_info.end() );
- m_ptx_param_info[parsed_index] = param_info(parsed_index,name,type);
+ m_ptx_param_info[parsed_index] = param_info(parsed_index, name, type, size);
} else {
assert( m_ptx_param_info.find(index) == m_ptx_param_info.end() );
- m_ptx_param_info[index] = param_info(index,name,type);
+ m_ptx_param_info[index] = param_info(index, name, type, size);
}
}
@@ -1015,7 +1015,9 @@ void function_info::add_param_data( unsigned argn, struct gpgpu_ptx_sim_arg *arg
param_t tmp;
if( data ) {
- memcpy(&tmp.data,data,args->m_nbytes);
+ tmp.pdata = args->m_start;
+ tmp.size = args->m_nbytes;
+ tmp.offset = args->m_offset;
std::map<unsigned,param_info>::iterator i=m_ptx_param_info.find(argn);
if( i != m_ptx_param_info.end()) {
i->second.add_data(tmp);
@@ -1047,6 +1049,48 @@ void function_info::add_param_data( unsigned argn, struct gpgpu_ptx_sim_arg *arg
}
}
+void function_info::finalize( memory_space *param_mem, symbol_table *symtab )
+{
+ unsigned param_address = 0;
+ for( std::map<unsigned,param_info>::iterator i=m_ptx_param_info.begin(); i!=m_ptx_param_info.end(); i++ ) {
+ param_info &p = i->second;
+ std::string name = p.get_name();
+ int type = p.get_type();
+ param_t param_value = p.get_value();
+ param_value.type = type;
+ symbol *param = symtab->lookup(name.c_str());
+ unsigned xtype = param->type()->get_key().scalar_type();
+ assert(xtype==(unsigned)type);
+ size_t size;
+ size = param_value.size; // size of param in bytes
+ assert(param_value.offset == param_address);
+ assert(size == p.get_size() / 8);
+ // copy the parameter over word-by-word so that parameter that crosses a memory page can be copied over
+ const size_t word_size = 4;
+ for (size_t idx = 0; idx < size; idx += word_size) {
+ const char *pdata = reinterpret_cast<const char*>(param_value.pdata) + idx; // cast to char * for ptr arithmetic
+ param_mem->write(param_address + idx, word_size, pdata);
+ }
+ param->set_address(param_address);
+ param_address += size;
+ }
+}
+
+void function_info::list_param( FILE *fout ) const
+{
+ symbol_table *symtab = g_current_symbol_table;
+ for( std::map<unsigned,param_info>::const_iterator i=m_ptx_param_info.begin(); i!=m_ptx_param_info.end(); i++ ) {
+ const param_info &p = i->second;
+ std::string name = p.get_name();
+ symbol *param = symtab->lookup(name.c_str());
+
+ addr_t param_addr = param->get_address();
+
+ fprintf(fout, "%s: %#08x\n", name.c_str(), param_addr);
+ }
+ fflush(fout);
+}
+
template<int activate_level>
bool ptx_debug_exec_dump_cond(int thd_uid, addr_t pc)
{
@@ -1112,10 +1156,13 @@ void function_info::ptx_exec_inst( ptx_thread_info *thread,
g_current_symbol_table = thread->get_finfo()->get_symtab();
thread->clearRPC();
thread->m_last_set_operand_value.u64 = 0;
- *space = -1;
- *addr = 0xFEEBDAED;
- thread->clear_modifiedregs();
+ if ( g_debug_execution >= 6 ) {
+ if ( (g_debug_thread_uid==0) || (thread->get_uid() == (unsigned)g_debug_thread_uid) ) {
+ thread->clear_modifiedregs();
+ thread->enable_debug_trace();
+ }
+ }
if( pI->has_pred() ) {
const operand_info &pred = pI->get_pred();
ptx_reg_t pred_value = thread->get_operand_value(pred);
@@ -1147,38 +1194,32 @@ void function_info::ptx_exec_inst( ptx_thread_info *thread,
fflush(stdout);
}
- *data_size = 0;
- if ( (pI->get_opcode() == LD_OP || pI->get_opcode() == ST_OP) ) {
- *addr = thread->last_eaddr();
- *space = thread->last_space();
+ addr_t insn_memaddr = 0xFEEBDAED;
+ unsigned insn_space = -1;
+ unsigned insn_data_size = 0;
+ if ( pI->get_opcode() == LD_OP || pI->get_opcode() == ST_OP || pI->get_opcode() == TEX_OP ) {
+ insn_memaddr = thread->last_eaddr();
+ insn_space = thread->last_space();
unsigned to_type = pI->get_type();
- *data_size = datatype2size(to_type);
+ insn_data_size = datatype2size(to_type);
}
if ( pI->get_opcode() == ATOM_OP ) {
- *addr = thread->last_eaddr();
- *space = thread->last_space();
+ insn_memaddr = thread->last_eaddr();
+ insn_space = thread->last_space();
callback->function = thread->last_callback().function;
callback->instruction = thread->last_callback().instruction;
callback->thread = thread;
unsigned to_type = pI->get_type();
- *data_size = datatype2size(to_type);
+ insn_data_size = datatype2size(to_type);
} else {
// make sure that the callback isn't set
callback->function = NULL;
callback->instruction = NULL;
}
- if (pI->get_opcode() == TEX_OP) {
- *addr = thread->last_eaddr();
- *space = thread->last_space();
-
- unsigned to_type = pI->get_type();
- *data_size = datatype2size(to_type);
- }
-
if ( g_debug_execution >= 6 ) {
if ( ptx_debug_exec_dump_cond<6>(thread->get_uid(), pc) )
thread->dump_modifiedregs();
@@ -1214,6 +1255,11 @@ void function_info::ptx_exec_inst( ptx_thread_info *thread,
g_ptx_sim_num_insn, ctaid.x,ctaid.y,ctaid.z,tid.x,tid.y,tid.z );
fflush(stdout);
}
+
+ // "Return values"
+ *space = insn_space;
+ *addr = insn_memaddr;
+ *data_size = insn_data_size;
}
unsigned g_gx, g_gy, g_gz;
@@ -1458,6 +1504,12 @@ void gpgpu_ptx_sim_init_grid( const char *kernel_key, struct gpgpu_ptx_sim_arg*
if ( g_host_to_kernel_entrypoint_name_lookup->find(kernel_key) ==
g_host_to_kernel_entrypoint_name_lookup->end() ) {
printf("GPGPU-Sim PTX: ERROR ** cannot locate PTX entry point\n" );
+ printf("GPGPU-Sim PTX: existing entry points: \n");
+ std::map<const void*,std::string>::iterator i_eptr = g_host_to_kernel_entrypoint_name_lookup->begin();
+ for (; i_eptr != g_host_to_kernel_entrypoint_name_lookup->end(); ++i_eptr) {
+ printf("GPGPU-Sim PTX: (%p,%s)\n", i_eptr->first, i_eptr->second.c_str());
+ }
+ printf("\n");
abort();
} else {
std::string kname = (*g_host_to_kernel_entrypoint_name_lookup)[kernel_key];
diff --git a/src/cuda-sim/instructions.cc b/src/cuda-sim/instructions.cc
index 60ff83d..4e82787 100644
--- a/src/cuda-sim/instructions.cc
+++ b/src/cuda-sim/instructions.cc
@@ -99,10 +99,11 @@ unsigned unfound_register_warned = 0;
ptx_reg_t ptx_thread_info::get_operand_value( const symbol *reg )
{
- assert( reg->type()->get_key().is_reg() );
- const std::string &name = reg->name();
- std::map<std::string,ptx_reg_t>::iterator regs_iter = m_regs.back().find(name);
+ // assume that the given symbol is a register and try to find it in the register hash map
+ reg_map_t::iterator regs_iter = m_regs.back().find(reg);
if (regs_iter == m_regs.back().end()) {
+ assert( reg->type()->get_key().is_reg() );
+ const std::string &name = reg->name();
unsigned call_uid = m_callstack.back().m_call_uid;
ptx_reg_t uninit_reg;
uninit_reg.u32 = 0xDEADBEEF;
@@ -113,14 +114,14 @@ ptx_reg_t ptx_thread_info::get_operand_value( const symbol *reg )
file_loc.c_str(), name.c_str(), call_uid );
unfound_register_warned = 1;
}
- regs_iter = m_regs.back().insert(std::make_pair(name, uninit_reg)).first;
+ regs_iter = m_regs.back().find(reg);
}
return regs_iter->second;
}
ptx_reg_t ptx_thread_info::get_operand_value( const operand_info &op )
{
- ptx_reg_t result, tmp;
+ ptx_reg_t result;
const char *name = NULL;
if ( op.is_reg() ) {
result = get_operand_value( op.get_symbol() );
@@ -134,10 +135,10 @@ ptx_reg_t ptx_thread_info::get_operand_value( const operand_info &op )
if ( info.is_reg() ) {
name = op.name().c_str();
- std::map<std::string,ptx_reg_t>::iterator regs_iter = m_regs.back().find(name);
+ reg_map_t::iterator regs_iter = m_regs.back().find(sym);
assert( regs_iter != m_regs.back().end() );
- tmp = regs_iter->second;
- result.u64 = tmp.u64 + op.get_addr_offset();
+ ptx_reg_t baseaddr = regs_iter->second;
+ result.u64 = baseaddr.u64 + op.get_addr_offset();
} else if ( info.is_param() ) {
result = sym->get_address() + op.get_addr_offset();
} else if ( info.is_global() ) {
@@ -207,26 +208,15 @@ unsigned get_operand_nbits( const operand_info &op )
void ptx_thread_info::get_vector_operand_values( const operand_info &op, ptx_reg_t* ptx_regs, unsigned num_elements )
{
- const char *name1, *name2, *name3, *name4 = NULL;
- if ( op.is_vector() ) {
- if (num_elements > 3) {
- name4 = op.vec_name4().c_str();
- assert( m_regs.back().find(name4) != m_regs.back().end() );
- ptx_regs[3] = m_regs.back()[ name4 ];
- }
- if (num_elements > 2) {
- name3 = op.vec_name3().c_str();
- assert( m_regs.back().find(name3) != m_regs.back().end() );
- ptx_regs[2] = m_regs.back()[ name3 ];
- }
- name1 = op.vec_name1().c_str();
- name2 = op.vec_name2().c_str();
- assert( m_regs.back().find(name1) != m_regs.back().end() );
- assert( m_regs.back().find(name2) != m_regs.back().end() );
- ptx_regs[0] = m_regs.back()[ name1 ];
- ptx_regs[1] = m_regs.back()[ name2 ];
- } else {
- assert(0);
+ assert( op.is_vector() );
+ assert( num_elements <= 4 ); // max 4 elements in a vector
+
+ for (int idx = num_elements - 1; idx >= 0; --idx) {
+ const symbol *sym = NULL;
+ sym = op.vec_symbol(idx);
+ reg_map_t::iterator reg_iter = m_regs.back().find(sym);
+ assert( reg_iter != m_regs.back().end() );
+ ptx_regs[idx] = reg_iter->second;
}
}
@@ -254,15 +244,19 @@ void sign_extend( ptx_reg_t &data, unsigned src_size, const operand_info &dst )
void ptx_thread_info::set_operand_value( const operand_info &dst, const ptx_reg_t &data )
{
- m_regs.back()[ dst.name() ] = data;
- m_debug_trace_regs_modified.back()[ dst.name() ] = data;
+ m_regs.back()[ dst.get_symbol() ] = data;
+ if (m_enable_debug_trace ) {
+ m_debug_trace_regs_modified[ dst.get_symbol() ] = data;
+ }
m_last_set_operand_value = data;
}
void ptx_thread_info::set_operand_value( const symbol *dst, const ptx_reg_t &data )
{
- m_regs.back()[ dst->name() ] = data;
- m_debug_trace_regs_modified.back()[ dst->name() ] = data;
+ m_regs.back()[ dst ] = data;
+ if (m_enable_debug_trace ) {
+ m_debug_trace_regs_modified[ dst ] = data;
+ }
m_last_set_operand_value = data;
}
@@ -273,18 +267,15 @@ void ptx_thread_info::set_vector_operand_values( const operand_info &dst,
const ptx_reg_t &data4,
unsigned num_elements )
{
- m_regs.back()[ dst.vec_name1() ] = data1;
- m_debug_trace_regs_modified.back()[ dst.vec_name1() ] = data1;
- m_regs.back()[ dst.vec_name2() ] = data2;
- m_debug_trace_regs_modified.back()[ dst.vec_name2() ] = data2;
+ set_operand_value(dst.vec_symbol(0), data1);
+ set_operand_value(dst.vec_symbol(1), data2);
if (num_elements > 2) {
- m_regs.back()[ dst.vec_name3() ] = data3;
- m_debug_trace_regs_modified.back()[ dst.vec_name3() ] = data3;
+ set_operand_value(dst.vec_symbol(2), data3);
if (num_elements > 3) {
- m_regs.back()[ dst.vec_name4() ] = data4;
- m_debug_trace_regs_modified.back()[ dst.vec_name4() ] = data4;
+ set_operand_value(dst.vec_symbol(3), data4);
}
}
+
m_last_set_operand_value = data1;
}
@@ -2743,13 +2734,44 @@ float reduce_precision( float x, unsigned bits )
return result;
}
-unsigned wrap( unsigned x, unsigned y, unsigned mx, unsigned my )
+unsigned wrap( unsigned x, unsigned y, unsigned mx, unsigned my, size_t elem_size )
{
unsigned nx = (mx+x)%mx;
unsigned ny = (my+y)%my;
return nx + mx*ny;
}
+unsigned clamp( unsigned x, unsigned y, unsigned mx, unsigned my, size_t elem_size )
+{
+ unsigned nx = x;
+ while (nx >= mx) nx -= elem_size;
+ unsigned ny = (y >= my)? my - 1 : y;
+ return nx + mx*ny;
+}
+
+typedef unsigned (*texAddr_t) (unsigned x, unsigned y, unsigned mx, unsigned my, size_t elem_size);
+float tex_linf_sampling(memory_space* mem, unsigned tex_array_base,
+ int x, int y, unsigned int width, unsigned int height, size_t elem_size,
+ float alpha, float beta, texAddr_t b_lim)
+{
+ float Tij;
+ float Ti1j;
+ float Tij1;
+ float Ti1j1;
+
+ mem->read(tex_array_base + b_lim(x,y,width,height,elem_size), 4, &Tij);
+ mem->read(tex_array_base + b_lim(x+elem_size,y,width,height,elem_size), 4, &Ti1j);
+ mem->read(tex_array_base + b_lim(x,y+1,width,height,elem_size), 4, &Tij1);
+ mem->read(tex_array_base + b_lim(x+elem_size,y+1,width,height,elem_size), 4, &Ti1j1);
+
+ float sample = (1-alpha)*(1-beta)*Tij +
+ alpha*(1-beta)*Ti1j +
+ (1-alpha)*beta*Tij1 +
+ alpha*beta*Ti1j1;
+
+ return sample;
+}
+
void tex_impl( const ptx_instruction *pI, ptx_thread_info *thread )
{
cudasim_n_tex_insn++;
@@ -2919,21 +2941,25 @@ void tex_impl( const ptx_instruction *pI, ptx_thread_info *thread )
case F16_TYPE: assert(0); break;
case F32_TYPE: {
if( texref->filterMode == cudaFilterModeLinear ) {
- float Tij;
- float Ti1j;
- float Tij1;
- float Ti1j1;
-
- mem->read(tex_array_base + wrap(x,y,width,height), 4, &Tij);
- mem->read(tex_array_base + wrap(x+4,y,width,height), 4, &Ti1j);
- mem->read(tex_array_base + wrap(x,y+1,width,height), 4, &Tij1);
- mem->read(tex_array_base + wrap(x+4,y+1,width,height), 4, &Ti1j1);
+ texAddr_t b_lim = wrap;
+ if ( texref->addressMode[0] == cudaAddressModeClamp ) {
+ b_lim = clamp;
+ }
+ size_t elem_size = (cuArray->desc.x + cuArray->desc.y + cuArray->desc.z + cuArray->desc.w) / 8;
+ size_t elem_ofst = 0;
- data1.f32 = (1-alpha)*(1-beta)*Tij +
- alpha*(1-beta)*Ti1j +
- (1-alpha)*beta*Tij1 +
- alpha*beta*Ti1j1;
-
+ data1.f32 = tex_linf_sampling(mem, tex_array_base, x + elem_ofst, y, width, height, elem_size, alpha, beta, b_lim);
+ elem_ofst += cuArray->desc.x / 8;
+ if (cuArray->desc.y) {
+ data2.f32 = tex_linf_sampling(mem, tex_array_base, x + elem_ofst, y, width, height, elem_size, alpha, beta, b_lim);
+ elem_ofst += cuArray->desc.y / 8;
+ if (cuArray->desc.z) {
+ data3.f32 = tex_linf_sampling(mem, tex_array_base, x + elem_ofst, y, width, height, elem_size, alpha, beta, b_lim);
+ elem_ofst += cuArray->desc.z / 8;
+ if (cuArray->desc.w)
+ data4.f32 = tex_linf_sampling(mem, tex_array_base, x + elem_ofst, y, width, height, elem_size, alpha, beta, b_lim);
+ }
+ }
} else {
mem->read( tex_array_index, cuArray->desc.x/8, &data1.f32);
if (cuArray->desc.y) {
diff --git a/src/cuda-sim/memory.cc b/src/cuda-sim/memory.cc
index c6a1a9b..754fe7f 100644
--- a/src/cuda-sim/memory.cc
+++ b/src/cuda-sim/memory.cc
@@ -104,11 +104,24 @@ template<unsigned BSIZE> void memory_space_impl<BSIZE>::read( mem_addr_t addr, s
}
}
+template<unsigned BSIZE> void memory_space_impl<BSIZE>::print( const char *format, FILE *fout ) const
+{
+ typename map_t::const_iterator i_page;
+ for (i_page = m_data.begin(); i_page != m_data.end(); ++i_page) {
+ fprintf(fout, "%s - %#x:", m_name.c_str(), i_page->first);
+ i_page->second.print(format, fout);
+ }
+}
+
template class memory_space_impl<32>;
template class memory_space_impl<64>;
template class memory_space_impl<8192>;
template class memory_space_impl<16*1024>;
+void g_print_memory_space(memory_space *mem, const char *format = "%08x", FILE *fout = stdout)
+{
+ mem->print(format,fout);
+}
#ifdef UNIT_TEST
diff --git a/src/cuda-sim/memory.h b/src/cuda-sim/memory.h
index 1ea3efe..78e7db7 100644
--- a/src/cuda-sim/memory.h
+++ b/src/cuda-sim/memory.h
@@ -83,6 +83,7 @@
#include <assert.h>
#include <string.h>
+#include <stdio.h>
#include <string>
#include "../abstract_hardware_model.h"
@@ -118,6 +119,20 @@ public:
memcpy(data,m_data+offset,length);
}
+ void print( const char *format, FILE *fout ) const
+ {
+ unsigned int *i_data = (unsigned int*)m_data;
+ for (int d = 0; d < (BSIZE / sizeof(unsigned int)); d++) {
+ if (d % 8 == 0) {
+ fprintf(fout, "\n");
+ }
+ fprintf(fout, format, i_data[d]);
+ fprintf(fout, " ");
+ }
+ fprintf(fout, "\n");
+ fflush(fout);
+ }
+
private:
unsigned m_nbytes;
unsigned char *m_data;
@@ -128,7 +143,8 @@ class memory_space
public:
virtual ~memory_space() {}
virtual void write( mem_addr_t addr, size_t length, const void *data ) = 0;
- virtual void read( mem_addr_t addr, size_t length, void *data ) const = 0;;
+ virtual void read( mem_addr_t addr, size_t length, void *data ) const = 0;
+ virtual void print( const char *format, FILE *fout ) const = 0;
};
template<unsigned BSIZE> class memory_space_impl : public memory_space {
@@ -137,6 +153,7 @@ public:
virtual void write( mem_addr_t addr, size_t length, const void *data );
virtual void read( mem_addr_t addr, size_t length, void *data ) const;
+ virtual void print( const char *format, FILE *fout ) const;
private:
std::string m_name;
diff --git a/src/cuda-sim/ptx-stats.cc b/src/cuda-sim/ptx-stats.cc
index 2d18286..6e7e6ec 100644
--- a/src/cuda-sim/ptx-stats.cc
+++ b/src/cuda-sim/ptx-stats.cc
@@ -65,6 +65,7 @@
#include "../option_parser.h"
#include <stdio.h>
#include <map>
+#include <unordered_map>
// external dependencies
extern function_info *g_func_info;
@@ -89,7 +90,7 @@ void ptx_file_line_stats_options(option_parser_t opp)
class ptx_file_line
{
public:
- ptx_file_line(const char* s, int l){
+ ptx_file_line(const char* s, int l) {
if( s == NULL )
st = "NULL_NAME";
else
@@ -109,13 +110,21 @@ public:
}
bool operator==(const ptx_file_line &other) const {
- return (st==other.st) and (line==other.line);
+ return (line==other.line) && (st==other.st);
}
std::string st;
unsigned line;
};
+struct hash_ptx_file_line
+{
+ std::size_t operator()(const ptx_file_line & pfline) const {
+ std::hash<unsigned> hash_line;
+ return hash_line(pfline.line);
+ }
+};
+
// holds all statistics collected for a singe PTX source line
class ptx_file_line_stats
{
@@ -138,7 +147,8 @@ public:
unsigned long long warp_divergence; // number of warp divergence occured at this instruction
};
-static std::map<ptx_file_line, ptx_file_line_stats> ptx_file_line_stats_tracker;
+typedef std::unordered_map<ptx_file_line, ptx_file_line_stats, hash_ptx_file_line> ptx_file_line_stats_map_t;
+static ptx_file_line_stats_map_t ptx_file_line_stats_tracker;
// output statistics to a file
void ptx_file_line_stats_write_file()
@@ -146,7 +156,7 @@ void ptx_file_line_stats_write_file()
// check if stat collection is turned on
if (enable_ptx_file_line_stats == 0) return;
- std::map<ptx_file_line, ptx_file_line_stats>::iterator it;
+ ptx_file_line_stats_map_t::iterator it;
FILE * pfile;
pfile = fopen(ptx_line_stats_filename, "w");
diff --git a/src/cuda-sim/ptx_ir.cc b/src/cuda-sim/ptx_ir.cc
index d5e8df2..752dfc5 100644
--- a/src/cuda-sim/ptx_ir.cc
+++ b/src/cuda-sim/ptx_ir.cc
@@ -483,7 +483,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident
if ( ti.is_param() ) {
if( !g_in_function_definition ) {
- g_func_info->add_param_name_and_type(g_entry_func_param_index,identifier, ti.scalar_type() );
+ g_func_info->add_param_name_type_size(g_entry_func_param_index,identifier, ti.scalar_type(), num_bits );
g_entry_func_param_index++;
}
}
diff --git a/src/cuda-sim/ptx_ir.h b/src/cuda-sim/ptx_ir.h
index bdcd1a4..87a0b14 100644
--- a/src/cuda-sim/ptx_ir.h
+++ b/src/cuda-sim/ptx_ir.h
@@ -505,6 +505,13 @@ public:
if( !m_value.m_vector_symbolic[3] ) return 3;
return 4;
}
+
+ const symbol* vec_symbol(int idx) const
+ {
+ assert(idx < 4);
+ return m_value.m_vector_symbolic[idx];
+ }
+
const std::string &vec_name1() const
{
assert( m_type == vector_t);
@@ -858,13 +865,14 @@ private:
class param_info {
public:
param_info() { m_valid = false; m_value_set=false;}
- param_info( unsigned index, std::string name, int type )
+ param_info( unsigned index, std::string name, int type, size_t size )
{
m_valid = true;
m_value_set = false;
m_index = index;
m_name = name;
m_type = type;
+ m_size = size;
}
void add_data( param_t v ) {
m_value_set = true;
@@ -873,11 +881,13 @@ public:
std::string get_name() const { return m_name; }
int get_type() const { return m_type; }
param_t get_value() const { assert(m_value_set); return m_value; }
+ size_t get_size() const { return m_size; }
private:
bool m_valid;
unsigned m_index;
std::string m_name;
int m_type;
+ size_t m_size;
bool m_value_set;
param_t m_value;
};
@@ -954,7 +964,7 @@ public:
{
m_params[ name ] = value;
}
- void add_param_name_and_type( unsigned index, std::string name, int type );
+ void add_param_name_type_size( unsigned index, std::string name, int type, size_t size );
void add_param_data( unsigned argn, struct gpgpu_ptx_sim_arg *args );
void add_return_var( const symbol *rv )
{
@@ -998,62 +1008,8 @@ public:
return m_start_PC;
}
- void finalize( memory_space *param_mem, symbol_table *symtab )
- {
- unsigned param_address = 0;
- for( std::map<unsigned,param_info>::iterator i=m_ptx_param_info.begin(); i!=m_ptx_param_info.end(); i++ ) {
- param_info &p = i->second;
- std::string name = p.get_name();
- int type = p.get_type();
- param_t value = p.get_value();
- value.type = type;
- symbol *param = symtab->lookup(name.c_str());
- unsigned xtype = param->type()->get_key().scalar_type();
- assert(xtype==(unsigned)type);
- int tmp;
- size_t size;
- type_decode(xtype,size,tmp);
- param_mem->write(param_address,size/8,&value);
- param->set_address(param_address);
- param_address += 8;//align to 64 bits so mem_access doesn't complain (before was size/8);
- }
- }
- ptx_reg_t get_param( const std::string &name ) const
- {
- std::map<std::string,param_t>::const_iterator i = m_params.find(name);
- if ( i == m_params.end() ) {
- printf("Loader error: parameter \"%s\" value not defined in configuration\n", name.c_str() );
- abort();
- } else {
- param_t x = i->second;
- ptx_reg_t y;
- switch ( x.type ) {
- case S8_TYPE:
- case S16_TYPE:
- case S32_TYPE:
- case S64_TYPE:
- case B8_TYPE:
- case B16_TYPE:
- case B32_TYPE:
- case B64_TYPE:
- case U8_TYPE:
- case U16_TYPE:
- case U32_TYPE:
- case U64_TYPE:
- y.u64 = x.data.int_value;
- break;
- case F16_TYPE:
- assert(0);
- case F32_TYPE:
- y.f32 = x.data.float_value;
- break;
- case F64_TYPE:
- y.f64 = x.data.double_value;
- break;
- }
- return y;
- }
- }
+ void finalize( memory_space *param_mem, symbol_table *symtab );
+ void list_param( FILE *fout ) const;
const struct gpgpu_ptx_sim_kernel_info* get_kernel_info () {
return &m_kernel_info;
diff --git a/src/cuda-sim/ptx_sim.cc b/src/cuda-sim/ptx_sim.cc
index d551c43..8998466 100644
--- a/src/cuda-sim/ptx_sim.cc
+++ b/src/cuda-sim/ptx_sim.cc
@@ -235,12 +235,12 @@ ptx_thread_info::ptx_thread_info()
m_hw_sid = -1;
m_last_dram_callback.function = NULL;
m_last_dram_callback.instruction = NULL;
- m_regs.push_back( std::map<std::string,ptx_reg_t>() );
- m_debug_trace_regs_modified.push_back( std::map<std::string,ptx_reg_t>() );
+ m_regs.push_back( reg_map_t() );
m_callstack.push_back( stack_entry() );
m_RPC = -1;
m_RPC_updated = false;
m_last_was_call = false;
+ m_enable_debug_trace = false;
}
const ptx_version &ptx_thread_info::get_ptx_version() const
@@ -356,8 +356,7 @@ void ptx_thread_info::callstack_push( unsigned pc, unsigned rpc, const symbol *r
m_RPC_updated = true;
m_last_was_call = true;
m_callstack.push_back( stack_entry(m_symbol_table,m_func_info,pc,rpc,return_var_src,return_var_dst,call_uid) );
- m_regs.push_back( std::map<std::string,ptx_reg_t>() );
- m_debug_trace_regs_modified.push_back( std::map<std::string,ptx_reg_t>() );
+ m_regs.push_back( reg_map_t() );
}
#define POST_DOMINATOR 1 /* must match definition in shader.h */
@@ -382,7 +381,6 @@ bool ptx_thread_info::callstack_pop()
rval = get_operand_value(rv_src);
m_callstack.pop_back();
m_regs.pop_back();
- m_debug_trace_regs_modified.pop_back();
if( rv_dst != NULL )
set_operand_value(rv_dst,rval);
return m_callstack.empty();
@@ -391,13 +389,13 @@ bool ptx_thread_info::callstack_pop()
void ptx_thread_info::dump_callstack() const
{
std::list<stack_entry>::const_iterator c=m_callstack.begin();
- std::list<std::map<std::string,ptx_reg_t> >::const_iterator r=m_regs.begin();
+ std::list<reg_map_t>::const_iterator r=m_regs.begin();
printf("\n\n");
printf("Call stack for thread uid = %u (sc=%u, hwtid=%u)\n", m_uid, m_hw_sid, m_hw_tid );
while( c != m_callstack.end() && r != m_regs.end() ) {
const stack_entry &c_e = *c;
- const std::map<std::string,ptx_reg_t> &regs = *r;
+ const reg_map_t &regs = *r;
if( !c_e.m_valid ) {
printf(" <entry> #regs = %zu\n", regs.size() );
} else {
@@ -427,9 +425,9 @@ std::string ptx_thread_info::get_location() const
void ptx_thread_info::dump_regs()
{
printf("Register File Contents:\n");
- std::map<std::string,ptx_reg_t>::const_iterator r;
+ reg_map_t::const_iterator r;
for ( r=m_regs.back().begin(); r != m_regs.back().end(); ++r ) {
- std::string name = r->first;
+ std::string name = r->first->name();
ptx_reg_t value = r->second;
print_reg(name,value);
@@ -441,9 +439,9 @@ void ptx_thread_info::dump_modifiedregs()
if( m_debug_trace_regs_modified.empty() )
return;
printf("Modified Registers:\n");
- std::map<std::string,ptx_reg_t>::const_iterator r;
- for ( r=m_debug_trace_regs_modified.back().begin(); r != m_debug_trace_regs_modified.back().end(); ++r ) {
- std::string name = r->first;
+ reg_map_t::const_iterator r;
+ for ( r=m_debug_trace_regs_modified.begin(); r != m_debug_trace_regs_modified.end(); ++r ) {
+ std::string name = r->first->name();
ptx_reg_t value = r->second;
print_reg(name,value);
}
diff --git a/src/cuda-sim/ptx_sim.h b/src/cuda-sim/ptx_sim.h
index 976ce70..c07308e 100644
--- a/src/cuda-sim/ptx_sim.h
+++ b/src/cuda-sim/ptx_sim.h
@@ -94,25 +94,23 @@ struct gpgpu_ptx_sim_kernel_info {
#include <assert.h>
#include "opcodes.h"
-struct param_t {
- union {
- float float_value;
- int int_value;
- double double_value;
- unsigned long long ptr_value;
- } data;
- int type;
-};
-
#ifdef __cplusplus
#include <string>
#include <map>
#include <set>
#include <list>
+ #include <unordered_map>
#include "memory.h"
+struct param_t {
+ const void *pdata;
+ int type;
+ size_t size;
+ size_t offset;
+};
+
union ptx_reg_t {
ptx_reg_t() {
bits.ms = 0;
@@ -421,9 +419,11 @@ public:
}
void dump_regs();
void dump_modifiedregs();
- void clear_modifiedregs() { m_debug_trace_regs_modified.back().clear();}
+ void clear_modifiedregs() { m_debug_trace_regs_modified.clear();}
function_info *get_finfo() { return m_func_info; }
+ void enable_debug_trace() { m_enable_debug_trace = true; }
+
public:
addr_t m_last_effective_address;
bool m_branch_taken;
@@ -465,8 +465,12 @@ private:
std::list<stack_entry> m_callstack;
- std::list<std::map<std::string,ptx_reg_t> > m_regs;
- std::list<std::map<std::string,ptx_reg_t> > m_debug_trace_regs_modified;
+ // typedef std::unordered_map<std::string,ptx_reg_t> reg_map_t;
+ typedef std::unordered_map<const symbol*,ptx_reg_t> reg_map_t;
+ std::list<reg_map_t> m_regs;
+
+ bool m_enable_debug_trace;
+ reg_map_t m_debug_trace_regs_modified; // track the modified register for each executed insn
};
unsigned type_decode( unsigned type, size_t &size, int &t );
diff --git a/src/gpgpu-sim/histogram.h b/src/gpgpu-sim/histogram.h
index 2d39410..5470050 100644
--- a/src/gpgpu-sim/histogram.h
+++ b/src/gpgpu-sim/histogram.h
@@ -78,6 +78,7 @@ protected:
int *m_bins; // bin boundaries
int *m_bin_cnts; // counters
int m_maximum; // the maximum sample
+ signed long long int m_sum; // for calculating the average
public:
diff --git a/src/gpgpu-sim/stat-tool.cc b/src/gpgpu-sim/stat-tool.cc
index 9845e06..98a6917 100644
--- a/src/gpgpu-sim/stat-tool.cc
+++ b/src/gpgpu-sim/stat-tool.cc
@@ -91,7 +91,7 @@
#include "../abstract_hardware_model.h"
binned_histogram::binned_histogram (std::string name, int nbins, int* bins)
- : m_name(name), m_nbins(nbins), m_bins(NULL), m_bin_cnts(new int[m_nbins]), m_maximum(0)
+ : m_name(name), m_nbins(nbins), m_bins(NULL), m_bin_cnts(new int[m_nbins]), m_maximum(0), m_sum(0)
{
if (bins) {
m_bins = new int[m_nbins];
@@ -105,7 +105,7 @@ binned_histogram::binned_histogram (std::string name, int nbins, int* bins)
binned_histogram::binned_histogram (const binned_histogram& other)
: m_name(other.m_name), m_nbins(other.m_nbins), m_bins(NULL),
- m_bin_cnts(new int[m_nbins]), m_maximum(0)
+ m_bin_cnts(new int[m_nbins]), m_maximum(0), m_sum(0)
{
for (int i = 0; i < m_nbins; i++) {
m_bin_cnts[i] = other.m_bin_cnts[i];
@@ -125,10 +125,17 @@ void binned_histogram::add2bin (int sample) {
void binned_histogram::fprint (FILE *fout) {
if (m_name.c_str() != NULL) fprintf(fout, "%s = ", m_name.c_str());
+ int total_sample = 0;
for (int i = 0; i < m_nbins; i++) {
fprintf(fout, "%d ", m_bin_cnts[i]);
+ total_sample += m_bin_cnts[i];
}
fprintf(fout, "max=%d ", m_maximum);
+ float avg = 0.0f;
+ if (total_sample > 0) {
+ avg = (float)m_sum / total_sample;
+ }
+ fprintf(fout, "avg=%0.2f ", avg);
}
binned_histogram::~binned_histogram () {
@@ -156,6 +163,7 @@ void pow2_histogram::add2bin (int sample) {
m_bin_cnts[bin] += 1;
m_maximum = (sample > m_maximum)? sample : m_maximum;
+ m_sum += sample;
}
linear_histogram::linear_histogram (int stride, const char *name, int nbins, int* bins)
@@ -167,10 +175,12 @@ void linear_histogram::add2bin (int sample) {
assert(sample >= 0);
int bin = sample / m_stride;
+ if (bin >= m_nbins) bin = m_nbins - 1;
m_bin_cnts[bin] += 1;
m_maximum = (sample > m_maximum)? sample : m_maximum;
+ m_sum += sample;
}