From e8886648c6f0a5414cd86e73ab782d77cac83ae8 Mon Sep 17 00:00:00 2001 From: foreman Date: Thu, 3 Nov 2016 02:35:28 -0500 Subject: [PATCH] P4 to Git Change 1335811 by lmoriche@lmoriche_opencl_lc on 2016/11/03 03:28:18 SWDEV-105604 - [OCL-LC-PAL] OpenCL program manager for LC on PAL - Fix the corrupted HSACO file when using -save-temps/-save-temps-all on Windows. Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#10 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#20 edit [ROCm/clr commit: 9227e8ede51c02230e98b706753fe03221fd333e] --- projects/clr/rocclr/runtime/device/pal/palcompiler.cpp | 5 ++++- projects/clr/rocclr/runtime/device/pal/palprogram.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp b/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp index 460e7ee80e..ae452d5678 100644 --- a/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp @@ -345,6 +345,7 @@ LightningProgram::compileImpl( "-c -emit-llvm -target amdgcn-amd-amdhsa-opencl -x cl " << driverOptions << " -include opencl-c.h " << "\n*/\n\n" << sourceCode; + f.close(); } else { buildLog_ += "Warning: opening the file to dump the OpenCL source failed.\n"; @@ -394,9 +395,11 @@ LightningProgram::compileImpl( elfSectionType_ = amd::OclElf::LLVMIR; if (options->isDumpFlagSet(amd::option::DUMP_BC_ORIGINAL)) { - std::ofstream f(options->getDumpFileName("_original.bc").c_str(), std::ios::trunc); + std::ofstream f(options->getDumpFileName("_original.bc").c_str(), + std::ios::binary | std::ios::trunc); if(f.is_open()) { f.write(llvmBinary_.data(), llvmBinary_.size()); + f.close(); } else { buildLog_ += "Warning: opening the file to dump the compiled IR failed.\n"; diff --git a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp index dccee6d56d..4e9ed615a5 100644 --- a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp @@ -1196,9 +1196,11 @@ LightningProgram::linkImpl(amd::option::Options *options) } if (options->isDumpFlagSet(amd::option::DUMP_BC_LINKED)) { - std::ofstream f(options->getDumpFileName("_linked.bc").c_str(), std::ios::trunc); + std::ofstream f(options->getDumpFileName("_linked.bc").c_str(), + std::ios::binary | std::ios::trunc); if(f.is_open()) { f.write(linked_bc->Buf().data(), linked_bc->Size()); + f.close(); } else { buildLog_ += "Warning: opening the file to dump the linked IR failed.\n"; @@ -1239,9 +1241,11 @@ LightningProgram::linkImpl(amd::option::Options *options) } if (options->isDumpFlagSet(amd::option::DUMP_O)) { - std::ofstream f(options->getDumpFileName(".so").c_str(), std::ios::trunc); + std::ofstream f(options->getDumpFileName(".so").c_str(), + std::ios::binary | std::ios::trunc); if(f.is_open()) { f.write(out_exec->Buf().data(), out_exec->Size()); + f.close(); } else { buildLog_ += "Warning: opening the file to dump the code object failed.\n";