Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Simple engine #30

Merged
merged 27 commits into from
Aug 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7a3fb78
[simple-engine] cherry pick Minjie's refactoring on interface
hotpxl Aug 23, 2015
6bfcc7d
[simple-engine] fix typo and unmark virtual
hotpxl Aug 23, 2015
e149942
[simple-engine] WIP, need to refactor interface and remove inheritance
hotpxl Aug 23, 2015
cfe80c6
[simple-engine] A not so simple engine that should somehow work
hotpxl Aug 23, 2015
005db3a
[simple-engine] lint
hotpxl Aug 23, 2015
5dfc759
[simple-engine] remove unnecessary files
hotpxl Aug 24, 2015
6b948fd
[simple-engine] that goes worker
hotpxl Aug 24, 2015
c7146a7
[simple-engine] passed some tests
hotpxl Aug 24, 2015
fef28d2
[simple-engine] some document
hotpxl Aug 24, 2015
761e0e1
[simple-engine] implement missing functions
hotpxl Aug 24, 2015
11432db
[simple-engine] fix order
hotpxl Aug 24, 2015
50bf69b
[simple-engine] fix concurrency
hotpxl Aug 24, 2015
1ad9132
[simple-engine] fix a concurrency bug
hotpxl Aug 24, 2015
4662b4e
[simple-engine] lint
hotpxl Aug 24, 2015
d59a125
[simple-engine] Merge branch 'master' into simple-engine
hotpxl Aug 25, 2015
e71055c
[simple-engine] @antinucleon Sorry I had to turn this on to pass Doxygen
hotpxl Aug 25, 2015
be8312d
[simple-engine] heavier test on engine
hotpxl Aug 25, 2015
3a15c13
[simple-engine] add tests to Makefile
hotpxl Aug 25, 2015
e9ab2a2
[simple-engine] use macro for debugging
hotpxl Aug 25, 2015
a3dbb93
[simple-engine] fix engine bug
hotpxl Aug 25, 2015
6b1b9a1
[simple-engine] even more tests
hotpxl Aug 25, 2015
1c57396
[simple-engine] Merge branch 'master' into simple-engine
hotpxl Aug 26, 2015
602a436
[simple-engine] Merge branch 'master' into simple-engine
hotpxl Aug 28, 2015
e85fb0d
[simple-engine] fix concurrency bug
hotpxl Aug 29, 2015
5d4189e
[simple-engine] obj pool raw implementation
hotpxl Aug 29, 2015
bb16dc4
[simple-engine] Merge branch 'master' into simple-engine
hotpxl Aug 29, 2015
8628138
[simple-engine] fix counter
hotpxl Aug 29, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ ifneq ($(ADD_LDFLAGS), NONE)
LDFLAGS += $(ADD_LDFLAGS)
endif

#BIN = test/test_threaded_engine test/api_registry_test
BIN = tests/test_simple_engine
OBJ = narray_function_cpu.o
# add threaded engine after it is done
OBJCXX11 = reshape_cpu.o engine.o narray.o c_api.o operator.o symbol.o storage.o fully_connected_cpu.o static_graph.o activation_cpu.o graph_executor.o softmax_cpu.o elementwise_sum_cpu.o pooling_cpu.o convolution_cpu.o io.o iter_mnist.o
OBJCXX11 = reshape_cpu.o dag_engine.o simple_engine.o narray.o c_api.o operator.o symbol.o storage.o fully_connected_cpu.o static_graph.o activation_cpu.o graph_executor.o softmax_cpu.o elementwise_sum_cpu.o pooling_cpu.o convolution_cpu.o io.o iter_mnist.o
CUOBJ =
SLIB = lib/libmxnet.so
ALIB = lib/libmxnet.a
Expand All @@ -82,7 +81,8 @@ $(DMLC_CORE)/libdmlc.a:
+ cd $(DMLC_CORE); make libdmlc.a config=$(ROOTDIR)/$(config); cd $(ROOTDIR)

