Skip to content

Commit

Permalink
Merge pull request #745 from roflcoopter/feature/postgres-rolename-10
Browse files Browse the repository at this point in the history
Upgrade OpenCL and VAA-API
  • Loading branch information
roflcoopter authored May 8, 2024
2 parents a5a498f + 61f3004 commit 05f5167
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 24 deletions.
9 changes: 5 additions & 4 deletions azure-pipelines/.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ MAKEFLAGS="-j 5"
PYTHON_VERSION="3.10.12"
PYTHON_GPG_KEY=A035C8C19219BA821ECEA86B64E628F8D684696D
PYTHON_PIP_VERSION="20.0.2"
OPENCL_VERSION="23.09.25812.14"
GMMLIB_VERSION="22.3.0"
IGC_VERSION="1.0.13463.18"
LEVEL_ZERO_GPU="1.3.25812.14"
OPENCL_VERSION="24.13.29138.7"
GMMLIB_VERSION="22.3.18"
IGC_VERSION="1.0.16510.2"
LEVEL_ZERO_GPU="1.3.29138.7"
OPENCL_SHA256_FILENAME="ww13"
JETSON_NANO_UBUNTU_VERSION="bionic"
JETPACK_VERSION_MAJOR=32
JETPACK_VERSION_MINOR=7
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines/docker-compose-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ services:
GMMLIB_VERSION: "$GMMLIB_VERSION"
IGC_VERSION: "$IGC_VERSION"
LEVEL_ZERO_GPU: "$LEVEL_ZERO_GPU"
OPENCL_SHA256_FILENAME: "$OPENCL_SHA256_FILENAME"
context: ..
dockerfile: ./docker/amd64/Dockerfile.base
cache_from:
Expand Down Expand Up @@ -239,6 +240,7 @@ services:
GMMLIB_VERSION: "$GMMLIB_VERSION"
IGC_VERSION: "$IGC_VERSION"
LEVEL_ZERO_GPU: "$LEVEL_ZERO_GPU"
OPENCL_SHA256_FILENAME: "$OPENCL_SHA256_FILENAME"
cache_from:
- roflcoopter/amd64-cuda-base:$BASE_VERSION
image: roflcoopter/amd64-cuda-base:$BASE_VERSION
Expand Down
20 changes: 16 additions & 4 deletions docker/amd64-cuda/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,35 @@ ARG OPENCL_VERSION
ARG GMMLIB_VERSION
ARG IGC_VERSION
ARG LEVEL_ZERO_GPU
ARG OPENCL_SHA256_FILENAME
ARG UBUNTU_VERSION_NUMBER
ARG OPENVINO_VERSION

ENV \
NVIDIA_DRIVER_CAPABILITIES=all \
NVIDIA_VISIBLE_DEVICES=all

RUN apt-get update && apt-get install -y --no-install-recommends \
RUN . /etc/os-release \
&& apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
wget \
gpg \
gpg-agent \
&& wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \
gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg \
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu ${VERSION_CODENAME}/lts/2350 unified" | \
tee /etc/apt/sources.list.d/intel-gpu-${VERSION_CODENAME}.list

RUN apt-get update && apt-get install -y --no-install-recommends \
# VA-API
vainfo \
intel-media-va-driver-non-free \
libva-drm2 \
libva2 \
i965-va-driver \
i965-va-driver-shaders \
mesa-va-drivers \
mesa-vdpau-drivers \
mesa-vulkan-drivers \
libmfx1 \
radeontop \
intel-gpu-tools \
Expand All @@ -56,8 +68,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/intel-level-zero-gpu_${LEVEL_ZERO_GPU}_amd64.deb --progress=bar:force:noscroll && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/intel-opencl-icd_${OPENCL_VERSION}_amd64.deb --progress=bar:force:noscroll && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/libigdgmm12_${GMMLIB_VERSION}_amd64.deb --progress=bar:force:noscroll && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/ww09.sum --progress=bar:force:noscroll && \
sha256sum --ignore-missing -c ww09.sum && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/${OPENCL_SHA256_FILENAME}.sum --progress=bar:force:noscroll && \
sha256sum --ignore-missing -c ${OPENCL_SHA256_FILENAME}.sum && \
dpkg -i *.deb && \
rm -R /opencl && \
# Add NVIDIA to OpenCL runtime
Expand Down
17 changes: 10 additions & 7 deletions docker/amd64/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ ARG OPENCL_VERSION
ARG GMMLIB_VERSION
ARG IGC_VERSION
ARG LEVEL_ZERO_GPU
ARG OPENCL_SHA256_FILENAME
ARG UBUNTU_VERSION_NUMBER
ARG OPENVINO_VERSION

