From 25c8e12f862c79cf429dd66d188d4146324a4f8f Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 23 Feb 2016 07:57:16 -0500
Subject: [PATCH] P4 to Git Change 1239589 by mtomarov@stg-ocl-mtomarov on
2016/02/23 07:47:15
SWDEV-76870 - Add write feature to AMD extension (Merging //depot/rel/r6/15.30.1023/stream/opencl/... to //depot/stg/opencl/drivers/opencl/...)
Add clEnqueueReadBufferToFileAMD function to AMD extension (added declaration in cl_context.cpp)
1. Added clEnqueueReadBufferToFileAMD_fn function declaration to cl_ext.h
2. Added LiquidFlashFile::writeBlock method who implements transfer from GPU to SSD. In order to avoid code duplication LiquidFlashFile::readBlock and LiquidFlashFile::writeBlock is called from new method LiquidFlashFile::transferBlock (changes in cl_lqdflash_amd.cpp)
3. clEnqueueWriteBufferFromFileAMD and clEnqueueWriteBufferFromFileAMD call internal function EnqueueTransferBufferFromFileAMD who makes the same preparations as clEnqueueWriteBufferFromFileAMD in the prvious release
4. WriteBufferFromFileCommand class is renamed to TransferBufferFromFileCommand and new class makes the same preparation except assigning transfer direction (read or write)
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#48 integrate
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp#13 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_lqdflash_amd.h#4 integrate
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h#24 integrate
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#267 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#396 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#138 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#74 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#81 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#96 edit
---
opencl/api/opencl/amdocl/cl_context.cpp | 1 +
opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp | 96 +++++++++++++++----
opencl/api/opencl/amdocl/cl_lqdflash_amd.h | 13 +++
.../khronos/headers/opencl2.0/CL/cl_ext.h | 85 +++++++++-------
4 files changed, 143 insertions(+), 52 deletions(-)
diff --git a/opencl/api/opencl/amdocl/cl_context.cpp b/opencl/api/opencl/amdocl/cl_context.cpp
index 6c76007cb4..a3ac326896 100644
--- a/opencl/api/opencl/amdocl/cl_context.cpp
+++ b/opencl/api/opencl/amdocl/cl_context.cpp
@@ -537,6 +537,7 @@ clGetExtensionFunctionAddress(const char* func_name)
CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueMakeBuffersResidentAMD);
#if cl_amd_liquid_flash && !defined(OPENCL_MAINLINE)
CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueWriteBufferFromFileAMD);
+ CL_EXTENSION_ENTRYPOINT_CHECK(clEnqueueReadBufferToFileAMD);
#endif // cl_amd_liquid_flash
break;
case 'G':
diff --git a/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp b/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp
index e6f6540160..aeccfdba8f 100644
--- a/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp
+++ b/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp
@@ -72,16 +72,24 @@ LiquidFlashFile::close()
}
bool
-LiquidFlashFile::readBlock(
- void* dst,
+LiquidFlashFile::transferBlock(
+ bool writeBuffer,
+ void* srcDst,
uint64_t fileOffset,
uint64_t bufferOffset,
uint64_t size) const
{
#if defined WITH_LIQUID_FLASH
+ lf_status status;
+
lf_region_descriptor region =
{ fileOffset / blockSize(), bufferOffset / blockSize(), size / blockSize() };
- lf_status status = lfReadFile(dst, size, (lf_file)handle_, 1, ®ion, NULL);
+ if (writeBuffer) {
+ status = lfReadFile(srcDst, size, (lf_file)handle_, 1, ®ion, NULL);
+ }
+ else {
+ status = lfWriteFile(srcDst, size, (lf_file)handle_, 1, ®ion, NULL);
+ }
if (lf_success == status) {
return true;
}
@@ -93,7 +101,7 @@ LiquidFlashFile::readBlock(
#endif // WITH_LIQUID_FLASH
}
-} // namesapce amd
+} // namespace amd
/*! \addtogroup API
* @{
@@ -179,7 +187,8 @@ RUNTIME_ENTRY(cl_int, clReleaseFileObjectAMD, (
}
RUNTIME_EXIT
-RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
+cl_int EnqueueTransferBufferFromFileAMD(
+ cl_bool isWrite,
cl_command_queue command_queue,
cl_mem buffer,
cl_bool blocking_write,
@@ -189,7 +198,7 @@ RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
size_t file_offset,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
- cl_event *event))
+ cl_event *event)
{
if (!is_valid(command_queue)) {
return CL_INVALID_COMMAND_QUEUE;
@@ -198,12 +207,12 @@ RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
if (!is_valid(buffer)) {
return CL_INVALID_MEM_OBJECT;
}
- amd::Buffer* dstBuffer = as_amd(buffer)->asBuffer();
- if (dstBuffer == NULL) {
+ amd::Buffer* pBuffer = as_amd(buffer)->asBuffer();
+ if (pBuffer == NULL) {
return CL_INVALID_MEM_OBJECT;
}
- if (dstBuffer->getMemFlags() &
+ if (pBuffer->getMemFlags() &
(CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) {
return CL_INVALID_OPERATION;
}
@@ -214,7 +223,7 @@ RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
}
amd::HostQueue& hostQueue = *queue;
- if(hostQueue.context() != dstBuffer->getContext()) {
+ if(hostQueue.context() != pBuffer->getContext()) {
return CL_INVALID_CONTEXT;
}
@@ -223,10 +232,10 @@ RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
}
amd::LiquidFlashFile* amdFile = as_amd(file);
- amd::Coord3D dstOffset(buffer_offset, 0, 0);
- amd::Coord3D dstSize(cb, 1, 1);
+ amd::Coord3D bufferOffset(buffer_offset, 0, 0);
+ amd::Coord3D bufferSize(cb, 1, 1);
- if ((!dstBuffer->validateRegion(dstOffset, dstSize)) ||
+ if ((!pBuffer->validateRegion(bufferOffset, bufferSize)) ||
// LF library supports aligned sizes only
((buffer_offset % amdFile->blockSize()) != 0) ||
((cb % amdFile->blockSize()) != 0) ||
@@ -241,9 +250,14 @@ RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
return err;
}
- amd::WriteBufferFromFileCommand *command = new amd::WriteBufferFromFileCommand(
- hostQueue, eventWaitList,
- *dstBuffer, dstOffset, dstSize, amdFile, file_offset);
+ amd::TransferBufferFileCommand *command;
+ command = new amd::TransferBufferFileCommand((isWrite
+ ? CL_COMMAND_WRITE_BUFFER_FROM_FILE_AMD
+ : CL_COMMAND_READ_BUFFER_FROM_FILE_AMD),
+ hostQueue, eventWaitList,
+ *pBuffer, bufferOffset, bufferSize,
+ amdFile, file_offset);
+
if (command == NULL) {
return CL_OUT_OF_HOST_MEMORY;
}
@@ -265,5 +279,55 @@ RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
}
return CL_SUCCESS;
}
+
+RUNTIME_ENTRY(cl_int, clEnqueueWriteBufferFromFileAMD, (
+ cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_write,
+ size_t buffer_offset,
+ size_t cb,
+ cl_file_amd file,
+ size_t file_offset,
+ cl_uint num_events_in_wait_list,
+ const cl_event *event_wait_list,
+ cl_event *event))
+{
+ return EnqueueTransferBufferFromFileAMD(CL_TRUE,
+ command_queue,
+ buffer,
+ blocking_write,
+ buffer_offset,
+ cb,
+ file,
+ file_offset,
+ num_events_in_wait_list,
+ event_wait_list,
+ event);
+}
RUNTIME_EXIT
+RUNTIME_ENTRY(cl_int, clEnqueueReadBufferToFileAMD, (
+ cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_write,
+ size_t buffer_offset,
+ size_t cb,
+ cl_file_amd file,
+ size_t file_offset,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event))
+{
+ return EnqueueTransferBufferFromFileAMD(CL_FALSE,
+ command_queue,
+ buffer,
+ blocking_write,
+ buffer_offset,
+ cb,
+ file,
+ file_offset,
+ num_events_in_wait_list,
+ event_wait_list,
+ event);
+}
+RUNTIME_EXIT
diff --git a/opencl/api/opencl/amdocl/cl_lqdflash_amd.h b/opencl/api/opencl/amdocl/cl_lqdflash_amd.h
index e5cbffbb26..b9cc9045c0 100644
--- a/opencl/api/opencl/amdocl/cl_lqdflash_amd.h
+++ b/opencl/api/opencl/amdocl/cl_lqdflash_amd.h
@@ -43,6 +43,19 @@ clEnqueueWriteBufferFromFileAMD(
const cl_event * event_wait_list,
cl_event * event) CL_EXT_SUFFIX__VERSION_1_2;
+extern CL_API_ENTRY cl_int CL_API_CALL
+clEnqueueReadBufferToFileAMD(
+ cl_command_queue command_queue,
+ cl_mem buffer,
+ cl_bool blocking_write,
+ size_t buffer_offset,
+ size_t cb,
+ cl_file_amd file,
+ size_t file_offset,
+ cl_uint num_events_in_wait_list,
+ const cl_event * event_wait_list,
+ cl_event * event) CL_EXT_SUFFIX__VERSION_1_2;
+
#ifdef __cplusplus
} /*extern "C"*/
#endif /*__cplusplus*/
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 87ff3e11e9..5c90d688c3 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
@@ -254,16 +254,16 @@ typedef cl_int (CL_CALLBACK * intercept_callback_fn)(cl_event, cl_int *);
* cl_ext_device_fission extension *
***********************************/
#define cl_ext_device_fission 1
-
+
extern CL_API_ENTRY cl_int CL_API_CALL
clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
-
+
typedef CL_API_ENTRY cl_int
(CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
extern CL_API_ENTRY cl_int CL_API_CALL
clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
-
+
typedef CL_API_ENTRY cl_int
(CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1;
@@ -287,14 +287,14 @@ typedef cl_int (CL_CALLBACK * intercept_callback_fn)(cl_event, cl_int *);
#define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051
#define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052
#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053
-
+
/* clDeviceGetInfo selectors */
#define CL_DEVICE_PARENT_DEVICE_EXT 0x4054
#define CL_DEVICE_PARTITION_TYPES_EXT 0x4055
#define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056
#define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057
#define CL_DEVICE_PARTITION_STYLE_EXT 0x4058
-
+
/* clGetImageInfo enum */
#define CL_IMAGE_BYTE_PITCH_AMD 0x4059
@@ -302,7 +302,7 @@ typedef cl_int (CL_CALLBACK * intercept_callback_fn)(cl_event, cl_int *);
#define CL_DEVICE_PARTITION_FAILED_EXT -1057
#define CL_INVALID_PARTITION_COUNT_EXT -1058
#define CL_INVALID_PARTITION_NAME_EXT -1059
-
+
/* CL_AFFINITY_DOMAINs */
#define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1
#define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2
@@ -457,6 +457,7 @@ typedef CL_API_ENTRY cl_int
#define cl_amd_liquid_flash 1
#define CL_COMMAND_WRITE_BUFFER_FROM_FILE_AMD 0x4083
+#define CL_COMMAND_READ_BUFFER_FROM_FILE_AMD 0x4087
#define CL_INVALID_FILE_OBJECT_AMD 0x4084
@@ -491,16 +492,28 @@ typedef CL_API_ENTRY cl_int
(CL_API_CALL * clReleaseFileObjectAMD_fn)( cl_file_amd /*file*/) CL_EXT_SUFFIX__VERSION_1_2;
typedef CL_API_ENTRY cl_int
-(CL_API_CALL * clEnqueueWriteBufferFromFileAMD_fn)( cl_command_queue /*command_queue*/,
- cl_mem /*buffer*/,
- cl_bool /*blocking_write*/,
- size_t /*buffer_offset*/,
- size_t /*cb*/,
- cl_file_amd /*file*/,
- size_t /*file_offset*/,
- cl_uint /*num_events_in_wait_list*/,
- const cl_event * /*event_wait_list*/,
- cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2;
+(CL_API_CALL * clEnqueueWriteBufferFromFileAMD_fn)(cl_command_queue /*command_queue*/,
+ cl_mem /*buffer*/,
+ cl_bool /*blocking_write*/,
+ size_t /*buffer_offset*/,
+ size_t /*cb*/,
+ cl_file_amd /*file*/,
+ size_t /*file_offset*/,
+ cl_uint /*num_events_in_wait_list*/,
+ const cl_event * /*event_wait_list*/,
+ cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2;
+
+typedef CL_API_ENTRY cl_int
+(CL_API_CALL * clEnqueueReadBufferToFileAMD_fn)(cl_command_queue /*command_queue*/,
+ cl_mem /*buffer*/,
+ cl_bool /*blocking_read*/,
+ size_t /*buffer_offset*/,
+ size_t /*cb*/,
+ cl_file_amd /*file*/,
+ size_t /*file_offset*/,
+ cl_uint /*num_events_in_wait_list*/,
+ const cl_event * /*event_wait_list*/,
+ cl_event * /*event*/) CL_EXT_SUFFIX__VERSION_1_2;
#endif /* CL_VERSION_1_2 */
@@ -514,28 +527,28 @@ typedef CL_API_ENTRY cl_int
typedef cl_uint cl_kernel_sub_group_info;
/* cl_khr_sub_group_info */
-#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033
-#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034
+#define CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR 0x2033
+#define CL_KERNEL_SUB_GROUP_COUNT_FOR_NDRANGE_KHR 0x2034
extern CL_API_ENTRY cl_int CL_API_CALL
clGetKernelSubGroupInfoKHR(cl_kernel /* in_kernel */,
- cl_device_id /*in_device*/,
- cl_kernel_sub_group_info /* param_name */,
- size_t /*input_value_size*/,
- const void * /*input_value*/,
- size_t /*param_value_size*/,
- void* /*param_value*/,
- size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0;
-
+ cl_device_id /*in_device*/,
+ cl_kernel_sub_group_info /* param_name */,
+ size_t /*input_value_size*/,
+ const void * /*input_value*/,
+ size_t /*param_value_size*/,
+ void* /*param_value*/,
+ size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0;
+
typedef CL_API_ENTRY cl_int
( CL_API_CALL * clGetKernelSubGroupInfoKHR_fn)(cl_kernel /* in_kernel */,
- cl_device_id /*in_device*/,
- cl_kernel_sub_group_info /* param_name */,
- size_t /*input_value_size*/,
- const void * /*input_value*/,
- size_t /*param_value_size*/,
- void* /*param_value*/,
- size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0;
+ cl_device_id /*in_device*/,
+ cl_kernel_sub_group_info /* param_name */,
+ size_t /*input_value_size*/,
+ const void * /*input_value*/,
+ size_t /*param_value_size*/,
+ void* /*param_value*/,
+ size_t* /*param_value_size_ret*/ ) CL_EXT_SUFFIX__VERSION_2_0;
#endif /* CL_VERSION_2_0 */
#ifdef CL_VERSION_2_0
/*********************************
@@ -551,9 +564,9 @@ clCreateProgramWithILKHR(cl_context /* context */,
typedef CL_API_ENTRY cl_program
( CL_API_CALL * clCreateProgramWithILKHR_fn)(cl_context /* context */,
- const void * /* strings */,
- size_t /* lengths */,
- cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_2_0;
+ const void * /* strings */,
+ size_t /* lengths */,
+ cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_2_0;
#endif /* CL_VERSION_2_0 */