From ee1361286bfdf327cc309f025bab35eaa0387895 Mon Sep 17 00:00:00 2001 From: Andrey Alekseenko Date: Thu, 8 Oct 2020 10:20:57 +0000 Subject: [PATCH] Add explicit types to NB kernel type enums So these enums could be used in template parameters --- src/gromacs/gpu_utils/devicebuffer_datatype.h | 10 ++- src/gromacs/gpu_utils/devicebuffer_sycl.h | 17 +++++ src/gromacs/gpu_utils/gpu_macros.h | 74 ++++++++----------- src/gromacs/nbnxm/nbnxm_gpu.h | 4 +- 4 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/gromacs/gpu_utils/devicebuffer_datatype.h b/src/gromacs/gpu_utils/devicebuffer_datatype.h index e88782b1ac..b4be8bd619 100644 --- a/src/gromacs/gpu_utils/devicebuffer_datatype.h +++ b/src/gromacs/gpu_utils/devicebuffer_datatype.h @@ -110,8 +110,14 @@ struct DeviceBuffer //! Helper function to get the size in bytes of a single element static constexpr size_t elementSize() { return sizeof(ValueType); } - // static_case is used in MPI+CUDA code, this stub is necessary for compilation. - explicit operator void*() const { throw; } + // Both explicit and implicit casts to void* are used in MPI+CUDA code, this stub is necessary for compilation. + operator void*() const { throw; } + + //! Allow implicit conversion to bool to check buffer status for compatibility with other implementations. + operator bool() const { return buffer_.get() != nullptr; } + + //! An assignment operator to allow resetting buffer by assigning nullptr to it. Necessery for compilation. + DeviceBuffer& operator=(std::nullptr_t nullPtr); }; // Must explicitly instantiate for some types. diff --git a/src/gromacs/gpu_utils/devicebuffer_sycl.h b/src/gromacs/gpu_utils/devicebuffer_sycl.h index 63a3b16fb8..a75e238448 100644 --- a/src/gromacs/gpu_utils/devicebuffer_sycl.h +++ b/src/gromacs/gpu_utils/devicebuffer_sycl.h @@ -99,6 +99,23 @@ DeviceBuffer& DeviceBuffer::operator=(DeviceBuffer const& src) template DeviceBuffer& DeviceBuffer::operator=(DeviceBuffer&& src) noexcept = default; +/*! \brief Dummy assignment operator to allow compilation of some cross-platform code. + * + * A hacky way to make SYCL implementation of DeviceBuffer compatible with details of CUDA and + * OpenCL implementations. + * + * \todo Should be removed after DeviceBuffer refactoring. + * + * \tparam T Type of buffer content. + * \param nullPtr \c std::nullptr. Not possible to assign any other pointers. + */ +template +DeviceBuffer& DeviceBuffer::operator=(std::nullptr_t nullPtr) +{ + buffer_.reset(nullPtr); + return *this; +} + #endif // #ifndef DOXYGEN /*! \libinternal \brief diff --git a/src/gromacs/gpu_utils/gpu_macros.h b/src/gromacs/gpu_utils/gpu_macros.h index e7ecf83f57..1bfbefd0a7 100644 --- a/src/gromacs/gpu_utils/gpu_macros.h +++ b/src/gromacs/gpu_utils/gpu_macros.h @@ -74,63 +74,47 @@ # define OPENCL_FUNC_TERM REAL_FUNC_TERM # define OPENCL_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg) -#elif GMX_GPU_OPENCL || GMX_GPU_CUDA - -/* GPU support is enabled, so these functions will have real code - * defined somewhere */ -# define GPU_FUNC_QUALIFIER REAL_FUNC_QUALIFIER -# define GPU_FUNC_ARGUMENT REAL_FUNC_ARGUMENT -# define GPU_FUNC_TERM REAL_FUNC_TERM -# define GPU_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg) +#else // Not DOXYGEN + +/* GPU support is enabled, so these functions will have real code defined somewhere */ +# if GMX_GPU && !GMX_GPU_SYCL +# define GPU_FUNC_QUALIFIER REAL_FUNC_QUALIFIER +# define GPU_FUNC_ARGUMENT REAL_FUNC_ARGUMENT +# define GPU_FUNC_TERM REAL_FUNC_TERM +# define GPU_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg) +# else +# define GPU_FUNC_QUALIFIER NULL_FUNC_QUALIFIER +# define GPU_FUNC_ARGUMENT NULL_FUNC_ARGUMENT +# define GPU_FUNC_TERM NULL_FUNC_TERM +# define GPU_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) +# +# endif +/* Enable and disable platform-specific function implementations */ # if GMX_GPU_OPENCL - -/* OpenCL support is enabled, so CUDA-specific functions need empty - * implementations, while OpenCL-specific functions will have real - * code defined somewhere. */ -# define CUDA_FUNC_QUALIFIER NULL_FUNC_QUALIFIER -# define CUDA_FUNC_ARGUMENT NULL_FUNC_ARGUMENT -# define CUDA_FUNC_TERM NULL_FUNC_TERM -# define CUDA_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) # define OPENCL_FUNC_QUALIFIER REAL_FUNC_QUALIFIER # define OPENCL_FUNC_ARGUMENT REAL_FUNC_ARGUMENT # define OPENCL_FUNC_TERM REAL_FUNC_TERM # define OPENCL_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg) - +# else +# define OPENCL_FUNC_QUALIFIER NULL_FUNC_QUALIFIER +# define OPENCL_FUNC_ARGUMENT NULL_FUNC_ARGUMENT +# define OPENCL_FUNC_TERM NULL_FUNC_TERM +# define OPENCL_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) # endif -# if GMX_GPU_CUDA -/* CUDA support is enabled, so OpenCL-specific functions need empty - * implementations, while CUDA-specific functions will have real - * code defined somewhere. */ +# if GMX_GPU_CUDA # define CUDA_FUNC_QUALIFIER REAL_FUNC_QUALIFIER # define CUDA_FUNC_ARGUMENT REAL_FUNC_ARGUMENT # define CUDA_FUNC_TERM REAL_FUNC_TERM # define CUDA_FUNC_TERM_WITH_RETURN(arg) REAL_FUNC_TERM_WITH_RETURN(arg) -# define OPENCL_FUNC_QUALIFIER NULL_FUNC_QUALIFIER -# define OPENCL_FUNC_ARGUMENT NULL_FUNC_ARGUMENT -# define OPENCL_FUNC_TERM NULL_FUNC_TERM -# define OPENCL_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) - +# else +# define CUDA_FUNC_QUALIFIER NULL_FUNC_QUALIFIER +# define CUDA_FUNC_ARGUMENT NULL_FUNC_ARGUMENT +# define CUDA_FUNC_TERM NULL_FUNC_TERM +# define CUDA_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) # endif -#elif !GMX_GPU || GMX_GPU_SYCL - -/* No GPU support is configured, so none of these functions will have - * real definitions. */ -# define GPU_FUNC_QUALIFIER NULL_FUNC_QUALIFIER -# define GPU_FUNC_ARGUMENT NULL_FUNC_ARGUMENT -# define GPU_FUNC_TERM NULL_FUNC_TERM -# define GPU_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) -# define CUDA_FUNC_QUALIFIER NULL_FUNC_QUALIFIER -# define CUDA_FUNC_ARGUMENT NULL_FUNC_ARGUMENT -# define CUDA_FUNC_TERM NULL_FUNC_TERM -# define CUDA_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) -# define OPENCL_FUNC_QUALIFIER NULL_FUNC_QUALIFIER -# define OPENCL_FUNC_ARGUMENT NULL_FUNC_ARGUMENT -# define OPENCL_FUNC_TERM NULL_FUNC_TERM -# define OPENCL_FUNC_TERM_WITH_RETURN(arg) NULL_FUNC_TERM_WITH_RETURN(arg) - -#endif +#endif // ifdef DOXYGEN -#endif +#endif // GMX_GPU_UTILS_MACROS_H diff --git a/src/gromacs/nbnxm/nbnxm_gpu.h b/src/gromacs/nbnxm/nbnxm_gpu.h index 00e7ae11f5..600bd20a62 100644 --- a/src/gromacs/nbnxm/nbnxm_gpu.h +++ b/src/gromacs/nbnxm/nbnxm_gpu.h @@ -76,7 +76,7 @@ class StepWorkload; * nbnxn_cuda.cu by the nb_*_kfunc_ptr function pointer table * should match the order of enumerated types below. */ -enum eelType +enum eelType : int { eelTypeCUT, eelTypeRF, @@ -96,7 +96,7 @@ enum eelType * nbnxn_cuda_ocl.cpp/.cu by the nb_*_kfunc_ptr function pointer table * should match the order of enumerated types below. */ -enum evdwType +enum evdwType : int { evdwTypeCUT, evdwTypeCUTCOMBGEOM, -- 2.22.0