RUN apt-get update && apt-get install -y \
RUN . /etc/os-release \
&& apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
wget \
gpg \
gpg-agent \
&& wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | \
&& wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \
gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg \
&& echo 'deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu focal main' | \
tee /etc/apt/sources.list.d/intel.gpu.focal.list
&& echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu ${VERSION_CODENAME}/lts/2350 unified" | \
tee /etc/apt/sources.list.d/intel-gpu-${VERSION_CODENAME}.list

RUN apt-get update && apt-get install -y --no-install-recommends \
# VA-API
Expand All @@ -29,7 +32,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
intel-media-va-driver-non-free \
libva-drm2 \
libva2 \
i965-va-driver \
i965-va-driver-shaders \
mesa-va-drivers \
mesa-vdpau-drivers \
mesa-vulkan-drivers \
Expand Down Expand Up @@ -59,8 +62,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/intel-level-zero-gpu_${LEVEL_ZERO_GPU}_amd64.deb --progress=bar:force:noscroll && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/intel-opencl-icd_${OPENCL_VERSION}_amd64.deb --progress=bar:force:noscroll && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/libigdgmm12_${GMMLIB_VERSION}_amd64.deb --progress=bar:force:noscroll && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/ww09.sum --progress=bar:force:noscroll && \
sha256sum --ignore-missing -c ww09.sum && \
wget https://github.com/intel/compute-runtime/releases/download/${OPENCL_VERSION}/${OPENCL_SHA256_FILENAME}.sum --progress=bar:force:noscroll && \
sha256sum --ignore-missing -c ${OPENCL_SHA256_FILENAME}.sum && \
dpkg -i *.deb && \
rm -R /opencl && \
ln -s /detectors/models/darknet/yolov7.weights /detectors/models/darknet/default.weights && \
Expand Down
11 changes: 9 additions & 2 deletions docs/src/pages/components-explorer/components/darknet/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ If you want to force `darknet` to run on OpenCL even if you have an NVIDIA GPU y
```yaml
darknet:
object_detector:
dnn_backend: openvino
dnn_backend: opencv
dnn_target: opencl
```

Expand All @@ -207,10 +207,17 @@ darknet:
#### Intel CPUs with integrated GPUs

If you are running on an Intel CPU with integrated GPU, you can use the `roflcoopter/amd64-viseron` image.
It will automatically use OpenCV with OpenVINO and OpenCL for object detection.
It will automatically use OpenCV with OpenCL for object detection.

The `dnn_backend` and `dnn_target` controls how the model runs.

:::warning

Since upgrading to Ubuntu 22.04, OpenCV 4.9.0 and OpenVINO 2023.3, the `openvino` backend is broken and causes segmentation faults.
Hopefully this will be resolved in future updates of the libraries.

:::

:::info
When not running on CUDA, OpenCVs implementation of Darknet is used.
:::
Expand Down
7 changes: 5 additions & 2 deletions rootfs/etc/cont-init.d/40-set-env-vars
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export HOME=/home/abc
printf "/home/abc" > /var/run/environment/HOME

