2
0

SWDEV-241902 - Changes to pass file descriptor and offset to load code object.

Change-Id: I0243cccdeaa533b2a56fde42f12d5424c3b63a3b
Este cometimento está contido em:
kjayapra-amd
2020-08-03 11:21:37 -04:00
cometido por Karthik Jayaprakash
ascendente de6e02f98b
cometimento a66c56d641
14 ficheiros modificados com 220 adições e 45 eliminações
+12 -2
Ver ficheiro
@@ -1,4 +1,4 @@
/* Copyright (c) 2008-present Advanced Micro Devices, Inc.
/* Copyright (c) 2008-presenet Advanced Micro Devices, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -759,7 +759,12 @@ bool ClBinary::createElfBinary(bool doencrypt, Program::type_t type) {
Program::binary_t ClBinary::data() const { return {binary_, size_}; }
bool ClBinary::setBinary(const char* theBinary, size_t theBinarySize, bool allocated) {
Program::finfo_t ClBinary::Datafd() const { return {fdesc_, foffset_}; }
std::string ClBinary::DataURI() const { return uri_; }
bool ClBinary::setBinary(const char* theBinary, size_t theBinarySize, bool allocated,
amd::Os::FileDesc fdesc, size_t foffset, std::string uri) {
release();
size_ = theBinarySize;
@@ -767,6 +772,11 @@ bool ClBinary::setBinary(const char* theBinary, size_t theBinarySize, bool alloc
if (allocated) {
flags_ |= BinaryAllocated;
}
fdesc_ = fdesc;
foffset_ = foffset;
uri_ = uri;
return true;
}
+24 -4
Ver ficheiro
@@ -869,9 +869,9 @@ class ClBinary : public amd::HeapObject {
void init(amd::option::Options* optionsObj, bool amdilRequired = false);
/** called only in loading image routines,
never called in storing routines */
bool setBinary(const char* theBinary, size_t theBinarySize, bool allocated = false);
/** called only in loading image routines, never storing routines */
bool setBinary(const char* theBinary, size_t theBinarySize, bool allocated = false,
amd::Os::FileDesc fd = -1, size_t foffset = 0, std::string uri = std::string());
//! setin elfIn_
bool setElfIn();
@@ -900,8 +900,10 @@ class ClBinary : public amd::HeapObject {
bool decryptElf(const char* binaryIn, size_t size, char** decryptBin, size_t* decryptSize,
int* encryptCode);
//! Returns the binary pair for the abstraction layer
//! Returns the binary pair, fdesc pair, uri for the abstraction layer
Program::binary_t data() const;
Program::finfo_t Datafd() const;
std::string DataURI() const;
//! Loads llvmir binary from OCL binary file
bool loadLlvmBinary(
@@ -1016,6 +1018,10 @@ class ClBinary : public amd::HeapObject {
size_t size_; //!< binary size
uint flags_; //!< CL binary object flags
amd::Os::FileDesc fdesc_; //!< file descriptor
size_t foffset_; //!< file offset
std::string uri_; //!< memory URI
const char* origBinary_; //!< original binary data
size_t origSize_; //!< original binary size
@@ -1034,6 +1040,20 @@ inline const Program::binary_t Program::binary() const {
return clBinary()->data();
}
inline std::string Program::BinaryURI() const {
if (clBinary() == NULL) {
return std::string();
}
return clBinary()->DataURI();
}
inline Program::finfo_t Program::BinaryFd() const {
if (clBinary() == NULL) {
return {-1, 0};
}
return clBinary()->Datafd();
}
inline Program::binary_t Program::binary() {
if (clBinary() == NULL) {
return {(const void*)0, 0};
+13 -6
Ver ficheiro
@@ -1089,10 +1089,12 @@ bool Program::linkImplLC(amd::option::Options* options) {
case ACL_TYPE_ISA: {
amd::Comgr::destroy_data_set(inputs);
binary_t isaBinary = binary();
finfo_t isaFdesc = BinaryFd();
if (GPU_DUMP_CODE_OBJECT) {
dumpCodeObject(std::string{(const char*)isaBinary.first, isaBinary.second});
}
return setKernels(options, const_cast<void *>(isaBinary.first), isaBinary.second);
return setKernels(options, const_cast<void *>(isaBinary.first), isaBinary.second,
isaFdesc.first, isaFdesc.second, BinaryURI());
break;
}
default:
@@ -1852,7 +1854,8 @@ bool isSPIRVMagicL(const void* Image, size_t Length) {
}
// ================================================================================================
bool Program::initClBinary(const char* binaryIn, size_t size) {
bool Program::initClBinary(const char* binaryIn, size_t size, amd::Os::FileDesc fdesc,
size_t foffset, std::string uri) {
if (!initClBinary()) {
DevLogError("Init CL Binary failed \n");
return false;
@@ -1947,12 +1950,13 @@ bool Program::initClBinary(const char* binaryIn, size_t size) {
clBinary()->setFlags(encryptCode);
return clBinary()->setBinary(bin, sz, (decryptedBin != nullptr));
return clBinary()->setBinary(bin, sz, (decryptedBin != nullptr), fdesc, foffset, uri);
}
// ================================================================================================
bool Program::setBinary(const char* binaryIn, size_t size, const device::Program* same_dev_prog) {
if (!initClBinary(binaryIn, size)) {
bool Program::setBinary(const char* binaryIn, size_t size, const device::Program* same_dev_prog,
amd::Os::FileDesc fdesc, size_t foffset, std::string uri) {
if (!initClBinary(binaryIn, size, fdesc, foffset, uri)) {
DevLogError("Init CL Binary failed \n");
return false;
}
@@ -2187,6 +2191,8 @@ aclType Program::getCompilationStagesFromBinary(std::vector<aclType>& completeSt
aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options) {
aclType continueCompileFrom = ACL_TYPE_DEFAULT;
binary_t binary = this->binary();
finfo_t finfo = this->BinaryFd();
std::string uri = this->BinaryURI();
// If the binary already exists
if ((binary.first != nullptr) && (binary.second > 0)) {
#if defined(WITH_COMPILER_LIB)
@@ -2207,7 +2213,8 @@ aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options
// Saving binary in the interface class,
// which also load compile & link options from binary
setBinary(static_cast<const char*>(binary.first), binary.second);
setBinary(static_cast<const char*>(binary.first), binary.second, nullptr,
finfo.first, finfo.second, uri);
// Calculate the next stage to compile from, based on sections in binaryElf_;
// No any validity checks here
+11 -4
Ver ficheiro
@@ -70,7 +70,8 @@ struct SymbolLoweredName {
//! A program object for a specific device.
class Program : public amd::HeapObject {
public:
typedef std::pair<const void*, size_t> binary_t;
typedef std::pair<const void* /* binary_image */, size_t /* binary size */> binary_t;
typedef std::pair<amd::Os::FileDesc /* file_desc */, size_t /* file_offset */> finfo_t;
typedef std::unordered_map<std::string, Kernel*> kernels_t;
// type of the program
typedef enum {
@@ -186,12 +187,15 @@ class Program : public amd::HeapObject {
//! Return the binary image.
inline const binary_t binary() const;
inline binary_t binary();
inline finfo_t BinaryFd() const;
inline std::string BinaryURI() const;
//! Returns the CL program binary file
ClBinary* clBinary() { return clBinary_; }
const ClBinary* clBinary() const { return clBinary_; }
bool setBinary(const char* binaryIn, size_t size, const device::Program* same_dev_prog = nullptr);
bool setBinary(const char* binaryIn, size_t size, const device::Program* same_dev_prog = nullptr,
amd::Os::FileDesc fdesc = -1, size_t foffset = 0, std::string uri = std::string());
type_t type() const { return type_; }
@@ -279,7 +283,8 @@ class Program : public amd::HeapObject {
virtual bool createBinary(amd::option::Options* options) = 0;
//! Initialize Binary (used only for clCreateProgramWithBinary()).
bool initClBinary(const char* binaryIn, size_t size);
bool initClBinary(const char* binaryIn, size_t size, amd::Os::FileDesc fdesc = -1,
size_t foffset = 0, std::string uri = std::string());
//! Initialize Binary
virtual bool initClBinary();
@@ -293,7 +298,9 @@ class Program : public amd::HeapObject {
virtual const aclTargetInfo& info(const char* str = "") = 0;
virtual bool setKernels(
amd::option::Options* options, void* binary, size_t binSize) { return true; }
amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
std::string uri = std::string()) { return true; }
//! Returns all the options to be appended while passing to the compiler library
std::vector<std::string> ProcessOptions(amd::option::Options* options);
Ficheiro normal → Ficheiro executável
+4 -2
Ver ficheiro
@@ -238,7 +238,8 @@ inline static std::vector<std::string> splitSpaceSeparatedString(char* str) {
return vec;
}
bool HSAILProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize) {
bool HSAILProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc, size_t foffset, std::string uri) {
#if defined(WITH_COMPILER_LIB)
// ACL_TYPE_CG stage is not performed for offline compilation
hsa_agent_t agent;
@@ -735,7 +736,8 @@ bool LightningProgram::createBinary(amd::option::Options* options) {
return true;
}
bool LightningProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize) {
bool LightningProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc, size_t foffset, std::string uri) {
#if defined(USE_COMGR_LIBRARY)
hsa_agent_t agent;
agent.handle = 1;
Ficheiro normal → Ficheiro executável
+3 -1
Ver ficheiro
@@ -195,7 +195,9 @@ class HSAILProgram : public device::Program {
virtual const aclTargetInfo& info(const char* str = "");
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize) override;
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
std::string uri = std::string()) override;
//! Destroys CPU allocations in the code segment
void DestroySegmentCpuAccess() const {
Ficheiro normal → Ficheiro executável
+7 -3
Ver ficheiro
@@ -264,7 +264,8 @@ bool HSAILProgram::saveBinaryAndSetType(type_t type) {
return true;
}
bool HSAILProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize) {
bool HSAILProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc, size_t foffset, std::string uri) {
#if defined(WITH_COMPILER_LIB)
// Stop compilation if it is an offline device - HSA runtime does not
// support ISA compiled offline
@@ -467,7 +468,8 @@ bool LightningProgram::saveBinaryAndSetType(type_t type, void* rawBinary, size_t
return true;
}
bool LightningProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize) {
bool LightningProgram::setKernels(amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc, size_t foffset, std::string uri) {
#if defined(USE_COMGR_LIBRARY)
// Find the size of global variables from the binary
if (!FindGlobalVarSize(binary, binSize)) {
@@ -488,7 +490,9 @@ bool LightningProgram::setKernels(amd::option::Options* options, void* binary, s
return false;
}
// Load the code object.
// Load the code object, either with file descriptor and offset
// or binary image and binary size with URI
// or binary image and binary size
status = hsa_code_object_reader_create_from_memory(binary, binSize, &hsaCodeObjectReader_);
if (status != HSA_STATUS_SUCCESS) {
buildLog_ += "Error: AMD HSA Code Object Reader create failed: ";
Ficheiro normal → Ficheiro executável
+6 -2
Ver ficheiro
@@ -91,7 +91,9 @@ class HSAILProgram : public roc::Program {
protected:
bool createBinary(amd::option::Options* options) override { return true; }
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize) override;
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
std::string uri = std::string()) override;
private:
std::string codegenOptions(amd::option::Options* options);
@@ -112,7 +114,9 @@ protected:
private:
bool saveBinaryAndSetType(type_t type, void* rawBinary, size_t size);
bool setKernels(amd::option::Options* options, void* binary, size_t binSize) final;
bool setKernels(amd::option::Options* options, void* binary, size_t binSize,
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
std::string uri = std::string()) final;
};
/*@}*/} // namespace roc