@@ -780,33 +780,17 @@ class __SYCL_EXPORT handler {
780780 // Range should be at least this to make rounding worthwhile.
781781 size_t MinRangeX = 1024 ;
782782
783- // Parse optional parameters of this form:
784- // MinRound:PreferredRound:MinRange
785- char *RoundParams = getenv (" SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS" );
786- if (RoundParams != nullptr ) {
787- std::string Params (RoundParams);
788- size_t Pos = Params.find (' :' );
789- if (Pos != std::string::npos) {
790- MinFactorX = std::stoi (Params.substr (0 , Pos));
791- Params.erase (0 , Pos + 1 );
792- Pos = Params.find (' :' );
793- if (Pos != std::string::npos) {
794- GoodFactorX = std::stoi (Params.substr (0 , Pos));
795- Params.erase (0 , Pos + 1 );
796- MinRangeX = std::stoi (Params);
797- }
798- }
799- }
783+ // Check if rounding parameters have been set through environment:
784+ // SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS=MinRound:PreferredRound:MinRange
785+ this ->GetRangeRoundingSettings (MinFactorX, GoodFactorX, MinRangeX);
800786
801787 // Disable the rounding-up optimizations under these conditions:
802788 // 1. The env var SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING is set.
803- // 2. The string SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING is in
804- // the kernel name.
805- // 3. The kernel is provided via an interoperability method.
806- // 4. The API "this_item" is used inside the kernel.
807- // 5. The range is already a multiple of the rounding factor.
789+ // 2. The kernel is provided via an interoperability method.
790+ // 3. The API "this_item" is used inside the kernel.
791+ // 4. The range is already a multiple of the rounding factor.
808792 //
809- // Cases 3 and 4 could be supported with extra effort.
793+ // Cases 2 and 3 could be supported with extra effort.
810794 // As an optimization for the common case it is an
811795 // implementation choice to not support those scenarios.
812796 // Note that "this_item" is a free function, i.e. not tied to any
@@ -816,13 +800,11 @@ class __SYCL_EXPORT handler {
816800 // call-graph to make this_item calls kernel-specific but this is
817801 // not considered worthwhile.
818802
819- // Get the kernal name to check condition 3 .
803+ // Get the kernel name to check condition 2 .
820804 std::string KName = typeid (NameT *).name ();
821805 using KI = detail::KernelInfo<KernelName>;
822806 bool DisableRounding =
823- (getenv (" SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING" ) != nullptr ) ||
824- (KName.find (" SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING" ) !=
825- std::string::npos) ||
807+ this ->DisableRangeRounding () ||
826808 (KI::getName () == nullptr || KI::getName ()[0 ] == ' \0 ' ) ||
827809 (KI::callsThisItem ());
828810
@@ -837,7 +819,7 @@ class __SYCL_EXPORT handler {
837819 // will yield a rounded-up value for the total range.
838820 size_t NewValX =
839821 ((NumWorkItems[0 ] + GoodFactorX - 1 ) / GoodFactorX) * GoodFactorX;
840- if (getenv ( " SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE " ) != nullptr )
822+ if (this -> RangeRoundingTrace () )
841823 std::cout << " parallel_for range adjusted from " << NumWorkItems[0 ]
842824 << " to " << NewValX << std::endl;
843825
@@ -2451,6 +2433,13 @@ class __SYCL_EXPORT handler {
24512433
24522434 friend class ::MockHandler;
24532435
2436+ bool DisableRangeRounding ();
2437+
2438+ bool RangeRoundingTrace ();
2439+
2440+ void GetRangeRoundingSettings (size_t &MinFactor, size_t &GoodFactor,
2441+ size_t &MinRange);
2442+
24542443 template <typename WrapperT, typename TransformedArgType, int Dims,
24552444 typename KernelType>
24562445 auto getRangeRoundedKernelLambda (KernelType KernelFunc,
0 commit comments