225 lines
7.9 KiB
C++
225 lines
7.9 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "CudaMatrix.h"
|
|
#include "Matrix.h"
|
|
#include "TestUtility.h"
|
|
|
|
#include "Function1D.h"
|
|
#include "Function1D.cuh"
|
|
|
|
class Function1D_Cuda_Test:public ::testing::Test
|
|
{
|
|
protected:
|
|
static void SetUpFunction1DCudaTester(){
|
|
|
|
}
|
|
static void TearDownTestCase(){
|
|
}
|
|
void SetUp(){
|
|
}
|
|
void TearDown(){
|
|
}
|
|
|
|
};
|
|
|
|
TEST_F(Function1D_Cuda_Test, complex)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1,2,3,4,5,6,7,8}, 2,2,2);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::complex(hostMatrix);
|
|
auto result2 = Aurora::complex(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Complex);
|
|
for(size_t i=0; i<result1.getDataSize() * 2; ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, real)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1,2,3,4,5,6,7,8}, 2,2,1,Aurora::Complex);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::real(hostMatrix);
|
|
auto result2 = Aurora::real(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, imag)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1,2,3,4,5,6,7,8}, 2,2,1,Aurora::Complex);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::imag(hostMatrix);
|
|
auto result2 = Aurora::imag(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, ceil)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::ceil(hostMatrix);
|
|
auto result2 = Aurora::ceil(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,2,1,Aurora::Complex);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::ceil(hostMatrix);
|
|
result2 = Aurora::ceil(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Complex);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, round)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::round(hostMatrix);
|
|
auto result2 = Aurora::round(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,2,1,Aurora::Complex);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::round(hostMatrix);
|
|
result2 = Aurora::round(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Complex);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, floor)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::floor(hostMatrix);
|
|
auto result2 = Aurora::floor(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,2,1,Aurora::Complex);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::floor(hostMatrix);
|
|
result2 = Aurora::floor(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Complex);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, sqrt)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::sqrt(hostMatrix);
|
|
auto result2 = Aurora::sqrt(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,2,1,Aurora::Complex);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::sqrt(hostMatrix);
|
|
result2 = Aurora::sqrt(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Complex);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, abs)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::abs(hostMatrix);
|
|
auto result2 = Aurora::abs(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,2,1,Aurora::Complex);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::abs(hostMatrix);
|
|
result2 = Aurora::abs(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, sign)
|
|
{
|
|
Aurora::Matrix hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,4);
|
|
Aurora::CudaMatrix deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
|
|
auto result1 = Aurora::sign(hostMatrix);
|
|
auto result2 = Aurora::sign(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[8]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8}, 2,2,1,Aurora::Complex);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::sign(hostMatrix);
|
|
result2 = Aurora::sign(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Complex);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
}
|