Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Driver] Test ignored target-specific options for AMDGPU/NVPTX #79222

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Jan 23, 2024

Fix missing test coverage after #70740 #70760

When compiling for CUDA/HIP, the driver creates a cc1 job to compile for amdgcn/nvptx triple using most options.
Certain target-specific options should be ignored, not lead to an error (err_drv_unsupported_opt_for_target).

Created using spr 1.3.4
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jan 23, 2024
@MaskRay MaskRay requested a review from Artem-B January 23, 2024 23:14
@llvmbot llvmbot added the clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' label Jan 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jan 23, 2024

@llvm/pr-subscribers-clang-driver

Author: Fangrui Song (MaskRay)

Changes

Fix missing test coverage after #70740 #70760


Full diff: https://github.com/llvm/llvm-project/pull/79222.diff

1 Files Affected:

  • (added) clang/test/Driver/unsupported-option-gpu.c (+7)
diff --git a/clang/test/Driver/unsupported-option-gpu.c b/clang/test/Driver/unsupported-option-gpu.c
new file mode 100644
index 000000000000000..5713dbbfc7ae4db
--- /dev/null
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all
+
+// REDEFINE: %{gpu_opts} = -x hip --rocm-path=%S/Inputs/rocm -nogpulib
+// RUN: %{check}

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 23, 2024

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)

Changes

Fix missing test coverage after #70740 #70760


Full diff: https://github.com/llvm/llvm-project/pull/79222.diff

1 Files Affected:

  • (added) clang/test/Driver/unsupported-option-gpu.c (+7)
diff --git a/clang/test/Driver/unsupported-option-gpu.c b/clang/test/Driver/unsupported-option-gpu.c
new file mode 100644
index 000000000000000..5713dbbfc7ae4db
--- /dev/null
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -0,0 +1,7 @@
+/// Some target-specific options are ignored for GPU, so %clang exits with code 0.
+// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
+// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
+// RUN: %{check} -fbasic-block-sections=all
+
+// REDEFINE: %{gpu_opts} = -x hip --rocm-path=%S/Inputs/rocm -nogpulib
+// RUN: %{check}

@@ -0,0 +1,7 @@
/// Some target-specific options are ignored for GPU, so %clang exits with code 0.
// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these defines seem overkill and harder to read compared to just duplicating the command line twice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think gpu_opts can be merged into %{check}. %{check} should be kept as it will become longer soon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purpose of warning checking, we can drop this altogether and use -nogpuinc -nogpulib . Whatever default GPU we end up targeting is also irrelevant.

@@ -0,0 +1,7 @@
/// Some target-specific options are ignored for GPU, so %clang exits with code 0.
// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purpose of warning checking, we can drop this altogether and use -nogpuinc -nogpulib . Whatever default GPU we end up targeting is also irrelevant.

/// Some target-specific options are ignored for GPU, so %clang exits with code 0.
// DEFINE: %{gpu_opts} = --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda --no-cuda-version-check
// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
// RUN: %{check} -fbasic-block-sections=all
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to either rename the file into .cu or use -x cuda. Otherwise you're running a plain C compilation.

Also, what exactly are we checking here? With -### CC1 sub-compilations do not run and, I think, that's where unsupported options were triggering warning/errors.

You may want to do two actual compilations, one with --cuda-host-only and one with --cuda-device-only -s.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added -x cuda. The test is to show we don't get an error (err_drv_unsupported_opt_for_target) when compiling for x86_64 using a device (AMDGPU/NVPTX) when certain target-specified options are specified.

I am not familiar with offloading but specifying --cuda-host-only would defeat the purpose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offloading compilation for these single-source languages pretty much just combines one "host" compilation job with N "Device" compilation jobs. Doing --offload-device-only and --offload-host-only simply does one part of that. There's probably some flags that behave differently depending on which end you're compiling on, so maybe it would be useful for separating that behavior if needed.

