From b013372e7e02461bf5e67845b333030eee164bea Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 8 Mar 2011 16:33:17 -0800 Subject: volk: replace posix_memalign with something cross platform --- volk/lib/qa_utils.cc | 57 ++++++++++++++++++++++++---------------------------- volk/lib/qa_utils.h | 2 +- 2 files changed, 27 insertions(+), 32 deletions(-) (limited to 'volk/lib') diff --git a/volk/lib/qa_utils.cc b/volk/lib/qa_utils.cc index e85e2c1bc..710d56fb8 100644 --- a/volk/lib/qa_utils.cc +++ b/volk/lib/qa_utils.cc @@ -1,19 +1,20 @@ #include "qa_utils.h" -#include +#include #include #include #include //#include #include #include -#include -#include +#include +#include #include //#include #include #include #include #include +#include float uniform() { return 2.0 * ((float) rand() / RAND_MAX - 0.5); // uniformly (-1, 1) @@ -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 &buffs, std::vector 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 get_arch_list(const int archs[]) { std::vector archlist; int num_archs = archs[0]; @@ -282,6 +267,18 @@ 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){ + boost::shared_array mem(new char[size + alignment-1]); + size_t ptr = size_t(mem.get() + alignment-1) & ~(alignment-1); + std::memset((void *)ptr, 0x00, size); + _mems.push_back(mem); + return (void *)ptr; + } +private: std::vector > _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 +289,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 inputsig, outputsig; get_signatures_from_name(inputsig, outputsig, name); @@ -309,12 +309,12 @@ bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, //for(int i=0; i inbuffs; - std::vector 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 arch_buffs; for(int j=0; j +#include #include struct volk_type_t { -- cgit From 888beebf6015d9a88dbd1c3c842cf2490899a99b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 14 Mar 2011 09:33:00 -0700 Subject: volk: simplify the get new method for the aligned pool --- volk/lib/qa_utils.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'volk/lib') diff --git a/volk/lib/qa_utils.cc b/volk/lib/qa_utils.cc index 710d56fb8..b0f63d2b5 100644 --- a/volk/lib/qa_utils.cc +++ b/volk/lib/qa_utils.cc @@ -6,6 +6,7 @@ //#include #include #include +#include #include #include #include @@ -14,7 +15,6 @@ #include #include #include -#include float uniform() { return 2.0 * ((float) rand() / RAND_MAX - 0.5); // uniformly (-1, 1) @@ -270,13 +270,11 @@ bool icompare(t *in1, t *in2, unsigned int vlen, unsigned int tol) { class volk_qa_aligned_mem_pool{ public: void *get_new(size_t size, size_t alignment = 16){ - boost::shared_array mem(new char[size + alignment-1]); - size_t ptr = size_t(mem.get() + alignment-1) & ~(alignment-1); - std::memset((void *)ptr, 0x00, size); - _mems.push_back(mem); - return (void *)ptr; + _mems.push_back(std::vector(size + alignment-1, 0)); + size_t ptr = size_t(&_mems.back().front()); + return (void *)((ptr + alignment-1) & ~(alignment-1)); } -private: std::vector > _mems; +private: std::list > _mems; }; bool run_volk_tests(const int archs[], void (*manual_func)(), std::string name, float tol, float scalar, int vlen, int iter) { -- cgit