Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kernel_tuner/backends/hip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .hip import *
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from kernel_tuner.backends.backend import GPUBackend
from kernel_tuner.observers.hip import HipRuntimeObserver
from kernel_tuner.backends.hip.util import hip_check

try:
from hip import hip, hiprtc
Expand All @@ -31,20 +32,6 @@

hipSuccess = 0


def hip_check(call_result):
"""helper function to check return values of hip calls"""
err = call_result[0]
result = call_result[1:]
if len(result) == 1:
result = result[0]
if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess:
_, error_name = hip.hipGetErrorName(err)
_, error_str = hip.hipGetErrorString(err)
raise RuntimeError(f"{error_name}: {error_str}")
return result


class HipFunctions(GPUBackend):
"""Class that groups the HIP functions on maintains state about the device."""

Expand Down
18 changes: 18 additions & 0 deletions kernel_tuner/backends/hip/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
try:
from hip import hip, hiprtc
except (ImportError, RuntimeError):
hip = None


def hip_check(call_result):
"""helper function to check return values of hip calls"""
err = call_result[0]
result = call_result[1:]
if len(result) == 1:
result = result[0]
if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess:
_, error_name = hip.hipGetErrorName(err)
_, error_str = hip.hipGetErrorString(err)
raise RuntimeError(f"{error_name}: {error_str}")
return result

3 changes: 2 additions & 1 deletion kernel_tuner/observers/hip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np

from kernel_tuner.observers.observer import BenchmarkObserver
from kernel_tuner.backends.hip.util import hip_check

try:
from hip import hip, hiprtc
Expand All @@ -24,7 +25,7 @@ def __init__(self, dev):

def after_finish(self):
# Time is measured in milliseconds
EventElapsedTime = hip.hipEventElapsedTime(self.start, self.end)
EventElapsedTime = hip_check(hip.hipEventElapsedTime(self.start, self.end))
self.times.append(EventElapsedTime)

def get_results(self):
Expand Down