From d0c8e12d008af970f60cfca58e689d14fe14a419 Mon Sep 17 00:00:00 2001 From: foreman Date: Thu, 4 Apr 2019 18:22:40 -0400 Subject: [PATCH] P4 to Git Change 1766106 by kjayapra@99_HIPWS_SLV_CHECKIN on 2019/04/04 18:07:26 SWDEV-144570 - Implementation of hipMemcpyToSymbol and simillar fns for PAL. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#24 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#22 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#26 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#23 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#89 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#37 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#102 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#46 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#135 edit --- hipamd/api/hip/hip_internal.hpp | 5 +-- hipamd/api/hip/hip_module.cpp | 17 ++------- hipamd/api/hip/hip_platform.cpp | 61 ++++++++++++++++++++------------- 3 files changed, 44 insertions(+), 39 deletions(-) diff --git a/hipamd/api/hip/hip_internal.hpp b/hipamd/api/hip/hip_internal.hpp index c5ba11b68a..de9de24a32 100644 --- a/hipamd/api/hip/hip_internal.hpp +++ b/hipamd/api/hip/hip_internal.hpp @@ -100,8 +100,8 @@ class PlatformState { public: struct RegisteredVar { public: - RegisteredVar(): hostVar_(nullptr), size_(0), devicePtr_(nullptr) {} - RegisteredVar(char* hostVar, size_t size, hipDeviceptr_t devicePtr); + RegisteredVar(): hostVar_(nullptr), size_(0), devicePtr_(nullptr), amd_mem_obj_(nullptr) {} + RegisteredVar(char* hostVar, size_t size, hipDeviceptr_t devicePtr, amd::Memory* amd_mem_obj); ~RegisteredVar() {} hipDeviceptr_t getdeviceptr() const { return devicePtr_; }; @@ -111,6 +111,7 @@ public: char* hostVar_; // Variable name in host code size_t size_; // Size of the variable hipDeviceptr_t devicePtr_; //Device Memory Address of the variable. + amd::Memory* amd_mem_obj_; }; private: diff --git a/hipamd/api/hip/hip_module.cpp b/hipamd/api/hip/hip_module.cpp index 62f676dfe0..b482f39b77 100644 --- a/hipamd/api/hip/hip_module.cpp +++ b/hipamd/api/hip/hip_module.cpp @@ -132,24 +132,13 @@ hipError_t hipModuleGetFunction(hipFunction_t *hfunc, hipModule_t hmod, const ch HIP_RETURN(hipSuccess); } - hipError_t hipModuleGetGlobal(hipDeviceptr_t* dptr, size_t* bytes, hipModule_t hmod, const char* name) { HIP_INIT_API(dptr, bytes, hmod, name); - amd::Program* program = nullptr; - const device::Program* dev_program = nullptr; - - /* Get Device Program pointer*/ - program = as_amd(reinterpret_cast(hmod)); - dev_program = program->getDeviceProgram(*hip::getCurrentContext()->devices()[0]); - - if (dev_program == nullptr) { - HIP_RETURN(hipErrorUnknown); - } - - /* Find the global Symbols */ - if(!dev_program->findGlobalSymbols(dptr, bytes, name)) { + /* Get address and size for the global symbol */ + if (!PlatformState::instance().getGlobalVar(name, ihipGetDevice(), dptr, + bytes)) { HIP_RETURN(hipErrorUnknown); } diff --git a/hipamd/api/hip/hip_platform.cpp b/hipamd/api/hip/hip_platform.cpp index f2602babb1..36a79cf35f 100644 --- a/hipamd/api/hip/hip_platform.cpp +++ b/hipamd/api/hip/hip_platform.cpp @@ -61,6 +61,9 @@ struct __ClangOffloadBundleHeader { hipError_t hipModuleGetGlobal(hipDeviceptr_t* dptr, size_t* bytes, hipModule_t hmod, const char* name); +hipError_t ihipCreateGlobalVarObj(const char* name, hipModule_t hmod, amd::Memory** amd_mem_obj, + hipDeviceptr_t* dptr, size_t* bytes); + extern "C" std::vector* __hipRegisterFatBinary(const void* data) { HIP_INIT(); @@ -122,26 +125,13 @@ extern "C" std::vector* __hipRegisterFatBinary(const void* data) return programs; } -PlatformState::RegisteredVar::RegisteredVar(char* hostVar, size_t size, hipDeviceptr_t devicePtr) - : hostVar_(hostVar), size_(size), devicePtr_(devicePtr) { - amd::Memory* amd_mem_obj = nullptr; - uint32_t flags = 0; - - /* Create an amd Memory object for the pointer */ - amd_mem_obj - = new (*hip::getCurrentContext()) amd::Buffer(*hip::getCurrentContext(), flags, size, devicePtr_); - - if (amd_mem_obj == nullptr) { - LogError("[OCL] failed to create a mem object!"); - } - - if (!amd_mem_obj->create(nullptr)) { - LogError("[OCL] failed to create a svm hidden buffer!"); - amd_mem_obj->release(); - } +PlatformState::RegisteredVar::RegisteredVar(char* hostVar, size_t size, hipDeviceptr_t devicePtr, + amd::Memory* amd_mem_obj) : hostVar_(hostVar), + size_(size), devicePtr_(devicePtr), + amd_mem_obj_(amd_mem_obj) { /* Add the memory to the MemObjMap */ - amd::MemObjMap::AddMemObj(devicePtr_, amd_mem_obj); + amd::MemObjMap::AddMemObj(devicePtr_, amd_mem_obj_); } void PlatformState::registerVar(const char* hostvar, @@ -245,7 +235,6 @@ extern "C" void __hipRegisterVar( int constant, // Whether this variable is constant int global) // Unknown, always 0 { -#if 0 HIP_INIT(); size_t sym_size = 0; @@ -253,14 +242,17 @@ extern "C" void __hipRegisterVar( for (size_t deviceId=0; deviceId < g_devices.size(); ++deviceId) { hipDeviceptr_t device_ptr = nullptr; - if((hipSuccess == hipModuleGetGlobal(&device_ptr, &sym_size, modules->at(deviceId), - hostVar)) && (device_ptr != nullptr)) { + amd::Memory* amd_mem_obj = nullptr; + + if((hipSuccess == ihipCreateGlobalVarObj(hostVar, modules->at(deviceId), &amd_mem_obj, + &device_ptr, &sym_size)) + && (device_ptr != nullptr)) { if (static_cast(size) != sym_size) { LogError("[OCL] Size Mismatch with the HSA Symbol retrieved \n"); } - global_vars[deviceId] = PlatformState::RegisteredVar(hostVar, sym_size, device_ptr); + global_vars[deviceId] = PlatformState::RegisteredVar(hostVar, sym_size, device_ptr, amd_mem_obj); } else { LogError("[OCL] __hipRegisterVar cannot find kernel for device \n"); @@ -268,7 +260,6 @@ extern "C" void __hipRegisterVar( } PlatformState::instance().registerVar(hostVar, global_vars); -#endif } extern "C" void __hipUnregisterFatBinary(std::vector* modules) @@ -350,6 +341,30 @@ hipError_t hipGetSymbolSize(size_t* sizePtr, const void* symbolName) { HIP_RETURN(hipSuccess); } +hipError_t ihipCreateGlobalVarObj(const char* name, hipModule_t hmod, amd::Memory** amd_mem_obj, hipDeviceptr_t* dptr, size_t* bytes) +{ + HIP_INIT(); + + amd::Program* program = nullptr; + device::Program* dev_program = nullptr; + + /* Get Device Program pointer*/ + program = as_amd(reinterpret_cast(hmod)); + dev_program = program->getDeviceProgram(*hip::getCurrentContext()->devices()[0]); + + if (dev_program == nullptr) { + HIP_RETURN(hipErrorUnknown); + } + + /* Find the global Symbols */ + if(!dev_program->createGlobalVarObj(amd_mem_obj, dptr, bytes, name)) { + HIP_RETURN(hipErrorUnknown); + } + + HIP_RETURN(hipSuccess); +} + + #if defined(ATI_OS_LINUX) namespace hip_impl {