Repository: spack/spack

Issue:
Installation issue: gcc
I'd like to build a GCC Spack package with OpenMP offloading support on Arm, but build fails.

```

$ spack install gcc@10.2.0+nvptx
==> Warning: Missing a source id for cuda@11.0.194
==> cuda@11.0.194 : externally installed in /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/cuda-11.0.2-noc4cl3o64limk22u73ixlsnf7h6er3l
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/cuda-11.0.2-noc4cl3o64limk22u73ixlsnf7h6er3l
==> autoconf@2.69 : externally installed in /usr
[+] /usr
==> automake@1.16.1 : externally installed in /usr
[+] /usr
==> libtool@2.4.6 : externally installed in /usr
[+] /usr
==> m4@1.4.18 : externally installed in /usr
[+] /usr
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/autoconf-archive-2019.01.06-arg5vbqxzjm2z7lyb5ugq5sgthym6war
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/zlib-1.2.11-g2qi3vharhazw3gny4qctrmutalr2i4m
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/gmp-6.1.2-cbrqvt3voio7zog75xwjtzvhymsczopt
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/zstd-1.4.5-yzcse6wxkurko7xy5wlakofsqlmxy6cn
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/mpfr-4.0.2-bc42mhxphj4zjp6ze5wd2hx2aquakexi
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/isl-0.21-xrj2pnuix2eud6idfxwyptpir4464ceg
[+] /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.1/mpc-1.1.0-jrmhvodgan3g7ftnsa6nl2czr3w7ynls
==> Installing gcc
==> No binary for gcc found: installing from source
==> Using cached archive: /home/users/itaru.kitayama/projects/spack/var/spack/cache/_source-cache/archive/b8/b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c.tar.xz
==> Using cached archive: /home/users/itaru.kitayama/projects/spack/var/spack/cache/_source-cache/git//MentorEmbedded/nvptx-tools/5f6f343a302d620b0868edab376c00b15741e39e.tar.gz
==> Using cached archive: /home/users/itaru.kitayama/projects/spack/var/spack/cache/_source-cache/archive/3a/3ad3664f227357df15ff34e954bfd9f501009a647667cd307bf0658aefd6eb5b.tar.gz
==> Warning: Fetching from mirror without a checksum!
  This package is normally checked out from a version control system, but it has been archived on a spack mirror.  This means we cannot know a checksum for the tarball in advance. Be sure that your connection to this mirror is secure!
==> Moving resource stage
	source : /tmp/itaru.kitayama/spack-stage/resource-nvptx-tools-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/
	destination : /tmp/itaru.kitayama/spack-stage/spack-stage-gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/nvptx-tools
==> Moving resource stage
	source : /tmp/itaru.kitayama/spack-stage/resource-newlib-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/
	destination : /tmp/itaru.kitayama/spack-stage/spack-stage-gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/newlibsource/newlib-3.0.0.20180831
==> gcc: Executing phase: 'autoreconf'
==> gcc: Executing phase: 'configure'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j16'

3 errors found in build log:
     85      checking for strings.h... yes
     86      checking for inttypes.h... yes
     87      checking for stdint.h... yes
     88      checking for unistd.h... yes
     89      checking whether byte ordering is bigendian... no
     90      checking for a BSD-compatible install... /usr/bin/install -c
  >> 91      /bin/sh: ./../move-if-change: No such file or directory
     92      checking for sys/file.h... yes
     93      checking for sys/param.h... yes
     94      checking for limits.h... yes
     95      checking for stdlib.h... (cached) yes
     96      checking for malloc.h... yes
     97      checking for string.h... (cached) yes

     ...

     5268    checking for nvptx-none-lipo... nvptx-none-lipo
     5269    checking for nvptx-none-nm... /tmp/itaru.kitayama/spack-stage/spack-stage-gcc-10.2.0
             -lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/spack-build-nvptx/./gcc/nm
     5270    checking for nvptx-none-ranlib... /home/users/itaru.kitayama/projects/spack/opt/spac
             k/linux-centos8-thunderx2/gcc-8.3.1/gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/nvpt
             x-none/bin/ranlib
     5271    checking for nvptx-none-strip... nvptx-none-strip
     5272    checking whether ln -s works... yes
     5273    checking for nvptx-none-gcc... /tmp/itaru.kitayama/spack-stage/spack-stage-gcc-10.2.
             0-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/spack-build-nvptx/./gcc/xgcc -B/tmp/ita
             ru.kitayama/spack-stage/spack-stage-gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/spac
             k-src/spack-build-nvptx/./gcc/ -nostdinc -B/tmp/itaru.kitayama/spack-stage/spack-sta
             ge-gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/spack-build-nvptx/nvptx-non
             e/newlib/ -isystem /tmp/itaru.kitayama/spack-stage/spack-stage-gcc-10.2.0-lliylnvoao
             tjpz3dibxbvn4de2lutcsu/spack-src/spack-build-nvptx/nvptx-none/newlib/targ-include -i
             system /tmp/itaru.kitayama/spack-stage/spack-stage-gcc-10.2.0-lliylnvoaotjpz3dibxbvn
             4de2lutcsu/spack-src/newlib/libc/include -B/home/users/itaru.kitayama/projects/spack
             /opt/spack/linux-centos8-thunderx2/gcc-8.3.1/gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lu
             tcsu/nvptx-none/bin/ -B/home/users/itaru.kitayama/projects/spack/opt/spack/linux-cen
             tos8-thunderx2/gcc-8.3.1/gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/nvptx-none/lib/
              -isystem /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx
             2/gcc-8.3.1/gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/nvptx-none/include -isystem
             /home/users/itaru.kitayama/projects/spack/opt/spack/linux-centos8-thunderx2/gcc-8.3.
             1/gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/nvptx-none/sys-include
  >> 5274    checking for suffix of object files... configure: error: in `/tmp/itaru.kitayama/spa
             ck-stage/spack-stage-gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-src/spack-bui
             ld-nvptx/nvptx-none/libgcc':
  >> 5275    configure: error: cannot compute suffix of object files: cannot compile
     5276    See `config.log' for more details
     5277    make[1]: *** [Makefile:11947: configure-target-libgcc] Error 1
     5278    make[1]: *** Waiting for unfinished jobs....
     5279    mv -f .deps/connection.Tpo .deps/connection.Plo
     5280    mv -f .deps/findcomp.Tpo .deps/findcomp.Plo
     5281    mv -f .deps/libcc1.Tpo .deps/libcc1.Plo

See build log for details:
  /tmp/itaru.kitayama/spack-stage/spack-stage-gcc-10.2.0-lliylnvoaotjpz3dibxbvn4de2lutcsu/spack-build-out.txt
```



