Line data Source code
1 : #include <cassert> 2 : #include <iostream> 3 : 4 : #include <libsakura/sakura.h> 5 : 6 : #include <casacore/casa/Logging/LogIO.h> 7 : #include <casacore/casa/Logging/LogOrigin.h> 8 : 9 : namespace casa { 10 : template<typename T> 11 859362 : inline SakuraAlignedArray<T>::SakuraAlignedArray(size_t num_data) : 12 859362 : num_data_(num_data) { 13 : #if !defined(NDEBUG) 14 1718724 : casacore::LogIO logger(casacore::LogOrigin("SakuraAlignedArray", "SakuraAlignedArray", WHERE)); 15 859362 : logger << casacore::LogIO::DEBUGGING << "Constructing SakuraAlignedArray..." << casacore::LogIO::POST; 16 : #endif 17 : 18 859362 : initialize(); 19 : 20 : #if !defined(NDEBUG) 21 859362 : logger << casacore::LogIO::DEBUGGING << " Initial Address = " << storage_ << casacore::LogIO::POST; 22 859362 : logger << casacore::LogIO::DEBUGGING << " Aligned Address = " << data_ << casacore::LogIO::POST; 23 : #endif 24 859362 : } 25 : 26 : template<typename T> 27 138 : inline SakuraAlignedArray<T>::SakuraAlignedArray(casacore::Vector<T> const &in_vector) : 28 138 : num_data_(in_vector.nelements()) { 29 : #if !defined(NDEBUG) 30 276 : casacore::LogIO logger(casacore::LogOrigin("SakuraAlignedArray", "SakuraAlignedArray", WHERE)); 31 138 : logger << casacore::LogIO::DEBUGGING << "Constructing SakuraAlignedArray..." << casacore::LogIO::POST; 32 : #endif 33 : 34 138 : initialize(); 35 : 36 138 : T *ptr = data_; 37 15730 : for (size_t i = 0; i < num_data_; ++i) { 38 15592 : ptr[i] = in_vector(i); 39 : } 40 : 41 : #if !defined(NDEBUG) 42 138 : logger << casacore::LogIO::DEBUGGING << " Initial Address = " << storage_ << casacore::LogIO::POST; 43 138 : logger << casacore::LogIO::DEBUGGING << " Aligned Address = " << data_ << casacore::LogIO::POST; 44 : #endif 45 138 : } 46 : 47 : template<typename T> 48 859500 : inline void SakuraAlignedArray<T>::initialize() { 49 859500 : storage_ = nullptr; 50 859500 : data_ = nullptr; 51 : 52 859500 : size_t size_required = sizeof(T) * num_data_; 53 859500 : size_t size_of_arena = size_required + LIBSAKURA_SYMBOL(GetAlignment)() - 1; 54 859500 : storage_ = malloc(size_of_arena); 55 859500 : if (storage_ == nullptr) { 56 0 : data_ = nullptr; 57 0 : throw std::bad_alloc(); 58 : } 59 859500 : data_ = reinterpret_cast<T *>(LIBSAKURA_SYMBOL(AlignAny)( 60 : size_of_arena, storage_, size_required)); 61 859500 : assert(data_ != nullptr); 62 859500 : assert(LIBSAKURA_SYMBOL(IsAligned)(data_)); 63 859500 : } 64 : 65 : template<typename T> 66 859500 : inline SakuraAlignedArray<T>::~SakuraAlignedArray() { 67 : #if !defined(NDEBUG) 68 1719000 : casacore::LogIO logger(casacore::LogOrigin("SakuraAlignedArray", "~SakuraAlignedArray", WHERE)); 69 859500 : logger << casacore::LogIO::DEBUGGING << "Destructing SakuraAlignedArray..." << casacore::LogIO::POST; 70 : #endif 71 : 72 859500 : free(storage_); 73 859500 : } 74 : 75 : } // End of casa namespace.