Samples - Updates (#206)

* Samples - Updates

* Readme - samples

[ROCm/rocdecode commit: 6658070d1c]
Este commit está contenido en:
Kiriti Gowda
2024-01-26 10:38:20 -08:00
cometido por GitHub
padre e5ad62fa09
commit 97a6f07780
Se han modificado 4 ficheros con 37 adiciones y 0 borrados
+37
Ver fichero
@@ -0,0 +1,37 @@
# Samples
rocDecode samples
## [Video decode](videoDecode)
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 cab ne 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 which 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 are then decoded on AMD hardware using rocDecode library.
The sample provides a user class `FileStreamProvider` derived from the existing `VideoDemuxer::StreamProvider` to read a video file and fill the buffer owned by the demuxer. It then takes frames from this buffer for further parsing and decoding.
## [Video decode multi files](videoDecodeMultiFiles)
The video decode multiple files sample illustrates the use of providing a list of files as input to showcase the reconfigure option in rocDecode library. The input video files have to be of the same codec type to use the reconfigure option but can have different resolution or resize parameters.
The reconfigure option can be disabled by the user if needed. The input file is parsed line by line and data is stored in a queue. The individual video files are demuxed and decoded one after the other in a loop. Outpuot for each individual input file can also be stored if needed.
## [Video decode performance](videoDecodePerf)
This sample illustrates the FFMPEG demuxer to get the individual frames which are then decoded on AMD hardware using rocDecode library.
This sample uses multiple threads to decode the same input video parallely.
## [Video decode RGB](videoDecodeRGB)
This sample illustrates the FFMPEG demuxer to get the individual frames which are then decoded using rocDecode API and optionally color-converted using custom HIP kernels on AMD hardware. This sample converts decoded YUV output to one of the RGB or BGR formats(24bit, 32bit, 464bit) in a separate thread allowing to run both VCN hardware and compute engine in parallel.
This sample uses HIP kernels to showcase the color conversion. Whenever a frame is ready after decoding, the `ColorSpaceConversionThread` is notified and can be used for post-processing.
@@ -1,64 +0,0 @@
# rocDecode Test Scripts
## Pre-requisites to run python script
* 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
* Python3 and pip packages - `pandas`, & ` tabulate`
```shell
python3 -m pip install pandas tabulate
```
## Scripts
**Usage:**
* **run_rocDecodeSamples.py**
```shell
usage: run_rocDecodeSamples.py [--rocDecode_directory ROCDECODE_DIRECTORY]
[--gpu_device_id GPU_DEVICE_ID]
[--files_directory FILES_DIRECTORY]
[--sample_mode SAMPLE_MODE]
[--num_threads NUM_THREADS]
optional arguments:
-h, --help show this help message and exit
--rocDecode_directory ROCDECODE_DIRECTORY
The rocDecode Directory - required
--gpu_device_id GPU_DEVICE_ID
The GPU device ID that will be used to run the test on it - optional (default:0 [range:0 - N-1] N = total number of available GPUs on a machine)
--files_directory FILES_DIRECTORY
The path to a dirctory containing one or more supported files for decoding (e.g., mp4, mov, etc.) - required
--sample_mode SAMPLE_MODE
The sample to run - optional (default:0 [range:0-1] 0: videoDecode, 1: videoDecodePerf)
--num_threads NUM_THREADS
The number of threads is only for the videoDecodePerf sample (sample_mode = 1) - optional (default:4)
```
* **run_rocDecode_Conformance.py**
```shell
usage: run_rocDecode_Conformance.py [--rocDecode_directory ROCDECODE_DIRECTORY]
[--gpu_device_id GPU_DEVICE_ID]
[--files_directory FILES_DIRECTORY]
optional arguments:
-h, --help show this help message and exit
--rocDecode_directory ROCDECODE_DIRECTORY
The rocDecode Directory - required
--gpu_device_id GPU_DEVICE_ID
The GPU device ID that will be used to run the test on it - optional (default:0 [range:0 - N-1] N = total number of available GPUs on a machine)
--files_directory FILES_DIRECTORY
The path to a dirctory containing one or more supported files for decoding (e.g., mp4, mov, etc.) and their corresponding reference MD5 digests - required
```
@@ -1,239 +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.
from datetime import datetime
from subprocess import Popen, PIPE
import argparse
import os
import shutil
import sys
import platform
import glob
import pandas as pd
from pathlib import Path
__license__ = "MIT"
__version__ = "1.0"
__status__ = "Shipping"
def shell(cmd):
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
output = p.communicate()[0][0:-1]
return output
def write_formatted(output, f):
f.write("````\n")
f.write("%s\n\n" % output)
f.write("````\n")
def strip_libtree_addresses(lib_tree):
return lib_tree
def iter_files(path):
for file_or_directory in path.rglob("*"):
if file_or_directory.is_file():
yield file_or_directory
# Import arguments
parser = argparse.ArgumentParser()
parser.add_argument('--rocDecode_directory', type=str, default='',
help='The rocDecode Directory - required')
parser.add_argument('--gpu_device_id', type=int, default=0,
help='The GPU device ID that will be used to run the test on it - optional (default:0 [range:0 - N-1] N = total number of available GPUs on a machine)')
parser.add_argument('--files_directory', type=str, default='',
help='The path to a dirctory containing one or more supported files for decoding (e.g., mp4, mov, etc.) - required')
parser.add_argument('--sample_mode', type=int, default=0,
help='The sample to run - optional (default:0 [range:0-1] 0: videoDecode, 1: videoDecodePerf)')
parser.add_argument('--num_threads', type=int, default=4,
help='The number of threads is only for the videoDecodePerf sample (sample_mode = 1) - optional (default:4)')
args = parser.parse_args()
rocDecodeDirectory = args.rocDecode_directory
gpuDeviceID = args.gpu_device_id
filesDir = args.files_directory
filesDirPath = Path(filesDir)
sampleMode = args.sample_mode
numThreads = args.num_threads
print("\nrunrocDecodeTests V"+__version__+"\n")
# rocDecode Application
scriptPath = os.path.dirname(os.path.realpath(__file__))
if sampleMode == 0:
rocDecode_exe = rocDecodeDirectory+'/samples/videoDecode/build/videodecode'
resultsPath = scriptPath+'/rocDecode_videoDecode_results'
elif sampleMode == 1:
rocDecode_exe = rocDecodeDirectory+'/samples/videoDecodePerf/build/videodecodeperf'
resultsPath = scriptPath+'/rocDecode_videoDecodePerf_results'
run_rocDecode_app = os.path.abspath(rocDecode_exe)
os.system('(mkdir -p ' + resultsPath + ')')
if(os.path.isfile(run_rocDecode_app)):
print("STATUS: rocDecode path - "+run_rocDecode_app+"\n")
else:
print("\nERROR: rocDecode Executable Not Found\n")
exit()
if os.path.exists(filesDir) and not os.path.isfile(filesDir):
# Checking if the directory is empty or not
if not os.listdir(filesDir):
print("\nERROR: Empty directory - no videos to decode")
exit()
else:
print("\nERROR: The input directory path is either for a file or directory does not exist!")
exit()
# Get cwd
cwd = os.getcwd()
if os.path.exists(resultsPath+'/rocDecode_output.log'):
os.remove(resultsPath+'/rocDecode_output.log')
if os.path.exists(resultsPath+'/rocDecode_test_results.csv'):
os.remove(resultsPath+'/rocDecode_test_results.csv')
if sampleMode == 0:
for current_file in iter_files(filesDirPath):
os.system(run_rocDecode_app+' -i '+str(current_file)+' -d '+str(gpuDeviceID)+' | tee -a '+resultsPath+'/rocDecode_output.log')
print("\n\n")
orig_stdout = sys.stdout
sys.stdout = open(resultsPath+'/rocDecode_test_results.csv', 'a')
echo_1 = 'File Name, Codec, Bit Depth, Total Frames, Average decoding time per frame (ms), Avg FPS'
print(echo_1)
sys.stdout = orig_stdout
runAwk_csv = r'''awk '/info: Input file: / {filename=$4; next}
/info: Using GPU device 0 - AMD Radeon Graphics[gfx1030] on PCI bus 0d:00.0/{next}
/info: decoding started, please wait!/{next}
/Input Video Information/{next}
/\tCodec : / {codec=$3; next}
/\tSequence : /{next}
/\tCoded size : /{next}
/\tDisplay area : /{next}
/\tChroma : /{next}
/\tBit depth : / {bitDepth=$4; next}
/Video Decoding Params:/{next}
/\tNum Surfaces : /{next}
/\tCrop : /{next}
/\tResize : /{next}
/^$/{next}
/info: Total frame decoded: / {totalFrames=$5; next}
/info: avg decoding time per frame: /{timePerFrame=$7; next}
/info: avg FPS: / { printf("%s, %s, %d, %d, %f, %f\n", filename, codec, bitDepth, totalFrames, timePerFrame, $4) }' rocDecode_videoDecode_results/rocDecode_output.log >> rocDecode_videoDecode_results/rocDecode_test_results.csv'''
os.system(runAwk_csv)
elif sampleMode == 1:
for current_file in iter_files(filesDirPath):
os.system(run_rocDecode_app+' -i '+str(current_file)+' -t '+str(numThreads)+' | tee -a '+resultsPath+'/rocDecode_output.log')
print("\n\n")
orig_stdout = sys.stdout
sys.stdout = open(resultsPath+'/rocDecode_test_results.csv', 'a')
echo_1 = 'File Name, Num Threads, Codec, Bit Depth, Total Frames, Average decoding time per frame (ms), Avg FPS'
print(echo_1)
sys.stdout = orig_stdout
runAwk_csv = r'''awk '/info: Input file: / {filename=$4; next}
/info: Number of threads: / {numThreads=$5; next}
/info: Using GPU device 0 - AMD Radeon Graphics[gfx1030] on PCI bus 0d:00.0/{next}
/info: decoding started, please wait!/{next}
/Input Video Information/{next}
/\tCodec : / {codec=$3; next}
/\tSequence : /{next}
/\tCoded size : /{next}
/\tDisplay area : /{next}
/\tChroma : /{next}
/\tBit depth : / {bitDepth=$4; next}
/Video Decoding Params:/{next}
/\tNum Surfaces : /{next}
/\tCrop : /{next}
/\tResize : /{next}
/^$/{next}
/info: Total frame decoded: / {totalFrames=$5; next}
/info: avg decoding time per frame: /{timePerFrame=$7; next}
/info: avg FPS: / { printf("%s, %d, %s, %d, %d, %f, %f\n", filename, numThreads, codec, bitDepth, totalFrames, timePerFrame, $4) }' rocDecode_videoDecodePerf_results/rocDecode_output.log >> rocDecode_videoDecodePerf_results/rocDecode_test_results.csv'''
sys.stdout = orig_stdout
os.system(runAwk_csv)
# get data
platform_name = platform.platform()
platform_name_fq = shell('hostname --all-fqdns')
platform_ip = shell('hostname -I')[0:-1] # extra trailing space
file_dtstr = datetime.now().strftime("%Y%m%d")
reportFilename = 'rocDecode_report_%s_%s.md' % (platform_name, file_dtstr)
report_dtstr = datetime.now().strftime("%Y-%m-%d %H:%M:%S %Z")
sys_info = shell('inxi -c0 -S')
cpu_info = shell('inxi -c0 -C')
gpu_info = shell('inxi -c0 -G')
memory_info = shell('inxi -c 0 -m')
board_info = shell('inxi -c0 -M')
lib_tree = shell('ldd '+run_rocDecode_app)
lib_tree = strip_libtree_addresses(lib_tree)
# Load the data
df = pd.read_csv(resultsPath+'/rocDecode_test_results.csv')
# Generate the markdown table
print(df.to_markdown(index=False))
# Write Report
with open(reportFilename, 'w') as f:
f.write("rocDecode app report\n")
f.write("================================\n")
f.write("\n")
f.write("Generated: %s\n" % report_dtstr)
f.write("\n")
f.write("Platform: %s (%s)\n" % (platform_name_fq, platform_ip))
f.write("--------\n")
f.write("\n")
write_formatted(sys_info, f)
write_formatted(cpu_info, f)
write_formatted(gpu_info, f)
write_formatted(board_info, f)
write_formatted(memory_info, f)
f.write("\n\nBenchmark Report\n")
f.write("--------\n")
f.write("\n")
f.write("\n")
f.write(df.to_markdown(index=False))
f.write("\n")
f.write("\n")
f.write("Dynamic Libraries Report\n")
f.write("-----------------\n")
f.write("\n")
write_formatted(lib_tree, f)
f.write("\n")
f.write(
"\n\n---\n**Copyright (c) 2023 - 2024 AMD ROCm rocDecode app -- run_rocDecode_tests.py V-"+__version__+"**\n")
f.write("\n")
# report file
reportFileDir = os.path.abspath(reportFilename)
print("\nSTATUS: Output Report File - "+reportFileDir)
print("\nrun_rocDecode_tests.py completed - V"+__version__+"\n")
@@ -1,138 +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.
from datetime import datetime
from subprocess import Popen, PIPE
import argparse
import os
import shutil
import sys
import platform
import glob
import pandas as pd
from pathlib import Path
__license__ = "MIT"
__version__ = "1.0"
__status__ = "Shipping"
# Import arguments
parser = argparse.ArgumentParser()
parser.add_argument('--rocDecode_directory', type=str, default='',
help='The rocDecode Directory - required')
parser.add_argument('--gpu_device_id', type=int, default=0,
help='The GPU device ID that will be used to run the test on it - optional (default:0 [range:0 - N-1] N = total number of available GPUs on a machine)')
parser.add_argument('--files_directory', type=str, default='',
help='The path to a dirctory containing one or more supported files for decoding (e.g., mp4, mov, etc.) and their corresponding reference MD5 digests - required')
args = parser.parse_args()
rocDecodeDirectory = args.rocDecode_directory
gpuDeviceID = args.gpu_device_id
filesDir = args.files_directory
print("\nrunrocDecodeTests V"+__version__+"\n")
# rocDecode Application
scriptPath = os.path.dirname(os.path.realpath(__file__))
rocDecode_exe = rocDecodeDirectory+'/samples/videoDecode/build/videodecode'
resultsPath = scriptPath+'/rocDecode_videoDecode_results'
run_rocDecode_app = os.path.abspath(rocDecode_exe)
os.system('(mkdir -p ' + resultsPath + ')')
if(os.path.isfile(run_rocDecode_app)):
print("STATUS: rocDecode path - "+run_rocDecode_app+"\n")
else:
print("\nERROR: rocDecode Executable Not Found\n")
exit()
if os.path.exists(filesDir) and not os.path.isfile(filesDir):
# Checking if the directory is empty or not
if not os.listdir(filesDir):
print("\nERROR: Empty directory - no videos to decode")
exit()
else:
print("\nERROR: The input directory path is either for a file or directory does not exist!")
exit()
if os.path.exists(resultsPath+'/rocDecode_output.log'):
os.remove(resultsPath+'/rocDecode_output.log')
print("Starting conformance test .....................................\n")
streamFileDir = filesDir + '/Streams/'
streamFileList = os.listdir(streamFileDir)
streamFileList.sort(key=str.lower)
streamListSize = len(streamFileList)
md5FileDir = filesDir + '/MD5/'
md5FileList = os.listdir(md5FileDir)
md5FileList.sort(key=str.lower)
md5ListSize = len(md5FileList)
if streamListSize == 0:
print("Error: Empty stream file folder\n")
exit()
if streamListSize != md5ListSize:
print("Error: Bit stream file number and MD5 file number do not match\n")
exit()
for i in range(streamListSize):
streamFilePath = streamFileDir + streamFileList[i]
md5FilePath = md5FileDir + md5FileList[i]
os.system(run_rocDecode_app +' -i ' + streamFilePath + ' -md5_check ' + md5FilePath + ' -d ' + str(gpuDeviceID) + ' | tee -a ' + resultsPath + '/rocDecode_output.log')
print("======================================================================================\n")
fileString = 'Input file'
md5String = 'MD5 message digest'
matchString = 'MD5 digest matches the reference MD5 digest'
mismatchString = 'MD5 digest does not match the reference MD5 digest'
passNum = 0
failNum = 0
with open(resultsPath + '/rocDecode_output.log', 'r') as logFile:
resultFile = open(resultsPath + '/rocDecode_conformance.log', 'w')
resultFile.write("=========================\n")
resultFile.write("Conformance test results\n")
resultFile.write("=========================\n")
line = logFile.readline()
while line:
if line.find(fileString) != -1:
resultFile.write(line)
if line.find(md5String) != -1:
resultFile.write(line)
if line.find(matchString) != -1:
resultFile.write(line)
passNum += 1
if line.find(mismatchString) != -1:
resultFile.write(line)
failNum += 1
line = logFile.readline()
print("Conformance test completed on the", streamListSize, "streams:")
print(" - The number of passing streams is", passNum)
print(" - The number of failing streams is", failNum)
print(" - The number of streams that did not finish decoding is " + str(streamListSize - passNum - failNum))
resultFile.write("\n===================================================\n")
resultFile.write("Conformance test result summary on the " + str(streamListSize) + " streams:\n")
resultFile.write("===================================================")
resultFile.write("\n - The number of passing streams is " + str(passNum))
resultFile.write("\n - The number of failing streams is " + str(failNum))
resultFile.write("\n - The number of streams that did not finish decoding is " + str(streamListSize - passNum - failNum))
resultFile.close()
logFile.close()