Add checking function for whether a buffer is pinned
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 17 Nov 2017 18:58:39 +0000 (11:58 -0700)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 17 Nov 2017 18:59:43 +0000 (19:59 +0100)
This is useful for several kinds of tests proposed.

Change-Id: If9fdd29e73f16299190b5485f473f6388aab9ec9

src/gromacs/gpu_utils/gpu_utils.cu
src/gromacs/gpu_utils/gpu_utils.h

index 5e0afd3f2bea342689a7c3ac1d0d660f42bbf81a..fb509f5d37e16b964b275d4a828796948d6274b7 100644 (file)
@@ -134,6 +134,31 @@ static void checkCompiledTargetCompatibility(const gmx_device_info_t *devInfo)
     }
 }
 
+bool isHostMemoryPinned(void *h_ptr)
+{
+    cudaPointerAttributes memoryAttributes;
+    cudaError_t           stat = cudaPointerGetAttributes(&memoryAttributes, h_ptr);
+
+    bool                  result = false;
+    switch (stat)
+    {
+        case cudaSuccess:
+            result = true;
+            break;
+
+        case cudaErrorInvalidValue:
+            // If the buffer was not pinned, then it will not be recognized by CUDA at all
+            result = false;
+            // Reset the last error status
+            cudaGetLastError();
+            break;
+
+        default:
+            CU_RET_ERR(stat, "Unexpected CUDA error");
+    }
+    return result;
+}
+
 /*!
  * \brief Runs GPU sanity checks.
  *
index ad2297eae05f8cd33c4d86433aa22321e749e5cd..8f596304629b040b187576636d7bf997cdaf5a78 100644 (file)
@@ -242,5 +242,8 @@ void resetGpuProfiler(void) CUDA_FUNC_TERM
 CUDA_FUNC_QUALIFIER
 void stopGpuProfiler(void) CUDA_FUNC_TERM
 
+//! Tells whether the host buffer was pinned for non-blocking transfers. Only implemented for CUDA.
+CUDA_FUNC_QUALIFIER
+bool isHostMemoryPinned(void *CUDA_FUNC_ARGUMENT(h_ptr)) CUDA_FUNC_TERM_WITH_RETURN(false)
 
 #endif