[nvptx] Choose -mptx default based on -misa

While testing with driver version 390.147 I ran into the problem that it
doesn't support ptx isa version 6.3 (the new default), only 6.1.

Furthermore, using the -mptx option is a bit user-unfriendly.

Say we want to compile for sm_80.  We can use -misa=sm_80 to specify that, but
then run into errors because the default ptx version is 6.3, which doesn't
support sm_80 yet.

Address both these issues by:
- picking a default -mptx based on the active -misa, and
- ensuring that the default -mptx is at least 6.0 (instead
  of 6.3).

Also add an error in case of incompatible options like
"-misa=sm_80 -mptx=6.3":
...
cc1: error: PTX version (-mptx) needs to be at least 7.0 to support \
  selected -misa (sm_80)
...

Tested on x86_64-linux with nvptx accelerator.

gcc/ChangeLog:

2022-02-08  Tom de Vries  <tdevries@suse.de>

	PR target/104283
	* config/nvptx/nvptx-opts.h (enum ptx_version): Add PTX_VERSION_3_0
	and PTX_VERSION_4_2.
	* config/nvptx/nvptx.cc (first_ptx_version_supporting_sm)
	(default_ptx_version_option, ptx_version_to_string)
	(sm_version_to_string, handle_ptx_version_option): New function.
	(nvptx_option_override): Call handle_ptx_version_option.
	(nvptx_file_start): Use ptx_version_to_string and sm_version_to_string.
	* config/nvptx/nvptx.md (define_insn "nvptx_shuffle<mode>")
	(define_insn "nvptx_vote_ballot"): Use TARGET_PTX_6_0.
	* config/nvptx/nvptx.opt (mptx): Remove 'Init'.
This commit is contained in:
Tom de Vries 2022-02-04 08:53:52 +01:00
parent 6de582dd62
commit decde11183
4 changed files with 122 additions and 19 deletions

View file

