Skip to content

Commit

Permalink
Merge pull request #231 from intel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chuckyount authored Jul 9, 2019
2 parents 35730ba + 9c91104 commit 834e950
Show file tree
Hide file tree
Showing 20 changed files with 160 additions and 85 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* New YASK users may want to start with the [YASK tutorial](http://intel.github.io/yask/YASK-tutorial.pdf).
* Users with existing YASK-based code may want to jump to the [backward-compatibility notices](#backward-compatibility-notices).
* All YASK users will also be interested in the [API documentation](http://intel.github.io/yask/api/html/index.html).

## Overview
YASK is a framework to rapidly create high-performance stencil code including optimizations and features such as
Expand All @@ -11,7 +12,7 @@ YASK is a framework to rapidly create high-performance stencil code including op
* Scaling to multiple sockets and nodes via MPI with overlapped communication and compute.
* Spatial tiling with automatically-tuned block sizes.
* Temporal tiling in multiple dimensions to further increase cache locality.
* APIs for C++ and Python: [API documentation](http://intel.github.io/yask/api/html/index.html)
* APIs for C++ and Python.

YASK contains a domain-specific compiler to convert stencil-equation specifications to SIMD-optimized code for Intel(R) Xeon Phi(TM) and Intel(R) Xeon(R) processors.

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 = "3.01.00";
const string version = "3.01.01";

string yask_get_version_string() {
return version;
Expand Down
85 changes: 63 additions & 22 deletions src/common/common_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,51 +179,92 @@ namespace yask {

// Set that retains order of things added.
// Or, vector that allows insertion if element doesn't exist.
// TODO: hide vector inside class and provide proper accessor methods.
template <typename T>
class vector_set : public std::vector<T> {
std::map<T, size_t> _posn;

private:
virtual void push_front(const T& val) {
THROW_YASK_EXCEPTION("push_front() not allowed");
}
class vector_set final {
std::vector<T> _items; // no duplicates.
std::map<T, size_t> _posn; // _posn[_items[i]] = i;

public:
vector_set() {}
virtual ~vector_set() {}
~vector_set() {}

// Copy ctor.
vector_set(const vector_set& src) :
std::vector<T>(src), _posn(src._posn) {}
// Default assign and copy ctor are okay.

virtual size_t count(const T& val) const {
// STL methods.
// Do not provide any non-const iterators or element access to prevent
// breaking _items <-> _posn relationship.
typename std::vector<T>::const_iterator begin() const {
return _items.begin();
}
typename std::vector<T>::const_iterator end() const {
return _items.end();
}
const T& at(size_t i) const {
return _items.at(i);
}
const T& operator[](size_t i) const {
return _items[i];
}
const T& front() const {
return _items.front();
}
const T& back() const {
return _items.back();
}
size_t size() const {
assert(_items.size() == _posn.size());
return _items.size();
}
bool empty() const {
return size() == 0 ;
}
size_t count(const T& val) const {
assert(_items.size() == _posn.size());
return _posn.count(val);
}
virtual void insert(const T& val) {
void insert(const T& val) {
assert(_items.size() == _posn.size());
if (_posn.count(val) == 0) {
std::vector<T>::push_back(val);
_posn[val] = std::vector<T>::size() - 1;
_items.push_back(val);
_posn[val] = _items.size() - 1;
}
assert(_items.size() == _posn.size());
}
virtual void push_back(const T& val) {
insert(val);
void push_back(const T& val) {
insert(val); // Does nothing if already exists.
}
virtual void erase(const T& val) {
void erase(const T& val) {
if (_posn.count(val) > 0) {
size_t op = _posn.at(val);
std::vector<T>::erase(std::vector<T>::begin() + op);
_items.erase(_items.begin() + op);

// Repair positions of items after 'val'.
for (auto pi : _posn) {
auto& p = pi.second;
if (p > op)
p--;
}
_posn.erase(val);
}
assert(_items.size() == _posn.size());
}
virtual void clear() {
std::vector<T>::clear();
void clear() {
_items.clear();
_posn.clear();
}

// New methods.
void swap(size_t i, size_t j) {
assert(i < _items.size());
assert(j < _items.size());
if (i == j)
return;
T tmp = _items[i];
_items[i] = _items[j];
_items[j] = tmp;
_posn[_items[i]] = i;
_posn[_items[j]] = j;
}
};

} // namespace.
Expand Down
22 changes: 19 additions & 3 deletions src/common/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ namespace yask {
void setVal(const T& val) { _val = val; }

// Comparison ops.
// Compare name pointers and actual names in case there
// is more than one pool, which can happen when loading
// more than one dynamic lib.
bool operator==(const Scalar& rhs) const {
return _val == rhs._val &&
(_namep == rhs._namep || *_namep == *rhs._namep);
Expand All @@ -133,7 +136,7 @@ namespace yask {
return (_val < rhs._val) ? true :
(_val > rhs._val) ? false :
(_namep == rhs._namep) ? false :
(*_namep < *rhs._namep) ? true : false;
(*_namep < *rhs._namep);
}
};

Expand Down Expand Up @@ -183,6 +186,12 @@ namespace yask {
const std::vector<Scalar<T>>& getDims() const {
return _q;
}
typename std::vector<Scalar<T>>::const_iterator begin() const {
return _q.begin();
}
typename std::vector<Scalar<T>>::const_iterator end() const {
return _q.end();
}

// Clear data.
void clear() {
Expand Down Expand Up @@ -251,10 +260,17 @@ namespace yask {
// Return dim posn or -1 if it doesn't exist.
// Lookup by name.
int lookup_posn(const std::string& dim) const {

// First check pointers.
for (size_t i = 0; i < _q.size(); i++) {
auto& s = _q[i];
if (s.getNamePtr() == &dim)
return int(i);
}

// Then check full strings.
for (size_t i = 0; i < _q.size(); i++) {
auto& s = _q[i];

// Check for match of name.
if (s.getName() == dim)
return int(i);
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/lib/Cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace yask {
// x=>x_elem, y=>(y_elem+2), z=>(z_elem+1) in var-point
// index args.
VarMap vMap;
for (auto& dim : vecPoint.getDims()) {
for (auto& dim : vecPoint) {
auto& dname = dim.getName();
int dofs = dim.getVal();

Expand Down Expand Up @@ -692,7 +692,7 @@ namespace yask {
auto& fold = getFold();
os << "\n // Element indices derived from vector indices.\n";
int i = 0;
for (auto& dim : fold.getDims()) {
for (auto& dim : fold) {
auto& dname = dim.getName();
string ename = dname + _elemSuffix;
string cap_dname = PrinterBase::allCaps(dname);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/lib/Eqs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace yask {
" cannot have a step condition");

// LHS must have all domain dims.
for (auto& dd : dims._domainDims.getDims()) {
for (auto& dd : dims._domainDims) {
auto& dname = dd.getName();
numExprPtr dexpr = op1->getArg(dname);
if (!dexpr)
Expand Down Expand Up @@ -580,7 +580,7 @@ namespace yask {
// dim is a simple offset. For example, in var dim 'x', the
// index in the corresponding posn must be 'x', 'x+n', or 'x-n'.
int fdoffsets = 0;
for (auto fdim : _dims._foldGT1.getDims()) {
for (auto fdim : _dims._foldGT1) {
auto& fdname = fdim.getName();
if (gp->getArgOffsets().lookup(fdname))
fdoffsets++;
Expand Down
12 changes: 5 additions & 7 deletions src/compiler/lib/Eqs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,16 @@ namespace yask {
// Want to keep original order as much as possible.
// Only reorder if dependencies are in conflict.

// Scan from beginning to end.
for (size_t i = 0; i < _all.size(); i++) {
auto& oi = _all.at(i);
// Scan from beginning to next-to-last.
for (size_t i = 0; i < _all.size() - 1; i++) {

// Repeat until no dependent found.
bool done = false;
while (!done) {

// Does obj[i] depend on any obj after it?
auto& oi = _all.at(i);
done = true;
for (size_t j = i+1; j < _all.size(); j++) {
auto& oj = _all.at(j);

Expand All @@ -296,16 +297,13 @@ namespace yask {
}

// Swap them.
auto temp = oi;
oi = oj;
oj = temp;
_all.swap(i, j);

// Start over at index i.
done = false;
break;
}
}
done = true;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/lib/Expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ namespace yask {

// Set given args to be given offsets.
virtual void setArgOffsets(const IntTuple& offsets) {
for (auto ofs : offsets.getDims())
for (auto ofs : offsets)
setArgOffset(ofs);
}

Expand Down
10 changes: 5 additions & 5 deletions src/compiler/lib/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace yask {

// Extract domain fold lengths based on cmd-line options.
IntTuple foldOpts;
for (auto& dim : _domainDims.getDims()) {
for (auto& dim : _domainDims) {
auto& dname = dim.getName();

// Was folding specified for this dim?
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace yask {
// sizes.
else {
IntTuple innerOpts;
for (auto& dim : _domainDims.getDims()) {
for (auto& dim : _domainDims) {
auto& dname = dim.getName();
if (dname == _innerDim)
continue;
Expand All @@ -208,7 +208,7 @@ namespace yask {
}

// Put them into the fold.
for (auto& dim : _domainDims.getDims()) {
for (auto& dim : _domainDims) {
auto& dname = dim.getName();
if (dname == _innerDim)
_fold[dname] = inner_sz;
Expand All @@ -227,7 +227,7 @@ namespace yask {
}

// Set foldGT1.
for (auto i : _fold.getDims()) {
for (auto i : _fold) {
auto& dname = i.getName();
auto& val = i.getVal();
if (val > 1)
Expand All @@ -254,7 +254,7 @@ namespace yask {
}

// Create final cluster lengths based on cmd-line options.
for (auto& dim : settings._clusterOptions.getDims()) {
for (auto& dim : settings._clusterOptions) {
auto& dname = dim.getName();
int mult = dim.getVal();

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/lib/Var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace yask {
}

// Find the number of folded dims used in this var.
for (auto fdim : dims._foldGT1.getDims()) {
for (auto fdim : dims._foldGT1) {
auto& fdname = fdim.getName();

// Search for dim in var.
Expand Down Expand Up @@ -203,7 +203,7 @@ namespace yask {
for (auto& i1 : m1) {
auto& step = i1.first;
const IntTuple& ohalos = i1.second;
for (auto& dim : ohalos.getDims()) {
for (auto& dim : ohalos) {
auto& dname = dim.getName();
auto& val = dim.getVal();

Expand Down Expand Up @@ -245,7 +245,7 @@ namespace yask {
int l1Dist = 0;

// Update halo vals.
for (auto& dim : offsets.getDims()) {
for (auto& dim : offsets) {
auto& dname = dim.getName();
int val = dim.getVal();
bool left = val <= 0;
Expand Down Expand Up @@ -283,7 +283,7 @@ namespace yask {
// Update const indices based on 'indices'.
void Var::updateConstIndices(const IntTuple& indices) {

for (auto& dim : indices.getDims()) {
for (auto& dim : indices) {
auto& dname = dim.getName();
int val = dim.getVal();

Expand Down
Loading

0 comments on commit 834e950

Please sign in to comment.