chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.79k stars 421 forks source link

Using `CHPL_GPU=cpu` with the gnu compiler gives an attribute warning #23837

Closed ShreyasKhandekar closed 11 months ago

ShreyasKhandekar commented 12 months ago

Summary of Problem

Using CHPL_GPU=cpu with the gnu compiler gives us a few instances of the following warning:

../include/chpl-gpu.h: In function ‘CHPL_GPU_DEBUG’:
../include/chpl-gpu.h:49:5: error: function ‘CHPL_GPU_DEBUG’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
     vfprintf(stdout, str, args);

This warning is raised to an error when using CHPL_DEVELOPER causing a build failure.

Steps to Reproduce

Build failure. No code needed. Just reproduce environment and make

Configuration Information

warning: The prototype GPU support implies --no-checks. This may impact debuggability. To suppress this warning, compile with --no-checks explicitly
chpl version 1.33.0 pre-release (30cf2617a4)
Copyright 2020-2023 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)
CHPL_TARGET_PLATFORM: linux64
CHPL_TARGET_COMPILER: gnu
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: gpu *
  CHPL_GPU: cpu *
CHPL_COMM: none *
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: bundled
CHPL_HWLOC: bundled
CHPL_RE2: bundled
CHPL_LLVM: none *
CHPL_AUX_FILESYS: none
gcc (SUSE Linux) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Since there is only once place where this warning is raised, we could do what the error suggests. Another option would be to squash this particular error.

mppf commented 12 months ago

In the C++ frontend we have e.g. __attribute__ ((format (printf, 3, 4))) on a number of functions. I'm not sure if this is non-standard or non-portable or C++ only. But, I think getting the C compiler's format string checking helps a lot.

ShreyasKhandekar commented 12 months ago

A quick docs search shows that it seems gcc has had these attributes since 3.1 and the list of supported attributes has grown since. https://gcc.gnu.org/onlinedocs/gcc-7.5.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes

e-kayrakli commented 12 months ago

I added one of those attributes relatively recently without any issues. So, we should just go ahead and add it. As long as we can build the runtime for CHPL_GPU={nvidia,amd}, I don't think we need to worry about its portability, given that none of the instances in the runtime has any checks for being portable.

We probably haven't come across this so far, because we (at least me) still use the LLVM backend with the cpu-as-device mode.