Skip to content

Commit 80d5a2b

Browse files
Merge pull request #334 from KernelTuner/fix_issue_332
fix issue #332
2 parents f9b223b + eb387e0 commit 80d5a2b

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .hip import *

kernel_tuner/backends/hip.py renamed to kernel_tuner/backends/hip/hip.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from kernel_tuner.backends.backend import GPUBackend
1010
from kernel_tuner.observers.hip import HipRuntimeObserver
11+
from kernel_tuner.backends.hip.util import hip_check
1112

1213
try:
1314
from hip import hip, hiprtc
@@ -31,20 +32,6 @@
3132

3233
hipSuccess = 0
3334

34-
35-
def hip_check(call_result):
36-
"""helper function to check return values of hip calls"""
37-
err = call_result[0]
38-
result = call_result[1:]
39-
if len(result) == 1:
40-
result = result[0]
41-
if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess:
42-
_, error_name = hip.hipGetErrorName(err)
43-
_, error_str = hip.hipGetErrorString(err)
44-
raise RuntimeError(f"{error_name}: {error_str}")
45-
return result
46-
47-
4835
class HipFunctions(GPUBackend):
4936
"""Class that groups the HIP functions on maintains state about the device."""
5037

kernel_tuner/backends/hip/util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
try:
2+
from hip import hip, hiprtc
3+
except (ImportError, RuntimeError):
4+
hip = None
5+
6+
7+
def hip_check(call_result):
8+
"""helper function to check return values of hip calls"""
9+
err = call_result[0]
10+
result = call_result[1:]
11+
if len(result) == 1:
12+
result = result[0]
13+
if isinstance(err, hip.hipError_t) and err != hip.hipError_t.hipSuccess:
14+
_, error_name = hip.hipGetErrorName(err)
15+
_, error_str = hip.hipGetErrorString(err)
16+
raise RuntimeError(f"{error_name}: {error_str}")
17+
return result
18+

kernel_tuner/observers/hip.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import numpy as np
22

33
from kernel_tuner.observers.observer import BenchmarkObserver
4+
from kernel_tuner.backends.hip.util import hip_check
45

56
try:
67
from hip import hip, hiprtc
@@ -24,7 +25,7 @@ def __init__(self, dev):
2425

2526
def after_finish(self):
2627
# Time is measured in milliseconds
27-
EventElapsedTime = hip.hipEventElapsedTime(self.start, self.end)
28+
EventElapsedTime = hip_check(hip.hipEventElapsedTime(self.start, self.end))
2829
self.times.append(EventElapsedTime)
2930

3031
def get_results(self):

0 commit comments

Comments
 (0)