UnpackerTester.cu 2.33 KB
Newer Older
1
#include "psrdada_cpp/effelsberg/paf/test/UnpackerTester.cuh"
Tobias Winchen's avatar
Tobias Winchen committed
2
#include "psrdada_cpp/cli_utils.hpp"
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "psrdada_cpp/cuda_utils.hpp"
#include <random>

#define BSWAP64(x) ((0xFF00000000000000 & x) >> 56) | \
                   ((0x00FF000000000000 & x) >> 40) | \
                   ((0x0000FF0000000000 & x) >> 24) | \
                   ((0x000000FF00000000 & x) >>  8) | \
                   ((0x00000000FF000000 & x) <<  8) | \
                   ((0x0000000000FF0000 & x) << 24) | \
                   ((0x000000000000FF00 & x) << 40) | \
                   ((0x00000000000000FF & x) << 56)

namespace psrdada_cpp {
namespace effelsberg {
namespace paf {
namespace test {

UnpackerTester::UnpackerTester()
    : ::testing::Test()
    , _stream(0)
{

}

UnpackerTester::~UnpackerTester()
{

}

void UnpackerTester::SetUp()
{
    CUDA_ERROR_CHECK(cudaStreamCreate(&_stream));
}

void UnpackerTester::TearDown()
{
    CUDA_ERROR_CHECK(cudaStreamDestroy(_stream));
}


void UnpackerTester::unpacker_c_reference(
    InputType const& input,
    OutputType& output)
{
    /*...*/
}

void UnpackerTester::compare_against_host(
    Unpacker::OutputType const& gpu_output,
    OutputType const& host_output)
{
    OutputType copy_from_gpu = gpu_output;
    ASSERT_EQ(host_output.size(), copy_from_gpu.size());
    for (std::size_t ii = 0; ii < host_output.size(); ++ii)
    {
	   ASSERT_EQ(host_output[ii].x, copy_from_gpu[ii].x);
       ASSERT_EQ(host_output[ii].y, copy_from_gpu[ii].y);
    }
}

TEST_F(UnpackerTester, paf_unpack_test)
{
    std::size_t n = 1024 * 3;
    std::default_random_engine generator;
    std::uniform_int_distribution<int> distribution(1,1<<31);
    InputType host_input(n);
69
    for (size_t ii = 0; ii < n; ++ii)
70
71
72
73
74
75
76
    {
        host_input[ii] = distribution(generator);
    }
    Unpacker::InputType gpu_input = host_input;
    Unpacker::OutputType gpu_output;
    OutputType host_output;
    Unpacker unpacker(_stream);
77
    unpacker.unpack(gpu_input, gpu_output);
78
79
80
81
82
83
84
85
86
    unpacker_c_reference(host_input, host_output);
    compare_against_host(gpu_output, host_output);
}


} //namespace test
} //namespace paf
} //namespace meerkat
} //namespace psrdada_cpp
Tobias Winchen's avatar
Tobias Winchen committed
87
88
89
90
91
92
93
94
95
96
97
98
99


int main(int argc, char **argv) {
  char * val = getenv("LOG_LEVEL");
  if ( val )
  {
      psrdada_cpp::set_log_level(val);
  }

  ::testing::InitGoogleTest(&argc, argv);

  return RUN_ALL_TESTS();
}