From 1fb385af6e036588a0b807aa51d74dcf34f841cd Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Fri, 17 May 2019 10:59:27 -0400 Subject: Move ptx parser to reentrant Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_parser.h | 134 +++++++++++++++++++++++++--------------------- 1 file changed, 73 insertions(+), 61 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index 7b6e3a2..70c4dfb 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -37,69 +37,81 @@ class symbol_table* init_parser(const char*); const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); #endif +typedef void * yyscan_t; +class ptx_recognizer { + public: + ptx_recognizer() { + scanner = NULL; + } + yyscan_t scanner; + void init_directive_state(); + void init_instruction_state(); + void start_function( int entry_point ); + void add_function_name( const char *fname ); + void add_directive(); + void end_function(); + void add_identifier( const char *s, int array_dim, unsigned array_ident ); + void add_function_arg(); + void add_scalar_type_spec( int type_spec ); + void add_scalar_operand( const char *identifier ); + void add_neg_pred_operand( const char *identifier ); + void add_variables(); + void set_variable_type(); + void add_opcode( int opcode ); + void add_pred( const char *identifier, int negate, int predModifier ); + void add_1vector_operand( const char *d1 ); + void add_2vector_operand( const char *d1, const char *d2 ); + void add_3vector_operand( const char *d1, const char *d2, const char *d3 ); + void add_4vector_operand( const char *d1, const char *d2, const char *d3, const char *d4 ); + void add_8vector_operand( const char *d1, const char *d2, const char *d3, const char *d4 ,const char *d5,const char *d6,const char *d7,const char *d8); + void add_option(int option ); + void add_wmma_option(int option ); + void add_builtin_operand( int builtin, int dim_modifier ); + void add_memory_operand( ); + void add_literal_int( int value ); + void add_literal_float( float value ); + void add_literal_double( double value ); + void add_address_operand( const char *identifier, int offset ); + void add_address_operand2( int offset ); + void add_label( const char *idenfiier ); + void add_vector_spec(int spec ); + void add_space_spec( enum _memory_space_t spec, int value ); + void add_ptr_spec( enum _memory_space_t spec ); + void add_extern_spec(); + void add_instruction(); + void set_return(); + void add_alignment_spec( int spec ); + void add_array_initializer(); + void add_file( unsigned num, const char *filename ); + void add_version_info( float ver, unsigned ext); + void *reset_symtab(); + void set_symtab(void*); + void add_pragma( const char *str ); + void func_header(const char* a); + void func_header_info(const char* a); + void func_header_info_int(const char* a, int b); + void add_constptr(const char* identifier1, const char* identifier2, int offset); + void target_header(char* a); + void target_header2(char* a, char* b); + void target_header3(char* a, char* b, char* c); + void add_double_operand( const char *d1, const char *d2 ); + void change_memory_addr_space( const char *identifier ); + void change_operand_lohi( int lohi ); + void change_double_operand_type( int addr_type ); + void change_operand_neg( ); + void set_immediate_operand_type( ); + void version_header(double a); + void maxnt_id(int x, int y, int z); + void parse_error_impl( const char *file, unsigned line, const char *msg, ... ); + void parse_assert_impl( int test_value, const char *file, unsigned line, const char *msg, ... ); + //Jin: handle instructino group for cdp + void start_inst_group(); + void end_inst_group(); + +}; + const char *decode_token( int type ); void read_parser_environment_variables(); -void start_function( int entry_point ); -void add_function_name( const char *fname ); -void init_directive_state(); -void add_directive(); -void end_function(); -void add_identifier( const char *s, int array_dim, unsigned array_ident ); -void add_function_arg(); -void add_scalar_type_spec( int type_spec ); -void add_scalar_operand( const char *identifier ); -void add_neg_pred_operand( const char *identifier ); -void add_variables(); -void set_variable_type(); -void add_opcode( int opcode ); -void add_pred( const char *identifier, int negate, int predModifier ); -void add_1vector_operand( const char *d1 ); -void add_2vector_operand( const char *d1, const char *d2 ); -void add_3vector_operand( const char *d1, const char *d2, const char *d3 ); -void add_4vector_operand( const char *d1, const char *d2, const char *d3, const char *d4 ); -void add_8vector_operand( const char *d1, const char *d2, const char *d3, const char *d4 ,const char *d5,const char *d6,const char *d7,const char *d8); -void add_option(int option ); -void add_wmma_option(int option ); -void add_builtin_operand( int builtin, int dim_modifier ); -void add_memory_operand( ); -void add_literal_int( int value ); -void add_literal_float( float value ); -void add_literal_double( double value ); -void add_address_operand( const char *identifier, int offset ); -void add_address_operand2( int offset ); -void add_label( const char *idenfiier ); -void add_vector_spec(int spec ); -void add_space_spec( enum _memory_space_t spec, int value ); -void add_ptr_spec( enum _memory_space_t spec ); -void add_extern_spec(); -void add_instruction(); -void set_return(); -void add_alignment_spec( int spec ); -void add_array_initializer(); -void add_file( unsigned num, const char *filename ); -void add_version_info( float ver, unsigned ext); -void *reset_symtab(); -void set_symtab(void*); -void add_pragma( const char *str ); -void func_header(const char* a); -void func_header_info(const char* a); -void func_header_info_int(const char* a, int b); -void add_constptr(const char* identifier1, const char* identifier2, int offset); -void target_header(char* a); -void target_header2(char* a, char* b); -void target_header3(char* a, char* b, char* c); -void add_double_operand( const char *d1, const char *d2 ); -void change_memory_addr_space( const char *identifier ); -void change_operand_lohi( int lohi ); -void change_double_operand_type( int addr_type ); -void change_operand_neg( ); -void set_immediate_operand_type( ); -void version_header(double a); -void maxnt_id(int x, int y, int z); - -//Jin: handle instructino group for cdp -void start_inst_group(); -void end_inst_group(); #define NON_ARRAY_IDENTIFIER 1 #define ARRAY_IDENTIFIER_NO_DIM 2 -- cgit v1.3 From 579047c1dd9fec1b69e7904aeb6a25553c8dbd69 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Mon, 20 May 2019 02:17:58 -0400 Subject: Fix col and linebuf Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx.l | 17 +++++++++-------- src/cuda-sim/ptx.y | 6 ++---- src/cuda-sim/ptx_parser.cc | 4 +++- src/cuda-sim/ptx_parser.h | 3 +++ 4 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx.l b/src/cuda-sim/ptx.l index cc83bd1..2546a99 100644 --- a/src/cuda-sim/ptx.l +++ b/src/cuda-sim/ptx.l @@ -37,17 +37,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %{ #include "opcodes.h" -class ptx_recognizer; +#include "ptx_parser.h" #include "ptx.tab.h" #include #define LINEBUF_SIZE (4*1024) -#define TC yylval->col+=strlen(yytext); +#define TC recognizer->col+=strlen(yytext); #define CHECK_UNSIGNED \ if( yytext[strlen(yytext)-1]=='U' ) { \ printf("GPGPU-Sim: ERROR ** U modifier not implemented\n"); \ abort(); \ } +#define YY_DECL int ptx_lex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner, ptx_recognizer* recognizer) int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ); %} @@ -414,7 +416,7 @@ breakaddr TC; yylval->int_value = BREAKADDR_OP; return OPCODE; "//"[^\n]* TC; // eat single -\n.* yylval->col=0; strncpy(yylval->linebuf, yytext + 1, LINEBUF_SIZE); yyless( 1 ); +\n.* recognizer->col=0; strncpy(recognizer->linebuf, yytext + 1, LINEBUF_SIZE); yyless( 1 ); " " TC; "\t" TC; @@ -447,9 +449,8 @@ breakaddr TC; yylval->int_value = BREAKADDR_OP; return OPCODE; <*>\t@@DWARF.*\n -. TC; +. TC; ptx_error(yyscanner, recognizer, (const char*)NULL); %% -//ptx_error(yyscanner, (const char*)NULL); extern int g_error_detected; extern const char *g_filename; @@ -462,10 +463,10 @@ int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ) fflush(stdout); if( s != NULL ) printf("%s:%u Syntax error:\n\n", g_filename, yylineno ); - printf(" %s\n", yylval->linebuf ); + printf(" %s\n", recognizer->linebuf ); printf(" "); - for( i=0; i < yylval->col-1; i++ ) { - if( yylval->linebuf[i] == '\t' ) printf("\t"); + for( i=0; i < recognizer->col-1; i++ ) { + if( recognizer->linebuf[i] == '\t' ) printf("\t"); else printf(" "); } diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y index 38a627f..8447693 100644 --- a/src/cuda-sim/ptx.y +++ b/src/cuda-sim/ptx.y @@ -36,6 +36,7 @@ class ptx_recognizer; %parse-param {yyscan_t scanner} %parse-param {ptx_recognizer* recognizer} %lex-param {yyscan_t scanner} +%lex-param {ptx_recognizer* recognizer} %union { double double_value; @@ -43,9 +44,6 @@ class ptx_recognizer; int int_value; char * string_value; void * ptr_value; -#define LINEBUF_SIZE (4*1024) - char linebuf[LINEBUF_SIZE]; - unsigned col; } %token STRING @@ -232,7 +230,7 @@ class ptx_recognizer; #include void syntax_not_implemented(yyscan_t yyscanner, ptx_recognizer* recognizer); extern int g_func_decl; - int ptx_lex(YYSTYPE * yylval_param, yyscan_t yyscanner); + int ptx_lex(YYSTYPE * yylval_param, yyscan_t yyscanner, ptx_recognizer* recognizer); int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ); %} diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 2ec8386..c4cc911 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -37,6 +37,7 @@ extern YYSTYPE* ptx_get_lval (yyscan_t yyscanner ); extern int ptx_error( yyscan_t yyscanner, const char *s ); extern int ptx_lex_init(yyscan_t* scanner); extern void ptx_set_in(FILE * _in_str ,yyscan_t yyscanner ); +extern FILE *ptx_get_in (yyscan_t yyscanner ); extern int ptx_parse(yyscan_t scanner, ptx_recognizer* recognizer); extern int ptx_lex_destroy(yyscan_t scanner); @@ -182,6 +183,7 @@ symbol_table *init_parser( const char *ptx_filename ) 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); fclose(ptx_in); return g_global_symbol_table; @@ -325,7 +327,7 @@ void ptx_recognizer::add_instruction() g_space_spec, g_filename, ptx_get_lineno(scanner), - ptx_get_lval(scanner)->linebuf, + linebuf, g_shader_core_config ); g_instructions.push_back(i); g_inst_lookup[g_filename][ptx_get_lineno(scanner)] = i; diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index 70c4dfb..fdff6ce 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -44,6 +44,9 @@ class ptx_recognizer { scanner = NULL; } yyscan_t scanner; +#define LINEBUF_SIZE (4*1024) + char linebuf[LINEBUF_SIZE]; + unsigned col; void init_directive_state(); void init_instruction_state(); void start_function( int entry_point ); -- cgit v1.3 From 603e53ee948fecd623837b52c4e94ca2dbf0012b Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Thu, 30 May 2019 13:44:15 -0400 Subject: Move some variables in ptx_parser Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_parser.cc | 5 ----- src/cuda-sim/ptx_parser.h | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index c4cc911..a61dc16 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -67,7 +67,6 @@ memory_space_t g_ptr_spec = undefined_space; int g_scalar_type_spec = -1; int g_vector_spec = -1; int g_alignment_spec = -1; -int g_size = -1; int g_extern_spec = 0; // variable declaration stuff: @@ -201,10 +200,6 @@ void ptx_recognizer::start_function( int entry_point ) g_entry_func_param_index=0; } -char *g_add_identifier_cached__identifier = NULL; -int g_add_identifier_cached__array_dim; -int g_add_identifier_cached__array_ident; - void ptx_recognizer::add_function_name( const char *name ) { PTX_PARSE_DPRINTF("add_function_name %s %s", name, ((g_entry_point==1)?"(entrypoint)":((g_entry_point==2)?"(extern)":""))); diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index fdff6ce..fb1b7f2 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -42,11 +42,18 @@ class ptx_recognizer { public: ptx_recognizer() { scanner = NULL; + g_size = -1; + g_add_identifier_cached__identifier = NULL; } yyscan_t scanner; #define LINEBUF_SIZE (4*1024) char linebuf[LINEBUF_SIZE]; unsigned col; + int g_size; + char *g_add_identifier_cached__identifier; + int g_add_identifier_cached__array_dim; + int g_add_identifier_cached__array_ident; + void init_directive_state(); void init_instruction_state(); void start_function( int entry_point ); -- cgit v1.3 From 976ec40b2614fe4e935486ce8be932bf5e573447 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Sun, 9 Jun 2019 21:36:23 -0400 Subject: Move ptx_parser vars Signed-off-by: Mengchi Zhang --- src/cuda-sim/Makefile | 8 ++++---- src/cuda-sim/ptx_parser.cc | 21 --------------------- src/cuda-sim/ptx_parser.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 25 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/Makefile b/src/cuda-sim/Makefile index 999dad7..85d1c8c 100644 --- a/src/cuda-sim/Makefile +++ b/src/cuda-sim/Makefile @@ -79,16 +79,16 @@ libgpgpu_ptx_sim.a: $(OBJS) ar rcs $(OUTPUT_DIR)/libgpgpu_ptx_sim.a $(OUTPUT_DIR)/ptx.tab.o $(OUTPUT_DIR)/lex.ptx_.o $(OUTPUT_DIR)/ptxinfo.tab.o $(OUTPUT_DIR)/lex.ptxinfo_.o $(OBJS) $(OUTPUT_DIR)/ptx.tab.o: $(OUTPUT_DIR)/ptx.tab.c - $(CPP) -c $(OPT) -DYYDEBUG $(OUTPUT_DIR)/ptx.tab.c -o $(OUTPUT_DIR)/ptx.tab.o + $(CPP) -c $(CXX_OPT) -DYYDEBUG $(OUTPUT_DIR)/ptx.tab.c -o $(OUTPUT_DIR)/ptx.tab.o $(OUTPUT_DIR)/lex.ptx_.o: $(OUTPUT_DIR)/lex.ptx_.c - $(CPP) -c $(OPT) $(OUTPUT_DIR)/lex.ptx_.c -o $(OUTPUT_DIR)/lex.ptx_.o + $(CPP) -c $(CXX_OPT) $(OUTPUT_DIR)/lex.ptx_.c -o $(OUTPUT_DIR)/lex.ptx_.o $(OUTPUT_DIR)/ptxinfo.tab.o: $(OUTPUT_DIR)/ptxinfo.tab.c - $(CPP) -c $(OPT) -DYYDEBUG $(OUTPUT_DIR)/ptxinfo.tab.c -o $(OUTPUT_DIR)/ptxinfo.tab.o + $(CPP) -c $(CXX_OPT) -DYYDEBUG $(OUTPUT_DIR)/ptxinfo.tab.c -o $(OUTPUT_DIR)/ptxinfo.tab.o $(OUTPUT_DIR)/lex.ptxinfo_.o: $(OUTPUT_DIR)/lex.ptxinfo_.c $(OUTPUT_DIR)/ptxinfo.tab.c - $(CPP) -c $(OPT) $(OUTPUT_DIR)/lex.ptxinfo_.c -o $(OUTPUT_DIR)/lex.ptxinfo_.o + $(CPP) -c $(CXX_OPT) $(OUTPUT_DIR)/lex.ptxinfo_.c -o $(OUTPUT_DIR)/lex.ptxinfo_.o $(OUTPUT_DIR)/ptx.tab.c: ptx.y bison --name-prefix=ptx_ -v -d ptx.y --file-prefix=$(OUTPUT_DIR)/ptx diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index a61dc16..84eec65 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -61,27 +61,6 @@ static symbol *g_last_symbol = NULL; int g_error_detected = 0; -// type specifier stuff: -memory_space_t g_space_spec = undefined_space; -memory_space_t g_ptr_spec = undefined_space; -int g_scalar_type_spec = -1; -int g_vector_spec = -1; -int g_alignment_spec = -1; -int g_extern_spec = 0; - -// variable declaration stuff: -type_info *g_var_type = NULL; - -// instruction definition stuff: -const symbol *g_pred; -int g_neg_pred; -int g_pred_mod; -symbol *g_label; -int g_opcode = -1; -std::list g_operands; -std::list g_options; -std::list g_wmma_options; -std::list g_scalar_type; #define PTX_PARSE_DPRINTF(...) \ if( g_debug_ir_generation ) { \ diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index fb1b7f2..b2388fa 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -29,6 +29,7 @@ #define ptx_parser_INCLUDED #include "../abstract_hardware_model.h" +#include "ptx_ir.h" extern const char *g_filename; extern int g_error_detected; @@ -44,7 +45,16 @@ class ptx_recognizer { scanner = NULL; g_size = -1; g_add_identifier_cached__identifier = NULL; + g_alignment_spec = -1; + g_var_type = NULL; + g_opcode = -1; + g_space_spec = undefined_space; + g_ptr_spec = undefined_space; + g_scalar_type_spec = -1; + g_vector_spec = -1; + g_extern_spec = 0; } + // global list yyscan_t scanner; #define LINEBUF_SIZE (4*1024) char linebuf[LINEBUF_SIZE]; @@ -53,7 +63,27 @@ class ptx_recognizer { char *g_add_identifier_cached__identifier; int g_add_identifier_cached__array_dim; int g_add_identifier_cached__array_ident; + int g_alignment_spec; + // variable declaration stuff: + type_info *g_var_type; + // instruction definition stuff: + const symbol *g_pred; + int g_neg_pred; + int g_pred_mod; + symbol *g_label; + int g_opcode; + std::list g_operands; + std::list g_options; + std::list g_wmma_options; + std::list g_scalar_type; + // type specifier stuff: + memory_space_t g_space_spec; + memory_space_t g_ptr_spec; + int g_scalar_type_spec; + int g_vector_spec; + int g_extern_spec; + // member function list void init_directive_state(); void init_instruction_state(); void start_function( int entry_point ); -- cgit v1.3 From dca532b090edcf3fb840a697a8a0919d301c3dd7 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Sun, 9 Jun 2019 21:57:13 -0400 Subject: Add more vars for ptx_parser Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_parser.cc | 5 ----- src/cuda-sim/ptx_parser.h | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 84eec65..897beaf 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -49,7 +49,6 @@ void set_ptx_warp_size(const struct core_config * warp_size) static bool g_debug_ir_generation=false; const char *g_filename; -unsigned g_max_regs_per_thread = 0; // the program intermediate representation... static symbol_table *g_global_allfiles_symbol_table = NULL; @@ -341,10 +340,6 @@ bool check_for_duplicates( const char *identifier ) extern std::set g_globals; extern std::set g_constants; -int g_func_decl = 0; -int g_ident_add_uid = 0; -unsigned g_const_alloc = 1; - // Returns padding that needs to be inserted ahead of address to make it aligned to min(size, maxalign) /* * @param address the address in bytes diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index b2388fa..c52fe20 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -53,6 +53,10 @@ class ptx_recognizer { g_scalar_type_spec = -1; g_vector_spec = -1; g_extern_spec = 0; + g_func_decl = 0; + g_ident_add_uid = 0; + g_const_alloc = 1; + g_max_regs_per_thread = 0; } // global list yyscan_t scanner; @@ -82,6 +86,10 @@ class ptx_recognizer { int g_scalar_type_spec; int g_vector_spec; int g_extern_spec; + int g_func_decl; + int g_ident_add_uid; + unsigned g_const_alloc; + unsigned g_max_regs_per_thread; // member function list void init_directive_state(); -- 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 'src/cuda-sim/ptx_parser.h') 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 'src/cuda-sim/ptx_parser.h') 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 From e5447646aaca133f2cc5cbafcaf7aeef4b384c62 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 19:13:55 -0400 Subject: Add some vars in ptx_parser Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx.l | 3 +-- src/cuda-sim/ptx_parser.cc | 5 ----- src/cuda-sim/ptx_parser.h | 5 +++++ 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx.l b/src/cuda-sim/ptx.l index 2546a99..18952a9 100644 --- a/src/cuda-sim/ptx.l +++ b/src/cuda-sim/ptx.l @@ -452,14 +452,13 @@ breakaddr TC; yylval->int_value = BREAKADDR_OP; return OPCODE; . TC; ptx_error(yyscanner, recognizer, (const char*)NULL); %% -extern int g_error_detected; extern const char *g_filename; int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; int i; - g_error_detected = 1; + recognizer->g_error_detected = 1; fflush(stdout); if( s != NULL ) printf("%s:%u Syntax error:\n\n", g_filename, yylineno ); diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 32e12a1..a01d1e3 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -53,10 +53,6 @@ const char *g_filename; // the program intermediate representation... std::map g_sym_name_to_symbol_table; -static std::list g_instructions; - -int g_error_detected = 0; - #define PTX_PARSE_DPRINTF(...) \ if( g_debug_ir_generation ) { \ @@ -67,7 +63,6 @@ int g_error_detected = 0; fflush(stdout); \ } -static unsigned g_entry_func_param_index=0; static function_info *g_func_info = NULL; static std::map g_ptx_token_decode; static operand_info g_return_var; diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index cc8fe18..c4e0b89 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -59,6 +59,8 @@ class ptx_recognizer { g_global_symbol_table = NULL; g_current_symbol_table = NULL; symbol *g_last_symbol = NULL; + g_error_detected = 0; + g_entry_func_param_index=0; } // global list yyscan_t scanner; @@ -95,6 +97,9 @@ class ptx_recognizer { symbol_table *g_global_symbol_table; symbol_table *g_current_symbol_table; symbol *g_last_symbol; + std::list g_instructions; + int g_error_detected; + unsigned g_entry_func_param_index; // member function list void init_directive_state(); -- cgit v1.3 From 632bdaab79b9c1fd51ef8152aa00209f76c03101 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 12 Jun 2019 19:55:35 -0400 Subject: Fix some compiler warning Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_loader.h | 4 ++-- src/cuda-sim/ptx_parser.cc | 2 -- src/cuda-sim/ptx_parser.h | 9 ++++++--- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_loader.h b/src/cuda-sim/ptx_loader.h index 3637bff..ee09e16 100644 --- a/src/cuda-sim/ptx_loader.h +++ b/src/cuda-sim/ptx_loader.h @@ -29,12 +29,12 @@ #define PTX_LOADER_H_INCLUDED #include -#define LINEBUF_SIZE 1024 +#define PTXINFO_LINEBUF_SIZE 1024 typedef void * yyscan_t; class ptxinfo_data{ public: yyscan_t scanner; - char linebuf[LINEBUF_SIZE]; + char linebuf[PTXINFO_LINEBUF_SIZE]; unsigned col; const char *g_ptxinfo_filename; diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index a01d1e3..2872b84 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -63,9 +63,7 @@ std::map g_sym_name_to_symbol_table; fflush(stdout); \ } -static function_info *g_func_info = NULL; static std::map g_ptx_token_decode; -static operand_info g_return_var; const char *decode_token( int type ) { diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index c4e0b89..25c01fe 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -58,14 +58,15 @@ class ptx_recognizer { g_max_regs_per_thread = 0; g_global_symbol_table = NULL; g_current_symbol_table = NULL; - symbol *g_last_symbol = NULL; + g_last_symbol = NULL; g_error_detected = 0; g_entry_func_param_index=0; + g_func_info = NULL; } // global list yyscan_t scanner; -#define LINEBUF_SIZE (4*1024) - char linebuf[LINEBUF_SIZE]; +#define PTX_LINEBUF_SIZE (4*1024) + char linebuf[PTX_LINEBUF_SIZE]; unsigned col; int g_size; char *g_add_identifier_cached__identifier; @@ -100,6 +101,8 @@ class ptx_recognizer { std::list g_instructions; int g_error_detected; unsigned g_entry_func_param_index; + function_info *g_func_info; + operand_info g_return_var; // member function list void init_directive_state(); -- cgit v1.3 From cb678c3670de4a435a3260ed80dc476da3860082 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Mon, 1 Jul 2019 16:23:33 -0400 Subject: Move g_debug_ir_generation and GPGPUSim_Init Signed-off-by: Mengchi Zhang --- libcuda/cuda_runtime_api.cc | 674 ++++++++++++++++++++++------------------ libcuda/gpgpu_context.h | 2 + libopencl/opencl_runtime_api.cc | 4 +- src/cuda-sim/ptx_parser.cc | 3 +- src/cuda-sim/ptx_parser.h | 3 + src/gpgpusim_entrypoint.cc | 5 +- src/gpgpusim_entrypoint.h | 1 - 7 files changed, 375 insertions(+), 317 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index 61f8415..a34727f 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -197,7 +197,7 @@ void register_ptx_function( const char *name, function_info *impl ) # endif #endif -struct _cuda_device_id *GPGPUSim_Init() +struct _cuda_device_id *gpgpu_context::GPGPUSim_Init() { //static _cuda_device_id *the_device = NULL; _cuda_device_id *the_device = GPGPUsim_ctx_ptr()->the_cude_device; @@ -255,9 +255,10 @@ struct _cuda_device_id *GPGPUSim_Init() static CUctx_st* GPGPUSim_Context() { //static CUctx_st *the_context = NULL; + gpgpu_context *cur_ctx = GPGPU_Context(); CUctx_st *the_context = GPGPUsim_ctx_ptr()->the_context; if( the_context == NULL ) { - _cuda_device_id *the_gpu = GPGPUSim_Init(); + _cuda_device_id *the_gpu = cur_ctx->GPGPUSim_Init(); GPGPUsim_ctx_ptr()->the_context = new CUctx_st(the_gpu); the_context = GPGPUsim_ctx_ptr()->the_context; } @@ -496,7 +497,7 @@ cudaError_t cudaSetDeviceInternal(int device, gpgpu_context* gpgpu_ctx = NULL) announce_call(__my_func__); } //set the active device to run cuda - if ( device <= GPGPUSim_Init()->num_devices() ) { + if ( device <= ctx->GPGPUSim_Init()->num_devices() ) { ctx->api->g_active_device = device; return g_last_cudaError = cudaSuccess; } else { @@ -519,6 +520,55 @@ cudaError_t cudaGetDeviceInternal(int *device, gpgpu_context* gpgpu_ctx = NULL) return g_last_cudaError = cudaSuccess; } +__host__ cudaError_t CUDARTAPI cudaDeviceGetLimitInternal( size_t* pValue, cudaLimit limit, gpgpu_context* gpgpu_ctx = NULL ) +{ + gpgpu_context *ctx; + if (gpgpu_ctx){ + ctx = gpgpu_ctx; + } else { + ctx = GPGPU_Context(); + } + if(g_debug_execution >= 3){ + announce_call(__my_func__); + } + _cuda_device_id *dev = ctx->GPGPUSim_Init(); + const struct cudaDeviceProp *prop = dev->get_prop(); + const gpgpu_sim_config& config=dev->get_gpgpu()->get_config(); + switch(limit) { + case 0: // cudaLimitStackSize + *pValue=config.stack_limit(); + break; + case 2: // cudaLimitMallocHeapSize + *pValue=config.heap_limit(); + break; +#if (CUDART_VERSION > 5050) + case 3: // cudaLimitDevRuntimeSyncDepth + if(prop->major > 2){ + *pValue=config.sync_depth_limit(); + break; + } + else{ + printf("ERROR:Limit %s is not supported on this architecture \n",limit); + abort(); + } + case 4: // cudaLimitDevRuntimePendingLaunchCount + if(prop->major > 2){ + *pValue=config.pending_launch_count_limit(); + break; + } + else{ + printf("ERROR:Limit %s is not supported on this architecture \n",limit); + abort(); + } +#endif + default: + printf("ERROR:Limit %s unimplemented \n",limit); + abort(); + } + return g_last_cudaError = cudaSuccess; + +} + void** cudaRegisterFatBinaryInternal( void *fatCubin, gpgpu_context* gpgpu_ctx = NULL) { @@ -739,6 +789,260 @@ cudaError_t cudaConfigureCallInternal(dim3 gridDim, dim3 blockDim, size_t shared return g_last_cudaError = cudaSuccess; } +__host__ cudaError_t CUDARTAPI cudaGetDeviceCountInternal(int *count, gpgpu_context* gpgpu_ctx = NULL) +{ + gpgpu_context *ctx; + if (gpgpu_ctx){ + ctx = gpgpu_ctx; + } else { + ctx = GPGPU_Context(); + } + if(g_debug_execution >= 3){ + announce_call(__my_func__); + } + _cuda_device_id *dev = ctx->GPGPUSim_Init(); + *count = dev->num_devices(); + return g_last_cudaError = cudaSuccess; +} + +__host__ cudaError_t CUDARTAPI cudaGetDevicePropertiesInternal(struct cudaDeviceProp *prop, int device, gpgpu_context* gpgpu_ctx = NULL) +{ + gpgpu_context *ctx; + if (gpgpu_ctx){ + ctx = gpgpu_ctx; + } else { + ctx = GPGPU_Context(); + } + if(g_debug_execution >= 3){ + announce_call(__my_func__); + } + _cuda_device_id *dev = ctx->GPGPUSim_Init(); + if (device <= dev->num_devices() ) { + *prop= *dev->get_prop(); + return g_last_cudaError = cudaSuccess; + } else { + return g_last_cudaError = cudaErrorInvalidDevice; + } +} + +#if (CUDART_VERSION > 5000) +__host__ cudaError_t CUDARTAPI cudaDeviceGetAttributeInternal(int *value, enum cudaDeviceAttr attr, int device, gpgpu_context* gpgpu_ctx = NULL) +{ + gpgpu_context *ctx; + if (gpgpu_ctx){ + ctx = gpgpu_ctx; + } else { + ctx = GPGPU_Context(); + } + if(g_debug_execution >= 3){ + announce_call(__my_func__); + } + const struct cudaDeviceProp *prop; + _cuda_device_id *dev = ctx->GPGPUSim_Init(); + if (device <= dev->num_devices() ) { + prop = dev->get_prop(); + switch (attr) { + case 1: + *value= prop->maxThreadsDim[0] * prop->maxThreadsDim[1] * prop->maxThreadsDim[2] * prop->maxGridSize[0] * prop->maxGridSize[1] * prop->maxGridSize[2]; + break; + case 2: + *value= prop->maxThreadsDim[0]; + break; + case 3: + *value= prop->maxThreadsDim[1]; + break; + case 4: + *value= prop->maxThreadsDim[2]; + break; + case 5: + *value= prop->maxGridSize[0]; + break; + case 6: + *value= prop->maxGridSize[1]; + break; + case 7: + *value= prop->maxGridSize[2]; + break; + case 8: + *value= prop->sharedMemPerBlock; + break; + case 9: + *value= prop->totalConstMem; + break; + case 10: + *value= prop->warpSize; + break; + case 11: + *value= 16;//dummy value + break; + case 12: + *value= prop->regsPerBlock; + break; + case 13: + *value= 1480000;//for 1080ti + break; + case 14: + *value= prop->textureAlignment ; + break; + case 15: + *value = 0; + break; + case 16: + *value= prop->multiProcessorCount ; + break; + case 17: + case 18: + case 19: + *value = 0; + break; + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 42: + case 45: + case 46: + case 47: + case 48: + case 49: + case 52: + case 53: + case 55: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 62: + case 63: + case 64: + case 66: + case 67: + case 69: + case 70: + case 71: + case 73: + case 74: + case 77: + *value = 1000;//dummy value + break; + case 29: + case 43: + case 54: + case 65: + case 68: + case 72: + *value = 10;//dummy value + break; + case 30: + case 51: + *value = 128;//dummy value + break; + case 31: + *value = 1; + break; + case 32: + *value = 0; + break; + case 33: + case 50: + *value = 0;//dummy value + break; + case 34: + *value= 0; + break; + case 35: + *value = 0; + break; + case 36: + *value = 1250000;//CK value for 1080ti + break; + case 37: + *value = 352;//value for 1080ti + break; + case 38: + *value = 3000000;//value for 1080ti + break; + case 39: + *value= dev->get_gpgpu()->threads_per_core(); + break; + case 40: + *value= 0; + break; + case 41: + *value= 0; + break; + case 75://cudaDevAttrComputeCapabilityMajor + *value= prop->major ; + break; + case 76://cudaDevAttrComputeCapabilityMinor + *value= prop->minor ; + break; + case 78: + *value= 0 ; //TODO: as of now, we dont support stream priorities. + break; + case 79: + *value= 0; + break; + case 80: + *value= 0; + break; + #if (CUDART_VERSION > 5050) + case 81: + *value= prop->sharedMemPerMultiprocessor; + break; + case 82: + *value= prop->regsPerMultiprocessor; + break; + #endif + case 83: + case 84: + case 85: + case 86: + *value= 0; + break; + case 87: + *value= 4;//dummy value + break; + case 88: + case 89: + case 90: + case 91: + case 95: + *value= 0; + break; + default: + printf("ERROR: Attribute number %d unimplemented \n",attr); + abort(); + } + return g_last_cudaError = cudaSuccess; + } else { + return g_last_cudaError = cudaErrorInvalidDevice; + } +} +#endif + +__host__ cudaError_t CUDARTAPI cudaChooseDeviceInternal(int *device, const struct cudaDeviceProp *prop, gpgpu_context* gpgpu_ctx = NULL) +{ + gpgpu_context *ctx; + if (gpgpu_ctx){ + ctx = gpgpu_ctx; + } else { + ctx = GPGPU_Context(); + } + if(g_debug_execution >= 3){ + announce_call(__my_func__); + } + _cuda_device_id *dev = ctx->GPGPUSim_Init(); + *device = dev->get_id(); + return g_last_cudaError = cudaSuccess; +} + cudaError_t cudaSetupArgumentInternal(const void *arg, size_t size, size_t offset, gpgpu_context* gpgpu_ctx = NULL) { gpgpu_context *ctx; @@ -1058,6 +1362,52 @@ cudaError_t cudaHostAllocInternal(void **pHost, size_t bytes, unsigned int flag #endif +size_t getMaxThreadsPerBlock(struct cudaFuncAttributes *attr, gpgpu_context *ctx) { + _cuda_device_id *dev = ctx->GPGPUSim_Init(); + struct cudaDeviceProp prop; + + prop = *dev->get_prop(); + + size_t max = prop.maxThreadsPerBlock; + + if ((prop.regsPerBlock / attr->numRegs) < max) + max = prop.regsPerBlock / attr->numRegs; + + return max; +} + +cudaError_t CUDARTAPI cudaFuncGetAttributesInternal(struct cudaFuncAttributes *attr, const char *hostFun, gpgpu_context* gpgpu_ctx = NULL ) +{ + gpgpu_context *ctx; + if (gpgpu_ctx){ + ctx = gpgpu_ctx; + } else { + ctx = GPGPU_Context(); + } + if(g_debug_execution >= 3){ + announce_call(__my_func__); + } + CUctx_st *context = GPGPUSim_Context(); + function_info *entry = context->get_kernel(hostFun); + if( entry ) { + const struct gpgpu_ptx_sim_info *kinfo = entry->get_kernel_info(); + attr->sharedSizeBytes = kinfo->smem; + attr->constSizeBytes = kinfo->cmem; + attr->localSizeBytes = kinfo->lmem; + attr->numRegs = kinfo->regs; + if(kinfo->maxthreads > 0) + attr->maxThreadsPerBlock = kinfo->maxthreads; + else + attr->maxThreadsPerBlock = getMaxThreadsPerBlock(attr, ctx); +#if CUDART_VERSION >= 3000 + attr->ptxVersion = kinfo->ptx_version; + attr->binaryVersion = kinfo->sm_target; +#endif + } + return g_last_cudaError = cudaSuccess; +} + + /******************************************************************************* * * * * @@ -1503,235 +1853,24 @@ __host__ cudaError_t CUDARTAPI cudaGetSymbolSize(size_t *size, const char *symbo *******************************************************************************/ __host__ cudaError_t CUDARTAPI cudaGetDeviceCount(int *count) { - if(g_debug_execution >= 3){ - announce_call(__my_func__); - } - _cuda_device_id *dev = GPGPUSim_Init(); - *count = dev->num_devices(); - return g_last_cudaError = cudaSuccess; + return cudaGetDeviceCountInternal(count); } - -__host__ cudaError_t CUDARTAPI cudaGetDeviceProperties(struct cudaDeviceProp *prop, int device) -{ - if(g_debug_execution >= 3){ - announce_call(__my_func__); - } - _cuda_device_id *dev = GPGPUSim_Init(); - if (device <= dev->num_devices() ) { - *prop= *dev->get_prop(); - return g_last_cudaError = cudaSuccess; - } else { - return g_last_cudaError = cudaErrorInvalidDevice; - } + +__host__ cudaError_t CUDARTAPI cudaGetDeviceProperties(struct cudaDeviceProp *prop, int device) +{ + return cudaGetDevicePropertiesInternal(prop, device); } #if (CUDART_VERSION > 5000) __host__ cudaError_t CUDARTAPI cudaDeviceGetAttribute(int *value, enum cudaDeviceAttr attr, int device) { - if(g_debug_execution >= 3){ - announce_call(__my_func__); - } - const struct cudaDeviceProp *prop; - _cuda_device_id *dev = GPGPUSim_Init(); - if (device <= dev->num_devices() ) { - prop = dev->get_prop(); - switch (attr) { - case 1: - *value= prop->maxThreadsDim[0] * prop->maxThreadsDim[1] * prop->maxThreadsDim[2] * prop->maxGridSize[0] * prop->maxGridSize[1] * prop->maxGridSize[2]; - break; - case 2: - *value= prop->maxThreadsDim[0]; - break; - case 3: - *value= prop->maxThreadsDim[1]; - break; - case 4: - *value= prop->maxThreadsDim[2]; - break; - case 5: - *value= prop->maxGridSize[0]; - break; - case 6: - *value= prop->maxGridSize[1]; - break; - case 7: - *value= prop->maxGridSize[2]; - break; - case 8: - *value= prop->sharedMemPerBlock; - break; - case 9: - *value= prop->totalConstMem; - break; - case 10: - *value= prop->warpSize; - break; - case 11: - *value= 16;//dummy value - break; - case 12: - *value= prop->regsPerBlock; - break; - case 13: - *value= 1480000;//for 1080ti - break; - case 14: - *value= prop->textureAlignment ; - break; - case 15: - *value = 0; - break; - case 16: - *value= prop->multiProcessorCount ; - break; - case 17: - case 18: - case 19: - *value = 0; - break; - case 21: - case 22: - case 23: - case 24: - case 25: - case 26: - case 27: - case 28: - case 42: - case 45: - case 46: - case 47: - case 48: - case 49: - case 52: - case 53: - case 55: - case 56: - case 57: - case 58: - case 59: - case 60: - case 61: - case 62: - case 63: - case 64: - case 66: - case 67: - case 69: - case 70: - case 71: - case 73: - case 74: - case 77: - *value = 1000;//dummy value - break; - case 29: - case 43: - case 54: - case 65: - case 68: - case 72: - *value = 10;//dummy value - break; - case 30: - case 51: - *value = 128;//dummy value - break; - case 31: - *value = 1; - break; - case 32: - *value = 0; - break; - case 33: - case 50: - *value = 0;//dummy value - break; - case 34: - *value= 0; - break; - case 35: - *value = 0; - break; - case 36: - *value = 1250000;//CK value for 1080ti - break; - case 37: - *value = 352;//value for 1080ti - break; - case 38: - *value = 3000000;//value for 1080ti - break; - case 39: - *value= dev->get_gpgpu()->threads_per_core(); - break; - case 40: - *value= 0; - break; - case 41: - *value= 0; - break; - case 75://cudaDevAttrComputeCapabilityMajor - *value= prop->major ; - break; - case 76://cudaDevAttrComputeCapabilityMinor - *value= prop->minor ; - break; - case 78: - *value= 0 ; //TODO: as of now, we dont support stream priorities. - break; - case 79: - *value= 0; - break; - case 80: - *value= 0; - break; - #if (CUDART_VERSION > 5050) - case 81: - *value= prop->sharedMemPerMultiprocessor; - break; - case 82: - *value= prop->regsPerMultiprocessor; - break; - #endif - case 83: - case 84: - case 85: - case 86: - *value= 0; - break; - case 87: - *value= 4;//dummy value - break; - case 88: - case 89: - case 90: - case 91: - case 92: - case 93: - case 94: - case 95: - *value= 0; - break; - default: - printf("ERROR: Attribute number %d unimplemented \n",attr); - abort(); - } - return g_last_cudaError = cudaSuccess; - } else { - return g_last_cudaError = cudaErrorInvalidDevice; - } + return cudaDeviceGetAttributeInternal(value, attr, device); } #endif __host__ cudaError_t CUDARTAPI cudaChooseDevice(int *device, const struct cudaDeviceProp *prop) { - if(g_debug_execution >= 3){ - announce_call(__my_func__); - } - _cuda_device_id *dev = GPGPUSim_Init(); - *device = dev->get_id(); - return g_last_cudaError = cudaSuccess; + return cudaChooseDeviceInternal(device, prop); } __host__ cudaError_t CUDARTAPI cudaSetDevice(int device) @@ -1744,47 +1883,9 @@ __host__ cudaError_t CUDARTAPI cudaGetDevice(int *device) return cudaGetDeviceInternal(device); } -__host__ cudaError_t CUDARTAPI cudaDeviceGetLimit ( size_t* pValue, cudaLimit limit ) +__host__ cudaError_t CUDARTAPI cudaDeviceGetLimit( size_t* pValue, cudaLimit limit ) { - if(g_debug_execution >= 3){ - announce_call(__my_func__); - } - _cuda_device_id *dev = GPGPUSim_Init(); - const struct cudaDeviceProp *prop = dev->get_prop(); - const gpgpu_sim_config& config=dev->get_gpgpu()->get_config(); - switch(limit) { - case 0: // cudaLimitStackSize - *pValue=config.stack_limit(); - break; - case 2: // cudaLimitMallocHeapSize - *pValue=config.heap_limit(); - break; -#if (CUDART_VERSION > 5050) - case 3: // cudaLimitDevRuntimeSyncDepth - if(prop->major > 2){ - *pValue=config.sync_depth_limit(); - break; - } - else{ - printf("ERROR:Limit %s is not supported on this architecture \n",limit); - abort(); - } - case 4: // cudaLimitDevRuntimePendingLaunchCount - if(prop->major > 2){ - *pValue=config.pending_launch_count_limit(); - break; - } - else{ - printf("ERROR:Limit %s is not supported on this architecture \n",limit); - abort(); - } -#endif - default: - printf("ERROR:Limit %s unimplemented \n",limit); - abort(); - } - return g_last_cudaError = cudaSuccess; - + return cudaDeviceGetLimitInternal( pValue, limit ); } __host__ cudaError_t CUDARTAPI cudaStreamGetPriority ( cudaStream_t hStream, int* priority ) @@ -3167,58 +3268,9 @@ cudaError_t CUDARTAPI cudaSetDeviceFlags( int flags ) } } -size_t getMaxThreadsPerBlock(struct cudaFuncAttributes *attr) { - _cuda_device_id *dev = GPGPUSim_Init(); - struct cudaDeviceProp prop; - - prop = *dev->get_prop(); - - size_t max = prop.maxThreadsPerBlock; - - if ((prop.regsPerBlock / attr->numRegs) < max) - max = prop.regsPerBlock / attr->numRegs; - - return max; -} - cudaError_t CUDARTAPI cudaFuncGetAttributes(struct cudaFuncAttributes *attr, const char *hostFun ) { - if(g_debug_execution >= 3){ - announce_call(__my_func__); - } - CUctx_st *context = GPGPUSim_Context(); - function_info *entry = context->get_kernel(hostFun); - if( entry ) { - const struct gpgpu_ptx_sim_info *kinfo = entry->get_kernel_info(); - attr->sharedSizeBytes = kinfo->smem; - attr->constSizeBytes = kinfo->cmem; - attr->localSizeBytes = kinfo->lmem; - attr->numRegs = kinfo->regs; - if(kinfo->maxthreads > 0) - attr->maxThreadsPerBlock = kinfo->maxthreads; - else - attr->maxThreadsPerBlock = getMaxThreadsPerBlock(attr); -#if CUDART_VERSION >= 3000 - attr->ptxVersion = kinfo->ptx_version; - attr->binaryVersion = kinfo->sm_target; -#endif - } - return g_last_cudaError = cudaSuccess; -} - -cudaError_t CUDARTAPI cudaEventCreateWithFlags(cudaEvent_t *event, int flags) -{ - if(g_debug_execution >= 3){ - announce_call(__my_func__); - } - CUevent_st *e = new CUevent_st(flags==cudaEventBlockingSync); - g_timer_events[e->get_uid()] = e; -#if CUDART_VERSION >= 3000 - *event = e; -#else - *event = e->get_uid(); -#endif - return g_last_cudaError = cudaSuccess; + return cudaFuncGetAttributesInternal(attr, hostFun ); } cudaError_t CUDARTAPI cudaDriverGetVersion(int *driverVersion) diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index fa5d02b..dd8b51d 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -26,6 +26,8 @@ class gpgpu_context { 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*); + class gpgpu_sim *gpgpu_ptx_sim_init_perf(); + struct _cuda_device_id *GPGPUSim_Init(); }; gpgpu_context* GPGPU_Context(); diff --git a/libopencl/opencl_runtime_api.cc b/libopencl/opencl_runtime_api.cc index 50a02fa..e91e2e0 100644 --- a/libopencl/opencl_runtime_api.cc +++ b/libopencl/opencl_runtime_api.cc @@ -648,7 +648,9 @@ class _cl_device_id *GPGPUSim_Init() { static _cl_device_id *the_device = NULL; if( !the_device ) { - gpgpu_sim *the_gpu = gpgpu_ptx_sim_init_perf(); + gpgpu_context *ctx; + ctx = GPGPU_Context(); + gpgpu_sim *the_gpu = ctx->gpgpu_ptx_sim_init_perf(); the_device = new _cl_device_id(the_gpu); } start_sim_thread(2); diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 2872b84..9094ec3 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -48,7 +48,6 @@ void set_ptx_warp_size(const struct core_config * warp_size) g_shader_core_config=warp_size; } -static bool g_debug_ir_generation=false; const char *g_filename; // the program intermediate representation... @@ -70,7 +69,7 @@ const char *decode_token( int type ) return g_ptx_token_decode[type].c_str(); } -void read_parser_environment_variables() +void ptx_recognizer::read_parser_environment_variables() { g_filename = getenv("PTX_SIM_KERNELFILE"); char *dbg_level = getenv("PTX_SIM_DEBUG"); diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index 25c01fe..bc9a872 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -62,6 +62,7 @@ class ptx_recognizer { g_error_detected = 0; g_entry_func_param_index=0; g_func_info = NULL; + g_debug_ir_generation=false; } // global list yyscan_t scanner; @@ -103,6 +104,7 @@ class ptx_recognizer { unsigned g_entry_func_param_index; function_info *g_func_info; operand_info g_return_var; + bool g_debug_ir_generation; // member function list void init_directive_state(); @@ -169,6 +171,7 @@ class ptx_recognizer { void start_inst_group(); void end_inst_group(); bool check_for_duplicates( const char *identifier ); + void read_parser_environment_variables(); }; diff --git a/src/gpgpusim_entrypoint.cc b/src/gpgpusim_entrypoint.cc index b09674a..476a9d4 100644 --- a/src/gpgpusim_entrypoint.cc +++ b/src/gpgpusim_entrypoint.cc @@ -35,6 +35,7 @@ #include "gpgpu-sim/gpu-sim.h" #include "gpgpu-sim/icnt_wrapper.h" #include "stream_manager.h" +#include "../libcuda/gpgpu_context.h" #define MAX(a,b) (((a)>(b))?(a):(b)) @@ -208,12 +209,12 @@ void exit_simulation() extern bool g_cuda_launch_blocking; -gpgpu_sim *gpgpu_ptx_sim_init_perf() +gpgpu_sim *gpgpu_context::gpgpu_ptx_sim_init_perf() { srand(1); print_splash(); read_sim_environment_variables(); - read_parser_environment_variables(); + ptx_parser->read_parser_environment_variables(); option_parser_t opp = option_parser_create(); ptx_reg_options(opp); diff --git a/src/gpgpusim_entrypoint.h b/src/gpgpusim_entrypoint.h index 9ce7fef..a443151 100644 --- a/src/gpgpusim_entrypoint.h +++ b/src/gpgpusim_entrypoint.h @@ -74,7 +74,6 @@ struct GPGPUsim_ctx { }; -class gpgpu_sim *gpgpu_ptx_sim_init_perf(); void start_sim_thread(int api); class gpgpu_sim* g_the_gpu(); -- cgit v1.3 From cb60ae4893086175fee49dc6088d46665a7f088b Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 3 Jul 2019 12:04:22 -0400 Subject: move g_shader_core_config Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_parser.cc | 4 +--- src/cuda-sim/ptx_parser.h | 3 +++ src/gpgpu-sim/gpu-sim.cc | 5 ++--- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 9094ec3..09bc15d 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -42,8 +42,7 @@ extern FILE *ptx_get_in (yyscan_t yyscanner ); extern int ptx_parse(yyscan_t scanner, ptx_recognizer* recognizer); extern int ptx_lex_destroy(yyscan_t scanner); -static const struct core_config *g_shader_core_config; -void set_ptx_warp_size(const struct core_config * warp_size) +void ptx_recognizer::set_ptx_warp_size(const struct core_config * warp_size) { g_shader_core_config=warp_size; } @@ -154,7 +153,6 @@ symbol_table * gpgpu_context::init_parser( const char *ptx_filename ) return ptx_parser->g_global_symbol_table; } -static int g_entry_point; void ptx_recognizer::start_function( int entry_point ) { diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index bc9a872..ec300a1 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -105,6 +105,8 @@ class ptx_recognizer { function_info *g_func_info; operand_info g_return_var; bool g_debug_ir_generation; + int g_entry_point; + const struct core_config *g_shader_core_config; // member function list void init_directive_state(); @@ -172,6 +174,7 @@ class ptx_recognizer { void end_inst_group(); bool check_for_duplicates( const char *identifier ); void read_parser_environment_variables(); + void set_ptx_warp_size(const struct core_config * warp_size); }; diff --git a/src/gpgpu-sim/gpu-sim.cc b/src/gpgpu-sim/gpu-sim.cc index c894278..2ff37d1 100644 --- a/src/gpgpu-sim/gpu-sim.cc +++ b/src/gpgpu-sim/gpu-sim.cc @@ -65,6 +65,7 @@ #include "visualizer.h" #include "stats.h" #include "../cuda-sim/cuda_device_runtime.h" +#include "../../libcuda/gpgpu_context.h" #ifdef GPGPUSIM_POWER_MODEL #include "power_interface.h" @@ -697,15 +698,13 @@ void gpgpu_sim::stop_all_running_kernels(){ } } -void set_ptx_warp_size(const struct core_config * warp_size); - gpgpu_sim::gpgpu_sim( const gpgpu_sim_config &config, gpgpu_context* ctx ) : gpgpu_t(config), m_config(config) { gpgpu_ctx = ctx; m_shader_config = &m_config.m_shader_config; m_memory_config = &m_config.m_memory_config; - set_ptx_warp_size(m_shader_config); + ctx->ptx_parser->set_ptx_warp_size(m_shader_config); ptx_file_line_stats_create_exposed_latency_tracker(m_config.num_shader()); #ifdef GPGPUSIM_POWER_MODEL -- cgit v1.3 From 60c38b0f77378eb111e88f632702d19dc3746cc7 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Wed, 3 Jul 2019 14:54:16 -0400 Subject: Remove g_filename Signed-off-by: Mengchi Zhang --- libcuda/gpgpu_context.h | 5 +++-- src/cuda-sim/ptx.l | 5 ++--- src/cuda-sim/ptx.y | 5 ++--- src/cuda-sim/ptx_loader.h | 5 +++++ src/cuda-sim/ptx_parser.cc | 26 ++++++++++++-------------- src/cuda-sim/ptx_parser.h | 7 +++++-- src/cuda-sim/ptxinfo.l | 4 ++-- src/gpgpu-sim/gpu-sim.h | 1 + 8 files changed, 32 insertions(+), 26 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index 69341be..d819559 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -10,12 +10,13 @@ class gpgpu_context { gpgpu_context() { g_global_allfiles_symbol_table = NULL; api = new cuda_runtime_api(); - ptxinfo = new ptxinfo_data(); - ptx_parser = new ptx_recognizer(); + ptxinfo = new ptxinfo_data(this); + ptx_parser = new ptx_recognizer(this); the_gpgpusim = new GPGPUsim_ctx(this); } // global list symbol_table *g_global_allfiles_symbol_table; + const char *g_filename; // objects pointers for each file cuda_runtime_api* api; ptxinfo_data* ptxinfo; diff --git a/src/cuda-sim/ptx.l b/src/cuda-sim/ptx.l index 18952a9..3a2a839 100644 --- a/src/cuda-sim/ptx.l +++ b/src/cuda-sim/ptx.l @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ptx_parser.h" #include "ptx.tab.h" #include +#include "../../libcuda/gpgpu_context.h" #define LINEBUF_SIZE (4*1024) #define TC recognizer->col+=strlen(yytext); @@ -452,8 +453,6 @@ breakaddr TC; yylval->int_value = BREAKADDR_OP; return OPCODE; . TC; ptx_error(yyscanner, recognizer, (const char*)NULL); %% -extern const char *g_filename; - int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; @@ -461,7 +460,7 @@ int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ) recognizer->g_error_detected = 1; fflush(stdout); if( s != NULL ) - printf("%s:%u Syntax error:\n\n", g_filename, yylineno ); + printf("%s:%u Syntax error:\n\n", recognizer->gpgpu_ctx->g_filename, yylineno ); printf(" %s\n", recognizer->linebuf ); printf(" "); for( i=0; i < recognizer->col-1; i++ ) { diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y index 837fbe9..a01c3c6 100644 --- a/src/cuda-sim/ptx.y +++ b/src/cuda-sim/ptx.y @@ -30,6 +30,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %{ typedef void * yyscan_t; class ptx_recognizer; +#include "../../libcuda/gpgpu_context.h" %} %define api.pure full @@ -628,11 +629,9 @@ address_expression: IDENTIFIER { recognizer->add_address_operand($1,0); } %% -extern const char *g_filename; - void syntax_not_implemented(yyscan_t yyscanner, ptx_recognizer* recognizer) { - printf("Parse error (%s): this syntax is not (yet) implemented:\n",g_filename); + printf("Parse error (%s): this syntax is not (yet) implemented:\n", recognizer->gpgpu_ctx->g_filename); ptx_error(yyscanner, recognizer, NULL); abort(); } diff --git a/src/cuda-sim/ptx_loader.h b/src/cuda-sim/ptx_loader.h index 77f27c8..c214b95 100644 --- a/src/cuda-sim/ptx_loader.h +++ b/src/cuda-sim/ptx_loader.h @@ -30,13 +30,18 @@ #include #define PTXINFO_LINEBUF_SIZE 1024 +class gpgpu_context; typedef void * yyscan_t; class ptxinfo_data{ public: + ptxinfo_data(gpgpu_context* ctx) { + gpgpu_ctx = ctx; + } yyscan_t scanner; char linebuf[PTXINFO_LINEBUF_SIZE]; unsigned col; const char *g_ptxinfo_filename; + class gpgpu_context* gpgpu_ctx; void ptxinfo_addinfo(); }; diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 09bc15d..05fc618 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -47,14 +47,12 @@ void ptx_recognizer::set_ptx_warp_size(const struct core_config * warp_size) g_shader_core_config=warp_size; } -const char *g_filename; - // the program intermediate representation... std::map g_sym_name_to_symbol_table; #define PTX_PARSE_DPRINTF(...) \ if( g_debug_ir_generation ) { \ - printf(" %s:%u => ",g_filename,ptx_get_lineno(scanner)); \ + printf(" %s:%u => ",gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); \ printf(" (%s:%u) ", __FILE__, __LINE__); \ printf(__VA_ARGS__); \ printf("\n"); \ @@ -70,7 +68,7 @@ const char *decode_token( int type ) void ptx_recognizer::read_parser_environment_variables() { - g_filename = getenv("PTX_SIM_KERNELFILE"); + gpgpu_ctx->g_filename = getenv("PTX_SIM_KERNELFILE"); char *dbg_level = getenv("PTX_SIM_DEBUG"); if ( dbg_level && strlen(dbg_level) ) { int debug_execution=0; @@ -180,7 +178,7 @@ void ptx_recognizer::add_function_name( const char *name ) if( prior_decl ) { g_func_info->remove_args(); } - g_global_symbol_table->add_function( g_func_info, g_filename, ptx_get_lineno(scanner) ); + g_global_symbol_table->add_function( g_func_info, gpgpu_ctx->g_filename, ptx_get_lineno(scanner) ); } //Jin: handle instruction group for cdp @@ -229,7 +227,7 @@ void ptx_recognizer::parse_error_impl( const char *file, unsigned line, const ch va_end(ap); g_error_detected = 1; - printf("%s:%u: Parse error: %s (%s:%u)\n\n", g_filename, ptx_get_lineno(scanner), buf, file, line); + printf("%s:%u: Parse error: %s (%s:%u)\n\n", gpgpu_ctx->g_filename, ptx_get_lineno(scanner), buf, file, line); ptx_error(scanner, NULL); abort(); exit(1); @@ -284,12 +282,12 @@ void ptx_recognizer::add_instruction() g_wmma_options, g_scalar_type, g_space_spec, - g_filename, + gpgpu_ctx->g_filename, ptx_get_lineno(scanner), linebuf, g_shader_core_config ); g_instructions.push_back(i); - g_inst_lookup[g_filename][ptx_get_lineno(scanner)] = i; + g_inst_lookup[gpgpu_ctx->g_filename][ptx_get_lineno(scanner)] = i; init_instruction_state(); } @@ -391,7 +389,7 @@ void ptx_recognizer::add_identifier( const char *identifier, int array_dim, unsi default: break; } - g_last_symbol = g_current_symbol_table->add_variable(identifier,type,num_bits/8,g_filename,ptx_get_lineno(scanner)); + g_last_symbol = g_current_symbol_table->add_variable(identifier,type,num_bits/8,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); switch ( ti.get_memory_space().get_type() ) { case reg_space: { regnum = g_current_symbol_table->next_reg_num(); @@ -654,7 +652,7 @@ void ptx_recognizer::add_label( const char *identifier ) if ( s != NULL ) { g_label = s; } else { - g_label = g_current_symbol_table->add_variable(identifier,NULL,0,g_filename,ptx_get_lineno(scanner)); + g_label = g_current_symbol_table->add_variable(identifier,NULL,0,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); } } @@ -912,7 +910,7 @@ void ptx_recognizer::add_scalar_operand( const char *identifier ) if ( s == NULL ) { if ( g_opcode == BRA_OP || g_opcode == CALLP_OP) { // forward branch target... - s = g_current_symbol_table->add_variable(identifier,NULL,0,g_filename,ptx_get_lineno(scanner)); + s = g_current_symbol_table->add_variable(identifier,NULL,0,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); } else { std::string msg = std::string("operand \"") + identifier + "\" has no declaration."; parse_error( msg.c_str() ); @@ -926,7 +924,7 @@ void ptx_recognizer::add_neg_pred_operand( const char *identifier ) PTX_PARSE_DPRINTF("add_neg_pred_operand"); const symbol *s = g_current_symbol_table->lookup(identifier); if ( s == NULL ) { - s = g_current_symbol_table->add_variable(identifier,NULL,1,g_filename,ptx_get_lineno(scanner)); + s = g_current_symbol_table->add_variable(identifier,NULL,1,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); } operand_info op(s); op.set_neg_pred(); @@ -962,7 +960,7 @@ void ptx_recognizer::add_version_info( float ver, unsigned ext ) void ptx_recognizer::add_file( unsigned num, const char *filename ) { - if( g_filename == NULL ) { + if( gpgpu_ctx->g_filename == NULL ) { char *b = strdup(filename); char *l=b; char *n=b; @@ -978,7 +976,7 @@ void ptx_recognizer::add_file( unsigned num, const char *filename ) char *q = strtok(NULL,"."); if( q && !strcmp(q,"cu") ) { - g_filename = strdup(buf); + gpgpu_ctx->g_filename = strdup(buf); } free( b ); diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index ec300a1..e09aab1 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -30,17 +30,17 @@ #include "../abstract_hardware_model.h" #include "ptx_ir.h" -extern const char *g_filename; extern int g_error_detected; #ifdef __cplusplus const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); #endif +class gpgpu_context; typedef void * yyscan_t; class ptx_recognizer { public: - ptx_recognizer() { + ptx_recognizer( gpgpu_context* ctx ) { scanner = NULL; g_size = -1; g_add_identifier_cached__identifier = NULL; @@ -63,6 +63,7 @@ class ptx_recognizer { g_entry_func_param_index=0; g_func_info = NULL; g_debug_ir_generation=false; + gpgpu_ctx = ctx; } // global list yyscan_t scanner; @@ -107,6 +108,8 @@ class ptx_recognizer { bool g_debug_ir_generation; int g_entry_point; const struct core_config *g_shader_core_config; + // backward pointer + class gpgpu_context* gpgpu_ctx; // member function list void init_directive_state(); diff --git a/src/cuda-sim/ptxinfo.l b/src/cuda-sim/ptxinfo.l index b0ada09..3a152b0 100644 --- a/src/cuda-sim/ptxinfo.l +++ b/src/cuda-sim/ptxinfo.l @@ -39,6 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "ptx_loader.h" #include "ptxinfo.tab.h" #include +#include "../../libcuda/gpgpu_context.h" #define LINEBUF_SIZE 1024 #define TC if( (yylineno == 1) && (ptxinfo->col + strlen(yytext) < LINEBUF_SIZE) ) { \ @@ -88,7 +89,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. %% extern int g_ptxinfo_error_detected; -extern const char *g_filename; int ptxinfo_error(yyscan_t yyscanner, ptxinfo_data* ptxinfo, const char* msg) { @@ -98,7 +98,7 @@ int ptxinfo_error(yyscan_t yyscanner, ptxinfo_data* ptxinfo, const char* msg) fflush(stdout); 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, ptxinfo->g_ptxinfo_filename, yylineno ); + printf("GPGPU-Sim: %s (%s:%u) Syntax error:\n\n", ptxinfo->gpgpu_ctx->g_filename, ptxinfo->g_ptxinfo_filename, yylineno ); printf(" %s\n", ptxinfo->linebuf ); printf(" "); for( i=0; i < ptxinfo->col-1; i++ ) { diff --git a/src/gpgpu-sim/gpu-sim.h b/src/gpgpu-sim/gpu-sim.h index b1d2e45..e2c913a 100644 --- a/src/gpgpu-sim/gpu-sim.h +++ b/src/gpgpu-sim/gpu-sim.h @@ -506,6 +506,7 @@ private: void gpgpu_debug(); ///// data ///// +// backward pointer class gpgpu_context* gpgpu_ctx; class simt_core_cluster **m_cluster; -- cgit v1.3 From 5b015d4347c4945de5a6a7b0559e67e3824d76d6 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Tue, 9 Jul 2019 10:27:35 -0400 Subject: Move some more vars Signed-off-by: Mengchi Zhang --- src/cuda-sim/cuda-sim.cc | 5 +---- src/cuda-sim/cuda-sim.h | 1 + src/cuda-sim/ptx_parser.h | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index c299b4f..e86395d 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -64,7 +64,6 @@ addr_t g_debug_pc = 0xBEEF1518; unsigned gpgpu_param_num_shaders = 0; -char *cdp_latency_str; unsigned cdp_latency[5]; void cuda_sim::ptx_opcocde_latency_options (option_parser_t opp) { @@ -689,7 +688,7 @@ void ptx_instruction::set_opcode_and_latency() &sfu_init); sscanf(gpgpu_ctx->func_sim->opcode_initiation_tensor, "%u", &tensor_init); - sscanf(cdp_latency_str, "%u,%u,%u,%u,%u", + sscanf(gpgpu_ctx->func_sim->cdp_latency_str, "%u,%u,%u,%u,%u", &cdp_latency[0],&cdp_latency[1],&cdp_latency[2], &cdp_latency[3],&cdp_latency[4]); @@ -2101,8 +2100,6 @@ void read_sim_environment_variables() } } -ptx_cta_info *g_func_cta_info = NULL; - #define MAX(a,b) (((a)>(b))?(a):(b)) unsigned max_cta (const struct gpgpu_ptx_sim_info *kernel_info, unsigned threads_per_cta, unsigned int warp_size, unsigned int n_thread_per_shader, unsigned int gpgpu_shmem_size, unsigned int gpgpu_shader_registers, unsigned int max_cta_per_core) diff --git a/src/cuda-sim/cuda-sim.h b/src/cuda-sim/cuda-sim.h index adb4448..16ee46e 100644 --- a/src/cuda-sim/cuda-sim.h +++ b/src/cuda-sim/cuda-sim.h @@ -150,6 +150,7 @@ class cuda_sim { int cp_cta_resume; int g_ptxinfo_error_detected; unsigned g_ptx_sim_num_insn; + char *cdp_latency_str; //global functions void ptx_opcocde_latency_options (option_parser_t opp); void gpgpu_cuda_ptx_sim_main_func( kernel_info_t &kernel, bool openCL = false ); diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index e09aab1..ef422e5 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -30,7 +30,6 @@ #include "../abstract_hardware_model.h" #include "ptx_ir.h" -extern int g_error_detected; #ifdef __cplusplus const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); -- cgit v1.3 From e6f475eaa9c27cd601033c37321466010299dabf Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Thu, 11 Jul 2019 01:47:04 -0400 Subject: Move g_inst_lookup Signed-off-by: Mengchi Zhang --- src/cuda-sim/ptx_loader.cc | 2 +- src/cuda-sim/ptx_parser.cc | 3 +-- src/cuda-sim/ptx_parser.h | 6 ++---- 3 files changed, 4 insertions(+), 7 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc index 2bf464c..891828a 100644 --- a/src/cuda-sim/ptx_loader.cc +++ b/src/cuda-sim/ptx_loader.cc @@ -90,7 +90,7 @@ void gpgpu_context::print_ptx_file( const char *p, unsigned source_num, const ch while ( (*u != '\n') && (*u != '\0') ) u++; unsigned last = (*u == '\0'); *u = '\0'; - const ptx_instruction *pI = ptx_instruction_lookup(filename,n); + const ptx_instruction *pI = ptx_parser->ptx_instruction_lookup(filename,n); char pc[64]; if( pI && pI->get_PC() ) snprintf(pc,64,"%4u", pI->get_PC() ); diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 5a94679..8b2b72e 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -254,9 +254,8 @@ void ptx_recognizer::set_return() g_return_var = g_operands.front(); } -std::map > g_inst_lookup; -const ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ) +const ptx_instruction *ptx_recognizer::ptx_instruction_lookup( const char *filename, unsigned linenumber ) { std::map >::iterator f=g_inst_lookup.find(filename); if( f == g_inst_lookup.end() ) diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index ef422e5..7e87ec8 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -31,10 +31,6 @@ #include "../abstract_hardware_model.h" #include "ptx_ir.h" -#ifdef __cplusplus -const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); -#endif - class gpgpu_context; typedef void * yyscan_t; class ptx_recognizer { @@ -107,6 +103,7 @@ class ptx_recognizer { bool g_debug_ir_generation; int g_entry_point; const struct core_config *g_shader_core_config; + std::map > g_inst_lookup; // backward pointer class gpgpu_context* gpgpu_ctx; @@ -177,6 +174,7 @@ class ptx_recognizer { bool check_for_duplicates( const char *identifier ); void read_parser_environment_variables(); void set_ptx_warp_size(const struct core_config * warp_size); + const class ptx_instruction *ptx_instruction_lookup( const char *filename, unsigned linenumber ); }; -- cgit v1.3 From 33d064f5a38b60fb0ed4b4ad78212c6e5d9bfc0f Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Thu, 11 Jul 2019 13:57:08 -0400 Subject: g_sym_name_to_symbol_table Signed-off-by: Mengchi Zhang --- src/cuda-sim/cuda-sim.cc | 4 ++-- src/cuda-sim/ptx_parser.cc | 2 -- src/cuda-sim/ptx_parser.h | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc index d098f2b..e4ff0f9 100644 --- a/src/cuda-sim/cuda-sim.cc +++ b/src/cuda-sim/cuda-sim.cc @@ -1995,8 +1995,8 @@ void cuda_sim::gpgpu_ptx_sim_memcpy_symbol(const char *hostVar, const void *src, const char *mem_name = NULL; memory_space *mem = NULL; - std::map::iterator st = g_sym_name_to_symbol_table.find(sym_name.c_str()); - assert( st != g_sym_name_to_symbol_table.end() ); + std::map::iterator st = gpgpu_ctx->ptx_parser->g_sym_name_to_symbol_table.find(sym_name.c_str()); + assert( st != gpgpu_ctx->ptx_parser->g_sym_name_to_symbol_table.end() ); symbol_table *symtab = st->second; symbol *sym = symtab->lookup(sym_name.c_str()); diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 8b2b72e..1d38edf 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -47,8 +47,6 @@ void ptx_recognizer::set_ptx_warp_size(const struct core_config * warp_size) g_shader_core_config=warp_size; } -// the program intermediate representation... -std::map g_sym_name_to_symbol_table; #define PTX_PARSE_DPRINTF(...) \ if( g_debug_ir_generation ) { \ diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index 7e87ec8..1e559a2 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -104,6 +104,8 @@ class ptx_recognizer { int g_entry_point; const struct core_config *g_shader_core_config; std::map > g_inst_lookup; + // the program intermediate representation... + std::map g_sym_name_to_symbol_table; // backward pointer class gpgpu_context* gpgpu_ctx; -- cgit v1.3 From 67950eb12eec495b1976934acc763db481d955f8 Mon Sep 17 00:00:00 2001 From: Mengchi Zhang Date: Mon, 15 Jul 2019 11:58:10 -0400 Subject: Move operand_info::sm_next_uid Signed-off-by: Mengchi Zhang --- libcuda/gpgpu_context.h | 2 ++ src/cuda-sim/ptx_ir.cc | 20 ++++++++++------- src/cuda-sim/ptx_ir.h | 54 ++++++++++++++++++++++++---------------------- src/cuda-sim/ptx_parser.cc | 30 +++++++++++++------------- src/cuda-sim/ptx_parser.h | 2 +- src/cuda-sim/ptx_sim.cc | 8 +++---- 6 files changed, 62 insertions(+), 54 deletions(-) (limited to 'src/cuda-sim/ptx_parser.h') diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index 0dd6311..9c5ae7b 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -13,6 +13,7 @@ class gpgpu_context { g_global_allfiles_symbol_table = NULL; sm_next_access_uid=0; warp_inst_sm_next_uid=0; + operand_info_sm_next_uid = 1; api = new cuda_runtime_api(this); ptxinfo = new ptxinfo_data(this); ptx_parser = new ptx_recognizer(this); @@ -25,6 +26,7 @@ class gpgpu_context { const char *g_filename; unsigned sm_next_access_uid; unsigned warp_inst_sm_next_uid; + unsigned operand_info_sm_next_uid;//uid for operand_info // objects pointers for each file cuda_runtime_api* api; ptxinfo_data* ptxinfo; diff --git a/src/cuda-sim/ptx_ir.cc b/src/cuda-sim/ptx_ir.cc index c537091..0fa29eb 100644 --- a/src/cuda-sim/ptx_ir.cc +++ b/src/cuda-sim/ptx_ir.cc @@ -39,6 +39,7 @@ typedef void * yyscan_t; #include "assert.h" #include "cuda-sim.h" +#include "../../libcuda/gpgpu_context.h" #define STR_SIZE 1024 @@ -322,11 +323,9 @@ void symbol_table::dump() printf("\n"); } -unsigned operand_info::sm_next_uid=1; - unsigned operand_info::get_uid() { - unsigned result = sm_next_uid++; + unsigned result = (gpgpu_ctx->operand_info_sm_next_uid)++; return result; } @@ -1015,7 +1014,7 @@ void copy_buffer_to_frame(ptx_thread_info * thread, const arg_buffer_t &a) { if( a.is_reg() ) { ptx_reg_t value = a.get_reg(); - operand_info dst_reg = operand_info(a.get_dst()); + operand_info dst_reg = operand_info(a.get_dst(), thread->get_gpu()->gpgpu_ctx); thread->set_reg(dst_reg.get_symbol(),value); } else { const void *buffer = a.get_param_buffer(); @@ -1039,7 +1038,8 @@ void copy_buffer_list_into_frame(ptx_thread_info * thread, arg_buffer_list_t &ar static std::list check_operands( int opcode, const std::list &scalar_type, - const std::list &operands ) + const std::list &operands, + gpgpu_context* ctx) { static int g_warn_literal_operands_two_type_inst; if( (opcode == CVT_OP) || (opcode == SET_OP) || (opcode == SLCT_OP) || (opcode == TEX_OP) || (opcode==MMA_OP) || (opcode == DP4A_OP)) { @@ -1066,7 +1066,7 @@ static std::list check_operands( int opcode, if( (op.get_type() == double_op_t) && (inst_type == F32_TYPE) ) { ptx_reg_t v = op.get_literal_value(); float u = (float)v.f64; - operand_info n(u); + operand_info n(u, ctx); result.push_back(n); } else { result.push_back(op); @@ -1097,7 +1097,7 @@ ptx_instruction::ptx_instruction( int opcode, unsigned line, const char *source, const core_config *config, - gpgpu_context* ctx ) : warp_inst_t(config) + gpgpu_context* ctx ) : warp_inst_t(config), m_return_var(ctx) { gpgpu_ctx = ctx; m_uid = ++g_num_ptx_inst_uid; @@ -1107,7 +1107,7 @@ ptx_instruction::ptx_instruction( int opcode, m_neg_pred = neg_pred; m_pred_mod = pred_mod; m_label = label; - const std::list checked_operands = check_operands(opcode,scalar_type,operands); + const std::list checked_operands = check_operands(opcode,scalar_type,operands, ctx); m_operands.insert(m_operands.begin(), checked_operands.begin(), checked_operands.end() ); m_return_var = return_var; m_options = options; @@ -1371,6 +1371,10 @@ std::string ptx_instruction::to_string() const m_source.c_str() ); return std::string( buf ); } +operand_info ptx_instruction::get_pred() const +{ + return operand_info( m_pred, gpgpu_ctx); +} unsigned function_info::sm_next_uid = 1; diff --git a/src/cuda-sim/ptx_ir.h b/src/cuda-sim/ptx_ir.h index babd54b..8ed94d9 100644 --- a/src/cuda-sim/ptx_ir.h +++ b/src/cuda-sim/ptx_ir.h @@ -377,9 +377,9 @@ private: class operand_info { public: - operand_info() + operand_info(gpgpu_context* ctx) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -392,9 +392,9 @@ public: m_addr_offset = 0; m_value.m_symbolic=NULL; } - operand_info( const symbol *addr ) + operand_info( const symbol *addr, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -435,9 +435,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( const symbol *addr1, const symbol *addr2 ) + operand_info( const symbol *addr1, const symbol *addr2, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -462,9 +462,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( int builtin_id, int dim_mod ) + operand_info( int builtin_id, int dim_mod, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -481,9 +481,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( const symbol *addr, int offset ) + operand_info( const symbol *addr, int offset, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -500,9 +500,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( unsigned x ) + operand_info( unsigned x, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -519,9 +519,9 @@ public: m_is_return_var = false; m_immediate_address=true; } - operand_info( int x ) + operand_info( int x, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -538,9 +538,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( float x ) + operand_info( float x, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -557,9 +557,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( double x ) + operand_info( double x, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -576,9 +576,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( const symbol *s1, const symbol *s2, const symbol *s3, const symbol *s4 ) + operand_info( const symbol *s1, const symbol *s2, const symbol *s3, const symbol *s4, gpgpu_context* ctx ) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -603,9 +603,9 @@ public: m_is_return_var = false; m_immediate_address=false; } - operand_info( const symbol *s1, const symbol *s2, const symbol *s3, const symbol *s4 ,const symbol *s5,const symbol *s6,const symbol *s7, const symbol *s8) + operand_info( const symbol *s1, const symbol *s2, const symbol *s3, const symbol *s4 ,const symbol *s5,const symbol *s6,const symbol *s7, const symbol *s8, gpgpu_context* ctx) { - init(); + init(ctx); m_is_non_arch_reg = false; m_addr_space = undefined_space; m_operand_lohi = 0; @@ -631,8 +631,9 @@ public: m_immediate_address=false; } - void init() + void init(gpgpu_context* ctx) { + gpgpu_ctx = ctx; m_uid=(unsigned)-1; m_valid=false; m_vector=false; @@ -842,6 +843,7 @@ public: bool is_non_arch_reg() const { return m_is_non_arch_reg; } private: + gpgpu_context* gpgpu_ctx; unsigned m_uid; bool m_valid; bool m_vector; @@ -957,7 +959,7 @@ public: unsigned source_line() const { return m_source_line;} unsigned get_num_operands() const { return m_operands.size();} bool has_pred() const { return m_pred != NULL;} - operand_info get_pred() const { return operand_info( m_pred );} + operand_info get_pred() const; bool get_pred_neg() const { return m_neg_pred;} int get_pred_mod() const { return m_pred_mod;} const char *get_source() const { return m_source.c_str();} @@ -1448,14 +1450,14 @@ private: class arg_buffer_t { public: - arg_buffer_t() + arg_buffer_t(gpgpu_context* ctx) : m_src_op(ctx) { m_is_reg=false; m_is_param=false; m_param_value=NULL; m_reg_value=ptx_reg_t(); } - arg_buffer_t( const arg_buffer_t &another ) + arg_buffer_t( const arg_buffer_t &another, gpgpu_context* ctx ) : m_src_op(ctx) { make_copy(another); } diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 1d38edf..81b70af 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -102,7 +102,7 @@ void ptx_recognizer::init_instruction_state() g_opcode = -1; g_options.clear(); g_wmma_options.clear(); - g_return_var = operand_info(); + g_return_var = operand_info(gpgpu_ctx); init_directive_state(); } @@ -689,7 +689,7 @@ void ptx_recognizer::add_double_operand( const char *d1, const char *d2 ) const symbol *s1 = g_current_symbol_table->lookup(d1); const symbol *s2 = g_current_symbol_table->lookup(d2); parse_assert( s1 != NULL && s2 != NULL, "component(s) missing declarations."); - g_operands.push_back( operand_info(s1,s2) ); + g_operands.push_back( operand_info(s1,s2,gpgpu_ctx) ); } void ptx_recognizer::add_1vector_operand( const char *d1 ) @@ -698,7 +698,7 @@ void ptx_recognizer::add_1vector_operand( const char *d1 ) PTX_PARSE_DPRINTF("add_1vector_operand"); const symbol *s1 = g_current_symbol_table->lookup(d1); parse_assert( s1 != NULL, "component(s) missing declarations."); - g_operands.push_back( operand_info(s1,NULL,NULL,NULL) ); + g_operands.push_back( operand_info(s1,NULL,NULL,NULL,gpgpu_ctx) ); } void ptx_recognizer::add_2vector_operand( const char *d1, const char *d2 ) @@ -707,7 +707,7 @@ void ptx_recognizer::add_2vector_operand( const char *d1, const char *d2 ) const symbol *s1 = g_current_symbol_table->lookup(d1); const symbol *s2 = g_current_symbol_table->lookup(d2); parse_assert( s1 != NULL && s2 != NULL, "v2 component(s) missing declarations."); - g_operands.push_back( operand_info(s1,s2,NULL,NULL) ); + g_operands.push_back( operand_info(s1,s2,NULL,NULL,gpgpu_ctx) ); } void ptx_recognizer::add_3vector_operand( const char *d1, const char *d2, const char *d3 ) @@ -717,7 +717,7 @@ void ptx_recognizer::add_3vector_operand( const char *d1, const char *d2, const const symbol *s2 = g_current_symbol_table->lookup(d2); const symbol *s3 = g_current_symbol_table->lookup(d3); parse_assert( s1 != NULL && s2 != NULL && s3 != NULL, "v3 component(s) missing declarations."); - g_operands.push_back( operand_info(s1,s2,s3,NULL) ); + g_operands.push_back( operand_info(s1,s2,s3,NULL,gpgpu_ctx) ); } void ptx_recognizer::add_4vector_operand( const char *d1, const char *d2, const char *d3, const char *d4 ) @@ -732,7 +732,7 @@ void ptx_recognizer::add_4vector_operand( const char *d1, const char *d2, const if ( s2 == null_op ) s2 = NULL; if ( s3 == null_op ) s3 = NULL; if ( s4 == null_op ) s4 = NULL; - g_operands.push_back( operand_info(s1,s2,s3,s4) ); + g_operands.push_back( operand_info(s1,s2,s3,s4,gpgpu_ctx) ); } void ptx_recognizer::add_8vector_operand( const char *d1, const char *d2, const char *d3, const char *d4,const char *d5,const char *d6,const char *d7,const char *d8 ) { @@ -754,13 +754,13 @@ void ptx_recognizer::add_8vector_operand( const char *d1, const char *d2, const if ( s6 == null_op ) s6 = NULL; if ( s7 == null_op ) s7 = NULL; if ( s8 == null_op ) s8 = NULL; - g_operands.push_back( operand_info(s1,s2,s3,s4,s5,s6,s7,s8) ); + g_operands.push_back( operand_info(s1,s2,s3,s4,s5,s6,s7,s8,gpgpu_ctx) ); } void ptx_recognizer::add_builtin_operand( int builtin, int dim_modifier ) { PTX_PARSE_DPRINTF("add_builtin_operand"); - g_operands.push_back( operand_info(builtin,dim_modifier) ); + g_operands.push_back( operand_info(builtin,dim_modifier,gpgpu_ctx) ); } void ptx_recognizer::add_memory_operand() @@ -883,19 +883,19 @@ void ptx_recognizer::change_operand_neg( ) void ptx_recognizer::add_literal_int( int value ) { PTX_PARSE_DPRINTF("add_literal_int"); - g_operands.push_back( operand_info(value) ); + g_operands.push_back( operand_info(value,gpgpu_ctx) ); } void ptx_recognizer::add_literal_float( float value ) { PTX_PARSE_DPRINTF("add_literal_float"); - g_operands.push_back( operand_info(value) ); + g_operands.push_back( operand_info(value,gpgpu_ctx) ); } void ptx_recognizer::add_literal_double( double value ) { PTX_PARSE_DPRINTF("add_literal_double"); - g_operands.push_back( operand_info(value) ); + g_operands.push_back( operand_info(value,gpgpu_ctx) ); } void ptx_recognizer::add_scalar_operand( const char *identifier ) @@ -911,7 +911,7 @@ void ptx_recognizer::add_scalar_operand( const char *identifier ) parse_error( msg.c_str() ); } } - g_operands.push_back( operand_info(s) ); + g_operands.push_back( operand_info(s,gpgpu_ctx) ); } void ptx_recognizer::add_neg_pred_operand( const char *identifier ) @@ -921,7 +921,7 @@ void ptx_recognizer::add_neg_pred_operand( const char *identifier ) if ( s == NULL ) { s = g_current_symbol_table->add_variable(identifier,NULL,1,gpgpu_ctx->g_filename,ptx_get_lineno(scanner)); } - operand_info op(s); + operand_info op(s, gpgpu_ctx); op.set_neg_pred(); g_operands.push_back( op ); } @@ -934,13 +934,13 @@ void ptx_recognizer::add_address_operand( const char *identifier, int offset ) std::string msg = std::string("operand \"") + identifier + "\" has no declaration."; parse_error( msg.c_str() ); } - g_operands.push_back( operand_info(s,offset) ); + g_operands.push_back( operand_info(s,offset,gpgpu_ctx) ); } void ptx_recognizer::add_address_operand2( int offset ) { PTX_PARSE_DPRINTF("add_address_operand"); - g_operands.push_back( operand_info((unsigned)offset) ); + g_operands.push_back( operand_info((unsigned)offset,gpgpu_ctx) ); } void ptx_recognizer::add_array_initializer() diff --git a/src/cuda-sim/ptx_parser.h b/src/cuda-sim/ptx_parser.h index 1e559a2..11a3d20 100644 --- a/src/cuda-sim/ptx_parser.h +++ b/src/cuda-sim/ptx_parser.h @@ -35,7 +35,7 @@ class gpgpu_context; typedef void * yyscan_t; class ptx_recognizer { public: - ptx_recognizer( gpgpu_context* ctx ) { + ptx_recognizer( gpgpu_context* ctx ) : g_return_var(ctx) { scanner = NULL; g_size = -1; g_add_identifier_cached__identifier = NULL; diff --git a/src/cuda-sim/ptx_sim.cc b/src/cuda-sim/ptx_sim.cc index b6cf4bd..62bb529 100644 --- a/src/cuda-sim/ptx_sim.cc +++ b/src/cuda-sim/ptx_sim.cc @@ -422,9 +422,9 @@ bool ptx_thread_info::callstack_pop() assert( !((rv_src != NULL) ^ (rv_dst != NULL)) ); // ensure caller and callee agree on whether there is a return value // read return value from callee frame - arg_buffer_t buffer; + arg_buffer_t buffer(m_gpu->gpgpu_ctx); if( rv_src != NULL ) - buffer = copy_arg_to_buffer(this, operand_info(rv_src), rv_dst ); + buffer = copy_arg_to_buffer(this, operand_info(rv_src, m_gpu->gpgpu_ctx), rv_dst ); m_symbol_table = m_callstack.back().m_symbol_table; m_NPC = m_callstack.back().m_PC; @@ -456,9 +456,9 @@ bool ptx_thread_info::callstack_pop_plus() assert( !((rv_src != NULL) ^ (rv_dst != NULL)) ); // ensure caller and callee agree on whether there is a return value // read return value from callee frame - arg_buffer_t buffer; + arg_buffer_t buffer(m_gpu->gpgpu_ctx); if( rv_src != NULL ) - buffer = copy_arg_to_buffer(this, operand_info(rv_src), rv_dst ); + buffer = copy_arg_to_buffer(this, operand_info(rv_src, m_gpu->gpgpu_ctx), rv_dst ); m_symbol_table = m_callstack.back().m_symbol_table; m_NPC = m_callstack.back().m_PC; -- cgit v1.3