From e51298aee13ee7dd1a5766729c38bdb4f5c8caae Mon Sep 17 00:00:00 2001 From: foreman Date: Sun, 11 Aug 2019 18:53:11 -0400 Subject: [PATCH] P4 to Git Change 1981324 by kjayapra@3_HIPWS_TXT_ROCM on 2019/08/11 18:44:40 SWDEV-188177 - Texture API implementation and support for extern variables. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.def.in#18 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_hcc.map.in#20 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#35 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#32 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#37 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_texture.cpp#14 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#340 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#57 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#31 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#608 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#172 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#250 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#79 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#152 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#41 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#96 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#39 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#133 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.hpp#39 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#105 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#48 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#102 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.hpp#46 edit --- hipamd/api/hip/hip_hcc.def.in | 1 + hipamd/api/hip/hip_hcc.map.in | 1 + hipamd/api/hip/hip_internal.hpp | 3 +++ hipamd/api/hip/hip_module.cpp | 26 ++++++++++++++++++++-- hipamd/api/hip/hip_platform.cpp | 21 +++++++++++++++++- hipamd/api/hip/hip_texture.cpp | 39 ++++++++++++++++++++++++++++----- 6 files changed, 83 insertions(+), 8 deletions(-) diff --git a/hipamd/api/hip/hip_hcc.def.in b/hipamd/api/hip/hip_hcc.def.in index 3c1a05716f..9acf1b1314 100644 --- a/hipamd/api/hip/hip_hcc.def.in +++ b/hipamd/api/hip/hip_hcc.def.in @@ -110,6 +110,7 @@ hipMemsetD8 hipMemset3D hipModuleGetFunction hipModuleGetGlobal +hipModuleGetTexRef hipModuleLaunchKernel hipModuleLaunchKernelExt hipLaunchCooperativeKernel diff --git a/hipamd/api/hip/hip_hcc.map.in b/hipamd/api/hip/hip_hcc.map.in index 624761944d..2af53915bc 100644 --- a/hipamd/api/hip/hip_hcc.map.in +++ b/hipamd/api/hip/hip_hcc.map.in @@ -111,6 +111,7 @@ global: hipMemset3D; hipModuleGetFunction; hipModuleGetGlobal; + hipModuleGetTexRef; hipModuleLaunchKernel; hipModuleLaunchKernelExt; hipLaunchCooperativeKernel; diff --git a/hipamd/api/hip/hip_internal.hpp b/hipamd/api/hip/hip_internal.hpp index 6e7614f315..1f7e31c9aa 100644 --- a/hipamd/api/hip/hip_internal.hpp +++ b/hipamd/api/hip/hip_internal.hpp @@ -135,7 +135,9 @@ public: std::vector functions; }; struct DeviceVar { + void* shadowVptr; std::string hostVar; + size_t size; std::vector< std::pair< hipModule_t, bool > >* modules; std::vector rvars; }; @@ -161,6 +163,7 @@ public: bool getFuncAttr(const void* hostFunction, hipFuncAttributes* func_attr); bool getGlobalVar(const void* hostVar, int deviceId, hipDeviceptr_t* dev_ptr, size_t* size_ptr); + bool getShadowVarInfo(std::string var_name, void** var_addr, size_t* var_size); void setupArgument(const void *arg, size_t size, size_t offset); void configureCall(dim3 gridDim, dim3 blockDim, size_t sharedMem, hipStream_t stream); diff --git a/hipamd/api/hip/hip_module.cpp b/hipamd/api/hip/hip_module.cpp index 315caffa31..77a8a34659 100644 --- a/hipamd/api/hip/hip_module.cpp +++ b/hipamd/api/hip/hip_module.cpp @@ -114,7 +114,7 @@ bool ihipModuleRegisterGlobal(amd::Program* program, hipModule_t* module) { device::Program* dev_program = program->getDeviceProgram(*hip::getCurrentContext()->devices()[0]); - if (!dev_program->getGlobalSymbolsFromCodeObj(&var_names)) { + if (!dev_program->getGlobalVarFromCodeObj(&var_names)) { return false; } @@ -124,7 +124,7 @@ bool ihipModuleRegisterGlobal(amd::Program* program, hipModule_t* module) { modules->at(dev) = std::make_pair(*module, false); } - PlatformState::DeviceVar dvar{it->c_str(), modules, + PlatformState::DeviceVar dvar{nullptr, it->c_str(), 0, modules, std::vector{ g_devices.size()}}; PlatformState::instance().registerVar(it->c_str(), dvar); } @@ -417,3 +417,25 @@ hipError_t hipExtLaunchMultiKernelMultiDevice(hipLaunchParams* launchParamsList, int numDevices, unsigned int flags) { return ihipLaunchCooperativeKernelMultiDevice(launchParamsList, numDevices, flags, 0); } + +hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const char* name) { + HIP_INIT_API(texRef, hmod, name); + + hipDeviceptr_t dptr = nullptr; + size_t bytes = 0; + + /* input args check */ + if ((texRef == nullptr) || (name == nullptr)) { + HIP_RETURN(hipErrorInvalidValue); + } + + /* Get address and size for the global symbol */ + if (!PlatformState::instance().getGlobalVar(name, ihipGetDevice(), &dptr, + &bytes)) { + HIP_RETURN(hipErrorUnknown); + } + + *texRef = reinterpret_cast(dptr); + HIP_RETURN(hipSuccess); +} + diff --git a/hipamd/api/hip/hip_platform.cpp b/hipamd/api/hip/hip_platform.cpp index 3e70f6e539..e05bae5c68 100644 --- a/hipamd/api/hip/hip_platform.cpp +++ b/hipamd/api/hip/hip_platform.cpp @@ -209,6 +209,23 @@ bool ihipGetFuncAttributes(const char* func_name, amd::Program* program, hipFunc return true; } +bool PlatformState::getShadowVarInfo(std::string var_name, void** var_addr, size_t* var_size) { + const auto it = vars_.find(var_name); + if (it != vars_.cend()) { + DeviceVar& dvar = it->second; + *var_addr = dvar.shadowVptr; + *var_size = dvar.size; + return true; + } else { + return false; + } +} + +bool CL_CALLBACK getSvarInfo(cl_program program, std::string var_name, void** var_addr, + size_t* var_size) { + return PlatformState::instance().getShadowVarInfo(var_name, var_addr, var_size); +} + hipFunction_t PlatformState::getFunc(const void* hostFunction, int deviceId) { amd::ScopedLock lock(lock_); const auto it = functions_.find(hostFunction); @@ -218,6 +235,7 @@ hipFunction_t PlatformState::getFunc(const void* hostFunction, int deviceId) { hipModule_t module = (*devFunc.modules)[deviceId].first; if (!(*devFunc.modules)[deviceId].second) { amd::Program* program = as_amd(reinterpret_cast(module)); + program->setVarInfoCallBack(&getSvarInfo); if (CL_SUCCESS != program->build(g_devices[deviceId]->devices(), nullptr, nullptr, nullptr)) { return nullptr; } @@ -280,6 +298,7 @@ bool PlatformState::getGlobalVar(const void* hostVar, int deviceId, if (!(*dvar.modules)[deviceId].second) { amd::Program* program = as_amd(reinterpret_cast((*dvar.modules)[deviceId].first)); + program->setVarInfoCallBack(&getSvarInfo); if (CL_SUCCESS != program->build(g_devices[deviceId]->devices(), nullptr, nullptr, nullptr)) { return false; } @@ -358,7 +377,7 @@ extern "C" void __hipRegisterVar( { HIP_INIT(); - PlatformState::DeviceVar dvar{ std::string{ hostVar }, modules, + PlatformState::DeviceVar dvar{var, std::string{ hostVar }, static_cast(size), modules, std::vector{ g_devices.size() } }; PlatformState::instance().registerVar(hostVar, dvar); diff --git a/hipamd/api/hip/hip_texture.cpp b/hipamd/api/hip/hip_texture.cpp index 4857e4ba55..08754fd773 100644 --- a/hipamd/api/hip/hip_texture.cpp +++ b/hipamd/api/hip/hip_texture.cpp @@ -442,13 +442,38 @@ hipError_t hipBindTextureToArray(textureReference* tex, hipArray_const_t array, HIP_RETURN(hipErrorUnknown); } +hipError_t ihipBindTextureImpl(int dim, enum hipTextureReadMode readMode, size_t* offset, + const void* devPtr, const struct hipChannelFormatDesc* desc, + size_t size, textureReference* tex) { + HIP_INIT_API(dim, readMode, offset, devPtr, size, tex); + + assert(1 == dim); + + HIP_RETURN(ihipBindTexture(CL_MEM_OBJECT_IMAGE1D, offset, tex, devPtr, desc, 1, 1, size)); +} + hipError_t ihipBindTextureToArrayImpl(TlsData* tls, int dim, enum hipTextureReadMode readMode, hipArray_const_t array, const struct hipChannelFormatDesc& desc, textureReference* tex) { - assert(0 && "Unimplemented"); + HIP_INIT_API(dim, readMode, &desc, array, tex); - return hipErrorUnknown; + cl_mem_object_type clType; + size_t offset = 0; + + switch (dim) { + case 1: + clType = CL_MEM_OBJECT_IMAGE1D_ARRAY; + break; + case 2: + clType = CL_MEM_OBJECT_IMAGE2D_ARRAY; + break; + default: + HIP_RETURN(hipErrorInvalidValue); + } + + HIP_RETURN(ihipBindTexture(clType, &offset, tex, array->data, &desc, array->width, + array->height, array->depth)); } hipError_t hipBindTextureToMipmappedArray(textureReference* tex, @@ -464,7 +489,7 @@ hipError_t hipBindTextureToMipmappedArray(textureReference* tex, hipError_t hipUnbindTexture(const textureReference* tex) { HIP_INIT_API(tex); - as_amd(reinterpret_cast(tex->textureObject))->release(); + ihipDestroyTextureObject(reinterpret_cast(tex->textureObject)); HIP_RETURN(hipSuccess); } @@ -482,9 +507,13 @@ hipError_t hipGetChannelDesc(hipChannelFormatDesc* desc, hipArray_const_t array) hipError_t hipGetTextureAlignmentOffset(size_t* offset, const textureReference* tex) { HIP_INIT_API(offset, tex); - assert(0 && "Unimplemented"); + if ((offset == nullptr) || (tex == nullptr)) { + HIP_RETURN(hipErrorInvalidValue); + } - HIP_RETURN(hipErrorUnknown); + *offset = 0; + + HIP_RETURN(hipSuccess); } hipError_t hipGetTextureReference(const textureReference** tex, const void* symbol) {