diff options
| author | KunoiSayami <[email protected]> | 2021-11-11 22:01:31 +0800 |
|---|---|---|
| committer | KunoiSayami <[email protected]> | 2021-11-11 22:01:31 +0800 |
| commit | ff62cbaad13d4bd309de5d3dda8c7051325d5663 (patch) | |
| tree | 8b04f0fe87368228a980f63bf280dd4ebd8e0f5d | |
| parent | 9907b61c574baf0747747f1c512f7cdd88ebed25 (diff) | |
feat(cmake): Support cuda build
Signed-off-by: KunoiSayami <[email protected]>
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | CMakeLists.txt | 14 | ||||
| -rw-r--r-- | db/memtable.h | 7 | ||||
| -rw-r--r-- | db/skiplist.h | 2 | ||||
| -rw-r--r-- | db/skiplist_test.cc | 6 | ||||
| -rw-r--r-- | util/arena.cu (renamed from util/arena.cc) | 7 | ||||
| -rw-r--r-- | util/arena.cuh (renamed from util/arena.h) | 0 | ||||
| -rw-r--r-- | util/arena_test.cu (renamed from util/arena_test.cc) | 4 |
8 files changed, 28 insertions, 15 deletions
@@ -6,3 +6,6 @@ # Build directory. build/ out/ + +cmake-* +.idea/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f8285b8..ad9a488 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.9) # Keep the version below in sync with the one in db.h -project(leveldb VERSION 1.23.0 LANGUAGES C CXX) +project(leveldb VERSION 1.23.0 LANGUAGES C CXX CUDA) # C standard can be overridden when this is used as a sub-project. if(NOT CMAKE_C_STANDARD) @@ -76,6 +76,8 @@ else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti") + # Test whether -Wthread-safety is available. See # https://clang.llvm.org/docs/ThreadSafetyAnalysis.html include(CheckCXXCompilerFlag) @@ -116,6 +118,9 @@ endif(BUILD_SHARED_LIBS) # Must be included before CMAKE_INSTALL_INCLUDEDIR is used. include(GNUInstallDirs) +set(CMAKE_CUDA_STANDARD 14) +find_package(CUDA REQUIRED) + add_library(leveldb "") target_sources(leveldb PRIVATE @@ -169,8 +174,8 @@ target_sources(leveldb "table/table.cc" "table/two_level_iterator.cc" "table/two_level_iterator.h" - "util/arena.cc" - "util/arena.h" + "util/arena.cu" + "util/arena.cuh" "util/bloom.cc" "util/cache.cc" "util/coding.cc" @@ -208,6 +213,7 @@ target_sources(leveldb "${LEVELDB_PUBLIC_INCLUDE_DIR}/table.h" "${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h" ) +set_target_properties(leveldb PROPERTIES CUDA_ARCHITECTURES "35;50;72") if (WIN32) target_sources(leveldb @@ -367,7 +373,7 @@ if(LEVELDB_BUILD_TESTS) leveldb_test("table/filter_block_test.cc") leveldb_test("table/table_test.cc") - leveldb_test("util/arena_test.cc") + leveldb_test("util/arena_test.cu") leveldb_test("util/bloom_test.cc") leveldb_test("util/cache_test.cc") leveldb_test("util/coding_test.cc") diff --git a/db/memtable.h b/db/memtable.h index 9d986b1..3d3444b 100644 --- a/db/memtable.h +++ b/db/memtable.h @@ -5,12 +5,13 @@ #ifndef STORAGE_LEVELDB_DB_MEMTABLE_H_ #define STORAGE_LEVELDB_DB_MEMTABLE_H_ -#include <string> - #include "db/dbformat.h" #include "db/skiplist.h" +#include <string> + #include "leveldb/db.h" -#include "util/arena.h" + +#include "util/arena.cuh" namespace leveldb { diff --git a/db/skiplist.h b/db/skiplist.h index a59b45b..13df778 100644 --- a/db/skiplist.h +++ b/db/skiplist.h @@ -31,7 +31,7 @@ #include <cassert> #include <cstdlib> -#include "util/arena.h" +#include "util/arena.cuh" #include "util/random.h" namespace leveldb { diff --git a/db/skiplist_test.cc b/db/skiplist_test.cc index 79a5b86..402cb47 100644 --- a/db/skiplist_test.cc +++ b/db/skiplist_test.cc @@ -7,15 +7,17 @@ #include <atomic> #include <set> -#include "gtest/gtest.h" #include "leveldb/env.h" + #include "port/port.h" #include "port/thread_annotations.h" -#include "util/arena.h" +#include "util/arena.cuh" #include "util/hash.h" #include "util/random.h" #include "util/testutil.h" +#include "gtest/gtest.h" + namespace leveldb { typedef uint64_t Key; diff --git a/util/arena.cc b/util/arena.cu index 46e3b2e..09ec6e6 100644 --- a/util/arena.cc +++ b/util/arena.cu @@ -2,7 +2,7 @@ // 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. -#include "util/arena.h" +#include "util/arena.cuh" namespace leveldb { @@ -13,7 +13,7 @@ Arena::Arena() Arena::~Arena() { for (size_t i = 0; i < blocks_.size(); i++) { - delete[] blocks_[i]; + cudaFree(blocks_[i]); } } @@ -56,7 +56,8 @@ char* Arena::AllocateAligned(size_t bytes) { } char* Arena::AllocateNewBlock(size_t block_bytes) { - char* result = new char[block_bytes]; + char* result = nullptr; + cudaMallocManaged((void **)&result, sizeof(char) * block_bytes); blocks_.push_back(result); memory_usage_.fetch_add(block_bytes + sizeof(char*), std::memory_order_relaxed); diff --git a/util/arena.h b/util/arena.cuh index 68fc55d..68fc55d 100644 --- a/util/arena.h +++ b/util/arena.cuh diff --git a/util/arena_test.cc b/util/arena_test.cu index 90226fe..9b87785 100644 --- a/util/arena_test.cc +++ b/util/arena_test.cu @@ -2,10 +2,10 @@ // 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. -#include "util/arena.h" +#include "util/arena.cuh" +#include "util/random.h" #include "gtest/gtest.h" -#include "util/random.h" namespace leveldb { |