Created using spr 1.3.4
// DEFINE: %{check} = %clang -### -c %{gpu_opts} -mcmodel=medium %s
// RUN: %{check} -fbasic-block-sections=all

// REDEFINE: %{gpu_opts} = -x hip --rocm-path=%S/Inputs/rocm -nogpulib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably include -nogpuinc as well. Best way to avoid spurious failures due to lack of a local CUDA / ROCm installation. Maybe in the future LLVM based offloading won't depend on so much external stuff.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

Created using spr 1.3.4
@@ -0,0 +1,5 @@
/// Some target-specific options are ignored for GPU, so %clang exits with code 0.
// DEFINE: %{check} = %clang -### -c -mcmodel=medium
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, what exactly are we checking here? With -### CC1 sub-compilations do not run and, I think, that's where unsupported options were triggering warning/errors.

We're still only running the top-level driver. Weren't errors reported by cc1 compilation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably depends on the option we're testing. We could do both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this particular case, the changes we test (and the error messages) were originating in the driver, so we're OK with -###.

That said, we do have other options that we do need to suppress/ignore and some of that does happen on cc1 level.

We'll eventually need to add the tests for those here and then enable actual compilation, but it should not hold this patch back.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general the error reporting is done in the driver and cc1 allows and ignores options that may be specific to other targets.

That said, we do have other options that we do need to suppress/ignore and some of that does happen on cc1 level.

Perhaps we should figure out them and check whether they should be moved to the driver

@MaskRay MaskRay merged commit ed7cee9 into main Jan 24, 2024
3 of 4 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/driver-test-ignored-target-specific-options-for-amdgpunvptx branch January 24, 2024 18:06
@gulfemsavrun
Copy link
Contributor

We started seeing a test failure in our Clang toolchain builders for Mac:

