From c166e2513c2cad58cb736664ecc55480128d4406 Mon Sep 17 00:00:00 2001 From: foreman Date: Mon, 27 May 2019 20:11:08 -0400 Subject: [PATCH] P4 to Git Change 1787806 by yaxunl@yaxunl-lc10 on 2019/05/27 10:53:56 SWDEV-145570 - Support loading fat binary generated through --genco by hipModuleLoad. hip-clang --genco generates fat binary instead of code object. To support that we need to extract code object from fat binary in hipModuleLoadData. This is needed for hipRTC since multiple GPU archs may be passed. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#27 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#31 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#42 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.hpp#308 edit --- rocclr/runtime/device/devprogram.cpp | 14 ++++++++++++++ rocclr/runtime/utils/flags.hpp | 2 ++ 2 files changed, 16 insertions(+) diff --git a/rocclr/runtime/device/devprogram.cpp b/rocclr/runtime/device/devprogram.cpp index a28cfb1bb3..6881d275f3 100644 --- a/rocclr/runtime/device/devprogram.cpp +++ b/rocclr/runtime/device/devprogram.cpp @@ -1403,6 +1403,17 @@ bool Program::linkImpl(amd::option::Options* options) { } } +static void dumpCodeObject(const std::string& image) { + char fname[30]; + static std::atomic index; + sprintf(fname, "_code_object%04d.o", index++); + LogPrintfInfo("Code object saved in %s\n", fname); + std::ofstream ofs; + ofs.open(fname, std::ios::binary); + ofs << image; + ofs.close(); +} + // ================================================================================================ #if defined(USE_COMGR_LIBRARY) bool Program::linkImplLC(amd::option::Options* options) { @@ -1445,6 +1456,9 @@ bool Program::linkImplLC(amd::option::Options* options) { case ACL_TYPE_ISA: { amd::Comgr::destroy_data_set(inputs); binary_t isaBinary = binary(); + if (OCL_DUMP_CODE_OBJECT) { + dumpCodeObject(std::string{(const char*)isaBinary.first, isaBinary.second}); + } return setKernels(options, const_cast(isaBinary.first), isaBinary.second); break; } diff --git a/rocclr/runtime/utils/flags.hpp b/rocclr/runtime/utils/flags.hpp index 1c48880088..24226ab715 100644 --- a/rocclr/runtime/utils/flags.hpp +++ b/rocclr/runtime/utils/flags.hpp @@ -181,6 +181,8 @@ release(cstring, CUDA_VISIBLE_DEVICES, "", \ "Only devices whose index is present in the sequence are visible to HIP") \ release(bool, GPU_ENABLE_WGP_MODE, true, \ "Enables WGP Mode in HW if available") \ +release(bool, OCL_DUMP_CODE_OBJECT, false, \ + "Enable dump code object") \ namespace amd {