From c452aecb2155e365efb1077e1e550991a651e32e Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Sun, 26 Sep 2021 16:56:41 +0200 Subject: [PATCH 1/3] index: Fix volk_get_index This function results in an infinite loop on Debian 11 for some impls. This is a first step to fix it. Fix #516 Signed-off-by: Johannes Demel --- lib/volk_rank_archs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/volk_rank_archs.c b/lib/volk_rank_archs.c index 58bbbc653..075450465 100644 --- a/lib/volk_rank_archs.c +++ b/lib/volk_rank_archs.c @@ -22,13 +22,16 @@ int volk_get_index(const char* impl_names[], // list of implementations by name { unsigned int i; for (i = 0; i < n_impls; i++) { - if (!strncmp(impl_names[i], impl_name, 20)) { + if (!strncmp(impl_names[i], impl_name, 42)) { return i; } } // TODO return -1; // something terrible should happen here fprintf(stderr, "Volk warning: no arch found, returning generic impl\n"); + if (strncmp(impl_name, "generic", 20)) { + return -1; + } return volk_get_index(impl_names, n_impls, "generic"); // but we'll fake it for now } From 8fe7ed8d9da4aade43bc75cef56f4a3b309bb9b1 Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Sat, 2 Oct 2021 12:03:47 +0200 Subject: [PATCH 2/3] index: Restructure volk_get_index Instead of recursively calling `volk_get_index`, a new function is introduced to walk through the list of impls. Then, we introduce a three step process: 1. Search for the requested impl. Return index if found. 2. Search for the generic impl. Return index if found. 3. Return `-1` and put the burden on the caller. Signed-off-by: Johannes Demel --- lib/volk_rank_archs.c | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/volk_rank_archs.c b/lib/volk_rank_archs.c index 075450465..a2fd4451e 100644 --- a/lib/volk_rank_archs.c +++ b/lib/volk_rank_archs.c @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2011-2012 Free Software Foundation, Inc. + * Copyright 2011-2012, 2021 Free Software Foundation, Inc. * * This file is part of VOLK * @@ -15,24 +15,43 @@ #include #include -int volk_get_index(const char* impl_names[], // list of implementations by name - const size_t n_impls, // number of implementations available - const char* impl_name // the implementation name to find -) +// This function is supposed to be private to this compilation unit. +int volk_search_index(const char* impl_names[], + const size_t n_impls, + const char* impl_name) { unsigned int i; for (i = 0; i < n_impls; i++) { - if (!strncmp(impl_names[i], impl_name, 42)) { + if (strncmp(impl_names[i], impl_name, 42) != 0) { return i; } } - // TODO return -1; - // something terrible should happen here - fprintf(stderr, "Volk warning: no arch found, returning generic impl\n"); - if (strncmp(impl_name, "generic", 20)) { - return -1; + return -1; // Indicate we couldn't find anything! +} + +int volk_get_index(const char* impl_names[], // list of implementations by name + const size_t n_impls, // number of implementations available + const char* impl_name // the implementation name to find +) +{ + /* + * We follow a 3 step process. + * 1. Search for the requested impl. Return index if found. + * 2. Search for the generic impl. Return as fail-safe. + * 3. Return -1 to indicate an error. Caller needs to handle this case. + */ + int idx = volk_search_index(impl_names, n_impls, impl_name); + if (idx >= 0) { + return idx; + } + + idx = volk_search_index(impl_names, n_impls, "generic"); + if (idx >= 0) { + fprintf(stderr, "Volk warning: no arch found, returning generic impl\n"); + return idx; } - return volk_get_index(impl_names, n_impls, "generic"); // but we'll fake it for now + fprintf(stderr, "Volk warning: no arch found, returning -1 aka not found!\n"); + return -1; } int volk_rank_archs(const char* kern_name, // name of the kernel to rank From c1ed567b313ca22ff6054ab107ce6de2da7138fb Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Sat, 2 Oct 2021 12:31:49 +0200 Subject: [PATCH 3/3] index: Revert to !strncmp This fix is a bit of a guess. aarch64, MacOS, and Win CI tests all fail after I changed the comparison from `!` to `!= 0`. Signed-off-by: Johannes Demel --- lib/volk_rank_archs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/volk_rank_archs.c b/lib/volk_rank_archs.c index a2fd4451e..6eb4a98e6 100644 --- a/lib/volk_rank_archs.c +++ b/lib/volk_rank_archs.c @@ -22,7 +22,7 @@ int volk_search_index(const char* impl_names[], { unsigned int i; for (i = 0; i < n_impls; i++) { - if (strncmp(impl_names[i], impl_name, 42) != 0) { + if (!strncmp(impl_names[i], impl_name, 42)) { return i; } } @@ -48,10 +48,10 @@ int volk_get_index(const char* impl_names[], // list of implementations by name idx = volk_search_index(impl_names, n_impls, "generic"); if (idx >= 0) { fprintf(stderr, "Volk warning: no arch found, returning generic impl\n"); - return idx; + } else { + fprintf(stderr, "Volk ERROR: no arch found. generic impl missing!\n"); } - fprintf(stderr, "Volk warning: no arch found, returning -1 aka not found!\n"); - return -1; + return idx; } int volk_rank_archs(const char* kern_name, // name of the kernel to rank