Skip to content
Snippets Groups Projects
Commit 856c5a6e authored by floreal.risso's avatar floreal.risso
Browse files

auto config nvidia

parent 22721bfe
No related branches found
No related tags found
2 merge requests!9fix sensor example (doc),!5Add dev name to labels
......@@ -4,12 +4,15 @@
# Copyright (C) 2023-2023 Georges Da Costa <georges.da-costa@irit.fr>
try() { "$@" || die "cannot $*"; }
die() { yell "$*"; exit 111; }
die() {
yell "$*"
exit 111
}
yell() { echo "$0: $*" >&2; }
echo() { printf '%s\n' "$*"; }
isnum() {
case "${1#[+-]}" in
*[!0-9]*|'') return 1 ;;
*[!0-9]* | '') return 1 ;;
*) return 0 ;;
esac
}
......@@ -51,7 +54,7 @@ ls_sensors() {
ls -1 *.h |
grep -xEv "($hdr_blacklist)\.h" |
grep -xE "($hdr_whitelist)\.h" |
grep -xE "($hdr_whitelist)\.h" |
sed 's/\.h$//'
}
......@@ -86,10 +89,10 @@ gen_sensors_h() {
printf ' int opt_idx = offset;\n'
for sensor in $sensors; do
cat <<-!
for (int i = 0; i < ${sensor}.nb_opt; i++) {
opts[opt_idx++] = ${sensor}_opt[i];
}
sensors[(*nb_defined)++] = ${sensor};
for (int i = 0; i < ${sensor}.nb_opt; i++) {
opts[opt_idx++] = ${sensor}_opt[i];
}
sensors[(*nb_defined)++] = ${sensor};
!
done
printf ' assert((offset + *nb_defined) <= len);\n'
......@@ -117,6 +120,8 @@ detect_caps() {
if [ -e /usr/local/cuda/lib64 ] && [ -e /usr/local/cuda/include ]; then
hdr_whitelist="${hdr_whitelist}|nvidia_gpu"
NVML_LDFLAGS="-L/usr/local/cuda/lib64 -lnvidia-ml"
NVML_IFLAGS="-I/usr/local/cuda/include"
fi
vendor=$(awk '/vendor_id/ {print $3; exit}' /proc/cpuinfo)
......@@ -140,7 +145,7 @@ detect_caps() {
}
case $1 in
--all|-a)
--all | -a)
all=1
;;
esac
......@@ -148,30 +153,33 @@ esac
[ "$all" ] || detect_caps
[ "$all" ] ||
while [ "$1" ]; do
case $1 in
--include|-i)
shift; [ "$1" ] || usage
hdr_whitelist="${hdr_whitelist}|${1}"
;;
--exclude|-e)
shift; [ "$1" ] || usage
hdr_blacklist="${hdr_blacklist}|${1}"
;;
--list-sensors|-l)
ls_sensors
exit 0
;;
--unique|-u)
shift; [ "$1" ] || usage
hdr_whitelist=$1
;;
--help|-h)
usage
;;
esac
shift
done
while [ "$1" ]; do
case $1 in
--include | -i)
shift
[ "$1" ] || usage
hdr_whitelist="${hdr_whitelist}|${1}"
;;
--exclude | -e)
shift
[ "$1" ] || usage
hdr_blacklist="${hdr_blacklist}|${1}"
;;
--list-sensors | -l)
ls_sensors
exit 0
;;
--unique | -u)
shift
[ "$1" ] || usage
hdr_whitelist=$1
;;
--help | -h)
usage
;;
esac
shift
done
sensors=$(ls_sensors)
nb_sensors=$(echo "$sensors" | sed '/^$/d' | wc -l)
......@@ -181,12 +189,13 @@ if [ "$nb_sensors" -eq 0 ]; then
exit 1
fi
try gen_sensors_h "$sensors" "$nb_sensors" > "$target_hdr"
try gen_sensors_mk "$sensors" > "$target_mk"
try gen_sensors_h "$sensors" "$nb_sensors" >"$target_hdr"
try gen_sensors_mk "$sensors" >"$target_mk"
try printf "LDFLAGS += %s\n" "$NVML_LDFLAGS" >>"$target_mk"
try printf "IFLAGS += %s\n" "$NVML_IFLAGS" >>"$target_mk"
printf -- 'Run `make` to build `bin/mojitos`.\n' >&2
printf -- 'The resulting binary will have the %d following sensors:\n' "$nb_sensors" >&2
echo "$sensors" >&2
make clean >/dev/null
......@@ -9,6 +9,8 @@ TESTS_DIR = tests
BIN = mojitos
CAPTOR_OBJ =
IFLAGS =
LDFLAGS =
include ./sensors.mk
......@@ -17,9 +19,9 @@ OBJ = \
$(OBJ_DIR)/util.o
CC = gcc
CPPFLAGS = -std=gnu99 -Wall -Wextra -Wpedantic -Wno-unused-function -I./lib -I/usr/local/cuda/include
CPPFLAGS = -std=gnu99 -Wall -Wextra -Wpedantic -Wno-unused-function -I./lib $(IFLAGS)
CFLAGS = $(CPPFLAGS) -O3 -Werror
LDFLAGS = -L/usr/local/cuda/lib64 -lnvidia-ml
LDFLAGS +=
ASTYLE = astyle --style=kr -xf -s4 -k3 -n -Z -Q
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment