summaryrefslogtreecommitdiff
path: root/src/cuda-sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuda-sim')
-rw-r--r--src/cuda-sim/cuda-sim.cc58
-rw-r--r--src/cuda-sim/cuda-sim.h6
-rw-r--r--src/cuda-sim/instructions.cc22
-rw-r--r--src/cuda-sim/ptx_ir.h51
4 files changed, 36 insertions, 101 deletions
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<const struct textureReference*,const struct cudaArray*> TextureToArrayMap; // texture bindings
-std::map<const struct textureReference*, const struct textureInfo*> TextureToInfoMap;
-std::map<std::string, const struct textureReference*> 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<std::string, const struct textureReference*>::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<std::string,function_info*> &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 <stdarg.h>
-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<struct textureReference*,struct cudaArray*> TextureToArrayMap; // texture bindings
-extern std::map<struct textureReference*,struct textureInfo*> TextureToInfoMap; // texture bindings
-extern std::map<std::string, struct textureReference*> 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