Skip to content

Commit

Permalink
Merge remote-tracking branch 'nwest/volk-json'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcorgan committed Sep 19, 2014
2 parents 2a58321 + 49252d9 commit 99c0bae
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 13 deletions.
61 changes: 58 additions & 3 deletions apps/volk_profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,49 @@

namespace fs = boost::filesystem;

void write_json(std::ofstream &json_file, std::vector<volk_test_results_t> results) {
json_file << "{" << std::endl;
json_file << " \"volk_tests\": [" << std::endl;
size_t len = results.size();
size_t i = 0;
BOOST_FOREACH(volk_test_results_t &result, results) {
json_file << " {" << std::endl;
json_file << " \"name\": \"" << result.name << "\"," << std::endl;
json_file << " \"vlen\": " << result.vlen << "," << std::endl;
json_file << " \"iter\": " << result.iter << "," << std::endl;
json_file << " \"best_arch_a\": \"" << result.best_arch_a
<< "\"," << std::endl;
json_file << " \"best_arch_u\": \"" << result.best_arch_u
<< "\"," << std::endl;
json_file << " \"results\": {" << std::endl;
size_t results_len = result.results.size();
size_t ri = 0;
typedef std::pair<std::string, volk_test_time_t> tpair;
BOOST_FOREACH(tpair pair, result.results) {
volk_test_time_t time = pair.second;
json_file << " \"" << time.name << "\": {" << std::endl;
json_file << " \"name\": \"" << time.name << "\"," << std::endl;
json_file << " \"time\": " << time.time << "," << std::endl;
json_file << " \"units\": \"" << time.units << "\"" << std::endl;
json_file << " }" ;
if(ri+1 != results_len) {
json_file << ",";
}
json_file << std::endl;
ri++;
}
json_file << " }" << std::endl;
json_file << " }";
if(i+1 != len) {
json_file << ",";
}
json_file << std::endl;
i++;
}
json_file << " ]" << std::endl;
json_file << "}" << std::endl;
}

