Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop ptx common header by detecting the end of common line #77

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions libcuda/cuda_runtime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,27 @@ std::list<cuobjdumpSection*> pruneSectionList(std::list<cuobjdumpSection*> cuobj
return prunedList;
}

static const char *
findPtxBody(const char *ptxcode)
{
const char *line_head;

line_head = ptxcode;
while (line_head) {
const char *line_next;

line_next = strchr(line_head, '\n');
if (line_next == NULL)
return NULL;
line_next++;
if (strncmp(line_head, ".address_size", 13) == 0)
return line_next;
line_head = line_next;
}

return NULL;
}

//! Merge all PTX sections that have a specific identifier into one file
std::list<cuobjdumpSection*> mergeMatchingSections(std::list<cuobjdumpSection*> cuobjdumpSectionList, std::string identifier){
const char *ptxcode = "";
Expand All @@ -1559,13 +1580,13 @@ std::list<cuobjdumpSection*> mergeMatchingSections(std::list<cuobjdumpSection*>
}

// 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) {
// Find the line after ".address_size" to ignore the information regarding version/target/address_size
ptxcode = findPtxBody(ptxcode);
if (ptxcode != NULL) {
FILE *ptxfile = fopen((ptxsection->getPTXfilename()).c_str(), "a");
fprintf(ptxfile, "%s", ptxcode + 50);
fprintf(ptxfile, "%s", ptxcode);
fclose(ptxfile);
}

old_iter = iter;
old_ptxsection = ptxsection;
}
Expand Down