From 7d971661e902b81a6b3f760b10d42c0b65e9cd29 Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Fri, 17 Nov 2017 11:58:39 -0700 Subject: [PATCH] Add checking function for whether a buffer is pinned This is useful for several kinds of tests proposed. Change-Id: If9fdd29e73f16299190b5485f473f6388aab9ec9 --- src/gromacs/gpu_utils/gpu_utils.cu | 25 +++++++++++++++++++++++++ src/gromacs/gpu_utils/gpu_utils.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/src/gromacs/gpu_utils/gpu_utils.cu b/src/gromacs/gpu_utils/gpu_utils.cu index 5e0afd3f2b..fb509f5d37 100644 --- a/src/gromacs/gpu_utils/gpu_utils.cu +++ b/src/gromacs/gpu_utils/gpu_utils.cu @@ -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. * diff --git a/src/gromacs/gpu_utils/gpu_utils.h b/src/gromacs/gpu_utils/gpu_utils.h index ad2297eae0..8f59630462 100644 --- a/src/gromacs/gpu_utils/gpu_utils.h +++ b/src/gromacs/gpu_utils/gpu_utils.h @@ -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 -- 2.22.0