MemoryPointer::new() not using default device
Opened this issue · 1 comments
smedegaard commented
when creating a memory allocation with MemoryPointer::new()
, the call to sys::hipMalloc
should allocate on the default device.
The observation is that even if hipGetDevice()
returns 0
, the memory was allocated on another device.
smedegaard commented
This behavior comes from the HIP C++ lib. Tested with the following
#include <hip/hip_runtime.h>
#include <iostream>
#include <chrono>
#include <thread>
int main() {
int device;
hipError_t err = hipGetDevice(&device);
if (err != hipSuccess) {
std::cerr << "Failed to get device: " << hipGetErrorString(err) << std::endl;
return 1;
}
std::cout << "Using device: " << device << std::endl;
void* ptr = nullptr;
size_t size = 1024 * 1024 * 1024; // 1GB
err = hipMalloc(&ptr, size);
if (err != hipSuccess) {
std::cerr << "Failed to allocate memory: " << hipGetErrorString(err) << std::endl;
return 1;
}
std::cout << "Allocated 1GB of device memory at address: " << ptr << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(5));
err = hipFree(ptr);
if (err != hipSuccess) {
std::cerr << "Failed to free memory: " << hipGetErrorString(err) << std::endl;
return 1;
}
std::cout << "Freed memory\n";
return 0;
}