Cleanup unused code in repository (#75)
* Remove unused forward_list * Remove unused __read_clock function * Replace wallClk code with hip function * Remove unused unit test for ipc * Remove slab heap * Remove unused EBO spinlock
Этот коммит содержится в:
1 родитель
68421895d6
Коммит
0fd628458c
22 files changed
+6
-1959
No files matched your search
@@ -27,6 +27,5 @@ target_sources(
|
||||
${PROJECT_NAME}
|
||||
PRIVATE
|
||||
single_heap.cpp
|
||||
slab_heap.cpp
|
||||
memory_allocator.cpp
|
||||
)
|
||||
@@ -1,116 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "slab_heap.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "../util.hpp"
|
||||
|
||||
namespace rocshmem {
|
||||
|
||||
SlabHeap::SlabHeap() {
|
||||
if (auto slab_size_cstr = getenv("ROCSHMEM_SLAB_SIZE")) {
|
||||
std::stringstream sstream(slab_size_cstr);
|
||||
size_t slab_size;
|
||||
sstream >> slab_size;
|
||||
heap_mem_ = HEAP_T{slab_size};
|
||||
strat_ = STRAT_T{&heap_mem_};
|
||||
}
|
||||
}
|
||||
|
||||
void SlabHeap::malloc(void** ptr, size_t size) {
|
||||
strat_.alloc(reinterpret_cast<char**>(ptr), size);
|
||||
}
|
||||
|
||||
__device__ void SlabHeap::malloc(void** ptr, size_t size) {
|
||||
/*
|
||||
* Grab the mutex from the proxy object which owns it.
|
||||
*/
|
||||
auto mutex{mutex_.get()};
|
||||
|
||||
/*
|
||||
* Take the ticketed lock.
|
||||
*
|
||||
* The lock is held jointly by all threads in the block.
|
||||
*/
|
||||
auto ticket{mutex->lock()};
|
||||
|
||||
/*
|
||||
* Perform allocation and verify it worked.
|
||||
*
|
||||
* Allocation should only be run by only one thread in the
|
||||
* strategy code.
|
||||
*/
|
||||
char** ptr_c{reinterpret_cast<char**>(ptr)};
|
||||
strat_.alloc(ptr_c, size);
|
||||
__threadfence();
|
||||
|
||||
/*
|
||||
* The notifier works with uint64_t for the address broadcasts
|
||||
* between threads (as type erasure for the pointer arithmetic).
|
||||
*/
|
||||
uint64_t ptr_deref_u64{reinterpret_cast<uint64_t>(*ptr)};
|
||||
|
||||
/*
|
||||
* Notify other threads in block about the allocation result.
|
||||
*/
|
||||
auto notifier{notifier_.get()};
|
||||
if (!threadIdx.x) {
|
||||
notifier->store(ptr_deref_u64);
|
||||
notifier->fence();
|
||||
}
|
||||
__syncthreads();
|
||||
uint64_t notification_u64{notifier->load()};
|
||||
|
||||
/*
|
||||
* Write to the ptr parameter (to return it back up the call stack).
|
||||
*/
|
||||
char* read_value_c{reinterpret_cast<char*>(notification_u64)};
|
||||
*ptr_c = read_value_c;
|
||||
|
||||
/*
|
||||
* Release the lock with our ticket number.
|
||||
*/
|
||||
mutex->unlock(ticket);
|
||||
}
|
||||
|
||||
__host__ __device__ void SlabHeap::free(void* ptr) {
|
||||
if (!ptr) {
|
||||
return;
|
||||
}
|
||||
strat_.free(reinterpret_cast<char*>(ptr));
|
||||
}
|
||||
|
||||
void* SlabHeap::realloc(void* ptr, size_t size) { return nullptr; }
|
||||
|
||||
void* SlabHeap::malign(size_t alignment, size_t size) { return nullptr; }
|
||||
|
||||
char* SlabHeap::get_base_ptr() { return heap_mem_.get_ptr(); }
|
||||
|
||||
size_t SlabHeap::get_size() { return heap_mem_.get_size(); }
|
||||
|
||||
size_t SlabHeap::get_used() { return strat_.current() - get_base_ptr(); }
|
||||
|
||||
size_t SlabHeap::get_avail() { return get_size() - get_used(); }
|
||||
|
||||
} // namespace rocshmem
|
||||
@@ -1,195 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef LIBRARY_SRC_MEMORY_SLAB_HEAP_HPP_
|
||||
#define LIBRARY_SRC_MEMORY_SLAB_HEAP_HPP_
|
||||
|
||||
#include "dev_mono_linear.hpp"
|
||||
#include "heap_memory.hpp"
|
||||
#include "heap_type.hpp"
|
||||
#include "notifier.hpp"
|
||||
#include "../sync/abql_block_mutex.hpp"
|
||||
|
||||
/**
|
||||
* @file slab_heap.hpp
|
||||
*
|
||||
* @brief Contains a heap used to allocate library objects
|
||||
*
|
||||
* The slab heap is used internally by the library
|
||||
*/
|
||||
|
||||
namespace rocshmem {
|
||||
|
||||
class SlabHeap {
|
||||
/**
|
||||
* @brief Helper type for allocation strategy
|
||||
*/
|
||||
using STRAT_T = DevMonoLinear<HEAP_T>;
|
||||
|
||||
/**
|
||||
* @brief Helper type for notifier
|
||||
*/
|
||||
using NOTIFIER_PROXY_T = NotifierProxy<HIPAllocator, detail::atomic::memory_scope_workgroup>;
|
||||
|
||||
/**
|
||||
* @brief Helper type for notifier
|
||||
*/
|
||||
using MUTEX_PROXY_T = ABQLBlockMutexProxy<HIPAllocator>;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Primary constructor
|
||||
*/
|
||||
SlabHeap();
|
||||
|
||||
/**
|
||||
* @brief Allocates memory from the heap
|
||||
*
|
||||
* @param[in,out] A pointer to memory handle
|
||||
* @param[in] Size in bytes of memory allocation
|
||||
*/
|
||||
void malloc(void** ptr, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Allocates memory from the heap
|
||||
*
|
||||
* @param[in,out] A pointer to memory handle
|
||||
* @param[in] Size in bytes of memory allocation
|
||||
*/
|
||||
__device__ void malloc(void** ptr, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Frees memory from the heap
|
||||
*
|
||||
* @param[in] Raw pointer to heap memory
|
||||
*/
|
||||
__host__ __device__ void free(void* ptr);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in]
|
||||
* @param[in]
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void* realloc(void* ptr, size_t size);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param[in]
|
||||
* @param[in]
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
void* malign(size_t alignment, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Accessor for heap base ptr
|
||||
*
|
||||
* @return Pointer to base of my heap
|
||||
*/
|
||||
char* get_base_ptr();
|
||||
|
||||
/**
|
||||
* @brief Accessor for heap size
|
||||
*
|
||||
* @return Amount of bytes in heap
|
||||
*/
|
||||
size_t get_size();
|
||||
|
||||
/**
|
||||
* @brief Accessor for heap usage
|
||||
*
|
||||
* @return Amount of used bytes in heap
|
||||
*/
|
||||
size_t get_used();
|
||||
|
||||
/**
|
||||
* @brief Accessor for heap available
|
||||
*
|
||||
* @return Amount of available bytes in heap
|
||||
*/
|
||||
size_t get_avail();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Heap memory object
|
||||
*/
|
||||
HEAP_T heap_mem_{};
|
||||
|
||||
/**
|
||||
* @brief Allocation strategy object
|
||||
*/
|
||||
STRAT_T strat_{&heap_mem_};
|
||||
|
||||
/**
|
||||
* @brief Notifier proxy to share information between threads.
|
||||
*
|
||||
* Need this object to share allocation information between the
|
||||
* leader thread (that does allocation) and the follower threads
|
||||
* (who need the allocation address).
|
||||
*/
|
||||
NOTIFIER_PROXY_T notifier_{};
|
||||
|
||||
/**
|
||||
* @brief Mutex to access the heap mutator methods.
|
||||
*/
|
||||
MUTEX_PROXY_T mutex_;
|
||||
};
|
||||
|
||||
template <typename ALLOCATOR>
|
||||
class SlabHeapProxy {
|
||||
using ProxyT = DeviceProxy<ALLOCATOR, SlabHeap>;
|
||||
|
||||
public:
|
||||
/*
|
||||
* Placement new the memory which is allocated by proxy_
|
||||
*/
|
||||
SlabHeapProxy(size_t num_elems = 1) : proxy_{num_elems} {
|
||||
new (proxy_.get()) SlabHeap();
|
||||
}
|
||||
|
||||
SlabHeapProxy(const SlabHeapProxy& other) = delete;
|
||||
|
||||
SlabHeapProxy& operator=(const SlabHeapProxy& other) = delete;
|
||||
|
||||
SlabHeapProxy(SlabHeapProxy&& other) = default;
|
||||
|
||||
SlabHeapProxy& operator=(SlabHeapProxy&& other) = default;
|
||||
|
||||
/*
|
||||
* Since placement new is called in the constructor, then
|
||||
* delete must be called manually.
|
||||
*/
|
||||
~SlabHeapProxy() { proxy_.get()->~SlabHeap(); }
|
||||
|
||||
__host__ __device__ SlabHeap* get() { return proxy_.get(); }
|
||||
|
||||
private:
|
||||
ProxyT proxy_{};
|
||||
};
|
||||
|
||||
} // namespace rocshmem
|
||||
|
||||
#endif // LIBRARY_SRC_MEMORY_SLAB_HEAP_HPP_
|
||||
Reference in new issue
Block a user