EXSWHTEC-265 - Implement Tests for Atomic Exchange (#196)
Change-Id: I4d332dcaad2d0a788b6711f5be05ca6d61a9e34b
This commit is contained in:
gecommit door
Maneesh Gupta
bovenliggende
f05f97758e
commit
f24d2dd934
@@ -29,10 +29,30 @@ enum class LinearAllocs {
|
||||
hipHostMalloc,
|
||||
hipMalloc,
|
||||
hipMallocManaged,
|
||||
noAlloc
|
||||
};
|
||||
|
||||
inline std::string to_string(const LinearAllocs allocation_type) {
|
||||
switch (allocation_type) {
|
||||
case LinearAllocs::malloc:
|
||||
return "host pageable";
|
||||
case LinearAllocs::mallocAndRegister:
|
||||
return "registered";
|
||||
case LinearAllocs::hipHostMalloc:
|
||||
return "host pinned";
|
||||
case LinearAllocs::hipMalloc:
|
||||
return "device malloc";
|
||||
case LinearAllocs::hipMallocManaged:
|
||||
return "managed";
|
||||
default:
|
||||
return "unknown alloc type";
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> class LinearAllocGuard {
|
||||
public:
|
||||
LinearAllocGuard() = default;
|
||||
|
||||
LinearAllocGuard(const LinearAllocs allocation_type, const size_t size,
|
||||
const unsigned int flags = 0u)
|
||||
: allocation_type_{allocation_type} {
|
||||
@@ -55,15 +75,36 @@ template <typename T> class LinearAllocGuard {
|
||||
case LinearAllocs::hipMallocManaged:
|
||||
HIP_CHECK(hipMallocManaged(reinterpret_cast<void**>(&ptr_), size, flags ? flags : 1u));
|
||||
host_ptr_ = ptr_;
|
||||
break;
|
||||
case LinearAllocs::noAlloc:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LinearAllocGuard(const LinearAllocGuard&) = delete;
|
||||
LinearAllocGuard(LinearAllocGuard&&) = delete;
|
||||
|
||||
LinearAllocGuard(LinearAllocGuard&& o)
|
||||
: allocation_type_{o.allocation_type_}, ptr_{o.ptr_}, host_ptr_{o.host_ptr_} {
|
||||
o.allocation_type_ = LinearAllocs::noAlloc;
|
||||
o.ptr_ = nullptr;
|
||||
o.host_ptr_ = nullptr;
|
||||
}
|
||||
|
||||
LinearAllocGuard& operator=(LinearAllocGuard&& o) {
|
||||
allocation_type_ = o.allocation_type_;
|
||||
ptr_ = o.ptr_;
|
||||
host_ptr_ = o.host_ptr_;
|
||||
|
||||
o.allocation_type_ = LinearAllocs::noAlloc;
|
||||
o.ptr_ = nullptr;
|
||||
o.host_ptr_ = nullptr;
|
||||
}
|
||||
|
||||
~LinearAllocGuard() {
|
||||
// No Catch macros, don't want to possibly throw in the destructor
|
||||
switch (allocation_type_) {
|
||||
case LinearAllocs::noAlloc:
|
||||
break;
|
||||
case LinearAllocs::malloc:
|
||||
free(ptr_);
|
||||
break;
|
||||
@@ -85,7 +126,7 @@ template <typename T> class LinearAllocGuard {
|
||||
T* host_ptr() const { return host_ptr_; }
|
||||
|
||||
private:
|
||||
const LinearAllocs allocation_type_;
|
||||
LinearAllocs allocation_type_ = LinearAllocs::noAlloc;
|
||||
T* ptr_ = nullptr;
|
||||
T* host_ptr_ = nullptr;
|
||||
};
|
||||
@@ -200,7 +241,10 @@ enum class Streams { nullstream, perThread, created, withFlags, withPriority };
|
||||
|
||||
class StreamGuard {
|
||||
public:
|
||||
StreamGuard(const Streams stream_type, unsigned int flags = hipStreamDefault, int priority = 0) : stream_type_{stream_type}, flags_{flags}, priority_{priority} {
|
||||
StreamGuard() = default;
|
||||
|
||||
StreamGuard(const Streams stream_type, unsigned int flags = hipStreamDefault, int priority = 0)
|
||||
: stream_type_{stream_type}, flags_{flags}, priority_{priority} {
|
||||
switch (stream_type_) {
|
||||
case Streams::nullstream:
|
||||
stream_ = nullptr;
|
||||
@@ -219,7 +263,28 @@ class StreamGuard {
|
||||
}
|
||||
|
||||
StreamGuard(const StreamGuard&) = delete;
|
||||
StreamGuard(StreamGuard&&) = delete;
|
||||
|
||||
StreamGuard(StreamGuard&& o)
|
||||
: stream_type_{o.stream_type_}, flags_{o.flags_}, priority_{o.priority_}, stream_{o.stream_} {
|
||||
o.stream_type_ = Streams::nullstream;
|
||||
o.flags_ = 0u;
|
||||
o.priority_ = 0;
|
||||
o.stream_ = nullptr;
|
||||
}
|
||||
|
||||
StreamGuard& operator=(StreamGuard&& o) {
|
||||
stream_type_ = o.stream_type_;
|
||||
flags_ = o.flags_;
|
||||
priority_ = o.priority_;
|
||||
stream_ = o.stream_;
|
||||
|
||||
o.stream_type_ = Streams::nullstream;
|
||||
o.flags_ = 0u;
|
||||
o.priority_ = 0;
|
||||
o.stream_ = nullptr;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~StreamGuard() {
|
||||
if (stream_type_ == Streams::created) {
|
||||
@@ -230,23 +295,23 @@ class StreamGuard {
|
||||
hipStream_t stream() const { return stream_; }
|
||||
|
||||
private:
|
||||
const Streams stream_type_;
|
||||
unsigned int flags_;
|
||||
int priority_;
|
||||
hipStream_t stream_;
|
||||
Streams stream_type_ = Streams::nullstream;
|
||||
unsigned int flags_ = 0u;
|
||||
int priority_ = 0;
|
||||
hipStream_t stream_ = nullptr;
|
||||
};
|
||||
|
||||
class EventsGuard {
|
||||
public:
|
||||
public:
|
||||
EventsGuard(size_t N) : events_(N) {
|
||||
for (auto &e : events_) HIP_CHECK(hipEventCreate(&e));
|
||||
for (auto& e : events_) HIP_CHECK(hipEventCreate(&e));
|
||||
}
|
||||
|
||||
EventsGuard(const EventsGuard&) = delete;
|
||||
EventsGuard(EventsGuard&&) = delete;
|
||||
|
||||
~EventsGuard() {
|
||||
for (auto &e : events_) static_cast<void>(hipEventDestroy(e));
|
||||
for (auto& e : events_) static_cast<void>(hipEventDestroy(e));
|
||||
}
|
||||
|
||||
hipEvent_t& operator[](int index) { return events_[index]; }
|
||||
@@ -255,21 +320,21 @@ public:
|
||||
|
||||
std::vector<hipEvent_t>& event_list() { return events_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<hipEvent_t> events_;
|
||||
};
|
||||
|
||||
class StreamsGuard {
|
||||
public:
|
||||
public:
|
||||
StreamsGuard(size_t N) : streams_(N) {
|
||||
for (auto &s : streams_) HIP_CHECK(hipStreamCreate(&s));
|
||||
for (auto& s : streams_) HIP_CHECK(hipStreamCreate(&s));
|
||||
}
|
||||
|
||||
StreamsGuard(const StreamsGuard&) = delete;
|
||||
StreamsGuard(StreamsGuard&&) = delete;
|
||||
|
||||
~StreamsGuard() {
|
||||
for (auto &s : streams_) static_cast<void>(hipStreamDestroy(s));
|
||||
for (auto& s : streams_) static_cast<void>(hipStreamDestroy(s));
|
||||
}
|
||||
|
||||
hipStream_t& operator[](int index) { return streams_[index]; }
|
||||
@@ -278,6 +343,6 @@ public:
|
||||
|
||||
std::vector<hipStream_t>& stream_list() { return streams_; }
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<hipStream_t> streams_;
|
||||
};
|
||||
|
||||
Verwijs in nieuw issue
Block a user