diff mbox

[gomp4] Basic -misa support for nvptx (was: How to use old GPU (Fermi) in gcc with OpenACC?)

Message ID 87lhgsjhf9.fsf@schwinge.name
State New
Headers show

Commit Message

Thomas Schwinge May 13, 2015, 9:28 p.m. UTC
Hi!

On Sat, 9 May 2015 10:26:22 -0700, Satoshi_OHSHIMA <satoshiohshima@gmail.com> wrote:
> I'm trying to use and evaluate gcc with OpenACC on some NVIDIA GPUs.
> I succeeded to build gcc with OpenACC by using
> http://scelementary.com/2015/04/25/openacc-in-gcc.html as a reference.

Heh, their build instructions very much look like the ones I provided in
<https://gcc.gnu.org/wiki/Offloading#How_to_try_offloading_enabled_GCC>:
trunk-offload-big.tar.bz2, trunk-offload-light.tar.bz2 (no problem with
them reusing these, of course).

> Then, I succeeded to use Kepler GPU.

:-)

> However, I tried to use it on old GPUs (Fermi), and I failed to execute it.
> I noticed that there are some "sm_30" and "COMPUTE_30" keywords in gcc and
> nvptx sources.
> Then, I modified them to "sm_20" and "COMPUTE_20", but I failed to execute
> my programs, too.
> Are there any developers who can make gcc with OpenACC to support other than
> "sm_30"?

"Can", yes, but this is unlikely to happen: a nontrivial amount of work
would be required to get the current code (and, in particular, our
patches under development) working on what nowadays is probably
considered "legacy" hardware.  (For example, if I remember correctly,
didn't Nvidia remove support for Fermi-class hardware from recent CUDA
toolkit releases?)

However, I committed the following patch to gomp-4_0-branch in r223182,
and you're of course very welcome to follow that route, and contribute
patches to properly conditionalize the respective PTX instructions,
provide replacement functions, and so on, in gcc/config/nvptx/nvptx.md,
libgcc/config/nvptx/, and probably other locations.

To use this patch, you'll also need to update your nvptx-tools sources.

commit 29001da9572e094164e1fca440925fafbceb67f2
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed May 13 21:25:42 2015 +0000

    Basic -misa support for nvptx
    
    	gcc/
    	* config/nvptx/nvptx-opts.h: New file.
    	* config/nvptx/nvptx.c (nvptx_file_start): Print the correct .target.
    	* config/nvptx/nvptx.h: Include "nvptx-opts.h".
    	(ASM_SPEC): Define.
    	(TARGET_SM35): New macro.
    	* config/nvptx/nvptx.md (atomic_fetch_<logic><mode>): Enable with the
    	correct predicate.
    	* config/nvptx/nvptx.opt (ptx_isa, sm_30, sm_35): New enum and its
    	values.
    	(misa=): New option.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gomp-4_0-branch@223182 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/ChangeLog.gomp            | 13 +++++++++++++
 gcc/config/nvptx/nvptx-opts.h | 31 +++++++++++++++++++++++++++++++
 gcc/config/nvptx/nvptx.c      |  5 ++++-
 gcc/config/nvptx/nvptx.h      |  8 ++++++++
 gcc/config/nvptx/nvptx.md     |  3 +--
 gcc/config/nvptx/nvptx.opt    | 14 ++++++++++++++
 6 files changed, 71 insertions(+), 3 deletions(-)



Grüße,
 Thomas

Comments

Joseph Myers May 13, 2015, 10:49 p.m. UTC | #1
On Wed, 13 May 2015, Thomas Schwinge wrote:

>     	* config/nvptx/nvptx.opt (ptx_isa, sm_30, sm_35): New enum and its
>     	values.
>     	(misa=): New option.

New options do of course need documenting in invoke.texi.
diff mbox

Patch

diff --git gcc/ChangeLog.gomp gcc/ChangeLog.gomp
index a4683c3..f43f668 100644
--- gcc/ChangeLog.gomp
+++ gcc/ChangeLog.gomp
@@ -1,3 +1,16 @@ 
+2015-05-13  Bernd Schmidt  <bernds@codesourcery.com>
+
+	* config/nvptx/nvptx-opts.h: New file.
+	* config/nvptx/nvptx.c (nvptx_file_start): Print the correct .target.
+	* config/nvptx/nvptx.h: Include "nvptx-opts.h".
+	(ASM_SPEC): Define.
+	(TARGET_SM35): New macro.
+	* config/nvptx/nvptx.md (atomic_fetch_<logic><mode>): Enable with the
+	correct predicate.
+	* config/nvptx/nvptx.opt (ptx_isa, sm_30, sm_35): New enum and its
+	values.
+	(misa=): New option.
+
 2015-05-13  Cesar Philippidis  <cesar@codesourcery.com>
 
 	* except.c (finish_eh_generation): Don't finalize exeception
