From 70e590fa2adb4c04000c920eb89e11fa3ecc8431 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
---
opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp | 134 ++++++++++++------
.../khronos/headers/opencl2.0/CL/cl_ext.h | 4 +-
2 files changed, 97 insertions(+), 41 deletions(-)
diff --git a/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp b/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp
index 685d3c9820..ab2e6126cf 100644
--- a/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp
+++ b/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp
@@ -24,34 +24,6 @@ typedef wchar_t char_t;
namespace amd {
-class LiquidFlashFile : public RuntimeObject
-{
-private:
- const wchar_t* name_;
- cl_file_flags_amd flags_;
- void* handle_;
-
-public:
- LiquidFlashFile(const wchar_t* name, cl_file_flags_amd flags)
- : name_(name), flags_(flags), handle_(NULL) { }
-
- ~LiquidFlashFile();
-
- bool open();
- void close();
-
- size_t blockSize() const;
-
- size_t readBlocks(
- void* dst,
- uint32_t count,
- const uint64_t* file_offsets,
- const uint64_t* buffer_offsets,
- const uint64_t* sizes);
-
- virtual ObjectType objectType() const {return ObjectTypeLiquidFlashFile;}
-};
-
LiquidFlashFile::~LiquidFlashFile()
{
close();
@@ -71,11 +43,17 @@ LiquidFlashFile::open()
}
handle_ = lfOpenFile(name_, flags, &err);
- if (err == lf_success) {
- return true;
+ if (err != lf_success) {
+ return false;
}
-#endif // WITH_LIQUID_FLASH
+
+ if (lfGetFileBlockSize((lf_file)handle_, &blockSize_) != lf_success) {
+ return false;
+ }
+ return true;
+#else
return false;
+#endif // WITH_LIQUID_FLASH
}
void
@@ -89,18 +67,26 @@ LiquidFlashFile::close()
#endif // WITH_LIQUID_FLASH
}
-size_t
-LiquidFlashFile::blockSize() const
+bool
+LiquidFlashFile::readBlock(
+ void* dst,
+ uint64_t fileOffset,
+ uint64_t bufferOffset,
+ uint64_t size) const
{
#if defined WITH_LIQUID_FLASH
- if (handle_ != NULL) {
- lf_uint32 blockSize;
- if (lfGetFileBlockSize((lf_file)handle_, &blockSize) == lf_success) {
- return blockSize;
- }
+ lf_region_descriptor region =
+ { fileOffset / blockSize(), bufferOffset / blockSize(), size / blockSize() };
+ lf_status status = lfReadFile(dst, size, handle_, 1, ®ion, NULL);
+ if (lf_success == status) {
+ return true;
}
+ else {
+ return false;
+ }
+#else
+ return false;
#endif // WITH_LIQUID_FLASH
- return 0;
}
} // namesapce amd
@@ -171,7 +157,75 @@ RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
const cl_event *event_wait_list,
cl_event *event))
{
- return CL_INVALID_FILE_OBJECT_AMD;
+ if (!is_valid(command_queue)) {
+ return CL_INVALID_COMMAND_QUEUE;
+ }
+
+ if (!is_valid(buffer)) {
+ return CL_INVALID_MEM_OBJECT;
+ }
+ amd::Buffer* dstBuffer = as_amd(buffer)->asBuffer();
+ if (dstBuffer == NULL) {
+ return CL_INVALID_MEM_OBJECT;
+ }
+
+ if (dstBuffer->getMemFlags() &
+ (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) {
+ return CL_INVALID_OPERATION;
+ }
+
+ amd::HostQueue* queue = as_amd(command_queue)->asHostQueue();
+ if (NULL == queue) {
+ return CL_INVALID_COMMAND_QUEUE;
+ }
+ amd::HostQueue& hostQueue = *queue;
+
+ if(hostQueue.context() != dstBuffer->getContext()) {
+ return CL_INVALID_CONTEXT;
+ }
+
+ if (!is_valid(file)) {
+ return CL_INVALID_FILE_OBJECT_AMD;
+ }
+
+ amd::LiquidFlashFile* amdFile = as_amd(file);
+ amd::Coord3D dstOffset(buffer_offset, 0, 0);
+ amd::Coord3D dstSize(cb, 1, 1);
+
+ if(!dstBuffer->validateRegion(dstOffset, dstSize)) {
+ return CL_INVALID_VALUE;
+ }
+
+ amd::Command::EventWaitList eventWaitList;
+ cl_int err = amd::clSetEventWaitList(eventWaitList,
+ hostQueue.context(), num_events_in_wait_list, event_wait_list);
+ if (err != CL_SUCCESS){
+ return err;
+ }
+
+ amd::WriteBufferFromFileCommand *command = new amd::WriteBufferFromFileCommand(
+ hostQueue, eventWaitList,
+ *dstBuffer, dstOffset, dstSize, amdFile, file_offset);
+ if (command == NULL) {
+ return CL_OUT_OF_HOST_MEMORY;
+ }
+
+ // Make sure we have memory for the command execution
+ if (!command->validateMemory()) {
+ delete command;
+ return CL_MEM_OBJECT_ALLOCATION_FAILURE;
+ }
+
+ command->enqueue();
+ if (blocking_write) {
+ command->awaitCompletion();
+ }
+
+ *not_null(event) = as_cl(&command->event());
+ if (event == NULL) {
+ command->release();
+ }
+ return CL_SUCCESS;
}
RUNTIME_EXIT
diff --git a/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h b/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h
index 8abf84b357..5b117e2b5a 100644
--- a/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h
+++ b/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h
@@ -456,7 +456,9 @@ typedef CL_API_ENTRY cl_int
***********************/
#define cl_amd_liquid_flash 1
-#define CL_INVALID_FILE_OBJECT_AMD 0x404D
+#define CL_COMMAND_WRITE_BUFFER_FROM_FILE_AMD 0x4083
+
+#define CL_INVALID_FILE_OBJECT_AMD 0x4084
typedef struct _cl_file_amd * cl_file_amd;