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

github.com/marian-nmt/intgemm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkpu <github@kheafield.com>2018-06-23 19:43:02 +0300
committerkpu <github@kheafield.com>2018-06-23 19:43:02 +0300
commitfaf1ac0293ce8c5c2b5e4eb25b785bdafd77fdd0 (patch)
treef03981a2b1c95e50f1dd3ab259db3e00d7ad9bee /aligned.h
parent559fb9b392bcf52e5b77c08fcd49d0f439582413 (diff)
Simplify aligned allocation, reduce C++ version
Diffstat (limited to 'aligned.h')
-rw-r--r--aligned.h33
1 files changed, 11 insertions, 22 deletions
diff --git a/aligned.h b/aligned.h
index a1a3ba1..733477a 100644
--- a/aligned.h
+++ b/aligned.h
@@ -1,38 +1,27 @@
#pragma once
-// Define allocation like:
-// free_ptr<Integer> quantized(AlignedArray<Integer>(rows * cols));
+// Aligned vector of things.
// This is only used by tests.
#include <cstdlib>
-#include <memory>
namespace intgemm {
-struct DeleteWithFree {
- template <class T> void operator() (T *t) const {
-// This requires newer C++
-// std::free(const_cast<std::remove_const_t<T>* >(t));
- std::free(t);
- }
-};
-template <class T> using free_ptr = std::unique_ptr<T, DeleteWithFree>;
-// Return memory suitably aligned for SIMD.
-template <class T> T* AlignedArray(std::size_t size) {
- return static_cast<T*>(aligned_alloc(64, size * sizeof(T)));
-}
-
template <class T> class AlignedVector {
public:
- explicit AlignedVector(std::size_t size) : mem_(AlignedArray<T>(size)) {}
+ explicit AlignedVector(std::size_t size)
+ : mem_(static_cast<T*>(aligned_alloc(64, size * sizeof(T)))) {}
+
+ ~AlignedVector() { std::free(mem_); }
+
+ T &operator[](std::size_t offset) { return mem_[offset]; }
+ const T &operator[](std::size_t offset) const { return mem_[offset]; }
- T &operator[](std::size_t offset) { return mem_.get()[offset]; }
- const T &operator[](std::size_t offset) const { return mem_.get()[offset]; }
+ T *get() { return mem_; }
+ const T *get() const { return mem_; }
- T *get() { return mem_.get(); }
- const T *get() const { return mem_.get(); }
private:
- free_ptr<T> mem_;
+ T *mem_;
};
} // namespace intgemm