Files
rocm-systems/rocclr/runtime/device/gpu/gpuconstbuf.cpp
T
foreman 4b23814a4d P4 to Git Change 1195141 by gandryey@gera-dev-w7 on 2015/09/28 15:09:34
SWDEV-77522 - Remove direct references to the Resource object
	- In non-VM mode Resource was used as a memory object outside of SW heap

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpublit.cpp#119 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpublit.hpp#39 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuconstbuf.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuconstbuf.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#528 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#153 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.cpp#298 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.hpp#117 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpumemory.hpp#49 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprintf.cpp#38 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprintf.hpp#14 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#208 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#60 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#228 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.hpp#84 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#383 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#135 edit
2015-09-28 17:41:36 -04:00

90 خطوط
2.2 KiB
C++

//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//
#include "device/gpu/gpuconstbuf.hpp"
#include "device/gpu/gpuvirtual.hpp"
#include "device/gpu/gpudevice.hpp"
#include "device/gpu/gpusettings.hpp"
namespace gpu {
ConstBuffer::ConstBuffer(
VirtualGPU& gpu,
size_t size)
: Memory(const_cast<gpu::Device&>(gpu.dev()), size * VectorSize)
, gpu_(gpu)
, size_(size * VectorSize)
, wrtOffset_(0)
, lastWrtSize_(0)
, wrtAddress_(NULL)
{
}
ConstBuffer::~ConstBuffer()
{
if (wrtAddress_ != NULL) {
unmap(&gpu_);
}
amd::AlignedMemory::deallocate(sysMemCopy_);
}
bool
ConstBuffer::create()
{
// Create sysmem copy for the constant buffer
sysMemCopy_ = reinterpret_cast<address>(amd::AlignedMemory::allocate(size_, 256));
if (sysMemCopy_ == NULL) {
LogPrintfError("We couldn't allocate sysmem copy for constant buffer,\
size(%d)!", size_);
return false;
}
memset(sysMemCopy_, 0, size_);
if (!Memory::create(Resource::RemoteUSWC)) {
LogPrintfError("We couldn't create HW constant buffer, size(%d)!", size_);
return false;
}
// Constant buffer warm-up
warmUpRenames(gpu_);
wrtAddress_ = map(&gpu_, Resource::Discard);
if (wrtAddress_ == NULL) {
LogPrintfError("We couldn't map HW constant buffer, size(%d)!", size_);
return false;
}
return true;
}
bool
ConstBuffer::uploadDataToHw(size_t size)
{
static const size_t HwCbAlignment = 256;
// Align copy size on the vector's boundary
size_t count = amd::alignUp(size, VectorSize);
wrtOffset_ += lastWrtSize_;
// Check if CB has enough space for copy
if ((wrtOffset_ + count) > size_) {
if (wrtAddress_ != NULL) {
unmap(&gpu_);
}
wrtAddress_ = map(&gpu_, Resource::Discard);
wrtOffset_ = 0;
lastWrtSize_ = 0;
}
// Update memory with new CB data
memcpy((reinterpret_cast<char*>(wrtAddress_) + wrtOffset_), sysMemCopy_, count);
// Adjust the size by the HW CB buffer alignment
lastWrtSize_ = amd::alignUp(size, HwCbAlignment);
return true;
}
} // namespace gpu