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
777ab888
Commit
777ab888
authored
4 months ago
by
Richard Angersbach
Browse files
Options
Downloads
Patches
Plain Diff
Use literals for C macros used for the numeric limits
parent
3e0daa67
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/generic_cpu.py
+20
-6
20 additions, 6 deletions
src/pystencils/backend/platforms/generic_cpu.py
with
20 additions
and
6 deletions
src/pystencils/backend/platforms/generic_cpu.py
+
20
−
6
View file @
777ab888
...
@@ -4,6 +4,7 @@ from typing import Sequence
...
@@ -4,6 +4,7 @@ from typing import Sequence
from
pystencils.backend.ast.expressions
import
PsCall
from
pystencils.backend.ast.expressions
import
PsCall
from
..functions
import
CFunction
,
PsMathFunction
,
MathFunctions
,
NumericLimitsFunctions
from
..functions
import
CFunction
,
PsMathFunction
,
MathFunctions
,
NumericLimitsFunctions
from
..literals
import
PsLiteral
from
...types
import
PsIntegerType
,
PsIeeeFloatType
,
PsScalarType
from
...types
import
PsIntegerType
,
PsIeeeFloatType
,
PsScalarType
from
.platform
import
Platform
from
.platform
import
Platform
...
@@ -25,7 +26,7 @@ from ..ast.expressions import (
...
@@ -25,7 +26,7 @@ from ..ast.expressions import (
PsLookup
,
PsLookup
,
PsGe
,
PsGe
,
PsLe
,
PsLe
,
PsTernary
,
PsTernary
,
PsLiteralExpr
,
)
)
from
..ast.vector
import
PsVecMemAcc
from
..ast.vector
import
PsVecMemAcc
from
...types
import
PsVectorType
,
PsCustomType
from
...types
import
PsVectorType
,
PsCustomType
...
@@ -43,7 +44,7 @@ class GenericCpu(Platform):
...
@@ -43,7 +44,7 @@ class GenericCpu(Platform):
@property
@property
def
required_headers
(
self
)
->
set
[
str
]:
def
required_headers
(
self
)
->
set
[
str
]:
return
{
"
<math.h>
"
,
"
<limits.h>
"
}
return
{
"
<math.h>
"
,
"
<limits.h>
"
,
"
<float.h>
"
}
def
materialize_iteration_space
(
def
materialize_iteration_space
(
self
,
body
:
PsBlock
,
ispace
:
IterationSpace
self
,
body
:
PsBlock
,
ispace
:
IterationSpace
...
@@ -63,12 +64,25 @@ class GenericCpu(Platform):
...
@@ -63,12 +64,25 @@ class GenericCpu(Platform):
arg_types
=
(
dtype
,)
*
func
.
num_args
arg_types
=
(
dtype
,)
*
func
.
num_args
if
isinstance
(
dtype
,
PsScalarType
)
and
func
in
(
NumericLimitsFunctions
.
Min
,
NumericLimitsFunctions
.
Max
):
if
isinstance
(
dtype
,
PsScalarType
)
and
func
in
(
NumericLimitsFunctions
.
Min
,
NumericLimitsFunctions
.
Max
):
cfunc
:
CFunction
# get type prefix for macro
cfunc
=
CFunction
(
f
"
{
dtype
.
c_string
()
}
_
{
func
.
function_name
}
"
.
capitalize
(),
arg_types
,
dtype
)
# TODO: there must be a better way...
call
.
function
=
cfunc
tpe
=
""
return
call
match
dtype
:
case
PsIeeeFloatType
():
match
dtype
.
width
:
case
32
:
tpe
=
"
FLT
"
case
64
:
tpe
=
"
DBL
"
case
_
:
raise
MaterializationError
(
f
"
No implementation available for function
{
func
}
on data type
{
dtype
}
"
)
return
PsLiteralExpr
(
PsLiteral
(
f
"
{
tpe
}
_
{
func
.
function_name
}
"
.
upper
(),
dtype
))
if
isinstance
(
dtype
,
PsIeeeFloatType
)
and
dtype
.
width
in
(
32
,
64
):
if
isinstance
(
dtype
,
PsIeeeFloatType
)
and
dtype
.
width
in
(
32
,
64
):
cfunc
:
CFunction
match
func
:
match
func
:
case
(
case
(
MathFunctions
.
Exp
MathFunctions
.
Exp
...
...
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