storage.o: src/storage/storage.cc
engine.o: src/dag_engine/simple_engine.cc
dag_engine.o: src/dag_engine/dag_engine.cc
simple_engine.o: src/dag_engine/simple_engine.cc
narray.o: src/narray/narray.cc
narray_function_cpu.o: src/narray/narray_function.cc src/narray/narray_function-inl.h
narray_function_gpu.o: src/narray/narray_function.cu src/narray/narray_function-inl.h
Expand Down Expand Up @@ -111,7 +111,8 @@ iter_mnist.o: src/io/iter_mnist.cc
lib/libmxnet.a: $(OBJ) $(OBJCXX11) $(CUOBJ) $(LIB_DEP)
lib/libmxnet.so: $(OBJ) $(OBJCXX11) $(CUOBJ) $(LIB_DEP)

test/test_storage: test/test_storage.cc lib/libmxnet.a
tests/test_storage: tests/test_storage.cc lib/libmxnet.a
tests/test_simple_engine: tests/test_simple_engine.cc lib/libmxnet.a

$(BIN) :
$(CXX) $(CFLAGS) -std=c++0x -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS)
Expand All @@ -125,7 +126,7 @@ $(OBJCXX11) :
$(SLIB) :
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS)

$(ALIB):
$(ALIB): $(OBJ) $(OBJCXX11)
ar cr $@ $+

$(CUOBJ) :
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ PERLMOD_MAKEVAR_PREFIX =
# C-preprocessor directives found in the sources and include files.
# The default value is: YES.

ENABLE_PREPROCESSING = NO
ENABLE_PREPROCESSING = YES

# If the MACRO_EXPANSION tag is set to YES doxygen will expand all macro names
# in the source code. If set to NO only conditional compilation will be
Expand Down
207 changes: 131 additions & 76 deletions include/mxnet/dag_engine.h
Original file line number Diff line number Diff line change
@@ -1,107 +1,162 @@
/*!
* Copyright (c) 2015 by Contributors
* Copyright (c) 2015 by Contributors
* \file dag_engine.h
* \brief dynamic data-flow dag engine that schedules
* operations in a concurrent way
* \brief DAG engine that schedules data.
*/
#ifndef MXNET_DAG_ENGINE_H_
#define MXNET_DAG_ENGINE_H_
#include <dmlc/base.h>
// check c++11

#if DMLC_USE_CXX11 == 0
#error "cxx11 was required for narray module"
#error "C++11 was required for DAG engine module."
#endif

#include <functional>
#include <vector>
#include "./base.h"
#include "./context.h"
#include "base.h"
#include "context.h"

