Меню Рубрики

Установка и настройка cuda

Установка OpenCV + CUDA на Windows

Введение

В данной статье речь пойдет о сборке и установке OpenCV 4 для C/C++, Python 2 и Python 3 из исходных файлов с дополнительными модулями CUDA 10 на ОС Windows.

Я постарался включить сюда все тонкости и нюансы, с которыми можно столкнуться в ходе установки, и про которые не написано в официальном мануале.

Сборка тестировалась для:

  • Windows 8.1 + Visual Studio 2017 + Python 2/3 + CUDA 10.0 + GeForce 840m
  • Windows 10 + Visual Studio 2019 + Python 2/3 + CUDA 10.0 + GeForce GTX 1060

Внимание! Сборка не подойдет для версии OpenCV 4.0.1 и/или CUDA ниже 10-й версии. CUDA 9 и ниже поддерживается OpenCV 3.

Что потребуется для установки

В моей сборке использовались следующие инструменты:

  1. CMake 3.15
  2. MS Visual Studio 2019 64-бит + средства CMake С++ для Windows
  3. Python 3.7.3 64-бит + NumPy 64-бит
  4. Python 2.7.16 64-бит + NumPy 64-бит
  5. CUDA 10.0
  6. CuDNN 7.6.2
  7. OpenCV 4.1.1 и OpenCV-contrib-4.1.1

Установка

Так как установка производится через консольные команды, то следует внимательно и аккуратно выполнять все шаги. Также, при необходимости, меняйте установочные пути на свои.
Для начала необходимо установить требуемое ПО, причем Visual Studio должна быть установлена до CUDA:

  • CMake (версия >= 3.9.1)
  • MS Visual Studio
  • Python 3.7 (дистрибутив Anaconda3)
  • CUDA 10.0
  • CuDNN 7.6.2

После установки всех компонент убедитесь, что пути для CMake, Visual Studio, Python, CUDA, CuDNN прописаны в переменных PATH, PYTHONPATH, CUDA_PATH и cudnn соответственно.

Далее загружаем архивы исходников opencv-4.1.1 и opencv-contrib-4.1.1 в желаемое место (в моем случае это C:\OpenCV\).

Создаем папку build/ внутри opencv-4.1.1.

Далее сгенерируем файлы сборки с помощью cmake. Мы будем использовать консольный вариант cmake, так как cmake-gui путает типы некоторых переменных (например, OPENCV_PYTHON3_VERSION) и, как следствие, неправильно генерирует файлы.

Открываем консоль по пути C:\OpenCV\ и прописываем переменные.

Примечание. Для Visual Studio 2017 генератор пишется как «Visual Studio 15 2017 Win64» и без флага -A.

Также можно явно указать питоновские библиотеки для python 2 и python 3 на случай, если сборщик не сможет найти их автоматически.

Примечание. Обратите внимание на то, что библиотека NumPy должна быть той же разрядности, что и OpenCV. Проверить это легко:

Выполняем генерацию файлов сборки с помощью длинной команды ниже. При неудачной генерации или наличии ошибок после выполнения команды, повторную генерацию следует производить вычистив все файлы в build/ и .cache/.

  • BUILD_opencv_world – необязательный модуль, содержащий копии всех выбранных в ходе установки библиотек. Удобен при разработке на C++, так как вместо подключения кучи зависимостей opencv можно подключить одну зависимость opencv_world411.lib в проект
  • INSTALL_EXAMPLES/INSTALL_TESTS – установка примеров/тестов кода opencv
  • CUDA_FAST_MATH, WITH_CUBLAS – дополнительные модули для CUDA, призванные ускорить вычисления
  • CUDA_ARCH_PTX – версия PTX инструкций для улучшения производительности вычислений
  • OPENCV_EXTRA_MODULES_PATH – путь до дополнительных модулей из opencv-contrib (обязательно для CUDA)
  • BUILD_PROTOBUF – для работы некоторых модулей opencv необходим Protobuf (сборщик opencv в любом случае поставит BUILD_PROTOBUF=ON)

Спустя примерно 10 минут в консоле должна появиться информация о сборке и завершающие строки «Configuring done» и «Generating done». Проверяем всю информацию, особенно разделы NVIDIA CUDA, Python 2, Python 3.

Далее собираем решение. На сборку может уйти несколько часов в зависимости от вашего процессора и версии Visual Studio.

После успешной установки создаем системную переменную OPENCV_DIR со значением C:\OpenCV\opencv-4.1.1\build\install\x64\vc15\bin и также добавляем ее в PATH.

