summaryrefslogtreecommitdiff
path: root/libcuda/cuda_runtime_api.cc
diff options
context:
space:
mode:
authortgrogers <[email protected]>2018-06-29 23:43:31 -0400
committertgrogers <[email protected]>2018-06-29 23:43:31 -0400
commitd42cb5648f77cd2caed9c656f4d6ad75c23b6f5a (patch)
tree8e5b964850a7cba2531c7e5d5ce594632f417ac3 /libcuda/cuda_runtime_api.cc
parent112a3a2e3c9d17af420d2389f68a35407c692744 (diff)
Fixing the PTXPLUS + new CUDA execution case.
Diffstat (limited to 'libcuda/cuda_runtime_api.cc')
-rw-r--r--libcuda/cuda_runtime_api.cc59
1 files changed, 42 insertions, 17 deletions
diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc
index 94705dc..5964a4d 100644
--- a/libcuda/cuda_runtime_api.cc
+++ b/libcuda/cuda_runtime_api.cc
@@ -1367,17 +1367,17 @@ void extract_code_using_cuobjdump(){
// Needs the option '-all' to extract PTX from CDP-enabled binary
extern bool g_cdp_enabled;
const int current_cuda = atoi(getenv("CUDA_VERSION_NUMBER"));
- if ( context->get_device()->get_gpgpu()->get_config().convert_to_ptxplus() && current_cuda > 42 ) {
+ if ( context->get_device()->get_gpgpu()->get_config().convert_to_ptxplus() && current_cuda > 4020 ) {
const char* cuda_42_path = getenv("CUDA_42_INSTALL_PATH");
if ( NULL == cuda_42_path ) {
printf("You are using a new version of CUDA and PTXPLUS. You are required to have CUDA SDK 4.2 and explicitly "
- "point to it via the environment variable $CUDA_42_INSTALL_PATH.");
+ "point to it via the environment variable $CUDA_42_INSTALL_PATH.\n\n");
exit(1);
} else {
command = "$CUDA_42_INSTALL_PATH/bin/cuobjdump";
}
} else {
- command = "$CUDA_INSTALL_PATH/bin/cuobjdump";
+ command = "$CUDA_42_INSTALL_PATH/bin/cuobjdump";
}
if(!g_cdp_enabled)
command += " -ptx -elf -sass " + app_binary + " > " + fname;
@@ -1778,21 +1778,46 @@ void** CUDARTAPI __cudaRegisterFatBinary( void *fatCubin )
if (sizeof(void*) == 4)
printf("GPGPU-Sim PTX: FatBin file name extraction has not been tested on 32-bit system.\n");
- #if (CUDART_VERSION <= 6000)
- // 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;
+ // This code will get the CUDA version the app was compiled with.
+ // We need this to determine how to handle the parsing of the binary.
+ // Making this a runtime variable based on the app, enables GPGPU-Sim compiled
+ // with a newer version of CUDA to run apps compiled with older versions of
+ // CUDA. This is especially useful for PTXPLUS execution.
+ char fname[1024];
+ snprintf(fname,1024,"_app_cuda_version_XXXXXX");
+ int fd=mkstemp(fname);
+ close(fd);
+ int app_cuda_version = 0;
+ std::string app_cuda_version_command = "ldd " + get_app_binary() + " | grep libcudart.so | sed 's/.*libcudart.so.\\(.*\\) =>.*/\\1/' > " + fname;
+ system(app_cuda_version_command.c_str());
+ FILE * cmd = fopen(fname, "r");
+ char buf[256];
+ while (fgets(buf, sizeof(buf), cmd) != 0) {
+ std::cout << buf;
+ app_cuda_version = atoi(buf);
+ }
+ fclose(cmd);
+ if ( app_cuda_version == 0 ) {
+ printf( "Error - Cannot detect the app's CUDA version.\n" );
+ exit(1);
+ }
+ const char* filename;
+ if ( app_cuda_version < 6 ) {
+ // 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));
+ filename = (pfatbin+16+offset);
+ } else {
+ filename = "default";
+ }
- // 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);
- #else
- const char * filename = "default";
- #endif
// 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