Skip to content

Commit 3b44884

Browse files
authored
SWDEV-508869 - Fix Linux build error for HIP on PAL (#176)
[ROCm/clr commit: 9699cc3]
1 parent 20a9e31 commit 3b44884

File tree

8 files changed

+37
-17
lines changed

8 files changed

+37
-17
lines changed

projects/clr/rocclr/device/device.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ class Memory : public amd::HeapObject {
981981
//! not a physical map. When a memory object does not use USE_HOST_PTR we
982982
//! can use a remote resource and DMA, avoiding the additional CPU memcpy.
983983
amd::Memory* mapMemory_; //!< Memory used as map target buffer
984-
volatile size_t indirectMapCount_; //!< Number of maps
984+
std::atomic<size_t> indirectMapCount_; //!< Number of maps
985985
std::unordered_map<const void*, WriteMapInfo>
986986
writeMapInfo_; //!< Saved write map info for partial unmap
987987

projects/clr/rocclr/device/pal/paldevice.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp,
426426
uint64_t(heaps[Pal::GpuHeapInvisible].physicalSize));
427427
}
428428

429-
#if defined(ATI_OS_WIN)
429+
#if IS_WINDOWS
430430
if (settings().apuSystem_) {
431431
info_.maxMemAllocSize_ = std::max(
432432
(static_cast<uint64_t>(heaps[Pal::GpuHeapGartUswc].logicalSize) * uswcPercentAvailable) /
@@ -673,8 +673,10 @@ void NullDevice::fillDeviceInfo(const Pal::DeviceProperties& palProp,
673673
info_.vgprsPerSimd_ = palProp.gfxipProperties.shaderCore.vgprsPerSimd;
674674
info_.sgprsPerSimd_ = palProp.gfxipProperties.shaderCore.sgprsPerSimd;
675675
info_.availableRegistersPerCU_ = info_.vgprsPerSimd_ * info_.simdPerCU_ * 32;
676+
#if IS_WINDOWS
676677
info_.luidLowPart_ = palProp.osProperties.luidLowPart;
677678
info_.luidHighPart_ = palProp.osProperties.luidHighPart;
679+
#endif
678680
// Setup the node mask for MGPU only case from the original PAL list of all devices
679681
if ((gNumDevices > 1) && (pal_device != nullptr)) {
680682
for (uint32_t i = 0; i < gNumDevices; ++i) {
@@ -2058,6 +2060,7 @@ bool Device::globalFreeMemory(size_t* freeMemory) const {
20582060
Pal::gpusize system_memory = allocedMem[Pal::GpuHeapGartCacheable] +
20592061
allocedMem[Pal::GpuHeapGartUswc] + cache_group_local - resourceCache().cacheSize();
20602062

2063+
#if IS_WINDOWS
20612064
// Second, query OS for overall memory usage on the system
20622065

20632066
if (properties().osProperties.supportMemoryBudgetQuery) {
@@ -2086,7 +2089,7 @@ bool Device::globalFreeMemory(size_t* freeMemory) const {
20862089
system_memory = system_total_alloced;
20872090
}
20882091
}
2089-
2092+
#endif
20902093
// Third, finalize reported free memory
20912094

20922095
// Fill free memory info
@@ -2799,12 +2802,12 @@ bool Device::createBlitProgram() {
27992802
if (asm_program->load()) {
28002803
trap_handler_ = asm_program;
28012804
} else {
2802-
DevLogPrintfError("Could not load the trap handler \n");
2805+
DevLogError("Could not load the trap handler \n");
28032806
asm_program->release();
28042807
}
28052808
}
28062809
} else {
2807-
DevLogPrintfError("Trap handler creation failed\n");
2810+
DevLogError("Trap handler creation failed\n");
28082811
}
28092812
}
28102813

projects/clr/rocclr/device/pal/paldevicegl.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ static PFNGlxGetProcAddress pfnGlxGetProcAddress = nullptr;
6565
typedef int(APIENTRYP PFNMesaGLInteropGLXQueryDeviceInfo)(Display* dpy, GLXContext context,
6666
mesa_glinterop_device_info* out);
6767
static PFNMesaGLInteropGLXQueryDeviceInfo pfnMesaGLInteropGLXQueryDeviceInfo = nullptr;
68+
typedef Bool(APIENTRYP PFNGLXBEGINCLINTEROPAMD)(GLXContext context, GLuint flags);
69+
typedef Bool(APIENTRYP PFNGLXENDCLINTEROPAMD)(GLXContext context, GLuint flags);
70+
typedef Bool(APIENTRYP PFNGLXRESOURCEATTACHAMD)(GLXContext context, GLvoid* resource,
71+
GLvoid* pResourceData);
72+
typedef Bool(APIENTRYP PFNGLXRESOURCEDETACHAMD)(GLXContext context, GLvoid* resource);
73+
typedef Bool(APIENTRYP PFNGLXRESOURCEDETACHAMD)(GLXContext context, GLvoid* resource);
74+
typedef Bool(APIENTRYP PFNGLXRESOURCEDETACHAMD)(GLXContext context, GLvoid* resource);
75+
typedef Bool(APIENTRYP PFNGLXGETCONTEXTMVPUINFOAMD)(GLXContext context, GLuint* deviceId,
76+
GLuint* chainMask);
6877
static PFNGLXBEGINCLINTEROPAMD glXBeginCLInteropAMD = nullptr;
6978
static PFNGLXENDCLINTEROPAMD glXEndCLInteropAMD = nullptr;
7079
static PFNGLXRESOURCEATTACHAMD glXResourceAttachAMD = nullptr;
@@ -90,8 +99,8 @@ static PFNWGLRESOURCEDETACHAMD wglResourceAcquireAMD = nullptr;
9099
static PFNWGLRESOURCEDETACHAMD wglResourceReleaseAMD = nullptr;
91100
static PFNWGLRESOURCEDETACHAMD wglResourceDetachAMD = nullptr;
92101
static PFNWGLGETCONTEXTGPUINFOAMD wglGetContextGPUInfoAMD = nullptr;
93-
bool gGlFuncInit = false;
94102
#endif
103+
bool gGlFuncInit = false;
95104

96105
namespace amd::pal {
97106

projects/clr/rocclr/device/pal/palmemory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,8 +1031,10 @@ Memory* Buffer::createBufferView(amd::Memory& subBufferOwner) const {
10311031
// ================================================================================================
10321032
bool Buffer::ExportHandle(void* handle) const {
10331033
Pal::GpuMemoryExportInfo exportInfo = {};
1034+
#if IS_WINDOWS
10341035
// Set default flags in case they are not provided by application
10351036
exportInfo.accessFlags = GENERIC_READ | GENERIC_WRITE;
1037+
#endif
10361038
*reinterpret_cast<Pal::OsExternalHandle*>(handle) = iMem()->ExportExternalHandle(exportInfo);
10371039
return true;
10381040
}

projects/clr/rocclr/device/pal/palresource.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ bool Resource::CreateInterop(CreateParams* params) {
792792

793793
if (!dev().resGLAssociate(oglRes->glPlatformContext_, oglRes->handle_, glType_,
794794
&openInfo.hExternalResource, &glInteropMbRes_, &offset_, desc_.format_
795-
#ifdef ATI_OS_WIN
795+
#if IS_WINDOWS
796796
,
797797
openInfo.doppDesktopInfo
798798
#endif
@@ -808,6 +808,7 @@ bool Resource::CreateInterop(CreateParams* params) {
808808
if (vparams->handle_) {
809809
openInfo.hExternalResource = vparams->handle_;
810810
} else if (vparams->name_) {
811+
#if IS_WINDOWS
811812
Pal::ExternalHandleInfo eHandleInfo = {};
812813
eHandleInfo.objectType = Pal::ExternalObjectType::Allocation;
813814
eHandleInfo.pNtObjectName = reinterpret_cast<const wchar_t*>(vparams->name_);
@@ -819,10 +820,13 @@ bool Resource::CreateInterop(CreateParams* params) {
819820
dev().iDev()->OpenExternalHandleFromName(eHandleInfo, &openInfo.hExternalResource)) {
820821
return false;
821822
}
823+
#else
824+
return false;
825+
#endif
822826
}
823827
openInfo.flags.ntHandle = vparams->nt_handle_;
824828
}
825-
#ifdef ATI_OS_WIN
829+
#if IS_WINDOWS
826830
else {
827831
D3DInteropParams* d3dRes = reinterpret_cast<D3DInteropParams*>(params);
828832
openInfo.hExternalResource = d3dRes->handle_;
@@ -883,7 +887,7 @@ bool Resource::CreateInterop(CreateParams* params) {
883887
switch (misc) {
884888
case 1: // NV12 or P010 formats
885889
switch (layer) {
886-
case -1:
890+
case std::numeric_limits<uint>::max():
887891
case 0:
888892
break;
889893
case 1:
@@ -899,7 +903,7 @@ bool Resource::CreateInterop(CreateParams* params) {
899903
break;
900904
case 2: // YV12 format
901905
switch (layer) {
902-
case -1:
906+
case std::numeric_limits<uint>::max():
903907
case 0:
904908
break;
905909
case 1:

projects/clr/rocclr/device/pal/palvirtual.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#pragma once
2222

2323
#include <queue>
24+
#include <inttypes.h>
2425
#include "device/pal/paldefs.hpp"
2526
#include "device/pal/palconstbuf.hpp"
2627
#include "device/pal/palprintf.hpp"
@@ -734,7 +735,7 @@ class VirtualGPU : public device::VirtualDevice {
734735
inline void VirtualGPU::logVmMemory(const std::string name, const Memory* memory) {
735736
if (PAL_EMBED_KERNEL_MD || (AMD_LOG_LEVEL >= amd::LOG_INFO)) {
736737
char buf[256];
737-
sprintf(buf, "%s = ptr:[%p-%p] size:[%llu] heap[%d]", name.c_str(),
738+
sprintf(buf, "%s = ptr:[%p-%p] size:[%" PRIu64 "] heap[%d]", name.c_str(),
738739
reinterpret_cast<void*>(memory->vmAddress()),
739740
reinterpret_cast<void*>(memory->vmAddress() + memory->size()),
740741
memory->iMem()->Desc().size, memory->iMem()->Desc().heaps[0]);

projects/clr/rocclr/include/GL/gl_interop.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#ifndef GL_INTEROP_H_
2222
#define GL_INTEROP_H_
2323

24-
#ifdef _WIN32
2524
#define GL_RESOURCE_ATTACH_TEXTURE_AMD 0x12a000
2625
#define GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD 0x12a001
2726
#define GL_RESOURCE_ATTACH_RENDERBUFFER_AMD 0x12a002
@@ -88,6 +87,7 @@ typedef struct GLResourceDataRec {
8887

8988
} GLResourceData;
9089

90+
#ifdef _WIN32
9191
typedef BOOL (WINAPI* PFNWGLBEGINCLINTEROPAMD)(HGLRC hglrc, GLuint flags);
9292
typedef BOOL (WINAPI* PFNWGLENDCLINTEROPAMD) (HGLRC hglrc, GLuint flags);
9393
typedef BOOL (WINAPI* PFNWGLRESOURCEATTACHAMD) (HGLRC hglrc, GLvoid* resource, GLvoid* pResourceData);

projects/clr/rocclr/utils/debug.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ inline void warning(const char* msg) { amd::report_warning(msg); }
237237
#else /*CL_LOG*/
238238
#define ClPrint(level, mask, format, ...) (void)(0)
239239
#define ClCondPrint(level, mask, condition, format, ...) (void)(0)
240+
#define HIPPrintDuration(level, mask, startTimeUs, format, ...) (void)(0)
240241
#endif /*CL_LOG*/
241242

242243
#define ClTrace(level, mask) ClPrint(level, mask, "%s", __func__)
@@ -245,13 +246,13 @@ inline void warning(const char* msg) { amd::report_warning(msg); }
245246
#define LogError(msg) ClPrint(amd::LOG_ERROR, amd::LOG_ALWAYS, msg)
246247
#define LogWarning(msg) ClPrint(amd::LOG_WARNING, amd::LOG_ALWAYS, msg)
247248

248-
#define LogPrintfDebug(format, ...) ClPrint(amd::LOG_DEBUG, amd::LOG_ALWAYS, format, __VA_ARGS__)
249-
#define LogPrintfError(format, ...) ClPrint(amd::LOG_ERROR, amd::LOG_ALWAYS, format, __VA_ARGS__)
250-
#define LogPrintfWarning(format, ...) ClPrint(amd::LOG_WARNING, amd::LOG_ALWAYS, format, __VA_ARGS__)
251-
#define LogPrintfInfo(format, ...) ClPrint(amd::LOG_INFO, amd::LOG_ALWAYS, format, __VA_ARGS__)
249+
#define LogPrintfDebug(format, ...) ClPrint(amd::LOG_DEBUG, amd::LOG_ALWAYS, format, ##__VA_ARGS__)
250+
#define LogPrintfError(format, ...) ClPrint(amd::LOG_ERROR, amd::LOG_ALWAYS, format, ##__VA_ARGS__)
251+
#define LogPrintfWarning(format, ...) ClPrint(amd::LOG_WARNING, amd::LOG_ALWAYS, format, ##__VA_ARGS__)
252+
#define LogPrintfInfo(format, ...) ClPrint(amd::LOG_INFO, amd::LOG_ALWAYS, format, ##__VA_ARGS__)
252253

253254
#if (defined(DEBUG) || defined(DEV_LOG_ENABLE))
254-
#define DevLogPrintfError(format, ...) LogPrintfError(format, __VA_ARGS__)
255+
#define DevLogPrintfError(format, ...) LogPrintfError(format, ##__VA_ARGS__)
255256
#define DevLogError(msg) LogError(msg)
256257
#else
257258
#define DevLogPrintfError(format, ...)

0 commit comments

Comments
 (0)