Skip to content

Commit

Permalink
Merge pull request #105 from intel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chuckyount authored Apr 18, 2018
2 parents 5958e12 + ba8caf1 commit e912981
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 70 deletions.
2 changes: 1 addition & 1 deletion bin/gen_layouts.pl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ END

# Creation.
print " else if (ndims == $n && do_wrap == $wrap)\n",
" gp = make_shared<YkElemGrid<$layout, $wrap>>(_dims, name, dims, _opts, &_ostr);\n";
" gp = make_shared<YkElemGrid<$layout, $wrap>>(_dims, name, dims, &_opts, &_ostr);\n";
}
}

Expand Down
10 changes: 6 additions & 4 deletions bin/yask_kernel_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import numpy as np
import ctypes as ct
import argparse
import yask_kernel
import yask_kernel as yk

# Read data from grid using NumPy ndarray.
def read_grid(grid, timestep) :
Expand Down Expand Up @@ -156,8 +156,8 @@ def init_grid(grid, timestep) :
if __name__ == "__main__":

# The factories from which all other kernel objects are made.
kfac = yask_kernel.yk_factory()
ofac = yask_kernel.yask_output_factory()
kfac = yk.yk_factory()
ofac = yk.yask_output_factory()

# Initalize MPI, etc.
env = kfac.new_env()
Expand Down Expand Up @@ -196,11 +196,13 @@ def init_grid(grid, timestep) :
else :
soln.set_block_size(dim_name, 32)

# Make a test fixed-size grid.
# Make a test fixed-size grid and set its NUMA preference.
fgrid_sizes = ()
for dim_name in soln_dims :
fgrid_sizes += (5,)
fgrid = soln.new_fixed_size_grid("fgrid", soln_dims, fgrid_sizes)
fgrid.set_numa_preferred(yk.cvar.yask_numa_local)
fgrid.alloc_storage()

# Simple rank configuration in 1st dim only.
# In production runs, the ranks would be distributed along
Expand Down
33 changes: 28 additions & 5 deletions include/yask_kernel_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,27 @@ namespace yask {
#endif

/// Allocate grids on local NUMA node.
/**
This is used in yk_solution::set_default_numa_preferred
and yk_grid::set_numa_preferred.
In Python, specify as `yask_kernel.cvar.yask_numa_local`.
*/
const int yask_numa_local = -1;

/// Allocate grids across all available NUMA nodes.
/**
This is used in yk_solution::set_default_numa_preferred
and yk_grid::set_numa_preferred.
In Python, specify as `yask_kernel.cvar.yask_numa_interleave`.
*/
const int yask_numa_interleave = -2;

/// Do not specify any NUMA binding.
/**
This is used in yk_solution::set_default_numa_preferred
and yk_grid::set_numa_preferred.
In Python, specify as `yask_kernel.cvar.yask_numa_none`.
*/
const int yask_numa_none = -9;

// Forward declarations of classes and pointers.
Expand Down Expand Up @@ -711,17 +726,21 @@ namespace yask {
Instead of specifying a NUMA node, a special value may be used
to specify another policy as listed.
This setting may be overridden for any specific grid.
@returns `true` if NUMA preference was set;
`false` if NUMA preferences are not enabled.
*/
virtual void
virtual bool
set_default_numa_preferred(int numa_node
/**< [in] Preferred NUMA node for data
allocation. Alternatively, use
`yask_numa_local` for explicit
local-node allocation,
`yask_numa_interleave` for
interleaving pages across all nodes,
or `yask_numa_none` for no NUMA
policy. */) =0;
or `yask_numa_none` for no explicit NUMA
policy. These constants are defined in
the _Variable Documentation_ section of
\ref yask_kernel_api.hpp. */) =0;

/// **[Advanced]** Get the default preferred NUMA node on which to allocate data.
/**
Expand Down Expand Up @@ -1441,11 +1460,15 @@ namespace yask {
/// **[Advanced]** Set the default preferred NUMA node on which to allocate data.
/**
This value is used when allocating data for this grid.
Thus, the desired NUMA policy must be set before calling alloc_data()
or yk_solution::prepare_solution().
@returns `true` if NUMA preference was set;
`false` if NUMA preferences are not enabled.
*/
virtual void
virtual bool
set_numa_preferred(int numa_node
/**< [in] Preferred NUMA node.
See set_default_numa_preferred() for other options. */) =0;
See yk_solution::set_default_numa_preferred() for other options. */) =0;

