Skip to content

Commit a3f291a

Browse files
committed
add test and char instantiation on array fill
1 parent 32ba2ef commit a3f291a

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

common/unified/components/fill_array_kernels.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void fill_array(std::shared_ptr<const DefaultExecutor> exec, ValueType* array,
2727

2828
GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(GKO_DECLARE_FILL_ARRAY_KERNEL);
2929
template GKO_DECLARE_FILL_ARRAY_KERNEL(bool);
30+
template GKO_DECLARE_FILL_ARRAY_KERNEL(char);
3031
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint16);
3132
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint32);
3233
#ifndef GKO_SIZE_T_IS_UINT64_T

core/base/array.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ ValueType reduce_add(const array<ValueType>& input_arr,
9292

9393
GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(GKO_DECLARE_ARRAY_FILL);
9494
template GKO_DECLARE_ARRAY_FILL(bool);
95+
template GKO_DECLARE_ARRAY_FILL(char);
9596
template GKO_DECLARE_ARRAY_FILL(uint16);
9697
template GKO_DECLARE_ARRAY_FILL(uint32);
9798
#ifndef GKO_SIZE_T_IS_UINT64_T

core/device_hooks/common_kernels.inc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ template GKO_DECLARE_PREFIX_SUM_NONNEGATIVE_KERNEL(size_type);
254254

255255
GKO_STUB_TEMPLATE_TYPE(GKO_DECLARE_FILL_ARRAY_KERNEL);
256256
template GKO_DECLARE_FILL_ARRAY_KERNEL(bool);
257+
template GKO_DECLARE_FILL_ARRAY_KERNEL(char);
257258
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint16);
258259
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint32);
259260
#ifndef GKO_SIZE_T_IS_UINT64_T

reference/components/fill_array_kernels.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void fill_array(std::shared_ptr<const DefaultExecutor> exec, ValueType* array,
2323

2424
GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(GKO_DECLARE_FILL_ARRAY_KERNEL);
2525
template GKO_DECLARE_FILL_ARRAY_KERNEL(bool);
26+
template GKO_DECLARE_FILL_ARRAY_KERNEL(char);
2627
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint16);
2728
template GKO_DECLARE_FILL_ARRAY_KERNEL(uint32);
2829
#ifndef GKO_SIZE_T_IS_UINT64_T

test/mpi/distributed/row_gatherer.cpp

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,164 @@ TYPED_TEST(RowGatherer, CanApplyAsyncWithMultipleColumns)
226226
}
227227

228228

