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[])
 
   72             throw std::runtime_error(std::string(
"Usage: ") + argv[0] + 
" <cpu|pva|cuda>");
 
   75         std::string strBackend = argv[1];
 
   80         if (strBackend == 
"cpu")
 
   84         else if (strBackend == 
"cuda")
 
   88         else if (strBackend == 
"pva")
 
   94             throw std::runtime_error(
"Backend '" + strBackend +
 
   95                                      "' 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' 
  108                   << 
"Algorithm: 5x5 Gaussian Filter" << std::endl;
 
  116         CHECK_STATUS(
vpiImageCreate(width, height, imgFormat, memFlags, &image));
 
  119         CHECK_STATUS(
vpiImageCreate(width, height, imgFormat, memFlags, &blurred));
 
  127         const int BATCH_COUNT     = 20;
 
  128         const int AVERAGING_COUNT = 50;
 
  131         std::vector<float> timingsMS;
 
  132         for (
int batch = 0; batch < BATCH_COUNT; ++batch)
 
  138             for (
int i = 0; i < AVERAGING_COUNT; ++i)
 
  152             timingsMS.push_back(elapsedMS / AVERAGING_COUNT);
 
  158         nth_element(timingsMS.begin(), timingsMS.begin() + timingsMS.size() / 2, timingsMS.end());
 
  159         float medianMS = timingsMS[timingsMS.size() / 2];
 
  161         printf(
"Approximated elapsed time per call: %f ms\n", medianMS);
 
  163     catch (std::exception &e)
 
  165         std::cerr << e.what() << std::endl;
 
Functions and structures for dealing with VPI events.
Declares functions that implement the Gaussian Filter algorithm.
Functions and structures for dealing with VPI images.
Declaration of VPI status codes handling functions.
Declares functions dealing with VPI streams.
#define VPI_EXCLUSIVE_STREAM_ACCESS
Specifies that the memory will be accessed by only one stream at a time.
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.
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 VPIStreamImpl * VPIStream
A handle to a stream.
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.