From b8040b3d6a15828bc1916e07208fb879de3aea7b Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 4 Nov 2016 18:18:13 -0400
Subject: [PATCH] P4 to Git Change 1337009 by gandryey@gera-w8 on 2016/11/04
18:04:52
SWDEV-79445 - OCL generic changes and code clean-up
- Use uint64_t for the scratch buffer size calculation
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#558 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#162 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLDevice.cpp#175 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLDevice.h#63 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#32 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#13 edit
---
rocclr/runtime/device/gpu/gpudevice.cpp | 16 +++++++++++++---
rocclr/runtime/device/gpu/gpudevice.hpp | 8 ++++----
.../device/gpu/gslbe/src/rt/GSLDevice.cpp | 6 ++----
.../device/gpu/gslbe/src/rt/GSLDevice.h | 2 +-
rocclr/runtime/device/pal/paldevice.cpp | 19 ++++++++++++++-----
rocclr/runtime/device/pal/paldevice.hpp | 8 ++++----
6 files changed, 38 insertions(+), 21 deletions(-)
diff --git a/rocclr/runtime/device/gpu/gpudevice.cpp b/rocclr/runtime/device/gpu/gpudevice.cpp
index fd71dfb10a..04b2ae9706 100644
--- a/rocclr/runtime/device/gpu/gpudevice.cpp
+++ b/rocclr/runtime/device/gpu/gpudevice.cpp
@@ -2072,6 +2072,13 @@ Device::allocScratch(uint regNum, const VirtualGPU* vgpu)
// Serialize the scratch buffer allocation code
amd::ScopedLock lk(*scratchAlloc_);
uint sb = vgpu->hwRing();
+
+ static const uint WaveSizeLimit = ((1 << 21) - 256);
+ const uint threadSizeLimit = WaveSizeLimit / getAttribs().wavefrontSize;
+ if (regNum > threadSizeLimit) {
+ LogError("Requested private memory is bigger than HW supports!");
+ regNum = threadSizeLimit;
+ }
// Check if the current buffer isn't big enough
if (regNum > scratch_[sb]->regNum_) {
@@ -2079,8 +2086,8 @@ Device::allocScratch(uint regNum, const VirtualGPU* vgpu)
ScopedLockVgpus lock(*this);
scratch_[sb]->regNum_ = regNum;
- size_t size = 0;
- uint offset = 0;
+ uint64_t size = 0;
+ uint64_t offset = 0;
// Destroy all views
for (uint s = 0; s < scratch_.size(); ++s) {
@@ -2089,6 +2096,9 @@ Device::allocScratch(uint regNum, const VirtualGPU* vgpu)
scratchBuf->destroyMemory();
// Calculate the size of the scratch buffer for a queue
scratchBuf->size_ = calcScratchBufferSize(scratchBuf->regNum_);
+ scratchBuf->size_ = std::min(scratchBuf->size_, info().maxMemAllocSize_);
+ scratchBuf->size_ = std::min(scratchBuf->size_, uint64_t(3 * Gi));
+ scratchBuf->size_ = amd::alignUp(scratchBuf->size_, 0xFFFF);
scratchBuf->offset_ = offset;
size += scratchBuf->size_;
offset += scratchBuf->size_;
@@ -2098,7 +2108,7 @@ Device::allocScratch(uint regNum, const VirtualGPU* vgpu)
delete globalScratchBuf_;
// Allocate new buffer.
- globalScratchBuf_ = new gpu::Memory(*this, size);
+ globalScratchBuf_ = new gpu::Memory(*this, static_cast(size));
if ((globalScratchBuf_ == NULL) ||
!globalScratchBuf_->create(Resource::Scratch)) {
LogError("Couldn't allocate scratch memory");
diff --git a/rocclr/runtime/device/gpu/gpudevice.hpp b/rocclr/runtime/device/gpu/gpudevice.hpp
index 3195289f75..05bd7daaf1 100644
--- a/rocclr/runtime/device/gpu/gpudevice.hpp
+++ b/rocclr/runtime/device/gpu/gpudevice.hpp
@@ -321,10 +321,10 @@ public:
struct ScratchBuffer : public amd::HeapObject
{
- uint regNum_; //!< The number of used scratch registers
- Memory* memObj_; //!< Memory objects for scratch buffers
- uint offset_; //!< Offset from the global scratch store
- uint size_; //!< Scratch buffer size on this queue
+ uint regNum_; //!< The number of used scratch registers
+ Memory* memObj_; //!< Memory objects for scratch buffers
+ uint64_t offset_; //!< Offset from the global scratch store
+ uint64_t size_; //!< Scratch buffer size on this queue
//! Default constructor
ScratchBuffer(): regNum_(0), memObj_(NULL), offset_(0) {}
diff --git a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.cpp b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.cpp
index 77bcd5e882..2b0f6a2a90 100644
--- a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.cpp
+++ b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.cpp
@@ -1263,7 +1263,7 @@ CALGSLDevice::GetCopyType(
return type;
}
-uint32
+uint64
CALGSLDevice::calcScratchBufferSize(uint32 regNum) const
{
gslProgramTargetEnum target = GSL_COMPUTE_PROGRAM;
@@ -1290,13 +1290,11 @@ CALGSLDevice::calcScratchBufferSize(uint32 regNum) const
// be 64K alignment)
if (scratchBufferSizes[target] > 0)
{
- scratchBufferSizes[target] = (scratchBufferSizes[target] >> 2) & 0xFFFF0000;
+ scratchBufferSizes[target] = (scratchBufferSizes[target] >> 2);
if (scratchBufferSizes[target] == 0) { // assign minimum scratch buffer size of 64K
scratchBufferSizes[target] = 0x10000;
}
-
- assert(scratchBufferSizes[target] <= 0xFFFFFFFF); // scratch buffer size < 4GB
}
return scratchBufferSizes[target];
diff --git a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h
index 099c61715a..8660344f4f 100644
--- a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h
+++ b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h
@@ -107,7 +107,7 @@ public:
CopyType GetCopyType(gslMemObject srcMem, gslMemObject destMem, size_t* srcOffset,
size_t* destOffset, bool allowDMA, uint32 flags, size_t size, bool enableCopyRect) const;
- uint32 calcScratchBufferSize(uint32 regNum) const;
+ uint64 calcScratchBufferSize(uint32 regNum) const;
amd::Monitor& gslDeviceOps() const { return *gslDeviceOps_; }
diff --git a/rocclr/runtime/device/pal/paldevice.cpp b/rocclr/runtime/device/pal/paldevice.cpp
index 91b3728019..930bfa0f0b 100644
--- a/rocclr/runtime/device/pal/paldevice.cpp
+++ b/rocclr/runtime/device/pal/paldevice.cpp
@@ -1804,15 +1804,21 @@ Device::allocScratch(uint regNum, const VirtualGPU* vgpu)
// Serialize the scratch buffer allocation code
amd::ScopedLock lk(*scratchAlloc_);
uint sb = vgpu->hwRing();
-
+ static const uint WaveSizeLimit = ((1 << 21) - 256);
+ const uint threadSizeLimit = WaveSizeLimit /
+ properties().gfxipProperties.shaderCore.wavefrontSize;
+ if (regNum > threadSizeLimit) {
+ LogError("Requested private memory is bigger than HW supports!");
+ regNum = threadSizeLimit;
+ }
// Check if the current buffer isn't big enough
if (regNum > scratch_[sb]->regNum_) {
// Stall all command queues, since runtime will reallocate memory
ScopedLockVgpus lock(*this);
scratch_[sb]->regNum_ = regNum;
- size_t size = 0;
- uint offset = 0;
+ uint64_t size = 0;
+ uint64_t offset = 0;
// Destroy all views
for (uint s = 0; s < scratch_.size(); ++s) {
@@ -1823,8 +1829,11 @@ Device::allocScratch(uint regNum, const VirtualGPU* vgpu)
uint32_t numTotalCUs = info().maxComputeUnits_;
uint32_t numMaxWaves =
properties().gfxipProperties.shaderCore.maxScratchWavesPerCu * numTotalCUs;
- scratchBuf->size_ = properties().gfxipProperties.shaderCore.wavefrontSize *
+ scratchBuf->size_ = static_cast(properties().
+ gfxipProperties.shaderCore.wavefrontSize) *
scratchBuf->regNum_ * numMaxWaves * sizeof(uint32_t);
+ scratchBuf->size_ = std::min(scratchBuf->size_, info().maxMemAllocSize_);
+ scratchBuf->size_ = std::min(scratchBuf->size_, uint64_t(3 * Gi));
scratchBuf->size_ = amd::alignUp(scratchBuf->size_, 0xFFFF);
scratchBuf->offset_ = offset;
size += scratchBuf->size_;
@@ -1835,7 +1844,7 @@ Device::allocScratch(uint regNum, const VirtualGPU* vgpu)
delete globalScratchBuf_;
// Allocate new buffer.
- globalScratchBuf_ = new pal::Memory(*this, size);
+ globalScratchBuf_ = new pal::Memory(*this, static_cast(size));
if ((globalScratchBuf_ == nullptr) ||
!globalScratchBuf_->create(Resource::Scratch)) {
LogError("Couldn't allocate scratch memory");
diff --git a/rocclr/runtime/device/pal/paldevice.hpp b/rocclr/runtime/device/pal/paldevice.hpp
index 22141ccd7e..ffb2e311fc 100644
--- a/rocclr/runtime/device/pal/paldevice.hpp
+++ b/rocclr/runtime/device/pal/paldevice.hpp
@@ -246,10 +246,10 @@ public:
struct ScratchBuffer : public amd::HeapObject
{
- uint regNum_; //!< The number of used scratch registers
- Memory* memObj_; //!< Memory objects for scratch buffers
- uint offset_; //!< Offset from the global scratch store
- uint size_; //!< Scratch buffer size on this queue
+ uint regNum_; //!< The number of used scratch registers
+ Memory* memObj_; //!< Memory objects for scratch buffers
+ uint64_t offset_; //!< Offset from the global scratch store
+ uint64_t size_; //!< Scratch buffer size on this queue
//! Default constructor
ScratchBuffer(): regNum_(0), memObj_(NULL), offset_(0) {}