From 05f02e48963660d60120aca2f0198e0723e257d5 Mon Sep 17 00:00:00 2001 From: "Andrew M. B. Boktor" Date: Fri, 4 May 2012 09:51:53 -0800 Subject: Supporting the option for removing temporary files . the option -gpgpu_ptx_save_converted_ptxplus allows keeping the ptxplus file . the option -gpgpu_keep allows keeping intermediate files used to communicate with other programs (e.g. cuobjdump) [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 12304] --- libcuda/cuda_runtime_api.cc | 39 +++++++++++++++++++++++++++++---------- src/abstract_hardware_model.cc | 4 ---- src/abstract_hardware_model.h | 2 -- src/cuda-sim/ptx_loader.cc | 27 ++++++++++++++++----------- src/cuda-sim/ptx_loader.h | 1 + 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc index e9744d0..85664a7 100644 --- a/libcuda/cuda_runtime_api.cc +++ b/libcuda/cuda_runtime_api.cc @@ -1159,10 +1159,15 @@ extern "C" FILE *cuobjdump_in; /*! * This Function extract the whole PTX (for all the files) using cuobjdump * */ -void extract_ptx(){ +void extract_code_using_cuobjdump(){ char command[1000]; + + char fname[1024]; + snprintf(fname,1024,"_cuobjdump_complete_output_XXXXXX"); + int fd=mkstemp(fname); + close(fd); + char* whole_code; - char fname[1024]="_ptx_whole_code_WESWW"; //! Running CUobjdump using dynamic link to current process snprintf(command,1000,"$CUDA_INSTALL_PATH/bin/cuobjdump -ptx -elf -sass /proc/%d/exe > %s",getpid(),fname); printf("Running cuobjdump using \"%s\"\n", command); @@ -1177,10 +1182,10 @@ void extract_ptx(){ printf("Done parsing!!!\n"); } -//! Return proper ptx version +//! Find the proper sm version to be used /*! - * This function return newest ptx version inside the argument - * which is is not newer than forced_max_capability + * The function finds the highest sm version lower than the option + * force_max_capability */ unsigned get_best_version(std::list sectionlist, CUctx_st *context){ @@ -1209,9 +1214,10 @@ unsigned get_best_version(std::list sectionlist, CUctx_st *con return max_capability; } +//! Find number of files with a certain sm version /*! - * Return number of diffrent ptx files generated in first argument - * which have sm version equal to selected_capability + * Once the sm verison to be used is known (using get_best_version), this + * function counts the number of files that use this sm version */ unsigned get_number_of_ptx(std::list sectionlist, unsigned selected_capability){ int result = 0; @@ -1275,7 +1281,7 @@ void useCuobjdump() { CUctx_st *context = GPGPUSim_Context(); unsigned source_num=1; char *sass, *elf; - extract_ptx(); //extract all the output of cuobjdump to _cuobjdump_*.* + extract_code_using_cuobjdump(); //extract all the output of cuobjdump to _cuobjdump_*.* unsigned selected_capability = get_best_version(cuobjdump, context); //Find max capability less than forced_max_capability unsigned total_ptx_files = get_number_of_ptx(cuobjdump,selected_capability); //Count ptx files for the given capability @@ -1311,6 +1317,19 @@ void useCuobjdump() { load_constants(symtab,STATIC_ALLOC_LIMIT,context->get_device()->get_gpgpu()); } } + if(!keep_intermediate_files()){ + char rm_commandline[1024]; + + snprintf(rm_commandline,1024,"rm -f _cuobjdump_*"); + + printf("GPGPU-Sim PTX: removing temporary files using \"%s\"\n", rm_commandline); + int rm_result = system(rm_commandline); + if( rm_result != 0 ) { + printf("GPGPU-Sim PTX: ERROR ** while removing temporary files %d\n", rm_result); + exit(1); + } + } + } void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin ) @@ -1326,8 +1345,8 @@ void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin ) next_fat_bin_handle++; printf("GPGPU-Sim PTX: __cudaRegisterFatBinary, fat_cubin_handle = %u\n", fat_cubin_handle); /*! - * This function extracting all data from all files in first call - * then for next calls, only return the appropriate number + * This function extracts all data from all files in first call + * then for next calls, only returns the appropriate number */ assert(fat_cubin_handle >= 1); if(fat_cubin_handle == 1) diff --git a/src/abstract_hardware_model.cc b/src/abstract_hardware_model.cc index 6457edd..01899d5 100644 --- a/src/abstract_hardware_model.cc +++ b/src/abstract_hardware_model.cc @@ -62,10 +62,6 @@ void gpgpu_functional_sim_config::reg_options(class OptionParser * opp) &m_ptx_convert_to_ptxplus, "Convert SASS (native ISA) to ptxplus and run ptxplus", "0"); - option_parser_register(opp, "-gpgpu_ptx_save_converted_ptxplus", OPT_BOOL, - &m_ptx_save_converted_ptxplus, - "Saved converted ptxplus to a file", - "0"); option_parser_register(opp, "-gpgpu_ptx_force_max_capability", OPT_UINT32, &m_ptx_force_max_capability, "Force maximum compute capability", diff --git a/src/abstract_hardware_model.h b/src/abstract_hardware_model.h index 28dc6cb..7a710f8 100644 --- a/src/abstract_hardware_model.h +++ b/src/abstract_hardware_model.h @@ -338,7 +338,6 @@ public: unsigned get_forced_max_capability() const { return m_ptx_force_max_capability; } bool convert_to_ptxplus() const { return m_ptx_convert_to_ptxplus; } bool use_cuobjdump() const { return m_ptx_use_cuobjdump; } - bool saved_converted_ptxplus() const { return m_ptx_save_converted_ptxplus; } int get_ptx_inst_debug_to_file() const { return g_ptx_inst_debug_to_file; } const char* get_ptx_inst_debug_file() const { return g_ptx_inst_debug_file; } @@ -348,7 +347,6 @@ public: private: // PTX options int m_ptx_convert_to_ptxplus; - int m_ptx_save_converted_ptxplus; int m_ptx_use_cuobjdump; unsigned m_ptx_force_max_capability; diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc index cbfa9f4..d405288 100644 --- a/src/cuda-sim/ptx_loader.cc +++ b/src/cuda-sim/ptx_loader.cc @@ -53,6 +53,9 @@ extern "C" FILE *ptxinfo_in; static bool g_save_embedded_ptx; bool g_keep_intermediate_files; +bool m_ptx_save_converted_ptxplus; + +bool keep_intermediate_files() {return g_keep_intermediate_files;} void ptx_reg_options(option_parser_t opp) { @@ -62,6 +65,10 @@ void ptx_reg_options(option_parser_t opp) option_parser_register(opp, "-keep", OPT_BOOL, &g_keep_intermediate_files, "keep intermediate files created by GPGPU-Sim when interfacing with external programs", "0"); + option_parser_register(opp, "-gpgpu_ptx_save_converted_ptxplus", OPT_BOOL, + &m_ptx_save_converted_ptxplus, + "Saved converted ptxplus to a file", + "0"); } void print_ptx_file( const char *p, unsigned source_num, const char *filename ) @@ -125,20 +132,18 @@ char* gpgpu_ptx_sim_convert_ptx_and_sass_to_ptxplus(const char *ptxfilename, con char* ptxplus_str = new char [strlen(text.c_str())+1]; strcpy(ptxplus_str, text.c_str()); - // Remove temporary files - // TODO: Fix deleting/keeping PTXPlus files - /* - char rm_commandline[1024]; + if (!m_ptx_save_converted_ptxplus){ + char rm_commandline[1024]; - snprintf(rm_commandline,1024,"rm -f %s", fname_ptxplus); + snprintf(rm_commandline,1024,"rm -f %s", fname_ptxplus); - printf("GPGPU-Sim PTX: removing temporary files using \"%s\"\n", rm_commandline); - int rm_result = system(rm_commandline); - if( rm_result != 0 ) { - printf("GPGPU-Sim PTX: ERROR ** while removing temporary files %d\n", rm_result); - exit(1); + printf("GPGPU-Sim PTX: removing temporary files using \"%s\"\n", rm_commandline); + int rm_result = system(rm_commandline); + if( rm_result != 0 ) { + printf("GPGPU-Sim PTX: ERROR ** while removing temporary files %d\n", rm_result); + exit(1); + } } - */ printf("GPGPU-Sim PTX: DONE converting EMBEDDED .ptx file to ptxplus \n"); return ptxplus_str; diff --git a/src/cuda-sim/ptx_loader.h b/src/cuda-sim/ptx_loader.h index 9227d85..21974e6 100644 --- a/src/cuda-sim/ptx_loader.h +++ b/src/cuda-sim/ptx_loader.h @@ -33,5 +33,6 @@ extern bool g_override_embedded_ptx; class symbol_table *gpgpu_ptx_sim_load_ptx_from_string( const char *p, unsigned source_num ); void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num ); char* gpgpu_ptx_sim_convert_ptx_and_sass_to_ptxplus(const char *ptx_str, const char *sass_str, const char *elf_str); +bool keep_intermediate_files(); #endif -- cgit v1.3