summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cuda-sim/cuda-sim.cc19
-rw-r--r--src/cuda-sim/ptx_loader.cc126
-rw-r--r--src/cuda-sim/ptxinfo.l4
-rw-r--r--src/cuda-sim/ptxinfo.y16
4 files changed, 160 insertions, 5 deletions
diff --git a/src/cuda-sim/cuda-sim.cc b/src/cuda-sim/cuda-sim.cc
index 15417d1..fba3a59 100644
--- a/src/cuda-sim/cuda-sim.cc
+++ b/src/cuda-sim/cuda-sim.cc
@@ -1864,10 +1864,14 @@ unsigned translate_pc_to_ptxlineno(unsigned pc)
// ptxinfo parser
+extern std::map<unsigned,const char*> get_duplicate();
+
int g_ptxinfo_error_detected;
static char *g_ptxinfo_kname = NULL;
static struct gpgpu_ptx_sim_info g_ptxinfo;
+static std::map<unsigned,const char*> g_duplicate;
+static const char *g_last_dup_type;
const char *get_ptxinfo_kname()
{
@@ -1897,6 +1901,21 @@ struct gpgpu_ptx_sim_info get_ptxinfo()
return g_ptxinfo;
}
+std::map<unsigned,const char*> get_duplicate()
+{
+ return g_duplicate;
+}
+
+void ptxinfo_linenum( unsigned linenum )
+{
+ g_duplicate[linenum] = g_last_dup_type;
+}
+
+void ptxinfo_dup_type( const char *dup_type )
+{
+ g_last_dup_type = dup_type;
+}
+
void ptxinfo_function(const char *fname )
{
clear_ptxinfo();
diff --git a/src/cuda-sim/ptx_loader.cc b/src/cuda-sim/ptx_loader.cc
index f7bf70e..9bb5008 100644
--- a/src/cuda-sim/ptx_loader.cc
+++ b/src/cuda-sim/ptx_loader.cc
@@ -46,6 +46,8 @@ bool g_override_embedded_ptx = false;
extern int ptx_parse();
extern int ptx__scan_string(const char*);
+extern std::map<unsigned,const char*> get_duplicate();
+
const char *g_ptxinfo_filename;
extern int ptxinfo_parse();
extern int ptxinfo_debug;
@@ -182,6 +184,109 @@ symbol_table *gpgpu_ptx_sim_load_ptx_from_string( const char *p, unsigned source
return symtab;
}
+void fix_duplicate_errors(char fname2[1024]) {
+ char tempfile[1024] = "_temp_ptx";
+ char commandline[1024];
+
+ // change the name of the ptx file to _temp_ptx
+ snprintf(commandline,1024,"mv %s %s",fname2,tempfile);
+ printf("Running: %s\n", commandline);
+ int result = system(commandline);
+ if (result != 0) {
+ printf("GPGPU-Sim PTX: ERROR ** while changing filename from %s to %s", fname2, tempfile);
+ exit(1);
+ }
+
+ // store all of the ptx into a char array
+ FILE *ptxsource = fopen(tempfile,"r");
+ fseek(ptxsource, 0, SEEK_END);
+ long filesize = ftell(ptxsource);
+ rewind(ptxsource);
+ char *ptxdata = (char*)malloc((filesize+1)*sizeof(char));
+ fread(ptxdata, filesize, 1, ptxsource);
+ fclose(ptxsource);
+
+ FILE *ptxdest = fopen(fname2,"w");
+ std::map<unsigned,const char*> duplicate = get_duplicate();
+ unsigned offset;
+ unsigned oldlinenum = 1;
+ unsigned linenum;
+ char *startptr = ptxdata;
+ char *funcptr;
+ char *tempptr = ptxdata - 1;
+ char *lineptr = ptxdata - 1;
+
+ // recreate the ptx file without duplications
+ for ( std::map<unsigned,const char*>::iterator iter = duplicate.begin();
+ iter != duplicate.end();
+ iter++){
+ // find the line of the next error
+ linenum = iter->first;
+ for (int i = oldlinenum; i < linenum; i++) {
+ lineptr = strchr(lineptr + 1, '\n');
+ }
+
+ // find the end of the current section to be copied over
+ // then find the start of the next section that will be copied
+ if (strcmp("function", iter->second) == 0) {
+ // get location of most recent .func
+ while (tempptr < lineptr && tempptr != NULL) {
+ funcptr = tempptr;
+ tempptr = strstr(funcptr + 1, ".func");
+ }
+
+ // get the start of the previous line
+ offset = 0;
+ while (*(funcptr - offset) != '\n') offset++;
+
+ fwrite(startptr, sizeof(char), funcptr - offset + 1 - startptr, ptxdest);
+
+ //find next location of startptr
+ if (*(lineptr + 3) == ';') {
+ // for function definitions
+ startptr = lineptr + 5;
+ } else if (*(lineptr + 3) == '{') {
+ // for functions enclosed with curly brackets
+ offset = 5;
+ unsigned bracket = 1;
+ while (bracket != 0) {
+ if (*(lineptr + offset) == '{') bracket++;
+ else if (*(lineptr + offset) == '}') bracket--;
+ offset++;
+ }
+ startptr = lineptr + offset + 1;
+ } else {
+ printf("GPGPU-Sim PTX: ERROR ** Unrecognized function format\n");
+ abort();
+ }
+ } else if (strcmp("variable", iter->second) == 0) {
+ fwrite(startptr, sizeof(char), (int)(lineptr + 1 - startptr), ptxdest);
+
+ //find next location of startptr
+ offset = 1;
+ while (*(lineptr + offset) != '\n') offset++;
+ startptr = lineptr + offset + 1;
+ } else {
+ printf("GPGPU-Sim PTX: ERROR ** Unsupported duplicate type: %s\n", iter->second);
+ }
+
+ oldlinenum = linenum;
+ }
+ // copy over the rest of the file
+ fwrite(startptr, sizeof(char), ptxdata + filesize - startptr, ptxdest);
+
+ // cleanup
+ free(ptxdata);
+ fclose(ptxdest);
+ snprintf(commandline,1024,"rm -f %s",tempfile);
+ printf("Running: %s\n", commandline);
+ result = system(commandline);
+ if (result != 0) {
+ printf("GPGPU-Sim PTX: ERROR ** while deleting %s", tempfile);
+ exit(1);
+ }
+}
+
void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num, unsigned sm_version )
{
char fname[1024];
@@ -225,14 +330,29 @@ void gpgpu_ptxinfo_load_from_string( const char *p_for_info, unsigned source_num
printf("GPGPU-Sim PTX: generating ptxinfo using \"%s\"\n", commandline);
result = system(commandline);
if( result != 0 ) {
- printf("GPGPU-Sim PTX: ERROR ** while loading PTX (b) %d\n", result);
- printf(" Ensure ptxas is in your path.\n");
- exit(1);
+ // 65280 = duplicate errors
+ if (result == 65280) {
+ ptxinfo_in = fopen(tempfile_ptxinfo,"r");
+ g_ptxinfo_filename = tempfile_ptxinfo;
+ ptxinfo_parse();
+
+ fix_duplicate_errors(fname2);
+ snprintf(commandline,1024,"$CUDA_INSTALL_PATH/bin/ptxas %s -v %s --output-file /dev/null 2> %s",
+ extra_flags, fname2, tempfile_ptxinfo);
+ printf("GPGPU-Sim PTX: regenerating ptxinfo using \"%s\"\n", commandline);
+ result = system(commandline);
+ }
+ if (result != 0) {
+ printf("GPGPU-Sim PTX: ERROR ** while loading PTX (b) %d\n", result);
+ printf(" Ensure ptxas is in your path.\n");
+ exit(1);
+ }
}
ptxinfo_in = fopen(tempfile_ptxinfo,"r");
g_ptxinfo_filename = tempfile_ptxinfo;
ptxinfo_parse();
+
if( ! g_save_embedded_ptx ) {
snprintf(commandline,1024,"rm -f %s %s %s", fname, fname2, tempfile_ptxinfo);
printf("GPGPU-Sim PTX: removing ptxinfo using \"%s\"\n", commandline);
diff --git a/src/cuda-sim/ptxinfo.l b/src/cuda-sim/ptxinfo.l
index f9b6846..33c2748 100644
--- a/src/cuda-sim/ptxinfo.l
+++ b/src/cuda-sim/ptxinfo.l
@@ -60,6 +60,10 @@ unsigned ptxinfo_col = 0;
"line" TC; return LINE;
"for" TC; return FOR;
"textures" TC; return TEXTURES;
+"error : Duplicate definition of" TC; return DUPLICATE;
+"function" TC; ptxinfo_lval.string_value = strdup(yytext); return FUNCTION;
+"variable" TC; ptxinfo_lval.string_value = strdup(yytext); return VARIABLE;
+"fatal : Ptx assembly aborted due to errors" TC; return FATAL;
[_A-Za-z$%][_0-9A-Za-z$]* TC; ptxinfo_lval.string_value = strdup(yytext); return IDENTIFIER;
[-]{0,1}[0-9]+ TC; ptxinfo_lval.int_value = atoi(yytext); return INT_OPERAND;
diff --git a/src/cuda-sim/ptxinfo.y b/src/cuda-sim/ptxinfo.y
index faa33eb..37092f4 100644
--- a/src/cuda-sim/ptxinfo.y
+++ b/src/cuda-sim/ptxinfo.y
@@ -55,11 +55,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
%token <string_value> WARNING
%token FOR
%token TEXTURES
+%token DUPLICATE
+%token <string_value> FUNCTION
+%token <string_value> VARIABLE
+%token FATAL
%{
#include <stdlib.h>
#include <string.h>
-
+
static unsigned g_declared;
static unsigned g_system;
int ptxinfo_lex(void);
@@ -71,6 +75,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
void ptxinfo_smem( unsigned declared, unsigned system );
void ptxinfo_cmem( unsigned nbytes, unsigned bank );
int ptxinfo_error(const char*);
+ void ptxinfo_linenum( unsigned );
+ void ptxinfo_dup_type( const char* );
%}
%%
@@ -82,6 +88,8 @@ 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); }
+ | HEADER IDENTIFIER COMMA LINE INT_OPERAND SEMICOLON DUPLICATE duplicate { ptxinfo_linenum($5); }
+ | HEADER FATAL
;
line_info: function_name
@@ -89,7 +97,7 @@ line_info: function_name
;
function_name: FUNC QUOTE IDENTIFIER QUOTE { ptxinfo_function($3); }
- | FUNC QUOTE IDENTIFIER QUOTE FOR QUOTE IDENTIFIER QUOTE {ptxinfo_function($3); }
+ | FUNC QUOTE IDENTIFIER QUOTE FOR QUOTE IDENTIFIER QUOTE { ptxinfo_function($3); }
;
function_info: info
@@ -110,6 +118,10 @@ info: USED INT_OPERAND REGS { ptxinfo_regs($2); }
tuple: INT_OPERAND PLUS INT_OPERAND BYTES { g_declared=$1; g_system=$3; }
+duplicate: FUNCTION QUOTE IDENTIFIER QUOTE { ptxinfo_dup_type($1); }
+ | VARIABLE QUOTE IDENTIFIER QUOTE { ptxinfo_dup_type($1); }
+ ;
+
%%