aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-04-07 01:32:17 +0800
committerKunoiSayami <[email protected]>2022-04-07 01:32:17 +0800
commit706cae9f460fe698857f47aaa42eb517ea2cb09f (patch)
tree2f3a775e280120d65191ce29760ae4aba06b57cf /util
parent32ce8b311269df205e192c2b61dc47faaa2c5971 (diff)
feat: Finish implement cuda memtable
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'util')
-rw-r--r--util/arena.cu10
-rw-r--r--util/arena.cuh18
-rw-r--r--util/coding.cu2
-rw-r--r--util/coding.cuh2
4 files changed, 16 insertions, 16 deletions
diff --git a/util/arena.cu b/util/arena.cu
index e6c8c04..e91d652 100644
--- a/util/arena.cu
+++ b/util/arena.cu
@@ -8,11 +8,11 @@ namespace leveldb {
static const int kBlockSize = 4096;
-__device__ __host__ Arena::Arena()
+__device__ __host__ ArenaCuda::ArenaCuda()
: alloc_ptr_(nullptr), alloc_bytes_remaining_(0), memory_usage_(0),
head_(nullptr), blocks_(nullptr) {}
-__host__ __device__ Arena::~Arena() {
+__host__ __device__ ArenaCuda::~ArenaCuda() {
ArenaNode * current = this->head_;
while (current != nullptr) {
ArenaNode * next = current->next;
@@ -22,7 +22,7 @@ __host__ __device__ Arena::~Arena() {
}
}
-__device__ char* Arena::AllocateFallback(size_t bytes) {
+__device__ char* ArenaCuda::AllocateFallback(size_t bytes) {
if (bytes > kBlockSize / 4) {
// Object is more than a quarter of our block size. Allocate it separately
// to avoid wasting too much space in leftover bytes.
@@ -40,7 +40,7 @@ __device__ char* Arena::AllocateFallback(size_t bytes) {
return result;
}
-__device__ char* Arena::AllocateAligned(size_t bytes) {
+__device__ char* ArenaCuda::AllocateAligned(size_t bytes) {
const int align = (sizeof(void*) > 8) ? sizeof(void*) : 8;
static_assert((align & (align - 1)) == 0,
"Pointer size should be a power of 2");
@@ -60,7 +60,7 @@ __device__ char* Arena::AllocateAligned(size_t bytes) {
return result;
}
-__device__ char* Arena::AllocateNewBlock(size_t block_bytes) {
+__device__ char* ArenaCuda::AllocateNewBlock(size_t block_bytes) {
// Allocate new target
char* result = nullptr;
// Allocate storage target
diff --git a/util/arena.cuh b/util/arena.cuh
index e9abd31..a92547f 100644
--- a/util/arena.cuh
+++ b/util/arena.cuh
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
-#ifndef STORAGE_LEVELDB_UTIL_ARENA_H_
-#define STORAGE_LEVELDB_UTIL_ARENA_H_
+#ifndef STORAGE_LEVELDB_UTIL_ARENA_CUDA_H_
+#define STORAGE_LEVELDB_UTIL_ARENA_CUDA_H_
#include <atomic>
#include <cassert>
@@ -15,14 +15,14 @@
namespace leveldb {
-class Arena {
+class ArenaCuda {
public:
- explicit __device__ __host__ Arena();
+ explicit __device__ __host__ ArenaCuda();
- Arena(const Arena&) = delete;
- Arena& operator=(const Arena&) = delete;
+ ArenaCuda(const ArenaCuda&) = delete;
+ ArenaCuda& operator=(const ArenaCuda&) = delete;
- __host__ __device__ ~Arena();
+ __host__ __device__ ~ArenaCuda();
// Return a pointer to a newly allocated memory block of "bytes" bytes.
__device__ char* Allocate(size_t bytes);
@@ -64,7 +64,7 @@ class Arena {
cuda::atomic<size_t> memory_usage_;
};
-__device__ inline char* Arena::Allocate(size_t bytes) {
+__device__ inline char* ArenaCuda::Allocate(size_t bytes) {
// The semantics of what to return are a bit messy if we allow
// 0-byte allocations, so we disallow them here (we don't need
// them for our internal use).
@@ -80,4 +80,4 @@ __device__ inline char* Arena::Allocate(size_t bytes) {
} // namespace leveldb
-#endif // STORAGE_LEVELDB_UTIL_ARENA_H_
+#endif // STORAGE_LEVELDB_UTIL_ARENA_CUDA_H_
diff --git a/util/coding.cu b/util/coding.cu
index 63ddf28..ee93ddb 100644
--- a/util/coding.cu
+++ b/util/coding.cu
@@ -75,7 +75,7 @@ void PutLengthPrefixedSlice(std::string* dst, const Slice& value) {
dst->append(value.data(), value.size());
}
-int VarintLength(uint64_t v) {
+__device__ __host__ int VarintLength(uint64_t v) {
int len = 1;
while (v >= 128) {
v >>= 7;
diff --git a/util/coding.cuh b/util/coding.cuh
index f89177b..dbe5564 100644
--- a/util/coding.cuh
+++ b/util/coding.cuh
@@ -40,7 +40,7 @@ const char* GetVarint32Ptr(const char* p, const char* limit, uint32_t* v);
const char* GetVarint64Ptr(const char* p, const char* limit, uint64_t* v);
// Returns the length of the varint32 or varint64 encoding of "v"
-int VarintLength(uint64_t v);
+__device__ __host__ int VarintLength(uint64_t v);
// Lower-level versions of Put... that write directly into a character buffer
// and return a pointer just past the last byte written.