Skip to content

Commit

Permalink
added DMA test
Browse files Browse the repository at this point in the history
  • Loading branch information
“Vinayak-YB” authored and venkat0907 committed Jul 11, 2023
1 parent fc5ab47 commit 6c7000f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 4 deletions.
4 changes: 2 additions & 2 deletions base/src/AffineTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ class DetailDMA : public DetailGPU
bool setPtrs()
{
#if defined(__arm__) || defined(__aarch64__)
inputPtr = static_cast<DMAFDWrapper*>(inputFrame->data());
outputPtr = static_cast<DMAFDWrapper*>(outputFrame->data());
inputPtr = (static_cast<DMAFDWrapper*>(inputFrame->data()))->getCudaPtr();
outputPtr = (static_cast<DMAFDWrapper*>(outputFrame->data()))->getCudaPtr();
cudaMemset(outputPtr, 0, outputFrame->size());
#endif
return true;
Expand Down
76 changes: 74 additions & 2 deletions base/test/affinetransform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "AffineTransform.h"
#include "FileReaderModule.h"
#include "RawImageMetadata.h"
#include "RawImagePlanarMetadata.h"
#include "FrameMetadata.h"
#include "FrameMetadataFactory.h"
#include "Frame.h"
Expand All @@ -17,6 +18,13 @@
#include "CudaMemCopy.h"
#endif

#if defined(__arm__) || defined(__aarch64__)
#include "NvV4L2Camera.h"
#include "NvTransform.h"
#include "CudaStreamSynchronize.h"
#include "DMAFDToHostCopy.h"
#include "FileWriterModule.h"
#endif

BOOST_AUTO_TEST_SUITE(affinetransform_tests)

Expand All @@ -43,9 +51,8 @@ struct AffineTestsStruct
else {
metadata = framemetadata_sp(new RawImageMetadata(width, height, imageType, bit_depth, 0, CV_8U, FrameMetadata::HOST, true));
}
#ifdef APRA_CUDA_ENABLED
createPipeline(inpFilePath, width, height, imageType, bit_depth, angle, x, y, scale, interpolation,type);
#endif
}
void createPipeline(const std::string& inpFilePath, int width, int height, ImageMetadata::ImageType imageType, int bit_depth, double angle, int x, int y, double scale, AffineTransformProps::Interpolation interpolation, AffineTransformProps::TransformType type)
{
Expand Down Expand Up @@ -90,6 +97,7 @@ struct AffineTestsStruct

BOOST_AUTO_TEST_CASE(MONO_rotation, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::MONO;
AffineTestsStruct f("./data/mono_1920x1080.raw", 1920, 1080, ImageMetadata::ImageType::MONO, CV_8UC1,AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 5, 0, 0, 1.0);

Expand All @@ -104,10 +112,12 @@ BOOST_AUTO_TEST_CASE(MONO_rotation, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-MONO_rotation_mono_1920x1080.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(MONO_scale_rotate, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::MONO;
AffineTestsStruct f("./data/mono_1920x1080.raw", 1920, 1080, ImageMetadata::ImageType::MONO, CV_8UC1, AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 45, 0, 0, 2.0);

Expand All @@ -122,10 +132,12 @@ BOOST_AUTO_TEST_CASE(MONO_scale_rotate, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-MONO_scale_rotate_mono_1920x1080.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(MONO_shrink,* boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::MONO;
AffineTestsStruct f("./data/mono_1920x1080.raw", 1920, 1080, ImageMetadata::ImageType::MONO, CV_8UC1, AffineTransformProps::USING_NPPI, AffineTransformProps::CUBIC, 0, 0, 0, 0.2);

Expand All @@ -140,10 +152,12 @@ BOOST_AUTO_TEST_CASE(MONO_shrink,* boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-MONO_shrink_mono_1920x1080.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(mono_shift_x, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::MONO;
AffineTestsStruct f("./data/mono_1920x1080.raw", 1920, 1080, ImageMetadata::ImageType::MONO, CV_8UC1, AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 0, 100, 0, 1.0);

Expand All @@ -158,10 +172,12 @@ BOOST_AUTO_TEST_CASE(mono_shift_x, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-mono_shift_x_mono_1920x1080.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(mono_shift_y, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::MONO;
AffineTestsStruct f("./data/mono_1920x1080.raw", 1920, 1080, ImageMetadata::ImageType::MONO, CV_8UC1, AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 0, 0, 300, 1.0);

Expand All @@ -176,6 +192,7 @@ BOOST_AUTO_TEST_CASE(mono_shift_y, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-mono_shift_y_mono_1920x1080.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(mono_shift_scale_rotate)
Expand All @@ -200,6 +217,7 @@ BOOST_AUTO_TEST_CASE(mono_shift_scale_rotate)

BOOST_AUTO_TEST_CASE(RGB_Image_rotation, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::RGB;
AffineTestsStruct f("./data/frame_1280x720_rgb.raw", 1280, 720, ImageMetadata::ImageType::RGB, CV_8UC3, AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 90, 0, 0, 1.0);

Expand All @@ -214,11 +232,13 @@ BOOST_AUTO_TEST_CASE(RGB_Image_rotation, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-RGB_Image_rotation_frame_1280x720_rgb.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif

}

BOOST_AUTO_TEST_CASE(RGB_Image_scaling, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::RGB;
AffineTestsStruct f("./data/frame_1280x720_rgb.raw", 1280, 720, ImageMetadata::ImageType::RGB, CV_8UC3, AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 0, 0, 0, 2.0);

Expand All @@ -233,10 +253,12 @@ BOOST_AUTO_TEST_CASE(RGB_Image_scaling, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-RGB_Image_scaling_frame_1280x720_rgb.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(RGB_Image_shifting,*boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::RGB;
AffineTestsStruct f("./data/frame_1280x720_rgb.raw", 1280, 720, ImageMetadata::ImageType::RGB, CV_8UC3, AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 0, 100, 300, 1.0);

Expand All @@ -251,10 +273,12 @@ BOOST_AUTO_TEST_CASE(RGB_Image_shifting,*boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-RGB_Image_shifting_frame_1280x720_rgb.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(RGB_scale_rotate, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::RGB;
AffineTestsStruct f("./data/frame_1280x720_rgb.raw", 1280, 720, ImageMetadata::ImageType::RGB, CV_8UC3, AffineTransformProps::USING_NPPI, AffineTransformProps::LINEAR, 30,0,0, 2.5);

Expand All @@ -269,6 +293,7 @@ BOOST_AUTO_TEST_CASE(RGB_scale_rotate, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests-RGB_scale_rotate_frame_1280x720_rgb.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(RGB_Image_shift_scale_rotate)
Expand All @@ -293,6 +318,7 @@ BOOST_AUTO_TEST_CASE(RGB_Image_shift_scale_rotate)

BOOST_AUTO_TEST_CASE(BGR_Image_shift_scale_rotate,*boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::BGR;
AffineTestsStruct f("./data/BGR_1080x720.raw", 1080, 720, ImageMetadata::ImageType::BGR, CV_8UC3, AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 5, 300, 100, 3.0);

Expand All @@ -307,11 +333,13 @@ BOOST_AUTO_TEST_CASE(BGR_Image_shift_scale_rotate,*boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests_BGR_1080x720.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif

}

BOOST_AUTO_TEST_CASE(RGBA_Image_scale_rotate, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::RGBA;
AffineTestsStruct f("./data/rgba_400x400.raw", 400,400, ImageMetadata::ImageType::RGBA, CV_8UC4, AffineTransformProps::USING_NPPI, AffineTransformProps::NN,90, 0, 0, 2.5);

Expand All @@ -326,6 +354,7 @@ BOOST_AUTO_TEST_CASE(RGBA_Image_scale_rotate, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests_frame_400x400_rgba.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(RGBA_Image_shift_scale_rotate)
Expand All @@ -350,6 +379,7 @@ BOOST_AUTO_TEST_CASE(RGBA_Image_shift_scale_rotate)

BOOST_AUTO_TEST_CASE(BGRA_Image_shift_scale_rotate, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::BGRA;
AffineTestsStruct f("./data/8bit_frame_1280x720_bgra.raw", 1280, 720, ImageMetadata::ImageType::BGRA, CV_8UC4, AffineTransformProps::USING_NPPI, AffineTransformProps::LINEAR, 90, 100,100, 2.5);

Expand All @@ -364,10 +394,12 @@ BOOST_AUTO_TEST_CASE(BGRA_Image_shift_scale_rotate, *boost::unit_test::disabled(
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests_8bit_frame_1280x720_bgra.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}

BOOST_AUTO_TEST_CASE(YUV444_scale_rotate, *boost::unit_test::disabled())
{
#ifdef APRA_CUDA_ENABLED
ImageMetadata::ImageType::YUV444;
AffineTestsStruct f("./data/yuv444.raw", 400, 400, ImageMetadata::ImageType::YUV444, size_t(0), AffineTransformProps::USING_NPPI, AffineTransformProps::NN, 90, 0, 0, 2.5);

Expand All @@ -382,6 +414,7 @@ BOOST_AUTO_TEST_CASE(YUV444_scale_rotate, *boost::unit_test::disabled())
auto outFrame = frames[outputPinId];
BOOST_TEST(outFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_tests_YUV444_scale_rotate_yuv444.raw", (const uint8_t*)outFrame->data(), outFrame->size(), 0);
#endif
}
BOOST_AUTO_TEST_CASE(YUV444_shift_scale_rotate)
{
Expand Down Expand Up @@ -502,4 +535,43 @@ BOOST_AUTO_TEST_CASE(GetSetProps, *boost::unit_test::disabled())
Test_Utils::saveOrCompare("./data/testOutput/affinetransform_getsetProps_RGB.raw", (const uint8_t*)outFrame2->data(), outFrame2->size(), 0);

}

BOOST_AUTO_TEST_CASE(DMABUF_RGBA,*boost::unit_test::disabled())
{
#if defined(__arm__) || defined(__aarch64__)
NvV4L2CameraProps nvCamProps(640,360, 10);
auto source = boost::shared_ptr<Module>(new NvV4L2Camera(nvCamProps));

NvTransformProps nvprops(ImageMetadata::RGBA);
auto transform = boost::shared_ptr<Module>(new NvTransform(nvprops));
source->setNext(transform);

auto stream = cudastream_sp(new ApraCudaStream);

AffineTransformProps affineProps(AffineTransformProps::USING_NPPI,AffineTransformProps::NN, stream,45,100, 300,3);
auto m_affineTransform = boost::shared_ptr<AffineTransform>(new AffineTransform(affineProps));
transform->setNext(m_affineTransform);

CudaStreamSynchronizeProps cuxtxProps(stream);
auto sync = boost::shared_ptr<CudaStreamSynchronize>(new CudaStreamSynchronize(cuxtxProps));
m_affineTransform->setNext(sync);

auto copySource = boost::shared_ptr<Module>(new DMAFDToHostCopy);
sync->setNext(copySource);

auto fileWriter = boost::shared_ptr<Module>(new FileWriterModule(FileWriterModuleProps("./data/testOutput/nvv4l2/frame_????.raw")));
copySource->setNext(fileWriter);

PipeLine p("test");
p.appendModule(source);
BOOST_TEST(p.init());
p.run_all_threaded();
boost::this_thread::sleep_for(boost::chrono::seconds(4));
p.stop();
p.term();
p.wait_for_all();
#endif
}


BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 6c7000f

Please sign in to comment.