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
aa384a5b
Commit
aa384a5b
authored
4 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
fix rank check for linear3d indexing
parent
28859ef6
No related branches found
No related tags found
1 merge request
!449
GPU Indexing Schemes and Launch Configurations
Pipeline
#74225
passed
4 months ago
Stage: Code Quality
Stage: Unit Tests
Stage: legacy_test
Stage: docs
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/pystencils/codegen/__init__.py
+2
-0
2 additions, 0 deletions
src/pystencils/codegen/__init__.py
src/pystencils/codegen/gpu_indexing.py
+8
-6
8 additions, 6 deletions
src/pystencils/codegen/gpu_indexing.py
tests/kernelcreation/test_gpu.py
+11
-1
11 additions, 1 deletion
tests/kernelcreation/test_gpu.py
with
21 additions
and
7 deletions
src/pystencils/codegen/__init__.py
+
2
−
0
View file @
aa384a5b
...
@@ -7,6 +7,7 @@ from .parameters import Parameter
...
@@ -7,6 +7,7 @@ from .parameters import Parameter
from
.kernel
import
Kernel
,
GpuKernel
from
.kernel
import
Kernel
,
GpuKernel
from
.driver
import
create_kernel
,
get_driver
from
.driver
import
create_kernel
,
get_driver
from
.functions
import
Lambda
from
.functions
import
Lambda
from
.errors
import
CodegenError
__all__
=
[
__all__
=
[
"
Target
"
,
"
Target
"
,
...
@@ -18,4 +19,5 @@ __all__ = [
...
@@ -18,4 +19,5 @@ __all__ = [
"
Lambda
"
,
"
Lambda
"
,
"
create_kernel
"
,
"
create_kernel
"
,
"
get_driver
"
,
"
get_driver
"
,
"
CodegenError
"
,
]
]
This diff is collapsed.
Click to expand it.
src/pystencils/codegen/gpu_indexing.py
+
8
−
6
View file @
aa384a5b
...
@@ -131,7 +131,7 @@ class ManualLaunchConfiguration(GpuLaunchConfiguration):
...
@@ -131,7 +131,7 @@ class ManualLaunchConfiguration(GpuLaunchConfiguration):
class
DynamicBlockSizeLaunchConfiguration
(
GpuLaunchConfiguration
):
class
DynamicBlockSizeLaunchConfiguration
(
GpuLaunchConfiguration
):
"""
GPU launch configuration that permits the user to set a block size and dynamically computes the grid size.
"""
GPU launch configuration that permits the user to set a block size and dynamically computes the grid size.
The actual launch grid size is computed from the user-defined ``user_block_size`` and the number of work items
The actual launch grid size is computed from the user-defined ``user_block_size`` and the number of work items
in the kernel
'
s iteration space as follows.
in the kernel
'
s iteration space as follows.
For each dimension :math:`c
\\
in
\\
{ x, y, z
\\
}`,
For each dimension :math:`c
\\
in
\\
{ x, y, z
\\
}`,
...
@@ -201,7 +201,7 @@ class DynamicBlockSizeLaunchConfiguration(GpuLaunchConfiguration):
...
@@ -201,7 +201,7 @@ class DynamicBlockSizeLaunchConfiguration(GpuLaunchConfiguration):
class
GpuIndexing
:
class
GpuIndexing
:
"""
Factory for GPU indexing objects required during code generation.
"""
Factory for GPU indexing objects required during code generation.
This class acts as a helper class for the code generation driver.
This class acts as a helper class for the code generation driver.
It produces both the `ThreadMapping` required by the backend,
It produces both the `ThreadMapping` required by the backend,
as well as factories for the launch configuration required later by the runtime system.
as well as factories for the launch configuration required later by the runtime system.
...
@@ -259,6 +259,12 @@ class GpuIndexing:
...
@@ -259,6 +259,12 @@ class GpuIndexing:
work_items_expr
=
self
.
_get_work_items
()
work_items_expr
=
self
.
_get_work_items
()
rank
=
len
(
work_items_expr
)
rank
=
len
(
work_items_expr
)
if
rank
>
3
:
raise
CodegenError
(
"
Cannot create a launch grid configuration using the Linear3D indexing scheme
"
f
"
for a
{
rank
}
-dimensional kernel.
"
)
num_work_items
=
cast
(
num_work_items
=
cast
(
_Dim3Lambda
,
_Dim3Lambda
,
tuple
(
Lambda
.
from_expression
(
self
.
_ctx
,
wit
)
for
wit
in
work_items_expr
),
tuple
(
Lambda
.
from_expression
(
self
.
_ctx
,
wit
)
for
wit
in
work_items_expr
),
...
@@ -328,10 +334,6 @@ class GpuIndexing:
...
@@ -328,10 +334,6 @@ class GpuIndexing:
match
ispace
:
match
ispace
:
case
FullIterationSpace
():
case
FullIterationSpace
():
dimensions
=
ispace
.
dimensions_in_loop_order
()[::
-
1
]
dimensions
=
ispace
.
dimensions_in_loop_order
()[::
-
1
]
if
len
(
dimensions
)
>
3
:
raise
NotImplementedError
(
f
"
Cannot create a GPU threads range for an
{
len
(
dimensions
)
}
-dimensional iteration space
"
)
from
..backend.ast.analysis
import
collect_undefined_symbols
as
collect
from
..backend.ast.analysis
import
collect_undefined_symbols
as
collect
...
...
This diff is collapsed.
Click to expand it.
tests/kernelcreation/test_gpu.py
+
11
−
1
View file @
aa384a5b
...
@@ -11,7 +11,6 @@ from pystencils import (
...
@@ -11,7 +11,6 @@ from pystencils import (
CreateKernelConfig
,
CreateKernelConfig
,
create_kernel
,
create_kernel
,
Target
,
Target
,
assignment_from_stencil
,
)
)
from
pystencils.slicing
import
(
from
pystencils.slicing
import
(
...
@@ -77,6 +76,17 @@ def test_indexing_options(
...
@@ -77,6 +76,17 @@ def test_indexing_options(
cp
.
testing
.
assert_allclose
(
dst_arr
,
expected
)
cp
.
testing
.
assert_allclose
(
dst_arr
,
expected
)
def
test_invalid_indexing_schemes
():
src
,
dst
=
fields
(
"
src, dst: [4D]
"
)
asm
=
Assignment
(
src
.
center
(
0
),
dst
.
center
(
0
))
cfg
=
CreateKernelConfig
(
target
=
Target
.
CUDA
)
cfg
.
gpu
.
indexing_scheme
=
"
linear3d
"
with
pytest
.
raises
(
Exception
):
create_kernel
(
asm
,
cfg
)
def
test_averaging_kernel
():
def
test_averaging_kernel
():
size
=
(
40
,
55
)
size
=
(
40
,
55
)
src_arr
=
np
.
random
.
rand
(
*
size
)
src_arr
=
np
.
random
.
rand
(
*
size
)
...
...
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