EXSWHTEC-267 - Implement tests for multi_grid_group APIs (#156)

Change-Id: I2820ec19831f0dad3b8ce60172c86791f274107e
This commit is contained in:
Nives Vukovic authored and Rakesh Roy committed 2024-02-15 19:41:22 +05:30
1 parent 10594ecb3a
commit 9b96b707ee
5 files changed
+701 -21

No files matched your search

+26
View File
@@ -78,6 +78,32 @@ struct CPUGrid {
unsigned int thread_count_;
};
struct CPUMultiGrid {
CPUMultiGrid(const unsigned int num_grids, const dim3 grid_dims[], const dim3 block_dims[]) {
thread_count_ = 0;
grid_count_ = num_grids;
grids_.reserve(grid_count_);
for (int i = 0; i < grid_count_; i++) {
grids_.emplace_back(grid_dims[i], block_dims[i]);
thread_count_ += grids_[i].thread_count_;
}
}
inline unsigned int thread0_rank_in_multi_grid(const unsigned int grid_rank) const {
unsigned int multi_grid_thread_rank_0 = 0;
unsigned int multi_grid_thread_count = 0;
for (int i = 0; i <= grid_rank; i++) {
multi_grid_thread_rank_0 = multi_grid_thread_count;
multi_grid_thread_count += grids_[i].thread_count_;
}
return multi_grid_thread_rank_0;
}
std::vector<CPUGrid> grids_;
unsigned int grid_count_;
unsigned int thread_count_;
};
/* Generate dimensions for 1D, 2D and 3D blocks of threads */
inline dim3 GenerateThreadDimensions() {
hipDeviceProp_t props;
+20 -19
View File
@@ -102,24 +102,25 @@ template <typename T> class LinearAllocGuard {
~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;
case LinearAllocs::mallocAndRegister:
// Cast to void to suppress nodiscard warnings
static_cast<void>(hipHostUnregister(host_ptr_));
free(host_ptr_);
break;
case LinearAllocs::hipHostMalloc:
static_cast<void>(hipHostFree(ptr_));
break;
case LinearAllocs::hipMalloc:
case LinearAllocs::hipMallocManaged:
static_cast<void>(hipFree(ptr_));
}
if (ptr_ != nullptr) {
switch (allocation_type_) {
case LinearAllocs::noAlloc:
break;
case LinearAllocs::malloc:
free(ptr_);
break;
case LinearAllocs::mallocAndRegister:
// Cast to void to suppress nodiscard warnings
static_cast<void>(hipHostUnregister(host_ptr_));
free(host_ptr_);
break;
case LinearAllocs::hipHostMalloc:
static_cast<void>(hipHostFree(ptr_));
break;
case LinearAllocs::hipMalloc:
case LinearAllocs::hipMallocManaged:
static_cast<void>(hipFree(ptr_));
}
}
T* ptr() const { return ptr_; };
@@ -287,7 +288,7 @@ class StreamGuard {
}
~StreamGuard() {
if (stream_type_ == Streams::created) {
if (stream_type_ == Streams::created && stream_ != nullptr) {
static_cast<void>(hipStreamDestroy(stream_));
}
}