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 << "" #STMT "\n"; \
51 ss << vpiStatusGetName(status) << ": " << buffer; \
52 throw std::runtime_error(ss.str()); \
56 int main(
int argc,
char *argv[])
73 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|pva|cuda>");
76 std::string strBackend = argv[1];
81 if (strBackend ==
"cpu")
85 else if (strBackend ==
"cuda")
89 else if (strBackend ==
"pva")
95 throw std::runtime_error(
"Backend '" + strBackend +
96 "' not recognized, it must be either cpu, cuda or pva.");
105 int width = 1920, height = 1080;
108 std::cout <<
"Input size: " << width <<
" x " << height <<
'\n'
110 <<
"Algorithm: 5x5 Gaussian Filter on " << strBackend << std::endl;
118 CHECK_STATUS(
vpiImageCreate(width, height, imgFormat, memFlags, &image));
121 CHECK_STATUS(
vpiImageCreate(width, height, imgFormat, memFlags, &blurred));
129 const int BATCH_COUNT = 20;
130 const int AVERAGING_COUNT = 50;
133 std::vector<float> timingsMS;
134 for (
int batch = 0; batch < BATCH_COUNT; ++batch)
140 for (
int i = 0; i < AVERAGING_COUNT; ++i)
154 timingsMS.push_back(elapsedMS / AVERAGING_COUNT);
160 nth_element(timingsMS.begin(), timingsMS.begin() + timingsMS.size() / 2, timingsMS.end());
161 float medianMS = timingsMS[timingsMS.size() / 2];
163 printf(
"Approximated elapsed time per call on %s: %f ms\n", strBackend.c_str(), medianMS);
165 catch (std::exception &e)
167 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_REQUIRE_BACKENDS
Require creation of requested backends.
#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 milliseconds 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 vpiEventCreate(uint64_t flags, VPIEvent *event)
Create an event instance.
VPIStatus vpiEventSync(VPIEvent event)
Blocks the calling thread until the event is signaled.
void vpiEventDestroy(VPIEvent event)
Destroy an event instance as well as all resources it owns.
VPIStatus vpiSubmitGaussianFilter(VPIStream stream, uint64_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, uint64_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(uint64_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.