297 lines
11 KiB
C++
297 lines
11 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(), result1.getDataSize());
|
|
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
|
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]);
|
|
}
|
|
}
|
|
|
|
TEST_F(Function1D_Cuda_Test, repmat)
|
|
{
|
|
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::repmat(hostMatrix,3,6);
|
|
auto result2 = Aurora::repmat(deviceMatrix,3,6).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 8 * 3 * 6);
|
|
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::repmat(hostMatrix, 4, 8);
|
|
result2 = Aurora::repmat(deviceMatrix, 4, 8).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 4 * 4 * 8);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Complex);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[12]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10,11,12}, 3, 4, 1,Aurora::Normal);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::repmat(hostMatrix, 4, 8, 3);
|
|
result2 = Aurora::repmat(deviceMatrix, 4, 8, 3).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 3 * 4 * 4 * 8 * 3);
|
|
EXPECT_EQ(result2.getValueType(), Aurora::Normal);
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_EQ(result1[i], result2[i]);
|
|
}
|
|
|
|
hostMatrix = Aurora::Matrix::fromRawData(new float[12]{1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10,11,12}, 3, 2, 1,Aurora::Complex);
|
|
deviceMatrix = hostMatrix.toDeviceMatrix();
|
|
result1 = Aurora::repmat(hostMatrix, 4, 8, 3);
|
|
result2 = Aurora::repmat(deviceMatrix, 4, 8, 3).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), 3 * 2 * 4 * 8 * 3);
|
|
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, log)
|
|
{
|
|
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::log(hostMatrix);
|
|
auto result2 = Aurora::log(deviceMatrix).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
|
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
|
}
|
|
|
|
result1 = Aurora::log(hostMatrix,3);
|
|
result2 = Aurora::log(deviceMatrix,3).toHostMatrix();
|
|
EXPECT_EQ(result2.getDataSize(), result1.getDataSize());
|
|
EXPECT_EQ(result2.getValueType(), result1.getValueType());
|
|
for(size_t i=0; i<result1.getDataSize() * result1.getValueType(); ++i)
|
|
{
|
|
EXPECT_FLOAT_AE(result1[i], result2[i]);
|
|
}
|
|
}
|