13#include <hip/hip_runtime.h>
27void check_hip_error(hipError_t error_code,
const char* operation) {
28 if (error_code != hipSuccess) {
29 throw std::runtime_error(std::string(
"HIPGPUDeviceBackend: ") + operation +
30 " failed: " + hipGetErrorString(error_code));
44 check_hip_error(hipSetDevice(0),
"hipSetDevice");
45 check_hip_error(hipGetDeviceProperties(&device_properties_, 0),
"hipGetDeviceProperties");
52 return std::string(device_properties_.name);
59 return device_properties_.totalGlobalMem;
77 void* pointer =
nullptr;
78 check_hip_error(hipMallocManaged(&pointer, size_bytes),
"hipMallocManaged");
86 check_hip_error(hipFree(pointer),
"hipFree");
93 check_hip_error(hipDeviceSynchronize(),
"hipDeviceSynchronize");
97 hipDeviceProp_t device_properties_;
103 return std::make_shared<HIPGPUDeviceBackend>();
void synchronize() override
void * allocate_unified(size_t size_bytes) override
bool supports_double_precision() const override
void deallocate(void *pointer) override
std::string device_name() const override
size_t total_memory_bytes() const override
std::shared_ptr< GPUDeviceBackend > create_gpu_device_backend()