相机连接时间较长

问题

相机第一次连接到 PC 时需要很长时间才能建立连接。

原因

OpenCL 内核是为相机所连接的特定硬件构建的,在相机与 PC 建立连接之前,硬件是未知的。构建这些内核会占用大量总连接时间,并且会在进程中第一次连接相机时发生。

如果进程保持活动状态(更具体地说是 Zivid 应用程序),则内核不需要重建。

解决方案

可以缓存内核以避免每次连接到相机时都必须重建它们。请注意,第一次连接时速度仍然会很慢,但之后每次连接都会很快。请按照特定硬件的说明进行操作。

Upgrade your Intel drivers to the newest available version to allow caching of the OpenCL kernels using the Intel Driver & Support assistant. To verify correct caching, check if the folder %LocalAppData%/NEO/neo_compiler_cache exists and is not empty.

如果升级英特尔驱动程序无法解决问题,您可以手动允许缓存(实验性)。请按照下面的下拉菜单获取进一步的说明。

手动启用缓存(实验性功能)

此方法被 Intel Graphics Compute Runtime 认为是过时且实验性的,但可作为一个临时解决方案,直到您的驱动程序得到更新。请注意上述链接中提到的关于 Windows 系统下 cl_cache 的局限性,并仅考虑在非生产环境中使用此方法。

  1. Create a folder where you want to store the cached kernels, e.g. in %LocalAppData%/NEO/neo_compiler_cache

  2. Add a new environment variable cl_cache_dir and set its value to the path of cache folder, e.g. %LocalAppData%/NEO/neo_compiler_cache

您可能需要重新启动计算机才能使更改生效。

大多数 NVIDIA GPU 和驱动程序默认都启用了缓存。如果您仍然遇到连接速度缓慢的问题,请尝试更新您的 NVIDIA GPU 至最新的驱动程序。

To verify correct caching, check if the folder %AppData%/NVIDIA/ComputeCache exists and is not empty.

将您的 OpenCL 驱动程序升级到最新可用版本,以允许缓存 OpenCL 内核。

sudo apt update && sudo apt upgrade intel-opencl-icd

If the latest version in the repositories is not sufficient, you can use the latest released package from Intel. To verify correct caching, check if the folder $HOME/.cache/neo_compiler_cache exists and is not empty.

如果升级英特尔驱动程序无法解决问题,您可以手动允许缓存。请按照下面的下拉菜单获取进一步的说明。

手动启用缓存
  1. 创建一个文件夹来存储缓存的内核,例如 $HOME/.cache/neo_compiler_cache

  2. 添加新的环境变量 cl_cache_dir ,并将其值设置为缓存文件夹的路径,例如 $HOME/.cache/neo_compiler_cache

mkdir $HOME/.cache/neo_compiler_cache
export cl_cache_dir=$HOME/.cache/neo_compiler_cache

缓存现在应在当前会话中保持持久化。

大多数 NVIDIA GPU 和驱动程序默认都启用了缓存。如果您仍然遇到连接速度缓慢的问题,请尝试更新您的 NVIDIA GPU 至最新的驱动程序。

To verify correct caching, check if the folder $HOME/.nv/ComputeCache exists and is not empty.

Docker

If you are connecting to the camera from a Docker container, you will have to mount the cache directory on the host to the root in the container to improve the first connection. This is because each Docker container gets its own file system, and each time the container is started the cache directory will be empty.

The below instructions are only intended to improve the first connection to the camera, and therefore only apply when initially running the container. Note that already cached kernels on the host machine are required.

Windows is currently not supported with Docker, as OpenCL is not fully supported on Windows in a Docker container.

The kernel cache location is based on the NEO_CACHE_DIR environment variable, which defaults to $HOME/.cache/neo_compiler_cache on the host machine. Mount this directory to the root directory in the container when running to share the cache.

To avoid creating files owned by root in the home directory, you can first copy the cache to the root directory.

sudo rsync -r --mkpath "$HOME"/.cache/neo_compiler_cache/ /root/.cache/neo_compiler_cache/
sudo docker run --interactive --tty --device=/dev/dri --volume /root/.cache/neo_compiler_cache:/root/.cache/neo_compiler_cache <image>

where <image> is the name of the image you want to run.

The kernel cache is stored in $HOME/.nv/ComputeCache on the host machine. Mount this directory to the root directory in the container when running to share the cache.

To avoid creating files owned by root in the home directory, you can first copy the cache to the root directory.

sudo rsync -r --mkpath "$HOME"/.nv/ComputeCache /root/.nv/ComputeCache
sudo docker run --interactive --tty --device=/dev/dri --gpus=all --volume /root/.nv/ComputeCache:/root/.nv/ComputeCache <image>

where <image> is the name of the image you want to run.