-
Notifications
You must be signed in to change notification settings - Fork 752
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
[SYCL] Add device config file consistency test #16369
base: sycl
Are you sure you want to change the base?
Changes from all commits
69e538a
78a751a
3855884
3c062ef
81431e7
07e599e
215bf25
d7264c9
b9e14c7
7cd1109
ef8481f
0b99853
7b61e9e
9a893a0
96da39b
9a4f880
415a6be
d9e0582
232357b
fcb7c46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -532,6 +532,11 @@ if("hip" IN_LIST SYCL_ENABLE_BACKENDS) | |
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS ur_adapter_hip) | ||
endif() | ||
|
||
if(SYCL_INSTALL_DEVICE_CONFIG_FILE) | ||
add_dependencies(sycl-toolchain DeviceConfigFile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you give some background on why we need to install this? thx There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm still testing things, so I might change some things, but I want to support the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry so what tools/files are required to generate that hpp file? Is it just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea just tablegen and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also just for some more background I was aiming so that DeviceConfigFile.hpp is not installed by default because outside of testing, this file is not needed for a SYCL distribution, it is only used in the compiler. |
||
list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS DeviceConfigFile) | ||
endif() | ||
|
||
# Use it as fake dependency in order to force another command(s) to execute. | ||
add_custom_command(OUTPUT __force_it | ||
COMMAND "${CMAKE_COMMAND}" -E echo | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// This test checks to see if every aspect and sub-group size declared in the | ||
// device config file is supported by the device. Note this does not mean | ||
// check that the device config file is exhaustive, only that the device | ||
// supports everything it declares. However, this test does print out any | ||
// aspects that are supported by the device but not declared in the device | ||
// config file. | ||
|
||
// UNSUPPORTED: accelerator | ||
// UNSUPPORTED-INTENDED: Accelerator is not supported by | ||
// sycl_ext_oneapi_device_architecture. | ||
// REQUIRES: device-config-file | ||
// RUN: %{build} -o %t.out %device_config_file_include_flag | ||
// RUN: %{run} %t.out | ||
#include <map> | ||
|
||
#include <llvm/SYCLLowerIR/DeviceConfigFile.hpp> | ||
#include <sycl/detail/core.hpp> | ||
|
||
#define __SYCL_ASPECT_DEPRECATED_ALIAS(ASPECT, ID, MESSAGE) \ | ||
__SYCL_ASPECT_DEPRECATED(ASPECT, ID, MESSAGE) | ||
|
||
using namespace sycl; | ||
|
||
const char *getArchName(const device &Device) { | ||
namespace syclex = sycl::ext::oneapi::experimental; | ||
auto Arch = Device.get_info<syclex::info::device::architecture>(); | ||
switch (Arch) { | ||
#define __SYCL_ARCHITECTURE(ARCH, VAL) \ | ||
case syclex::architecture::ARCH: \ | ||
return #ARCH; | ||
#define __SYCL_ARCHITECTURE_ALIAS(ARCH, VAL) | ||
#include <sycl/ext/oneapi/experimental/device_architecture.def> | ||
#undef __SYCL_ARCHITECTURE | ||
#undef __SYCL_ARCHITECTURE_ALIAS | ||
} | ||
return "unknown"; | ||
} | ||
|
||
// Checks if a container contains a specific element. | ||
template <typename Container, typename T> | ||
bool contains(const Container &C, const T &Elem) { | ||
return std::find(C.begin(), C.end(), Elem) != C.end(); | ||
} | ||
|
||
std::string_view getAspectName(aspect Asp) { | ||
switch (Asp) { | ||
#define __SYCL_ASPECT(ASPECT, ID) \ | ||
case aspect::ASPECT: \ | ||
return #ASPECT; | ||
#include <sycl/info/aspects.def> | ||
#undef __SYCL_ASPECT | ||
} | ||
return "unknown"; | ||
} | ||
|
||
aspect getAspectByName(std::string_view Name) { | ||
#define __SYCL_ASPECT(ASPECT, ID) \ | ||
if (Name == #ASPECT) \ | ||
return aspect::ASPECT; | ||
#include <sycl/info/aspects.def> | ||
throw std::invalid_argument("Unknown aspect name"); | ||
} | ||
|
||
int main() { | ||
// Get the device arch | ||
jzc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
queue Q; | ||
auto Dev = Q.get_device(); | ||
auto DeviceName = getArchName(Dev); | ||
|
||
auto TargetInfo = DeviceConfigFile::TargetTable.find(DeviceName); | ||
if (TargetInfo == DeviceConfigFile::TargetTable.end()) { | ||
std::cout << "No aspects found for device " << DeviceName << "\n"; | ||
return 1; | ||
} | ||
|
||
// Check aspects consistency | ||
jzc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int NAspectInconsistencies = 0; | ||
std::cout << "Checking consistency of aspects for device " << DeviceName | ||
<< "...\n"; | ||
|
||
auto SupportedAspects = Dev.get_info<info::device::aspects>(); | ||
auto DeviceConfigAspectNames = TargetInfo->second.aspects; | ||
std::vector<aspect> DeviceConfigAspects; | ||
for (auto AspectName : DeviceConfigAspectNames) { | ||
DeviceConfigAspects.push_back(getAspectByName(AspectName)); | ||
} | ||
|
||
for (auto Asp : DeviceConfigAspects) { | ||
if (!contains(SupportedAspects, Asp)) { | ||
std::cout << "error: " << DeviceName << " does not support aspect " | ||
<< getAspectName(Asp) | ||
<< " but it is declared in the device config file\n"; | ||
++NAspectInconsistencies; | ||
} | ||
} | ||
for (auto Asp : SupportedAspects) { | ||
if (!contains(DeviceConfigAspects, Asp)) { | ||
std::cout << "note: the device " << DeviceName << " supports aspect " | ||
<< getAspectName(Asp) | ||
<< " but it is not declared in the device config file\n"; | ||
// Not necessarily an error, so we won't increment n_fail | ||
jzc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
if (NAspectInconsistencies == 0) | ||
std::cout << "All aspects are consistent\n"; | ||
|
||
// Check sub-group sizes consistency | ||
jzc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int NSubGroupSizeInconsistencies = 0; | ||
std::cout << "Checking consistency of sub-group sizes for device " | ||
<< DeviceName << "...\n"; | ||
|
||
auto SupportedSubGroupSizes = Dev.get_info<info::device::sub_group_sizes>(); | ||
auto DeviceConfigSubGroupSizes = TargetInfo->second.subGroupSizes; | ||
|
||
for (auto Size : DeviceConfigSubGroupSizes) { | ||
if (!contains(SupportedSubGroupSizes, Size)) { | ||
std::cout << "error: " << DeviceName | ||
<< " does not support sub-group size " << Size | ||
<< " but it is declared in the device config file\n"; | ||
++NSubGroupSizeInconsistencies; | ||
} | ||
} | ||
for (auto Size : SupportedSubGroupSizes) { | ||
if (!contains(DeviceConfigSubGroupSizes, Size)) { | ||
std::cout << "note: the device " << DeviceName | ||
<< " supports sub-group size " << Size | ||
<< " but it is not declared in the device config file\n"; | ||
// Not necessarily an error, so we won't increment n_fail | ||
jzc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
if (NSubGroupSizeInconsistencies == 0) | ||
std::cout << "All sub-group sizes are consistent\n"; | ||
|
||
return NAspectInconsistencies + NSubGroupSizeInconsistencies; | ||
} | ||
|
||
#undef __SYCL_ASPECT_DEPRECATED_ALIAS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From CI: