Skip to content

Commit

Permalink
feat: add umpire to handle memory allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-sivaraman committed Jan 24, 2024
1 parent 096ee51 commit 2c6ac73
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/raja/fasten.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <string>

#include "RAJA/RAJA.hpp"
#include "umpire/Allocator.hpp"
#include "umpire/ResourceManager.hpp"
#include "camp/resource.hpp"

#ifdef IMPL_CLS
Expand Down Expand Up @@ -233,23 +235,20 @@ template <size_t PPWI> class IMPL_CLS final : public Bude<PPWI> {
std::copy(xs.begin(), xs.end(), data);
return data;
}

template <typename T> static T *allocate(const size_t size) {
#ifndef RAJA_DEVICE_ACTIVE
return static_cast<T *>(std::malloc(sizeof(T) * size));
auto &rm = umpire::ResourceManager::getInstance();
#ifndef RAJA_TARGET_GPU
auto alloc = rm.getAllocator("HOST");
#else
T *ptr;
cudaMallocManaged((void **)&ptr, sizeof(T) * size, cudaMemAttachGlobal);
return ptr;
auto alloc = rm.getAllocator("UM");
#endif
return static_cast<T *>(alloc.allocate(sizeof(T) * size));
}

template <typename T> static void deallocate(T *ptr) {
#ifndef RAJA_DEVICE_ACTIVE
std::free(ptr);
#else
cudaFree(ptr);
#endif
auto &rm = umpire::ResourceManager::getInstance();
rm.getAllocator(ptr).deallocate(ptr);
}

static void synchronise() {
Expand All @@ -271,26 +270,26 @@ template <size_t PPWI> class IMPL_CLS final : public Bude<PPWI> {
[[nodiscard]] std::string name() { return "raja"; };

[[nodiscard]] std::vector<Device> enumerateDevices() override {
std::vector<Device> devices{{RAJA::ExecPlace::HOST, "RAJA Host device"}};
#if defined(RAJA_DEVICE_ACTIVE)
std::vector<Device> devices{{(size_t) RAJA::ExecPlace::HOST, "RAJA Host device"}};
#if defined(RAJA_TARGET_GPU)
#if defined(RAJA_ENABLE_CUDA)
const auto deviceName = "RAJA CUDA device";
#endif
#if defined(RAJA_ENABLE_HIP)
const auto deviceName = "Raja HIP device";
const auto deviceName = "RAJA HIP device";
#endif
#if defined(RAJA_ENABLE_SYCL)
const auto deviceName = "Raja SYCL device";
const auto deviceName = "RAJA SYCL device";
#endif
devices.template emplace_back(RAJA::ExecPlace::DEVICE, deviceName);
devices.template emplace_back((size_t) RAJA::ExecPlace::DEVICE, deviceName);
#endif
return devices;
};

[[nodiscard]] Sample fasten(const Params &p, size_t wgsize, size_t device) const override {

Sample sample(PPWI, wgsize, p.nposes());

auto contextStart = now();

auto protein = allocate(p.protein);
Expand Down

0 comments on commit 2c6ac73

Please sign in to comment.