229+
TYPED_TEST(RowGatherer, CanApplyAsyncWithEvent)
230+
{
231+
using Dense = gko::matrix::Dense<double>;
232+
using Vector = gko::experimental::distributed::Vector<double>;
233+
int rank = this->comm.rank();
234+
auto offset = static_cast<double>(rank * 3);
235+
auto b = Vector::create(
236+
this->exec, this->comm, gko::dim<2>{18, 1},
237+
gko::initialize<Dense>({offset, offset + 1, offset + 2}, this->exec));
238+
auto expected = this->template create_recv_connections<double>()[rank];
239+
auto x = Vector::create(this->mpi_exec, this->comm,
240+
gko::dim<2>{this->rg->get_size()[0], 1},
241+
gko::dim<2>{expected.get_size(), 1});
242+
243+
auto ev = this->rg->apply_prepare(b, x);
244+
auto req = this->rg->apply_finalize(b, x, ev);
245+
req.wait();
246+
247+
auto expected_vec = Vector::create(
248+
this->mpi_exec, this->comm, gko::dim<2>{this->rg->get_size()[0], 1},
249+
Dense::create(this->mpi_exec, gko::dim<2>{expected.get_size(), 1},
250+
expected, 1));
251+
GKO_ASSERT_MTX_NEAR(x->get_local_vector(), expected_vec->get_local_vector(),
252+
0.0);
253+
}
254+
255+
256+
TYPED_TEST(RowGatherer, CanApplyAsyncWithEventConsequetively)
257+
{
258+
using Dense = gko::matrix::Dense<double>;
259+
using Vector = gko::experimental::distributed::Vector<double>;
260+
int rank = this->comm.rank();
261+
auto offset = static_cast<double>(rank * 3);
262+
auto b = Vector::create(
263+
this->exec, this->comm, gko::dim<2>{18, 1},
264+
gko::initialize<Dense>({offset, offset + 1, offset + 2}, this->exec));
265+
auto expected = this->template create_recv_connections<double>()[rank];
266+
auto x = Vector::create(this->mpi_exec, this->comm,
267+
gko::dim<2>{this->rg->get_size()[0], 1},
268+
gko::dim<2>{expected.get_size(), 1});
269+
270+
this->rg->apply_finalize(b, x, this->rg->apply_prepare(b, x)).wait();
271+
this->rg->apply_finalize(b, x, this->rg->apply_prepare(b, x)).wait();
272+
273+
auto expected_vec = Vector::create(
274+
this->mpi_exec, this->comm, gko::dim<2>{this->rg->get_size()[0], 1},
275+
Dense::create(this->mpi_exec, gko::dim<2>{expected.get_size(), 1},
276+
expected, 1));
277+
GKO_ASSERT_MTX_NEAR(x->get_local_vector(), expected_vec->get_local_vector(),
278+
0.0);
279+
}
280+
281+
282+
TYPED_TEST(RowGatherer, CanApplyAsyncWithEventAndWorkspace)
283+
{
284+
using Dense = gko::matrix::Dense<double>;
285+
using Vector = gko::experimental::distributed::Vector<double>;
286+
int rank = this->comm.rank();
287+
auto offset = static_cast<double>(rank * 3);
288+
auto b = Vector::create(
289+
this->exec, this->comm, gko::dim<2>{18, 1},
290+
gko::initialize<Dense>({offset, offset + 1, offset + 2}, this->exec));
291+
auto expected = this->template create_recv_connections<double>()[rank];
292+
auto x = Vector::create(this->mpi_exec, this->comm,
293+
gko::dim<2>{this->rg->get_size()[0], 1},
294+
gko::dim<2>{expected.get_size(), 1});
295+
gko::array<char> workspace;
296+
297+
auto ev = this->rg->apply_prepare(b, x, workspace);
298+
auto req = this->rg->apply_finalize(b, x, ev, workspace);
299+
req.wait();
300+
301+
auto expected_vec = Vector::create(
302+
this->mpi_exec, this->comm, gko::dim<2>{this->rg->get_size()[0], 1},
303+
Dense::create(this->mpi_exec, gko::dim<2>{expected.get_size(), 1},
304+
expected, 1));
305+
GKO_ASSERT_MTX_NEAR(x->get_local_vector(), expected_vec->get_local_vector(),
306+
0.0);
307+
ASSERT_GT(workspace.get_size(), 0);
308+
}
309+
310+
311+
TYPED_TEST(RowGatherer, CanApplyAsyncMultipleTimesWithEventAndWorkspace)
312+
{
313+
using Dense = gko::matrix::Dense<double>;
314+
using Vector = gko::experimental::distributed::Vector<double>;
315+
int rank = this->comm.rank();
316+
auto offset = static_cast<double>(rank * 3);
317+
auto b1 = Vector::create(
318+
this->exec, this->comm, gko::dim<2>{18, 1},
319+
gko::initialize<Dense>({offset, offset + 1, offset + 2}, this->exec));
320+
auto b2 = gko::clone(b1);
321+
b2->scale(gko::initialize<Dense>({-1}, this->exec));
322+
auto expected = this->template create_recv_connections<double>()[rank];
323+
auto x1 = Vector::create(this->mpi_exec, this->comm,
324+
gko::dim<2>{this->rg->get_size()[0], 1},
325+
gko::dim<2>{expected.get_size(), 1});
326+
auto x2 = gko::clone(x1);
327+
gko::array<char> workspace1;
328+
gko::array<char> workspace2;
329+
330+
auto ev1 = this->rg->apply_prepare(b1, x1, workspace1);
331+
auto ev2 = this->rg->apply_prepare(b2, x2, workspace2);
332+
auto req1 = this->rg->apply_finalize(b1, x1, ev1, workspace1);
333+
auto req2 = this->rg->apply_finalize(b2, x2, ev2, workspace2);
334+
req1.wait();
335+
req2.wait();
336+
337+
auto expected_vec1 = Vector::create(
338+
this->mpi_exec, this->comm, gko::dim<2>{this->rg->get_size()[0], 1},
339+
Dense::create(this->mpi_exec, gko::dim<2>{expected.get_size(), 1},
340+
expected, 1));
341+
auto expected_vec2 = gko::clone(expected_vec1);
342+
expected_vec2->scale(gko::initialize<Dense>({-1}, this->exec));
343+
GKO_ASSERT_MTX_NEAR(x1->get_local_vector(),
344+
expected_vec1->get_local_vector(), 0.0);
345+
GKO_ASSERT_MTX_NEAR(x2->get_local_vector(),
346+
expected_vec2->get_local_vector(), 0.0);
347+
}
348+
349+
350+
TYPED_TEST(
351+
RowGatherer,
352+
CanApplyAsyncWithEventAndWorkspaceEnsuringPrepareAndFinalizeSeparately)
353+
{
354+
using Dense = gko::matrix::Dense<double>;
355+
using Vector = gko::experimental::distributed::Vector<double>;
356+
int rank = this->comm.rank();
357+
auto offset = static_cast<double>(rank * 3);
358+
auto b = Vector::create(
359+
this->exec, this->comm, gko::dim<2>{18, 1},
360+
gko::initialize<Dense>({offset, offset + 1, offset + 2}, this->exec));
361+
auto expected = this->template create_recv_connections<double>()[rank];
362+
auto modified_expected =
363+
gko::array<double>(expected.get_executor(), expected.get_size());
364+
modified_expected.fill(0.0);
365+
auto x = Vector::create(this->mpi_exec, this->comm,
366+
gko::dim<2>{this->rg->get_size()[0], 1},
367+
gko::dim<2>{expected.get_size(), 1});
368+
gko::array<char> workspace;
369+
370+
auto ev = this->rg->apply_prepare(b, x, workspace);
371+
// we modify the workspace to all 0
372+
workspace.fill(static_cast<char>(0));
373+
this->exec->synchronize();
374+
auto req = this->rg->apply_finalize(b, x, ev, workspace);
375+
req.wait();
376+
377+
auto expected_vec = Vector::create(
378+
this->mpi_exec, this->comm, gko::dim<2>{this->rg->get_size()[0], 1},
379+
Dense::create(this->mpi_exec,
380+
gko::dim<2>{modified_expected.get_size(), 1},
381+
modified_expected, 1));
382+
GKO_ASSERT_MTX_NEAR(x->get_local_vector(), expected_vec->get_local_vector(),
383+
0.0);
384+
}
385+
386+
229387
TYPED_TEST(RowGatherer, ThrowsOnNonMatchingExecutor)
230388
{
231389
if (this->mpi_exec == this->exec) {

0 commit comments

Comments
 (0)