本文整理汇总了C++中Symbol::GetHandle方法的典型用法代码示例。如果您正苦于以下问题:C++ Symbol::GetHandle方法的具体用法?C++ Symbol::GetHandle怎么用?C++ Symbol::GetHandle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symbol
的用法示例。
在下文中一共展示了Symbol::GetHandle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Executor
inline Executor::Executor(const Symbol &symbol, Context context,
const std::vector<NDArray> &arg_arrays,
const std::vector<NDArray> &grad_arrays,
const std::vector<OpReqType> &grad_reqs,
const std::vector<NDArray> &aux_arrays,
const std::map<std::string, Context> &group_to_ctx,
Executor *shared_exec) {
this->arg_arrays = arg_arrays;
this->grad_arrays = grad_arrays;
this->aux_arrays = aux_arrays;
this->symbol_ = symbol;
std::vector<NDArrayHandle> arg_handles;
std::vector<NDArrayHandle> grad_handles;
std::vector<NDArrayHandle> aux_handles;
for (const auto &array : arg_arrays) {
arg_handles.push_back(array.GetHandle());
}
for (const auto &array : grad_arrays) {
grad_handles.push_back(array.GetHandle());
}
for (const auto &array : aux_arrays) {
aux_handles.push_back(array.GetHandle());
}
std::vector<mx_uint> grad_reqs_uint;
for (auto s : grad_reqs) grad_reqs_uint.push_back(s);
std::vector<const char *> map_keys;
std::vector<int> dev_types, dev_ids;
for (const auto &s : group_to_ctx) {
map_keys.push_back(s.first.c_str());
dev_types.push_back(s.second.GetDeviceType());
dev_ids.push_back(s.second.GetDeviceId());
}
ExecutorHandle *shared_exec_handle =
shared_exec == nullptr ? nullptr : &shared_exec->handle_;
CHECK_EQ(MXExecutorBindEX(symbol.GetHandle(), context.GetDeviceType(),
context.GetDeviceId(), group_to_ctx.size(),
map_keys.data(), dev_types.data(), dev_ids.data(),
arg_handles.size(), arg_handles.data(),
grad_handles.data(), grad_reqs_uint.data(),
aux_handles.size(), aux_handles.data(),
shared_exec_handle, &handle_),
0);
mx_uint out_size;
NDArrayHandle *out_array;
CHECK_EQ(MXExecutorOutputs(handle_, &out_size, &out_array), 0);
for (mx_uint i = 0; i < out_size; ++i) {
outputs.push_back(NDArray(out_array[i]));
}
}