summaryrefslogtreecommitdiff
path: root/src/cuda-sim
diff options
context:
space:
mode:
authorTor Aamodt <[email protected]>2010-07-17 08:42:20 -0800
committerTor Aamodt <[email protected]>2010-07-17 08:42:20 -0800
commitca7e2e58e7fd932d67c6d28477a5c15ed3b156b0 (patch)
tree1a66586b291019476ec06715d259560818baf923 /src/cuda-sim
parentb6661da800739b0fca9e01ba6d5afaca4f286d84 (diff)
- add support for cvta and isspacep instructions (currently assuming
a fixed address mapping between shared,local to generic that depends upon hardware thread context used... might be interesting to explore tradeoffs at some point) - remove util.h... we don't need TRUE, FALSE anymore now that everything is C++ - remove some dead code from shader_decode [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 6867]
Diffstat (limited to 'src/cuda-sim')
-rw-r--r--src/cuda-sim/cuda-sim.cc92
-rw-r--r--src/cuda-sim/instructions.cc64
-rw-r--r--src/cuda-sim/memory.h2
-rw-r--r--src/cuda-sim/ptx.l2
-rw-r--r--src/cuda-sim/ptx.y5
-rw-r--r--src/cuda-sim/ptx_ir.h4
-rw-r--r--src/cuda-sim/ptx_sim.h10
7 files changed, 157 insertions, 22 deletions
diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc
index e2326f2..f8a8db0 100644
--- a/src/cuda-sim/cuda-sim.cc
+++ b/src/cuda-sim/cuda-sim.cc
@@ -73,7 +73,7 @@
#include "dram_callback.h"
#include <set>
#include <map>
-#include "../util.h"
+#include "../abstract_hardware_model.h"
#include "memory.h"
#include "ptx-stats.h"
@@ -293,6 +293,7 @@ ptx_instruction::ptx_instruction( int opcode,
m_hi = false;
m_lo = false;
m_uni = false;
+ m_to_option = false;
m_rounding_mode = RN_OPTION;
m_compare_op = -1;
m_saturation_mode = 0;
@@ -401,6 +402,9 @@ ptx_instruction::ptx_instruction( int opcode,
break;
case FTZ_OPTION:
break;
+ case TO_OPTION:
+ m_to_option = true;
+ break;
default:
assert(0);
@@ -587,7 +591,7 @@ int load_static_globals( symbol_table *symtab, unsigned min_gaddr, unsigned max_
return ng_bytes;
}
-int load_constants( symbol_table *symtab )
+int load_constants( symbol_table *symtab, addr_t min_gaddr )
{
printf( "GPGPU-Sim PTX: loading constants with explicit initializers... " );
fflush(stdout);
@@ -617,6 +621,7 @@ int load_constants( symbol_table *symtab )
abort();
}
unsigned addr=constant->get_address() + nbytes_written;
+ assert( addr+nbytes < min_gaddr );
g_global_mem->write(addr,nbytes,&value); // assume little endian (so u8 is the first byte in u32)
nc_bytes+=nbytes;
@@ -629,7 +634,70 @@ int load_constants( symbol_table *symtab )
return nc_bytes;
}
-unsigned long long g_dev_malloc=0x10000000; // start allocating from this address (lower values used for allocating globals in .ptx file)
+#define GLOBAL_HEAP_START 0x10000000
+ // start allocating from this address (lower values used for allocating globals in .ptx file)
+
+#define SHARED_MEM_SIZE_MAX (64*1024)
+#define LOCAL_MEM_SIZE_MAX 1024
+#define MAX_STREAMING_MULTIPROCESSORS 64
+#define MAX_THREAD_PER_SM 1024
+#define TOTAL_LOCAL_MEM_PER_SM (MAX_THREAD_PER_SM*LOCAL_MEM_SIZE_MAX)
+#define TOTAL_SHARED_MEM (MAX_STREAMING_MULTIPROCESSORS*SHARED_MEM_SIZE_MAX)
+#define TOTAL_LOCAL_MEM (MAX_STREAMING_MULTIPROCESSORS*MAX_THREAD_PER_SM*LOCAL_MEM_SIZE_MAX)
+#define SHARED_GENERIC_START (GLOBAL_HEAP_START-TOTAL_SHARED_MEM)
+#define LOCAL_GENERIC_START (SHARED_GENERIC_START-TOTAL_LOCAL_MEM)
+
+#define STATIC_ALLOC_LIMIT (GLOBAL_HEAP_START - (TOTAL_LOCAL_MEM+TOTAL_SHARED_MEM))
+
+addr_t shared_to_generic( unsigned smid, addr_t addr )
+{
+ assert( addr < SHARED_MEM_SIZE_MAX );
+ return SHARED_GENERIC_START + smid*SHARED_MEM_SIZE_MAX + addr;
+}
+
+bool isspace_shared( unsigned smid, addr_t addr )
+{
+ addr_t start = SHARED_GENERIC_START + smid*SHARED_MEM_SIZE_MAX;
+ addr_t end = SHARED_GENERIC_START + (smid+1)*SHARED_MEM_SIZE_MAX;
+ if( (addr >= end) || (addr < start) )
+ return false;
+ return true;
+}
+
+bool isspace_global( addr_t addr )
+{
+ return (addr > GLOBAL_HEAP_START) || (addr < STATIC_ALLOC_LIMIT);
+}
+
+addr_t generic_to_shared( unsigned smid, addr_t addr )
+{
+ assert(isspace_shared(smid,addr));
+ return addr - (SHARED_GENERIC_START + smid*SHARED_MEM_SIZE_MAX);
+}
+
+addr_t local_to_generic( unsigned smid, unsigned hwtid, addr_t addr )
+{
+ assert(addr < LOCAL_MEM_SIZE_MAX);
+ return LOCAL_GENERIC_START + (TOTAL_LOCAL_MEM_PER_SM * smid) + (LOCAL_MEM_SIZE_MAX * hwtid) + addr;
+}
+
+bool isspace_local( unsigned smid, unsigned hwtid, addr_t addr )
+{
+ addr_t start = LOCAL_GENERIC_START + (TOTAL_LOCAL_MEM_PER_SM * smid) + (LOCAL_MEM_SIZE_MAX * hwtid);
+ addr_t end = LOCAL_GENERIC_START + (TOTAL_LOCAL_MEM_PER_SM * smid) + (LOCAL_MEM_SIZE_MAX * (hwtid+1));
+ if( (addr >= end) || (addr < start) )
+ return false;
+ return true;
+}
+
+addr_t generic_to_local( unsigned smid, unsigned hwtid, addr_t addr )
+{
+ assert(isspace_local(smid,hwtid,addr));
+ return addr - (LOCAL_GENERIC_START + (TOTAL_LOCAL_MEM_PER_SM * smid) + (LOCAL_MEM_SIZE_MAX * hwtid));
+}
+
+
+unsigned long long g_dev_malloc=GLOBAL_HEAP_START;
void* gpgpu_ptx_sim_malloc( size_t size )
{
@@ -954,12 +1022,6 @@ void function_info::add_param_data( unsigned argn, struct gpgpu_ptx_sim_arg *arg
}
}
-int ptx_branch_taken( void *thd )
-{
- ptx_thread_info *thread = (ptx_thread_info *) thd;
- return (thread != NULL) && thread->branch_taken();
-}
-
template<int activate_level>
bool ptx_debug_exec_dump_cond(int thd_uid, addr_t pc)
{
@@ -1810,8 +1872,8 @@ void gpgpu_ptx_sim_load_gpu_kernels()
ptx_parse();
ptxinfo_in = open_ptxinfo(g_filename);
ptxinfo_parse();
- load_static_globals(g_global_symbol_table,0x10000000,0xFFFFFFFF);
- load_constants(g_global_symbol_table);
+ load_static_globals(g_global_symbol_table,STATIC_ALLOC_LIMIT,0xFFFFFFFF);
+ load_constants(g_global_symbol_table,STATIC_ALLOC_LIMIT);
} else {
if (!g_override_embedded_ptx) {
g_used_embedded_ptx_files=1;
@@ -1819,8 +1881,8 @@ void gpgpu_ptx_sim_load_gpu_kernels()
ptx_info_t *s;
for ( s=g_ptx_source_array; s!=NULL; s=s->next ) {
gpgpu_ptx_sim_load_ptx_from_string(s->str, ++source_num);
- load_static_globals(g_global_symbol_table,0x10000000,0xFFFFFFFF);
- load_constants(g_global_symbol_table);
+ load_static_globals(g_global_symbol_table,STATIC_ALLOC_LIMIT,0xFFFFFFFF);
+ load_constants(g_global_symbol_table,STATIC_ALLOC_LIMIT);
}
} else {
g_filename = NULL;
@@ -1845,8 +1907,8 @@ void gpgpu_ptx_sim_load_gpu_kernels()
ptxinfo_in = open_ptxinfo(g_filename);
ptxinfo_parse();
g_filename = NULL;
- load_static_globals(g_global_symbol_table,0x10000000,0xFFFFFFFF);
- load_constants(g_global_symbol_table);
+ load_static_globals(g_global_symbol_table,STATIC_ALLOC_LIMIT,0xFFFFFFFF);
+ load_constants(g_global_symbol_table,STATIC_ALLOC_LIMIT);
}
free(namelist);
}
diff --git a/src/cuda-sim/instructions.cc b/src/cuda-sim/instructions.cc
index 7cdf0de..ffbcd8f 100644
--- a/src/cuda-sim/instructions.cc
+++ b/src/cuda-sim/instructions.cc
@@ -1326,7 +1326,41 @@ void cvt_impl( const ptx_instruction *pI, ptx_thread_info *thread )
thread->set_operand_value(dst,data);
}
-void cvta_impl( const ptx_instruction *pI, ptx_thread_info *thread ) { inst_not_implemented(pI); }
+void cvta_impl( const ptx_instruction *pI, ptx_thread_info *thread )
+{
+ ptx_reg_t data;
+
+ const operand_info &dst = pI->dst();
+ const operand_info &src1 = pI->src1();
+ unsigned space = pI->get_space();
+ bool to_non_generic = pI->is_to();
+
+ ptx_reg_t from_addr = thread->get_operand_value(src1);
+ addr_t from_addr_hw = (addr_t)from_addr.u64;
+ addr_t to_addr_hw = 0;
+ unsigned smid = thread->get_hw_sid();
+ unsigned hwtid = thread->get_hw_tid();
+
+ 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 = 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 = from_addr_hw; break;
+ default: abort();
+ }
+ }
+
+ ptx_reg_t to_addr;
+ to_addr.u64 = to_addr_hw;
+ thread->set_operand_value(dst,to_addr);
+}
void div_impl( const ptx_instruction *pI, ptx_thread_info *thread )
{
@@ -1402,7 +1436,33 @@ void fma_impl( const ptx_instruction *pI, ptx_thread_info *thread )
mad_def(pI,thread);
}
-void isspacep_impl( const ptx_instruction *pI, ptx_thread_info *thread ) { inst_not_implemented(pI); }
+void isspacep_impl( const ptx_instruction *pI, ptx_thread_info *thread )
+{
+ ptx_reg_t a;
+ bool t=false;
+
+ const operand_info &dst = pI->dst();
+ const operand_info &src1 = pI->src1();
+ unsigned space = pI->get_space();
+
+ a = thread->get_operand_value(src1);
+ addr_t addr = (addr_t)a.u64;
+ unsigned smid = thread->get_hw_sid();
+ 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 );
+ default: abort();
+ }
+
+ ptx_reg_t p;
+ p.pred = t?1:0;
+
+ thread->set_operand_value(dst,p);
+}
+
void ld_impl( const ptx_instruction *pI, ptx_thread_info *thread )
{
diff --git a/src/cuda-sim/memory.h b/src/cuda-sim/memory.h
index 6eebcf4..1ea3efe 100644
--- a/src/cuda-sim/memory.h
+++ b/src/cuda-sim/memory.h
@@ -84,7 +84,7 @@
#include <assert.h>
#include <string.h>
#include <string>
-#include "../util.h"
+#include "../abstract_hardware_model.h"
typedef address_type mem_addr_t;
diff --git a/src/cuda-sim/ptx.l b/src/cuda-sim/ptx.l
index 9e45bc3..4711470 100644
--- a/src/cuda-sim/ptx.l
+++ b/src/cuda-sim/ptx.l
@@ -305,6 +305,8 @@ xor TC; ptx_lval.int_value = XOR_OP; return OPCODE;
\.gl TC; return GLOBAL_OPTION;
\.cta TC; return CTA_OPTION;
+\.to TC; return TO_OPTION;
+
\.and TC; return ATOMIC_AND;
\.or TC; return ATOMIC_OR;
\.xor TC; return ATOMIC_XOR;
diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y
index 4f1502a..7b4c17a 100644
--- a/src/cuda-sim/ptx.y
+++ b/src/cuda-sim/ptx.y
@@ -195,6 +195,7 @@
%token ALL_OPTION
%token GLOBAL_OPTION
%token CTA_OPTION
+%token TO_OPTION
%type <int_value> function_decl_header
%type <ptr_value> function_decl
@@ -384,7 +385,9 @@ option: type_spec
| FTZ_OPTION { add_option(FTZ_OPTION); }
| APPROX_OPTION { add_option(APPROX_OPTION); }
| FULL_OPTION { add_option(FULL_OPTION); }
- | atomic_operation_spec ;
+ | atomic_operation_spec
+ | TO_OPTION { add_option(TO_OPTION); }
+ ;
atomic_operation_spec: ATOMIC_AND { add_option(ATOMIC_AND); }
| ATOMIC_OR { add_option(ATOMIC_OR); }
diff --git a/src/cuda-sim/ptx_ir.h b/src/cuda-sim/ptx_ir.h
index 67b274c..3f2080b 100644
--- a/src/cuda-sim/ptx_ir.h
+++ b/src/cuda-sim/ptx_ir.h
@@ -78,7 +78,7 @@
#include "ptx.tab.h"
#include "ptx_sim.h"
#include "dram_callback.h"
- #include "../util.h"
+ #include "../abstract_hardware_model.h"
#include "memory.h"
@@ -807,6 +807,7 @@ public:
bool is_lo() const { return m_lo;}
bool is_wide() const { return m_wide;}
bool is_uni() const { return m_uni;}
+ bool is_to() const { return m_to_option; }
unsigned rounding_mode() const { return m_rounding_mode;}
unsigned saturation_mode() const { return m_saturation_mode;}
unsigned dimension() const { return m_geom_spec;}
@@ -836,6 +837,7 @@ private:
bool m_hi;
bool m_lo;
bool m_uni; //if branch instruction, this evaluates to true for uniform branches (ie jumps)
+ bool m_to_option;
unsigned m_rounding_mode;
unsigned m_compare_op;
unsigned m_saturation_mode;
diff --git a/src/cuda-sim/ptx_sim.h b/src/cuda-sim/ptx_sim.h
index 17eb250..b4a78c8 100644
--- a/src/cuda-sim/ptx_sim.h
+++ b/src/cuda-sim/ptx_sim.h
@@ -68,10 +68,8 @@
#include <stdlib.h>
#include "dram_callback.h"
-#include "../util.h"
#include "../abstract_hardware_model.h"
-typedef address_type addr_t;
struct dim3 {
unsigned int x, y, z;
@@ -450,6 +448,14 @@ private:
unsigned type_decode( unsigned type, size_t &size, int &t );
+addr_t generic_to_local( unsigned smid, unsigned hwtid, addr_t addr );
+addr_t generic_to_shared( unsigned smid, addr_t addr );
+addr_t local_to_generic( unsigned smid, unsigned hwtid, addr_t addr );
+addr_t shared_to_generic( unsigned smid, 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 );
+
#endif
#define MAX_REG_OPERANDS 8