summaryrefslogtreecommitdiff
path: root/src/cuda-sim/ptx_ir.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuda-sim/ptx_ir.cc')
-rw-r--r--src/cuda-sim/ptx_ir.cc137
1 files changed, 5 insertions, 132 deletions
diff --git a/src/cuda-sim/ptx_ir.cc b/src/cuda-sim/ptx_ir.cc
index cd70daf..5945b72 100644
--- a/src/cuda-sim/ptx_ir.cc
+++ b/src/cuda-sim/ptx_ir.cc
@@ -191,6 +191,8 @@ void symbol_table::add_function( function_info *func, const char *filename, unsi
m_symbols[ func->get_name() ] = s;
}
+void register_ptx_function( const char *name, function_info *impl ); // either libcuda or libopencl
+
bool symbol_table::add_function_decl( const char *name, int entry_point, function_info **func_info, symbol_table **sym_table )
{
std::string key = std::string(name);
@@ -209,13 +211,14 @@ bool symbol_table::add_function_decl( const char *name, int entry_point, functio
*sym_table = m_function_symtab_lookup[key];
} else {
assert( !prior_decl );
- *sym_table = new symbol_table( "", entry_point, g_global_symbol_table );
+ *sym_table = new symbol_table( "", entry_point, this );
symbol *null_reg = (*sym_table)->add_variable("_",NULL,0,"",0);
null_reg->set_regno(0, 0);
(*sym_table)->set_name(name);
(*func_info)->set_symtab(*sym_table);
m_function_symtab_lookup[key] = *sym_table;
- register_ptx_function(name,*func_info,*sym_table);
+ assert( (*func_info)->get_symtab() == *sym_table );
+ register_ptx_function(name,*func_info);
}
return prior_decl;
}
@@ -1010,8 +1013,6 @@ void function_info::print_insn( unsigned pc, FILE * fp ) const
}
}
-static int g_save_embedded_ptx = 0;
-
extern "C" int ptx_parse();
extern "C" int ptx__scan_string(const char*);
extern "C" FILE *ptx_in;
@@ -1021,128 +1022,6 @@ extern "C" int ptxinfo_parse();
extern "C" int ptxinfo_debug;
extern "C" FILE *ptxinfo_in;
-static void print_ptx_file( const char *p, unsigned source_num, const char *filename );
-
-void ptx_reg_options(option_parser_t opp)
-{
- option_parser_register(opp, "-save_embedded_ptx", OPT_BOOL, &g_save_embedded_ptx,
- "saves ptx files embedded in binary as <n>.ptx",
- "0");
-}
-
-void gpgpu_ptx_sim_load_ptx_from_string( const char *p, unsigned source_num )
-{
- char buf[1024];
- snprintf(buf,1024,"_%u.ptx", source_num );
- if( g_save_embedded_ptx ) {
- FILE *fp = fopen(buf,"w");
- fprintf(fp,"%s",p);
- fclose(fp);
- }
- init_parser(buf);
- ptx__scan_string(p);
- int errors = ptx_parse ();
- if ( errors ) {
- char fname[1024];
- snprintf(fname,1024,"_ptx_XXXXXX");
- int fd=mkstemp(fname);
- close(fd);
- printf("GPGPU-Sim PTX: parser error detected, exiting... but first extracting .ptx to \"%s\"\n", fname);
- FILE *ptxfile = fopen(fname,"w");
- fprintf(ptxfile,"%s", p );
- fclose(ptxfile);
- abort();
- exit(40);
- }
-
- if ( g_debug_execution >= 100 )
- print_ptx_file(p,source_num,buf);
-
- printf("GPGPU-Sim PTX: finished parsing EMBEDDED .ptx file %s\n",buf);
-
- char fname[1024];
- snprintf(fname,1024,"_ptx_XXXXXX");
- int fd=mkstemp(fname);
- close(fd);
-
- printf("GPGPU-Sim PTX: extracting embedded .ptx to temporary file \"%s\"\n", fname);
- FILE *ptxfile = fopen(fname,"w");
- fprintf(ptxfile,"%s",p);
- fclose(ptxfile);
-
- char fname2[1024];
- snprintf(fname2,1024,"_ptx2_XXXXXX");
- fd=mkstemp(fname2);
- close(fd);
- char commandline2[4096];
- snprintf(commandline2,4096,"cat %s | sed 's/.version 1.5/.version 1.4/' | sed 's/, texmode_independent//' | sed 's/\\(\\.extern \\.const\\[1\\] .b8 \\w\\+\\)\\[\\]/\\1\\[1\\]/' | sed 's/const\\[.\\]/const\\[0\\]/g' > %s", fname, fname2);
- int result = system(commandline2);
- if( result != 0 ) {
- printf("GPGPU-Sim PTX: ERROR ** while loading PTX (a) %d\n", result);
- printf(" Ensure you have write access to simulation directory\n");
- printf(" and have \'cat\' and \'sed\' in your path.\n");
- exit(1);
- }
-
- char tempfile_ptxinfo[1024];
- snprintf(tempfile_ptxinfo,1024,"%sinfo",fname);
- char commandline[1024];
- char extra_flags[1024];
- extra_flags[0]=0;
-#if CUDART_VERSION >= 3000
- snprintf(extra_flags,1024,"--gpu-name=sm_20");
-#endif
- snprintf(commandline,1024,"ptxas %s -v %s --output-file /dev/null 2> %s",
- extra_flags, fname2, tempfile_ptxinfo);
- printf("GPGPU-Sim PTX: generating ptxinfo using \"%s\"\n", commandline);
- result = system(commandline);
- if( result != 0 ) {
- printf("GPGPU-Sim PTX: ERROR ** while loading PTX (b) %d\n", result);
- printf(" Ensure ptxas is in your path.\n");
- exit(1);
- }
-
- ptxinfo_in = fopen(tempfile_ptxinfo,"r");
- g_ptxinfo_filename = tempfile_ptxinfo;
- ptxinfo_parse();
- snprintf(commandline,1024,"rm -f %s %s %s", fname, fname2, tempfile_ptxinfo);
- printf("GPGPU-Sim PTX: removing ptxinfo using \"%s\"\n", commandline);
- result = system(commandline);
- if( result != 0 ) {
- printf("GPGPU-Sim PTX: ERROR ** while loading PTX (c) %d\n", result);
- exit(1);
- }
-}
-
-
-const ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber );
-
-void print_ptx_file( const char *p, unsigned source_num, const char *filename )
-{
- printf("\nGPGPU-Sim PTX: file _%u.ptx contents:\n\n", source_num );
- char *s = strdup(p);
- char *t = s;
- unsigned n=1;
- while ( *t != '\0' ) {
- char *u = t;
- while ( (*u != '\n') && (*u != '\0') ) u++;
- unsigned last = (*u == '\0');
- *u = '\0';
- const ptx_instruction *pI = ptx_instruction_lookup(filename,n);
- char pc[64];
- if( pI && pI->get_PC() )
- snprintf(pc,64,"%4u", pI->get_PC() );
- else
- snprintf(pc,64," ");
- printf(" _%u.ptx %4u (pc=%s): %s\n", source_num, n, pc, t );
- if ( last ) break;
- t = u+1;
- n++;
- }
- free(s);
- fflush(stdout);
-}
-
void gpgpu_ptx_assemble( std::string kname, void *kinfo )
{
function_info *func_info = (function_info *)kinfo;
@@ -1150,12 +1029,6 @@ void gpgpu_ptx_assemble( std::string kname, void *kinfo )
printf("GPGPU-Sim PTX: skipping assembly for extern declared function \'%s\'\n", func_info->get_name().c_str() );
return;
}
- if( g_kernel_name_to_symtab_lookup[ kname ] == NULL ) {
- printf("\nGPGPU-Sim PTX: ERROR no information for kernel \'%s\'\n"
- " this can happen for kernels contained in CUDA\n"
- " libraries (such as CUBLAS, CUFFT, or CUDPP)\n", kname.c_str() );
- exit(1);
- }
g_func_info = func_info;
func_info->ptx_assemble();
}