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 is using the CUDA backend. Try other backends to see how the processing time differs between them.
The input image is 1920x1080, 8bpp single channel. Image downsample currently isn't supported on PVA, so no data for this backend.
For convenience, here's the code that is also installed in the samples directory.
41 #define CHECK_STATUS(STMT) \
44 VPIStatus status = (STMT); \
45 if (status != VPI_SUCCESS) \
47 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
48 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
49 std::ostringstream ss; \
50 ss << vpiStatusGetName(status) << ": " << buffer; \
51 throw std::runtime_error(ss.str()); \
55 int main(
int argc,
char *argv[])
74 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|pva|cuda>");
77 std::string strBackend = argv[1];
82 if (strBackend ==
"cpu")
86 else if (strBackend ==
"cuda")
90 else if (strBackend ==
"pva")
96 throw std::runtime_error(
"Backend '" + strBackend +
97 "' not recognized, it must be either cpu, cuda or pva.");
103 int width = 1920, height = 1080;
106 std::cout <<
"Input size: " << width <<
" x " << height <<
'\n';
109 CHECK_STATUS(
vpiImageCreate(width, height, imgFormat, 0, &image));
112 CHECK_STATUS(
vpiPyramidCreate(width, height, imgFormat, 3, 0.5, 0, &output));
115 CHECK_STATUS(
vpiImageCreate(width, height, imgFormat, 0, &blurred));
144 float elapsedBlurMS, elapsedPyramidMS, elapsedTotalMS;
149 printf(
"Blurring elapsed time: %f ms\n", elapsedBlurMS);
150 printf(
"Gaussian pyramid elapsed time: %f ms\n", elapsedPyramidMS);
151 printf(
"Total elapsed time: %f ms\n", elapsedTotalMS);
153 catch (std::exception &e)
155 std::cerr << e.what() << std::endl;
Functions and structures for dealing with VPI events.
Declares functions that implement the Gaussian Filter algorithm.
Declares functions that handle gaussian pyramids.
Functions and structures for dealing with VPI images.
Functions and structures for dealing with VPI pyramids.
Declaration of VPI status codes handling functions.
Declares functions dealing with VPI streams.
struct VPIEventImpl * VPIEvent
A handle to an event.
VPIStatus vpiEventElapsedTimeMillis(VPIEvent start, VPIEvent end, float *msec)
Computes the elapsed time in (msec) between two completed events.
VPIStatus vpiEventRecord(VPIEvent event, VPIStream stream)
Captures in the event the contents of the stream command queue at the time of this call.
VPIStatus vpiEventSync(VPIEvent event)
Blocks the calling thread until the event is signaled.
VPIStatus vpiEventCreate(uint32_t flags, VPIEvent *event)
Create an event instance with the specified flags.
void vpiEventDestroy(VPIEvent event)
Destroy an event instance as well as all resources it owns.
VPIStatus vpiSubmitGaussianFilter(VPIStream stream, uint32_t backend, VPIImage input, VPIImage output, int32_t kernelSizeX, int32_t kernelSizeY, float sigmaX, float sigmaY, VPIBorderExtension border)
Runs a 2D Gaussian filter over an image.
VPIStatus vpiSubmitGaussianPyramidGenerator(VPIStream stream, uint32_t backend, VPIImage input, VPIPyramid output)
Computes the Gaussian pyramid from the input image.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
struct VPIImageImpl * VPIImage
A handle to an image.
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
struct VPIPyramidImpl * VPIPyramid
A handle to an image pyramid.
VPIStatus vpiPyramidCreate(int32_t width, int32_t height, VPIImageFormat fmt, int32_t numLevels, float scale, uint32_t flags, VPIPyramid *pyr)
Create an empty image pyramid instance with the specified flags.
void vpiPyramidDestroy(VPIPyramid pyr)
Destroy an image pyramid instance as well as all resources it owns.
struct VPIStreamImpl * VPIStream
A handle to a stream.
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
VPIBackend
VPI Backend types.
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
Create a stream instance.
@ VPI_BACKEND_CUDA
CUDA backend.
@ VPI_BACKEND_PVA
PVA backend.
@ VPI_BACKEND_CPU
CPU backend.
@ VPI_BORDER_ZERO
All pixels outside the image are considered to be zero.