Page MenuHomePhabricator

[SYCL] Rework the SYCL driver options
ClosedPublic

Authored by aaron.ballman on Mar 1 2021, 11:57 AM.

Details

Summary

SYCL compilations initiated by the driver will spawn off one or more frontend compilation jobs (one for device and one for host). This patch reworks the driver options to make upstreaming this from the downstream SYCL fork easier.

This patch introduces a language option to identify host executions (SYCLIsHost) and a -cc1 frontend option to enable this mode. -fsycl and -fno-sycl become driver-only options that are rejected when passed to -cc1. This is because the frontend and beyond should be looking at whether the user is doing a device or host compilation specifically. Because the frontend should only ever be in one mode or the other, -fsycl-is-device and -fsycl-is-host are mutually exclusive options.

Diff Detail

Unit TestsFailed

TimeTest
20 msx64 debian > Clang.OpenMP::simd_null_pointer_access.cpp
Script: -- : 'RUN: at line 1'; /mnt/disks/ssd0/agent/llvm-project/build/bin/clang -cc1 -internal-isystem /mnt/disks/ssd0/agent/llvm-project/build/lib/clang/13.0.0/include -nostdsysteminc -fopenmp-simd -fsycl -fsycl-is-device -triple spir64 -verify -fsyntax-only /mnt/disks/ssd0/agent/llvm-project/clang/test/OpenMP/simd_null_pointer_access.cpp
50 msx64 windows > Clang.OpenMP::simd_null_pointer_access.cpp
Script: -- : 'RUN: at line 1'; c:\ws\w16n2-1\llvm-project\premerge-checks\build\bin\clang.exe -cc1 -internal-isystem c:\ws\w16n2-1\llvm-project\premerge-checks\build\lib\clang\13.0.0\include -nostdsysteminc -fopenmp-simd -fsycl -fsycl-is-device -triple spir64 -verify -fsyntax-only C:\ws\w16n2-1\llvm-project\premerge-checks\clang\test\OpenMP\simd_null_pointer_access.cpp

Event Timeline

aaron.ballman created this revision.Mar 1 2021, 11:57 AM
aaron.ballman requested review of this revision.Mar 1 2021, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2021, 11:57 AM
keryell added a subscriber: keryell.

Rebased and added a Frontend-specific test.

bader added a subscriber: Naghasan.Mar 3 2021, 1:32 AM
bader added a comment.Mar 3 2021, 1:52 AM

@aaron.ballman, it looks like unittests should be updated as well. Please, take a look at failures in pre-merge checks.

clang/include/clang/Basic/LangOptions.def
252

I'm okay with that change, but IIRC, @ABataev suggested to have both -fsycl and -fsycl-is-device options to align with OpenMP mode (full discussion is here - https://reviews.llvm.org/D72857#inline-674377).

@aaron.ballman, it looks like unittests should be updated as well. Please, take a look at failures in pre-merge checks.

Thanks, I'll correct those!

clang/include/clang/Basic/LangOptions.def
252

Thanks for pointing this out!

As far as the frontend is concerned, being in "SCYL" mode is not a useful construct because you don't know *which* SYCL mode you're in (host or device). Downstream, we're finding that having SYCL, SYCLIsDevice, and SYCLIsHost introduces bugs because developers may check SYCL when they mean SYCLIsDevice or they do things like check SYCL && SYCLIsDevice which is redundant.

Fixed the failing unit tests.

jansvoboda11 requested changes to this revision.Mon, Mar 15, 5:59 AM

I like the simplification of the command line interface. I have concerns about changing the tests just to make them pass though.

clang/unittests/Frontend/CompilerInvocationTest.cpp
550

The generateCC1CommandLine function is used when CC1 gets invoked with -round-trip-args. It is also going to be used in clang-scan-deps.

Instead of putting a fixme here, I think it would make more sense to decide how to handle the option properly. There are a couple of approaches:

  • Instead of removing ShouldParseIf<fsycl.KeyPath> from sycl_std_EQ, it could be replaced with ShouldParseIf<!strconcat(fsycl_is_device.KeyPath, "||", fsycl_is_host.KeyPath)>.
  • Remove ShouldParseIf<fsycl.KeyPath> from sycl_std_EQ, but issue warning/error in CompilerInvocation::fixupInvocation whenever SYCLVersion != LangOptions::SYCL_None && !(SYCLIsDevice || SYCLIsHost).
  • Remove the marshalling annotation from sycl_std_EQ and handle its parsing/generation including the device/host checks manually in CompilerInvocation. (I'm personally not fan of moving simple logic like this from tablegen marshalling annotations to CompilerInvocation though.)

See https://clang.llvm.org/docs/InternalsManual.html#adding-new-command-line-option for more information.

This revision now requires changes to proceed.Mon, Mar 15, 5:59 AM

Update based on review feedback to gate use of -sycl-std on use of -fsycl-is-device or -fsycl-is-host.

aaron.ballman marked an inline comment as done.Mon, Mar 15, 1:26 PM
aaron.ballman added inline comments.
clang/unittests/Frontend/CompilerInvocationTest.cpp
550

Thank you for the suggestions! I took the first suggestion and applied it in this latest revision and I really like the results.

jansvoboda11 added inline comments.Wed, Mar 17, 2:47 AM
clang/unittests/Frontend/CompilerInvocationTest.cpp
547

This test originally checked that enabling SYCL without specifying the version is fine and results in LangOptions::SYCL_None.

I'd like to keep the semantics of this test intact (it exercises the underlying tablegen machinery of ShouldParseIf).

I suggested only replacing -fsycl with -fsycl-is-host here and in the assert below.

556
566

Here, too, I'd like to keep the test mostly intact, only updating -fsycl to -fsycl-is-host or -fsycl-is-device.

You already test that -fsycl passed to CC1 results in an error in clang/test/Frontend/sycl.cpp, so I don't think we need an unit test for that.

aaron.ballman marked 3 inline comments as done.

Updating the unit tests based on review feedback.

aaron.ballman marked an inline comment as done.Wed, Mar 17, 4:48 AM
aaron.ballman added inline comments.
clang/unittests/Frontend/CompilerInvocationTest.cpp
547

Thank you for the suggestions, I've applied them.

jansvoboda11 accepted this revision.Wed, Mar 17, 5:16 AM

Thanks for addressing this! LGTM

This revision is now accepted and ready to land.Wed, Mar 17, 5:16 AM
aaron.ballman closed this revision.Wed, Mar 17, 5:28 AM
aaron.ballman marked an inline comment as done.

Thanks for addressing this! LGTM

Thank you for the review! I've commit in c165a99a1b8861af87e0509a2e14debf2764804b