diff options
| author | Mengchi Zhang <[email protected]> | 2019-05-08 14:31:31 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-05-08 14:31:31 -0400 |
| commit | 7815b7ee86d4716e7133d91dd0c53d41580861b0 (patch) | |
| tree | 562d4b6708804e29a98c749f22bc0e5d58c91db3 | |
| parent | 204e6bf66c468f9ed8b42ea71ed74c5352d3c902 (diff) | |
| parent | dab24b95a31bf1401e42237ae2b46ab3df22058c (diff) | |
Merge pull request #2 from echoedit/dev
Move GPGPU-Sim to no reentrant
| -rw-r--r-- | libcuda/cuda_runtime_api.cc | 21 | ||||
| -rw-r--r-- | libcuda/cuobjdump.l | 53 | ||||
| -rw-r--r-- | libcuda/cuobjdump.y | 12 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_loader.cc | 34 | ||||
| -rw-r--r-- | src/cuda-sim/ptxinfo.l | 35 | ||||
| -rw-r--r-- | src/cuda-sim/ptxinfo.y | 15 |
6 files changed, 113 insertions, 57 deletions
diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index 3a9d613..11dcd5a 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -1971,8 +1971,11 @@ void setCuobjdumpsassfilename(const char* filename){ } (dynamic_cast<cuobjdumpELFSection*>(cuobjdumpSectionList.front()))->setSASSfilename(filename); } -extern int cuobjdump_parse(); -extern FILE *cuobjdump_in; +typedef void * yyscan_t; +extern int cuobjdump_lex_init(yyscan_t* scanner); +extern void cuobjdump_set_in (FILE * _in_str ,yyscan_t yyscanner ); +extern int cuobjdump_parse(yyscan_t scanner); +extern int cuobjdump_lex_destroy(yyscan_t scanner); //! Return the executable file of the process containing the PTX/SASS code //! @@ -2181,9 +2184,14 @@ void extract_code_using_cuobjdump(){ if (parse_output) { printf("Parsing file %s\n", fname); + FILE *cuobjdump_in; cuobjdump_in = fopen(fname, "r"); - cuobjdump_parse(); + yyscan_t scanner; + cuobjdump_lex_init(&scanner); + cuobjdump_set_in(cuobjdump_in, scanner); + cuobjdump_parse(scanner); + cuobjdump_lex_destroy(scanner); fclose(cuobjdump_in); printf("Done parsing!!!\n"); } else { @@ -2231,8 +2239,13 @@ void extract_code_using_cuobjdump(){ std::cout << "Done" << std::endl; std::cout << "Trying to parse " << libcodfn.str() << std::endl; + FILE *cuobjdump_in; cuobjdump_in = fopen(libcodfn.str().c_str(), "r"); - cuobjdump_parse(); + yyscan_t scanner; + cuobjdump_lex_init(&scanner); + cuobjdump_set_in(cuobjdump_in, scanner); + cuobjdump_parse(scanner); + cuobjdump_lex_destroy(scanner); fclose(cuobjdump_in); std::getline(libsf, line); } diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index 2b0dac8..9359281 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -38,9 +38,7 @@ #define YYDEBUG 1 -#define yylval cuobjdump_lval - -void cuobjdump_error(const char*); +void cuobjdump_error(yyscan_t yyscanner, const char* msg); %} %option stack @@ -48,6 +46,8 @@ void cuobjdump_error(const char*); %option yylineno %option nounput +%option bison-bridge +%option reentrant %s ptxcode %s sasscode @@ -69,54 +69,54 @@ newlines {newline}+ "ptxasOptions"{notnewline}*{newline} -[1-9]{numeric}* yylval.string_value = strdup(yytext); return DECIMAL; +[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(identifier); - yy_push_state(ptxheader); - yylval.string_value = strdup(yytext); + yy_push_state(ptxcode, yyscanner); + yy_push_state(identifier, yyscanner); + yy_push_state(ptxheader, yyscanner); + yylval->string_value = strdup(yytext); return PTXHEADER; } "Fatbin elf code:"{newline} { - yy_push_state(elfcode); - yy_push_state(identifier); - yy_push_state(elfheader); - yylval.string_value = strdup(yytext); + yy_push_state(elfcode, yyscanner); + yy_push_state(identifier, yyscanner); + yy_push_state(elfheader, yyscanner); + yylval->string_value = strdup(yytext); return ELFHEADER; } /*PTX code tokens*/ -<ptxcode>{notnewline}*{newline} yylval.string_value = strdup(yytext); return PTXLINE; +<ptxcode>{notnewline}*{newline} yylval->string_value = strdup(yytext); return PTXLINE; /*ELF code tokens*/ <elfcode>{whitespace}*"code for sm_"{numeric}+{newline} { BEGIN(sasscode); - yylval.string_value = strdup(yytext); + yylval->string_value = strdup(yytext); return SASSLINE; } -<elfcode>{notnewline}*{newline} yylval.string_value = strdup(yytext); return ELFLINE; +<elfcode>{notnewline}*{newline} yylval->string_value = strdup(yytext); return ELFLINE; /*SASS code tokens*/ -<sasscode>{notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; +<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(); +<identifier>{newline}{newline} yy_pop_state(yyscanner); <conidentifier>"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; -<conidentifier>{newline} yy_pop_state(); +<conidentifier>{newline} yy_pop_state(yyscanner); -<endidentifier>{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; +<endidentifier>{notnewline}+ yylval->string_value = strdup(yytext); yy_pop_state(yyscanner); return FILENAME; /*Header tokens*/ -<elfheader>[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +<elfheader>[[:alnum:]_]+ yylval->string_value = strdup(yytext); return IDENTIFIER; <elfheader>"================" return H_SEPARATOR; <elfheader>"arch = " return H_ARCH; <elfheader>"code version = " return H_CODEVERSION; @@ -128,7 +128,7 @@ newlines {newline}+ /*Header tokens*/ -<ptxheader>[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +<ptxheader>[[:alnum:]_]+ yylval->string_value = strdup(yytext); return IDENTIFIER; <ptxheader>"================" return H_SEPARATOR; <ptxheader>"arch = " return H_ARCH; <ptxheader>"code version = " return H_CODEVERSION; @@ -143,7 +143,7 @@ newlines {newline}+ /* Looking for the identifier (filename) then the header is done */ -<endheader>{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return IDENTIFIER; +<endheader>{notnewline}+ yylval->string_value = strdup(yytext); yy_pop_state(yyscanner); return IDENTIFIER; @@ -153,11 +153,12 @@ newlines {newline}+ <<EOF>> BEGIN(INITIAL);return 0; /*No other rule matched. Throw an error*/ -. cuobjdump_error("Invalid token"); +. cuobjdump_error(yyscanner, "Invalid token"); %% -void cuobjdump_error(const char* message) +void cuobjdump_error(yyscan_t yyscanner, const char* msg) { - printf(" %s near \"%s\"",message, yytext); - printf(" on line %i\n",yylineno); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + printf(" %s near \"%s\"",msg, yytext); + printf(" on line %i\n",yylineno); } diff --git a/libcuda/cuobjdump.y b/libcuda/cuobjdump.y index 31760f7..66cbace 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -29,8 +29,8 @@ %{ #include <stdio.h> -int yylex(void); -void yyerror(const char*); +typedef void * yyscan_t; + extern void addCuobjdumpSection(int sectiontype); void setCuobjdumparch(const char* arch); void setCuobjdumpidentifier(const char* identifier); @@ -44,9 +44,17 @@ FILE *elffile; FILE *sassfile; char filename [1024]; %} +%define api.pure full +%parse-param {yyscan_t scanner} +%lex-param {yyscan_t scanner} + %union { char* string_value; } +%{ +int yylex(YYSTYPE * yylval_param, yyscan_t yyscanner); +void yyerror(yyscan_t yyscanner, const char* msg); +%} %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 diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc index 8c6f361..da7c32d 100644 --- a/src/cuda-sim/ptx_loader.cc +++ b/src/cuda-sim/ptx_loader.cc @@ -50,9 +50,12 @@ extern int ptx__scan_string(const char*); extern std::map<unsigned,const char*> get_duplicate(); const char *g_ptxinfo_filename; -extern int ptxinfo_parse(); -extern int ptxinfo_debug; -extern FILE *ptxinfo_in; + +typedef void * yyscan_t; +extern int ptxinfo_lex_init(yyscan_t* scanner); +extern void ptxinfo_set_in (FILE * _in_str ,yyscan_t yyscanner ); +extern int ptxinfo_parse(yyscan_t scanner); +extern int ptxinfo_lex_destroy(yyscan_t scanner); static bool g_save_embedded_ptx; static int g_occupancy_sm_number; @@ -347,8 +350,13 @@ void gpgpu_ptx_info_load_from_filename( const char *filename, unsigned sm_versio } g_ptxinfo_filename = strdup(ptxas_filename.c_str()); + FILE *ptxinfo_in; ptxinfo_in = fopen(g_ptxinfo_filename,"r"); - ptxinfo_parse(); + yyscan_t scanner; + ptxinfo_lex_init(&scanner); + ptxinfo_set_in(ptxinfo_in, scanner); + ptxinfo_parse(scanner); + ptxinfo_lex_destroy(scanner); fclose(ptxinfo_in); } @@ -410,9 +418,15 @@ void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num if( result != 0 ) { // 65280 = duplicate errors if (result == 65280) { + FILE *ptxinfo_in; ptxinfo_in = fopen(tempfile_ptxinfo,"r"); g_ptxinfo_filename = tempfile_ptxinfo; - ptxinfo_parse(); + yyscan_t scanner; + ptxinfo_lex_init(&scanner); + ptxinfo_set_in(ptxinfo_in, scanner); + ptxinfo_parse(scanner); + ptxinfo_lex_destroy(scanner); + fclose(ptxinfo_in); fix_duplicate_errors(fname2); snprintf(commandline,1024,"$CUDA_INSTALL_PATH/bin/ptxas %s -v %s --output-file /dev/null 2> %s", @@ -495,9 +509,15 @@ void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num g_ptxinfo_filename = final_tempfile_ptxinfo; else g_ptxinfo_filename = tempfile_ptxinfo; + FILE *ptxinfo_in; ptxinfo_in = fopen(g_ptxinfo_filename,"r"); - ptxinfo_parse(); + yyscan_t scanner; + ptxinfo_lex_init(&scanner); + ptxinfo_set_in(ptxinfo_in, scanner); + ptxinfo_parse(scanner); + ptxinfo_lex_destroy(scanner); + fclose(ptxinfo_in); snprintf(commandline,1024,"rm -f *info"); if( system(commandline) != 0 ) { @@ -515,4 +535,4 @@ void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num exit(1); } } -}
\ No newline at end of file +} diff --git a/src/cuda-sim/ptxinfo.l b/src/cuda-sim/ptxinfo.l index 33c2748..a190e6d 100644 --- a/src/cuda-sim/ptxinfo.l +++ b/src/cuda-sim/ptxinfo.l @@ -31,17 +31,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %option noyywrap %option yylineno %option prefix="ptxinfo_" + +%option bison-bridge +%option reentrant + %{ #include "ptxinfo.tab.h" #include <string.h> #define LINEBUF_SIZE 1024 -char ptxinfo_linebuf[LINEBUF_SIZE]; -unsigned ptxinfo_col = 0; -#define TC if( (ptxinfo_lineno == 1) && ((ptxinfo_col + strlen(ptxinfo_text)) < LINEBUF_SIZE) ) { \ - strncpy(ptxinfo_linebuf+ptxinfo_col,ptxinfo_text,strlen(ptxinfo_text)); \ +#define TC if( (yylineno == 1) && (yylval->col + strlen(yytext) < LINEBUF_SIZE) ) { \ + strncpy(yylval->linebuf+yylval->col,yytext,strlen(yytext)); \ } \ - ptxinfo_col+=strlen(ptxinfo_text); + yylval->col+=strlen(yytext); %} %% @@ -61,12 +63,12 @@ unsigned ptxinfo_col = 0; "for" TC; return FOR; "textures" TC; return TEXTURES; "error : Duplicate definition of" TC; return DUPLICATE; -"function" TC; ptxinfo_lval.string_value = strdup(yytext); return FUNCTION; -"variable" TC; ptxinfo_lval.string_value = strdup(yytext); return VARIABLE; +"function" TC; yylval->string_value = strdup(yytext); return FUNCTION; +"variable" TC; yylval->string_value = strdup(yytext); return VARIABLE; "fatal : Ptx assembly aborted due to errors" TC; return FATAL; -[_A-Za-z$%][_0-9A-Za-z$]* TC; ptxinfo_lval.string_value = strdup(yytext); return IDENTIFIER; -[-]{0,1}[0-9]+ TC; ptxinfo_lval.int_value = atoi(yytext); return INT_OPERAND; +[_A-Za-z$%][_0-9A-Za-z$]* TC; yylval->string_value = strdup(yytext); return IDENTIFIER; +[-]{0,1}[0-9]+ TC; yylval->int_value = atoi(yytext); return INT_OPERAND; "+" TC; return PLUS; "," TC; return COMMA; @@ -78,7 +80,7 @@ unsigned ptxinfo_col = 0; " " TC; "\t" TC; -\n.* ptxinfo_col=0; strncpy(ptxinfo_linebuf, yytext + 1, 1024); yyless( 1 ); +\n.* yylval->col=0; strncpy(yylval->linebuf, yytext + 1, 1024); yyless( 1 ); %% @@ -86,18 +88,19 @@ extern int g_ptxinfo_error_detected; extern const char *g_filename; extern const char *g_ptxinfo_filename; -int ptxinfo_error( const char *s ) +int ptxinfo_error(yyscan_t yyscanner, const char* msg) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; int i; g_ptxinfo_error_detected = 1; fflush(stdout); printf("GPGPU-Sim: ERROR while parsing output of ptxas (used to capture resource usage information)\n"); - if( s != NULL ) - printf("GPGPU-Sim: %s (%s:%u) Syntax error:\n\n", g_filename, g_ptxinfo_filename, ptxinfo_lineno ); - printf(" %s\n", ptxinfo_linebuf ); + if( msg != NULL ) + printf("GPGPU-Sim: %s (%s:%u) Syntax error:\n\n", g_filename, g_ptxinfo_filename, yylineno ); + printf(" %s\n", yylval->linebuf ); printf(" "); - for( i=0; i < ptxinfo_col-1; i++ ) { - if( ptxinfo_linebuf[i] == '\t' ) printf("\t"); + for( i=0; i < yylval->col-1; i++ ) { + if( yylval->linebuf[i] == '\t' ) printf("\t"); else printf(" "); } diff --git a/src/cuda-sim/ptxinfo.y b/src/cuda-sim/ptxinfo.y index d241d8c..eed304c 100644 --- a/src/cuda-sim/ptxinfo.y +++ b/src/cuda-sim/ptxinfo.y @@ -27,9 +27,20 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +%{ +typedef void * yyscan_t; +%} + +%define api.pure full +%parse-param {yyscan_t scanner} +%lex-param {yyscan_t scanner} + %union { +#define LINEBUF_SIZE 1024 int int_value; char * string_value; + char linebuf[LINEBUF_SIZE]; + unsigned col; } %token <int_value> INT_OPERAND @@ -66,7 +77,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. static unsigned g_declared; static unsigned g_system; - int ptxinfo_lex(void); + int ptxinfo_lex(YYSTYPE * yylval_param, yyscan_t yyscanner); + void yyerror(yyscan_t yyscanner, const char* msg); void ptxinfo_addinfo(); void ptxinfo_function(const char *fname ); void ptxinfo_regs( unsigned nregs ); @@ -74,7 +86,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void ptxinfo_gmem( unsigned declared, unsigned system ); void ptxinfo_smem( unsigned declared, unsigned system ); void ptxinfo_cmem( unsigned nbytes, unsigned bank ); - int ptxinfo_error(const char*); void ptxinfo_linenum( unsigned ); void ptxinfo_dup_type( const char* ); %} |