# Find latest version of postgresql
export PG_BIN="$(find /usr/lib/postgresql -maxdepth 1 -type d | sort -V | tail -n 1)/bin"
export PG_VERSION=$(pg_config --version | awk '{print $2}' | awk -F'.' '{print $1}')
export PG_BIN="/usr/lib/postgresql/$PG_VERSION/bin"
printf "$PG_VERSION" > /var/run/environment/PG_VERSION
printf "$PG_BIN" > /var/run/environment/PG_BIN
log_info "Found PostgreSQL bin: $PG_BIN"
log_info "PostgreSQL major version: $PG_VERSION"
log_info "PostgreSQL bin: $PG_BIN"
log_info "*********************** Done *****************************"
28 changes: 25 additions & 3 deletions rootfs/etc/cont-init.d/80-postgres
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ create_db() {

upgrade_db() {
old_version=$(cat $PGDATA/PG_VERSION)
log_info "Upgrading database to new PostgreSQL version..."
log_warning "Upgrading database to new PostgreSQL version..."

log_info "Installing PostgreSQL $old_version..."
echo "deb https://apt.postgresql.org/pub/repos/apt ${UBUNTU_CODENAME}-pgdg main" > /etc/apt/sources.list.d/pgdg.list
Expand All @@ -46,6 +46,27 @@ upgrade_db() {
chown postgres:abc $new_db_path
init_db $new_db_path false

# Make sure that the rolname for oid 10 is postgres
# In previous versions the database superuser was set to abc which breaks pg_upgrade
log_info "Starting PostgreSQL..."
s6-setuidgid postgres /usr/lib/postgresql/$old_version/bin/pg_ctl -D $PGDATA -l $PGDATA/logfile start
PG_SUPERUSER=$(s6-setuidgid postgres psql -q -d viseron -tc "SELECT rolname FROM pg_roles WHERE oid = 10;" | xargs)
if [ "$PG_SUPERUSER" != "postgres" ]; then
log_info "Changing superuser role name to postgres..."
log_info "Creating temporary superuser..."
s6-setuidgid postgres psql -d viseron -c 'CREATE ROLE "temp" WITH SUPERUSER CREATEDB CREATEROLE REPLICATION BYPASSRLS LOGIN;'
log_info "Dropping old postgres user..."
s6-setuidgid postgres psql -d viseron -U temp -c 'DROP ROLE "postgres";'
log_info "Renaming old superuser to postgres..."
s6-setuidgid postgres psql -d viseron -U temp -c "ALTER ROLE $PG_SUPERUSER RENAME TO postgres;"
log_info "Dropping temporary superuser..."
s6-setuidgid postgres psql -d viseron -c 'DROP ROLE "temp";'
log_info "Create abc user"
s6-setuidgid postgres createuser abc
fi
log_info "Stopping PostgreSQL..."
s6-setuidgid postgres /usr/lib/postgresql/$old_version/bin/pg_ctl -D $PGDATA -l $PGDATA/logfile stop

log_info "Running pg_upgrade..."
cd $new_db_path
s6-setuidgid postgres $PG_BIN/pg_upgrade -b /usr/lib/postgresql/$old_version/bin -B $PG_BIN -d $PGDATA -D $new_db_path
Expand All @@ -63,8 +84,9 @@ upgrade_db() {

if [ -e $PGDATA/postgresql.conf ]; then
log_info "Database has already been initialized."
if [ "$(cat $PGDATA/PG_VERSION)" != "14" ]; then
log_info "Database version is not 14."
DATABASE_VERSION=$(cat $PGDATA/PG_VERSION)
if [ $DATABASE_VERSION != $PG_VERSION ]; then
log_warning "Database version ($DATABASE_VERSION) is not the same as the installed PostgreSQL version ($PG_VERSION)."
upgrade_db
fi
else
Expand Down
4 changes: 2 additions & 2 deletions viseron/components/darknet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
DNN_CPU,
DNN_DEFAULT,
DNN_OPENCL,
DNN_OPENVINO,
DNN_OPENCV,
DNN_TARGETS,
)

Expand Down Expand Up @@ -303,7 +303,7 @@ def dnn_preferable_backend(self) -> int:
if self._config[CONFIG_DNN_BACKEND]:
return DNN_BACKENDS[self._config[CONFIG_DNN_BACKEND]]
if os.getenv(ENV_OPENCL_SUPPORTED) == "true":
return DNN_BACKENDS[DNN_OPENVINO]
return DNN_BACKENDS[DNN_OPENCV]
return DNN_BACKENDS[DNN_DEFAULT]

@property
Expand Down

0 comments on commit 05f5167

Please sign in to comment.