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;
#define VPI_REQUIRE_BACKENDS
要求创建请求的后端。
#define VPI_EXCLUSIVE_STREAM_ACCESS
指定内存一次只能被一个流访问。
struct VPIEventImpl * VPIEvent
事件的句柄。
VPIStatus vpiEventElapsedTimeMillis(VPIEvent start, VPIEvent end, float *msec)
计算两个已完成事件之间经过的时间(以毫秒为单位)。
VPIStatus vpiEventRecord(VPIEvent event, VPIStream stream)
在此调用时捕获事件中流命令队列的内容。
VPIStatus vpiEventCreate(uint64_t flags, VPIEvent *event)
创建事件实例。
VPIStatus vpiEventSync(VPIEvent event)
阻塞调用线程,直到事件发出信号。
void vpiEventDestroy(VPIEvent event)
销毁事件实例以及它拥有的所有资源。
VPIStatus vpiSubmitGaussianFilter(VPIStream stream, uint64_t backend, VPIImage input, VPIImage output, int32_t kernelSizeX, int32_t kernelSizeY, float sigmaX, float sigmaY, VPIBorderExtension border)
在图像上运行 2D 高斯滤波器。
void vpiImageDestroy(VPIImage img)
销毁图像实例。
struct VPIImageImpl * VPIImage
图像的句柄。
VPIStatus vpiImageCreate(int32_t width, int32_t height, VPIImageFormat fmt, uint64_t flags, VPIImage *img)
使用指定的标志创建空的图像实例。
struct VPIStreamImpl * VPIStream
流的句柄。
void vpiStreamDestroy(VPIStream stream)
销毁流实例并释放所有硬件资源。
VPIStatus vpiStreamCreate(uint64_t flags, VPIStream *stream)
创建流实例。
@ VPI_BACKEND_CUDA
CUDA 后端。
@ VPI_BORDER_ZERO
图像外部的所有像素均被视为零。