SWDEV-369552 - SWDEV-369553 - SWDEV-369555 - Fix hipMemAdvise
- API should return error if the size passed is more than the
bytes allocated
- Passing invalid device should return error except for the
advise hipMemAdviseSetReadMostly
Change-Id: I1c4c15136b825215bf1e1f5ee7a9a08e5895d870
[ROCm/clr commit: 873bc03034]
This commit is contained in:
@@ -133,11 +133,29 @@ hipError_t hipMemPrefetchAsync(const void* dev_ptr, size_t count, int device,
|
||||
hipError_t hipMemAdvise(const void* dev_ptr, size_t count, hipMemoryAdvise advice, int device) {
|
||||
HIP_INIT_API(hipMemAdvise, dev_ptr, count, advice, device);
|
||||
|
||||
if ((dev_ptr == nullptr) || (count == 0) ||
|
||||
((device != hipCpuDeviceId) && (static_cast<size_t>(device) >= g_devices.size()))) {
|
||||
bool isAdviseReadMostly = (advice == hipMemAdviseSetReadMostly) ||
|
||||
(advice == hipMemAdviseUnsetReadMostly);
|
||||
|
||||
if (!isAdviseReadMostly && ((device != hipCpuDeviceId) &&
|
||||
(static_cast<size_t>(device) >= g_devices.size()))) {
|
||||
HIP_RETURN(hipErrorInvalidDevice);
|
||||
}
|
||||
|
||||
if ((dev_ptr == nullptr) || (count == 0)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
amd::Device* dev = (device == hipCpuDeviceId) ?
|
||||
|
||||
size_t offset = 0;
|
||||
amd::Memory* memObj = getMemoryObject(dev_ptr, offset);
|
||||
if (memObj == nullptr) {
|
||||
HIP_RETURN(hipErrorMemoryAllocation);
|
||||
}
|
||||
|
||||
if (count > (memObj->getSize() - offset)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
amd::Device* dev = (device == hipCpuDeviceId || isAdviseReadMostly) ?
|
||||
g_devices[0]->devices()[0] : g_devices[device]->devices()[0];
|
||||
bool use_cpu = (device == hipCpuDeviceId) ? true : false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user