diff options
Diffstat (limited to 'volk/lib')
-rw-r--r-- | volk/lib/.gitignore | 1 | ||||
-rw-r--r-- | volk/lib/Makefile.am | 5 | ||||
-rw-r--r-- | volk/lib/qa_utils.cc | 55 | ||||
-rw-r--r-- | volk/lib/qa_utils.h | 2 |
4 files changed, 29 insertions, 34 deletions
diff --git a/volk/lib/.gitignore b/volk/lib/.gitignore index 0f17543ab..6a5fde28f 100644 --- a/volk/lib/.gitignore +++ b/volk/lib/.gitignore @@ -20,3 +20,4 @@ /volk_proccpu_sim.c /volk_runtime.c /test_all +/testqa diff --git a/volk/lib/Makefile.am b/volk/lib/Makefile.am index 3e5502369..473acd2a6 100644 --- a/volk/lib/Makefile.am +++ b/volk/lib/Makefile.am @@ -119,8 +119,9 @@ noinst_PROGRAMS = \ testqa testqa_SOURCES = testqa.cc qa_utils.cc -testqa_CPPFLAGS = -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN $(AM_CPPFLAGS) -testqa_LDFLAGS = $(BOOST_UNIT_TEST_FRAMEWORK_LIB) +testqa_CPPFLAGS = -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN $(AM_CPPFLAGS) \ + $(BOOST_CPPFLAGS) +testqa_LDFLAGS = $(BOOST_LDFLAGS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) if LV_HAVE_ORC testqa_LDADD = \ libvolk.la \ diff --git a/volk/lib/qa_utils.cc b/volk/lib/qa_utils.cc index e85e2c1bc..b0f63d2b5 100644 --- a/volk/lib/qa_utils.cc +++ b/volk/lib/qa_utils.cc @@ -1,13 +1,14 @@ #include "qa_utils.h" -#include <stdlib.h> +#include <cstring> #include <boost/foreach.hpp> #include <boost/assign/list_of.hpp> #include <boost/tokenizer.hpp> //#include <boost/test/unit_test.hpp> #include <iostream> #include <vector> -#include <time.h> -#include <math.h> +#include <list> +#include <ctime> +#include <cmath> #include <boost/lexical_cast.hpp> //#include <volk/volk_runtime.h> #include <volk/volk_registry.h> @@ -61,22 +62,6 @@ void load_random_data(void *data, volk_type_t type, unsigned int n) { } } -void *make_aligned_buffer(unsigned int len, unsigned int size) { - void *buf; - int ret; - ret = posix_memalign((void**)&buf, 16, len * size); - assert(ret == 0); - memset(buf, 0x00, len*size); - return buf; -} - -void make_buffer_for_signature(std::vector<void *> &buffs, std::vector<volk_type_t> inputsig, unsigned int vlen) { - BOOST_FOREACH(volk_type_t sig, inputsig) { - if(!sig.is_scalar) //we don't make buffers for scalars - buffs.push_back(make_aligned_buffer(vlen, sig.size*(sig.is_complex ? 2 : 1))); - } -} - static std::vector<std::string> get_arch_list(const int archs[]) { std::vector<std::string> archlist; int num_archs = archs[0]; @@ -282,6 +267,16 @@ bool icompare(t *in1, t *in2, unsigned int vlen, unsigned int tol) { return fail; } +class volk_qa_aligned_mem_pool{ +public: + void *get_new(size_t size, size_t alignment = 16){ + _mems.push_back(std::vector<char>(size + alignment-1, 0)); + size_t ptr = size_t(&_mems.back().front()); + return (void *)((ptr + alignment-1) & ~(alignment-1)); + } +private: std::list<std::vector<char> > _mems; +}; + bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, float tol, float scalar, int vlen, int iter) { std::cout << "RUN_VOLK_TESTS: " << name << std::endl; @@ -292,7 +287,10 @@ bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, std::cout << "no architectures to test" << std::endl; return false; } - + + //something that can hang onto memory and cleanup when this function exits + volk_qa_aligned_mem_pool mem_pool; + //now we have to get a function signature by parsing the name std::vector<volk_type_t> inputsig, outputsig; get_signatures_from_name(inputsig, outputsig, name); @@ -309,12 +307,12 @@ bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, //for(int i=0; i<inputsig.size(); i++) std::cout << "Input: " << inputsig[i].str << std::endl; //for(int i=0; i<outputsig.size(); i++) std::cout << "Output: " << outputsig[i].str << std::endl; std::vector<void *> inbuffs; - std::vector<void *> free_buffs; //this is just a list of void*'s that i'll have to free later. - //we need it because we dupe void*s in test_data below. - make_buffer_for_signature(inbuffs, inputsig, vlen); + BOOST_FOREACH(volk_type_t sig, inputsig) { + if(!sig.is_scalar) //we don't make buffers for scalars + inbuffs.push_back(mem_pool.get_new(vlen*sig.size*(sig.is_complex ? 2 : 1))); + } for(int i=0; i<inbuffs.size(); i++) { - load_random_data(inbuffs[i], inputsig[i], vlen); - free_buffs.push_back(inbuffs[i]); + load_random_data(inbuffs[i], inputsig[i], vlen); } //ok let's make a vector of vector of void buffers, which holds the input/output vectors for each arch @@ -322,8 +320,7 @@ bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, for(int i=0; i<arch_list.size(); i++) { std::vector<void *> arch_buffs; for(int j=0; j<outputsig.size(); j++) { - arch_buffs.push_back(make_aligned_buffer(vlen, outputsig[j].size*(outputsig[j].is_complex ? 2 : 1))); - free_buffs.push_back(arch_buffs.back()); + arch_buffs.push_back(mem_pool.get_new(vlen*outputsig[j].size*(outputsig[j].is_complex ? 2 : 1))); } for(int j=0; j<inputsig.size(); j++) { arch_buffs.push_back(inbuffs[j]); @@ -437,10 +434,6 @@ bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, } } - BOOST_FOREACH(void *buf, free_buffs) { - free(buf); - } - return fail_global; } diff --git a/volk/lib/qa_utils.h b/volk/lib/qa_utils.h index e2539060a..1b64bacaa 100644 --- a/volk/lib/qa_utils.h +++ b/volk/lib/qa_utils.h @@ -1,7 +1,7 @@ #ifndef VOLK_QA_UTILS_H #define VOLK_QA_UTILS_H -#include <stdlib.h> +#include <cstdlib> #include <string> struct volk_type_t { |