Skip to content

Commit

Permalink
initial 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MaynardMiner committed Dec 8, 2018
1 parent 7387f87 commit 0713f5c
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
ARCH := $(shell getconf LONG_BIT)
OS := $(shell cat /etc/issue)
RHEL_OS := $(shell cat /etc/redhat-release)

# Gets Driver Branch
DRIVER_BRANCH := $(shell nvidia-smi | grep Driver | cut -f 3 -d' ' | cut -f 1 -d '.')

# Location of the CUDA Toolkit
CUDA_PATH ?= "/usr/local/cuda-8.0"

ifeq (${ARCH},$(filter ${ARCH},32 64))
# If correct architecture and libnvidia-ml library is not found
# within the environment, build using the stub library

ifneq (,$(findstring Ubuntu,$(OS)))
DEB := $(shell dpkg -l | grep cuda)
ifneq (,$(findstring cuda, $(DEB)))
NVML_LIB := /usr/lib/nvidia-$(DRIVER_BRANCH)
else
NVML_LIB := /lib${ARCH}
endif
endif

ifneq (,$(findstring SUSE,$(OS)))
RPM := $(shell rpm -qa cuda*)
ifneq (,$(findstring cuda, $(RPM)))
NVML_LIB := /usr/lib${ARCH}
else
NVML_LIB := /lib${ARCH}
endif
endif

ifneq (,$(findstring CentOS,$(RHEL_OS)))
RPM := $(shell rpm -qa cuda*)
ifneq (,$(findstring cuda, $(RPM)))
NVML_LIB := /usr/lib${ARCH}/nvidia
else
NVML_LIB := /lib${ARCH}
endif
endif

ifneq (,$(findstring Red Hat,$(RHEL_OS)))
RPM := $(shell rpm -qa cuda*)
ifneq (,$(findstring cuda, $(RPM)))
NVML_LIB := /usr/lib${ARCH}/nvidia
else
NVML_LIB := /lib${ARCH}
endif
endif

ifneq (,$(findstring Fedora,$(RHEL_OS)))
RPM := $(shell rpm -qa cuda*)
ifneq (,$(findstring cuda, $(RPM)))
NVML_LIB := /usr/lib${ARCH}/nvidia
else
NVML_LIB := /lib${ARCH}
endif
endif

else
NVML_LIB := ../../lib${ARCH}/stubs/
$(info "libnvidia-ml.so.1" not found, using stub library.)
endif

ifneq (${ARCH},$(filter ${ARCH},32 64))
$(error Unknown architecture!)
endif

NVML_LIB += /usr/local/cuda-10.0/lib64
NVML_LIB_L := $(addprefix -L , $(NVML_LIB))

CFLAGS := -I /usr/local/cuda-10.0/include
LDFLAGS := -lnvidia-ml $(NVML_LIB_L)

all: VII-smi
VII-smi: VII-smi.o
$(CC) $< $(CFLAGS) $(LDFLAGS) -o $@
clean:
-@rm -f VII-smi.o
-@rm -f VII-smi

55 changes: 55 additions & 0 deletions VII-smi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <stdio.h>
#include <nvml.h>

int main()
{
nvmlReturn_t result;
unsigned int device_count, i;

// First initialize NVML library
result = nvmlInit();
if (NVML_SUCCESS == result)
{
result = nvmlDeviceGetCount(&device_count);
if (NVML_SUCCESS == result)
{
for (i = 0; i < device_count; i++)
{
nvmlDevice_t device;
nvmlReturn_t result1;
nvmlReturn_t result2;
unsigned int fanspeed;
unsigned int temperature;
nvmlComputeMode_t sensor = 0;

result = nvmlDeviceGetHandleByIndex(i, &device);
if (NVML_SUCCESS == result)
{
result1 = nvmlDeviceGetFanSpeed(device, &fanspeed);
result2 = nvmlDeviceGetTemperature ( device, sensor, &temperature );
if(NVML_SUCCESS == result1)
{
printf("%i fan speed=%d\n", i, fanspeed);
}
else printf("Failed to get fan speed for device %i:\n", i);
if (NVML_SUCCESS == result2)
{
printf("%i temperature=%d\n", i, temperature);
}
else printf("Failed to get temperature for device %i\n", i);
}
else printf("Failed to get handle for device %i\n", i);
}
}
else printf("API failed\n");

result = nvmlShutdown();

if (NVML_SUCCESS != result)
{
printf("Warning: Failed to shutdown NVML\n");
}
}
return 0;
}

0 comments on commit 0713f5c

Please sign in to comment.