mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-26 06:38:16 +08:00
Apply consistent code formatting across the repo. Add clang-format and pre-commit hooks.
This commit is contained in:
@@ -37,4 +37,3 @@ Download and install the [CUDA Toolkit 12.5](https://developer.nvidia.com/cuda-d
|
||||
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
|
||||
|
||||
## References (for more details)
|
||||
|
||||
|
||||
@@ -25,404 +25,382 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <helper_image.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include "cuda_consumer.h"
|
||||
#include <helper_image.h>
|
||||
#include "nvmedia_image_nvscibuf.h"
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
|
||||
// Enable this to 1 if require cuda processed output to ppm file.
|
||||
#define WRITE_OUTPUT_IMAGE 0
|
||||
|
||||
#define checkNvSciErrors(call) \
|
||||
do { \
|
||||
NvSciError _status = call; \
|
||||
if (NvSciError_Success != _status) { \
|
||||
printf( \
|
||||
"NVSCI call in file '%s' in line %i returned" \
|
||||
" %d, expected %d\n", \
|
||||
__FILE__, __LINE__, _status, NvSciError_Success); \
|
||||
fflush(stdout); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
#define checkNvSciErrors(call) \
|
||||
do { \
|
||||
NvSciError _status = call; \
|
||||
if (NvSciError_Success != _status) { \
|
||||
printf("NVSCI call in file '%s' in line %i returned" \
|
||||
" %d, expected %d\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
_status, \
|
||||
NvSciError_Success); \
|
||||
fflush(stdout); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
__global__ static void yuvToGrayscale(cudaSurfaceObject_t surfaceObject,
|
||||
unsigned int *dstImage,
|
||||
int32_t imageWidth, int32_t imageHeight) {
|
||||
size_t x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
size_t y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
__global__ static void
|
||||
yuvToGrayscale(cudaSurfaceObject_t surfaceObject, unsigned int *dstImage, int32_t imageWidth, int32_t imageHeight)
|
||||
{
|
||||
size_t x = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
size_t y = blockIdx.y * blockDim.y + threadIdx.y;
|
||||
|
||||
uchar4 *dstImageUchar4 = (uchar4 *)dstImage;
|
||||
for (; x < imageWidth && y < imageHeight;
|
||||
x += gridDim.x * blockDim.x, y += gridDim.y * blockDim.y) {
|
||||
int colInBytes = x * sizeof(unsigned char);
|
||||
unsigned char luma =
|
||||
surf2Dread<unsigned char>(surfaceObject, colInBytes, y);
|
||||
uchar4 grayscalePix = make_uchar4(luma, luma, luma, 0);
|
||||
uchar4 *dstImageUchar4 = (uchar4 *)dstImage;
|
||||
for (; x < imageWidth && y < imageHeight; x += gridDim.x * blockDim.x, y += gridDim.y * blockDim.y) {
|
||||
int colInBytes = x * sizeof(unsigned char);
|
||||
unsigned char luma = surf2Dread<unsigned char>(surfaceObject, colInBytes, y);
|
||||
uchar4 grayscalePix = make_uchar4(luma, luma, luma, 0);
|
||||
|
||||
dstImageUchar4[y * imageWidth + x] = grayscalePix;
|
||||
}
|
||||
dstImageUchar4[y * imageWidth + x] = grayscalePix;
|
||||
}
|
||||
}
|
||||
|
||||
static void cudaImportNvSciSync(cudaExternalSemaphore_t &extSem,
|
||||
NvSciSyncObj &syncObj) {
|
||||
cudaExternalSemaphoreHandleDesc extSemDesc;
|
||||
memset(&extSemDesc, 0, sizeof(extSemDesc));
|
||||
extSemDesc.type = cudaExternalSemaphoreHandleTypeNvSciSync;
|
||||
extSemDesc.handle.nvSciSyncObj = (void *)syncObj;
|
||||
static void cudaImportNvSciSync(cudaExternalSemaphore_t &extSem, NvSciSyncObj &syncObj)
|
||||
{
|
||||
cudaExternalSemaphoreHandleDesc extSemDesc;
|
||||
memset(&extSemDesc, 0, sizeof(extSemDesc));
|
||||
extSemDesc.type = cudaExternalSemaphoreHandleTypeNvSciSync;
|
||||
extSemDesc.handle.nvSciSyncObj = (void *)syncObj;
|
||||
|
||||
checkCudaErrors(cudaImportExternalSemaphore(&extSem, &extSemDesc));
|
||||
checkCudaErrors(cudaImportExternalSemaphore(&extSem, &extSemDesc));
|
||||
}
|
||||
|
||||
static void waitExternalSemaphore(cudaExternalSemaphore_t &waitSem,
|
||||
NvSciSyncFence *fence, cudaStream_t stream) {
|
||||
cudaExternalSemaphoreWaitParams waitParams;
|
||||
memset(&waitParams, 0, sizeof(waitParams));
|
||||
// For cross-process signaler-waiter applications need to use NvSciIpc
|
||||
// and NvSciSync[Export|Import] utilities to share the NvSciSyncFence
|
||||
// across process. This step is optional in single-process.
|
||||
waitParams.params.nvSciSync.fence = (void *)fence;
|
||||
waitParams.flags = 0;
|
||||
static void waitExternalSemaphore(cudaExternalSemaphore_t &waitSem, NvSciSyncFence *fence, cudaStream_t stream)
|
||||
{
|
||||
cudaExternalSemaphoreWaitParams waitParams;
|
||||
memset(&waitParams, 0, sizeof(waitParams));
|
||||
// For cross-process signaler-waiter applications need to use NvSciIpc
|
||||
// and NvSciSync[Export|Import] utilities to share the NvSciSyncFence
|
||||
// across process. This step is optional in single-process.
|
||||
waitParams.params.nvSciSync.fence = (void *)fence;
|
||||
waitParams.flags = 0;
|
||||
|
||||
checkCudaErrors(
|
||||
cudaWaitExternalSemaphoresAsync(&waitSem, &waitParams, 1, stream));
|
||||
checkCudaErrors(cudaWaitExternalSemaphoresAsync(&waitSem, &waitParams, 1, stream));
|
||||
}
|
||||
|
||||
static void signalExternalSemaphore(cudaExternalSemaphore_t &signalSem,
|
||||
NvSciSyncFence *fence,
|
||||
cudaStream_t stream) {
|
||||
cudaExternalSemaphoreSignalParams signalParams;
|
||||
memset(&signalParams, 0, sizeof(signalParams));
|
||||
// For cross-process signaler-waiter applications need to use NvSciIpc
|
||||
// and NvSciSync[Export|Import] utilities to share the NvSciSyncFence
|
||||
// across process. This step is optional in single-process.
|
||||
signalParams.params.nvSciSync.fence = (void *)fence;
|
||||
signalParams.flags = 0;
|
||||
static void signalExternalSemaphore(cudaExternalSemaphore_t &signalSem, NvSciSyncFence *fence, cudaStream_t stream)
|
||||
{
|
||||
cudaExternalSemaphoreSignalParams signalParams;
|
||||
memset(&signalParams, 0, sizeof(signalParams));
|
||||
// For cross-process signaler-waiter applications need to use NvSciIpc
|
||||
// and NvSciSync[Export|Import] utilities to share the NvSciSyncFence
|
||||
// across process. This step is optional in single-process.
|
||||
signalParams.params.nvSciSync.fence = (void *)fence;
|
||||
signalParams.flags = 0;
|
||||
|
||||
checkCudaErrors(
|
||||
cudaSignalExternalSemaphoresAsync(&signalSem, &signalParams, 1, stream));
|
||||
checkCudaErrors(cudaSignalExternalSemaphoresAsync(&signalSem, &signalParams, 1, stream));
|
||||
}
|
||||
|
||||
static void yuvToGrayscaleCudaKernel(cudaExternalResInterop &cudaExtResObj,
|
||||
int32_t imageWidth, int32_t imageHeight) {
|
||||
static void yuvToGrayscaleCudaKernel(cudaExternalResInterop &cudaExtResObj, int32_t imageWidth, int32_t imageHeight)
|
||||
{
|
||||
#if WRITE_OUTPUT_IMAGE
|
||||
unsigned int *h_dstImage;
|
||||
checkCudaErrors(cudaMallocHost(
|
||||
&h_dstImage, sizeof(unsigned int) * imageHeight * imageWidth));
|
||||
unsigned int *h_dstImage;
|
||||
checkCudaErrors(cudaMallocHost(&h_dstImage, sizeof(unsigned int) * imageHeight * imageWidth));
|
||||
#endif
|
||||
dim3 block(16, 16, 1);
|
||||
dim3 grid((imageWidth / block.x) + 1, (imageHeight / block.y) + 1, 1);
|
||||
dim3 block(16, 16, 1);
|
||||
dim3 grid((imageWidth / block.x) + 1, (imageHeight / block.y) + 1, 1);
|
||||
|
||||
yuvToGrayscale<<<grid, block, 0, cudaExtResObj.stream>>>(
|
||||
cudaExtResObj.cudaSurfaceNvmediaBuf[0], cudaExtResObj.d_outputImage,
|
||||
imageWidth, imageHeight);
|
||||
yuvToGrayscale<<<grid, block, 0, cudaExtResObj.stream>>>(
|
||||
cudaExtResObj.cudaSurfaceNvmediaBuf[0], cudaExtResObj.d_outputImage, imageWidth, imageHeight);
|
||||
|
||||
#if WRITE_OUTPUT_IMAGE
|
||||
checkCudaErrors(
|
||||
cudaMemcpyAsync(h_dstImage, cudaExtResObj.d_outputImage,
|
||||
sizeof(unsigned int) * imageHeight * imageWidth,
|
||||
cudaMemcpyDeviceToHost, cudaExtResObj.stream));
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream));
|
||||
char outputFilename[1024];
|
||||
std::string image_filename = "Grayscale";
|
||||
strcpy(outputFilename, image_filename.c_str());
|
||||
strcpy(outputFilename + image_filename.length(), "_nvsci_out.ppm");
|
||||
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth,
|
||||
imageHeight);
|
||||
printf("Wrote '%s'\n", outputFilename);
|
||||
checkCudaErrors(cudaFreeHost(h_dstImage));
|
||||
checkCudaErrors(cudaMemcpyAsync(h_dstImage,
|
||||
cudaExtResObj.d_outputImage,
|
||||
sizeof(unsigned int) * imageHeight * imageWidth,
|
||||
cudaMemcpyDeviceToHost,
|
||||
cudaExtResObj.stream));
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream));
|
||||
char outputFilename[1024];
|
||||
std::string image_filename = "Grayscale";
|
||||
strcpy(outputFilename, image_filename.c_str());
|
||||
strcpy(outputFilename + image_filename.length(), "_nvsci_out.ppm");
|
||||
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth, imageHeight);
|
||||
printf("Wrote '%s'\n", outputFilename);
|
||||
checkCudaErrors(cudaFreeHost(h_dstImage));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void cudaImportNvSciImage(cudaExternalResInterop &cudaExtResObj,
|
||||
NvSciBufObj &inputBufObj) {
|
||||
NvSciBufModule module = NULL;
|
||||
NvSciBufAttrList attrlist = NULL;
|
||||
NvSciBufAttrKeyValuePair pairArrayOut[10];
|
||||
static void cudaImportNvSciImage(cudaExternalResInterop &cudaExtResObj, NvSciBufObj &inputBufObj)
|
||||
{
|
||||
NvSciBufModule module = NULL;
|
||||
NvSciBufAttrList attrlist = NULL;
|
||||
NvSciBufAttrKeyValuePair pairArrayOut[10];
|
||||
|
||||
checkNvSciErrors(NvSciBufModuleOpen(&module));
|
||||
checkNvSciErrors(NvSciBufAttrListCreate(module, &attrlist));
|
||||
checkNvSciErrors(NvSciBufObjGetAttrList(inputBufObj, &attrlist));
|
||||
checkNvSciErrors(NvSciBufModuleOpen(&module));
|
||||
checkNvSciErrors(NvSciBufAttrListCreate(module, &attrlist));
|
||||
checkNvSciErrors(NvSciBufObjGetAttrList(inputBufObj, &attrlist));
|
||||
|
||||
memset(pairArrayOut, 0, sizeof(NvSciBufAttrKeyValuePair) * 10);
|
||||
memset(pairArrayOut, 0, sizeof(NvSciBufAttrKeyValuePair) * 10);
|
||||
|
||||
int numAttrs = 0;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Size;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneChannelCount;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneCount;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneWidth;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneHeight;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Layout;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneBitsPerPixel;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneOffset;
|
||||
int numAttrs = 0;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Size;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneChannelCount;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneCount;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneWidth;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneHeight;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_Layout;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneBitsPerPixel;
|
||||
pairArrayOut[numAttrs++].key = NvSciBufImageAttrKey_PlaneOffset;
|
||||
|
||||
checkNvSciErrors(NvSciBufAttrListGetAttrs(attrlist, pairArrayOut, numAttrs));
|
||||
checkNvSciErrors(NvSciBufAttrListGetAttrs(attrlist, pairArrayOut, numAttrs));
|
||||
|
||||
uint64_t size = *(uint64_t *)pairArrayOut[0].value;
|
||||
uint8_t channelCount = *(uint8_t *)pairArrayOut[1].value;
|
||||
cudaExtResObj.planeCount = *(int32_t *)pairArrayOut[2].value;
|
||||
cudaExtResObj.imageWidth =
|
||||
(int32_t *)malloc(sizeof(int32_t) * cudaExtResObj.planeCount);
|
||||
cudaExtResObj.imageHeight =
|
||||
(int32_t *)malloc(sizeof(int32_t) * cudaExtResObj.planeCount);
|
||||
cudaExtResObj.planeOffset =
|
||||
(uint64_t *)malloc(sizeof(uint64_t) * cudaExtResObj.planeCount);
|
||||
uint64_t size = *(uint64_t *)pairArrayOut[0].value;
|
||||
uint8_t channelCount = *(uint8_t *)pairArrayOut[1].value;
|
||||
cudaExtResObj.planeCount = *(int32_t *)pairArrayOut[2].value;
|
||||
cudaExtResObj.imageWidth = (int32_t *)malloc(sizeof(int32_t) * cudaExtResObj.planeCount);
|
||||
cudaExtResObj.imageHeight = (int32_t *)malloc(sizeof(int32_t) * cudaExtResObj.planeCount);
|
||||
cudaExtResObj.planeOffset = (uint64_t *)malloc(sizeof(uint64_t) * cudaExtResObj.planeCount);
|
||||
|
||||
memcpy(cudaExtResObj.imageWidth, (int32_t *)pairArrayOut[3].value,
|
||||
cudaExtResObj.planeCount * sizeof(int32_t));
|
||||
memcpy(cudaExtResObj.imageHeight, (int32_t *)pairArrayOut[4].value,
|
||||
cudaExtResObj.planeCount * sizeof(int32_t));
|
||||
memcpy(cudaExtResObj.planeOffset, (uint64_t *)pairArrayOut[7].value,
|
||||
cudaExtResObj.planeCount * sizeof(uint64_t));
|
||||
memcpy(cudaExtResObj.imageWidth, (int32_t *)pairArrayOut[3].value, cudaExtResObj.planeCount * sizeof(int32_t));
|
||||
memcpy(cudaExtResObj.imageHeight, (int32_t *)pairArrayOut[4].value, cudaExtResObj.planeCount * sizeof(int32_t));
|
||||
memcpy(cudaExtResObj.planeOffset, (uint64_t *)pairArrayOut[7].value, cudaExtResObj.planeCount * sizeof(uint64_t));
|
||||
|
||||
NvSciBufAttrValImageLayoutType layout =
|
||||
*(NvSciBufAttrValImageLayoutType *)pairArrayOut[5].value;
|
||||
uint32_t bitsPerPixel = *(uint32_t *)pairArrayOut[6].value;
|
||||
NvSciBufAttrValImageLayoutType layout = *(NvSciBufAttrValImageLayoutType *)pairArrayOut[5].value;
|
||||
uint32_t bitsPerPixel = *(uint32_t *)pairArrayOut[6].value;
|
||||
|
||||
if (layout != NvSciBufImage_BlockLinearType) {
|
||||
printf("Image layout is not block linear.. waiving execution\n");
|
||||
exit(EXIT_WAIVED);
|
||||
}
|
||||
|
||||
cudaExternalMemoryHandleDesc memHandleDesc;
|
||||
memset(&memHandleDesc, 0, sizeof(memHandleDesc));
|
||||
memHandleDesc.type = cudaExternalMemoryHandleTypeNvSciBuf;
|
||||
memHandleDesc.handle.nvSciBufObject = inputBufObj;
|
||||
memHandleDesc.size = size;
|
||||
checkCudaErrors(
|
||||
cudaImportExternalMemory(&cudaExtResObj.extMemImageBuf, &memHandleDesc));
|
||||
|
||||
cudaExtResObj.d_mipmapArray = (cudaMipmappedArray_t *)malloc(
|
||||
sizeof(cudaMipmappedArray_t) * cudaExtResObj.planeCount);
|
||||
|
||||
for (int i = 0; i < cudaExtResObj.planeCount; i++) {
|
||||
cudaExtent extent = {};
|
||||
memset(&extent, 0, sizeof(extent));
|
||||
extent.width = cudaExtResObj.imageWidth[i];
|
||||
extent.height = cudaExtResObj.imageHeight[i];
|
||||
extent.depth = 0;
|
||||
cudaChannelFormatDesc desc;
|
||||
switch (channelCount) {
|
||||
case 1:
|
||||
default:
|
||||
desc = cudaCreateChannelDesc(bitsPerPixel, 0, 0, 0,
|
||||
cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
case 2:
|
||||
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, 0, 0,
|
||||
cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
case 3:
|
||||
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, bitsPerPixel,
|
||||
0, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
case 4:
|
||||
desc =
|
||||
cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, bitsPerPixel,
|
||||
bitsPerPixel, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
if (layout != NvSciBufImage_BlockLinearType) {
|
||||
printf("Image layout is not block linear.. waiving execution\n");
|
||||
exit(EXIT_WAIVED);
|
||||
}
|
||||
|
||||
cudaExternalMemoryMipmappedArrayDesc mipmapDesc = {0};
|
||||
mipmapDesc.offset = cudaExtResObj.planeOffset[i];
|
||||
mipmapDesc.formatDesc = desc;
|
||||
mipmapDesc.extent = extent;
|
||||
mipmapDesc.flags = 0;
|
||||
mipmapDesc.numLevels = 1;
|
||||
checkCudaErrors(cudaExternalMemoryGetMappedMipmappedArray(
|
||||
&cudaExtResObj.d_mipmapArray[i], cudaExtResObj.extMemImageBuf,
|
||||
&mipmapDesc));
|
||||
}
|
||||
cudaExternalMemoryHandleDesc memHandleDesc;
|
||||
memset(&memHandleDesc, 0, sizeof(memHandleDesc));
|
||||
memHandleDesc.type = cudaExternalMemoryHandleTypeNvSciBuf;
|
||||
memHandleDesc.handle.nvSciBufObject = inputBufObj;
|
||||
memHandleDesc.size = size;
|
||||
checkCudaErrors(cudaImportExternalMemory(&cudaExtResObj.extMemImageBuf, &memHandleDesc));
|
||||
|
||||
cudaExtResObj.d_mipmapArray =
|
||||
(cudaMipmappedArray_t *)malloc(sizeof(cudaMipmappedArray_t) * cudaExtResObj.planeCount);
|
||||
|
||||
for (int i = 0; i < cudaExtResObj.planeCount; i++) {
|
||||
cudaExtent extent = {};
|
||||
memset(&extent, 0, sizeof(extent));
|
||||
extent.width = cudaExtResObj.imageWidth[i];
|
||||
extent.height = cudaExtResObj.imageHeight[i];
|
||||
extent.depth = 0;
|
||||
cudaChannelFormatDesc desc;
|
||||
switch (channelCount) {
|
||||
case 1:
|
||||
default:
|
||||
desc = cudaCreateChannelDesc(bitsPerPixel, 0, 0, 0, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
case 2:
|
||||
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, 0, 0, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
case 3:
|
||||
desc = cudaCreateChannelDesc(bitsPerPixel, bitsPerPixel, bitsPerPixel, 0, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
case 4:
|
||||
desc = cudaCreateChannelDesc(
|
||||
bitsPerPixel, bitsPerPixel, bitsPerPixel, bitsPerPixel, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
}
|
||||
|
||||
cudaExternalMemoryMipmappedArrayDesc mipmapDesc = {0};
|
||||
mipmapDesc.offset = cudaExtResObj.planeOffset[i];
|
||||
mipmapDesc.formatDesc = desc;
|
||||
mipmapDesc.extent = extent;
|
||||
mipmapDesc.flags = 0;
|
||||
mipmapDesc.numLevels = 1;
|
||||
checkCudaErrors(cudaExternalMemoryGetMappedMipmappedArray(
|
||||
&cudaExtResObj.d_mipmapArray[i], cudaExtResObj.extMemImageBuf, &mipmapDesc));
|
||||
}
|
||||
}
|
||||
|
||||
static cudaSurfaceObject_t createCudaSurface(cudaArray_t &d_mipLevelArray) {
|
||||
cudaResourceDesc resourceDesc;
|
||||
memset(&resourceDesc, 0, sizeof(resourceDesc));
|
||||
resourceDesc.resType = cudaResourceTypeArray;
|
||||
resourceDesc.res.array.array = d_mipLevelArray;
|
||||
static cudaSurfaceObject_t createCudaSurface(cudaArray_t &d_mipLevelArray)
|
||||
{
|
||||
cudaResourceDesc resourceDesc;
|
||||
memset(&resourceDesc, 0, sizeof(resourceDesc));
|
||||
resourceDesc.resType = cudaResourceTypeArray;
|
||||
resourceDesc.res.array.array = d_mipLevelArray;
|
||||
|
||||
cudaSurfaceObject_t surfaceObject;
|
||||
checkCudaErrors(cudaCreateSurfaceObject(&surfaceObject, &resourceDesc));
|
||||
return surfaceObject;
|
||||
cudaSurfaceObject_t surfaceObject;
|
||||
checkCudaErrors(cudaCreateSurfaceObject(&surfaceObject, &resourceDesc));
|
||||
return surfaceObject;
|
||||
}
|
||||
|
||||
static cudaStream_t createCudaStream(int deviceId) {
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
cudaStream_t stream;
|
||||
checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
|
||||
return stream;
|
||||
static cudaStream_t createCudaStream(int deviceId)
|
||||
{
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
cudaStream_t stream;
|
||||
checkCudaErrors(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
|
||||
return stream;
|
||||
}
|
||||
|
||||
// CUDA setup buffers/synchronization objects for interop via NvSci API.
|
||||
void setupCuda(cudaExternalResInterop &cudaExtResObj, NvSciBufObj &inputBufObj,
|
||||
NvSciSyncObj &syncObj, NvSciSyncObj &cudaSignalerSyncObj,
|
||||
int deviceId) {
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
cudaImportNvSciSync(cudaExtResObj.waitSem, syncObj);
|
||||
cudaImportNvSciSync(cudaExtResObj.signalSem, cudaSignalerSyncObj);
|
||||
void setupCuda(cudaExternalResInterop &cudaExtResObj,
|
||||
NvSciBufObj &inputBufObj,
|
||||
NvSciSyncObj &syncObj,
|
||||
NvSciSyncObj &cudaSignalerSyncObj,
|
||||
int deviceId)
|
||||
{
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
cudaImportNvSciSync(cudaExtResObj.waitSem, syncObj);
|
||||
cudaImportNvSciSync(cudaExtResObj.signalSem, cudaSignalerSyncObj);
|
||||
|
||||
cudaImportNvSciImage(cudaExtResObj, inputBufObj);
|
||||
cudaExtResObj.d_mipLevelArray =
|
||||
(cudaArray_t *)malloc(sizeof(cudaArray_t) * cudaExtResObj.planeCount);
|
||||
cudaExtResObj.cudaSurfaceNvmediaBuf = (cudaSurfaceObject_t *)malloc(
|
||||
sizeof(cudaSurfaceObject_t) * cudaExtResObj.planeCount);
|
||||
cudaImportNvSciImage(cudaExtResObj, inputBufObj);
|
||||
cudaExtResObj.d_mipLevelArray = (cudaArray_t *)malloc(sizeof(cudaArray_t) * cudaExtResObj.planeCount);
|
||||
cudaExtResObj.cudaSurfaceNvmediaBuf =
|
||||
(cudaSurfaceObject_t *)malloc(sizeof(cudaSurfaceObject_t) * cudaExtResObj.planeCount);
|
||||
|
||||
for (int i = 0; i < cudaExtResObj.planeCount; ++i) {
|
||||
uint32_t mipLevelId = 0;
|
||||
checkCudaErrors(
|
||||
cudaGetMipmappedArrayLevel(&cudaExtResObj.d_mipLevelArray[i],
|
||||
cudaExtResObj.d_mipmapArray[i], mipLevelId));
|
||||
cudaExtResObj.cudaSurfaceNvmediaBuf[i] =
|
||||
createCudaSurface(cudaExtResObj.d_mipLevelArray[i]);
|
||||
}
|
||||
for (int i = 0; i < cudaExtResObj.planeCount; ++i) {
|
||||
uint32_t mipLevelId = 0;
|
||||
checkCudaErrors(
|
||||
cudaGetMipmappedArrayLevel(&cudaExtResObj.d_mipLevelArray[i], cudaExtResObj.d_mipmapArray[i], mipLevelId));
|
||||
cudaExtResObj.cudaSurfaceNvmediaBuf[i] = createCudaSurface(cudaExtResObj.d_mipLevelArray[i]);
|
||||
}
|
||||
|
||||
cudaExtResObj.stream = createCudaStream(deviceId);
|
||||
checkCudaErrors(cudaMalloc(&cudaExtResObj.d_outputImage,
|
||||
sizeof(unsigned int) *
|
||||
cudaExtResObj.imageWidth[0] *
|
||||
cudaExtResObj.imageHeight[0]));
|
||||
cudaExtResObj.stream = createCudaStream(deviceId);
|
||||
checkCudaErrors(cudaMalloc(&cudaExtResObj.d_outputImage,
|
||||
sizeof(unsigned int) * cudaExtResObj.imageWidth[0] * cudaExtResObj.imageHeight[0]));
|
||||
}
|
||||
|
||||
// CUDA clean up buffers used **with** NvSci API.
|
||||
void cleanupCuda(cudaExternalResInterop &cudaExtResObj) {
|
||||
for (int i = 0; i < cudaExtResObj.planeCount; i++) {
|
||||
checkCudaErrors(
|
||||
cudaDestroySurfaceObject(cudaExtResObj.cudaSurfaceNvmediaBuf[i]));
|
||||
checkCudaErrors(cudaFreeMipmappedArray(cudaExtResObj.d_mipmapArray[i]));
|
||||
}
|
||||
free(cudaExtResObj.d_mipmapArray);
|
||||
free(cudaExtResObj.d_mipLevelArray);
|
||||
free(cudaExtResObj.cudaSurfaceNvmediaBuf);
|
||||
free(cudaExtResObj.imageWidth);
|
||||
free(cudaExtResObj.imageHeight);
|
||||
checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.waitSem));
|
||||
checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.signalSem));
|
||||
checkCudaErrors(cudaDestroyExternalMemory(cudaExtResObj.extMemImageBuf));
|
||||
checkCudaErrors(cudaStreamDestroy(cudaExtResObj.stream));
|
||||
checkCudaErrors(cudaFree(cudaExtResObj.d_outputImage));
|
||||
void cleanupCuda(cudaExternalResInterop &cudaExtResObj)
|
||||
{
|
||||
for (int i = 0; i < cudaExtResObj.planeCount; i++) {
|
||||
checkCudaErrors(cudaDestroySurfaceObject(cudaExtResObj.cudaSurfaceNvmediaBuf[i]));
|
||||
checkCudaErrors(cudaFreeMipmappedArray(cudaExtResObj.d_mipmapArray[i]));
|
||||
}
|
||||
free(cudaExtResObj.d_mipmapArray);
|
||||
free(cudaExtResObj.d_mipLevelArray);
|
||||
free(cudaExtResObj.cudaSurfaceNvmediaBuf);
|
||||
free(cudaExtResObj.imageWidth);
|
||||
free(cudaExtResObj.imageHeight);
|
||||
checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.waitSem));
|
||||
checkCudaErrors(cudaDestroyExternalSemaphore(cudaExtResObj.signalSem));
|
||||
checkCudaErrors(cudaDestroyExternalMemory(cudaExtResObj.extMemImageBuf));
|
||||
checkCudaErrors(cudaStreamDestroy(cudaExtResObj.stream));
|
||||
checkCudaErrors(cudaFree(cudaExtResObj.d_outputImage));
|
||||
}
|
||||
|
||||
void runCudaOperation(cudaExternalResInterop &cudaExtResObj,
|
||||
NvSciSyncFence *cudaWaitFence,
|
||||
NvSciSyncFence *cudaSignalFence, int deviceId,
|
||||
int iterations) {
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
static int64_t launch = 0;
|
||||
NvSciSyncFence *cudaWaitFence,
|
||||
NvSciSyncFence *cudaSignalFence,
|
||||
int deviceId,
|
||||
int iterations)
|
||||
{
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
static int64_t launch = 0;
|
||||
|
||||
waitExternalSemaphore(cudaExtResObj.waitSem, cudaWaitFence,
|
||||
cudaExtResObj.stream);
|
||||
waitExternalSemaphore(cudaExtResObj.waitSem, cudaWaitFence, cudaExtResObj.stream);
|
||||
|
||||
// run cuda kernel over surface object of the LUMA surface part to extract
|
||||
// grayscale.
|
||||
yuvToGrayscaleCudaKernel(cudaExtResObj, cudaExtResObj.imageWidth[0],
|
||||
cudaExtResObj.imageHeight[0]);
|
||||
// run cuda kernel over surface object of the LUMA surface part to extract
|
||||
// grayscale.
|
||||
yuvToGrayscaleCudaKernel(cudaExtResObj, cudaExtResObj.imageWidth[0], cudaExtResObj.imageHeight[0]);
|
||||
|
||||
// signal fence till the second last iterations for NvMedia2DBlit to wait for
|
||||
// cuda signal and for final iteration as there is no corresponding NvMedia
|
||||
// operation pending therefore we end with cudaStreamSynchronize()
|
||||
if (launch < iterations - 1) {
|
||||
signalExternalSemaphore(cudaExtResObj.signalSem, cudaSignalFence,
|
||||
cudaExtResObj.stream);
|
||||
} else {
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream));
|
||||
}
|
||||
launch++;
|
||||
// signal fence till the second last iterations for NvMedia2DBlit to wait for
|
||||
// cuda signal and for final iteration as there is no corresponding NvMedia
|
||||
// operation pending therefore we end with cudaStreamSynchronize()
|
||||
if (launch < iterations - 1) {
|
||||
signalExternalSemaphore(cudaExtResObj.signalSem, cudaSignalFence, cudaExtResObj.stream);
|
||||
}
|
||||
else {
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaExtResObj.stream));
|
||||
}
|
||||
launch++;
|
||||
}
|
||||
|
||||
// CUDA imports and operates on NvSci buffer/synchronization objects
|
||||
void setupCuda(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId) {
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
cudaResObj.d_yuvArray =
|
||||
(cudaArray_t *)malloc(sizeof(cudaArray_t) * ctx->numSurfaces);
|
||||
cudaResObj.cudaSurfaceNvmediaBuf = (cudaSurfaceObject_t *)malloc(
|
||||
sizeof(cudaSurfaceObject_t) * ctx->numSurfaces);
|
||||
cudaChannelFormatDesc channelDesc;
|
||||
switch (ctx->bytesPerPixel) {
|
||||
void setupCuda(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId)
|
||||
{
|
||||
checkCudaErrors(cudaSetDevice(deviceId));
|
||||
cudaResObj.d_yuvArray = (cudaArray_t *)malloc(sizeof(cudaArray_t) * ctx->numSurfaces);
|
||||
cudaResObj.cudaSurfaceNvmediaBuf = (cudaSurfaceObject_t *)malloc(sizeof(cudaSurfaceObject_t) * ctx->numSurfaces);
|
||||
cudaChannelFormatDesc channelDesc;
|
||||
switch (ctx->bytesPerPixel) {
|
||||
case 1:
|
||||
default:
|
||||
channelDesc =
|
||||
cudaCreateChannelDesc(8, 0, 0, 0, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
}
|
||||
channelDesc = cudaCreateChannelDesc(8, 0, 0, 0, cudaChannelFormatKindUnsigned);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int k = 0; k < ctx->numSurfaces; k++) {
|
||||
checkCudaErrors(cudaMallocArray(
|
||||
&cudaResObj.d_yuvArray[k], &channelDesc,
|
||||
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
|
||||
ctx->heightSurface * ctx->yScalePtr[k]));
|
||||
cudaResObj.cudaSurfaceNvmediaBuf[k] =
|
||||
createCudaSurface(cudaResObj.d_yuvArray[k]);
|
||||
}
|
||||
checkCudaErrors(cudaMalloc(
|
||||
&cudaResObj.d_outputImage,
|
||||
sizeof(unsigned int) * ctx->widthSurface * ctx->heightSurface));
|
||||
for (int k = 0; k < ctx->numSurfaces; k++) {
|
||||
checkCudaErrors(cudaMallocArray(&cudaResObj.d_yuvArray[k],
|
||||
&channelDesc,
|
||||
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
|
||||
ctx->heightSurface * ctx->yScalePtr[k]));
|
||||
cudaResObj.cudaSurfaceNvmediaBuf[k] = createCudaSurface(cudaResObj.d_yuvArray[k]);
|
||||
}
|
||||
checkCudaErrors(
|
||||
cudaMalloc(&cudaResObj.d_outputImage, sizeof(unsigned int) * ctx->widthSurface * ctx->heightSurface));
|
||||
|
||||
cudaResObj.stream = createCudaStream(deviceId);
|
||||
cudaResObj.stream = createCudaStream(deviceId);
|
||||
}
|
||||
|
||||
// CUDA clean up buffers used **without** NvSci API.
|
||||
void cleanupCuda(Blit2DTest *ctx, cudaResources &cudaResObj) {
|
||||
for (int k = 0; k < ctx->numSurfaces; k++) {
|
||||
checkCudaErrors(
|
||||
cudaDestroySurfaceObject(cudaResObj.cudaSurfaceNvmediaBuf[k]));
|
||||
checkCudaErrors(cudaFreeArray(cudaResObj.d_yuvArray[k]));
|
||||
}
|
||||
void cleanupCuda(Blit2DTest *ctx, cudaResources &cudaResObj)
|
||||
{
|
||||
for (int k = 0; k < ctx->numSurfaces; k++) {
|
||||
checkCudaErrors(cudaDestroySurfaceObject(cudaResObj.cudaSurfaceNvmediaBuf[k]));
|
||||
checkCudaErrors(cudaFreeArray(cudaResObj.d_yuvArray[k]));
|
||||
}
|
||||
|
||||
free(cudaResObj.cudaSurfaceNvmediaBuf);
|
||||
free(cudaResObj.cudaSurfaceNvmediaBuf);
|
||||
|
||||
checkCudaErrors(cudaStreamDestroy(cudaResObj.stream));
|
||||
checkCudaErrors(cudaFree(cudaResObj.d_outputImage));
|
||||
checkCudaErrors(cudaStreamDestroy(cudaResObj.stream));
|
||||
checkCudaErrors(cudaFree(cudaResObj.d_outputImage));
|
||||
}
|
||||
|
||||
static void yuvToGrayscaleCudaKernelNonNvSci(cudaResources &cudaResObj,
|
||||
int deviceId, int32_t imageWidth,
|
||||
int32_t imageHeight) {
|
||||
static void
|
||||
yuvToGrayscaleCudaKernelNonNvSci(cudaResources &cudaResObj, int deviceId, int32_t imageWidth, int32_t imageHeight)
|
||||
{
|
||||
#if WRITE_OUTPUT_IMAGE
|
||||
unsigned int *h_dstImage;
|
||||
checkCudaErrors(cudaMallocHost(
|
||||
&h_dstImage, sizeof(unsigned int) * imageHeight * imageWidth));
|
||||
unsigned int *h_dstImage;
|
||||
checkCudaErrors(cudaMallocHost(&h_dstImage, sizeof(unsigned int) * imageHeight * imageWidth));
|
||||
#endif
|
||||
dim3 block(16, 16, 1);
|
||||
dim3 grid((imageWidth / block.x) + 1, (imageHeight / block.y) + 1, 1);
|
||||
dim3 block(16, 16, 1);
|
||||
dim3 grid((imageWidth / block.x) + 1, (imageHeight / block.y) + 1, 1);
|
||||
|
||||
yuvToGrayscale<<<grid, block, 0, cudaResObj.stream>>>(
|
||||
cudaResObj.cudaSurfaceNvmediaBuf[0], cudaResObj.d_outputImage, imageWidth,
|
||||
imageHeight);
|
||||
yuvToGrayscale<<<grid, block, 0, cudaResObj.stream>>>(
|
||||
cudaResObj.cudaSurfaceNvmediaBuf[0], cudaResObj.d_outputImage, imageWidth, imageHeight);
|
||||
|
||||
#if WRITE_OUTPUT_IMAGE
|
||||
checkCudaErrors(
|
||||
cudaMemcpyAsync(h_dstImage, cudaResObj.d_outputImage,
|
||||
sizeof(unsigned int) * imageHeight * imageWidth,
|
||||
cudaMemcpyDeviceToHost, cudaResObj.stream));
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream));
|
||||
char outputFilename[1024];
|
||||
std::string image_filename = "Grayscale";
|
||||
strcpy(outputFilename, image_filename.c_str());
|
||||
strcpy(outputFilename + image_filename.length(), "_non-nvsci_out.ppm");
|
||||
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth,
|
||||
imageHeight);
|
||||
printf("Wrote '%s'\n", outputFilename);
|
||||
checkCudaErrors(cudaFreeHost(h_dstImage));
|
||||
checkCudaErrors(cudaMemcpyAsync(h_dstImage,
|
||||
cudaResObj.d_outputImage,
|
||||
sizeof(unsigned int) * imageHeight * imageWidth,
|
||||
cudaMemcpyDeviceToHost,
|
||||
cudaResObj.stream));
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream));
|
||||
char outputFilename[1024];
|
||||
std::string image_filename = "Grayscale";
|
||||
strcpy(outputFilename, image_filename.c_str());
|
||||
strcpy(outputFilename + image_filename.length(), "_non-nvsci_out.ppm");
|
||||
sdkSavePPM4ub(outputFilename, (unsigned char *)h_dstImage, imageWidth, imageHeight);
|
||||
printf("Wrote '%s'\n", outputFilename);
|
||||
checkCudaErrors(cudaFreeHost(h_dstImage));
|
||||
#else
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream));
|
||||
checkCudaErrors(cudaStreamSynchronize(cudaResObj.stream));
|
||||
#endif
|
||||
}
|
||||
|
||||
// CUDA operates **without** NvSci APIs buffer/synchronization objects.
|
||||
void runCudaOperation(Blit2DTest *ctx, cudaResources &cudaResObj,
|
||||
int deviceId) {
|
||||
for (int k = 0; k < ctx->numSurfaces; k++) {
|
||||
checkCudaErrors(cudaMemcpy2DToArray(
|
||||
cudaResObj.d_yuvArray[k], 0, 0, ctx->dstBuff[k],
|
||||
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
|
||||
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
|
||||
ctx->heightSurface * ctx->yScalePtr[k], cudaMemcpyHostToDevice));
|
||||
}
|
||||
// run cuda kernel over surface object of the LUMA surface part to extract
|
||||
// grayscale.
|
||||
yuvToGrayscaleCudaKernelNonNvSci(cudaResObj, deviceId, ctx->widthSurface,
|
||||
ctx->heightSurface);
|
||||
void runCudaOperation(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId)
|
||||
{
|
||||
for (int k = 0; k < ctx->numSurfaces; k++) {
|
||||
checkCudaErrors(cudaMemcpy2DToArray(cudaResObj.d_yuvArray[k],
|
||||
0,
|
||||
0,
|
||||
ctx->dstBuff[k],
|
||||
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
|
||||
ctx->widthSurface * ctx->xScalePtr[k] * ctx->bytesPerPixel,
|
||||
ctx->heightSurface * ctx->yScalePtr[k],
|
||||
cudaMemcpyHostToDevice));
|
||||
}
|
||||
// run cuda kernel over surface object of the LUMA surface part to extract
|
||||
// grayscale.
|
||||
yuvToGrayscaleCudaKernelNonNvSci(cudaResObj, deviceId, ctx->widthSurface, ctx->heightSurface);
|
||||
}
|
||||
|
||||
@@ -29,42 +29,49 @@
|
||||
#define __CUDA_BUFIMPORT_KERNEL_H__
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "helper_cuda.h"
|
||||
#include "nvmedia_image_nvscibuf.h"
|
||||
#include "nvscisync.h"
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvscisync.h"
|
||||
|
||||
struct cudaExternalResInterop {
|
||||
cudaMipmappedArray_t *d_mipmapArray;
|
||||
cudaArray_t *d_mipLevelArray;
|
||||
cudaSurfaceObject_t *cudaSurfaceNvmediaBuf;
|
||||
cudaStream_t stream;
|
||||
cudaExternalMemory_t extMemImageBuf;
|
||||
cudaExternalSemaphore_t waitSem;
|
||||
cudaExternalSemaphore_t signalSem;
|
||||
struct cudaExternalResInterop
|
||||
{
|
||||
cudaMipmappedArray_t *d_mipmapArray;
|
||||
cudaArray_t *d_mipLevelArray;
|
||||
cudaSurfaceObject_t *cudaSurfaceNvmediaBuf;
|
||||
cudaStream_t stream;
|
||||
cudaExternalMemory_t extMemImageBuf;
|
||||
cudaExternalSemaphore_t waitSem;
|
||||
cudaExternalSemaphore_t signalSem;
|
||||
|
||||
int32_t planeCount;
|
||||
uint64_t *planeOffset;
|
||||
int32_t *imageWidth;
|
||||
int32_t *imageHeight;
|
||||
unsigned int *d_outputImage;
|
||||
int32_t planeCount;
|
||||
uint64_t *planeOffset;
|
||||
int32_t *imageWidth;
|
||||
int32_t *imageHeight;
|
||||
unsigned int *d_outputImage;
|
||||
};
|
||||
|
||||
struct cudaResources {
|
||||
cudaArray_t *d_yuvArray;
|
||||
cudaStream_t stream;
|
||||
cudaSurfaceObject_t *cudaSurfaceNvmediaBuf;
|
||||
unsigned int *d_outputImage;
|
||||
struct cudaResources
|
||||
{
|
||||
cudaArray_t *d_yuvArray;
|
||||
cudaStream_t stream;
|
||||
cudaSurfaceObject_t *cudaSurfaceNvmediaBuf;
|
||||
unsigned int *d_outputImage;
|
||||
};
|
||||
|
||||
void runCudaOperation(cudaExternalResInterop &cudaExtResObj,
|
||||
NvSciSyncFence *fence, NvSciSyncFence *cudaSignalfence,
|
||||
int deviceId, int iterations);
|
||||
NvSciSyncFence *fence,
|
||||
NvSciSyncFence *cudaSignalfence,
|
||||
int deviceId,
|
||||
int iterations);
|
||||
void runCudaOperation(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId);
|
||||
|
||||
void setupCuda(cudaExternalResInterop &cudaExtResObj, NvSciBufObj &inputBufObj,
|
||||
NvSciSyncObj &syncObj, NvSciSyncObj &cudaSignalerSyncObj,
|
||||
int deviceId);
|
||||
void setupCuda(cudaExternalResInterop &cudaExtResObj,
|
||||
NvSciBufObj &inputBufObj,
|
||||
NvSciSyncObj &syncObj,
|
||||
NvSciSyncObj &cudaSignalerSyncObj,
|
||||
int deviceId);
|
||||
void setupCuda(Blit2DTest *ctx, cudaResources &cudaResObj, int deviceId);
|
||||
void cleanupCuda(cudaExternalResInterop &cudaObjs);
|
||||
void cleanupCuda(Blit2DTest *ctx, cudaResources &cudaResObj);
|
||||
|
||||
@@ -26,185 +26,186 @@
|
||||
*/
|
||||
|
||||
/* standard headers */
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
/* Nvidia headers */
|
||||
#include <nvscisync.h>
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvmedia_image.h"
|
||||
|
||||
#include "cuda_consumer.h"
|
||||
#include "nvmedia_2d.h"
|
||||
#include "nvmedia_2d_nvscisync.h"
|
||||
#include "nvmedia_surface.h"
|
||||
#include "nvmedia_utils/image_utils.h"
|
||||
#include "nvmedia_image.h"
|
||||
#include "nvmedia_image_nvscibuf.h"
|
||||
#include "cuda_consumer.h"
|
||||
#include "nvmedia_producer.h"
|
||||
#include "nvmedia_surface.h"
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvmedia_utils/image_utils.h"
|
||||
#include "nvsci_setup.h"
|
||||
|
||||
#define checkNvSciErrors(call) \
|
||||
do { \
|
||||
NvSciError _status = call; \
|
||||
if (NvSciError_Success != _status) { \
|
||||
printf( \
|
||||
"NVSCI call in file '%s' in line %i returned" \
|
||||
" %d, expected %d\n", \
|
||||
__FILE__, __LINE__, _status, NvSciError_Success); \
|
||||
fflush(stdout); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
#define checkNvSciErrors(call) \
|
||||
do { \
|
||||
NvSciError _status = call; \
|
||||
if (NvSciError_Success != _status) { \
|
||||
printf("NVSCI call in file '%s' in line %i returned" \
|
||||
" %d, expected %d\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
_status, \
|
||||
NvSciError_Success); \
|
||||
fflush(stdout); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void cleanup(Blit2DTest* ctx, NvMediaStatus status) {
|
||||
if (ctx->i2d != NULL) {
|
||||
NvMedia2DDestroy(ctx->i2d);
|
||||
}
|
||||
|
||||
if (ctx->device != NULL) {
|
||||
NvMediaDeviceDestroy(ctx->device);
|
||||
}
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
TestArgs args;
|
||||
Blit2DTest ctx;
|
||||
NvMediaStatus status = NVMEDIA_STATUS_ERROR;
|
||||
NvSciSyncFence nvMediaSignalerFence = NvSciSyncFenceInitializer;
|
||||
NvSciSyncFence cudaSignalerFence = NvSciSyncFenceInitializer;
|
||||
|
||||
int cudaDeviceId;
|
||||
uint64_t startTime, endTime;
|
||||
uint64_t operationStartTime, operationEndTime;
|
||||
double processingTime;
|
||||
|
||||
/* Read configuration from command line and config file */
|
||||
memset(&args, 0, sizeof(TestArgs));
|
||||
memset(&ctx, 0, sizeof(Blit2DTest));
|
||||
|
||||
/* ParseArgs parses the command line and the 2D configuration file and
|
||||
* populates all initParams and run time configuration in to appropriate
|
||||
* structures within args
|
||||
*/
|
||||
if (ParseArgs(argc, argv, &args)) {
|
||||
PrintUsage();
|
||||
return -1;
|
||||
}
|
||||
/* Check version */
|
||||
NvMediaVersion version;
|
||||
status = NvMedia2DGetVersion(&version);
|
||||
if (status == NVMEDIA_STATUS_OK) {
|
||||
printf("Library version: %u.%u\n", version.major, version.minor);
|
||||
printf("Header version: %u.%u\n", NVMEDIA_2D_VERSION_MAJOR,
|
||||
NVMEDIA_2D_VERSION_MINOR);
|
||||
if ((version.major != NVMEDIA_2D_VERSION_MAJOR) ||
|
||||
(version.minor != NVMEDIA_2D_VERSION_MINOR)) {
|
||||
printf("Library and Header mismatch!\n");
|
||||
cleanup(&ctx, status);
|
||||
static void cleanup(Blit2DTest *ctx, NvMediaStatus status)
|
||||
{
|
||||
if (ctx->i2d != NULL) {
|
||||
NvMedia2DDestroy(ctx->i2d);
|
||||
}
|
||||
}
|
||||
|
||||
// Create NvMedia device
|
||||
ctx.device = NvMediaDeviceCreate();
|
||||
if (!ctx.device) {
|
||||
printf("%s: Failed to create NvMedia device\n", __func__);
|
||||
cleanup(&ctx, status);
|
||||
}
|
||||
|
||||
// Create 2D blitter
|
||||
ctx.i2d = NvMedia2DCreate(ctx.device);
|
||||
if (!ctx.i2d) {
|
||||
printf("%s: Failed to create NvMedia 2D i2d\n", __func__);
|
||||
cleanup(&ctx, status);
|
||||
}
|
||||
|
||||
cudaDeviceId = findCudaDevice(argc, (const char**)argv);
|
||||
|
||||
// NvMedia-CUDA operations without NvSCI APIs starts
|
||||
cudaResources cudaResObj;
|
||||
GetTimeMicroSec(&startTime);
|
||||
setupNvMedia(&args, &ctx);
|
||||
setupCuda(&ctx, cudaResObj, cudaDeviceId);
|
||||
|
||||
GetTimeMicroSec(&operationStartTime);
|
||||
for (int i = 0; i < args.iterations; i++) {
|
||||
runNvMediaBlit2D(&args, &ctx);
|
||||
runCudaOperation(&ctx, cudaResObj, cudaDeviceId);
|
||||
}
|
||||
GetTimeMicroSec(&operationEndTime);
|
||||
|
||||
cleanupNvMedia(&ctx);
|
||||
cleanupCuda(&ctx, cudaResObj);
|
||||
GetTimeMicroSec(&endTime);
|
||||
// NvMedia-CUDA operations without NvSCI APIs ends
|
||||
|
||||
processingTime = (double)(operationEndTime - operationStartTime) / 1000.0;
|
||||
printf(
|
||||
"Overall Processing time of NvMedia-CUDA Operations without NvSCI APIs "
|
||||
"%.4f ms with %zu iterations\n",
|
||||
processingTime, args.iterations);
|
||||
processingTime = (double)(endTime - startTime) / 1000.0;
|
||||
printf(
|
||||
"Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup "
|
||||
"without NvSCI APIs %.4f ms with %zu iterations\n",
|
||||
processingTime, args.iterations);
|
||||
|
||||
NvSciBufObj dstNvSciBufobj, srcNvSciBufobj;
|
||||
NvSciSyncObj nvMediaSignalerSyncObj, cudaSignalerSyncObj;
|
||||
cudaExternalResInterop cudaExtResObj;
|
||||
// NvMedia-CUDA operations via interop with NvSCI APIs starts
|
||||
GetTimeMicroSec(&startTime);
|
||||
setupNvMediaSignalerNvSciSync(&ctx, nvMediaSignalerSyncObj, cudaDeviceId);
|
||||
setupCudaSignalerNvSciSync(&ctx, cudaSignalerSyncObj, cudaDeviceId);
|
||||
setupNvMedia(&args, &ctx, srcNvSciBufobj, dstNvSciBufobj,
|
||||
nvMediaSignalerSyncObj, cudaSignalerSyncObj, cudaDeviceId);
|
||||
setupCuda(cudaExtResObj, dstNvSciBufobj, nvMediaSignalerSyncObj,
|
||||
cudaSignalerSyncObj, cudaDeviceId);
|
||||
|
||||
GetTimeMicroSec(&operationStartTime);
|
||||
for (int i = 0; i < args.iterations; i++) {
|
||||
runNvMediaBlit2D(&args, &ctx, nvMediaSignalerSyncObj, &cudaSignalerFence,
|
||||
&nvMediaSignalerFence);
|
||||
runCudaOperation(cudaExtResObj, &nvMediaSignalerFence, &cudaSignalerFence,
|
||||
cudaDeviceId, args.iterations);
|
||||
}
|
||||
GetTimeMicroSec(&operationEndTime);
|
||||
|
||||
cleanupNvMedia(&ctx, nvMediaSignalerSyncObj, cudaSignalerSyncObj);
|
||||
cleanupCuda(cudaExtResObj);
|
||||
cleanupNvSciSync(nvMediaSignalerSyncObj);
|
||||
cleanupNvSciSync(cudaSignalerSyncObj);
|
||||
cleanupNvSciBuf(srcNvSciBufobj);
|
||||
cleanupNvSciBuf(dstNvSciBufobj);
|
||||
GetTimeMicroSec(&endTime);
|
||||
// NvMedia-CUDA operations via interop with NvSCI APIs ends
|
||||
|
||||
processingTime = (double)(operationEndTime - operationStartTime) / 1000.0;
|
||||
printf(
|
||||
"Overall Processing time of NvMedia-CUDA Operations with NvSCI APIs %.4f "
|
||||
"ms with %zu iterations\n",
|
||||
processingTime, args.iterations);
|
||||
processingTime = (double)(endTime - startTime) / 1000.0;
|
||||
printf(
|
||||
"Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup "
|
||||
"with NvSCI APIs %.4f ms with %zu iterations\n",
|
||||
processingTime, args.iterations);
|
||||
|
||||
if (ctx.i2d != NULL) {
|
||||
NvMedia2DDestroy(ctx.i2d);
|
||||
}
|
||||
|
||||
if (ctx.device != NULL) {
|
||||
NvMediaDeviceDestroy(ctx.device);
|
||||
}
|
||||
|
||||
if (status == NVMEDIA_STATUS_OK) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
if (ctx->device != NULL) {
|
||||
NvMediaDeviceDestroy(ctx->device);
|
||||
}
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TestArgs args;
|
||||
Blit2DTest ctx;
|
||||
NvMediaStatus status = NVMEDIA_STATUS_ERROR;
|
||||
NvSciSyncFence nvMediaSignalerFence = NvSciSyncFenceInitializer;
|
||||
NvSciSyncFence cudaSignalerFence = NvSciSyncFenceInitializer;
|
||||
|
||||
int cudaDeviceId;
|
||||
uint64_t startTime, endTime;
|
||||
uint64_t operationStartTime, operationEndTime;
|
||||
double processingTime;
|
||||
|
||||
/* Read configuration from command line and config file */
|
||||
memset(&args, 0, sizeof(TestArgs));
|
||||
memset(&ctx, 0, sizeof(Blit2DTest));
|
||||
|
||||
/* ParseArgs parses the command line and the 2D configuration file and
|
||||
* populates all initParams and run time configuration in to appropriate
|
||||
* structures within args
|
||||
*/
|
||||
if (ParseArgs(argc, argv, &args)) {
|
||||
PrintUsage();
|
||||
return -1;
|
||||
}
|
||||
/* Check version */
|
||||
NvMediaVersion version;
|
||||
status = NvMedia2DGetVersion(&version);
|
||||
if (status == NVMEDIA_STATUS_OK) {
|
||||
printf("Library version: %u.%u\n", version.major, version.minor);
|
||||
printf("Header version: %u.%u\n", NVMEDIA_2D_VERSION_MAJOR, NVMEDIA_2D_VERSION_MINOR);
|
||||
if ((version.major != NVMEDIA_2D_VERSION_MAJOR) || (version.minor != NVMEDIA_2D_VERSION_MINOR)) {
|
||||
printf("Library and Header mismatch!\n");
|
||||
cleanup(&ctx, status);
|
||||
}
|
||||
}
|
||||
|
||||
// Create NvMedia device
|
||||
ctx.device = NvMediaDeviceCreate();
|
||||
if (!ctx.device) {
|
||||
printf("%s: Failed to create NvMedia device\n", __func__);
|
||||
cleanup(&ctx, status);
|
||||
}
|
||||
|
||||
// Create 2D blitter
|
||||
ctx.i2d = NvMedia2DCreate(ctx.device);
|
||||
if (!ctx.i2d) {
|
||||
printf("%s: Failed to create NvMedia 2D i2d\n", __func__);
|
||||
cleanup(&ctx, status);
|
||||
}
|
||||
|
||||
cudaDeviceId = findCudaDevice(argc, (const char **)argv);
|
||||
|
||||
// NvMedia-CUDA operations without NvSCI APIs starts
|
||||
cudaResources cudaResObj;
|
||||
GetTimeMicroSec(&startTime);
|
||||
setupNvMedia(&args, &ctx);
|
||||
setupCuda(&ctx, cudaResObj, cudaDeviceId);
|
||||
|
||||
GetTimeMicroSec(&operationStartTime);
|
||||
for (int i = 0; i < args.iterations; i++) {
|
||||
runNvMediaBlit2D(&args, &ctx);
|
||||
runCudaOperation(&ctx, cudaResObj, cudaDeviceId);
|
||||
}
|
||||
GetTimeMicroSec(&operationEndTime);
|
||||
|
||||
cleanupNvMedia(&ctx);
|
||||
cleanupCuda(&ctx, cudaResObj);
|
||||
GetTimeMicroSec(&endTime);
|
||||
// NvMedia-CUDA operations without NvSCI APIs ends
|
||||
|
||||
processingTime = (double)(operationEndTime - operationStartTime) / 1000.0;
|
||||
printf("Overall Processing time of NvMedia-CUDA Operations without NvSCI APIs "
|
||||
"%.4f ms with %zu iterations\n",
|
||||
processingTime,
|
||||
args.iterations);
|
||||
processingTime = (double)(endTime - startTime) / 1000.0;
|
||||
printf("Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup "
|
||||
"without NvSCI APIs %.4f ms with %zu iterations\n",
|
||||
processingTime,
|
||||
args.iterations);
|
||||
|
||||
NvSciBufObj dstNvSciBufobj, srcNvSciBufobj;
|
||||
NvSciSyncObj nvMediaSignalerSyncObj, cudaSignalerSyncObj;
|
||||
cudaExternalResInterop cudaExtResObj;
|
||||
// NvMedia-CUDA operations via interop with NvSCI APIs starts
|
||||
GetTimeMicroSec(&startTime);
|
||||
setupNvMediaSignalerNvSciSync(&ctx, nvMediaSignalerSyncObj, cudaDeviceId);
|
||||
setupCudaSignalerNvSciSync(&ctx, cudaSignalerSyncObj, cudaDeviceId);
|
||||
setupNvMedia(
|
||||
&args, &ctx, srcNvSciBufobj, dstNvSciBufobj, nvMediaSignalerSyncObj, cudaSignalerSyncObj, cudaDeviceId);
|
||||
setupCuda(cudaExtResObj, dstNvSciBufobj, nvMediaSignalerSyncObj, cudaSignalerSyncObj, cudaDeviceId);
|
||||
|
||||
GetTimeMicroSec(&operationStartTime);
|
||||
for (int i = 0; i < args.iterations; i++) {
|
||||
runNvMediaBlit2D(&args, &ctx, nvMediaSignalerSyncObj, &cudaSignalerFence, &nvMediaSignalerFence);
|
||||
runCudaOperation(cudaExtResObj, &nvMediaSignalerFence, &cudaSignalerFence, cudaDeviceId, args.iterations);
|
||||
}
|
||||
GetTimeMicroSec(&operationEndTime);
|
||||
|
||||
cleanupNvMedia(&ctx, nvMediaSignalerSyncObj, cudaSignalerSyncObj);
|
||||
cleanupCuda(cudaExtResObj);
|
||||
cleanupNvSciSync(nvMediaSignalerSyncObj);
|
||||
cleanupNvSciSync(cudaSignalerSyncObj);
|
||||
cleanupNvSciBuf(srcNvSciBufobj);
|
||||
cleanupNvSciBuf(dstNvSciBufobj);
|
||||
GetTimeMicroSec(&endTime);
|
||||
// NvMedia-CUDA operations via interop with NvSCI APIs ends
|
||||
|
||||
processingTime = (double)(operationEndTime - operationStartTime) / 1000.0;
|
||||
printf("Overall Processing time of NvMedia-CUDA Operations with NvSCI APIs %.4f "
|
||||
"ms with %zu iterations\n",
|
||||
processingTime,
|
||||
args.iterations);
|
||||
processingTime = (double)(endTime - startTime) / 1000.0;
|
||||
printf("Overall Processing time of NvMedia-CUDA Operations + allocation/cleanup "
|
||||
"with NvSCI APIs %.4f ms with %zu iterations\n",
|
||||
processingTime,
|
||||
args.iterations);
|
||||
|
||||
if (ctx.i2d != NULL) {
|
||||
NvMedia2DDestroy(ctx.i2d);
|
||||
}
|
||||
|
||||
if (ctx.device != NULL) {
|
||||
NvMediaDeviceDestroy(ctx.device);
|
||||
}
|
||||
|
||||
if (status == NVMEDIA_STATUS_OK) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,447 +25,464 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
/* Nvidia headers */
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvmedia_image.h"
|
||||
#include "nvmedia_2d.h"
|
||||
#include "nvmedia_surface.h"
|
||||
#include "nvmedia_utils/image_utils.h"
|
||||
#include "nvmedia_2d_nvscisync.h"
|
||||
#include "nvmedia_image.h"
|
||||
#include "nvmedia_image_nvscibuf.h"
|
||||
#include "nvmedia_producer.h"
|
||||
#include "nvmedia_2d_nvscisync.h"
|
||||
#include "nvmedia_surface.h"
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvmedia_utils/image_utils.h"
|
||||
#include "nvsci_setup.h"
|
||||
|
||||
NvMediaImage *NvMediaImageCreateUsingNvScibuf(NvMediaDevice *device,
|
||||
NvMediaSurfaceType type,
|
||||
NvMediaImage *NvMediaImageCreateUsingNvScibuf(NvMediaDevice *device,
|
||||
NvMediaSurfaceType type,
|
||||
const NvMediaSurfAllocAttr *attrs,
|
||||
uint32_t numAttrs, uint32_t flags,
|
||||
NvSciBufObj &bufobj,
|
||||
int cudaDeviceId) {
|
||||
NvSciBufModule module = NULL;
|
||||
NvSciError err = NvSciError_Success;
|
||||
NvMediaStatus status = NVMEDIA_STATUS_OK;
|
||||
NvSciBufAttrList attrlist = NULL;
|
||||
NvSciBufAttrList conflictlist = NULL;
|
||||
NvSciBufAttrValAccessPerm access_perm = NvSciBufAccessPerm_ReadWrite;
|
||||
NvSciBufAttrKeyValuePair attr_kvp = {NvSciBufGeneralAttrKey_RequiredPerm,
|
||||
&access_perm, sizeof(access_perm)};
|
||||
NvSciBufAttrKeyValuePair pairArrayOut[10];
|
||||
uint32_t numAttrs,
|
||||
uint32_t flags,
|
||||
NvSciBufObj &bufobj,
|
||||
int cudaDeviceId)
|
||||
{
|
||||
NvSciBufModule module = NULL;
|
||||
NvSciError err = NvSciError_Success;
|
||||
NvMediaStatus status = NVMEDIA_STATUS_OK;
|
||||
NvSciBufAttrList attrlist = NULL;
|
||||
NvSciBufAttrList conflictlist = NULL;
|
||||
NvSciBufAttrValAccessPerm access_perm = NvSciBufAccessPerm_ReadWrite;
|
||||
NvSciBufAttrKeyValuePair attr_kvp = {NvSciBufGeneralAttrKey_RequiredPerm, &access_perm, sizeof(access_perm)};
|
||||
NvSciBufAttrKeyValuePair pairArrayOut[10];
|
||||
|
||||
NvMediaImage *image = NULL;
|
||||
NvMediaImage *image = NULL;
|
||||
|
||||
err = NvSciBufModuleOpen(&module);
|
||||
if (err != NvSciError_Success) {
|
||||
printf("%s: NvSciBuffModuleOpen failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
err = NvSciBufModuleOpen(&module);
|
||||
if (err != NvSciError_Success) {
|
||||
printf("%s: NvSciBuffModuleOpen failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
|
||||
err = NvSciBufAttrListCreate(module, &attrlist);
|
||||
if (err != NvSciError_Success) {
|
||||
printf("%s: SciBufAttrListCreate failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
err = NvSciBufAttrListCreate(module, &attrlist);
|
||||
if (err != NvSciError_Success) {
|
||||
printf("%s: SciBufAttrListCreate failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
|
||||
err = NvSciBufAttrListSetAttrs(attrlist, &attr_kvp, 1);
|
||||
if (err != NvSciError_Success) {
|
||||
printf("%s: AccessPermSetAttr failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
err = NvSciBufAttrListSetAttrs(attrlist, &attr_kvp, 1);
|
||||
if (err != NvSciError_Success) {
|
||||
printf("%s: AccessPermSetAttr failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
|
||||
status =
|
||||
NvMediaImageFillNvSciBufAttrs(device, type, attrs, numAttrs, 0, attrlist);
|
||||
status = NvMediaImageFillNvSciBufAttrs(device, type, attrs, numAttrs, 0, attrlist);
|
||||
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: ImageFillSciBufAttrs failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: ImageFillSciBufAttrs failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
|
||||
setupNvSciBuf(bufobj, attrlist, cudaDeviceId);
|
||||
setupNvSciBuf(bufobj, attrlist, cudaDeviceId);
|
||||
|
||||
status = NvMediaImageCreateFromNvSciBuf(device, bufobj, &image);
|
||||
status = NvMediaImageCreateFromNvSciBuf(device, bufobj, &image);
|
||||
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: ImageCreatefromSciBuf failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: ImageCreatefromSciBuf failed. Error: %d \n", __func__, err);
|
||||
goto fail_cleanup;
|
||||
}
|
||||
|
||||
NvSciBufAttrListFree(attrlist);
|
||||
NvSciBufAttrListFree(attrlist);
|
||||
|
||||
if (module != NULL) {
|
||||
NvSciBufModuleClose(module);
|
||||
}
|
||||
if (module != NULL) {
|
||||
NvSciBufModuleClose(module);
|
||||
}
|
||||
|
||||
return image;
|
||||
return image;
|
||||
|
||||
fail_cleanup:
|
||||
if (attrlist != NULL) {
|
||||
NvSciBufAttrListFree(attrlist);
|
||||
}
|
||||
if (bufobj != NULL) {
|
||||
NvSciBufObjFree(bufobj);
|
||||
bufobj = NULL;
|
||||
}
|
||||
if (attrlist != NULL) {
|
||||
NvSciBufAttrListFree(attrlist);
|
||||
}
|
||||
if (bufobj != NULL) {
|
||||
NvSciBufObjFree(bufobj);
|
||||
bufobj = NULL;
|
||||
}
|
||||
|
||||
if (module != NULL) {
|
||||
NvSciBufModuleClose(module);
|
||||
}
|
||||
NvMediaImageDestroy(image);
|
||||
return NULL;
|
||||
if (module != NULL) {
|
||||
NvSciBufModuleClose(module);
|
||||
}
|
||||
NvMediaImageDestroy(image);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Create NvMediaImage surface based on the input attributes.
|
||||
* Returns NVMEDIA_STATUS_OK on success
|
||||
*/
|
||||
static NvMediaStatus createSurface(Blit2DTest *ctx,
|
||||
static NvMediaStatus createSurface(Blit2DTest *ctx,
|
||||
NvMediaSurfFormatAttr *surfFormatAttrs,
|
||||
NvMediaSurfAllocAttr *surfAllocAttrs,
|
||||
uint32_t numSurfAllocAttrs,
|
||||
NvMediaImage **image, NvSciBufObj &bufObj,
|
||||
int cudaDeviceId) {
|
||||
NvMediaSurfaceType surfType;
|
||||
NvMediaSurfAllocAttr *surfAllocAttrs,
|
||||
uint32_t numSurfAllocAttrs,
|
||||
NvMediaImage **image,
|
||||
NvSciBufObj &bufObj,
|
||||
int cudaDeviceId)
|
||||
{
|
||||
NvMediaSurfaceType surfType;
|
||||
|
||||
/* create source image */
|
||||
surfType =
|
||||
NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX);
|
||||
*image = NvMediaImageCreateUsingNvScibuf(ctx->device, /* device */
|
||||
surfType, /* surface type */
|
||||
surfAllocAttrs, numSurfAllocAttrs, 0,
|
||||
bufObj, cudaDeviceId);
|
||||
/* create source image */
|
||||
surfType = NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX);
|
||||
*image = NvMediaImageCreateUsingNvScibuf(ctx->device, /* device */
|
||||
surfType, /* surface type */
|
||||
surfAllocAttrs,
|
||||
numSurfAllocAttrs,
|
||||
0,
|
||||
bufObj,
|
||||
cudaDeviceId);
|
||||
|
||||
if (*image == NULL) {
|
||||
printf("Unable to create image\n");
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
InitImage(*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value);
|
||||
if (*image == NULL) {
|
||||
printf("Unable to create image\n");
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
InitImage(*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value);
|
||||
|
||||
/* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n",
|
||||
__func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value,
|
||||
surfType);*/
|
||||
/* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n",
|
||||
__func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value,
|
||||
surfType);*/
|
||||
|
||||
return NVMEDIA_STATUS_OK;
|
||||
return NVMEDIA_STATUS_OK;
|
||||
}
|
||||
|
||||
/* Create NvMediaImage surface based on the input attributes.
|
||||
* Returns NVMEDIA_STATUS_OK on success
|
||||
*/
|
||||
static NvMediaStatus createSurfaceNonNvSCI(
|
||||
Blit2DTest *ctx, NvMediaSurfFormatAttr *surfFormatAttrs,
|
||||
NvMediaSurfAllocAttr *surfAllocAttrs, uint32_t numSurfAllocAttrs,
|
||||
NvMediaImage **image) {
|
||||
NvMediaSurfaceType surfType;
|
||||
static NvMediaStatus createSurfaceNonNvSCI(Blit2DTest *ctx,
|
||||
NvMediaSurfFormatAttr *surfFormatAttrs,
|
||||
NvMediaSurfAllocAttr *surfAllocAttrs,
|
||||
uint32_t numSurfAllocAttrs,
|
||||
NvMediaImage **image)
|
||||
{
|
||||
NvMediaSurfaceType surfType;
|
||||
|
||||
/* create source image */
|
||||
surfType =
|
||||
NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX);
|
||||
/* create source image */
|
||||
surfType = NvMediaSurfaceFormatGetType(surfFormatAttrs, NVM_SURF_FMT_ATTR_MAX);
|
||||
|
||||
*image = NvMediaImageCreateNew(ctx->device, surfType, surfAllocAttrs,
|
||||
numSurfAllocAttrs, 0);
|
||||
*image = NvMediaImageCreateNew(ctx->device, surfType, surfAllocAttrs, numSurfAllocAttrs, 0);
|
||||
|
||||
if (*image == NULL) {
|
||||
printf("Unable to create image\n");
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
InitImage(*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value);
|
||||
if (*image == NULL) {
|
||||
printf("Unable to create image\n");
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
InitImage(*image, surfAllocAttrs[0].value, surfAllocAttrs[1].value);
|
||||
|
||||
/* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n",
|
||||
__func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value,
|
||||
surfType);*/
|
||||
/* printf("%s: NvMediaImageCreate:: Image size: %ux%u Image type: %d\n",
|
||||
__func__, surfAllocAttrs[0].value, surfAllocAttrs[1].value,
|
||||
surfType);*/
|
||||
|
||||
return NVMEDIA_STATUS_OK;
|
||||
return NVMEDIA_STATUS_OK;
|
||||
}
|
||||
|
||||
static void destroySurface(NvMediaImage *image) { NvMediaImageDestroy(image); }
|
||||
|
||||
static NvMediaStatus blit2DImage(Blit2DTest *ctx, TestArgs *args,
|
||||
NvSciSyncObj &nvMediaSignalerSyncObj,
|
||||
static NvMediaStatus blit2DImage(Blit2DTest *ctx,
|
||||
TestArgs *args,
|
||||
NvSciSyncObj &nvMediaSignalerSyncObj,
|
||||
NvSciSyncFence *preSyncFence,
|
||||
NvSciSyncFence *fence) {
|
||||
NvMediaStatus status;
|
||||
NvMediaImageSurfaceMap surfaceMap;
|
||||
NvSciSyncFence *fence)
|
||||
{
|
||||
NvMediaStatus status;
|
||||
NvMediaImageSurfaceMap surfaceMap;
|
||||
|
||||
status = ReadImage(args->inputFileName, /* fileName */
|
||||
0, /* frameNum */
|
||||
args->srcSurfAllocAttrs[0].value, /* source image width */
|
||||
args->srcSurfAllocAttrs[1].value, /* source image height */
|
||||
ctx->srcImage, /* srcImage */
|
||||
NVMEDIA_TRUE, /* uvOrderFlag */
|
||||
1, /* bytesPerPixel */
|
||||
MSB_ALIGNED); /* pixelAlignment */
|
||||
status = ReadImage(args->inputFileName, /* fileName */
|
||||
0, /* frameNum */
|
||||
args->srcSurfAllocAttrs[0].value, /* source image width */
|
||||
args->srcSurfAllocAttrs[1].value, /* source image height */
|
||||
ctx->srcImage, /* srcImage */
|
||||
NVMEDIA_TRUE, /* uvOrderFlag */
|
||||
1, /* bytesPerPixel */
|
||||
MSB_ALIGNED); /* pixelAlignment */
|
||||
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: ReadImage failed for input buffer: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
if ((args->srcRect.x1 <= args->srcRect.x0) ||
|
||||
(args->srcRect.y1 <= args->srcRect.y0)) {
|
||||
ctx->srcRect = NULL;
|
||||
} else {
|
||||
ctx->srcRect = &(args->srcRect);
|
||||
}
|
||||
|
||||
if ((args->dstRect.x1 <= args->dstRect.x0) ||
|
||||
(args->dstRect.y1 <= args->dstRect.y0)) {
|
||||
ctx->dstRect = NULL;
|
||||
} else {
|
||||
ctx->dstRect = &(args->dstRect);
|
||||
}
|
||||
|
||||
static int64_t launch = 0;
|
||||
// Start inserting pre-fence from second launch inorder to for NvMedia2Blit to
|
||||
// wait
|
||||
// for cuda signal on fence.
|
||||
if (launch) {
|
||||
status = NvMedia2DInsertPreNvSciSyncFence(ctx->i2d, preSyncFence);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__,
|
||||
status);
|
||||
return status;
|
||||
printf("%s: ReadImage failed for input buffer: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
NvSciSyncFenceClear(preSyncFence);
|
||||
}
|
||||
launch++;
|
||||
|
||||
status = NvMedia2DSetNvSciSyncObjforEOF(ctx->i2d, nvMediaSignalerSyncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__,
|
||||
status);
|
||||
return status;
|
||||
}
|
||||
if ((args->srcRect.x1 <= args->srcRect.x0) || (args->srcRect.y1 <= args->srcRect.y0)) {
|
||||
ctx->srcRect = NULL;
|
||||
}
|
||||
else {
|
||||
ctx->srcRect = &(args->srcRect);
|
||||
}
|
||||
|
||||
/* 2DBlit processing on input image */
|
||||
status = NvMedia2DBlitEx(ctx->i2d, /* i2d */
|
||||
ctx->dstImage, /* dstSurface */
|
||||
ctx->dstRect, /* dstRect */
|
||||
ctx->srcImage, /* srcSurface */
|
||||
ctx->srcRect, /* srcRect */
|
||||
&args->blitParams, /* params */
|
||||
NULL); /* paramsOut */
|
||||
if ((args->dstRect.x1 <= args->dstRect.x0) || (args->dstRect.y1 <= args->dstRect.y0)) {
|
||||
ctx->dstRect = NULL;
|
||||
}
|
||||
else {
|
||||
ctx->dstRect = &(args->dstRect);
|
||||
}
|
||||
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
static int64_t launch = 0;
|
||||
// Start inserting pre-fence from second launch inorder to for NvMedia2Blit to
|
||||
// wait
|
||||
// for cuda signal on fence.
|
||||
if (launch) {
|
||||
status = NvMedia2DInsertPreNvSciSyncFence(ctx->i2d, preSyncFence);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
NvSciSyncFenceClear(preSyncFence);
|
||||
}
|
||||
launch++;
|
||||
|
||||
status =
|
||||
NvMedia2DGetEOFNvSciSyncFence(ctx->i2d, nvMediaSignalerSyncObj, fence);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DGetEOFNvSciSyncFence failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
status = NvMedia2DSetNvSciSyncObjforEOF(ctx->i2d, nvMediaSignalerSyncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DSetNvSciSyncObjforEOF failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
return NVMEDIA_STATUS_OK;
|
||||
/* 2DBlit processing on input image */
|
||||
status = NvMedia2DBlitEx(ctx->i2d, /* i2d */
|
||||
ctx->dstImage, /* dstSurface */
|
||||
ctx->dstRect, /* dstRect */
|
||||
ctx->srcImage, /* srcSurface */
|
||||
ctx->srcRect, /* srcRect */
|
||||
&args->blitParams, /* params */
|
||||
NULL); /* paramsOut */
|
||||
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
status = NvMedia2DGetEOFNvSciSyncFence(ctx->i2d, nvMediaSignalerSyncObj, fence);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DGetEOFNvSciSyncFence failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
return NVMEDIA_STATUS_OK;
|
||||
}
|
||||
|
||||
static NvMediaStatus blit2DImageNonNvSCI(Blit2DTest *ctx, TestArgs *args) {
|
||||
NvMediaStatus status;
|
||||
NvMediaImageSurfaceMap surfaceMap;
|
||||
static NvMediaStatus blit2DImageNonNvSCI(Blit2DTest *ctx, TestArgs *args)
|
||||
{
|
||||
NvMediaStatus status;
|
||||
NvMediaImageSurfaceMap surfaceMap;
|
||||
|
||||
status = ReadImage(args->inputFileName, /* fileName */
|
||||
0, /* frameNum */
|
||||
args->srcSurfAllocAttrs[0].value, /* source image width */
|
||||
args->srcSurfAllocAttrs[1].value, /* source image height */
|
||||
ctx->srcImage, /* srcImage */
|
||||
NVMEDIA_TRUE, /* uvOrderFlag */
|
||||
1, /* bytesPerPixel */
|
||||
MSB_ALIGNED); /* pixelAlignment */
|
||||
status = ReadImage(args->inputFileName, /* fileName */
|
||||
0, /* frameNum */
|
||||
args->srcSurfAllocAttrs[0].value, /* source image width */
|
||||
args->srcSurfAllocAttrs[1].value, /* source image height */
|
||||
ctx->srcImage, /* srcImage */
|
||||
NVMEDIA_TRUE, /* uvOrderFlag */
|
||||
1, /* bytesPerPixel */
|
||||
MSB_ALIGNED); /* pixelAlignment */
|
||||
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: ReadImage failed for input buffer: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: ReadImage failed for input buffer: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
if ((args->srcRect.x1 <= args->srcRect.x0) ||
|
||||
(args->srcRect.y1 <= args->srcRect.y0)) {
|
||||
ctx->srcRect = NULL;
|
||||
} else {
|
||||
ctx->srcRect = &(args->srcRect);
|
||||
}
|
||||
if ((args->srcRect.x1 <= args->srcRect.x0) || (args->srcRect.y1 <= args->srcRect.y0)) {
|
||||
ctx->srcRect = NULL;
|
||||
}
|
||||
else {
|
||||
ctx->srcRect = &(args->srcRect);
|
||||
}
|
||||
|
||||
if ((args->dstRect.x1 <= args->dstRect.x0) ||
|
||||
(args->dstRect.y1 <= args->dstRect.y0)) {
|
||||
ctx->dstRect = NULL;
|
||||
} else {
|
||||
ctx->dstRect = &(args->dstRect);
|
||||
}
|
||||
if ((args->dstRect.x1 <= args->dstRect.x0) || (args->dstRect.y1 <= args->dstRect.y0)) {
|
||||
ctx->dstRect = NULL;
|
||||
}
|
||||
else {
|
||||
ctx->dstRect = &(args->dstRect);
|
||||
}
|
||||
|
||||
/* 2DBlit processing on input image */
|
||||
status = NvMedia2DBlitEx(ctx->i2d, /* i2d */
|
||||
ctx->dstImage, /* dstSurface */
|
||||
ctx->dstRect, /* dstRect */
|
||||
ctx->srcImage, /* srcSurface */
|
||||
ctx->srcRect, /* srcRect */
|
||||
&args->blitParams, /* params */
|
||||
NULL); /* paramsOut */
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
/* 2DBlit processing on input image */
|
||||
status = NvMedia2DBlitEx(ctx->i2d, /* i2d */
|
||||
ctx->dstImage, /* dstSurface */
|
||||
ctx->dstRect, /* dstRect */
|
||||
ctx->srcImage, /* srcSurface */
|
||||
ctx->srcRect, /* srcRect */
|
||||
&args->blitParams, /* params */
|
||||
NULL); /* paramsOut */
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DBlitEx failed: %d\n", __func__, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Write output image into buffer */
|
||||
ctx->bytesPerPixel = 1;
|
||||
WriteImageToAllocatedBuffer(ctx, ctx->dstImage, NVMEDIA_TRUE, NVMEDIA_FALSE,
|
||||
ctx->bytesPerPixel);
|
||||
/* Write output image into buffer */
|
||||
ctx->bytesPerPixel = 1;
|
||||
WriteImageToAllocatedBuffer(ctx, ctx->dstImage, NVMEDIA_TRUE, NVMEDIA_FALSE, ctx->bytesPerPixel);
|
||||
|
||||
return NVMEDIA_STATUS_OK;
|
||||
return NVMEDIA_STATUS_OK;
|
||||
}
|
||||
|
||||
static void cleanup(Blit2DTest *ctx, NvMediaStatus status = NVMEDIA_STATUS_OK) {
|
||||
if (ctx->srcImage != NULL) {
|
||||
NvMedia2DImageUnRegister(ctx->i2d, ctx->srcImage);
|
||||
destroySurface(ctx->srcImage);
|
||||
}
|
||||
if (ctx->dstImage != NULL) {
|
||||
NvMedia2DImageUnRegister(ctx->i2d, ctx->dstImage);
|
||||
destroySurface(ctx->dstImage);
|
||||
}
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
static void cleanup(Blit2DTest *ctx, NvMediaStatus status = NVMEDIA_STATUS_OK)
|
||||
{
|
||||
if (ctx->srcImage != NULL) {
|
||||
NvMedia2DImageUnRegister(ctx->i2d, ctx->srcImage);
|
||||
destroySurface(ctx->srcImage);
|
||||
}
|
||||
if (ctx->dstImage != NULL) {
|
||||
NvMedia2DImageUnRegister(ctx->i2d, ctx->dstImage);
|
||||
destroySurface(ctx->dstImage);
|
||||
}
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void cleanupNvMedia(Blit2DTest *ctx, NvSciSyncObj &syncObj,
|
||||
NvSciSyncObj &preSyncObj) {
|
||||
NvMediaStatus status;
|
||||
cleanup(ctx);
|
||||
status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, syncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMediaImageSciBufInit failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, preSyncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMediaImageSciBufInit failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
NvMediaImageNvSciBufDeinit();
|
||||
void cleanupNvMedia(Blit2DTest *ctx, NvSciSyncObj &syncObj, NvSciSyncObj &preSyncObj)
|
||||
{
|
||||
NvMediaStatus status;
|
||||
cleanup(ctx);
|
||||
status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, syncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMediaImageSciBufInit failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
status = NvMedia2DUnregisterNvSciSyncObj(ctx->i2d, preSyncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMediaImageSciBufInit failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
NvMediaImageNvSciBufDeinit();
|
||||
}
|
||||
|
||||
void cleanupNvMedia(Blit2DTest *ctx) {
|
||||
cleanup(ctx);
|
||||
free(ctx->dstBuffPitches);
|
||||
free(ctx->dstBuffer);
|
||||
free(ctx->dstBuff);
|
||||
void cleanupNvMedia(Blit2DTest *ctx)
|
||||
{
|
||||
cleanup(ctx);
|
||||
free(ctx->dstBuffPitches);
|
||||
free(ctx->dstBuffer);
|
||||
free(ctx->dstBuff);
|
||||
}
|
||||
|
||||
void setupNvMedia(TestArgs *args, Blit2DTest *ctx, NvSciBufObj &srcNvSciBufobj,
|
||||
NvSciBufObj &dstNvSciBufobj, NvSciSyncObj &syncObj,
|
||||
NvSciSyncObj &preSyncObj, int cudaDeviceId) {
|
||||
NvMediaStatus status;
|
||||
status = NvMediaImageNvSciBufInit();
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMediaImageSciBufInit failed\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
void setupNvMedia(TestArgs *args,
|
||||
Blit2DTest *ctx,
|
||||
NvSciBufObj &srcNvSciBufobj,
|
||||
NvSciBufObj &dstNvSciBufobj,
|
||||
NvSciSyncObj &syncObj,
|
||||
NvSciSyncObj &preSyncObj,
|
||||
int cudaDeviceId)
|
||||
{
|
||||
NvMediaStatus status;
|
||||
status = NvMediaImageNvSciBufInit();
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMediaImageSciBufInit failed\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
// Create source surface
|
||||
status = createSurface(ctx, args->srcSurfFormatAttrs, args->srcSurfAllocAttrs,
|
||||
args->numSurfAllocAttrs, &ctx->srcImage,
|
||||
srcNvSciBufobj, cudaDeviceId);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Create source surface
|
||||
status = createSurface(ctx,
|
||||
args->srcSurfFormatAttrs,
|
||||
args->srcSurfAllocAttrs,
|
||||
args->numSurfAllocAttrs,
|
||||
&ctx->srcImage,
|
||||
srcNvSciBufobj,
|
||||
cudaDeviceId);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
// Create destination surface
|
||||
status = createSurface(ctx, args->dstSurfFormatAttrs, args->dstSurfAllocAttrs,
|
||||
args->numSurfAllocAttrs, &ctx->dstImage,
|
||||
dstNvSciBufobj, cudaDeviceId);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Create destination surface
|
||||
status = createSurface(ctx,
|
||||
args->dstSurfFormatAttrs,
|
||||
args->dstSurfAllocAttrs,
|
||||
args->numSurfAllocAttrs,
|
||||
&ctx->dstImage,
|
||||
dstNvSciBufobj,
|
||||
cudaDeviceId);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
// Register source Surface
|
||||
status =
|
||||
NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register source surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Register destination Surface
|
||||
status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage,
|
||||
NVMEDIA_ACCESS_MODE_READ_WRITE);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register destination surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Register source Surface
|
||||
status = NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register source surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Register destination Surface
|
||||
status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage, NVMEDIA_ACCESS_MODE_READ_WRITE);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register destination surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
status = NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_EOFSYNCOBJ, syncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__);
|
||||
}
|
||||
status = NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_EOFSYNCOBJ, syncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__);
|
||||
}
|
||||
|
||||
status =
|
||||
NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_PRESYNCOBJ, preSyncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__);
|
||||
}
|
||||
status = NvMedia2DRegisterNvSciSyncObj(ctx->i2d, NVMEDIA_PRESYNCOBJ, preSyncObj);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to NvMedia2DRegisterNvSciSyncObj\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
// Create NvMedia src & dst image without NvSciBuf
|
||||
void setupNvMedia(TestArgs *args, Blit2DTest *ctx) {
|
||||
NvMediaStatus status;
|
||||
void setupNvMedia(TestArgs *args, Blit2DTest *ctx)
|
||||
{
|
||||
NvMediaStatus status;
|
||||
|
||||
// Create source surface
|
||||
status = createSurfaceNonNvSCI(ctx, args->srcSurfFormatAttrs,
|
||||
args->srcSurfAllocAttrs,
|
||||
args->numSurfAllocAttrs, &ctx->srcImage);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Create source surface
|
||||
status = createSurfaceNonNvSCI(
|
||||
ctx, args->srcSurfFormatAttrs, args->srcSurfAllocAttrs, args->numSurfAllocAttrs, &ctx->srcImage);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
// Create destination surface
|
||||
status = createSurfaceNonNvSCI(ctx, args->dstSurfFormatAttrs,
|
||||
args->dstSurfAllocAttrs,
|
||||
args->numSurfAllocAttrs, &ctx->dstImage);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Create destination surface
|
||||
status = createSurfaceNonNvSCI(
|
||||
ctx, args->dstSurfFormatAttrs, args->dstSurfAllocAttrs, args->numSurfAllocAttrs, &ctx->dstImage);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to create buffer pools\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
// Register source Surface
|
||||
status =
|
||||
NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register source surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Register source Surface
|
||||
status = NvMedia2DImageRegister(ctx->i2d, ctx->srcImage, NVMEDIA_ACCESS_MODE_READ);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register source surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
// Register destination Surface
|
||||
status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage,
|
||||
NVMEDIA_ACCESS_MODE_READ_WRITE);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register destination surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
// Register destination Surface
|
||||
status = NvMedia2DImageRegister(ctx->i2d, ctx->dstImage, NVMEDIA_ACCESS_MODE_READ_WRITE);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Unable to register destination surface\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
|
||||
// Allocate buffer for writing image & set image parameters in Blit2DTest.
|
||||
ctx->bytesPerPixel = 1;
|
||||
AllocateBufferToWriteImage(ctx, ctx->dstImage, NVMEDIA_TRUE, /* uvOrderFlag */
|
||||
NVMEDIA_FALSE); /* appendFlag */
|
||||
// Allocate buffer for writing image & set image parameters in Blit2DTest.
|
||||
ctx->bytesPerPixel = 1;
|
||||
AllocateBufferToWriteImage(ctx,
|
||||
ctx->dstImage,
|
||||
NVMEDIA_TRUE, /* uvOrderFlag */
|
||||
NVMEDIA_FALSE); /* appendFlag */
|
||||
}
|
||||
|
||||
void runNvMediaBlit2D(TestArgs *args, Blit2DTest *ctx) {
|
||||
// Blit2D function
|
||||
NvMediaStatus status = blit2DImageNonNvSCI(ctx, args);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Blit2D failed\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
void runNvMediaBlit2D(TestArgs *args, Blit2DTest *ctx)
|
||||
{
|
||||
// Blit2D function
|
||||
NvMediaStatus status = blit2DImageNonNvSCI(ctx, args);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Blit2D failed\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
}
|
||||
|
||||
void runNvMediaBlit2D(TestArgs *args, Blit2DTest *ctx,
|
||||
NvSciSyncObj &nvMediaSignalerSyncObj,
|
||||
NvSciSyncFence *preSyncFence, NvSciSyncFence *fence) {
|
||||
// Blit2D function
|
||||
NvMediaStatus status =
|
||||
blit2DImage(ctx, args, nvMediaSignalerSyncObj, preSyncFence, fence);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Blit2D failed\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
void runNvMediaBlit2D(TestArgs *args,
|
||||
Blit2DTest *ctx,
|
||||
NvSciSyncObj &nvMediaSignalerSyncObj,
|
||||
NvSciSyncFence *preSyncFence,
|
||||
NvSciSyncFence *fence)
|
||||
{
|
||||
// Blit2D function
|
||||
NvMediaStatus status = blit2DImage(ctx, args, nvMediaSignalerSyncObj, preSyncFence, fence);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: Blit2D failed\n", __func__);
|
||||
cleanup(ctx, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,22 +27,28 @@
|
||||
|
||||
#ifndef __NVMEDIA_PRODUCER_H__
|
||||
#define __NVMEDIA_PRODUCER_H__
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvmedia_image.h"
|
||||
#include "nvmedia_2d.h"
|
||||
#include "nvmedia_surface.h"
|
||||
#include "nvmedia_utils/image_utils.h"
|
||||
#include "nvmedia_image.h"
|
||||
#include "nvmedia_image_nvscibuf.h"
|
||||
#include "nvmedia_surface.h"
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvmedia_utils/image_utils.h"
|
||||
#include "nvscisync.h"
|
||||
|
||||
void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx, NvSciSyncObj& syncObj,
|
||||
NvSciSyncFence* preSyncFence, NvSciSyncFence* fence);
|
||||
void runNvMediaBlit2D(TestArgs* args, Blit2DTest* ctx);
|
||||
void setupNvMedia(TestArgs* args, Blit2DTest* ctx, NvSciBufObj& srcNvSciBufobj,
|
||||
NvSciBufObj& dstNvSciBufobj, NvSciSyncObj& syncObj,
|
||||
NvSciSyncObj& preSyncObj, int cudaDeviceId);
|
||||
void setupNvMedia(TestArgs* args, Blit2DTest* ctx);
|
||||
void cleanupNvMedia(Blit2DTest* ctx, NvSciSyncObj& syncObj,
|
||||
NvSciSyncObj& preSyncObj);
|
||||
void cleanupNvMedia(Blit2DTest* ctx);
|
||||
void runNvMediaBlit2D(TestArgs *args,
|
||||
Blit2DTest *ctx,
|
||||
NvSciSyncObj &syncObj,
|
||||
NvSciSyncFence *preSyncFence,
|
||||
NvSciSyncFence *fence);
|
||||
void runNvMediaBlit2D(TestArgs *args, Blit2DTest *ctx);
|
||||
void setupNvMedia(TestArgs *args,
|
||||
Blit2DTest *ctx,
|
||||
NvSciBufObj &srcNvSciBufobj,
|
||||
NvSciBufObj &dstNvSciBufobj,
|
||||
NvSciSyncObj &syncObj,
|
||||
NvSciSyncObj &preSyncObj,
|
||||
int cudaDeviceId);
|
||||
void setupNvMedia(TestArgs *args, Blit2DTest *ctx);
|
||||
void cleanupNvMedia(Blit2DTest *ctx, NvSciSyncObj &syncObj, NvSciSyncObj &preSyncObj);
|
||||
void cleanupNvMedia(Blit2DTest *ctx);
|
||||
#endif
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
|
||||
/* Nvidia headers */
|
||||
#include "cmdline.h"
|
||||
#include "log_utils.h"
|
||||
#include "misc_utils.h"
|
||||
#include "config_parser.h"
|
||||
#include "helper_cuda.h"
|
||||
#include "log_utils.h"
|
||||
#include "misc_utils.h"
|
||||
|
||||
/* see cmdline.h for details */
|
||||
void PrintUsage()
|
||||
@@ -59,11 +59,11 @@ SectionMap sectionsMap[] = {
|
||||
/* see cmdline.h for details */
|
||||
int ParseArgs(int argc, char *argv[], TestArgs *args)
|
||||
{
|
||||
NvMediaBool bLastArg = NVMEDIA_FALSE;
|
||||
NvMediaBool bDataAvailable = NVMEDIA_FALSE;
|
||||
NvMediaStatus status = NVMEDIA_STATUS_OK;
|
||||
const char* filename = NULL;
|
||||
int i;
|
||||
NvMediaBool bLastArg = NVMEDIA_FALSE;
|
||||
NvMediaBool bDataAvailable = NVMEDIA_FALSE;
|
||||
NvMediaStatus status = NVMEDIA_STATUS_OK;
|
||||
const char *filename = NULL;
|
||||
int i;
|
||||
|
||||
args->srcSurfAllocAttrs[0].type = args->dstSurfAllocAttrs[0].type = NVM_SURF_ATTR_WIDTH;
|
||||
args->srcSurfAllocAttrs[1].type = args->dstSurfAllocAttrs[1].type = NVM_SURF_ATTR_HEIGHT;
|
||||
@@ -73,7 +73,7 @@ int ParseArgs(int argc, char *argv[], TestArgs *args)
|
||||
args->srcSurfAllocAttrs[5].type = args->dstSurfAllocAttrs[5].type = NVM_SURF_ATTR_ALLOC_TYPE;
|
||||
args->srcSurfAllocAttrs[6].type = args->dstSurfAllocAttrs[6].type = NVM_SURF_ATTR_SCAN_TYPE;
|
||||
args->srcSurfAllocAttrs[7].type = args->dstSurfAllocAttrs[7].type = NVM_SURF_ATTR_COLOR_STD_TYPE;
|
||||
args->numSurfAllocAttrs = 8;
|
||||
args->numSurfAllocAttrs = 8;
|
||||
|
||||
args->srcSurfFormatAttrs[0].type = args->dstSurfFormatAttrs[0].type = NVM_SURF_ATTR_SURF_TYPE;
|
||||
args->srcSurfFormatAttrs[1].type = args->dstSurfFormatAttrs[1].type = NVM_SURF_ATTR_LAYOUT;
|
||||
@@ -87,56 +87,74 @@ int ParseArgs(int argc, char *argv[], TestArgs *args)
|
||||
* See nvmedia_2d.h and sample config file(s) for details.
|
||||
*/
|
||||
ConfigParamsMap paramsMap[] = {
|
||||
/*ParamName, &args->variableName, paramType, D, LimitType, Mn, Mx, CharSize, p2C, section */
|
||||
{"transformMode", &args->blitParams.dstTransform, TYPE_UINT, 0, LIMITS_BOTH, 0, 7, 0, 0, SECTION_NONE},
|
||||
{"filterMode", &args->blitParams.filter, TYPE_UINT, 1, LIMITS_BOTH, 1, 4, 0, 0, SECTION_NONE},
|
||||
{"colorStd", &args->blitParams.colorStandard, TYPE_UINT, 0, LIMITS_MIN, 0, 3, 0, 0, SECTION_NONE},
|
||||
{"validOperations", &args->blitParams.validFields, TYPE_UINT, 0, LIMITS_BOTH, 0, 15, 0, 0, SECTION_NONE},
|
||||
{"inputfile", &args->inputFileName, TYPE_CHAR_ARR, 0, LIMITS_NONE, 0, 0, FILE_NAME_SIZE, 0, SECTION_NONE},
|
||||
/*ParamName, &args->variableName, paramType, D, LimitType, Mn,
|
||||
Mx, CharSize, p2C, section */
|
||||
{"transformMode", &args->blitParams.dstTransform, TYPE_UINT, 0, LIMITS_BOTH, 0, 7, 0, 0, SECTION_NONE},
|
||||
{"filterMode", &args->blitParams.filter, TYPE_UINT, 1, LIMITS_BOTH, 1, 4, 0, 0, SECTION_NONE},
|
||||
{"colorStd", &args->blitParams.colorStandard, TYPE_UINT, 0, LIMITS_MIN, 0, 3, 0, 0, SECTION_NONE},
|
||||
{"validOperations", &args->blitParams.validFields, TYPE_UINT, 0, LIMITS_BOTH, 0, 15, 0, 0, SECTION_NONE},
|
||||
{"inputfile", &args->inputFileName, TYPE_CHAR_ARR, 0, LIMITS_NONE, 0, 0, FILE_NAME_SIZE, 0, SECTION_NONE},
|
||||
|
||||
/*src surface alloc attributes*/
|
||||
{"srcWidth", &args->srcSurfAllocAttrs[0].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcHeight", &args->srcSurfAllocAttrs[1].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcCPUAccess", &args->srcSurfAllocAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"srcAllocType", &args->srcSurfAllocAttrs[5].value, TYPE_UINT, 0, LIMITS_BOTH, 0, 1, 0, 0, SECTION_NONE},
|
||||
{"srcScanType", &args->srcSurfAllocAttrs[6].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 1, 0, 0, SECTION_NONE},
|
||||
{"srcColorStd", &args->srcSurfAllocAttrs[7].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 12, 0, 0, SECTION_NONE},
|
||||
{"srcWidth", &args->srcSurfAllocAttrs[0].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcHeight", &args->srcSurfAllocAttrs[1].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcCPUAccess", &args->srcSurfAllocAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"srcAllocType", &args->srcSurfAllocAttrs[5].value, TYPE_UINT, 0, LIMITS_BOTH, 0, 1, 0, 0, SECTION_NONE},
|
||||
{"srcScanType", &args->srcSurfAllocAttrs[6].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 1, 0, 0, SECTION_NONE},
|
||||
{"srcColorStd", &args->srcSurfAllocAttrs[7].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 12, 0, 0, SECTION_NONE},
|
||||
/*src surface format attributes*/
|
||||
{"srcSurfType", &args->srcSurfFormatAttrs[0].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"srcLayout", &args->srcSurfFormatAttrs[1].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 2, 0, 0, SECTION_NONE},
|
||||
{"srcDataType", &args->srcSurfFormatAttrs[2].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 4, 0, 0, SECTION_NONE},
|
||||
{"srcMemory", &args->srcSurfFormatAttrs[3].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"srcSubSamplingType", &args->srcSurfFormatAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 0, 4, 0, 0, SECTION_NONE},
|
||||
{"srcBitsPerComponent", &args->srcSurfFormatAttrs[5].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 10, 0, 0, SECTION_NONE},
|
||||
{"srcComponentOrder", &args->srcSurfFormatAttrs[6].value, TYPE_UINT, 2, LIMITS_BOTH, 1, 45, 0, 0, SECTION_NONE},
|
||||
{"srcSurfType", &args->srcSurfFormatAttrs[0].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"srcLayout", &args->srcSurfFormatAttrs[1].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 2, 0, 0, SECTION_NONE},
|
||||
{"srcDataType", &args->srcSurfFormatAttrs[2].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 4, 0, 0, SECTION_NONE},
|
||||
{"srcMemory", &args->srcSurfFormatAttrs[3].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"srcSubSamplingType", &args->srcSurfFormatAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 0, 4, 0, 0, SECTION_NONE},
|
||||
{"srcBitsPerComponent",
|
||||
&args->srcSurfFormatAttrs[5].value,
|
||||
TYPE_UINT,
|
||||
1,
|
||||
LIMITS_BOTH,
|
||||
1,
|
||||
10,
|
||||
0,
|
||||
0,
|
||||
SECTION_NONE},
|
||||
{"srcComponentOrder", &args->srcSurfFormatAttrs[6].value, TYPE_UINT, 2, LIMITS_BOTH, 1, 45, 0, 0, SECTION_NONE},
|
||||
/*srcRect*/
|
||||
{"srcRectx0", &args->srcRect.x0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcRecty0", &args->srcRect.y0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcRectx1", &args->srcRect.x1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcRecty1", &args->srcRect.y1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcRectx0", &args->srcRect.x0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcRecty0", &args->srcRect.y0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcRectx1", &args->srcRect.x1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"srcRecty1", &args->srcRect.y1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
/*dst surface alloc attributes*/
|
||||
{"dstWidth", &args->dstSurfAllocAttrs[0].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstHeight", &args->dstSurfAllocAttrs[1].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstCPUAccess", &args->dstSurfAllocAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"dstAllocType", &args->dstSurfAllocAttrs[5].value, TYPE_UINT, 0, LIMITS_BOTH, 0, 1, 0, 0, SECTION_NONE},
|
||||
{"dstScanType", &args->dstSurfAllocAttrs[6].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 1, 0, 0, SECTION_NONE},
|
||||
{"dstColorStd", &args->dstSurfAllocAttrs[7].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 12, 0, 0, SECTION_NONE},
|
||||
{"dstWidth", &args->dstSurfAllocAttrs[0].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstHeight", &args->dstSurfAllocAttrs[1].value, TYPE_UINT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstCPUAccess", &args->dstSurfAllocAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"dstAllocType", &args->dstSurfAllocAttrs[5].value, TYPE_UINT, 0, LIMITS_BOTH, 0, 1, 0, 0, SECTION_NONE},
|
||||
{"dstScanType", &args->dstSurfAllocAttrs[6].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 1, 0, 0, SECTION_NONE},
|
||||
{"dstColorStd", &args->dstSurfAllocAttrs[7].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 12, 0, 0, SECTION_NONE},
|
||||
/*dst surface format attributes*/
|
||||
{"dstSurfType", &args->dstSurfFormatAttrs[0].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"dstLayout", &args->dstSurfFormatAttrs[1].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 2, 0, 0, SECTION_NONE},
|
||||
{"dstDataType", &args->dstSurfFormatAttrs[2].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 4, 0, 0, SECTION_NONE},
|
||||
{"dstMemory", &args->dstSurfFormatAttrs[3].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"dstSubSamplingType", &args->dstSurfFormatAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 0, 4, 0, 0, SECTION_NONE},
|
||||
{"dstBitsPerComponent", &args->dstSurfFormatAttrs[5].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 10, 0, 0, SECTION_NONE},
|
||||
{"dstComponentOrder", &args->dstSurfFormatAttrs[6].value, TYPE_UINT, 2, LIMITS_BOTH, 1, 45, 0, 0, SECTION_NONE},
|
||||
{"dstSurfType", &args->dstSurfFormatAttrs[0].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"dstLayout", &args->dstSurfFormatAttrs[1].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 2, 0, 0, SECTION_NONE},
|
||||
{"dstDataType", &args->dstSurfFormatAttrs[2].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 4, 0, 0, SECTION_NONE},
|
||||
{"dstMemory", &args->dstSurfFormatAttrs[3].value, TYPE_UINT, 1, LIMITS_BOTH, 1, 3, 0, 0, SECTION_NONE},
|
||||
{"dstSubSamplingType", &args->dstSurfFormatAttrs[4].value, TYPE_UINT, 1, LIMITS_BOTH, 0, 4, 0, 0, SECTION_NONE},
|
||||
{"dstBitsPerComponent",
|
||||
&args->dstSurfFormatAttrs[5].value,
|
||||
TYPE_UINT,
|
||||
1,
|
||||
LIMITS_BOTH,
|
||||
1,
|
||||
10,
|
||||
0,
|
||||
0,
|
||||
SECTION_NONE},
|
||||
{"dstComponentOrder", &args->dstSurfFormatAttrs[6].value, TYPE_UINT, 2, LIMITS_BOTH, 1, 45, 0, 0, SECTION_NONE},
|
||||
/*dstRect*/
|
||||
{"dstRectx0", &args->dstRect.x0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstRecty0", &args->dstRect.y0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstRectx1", &args->dstRect.x1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstRecty1", &args->dstRect.y1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstRectx0", &args->dstRect.x0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstRecty0", &args->dstRect.y0, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstRectx1", &args->dstRect.x1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
{"dstRecty1", &args->dstRect.y1, TYPE_USHORT, 0, LIMITS_MIN, 0, 0, 0, 0, SECTION_NONE},
|
||||
/*End of the array */
|
||||
{NULL, NULL, TYPE_UINT, 0, LIMITS_NONE, 0, 0, 0, 0, SECTION_NONE}
|
||||
};
|
||||
{NULL, NULL, TYPE_UINT, 0, LIMITS_NONE, 0, 0, 0, 0, SECTION_NONE}};
|
||||
|
||||
args->iterations = 100; // Set default iterations value.
|
||||
|
||||
@@ -146,7 +164,7 @@ int ParseArgs(int argc, char *argv[], TestArgs *args)
|
||||
if (checkCmdLineFlag(argc, (const char **)argv, "cf")) {
|
||||
|
||||
char *inputFileName = NULL;
|
||||
getCmdLineArgumentString(argc, (const char **)argv, "cf", (char**)&inputFileName);
|
||||
getCmdLineArgumentString(argc, (const char **)argv, "cf", (char **)&inputFileName);
|
||||
if (!inputFileName) {
|
||||
printf("ERR: Invalid config file name\n");
|
||||
return -1;
|
||||
@@ -162,8 +180,7 @@ int ParseArgs(int argc, char *argv[], TestArgs *args)
|
||||
filename = sdkFindFilePath("sample.cfg", ".");
|
||||
}
|
||||
|
||||
if (filename != NULL)
|
||||
{
|
||||
if (filename != NULL) {
|
||||
printf("Using config file %s\n", filename);
|
||||
|
||||
/* Init Parser Map*/
|
||||
@@ -173,7 +190,7 @@ int ParseArgs(int argc, char *argv[], TestArgs *args)
|
||||
return -1;
|
||||
}
|
||||
|
||||
status = ConfigParser_ParseFile(paramsMap, 1, sectionsMap, (char*)filename);
|
||||
status = ConfigParser_ParseFile(paramsMap, 1, sectionsMap, (char *)filename);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("ERR: Failed to parse config file. status:%x\n", status);
|
||||
return -1;
|
||||
@@ -189,4 +206,3 @@ int ParseArgs(int argc, char *argv[], TestArgs *args)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,55 +36,57 @@
|
||||
#define FILE_NAME_SIZE 1024
|
||||
|
||||
/* TestArgs contains all arguments required to run the 2D test */
|
||||
typedef struct _TestArgs {
|
||||
typedef struct _TestArgs
|
||||
{
|
||||
char inputFileName[FILE_NAME_SIZE];
|
||||
|
||||
NvMediaSurfAllocAttr srcSurfAllocAttrs[NVM_SURF_ALLOC_ATTR_MAX];
|
||||
NvMediaSurfAllocAttr dstSurfAllocAttrs[NVM_SURF_ALLOC_ATTR_MAX];
|
||||
uint32_t numSurfAllocAttrs;
|
||||
uint32_t numSurfAllocAttrs;
|
||||
|
||||
NvMediaSurfFormatAttr srcSurfFormatAttrs[NVM_SURF_FMT_ATTR_MAX];
|
||||
NvMediaSurfFormatAttr dstSurfFormatAttrs[NVM_SURF_FMT_ATTR_MAX];
|
||||
|
||||
NvMediaRect srcRect;
|
||||
NvMediaRect dstRect;
|
||||
NvMedia2DBlitParameters blitParams;
|
||||
size_t iterations;
|
||||
NvMediaRect srcRect;
|
||||
NvMediaRect dstRect;
|
||||
NvMedia2DBlitParameters blitParams;
|
||||
size_t iterations;
|
||||
} TestArgs;
|
||||
|
||||
typedef struct {
|
||||
NvMediaDevice *device;
|
||||
typedef struct
|
||||
{
|
||||
NvMediaDevice *device;
|
||||
/* I2D for 2D blit processing */
|
||||
NvMedia2D *i2d;
|
||||
NvMediaImage *srcImage;
|
||||
NvMediaImage *dstImage;
|
||||
NvMediaRect *srcRect;
|
||||
NvMediaRect *dstRect;
|
||||
uint8_t **dstBuff;
|
||||
uint32_t *dstBuffPitches;
|
||||
uint8_t *dstBuffer;
|
||||
uint32_t numSurfaces;
|
||||
uint32_t bytesPerPixel;
|
||||
uint32_t heightSurface;
|
||||
uint32_t widthSurface;
|
||||
float *xScalePtr;
|
||||
float *yScalePtr;
|
||||
NvMedia2D *i2d;
|
||||
NvMediaImage *srcImage;
|
||||
NvMediaImage *dstImage;
|
||||
NvMediaRect *srcRect;
|
||||
NvMediaRect *dstRect;
|
||||
uint8_t **dstBuff;
|
||||
uint32_t *dstBuffPitches;
|
||||
uint8_t *dstBuffer;
|
||||
uint32_t numSurfaces;
|
||||
uint32_t bytesPerPixel;
|
||||
uint32_t heightSurface;
|
||||
uint32_t widthSurface;
|
||||
float *xScalePtr;
|
||||
float *yScalePtr;
|
||||
|
||||
} Blit2DTest;
|
||||
|
||||
/* Prints application usage options */
|
||||
void PrintUsage (void);
|
||||
void PrintUsage(void);
|
||||
|
||||
/* Parses command line arguments.
|
||||
* Also parses any configuration files supplied in the command line arguments.
|
||||
* Arguments:
|
||||
* argc
|
||||
* (in) Number of tokens in the command line
|
||||
* argv
|
||||
* (in) Command line tokens
|
||||
* args
|
||||
* (out) Pointer to test arguments structure
|
||||
*/
|
||||
int ParseArgs(int argc, char **argv, TestArgs *args);
|
||||
* Also parses any configuration files supplied in the command line arguments.
|
||||
* Arguments:
|
||||
* argc
|
||||
* (in) Number of tokens in the command line
|
||||
* argv
|
||||
* (in) Command line tokens
|
||||
* args
|
||||
* (out) Pointer to test arguments structure
|
||||
*/
|
||||
int ParseArgs(int argc, char **argv, TestArgs *args);
|
||||
|
||||
#endif /* _NVMEDIA_2D_CMD_LINE_H_ */
|
||||
|
||||
@@ -25,9 +25,10 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config_parser.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "config_parser.h"
|
||||
#include "log_utils.h"
|
||||
#if defined(__QNX__)
|
||||
#include <strings.h>
|
||||
@@ -37,11 +38,12 @@ static NvMediaStatus GetParamIndex(ConfigParamsMap *paramsMap, char *paramName,
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while(paramsMap[i].paramName != NULL) {
|
||||
while (paramsMap[i].paramName != NULL) {
|
||||
if (strcasecmp(paramsMap[i].paramName, paramName) == 0) {
|
||||
*index = i;
|
||||
return NVMEDIA_STATUS_OK;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -53,11 +55,12 @@ NvMediaStatus ConfigParser_GetSectionIndexByName(SectionMap *sectionsMap, char *
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
while(sectionsMap[i].secType != SECTION_NONE) {
|
||||
if(strcmp(sectionsMap[i].name, sectionName) == 0) {
|
||||
while (sectionsMap[i].secType != SECTION_NONE) {
|
||||
if (strcmp(sectionsMap[i].name, sectionName) == 0) {
|
||||
*index = i;
|
||||
return NVMEDIA_STATUS_OK;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -69,11 +72,12 @@ NvMediaStatus ConfigParser_GetSectionIndexByType(SectionMap *sectionsMap, Sectio
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
while(sectionsMap[i].secType != SECTION_NONE) {
|
||||
if(sectionsMap[i].secType == sectionType) {
|
||||
while (sectionsMap[i].secType != SECTION_NONE) {
|
||||
if (sectionsMap[i].secType == sectionType) {
|
||||
*index = i;
|
||||
return NVMEDIA_STATUS_OK;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -86,10 +90,10 @@ static NvMediaStatus GetFileContent(char *filename, char **fileContentOut)
|
||||
{
|
||||
FILE *file;
|
||||
char *fileCotent;
|
||||
long fileSize;
|
||||
long fileSize;
|
||||
|
||||
file = fopen(filename, "r");
|
||||
if(file == NULL) {
|
||||
if (file == NULL) {
|
||||
printf("Parser_GetFileContent: Cannot open configuration file %s\n", filename);
|
||||
return NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
@@ -100,152 +104,162 @@ static NvMediaStatus GetFileContent(char *filename, char **fileContentOut)
|
||||
}
|
||||
|
||||
fileSize = ftell(file);
|
||||
if(fileSize < 0 || fileSize > 150000) {
|
||||
if (fileSize < 0 || fileSize > 150000) {
|
||||
printf("Parser_GetFileContent: Unreasonable Filesize %ld encountered for file %s\n", fileSize, filename);
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
if(fseek (file, 0, SEEK_SET) != 0) {
|
||||
if (fseek(file, 0, SEEK_SET) != 0) {
|
||||
printf("Parser_GetFileContent: Cannot fseek in configuration file %s\n", filename);
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
fileCotent = (char*)malloc(fileSize + 1);
|
||||
if(fileCotent == NULL) {
|
||||
fileCotent = (char *)malloc(fileSize + 1);
|
||||
if (fileCotent == NULL) {
|
||||
printf("Parser_GetFileContent: Failed allocating buffer for file Content\n");
|
||||
return NVMEDIA_STATUS_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
fileSize = (long)fread(fileCotent, 1, fileSize, file);
|
||||
fileSize = (long)fread(fileCotent, 1, fileSize, file);
|
||||
fileCotent[fileSize] = '\0';
|
||||
*fileContentOut = fileCotent;
|
||||
*fileContentOut = fileCotent;
|
||||
|
||||
fclose(file);
|
||||
|
||||
return NVMEDIA_STATUS_OK;
|
||||
}
|
||||
|
||||
NvMediaStatus ConfigParser_ParseFile(ConfigParamsMap *paramsMap, unsigned int numParams, SectionMap *sectionsMap, char *fileName)
|
||||
NvMediaStatus
|
||||
ConfigParser_ParseFile(ConfigParamsMap *paramsMap, unsigned int numParams, SectionMap *sectionsMap, char *fileName)
|
||||
{
|
||||
char *items[MAX_ITEMS_TO_PARSE] = {NULL};
|
||||
int intValue, itemsCount = 0, i = 0, sectionIndex = 0;
|
||||
double doubleValue;
|
||||
float floatValue;
|
||||
unsigned int currItemIndex, uintValue, sectionId = 0, currSectionId = 0, charValue, paramDefaultLength;
|
||||
unsigned short ushortValue;
|
||||
short shortValue;
|
||||
char *items[MAX_ITEMS_TO_PARSE] = {NULL};
|
||||
int intValue, itemsCount = 0, i = 0, sectionIndex = 0;
|
||||
double doubleValue;
|
||||
float floatValue;
|
||||
unsigned int currItemIndex, uintValue, sectionId = 0, currSectionId = 0, charValue, paramDefaultLength;
|
||||
unsigned short ushortValue;
|
||||
short shortValue;
|
||||
unsigned long long ullValue;
|
||||
NvMediaBool isInString = NVMEDIA_FALSE, isInItem = NVMEDIA_FALSE;
|
||||
char *buffer, *bufferEnd, *param, *pParamLength;
|
||||
char sectionName[100];
|
||||
char currDigit;
|
||||
char *configContentBuf = NULL;
|
||||
unsigned int numSetsInSection = 0;
|
||||
NvMediaBool isInString = NVMEDIA_FALSE, isInItem = NVMEDIA_FALSE;
|
||||
char *buffer, *bufferEnd, *param, *pParamLength;
|
||||
char sectionName[100];
|
||||
char currDigit;
|
||||
char *configContentBuf = NULL;
|
||||
unsigned int numSetsInSection = 0;
|
||||
|
||||
if(GetFileContent(fileName, &configContentBuf) != NVMEDIA_STATUS_OK) {
|
||||
if (GetFileContent(fileName, &configContentBuf) != NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_ParseFile: Failed reading file %s", fileName);
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
buffer = configContentBuf;
|
||||
buffer = configContentBuf;
|
||||
bufferEnd = &configContentBuf[strlen(configContentBuf)];
|
||||
|
||||
// Stage one: Create items mapping in the content using "items" pointers array. For each parameter we have 3 items: param name, '=' char and the param value.
|
||||
while(buffer < bufferEnd) {
|
||||
if(itemsCount >= MAX_ITEMS_TO_PARSE) {
|
||||
LOG_WARN("ConfigParser_ParseFile: Number of items in configuration file exceeded the maximum allowed (%d). Only %d items will be parsed.\n",
|
||||
MAX_ITEMS_TO_PARSE, MAX_ITEMS_TO_PARSE);
|
||||
// Stage one: Create items mapping in the content using "items" pointers array. For each parameter we have 3 items:
|
||||
// param name, '=' char and the param value.
|
||||
while (buffer < bufferEnd) {
|
||||
if (itemsCount >= MAX_ITEMS_TO_PARSE) {
|
||||
LOG_WARN("ConfigParser_ParseFile: Number of items in configuration file exceeded the maximum allowed (%d). "
|
||||
"Only %d items will be parsed.\n",
|
||||
MAX_ITEMS_TO_PARSE,
|
||||
MAX_ITEMS_TO_PARSE);
|
||||
itemsCount = MAX_ITEMS_TO_PARSE;
|
||||
break;
|
||||
}
|
||||
switch(*buffer) {
|
||||
// Carriage return
|
||||
case 13:
|
||||
switch (*buffer) {
|
||||
// Carriage return
|
||||
case 13:
|
||||
++buffer;
|
||||
break;
|
||||
case '#':
|
||||
*buffer = '\0'; // Replace '#' with '\0' in case of comment immediately following integer or string
|
||||
while (*buffer != '\n' && buffer < bufferEnd) { // Skip till EOL or EOF
|
||||
++buffer;
|
||||
break;
|
||||
case '#':
|
||||
*buffer = '\0'; // Replace '#' with '\0' in case of comment immediately following integer or string
|
||||
while(*buffer != '\n' && buffer < bufferEnd) { // Skip till EOL or EOF
|
||||
++buffer;
|
||||
}
|
||||
isInString = NVMEDIA_FALSE;
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
break;
|
||||
case '\n':
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
isInString = NVMEDIA_FALSE;
|
||||
*buffer++='\0';
|
||||
break;
|
||||
case ' ':
|
||||
case '\t': // Skip whitespace, leave state unchanged
|
||||
if(isInString)
|
||||
buffer++;
|
||||
else { // Terminate non-strings once whitespace is found
|
||||
*buffer++ = '\0';
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
}
|
||||
break;
|
||||
case '"': // Begin/End of String
|
||||
*buffer++ = '\0';
|
||||
if(!isInString) {
|
||||
items[itemsCount++] = buffer;
|
||||
isInItem = ~isInItem;
|
||||
} else {
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
}
|
||||
isInString = ~isInString; // Toggle
|
||||
break;
|
||||
case '[':
|
||||
*(buffer++) = '\0';
|
||||
items[itemsCount++] = buffer;
|
||||
while(*buffer != ' ' && *buffer != '\n' && buffer < bufferEnd) { // Skip till whitespace (after which is located the parsed section number) or EOL or EOF
|
||||
sectionName[i++] = *(buffer++);
|
||||
}
|
||||
sectionName[i] = '\0';
|
||||
i = 0;
|
||||
while(*buffer == ' ') {
|
||||
*(buffer++) = '\0';
|
||||
}
|
||||
items[itemsCount++] = buffer;
|
||||
while(*buffer != ']' && *buffer != '\n' && buffer < bufferEnd) { // Read the section number
|
||||
currDigit = *buffer;
|
||||
sectionIndex = sectionIndex * 10 + (currDigit - '0');
|
||||
buffer++;
|
||||
}
|
||||
*(buffer++) = '\0';
|
||||
sectionIndex--;
|
||||
if(ConfigParser_GetSectionIndexByName(sectionsMap, sectionName, §ionId) != NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_ParseFile: SectionName couldn't be found in section map: '%s'.\n", sectionName);
|
||||
}
|
||||
numSetsInSection++;
|
||||
sectionsMap[sectionId].lastSectionIndex = sectionIndex;
|
||||
sectionIndex = 0;
|
||||
isInString = NVMEDIA_FALSE;
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
break;
|
||||
default:
|
||||
if(!isInItem) {
|
||||
items[itemsCount++] = buffer;
|
||||
isInItem = ~isInItem;
|
||||
}
|
||||
}
|
||||
isInString = NVMEDIA_FALSE;
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
break;
|
||||
case '\n':
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
isInString = NVMEDIA_FALSE;
|
||||
*buffer++ = '\0';
|
||||
break;
|
||||
case ' ':
|
||||
case '\t': // Skip whitespace, leave state unchanged
|
||||
if (isInString)
|
||||
buffer++;
|
||||
else { // Terminate non-strings once whitespace is found
|
||||
*buffer++ = '\0';
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
}
|
||||
break;
|
||||
case '"': // Begin/End of String
|
||||
*buffer++ = '\0';
|
||||
if (!isInString) {
|
||||
items[itemsCount++] = buffer;
|
||||
isInItem = ~isInItem;
|
||||
}
|
||||
else {
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
}
|
||||
isInString = ~isInString; // Toggle
|
||||
break;
|
||||
case '[':
|
||||
*(buffer++) = '\0';
|
||||
items[itemsCount++] = buffer;
|
||||
while (*buffer != ' ' && *buffer != '\n'
|
||||
&& buffer < bufferEnd) { // Skip till whitespace (after which is located the parsed section number)
|
||||
// or EOL or EOF
|
||||
sectionName[i++] = *(buffer++);
|
||||
}
|
||||
sectionName[i] = '\0';
|
||||
i = 0;
|
||||
while (*buffer == ' ') {
|
||||
*(buffer++) = '\0';
|
||||
}
|
||||
items[itemsCount++] = buffer;
|
||||
while (*buffer != ']' && *buffer != '\n' && buffer < bufferEnd) { // Read the section number
|
||||
currDigit = *buffer;
|
||||
sectionIndex = sectionIndex * 10 + (currDigit - '0');
|
||||
buffer++;
|
||||
}
|
||||
*(buffer++) = '\0';
|
||||
sectionIndex--;
|
||||
if (ConfigParser_GetSectionIndexByName(sectionsMap, sectionName, §ionId) != NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_ParseFile: SectionName couldn't be found in section map: '%s'.\n", sectionName);
|
||||
}
|
||||
numSetsInSection++;
|
||||
sectionsMap[sectionId].lastSectionIndex = sectionIndex;
|
||||
sectionIndex = 0;
|
||||
isInString = NVMEDIA_FALSE;
|
||||
isInItem = NVMEDIA_FALSE;
|
||||
break;
|
||||
default:
|
||||
if (!isInItem) {
|
||||
items[itemsCount++] = buffer;
|
||||
isInItem = ~isInItem;
|
||||
}
|
||||
buffer++;
|
||||
}
|
||||
}
|
||||
|
||||
itemsCount--;
|
||||
|
||||
if(numSetsInSection > numParams) {
|
||||
printf("%s: Not enough buffers allocated for parsing. Number of sets allocated: %d. Number of sets in config file: %d \n",
|
||||
__func__, numParams, numSetsInSection);
|
||||
if(configContentBuf) {
|
||||
if (numSetsInSection > numParams) {
|
||||
printf("%s: Not enough buffers allocated for parsing. Number of sets allocated: %d. Number of sets in config "
|
||||
"file: %d \n",
|
||||
__func__,
|
||||
numParams,
|
||||
numSetsInSection);
|
||||
if (configContentBuf) {
|
||||
free(configContentBuf);
|
||||
}
|
||||
return NVMEDIA_STATUS_ERROR;
|
||||
}
|
||||
|
||||
// Stage 2: Go through the list of items and save their values in parameters map
|
||||
for(i = 0; i < itemsCount; i += 3) {
|
||||
if(ConfigParser_GetSectionIndexByName(sectionsMap, items[i], &currItemIndex) == NVMEDIA_STATUS_OK) {
|
||||
for (i = 0; i < itemsCount; i += 3) {
|
||||
if (ConfigParser_GetSectionIndexByName(sectionsMap, items[i], &currItemIndex) == NVMEDIA_STATUS_OK) {
|
||||
currSectionId = atoi(items[i + 1]);
|
||||
currSectionId--;
|
||||
LOG_DBG("ConfigParser_ParseFile: Parsing section %s index %d\n", items[i], currSectionId);
|
||||
@@ -253,105 +267,130 @@ NvMediaStatus ConfigParser_ParseFile(ConfigParamsMap *paramsMap, unsigned int nu
|
||||
continue;
|
||||
}
|
||||
|
||||
if(GetParamIndex(paramsMap, items[i], &currItemIndex) != NVMEDIA_STATUS_OK) {
|
||||
LOG_WARN("ConfigParser_ParseFile: Parameter Name '%s' is not recognized. Dismissing this parameter.\n", items[i]);
|
||||
if (GetParamIndex(paramsMap, items[i], &currItemIndex) != NVMEDIA_STATUS_OK) {
|
||||
LOG_WARN("ConfigParser_ParseFile: Parameter Name '%s' is not recognized. Dismissing this parameter.\n",
|
||||
items[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(strcmp("=", items[i + 1])) {
|
||||
printf("ConfigParser_ParseFile: '=' expected as the second token in each line. Error caught while parsing parameter '%s'.\n", items[i]);
|
||||
if (strcmp("=", items[i + 1])) {
|
||||
printf("ConfigParser_ParseFile: '=' expected as the second token in each line. Error caught while parsing "
|
||||
"parameter '%s'.\n",
|
||||
items[i]);
|
||||
i -= 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ConfigParser_GetSectionIndexByType(sectionsMap, paramsMap[currItemIndex].sectionType, §ionId) != NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_ParseFile: Section index couldn't be found in section map by type. Param Name: '%s'.\n", paramsMap[currItemIndex].paramName);
|
||||
if (ConfigParser_GetSectionIndexByType(sectionsMap, paramsMap[currItemIndex].sectionType, §ionId)
|
||||
!= NVMEDIA_STATUS_OK) {
|
||||
printf(
|
||||
"ConfigParser_ParseFile: Section index couldn't be found in section map by type. Param Name: '%s'.\n",
|
||||
paramsMap[currItemIndex].paramName);
|
||||
}
|
||||
|
||||
if(sectionsMap[sectionId].lastSectionIndex == 0) {
|
||||
if (sectionsMap[sectionId].lastSectionIndex == 0) {
|
||||
// Param is not part of a collection or collection includes only one item
|
||||
currSectionId = 0;
|
||||
}
|
||||
|
||||
param = (char *)paramsMap[currItemIndex].mappedLocation + currSectionId * sectionsMap[sectionId].sizeOfStruct;
|
||||
pParamLength = (char *)paramsMap[currItemIndex].stringLengthAddr + currSectionId * sectionsMap[sectionId].sizeOfStruct;
|
||||
pParamLength =
|
||||
(char *)paramsMap[currItemIndex].stringLengthAddr + currSectionId * sectionsMap[sectionId].sizeOfStruct;
|
||||
paramDefaultLength = paramsMap[currItemIndex].stringLength;
|
||||
|
||||
// Interpret the Value
|
||||
LOG_DBG("ConfigParser_ParseFile: Interpreting parameter %s\n", items[i]);
|
||||
switch(paramsMap[currItemIndex].type) {
|
||||
case TYPE_INT:
|
||||
if(sscanf(items[i + 2], "%d", &intValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected numerical value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(int *)(void *)param = intValue;
|
||||
break;
|
||||
case TYPE_UINT:
|
||||
if(sscanf(items[i + 2], "%u", &uintValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected numerical value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(unsigned int *)(void *)param = uintValue;
|
||||
break;
|
||||
case TYPE_UINT_HEX:
|
||||
if(sscanf(items[i + 2], "%x", &uintValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected unsigned char value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(unsigned int *)(void *)param = uintValue;
|
||||
break;
|
||||
case TYPE_CHAR_ARR:
|
||||
if(items[i + 2] == NULL)
|
||||
memset(param, 0, (pParamLength != NULL && *pParamLength != 0) ? *pParamLength : paramDefaultLength);
|
||||
else {
|
||||
strncpy(param, items[i + 2], paramsMap[currItemIndex].stringLength);
|
||||
param[strlen(items[i + 2])] = '\0';
|
||||
}
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
if(sscanf(items[i + 2], "%lf", &doubleValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected double value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(double *)(void *)param = doubleValue;
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
if(sscanf(items[i + 2], "%f", &floatValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected double value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(float *)(void *)param = floatValue;
|
||||
break;
|
||||
case TYPE_UCHAR:
|
||||
if(sscanf(items[i + 2], "%u", &charValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected unsigned char value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(unsigned char *)(void *)param = charValue;
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
if(sscanf(items[i + 2], "%hu", &ushortValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected unsigned short value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(unsigned short *)(void *)param = ushortValue;
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
if(sscanf(items[i + 2], "%hd", &shortValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected short value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(short *)(void *)param = shortValue;
|
||||
break;
|
||||
case TYPE_UCHAR_ARR:
|
||||
if(items[i + 2] == NULL)
|
||||
memset(param, 0, (pParamLength != NULL && *pParamLength != 0) ? *pParamLength : paramDefaultLength);
|
||||
else {
|
||||
strncpy(param, items[i + 2], paramsMap[currItemIndex].stringLength);
|
||||
param[strlen(items[i + 2])] = '\0';
|
||||
}
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
if(sscanf(items[i + 2], "%llu", &ullValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected numerical value for Parameter %s, found value '%s'\n", items[i], items[i + 2]);
|
||||
}
|
||||
*(unsigned long long *)(void *)param = ullValue;
|
||||
break;
|
||||
default:
|
||||
printf("ConfigParser_ParseFile: Encountered unknown value type in the map\n");
|
||||
switch (paramsMap[currItemIndex].type) {
|
||||
case TYPE_INT:
|
||||
if (sscanf(items[i + 2], "%d", &intValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected numerical value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(int *)(void *)param = intValue;
|
||||
break;
|
||||
case TYPE_UINT:
|
||||
if (sscanf(items[i + 2], "%u", &uintValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected numerical value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(unsigned int *)(void *)param = uintValue;
|
||||
break;
|
||||
case TYPE_UINT_HEX:
|
||||
if (sscanf(items[i + 2], "%x", &uintValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected unsigned char value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(unsigned int *)(void *)param = uintValue;
|
||||
break;
|
||||
case TYPE_CHAR_ARR:
|
||||
if (items[i + 2] == NULL)
|
||||
memset(param, 0, (pParamLength != NULL && *pParamLength != 0) ? *pParamLength : paramDefaultLength);
|
||||
else {
|
||||
strncpy(param, items[i + 2], paramsMap[currItemIndex].stringLength);
|
||||
param[strlen(items[i + 2])] = '\0';
|
||||
}
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
if (sscanf(items[i + 2], "%lf", &doubleValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected double value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(double *)(void *)param = doubleValue;
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
if (sscanf(items[i + 2], "%f", &floatValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected double value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(float *)(void *)param = floatValue;
|
||||
break;
|
||||
case TYPE_UCHAR:
|
||||
if (sscanf(items[i + 2], "%u", &charValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected unsigned char value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(unsigned char *)(void *)param = charValue;
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
if (sscanf(items[i + 2], "%hu", &ushortValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected unsigned short value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(unsigned short *)(void *)param = ushortValue;
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
if (sscanf(items[i + 2], "%hd", &shortValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected short value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(short *)(void *)param = shortValue;
|
||||
break;
|
||||
case TYPE_UCHAR_ARR:
|
||||
if (items[i + 2] == NULL)
|
||||
memset(param, 0, (pParamLength != NULL && *pParamLength != 0) ? *pParamLength : paramDefaultLength);
|
||||
else {
|
||||
strncpy(param, items[i + 2], paramsMap[currItemIndex].stringLength);
|
||||
param[strlen(items[i + 2])] = '\0';
|
||||
}
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
if (sscanf(items[i + 2], "%llu", &ullValue) != 1) {
|
||||
printf("ConfigParser_ParseFile: Expected numerical value for Parameter %s, found value '%s'\n",
|
||||
items[i],
|
||||
items[i + 2]);
|
||||
}
|
||||
*(unsigned long long *)(void *)param = ullValue;
|
||||
break;
|
||||
default:
|
||||
printf("ConfigParser_ParseFile: Encountered unknown value type in the map\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,42 +404,42 @@ NvMediaStatus ConfigParser_InitParamsMap(ConfigParamsMap *paramsMap)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while(paramsMap[i].paramName != NULL) {
|
||||
while (paramsMap[i].paramName != NULL) {
|
||||
if (paramsMap[i].mappedLocation == NULL) {
|
||||
i++;
|
||||
continue;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(paramsMap[i].type) {
|
||||
case TYPE_UINT:
|
||||
case TYPE_UINT_HEX:
|
||||
*(unsigned int *)(paramsMap[i].mappedLocation) = (unsigned int)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_INT:
|
||||
*(int *)(paramsMap[i].mappedLocation) = (int)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
*(double *)(paramsMap[i].mappedLocation) = (double)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
*(float *)(paramsMap[i].mappedLocation) = (float)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_UCHAR:
|
||||
*(unsigned char *)(paramsMap[i].mappedLocation) = (NvMediaBool)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
*(unsigned short *)(paramsMap[i].mappedLocation) = (unsigned short)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
*(short *)(paramsMap[i].mappedLocation) = (short)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
*(unsigned long long *)(paramsMap[i].mappedLocation) = (unsigned long long)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_CHAR_ARR:
|
||||
case TYPE_UCHAR_ARR:
|
||||
default:
|
||||
break;
|
||||
switch (paramsMap[i].type) {
|
||||
case TYPE_UINT:
|
||||
case TYPE_UINT_HEX:
|
||||
*(unsigned int *)(paramsMap[i].mappedLocation) = (unsigned int)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_INT:
|
||||
*(int *)(paramsMap[i].mappedLocation) = (int)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
*(double *)(paramsMap[i].mappedLocation) = (double)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
*(float *)(paramsMap[i].mappedLocation) = (float)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_UCHAR:
|
||||
*(unsigned char *)(paramsMap[i].mappedLocation) = (NvMediaBool)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
*(unsigned short *)(paramsMap[i].mappedLocation) = (unsigned short)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
*(short *)(paramsMap[i].mappedLocation) = (short)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
*(unsigned long long *)(paramsMap[i].mappedLocation) = (unsigned long long)paramsMap[i].defaultValue;
|
||||
break;
|
||||
case TYPE_CHAR_ARR:
|
||||
case TYPE_UCHAR_ARR:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -410,82 +449,88 @@ NvMediaStatus ConfigParser_InitParamsMap(ConfigParamsMap *paramsMap)
|
||||
|
||||
NvMediaStatus ConfigParser_ValidateParams(ConfigParamsMap *paramsMap, SectionMap *sectionsMap)
|
||||
{
|
||||
NvMediaStatus status = NVMEDIA_STATUS_OK;
|
||||
unsigned int sectionId = 0, i = 0, j;
|
||||
char *param;
|
||||
NvMediaStatus status = NVMEDIA_STATUS_OK;
|
||||
unsigned int sectionId = 0, i = 0, j;
|
||||
char *param;
|
||||
|
||||
while(paramsMap[i].paramName != NULL) {
|
||||
if(ConfigParser_GetSectionIndexByType(sectionsMap, paramsMap[i].sectionType, §ionId) != NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_ValidateParams: Section index couldn't be found in section map. Param Name: '%s'.\n", paramsMap[i].paramName);
|
||||
while (paramsMap[i].paramName != NULL) {
|
||||
if (ConfigParser_GetSectionIndexByType(sectionsMap, paramsMap[i].sectionType, §ionId)
|
||||
!= NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_ValidateParams: Section index couldn't be found in section map. Param Name: '%s'.\n",
|
||||
paramsMap[i].paramName);
|
||||
}
|
||||
|
||||
for(j = 0; j <= sectionsMap[sectionId].lastSectionIndex; j++) {
|
||||
if(paramsMap[i].paramLimits == 1 || paramsMap[i].paramLimits == 2) {
|
||||
for (j = 0; j <= sectionsMap[sectionId].lastSectionIndex; j++) {
|
||||
if (paramsMap[i].paramLimits == 1 || paramsMap[i].paramLimits == 2) {
|
||||
param = (char *)paramsMap[i].mappedLocation + j * sectionsMap[sectionId].sizeOfStruct;
|
||||
if (param == NULL) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
switch (paramsMap[i].type) {
|
||||
case TYPE_UINT:
|
||||
case TYPE_UINT_HEX:
|
||||
if(*(unsigned int *)(void *)param < (unsigned int)paramsMap[i].minLimit ||
|
||||
(paramsMap[i].paramLimits == 2 && *(unsigned int *)(void *)param > (unsigned int)paramsMap[i].maxLimit )) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
if(*(double *)(void *)param < (double)paramsMap[i].minLimit ||
|
||||
(paramsMap[i].paramLimits == 2 && *(double *)(void *)param > (double)paramsMap[i].maxLimit )) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
if(*(float *)(void *)param < (float)paramsMap[i].minLimit ||
|
||||
(paramsMap[i].paramLimits == 2 && *(float *)(void *)param > (float)paramsMap[i].maxLimit )) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_INT:
|
||||
if(*(int *)(void *)param < (int)paramsMap[i].minLimit ||
|
||||
(paramsMap[i].paramLimits == 2 && *(int *)(void *)param > (int)paramsMap[i].maxLimit )) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
if(*(unsigned short *)(void *)param < (unsigned short)paramsMap[i].minLimit ||
|
||||
(paramsMap[i].paramLimits == 2 && *(unsigned short *)(void *)param > (unsigned short)paramsMap[i].maxLimit )) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
if(*(short *)(void *)param < (short)paramsMap[i].minLimit ||
|
||||
(paramsMap[i].paramLimits == 2 && *(short *)(void *)param > (short)paramsMap[i].maxLimit )) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
if(*(unsigned long long *)(void *)param < (unsigned long long)paramsMap[i].minLimit ||
|
||||
(paramsMap[i].paramLimits == 2 && *(unsigned long long *)(void *)param > (unsigned long long)paramsMap[i].maxLimit )) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case TYPE_UINT:
|
||||
case TYPE_UINT_HEX:
|
||||
if (*(unsigned int *)(void *)param < (unsigned int)paramsMap[i].minLimit
|
||||
|| (paramsMap[i].paramLimits == 2
|
||||
&& *(unsigned int *)(void *)param > (unsigned int)paramsMap[i].maxLimit)) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
if (*(double *)(void *)param < (double)paramsMap[i].minLimit
|
||||
|| (paramsMap[i].paramLimits == 2
|
||||
&& *(double *)(void *)param > (double)paramsMap[i].maxLimit)) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
if (*(float *)(void *)param < (float)paramsMap[i].minLimit
|
||||
|| (paramsMap[i].paramLimits == 2 && *(float *)(void *)param > (float)paramsMap[i].maxLimit)) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_INT:
|
||||
if (*(int *)(void *)param < (int)paramsMap[i].minLimit
|
||||
|| (paramsMap[i].paramLimits == 2 && *(int *)(void *)param > (int)paramsMap[i].maxLimit)) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
if (*(unsigned short *)(void *)param < (unsigned short)paramsMap[i].minLimit
|
||||
|| (paramsMap[i].paramLimits == 2
|
||||
&& *(unsigned short *)(void *)param > (unsigned short)paramsMap[i].maxLimit)) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
if (*(short *)(void *)param < (short)paramsMap[i].minLimit
|
||||
|| (paramsMap[i].paramLimits == 2 && *(short *)(void *)param > (short)paramsMap[i].maxLimit)) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
if (*(unsigned long long *)(void *)param < (unsigned long long)paramsMap[i].minLimit
|
||||
|| (paramsMap[i].paramLimits == 2
|
||||
&& *(unsigned long long *)(void *)param > (unsigned long long)paramsMap[i].maxLimit)) {
|
||||
printf("ConfigParser_ValidateParams: Error in input parameter %s\n", paramsMap[i].paramName);
|
||||
printf("Check configuration file for parameter limits\n");
|
||||
status = NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,57 +543,70 @@ NvMediaStatus ConfigParser_ValidateParams(ConfigParamsMap *paramsMap, SectionMap
|
||||
NvMediaStatus ConfigParser_DisplayParams(ConfigParamsMap *pParamsMap, SectionMap *pSectionsMap)
|
||||
{
|
||||
unsigned int i = 0, j, sectionId = 0;
|
||||
char *param;
|
||||
char *param;
|
||||
|
||||
while(pParamsMap[i].paramName != NULL) {
|
||||
if(ConfigParser_GetSectionIndexByType(pSectionsMap, pParamsMap[i].sectionType, §ionId) != NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_DisplayParams: Section index couldn't be found in section map by type. Param Name: '%s'.\n", pParamsMap[i].paramName);
|
||||
while (pParamsMap[i].paramName != NULL) {
|
||||
if (ConfigParser_GetSectionIndexByType(pSectionsMap, pParamsMap[i].sectionType, §ionId)
|
||||
!= NVMEDIA_STATUS_OK) {
|
||||
printf("ConfigParser_DisplayParams: Section index couldn't be found in section map by type. Param Name: "
|
||||
"'%s'.\n",
|
||||
pParamsMap[i].paramName);
|
||||
}
|
||||
|
||||
for(j = 0; j <= pSectionsMap[sectionId].lastSectionIndex; j++) {
|
||||
for (j = 0; j <= pSectionsMap[sectionId].lastSectionIndex; j++) {
|
||||
param = (char *)pParamsMap[i].mappedLocation + j * pSectionsMap[sectionId].sizeOfStruct;
|
||||
if (param == NULL) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(pParamsMap[i].type) {
|
||||
case TYPE_UINT:
|
||||
printf("(%d) %s = %u\n", j, pParamsMap[i].paramName, *(unsigned int *)(void *)param);
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
printf("(%d) %s = %.2lf\n", j, pParamsMap[i].paramName, *(double *)(void *)param);
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
printf("(%d) %s = %.2f\n", j, pParamsMap[i].paramName, *(float *)(void *)param);
|
||||
break;
|
||||
case TYPE_UCHAR:
|
||||
printf("(%d) %s = %d\n", j, pParamsMap[i].paramName, *(unsigned char *)(void *)param);
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
printf("(%d) %s = %hu\n", j, pParamsMap[i].paramName, *(unsigned short *)(void *)param);
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
printf("(%d) %s = %hd\n", j, pParamsMap[i].paramName, *(short *)(void *)param);
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
printf("(%d) %s = %llu\n", j, pParamsMap[i].paramName, *(unsigned long long *)(void *)param);
|
||||
break;
|
||||
case TYPE_CHAR_ARR:
|
||||
printf("(%d) %s = ""%s""\n", j, pParamsMap[i].paramName, param);
|
||||
break;
|
||||
case TYPE_UCHAR_ARR:
|
||||
printf("(%d) %s = ""%s""\n", j, pParamsMap[i].paramName, (unsigned char *)(void *)param);
|
||||
break;
|
||||
case TYPE_INT:
|
||||
printf("(%d) %s = %d\n", j, pParamsMap[i].paramName, *(int *)(void *)param);
|
||||
break;
|
||||
case TYPE_UINT_HEX:
|
||||
printf("(%d) %s = %x\n", j, pParamsMap[i].paramName, *(unsigned int *)(void *)param);
|
||||
break;
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
switch (pParamsMap[i].type) {
|
||||
case TYPE_UINT:
|
||||
printf("(%d) %s = %u\n", j, pParamsMap[i].paramName, *(unsigned int *)(void *)param);
|
||||
break;
|
||||
case TYPE_DOUBLE:
|
||||
printf("(%d) %s = %.2lf\n", j, pParamsMap[i].paramName, *(double *)(void *)param);
|
||||
break;
|
||||
case TYPE_FLOAT:
|
||||
printf("(%d) %s = %.2f\n", j, pParamsMap[i].paramName, *(float *)(void *)param);
|
||||
break;
|
||||
case TYPE_UCHAR:
|
||||
printf("(%d) %s = %d\n", j, pParamsMap[i].paramName, *(unsigned char *)(void *)param);
|
||||
break;
|
||||
case TYPE_USHORT:
|
||||
printf("(%d) %s = %hu\n", j, pParamsMap[i].paramName, *(unsigned short *)(void *)param);
|
||||
break;
|
||||
case TYPE_SHORT:
|
||||
printf("(%d) %s = %hd\n", j, pParamsMap[i].paramName, *(short *)(void *)param);
|
||||
break;
|
||||
case TYPE_ULLONG:
|
||||
printf("(%d) %s = %llu\n", j, pParamsMap[i].paramName, *(unsigned long long *)(void *)param);
|
||||
break;
|
||||
case TYPE_CHAR_ARR:
|
||||
printf("(%d) %s = "
|
||||
"%s"
|
||||
"\n",
|
||||
j,
|
||||
pParamsMap[i].paramName,
|
||||
param);
|
||||
break;
|
||||
case TYPE_UCHAR_ARR:
|
||||
printf("(%d) %s = "
|
||||
"%s"
|
||||
"\n",
|
||||
j,
|
||||
pParamsMap[i].paramName,
|
||||
(unsigned char *)(void *)param);
|
||||
break;
|
||||
case TYPE_INT:
|
||||
printf("(%d) %s = %d\n", j, pParamsMap[i].paramName, *(int *)(void *)param);
|
||||
break;
|
||||
case TYPE_UINT_HEX:
|
||||
printf("(%d) %s = %x\n", j, pParamsMap[i].paramName, *(unsigned int *)(void *)param);
|
||||
break;
|
||||
default:
|
||||
// Do nothing
|
||||
break;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
|
||||
@@ -29,7 +29,8 @@
|
||||
#define _NVMEDIA_TEST_CONFIG_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
@@ -42,65 +43,65 @@ extern "C" {
|
||||
|
||||
#define MAX_ITEMS_TO_PARSE 10000
|
||||
|
||||
typedef enum _ParamType {
|
||||
TYPE_UINT = 0,
|
||||
TYPE_UINT_HEX,
|
||||
TYPE_INT,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_FLOAT,
|
||||
TYPE_UCHAR,
|
||||
TYPE_ULLONG,
|
||||
TYPE_USHORT,
|
||||
TYPE_CHAR_ARR,
|
||||
TYPE_UCHAR_ARR,
|
||||
TYPE_SHORT
|
||||
} ParamType;
|
||||
typedef enum _ParamType {
|
||||
TYPE_UINT = 0,
|
||||
TYPE_UINT_HEX,
|
||||
TYPE_INT,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_FLOAT,
|
||||
TYPE_UCHAR,
|
||||
TYPE_ULLONG,
|
||||
TYPE_USHORT,
|
||||
TYPE_CHAR_ARR,
|
||||
TYPE_UCHAR_ARR,
|
||||
TYPE_SHORT
|
||||
} ParamType;
|
||||
|
||||
typedef enum {
|
||||
LIMITS_NONE = 0,
|
||||
LIMITS_MIN = 1,
|
||||
LIMITS_BOTH = 2
|
||||
} LimitsType;
|
||||
typedef enum { LIMITS_NONE = 0, LIMITS_MIN = 1, LIMITS_BOTH = 2 } LimitsType;
|
||||
|
||||
typedef enum {
|
||||
SECTION_NONE,
|
||||
SECTION_CAPTURE,
|
||||
SECTION_QP,
|
||||
SECTION_RC,
|
||||
SECTION_ENCODE_PIC,
|
||||
SECTION_ENCODE_PIC_H264,
|
||||
SECTION_ENCODE_PIC_H265,
|
||||
SECTION_MVC,
|
||||
SECTION_PAYLOAD,
|
||||
SECTION_2DPROCESSOR
|
||||
} SectionType;
|
||||
typedef enum {
|
||||
SECTION_NONE,
|
||||
SECTION_CAPTURE,
|
||||
SECTION_QP,
|
||||
SECTION_RC,
|
||||
SECTION_ENCODE_PIC,
|
||||
SECTION_ENCODE_PIC_H264,
|
||||
SECTION_ENCODE_PIC_H265,
|
||||
SECTION_MVC,
|
||||
SECTION_PAYLOAD,
|
||||
SECTION_2DPROCESSOR
|
||||
} SectionType;
|
||||
|
||||
typedef struct {
|
||||
SectionType secType;
|
||||
const char *name;
|
||||
unsigned int lastSectionIndex;
|
||||
size_t sizeOfStruct;
|
||||
} SectionMap;
|
||||
typedef struct
|
||||
{
|
||||
SectionType secType;
|
||||
const char *name;
|
||||
unsigned int lastSectionIndex;
|
||||
size_t sizeOfStruct;
|
||||
} SectionMap;
|
||||
|
||||
typedef struct {
|
||||
const char *paramName;
|
||||
void *mappedLocation;
|
||||
ParamType type;
|
||||
double defaultValue;
|
||||
LimitsType paramLimits;
|
||||
double minLimit;
|
||||
double maxLimit;
|
||||
unsigned int stringLength; // string param size
|
||||
unsigned int *stringLengthAddr; // address of string param size
|
||||
SectionType sectionType;
|
||||
} ConfigParamsMap;
|
||||
typedef struct
|
||||
{
|
||||
const char *paramName;
|
||||
void *mappedLocation;
|
||||
ParamType type;
|
||||
double defaultValue;
|
||||
LimitsType paramLimits;
|
||||
double minLimit;
|
||||
double maxLimit;
|
||||
unsigned int stringLength; // string param size
|
||||
unsigned int *stringLengthAddr; // address of string param size
|
||||
SectionType sectionType;
|
||||
} ConfigParamsMap;
|
||||
|
||||
NvMediaStatus ConfigParser_InitParamsMap(ConfigParamsMap *paramsMap);
|
||||
NvMediaStatus ConfigParser_ParseFile(ConfigParamsMap *paramsMap, unsigned int numParams, SectionMap *sectionsMap, char *file);
|
||||
NvMediaStatus ConfigParser_ValidateParams(ConfigParamsMap *paramsMap, SectionMap *sectionsMap);
|
||||
NvMediaStatus ConfigParser_DisplayParams(ConfigParamsMap *paramsMap, SectionMap *sectionsMap);
|
||||
NvMediaStatus ConfigParser_GetSectionIndexByName(SectionMap *sectionsMap, char *sectionName, unsigned int *index);
|
||||
NvMediaStatus ConfigParser_GetSectionIndexByType(SectionMap *sectionsMap, SectionType sectionType, unsigned int *index);
|
||||
NvMediaStatus ConfigParser_InitParamsMap(ConfigParamsMap *paramsMap);
|
||||
NvMediaStatus
|
||||
ConfigParser_ParseFile(ConfigParamsMap *paramsMap, unsigned int numParams, SectionMap *sectionsMap, char *file);
|
||||
NvMediaStatus ConfigParser_ValidateParams(ConfigParamsMap *paramsMap, SectionMap *sectionsMap);
|
||||
NvMediaStatus ConfigParser_DisplayParams(ConfigParamsMap *paramsMap, SectionMap *sectionsMap);
|
||||
NvMediaStatus ConfigParser_GetSectionIndexByName(SectionMap *sectionsMap, char *sectionName, unsigned int *index);
|
||||
NvMediaStatus
|
||||
ConfigParser_GetSectionIndexByType(SectionMap *sectionsMap, SectionType sectionType, unsigned int *index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -29,110 +29,96 @@
|
||||
#define _NVMEDIA_TEST_IMAGE_UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "cmdline.h"
|
||||
#include "misc_utils.h"
|
||||
#include "nvmedia_core.h"
|
||||
#include "nvmedia_surface.h"
|
||||
#include "nvmedia_image.h"
|
||||
#include "cmdline.h"
|
||||
#include "nvmedia_surface.h"
|
||||
|
||||
#if (NV_IS_SAFETY == 1)
|
||||
#include "nvmedia_image_internal.h"
|
||||
#endif
|
||||
|
||||
#define PACK_RGBA(R, G, B, A) (((uint32_t)(A) << 24) | ((uint32_t)(B) << 16) | \
|
||||
((uint32_t)(G) << 8) | (uint32_t)(R))
|
||||
#define DEFAULT_ALPHA 0x80
|
||||
#define PACK_RGBA(R, G, B, A) (((uint32_t)(A) << 24) | ((uint32_t)(B) << 16) | ((uint32_t)(G) << 8) | (uint32_t)(R))
|
||||
#define DEFAULT_ALPHA 0x80
|
||||
|
||||
|
||||
// ReadImage
|
||||
//
|
||||
// ReadImage() Read image from file
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// filename
|
||||
// (in) Input file name
|
||||
//
|
||||
// frameNum
|
||||
// (in) Frame number to read. Use for stream input files.
|
||||
//
|
||||
// width
|
||||
// (in) Surface width
|
||||
//
|
||||
// height
|
||||
// (in) Surface height
|
||||
//
|
||||
// image
|
||||
// (out) Pointer to pre-allocated output surface
|
||||
//
|
||||
// uvOrderFlag
|
||||
// (in) Flag for UV order. If true - UV; If false - VU;
|
||||
//
|
||||
// bytesPerPixel
|
||||
// (in) Bytes per pixel. Nedded for RAW image types handling.
|
||||
// RAW8 - 1 byte per pixel
|
||||
// RAW10, RAW12, RAW14 - 2 bytes per pixel
|
||||
//
|
||||
// pixelAlignment
|
||||
// (in) Alignment of bits in pixel.
|
||||
// 0 - LSB Aligned
|
||||
// 1 - MSB Aligned
|
||||
|
||||
NvMediaStatus ReadImage(char *fileName,
|
||||
uint32_t frameNum,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
NvMediaImage *image,
|
||||
NvMediaBool uvOrderFlag,
|
||||
uint32_t bytesPerPixel,
|
||||
uint32_t pixelAlignment);
|
||||
|
||||
// ReadImage
|
||||
//
|
||||
// ReadImage() Read image from file
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// filename
|
||||
// (in) Input file name
|
||||
//
|
||||
// frameNum
|
||||
// (in) Frame number to read. Use for stream input files.
|
||||
//
|
||||
// width
|
||||
// (in) Surface width
|
||||
//
|
||||
// height
|
||||
// (in) Surface height
|
||||
//
|
||||
// image
|
||||
// (out) Pointer to pre-allocated output surface
|
||||
//
|
||||
// uvOrderFlag
|
||||
// (in) Flag for UV order. If true - UV; If false - VU;
|
||||
//
|
||||
// bytesPerPixel
|
||||
// (in) Bytes per pixel. Nedded for RAW image types handling.
|
||||
// RAW8 - 1 byte per pixel
|
||||
// RAW10, RAW12, RAW14 - 2 bytes per pixel
|
||||
//
|
||||
// pixelAlignment
|
||||
// (in) Alignment of bits in pixel.
|
||||
// 0 - LSB Aligned
|
||||
// 1 - MSB Aligned
|
||||
// InitImage
|
||||
//
|
||||
// InitImage() Init image data to zeros
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// image
|
||||
// (in) image to initialize
|
||||
//
|
||||
// width
|
||||
// (in) Surface width
|
||||
//
|
||||
// height
|
||||
// (in) Surface height
|
||||
|
||||
NvMediaStatus
|
||||
ReadImage(
|
||||
char *fileName,
|
||||
uint32_t frameNum,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
NvMediaImage *image,
|
||||
NvMediaBool uvOrderFlag,
|
||||
uint32_t bytesPerPixel,
|
||||
uint32_t pixelAlignment);
|
||||
NvMediaStatus InitImage(NvMediaImage *image, uint32_t width, uint32_t height);
|
||||
|
||||
// InitImage
|
||||
//
|
||||
// InitImage() Init image data to zeros
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// image
|
||||
// (in) image to initialize
|
||||
//
|
||||
// width
|
||||
// (in) Surface width
|
||||
//
|
||||
// height
|
||||
// (in) Surface height
|
||||
NvMediaStatus
|
||||
AllocateBufferToWriteImage(Blit2DTest *ctx, NvMediaImage *image, NvMediaBool uvOrderFlag, NvMediaBool appendFlag);
|
||||
|
||||
NvMediaStatus
|
||||
InitImage(
|
||||
NvMediaImage *image,
|
||||
uint32_t width,
|
||||
uint32_t height);
|
||||
|
||||
NvMediaStatus
|
||||
AllocateBufferToWriteImage(
|
||||
Blit2DTest *ctx,
|
||||
NvMediaImage *image,
|
||||
NvMediaBool uvOrderFlag,
|
||||
NvMediaBool appendFlag);
|
||||
|
||||
// WriteImageToBuffer
|
||||
//
|
||||
// WriteImageToBuffer() Save RGB or YUV image
|
||||
//
|
||||
NvMediaStatus
|
||||
WriteImageToAllocatedBuffer(
|
||||
Blit2DTest *ctx,
|
||||
NvMediaImage *image,
|
||||
NvMediaBool uvOrderFlag,
|
||||
NvMediaBool appendFlag,
|
||||
uint32_t bytesPerPixel);
|
||||
// WriteImageToBuffer
|
||||
//
|
||||
// WriteImageToBuffer() Save RGB or YUV image
|
||||
//
|
||||
NvMediaStatus WriteImageToAllocatedBuffer(Blit2DTest *ctx,
|
||||
NvMediaImage *image,
|
||||
NvMediaBool uvOrderFlag,
|
||||
NvMediaBool appendFlag,
|
||||
uint32_t bytesPerPixel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef NVMEDIA_ANDROID
|
||||
#define LOG_TAG "nvmedia_common"
|
||||
#define LOG_TAG "nvmedia_common"
|
||||
#define LOG_NDEBUG 1
|
||||
#include <utils/Log.h>
|
||||
#endif
|
||||
@@ -48,99 +48,100 @@
|
||||
|
||||
static enum LogLevel msg_level = LEVEL_ERR;
|
||||
static enum LogStyle msg_style = LOG_STYLE_NORMAL;
|
||||
static FILE *msg_file = NULL;
|
||||
static FILE *msg_file = NULL;
|
||||
|
||||
void SetLogLevel(enum LogLevel level)
|
||||
{
|
||||
if (level > LEVEL_DBG)
|
||||
return;
|
||||
if (level > LEVEL_DBG)
|
||||
return;
|
||||
|
||||
msg_level = level;
|
||||
msg_level = level;
|
||||
}
|
||||
|
||||
void SetLogStyle(enum LogStyle style)
|
||||
{
|
||||
if (style > LOG_STYLE_FUNCTION_LINE)
|
||||
return;
|
||||
if (style > LOG_STYLE_FUNCTION_LINE)
|
||||
return;
|
||||
|
||||
msg_style = style;
|
||||
msg_style = style;
|
||||
}
|
||||
|
||||
void SetLogFile(FILE *logFileHandle)
|
||||
{
|
||||
if(!logFileHandle)
|
||||
if (!logFileHandle)
|
||||
return;
|
||||
|
||||
msg_file = logFileHandle;
|
||||
}
|
||||
|
||||
void LogLevelMessage(enum LogLevel level, const char *functionName,
|
||||
int lineNumber, const char *format, ...)
|
||||
void LogLevelMessage(enum LogLevel level, const char *functionName, int lineNumber, const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char str[LOG_BUFFER_BYTES] = {'\0',};
|
||||
char str[LOG_BUFFER_BYTES] = {
|
||||
'\0',
|
||||
};
|
||||
FILE *logFile = msg_file ? msg_file : stdout;
|
||||
|
||||
if (level > msg_level)
|
||||
return;
|
||||
|
||||
#ifndef NVMEDIA_ANDROID
|
||||
/** In the case of Android ADB log, if LOG_TAG is defined,
|
||||
* before 'Log.h' is included in source file,
|
||||
* LOG_TAG is automatically concatenated at the beginning of log message,
|
||||
* so, we don't copy 'nvmedia: ' into 'str'.
|
||||
*/
|
||||
/** In the case of Android ADB log, if LOG_TAG is defined,
|
||||
* before 'Log.h' is included in source file,
|
||||
* LOG_TAG is automatically concatenated at the beginning of log message,
|
||||
* so, we don't copy 'nvmedia: ' into 'str'.
|
||||
*/
|
||||
strcpy(str, "nvmedia: ");
|
||||
|
||||
/** As LOG_TAG is concatednated, log level is also automatically concatenated,
|
||||
* by calling different ADB log function such as ALOGE(for eror log message),
|
||||
* ALOGW(for warning log message).
|
||||
*/
|
||||
/** As LOG_TAG is concatednated, log level is also automatically concatenated,
|
||||
* by calling different ADB log function such as ALOGE(for eror log message),
|
||||
* ALOGW(for warning log message).
|
||||
*/
|
||||
switch (level) {
|
||||
case LEVEL_ERR:
|
||||
strcat(str, "ERROR: ");
|
||||
break;
|
||||
case LEVEL_WARN:
|
||||
strcat(str, "WARNING: ");
|
||||
break;
|
||||
case LEVEL_INFO:
|
||||
case LEVEL_DBG:
|
||||
// Empty
|
||||
break;
|
||||
case LEVEL_ERR:
|
||||
strcat(str, "ERROR: ");
|
||||
break;
|
||||
case LEVEL_WARN:
|
||||
strcat(str, "WARNING: ");
|
||||
break;
|
||||
case LEVEL_INFO:
|
||||
case LEVEL_DBG:
|
||||
// Empty
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
va_start(ap, format);
|
||||
vsnprintf(str + strlen(str), sizeof(str) - strlen(str), format, ap);
|
||||
|
||||
if(msg_style == LOG_STYLE_NORMAL) {
|
||||
if (msg_style == LOG_STYLE_NORMAL) {
|
||||
// Add trailing new line char
|
||||
if(strlen(str) && str[strlen(str) - 1] != '\n')
|
||||
if (strlen(str) && str[strlen(str) - 1] != '\n')
|
||||
strcat(str, "\n");
|
||||
|
||||
} else if(msg_style == LOG_STYLE_FUNCTION_LINE) {
|
||||
}
|
||||
else if (msg_style == LOG_STYLE_FUNCTION_LINE) {
|
||||
// Remove trailing new line char
|
||||
if(strlen(str) && str[strlen(str) - 1] == '\n')
|
||||
if (strlen(str) && str[strlen(str) - 1] == '\n')
|
||||
str[strlen(str) - 1] = 0;
|
||||
|
||||
// Add function and line info
|
||||
snprintf(str + + strlen(str), sizeof(str) - strlen(str), " at %s():%d\n", functionName, lineNumber);
|
||||
snprintf(str + +strlen(str), sizeof(str) - strlen(str), " at %s():%d\n", functionName, lineNumber);
|
||||
}
|
||||
|
||||
#ifdef NVMEDIA_ANDROID
|
||||
switch (msg_level) {
|
||||
case LEVEL_ERR:
|
||||
ALOGE("%s", str);
|
||||
break;
|
||||
case LEVEL_WARN:
|
||||
ALOGW("%s", str);
|
||||
break;
|
||||
case LEVEL_INFO:
|
||||
ALOGI("%s", str);
|
||||
break;
|
||||
case LEVEL_DBG:
|
||||
ALOGD("%s", str);
|
||||
break;
|
||||
case LEVEL_ERR:
|
||||
ALOGE("%s", str);
|
||||
break;
|
||||
case LEVEL_WARN:
|
||||
ALOGW("%s", str);
|
||||
break;
|
||||
case LEVEL_INFO:
|
||||
ALOGI("%s", str);
|
||||
break;
|
||||
case LEVEL_DBG:
|
||||
ALOGD("%s", str);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
fprintf(logFile, "%s", str);
|
||||
@@ -151,4 +152,3 @@ void LogLevelMessage(enum LogLevel level, const char *functionName,
|
||||
#endif
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,90 +29,76 @@
|
||||
#define _NVMEDIA_TEST_LOG_UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum LogLevel {
|
||||
LEVEL_ERR = 0,
|
||||
LEVEL_WARN = 1,
|
||||
LEVEL_INFO = 2,
|
||||
LEVEL_DBG = 3,
|
||||
};
|
||||
enum LogLevel {
|
||||
LEVEL_ERR = 0,
|
||||
LEVEL_WARN = 1,
|
||||
LEVEL_INFO = 2,
|
||||
LEVEL_DBG = 3,
|
||||
};
|
||||
|
||||
enum LogStyle {
|
||||
LOG_STYLE_NORMAL = 0,
|
||||
LOG_STYLE_FUNCTION_LINE
|
||||
};
|
||||
enum LogStyle { LOG_STYLE_NORMAL = 0, LOG_STYLE_FUNCTION_LINE };
|
||||
|
||||
#define LINE_INFO __FUNCTION__, __LINE__
|
||||
#define LOG_DBG(...) LogLevelMessage(LEVEL_DBG, LINE_INFO, __VA_ARGS__)
|
||||
#define LOG_INFO(...) LogLevelMessage(LEVEL_INFO, LINE_INFO, __VA_ARGS__)
|
||||
#define LOG_WARN(...) LogLevelMessage(LEVEL_WARN, LINE_INFO, __VA_ARGS__)
|
||||
#define LINE_INFO __FUNCTION__, __LINE__
|
||||
#define LOG_DBG(...) LogLevelMessage(LEVEL_DBG, LINE_INFO, __VA_ARGS__)
|
||||
#define LOG_INFO(...) LogLevelMessage(LEVEL_INFO, LINE_INFO, __VA_ARGS__)
|
||||
#define LOG_WARN(...) LogLevelMessage(LEVEL_WARN, LINE_INFO, __VA_ARGS__)
|
||||
|
||||
// SetLogLevel
|
||||
//
|
||||
// SetLogLevel() Set logging level
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// level
|
||||
// (in) Logging level
|
||||
// SetLogLevel
|
||||
//
|
||||
// SetLogLevel() Set logging level
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// level
|
||||
// (in) Logging level
|
||||
|
||||
void
|
||||
SetLogLevel(
|
||||
enum LogLevel level);
|
||||
void SetLogLevel(enum LogLevel level);
|
||||
|
||||
// SetLogStyle
|
||||
//
|
||||
// SetLogStyle() Set logging print slyle
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// level
|
||||
// (in) Logging style
|
||||
// SetLogStyle
|
||||
//
|
||||
// SetLogStyle() Set logging print slyle
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// level
|
||||
// (in) Logging style
|
||||
|
||||
void
|
||||
SetLogStyle(
|
||||
enum LogStyle style);
|
||||
void SetLogStyle(enum LogStyle style);
|
||||
|
||||
// SetLogFile
|
||||
//
|
||||
// SetLogFile() Set logging file handle
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// level
|
||||
// (in) Logging file handle
|
||||
// SetLogFile
|
||||
//
|
||||
// SetLogFile() Set logging file handle
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// level
|
||||
// (in) Logging file handle
|
||||
|
||||
void
|
||||
SetLogFile(
|
||||
FILE *logFileHandle);
|
||||
void SetLogFile(FILE *logFileHandle);
|
||||
|
||||
// LogLevelMessage
|
||||
//
|
||||
// LogLevelMessage() Print message if logging level is higher than message level
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// LogLevel
|
||||
// (in) Message level
|
||||
//
|
||||
// format
|
||||
// (in) Message format
|
||||
//
|
||||
// ...
|
||||
// (in) Parameters list
|
||||
// LogLevelMessage
|
||||
//
|
||||
// LogLevelMessage() Print message if logging level is higher than message level
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// LogLevel
|
||||
// (in) Message level
|
||||
//
|
||||
// format
|
||||
// (in) Message format
|
||||
//
|
||||
// ...
|
||||
// (in) Parameters list
|
||||
|
||||
void
|
||||
LogLevelMessage(
|
||||
enum LogLevel level,
|
||||
const char *functionName,
|
||||
int lineNumber,
|
||||
const char *format,
|
||||
...);
|
||||
void LogLevelMessage(enum LogLevel level, const char *functionName, int lineNumber, const char *format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -28,35 +28,29 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#if defined (__QNX__)
|
||||
#include <unistd.h>
|
||||
#if defined(__QNX__)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "misc_utils.h"
|
||||
|
||||
uint32_t
|
||||
u32(const uint8_t* ptr)
|
||||
{
|
||||
return ptr[0] | (ptr[1]<<8) | (ptr[2]<<16) | (ptr[3]<<24);
|
||||
}
|
||||
uint32_t u32(const uint8_t *ptr) { return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24); }
|
||||
|
||||
NvMediaStatus
|
||||
GetTimeMicroSec(
|
||||
uint64_t *uTime)
|
||||
NvMediaStatus GetTimeMicroSec(uint64_t *uTime)
|
||||
{
|
||||
struct timespec t;
|
||||
#if !(defined(CLOCK_MONOTONIC) && defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && _POSIX_TIMERS > 0)
|
||||
struct timeval tv;
|
||||
#endif
|
||||
|
||||
if(!uTime)
|
||||
if (!uTime)
|
||||
return NVMEDIA_STATUS_BAD_PARAMETER;
|
||||
|
||||
#if !(defined(CLOCK_MONOTONIC) && defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && _POSIX_TIMERS > 0)
|
||||
gettimeofday(&tv, NULL);
|
||||
t.tv_sec = tv.tv_sec;
|
||||
t.tv_nsec = tv.tv_usec*1000L;
|
||||
t.tv_sec = tv.tv_sec;
|
||||
t.tv_nsec = tv.tv_usec * 1000L;
|
||||
#else
|
||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
#endif
|
||||
@@ -64,4 +58,3 @@ GetTimeMicroSec(
|
||||
*uTime = (uint64_t)t.tv_sec * 1000000LL + (uint64_t)t.tv_nsec / 1000LL;
|
||||
return NVMEDIA_STATUS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,46 +29,42 @@
|
||||
#define _NVMEDIA_TEST_MISC_UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "nvmedia_core.h"
|
||||
#include "nvmedia_common.h"
|
||||
#include "nvmedia_core.h"
|
||||
|
||||
#ifndef __INTEGRITY
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
LSB_ALIGNED,
|
||||
MSB_ALIGNED
|
||||
} PixelAlignment;
|
||||
typedef enum { LSB_ALIGNED, MSB_ALIGNED } PixelAlignment;
|
||||
|
||||
|
||||
// u32
|
||||
//
|
||||
// u32() Reads 4 bytes from buffer and returns the read value
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// ptr
|
||||
// (in) Input buffer
|
||||
// u32
|
||||
//
|
||||
// u32() Reads 4 bytes from buffer and returns the read value
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// ptr
|
||||
// (in) Input buffer
|
||||
|
||||
uint32_t u32(const uint8_t* ptr);
|
||||
uint32_t u32(const uint8_t *ptr);
|
||||
|
||||
// GetTimeMicroSec
|
||||
//
|
||||
// GetTimeMicroSec() Returns current time in microseconds
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// uTime
|
||||
// (out) Pointer to current time in microseconds
|
||||
// GetTimeMicroSec
|
||||
//
|
||||
// GetTimeMicroSec() Returns current time in microseconds
|
||||
//
|
||||
// Arguments:
|
||||
//
|
||||
// uTime
|
||||
// (out) Pointer to current time in microseconds
|
||||
|
||||
NvMediaStatus
|
||||
GetTimeMicroSec(
|
||||
uint64_t *uTime);
|
||||
NvMediaStatus GetTimeMicroSec(uint64_t *uTime);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -25,133 +25,130 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include "nvsci_setup.h"
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
|
||||
#include "helper_cuda.h"
|
||||
#include "nvsci_setup.h"
|
||||
#include "nvmedia_2d_nvscisync.h"
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
|
||||
#define checkNvSciErrors(call) \
|
||||
do { \
|
||||
NvSciError _status = call; \
|
||||
if (NvSciError_Success != _status) { \
|
||||
printf( \
|
||||
"NVSCI call in file '%s' in line %i returned" \
|
||||
" %d, expected %d\n", \
|
||||
__FILE__, __LINE__, _status, NvSciError_Success); \
|
||||
fflush(stdout); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
#define checkNvSciErrors(call) \
|
||||
do { \
|
||||
NvSciError _status = call; \
|
||||
if (NvSciError_Success != _status) { \
|
||||
printf("NVSCI call in file '%s' in line %i returned" \
|
||||
" %d, expected %d\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
_status, \
|
||||
NvSciError_Success); \
|
||||
fflush(stdout); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void setupNvMediaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
|
||||
int cudaDeviceId) {
|
||||
NvSciSyncModule sciSyncModule;
|
||||
checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule));
|
||||
NvSciSyncAttrList signalerAttrList, waiterAttrList;
|
||||
NvSciSyncAttrList syncUnreconciledList[2];
|
||||
NvSciSyncAttrList syncReconciledList, syncConflictList;
|
||||
void setupNvMediaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj, int cudaDeviceId)
|
||||
{
|
||||
NvSciSyncModule sciSyncModule;
|
||||
checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule));
|
||||
NvSciSyncAttrList signalerAttrList, waiterAttrList;
|
||||
NvSciSyncAttrList syncUnreconciledList[2];
|
||||
NvSciSyncAttrList syncReconciledList, syncConflictList;
|
||||
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList));
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList));
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList));
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList));
|
||||
|
||||
NvMediaStatus status = NvMedia2DFillNvSciSyncAttrList(
|
||||
ctx->i2d, signalerAttrList, NVMEDIA_SIGNALER);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
NvMediaStatus status = NvMedia2DFillNvSciSyncAttrList(ctx->i2d, signalerAttrList, NVMEDIA_SIGNALER);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
checkCudaErrors(cudaSetDevice(cudaDeviceId));
|
||||
checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(waiterAttrList, cudaDeviceId,
|
||||
cudaNvSciSyncAttrWait));
|
||||
checkCudaErrors(cudaSetDevice(cudaDeviceId));
|
||||
checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(waiterAttrList, cudaDeviceId, cudaNvSciSyncAttrWait));
|
||||
|
||||
syncUnreconciledList[0] = signalerAttrList;
|
||||
syncUnreconciledList[1] = waiterAttrList;
|
||||
checkNvSciErrors(NvSciSyncAttrListReconcile(
|
||||
syncUnreconciledList, 2, &syncReconciledList, &syncConflictList));
|
||||
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj));
|
||||
syncUnreconciledList[0] = signalerAttrList;
|
||||
syncUnreconciledList[1] = waiterAttrList;
|
||||
checkNvSciErrors(NvSciSyncAttrListReconcile(syncUnreconciledList, 2, &syncReconciledList, &syncConflictList));
|
||||
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj));
|
||||
|
||||
NvSciSyncAttrListFree(signalerAttrList);
|
||||
NvSciSyncAttrListFree(waiterAttrList);
|
||||
if (syncConflictList != nullptr) {
|
||||
NvSciSyncAttrListFree(syncConflictList);
|
||||
}
|
||||
NvSciSyncAttrListFree(signalerAttrList);
|
||||
NvSciSyncAttrListFree(waiterAttrList);
|
||||
if (syncConflictList != nullptr) {
|
||||
NvSciSyncAttrListFree(syncConflictList);
|
||||
}
|
||||
}
|
||||
|
||||
void setupCudaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
|
||||
int cudaDeviceId) {
|
||||
NvSciSyncModule sciSyncModule;
|
||||
checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule));
|
||||
NvSciSyncAttrList signalerAttrList, waiterAttrList;
|
||||
NvSciSyncAttrList syncUnreconciledList[2];
|
||||
NvSciSyncAttrList syncReconciledList, syncConflictList;
|
||||
void setupCudaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj, int cudaDeviceId)
|
||||
{
|
||||
NvSciSyncModule sciSyncModule;
|
||||
checkNvSciErrors(NvSciSyncModuleOpen(&sciSyncModule));
|
||||
NvSciSyncAttrList signalerAttrList, waiterAttrList;
|
||||
NvSciSyncAttrList syncUnreconciledList[2];
|
||||
NvSciSyncAttrList syncReconciledList, syncConflictList;
|
||||
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList));
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList));
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &signalerAttrList));
|
||||
checkNvSciErrors(NvSciSyncAttrListCreate(sciSyncModule, &waiterAttrList));
|
||||
|
||||
NvMediaStatus status =
|
||||
NvMedia2DFillNvSciSyncAttrList(ctx->i2d, waiterAttrList, NVMEDIA_WAITER);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
NvMediaStatus status = NvMedia2DFillNvSciSyncAttrList(ctx->i2d, waiterAttrList, NVMEDIA_WAITER);
|
||||
if (status != NVMEDIA_STATUS_OK) {
|
||||
printf("%s: NvMedia2DFillNvSciSyncAttrList failed\n", __func__);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
checkCudaErrors(cudaSetDevice(cudaDeviceId));
|
||||
checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(
|
||||
signalerAttrList, cudaDeviceId, cudaNvSciSyncAttrSignal));
|
||||
checkCudaErrors(cudaSetDevice(cudaDeviceId));
|
||||
checkCudaErrors(cudaDeviceGetNvSciSyncAttributes(signalerAttrList, cudaDeviceId, cudaNvSciSyncAttrSignal));
|
||||
|
||||
syncUnreconciledList[0] = signalerAttrList;
|
||||
syncUnreconciledList[1] = waiterAttrList;
|
||||
checkNvSciErrors(NvSciSyncAttrListReconcile(
|
||||
syncUnreconciledList, 2, &syncReconciledList, &syncConflictList));
|
||||
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj));
|
||||
syncUnreconciledList[0] = signalerAttrList;
|
||||
syncUnreconciledList[1] = waiterAttrList;
|
||||
checkNvSciErrors(NvSciSyncAttrListReconcile(syncUnreconciledList, 2, &syncReconciledList, &syncConflictList));
|
||||
checkNvSciErrors(NvSciSyncObjAlloc(syncReconciledList, &syncObj));
|
||||
|
||||
NvSciSyncAttrListFree(signalerAttrList);
|
||||
NvSciSyncAttrListFree(waiterAttrList);
|
||||
if (syncConflictList != nullptr) {
|
||||
NvSciSyncAttrListFree(syncConflictList);
|
||||
}
|
||||
NvSciSyncAttrListFree(signalerAttrList);
|
||||
NvSciSyncAttrListFree(waiterAttrList);
|
||||
if (syncConflictList != nullptr) {
|
||||
NvSciSyncAttrListFree(syncConflictList);
|
||||
}
|
||||
}
|
||||
|
||||
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist,
|
||||
int cudaDeviceId) {
|
||||
CUuuid devUUID;
|
||||
NvSciBufAttrList conflictlist;
|
||||
NvSciBufAttrList bufUnreconciledAttrlist[1];
|
||||
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist, int cudaDeviceId)
|
||||
{
|
||||
CUuuid devUUID;
|
||||
NvSciBufAttrList conflictlist;
|
||||
NvSciBufAttrList bufUnreconciledAttrlist[1];
|
||||
|
||||
CUresult res = cuDeviceGetUuid(&devUUID, cudaDeviceId);
|
||||
if (res != CUDA_SUCCESS) {
|
||||
fprintf(stderr, "Driver API error = %04d \n", res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
CUresult res = cuDeviceGetUuid(&devUUID, cudaDeviceId);
|
||||
if (res != CUDA_SUCCESS) {
|
||||
fprintf(stderr, "Driver API error = %04d \n", res);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
NvSciBufAttrKeyValuePair attr_gpuid[] = {NvSciBufGeneralAttrKey_GpuId,
|
||||
&devUUID, sizeof(devUUID)};
|
||||
NvSciBufAttrKeyValuePair attr_gpuid[] = {NvSciBufGeneralAttrKey_GpuId, &devUUID, sizeof(devUUID)};
|
||||
|
||||
// set CUDA GPU ID to attribute list
|
||||
checkNvSciErrors(NvSciBufAttrListSetAttrs(
|
||||
nvmediaAttrlist, attr_gpuid,
|
||||
sizeof(attr_gpuid) / sizeof(NvSciBufAttrKeyValuePair)));
|
||||
// set CUDA GPU ID to attribute list
|
||||
checkNvSciErrors(
|
||||
NvSciBufAttrListSetAttrs(nvmediaAttrlist, attr_gpuid, sizeof(attr_gpuid) / sizeof(NvSciBufAttrKeyValuePair)));
|
||||
|
||||
bufUnreconciledAttrlist[0] = nvmediaAttrlist;
|
||||
bufUnreconciledAttrlist[0] = nvmediaAttrlist;
|
||||
|
||||
checkNvSciErrors(NvSciBufAttrListReconcileAndObjAlloc(
|
||||
bufUnreconciledAttrlist, 1, &bufobj, &conflictlist));
|
||||
if (conflictlist != NULL) {
|
||||
NvSciBufAttrListFree(conflictlist);
|
||||
}
|
||||
checkNvSciErrors(NvSciBufAttrListReconcileAndObjAlloc(bufUnreconciledAttrlist, 1, &bufobj, &conflictlist));
|
||||
if (conflictlist != NULL) {
|
||||
NvSciBufAttrListFree(conflictlist);
|
||||
}
|
||||
}
|
||||
|
||||
void cleanupNvSciBuf(NvSciBufObj &Bufobj) {
|
||||
if (Bufobj != NULL) {
|
||||
NvSciBufObjFree(Bufobj);
|
||||
}
|
||||
void cleanupNvSciBuf(NvSciBufObj &Bufobj)
|
||||
{
|
||||
if (Bufobj != NULL) {
|
||||
NvSciBufObjFree(Bufobj);
|
||||
}
|
||||
}
|
||||
|
||||
void cleanupNvSciSync(NvSciSyncObj &syncObj) {
|
||||
if (NvSciSyncObjFree != NULL) {
|
||||
NvSciSyncObjFree(syncObj);
|
||||
}
|
||||
void cleanupNvSciSync(NvSciSyncObj &syncObj)
|
||||
{
|
||||
if (NvSciSyncObjFree != NULL) {
|
||||
NvSciSyncObjFree(syncObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,14 @@
|
||||
|
||||
#ifndef __NVSCI_SETUP_H__
|
||||
#define __NVSCI_SETUP_H__
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
#include <nvscibuf.h>
|
||||
#include <nvscisync.h>
|
||||
|
||||
void setupNvMediaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
|
||||
int cudaDeviceId);
|
||||
void setupCudaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj,
|
||||
int cudaDeviceId);
|
||||
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist,
|
||||
int cudaDeviceId);
|
||||
#include "nvmedia_utils/cmdline.h"
|
||||
|
||||
void setupNvMediaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj, int cudaDeviceId);
|
||||
void setupCudaSignalerNvSciSync(Blit2DTest *ctx, NvSciSyncObj &syncObj, int cudaDeviceId);
|
||||
void setupNvSciBuf(NvSciBufObj &bufobj, NvSciBufAttrList &nvmediaAttrlist, int cudaDeviceId);
|
||||
void cleanupNvSciBuf(NvSciBufObj &Bufobj);
|
||||
void cleanupNvSciSync(NvSciSyncObj &syncObj);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user