mirror of
https://github.com/RustyRaptor/incubator-mxnet.git
synced 2026-12-04 00:05:18 -07:00
* Copy mxnet.cpp to cpp-package sub directory * Add missing type name declaration for nnvm::Tuple<dmlc::optional<int>> * Add trigger to update operation wrapper in cpp package when building mxnet * Add test to travis scripts * Disable op generation on windows
93 lines
2.3 KiB
C++
93 lines
2.3 KiB
C++
/*!
|
|
* Copyright (c) 2016 by Contributors
|
|
* \file op_map.h
|
|
* \brief definition of OpMap
|
|
* \author Chuntao Hong
|
|
*/
|
|
|
|
#ifndef MXNETCPP_MXNET_H
|
|
#define MXNETCPP_MXNET_H
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include "mxnet-cpp/base.h"
|
|
#include "dmlc/logging.h"
|
|
|
|
namespace mxnet {
|
|
namespace cpp {
|
|
|
|
/*!
|
|
* \brief OpMap instance holds a map of all the symbol creators so we can
|
|
* get symbol creators by name.
|
|
* This is used internally by Symbol and Operator.
|
|
*/
|
|
class OpMap {
|
|
public:
|
|
/*!
|
|
* \brief Create an Mxnet instance
|
|
*/
|
|
inline OpMap() {
|
|
mx_uint num_symbol_creators = 0;
|
|
AtomicSymbolCreator *symbol_creators = nullptr;
|
|
int r =
|
|
MXSymbolListAtomicSymbolCreators(&num_symbol_creators, &symbol_creators);
|
|
CHECK_EQ(r, 0);
|
|
for (mx_uint i = 0; i < num_symbol_creators; i++) {
|
|
const char *name;
|
|
const char *description;
|
|
mx_uint num_args;
|
|
const char **arg_names;
|
|
const char **arg_type_infos;
|
|
const char **arg_descriptions;
|
|
const char *key_var_num_args;
|
|
r = MXSymbolGetAtomicSymbolInfo(symbol_creators[i], &name, &description,
|
|
&num_args, &arg_names, &arg_type_infos,
|
|
&arg_descriptions, &key_var_num_args);
|
|
CHECK_EQ(r, 0);
|
|
symbol_creators_[name] = symbol_creators[i];
|
|
}
|
|
|
|
nn_uint num_ops;
|
|
const char **op_names;
|
|
r = NNListAllOpNames(&num_ops, &op_names);
|
|
CHECK_EQ(r, 0);
|
|
for (nn_uint i = 0; i < num_ops; i++) {
|
|
OpHandle handle;
|
|
r = NNGetOpHandle(op_names[i], &handle);
|
|
CHECK_EQ(r, 0);
|
|
op_handles_[op_names[i]] = handle;
|
|
}
|
|
}
|
|
|
|
/*!
|
|
* \brief Get a symbol creator with its name.
|
|
*
|
|
* \param name name of the symbol creator
|
|
* \return handle to the symbol creator
|
|
*/
|
|
inline AtomicSymbolCreator GetSymbolCreator(const std::string &name) {
|
|
if (symbol_creators_.count(name) == 0)
|
|
return GetOpHandle(name);
|
|
return symbol_creators_[name];
|
|
}
|
|
|
|
/*!
|
|
* \brief Get an op handle with its name.
|
|
*
|
|
* \param name name of the op
|
|
* \return handle to the op
|
|
*/
|
|
inline OpHandle GetOpHandle(const std::string &name) {
|
|
return op_handles_[name];
|
|
}
|
|
|
|
private:
|
|
std::map<std::string, AtomicSymbolCreator> symbol_creators_;
|
|
std::map<std::string, OpHandle> op_handles_;
|
|
};
|
|
|
|
} // namespace cpp
|
|
} // namespace mxnet
|
|
|
|
#endif // MXNETCPP_MXNET_H
|