Commit 3afc855d authored by Matt Clarkson's avatar Matt Clarkson

Issue #1: Review/Tidy tests.

parent 97aaf9d3
......@@ -21,11 +21,6 @@ namespace sks
{
//-----------------------------------------------------------------------------
int MyFirstAddFunction(int a, int b)
{
return a + b;
}
cv::Mat MultiplyTwoArrays(const cv::Mat &a, const cv::Mat &b)
{
cv::cuda::GpuMat mul, src_a, src_b;
......@@ -33,14 +28,16 @@ cv::Mat MultiplyTwoArrays(const cv::Mat &a, const cv::Mat &b)
src_b.upload(b);
cv::cuda::multiply(src_a, src_b, mul);
cv::Mat result_host;
mul.download(result_host);
return result_host;
}
//-----------------------------------------------------------------------------
cv::Mat GpuThreshold(const cv::Mat &input)
/* Example adapted from https://opencv.org/cuda/ */
{
cv::cuda::GpuMat dst, src;
......@@ -54,6 +51,8 @@ cv::Mat GpuThreshold(const cv::Mat &input)
return result_host;
}
//-----------------------------------------------------------------------------
void PrintCudaDeviceInfo()
{
int deviceCount = cv::cuda::getCudaEnabledDeviceCount();
......@@ -61,7 +60,6 @@ void PrintCudaDeviceInfo()
{
std::cout << "No CUDA Devices Detected." << std::endl;
}
else
{
cv::cuda::printCudaDeviceInfo(0);
......
......@@ -27,11 +27,18 @@ namespace sks
{
/**
* \brief My first function, adds two integers.
* \brief Example function to multiply two cv::Mat on GPU.
*/
SKSURGERYGPUCPP_WINEXPORT int MyFirstAddFunction(int a, int b);
extern "C++" SKSURGERYGPUCPP_WINEXPORT cv::Mat MultiplyTwoArrays(const cv::Mat &a, const cv::Mat &b);
/**
* \brief Example function to threshold an image.
*/
extern "C++" SKSURGERYGPUCPP_WINEXPORT cv::Mat GpuThreshold(const cv::Mat &input);
/**
* \brief Prints CUDA device info.
*/
void PrintCudaDeviceInfo();
} // namespace sks
......
......@@ -18,7 +18,6 @@ set(TMP_DIR ${CMAKE_BINARY_DIR}/Testing/Temporary)
set(TEST_CASES
sksBasicTest
sksCommandLineArgsTest
)
foreach(_test_case ${TEST_CASES})
......@@ -28,8 +27,8 @@ endforeach()
if (SKSURGERYGPUCPP_USE_CUDA)
set(CUDA_TEST_CASES
mpCudaTest
cvCudaTest
sksCudaTest
sksOpenCVCudaTest
)
foreach(_test_case ${CUDA_TEST_CASES})
cuda_add_executable(${_test_case} ${_test_case}.cu sksCatchMain.cpp)
......@@ -47,6 +46,6 @@ endif()
add_test(NoArgs ${EXECUTABLE_OUTPUT_PATH}/sksBasicTest)
add_test(1File ${EXECUTABLE_OUTPUT_PATH}/sksCommandLineArgsTest ${DATA_DIR}/input.txt)
if (SKSURGERYGPUCPP_USE_CUDA)
add_test(Cuda ${EXECUTABLE_OUTPUT_PATH}/mpCudaTest)
add_test(OpenCVCuda ${EXECUTABLE_OUTPUT_PATH}/cvCudaTest)
add_test(Cuda ${EXECUTABLE_OUTPUT_PATH}/sksCudaTest)
add_test(OpenCVCuda ${EXECUTABLE_OUTPUT_PATH}/sksOpenCVCudaTest)
endif()
\ No newline at end of file
#include "catch.hpp"
#include <iostream>
#include "opencv2/core/core_c.h"
#include "opencv2/core/cuda.hpp"
#include "opencv2/cudaarithm.hpp"
TEST_CASE("OpenCV CUDA", "[OpenCV_CUDA]") {
cv::Mat src_host_A = cv::Mat(1000, 1000, CV_32FC1, cv::Scalar(2));
cv::Mat src_host_B = cv::Mat(1000, 1000, CV_32FC1, cv::Scalar(3));
cv::cuda::GpuMat dst, src_A, src_B;
src_A.upload(src_host_A);
src_B.upload(src_host_B);
cv::cuda::multiply(src_A, src_B, dst);
cv::Mat result_host;
dst.download(result_host);
REQUIRE (result_host.at<float>(0,0) == 6);
}
\ No newline at end of file
......@@ -14,20 +14,10 @@
#include "catch.hpp"
#include "sksCatchMain.h"
#include "sksMyFunctions.h"
#include <iostream>
#include <vector>
TEST_CASE( "My first test", "[some group identifier]" ) {
TEST_CASE( "Demo/Example unit test", "Basic C++ Tests" ) {
int a = 5;
REQUIRE( a < 6 );
}
TEST_CASE( "My second test", "[some group identifier]" ) {
std::vector<int> a;
REQUIRE( a.size() == 0 );
}
TEST_CASE( "Simple add", "[MyFirstAddFunction]") {
REQUIRE( sks::MyFirstAddFunction(1, 2) == 3);
}
......@@ -41,6 +41,7 @@ TEST_CASE( "Copy to device, sort", "[CUDA]" ) {
REQUIRE(d[0] == 1);
REQUIRE(d[1] == 3);
}
/*
TEST_CASE( "Sort 32M numbers on GPU", "[CUDA]" ) {
......
/*=============================================================================
SKSURGERYGPUCPP: Image-guided surgery functions, in C++, using GPU.
Copyright (c) University College London (UCL). All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
See LICENSE.txt in the top level directory for details.
=============================================================================*/
#include "catch.hpp"
#include <iostream>
#include "opencv2/core/core_c.h"
#include "opencv2/core/cuda.hpp"
#include "opencv2/cudaarithm.hpp"
TEST_CASE("OpenCV CUDA", "[OpenCV_CUDA]") {
cv::Mat src_host_A = cv::Mat(1000, 1000, CV_32FC1, cv::Scalar(2));
cv::Mat src_host_B = cv::Mat(1000, 1000, CV_32FC1, cv::Scalar(3));
cv::cuda::GpuMat dst, src_A, src_B;
src_A.upload(src_host_A);
src_B.upload(src_host_B);
cv::cuda::multiply(src_A, src_B, dst);
cv::Mat result_host;
dst.download(result_host);
REQUIRE (result_host.at<float>(0,0) == 6);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment