P4 to Git Change 1199371 by lmoriche@lmoriche_opencl_dev on 2015/10/13 16:29:28

SWDEV-78467 - Add the LiquidFlashFile implementation (except for readBlocks)

Affected files ...

... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#121 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_lqdflash_amd.cpp#2 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_lqdflash_amd.h#2 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/khronos/headers/opencl2.0/CL/cl_ext.h#19 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/object.hpp#16 edit


[ROCm/clr commit: d53303025f]
This commit is contained in:
foreman
2015-10-13 16:47:28 -04:00
parent 0fd02cea75
commit 512a7c282c
3 changed files with 132 additions and 9 deletions
@@ -3,9 +3,108 @@
//
#include "cl_common.hpp"
#include <CL/cl_ext.h>
#include "platform/object.hpp"
#include "cl_lqdflash_amd.h"
#if defined __linux__
typedef wchar_t char_t;
#endif // __linux__
#if defined _WIN32
//#define WITH_LIQUID_FLASH 1
#endif // _WIN32
#if defined WITH_LIQUID_FLASH
#include "lf.h"
#endif // WITH_LIQUID_FLASH
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();
}
bool
LiquidFlashFile::open()
{
#if defined WITH_LIQUID_FLASH
lf_status err;
lf_file_flags flags;
switch (flags_) {
case CL_FILE_READ_ONLY_AMD: flags = LF_READ; break;
case CL_FILE_WRITE_ONLY_AMD: flags = LF_WRITE; break;
case CL_FILE_READ_WRITE_AMD: flags = LF_READ|LF_WRITE; break;
}
handle_ = lfOpenFile(name_, flags, &err);
if (err == lf_success) {
return true;
}
#endif // WITH_LIQUID_FLASH
return false;
}
void
LiquidFlashFile::close()
{
#if defined WITH_LIQUID_FLASH
if (handle_ != NULL) {
lfReleaseFile((lf_file)handle_);
handle_ = NULL;
}
#endif // WITH_LIQUID_FLASH
}
size_t
LiquidFlashFile::blockSize() const
{
#if defined WITH_LIQUID_FLASH
if (handle_ != NULL) {
lf_uint32 blockSize;
if (lfGetFileBlockSize((lf_file)handle_, &blockSize) == lf_success) {
return blockSize;
}
}
#endif // WITH_LIQUID_FLASH
return 0;
}
} // namesapce amd
/*! \addtogroup API
* @{
*
@@ -16,26 +115,47 @@
RUNTIME_ENTRY_RET(cl_file_amd, clCreateFileObjectAMD, (
cl_context context,
cl_file_flags_amd,
cl_char * file_name,
cl_int *errcode_ret))
cl_file_flags_amd flags,
const wchar_t* file_name,
cl_int* errcode_ret))
{
*not_null(errcode_ret) = CL_INVALID_CONTEXT;
return (cl_file_amd) 0;
amd::LiquidFlashFile* file = new amd::LiquidFlashFile(file_name, flags);
if (file == NULL) {
*not_null(errcode_ret) = CL_OUT_OF_HOST_MEMORY;
return (cl_file_amd)0;
}
if (!file->open()) {
*not_null(errcode_ret) = CL_INVALID_VALUE;
delete file;
return (cl_file_amd)0;
}
*not_null(errcode_ret) = CL_SUCCESS;
return as_cl(file);
}
RUNTIME_EXIT
RUNTIME_ENTRY(cl_int, clRetainFileObjectAMD, (
cl_file_amd file))
{
return CL_INVALID_FILE_OBJECT_AMD;
if (!is_valid(file)) {
return CL_INVALID_FILE_OBJECT_AMD;
}
as_amd(file)->retain();
return CL_SUCCESS;
}
RUNTIME_EXIT
RUNTIME_ENTRY(cl_int, clReleaseFileObjectAMD, (
cl_file_amd file))
{
return CL_INVALID_FILE_OBJECT_AMD;
if (!is_valid(file)) {
return CL_INVALID_FILE_OBJECT_AMD;
}
as_amd(file)->release();
return CL_SUCCESS;
}
RUNTIME_EXIT
@@ -11,7 +11,7 @@ extern CL_API_ENTRY cl_file_amd CL_API_CALL
clCreateFileObjectAMD(
cl_context context,
cl_file_flags_amd flags,
cl_char * file_name,
const wchar_t * file_name,
cl_int * errcode_ret) CL_EXT_SUFFIX__VERSION_1_2;
extern CL_API_ENTRY cl_int CL_API_CALL
@@ -461,11 +461,14 @@ typedef CL_API_ENTRY cl_int
typedef struct _cl_file_amd * cl_file_amd;
typedef cl_uint cl_file_flags_amd;
#define CL_FILE_READ_ONLY_AMD (1 << 0)
#define CL_FILE_WRITE_ONLY_AMD (1 << 1)
#define CL_FILE_READ_WRITE_AMD (1 << 2)
typedef CL_API_ENTRY cl_file_amd
(CL_API_CALL * clCreateFileObjectAMD_fn)( cl_context /*context*/,
cl_file_flags_amd /*flags*/,
cl_char * /*file_name*/,
const wchar_t * /*file_name*/,
cl_int * /*errcode_ret*/) CL_EXT_SUFFIX__VERSION_1_2;
typedef CL_API_ENTRY cl_int