[rocprofiler-compute] Add exception handling for native tool path search (#2159)

* Add exception handling for native tool path search

* Fix formatting in roofline benchmark code

* Fix detection of .so files

* include hip code and native tool code in standalone binary

* add fallback path for ROCM_PATH
This commit is contained in:
vedithal-amd
2025-12-04 10:29:49 -05:00
committed by GitHub
parent 4ff89b6fd1
commit d8a8a3ef30
6 changed files with 102 additions and 64 deletions
+2 -14
View File
@@ -37,8 +37,9 @@ from ctypes import (
c_uint8,
c_void_p,
)
import os
_lib = ctypes.CDLL("libamdhip64.so")
_lib = ctypes.CDLL(f"{os.getenv('ROCM_PATH', '/opt/rocm')}/lib/libamdhip64.so")
# Mirrors struct hipUUID_t
@@ -299,7 +300,6 @@ class HIPModule:
def hipGetDeviceCount() -> int:
device_count = c_int()
status = _lib.hipGetDeviceCount(byref(device_count))
@@ -310,7 +310,6 @@ def hipGetDeviceCount() -> int:
def hipGetDeviceProperties(device_id: int) -> HIPDeviceProperties:
props = HIPDeviceProperties()
res = _lib.hipGetDevicePropertiesR0600(byref(props), device_id)
@@ -321,7 +320,6 @@ def hipGetDeviceProperties(device_id: int) -> HIPDeviceProperties:
def hipMalloc(size: int) -> HIPDeviceMemory:
buf_size = c_size_t(size)
ptr = c_void_p()
@@ -334,7 +332,6 @@ def hipMalloc(size: int) -> HIPDeviceMemory:
def hipMemcpyHtoD(dst: HIPDeviceMemory, src: POINTER, size: int) -> None:
res = _lib.hipMemcpyHtoD(dst.ptr, src, size)
if res != 0:
@@ -342,7 +339,6 @@ def hipMemcpyHtoD(dst: HIPDeviceMemory, src: POINTER, size: int) -> None:
def hipMemcpyDtoH(dst: POINTER, src: HIPDeviceMemory, size: int) -> None:
res = _lib.hipMemcpyDtoH(dst, src.ptr, size)
if res != 0:
@@ -350,7 +346,6 @@ def hipMemcpyDtoH(dst: POINTER, src: HIPDeviceMemory, size: int) -> None:
def hipSetDevice(id: int) -> None:
status = _lib.hipSetDevice(id)
if status != 0:
@@ -358,7 +353,6 @@ def hipSetDevice(id: int) -> None:
def hipDeviceSynchronize() -> None:
res = _lib.hipDeviceSynchronize()
if res != 0:
@@ -366,7 +360,6 @@ def hipDeviceSynchronize() -> None:
def hipModuleLoadData(code: POINTER) -> HIPModule:
module = c_void_p()
res = _lib.hipModuleLoadData(byref(module), code)
@@ -377,7 +370,6 @@ def hipModuleLoadData(code: POINTER) -> HIPModule:
def hipModuleGetFunction(module: POINTER, name: str) -> POINTER:
name_bytes = name.encode("utf-8")
func = c_void_p()
@@ -402,7 +394,6 @@ def hipModuleLaunchKernel(
kernel_params: POINTER,
extra: POINTER = None,
) -> None:
res = _lib.hipModuleLaunchKernel(
func,
grid_dim_x,
@@ -422,7 +413,6 @@ def hipModuleLaunchKernel(
def hipEventCreate() -> HIPEvent:
handle = c_void_p()
res = _lib.hipEventCreate(byref(handle))
@@ -434,7 +424,6 @@ def hipEventCreate() -> HIPEvent:
def hipEventRecord(event: HIPEvent, stream: POINTER = None) -> None:
res = _lib.hipEventRecord(event.handle, stream)
if res != 0:
@@ -442,7 +431,6 @@ def hipEventRecord(event: HIPEvent, stream: POINTER = None) -> None:
def hipEventElapsedTime(start: HIPEvent, stop: HIPEvent) -> float:
ms = c_float()
res = _lib.hipEventElapsedTime(byref(ms), start.handle, stop.handle)
@@ -33,8 +33,9 @@ from ctypes import (
c_size_t,
c_void_p,
)
import os
_lib = ctypes.CDLL("libhiprtc.so")
_lib = ctypes.CDLL(f"{os.getenv('ROCM_PATH', '/opt/rocm')}/lib/libhiprtc.so")
_lib.hiprtcCreateProgram.restype = c_int
@@ -112,7 +113,6 @@ class HIPRTCProgram:
# TODO: Handle headers
def hiprtcCreateProgram(src: str, name: str) -> HIPRTCProgram:
src_bytes = src.encode("utf-8")
name_bytes = name.encode("utf-8")
@@ -128,7 +128,6 @@ def hiprtcCreateProgram(src: str, name: str) -> HIPRTCProgram:
# TODO: Handle compile options
def hiprtcCompileProgram(prog: HIPRTCProgram) -> None:
res = _lib.hiprtcCompileProgram(prog.handle, 0, None)
if res != 0:
@@ -136,7 +135,6 @@ def hiprtcCompileProgram(prog: HIPRTCProgram) -> None:
def hiprtcGetProgramLogSize(prog: HIPRTCProgram) -> int:
size = c_size_t(0)
res = _lib.hiprtcGetProgramLogSize(prog.handle, byref(size))
@@ -148,7 +146,6 @@ def hiprtcGetProgramLogSize(prog: HIPRTCProgram) -> int:
def hiprtcGetProgramLog(prog: HIPRTCProgram) -> str:
size = hiprtcGetProgramLogSize(prog)
buf = (ctypes.c_char * size)()
@@ -171,7 +168,6 @@ def hiprtcGetCodeSize(prog: HIPRTCProgram) -> int:
def hiprtcGetCode(prog: HIPRTCProgram) -> POINTER:
size = hiprtcGetCodeSize(prog)
buf = (c_char * size)()
res = _lib.hiprtcGetCode(prog.handle, buf)
@@ -183,7 +179,6 @@ def hiprtcGetCode(prog: HIPRTCProgram) -> POINTER:
def hiprtcGetLoweredName(prog: HIPRTCProgram, name_expression: str) -> str:
expr_bytes = name_expression.encode("utf-8")
name_bytes = c_char_p()
@@ -196,7 +191,6 @@ def hiprtcGetLoweredName(prog: HIPRTCProgram, name_expression: str) -> str:
def hiprtcAddNameExpression(prog: HIPRTCProgram, name_expression: str) -> None:
expr_bytes = name_expression.encode("utf-8")
res = _lib.hiprtcAddNameExpression(prog.handle, expr_bytes)