From dab24b95a31bf1401e42237ae2b46ab3df22058c Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Mon, 22 Apr 2019 23:27:52 -0400 Subject: Move ptxinfo to reentrant Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptxinfo.y | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/cuda-sim/ptxinfo.y') 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_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* ); %} -- cgit v1.3 From dc835911d5320008b2c227722a90240a8f6b0f3a Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Thu, 23 May 2019 22:44:37 -0400 Subject: Fix linebuf for ptxinfo Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_loader.cc | 32 ++++++++++++++++---------------- src/cuda-sim/ptx_loader.h | 10 ++++++++++ src/cuda-sim/ptxinfo.l | 19 +++++++++++-------- src/cuda-sim/ptxinfo.y | 10 +++++----- 4 files changed, 42 insertions(+), 29 deletions(-) (limited to 'src/cuda-sim/ptxinfo.y') diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc index 7eb18ee..735ff84 100644 --- a/src/cuda-sim/ptx_loader.cc +++ b/src/cuda-sim/ptx_loader.cc @@ -58,7 +58,7 @@ const char *g_ptxinfo_filename; 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_parse(yyscan_t scanner, ptxinfo_data* ptxinfo); extern int ptxinfo_lex_destroy(yyscan_t scanner); static bool g_save_embedded_ptx; @@ -359,11 +359,11 @@ 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"); - yyscan_t scanner; - ptxinfo_lex_init(&scanner); - ptxinfo_set_in(ptxinfo_in, scanner); - ptxinfo_parse(scanner); - ptxinfo_lex_destroy(scanner); + ptxinfo_data ptxinfo; + ptxinfo_lex_init(&(ptxinfo.scanner)); + ptxinfo_set_in(ptxinfo_in, ptxinfo.scanner); + ptxinfo_parse(ptxinfo.scanner, &ptxinfo); + ptxinfo_lex_destroy(ptxinfo.scanner); fclose(ptxinfo_in); } @@ -428,11 +428,11 @@ void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num FILE *ptxinfo_in; ptxinfo_in = fopen(tempfile_ptxinfo,"r"); g_ptxinfo_filename = tempfile_ptxinfo; - yyscan_t scanner; - ptxinfo_lex_init(&scanner); - ptxinfo_set_in(ptxinfo_in, scanner); - ptxinfo_parse(scanner); - ptxinfo_lex_destroy(scanner); + ptxinfo_data ptxinfo; + ptxinfo_lex_init(&(ptxinfo.scanner)); + ptxinfo_set_in(ptxinfo_in, ptxinfo.scanner); + ptxinfo_parse(ptxinfo.scanner, &ptxinfo); + ptxinfo_lex_destroy(ptxinfo.scanner); fclose(ptxinfo_in); fix_duplicate_errors(fname2); @@ -519,11 +519,11 @@ void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num FILE *ptxinfo_in; ptxinfo_in = fopen(g_ptxinfo_filename,"r"); - yyscan_t scanner; - ptxinfo_lex_init(&scanner); - ptxinfo_set_in(ptxinfo_in, scanner); - ptxinfo_parse(scanner); - ptxinfo_lex_destroy(scanner); + ptxinfo_data ptxinfo; + ptxinfo_lex_init(&(ptxinfo.scanner)); + ptxinfo_set_in(ptxinfo_in, ptxinfo.scanner); + ptxinfo_parse(ptxinfo.scanner, &ptxinfo); + ptxinfo_lex_destroy(ptxinfo.scanner); fclose(ptxinfo_in); snprintf(commandline,1024,"rm -f *info"); diff --git a/src/cuda-sim/ptx_loader.h b/src/cuda-sim/ptx_loader.h index e5df6a9..36e439e 100644 --- a/src/cuda-sim/ptx_loader.h +++ b/src/cuda-sim/ptx_loader.h @@ -29,6 +29,16 @@ #define PTX_LOADER_H_INCLUDED #include +#define LINEBUF_SIZE 1024 +typedef void * yyscan_t; +class ptxinfo_data{ + public: + yyscan_t scanner; + char linebuf[LINEBUF_SIZE]; + unsigned col; +}; + + extern bool g_override_embedded_ptx; extern int no_of_ptx; //counter to track number of ptx files to be extracted in an application. diff --git a/src/cuda-sim/ptxinfo.l b/src/cuda-sim/ptxinfo.l index a190e6d..92f7a30 100644 --- a/src/cuda-sim/ptxinfo.l +++ b/src/cuda-sim/ptxinfo.l @@ -36,14 +36,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %option reentrant %{ +#include "ptx_loader.h" #include "ptxinfo.tab.h" #include #define LINEBUF_SIZE 1024 -#define TC if( (yylineno == 1) && (yylval->col + strlen(yytext) < LINEBUF_SIZE) ) { \ - strncpy(yylval->linebuf+yylval->col,yytext,strlen(yytext)); \ +#define TC if( (yylineno == 1) && (ptxinfo->col + strlen(yytext) < LINEBUF_SIZE) ) { \ + strncpy(ptxinfo->linebuf+ptxinfo->col,yytext,strlen(yytext)); \ } \ - yylval->col+=strlen(yytext); + ptxinfo->col+=strlen(yytext); +#define YY_DECL int ptxinfo_lex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner, ptxinfo_data* ptxinfo) %} %% @@ -80,7 +83,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. " " TC; "\t" TC; -\n.* yylval->col=0; strncpy(yylval->linebuf, yytext + 1, 1024); yyless( 1 ); +\n.* ptxinfo->col=0; strncpy(ptxinfo->linebuf, yytext + 1, 1024); yyless( 1 ); %% @@ -88,7 +91,7 @@ extern int g_ptxinfo_error_detected; extern const char *g_filename; extern const char *g_ptxinfo_filename; -int ptxinfo_error(yyscan_t yyscanner, const char* msg) +int ptxinfo_error(yyscan_t yyscanner, ptxinfo_data* ptxinfo, const char* msg) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; int i; @@ -97,10 +100,10 @@ int ptxinfo_error(yyscan_t yyscanner, const char* msg) printf("GPGPU-Sim: ERROR while parsing output of ptxas (used to capture resource usage information)\n"); 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(" %s\n", ptxinfo->linebuf ); printf(" "); - for( i=0; i < yylval->col-1; i++ ) { - if( yylval->linebuf[i] == '\t' ) printf("\t"); + for( i=0; i < ptxinfo->col-1; i++ ) { + if( ptxinfo->linebuf[i] == '\t' ) printf("\t"); else printf(" "); } diff --git a/src/cuda-sim/ptxinfo.y b/src/cuda-sim/ptxinfo.y index eed304c..00c81e0 100644 --- a/src/cuda-sim/ptxinfo.y +++ b/src/cuda-sim/ptxinfo.y @@ -29,18 +29,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %{ typedef void * yyscan_t; +class ptxinfo_data; %} %define api.pure full %parse-param {yyscan_t scanner} +%parse-param {ptxinfo_data* ptxinfo} %lex-param {yyscan_t scanner} +%lex-param {ptxinfo_data* ptxinfo} %union { -#define LINEBUF_SIZE 1024 int int_value; char * string_value; - char linebuf[LINEBUF_SIZE]; - unsigned col; } %token INT_OPERAND @@ -77,8 +77,8 @@ typedef void * yyscan_t; static unsigned g_declared; static unsigned g_system; - int ptxinfo_lex(YYSTYPE * yylval_param, yyscan_t yyscanner); - void yyerror(yyscan_t yyscanner, const char* msg); + int ptxinfo_lex(YYSTYPE * yylval_param, yyscan_t yyscanner, ptxinfo_data* ptxinfo); + void yyerror(yyscan_t yyscanner, ptxinfo_data* ptxinfo, const char* msg); void ptxinfo_addinfo(); void ptxinfo_function(const char *fname ); void ptxinfo_regs( unsigned nregs ); -- cgit v1.3 From 3600ed5c59adafe40840524d19f622aa25e60dd6 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Tue, 2 Jul 2019 00:22:15 -0400 Subject: Move ptxinfo_addinfo Signed-off-by: Mengchi Zhang --- libcuda/cuda_runtime_api.cc | 2 +- src/cuda-sim/ptx_loader.h | 2 +- src/cuda-sim/ptxinfo.y | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'src/cuda-sim/ptxinfo.y') diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index a34727f..eb645ce 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -274,7 +274,7 @@ gpgpu_context* GPGPU_Context() return gpgpu_ctx; } - void ptxinfo_addinfo() + void ptxinfo_data::ptxinfo_addinfo() { if(!get_ptxinfo_kname()){ /* This info is not per kernel (since CUDA 5.0 some info (e.g. gmem, and cmem) is added at the beginning for the whole binary ) */ diff --git a/src/cuda-sim/ptx_loader.h b/src/cuda-sim/ptx_loader.h index ee09e16..77f27c8 100644 --- a/src/cuda-sim/ptx_loader.h +++ b/src/cuda-sim/ptx_loader.h @@ -37,7 +37,7 @@ class ptxinfo_data{ char linebuf[PTXINFO_LINEBUF_SIZE]; unsigned col; const char *g_ptxinfo_filename; - + void ptxinfo_addinfo(); }; diff --git a/src/cuda-sim/ptxinfo.y b/src/cuda-sim/ptxinfo.y index 00c81e0..b303958 100644 --- a/src/cuda-sim/ptxinfo.y +++ b/src/cuda-sim/ptxinfo.y @@ -29,7 +29,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %{ typedef void * yyscan_t; -class ptxinfo_data; +#include "ptx_loader.h" %} %define api.pure full @@ -79,7 +79,6 @@ class ptxinfo_data; static unsigned g_system; int ptxinfo_lex(YYSTYPE * yylval_param, yyscan_t yyscanner, ptxinfo_data* ptxinfo); void yyerror(yyscan_t yyscanner, ptxinfo_data* ptxinfo, const char* msg); - void ptxinfo_addinfo(); void ptxinfo_function(const char *fname ); void ptxinfo_regs( unsigned nregs ); void ptxinfo_lmem( unsigned declared, unsigned system ); @@ -104,7 +103,7 @@ line: HEADER INFO COLON line_info ; line_info: function_name - | function_info { ptxinfo_addinfo(); } + | function_info { ptxinfo->ptxinfo_addinfo(); } | gmem_info ; -- cgit v1.3