Проверим работоспособность OpenCV с модулем CUDA на простом примере умножения матриц.

  1. Установить тип сборки Release/x64 (для Debug следует собрать OpenCV с флагом Debug)
  2. Project Properties → C/C++ → General → Добавить строку «C:\OpenCV\opencv-4.1.1\build\install\include» в Additional Include Directories
  3. Project Properties → Linker → General → Добавить строку « C:\OpenCV\opencv-4.1.1\build\install\x64\vc16\lib» в Additional Library Directories
  4. Project Properties → Linker → General → Добавить «;opencv_world411.lib» («;opencv_world411d.lib» для Debug) в конец Additional Dependencies

Удаление

Чтобы удалить OpenCV, нужно выполнить команду.

и удалить системную переменную OPENCV_DIR и убрать путь до OpenCV из PATH.

Заключение

В статье мы рассмотрели установку OpenCV 4 для ОС Windows 10. Данный алгоритм тестировался на Windows 8.1 и Windows 10, но, в теории, может собираться и на Windows 7. За дополнительной информацией можно обратиться к списку источников ниже.

источник

Установка и настройка cuda

The installation instructions for the CUDA Toolkit on MS-Windows systems.

1. Introduction

CUDA В® is a parallel computing platform and programming model invented by NVIDIA. It enables dramatic increases in computing performance by harnessing the power of the graphics processing unit (GPU).

This guide will show you how to install and check the correct operation of the CUDA development tools.

1.1. System Requirements

The next two tables list the currently supported Windows operating systems and compilers.

Table 1. Windows Operating System Support in CUDA 10.2

Operating System Native x86_64 Cross (x86_32 on x86_64)
Windows 10 YES YES
Windows 8.1 YES YES
Windows 7 YES YES
Windows Server 2019 YES NO
Windows Server 2016 YES NO
Windows Server 2012 R2 YES NO
Table 2. Windows Compiler Support in CUDA 10.2

Compiler* IDE Native x86_64 Cross (x86_32 on x86_64)
MSVC Version 192x Visual Studio 2019 16.x (Preview releases) YES NO
MSVC Version 191x Visual Studio 2017 15.x (RTW and all updates) YES NO
MSVC Version 1900 Visual Studio 2015 14.0 (RTW and updates 1, 2, and 3) YES NO
Visual Studio Community 2015 YES NO
MSVC Version 1800 Visual Studio 2013 12.0 YES YES
MSVC Version 1700 Visual Studio 2012 11.0 YES YES

x86_32 support is limited. See the x86 32-bit Support section for details.

For more information on MSVC versions, Visual Studio product versions, visit https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd.

x86 32-bit Support

Native development using the CUDA Toolkit on x86_32 is unsupported. Deployment and execution of CUDA applications on x86_32 is still supported, but is limited to use with GeForce GPUs. To create 32-bit CUDA applications, use the cross-development capabilities of the CUDA Toolkit on x86_64.

1.2. About This Document

This document is intended for readers familiar with Microsoft Windows operating systems and the Microsoft Visual Studio environment. You do not need previous experience with CUDA or experience with parallel computation.

2. Installing CUDA Development Tools

Basic instructions can be found in the Quick Start Guide. Read on for more detailed instructions.

2.1. Verify You Have a CUDA-Capable GPU

You can verify that you have a CUDA-capable GPU through the Display Adapters section in the Windows Device Manager. Here you will find the vendor name and model of your graphics card(s). If you have an NVIDIA card that is listed in http://developer.nvidia.com/cuda-gpus, that GPU is CUDA-capable. The Release Notes for the CUDA Toolkit also contain a list of supported products.

2.2. Download the NV >

The CUDA Toolkit installs the CUDA driver and tools needed to create, build and run a CUDA application as well as libraries, header files, CUDA samples source code, and other resources.

Download Verification

The download can be verified by comparing the MD5 checksum posted at http://developer.nvidia.com/cuda-downloads/checksums with that of the downloaded file. If either of the checksums differ, the downloaded file is corrupt and needs to be downloaded again.

To calculate the MD5 checksum of the downloaded file, follow the instructions at http://support.microsoft.com/kb/889768.

2.3. Install the CUDA Software

Before installing the toolkit, you should read the Release Notes , as they provide details on installation and software functionality.

Graphical Installation

Install the CUDA Software by executing the CUDA installer and following the on-screen prompts.

Silent Installation

The installer can be executed in silent mode by executing the package with the -s flag. Additional parameters can be passed which will install specific subpackages instead of all packages. See the table below for a list of all the subpackage names.

Table 3. Possible Subpackage Names

Source code for many example CUDA applications using supported versions of Visual Studio.

Note: C:\ProgramData\ is a hidden folder. It can be made visible within the Windows Explorer options at (Tools | Options).

