summaryrefslogtreecommitdiff
path: root/libcuda/cuda_runtime_api.cc
diff options
context:
space:
mode:
authorspeverel <[email protected]>2016-06-03 15:25:30 -0700
committerspeverel <[email protected]>2016-06-03 15:25:30 -0700
commitd68b2883629d4804737ce0501251ac88bdf4bea9 (patch)
treed2035cd0d4ab958c00f1ee9b7bcb38d3e7df6b00 /libcuda/cuda_runtime_api.cc
parent71ccce6074de5d7eef3fbe2cda1dbca008549f07 (diff)
parenta2c48c472fc2ab159b826f3af1d1503c23eaed39 (diff)
Merge branch 'dev' of https://github.com/sspenst/gpgpu-sim_distribution into dev
Diffstat (limited to 'libcuda/cuda_runtime_api.cc')
-rw-r--r--libcuda/cuda_runtime_api.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/libcuda/cuda_runtime_api.cc b/libcuda/cuda_runtime_api.cc
index e2626d2..8049f43 100644
--- a/libcuda/cuda_runtime_api.cc
+++ b/libcuda/cuda_runtime_api.cc
@@ -1496,6 +1496,49 @@ std::list<cuobjdumpSection*> pruneSectionList(std::list<cuobjdumpSection*> cuobj
return prunedList;
}
+//! Merge all remaining PTX sections in the section list into one PTX file
+// NOTE: this function needs some tweaking to deal with repeated fucntion/variable declarations/definitions
+std::list<cuobjdumpSection*> mergeSectionList(std::list<cuobjdumpSection*> cuobjdumpSectionList){
+ char *ptxcode = "";
+ std::list<cuobjdumpSection*>::iterator old_iter;
+ cuobjdumpPTXSection* old_ptxsection = NULL;
+ cuobjdumpPTXSection* ptxsection;
+ std::list<cuobjdumpSection*> mergedList;
+
+ for ( std::list<cuobjdumpSection*>::iterator iter = cuobjdumpSectionList.begin();
+ iter != cuobjdumpSectionList.end();
+ iter++){
+ if((ptxsection=dynamic_cast<cuobjdumpPTXSection*>(*iter)) != NULL){
+ // Read and remove the last PTX section
+ if (old_ptxsection != NULL) {
+ ptxcode = readfile(old_ptxsection->getPTXfilename());
+ // remove ptx file?
+ delete *old_iter;
+ }
+
+ // Append all the PTX from the last PTX section into the current PTX section
+ // Add 50 to ptxcode to ignore the information regarding version/target/address_size
+ if (strlen(ptxcode) >= 50) {
+ FILE *ptxfile = fopen((ptxsection->getPTXfilename()).c_str(), "a");
+ fprintf(ptxfile, "%s", ptxcode + 50);
+ fclose(ptxfile);
+ }
+
+ old_iter = iter;
+ old_ptxsection = ptxsection;
+ }
+ // Store all non-PTX sections
+ else {
+ mergedList.push_back(*iter);
+ }
+ }
+
+ // Store the final PTX section
+ mergedList.push_front(*old_iter);
+
+ return mergedList;
+}
+
//! Within the section list, find the ELF section corresponding to a given identifier
cuobjdumpELFSection* findELFSectionInList(std::list<cuobjdumpSection*> sectionlist, const std::string identifier){
@@ -1559,6 +1602,7 @@ void cuobjdumpInit(){
CUctx_st *context = GPGPUSim_Context();
extract_code_using_cuobjdump(); //extract all the output of cuobjdump to _cuobjdump_*.*
cuobjdumpSectionList = pruneSectionList(cuobjdumpSectionList, context);
+ cuobjdumpSectionList = mergeSectionList(cuobjdumpSectionList);
}
std::map<int, std::string> fatbinmap;