P4 to Git Change 1781985 by gandryey@gera-win10 on 2019/05/13 11:54:40
SWDEV-189140 - Add P2P support in PAL path - PAL requires P2P resource open on the usage device. Add the new interface to open the resource - Add a hidden P2P device object creation into amd::Memory. It can be activated with OCL context that has a single device. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_p2p_amd.cpp#2 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#337 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#134 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palmemory.cpp#25 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#74 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.hpp#28 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palsettings.cpp#80 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palsettings.hpp#23 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#133 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#126 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#93 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#136 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#109 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.hpp#306 edit
This commit is contained in:
@@ -552,7 +552,14 @@ bool CopyMemoryP2PCommand::validateMemory() {
|
||||
LogPrintfError("Can't allocate memory size - 0x%08X bytes!", memory2_->getSize());
|
||||
return false;
|
||||
}
|
||||
if (devices[0]->P2PStage() != nullptr) {
|
||||
bool p2pStaging = false;
|
||||
// Validate P2P memories on the current device, if any of them is null, then it's p2p staging
|
||||
if ((nullptr == memory1_->getDeviceMemory(queue()->device())) ||
|
||||
(nullptr == memory2_->getDeviceMemory(queue()->device()))) {
|
||||
p2pStaging = true;
|
||||
}
|
||||
|
||||
if (devices[0]->P2PStage() != nullptr && p2pStaging) {
|
||||
amd::ScopedLock lock(devices[0]->P2PStageOps());
|
||||
// Make sure runtime allocates memory on every device
|
||||
for (uint d = 0; d < devices[0]->GlbCtx().devices().size(); ++d) {
|
||||
|
||||
@@ -70,14 +70,14 @@ Memory::Memory(Context& context, Type type, Flags flags, size_t size, void* svmP
|
||||
version_(0),
|
||||
lastWriter_(NULL),
|
||||
interopObj_(NULL),
|
||||
isParent_(false),
|
||||
vDev_(NULL),
|
||||
forceSysMemAlloc_(false),
|
||||
mapCount_(0),
|
||||
svmHostAddress_(svmPtr),
|
||||
svmPtrCommited_(flags & CL_MEM_SVM_FINE_GRAIN_BUFFER ? true : false),
|
||||
canBeCached_(true),
|
||||
lockMemoryOps_("Memory Ops Lock", true) {}
|
||||
flagsEx_(0),
|
||||
lockMemoryOps_("Memory Ops Lock", true) {
|
||||
svmPtrCommited_ = (flags & CL_MEM_SVM_FINE_GRAIN_BUFFER) ? true : false;
|
||||
canBeCached_ = true;
|
||||
}
|
||||
|
||||
Memory::Memory(Memory& parent, Flags flags, size_t origin, size_t size, Type type)
|
||||
: numDevices_(0),
|
||||
@@ -93,14 +93,13 @@ Memory::Memory(Memory& parent, Flags flags, size_t origin, size_t size, Type typ
|
||||
version_(parent.getVersion()),
|
||||
lastWriter_(parent.getLastWriter()),
|
||||
interopObj_(parent.getInteropObj()),
|
||||
isParent_(false),
|
||||
vDev_(NULL),
|
||||
forceSysMemAlloc_(false),
|
||||
mapCount_(0),
|
||||
svmHostAddress_(parent.getSvmPtr()),
|
||||
svmPtrCommited_(parent.isSvmPtrCommited()),
|
||||
canBeCached_(true),
|
||||
flagsEx_(0),
|
||||
lockMemoryOps_("Memory Ops Lock", true) {
|
||||
svmPtrCommited_ = parent.isSvmPtrCommited();
|
||||
canBeCached_ = true;
|
||||
parent_->retain();
|
||||
parent_->isParent_ = true;
|
||||
|
||||
@@ -126,13 +125,31 @@ Memory::Memory(Memory& parent, Flags flags, size_t origin, size_t size, Type typ
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Memory::NumDevicesWithP2P() {
|
||||
uint32_t devices = context_().devices().size();
|
||||
if (devices == 1) {
|
||||
// Add p2p devices for allocation
|
||||
devices = context_().devices().size() + context_().devices()[0]->P2PAccessDevices().size();
|
||||
if (devices > 1) {
|
||||
p2pAccess_ = true;
|
||||
}
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
void Memory::initDeviceMemory() {
|
||||
deviceMemories_ = reinterpret_cast<DeviceMemory*>(reinterpret_cast<char*>(this) + sizeof(Memory));
|
||||
memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory));
|
||||
memset(deviceMemories_, 0, NumDevicesWithP2P() * sizeof(DeviceMemory));
|
||||
}
|
||||
|
||||
void* Memory::operator new(size_t size, const Context& context) {
|
||||
return RuntimeObject::operator new(size + context.devices().size() * sizeof(DeviceMemory));
|
||||
uint32_t devices = context.devices().size();
|
||||
if (devices == 1) {
|
||||
// Add p2p devices for allocation
|
||||
devices = context.devices().size() + context.devices()[0]->P2PAccessDevices().size();
|
||||
}
|
||||
|
||||
return RuntimeObject::operator new(size + devices * sizeof(DeviceMemory));
|
||||
}
|
||||
|
||||
void Memory::operator delete(void* p) { RuntimeObject::operator delete(p); }
|
||||
@@ -259,7 +276,14 @@ bool Memory::addDeviceMemory(const Device* dev) {
|
||||
bool result = false;
|
||||
AllocState create = AllocCreate;
|
||||
AllocState init = AllocInit;
|
||||
|
||||
if (make_atomic(deviceAlloced_[dev]).compareAndSet(init, create)) {
|
||||
// Check if runtime already allocated all available slots for device memory
|
||||
if (numDevices() == NumDevicesWithP2P()) {
|
||||
// Mark the allocation as an empty
|
||||
deviceAlloced_[dev] = AllocInit;
|
||||
return false;
|
||||
}
|
||||
device::Memory* dm = dev->createMemory(*this);
|
||||
|
||||
// Add the new memory allocation to the device map
|
||||
@@ -267,7 +291,7 @@ bool Memory::addDeviceMemory(const Device* dev) {
|
||||
deviceMemories_[numDevices_].ref_ = dev;
|
||||
deviceMemories_[numDevices_].value_ = dm;
|
||||
numDevices_++;
|
||||
assert((numDevices() <= context_().devices().size()) && "Too many device objects");
|
||||
assert((numDevices() <= NumDevicesWithP2P()) && "Too many device objects");
|
||||
|
||||
// Mark the allocation with the complete flag
|
||||
deviceAlloced_[dev] = AllocComplete;
|
||||
@@ -275,6 +299,7 @@ bool Memory::addDeviceMemory(const Device* dev) {
|
||||
svmBase_ = dm;
|
||||
}
|
||||
} else {
|
||||
LogError("Video memory allocation failed!");
|
||||
// Mark the allocation as an empty
|
||||
deviceAlloced_[dev] = AllocInit;
|
||||
}
|
||||
@@ -322,7 +347,6 @@ device::Memory* Memory::getDeviceMemory(const Device& dev, bool alloc) {
|
||||
|
||||
if ((NULL == dm) && alloc) {
|
||||
if (!addDeviceMemory(&dev)) {
|
||||
LogError("Video memory allocation failed!");
|
||||
return NULL;
|
||||
}
|
||||
dm = deviceMemories_[numDevices() - 1].value_;
|
||||
@@ -446,7 +470,7 @@ void Memory::uncommitSvmMemory() {
|
||||
|
||||
void Buffer::initDeviceMemory() {
|
||||
deviceMemories_ = reinterpret_cast<DeviceMemory*>(reinterpret_cast<char*>(this) + sizeof(Buffer));
|
||||
memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory));
|
||||
memset(deviceMemories_, 0, NumDevicesWithP2P() * sizeof(DeviceMemory));
|
||||
}
|
||||
|
||||
bool Buffer::create(void* initFrom, bool sysMemAlloc, bool skipAlloc) {
|
||||
@@ -472,7 +496,7 @@ bool Buffer::validateRegion(const Coord3D& origin, const Coord3D& region) const
|
||||
|
||||
void Pipe::initDeviceMemory() {
|
||||
deviceMemories_ = reinterpret_cast<DeviceMemory*>(reinterpret_cast<char*>(this) + sizeof(Pipe));
|
||||
memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory));
|
||||
memset(deviceMemories_, 0, NumDevicesWithP2P() * sizeof(DeviceMemory));
|
||||
}
|
||||
|
||||
#define GETMIPDIM(dim, mip) (((dim >> mip) > 0) ? (dim >> mip) : 1)
|
||||
@@ -631,7 +655,7 @@ void Image::initDimension() {
|
||||
|
||||
void Image::initDeviceMemory() {
|
||||
deviceMemories_ = reinterpret_cast<DeviceMemory*>(reinterpret_cast<char*>(this) + sizeof(Image));
|
||||
memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory));
|
||||
memset(deviceMemories_, 0, NumDevicesWithP2P() * sizeof(DeviceMemory));
|
||||
}
|
||||
bool Image::create(void* initFrom) { return Memory::create(initFrom); }
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace device {
|
||||
class Memory;
|
||||
class VirtualDevice;
|
||||
}
|
||||
} // namespace device
|
||||
|
||||
namespace amd {
|
||||
|
||||
@@ -42,7 +42,7 @@ struct BufferRect : public amd::EmbeddedObject {
|
||||
const size_t* region, //!< Copy region
|
||||
size_t bufferRowPitch, //!< Provided buffer's row pitch
|
||||
size_t bufferSlicePitch //!< Provided buffer's slice pitch
|
||||
);
|
||||
);
|
||||
|
||||
//! Returns the plain offset for the (X, Y, Z) location
|
||||
size_t offset(size_t x, //!< Coordinate in X dimension
|
||||
@@ -120,6 +120,9 @@ class Memory : public amd::RuntimeObject {
|
||||
typedef cl_mem_flags Flags;
|
||||
typedef DeviceMap<const Device*, device::Memory*> DeviceMemory;
|
||||
|
||||
//! Returns the number of devices this memory object is associated, including P2P access
|
||||
uint32_t NumDevicesWithP2P();
|
||||
|
||||
size_t numDevices_; //!< Number of devices
|
||||
|
||||
//! The device memory objects included in this memory
|
||||
@@ -141,13 +144,19 @@ class Memory : public amd::RuntimeObject {
|
||||
size_t version_; //!< Update count, used for coherency
|
||||
const Device* lastWriter_; //!< Which device wrote most recently (NULL if host)
|
||||
InteropObject* interopObj_; //!< Interop object
|
||||
bool isParent_; //!< This object is a parent
|
||||
device::VirtualDevice* vDev_; //!< Memory object belongs to a virtual device only
|
||||
bool forceSysMemAlloc_; //!< Forces system memory allocation
|
||||
std::atomic_uint mapCount_; //!< Keep track of number of mappings for a memory object
|
||||
void* svmHostAddress_; //!< svm host address;
|
||||
bool svmPtrCommited_; //!< svm host address committed flag;
|
||||
bool canBeCached_; //!< flag to if the object can be cached;
|
||||
union {
|
||||
struct {
|
||||
uint32_t isParent_ : 1; //!< This object is a parent
|
||||
uint32_t forceSysMemAlloc_ : 1; //!< Forces system memory allocation
|
||||
uint32_t svmPtrCommited_ : 1; //!< svm host address committed flag
|
||||
uint32_t canBeCached_ : 1; //!< flag to if the object can be cached
|
||||
uint32_t p2pAccess_ : 1; //!< Memory object allows P2P access
|
||||
};
|
||||
uint32_t flagsEx_;
|
||||
};
|
||||
|
||||
private:
|
||||
//! Disable default assignment operator
|
||||
@@ -168,20 +177,20 @@ class Memory : public amd::RuntimeObject {
|
||||
Flags flags, //!< Object's flags
|
||||
size_t size, //!< Memory size
|
||||
void* svmPtr = NULL //!< svm host memory address, NULL if no SVM mem object
|
||||
);
|
||||
);
|
||||
Memory(Memory& parent, //!< Context object
|
||||
Flags flags, //!< Object's flags
|
||||
size_t offset, //!< Memory offset
|
||||
size_t size, //!< Memory size
|
||||
Type type = 0 //!< Memory type
|
||||
);
|
||||
);
|
||||
|
||||
//! Memory object destructor
|
||||
virtual ~Memory();
|
||||
|
||||
//! Copies initialization data to the backing store
|
||||
virtual void copyToBackingStore(void* initFrom //!< Pointer to the initialization memory
|
||||
);
|
||||
);
|
||||
|
||||
//! Initializes the device memory array
|
||||
virtual void initDeviceMemory();
|
||||
@@ -193,14 +202,14 @@ class Memory : public amd::RuntimeObject {
|
||||
//! Placement new operator.
|
||||
void* operator new(size_t size, //!< Original allocation size
|
||||
const Context& context //!< Context this memory object is allocated in.
|
||||
);
|
||||
);
|
||||
// Provide a "matching" placement delete operator.
|
||||
void operator delete(void*, //!< Pointer to deallocate
|
||||
const Context& context //!< Context this memory object is allocated in.
|
||||
);
|
||||
);
|
||||
// and a regular delete operator to satisfy synthesized methods.
|
||||
void operator delete(void* //!< Pointer to deallocate
|
||||
);
|
||||
);
|
||||
|
||||
//! Returns the memory lock object
|
||||
amd::Monitor& lockMemoryOps() { return lockMemoryOps_; }
|
||||
@@ -228,32 +237,32 @@ class Memory : public amd::RuntimeObject {
|
||||
virtual Pipe* asPipe() { return NULL; }
|
||||
|
||||
//! Creates and initializes device (cache) memory for all devices
|
||||
virtual bool create(void* initFrom = NULL, //!< Pointer to the initialization data
|
||||
bool sysMemAlloc = false, //!< Allocate device memory in system memory
|
||||
bool skipAlloc = false //!< Skip device memory allocation
|
||||
);
|
||||
virtual bool create(void* initFrom = NULL, //!< Pointer to the initialization data
|
||||
bool sysMemAlloc = false, //!< Allocate device memory in system memory
|
||||
bool skipAlloc = false //!< Skip device memory allocation
|
||||
);
|
||||
|
||||
//! Allocates device (cache) memory for a specific device
|
||||
bool addDeviceMemory(const Device* dev //!< Device object
|
||||
);
|
||||
);
|
||||
|
||||
//! Replaces device (cache) memory for a specific device
|
||||
void replaceDeviceMemory(const Device* dev, //!< Device object
|
||||
device::Memory* dm //!< New device memory object for replacement
|
||||
);
|
||||
);
|
||||
|
||||
//! Find the section for the given device. Return NULL if not found.
|
||||
device::Memory* getDeviceMemory(const Device& dev, //!< Device object
|
||||
bool alloc = true //!< Allocates memory
|
||||
);
|
||||
);
|
||||
|
||||
//! Allocate host memory (as required)
|
||||
bool allocHostMemory(void* initFrom, //!< Host memory provided by the application
|
||||
bool allocHostMem, //!< Force system memory allocation
|
||||
bool forceCopy = false //!< Force system memory allocation
|
||||
);
|
||||
);
|
||||
|
||||
virtual void IpcCreate (size_t offset, size_t* mem_size, void* handle) const {
|
||||
virtual void IpcCreate(size_t offset, size_t* mem_size, void* handle) const {
|
||||
ShouldNotReachHere();
|
||||
}
|
||||
|
||||
@@ -314,8 +323,14 @@ class Memory : public amd::RuntimeObject {
|
||||
void uncommitSvmMemory();
|
||||
void setCacheStatus(bool canBeCached) {
|
||||
canBeCached_ = canBeCached;
|
||||
} //!< set the memobject cached status;
|
||||
bool canBeCached() const { return canBeCached_; } //!< get the memobject cached status;
|
||||
} //!< set the memobject cached status
|
||||
bool canBeCached() const { return canBeCached_; } //!< get the memobject cached status
|
||||
|
||||
//! Check if this objects allows P2P access
|
||||
bool P2PAccess() const { return p2pAccess_; }
|
||||
|
||||
//! Returns the base device memory object for possible P2P access
|
||||
device::Memory* BaseP2PMemory() const { return deviceMemories_[0].value_; }
|
||||
device::Memory* svmBase() const { return svmBase_; } //!< Returns SVM base for MGPU case
|
||||
};
|
||||
|
||||
@@ -339,10 +354,10 @@ class Buffer : public Memory {
|
||||
Buffer(Memory& parent, Flags flags, size_t origin, size_t size)
|
||||
: Memory(parent, flags, origin, size) {}
|
||||
|
||||
bool create(void* initFrom = NULL, //!< Pointer to the initialization data
|
||||
bool sysMemAlloc = false, //!< Allocate device memory in system memory
|
||||
bool skipAlloc = false //!< Skip device memory allocation
|
||||
);
|
||||
bool create(void* initFrom = NULL, //!< Pointer to the initialization data
|
||||
bool sysMemAlloc = false, //!< Allocate device memory in system memory
|
||||
bool skipAlloc = false //!< Skip device memory allocation
|
||||
);
|
||||
|
||||
//! static_cast to Buffer with sanity check
|
||||
virtual Buffer* asBuffer() { return this; }
|
||||
@@ -463,7 +478,7 @@ class Image : public Memory {
|
||||
|
||||
//! Copies initialization data to the backing store
|
||||
virtual void copyToBackingStore(void* initFrom //!< Pointer to the initialization memory
|
||||
);
|
||||
);
|
||||
|
||||
void initDimension();
|
||||
|
||||
@@ -482,7 +497,7 @@ class Image : public Memory {
|
||||
size_t height, //!< Image height
|
||||
size_t depth, //!< Image depth
|
||||
size_t arraySize //!< Image array size
|
||||
);
|
||||
);
|
||||
|
||||
const Format& getImageFormat() const { return impl_.format_; }
|
||||
|
||||
@@ -512,7 +527,7 @@ class Image : public Memory {
|
||||
device::VirtualDevice* vDev, //!< Virtual device object
|
||||
uint baseMipLevel = 0, //!< Base mip level for a view
|
||||
cl_mem_flags flags = 0 //!< Memory allocation flags
|
||||
);
|
||||
);
|
||||
|
||||
//! Returns the impl for this image.
|
||||
Impl& getImpl() { return impl_; }
|
||||
@@ -554,7 +569,7 @@ class Image : public Memory {
|
||||
|
||||
//! Creates and initializes device (cache) memory for all devices
|
||||
bool create(void* initFrom = NULL //!< Pointer to the initialization data
|
||||
);
|
||||
);
|
||||
};
|
||||
|
||||
//! SVM-related functionality.
|
||||
|
||||
Reference in New Issue
Block a user