diff options
author | Arne Juul <arnej@verizonmedia.com> | 2020-02-11 11:20:51 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2020-02-11 11:24:45 +0000 |
commit | ad4701f0df41199eb4ef17a7e3698a5f9f6f3823 (patch) | |
tree | 0a463cee5d00e9808aba51cc91480b7ca89ab56b | |
parent | 47710bc9914f2a4fefef940ba53bbb5ecb60fc86 (diff) |
cannot use std::aligned_alloc
-rw-r--r-- | eval/src/tests/ann/remove-bm.cpp | 8 | ||||
-rw-r--r-- | eval/src/tests/ann/sift_benchmark.cpp | 10 |
2 files changed, 10 insertions, 8 deletions
diff --git a/eval/src/tests/ann/remove-bm.cpp b/eval/src/tests/ann/remove-bm.cpp index 2da735f1929..be010552ab8 100644 --- a/eval/src/tests/ann/remove-bm.cpp +++ b/eval/src/tests/ann/remove-bm.cpp @@ -30,15 +30,15 @@ struct PointVector { }; static PointVector *aligned_alloc(size_t num) { - size_t num_bytes = num * sizeof(PointVector); - double mega_bytes = num_bytes / (1024.0*1024.0); + size_t sz = num * sizeof(PointVector); + double mega_bytes = sz / (1024.0*1024.0); fprintf(stderr, "allocate %.2f MB of vectors\n", mega_bytes); - char *mem = (char *)malloc(num_bytes + 512); + char *mem = (char *)malloc(sz + 512); mem += 512; size_t val = (size_t)mem; size_t unalign = val % 512; mem -= unalign; - return (PointVector *)mem; + return reinterpret_cast<PointVector *>(mem); } static PointVector *generatedQueries = aligned_alloc(NUM_Q); diff --git a/eval/src/tests/ann/sift_benchmark.cpp b/eval/src/tests/ann/sift_benchmark.cpp index 7c060d86371..022c9404f5d 100644 --- a/eval/src/tests/ann/sift_benchmark.cpp +++ b/eval/src/tests/ann/sift_benchmark.cpp @@ -30,11 +30,13 @@ struct PointVector { static PointVector *aligned_alloc(size_t num) { size_t sz = num * sizeof(PointVector); - size_t align = 512; - while ((sz % align) != 0) { align /= 2; } double mega_bytes = sz / (1024.0*1024.0); - fprintf(stderr, "allocate %.2f MB of vectors (align %zu)\n", mega_bytes, align); - void *mem = std::aligned_alloc(align, sz); + fprintf(stderr, "allocate %.2f MB of vectors\n", mega_bytes); + char *mem = (char *)malloc(sz + 512); + mem += 512; + size_t val = (size_t)mem; + size_t unalign = val % 512; + mem -= unalign; return reinterpret_cast<PointVector *>(mem); } |