diff --git gcc/config/nvptx/nvptx-opts.h gcc/config/nvptx/nvptx-opts.h
new file mode 100644
index 0000000..512c37a
--- /dev/null
+++ gcc/config/nvptx/nvptx-opts.h
@@ -0,0 +1,31 @@ 
+/* Definitions for the NVPTX port needed for option handling.
+   Copyright (C) 2015 Free Software Foundation, Inc.
+   Contributed by Bernd Schmidt <bernds@codesourcery.com>
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef NVPTX_OPTS_H
+#define NVPTX_OPTS_H
+
+enum ptx_isa
+{
+  PTX_ISA_SM30,
+  PTX_ISA_SM35
+};
+
+#endif
+
diff --git gcc/config/nvptx/nvptx.c gcc/config/nvptx/nvptx.c
index 10ac976..9bec12f 100644
--- gcc/config/nvptx/nvptx.c
+++ gcc/config/nvptx/nvptx.c
@@ -2048,7 +2048,10 @@  nvptx_file_start (void)
 {
   fputs ("// BEGIN PREAMBLE\n", asm_out_file);
   fputs ("\t.version\t3.1\n", asm_out_file);
-  fputs ("\t.target\tsm_30\n", asm_out_file);
+  if (TARGET_SM35)
+    fputs ("\t.target\tsm_35\n", asm_out_file);
+  else
+    fputs ("\t.target\tsm_30\n", asm_out_file);
   fprintf (asm_out_file, "\t.address_size %d\n", GET_MODE_BITSIZE (Pmode));
   fprintf (asm_out_file, "\t.extern .shared .u8 sdata[];\n");
   fputs ("// END PREAMBLE\n", asm_out_file);
diff --git gcc/config/nvptx/nvptx.h gcc/config/nvptx/nvptx.h
index e4e58dd..c304121 100644
--- gcc/config/nvptx/nvptx.h
+++ gcc/config/nvptx/nvptx.h
@@ -21,10 +21,16 @@ 
 #ifndef GCC_NVPTX_H
 #define GCC_NVPTX_H
 
+#ifndef NVPTX_OPTS_H
+#include "config/nvptx/nvptx-opts.h"
+#endif
+
 /* Run-time Target.  */
 
 #define STARTFILE_SPEC "%{mmainkernel:crt0.o}"
 
+#define ASM_SPEC "%{misa=*:-m %*}"
+
 #define TARGET_CPU_CPP_BUILTINS()		\
   do						\
     {						\
@@ -77,6 +83,8 @@ 
 
 #define Pmode (TARGET_ABI64 ? DImode : SImode)
 
+#define TARGET_SM35 (ptx_isa_option >= PTX_ISA_SM35)
+
 /* Registers.  Since ptx is a virtual target, we just define a few
    hard registers for special purposes and leave pseudos unallocated.  */
 
diff --git gcc/config/nvptx/nvptx.md gcc/config/nvptx/nvptx.md
index 48f9acf..f5b1a20 100644
--- gcc/config/nvptx/nvptx.md
+++ gcc/config/nvptx/nvptx.md
@@ -1414,7 +1414,6 @@ 
 (define_code_iterator any_logic [and ior xor])
 (define_code_attr logic [(and "and") (ior "or") (xor "xor")])
 
-;; Currently disabled until we add better subtarget support - requires sm_32.
 (define_insn "atomic_fetch_<logic><mode>"
   [(set (match_operand:SDIM 1 "memory_operand" "+m")
 	(unspec_volatile:SDIM
@@ -1424,5 +1423,5 @@ 
 	  UNSPECV_LOCK))
    (set (match_operand:SDIM 0 "nvptx_register_operand" "=R")
 	(match_dup 1))]
-  "0"
+  "<MODE>mode == SImode || TARGET_SM35"
   "%.\\tatom%A1.b%T0.<logic>\\t%0, %1, %2;")
diff --git gcc/config/nvptx/nvptx.opt gcc/config/nvptx/nvptx.opt
index 249a61d..9ba050e 100644
--- gcc/config/nvptx/nvptx.opt
+++ gcc/config/nvptx/nvptx.opt
@@ -28,3 +28,17 @@  Generate code for a 64-bit ABI
 mmainkernel
 Target Report RejectNegative
 Link in code for a __main kernel.
+
+Enum
+Name(ptx_isa) Type(int)
+Known PTX ISA versions (for use with the -misa= option):
+
+EnumValue
+Enum(ptx_isa) String(sm_30) Value(PTX_ISA_SM30)
+
+EnumValue
+Enum(ptx_isa) String(sm_35) Value(PTX_ISA_SM35)
+
+misa=
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Specify the version of the ptx ISA to use