node_attr.h 832 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*!
 * Copyright (c) 2017 by Contributors
 * \file node_attr.h
 * \brief utility to access node attributes
*/
#ifndef NNVM_COMPILER_NODE_ATTR_H_
#define NNVM_COMPILER_NODE_ATTR_H_

#include <nnvm/op.h>
#include <nnvm/compiler/op_attr_types.h>
#include <unordered_map>
#include <string>

namespace nnvm {
namespace compiler {

using AttrDict = std::unordered_map<std::string, std::string>;
/*!
 * \brief Get canonicalized attr dict from node
 * \param attrs The node attrs
 * \return The attribute dict
 */
inline AttrDict GetAttrDict(const NodeAttrs& attrs) {
  static auto& fgetdict = nnvm::Op::GetAttr<FGetAttrDict>("FGetAttrDict");
  if (fgetdict.count(attrs.op)) {
    return fgetdict[attrs.op](attrs);
  } else {
    return attrs.dict;
  }
}

}  // namespace compiler
}  // namespace nnvm
#endif  // NNVM_COMPILER_NODE_ATTR_H_