P4 to Git Change 1282811 by gandryey@gera-w8 on 2016/06/22 12:06:40

SWDEV-91794 - Memory leak when looping BuildProgram
	- Release binary raw inside runtime and compiler library

Affected files ...

... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/acl.cpp#43 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/bif/bifbase.cpp#57 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpucompiler.cpp#155 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#227 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#68 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#8 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#6 edit
Este commit está contenido en:
foreman
2016-06-22 12:40:45 -04:00
padre 047ef6b06e
commit af8e9cc3bb
Se han modificado 6 ficheros con 57 adiciones y 55 borrados
+3 -8
Ver fichero
@@ -447,15 +447,10 @@ HSAILProgram::compileImpl(
}
clBinary()->storeCompileOptions(compileOptions_);
// Save the binary in the interface class
size_t size = 0;
void* mem = NULL;
aclWriteToMem(binaryElf_, &mem, &size);
setBinary(static_cast<char*>(mem), size);
// Save the binary inside the program
// The FSAILProgram will be responsible to free it during destruction
rawBinary_ = mem;
// Save the binary in the interface class
saveBinaryAndSetType(TYPE_COMPILED);
return true;
}
+23 -11
Ver fichero
@@ -1715,7 +1715,7 @@ HSAILProgram::~HSAILProgram()
delete it;
}
if (rawBinary_ != NULL) {
free(rawBinary_);
aclFreeMem(binaryElf_, rawBinary_);
}
acl_error error;
// Free the elf binary
@@ -1863,12 +1863,8 @@ HSAILProgram::linkImpl(
aclBinaryFini(binaries_to_link[i]);
}
if (createLibrary) {
size_t size = 0;
void *mem = NULL;
aclWriteToMem(binaryElf_, &mem, &size);
setBinary(static_cast<char*>(mem), size);
saveBinaryAndSetType(TYPE_LIBRARY);
buildLog_ += aclGetCompilerLog(dev().hsaCompiler());
setType(TYPE_LIBRARY);
return true;
}
// Now call linkImpl with the new options
@@ -2227,12 +2223,8 @@ HSAILProgram::linkImpl(amd::option::Options* options)
}
}
// Save the binary in the interface class
size_t size = 0;
void *mem = NULL;
aclWriteToMem(binaryElf_, &mem, &size);
setBinary(static_cast<char*>(mem), size);
saveBinaryAndSetType(TYPE_EXECUTABLE);
buildLog_ += aclGetCompilerLog(dev().hsaCompiler());
setType(TYPE_EXECUTABLE);
return true;
}
@@ -2345,6 +2337,26 @@ HSAILProgram::info(const char * str) {
return info_;
}
bool
HSAILProgram::saveBinaryAndSetType(type_t type)
{
//Write binary to memory
if (rawBinary_ != NULL) {
//Free memory containing rawBinary
aclFreeMem(binaryElf_, rawBinary_);
rawBinary_ = NULL;
}
size_t size = 0;
if (aclWriteToMem(binaryElf_, &rawBinary_, &size) != ACL_SUCCESS) {
buildLog_ += "Failed to write binary to memory \n";
return false;
}
setBinary(static_cast<char*>(rawBinary_), size);
//Set the type of binary
setType(type);
return true;
}
hsa_isa_t ORCAHSALoaderContext::IsaFromName(const char *name) {
hsa_isa_t isa = {0};
if (!strcmp(Gfx700, name)) { isa.handle = gfx700; return isa; }
+1 -7
Ver fichero
@@ -559,13 +559,7 @@ protected:
*/
aclType getNextCompilationStageFromBinary(amd::option::Options* options);
/*! \brief Compiles LLVM binary to FSAIL code (compiler backend: link+opt+codegen)
*
* \return The build error code
*/
int compileBinaryToFSAIL(
amd::option::Options* options //!< options for compilation
);
bool saveBinaryAndSetType(type_t type);
virtual bool linkImpl(amd::option::Options* options);
+3 -8
Ver fichero
@@ -132,15 +132,10 @@ HSAILProgram::compileImpl(
}
clBinary()->storeCompileOptions(compileOptions_);
// Save the binary in the interface class
size_t size = 0;
void* mem = nullptr;
aclWriteToMem(binaryElf_, &mem, &size);
setBinary(static_cast<char*>(mem), size);
// Save the binary inside the program
// The FSAILProgram will be responsible to free it during destruction
rawBinary_ = mem;
// Save the binary in the interface class
saveBinaryAndSetType(TYPE_COMPILED);
return true;
}
+23 -11
Ver fichero
@@ -68,7 +68,7 @@ HSAILProgram::~HSAILProgram()
delete it;
}
if (rawBinary_ != nullptr) {
free(rawBinary_);
aclFreeMem(binaryElf_, rawBinary_);
}
acl_error error;
// Free the elf binary
@@ -216,12 +216,8 @@ HSAILProgram::linkImpl(
aclBinaryFini(binaries_to_link[i]);
}
if (createLibrary) {
size_t size = 0;
void *mem = NULL;
aclWriteToMem(binaryElf_, &mem, &size);
setBinary(static_cast<char*>(mem), size);
saveBinaryAndSetType(TYPE_LIBRARY);
buildLog_ += aclGetCompilerLog(dev().compiler());
setType(TYPE_LIBRARY);
return true;
}
// Now call linkImpl with the new options
@@ -578,12 +574,8 @@ HSAILProgram::linkImpl(amd::option::Options* options)
}
}
// Save the binary in the interface class
size_t size = 0;
void *mem = nullptr;
aclWriteToMem(binaryElf_, &mem, &size);
setBinary(static_cast<char*>(mem), size);
saveBinaryAndSetType(TYPE_EXECUTABLE);
buildLog_ += aclGetCompilerLog(dev().compiler());
setType(TYPE_EXECUTABLE);
return true;
}
@@ -696,6 +688,26 @@ HSAILProgram::info(const char * str) {
return info_;
}
bool
HSAILProgram::saveBinaryAndSetType(type_t type)
{
//Write binary to memory
if (rawBinary_ != nullptr) {
//Free memory containing rawBinary
aclFreeMem(binaryElf_, rawBinary_);
rawBinary_ = nullptr;
}
size_t size = 0;
if (aclWriteToMem(binaryElf_, &rawBinary_, &size) != ACL_SUCCESS) {
buildLog_ += "Failed to write binary to memory \n";
return false;
}
setBinary(static_cast<char*>(rawBinary_), size);
//Set the type of binary
setType(type);
return true;
}
hsa_isa_t ORCAHSALoaderContext::IsaFromName(const char *name) {
hsa_isa_t isa = {0};
if (!strcmp(Gfx700, name)) { isa.handle = gfx700; return isa; }
+4 -10
Ver fichero
@@ -208,14 +208,8 @@ protected:
/* \brief Returns the next stage to compile from, based on sections and options in binary
*/
aclType getNextCompilationStageFromBinary(amd::option::Options* options);
/*! \brief Compiles LLVM binary to FSAIL code (compiler backend: link+opt+codegen)
*
* \return The build error code
*/
int compileBinaryToFSAIL(
amd::option::Options* options //!< options for compilation
);
bool saveBinaryAndSetType(type_t type);
virtual bool linkImpl(amd::option::Options* options);
@@ -269,10 +263,10 @@ private:
aclBinary* binaryElf_; //!< Binary for the new compiler library
void* rawBinary_; //!< Pointer to the raw binary
aclBinaryOptions binOpts_; //!< Binary options to create aclBinary
std::vector<Memory*> globalStores_; //!< Global memory for the program
std::vector<Memory*> globalStores_; //!< Global memory for the program
Memory* kernels_; //!< Table with kernel object pointers
uint maxScratchRegs_; //!< Maximum number of scratch regs used in the program by individual kernel
std::list<Sampler*> staticSamplers_; //!< List od internal static samplers
std::list<Sampler*> staticSamplers_; //!< List od internal static samplers
bool isNull_; //!< Null program no memory allocations
amd::hsa::loader::Loader* loader_; //!< Loader object
amd::hsa::loader::Executable* executable_; //!< Executable for HSA Loader