diff options
| author | Mahmoud <[email protected]> | 2019-09-04 21:38:57 -0400 |
|---|---|---|
| committer | Mahmoud <[email protected]> | 2019-09-04 21:38:57 -0400 |
| commit | eb3b077cddb24a734bb72f5c1588dee4034214a7 (patch) | |
| tree | 7350591f8d5e3156f6b2c69cc54b7568cc77aa77 | |
| parent | 41da287aced4587c6005725ac4ca9b9809c2e08f (diff) | |
adding trace class and parss kernel info
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | libcuda/gpgpu_context.h | 1 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_ir.h | 10 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_loader.cc | 2 | ||||
| -rw-r--r-- | src/cuda-sim/ptx_parser.cc | 4 | ||||
| -rw-r--r-- | src/gpgpu-sim/gpu-sim.cc | 9 | ||||
| -rw-r--r-- | src/gpgpu-sim/gpu-sim.h | 7 | ||||
| -rw-r--r-- | src/gpgpusim_entrypoint.cc | 32 | ||||
| -rw-r--r-- | src/gpgpusim_entrypoint.h | 2 | ||||
| -rw-r--r-- | src/trace-driven/gpgpusim_trace_driven_main.cc | 263 | ||||
| -rw-r--r-- | src/trace-driven/trace_driven.h | 71 |
11 files changed, 301 insertions, 104 deletions
@@ -144,7 +144,7 @@ no_opencl_support: @echo "Warning: gpgpu-sim is building without opencl support. Make sure NVOPENCL_LIBDIR and NVOPENCL_INCDIR are set" $(SIM_LIB_DIR)/libcudart.so: makedirs $(LIBS) cudalib - g++ -shared -Wl,-soname,libcudart_$(GPGPUSIM_BUILD).so -Wl,--version-script=linux-so-version.txt\ + g++ -shared -Wl,-soname,libcudart.so -Wl,--version-script=linux-so-version.txt\ $(SIM_OBJ_FILES_DIR)/libcuda/*.o \ $(SIM_OBJ_FILES_DIR)/cuda-sim/*.o \ $(SIM_OBJ_FILES_DIR)/cuda-sim/decuda_pred_table/*.o \ @@ -171,7 +171,7 @@ $(SIM_LIB_DIR)/libcudart.so: makedirs $(LIBS) cudalib $(SIM_LIB_DIR)/gpgpusim.out: makedirs $(LIBS) cudalib $(SIM_LIB_DIR)/libcudart.so - g++ -std=c++0x -L$(SIM_LIB_DIR) -lcudart -o $(SIM_LIB_DIR)/gpgpusim.out src/trace-driven/gpgpusim_trace_driven_main.cc + g++ -std=c++0x -L$(SIM_LIB_DIR) -I$(CUDA_INSTALL_PATH)/include -lcudart -o $(SIM_LIB_DIR)/gpgpusim.out src/trace-driven/gpgpusim_trace_driven_main.cc $(SIM_LIB_DIR)/libcudart.dylib: makedirs $(LIBS) cudalib g++ -dynamiclib -Wl,-headerpad_max_install_names,-undefined,dynamic_lookup,-compatibility_version,1.1,-current_version,1.1\ diff --git a/libcuda/gpgpu_context.h b/libcuda/gpgpu_context.h index 45c5cdd..d3c5d74 100644 --- a/libcuda/gpgpu_context.h +++ b/libcuda/gpgpu_context.h @@ -65,6 +65,7 @@ class gpgpu_context { const ptx_instruction* pc_to_instruction(unsigned pc); const warp_inst_t *ptx_fetch_inst( address_type pc ); unsigned translate_pc_to_ptxlineno(unsigned pc); + class gpgpu_sim *gpgpu_trace_sim_init_perf(int argc, const char *argv[]); }; gpgpu_context* GPGPU_Context(); diff --git a/src/cuda-sim/ptx_ir.h b/src/cuda-sim/ptx_ir.h index f4c5c37..8ceb60b 100644 --- a/src/cuda-sim/ptx_ir.h +++ b/src/cuda-sim/ptx_ir.h @@ -1354,13 +1354,13 @@ public: void list_param( FILE *fout ) const; void ptx_jit_config(std::map<unsigned long long, size_t> mallocPtr_Size, memory_space *param_mem, gpgpu_t* gpu, dim3 gridDim, dim3 blockDim) ; - const struct gpgpu_ptx_sim_info* get_kernel_info () const + virtual const struct gpgpu_ptx_sim_info* get_kernel_info () const { assert (m_kernel_info.maxthreads == maxnt_id); return &m_kernel_info; } - const void set_kernel_info (const struct gpgpu_ptx_sim_info &info) { + virtual const void set_kernel_info (const struct gpgpu_ptx_sim_info &info) { m_kernel_info = info; m_kernel_info.ptx_version = 10*get_ptx_version().ver(); m_kernel_info.sm_target = get_ptx_version().target(); @@ -1401,6 +1401,10 @@ public: // backward pointer class gpgpu_context* gpgpu_ctx; +protected: + //Registers/shmem/etc. used (from ptxas -v), loaded from ___.ptxinfo along with ___.ptx + struct gpgpu_ptx_sim_info m_kernel_info; + private: unsigned maxnt_id; unsigned m_uid; @@ -1424,8 +1428,6 @@ private: std::map<std::string,unsigned> labels; unsigned num_reconvergence_pairs; - //Registers/shmem/etc. used (from ptxas -v), loaded from ___.ptxinfo along with ___.ptx - struct gpgpu_ptx_sim_info m_kernel_info; symbol_table *m_symtab; diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc index dca3cec..207fa1f 100644 --- a/src/cuda-sim/ptx_loader.cc +++ b/src/cuda-sim/ptx_loader.cc @@ -37,7 +37,7 @@ /// extern prototypes -extern int ptx_error( yyscan_t yyscanner, const char *s ); +extern int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, const char *s ); extern int ptx_lex_init(yyscan_t* scanner); extern void ptx_set_in(FILE * _in_str ,yyscan_t yyscanner ); extern int ptx_parse(yyscan_t scanner, ptx_recognizer* recognizer); diff --git a/src/cuda-sim/ptx_parser.cc b/src/cuda-sim/ptx_parser.cc index 81b70af..9e9d500 100644 --- a/src/cuda-sim/ptx_parser.cc +++ b/src/cuda-sim/ptx_parser.cc @@ -35,7 +35,7 @@ typedef void * yyscan_t; extern int ptx_get_lineno (yyscan_t yyscanner ); extern YYSTYPE* ptx_get_lval (yyscan_t yyscanner ); -extern int ptx_error( yyscan_t yyscanner, const char *s ); +extern int ptx_error( yyscan_t yyscanner, ptx_recognizer* recognizer, 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 ); @@ -226,7 +226,7 @@ void ptx_recognizer::parse_error_impl( const char *file, unsigned line, const ch g_error_detected = 1; 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); + ptx_error(scanner, this, NULL); abort(); exit(1); } diff --git a/src/gpgpu-sim/gpu-sim.cc b/src/gpgpu-sim/gpu-sim.cc index a151379..234a8d6 100644 --- a/src/gpgpu-sim/gpu-sim.cc +++ b/src/gpgpu-sim/gpu-sim.cc @@ -560,6 +560,15 @@ void gpgpu_sim_config::reg_options(option_parser_t opp) option_parser_register(opp, "-gpgpu_cdp_enabled", OPT_BOOL, &(gpgpu_ctx->device_runtime->g_cdp_enabled), "Turn on CDP", "0"); + + //Trace driven mode parameters + option_parser_register(opp, "-trace_driven_mode", OPT_BOOL, + &trace_driven_mode, "Turn on trace_driven_mode", + "0"); + option_parser_register(opp, "-trace", OPT_CSTR, + &g_traces_filename, "traces kernel file" + "traces kernel file directory", + "./traces/kernelslist.g"); } ///////////////////////////////////////////////////////////////////////////// diff --git a/src/gpgpu-sim/gpu-sim.h b/src/gpgpu-sim/gpu-sim.h index 76c7a06..6b57bd8 100644 --- a/src/gpgpu-sim/gpu-sim.h +++ b/src/gpgpu-sim/gpu-sim.h @@ -348,6 +348,9 @@ public: size_t sync_depth_limit() const {return runtime_sync_depth_limit; } size_t pending_launch_count_limit() const {return runtime_pending_launch_count_limit;} + unsigned is_trace_driven_mode() const { return trace_driven_mode; } + char* get_traces_filename() const { return g_traces_filename; } + private: void init_clock_domains(void ); @@ -401,6 +404,10 @@ private: unsigned int gpgpu_compute_capability_minor; unsigned long long liveness_message_freq; + //trace driven mode options + bool trace_driven_mode; + char *g_traces_filename; + friend class gpgpu_sim; }; diff --git a/src/gpgpusim_entrypoint.cc b/src/gpgpusim_entrypoint.cc index 816159f..4da74c0 100644 --- a/src/gpgpusim_entrypoint.cc +++ b/src/gpgpusim_entrypoint.cc @@ -60,7 +60,6 @@ class stream_manager* g_stream_manager() { return GPGPUsim_ctx_ptr()->g_stream_manager; } -static void print_simulation_time(); void *gpgpu_sim_thread_sequential(void*) { @@ -242,6 +241,37 @@ gpgpu_sim *gpgpu_context::gpgpu_ptx_sim_init_perf() return GPGPUsim_ctx_ptr()->g_the_gpu; } +gpgpu_sim *gpgpu_context::gpgpu_trace_sim_init_perf(int argc, const char *argv[]) +{ + srand(1); + print_splash(); + func_sim->read_sim_environment_variables(); + ptx_parser->read_parser_environment_variables(); + option_parser_t opp = option_parser_create(); + + ptx_reg_options(opp); + func_sim->ptx_opcocde_latency_options(opp); + + icnt_reg_options(opp); + GPGPUsim_ctx_ptr()->g_the_gpu_config = new gpgpu_sim_config(this); + GPGPUsim_ctx_ptr()->g_the_gpu_config->reg_options(opp); // register GPU microrachitecture options + + option_parser_cmdline(opp, argc, argv); // parse configuration options + fprintf(stdout, "GPGPU-Sim: Configuration options:\n\n"); + option_parser_print(opp, stdout); + // Set the Numeric locale to a standard locale where a decimal point is a "dot" not a "comma" + // so it does the parsing correctly independent of the system environment variables + 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), this); + GPGPUsim_ctx_ptr()->g_stream_manager = new stream_manager((GPGPUsim_ctx_ptr()->g_the_gpu), func_sim->g_cuda_launch_blocking); + + GPGPUsim_ctx_ptr()->g_simulation_starttime = time((time_t *)NULL); + + return GPGPUsim_ctx_ptr()->g_the_gpu; +} + void start_sim_thread(int api) { if( GPGPUsim_ctx_ptr()->g_sim_done ) { diff --git a/src/gpgpusim_entrypoint.h b/src/gpgpusim_entrypoint.h index 887b3c8..4a8d796 100644 --- a/src/gpgpusim_entrypoint.h +++ b/src/gpgpusim_entrypoint.h @@ -84,4 +84,6 @@ class stream_manager* g_stream_manager(); int gpgpu_opencl_ptx_sim_main_perf( kernel_info_t *grid ); +void print_simulation_time(); + #endif diff --git a/src/trace-driven/gpgpusim_trace_driven_main.cc b/src/trace-driven/gpgpusim_trace_driven_main.cc index 6553fd7..881e351 100644 --- a/src/trace-driven/gpgpusim_trace_driven_main.cc +++ b/src/trace-driven/gpgpusim_trace_driven_main.cc @@ -1,138 +1,213 @@ //developed by Mahmoud Khairy, Purdue Univ -#include "../abstract_hardware_model.h" +//#include "../abstract_hardware_model.h" #include <time.h> #include <stdio.h> +#include <vector> +#include <iostream> +#include <fstream> +#include <string> +#include <sstream> +#include <stdio.h> +#include <math.h> + -#include "../option_parser.h" -#include "../cuda-sim/cuda-sim.h" -#include "../cuda-sim/ptx_ir.h" -#include "../cuda-sim/ptx_parser.h" +//#include "../option_parser.h" +//#include "../cuda-sim/cuda-sim.h" +//#include "../cuda-sim/ptx_ir.h" +//#include "../cuda-sim/ptx_parser.h" #include "../gpgpu-sim/gpu-sim.h" -#include "../gpgpu-sim/icnt_wrapper.h" +//#include "../gpgpu-sim/icnt_wrapper.h" +//#include "../gpgpu-sim/icnt_wrapper.h" +#include "../../libcuda/gpgpu_context.h" +#include "trace_driven.h" + //#include "../stream_manager.h" +void arguments_check(); -gpgpu_sim_config g_the_gpu_config; -gpgpu_sim *g_the_gpu; -time_t g_simulation_starttime; +int main ( int argc, const char **argv ) +{ -#define MAX(a,b) (((a)>(b))?(a):(b)) + gpgpu_context* m_gpgpu_context = GPGPU_Context(); + gpgpu_sim * m_gpgpu_sim = m_gpgpu_context->gpgpu_trace_sim_init_perf(argc,argv); + m_gpgpu_sim->init(); -static void print_simulation_time(); + //for each kernel + //load file + //parse and create kernel info + //launch + //while loop till the end of the end kernel execution + //prints stats + trace_parser tracer(m_gpgpu_sim->get_config().get_traces_filename(), m_gpgpu_sim, m_gpgpu_context); -int main ( int argc, char **argv ) -{ - srand(1); + std::vector<std::string> kernellist; + tracer.parse_kernellist_file(kernellist); - option_parser_t opp = option_parser_create(); + for(unsigned i=0; i<kernellist.size(); ++i) { - icnt_reg_options(opp); - g_the_gpu_config.reg_options(opp); // register GPU microrachitecture options - ptx_reg_options(opp); - ptx_opcocde_latency_options(opp); + trace_kernel_info_t* kernel_info = tracer.parse_kernel_info(kernellist[i]); + m_gpgpu_sim->launch(kernel_info); - //ptx_opcocde_latency_options(opp); //do this for trace driven + bool active = false; + bool sim_cycles = false; + bool break_limit = false; - fprintf(stdout, "I am here:\n\n"); - option_parser_cmdline(opp, argc, (const char **)argv); // parse configuration options + do { + if(!m_gpgpu_sim->active()) + break; - fprintf(stdout, "GPGPU-Sim: Configuration options:\n\n"); - option_parser_print(opp, stdout); - // Set the Numeric locale to a standard locale where a decimal point is a "dot" not a "comma" - // so it does the parsing correctly independent of the system environment variables - assert(setlocale(LC_NUMERIC,"C")); - g_the_gpu_config.init(); + //performance simulation + if( m_gpgpu_sim->active() ) { + m_gpgpu_sim->cycle(); + sim_cycles = true; + m_gpgpu_sim->deadlock_check(); + }else { + if(m_gpgpu_sim->cycle_insn_cta_max_hit()){ + g_stream_manager()->stop_all_running_kernels(); + break_limit = true; + } + } - g_the_gpu = new gpgpu_sim(g_the_gpu_config); - //g_stream_manager = new stream_manager(g_the_gpu,g_cuda_launch_blocking); + active=m_gpgpu_sim->active() ; - //load file - //create kernel info - //launch - //while loop till the end - //prints stats - //g_the_gpu->launch(grid); + } while( active ); - g_simulation_starttime = time((time_t *)NULL); + tracer.kernel_finalizer(kernel_info); - bool active = false; - bool sim_cycles = false; - bool break_limit = false; + m_gpgpu_sim->print_stats(); - g_the_gpu->init(); - do { - // check if a kernel has completed - // launch operation on device if one is pending and can be run + if(sim_cycles) { + m_gpgpu_sim->update_stats(); + print_simulation_time(); + } - // Need to break this loop when a kernel completes. This was a - // source of non-deterministic behaviour in GPGPU-Sim (bug 147). - // If another stream operation is available, g_the_gpu remains active, - // causing this loop to not break. If the next operation happens to be - // another kernel, the gpu is not re-initialized and the inter-kernel - // behaviour may be incorrect. Check that a kernel has finished and - // no other kernel is currently running. - if(!g_the_gpu->active()) - break; + if(break_limit) { + printf("GPGPU-Sim: ** break due to reaching the maximum cycles (or instructions) **\n"); + fflush(stdout); + exit(1); + } + } - //performance simulation - if( g_the_gpu->active() ) { - g_the_gpu->cycle(); - sim_cycles = true; - g_the_gpu->deadlock_check(); - }else { - if(g_the_gpu->cycle_insn_cta_max_hit()){ - g_stream_manager->stop_all_running_kernels(); - break_limit = true; - } - } + return 1; +} - active=g_the_gpu->active() ; +trace_parser::trace_parser(const char* kernellist_filepath, gpgpu_sim * m_gpgpu_sim, gpgpu_context* m_gpgpu_context) +{ - } while( active ); + this->m_gpgpu_sim = m_gpgpu_sim; + this->m_gpgpu_context = m_gpgpu_context; + kernellist_filename = kernellist_filepath; +} - printf("GPGPU-Sim: ** STOP simulation thread (no work) **\n"); - fflush(stdout); +void trace_parser::parse_kernellist_file(std::vector<std::string>& kernellist) { - g_the_gpu->print_stats(); + ifs.open(kernellist_filename); - if(sim_cycles) { - g_the_gpu->update_stats(); - print_simulation_time(); - } + if (!ifs.is_open()) { + std::cout << "Unable to open file: " <<kernellist_filename<<std::endl; + exit(1); + } + std::string directory(kernellist_filename); + const size_t last_slash_idx = directory.rfind('/'); + if (std::string::npos != last_slash_idx) + { + directory = directory.substr(0, last_slash_idx); + } - printf("GPGPU-Sim: *** simulation thread exiting ***\n"); - fflush(stdout); + std::string line, filepath; + while(!ifs.eof()) { + getline(ifs, line); + if(line.empty()) + continue; + filepath = directory+"/"+line; + kernellist.push_back(filepath); + } + + ifs.close(); +} - if(break_limit) { - printf("GPGPU-Sim: ** break due to reaching the maximum cycles (or instructions) **\n"); + +trace_kernel_info_t* trace_parser::parse_kernel_info(const std::string& kerneltraces_filepath) { + + ifs.open(kerneltraces_filepath.c_str()); + + if (!ifs.is_open()) { + std::cout << "Unable to open file: " <<kerneltraces_filepath<<std::endl; exit(1); - } + } + + std::cout << "Processing kernel " <<kerneltraces_filepath<<std::endl; + + unsigned grid_dim_x=0, grid_dim_y=0, grid_dim_z=0, tb_dim_x=0, tb_dim_y=0, tb_dim_z=0; + unsigned shmem=0, nregs=0, cuda_stream_id=0, kernel_id=0; + std::string line; + std::stringstream ss; + std::string string1, string2; + std::string kernel_name; - return 1; + while(!ifs.eof()) { + getline(ifs, line); + + if (line.length() == 0) { + continue; + } + else if(line[0] == '#'){ + break; //the begin of the instruction stream + } + else if(line[0] == '-') { + ss.str(line); + ss.ignore(); + ss>>string1>>string2; + if(string1 == "kernel" && string2 == "name") { + const size_t equal_idx = line.find('='); + kernel_name = line.substr(equal_idx+1); + } + else if(string1 == "kernel" && string2 == "id") { + sscanf(line.c_str(), "-kernel id = %d", &kernel_id); + } + else if(string1 == "grid" && string2 == "dim") { + sscanf(line.c_str(), "-grid dim = (%d,%d,%d)", &grid_dim_x, &grid_dim_y, &grid_dim_z); + } + else if (string1 == "block" && string2 == "dim") { + sscanf(line.c_str(), "-block dim = (%d,%d,%d)", &tb_dim_x, &tb_dim_y, &tb_dim_z); + } + else if (string1 == "shmem") { + sscanf(line.c_str(), "-shmem = %d", &shmem); + } + else if (string1 == "nregs") { + sscanf(line.c_str(), "-nregs = %d", &nregs); + } + else if (string1 == "cuda" && string2 == "stream") { + sscanf(line.c_str(), "-cuda stream id = %d", &cuda_stream_id); + } + continue; + } + } + + gpgpu_ptx_sim_info info; + info.smem = shmem; + info.regs = nregs; + dim3 gridDim(grid_dim_x, grid_dim_y, grid_dim_z); + dim3 blockDim(tb_dim_x, tb_dim_y, tb_dim_z); + trace_function_info* function_info = new trace_function_info(info, m_gpgpu_context); + trace_kernel_info_t* kernel_info = new trace_kernel_info_t(gridDim, blockDim, function_info, kerneltraces_filepath); + + return kernel_info; } -void print_simulation_time() -{ - time_t current_time, difference, d, h, m, s; - current_time = time((time_t *)NULL); - difference = MAX(current_time - g_simulation_starttime, 1); - d = difference/(3600*24); - h = difference/3600 - 24*d; - m = difference/60 - 60*(h + 24*d); - s = difference - 60*(m + 60*(h + 24*d)); +void trace_parser::kernel_finalizer(trace_kernel_info_t* kernel_info){ + if (ifs.is_open()) + ifs.close(); - fflush(stderr); - printf("\n\ngpgpu_simulation_time = %u days, %u hrs, %u min, %u sec (%u sec)\n", - (unsigned)d, (unsigned)h, (unsigned)m, (unsigned)s, (unsigned)difference ); - printf("gpgpu_simulation_rate = %u (inst/sec)\n", (unsigned)(g_the_gpu->gpu_tot_sim_insn / difference) ); - printf("gpgpu_simulation_rate = %u (cycle/sec)\n", (unsigned)(gpu_tot_sim_cycle / difference) ); - fflush(stdout); + delete kernel_info->entry(); + delete kernel_info; } + diff --git a/src/trace-driven/trace_driven.h b/src/trace-driven/trace_driven.h new file mode 100644 index 0000000..91ff90b --- /dev/null +++ b/src/trace-driven/trace_driven.h @@ -0,0 +1,71 @@ +//developed by Mahmoud Khairy, Purdue Univ + +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +#ifndef TRACE_DRIVEN_H +#define TRACE_DRIVEN_H + +#include "../abstract_hardware_model.h" + + +class trace_function_info: public function_info { +public: + trace_function_info(const struct gpgpu_ptx_sim_info &info, gpgpu_context* m_gpgpu_context):function_info(0, m_gpgpu_context ) { + m_kernel_info = info; + } + + virtual const struct gpgpu_ptx_sim_info* get_kernel_info () const { + return &m_kernel_info; + } + + virtual const void set_kernel_info (const struct gpgpu_ptx_sim_info &info) { + m_kernel_info = info; + } + +private: + + +}; + +class trace_kernel_info_t: public kernel_info_t { +public: + trace_kernel_info_t(dim3 gridDim, dim3 blockDim, trace_function_info* m_function_info, const std::string& filepath):kernel_info_t(gridDim, blockDim, m_function_info) { + traces_filepath = filepath; + } + +private: + std::string traces_filepath; + +}; + +class trace_warp_inst_t: public warp_inst_t { +public: + + trace_warp_inst_t() { + } + +private: + + +}; + +class trace_parser { +public: + trace_parser(const char* kernellist_filepath, gpgpu_sim * m_gpgpu_sim, gpgpu_context* m_gpgpu_context); + + void parse_kernellist_file(std::vector<std::string>& kernellist); + trace_kernel_info_t* parse_kernel_info(const std::string& kerneltraces_filepath); + void kernel_finalizer(trace_kernel_info_t* kernel_info); + +private: + + std::string kernellist_filename; + std::ifstream ifs; + gpgpu_sim * m_gpgpu_sim; + gpgpu_context* m_gpgpu_context; + +}; + +#endif |
