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 859342 : inline SakuraAlignedArray<T>::SakuraAlignedArray(size_t num_data) : 12 859342 : num_data_(num_data) { 13 : #if !defined(NDEBUG) 14 2578026 : casacore::LogIO logger(casacore::LogOrigin("SakuraAlignedArray", "SakuraAlignedArray", WHERE)); 15 859342 : logger << casacore::LogIO::DEBUGGING << "Constructing SakuraAlignedArray..." << casacore::LogIO::POST; 16 : #endif 17 : 18 859342 : initialize(); 19 : 20 : #if !defined(NDEBUG) 21 859342 : logger << casacore::LogIO::DEBUGGING << " Initial Address = " << storage_ << casacore::LogIO::POST; 22 859342 : logger << casacore::LogIO::DEBUGGING << " Aligned Address = " << data_ << casacore::LogIO::POST; 23 : #endif 24 859342 : } 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 414 : 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 859480 : inline void SakuraAlignedArray<T>::initialize() { 49 859480 : storage_ = nullptr; 50 859480 : data_ = nullptr; 51 : 52 859480 : size_t size_required = sizeof(T) * num_data_; 53 859480 : size_t size_of_arena = size_required + LIBSAKURA_SYMBOL(GetAlignment)() - 1; 54 859480 : storage_ = malloc(size_of_arena); 55 859480 : if (storage_ == nullptr) { 56 0 : data_ = nullptr; 57 0 : throw std::bad_alloc(); 58 : } 59 859480 : data_ = reinterpret_cast<T *>(LIBSAKURA_SYMBOL(AlignAny)( 60 : size_of_arena, storage_, size_required)); 61 859480 : assert(data_ != nullptr); 62 859480 : assert(LIBSAKURA_SYMBOL(IsAligned)(data_)); 63 859480 : } 64 : 65 : template<typename T> 66 859480 : inline SakuraAlignedArray<T>::~SakuraAlignedArray() { 67 : #if !defined(NDEBUG) 68 1718960 : casacore::LogIO logger(casacore::LogOrigin("SakuraAlignedArray", "~SakuraAlignedArray", WHERE)); 69 859480 : logger << casacore::LogIO::DEBUGGING << "Destructing SakuraAlignedArray..." << casacore::LogIO::POST; 70 : #endif 71 : 72 859480 : free(storage_); 73 859480 : } 74 : 75 : } // End of casa namespace.