Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
nvidia-patch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
nvidia-patch
Commits
8efe984c
Commit
8efe984c
authored
Sep 28, 2019
by
Snawoot
Committed by
GitHub
Sep 28, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #163 from Snawoot/opmodes
Automation-friendly patch.sh
parents
9d889d63
2ca36928
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
55 deletions
+117
-55
README.md
README.md
+9
-6
patch.sh
patch.sh
+108
-49
No files found.
README.md
View file @
8efe984c
...
...
@@ -49,14 +49,17 @@ Requirements:
# bash ./patch.sh -h
SYNOPSIS
patch.sh [
OPTION]...
patch.sh [
-s] [-r|-h|-c VERSION|-l]
DESCRIPTION
The patch for Nvidia drivers to increase encoder sessions
-s Silent mode (No output)
-r Rollback to original (Restore lib from backup)
-h Print this help message
The patch for Nvidia drivers to remove NVENC session limit
-s Silent mode (No output)
-r Rollback to original (Restore lib from backup)
-h Print this help message
-c VERSION Check if version VERSION supported by this patch.
Returns true exit code (0) if version is supported.
-l List supported driver versions
```
...
...
patch.sh
View file @
8efe984c
...
...
@@ -6,29 +6,36 @@ set -euo pipefail ; # <- this semicolon and comment make options apply
backup_path
=
"/opt/nvidia/libnvidia-encode-backup"
silent_flag
=
''
rollback_flag
=
''
print_usage
()
{
printf
'
SYNOPSIS
patch.sh [
OPTION]...
patch.sh [
-s] [-r|-h|-c VERSION|-l]
DESCRIPTION
The patch for Nvidia drivers to
increase encoder sessions
The patch for Nvidia drivers to
remove NVENC session limit
-s Silent mode (No output)
-r Rollback to original (Restore lib from backup)
-h Print this help message
-s Silent mode (No output)
-r Rollback to original (Restore lib from backup)
-h Print this help message
-c VERSION Check if version VERSION supported by this patch.
Returns true exit code (0) if version is supported.
-l List supported driver versions
'
}
while
getopts
'rsh'
flag
;
do
case
"
${
flag
}
"
in
r
)
rollback_flag
=
'true'
;;
s
)
silent_flag
=
'true'
;;
*
)
print_usage
exit
1
;;
esac
# shellcheck disable=SC2209
opmode
=
"patch"
while
getopts
'rshc:l'
flag
;
do
case
"
${
flag
}
"
in
r
)
opmode
=
"
${
opmode
}
rollback"
;;
s
)
silent_flag
=
'true'
;;
h
)
opmode
=
"
${
opmode
}
help"
;;
c
)
opmode
=
"
${
opmode
}
checkversion"
;
checked_version
=
"
$OPTARG
"
;;
l
)
opmode
=
"
${
opmode
}
listversions"
;;
*
)
echo
"Incorrect option specified in command line"
;
exit
2
;;
esac
done
if
[[
$silent_flag
]]
;
then
...
...
@@ -105,56 +112,84 @@ declare -A object_list=(
[
"435.21"
]=
'libnvcuvid.so'
)
NVIDIA_SMI
=
"
$(
command
-v
nvidia-smi
)
"
if
!
driver_version
=
$(
"
$NVIDIA_SMI
"
--query-gpu
=
driver_version
--format
=
csv,noheader,nounits |
head
-n
1
)
;
then
echo
'Something went wrong. Check nvidia driver'
exit
1
;
fi
echo
"Detected nvidia driver version:
$driver_version
"
check_version_supported
()
{
local
ver
=
"
$1
"
[[
"
${
patch_list
[
$ver
]+isset
}
"
&&
"
${
object_list
[
$ver
]+isset
}
"
]]
}
if
[[
!
"
${
patch_list
[
$driver_version
]+isset
}
"
||
!
"
${
object_list
[
$driver_version
]+isset
}
"
]]
;
then
echo
"Patch for this (
$driver_version
) nvidia driver not found."
1>&2
echo
"Available patches for: "
1>&2
get_supported_versions
()
{
for
drv
in
"
${
!patch_list[@]
}
"
;
do
echo
"
$drv
"
1>&2
done
exit
1
;
fi
[[
"
${
object_list
[
$drv
]+isset
}
"
]]
&&
echo
"
$drv
"
done
|
sort
-t
.
-n
return
0
}
patch
=
"
${
patch_list
[
$driver_version
]
}
"
object
=
"
${
object_list
[
$driver_version
]
}
"
patch_common
()
{
NVIDIA_SMI
=
"
$(
command
-v
nvidia-smi
||
true
)
"
if
[[
!
"
$NVIDIA_SMI
"
]]
;
then
echo
'nvidia-smi utility not found. Probably driver is not installed.'
exit
1
fi
declare
-a
driver_locations
=(
'/usr/lib/x86_64-linux-gnu'
'/usr/lib/x86_64-linux-gnu/nvidia/current/'
'/usr/lib64'
"/usr/lib/nvidia-
${
driver_version
%%.*
}
"
)
if
!
driver_version
=
$(
"
$NVIDIA_SMI
"
--query-gpu
=
driver_version
--format
=
csv,noheader,nounits |
head
-n
1
)
;
then
echo
'Something went wrong. Check nvidia driver'
exit
1
fi
dir_found
=
''
for
driver_dir
in
"
${
driver_locations
[@]
}
"
;
do
if
[[
-e
"
$driver_dir
/
$object
.
$driver_version
"
]]
;
then
dir_found
=
'true'
break
echo
"Detected nvidia driver version:
$driver_version
"
if
!
check_version_supported
"
$driver_version
"
;
then
echo
"Patch for this (
$driver_version
) nvidia driver not found."
echo
"Patch is available for versions: "
get_supported_versions
exit
1
fi
done
[[
"
$dir_found
"
]]
||
{
echo
"ERROR: cannot detect driver directory"
;
exit
1
;
}
patch
=
"
${
patch_list
[
$driver_version
]
}
"
object
=
"
${
object_list
[
$driver_version
]
}
"
declare
-a
driver_locations
=(
'/usr/lib/x86_64-linux-gnu'
'/usr/lib/x86_64-linux-gnu/nvidia/current/'
'/usr/lib64'
"/usr/lib/nvidia-
${
driver_version
%%.*
}
"
)
dir_found
=
''
for
driver_dir
in
"
${
driver_locations
[@]
}
"
;
do
if
[[
-e
"
$driver_dir
/
$object
.
$driver_version
"
]]
;
then
dir_found
=
'true'
break
fi
done
[[
"
$dir_found
"
]]
||
{
echo
"ERROR: cannot detect driver directory"
;
exit
1
;
}
if
[[
$rollback_flag
]]
;
then
}
rollback
()
{
patch_common
if
[[
-f
"
$backup_path
/
$object
.
$driver_version
"
]]
;
then
cp
-p
"
$backup_path
/
$object
.
$driver_version
"
\
"
$driver_dir
/
$object
.
$driver_version
"
echo
"Restore from backup
$object
.
$driver_version
"
else
echo
"Backup not found. Try to patch first."
exit
1
;
exit
1
fi
else
if
[[
!
-f
"
$backup_path
/
$object
.
$driver_version
"
]]
;
then
echo
"Attention! Backup not found. Copy current
$object
to backup."
}
patch
()
{
patch_common
if
[[
-f
"
$backup_path
/
$object
.
$driver_version
"
]]
;
then
bkp_hash
=
"
$(
sha1sum
"
$backup_path
/
$object
.
$driver_version
"
|
cut
-f1
-d
\
)
"
drv_hash
=
"
$(
sha1sum
"
$driver_dir
/
$object
.
$driver_version
"
|
cut
-f1
-d
\
)
"
if
[[
"
$bkp_hash
"
!=
"
$drv_hash
"
]]
;
then
echo
"Backup exists and driver file differ from backup. Skipping patch."
return
0
fi
else
echo
"Attention! Backup not found. Copying current
$object
to backup."
mkdir
-p
"
$backup_path
"
cp
-p
"
$driver_dir
/
$object
.
$driver_version
"
\
"
$backup_path
/
$object
.
$driver_version
"
...
...
@@ -165,4 +200,28 @@ else
sha1sum
"
${
PATCH_OUTPUT_DIR
-
$driver_dir
}
/
$object
.
$driver_version
"
ldconfig
echo
"Patched!"
fi
}
query_version_support
()
{
if
check_version_supported
"
$checked_version
"
;
then
echo
"SUPPORTED"
exit
0
else
echo
"NOT SUPPORTED"
exit
1
fi
}
list_supported_versions
()
{
get_supported_versions
}
case
"
${
opmode
}
"
in
patch
)
patch
;;
patchrollback
)
rollback
;;
patchhelp
)
print_usage
;
exit
2
;;
patchcheckversion
)
query_version_support
;;
patchlistversions
)
list_supported_versions
;;
*
)
echo
"Incorrect combination of flags. Use option -h to get help."
exit
2
;;
esac
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment