Skip to content

Commit

Permalink
Track and check step-var indices. Closes #194.
Browse files Browse the repository at this point in the history
  • Loading branch information
chuck.yount committed Apr 4, 2019
1 parent db54e84 commit c9afdb3
Show file tree
Hide file tree
Showing 14 changed files with 420 additions and 270 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ YASK contains a domain-specific compiler to convert scalar stencil code to SIMD-
for functional testing if you don't have native support for any given instruction set.

### Backward-compatibility notices, including changes in default behavior:
* Version 2.20.00 added checking of the step-dimension index value in the `yk_grid::get_element()` and similar APIs. Previously, invalid values silently "wrapped" around to valid ones. Now, the step index must be valid when reading, and the valid step indices are updated when writing.
* Version 2.19.01 turned off multi-pass tuning by default. Enable with `-auto_tune_each_pass`.
* Version 2.18.03 allowed the default radius to be stencil-specific and changed the names of example stencil "9axis" to "3axis_with_diags".
* Version 2.18.00 added the ability to specify the global-domain size, and it will calculate the local-domain sizes from it.
Expand Down
8 changes: 4 additions & 4 deletions include/yask_compiler_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace yask {
/**
C++ initializer-list version with same semantics as
new_grid(const std::string& name, const std::vector<yc_index_node_ptr>& dims).
@note This version is not available (or needed) in SWIG-based APIs, e.g., Python.
@note This version is not available (or needed) in the Python API.
@returns Pointer to the new \ref yc_grid object.
*/
virtual yc_grid_ptr
Expand Down Expand Up @@ -223,7 +223,7 @@ namespace yask {
/**
C++ initializer-list version with same semantics as
new_scratch_grid(const std::string& name, const std::vector<yc_index_node_ptr>& dims).
@note This version is not available (or needed) in SWIG-based APIs, e.g., Python.
@note This version is not available (or needed) in the Python API.
@returns Pointer to the new \ref yc_grid object.
*/
virtual yc_grid_ptr
Expand Down Expand Up @@ -492,7 +492,7 @@ namespace yask {
/**
C++ initializer-list version with same semantics as
new_grid_point(std::vector<yc_index_node_ptr> index_exprs).
@note This version is not available (or needed) in SWIG-based APIs, e.g., Python.
@note This version is not available (or needed) in the Python API.
@returns Pointer to AST node used to read or write from point in grid. */
virtual yc_grid_point_node_ptr
new_grid_point(const std::initializer_list<yc_number_node_ptr>& index_exprs) = 0;
Expand Down Expand Up @@ -523,7 +523,7 @@ namespace yask {
/**
C++ initializer-list version with same semantics as
new_relative_grid_point(std::vector<int> dim_offsets).
@note This version is not available (or needed) in SWIG-based APIs, e.g., Python.
@note This version is not available (or needed) in the Python API.
@returns Pointer to AST node used to read or write from point in grid. */
virtual yc_grid_point_node_ptr
new_relative_grid_point(const std::initializer_list<int>& dim_offsets) = 0;
Expand Down
300 changes: 174 additions & 126 deletions include/yk_grid_api.hpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions include/yk_solution_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ namespace yask {
/**
See documentation for the version of new_grid() with a vector of dimension names
as a parameter.
@note This version is not available (or needed) in SWIG-based APIs, e.g., Python.
@note This version is not available (or needed) in the Python API.
@returns Pointer to the new grid.
*/
virtual yk_grid_ptr
Expand Down Expand Up @@ -786,7 +786,7 @@ namespace yask {
/**
See documentation for the version of new_fixed_size_grid() with a vector of dimension names
as a parameter.
@note This version is not available (or needed) in SWIG-based APIs, e.g., Python.
@note This version is not available (or needed) in the Python API.
@returns Pointer to the new grid.
*/
virtual yk_grid_ptr
Expand Down
2 changes: 1 addition & 1 deletion src/common/common_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace yask {
// for numbers above 9 (at least up to 99).

// Format: "major.minor.patch".
const string version = "2.19.04";
const string version = "2.20.00";

string yask_get_version_string() {
return version;
Expand Down
20 changes: 7 additions & 13 deletions src/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ py-api-no-yc:
$(MAKE) $(NO_YC_MAKE_FLAGS) py-api

# Validation runs for each binary.
DEF_TEST_ARGS := -stencil $(YK_STENCIL) -arch $(YK_ARCH) -v \
DEF_TEST_ARGS := -ranks $(ranks) -stencil $(YK_STENCIL) -arch $(YK_ARCH) -v \
-trial_steps 2 -max_threads 6 -block_threads 2 -no-use_shm -overlap_comms

val0 := $(DEF_TEST_ARGS) -l 48 -r 32 -b 24 -rt 0 $(EXTRA_TEST_ARGS)
Expand All @@ -800,24 +800,18 @@ yk-tests:
$(YK_SCRIPT) $(val2)
$(YK_SCRIPT) $(val3)
$(YK_SCRIPT) $(val4a)

yk-mp-tests:
$(YK_SCRIPT) -ranks $(ranks) $(val0)
$(YK_SCRIPT) -ranks $(ranks) $(val1)
$(YK_SCRIPT) -ranks $(ranks) $(val2)
$(YK_SCRIPT) -ranks $(ranks) $(val3)
$(YK_SCRIPT) -ranks $(ranks) $(val4b)
$(YK_SCRIPT) -ranks $(ranks) $(val4c)
$(YK_SCRIPT) $(val4b)
$(YK_SCRIPT) $(val4c)

# Run the default YASK compiler and kernel.
yc-and-yk-test: $(YK_EXEC) $(YK_SCRIPT)
$(MAKE) yk-tests
if (( $(ranks) > 1 )); then $(MAKE) yk-mp-tests; fi
$(MAKE) ranks=1 yk-tests
if (( $(ranks) > 1 )); then $(MAKE) yk-tests; fi

# Run the YASK kernel test without implicity using the YASK compiler.
yk-test-no-yc: kernel-no-yc $(YK_SCRIPT)
$(MAKE) yk-tests
if (( $(ranks) > 1 )); then $(MAKE) yk-mp-tests; fi
$(MAKE) ranks=1 yk-tests
if (( $(ranks) > 1 )); then $(MAKE) yk-tests; fi

# Run the kernel API tests for C++ and Python with and w/o expected exceptions.
api-tests:
Expand Down
66 changes: 33 additions & 33 deletions src/kernel/lib/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace yask {
// rank. This is needed because neighbors will not know what
// grids are actually dirty, and all ranks must have the same
// information about which grids are possibly dirty.
mark_grids_dirty(nullptr, start_t, stop_t);
update_grids(nullptr, start_t, stop_t, true);

} // all bundles.

Expand All @@ -183,7 +183,7 @@ namespace yask {
exchange_halos();

run_time.stop();
}
} // run_ref.

// Eval stencil bundle pack(s) over grid(s) using optimized code.
void StencilContext::run_solution(idx_t first_step_index,
Expand Down Expand Up @@ -405,7 +405,7 @@ namespace yask {
// same information about which grids are possibly
// dirty. TODO: make this smarter to save unneeded
// MPI exchanges.
mark_grids_dirty(bp, start_t, stop_t);
update_grids(bp, start_t, stop_t, true);

// Do the appropriate steps for halo exchange of exterior.
// TODO: exchange halo for each dim as soon as it's done.
Expand All @@ -426,8 +426,8 @@ namespace yask {
#include "yask_rank_loops.hpp"

// Mark as dirty only if we did exterior.
if (do_mpi_left || do_mpi_right)
mark_grids_dirty(bp, start_t, stop_t);
bool mark_dirty = do_mpi_left || do_mpi_right;
update_grids(bp, start_t, stop_t, mark_dirty);

// Do the appropriate steps for halo exchange depending
// on 'do_mpi_*' flags.
Expand Down Expand Up @@ -483,7 +483,7 @@ namespace yask {
} // domain dims.

// Mark grids dirty for all packs.
mark_grids_dirty(bp, start_t, stop_t);
update_grids(bp, start_t, stop_t, true);

// Do the appropriate steps for halo exchange of exterior.
// TODO: exchange halo for each dim as soon as it's done.
Expand All @@ -504,8 +504,8 @@ namespace yask {
#include "yask_rank_loops.hpp"

// Mark as dirty only if we did exterior.
if (do_mpi_left || do_mpi_right)
mark_grids_dirty(bp, start_t, stop_t);
bool mark_dirty = do_mpi_left || do_mpi_right;
update_grids(bp, start_t, stop_t, mark_dirty);

// Do the appropriate steps for halo exchange depending
// on 'do_mpi_*' flags.
Expand Down Expand Up @@ -1639,10 +1639,13 @@ namespace yask {
continue;

// Check all allocated step indices.
idx_t stop_t = 1;
if (gp->is_dim_used(step_dim))
stop_t = gp->get_alloc_size(step_dim);
for (idx_t t = 0; t < stop_t; t++) {
// Use '0' for grids that don't use the step dim.
idx_t start_t = 0, stop_t = 1;
if (gp->is_dim_used(step_dim)) {
start_t = gp->get_first_valid_step_index();
stop_t = gp->get_last_valid_step_index() + 1;
}
for (idx_t t = start_t; t < stop_t; t++) {

// Only need to swap grids whose halos are not up-to-date
// for this step.
Expand All @@ -1652,13 +1655,14 @@ namespace yask {
// Swap this grid.
gridsToSwap[gname] = gp;

// Update last step.
lastStepsToSwap[gp] = t;

// First?
if (firstStepsToSwap.count(gp) == 0)
// Update first step.
if (firstStepsToSwap.count(gp) == 0 || t < firstStepsToSwap[gp])
firstStepsToSwap[gp] = t;

// Update last step.
if (lastStepsToSwap.count(gp) == 0 || t > lastStepsToSwap[gp])
lastStepsToSwap[gp] = t;

} // steps.
} // grids.
TRACE_MSG("exchange_halos: need to exchange halos for " <<
Expand Down Expand Up @@ -1781,9 +1785,7 @@ namespace yask {
(send_vec_ok ? "with" : "without") <<
" vector copy into " << buf);
if (send_vec_ok)
nelems = gp->get_vecs_in_slice(buf,
first, firstStepsToSwap[gp],
last, lastStepsToSwap[gp]);
nelems = gp->get_vecs_in_slice(buf, first, last);
else
nelems = gp->get_elements_in_slice(buf, first, last);
idx_t nbytes = nelems * get_element_bytes();
Expand Down Expand Up @@ -1853,9 +1855,7 @@ namespace yask {
(recv_vec_ok ? "with" : "without") <<
" vector copy from " << buf);
if (recv_vec_ok)
nelems = gp->set_vecs_in_slice(buf,
first, firstStepsToSwap[gp],
last, lastStepsToSwap[gp]);
nelems = gp->set_vecs_in_slice(buf, first, last);
else
nelems = gp->set_elements_in_slice(buf, first, last);
assert(nelems <= recvBuf.get_size());
Expand Down Expand Up @@ -1918,12 +1918,10 @@ namespace yask {
#endif
}

// Mark grids that have been written to by bundle pack 'sel_bp'.
// TODO: only mark grids that are written to in their halo-read area.
// TODO: add index for misc dim(s).
// TODO: track sub-domain of grid that is dirty.
void StencilContext::mark_grids_dirty(const BundlePackPtr& sel_bp,
idx_t start, idx_t stop) {
// Update data in grids that have been written to by bundle pack 'sel_bp'.
void StencilContext::update_grids(const BundlePackPtr& sel_bp,
idx_t start, idx_t stop,
bool mark_dirty) {
STATE_VARS(this);
idx_t stride = (start > stop) ? -1 : 1;
map<YkGridPtr, set<idx_t>> grids_done;
Expand Down Expand Up @@ -1952,18 +1950,20 @@ namespace yask {
// scratch grids as dirty because they are never exchanged.
for (auto gp : sb->outputGridPtrs) {

// Mark output step as dirty if not already done.
// Update if not already done.
if (grids_done[gp].count(t_out) == 0) {
gp->set_dirty(true, t_out);
gp->update_valid_step(t_out);
if (mark_dirty)
gp->set_dirty(true, t_out);
TRACE_MSG("grid '" << gp->get_name() <<
"' marked as dirty at step " << t_out);
"' updated at step " << t_out);
grids_done[gp].insert(t_out);
}
}
} // bundles.
} // steps.
} // packs.
} // mark_grids_dirty().
} // update_grids().

// Reset any locks, etc.
void StencilContext::reset_locks() {
Expand Down
8 changes: 5 additions & 3 deletions src/kernel/lib/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,12 @@ namespace yask {
// Call MPI_Test() on all unfinished requests to promote MPI progress.
void poke_halo_exchange();

// Mark grids that have been written to by bundle pack 'sel_bp'.
// Update valid steps in grids that have been written to by bundle pack 'sel_bp'.
// If sel_bp==null, use all bundles.
void mark_grids_dirty(const BundlePackPtr& sel_bp,
idx_t start, idx_t stop);
// If 'mark_dirty', also mark as needing halo exchange.
void update_grids(const BundlePackPtr& sel_bp,
idx_t start, idx_t stop,
bool mark_dirty);

// Set various limits in 'idxs' based on current step in region.
bool shift_region(const Indices& base_start, const Indices& base_stop,
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/lib/generic_grids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace yask {
const static int _numa_unset = -999;
int _numa_pref = _numa_unset; // use default from _opts.

// Note that both _dims and *_layout_base hold dimensions unless this
// Note that both _dims and *_layout_base hold sizes unless this
// is a scalar. For a scalar, _dims is empty and _layout_base = 0.
IdxTuple _grid_dims; // names and lengths of grid dimensions.
Layout* _layout_base = 0; // memory layout.
Expand Down
Loading

0 comments on commit c9afdb3

Please sign in to comment.