Skip to content

Commit 6978c25

Browse files
[SYCL][Docs] Change ODF design document to run pass twice (#8530)
This commit changes the Optional Device Features design document to describe a change in approach for the aspect propagation pass to be run twice to allow some aspect uses to be optimized out. --------- Signed-off-by: Larsen, Steffen <[email protected]> Co-authored-by: Greg Lueck <[email protected]>
1 parent 016d68b commit 6978c25

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

sycl/doc/design/OptionalDeviceFeatures.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,19 @@ We add a new IR phase to the device compiler which does the following:
524524
graph so that each function lists the aspects used by that function and by
525525
any functions it calls.
526526

527-
* Diagnoses a warning if any function that has `!sycl_declared_aspects` uses
528-
an aspect not listed in that declared set.
529-
530527
* Creates an `!sycl_fixed_targets` metadata for each kernel function or
531528
`SYCL_EXTERNAL` function that is defined. This is done regardless of whether
532529
the `-fsycl-fixed-targets` command line switch is specified. If the switch
533530
is not specified, the metadata has an empty list of targets.
534531

535-
* If the `-fsycl-fixed-targets` command line switch is specified, diagnoses a
536-
warning if any function uses an aspect that is not compatible with all target
537-
devices specified by that switch.
532+
Additionally, the pass will issue warning diagnostics in the following cases:
533+
534+
* If any function that has `!sycl_declared_aspects` uses an aspect not listed in
535+
that declared set.
536+
537+
* If the `-fsycl-fixed-targets` command line switch is specified and any
538+
function uses an aspect that is not compatible with all target devices
539+
specified by that switch.
538540

539541
It is important that this IR phase runs before any other optimization phase
540542
that might eliminate a reference to a type or inline a function call because
@@ -568,13 +570,13 @@ need only look at the `!sycl_used_aspects` metadata for each function,
568570
propagating the aspects used by each function up to it callers and augmenting
569571
the caller's `!sycl_used_aspects` set.
570572

571-
Diagnosing warnings for the third bullet point is then straightforward. The
573+
Diagnosing warnings for the fifth bullet point is then straightforward. The
572574
implementation looks for functions that have `!sycl_declared_aspects` and
573575
compares that set with the `!sycl_used_aspects` set (if any). If a function
574576
uses an aspect that is not in the declared set, the implementation issues a
575577
warning.
576578

577-
Diagnosing warnings for the fifth bullet point requires the [device
579+
Diagnosing warnings for the sixth bullet point requires the [device
578580
configuration file][7] which gives the set of allowed optional features for
579581
each target device. The implementation looks for functions that have either
580582
`!sycl_declared_aspects` or `!sycl_used_aspects`, and it compares the aspects
@@ -632,6 +634,39 @@ AST. By contrast, we can diagnose the warning more efficiently in an IR pass
632634
because traversal of the IR is much more efficient than traversal of the AST.
633635
The downside, though, is that the warning message is less informative.
634636

637+
#### Pre- and post-optimization aspect propagation
638+
639+
Sometimes aspects that are used by a kernel in source code are eliminated during
640+
optimization. The most common case is when a kernel uses a double precision
641+
floating point literal to initialize a single precision floating point variable.
642+
Although the kernel uses the aspect `fp64` (corresponding to `double`) in its
643+
source code, the optimizer commonly replaces the double precision literal with a
644+
single precision literal, and this can sometimes mean that the kernel does not
645+
actually rely on the `fp64` aspect at all. We therefore have a quandary, should
646+
kernels like this be allowed to run on a device that doesn't have `fp64`
647+
support?
648+
649+
It seems too extreme to raise an exception if the application attempts to submit
650+
a kernel like this to a device without fp64 support because applications like
651+
this previously ran without error (prior to this design being implemented).
652+
However, it also seems useful to issue a warning in a case like this if the
653+
application specifically decorated the kernel with `[[sycl::device_has()]]`
654+
(i.e. requesting a warning if the kernel uses aspects not listed in that
655+
attribute). We therefore run the aspect propagation pass twice: once before
656+
optimization and again after optimization.
657+
658+
The first run of the pass takes a list of aspect names to exclude when saving
659+
the result of the propagation. It will still propagate the excluded aspects to
660+
correctly issue strict warning diagnostics for the cases mentioned above, but
661+
after the pass finishes functions will only have the excluded aspects in their
662+
`!sycl_used_aspects` metadata if they had them prior to the execution of the
663+
pass.
664+
665+
In the second run of the pass, all aspects are propagated and saved. For the
666+
aspects that were not excluded from the first run of the pass this will have no
667+
effect and the pass may elect to ignore these aspects. To avoid repeating
668+
warnings issued by the previous execution of the pass, this run will not issue
669+
any warning diagnostics.
635670

636671
### Assumptions on other phases of clang
637672

0 commit comments

Comments
 (0)