[PATCH 37/42] add pocl_get_distro_cpu_name()
authorAndreas Beckmann <anbe@debian.org>
Thu, 7 Apr 2022 10:04:05 +0000 (12:04 +0200)
committerAndreas Beckmann <anbe@debian.org>
Mon, 14 Aug 2023 13:53:17 +0000 (14:53 +0100)
in distro builds, map each kernellib_name to a specific llvm_cpu
which is then used as compilation target instead of the native cpu

this limits the possible code generation targets in distro builds
in order to be able to run tests against all of them with a minimal
number of different (physical) CPU models

Gbp-Pq: Name 0037-add-pocl_get_distro_cpu_name.patch

lib/CL/pocl_llvm.h
lib/CL/pocl_llvm_utils.cc

index 5ed413060aac5d1a62b9cce3801543c6a3fe6ca3..30dc3572fd3cde6fd2306ca381e20ec74fac7f4e 100644 (file)
@@ -43,6 +43,10 @@ extern "C" {
   POCL_EXPORT
   const char *pocl_get_distro_kernellib_name ();
 
+  /* For distro builds, return the target cpu name for a kernellib name */
+  POCL_EXPORT
+  const char *pocl_get_distro_cpu_name (const char *kernellib_name);
+
   /* Returns if the cpu supports FMA instruction (uses LLVM). */
   int cpu_has_fma ();
 
index c55ee075d0d8fd1052e3fb3b164660aa4b2aa706..dca2ad64f8896a1e1eb13429d85560025e5fa19b 100644 (file)
@@ -160,29 +160,39 @@ char *pocl_get_llvm_cpu_name() {
 #ifdef KERNELLIB_HOST_DISTRO_VARIANTS
 const struct kernellib_features {
   const char *kernellib_name;
+  const char *cpu_name;
   const char *features[12];
 } kernellib_feature_map[] = {
 // order the entries s.t. if a cpu matches multiple entries, the "best" match
 // comes last
 #if defined(__x86_64__)
     "sse2",
+    "athlon64",
     {"sse2", NULL},
     "ssse3",
+    "core2",
     {"sse2", "ssse3", "cx16", NULL},
     "sse41",
+    "penryn",
     {"sse2", "sse4.1", "cx16", NULL},
     "avx",
+    "sandybridge",
     {"sse2", "avx", "cx16", "popcnt", NULL},
     "avx_f16c",
+    "ivybridge",
     {"sse2", "avx", "cx16", "popcnt", "f16c", NULL},
     "avx_fma4",
+    "bdver1",
     {"sse2", "avx", "cx16", "popcnt", "xop", "fma4", NULL},
     "avx2",
+    "haswell",
     {"sse2", "avx", "avx2", "cx16", "popcnt", "lzcnt", "f16c", "fma", "bmi",
      "bmi2", NULL},
     "avx512",
+    "skylake-avx512",
     {"sse2", "avx512f", NULL},
 #endif
+    NULL,
     NULL,
     {NULL}};
 
@@ -192,7 +202,7 @@ const char *pocl_get_distro_kernellib_name() {
 
   if (!llvm::sys::getHostCPUFeatures(Features)) {
     POCL_MSG_WARN("LLVM can't get host CPU flags!\n");
-    return "";
+    return NULL;
   }
 
   const kernellib_features *best_match = NULL;
@@ -209,11 +219,33 @@ const char *pocl_get_distro_kernellib_name() {
   if (!best_match) {
     POCL_MSG_WARN("Can't find a kernellib supported by the host CPU (%s)\n",
                   llvm::sys::getHostCPUName());
-    return "";
+    return NULL;
   }
 
   return best_match->kernellib_name;
 }
+
+/* for "distro" style kernel libs, return which target cpu to use for a given
+ * kernellib */
+const char *pocl_get_distro_cpu_name(const char *kernellib_name) {
+  StringMap<bool> Features;
+
+  if (!llvm::sys::getHostCPUFeatures(Features)) {
+    POCL_MSG_WARN("LLVM can't get host CPU flags!\n");
+    return NULL;
+  }
+
+  const kernellib_features *best_match = NULL;
+  for (const kernellib_features *kf = kernellib_feature_map; kf->kernellib_name;
+       ++kf) {
+    if (!strcmp(kernellib_name, kf->kernellib_name))
+      return kf->cpu_name;
+  }
+
+  POCL_MSG_WARN("Can't find a cpu name matching the kernellib (%s)\n",
+                kernellib_name);
+  return NULL;
+}
 #endif
 
 int pocl_bitcode_is_triple(const char *bitcode, size_t size, const char *triple) {