summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilson Fung <[email protected]>2012-08-16 20:11:16 -0800
committerAndrew Boktor <[email protected]>2014-08-14 13:48:54 -0700
commit888dd6c18d927d93856c721a06c7155d5eac2d53 (patch)
tree91627090401871d6093b51ee6afa8656c616ea4c
parent630ea0793949ef5845318e677d80c7b60a89d801 (diff)
Integration from TM-311 branch.
- Updated PTX parser to support CUDA 4.1 and 4.2. - Revised fatbin workaround to a more robust version (with comments explaining it). - Added print_simulation_time() in gpgpu_sim_thread_concurrent(). [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 13789]
-rw-r--r--CHANGES11
-rw-r--r--libcuda/cuda_runtime_api.cc42
-rw-r--r--src/cuda-sim/ptx.l8
-rw-r--r--src/cuda-sim/ptx.y1
-rw-r--r--src/cuda-sim/ptxinfo.y3
-rw-r--r--src/gpgpusim_entrypoint.cc7
6 files changed, 49 insertions, 23 deletions
diff --git a/CHANGES b/CHANGES
index 33ceee2..f077145 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,20 +1,25 @@
CHANGE LOG:
Version 3.1.1+edits (development branch) versus 3.1.1
+- Added support for CUDA 4.1 and 4.2 (PTX 3.0).
- Added an improved and less brittle support for associating fatbins to
sections from the output of cuobjdump
+- Added raw simulation time printout back for CUDA.
+- Revived support for PTX file override via environment variables for CUDA 4.0
+ onwards.
- Bug Fixes:
- Fixed a compile error that happens with newer gcc/g++ versions (4.7.1)
- - Fixed a bug with the association between cuobjdump output and cubin
+ - Fixed a bug with the association between cuobjdump output and cubin
handles (Bug #7 external)
- Adding support for atomic operations with generic memory space. Before
this, atomic operations can only work on global memory space. (Bug #14
external)
- - Fixed a bug in conversion to ptxplus that was causing local memory store
+ - Fixed a bug in conversion to ptxplus that was causing local memory store
or load instruction to be ignored.
- Adding support for direct addressing using immediate values for the load
and store instructions.
- - Fixed a bug that was causing inconsistency in local memory address calculations
+ - Fixed a bug that was causing inconsistency in local memory address
+ calculations
Version 3.1.1 versus 3.1.0
- Add checks to top level makefile to ensure setup_environment is run and checks to
diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc
index 6bbd2f2..58ffd4d 100644
--- a/libcuda/cuda_runtime_api.cc
+++ b/libcuda/cuda_runtime_api.cc
@@ -1387,7 +1387,14 @@ void cuobjdumpRegisterFatBinary(unsigned int handle, char* filename){
cuobjdumpPTXSection* ptx = findptxsection(cuobjdumpSectionList, fname);
symbol_table *symtab;
- char *ptxcode = readfile(ptx->getPTXfilename());
+ char *ptxcode;
+ const char *override_ptx_name = getenv("PTX_SIM_KERNELFILE");
+ if (override_ptx_name == NULL or getenv("PTX_SIM_USE_PTX_FILE") == NULL) {
+ ptxcode = readfile(ptx->getPTXfilename());
+ } else {
+ printf("GPGPU-Sim PTX: overriding embedded ptx with '%s' (PTX_SIM_USE_PTX_FILE is set)\n", override_ptx_name);
+ ptxcode = readfile(override_ptx_name);
+ }
if(context->get_device()->get_gpgpu()->get_config().convert_to_ptxplus() ) {
cuobjdumpELFSection* elfsection = findelfsection(cuobjdumpSectionList, ptx->getIdentifier());
assert (elfsection!= NULL);
@@ -1491,17 +1498,28 @@ void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin )
CUctx_st *context = GPGPUSim_Context();
static unsigned next_fat_bin_handle = 1;
if(context->get_device()->get_gpgpu()->get_config().use_cuobjdump()) {
- char * s1 = *((char**)((char*)fatCubin+8));
-#if (CUDART_VERSION < 4010)
- char * filename = (s1+72);
-#else
- // for CUDA 4.1 and 4.2, the source file name can be found at offset 80,
- // or offset 96 if the source file has been compiled with a ptxas option
- char * filename = (s1+80);
- if (strncmp(filename, "-dlcm=", 6) == 0) {
- filename += 16;
- }
-#endif
+ // The following workaround has only been verified on 64-bit systems.
+ if (sizeof(void*) == 4)
+ printf("GPGPU-Sim PTX: FatBin file name extraction has not been tested on 32-bit system.\n");
+
+ // FatBin handle from the .fatbin.c file (one of the intermediate files generated by NVCC)
+ typedef struct {int m; int v; const unsigned long long* d; char* f;} __fatDeviceText __attribute__ ((aligned (8)));
+ __fatDeviceText * fatDeviceText = (__fatDeviceText *) fatCubin;
+
+ // Extract the source code file name that generate the given FatBin.
+ // - Obtains the pointer to the actual fatbin structure from the FatBin handle (fatCubin).
+ // - An integer inside the fatbin structure contains the relative offset to the source code file name.
+ // - This offset differs among different CUDA and GCC versions.
+ char * pfatbin = (char*) fatDeviceText->d;
+ int offset = *((int*)(pfatbin+48));
+ char * filename = (pfatbin+16+offset);
+
+ // The extracted file name is associated with a fat_cubin_handle passed
+ // into cudaLaunch(). Inside cudaLaunch(), the associated file name is
+ // used to find the PTX/SASS section from cuobjdump, which contains the
+ // PTX/SASS code for the launched kernel function.
+ // This allows us to work around the fact that cuobjdump only outputs the
+ // file name associated with each section.
unsigned fat_cubin_handle = next_fat_bin_handle;
next_fat_bin_handle++;
printf("GPGPU-Sim PTX: __cudaRegisterFatBinary, fat_cubin_handle = %u, filename=%s\n", fat_cubin_handle, filename);
diff --git a/src/cuda-sim/ptx.l b/src/cuda-sim/ptx.l
index 4747181..2d0e065 100644
--- a/src/cuda-sim/ptx.l
+++ b/src/cuda-sim/ptx.l
@@ -66,8 +66,8 @@ bfind TC; ptx_lval.int_value = BFIND_OP; return OPCODE;
bra TC; ptx_lval.int_value = BRA_OP; return OPCODE;
brev TC; ptx_lval.int_value = BREV_OP; return OPCODE;
brkpt TC; ptx_lval.int_value = BRKPT_OP; return OPCODE;
-call TC; ptx_lval.int_value = CALL_OP; return OPCODE;
-callp TC; ptx_lval.int_value = CALLP_OP; return OPCODE;
+call TC; BEGIN(NOT_OPCODE); ptx_lval.int_value = CALL_OP; return OPCODE; // blocking opcode token in case the callee has the same name as an opcode
+callp TC; BEGIN(NOT_OPCODE); ptx_lval.int_value = CALLP_OP; return OPCODE;
clz TC; ptx_lval.int_value = CLZ_OP; return OPCODE;
cnot TC; ptx_lval.int_value = CNOT_OP; return OPCODE;
cos TC; ptx_lval.int_value = COS_OP; return OPCODE;
@@ -155,7 +155,7 @@ breakaddr TC; ptx_lval.int_value = BREAKADDR_OP; return OPCODE;
\.entry TC; return ENTRY_DIRECTIVE;
\.extern TC; return EXTERN_DIRECTIVE;
\.file TC; BEGIN(INITIAL); return FILE_DIRECTIVE;
-\.func TC; BEGIN(NOT_OPCODE); return FUNC_DIRECTIVE;
+\.func TC; BEGIN(NOT_OPCODE); return FUNC_DIRECTIVE; // blocking opcode parsing in case the function has the same name as an opcode (e.g. sin(), cos())
\.global TC; return GLOBAL_DIRECTIVE;
\.local TC; return LOCAL_DIRECTIVE;
\.loc TC; return LOC_DIRECTIVE;
@@ -352,7 +352,7 @@ breakaddr TC; ptx_lval.int_value = BREAKADDR_OP; return OPCODE;
";" TC; BEGIN(INITIAL); return SEMI_COLON;
"!" TC; return EXCLAMATION;
"=" TC; return EQUALS;
-"{" TC; return LEFT_BRACE;
+"{" TC; BEGIN(INITIAL); return LEFT_BRACE; // starting a statement block (allow next token to be parsed as an opcode)
"}" TC; return RIGHT_BRACE;
\. TC; return PERIOD;
"/" TC; return BACKSLASH;
diff --git a/src/cuda-sim/ptx.y b/src/cuda-sim/ptx.y
index 2c01a70..5b69975 100644
--- a/src/cuda-sim/ptx.y
+++ b/src/cuda-sim/ptx.y
@@ -259,6 +259,7 @@ directive_statement: variable_declaration SEMI_COLON
| FILE_DIRECTIVE INT_OPERAND STRING { add_file($2,$3); }
| LOC_DIRECTIVE INT_OPERAND INT_OPERAND INT_OPERAND
| PRAGMA_DIRECTIVE STRING SEMI_COLON { add_pragma($2); }
+ | function_decl SEMI_COLON {/*Do nothing*/}
;
variable_declaration: variable_spec identifier_list { add_variables(); }
diff --git a/src/cuda-sim/ptxinfo.y b/src/cuda-sim/ptxinfo.y
index 8bc1306..e4ba6b2 100644
--- a/src/cuda-sim/ptxinfo.y
+++ b/src/cuda-sim/ptxinfo.y
@@ -51,7 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%token SEMICOLON
%token QUOTE
%token LINE
-%token WARNING
+%token <string_value> WARNING
%token FOR
%{
@@ -78,6 +78,7 @@ input: /* empty */
line: HEADER INFO COLON line_info
| HEADER IDENTIFIER COMMA LINE INT_OPERAND SEMICOLON WARNING
+ | HEADER WARNING { printf("GPGPU-Sim: ptxas %s\n", $2); }
;
line_info: function_name
diff --git a/src/gpgpusim_entrypoint.cc b/src/gpgpusim_entrypoint.cc
index 006cecd..6271f79 100644
--- a/src/gpgpusim_entrypoint.cc
+++ b/src/gpgpusim_entrypoint.cc
@@ -132,9 +132,10 @@ void *gpgpu_sim_thread_concurrent(void*)
printf("GPGPU-Sim: ** STOP simulation thread (no work) **\n");
fflush(stdout);
}
- if(sim_cycles) {
- g_the_gpu->update_stats();
- }
+ if(sim_cycles) {
+ g_the_gpu->update_stats();
+ print_simulation_time();
+ }
pthread_mutex_lock(&g_sim_lock);
g_sim_active = false;
pthread_mutex_unlock(&g_sim_lock);