From 8923e6d97dae84d2f0dd15cae394b87fed7381b3 Mon Sep 17 00:00:00 2001 From: Sarbojit Sarkar Date: Fri, 17 Sep 2021 09:31:54 +0000 Subject: [PATCH] SWDEV-301823 - Optimized hipMemset2D/3D Change-Id: I1e817ab135bfdf9b8f9af18c1bf2cd2e926db729 [ROCm/clr commit: 98c172c2e4ca4923f5b24cd6cd0ab7f2d8b54ac0] --- projects/clr/hipamd/src/hip_memory.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/projects/clr/hipamd/src/hip_memory.cpp b/projects/clr/hipamd/src/hip_memory.cpp index 18c5a804bd..340b18c5f2 100644 --- a/projects/clr/hipamd/src/hip_memory.cpp +++ b/projects/clr/hipamd/src/hip_memory.cpp @@ -2070,9 +2070,11 @@ hipError_t packFillMemoryCommand(amd::Command*& command, amd::Memory* memory, si amd::Command::EventWaitList waitList; amd::Coord3D fillOffset(offset, 0, 0); amd::Coord3D fillSize(sizeBytes, 1, 1); + // surface=[pitch, width, height] + amd::Coord3D surface(sizeBytes, sizeBytes, 1); command = new amd::FillMemoryCommand(*queue, CL_COMMAND_FILL_BUFFER, waitList, *memory->asBuffer(), - &value, valueSize, fillOffset, fillSize); + &value, valueSize, fillOffset, fillSize, surface); if (command == nullptr) { return hipErrorOutOfMemory; } @@ -2264,23 +2266,20 @@ hipError_t ihipMemset3DCommand(std::vector &commands, hipPitchedP // Workaround for cases when pitch > row until fill kernel will be updated to support pitch. // Fall back to filling one row at a time. amd::Coord3D origin(offset); - amd::Coord3D region(pitchedDevPtr.xsize, pitchedDevPtr.ysize, extent.depth); + amd::Coord3D region(extent.width, extent.height, extent.depth); + amd::Coord3D surface(pitchedDevPtr.pitch, pitchedDevPtr.xsize, pitchedDevPtr.ysize); amd::BufferRect rect; if (pitchedDevPtr.pitch == 0 || - !rect.create(static_cast(origin), static_cast(region), pitchedDevPtr.pitch, - 0)) { + !rect.create(static_cast(origin), + static_cast(amd::Coord3D{pitchedDevPtr.xsize, pitchedDevPtr.ysize, extent.depth}), + pitchedDevPtr.pitch, 0)) { return hipErrorInvalidValue; } amd::FillMemoryCommand* command; - for (size_t slice = 0; slice < extent.depth; slice++) { - for (size_t row = 0; row < extent.height; row++) { - const size_t rowOffset = rect.offset(0, row, slice); - command = new amd::FillMemoryCommand( - *queue, CL_COMMAND_FILL_BUFFER, amd::Command::EventWaitList{}, *memory->asBuffer(), - &value, sizeof(int8_t), amd::Coord3D{rowOffset, 0, 0}, amd::Coord3D{extent.width, 1, 1}); - commands.push_back(command); - } - } + command = new amd::FillMemoryCommand( + *queue, CL_COMMAND_FILL_BUFFER, amd::Command::EventWaitList{}, *memory->asBuffer(), + &value, sizeof(int8_t), origin, region, surface); + commands.push_back(command); return hipSuccess; }