================
@@ -63,3 +74,111 @@ std::string llvm::IntelGPU::getNumericArchName(uint32_t
GPUIPVersion) {
return ("xe_" + Twine(Major) + "." + Twine(Minor) + "." + Twine(Revision))
.str();
}
+
+StringRef llvm::IntelGPU::getArchName(GPUKind Kind) {
+ switch (Kind) {
+ case GK_NONE:
+ return "";
+#define INTEL_GPU(NAME, KIND, MAJOR, MINOR, IGCA_TARGET, IGCA_FEATURE_SETS)
\
+ case GK_##KIND:
\
+ return NAME;
+#define INTEL_GPU_COMPAT(NAME, KIND, IGCA_TARGET, IGCA_FEATURE_SETS)
\
+ case GK_##KIND:
\
+ return NAME;
+#include "llvm/TargetParser/IntelGPUTargetParser.def"
+ }
+ llvm_unreachable("invalid Intel GPU GPUKind");
+}
+
+// Read a numeric architecture name, e.g. "xe_12.60.7", into the GPU IP version
+// it spells. The revision may be omitted, since it takes no part in a lookup
+// either way. Anything else is not a numeric name, which is not the same as
+// naming no device: a caller distinguishes the two by whether this succeeds.
+static bool parseNumericArchName(StringRef Name, uint32_t &GPUIPVersion) {
+ if (!Name.consume_front("xe_"))
+ return false;
+
+ StringRef MajorStr, MinorStr, RevisionStr;
+ std::tie(MajorStr, Name) = Name.split('.');
+ // The revision may be omitted, but a separator with no revision after it is
+ // malformed rather than an omitted revision.
+ const bool HasRevision = Name.contains('.');
+ std::tie(MinorStr, RevisionStr) = Name.split('.');
+ uint32_t Major, Minor, Revision = 0;
+ if (MajorStr.getAsInteger(10, Major) || MinorStr.getAsInteger(10, Minor))
+ return false;
+ if (HasRevision && RevisionStr.getAsInteger(10, Revision))
+ return false;
+
+ // A field too wide for the GPU IP version it spells describes no GPU that
+ // could ever report it, so this is not a numeric name rather than one naming
+ // no device.
+ if (Major > GPUIPMajorMask || Minor > GPUIPMinorMask ||
+ Revision > GPUIPRevisionMask)
+ return false;
+ GPUIPVersion = packDevice(Major, Minor) | Revision;
+ return true;
+}
+
+GPUKind llvm::IntelGPU::parseArch(StringRef Name) {
+ GPUKind Kind = StringSwitch<GPUKind>(Name)
+#define INTEL_GPU(NAME, KIND, MAJOR, MINOR, IGCA_TARGET, IGCA_FEATURE_SETS)
\
+ .Case(NAME, GK_##KIND)
+#define INTEL_GPU_COMPAT(NAME, KIND, IGCA_TARGET, IGCA_FEATURE_SETS)
\
+ .Case(NAME, GK_##KIND)
+#define INTEL_GPU_ALIAS(NAME, KIND) .Case(NAME, GK_##KIND)
+#include "llvm/TargetParser/IntelGPUTargetParser.def"
+ .Default(GK_NONE);
+ if (Kind != GK_NONE)
+ return Kind;
+
+ // A device with no human-friendly name is spelled numerically, so the same
+ // lookup the driver does for a reported GPU IP version has to be reachable
by
+ // name.
+ uint32_t GPUIPVersion;
+ if (parseNumericArchName(Name, GPUIPVersion))
+ return getKindForVersion(GPUIPVersion);
+ return GK_NONE;
+}
+
+// The suffix each IGCA_FEATURE_SETS token contributes to a target name.
+#define IGCA_FEATURE_SETS_Core ""
+#define IGCA_FEATURE_SETS_Compute "c"
+#define IGCA_FEATURE_SETS_Render "r"
+#define IGCA_FEATURE_SETS_ComputeExact "ca"
+#define IGCA_FEATURE_SETS_RenderExact "ra"
----------------
srividya-sundaram wrote:
I prefer keeping the name.
With letters, `getIGCAName` would build the string as `"igca_" #IGCA_TARGET
#IGCA_FEATURE_SETS`.
A typo such as - `INTEL_GPU("xe-cri", XE_CRI, 35, 11, 60, czz)`
would then produce `igca_60czz`.
But a typo such as `Compte` becomes the undefined `IGCA_FEATURE_SETS_Compte`
and the build fails.
Also,
https://github.com/llvm/llvm-project/pull/227468/changes#diff-812874946e78e26e16469e6b1d41916500725e2648130ced595b8b9042663b8eR43
already uses the current format, so might be better to leave them as is.
https://github.com/llvm/llvm-project/pull/229247
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits