GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Adding numba-HIP examples · amd/HPCTrainingExamples@5268f05

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Python/hip-python
    • README.md
    • numba-hip-cuda-posing.py
    • numba-hip.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Python/hip-python/README.md‎

Copy file name to clipboardExpand all lines: Python/hip-python/README.md
+56Lines changed: 56 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -858,4 +858,60 @@ python3 kernel_with_args.py
858858
```
859859

860860

861+
## numba-HIP
861862

863+
A simple numba-HIP vector addition example
864+
865+
```
866+
from numba import hip
867+
868+
@hip.jit
869+
def f(a, b, c):
870+
# like threadIdx.x + (blockIdx.x * blockDim.x)
871+
tid = hip.grid(1)
872+
size = len(c)
873+
874+
if tid < size:
875+
c[tid] = a[tid] + b[tid]
876+
877+
print("Ok")
878+
```
879+
880+
To run the example
881+
882+
```
883+
module load rocm hip-python
884+
python3 numba-hip.py
885+
```
886+
887+
An alternative approach to changing all the `@cuda.jit` to `@hip.jit` is to have
888+
numba-hip pose as CUDA. We do this with the addition of the following two lines:
889+
890+
```
891+
hip.pose_as_cuda()
892+
from numba import cuda
893+
```
894+
```
895+
from numba import hip
896+
897+
hip.pose_as_cuda()
898+
from numba import cuda
899+
900+
@cuda.jit
901+
def f(a, b, c):
902+
# like threadIdx.x + (blockIdx.x * blockDim.x)
903+
tid = cuda.grid(1)
904+
size = len(c)
905+
906+
if tid < size:
907+
c[tid] = a[tid] + b[tid]
908+
909+
print("Ok")
910+
```
911+
912+
Running this example
913+
914+
```
915+
module load rocm hip-python
916+
python3 numba-hip-cuda-posing.py
917+
```
Collapse file

‎Python/hip-python/numba-hip-cuda-posing.py‎

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from numba import hip
2+
3+
hip.pose_as_cuda()
4+
from numba import cuda
5+
6+
@cuda.jit
7+
def f(a, b, c):
8+
# like threadIdx.x + (blockIdx.x * blockDim.x)
9+
tid = cuda.grid(1)
10+
size = len(c)
11+
12+
if tid < size:
13+
c[tid] = a[tid] + b[tid]
14+
15+
print("Ok")
Collapse file

‎Python/hip-python/numba-hip.py‎

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from numba import hip
2+
3+
@hip.jit
4+
def f(a, b, c):
5+
# like threadIdx.x + (blockIdx.x * blockDim.x)
6+
tid = hip.grid(1)
7+
size = len(c)
8+
9+
if tid < size:
10+
c[tid] = a[tid] + b[tid]
11+
12+
print("Ok")

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.