From 6284c1d2825ea171d35b5fde8801ed5a640be2ac Mon Sep 17 00:00:00 2001 From: Frederik Hennig <frederik.hennig@fau.de> Date: Thu, 6 Mar 2025 14:52:10 +0100 Subject: [PATCH] Some cleanup to the pystencils runtime headers - Remove ancient `PyStencilsField.h` - move half-precision and HIP-specific integer typedefs to `pystencils_runtime/*.h` directory - remove `INFINITY` macros since they cause redefinition errors with nvcc and hipcc --- src/pystencils/backend/platforms/cuda.py | 2 +- src/pystencils/include/PyStencilsField.h | 19 ------------------- .../half.h} | 0 .../hip.h} | 4 ---- src/pystencils/jit/gpu_cupy.py | 4 ++-- src/pystencils/types/types.py | 4 ++-- 6 files changed, 5 insertions(+), 28 deletions(-) delete mode 100644 src/pystencils/include/PyStencilsField.h rename src/pystencils/include/{half_precision.h => pystencils_runtime/half.h} (100%) rename src/pystencils/include/{gpu_defines.h => pystencils_runtime/hip.h} (56%) diff --git a/src/pystencils/backend/platforms/cuda.py b/src/pystencils/backend/platforms/cuda.py index e896fc2bb..d630594ba 100644 --- a/src/pystencils/backend/platforms/cuda.py +++ b/src/pystencils/backend/platforms/cuda.py @@ -188,7 +188,7 @@ class CudaPlatform(GenericGpu): @property def required_headers(self) -> set[str]: - return {'"gpu_defines.h"'} + return {'"pystencils_runtime/hip.h"'} # TODO: move to HipPlatform once it is introduced def materialize_iteration_space( self, body: PsBlock, ispace: IterationSpace diff --git a/src/pystencils/include/PyStencilsField.h b/src/pystencils/include/PyStencilsField.h deleted file mode 100644 index 3055cae23..000000000 --- a/src/pystencils/include/PyStencilsField.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -extern "C++" { -#ifdef __CUDA_ARCH__ -template <typename DTYPE_T, std::size_t DIMENSION> struct PyStencilsField { - DTYPE_T *data; - DTYPE_T shape[DIMENSION]; - DTYPE_T stride[DIMENSION]; -}; -#else -#include <array> - -template <typename DTYPE_T, std::size_t DIMENSION> struct PyStencilsField { - DTYPE_T *data; - std::array<DTYPE_T, DIMENSION> shape; - std::array<DTYPE_T, DIMENSION> stride; -}; -#endif -} diff --git a/src/pystencils/include/half_precision.h b/src/pystencils/include/pystencils_runtime/half.h similarity index 100% rename from src/pystencils/include/half_precision.h rename to src/pystencils/include/pystencils_runtime/half.h diff --git a/src/pystencils/include/gpu_defines.h b/src/pystencils/include/pystencils_runtime/hip.h similarity index 56% rename from src/pystencils/include/gpu_defines.h rename to src/pystencils/include/pystencils_runtime/hip.h index 67e7722e9..4bf4917f8 100644 --- a/src/pystencils/include/gpu_defines.h +++ b/src/pystencils/include/pystencils_runtime/hip.h @@ -1,9 +1,5 @@ #pragma once -#define POS_INFINITY __int_as_float(0x7f800000) -#define INFINITY POS_INFINITY -#define NEG_INFINITY __int_as_float(0xff800000) - #ifdef __HIPCC_RTC__ typedef __hip_uint8_t uint8_t; typedef __hip_int8_t int8_t; diff --git a/src/pystencils/jit/gpu_cupy.py b/src/pystencils/jit/gpu_cupy.py index 1c771a427..d45abf878 100644 --- a/src/pystencils/jit/gpu_cupy.py +++ b/src/pystencils/jit/gpu_cupy.py @@ -250,8 +250,8 @@ class CupyJit(JitBase): headers = self._runtime_headers headers |= kfunc.required_headers - if '"half_precision.h"' in headers: - headers.remove('"half_precision.h"') + if '"pystencils_runtime/half.h"' in headers: + headers.remove('"pystencils_runtime/half.h"') if cp.cuda.runtime.is_hip: headers.add("<hip/hip_fp16.h>") else: diff --git a/src/pystencils/types/types.py b/src/pystencils/types/types.py index 825ac1d5d..8dea97ca4 100644 --- a/src/pystencils/types/types.py +++ b/src/pystencils/types/types.py @@ -661,7 +661,7 @@ class PsIeeeFloatType(PsScalarType): @property def required_headers(self) -> set[str]: if self._width == 16: - return {'"half_precision.h"'} + return {'"pystencils_runtime/half.h"'} else: return set() @@ -672,7 +672,7 @@ class PsIeeeFloatType(PsScalarType): match self.width: case 16: - return f"((half) {value})" # see include/half_precision.h + return f"((half) {value})" # see include/pystencils_runtime/half.h case 32: return f"{value}f" case 64: -- GitLab