diff options
| author | Wilson Fung <[email protected]> | 2012-08-16 20:11:16 -0800 |
|---|---|---|
| committer | Andrew Boktor <[email protected]> | 2014-08-14 13:48:54 -0700 |
| commit | 888dd6c18d927d93856c721a06c7155d5eac2d53 (patch) | |
| tree | 91627090401871d6093b51ee6afa8656c616ea4c /libcuda/cuda_runtime_api.cc | |
| parent | 630ea0793949ef5845318e677d80c7b60a89d801 (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]
Diffstat (limited to 'libcuda/cuda_runtime_api.cc')
| -rw-r--r-- | libcuda/cuda_runtime_api.cc | 42 |
1 files changed, 30 insertions, 12 deletions
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); |
