From 4634d4dcc6604abf4f05a1a19ec22de39a200d79 Mon Sep 17 00:00:00 2001 From: KunoiSayami Date: Sun, 26 Dec 2021 15:52:52 +0800 Subject: fix: Fix wrong memory manange Signed-off-by: KunoiSayami --- db/skiplist_test.cu | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/db/skiplist_test.cu b/db/skiplist_test.cu index b8fcb5e..c926575 100644 --- a/db/skiplist_test.cu +++ b/db/skiplist_test.cu @@ -393,16 +393,17 @@ class TestClass { cuda::atomic atomic; }; -__global__ void init(Arena * pArena, SkipList * pSkipList) { +__global__ void init(Arena ** pArena, SkipList ** pSkipList) { Comparator cmp; printf("init\n"); - pArena = new Arena(); + *pArena = new Arena(); //new TestClass(); printf("init arena\n"); - pSkipList = new SkipList(cmp, pArena); + // new = SkipList * + *pSkipList = new SkipList(cmp, *pArena); printf("init2\n"); - pSkipList->Insert(16807); - printf("skiplist: %p\n", pSkipList); + //pSkipList->Insert(16807); + printf("skiplist: %p\n", *pSkipList); printf("init3\n"); } @@ -410,8 +411,8 @@ __global__ void testParallel(SkipList * skipList, Key * keys) { unsigned int start = threadIdx.x; printf("skiplist: %p\n", skipList); printf("start: %u\n", start); - for (unsigned i = start; i < start + 100 ; i++) { - printf("key: %lu\n", keys[i]); + for (unsigned i = start * 100; i < (start + 1) * 100 ; i++) { + //printf("key: %lu\n", keys[i]); skipList->Insert(keys[i]); } printf("done: %u\n", start); @@ -426,12 +427,12 @@ void host_insert_test() { keys[i] = .Next(); }*/ Key * keys = new Key[1000]; - Arena * pArena; - SkipList * skipList; + Arena ** pArena; + SkipList ** skipList; std::set k; - cudaMallocManaged((void**)&pArena, sizeof(Arena)); - cudaMallocManaged((void**)&skipList, sizeof(SkipList)); + cudaMallocManaged((void**)&pArena, sizeof(void*)); + cudaMallocManaged((void**)&skipList, sizeof(void*)); auto * device_rnd = new Random(test::RandomSeed()); Key * device_keys = nullptr; cudaMallocManaged((void**)&device_keys, sizeof(Key) * 1000 ); @@ -457,12 +458,14 @@ void host_insert_test() { cudaDeviceSynchronize(); //insert_skiplist<<>>(skipList, device_rnd); - testParallel<<>>(skipList, device_keys); + testParallel<<>>(*skipList, device_keys); //cudaDeviceSynchronize(); //insert_and_lookup<<>>(skipList); cudaDeviceSynchronize(); - std::cout << "test\n"; + cudaFree(device_keys); + cudaFree(skipList); + cudaFree(pArena); } -- cgit v1.2.3