Overview
This application shows how to use events to measure the time taken to process VPI tasks. It does an image downsampling composed of two tasks: image blurring to avoid aliasing, followed by actual downsampling. Using a 1920x1080, 8bpp single channel input image, it record events before and after processing it, and also in between the tasks. At the end it shows the time taken for each task and the total time.
This sample shows the following VPI features:
- Creating and destroying a VPI device.
- Creating a VPI-managed 2D images.
- Create a GaussianFilter and Resample algorithms and submit them.
- Creation of VPI events.
- Use events to record the state of a VPI device.
- Measure elapsed time between events.
- Simple device synchronization.
- Error handling.
- Environment clean up.
Instructions
The usage is:
./vpi_sample_05_timing <backend>
where
- backend: either cpu, cuda or pva; it defines the backend that will perform the processing.
Here's one example:
./vpi_sample_05_timing cuda
This is using the CUDA backend. Try other backends to see how the processing time differs between them.
Source code
For convenience, here's the code that is also installed in the samples directory.
#include <iostream>
#define CHECK_STATUS(STMT) \
do \
{ \
VPIStatus status = (STMT); \
if (status != VPI_SUCCESS) \
{ \
throw std::runtime_error(vpiStatusGetName(status)); \
} \
} while (0);
int main(int argc, char *argv[])
{
int retval = 0;
try
{
if (argc != 2)
{
throw std::runtime_error(std::string("Usage: ") + argv[0] + " <cpu|pva|cuda>");
}
std::string strDevType = argv[1];
if (strDevType == "cpu")
{
}
else if (strDevType == "cuda")
{
}
else if (strDevType == "pva")
{
}
else
{
throw std::runtime_error("Backend '" + strDevType +
"' not recognized, it must be either cpu, cuda or pva.");
}
int width = 1920, height = 1080;
std::cout << "Input size: " << width << " x " << height << '\n';
float elapsedBlurMS, elapsedPyramidMS, elapsedTotalMS;
printf("Blurring elapsed time: %f ms\n", elapsedBlurMS);
printf("Gaussian pyramid elapsed time: %f ms\n", elapsedPyramidMS);
printf("Total elapsed time: %f ms\n", elapsedTotalMS);
}
catch (std::exception &e)
{
std::cerr << e.what() << std::endl;
retval = 1;
}
return retval;
}
Results
The input image is 1920x1080, 8bpp single channel. Image downsample currently isn't supported on PVA, so no data for this backend.
- Note
- You should not interpret these elapsed times as a performance benchmark. For this reason, we're not specifying here the hardware used to measure them.
CPU Backend
Input size: 1920 x 1080
Blurring elapsed time: 703.280823 ms
Gaussian pyramid elapsed time: 97.995987 ms
Total elapsed time: 801.276855 ms
CUDA Backend
Input size: 1920 x 1080
Blurring elapsed time: 0.531488 ms
Gaussian pyramid elapsed time: 0.313856 ms
Total elapsed time: 0.845344 ms