namespace mxnet {

/*!
* \brief Namespace of engine implementation.
*/
namespace engine {

/*!
* \brief dynamic data-flow dag engine that schedules
* operations in a concurrent way
* \brief Inner representation of variable.
*/
struct Var;

/*!
* \brief Inner representation of operator.
*/
struct Opr;

} // namespace engine

/*!
* \brief Dynamic dataflow DAG engine that schedules operations.
*/
class DAGEngine {
public:
/*!
* \brief operation to pass to DAG engine
* \param ctx runtime context
* \brief Operation to pass to DAG engine.
*/
using Fn = std::function<void(RunContext)>;
/*!
* \brief Callback function to notify operation complete.
*/
using Callback = std::function<void()>;
/*!
* \brief Asynchronous operation to pass to DAG engine.
*/
using AsyncFn = std::function<void(RunContext, Callback)>;
/*!
* \brief Variable of dag engine, used to specify dependencies defined to be a
* pointer, that points to an internal data structure of the engine
* itself.
*/
using Variable = engine::Var*;
/*!
* \brief Operator of the engine.
*/
using OprHandle = engine::Opr*;
/*!
* \brief Allocate a new variable, the variable can then
* be used to schedule the operation concurrently via dependency
* patterns.
* \return The new variable allocated.
*/
virtual Variable NewVar() = 0;
/*!
* \brief Create a new operator. The returned operator could be saved
* externally so that it could be resued for scheduling.
* \param fn The execution function.
* \param use_vars The variables that current operation will use but not
* mutate.
* \param mutate_vars Teh variables that current operation will mutate.
* \return The new operator allocated.
*/
virtual OprHandle NewOperator(AsyncFn fn,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) = 0;
/*!
* \brief Delete the given operator.
* \param op The operator to delete.
*/
typedef std::function<void(RunContext rctx)> Op;
/*! \brief callback function to notify operation complete */
typedef std::function<void()> Callback;
virtual void DeleteOperator(OprHandle op) = 0;
/*!
* \brief operation to pass to DAG engine
* \param ctx runtime context
* \param on_complete a callback function used to notify the engine the action completes
* \brief Push an operator to the engine.
* \param op The operator to push.
* \param exec_ctx Execution context.
*/
typedef std::function<void(RunContext ctx, Callback on_complete)> AsyncOp;
virtual void Push(OprHandle op, Context exec_ctx) = 0;
/*!
* \brief variable of dag engine, used to specify dependencies
* defined to be a pointer, that can points to a internal data structure
* of the engine itself
* \brief Push an synchronous operation to the DAG engine.
* \param exec_fun Execution function that executes the operation.
* \param exec_ctx Execution context.
* \param use_vars The variables that current operation will use but not
* mutate.
* \param mutate_vars The variables that current operation will mutate.
*/
void Push(Fn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars);
/*!
* \brief Push an asynchronous operation to the DAG engine.
* \param exec_fun Execution function, this function takes a parameter
* on_complete that must be called when the execution
* completes.
* \param exec_ctx Execution context.
* \param use_vars The variables that current operation will use but not
* mutate.
* \param mutate_vars The variables that current operation will mutate.
*/
virtual void PushAsync(AsyncFn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) = 0;
/*!
* \brief Schedule the delete of a variable.
*
* Design detail: we choose pointer instead of some ID to avoid
* indirect map lookup. usually, Variable directly points to the content we need
*/
typedef void *Variable;
/*!
* \brief Push an asynchronize operation to the DAG engine
* \param exec_fun execution funtion, this function takes a parameter on_complete
* that must be called when the execution completes. For synchronize operations
* \param exec_ctx execution context
* \param use_vars the variables that current operation will use(but not mutate)
* \param mutate_vars the variables that current operation will mutate
*/
virtual void PushAsync(AsyncOp exec_fun,
Context exec_ctx,
const std::vector<Variable> &use_vars,
const std::vector<Variable> &mutate_vars) = 0;
/*!
* \brief Push an synchronize operation to the DAG engine
* \param exec_fun execution funtion that executes the operation
* \param exec_ctx execution context
* \param use_vars the variables that current operation will use(but not mutate)
* \param mutate_vars the variables that current operation will mutate
*/
virtual void Push(Op exec_fun,
Context exec_ctx,
const std::vector<Variable> &use_vars,
const std::vector<Variable> &mutate_vars) {
AsyncOp f = [exec_fun](RunContext ctx, Callback on_complete) {
exec_fun(ctx); on_complete();
};
this->PushAsync(f, exec_ctx, use_vars, mutate_vars);
}
/*!
* \brief schedule the delete of variable var,
* The delete will not happen immediately, but will wait until all the operations
* depending on var is completed
* The delete will not happen immediately, but will wait until all the
* operations depending on var is completed.
*
* \param delete_fun a function that will be called after var is deleted
* \param exec_ctx execution context
* \param var the variable to be deleted
* \param delete_fun A function that will be called after the variable is
* deleted.
* \param exec_ctx Execution context.
* \param var The variable to be deleted.
*/
virtual void PushDelete(Op delete_fun,
Context exec_ctx,
Variable var) = 0;
virtual void PushDelete(Fn delete_fun, Context exec_ctx, Variable var) = 0;
/*!
* \brief allocate a new variable, the variable can then
* be used to schedul the operation concurrently via dependency patterns
* \return thew new variable allocated
* \brief Wait for variable.
* \param var The variable we should wait for, this function returns when all
* the operations related to var has been completed.
*/
virtual Variable NewVar() = 0;
virtual void WaitForVar(Variable var) = 0;
/*!
* \brief wait for variable var
* \param var the variable we should wait for, this function returns when all the operations
* related to var has been completed
* \brief Wait until all the activity of dag engine finishes.
*/
virtual void WaitForVar(Variable var) {}
/*! \brief wait until all the activity of dag engine finishes */
virtual void WaitForAll() {}
/*! \return DAG engine singleton */
static DAGEngine *Get();
};
virtual void WaitForAll() = 0;
/*!
* \brief Virtual destructor.
*/
virtual ~DAGEngine() noexcept(false);
/*!
* \return DAG engine singleton.
*/
static DAGEngine* Get();

protected:
/*!
* \brief Hidden constructors.
*/
DAGEngine();

private:
DISALLOW_COPY_AND_ASSIGN(DAGEngine);
}; // class DAGEngine

} // namespace mxnet

#endif // MXNET_DAG_ENGINE_H_
Loading