From f845041f7d8eedd95bf3c97bea0254b75c024255 Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Tue, 27 Apr 2021 04:30:18 -0700 Subject: [PATCH] SWDEV-283213 - Fix hipMemset2D, 3D failures in Debug mode If the width is 0, hipMemset2D or 3D APIs should return success doing nothing Change-Id: I97f8825d090a73ee63145e52d2b6d2cc0eddade3 Change-Id: I9d62fee70929ad0c79b947aa4cbbc8ab898fb64a --- hipamd/rocclr/hip_memory.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hipamd/rocclr/hip_memory.cpp b/hipamd/rocclr/hip_memory.cpp index bf70b3cdad..3f6cc4234f 100755 --- a/hipamd/rocclr/hip_memory.cpp +++ b/hipamd/rocclr/hip_memory.cpp @@ -2066,16 +2066,11 @@ hipError_t hipMemsetD32Async(hipDeviceptr_t dst, int value, size_t count, HIP_RETURN(ihipMemset(dst, value, sizeof(int32_t), count * sizeof(int32_t), stream, true)); } -inline hipError_t ihipMemset3D_validate(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent) { +inline hipError_t ihipMemset3D_validate(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent, + size_t sizeBytes) { size_t offset = 0; amd::Memory* memory = getMemoryObject(pitchedDevPtr.ptr, offset); - auto sizeBytes = extent.width * extent.height * extent.depth; - - if (sizeBytes == 0) { - // sizeBytes is zero hence returning early as nothing to be set - return hipSuccess; - } if (memory == nullptr) { return hipErrorInvalidValue; } @@ -2120,7 +2115,13 @@ hipError_t ihipMemset3DCommand(std::vector &commands, hipPitchedP hipError_t ihipMemset3D(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent, hipStream_t stream, bool isAsync = false) { - hipError_t status = ihipMemset3D_validate(pitchedDevPtr, value, extent); + auto sizeBytes = extent.width * extent.height * extent.depth; + + if (sizeBytes == 0) { + // sizeBytes is zero hence returning early as nothing to be set + return hipSuccess; + } + hipError_t status = ihipMemset3D_validate(pitchedDevPtr, value, extent, sizeBytes); if (status != hipSuccess) { return status; } @@ -2128,7 +2129,7 @@ hipError_t ihipMemset3D(hipPitchedPtr pitchedDevPtr, int value, hipExtent extent std::vector commands; ihipMemset3DCommand(commands, pitchedDevPtr, value, extent, queue); for (auto& command : commands) { - command->enqueue(); + command->enqueue(); if (!isAsync) { command->awaitCompletion(); }