Quellcode durchsuchen

Add starpu_cuda_get_nvmldev function.

Samuel Thibault vor 4 Jahren
Ursprung
Commit
c689d70e5e
5 geänderte Dateien mit 33 neuen und 5 gelöschten Zeilen
  1. 1 0
      ChangeLog
  2. 1 1
      configure.ac
  3. 8 0
      include/starpu_config.h.in
  4. 12 0
      include/starpu_cuda.h
  5. 11 4
      src/drivers/cuda/driver_cuda.c

+ 1 - 0
ChangeLog

@@ -70,6 +70,7 @@ Small features:
     instead of hyperthreads.
   * New STARPU_TASK_PROGRESS environment variable to show task progression.
   * Add STARPU_SIMGRID environment variable guard against native builds.
+  * Add starpu_cuda_get_nvmldev function.
 
 StarPU 1.3.7
 ====================================================================

+ 1 - 1
configure.ac

@@ -1409,7 +1409,7 @@ if test x$enable_cuda = xyes; then
 		AC_CHECK_DECLS([nvmlDeviceGetTotalEnergyConsumption], [
 			AC_CHECK_FUNCS([nvmlDeviceGetTotalEnergyConsumption])
 			], [], [[#include <nvml.h>]])
-		AC_DEFINE([HAVE_LIBNVIDIA_ML], [1], [Define to 1 if you have the nvidia-ml library])
+		AC_DEFINE([STARPU_HAVE_LIBNVIDIA_ML], [1], [Define to 1 if you have the nvidia-ml library])
 		STARPU_CUDA_LDFLAGS="$STARPU_CUDA_LDFLAGS -lnvidia-ml"
 	fi
 	AC_MSG_CHECKING(whether nvidia-ml should be used)

+ 8 - 0
include/starpu_config.h.in

@@ -57,6 +57,14 @@
 #undef STARPU_USE_CUDA
 
 /**
+   Defined when StarPU has been installed with
+   NVidia-ML support. It should be used in your code to detect the
+   availability of NVML-related functions.
+   @ingroup API_CUDA_Extensions
+*/
+#undef STARPU_HAVE_LIBNVIDIA_ML
+
+/**
    Defined when StarPU has been installed with OpenCL support. It
    should be used in your code to detect the availability of OpenCL as
    shown in \ref FullSourceCodeVectorScal.

+ 12 - 0
include/starpu_cuda.h

@@ -24,6 +24,10 @@
 #include <cuda_runtime.h>
 #include <cuda_runtime_api.h>
 
+#ifdef STARPU_HAVE_LIBNVIDIA_ML
+#include <nvml.h>
+#endif
+
 #ifdef __cplusplus
 extern "C"
 {
@@ -129,6 +133,14 @@ int starpu_cuda_copy3d_async_sync(void *src_ptr, unsigned src_node, void *dst_pt
 */
 void starpu_cuda_set_device(unsigned devid);
 
+#ifdef STARPU_HAVE_LIBNVIDIA_ML
+/**
+  Return the nvml device for a CUDA device
+*/
+nvmlDevice_t starpu_cuda_get_nvmldev(unsigned devid);
+#endif
+
+
 /** @} */
 
 #ifdef __cplusplus

+ 11 - 4
src/drivers/cuda/driver_cuda.c

@@ -31,7 +31,7 @@
 #ifdef HAVE_CUDA_GL_INTEROP_H
 #include <cuda_gl_interop.h>
 #endif
-#ifdef HAVE_LIBNVIDIA_ML
+#ifdef STARPU_HAVE_LIBNVIDIA_ML
 #include <nvml.h>
 #endif
 #include <datawizard/memory_manager.h>
@@ -63,7 +63,7 @@
 static int ncudagpus = -1;
 
 static size_t global_mem[STARPU_MAXCUDADEVS];
-#ifdef HAVE_LIBNVIDIA_ML
+#ifdef STARPU_HAVE_LIBNVIDIA_ML
 static nvmlDevice_t nvmlDev[STARPU_MAXCUDADEVS];
 #endif
 int _starpu_cuda_bus_ids[STARPU_MAXCUDADEVS+STARPU_MAXNUMANODES][STARPU_MAXCUDADEVS+STARPU_MAXNUMANODES];
@@ -105,6 +105,13 @@ static size_t _starpu_cuda_get_global_mem_size(unsigned devid)
 	return global_mem[devid];
 }
 
+#ifdef STARPU_HAVE_LIBNVIDIA_ML
+nvmlDevice_t starpu_cuda_get_nvmldev(unsigned devid)
+{
+	return nvmlDev[devid];
+}
+#endif
+
 void
 _starpu_cuda_discover_devices (struct _starpu_machine_config *config)
 {
@@ -120,7 +127,7 @@ _starpu_cuda_discover_devices (struct _starpu_machine_config *config)
 	if (STARPU_UNLIKELY(cures != cudaSuccess))
 		cnt = 0;
 	config->topology.nhwdevices[STARPU_CUDA_WORKER] = cnt;
-#ifdef HAVE_LIBNVIDIA_ML
+#ifdef STARPU_HAVE_LIBNVIDIA_ML
 	nvmlInit();
 #endif
 #endif
@@ -738,7 +745,7 @@ int _starpu_cuda_driver_init(struct _starpu_worker_set *worker_set)
 
 #if defined(STARPU_HAVE_BUSID) && !defined(STARPU_SIMGRID)
 #if defined(STARPU_HAVE_DOMAINID) && !defined(STARPU_SIMGRID)
-#ifdef HAVE_LIBNVIDIA_ML
+#ifdef STARPU_HAVE_LIBNVIDIA_ML
 		char busid[13];
 		snprintf(busid, sizeof(busid), "%04x:%02x:%02x.0", props[devid].pciDomainID, props[devid].pciBusID, props[devid].pciDeviceID);
 		nvmlDeviceGetHandleByPciBusId(busid, &nvmlDev[devid]);