11 #include "MemorySpace.h"
13 #include <unordered_set>
15 namespace faiss {
namespace gpu {
20 typedef char value_type;
23 : start_((
char*) mem),
25 end_((
char*) mem + size) {
31 for (
auto p : mallocAllocs_) {
32 freeMemorySpace(MemorySpace::Device, p);
36 char* allocate(std::ptrdiff_t size) {
37 if (size <= (end_ - cur_)) {
40 FAISS_ASSERT(cur_ <= end_);
45 allocMemorySpace(MemorySpace::Device, &p, size);
46 mallocAllocs_.insert(p);
51 void deallocate(
char* p,
size_t size) {
54 auto it = mallocAllocs_.find(p);
55 if (it != mallocAllocs_.end()) {
56 freeMemorySpace(MemorySpace::Device, p);
57 mallocAllocs_.erase(it);
65 std::unordered_set<char*> mallocAllocs_;
Allocator for Thrust that comes out of a specified memory space.