Add GMX_OCL_SHOW_DIAGNOSTICS env option
authorRoland Schulz <roland.schulz@intel.com>
Sat, 28 Apr 2018 01:20:33 +0000 (18:20 -0700)
committerRoland Schulz <roland.schulz@intel.com>
Tue, 19 Feb 2019 09:18:14 +0000 (01:18 -0800)
Change-Id: Ie886544d40ff78fccd301b87d610ae8c42483b14

docs/user-guide/environment-variables.rst
src/gromacs/nbnxm/opencl/nbnxm_ocl_data_mgmt.cpp

index ebfbe22ffa8875a48539908382af154b19812325..9549a9d6286df907ca69b1309bac7762238ab315 100644 (file)
@@ -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``
index 72be7654413da5ea4753ca1e78cd9b474cab67a4..3ee147cfd47deb954208fdfc0d23f97f81b05597 100644 (file)
 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<cl_context_properties>(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<cl_context_properties>(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",