Commit 871529b1 by Tianqi Chen

Update README.md first init

parent 9a3a1bd0
export LDFLAGS= -pthread -lm
export CFLAGS= -std=c++11 -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops\
-Iinclude -Idmlc-core/include -fPIC
# specify tensor path
.PHONY: clean all test
all: lib/libnngraph.so test
SRC = $(wildcard src/*.cc src/*/*.cc)
ALL_OBJ = $(patsubst src/%.cc, build/%.o, $(SRC)) $(PLUGIN_OBJS)
ALL_DEP = $(ALL_OBJ)
build/%.o: src/%.cc
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -MM -MT build/$*.o $< >build/$*.d
$(CXX) -c $(CFLAGS) -c $< -o $@
lib/libnngraph.so: $(ALL_DEP)
@mkdir -p $(@D)
$(CXX) $(CFLAGS) -shared -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
test: $(ALL_DEP)
$(CXX) $(CFLAGS) -o $@ $(filter %.o %.a, $^) $(LDFLAGS)
clean:
$(RM) -rf build lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o xgboost
-include build/*.d
-include build/*/*.d
......@@ -6,7 +6,4 @@ Prototype of graph optimizer and construction API for next generation core engin
- Pluggable inference, optimization algorithms
- Can be used as input graph execution in various settings, specifically be able to support mxnet's symbolic execution API
## Related Projects
- https://github.com/dmlc/mxnet
- https://github.com/ajtulloch/dnngraph
/*!
* Copyright (c) 2016 by Contributors
* \file attr_frame.h
* \brief Attribute frame data structure for properties in the graph.
* This data structure is inspired by data_frame for general.
*/
#include "./base.h"
namespace nngraph {
struct AttrFrame {
std::unique_ptr<std::unordered_map<std::string, any> > info;
};
} // namespace nngraph
/*!
* Copyright (c) 2016 by Contributors
* \file base.h
* \brief Configuation of nngraph as well as basic data structure.
*/
#ifndef NNGRAPH_BASE_H_
#define NNGRAPH_BASE_H_
#include <dmlc/base.h>
#include <dmlc/any.h>
#include <dmlc/logging.h>
namespace nngraph {
/*! \brief any type */
using any = dmlc::any;
/*!
* \brief get reference of type T stored in src.
* \param src The source container
* \return the reference to the type.
* \tparam T The type to be fetched.
*/
template<typename T>
inline T& get(any& src) { // NOLINT(*)
return dmlc::get<T>(src);
}
/*!
* \brief get const reference of type T stored in src.
* \param src The source container
* \return the reference to the type.
* \tparam T The type to be fetched.
*/
template<typename T>
inline const T& get(const any& src) {
return dmlc::get<T>(src);
}
} // namespace nngraph
#endif // NNGRAPH_BASE_H_
/*!
* Copyright (c) 2016 by Contributors
* \file graph.h
* \brief Configuation of nngraph as well as basic data structure.
*/
#ifndef NNGRAPH_GRAPH_H_
#define NNGRAPH_GRAPH_H_
#include <vector>
#include "./node.h"
#include "./attr_frame.h"
namespace nngraph {
/*!
* \brief Symbolic computation graph.
*/
class Graph {
public:
/*!
* \brief get the index th element from the returned tuple.
* \param index index of multi output
* \return the symbol corresponds to the indexed element.
*/
Graph operator[] (size_t index) const;
/*!
* \brief get number of outputs of this symbol
* \return number of outputs
*/
inline size_t outputs_size() const {
return outputs_.size();
}
private:
/*! \brief outputs of the graph. */
std::vector<NodeEntry> outputs_;
/*! \brief additional internal attribute */
AttrFrame attr_frame_;
};
} // namespace nngraph
#endif // NNGRAPH_GRAPH_H_
/*!
* Copyright (c) 2016 by Contributors
* \file base.h
* \brief Configuation of nngraph as well as basic data structure.
*/
#ifndef NNGRAPH_NODE_H_
#define NNGRAPH_NODE_H_
#include <memory>
#include <unordered_map>
#include "./op_prop.h"
namespace nngraph {
// Forward declare node.
struct Node;
/*! \brief an entry that represents output data from a node */
struct NodeEntry {
/*! \brief the source node of this data */
std::shared_ptr<Node> node;
/*! \brief index of output from the source. */
uint32_t index;
};
/*!
* \brief Node represents an operation in a computation graph.
*/
struct Node {
/*! \brief name of the node */
std::string name;
/*! \brief the operator this node is pointing at */
const OpProperty *op;
/*! \brief inputs to this node */
std::vector<NodeEntry> inputs;
/*!
* \brief additional attributes about the node,
* Use pointer to save space, as attr can be accessed in a slow way,
* not every node will have attributes.
*/
std::unordered_map<std::string, std::string> attr;
~Node() {
if (inputs.size() != 0) {
// explicit deletion via DFS
// this is used to avoid stackoverflow caused by chain of deletions
std::vector<Node*> stack{this};
std::vector<std::shared_ptr<Node> > to_delete;
while (!stack.empty()) {
Node* n = stack.back();
stack.pop_back();
for (NodeEntry& e: n->inputs) {
if (e.node.unique()) {
stack.push_back(e.node.get());
to_delete.emplace_back(std::move(e.node));
} else {
e.node.reset();
}
}
n->inputs.clear();
}
}
}
};
} // namespace nngraph
#endif // NNGRAPH_NODE_H_
/*!
* Copyright (c) 2016 by Contributors
* \file op_prop.h
* \brief Data structure about property of operators
*/
#ifndef NNGRAPH_OP_PROP_H_
#define NNGRAPH_OP_PROP_H_
namespace nngraph {
/*!
* \brief operator specific data structure
*/
struct OpProperty {
/*! \brief name of the operator */
std::string name;
/*! \brief number of inputs to the operator */
int num_inputs;
/*! \brief number of outputs to the operator */
int num_outputs;
};
} // namespace nngraph
#endif // NNGRAPH_OP_PROP_H_
#include <nngraph/graph.h>
int main() {
nngraph::any a = 1;
LOG(INFO) << nngraph::get<int>(a);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment