diff options
| author | Tor Aamodt <[email protected]> | 2010-07-17 16:53:43 -0800 |
|---|---|---|
| committer | Tor Aamodt <[email protected]> | 2010-07-17 16:53:43 -0800 |
| commit | c5677a028d56b84dfe5939f78a71e0e60373a0ed (patch) | |
| tree | 7db88eddba683ff5326297e4fa93f4a5d01f7bf2 | |
| parent | 766dceb168cbd8269828a310a924863020edc9ae (diff) | |
param space updates for correct parsing (still need to allocate thread
local storage for local param memory)
[git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6871]
| -rw-r--r-- | src/abstract_hardware_model.h | 5 | ||||
| -rw-r--r-- | src/cuda-sim/cuda-sim.cc | 28 | ||||
| -rw-r--r-- | src/cuda-sim/instructions.cc | 6 | ||||
| -rw-r--r-- | src/cuda-sim/ptx.y | 6 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_ir.cc | 44 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_ir.h | 22 | ||||
| -rw-r--r-- | src/gpgpu-sim/shader.cc | 16 |
7 files changed, 61 insertions, 66 deletions
diff --git a/src/abstract_hardware_model.h b/src/abstract_hardware_model.h index 1138270..4c6e23e 100644 --- a/src/abstract_hardware_model.h +++ b/src/abstract_hardware_model.h @@ -30,9 +30,8 @@ typedef enum _memory_space_t { local_space, shared_space, param_space_unclassified, - param_space_kernel, /* input parameters on kernel entry points */ - param_space_local_r, /* device functions can read this : input parameters on device functions */ - param_space_local_w, /* device functions can write this : used for return values and locally declared param memory */ + param_space_kernel, /* global to all threads in a kernel : read-only */ + param_space_local, /* local to a thread : read-writable */ const_space, tex_space, surf_space, diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index 700d985..bf0f305 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -978,14 +978,19 @@ void function_info::add_param_name_type_size( unsigned index, std::string name, snprintf(buffer,2048,"%s_param_%%u", m_name.c_str() ); 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, size); + assert( m_ptx_kernel_param_info.find(parsed_index) == m_ptx_kernel_param_info.end() ); + m_ptx_kernel_param_info[parsed_index] = param_info(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, size); + assert( m_ptx_kernel_param_info.find(index) == m_ptx_kernel_param_info.end() ); + m_ptx_kernel_param_info[index] = param_info(name, type, size); } } +void function_info::add_local_param_name_type_size( std::string name, int type, size_t size ) +{ + m_ptx_local_params[name] = param_info(name, type, size); +} + void function_info::add_param_data( unsigned argn, struct gpgpu_ptx_sim_arg *args ) { const void *data = args->m_start; @@ -995,8 +1000,8 @@ void function_info::add_param_data( unsigned argn, struct gpgpu_ptx_sim_arg *arg 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()) { + std::map<unsigned,param_info>::iterator i=m_ptx_kernel_param_info.find(argn); + if( i != m_ptx_kernel_param_info.end()) { i->second.add_data(tmp); } else { // This should only happen for OpenCL: @@ -1017,8 +1022,10 @@ void function_info::add_param_data( unsigned argn, struct gpgpu_ptx_sim_arg *arg snprintf(buffer,2048,"%s_param_%u",m_name.c_str(),argn); symbol *p = m_symtab->lookup(buffer); - if( p == NULL ) + if( p == NULL ) { printf("GPGPU-Sim PTX: ERROR ** could not locate symbol for \'%s\' : cannot bind buffer\n", buffer); + abort(); + } p->set_address((addr_t)*(size_t*)data); } } else { @@ -1029,7 +1036,7 @@ 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++ ) { + for( std::map<unsigned,param_info>::iterator i=m_ptx_kernel_param_info.begin(); i!=m_ptx_kernel_param_info.end(); i++ ) { param_info &p = i->second; std::string name = p.get_name(); int type = p.get_type(); @@ -1056,7 +1063,7 @@ void function_info::finalize( memory_space *param_mem, symbol_table *symtab ) 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++ ) { + 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(); symbol *param = symtab->lookup(name.c_str()); @@ -1215,8 +1222,7 @@ void function_info::ptx_exec_inst( ptx_thread_info *thread, case tex_space: space_type = 12; break; case surf_space: space_type = 13; break; case param_space_kernel: - case param_space_local_r: - case param_space_local_w: + case param_space_local: space_type = 14; break; case shared_space: space_type = 15; break; case const_space: space_type = 16; break; diff --git a/src/cuda-sim/instructions.cc b/src/cuda-sim/instructions.cc index 783f97c..2b4b410 100644 --- a/src/cuda-sim/instructions.cc +++ b/src/cuda-sim/instructions.cc @@ -139,7 +139,7 @@ ptx_reg_t ptx_thread_info::get_operand_value( const operand_info &op ) assert( regs_iter != m_regs.back().end() ); ptx_reg_t baseaddr = regs_iter->second; result.u64 = baseaddr.u64 + op.get_addr_offset(); - } else if ( info.is_param() ) { + } else if ( info.is_param_kernel() ) { result = sym->get_address() + op.get_addr_offset(); } else if ( info.is_global() ) { assert( op.get_addr_offset() == 0 ); @@ -1463,9 +1463,7 @@ void decode_space( memory_space_t &space, ptx_thread_info *thread, memory_space case local_space: mem = thread->m_local_mem; break; case tex_space: mem = g_tex_mem; break; case surf_space: mem = g_surf_mem; break; - case param_space_local_r: - abort(); // finish this - case param_space_local_w: + case param_space_local: abort(); // finish this case param_space_kernel: mem = g_param_mem; break; case shared_space: mem = thread->m_shared_mem; break; diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y index 8a897ce..79f3593 100644 --- a/src/cuda-sim/ptx.y +++ b/src/cuda-sim/ptx.y @@ -224,7 +224,7 @@ input: /* empty */ | input function_decl ; -function_defn: function_decl { set_symtab($1); start_function_definition(); } LEFT_BRACE statement_list RIGHT_BRACE { end_function(); } +function_defn: function_decl { set_symtab($1); } LEFT_BRACE statement_list RIGHT_BRACE { end_function(); } | function_decl { set_symtab($1); } block_spec LEFT_BRACE statement_list RIGHT_BRACE { end_function(); } ; @@ -304,8 +304,8 @@ var_spec: space_spec align_spec: ALIGN_DIRECTIVE INT_OPERAND { add_alignment_spec($2); } -space_spec: REG_DIRECTIVE { add_space_spec(REG_DIRECTIVE); } - | SREG_DIRECTIVE { add_space_spec(SREG_DIRECTIVE); } +space_spec: REG_DIRECTIVE { add_space_spec(reg_space); } + | SREG_DIRECTIVE { add_space_spec(reg_space); } | addressable_spec ; diff --git a/src/cuda-sim/ptx_ir.cc b/src/cuda-sim/ptx_ir.cc index ac93aa3..da1c49b 100644 --- a/src/cuda-sim/ptx_ir.cc +++ b/src/cuda-sim/ptx_ir.cc @@ -181,14 +181,6 @@ void start_function( int entry_point ) g_entry_func_param_index=0; } -static bool g_in_function_definition = false; - -void start_function_definition() -{ - DPRINTF("start_function_definition"); - g_in_function_definition = true; -} - char *g_add_identifier_cached__identifier = NULL; int g_add_identifier_cached__array_dim; int g_add_identifier_cached__array_ident; @@ -230,7 +222,6 @@ void end_function() { DPRINTF("end_function"); - g_in_function_definition = false; init_directive_state(); init_instruction_state(); g_max_regs_per_thread = mymax( g_max_regs_per_thread, (g_current_symbol_table->next_reg_num()-1)); @@ -333,7 +324,7 @@ void set_variable_type() DPRINTF("set_variable_type space_spec=%s scalar_type_spec=%s", g_ptx_token_decode[g_space_spec].c_str(), g_ptx_token_decode[g_scalar_type_spec].c_str() ); - parse_assert( g_space_spec != -1, "variable has no space specification" ); + parse_assert( g_space_spec != undefined_space, "variable has no space specification" ); parse_assert( g_scalar_type_spec != -1, "variable has no type information" ); // need to extend for structs? g_var_type = g_current_symbol_table->add_type( g_space_spec, g_scalar_type_spec, @@ -399,7 +390,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident break; } g_last_symbol = g_current_symbol_table->add_variable(identifier,type,g_filename,ptx_lineno); - switch ( g_space_spec ) { + switch ( ti.get_memory_space() ) { case reg_space: { regnum = g_current_symbol_table->next_reg_num(); int arch_regnum = -1; @@ -476,16 +467,20 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident case tex_space: printf("GPGPU-Sim PTX: encountered texture directive %s.\n", identifier); break; + case param_space_local: + case param_space_kernel: + break; default: + abort(); break; } - if ( ti.is_param() ) { - if( !g_in_function_definition ) { - g_func_info->add_param_name_type_size(g_entry_func_param_index,identifier, ti.scalar_type(), num_bits ); - g_entry_func_param_index++; - } + if ( ti.is_param_kernel() ) { + g_func_info->add_param_name_type_size(g_entry_func_param_index,identifier, ti.scalar_type(), num_bits ); + g_entry_func_param_index++; + } else if ( ti.is_param_local() || ti.is_param_unclassified() ) { + g_func_info->add_local_param_name_type_size( identifier, ti.scalar_type(), num_bits ); } } @@ -514,14 +509,14 @@ void add_space_spec( memory_space_t spec ) { DPRINTF("add_space_spec \"%s\"", g_ptx_token_decode[spec].c_str() ); parse_assert( g_space_spec == undefined_space, "multiple space specifiers not allowed." ); - if( g_space_spec == param_space_unclassified ) { - if( g_func_decl && !g_in_function_definition ) { + if( spec == param_space_unclassified ) { + if( g_func_decl ) { if( g_entry_point == 1) g_space_spec = param_space_kernel; - else - g_space_spec = param_space_local_r; - } else - g_space_spec = param_space_local_w; + else + g_space_spec = param_space_local; + } else + g_space_spec = param_space_unclassified; } else g_space_spec = spec; } @@ -774,9 +769,6 @@ symbol *symbol_table::add_variable( const char *identifier, const type_info *typ symbol *s = new symbol(identifier,type,buf); m_symbols[ key ] = s; - if ( type != NULL && type->get_key().is_param() ) { - m_params.push_back(s); - } if ( type != NULL && type->get_key().is_global() ) { m_globals.push_back(s); } @@ -831,6 +823,8 @@ bool symbol_table::add_function_decl( const char *name, int entry_point, functio type_info *symbol_table::add_type( memory_space_t space_spec, int scalar_type_spec, int vector_spec, int alignment_spec, int extern_spec ) { + if( space_spec == param_space_unclassified ) + space_spec = param_space_local; type_info_key t(space_spec,scalar_type_spec,vector_spec,alignment_spec,extern_spec,0); type_info *pt; pt = new type_info(this,t); diff --git a/src/cuda-sim/ptx_ir.h b/src/cuda-sim/ptx_ir.h index eaa3919..b143697 100644 --- a/src/cuda-sim/ptx_ir.h +++ b/src/cuda-sim/ptx_ir.h @@ -119,7 +119,9 @@ public: } bool is_reg() const { return m_space_spec == reg_space;} - bool is_param() const { abort(); /*this make sense?*/ return m_space_spec == param_space_kernel;} + bool is_param_kernel() const { return m_space_spec == param_space_kernel;} + bool is_param_local() const { return m_space_spec == param_space_local; } + bool is_param_unclassified() const { return m_space_spec == param_space_unclassified; } bool is_global() const { return m_space_spec == global_space;} bool is_local() const { return m_space_spec == local_space;} bool is_shared() const { return m_space_spec == shared_space;} @@ -127,6 +129,7 @@ public: bool is_tex() const { return m_space_spec == tex_space;} bool is_func_addr() const { return m_is_function?true:false; } int scalar_type() const { return m_scalar_type_spec;} + memory_space_t get_memory_space() const { return m_space_spec; } private: bool m_init; memory_space_t m_space_spec; @@ -324,9 +327,6 @@ public: typedef std::list<symbol*>::iterator iterator; - iterator param_iterator_begin() { return m_params.begin();} - iterator param_iterator_end() { return m_params.end();} - iterator global_iterator_begin() { return m_globals.begin();} iterator global_iterator_end() { return m_globals.end();} @@ -347,7 +347,6 @@ private: std::string m_scope_name; std::map<std::string, symbol *> m_symbols; //map from name of register to pointers to the registers std::map<type_info_key,type_info*,type_info_key_compare> m_types; - std::list<symbol*> m_params; std::list<symbol*> m_globals; std::list<symbol*> m_consts; std::map<std::string,function_info*> m_function_info_lookup; @@ -848,11 +847,10 @@ private: class param_info { public: param_info() { m_valid = false; m_value_set=false;} - param_info( unsigned index, std::string name, int type, size_t size ) + param_info( 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; @@ -867,7 +865,6 @@ public: 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; @@ -944,9 +941,10 @@ public: void ptx_exec_inst( ptx_thread_info *thd, addr_t *addr, memory_space_t *space, unsigned *data_size, dram_callback_t* callback, unsigned warp_active_mask ); void add_param( const char *name, struct param_t value ) { - m_params[ name ] = value; + m_kernel_params[ name ] = value; } void add_param_name_type_size( unsigned index, std::string name, int type, size_t size ); + void add_local_param_name_type_size( 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 ) { @@ -1021,8 +1019,9 @@ private: ptx_instruction **m_instr_mem; unsigned m_start_PC; unsigned m_instr_mem_size; - std::map<std::string,param_t> m_params; - std::map<unsigned,param_info> m_ptx_param_info; + std::map<std::string,param_t> m_kernel_params; + std::map<unsigned,param_info> m_ptx_kernel_param_info; + std::map<std::string,param_info> m_ptx_local_params; const symbol *m_return_var_sym; std::vector<const symbol*> m_args; std::list<ptx_instruction*> m_instructions; @@ -1113,7 +1112,6 @@ extern "C" { #endif void start_function( int entry_point ); - void start_function_definition(); void add_function_name( const char *fname ); void init_directive_state(); void add_directive(); diff --git a/src/gpgpu-sim/shader.cc b/src/gpgpu-sim/shader.cc index c0e500d..b9ae7da 100644 --- a/src/gpgpu-sim/shader.cc +++ b/src/gpgpu-sim/shader.cc @@ -1659,7 +1659,7 @@ inline int is_const ( memory_space_t space ) { } inline int is_local ( memory_space_t space ) { - assert( space != param_space_local_r && space != param_space_local_w ); // todo: map local param memory to linear address space + assert( space != param_space_local ); // todo: map local param memory to linear address space return((space) == local_space); } @@ -2484,8 +2484,7 @@ mem_stage_stall_type send_mem_request(shader_core_ctx_t *shader, mem_access_t &a code = DCACHE; access_type = (access.iswrite)? LOCAL_ACC_W: LOCAL_ACC_R; break; - case param_space_local_r: - case param_space_local_w: + case param_space_local: abort(); // todo: define mapping of local param space to linear memory ? break; default: @@ -2778,8 +2777,7 @@ inline void mem_instruction_stats(inst_t* warp){ gpgpu_n_const_insn++; break; case param_space_kernel: - case param_space_local_r: - case param_space_local_w: + case param_space_local: gpgpu_n_param_insn++; break; case tex_space: @@ -2842,10 +2840,12 @@ void shader_memory_queue(shader_core_ctx_t *shader, shader_queues_t *accessqs) path[i] = GLOBAL_MEM_PATH; type_counts[GLOBAL_MEM_PATH]++; break; - case param_space_local_r: - case param_space_local_w: + case param_space_local: + case param_space_unclassified: + abort(); // todo: define access details + break; default: - abort(); + break; } } |
