Skip to content

Commit

Permalink
Merge pull request #8 from coneoproject/fixes
Browse files Browse the repository at this point in the history
Bunch of fixes
  • Loading branch information
FabioLuporini authored Jul 21, 2016
2 parents 41fba5c + 50ac500 commit 3ecde32
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 170 deletions.
68 changes: 39 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# The following environment variable(s) should be predefined:
# The following environment variable(s) should have been set:
#
# CXX
# CXX_OPTS
# SLOPE_ARCH (mac,linux)
# SLOPE_LIB (static,shared)
# SLOPE_ARCH (mac,linux) [default: linux]
# SLOPE_COMPILER (gnu,intel) [default: gnu]
# CXX_OPTS [default: -O3]
# MPICXX [default: mpicc]

#
# The following environment variable(s) can be predefined
Expand Down Expand Up @@ -32,29 +32,41 @@ ALL_OBJS = $(OBJ)/inspector.o $(OBJ)/partitioner.o $(OBJ)/coloring.o $(OBJ)/tile
$(OBJ)/parloop.o $(OBJ)/tiling.o $(OBJ)/map.o $(OBJ)/executor.o $(OBJ)/utils.o \
$(OBJ)/schedule.o

METIS_INC = $(SLOPE_METIS)/include
METIS_LIB = $(SLOPE_METIS)/lib
METIS_LINK = -L$(METIS_LIB) -lmetis
ifdef SLOPE_METIS
METIS_INC = -I$(SLOPE_METIS)/include
METIS_LIB = $(SLOPE_METIS)/lib
METIS_LINK = -L$(METIS_LIB) -lmetis
endif

#
# Compiler settings
#

CXX := $(CXX)
MPICXX := $(MPICXX)
CXXFLAGS := -std=c++0x $(CXX_OPTS) $(SLOPE_VTK)
CXX := g++
MPICXX := mpicc
CXXFLAGS := -std=c++0x -fPIC -O3 $(CXX_OPTS) $(SLOPE_VTK)
CLOCK_LIB = -lrt

ifeq ($(SLOPE_ARCH),linux)
CLOCK_LIB = -lrt
ifeq ($(SLOPE_COMPILER),gnu)
CXX := g++
endif
ifeq ($(SLOPE_COMPILER),intel)
CXX := icpc
endif

ifdef MPICXX
MPICXX := $(MPICXX)
endif

ifeq ($(SLOPE_LIB),shared)
LIBFLAGS = -fPIC
ifeq ($(SLOPE_ARCH),linux)
CLOCK_LIB = -lrt
endif

.PHONY: clean mklib

all: warning clean mklib sparsetiling tests demos
all: sparsetiling

full: warning clean mklib sparsetiling tests demos

warning:
@echo "Recommended compiler options for maximum performance on an Intel processor:"
Expand All @@ -65,21 +77,19 @@ mklib:

sparsetiling: mklib
@echo "Compiling the library"
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/inspector.cpp -o $(OBJ)/inspector.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/executor.cpp -o $(OBJ)/executor.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -I$(METIS_INC) -c $(ST_SRC)/partitioner.cpp -o $(OBJ)/partitioner.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/coloring.cpp -o $(OBJ)/coloring.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/map.cpp -o $(OBJ)/map.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/tile.cpp -o $(OBJ)/tile.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/parloop.cpp -o $(OBJ)/parloop.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/tiling.cpp -o $(OBJ)/tiling.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/schedule.cpp -o $(OBJ)/schedule.o
$(CXX) $(LIBFLAGS) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/utils.cpp -o $(OBJ)/utils.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/inspector.cpp -o $(OBJ)/inspector.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/executor.cpp -o $(OBJ)/executor.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) $(METIS_INC) -c $(ST_SRC)/partitioner.cpp -o $(OBJ)/partitioner.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/coloring.cpp -o $(OBJ)/coloring.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/map.cpp -o $(OBJ)/map.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/tile.cpp -o $(OBJ)/tile.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/parloop.cpp -o $(OBJ)/parloop.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/tiling.cpp -o $(OBJ)/tiling.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/schedule.cpp -o $(OBJ)/schedule.o
$(CXX) $(CXXFLAGS) -I$(ST_INC) -c $(ST_SRC)/utils.cpp -o $(OBJ)/utils.o
ar cru $(LIB)/libst.a $(ALL_OBJS)
ranlib $(LIB)/libst.a
ifeq ($(SLOPE_LIB),shared)
$(CXX) -shared -Wl,-soname,libst.so.1 -o $(LIB)/libst.so.1.0.1 $(ALL_OBJS)
endif
$(CXX) -shared -Wl,-soname,libst.so -o $(LIB)/libst.so $(ALL_OBJS) $(METIS_LINK)