Subpackage Name Subpackage Description
Toolkit Subpackages (defaults to C:\Program Files\NV >10.2 )
nvcc_ 10.2 CUDA compiler.
cuobjdump_ 10.2 Extracts information from cubin files.
nvprune_ 10.2 Prunes host object files and libraries to only contain device code for the specified targets.
cupti_ 10.2 The CUDA Profiler Tools Interface for creating profiling and tracing tools that target CUDA applications.
gpu_library_advisor_ 10.2 Identifies opportunities to improve application performance by replacing existing CPU libraries with GPU-accelerated versions of those libraries.
memcheck_ 10.2 Functional correctness checking suite.
nvdisasm_ 10.2 Extracts information from standalone cubin files.
nvprof_ 10.2 Tool for collecting and viewing CUDA application profiling data from the command-line.
visual_profiler_ 10.2 GUI profiler for CUDA applications.
visual_studio_integration_ 10.2 Registers the CUDA plugins with supported and installed versions of Visual Studio. Also installs Nsight Visual Studio Edition as well as the NVIDIA Tools Extension SDK. This integration allows for CUDA development within Visual Studio.
demo_suite_ 10.2 Prebuilt demo applications using CUDA.
documentation_ 10.2 CUDA HTML and PDF documentation files including the CUDA C++ Programming Guide, CUDA C++ Best Practices Guide, CUDA library documentation, etc.
cublas_ 10.2 CUBLAS runtime libraries.
cublas_dev_ 10.2 CUBLAS development libraries and headers.
cudart_ 10.2 CUDART runtime libraries.
cufft_ 10.2 CUFFT runtime libraries.
cufft_dev_ 10.2 CUFFT development libraries and headers.
curand_ 10.2 CURAND runtime libraries.
curand_dev_ 10.2 CURAND development libraries and headers.
cusolver_ 10.2 CUSOLVER runtime libraries.
cusolver_dev_ 10.2 CUSOLVER development libraries and headers.
cusparse_ 10.2 CUSPARSE runtime libraries.
cusparse_dev_ 10.2 CUSPARSE development libraries and headers.
nvgraph_ 10.2 NVIDIA Graph Analytics runtime libraries.
nvgraph_dev_ 10.2 NVIDIA Graph Analytics development libraries and headers.
npp_ 10.2 NPP runtime libraries.
npp_dev_ 10.2 NPP development libraries and headers.
nvrtc_ 10.2 NVRTC runtime libraries.
nvrtc_dev_ 10.2 NVRTC development libraries and headers.
nvml_dev_ 10.2 NVML development libraries and headers.
occupancy_calculator_ 10.2 Excel spreadsheet used to test occupancy scenarios.
fortran_examples_ 10.2 CUDA Fortran examples.
Samples Subpackages (defaults to C:\ProgramData\NV >10.2 )
samples_ 10.2
Driver Subpackages
Display.Driver The NVIDIA Display Driver. Required to run CUDA applications.

Extracting and Inspecting the Files Manually

Sometimes it may be desirable to extract or inspect the installable files directly, such as in enterprise deployment, or to browse the files before installation. The full installation package can be extracted using a decompression tool which supports the LZMA compression method, such as 7-zip or WinZip.

Once extracted, the CUDA Toolkit files will be in the CUDAToolkit folder, and similarily for the CUDA Samples and CUDA Visual Studio Integration. Within each directory is a .dll and .nvi file that can be ignored as they are not part of the installable files.

2.3.1. Uninstalling the CUDA Software

All subpackages can be uninstalled through the Windows Control Panel by using the Programs and Features widget.

2.4. Use a Suitable Driver Model

On Windows 7 and later, the operating system provides two under which the NVIDIA Driver may operate:

  • The driver model is used for display devices.
  • The mode of the NV >The TCC driver mode provides a number of advantages for CUDA applications on GPUs that support this mode. For example:

  • TCC eliminates the timeouts that can occur when running under WDDM due to the Windows Timeout Detection and Recovery mechanism for display devices.
  • TCC allows the use of CUDA with Windows Remote Desktop, which is not possible for WDDM devices.
  • TCC allows the use of CUDA from within processes running as Windows services, which is not possible for WDDM devices.
  • TCC reduces the latency of CUDA kernel launches.

TCC is enabled by default on most recent NV >nvidia-smi tool that is included with the NV >nvidia-smi -h for details).

2.5. Verify the Installation

Before continuing, it is important to verify that the CUDA toolkit can find and communicate correctly with the CUDA-capable hardware. To do this, you need to compile and run some of the included sample programs.

2.5.1. Running the Compiled Examples

The version of the CUDA Toolkit can be checked by running nvcc -V in a Command Prompt window. You can display a Command Prompt window by going to:

Start > All Programs > Accessories > Command Prompt

This assumes that you used the default installation directory structure. If CUDA is installed and configured correctly, the output should look similar to Figure 1.

The exact appearance and the output lines might be different on your system. The important outcomes are that a device was found, that the device(s) match what is installed in your system, and that the test passed.

If a CUDA-capable device and the CUDA Driver are installed but deviceQuery reports that no CUDA-capable devices are present, ensure the deivce and driver are properly installed.

