Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
6b3f5288
Commit
6b3f5288
authored
4 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
small extension to the user guide
parent
72793960
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!449
GPU Indexing Schemes and Launch Configurations
Pipeline
#74142
passed
4 months ago
Stage: Code Quality
Stage: Unit Tests
Stage: legacy_test
Stage: docs
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/source/user_manual/gpu_kernels.md
+32
-13
32 additions, 13 deletions
docs/source/user_manual/gpu_kernels.md
tests/kernelcreation/test_gpu.py
+1
-5
1 addition, 5 deletions
tests/kernelcreation/test_gpu.py
with
33 additions
and
18 deletions
docs/source/user_manual/gpu_kernels.md
+
32
−
13
View file @
6b3f5288
...
@@ -54,7 +54,19 @@ It extends {py:class}`Kernel` with some GPU-specific information.
...
@@ -54,7 +54,19 @@ It extends {py:class}`Kernel` with some GPU-specific information.
If a GPU is available and
[
CuPy
][
cupy
]
is installed in the current environment,
If a GPU is available and
[
CuPy
][
cupy
]
is installed in the current environment,
the kernel can be compiled and run immediately.
the kernel can be compiled and run immediately.
To execute the kernel, a {any}
`cupy.ndarray`
has to be passed for each field.
To execute the kernel, a {any}
`cupy.ndarray`
has to be passed for each field:
```
{code-cell} ipython3
:tags: [raises-exception]
import cupy as cp
rng = cp.random.default_rng(seed=42)
f_arr = rng.random((16, 16, 16))
g_arr = cp.zeros_like(f_arr)
kfunc = kernel.compile()
kfunc(f=f_arr, g=g_arr)
```
:::{note}
:::{note}
[
CuPy
][
cupy
]
is a Python library for numerical computations on GPU arrays,
[
CuPy
][
cupy
]
is a Python library for numerical computations on GPU arrays,
...
@@ -69,18 +81,6 @@ and to allocate and manage the data these kernels can be executed on.
...
@@ -69,18 +81,6 @@ and to allocate and manage the data these kernels can be executed on.
For more information on CuPy, refer to
[
their documentation
][
cupy-docs
]
.
For more information on CuPy, refer to
[
their documentation
][
cupy-docs
]
.
:::
:::
```
{code-cell} ipython3
:tags: [raises-exception]
import cupy as cp
rng = cp.random.default_rng(seed=42)
f_arr = rng.random((16, 16, 16))
g_arr = cp.zeros_like(f_arr)
kfunc = kernel.compile()
kfunc(f=f_arr, g=g_arr)
```
(indexing_and_launch_config)=
(indexing_and_launch_config)=
## Modify the Indexing Scheme and Launch Configuration
## Modify the Indexing Scheme and Launch Configuration
...
@@ -130,6 +130,25 @@ kfunc(f=f_arr, g=g_arr)
...
@@ -130,6 +130,25 @@ kfunc(f=f_arr, g=g_arr)
In any case. pystencils will automatically compute the grid size from the shapes of the kernel's array arguments
In any case. pystencils will automatically compute the grid size from the shapes of the kernel's array arguments
and the given thread block size.
and the given thread block size.
:::{attention}
According to the way GPU architecture splits thread blocks into warps,
pystencils will map the kernel's
*fastest*
spatial coordinate onto the
`x`
block and thread
indices, the second-fastest to
`y`
, and the slowest coordiante to
`z`
.
This can mean that, when using
`cupy`
arrays with the default memory layout
(corresponding to the
`"numpy"`
field layout specifier),
the
*thread coordinates*
and the
*spatial coordinates*
map to each other in
*opposite order*
; e.g.
| Spatial Coordinate | Thread Index |
|--------------------|---------------|
|
`x`
(slowest) |
`threadIdx.z`
|
|
`y`
|
`threadIdx.y`
|
|
`z`
(fastest) |
`threadIdx.x`
|
:::
(manual_launch_grids)=
(manual_launch_grids)=
### Manual Launch Grids and Non-Cuboid Iteration Patterns
### Manual Launch Grids and Non-Cuboid Iteration Patterns
...
...
This diff is collapsed.
Click to expand it.
tests/kernelcreation/test_gpu.py
+
1
−
5
View file @
6b3f5288
...
@@ -67,11 +67,7 @@ def test_indexing_options(
...
@@ -67,11 +67,7 @@ def test_indexing_options(
kernel
.
launch_config
.
grid_size
=
(
32
,
16
,
1
)
kernel
.
launch_config
.
grid_size
=
(
32
,
16
,
1
)
elif
indexing_scheme
==
"
linear3d
"
:
elif
indexing_scheme
==
"
linear3d
"
:
kernel
.
launch_config
.
block_size
=
(
kernel
.
launch_config
.
block_size
=
(
10
,
8
,
8
)
10
,
8
,
8
,
)
# must fit the src_arr shape (without ghost layers)
kernel
(
src
=
src_arr
,
dst
=
dst_arr
)
kernel
(
src
=
src_arr
,
dst
=
dst_arr
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment