From 8bc740887cf4d47f86084043220e7a637e362c2b Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Fri, 27 Apr 2018 18:20:33 -0700 Subject: [PATCH] Add GMX_OCL_SHOW_DIAGNOSTICS env option Change-Id: Ie886544d40ff78fccd301b87d610ae8c42483b14 --- docs/user-guide/environment-variables.rst | 4 +++ .../nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp | 36 ++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/user-guide/environment-variables.rst b/docs/user-guide/environment-variables.rst index ebfbe22ffa..9549a9d628 100644 --- a/docs/user-guide/environment-variables.rst +++ b/docs/user-guide/environment-variables.rst @@ -485,6 +485,10 @@ compilation of OpenCL kernels, but they are also used in device selection. and allows testing the OpenCL kernels on non-supported platforms (like Intel iGPUs) without source code modification. +``GMX_OCL_SHOW_DIAGNOSTICS`` + Use Intel OpenCL extension to show additional runtime performance + diagnostics. + Analysis and Core Functions --------------------------- ``GMX_QM_ACCURACY`` diff --git a/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp b/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp index 72be765441..3ee147cfd4 100644 --- a/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp +++ b/src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp @@ -79,6 +79,15 @@ namespace Nbnxm { +/*! \brief Copies of values from cl_driver_diagnostics_intel.h, + * which isn't guaranteed to be available. */ +/**@{*/ +#define CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL 0x4106 +#define CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL 0x1 +#define CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL 0x2 +#define CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL 0x4 +/**@}*/ + /*! \brief This parameter should be determined heuristically from the * kernel execution times * @@ -473,6 +482,17 @@ static void init_timings(gmx_wallclock_gpu_nbnxn_t *t) t->dynamicPruneTime.t = 0.0; } + +//! OpenCL notification callback function +static void CL_CALLBACK +ocl_notify_fn( const char *pErrInfo, const void *, size_t, void *) +{ + if (pErrInfo != NULL) + { + printf("%s\n", pErrInfo ); // Print error/hint + } +} + /*! \brief Creates context for OpenCL GPU given by \p mygpu * * A fatal error results if creation fails. @@ -486,7 +506,7 @@ nbnxn_gpu_create_context(gmx_device_runtime_data_t *runtimeData, const gmx_device_info_t *devInfo, int rank) { - cl_context_properties context_properties[3]; + cl_context_properties context_properties[5]; cl_platform_id platform_id; cl_device_id device_id; cl_context context; @@ -498,11 +518,17 @@ nbnxn_gpu_create_context(gmx_device_runtime_data_t *runtimeData, platform_id = devInfo->ocl_gpu_id.ocl_platform_id; device_id = devInfo->ocl_gpu_id.ocl_device_id; - context_properties[0] = CL_CONTEXT_PLATFORM; - context_properties[1] = reinterpret_cast(platform_id); - context_properties[2] = 0; /* Terminates the list of properties */ + int i = 0; + context_properties[i++] = CL_CONTEXT_PLATFORM; + context_properties[i++] = reinterpret_cast(platform_id); + if (getenv("GMX_OCL_SHOW_DIAGNOSTICS")) + { + context_properties[i++] = CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL; + context_properties[i++] = CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL | CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL; + } + context_properties[i++] = 0; /* Terminates the list of properties */ - context = clCreateContext(context_properties, 1, &device_id, nullptr, nullptr, &cl_error); + context = clCreateContext(context_properties, 1, &device_id, ocl_notify_fn, nullptr, &cl_error); if (CL_SUCCESS != cl_error) { gmx_fatal(FARGS, "On rank %d failed to create context for GPU #%s:\n OpenCL error %d: %s", -- 2.22.0