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

Do some basic validation of Target Features (#7986) #7987

Merged
merged 9 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
92 changes: 92 additions & 0 deletions src/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,98 @@ void bad_target_string(const std::string &target) {

} // namespace

void Target::validate_features() const {
// Note that the features don't have to be exhaustive, but enough to avoid obvious mistakes is good.
if (arch == X86) {
static const std::vector<Feature> bad_features_x86 = {
ARMDotProd,
ARMFp16,
ARMv7s,
ARMv81a,
HVX_128,
HVX_128,
HVX_v62,
HVX_v65,
HVX_v66,
NoNEON,
POWER_ARCH_2_07,
RVV,
SVE,
SVE2,
VSX,
WasmBulkMemory,
WasmSatFloatToInt,
WasmSignExt,
WasmSimd128,
WasmThreads,
};
user_assert(!features_any_of(bad_features_x86)) << "At least os_entry of the features for "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"os_entry"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops fixed

<< *this << " is incompatible with the Target's architecture.";
} else if (arch == ARM) {
static const std::vector<Feature> bad_features_arm = {
AVX,
AVX2,
AVX512,
AVX512_Cannonlake,
AVX512_KNL,
AVX512_SapphireRapids,
AVX512_Skylake,
AVX512_Zen4,
F16C,
FMA,
FMA4,
HVX_128,
HVX_128,
HVX_v62,
HVX_v65,
HVX_v66,
POWER_ARCH_2_07,
RVV,
SSE41,
VSX,
WasmBulkMemory,
WasmSatFloatToInt,
WasmSignExt,
WasmSimd128,
WasmThreads,
};
user_assert(!features_any_of(bad_features_arm)) << "At least os_entry of the features for "
<< *this << " is incompatible with the Target's architecture.";
} else if (arch == WebAssembly) {
static const std::vector<Feature> bad_features_wasm = {
ARMDotProd,
ARMFp16,
ARMv7s,
ARMv81a,
AVX,
AVX2,
AVX512,
AVX512_Cannonlake,
AVX512_KNL,
AVX512_SapphireRapids,
AVX512_Skylake,
AVX512_Zen4,
F16C,
FMA,
FMA4,
HVX_128,
HVX_128,
HVX_v62,
HVX_v65,
HVX_v66,
NoNEON,
POWER_ARCH_2_07,
RVV,
SSE41,
SVE,
SVE2,
VSX,
};
user_assert(!features_any_of(bad_features_wasm)) << "At least os_entry of the features for "
<< *this << " is incompatible with the Target's architecture.";
}
}

Target::Target(const std::string &target) {
Target host = get_host_target();

Expand Down
6 changes: 6 additions & 0 deletions src/Target.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ struct Target {
for (const auto &f : initial_features) {
set_feature(f);
}
validate_features();
}

Target(OS o, Arch a, int b, const std::vector<Feature> &initial_features = std::vector<Feature>())
Expand Down Expand Up @@ -358,6 +359,11 @@ struct Target {
private:
/** A bitmask that stores the active features. */
std::bitset<FeatureEnd> features;

/** Attempt to validate that all features set are sensible for the base Target.
* This is *not* guaranteed to get all invalid combinations, but is intended
* to catch at least the most common (e.g., setting arm-specific features on x86). */
void validate_features() const;
};

/** Return the target corresponding to the host machine. */
Expand Down