[PATCH] nvptx: Add a __PTX_ISA__ predefined macro based on target ISA.

Tom de Vries tdevries@suse.de
Tue Aug 24 16:01:20 GMT 2021


On 8/20/21 12:54 AM, Roger Sayle wrote:
> 
> This patch adds a __PTX_ISA__ predefined macro to the nvptx backend that
> allows code to check the compute model being targeted by the compiler.

Hi Roger,

The naming __PTX_ISA__ is consistent with the naming of -misa=sm_30/sm_35.

The -misa=sm_30/sm_35 naming was very unfortunate given that the ptx
format actually defines an ISA version which gcc now accepts using
-mptx=3.1/6.3.

We really should have had something like:
- -march=sm_30/sm_35
- -mptx-isa=3.1/6.3
but I suppose it's too late to change that now.

Having said that, the __PTX_ISA__ name very much suggests that it's the
ptx ISA version, which, as explained above, it's not.  Sigh.

We could go for __PTX_ARCH__ instead, but it would be very
counterintuitive to have -misa=sm_30/sm_35 set this.

So I propose __PTX_SM__ instead.  [ I also considered __PTX_ISA_SM__ but
if we ever decide to change the name of the switch then that doesn't
make sense anymore. ]

> This is equivalent to the __CUDA_ARCH__ macro defined by CUDA's nvcc
> compiler, but to avoid causing problems for source code that checks
> for that compiler, this macro uses GCC's nomenclature; it's easy
> enough for users to "#define __CUDA_ARCH__ __PTX_ISA__", but I'm
> also happy to modify this patch to define __CUDA_ARCH__ if that's
> the preference of the nvptx backend maintainers.
> 

I agree with this approach.  The definition of the __CUDA_ARCH__ macro
in the cuda documentation is nvcc-specific, so let's not define it.

> What might have been a four line patch is actually a little more
> complicated, as this patch takes the opportunity to upgrade the
> nvptx backend to use the now preferred nvptx-c.c idiom.
> 

Ack.  You could split it up, but not strictly necessary.

> This patch has been tested with a cross-compiler from
> x86_64-pc-linux-gnu to nvptx-none, and tested with
> "make -k check" with no new failures.  This feature is
> useful for implementing clock() on nvptx in newlib.
> 

I see, thanks for working on that.

> Ok for mainline?

OK with name of predefined macro updated to __PTX_SM__ .

Thanks,
- Tom

> 2021-08-19  Roger Sayle  <roger@nextmovesoftware.com>
> 
> gcc/ChangeLog
> 	* config.gcc (nvptx-*-*): Define {c,c++}_target_objs.
> 	* config/nvptx/nvptx-protos.h (nvptx_cpu_cpp_builtins): Prototype.
> 	* config/nvptx/nvptx.h (TARGET_CPU_CPP_BUILTINS): Implement with
> 	a call to the new nvptx_cpu_cpp_builtins function in nvptx-c.c.
> 	* config/nvptx/t-nvptx (nvptx-c.o): New rule.
> 	* config/nvptx/nvptx-c.c: New source file.
> 	(nvptx_cpu_cpp_builtins): Move implementation here.
> 
> Roger
> --
> Roger Sayle
> NextMove Software
> Cambridge, UK
> 


More information about the Gcc-patches mailing list