19
19
#include " dali/test/tensor_test_utils.h"
20
20
#include " dali/test/test_tensors.h"
21
21
#include " dali/kernels/signal/dct/dct_test.h"
22
+ #include " dali/core/dev_buffer.h"
22
23
23
24
namespace dali {
24
25
namespace kernels {
@@ -27,13 +28,21 @@ namespace dct {
27
28
namespace test {
28
29
29
30
class Dct1DGpuTest : public ::testing::TestWithParam<
30
- std::tuple<int , std::pair<int , std::vector<int >>>> {
31
+ std::tuple<int , float , std::pair<int , std::vector<int >>>> {
31
32
public:
32
33
Dct1DGpuTest ()
33
34
: batch_size_(std::get<0 >(GetParam()))
34
- , dims_(std::get<1 >(GetParam()).first)
35
- , axes_(std::get<1 >(GetParam()).second)
35
+ , lifter_(std::get<1 >(GetParam()))
36
+ , dims_(std::get<2 >(GetParam()).first)
37
+ , axes_(std::get<2 >(GetParam()).second)
36
38
, in_shape_(batch_size_, dims_) {
39
+ if (lifter_) {
40
+ FillLifter ();
41
+ lifter_coeffs_gpu_buffer.resize (max_ndct);
42
+ lifter_coeffs_gpu_ = make_tensor_gpu<1 >(lifter_coeffs_gpu_buffer.data (), {max_ndct});
43
+ cudaMemcpy (lifter_coeffs_gpu_.data , lifter_coeffs_.data (),
44
+ lifter_coeffs_.size () * sizeof (float ), cudaMemcpyHostToDevice);
45
+ }
37
46
while (args_.size () < static_cast <size_t >(batch_size_) * axes_.size ()) {
38
47
for (auto dct : dct_type) {
39
48
for (auto norm : normalize) {
@@ -49,6 +58,13 @@ class Dct1DGpuTest : public ::testing::TestWithParam<
49
58
~Dct1DGpuTest () override = default ;
50
59
51
60
protected:
61
+ void FillLifter () {
62
+ lifter_coeffs_.resize (max_ndct);
63
+ for (int i = 0 ; i < max_ndct; ++i) {
64
+ lifter_coeffs_[i] = 1.0 + lifter_ / 2 * std::sin (M_PI / lifter_ * (i + 1 ));
65
+ }
66
+ }
67
+
52
68
void PrepareInput () {
53
69
std::mt19937_64 rng{12345 };
54
70
std::uniform_int_distribution<> dim_dist (1 , 3 );
@@ -82,17 +98,22 @@ class Dct1DGpuTest : public ::testing::TestWithParam<
82
98
}
83
99
84
100
int batch_size_;
101
+ float lifter_;
85
102
int dims_;
86
103
std::vector<int > axes_;
87
104
TensorListShape<> in_shape_;
88
105
TestTensorList<float > ttl_in_;
89
106
TestTensorList<float > ttl_out_;
90
107
std::vector<DctArgs> args_;
108
+ std::vector<float > lifter_coeffs_;
109
+ DeviceBuffer<float > lifter_coeffs_gpu_buffer;
110
+ OutTensorGPU<float , 1 > lifter_coeffs_gpu_{};
91
111
int args_idx_ = 0 ;
92
112
span<const DctArgs> args_span_;
93
113
const std::array<int , 4 > dct_type = {{1 , 2 , 3 , 4 }};
94
114
const std::array<bool , 2 > normalize = {{false , true }};
95
115
const std::array<int , 3 > ndct = {{-1 , 10 , 20 }};
116
+ const int max_ndct = 40 ;
96
117
};
97
118
98
119
@@ -112,7 +133,7 @@ TEST_P(Dct1DGpuTest, DctTest) {
112
133
ASSERT_EQ (out_shape, req.output_shapes [0 ]);
113
134
ttl_out_.reshape (out_shape);
114
135
auto out_view = ttl_out_.gpu ();
115
- kmgr.Run <Kernel>(0 , 0 , ctx, out_view, in_view, args_span_, axis );
136
+ kmgr.Run <Kernel>(0 , 0 , ctx, out_view, in_view, lifter_coeffs_gpu_ );
116
137
cudaStreamSynchronize (ctx.gpu .stream );
117
138
auto cpu_in_view = ttl_in_.cpu ();
118
139
auto cpu_out_view = ttl_out_.cpu ();
@@ -148,7 +169,7 @@ TEST_P(Dct1DGpuTest, DctTest) {
148
169
LOG_LINE << " \n " ;
149
170
int ndct = args.ndct > 0 ? args.ndct : in_shape_[s][axis];
150
171
std::vector<float > ref (ndct, 0 );
151
- ReferenceDct (args.dct_type , make_span (ref), make_cspan (in_buf), args.normalize );
172
+ ReferenceDct (args.dct_type , make_span (ref), make_cspan (in_buf), args.normalize , lifter_ );
152
173
LOG_LINE << " DCT (type " << args.dct_type << " ):" ;
153
174
for (int k = 0 ; k < ndct; k++) {
154
175
EXPECT_NEAR (ref[k], out[out_idx], 1e-5 );
@@ -163,7 +184,8 @@ TEST_P(Dct1DGpuTest, DctTest) {
163
184
}
164
185
165
186
INSTANTIATE_TEST_SUITE_P (Dct1DGpuTest, Dct1DGpuTest, testing::Combine(
166
- testing::Values (1 , 6 , 12 ), // batch_size
187
+ testing::Values (1 , 12 ), // batch_size
188
+ testing::Values(0 .f, 0 .5f ), // lifter
167
189
testing::Values(std::make_pair(2 , std::vector<int >{1 }),
168
190
std::make_pair(4 , std::vector<int >{0 , 3 , 1 }),
169
191
std::make_pair(1 , std::vector<int >{0 , 0 })) // dims, axes
0 commit comments