Skip to content

Commit

Permalink
gh-164: add immediate execution of single task
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Oct 13, 2022
1 parent c800d05 commit 20b8394
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
9 changes: 9 additions & 0 deletions include/spla/schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ namespace spla {
*/
SPLA_API ref_ptr<Schedule> make_schedule();

/**
* @brief Immediately executes provided task and return only when task is finished
*
* @param task Task to execute immediately
*
* @return Ok if finished without errors
*/
SPLA_API Status execute_immediate(ref_ptr<ScheduleTask> task);

/**
* @brief Scheduled callback function
*
Expand Down
11 changes: 3 additions & 8 deletions src/algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,9 @@ namespace spla {
while (!frontier_empty) {
depth->set_int(current_level);

ref_ptr<Schedule> bfs_body = make_schedule();
ref_ptr<ScheduleTask> bfs_assign = make_sched_v_assign_masked(v, frontier_prev, depth, SECOND_INT);
ref_ptr<ScheduleTask> bfs_step = make_sched_mxv_masked(frontier_new, v, A, frontier_prev, MULT_INT, OR_INT, zero, complement);
ref_ptr<ScheduleTask> bfs_check = make_sched_v_reduce(frontier_size, zero, frontier_new, PLUS_INT);
bfs_body->step_task(bfs_assign);
bfs_body->step_task(bfs_step);
bfs_body->step_task(bfs_check);
bfs_body->submit();
spla::execute_immediate(make_sched_v_assign_masked(v, frontier_prev, depth, SECOND_INT));
spla::execute_immediate(make_sched_mxv_masked(frontier_new, v, A, frontier_prev, MULT_INT, OR_INT, zero, complement));
spla::execute_immediate(make_sched_v_reduce(frontier_size, zero, frontier_new, PLUS_INT));

int observed_vertices;
frontier_size->get_int(observed_vertices);
Expand Down
6 changes: 6 additions & 0 deletions src/schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ namespace spla {
return ref_ptr<Schedule>(new ScheduleSingleThread);
}

Status execute_immediate(ref_ptr<ScheduleTask> task) {
auto schedule = make_schedule();
schedule->step_task(std::move(task));
return schedule->submit();
}

ref_ptr<ScheduleTask> make_sched_callback(
ScheduleCallback callback,
ref_ptr<Descriptor> desc) {
Expand Down
4 changes: 1 addition & 3 deletions tests/test_mxv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ TEST(mxv_masked_comp, naive) {
iM->set_int(2, 2, 3);
iM->set_int(3, 4, -1);

auto schedule = spla::make_schedule();
schedule->step_task(spla::make_sched_mxv_masked(ir, imask, iM, iv, spla::MULT_INT, spla::PLUS_INT, iinit, true));
schedule->submit();
spla::execute_immediate(spla::make_sched_mxv_masked(ir, imask, iM, iv, spla::MULT_INT, spla::PLUS_INT, iinit, true));

int r;

Expand Down
16 changes: 4 additions & 12 deletions tests/test_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ TEST(vector, reduce_plus) {
isum += X[k];
}

auto schedule = spla::make_schedule();
schedule->step_task(spla::make_sched_v_reduce(ir, istart, ivec, spla::PLUS_INT));
schedule->submit();
spla::execute_immediate(spla::make_sched_v_reduce(ir, istart, ivec, spla::PLUS_INT));

int result;
ir->get_int(result);
Expand Down Expand Up @@ -110,9 +108,7 @@ TEST(vector, reduce_mult) {
isum *= X[k];
}

auto schedule = spla::make_schedule();
schedule->step_task(spla::make_sched_v_reduce(ir, istart, ivec, spla::MULT_INT));
schedule->submit();
spla::execute_immediate(spla::make_sched_v_reduce(ir, istart, ivec, spla::MULT_INT));

int result;
ir->get_int(result);
Expand Down Expand Up @@ -142,9 +138,7 @@ TEST(vector, assign_plus) {
R[I[k]] = R[I[k]] + S;
}

auto schedule = spla::make_schedule();
schedule->step_task(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::PLUS_INT));
schedule->submit();
spla::execute_immediate(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::PLUS_INT));

for (int k = 0; k < N; k++) {
int r;
Expand Down Expand Up @@ -175,9 +169,7 @@ TEST(vector, assign_second) {
R[I[k]] = S;
}

auto schedule = spla::make_schedule();
schedule->step_task(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::SECOND_INT));
schedule->submit();
spla::execute_immediate(spla::make_sched_v_assign_masked(ivec, imask, ival, spla::SECOND_INT));

for (int k = 0; k < N; k++) {
int r;
Expand Down

0 comments on commit 20b8394

Please sign in to comment.