From 18e0b0614611edcb19ee0a3b315c7b45e50b5595 Mon Sep 17 00:00:00 2001 From: Ahmed ElTantawy Date: Wed, 4 Mar 2015 12:02:52 -0800 Subject: initial support for CUDA 5.0, 5.5, 6.0 to get template from SDK running --- libcuda/cuobjdump.l | 1 + 1 file changed, 1 insertion(+) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index d264338..d7086ad 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -103,6 +103,7 @@ newlines {newline}+
"producer = " return H_PRODUCER;
"host = " return H_HOST;
"compile_size = " return H_COMPILESIZE; +
"compressed"{newline}
"identifier = " BEGIN(endheader); return H_IDENTIFIER;
"has debug info"{newline} -- cgit v1.3 From b2fc784cbb1c2e65736cea88d61509d08fddd83f Mon Sep 17 00:00:00 2001 From: ElTantawy Date: Thu, 12 May 2016 13:36:03 -0700 Subject: initial support for cuda 7.5 parsing --- libcuda/cuobjdump.l | 60 +++++++++++++++++++++++++++++++++++++++-------------- libcuda/cuobjdump.y | 30 +++++++++++++++++++++------ 2 files changed, 69 insertions(+), 21 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index d7086ad..c86a861 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -52,8 +52,11 @@ void cuobjdump_error(const char*); %s ptxcode %s sasscode %s elfcode -%s header +%s elfheader +%s ptxheader %s endheader +%s identifier +%s identifierF alpha [a-zA-Z] numeric [0-9] @@ -67,16 +70,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 +101,45 @@ newlines {newline}+ /*SASS code tokens*/ {notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; +"identifier = " BEGIN(identifierF); return H_IDENTIFIER; +"\n" yy_pop_state(); + +{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; + + + + /*Header tokens*/ +[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +"================" return H_SEPARATOR; +"arch = " return H_ARCH; +"code version = " return H_CODEVERSION; +\[{numeric},{numeric}\] return CODEVERSION; +"producer = " return H_PRODUCER; +"" return H_UNKNOWN; +"host = " return H_HOST; +"compile_size = " BEGIN(endheader); return H_COMPILESIZE; + + /*Header tokens*/ -
[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; -
"================" return H_SEPARATOR; -
"arch = " return H_ARCH; -
"code version = " return H_CODEVERSION; -
\[{numeric},{numeric}\] return CODEVERSION; -
"producer = " return H_PRODUCER; -
"host = " return H_HOST; -
"compile_size = " return H_COMPILESIZE; -
"compressed"{newline} -
"identifier = " BEGIN(endheader); return H_IDENTIFIER; -
"has debug info"{newline} +[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +"================" return H_SEPARATOR; +"arch = " return H_ARCH; +"code version = " return H_CODEVERSION; +\[{numeric},{numeric}\] return CODEVERSION; +"producer = " return H_PRODUCER; +"host = " return H_HOST; +"compile_size = " return H_COMPILESIZE; +"compressed"{newline} yy_pop_state(); return H_COMPRESSED; + + + + + /* Looking for the identifier (filename) then the header is done */ /* [[:alnum:]_\./]+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; */ -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; +{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..f86d445 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -39,6 +39,7 @@ void setCuobjdumpelffilename(const char* filename); void setCuobjdumpsassfilename(const char* filename); int elfserial = 1; int ptxserial = 1; +int yydebug=1; FILE *ptxfile; FILE *elffile; FILE *sassfile; @@ -47,7 +48,7 @@ char filename [1024]; %union { char* string_value; } -%token H_SEPARATOR H_ARCH H_CODEVERSION H_PRODUCER H_HOST H_COMPILESIZE H_IDENTIFIER +%token H_SEPARATOR H_ARCH H_CODEVERSION H_PRODUCER H_HOST H_COMPILESIZE H_IDENTIFIER H_UNKNOWN H_COMPRESSED %token CODEVERSION %token STRING %token FILENAME @@ -61,6 +62,7 @@ char filename [1024]; %% + program : {printf("######### cuobjdump parser ########\n");} emptylines section | program section; @@ -73,7 +75,7 @@ section : PTXHEADER { snprintf(filename, 1024, "_cuobjdump_%d.ptx", ptxserial++); ptxfile = fopen(filename, "w"); setCuobjdumpptxfilename(filename); - } headerinfo ptxcode { + } headerinfo identifier ptxcode { fclose(ptxfile); } | ELFHEADER { @@ -81,7 +83,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"); @@ -91,17 +94,32 @@ 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 emptylines {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 emptylines {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_COMPRESSED emptylines {setCuobjdumparch($4);}; + +identifier : H_IDENTIFIER FILENAME {setCuobjdumpidentifier($2);}; + | ; 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);} -- cgit v1.3 From 0b95282e887e6cc6eb48d93d5aa51252588c3260 Mon Sep 17 00:00:00 2001 From: Ahmed ElTantawy Date: Fri, 13 May 2016 08:06:17 -0700 Subject: getting the parsing compatible with previous version - tested on 4.2, 5.5 and 7.5 --- libcuda/cuobjdump.l | 20 +++++++++++++------- libcuda/cuobjdump.y | 21 +++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index c86a861..f63ee73 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -55,8 +55,9 @@ void cuobjdump_error(const char*); %s elfheader %s ptxheader %s endheader -%s identifier -%s identifierF +%x identifier +%x conidentifier +%s endidentifier alpha [a-zA-Z] numeric [0-9] @@ -101,10 +102,16 @@ newlines {newline}+ /*SASS code tokens*/ {notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; -"identifier = " BEGIN(identifierF); return H_IDENTIFIER; -"\n" yy_pop_state(); +{newline}"compressed"{newline} BEGIN(conidentifier); return H_COMPRESSED; +{newline}"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; +{newline}{newline} yy_pop_state(); -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; + +"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; +{newline} yy_pop_state(); + + +{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; @@ -128,8 +135,7 @@ newlines {newline}+ \[{numeric},{numeric}\] return CODEVERSION; "producer = " return H_PRODUCER; "host = " return H_HOST; -"compile_size = " return H_COMPILESIZE; -"compressed"{newline} yy_pop_state(); return H_COMPRESSED; +"compile_size = " BEGIN(endheader); return H_COMPILESIZE; diff --git a/libcuda/cuobjdump.y b/libcuda/cuobjdump.y index 5fc0c8f..29509e8 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -39,7 +39,7 @@ void setCuobjdumpelffilename(const char* filename); void setCuobjdumpsassfilename(const char* filename); int elfserial = 1; int ptxserial = 1; - +int yydebug = 1; FILE *ptxfile; FILE *elffile; FILE *sassfile; @@ -75,7 +75,7 @@ section : PTXHEADER { snprintf(filename, 1024, "_cuobjdump_%d.ptx", ptxserial++); ptxfile = fopen(filename, "w"); setCuobjdumpptxfilename(filename); - } headerinfo identifier ptxcode { + } headerinfo compressedkeyword identifier ptxcode { fclose(ptxfile); } | ELFHEADER { @@ -84,6 +84,7 @@ section : PTXHEADER { elffile = fopen(filename, "w"); setCuobjdumpelffilename(filename); } headerinfo identifier{ + printf("\nHeader Info and Identifier Parsed\n"); } elfcode { fclose(elffile); snprintf(filename, 1024, "_cuobjdump_%d.sass", elfserial++); @@ -98,24 +99,20 @@ headerinfo : H_SEPARATOR NEWLINE H_CODEVERSION CODEVERSION NEWLINE H_PRODUCER H_UNKNOWN NEWLINE H_HOST IDENTIFIER NEWLINE - H_COMPILESIZE IDENTIFIER emptylines {setCuobjdumparch($4);}; + 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 emptylines {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_COMPRESSED emptylines {setCuobjdumparch($4);}; + H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4);}; -identifier : H_IDENTIFIER FILENAME {setCuobjdumpidentifier($2);}; +identifier : H_IDENTIFIER FILENAME emptylines {setCuobjdumpidentifier($2);}; | ; +compressedkeyword : H_COMPRESSED emptylines + | ; + ptxcode : ptxcode PTXLINE {fprintf(ptxfile, "%s", $2);} | ; -- cgit v1.3 From 17ff26759ca0fb41095d2d0afaaed3059e6360ad Mon Sep 17 00:00:00 2001 From: Nathan Conrad Date: Mon, 26 Mar 2018 19:35:41 -0400 Subject: Don't directly pass strings to printf (beacuse they wouldn't be escapped). Clang gives warnings about this. --- libcuda/cuobjdump.l | 6 ++---- src/cuda-sim/ptx_parser.cc | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index f63ee73..0953ea1 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -159,8 +159,6 @@ newlines {newline}+ %% void cuobjdump_error(const char* message) { - printf(" "); printf(message); printf(" near \""); printf(yytext); printf("\""); - printf(" on line "); - char line[5]; sprintf(line, "%i", yylineno); printf(line); - printf("\n"); + printf(" %s near \"%s\"",message, yytext); + printf(" on line %i\n",yylineno); } diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index baa3bcd..a180da9 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -433,7 +433,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident assert( (num_bits%8) == 0 ); addr = g_current_symbol_table->get_shared_next(); addr_pad = pad_address(addr, num_bits/8, 128); - printf("from 0x%x to 0x%lx (shared memory space)\n", + printf("from 0x%llx to 0x%llx (shared memory space)\n", addr+addr_pad, addr+addr_pad + num_bits/8); fflush(stdout); @@ -450,7 +450,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident assert( (num_bits%8) == 0 ); addr = g_current_symbol_table->get_global_next(); addr_pad = pad_address(addr, num_bits/8, 128); - printf("from 0x%x to 0x%lx (global memory space) %u\n", + printf("from 0x%llx to 0x%llx (global memory space) %u\n", addr+addr_pad, addr+addr_pad + num_bits/8, g_const_alloc++); @@ -471,7 +471,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident assert( (num_bits%8) == 0 ); addr = g_current_symbol_table->get_global_next(); addr_pad = pad_address(addr, num_bits/8, 128); - printf("from 0x%x to 0x%lx (global memory space)\n", + printf("from 0x%llx to 0x%llx (global memory space)\n", addr+addr_pad, addr+addr_pad + num_bits/8); fflush(stdout); @@ -488,7 +488,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident assert( (num_bits%8) == 0 ); addr = g_current_symbol_table->get_local_next(); addr_pad = pad_address(addr, num_bits/8, 128); - printf("from 0x%x to 0x%lx (local memory space)\n", + printf("from 0x%llx to 0x%llx (local memory space)\n", addr+addr_pad, addr+addr_pad + num_bits/8); fflush(stdout); @@ -501,7 +501,7 @@ void add_identifier( const char *identifier, int array_dim, unsigned array_ident assert( (num_bits%8) == 0 ); addr = g_current_symbol_table->get_local_next(); addr_pad = pad_address(addr, num_bits/8, 128); - printf("from 0x%x to 0x%lx\n", + printf("from 0x%llx to 0x%llx\n", addr+addr_pad, addr+addr_pad + num_bits/8); fflush(stdout); -- cgit v1.3 From 52e742bc355f202f965177113b382c0fb7243f61 Mon Sep 17 00:00:00 2001 From: Matteo Maria Fusi Date: Thu, 20 Sep 2018 10:59:35 +0200 Subject: libcuda: removed comment from cuobjdump.l This comment made the build fail in ubuntu 18.04 due to a flex error. This error is probably produced by a flex bug. --- libcuda/cuobjdump.l | 1 - 1 file changed, 1 deletion(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index 0953ea1..2b0dac8 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -143,7 +143,6 @@ newlines {newline}+ /* Looking for the identifier (filename) then the header is done */ - /* [[:alnum:]_\./]+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; */ {notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return IDENTIFIER; -- cgit v1.3 From a7ae218e89859b5a5b8433f57029590b8877fc18 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Sun, 21 Apr 2019 15:55:21 -0400 Subject: Move cuobjdump parser to reentrant Signed-off-by: Mengchi Zhang --- libcuda/cuda_runtime_api.cc | 15 ++++++++++--- libcuda/cuobjdump.l | 52 ++++++++++++++++++++++----------------------- libcuda/cuobjdump.y | 8 +++++-- 3 files changed, 44 insertions(+), 31 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index 27644b3..ef5abce 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -1935,7 +1935,10 @@ void setCuobjdumpsassfilename(const char* filename){ } (dynamic_cast(cuobjdumpSectionList.front()))->setSASSfilename(filename); } -extern int cuobjdump_parse(); +typedef void * yyscan_t; +extern int cuobjdump_lex_init(yyscan_t* scanner); +extern int cuobjdump_parse(yyscan_t scanner); +extern int cuobjdump_lex_destroy(yyscan_t scanner); extern FILE *cuobjdump_in; //! Return the executable file of the process containing the PTX/SASS code @@ -2147,7 +2150,10 @@ void extract_code_using_cuobjdump(){ printf("Parsing file %s\n", fname); cuobjdump_in = fopen(fname, "r"); - cuobjdump_parse(); + yyscan_t scanner; + cuobjdump_lex_init(&scanner); + cuobjdump_parse(scanner); + cuobjdump_lex_destroy(scanner); fclose(cuobjdump_in); printf("Done parsing!!!\n"); } else { @@ -2196,7 +2202,10 @@ void extract_code_using_cuobjdump(){ std::cout << "Trying to parse " << libcodfn.str() << std::endl; cuobjdump_in = fopen(libcodfn.str().c_str(), "r"); - cuobjdump_parse(); + yyscan_t scanner; + cuobjdump_lex_init(&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..9a468ba 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 print_error(const char*, const char*, int); %} %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*/ -{notnewline}*{newline} yylval.string_value = strdup(yytext); return PTXLINE; +{notnewline}*{newline} yylval->string_value = strdup(yytext); return PTXLINE; /*ELF code tokens*/ {whitespace}*"code for sm_"{numeric}+{newline} { BEGIN(sasscode); - yylval.string_value = strdup(yytext); + yylval->string_value = strdup(yytext); return SASSLINE; } -{notnewline}*{newline} yylval.string_value = strdup(yytext); return ELFLINE; +{notnewline}*{newline} yylval->string_value = strdup(yytext); return ELFLINE; /*SASS code tokens*/ -{notnewline}*{newline} yylval.string_value = strdup(yytext); return SASSLINE; +{notnewline}*{newline} yylval->string_value = strdup(yytext); return SASSLINE; {newline}"compressed"{newline} BEGIN(conidentifier); return H_COMPRESSED; {newline}"identifier = " BEGIN(endidentifier); return H_IDENTIFIER; -{newline}{newline} yy_pop_state(); +{newline}{newline} yy_pop_state(yyscanner); "identifier = " BEGIN(endidentifier); return H_IDENTIFIER; -{newline} yy_pop_state(); +{newline} yy_pop_state(yyscanner); -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return FILENAME; +{notnewline}+ yylval->string_value = strdup(yytext); yy_pop_state(yyscanner); return FILENAME; /*Header tokens*/ -[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +[[:alnum:]_]+ yylval->string_value = strdup(yytext); return IDENTIFIER; "================" return H_SEPARATOR; "arch = " return H_ARCH; "code version = " return H_CODEVERSION; @@ -128,7 +128,7 @@ newlines {newline}+ /*Header tokens*/ -[[:alnum:]_]+ yylval.string_value = strdup(yytext); return IDENTIFIER; +[[:alnum:]_]+ yylval->string_value = strdup(yytext); return IDENTIFIER; "================" return H_SEPARATOR; "arch = " return H_ARCH; "code version = " return H_CODEVERSION; @@ -143,7 +143,7 @@ newlines {newline}+ /* Looking for the identifier (filename) then the header is done */ -{notnewline}+ yylval.string_value = strdup(yytext); yy_pop_state(); return IDENTIFIER; +{notnewline}+ yylval->string_value = strdup(yytext); yy_pop_state(yyscanner); return IDENTIFIER; @@ -153,11 +153,11 @@ newlines {newline}+ <> BEGIN(INITIAL);return 0; /*No other rule matched. Throw an error*/ -. cuobjdump_error("Invalid token"); +. print_error("Invalid token", yytext, yylineno); %% -void cuobjdump_error(const char* message) +void print_error(const char* message, const char* text, int lineno) { - printf(" %s near \"%s\"",message, yytext); - printf(" on line %i\n",yylineno); + printf(" %s near \"%s\"",message, text); + printf(" on line %i\n",lineno); } diff --git a/libcuda/cuobjdump.y b/libcuda/cuobjdump.y index 31760f7..eea0a1f 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -29,8 +29,8 @@ %{ #include -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,6 +44,10 @@ 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; } -- cgit v1.3 From b6631a07ca4aa0345f569b49116c649feadccc89 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Sun, 21 Apr 2019 22:32:26 -0400 Subject: Add yyerror definition Signed-off-by: Mengchi Zhang --- libcuda/cuobjdump.l | 11 ++++++----- libcuda/cuobjdump.y | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index 9a468ba..9359281 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -38,7 +38,7 @@ #define YYDEBUG 1 -void print_error(const char*, const char*, int); +void cuobjdump_error(yyscan_t yyscanner, const char* msg); %} %option stack @@ -153,11 +153,12 @@ newlines {newline}+ <> BEGIN(INITIAL);return 0; /*No other rule matched. Throw an error*/ -. print_error("Invalid token", yytext, yylineno); +. cuobjdump_error(yyscanner, "Invalid token"); %% -void print_error(const char* message, const char* text, int lineno) +void cuobjdump_error(yyscan_t yyscanner, const char* msg) { - printf(" %s near \"%s\"",message, text); - printf(" on line %i\n",lineno); + 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 927d17e..66cbace 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -53,7 +53,7 @@ char filename [1024]; } %{ int yylex(YYSTYPE * yylval_param, yyscan_t yyscanner); -int yyerror(yyscan_t yyscanner, const char* msg); +void yyerror(yyscan_t yyscanner, const char* msg); %} %token H_SEPARATOR H_ARCH H_CODEVERSION H_PRODUCER H_HOST H_COMPILESIZE H_IDENTIFIER H_UNKNOWN H_COMPRESSED %token CODEVERSION -- cgit v1.3 From 913865e6ac7d0f7c12faeb8430dc5724fdc4be80 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Mon, 27 May 2019 17:27:58 -0400 Subject: Move some cuobjdump parser variables Signed-off-by: Mengchi Zhang --- libcuda/Makefile | 4 ++-- libcuda/cuda_runtime_api.cc | 23 ++++++++++++----------- libcuda/cuobjdump.h | 18 ++++++++++++++++++ libcuda/cuobjdump.l | 9 ++++++--- libcuda/cuobjdump.y | 43 ++++++++++++++++++++----------------------- 5 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 libcuda/cuobjdump.h (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/Makefile b/libcuda/Makefile index 13932e2..c8ff2e3 100644 --- a/libcuda/Makefile +++ b/libcuda/Makefile @@ -111,10 +111,10 @@ $(OUTPUT_DIR)/%.o: %.cc $(CPP) $(CXXFLAGS) -I./ -I$(OUTPUT_DIR) -I$(CUDA_INSTALL_PATH)/include -c $< -o $@ $(OUTPUT_DIR)/%.o: %.c - $(CC) $(CCFLAGS) -I./ -I$(OUTPUT_DIR) -I$(CUDA_INSTALL_PATH)/include -c $< -o $@ + $(CPP) $(CCFLAGS) -I./ -I$(OUTPUT_DIR) -I$(CUDA_INSTALL_PATH)/include -c $< -o $@ $(OUTPUT_DIR)/%.o: $(OUTPUT_DIR)/%.c - $(CC) $(CCFLAGS) -I./ -I$(OUTPUT_DIR) -I$(CUDA_INSTALL_PATH)/include -c $< -o $@ + $(CPP) $(CCFLAGS) -I./ -I$(OUTPUT_DIR) -I$(CUDA_INSTALL_PATH)/include -c $< -o $@ $(OUTPUT_DIR)/cuobjdump_parser.c: cuobjdump.y $(YACC) $(YFLAGS) -p cuobjdump_ -o$@ $< --file-prefix=$(OUTPUT_DIR)/cuobjdump diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index fc152c2..1d4e870 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -1972,9 +1972,10 @@ void setCuobjdumpsassfilename(const char* filename){ (dynamic_cast(cuobjdumpSectionList.front()))->setSASSfilename(filename); } typedef void * yyscan_t; +#include "cuobjdump.h" 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_parse(yyscan_t scanner, cuobjdump_parser* parser); extern int cuobjdump_lex_destroy(yyscan_t scanner); //! Return the executable file of the process containing the PTX/SASS code @@ -2187,11 +2188,11 @@ void extract_code_using_cuobjdump(){ FILE *cuobjdump_in; cuobjdump_in = fopen(fname, "r"); - yyscan_t scanner; - cuobjdump_lex_init(&scanner); - cuobjdump_set_in(cuobjdump_in, scanner); - cuobjdump_parse(scanner); - cuobjdump_lex_destroy(scanner); + cuobjdump_parser parser; + cuobjdump_lex_init(&(parser.scanner)); + cuobjdump_set_in(cuobjdump_in, (parser.scanner)); + cuobjdump_parse(parser.scanner, &parser); + cuobjdump_lex_destroy(parser.scanner); fclose(cuobjdump_in); printf("Done parsing!!!\n"); } else { @@ -2241,11 +2242,11 @@ void extract_code_using_cuobjdump(){ std::cout << "Trying to parse " << libcodfn.str() << std::endl; FILE *cuobjdump_in; cuobjdump_in = fopen(libcodfn.str().c_str(), "r"); - yyscan_t scanner; - cuobjdump_lex_init(&scanner); - cuobjdump_set_in(cuobjdump_in, scanner); - cuobjdump_parse(scanner); - cuobjdump_lex_destroy(scanner); + cuobjdump_parser parser; + cuobjdump_lex_init(&(parser.scanner)); + cuobjdump_set_in(cuobjdump_in, (parser.scanner)); + cuobjdump_parse(parser.scanner, &parser); + cuobjdump_lex_destroy(parser.scanner); fclose(cuobjdump_in); std::getline(libsf, line); } diff --git a/libcuda/cuobjdump.h b/libcuda/cuobjdump.h new file mode 100644 index 0000000..61bf806 --- /dev/null +++ b/libcuda/cuobjdump.h @@ -0,0 +1,18 @@ +#ifndef __cuobjdump_h__ +#define __cuobjdump_h__ +class cuobjdump_parser { + + public: + yyscan_t scanner; + int elfserial; + int ptxserial; + FILE *ptxfile; + FILE *elffile; + FILE *sassfile; + char filename [1024]; + cuobjdump_parser() { + int elfserial = 1; + int ptxserial = 1; + } +}; +#endif /* __cuobjdump_h__ */ diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index 9359281..26fbb55 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -30,6 +30,7 @@ %{ #include #include +#include "cuobjdump.h" #include "cuobjdump_parser.h" #define YY_NEVER_INTERACTIVE 1 @@ -38,7 +39,9 @@ #define YYDEBUG 1 -void cuobjdump_error(yyscan_t yyscanner, const char* msg); +void cuobjdump_error(yyscan_t yyscanner, cuobjdump_parser* parser, const char* msg); +#define YY_DECL int cuobjdump_lex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner, cuobjdump_parser* parser) %} %option stack @@ -153,10 +156,10 @@ newlines {newline}+ <> BEGIN(INITIAL);return 0; /*No other rule matched. Throw an error*/ -. cuobjdump_error(yyscanner, "Invalid token"); +. cuobjdump_error(yyscanner, parser, "Invalid token"); %% -void cuobjdump_error(yyscan_t yyscanner, const char* msg) +void cuobjdump_error(yyscan_t yyscanner, cuobjdump_parser* parser, const char* msg) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; printf(" %s near \"%s\"",msg, yytext); diff --git a/libcuda/cuobjdump.y b/libcuda/cuobjdump.y index 66cbace..9c0c28d 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -30,6 +30,7 @@ #include typedef void * yyscan_t; +#include "cuobjdump.h" extern void addCuobjdumpSection(int sectiontype); void setCuobjdumparch(const char* arch); @@ -37,23 +38,19 @@ void setCuobjdumpidentifier(const char* identifier); void setCuobjdumpptxfilename(const char* filename); void setCuobjdumpelffilename(const char* filename); void setCuobjdumpsassfilename(const char* filename); -int elfserial = 1; -int ptxserial = 1; -FILE *ptxfile; -FILE *elffile; -FILE *sassfile; -char filename [1024]; %} %define api.pure full %parse-param {yyscan_t scanner} +%parse-param {cuobjdump_parser* parser} %lex-param {yyscan_t scanner} +%lex-param {cuobjdump_parser* parser} %union { char* string_value; } %{ -int yylex(YYSTYPE * yylval_param, yyscan_t yyscanner); -void yyerror(yyscan_t yyscanner, const char* msg); +int yylex(YYSTYPE * yylval_param, yyscan_t yyscanner, cuobjdump_parser* parser); +void yyerror(yyscan_t yyscanner, cuobjdump_parser* parser, const char* msg); %} %token H_SEPARATOR H_ARCH H_CODEVERSION H_PRODUCER H_HOST H_COMPILESIZE H_IDENTIFIER H_UNKNOWN H_COMPRESSED %token CODEVERSION @@ -79,24 +76,24 @@ emptylines : emptylines NEWLINE section : PTXHEADER { addCuobjdumpSection(0); - snprintf(filename, 1024, "_cuobjdump_%d.ptx", ptxserial++); - ptxfile = fopen(filename, "w"); - setCuobjdumpptxfilename(filename); + snprintf(parser->filename, 1024, "_cuobjdump_%d.ptx", parser->ptxserial++); + parser->ptxfile = fopen(parser->filename, "w"); + setCuobjdumpptxfilename(parser->filename); } headerinfo compressedkeyword identifier ptxcode { - fclose(ptxfile); + fclose(parser->ptxfile); } | ELFHEADER { addCuobjdumpSection(1); - snprintf(filename, 1024, "_cuobjdump_%d.elf", elfserial); - elffile = fopen(filename, "w"); - setCuobjdumpelffilename(filename); + snprintf(parser->filename, 1024, "_cuobjdump_%d.elf", parser->elfserial); + parser->elffile = fopen(parser->filename, "w"); + setCuobjdumpelffilename(parser->filename); } headerinfo compressedkeyword identifier elfcode { - fclose(elffile); - snprintf(filename, 1024, "_cuobjdump_%d.sass", elfserial++); - sassfile = fopen(filename, "w"); - setCuobjdumpsassfilename(filename); + fclose(parser->elffile); + snprintf(parser->filename, 1024, "_cuobjdump_%d.sass", parser->elfserial++); + parser->sassfile = fopen(parser->filename, "w"); + setCuobjdumpsassfilename(parser->filename); } sasscode { - fclose(sassfile); + fclose(parser->sassfile); }; headerinfo : H_SEPARATOR NEWLINE @@ -118,13 +115,13 @@ identifier : H_IDENTIFIER FILENAME emptylines {setCuobjdumpidentifier($2);} compressedkeyword : H_COMPRESSED emptylines | ; -ptxcode : ptxcode PTXLINE {fprintf(ptxfile, "%s", $2);} +ptxcode : ptxcode PTXLINE {fprintf(parser->ptxfile, "%s", $2);} | ; -elfcode : elfcode ELFLINE {fprintf(elffile, "%s", $2);} +elfcode : elfcode ELFLINE {fprintf(parser->elffile, "%s", $2);} | ; -sasscode : sasscode SASSLINE {fprintf(sassfile, "%s", $2);} +sasscode : sasscode SASSLINE {fprintf(parser->sassfile, "%s", $2);} | ; -- cgit v1.3 From 25bdc0dd89932f95ace0fc617649a4e041aaadd9 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 29 May 2019 01:28:29 -0400 Subject: Move SectionList to context Signed-off-by: Mengchi Zhang --- libcuda/cuda_runtime_api.cc | 109 ++++++++++---------------------------------- libcuda/cuobjdump.h | 67 +++++++++++++++++++++++++++ libcuda/cuobjdump.l | 8 ++-- libcuda/cuobjdump.y | 36 ++++++++------- 4 files changed, 113 insertions(+), 107 deletions(-) (limited to 'libcuda/cuobjdump.l') diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index afe47f8..df7ddc7 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -139,6 +139,8 @@ #include "../src/gpgpusim_entrypoint.h" #include "../src/stream_manager.h" #include "../src/abstract_hardware_model.h" +typedef void * yyscan_t; +#include "cuobjdump.h" #include #include @@ -302,6 +304,7 @@ struct CUctx_st { return i->second; } + std::list cuobjdumpSectionList; private: _cuda_device_id *m_gpu; // selected gpu std::map m_code; // fat binary handle => global symbol table @@ -483,11 +486,9 @@ event_tracker_t g_timer_events; int g_active_device = 0; //active gpu that runs the code std::list g_cuda_launch_stack; -typedef void * yyscan_t; -#include "cuobjdump.h" 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, struct cuobjdump_parser* parser); +extern int cuobjdump_parse(yyscan_t scanner, struct cuobjdump_parser* parser, std::list &cuobjdumpSectionList); extern int cuobjdump_lex_destroy(yyscan_t scanner); enum cuobjdumpSectionType { @@ -496,74 +497,10 @@ enum cuobjdumpSectionType { }; -class cuobjdumpSection { -public: - //Constructor - cuobjdumpSection() { - arch = 0; - identifier = ""; - } - virtual ~cuobjdumpSection() {} - unsigned getArch() {return arch;} - void setArch(unsigned a) {arch = a;} - std::string getIdentifier() {return identifier;} - void setIdentifier(std::string i) {identifier = i;} - virtual void print(){std::cout << "cuobjdump Section: unknown type" << std::endl;} -private: - unsigned arch; - std::string identifier; -}; - -class cuobjdumpELFSection : public cuobjdumpSection -{ -public: - cuobjdumpELFSection() {} - virtual ~cuobjdumpELFSection() { - elffilename = ""; - sassfilename = ""; - } - std::string getELFfilename() {return elffilename;} - void setELFfilename(std::string f) {elffilename = f;} - std::string getSASSfilename() {return sassfilename;} - void setSASSfilename(std::string f) {sassfilename = f;} - virtual void print() { - std::cout << "ELF Section:" << std::endl; - std::cout << "arch: sm_" << getArch() << std::endl; - std::cout << "identifier: " << getIdentifier() << std::endl; - std::cout << "elf filename: " << getELFfilename() << std::endl; - std::cout << "sass filename: " << getSASSfilename() << std::endl; - std::cout << std::endl; - } -private: - std::string elffilename; - std::string sassfilename; -}; - -class cuobjdumpPTXSection : public cuobjdumpSection -{ -public: - cuobjdumpPTXSection(){ - ptxfilename = ""; - } - std::string getPTXfilename() {return ptxfilename;} - void setPTXfilename(std::string f) {ptxfilename = f;} - virtual void print() { - std::cout << "PTX Section:" << std::endl; - std::cout << "arch: sm_" << getArch() << std::endl; - std::cout << "identifier: " << getIdentifier() << std::endl; - std::cout << "ptx filename: " << getPTXfilename() << std::endl; - std::cout << std::endl; - } -private: - std::string ptxfilename; -}; - - -std::list cuobjdumpSectionList; std::list libSectionList; // sectiontype: 0 for ptx, 1 for elf -void addCuobjdumpSection(int sectiontype){ +void addCuobjdumpSection(int sectiontype, std::list &cuobjdumpSectionList){ if (sectiontype) cuobjdumpSectionList.push_front(new cuobjdumpELFSection()); else @@ -571,7 +508,7 @@ void addCuobjdumpSection(int sectiontype){ printf("## Adding new section %s\n", sectiontype?"ELF":"PTX"); } -void setCuobjdumparch(const char* arch){ +void setCuobjdumparch(const char* arch, std::list &cuobjdumpSectionList){ unsigned archnum; sscanf(arch, "sm_%u", &archnum); assert (archnum && "cannot have sm_0"); @@ -579,12 +516,12 @@ void setCuobjdumparch(const char* arch){ cuobjdumpSectionList.front()->setArch(archnum); } -void setCuobjdumpidentifier(const char* identifier){ +void setCuobjdumpidentifier(const char* identifier, std::list &cuobjdumpSectionList){ printf("Adding identifier: %s\n", identifier); cuobjdumpSectionList.front()->setIdentifier(identifier); } -void setCuobjdumpptxfilename(const char* filename){ +void setCuobjdumpptxfilename(const char* filename, std::list &cuobjdumpSectionList){ printf("Adding ptx filename: %s\n", filename); cuobjdumpSection* x = cuobjdumpSectionList.front(); if (dynamic_cast(x) == NULL){ @@ -593,14 +530,14 @@ void setCuobjdumpptxfilename(const char* filename){ (dynamic_cast(x))->setPTXfilename(filename); } -void setCuobjdumpelffilename(const char* filename){ +void setCuobjdumpelffilename(const char* filename, std::list &cuobjdumpSectionList){ if (dynamic_cast(cuobjdumpSectionList.front()) == NULL){ assert (0 && "You shouldn't be trying to add a elffilename to an ptx section"); } (dynamic_cast(cuobjdumpSectionList.front()))->setELFfilename(filename); } -void setCuobjdumpsassfilename(const char* filename){ +void setCuobjdumpsassfilename(const char* filename, std::list &cuobjdumpSectionList){ if (dynamic_cast(cuobjdumpSectionList.front()) == NULL){ assert (0 && "You shouldn't be trying to add a sassfilename to an ptx section"); } @@ -2132,7 +2069,7 @@ static int get_app_cuda_version() { * It is also responsible for extracting the libraries linked to the binary if the option is * enabled * */ -void extract_code_using_cuobjdump(){ +void extract_code_using_cuobjdump(std::list &cuobjdumpSectionList){ CUctx_st *context = GPGPUSim_Context(); unsigned forced_max_capability = context->get_device()->get_gpgpu()->get_config().get_forced_max_capability(); @@ -2195,7 +2132,7 @@ void extract_code_using_cuobjdump(){ parser.ptxserial = 1; cuobjdump_lex_init(&(parser.scanner)); cuobjdump_set_in(cuobjdump_in, (parser.scanner)); - cuobjdump_parse(parser.scanner, &parser); + cuobjdump_parse(parser.scanner, &parser, cuobjdumpSectionList); cuobjdump_lex_destroy(parser.scanner); fclose(cuobjdump_in); printf("Done parsing!!!\n"); @@ -2251,7 +2188,7 @@ void extract_code_using_cuobjdump(){ parser.ptxserial = 1; cuobjdump_lex_init(&(parser.scanner)); cuobjdump_set_in(cuobjdump_in, (parser.scanner)); - cuobjdump_parse(parser.scanner, &parser); + cuobjdump_parse(parser.scanner, &parser, cuobjdumpSectionList); cuobjdump_lex_destroy(parser.scanner); fclose(cuobjdump_in); std::getline(libsf, line); @@ -2445,7 +2382,7 @@ cuobjdumpELFSection* findELFSectionInList(std::list sectionli } //! Find an ELF section in all the known lists -cuobjdumpELFSection* findELFSection(const std::string identifier){ +cuobjdumpELFSection* findELFSection(const std::string identifier, std::list cuobjdumpSectionList){ cuobjdumpELFSection* sec = findELFSectionInList(cuobjdumpSectionList, identifier); if (sec!=NULL)return sec; sec = findELFSectionInList(libSectionList, identifier); @@ -2480,7 +2417,7 @@ cuobjdumpPTXSection* findPTXSectionInList(std::list sectionli } //! Find an PTX section in all the known lists -cuobjdumpPTXSection* findPTXSection(const std::string identifier){ +cuobjdumpPTXSection* findPTXSection(const std::string identifier, std::list cuobjdumpSectionList){ cuobjdumpPTXSection* sec = findPTXSectionInList(cuobjdumpSectionList, identifier); if (sec!=NULL)return sec; sec = findPTXSectionInList(libSectionList, identifier); @@ -2493,9 +2430,9 @@ cuobjdumpPTXSection* findPTXSection(const std::string identifier){ //! Extract the code using cuobjdump and remove unnecessary sections -void cuobjdumpInit(){ +void cuobjdumpInit(std::list &cuobjdumpSectionList){ CUctx_st *context = GPGPUSim_Context(); - extract_code_using_cuobjdump(); //extract all the output of cuobjdump to _cuobjdump_*.* + extract_code_using_cuobjdump(cuobjdumpSectionList); //extract all the output of cuobjdump to _cuobjdump_*.* const char* pre_load = getenv("CUOBJDUMP_SIM_FILE"); if (pre_load ==NULL || strlen(pre_load)==0){ cuobjdumpSectionList = pruneSectionList(cuobjdumpSectionList, context); @@ -2513,7 +2450,7 @@ void cuobjdumpRegisterFatBinary(unsigned int handle, const char* filename){ } //! Either submit PTX for simulation or convert SASS to PTXPlus and submit it -void cuobjdumpParseBinary(unsigned int handle){ +void cuobjdumpParseBinary(unsigned int handle, std::list &cuobjdumpSectionList){ if(fatbin_registered[handle]) return; fatbin_registered[handle] = true; @@ -2566,7 +2503,7 @@ void cuobjdumpParseBinary(unsigned int handle){ cuobjdumpPTXSection* ptx = NULL; const char* pre_load = getenv("CUOBJDUMP_SIM_FILE"); if(pre_load==NULL || strlen(pre_load)==0) - ptx = findPTXSection(fname); + ptx = findPTXSection(fname, context->cuobjdumpSectionList); char *ptxcode; const char *override_ptx_name = getenv("PTX_SIM_KERNELFILE"); if (override_ptx_name == NULL or getenv("PTX_SIM_USE_PTX_FILE") == NULL or strlen(getenv("PTX_SIM_USE_PTX_FILE"))==0) { @@ -2576,7 +2513,7 @@ void cuobjdumpParseBinary(unsigned int handle){ ptxcode = readfile(override_ptx_name); } if(context->get_device()->get_gpgpu()->get_config().convert_to_ptxplus() ) { - cuobjdumpELFSection* elfsection = findELFSection(ptx->getIdentifier()); + cuobjdumpELFSection* elfsection = findELFSection(ptx->getIdentifier(), context->cuobjdumpSectionList); assert (elfsection!= NULL); char *ptxplus_str = gpgpu_ptx_sim_convert_ptx_and_sass_to_ptxplus( ptx->getPTXfilename(), @@ -2664,7 +2601,7 @@ void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin ) * then for next calls, only returns the appropriate number */ assert(fat_cubin_handle >= 1); - if (fat_cubin_handle==1) cuobjdumpInit(); + if (fat_cubin_handle==1) cuobjdumpInit(context->cuobjdumpSectionList); cuobjdumpRegisterFatBinary(fat_cubin_handle, filename); return (void**)fat_cubin_handle; @@ -2779,7 +2716,7 @@ void CUDARTAPI __cudaRegisterFunction( printf("GPGPU-Sim PTX: __cudaRegisterFunction %s : hostFun 0x%p, fat_cubin_handle = %u\n", deviceFun, hostFun, fat_cubin_handle); if(context->get_device()->get_gpgpu()->get_config().use_cuobjdump()) - cuobjdumpParseBinary(fat_cubin_handle); + cuobjdumpParseBinary(fat_cubin_handle, context->cuobjdumpSectionList); context->register_function( fat_cubin_handle, hostFun, deviceFun ); } @@ -2799,7 +2736,7 @@ extern void __cudaRegisterVar( printf("GPGPU-Sim PTX: __cudaRegisterVar: hostVar = %p; deviceAddress = %s; deviceName = %s\n", hostVar, deviceAddress, deviceName); printf("GPGPU-Sim PTX: __cudaRegisterVar: Registering const memory space of %d bytes\n", size); if(GPGPUSim_Context()->get_device()->get_gpgpu()->get_config().use_cuobjdump()) - cuobjdumpParseBinary((unsigned)(unsigned long long)fatCubinHandle); + cuobjdumpParseBinary((unsigned)(unsigned long long)fatCubinHandle, GPGPUSim_Context()->cuobjdumpSectionList ); fflush(stdout); if ( constant && !global && !ext ) { gpgpu_ptx_sim_register_const_variable(hostVar,deviceName,size); diff --git a/libcuda/cuobjdump.h b/libcuda/cuobjdump.h index 66cd736..49af3e2 100644 --- a/libcuda/cuobjdump.h +++ b/libcuda/cuobjdump.h @@ -1,5 +1,9 @@ #ifndef __cuobjdump_h__ #define __cuobjdump_h__ +#include +#include +#include + struct cuobjdump_parser { yyscan_t scanner; int elfserial; @@ -9,4 +13,67 @@ struct cuobjdump_parser { FILE *sassfile; char filename [1024]; }; + +class cuobjdumpSection { +public: + //Constructor + cuobjdumpSection() { + arch = 0; + identifier = ""; + } + virtual ~cuobjdumpSection() {} + unsigned getArch() {return arch;} + void setArch(unsigned a) {arch = a;} + std::string getIdentifier() {return identifier;} + void setIdentifier(std::string i) {identifier = i;} + virtual void print(){std::cout << "cuobjdump Section: unknown type" << std::endl;} +private: + unsigned arch; + std::string identifier; +}; + +class cuobjdumpELFSection : public cuobjdumpSection +{ +public: + cuobjdumpELFSection() {} + virtual ~cuobjdumpELFSection() { + elffilename = ""; + sassfilename = ""; + } + std::string getELFfilename() {return elffilename;} + void setELFfilename(std::string f) {elffilename = f;} + std::string getSASSfilename() {return sassfilename;} + void setSASSfilename(std::string f) {sassfilename = f;} + virtual void print() { + std::cout << "ELF Section:" << std::endl; + std::cout << "arch: sm_" << getArch() << std::endl; + std::cout << "identifier: " << getIdentifier() << std::endl; + std::cout << "elf filename: " << getELFfilename() << std::endl; + std::cout << "sass filename: " << getSASSfilename() << std::endl; + std::cout << std::endl; + } +private: + std::string elffilename; + std::string sassfilename; +}; + +class cuobjdumpPTXSection : public cuobjdumpSection +{ +public: + cuobjdumpPTXSection(){ + ptxfilename = ""; + } + std::string getPTXfilename() {return ptxfilename;} + void setPTXfilename(std::string f) {ptxfilename = f;} + virtual void print() { + std::cout << "PTX Section:" << std::endl; + std::cout << "arch: sm_" << getArch() << std::endl; + std::cout << "identifier: " << getIdentifier() << std::endl; + std::cout << "ptx filename: " << getPTXfilename() << std::endl; + std::cout << std::endl; + } +private: + std::string ptxfilename; +}; + #endif /* __cuobjdump_h__ */ diff --git a/libcuda/cuobjdump.l b/libcuda/cuobjdump.l index eccc1f2..5a19d65 100644 --- a/libcuda/cuobjdump.l +++ b/libcuda/cuobjdump.l @@ -39,9 +39,9 @@ #define YYDEBUG 1 -void cuobjdump_error(yyscan_t yyscanner, struct cuobjdump_parser* parser, const char* msg); +void cuobjdump_error(yyscan_t yyscanner, struct cuobjdump_parser* parser, std::list &cuobjdumpSectionList, const char* msg); #define YY_DECL int cuobjdump_lex \ - (YYSTYPE * yylval_param , yyscan_t yyscanner, struct cuobjdump_parser* parser) + (YYSTYPE * yylval_param , yyscan_t yyscanner, struct cuobjdump_parser* parser, std::list &cuobjdumpSectionList) %} %option stack @@ -156,10 +156,10 @@ newlines {newline}+ <> BEGIN(INITIAL);return 0; /*No other rule matched. Throw an error*/ -. cuobjdump_error(yyscanner, parser, "Invalid token"); +. cuobjdump_error(yyscanner, parser, cuobjdumpSectionList, "Invalid token"); %% -void cuobjdump_error(yyscan_t yyscanner, struct cuobjdump_parser* parser, const char* msg) +void cuobjdump_error(yyscan_t yyscanner, struct cuobjdump_parser* parser, std::list &cuobjdumpSectionList, const char* msg) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; printf(" %s near \"%s\"",msg, yytext); diff --git a/libcuda/cuobjdump.y b/libcuda/cuobjdump.y index fcc863e..8d1bca6 100644 --- a/libcuda/cuobjdump.y +++ b/libcuda/cuobjdump.y @@ -32,25 +32,27 @@ typedef void * yyscan_t; #include "cuobjdump.h" -extern void addCuobjdumpSection(int sectiontype); -void setCuobjdumparch(const char* arch); -void setCuobjdumpidentifier(const char* identifier); -void setCuobjdumpptxfilename(const char* filename); -void setCuobjdumpelffilename(const char* filename); -void setCuobjdumpsassfilename(const char* filename); +extern void addCuobjdumpSection(int sectiontype, std::list &cuobjdumpSectionList); +void setCuobjdumparch(const char* arch, std::list &cuobjdumpSectionList); +void setCuobjdumpidentifier(const char* identifier, std::list &cuobjdumpSectionList); +void setCuobjdumpptxfilename(const char* filename, std::list &cuobjdumpSectionList); +void setCuobjdumpelffilename(const char* filename, std::list &cuobjdumpSectionList); +void setCuobjdumpsassfilename(const char* filename, std::list &cuobjdumpSectionList); %} %define api.pure full %parse-param {yyscan_t scanner} %parse-param {struct cuobjdump_parser* parser} +%parse-param {std::list &cuobjdumpSectionList} %lex-param {yyscan_t scanner} %lex-param {struct cuobjdump_parser* parser} +%lex-param {std::list &cuobjdumpSectionList} %union { char* string_value; } %{ -int yylex(YYSTYPE * yylval_param, yyscan_t yyscanner, struct cuobjdump_parser* parser); -void yyerror(yyscan_t yyscanner, struct cuobjdump_parser* parser, const char* msg); +int yylex(YYSTYPE * yylval_param, yyscan_t yyscanner, struct cuobjdump_parser* parser, std::list &cuobjdumpSectionList); +void yyerror(yyscan_t yyscanner, struct cuobjdump_parser* parser, std::list &cuobjdumpSectionList, const char* msg); %} %token H_SEPARATOR H_ARCH H_CODEVERSION H_PRODUCER H_HOST H_COMPILESIZE H_IDENTIFIER H_UNKNOWN H_COMPRESSED %token CODEVERSION @@ -75,23 +77,23 @@ emptylines : emptylines NEWLINE | ; section : PTXHEADER { - addCuobjdumpSection(0); + addCuobjdumpSection(0, cuobjdumpSectionList); snprintf(parser->filename, 1024, "_cuobjdump_%d.ptx", parser->ptxserial++); parser->ptxfile = fopen(parser->filename, "w"); - setCuobjdumpptxfilename(parser->filename); + setCuobjdumpptxfilename(parser->filename, cuobjdumpSectionList); } headerinfo compressedkeyword identifier ptxcode { fclose(parser->ptxfile); } | ELFHEADER { - addCuobjdumpSection(1); + addCuobjdumpSection(1, cuobjdumpSectionList); snprintf(parser->filename, 1024, "_cuobjdump_%d.elf", parser->elfserial); parser->elffile = fopen(parser->filename, "w"); - setCuobjdumpelffilename(parser->filename); + setCuobjdumpelffilename(parser->filename, cuobjdumpSectionList); } headerinfo compressedkeyword identifier elfcode { fclose(parser->elffile); snprintf(parser->filename, 1024, "_cuobjdump_%d.sass", parser->elfserial++); parser->sassfile = fopen(parser->filename, "w"); - setCuobjdumpsassfilename(parser->filename); + setCuobjdumpsassfilename(parser->filename, cuobjdumpSectionList); } sasscode { fclose(parser->sassfile); }; @@ -101,16 +103,16 @@ headerinfo : H_SEPARATOR NEWLINE H_CODEVERSION CODEVERSION NEWLINE H_PRODUCER H_UNKNOWN NEWLINE H_HOST IDENTIFIER NEWLINE - H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4);}; + H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4, cuobjdumpSectionList);}; | H_SEPARATOR NEWLINE H_ARCH IDENTIFIER NEWLINE H_CODEVERSION CODEVERSION NEWLINE H_PRODUCER IDENTIFIER NEWLINE H_HOST IDENTIFIER NEWLINE - H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4);}; + H_COMPILESIZE IDENTIFIER {setCuobjdumparch($4, cuobjdumpSectionList);}; -identifier : H_IDENTIFIER FILENAME emptylines {setCuobjdumpidentifier($2);} - | {setCuobjdumpidentifier("default");}; +identifier : H_IDENTIFIER FILENAME emptylines {setCuobjdumpidentifier($2, cuobjdumpSectionList);} + | {setCuobjdumpidentifier("default", cuobjdumpSectionList);}; compressedkeyword : H_COMPRESSED emptylines | ; -- cgit v1.3