Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,51 @@ template <> class SYCLConfig<SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS> {
return;

static bool ProcessedFactors = false;
static bool FactorsAreValid = false;
static size_t MF;
static size_t GF;
static size_t MR;
if (!ProcessedFactors) {
auto GuardedStoi = [](size_t &val, const std::string &str) {
try {
val = std::stoi(str);
return true;
// Ignore parsing exceptions, but throw on unexpected exceptions:
} catch (const std::invalid_argument&) {
} catch (const std::out_of_range&) {
}
return false;
};

// Parse optional parameters of this form (all values required):
// MinRound:PreferredRound:MinRange
std::string Params(RoundParams);
size_t Pos = Params.find(':');
if (Pos != std::string::npos) {
MF = std::stoi(Params.substr(0, Pos));
if (Pos != std::string::npos &&
GuardedStoi(MF, Params.substr(0, Pos)) && MF > 0) {
Params.erase(0, Pos + 1);
Pos = Params.find(':');
if (Pos != std::string::npos) {
GF = std::stoi(Params.substr(0, Pos));
if (Pos != std::string::npos &&
GuardedStoi(GF, Params.substr(0, Pos)) && GF > 0) {
Params.erase(0, Pos + 1);
MR = std::stoi(Params);
// Factors are valid only if all parsed successfully:
FactorsAreValid = GuardedStoi(MR, Params);
// Note that MinRange = 0 is considered valid.
}
}
ProcessedFactors = true;
}
MinFactor = MF;
GoodFactor = GF;
MinRange = MR;
if (FactorsAreValid) {
MinFactor = MF;
GoodFactor = GF;
MinRange = MR;
} else {
std::cerr
<< "WARNING: Invalid value passed for "
<< "SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS (Expected format "
<< "MinRound:PreferredRound:MinRange, where MinRound, PreferredRound"
<< " > 0). Provided parameters will be ignored." << std::endl;
}
}
};

Expand Down
Loading