This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On Sat, 9 May 2015 10:26:22 -0700, Satoshi_OHSHIMA <> wrote:
> I'm trying to use and evaluate gcc with OpenACC on some NVIDIA GPUs.
> I succeeded to build gcc with OpenACC by using
> as a reference.

Heh, their build instructions very much look like the ones I provided in
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/,
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
    	* 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/ (atomic_fetch_<logic><mode>): Enable with the
    	correct predicate.
    	* config/nvptx/nvptx.opt (ptx_isa, sm_30, sm_35): New enum and its
    	(misa=): New option.
    git-svn-id: svn+ssh:// 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/     |  3 +--
 gcc/config/nvptx/nvptx.opt    | 14 ++++++++++++++
 6 files changed, 71 insertions(+), 3 deletions(-)

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  <>
+	* 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/ (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  <>
 	* 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 <>
+   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
+   <>.  */
+#ifndef NVPTX_OPTS_H
+#define NVPTX_OPTS_H
+enum ptx_isa
+  PTX_ISA_SM30,
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 ("\\tsm_30\n", asm_out_file);
+  if (TARGET_SM35)
+    fputs ("\\tsm_35\n", asm_out_file);
+  else
+    fputs ("\\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"
 /* Run-time Target.  */
 #define STARTFILE_SPEC "%{mmainkernel:crt0.o}"
+#define ASM_SPEC "%{misa=*:-m %*}"
   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/ gcc/config/nvptx/
index 48f9acf..f5b1a20 100644
--- gcc/config/nvptx/
+++ gcc/config/nvptx/
@@ -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")
@@ -1424,5 +1423,5 @@
    (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
 Target Report RejectNegative
 Link in code for a __main kernel.
+Name(ptx_isa) Type(int)
+Known PTX ISA versions (for use with the -misa= option):
+Enum(ptx_isa) String(sm_30) Value(PTX_ISA_SM30)
+Enum(ptx_isa) String(sm_35) Value(PTX_ISA_SM35)
+Target RejectNegative ToLower Joined Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)
+Specify the version of the ptx ISA to use


Attachment: pgpsqZoD4isAp.pgp
Description: PGP signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]