From 9406aaf2566cc68e75cc01ba02dfa83b2179d9f6 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Sun, 19 Dec 2021 15:25:11 +0800 Subject: test(skiplist): Make cuda code work in test Signed-off-by: KunoiSayami --- db/skiplist_test.cu | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'db') diff --git a/db/skiplist_test.cu b/db/skiplist_test.cu index 0022c84..a9f7e08 100644 --- a/db/skiplist_test.cu +++ b/db/skiplist_test.cu @@ -17,7 +17,7 @@ #include "util/random.cuh" #include "util/testutil.h" -#include "gtest/gtest.h" +#include "util/cuda_gtest_plugin.h" namespace leveldb { @@ -364,10 +364,41 @@ __global__ void insert_and_lookup(SkipList * skipList) { } + +__device__ void new_cuda_atomic() { +} + +class TestClass { + public: + explicit __device__ TestClass(): atomic(0), alloc_ptr_(nullptr), alloc_bytes_remaining_(0), + head_(nullptr), blocks_(nullptr) { + + } + + TestClass(const TestClass&) = delete; + TestClass& operator=(const TestClass&) = delete; + + char* alloc_ptr_; + size_t alloc_bytes_remaining_; + + // Array of new[] allocated memory blocks + //thrust::host_vector blocks_; + //std::vector blocks_; + + void * head_; + void * blocks_; + + cuda::atomic atomic; +}; + __global__ void init(Arena ** pArena, SkipList ** pSkipList) { Comparator cmp; + printf("init\n"); + //cuda::atomic a; *pArena = new Arena(); - *pSkipList = new SkipList(cmp, reinterpret_cast(&*pArena)); + printf("init arena\n"); + //*pSkipList = new SkipList(cmp, reinterpret_cast(&*pArena)); + printf("init2\n"); } @@ -380,12 +411,13 @@ __host__ void host_insert_test() { keys[i] = .Next(); }*/ Arena * pArena; + cudaMalloc((void**)&pArena, sizeof(*pArena)); SkipList * skipList; auto * device_rnd = new Random(test::RandomSeed()); dim3 blockSize(1, 1); - dim3 gridSize(32, 32); + dim3 gridSize(1, 1); init<<>>(&pArena, &skipList); cudaDeviceSynchronize(); @@ -396,7 +428,7 @@ __host__ void host_insert_test() { insert_and_lookup<<>>(skipList); cudaDeviceSynchronize(); - + std::cout << "test"; } @@ -427,9 +459,8 @@ __global__ void test_fail() { assert(0); } -TEST(SkipTest, Empty) { - test_fail<<<1,1>>>(); - cudaDeviceSynchronize(); +CUDA_TEST(SkipTest, Empty) { + } /* @@ -522,5 +553,7 @@ TEST(SkipTest, Concurrent5) { RunConcurrent(5); } int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + int i = RUN_ALL_TESTS(); + sleep(1); + return i; } -- cgit v1.3.1