tests: mklib
@echo "Compiling the tests"
Expand Down
2 changes: 2 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [ ] a proper configure - make - make install building process
- [ ] more unit testing, more demos
91 changes: 51 additions & 40 deletions python/slope_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Author: Fabio Luporini (2015)

import ctypes
from collections import defaultdict


### SLOPE C-types for python-C interaction ###
Expand All @@ -26,6 +25,7 @@ class Map(ctypes.Structure):
('map', ctypes.POINTER(ctypes.c_int)),
('size', ctypes.c_int)]


class Part(ctypes.Structure):
_fields_ = [('name', ctypes.c_char_p),
('data', ctypes.POINTER(ctypes.c_int)),
Expand Down Expand Up @@ -119,7 +119,9 @@ class Inspector(object):
int avgTileSize = tileSize;
int prefetchHalo = %(prefetchHalo)d;
inspector_t* insp = insp_init (avgTileSize, %(mode)s, %(coloring)s, %(mesh_map_list)s, %(partitionings_list)s, prefetchHalo, %(name)s);
bool ignoreWAR = %(ignore_war)s;
inspector_t* insp = insp_init (avgTileSize, %(mode)s, %(coloring)s, %(mesh_map_list)s,
%(partitionings_list)s, prefetchHalo, ignoreWAR, %(name)s);
%(loop_defs)s
Expand All @@ -136,19 +138,21 @@ class Inspector(object):
}
"""

def __init__(self, name):
def __init__(self, name, **kwargs):
self._name = name

self._sets = []
self._maps = []
self._loops = []
self._sets = kwargs.get('sets', [])
self._maps = kwargs.get('maps', [])
self._loops = kwargs.get('loops', [])

self._mesh_maps = []
self._partitionings = []
self._mesh_maps = kwargs.get('mesh_maps', [])
self._partitionings = kwargs.get('partitionings', [])

self._slope_part_mode = 'chunk'
self._slope_coloring = 'default'
self._slope_prefetch = 0
self._part_mode = kwargs.get('part_mode', 'chunk')
self._coloring = kwargs.get('coloring', 'default')
self._prefetch = kwargs.get('prefetch', 0)
self._seed_loop = kwargs.get('seed_loop', None)
self._ignore_war = kwargs.get('ignore_war', False)

def add_sets(self, sets):
"""Add ``sets`` to this Inspector
Expand Down Expand Up @@ -207,31 +211,6 @@ def add_partitionings(self, partitionings):
return (ctype, ctype(*[Part(s, v.ctypes.data_as(ctypes.POINTER(ctypes.c_int)),
v.size, max(v)) for n, _, _, v in partitionings]))

def set_part_mode(self, mode):
"""Set the seed iteration space partitioning mode. This method should be
called prior to /generate_code/.
:param mode: defaults to 'chunk' (available: 'chunk', 'metis')
"""
if mode not in ['chunk', 'metis']:
raise SlopeError("Invalid partitioning mode (available: 'chunk', 'metis')")
self._slope_part_mode = mode

def set_coloring(self, coloring):
"""Set the way tiles should be colored. This method should be called prior
to /generate_code/.
:param coloring: defaults to 'default' (available: 'default', 'rand', 'mincols')
"""
valid = ['default', 'rand', 'mincols']
if coloring not in valid:
raise SlopeError("Invalid coloring (available: %s)" % str(valid))
self._slope_coloring = coloring

def set_prefetch_halo(self, val):
assert isinstance(val, int) and val >= 0
self._slope_prefetch = val

def set_tile_size(self, tile_size):
"""Set a tile size for this Inspector"""
ctype = ctypes.c_int
Expand All @@ -242,6 +221,35 @@ def set_mpi_rank(self, rank):
ctype = ctypes.c_int
return (ctype, ctype(rank))

def drive_inspection(self, **kwargs):
"""Provide additional information to optimize the inspection phase.
This method should be called prior to ``generate_code``.
:param kwargs:
* 'ignore_war': inform the inspector that for the given loop chain
there is no need to track write-after-read dependencies.
* 'seed_loop': set the loop from which tiles are derived.
* 'prefetch': a value N such that N >= 0, default N = 0. N is the
software prefetch distance that will be used by the executor.
* 'coloring': set a coloring mode (available: ``default``, ``rand``,
``mincols``). May be used to improve load balancing.
* 'part_mode': set the seed loop partitioning mode (available:
``chunk``, ``metis``). May be used to improve load balancing.
"""
self._ignore_war = kwargs.get('ignore_war', False)

self._seed_loop = kwargs.get('seed_loop', 0)
assert self._seed_loop >= 0 and self._seed_loop < len(self._loops)

self._prefetch = kwargs.get('prefetch', 0)
assert isinstance(self._prefetch, int) and self._prefetch >= 0

