From 9aba275f0c2f9f7d125cb1364d991dbdcb6195c8 Mon Sep 17 00:00:00 2001 From: Tor Aamodt Date: Sat, 9 Oct 2010 09:22:16 -0800 Subject: refactoring: moving texture reference mappings into gpgpu_t [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 7835] --- src/abstract_hardware_model.cc | 10 ++-- src/abstract_hardware_model.h | 118 ++++++++++++++++++++++++++++++++++------- src/cuda-sim/cuda-sim.cc | 58 ++++++++++---------- src/cuda-sim/cuda-sim.h | 6 --- src/cuda-sim/instructions.cc | 22 +++----- src/cuda-sim/ptx_ir.h | 51 +----------------- src/debug.cc | 6 +-- src/gpgpu-sim/shader.cc | 2 +- 8 files changed, 145 insertions(+), 128 deletions(-) (limited to 'src') diff --git a/src/abstract_hardware_model.cc b/src/abstract_hardware_model.cc index c52be1d..b943a76 100644 --- a/src/abstract_hardware_model.cc +++ b/src/abstract_hardware_model.cc @@ -15,12 +15,12 @@ void move_warp( warp_inst_t *&dst, warp_inst_t *&src ) gpgpu_t::gpgpu_t() { - g_global_mem = new memory_space_impl<8192>("global",64*1024); - g_param_mem = new memory_space_impl<8192>("param",64*1024); - g_tex_mem = new memory_space_impl<8192>("tex",64*1024); - g_surf_mem = new memory_space_impl<8192>("surf",64*1024); + m_global_mem = new memory_space_impl<8192>("global",64*1024); + m_param_mem = new memory_space_impl<8192>("param",64*1024); + m_tex_mem = new memory_space_impl<8192>("tex",64*1024); + m_surf_mem = new memory_space_impl<8192>("surf",64*1024); - g_dev_malloc=GLOBAL_HEAP_START; + m_dev_malloc=GLOBAL_HEAP_START; } void warp_inst_t::sort_accessq( unsigned qbegin ) diff --git a/src/abstract_hardware_model.h b/src/abstract_hardware_model.h index 7162441..62a59e0 100644 --- a/src/abstract_hardware_model.h +++ b/src/abstract_hardware_model.h @@ -52,6 +52,7 @@ enum _memory_op_t { #include #include #include +#include #if !defined(__VECTOR_TYPES_H__) struct dim3 { @@ -152,29 +153,110 @@ public: #define LOCAL_GENERIC_START (SHARED_GENERIC_START-TOTAL_LOCAL_MEM) #define STATIC_ALLOC_LIMIT (GLOBAL_HEAP_START - (TOTAL_LOCAL_MEM+TOTAL_SHARED_MEM)) +#if !defined(__CUDA_RUNTIME_API_H__) + +enum cudaChannelFormatKind { + cudaChannelFormatKindSigned, + cudaChannelFormatKindUnsigned, + cudaChannelFormatKindFloat +}; + +struct cudaChannelFormatDesc { + int x; + int y; + int z; + int w; + enum cudaChannelFormatKind f; +}; + +struct cudaArray { + void *devPtr; + int devPtr32; + struct cudaChannelFormatDesc desc; + int width; + int height; + int size; //in bytes + unsigned dimensions; +}; + +enum cudaTextureAddressMode { + cudaAddressModeWrap, + cudaAddressModeClamp +}; + +enum cudaTextureFilterMode { + cudaFilterModePoint, + cudaFilterModeLinear +}; + +enum cudaTextureReadMode { + cudaReadModeElementType, + cudaReadModeNormalizedFloat +}; + +struct textureReference { + int normalized; + enum cudaTextureFilterMode filterMode; + enum cudaTextureAddressMode addressMode[2]; + struct cudaChannelFormatDesc channelDesc; +}; + +#endif + class gpgpu_t { public: - gpgpu_t(); - void* gpgpu_ptx_sim_malloc( size_t size ); - void* gpgpu_ptx_sim_mallocarray( size_t count ); - void gpgpu_ptx_sim_memcpy_to_gpu( size_t dst_start_addr, const void *src, size_t count ); - void gpgpu_ptx_sim_memcpy_from_gpu( void *dst, size_t src_start_addr, size_t count ); - void gpgpu_ptx_sim_memcpy_gpu_to_gpu( size_t dst, size_t src, size_t count ); - void gpgpu_ptx_sim_memset( size_t dst_start_addr, int c, size_t count ); - - class memory_space *get_global_memory() { return g_global_mem; } - class memory_space *get_tex_memory() { return g_tex_mem; } - class memory_space *get_surf_memory() { return g_surf_mem; } - class memory_space *get_param_memory() { return g_param_mem; } + gpgpu_t(); + void* gpu_malloc( size_t size ); + void* gpu_mallocarray( size_t count ); + void gpu_memset( size_t dst_start_addr, int c, size_t count ); + void memcpy_to_gpu( size_t dst_start_addr, const void *src, size_t count ); + void memcpy_from_gpu( void *dst, size_t src_start_addr, size_t count ); + void memcpy_gpu_to_gpu( size_t dst, size_t src, size_t count ); + + class memory_space *get_global_memory() { return m_global_mem; } + class memory_space *get_tex_memory() { return m_tex_mem; } + class memory_space *get_surf_memory() { return m_surf_mem; } + class memory_space *get_param_memory() { return m_param_mem; } + + void gpgpu_ptx_sim_bindTextureToArray(const struct textureReference* texref, const struct cudaArray* array); + void gpgpu_ptx_sim_bindNameToTexture(const char* name, const struct textureReference* texref); + const char* gpgpu_ptx_sim_findNamefromTexture(const struct textureReference* texref); + unsigned ptx_set_tex_cache_linesize(unsigned linesize); + const struct cudaArray* gpgpu_ptx_sim_accessArrayofTexture(struct textureReference* texref); + const struct textureReference* gpgpu_ptx_sim_accessTextureofName(const char* name); + int gpgpu_ptx_sim_sizeofTexture(const char* name); + + const struct textureReference* get_texref(const std::string &texname) const + { + std::map::const_iterator t=NameToTextureMap.find(texname); + assert( t != NameToTextureMap.end() ); + return t->second; + } + const struct cudaArray* get_texarray( const struct textureReference *texref ) const + { + std::map::const_iterator t=TextureToArrayMap.find(texref); + assert(t != TextureToArrayMap.end()); + return t->second; + } + const struct textureInfo* get_texinfo( const struct textureReference *texref ) const + { + std::map::const_iterator t=TextureToInfoMap.find(texref); + assert(t != TextureToInfoMap.end()); + return t->second; + } protected: - // functional simulation state - class memory_space *g_global_mem; - class memory_space *g_tex_mem; - class memory_space *g_surf_mem; - class memory_space *g_param_mem; + class memory_space *m_global_mem; + class memory_space *m_tex_mem; + class memory_space *m_surf_mem; + class memory_space *m_param_mem; + + unsigned long long m_dev_malloc; - unsigned long long g_dev_malloc; + std::map TextureToArrayMap; // texture bindings + std::map TextureToInfoMap; + std::map NameToTextureMap; + unsigned int g_texcache_linesize; }; struct gpgpu_ptx_sim_kernel_info diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index 5293d7d..5d60010 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -95,24 +95,21 @@ addr_t g_debug_pc = 0xBEEF1518; FILE* ptx_inst_debug_file; unsigned g_ptx_sim_num_insn = 0; -std::map TextureToArrayMap; // texture bindings -std::map TextureToInfoMap; -std::map NameToTextureMap; -unsigned int g_texcache_linesize; unsigned gpgpu_param_num_shaders = 0; -void gpgpu_ptx_sim_bindNameToTexture(const char* name, const struct textureReference* texref) +void gpgpu_t::gpgpu_ptx_sim_bindNameToTexture(const char* name, const struct textureReference* texref) { std::string texname(name); NameToTextureMap[texname] = texref; } -const struct textureReference* gpgpu_ptx_sim_accessTextureofName(const char* name) { +const struct textureReference* gpgpu_t::gpgpu_ptx_sim_accessTextureofName(const char* name) +{ std::string texname(name); return NameToTextureMap[texname]; } -const char* gpgpu_ptx_sim_findNamefromTexture(const struct textureReference* texref) +const char* gpgpu_t::gpgpu_ptx_sim_findNamefromTexture(const struct textureReference* texref) { std::map::iterator itr = NameToTextureMap.begin(); while (itr != NameToTextureMap.end()) { @@ -140,7 +137,7 @@ unsigned int intLOGB2( unsigned int v ) { return r; } -void gpgpu_ptx_sim_bindTextureToArray(const struct textureReference* texref, const struct cudaArray* array) +void gpgpu_t::gpgpu_ptx_sim_bindTextureToArray(const struct textureReference* texref, const struct cudaArray* array) { TextureToArrayMap[texref] = array; unsigned int texel_size_bits = array->desc.w + array->desc.x + array->desc.y + array->desc.z; @@ -195,11 +192,12 @@ void gpgpu_ptx_sim_bindTextureToArray(const struct textureReference* texref, con TextureToInfoMap[texref] = texInfo; } -const struct cudaArray* gpgpu_ptx_sim_accessArrayofTexture(struct textureReference* texref) { +const struct cudaArray* gpgpu_t::gpgpu_ptx_sim_accessArrayofTexture(struct textureReference* texref) +{ return TextureToArrayMap[texref]; } -int gpgpu_ptx_sim_sizeofTexture(const char* name) +int gpgpu_t::gpgpu_ptx_sim_sizeofTexture(const char* name) { std::string texname(name); const struct textureReference* texref = NameToTextureMap[texname]; @@ -378,71 +376,71 @@ addr_t generic_to_global( addr_t addr ) } -void* gpgpu_t::gpgpu_ptx_sim_malloc( size_t size ) +void* gpgpu_t::gpu_malloc( size_t size ) { - unsigned long long result = g_dev_malloc; - printf("GPGPU-Sim PTX: allocating %zu bytes on GPU starting at address 0x%Lx\n", size, g_dev_malloc ); + unsigned long long result = m_dev_malloc; + printf("GPGPU-Sim PTX: allocating %zu bytes on GPU starting at address 0x%Lx\n", size, m_dev_malloc ); fflush(stdout); - g_dev_malloc += size; - if (size%64) g_dev_malloc += (64 - size%64); //align to 64 byte boundaries + m_dev_malloc += size; + if (size%64) m_dev_malloc += (64 - size%64); //align to 64 byte boundaries return(void*) result; } -void* gpgpu_t::gpgpu_ptx_sim_mallocarray( size_t size ) +void* gpgpu_t::gpu_mallocarray( size_t size ) { - unsigned long long result = g_dev_malloc; - printf("GPGPU-Sim PTX: allocating %zu bytes on GPU starting at address 0x%Lx\n", size, g_dev_malloc ); + unsigned long long result = m_dev_malloc; + printf("GPGPU-Sim PTX: allocating %zu bytes on GPU starting at address 0x%Lx\n", size, m_dev_malloc ); fflush(stdout); - g_dev_malloc += size; - if (size%64) g_dev_malloc += (64 - size%64); //align to 64 byte boundaries + m_dev_malloc += size; + if (size%64) m_dev_malloc += (64 - size%64); //align to 64 byte boundaries return(void*) result; } -void gpgpu_t::gpgpu_ptx_sim_memcpy_to_gpu( size_t dst_start_addr, const void *src, size_t count ) +void gpgpu_t::memcpy_to_gpu( size_t dst_start_addr, const void *src, size_t count ) { printf("GPGPU-Sim PTX: copying %zu bytes from CPU[0x%Lx] to GPU[0x%Lx] ... ", count, (unsigned long long) src, (unsigned long long) dst_start_addr ); fflush(stdout); char *src_data = (char*)src; for (unsigned n=0; n < count; n ++ ) - g_global_mem->write(dst_start_addr+n,1, src_data+n,NULL,NULL); + m_global_mem->write(dst_start_addr+n,1, src_data+n,NULL,NULL); printf( " done.\n"); fflush(stdout); } -void gpgpu_t::gpgpu_ptx_sim_memcpy_from_gpu( void *dst, size_t src_start_addr, size_t count ) +void gpgpu_t::memcpy_from_gpu( void *dst, size_t src_start_addr, size_t count ) { printf("GPGPU-Sim PTX: copying %zu bytes from GPU[0x%Lx] to CPU[0x%Lx] ...", count, (unsigned long long) src_start_addr, (unsigned long long) dst ); fflush(stdout); unsigned char *dst_data = (unsigned char*)dst; for (unsigned n=0; n < count; n ++ ) - g_global_mem->read(src_start_addr+n,1,dst_data+n); + m_global_mem->read(src_start_addr+n,1,dst_data+n); printf( " done.\n"); fflush(stdout); } -void gpgpu_t::gpgpu_ptx_sim_memcpy_gpu_to_gpu( size_t dst, size_t src, size_t count ) +void gpgpu_t::memcpy_gpu_to_gpu( size_t dst, size_t src, size_t count ) { printf("GPGPU-Sim PTX: copying %zu bytes from GPU[0x%Lx] to GPU[0x%Lx] ...", count, (unsigned long long) src, (unsigned long long) dst ); fflush(stdout); for (unsigned n=0; n < count; n ++ ) { unsigned char tmp; - g_global_mem->read(src+n,1,&tmp); - g_global_mem->write(dst+n,1, &tmp,NULL,NULL); + m_global_mem->read(src+n,1,&tmp); + m_global_mem->write(dst+n,1, &tmp,NULL,NULL); } printf( " done.\n"); fflush(stdout); } -void gpgpu_t::gpgpu_ptx_sim_memset( size_t dst_start_addr, int c, size_t count ) +void gpgpu_t::gpu_memset( size_t dst_start_addr, int c, size_t count ) { printf("GPGPU-Sim PTX: setting %zu bytes of memory to 0x%x starting at 0x%Lx... ", count, (unsigned char) c, (unsigned long long) dst_start_addr ); fflush(stdout); unsigned char c_value = (unsigned char)c; for (unsigned n=0; n < count; n ++ ) - g_global_mem->write(dst_start_addr+n,1,&c_value,NULL,NULL); + m_global_mem->write(dst_start_addr+n,1,&c_value,NULL,NULL); printf( " done.\n"); fflush(stdout); } @@ -1474,7 +1472,7 @@ void gpgpu_cuda_ptx_sim_main_func( kernel_info_t kernel, dim3 gridDim, dim3 bloc fflush(stdout); } -unsigned ptx_set_tex_cache_linesize(unsigned linesize) +unsigned gpgpu_t::ptx_set_tex_cache_linesize(unsigned linesize) { g_texcache_linesize = linesize; return 0; diff --git a/src/cuda-sim/cuda-sim.h b/src/cuda-sim/cuda-sim.h index b72a157..b095afb 100644 --- a/src/cuda-sim/cuda-sim.h +++ b/src/cuda-sim/cuda-sim.h @@ -32,11 +32,6 @@ extern void gpgpu_ptx_sim_register_const_variable(void*, const char *deviceNam extern void gpgpu_ptx_sim_register_global_variable(void *hostVar, const char *deviceName, size_t size ); extern void gpgpu_ptx_sim_memcpy_symbol(const char *hostVar, const void *src, size_t count, size_t offset, int to, gpgpu_t *gpu ); -extern void gpgpu_ptx_sim_bindTextureToArray(const struct textureReference* texref, const struct cudaArray* array); -extern void gpgpu_ptx_sim_bindNameToTexture(const char* name, const struct textureReference* texref); -extern int gpgpu_ptx_sim_sizeofTexture(const char* name); -extern const char* gpgpu_ptx_sim_findNamefromTexture(const struct textureReference* texref); -extern const struct textureReference* gpgpu_ptx_sim_accessTextureofName(const char* name); extern void read_sim_environment_variables(); extern void ptxinfo_opencl_addinfo( std::map &kernels ); unsigned ptx_sim_init_thread( kernel_info_t &kernel, @@ -52,7 +47,6 @@ unsigned ptx_sim_init_thread( kernel_info_t &kernel, const warp_inst_t *ptx_fetch_inst( address_type pc ); const struct gpgpu_ptx_sim_kernel_info* ptx_sim_kernel_info(class function_info *kernel); void ptx_print_insn( address_type pc, FILE *fp ); -unsigned int ptx_set_tex_cache_linesize( unsigned linesize); void set_param_gpgpu_num_shaders(int num_shaders); unsigned int get_converge_point(unsigned int pc, void *thd); const char *get_ptxinfo_kname(); diff --git a/src/cuda-sim/instructions.cc b/src/cuda-sim/instructions.cc index 335ea59..e67c779 100644 --- a/src/cuda-sim/instructions.cc +++ b/src/cuda-sim/instructions.cc @@ -81,8 +81,7 @@ #include -unsigned g_num_ptx_inst_uid=0; -unsigned cudasim_n_tex_insn=0; +unsigned ptx_instruction::g_num_ptx_inst_uid=0; const char *g_opcode_string[NUM_OPCODES] = { #define OP_DEF(OP,FUNC,STR,DST,CLASSIFICATION) STR, @@ -90,13 +89,8 @@ const char *g_opcode_string[NUM_OPCODES] = { #undef OP_DEF }; -extern std::map TextureToArrayMap; // texture bindings -extern std::map TextureToInfoMap; // texture bindings -extern std::map NameToTextureMap; - void inst_not_implemented( const ptx_instruction * pI ) ; ptx_reg_t srcOperandModifiers(ptx_reg_t opData, operand_info opInfo, operand_info dstInfo, unsigned type, ptx_thread_info *thread); -unsigned unfound_register_warned = 0; void sign_extend( ptx_reg_t &data, unsigned src_size, const operand_info &dst ); @@ -114,6 +108,7 @@ void ptx_thread_info::set_reg( const symbol *reg, const ptx_reg_t &value ) ptx_reg_t ptx_thread_info::get_reg( const symbol *reg ) { + static bool unfound_register_warned = false; assert( reg != NULL ); assert( !m_regs.empty() ); reg_map_t::iterator regs_iter = m_regs.back().find(reg); @@ -128,7 +123,7 @@ ptx_reg_t ptx_thread_info::get_reg( const symbol *reg ) if( !unfound_register_warned ) { printf("GPGPU-Sim PTX: WARNING (%s) ** reading undefined register \'%s\' (cuid:%u). Setting to 0XDEADBEEF.\n", file_loc.c_str(), name.c_str(), call_uid ); - unfound_register_warned = 1; + unfound_register_warned = true; } regs_iter = m_regs.back().find(reg); } @@ -3532,7 +3527,6 @@ float tex_linf_sampling(memory_space* mem, unsigned tex_array_base, void tex_impl( const ptx_instruction *pI, ptx_thread_info *thread ) { - cudasim_n_tex_insn++; unsigned dimension = pI->dimension(); const operand_info &dst = pI->dst(); //the registers to which fetched texel will be placed const operand_info &src1 = pI->src1(); //the name of the texture @@ -3546,12 +3540,10 @@ void tex_impl( const ptx_instruction *pI, ptx_thread_info *thread ) unsigned nelem = src2.get_vect_nelem(); thread->get_vector_operand_values(src2, ptx_tex_regs, nelem); //ptx_reg should be 4 entry vector type...coordinates into texture - assert(NameToTextureMap.find(texname) != NameToTextureMap.end());//use map to find texturerefence, then use map to find pointer to array - struct textureReference* texref = NameToTextureMap[texname]; - assert(TextureToArrayMap.find(texref) != TextureToArrayMap.end()); - struct cudaArray* cuArray = TextureToArrayMap[texref]; - assert(TextureToInfoMap.find(texref) != TextureToInfoMap.end()); - struct textureInfo* texInfo = TextureToInfoMap[texref]; + gpgpu_t *gpu = thread->get_gpu(); + const struct textureReference* texref = gpu->get_texref(texname); + const struct cudaArray* cuArray = gpu->get_texarray(texref); + const struct textureInfo* texInfo = gpu->get_texinfo(texref); //assume always 2D f32 input //access array with src2 coordinates diff --git a/src/cuda-sim/ptx_ir.h b/src/cuda-sim/ptx_ir.h index 612326c..07f2e36 100644 --- a/src/cuda-sim/ptx_ir.h +++ b/src/cuda-sim/ptx_ir.h @@ -1009,6 +1009,7 @@ private: virtual void pre_decode(); friend class function_info; + static unsigned g_num_ptx_inst_uid; }; class param_info { @@ -1343,56 +1344,6 @@ void copy_args_into_buffer_list( const ptx_instruction * pI, void copy_buffer_list_into_frame(ptx_thread_info * thread, arg_buffer_list_t &arg_values); void copy_buffer_to_frame(ptx_thread_info * thread, const arg_buffer_t &a); -#if !defined(__CUDA_RUNTIME_API_H__) -/*******************************/ -// These declarations should be identical to those in ./../../cuda-sim-dev/libcuda/texture_types.h -enum cudaChannelFormatKind { - cudaChannelFormatKindSigned, - cudaChannelFormatKindUnsigned, - cudaChannelFormatKindFloat -}; - -struct cudaChannelFormatDesc { - int x; - int y; - int z; - int w; - enum cudaChannelFormatKind f; -}; - -struct cudaArray { - void *devPtr; - int devPtr32; - struct cudaChannelFormatDesc desc; - int width; - int height; - int size; //in bytes - unsigned dimensions; -}; - -enum cudaTextureAddressMode { - cudaAddressModeWrap, - cudaAddressModeClamp -}; - -enum cudaTextureFilterMode { - cudaFilterModePoint, - cudaFilterModeLinear -}; - -enum cudaTextureReadMode { - cudaReadModeElementType, - cudaReadModeNormalizedFloat -}; - -struct textureReference { - int normalized; - enum cudaTextureFilterMode filterMode; - enum cudaTextureAddressMode addressMode[2]; - struct cudaChannelFormatDesc channelDesc; -}; -/**********************************/ -#endif struct textureInfo { unsigned int texel_size; //size in bytes, e.g. (channelDesc.x+y+z+w)/8 diff --git a/src/debug.cc b/src/debug.cc index 928c057..236870c 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -62,7 +62,7 @@ void gpgpu_sim::gpgpu_debug() if( b.is_watchpoint() ) { unsigned addr = b.get_addr(); unsigned new_value; - g_global_mem->read(addr,4,&new_value); + m_global_mem->read(addr,4,&new_value); if( new_value != b.get_value() || g_watchpoint_hits.find(num) != g_watchpoint_hits.end() ) { printf( "GPGPU-Sim PTX DBG: watch point %u triggered (old value=%x, new value=%x)\n", num,b.get_value(),new_value ); @@ -156,8 +156,8 @@ void gpgpu_sim::gpgpu_debug() unsigned addr; sscanf(tok,"%x",&addr); unsigned value; - g_global_mem->read(addr,4,&value); - g_global_mem->set_watch(addr,next_brkpt); + m_global_mem->read(addr,4,&value); + m_global_mem->set_watch(addr,next_brkpt); breakpoints[next_brkpt++] = brk_pt(addr,value); } else if( !strcmp(tok,"l") ) { if( brk_thd == NULL ) { diff --git a/src/gpgpu-sim/shader.cc b/src/gpgpu-sim/shader.cc index 9ffb3e7..28ec00d 100644 --- a/src/gpgpu-sim/shader.cc +++ b/src/gpgpu-sim/shader.cc @@ -387,7 +387,7 @@ shader_core_ctx::shader_core_ctx( class gpgpu_sim *gpu, m_L1T = new cache_t(L1T_name,m_config->gpgpu_cache_texl1_opt, 0,no_writes, m_sid,get_shader_texture_cache_id()); m_L1C = new cache_t(L1C_name,m_config->gpgpu_cache_constl1_opt,0,no_writes, m_sid,get_shader_constant_cache_id()); m_L1I = new cache_t(L1I_name,m_config->gpgpu_cache_il1_opt, 0,no_writes, m_sid,get_shader_instruction_cache_id()); - ptx_set_tex_cache_linesize(m_L1T->get_line_sz()); + m_gpu->ptx_set_tex_cache_linesize(m_L1T->get_line_sz()); m_mshr_unit = new mshr_shader_unit(m_config); m_pdom_warp = new pdom_warp_ctx_t*[config->max_warps_per_shader]; -- cgit v1.3