FAIL: Clang :: Driver/unsupported-option-gpu.c (10452 of 19269)
******************** TEST 'Clang :: Driver/unsupported-option-gpu.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 4: /Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang -### -c -mcmodel=medium -x cuda /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/unsupported-option-gpu.c --cuda-path=/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/CUDA/usr/local/cuda --offload-arch=sm_60 --no-cuda-version-check -fbasic-block-sections=all
+ /Volumes/Work/s/w/ir/x/w/llvm_build/bin/clang -### -c -mcmodel=medium -x cuda /Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/unsupported-option-gpu.c --cuda-path=/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/CUDA/usr/local/cuda --offload-arch=sm_60 --no-cuda-version-check -fbasic-block-sections=all
Fuchsia clang version 19.0.0git (https://llvm.googlesource.com/llvm-project c1cb0b80f00888920050068a8c6b4f78ca40dd43)
Target: x86_64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Volumes/Work/s/w/ir/x/w/llvm_build/bin
clang: error: unsupported option '-fbasic-block-sections=all' for target 'x86_64-apple-macosx13.0.0'
 "/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm" "clang" "-cc1" "-triple" "nvptx64-nvidia-cuda" "-aux-triple" "x86_64-apple-darwin22.6.0" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-S" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "unsupported-option-gpu.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-fno-rounding-math" "-no-integrated-as" "-aux-target-cpu" "penryn" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-fbuiltin-headers-in-system-modules" "-fdefine-target-os-macros" "-fcuda-is-device" "-mllvm" "-enable-memcpyopt-without-libcalls" "-mlink-builtin-bitcode" "/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/libdevice.compute_30.10.bc" "-target-sdk-version=7.0" "-mcmodel=medium" "-target-cpu" "sm_60" "-target-feature" "+ptx42" "-debugger-tuning=gdb" "-fno-dwarf-directory-asm" "-fdebug-compilation-dir=/Volumes/Work/s/w/ir/x/w/llvm_build/tools/clang/test/Driver" "-target-linker-version" "857.1" "-resource-dir" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19/include/cuda_wrappers" "-include" "__clang_cuda_runtime_wrapper.h" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/bin/../include/c++/v1" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/bin/../include/c++/v1" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/CUDA/usr/local/cuda/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fno-autolink" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-cuid=5730a5be306aa06d" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/Volumes/Work/s/w/ir/x/t/lit-tmp-sgc_485s/unsupported-option-gpu-sm_60-18c1d6.s" "-x" "cuda" "/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/unsupported-option-gpu.c"
 "/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/CUDA/usr/local/cuda/bin/ptxas" "-m64" "-O0" "--gpu-name" "sm_60" "--output-file" "/Volumes/Work/s/w/ir/x/t/lit-tmp-sgc_485s/unsupported-option-gpu-sm_60-02dbb3.cubin" "/Volumes/Work/s/w/ir/x/t/lit-tmp-sgc_485s/unsupported-option-gpu-sm_60-18c1d6.s"
 "fatbinary" "--cuda" "-64" "--create" "/Volumes/Work/s/w/ir/x/t/lit-tmp-sgc_485s/unsupported-option-gpu-36608d.fatbin" "--image=profile=sm_60,file=/Volumes/Work/s/w/ir/x/t/lit-tmp-sgc_485s/unsupported-option-gpu-sm_60-02dbb3.cubin" "--image=profile=compute_60,file=/Volumes/Work/s/w/ir/x/t/lit-tmp-sgc_485s/unsupported-option-gpu-sm_60-18c1d6.s"
 "/Volumes/Work/s/w/ir/x/w/llvm_build/bin/llvm" "clang" "-cc1" "-triple" "x86_64-apple-macosx13.0.0" "-target-sdk-version=7.0" "-aux-triple" "nvptx64-nvidia-cuda" "-Wundef-prefix=TARGET_OS_" "-Werror=undef-prefix" "-Wdeprecated-objc-isa-usage" "-Werror=deprecated-objc-isa-usage" "-emit-obj" "-mrelax-all" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "unsupported-option-gpu.c" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all" "-ffp-contract=on" "-fno-rounding-math" "-funwind-tables=2" "-fcompatibility-qualified-id-block-type-checking" "-fvisibility-inlines-hidden-static-local-var" "-fbuiltin-headers-in-system-modules" "-fdefine-target-os-macros" "-mcmodel=medium" "-mlarge-data-threshold=65536" "-target-cpu" "penryn" "-tune-cpu" "generic" "-debugger-tuning=lldb" "-fdebug-compilation-dir=/Volumes/Work/s/w/ir/x/w/llvm_build/tools/clang/test/Driver" "-target-linker-version" "857.1" "-fcoverage-compilation-dir=/Volumes/Work/s/w/ir/x/w/llvm_build/tools/clang/test/Driver" "-resource-dir" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19/include/cuda_wrappers" "-include" "__clang_cuda_runtime_wrapper.h" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/bin/../include/c++/v1" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/bin/../include/c++/v1" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm_build/lib/clang/19/include" "-internal-externc-isystem" "/usr/include" "-internal-isystem" "/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/Inputs/CUDA/usr/local/cuda/include" "-fdeprecated-macro" "-ferror-limit" "19" "-stack-protector" "1" "-fblocks" "-fencode-extended-block-signature" "-fregister-global-dtors-with-atexit" "-fgnuc-version=4.2.1" "-fcxx-exceptions" "-fexceptions" "-fmax-type-align=16" "-fcuda-include-gpubinary" "/Volumes/Work/s/w/ir/x/t/lit-tmp-sgc_485s/unsupported-option-gpu-36608d.fatbin" "-cuid=5730a5be306aa06d" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "unsupported-option-gpu.o" "-x" "cuda" "/Volumes/Work/s/w/ir/x/w/llvm-llvm-project/clang/test/Driver/unsupported-option-gpu.c"

--

********************

https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-mac-x64/b8757994508930469025/overview

@jhuber6
Copy link
Contributor

jhuber6 commented Jan 24, 2024

Maybe need to specify --target=x86_64-unknown-linux-gnu in the test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants