diff --git a/src/pystencils/backend/platforms/cuda.py b/src/pystencils/backend/platforms/cuda.py index bf5b91b8228029cdcc9305be64a3879f3412b97d..ef3c115982b6a0470b761fed358a27cd98d8e5ed 100644 --- a/src/pystencils/backend/platforms/cuda.py +++ b/src/pystencils/backend/platforms/cuda.py @@ -28,7 +28,8 @@ from ..ast.expressions import ( from ..ast.expressions import PsLt, PsAnd from ...types import PsSignedIntegerType, PsIeeeFloatType from ..literals import PsLiteral -from ..functions import PsMathFunction, MathFunctions, CFunction, PsReductionFunction, ReductionFunctions +from ..functions import PsMathFunction, MathFunctions, CFunction, PsReductionFunction, ReductionFunctions, \ + NumericLimitsFunctions if TYPE_CHECKING: from ...codegen import GpuIndexingConfig, GpuThreadsRange @@ -64,7 +65,7 @@ class CudaPlatform(GenericGpu): @property def required_headers(self) -> set[str]: - return {'"gpu_defines.h"'} + return {'"gpu_defines.h"', "<cuda/std/limits>"} def materialize_iteration_space( self, body: PsBlock, ispace: IterationSpace @@ -83,6 +84,9 @@ class CudaPlatform(GenericGpu): dtype = call.get_dtype() arg_types = (dtype,) * func.num_args + if isinstance(dtype, PsScalarType) and func in (NumericLimitsFunctions.Min, NumericLimitsFunctions.Max): + return PsLiteralExpr(PsLiteral(f"::cuda::std::numeric_limits<{dtype.c_string()}>::{func.function_name}()", dtype)) + if isinstance(dtype, PsIeeeFloatType): match func: case (