Skip to content

Commit

Permalink
Issue 30: Ignore not-supported sm_* error without --verify
Browse files Browse the repository at this point in the history
	* 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.
  • Loading branch information
tob2 committed Mar 3, 2022
1 parent d0524fb commit 0a1bdb5
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions nvptx-as.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@

#define DIR_UP ".."

/* The following ptx message is no error, unless --verify has been specified.
To be used when a sm_ has been specified which the installed ptxas does
not support. */
#define PTXAS_IGNORE_ERR "is not defined for option 'gpu-name'"

static const char *outname = NULL;

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

int
collect_wait (const char *prog, struct pex_obj *pex)
collect_wait (const char *prog, struct pex_obj *pex, int force)
{
int status;

if (!pex_get_status (pex, 1, &status))
fatal_error ("can't get program status: %m");
if (!force)
{
FILE *in = pex_read_err (pex, 0);
char buffer[1024];
size_t n = fread(buffer, sizeof(char), 1024, in);
if (n && memmem (buffer, n, PTXAS_IGNORE_ERR, strlen (PTXAS_IGNORE_ERR)))
return 0;
while (n)
{
fwrite(buffer, sizeof(char), n, stderr);
n = fread(buffer, sizeof(char), 1024, in);
}
}
pex_free (pex);

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

static void
do_wait (const char *prog, struct pex_obj *pex)
do_wait (const char *prog, struct pex_obj *pex, int force)
{
int ret = collect_wait (prog, pex);
int ret = collect_wait (prog, pex, force);
if (ret != 0)
{
fatal_error ("%s returned %d exit status", prog, ret);
Expand All @@ -984,16 +1002,18 @@ do_wait (const char *prog, struct pex_obj *pex)

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

int err;
const char *errmsg;

errmsg = pex_run (pex, PEX_LAST | PEX_SEARCH, argv[0], argv, NULL,
int flags = PEX_LAST | PEX_SEARCH;
if (!force)
flags |= PEX_STDERR_TO_PIPE;
errmsg = pex_run (pex, flags, argv[0], argv, NULL,
NULL, &err);
if (errmsg != NULL)
{
Expand All @@ -1005,7 +1025,7 @@ fork_execute (const char *prog, char *const *argv)
else
fatal_error ("%s", errmsg);
}
do_wait (prog, pex);
do_wait (prog, pex, force);
}

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

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

0 comments on commit 0a1bdb5

Please sign in to comment.