Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/intgemm/intgemm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2021-04-01 01:28:07 +0300
committerKenneth Heafield <github@kheafield.com>2021-04-01 01:28:07 +0300
commitd3657687c9b84d2ea2ea39b2fac7b89597bde848 (patch)
treedb98acbd4b212de166b0670e5dc60db5426af1ca
parent1a176394bb0c2d243c42fe574e063924a92aa120 (diff)
Move sematics for AlignedVector
-rw-r--r--intgemm/aligned.h23
1 files changed, 19 insertions, 4 deletions
diff --git a/intgemm/aligned.h b/intgemm/aligned.h
index 7500a8c..6fda369 100644
--- a/intgemm/aligned.h
+++ b/intgemm/aligned.h
@@ -5,24 +5,39 @@
#include <malloc.h>
#endif
-// 64-byte aligned simple vector.
+// Aligned simple vector.
namespace intgemm {
template <class T> class AlignedVector {
public:
- explicit AlignedVector(std::size_t size)
+ AlignedVector() : mem_(nullptr), size_(0) {}
+
+ explicit AlignedVector(std::size_t size, std::size_t alignment = 64 /* CPU cares about this */)
: size_(size) {
#ifdef _MSC_VER
- mem_ = static_cast<T*>(_aligned_malloc(size * sizeof(T), 64));
+ mem_ = static_cast<T*>(_aligned_malloc(size * sizeof(T), alignment));
if (!mem_) throw std::bad_alloc();
#else
- if (posix_memalign(reinterpret_cast<void **>(&mem_), 64, size * sizeof(T))) {
+ if (posix_memalign(reinterpret_cast<void **>(&mem_), alignment, size * sizeof(T))) {
throw std::bad_alloc();
}
#endif
}
+ AlignedVector(AlignedVector &&from) : mem_(from.mem_), size_(from.size_) {
+ from.mem_ = nullptr;
+ from.size_ = 0;
+ }
+
+ AlignedVector &operator=(AlignedVector &&from) {
+ mem_ = from.mem_;
+ size_ = from.size_;
+ from.mem_ = nullptr;
+ from.size_ = 0;
+ return *this;
+ }
+
AlignedVector(const AlignedVector&) = delete;
AlignedVector& operator=(const AlignedVector&) = delete;