/// **[Advanced]** Get the default preferred NUMA node on which to allocate data.
/**
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 @@ -41,7 +41,7 @@ namespace yask {
// for numbers above 9 (at least up to 99).

// Format: "major.minor.patch".
const string version = "2.05.06";
const string version = "2.05.08";

string yask_get_version_string() {
return version;
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/lib/YaskKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ namespace yask {
ctorCode += " " + grid + "_dim_names = {" +
gdims.makeDimStr(", ", "\"", "\"") + "};\n";
string initCode = " " + grid + "_ptr = std::make_shared<" + typeDef +
">(_dims, \"" + grid + "\", " + grid + "_dim_names, _opts, &_ostr);\n"
">(_dims, \"" + grid + "\", " + grid + "_dim_names, &_opts, &_ostr);\n"
" assert(" + grid + "_ptr);\n";

// Grid vars.
Expand Down Expand Up @@ -391,7 +391,7 @@ namespace yask {
if (!firstGrid)
newGridCode += " else";
newGridCode += " if (dims == " + grid + "_dim_names) gp = std::make_shared<" +
typeDef + ">(_dims, name, dims, _opts, &_ostr);\n";
typeDef + ">(_dims, name, dims, &_opts, &_ostr);\n";
}

} // grids.
Expand All @@ -416,7 +416,7 @@ namespace yask {
os << "\n // Make a new grid iff its dims match any in the stencil.\n"
" // Returns pointer to the new grid or nullptr if no match.\n"
" virtual YkGridPtr newStencilGrid(const std::string& name,"
" const GridDimNames& dims, KernelSettingsPtr settings) {\n"
" const GridDimNames& dims) {\n"
" YkGridPtr gp;\n" <<
newGridCode <<
" return gp;\n"
Expand Down
24 changes: 15 additions & 9 deletions src/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
stencil = iso3dfd
arch = snb
mpi = 1
numa = 1
real_bytes = 4
radius = 2
ranks = 1
Expand Down Expand Up @@ -429,21 +430,26 @@ YK_LD := $(YK_CXX)
YK_LIBS := -lrt
YK_LFLAGS := -Wl,-rpath=$(LIB_DIR) -L$(LIB_DIR) -l$(YK_BASE2)

# Add options for NUMA.
ifeq ($(numa),1)

# Look for libnuma.
# TODO: make this more portable.
ifneq ($(wildcard /usr/lib64/libnuma.so),)
YK_LIBS += -lnuma
MACROS += USE_NUMA
else ifneq ($(wildcard /usr/lib64/libnuma.so.1),)
YK_LIBS += /usr/lib64/libnuma.so.1
MACROS += USE_NUMA
endif

# Work-around missing numaif.h:
# IF numaif.h is found in /usr/include,
# THEN enable the macro to use it.
ifneq ($(shell find /usr/include -name 'numaif.h' | wc -l),0)
MACROS += USE_NUMAIF_H
endif

# Work-around missing libnuma.so:
# IF libnuma.so.1 exists AND "normal" libnuma can't be found,
# THEN use hard-coded libnuma.so.1,
# ELSE use "normal" libnuma.
ifeq ($(and $(wildcard /usr/lib64/libnuma.so.1),$(shell whereis libnuma |wc -w)),1)
YK_LIBS += /usr/lib64/libnuma.so.1
else
YK_LIBS += -lnuma
endif

# Tools.
Expand Down Expand Up @@ -738,9 +744,9 @@ yk-test-no-yc: kernel-only
# run the tests from the top-level Makefile.
all-tests:
$(MAKE) clean; $(MAKE) stencil=test_3d fold=x=4,y=2 cxx-yk-grid-test
$(MAKE) clean; $(MAKE) stencil=test_1d yc-and-yk-test
$(MAKE) clean; $(MAKE) stencil=iso3dfd real_bytes=8 cxx-yk-api-test
$(MAKE) clean; $(MAKE) stencil=iso3dfd py-yk-api-test
$(MAKE) clean; $(MAKE) stencil=test_1d yc-and-yk-test
$(MAKE) clean; $(MAKE) stencil=3axis fold=x=4,y=2 yc-and-yk-test
$(MAKE) clean; $(MAKE) stencil=9axis fold=z=2 yc-and-yk-test
$(MAKE) clean; $(MAKE) stencil=3plane fold=y=2,z=4 yc-and-yk-test
Expand Down
14 changes: 5 additions & 9 deletions src/kernel/lib/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,34 +1161,30 @@ namespace yask {
const std::string& type) {
ostream& os = get_ostr();

// Get default NUMA node from settings.
int numa_def = _opts->_numa_pref;

for (const auto& i : nbytes) {
int np = i.first;
int numa_pref = i.first;
size_t nb = i.second;
size_t ng = ngrids.at(np);
size_t ng = ngrids.at(numa_pref);

// Don't need pad after last one.
if (nb >= _data_buf_pad)
nb -= _data_buf_pad;

// What node?
int numa_pref = (np >= 0) ? np : numa_def;

// Allocate data.
os << "Allocating " << makeByteStr(nb) <<
" for " << ng << " " << type << "(s)";
#ifdef USE_NUMA
if (numa_pref >= 0)
os << " preferring NUMA node " << numa_pref;
else
os << " using NUMA policy " << numa_pref;
#endif
os << "...\n" << flush;
auto p = shared_numa_alloc<char>(nb, numa_pref);
TRACE_MSG("Got memory at " << static_cast<void*>(p.get()));

// Save using original key.
data_buf[np] = p;
data_buf[numa_pref] = p;
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/kernel/lib/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,7 @@ namespace yask {
// Make a new grid iff its dims match any in the stencil.
// Returns pointer to the new grid or nullptr if no match.
virtual YkGridPtr newStencilGrid (const std::string & name,
const GridDimNames & dims,
KernelSettingsPtr settings) =0;
const GridDimNames & dims) =0;

// Make a new grid with 'name' and 'dims'.
// Set sizes if 'sizes' is non-null.
Expand Down Expand Up @@ -654,8 +653,14 @@ namespace yask {
virtual idx_t get_num_ranks(const std::string& dim) const;
virtual idx_t get_rank_index(const std::string& dim) const;
virtual std::string apply_command_line_options(const std::string& args);
virtual void set_default_numa_preferred(int numa_node) {
virtual bool set_default_numa_preferred(int numa_node) {
#ifdef USE_NUMA
_opts->_numa_pref = numa_node;
return true;
#else
_opts->_numa_pref = yask_numa_none;
return numa_node == yask_numa_none;
#endif
}
virtual int get_default_numa_preferred() const {
return _opts->_numa_pref;
Expand Down
11 changes: 5 additions & 6 deletions src/kernel/lib/generic_grids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace yask {
GenericGridBase::GenericGridBase(string name,
Layout& layout_base,
const GridDimNames& dimNames,
KernelSettingsPtr settings,
KernelSettingsPtr* settings,
ostream** ostr) :
_name(name), _layout_base(&layout_base), _opts(settings), _ostr(ostr) {
for (auto& dn : dimNames)
Expand All @@ -51,22 +51,21 @@ namespace yask {
// Release any old data if last owner.
release_storage();

// Get default NUMA node from settings.
int numa_def = _opts->_numa_pref;

// What node?
int numa_pref = (_numa_pref >= 0) ? _numa_pref : numa_def;
int numa_pref = get_numa_pref();

// Alloc required number of bytes.
size_t sz = get_num_bytes();
os << "Allocating " << makeByteStr(sz) <<
" for grid '" << _name << "'";
#ifdef USE_NUMA
if (numa_pref >= 0)
os << " preferring NUMA node " << numa_pref;
else
os << " on local NUMA node";
#endif
os << "...\n" << flush;
_base = shared_numa_alloc<char>(sz, _numa_pref);
_base = shared_numa_alloc<char>(sz, numa_pref);

// No offset.
_elems = _base.get();
Expand Down
28 changes: 20 additions & 8 deletions src/kernel/lib/generic_grids.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,16 @@ namespace yask {
void* _elems = 0; // actual data, which may be offset from _base.

// Preferred NUMA node.
int _numa_pref = -1; // -1 => use default.
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
// is a scalar. For a scalar, _dims is empty and _layout_base = 0.
IdxTuple _dims; // names and lengths of grid dimensions.
Layout* _layout_base = 0; // memory layout.

// Command-line and env parameters.
KernelSettingsPtr _opts;
KernelSettingsPtr* _opts;

// Output stream for messages.
// Pointer-to-pointer to let it follow a parent's pointer.
Expand All @@ -76,7 +77,7 @@ namespace yask {
GenericGridBase(std::string name,
Layout& layout_base,
const GridDimNames& dimNames,
KernelSettingsPtr settings,
KernelSettingsPtr* settings,
std::ostream** ostr);

virtual ~GenericGridBase() { }
Expand All @@ -92,9 +93,20 @@ namespace yask {
void set_name(const std::string& name) { _name = name; }

// NUMA accessors.
virtual int get_numa_pref() const { return _numa_pref; }
virtual void set_numa_pref(int pref_numa_node) { _numa_pref = pref_numa_node; }

virtual int get_numa_pref() const {
return (_numa_pref != _numa_unset) ?
_numa_pref : (*_opts)->_numa_pref;
}
virtual bool set_numa_pref(int numa_node) {
#ifdef USE_NUMA
_numa_pref = numa_node;
return true;
#else
_numa_pref = yask_numa_none;
return numa_node == yask_numa_none;
#endif
}

// Access dims.
const IdxTuple& get_dims() const { return _dims; }

Expand Down Expand Up @@ -204,7 +216,7 @@ namespace yask {
GenericGridTemplate(std::string name,
Layout& layout_base,
const GridDimNames& dimNames,
KernelSettingsPtr settings,
KernelSettingsPtr* settings,
std::ostream** ostr) :
GenericGridBase(name, layout_base, dimNames, settings, ostr) { }

Expand Down Expand Up @@ -309,7 +321,7 @@ namespace yask {
// Construct an unallocated grid.
GenericGrid(std::string name,
const GridDimNames& dimNames,
KernelSettingsPtr settings,
KernelSettingsPtr* settings,
std::ostream** ostr) :
GenericGridTemplate<T>(name, _layout, dimNames, settings, ostr) {
assert(int(dimNames.size()) == _layout.get_num_sizes());
Expand Down
4 changes: 2 additions & 2 deletions src/kernel/lib/new_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace yask {

// First, try to make a grid that matches the layout in
// the stencil.
YkGridPtr gp = newStencilGrid(name, dims, _opts);
YkGridPtr gp = newStencilGrid(name, dims);

// If there was no match, use default layout.
if (!gp) {
Expand Down Expand Up @@ -76,7 +76,7 @@ namespace yask {

// Scalar?
if (ndims == 0)
gp = make_shared<YkElemGrid<Layout_0d, false>>(_dims, name, dims, _opts, &_ostr);
gp = make_shared<YkElemGrid<Layout_0d, false>>(_dims, name, dims, &_opts, &_ostr);

// Include auto-gen code for all other cases.
#include "yask_grid_code.hpp"
Expand Down
Loading

0 comments on commit e912981

Please sign in to comment.