diff options
| author | Tor Aamodt <[email protected]> | 2010-07-17 15:22:54 -0800 |
|---|---|---|
| committer | Tor Aamodt <[email protected]> | 2010-07-17 15:22:54 -0800 |
| commit | 766dceb168cbd8269828a310a924863020edc9ae (patch) | |
| tree | 443db0e515b91a34d972d6c55f1aeca10309bdd0 | |
| parent | d3d0b38b90f14660ecb6243373daa921f8ae02b1 (diff) | |
- adding new memory_space_t type to enable differentiation of different
parameter spaces (kernel parameters are conceptually different from
function parameters, but PTX only has one .param keyword)
- removing more dead code
[git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6870]
| -rw-r--r-- | src/abstract_hardware_model.h | 21 | ||||
| -rw-r--r-- | src/cuda-sim/cuda-sim.cc | 89 | ||||
| -rw-r--r-- | src/cuda-sim/instructions.cc | 60 | ||||
| -rw-r--r-- | src/cuda-sim/ptx.y | 18 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_ir.cc | 33 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_ir.h | 56 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_sim.cc | 2 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_sim.h | 6 | ||||
| -rw-r--r-- | src/gpgpu-sim/gpu-misc.h | 8 | ||||
| -rw-r--r-- | src/gpgpu-sim/shader.cc | 84 | ||||
| -rw-r--r-- | src/gpgpu-sim/shader.h | 2 |
11 files changed, 184 insertions, 195 deletions
diff --git a/src/abstract_hardware_model.h b/src/abstract_hardware_model.h index 7066aa6..1138270 100644 --- a/src/abstract_hardware_model.h +++ b/src/abstract_hardware_model.h @@ -1,6 +1,8 @@ #ifndef ABSTRACT_HARDWARE_MODEL_INCLUDED #define ABSTRACT_HARDWARE_MODEL_INCLUDED +#ifdef __cplusplus + class core_t { public: virtual ~core_t() {} @@ -9,9 +11,12 @@ public: virtual bool warp_waiting_at_barrier( unsigned warp_id ) = 0; }; +#endif + typedef unsigned address_type; typedef unsigned addr_t; +// these are operations the timing model can see #define NO_OP -1 #define ALU_OP 1000 #define LOAD_OP 2000 @@ -19,4 +24,20 @@ typedef unsigned addr_t; #define BRANCH_OP 4000 #define BARRIER_OP 5000 +typedef enum _memory_space_t { + undefined_space=0, + reg_space, + 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 */ + const_space, + tex_space, + surf_space, + global_space, + generic_space +} memory_space_t; + #endif diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index f7b127c..700d985 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -274,7 +274,7 @@ ptx_instruction::ptx_instruction( int opcode, const operand_info &return_var, const std::list<int> &options, const std::list<int> &scalar_type, - int space_spec, + memory_space_t space_spec, const char *file, unsigned line, const char *source ) @@ -678,14 +678,14 @@ bool isspace_global( addr_t addr ) return (addr > GLOBAL_HEAP_START) || (addr < STATIC_ALLOC_LIMIT); } -unsigned whichspace( addr_t addr ) +memory_space_t whichspace( addr_t addr ) { if( (addr > GLOBAL_HEAP_START) || (addr < STATIC_ALLOC_LIMIT) ) { - return GLOBAL_DIRECTIVE; + return global_space; } else if( addr > SHARED_GENERIC_START ) { - return SHARED_DIRECTIVE; + return shared_space; } else { - return LOCAL_DIRECTIVE; + return local_space; } } @@ -971,29 +971,6 @@ void function_info::ptx_decode_inst( ptx_thread_info *thread, } } -unsigned function_info::ptx_get_inst_op( ptx_thread_info *thread ) -{ - addr_t pc = thread->get_pc(); - unsigned index = pc - m_start_PC; - assert( index < m_instr_mem_size ); - ptx_instruction *pI = m_instr_mem[index]; //get instruction from m_instr_mem[PC] - - int opcode = pI->get_opcode(); //determine the opcode - - if ( opcode == LD_OP ) { - if ( pI->get_space() != SHARED_DIRECTIVE ) //treat shared memory access as generic instruction (e.g. no bank conflicts) - return LOAD_OP; - } else if ( opcode == ST_OP ) { - if ( pI->get_space() != SHARED_DIRECTIVE ) - return STORE_OP; - } else if ( opcode == BRA_OP ) { - return BRANCH_OP; - } else if ( opcode == TEX_OP ) { - return LOAD_OP; - } - return ALU_OP; -} - void function_info::add_param_name_type_size( unsigned index, std::string name, int type, size_t size ) { unsigned parsed_index; @@ -1142,7 +1119,7 @@ unsigned g_warp_active_mask; void function_info::ptx_exec_inst( ptx_thread_info *thread, addr_t *addr, - unsigned *space, + memory_space_t *space, unsigned *data_size, dram_callback_t* callback, unsigned warp_active_mask ) @@ -1195,7 +1172,7 @@ void function_info::ptx_exec_inst( ptx_thread_info *thread, } addr_t insn_memaddr = 0xFEEBDAED; - unsigned insn_space = -1; + memory_space_t insn_space = undefined_space; 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(); @@ -1231,21 +1208,24 @@ void function_info::ptx_exec_inst( ptx_thread_info *thread, g_ptx_sim_num_insn++; ptx_file_line_stats_add_exec_count(pI); if ( gpgpu_ptx_instruction_classification ) { - unsigned space = pI->get_space(); - switch ( space ) { - case GLOBAL_DIRECTIVE: space = 10; break; - case LOCAL_DIRECTIVE: space = 11; break; - case TEX_DIRECTIVE: space = 12; break; - case SURF_DIRECTIVE: space = 13; break; - case PARAM_DIRECTIVE: space = 14; break; - case SHARED_DIRECTIVE: space = 15; break; - case CONST_DIRECTIVE: space = 16; break; + unsigned space_type=0; + switch ( pI->get_space() ) { + case global_space: space_type = 10; break; + case local_space: space_type = 11; break; + 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: + space_type = 14; break; + case shared_space: space_type = 15; break; + case const_space: space_type = 16; break; default: - space = 0 ; + space_type = 0 ; break; } StatAddSample( g_inst_classification_stat[g_ptx_kernel_count], op_classification); - if (space) StatAddSample( g_inst_classification_stat[g_ptx_kernel_count], ( int )space); + if (space_type) StatAddSample( g_inst_classification_stat[g_ptx_kernel_count], ( int )space_type); StatAddSample( g_inst_op_classification_stat[g_ptx_kernel_count], (int) pI->get_opcode() ); } if ( (g_ptx_sim_num_insn % 100000) == 0 ) { @@ -1623,14 +1603,14 @@ void gpgpu_ptx_sim_memcpy_symbol(const char *hostVar, const void *src, size_t co { printf("GPGPU-Sim PTX: starting gpgpu_ptx_sim_memcpy_symbol with hostVar 0x%p\n", hostVar); bool found_sym = false; - int mem_region = 0; + memory_space_t mem_region = undefined_space; std::string sym_name; std::map<const void*,std::string>::iterator c=g_const_name_lookup.find(hostVar); if ( c!=g_const_name_lookup.end() ) { found_sym = true; sym_name = c->second; - mem_region = CONST_DIRECTIVE; + mem_region = const_space; } std::map<const void*,std::string>::iterator g=g_global_name_lookup.find(hostVar); if ( g!=g_global_name_lookup.end() ) { @@ -1641,17 +1621,17 @@ void gpgpu_ptx_sim_memcpy_symbol(const char *hostVar, const void *src, size_t co } found_sym = true; sym_name = g->second; - mem_region = GLOBAL_DIRECTIVE; + mem_region = global_space; } if( g_globals.find(hostVar) != g_globals.end() ) { found_sym = true; sym_name = hostVar; - mem_region = GLOBAL_DIRECTIVE; + mem_region = global_space; } if( g_constants.find(hostVar) != g_constants.end() ) { found_sym = true; sym_name = hostVar; - mem_region = CONST_DIRECTIVE; + mem_region = const_space; } if ( !found_sym ) { @@ -1670,11 +1650,11 @@ void gpgpu_ptx_sim_memcpy_symbol(const char *hostVar, const void *src, size_t co assert(sym); unsigned dst = sym->get_address() + offset; switch (mem_region) { - case CONST_DIRECTIVE: + case const_space: mem = g_global_mem; mem_name = "global"; break; - case GLOBAL_DIRECTIVE: + case global_space: mem = g_global_mem; mem_name = "global"; break; @@ -2117,7 +2097,7 @@ void gpgpu_ptx_sim_main_func( const char *kernel_key, dim3 gridDim, dim3 blockDi unsigned op_type; addr_t addr; - unsigned space; + memory_space_t space; int arch_reg[MAX_REG_OPERANDS] = { -1 }; unsigned data_size; dram_callback_t callback; @@ -2174,16 +2154,7 @@ void ptx_decode_inst( void *thd, unsigned *op, int *i1, int *i2, int *i3, int *i g_func_info->ptx_decode_inst(thread,op,i1,i2,i3,i4,o1,o2,o3,o4,vectorin,vectorout,arch_reg); } -unsigned ptx_get_inst_op( void *thd) -{ - if ( thd == NULL ) - return NO_OP; - - ptx_thread_info *thread = (ptx_thread_info *) thd; - return(thread->func_info())->ptx_get_inst_op(thread); -} - -void ptx_exec_inst( void *thd, address_type *addr, unsigned *space, unsigned *data_size, dram_callback_t* callback, unsigned warp_active_mask ) +void ptx_exec_inst( void *thd, address_type *addr, memory_space_t *space, unsigned *data_size, dram_callback_t* callback, unsigned warp_active_mask ) { if ( thd == NULL ) return; diff --git a/src/cuda-sim/instructions.cc b/src/cuda-sim/instructions.cc index 4e82787..783f97c 100644 --- a/src/cuda-sim/instructions.cc +++ b/src/cuda-sim/instructions.cc @@ -380,7 +380,7 @@ void atom_callback( void* ptx_inst, void* thd ) ptx_instruction *pI = (ptx_instruction*)ptx_inst; // Check state space - assert( pI->get_space()==GLOBAL_DIRECTIVE ); + assert( pI->get_space()==global_space ); // "Decode" the output type unsigned to_type = pI->get_type(); @@ -640,13 +640,13 @@ void atom_impl( const ptx_instruction *pI, ptx_thread_info *thread ) // atom.space.operation.type d, a, b[, c]; (now read in callback) // Check state space - assert( pI->get_space()==GLOBAL_DIRECTIVE ); + assert( pI->get_space()== global_space ); // get the memory address const operand_info &src1 = pI->src1(); ptx_reg_t src1_data = thread->get_operand_value(src1); - unsigned space = pI->get_space(); + memory_space_t space = pI->get_space(); thread->m_last_effective_address = src1_data.u32; thread->m_last_memory_space = space; @@ -1323,7 +1323,7 @@ void cvta_impl( const ptx_instruction *pI, ptx_thread_info *thread ) const operand_info &dst = pI->dst(); const operand_info &src1 = pI->src1(); - unsigned space = pI->get_space(); + memory_space_t space = pI->get_space(); bool to_non_generic = pI->is_to(); ptx_reg_t from_addr = thread->get_operand_value(src1); @@ -1334,16 +1334,16 @@ void cvta_impl( const ptx_instruction *pI, ptx_thread_info *thread ) if( to_non_generic ) { switch( space ) { - case SHARED_DIRECTIVE: to_addr_hw = generic_to_shared( smid, from_addr_hw ); break; - case LOCAL_DIRECTIVE: to_addr_hw = generic_to_local( smid, hwtid, from_addr_hw ); break; - case GLOBAL_DIRECTIVE: to_addr_hw = generic_to_global(from_addr_hw ); break; + case shared_space: to_addr_hw = generic_to_shared( smid, from_addr_hw ); break; + case local_space: to_addr_hw = generic_to_local( smid, hwtid, from_addr_hw ); break; + case global_space: to_addr_hw = generic_to_global(from_addr_hw ); break; default: abort(); } } else { switch( space ) { - case SHARED_DIRECTIVE: to_addr_hw = shared_to_generic( smid, from_addr_hw ); break; - case LOCAL_DIRECTIVE: to_addr_hw = local_to_generic( smid, hwtid, from_addr_hw ); break; - case GLOBAL_DIRECTIVE: to_addr_hw = global_to_generic( from_addr_hw ); break; + case shared_space: to_addr_hw = shared_to_generic( smid, from_addr_hw ); break; + case local_space: to_addr_hw = local_to_generic( smid, hwtid, from_addr_hw ); break; + case global_space: to_addr_hw = global_to_generic( from_addr_hw ); break; default: abort(); } } @@ -1434,7 +1434,7 @@ void isspacep_impl( const ptx_instruction *pI, ptx_thread_info *thread ) const operand_info &dst = pI->dst(); const operand_info &src1 = pI->src1(); - unsigned space = pI->get_space(); + memory_space_t space = pI->get_space(); a = thread->get_operand_value(src1); addr_t addr = (addr_t)a.u64; @@ -1442,9 +1442,9 @@ void isspacep_impl( const ptx_instruction *pI, ptx_thread_info *thread ) unsigned hwtid = thread->get_hw_tid(); switch( space ) { - case SHARED_DIRECTIVE: t = isspace_shared( smid, addr ); - case LOCAL_DIRECTIVE: t = isspace_local( smid, hwtid, addr ); - case GLOBAL_DIRECTIVE: t = isspace_global( addr ); + case shared_space: t = isspace_shared( smid, addr ); + case local_space: t = isspace_local( smid, hwtid, addr ); + case global_space: t = isspace_global( addr ); default: abort(); } @@ -1454,26 +1454,30 @@ void isspacep_impl( const ptx_instruction *pI, ptx_thread_info *thread ) thread->set_operand_value(dst,p); } -void decode_space( unsigned &space, ptx_thread_info *thread, memory_space *&mem, addr_t &addr) +void decode_space( memory_space_t &space, ptx_thread_info *thread, memory_space *&mem, addr_t &addr) { unsigned smid = thread->get_hw_sid(); unsigned hwtid = thread->get_hw_tid(); switch ( space ) { - case GLOBAL_DIRECTIVE: mem = g_global_mem; break; - case LOCAL_DIRECTIVE: mem = thread->m_local_mem; break; - case TEX_DIRECTIVE: mem = g_tex_mem; break; - case SURF_DIRECTIVE: mem = g_surf_mem; break; - case PARAM_DIRECTIVE: mem = g_param_mem; break; - case SHARED_DIRECTIVE: mem = thread->m_shared_mem; break; - case CONST_DIRECTIVE: mem = g_global_mem; break; + case global_space: mem = g_global_mem; break; + 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: + abort(); // finish this + case param_space_kernel: mem = g_param_mem; break; + case shared_space: mem = thread->m_shared_mem; break; + case const_space: mem = g_global_mem; break; default: if( thread->get_ptx_version().ver() >= 2.0 ) { // convert generic address to memory space address space = whichspace(addr); switch ( space ) { - case GLOBAL_DIRECTIVE: mem = g_global_mem; addr = generic_to_global(addr); break; - case LOCAL_DIRECTIVE: mem = thread->m_local_mem; addr = generic_to_local(smid,hwtid,addr); break; - case SHARED_DIRECTIVE: mem = thread->m_shared_mem; addr = generic_to_shared(smid,addr); break; + case global_space: mem = g_global_mem; addr = generic_to_global(addr); break; + case local_space: mem = thread->m_local_mem; addr = generic_to_local(smid,hwtid,addr); break; + case shared_space: mem = thread->m_shared_mem; addr = generic_to_shared(smid,addr); break; default: abort(); } } else { @@ -1489,7 +1493,7 @@ void ld_impl( const ptx_instruction *pI, ptx_thread_info *thread ) const operand_info &src1 = pI->src1(); ptx_reg_t src1_data = thread->get_operand_value(src1); ptx_reg_t data; - unsigned space = pI->get_space(); + memory_space_t space = pI->get_space(); unsigned vector_spec = pI->get_vector(); unsigned type = pI->get_type(); memory_space *mem = NULL; @@ -2626,7 +2630,7 @@ void st_impl( const ptx_instruction *pI, ptx_thread_info *thread ) const operand_info &src1 = pI->src1(); //may be scalar or vector of regs ptx_reg_t addr_reg = thread->get_operand_value(dst); ptx_reg_t data; - unsigned space = pI->get_space(); + memory_space_t space = pI->get_space(); unsigned vector_spec = pI->get_vector(); unsigned type = pI->get_type(); memory_space *mem = NULL; @@ -3007,7 +3011,7 @@ void tex_impl( const ptx_instruction *pI, ptx_thread_info *thread ) default: assert(0); } - thread->m_last_memory_space = TEX_DIRECTIVE; + thread->m_last_memory_space = tex_space; thread->set_vector_operand_values(dst,data1,data2,data3,data4,4); } diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y index 5711b94..8a897ce 100644 --- a/src/cuda-sim/ptx.y +++ b/src/cuda-sim/ptx.y @@ -248,8 +248,8 @@ function_decl_header: ENTRY_DIRECTIVE { $$ = 1; g_func_decl=1; } param_list: param_entry { add_directive(); } | param_list COMMA param_entry { add_directive(); } -param_entry: PARAM_DIRECTIVE { add_space_spec(PARAM_DIRECTIVE); } variable_spec identifier_spec { add_function_arg(); } - | REG_DIRECTIVE { add_space_spec(REG_DIRECTIVE); } variable_spec identifier_spec { add_function_arg(); } +param_entry: PARAM_DIRECTIVE { add_space_spec(param_space_unclassified); } variable_spec identifier_spec { add_function_arg(); } + | REG_DIRECTIVE { add_space_spec(reg_space); } variable_spec identifier_spec { add_function_arg(); } statement_list: directive_statement { add_directive(); } | instruction_statement { add_instruction(); } @@ -309,13 +309,13 @@ space_spec: REG_DIRECTIVE { add_space_spec(REG_DIRECTIVE); } | addressable_spec ; -addressable_spec: CONST_DIRECTIVE { add_space_spec(CONST_DIRECTIVE); } - | GLOBAL_DIRECTIVE { add_space_spec(GLOBAL_DIRECTIVE); } - | LOCAL_DIRECTIVE { add_space_spec(LOCAL_DIRECTIVE); } - | PARAM_DIRECTIVE { add_space_spec(PARAM_DIRECTIVE); } - | SHARED_DIRECTIVE { add_space_spec(SHARED_DIRECTIVE); } - | SURF_DIRECTIVE { add_space_spec(SURF_DIRECTIVE); } - | TEX_DIRECTIVE { add_space_spec(TEX_DIRECTIVE); } +addressable_spec: CONST_DIRECTIVE { add_space_spec(const_space); } + | GLOBAL_DIRECTIVE { add_space_spec(global_space); } + | LOCAL_DIRECTIVE { add_space_spec(local_space); } + | PARAM_DIRECTIVE { add_space_spec(param_space_unclassified); } + | SHARED_DIRECTIVE { add_space_spec(shared_space); } + | SURF_DIRECTIVE { add_space_spec(surf_space); } + | TEX_DIRECTIVE { add_space_spec(tex_space); } ; type_spec: scalar_type diff --git a/src/cuda-sim/ptx_ir.cc b/src/cuda-sim/ptx_ir.cc index 752dfc5..ac93aa3 100644 --- a/src/cuda-sim/ptx_ir.cc +++ b/src/cuda-sim/ptx_ir.cc @@ -90,7 +90,7 @@ std::map<std::string,symbol_table*> g_sym_name_to_symbol_table; int g_error_detected = 0; // type specifier stuff: -int g_space_spec = -1; +memory_space_t g_space_spec = undefined_space; int g_scalar_type_spec = -1; int g_vector_spec = -1; int g_alignment_spec = -1; @@ -144,7 +144,7 @@ void init_parser() void init_directive_state() { DPRINTF("init_directive_state"); - g_space_spec=-1; + g_space_spec=undefined_space; g_scalar_type_spec=-1; g_vector_spec=-1; g_opcode=-1; @@ -400,7 +400,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident } g_last_symbol = g_current_symbol_table->add_variable(identifier,type,g_filename,ptx_lineno); switch ( g_space_spec ) { - case REG_DIRECTIVE: { + case reg_space: { regnum = g_current_symbol_table->next_reg_num(); int arch_regnum = -1; for (int d = 0; d < strlen(identifier); d++) { @@ -414,7 +414,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident } g_last_symbol->set_regno(regnum, arch_regnum); } break; - case SHARED_DIRECTIVE: + case shared_space: printf("GPGPU-Sim PTX: allocating shared region for \"%s\" from 0x%x to 0x%lx (shared memory space)\n", identifier, g_current_symbol_table->get_shared_next(), @@ -426,7 +426,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident g_last_symbol->set_address( addr+addr_pad ); g_current_symbol_table->alloc_shared( num_bits/8 + addr_pad ); break; - case CONST_DIRECTIVE: + case const_space: if( array_ident == ARRAY_IDENTIFIER_NO_DIM ) { printf("GPGPU-Sim PTX: deferring allocation of constant region for \"%s\" (need size information)\n", identifier ); } else { @@ -448,7 +448,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident assert( g_current_symbol_table != NULL ); g_sym_name_to_symbol_table[ identifier ] = g_current_symbol_table; break; - case GLOBAL_DIRECTIVE: + case global_space: printf("GPGPU-Sim PTX: allocating global region for \"%s\" from 0x%x to 0x%lx (global memory space)\n", identifier, g_current_symbol_table->get_global_next(), @@ -463,7 +463,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident assert( g_current_symbol_table != NULL ); g_sym_name_to_symbol_table[ identifier ] = g_current_symbol_table; break; - case LOCAL_DIRECTIVE: + case local_space: printf("GPGPU-Sim PTX: allocating local region for \"%s\" from 0x%x to 0x%lx (local memory space)\n", identifier, g_current_symbol_table->get_local_next(), @@ -473,7 +473,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident g_last_symbol->set_address( g_current_symbol_table->get_local_next() ); g_current_symbol_table->alloc_local( num_bits/8 ); break; - case TEX_DIRECTIVE: + case tex_space: printf("GPGPU-Sim PTX: encountered texture directive %s.\n", identifier); break; default: @@ -510,11 +510,20 @@ void add_alignment_spec( int spec ) g_alignment_spec = spec; } -void add_space_spec( int spec ) +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 == -1, "multiple space specifiers not allowed." ); - g_space_spec = spec; + 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( 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 = spec; } void add_vector_spec(int spec ) @@ -820,7 +829,7 @@ bool symbol_table::add_function_decl( const char *name, int entry_point, functio return prior_decl; } -type_info *symbol_table::add_type( int space_spec, int scalar_type_spec, int vector_spec, int alignment_spec, int extern_spec ) +type_info *symbol_table::add_type( memory_space_t space_spec, int scalar_type_spec, int vector_spec, int alignment_spec, int extern_spec ) { type_info_key t(space_spec,scalar_type_spec,vector_spec,alignment_spec,extern_spec,0); type_info *pt; diff --git a/src/cuda-sim/ptx_ir.h b/src/cuda-sim/ptx_ir.h index 87a0b14..eaa3919 100644 --- a/src/cuda-sim/ptx_ir.h +++ b/src/cuda-sim/ptx_ir.h @@ -65,6 +65,8 @@ #ifndef ptx_ir_INCLUDED #define ptx_ir_INCLUDED +#include "../abstract_hardware_model.h" + #ifdef __cplusplus #include <cstdlib> @@ -78,35 +80,16 @@ #include "ptx.tab.h" #include "ptx_sim.h" #include "dram_callback.h" - #include "../abstract_hardware_model.h" #include "memory.h" -enum space_type { - undefined, inst_space -}; - - -class addr { /* need this because there are many distinct address spaces (global, local, param, tex, surf, shared) */ -public: - - addr() { m_space=undefined; m_addr = 0;} - void set_space( enum space_type space ); - operator unsigned() { return m_addr;} - -private: - enum space_type m_space; - unsigned m_addr; -}; - - class type_info_key { public: type_info_key() { m_init = false; } - type_info_key( int space_spec, int scalar_type_spec, int vector_spec, int alignment_spec, int extern_spec, int array_dim ) + type_info_key( memory_space_t space_spec, int scalar_type_spec, int vector_spec, int alignment_spec, int extern_spec, int array_dim ) { m_init = true; m_space_spec = space_spec; @@ -116,12 +99,12 @@ public: m_extern_spec = extern_spec; m_array_dim = array_dim; m_is_function = 0; - } + } void set_is_func() { assert(!m_init); m_init = true; - m_space_spec = 0; + m_space_spec = undefined_space; m_scalar_type_spec = 0; m_vector_spec = 0; m_alignment_spec = 0; @@ -135,18 +118,18 @@ public: m_array_dim = array_dim; } - bool is_reg() const { return m_space_spec == REG_DIRECTIVE;} - bool is_param() const { return m_space_spec == PARAM_DIRECTIVE;} - bool is_global() const { return m_space_spec == GLOBAL_DIRECTIVE;} - bool is_local() const { return m_space_spec == LOCAL_DIRECTIVE;} - bool is_shared() const { return m_space_spec == SHARED_DIRECTIVE;} - bool is_const() const { return m_space_spec == CONST_DIRECTIVE;} - bool is_tex() const { return m_space_spec == TEX_DIRECTIVE;} + 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_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;} + bool is_const() const { return m_space_spec == const_space;} + 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;} private: bool m_init; - int m_space_spec; + memory_space_t m_space_spec; int m_scalar_type_spec; int m_vector_spec; int m_alignment_spec; @@ -325,7 +308,7 @@ public: symbol *add_variable( const char *identifier, const type_info *type, const char *filename, unsigned line ); void add_function( function_info *func ); bool add_function_decl( const char *name, int entry_point, function_info **func_info, symbol_table **symbol_table ); - type_info *add_type( int space_spec, int scalar_type_spec, int vector_spec, int alignment_spec, int extern_spec ); + type_info *add_type( memory_space_t space_spec, int scalar_type_spec, int vector_spec, int alignment_spec, int extern_spec ); type_info *add_type( function_info *func ); type_info *get_array_type( type_info *base_type, unsigned array_dim ); void set_label_address( const symbol *label, unsigned addr ); @@ -687,7 +670,7 @@ public: const operand_info &return_var, const std::list<int> &options, const std::list<int> &scalar_type, - int space_spec, + memory_space_t space_spec, const char *file, unsigned line, const char *source ); @@ -774,7 +757,7 @@ public: return m_return_var.is_valid(); } - unsigned get_space() const { return m_space_spec;} + memory_space_t get_space() const { return m_space_spec;} unsigned get_vector() const { return m_vector_spec;} unsigned get_atomic() const { return m_atomic_spec;} @@ -853,7 +836,7 @@ private: unsigned m_saturation_mode; std::list<int> m_scalar_type; - int m_space_spec; + memory_space_t m_space_spec; int m_geom_spec; int m_vector_spec; int m_atomic_spec; @@ -958,8 +941,7 @@ public: int *vectorin, int *vectorout, int *arch_reg ); - unsigned ptx_get_inst_op( ptx_thread_info *thread ); - void ptx_exec_inst( ptx_thread_info *thd, addr_t *addr, unsigned *space, unsigned *data_size, dram_callback_t* callback, unsigned warp_active_mask ); + 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; @@ -1157,7 +1139,7 @@ extern "C" { void add_address_operand( const char *identifier, int offset ); void add_label( const char *idenfiier ); void add_vector_spec(int spec ); - void add_space_spec(int spec ); + void add_space_spec( memory_space_t spec ); void add_extern_spec(); void add_instruction(); void set_return(); diff --git a/src/cuda-sim/ptx_sim.cc b/src/cuda-sim/ptx_sim.cc index 8998466..269b858 100644 --- a/src/cuda-sim/ptx_sim.cc +++ b/src/cuda-sim/ptx_sim.cc @@ -223,7 +223,7 @@ ptx_thread_info::ptx_thread_info() m_PC=0; m_icount = 0; m_last_effective_address = 0; - m_last_memory_space = 0; + m_last_memory_space = undefined_space; m_branch_taken = 0; m_shared_mem = NULL; m_cta_info = NULL; diff --git a/src/cuda-sim/ptx_sim.h b/src/cuda-sim/ptx_sim.h index c07308e..8a74168 100644 --- a/src/cuda-sim/ptx_sim.h +++ b/src/cuda-sim/ptx_sim.h @@ -310,7 +310,7 @@ public: unsigned get_icount() const { return m_icount;} void set_valid() { m_valid = true;} addr_t last_eaddr() const { return m_last_effective_address;} - unsigned last_space() const { return m_last_memory_space;} + memory_space_t last_space() const { return m_last_memory_space;} dram_callback_t last_callback() const { return m_last_dram_callback;} void set_at_barrier( int barrier_num ) { @@ -427,7 +427,7 @@ public: public: addr_t m_last_effective_address; bool m_branch_taken; - unsigned m_last_memory_space; + memory_space_t m_last_memory_space; dram_callback_t m_last_dram_callback; memory_space *m_shared_mem; memory_space *m_local_mem; @@ -484,7 +484,7 @@ addr_t global_to_generic( addr_t addr ); bool isspace_local( unsigned smid, unsigned hwtid, addr_t addr ); bool isspace_shared( unsigned smid, addr_t addr ); bool isspace_global( addr_t addr ); -unsigned whichspace( addr_t addr ); +memory_space_t whichspace( addr_t addr ); #endif diff --git a/src/gpgpu-sim/gpu-misc.h b/src/gpgpu-sim/gpu-misc.h index 3d07d77..3b3cb4c 100644 --- a/src/gpgpu-sim/gpu-misc.h +++ b/src/gpgpu-sim/gpu-misc.h @@ -79,14 +79,6 @@ #define ispowerof2(x) ((((x) - 1) & (x)) == 0) #define powerof2(x) (1 << (x)) - -enum mem_space { //used for cudasim - SHARED_SPACE, - CONST_SPACE, - GLOBAL_SPACE, - LOCAL_SPACE, - TEX_SPACE -}; //enables a verbose printout of all L1 cache misses and all MSHR status changes //good for a single shader configuration #define DEBUGL1MISS 0 diff --git a/src/gpgpu-sim/shader.cc b/src/gpgpu-sim/shader.cc index c173206..c0e500d 100644 --- a/src/gpgpu-sim/shader.cc +++ b/src/gpgpu-sim/shader.cc @@ -221,8 +221,7 @@ extern unsigned long long gpu_tot_sim_cycle; extern unsigned g_max_regs_per_thread; void ptx_decode_inst( void *thd, unsigned *op, int *i1, int *i2, int *i3, int *i4, int *o1, int *o2, int *o3, int *o4, int *vectorin, int *vectorout, int *arch_reg ); -unsigned ptx_get_inst_op( void *thd); -void ptx_exec_inst( void *thd, address_type *addr, unsigned *space, unsigned *data_size, dram_callback_t* callback, unsigned warp_active_mask); +void ptx_exec_inst( void *thd, address_type *addr, memory_space_t *space, unsigned *data_size, dram_callback_t* callback, unsigned warp_active_mask); void ptx_sim_free_sm( void** thread_info ); unsigned ptx_sim_init_thread( void** thread_info, int sid, unsigned tid,unsigned threads_left,unsigned num_threads, core_t *core, unsigned hw_cta_id, unsigned hw_warp_id); unsigned ptx_sim_cta_size(); @@ -1651,24 +1650,25 @@ inline int is_store ( op_type op ) { return op == STORE_OP; } -inline int is_tex ( int space ) { - return((space) == TEX_DIRECTIVE); +inline int is_tex ( memory_space_t space ) { + return((space) == tex_space); } -inline int is_const ( int space ) { - return((space) == CONST_DIRECTIVE || (space) == PARAM_DIRECTIVE); +inline int is_const ( memory_space_t space ) { + return((space == const_space) || (space == param_space_kernel)); } -inline int is_local ( int space ) { - return((space) == LOCAL_DIRECTIVE); +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 + return((space) == local_space); } -inline int is_param ( int space ) { - return((space) == PARAM_DIRECTIVE); +inline int is_param ( memory_space_t space ) { + return (space == param_space_kernel); } -inline int is_shared ( int space ) { - return((space) == SHARED_DIRECTIVE); +inline int is_shared ( memory_space_t space ) { + return((space) == shared_space); } inline int shmem_bank ( address_type addr ) { @@ -1754,7 +1754,8 @@ void shader_decode( shader_core_ctx_t *shader, int i; int touched_priority=0; int warp_tid=0; - unsigned space, data_size; + unsigned data_size; + memory_space_t space; int vectorin, vectorout; int arch_reg[MAX_REG_OPERANDS] = { -1 }; address_type regs_regs_PC = 0xDEADBEEF; @@ -2143,7 +2144,7 @@ static unsigned next_access_uid = 0; class mem_access_t{ public: - mem_access_t(): uid(next_access_uid++),addr(0),req_size(0),order(0),_quarter_count_all(0),warp_indices(),space(0),path(NO_MEM_PATH),isatomic(false),cache_hit(false),cache_checked(false),recheck_cache(false),iswrite(false),need_wb(false),wb_addr(0),reserved_mshr(NULL){}; + mem_access_t(): uid(next_access_uid++),addr(0),req_size(0),order(0),_quarter_count_all(0),warp_indices(),space(undefined_space),path(NO_MEM_PATH),isatomic(false),cache_hit(false),cache_checked(false),recheck_cache(false),iswrite(false),need_wb(false),wb_addr(0),reserved_mshr(NULL){}; bool operator<(const mem_access_t &other) const {return (order > other.order);}//this is reverse unsigned uid; address_type addr; //address of the segment to load. @@ -2154,7 +2155,7 @@ public: char quarter_count[4]; //access counts to each quarter of segment, for compaction; }; std::vector<unsigned> warp_indices; //warp indicies for this request. - unsigned space; + memory_space_t space; memory_path path; bool isatomic; bool cache_hit; @@ -2231,7 +2232,7 @@ void check_accessq( shader_core_ctx_t *shader, std::vector<mem_access_t> &acces for (unsigned i = 0; i < accessq.size(); i++) { if (shader) { std::cout << shader->sid << ":" << i << " space " << accessq[i].space << " " << gpu_sim_cycle << std::endl; - assert(accessq[i].space == (unsigned) shader->pipeline_reg[EX_MM][accessq[i].warp_indices[0]].space); + assert(accessq[i].space == shader->pipeline_reg[EX_MM][accessq[i].warp_indices[0]].space); } for (unsigned j = 0; j < accessq[i].warp_indices.size(); j++) { if (check[accessq[i].warp_indices[j]]) { @@ -2466,23 +2467,27 @@ mem_stage_stall_type send_mem_request(shader_core_ctx_t *shader, mem_access_t &a unsigned code; mem_access_type access_type; switch(access.space) { - case CONST_DIRECTIVE: - case PARAM_DIRECTIVE: + case const_space: + case param_space_kernel: code = CONSTC; access_type = CONST_ACC_R; break; - case TEX_DIRECTIVE: + case tex_space: code = TEXTC; access_type = TEXTURE_ACC_R; break; - case GLOBAL_DIRECTIVE: + case global_space: code = DCACHE; access_type = (access.iswrite)? GLOBAL_ACC_W: GLOBAL_ACC_R; break; - case LOCAL_DIRECTIVE: + case local_space: code = DCACHE; access_type = (access.iswrite)? LOCAL_ACC_W: LOCAL_ACC_R; break; + case param_space_local_r: + case param_space_local_w: + abort(); // todo: define mapping of local param space to linear memory ? + break; default: assert(0); // NOT A MEM SPACE; break; @@ -2763,20 +2768,25 @@ inline void mem_instruction_stats(inst_t* warp){ //this breaks some encapsulation: the is_[space] functions, if you change those, change this. bool store = is_store(warp[i].op); switch (warp[i].space) { - case SHARED_DIRECTIVE: + case undefined_space: + case reg_space: + break; + case shared_space: gpgpu_n_shmem_insn++; break; - case CONST_DIRECTIVE: + case const_space: gpgpu_n_const_insn++; break; - case PARAM_DIRECTIVE: + case param_space_kernel: + case param_space_local_r: + case param_space_local_w: gpgpu_n_param_insn++; break; - case TEX_DIRECTIVE: + case tex_space: gpgpu_n_tex_insn++; break; - case GLOBAL_DIRECTIVE: - case LOCAL_DIRECTIVE: + case global_space: + case local_space: if (store){ gpgpu_n_store_insn++; } else { @@ -2784,8 +2794,7 @@ inline void mem_instruction_stats(inst_t* warp){ } break; default: - //assert(0); //unknown mem space. - break; //not a mem instruction + abort(); } } } @@ -2815,27 +2824,28 @@ void shader_memory_queue(shader_core_ctx_t *shader, shader_queues_t *accessqs) if (shader->pipeline_reg[EX_MM][i].hw_thread_id == -1) continue; //bubble //this breaks some encapsulation: the is_[space] functions; if you change those, change this. switch (shader->pipeline_reg[EX_MM][i].space) { - case SHARED_DIRECTIVE: + case shared_space: path[i] = SHARED_MEM_PATH; type_counts[SHARED_MEM_PATH]++; break; - case CONST_DIRECTIVE: - case PARAM_DIRECTIVE: + case const_space: + case param_space_kernel: path[i] = CONSTANT_MEM_PATH; type_counts[CONSTANT_MEM_PATH]++; break; - case TEX_DIRECTIVE: + case tex_space: path[i] = TEXTURE_MEM_PATH; type_counts[TEXTURE_MEM_PATH]++; break; - case GLOBAL_DIRECTIVE: - case LOCAL_DIRECTIVE: + case global_space: + case local_space: path[i] = GLOBAL_MEM_PATH; type_counts[GLOBAL_MEM_PATH]++; break; + case param_space_local_r: + case param_space_local_w: default: - //path[i] = NO_MEM_PATH; - break; //not a mem instruction + abort(); } } diff --git a/src/gpgpu-sim/shader.h b/src/gpgpu-sim/shader.h index 1567d6a..3b99ad3 100644 --- a/src/gpgpu-sim/shader.h +++ b/src/gpgpu-sim/shader.h @@ -121,7 +121,7 @@ typedef struct { address_type pc; op_type op; - int space; + memory_space_t space; unsigned long long int memreqaddr; //Each instruction keeps track of which hardware thread it came from |
