-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from MiloLurati/HIPbackend
HIP Backend
- Loading branch information
Showing
17 changed files
with
753 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
"""Minimal example for a HIP Kernel unit test with the Kernel Tuner""" | ||
|
||
import numpy | ||
from kernel_tuner import run_kernel | ||
import pytest | ||
|
||
#Check pyhip is installed and if a HIP capable device is present, if not skip the test | ||
try: | ||
from pyhip import hip, hiprtc | ||
except ImportError: | ||
pytest.skip("PyHIP not installed or PYTHONPATH does not includes PyHIP") | ||
hip = None | ||
hiprtc = None | ||
|
||
def test_vector_add(): | ||
|
||
kernel_string = """ | ||
__global__ void vector_add(float *c, float *a, float *b, int n) { | ||
int i = blockIdx.x * block_size_x + threadIdx.x; | ||
if (i<n) { | ||
c[i] = a[i] + b[i]; | ||
} | ||
} | ||
""" | ||
|
||
size = 10000000 | ||
problem_size = (size, 1) | ||
|
||
a = numpy.random.randn(size).astype(numpy.float32) | ||
b = numpy.random.randn(size).astype(numpy.float32) | ||
c = numpy.zeros_like(b) | ||
n = numpy.int32(size) | ||
|
||
args = [c, a, b, n] | ||
params = {"block_size_x": 512} | ||
|
||
answer = run_kernel("vector_add", kernel_string, problem_size, args, params, lang="HIP") | ||
|
||
assert numpy.allclose(answer[0], a+b, atol=1e-8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python | ||
"""This is the minimal example from the README""" | ||
|
||
import numpy | ||
from kernel_tuner import tune_kernel | ||
from kernel_tuner.file_utils import store_output_file, store_metadata_file | ||
import logging | ||
from collections import OrderedDict | ||
|
||
def tune(): | ||
|
||
kernel_string = """ | ||
__global__ void vector_add(float *c, float *a, float *b, int n) { | ||
int i = blockIdx.x * block_size_x + threadIdx.x; | ||
if (i<n) { | ||
c[i] = a[i] + b[i]; | ||
} | ||
} | ||
""" | ||
|
||
size = 10000000 | ||
|
||
a = numpy.random.randn(size).astype(numpy.float32) | ||
b = numpy.random.randn(size).astype(numpy.float32) | ||
c = numpy.zeros_like(b) | ||
n = numpy.int32(size) | ||
|
||
args = [c, a, b, n] | ||
|
||
tune_params = OrderedDict() | ||
tune_params["block_size_x"] = [128+64*i for i in range(15)] | ||
|
||
results, env = tune_kernel("vector_add", kernel_string, size, args, tune_params, lang="HIP", | ||
cache="vector_add_cache.json", log=logging.DEBUG) | ||
|
||
# Store the metadata of this run | ||
store_metadata_file("vector_add-metadata.json") | ||
|
||
return results | ||
|
||
|
||
if __name__ == "__main__": | ||
tune() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env python | ||
"""This is the minimal example from the README""" | ||
|
||
import numpy | ||
from kernel_tuner import tune_kernel | ||
from kernel_tuner.file_utils import store_output_file, store_metadata_file | ||
import logging | ||
from collections import OrderedDict | ||
import os | ||
|
||
def tune(): | ||
|
||
kernel_string = """ | ||
__global__ void vector_add(float *c, float *a, float *b, int n) { | ||
int i = blockIdx.x * block_size_x + threadIdx.x; | ||
if (i<n) { | ||
c[i] = a[i] + b[i]; | ||
} | ||
} | ||
""" | ||
|
||
size = 10000000 | ||
|
||
a = numpy.random.randn(size).astype(numpy.float32) | ||
b = numpy.random.randn(size).astype(numpy.float32) | ||
c = numpy.zeros_like(b) | ||
n = numpy.int32(size) | ||
|
||
args = [c, a, b, n] | ||
|
||
tune_params = OrderedDict() | ||
tune_params["block_size_x"] = [128+64*i for i in range(15)] | ||
|
||
filename = "vector_add_cache.json" | ||
if os.path.isfile(filename): | ||
results, env = tune_kernel("vector_add", kernel_string, size, args, tune_params, | ||
strategy="random_sample", strategy_options=dict(max_fevals=10), | ||
lang="HIP", simulation_mode=True, cache="vector_add_cache.json") | ||
|
||
else: | ||
print(f"{filename} does not exist in the directory, run vector_add.py first.") | ||
|
||
|
||
if __name__ == "__main__": | ||
tune() |
Oops, something went wrong.