From c507deb37f18ba9d3070c2f6fcf5076b31f0098c Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 6 Apr 2018 12:39:00 -0400
Subject: [PATCH] P4 to Git Change 1537540 by gandryey@gera-w8 on 2018/04/06
12:30:49
SWDEV-79445 - OCL generic changes and code clean-up
- Reduce the managed buffer alignment to 128 bytes
- Add direct upload function to the constant buffer
- Add heap preference print into the active allocations
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palconstbuf.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palconstbuf.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palkernel.cpp#49 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#87 edit
[ROCm/clr commit: c006b7b2628eb93ad509e64fc0194fa5407c90b7]
---
.../rocclr/runtime/device/pal/palconstbuf.cpp | 15 ++++--
.../rocclr/runtime/device/pal/palconstbuf.hpp | 8 ++++
.../rocclr/runtime/device/pal/palkernel.cpp | 18 +++----
.../rocclr/runtime/device/pal/palvirtual.cpp | 47 ++++++++++---------
4 files changed, 52 insertions(+), 36 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/pal/palconstbuf.cpp b/projects/clr/rocclr/runtime/device/pal/palconstbuf.cpp
index fe4b265fe7..b5a266fe43 100644
--- a/projects/clr/rocclr/runtime/device/pal/palconstbuf.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palconstbuf.cpp
@@ -53,7 +53,8 @@ bool ManagedBuffer::create(Resource::MemoryType type) {
// ================================================================================================
address ManagedBuffer::reserve(uint32_t size, uint64_t* gpu_address) {
- static constexpr uint32_t MemAlignment = 256;
+ // Align to the maximum data size available in OpenCL
+ static constexpr uint32_t MemAlignment = sizeof(cl_double16);
// Align reserve size on the vector's boundary
uint32_t count = amd::alignUp(size, MemAlignment);
@@ -103,8 +104,7 @@ bool ConstantBuffer::Create() {
}
// ================================================================================================
-uint64_t ConstantBuffer::UploadDataToHw(uint32_t size) const
-{
+uint64_t ConstantBuffer::UploadDataToHw(uint32_t size) const {
uint64_t vm_address;
address cpu_address = mbuf_.reserve(size, &vm_address);
// Update memory with new CB data
@@ -112,4 +112,13 @@ uint64_t ConstantBuffer::UploadDataToHw(uint32_t size) const
return vm_address;
}
+// ================================================================================================
+uint64_t ConstantBuffer::UploadDataToHw(const void* sysmem, uint32_t size) const {
+ uint64_t vm_address;
+ address cpu_address = mbuf_.reserve(size, &vm_address);
+ // Update memory with new CB data
+ memcpy(cpu_address, sysmem, size);
+ return vm_address;
+}
+
} // namespace pal
diff --git a/projects/clr/rocclr/runtime/device/pal/palconstbuf.hpp b/projects/clr/rocclr/runtime/device/pal/palconstbuf.hpp
index d2595036a1..5b6cb2af1b 100644
--- a/projects/clr/rocclr/runtime/device/pal/palconstbuf.hpp
+++ b/projects/clr/rocclr/runtime/device/pal/palconstbuf.hpp
@@ -79,6 +79,14 @@ public:
uint64_t UploadDataToHw(uint32_t size //!< real data size for upload
) const;
+ /*! \brief Uploads current constant buffer data from sysMemCopy_ to HW
+ *
+ * \return GPU address for the uploaded data
+ */
+ uint64_t UploadDataToHw(const void* sysmem, //!< Pointer to the data for upload
+ uint32_t size //!< Real data size for upload
+ ) const;
+
//! Returns a pointer to the system memory copy for CB
address SysMemCopy(uint32_t size = 0) const { return sys_mem_copy_; }
diff --git a/projects/clr/rocclr/runtime/device/pal/palkernel.cpp b/projects/clr/rocclr/runtime/device/pal/palkernel.cpp
index d8a290ffba..18d03debf5 100644
--- a/projects/clr/rocclr/runtime/device/pal/palkernel.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palkernel.cpp
@@ -921,16 +921,14 @@ hsa_kernel_dispatch_packet_t* HSAILKernel::loadArguments(
static const bool WaitOnBusyEngine = true;
uint64_t ldsAddress = ldsSize();
address aqlArgBuf = gpu.cb(0)->SysMemCopy();
- address aqlStruct = gpu.cb(1)->SysMemCopy();
bool srdResource = false;
if (dynamicParallelism()) {
// Provide the host parent AQL wrap object to the kernel
- AmdAqlWrap* wrap = reinterpret_cast(aqlStruct);
- memset(wrap, 0, sizeof(AmdAqlWrap));
- wrap->state = AQL_WRAP_BUSY;
+ AmdAqlWrap wrap = {};
+ wrap.state = AQL_WRAP_BUSY;
const ConstantBuffer* cb = gpu.cb(1);
- *vmParentWrap = cb->UploadDataToHw(sizeof(AmdAqlWrap));
+ *vmParentWrap = cb->UploadDataToHw(&wrap, sizeof(AmdAqlWrap));
gpu.addVmMemory(cb->ActiveMemory());
}
@@ -1063,11 +1061,10 @@ hsa_kernel_dispatch_packet_t* HSAILKernel::loadArguments(
break;
}
case HSAIL_ARGTYPE_REFERENCE: {
- // Copy the current structure into CB1
- memcpy(aqlStruct, paramaddr, arg->size_);
const ConstantBuffer* cb = gpu.cb(1);
+ // Copy the current structure into CB1
+ size_t gpuPtr = static_cast(cb->UploadDataToHw(paramaddr, arg->size_));
// Then use a pointer in aqlArgBuffer to CB1
- size_t gpuPtr = static_cast(cb->UploadDataToHw(arg->size_));
WriteAqlArg(&aqlArgBuf, &gpuPtr, sizeof(size_t), sizeof(size_t));
gpu.addVmMemory(cb->ActiveMemory());
break;
@@ -1105,11 +1102,10 @@ hsa_kernel_dispatch_packet_t* HSAILKernel::loadArguments(
//! Copy SRD to CB1, so blit manager will be able to release
//! this view without a wait for SRD resource.
if (image->memoryType() == Resource::ImageView) {
- // Copy the current structre into CB1
- memcpy(aqlStruct, image->hwState(), HsaImageObjectSize);
+ // Copy the current image SRD into CB1
const ConstantBuffer* cb = gpu.cb(1);
+ uint64_t srd = cb->UploadDataToHw(image->hwState(), HsaImageObjectSize);
// Then use a pointer in aqlArgBuffer to CB1
- uint64_t srd = cb->UploadDataToHw(HsaImageObjectSize);
WriteAqlArg(&aqlArgBuf, &srd, sizeof(srd), sizeof(srd));
gpu.addVmMemory(cb->ActiveMemory());
} else {
diff --git a/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp b/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp
index 4d07346f49..e24ddc5373 100644
--- a/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palvirtual.cpp
@@ -360,42 +360,45 @@ void VirtualGPU::Queue::DumpMemoryReferences() const {
if (dump.is_open()) {
dump << start << " Queue: ";
switch (iQueue_->Type()) {
- case Pal::QueueTypeCompute:
- dump << "Compute";
- break;
- case Pal::QueueTypeDma:
- dump << "SDMA";
- break;
- default:
- dump << "unknown";
- break;
+ case Pal::QueueTypeCompute:
+ dump << "Compute";
+ break;
+ case Pal::QueueTypeDma:
+ dump << "SDMA";
+ break;
+ default:
+ dump << "unknown";
+ break;
}
dump << "\n"
- << "Resident memory resources:\n";
+ << "Resident memory resources:\n";
uint idx = 0;
for (auto it : memReferences_) {
dump << " " << idx << "\t[";
dump.setf(std::ios::hex, std::ios::basefield);
dump.setf(std::ios::showbase);
dump << (it.first)->iMem()->Desc().gpuVirtAddr << ", "
- << (it.first)->iMem()->Desc().gpuVirtAddr + (it.first)->iMem()->Desc().size;
+ << (it.first)->iMem()->Desc().gpuVirtAddr + (it.first)->iMem()->Desc().size;
dump.setf(std::ios::dec);
- dump << "] CbId:" << it.second << "\n";
+ dump << "] CbId:" << it.second <<
+ ", Heap: " << (it.first)->iMem()->Desc().preferredHeap << "\n";
idx++;
}
- }
- if (last_kernel_ != nullptr) {
- const amd::KernelSignature& signature = last_kernel_->signature();
- dump << last_kernel_->name() << std::endl;
- for (size_t i = 0; i < signature.numParameters(); ++i) {
- const amd::KernelParameterDescriptor& desc = signature.at(i);
- // Find if the current argument is a memory object
- if ((desc.type_ == T_POINTER) && (desc.addressQualifier_ != CL_KERNEL_ARG_ADDRESS_LOCAL)) {
- dump << " " << desc.name_ << ": " << std::endl;
+
+ if (last_kernel_ != nullptr) {
+ const amd::KernelSignature& signature = last_kernel_->signature();
+ dump << last_kernel_->name() << std::endl;
+ for (size_t i = 0; i < signature.numParameters(); ++i) {
+ const amd::KernelParameterDescriptor& desc = signature.at(i);
+ // Find if the current argument is a memory object
+ if ((desc.type_ == T_POINTER) &&
+ (desc.addressQualifier_ != CL_KERNEL_ARG_ADDRESS_LOCAL)) {
+ dump << " " << desc.name_ << ": " << std::endl;
+ }
}
}
+ dump.close();
}
- dump.close();
}
bool VirtualGPU::MemoryDependency::create(size_t numMemObj) {