summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMengchi Zhang <[email protected]>2019-07-03 20:54:01 -0400
committerGitHub <[email protected]>2019-07-03 20:54:01 -0400
commitce63582472e027107783b81be40b2429bd8e8f73 (patch)
tree36ce48f9e23cd20797b765c04b4161b08edf8398 /src
parentc7b8987b313602bf0c3a6edb4830bfba3aa083ae (diff)
parent60c38b0f77378eb111e88f632702d19dc3746cc7 (diff)
Merge pull request #21 from echoedit/dev
Dev
Diffstat (limited to 'src')
-rw-r--r--src/cuda-sim/ptx.l5
-rw-r--r--src/cuda-sim/ptx.y5
-rw-r--r--src/cuda-sim/ptx_loader.h5
-rw-r--r--src/cuda-sim/ptx_parser.cc30
-rw-r--r--src/cuda-sim/ptx_parser.h10
-rw-r--r--src/cuda-sim/ptxinfo.l4
-rw-r--r--src/gpgpu-sim/gpu-sim.cc10
-rw-r--r--src/gpgpu-sim/gpu-sim.h5
-rw-r--r--src/gpgpusim_entrypoint.cc8
-rw-r--r--src/gpgpusim_entrypoint.h10
10 files changed, 51 insertions, 41 deletions
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 <string.h>
+#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;
<INITIAL,NOT_OPCODE,IN_FUNC_DECL>. 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 <string>
#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 9094ec3..05fc618 100644
--- a/src/cuda-sim/ptx_parser.cc
+++ b/src/cuda-sim/ptx_parser.cc
@@ -42,20 +42,17 @@ 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;
}
-const char *g_filename;
-
// the program intermediate representation...
std::map<std::string,symbol_table*> 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"); \
@@ -71,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;
@@ -154,7 +151,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 )
{
@@ -182,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
@@ -231,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);
@@ -286,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();
}
@@ -393,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();
@@ -656,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));
}
}
@@ -914,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() );
@@ -928,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();
@@ -964,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;
@@ -980,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 bc9a872..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;
@@ -105,6 +106,10 @@ 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;
+ // backward pointer
+ class gpgpu_context* gpgpu_ctx;
// member function list
void init_directive_state();
@@ -172,6 +177,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/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 <string.h>
+#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.cc b/src/gpgpu-sim/gpu-sim.cc
index a557d6f..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,14 +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_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
diff --git a/src/gpgpu-sim/gpu-sim.h b/src/gpgpu-sim/gpu-sim.h
index 5ea5765..e2c913a 100644
--- a/src/gpgpu-sim/gpu-sim.h
+++ b/src/gpgpu-sim/gpu-sim.h
@@ -416,10 +416,11 @@ struct occupancy_stats {
}
};
+class gpgpu_context;
class gpgpu_sim : public gpgpu_t {
public:
- gpgpu_sim( const gpgpu_sim_config &config );
+ gpgpu_sim( const gpgpu_sim_config &config, gpgpu_context* ctx );
void set_prop( struct cudaDeviceProp *prop );
@@ -505,6 +506,8 @@ private:
void gpgpu_debug();
///// data /////
+// backward pointer
+ class gpgpu_context* gpgpu_ctx;
class simt_core_cluster **m_cluster;
class memory_partition_unit **m_memory_partition_unit;
diff --git a/src/gpgpusim_entrypoint.cc b/src/gpgpusim_entrypoint.cc
index 476a9d4..b54f20c 100644
--- a/src/gpgpusim_entrypoint.cc
+++ b/src/gpgpusim_entrypoint.cc
@@ -43,11 +43,11 @@ static int sg_argc = 3;
static const char *sg_argv[] = {"", "-config","gpgpusim.config"};
-struct GPGPUsim_ctx* the_gpgpusim = NULL;
+GPGPUsim_ctx* the_gpgpusim = NULL;
-struct GPGPUsim_ctx* GPGPUsim_ctx_ptr(){
+GPGPUsim_ctx* GPGPUsim_ctx_ptr(){
if(the_gpgpusim == NULL)
- the_gpgpusim = new GPGPUsim_ctx();
+ the_gpgpusim = GPGPU_Context()->the_gpgpusim;
return the_gpgpusim;
}
@@ -232,7 +232,7 @@ gpgpu_sim *gpgpu_context::gpgpu_ptx_sim_init_perf()
assert(setlocale(LC_NUMERIC,"C"));
GPGPUsim_ctx_ptr()->g_the_gpu_config->init();
- GPGPUsim_ctx_ptr()->g_the_gpu = new gpgpu_sim(*(GPGPUsim_ctx_ptr()->g_the_gpu_config));
+ GPGPUsim_ctx_ptr()->g_the_gpu = new gpgpu_sim(*(GPGPUsim_ctx_ptr()->g_the_gpu_config), this);
GPGPUsim_ctx_ptr()->g_stream_manager = new stream_manager((GPGPUsim_ctx_ptr()->g_the_gpu),g_cuda_launch_blocking);
GPGPUsim_ctx_ptr()->g_simulation_starttime = time((time_t *)NULL);
diff --git a/src/gpgpusim_entrypoint.h b/src/gpgpusim_entrypoint.h
index a443151..dfb82d0 100644
--- a/src/gpgpusim_entrypoint.h
+++ b/src/gpgpusim_entrypoint.h
@@ -34,11 +34,11 @@
#include <time.h>
//extern time_t g_simulation_starttime;
+class gpgpu_context;
-
-struct GPGPUsim_ctx {
-
- GPGPUsim_ctx() {
+class GPGPUsim_ctx {
+ public:
+ GPGPUsim_ctx(gpgpu_context* ctx) {
g_sim_active = false;
g_sim_done = true;
break_limit = false;
@@ -49,6 +49,7 @@ struct GPGPUsim_ctx {
g_stream_manager=NULL;
the_cude_device=NULL;
the_context=NULL;
+ gpgpu_ctx = ctx;
}
//struct gpgpu_ptx_sim_arg *grid_params;
@@ -65,6 +66,7 @@ struct GPGPUsim_ctx {
struct _cuda_device_id *the_cude_device;
struct CUctx_st* the_context;
+ gpgpu_context* gpgpu_ctx;
pthread_mutex_t g_sim_lock;