Skip to content

Commit 0a1bdb5

Browse files
committed
Issue 30: Ignore not-supported sm_* error without --verify
* nvptx-as.c (PTXAS_IGNORE_ERR): Define. (collect_wait, do_wait, fork_execute, main): Unless --verify is used, don't error when the ptxas error message contains PTXAS_IGNORE_ERR.
1 parent d0524fb commit 0a1bdb5

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

nvptx-as.c

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979

8080
#define DIR_UP ".."
8181

82+
/* The following ptx message is no error, unless --verify has been specified.
83+
To be used when a sm_ has been specified which the installed ptxas does
84+
not support. */
85+
#define PTXAS_IGNORE_ERR "is not defined for option 'gpu-name'"
86+
8287
static const char *outname = NULL;
8388

8489
static void __attribute__ ((format (printf, 1, 2)))
@@ -947,12 +952,25 @@ process (FILE *in, FILE *out, int *verify, const char *inname)
947952
/* Wait for a process to finish, and exit if a nonzero status is found. */
948953

949954
int
950-
collect_wait (const char *prog, struct pex_obj *pex)
955+
collect_wait (const char *prog, struct pex_obj *pex, int force)
951956
{
952957
int status;
953958

954959
if (!pex_get_status (pex, 1, &status))
955960
fatal_error ("can't get program status: %m");
961+
if (!force)
962+
{
963+
FILE *in = pex_read_err (pex, 0);
964+
char buffer[1024];
965+
size_t n = fread(buffer, sizeof(char), 1024, in);
966+
if (n && memmem (buffer, n, PTXAS_IGNORE_ERR, strlen (PTXAS_IGNORE_ERR)))
967+
return 0;
968+
while (n)
969+
{
970+
fwrite(buffer, sizeof(char), n, stderr);
971+
n = fread(buffer, sizeof(char), 1024, in);
972+
}
973+
}
956974
pex_free (pex);
957975

958976
if (status)
@@ -972,9 +990,9 @@ collect_wait (const char *prog, struct pex_obj *pex)
972990
}
973991

974992
static void
975-
do_wait (const char *prog, struct pex_obj *pex)
993+
do_wait (const char *prog, struct pex_obj *pex, int force)
976994
{
977-
int ret = collect_wait (prog, pex);
995+
int ret = collect_wait (prog, pex, force);
978996
if (ret != 0)
979997
{
980998
fatal_error ("%s returned %d exit status", prog, ret);
@@ -984,16 +1002,18 @@ do_wait (const char *prog, struct pex_obj *pex)
9841002

9851003
/* Execute a program, and wait for the reply. */
9861004
static void
987-
fork_execute (const char *prog, char *const *argv)
1005+
fork_execute (const char *prog, char *const *argv, int force)
9881006
{
9891007
struct pex_obj *pex = pex_init (0, "nvptx-as", NULL);
9901008
if (pex == NULL)
9911009
fatal_error ("pex_init failed: %m");
9921010

9931011
int err;
9941012
const char *errmsg;
995-
996-
errmsg = pex_run (pex, PEX_LAST | PEX_SEARCH, argv[0], argv, NULL,
1013+
int flags = PEX_LAST | PEX_SEARCH;
1014+
if (!force)
1015+
flags |= PEX_STDERR_TO_PIPE;
1016+
errmsg = pex_run (pex, flags, argv[0], argv, NULL,
9971017
NULL, &err);
9981018
if (errmsg != NULL)
9991019
{
@@ -1005,7 +1025,7 @@ fork_execute (const char *prog, char *const *argv)
10051025
else
10061026
fatal_error ("%s", errmsg);
10071027
}
1008-
do_wait (prog, pex);
1028+
do_wait (prog, pex, force);
10091029
}
10101030

10111031
/* Determine if progname is available in PATH. */
@@ -1186,10 +1206,10 @@ This program has absolutely no warranty.\n",
11861206
/* We don't have a PTX file for 'ptxas' to read in; skip verification. */
11871207
verify = 0;
11881208
else if (verify == -1)
1189-
if (program_available ("ptxas"))
1190-
verify = 1;
1209+
if (!program_available ("ptxas"))
1210+
verify = 0;
11911211

1192-
if (verify > 0)
1212+
if (verify != 0)
11931213
{
11941214
/* We override the default '--gpu-name' of 'ptxas': its default may not
11951215
be sufficient for what is requested in the '.target' directive in the
@@ -1217,7 +1237,7 @@ This program has absolutely no warranty.\n",
12171237
obstack_ptr_grow (&argv_obstack, "-O0");
12181238
obstack_ptr_grow (&argv_obstack, NULL);
12191239
char *const *new_argv = XOBFINISH (&argv_obstack, char *const *);
1220-
fork_execute (new_argv[0], new_argv);
1240+
fork_execute (new_argv[0], new_argv, verify > 0);
12211241
}
12221242
return 0;
12231243
}

0 commit comments

Comments
 (0)