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

Commit

Permalink
checkin naive engine back
Browse files Browse the repository at this point in the history
  • Loading branch information
antinucleon committed Sep 5, 2015
1 parent 27f8241 commit 2ca56c9
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 31 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ ifneq ($(ADD_LDFLAGS), NONE)
LDFLAGS += $(ADD_LDFLAGS)
endif

#ENGINE=simple_engine.o dag_engine.o
ENGINE=naive_engine.o
BIN = tests/test_simple_engine
OBJ = narray_function_cpu.o
OBJCXX11 = batch_norm_cpu.o 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
OBJCXX11 = batch_norm_cpu.o reshape_cpu.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 $(ENGINE)
CUOBJ =
SLIB = lib/libmxnet.so
ALIB = lib/libmxnet.a
Expand All @@ -81,8 +83,9 @@ $(DMLC_CORE)/libdmlc.a:
+ cd $(DMLC_CORE); make libdmlc.a config=$(ROOTDIR)/$(config); cd $(ROOTDIR)

storage.o: src/storage/storage.cc
naive_engine.o: src/dag_engine/naive_engine.cc
dag_engine.o: src/dag_engine/dag_engine.cc
simple_engine.o: src/dag_engine/simple_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 @@ -120,10 +123,10 @@ $(BIN) :
$(CXX) $(CFLAGS) -std=c++0x -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS)

$(OBJ) :
$(CXX) -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
$(CXX) -c $(CFLAGS) -o $@ $(filter %.cpp %.c %.cc, $^)

$(OBJCXX11) :
$(CXX) -std=c++0x -c $(CFLAGS) -o $@ $(firstword $(filter %.cpp %.c %.cc, $^) )
$(CXX) -std=c++0x -c $(CFLAGS) -o $@ $(filter %.cpp %.c %.cc, $^)

$(SLIB) :
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.cpp %.o %.c %.a %.cc, $^) $(LDFLAGS)
Expand Down
17 changes: 5 additions & 12 deletions include/mxnet/dag_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class DAGEngine {
* 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);
virtual void Push(Fn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) = 0;
/*!
* \brief Push an asynchronous operation to the DAG engine.
* \param exec_fun Execution function, this function takes a parameter
Expand Down Expand Up @@ -141,20 +141,13 @@ class DAGEngine {
/*!
* \brief Virtual destructor.
*/
virtual ~DAGEngine() noexcept(false);
virtual ~DAGEngine() noexcept(false) {}
/*!
* \return DAG engine singleton.
*/
static DAGEngine* Get();

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

private:
DISALLOW_COPY_AND_ASSIGN(DAGEngine);
// remove DISALLOW_COPY_AND_ASSIGN since this is virtual class.
}; // class DAGEngine

} // namespace mxnet
Expand Down
14 changes: 0 additions & 14 deletions src/dag_engine/dag_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@

namespace mxnet {

void DAGEngine::Push(Fn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) {
auto f = [exec_fun](RunContext ctx, Callback on_complete) {
exec_fun(ctx);
on_complete();
};
PushAsync(f, exec_ctx, use_vars, mutate_vars);
}

DAGEngine::~DAGEngine() noexcept(false) {}

DAGEngine::DAGEngine() = default;

DAGEngine* DAGEngine::Get() {
/*!
* \brief Change specific engine to use.
Expand Down
62 changes: 62 additions & 0 deletions src/dag_engine/naive_engine.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright by Contributors
#include <mxnet/dag_engine.h>

namespace mxnet {
namespace engine {

// The Naive engine interface
class NaiveEngine : public DAGEngine {
public:
Variable NewVar() override {
return nullptr;
}

OprHandle NewOperator(AsyncFn fn,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) override {
LOG(FATAL) << "Not implemented";
return nullptr;
}

void DeleteOperator(OprHandle op) override {
LOG(FATAL) << "Not implemented";
}

void Push(OprHandle op, Context exec_ctx) override {
LOG(FATAL) << "Not implemented";
}

void Push(Fn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) override {
RunContext ctx;
ctx.stream = nullptr;
exec_fun(ctx);
}

void PushAsync(AsyncFn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) override {
LOG(FATAL) << "Not implemented";
}

void PushDelete(Fn delete_fun, Context exec_ctx, Variable var) override {
RunContext ctx;
ctx.stream = nullptr;
delete_fun(ctx);
}

void WaitForVar(Variable var) override {
}

void WaitForAll() override {
}
};

} // namespace engine

DAGEngine* DAGEngine::Get() {
static mxnet::engine::NaiveEngine engine;
return &engine;
}
} // namespace mxnet
10 changes: 10 additions & 0 deletions src/dag_engine/simple_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ void SimpleEngine::DeleteOperator(OprHandle op) {
Push(func, Context{}, {}, deps);
}

void SimpleEngine::Push(Fn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) {
auto f = [exec_fun](RunContext ctx, Callback on_complete) {
exec_fun(ctx);
on_complete();
};
PushAsync(f, exec_ctx, use_vars, mutate_vars);
}

void SimpleEngine::Push(OprHandle op, Context exec_ctx) {
auto&& simple_opr = SimpleOpr::CastFromBase(op);
auto&& opr_block = new OprBlock{};
Expand Down
4 changes: 3 additions & 1 deletion src/dag_engine/simple_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class SimpleEngine final : public DAGEngine {
std::vector<Variable> const& mutate_vars) override;
void DeleteOperator(OprHandle op) override;
void Push(OprHandle op, Context exec_ctx) override;
using DAGEngine::Push;
void Push(Fn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) override;
void PushAsync(AsyncFn exec_fun, Context exec_ctx,
std::vector<Variable> const& use_vars,
std::vector<Variable> const& mutate_vars) override;
Expand Down

0 comments on commit 2ca56c9

Please sign in to comment.