diff options
Diffstat (limited to 'libcuda')
| -rw-r--r-- | libcuda/cuda_runtime_api.cc | 41 | ||||
| -rw-r--r-- | libcuda/cuobjdump.l | 66 | ||||
| -rw-r--r-- | libcuda/cuobjdump.y | 25 |
3 files changed, 101 insertions, 31 deletions
diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index eed4017..910bebd 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -1457,18 +1457,22 @@ std::list<cuobjdumpSection*> pruneSectionList(std::list<cuobjdumpSection*> cuobj std::list<cuobjdumpSection*> prunedList; - //Find the highest capability (that is lower than the forces maximum) for each cubin file + //Find the highest capability (that is lower than the forced maximum) for each cubin file //and set it in cuobjdumpSectionMap. Do this only for ptx sections std::map<std::string, unsigned> cuobjdumpSectionMap; + int min_ptx_capability_found=0; for ( std::list<cuobjdumpSection*>::iterator iter = cuobjdumpSectionList.begin(); iter != cuobjdumpSectionList.end(); iter++){ unsigned capability = (*iter)->getArch(); - if(dynamic_cast<cuobjdumpPTXSection*>(*iter) != NULL && - (capability <= forced_max_capability || - forced_max_capability==0)) { - if(cuobjdumpSectionMap[(*iter)->getIdentifier()] < capability) - cuobjdumpSectionMap[(*iter)->getIdentifier()] = capability; + if(dynamic_cast<cuobjdumpPTXSection*>(*iter) != NULL){ + if(capability<min_ptx_capability_found || min_ptx_capability_found==0) + min_ptx_capability_found=capability; + if (capability <= forced_max_capability || forced_max_capability==0) { + if((cuobjdumpSectionMap.find((*iter)->getIdentifier())==cuobjdumpSectionMap.end()) + || (cuobjdumpSectionMap[(*iter)->getIdentifier()] < capability)) + cuobjdumpSectionMap[(*iter)->getIdentifier()] = capability; + } } } @@ -1484,6 +1488,10 @@ std::list<cuobjdumpSection*> pruneSectionList(std::list<cuobjdumpSection*> cuobj delete *iter; } } + if(prunedList.empty()){ + printf("Error: No PTX sections found with sm capability that is lower than current forced maximum capability \n minimum ptx capability found = %u, maximum forced ptx capability = %u \n User might want to change either the forced maximum capability from gpgpusim configuration or update the compilation to generate the required PTX version\n",min_ptx_capability_found,forced_max_capability); + abort(); + } return prunedList; } @@ -1567,6 +1575,16 @@ void cuobjdumpParseBinary(unsigned int handle){ fatbin_registered[handle] = true; CUctx_st *context = GPGPUSim_Context(); + unsigned max_capability = 0; + for ( std::list<cuobjdumpSection*>::iterator iter = cuobjdumpSectionList.begin(); + iter != cuobjdumpSectionList.end(); + iter++){ + unsigned capability = (*iter)->getArch(); + if (capability > max_capability) max_capability = capability; + } + + if (max_capability > 20) printf("WARNING: No guarantee that PTX will be parsed for SM version %u\n", max_capability); + std::string fname = fatbinmap[handle]; cuobjdumpPTXSection* ptx = findPTXSection(fname); @@ -1589,13 +1607,13 @@ void cuobjdumpParseBinary(unsigned int handle){ symtab=gpgpu_ptx_sim_load_ptx_from_string(ptxplus_str, handle); printf("Adding %s with cubin handle %u\n", ptx->getPTXfilename().c_str(), handle); context->add_binary(symtab, handle); - gpgpu_ptxinfo_load_from_string( ptxcode, handle); + gpgpu_ptxinfo_load_from_string( ptxcode, handle, max_capability ); delete[] ptxplus_str; } else { symtab=gpgpu_ptx_sim_load_ptx_from_string(ptxcode, handle); printf("Adding %s with cubin handle %u\n", ptx->getPTXfilename().c_str(), handle); context->add_binary(symtab, handle); - gpgpu_ptxinfo_load_from_string( ptxcode, handle); + gpgpu_ptxinfo_load_from_string( ptxcode, handle, max_capability ); } load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF,context->get_device()->get_gpgpu()); load_constants(symtab,STATIC_ALLOC_LIMIT,context->get_device()->get_gpgpu()); @@ -1624,10 +1642,13 @@ void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin ) // - Obtains the pointer to the actual fatbin structure from the FatBin handle (fatCubin). // - An integer inside the fatbin structure contains the relative offset to the source code file name. // - This offset differs among different CUDA and GCC versions. + #if (CUDART_VERSION <= 6000) char * pfatbin = (char*) fatDeviceText->d; int offset = *((int*)(pfatbin+48)); char * filename = (pfatbin+16+offset); - + #else + char * filename = "default"; + #endif // The extracted file name is associated with a fat_cubin_handle passed // into cudaLaunch(). Inside cudaLaunch(), the associated file name is // used to find the PTX/SASS section from cuobjdump, which contains the @@ -1693,7 +1714,7 @@ void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin ) } else { symtab=gpgpu_ptx_sim_load_ptx_from_string(ptx,source_num); context->add_binary(symtab,fat_cubin_handle); - gpgpu_ptxinfo_load_from_string( ptx, source_num ); + gpgpu_ptxinfo_load_from_string( ptx, source_num, max_capability ); } source_num++; load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF,context->get_device()->get_gpgpu()); diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index d7086ad..f63ee73 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -52,8 +52,12 @@ void cuobjdump_error(const char*); %s ptxcode %s sasscode %s elfcode -%s header +%s elfheader +%s ptxheader %s endheader +%x identifier +%x conidentifier +%s endidentifier alpha [a-zA-Z] numeric [0-9] @@ -67,16 +71,20 @@ newlines {newline}+ "ptxasOptions"{notnewline}*{newline} [1-9]{numeric}* yylval.string_value = strdup(yytext); return DECIMAL; +"has debug info"{newline} + "Fatbin ptx code:"{newline} { yy_push_state(ptxcode); - yy_push_state(header); + yy_push_state(identifier); + yy_push_state(ptxheader); yylval.string_value = strdup(yytext); return PTXHEADER; } "Fatbin elf code:"{newline} { yy_push_state(elfcode); - yy_push_state(header); + yy_push_state(identifier); + yy_push_state(elfheader); yylval.string_value = strdup(yytext); return ELFHEADER; } @@ -94,22 +102,50 @@ newlines {newline}+ /*SASS code tokens*/ <sasscode>{notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; +<identifier>{newline}"compressed"{newline} BEGIN(conidentifier); return H_COMPRESSED; +<identifier>{newline}"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; +<identifier>{newline}{newline} yy_pop_state(); + + +<conidentifier>"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; +<conidentifier>{newline} yy_pop_state(); + + +<endidentifier>{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; + + + /*Header tokens*/ -<header>[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; -<header>"================" return H_SEPARATOR; -<header>"arch = " return H_ARCH; -<header>"code version = " return H_CODEVERSION; -<header>\[{numeric},{numeric}\] return CODEVERSION; -<header>"producer = " return H_PRODUCER; -<header>"host = " return H_HOST; -<header>"compile_size = " return H_COMPILESIZE; -<header>"compressed"{newline} -<header>"identifier = " BEGIN(endheader); return H_IDENTIFIER; -<header>"has debug info"{newline} +<elfheader>[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +<elfheader>"================" return H_SEPARATOR; +<elfheader>"arch = " return H_ARCH; +<elfheader>"code version = " return H_CODEVERSION; +<elfheader>\[{numeric},{numeric}\] return CODEVERSION; +<elfheader>"producer = " return H_PRODUCER; +<elfheader>"<unknown>" return H_UNKNOWN; +<elfheader>"host = " return H_HOST; +<elfheader>"compile_size = " BEGIN(endheader); return H_COMPILESIZE; + + + /*Header tokens*/ +<ptxheader>[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +<ptxheader>"================" return H_SEPARATOR; +<ptxheader>"arch = " return H_ARCH; +<ptxheader>"code version = " return H_CODEVERSION; +<ptxheader>\[{numeric},{numeric}\] return CODEVERSION; +<ptxheader>"producer = " return H_PRODUCER; +<ptxheader>"host = " return H_HOST; +<ptxheader>"compile_size = " BEGIN(endheader); return H_COMPILESIZE; + + + + + /* Looking for the identifier (filename) then the header is done */ /* <endheader>[[:alnum:]_\./]+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; */ -<endheader>{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; +<endheader>{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return IDENTIFIER; + {newline} return NEWLINE; diff --git a/libcuda/cuobjdump.y b/libcuda/cuobjdump.y index ec97283..dce7e3d 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -47,7 +47,7 @@ char filename [1024]; %union { char* string_value; } -%token <string_value> H_SEPARATOR H_ARCH H_CODEVERSION H_PRODUCER H_HOST H_COMPILESIZE H_IDENTIFIER +%token <string_value> H_SEPARATOR H_ARCH H_CODEVERSION H_PRODUCER H_HOST H_COMPILESIZE H_IDENTIFIER H_UNKNOWN H_COMPRESSED %token <string_value> CODEVERSION %token <string_value> STRING %token <string_value> FILENAME @@ -61,6 +61,7 @@ char filename [1024]; %% + program : {printf("######### cuobjdump parser ########\n");} emptylines section | program section; @@ -73,7 +74,7 @@ section : PTXHEADER { snprintf(filename, 1024, "_cuobjdump_%d.ptx", ptxserial++); ptxfile = fopen(filename, "w"); setCuobjdumpptxfilename(filename); - } headerinfo ptxcode { + } headerinfo compressedkeyword identifier ptxcode { fclose(ptxfile); } | ELFHEADER { @@ -81,7 +82,8 @@ section : PTXHEADER { snprintf(filename, 1024, "_cuobjdump_%d.elf", elfserial); elffile = fopen(filename, "w"); setCuobjdumpelffilename(filename); - } headerinfo elfcode { + } headerinfo identifier{ + } elfcode { fclose(elffile); snprintf(filename, 1024, "_cuobjdump_%d.sass", elfserial++); sassfile = fopen(filename, "w"); @@ -93,15 +95,26 @@ section : PTXHEADER { headerinfo : H_SEPARATOR NEWLINE H_ARCH IDENTIFIER NEWLINE H_CODEVERSION CODEVERSION NEWLINE + H_PRODUCER H_UNKNOWN NEWLINE + H_HOST IDENTIFIER NEWLINE + H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4);}; + | H_SEPARATOR NEWLINE + H_ARCH IDENTIFIER NEWLINE + H_CODEVERSION CODEVERSION NEWLINE H_PRODUCER IDENTIFIER NEWLINE H_HOST IDENTIFIER NEWLINE - H_COMPILESIZE IDENTIFIER NEWLINE - H_IDENTIFIER FILENAME emptylines {setCuobjdumparch($4); setCuobjdumpidentifier($19);}; + H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4);}; + +identifier : H_IDENTIFIER FILENAME emptylines {setCuobjdumpidentifier($2);} + | {setCuobjdumpidentifier("default");}; + +compressedkeyword : H_COMPRESSED emptylines + | ; ptxcode : ptxcode PTXLINE {fprintf(ptxfile, "%s", $2);} | ; -elfcode : elfcode ELFLINE {fprintf(elffile, "%s", $2);} +elfcode : elfcode ELFLINE {printf(elffile, "%s", $2);} | ; sasscode : sasscode SASSLINE {fprintf(sassfile, "%s", $2);} |
