diff options
author | Nick Foster <nick@ettus.com> | 2011-05-12 14:21:17 -0700 |
---|---|---|
committer | Nick Foster <nick@ettus.com> | 2011-05-12 14:21:17 -0700 |
commit | 30fdc38d20d4e38908059b6e351c550de5741621 (patch) | |
tree | 2f74d3bd790bfbae2ca7e4ccac963446e8cb86be | |
parent | b50dbc4498842fecd7f0c6adc22f25726f8d27d3 (diff) |
Volk: profiling works. loads prefs on init. volk_rank_archs looks in prefs first.
-rw-r--r-- | volk/apps/CMakeLists.txt | 1 | ||||
-rw-r--r-- | volk/apps/volk_profile.cc | 11 | ||||
-rw-r--r-- | volk/gen/make_c.py | 14 | ||||
-rw-r--r-- | volk/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | volk/lib/volk_rank_archs.c | 92 | ||||
-rw-r--r-- | volk/lib/volk_rank_archs.h | 3 |
6 files changed, 37 insertions, 85 deletions
diff --git a/volk/apps/CMakeLists.txt b/volk/apps/CMakeLists.txt index 752cbc6795..a0bf7e900d 100644 --- a/volk/apps/CMakeLists.txt +++ b/volk/apps/CMakeLists.txt @@ -33,7 +33,6 @@ INCLUDE_DIRECTORIES( ADD_EXECUTABLE(volk_profile ${CMAKE_CURRENT_SOURCE_DIR}/volk_profile.cc ${CMAKE_SOURCE_DIR}/lib/qa_utils.cc - ${CMAKE_SOURCE_DIR}/lib/volk_prefs.cc ) TARGET_LINK_LIBRARIES(volk_profile volk ${Boost_LIBRARIES}) diff --git a/volk/apps/volk_profile.cc b/volk/apps/volk_profile.cc index eb7b708873..49e6db3fca 100644 --- a/volk/apps/volk_profile.cc +++ b/volk/apps/volk_profile.cc @@ -1,6 +1,8 @@ #include "qa_utils.h" +extern "C" { #include <volk/volk.h> #include <volk/volk_prefs.h> +} #include <vector> #include <boost/foreach.hpp> #include <iostream> @@ -9,8 +11,10 @@ int main(int argc, char *argv[]) { std::vector<std::string> results; - std::string config_path = get_config_path(); -/* + char path[256]; + get_config_path(path); + std::string config_path(path); + //VOLK_PROFILE(volk_16i_x5_add_quad_16i_x4_a16, 1e-4, 2046, 10000, &results); //VOLK_PROFILE(volk_16i_branch_4_state_8_a16, 1e-4, 2046, 10000, &results); VOLK_PROFILE(volk_16ic_s32f_deinterleave_real_32f_a16, 1e-5, 32768.0, 204600, 10000, &results); @@ -97,7 +101,6 @@ int main(int argc, char *argv[]) { VOLK_PROFILE(volk_8ic_x2_s32f_multiply_conjugate_32fc_a16, 1e-4, 100, 204600, 400, &results); VOLK_PROFILE(volk_8i_convert_16i_a16, 0, 0, 204600, 20000, &results); VOLK_PROFILE(volk_8i_convert_16i_u, 0, 0, 204600, 2000, &results); -*/ VOLK_PROFILE(volk_8i_s32f_convert_32f_a16, 1e-4, 100, 204600, 2000, &results); VOLK_PROFILE(volk_8i_s32f_convert_32f_u, 1e-4, 100, 204600, 2000, &results); @@ -114,6 +117,4 @@ int main(int argc, char *argv[]) { config << result << std::endl; } config.close(); - - load_preferences(); } diff --git a/volk/gen/make_c.py b/volk/gen/make_c.py index 11b614644b..fa08bbb0e4 100644 --- a/volk/gen/make_c.py +++ b/volk/gen/make_c.py @@ -66,23 +66,11 @@ struct volk_machine *get_machine(void) { } } -static unsigned int get_index(const char *indices[], unsigned int n_archs, const char *arch_name) { - int i; - for(i=0; i<n_archs; i++) { - if(!strncmp(indices[i], arch_name, 20)) { - return i; - } - } - //something terrible should happen here - printf("Volk warning: no arch found, returning generic impl\n"); - return get_index(indices, n_archs, "generic"); //but we'll fake it for now -} - """ for i in range(len(functions)): tempstring += "void get_" + functions[i] + replace_arch.sub("", arched_arglist[i]) + "\n" - tempstring += " %s = get_machine()->%s_archs[volk_rank_archs(get_machine()->%s_arch_defs, get_machine()->%s_n_archs, get_machine()->%s_name, volk_get_lvarch())];\n" % (functions[i], functions[i], functions[i], functions[i], functions[i]) + tempstring += " %s = get_machine()->%s_archs[volk_rank_archs(get_machine()->%s_indices, get_machine()->%s_arch_defs, get_machine()->%s_n_archs, get_machine()->%s_name, volk_get_lvarch())];\n" % (functions[i], functions[i], functions[i], functions[i], functions[i], functions[i]) tempstring += " %s(%s);\n}\n\n" % (functions[i], my_arglist[i]) tempstring += replace_volk.sub("p", functions[i]) + " " + functions[i] + " = &get_" + functions[i] + ";\n\n" tempstring += "void %s_manual%s\n" % (functions[i], arched_arglist[i]) diff --git a/volk/lib/CMakeLists.txt b/volk/lib/CMakeLists.txt index dfb1d42195..df0a224dba 100644 --- a/volk/lib/CMakeLists.txt +++ b/volk/lib/CMakeLists.txt @@ -176,6 +176,7 @@ INCLUDE_DIRECTORIES( SET(volk_sources ${CMAKE_CURRENT_BINARY_DIR}/volk.c ${CMAKE_CURRENT_BINARY_DIR}/volk_cpu.c + ${CMAKE_CURRENT_SOURCE_DIR}/volk_prefs.c ${CMAKE_CURRENT_SOURCE_DIR}/volk_rank_archs.c ${CMAKE_CURRENT_BINARY_DIR}/volk_machines.c ) diff --git a/volk/lib/volk_rank_archs.c b/volk/lib/volk_rank_archs.c index 14f1789dac..1b75af8f4a 100644 --- a/volk/lib/volk_rank_archs.c +++ b/volk/lib/volk_rank_archs.c @@ -1,78 +1,40 @@ #include <volk_rank_archs.h> +#include <volk/volk_prefs.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#if defined(_WIN32) -#include <Windows.h> -#endif - -//this should be used by the profiler app to find the path as well -//possibly all this stuff should go in a separate volk_prefs.cc -void get_config_path(char *path) { - const char *suffix = "/.gnuradio/volk_config"; - memcpy(path, getenv("HOME"), strlen(getenv("HOME"))+1); - strcat(path, suffix); -} - -/* - * ok so volk stuff has to be loaded piecemeal, and to avoid reading - * the whole config file in at startup we should probably create a static - * prefs struct that can be read in by rank_archs with minimal modification. - * this makes rank_archs slower and load_preferences more complex, but - * we don't have to export load_preferences and we don't have to include volk.h. - * means we need to pass the name into rank_archs, though - * problem is that names don't appear anywhere in the volk function descriptor. - * so we have to modify things to include the name in the descriptor. - * - * also means you don't have to also spec the fn name in qa_utils.h/c, you can - * pass it in along with the func_desc - * - * your prefs reader should also have a prefs writer which takes a vector of prefs and writes them - * then your profiler can just write the prefs by passing that out - * - */ - -struct volk_arch_pref { - const char *name; - const char *arch; -}; - -//if we end up with more this will have to use realloc -struct volk_arch_pref volk_arch_prefs[400]; - -void load_preferences(void) { - static int prefs_loaded = 0; - FILE *config_file; - char path[512], line[512], function[256], arch[64]; - - if(prefs_loaded) return; - - int n_arch_preferences = 0; - - //get the config path - get_config_path(path); - config_file = fopen(path, "r"); - if(!config_file) return; //no prefs found - - while(fgets(line, 512, config_file) != NULL) { - if(sscanf(line, "%s %s", function, arch) == 2 && !strncmp(function, "volk_", 5)) { - printf("func: %s, arch: %s\n", function, arch); - //we have a function and we have an arch, let's set it - n_arch_preferences++; +unsigned int get_index(const char *indices[], unsigned int n_archs, const char *arch_name) { + int i; + for(i=0; i<n_archs; i++) { + if(!strncmp(indices[i], arch_name, 20)) { + return i; } } - - fclose(config_file); - - printf("Found %d prefs\n", n_arch_preferences); - prefs_loaded = 1; + //something terrible should happen here + printf("Volk warning: no arch found, returning generic impl\n"); + return get_index(indices, n_archs, "generic"); //but we'll fake it for now } -unsigned int volk_rank_archs(const int* arch_defs, unsigned int n_archs, const char* name, unsigned int arch) { - int i = 1; +unsigned int volk_rank_archs(const char *indices[], const int* arch_defs, unsigned int n_archs, const char* name, unsigned int arch) { + int i; unsigned int best_val = 0; - for(; i < n_archs; ++i) { + static struct volk_arch_pref *volk_arch_prefs; + static int n_arch_prefs = 0; + static int prefs_loaded = 0; + if(!prefs_loaded) { + n_arch_prefs = load_preferences(&volk_arch_prefs); + prefs_loaded = 1; + } + + //now look for the function name in the prefs list + for(i=0; i < n_arch_prefs; i++) { + if(!strncmp(name, volk_arch_prefs[i].name, 128)) { //found it + best_val = get_index(indices, n_archs, volk_arch_prefs[i].arch); + } + } + + for(i=1; i < n_archs; ++i) { if((arch_defs[i]&(!arch)) == 0) { best_val = (arch_defs[i] > arch_defs[best_val + 1]) ? i-1 : best_val; } diff --git a/volk/lib/volk_rank_archs.h b/volk/lib/volk_rank_archs.h index ba248aa59a..546240d2c6 100644 --- a/volk/lib/volk_rank_archs.h +++ b/volk/lib/volk_rank_archs.h @@ -5,7 +5,8 @@ extern "C" { #endif -unsigned int volk_rank_archs(const int* arch_defs, unsigned int n_archs, const char *name, unsigned int arch); +unsigned int get_index(const char *indices[], unsigned int n_archs, const char *arch_name); +unsigned int volk_rank_archs(const char *indices[], const int* arch_defs, unsigned int n_archs, const char *name, unsigned int arch); #ifdef __cplusplus } |