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
ce816539
Commit
ce816539
authored
4 months ago
by
Richard Angersbach
Browse files
Options
Downloads
Patches
Plain Diff
Encapsulate fetching of kernel conditions for iteration spaces in separate function
parent
d10c65d4
No related branches found
No related tags found
1 merge request
!438
Reduction Support
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pystencils/backend/platforms/cuda.py
+42
-13
42 additions, 13 deletions
src/pystencils/backend/platforms/cuda.py
with
42 additions
and
13 deletions
src/pystencils/backend/platforms/cuda.py
+
42
−
13
View file @
ce816539
...
...
@@ -315,13 +315,47 @@ class CudaPlatform(GenericGpu):
# Internals
# TODO: SYCL platform has very similar code for fetching conditionals -> move to GenericGPU?
def
_get_condition_for_translation
(
self
,
ispace
:
IterationSpace
):
if
not
self
.
_omit_range_check
:
return
None
match
ispace
:
case
FullIterationSpace
():
dimensions
=
ispace
.
dimensions_in_loop_order
()
conds
=
[]
for
dim
in
dimensions
:
ctr_expr
=
PsExpression
.
make
(
dim
.
counter
)
conds
.
append
(
PsLt
(
ctr_expr
,
dim
.
stop
))
if
conds
:
condition
:
PsExpression
=
conds
[
0
]
for
cond
in
conds
[
1
:]:
condition
=
PsAnd
(
condition
,
cond
)
return
condition
else
:
return
None
case
SparseIterationSpace
():
sparse_ctr_expr
=
PsExpression
.
make
(
ispace
.
sparse_counter
)
stop
=
PsExpression
.
make
(
ispace
.
index_list
.
shape
[
0
])
return
PsLt
(
sparse_ctr_expr
.
clone
(),
stop
)
case
_
:
assert
False
,
"
Unknown iteration space
"
def
_prepend_dense_translation
(
self
,
body
:
PsBlock
,
ispace
:
FullIterationSpace
)
->
PsBlock
:
ctr_mapping
=
self
.
_thread_mapping
(
ispace
)
indexing_decls
=
[]
cond
s
=
[]
cond
=
self
.
_get_condition_for_translation
(
ispace
)
dimensions
=
ispace
.
dimensions_in_loop_order
()
...
...
@@ -335,14 +369,9 @@ class CudaPlatform(GenericGpu):
indexing_decls
.
append
(
self
.
_typify
(
PsDeclaration
(
ctr_expr
,
ctr_mapping
[
dim
.
counter
]))
)
if
not
self
.
_omit_range_check
:
conds
.
append
(
PsLt
(
ctr_expr
,
dim
.
stop
))
if
conds
:
condition
:
PsExpression
=
conds
[
0
]
for
cond
in
conds
[
1
:]:
condition
=
PsAnd
(
condition
,
cond
)
ast
=
PsBlock
(
indexing_decls
+
[
PsConditional
(
condition
,
body
)])
if
cond
:
ast
=
PsBlock
(
indexing_decls
+
[
PsConditional
(
cond
,
body
)])
else
:
body
.
statements
=
indexing_decls
+
body
.
statements
ast
=
body
...
...
@@ -355,6 +384,8 @@ class CudaPlatform(GenericGpu):
factory
=
AstFactory
(
self
.
_ctx
)
ispace
.
sparse_counter
.
dtype
=
constify
(
ispace
.
sparse_counter
.
get_dtype
())
cond
=
self
.
_get_condition_for_translation
(
ispace
)
sparse_ctr_expr
=
PsExpression
.
make
(
ispace
.
sparse_counter
)
ctr_mapping
=
self
.
_thread_mapping
(
ispace
)
...
...
@@ -377,10 +408,8 @@ class CudaPlatform(GenericGpu):
]
body
.
statements
=
mappings
+
body
.
statements
if
not
self
.
_omit_range_check
:
stop
=
PsExpression
.
make
(
ispace
.
index_list
.
shape
[
0
])
condition
=
PsLt
(
sparse_ctr_expr
.
clone
(),
stop
)
ast
=
PsBlock
([
sparse_idx_decl
,
PsConditional
(
condition
,
body
)])
if
cond
:
ast
=
PsBlock
([
sparse_idx_decl
,
PsConditional
(
cond
,
body
)])
else
:
body
.
statements
=
[
sparse_idx_decl
]
+
body
.
statements
ast
=
body
...
...
This diff is collapsed.
Click to expand it.
Frederik Hennig
@da15siwa
mentioned in commit
4e688b86
·
1 month ago
mentioned in commit
4e688b86
mentioned in commit 4e688b867339c90a6fba3ad12c383d1e59211ed9
Toggle commit list
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