Skip to content
Permalink
Browse files

Fix issue #778 - assert fail in cpu_setup_vector_widths()

  • Loading branch information
Michal Babej
Michal Babej committed Mar 22, 2020
1 parent e51448d commit e64cc2a08eeca19a259258c8c8ae4850d9cdb1d7
Showing with 16 additions and 10 deletions.
  1. +7 −1 lib/CL/pocl_llvm_build.cc
  2. +9 −9 lib/CL/pocl_llvm_utils.cc
@@ -768,9 +768,15 @@ int pocl_llvm_link_program(cl_program program, unsigned device_i,
#ifdef KERNELLIB_HOST_DISTRO_VARIANTS
const char *getX86KernelLibName() {
StringMap<bool> Features;
llvm::sys::getHostCPUFeatures(Features);
const char *res = NULL;

if (!llvm::sys::getHostCPUFeatures(Features)) {
POCL_MSG_WARN ("getX86KernelLibName(): LLVM can't get host CPU flags!\n");
/* getX86KernelLibName should only ever be enabled
on x86-64, which always has sse2 */
return "sse2";
}

if (Features["sse2"])
res = "sse2";
else
@@ -168,8 +168,7 @@ int bitcode_is_spirv(const char *bitcode, size_t size, int *is_opencl) {
int cpu_has_fma() {
StringMap<bool> features;
bool res = llvm::sys::getHostCPUFeatures(features);
assert(res);
return ((features["fma"] || features["fma4"]) ? 1 : 0);
return ((res && (features["fma"] || features["fma4"])) ? 1 : 0);
}

#define VECWIDTH(x) \
@@ -178,14 +177,15 @@ int cpu_has_fma() {
void cpu_setup_vector_widths(cl_device_id dev) {
StringMap<bool> features;
bool res = llvm::sys::getHostCPUFeatures(features);
assert(res);
unsigned lane_width = 1;
if ((features["sse"]) || (features["neon"]))
lane_width = 16;
if (features["avx"])
lane_width = 32;
if (features["avx512f"])
lane_width = 64;
if (res) {
if ((features["sse"]) || (features["neon"]))
lane_width = 16;
if (features["avx"])
lane_width = 32;
if (features["avx512f"])
lane_width = 64;
}

dev->native_vector_width_char = dev->preferred_vector_width_char =
VECWIDTH(cl_char);

0 comments on commit e64cc2a

Please sign in to comment.
You can’t perform that action at this time.