diff --git a/.jenkins/common.groovy b/.jenkins/common.groovy index d47f21fcd7..bdcccb377c 100644 --- a/.jenkins/common.groovy +++ b/.jenkins/common.groovy @@ -18,7 +18,7 @@ def runCompileCommand(platform, project, jobName, boolean debug=false, boolean s if (platform.jenkinsLabel.contains('centos')) { osInfo = 'cat /etc/os-release && uname -r' update = 'sudo yum -y --nogpgcheck update && sudo yum -y --nogpgcheck install zip && sudo alternatives --set python /usr/bin/python2' - installPackageDeps = 'python MIVisionX-setup.py --reinstall yes --ffmpeg yes' + installPackageDeps = 'python MIVisionX-setup.py --reinstall yes --ffmpeg yes --backend OCL' if (platform.jenkinsLabel.contains('centos7')) { update = 'echo scl enable devtoolset-7 bash | sudo tee /etc/profile.d/ree.sh && sudo chmod +x /etc/profile.d/ree.sh && . /etc/profile && scl enable devtoolset-7 bash && sudo yum -y --nogpgcheck install lcov zip && sudo yum -y --nogpgcheck update' cmake = 'cmake3' @@ -33,12 +33,12 @@ def runCompileCommand(platform, project, jobName, boolean debug=false, boolean s else if (platform.jenkinsLabel.contains('sles')) { osInfo = 'cat /etc/os-release && uname -r' update = 'sudo zypper -n --no-gpg-checks install lcov zip && sudo zypper -n --no-gpg-checks update' - installPackageDeps = 'python MIVisionX-setup.py --reinstall yes --ffmpeg yes' + installPackageDeps = 'python MIVisionX-setup.py --reinstall yes --ffmpeg yes --backend OCL' } else if (platform.jenkinsLabel.contains('ubuntu')) { osInfo = 'cat /etc/lsb-release && uname -r' update = 'sudo apt-get -y --allow-unauthenticated update && sudo apt-get -y --allow-unauthenticated install lcov zip' - installPackageDeps = 'python MIVisionX-setup.py --reinstall yes --ffmpeg yes' + installPackageDeps = 'python MIVisionX-setup.py --reinstall yes --ffmpeg yes --backend OCL' if (platform.jenkinsLabel.contains('ubuntu18')) { codeCovFlags = '-D CMAKE_CXX_FLAGS="-fprofile-arcs -ftest-coverage"' } diff --git a/.travis.yml b/.travis.yml index c02b1d5c7b..c89c578d1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -91,5 +91,4 @@ after_success: notifications: email: - - kiriti.nageshgowda@amd.com - - pavel.tcherniaev@amd.com + - mivisionx.support@amd.com diff --git a/CHANGELOG.md b/CHANGELOG.md index 71bf156ee1..b3bca0b5c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,47 @@ [MIVisionX Documentation](https://gpuopen-professionalcompute-libraries.github.io/MIVisionX/) -## MIVisionX 2.0.1 (unreleased) +## MIVisionX 2.1.0 (Unreleased) + +### Added + +* `TBD` + +### Optimizations + +* Readme Updates + +### Changed + +* **Backend** - Default Backend set to `HIP` + +### Fixed + +* Minor bugs and warnings + +### Tested Configurations + +* Windows 10 +* Linux distribution + + Ubuntu - `18.04` / `20.04` + + CentOS - `7` / `8` + + SLES - `15-SP2` +* ROCm: rocm-dev - `4.5.2.40502-164` +* rocm-cmake - [rocm-4.2.0](https://github.com/RadeonOpenCompute/rocm-cmake/releases/tag/rocm-4.2.0) +* MIOpenGEMM - [1.1.5](https://github.com/ROCmSoftwarePlatform/MIOpenGEMM/releases/tag/1.1.5) +* MIOpen - [2.14.0](https://github.com/ROCmSoftwarePlatform/MIOpen/releases/tag/2.14.0) +* Protobuf - [V3.12.0](https://github.com/protocolbuffers/protobuf/releases/tag/v3.12.0) +* OpenCV - [4.5.5](https://github.com/opencv/opencv/releases/tag/4.5.5) +* RPP - [0.92](https://github.com/GPUOpen-ProfessionalCompute-Libraries/rpp/releases/tag/0.92) +* FFMPEG - [n4.0.4](https://github.com/FFmpeg/FFmpeg/releases/tag/n4.0.4) +* Dependencies for all the above packages +* MIVisionX Setup Script - `V2.0.0` + +### Known issues + +* `TBD` + +## MIVisionX 2.0.1 ### Added @@ -18,6 +58,7 @@ ### Optimizations * Code Cleanup +* Readme Updates ### Changed @@ -26,6 +67,8 @@ ### Fixed * Minor bugs and warnings +* Inference server application - OpenCL Backend +* vxCreateThreshold Fix - Apps & Sample ### Tested Configurations diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f9a626dd0..81d92c2c67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ cmake_minimum_required(VERSION 3.0) project(MIVisionX) -set(VERSION "2.0.1") +set(VERSION "2.1.0") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) @@ -54,7 +54,7 @@ message("-- ${BoldBlue}MIVisionX Version -- ${VERSION}${ColourReset}") message("-- ${BoldBlue}MIVisionX Install Path -- ${CMAKE_INSTALL_PREFIX}${ColourReset}") if(NOT DEFINED BACKEND) - set(BACKEND "OPENCL") # set default backend to OPENCL + set(BACKEND "HIP") # set default backend to HIP else() if("${BACKEND}" STREQUAL "OPENCL" OR "${BACKEND}" STREQUAL "OCL" OR "${BACKEND}" STREQUAL "OpenCL") set(BACKEND "OPENCL") @@ -66,7 +66,7 @@ else() else() message("-- ${Red}Warning: MIVisionX backend option unknown -- ${BACKEND}${ColourReset}") message("-- ${Red}Warning: MIVisionX default backend will enforced${ColourReset}") - set(BACKEND "OPENCL") + set(BACKEND "HIP") endif() endif() message("-- ${BoldBlue}MIVisionX Backend set to -- ${BACKEND}${ColourReset}") @@ -92,7 +92,7 @@ message("-- ${Cyan} -D NEURAL_NET=OFF [Turn OFF Neural Net Modules (default: message("-- ${Cyan} -D ROCAL=OFF [Turn OFF ROCAL Modules (default:ON)]${ColourReset}") message("-- ${Cyan} -D LOOM=OFF [Turn OFF LOOM Modules (default:ON)]${ColourReset}") message("-- ${Cyan} -D GPU_SUPPORT=OFF [Turn OFF GPU support (default:ON)]${ColourReset}") -message("-- ${Cyan} -D BACKEND=HIP [select HIP for GPU backend [options:CPU/OPENCL/HIP](default:OPENCL)]${ColourReset}") +message("-- ${Cyan} -D BACKEND=OPENCL [select OPENCL for GPU backend [options:CPU/OPENCL/HIP](default:HIP)]${ColourReset}") if(APPLE) set(CMAKE_MACOSX_RPATH 1) diff --git a/MIVisionX-setup.py b/MIVisionX-setup.py index 3e403acc9c..69b944af29 100644 --- a/MIVisionX-setup.py +++ b/MIVisionX-setup.py @@ -30,17 +30,17 @@ __author__ = "Kiriti Nagesh Gowda" __copyright__ = "Copyright 2018 - 2022, AMD ROCm MIVisionX" __license__ = "MIT" -__version__ = "2.0.0" +__version__ = "2.1.0" __maintainer__ = "Kiriti Nagesh Gowda" -__email__ = "Kiriti.NageshGowda@amd.com" +__email__ = "mivisionx.support@amd.com" __status__ = "Shipping" # Arguments parser = argparse.ArgumentParser() parser.add_argument('--directory', type=str, default='~/mivisionx-deps', help='Setup home directory - optional (default:~/)') -parser.add_argument('--opencv', type=str, default='3.4.0', - help='OpenCV Version - optional (default:3.4.0)') +parser.add_argument('--opencv', type=str, default='4.5.5', + help='OpenCV Version - optional (default:4.5.5)') parser.add_argument('--miopen', type=str, default='2.14.0', help='MIOpen Version - optional (default:2.14.0)') parser.add_argument('--miopengemm', type=str, default='1.1.5', @@ -57,8 +57,8 @@ help='MIVisionX rocAL Dependency Install - optional (default:yes) [options:yes/no]') parser.add_argument('--reinstall', type=str, default='no', help='Remove previous setup and reinstall - optional (default:no) [options:yes/no]') -parser.add_argument('--backend', type=str, default='OCL', - help='MIVisionX Dependency Backend - optional (default:OCL) [options:OCL/HIP]') +parser.add_argument('--backend', type=str, default='HIP', + help='MIVisionX Dependency Backend - optional (default:HIP) [options:OCL/HIP]') parser.add_argument('--rocm_path', type=str, default='/opt/rocm', help='ROCm Installation Path - optional (default:/opt/rocm) - ROCm Installation Required') args = parser.parse_args() @@ -399,7 +399,7 @@ ' install -t pattern devel_basis') os.system('sudo '+linuxFlag+' '+linuxSystemInstall+' '+linuxSystemInstall_check + ' install gtk2-devel libjpeg-devel libpng-devel libtiff-devel libavc1394 wget unzip') - # OpenCV 3.4.0 + # OpenCV 4.5.5 os.system('(cd '+deps_dir+'/build/OpenCV; '+linuxCMake + ' -D WITH_OPENCL=OFF -D WITH_OPENCLAMDFFT=OFF -D WITH_OPENCLAMDBLAS=OFF -D WITH_VA_INTEL=OFF -D WITH_OPENCL_SVM=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ../../opencv-'+opencvVersion+' )') os.system('(cd '+deps_dir+'/build/OpenCV; make -j8 )') diff --git a/README.md b/README.md index 5c455f8b97..762aaad2fc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

-MIVisionX toolkit is a set of comprehensive computer vision and machine intelligence libraries, utilities, and applications bundled into a single toolkit. AMD MIVisionX delivers highly optimized open-source implementation of the Khronos OpenVX™ and OpenVX™ Extensions along with Convolution Neural Net Model Compiler & Optimizer supporting ONNX, and Khronos NNEF™ exchange formats. The toolkit allows for rapid prototyping and deployment of optimized computer vision and machine learning inference workloads on a wide range of computer hardware, including small embedded x86 CPUs, APUs, discrete GPUs, and heterogeneous servers. +MIVisionX toolkit is a set of comprehensive computer vision and machine intelligence libraries, utilities, and applications bundled into a single toolkit. AMD MIVisionX delivers highly optimized open-source implementation of the Khronos OpenVX™ and OpenVX™ Extensions along with Convolution Neural Net Model Compiler & Optimizer supporting ONNX, and Khronos NNEF™ exchange formats. The toolkit allows for rapid prototyping and deployment of optimized computer vision and machine learning inference workloads on a wide range of computer hardware, including small embedded x86 CPUs, APUs, discrete GPUs, and heterogeneous servers. #### Latest Release @@ -55,9 +55,9 @@ MIVisionX toolkit is a set of comprehensive computer vision and machine intellig

-[AMD OpenVX](amd_openvx#amd-openvx-amd_openvx) is a highly optimized open source implementation of the Khronos OpenVX™ 1.3 computer vision specification. It allows for rapid prototyping as well as fast execution on a wide range of computer hardware, including small embedded x86 CPUs and large workstation discrete GPUs. +[AMD OpenVX](amd_openvx#amd-openvx-amd_openvx) is a highly optimized open source implementation of the Khronos OpenVX™ 1.3 computer vision specification. It allows for rapid prototyping as well as fast execution on a wide range of computer hardware, including small embedded x86 CPUs and large workstation discrete GPUs. -Khronos OpenVX™ 1.0.1 conformant implementation is available in [MIVisionX Lite](https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX/tree/openvx-1.0.1) +Khronos OpenVX™ 1.0.1 conformant implementation is available in [MIVisionX Lite](https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX/tree/openvx-1.0.1) ## AMD OpenVX Extensions @@ -132,7 +132,7 @@ MIVisionX provides you with tools for accomplishing your tasks throughout the wh * Visual Studio 2019 or later * Install the latest AMD [drivers](https://www.amd.com/en/support) * Install [OpenCL SDK](https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK/releases/tag/1.0) -* Install [OpenCV 3.4](https://github.com/opencv/opencv/releases/tag/3.4.0) +* Install [OpenCV 4.5.5](https://github.com/opencv/opencv/releases/tag/4.5.5) + Set `OpenCV_DIR` environment variable to `OpenCV/build` folder + Add `%OpenCV_DIR%\x64\vc14\bin` or `%OpenCV_DIR%\x64\vc15\bin` to your `PATH` @@ -140,7 +140,7 @@ MIVisionX provides you with tools for accomplishing your tasks throughout the wh * Install [Homebrew](https://brew.sh) * Install [CMake](https://cmake.org) -* Install OpenCV 3.4 +* Install OpenCV `3`/`4` **Note:** macOS [build instructions](https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX/wiki/macOS#macos-build-instructions) @@ -155,7 +155,7 @@ MIVisionX provides you with tools for accomplishing your tasks throughout the wh * Qt Creator for [Cloud Inference Client](apps/cloud_inference/client_app/README.md) * [Protobuf](https://github.com/google/protobuf) for inference generator & model compiler + install `libprotobuf-dev` and `protobuf-compiler` needed for vx_nn -* [OpenCV 3.4](https://github.com/opencv/opencv/releases/tag/3.4.0) +* [OpenCV 4.5.5](https://github.com/opencv/opencv/releases/tag/4.5.5) + Set `OpenCV_DIR` environment variable to `OpenCV/build` folder * [FFMPEG n4.0.4](https://github.com/FFmpeg/FFmpeg/releases/tag/n4.0.4) + FFMPEG is required for amd_media & mv_deploy modules @@ -179,7 +179,7 @@ For the convenience of the developer, we here provide the setup script which wil ``` python MIVisionX-setup.py --directory [setup directory - optional (default:~/)] - --opencv [OpenCV Version - optional (default:3.4.0)] + --opencv [OpenCV Version - optional (default:4.5.5)] --miopen [MIOpen Version - optional (default:2.14.0)] --miopengemm[MIOpenGEMM Version - optional (default:1.1.5)] --protobuf [ProtoBuf Version - optional (default:3.12.0)] @@ -188,7 +188,7 @@ For the convenience of the developer, we here provide the setup script which wil --rocal [MIVisionX rocAL Dependency Install - optional (default:yes) [options:yes/no]] --neural_net[MIVisionX Neural Net Dependency Install - optional (default:yes) [options:yes/no]] --reinstall [Remove previous setup and reinstall (default:no)[options:yes/no]] - --backend [MIVisionX Dependency Backend - optional (default:OCL) [options:OCL/HIP]] + --backend [MIVisionX Dependency Backend - optional (default:HIP) [options:OCL/HIP]] --rocm_path [ROCm Installation Path - optional (default:/opt/rocm) - ROCm Installation Required] ``` **Note:** @@ -238,7 +238,7 @@ macOS [build instructions](https://github.com/GPUOpen-ProfessionalCompute-Librar + libraries into `/opt/rocm/mivisionx/lib` + OpenVX and module header files into `/opt/rocm/mivisionx/include` + model compiler, toolkit, & samples placed in `/opt/rocm/mivisionx` - * Package (.deb & .rpm) install requires `OpenCV v3.4.0` to execute `AMD OpenCV extensions` + * Package (.deb & .rpm) install requires `OpenCV v3+` to execute `AMD OpenCV extensions` #### Using `MIVisionX-setup.py` @@ -252,37 +252,37 @@ macOS [build instructions](https://github.com/GPUOpen-ProfessionalCompute-Librar **Note:** MIVisionX has support for two GPU backends: **OPENCL** and **HIP**: - + Instructions for building MIVisionX with **OPENCL** (i.e., default GPU backend): + + Instructions for building MIVisionX with the **HIP** GPU backend (i.e., default GPU backend): - * run the setup script to install all the dependencies required by the **OPENCL** GPU backend: - ``` - python MIVisionX-setup.py - ``` + + run the setup script to install all the dependencies required by the **HIP** GPU backend: + ``` + python MIVisionX-setup.py + ``` - * run the below commands to build MIVisionX with the **OPENCL** GPU backend: - ``` - mkdir build - cd build - cmake ../ - make -j8 - sudo make install - ``` + + run the below commands to build MIVisionX with the **HIP** GPU backend: + ``` + mkdir build-hip + cd build-hip + cmake ../ + make -j8 + sudo make install + ``` - + Instructions for building MIVisionX with the **HIP** GPU backend: + + Instructions for building MIVisionX with **OPENCL** GPU backend: - * run the setup script to install all the dependencies required by the **HIP** GPU backend: - ``` - python MIVisionX-setup.py --reinstall yes --backend HIP - ``` + + run the setup script to install all the dependencies required by the **OPENCL** GPU backend: + ``` + python MIVisionX-setup.py --reinstall yes --backend OCL + ``` - * run the below commands to build MIVisionX with the **HIP** GPU backend: - ``` - mkdir build-hip - cd build-hip - cmake -DBACKEND=HIP ../ - make -j8 - sudo make install - ``` + + run the below commands to build MIVisionX with the **OPENCL** GPU backend: + ``` + mkdir build-ocl + cd build-ocl + cmake -DBACKEND=OPENCL ../ + make -j8 + sudo make install + ``` **Note:** + MIVisionX cannot be installed for both GPU backends in the same default folder (i.e., /opt/rocm/mivisionx) @@ -436,7 +436,7 @@ Review all notable [changes](CHANGELOG.md#changelog) with the latest release * MIOpenGEMM - [1.1.5](https://github.com/ROCmSoftwarePlatform/MIOpenGEMM/releases/tag/1.1.5) * MIOpen - [2.14.0](https://github.com/ROCmSoftwarePlatform/MIOpen/releases/tag/2.14.0) * Protobuf - [V3.12.0](https://github.com/protocolbuffers/protobuf/releases/tag/v3.12.0) -* OpenCV - [3.4.0](https://github.com/opencv/opencv/releases/tag/3.4.0) +* OpenCV - [4.5.5](https://github.com/opencv/opencv/releases/tag/4.5.5) * RPP - [0.92](https://github.com/GPUOpen-ProfessionalCompute-Libraries/rpp/releases/tag/0.92) * FFMPEG - [n4.0.4](https://github.com/FFmpeg/FFmpeg/releases/tag/n4.0.4) * Dependencies for all the above packages @@ -444,19 +444,19 @@ Review all notable [changes](CHANGELOG.md#changelog) with the latest release ### Known issues -* Package install requires **OpenCV** `v3.4.X` to execute `AMD OpenCV extensions` +* Package install requires **OpenCV** `V-3+` to execute `AMD OpenCV extensions` ## MIVisionX Dependency Map -**Docker Image:** `docker pull kiritigowda/ubuntu-18.04:{TAGNAME}` +**Docker Image:** `sudo docker build -f docker/ubuntu20/{DOCKER_LEVEL_FILE_NAME}.dockerfile -t {mivisionx-level-NUMBER} .` - ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `new component added to the level` - ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `existing component from the previous level` -| Build Level | MIVisionX Dependencies | Modules | Libraries and Executables | Docker Tag | -|-------------|----------------------------------------------------|--------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `Level_1` | cmake
gcc
g++ | amd_openvx
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - CPU with Display OFF | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-1?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | -| `Level_2` | ROCm OpenCL
+Level 1 | amd_openvx
amd_openvx_extensions
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `loom_shell` - 360 Stitch App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display OFF | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-2?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | -| `Level_3` | OpenCV
FFMPEG
+Level 2 | amd_openvx
amd_openvx_extensions
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `mv_compile` - Neural Net Model Compile
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-3?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | -| `Level_4` | MIOpenGEMM
MIOpen
ProtoBuf
+Level 3 | amd_openvx
amd_openvx_extensions
apps
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `inference_server_app` - Cloud Inference App | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-4?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | -| `Level_5` | AMD_RPP
rocAL deps
+Level 4 | amd_openvx
amd_openvx_extensions
apps
rocAL
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `inference_server_app` - Cloud Inference App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_rpp.so` - OpenVX™ RPP Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `librali.so` - Radeon Augmentation Library
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `rali_pybind.so` - rocAL Pybind Lib | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-5?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | +| Build Level | MIVisionX Dependencies | Modules | Libraries and Executables | Docker Tag | +| ----------- | -------------------------------------------------- | ------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `Level_1` | cmake
gcc
g++ | amd_openvx
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - CPU with Display OFF | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-1?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | +| `Level_2` | ROCm OpenCL
+Level 1 | amd_openvx
amd_openvx_extensions
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `loom_shell` - 360 Stitch App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display OFF | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-2?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | +| `Level_3` | OpenCV
FFMPEG
+Level 2 | amd_openvx
amd_openvx_extensions
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `mv_compile` - Neural Net Model Compile
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-3?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | +| `Level_4` | MIOpenGEMM
MIOpen
ProtoBuf
+Level 3 | amd_openvx
amd_openvx_extensions
apps
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `inference_server_app` - Cloud Inference App | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-4?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | +| `Level_5` | AMD_RPP
rocAL deps
+Level 4 | amd_openvx
amd_openvx_extensions
apps
rocAL
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `inference_server_app` - Cloud Inference App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_rpp.so` - OpenVX™ RPP Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `librali.so` - Radeon Augmentation Library
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `rali_pybind.so` - rocAL Pybind Lib | [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/kiritigowda/ubuntu-18.04/mivisionx-level-5?style=flat-square)](https://hub.docker.com/repository/docker/kiritigowda/ubuntu-18.04) | diff --git a/amd_openvx/openvx/ago/ago_interface.cpp b/amd_openvx/openvx/ago/ago_interface.cpp index 486c6b48f6..47424e2ac6 100644 --- a/amd_openvx/openvx/ago/ago_interface.cpp +++ b/amd_openvx/openvx/ago/ago_interface.cpp @@ -1373,8 +1373,8 @@ vx_status agoVerifyNode(AgoNode * node) data->u.img.rect_valid.end_y = data->u.img.height; // check for VX_IMAGE_ATTRIBUTE_AMD_ENABLE_USER_BUFFER_GPU attribute if (meta->data.u.img.enableUserBufferGPU) { - // supports only virtual images with single color plane and without ROI - if (!data->isVirtual || data->u.img.planes != 1 || data->u.img.isROI || data->ownerOfUserBufferGPU) { + // supports only virtual images without ROI (planes commented out for accepting NV12 user buffer for amd_media) + if (!data->isVirtual /*|| data->u.img.planes != 1 */|| data->u.img.isROI || data->ownerOfUserBufferGPU) { agoAddLogEntry(&kernel->ref, VX_ERROR_NOT_SUPPORTED, "ERROR: agoVerifyGraph: kernel %s: VX_IMAGE_ATTRIBUTE_AMD_ENABLE_USER_BUFFER_GPU is not supported for argument#%d\n", kernel->name, arg); return VX_ERROR_NOT_SUPPORTED; } diff --git a/amd_openvx_extensions/CMakeLists.txt b/amd_openvx_extensions/CMakeLists.txt index 8edc48a8e5..4afabb11db 100644 --- a/amd_openvx_extensions/CMakeLists.txt +++ b/amd_openvx_extensions/CMakeLists.txt @@ -49,8 +49,12 @@ if(GPU_SUPPORT) ELSE() SET(HSA_PATH $ENV{HSA_PATH}) ENDIF() - find_package(HIP QUIET REQUIRED) - list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} ${ROCM_PATH}/llvm ${ROCM_PATH}/hip) + find_package(HIP QUIET) + if(HIP_FOUND) + list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} ${ROCM_PATH}/llvm ${ROCM_PATH}/hip) + else() + set(GPU_SUPPORT OFF) + endif() endif() find_package(miopen PATHS ${ROCM_PATH} QUIET) diff --git a/amd_openvx_extensions/amd_media/README.md b/amd_openvx_extensions/amd_media/README.md index fe39b966fc..063a8d002b 100644 --- a/amd_openvx_extensions/amd_media/README.md +++ b/amd_openvx_extensions/amd_media/README.md @@ -57,8 +57,9 @@ Following is an example gdf to encode to .h264 stream from a YUV input file import vx_amd_media # read input sequences -data yuvimg = image:1920,1080,IYUV:read,input.yuv -data vid1 = scalar:STRING,"{4, 30, 0, 15}," +data yuvimg = image:1920,1080,NV12:read,input.yuv +data vid1 = scalar:STRING,"fname_with_full_path.264" data aux_output = array:UINT8,256 -node com.amd.amd_media.encode yuvimg vid1 NULL aux_output +data gpu_mode = scalar:BOOL,FALSE +node com.amd.amd_media.encode yuvimg vid1 NULL aux_output gpu_mode ``` diff --git a/amd_openvx_extensions/amd_media/decoder.cpp b/amd_openvx_extensions/amd_media/decoder.cpp index 58bd138e74..db9a195eab 100644 --- a/amd_openvx_extensions/amd_media/decoder.cpp +++ b/amd_openvx_extensions/amd_media/decoder.cpp @@ -567,7 +567,9 @@ vx_status CLoomIoMediaDecoder::Initialize() #endif ERROR_CHECK_NULLPTR(cmdq); for (int i = 0; i < DECODE_BUFFER_POOL_SIZE; i++) { - mem[i] = clCreateBuffer(context, CL_MEM_READ_WRITE, gpuOffset + gpuStride * height, nullptr, nullptr); + int buf_height = height; + if (outputFormat == AV_PIX_FMT_NV12) buf_height = height + (height>>1); + mem[i] = clCreateBuffer(context, CL_MEM_READ_WRITE, gpuOffset + gpuStride * buf_height, nullptr, nullptr); ERROR_CHECK_NULLPTR(mem[i]); } #elif ENABLE_HIP @@ -583,7 +585,9 @@ vx_status CLoomIoMediaDecoder::Initialize() } for (int i = 0; i < DECODE_BUFFER_POOL_SIZE; i++) { - err = hipHostMalloc((void **)&decodeBuffer[i], gpuOffset + gpuStride * height); + int buf_height = height; + if (outputFormat == AV_PIX_FMT_NV12) buf_height = height + (height>>1); + err = hipHostMalloc((void **)&decodeBuffer[i], gpuOffset + gpuStride * buf_height); if (err != hipSuccess) { vxAddLogEntry(NULL, VX_FAILURE, "ERROR: hipHostMalloc => %d (failed)\n", err); return VX_FAILURE; @@ -595,7 +599,7 @@ vx_status CLoomIoMediaDecoder::Initialize() return VX_FAILURE; } } else { - err = hipMalloc(&mem[i], gpuOffset + gpuStride * height); + err = hipMalloc(&mem[i], gpuOffset + gpuStride * buf_height); if (err != hipSuccess) { vxAddLogEntry(NULL, VX_FAILURE, "ERROR: hipMalloc(%p) => %d (failed)\n", mem[i], err); return VX_FAILURE; @@ -933,6 +937,7 @@ static vx_status VX_CALLBACK amd_media_decode_initialize(vx_node node, const vx_ ERROR_CHECK_STATUS(vxCopyScalar((vx_scalar)parameters[4], &enableUserBufferGPU, VX_READ_ONLY, VX_MEMORY_TYPE_HOST)); ERROR_CHECK_STATUS(vxQueryImage((vx_image)parameters[1], VX_IMAGE_ATTRIBUTE_AMD_GPU_BUFFER_STRIDE, &stride, sizeof(stride))); ERROR_CHECK_STATUS(vxQueryImage((vx_image)parameters[1], VX_IMAGE_ATTRIBUTE_AMD_GPU_BUFFER_OFFSET, &offset, sizeof(offset))); + if (stride == 0) stride = width; // in case stride is not set for the buffer } // create and initialize decoder diff --git a/amd_openvx_extensions/amd_media/encoder.cpp b/amd_openvx_extensions/amd_media/encoder.cpp index 9780a89073..ebe52bfd72 100644 --- a/amd_openvx_extensions/amd_media/encoder.cpp +++ b/amd_openvx_extensions/amd_media/encoder.cpp @@ -26,11 +26,13 @@ THE SOFTWARE. #include #include #include +#include +#include +#include // GPU configuration #define ENCODE_ENABLE_GPU 1 // enable use of GPU buffers -#if ENCODE_ENABLE_GPU #if __APPLE__ #include #else @@ -40,7 +42,6 @@ THE SOFTWARE. #include "hip/hip_runtime.h" #endif #endif -#endif #define DEFAULT_MBPS 4.0f #define DEFAULT_FPS 30.0f @@ -67,6 +68,9 @@ class CLoomIoMediaEncoder { vx_status Initialize(); vx_status ProcessFrame(vx_image input_image, vx_array input_aux, vx_array output_aux); vx_status UpdateBufferGPU(vx_image input_image, vx_array input_aux); + void SetEnableUserBufferGPUMode(vx_bool bEnable) { m_enableUserBufferGPU = bEnable;}; + vx_bool m_enableUserBufferGPU; + protected: typedef enum { cmd_abort, cmd_encode } command; void EncodeLoop(); @@ -74,11 +78,11 @@ class CLoomIoMediaEncoder { void PushAck(int ack); command PopCommand(); int PopAck(); + private: vx_node node; std::string ioConfig; - int width; - int height; + vx_uint32 width, height; vx_df_image format; AVPixelFormat inputFormat; int stride, offset; @@ -88,14 +92,12 @@ class CLoomIoMediaEncoder { AVCodecContext * videoCodecContext; AVCodec * videoCodec; SwsContext * conversionContext; -#if ENCODE_ENABLE_GPU void* mem[ENCODE_BUFFER_POOL_SIZE]; #if ENABLE_OPENCL cl_command_queue cmdq; #elif ENABLE_HIP hipDeviceProp_t hip_dev_prop; - uint8_t *hostBuffer[ENCODE_BUFFER_POOL_SIZE]; -#endif + uint8_t *hostBuffer; #endif AVFrame * videoFrame[ENCODE_BUFFER_POOL_SIZE]; uint8_t * outputBuffer; @@ -115,6 +117,9 @@ class CLoomIoMediaEncoder { int bframes, gopsize; }; +// helper function for spliting streams. +extern std::vector split(const std::string& s, char delimiter); + void CLoomIoMediaEncoder::PushCommand(CLoomIoMediaEncoder::command cmd) { std::unique_lock lock(mutexCmd); @@ -148,19 +153,18 @@ int CLoomIoMediaEncoder::PopAck() } CLoomIoMediaEncoder::CLoomIoMediaEncoder(vx_node node_, const char ioConfig_[], vx_uint32 width_, vx_uint32 height_, vx_df_image format_, vx_uint32 stride_, vx_uint32 offset_, vx_size input_aux_data_max_size_) - : node{ node_ }, ioConfig(ioConfig_), width{ static_cast(width_) }, height{ static_cast(height_) }, format{ format_ }, + : node{ node_ }, ioConfig(ioConfig_), width{ width_ }, height{ height_ }, format{ format_ }, stride{ static_cast(stride_) }, offset{ static_cast(offset_) }, input_aux_data_max_size{ input_aux_data_max_size_ }, inputFrameCount{ 0 }, encodeFrameCount{ 0 }, threadTerminated{ false }, inputFormat{ AV_PIX_FMT_UYVY422 }, outputBuffer{ nullptr }, outputBufferSize{ 1000000 }, fpOutput{ nullptr }, formatContext{ nullptr }, videoStream{ nullptr }, outputAuxBuffer{ nullptr }, outputAuxLength{ 0 }, videoCodecContext{ nullptr }, videoCodec{ nullptr }, conversionContext{ nullptr }, thread{ nullptr }, mbps{ DEFAULT_MBPS }, fps{ DEFAULT_FPS }, gopsize{ DEFAULT_GOPSIZE }, bframes{ DEFAULT_BFRAMES } { -#if ENCODE_ENABLE_GPU + m_enableUserBufferGPU = false; // use host buffers by default #if ENABLE_OPENCL cmdq = nullptr; #endif memset(mem, 0, sizeof(mem)); -#endif memset(videoFrame, 0, sizeof(videoFrame)); outputAuxBuffer = new uint8_t[input_aux_data_max_size + sizeof(LoomIoMediaEncoderAuxInfo)](); // initialize freq inside GetTimeInMicroseconds() @@ -191,34 +195,14 @@ CLoomIoMediaEncoder::~CLoomIoMediaEncoder() // release GPU and media resources if (outputBuffer) aligned_free(outputBuffer); -#if ENCODE_ENABLE_GPU -#if ENABLE_OPENCL - if (cmdq) clReleaseCommandQueue(cmdq); - for (int i = 0; i < ENCODE_BUFFER_POOL_SIZE; i++) { - if (mem[i]) clReleaseMemObject((cl_mem)mem[i]); + if (m_enableUserBufferGPU) { + #if ENABLE_OPENCL + if (cmdq) clReleaseCommandQueue(cmdq); + #elif ENABLE_HIP + if (hostBuffer) hipHostFree((void *)hostBuffer); + #endif } -#elif ENABLE_HIP - hipError_t status; - for (int i = 0; i < ENCODE_BUFFER_POOL_SIZE; i++) { - if (hostBuffer[i]) { - status = hipHostFree(hostBuffer[i]); - if (status != hipSuccess) { - vxAddLogEntry(NULL, VX_FAILURE, "ERROR: hipHostFree(%p) failed (%d)\n", hostBuffer[i], status); - } - } - if (mem[i]) { - if (hip_dev_prop.canMapHostMemory) { - mem[i] = nullptr; - } else { - status = hipFree(mem[i]); - if (status != hipSuccess) { - vxAddLogEntry(NULL, VX_FAILURE, "ERROR: hipFree(%p) failed (%d)\n", mem[i], status); - } - } - } - } -#endif -#endif + for (int i = 0; i < ENCODE_BUFFER_POOL_SIZE; i++) { if (videoFrame[i]) { if (videoFrame[i]->data[0]) aligned_free(videoFrame[i]->data[0]); @@ -231,14 +215,17 @@ CLoomIoMediaEncoder::~CLoomIoMediaEncoder() avcodec_close(videoCodecContext); av_free(videoCodecContext); } - if (videoCodec) av_free(videoCodec); if (outputAuxBuffer) delete[] outputAuxBuffer; } vx_status CLoomIoMediaEncoder::Initialize() { + const char * outFileName = nullptr; // check for valid image type support and get stride in bytes (aligned to 16-byte boundary) - if (format == VX_DF_IMAGE_UYVY) { + if (format == VX_DF_IMAGE_NV12) { + inputFormat = AV_PIX_FMT_NV12; + } + else if (format == VX_DF_IMAGE_UYVY) { inputFormat = AV_PIX_FMT_UYVY422; } else if (format == VX_DF_IMAGE_YUYV) { @@ -253,6 +240,26 @@ vx_status CLoomIoMediaEncoder::Initialize() } // get media configuration and fileName + std::vector mediainfo = split(ioConfig, ','); + if (mediainfo.size() < 1) { + vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: invalid input arguments"); + return VX_ERROR_INVALID_LINK; + } + if (mediainfo.size() == 1) { + outFileName = mediainfo[0].c_str(); + } + else if (mediainfo.size() == 5) { + outFileName = mediainfo[0].c_str(); + mbps = atoi(mediainfo[1].c_str()); + fps = atoi(mediainfo[2].c_str()); + bframes = atoi(mediainfo[3].c_str()); + gopsize = atoi(mediainfo[4].c_str()); + } else{ + vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: invalid input arguments"); + return VX_ERROR_INVALID_LINK; + } + +#if 0 // todo:: runvx has issue taking this string format const char * s = ioConfig.c_str(); if (*s == '{') { sscanf(s + 1, "%f,%f,%d,%d", &mbps, &fps, &bframes, &gopsize); @@ -266,6 +273,7 @@ vx_status CLoomIoMediaEncoder::Initialize() } } const char * fileName = s; +#endif // open media file and initialize codec ERROR_CHECK_STATUS(initialize_ffmpeg()); @@ -288,36 +296,35 @@ vx_status CLoomIoMediaEncoder::Initialize() videoFrame[i]->linesize[0] = width; videoFrame[i]->linesize[1] = width; videoFrame[i]->format = AV_PIX_FMT_NV12; -#if ENCODE_ENABLE_GPU - // just one videoFrame[0] is sufficient - break; -#endif + // just one videoFrame[0] is sufficient for GPU mode + if (m_enableUserBufferGPU) + break; } outputBufferSize = 1024*1024; ERROR_CHECK_NULLPTR(outputBuffer = aligned_alloc(outputBufferSize)); // open output file - if (strlen(fileName) > 4 && !strcmp(fileName + strlen(fileName) - 4, ".264")) { - fpOutput = fopen(fileName, "wb"); + if (strlen(outFileName) > 4 && !strcmp(outFileName + strlen(outFileName) - 4, ".264")) { + fpOutput = fopen(outFileName, "wb"); if (!fpOutput) { - vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: CLoomIoMediaEncoder::Initialize: unable to create: %s", fileName); + vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: CLoomIoMediaEncoder::Initialize: unable to create: %s", outFileName); return VX_ERROR_INVALID_LINK; } } else { - int status = avformat_alloc_output_context2(&formatContext, nullptr, nullptr, fileName); + int status = avformat_alloc_output_context2(&formatContext, nullptr, nullptr, outFileName); if (status < 0) { - vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: CLoomIoMediaEncoder::Initialize: avformat_alloc_output_context2(...,%s) failed (%d)", fileName, status); + vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: CLoomIoMediaEncoder::Initialize: avformat_alloc_output_context2(...,%s) failed (%d)", outFileName, status); return VX_ERROR_INVALID_LINK; } ERROR_CHECK_NULLPTR(videoStream = avformat_new_stream(formatContext, videoCodec)); videoStream->id = formatContext->nb_streams - 1; if (formatContext->oformat->flags & AVFMT_GLOBALHEADER) videoCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; - av_dump_format(formatContext, 0, fileName, 1); + av_dump_format(formatContext, 0, outFileName, 1); if (!(formatContext->oformat->flags & AVFMT_NOFILE)) { - if ((status = avio_open(&formatContext->pb, fileName, AVIO_FLAG_WRITE)) < 0) { - vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: CLoomIoMediaEncoder::Initialize: avio_open(...,%s) failed (%d)", fileName, status); + if ((status = avio_open(&formatContext->pb, outFileName, AVIO_FLAG_WRITE)) < 0) { + vxAddLogEntry((vx_reference)node, VX_ERROR_INVALID_LINK, "ERROR: CLoomIoMediaEncoder::Initialize: avio_open(...,%s) failed (%d)", outFileName, status); return VX_ERROR_INVALID_LINK; } } @@ -331,57 +338,33 @@ vx_status CLoomIoMediaEncoder::Initialize() ERROR_CHECK_STATUS(avformat_write_header(formatContext, nullptr)); } -#if ENCODE_ENABLE_GPU -#if ENABLE_OPENCL - // allocate OpenCL encode buffers - cl_context context = nullptr; - ERROR_CHECK_STATUS(vxQueryContext(vxGetContext((vx_reference)node), VX_CONTEXT_ATTRIBUTE_AMD_OPENCL_CONTEXT, &context, sizeof(context))); - cl_device_id device_id = nullptr; - ERROR_CHECK_STATUS(clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(device_id), &device_id, nullptr)); -#if defined(CL_VERSION_2_0) - cmdq = clCreateCommandQueueWithProperties(context, device_id, 0, nullptr); -#else - cmdq = clCreateCommandQueue(context, device_id, 0, nullptr); -#endif - ERROR_CHECK_NULLPTR(cmdq); - for (int i = 0; i < ENCODE_BUFFER_POOL_SIZE; i++) { - mem[i] = clCreateBuffer(context, CL_MEM_READ_WRITE, offset + stride * height, nullptr, nullptr); - ERROR_CHECK_NULLPTR(mem[i]); - } - -#elif ENABLE_HIP - int hip_device = -1; - ERROR_CHECK_STATUS(vxQueryContext(vxGetContext((vx_reference)node), VX_CONTEXT_ATTRIBUTE_AMD_HIP_DEVICE, &hip_device, sizeof(hip_device))); - if (hip_device < 0) { - return VX_FAILURE; - } - hipError_t err; - - for (int i = 0; i < ENCODE_BUFFER_POOL_SIZE; i++) { - err = hipHostMalloc((void **)&hostBuffer[i], offset + stride * height); - if (err != hipSuccess) { - vxAddLogEntry(NULL, VX_FAILURE, "ERROR: hipHostMalloc => %d (failed)\n", err); + if (m_enableUserBufferGPU) { + #if ENABLE_OPENCL + cl_context context = nullptr; + ERROR_CHECK_STATUS(vxQueryContext(vxGetContext((vx_reference)node), VX_CONTEXT_ATTRIBUTE_AMD_OPENCL_CONTEXT, &context, sizeof(context))); + cl_device_id device_id = nullptr; + ERROR_CHECK_STATUS(clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(device_id), &device_id, nullptr)); + #if defined(CL_VERSION_2_0) + cmdq = clCreateCommandQueueWithProperties(context, device_id, 0, nullptr); + #else + cmdq = clCreateCommandQueue(context, device_id, 0, nullptr); + #endif + ERROR_CHECK_NULLPTR(cmdq); + #elif ENABLE_HIP + hostBuffer = nullptr; + int hip_device = -1; + ERROR_CHECK_STATUS(vxQueryContext(vxGetContext((vx_reference)node), VX_CONTEXT_ATTRIBUTE_AMD_HIP_DEVICE, &hip_device, sizeof(hip_device))); + if (hip_device < 0) { return VX_FAILURE; } - if (hip_dev_prop.canMapHostMemory) { - err = hipHostGetDevicePointer((void **)&mem[i], hostBuffer[i], 0 ); - if (err != hipSuccess) { - vxAddLogEntry(NULL, VX_FAILURE, "ERROR: hipHostGetDevicePointer => %d (failed)\n", err); - return VX_FAILURE; - } - } else { - err = hipMalloc(&mem[i], offset + stride * height); - if (err != hipSuccess) { - vxAddLogEntry(NULL, VX_FAILURE, "ERROR: hipMalloc(%p) => %d (failed)\n", mem[i], err); - return VX_FAILURE; - } + int bufHeight = (inputFormat == AV_PIX_FMT_NV12) ? (height + (height>>1)) : height; + hipError_t err = hipHostMalloc((void **)&hostBuffer, offset + stride * bufHeight, hipHostMallocDefault); + if (err != hipSuccess) { + vxAddLogEntry((vx_reference)node, VX_ERROR_NO_MEMORY, "ERROR: CLoomIoMediaEncoder::Memory allocation failed \n"); } + #endif } - -#endif -#endif - // start encoder thread inputFrameCount = 0; encodeFrameCount = 0; @@ -390,7 +373,7 @@ vx_status CLoomIoMediaEncoder::Initialize() ERROR_CHECK_NULLPTR(thread); // debug info - vxAddLogEntry((vx_reference)node, VX_SUCCESS, "INFO: writing %dx%d %.2fmbps %.2ffps gopsize=%d bframes=%d video into %s", width, height, mbps, fps, gopsize, bframes, fileName); + vxAddLogEntry((vx_reference)node, VX_SUCCESS, "INFO: writing %dx%d %.2fmbps %.2ffps gopsize=%d bframes=%d video into %s", width, height, mbps, fps, gopsize, bframes, outFileName); return VX_SUCCESS; } @@ -398,13 +381,6 @@ vx_status CLoomIoMediaEncoder::Initialize() #if ENCODE_ENABLE_GPU vx_status CLoomIoMediaEncoder::UpdateBufferGPU(vx_image input_image, vx_array input_aux) { - // wait until there is an ACK from encoder thread - int ack = PopAck(); - if ((ack < 0) || threadTerminated) { - // nothing to process, so abandon the graph execution - return VX_ERROR_GRAPH_ABANDONED; - } - // update output auxiliary information outputAuxLength = 0; if (input_aux) { @@ -422,49 +398,46 @@ vx_status CLoomIoMediaEncoder::UpdateBufferGPU(vx_image input_image, vx_array in // pick the OpenCL buffer frame from pool int bufId = inputFrameCount % ENCODE_BUFFER_POOL_SIZE; inputFrameCount++; - -#if ENABLE_OPENCL - ERROR_CHECK_STATUS(vxSetImageAttribute(input_image, VX_IMAGE_ATTRIBUTE_AMD_OPENCL_BUFFER, &mem[bufId], sizeof(void*))); -#elif ENABLE_HIP - ERROR_CHECK_STATUS(vxSetImageAttribute(input_image, VX_IMAGE_ATTRIBUTE_AMD_HIP_BUFFER, &mem[bufId], sizeof(void*))); -#endif - + if (m_enableUserBufferGPU) { + #if ENABLE_OPENCL + ERROR_CHECK_STATUS(vxQueryImage(input_image, VX_IMAGE_ATTRIBUTE_AMD_OPENCL_BUFFER, &mem[bufId], sizeof(void*))); + #elif ENABLE_HIP + ERROR_CHECK_STATUS(vxQueryImage(input_image, VX_IMAGE_ATTRIBUTE_AMD_HIP_BUFFER, &mem[bufId], sizeof(void*))); + #endif + } return VX_SUCCESS; } #endif vx_status CLoomIoMediaEncoder::ProcessFrame(vx_image input_image, vx_array input_aux, vx_array output_aux) { -#if ENCODE_ENABLE_GPU - if (threadTerminated) -#else // wait until there is an ACK from encoder thread int ack = PopAck(); if ((ack < 0) || threadTerminated) -#endif { // nothing to process, so abandon the graph execution return VX_ERROR_GRAPH_ABANDONED; } -#if ENCODE_ENABLE_GPU - // just submit GPU buffer for encoding - PushCommand(cmd_encode); -#else - // format convert input image into encode buffer - int bufId = inputFrameCount % ENCODE_BUFFER_POOL_SIZE; inputFrameCount++; - vx_rectangle_t rect = { 0, 0, width, height }; - vx_map_id map_id; vx_imagepatch_addressing_t addr; - uint8_t * ptr = nullptr; - ERROR_CHECK_STATUS(vxMapImagePatch(input_image, &rect, 0, &map_id, &addr, (void **)&ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST, VX_NOGAP_X)); - int status = sws_scale(conversionContext, &ptr, &addr.stride_y, 0, height, videoFrame[bufId]->data, videoFrame[bufId]->linesize); - ERROR_CHECK_STATUS(vxUnmapImagePatch(input_image, map_id)); - if (status < 0) { - vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::ProcessFrame: sws_scale() failed (%d)\n", status); - return VX_FAILURE; - } - // submit encoding - PushCommand(cmd_encode); -#endif + if (m_enableUserBufferGPU) { + UpdateBufferGPU(input_image, input_aux); + // just submit GPU buffer for encoding + PushCommand(cmd_encode); + } else { + // format convert input image into encode buffer + int bufId = inputFrameCount % ENCODE_BUFFER_POOL_SIZE; inputFrameCount++; + vx_rectangle_t rect = { 0, 0, width, height }; + vx_map_id map_id; vx_imagepatch_addressing_t addr; + uint8_t * ptr = nullptr; + ERROR_CHECK_STATUS(vxMapImagePatch(input_image, &rect, 0, &map_id, &addr, (void **)&ptr, VX_READ_ONLY, VX_MEMORY_TYPE_HOST, VX_NOGAP_X)); + int status = sws_scale(conversionContext, &ptr, &addr.stride_y, 0, height, videoFrame[bufId]->data, videoFrame[bufId]->linesize); + ERROR_CHECK_STATUS(vxUnmapImagePatch(input_image, map_id)); + if (status < 0) { + vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::ProcessFrame: sws_scale() failed (%d)\n", status); + return VX_FAILURE; + } + // submit encoding + PushCommand(cmd_encode); + } // copy input aux data to output, if there is input aux data. ERROR_CHECK_STATUS(vxTruncateArray(output_aux, 0)); @@ -492,68 +465,64 @@ void CLoomIoMediaEncoder::EncodeLoop() // get the bufId to process int bufId = (encodeFrameCount % ENCODE_BUFFER_POOL_SIZE); int got_output = 0; -#if ENCODE_ENABLE_GPU // format convert input image into encode buffer -#if ENABLE_OPENCL - cl_int err = -1; - uint8_t * ptr = (uint8_t *)clEnqueueMapBuffer(cmdq, (cl_mem)mem[bufId], CL_TRUE, CL_MAP_READ, offset, height * stride, 0, nullptr, nullptr, &err); - if (err < 0 || !ptr) { - vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: clEnqueueMapBuffer() failed (%d)\n", err); - threadTerminated = true; - PushAck(-1); - return; - } - clFinish(cmdq); - status = sws_scale(conversionContext, &ptr, &stride, 0, height, videoFrame[0]->data, videoFrame[0]->linesize); - err = clEnqueueUnmapMemObject(cmdq, (cl_mem)mem[bufId], ptr, 0, nullptr, nullptr); - if (err < 0) { - vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: clEnqueueUnmapMemObject() failed (%d)\n", err); - threadTerminated = true; - PushAck(-1); - return; - } - clFinish(cmdq); - if (status < 0) { - vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: sws_scale() failed (%d)\n", status); - threadTerminated = true; - PushAck(-1); - return; - } -#elif ENABLE_HIP - hipError_t err; - if (!hip_dev_prop.canMapHostMemory) { - err = hipMemcpyDtoH((void *)hostBuffer[bufId], ((uint8_t *)mem[bufId] + offset), height * stride); + if ( m_enableUserBufferGPU) { + int mapHeight = (inputFormat == AV_PIX_FMT_NV12)? (height + (height>>1)) : height; + #if ENABLE_OPENCL + cl_int err = -1; + uint8_t * ptr = (uint8_t *)clEnqueueMapBuffer(cmdq, (cl_mem)mem[bufId], CL_TRUE, CL_MAP_READ, offset, mapHeight * stride, 0, nullptr, nullptr, &err); + if (err < 0 || !ptr) { + vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: clEnqueueMapBuffer() failed (%d)\n", err); + threadTerminated = true; + PushAck(-1); + return; + } + clFinish(cmdq); + uint8_t *src_data[4] = {0}; + int src_linesize[4] = {stride}; + src_data[0] = ptr; + if (inputFormat == AV_PIX_FMT_NV12) src_data[1] = src_data[0] + height*stride; + status = sws_scale(conversionContext, src_data, src_linesize, 0, height, videoFrame[0]->data, videoFrame[0]->linesize); + + err = clEnqueueUnmapMemObject(cmdq, (cl_mem)mem[bufId], ptr, 0, nullptr, nullptr); + if (err < 0) { + vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: clEnqueueUnmapMemObject() failed (%d)\n", err); + threadTerminated = true; + PushAck(-1); + return; + } + clFinish(cmdq); + if (status < 0) { + vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: sws_scale() failed (%d)\n", status); + threadTerminated = true; + PushAck(-1); + return; + } + #elif ENABLE_HIP + hipError_t err; + err = hipMemcpyDtoH((void *)hostBuffer, ((uint8_t *)mem[bufId] + offset), mapHeight * stride); if (err != hipSuccess) { vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: hipMemcpyDtoH failed => %d\n", err); threadTerminated = true; PushAck(-1); return; } - } - - status = sws_scale(conversionContext, &hostBuffer[bufId], &stride, 0, height, videoFrame[0]->data, videoFrame[0]->linesize); - - if (!hip_dev_prop.canMapHostMemory) { - err = hipMemcpyHtoD((void *)((uint8_t *)mem[bufId] + offset), hostBuffer[bufId], height * stride); - if (err != hipSuccess) { - vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: hipMemcpyHtoD(buf[%d]) failed (%d)\n", bufId, err); + uint8_t *src_data[4] = {0}; + int src_linesize[4] = {stride}; + src_data[0] = hostBuffer; + if (inputFormat == AV_PIX_FMT_NV12) src_data[1] = src_data[0] + height*stride; + + status = sws_scale(conversionContext, src_data, src_linesize, 0, height, videoFrame[0]->data, videoFrame[0]->linesize); + if (status < 0) { + vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: sws_scale() failed (%d)\n", status); threadTerminated = true; PushAck(-1); return; } + #endif + // reset bufId to zero because only videoFrame[0] is valid + bufId = 0; } - - if (status < 0) { - vxAddLogEntry((vx_reference)node, VX_FAILURE, "ERROR: CLoomIoMediaEncoder::EncodeLoop: sws_scale() failed (%d)\n", status); - threadTerminated = true; - PushAck(-1); - return; - } -#endif - // reset bufId to zero because only videoFrame[0] is valid - bufId = 0; - -#endif // encode video frame and write output to file videoFrame[bufId]->pts = pts; status = avcodec_encode_video2(videoCodecContext, &pkt, videoFrame[bufId], &got_output); @@ -608,19 +577,6 @@ void CLoomIoMediaEncoder::EncodeLoop() PushAck(-1); } -#if ENCODE_ENABLE_GPU -//! \brief The kernel execution. -static vx_status VX_CALLBACK amd_media_encode_gpu_buffer_update_callback(vx_node node, const vx_reference parameters[], vx_uint32 num) -{ - // get encoder and input image - CLoomIoMediaEncoder * encoder = nullptr; - ERROR_CHECK_STATUS(vxQueryNode(node, VX_NODE_LOCAL_DATA_PTR, &encoder, sizeof(encoder))); - if (!encoder) return VX_FAILURE; - - return encoder->UpdateBufferGPU((vx_image)parameters[1], (vx_array)parameters[2]); -} -#endif - //! \brief The kernel execution. static vx_status VX_CALLBACK amd_media_encode_kernel(vx_node node, const vx_reference * parameters, vx_uint32 num) { @@ -628,13 +584,13 @@ static vx_status VX_CALLBACK amd_media_encode_kernel(vx_node node, const vx_refe CLoomIoMediaEncoder * encoder = nullptr; ERROR_CHECK_STATUS(vxQueryNode(node, VX_NODE_LOCAL_DATA_PTR, &encoder, sizeof(encoder))); if (!encoder) return VX_FAILURE; - return encoder->ProcessFrame((vx_image)parameters[1], (vx_array)parameters[2], (vx_array)parameters[3]); } //! \brief The kernel initializer. static vx_status VX_CALLBACK amd_media_encode_initialize(vx_node node, const vx_reference * parameters, vx_uint32 num) { + vx_bool enableUserBufferGPU = false; // get input parameters char ioConfig[VX_MAX_STRING_BUFFER_SIZE_AMD]; vx_uint32 width = 0, height = 0, stride = 0, offset = 0; @@ -649,9 +605,19 @@ static vx_status VX_CALLBACK amd_media_encode_initialize(vx_node node, const vx_ if (parameters[2]) { ERROR_CHECK_STATUS(vxQueryArray((vx_array)parameters[2], VX_ARRAY_CAPACITY, &input_aux_data_max_size, sizeof(input_aux_data_max_size))); } + if (parameters[4]) { + ERROR_CHECK_STATUS(vxCopyScalar((vx_scalar)parameters[4], &enableUserBufferGPU, VX_READ_ONLY, VX_MEMORY_TYPE_HOST)); + } + // create and initialize encoder + if (stride == 0) stride = width; // stride can't be zero CLoomIoMediaEncoder * encoder = new CLoomIoMediaEncoder(node, ioConfig, width, height, format, stride, offset, input_aux_data_max_size); ERROR_CHECK_STATUS(vxSetNodeAttribute(node, VX_NODE_LOCAL_DATA_PTR, &encoder, sizeof(encoder))); + if (parameters[4]) { + printf("encoder: GPU mode : %d\n", enableUserBufferGPU); + encoder->SetEnableUserBufferGPUMode(enableUserBufferGPU); + } + ERROR_CHECK_STATUS(encoder->Initialize()); return VX_SUCCESS; @@ -686,7 +652,7 @@ static vx_status VX_CALLBACK amd_media_encode_validate(vx_node node, const vx_re ERROR_CHECK_STATUS(vxQueryImage((vx_image)parameters[1], VX_IMAGE_WIDTH, &width, sizeof(width))); ERROR_CHECK_STATUS(vxQueryImage((vx_image)parameters[1], VX_IMAGE_HEIGHT, &height, sizeof(height))); ERROR_CHECK_STATUS(vxQueryImage((vx_image)parameters[1], VX_IMAGE_FORMAT, &format, sizeof(format))); - if (format != VX_DF_IMAGE_UYVY && format != VX_DF_IMAGE_YUYV && format != VX_DF_IMAGE_RGB) + if (format != VX_DF_IMAGE_UYVY && format != VX_DF_IMAGE_YUYV && format != VX_DF_IMAGE_RGB && format != VX_DF_IMAGE_NV12) return VX_ERROR_INVALID_FORMAT; // check input auxiliary data parameter if (parameters[2]) { @@ -707,6 +673,17 @@ static vx_status VX_CALLBACK amd_media_encode_validate(vx_node node, const vx_re return VX_ERROR_INVALID_TYPE; ERROR_CHECK_STATUS(vxSetMetaFormatAttribute(metas[3], VX_ARRAY_ITEMTYPE, &itemtype, sizeof(itemtype))); ERROR_CHECK_STATUS(vxSetMetaFormatAttribute(metas[3], VX_ARRAY_CAPACITY, &capacity, sizeof(capacity))); + vx_bool enableUserBufferGPU = false; + if (parameters[4]) { + vx_enum scalar_type; + ERROR_CHECK_STATUS(vxQueryScalar((vx_scalar)parameters[4], VX_SCALAR_TYPE, &scalar_type, sizeof(scalar_type))); + if(scalar_type != VX_TYPE_BOOL) return VX_ERROR_INVALID_TYPE; + ERROR_CHECK_STATUS(vxCopyScalar((vx_scalar)parameters[4], &enableUserBufferGPU, VX_READ_ONLY, VX_MEMORY_TYPE_HOST)); + // do we need to do the following? + ERROR_CHECK_STATUS(vxSetMetaFormatAttribute(metas[1], VX_IMAGE_ATTRIBUTE_AMD_ENABLE_USER_BUFFER_GPU, &enableUserBufferGPU, sizeof(enableUserBufferGPU))); +// printf("decoder validate:: set enableUserBufferGPU: %d\n", enableUserBufferGPU); + } + return VX_SUCCESS; } @@ -715,21 +692,16 @@ vx_status amd_media_encode_publish(vx_context context) { // add kernel to the context with callbacks vx_kernel kernel = vxAddUserKernel(context, "com.amd.amd_media.encode", AMDOVX_KERNEL_AMD_MEDIA_ENCODE, - amd_media_encode_kernel, 4, amd_media_encode_validate, + amd_media_encode_kernel, 5, amd_media_encode_validate, amd_media_encode_initialize, amd_media_encode_deinitialize); ERROR_CHECK_OBJECT(kernel); // set kernel parameters - ERROR_CHECK_STATUS(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); // media config+filename: "[{mbps,fps,bframes,gopsize},]filename.mp4" + ERROR_CHECK_STATUS(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED)); // media config+filename: "[mbps,fps,bframes,gopsize],filename.mp4" ERROR_CHECK_STATUS(vxAddParameterToKernel(kernel, 1, VX_INPUT, VX_TYPE_IMAGE, VX_PARAMETER_STATE_REQUIRED)); // input image ERROR_CHECK_STATUS(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_ARRAY, VX_PARAMETER_STATE_OPTIONAL)); // input auxiliary data (optional) ERROR_CHECK_STATUS(vxAddParameterToKernel(kernel, 3, VX_OUTPUT, VX_TYPE_ARRAY, VX_PARAMETER_STATE_REQUIRED)); // output auxiliary data - -#if ENCODE_ENABLE_GPU - // register amd_kernel_gpu_buffer_update_callback_f for input image - AgoKernelGpuBufferUpdateInfo info = { amd_media_encode_gpu_buffer_update_callback, 1 }; - ERROR_CHECK_STATUS(vxSetKernelAttribute(kernel, VX_KERNEL_ATTRIBUTE_AMD_GPU_BUFFER_UPDATE_CALLBACK, &info, sizeof(info))); -#endif + ERROR_CHECK_STATUS(vxAddParameterToKernel(kernel, 4, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_OPTIONAL)); // input: to set enableUserBufferGPU flag // finalize and release kernel object ERROR_CHECK_STATUS(vxFinalizeKernel(kernel)); @@ -738,21 +710,24 @@ vx_status amd_media_encode_publish(vx_context context) return VX_SUCCESS; } -VX_API_ENTRY vx_node VX_API_CALL amdMediaEncoderNode(vx_graph graph, const char *output_str, vx_image input, vx_array aux_data_in, vx_array aux_data_out) +VX_API_ENTRY vx_node VX_API_CALL amdMediaEncoderNode(vx_graph graph, const char *output_str, vx_image input, vx_array aux_data_in, vx_array aux_data_out, vx_bool enable_gpu_input) { vx_node node = NULL; vx_context context = vxGetContext((vx_reference)graph); if (vxGetStatus((vx_reference)context) == VX_SUCCESS) { vx_scalar s_output = vxCreateScalar(context, VX_TYPE_STRING_AMD, output_str); + vx_scalar s_enable_gpu_input = vxCreateScalar(context, VX_TYPE_BOOL, &enable_gpu_input); vx_reference params[] = { (vx_reference)s_output, (vx_reference)input, (vx_reference)aux_data_in, (vx_reference)aux_data_out, + (vx_reference)s_enable_gpu_input, }; if (vxGetStatus((vx_reference)s_output) == VX_SUCCESS) { node = createMediaNode(graph, "com.amd.amd_media.encode", params, sizeof(params) / sizeof(params[0])); // added node to graph vxReleaseScalar(&s_output); + vxReleaseScalar(&s_enable_gpu_input); } } return node; diff --git a/amd_openvx_extensions/amd_media/include/vx_amd_media.h b/amd_openvx_extensions/amd_media/include/vx_amd_media.h index f0ed72fd44..d12babb46e 100644 --- a/amd_openvx_extensions/amd_media/include/vx_amd_media.h +++ b/amd_openvx_extensions/amd_media/include/vx_amd_media.h @@ -51,7 +51,7 @@ VX_API_ENTRY vx_node VX_API_CALL amdMediaDecoderNode(vx_graph graph, const char * \returns A node reference \ref vx_node. Any possible errors preventing a * successful creation should be checked using \ref vxGetStatus. */ -VX_API_ENTRY vx_node VX_API_CALL amdMediaEncoderNode(vx_graph graph, const char *output_str, vx_image input, vx_array aux_data_in, vx_array aux_data_out); +VX_API_ENTRY vx_node VX_API_CALL amdMediaEncoderNode(vx_graph graph, const char *output_str, vx_image input, vx_array aux_data_in, vx_array aux_data_out, vx_bool enable_gpu_input=false); #ifdef __cplusplus } diff --git a/amd_openvx_extensions/amd_nn/include/vx_amd_nn.h b/amd_openvx_extensions/amd_nn/include/vx_amd_nn.h index 34dfa74524..3f2a4fbd35 100644 --- a/amd_openvx_extensions/amd_nn/include/vx_amd_nn.h +++ b/amd_openvx_extensions/amd_nn/include/vx_amd_nn.h @@ -384,6 +384,6 @@ VX_API_ENTRY vx_node VX_API_CALL vxTileLayer(vx_graph graph, vx_tensor input, vx * \return vx_node. * \returns A node reference \ref vx_node. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus. */ - VX_API_ENTRY vx_node VX_API_CALL vxTensorCompareNode(vx_graph graph, vx_tensor input, vx_tensor input2, vx_tensor output) + VX_API_ENTRY vx_node VX_API_CALL vxTensorCompareNode(vx_graph graph, vx_tensor input, vx_tensor input2, vx_tensor output); #endif diff --git a/amd_openvx_extensions/amd_winml/README.md b/amd_openvx_extensions/amd_winml/README.md index cd27677662..83047935c6 100644 --- a/amd_openvx_extensions/amd_winml/README.md +++ b/amd_openvx_extensions/amd_winml/README.md @@ -30,7 +30,7 @@ The following is a list of WinML functions that have been included in the vx_win + Visual Studio extension for C++/WinRT * Install the latest AMD [drivers](https://www.amd.com/en/support) * Install [OpenCL SDK](https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK/releases/tag/1.0) -* Install [OpenCV 3.4](https://github.com/opencv/opencv/releases/tag/3.4.0) +* Install [OpenCV 4.5.5](https://github.com/opencv/opencv/releases/tag/4.5.5) + Set `OpenCV_DIR` environment variable to `OpenCV/build` folder + Add `%OpenCV_DIR%\x64\vc14\bin` or `%OpenCV_DIR%\x64\vc15\bin` to your `PATH` diff --git a/apps/bubble_pop/CMakeLists.txt b/apps/bubble_pop/CMakeLists.txt index 00c11529b0..fa5b8c5576 100644 --- a/apps/bubble_pop/CMakeLists.txt +++ b/apps/bubble_pop/CMakeLists.txt @@ -39,10 +39,16 @@ else() include_directories (/opt/rocm/mivisionx/include) endif() +set(SHARED_LIB_TYPE so) +if(APPLE) + set(SHARED_LIB_TYPE dylib) +endif() + if(DEFINED OPENVX_LIBRARIES) - message(STATUS "OPENVX_LIBRARIES: \t${OPENVX_LIBRARIES}") + message(STATUS "OPENVX_LIBRARIES: ${OPENVX_LIBRARIES}") else() - set(OPENVX_LIBRARIES /opt/rocm/mivisionx/lib/libopenvx.so) + set(OPENVX_LIBRARIES /opt/rocm/mivisionx/lib/libopenvx.${SHARED_LIB_TYPE}) + message(STATUS "OPENVX_LIBRARIES: ${OPENVX_LIBRARIES}") endif() list (APPEND SOURCES @@ -59,6 +65,14 @@ target_link_libraries(${PROJECT_NAME} ${OPENVX_LIBRARIES} ${OpenCV_LIBRARIES}) add_executable(vxPop source/AMD_app.cpp) target_link_libraries(vxPop ${OPENVX_LIBRARIES} ${OpenCV_LIBRARIES} ${PROJECT_NAME}) +if(${OpenCV_VERSION_MAJOR} EQUAL 4) + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_OPENCV_4=1) + target_compile_definitions(vxPop PUBLIC USE_OPENCV_4=1) +else() + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_OPENCV_4=0) + target_compile_definitions(vxPop PUBLIC USE_OPENCV_4=0) +endif() + file(COPY image DESTINATION ${CMAKE_BINARY_DIR}) file(COPY gdf DESTINATION ${CMAKE_BINARY_DIR}) diff --git a/apps/bubble_pop/README.md b/apps/bubble_pop/README.md index ac40d4ac70..51b10289bd 100644 --- a/apps/bubble_pop/README.md +++ b/apps/bubble_pop/README.md @@ -1,10 +1,10 @@ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) -

+

# OpenVX Samples -Khronos OpenVX™ is an open, royalty-free standard for cross-platform acceleration of computer vision applications. OpenVX enables a performance and power-optimized computer vision processing, especially important in embedded and real-time use cases such as face, body, and gesture tracking, smart video surveillance, advanced driver assistance systems (ADAS), object and scene reconstruction, augmented reality, visual inspection, robotics and more. +Khronos OpenVX™ is an open, royalty-free standard for cross-platform acceleration of computer vision applications. OpenVX enables a performance and power-optimized computer vision processing, especially important in embedded and real-time use cases such as face, body, and gesture tracking, smart video surveillance, advanced driver assistance systems (ADAS), object and scene reconstruction, augmented reality, visual inspection, robotics and more. In this project, we provide OpenVX sample applications to use with any conformant implementation of OpenVX. diff --git a/apps/bubble_pop/include/internal_opencvTunnel.h b/apps/bubble_pop/include/internal_opencvTunnel.h index 3423f12981..c03d05f165 100644 --- a/apps/bubble_pop/include/internal_opencvTunnel.h +++ b/apps/bubble_pop/include/internal_opencvTunnel.h @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,32 +24,48 @@ THE SOFTWARE. #define _CV_TUNNEL_ #if _WIN32 -#include +#include #endif #include "vx_pop.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace cv; using namespace std; -#define STATUS_ERROR_CHECK(call){vx_status status = call; if(status!= VX_SUCCESS) return status;} -#define PARAM_ERROR_CHECK(call){vx_status status = call; if(status!= VX_SUCCESS) goto exit;} +#if USE_OPENCV_4 +#define CV_BGR2RGB COLOR_BGR2RGB +#define CV_AA LINE_AA +#define cvScalar Scalar +#define cvPoint Point +#endif + +#define STATUS_ERROR_CHECK(call) \ + { \ + vx_status status = call; \ + if (status != VX_SUCCESS) \ + return status; \ + } +#define PARAM_ERROR_CHECK(call) \ + { \ + vx_status status = call; \ + if (status != VX_SUCCESS) \ + goto exit; \ + } -int VX_to_CV_Image(Mat**, vx_image); -int VX_to_CV_MATRIX(Mat**, vx_matrix); +int VX_to_CV_Image(Mat **, vx_image); +int VX_to_CV_MATRIX(Mat **, vx_matrix); int CV_to_VX_Pyramid(vx_pyramid, vector); -int CV_to_VX_Image(vx_image, Mat*); +int CV_to_VX_Image(vx_image, Mat *); int CV_to_VX_keypoints(vector, vx_array); int CVPoints2f_to_VX_keypoints(vector, vx_array); @@ -61,19 +77,42 @@ void overlay_bubble(const Mat &, const Mat &, Mat &, Point2i); class Kernellist { public: - struct node{ public: std::function func; node* next; }; + struct node + { + public: + std::function func; + node *next; + }; int count; - Kernellist(int max){ top = nullptr; maxnum = max; count = 0;} + Kernellist(int max) + { + top = nullptr; + maxnum = max; + count = 0; + } vx_status ADD(std::function element) { vx_status status = VX_SUCCESS; - if (count == maxnum) return VX_ERROR_NO_RESOURCES; + if (count == maxnum) + return VX_ERROR_NO_RESOURCES; else { node *newTop = new node; - if (top == nullptr){ newTop->func = element; newTop->next = nullptr; top = newTop; count++; } - else{ newTop->func = element; newTop->next = top; top = newTop; count++; } + if (top == nullptr) + { + newTop->func = element; + newTop->next = nullptr; + top = newTop; + count++; + } + else + { + newTop->func = element; + newTop->next = top; + top = newTop; + count++; + } } return status; } @@ -81,8 +120,15 @@ class Kernellist vx_status REMOVE() { vx_status status = VX_SUCCESS; - if (top == nullptr) return VX_ERROR_NO_RESOURCES; - else{ node * old = top; top = top->next; count--; delete(old); } + if (top == nullptr) + return VX_ERROR_NO_RESOURCES; + else + { + node *old = top; + top = top->next; + count--; + delete (old); + } return status; } @@ -90,18 +136,27 @@ class Kernellist { vx_status status = VX_SUCCESS; - if (top == nullptr) { vxAddLogEntry((vx_reference)context, VX_ERROR_NO_RESOURCES, "PUBLISH Fail, Kernel list is empty"); return VX_ERROR_NO_RESOURCES; } + if (top == nullptr) + { + vxAddLogEntry((vx_reference)context, VX_ERROR_NO_RESOURCES, "PUBLISH Fail, Kernel list is empty"); + return VX_ERROR_NO_RESOURCES; + } else { - node * Kernel = top; - for (int i = 0; i < count; i++){ STATUS_ERROR_CHECK(Kernel->func(context)); Kernel = Kernel->next;} + node *Kernel = top; + for (int i = 0; i < count; i++) + { + STATUS_ERROR_CHECK(Kernel->func(context)); + Kernel = Kernel->next; + } } return status; } private: - node *top; int maxnum; + node *top; + int maxnum; }; static Kernellist *Kernel_List; diff --git a/apps/bubble_pop/include/internal_publishKernels.h b/apps/bubble_pop/include/internal_publishKernels.h index 689822238b..4a0b11a698 100644 --- a/apps/bubble_pop/include/internal_publishKernels.h +++ b/apps/bubble_pop/include/internal_publishKernels.h @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -22,10 +22,10 @@ THE SOFTWARE. #ifndef _PUBLISH_KERNELS_H_ #define _PUBLISH_KERNELS_H_ -#if _WIN32 +#if _WIN32 #define SHARED_PUBLIC __declspec(dllexport) #else -#define SHARED_PUBLIC __attribute__ ((visibility ("default"))) +#define SHARED_PUBLIC __attribute__((visibility("default"))) #endif #include "internal_opencvTunnel.h" @@ -41,7 +41,6 @@ vx_status VX_bubbles_pop_Register(vx_context); vx_status VX_donut_pop_Register(vx_context); #define VX_KERNEL_EXT_POP_BUBBLE_POP_NAME "org.pop.bubble_pop" -#define VX_KERNEL_EXT_POP_DONUT_POP_NAME "org.pop.donut_pop" +#define VX_KERNEL_EXT_POP_DONUT_POP_NAME "org.pop.donut_pop" #endif //_PUBLISH_KERNELS_H_ - diff --git a/apps/bubble_pop/include/vx_ext_pop.h b/apps/bubble_pop/include/vx_ext_pop.h index 83efd30d4e..fe7b27346a 100644 --- a/apps/bubble_pop/include/vx_ext_pop.h +++ b/apps/bubble_pop/include/vx_ext_pop.h @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,42 +23,43 @@ THE SOFTWARE. #include #include "opencv2/opencv.hpp" -#if _WIN32 +#if _WIN32 #define SHARED_PUBLIC __declspec(dllexport) #else -#define SHARED_PUBLIC __attribute__ ((visibility ("default"))) +#define SHARED_PUBLIC __attribute__((visibility("default"))) #endif #ifndef dimof -#define dimof(x) (sizeof(x)/sizeof(x[0])) +#define dimof(x) (sizeof(x) / sizeof(x[0])) #endif vx_node vxCreateNodeByStructure(vx_graph graph, vx_enum kernelenum, vx_reference params[], vx_uint32 num); #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif /*!*********************************************************************************************************** VX POP - Bubble Pop VX_API_ENTRY C Function NODE *************************************************************************************************************/ /*! \brief [Graph] Creates a OpenCV blur function node. - * \param [in] graph The reference to the graph. - * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. - * \param [out] output The output image is as same size and type of input. - * \return \ref vx_node. - * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtPopNode_bubblePop(vx_graph graph, vx_image input, vx_image output); /*!*********************************************************************************************************** VX POP - Donut Pop VX_API_ENTRY C Function NODE *************************************************************************************************************/ /*! \brief [Graph] Creates a OpenCV blur function node. - * \param [in] graph The reference to the graph. - * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. - * \param [out] output The output image is as same size and type of input. - * \return \ref vx_node. - * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ + * \param [in] graph The reference to the graph. + * \param [in] input The input image in \ref VX_DF_IMAGE_U8 format. + * \param [out] output The output image is as same size and type of input. + * \return \ref vx_node. + * \retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using \ref vxGetStatus*/ extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtPopNode_donutPop(vx_graph graph, vx_image input, vx_image output); #ifdef __cplusplus diff --git a/apps/bubble_pop/include/vx_pop.h b/apps/bubble_pop/include/vx_pop.h index ee9b473395..011f760b51 100644 --- a/apps/bubble_pop/include/vx_pop.h +++ b/apps/bubble_pop/include/vx_pop.h @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,8 +25,9 @@ THE SOFTWARE. #include "vx_ext_pop.h" -#ifdef __cplusplus -extern "C" { +#ifdef __cplusplus +extern "C" +{ #endif /*! \brief The AMD extension library for Pop */ @@ -47,7 +48,7 @@ extern "C" { VX_KERNEL_EXT_POP_DONUT_POP = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_EXT_POP) + 0x002, }; -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/apps/bubble_pop/source/AMD_VX_Pop_Bubble.cpp b/apps/bubble_pop/source/AMD_VX_Pop_Bubble.cpp index efd5f79de1..795e97fa23 100644 --- a/apps/bubble_pop/source/AMD_VX_Pop_Bubble.cpp +++ b/apps/bubble_pop/source/AMD_VX_Pop_Bubble.cpp @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -21,32 +21,31 @@ THE SOFTWARE. */ #include "internal_publishKernels.h" -#include +#include int poppedBubbles = 0; int globalBubblesflag = 0; Mat globalBubblesRefImage; int globalBubblesChange = 0; -Mat bubble_PNG = imread("image/b20.png",-1); +Mat bubble_PNG = imread("image/b20.png", -1); /************************************************************************************************************ Overlay Image Function *************************************************************************************************************/ -void overlayImage(const Mat &background, const Mat &foreground,Mat &output, Point2i location) +void overlayImage(const Mat &background, const Mat &foreground, Mat &output, Point2i location) { background.copyTo(output); for (int y = std::max(location.y, 0); y < background.rows; ++y) { - int fY = y - location.y; + int fY = y - location.y; if (fY >= foreground.rows) break; for (int x = std::max(location.x, 0); x < background.cols; ++x) { - int fX = x - location.x; + int fX = x - location.x; - if (fX >= foreground.cols) break; @@ -61,7 +60,7 @@ void overlayImage(const Mat &background, const Mat &foreground,Mat &output, Poin foreground.data[fY * foreground.step + fX * foreground.channels() + c]; unsigned char backgroundPx = background.data[y * background.step + x * background.channels() + c]; - output.data[y*output.step + output.channels()*x + c] = + output.data[y * output.step + output.channels() * x + c] = backgroundPx * (1. - opacity) + foregroundPx * opacity; } } @@ -79,12 +78,18 @@ class AMD_bubble_pop public: AMD_bubble_pop(int bX, int bY, int bW, int bH) { - bubbleX = bX; bubbleY = bY; bubbleWidth = bW; bubbleHeight = bH; + bubbleX = bX; + bubbleY = bY; + bubbleWidth = bW; + bubbleHeight = bH; } ~AMD_bubble_pop() { - bubbleX = 0; bubbleY = 0; bubbleWidth = 0; bubbleHeight = 0; + bubbleX = 0; + bubbleY = 0; + bubbleWidth = 0; + bubbleHeight = 0; } int update(int width, int height, Mat *Image) @@ -103,19 +108,19 @@ class AMD_bubble_pop cv::threshold(diff_image, diff_image, 160, 255, 0); - unsigned char *input = (unsigned char*)(diff_image.data); + unsigned char *input = (unsigned char *)(diff_image.data); int b; for (int x = bubbleX; x <= (bubbleX + (bubbleWidth - 1)); x++) - for (int y = bubbleY; y <= (bubbleY + (bubbleWidth - 1)); y++) - { - if ((x < diff_image.cols && x > 0) && (y < diff_image.rows && y > 0)) + for (int y = bubbleY; y <= (bubbleY + (bubbleWidth - 1)); y++) { - b = input[diff_image.cols * y + x]; - if (b == 255) - movementAmount++; + if ((x < diff_image.cols && x > 0) && (y < diff_image.rows && y > 0)) + { + b = input[diff_image.cols * y + x]; + if (b == 255) + movementAmount++; + } } - } } if (movementAmount > 100) @@ -134,7 +139,11 @@ class AMD_bubble_pop test_image = *Image; // draw bubbles - if(bubble_PNG.empty()){ printf("--image/b20.png-- Image not found\n"); return -1;}; + if (bubble_PNG.empty()) + { + printf("--image/b20.png-- Image not found\n"); + return -1; + }; overlayImage(test_image, bubble_PNG, *Image, cv::Point(bubbleX, bubbleY)); return 0; @@ -142,18 +151,19 @@ class AMD_bubble_pop } }; -struct Linked_list_pop{ +struct Linked_list_pop +{ AMD_bubble_pop bubble; int data; - struct Linked_list_pop* next; + struct Linked_list_pop *next; }; typedef struct Linked_list_pop BubbleNode; -//Function Prototyping -BubbleNode* insert_pop(BubbleNode* head, BubbleNode* x); -BubbleNode* pop_position_delete(BubbleNode* head, int p); -BubbleNode* pop_clean_node(BubbleNode* head); -void draw_pop_bubbles(int, int, Mat*); +// Function Prototyping +BubbleNode *insert_pop(BubbleNode *head, BubbleNode *x); +BubbleNode *pop_position_delete(BubbleNode *head, int p); +BubbleNode *pop_clean_node(BubbleNode *head); +void draw_pop_bubbles(int, int, Mat *); BubbleNode *POPbubble = NULL; /************************************************************************************************************ @@ -166,7 +176,7 @@ void draw_pop_bubbles(int width, int height, Mat *Image) int randx = rand() % (width + 1); AMD_bubble_pop new_element = AMD_bubble_pop(randx, 0, 20, 20); - BubbleNode * temp = (BubbleNode*)malloc(sizeof(BubbleNode)); + BubbleNode *temp = (BubbleNode *)malloc(sizeof(BubbleNode)); temp->bubble = new_element; temp->next = NULL; POPbubble = insert_pop(POPbubble, temp); @@ -196,7 +206,6 @@ void draw_pop_bubbles(int width, int height, Mat *Image) } return; - } /************************************************************************************************************ @@ -244,7 +253,9 @@ static vx_status VX_CALLBACK VX_bubbles_OutputValidator(vx_node node, vx_uint32 if (index == 1) { vx_parameter output_param = vxGetParameterByIndex(node, 1); - vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + vx_image output; + vx_uint32 width = 0, height = 0; + vx_df_image format = VX_DF_IMAGE_VIRT; STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); @@ -276,14 +287,25 @@ static vx_status VX_CALLBACK VX_bubbles_Kernel(vx_node node, const vx_reference Mat *mat, bl; // wait to restart - press any key - if(poppedBubbles >= 1015){ poppedBubbles = 0; waitKey(0);} + if (poppedBubbles >= 1015) + { + poppedBubbles = 0; + waitKey(0); + } - //Converting VX Image to OpenCV Mat + // Converting VX Image to OpenCV Mat STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); Mat Image = *mat, clean_img; flip(Image, Image, 1); - if (globalBubblesflag == 0){ globalBubblesRefImage = Image;} else{clean_img = Image;} + if (globalBubblesflag == 0) + { + globalBubblesRefImage = Image; + } + else + { + clean_img = Image; + } draw_pop_bubbles(Image.cols, Image.rows, &Image); @@ -291,7 +313,7 @@ static vx_status VX_CALLBACK VX_bubbles_Kernel(vx_node node, const vx_reference if (poppedBubbles >= 1000) { statusStr << "Congratulations! Click any Key to Contiue Popping!"; - putText(Image, statusStr.str(), cvPoint(5, int(Image.rows/2)), FONT_HERSHEY_COMPLEX_SMALL, 1, cvScalar(200, 200, 250), 1, CV_AA); + putText(Image, statusStr.str(), cvPoint(5, int(Image.rows / 2)), FONT_HERSHEY_COMPLEX_SMALL, 1, cvScalar(200, 200, 250), 1, CV_AA); } else { @@ -299,10 +321,16 @@ static vx_status VX_CALLBACK VX_bubbles_Kernel(vx_node node, const vx_reference putText(Image, statusStr.str(), cvPoint(30, 30), FONT_HERSHEY_COMPLEX_SMALL, 1.2, cvScalar(200, 200, 250), 1, CV_AA); } - //Converting OpenCV Mat into VX Image + // Converting OpenCV Mat into VX Image STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &Image)); - if (globalBubblesflag == 0) globalBubblesflag++; else{ globalBubblesRefImage = clean_img; globalBubblesflag++; } + if (globalBubblesflag == 0) + globalBubblesflag++; + else + { + globalBubblesRefImage = clean_img; + globalBubblesflag++; + } return status; } @@ -314,14 +342,14 @@ vx_status VX_bubbles_pop_Register(vx_context context) { vx_status status = VX_SUCCESS; vx_kernel kernel = vxAddKernel(context, - "org.pop.bubble_pop", - VX_KERNEL_EXT_POP_BUBBLE_POP, - VX_bubbles_Kernel, - 2, - VX_bubbles_InputValidator, - VX_bubbles_OutputValidator, - nullptr, - nullptr); + "org.pop.bubble_pop", + VX_KERNEL_EXT_POP_BUBBLE_POP, + VX_bubbles_Kernel, + 2, + VX_bubbles_InputValidator, + VX_bubbles_OutputValidator, + nullptr, + nullptr); if (kernel) { @@ -332,29 +360,33 @@ vx_status VX_bubbles_pop_Register(vx_context context) if (status != VX_SUCCESS) { - exit: vxRemoveKernel(kernel); return VX_FAILURE; + exit: + vxRemoveKernel(kernel); + return VX_FAILURE; } return status; } /* -* linked_list.c -* Author: Kiriti Nagesh Gowda -*/ + * linked_list.c + * Author: Kiriti Nagesh Gowda + */ -//Insert a variable function -BubbleNode* insert_pop(BubbleNode* head, BubbleNode* x) +// Insert a variable function +BubbleNode *insert_pop(BubbleNode *head, BubbleNode *x) { - BubbleNode* temp; - BubbleNode* temp1 = x; + BubbleNode *temp; + BubbleNode *temp1 = x; if (head == NULL) head = temp1; - else{ + else + { temp = head; - while (temp->next != NULL){ + while (temp->next != NULL) + { temp = temp->next; } temp->next = temp1; @@ -362,25 +394,28 @@ BubbleNode* insert_pop(BubbleNode* head, BubbleNode* x) return (head); } -//Delete a node from the list -BubbleNode* pop_position_delete(BubbleNode* head, int p) +// Delete a node from the list +BubbleNode *pop_position_delete(BubbleNode *head, int p) { - BubbleNode* temp; - BubbleNode* temp1; + BubbleNode *temp; + BubbleNode *temp1; int count = 2; temp = head; - if (temp == NULL || p <= 0){ + if (temp == NULL || p <= 0) + { printf("The List is empty or the position is invalid\n"); return (head); } - if (p == 1){ + if (p == 1) + { head = temp->next; free(temp); return (head); } - while (temp != NULL){ + while (temp != NULL) + { if (count == (p)) { temp1 = temp->next; @@ -390,21 +425,23 @@ BubbleNode* pop_position_delete(BubbleNode* head, int p) } temp = temp->next; - if (temp == NULL) break; + if (temp == NULL) + break; ++count; } return head; } -//clean node -BubbleNode *pop_clean_node(BubbleNode * head) +// clean node +BubbleNode *pop_clean_node(BubbleNode *head) { BubbleNode *temp1; - while (head != NULL){ + while (head != NULL) + { temp1 = head->next; free(head); head = temp1; } - return(head); + return (head); } diff --git a/apps/bubble_pop/source/AMD_VX_Pop_Donut.cpp b/apps/bubble_pop/source/AMD_VX_Pop_Donut.cpp index 0cc2219ab2..de7a79e5c2 100644 --- a/apps/bubble_pop/source/AMD_VX_Pop_Donut.cpp +++ b/apps/bubble_pop/source/AMD_VX_Pop_Donut.cpp @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -21,7 +21,7 @@ THE SOFTWARE. */ #include "internal_publishKernels.h" -#include +#include int poppedDonuts = 0; int globalDonutFlag = 0; @@ -39,12 +39,18 @@ class AMD_donut_pop public: AMD_donut_pop(int bX, int bY, int bW, int bH) { - donutX = bX; donutY = bY; donutWidth = bW; donutHeight = bH; + donutX = bX; + donutY = bY; + donutWidth = bW; + donutHeight = bH; } ~AMD_donut_pop() { - donutX = 0; donutY = 0; donutWidth = 0; donutHeight = 0; + donutX = 0; + donutY = 0; + donutWidth = 0; + donutHeight = 0; } int update(int width, int height, Mat *Image) @@ -63,19 +69,19 @@ class AMD_donut_pop cv::threshold(diff_image, diff_image, 160, 255, 0); - unsigned char *input = (unsigned char*)(diff_image.data); + unsigned char *input = (unsigned char *)(diff_image.data); int b; for (int x = donutX; x <= (donutX + (donutWidth - 1)); x++) - for (int y = donutY; y <= (donutY + (donutWidth - 1)); y++) - { - if ((x < diff_image.cols && x > 0) && (y < diff_image.rows && y > 0)) + for (int y = donutY; y <= (donutY + (donutWidth - 1)); y++) { - b = input[diff_image.cols * y + x]; - if (b == 255) - movementAmount++; + if ((x < diff_image.cols && x > 0) && (y < diff_image.rows && y > 0)) + { + b = input[diff_image.cols * y + x]; + if (b == 255) + movementAmount++; + } } - } } if (movementAmount > 100) @@ -110,18 +116,19 @@ class AMD_donut_pop } }; -struct Linked_list_pop{ +struct Linked_list_pop +{ AMD_donut_pop donut; int data; - struct Linked_list_pop* next; + struct Linked_list_pop *next; }; typedef struct Linked_list_pop donutNode; -//Function Prototyping -donutNode* donut_insert(donutNode* head, donutNode* x); -donutNode* donut_position_delete(donutNode* head, int p); -donutNode* donut_clean_node(donutNode* head); -int draw_pop_donuts(int, int, Mat*); +// Function Prototyping +donutNode *donut_insert(donutNode *head, donutNode *x); +donutNode *donut_position_delete(donutNode *head, int p); +donutNode *donut_clean_node(donutNode *head); +int draw_pop_donuts(int, int, Mat *); donutNode *PopDonuts = NULL; /************************************************************************************************************ @@ -134,7 +141,7 @@ int draw_pop_donuts(int width, int height, Mat *Image) int randx = rand() % (width + 1); AMD_donut_pop new_element = AMD_donut_pop(randx, 0, 20, 20); - donutNode * temp = (donutNode*)malloc(sizeof(donutNode)); + donutNode *temp = (donutNode *)malloc(sizeof(donutNode)); temp->donut = new_element; temp->next = NULL; PopDonuts = donut_insert(PopDonuts, temp); @@ -164,7 +171,6 @@ int draw_pop_donuts(int width, int height, Mat *Image) } return 0; - } /************************************************************************************************************ @@ -212,7 +218,9 @@ vx_status VX_CALLBACK VX_bubbles_OutputValidator(vx_node node, vx_uint32 index, if (index == 1) { vx_parameter output_param = vxGetParameterByIndex(node, 1); - vx_image output; vx_uint32 width = 0, height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; + vx_image output; + vx_uint32 width = 0, height = 0; + vx_df_image format = VX_DF_IMAGE_VIRT; STATUS_ERROR_CHECK(vxQueryParameter(output_param, VX_PARAMETER_ATTRIBUTE_REF, &output, sizeof(vx_image))); STATUS_ERROR_CHECK(vxQueryImage(output, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); @@ -244,30 +252,42 @@ vx_status VX_CALLBACK VX_bubbles_Kernel(vx_node node, const vx_reference *parame Mat *mat, bl; // wait to restart - press any key - if(poppedDonuts >= 1015){ poppedDonuts = 0; waitKey(0);} + if (poppedDonuts >= 1015) + { + poppedDonuts = 0; + waitKey(0); + } - //Converting VX Image to OpenCV Mat + // Converting VX Image to OpenCV Mat STATUS_ERROR_CHECK(VX_to_CV_Image(&mat, image_in)); Mat Image = *mat, clean_img; flip(Image, Image, 1); - if (globalDonutFlag == 0){ + if (globalDonutFlag == 0) + { globalDonutRefImage = Image; } - else{ - clean_img = Image; + else + { + clean_img = Image; } // change donut size - press "d" - if(waitKey(2) == 100){if (globalDonutChange == 0) globalDonutChange = 1; else globalDonutChange = 0;} - if(draw_pop_donuts(Image.cols, Image.rows, &Image)) + if (waitKey(2) == 100) + { + if (globalDonutChange == 0) + globalDonutChange = 1; + else + globalDonutChange = 0; + } + if (draw_pop_donuts(Image.cols, Image.rows, &Image)) return VX_FAILURE; std::ostringstream statusStr; if (poppedDonuts >= 1000) { statusStr << "Congratulations! Click any Key to Contiue Popping!"; - putText(Image, statusStr.str(), cvPoint(5, int(Image.rows/2)), FONT_HERSHEY_COMPLEX_SMALL, 1, cvScalar(200, 200, 250), 1, CV_AA); + putText(Image, statusStr.str(), cvPoint(5, int(Image.rows / 2)), FONT_HERSHEY_COMPLEX_SMALL, 1, cvScalar(200, 200, 250), 1, CV_AA); } else { @@ -275,10 +295,16 @@ vx_status VX_CALLBACK VX_bubbles_Kernel(vx_node node, const vx_reference *parame putText(Image, statusStr.str(), cvPoint(30, 30), FONT_HERSHEY_COMPLEX_SMALL, 1.2, cvScalar(200, 200, 250), 1, CV_AA); } - //Converting OpenCV Mat into VX Image + // Converting OpenCV Mat into VX Image STATUS_ERROR_CHECK(CV_to_VX_Image(image_out, &Image)); - if (globalDonutFlag == 0) globalDonutFlag++; else{ globalDonutRefImage = clean_img; globalDonutFlag++; } + if (globalDonutFlag == 0) + globalDonutFlag++; + else + { + globalDonutRefImage = clean_img; + globalDonutFlag++; + } return status; } @@ -290,14 +316,14 @@ vx_status VX_donut_pop_Register(vx_context context) { vx_status status = VX_SUCCESS; vx_kernel kernel = vxAddKernel(context, - "org.pop.donut_pop", - VX_KERNEL_EXT_POP_DONUT_POP, - VX_bubbles_Kernel, - 2, - VX_bubbles_InputValidator, - VX_bubbles_OutputValidator, - nullptr, - nullptr); + "org.pop.donut_pop", + VX_KERNEL_EXT_POP_DONUT_POP, + VX_bubbles_Kernel, + 2, + VX_bubbles_InputValidator, + VX_bubbles_OutputValidator, + nullptr, + nullptr); if (kernel) { @@ -308,29 +334,33 @@ vx_status VX_donut_pop_Register(vx_context context) if (status != VX_SUCCESS) { - exit: vxRemoveKernel(kernel); return VX_FAILURE; + exit: + vxRemoveKernel(kernel); + return VX_FAILURE; } return status; } /* -* linked_list.c -* Author: Kiriti Nagesh Gowda -*/ + * linked_list.c + * Author: Kiriti Nagesh Gowda + */ -//Insert a variable function -donutNode* donut_insert(donutNode* head, donutNode* x) +// Insert a variable function +donutNode *donut_insert(donutNode *head, donutNode *x) { - donutNode* temp; - donutNode* temp1 = x; + donutNode *temp; + donutNode *temp1 = x; if (head == NULL) head = temp1; - else{ + else + { temp = head; - while (temp->next != NULL){ + while (temp->next != NULL) + { temp = temp->next; } temp->next = temp1; @@ -338,25 +368,28 @@ donutNode* donut_insert(donutNode* head, donutNode* x) return (head); } -//Delete a node from the list -donutNode* donut_position_delete(donutNode* head, int p) +// Delete a node from the list +donutNode *donut_position_delete(donutNode *head, int p) { - donutNode* temp; - donutNode* temp1; + donutNode *temp; + donutNode *temp1; int count = 2; temp = head; - if (temp == NULL || p <= 0){ + if (temp == NULL || p <= 0) + { printf("The List is empty or the position is invalid\n"); return (head); } - if (p == 1){ + if (p == 1) + { head = temp->next; free(temp); return (head); } - while (temp != NULL){ + while (temp != NULL) + { if (count == (p)) { temp1 = temp->next; @@ -366,21 +399,23 @@ donutNode* donut_position_delete(donutNode* head, int p) } temp = temp->next; - if (temp == NULL) break; + if (temp == NULL) + break; ++count; } return head; } -//clean node -donutNode *donut_clean_node(donutNode * head) +// clean node +donutNode *donut_clean_node(donutNode *head) { donutNode *temp1; - while (head != NULL){ + while (head != NULL) + { temp1 = head->next; free(head); head = temp1; } - return(head); + return (head); } \ No newline at end of file diff --git a/apps/bubble_pop/source/AMD_app.cpp b/apps/bubble_pop/source/AMD_app.cpp index db8bb92dec..13d3b28451 100644 --- a/apps/bubble_pop/source/AMD_app.cpp +++ b/apps/bubble_pop/source/AMD_app.cpp @@ -7,26 +7,35 @@ using namespace cv; using namespace std; -#define ERROR_CHECK_STATUS( status ) { \ - vx_status status_ = (status); \ - if(status_ != VX_SUCCESS) { \ +#if USE_OPENCV_4 +#define CV_BGR2RGB COLOR_BGR2RGB +#endif + +#define ERROR_CHECK_STATUS(status) \ + { \ + vx_status status_ = (status); \ + if (status_ != VX_SUCCESS) \ + { \ printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \ - exit(1); \ - } \ -} + exit(1); \ + } \ + } -#define ERROR_CHECK_OBJECT( obj ) { \ - vx_status status_ = vxGetStatus((vx_reference)(obj)); \ - if(status_ != VX_SUCCESS) { \ +#define ERROR_CHECK_OBJECT(obj) \ + { \ + vx_status status_ = vxGetStatus((vx_reference)(obj)); \ + if (status_ != VX_SUCCESS) \ + { \ printf("ERROR: failed with status = (%d) at " __FILE__ "#%d\n", status_, __LINE__); \ - exit(1); \ - } \ -} + exit(1); \ + } \ + } static void VX_CALLBACK log_callback(vx_context context, vx_reference ref, vx_status status, const vx_char string[]) { size_t len = strlen(string); - if (len > 0) { + if (len > 0) + { printf("%s", string); if (string[len - 1] != '\n') printf("\n"); @@ -36,10 +45,21 @@ static void VX_CALLBACK log_callback(vx_context context, vx_reference ref, vx_st int main(int argc, char **argv) { - if (argc < 2) { + if (argc < 2) + { printf("Usage:\n" - "./vxPop --donut\n" - "./vxPop --bubble \n"); + "./vxPop --donut\n" + "./vxPop --bubble \n"); + return 0; + } + + // check option + string optionCheck = argv[1]; + if (optionCheck != "--bubble" && optionCheck != "--donut") + { + printf("Usage:\n" + "./vxPop --donut\n" + "./vxPop --bubble \n"); return 0; } @@ -52,11 +72,11 @@ int main(int argc, char **argv) // load vx_pop kernels ERROR_CHECK_STATUS(vxLoadKernels(context, "vx_pop")); - + // create OpenVX Graph vx_graph graph = vxCreateGraph(context); ERROR_CHECK_OBJECT(graph); - + // create OpenVX Images vx_image input_rgb_image = vxCreateImage(context, width, height, VX_DF_IMAGE_RGB); vx_image output_pop_image = vxCreateImage(context, width, height, VX_DF_IMAGE_U8); @@ -64,11 +84,11 @@ int main(int argc, char **argv) ERROR_CHECK_OBJECT(output_pop_image); // create intermediate images - vx_image yuv_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_IYUV); + vx_image yuv_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_IYUV); vx_image luma_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); vx_image output_canny_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image output_skinTone_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image output_canny_skinTone_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image output_skinTone_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image output_canny_skinTone_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); ERROR_CHECK_OBJECT(yuv_image); ERROR_CHECK_OBJECT(luma_image); ERROR_CHECK_OBJECT(output_canny_image); @@ -76,27 +96,27 @@ int main(int argc, char **argv) ERROR_CHECK_OBJECT(output_canny_skinTone_image); // create threshold variable - vx_threshold hyst = vxCreateThreshold(context, VX_THRESHOLD_TYPE_RANGE, VX_TYPE_UINT8); + vx_threshold hyst = vxCreateThresholdForImage(context, VX_THRESHOLD_TYPE_RANGE, VX_DF_IMAGE_U8, VX_DF_IMAGE_U8); vx_int32 lower = 80, upper = 100; - vxSetThresholdAttribute(hyst, VX_THRESHOLD_ATTRIBUTE_THRESHOLD_LOWER, &lower, sizeof(lower)); - vxSetThresholdAttribute(hyst, VX_THRESHOLD_ATTRIBUTE_THRESHOLD_UPPER, &upper, sizeof(upper)); + vxSetThresholdAttribute(hyst, VX_THRESHOLD_ATTRIBUTE_THRESHOLD_LOWER, &lower, sizeof(vx_int32)); + vxSetThresholdAttribute(hyst, VX_THRESHOLD_ATTRIBUTE_THRESHOLD_UPPER, &upper, sizeof(vx_int32)); ERROR_CHECK_OBJECT(hyst); vx_int32 gradient_size = 3; // create intermediate images which are not accessed by the user to be mem optimized - vx_image R_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image G_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image B_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image RmG_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image RmB_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image R95_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image G40_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image B20_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image RmG15_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image RmB0_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image and1_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image and2_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); - vx_image and3_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image R_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image G_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image B_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image RmG_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image RmB_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image R95_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image G40_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image B20_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image RmG15_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image RmB0_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image and1_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image and2_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); + vx_image and3_image = vxCreateVirtualImage(graph, width, height, VX_DF_IMAGE_U8); ERROR_CHECK_OBJECT(R_image); ERROR_CHECK_OBJECT(G_image); ERROR_CHECK_OBJECT(B_image); @@ -112,23 +132,23 @@ int main(int argc, char **argv) ERROR_CHECK_OBJECT(and3_image); // create threshold values - vx_threshold thresh95 = vxCreateThreshold(context, VX_THRESHOLD_TYPE_BINARY, VX_TYPE_UINT8); + vx_threshold thresh95 = vxCreateThresholdForImage(context, VX_THRESHOLD_TYPE_BINARY, VX_DF_IMAGE_U8, VX_DF_IMAGE_U8); vx_int32 thresValue95 = 95; vxSetThresholdAttribute(thresh95, VX_THRESHOLD_THRESHOLD_VALUE, &thresValue95, sizeof(vx_int32)); ERROR_CHECK_OBJECT(thresh95); - vx_threshold thresh40 = vxCreateThreshold(context, VX_THRESHOLD_TYPE_BINARY, VX_TYPE_UINT8); + vx_threshold thresh40 = vxCreateThresholdForImage(context, VX_THRESHOLD_TYPE_BINARY, VX_DF_IMAGE_U8, VX_DF_IMAGE_U8); vx_int32 thresValue40 = 40; vxSetThresholdAttribute(thresh40, VX_THRESHOLD_THRESHOLD_VALUE, &thresValue40, sizeof(vx_int32)); ERROR_CHECK_OBJECT(thresh40); - vx_threshold thresh20 = vxCreateThreshold(context, VX_THRESHOLD_TYPE_BINARY, VX_TYPE_UINT8); + vx_threshold thresh20 = vxCreateThresholdForImage(context, VX_THRESHOLD_TYPE_BINARY, VX_DF_IMAGE_U8, VX_DF_IMAGE_U8); vx_int32 thresValue20 = 20; vxSetThresholdAttribute(thresh20, VX_THRESHOLD_THRESHOLD_VALUE, &thresValue20, sizeof(vx_int32)); ERROR_CHECK_OBJECT(thresh20); - vx_threshold thresh15 = vxCreateThreshold(context, VX_THRESHOLD_TYPE_BINARY, VX_TYPE_UINT8); + vx_threshold thresh15 = vxCreateThresholdForImage(context, VX_THRESHOLD_TYPE_BINARY, VX_DF_IMAGE_U8, VX_DF_IMAGE_U8); vx_int32 thresValue15 = 15; vxSetThresholdAttribute(thresh15, VX_THRESHOLD_THRESHOLD_VALUE, &thresValue15, sizeof(vx_int32)); ERROR_CHECK_OBJECT(thresh15); - vx_threshold thresh0 = vxCreateThreshold(context, VX_THRESHOLD_TYPE_BINARY, VX_TYPE_UINT8); + vx_threshold thresh0 = vxCreateThresholdForImage(context, VX_THRESHOLD_TYPE_BINARY, VX_DF_IMAGE_U8, VX_DF_IMAGE_U8); vx_int32 thresValue0 = 0; vxSetThresholdAttribute(thresh0, VX_THRESHOLD_THRESHOLD_VALUE, &thresValue0, sizeof(vx_int32)); ERROR_CHECK_OBJECT(thresh0); @@ -138,145 +158,146 @@ int main(int argc, char **argv) if (option == "--bubble") { vx_node nodes[] = - { - // extract R,G,B channels and compute R-G and R-B - vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_R, R_image), - vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_G, G_image), - vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_B, B_image), - vxSubtractNode(graph, R_image, G_image, VX_CONVERT_POLICY_SATURATE, RmG_image), - vxSubtractNode(graph, R_image, B_image, VX_CONVERT_POLICY_SATURATE, RmB_image), - // compute threshold - vxThresholdNode(graph, R_image, thresh95, R95_image), - vxThresholdNode(graph, G_image, thresh40, G40_image), - vxThresholdNode(graph, B_image, thresh20, B20_image), - vxThresholdNode(graph, RmG_image, thresh15, RmG15_image), - vxThresholdNode(graph, RmB_image, thresh0, RmB0_image), - // aggregate all thresholded values to produce SKIN pixels - vxAndNode(graph, R95_image, G40_image, and1_image), - vxAndNode(graph, and1_image, B20_image, and2_image), - vxAndNode(graph, RmG15_image, RmB0_image, and3_image), - vxAndNode(graph, and2_image, and3_image, output_skinTone_image), - // create canny edge - vxColorConvertNode(graph, input_rgb_image, yuv_image), - vxChannelExtractNode(graph, yuv_image, VX_CHANNEL_Y, luma_image), - vxCannyEdgeDetectorNode(graph, luma_image, hyst, gradient_size, VX_NORM_L1, output_canny_image), - // or - canny & skintone images - vxOrNode(graph, output_canny_image, output_skinTone_image, output_canny_skinTone_image), - // vx pop - bubble pop - vxExtPopNode_bubblePop(graph, output_canny_skinTone_image, output_pop_image) - }; - for( vx_size i = 0; i < sizeof( nodes ) / sizeof( nodes[0] ); i++ ) + { + // extract R,G,B channels and compute R-G and R-B + vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_R, R_image), + vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_G, G_image), + vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_B, B_image), + vxSubtractNode(graph, R_image, G_image, VX_CONVERT_POLICY_SATURATE, RmG_image), + vxSubtractNode(graph, R_image, B_image, VX_CONVERT_POLICY_SATURATE, RmB_image), + // compute threshold + vxThresholdNode(graph, R_image, thresh95, R95_image), + vxThresholdNode(graph, G_image, thresh40, G40_image), + vxThresholdNode(graph, B_image, thresh20, B20_image), + vxThresholdNode(graph, RmG_image, thresh15, RmG15_image), + vxThresholdNode(graph, RmB_image, thresh0, RmB0_image), + // aggregate all thresholded values to produce SKIN pixels + vxAndNode(graph, R95_image, G40_image, and1_image), + vxAndNode(graph, and1_image, B20_image, and2_image), + vxAndNode(graph, RmG15_image, RmB0_image, and3_image), + vxAndNode(graph, and2_image, and3_image, output_skinTone_image), + // create canny edge + vxColorConvertNode(graph, input_rgb_image, yuv_image), + vxChannelExtractNode(graph, yuv_image, VX_CHANNEL_Y, luma_image), + vxCannyEdgeDetectorNode(graph, luma_image, hyst, gradient_size, VX_NORM_L1, output_canny_image), + // or - canny & skintone images + vxOrNode(graph, output_canny_image, output_skinTone_image, output_canny_skinTone_image), + // vx pop - bubble pop + vxExtPopNode_bubblePop(graph, output_canny_skinTone_image, output_pop_image)}; + for (vx_size i = 0; i < sizeof(nodes) / sizeof(nodes[0]); i++) { - ERROR_CHECK_OBJECT( nodes[i] ); - ERROR_CHECK_STATUS( vxReleaseNode( &nodes[i] ) ); + ERROR_CHECK_OBJECT(nodes[i]); + ERROR_CHECK_STATUS(vxReleaseNode(&nodes[i])); } } else { vx_node nodes[] = + { + // extract R,G,B channels and compute R-G and R-B + vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_R, R_image), + vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_G, G_image), + vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_B, B_image), + vxSubtractNode(graph, R_image, G_image, VX_CONVERT_POLICY_SATURATE, RmG_image), + vxSubtractNode(graph, R_image, B_image, VX_CONVERT_POLICY_SATURATE, RmB_image), + // compute threshold + vxThresholdNode(graph, R_image, thresh95, R95_image), + vxThresholdNode(graph, G_image, thresh40, G40_image), + vxThresholdNode(graph, B_image, thresh20, B20_image), + vxThresholdNode(graph, RmG_image, thresh15, RmG15_image), + vxThresholdNode(graph, RmB_image, thresh0, RmB0_image), + // aggregate all thresholded values to produce SKIN pixels + vxAndNode(graph, R95_image, G40_image, and1_image), + vxAndNode(graph, and1_image, B20_image, and2_image), + vxAndNode(graph, RmG15_image, RmB0_image, and3_image), + vxAndNode(graph, and2_image, and3_image, output_skinTone_image), + // create canny edge + vxColorConvertNode(graph, input_rgb_image, yuv_image), + vxChannelExtractNode(graph, yuv_image, VX_CHANNEL_Y, luma_image), + vxCannyEdgeDetectorNode(graph, luma_image, hyst, gradient_size, VX_NORM_L1, output_canny_image), + // or - canny & skintone images + vxOrNode(graph, output_canny_image, output_skinTone_image, output_canny_skinTone_image), + // vx pop - donut pop + vxExtPopNode_donutPop(graph, output_canny_skinTone_image, output_pop_image)}; + for (vx_size i = 0; i < sizeof(nodes) / sizeof(nodes[0]); i++) { - // extract R,G,B channels and compute R-G and R-B - vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_R, R_image), - vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_G, G_image), - vxChannelExtractNode(graph, input_rgb_image, VX_CHANNEL_B, B_image), - vxSubtractNode(graph, R_image, G_image, VX_CONVERT_POLICY_SATURATE, RmG_image), - vxSubtractNode(graph, R_image, B_image, VX_CONVERT_POLICY_SATURATE, RmB_image), - // compute threshold - vxThresholdNode(graph, R_image, thresh95, R95_image), - vxThresholdNode(graph, G_image, thresh40, G40_image), - vxThresholdNode(graph, B_image, thresh20, B20_image), - vxThresholdNode(graph, RmG_image, thresh15, RmG15_image), - vxThresholdNode(graph, RmB_image, thresh0, RmB0_image), - // aggregate all thresholded values to produce SKIN pixels - vxAndNode(graph, R95_image, G40_image, and1_image), - vxAndNode(graph, and1_image, B20_image, and2_image), - vxAndNode(graph, RmG15_image, RmB0_image, and3_image), - vxAndNode(graph, and2_image, and3_image, output_skinTone_image), - // create canny edge - vxColorConvertNode(graph, input_rgb_image, yuv_image), - vxChannelExtractNode(graph, yuv_image, VX_CHANNEL_Y, luma_image), - vxCannyEdgeDetectorNode(graph, luma_image, hyst, gradient_size, VX_NORM_L1, output_canny_image), - // or - canny & skintone images - vxOrNode(graph, output_canny_image, output_skinTone_image, output_canny_skinTone_image), - // vx pop - donut pop - vxExtPopNode_donutPop(graph, output_canny_skinTone_image, output_pop_image) - }; - for( vx_size i = 0; i < sizeof( nodes ) / sizeof( nodes[0] ); i++ ) - { - ERROR_CHECK_OBJECT( nodes[i] ); - ERROR_CHECK_STATUS( vxReleaseNode( &nodes[i] ) ); + ERROR_CHECK_OBJECT(nodes[i]); + ERROR_CHECK_STATUS(vxReleaseNode(&nodes[i])); } } // verify graph - only once - ERROR_CHECK_STATUS( vxVerifyGraph( graph ) ); - + ERROR_CHECK_STATUS(vxVerifyGraph(graph)); + Mat input, input_rgb; cv::namedWindow("VX POP - LIVE", cv::WINDOW_GUI_EXPANDED); VideoCapture cap(0); - if (!cap.isOpened()) { + if (!cap.isOpened()) + { printf("Unable to open camera\n"); return 0; } - for(;;) + for (;;) { cap >> input; resize(input, input, Size(width, height)); cvtColor(input, input_rgb, CV_BGR2RGB); - if(waitKey(30) >= 0) break; + if (waitKey(30) >= 0) + break; vx_rectangle_t cv_rgb_image_region; - cv_rgb_image_region.start_x = 0; - cv_rgb_image_region.start_y = 0; - cv_rgb_image_region.end_x = width; - cv_rgb_image_region.end_y = height; + cv_rgb_image_region.start_x = 0; + cv_rgb_image_region.start_y = 0; + cv_rgb_image_region.end_x = width; + cv_rgb_image_region.end_y = height; vx_imagepatch_addressing_t cv_rgb_image_layout; - cv_rgb_image_layout.stride_x = 3; - cv_rgb_image_layout.stride_y = input_rgb.step; - vx_uint8 * cv_rgb_image_buffer = input_rgb.data; - ERROR_CHECK_STATUS( vxCopyImagePatch( input_rgb_image, &cv_rgb_image_region, 0, + cv_rgb_image_layout.stride_x = 3; + cv_rgb_image_layout.stride_y = input_rgb.step; + vx_uint8 *cv_rgb_image_buffer = input_rgb.data; + ERROR_CHECK_STATUS(vxCopyImagePatch(input_rgb_image, &cv_rgb_image_region, 0, &cv_rgb_image_layout, cv_rgb_image_buffer, - VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST ) ); - ERROR_CHECK_STATUS( vxProcessGraph( graph ) ); - vx_rectangle_t rect = { 0, 0, (vx_uint32)width, (vx_uint32)height }; + VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST)); + ERROR_CHECK_STATUS(vxProcessGraph(graph)); + vx_rectangle_t rect = {0, 0, (vx_uint32)width, (vx_uint32)height}; vx_map_id map_id; vx_imagepatch_addressing_t addr; - void * ptr; - ERROR_CHECK_STATUS( vxMapImagePatch( output_pop_image, &rect, 0, &map_id, &addr, &ptr, - VX_READ_ONLY, VX_MEMORY_TYPE_HOST, VX_NOGAP_X ) ); - Mat mat( height, width, CV_8U, ptr, addr.stride_y ); - imshow( "VX POP - LIVE", mat ); - if(waitKey(30) >= 0) break; - ERROR_CHECK_STATUS( vxUnmapImagePatch( output_pop_image, map_id ) ); + void *ptr; + ERROR_CHECK_STATUS(vxMapImagePatch(output_pop_image, &rect, 0, &map_id, &addr, &ptr, + VX_READ_ONLY, VX_MEMORY_TYPE_HOST, VX_NOGAP_X)); + Mat mat(height, width, CV_8U, ptr, addr.stride_y); + imshow("VX POP - LIVE", mat); + if (waitKey(30) >= 0) + break; + ERROR_CHECK_STATUS(vxUnmapImagePatch(output_pop_image, map_id)); } // release objects - ERROR_CHECK_STATUS(vxReleaseGraph( &graph ) ); - ERROR_CHECK_STATUS(vxReleaseThreshold( &hyst )); - ERROR_CHECK_STATUS(vxReleaseThreshold( &thresh95 )); - ERROR_CHECK_STATUS(vxReleaseThreshold( &thresh40 )); - ERROR_CHECK_STATUS(vxReleaseThreshold( &thresh20 )); - ERROR_CHECK_STATUS(vxReleaseThreshold( &thresh15 )); - ERROR_CHECK_STATUS(vxReleaseThreshold( &thresh0 )); - ERROR_CHECK_STATUS(vxReleaseImage( &yuv_image ) ); - ERROR_CHECK_STATUS(vxReleaseImage( &luma_image ) ); - ERROR_CHECK_STATUS(vxReleaseImage( &output_canny_image ) ); - ERROR_CHECK_STATUS(vxReleaseImage( &input_rgb_image ) ); - ERROR_CHECK_STATUS(vxReleaseImage( &R_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &G_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &B_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &RmG_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &RmB_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &R95_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &G40_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &B20_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &RmG15_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &RmB0_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &and1_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &and2_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &and3_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &output_skinTone_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &output_canny_skinTone_image )); - ERROR_CHECK_STATUS(vxReleaseImage( &output_pop_image ) ); - ERROR_CHECK_STATUS(vxReleaseContext( &context ) ); + ERROR_CHECK_STATUS(vxReleaseGraph(&graph)); + ERROR_CHECK_STATUS(vxReleaseThreshold(&hyst)); + ERROR_CHECK_STATUS(vxReleaseThreshold(&thresh95)); + ERROR_CHECK_STATUS(vxReleaseThreshold(&thresh40)); + ERROR_CHECK_STATUS(vxReleaseThreshold(&thresh20)); + ERROR_CHECK_STATUS(vxReleaseThreshold(&thresh15)); + ERROR_CHECK_STATUS(vxReleaseThreshold(&thresh0)); + ERROR_CHECK_STATUS(vxReleaseImage(&yuv_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&luma_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&output_canny_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&input_rgb_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&R_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&G_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&B_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&RmG_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&RmB_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&R95_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&G40_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&B20_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&RmG15_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&RmB0_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&and1_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&and2_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&and3_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&output_skinTone_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&output_canny_skinTone_image)); + ERROR_CHECK_STATUS(vxReleaseImage(&output_pop_image)); + ERROR_CHECK_STATUS(vxReleaseContext(&context)); return 0; } diff --git a/apps/bubble_pop/source/internal_dataTranslator.cpp b/apps/bubble_pop/source/internal_dataTranslator.cpp index a27eddf391..7b5427026c 100644 --- a/apps/bubble_pop/source/internal_dataTranslator.cpp +++ b/apps/bubble_pop/source/internal_dataTranslator.cpp @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -20,7 +20,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - #include "internal_opencvTunnel.h" /************************************************************************************************************ @@ -29,7 +28,10 @@ Converting CV Pyramid into an OpenVX Pyramid int CV_to_VX_Pyramid(vx_pyramid pyramid_vx, vector pyramid_cv) { vx_status status = VX_SUCCESS; - vx_size Level_vx = 0; vx_uint32 width = 0; vx_uint32 height = 0; vx_int32 i; + vx_size Level_vx = 0; + vx_uint32 width = 0; + vx_uint32 height = 0; + vx_int32 i; STATUS_ERROR_CHECK(vxQueryPyramid(pyramid_vx, VX_PYRAMID_ATTRIBUTE_LEVELS, &Level_vx, sizeof(Level_vx))); for (i = 0; i < (int)Level_vx; i++) @@ -39,9 +41,10 @@ int CV_to_VX_Pyramid(vx_pyramid pyramid_vx, vector pyramid_cv) STATUS_ERROR_CHECK(vxQueryImage(this_level, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); if (width != pyramid_cv[i].cols && height != pyramid_cv[i].rows) { - vxAddLogEntry((vx_reference)pyramid_vx, VX_ERROR_INVALID_DIMENSION, "CV_to_VX_Pyramid ERROR: Pyramid Image Mismatch\n"); return VX_ERROR_INVALID_DIMENSION; + vxAddLogEntry((vx_reference)pyramid_vx, VX_ERROR_INVALID_DIMENSION, "CV_to_VX_Pyramid ERROR: Pyramid Image Mismatch\n"); + return VX_ERROR_INVALID_DIMENSION; } - Mat* pyr_level; + Mat *pyr_level; pyr_level = &pyramid_cv[i]; CV_to_VX_Image(this_level, pyr_level); } @@ -51,32 +54,42 @@ int CV_to_VX_Pyramid(vx_pyramid pyramid_vx, vector pyramid_cv) /************************************************************************************************************ Converting VX matrix into an OpenCV Mat *************************************************************************************************************/ -int VX_to_CV_MATRIX(Mat** mat, vx_matrix matrix_vx) +int VX_to_CV_MATRIX(Mat **mat, vx_matrix matrix_vx) { vx_status status = VX_SUCCESS; - vx_size numRows = 0; vx_size numCols = 0; vx_enum type; int Type_CV = 0; + vx_size numRows = 0; + vx_size numCols = 0; + vx_enum type; + int Type_CV = 0; STATUS_ERROR_CHECK(vxQueryMatrix(matrix_vx, VX_MATRIX_ATTRIBUTE_ROWS, &numRows, sizeof(numRows))); STATUS_ERROR_CHECK(vxQueryMatrix(matrix_vx, VX_MATRIX_ATTRIBUTE_COLUMNS, &numCols, sizeof(numCols))); STATUS_ERROR_CHECK(vxQueryMatrix(matrix_vx, VX_MATRIX_ATTRIBUTE_TYPE, &type, sizeof(type))); - if (type == VX_TYPE_INT32)Type_CV = CV_32S; - if (type == VX_TYPE_FLOAT32)Type_CV = CV_32F; + if (type == VX_TYPE_INT32) + Type_CV = CV_32S; + if (type == VX_TYPE_FLOAT32) + Type_CV = CV_32F; if (type != VX_TYPE_FLOAT32 && type != VX_TYPE_INT32) { - vxAddLogEntry((vx_reference)matrix_vx, VX_ERROR_INVALID_FORMAT, "VX_to_CV_MATRIX ERROR: Matrix type not Supported in this RELEASE\n"); return VX_ERROR_INVALID_FORMAT; + vxAddLogEntry((vx_reference)matrix_vx, VX_ERROR_INVALID_FORMAT, "VX_to_CV_MATRIX ERROR: Matrix type not Supported in this RELEASE\n"); + return VX_ERROR_INVALID_FORMAT; } - Mat * m_cv; m_cv = new Mat((int)numRows, (int)numCols, Type_CV); vx_size mat_size = numRows * numCols; - float *dyn_matrix = new float[mat_size]; int z = 0; + Mat *m_cv; + m_cv = new Mat((int)numRows, (int)numCols, Type_CV); + vx_size mat_size = numRows * numCols; + float *dyn_matrix = new float[mat_size]; + int z = 0; STATUS_ERROR_CHECK(vxReadMatrix(matrix_vx, (void *)dyn_matrix)); for (int i = 0; i < (int)numRows; i++) - for (int j = 0; j < (int)numCols; j++) - { - m_cv->at(i, j) = dyn_matrix[z]; z++; - } + for (int j = 0; j < (int)numCols; j++) + { + m_cv->at(i, j) = dyn_matrix[z]; + z++; + } *mat = m_cv; return status; @@ -85,30 +98,47 @@ int VX_to_CV_MATRIX(Mat** mat, vx_matrix matrix_vx) /************************************************************************************************************ Converting VX Image into an OpenCV Mat *************************************************************************************************************/ -int VX_to_CV_Image(Mat** mat, vx_image image) +int VX_to_CV_Image(Mat **mat, vx_image image) { vx_status status = VX_SUCCESS; - vx_uint32 width = 0; vx_uint32 height = 0; vx_df_image format = VX_DF_IMAGE_VIRT; int CV_format = 0; vx_size planes = 0; + vx_uint32 width = 0; + vx_uint32 height = 0; + vx_df_image format = VX_DF_IMAGE_VIRT; + int CV_format = 0; + vx_size planes = 0; STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_FORMAT, &format, sizeof(format))); STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_PLANES, &planes, sizeof(planes))); - - if (format == VX_DF_IMAGE_U8)CV_format = CV_8U; - if (format == VX_DF_IMAGE_S16)CV_format = CV_16S; - if (format == VX_DF_IMAGE_RGB)CV_format = CV_8UC3; - + + if (format == VX_DF_IMAGE_U8) + CV_format = CV_8U; + if (format == VX_DF_IMAGE_S16) + CV_format = CV_16S; + if (format == VX_DF_IMAGE_RGB) + CV_format = CV_8UC3; + if (format != VX_DF_IMAGE_U8 && format != VX_DF_IMAGE_S16 && format != VX_DF_IMAGE_RGB) { - vxAddLogEntry((vx_reference)image, VX_ERROR_INVALID_FORMAT, "VX_to_CV_Image ERROR: Image type not Supported in this RELEASE\n"); return VX_ERROR_INVALID_FORMAT; + vxAddLogEntry((vx_reference)image, VX_ERROR_INVALID_FORMAT, "VX_to_CV_Image ERROR: Image type not Supported in this RELEASE\n"); + return VX_ERROR_INVALID_FORMAT; } - - Mat * m_cv; m_cv = new Mat(height, width, CV_format); Mat *pMat = (Mat *)m_cv; - vx_rectangle_t rect; rect.start_x = 0; rect.start_y = 0; rect.end_x = width; rect.end_y = height; - vx_uint8 *src[4] = { NULL, NULL, NULL, NULL }; vx_uint32 p; void *ptr = NULL; - vx_imagepatch_addressing_t addr[4] = { 0, 0, 0, 0 }; vx_uint32 y = 0u; + Mat *m_cv; + m_cv = new Mat(height, width, CV_format); + Mat *pMat = (Mat *)m_cv; + vx_rectangle_t rect; + rect.start_x = 0; + rect.start_y = 0; + rect.end_x = width; + rect.end_y = height; + + vx_uint8 *src[4] = {NULL, NULL, NULL, NULL}; + vx_uint32 p; + void *ptr = NULL; + vx_imagepatch_addressing_t addr[4] = {0, 0, 0, 0}; + vx_uint32 y = 0u; for (p = 0u; (p < (int)planes); p++) { @@ -132,20 +162,31 @@ int VX_to_CV_Image(Mat** mat, vx_image image) /************************************************************************************************************ Converting CV Image into an OpenVX Image *************************************************************************************************************/ -int CV_to_VX_Image(vx_image image, Mat* mat) +int CV_to_VX_Image(vx_image image, Mat *mat) { - vx_status status = VX_SUCCESS; vx_uint32 width = 0; vx_uint32 height = 0; vx_size planes = 0; + vx_status status = VX_SUCCESS; + vx_uint32 width = 0; + vx_uint32 height = 0; + vx_size planes = 0; STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_WIDTH, &width, sizeof(width))); STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_HEIGHT, &height, sizeof(height))); STATUS_ERROR_CHECK(vxQueryImage(image, VX_IMAGE_ATTRIBUTE_PLANES, &planes, sizeof(planes))); - Mat *pMat = mat; vx_rectangle_t rect; rect.start_x = 0; rect.start_y = 0; rect.end_x = width; rect.end_y = height; + Mat *pMat = mat; + vx_rectangle_t rect; + rect.start_x = 0; + rect.start_y = 0; + rect.end_x = width; + rect.end_y = height; - vx_uint8 *src[4] = { NULL, NULL, NULL, NULL }; vx_uint32 p; void *ptr = NULL; - vx_imagepatch_addressing_t addr[4] = { 0, 0, 0, 0 }; vx_uint32 y = 0u; + vx_uint8 *src[4] = {NULL, NULL, NULL, NULL}; + vx_uint32 p; + void *ptr = NULL; + vx_imagepatch_addressing_t addr[4] = {0, 0, 0, 0}; + vx_uint32 y = 0u; - for (p = 0u; (p <(int)planes); p++) + for (p = 0u; (p < (int)planes); p++) { STATUS_ERROR_CHECK(vxAccessImagePatch(image, &rect, p, &addr[p], (void **)&src[p], VX_READ_ONLY)); size_t len = addr[p].stride_x * (addr[p].dim_x * addr[p].scale_x) / VX_SCALE_UNITY; @@ -179,36 +220,64 @@ int CV_to_VX_keypoints(vector key_points, vx_array array) vx_status status = VX_SUCCESS; vector Keypoint_VX; - float X, Y, K_Size, K_Angle, K_Response; int x, y, j = 0; - void *ptr = NULL; vx_size size = 0; + int x, y, j = 0; + void *ptr = NULL; + vx_size size = 0; STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); - size_t S = key_points.size(); Keypoint_VX.resize(S); + size_t S = key_points.size(); + Keypoint_VX.resize(S); sort(key_points.begin(), key_points.end(), sortbysize_CV); - vx_size stride = 0; void *base = NULL; vx_size L = 0; + vx_size stride = 0; + void *base = NULL; + vx_size L = 0; for (vector::const_iterator i = key_points.begin(); i != key_points.end(); ++i) { - X = key_points[j].pt.x; Y = key_points[j].pt.y; - K_Size = key_points[j].size; K_Angle = key_points[j].angle; K_Response = key_points[j].response; - - if (fmod(X, 1) >= 0.5)x = (int)ceil(X); else x = (int)floor(X); - if (fmod(Y, 1) >= 0.5)y = (int)ceil(Y); else y = (int)floor(Y); - - Keypoint_VX[j].x = x; Keypoint_VX[j].y = y; - Keypoint_VX[j].strength = K_Size; Keypoint_VX[j].orientation = K_Angle; Keypoint_VX[j].scale = K_Response; - Keypoint_VX[j].tracking_status = 1; Keypoint_VX[j].error = 0; + float X, Y, K_Size, K_Angle, K_Response; + + X = key_points[j].pt.x; + Y = key_points[j].pt.y; + K_Size = key_points[j].size; + K_Angle = key_points[j].angle; + K_Response = key_points[j].response; + + if (fmod(X, 1) >= 0.5) + x = (int)ceil(X); + else + x = (int)floor(X); + if (fmod(Y, 1) >= 0.5) + y = (int)ceil(Y); + else + y = (int)floor(Y); + + Keypoint_VX[j].x = x; + Keypoint_VX[j].y = y; + Keypoint_VX[j].strength = K_Size; + Keypoint_VX[j].orientation = K_Angle; + Keypoint_VX[j].scale = K_Response; + Keypoint_VX[j].tracking_status = 1; + Keypoint_VX[j].error = 0; j++; } - vx_keypoint_t * keypoint_ptr = &Keypoint_VX[0]; size = min(size, S); + vx_keypoint_t *keypoint_ptr = &Keypoint_VX[0]; + size = min(size, S); status = vxTruncateArray(array, 0); - if (status){ vxAddLogEntry((vx_reference)array, status, "CV_to_VX_keypoints ERROR: vxTruncateArray failed\n"); return status; } + if (status) + { + vxAddLogEntry((vx_reference)array, status, "CV_to_VX_keypoints ERROR: vxTruncateArray failed\n"); + return status; + } status = vxAddArrayItems(array, size, keypoint_ptr, sizeof(vx_keypoint_t)); - if (status){ vxAddLogEntry((vx_reference)array, status, "CV_to_VX_keypoints ERROR: vxAddArrayItems failed\n"); return status; } + if (status) + { + vxAddLogEntry((vx_reference)array, status, "CV_to_VX_keypoints ERROR: vxAddArrayItems failed\n"); + return status; + } return status; } @@ -219,37 +288,61 @@ OpenCV Points to OpenVX Keypoints int CVPoints2f_to_VX_keypoints(vector key_points, vx_array array) { vx_status status = VX_SUCCESS; - vector Keypoint_VX; float X, Y; int x, y, j = 0; - void *ptr = NULL; vx_size size = 0; + vector Keypoint_VX; + + int x, y, j = 0; + void *ptr = NULL; + vx_size size = 0; STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); - size_t S = key_points.size(); Keypoint_VX.resize(S); + size_t S = key_points.size(); + Keypoint_VX.resize(S); for (int i = 0; i < (int)key_points.size(); ++i) { - X = key_points[j].x; Y = key_points[j].y; - - if (fmod(X, 1) >= 0.5)x = (int)ceil(X); else x = (int)floor(X); - if (fmod(Y, 1) >= 0.5)y = (int)ceil(Y); else y = (int)floor(Y); - - Keypoint_VX[j].x = x; Keypoint_VX[j].y = y; - Keypoint_VX[j].strength = 0; Keypoint_VX[j].orientation = 0; Keypoint_VX[j].scale = 0; - Keypoint_VX[j].tracking_status = 0; Keypoint_VX[j].error = 0; + float X, Y; + X = key_points[j].x; + Y = key_points[j].y; + + if (fmod(X, 1) >= 0.5) + x = (int)ceil(X); + else + x = (int)floor(X); + if (fmod(Y, 1) >= 0.5) + y = (int)ceil(Y); + else + y = (int)floor(Y); + + Keypoint_VX[j].x = x; + Keypoint_VX[j].y = y; + Keypoint_VX[j].strength = 0; + Keypoint_VX[j].orientation = 0; + Keypoint_VX[j].scale = 0; + Keypoint_VX[j].tracking_status = 0; + Keypoint_VX[j].error = 0; j++; } - vx_keypoint_t * keypoint_ptr = &Keypoint_VX[0]; size = min(size, S); + vx_keypoint_t *keypoint_ptr = &Keypoint_VX[0]; + size = min(size, S); status = vxTruncateArray(array, 0); - if (status){ vxAddLogEntry((vx_reference)array, status, "CVPoints2f_to_VX_keypoints ERROR: vxTruncateArray failed\n"); return status; } + if (status) + { + vxAddLogEntry((vx_reference)array, status, "CVPoints2f_to_VX_keypoints ERROR: vxTruncateArray failed\n"); + return status; + } status = vxAddArrayItems(array, size, keypoint_ptr, sizeof(vx_keypoint_t)); - if (status){ vxAddLogEntry((vx_reference)array, status, "CVPoints2f_to_VX_keypoints ERROR: vxAddArrayItems failed\n"); return status; } + if (status) + { + vxAddLogEntry((vx_reference)array, status, "CVPoints2f_to_VX_keypoints ERROR: vxAddArrayItems failed\n"); + return status; + } return status; - } /************************************************************************************************************ @@ -257,17 +350,26 @@ OpenCV Descriptors to OpenVX Descriptors *************************************************************************************************************/ int CV_DESP_to_VX_DESP(Mat mat, vx_array array, int stride) { - vx_status status = VX_SUCCESS; vx_size size = 0; + vx_status status = VX_SUCCESS; + vx_size size = 0; STATUS_ERROR_CHECK(vxQueryArray(array, VX_ARRAY_ATTRIBUTE_CAPACITY, &size, sizeof(size))); uchar *p = mat.data; status = vxTruncateArray(array, 0); - if (status){ vxAddLogEntry((vx_reference)array, status, "CV_DESP_to_VX_DESP ERROR: vxTruncateArray failed\n"); return status; } + if (status) + { + vxAddLogEntry((vx_reference)array, status, "CV_DESP_to_VX_DESP ERROR: vxTruncateArray failed\n"); + return status; + } status = vxAddArrayItems(array, size, p, stride); - if (status){ vxAddLogEntry((vx_reference)array, status, "CV_DESP_to_VX_DESP ERROR: vxAddArrayItems failed\n"); return status; } + if (status) + { + vxAddLogEntry((vx_reference)array, status, "CV_DESP_to_VX_DESP ERROR: vxAddArrayItems failed\n"); + return status; + } return status; } @@ -278,15 +380,17 @@ Match VX in and out image size int match_vx_image_parameters(vx_image image1, vx_image image2) { vx_status status = VX_SUCCESS; - vx_uint32 W1 = 0; vx_uint32 H1 = 0; + vx_uint32 W1 = 0; + vx_uint32 H1 = 0; STATUS_ERROR_CHECK(vxQueryImage(image1, VX_IMAGE_ATTRIBUTE_WIDTH, &W1, sizeof(W1))); STATUS_ERROR_CHECK(vxQueryImage(image1, VX_IMAGE_ATTRIBUTE_HEIGHT, &H1, sizeof(H1))); - vx_uint32 W2 = 0; vx_uint32 H2 = 0; + vx_uint32 W2 = 0; + vx_uint32 H2 = 0; STATUS_ERROR_CHECK(vxQueryImage(image2, VX_IMAGE_ATTRIBUTE_WIDTH, &W2, sizeof(W2))); STATUS_ERROR_CHECK(vxQueryImage(image2, VX_IMAGE_ATTRIBUTE_HEIGHT, &H2, sizeof(H2))); - //Input and Output image size match check + // Input and Output image size match check if (W1 != W2 || H1 != H2) { status = VX_ERROR_INVALID_DIMENSION; diff --git a/apps/bubble_pop/source/internal_publishKernels.cpp b/apps/bubble_pop/source/internal_publishKernels.cpp index 912d2f1bad..72264b34df 100644 --- a/apps/bubble_pop/source/internal_publishKernels.cpp +++ b/apps/bubble_pop/source/internal_publishKernels.cpp @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,7 +26,7 @@ THE SOFTWARE. /********************************************************************** PUBLIC FUNCTION for VX POP user defined functions **********************************************************************/ -extern "C" SHARED_PUBLIC vx_status VX_API_CALL vxPublishKernels(vx_context context) +extern "C" SHARED_PUBLIC vx_status VX_API_CALL vxPublishKernels(vx_context context) { vx_status status = VX_SUCCESS; printf("vxPublishKernels\n"); diff --git a/apps/bubble_pop/source/internal_vxNodes.cpp b/apps/bubble_pop/source/internal_vxNodes.cpp index 201cac7abc..fe9349a512 100644 --- a/apps/bubble_pop/source/internal_vxNodes.cpp +++ b/apps/bubble_pop/source/internal_vxNodes.cpp @@ -1,16 +1,16 @@ -/* +/* Copyright (c) 2015 - 2022 Advanced Micro Devices, Inc. All rights reserved. - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,9 +24,9 @@ THE SOFTWARE. #include "vx_ext_pop.h" vx_node vxCreateNodeByStructure(vx_graph graph, - vx_enum kernelenum, - vx_reference params[], - vx_uint32 num) + vx_enum kernelenum, + vx_reference params[], + vx_uint32 num) { vx_status status = VX_SUCCESS; vx_node node = 0; @@ -43,8 +43,8 @@ vx_node vxCreateNodeByStructure(vx_graph graph, if (params[p]) { status = vxSetParameterByIndex(node, - p, - params[p]); + p, + params[p]); if (status != VX_SUCCESS) { vxAddLogEntry((vx_reference)graph, status, "Kernel %d Parameter %u is invalid.\n", kernelenum, p); @@ -82,9 +82,9 @@ extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtPopNode_bubblePop(vx_graph gra }; return vxCreateNodeByStructure(graph, - VX_KERNEL_EXT_POP_BUBBLE_POP, - params, - dimof(params)); + VX_KERNEL_EXT_POP_BUBBLE_POP, + params, + dimof(params)); } /******************************************************************************************************************* @@ -99,7 +99,7 @@ extern "C" SHARED_PUBLIC vx_node VX_API_CALL vxExtPopNode_donutPop(vx_graph grap }; return vxCreateNodeByStructure(graph, - VX_KERNEL_EXT_POP_DONUT_POP, - params, - dimof(params)); + VX_KERNEL_EXT_POP_DONUT_POP, + params, + dimof(params)); } \ No newline at end of file diff --git a/apps/cloud_inference/server_app/CMakeLists.txt b/apps/cloud_inference/server_app/CMakeLists.txt index 09e5b8858b..89a1912a10 100644 --- a/apps/cloud_inference/server_app/CMakeLists.txt +++ b/apps/cloud_inference/server_app/CMakeLists.txt @@ -21,17 +21,29 @@ cmake_minimum_required(VERSION 3.0) project(inference_server_app) +set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm Installation Path") +# need to do this to avoid setting the default path to /usr/local +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX ${ROCM_PATH}/mivisionx CACHE PATH "mivisionx default ROCm installation path" FORCE) +endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) + list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../../amd_openvx/cmake) set(CMAKE_CXX_STANDARD 11) -find_package(OpenCL REQUIRED) +find_package(OpenCL QUIET) find_package(OpenCV REQUIRED) +if(NOT OpenCL_FOUND) + message(FATAL_ERROR "inference_server_app - Only supported with OpenCL Backend" ) +endif(NOT OpenCL_FOUND) + include_directories(../../../amd_openvx/openvx/include ${OpenCL_INCLUDE_DIRS} ../../../amd_openvx_extensions/amd_nn ) +link_directories(${ROCM_PATH}/mivisionx/lib) list(APPEND SOURCES common.cpp @@ -48,7 +60,7 @@ list(APPEND SOURCES ) add_executable(inference_server_app ${SOURCES}) -target_link_libraries(inference_server_app vx_nn openvx pthread) +target_link_libraries(inference_server_app vx_nn openvx pthread dl) install(TARGETS inference_server_app DESTINATION bin) if(OpenCL_FOUND) diff --git a/apps/dg_test/README.md b/apps/dg_test/README.md index e728c5d5cb..4a7cde5001 100644 --- a/apps/dg_test/README.md +++ b/apps/dg_test/README.md @@ -31,7 +31,7 @@ See the [OpenVX documentation](https://www.khronos.org/registry/OpenVX/specs/1.0 ### Pre-requisites 1. Build & Install [MIVisionX](https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX#build--install-mivisionx) -2. [OpenCV 3.1](https://opencv.org/opencv-3-1.html) or higher +2. [OpenCV 3.1](https://github.com/opencv/opencv/releases) or higher ### Build using Cmake on Linux (Ubuntu 16.04 64bit) diff --git a/apps/image_augmentation/README.md b/apps/image_augmentation/README.md index d1e3c7e5a1..d39493edcf 100644 --- a/apps/image_augmentation/README.md +++ b/apps/image_augmentation/README.md @@ -10,7 +10,7 @@ This application demonstrates the basic usage of rocAL's C API to load JPEG imag * Ubuntu Linux, [version `16.04` or later](https://www.microsoft.com/software-download/windows10) * rocAL library (Part of the MIVisionX toolkit) -* [OpenCV 3.4+](https://github.com/opencv/opencv/releases/tag/3.4.0) +* [OpenCV 3.1](https://github.com/opencv/opencv/releases) or higher * Radeon Performance Primitives (RPP) ### build diff --git a/apps/mivisionx_inference_analyzer/mivisionx_inference_analyzer.py b/apps/mivisionx_inference_analyzer/mivisionx_inference_analyzer.py index 45aabe0c6d..5b9bb43ce3 100644 --- a/apps/mivisionx_inference_analyzer/mivisionx_inference_analyzer.py +++ b/apps/mivisionx_inference_analyzer/mivisionx_inference_analyzer.py @@ -4,7 +4,7 @@ __license__ = "MIT" __version__ = "1.0" __maintainer__ = "Kiriti Nagesh Gowda" -__email__ = "Kiriti.NageshGowda@amd.com" +__email__ = "mivisionx.support@amd.com" __status__ = "Shipping" __script_name__ = "MIVisionX Inference Analyzer" diff --git a/apps/mivisionx_validation_tool/mivisionx_validation_tool.py b/apps/mivisionx_validation_tool/mivisionx_validation_tool.py index e2b1c11d01..2a887afd52 100644 --- a/apps/mivisionx_validation_tool/mivisionx_validation_tool.py +++ b/apps/mivisionx_validation_tool/mivisionx_validation_tool.py @@ -4,7 +4,7 @@ __license__ = "MIT" __version__ = "0.9.5" __maintainer__ = "Kiriti Nagesh Gowda" -__email__ = "Kiriti.NageshGowda@amd.com" +__email__ = "mivisionx.support@amd.com" __status__ = "ALPHA" __script_name__ = "MIVisionX Validation Tool" diff --git a/apps/mivisionx_winml_classifier/README.md b/apps/mivisionx_winml_classifier/README.md index 7495ccad09..bc724fecdd 100644 --- a/apps/mivisionx_winml_classifier/README.md +++ b/apps/mivisionx_winml_classifier/README.md @@ -13,7 +13,7 @@ This application is a sample for developing windows application using MIVisionX * Visual Studio 2019, [version `16.11.5` or later](https://developer.microsoft.com/en-us/windows/downloads) - Visual Studio extension for C++/WinRT * Install [OpenCL SDK](https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK/releases/tag/1.0) -* [OpenCV 3.4+](https://github.com/opencv/opencv/releases/tag/3.4.0) +* [OpenCV 3.1](https://github.com/opencv/opencv/releases) or higher + Set `OpenCV_DIR` environment variable to `OpenCV/build` folder + Add `OpenCV_DIR\x64\vc14\bin` or `OpenCV_DIR\x64\vc15\bin` to your `PATH` diff --git a/apps/mivisionx_winml_yolov2/README.md b/apps/mivisionx_winml_yolov2/README.md index 7c7c838aef..f3a45c6d4b 100644 --- a/apps/mivisionx_winml_yolov2/README.md +++ b/apps/mivisionx_winml_yolov2/README.md @@ -14,7 +14,7 @@ This application shows how to run tiny yolov2 (20 classes) with MIVisionX RunTim - Visual Studio extension for C++/WinRT * Install [OpenCL SDK](https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK/releases/tag/1.0) -* [OpenCV 3.4+](https://github.com/opencv/opencv/releases/tag/3.4.0) +* [OpenCV 3.1](https://github.com/opencv/opencv/releases) or higher + Set `OpenCV_DIR` environment variable to `OpenCV/build` folder + Add `OpenCV_DIR\x64\vc14\bin` or `OpenCV_DIR\x64\vc15\bin` to your `PATH` diff --git a/apps/optical_flow/README.md b/apps/optical_flow/README.md index 33785cd36d..7b73560617 100644 --- a/apps/optical_flow/README.md +++ b/apps/optical_flow/README.md @@ -4,7 +4,7 @@ # OpenVX Samples -Khronos OpenVX™ is an open, royalty-free standard for cross-platform acceleration of computer vision applications. OpenVX enables performance and power-optimized computer vision processing, especially important in embedded and real-time use cases such as face, body, and gesture tracking, smart video surveillance, advanced driver assistance systems (ADAS), object and scene reconstruction, augmented reality, visual inspection, robotics and more. +Khronos OpenVX™ is an open, royalty-free standard for cross-platform acceleration of computer vision applications. OpenVX enables performance and power-optimized computer vision processing, especially important in embedded and real-time use cases such as face, body, and gesture tracking, smart video surveillance, advanced driver assistance systems (ADAS), object and scene reconstruction, augmented reality, visual inspection, robotics and more. In this sample, we provide OpenVX sample applications to use with any conformant implementation of OpenVX. diff --git a/docker/README.md b/docker/README.md index a1d389f84d..073194ead3 100644 --- a/docker/README.md +++ b/docker/README.md @@ -20,10 +20,10 @@ sudo docker run -it --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --de | Build Level | MIVisionX Dependencies | Modules | Libraries and Executables | Docker File | |-------------|----------------------------------------------------|--------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `Level_1` | cmake
gcc
g++ | amd_openvx
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - CPU with Display OFF | level-1.dockerfile | -| `Level_2` | ROCm OpenCL
+Level 1 | amd_openvx
amd_openvx_extensions
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `loom_shell` - 360 Stitch App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display OFF | level-2.dockerfile | -| `Level_3` | OpenCV
FFMPEG
+Level 2 | amd_openvx
amd_openvx_extensions
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `mv_compile` - Neural Net Model Compile
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON | level-3.dockerfile | -| `Level_4` | MIOpenGEMM
MIOpen
ProtoBuf
+Level 3 | amd_openvx
amd_openvx_extensions
apps
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `inference_server_app` - Cloud Inference App | level-4.dockerfile | +| `Level_1` | cmake
gcc
g++ | amd_openvx
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - CPU with Display OFF | level-1.dockerfile | +| `Level_2` | ROCm OpenCL
+Level 1 | amd_openvx
amd_openvx_extensions
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `loom_shell` - 360 Stitch App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display OFF | level-2.dockerfile | +| `Level_3` | OpenCV
FFMPEG
+Level 2 | amd_openvx
amd_openvx_extensions
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `mv_compile` - Neural Net Model Compile
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON | level-3.dockerfile | +| `Level_4` | MIOpenGEMM
MIOpen
ProtoBuf
+Level 3 | amd_openvx
amd_openvx_extensions
apps
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `inference_server_app` - Cloud Inference App | level-4.dockerfile | ## Ubuntu `18`/`20` DockerFiles @@ -32,8 +32,8 @@ sudo docker run -it --device=/dev/kfd --device=/dev/dri --cap-add=SYS_RAWIO --de | Build Level | MIVisionX Dependencies | Modules | Libraries and Executables | Docker File | |-------------|----------------------------------------------------|--------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `Level_1` | cmake
gcc
g++ | amd_openvx
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - CPU with Display OFF | level-1.dockerfile | -| `Level_2` | ROCm OpenCL
+Level 1 | amd_openvx
amd_openvx_extensions
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `loom_shell` - 360 Stitch App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display OFF | level-2.dockerfile | -| `Level_3` | OpenCV
FFMPEG
+Level 2 | amd_openvx
amd_openvx_extensions
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `mv_compile` - Neural Net Model Compile
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON | level-3.dockerfile | -| `Level_4` | MIOpenGEMM
MIOpen
ProtoBuf
+Level 3 | amd_openvx
amd_openvx_extensions
apps
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `inference_server_app` - Cloud Inference App | level-4.dockerfile | -| `Level_5` | AMD_RPP
rocAL deps
+Level 4 | amd_openvx
amd_openvx_extensions
apps
rocAL
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `inference_server_app` - Cloud Inference App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_rpp.so` - OpenVX™ RPP Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `librali.so` - ROCm Augmentation Library
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `rali_pybind.so` - rocAL Pybind Lib | level-5.dockerfile | +| `Level_1` | cmake
gcc
g++ | amd_openvx
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - CPU with Display OFF | level-1.dockerfile | +| `Level_2` | ROCm OpenCL
+Level 1 | amd_openvx
amd_openvx_extensions
utilities | ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libopenvx.so` - OpenVX™ Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib - CPU/GPU
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `loom_shell` - 360 Stitch App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display OFF | level-2.dockerfile | +| `Level_3` | OpenCV
FFMPEG
+Level 2 | amd_openvx
amd_openvx_extensions
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `mv_compile` - Neural Net Model Compile
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON | level-3.dockerfile | +| `Level_4` | MIOpenGEMM
MIOpen
ProtoBuf
+Level 3 | amd_openvx
amd_openvx_extensions
apps
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `inference_server_app` - Cloud Inference App | level-4.dockerfile | +| `Level_5` | AMD_RPP
rocAL deps
+Level 4 | amd_openvx
amd_openvx_extensions
apps
rocAL
utilities | ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libopenvx.so` - OpenVX™ Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvxu.so` - OpenVX™ immediate node Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_loomsl.so` - Loom 360 Stitch Lib
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `loom_shell` - 360 Stitch App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_amd_media.so` - OpenVX™ Media Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_opencv.so` - OpenVX™ OpenCV InterOp Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `mv_compile` - Neural Net Model Compile
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runcl` - OpenCL™ program debug App
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `runvx` - OpenVX™ Graph Executor - Display ON
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `libvx_nn.so` - OpenVX™ Neural Net Extension
![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `inference_server_app` - Cloud Inference App
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `libvx_rpp.so` - OpenVX™ RPP Extension
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `librali.so` - ROCm Augmentation Library
![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `rali_pybind.so` - rocAL Pybind Lib | level-5.dockerfile | diff --git a/docker/centos7/level-3.dockerfile b/docker/centos7/level-3.dockerfile index 62500920a1..6e9f236fda 100644 --- a/docker/centos7/level-3.dockerfile +++ b/docker/centos7/level-3.dockerfile @@ -14,9 +14,9 @@ RUN echo -e "[ROCm]\nname=ROCm\nbaseurl=https://repo.radeon.com/rocm/yum/rpm\nen /etc/yum.repos.d/rocm.repo && yum -y install --nogpgcheck rocm-dev # install OpenCV & FFMPEG - Level 3 RUN yum -y groupinstall 'Development Tools' --nogpgcheck && yum -y install --nogpgcheck gtk2-devel libjpeg-devel libpng-devel libtiff-devel libavc1394 wget unzip && \ - mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ + mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ mkdir build && cd build && \ - cmake3 -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-3.4.0 && \ + cmake3 -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-4.5.5 && \ make -j8 && make install RUN yum -y install --nogpgcheck autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make pkgconfig zlib-devel && \ yum -y install --nogpgcheck nasm && yum -y --enablerepo=extras install --nogpgcheck epel-release && yum -y install --nogpgcheck yasm && \ diff --git a/docker/centos7/level-4.dockerfile b/docker/centos7/level-4.dockerfile index ed1ebf35fe..c121ae73a1 100644 --- a/docker/centos7/level-4.dockerfile +++ b/docker/centos7/level-4.dockerfile @@ -14,9 +14,9 @@ RUN echo -e "[ROCm]\nname=ROCm\nbaseurl=https://repo.radeon.com/rocm/yum/rpm\nen /etc/yum.repos.d/rocm.repo && yum -y install --nogpgcheck rocm-dev # install OpenCV & FFMPEG - Level 3 RUN yum -y groupinstall 'Development Tools' --nogpgcheck && yum -y install --nogpgcheck gtk2-devel libjpeg-devel libpng-devel libtiff-devel libavc1394 wget unzip && \ - mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ + mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ mkdir build && cd build && \ - cmake3 -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-3.4.0 && \ + cmake3 -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-4.5.5 && \ make -j8 && make install RUN yum -y install --nogpgcheck autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make pkgconfig zlib-devel && \ yum -y install --nogpgcheck nasm && yum -y --enablerepo=extras install --nogpgcheck epel-release && yum -y install --nogpgcheck yasm && \ diff --git a/docker/centos8/level-3.dockerfile b/docker/centos8/level-3.dockerfile index e3cab5c575..71fd9a94c9 100644 --- a/docker/centos8/level-3.dockerfile +++ b/docker/centos8/level-3.dockerfile @@ -10,9 +10,9 @@ RUN echo -e "[ROCm]\nname=ROCm\nbaseurl=https://repo.radeon.com/rocm/centos8/rpm /etc/yum.repos.d/rocm.repo && yum -y update --nogpgcheck && yum -y install --nogpgcheck rocm-dev # install OpenCV & FFMPEG - Level 3 RUN yum -y groupinstall 'Development Tools' --nogpgcheck && yum -y install --nogpgcheck gtk2-devel libjpeg-devel libpng-devel libtiff-devel libavc1394 wget unzip && \ - mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ + mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ mkdir build && cd build && \ - cmake -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-3.4.0 && \ + cmake -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-4.5.5 && \ make -j8 && make install RUN yum -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \ yum -y install --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm && \ diff --git a/docker/centos8/level-4.dockerfile b/docker/centos8/level-4.dockerfile index 5b8839e70a..9c94ed80c6 100644 --- a/docker/centos8/level-4.dockerfile +++ b/docker/centos8/level-4.dockerfile @@ -10,9 +10,9 @@ RUN echo -e "[ROCm]\nname=ROCm\nbaseurl=https://repo.radeon.com/rocm/centos8/rpm /etc/yum.repos.d/rocm.repo && yum -y update --nogpgcheck && yum -y install --nogpgcheck rocm-dev # install OpenCV & FFMPEG - Level 3 RUN yum -y groupinstall 'Development Tools' --nogpgcheck && yum -y install --nogpgcheck gtk2-devel libjpeg-devel libpng-devel libtiff-devel libavc1394 wget unzip && \ - mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ + mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ mkdir build && cd build && \ - cmake -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-3.4.0 && \ + cmake -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-4.5.5 && \ make -j8 && make install RUN yum -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \ yum -y install --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm && \ diff --git a/docker/conformance/system_info.py b/docker/conformance/system_info.py index 027185affb..fd1915caf2 100644 --- a/docker/conformance/system_info.py +++ b/docker/conformance/system_info.py @@ -28,7 +28,7 @@ __license__ = "MIT" __version__ = "1.0.0" __maintainer__ = "Kiriti Nagesh Gowda" -__email__ = "Kiriti.NageshGowda@amd.com" +__email__ = "mivisionx.support@amd.com" __status__ = "Shipping" diff --git a/docker/mivisionx-on-centos7.dockerfile b/docker/mivisionx-on-centos7.dockerfile index ed1ebf35fe..433f7fde2a 100644 --- a/docker/mivisionx-on-centos7.dockerfile +++ b/docker/mivisionx-on-centos7.dockerfile @@ -14,9 +14,9 @@ RUN echo -e "[ROCm]\nname=ROCm\nbaseurl=https://repo.radeon.com/rocm/yum/rpm\nen /etc/yum.repos.d/rocm.repo && yum -y install --nogpgcheck rocm-dev # install OpenCV & FFMPEG - Level 3 RUN yum -y groupinstall 'Development Tools' --nogpgcheck && yum -y install --nogpgcheck gtk2-devel libjpeg-devel libpng-devel libtiff-devel libavc1394 wget unzip && \ - mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ + mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ mkdir build && cd build && \ - cmake3 -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-3.4.0 && \ + cmake3 -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-4.5.5 && \ make -j8 && make install RUN yum -y install --nogpgcheck autoconf automake bzip2 bzip2-devel cmake freetype-devel gcc gcc-c++ git libtool make pkgconfig zlib-devel && \ yum -y install --nogpgcheck nasm && yum -y --enablerepo=extras install --nogpgcheck epel-release && yum -y install --nogpgcheck yasm && \ @@ -49,4 +49,4 @@ WORKDIR /workspace # install MIVisionX RUN git clone https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX.git && mkdir build && cd build && \ - cmake3 ../MIVisionX && make -j8 && make install \ No newline at end of file + cmake3 -DBACKEND=HIP ../MIVisionX && make -j8 && make install diff --git a/docker/mivisionx-on-centos8.dockerfile b/docker/mivisionx-on-centos8.dockerfile index 5b8839e70a..7ea3009e20 100644 --- a/docker/mivisionx-on-centos8.dockerfile +++ b/docker/mivisionx-on-centos8.dockerfile @@ -10,9 +10,9 @@ RUN echo -e "[ROCm]\nname=ROCm\nbaseurl=https://repo.radeon.com/rocm/centos8/rpm /etc/yum.repos.d/rocm.repo && yum -y update --nogpgcheck && yum -y install --nogpgcheck rocm-dev # install OpenCV & FFMPEG - Level 3 RUN yum -y groupinstall 'Development Tools' --nogpgcheck && yum -y install --nogpgcheck gtk2-devel libjpeg-devel libpng-devel libtiff-devel libavc1394 wget unzip && \ - mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ + mkdir opencv && cd opencv && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ mkdir build && cd build && \ - cmake -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-3.4.0 && \ + cmake -DWITH_OPENCL=OFF -DWITH_OPENCLAMDFFT=OFF -DWITH_OPENCLAMDBLAS=OFF -DWITH_VA_INTEL=OFF -DWITH_OPENCL_SVM=OFF ../opencv-4.5.5 && \ make -j8 && make install RUN yum -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \ yum -y install --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm && \ @@ -39,4 +39,4 @@ WORKDIR /workspace # install MIVisionX RUN git clone https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX.git && mkdir build && cd build && \ - cmake ../MIVisionX && make -j8 && make install \ No newline at end of file + cmake -DBACKEND=HIP ../MIVisionX && make -j8 && make install diff --git a/docker/mivisionx-on-ubuntu18.dockerfile b/docker/mivisionx-on-ubuntu18.dockerfile index 0a3c4d0be5..6136b58ef4 100644 --- a/docker/mivisionx-on-ubuntu18.dockerfile +++ b/docker/mivisionx-on-ubuntu18.dockerfile @@ -15,8 +15,8 @@ RUN apt-get -y install libnuma-dev wget sudo gnupg2 kmod python3-dev && \ # install OpenCV & FFMPEG - Level 3 RUN apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ @@ -41,7 +41,7 @@ RUN apt-get -y install sqlite3 libsqlite3-dev libbz2-dev libssl-dev python-dev p wget https://github.com/ROCmSoftwarePlatform/MIOpen/archive/2.14.0.zip && unzip 2.14.0.zip && \ cd MIOpen-2.14.0 && mkdir build && cd build && \ #cd MIOpen-2.14.0 && sudo cmake -P install_deps.cmake --minimum && mkdir build && cd build && \ - deps install turned off - cmake -DMIOPEN_BACKEND=OpenCL -DMIOPEN_USE_MIOPENGEMM=On ../ && make -j8 && make MIOpenDriver && sudo make install && cd ../../ && \ + CXX=/opt/rocm/llvm/bin/clang++ cmake -DMIOPEN_BACKEND=HIP ../ && make -j8 && make MIOpenDriver && sudo make install && cd ../../ && \ git clone -b v3.12.0 https://github.com/protocolbuffers/protobuf.git && cd protobuf && git submodule update --init --recursive && \ ./autogen.sh && ./configure && make -j8 && make check -j8 && sudo make install && sudo ldconfig && cd # install MIVisionX rocAL dependency - Level 5 @@ -50,10 +50,10 @@ RUN apt-get -y install libgflags-dev libgoogle-glog-dev liblmdb-dev nasm yasm li cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_STATIC=FALSE -DCMAKE_INSTALL_DOCDIR=/usr/share/doc/libjpeg-turbo-2.0.3 \ -DCMAKE_INSTALL_DEFAULT_LIBDIR=lib ../ && make -j4 && sudo make install && cd ../../ && \ git clone -b 0.92 https://github.com/GPUOpen-ProfessionalCompute-Libraries/rpp.git && cd rpp && mkdir build && cd build && \ - cmake -DBACKEND=OCL ../ && make -j4 && sudo make install && cd + cmake -DBACKEND=HIP ../ && make -j4 && sudo make install && cd WORKDIR /workspace # install MIVisionX RUN git clone https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX.git && mkdir build && cd build && \ - cmake ../MIVisionX && make -j8 && make install \ No newline at end of file + cmake -DBACKEND=HIP ../MIVisionX && make -j8 && make install diff --git a/docker/mivisionx-on-ubuntu20.dockerfile b/docker/mivisionx-on-ubuntu20.dockerfile index e59dbc25f6..f48a28920a 100644 --- a/docker/mivisionx-on-ubuntu20.dockerfile +++ b/docker/mivisionx-on-ubuntu20.dockerfile @@ -15,8 +15,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y install libnuma-dev wget sudo gnup # install OpenCV & FFMPEG - Level 3 RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN DEBIAN_FRONTEND=noninteractive apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ @@ -41,7 +41,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y install sqlite3 libsqlite3-dev lib wget https://github.com/ROCmSoftwarePlatform/MIOpen/archive/2.14.0.zip && unzip 2.14.0.zip && \ cd MIOpen-2.14.0 && mkdir build && cd build && \ #cd MIOpen-2.14.0 && sudo cmake -P install_deps.cmake --minimum && mkdir build && cd build && \ - deps install turned off - cmake -DMIOPEN_BACKEND=OpenCL -DMIOPEN_USE_MIOPENGEMM=On ../ && make -j8 && make MIOpenDriver && sudo make install && cd ../../ && \ + CXX=/opt/rocm/llvm/bin/clang++ cmake -DMIOPEN_BACKEND=HIP ../ && make -j8 && make MIOpenDriver && sudo make install && cd ../../ && \ git clone -b v3.12.0 https://github.com/protocolbuffers/protobuf.git && cd protobuf && git submodule update --init --recursive && \ ./autogen.sh && ./configure && make -j8 && make check -j8 && sudo make install && sudo ldconfig && cd # install MIVisionX rocAL dependency - Level 5 @@ -50,10 +50,10 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y install libgflags-dev libgoogle-gl cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_STATIC=FALSE -DCMAKE_INSTALL_DOCDIR=/usr/share/doc/libjpeg-turbo-2.0.3 \ -DCMAKE_INSTALL_DEFAULT_LIBDIR=lib ../ && make -j4 && sudo make install && cd ../../ && \ git clone -b 0.92 https://github.com/GPUOpen-ProfessionalCompute-Libraries/rpp.git && cd rpp && mkdir build && cd build && \ - cmake -DBACKEND=OCL ../ && make -j4 && sudo make install && cd + cmake -DBACKEND=HIP ../ && make -j4 && sudo make install && cd WORKDIR /workspace # install MIVisionX RUN git clone https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX.git && mkdir build && cd build && \ - cmake ../MIVisionX && make -j8 && make install \ No newline at end of file + cmake -DBACKEND=HIP ../MIVisionX && make -j8 && make install diff --git a/docker/pytorch/mivisionx-with-pytorch.dockerfile b/docker/pytorch/mivisionx-with-pytorch.dockerfile index 7696f97e66..c895270f38 100644 --- a/docker/pytorch/mivisionx-with-pytorch.dockerfile +++ b/docker/pytorch/mivisionx-with-pytorch.dockerfile @@ -9,8 +9,8 @@ RUN apt-get -y install gcc g++ cmake git # install OpenCV & FFMPEG RUN apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ @@ -35,10 +35,10 @@ RUN apt-get -y install libgflags-dev libgoogle-glog-dev liblmdb-dev nasm yasm li git clone -b 2.0.6.2 https://github.com/rrawther/libjpeg-turbo.git && cd libjpeg-turbo && mkdir build && cd build && \ cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_STATIC=FALSE -DCMAKE_INSTALL_DEFAULT_LIBDIR=lib ../ && make -j4 && sudo make install && cd ../../ && \ git clone -b 0.92 https://github.com/GPUOpen-ProfessionalCompute-Libraries/rpp.git && cd rpp && mkdir build && cd build && \ - cmake -DBACKEND=OCL ../ && make -j4 && sudo make install && cd + cmake -DBACKEND=HIP ../ && make -j4 && sudo make install && cd WORKDIR /workspace # install MIVisionX RUN git clone https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX.git && mkdir build && cd build && \ - cmake ../MIVisionX && make -j8 && sudo make install && cd + cmake -DBACKEND=HIP ../MIVisionX && make -j8 && sudo make install && cd diff --git a/docker/ubuntu18/level-3.dockerfile b/docker/ubuntu18/level-3.dockerfile index ed6106833a..085fcd892f 100644 --- a/docker/ubuntu18/level-3.dockerfile +++ b/docker/ubuntu18/level-3.dockerfile @@ -15,8 +15,8 @@ RUN apt-get -y install libnuma-dev wget sudo gnupg2 kmod python3-dev && \ # install OpenCV & FFMPEG - Level 3 RUN apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ diff --git a/docker/ubuntu18/level-4.dockerfile b/docker/ubuntu18/level-4.dockerfile index 65cb2bb695..ce2ab19c0d 100644 --- a/docker/ubuntu18/level-4.dockerfile +++ b/docker/ubuntu18/level-4.dockerfile @@ -15,8 +15,8 @@ RUN apt-get -y install libnuma-dev wget sudo gnupg2 kmod python3-dev && \ # install OpenCV & FFMPEG - Level 3 RUN apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ diff --git a/docker/ubuntu18/level-5.dockerfile b/docker/ubuntu18/level-5.dockerfile index 0a3c4d0be5..9b7336c4b0 100644 --- a/docker/ubuntu18/level-5.dockerfile +++ b/docker/ubuntu18/level-5.dockerfile @@ -15,8 +15,8 @@ RUN apt-get -y install libnuma-dev wget sudo gnupg2 kmod python3-dev && \ # install OpenCV & FFMPEG - Level 3 RUN apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ diff --git a/docker/ubuntu20/level-3.dockerfile b/docker/ubuntu20/level-3.dockerfile index 7989c37f04..74093d4a44 100644 --- a/docker/ubuntu20/level-3.dockerfile +++ b/docker/ubuntu20/level-3.dockerfile @@ -15,8 +15,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y install libnuma-dev wget sudo gnup # install OpenCV & FFMPEG - Level 3 RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN DEBIAN_FRONTEND=noninteractive apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ diff --git a/docker/ubuntu20/level-4.dockerfile b/docker/ubuntu20/level-4.dockerfile index 9371b02ccf..c52f52d30c 100644 --- a/docker/ubuntu20/level-4.dockerfile +++ b/docker/ubuntu20/level-4.dockerfile @@ -15,8 +15,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y install libnuma-dev wget sudo gnup # install OpenCV & FFMPEG - Level 3 RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN DEBIAN_FRONTEND=noninteractive apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ diff --git a/docker/ubuntu20/level-5.dockerfile b/docker/ubuntu20/level-5.dockerfile index e59dbc25f6..3128979a5c 100644 --- a/docker/ubuntu20/level-5.dockerfile +++ b/docker/ubuntu20/level-5.dockerfile @@ -15,8 +15,8 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get -y install libnuma-dev wget sudo gnup # install OpenCV & FFMPEG - Level 3 RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy \ libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev unzip && \ - mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/3.4.0.zip && unzip 3.4.0.zip && \ - mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-3.4.0 && make -j8 && sudo make install && sudo ldconfig && cd + mkdir OpenCV && cd OpenCV && wget https://github.com/opencv/opencv/archive/4.5.5.zip && unzip 4.5.5.zip && \ + mkdir build && cd build && cmake -DWITH_OPENCL=OFF ../opencv-4.5.5 && make -j8 && sudo make install && sudo ldconfig && cd RUN DEBIAN_FRONTEND=noninteractive apt-get -y install autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev libsdl2-dev libtool libva-dev \ libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev \ nasm yasm libx264-dev libx265-dev libnuma-dev libfdk-aac-dev && \ diff --git a/rocAL/rocAL/CMakeLists.txt b/rocAL/rocAL/CMakeLists.txt index 9e956323d3..b53055aa6a 100644 --- a/rocAL/rocAL/CMakeLists.txt +++ b/rocAL/rocAL/CMakeLists.txt @@ -55,7 +55,7 @@ if( GPU_SUPPORT AND "${BACKEND}" STREQUAL "HIP") ELSE() SET(HSA_PATH $ENV{HSA_PATH}) ENDIF() - find_package(HIP QUIET REQUIRED) + find_package(HIP QUIET) if(HIP_FOUND) SET(BUILD_RALI true) message(STATUS "Found HIP for rocAL: " ${HIP_VERSION} ${HIP_PATH} ) @@ -66,7 +66,7 @@ if( GPU_SUPPORT AND "${BACKEND}" STREQUAL "HIP") endif() else() SET(BUILD_RALI false) - message(FATAL_ERROR "Could'nt find HIP. Ensure that HIP is either installed in /opt/rocm/hip or the variable HIP_PATH is set.") + message("-- ${Yellow}NOTE: rocAL library requires HIP for BACKEND=HIP, Not Found ${ColourReset}") endif() endif() @@ -211,6 +211,11 @@ if(${BUILD_RALI}) target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_OPENCV=1) include_directories(${OpenCV_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBRARIES}) + if(${OpenCV_VERSION_MAJOR} EQUAL 4) + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_OPENCV_4=1) + else() + target_compile_definitions(${PROJECT_NAME} PUBLIC USE_OPENCV_4=0) + endif() else() target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_OPENCV=0) endif() diff --git a/rocAL/rocAL/include/hardware_video_decoder.h b/rocAL/rocAL/include/hardware_video_decoder.h new file mode 100644 index 0000000000..68f705cdc9 --- /dev/null +++ b/rocAL/rocAL/include/hardware_video_decoder.h @@ -0,0 +1,51 @@ +/* +Copyright (c) 2019 - 2022 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once + +#include "video_decoder.h" + +#ifdef RALI_VIDEO +class HardWareVideoDecoder : public VideoDecoder +{ +public: + //! Default constructor + HardWareVideoDecoder(); + VideoDecoder::Status Initialize(const char *src_filename) override; + VideoDecoder::Status Decode(unsigned char *output_buffer, unsigned seek_frame_number, size_t sequence_length, size_t stride, int out_width, int out_height, int out_stride, AVPixelFormat out_format) override; + int seek_frame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) override; + void release() override; + ~HardWareVideoDecoder() override; +private: + const char *_src_filename = NULL; + AVFormatContext *_fmt_ctx = NULL; + AVCodecContext *_video_dec_ctx = NULL; + AVCodec *_decoder = NULL; + AVStream *_video_stream = NULL; + int _video_stream_idx = -1; + AVPixelFormat _dec_pix_fmt; + int _codec_width, _codec_height; + AVHWDeviceType *hwDeviceType; + AVBufferRef *hw_device_ctx = NULL; + int hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type, AVBufferRef *hw_device_ctx); +}; +#endif diff --git a/rocAL/rocAL/include/master_graph.h b/rocAL/rocAL/include/master_graph.h index 92ed3516c1..1fde133a84 100644 --- a/rocAL/rocAL/include/master_graph.h +++ b/rocAL/rocAL/include/master_graph.h @@ -84,6 +84,7 @@ class MasterGraph MetaDataBatch *create_caffe_lmdb_record_meta_data_reader(const char *source_path, MetaDataReaderType reader_type, MetaDataType label_type); MetaDataBatch *create_caffe2_lmdb_record_meta_data_reader(const char *source_path, MetaDataReaderType reader_type, MetaDataType label_type); MetaDataBatch* create_cifar10_label_reader(const char *source_path, const char *file_prefix); + MetaDataBatch *create_mxnet_label_reader(const char *source_path, bool is_output); void box_encoder(std::vector &anchors, float criteria, const std::vector &means, const std::vector &stds, bool offset, float scale); void create_randombboxcrop_reader(RandomBBoxCrop_MetaDataReaderType reader_type, RandomBBoxCrop_MetaDataType label_type, bool all_boxes_overlap, bool no_crop, FloatParam* aspect_ratio, bool has_shape, int crop_width, int crop_height, int num_attempts, FloatParam* scaling, int total_num_attempts, int64_t seed=0); const std::pair& meta_data(); diff --git a/rocAL/rocAL/include/meta_data_reader.h b/rocAL/rocAL/include/meta_data_reader.h index 9debf7a10c..bbddb9bf09 100644 --- a/rocAL/rocAL/include/meta_data_reader.h +++ b/rocAL/rocAL/include/meta_data_reader.h @@ -40,7 +40,8 @@ enum class MetaDataReaderType CAFFE2_META_DATA_READER, CAFFE2_DETECTION_META_DATA_READER, TF_DETECTION_META_DATA_READER, - VIDEO_LABEL_READER + VIDEO_LABEL_READER, + MXNET_META_DATA_READER }; enum class MetaDataType { diff --git a/rocAL/rocAL/include/mxnet_meta_data_reader.h b/rocAL/rocAL/include/mxnet_meta_data_reader.h new file mode 100644 index 0000000000..f73d348485 --- /dev/null +++ b/rocAL/rocAL/include/mxnet_meta_data_reader.h @@ -0,0 +1,65 @@ +/* +Copyright (c) 2019 - 2022 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include "commons.h" +#include "meta_data.h" +#include "meta_data_reader.h" +#include "reader.h" + +class MXNetMetaDataReader: public MetaDataReader +{ +public : + void init(const MetaDataConfig& cfg) override; + void lookup(const std::vector& image_names) override; + void read_all(const std::string& path) override; + void release(std::string image_name); + void release() override; + void print_map_contents(); + bool set_timestamp_mode() override { return false; } + MetaDataBatch * get_output() override { return _output; } + MXNetMetaDataReader(); + ~MXNetMetaDataReader() override { delete _output; } +private: + void read_images(); + bool exists(const std::string &image_name); + void add(std::string image_name, int label); + uint32_t DecodeFlag(uint32_t rec) {return (rec >> 29U) & 7U; }; + uint32_t DecodeLength(uint32_t rec) {return rec & ((1U << 29U) - 1U); }; + std::vector> _indices; // used to store seek position and record size for a particular record. + std::ifstream _file_contents; + ImageRecordIOHeader _hdr; + const uint32_t _kMagic = 0xced7230a; + std::map> _map_content; + std::string _path; + DIR *_src_dir; + struct dirent *_entity; + LabelBatch* _output; + std::vector _image_name; +}; \ No newline at end of file diff --git a/rocAL/rocAL/include/mxnet_recordio_reader.h b/rocAL/rocAL/include/mxnet_recordio_reader.h new file mode 100644 index 0000000000..1086c2ec1a --- /dev/null +++ b/rocAL/rocAL/include/mxnet_recordio_reader.h @@ -0,0 +1,113 @@ +/* +Copyright (c) 2019 - 2022 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include "reader.h" +#include "timing_debug.h" + +class MXNetRecordIOReader : public Reader{ +public: + //! Reads the MXNet Record File, and loads the image ids and other necessary info + /*! + \param desc User provided descriptor containing the files' path. + */ + Reader::Status initialize(ReaderConfig desc) override; + //! Reads the next resource item + /*! + \param buf User's provided buffer to receive the loaded images + \return Size of the loaded resource + */ + size_t read_data(unsigned char* buf, size_t max_size) override; + //! Opens the next file in the folder + /*! + \return The size of the next file, 0 if couldn't access it + */ + size_t open() override; + //! Resets the object's state to read from the first file in the folder + void reset() override; + + //! Returns the id of the latest file opened + std::string id() override { return _last_id;}; + + unsigned count_items() override; + + ~MXNetRecordIOReader() override; + + int close() override; + + MXNetRecordIOReader(); + unsigned long long get_shuffle_time() override {return 0;} +private: + //! opens the folder containnig the images + Reader::Status record_reading(); + Reader::Status MXNet_reader(); + std::string _path; + DIR *_src_dir; + struct dirent *_entity; + std::string _image_key; + std::vector _file_names; + std::map > _record_properties; + unsigned _curr_file_idx; + unsigned _current_file_size; + std::string _last_id, _last_file_name; + unsigned int _last_file_size; + int64_t _last_seek_pos; + int64_t _last_data_size; + size_t _shard_id = 0; + size_t _shard_count = 1;// equivalent of batch size + //!< _batch_count Defines the quantum count of the images to be read. It's usually equal to the user's batch size. + /// The loader will repeat images if necessary to be able to have images available in multiples of the load_batch_count, + /// for instance if there are 10 images in the dataset and _batch_count is 3, the loader repeats 2 images as if there are 12 images available. + size_t _batch_count = 1; + size_t _file_id = 0; + size_t _in_batch_read_count = 0; + bool _loop; + bool _shuffle; + int _read_counter = 0; + //!< _file_count_all_shards total_number of files in to figure out the max_batch_size (usually needed for distributed training). + size_t _file_count_all_shards; + void incremenet_read_ptr(); + int release(); + size_t get_file_shard_id(); + void incremenet_file_id() { _file_id++; } + void replicate_last_image_to_fill_last_shard(); + void replicate_last_batch_to_pad_partial_shard(); + void read_image(unsigned char* buff, int64_t seek_position, int64_t data_size); + void read_image_names(); + uint32_t DecodeFlag(uint32_t rec) {return (rec >> 29U) & 7U; }; + uint32_t DecodeLength(uint32_t rec) {return rec & ((1U << 29U) - 1U); }; + std::vector> _indices;// used to store seek position and record size for a particular record. + std::ifstream _file_contents; + const uint32_t _kMagic = 0xced7230a; + int64_t _seek_pos, _data_size_to_read; + ImageRecordIOHeader _hdr; + TimingDBG _shuffle_time; +}; + diff --git a/rocAL/rocAL/include/open_cv_decoder.h b/rocAL/rocAL/include/open_cv_decoder.h index def9d0310c..613b35343c 100644 --- a/rocAL/rocAL/include/open_cv_decoder.h +++ b/rocAL/rocAL/include/open_cv_decoder.h @@ -25,6 +25,13 @@ THE SOFTWARE. #include "decoder.h" #if ENABLE_OPENCV #include + +#if USE_OPENCV_4 +using namespace cv; +#define CV_LOAD_IMAGE_COLOR IMREAD_COLOR +#define CV_LOAD_IMAGE_GRAYSCALE IMREAD_GRAYSCALE +#endif + class CVDecoder : public Decoder { public: //! Default constructor diff --git a/rocAL/rocAL/include/rali_api_data_loaders.h b/rocAL/rocAL/include/rali_api_data_loaders.h index 75d82c4af6..ff8d3a903c 100644 --- a/rocAL/rocAL/include/rali_api_data_loaders.h +++ b/rocAL/rocAL/include/rali_api_data_loaders.h @@ -321,6 +321,53 @@ extern "C" RaliImage RALI_API_CALL raliJpegCaffe2LMDBRecordSourceSingleShard(R RaliImageSizeEvaluationPolicy decode_size_policy = RALI_USE_MOST_FREQUENT_SIZE, unsigned max_width = 0, unsigned max_height = 0); +/// Creates JPEG image reader and decoder for MXNet records. It allocates the resources and objects required to read and decode Jpeg images stored in MXNet Records. It has internal sharding capability to load/decode in parallel is user wants. +/// If images are not Jpeg compressed they will be ignored. +/// \param context Rali context +/// \param source_path A NULL terminated char string pointing to the location on the disk +/// \param rali_color_format The color format the images will be decoded to. +/// \param internal_shard_count Defines the parallelism level by internally sharding the input dataset and load/decode using multiple decoder/loader instances. Using shard counts bigger than 1 improves the load/decode performance if compute resources (CPU cores) are available. +/// \param is_output Determines if the user wants the loaded images to be part of the output or not. +/// \param shuffle Determines if the user wants to shuffle the dataset or not. +/// \param loop Determines if the user wants to indefinitely loops through images or not. +/// \param decode_size_policy +/// \param max_width The maximum width of the decoded images, larger or smaller will be resized to closest +/// \param max_height The maximum height of the decoded images, larger or smaller will be resized to closest +/// \return Reference to the output image +extern "C" RaliImage RALI_API_CALL raliMXNetRecordSource(RaliContext context, + const char* source_path, + RaliImageColor rali_color_format, + unsigned internal_shard_count, + bool is_output, + bool shuffle = false, + bool loop = false, + RaliImageSizeEvaluationPolicy decode_size_policy = RALI_USE_MOST_FREQUENT_SIZE, + unsigned max_width = 0, unsigned max_height = 0); + +/// Creates JPEG image reader and decoder for MXNet records. It allocates the resources and objects required to read and decode Jpeg images stored on the MXNet records. It accepts external sharding information to load a singe shard. only +/// \param p_context Rali context +/// \param source_path A NULL terminated char string pointing to the location on the disk +/// \param rali_color_format The color format the images will be decoded to. +/// \param shard_id Shard id for this loader +/// \param shard_count Total shard count +/// \param is_output Determines if the user wants the loaded images to be part of the output or not. +/// \param shuffle Determines if the user wants to shuffle the dataset or not. +/// \param loop Determines if the user wants to indefinitely loops through images or not. +/// \param decode_size_policy +/// \param max_width The maximum width of the decoded images, larger or smaller will be resized to closest +/// \param max_height The maximum height of the decoded images, larger or smaller will be resized to closest +/// \return Reference to the output image +extern "C" RaliImage RALI_API_CALL raliMXNetRecordSourceSingleShard(RaliContext p_context, + const char* source_path, + RaliImageColor rali_color_format, + unsigned shard_id, + unsigned shard_count, + bool is_output, + bool shuffle = false, + bool loop = false, + RaliImageSizeEvaluationPolicy decode_size_policy = RALI_USE_MOST_FREQUENT_SIZE, + unsigned max_width = 0, unsigned max_height = 0); + /// Creates JPEG image reader and partial decoder. It allocates the resources and objects required to read and decode Jpeg images stored on the file systems. It has internal sharding capability to load/decode in parallel is user wants. /// If images are not Jpeg compressed they will be ignored and Crops t /// \param context Rali context diff --git a/rocAL/rocAL/include/rali_api_meta_data.h b/rocAL/rocAL/include/rali_api_meta_data.h index 939daaf411..1a32cb6613 100644 --- a/rocAL/rocAL/include/rali_api_meta_data.h +++ b/rocAL/rocAL/include/rali_api_meta_data.h @@ -104,6 +104,12 @@ extern "C" RaliMetaData RALI_API_CALL raliCreateCaffe2LMDBLabelReader(RaliContex extern "C" RaliMetaData RALI_API_CALL raliCreateCaffe2LMDBReaderDetection(RaliContext rali_context, const char* source_path, bool is_output); +/// +/// \param rali_context +/// \param source_path path to the MXNet recordio files for Classification +/// \return RaliMetaData object, can be used to inquire about the rali's output (processed) tensors +extern "C" RaliMetaData RALI_API_CALL raliCreateMXNetReader(RaliContext rali_context, const char* source_path, bool is_output); + /// /// \param rali_context /// \param buf user buffer provided to be filled with output image names for images in the output batch. diff --git a/rocAL/rocAL/include/reader.h b/rocAL/rocAL/include/reader.h index b3116b2851..d13efb45f8 100644 --- a/rocAL/rocAL/include/reader.h +++ b/rocAL/rocAL/include/reader.h @@ -40,7 +40,8 @@ enum class StorageType CAFFE_LMDB_RECORD = 3, CAFFE2_LMDB_RECORD = 4, COCO_FILE_SYSTEM = 5, - SEQUENCE_FILE_SYSTEM = 6 + SEQUENCE_FILE_SYSTEM = 6, + MXNET_RECORDIO = 7, }; struct ReaderConfig @@ -94,6 +95,16 @@ struct ReaderConfig std::shared_ptr _meta_data_reader = nullptr; }; +// MXNet image recordio struct - used to read the contents from the MXNet recordIO files. +struct ImageRecordIOHeader { + uint32_t flag; //flag of the header + float label; //label field that returns label of images + uint64_t image_id[2]; /* unique image index + * image_id[1] is always set to 0, + * reserved for future purposes for 128bit id + * image_id[0] is used to store image id + */ +}; class Reader { public: diff --git a/rocAL/rocAL/include/video_decoder.h b/rocAL/rocAL/include/video_decoder.h index 9965103763..d67b235d6c 100644 --- a/rocAL/rocAL/include/video_decoder.h +++ b/rocAL/rocAL/include/video_decoder.h @@ -36,13 +36,18 @@ extern "C" #include #include #include +#include +#include +#include +#include } #endif #include "parameter_factory.h" enum class VideoDecoderType { - FFMPEG_VIDEO = 0, //!< Can decode video stream + FFMPEG_SOFTWARE_DECODE = 0, + FFMPEG_HARDWARE_DECODE = 1, }; class VideoDecoderConfig @@ -51,7 +56,7 @@ class VideoDecoderConfig VideoDecoderConfig() {} explicit VideoDecoderConfig(VideoDecoderType type) : _type(type) {} virtual VideoDecoderType type() { return _type; }; - VideoDecoderType _type = VideoDecoderType::FFMPEG_VIDEO; + VideoDecoderType _type = VideoDecoderType::FFMPEG_SOFTWARE_DECODE; }; #ifdef RALI_VIDEO diff --git a/rocAL/rocAL/include/video_properties.h b/rocAL/rocAL/include/video_properties.h index c7f4ee7175..4aceed0fc2 100644 --- a/rocAL/rocAL/include/video_properties.h +++ b/rocAL/rocAL/include/video_properties.h @@ -50,8 +50,13 @@ typedef struct VideoProperties std::vector labels; } VideoProperties; +typedef struct Properties +{ + unsigned width, height, frames_count, avg_frame_rate_num, avg_frame_rate_den; +} Properties; + void substring_extraction(std::string const &str, const char delim, std::vector &out); -void open_video_context(const char *video_file_path, std::vector &props); +void open_video_context(const char *video_file_path, Properties &props); void get_video_properties_from_txt_file(VideoProperties &video_props, const char *file_path, bool file_list_frame_num); void find_video_properties(VideoProperties &video_props, const char *source_path, bool file_list_frame_num); #endif diff --git a/rocAL/rocAL/source/hardware_video_decoder.cpp b/rocAL/rocAL/source/hardware_video_decoder.cpp new file mode 100644 index 0000000000..cd3aa0c4a2 --- /dev/null +++ b/rocAL/rocAL/source/hardware_video_decoder.cpp @@ -0,0 +1,283 @@ +/* +Copyright (c) 2019 - 2022 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include +#include +#include "hardware_video_decoder.h" + +#ifdef RALI_VIDEO +HardWareVideoDecoder::HardWareVideoDecoder(){}; + +int HardWareVideoDecoder::seek_frame(AVRational avg_frame_rate, AVRational time_base, unsigned frame_number) +{ + auto seek_time = av_rescale_q((int64_t)frame_number, av_inv_q(avg_frame_rate), AV_TIME_BASE_Q); + int64_t select_frame_pts = av_rescale_q((int64_t)frame_number, av_inv_q(avg_frame_rate), time_base); + int ret = av_seek_frame(_fmt_ctx, -1, seek_time, AVSEEK_FLAG_BACKWARD); + if (ret < 0) + { + ERR("HardWareVideoDecoder::seek_frame Error in seeking frame. Unable to seek the given frame in a video"); + return ret; + } + return select_frame_pts; +} + +int HardWareVideoDecoder::hw_decoder_init(AVCodecContext *ctx, const enum AVHWDeviceType type, AVBufferRef *hw_device_ctx) +{ + int err = 0; + if ((err = av_hwdevice_ctx_create(&hw_device_ctx, type, NULL, NULL, 0)) < 0) + return err; + ctx->hw_device_ctx = av_buffer_ref(hw_device_ctx); + return err; +} + +// Seeks to the frame_number in the video file and decodes each frame in the sequence. +VideoDecoder::Status HardWareVideoDecoder::Decode(unsigned char *out_buffer, unsigned seek_frame_number, size_t sequence_length, size_t stride, int out_width, int out_height, int out_stride, AVPixelFormat out_pix_format) +{ + VideoDecoder::Status status = Status::OK; + + // Initialize the SwsContext + SwsContext *swsctx = nullptr; + if ((out_width != _codec_width) || (out_height != _codec_height) || (out_pix_format != _dec_pix_fmt)) + { + swsctx = sws_getCachedContext(nullptr, _codec_width, _codec_height, _dec_pix_fmt, + out_width, out_height, out_pix_format, SWS_BILINEAR, nullptr, nullptr, nullptr); + if (!swsctx) + { + ERR("HardWareVideoDecoder::Decode Failed to get sws_getCachedContext"); + return Status::FAILED; + } + } + int select_frame_pts = seek_frame(_video_stream->avg_frame_rate, _video_stream->time_base, seek_frame_number); + if (select_frame_pts < 0) + { + ERR("HardWareVideoDecoder::Decode Error in seeking frame. Unable to seek the given frame in a video"); + return Status::FAILED; + } + unsigned frame_count = 0; + bool end_of_stream = false; + bool sequence_filled = false; + uint8_t *dst_data[4] = {0}; + int dst_linesize[4] = {0}; + int image_size = out_height * out_stride * sizeof(unsigned char); + AVPacket pkt; + AVFrame *dec_frame = av_frame_alloc(); + AVFrame *sw_frame = av_frame_alloc(); + if (!dec_frame) + { + ERR("HardWareVideoDecoder::Decode Could not allocate dec_frame"); + return Status::NO_MEMORY; + } + if (!sw_frame) + { + ERR("HardWareVideoDecoder::Decode Could not allocate sw_frame"); + return Status::NO_MEMORY; + } + do + { + int ret; + // read packet from input file + ret = av_read_frame(_fmt_ctx, &pkt); + if (ret < 0 && ret != AVERROR_EOF) + { + ERR("HardWareVideoDecoder::Decode Failed to read the frame: ret=" + TOSTR(ret)); + status = Status::FAILED; + break; + } + if (ret == 0 && pkt.stream_index != _video_stream_idx) continue; + end_of_stream = (ret == AVERROR_EOF); + if (end_of_stream) + { + // null packet for bumping process + pkt.data = nullptr; + pkt.size = 0; + } + + // submit the packet to the decoder + ret = avcodec_send_packet(_video_dec_ctx, &pkt); + if (ret < 0) + { + ERR("HardWareVideoDecoder::Decode Error while sending packet to the decoder\n"); + status = Status::FAILED; + break; + } + + // get all the available frames from the decoder + while (ret >= 0) + { + ret = avcodec_receive_frame(_video_dec_ctx, dec_frame); + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) break; + if ((dec_frame->pts < select_frame_pts) || (ret < 0)) continue; + if (frame_count % stride == 0) + { + //retrieve data from GPU to CPU + if ((av_hwframe_transfer_data(sw_frame, dec_frame, 0)) < 0) { + ERR("HardWareVideoDecoder::Decode avcodec_receive_frame() failed"); + return Status::FAILED; + } + + dst_data[0] = out_buffer; + dst_linesize[0] = out_stride; + if (swsctx) + sws_scale(swsctx, sw_frame->data, sw_frame->linesize, 0, sw_frame->height, dst_data, dst_linesize); + else + { + // copy from frame to out_buffer + memcpy(out_buffer, sw_frame->data[0], sw_frame->linesize[0] * out_height); + } + out_buffer = out_buffer + image_size; + } + ++frame_count; + av_frame_unref(sw_frame); + av_frame_unref(dec_frame); + if (frame_count == sequence_length * stride) + { + sequence_filled = true; + break; + } + } + av_packet_unref(&pkt); + if (sequence_filled) break; + } while (!end_of_stream); + avcodec_flush_buffers(_video_dec_ctx); + av_frame_free(&dec_frame); + av_frame_free(&sw_frame); + sws_freeContext(swsctx); + return status; +} + +// Initialize will open a new decoder and initialize the context +VideoDecoder::Status HardWareVideoDecoder::Initialize(const char *src_filename) +{ + VideoDecoder::Status status = Status::OK; + int ret; + AVDictionary *opts = NULL; + + // open input file, and initialize the context required for decoding + _fmt_ctx = avformat_alloc_context(); + _src_filename = src_filename; + + // find if hardware decode is available + AVHWDeviceType hw_type = AV_HWDEVICE_TYPE_NONE; + hw_type = av_hwdevice_find_type_by_name("vaapi"); + if (hw_type == AV_HWDEVICE_TYPE_NONE) { + ERR("HardWareVideoDecoder::Initialize ERROR: vaapi is not supported for this device\n"); + return Status::FAILED; + } + else + INFO("HardWareVideoDecoder::Initialize : Found vaapi device for the device\n"); + + if (avformat_open_input(&_fmt_ctx, src_filename, NULL, NULL) < 0) + { + ERR("HardWareVideoDecoder::Initialize Couldn't Open video file " + STR(src_filename)); + return Status::FAILED; + } + if (avformat_find_stream_info(_fmt_ctx, NULL) < 0) + { + ERR("HardWareVideoDecoder::Initialize av_find_stream_info error"); + return Status::FAILED; + } + ret = av_find_best_stream(_fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &_decoder, 0); + if (ret < 0) + { + ERR("HardWareVideoDecoder::Initialize Could not find %s stream in input file " + + STR(av_get_media_type_string(AVMEDIA_TYPE_VIDEO)) + " " + STR(src_filename)); + return Status::FAILED; + } + // for hardware accelerated decoding, find config + for (int i = 0; ; i++) { + const AVCodecHWConfig *config = avcodec_get_hw_config(_decoder, i); + if (!config) { + ERR("HardWareVideoDecoder::Initialize ERROR: decoder " + STR(_decoder->name) + " doesn't support device_type " + STR(av_hwdevice_get_type_name(hw_type))); + return Status::FAILED; + } + if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX && + config->device_type == hw_type) { + break; + } + } + + _video_stream_idx = ret; + _video_stream = _fmt_ctx->streams[_video_stream_idx]; + + if (!_video_stream) + { + ERR("HardWareVideoDecoder::Initialize Could not find video stream in the input, aborting"); + return Status::FAILED; + } + + // find decoder for the stream + _decoder = avcodec_find_decoder(_video_stream->codecpar->codec_id); + if (!_decoder) + { + ERR("HardWareVideoDecoder::Initialize Failed to find " + + STR(av_get_media_type_string(AVMEDIA_TYPE_VIDEO)) + " codec"); + return Status::FAILED; + } + + // Allocate a codec context for the decoder + _video_dec_ctx = avcodec_alloc_context3(_decoder); + if (!_video_dec_ctx) + { + ERR("HardWareVideoDecoder::Initialize Failed to allocate the " + + STR(av_get_media_type_string(AVMEDIA_TYPE_VIDEO)) + " codec context"); + return Status::NO_MEMORY; + } + + // Copy codec parameters from input stream to output codec context + if ((ret = avcodec_parameters_to_context(_video_dec_ctx, _video_stream->codecpar)) < 0) + { + ERR("HardWareVideoDecoder::Initialize Failed to copy " + + STR(av_get_media_type_string(AVMEDIA_TYPE_VIDEO)) + " codec parameters to decoder context"); + return Status::FAILED; + } + + if (hw_decoder_init(_video_dec_ctx, hw_type, hw_device_ctx) < 0) { + ERR("HardWareVideoDecoder::Initialize ERROR: Failed to create specified HW device"); + return Status::FAILED; + } + _dec_pix_fmt = AV_PIX_FMT_NV12; // nv12 for vaapi + + // Init the decoders + if ((ret = avcodec_open2(_video_dec_ctx, _decoder, &opts)) < 0) + { + ERR("HardWareVideoDecoder::Initialize Failed to open " + + STR(av_get_media_type_string(AVMEDIA_TYPE_VIDEO)) + " codec"); + return Status::FAILED; + } + _codec_width = _video_stream->codecpar->width; + _codec_height = _video_stream->codecpar->height; + return status; +} + +void HardWareVideoDecoder::release() +{ + if (_video_dec_ctx) + avcodec_free_context(&_video_dec_ctx); + if (_fmt_ctx) + avformat_close_input(&_fmt_ctx); +} + +HardWareVideoDecoder::~HardWareVideoDecoder() +{ + release(); +} +#endif diff --git a/rocAL/rocAL/source/master_graph.cpp b/rocAL/rocAL/source/master_graph.cpp index f759290a57..61fb357106 100644 --- a/rocAL/rocAL/source/master_graph.cpp +++ b/rocAL/rocAL/source/master_graph.cpp @@ -328,8 +328,12 @@ void MasterGraph::release() _image_map.clear(); _ring_buffer.release_gpu_res(); //shut_down loader:: required for releasing any allocated resourses - _loader_module->shut_down(); - +#ifdef RALI_VIDEO + if(_is_video_loader) + _video_loader_module->shut_down(); + else +#endif + _loader_module->shut_down(); // release all openvx resources. vx_status status; for(auto& image: _internal_images) @@ -1201,6 +1205,25 @@ MetaDataBatch * MasterGraph::create_video_label_reader(const char *source_path, return _meta_data_reader->get_output(); } +MetaDataBatch * MasterGraph::create_mxnet_label_reader(const char *source_path, bool is_output) +{ + if( _meta_data_reader) + THROW("A metadata reader has already been created") + MetaDataConfig config(MetaDataType::Label, MetaDataReaderType::MXNET_META_DATA_READER, source_path); + _meta_data_graph = create_meta_data_graph(config); + _meta_data_reader = create_meta_data_reader(config); + _meta_data_reader->init(config); + _meta_data_reader->read_all(source_path); + if(is_output) + { + if (_augmented_meta_data) + THROW("Metadata output already defined, there can only be a single output for metadata augmentation") + else + _augmented_meta_data = _meta_data_reader->get_output(); + } + return _meta_data_reader->get_output(); +} + void MasterGraph::create_randombboxcrop_reader(RandomBBoxCrop_MetaDataReaderType reader_type, RandomBBoxCrop_MetaDataType label_type, bool all_boxes_overlap, bool no_crop, FloatParam* aspect_ratio, bool has_shape, int crop_width, int crop_height, int num_attempts, FloatParam* scaling, int total_num_attempts, int64_t seed) { if( _randombboxcrop_meta_data_reader) diff --git a/rocAL/rocAL/source/meta_data_reader_factory.cpp b/rocAL/rocAL/source/meta_data_reader_factory.cpp index 26ded2555e..04944a5437 100644 --- a/rocAL/rocAL/source/meta_data_reader_factory.cpp +++ b/rocAL/rocAL/source/meta_data_reader_factory.cpp @@ -36,6 +36,7 @@ THE SOFTWARE. #include "caffe2_meta_data_reader_detection.h" #include "tf_meta_data_reader_detection.h" #include "video_label_reader.h" +#include "mxnet_meta_data_reader.h" std::shared_ptr create_meta_data_reader(const MetaDataConfig& config) { switch(config.reader_type()) { @@ -149,6 +150,15 @@ std::shared_ptr create_meta_data_reader(const MetaDataConfig& co return ret; } break; + case MetaDataReaderType::MXNET_META_DATA_READER: + { + if(config.type() != MetaDataType::Label) + THROW("MXNetMetaDataReader can only be used to load labels") + auto ret = std::make_shared(); + ret->init(config); + return ret; + } + break; default: THROW("MetaDataReader type is unsupported : "+ TOSTR(config.reader_type())); } diff --git a/rocAL/rocAL/source/mxnet_meta_data_reader.cpp b/rocAL/rocAL/source/mxnet_meta_data_reader.cpp new file mode 100644 index 0000000000..4c53f171f5 --- /dev/null +++ b/rocAL/rocAL/source/mxnet_meta_data_reader.cpp @@ -0,0 +1,187 @@ +/* +Copyright (c) 2019 - 2022 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include +#include "mxnet_meta_data_reader.h" +#include + +namespace filesys = boost::filesystem; +using namespace std; + +void MXNetMetaDataReader::init(const MetaDataConfig &cfg) +{ + _path = cfg.path(); + _output = new LabelBatch(); + _src_dir = nullptr; + _entity = nullptr; +} + +bool MXNetMetaDataReader::exists(const std::string& _image_name) +{ + return _map_content.find(_image_name) != _map_content.end(); +} + +void MXNetMetaDataReader::add(std::string image_name, int label) +{ + pMetaData info = std::make_shared