Files
mi300a-xnack/hipmallocmanaged_hostaccess.cpp
Carl Pearson cf83db731c Initial commit
2024-12-03 15:36:32 -08:00

28 lines
451 B
C++

#include <iostream>
#include <hip/hip_runtime.h>
#define HIP(e) \
if (hipError_t err = (e); err != hipSuccess) { \
std::cerr << __FILE__ << ":" << __LINE__ << " " << err << "\n"; \
exit(1); \
}
int main(void) {
size_t n = 1024 * 1024;
double *p;
HIP(hipMallocManaged(&p, sizeof(double) * n, hipMemAttachGlobal));
HIP(hipDeviceSynchronize());
for (size_t i = 0; i < n; ++i) {
p[i] = i;
}
HIP(hipDeviceSynchronize());
return 0;
}