Running the bandwidthTest program, located in the same directory as deviceQuery above, ensures that the system and the CUDA-capable device are able to communicate correctly. The output should resemble Figure 2.

The device name (second line) and the bandwidth numbers vary from system to system. The important items are the second line, which confirms a CUDA device was found, and the second-to-last line, which confirms that all necessary tests passed.

If the tests do not pass, make sure you do have a CUDA-capable NVIDIA GPU on your system and make sure it is properly installed.

3. Compiling CUDA Programs

CUDA Samples are organized according to . Each sample is organized into one of the following folders: ( 0_Simple , 1_Utilities , 2_Graphics , 3_Imaging , 4_Finance , 5_Simulations , 6_Advanced , 7_CUDALibraries ).

3.1. Compiling Sample Projects

The bandwidthTest project is a good sample project to build and run. It is located in the NV >10.2 \1_Utilities\bandwidthTest directory.

If you elected to use the default installation location, the output is placed in CUDA Samples\v 10.2 \bin\win64\Release . Build the program using the appropriate solution file and run the executable. If all works correctly, the output should be similar to Figure 2.

3.2. Sample Projects

The sample projects come in two configurations: debug and release (where release contains no debugging information) and different Visual Studio projects.

A few of the example projects require some additional setup. The simpleD3D9 example requires the system to have a Direct3D SDK (June 2010 or later) installed and the Visual C++ directory paths (located in Tools > Options. ) properly configured. Consult the Direct3D documentation for additional details.

These sample projects also make use of the $CUDA_PATH environment variable to locate where the CUDA Toolkit and the associated .props files are.

The environment variable is set automatically using the Build Customization CUDA 10.2 .props file, and is installed automatically as part of the CUDA Toolkit installation process.

Table 4. CUDA Visual Studio .props locations

Visual Studio CUDA 10.2 .props file Install Directory
Visual Studio 2019 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations
Visual Studio 2017 \Common7\IDE\VC\VCTargets\BuildCustomizations
Visual Studio 2015 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations
Visual Studio 2013 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations
Visual Studio 2012 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations

You can reference this CUDA 10.2 .props file when building your own CUDA applications.

3.3. Build Customizations for New Projects

When creating a new CUDA application, the Visual Studio project file must be configured to include CUDA build customizations. To accomplish this, click File-> New | Project. NVIDIA-> CUDA->, then select a template for your CUDA Toolkit version. For example, selecting the «CUDA 10.2 Runtime» template will configure your project for use with the CUDA 10.2 Toolkit. The new project is technically a C++ project (.vcxproj) that is preconfigured to use NVIDIA’s Build Customizations. All standard capabilities of Visual Studio C++ projects will be available.

To specify a custom CUDA Toolkit location, under CUDA C/C++, select Common, and set the CUDA Toolkit Custom Dir field as desired. Note that the selected toolkit must match the version of the Build Customizations.

3.4. Build Customizations for Existing Projects

While Option 2 will allow your project to automatically use any new CUDA Toolkit version you may install in the future, selecting the toolkit version explicitly as in Option 1 is often better in practice, because if there are new CUDA configuration options added to the build customization rules accompanying the newer toolkit, you would not see those new options using Option 2.

Files which contain CUDA code must be marked as a CUDA C/C++ file. This can done when adding the file by right clicking the project you wish to add the file to, selecting Add\New Item , selecting NV >10.2 \Code\CUDA C/C++ File , and then selecting the file you wish to add.

4. Additional Cons >

Now that you have CUDA-capable hardware and the NV >CUDA C Programming Guide , located in the CUDA Toolkit documentation directory.

A number of helpful development tools are included in the CUDA Toolkit or are available for download from the NVIDIA Developer Zone to assist you as you develop your CUDA programs, such as NVIDIA В® Nsightв„ў Visual Studio Edition, NVIDIA Visual Profiler, and cuda-memcheck.

For technical support on programming questions, consult and participate in the developer forums at http://developer.nvidia.com/cuda/.

Notices

Notice

ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, «MATERIALS») ARE BEING PROVIDED «AS IS.» NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.

Information furnished is believed to be accurate and reliable. However, NVIDIA Corporation assumes no responsibility for the consequences of use of such information or for any infringement of patents or other rights of third parties that may result from its use. No license is granted by implication of otherwise under any patent rights of NVIDIA Corporation. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all other information previously supplied. NVIDIA Corporation products are not authorized as critical components in life support devices or systems without express written approval of NVIDIA Corporation.

Trademarks

NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA Corporation in the U.S. and other countries. Other company and product names may be trademarks of the respective companies with which they are associated.

Copyright

В© 2009 — 2019 NVIDIA Corporation. All rights reserved.

источник

Читайте также:  Установка передней камеры тигуан