Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions Detectors/ITSMFT/ITS/tracking/GPU/cuda/TrackingKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,43 @@ namespace gpu
{

template <typename T>
class TypedAllocator : public thrust::device_allocator<T>
{
public:
struct TypedAllocator {
using value_type = T;
using pointer = T*;
using pointer = thrust::device_ptr<T>;
using const_pointer = thrust::device_ptr<const T>;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;

TypedAllocator() noexcept : mInternalAllocator(nullptr) {}
explicit TypedAllocator(ExternalAllocator* a) noexcept : mInternalAllocator(a) {}

template <typename U>
struct rebind {
using other = TypedAllocator<U>;
};
TypedAllocator(const TypedAllocator<U>& o) noexcept : mInternalAllocator(o.mInternalAllocator)
{
}

explicit TypedAllocator(ExternalAllocator* allocPtr)
: mInternalAllocator(allocPtr) {}
pointer allocate(size_type n)
{
void* raw = mInternalAllocator->allocate(n * sizeof(T));
return thrust::device_pointer_cast(static_cast<T*>(raw));
}

T* allocate(size_t n)
void deallocate(pointer p, size_type n) noexcept
{
return reinterpret_cast<T*>(mInternalAllocator->allocate(n * sizeof(T)));
if (!p) {
return;
}
void* raw = thrust::raw_pointer_cast(p);
mInternalAllocator->deallocate(static_cast<char*>(raw), n * sizeof(T));
}

void deallocate(T* p, size_t n)
bool operator==(TypedAllocator const& o) const noexcept
{
return mInternalAllocator == o.mInternalAllocator;
}
bool operator!=(TypedAllocator const& o) const noexcept
{
char* raw_ptr = reinterpret_cast<char*>(p);
size_t bytes = n * sizeof(T);
mInternalAllocator->deallocate(raw_ptr, bytes); // redundant as internal dealloc is no-op.
return !(*this == o);
}

private:
Expand Down