From 9699cc3864edb4f58cfc2ea996123692c1346ee9 Mon Sep 17 00:00:00 2001 From: "Lin, Qun" Date: Fri, 27 Jun 2025 07:51:22 +0800 Subject: [PATCH] SWDEV-508869 - Fix Linux build error for HIP on PAL (#176) --- rocclr/device/device.hpp | 2 +- rocclr/device/pal/paldevice.cpp | 11 +++++++---- rocclr/device/pal/paldevicegl.cpp | 11 ++++++++++- rocclr/device/pal/palmemory.cpp | 2 ++ rocclr/device/pal/palresource.cpp | 12 ++++++++---- rocclr/device/pal/palvirtual.hpp | 3 ++- rocclr/include/GL/gl_interop.h | 2 +- rocclr/utils/debug.hpp | 11 ++++++----- 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/rocclr/device/device.hpp b/rocclr/device/device.hpp index 5c2798ad76..ee9296eae5 100644 --- a/rocclr/device/device.hpp +++ b/rocclr/device/device.hpp @@ -981,7 +981,7 @@ class Memory : public amd::HeapObject { //! not a physical map. When a memory object does not use USE_HOST_PTR we //! can use a remote resource and DMA, avoiding the additional CPU memcpy. amd::Memory* mapMemory_; //!< Memory used as map target buffer - volatile size_t indirectMapCount_; //!< Number of maps + std::atomic indirectMapCount_; //!< Number of maps std::unordered_map writeMapInfo_; //!< Saved write map info for partial unmap diff --git a/rocclr/device/pal/paldevice.cpp b/rocclr/device/pal/paldevice.cpp index e10f8e2114..23ee6e04fc 100644 --- a/rocclr/device/pal/paldevice.cpp +++ b/rocclr/device/pal/paldevice.cpp @@ -426,7 +426,7 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp, uint64_t(heaps[Pal::GpuHeapInvisible].physicalSize)); } -#if defined(ATI_OS_WIN) +#if IS_WINDOWS if (settings().apuSystem_) { info_.maxMemAllocSize_ = std::max( (static_cast(heaps[Pal::GpuHeapGartUswc].logicalSize) * uswcPercentAvailable) / @@ -673,8 +673,10 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp, info_.vgprsPerSimd_ = palProp.gfxipProperties.shaderCore.vgprsPerSimd; info_.sgprsPerSimd_ = palProp.gfxipProperties.shaderCore.sgprsPerSimd; info_.availableRegistersPerCU_ = info_.vgprsPerSimd_ * info_.simdPerCU_ * 32; +#if IS_WINDOWS info_.luidLowPart_ = palProp.osProperties.luidLowPart; info_.luidHighPart_ = palProp.osProperties.luidHighPart; +#endif // Setup the node mask for MGPU only case from the original PAL list of all devices if ((gNumDevices > 1) && (pal_device != nullptr)) { for (uint32_t i = 0; i < gNumDevices; ++i) { @@ -2058,6 +2060,7 @@ bool Device::globalFreeMemory(size_t* freeMemory) const { Pal::gpusize system_memory = allocedMem[Pal::GpuHeapGartCacheable] + allocedMem[Pal::GpuHeapGartUswc] + cache_group_local - resourceCache().cacheSize(); +#if IS_WINDOWS // Second, query OS for overall memory usage on the system if (properties().osProperties.supportMemoryBudgetQuery) { @@ -2086,7 +2089,7 @@ bool Device::globalFreeMemory(size_t* freeMemory) const { system_memory = system_total_alloced; } } - +#endif // Third, finalize reported free memory // Fill free memory info @@ -2799,12 +2802,12 @@ bool Device::createBlitProgram() { if (asm_program->load()) { trap_handler_ = asm_program; } else { - DevLogPrintfError("Could not load the trap handler \n"); + DevLogError("Could not load the trap handler \n"); asm_program->release(); } } } else { - DevLogPrintfError("Trap handler creation failed\n"); + DevLogError("Trap handler creation failed\n"); } } diff --git a/rocclr/device/pal/paldevicegl.cpp b/rocclr/device/pal/paldevicegl.cpp index 15a40e765d..a55a50956c 100644 --- a/rocclr/device/pal/paldevicegl.cpp +++ b/rocclr/device/pal/paldevicegl.cpp @@ -65,6 +65,15 @@ static PFNGlxGetProcAddress pfnGlxGetProcAddress = nullptr; typedef int(APIENTRYP PFNMesaGLInteropGLXQueryDeviceInfo)(Display* dpy, GLXContext context, mesa_glinterop_device_info* out); static PFNMesaGLInteropGLXQueryDeviceInfo pfnMesaGLInteropGLXQueryDeviceInfo = nullptr; +typedef Bool(APIENTRYP PFNGLXBEGINCLINTEROPAMD)(GLXContext context, GLuint flags); +typedef Bool(APIENTRYP PFNGLXENDCLINTEROPAMD)(GLXContext context, GLuint flags); +typedef Bool(APIENTRYP PFNGLXRESOURCEATTACHAMD)(GLXContext context, GLvoid* resource, + GLvoid* pResourceData); +typedef Bool(APIENTRYP PFNGLXRESOURCEDETACHAMD)(GLXContext context, GLvoid* resource); +typedef Bool(APIENTRYP PFNGLXRESOURCEDETACHAMD)(GLXContext context, GLvoid* resource); +typedef Bool(APIENTRYP PFNGLXRESOURCEDETACHAMD)(GLXContext context, GLvoid* resource); +typedef Bool(APIENTRYP PFNGLXGETCONTEXTMVPUINFOAMD)(GLXContext context, GLuint* deviceId, + GLuint* chainMask); static PFNGLXBEGINCLINTEROPAMD glXBeginCLInteropAMD = nullptr; static PFNGLXENDCLINTEROPAMD glXEndCLInteropAMD = nullptr; static PFNGLXRESOURCEATTACHAMD glXResourceAttachAMD = nullptr; @@ -90,8 +99,8 @@ static PFNWGLRESOURCEDETACHAMD wglResourceAcquireAMD = nullptr; static PFNWGLRESOURCEDETACHAMD wglResourceReleaseAMD = nullptr; static PFNWGLRESOURCEDETACHAMD wglResourceDetachAMD = nullptr; static PFNWGLGETCONTEXTGPUINFOAMD wglGetContextGPUInfoAMD = nullptr; -bool gGlFuncInit = false; #endif +bool gGlFuncInit = false; namespace amd::pal { diff --git a/rocclr/device/pal/palmemory.cpp b/rocclr/device/pal/palmemory.cpp index 3c9177f3a2..8b2b2b912e 100644 --- a/rocclr/device/pal/palmemory.cpp +++ b/rocclr/device/pal/palmemory.cpp @@ -1031,8 +1031,10 @@ Memory* Buffer::createBufferView(amd::Memory& subBufferOwner) const { // ================================================================================================ bool Buffer::ExportHandle(void* handle) const { Pal::GpuMemoryExportInfo exportInfo = {}; +#if IS_WINDOWS // Set default flags in case they are not provided by application exportInfo.accessFlags = GENERIC_READ | GENERIC_WRITE; +#endif *reinterpret_cast(handle) = iMem()->ExportExternalHandle(exportInfo); return true; } diff --git a/rocclr/device/pal/palresource.cpp b/rocclr/device/pal/palresource.cpp index c03a90aa7a..432f6e4fee 100644 --- a/rocclr/device/pal/palresource.cpp +++ b/rocclr/device/pal/palresource.cpp @@ -792,7 +792,7 @@ bool Resource::CreateInterop(CreateParams* params) { if (!dev().resGLAssociate(oglRes->glPlatformContext_, oglRes->handle_, glType_, &openInfo.hExternalResource, &glInteropMbRes_, &offset_, desc_.format_ -#ifdef ATI_OS_WIN +#if IS_WINDOWS , openInfo.doppDesktopInfo #endif @@ -808,6 +808,7 @@ bool Resource::CreateInterop(CreateParams* params) { if (vparams->handle_) { openInfo.hExternalResource = vparams->handle_; } else if (vparams->name_) { +#if IS_WINDOWS Pal::ExternalHandleInfo eHandleInfo = {}; eHandleInfo.objectType = Pal::ExternalObjectType::Allocation; eHandleInfo.pNtObjectName = reinterpret_cast(vparams->name_); @@ -819,10 +820,13 @@ bool Resource::CreateInterop(CreateParams* params) { dev().iDev()->OpenExternalHandleFromName(eHandleInfo, &openInfo.hExternalResource)) { return false; } +#else + return false; +#endif } openInfo.flags.ntHandle = vparams->nt_handle_; } -#ifdef ATI_OS_WIN +#if IS_WINDOWS else { D3DInteropParams* d3dRes = reinterpret_cast(params); openInfo.hExternalResource = d3dRes->handle_; @@ -883,7 +887,7 @@ bool Resource::CreateInterop(CreateParams* params) { switch (misc) { case 1: // NV12 or P010 formats switch (layer) { - case -1: + case std::numeric_limits::max(): case 0: break; case 1: @@ -899,7 +903,7 @@ bool Resource::CreateInterop(CreateParams* params) { break; case 2: // YV12 format switch (layer) { - case -1: + case std::numeric_limits::max(): case 0: break; case 1: diff --git a/rocclr/device/pal/palvirtual.hpp b/rocclr/device/pal/palvirtual.hpp index 7e16dea9ff..52c347eb3b 100644 --- a/rocclr/device/pal/palvirtual.hpp +++ b/rocclr/device/pal/palvirtual.hpp @@ -21,6 +21,7 @@ #pragma once #include +#include #include "device/pal/paldefs.hpp" #include "device/pal/palconstbuf.hpp" #include "device/pal/palprintf.hpp" @@ -734,7 +735,7 @@ class VirtualGPU : public device::VirtualDevice { inline void VirtualGPU::logVmMemory(const std::string name, const Memory* memory) { if (PAL_EMBED_KERNEL_MD || (AMD_LOG_LEVEL >= amd::LOG_INFO)) { char buf[256]; - sprintf(buf, "%s = ptr:[%p-%p] size:[%llu] heap[%d]", name.c_str(), + sprintf(buf, "%s = ptr:[%p-%p] size:[%" PRIu64 "] heap[%d]", name.c_str(), reinterpret_cast(memory->vmAddress()), reinterpret_cast(memory->vmAddress() + memory->size()), memory->iMem()->Desc().size, memory->iMem()->Desc().heaps[0]); diff --git a/rocclr/include/GL/gl_interop.h b/rocclr/include/GL/gl_interop.h index f70bef98fe..c28bfdeb88 100644 --- a/rocclr/include/GL/gl_interop.h +++ b/rocclr/include/GL/gl_interop.h @@ -21,7 +21,6 @@ #ifndef GL_INTEROP_H_ #define GL_INTEROP_H_ -#ifdef _WIN32 #define GL_RESOURCE_ATTACH_TEXTURE_AMD 0x12a000 #define GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD 0x12a001 #define GL_RESOURCE_ATTACH_RENDERBUFFER_AMD 0x12a002 @@ -88,6 +87,7 @@ typedef struct GLResourceDataRec { } GLResourceData; +#ifdef _WIN32 typedef BOOL (WINAPI* PFNWGLBEGINCLINTEROPAMD)(HGLRC hglrc, GLuint flags); typedef BOOL (WINAPI* PFNWGLENDCLINTEROPAMD) (HGLRC hglrc, GLuint flags); typedef BOOL (WINAPI* PFNWGLRESOURCEATTACHAMD) (HGLRC hglrc, GLvoid* resource, GLvoid* pResourceData); diff --git a/rocclr/utils/debug.hpp b/rocclr/utils/debug.hpp index 952bae39bc..b17c5410da 100644 --- a/rocclr/utils/debug.hpp +++ b/rocclr/utils/debug.hpp @@ -237,6 +237,7 @@ inline void warning(const char* msg) { amd::report_warning(msg); } #else /*CL_LOG*/ #define ClPrint(level, mask, format, ...) (void)(0) #define ClCondPrint(level, mask, condition, format, ...) (void)(0) +#define HIPPrintDuration(level, mask, startTimeUs, format, ...) (void)(0) #endif /*CL_LOG*/ #define ClTrace(level, mask) ClPrint(level, mask, "%s", __func__) @@ -245,13 +246,13 @@ inline void warning(const char* msg) { amd::report_warning(msg); } #define LogError(msg) ClPrint(amd::LOG_ERROR, amd::LOG_ALWAYS, msg) #define LogWarning(msg) ClPrint(amd::LOG_WARNING, amd::LOG_ALWAYS, msg) -#define LogPrintfDebug(format, ...) ClPrint(amd::LOG_DEBUG, amd::LOG_ALWAYS, format, __VA_ARGS__) -#define LogPrintfError(format, ...) ClPrint(amd::LOG_ERROR, amd::LOG_ALWAYS, format, __VA_ARGS__) -#define LogPrintfWarning(format, ...) ClPrint(amd::LOG_WARNING, amd::LOG_ALWAYS, format, __VA_ARGS__) -#define LogPrintfInfo(format, ...) ClPrint(amd::LOG_INFO, amd::LOG_ALWAYS, format, __VA_ARGS__) +#define LogPrintfDebug(format, ...) ClPrint(amd::LOG_DEBUG, amd::LOG_ALWAYS, format, ##__VA_ARGS__) +#define LogPrintfError(format, ...) ClPrint(amd::LOG_ERROR, amd::LOG_ALWAYS, format, ##__VA_ARGS__) +#define LogPrintfWarning(format, ...) ClPrint(amd::LOG_WARNING, amd::LOG_ALWAYS, format, ##__VA_ARGS__) +#define LogPrintfInfo(format, ...) ClPrint(amd::LOG_INFO, amd::LOG_ALWAYS, format, ##__VA_ARGS__) #if (defined(DEBUG) || defined(DEV_LOG_ENABLE)) - #define DevLogPrintfError(format, ...) LogPrintfError(format, __VA_ARGS__) + #define DevLogPrintfError(format, ...) LogPrintfError(format, ##__VA_ARGS__) #define DevLogError(msg) LogError(msg) #else #define DevLogPrintfError(format, ...)