SWDEV-279486 - Fix hipMemcpyPeer/hipMemcpy APIs

Addresses the scenarios when the size passed is more than
the allocated size and when the deviceid is invalid
Change-Id: I6c9b62639096f655ffb61976905b1ce8c5f51ee7

Change-Id: I8a0d660924a8e2300c517aba6f9088626b8f6ef5
This commit is contained in:
Satyanvesh Dittakavi
2021-04-06 06:37:14 -07:00
parent 865ecc64af
commit 68161ff0dd
3 changed files with 19 additions and 1 deletions
+6
View File
@@ -212,6 +212,12 @@ hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKin
amd::Memory *srcMemory = getMemoryObject(src, sOffset);
size_t dOffset = 0;
amd::Memory *dstMemory = getMemoryObject(dst, dOffset);
// Return error if sizeBytes passed to memcpy is more than the actual size allocated
if ((dstMemory && sizeBytes > (dstMemory->getSize() - dOffset)) ||
(srcMemory && sizeBytes > (srcMemory->getSize() - sOffset))) {
return hipErrorInvalidValue;
}
amd::Device* queueDevice = &queue.device();
if ((srcMemory == nullptr) && (dstMemory == nullptr)) {
if ((kind == hipMemcpyHostToHost) || (kind == hipMemcpyDefault)) {