Skip to content

Commit 85dfc7b

Browse files
committed
add test and char instantiation on array fill
1 parent f716c56 commit 85dfc7b

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
@@ -227,6 +227,164 @@ TYPED_TEST(RowGatherer, CanApplyAsyncWithMultipleColumns)
227227
}
228228

229229

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

0 commit comments

Comments
 (0)