From 37d76bc6a6018221d03de61d7316db6de2912472 Mon Sep 17 00:00:00 2001 From: Jaydeep Patel Date: Fri, 17 Mar 2023 06:08:11 +0000 Subject: [PATCH] SWDEV-388942 - hipGraphMemsetNodeSetParams & hipGraphExecMemsetNodeSetParams differs in validation as per cuda. Change-Id: Ie013aa5e94e8c468d949797890fb6b629e97a323 [ROCm/clr commit: 17553de9b79a54bce7189cd7d2146b5f5a1a73a5] --- .../clr/hipamd/src/hip_graph_internal.hpp | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/projects/clr/hipamd/src/hip_graph_internal.hpp b/projects/clr/hipamd/src/hip_graph_internal.hpp index f033ec01c2..0918f4fce8 100644 --- a/projects/clr/hipamd/src/hip_graph_internal.hpp +++ b/projects/clr/hipamd/src/hip_graph_internal.hpp @@ -1628,8 +1628,6 @@ class hipGraphMemsetNode : public hipGraphNode { hipError_t SetParams(const hipMemsetParams* params, bool isExec = false) { hipError_t hip_error = hipSuccess; - hipMemsetParams origParams = {}; - GetParams(&origParams); hip_error = ihipGraphMemsetParams_validate(params); if (hip_error != hipSuccess) { return hip_error; @@ -1648,16 +1646,38 @@ class hipGraphMemsetNode : public hipGraphNode { } size_t sizeBytes; if (params->height == 1) { + // 1D - for hipGraphMemsetNodeSetParams & hipGraphExecMemsetNodeSetParams, They return + // invalid value if new width is more than actual allocation. + size_t discardOffset = 0; + amd::Memory *memObj = getMemoryObject(params->dst, discardOffset); + if (memObj != nullptr) { + if (params->width * params->elementSize > memObj->getSize()) { + return hipErrorInvalidValue; + } + } sizeBytes = params->width * params->elementSize; - if (sizeBytes != origParams.width * origParams.elementSize) { - return hipErrorInvalidValue; - } hip_error = ihipMemset_validate(params->dst, params->value, params->elementSize, sizeBytes); } else { - sizeBytes = params->width * params->height * 1; - if (sizeBytes != origParams.width * origParams.height * 1) { - return hipErrorInvalidValue; - } + if (isExec) { + // 2D - hipGraphExecMemsetNodeSetParams returns invalid value if new width or new height is + // not same as what memset node is added with. + if (pMemsetParams_->width * pMemsetParams_->elementSize != params->width * params->elementSize + || pMemsetParams_->height != params->height) { + return hipErrorInvalidValue; + } + } else { + // 2D - hipGraphMemsetNodeSetParams returns invalid value if new width or new height is + // greter than actual allocation. + size_t discardOffset = 0; + amd::Memory *memObj = getMemoryObject(params->dst, discardOffset); + if (memObj != nullptr) { + if (params->width * params->elementSize > memObj->getUserData().width_ + || params->height > memObj->getUserData().height_) { + return hipErrorInvalidValue; + } + } + } + sizeBytes = params->width * params->elementSize * params->height * 1; hip_error = ihipMemset3D_validate({params->dst, params->pitch, params->width * params->elementSize, params->height}, params->value, {params->width * params->elementSize, params->height, 1}, sizeBytes);