X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=blobdiff_plain;f=src%2Fgromacs%2Fgpu_utils%2Fsycl_kernel_utils.h;h=aba31db05351b8ca1d83937c98d64fd1761f0af1;hb=01449308f91c3f4ab9cac235fef076e6aac1fa9a;hp=544c9e2b13236021dda8eeef37919d77eb25bf2c;hpb=eb74bfa4c8a28798caf8cb5bb5fa922d87829d62;p=alexxy%2Fgromacs.git diff --git a/src/gromacs/gpu_utils/sycl_kernel_utils.h b/src/gromacs/gpu_utils/sycl_kernel_utils.h index 544c9e2b13..aba31db053 100644 --- a/src/gromacs/gpu_utils/sycl_kernel_utils.h +++ b/src/gromacs/gpu_utils/sycl_kernel_utils.h @@ -144,6 +144,113 @@ static inline float shift_right(sycl_2020::sub_group sg, float var, sycl_2020::s return sg.shuffle_up(var, delta); } #endif + +#if GMX_SYCL_HIPSYCL +/*! \brief Polyfill for sycl::isfinite missing from hipSYCL + * + * Does not follow GROMACS style because it should follow the name for + * which it is a polyfill. */ +template +__device__ __host__ static inline bool isfinite(Real value) +{ + // This is not yet implemented in hipSYCL pending + // https://github.com/illuhad/hipSYCL/issues/636 +# ifdef SYCL_DEVICE_ONLY +# if defined(HIPSYCL_PLATFORM_CUDA) && defined(__HIPSYCL_ENABLE_CUDA_TARGET__) + return isfinite(value); +# elif defined(HIPSYCL_PLATFORM_ROCM) && defined(__HIPSYCL_ENABLE_HIP_TARGET__) + return isfinite(value); +# else +# error "Unsupported hipSYCL target" +# endif +# else + // Should never be called + assert(false); + GMX_UNUSED_VALUE(value); + return false; +# endif +} +#elif GMX_SYCL_DPCPP +template +static inline bool isfinite(Real value) +{ + return cl::sycl::isfinite(value); +} + +#endif + +#if GMX_SYCL_HIPSYCL + +/*! \brief Polyfill for sycl::vec::load buggy in hipSYCL + * + * Loads from the address \c ptr offset in elements of type T by + * NumElements * offset, into the components of \c v. + * + * Can probably be removed when + * https://github.com/illuhad/hipSYCL/issues/647 is resolved. */ +template +static inline void loadToVec(size_t offset, + cl::sycl::multi_ptr ptr, + cl::sycl::vec* v) +{ + for (int i = 0; i < NumElements; ++i) + { + (*v)[i] = ptr.get()[offset * NumElements + i]; + } +} + +/*! \brief Polyfill for sycl::vec::store buggy in hipSYCL + * + * Loads from the address \c ptr offset in elements of type T by + * NumElements * offset, into the components of \c v. + * + * Can probably be removed when + * https://github.com/illuhad/hipSYCL/issues/647 is resolved. */ +template +static inline void storeFromVec(const cl::sycl::vec& v, + size_t offset, + cl::sycl::multi_ptr ptr) +{ + for (int i = 0; i < NumElements; ++i) + { + ptr.get()[offset * NumElements + i] = v[i]; + } +} + +#elif GMX_SYCL_DPCPP + +/*! \brief Polyfill for sycl::vec::load buggy in hipSYCL + * + * Loads from the address \c ptr offset in elements of type T by + * NumElements * offset, into the components of \c v. + * + * Can probably be removed when + * https://github.com/illuhad/hipSYCL/issues/647 is resolved. */ +template +static inline void loadToVec(size_t offset, + cl::sycl::multi_ptr ptr, + cl::sycl::vec* v) +{ + v->load(offset, ptr); +} + +/*! \brief Polyfill for sycl::vec::store buggy in hipSYCL + * + * Loads from the address \c ptr offset in elements of type T by + * NumElements * offset, into the components of \c v. + * + * Can probably be removed when + * https://github.com/illuhad/hipSYCL/issues/647 is resolved. */ +template +static inline void storeFromVec(const cl::sycl::vec& v, + size_t offset, + cl::sycl::multi_ptr ptr) +{ + v.store(offset, ptr); +} + +#endif + } // namespace sycl_2020 #endif /* GMX_GPU_UTILS_SYCL_KERNEL_UTILS_H */