Skip to content

Commit

Permalink
Merge pull request #49 from markusbattarbee/loop_reductions
Browse files Browse the repository at this point in the history
Tests ran offline but pass!
  • Loading branch information
kstppd authored Apr 9, 2024
2 parents 3f214f5 + acee2ef commit a702a9b
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 154 deletions.
22 changes: 22 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ constexpr inline size_t nextOverflow(size_t currentOverflow, size_t virtualWarp)
return ((remainder)==0)?currentOverflow: currentOverflow + (virtualWarp - remainder);
}

inline bool isDeviceAccessible(void* ptr){
#ifdef __NVCC__
cudaPointerAttributes attributes;
cudaPointerGetAttributes(&attributes, ptr);
if (attributes.type != cudaMemoryType::cudaMemoryTypeManaged &&
attributes.type != cudaMemoryType::cudaMemoryTypeDevice) {
return false;
}
return true;
#endif

#ifdef __HIP__
hipPointerAttribute_t attributes;
hipPointerGetAttributes(&attributes, ptr);
if (attributes.type != hipMemoryType::hipMemoryTypeManaged &&
attributes.type != hipMemoryType::hipMemoryTypeDevice) {
return false;
}
return true;
#endif
}

/**
* @brief Enum for error checking in Hahsinator.
*/
Expand Down
32 changes: 29 additions & 3 deletions include/hashinator/hashinator.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ class Hashmap {
const_iterator it = find(i.first);
int64_t overflow = llabs(it.getIndex() - optimalIndex);
if (i.first == TOMBSTONE) {
std::cout << "[╀] ";
printf("[╀] ");
} else if (i.first == EMPTYBUCKET) {
std::cout << "[▢] ";
printf("[▢] ");
} else {
if (overflow > 0) {
printf("[%d,%d,\033[1;31m%li\033[0m] ", i.first, i.second, overflow);
Expand All @@ -543,7 +543,7 @@ class Hashmap {
for (int i = 0; i < buckets.size(); ++i) {
print_pair(buckets[i]);
}
std::cout << std::endl;
printf("\n");
}

HASHINATOR_HOSTDEVICE
Expand Down Expand Up @@ -1122,6 +1122,19 @@ class Hashmap {
buckets, elements, rule, nBlocks, mPool, s);
return retval;
}
template <typename Rule>
void extractPatternLoop(split::SplitVector<hash_pair<KEY_TYPE, VAL_TYPE>>& elements, Rule rule, split_gpuStream_t s = 0) {
// Extract elements matching the Pattern Rule(element)==true;
split::tools::copy_if_loop<hash_pair<KEY_TYPE, VAL_TYPE>, Rule, defaults::MAX_BLOCKSIZE,
defaults::WARPSIZE>(buckets, elements, rule, s);
}
void extractLoop(split::SplitVector<hash_pair<KEY_TYPE, VAL_TYPE>>& elements, split_gpuStream_t s = 0) {
// Extract all valid elements
auto rule = [] __host__ __device__(const hash_pair<KEY_TYPE, VAL_TYPE>& kval) -> bool {
return kval.first != EMPTYBUCKET && kval.first != TOMBSTONE;
};
extractPatternLoop(elements, rule, s);
}

template <typename Rule>
size_t extractKeysByPattern(split::SplitVector<KEY_TYPE>& elements, Rule rule, split_gpuStream_t s = 0,
Expand Down Expand Up @@ -1150,6 +1163,12 @@ class Hashmap {
defaults::WARPSIZE>(buckets, elements, rule, stack, max_size, s);
return elements.size();
}
template <typename Rule>
void extractKeysByPatternLoop(split::SplitVector<KEY_TYPE>& elements, Rule rule, split_gpuStream_t s = 0) {
// Extract element **keys** matching the Pattern Rule(element)==true;
split::tools::copy_if_keys_loop<hash_pair<KEY_TYPE, VAL_TYPE>, KEY_TYPE, Rule, defaults::MAX_BLOCKSIZE,
defaults::WARPSIZE>(buckets, elements, rule, s);
}

size_t extractAllKeys(split::SplitVector<KEY_TYPE>& elements, split_gpuStream_t s = 0, bool prefetches = true) {
// Extract all keys
Expand All @@ -1165,6 +1184,13 @@ class Hashmap {
};
return extractKeysByPattern(elements, rule, stack, max_size, s, prefetches);
}
void extractAllKeysLoop(split::SplitVector<KEY_TYPE>& elements, split_gpuStream_t s = 0) {
// Extract all keys
auto rule = [] __host__ __device__(const hash_pair<KEY_TYPE, VAL_TYPE>& kval) -> bool {
return kval.first != EMPTYBUCKET && kval.first != TOMBSTONE;
};
extractKeysByPatternLoop(elements, rule, s);
}

void clean_tombstones(split_gpuStream_t s = 0, bool prefetches = false) {

Expand Down
Loading

0 comments on commit a702a9b

Please sign in to comment.