@@ -524,17 +524,19 @@ We add a new IR phase to the device compiler which does the following:
524
524
graph so that each function lists the aspects used by that function and by
525
525
any functions it calls.
526
526
527
- * Diagnoses a warning if any function that has ` !sycl_declared_aspects ` uses
528
- an aspect not listed in that declared set.
529
-
530
527
* Creates an ` !sycl_fixed_targets ` metadata for each kernel function or
531
528
` SYCL_EXTERNAL ` function that is defined. This is done regardless of whether
532
529
the ` -fsycl-fixed-targets ` command line switch is specified. If the switch
533
530
is not specified, the metadata has an empty list of targets.
534
531
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.
538
540
539
541
It is important that this IR phase runs before any other optimization phase
540
542
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,
568
570
propagating the aspects used by each function up to it callers and augmenting
569
571
the caller's ` !sycl_used_aspects ` set.
570
572
571
- Diagnosing warnings for the third bullet point is then straightforward. The
573
+ Diagnosing warnings for the fifth bullet point is then straightforward. The
572
574
implementation looks for functions that have ` !sycl_declared_aspects ` and
573
575
compares that set with the ` !sycl_used_aspects ` set (if any). If a function
574
576
uses an aspect that is not in the declared set, the implementation issues a
575
577
warning.
576
578
577
- Diagnosing warnings for the fifth bullet point requires the [ device
579
+ Diagnosing warnings for the sixth bullet point requires the [ device
578
580
configuration file] [ 7 ] which gives the set of allowed optional features for
579
581
each target device. The implementation looks for functions that have either
580
582
` !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
632
634
because traversal of the IR is much more efficient than traversal of the AST.
633
635
The downside, though, is that the warning message is less informative.
634
636
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.
635
670
636
671
### Assumptions on other phases of clang
637
672
0 commit comments