Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add concept BlobAllocator #146

Merged
merged 1 commit into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/llama/Allocators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace llama::allocator
}
};
#ifdef __cpp_concepts
static_assert(StorageBlob<decltype(Stack<64>{}(0))>);
static_assert(BlobAllocator<Stack<64>>);
#endif

/// Allocates heap memory managed by a `std::shared_ptr` for a \ref View.
Expand All @@ -46,7 +46,7 @@ namespace llama::allocator
}
};
#ifdef __cpp_concepts
static_assert(StorageBlob<decltype(SharedPtr{}(0))>);
static_assert(BlobAllocator<SharedPtr<>>);
#endif

template <typename T, std::size_t Alignment>
Expand Down Expand Up @@ -102,6 +102,6 @@ namespace llama::allocator
}
};
#ifdef __cpp_concepts
static_assert(StorageBlob<decltype(Vector{}(0))>);
static_assert(BlobAllocator<Vector<>>);
#endif
} // namespace llama::allocator
7 changes: 7 additions & 0 deletions include/llama/Concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ namespace llama
// other types
std::is_same_v<decltype(b[i]), std::byte&> || std::is_same_v<decltype(b[i]), unsigned char&>;
};

// clang-format off
template <typename BA>
concept BlobAllocator = requires(BA ba, std::size_t i) {
{ ba(i) } -> StorageBlob;
};
// clang-format on
} // namespace llama

#endif
4 changes: 4 additions & 0 deletions include/llama/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ namespace llama
/// view's underlying memory, the specified allocator callable is used (or the default one, which is \ref
/// allocator::Vector). The allocator callable is called with the size of bytes to allocate for each blob of the
/// mapping. This function is the preferred way to create a \ref View.
#ifdef __cpp_concepts
template <typename Mapping, BlobAllocator Allocator = allocator::Vector<>>
#else
template <typename Mapping, typename Allocator = allocator::Vector<>>
#endif
LLAMA_FN_HOST_ACC_INLINE auto allocView(Mapping mapping = {}, const Allocator& alloc = {})
-> View<Mapping, internal::AllocatorBlobType<Allocator>>
{
Expand Down