Add explicit types to NB kernel type enums
authorAndrey Alekseenko <al42and@gmail.com>
Thu, 8 Oct 2020 10:20:57 +0000 (10:20 +0000)
committerArtem Zhmurov <zhmurov@gmail.com>
Thu, 8 Oct 2020 10:20:57 +0000 (10:20 +0000)
So these enums could be used in template parameters

src/gromacs/gpu_utils/devicebuffer_datatype.h
src/gromacs/gpu_utils/devicebuffer_sycl.h
src/gromacs/gpu_utils/gpu_macros.h
src/gromacs/nbnxm/nbnxm_gpu.h

index e88782b1ac807e7169b9e1ae3507231204a5b8bd..b4be8bd619821f891e593d6c33638a4e8479f73c 100644 (file)
@@ -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<void*> 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.
index 63a3b16fb8f9cda6f3bfebb464c80fcd72c9cba7..a75e238448cb6cd3023fafa7edbe2c0cf0c17f47 100644 (file)
@@ -99,6 +99,23 @@ DeviceBuffer<T>& DeviceBuffer<T>::operator=(DeviceBuffer<T> const& src)
 template<typename T>
 DeviceBuffer<T>& DeviceBuffer<T>::operator=(DeviceBuffer<T>&& 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<typename T>
+DeviceBuffer<T>& DeviceBuffer<T>::operator=(std::nullptr_t nullPtr)
+{
+    buffer_.reset(nullPtr);
+    return *this;
+}
+
 #endif // #ifndef DOXYGEN
 
 /*! \libinternal \brief
index e7ecf83f57683d28cb95fe93eb717ee48eb20837..1bfbefd0a75735bc77ab622215338eb9c790ac60 100644 (file)
 #    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
index 00e7ae11f5a1240b351033e622ba615314957eab..600bd20a62d7e27165604de21e2a6d6efd8b6298 100644 (file)
@@ -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,