Part of the problem is that you're using $(nvidia-smi ...)
instead of $(shell nvidia-smi ...)
. That's easily solved.
You also have to use $$2
instead of just $2
to prevent make
from expanding it (probably expanding to nothing, resulting in the awk expression being just {print }
and printing the entire line).
e.g. with a minimalist Makefile
:
all:
CUDA="$(shell nvidia-smi -q | awk -F': ' '/CUDA Version/ {print $$2}')"
Note the colon followed by space in awk's -F
field separator.
$ make
CUDA="Not Found"
This is actually the correct value for my system, I don't have CUDA installed.
BTW, it's important to realise that while some make syntax looks a bit like shell syntax, it's very different....and, worse, the similarities can make it easy to write buggy makefiles.
See Makefile: how to sed correctly to edit a variable for a good answer relevant to your question.
On a more general note, you will probably find the output of nvidia-smi -q
to be much easier to process with awk (or sed
or perl
or whatever).
e.g. on my system:
$ nvidia-smi -q | grep -i version
Driver Version : 460.56
CUDA Version : Not Found
VBIOS Version : 86.06.0E.00.38
Inforom Version
Image Version : G001.0000.01.03
$ nvidia-smi -q | awk -F': ' '/CUDA Version/ {print $2}'
Not Found
I don't have CUDA stuff installed, so I just get "not found". I can get a useful result for Driver Version:
$ nvidia-smi -q | awk -F': ' '/Driver Version/ {print $2}'
460.56
nvidia-smi
also has various --query-gpu
options. e.g.
$ nvidia-smi --query-gpu=driver_version,vbios_version --format=csv
driver_version, vbios_version
460.56, 86.06.0E.00.38
Oddly, CUDA version isn't one of the query-gpu
options. See nvidia-smi --help-query-gpu
for full details.