|
VPI - Vision Programming Interface
0.4.4 Release
|
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:
- Creating and destroying a VPI stream.
- Creating a VPI-managed 2D images.
- Create a GaussianFilter and Rescale algorithms and submit them.
- Creation of VPI events.
- Use events to record the state of a VPI stream.
- Measure elapsed time between events.
- Simple stream 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.
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: 3.584764 ms
Gaussian pyramid elapsed time: 7.906268 ms
Total elapsed time: 11.491032 ms
CUDA Backend
Input size: 1920 x 1080
Blurring elapsed time: 0.245760 ms
Gaussian pyramid elapsed time: 0.135008 ms
Total elapsed time: 0.380768 ms
Source code
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;
VPIStatus vpiEventElapsedTime(VPIEvent start, VPIEvent end, float *msec)
Computes the elapsed time in (msec) between two completed events.
VPIStatus vpiEventCreate(uint32_t flags, VPIEvent *event)
Create an event instance with the specified flags.
Declares functions that handle gaussian pyramids.
VPIStatus vpiEventSync(VPIEvent event)
Blocks the calling thread until the event is signaled.
Declares functions that implement the Gaussian Filter algorithm.
VPIStatus vpiStreamCreate(uint32_t flags, VPIStream *stream)
Create a stream instance.
VPIBackend
VPI Backend types.
VPIStatus vpiSubmitGaussianFilter(VPIStream stream, VPIBackend backend, VPIImage input, VPIImage output, uint32_t kernelSizeX, uint32_t kernelSizeY, float sigmaX, float sigmaY, VPIBoundaryCond boundary)
Runs a 2D Gaussian filter over an image.
VPIStatus vpiEventRecord(VPIEvent event, VPIStream stream)
Captures in the event the contents of the stream command queue at the time of this call.
VPIStatus vpiStreamSync(VPIStream stream)
Blocks the calling thread until all submitted commands in this stream queue are done (queue is empty)...
@ VPI_BACKEND_CUDA
CUDA backend.
struct VPIStreamImpl * VPIStream
A handle to a stream.
void vpiStreamDestroy(VPIStream stream)
Destroy a stream instance and deallocate all HW resources.
VPIStatus vpiImageCreate(uint32_t width, uint32_t height, VPIImageFormat fmt, uint32_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
Functions and structures for dealing with VPI images.
Functions and structures for dealing with VPI events.
struct VPIEventImpl * VPIEvent
A handle to an event.
struct VPIImageImpl * VPIImage
A handle to an image.
VPIStatus vpiPyramidCreate(uint32_t width, uint32_t height, VPIImageFormat fmt, uint32_t numLevels, float scale, uint32_t flags, VPIPyramid *pyr)
Create an empty image pyramid instance with the specified flags.
@ VPI_BOUNDARY_COND_ZERO
All pixels outside the image are considered to be zero.
Functions and structures for dealing with VPI pyramids.
VPIStatus vpiSubmitGaussianPyramidGenerator(VPIStream stream, VPIBackend backend, VPIImage input, VPIPyramid output)
Computes the Gaussian pyramid from the input image.
Declaration of VPI status codes handling functions.
@ VPI_BACKEND_CPU
CPU backend.
Declares functions dealing with VPI streams.
void vpiPyramidDestroy(VPIPyramid pyr)
Destroy an image pyramid instance as well as all resources it owns.
@ VPI_BACKEND_PVA
PVA backend.
void vpiEventDestroy(VPIEvent event)
Destroy an event instance as well as all resources it owns.
struct VPIPyramidImpl * VPIPyramid
A handle to an image pyramid.