Discussion:
@michaelkuhn 
It looks like GCC is not compatible with newer versions of CUDA. Could you give #19267 a try?

You will probably also need #18449.
Is the gcc package written so that it self-checks whether its version is
accepted by CUDA Toolkit?

On Mon, Oct 12, 2020 at 10:55 PM Michael Kuhn <notifications@github.com>
wrote:

> It looks like GCC is not compatible with newer versions of CUDA. Could you
> give #19267 <https://github.com/spack/spack/pull/19267> a try?
>
> You will probably also need #18449
> <https://github.com/spack/spack/pull/18449>.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/spack/spack/issues/19255#issuecomment-707135777>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAHLBZ6DWIJ3VB7IMSSXCTTSKMDGLANCNFSM4SLOYQTQ>
> .
>

I'd like the possible combinations of `spack install` so that I can get GCC
with OpenMP offloading support to the CUDA device.

On Tue, Oct 13, 2020 at 9:19 AM Itaru Kitayama <itaru.kitayama@gmail.com>
wrote:

> Is the gcc package written so that it self-checks whether its version is
> accepted by CUDA Toolkit?
>
> On Mon, Oct 12, 2020 at 10:55 PM Michael Kuhn <notifications@github.com>
> wrote:
>
>> It looks like GCC is not compatible with newer versions of CUDA. Could
>> you give #19267 <https://github.com/spack/spack/pull/19267> a try?
>>
>> You will probably also need #18449
>> <https://github.com/spack/spack/pull/18449>.
>>
>> —
>> You are receiving this because you authored the thread.
>> Reply to this email directly, view it on GitHub
>> <https://github.com/spack/spack/issues/19255#issuecomment-707135777>, or
>> unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AAHLBZ6DWIJ3VB7IMSSXCTTSKMDGLANCNFSM4SLOYQTQ>
>> .
>>
>

