-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7387f87
commit 0713f5c
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|