remove fork example (#232)

[ROCm/rocdecode commit: 072d6fe0e2]
Bu işleme şunda yer alıyor:
Lakshmi Kumar
2024-02-09 12:46:48 -08:00
işlemeyi yapan: GitHub
ebeveyn cd37b816b6
işleme 6443588c8d
8 değiştirilmiş dosya ile 0 ekleme ve 366 silme
-1
Dosyayı Görüntüle
@@ -138,7 +138,6 @@ if(HIP_FOUND AND Libva_FOUND AND Libdrm_FOUND)
install(DIRECTORY cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} COMPONENT dev)
install(DIRECTORY utils/rocvideodecode DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/utils COMPONENT dev)
install(DIRECTORY samples/videoDecode DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/samples COMPONENT dev)
install(DIRECTORY samples/videoDecodeFork DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/samples COMPONENT dev)
install(DIRECTORY samples/videoDecodeMem DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/samples COMPONENT dev)
install(DIRECTORY samples/videoDecodePerf DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/samples COMPONENT dev)
install(DIRECTORY samples/videoDecodeRGB DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}/samples COMPONENT dev)
-1
Dosyayı Görüntüle
@@ -41,7 +41,6 @@ left_nav_title = f"rocDecode {version_number} Documentation"
shutil.copy2('../README.md','./quickStart.md')
shutil.copy2('../samples/README.md','./samples.md')
shutil.copy2('../samples/videoDecode/README.md','./videoDecode.md')
shutil.copy2('../samples/videoDecodeFork/README.md','./videoDecodeFork.md')
shutil.copy2('../samples/videoDecodeMem/README.md','./videoDecodeMem.md')
shutil.copy2('../samples/videoDecodeMultiFiles/README.md','./videoDecodeMultiFiles.md')
shutil.copy2('../samples/videoDecodePerf/README.md','./videoDecodePerf.md')
-1
Dosyayı Görüntüle
@@ -25,7 +25,6 @@ subtrees:
subtrees:
- entries:
- file: videoDecode
- file: videoDecodeFork
- file: videoDecodeMem
- file: videoDecodeMultiFiles
- file: videoDecodePerf
-6
Dosyayı Görüntüle
@@ -6,12 +6,6 @@ rocDecode samples
The video decode sample illustrates decoding a single packetized video stream using FFMPEG demuxer, video parser, and rocDecoder to get the individual decoded frames in YUV format. This sample can be configured with a device ID and optionally able to dump the output to a file. This sample uses the high-level RocVideoDecoder class which connects both the video parser and Rocdecoder. This process repeats in a loop until all frames have been decoded.
## [Video decode fork](videoDecodeFork)
The video decode fork sample creates multiple processes that demux and decode the same video in parallel. The demuxer uses FFMPEG to get the individual frames which are then sent to the decoder APIs. The sample uses shared memory to keep count of the number of frames decoded in the different processes. Each child process needs to exit successfully for the sample to complete successfully.
This sample shows scaling in performance for `N` VCN engines as per GPU architecture.
## [Video decode memory](videoDecodeMem)
The video decode memory sample illustrates a way to pass the data chunk-by-chunk sequentially to the FFMPEG demuxer which is then decoded on AMD hardware using rocDecode library.
-78
Dosyayı Görüntüle
@@ -1,78 +0,0 @@
################################################################################
# Copyright (c) 2023 - 2024 Advanced Micro Devices, Inc.
#
# 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.
#
################################################################################
cmake_minimum_required (VERSION 3.5)
project(videodecodefork)
set(CMAKE_CXX_STANDARD 17)
# ROCM Path
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path")
elseif(ROCM_PATH)
message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake)
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/hip ${ROCM_PATH})
set(CMAKE_CXX_COMPILER ${ROCM_PATH}/llvm/bin/clang++)
find_package(HIP QUIET)
find_package(FFmpeg QUIET)
# find rocDecode
find_library(ROCDECODE_LIBRARY NAMES rocdecode HINTS {ROCM_PATH}/lib)
find_path(ROCDECODE_INCLUDE_DIR NAMES rocdecode.h PATHS /opt/rocm/include/rocdecode {ROCM_PATH}/include/rocdecode)
if(ROCDECODE_LIBRARY AND ROCDECODE_INCLUDE_DIR)
set(ROCDECODE_FOUND TRUE)
message("-- ${White}Using rocDecode -- \n\tLibraries:${ROCDECODE_LIBRARY} \n\tIncludes:${ROCDECODE_INCLUDE_DIR}${ColourReset}")
endif()
if(HIP_FOUND AND FFMPEG_FOUND AND ROCDECODE_FOUND)
# HIP
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host)
# FFMPEG
include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR}
${SWSCALE_INCLUDE_DIR} ${AVFORMAT_INCLUDE_DIR})
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES})
# rocDecode
include_directories (${ROCDECODE_INCLUDE_DIR})
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${ROCDECODE_LIBRARY})
list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecodefork.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp)
add_executable(${PROJECT_NAME} ${SOURCES})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17")
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST})
else()
message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!")
if (NOT HIP_FOUND)
message(FATAL_ERROR "-- ERROR!: HIP Not Found! - please install ROCm and HIP!")
endif()
if (NOT FFMPEG_FOUND)
message(FATAL_ERROR "-- ERROR!: FFMPEG Not Found! - please install FFMPEG!")
endif()
if (NOT ROCDECODE_FOUND)
message(FATAL_ERROR "-- ERROR!: rocDecode Not Found! - please install rocDecode!")
endif()
endif()
-37
Dosyayı Görüntüle
@@ -1,37 +0,0 @@
# Video decode fork sample
The video decode fork sample creates multiple processes that demux and decode the same video in parallel. The demuxer uses FFMPEG to get the individual frames which are then sent to the decoder APIs. The sample uses shared memory to keep count of the number of frames decoded in the different processes. Each child process needs to exit successfully for the sample to complete successfully.
This sample shows scaling in performance for `N` VCN engines as per GPU architecture.
## Prerequisites:
* Install [rocDecode](../../README.md#build-and-install-instructions)
* [FFMPEG](https://ffmpeg.org/about.html)
* On `Ubuntu`
```shell
sudo apt install ffmpeg libavcodec-dev libavformat-dev libavutil-dev
```
* On `RHEL`/`SLES` - install ffmpeg development packages manually or use [rocDecode-setup.py](../../rocDecode-setup.py) script
## Build
```shell
mkdir video_decode_fork_sample && cd video_decode_fork_sample
cmake ../
make -j
```
## Run
```shell
./videodecodefork -i <input video file [required]>
-f <Number of forks ( >= 1) [optional; default:4]>
-d <Device ID (>= 0) [optional - default:0]>
-z <force_zero_latency - Decoded frames will be flushed out for display immediately [optional]>
-m <output_surface_memory_type - decoded surface memory [optional - default: 0][0 : OUT_SURFACE_MEM_DEV_INTERNAL/ 1 : OUT_SURFACE_MEM_DEV_COPIED/ 2 : OUT_SURFACE_MEM_HOST_COPIED]>
```
-229
Dosyayı Görüntüle
@@ -1,229 +0,0 @@
/*
Copyright (c) 2023 - 2024 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 <iostream>
#include <iomanip>
#include <unistd.h>
#include <vector>
#include <string>
#include <chrono>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <libgen.h>
#if __cplusplus >= 201703L && __has_include(<filesystem>)
#include <filesystem>
#else
#include <experimental/filesystem>
#endif
#include "video_demuxer.h"
#include "roc_video_dec.h"
static int *n_total;
void DecProc(RocVideoDecoder *p_dec, VideoDemuxer *demuxer, int *pn_frame) {
int n_video_bytes = 0, n_frame_returned = 0, n_frame = 0;
uint8_t *p_video = nullptr;
int64_t pts = 0;
do {
demuxer->Demux(&p_video, &n_video_bytes, &pts);
n_frame_returned = p_dec->DecodeFrame(p_video, n_video_bytes, 0, pts);
n_frame += n_frame_returned;
} while (n_video_bytes);
*pn_frame = n_frame;
}
void ShowHelpAndExit(const char *option = NULL) {
std::cout << "Options:" << std::endl
<< "-i Input File Path - required" << std::endl
<< "-f Number of forks (>= 1) - optional; default: 4" << std::endl
<< "-d Device ID (>= 0) - optional; default: 0" << std::endl
<< "-z force_zero_latency (force_zero_latency, Decoded frames will be flushed out for display immediately); optional;" << std::endl;
exit(0);
}
int main(int argc, char **argv) {
std::string input_file_path;
int n_fork = 4;
int device_id = 0;
Rect *p_crop_rect = nullptr;
OutputSurfaceMemoryType mem_type = OUT_SURFACE_MEM_NOT_MAPPED; // set to unmapped: output frames are not mapped for performance
bool b_force_zero_latency = false;
// Parse command-line arguments
if(argc <= 1) {
ShowHelpAndExit();
}
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-h")) {
ShowHelpAndExit();
}
if (!strcmp(argv[i], "-i")) {
if (++i == argc) {
ShowHelpAndExit("-i");
}
input_file_path = argv[i];
continue;
}
if (!strcmp(argv[i], "-f")) {
if (++i == argc) {
ShowHelpAndExit("-f");
}
n_fork = atoi(argv[i]);
if (n_fork <= 0) {
ShowHelpAndExit(argv[i]);
}
continue;
}
if (!strcmp(argv[i], "-d")) {
if (++i == argc) {
ShowHelpAndExit("-d");
}
device_id = atoi(argv[i]);
if (device_id < 0) {
ShowHelpAndExit(argv[i]);
}
continue;
}
if (!strcmp(argv[i], "-z")) {
if (i == argc) {
ShowHelpAndExit("-z");
}
b_force_zero_latency = true;
continue;
}
ShowHelpAndExit(argv[i]);
}
try {
std::vector<std::unique_ptr<VideoDemuxer>> v_demuxer;
std::vector<std::unique_ptr<RocVideoDecoder>> v_viddec;
std::vector<int> v_device_id(n_fork);
// TODO: Change this block to use VCN query API
int num_devices = 0, sd = 0;
hipError_t hip_status = hipSuccess;
hipDeviceProp_t hip_dev_prop;
std::string gcn_arch_name;
hip_status = hipGetDeviceCount(&num_devices);
if (hip_status != hipSuccess) {
std::cout << "ERROR: hipGetDeviceCount failed! (" << hip_status << ")" << std::endl;
return 1;
}
if (num_devices < 1) {
ERR("ERROR: didn't find any GPU!");
return -1;
}
hip_status = hipGetDeviceProperties(&hip_dev_prop, device_id);
if (hip_status != hipSuccess) {
ERR("ERROR: hipGetDeviceProperties for device (" +TOSTR(device_id) + " ) failed! (" + hipGetErrorName(hip_status) + ")" );
return -1;
}
gcn_arch_name = hip_dev_prop.gcnArchName;
std::size_t pos = gcn_arch_name.find_first_of(":");
std::string gcn_arch_name_base = (pos != std::string::npos) ? gcn_arch_name.substr(0, pos) : gcn_arch_name;
// gfx90a has two GCDs as two separate devices
if (!gcn_arch_name_base.compare("gfx90a") && num_devices > 1) {
sd = 1;
}
int hip_vis_dev_count = 0;
GetEnvVar("HIP_VISIBLE_DEVICES", hip_vis_dev_count);
for (int i = 0; i < n_fork; i++) {
std::unique_ptr<VideoDemuxer> demuxer(new VideoDemuxer(input_file_path.c_str()));
rocDecVideoCodec rocdec_codec_id = AVCodec2RocDecVideoCodec(demuxer->GetCodecID());
if (!hip_vis_dev_count) {
if (device_id % 2 == 0)
v_device_id[i] = (i % 2 == 0) ? device_id : device_id + sd;
else
v_device_id[i] = (i % 2 == 0) ? device_id - sd : device_id;
} else {
v_device_id[i] = i % hip_vis_dev_count;
}
std::unique_ptr<RocVideoDecoder> dec(new RocVideoDecoder(v_device_id[i], mem_type, rocdec_codec_id, b_force_zero_latency, p_crop_rect));
v_demuxer.push_back(std::move(demuxer));
v_viddec.push_back(std::move(dec));
}
std::vector<int> v_frame;
v_frame.resize(n_fork, 0);
std::string device_name;
int pci_bus_id, pci_domain_id, pci_device_id;
for (int i = 0; i < n_fork; i++) {
v_viddec[i]->GetDeviceinfo(device_name, gcn_arch_name, pci_bus_id, pci_domain_id, pci_device_id);
std::cout << "info: stream " << i << " using GPU device " << v_device_id[i] << " - " << device_name << "[" << gcn_arch_name << "] on PCI bus " <<
std::setfill('0') << std::setw(2) << std::right << std::hex << pci_bus_id << ":" << std::setfill('0') << std::setw(2) <<
std::right << std::hex << pci_domain_id << "." << pci_device_id << std::dec << std::endl;
std::cout << "info: decoding started for thread " << i << " ,please wait!" << std::endl;
}
int pid_status;
pid_t pids[n_fork];
n_total = (int *) mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
*n_total = 0;
auto start_time = std::chrono::high_resolution_clock::now();
for (int i = 0; i < n_fork; i++) {
pids[i] = fork();
if (pids[i] < 0) {
std::cout << "ERROR: failed to create fork" << std::endl;
abort();
} else {
DecProc(v_viddec[i].get(), v_demuxer[i].get(), &v_frame[i]);
*n_total += v_frame[i];
}
}
for(int i = 0; i < n_fork; i++) {
waitpid(pids[i], &pid_status, 0);
if (!WIFEXITED(pid_status)) {
std::cout << "child with " << pids[i] << " exited with status " << WEXITSTATUS(pid_status) << std::endl;
}
}
auto end_time = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration<double, std::milli>(end_time - start_time).count();
// Calculate average decoding time
double total_decoding_time = 0.0;
total_decoding_time = duration;
double average_decoding_time = total_decoding_time / *n_total;
std::cout << "info: Total Frames Decoded: " << *n_total << std::endl;
std::cout << "info: avg decoding time per frame (ms): " << average_decoding_time << std::endl;
std::cout << "info: avg FPS: " << 1000 / average_decoding_time << std::endl;
munmap(n_total, sizeof(int));
} catch (const std::exception &ex) {
std::cout << ex.what() << std::endl;
exit(1);
}
return 0;
}
-13
Dosyayı Görüntüle
@@ -63,19 +63,6 @@ add_test(
-i ${ROCM_PATH}/share/rocdecode/video/AMD_driving_virtual_20-H265.mp4
)
# videoDecodeFork - TBD - https://github.com/ROCm/rocDecode/issues/221 - Needs Fixed to enable
#add_test(
#NAME
#video_decodeFork-H265
#COMMAND
#"${CMAKE_CTEST_COMMAND}"
#--build-and-test "${ROCM_PATH}/share/rocdecode/samples/videoDecodeFork"
#"${CMAKE_CURRENT_BINARY_DIR}/videoDecodeFork"
#--build-generator "${CMAKE_GENERATOR}"
#--test-command "videodecodefork"
#-i ${ROCM_PATH}/share/rocdecode/video/AMD_driving_virtual_20-H265.mp4
#)
# videoDecodeMem
add_test(
NAME