From 580eb5f852b74d3d0e17353fccca4ef89d0fbf0b Mon Sep 17 00:00:00 2001 From: foreman Date: Fri, 24 Jul 2015 11:35:14 -0400 Subject: [PATCH] P4 to Git Change 1173703 by emankov@em-hsa-amd on 2015/07/24 11:22:49 ECR #333753 - Compiler Lib/aoc2: AMD HSA Code Object Import feature Works only in case of whole compilation from the source CL to ISA. Doesn't work for -srctoir, -irtocg, -cgtoisa as meaningless. Importing occurs instead of finalization. To use offline by aoc2: aoc2 -hsacodeobject= -cl-std=CL2.0 -march=hsail(-64) -mdevice=Bonaire To use online by setting env: AMD_DEBUG_HSA_CODE_OBJECT_INPUT= Misc: + fix a few aoc2 bugs & typos + readFile/writeFile functions duplication removal + std::getenv instead of :getenv (ToDo: :putenv -> std::system in separate change) + fix memory leak in hsail_be.cpp on CodeObject Testing: pre checin, ursa.pl -t complib -M hsacodeobject Reviewers: Nikolay Haustov, Brian Sumner http://ocltc.amd.com/reviews/r/8058/ Affected files ... ... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/acl.cpp#32 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#71 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/MDParser/Main.cxx#2 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/hsail_be.cpp#46 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/v0_8/libUtils.h#19 edit ... //depot/stg/opencl/drivers/opencl/compiler/tools/aoc2/aoc2.cpp#73 edit ... //depot/stg/opencl/drivers/opencl/tests/hsa/bin/test_driver.pl#14 edit ... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/aoc2/hsacodeobject/hsacodeobject.1.cl#1 add ... //depot/stg/opencl/drivers/opencl/tests/hsa/src/complib/aoc2/hsacodeobject/hsacodeobject.cl#1 add ... //depot/stg/opencl/drivers/opencl/tests/hsa/tlst/complib.tlst#7 edit --- .../lib/backends/common/v0_8/if_acl.cpp | 30 --------- rocclr/compiler/lib/utils/v0_8/libUtils.h | 62 +++++++++++++++++++ 2 files changed, 62 insertions(+), 30 deletions(-) diff --git a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp index 100b4397f3..a488b99f62 100644 --- a/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp +++ b/rocclr/compiler/lib/backends/common/v0_8/if_acl.cpp @@ -1056,36 +1056,6 @@ HSAILFEToISA( return BEAsmPhase(ald, source, data_size); } -static char * readFile(const char *source, size_t& size) { - FILE *fp = ::fopen( source, "rb" ); - unsigned int length; - size_t offset = 0; - char *ptr; - - if (!fp) { - return NULL; - } - - // obtain file size. - ::fseek (fp , 0 , SEEK_END); - length = ::ftell (fp); - ::rewind (fp); - - ptr = new char[offset + length + 1]; - - if (length != fread(&ptr[offset], 1, length, fp)) - { - delete [] ptr; - return NULL; - } - - ptr[offset + length] = '\0'; - size = offset + length; - ::fclose(fp); - - return ptr; -} - static acl_error aclCompileInternal( aclCompiler *cl, diff --git a/rocclr/compiler/lib/utils/v0_8/libUtils.h b/rocclr/compiler/lib/utils/v0_8/libUtils.h index d3a068573d..b49de55d9a 100644 --- a/rocclr/compiler/lib/utils/v0_8/libUtils.h +++ b/rocclr/compiler/lib/utils/v0_8/libUtils.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "library.hpp" // Utility function to set a flag in option structure // of the aclDevCaps. @@ -218,4 +219,65 @@ alignedFree(void *ptr) #endif } +#if defined(_WIN32) +inline void convertLongAbsFilePathIfNeeded(std::string &filename) +{ + if (filename.empty()) { + return; + } + std::wstring ws(filename.begin(), filename.end()); + wchar_t abs_path[_MAX_ENV]; + _wfullpath(abs_path, ws.c_str(), _MAX_ENV); + std::wstring ws_abs = std::wstring(abs_path); + if (ws_abs.size() >= _MAX_PATH) { + std::string s(ws_abs.begin(), ws_abs.end()); + filename = "\\\\?\\" + s; + } +} +#endif + +inline char* readFile(std::string source_filename, size_t& size) +{ +#if defined(_WIN32) + convertLongAbsFilePathIfNeeded(source_filename); +#endif + FILE *fp = ::fopen( source_filename.c_str(), "rb" ); + unsigned int length; + size_t offset = 0; + char *ptr; + if (!fp) { + return NULL; + } + // obtain file size + ::fseek (fp , 0 , SEEK_END); + length = ::ftell (fp); + ::rewind (fp); + ptr = reinterpret_cast(::malloc(offset + length + 1)); + if (length != fread(&ptr[offset], 1, length, fp)) + { + ::free(ptr); + return NULL; + } + ptr[offset + length] = '\0'; + size = offset + length; + ::fclose(fp); + return ptr; +} + +inline bool writeFile(std::string source_filename, const char *source, size_t size) +{ +#if defined(_WIN32) + convertLongAbsFilePathIfNeeded(source_filename); +#endif + FILE *fp = ::fopen(source_filename.c_str(), "wb"); + if (!fp) { + return EXIT_FAILURE; + } + if (!::fwrite(source, size, 1, fp)) { + return EXIT_FAILURE; + } + ::fclose(fp); + return EXIT_SUCCESS; +} + #endif // _CL_LIB_UTILS_0_8_H_