19
19
#include < raft/cudart_utils.h>
20
20
#include < iostream>
21
21
#include < memory>
22
+ #include < vector>
22
23
#include < raft/cuda_utils.cuh>
23
24
24
25
namespace raft {
@@ -77,14 +78,14 @@ template <typename T, typename L>
77
78
testing::AssertionResult devArrMatch (const T *expected, const T *actual,
78
79
size_t size, L eq_compare,
79
80
cudaStream_t stream = 0 ) {
80
- std::shared_ptr <T> exp_h (new T[ size] );
81
- std::shared_ptr <T> act_h (new T[ size] );
82
- raft::update_host<T>(exp_h.get (), expected, size, stream);
83
- raft::update_host<T>(act_h.get (), actual, size, stream);
81
+ std::vector <T> exp_h (size);
82
+ std::vector <T> act_h (size);
83
+ raft::update_host<T>(exp_h.data (), expected, size, stream);
84
+ raft::update_host<T>(act_h.data (), actual, size, stream);
84
85
CUDA_CHECK (cudaStreamSynchronize (stream));
85
86
for (size_t i (0 ); i < size; ++i) {
86
- auto exp = exp_h. get () [i];
87
- auto act = act_h. get () [i];
87
+ auto exp = exp_h[i];
88
+ auto act = act_h[i];
88
89
if (!eq_compare (exp , act)) {
89
90
return testing::AssertionFailure ()
90
91
<< " actual=" << act << " != expected=" << exp << " @" << i;
@@ -96,11 +97,11 @@ testing::AssertionResult devArrMatch(const T *expected, const T *actual,
96
97
template <typename T, typename L>
97
98
testing::AssertionResult devArrMatch (T expected, const T *actual, size_t size,
98
99
L eq_compare, cudaStream_t stream = 0 ) {
99
- std::shared_ptr <T> act_h (new T[ size] );
100
- raft::update_host<T>(act_h.get (), actual, size, stream);
100
+ std::vector <T> act_h (size);
101
+ raft::update_host<T>(act_h.data (), actual, size, stream);
101
102
CUDA_CHECK (cudaStreamSynchronize (stream));
102
103
for (size_t i (0 ); i < size; ++i) {
103
- auto act = act_h. get () [i];
104
+ auto act = act_h[i];
104
105
if (!eq_compare (expected, act)) {
105
106
return testing::AssertionFailure ()
106
107
<< " actual=" << act << " != expected=" << expected << " @" << i;
@@ -114,16 +115,16 @@ testing::AssertionResult devArrMatch(const T *expected, const T *actual,
114
115
size_t rows, size_t cols, L eq_compare,
115
116
cudaStream_t stream = 0 ) {
116
117
size_t size = rows * cols;
117
- std::shared_ptr <T> exp_h (new T[ size] );
118
- std::shared_ptr <T> act_h (new T[ size] );
119
- raft::update_host<T>(exp_h.get (), expected, size, stream);
120
- raft::update_host<T>(act_h.get (), actual, size, stream);
118
+ std::vector <T> exp_h (size);
119
+ std::vector <T> act_h (size);
120
+ raft::update_host<T>(exp_h.data (), expected, size, stream);
121
+ raft::update_host<T>(act_h.data (), actual, size, stream);
121
122
CUDA_CHECK (cudaStreamSynchronize (stream));
122
123
for (size_t i (0 ); i < rows; ++i) {
123
124
for (size_t j (0 ); j < cols; ++j) {
124
125
auto idx = i * cols + j; // row major assumption!
125
- auto exp = exp_h. get () [idx];
126
- auto act = act_h. get () [idx];
126
+ auto exp = exp_h[idx];
127
+ auto act = act_h[idx];
127
128
if (!eq_compare (exp , act)) {
128
129
return testing::AssertionFailure ()
129
130
<< " actual=" << act << " != expected=" << exp << " @" << i << " ,"
@@ -139,13 +140,13 @@ testing::AssertionResult devArrMatch(T expected, const T *actual, size_t rows,
139
140
size_t cols, L eq_compare,
140
141
cudaStream_t stream = 0 ) {
141
142
size_t size = rows * cols;
142
- std::shared_ptr <T> act_h (new T[ size] );
143
- raft::update_host<T>(act_h.get (), actual, size, stream);
143
+ std::vector <T> act_h (size);
144
+ raft::update_host<T>(act_h.data (), actual, size, stream);
144
145
CUDA_CHECK (cudaStreamSynchronize (stream));
145
146
for (size_t i (0 ); i < rows; ++i) {
146
147
for (size_t j (0 ); j < cols; ++j) {
147
148
auto idx = i * cols + j; // row major assumption!
148
- auto act = act_h. get () [idx];
149
+ auto act = act_h[idx];
149
150
if (!eq_compare (expected, act)) {
150
151
return testing::AssertionFailure ()
151
152
<< " actual=" << act << " != expected=" << expected << " @" << i
@@ -171,14 +172,14 @@ template <typename T, typename L>
171
172
testing::AssertionResult devArrMatchHost (const T *expected_h, const T *actual_d,
172
173
size_t size, L eq_compare,
173
174
cudaStream_t stream = 0 ) {
174
- std::shared_ptr <T> act_h (new T[ size] );
175
+ std::vector <T> act_h (size);
175
176
raft::update_host<T>(act_h.get (), actual_d, size, stream);
176
177
CUDA_CHECK (cudaStreamSynchronize (stream));
177
178
bool ok = true ;
178
179
auto fail = testing::AssertionFailure ();
179
180
for (size_t i (0 ); i < size; ++i) {
180
181
auto exp = expected_h[i];
181
- auto act = act_h. get () [i];
182
+ auto act = act_h[i];
182
183
if (!eq_compare (exp , act)) {
183
184
ok = false ;
184
185
fail << " actual=" << act << " != expected=" << exp << " @" << i << " ; " ;
@@ -203,14 +204,14 @@ testing::AssertionResult diagonalMatch(T expected, const T *actual, size_t rows,
203
204
size_t cols, L eq_compare,
204
205
cudaStream_t stream = 0 ) {
205
206
size_t size = rows * cols;
206
- std::shared_ptr <T> act_h (new T[ size] );
207
- raft::update_host<T>(act_h.get (), actual, size, stream);
207
+ std::vector <T> act_h (size);
208
+ raft::update_host<T>(act_h.data (), actual, size, stream);
208
209
CUDA_CHECK (cudaStreamSynchronize (stream));
209
210
for (size_t i (0 ); i < rows; ++i) {
210
211
for (size_t j (0 ); j < cols; ++j) {
211
212
if (i != j) continue ;
212
213
auto idx = i * cols + j; // row major assumption!
213
- auto act = act_h. get () [idx];
214
+ auto act = act_h[idx];
214
215
if (!eq_compare (expected, act)) {
215
216
return testing::AssertionFailure ()
216
217
<< " actual=" << act << " != expected=" << expected << " @" << i
0 commit comments