From 20974393b14d8de18e3b60b4cb12e534a38cb1e6 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 24 Mar 2015 11:45:49 -0400
Subject: [PATCH] P4 to Git Change 1133818 by gandryey@gera-w8 on 2015/03/24
11:30:12
ECR #304775 - Mipmaps support in OCL
- Add support for clEnqueueMapImage/Unmap functionality
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_memobj.cpp#76 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#175 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#241 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#503 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#140 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpumemory.cpp#120 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#212 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#356 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa/hsadevice.cpp#89 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa/hsadevice.hpp#46 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.cpp#27 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/hsa_foundation/hsadevice.hpp#13 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.hpp#14 edit
---
rocclr/runtime/device/device.cpp | 27 +++++++++++++++---
rocclr/runtime/device/device.hpp | 17 ++++++++++--
rocclr/runtime/device/gpu/gpudevice.cpp | 21 +-------------
rocclr/runtime/device/gpu/gpudevice.hpp | 22 ---------------
rocclr/runtime/device/gpu/gpumemory.cpp | 3 +-
rocclr/runtime/device/gpu/gpuresource.cpp | 7 +++--
rocclr/runtime/device/gpu/gpuvirtual.cpp | 34 +++++++++++++++++++++++
rocclr/runtime/device/hsa/hsadevice.cpp | 20 -------------
rocclr/runtime/device/hsa/hsadevice.hpp | 25 -----------------
rocclr/runtime/platform/commandqueue.hpp | 4 +--
10 files changed, 81 insertions(+), 99 deletions(-)
diff --git a/rocclr/runtime/device/device.cpp b/rocclr/runtime/device/device.cpp
index 22fb11b9d5..ade4bb3358 100644
--- a/rocclr/runtime/device/device.cpp
+++ b/rocclr/runtime/device/device.cpp
@@ -269,9 +269,6 @@ Device::isAncestor(const Device* sub) const
return false;
}
-
-
-
bool Device::IsHsaCapableDevice() {
static bool init = false;
typedef std::vector ListType;
@@ -506,6 +503,26 @@ Device::getExtensionString()
return result;
}
+void*
+Device::allocMapTarget(
+ amd::Memory& mem,
+ const amd::Coord3D& origin,
+ const amd::Coord3D& region,
+ uint mapFlags,
+ size_t* rowPitch,
+ size_t* slicePitch)
+{
+ // Translate memory references
+ device::Memory* devMem = mem.getDeviceMemory(*this);
+ if (devMem == NULL) {
+ LogError("allocMapTarget failed. Can't allocate video memory");
+ return NULL;
+ }
+
+ // Pass request over to memory
+ return devMem->allocMapTarget(origin, region, mapFlags, rowPitch, slicePitch);
+}
+
} // namespace amd
namespace device {
@@ -577,11 +594,13 @@ Memory::saveMapInfo(
const amd::Coord3D origin,
const amd::Coord3D region,
uint mapFlags,
- bool entire)
+ bool entire,
+ amd::Image* baseMip)
{
if (mapFlags & (CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION)) {
writeMapInfo_.origin_ = origin;
writeMapInfo_.region_ = region;
+ writeMapInfo_.baseMip_ = baseMip;
writeMapInfo_.entire_ = entire;
flags_ |= UnmapWrite;
}
diff --git a/rocclr/runtime/device/device.hpp b/rocclr/runtime/device/device.hpp
index b05c79ef43..77697ba379 100644
--- a/rocclr/runtime/device/device.hpp
+++ b/rocclr/runtime/device/device.hpp
@@ -648,8 +648,9 @@ public:
{
amd::Coord3D origin_; //!< Origin of the map location
amd::Coord3D region_; //!< Mapped region
+ amd::Image* baseMip_; //!< The base mip level for images
bool entire_; //!< True if the enitre memory was mapped
- WriteMapInfo(): origin_(0, 0, 0), region_(0, 0, 0), entire_(false) {}
+ WriteMapInfo(): origin_(0, 0, 0), region_(0, 0, 0), baseMip_(NULL), entire_(false) {}
};
//! Constructor (from an amd::Memory object).
@@ -698,6 +699,15 @@ public:
SyncFlags syncFlags = SyncFlags()
) {}
+ //! Allocate memory for API-level maps
+ virtual void* allocMapTarget(
+ const amd::Coord3D& origin, //!< The map location in memory
+ const amd::Coord3D& region, //!< The map region in memory
+ uint mapFlags, //!< Map flags
+ size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
+ size_t* slicePitch = NULL //!< Slice for the mapped memory
+ ) { return NULL; }
+
virtual bool pinSystemMemory(
void* hostPtr, //!< System memory address
size_t size //!< Size of allocated system memory
@@ -741,7 +751,8 @@ public:
const amd::Coord3D origin, //!< Origin of the map location
const amd::Coord3D region, //!< Mapped region
uint mapFlags, //< Map flags
- bool entire //!< True if the enitre memory was mapped
+ bool entire, //!< True if the enitre memory was mapped
+ amd::Image* baseMip = NULL //!< The base mip level for map
);
const WriteMapInfo* writeMapInfo() const { return &writeMapInfo_; }
@@ -1605,7 +1616,7 @@ public:
uint mapFlags, //!< Map flags
size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
size_t* slicePitch = NULL //!< Slice for the mapped memory
- ) = 0;
+ );
//! Gets free memory on a GPU device
virtual bool globalFreeMemory(
diff --git a/rocclr/runtime/device/gpu/gpudevice.cpp b/rocclr/runtime/device/gpu/gpudevice.cpp
index f0c71f9de7..af1a94fbae 100644
--- a/rocclr/runtime/device/gpu/gpudevice.cpp
+++ b/rocclr/runtime/device/gpu/gpudevice.cpp
@@ -1669,6 +1669,7 @@ Device::createBuffer(
!internalAlloc) {
Resource::CreateParams params;
params.owner_ = &owner;
+ params.gpu_ = static_cast(owner.getVirtualDevice());
// Create memory object
result = gpuMemory->create(type, ¶ms);
@@ -2145,26 +2146,6 @@ Device::unbindExternalDevice(intptr_t type, void* pDevice, void* pContext, bool
return true;
}
-void*
-Device::allocMapTarget(
- amd::Memory& mem,
- const amd::Coord3D& origin,
- const amd::Coord3D& region,
- uint mapFlags,
- size_t* rowPitch,
- size_t* slicePitch)
-{
- // Translate memory references
- gpu::Memory* memory = getGpuMemory(&mem);
- if (memory == NULL) {
- LogError("allocMapTarget failed. Can't allocate video memory");
- return NULL;
- }
-
- // Pass request over to memory
- return memory->allocMapTarget(origin, region, mapFlags, rowPitch, slicePitch);
-}
-
bool
Device::globalFreeMemory(size_t* freeMemory) const
{
diff --git a/rocclr/runtime/device/gpu/gpudevice.hpp b/rocclr/runtime/device/gpu/gpudevice.hpp
index bf9dd48a58..939212c4ce 100644
--- a/rocclr/runtime/device/gpu/gpudevice.hpp
+++ b/rocclr/runtime/device/gpu/gpudevice.hpp
@@ -105,17 +105,6 @@ public:
virtual bool unbindExternalDevice(
intptr_t type, void* pDevice, void* pContext, bool validateOnly) { return true; }
- //! Gets a pointer to a region of host-visible memory for use as the target
- //! of a non-blocking map for a given memory object
- virtual void* allocMapTarget(
- amd::Memory& mem, //!< Abstraction layer memory object
- const amd::Coord3D& origin, //!< The map location in memory
- const amd::Coord3D& region, //!< The map region in memory
- uint mapFlags, //!< Map flags
- size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
- size_t* slicePitch = NULL //!< Slice for the mapped memory
- ) { return NULL; }
-
//! Releases non-blocking map target memory
virtual void freeMapTarget(amd::Memory& mem, void* target) {}
@@ -432,17 +421,6 @@ public:
const device::VirtualDevice* vdev
);
- //! Gets a pointer to a region of host-visible memory for use as the target
- //! of a non-blocking map for a given memory object
- virtual void* allocMapTarget(
- amd::Memory& mem, //!< Abstraction layer memory object
- const amd::Coord3D& origin, //!< The map location in memory
- const amd::Coord3D& region, //!< The map region in memory
- uint mapFlags, //!< Map flags
- size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
- size_t* slicePitch = NULL //!< Slice for the mapped memory
- );
-
//! Retrieves information about free memory on a GPU device
virtual bool globalFreeMemory(size_t* freeMemory) const;
diff --git a/rocclr/runtime/device/gpu/gpumemory.cpp b/rocclr/runtime/device/gpu/gpumemory.cpp
index 9873a17eb1..45ae2e09c6 100644
--- a/rocclr/runtime/device/gpu/gpumemory.cpp
+++ b/rocclr/runtime/device/gpu/gpumemory.cpp
@@ -1324,8 +1324,9 @@ Image::allocMapTarget(
memory = new (owner()->getContext())
amd::Buffer(owner()->getContext(), 0,
cal()->width_ * height * depth * elementSize());
- Memory* gpuMemory;
+ memory->setVirtualDevice(owner()->getVirtualDevice());
+ Memory* gpuMemory;
do {
if ((memory == NULL) || !memory->create(NULL, SysMem)) {
failed = true;
diff --git a/rocclr/runtime/device/gpu/gpuresource.cpp b/rocclr/runtime/device/gpu/gpuresource.cpp
index 8c4eb36be7..dc1f767910 100644
--- a/rocclr/runtime/device/gpu/gpuresource.cpp
+++ b/rocclr/runtime/device/gpu/gpuresource.cpp
@@ -664,6 +664,9 @@ Resource::create(MemoryType memType, CreateParams* params, bool heap)
viewLevel = imageView->level_;
gslResource = imageView->resource_->gslResource();
viewOwner_ = imageView->resource_;
+ if (viewLevel != 0) {
+ viewFlags |= CAL_RESALLOCSLICEVIEW_LEVEL;
+ }
if (viewLayer != 0) {
viewFlags |= CAL_RESALLOCSLICEVIEW_LEVEL_AND_LAYER;
}
@@ -1662,7 +1665,7 @@ Resource::mapLayers(VirtualGPU* gpu, CALuint flags)
sliceResource = dev().resAllocView(
gslResource(), gslSize,
calOffset, cal()->format_, cal()->channelOrder_, gslDim,
- 0, i, CAL_RESALLOCSLICEVIEW_LAYER);
+ 0, i, CAL_RESALLOCSLICEVIEW_LEVEL_AND_LAYER);
if (0 == sliceResource) {
LogError("Map layer. resAllocSliceView failed!");
return NULL;
@@ -1772,7 +1775,7 @@ Resource::unmapLayers(VirtualGPU* gpu)
sliceResource = dev().resAllocView(
gslResource(), gslSize,
calOffset, cal()->format_, cal()->channelOrder_, gslDim,
- 0, i, CAL_RESALLOCSLICEVIEW_LAYER);
+ 0, i, CAL_RESALLOCSLICEVIEW_LEVEL_AND_LAYER);
if (0 == sliceResource) {
LogError("Unmap layer. resAllocSliceView failed!");
return;
diff --git a/rocclr/runtime/device/gpu/gpuvirtual.cpp b/rocclr/runtime/device/gpu/gpuvirtual.cpp
index 73742a35a0..611c7b3b66 100644
--- a/rocclr/runtime/device/gpu/gpuvirtual.cpp
+++ b/rocclr/runtime/device/gpu/gpuvirtual.cpp
@@ -1150,6 +1150,17 @@ VirtualGPU::submitMapMemory(amd::MapMemoryCommand& vcmd)
}
}
else {
+ // Validate if it's a view for a map of mip level
+ if (memory->isUnmapWrite() && (vcmd.memory().parent() != NULL)) {
+ amd::Image* amdImage = vcmd.memory().parent()->asImage();
+ if ((amdImage != NULL) && (amdImage->getMipLevels() > 1)) {
+ // Save map write info in the parent object
+ dev().getGpuMemory(amdImage)->saveMapInfo(
+ vcmd.origin(), vcmd.size(),
+ vcmd.mapFlags(), vcmd.isEntireMemory(),
+ vcmd.memory().asImage());
+ }
+ }
if (!blitMgr().copyImageToBuffer(*memory,
*memory->mapMemory(), vcmd.origin(), dstOrigin,
vcmd.size(), vcmd.isEntireMemory())) {
@@ -1175,6 +1186,20 @@ VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd)
profilingBegin(vcmd, true);
gpu::Memory* memory = dev().getGpuMemory(&vcmd.memory());
amd::Memory* owner = memory->owner();
+ bool unmapMip = false;
+
+ // Check if image is a mipmap and assign a saved view
+ amd::Image* amdImage = owner->asImage();
+ if ((amdImage != NULL) && (amdImage->getMipLevels() > 1) &&
+ memory->isUnmapWrite() &&
+ (memory->writeMapInfo()->baseMip_ != NULL)) {
+ // Clear unmap flags from the parent image
+ memory->clearUnmapFlags();
+ // Assign mip level view
+ amdImage = memory->writeMapInfo()->baseMip_;
+ memory = dev().getGpuMemory(amdImage);
+ unmapMip = true;
+ }
// We used host memory
if ((owner->getHostMem() != NULL) && memory->isDirectMap()) {
@@ -1249,6 +1274,11 @@ VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd)
}
}
}
+ else if ((amdImage != NULL) && (amdImage->getMipLevels() > 1) &&
+ (!memory->isUnmapWrite())) {
+ // Release a view for a mipmap map
+ amdImage->release();
+ }
else {
LogError("Unhandled unmap!");
vcmd.setStatus(CL_INVALID_VALUE);
@@ -1257,6 +1287,10 @@ VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd)
// Clear unmap flags
memory->clearUnmapFlags();
+ // Release a view for a mipmap map
+ if (unmapMip) {
+ amdImage->release();
+ }
profilingEnd(vcmd);
}
diff --git a/rocclr/runtime/device/hsa/hsadevice.cpp b/rocclr/runtime/device/hsa/hsadevice.cpp
index fc7443bc85..2b8a92fb08 100644
--- a/rocclr/runtime/device/hsa/hsadevice.cpp
+++ b/rocclr/runtime/device/hsa/hsadevice.cpp
@@ -680,26 +680,6 @@ Device::globalFreeMemory(size_t *freeMemory) const
return false;
}
-void*
-Device::allocMapTarget(
- amd::Memory& mem,
- const amd::Coord3D& origin,
- const amd::Coord3D& region,
- uint mapFlags,
- size_t* rowPitch,
- size_t* slicePitch)
-{
- // Translate memory references
- oclhsa::Memory* memory = getOclHsaMemory(&mem);
- if (memory == NULL) {
- LogError("allocMapTarget failed. Can't allocate video memory");
- return NULL;
- }
-
- // Pass request over to memory
- return memory->allocMapTarget(origin, region, mapFlags, rowPitch, slicePitch);
-}
-
bool
Device::bindExternalDevice(
intptr_t type,
diff --git a/rocclr/runtime/device/hsa/hsadevice.hpp b/rocclr/runtime/device/hsa/hsadevice.hpp
index 5cd55add6b..3b7c3cdbba 100644
--- a/rocclr/runtime/device/hsa/hsadevice.hpp
+++ b/rocclr/runtime/device/hsa/hsadevice.hpp
@@ -185,20 +185,6 @@ public:
return false;
}
- //! Gets a pointer to a region of host-visible memory for use as the target
- //! of a non-blocking map for a given memory object
- virtual void* allocMapTarget(
- amd::Memory& mem, //!< Abstraction layer memory object
- const amd::Coord3D& origin, //!< The map location in memory
- const amd::Coord3D& region, //!< The map region in memory
- uint mapFlags, //!< Map flags
- size_t* rowPitch = NULL, //!< Row pitch for the mapped memory
- size_t* slicePitch = NULL //!< Slice for the mapped memory
- ) {
- ShouldNotReachHere();
- return NULL;
- }
-
//! Releases non-blocking map target memory
virtual void freeMapTarget(amd::Memory& mem, void* target) { ShouldNotReachHere();}
@@ -318,17 +304,6 @@ public:
//!< pDevice/pContext, do not bind.
);
- //! Gets a pointer to a region of host-visible memory for use as the target
- //! of a non-blocking map for a given memory object
- virtual void *allocMapTarget(
- amd::Memory &mem, //!< Abstraction layer memory object
- const amd::Coord3D &origin, //!< The map location in memory
- const amd::Coord3D ®ion, //!< The map region in memory
- uint mapFlags, //!< Map flags
- size_t *rowPitch = NULL, //!< Row pitch for the mapped memory
- size_t *slicePitch = NULL //!< Slice for the mapped memory
- );
-
//! Gets free memory on a GPU device
virtual bool globalFreeMemory(size_t *freeMemory) const;
diff --git a/rocclr/runtime/platform/commandqueue.hpp b/rocclr/runtime/platform/commandqueue.hpp
index f558cfffdc..9df958e17e 100644
--- a/rocclr/runtime/platform/commandqueue.hpp
+++ b/rocclr/runtime/platform/commandqueue.hpp
@@ -156,7 +156,7 @@ class HostQueue : public CommandQueue
}
//! Get virtual device for the current thread
- const device::VirtualDevice* vdev() const { return virtualDevice_; }
+ device::VirtualDevice* vdev() const { return virtualDevice_; }
private:
device::VirtualDevice* virtualDevice_; //!< Virtual device for this thread
@@ -207,7 +207,7 @@ public:
void finish();
//! Get virtual device for the current command queue
- const device::VirtualDevice* vdev() const { return thread_.vdev(); }
+ device::VirtualDevice* vdev() const { return thread_.vdev(); }
//! Return the current queue as the HostQueue
virtual HostQueue* asHostQueue() { return this; }