Skip to content

Commit

Permalink
Merge pull request #217 from intel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chuckyount authored Apr 30, 2019
2 parents 6f259f3 + 898dcef commit 916dc76
Show file tree
Hide file tree
Showing 31 changed files with 937 additions and 570 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ 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.22.00 changed the heuristic to determine vector-folding sizes when some
sizes are specified. This did not affect the default folding sizes.
* Version 2.21.02 simplified the example 3-D stencils (`3axis`, `3plane`, etc.)
to calculate simple averages like those in the MiniGhost benchmark.
This reduced the number of floating-point operations but not the number of points read for each stencil.
Expand Down
Binary file modified docs/YASK-tutorial.pdf
Binary file not shown.
48 changes: 44 additions & 4 deletions include/yask_compiler_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ namespace yask {
/// Create an n-dimensional grid variable in the solution.
/**
C++ initializer-list version with same semantics as
new_grid(const std::string& name, const std::vector<yc_index_node_ptr>& dims).
the vector version of new_grid().
@note This version is not available (or needed) in the Python API.
@returns Pointer to the new \ref yc_grid object.
*/
Expand Down Expand Up @@ -222,7 +222,7 @@ namespace yask {
/// Create an n-dimensional scratch-grid variable in the solution.
/**
C++ initializer-list version with same semantics as
new_scratch_grid(const std::string& name, const std::vector<yc_index_node_ptr>& dims).
the vector version of new_scratch_grid().
@note This version is not available (or needed) in the Python API.
@returns Pointer to the new \ref yc_grid object.
*/
Expand Down Expand Up @@ -320,6 +320,7 @@ namespace yask {
dot | DOT-language description.
dot-lite| DOT-language description of grid accesses only.
pseudo | Human-readable pseudo-code (for debug).
pseudo-long | Human-readable pseudo-code with intermediate variables.
Progress text will be written to the output stream set via set_debug_output().
Expand All @@ -335,6 +336,45 @@ namespace yask {
/**< [out] Pointer to object to receive formatted output.
See \ref yask_output_factory. */) =0;

/// **[Advanced]** Explicitly list the domain dimensions in the solution.
/**
In addition, domain dimension(s) are added when new_grid() or
new_scratch_grid() is called with one or more domain dimensions.
Either way, the last unique domain dimension specified will become the 'inner' or
'unit-stride' dimension in memory layouts.
Thus, this option can be used to override the default layout order.
It also allows specification of the domain dimensions in the
unusual case where a solution is defined without any
grids containing all of the domain dimensions.
*/
virtual void
set_domain_dims(const std::vector<yc_index_node_ptr>& dims
/**< [in] Domain dimensions of the solution. */ ) =0;

#ifndef SWIG
/// **[Advanced]** Explicitly list the domain dimensions in the solution.
/**
C++ initializer-list version with same semantics as
the vector version of new_grid().
@note This version is not available (or needed) in the Python API.
*/
virtual void
set_domain_dims(const std::initializer_list<yc_index_node_ptr>& dims
/**< [in] Domain dimensions of the solution. */ ) =0;
#endif

/// **[Advanced]** Explicitly identify the step dimension in the solution.
/**
By default, the step dimension is defined when new_grid() or
new_scratch_grid() is called with the step dimension.
This allows specification of the step dimension in the
unusual case where a solution is defined without any
grids containing the step dimension.
*/
virtual void
set_step_dim(const yc_index_node_ptr dim
/**< [in] Step dimension. */) =0;

/// **[Advanced]** Enable or disable automatic dependency checker.
/**
Disabling the built-in dependency checker may be done when it is
Expand Down Expand Up @@ -491,7 +531,7 @@ namespace yask {
/// Create a reference to a point in this grid.
/**
C++ initializer-list version with same semantics as
new_grid_point(std::vector<yc_index_node_ptr> index_exprs).
the vector version of new_grid_point().
@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
Expand Down Expand Up @@ -522,7 +562,7 @@ namespace yask {
/// Create a reference to a point in this grid using relative offsets.
/**
C++ initializer-list version with same semantics as
new_relative_grid_point(std::vector<int> dim_offsets).
the vector version of new_relative_grid_point().
@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
Expand Down
3 changes: 2 additions & 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.21.02";
const string version = "2.22.00";

string yask_get_version_string() {
return version;
Expand Down Expand Up @@ -159,4 +159,5 @@ namespace yask {
const char* yask_exception::get_message() const {
return _msg.c_str();
}

}
3 changes: 0 additions & 3 deletions src/common/tests/tuple_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ IN THE SOFTWARE.
using namespace std;
using namespace yask;

typedef Tuple<int> IntTuple;


void ttest(bool firstInner) {

ostream& os = cout;
Expand Down
92 changes: 92 additions & 0 deletions src/common/tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,98 @@ namespace yask {
return oss.str();
}

// Return a "compact" set of K factors of N.
template <typename T>
Tuple<T> Tuple<T>::get_compact_factors(idx_t N) const {
int K = getNumDims();

// Keep track of "best" result, where the best is most compact.
Tuple best;

// Trivial cases.
if (K == 0)
return best; // empty tuple.
if (N == 0) {
best = *this;
best.setValsSame(0); // tuple of all 0s.
return best;
}
if (product() == N)
return *this; // already done.

// Make list of factors of N.
vector<idx_t> facts;
for (idx_t n = 1; n <= N; n++)
if (N % n == 0)
facts.push_back(n);

// Try once with keeping pre-set values and then without.
for (bool keep : { true, false }) {

// Try every combo of K-1 factors.
// TODO: make more efficient--need algorithm to directly get
// set of K factors that are valid.
Tuple combos;
for (int j = 0; j < K; j++) {
auto& dname = getDimName(j);
auto dval = getVal(j);

// Number of factors.
auto sz = facts.size();

// Set first number of options 1 because it will be calculated
// based on the other values, i.e., we don't need to search over
// first dim. Also don't need to search any specified value.
if (j == 0 || (keep && dval > 0))
sz = 1;

combos.addDimBack(dname, sz);
}
combos.visitAllPoints
([&](const Tuple& combo, size_t idx)->bool {

// Make candidate tuple w/factors at given indices.
auto can = combo.mapElements([&](T in) {
return facts.at(in);
});

// Override with specified values.
for (int j = 0; j < K; j++) {
auto dval = getVal(j);
if (keep && dval > 0)
can[j] = dval;
else if (j == 0)
can[j] = -1; // -1 => needs to be calculated.
}

// Replace first factor with computed value if not set.
if (can[0] == -1) {
can[0] = 1; // to calculate product of remaining ones.
can[0] = N / can.product();
}

// Valid?
if (can.product() == N) {

// Best so far?
// Layout is better if max size is smaller.
if (best.size() == 0 ||
can.max() < best.max())
best = can;
}

return true; // keep looking.
});

if (best.product() == N)
break; // done.

} // keep or not.
assert(best.size() == K);
assert(best.product() == N);
return best;
}

// Explicitly allowed instantiations.
template class Tuple<int>;
template class Tuple<idx_t>;
Expand Down
14 changes: 13 additions & 1 deletion src/common/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@ namespace yask {
std::string prefix="",
std::string suffix="") const;

// Return a "compact" set of K factors of N,
// a set of factors with largest factor as small as possible,
// where K is the size of 'this'.
// Any non-zero numbers in 'this' will be kept if possible.
Tuple get_compact_factors(idx_t N) const;

// Call the 'visitor' lambda function at every point in the space defined by 'this'.
// 'idx' parameter contains sequentially-numbered index.
// Visitation order is with first dimension in unit stride, i.e., a conceptual
Expand Down Expand Up @@ -726,7 +732,13 @@ namespace yask {
#endif
}

};
}; // Tuple.

// Explicit types.
typedef Scalar<int> IntScalar;
typedef Scalar<idx_t> IdxScalar;
typedef Tuple<int> IntTuple;
typedef Tuple<idx_t> IdxTuple;

} // namespace yask.

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ YC_PY_LIB := $(PY_OUT_DIR)/_$(YC_MODULE)$(SO_SUFFIX)
YC_PY_MOD := $(PY_OUT_DIR)/$(YC_MODULE).py
YC_TEST_EXEC := $(BIN_OUT_DIR)/$(YC_BASE)_api_test.exe
YC_TEST_EXEC_WITH_EXCEPTION := $(BIN_OUT_DIR)/$(YC_BASE)_api_exception_test.exe
YC_SRC_NAMES := Expr ExprUtils Grid Eqs Print Vec Cpp CppIntrin YaskKernel Soln
YC_SRC_NAMES := Expr ExprUtils Grid Settings Eqs Print Vec Cpp CppIntrin YaskKernel Soln
YC_STENCIL_NAMES:= $(notdir $(patsubst %.cpp,%,$(wildcard $(YC_STENCIL_DIR)/*.cpp)))
YC_OBJS := $(addprefix $(YC_OBJ_DIR)/,$(addsuffix .o,$(YC_SRC_NAMES) $(COMM_SRC_NAMES)))
YC_STENCIL_OBJS := $(addprefix $(YC_OBJ_DIR)/,$(addsuffix .o,$(YC_STENCIL_NAMES)))
Expand Down
60 changes: 36 additions & 24 deletions src/compiler/lib/Eqs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,33 @@ namespace yask {

// Scratch grid must not have a condition.
if (cond1 && og1->isScratch())
THROW_YASK_EXCEPTION("Error: scratch-grid equation '" + eq1->makeQuotedStr() +
"' cannot have a domain condition");
THROW_YASK_EXCEPTION("Error: scratch-grid equation " + eq1->makeQuotedStr() +
" cannot have a domain condition");
if (stcond1 && og1->isScratch())
THROW_YASK_EXCEPTION("Error: scratch-grid equation '" + eq1->makeQuotedStr() +
"' cannot have a step condition");
THROW_YASK_EXCEPTION("Error: scratch-grid equation " + eq1->makeQuotedStr() +
" cannot have a step condition");

// LHS must have all domain dims.
for (auto& dd : dims._domainDims.getDims()) {
auto& dname = dd.getName();
NumExprPtr dexpr = op1->getArg(dname);
if (!dexpr)
THROW_YASK_EXCEPTION("Error: grid equation " + eq1->makeQuotedStr() +
" does not use domain-dimension '" + dname +
"' on LHS");
}

// LHS of non-scratch must have step dim and vice-versa.
if (!og1->isScratch()) {
if (!step_expr1)
THROW_YASK_EXCEPTION("Error: non-scratch grid equation " + eq1->makeQuotedStr() +
" does not use step-dimension '" + stepDim +
"' on LHS");
} else {
if (step_expr1)
THROW_YASK_EXCEPTION("Error: scratch-grid equation " + eq1->makeQuotedStr() +
" cannot use step-dimension '" + stepDim + "'");
}

// Check LHS grid dimensions and associated args.
for (int di = 0; di < og1->get_num_dims(); di++) {
Expand All @@ -215,13 +237,6 @@ namespace yask {

// Check based on dim type.
if (dn == stepDim) {

// Scratch grid must not use step dim.
if (og1->isScratch())
THROW_YASK_EXCEPTION("Error: scratch-grid '" + og1->getName() +
"' cannot use '" + dn + "' dim");

// Validity of step-dim expression in non-scratch grids is checked later.
}

// LHS must have simple indices in domain dims.
Expand All @@ -239,28 +254,25 @@ namespace yask {
" is expected");
}

// Misc dim must be a const.
// Misc dim must be a const. TODO: allow non-const misc
// dims and treat const and non-const ones separately, e.g.,
// for interleaving.
else {

if (!argn->isConstVal())
THROW_YASK_EXCEPTION("Error: LHS of equation " + eq1->makeQuotedStr() +
" contains expression " + argn->makeQuotedStr() +
" for misc dimension '" + dn +
"' where constant integer is expected");
"' where kernel-run-time constant integer is expected");
argn->getIntVal(); // throws exception if not an integer.
}
}

// Checks for a non-scratch eq.
// Heuristics to set the default step direction.
// The accuracy isn't critical, because the default is only be
// used in the standalone test utility and the auto-tuner.
if (!og1->isScratch()) {

if (!step_expr1)
THROW_YASK_EXCEPTION("Error: non-scratch-grid '" + og1->getName() +
"' does not use '" + stepDim + "' dim");

// Heuristics to set the default step direction.
// The accuracy isn't critical, because the default should only be
// used in the standalone test utility and the auto-tuner.
// First, see if LHS step arg is a simple offset, e.g., 'u(t+1, ...)'.
// This is the most common case.
auto& lofss = op1->getArgOffsets();
Expand All @@ -283,7 +295,7 @@ namespace yask {
dims._stepDir = 1;
break;
}
else if (lofs > rofs) {
else if (lofs < rofs) {
dims._stepDir = -1;
break;
}
Expand Down Expand Up @@ -1095,8 +1107,8 @@ namespace yask {
// eq1: u(t,x+1) on rhs and new halo of scr1 on lhs.

// Example:
// eq1: scr1(x) EQUALS u(t,x+1); <-|
// eq2: scr2(x) EQUALS u(t,x+2); <-- orig halo of u = max(1,2) = 2.
// eq1: scr1(x) EQUALS u(t,x+1); <--|
// eq2: scr2(x) EQUALS u(t,x+2); <--| orig halo of u = max(1,2) = 2.
// eq3: u(t+1,x) EQUALS scr1(x+3) + scr2(x+4);
// eq1 and eq2 are bundled => scr1 and scr2 halos are max(3,4) = 4.
// Direct deps: eq3 -> eq1(s), eq3 -> eq2(s).
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/lib/Eqs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ IN THE SOFTWARE.

///////// Classes for equations, equation bundles, and bundle packs. ////////////

#ifndef EQS_HPP
#define EQS_HPP
#pragma once

#include "Expr.hpp"
#include "Grid.hpp"
#include "Settings.hpp"

using namespace std;

Expand Down Expand Up @@ -700,4 +699,3 @@ namespace yask {

} // namespace yask.

#endif
4 changes: 0 additions & 4 deletions src/compiler/lib/Expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ using namespace std;

namespace yask {

// Collections of integers, used for dimensions, indices, etc.
typedef Scalar<int> IntScalar;
typedef Tuple<int> IntTuple;

// Forward-decls of expressions.
class Expr;
typedef shared_ptr<Expr> ExprPtr;
Expand Down
Loading

0 comments on commit 916dc76

Please sign in to comment.