Now that #19267 has been merged, it should be enough to manually apply #18449 and do a `spack install gcc+nvptx`.
Then could you merge #18449 as well to develop it is much easier for me.

On Tue, Oct 13, 2020 at 4:49 PM Michael Kuhn <notifications@github.com> wrote:
>
> Now that #19267 has been merged, it should be enough to manually apply #18449 and do a spack install gcc+nvptx.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub, or unsubscribe.

That PR is still under discussion/review, so you will have to apply it manually for now.
@michaelkuhn OK. I think this Spack navigated GCC build with CUDA Toolkit is much, much easier than manually building. I will watch the progress there and once done, I will try it and close. OK?

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py
--- a/var/spack/repos/builtin/packages/gcc/package.py
+++ b/var/spack/repos/builtin/packages/gcc/package.py
@@ -128,7 +128,7 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage):
     depends_on('gnat', when='languages=ada')
     depends_on('binutils+ld+plugins~libiberty', when='+binutils', type=('build', 'link', 'run'))
     depends_on('zip', type='build', when='languages=java')
-    depends_on('cuda@:10', when='+nvptx')
+    depends_on('cuda', when='+nvptx')
 
     # The server is sometimes a bit slow to respond
     timeout = {'timeout': 60}
@@ -145,7 +145,7 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage):
     # nvptx-tools doesn't have any releases, so grabbing the last commit
     resource(name='nvptx-tools',
              git='https://github.com/MentorEmbedded/nvptx-tools',
-             commit='5f6f343a302d620b0868edab376c00b15741e39e',
+             commit='d0524fbdc86dfca068db5a21cc78ac255b335be5',
              when='+nvptx')
 
     # TODO: integrate these libraries.
@@ -442,6 +442,19 @@ def patch(self):
                         '-I{0}'.format(spec['zlib'].prefix.include),
                         'gcc/Makefile.in')
 
+        if spec.satisfies('+nvptx'):
+            # backport of 383400a6078d upstream to allow support of cuda@11:
+            filter_file('#define ASM_SPEC "%{misa=*:-m %*}"',
+                        '#define ASM_SPEC "%{misa=*:-m %*; :-m sm_35}"',
+                        'gcc/config/nvptx/nvptx.h',
+                        string=True)
+            filter_file('Target RejectNegative ToLower Joined '
+                        'Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM30)',
+                        'Target RejectNegative ToLower Joined '
+                        'Enum(ptx_isa) Var(ptx_isa_option) Init(PTX_ISA_SM35)',
+                        'gcc/config/nvptx/nvptx.opt',
+                        string=True)
+
     # https://gcc.gnu.org/install/configure.html
     def configure_args(self):
         spec = self.spec
diff --git a/var/spack/repos/builtin/packages/nvptx-tools/package.py b/var/spack/repos/builtin/packages/nvptx-tools/package.py
--- a/var/spack/repos/builtin/packages/nvptx-tools/package.py
+++ b/var/spack/repos/builtin/packages/nvptx-tools/package.py
@@ -15,6 +15,7 @@ class NvptxTools(AutotoolsPackage):
     homepage = "https://github.com/MentorEmbedded/nvptx-tools"
     git      = "https://github.com/MentorEmbedded/nvptx-tools"
 
+    version('2021-05-21', commit='d0524fbdc86dfca068db5a21cc78ac255b335be5')
     version('2018-03-01', commit='5f6f343a302d620b0868edab376c00b15741e39e')
 
     depends_on('binutils')


Test patch: