Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ABI-Break][SYCL] Drop SYCL_DEVICE_FILTER support #13192

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
64 changes: 0 additions & 64 deletions sycl/include/sycl/detail/device_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,70 +69,6 @@ class ods_target_list {
std::ostream &operator<<(std::ostream &Out, const ods_target &Target);
std::vector<ods_target> Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envStr);

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
// ---------------------------------------
// SYCL_DEVICE_FILTER support

struct device_filter {
std::optional<backend> Backend;
std::optional<info::device_type> DeviceType;
std::optional<int> DeviceNum;
int MatchesSeen = 0;

device_filter(){};
device_filter(const std::string &FilterString);
friend std::ostream &operator<<(std::ostream &Out,
const device_filter &Filter);
};

class device_filter_list {
std::vector<device_filter> FilterList;

public:
device_filter_list() {}
device_filter_list(const std::string &FilterString);
device_filter_list(device_filter &Filter);
void addFilter(device_filter &Filter);
std::vector<device_filter> &get() { return FilterList; }
bool backendCompatible(backend Backend);
bool deviceTypeCompatible(info::device_type DeviceType);
bool deviceNumberCompatible(int DeviceNum);
friend std::ostream &operator<<(std::ostream &Out,
const device_filter_list &List);
};

inline std::ostream &operator<<(std::ostream &Out,
const device_filter &Filter) {
Out << Filter.Backend << ":";
if (Filter.DeviceType == info::device_type::host) {
Out << "host";
} else if (Filter.DeviceType == info::device_type::cpu) {
Out << "cpu";
} else if (Filter.DeviceType == info::device_type::gpu) {
Out << "gpu";
} else if (Filter.DeviceType == info::device_type::accelerator) {
Out << "accelerator";
} else if (Filter.DeviceType == info::device_type::all) {
Out << "*";
} else {
Out << "unknown";
}
if (Filter.DeviceNum) {
Out << ":" << Filter.DeviceNum.value();
}
return Out;
}

inline std::ostream &operator<<(std::ostream &Out,
const device_filter_list &List) {
for (const device_filter &Filter : List.FilterList) {
Out << Filter;
Out << ",";
}
return Out;
}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

} // namespace detail
} // namespace _V1
} // namespace sycl
3 changes: 0 additions & 3 deletions sycl/source/detail/config.def
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ CONFIG(SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE, 16, __SYCL_PARALLEL_FOR_RANGE_ROU
CONFIG(SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING, 16, __SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING)
CONFIG(SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS, 64, __SYCL_PARALLEL_FOR_RANGE_ROUNDING_PARAMS)
CONFIG(SYCL_DEVICELIB_NO_FALLBACK, 1, __SYCL_DEVICELIB_NO_FALLBACK)
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
CONFIG(SYCL_DEVICE_FILTER, 1024, __SYCL_DEVICE_FILTER)
#endif
CONFIG(SYCL_PROGRAM_LINK_OPTIONS, 64, __SYCL_PROGRAM_LINK_OPTIONS)
CONFIG(SYCL_PROGRAM_COMPILE_OPTIONS, 64, __SYCL_PROGRAM_COMPILE_OPTIONS)
CONFIG(SYCL_PROGRAM_APPEND_LINK_OPTIONS, 64, __SYCL_PROGRAM_APPEND_LINK_OPTIONS)
Expand Down
44 changes: 0 additions & 44 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,50 +285,6 @@ template <> class SYCLConfig<ONEAPI_DEVICE_SELECTOR> {
}
};

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
// ---------------------------------------
// SYCL_DEVICE_FILTER support

template <>
class __SYCL2020_DEPRECATED("Use SYCLConfig<ONEAPI_DEVICE_SELECTOR> instead")
SYCLConfig<SYCL_DEVICE_FILTER> {
using BaseT = SYCLConfigBase<SYCL_DEVICE_FILTER>;

public:
static device_filter_list *get() {
static bool Initialized = false;
static device_filter_list *FilterList = nullptr;

// Configuration parameters are processed only once, like reading a string
// from environment and converting it into a typed object.
if (Initialized) {
return FilterList;
}

const char *ValStr = BaseT::getRawValue();
if (ValStr) {

std::cerr
<< "\nWARNING: The enviroment variable SYCL_DEVICE_FILTER"
" is deprecated. Please use ONEAPI_DEVICE_SELECTOR instead.\n"
"For more details, please refer to:\n"
"https://github.com/intel/llvm/blob/sycl/sycl/doc/"
"EnvironmentVariables.md#oneapi_device_selector\n\n";

FilterList = &GlobalHandler::instance().getDeviceFilterList(ValStr);
}

// As mentioned above, configuration parameters are processed only once.
// If multiple threads are checking this env var at the same time,
// they will end up setting the configration to the same value.
// If other threads check after one thread already set configration,
// the threads will get the same value as the first thread.
Initialized = true;
return FilterList;
}
};
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

template <> class SYCLConfig<SYCL_ENABLE_DEFAULT_CONTEXTS> {
using BaseT = SYCLConfigBase<SYCL_ENABLE_DEFAULT_CONTEXTS>;

Expand Down
142 changes: 2 additions & 140 deletions sycl/source/detail/device_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ static void Parse_ODS_Device(ods_target &Target,
std::string_view TopDeviceStr = DeviceSubTuple[0];

// Handle explicit device type (e.g. 'gpu').
auto DeviceTypeMap = getSyclDeviceTypeMap<
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
true /*Enable 'acc'*/
#endif
>(); // <-- std::array<std::pair<std::string,
// info::device::type>>
auto DeviceTypeMap = getSyclDeviceTypeMap();

auto It =
std::find_if(std::begin(DeviceTypeMap), std::end(DeviceTypeMap),
Expand Down Expand Up @@ -266,11 +261,7 @@ Parse_ONEAPI_DEVICE_SELECTOR(const std::string &envString) {
std::ostream &operator<<(std::ostream &Out, const ods_target &Target) {
Out << Target.Backend;
if (Target.DeviceType) {
auto DeviceTypeMap = getSyclDeviceTypeMap<
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
true /*Enable 'acc'*/
#endif
>();
auto DeviceTypeMap = getSyclDeviceTypeMap();
auto Match = std::find_if(
DeviceTypeMap.begin(), DeviceTypeMap.end(),
[&](auto Pair) { return (Pair.second == Target.DeviceType); });
Expand Down Expand Up @@ -307,135 +298,6 @@ bool ods_target_list::backendCompatible(backend Backend) {
return (TargetBackend == Backend) || (TargetBackend == backend::all);
});
}

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
// ---------------------------------------
// SYCL_DEVICE_FILTER support

device_filter::device_filter(const std::string &FilterString) {
std::vector<std::string_view> Tokens = tokenize(FilterString, ":");
size_t TripleValueID = 0;

auto FindElement = [&](auto Element) {
return std::string::npos != Tokens[TripleValueID].find(Element.first);
};

// Handle the optional 1st field of the filter, backend
// Check if the first entry matches with a known backend type
auto It = std::find_if(std::begin(getSyclBeMap()), std::end(getSyclBeMap()),
FindElement);
// If no match is found, set the backend type backend::all
// which actually means 'any backend' will be a match.
if (It == getSyclBeMap().end())
Backend = backend::all;
else {
Backend = It->second;
TripleValueID++;

if (Backend == backend::host)
std::cerr << "WARNING: The 'host' backend type is no longer supported in "
"device filter."
<< std::endl;
}

// Handle the optional 2nd field of the filter - device type.
// Check if the 2nd entry matches with any known device type.
if (TripleValueID >= Tokens.size()) {
DeviceType = info::device_type::all;
} else {
auto Iter = std::find_if(
std::begin(getSyclDeviceTypeMap<true /*Enable 'acc'*/>()),
std::end(getSyclDeviceTypeMap<true /*Enable 'acc'*/>()), FindElement);
// If no match is found, set device_type 'all',
// which actually means 'any device_type' will be a match.
if (Iter == getSyclDeviceTypeMap<true /*Enable 'acc'*/>().end())
DeviceType = info::device_type::all;
else {
DeviceType = Iter->second;
TripleValueID++;

if (DeviceType == info::device_type::host)
std::cerr << "WARNING: The 'host' device type is no longer supported "
"in device filter."
<< std::endl;
}
}

// Handle the optional 3rd field of the filter, device number
// Try to convert the remaining string to an integer.
// If succeessful, the converted integer is the desired device num.
if (TripleValueID < Tokens.size()) {
try {
DeviceNum = std::stoi(Tokens[TripleValueID].data());
} catch (...) {
std::string Message =
std::string("Invalid device filter: ") + FilterString +
"\nPossible backend values are "
"{opencl,level_zero,cuda,hip,*}.\n"
"Possible device types are {cpu,gpu,acc,*}.\n"
"Device number should be an non-negative integer.\n";
throw sycl::invalid_parameter_error(Message, PI_ERROR_INVALID_VALUE);
}
}
}

device_filter_list::device_filter_list(const std::string &FilterStr) {
// First, change the string in all lowercase.
// This means we allow the user to use both uppercase and lowercase strings.
std::string FilterString = FilterStr;
std::transform(FilterString.begin(), FilterString.end(), FilterString.begin(),
::tolower);
// SYCL_DEVICE_FILTER can set multiple filters separated by commas.
// convert each filter triple string into an istance of device_filter class.
size_t Pos = 0;
while (Pos < FilterString.size()) {
size_t CommaPos = FilterString.find(",", Pos);
if (CommaPos == std::string::npos) {
CommaPos = FilterString.size();
}
std::string SubString = FilterString.substr(Pos, CommaPos - Pos);
FilterList.push_back(device_filter(SubString));
Pos = CommaPos + 1;
}
}

device_filter_list::device_filter_list(device_filter &Filter) {
FilterList.push_back(Filter);
}

void device_filter_list::addFilter(device_filter &Filter) {
FilterList.push_back(Filter);
}

// Backend is compatible with the SYCL_DEVICE_FILTER in the following cases.
// 1. Filter backend is '*' which means ANY backend.
// 2. Filter backend match exactly with the given 'Backend'
bool device_filter_list::backendCompatible(backend Backend) {
return std::any_of(
FilterList.begin(), FilterList.end(), [&](device_filter &Filter) {
backend FilterBackend = Filter.Backend.value_or(backend::all);
return (FilterBackend == Backend) || (FilterBackend == backend::all);
});
}

bool device_filter_list::deviceTypeCompatible(info::device_type DeviceType) {
return std::any_of(FilterList.begin(), FilterList.end(),
[&](device_filter &Filter) {
info::device_type FilterDevType =
Filter.DeviceType.value_or(info::device_type::all);
return (FilterDevType == DeviceType) ||
(FilterDevType == info::device_type::all);
});
}

bool device_filter_list::deviceNumberCompatible(int DeviceNum) {
return std::any_of(
FilterList.begin(), FilterList.end(), [&](device_filter &Filter) {
return (!Filter.DeviceNum) || (Filter.DeviceNum.value() == DeviceNum);
});
}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

} // namespace detail
} // namespace _V1
} // namespace sycl
6 changes: 1 addition & 5 deletions sycl/source/detail/filter_selector_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ namespace ext {
namespace oneapi {
namespace detail {

#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
typedef struct sycl::detail::ods_target filter;
#else
typedef struct sycl::detail::device_filter filter;
#endif
using filter = sycl::detail::ods_target;

class filter_selector_impl {
public:
Expand Down
7 changes: 0 additions & 7 deletions sycl/source/detail/global_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,6 @@ std::vector<PluginPtr> &GlobalHandler::getPlugins() {
return getOrCreate(MPlugins);
}

#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
device_filter_list &
GlobalHandler::getDeviceFilterList(const std::string &InitValue) {
return getOrCreate(MDeviceFilterList, InitValue);
}
#endif

ods_target_list &
GlobalHandler::getOneapiDeviceSelectorTargets(const std::string &InitValue) {
return getOrCreate(MOneapiDeviceSelectorTargets, InitValue);
Expand Down
9 changes: 0 additions & 9 deletions sycl/source/detail/global_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Scheduler;
class ProgramManager;
class Sync;
class plugin;
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
class device_filter_list;
#endif
class ods_target_list;
class XPTIRegistry;
class ThreadPool;
Expand Down Expand Up @@ -72,9 +69,6 @@ class GlobalHandler {
std::mutex &getPlatformMapMutex();
std::mutex &getFilterMutex();
std::vector<PluginPtr> &getPlugins();
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
device_filter_list &getDeviceFilterList(const std::string &InitValue);
#endif
ods_target_list &getOneapiDeviceSelectorTargets(const std::string &InitValue);
XPTIRegistry &getXPTIRegistry();
ThreadPool &getHostTaskThreadPool();
Expand Down Expand Up @@ -125,9 +119,6 @@ class GlobalHandler {
InstWithLock<std::mutex> MPlatformMapMutex;
InstWithLock<std::mutex> MFilterMutex;
InstWithLock<std::vector<PluginPtr>> MPlugins;
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
InstWithLock<device_filter_list> MDeviceFilterList;
#endif
InstWithLock<ods_target_list> MOneapiDeviceSelectorTargets;
InstWithLock<XPTIRegistry> MXPTIRegistry;
// Thread pool for host task and event callbacks execution
Expand Down
Loading
Loading