39 #define CHECK_STATUS(STMT) \
42 VPIStatus status = (STMT); \
43 if (status != VPI_SUCCESS) \
45 char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
46 vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
47 std::ostringstream ss; \
48 ss << vpiStatusGetName(status) << ": " << buffer; \
49 throw std::runtime_error(ss.str()); \
53 int main(
int argc,
char *argv[])
66 throw std::runtime_error(std::string(
"Usage: ") + argv[0] +
" <cpu|pva|cuda>");
69 std::string strBackend = argv[1];
74 if (strBackend ==
"cpu")
78 else if (strBackend ==
"cuda")
82 else if (strBackend ==
"pva")
88 throw std::runtime_error(
"Backend '" + strBackend +
89 "' not recognized, it must be either cpu, cuda or pva.");
95 char imgContents[512][512];
96 for (
int i = 0; i < 512; ++i)
98 for (
int j = 0; j < 512; ++j)
100 imgContents[i][j] = i * 512 + j + i;
108 memset(&imgData, 0,
sizeof(imgData));
140 std::ofstream fd((
"boxfiltered_" + strBackend +
".pgm").c_str());
142 fd <<
"P5\n512 512 255\n";
143 for (
int i = 0; i < 512; ++i)
154 catch (std::exception &e)
156 std::cerr << e.what() << std::endl;
Declares functions that implement the Box Filter algorithm.
Functions and structures for dealing with VPI images.
Declaration of VPI status codes handling functions.
Declares functions dealing with VPI streams.
VPIStatus vpiSubmitBoxFilter(VPIStream stream, uint64_t backend, VPIImage input, VPIImage output, int32_t kernelWidth, int32_t kernelHeight, VPIBorderExtension border)
Runs a 2D box filter over an image.
VPIImageBuffer buffer
Stores the image contents.
VPIImagePlanePitchLinear planes[VPI_MAX_PLANE_COUNT]
Data of all image planes in pitch-linear layout.
VPIImageBufferPitchLinear pitch
Image stored in pitch-linear layout.
void * data
Pointer to the first row of this plane.
int32_t numPlanes
Number of planes.
VPIImageFormat format
Image format.
VPIImageBufferType bufferType
Type of image buffer.
int32_t height
Height of this plane in pixels.
int32_t width
Width of this plane in pixels.
int32_t pitchBytes
Difference in bytes of beginning of one row and the beginning of the previous.
void vpiImageDestroy(VPIImage img)
Destroy an image instance.
struct VPIImageImpl * VPIImage
A handle to an image.
VPIStatus vpiImageCreateWrapper(const VPIImageData *data, const VPIImageWrapperParams *params, uint64_t flags, VPIImage *img)
Create an image object by wrapping an existing memory block.
VPIStatus vpiImageLockData(VPIImage img, VPILockMode mode, VPIImageBufferType bufType, VPIImageData *data)
Acquires the lock on an image object and returns the image contents.
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
Create an empty image instance with the specified flags.
VPIStatus vpiImageUnlock(VPIImage img)
Releases the lock on an image object.
@ VPI_IMAGE_BUFFER_HOST_PITCH_LINEAR
Host-accessible with planes in pitch-linear memory layout.
Stores the image plane contents.
Stores information about image characteristics and content.
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(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.
@ VPI_LOCK_READ
Lock memory only for reading.