@ -31,7 +31,9 @@ enum ptx_isa
enum ptx_version
{
PTX_VERSION_3_0,
PTX_VERSION_3_1,
PTX_VERSION_4_2,
PTX_VERSION_6_0,
PTX_VERSION_6_3,
PTX_VERSION_7_0

View file

@ -205,6 +205,109 @@ diagnose_openacc_conflict (bool optval, const char *optname)
error ("option %s is not supported together with %<-fopenacc%>", optname);
}
static enum ptx_version
first_ptx_version_supporting_sm (enum ptx_isa sm)
{
switch (sm)
{
case PTX_ISA_SM30:
return PTX_VERSION_3_0;
case PTX_ISA_SM35:
return PTX_VERSION_3_1;
case PTX_ISA_SM53:
return PTX_VERSION_4_2;
case PTX_ISA_SM75:
return PTX_VERSION_6_3;
case PTX_ISA_SM80:
return PTX_VERSION_7_0;
default:
gcc_unreachable ();
}
}
static enum ptx_version
default_ptx_version_option (void)
{
enum ptx_version first
= first_ptx_version_supporting_sm ((enum ptx_isa) ptx_isa_option);
/* Pick a version that supports the sm. */
enum ptx_version res = first;
/* Pick at least 3.1. This has been the smallest version historically. */
res = MAX (res, PTX_VERSION_3_1);
/* Pick at least 6.0, to enable using bar.warp.sync to have a way to force
warp convergence. */
res = MAX (res, PTX_VERSION_6_0);
/* Verify that we pick a version that supports the sm. */
gcc_assert (first <= res);
return res;
}
static const char *
ptx_version_to_string (enum ptx_version v)
{
switch (v)
{
case PTX_VERSION_3_0:
return "3.0";
case PTX_VERSION_3_1:
return "3.1";
case PTX_VERSION_4_2:
return "4.2";
case PTX_VERSION_6_0:
return "6.0";
case PTX_VERSION_6_3:
return "6.3";
case PTX_VERSION_7_0:
return "7.0";
default:
gcc_unreachable ();
}
}
static const char *
sm_version_to_string (enum ptx_isa sm)
{
switch (sm)
{
case PTX_ISA_SM30:
return "30";
case PTX_ISA_SM35:
return "35";
case PTX_ISA_SM53:
return "53";
case PTX_ISA_SM70:
return "70";
case PTX_ISA_SM75:
return "75";
case PTX_ISA_SM80:
return "80";
default:
gcc_unreachable ();
}
}
static void
handle_ptx_version_option (void)
{
if (!OPTION_SET_P (ptx_version_option))
{
ptx_version_option = default_ptx_version_option ();
return;
}
enum ptx_version first
= first_ptx_version_supporting_sm ((enum ptx_isa) ptx_isa_option);
if (ptx_version_option < first)
error ("PTX version (-mptx) needs to be at least %s to support selected"
" -misa (sm_%s)", ptx_version_to_string (first),
sm_version_to_string ((enum ptx_isa)ptx_isa_option));
}
/* Implement TARGET_OPTION_OVERRIDE. */
static void
@ -212,6 +315,8 @@ nvptx_option_override (void)
{
init_machine_status = nvptx_init_machine_status;
handle_ptx_version_option ();
/* Set toplevel_reorder, unless explicitly disabled. We need
reordering so that we emit necessary assembler decls of
undeclared variables. */
@ -5430,23 +5535,19 @@ static void
nvptx_file_start (void)
{
fputs ("// BEGIN PREAMBLE\n", asm_out_file);
if (TARGET_PTX_7_0)
fputs ("\t.version\t7.0\n", asm_out_file);
else if (TARGET_PTX_6_3)
fputs ("\t.version\t6.3\n", asm_out_file);
else
fputs ("\t.version\t3.1\n", asm_out_file);
if (TARGET_SM80)
fputs ("\t.target\tsm_80\n", asm_out_file);
else if (TARGET_SM75)
fputs ("\t.target\tsm_75\n", asm_out_file);
else if (TARGET_SM53)
fputs ("\t.target\tsm_53\n", asm_out_file);
else if (TARGET_SM35)
fputs ("\t.target\tsm_35\n", asm_out_file);
else
fputs ("\t.target\tsm_30\n", asm_out_file);
fputs ("\t.version\t", asm_out_file);
fputs (ptx_version_to_string ((enum ptx_version)ptx_version_option),
asm_out_file);
fputs ("\n", asm_out_file);
fputs ("\t.target\tsm_", asm_out_file);
fputs (sm_version_to_string ((enum ptx_isa)ptx_isa_option),
asm_out_file);
fputs ("\n", asm_out_file);
fprintf (asm_out_file, "\t.address_size %d\n", GET_MODE_BITSIZE (Pmode));
fputs ("// END PREAMBLE\n", asm_out_file);
}

View file

@ -1603,7 +1603,7 @@
UNSPEC_SHUFFLE))]
""
{
if (TARGET_PTX_6_3)
if (TARGET_PTX_6_0)
return "%.\\tshfl.sync%S3.b32\\t%0, %1, %2, 31, 0xffffffff;";
else
return "%.\\tshfl%S3.b32\\t%0, %1, %2, 31;";
@ -1615,7 +1615,7 @@
UNSPEC_VOTE_BALLOT))]
""
{
if (TARGET_PTX_6_3)
if (TARGET_PTX_6_0)
return "%.\\tvote.sync.ballot.b32\\t%0, %1, 0xffffffff;";
else
return "%.\\tvote.ballot.b32\\t%0, %1;";

View file

@ -89,5 +89,5 @@ EnumValue
Enum(ptx_version) String(7.0) Value(PTX_VERSION_7_0)
mptx=
Target RejectNegative ToLower Joined Enum(ptx_version) Var(ptx_version_option) Init(PTX_VERSION_6_3)
Target RejectNegative ToLower Joined Enum(ptx_version) Var(ptx_version_option)
Specify the version of the ptx version to use.