From 3b942d7e0e4e62d945ce55b4818d478dd0b6b2bd Mon Sep 17 00:00:00 2001 From: foreman Date: Wed, 28 Oct 2015 17:25:52 -0400 Subject: [PATCH] P4 to Git Change 1205056 by gandryey@gera-w8 on 2015/10/28 17:13:54 SWDEV-78467 - OpenCL LiquidFlash feature - Add WriteBufferFromFile command Affected files ... ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp#8 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h#21 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#189 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#259 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpusettings.cpp#333 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#72 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#79 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#93 edit ... //depot/stg/opencl/drivers/opencl/runtime/runtimedefs#35 edit [ROCm/clr commit: 715cbfd662f5a74c890d4624e881d2efa12f01c1] --- projects/clr/rocclr/runtime/device/device.hpp | 8 ++- .../rocclr/runtime/device/gpu/gpusettings.cpp | 9 ++-- .../clr/rocclr/runtime/platform/command.cpp | 35 ++++++++++-- .../clr/rocclr/runtime/platform/command.hpp | 53 +++++++++++++++++-- .../clr/rocclr/runtime/platform/memory.hpp | 29 ++++++++++ 5 files changed, 120 insertions(+), 14 deletions(-) diff --git a/projects/clr/rocclr/runtime/device/device.hpp b/projects/clr/rocclr/runtime/device/device.hpp index c43c9b8c92..d5df880689 100644 --- a/projects/clr/rocclr/runtime/device/device.hpp +++ b/projects/clr/rocclr/runtime/device/device.hpp @@ -58,6 +58,7 @@ class SvmCopyMemoryCommand; class SvmFillMemoryCommand; class SvmMapMemoryCommand; class SvmUnmapMemoryCommand; +class WriteBufferFromFileCommand; class HwDebugManager; class Device; struct KernelParameterDescriptor; @@ -111,6 +112,7 @@ enum OclExtensions { ClKhrMipMapImage, ClKhrMipMapImageWrites, ClKhrIlProgram, + ClAMDLiquidFlash, ClExtTotal }; @@ -153,6 +155,7 @@ OclExtensionsString[] = { "cl_khr_mipmap_image ", "cl_khr_mipmap_image_writes ", "", + (IS_MAINLINE || IS_LINUX) ? "" : "cl_amd_liquid_flash ", NULL }; @@ -1410,13 +1413,14 @@ public: virtual void submitThreadTraceMemObjects(amd::ThreadTraceMemObjectsCommand& cmd) = 0; virtual void submitThreadTrace(amd::ThreadTraceCommand& cmd) = 0; virtual void flush(amd::Command* list = NULL, bool wait = false) = 0; - virtual void submitSignal(amd::SignalCommand & cmd) = 0; - virtual void submitMakeBuffersResident(amd::MakeBuffersResidentCommand & cmd) = 0; virtual void submitSvmFreeMemory(amd::SvmFreeMemoryCommand& cmd) = 0; virtual void submitSvmCopyMemory(amd::SvmCopyMemoryCommand& cmd) = 0; virtual void submitSvmFillMemory(amd::SvmFillMemoryCommand& cmd) = 0; virtual void submitSvmMapMemory(amd::SvmMapMemoryCommand& cmd) = 0; virtual void submitSvmUnmapMemory(amd::SvmUnmapMemoryCommand& cmd) = 0; + /// Optional extensions + virtual void submitSignal(amd::SignalCommand & cmd) = 0; + virtual void submitMakeBuffersResident(amd::MakeBuffersResidentCommand & cmd) = 0; //! Get the blit manager object device::BlitManager& blitMgr() const { return *blitMgr_; } diff --git a/projects/clr/rocclr/runtime/device/gpu/gpusettings.cpp b/projects/clr/rocclr/runtime/device/gpu/gpusettings.cpp index 6182f358e1..dd0b1916ef 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpusettings.cpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpusettings.cpp @@ -337,6 +337,10 @@ Settings::create( enableExtension(ClAmdVec3); enableExtension(ClAmdPrintf); enableExtension(ClExtAtomicCounters32); + // Enable some platform extensions + enableExtension(ClAmdDeviceAttributeQuery); + enableExtension(ClKhrSpir); + enableExtension(ClAMDLiquidFlash); hwLDSSize_ = 32 * Ki; @@ -380,11 +384,6 @@ Settings::create( svmAtomics_ = (calAttr.svmAtomics || calAttr.isSVMFineGrainSystem) ? true : false; - // Enable some platform extensions - enableExtension(ClAmdDeviceAttributeQuery); - - enableExtension(ClKhrSpir); - // SVM is not currently supported for DX Interop if (!svmFineGrainSystem_) { #if defined(_WIN32) diff --git a/projects/clr/rocclr/runtime/platform/command.cpp b/projects/clr/rocclr/runtime/platform/command.cpp index 4cd2497c06..217b46ea69 100644 --- a/projects/clr/rocclr/runtime/platform/command.cpp +++ b/projects/clr/rocclr/runtime/platform/command.cpp @@ -217,10 +217,6 @@ Command::Command( std::mem_fun(&Command::retain)); } -Command::~Command() -{ -} - void Command::releaseResources() { @@ -577,4 +573,35 @@ ThreadTraceMemObjectsCommand::validateMemory() return true; } +void +WriteBufferFromFileCommand::submit(device::VirtualDevice& device) +{ + device::Memory* mem = memory_->getDeviceMemory(queue()->device()); + void* dstBuffer = mem->cpuMap(device); + // Make HD transfer to the host accessible memory + if (!file()->readBlock(dstBuffer, fileOffset(), origin()[0], size()[0])) { + return; + } + mem->cpuUnmap(device); +} + +bool +WriteBufferFromFileCommand::validateMemory() +{ + if (!(memory_->getMemFlags() & (CL_MEM_USE_HOST_PTR | + CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_PERSISTENT_MEM_AMD))) { + return false; + } + + if (queue()->device().info().type_ & CL_DEVICE_TYPE_GPU) { + device::Memory* mem = memory_->getDeviceMemory(queue()->device()); + if (NULL == mem) { + LogPrintfError("Can't allocate memory size - 0x%08X bytes!", + memory_->getSize()); + return false; + } + } + return true; +} + } // namespace amd diff --git a/projects/clr/rocclr/runtime/platform/command.hpp b/projects/clr/rocclr/runtime/platform/command.hpp index a33d8acf9b..4e9a6bd0ef 100644 --- a/projects/clr/rocclr/runtime/platform/command.hpp +++ b/projects/clr/rocclr/runtime/platform/command.hpp @@ -223,9 +223,6 @@ protected: exception_(0), data_(NULL), eventWaitList_(nullWaitList) { } - //! Destroy the command object. - virtual ~Command(); - bool terminate() { if (Agent::shouldPostEventEvents() && type() != 0) { Agent::postEventFree(as_cl(static_cast(this))); @@ -1472,6 +1469,56 @@ public: Memory* getSvmMem() const {return svmMem_;} }; +/*! \brief A generic write memory from file command. + * + * \details Currently supports buffers only. Buffers + * are treated as 1D structures so origin_[0] and size_[0] + * are equivalent to offset_ and count_ respectively. + */ +class WriteBufferFromFileCommand : public OneMemoryArgCommand +{ +private: + const Coord3D origin_; //!< Origin of the region to write to + const Coord3D size_; //!< Size of the region to write to + LiquidFlashFile* file_; //!< The file object for data read + size_t fileOffset_; //!< Offset in the file for data read + +public: + WriteBufferFromFileCommand( + HostQueue& queue, + const EventWaitList& eventWaitList, + Memory& memory, const Coord3D& origin, + const Coord3D& size, LiquidFlashFile* file, size_t fileOffset) + : OneMemoryArgCommand(queue, CL_COMMAND_WRITE_BUFFER_FROM_FILE_AMD, + eventWaitList, memory) + , origin_(origin) + , size_(size) + , file_(file) + , fileOffset_(fileOffset) + { + // Sanity checks + assert(size.c[0] > 0 && "invalid"); + } + + virtual void submit(device::VirtualDevice& device); + + //! Return the memory object to write to + Memory& memory() const { return *memory_; } + + //! Return the host memory to read from + LiquidFlashFile* file() const { return file_; } + + //! Returns file offset + size_t fileOffset() const { return fileOffset_; } + + //! Return the region origin + const Coord3D& origin() const { return origin_; } + //! Return the region size + const Coord3D& size() const { return size_; } + + bool validateMemory(); +}; + /*! @} * @} */ diff --git a/projects/clr/rocclr/runtime/platform/memory.hpp b/projects/clr/rocclr/runtime/platform/memory.hpp index 441b9d0039..62bbd67a4d 100644 --- a/projects/clr/rocclr/runtime/platform/memory.hpp +++ b/projects/clr/rocclr/runtime/platform/memory.hpp @@ -12,6 +12,7 @@ #include "platform/object.hpp" #include "platform/interop.hpp" #include "device/device.hpp" +#include "lf.h" #include #include @@ -671,6 +672,34 @@ private: static Monitor AllocatedLock_; }; +//! Liquid flash extension +class LiquidFlashFile : public RuntimeObject +{ +private: + const wchar_t* name_; + cl_file_flags_amd flags_; + lf_file handle_; + uint32_t blockSize_; + +public: + LiquidFlashFile(const wchar_t* name, cl_file_flags_amd flags) + : name_(name), flags_(flags), handle_(NULL) { } + + ~LiquidFlashFile(); + + bool open(); + void close(); + + uint32_t blockSize() const { return blockSize_; }; + + bool readBlock( + void* dst, + uint64_t fileOffset, + uint64_t bufferOffset, + uint64_t size) const; + + virtual ObjectType objectType() const { return ObjectTypeLiquidFlashFile; } +}; } // namespace amd #endif // MEMORY_H_