From 7d02cbb061485db38ed8e5f6bf06c9b2fa40eed2 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 13:19:08 -0400 Subject: Integrate ptxinfo into gpgpu_context Signed-off-by: Mengchi Zhang --- libcuda/cuda_runtime_api.cc | 2 +- libcuda/gpgpu_context.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'libcuda') diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index 14e3329..0a6eabb 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -640,7 +640,7 @@ void** cudaRegisterFatBinaryInternal( void *fatCubin, gpgpu_context* gpgpu_ctx = } else { symtab=ctx->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, max_capability, context->no_of_ptx ); + ctx->gpgpu_ptxinfo_load_from_string( ptx, source_num, max_capability, context->no_of_ptx ); } source_num++; ctx->api->load_static_globals(symtab,STATIC_ALLOC_LIMIT,0xFFFFFFFF,context->get_device()->get_gpgpu()); diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index 16626eb..d3db1ad 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -1,19 +1,24 @@ #ifndef __gpgpu_context_h__ #define __gpgpu_context_h__ #include "cuda_api_object.h" +#include "../src/cuda-sim/ptx_loader.h" class gpgpu_context { public: gpgpu_context() { api = new cuda_runtime_api(); + ptxinfo = new ptxinfo_data(); } // global list // objects pointers for each file cuda_runtime_api* api; + ptxinfo_data* ptxinfo; // member function list void cuobjdumpParseBinary(unsigned int handle); class symbol_table *gpgpu_ptx_sim_load_ptx_from_string( const char *p, unsigned source_num ); class symbol_table *gpgpu_ptx_sim_load_ptx_from_filename( const char *filename ); + void gpgpu_ptx_info_load_from_filename( const char *filename, unsigned sm_version); + void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num, unsigned sm_version=20, int no_of_ptx=0 ); }; gpgpu_context* GPGPU_Context(); -- cgit v1.3 From 7ac6034a99b52d09db7ef07bc008b8f6b039f929 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 18:03:35 -0400 Subject: Move print_ptx_file Signed-off-by: Mengchi Zhang --- libcuda/gpgpu_context.h | 1 + src/cuda-sim/ptx_loader.cc | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'libcuda') diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index d3db1ad..dbc3140 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -19,6 +19,7 @@ class gpgpu_context { class symbol_table *gpgpu_ptx_sim_load_ptx_from_filename( const char *filename ); void gpgpu_ptx_info_load_from_filename( const char *filename, unsigned sm_version); void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num, unsigned sm_version=20, int no_of_ptx=0 ); + void print_ptx_file( const char *p, unsigned source_num, const char *filename ); }; gpgpu_context* GPGPU_Context(); diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc index 2a6d930..38597e0 100644 --- a/src/cuda-sim/ptx_loader.cc +++ b/src/cuda-sim/ptx_loader.cc @@ -81,7 +81,7 @@ void ptx_reg_options(option_parser_t opp) "0"); } -void print_ptx_file( const char *p, unsigned source_num, const char *filename ) +void gpgpu_context::print_ptx_file( const char *p, unsigned source_num, const char *filename ) { printf("\nGPGPU-Sim PTX: file _%u.ptx contents:\n\n", source_num ); char *s = strdup(p); -- cgit v1.3 From c146d3707216f235a1dde3bd978239fd55b111ed Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 18:17:45 -0400 Subject: Move all ptx_parser inside gpgpu_context Signed-off-by: Mengchi Zhang --- libcuda/gpgpu_context.h | 4 ++++ src/cuda-sim/ptx_loader.cc | 9 ++++----- src/cuda-sim/ptx_parser.cc | 18 +++++++++--------- src/cuda-sim/ptx_parser.h | 1 - 4 files changed, 17 insertions(+), 15 deletions(-) (limited to 'libcuda') diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index dbc3140..b586e47 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -2,17 +2,20 @@ #define __gpgpu_context_h__ #include "cuda_api_object.h" #include "../src/cuda-sim/ptx_loader.h" +#include "../src/cuda-sim/ptx_parser.h" class gpgpu_context { public: gpgpu_context() { api = new cuda_runtime_api(); ptxinfo = new ptxinfo_data(); + ptx_parser = new ptx_recognizer(); } // global list // objects pointers for each file cuda_runtime_api* api; ptxinfo_data* ptxinfo; + ptx_recognizer* ptx_parser; // member function list void cuobjdumpParseBinary(unsigned int handle); class symbol_table *gpgpu_ptx_sim_load_ptx_from_string( const char *p, unsigned source_num ); @@ -20,6 +23,7 @@ class gpgpu_context { void gpgpu_ptx_info_load_from_filename( const char *filename, unsigned sm_version); void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num, unsigned sm_version=20, int no_of_ptx=0 ); void print_ptx_file( const char *p, unsigned source_num, const char *filename ); + class symbol_table* init_parser(const char*); }; gpgpu_context* GPGPU_Context(); diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc index 38597e0..921d1e6 100644 --- a/src/cuda-sim/ptx_loader.cc +++ b/src/cuda-sim/ptx_loader.cc @@ -170,10 +170,9 @@ symbol_table *gpgpu_context::gpgpu_ptx_sim_load_ptx_from_string( const char *p, fclose(fp); } symbol_table *symtab=init_parser(buf); - ptx_recognizer recognizer; - ptx_lex_init(&(recognizer.scanner)); - ptx__scan_string(p, recognizer.scanner); - int errors = ptx_parse (recognizer.scanner, &recognizer); + ptx_lex_init(&(ptx_parser->scanner)); + ptx__scan_string(p, ptx_parser->scanner); + int errors = ptx_parse (ptx_parser->scanner, ptx_parser); if ( errors ) { char fname[1024]; snprintf(fname,1024,"_ptx_errors_XXXXXX"); @@ -186,7 +185,7 @@ symbol_table *gpgpu_context::gpgpu_ptx_sim_load_ptx_from_string( const char *p, abort(); exit(40); } - ptx_lex_destroy(recognizer.scanner); + ptx_lex_destroy(ptx_parser->scanner); if ( g_debug_execution >= 100 ) print_ptx_file(p,source_num,buf); diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 897beaf..7080ee9 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -27,6 +27,7 @@ #include "ptx_parser.h" #include "ptx_ir.h" +#include "../../libcuda/gpgpu_context.h" typedef void * yyscan_t; #include "ptx.tab.h" @@ -122,7 +123,7 @@ void ptx_recognizer::init_instruction_state() init_directive_state(); } -symbol_table *init_parser( const char *ptx_filename ) +symbol_table * gpgpu_context::init_parser( const char *ptx_filename ) { g_filename = strdup(ptx_filename); if (g_global_allfiles_symbol_table == NULL) { @@ -151,17 +152,16 @@ symbol_table *init_parser( const char *ptx_filename ) g_ptx_token_decode[generic_space] = "generic_space"; g_ptx_token_decode[instruction_space] = "instruction_space"; - ptx_recognizer recognizer; - ptx_lex_init(&(recognizer.scanner)); - recognizer.init_directive_state(); - recognizer.init_instruction_state(); + ptx_lex_init(&(ptx_parser->scanner)); + ptx_parser->init_directive_state(); + ptx_parser->init_instruction_state(); FILE *ptx_in; ptx_in = fopen(ptx_filename, "r"); - ptx_set_in(ptx_in, recognizer.scanner); - ptx_parse(recognizer.scanner, &recognizer); - ptx_in = ptx_get_in(recognizer.scanner); - ptx_lex_destroy(recognizer.scanner); + ptx_set_in(ptx_in, ptx_parser->scanner); + ptx_parse(ptx_parser->scanner, ptx_parser); + ptx_in = ptx_get_in(ptx_parser->scanner); + ptx_lex_destroy(ptx_parser->scanner); fclose(ptx_in); return g_global_symbol_table; } diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index c52fe20..5293c2e 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -34,7 +34,6 @@ extern const char *g_filename; extern int g_error_detected; #ifdef __cplusplus -class symbol_table* init_parser(const char*); const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); #endif -- cgit v1.3 From 5530b51c7c572d25717ad7f5d81196011dfcb540 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 18:49:58 -0400 Subject: Move symbol table globals Signed-off-by: Mengchi Zhang --- libcuda/gpgpu_context.h | 2 ++ src/cuda-sim/ptx_parser.cc | 10 +++------- src/cuda-sim/ptx_parser.h | 7 +++++++ 3 files changed, 12 insertions(+), 7 deletions(-) (limited to 'libcuda') diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index b586e47..fa5d02b 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -7,11 +7,13 @@ class gpgpu_context { public: gpgpu_context() { + g_global_allfiles_symbol_table = NULL; api = new cuda_runtime_api(); ptxinfo = new ptxinfo_data(); ptx_parser = new ptx_recognizer(); } // global list + symbol_table *g_global_allfiles_symbol_table; // objects pointers for each file cuda_runtime_api* api; ptxinfo_data* ptxinfo; diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 7080ee9..32e12a1 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -52,12 +52,8 @@ static bool g_debug_ir_generation=false; const char *g_filename; // the program intermediate representation... -static symbol_table *g_global_allfiles_symbol_table = NULL; -static symbol_table *g_global_symbol_table = NULL; std::map g_sym_name_to_symbol_table; -static symbol_table *g_current_symbol_table = NULL; static std::list g_instructions; -static symbol *g_last_symbol = NULL; int g_error_detected = 0; @@ -128,7 +124,7 @@ symbol_table * gpgpu_context::init_parser( const char *ptx_filename ) g_filename = strdup(ptx_filename); if (g_global_allfiles_symbol_table == NULL) { g_global_allfiles_symbol_table = new symbol_table("global_allfiles", 0, NULL); - g_global_symbol_table = g_current_symbol_table = g_global_allfiles_symbol_table; + ptx_parser->g_global_symbol_table = ptx_parser->g_current_symbol_table = g_global_allfiles_symbol_table; } /*else { g_global_symbol_table = g_current_symbol_table = new symbol_table("global",0,g_global_allfiles_symbol_table); @@ -163,7 +159,7 @@ symbol_table * gpgpu_context::init_parser( const char *ptx_filename ) ptx_in = ptx_get_in(ptx_parser->scanner); ptx_lex_destroy(ptx_parser->scanner); fclose(ptx_in); - return g_global_symbol_table; + return ptx_parser->g_global_symbol_table; } static int g_entry_point; @@ -331,7 +327,7 @@ void ptx_recognizer::set_variable_type() g_extern_spec ); } -bool check_for_duplicates( const char *identifier ) +bool ptx_recognizer::check_for_duplicates( const char *identifier ) { const symbol *s = g_current_symbol_table->lookup(identifier); return ( s != NULL ); diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index 5293c2e..cc8fe18 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -56,6 +56,9 @@ class ptx_recognizer { g_ident_add_uid = 0; g_const_alloc = 1; g_max_regs_per_thread = 0; + g_global_symbol_table = NULL; + g_current_symbol_table = NULL; + symbol *g_last_symbol = NULL; } // global list yyscan_t scanner; @@ -89,6 +92,9 @@ class ptx_recognizer { int g_ident_add_uid; unsigned g_const_alloc; unsigned g_max_regs_per_thread; + symbol_table *g_global_symbol_table; + symbol_table *g_current_symbol_table; + symbol *g_last_symbol; // member function list void init_directive_state(); @@ -154,6 +160,7 @@ class ptx_recognizer { //Jin: handle instructino group for cdp void start_inst_group(); void end_inst_group(); + bool check_for_duplicates( const char *identifier ); }; -- cgit v1.3