summaryrefslogtreecommitdiff
path: root/src/cuda-sim/ptx_loader.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuda-sim/ptx_loader.cc')
-rw-r--r--src/cuda-sim/ptx_loader.cc268
1 files changed, 0 insertions, 268 deletions
diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc
index c836fac..d4f3822 100644
--- a/src/cuda-sim/ptx_loader.cc
+++ b/src/cuda-sim/ptx_loader.cc
@@ -77,286 +77,18 @@ memory_space *g_surf_mem;
memory_space *g_param_mem;
bool g_override_embedded_ptx = false;
-struct ptx_info_t {
- unsigned fat_cubin_handle;
- char *str;
- char *cubin_str;
- char *fname;
- ptx_info_t *next;
- unsigned capability;
-};
-
/// extern prototypes
extern "C" int ptx_parse();
extern "C" int ptx__scan_string(const char*);
-extern "C" FILE *ptx_in;
extern "C" const char *g_ptxinfo_filename = NULL;
extern "C" int ptxinfo_parse();
extern "C" int ptxinfo_debug;
extern "C" FILE *ptxinfo_in;
-extern int g_ptx_convert_to_ptxplus;
extern int g_ptx_save_converted_ptxplus;
-extern unsigned g_ptx_force_max_capability;
-
-/// static functions
-
-static int load_static_globals( symbol_table *symtab, unsigned min_gaddr, unsigned max_gaddr)
-{
- printf( "GPGPU-Sim PTX: loading globals with explicit initializers... \n" );
- fflush(stdout);
- int ng_bytes=0;
- symbol_table::iterator g=symtab->global_iterator_begin();
-
- for ( ; g!=symtab->global_iterator_end(); g++) {
- symbol *global = *g;
- if ( global->has_initializer() ) {
- printf( "GPGPU-Sim PTX: initializing '%s' ... ", global->name().c_str() );
- unsigned addr=global->get_address();
- const type_info *type = global->type();
- type_info_key ti=type->get_key();
- size_t size;
- int t;
- ti.type_decode(size,t);
- int nbytes = size/8;
- int offset=0;
- std::list<operand_info> init_list = global->get_initializer();
- for ( std::list<operand_info>::iterator i=init_list.begin(); i!=init_list.end(); i++ ) {
- operand_info op = *i;
- ptx_reg_t value = op.get_literal_value();
- assert( (addr+offset+nbytes) < min_gaddr ); // min_gaddr is start of "heap" for cudaMalloc
- g_global_mem->write(addr+offset,nbytes,&value,NULL,NULL); // assuming little endian here
- offset+=nbytes;
- ng_bytes+=nbytes;
- }
- printf(" wrote %u bytes\n", offset );
- }
- }
- printf( "GPGPU-Sim PTX: finished loading globals (%u bytes total).\n", ng_bytes );
- fflush(stdout);
- return ng_bytes;
-}
-
-static int load_constants( symbol_table *symtab, addr_t min_gaddr )
-{
- printf( "GPGPU-Sim PTX: loading constants with explicit initializers... " );
- fflush(stdout);
- int nc_bytes = 0;
- symbol_table::iterator g=symtab->const_iterator_begin();
-
- for ( ; g!=symtab->const_iterator_end(); g++) {
- symbol *constant = *g;
- if ( constant->is_const() && constant->has_initializer() ) {
- // get the constant element data size
- int basic_type;
- size_t num_bits;
- constant->type()->get_key().type_decode(num_bits,basic_type);
-
- std::list<operand_info> init_list = constant->get_initializer();
- int nbytes_written = 0;
- for ( std::list<operand_info>::iterator i=init_list.begin(); i!=init_list.end(); i++ ) {
- operand_info op = *i;
- ptx_reg_t value = op.get_literal_value();
- int nbytes = num_bits/8;
- switch ( op.get_type() ) {
- case int_t: assert(nbytes >= 1); break;
- case float_op_t: assert(nbytes == 4); break;
- case double_op_t: assert(nbytes >= 4); break; // account for double DEMOTING
- default:
- abort();
- }
- unsigned addr=constant->get_address() + nbytes_written;
- assert( addr+nbytes < min_gaddr );
-
- g_global_mem->write(addr,nbytes,&value,NULL,NULL); // assume little endian (so u8 is the first byte in u32)
- nc_bytes+=nbytes;
- nbytes_written += nbytes;
- }
- }
- }
- printf( " done.\n");
- fflush(stdout);
- return nc_bytes;
-}
-
-static FILE *open_ptxinfo (const char* ptx_filename)
-{
- const int ptx_fnamelen = strlen(ptx_filename);
- char *ptxi_fname = new char[ptx_fnamelen+5];
- strcpy (ptxi_fname, ptx_filename);
- strcpy (ptxi_fname+ptx_fnamelen, "info");
-
- //ptxinfo_debug=1;
- g_ptxinfo_filename = ptxi_fname;
- FILE *f = fopen (ptxi_fname, "rt");
- return f;
-}
-
-static int ptx_file_filter(
-#if !defined(__APPLE__)
- const
-#endif
- struct dirent *de )
-{
- const char *tmp = strstr(de->d_name,".ptx");
- if ( tmp != NULL && tmp[4] == 0 ) {
- return 1;
- }
- return 0;
-}
-
-// global functions
-
-static ptx_info_t *g_ptx_source_array = NULL;
-static unsigned g_ptx_max_capability = 0;
-
-void gpgpu_ptx_sim_load_gpu_kernels()
-{
- static unsigned source_num = 0;
- ptx_in = NULL;
- if ( g_filename )
- ptx_in = fopen( g_filename, "r" );
- gpgpu_ptx_sim_init_memory();
- if (ptx_in) {
- symbol_table *symtab=init_parser(g_filename);
- ptx_parse();
- ptxinfo_in = open_ptxinfo(g_filename);
- ptxinfo_parse();
- load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF);
- load_constants(symtab,STATIC_ALLOC_LIMIT);
- } else {
- if (!g_override_embedded_ptx) {
- printf("GPGPU-Sim PTX: USING EMBEDDED .ptx files...\n");
- unsigned selected_capability = 0;
-
- if(g_ptx_force_max_capability == 0) {
- // No forced max capability, selected the highest capability
- //assert(g_ptx_max_capability > 0);
- selected_capability = g_ptx_max_capability;
- printf("GPGPU-Sim PTX: Loading PTX, selected capability: compute_%u\n", selected_capability);
- } else {
- // Forced max capability, select the highest capability less than or equal to forced capability
- ptx_info_t *pti;
- for( pti=g_ptx_source_array; pti!=NULL; pti=pti->next ){
- if(selected_capability < pti->capability && pti->capability <= g_ptx_force_max_capability)
- selected_capability = pti->capability;
- }
- //assert(selected_capability > 0);
- printf("GPGPU-Sim PTX: Loading PTX, max forced capability: compute_%u, selected capability: compute_%u\n",
- g_ptx_force_max_capability, selected_capability);
- }
-
- ptx_info_t *s;
- for ( s=g_ptx_source_array; s!=NULL; s=s->next ) {
- if(s->capability != selected_capability)
- continue;
-
- printf("GPGPU-Sim PTX: Loading PTX for %s, capability = compute_%u\n", s->fname, s->capability);
-
- symbol_table *symtab;
- source_num++;
- if(g_ptx_convert_to_ptxplus) {
- char *ptxplus_str = gpgpu_ptx_sim_convert_ptx_to_ptxplus(s->str, s->cubin_str, source_num);
- symtab=gpgpu_ptx_sim_load_ptx_from_string(ptxplus_str, s->str, source_num);
- delete[] ptxplus_str;
- } else {
- symtab=gpgpu_ptx_sim_load_ptx_from_string(s->str, s->str, source_num);
- }
- load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF);
- load_constants(symtab,STATIC_ALLOC_LIMIT);
- }
- } else {
- if(g_ptx_convert_to_ptxplus) {
- perror("GPGPU-Sim PTX: convert_to_ptxplus option enabled. Cannot use this option with external ptx files.\n");
- assert(0);
- }
- const char *filename = NULL;
- struct dirent **namelist;
- int n = scandir(".", &namelist, ptx_file_filter, alphasort);
- if (n < 0)
- perror("GPGPU-Sim PTX: no PTX files returned by scandir");
- else {
- while (n--) {
- filename = namelist[n]->d_name;
- printf("Parsing %s..\n", filename);
- ptx_in = fopen( filename, "r" );
- symbol_table *symtab=init_parser(filename);
- ptx_parse ();
- ptxinfo_in = open_ptxinfo(filename);
- ptxinfo_parse();
- load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF);
- load_constants(symtab,STATIC_ALLOC_LIMIT);
-
- free(namelist[n]);
- }
- free(namelist);
- }
- }
- }
-
- if ( ptx_in == NULL && g_override_embedded_ptx ) {
- printf("GPGPU-Sim PTX Simulator error: Could find/open .ptx file for reading\n");
- printf(" This means there are no .ptx files in the current directory.\n");
- printf(" Either place a .ptx file in the current directory, or ensure\n" );
- printf(" the PTX_SIM_KERNELFILE environment variable points to .ptx file.\n");
- printf(" PTX_SIM_KERNELFILE=\"%s\"\n", g_filename );
- exit(1);
- }
-
- if ( g_error_detected ) {
- printf( "GPGPU-Sim PTX: PTX parsing errors detected -- exiting.\n" );
- exit(1);
- }
- printf( "GPGPU-Sim PTX: Program parsing completed\n" );
-
- if ( g_kernel_name_to_function_lookup ) {
- for ( std::map<std::string,function_info*>::iterator f=g_kernel_name_to_function_lookup->begin();
- f != g_kernel_name_to_function_lookup->end(); f++ ) {
- gpgpu_ptx_assemble(f->first,f->second);
- }
- }
-}
-
-void gpgpu_ptx_sim_add_ptxstring( unsigned fat_cubin_handle, const char *ptx_string, const char *cubin_string, const char *sourcefname, unsigned capability )
-{
- ptx_info_t *t = new ptx_info_t;
- t->next = NULL;
- t->str = strdup(ptx_string);
- t->fat_cubin_handle = fat_cubin_handle;
- if (cubin_string != NULL) {
- t->cubin_str = strdup(cubin_string);
- } else {
- if(g_ptx_convert_to_ptxplus != 0) {
- printf("GPGPU-Sim PTX: ERROR cubin information, required for ptxplus, missing from fat bin object\n");
- printf("GPGPU-Sim PTX: ptxplus currently requires CUDA 2.3 or earlier... disable ptxplus by removing\n");
- printf("GPGPU-Sim PTX: \'-gpgpu_ptx_convert_to_ptxplus 1\' in \'gpgpusim.config\'\n");
- abort();
- }
- t->cubin_str = NULL;
- }
- t->fname = strdup(sourcefname);
- t->capability = capability;
-
- // Set overall max capability
- if(g_ptx_max_capability < capability)
- g_ptx_max_capability = capability;
-
- // put ptx source into a fifo
- if (g_ptx_source_array == NULL) {
- // first ptx source
- g_ptx_source_array = t;
- } else {
- // insert subsequent ptx source at the end of queue
- ptx_info_t *l_ptx_source = g_ptx_source_array;
- while (l_ptx_source->next != NULL) {
- l_ptx_source = l_ptx_source->next;
- }
- l_ptx_source->next = t;
- }
-}
static bool g_save_embedded_ptx;
bool g_keep_intermediate_files;