int main(int argc, char *argv[]) {
// Adding program options
boost::program_options::options_description desc("Options");
Expand All @@ -49,13 +92,18 @@ int main(int argc, char *argv[]) {
("tests-regex,R",
boost::program_options::value<std::string>(),
"Run tests matching regular expression.")
("json,j",
boost::program_options::value<std::string>(),
"JSON output file")
;

// Handle the options that were given
boost::program_options::variables_map vm;
bool benchmark_mode;
std::string kernel_regex;
bool store_results = true;
std::ofstream json_file;

try {
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);
Expand Down Expand Up @@ -83,9 +131,14 @@ int main(int argc, char *argv[]) {
return 0;
}

if ( vm.count("json") )
{
json_file.open( vm["json"].as<std::string>().c_str() );
}


// Run tests
std::vector<std::string> results;
std::vector<volk_test_results_t> results;

//VOLK_PROFILE(volk_16i_x5_add_quad_16i_x4, 1e-4, 2046, 10000, &results, benchmark_mode, kernel_regex);
//VOLK_PROFILE(volk_16i_branch_4_state_8, 1e-4, 2046, 10000, &results, benchmark_mode, kernel_regex);
Expand Down Expand Up @@ -205,8 +258,10 @@ int main(int argc, char *argv[]) {
#the function name is followed by the preferred architecture.\n\
";

BOOST_FOREACH(std::string result, results) {
config << result << std::endl;
BOOST_FOREACH(volk_test_results_t result, results) {
config << result.config_name << " "
<< result.best_arch_a << " "
<< result.best_arch_u << std::endl;
}
config.close();
}
Expand Down
32 changes: 24 additions & 8 deletions lib/qa_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <boost/tokenizer.hpp>
#include <boost/xpressive/xpressive.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <list>
#include <ctime>
#include <cmath>
Expand Down Expand Up @@ -328,16 +330,22 @@ bool run_volk_tests(volk_func_desc_t desc,
lv_32fc_t scalar,
int vlen,
int iter,
std::vector<std::string> *best_arch_vector = 0,
std::string puppet_master_name = "NULL",
bool benchmark_mode,
std::vector<volk_test_results_t> *results,
std::string puppet_master_name,
bool benchmark_mode,
std::string kernel_regex
) {
boost::xpressive::sregex kernel_expression = boost::xpressive::sregex::compile(kernel_regex);
if( !boost::xpressive::regex_search(name, kernel_expression) ) {
// in this case we have a regex and are only looking to test one kernel
return false;
}
if(results) {
results->push_back(volk_test_results_t());
results->back().name = name;
results->back().vlen = vlen;
results->back().iter = iter;
}
std::cout << "RUN_VOLK_TESTS: " << name << "(" << vlen << "," << iter << ")" << std::endl;

// The multiply and lv_force_cast_hf are work arounds for GNU Radio bugs 582 and 583
Expand Down Expand Up @@ -453,6 +461,13 @@ bool run_volk_tests(volk_func_desc_t desc,
end = clock();
double arch_time = 1000.0 * (double)(end-start)/(double)CLOCKS_PER_SEC;
std::cout << arch_list[i] << " completed in " << arch_time << "ms" << std::endl;
if(results) {
volk_test_time_t result;
result.name = arch_list[i];
result.time = arch_time;
result.units = "ms";
results->back().results[result.name] = result;
}

profile_times.push_back(arch_time);
}
Expand Down Expand Up @@ -553,13 +568,14 @@ bool run_volk_tests(volk_func_desc_t desc,

std::cout << "Best aligned arch: " << best_arch_a << std::endl;
std::cout << "Best unaligned arch: " << best_arch_u << std::endl;
if(best_arch_vector) {
if(results) {
if(puppet_master_name == "NULL") {
best_arch_vector->push_back(name + " " + best_arch_a + " " + best_arch_u);
}
else {
best_arch_vector->push_back(puppet_master_name + " " + best_arch_a + " " + best_arch_u);
results->back().config_name = name;
} else {
results->back().config_name = puppet_master_name;
}
results->back().best_arch_a = best_arch_a;
results->back().best_arch_u = best_arch_u;
}

return fail_global;
Expand Down
43 changes: 41 additions & 2 deletions lib/qa_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

#include <cstdlib>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <volk/volk.h>
#include <volk/volk_common.h>

Expand All @@ -21,10 +24,46 @@ volk_type_t volk_type_from_string(std::string);
float uniform(void);
void random_floats(float *buf, unsigned n);

bool run_volk_tests(volk_func_desc_t, void(*)(), std::string, float, lv_32fc_t, int, int, std::vector<std::string> *, std::string, bool benchmark_mode=false, std::string kernel_regex="");
class volk_test_time_t {
public:
std::string name;
double time;
std::string units;
};

class volk_test_results_t {
public:
std::string name;
std::string config_name;
int vlen;
int iter;
std::map<std::string, volk_test_time_t> results;
std::string best_arch_a;
std::string best_arch_u;
};

bool run_volk_tests(
volk_func_desc_t,
void(*)(),
std::string,
float,
lv_32fc_t,
int,
int,
std::vector<volk_test_results_t> *results = NULL,
std::string puppet_master_name = "NULL",
bool benchmark_mode=false,
std::string kernel_regex=""
);


#define VOLK_RUN_TESTS(func, tol, scalar, len, iter) BOOST_AUTO_TEST_CASE(func##_test) { BOOST_CHECK_EQUAL(run_volk_tests(func##_get_func_desc(), (void (*)())func##_manual, std::string(#func), tol, scalar, len, iter, 0, "NULL"), 0); }
#define VOLK_RUN_TESTS(func, tol, scalar, len, iter) \
BOOST_AUTO_TEST_CASE(func##_test) { \
BOOST_CHECK_EQUAL(run_volk_tests( \
func##_get_func_desc(), (void (*)())func##_manual, \
std::string(#func), tol, scalar, len, iter, 0, "NULL"), \
0); \
}
#define VOLK_PROFILE(func, tol, scalar, len, iter, results, bnmode, kernel_regex) run_volk_tests(func##_get_func_desc(), (void (*)())func##_manual, std::string(#func), tol, scalar, len, iter, results, "NULL", bnmode, kernel_regex)
#define VOLK_PUPPET_PROFILE(func, puppet_master_func, tol, scalar, len, iter, results, bnmode, kernel_regex) run_volk_tests(func##_get_func_desc(), (void (*)())func##_manual, std::string(#func), tol, scalar, len, iter, results, std::string(#puppet_master_func), bnmode, kernel_regex)
typedef void (*volk_fn_1arg)(void *, unsigned int, const char*); //one input, operate in place
Expand Down

0 comments on commit 99c0bae

Please sign in to comment.