self._coloring = kwargs.get('coloring', 'default')
assert self._coloring in ['default', 'rand', 'mincols']

self._part_mode = kwargs.get('part_mode', 'chunk')
assert self._part_mode in ['chunk', 'metis']

def add_extra_info(self):
"""Inspection/Execution can benefit of certain data fields that are not
strictly included in the loop chain definition. For example, for debugging
Expand Down Expand Up @@ -301,7 +309,7 @@ def generate_code(self):
avail = lambda s: all(i in [s[0] for s in self._sets] for i in s)

mesh_map_defs, mesh_map_list = "", "NULL"
if self._mesh_maps and self._slope_part_mode == 'metis':
if self._mesh_maps and self._part_mode == 'metis':
mesh_map_defs = [Inspector.mesh_map_def % ("mm_%s" % m[0], i, m[1], m[2], i, i)
for i, m in enumerate(self._mesh_maps) if avail([m[1], m[2]])]
mesh_map_defs += ["meshMaps->insert(mm_%s);" % m[0]
Expand All @@ -317,7 +325,9 @@ def generate_code(self):
for m in self._partitionings if avail([m[1]])]
partitionings_list = "setPartitionings"

coloring = "COL_%s" % self._slope_coloring.upper()
coloring = "COL_%s" % self._coloring.upper()

seed_loop = self._seed_loop if self._seed_loop is not None else len(self._loops) / 2

debug_mode = Inspector._globaldata.get('debug_mode')
coordinates = Inspector._globaldata.get('coordinates')
Expand All @@ -337,12 +347,13 @@ def generate_code(self):
'n_sets': len(self._sets),
'mode': Inspector._globaldata['mode'],
'coloring': coloring,
'prefetchHalo': self._slope_prefetch,
'seed': len(self._loops) / 2,
'prefetchHalo': self._prefetch,
'seed': seed_loop,
'mesh_map_defs': "\n ".join(mesh_map_defs),
'mesh_map_list': mesh_map_list,
'partitionings_defs': "\n ".join(partitionings_defs),
'partitionings_list': partitionings_list,
'ignore_war': str(self._ignore_war).lower(),
'name': '"%s"' % self._name,
'output_vtk': output_vtk,
'output_insp': output_insp
Expand Down
4 changes: 4 additions & 0 deletions sparsetiling/include/inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ typedef struct {
/* number of extra iterations in a tile, useful for SW prefetching */
int prefetchHalo;

/* should we ignore write-after-read dependencies during inspection ? */
bool ignoreWAR;

/* the following fields track the time spent in various code sections*/
double totalInspectionTime;
double partitioningTime;
Expand Down Expand Up @@ -98,6 +101,7 @@ inspector_t* insp_init (int tileSize,
map_list* meshMaps = NULL,
map_list* partitionings = NULL,
int prefetchHalo = 1,
bool ignoreWAR = false,
std::string name = "");

/*
Expand Down
2 changes: 2 additions & 0 deletions sparsetiling/include/schedule.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ typedef struct {
int* iter2color;
/* tiling direction */
direction_t direction;
/* has the schedule been computed ? */
bool computed;

} schedule_t;

Expand Down
14 changes: 12 additions & 2 deletions sparsetiling/include/tiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ typedef std::map<int, index_set> tracker_t;
* accessed as tiling forward that has to be used for backward tiling.
* @param conflictsTracker
* track conflicting tiles encountered by each tile during the tiling process
* @param ignoreWAR
* if true, avoid tracking write-after-read dependencies, which decreases
* inspection time and, potentially, improves load balancing. This may be useful
* in unstructured mesh codes.
*/
void project_forward (loop_t* tiledLoop,
schedule_t* tilingInfo,
projection_t* prevLoopProj,
projection_t* seedLoopProj,
tracker_t* conflictsTracker);
tracker_t* conflictsTracker,
bool ignoreWAR);

/*
* Project tiling and coloring of an iteration set to all sets that are
Expand All @@ -78,11 +83,16 @@ void project_forward (loop_t* tiledLoop,
* projection of tiling at loop_{i+1}.
* @param conflictsTracker
* track conflicting tiles encountered by each tile during the tiling process
* @param ignoreWAR
* if true, avoid tracking write-after-read dependencies, which decreases
* inspection time and, potentially, improves load balancing. This may be useful
* in unstructured mesh codes.
*/
void project_backward (loop_t* tiledLoop,
schedule_t* tilingInfo,
projection_t* prevLoopProj,
tracker_t* conflictsTracker);
tracker_t* conflictsTracker,
bool ignoreWAR);

/*
* Tile a parloop moving forward along the loop chain.
Expand Down
Loading

0 comments on commit 3ecde32

Please sign in to comment.